@streamflow/distributor 8.8.0 → 8.9.0-alpha.p308.94c0898
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +119 -51
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -6,6 +6,20 @@ Token Distributor essentially that allows you to Airdrop tokens to multiple (tho
|
|
|
6
6
|
|
|
7
7
|
You can also use `getClaims` and `getDistributors` to fetch active claims and distributors respectively.
|
|
8
8
|
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [Installation](#installation)
|
|
12
|
+
- [Documentation](#documentation)
|
|
13
|
+
- [Import SDK](#import-sdk)
|
|
14
|
+
- [Create DistributorClient instance](#create-distributorclient-instance)
|
|
15
|
+
- [Solana](#solana)
|
|
16
|
+
- [Create an Airdrop (Distributor account)](#create-an-airdrop-distributor-account)
|
|
17
|
+
- [Claim an Airdrop](#claim-an-airdrop)
|
|
18
|
+
- [Close a Claim](#close-a-claim)
|
|
19
|
+
- [Clawback an Airdrop](#clawback-an-airdrop)
|
|
20
|
+
- [Search Airdrops](#search-airdrops)
|
|
21
|
+
- [Additional notes](#additional-notes)
|
|
22
|
+
|
|
9
23
|
---
|
|
10
24
|
|
|
11
25
|
## Installation
|
|
@@ -17,7 +31,9 @@ or
|
|
|
17
31
|
`yarn add @streamflow/common @streamflow/distributor`
|
|
18
32
|
|
|
19
33
|
## Documentation
|
|
20
|
-
|
|
34
|
+
More Documentation available here: [docs site →](https://streamflow-finance.github.io/js-sdk/)
|
|
35
|
+
|
|
36
|
+
Public API documentation: [API docs →](https://api-public.streamflow.finance/v2/docs#/)
|
|
21
37
|
|
|
22
38
|
Automated Airdrop Creation: [notion doc →](https://streamflow.notion.site/Automated-Airdrop-Creation-45b84bfd2dda4d7196be5dd02eed29c8)
|
|
23
39
|
|
|
@@ -48,28 +64,77 @@ const client = new SolanaDistributorClient({
|
|
|
48
64
|
```javascript
|
|
49
65
|
const now = Math.floor(Date.now() / 1000);
|
|
50
66
|
|
|
67
|
+
const createData = {
|
|
68
|
+
mint: "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj", // mint
|
|
69
|
+
name: "My Airdrop", // airdrop name
|
|
70
|
+
file: csvFile, // CSV file, File | Blob
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/* The CSV file should have the following format (headers can be omitted)
|
|
74
|
+
pubkey,amount_unlocked,amount_locked,category
|
|
75
|
+
1111111QLbz7JHiBTspS962RLKV8GndWFwiEaqKM,0,1,Staker
|
|
76
|
+
1111111ogCyDbaRMvkdsHB3qfdyFYaG1WtRUAfdh,0,1,Staker
|
|
77
|
+
11111112D1oxKts8YPdTJRG5FzxTNpMtWmq8hkVx3,0,1,Staker
|
|
78
|
+
11111112cMQwSC9qirWGjZM6gLGwW69X22mqwLLGP,0,1,Staker
|
|
79
|
+
|
|
80
|
+
Where:
|
|
81
|
+
- amount_unlocked - amount of tokens unlocked right at the start of vesting (cliff);
|
|
82
|
+
- amount_locked - amount to be distributed;
|
|
83
|
+
- category - set to `Staker` as constant, it’s not used right now;
|
|
84
|
+
|
|
85
|
+
Amounts are in raw format - you need to account for decimal places -> 1.5 tokens with 6 decimals will be 1500000
|
|
86
|
+
*/
|
|
87
|
+
|
|
51
88
|
const solanaParams = {
|
|
52
89
|
invoker: wallet, // SignerWalletAdapter or Keypair of Sender account
|
|
53
90
|
isNative: // [optional] [WILL CREATE A wSOL Airdrop] Needed only if you need to Airdrop Solana native token
|
|
54
91
|
};
|
|
55
92
|
|
|
56
|
-
const
|
|
57
|
-
{
|
|
93
|
+
const distributorParams = {
|
|
58
94
|
mint: "Gssm3vfi8s65R31SBdmQRq6cKeYojGgup7whkw4VCiQj", // mint
|
|
59
|
-
version: now, // version of the Airdrop, version will be used to generate unique address of the Distributor Account
|
|
60
|
-
root: [
|
|
61
|
-
54, 218, 49, 68, 131, 214, 250, 113, 37, 143, 167, 73, 17, 54, 233, 26, 141, 93, 28, 186, 137, 211, 251, 205,
|
|
62
|
-
240, 192, 134, 208, 108, 246, 0, 191,
|
|
63
|
-
], // Merkle root
|
|
64
|
-
maxNumNodes: 4, // Number of recipients
|
|
65
|
-
maxTotalClaim: new BN("4000000000"), // Total amount to distribute
|
|
66
95
|
unlockPeriod: 1, // Unlock period in seconds
|
|
67
|
-
startVestingTs: 0, // Timestamp when Airdrop starts
|
|
96
|
+
startVestingTs: 0, // Timestamp when Airdrop starts, 0 for immediately upon creation
|
|
68
97
|
endVestingTs: now + 3600 * 24 * 7, // Timestamp when Airdrop ends
|
|
69
98
|
clawbackStartTs: now + 5, // Timestamp after which Airdrop can be clawed back to the Sender address
|
|
70
99
|
claimsClosableByAdmin: false, // Whether individual Claims can be closed by the Sender
|
|
71
100
|
claimsClosableByClaimant: false, // Whether the Recipient can close their own Claim
|
|
72
101
|
claimsLimit: null, // The number of times a Recipient can Claim the Airdrop - 0 or null for no limit on claims
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/* You can use our public API for generating a merkleTree or use your own implementation
|
|
105
|
+
The public API is accessed with an auth token passed in in the x-api-key header of the request
|
|
106
|
+
The tokens are provided manually by Streamflow by reaching out to us with the
|
|
107
|
+
wallet address that will create the Airdrop
|
|
108
|
+
*/
|
|
109
|
+
const { data: merkleResponse } = await httpClient.post(
|
|
110
|
+
"https://api-public.streamflow.finance/v2/api/airdrops/",
|
|
111
|
+
createData,
|
|
112
|
+
headers: {
|
|
113
|
+
"Content-Type": "multipart/form-data",
|
|
114
|
+
"x-api-key": "<your-auth-token>"
|
|
115
|
+
}
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
// You can prepare the instructions for more granular control of execution
|
|
119
|
+
const { ixs } = await client.prepareCreateInstructions(
|
|
120
|
+
{
|
|
121
|
+
...merkleResponse,
|
|
122
|
+
root: merkleResponse.merkleRoot,
|
|
123
|
+
maxNumNodes: new BN(merkleResponse.maxNumNodes).toString(),
|
|
124
|
+
maxTotalClaim: new BN(merkleResponse.maxTotalClaim),
|
|
125
|
+
...distributorData,
|
|
126
|
+
},
|
|
127
|
+
solanaParams,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
// Or you can call the create function which will trigger the transaction execution for you
|
|
131
|
+
const res = await client.create(
|
|
132
|
+
{
|
|
133
|
+
...merkleResponse,
|
|
134
|
+
root: merkleResponse.merkleRoot,
|
|
135
|
+
maxNumNodes: new BN(merkleResponse.maxNumNodes).toString(),
|
|
136
|
+
maxTotalClaim: new BN(merkleResponse.maxTotalClaim),
|
|
137
|
+
...distributorData,
|
|
73
138
|
},
|
|
74
139
|
solanaParams,
|
|
75
140
|
);
|
|
@@ -82,23 +147,32 @@ const solanaParams = {
|
|
|
82
147
|
invoker: recipient, // SignerWalletAdapter or Keypair of Recipient account
|
|
83
148
|
};
|
|
84
149
|
|
|
150
|
+
const claimantAddress = "s3pWmY359mDrNRnDBZ3v5TrrqqxvxiW2t4U2WZyxRoA" // Wallet that will perform the claim
|
|
151
|
+
const ditributorAddress = res.metadataId; // address of the distributor account
|
|
152
|
+
|
|
153
|
+
// Use our public api or your own solution
|
|
154
|
+
const claimantData = await httpClient.get(
|
|
155
|
+
`https://api-public.streamflow.finance/v2/api/airdrops/${distributorAddress}/claimants/${claimantAddress}`,
|
|
156
|
+
headers: { "x-api-key": "<your-auth-token>" }
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
const claimantParams = {
|
|
160
|
+
id: claimantData.distributorAddress,
|
|
161
|
+
proof: claimantData.proof, // Merkle Proof used to verify claim
|
|
162
|
+
amountUnlocked: new BN(claimantData.amountUnlocked), // Total amount unlocked for a Recipient
|
|
163
|
+
amountLocked: new BN(claimantData.amountLocked), // Total amount locked for a Recipient
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
// Prepare the claim instructions
|
|
167
|
+
const { ixs } = client.prepareClaimInstructions(
|
|
168
|
+
claimantParams,
|
|
169
|
+
solanaParams,
|
|
170
|
+
),
|
|
171
|
+
|
|
172
|
+
// Or use the SDK to trigger the transaction
|
|
85
173
|
const claimRes = await client.claim(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
proof: [
|
|
89
|
-
[
|
|
90
|
-
36, 11, 128, 61, 125, 228, 9, 50, 112, 51, 54, 201, 213, 81, 228, 216, 62, 191, 68, 63, 59, 125, 163, 77, 44,
|
|
91
|
-
88, 170, 65, 139, 25, 147, 145,
|
|
92
|
-
],
|
|
93
|
-
[
|
|
94
|
-
53, 101, 204, 14, 202, 64, 98, 238, 49, 6, 119, 208, 98, 195, 150, 81, 191, 55, 46, 103, 91, 245, 121, 195,
|
|
95
|
-
43, 104, 75, 183, 12, 38, 37, 153,
|
|
96
|
-
],
|
|
97
|
-
], // Merkle Proof used to verify claim
|
|
98
|
-
amountUnlocked: new BN("0"), // Total amount unlocked for a Recipient
|
|
99
|
-
amountLocked: new BN("1000000000"), // Total amount locked for a Recipient
|
|
100
|
-
},
|
|
101
|
-
solanaParams,
|
|
174
|
+
claimantParams,
|
|
175
|
+
solanaParams,
|
|
102
176
|
);
|
|
103
177
|
```
|
|
104
178
|
|
|
@@ -109,7 +183,7 @@ const solanaParams = {
|
|
|
109
183
|
invoker: recipient, // SignerWalletAdapter or Keypair of Recipient account
|
|
110
184
|
};
|
|
111
185
|
|
|
112
|
-
// By Admin
|
|
186
|
+
// By Admin of the Airdrop, no need for proof in this case
|
|
113
187
|
const closeRes = await client.closeClaim(
|
|
114
188
|
{
|
|
115
189
|
id: res.metadataId, // address of the Distributor Account
|
|
@@ -118,23 +192,25 @@ const closeRes = await client.closeClaim(
|
|
|
118
192
|
solanaParams,
|
|
119
193
|
);
|
|
120
194
|
|
|
195
|
+
|
|
196
|
+
|
|
121
197
|
// By Claimant
|
|
198
|
+
const claimantAddress = "s3pWmY359mDrNRnDBZ3v5TrrqqxvxiW2t4U2WZyxRoA" // Wallet that will perform the claim
|
|
199
|
+
const ditributorAddress = res.metadataId; // address of the distributor account
|
|
200
|
+
|
|
201
|
+
// Use our public api or your own solution
|
|
202
|
+
const claimantData = await httpClient.get(
|
|
203
|
+
`https://api-public.streamflow.finance/v2/api/airdrops/${distributorAddress}/claimants/${claimantAddress}`,
|
|
204
|
+
headers: { "x-api-key": "<your-auth-token>" }
|
|
205
|
+
)
|
|
206
|
+
|
|
122
207
|
const closeRes = await client.closeClaim(
|
|
123
208
|
{
|
|
124
|
-
id:
|
|
125
|
-
proof:
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
],
|
|
130
|
-
[
|
|
131
|
-
53, 101, 204, 14, 202, 64, 98, 238, 49, 6, 119, 208, 98, 195, 150, 81, 191, 55, 46, 103, 91, 245, 121, 195,
|
|
132
|
-
43, 104, 75, 183, 12, 38, 37, 153,
|
|
133
|
-
],
|
|
134
|
-
], // Merkle Proof used to verify claim
|
|
135
|
-
amountUnlocked: new BN("0"), // Total amount unlocked for a Recipient
|
|
136
|
-
amountLocked: new BN("1000000000"), // Total amount locked for a Recipient
|
|
137
|
-
claimant: "s3pWmY359mDrNRnDBZ3v5TrrqqxvxiW2t4U2WZyxRoA" // address of the Recipient/Claimant
|
|
209
|
+
id: claimantData.distributorAddress,
|
|
210
|
+
proof: claimantData.proof, // Merkle Proof used to verify claim
|
|
211
|
+
amountUnlocked: new BN(claimantData.amountUnlocked), // Total amount unlocked for a Recipient
|
|
212
|
+
amountLocked: new BN(claimantData.amountLocked), // Total amount locked for a Recipient
|
|
213
|
+
claimant: claimantAddress // address of the Recipient/Claimant
|
|
138
214
|
},
|
|
139
215
|
solanaParams,
|
|
140
216
|
);
|
|
@@ -159,7 +235,7 @@ const clawbackRes = await client.clawback({ id: res.metadataId }, solanaParams);
|
|
|
159
235
|
As all the data is stored on-chain you can also search Airdrops with `searchDistributors` method:
|
|
160
236
|
|
|
161
237
|
```javascript
|
|
162
|
-
// All parameters are optional, so in theory you just fetch all Distributors
|
|
238
|
+
// All parameters are optional, so in theory you can just fetch all Distributors
|
|
163
239
|
const params = {
|
|
164
240
|
mint: "BZLbGTNCSFfoth2GYDtwr7e4imWzpR5jqcUuGEwr646K",
|
|
165
241
|
admin: "s3pWmY359mDrNRnDBZ3v5TrrqqxvxiW2t4U2WZyxRoA"
|
|
@@ -168,14 +244,6 @@ const params = {
|
|
|
168
244
|
const disributors = await client.searchDistributors(params);
|
|
169
245
|
```
|
|
170
246
|
|
|
171
|
-
## Handling errors
|
|
172
|
-
|
|
173
|
-
`GenericStreamClient` wraps all errors when making on-chain calls with `ContractError` error class:
|
|
174
|
-
- this class inherits original traceback
|
|
175
|
-
- error may optionally contain `contractErrorCode` property that can be further mapped to a specific **Contract** error
|
|
176
|
-
- for `createMultiple` method errors are wrapped individually for every recipient address
|
|
177
|
-
- please check documentation for enums `AnchorErrorCode` and `ContractErrorCode` at `solana/types.ts` to see short description for each error
|
|
178
|
-
|
|
179
247
|
## Additional notes
|
|
180
248
|
|
|
181
249
|
Streamflow Distributor protocol program IDs
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamflow/distributor",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.9.0-alpha.p308.94c0898",
|
|
4
4
|
"description": "JavaScript SDK to interact with Streamflow Airdrop protocol.",
|
|
5
5
|
"homepage": "https://github.com/streamflow-finance/js-sdk/",
|
|
6
6
|
"main": "./dist/cjs/index.cjs",
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"lint": "eslint --fix .",
|
|
69
69
|
"prepublishOnly": "pnpm run lint && pnpm run test && pnpm run build"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "4d07fab65928f4bb128b55418fe3b35bc0531968",
|
|
72
72
|
"devDependencies": {
|
|
73
|
-
"@streamflow/eslint-config": "8.
|
|
73
|
+
"@streamflow/eslint-config": "8.9.0-alpha.p308.94c0898",
|
|
74
74
|
"@types/bn.js": "5.1.1",
|
|
75
75
|
"typescript": "^5.6.3"
|
|
76
76
|
},
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"@solana/spl-token": "0.4.9",
|
|
82
82
|
"@solana/wallet-adapter-base": "0.9.19",
|
|
83
83
|
"@solana/web3.js": "1.95.4",
|
|
84
|
-
"@streamflow/common": "8.
|
|
84
|
+
"@streamflow/common": "8.9.0-alpha.p308.94c0898",
|
|
85
85
|
"bn.js": "5.2.1",
|
|
86
86
|
"borsh": "^2.0.0",
|
|
87
87
|
"bs58": "5.0.0",
|