πŸ’°
Instant Distribution
Create a pool and distribute tokens using @superfluid-finance/js-sdk

Introduction

Let's take a look at another Superfluid Agreement. The Instant Distribution Agreement (IDA) can be used to make one-time-payments to multiple recipients. The IDA could be used for revenue sharing or airdrops. It consists of a Publishing Index with indexId, an indexValue, and one or more subscribers.
Here is an quick glimpse at the IDA contract we'll use in this tutorial. Don't worry, you don't need to memorize this.
1
contract IInstantDistributionAgreementV1 is ISuperAgreement {
2
function createIndex(
3
ISuperToken token,
4
uint32 indexId,
5
bytes calldata ctx)
6
external
7
virtual
8
returns(bytes memory newCtx);
9
​
10
function updateIndex(
11
ISuperToken token,
12
uint32 indexId,
13
uint128 indexValue,
14
bytes calldata ctx)
15
external
16
virtual
17
returns(bytes memory newCtx);
Copied!

Prerequisites

Before starting this tutorial you should:

Create a Pool

The first step to using an IDA is to create a Publishing Index. Once created, the Publishing Index can be used to send tokens at any point in the future. To make things easier, we will just call this poolId
Lets create a new pool:
1
await alice.createPool({ poolId: 1 });
Copied!
Now that we have our Plublishing Index / pool, we can assign it some Subscribers. We do this by giving shares to other people like this:
1
await alice.giveShares({ poolId: 1, recipient: bob, shares: 90 });
2
await alice.giveShares({ poolId: 1, recipient: carol, shares: 10 });
Copied!
And finally we can distribute funds to everyone in the pool, based on the amount of shares they have.
1
await alice.distributeToPool({ poolId: 1, amount: 1000 });
Copied!
In this example, bob will receive 90% of the tokens alice sent, while carol only receives 10%. Bob will have 900 and carol will have 100.
Thats it! One thing to pay attention - for a recipient's balance to reflect the distribution event, they should first call approveSubscription one time. If they fail to do this, don't worry, they can still receive their tokens after calling the claim function at any time.
βš” Look at you now, with two agreements at your disposal. You can duel-wield! Its time to learn more about Super Tokens.
Last modified 25d ago