@streamflow/distributor 6.3.9 → 7.0.0-alpha.2
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 +4 -5
- package/dist/{solana → cjs/solana}/client.js +18 -17
- package/dist/{solana → cjs/solana}/generated/accounts/ClaimStatus.js +6 -6
- package/dist/{solana → cjs/solana}/generated/accounts/MerkleDistributor.js +10 -10
- package/dist/{solana → cjs/solana}/generated/instructions/clawback.js +2 -1
- package/dist/{solana → cjs/solana}/generated/instructions/closeClaim.js +2 -1
- package/dist/{solana → cjs/solana}/generated/instructions/newDistributor.js +4 -3
- package/dist/{solana → cjs/solana}/generated/instructions/setAdmin.js +2 -1
- package/dist/{solana → cjs/solana}/generated/instructions/setClawbackReceiver.js +2 -1
- package/dist/{solana → cjs/solana}/utils.js +5 -4
- package/dist/esm/index.js +1 -0
- package/dist/esm/solana/client.js +189 -0
- package/dist/esm/solana/constants.js +8 -0
- package/dist/{solana → esm/solana}/generated/accounts/ClaimStatus.d.ts +11 -11
- package/dist/esm/solana/generated/accounts/ClaimStatus.js +113 -0
- package/dist/{solana → esm/solana}/generated/accounts/MerkleDistributor.d.ts +19 -19
- package/dist/esm/solana/generated/accounts/MerkleDistributor.js +190 -0
- package/dist/esm/solana/generated/accounts/index.js +2 -0
- package/dist/esm/solana/generated/errors/anchor.js +707 -0
- package/dist/esm/solana/generated/errors/custom.js +252 -0
- package/dist/esm/solana/generated/errors/index.js +37 -0
- package/dist/esm/solana/generated/instructions/claimLocked.js +19 -0
- package/dist/esm/solana/generated/instructions/clawback.js +18 -0
- package/dist/esm/solana/generated/instructions/closeClaim.js +18 -0
- package/dist/esm/solana/generated/instructions/index.js +7 -0
- package/dist/{solana → esm/solana}/generated/instructions/newClaim.d.ts +3 -3
- package/dist/esm/solana/generated/instructions/newClaim.js +32 -0
- package/dist/{solana → esm/solana}/generated/instructions/newDistributor.d.ts +8 -8
- package/dist/esm/solana/generated/instructions/newDistributor.js +67 -0
- package/dist/esm/solana/generated/instructions/setAdmin.js +14 -0
- package/dist/esm/solana/generated/instructions/setClawbackReceiver.js +14 -0
- package/dist/esm/solana/generated/programId.js +5 -0
- package/dist/esm/solana/index.js +7 -0
- package/dist/{solana → esm/solana}/types.d.ts +4 -5
- package/dist/esm/solana/types.js +156 -0
- package/dist/esm/solana/utils.js +60 -0
- package/package.json +21 -21
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{solana → cjs/solana}/constants.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/accounts/index.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/errors/anchor.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/errors/custom.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/errors/index.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/instructions/claimLocked.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/instructions/index.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/instructions/newClaim.js +0 -0
- /package/dist/{solana → cjs/solana}/generated/programId.js +0 -0
- /package/dist/{solana → cjs/solana}/index.js +0 -0
- /package/dist/{solana → cjs/solana}/types.js +0 -0
- /package/dist/{index.d.ts → esm/index.d.ts} +0 -0
- /package/dist/{solana → esm/solana}/client.d.ts +0 -0
- /package/dist/{solana → esm/solana}/constants.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/accounts/index.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/errors/anchor.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/errors/custom.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/errors/index.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/claimLocked.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/clawback.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/closeClaim.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/index.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/setAdmin.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/instructions/setClawbackReceiver.d.ts +0 -0
- /package/dist/{solana → esm/solana}/generated/programId.d.ts +0 -0
- /package/dist/{solana → esm/solana}/index.d.ts +0 -0
- /package/dist/{solana → esm/solana}/utils.d.ts +0 -0
package/README.md
CHANGED
|
@@ -24,7 +24,6 @@ API Documentation available here: [docs site →](https://streamflow-finance.git
|
|
|
24
24
|
Most common imports:
|
|
25
25
|
|
|
26
26
|
```javascript
|
|
27
|
-
import { BN } from "bn.js";
|
|
28
27
|
import { ICluster } from "@streamflow/common";
|
|
29
28
|
import { SolanaDistributorClient } from "@streamflow/distributor/solana";
|
|
30
29
|
```
|
|
@@ -60,8 +59,8 @@ const res = await client.create(
|
|
|
60
59
|
54, 218, 49, 68, 131, 214, 250, 113, 37, 143, 167, 73, 17, 54, 233, 26, 141, 93, 28, 186, 137, 211, 251, 205,
|
|
61
60
|
240, 192, 134, 208, 108, 246, 0, 191,
|
|
62
61
|
], // Merkle root
|
|
63
|
-
maxNumNodes:
|
|
64
|
-
maxTotalClaim:
|
|
62
|
+
maxNumNodes: 4, // Number of recipients
|
|
63
|
+
maxTotalClaim: "4000000000", // Total amount to distribute
|
|
65
64
|
unlockPeriod: 1, // Unlock period in seconds
|
|
66
65
|
startVestingTs: 0, // Timestamp when Airdrop starts
|
|
67
66
|
endVestingTs: now + 3600 * 24 * 7, // Timestamp when Airdrop ends
|
|
@@ -92,8 +91,8 @@ const claimRes = await client.claim(
|
|
|
92
91
|
43, 104, 75, 183, 12, 38, 37, 153,
|
|
93
92
|
],
|
|
94
93
|
], // Merkle Proof used to verify claim
|
|
95
|
-
amountUnlocked:
|
|
96
|
-
amountLocked:
|
|
94
|
+
amountUnlocked: "0", // Total amount unlocked for a Recipient
|
|
95
|
+
amountLocked: "1000000000", // Total amount locked for a Recipient
|
|
97
96
|
},
|
|
98
97
|
solanaParams,
|
|
99
98
|
);
|
|
@@ -64,7 +64,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
64
64
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
65
65
|
};
|
|
66
66
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
|
-
var
|
|
67
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
68
68
|
var spl_token_1 = require("@solana/spl-token");
|
|
69
69
|
var web3_js_1 = require("@solana/web3.js");
|
|
70
70
|
var common_1 = require("@streamflow/common");
|
|
@@ -137,14 +137,14 @@ var SolanaDistributorClient = /** @class */ (function () {
|
|
|
137
137
|
case 3:
|
|
138
138
|
senderTokens = _g.sent();
|
|
139
139
|
args = {
|
|
140
|
-
version:
|
|
140
|
+
version: (0, bignumber_js_1.default)(data.version),
|
|
141
141
|
root: data.root,
|
|
142
|
-
maxTotalClaim: data.maxTotalClaim,
|
|
143
|
-
maxNumNodes: data.maxNumNodes,
|
|
144
|
-
unlockPeriod:
|
|
145
|
-
startVestingTs:
|
|
146
|
-
endVestingTs:
|
|
147
|
-
clawbackStartTs:
|
|
142
|
+
maxTotalClaim: (0, bignumber_js_1.default)(data.maxTotalClaim),
|
|
143
|
+
maxNumNodes: (0, bignumber_js_1.default)(data.maxNumNodes),
|
|
144
|
+
unlockPeriod: (0, bignumber_js_1.default)(data.unlockPeriod),
|
|
145
|
+
startVestingTs: (0, bignumber_js_1.default)(data.startVestingTs),
|
|
146
|
+
endVestingTs: (0, bignumber_js_1.default)(data.endVestingTs),
|
|
147
|
+
clawbackStartTs: (0, bignumber_js_1.default)(data.clawbackStartTs),
|
|
148
148
|
claimsClosable: data.claimsClosable,
|
|
149
149
|
};
|
|
150
150
|
accounts = {
|
|
@@ -161,15 +161,15 @@ var SolanaDistributorClient = /** @class */ (function () {
|
|
|
161
161
|
_c = (_b = ixs.push).apply;
|
|
162
162
|
_d = [ixs];
|
|
163
163
|
_e = [[]];
|
|
164
|
-
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, extParams.invoker.publicKey, data.maxTotalClaim)];
|
|
164
|
+
return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, extParams.invoker.publicKey, (0, bignumber_js_1.default)(data.maxTotalClaim))];
|
|
165
165
|
case 4:
|
|
166
166
|
_c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [(_g.sent())]), false]))]));
|
|
167
167
|
_g.label = 5;
|
|
168
168
|
case 5:
|
|
169
|
-
nowTs =
|
|
170
|
-
endVestingTs = args.endVestingTs.
|
|
171
|
-
startVestingTs = args.startVestingTs.
|
|
172
|
-
if (endVestingTs.gt(startVestingTs) && endVestingTs.
|
|
169
|
+
nowTs = (0, bignumber_js_1.default)(Math.floor(Date.now() / 1000));
|
|
170
|
+
endVestingTs = args.endVestingTs.isZero() ? nowTs : args.endVestingTs;
|
|
171
|
+
startVestingTs = args.startVestingTs.isZero() ? nowTs : args.startVestingTs;
|
|
172
|
+
if (endVestingTs.gt(startVestingTs) && endVestingTs.minus(startVestingTs).lt(args.unlockPeriod)) {
|
|
173
173
|
throw new Error("The unlock period cannot be longer than the total vesting duration!");
|
|
174
174
|
}
|
|
175
175
|
ixs.push((0, instructions_1.newDistributor)(args, accounts, this.programId));
|
|
@@ -258,14 +258,15 @@ var SolanaDistributorClient = /** @class */ (function () {
|
|
|
258
258
|
};
|
|
259
259
|
if (!claimStatus) {
|
|
260
260
|
args = {
|
|
261
|
-
amountLocked: data.amountLocked,
|
|
262
|
-
amountUnlocked: data.amountUnlocked,
|
|
261
|
+
amountLocked: (0, bignumber_js_1.default)(data.amountLocked),
|
|
262
|
+
amountUnlocked: (0, bignumber_js_1.default)(data.amountUnlocked),
|
|
263
263
|
proof: data.proof,
|
|
264
264
|
};
|
|
265
265
|
ixs.push((0, instructions_1.newClaim)(args, accounts, this.programId));
|
|
266
266
|
}
|
|
267
|
-
nowTs =
|
|
268
|
-
if (claimStatus ||
|
|
267
|
+
nowTs = (0, bignumber_js_1.default)(Math.floor(Date.now() / 1000));
|
|
268
|
+
if (claimStatus ||
|
|
269
|
+
((0, bignumber_js_1.default)(data.amountLocked).gt(0) && nowTs.minus(distributor.startTs).gte(distributor.unlockPeriod))) {
|
|
269
270
|
ixs.push((0, instructions_1.claimLocked)(accounts, this.programId));
|
|
270
271
|
}
|
|
271
272
|
return [2 /*return*/, ixs];
|
|
@@ -64,7 +64,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
65
|
exports.ClaimStatus = void 0;
|
|
66
66
|
var web3_js_1 = require("@solana/web3.js");
|
|
67
|
-
var
|
|
67
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
68
68
|
var borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
69
69
|
var programId_1 = require("../programId");
|
|
70
70
|
/** Holds whether or not a claimant has claimed tokens. */
|
|
@@ -156,11 +156,11 @@ var ClaimStatus = /** @class */ (function () {
|
|
|
156
156
|
ClaimStatus.fromJSON = function (obj) {
|
|
157
157
|
return new ClaimStatus({
|
|
158
158
|
claimant: new web3_js_1.PublicKey(obj.claimant),
|
|
159
|
-
lockedAmount:
|
|
160
|
-
lockedAmountWithdrawn:
|
|
161
|
-
unlockedAmount:
|
|
162
|
-
lastClaimTs:
|
|
163
|
-
lastAmountPerUnlock:
|
|
159
|
+
lockedAmount: (0, bignumber_js_1.default)(obj.lockedAmount),
|
|
160
|
+
lockedAmountWithdrawn: (0, bignumber_js_1.default)(obj.lockedAmountWithdrawn),
|
|
161
|
+
unlockedAmount: (0, bignumber_js_1.default)(obj.unlockedAmount),
|
|
162
|
+
lastClaimTs: (0, bignumber_js_1.default)(obj.lastClaimTs),
|
|
163
|
+
lastAmountPerUnlock: (0, bignumber_js_1.default)(obj.lastAmountPerUnlock),
|
|
164
164
|
closed: obj.closed,
|
|
165
165
|
buffer1: obj.buffer1,
|
|
166
166
|
buffer2: obj.buffer2,
|
|
@@ -64,7 +64,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
64
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
65
|
exports.MerkleDistributor = void 0;
|
|
66
66
|
var web3_js_1 = require("@solana/web3.js");
|
|
67
|
-
var
|
|
67
|
+
var bignumber_js_1 = __importDefault(require("bignumber.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
68
68
|
var borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
69
69
|
var programId_1 = require("../programId");
|
|
70
70
|
/** State for the account which distributes tokens. */
|
|
@@ -189,18 +189,18 @@ var MerkleDistributor = /** @class */ (function () {
|
|
|
189
189
|
MerkleDistributor.fromJSON = function (obj) {
|
|
190
190
|
return new MerkleDistributor({
|
|
191
191
|
bump: obj.bump,
|
|
192
|
-
version:
|
|
192
|
+
version: (0, bignumber_js_1.default)(obj.version),
|
|
193
193
|
root: obj.root,
|
|
194
194
|
mint: new web3_js_1.PublicKey(obj.mint),
|
|
195
195
|
tokenVault: new web3_js_1.PublicKey(obj.tokenVault),
|
|
196
|
-
maxTotalClaim:
|
|
197
|
-
maxNumNodes:
|
|
198
|
-
unlockPeriod:
|
|
199
|
-
totalAmountClaimed:
|
|
200
|
-
numNodesClaimed:
|
|
201
|
-
startTs:
|
|
202
|
-
endTs:
|
|
203
|
-
clawbackStartTs:
|
|
196
|
+
maxTotalClaim: (0, bignumber_js_1.default)(obj.maxTotalClaim),
|
|
197
|
+
maxNumNodes: (0, bignumber_js_1.default)(obj.maxNumNodes),
|
|
198
|
+
unlockPeriod: (0, bignumber_js_1.default)(obj.unlockPeriod),
|
|
199
|
+
totalAmountClaimed: (0, bignumber_js_1.default)(obj.totalAmountClaimed),
|
|
200
|
+
numNodesClaimed: (0, bignumber_js_1.default)(obj.numNodesClaimed),
|
|
201
|
+
startTs: (0, bignumber_js_1.default)(obj.startTs),
|
|
202
|
+
endTs: (0, bignumber_js_1.default)(obj.endTs),
|
|
203
|
+
clawbackStartTs: (0, bignumber_js_1.default)(obj.clawbackStartTs),
|
|
204
204
|
clawbackReceiver: new web3_js_1.PublicKey(obj.clawbackReceiver),
|
|
205
205
|
admin: new web3_js_1.PublicKey(obj.admin),
|
|
206
206
|
clawedBack: obj.clawedBack,
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.clawback = void 0;
|
|
4
4
|
var web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
5
|
+
var buffer_1 = require("buffer");
|
|
5
6
|
var programId_1 = require("../programId");
|
|
6
7
|
function clawback(accounts, programId) {
|
|
7
8
|
if (programId === void 0) { programId = programId_1.PROGRAM_ID; }
|
|
@@ -14,7 +15,7 @@ function clawback(accounts, programId) {
|
|
|
14
15
|
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
|
|
15
16
|
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
16
17
|
];
|
|
17
|
-
var identifier = Buffer.from([111, 92, 142, 79, 33, 234, 82, 27]);
|
|
18
|
+
var identifier = buffer_1.Buffer.from([111, 92, 142, 79, 33, 234, 82, 27]);
|
|
18
19
|
var data = identifier;
|
|
19
20
|
var ix = new web3_js_1.TransactionInstruction({ keys: keys, programId: programId, data: data });
|
|
20
21
|
return ix;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.closeClaim = void 0;
|
|
4
4
|
var web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
5
|
+
var buffer_1 = require("buffer");
|
|
5
6
|
var programId_1 = require("../programId");
|
|
6
7
|
function closeClaim(accounts, programId) {
|
|
7
8
|
if (programId === void 0) { programId = programId_1.PROGRAM_ID; }
|
|
@@ -14,7 +15,7 @@ function closeClaim(accounts, programId) {
|
|
|
14
15
|
{ pubkey: accounts.eventAuthority, isSigner: false, isWritable: false },
|
|
15
16
|
{ pubkey: accounts.program, isSigner: false, isWritable: false },
|
|
16
17
|
];
|
|
17
|
-
var identifier = Buffer.from([42, 177, 165, 35, 213, 179, 211, 19]);
|
|
18
|
+
var identifier = buffer_1.Buffer.from([42, 177, 165, 35, 213, 179, 211, 19]);
|
|
18
19
|
var data = identifier;
|
|
19
20
|
var ix = new web3_js_1.TransactionInstruction({ keys: keys, programId: programId, data: data });
|
|
20
21
|
return ix;
|
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.newDistributor = exports.layout = void 0;
|
|
27
27
|
var web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
28
28
|
var borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
29
|
+
var buffer_1 = require("buffer");
|
|
29
30
|
var programId_1 = require("../programId");
|
|
30
31
|
exports.layout = borsh.struct([
|
|
31
32
|
borsh.u64("version"),
|
|
@@ -74,8 +75,8 @@ function newDistributor(args, accounts, programId) {
|
|
|
74
75
|
},
|
|
75
76
|
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
|
|
76
77
|
];
|
|
77
|
-
var identifier = Buffer.from([32, 139, 112, 171, 0, 2, 225, 155]);
|
|
78
|
-
var buffer = Buffer.alloc(1000);
|
|
78
|
+
var identifier = buffer_1.Buffer.from([32, 139, 112, 171, 0, 2, 225, 155]);
|
|
79
|
+
var buffer = buffer_1.Buffer.alloc(1000);
|
|
79
80
|
var len = exports.layout.encode({
|
|
80
81
|
version: args.version,
|
|
81
82
|
root: args.root,
|
|
@@ -87,7 +88,7 @@ function newDistributor(args, accounts, programId) {
|
|
|
87
88
|
clawbackStartTs: args.clawbackStartTs,
|
|
88
89
|
claimsClosable: args.claimsClosable,
|
|
89
90
|
}, buffer);
|
|
90
|
-
var data = Buffer.concat([identifier, buffer]).slice(0, 8 + len);
|
|
91
|
+
var data = buffer_1.Buffer.concat([identifier, buffer]).slice(0, 8 + len);
|
|
91
92
|
var ix = new web3_js_1.TransactionInstruction({ keys: keys, programId: programId, data: data });
|
|
92
93
|
return ix;
|
|
93
94
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setAdmin = void 0;
|
|
4
4
|
var web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
5
|
+
var buffer_1 = require("buffer");
|
|
5
6
|
var programId_1 = require("../programId");
|
|
6
7
|
function setAdmin(accounts, programId) {
|
|
7
8
|
if (programId === void 0) { programId = programId_1.PROGRAM_ID; }
|
|
@@ -10,7 +11,7 @@ function setAdmin(accounts, programId) {
|
|
|
10
11
|
{ pubkey: accounts.admin, isSigner: true, isWritable: true },
|
|
11
12
|
{ pubkey: accounts.newAdmin, isSigner: false, isWritable: true },
|
|
12
13
|
];
|
|
13
|
-
var identifier = Buffer.from([251, 163, 0, 52, 91, 194, 187, 92]);
|
|
14
|
+
var identifier = buffer_1.Buffer.from([251, 163, 0, 52, 91, 194, 187, 92]);
|
|
14
15
|
var data = identifier;
|
|
15
16
|
var ix = new web3_js_1.TransactionInstruction({ keys: keys, programId: programId, data: data });
|
|
16
17
|
return ix;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setClawbackReceiver = void 0;
|
|
4
4
|
var web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
5
|
+
var buffer_1 = require("buffer");
|
|
5
6
|
var programId_1 = require("../programId");
|
|
6
7
|
function setClawbackReceiver(accounts, programId) {
|
|
7
8
|
if (programId === void 0) { programId = programId_1.PROGRAM_ID; }
|
|
@@ -10,7 +11,7 @@ function setClawbackReceiver(accounts, programId) {
|
|
|
10
11
|
{ pubkey: accounts.newClawbackAccount, isSigner: false, isWritable: false },
|
|
11
12
|
{ pubkey: accounts.admin, isSigner: true, isWritable: true },
|
|
12
13
|
];
|
|
13
|
-
var identifier = Buffer.from([153, 217, 34, 20, 19, 29, 229, 75]);
|
|
14
|
+
var identifier = buffer_1.Buffer.from([153, 217, 34, 20, 19, 29, 229, 75]);
|
|
14
15
|
var data = identifier;
|
|
15
16
|
var ix = new web3_js_1.TransactionInstruction({ keys: keys, programId: programId, data: data });
|
|
16
17
|
return ix;
|
|
@@ -37,6 +37,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
exports.calculateAmountWithTransferFees = exports.wrappedSignAndExecuteTransaction = exports.getEventAuthorityPda = exports.getClaimantStatusPda = exports.getDistributorPda = exports.divCeilN = void 0;
|
|
40
|
+
var buffer_1 = require("buffer");
|
|
40
41
|
var web3_js_1 = require("@solana/web3.js");
|
|
41
42
|
var common_1 = require("@streamflow/common");
|
|
42
43
|
var solana_1 = require("@streamflow/common/solana");
|
|
@@ -47,9 +48,9 @@ exports.divCeilN = divCeilN;
|
|
|
47
48
|
function getDistributorPda(programId, mint, version) {
|
|
48
49
|
// Constructing the seed for the PDA
|
|
49
50
|
var seeds = [
|
|
50
|
-
Buffer.from("MerkleDistributor"),
|
|
51
|
+
buffer_1.Buffer.from("MerkleDistributor"),
|
|
51
52
|
mint.toBuffer(),
|
|
52
|
-
Buffer.from(new Uint8Array(new BigUint64Array([BigInt(version)]).buffer)),
|
|
53
|
+
buffer_1.Buffer.from(new Uint8Array(new BigUint64Array([BigInt(version)]).buffer)),
|
|
53
54
|
];
|
|
54
55
|
// Finding the PDA
|
|
55
56
|
return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
@@ -57,14 +58,14 @@ function getDistributorPda(programId, mint, version) {
|
|
|
57
58
|
exports.getDistributorPda = getDistributorPda;
|
|
58
59
|
function getClaimantStatusPda(programId, distributor, claimant) {
|
|
59
60
|
// Constructing the seed for the PDA
|
|
60
|
-
var seeds = [Buffer.from("ClaimStatus"), claimant.toBuffer(), distributor.toBuffer()];
|
|
61
|
+
var seeds = [buffer_1.Buffer.from("ClaimStatus"), claimant.toBuffer(), distributor.toBuffer()];
|
|
61
62
|
// Finding the PDA
|
|
62
63
|
return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
63
64
|
}
|
|
64
65
|
exports.getClaimantStatusPda = getClaimantStatusPda;
|
|
65
66
|
function getEventAuthorityPda(programId) {
|
|
66
67
|
// Constructing the seed for the PDA
|
|
67
|
-
var seeds = [Buffer.from("__event_authority")];
|
|
68
|
+
var seeds = [buffer_1.Buffer.from("__event_authority")];
|
|
68
69
|
// Finding the PDA
|
|
69
70
|
return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
|
|
70
71
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * as StreamflowDistributorSolana from "./solana";
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT, createTransferCheckedInstruction, createTransferCheckedWithFeeInstruction, getTransferFeeConfig, } from "@solana/spl-token";
|
|
3
|
+
import { Connection, PublicKey, SystemProgram, } from "@solana/web3.js";
|
|
4
|
+
import { ICluster } from "@streamflow/common";
|
|
5
|
+
import { ata, checkOrCreateAtaBatch, prepareWrappedAccount, prepareBaseInstructions, prepareTransaction, getMintAndProgram, buildSendThrottler, } from "@streamflow/common/solana";
|
|
6
|
+
import { DISTRIBUTOR_PROGRAM_ID } from "./constants";
|
|
7
|
+
import { claimLocked, clawback, newClaim, newDistributor, } from "./generated/instructions";
|
|
8
|
+
import { ClaimStatus, MerkleDistributor } from "./generated/accounts";
|
|
9
|
+
import { calculateAmountWithTransferFees, getClaimantStatusPda, getDistributorPda, getEventAuthorityPda, wrappedSignAndExecuteTransaction, } from "./utils";
|
|
10
|
+
export default class SolanaDistributorClient {
|
|
11
|
+
connection;
|
|
12
|
+
programId;
|
|
13
|
+
commitment;
|
|
14
|
+
sendThrottler;
|
|
15
|
+
/**
|
|
16
|
+
* Create Stream instance
|
|
17
|
+
*/
|
|
18
|
+
constructor({ clusterUrl, cluster = ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler, }) {
|
|
19
|
+
this.commitment = commitment;
|
|
20
|
+
this.connection = new Connection(clusterUrl, this.commitment);
|
|
21
|
+
this.programId = programId !== "" ? new PublicKey(programId) : new PublicKey(DISTRIBUTOR_PROGRAM_ID[cluster]);
|
|
22
|
+
this.sendThrottler = sendThrottler ?? buildSendThrottler(sendRate);
|
|
23
|
+
}
|
|
24
|
+
getCommitment() {
|
|
25
|
+
return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
26
|
+
}
|
|
27
|
+
async create(data, extParams) {
|
|
28
|
+
const { ixs, distributorPublicKey } = await this.prepareCreateInstructions(data, extParams);
|
|
29
|
+
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
|
|
30
|
+
const signature = await wrappedSignAndExecuteTransaction(this.connection, extParams.invoker, tx, {
|
|
31
|
+
hash,
|
|
32
|
+
context,
|
|
33
|
+
commitment: this.getCommitment(),
|
|
34
|
+
}, { sendThrottler: this.sendThrottler });
|
|
35
|
+
return {
|
|
36
|
+
ixs,
|
|
37
|
+
txId: signature,
|
|
38
|
+
metadataId: distributorPublicKey.toBase58(),
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
async prepareCreateInstructions(data, extParams) {
|
|
42
|
+
if (!extParams.invoker.publicKey) {
|
|
43
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
44
|
+
}
|
|
45
|
+
const ixs = prepareBaseInstructions(this.connection, extParams);
|
|
46
|
+
const mint = extParams.isNative ? NATIVE_MINT : new PublicKey(data.mint);
|
|
47
|
+
const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mint);
|
|
48
|
+
const transferFeeConfig = getTransferFeeConfig(mintAccount);
|
|
49
|
+
const distributorPublicKey = getDistributorPda(this.programId, mint, data.version);
|
|
50
|
+
const tokenVault = await ata(mint, distributorPublicKey, tokenProgramId);
|
|
51
|
+
const senderTokens = await ata(mint, extParams.invoker.publicKey, tokenProgramId);
|
|
52
|
+
const args = {
|
|
53
|
+
version: BigNumber(data.version),
|
|
54
|
+
root: data.root,
|
|
55
|
+
maxTotalClaim: BigNumber(data.maxTotalClaim),
|
|
56
|
+
maxNumNodes: BigNumber(data.maxNumNodes),
|
|
57
|
+
unlockPeriod: BigNumber(data.unlockPeriod),
|
|
58
|
+
startVestingTs: BigNumber(data.startVestingTs),
|
|
59
|
+
endVestingTs: BigNumber(data.endVestingTs),
|
|
60
|
+
clawbackStartTs: BigNumber(data.clawbackStartTs),
|
|
61
|
+
claimsClosable: data.claimsClosable,
|
|
62
|
+
};
|
|
63
|
+
const accounts = {
|
|
64
|
+
distributor: distributorPublicKey,
|
|
65
|
+
clawbackReceiver: senderTokens,
|
|
66
|
+
mint,
|
|
67
|
+
tokenVault,
|
|
68
|
+
admin: extParams.invoker.publicKey,
|
|
69
|
+
systemProgram: SystemProgram.programId,
|
|
70
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
71
|
+
tokenProgram: tokenProgramId,
|
|
72
|
+
};
|
|
73
|
+
if (extParams.isNative) {
|
|
74
|
+
ixs.push(...(await prepareWrappedAccount(this.connection, extParams.invoker.publicKey, BigNumber(data.maxTotalClaim))));
|
|
75
|
+
}
|
|
76
|
+
const nowTs = BigNumber(Math.floor(Date.now() / 1000));
|
|
77
|
+
const endVestingTs = args.endVestingTs.isZero() ? nowTs : args.endVestingTs;
|
|
78
|
+
const startVestingTs = args.startVestingTs.isZero() ? nowTs : args.startVestingTs;
|
|
79
|
+
if (endVestingTs.gt(startVestingTs) && endVestingTs.minus(startVestingTs).lt(args.unlockPeriod)) {
|
|
80
|
+
throw new Error("The unlock period cannot be longer than the total vesting duration!");
|
|
81
|
+
}
|
|
82
|
+
ixs.push(newDistributor(args, accounts, this.programId));
|
|
83
|
+
if (transferFeeConfig) {
|
|
84
|
+
const { transferAmount, feeCharged } = await calculateAmountWithTransferFees(this.connection, transferFeeConfig, BigInt(data.maxTotalClaim.toString()));
|
|
85
|
+
ixs.push(createTransferCheckedWithFeeInstruction(senderTokens, mint, tokenVault, extParams.invoker.publicKey, transferAmount, mintAccount.decimals, feeCharged, undefined, tokenProgramId));
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
ixs.push(createTransferCheckedInstruction(senderTokens, mint, tokenVault, extParams.invoker.publicKey, BigInt(data.maxTotalClaim.toString()), mintAccount.decimals, undefined, tokenProgramId));
|
|
89
|
+
}
|
|
90
|
+
return { distributorPublicKey, ixs };
|
|
91
|
+
}
|
|
92
|
+
async claim(data, extParams) {
|
|
93
|
+
const ixs = await this.prepareClaimInstructions(data, extParams);
|
|
94
|
+
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
|
|
95
|
+
const signature = await wrappedSignAndExecuteTransaction(this.connection, extParams.invoker, tx, {
|
|
96
|
+
hash,
|
|
97
|
+
context,
|
|
98
|
+
commitment: this.getCommitment(),
|
|
99
|
+
}, { sendThrottler: this.sendThrottler });
|
|
100
|
+
return { ixs, txId: signature };
|
|
101
|
+
}
|
|
102
|
+
async prepareClaimInstructions(data, extParams) {
|
|
103
|
+
if (!extParams.invoker.publicKey) {
|
|
104
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
105
|
+
}
|
|
106
|
+
const distributorPublicKey = new PublicKey(data.id);
|
|
107
|
+
const distributor = await MerkleDistributor.fetch(this.connection, distributorPublicKey);
|
|
108
|
+
if (!distributor) {
|
|
109
|
+
throw new Error("Couldn't get account info");
|
|
110
|
+
}
|
|
111
|
+
const { tokenProgramId } = await getMintAndProgram(this.connection, distributor.mint);
|
|
112
|
+
const ixs = prepareBaseInstructions(this.connection, extParams);
|
|
113
|
+
ixs.push(...(await checkOrCreateAtaBatch(this.connection, [extParams.invoker.publicKey], distributor.mint, extParams.invoker, tokenProgramId)));
|
|
114
|
+
const invokerTokens = await ata(distributor.mint, extParams.invoker.publicKey, tokenProgramId);
|
|
115
|
+
const claimStatusPublicKey = getClaimantStatusPda(this.programId, distributorPublicKey, extParams.invoker.publicKey);
|
|
116
|
+
const eventAuthorityPublicKey = getEventAuthorityPda(this.programId);
|
|
117
|
+
const claimStatus = await ClaimStatus.fetch(this.connection, claimStatusPublicKey);
|
|
118
|
+
const accounts = {
|
|
119
|
+
distributor: distributorPublicKey,
|
|
120
|
+
claimStatus: claimStatusPublicKey,
|
|
121
|
+
from: distributor.tokenVault,
|
|
122
|
+
to: invokerTokens,
|
|
123
|
+
claimant: extParams.invoker.publicKey,
|
|
124
|
+
mint: distributor.mint,
|
|
125
|
+
tokenProgram: tokenProgramId,
|
|
126
|
+
systemProgram: SystemProgram.programId,
|
|
127
|
+
eventAuthority: eventAuthorityPublicKey,
|
|
128
|
+
program: this.programId,
|
|
129
|
+
};
|
|
130
|
+
if (!claimStatus) {
|
|
131
|
+
const args = {
|
|
132
|
+
amountLocked: BigNumber(data.amountLocked),
|
|
133
|
+
amountUnlocked: BigNumber(data.amountUnlocked),
|
|
134
|
+
proof: data.proof,
|
|
135
|
+
};
|
|
136
|
+
ixs.push(newClaim(args, accounts, this.programId));
|
|
137
|
+
}
|
|
138
|
+
const nowTs = BigNumber(Math.floor(Date.now() / 1000));
|
|
139
|
+
if (claimStatus ||
|
|
140
|
+
(BigNumber(data.amountLocked).gt(0) && nowTs.minus(distributor.startTs).gte(distributor.unlockPeriod))) {
|
|
141
|
+
ixs.push(claimLocked(accounts, this.programId));
|
|
142
|
+
}
|
|
143
|
+
return ixs;
|
|
144
|
+
}
|
|
145
|
+
async clawback(data, extParams) {
|
|
146
|
+
const ixs = await this.prepareClawbackInstructions(data, extParams);
|
|
147
|
+
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
|
|
148
|
+
const signature = await wrappedSignAndExecuteTransaction(this.connection, extParams.invoker, tx, {
|
|
149
|
+
hash,
|
|
150
|
+
context,
|
|
151
|
+
commitment: this.getCommitment(),
|
|
152
|
+
}, { sendThrottler: this.sendThrottler });
|
|
153
|
+
return { ixs, txId: signature };
|
|
154
|
+
}
|
|
155
|
+
async prepareClawbackInstructions(data, extParams) {
|
|
156
|
+
if (!extParams.invoker.publicKey) {
|
|
157
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
158
|
+
}
|
|
159
|
+
const distributorPublicKey = new PublicKey(data.id);
|
|
160
|
+
const distributor = await MerkleDistributor.fetch(this.connection, distributorPublicKey);
|
|
161
|
+
if (!distributor) {
|
|
162
|
+
throw new Error("Couldn't get account info");
|
|
163
|
+
}
|
|
164
|
+
const { tokenProgramId } = await getMintAndProgram(this.connection, distributor.mint);
|
|
165
|
+
const ixs = prepareBaseInstructions(this.connection, extParams);
|
|
166
|
+
ixs.push(...(await checkOrCreateAtaBatch(this.connection, [extParams.invoker.publicKey], distributor.mint, extParams.invoker, tokenProgramId)));
|
|
167
|
+
const accounts = {
|
|
168
|
+
distributor: distributorPublicKey,
|
|
169
|
+
from: distributor.tokenVault,
|
|
170
|
+
to: distributor.clawbackReceiver,
|
|
171
|
+
admin: extParams.invoker.publicKey,
|
|
172
|
+
mint: distributor.mint,
|
|
173
|
+
systemProgram: SystemProgram.programId,
|
|
174
|
+
tokenProgram: tokenProgramId,
|
|
175
|
+
};
|
|
176
|
+
ixs.push(clawback(accounts, this.programId));
|
|
177
|
+
return ixs;
|
|
178
|
+
}
|
|
179
|
+
async getClaims(data) {
|
|
180
|
+
const claimStatusPublicKeys = data.map(({ id, recipient }) => {
|
|
181
|
+
return getClaimantStatusPda(this.programId, new PublicKey(id), new PublicKey(recipient));
|
|
182
|
+
});
|
|
183
|
+
return ClaimStatus.fetchMultiple(this.connection, claimStatusPublicKeys, this.programId);
|
|
184
|
+
}
|
|
185
|
+
async getDistributors(data) {
|
|
186
|
+
const distributorPublicKeys = data.ids.map((distributorId) => new PublicKey(distributorId));
|
|
187
|
+
return MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ICluster } from "@streamflow/common";
|
|
2
|
+
export const ONE_IN_BASIS_POINTS = BigInt(10000);
|
|
3
|
+
export const DISTRIBUTOR_PROGRAM_ID = {
|
|
4
|
+
[ICluster.Devnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
5
|
+
[ICluster.Mainnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
6
|
+
[ICluster.Testnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
7
|
+
[ICluster.Local]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
8
|
+
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { PublicKey, Connection } from "@solana/web3.js";
|
|
3
|
-
import
|
|
3
|
+
import BigNumber from "bignumber.js";
|
|
4
4
|
export interface ClaimStatusFields {
|
|
5
5
|
/** Authority that claimed the tokens. */
|
|
6
6
|
claimant: PublicKey;
|
|
7
7
|
/** Locked amount */
|
|
8
|
-
lockedAmount:
|
|
8
|
+
lockedAmount: BigNumber;
|
|
9
9
|
/** Locked amount withdrawn */
|
|
10
|
-
lockedAmountWithdrawn:
|
|
10
|
+
lockedAmountWithdrawn: BigNumber;
|
|
11
11
|
/** Unlocked amount */
|
|
12
|
-
unlockedAmount:
|
|
12
|
+
unlockedAmount: BigNumber;
|
|
13
13
|
/** Last claim time */
|
|
14
|
-
lastClaimTs:
|
|
14
|
+
lastClaimTs: BigNumber;
|
|
15
15
|
/** Track amount per unlock, can be useful for non-linear vesting */
|
|
16
|
-
lastAmountPerUnlock:
|
|
16
|
+
lastAmountPerUnlock: BigNumber;
|
|
17
17
|
/** Whether claim is closed */
|
|
18
18
|
closed: boolean;
|
|
19
19
|
/** Buffer for additional fields */
|
|
@@ -46,15 +46,15 @@ export declare class ClaimStatus {
|
|
|
46
46
|
/** Authority that claimed the tokens. */
|
|
47
47
|
readonly claimant: PublicKey;
|
|
48
48
|
/** Locked amount */
|
|
49
|
-
readonly lockedAmount:
|
|
49
|
+
readonly lockedAmount: BigNumber;
|
|
50
50
|
/** Locked amount withdrawn */
|
|
51
|
-
readonly lockedAmountWithdrawn:
|
|
51
|
+
readonly lockedAmountWithdrawn: BigNumber;
|
|
52
52
|
/** Unlocked amount */
|
|
53
|
-
readonly unlockedAmount:
|
|
53
|
+
readonly unlockedAmount: BigNumber;
|
|
54
54
|
/** Last claim time */
|
|
55
|
-
readonly lastClaimTs:
|
|
55
|
+
readonly lastClaimTs: BigNumber;
|
|
56
56
|
/** Track amount per unlock, can be useful for non-linear vesting */
|
|
57
|
-
readonly lastAmountPerUnlock:
|
|
57
|
+
readonly lastAmountPerUnlock: BigNumber;
|
|
58
58
|
/** Whether claim is closed */
|
|
59
59
|
readonly closed: boolean;
|
|
60
60
|
/** Buffer for additional fields */
|