sora-xor / sora-card

Designing a Better World Through Decentralized Technologies
4 stars 1 forks source link

SORA Card Referral Program #1

Open bgodlin opened 1 year ago

bgodlin commented 1 year ago

User story

As a SORA Card user I want to invite people to order and use SORA Card so that I can help grow the ecosystem and get rewarded for helping grow the ecosystem.

Requirements

Referral link needs to stick to a certain account Referee and referral each receive EUR 40 worth of XOR when:

When the criteria are fulfilled, both the referree´s balance and the referrals balance should automatically receive EUR 40 worth of XOR from a SORA wallet.

Solution

Gatehub operates a single SORA network wallet that monitors transactions to and from its address and automatically converts them to fiat currency as needed. This conversion is performed by sending funds from the wallet's address. By tracking transactions associated with this address, it is possible to calculate the amount of currency conversion that has occurred.

To track historical data and emit the referral payout event, we need to develop a service that can monitor transaction volume and has access to a private key for the referral payment sender's account.

To ensure a successful payout, the wallet must have sufficient funds that can originate from other accounts. However, transactions from these accounts must be excluded from the calculation as they are associated with different addresses.

Flow

Step 1. Service subscribes to the historical blockchain data using Subquery instance:

graphql query { historyElements( first: $countRemote orderBy: TIMESTAMP_DESC offset: $offsetNumber filter: { or: [ { address: { equalTo: "$GateHubWalletAddress" } module: { equalTo: "assets" } method: { equalTo: "transfer" } } { data: { contains: { to: "$GateHubWalletAddress" } } execution: { contains: { success: true } } } ] } ) { nodes { id blockHeight module method address networkFee execution timestamp data } } }

Step 2. Service initiates the process of computing the traded volume.

It begins by aggregating the trading volume for each unique address linked to the master wallet using from and to responses from Subquery (see https://github.com/soramitsu/sora-card-backend/issues/147). Since the volume needs to be determined in EUR, the service directly retrieves the equivalent EUR value by accessing the corresponding endpoint.

Step 3. Once a certain threshold is reached, a transfer is initiated to the corresponding address. Example in JS.

Tasks

Web

Mobile

Aha! Link: https://soramitsucoltd.aha.io/features/SC-15

Tieumsan commented 1 year ago

Comment added by Soramitsu Labs in Aha! - View

Need gatehub doc