@streamflow/distributor 7.0.0-alpha.3 → 7.0.0-alpha.5
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/dist/cjs/solana/client.js +176 -350
- package/dist/cjs/solana/constants.js +7 -8
- package/dist/cjs/solana/generated/accounts/ClaimStatus.js +47 -105
- package/dist/cjs/solana/generated/accounts/MerkleDistributor.js +58 -116
- package/dist/cjs/solana/generated/errors/anchor.js +540 -717
- package/dist/cjs/solana/generated/errors/custom.js +171 -243
- package/dist/cjs/solana/generated/errors/index.js +12 -51
- package/dist/cjs/solana/generated/instructions/claimLocked.js +7 -8
- package/dist/cjs/solana/generated/instructions/clawback.js +8 -9
- package/dist/cjs/solana/generated/instructions/closeClaim.js +8 -9
- package/dist/cjs/solana/generated/instructions/newClaim.js +10 -11
- package/dist/cjs/solana/generated/instructions/newDistributor.js +11 -12
- package/dist/cjs/solana/generated/instructions/setAdmin.js +8 -9
- package/dist/cjs/solana/generated/instructions/setClawbackReceiver.js +8 -9
- package/dist/cjs/solana/generated/programId.js +1 -1
- package/dist/cjs/solana/utils.js +38 -92
- package/package.json +4 -4
|
@@ -1,365 +1,191 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
-
if (!m) return o;
|
|
41
|
-
var i = m.call(o), r, ar = [], e;
|
|
42
|
-
try {
|
|
43
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
-
}
|
|
45
|
-
catch (error) { e = { error: error }; }
|
|
46
|
-
finally {
|
|
47
|
-
try {
|
|
48
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
-
}
|
|
50
|
-
finally { if (e) throw e.error; }
|
|
51
|
-
}
|
|
52
|
-
return ar;
|
|
53
|
-
};
|
|
54
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
55
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
56
|
-
if (ar || !(i in from)) {
|
|
57
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
58
|
-
ar[i] = from[i];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
62
|
-
};
|
|
63
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
64
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
65
4
|
};
|
|
66
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
6
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
7
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
8
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
9
|
+
const common_1 = require("@streamflow/common");
|
|
10
|
+
const solana_1 = require("@streamflow/common/solana");
|
|
11
|
+
const constants_1 = require("./constants");
|
|
12
|
+
const instructions_1 = require("./generated/instructions");
|
|
13
|
+
const accounts_1 = require("./generated/accounts");
|
|
14
|
+
const utils_1 = require("./utils");
|
|
15
|
+
class SolanaDistributorClient {
|
|
77
16
|
/**
|
|
78
17
|
* Create Stream instance
|
|
79
18
|
*/
|
|
80
|
-
|
|
81
|
-
var clusterUrl = _a.clusterUrl, _b = _a.cluster, cluster = _b === void 0 ? common_1.ICluster.Mainnet : _b, _c = _a.commitment, commitment = _c === void 0 ? "confirmed" : _c, _d = _a.programId, programId = _d === void 0 ? "" : _d, _e = _a.sendRate, sendRate = _e === void 0 ? 1 : _e, sendThrottler = _a.sendThrottler;
|
|
19
|
+
constructor({ clusterUrl, cluster = common_1.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler, }) {
|
|
82
20
|
this.commitment = commitment;
|
|
83
21
|
this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
|
|
84
22
|
this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_1.DISTRIBUTOR_PROGRAM_ID[cluster]);
|
|
85
|
-
this.sendThrottler = sendThrottler
|
|
23
|
+
this.sendThrottler = sendThrottler ?? (0, solana_1.buildSendThrottler)(sendRate);
|
|
86
24
|
}
|
|
87
|
-
|
|
25
|
+
getCommitment() {
|
|
88
26
|
return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
case 5:
|
|
246
|
-
claimStatus = _e.sent();
|
|
247
|
-
accounts = {
|
|
248
|
-
distributor: distributorPublicKey,
|
|
249
|
-
claimStatus: claimStatusPublicKey,
|
|
250
|
-
from: distributor.tokenVault,
|
|
251
|
-
to: invokerTokens,
|
|
252
|
-
claimant: extParams.invoker.publicKey,
|
|
253
|
-
mint: distributor.mint,
|
|
254
|
-
tokenProgram: tokenProgramId,
|
|
255
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
256
|
-
eventAuthority: eventAuthorityPublicKey,
|
|
257
|
-
program: this.programId,
|
|
258
|
-
};
|
|
259
|
-
if (!claimStatus) {
|
|
260
|
-
args = {
|
|
261
|
-
amountLocked: (0, bignumber_js_1.default)(data.amountLocked),
|
|
262
|
-
amountUnlocked: (0, bignumber_js_1.default)(data.amountUnlocked),
|
|
263
|
-
proof: data.proof,
|
|
264
|
-
};
|
|
265
|
-
ixs.push((0, instructions_1.newClaim)(args, accounts, this.programId));
|
|
266
|
-
}
|
|
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))) {
|
|
270
|
-
ixs.push((0, instructions_1.claimLocked)(accounts, this.programId));
|
|
271
|
-
}
|
|
272
|
-
return [2 /*return*/, ixs];
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
};
|
|
277
|
-
SolanaDistributorClient.prototype.clawback = function (data, extParams) {
|
|
278
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
279
|
-
var ixs, _a, tx, hash, context, signature;
|
|
280
|
-
return __generator(this, function (_b) {
|
|
281
|
-
switch (_b.label) {
|
|
282
|
-
case 0: return [4 /*yield*/, this.prepareClawbackInstructions(data, extParams)];
|
|
283
|
-
case 1:
|
|
284
|
-
ixs = _b.sent();
|
|
285
|
-
return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
|
|
286
|
-
case 2:
|
|
287
|
-
_a = _b.sent(), tx = _a.tx, hash = _a.hash, context = _a.context;
|
|
288
|
-
return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
289
|
-
hash: hash,
|
|
290
|
-
context: context,
|
|
291
|
-
commitment: this.getCommitment(),
|
|
292
|
-
}, { sendThrottler: this.sendThrottler })];
|
|
293
|
-
case 3:
|
|
294
|
-
signature = _b.sent();
|
|
295
|
-
return [2 /*return*/, { ixs: ixs, txId: signature }];
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
});
|
|
299
|
-
};
|
|
300
|
-
SolanaDistributorClient.prototype.prepareClawbackInstructions = function (data, extParams) {
|
|
301
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
302
|
-
var distributorPublicKey, distributor, tokenProgramId, ixs, _a, _b, _c, _d, accounts;
|
|
303
|
-
return __generator(this, function (_e) {
|
|
304
|
-
switch (_e.label) {
|
|
305
|
-
case 0:
|
|
306
|
-
if (!extParams.invoker.publicKey) {
|
|
307
|
-
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
308
|
-
}
|
|
309
|
-
distributorPublicKey = new web3_js_1.PublicKey(data.id);
|
|
310
|
-
return [4 /*yield*/, accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey)];
|
|
311
|
-
case 1:
|
|
312
|
-
distributor = _e.sent();
|
|
313
|
-
if (!distributor) {
|
|
314
|
-
throw new Error("Couldn't get account info");
|
|
315
|
-
}
|
|
316
|
-
return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, distributor.mint)];
|
|
317
|
-
case 2:
|
|
318
|
-
tokenProgramId = (_e.sent()).tokenProgramId;
|
|
319
|
-
ixs = (0, solana_1.prepareBaseInstructions)(this.connection, extParams);
|
|
320
|
-
_b = (_a = ixs.push).apply;
|
|
321
|
-
_c = [ixs];
|
|
322
|
-
_d = [[]];
|
|
323
|
-
return [4 /*yield*/, (0, solana_1.checkOrCreateAtaBatch)(this.connection, [extParams.invoker.publicKey], distributor.mint, extParams.invoker, tokenProgramId)];
|
|
324
|
-
case 3:
|
|
325
|
-
_b.apply(_a, _c.concat([__spreadArray.apply(void 0, _d.concat([__read.apply(void 0, [(_e.sent())]), false]))]));
|
|
326
|
-
accounts = {
|
|
327
|
-
distributor: distributorPublicKey,
|
|
328
|
-
from: distributor.tokenVault,
|
|
329
|
-
to: distributor.clawbackReceiver,
|
|
330
|
-
admin: extParams.invoker.publicKey,
|
|
331
|
-
mint: distributor.mint,
|
|
332
|
-
systemProgram: web3_js_1.SystemProgram.programId,
|
|
333
|
-
tokenProgram: tokenProgramId,
|
|
334
|
-
};
|
|
335
|
-
ixs.push((0, instructions_1.clawback)(accounts, this.programId));
|
|
336
|
-
return [2 /*return*/, ixs];
|
|
337
|
-
}
|
|
338
|
-
});
|
|
339
|
-
});
|
|
340
|
-
};
|
|
341
|
-
SolanaDistributorClient.prototype.getClaims = function (data) {
|
|
342
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
343
|
-
var claimStatusPublicKeys;
|
|
344
|
-
var _this = this;
|
|
345
|
-
return __generator(this, function (_a) {
|
|
346
|
-
claimStatusPublicKeys = data.map(function (_a) {
|
|
347
|
-
var id = _a.id, recipient = _a.recipient;
|
|
348
|
-
return (0, utils_1.getClaimantStatusPda)(_this.programId, new web3_js_1.PublicKey(id), new web3_js_1.PublicKey(recipient));
|
|
349
|
-
});
|
|
350
|
-
return [2 /*return*/, accounts_1.ClaimStatus.fetchMultiple(this.connection, claimStatusPublicKeys, this.programId)];
|
|
351
|
-
});
|
|
352
|
-
});
|
|
353
|
-
};
|
|
354
|
-
SolanaDistributorClient.prototype.getDistributors = function (data) {
|
|
355
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
356
|
-
var distributorPublicKeys;
|
|
357
|
-
return __generator(this, function (_a) {
|
|
358
|
-
distributorPublicKeys = data.ids.map(function (distributorId) { return new web3_js_1.PublicKey(distributorId); });
|
|
359
|
-
return [2 /*return*/, accounts_1.MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId)];
|
|
360
|
-
});
|
|
27
|
+
}
|
|
28
|
+
async create(data, extParams) {
|
|
29
|
+
const { ixs, distributorPublicKey } = await this.prepareCreateInstructions(data, extParams);
|
|
30
|
+
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
|
|
31
|
+
const signature = await (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
32
|
+
hash,
|
|
33
|
+
context,
|
|
34
|
+
commitment: this.getCommitment(),
|
|
35
|
+
}, { sendThrottler: this.sendThrottler });
|
|
36
|
+
return {
|
|
37
|
+
ixs,
|
|
38
|
+
txId: signature,
|
|
39
|
+
metadataId: distributorPublicKey.toBase58(),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async prepareCreateInstructions(data, extParams) {
|
|
43
|
+
if (!extParams.invoker.publicKey) {
|
|
44
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
45
|
+
}
|
|
46
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, extParams);
|
|
47
|
+
const mint = extParams.isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(data.mint);
|
|
48
|
+
const { mint: mintAccount, tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mint);
|
|
49
|
+
const transferFeeConfig = (0, spl_token_1.getTransferFeeConfig)(mintAccount);
|
|
50
|
+
const distributorPublicKey = (0, utils_1.getDistributorPda)(this.programId, mint, data.version);
|
|
51
|
+
const tokenVault = await (0, solana_1.ata)(mint, distributorPublicKey, tokenProgramId);
|
|
52
|
+
const senderTokens = await (0, solana_1.ata)(mint, extParams.invoker.publicKey, tokenProgramId);
|
|
53
|
+
const args = {
|
|
54
|
+
version: (0, bignumber_js_1.default)(data.version),
|
|
55
|
+
root: data.root,
|
|
56
|
+
maxTotalClaim: (0, bignumber_js_1.default)(data.maxTotalClaim),
|
|
57
|
+
maxNumNodes: (0, bignumber_js_1.default)(data.maxNumNodes),
|
|
58
|
+
unlockPeriod: (0, bignumber_js_1.default)(data.unlockPeriod),
|
|
59
|
+
startVestingTs: (0, bignumber_js_1.default)(data.startVestingTs),
|
|
60
|
+
endVestingTs: (0, bignumber_js_1.default)(data.endVestingTs),
|
|
61
|
+
clawbackStartTs: (0, bignumber_js_1.default)(data.clawbackStartTs),
|
|
62
|
+
claimsClosable: data.claimsClosable,
|
|
63
|
+
};
|
|
64
|
+
const accounts = {
|
|
65
|
+
distributor: distributorPublicKey,
|
|
66
|
+
clawbackReceiver: senderTokens,
|
|
67
|
+
mint,
|
|
68
|
+
tokenVault,
|
|
69
|
+
admin: extParams.invoker.publicKey,
|
|
70
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
71
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
72
|
+
tokenProgram: tokenProgramId,
|
|
73
|
+
};
|
|
74
|
+
if (extParams.isNative) {
|
|
75
|
+
ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, extParams.invoker.publicKey, (0, bignumber_js_1.default)(data.maxTotalClaim))));
|
|
76
|
+
}
|
|
77
|
+
const nowTs = (0, bignumber_js_1.default)(Math.floor(Date.now() / 1000));
|
|
78
|
+
const endVestingTs = args.endVestingTs.isZero() ? nowTs : args.endVestingTs;
|
|
79
|
+
const startVestingTs = args.startVestingTs.isZero() ? nowTs : args.startVestingTs;
|
|
80
|
+
if (endVestingTs.gt(startVestingTs) && endVestingTs.minus(startVestingTs).lt(args.unlockPeriod)) {
|
|
81
|
+
throw new Error("The unlock period cannot be longer than the total vesting duration!");
|
|
82
|
+
}
|
|
83
|
+
ixs.push((0, instructions_1.newDistributor)(args, accounts, this.programId));
|
|
84
|
+
if (transferFeeConfig) {
|
|
85
|
+
const { transferAmount, feeCharged } = await (0, utils_1.calculateAmountWithTransferFees)(this.connection, transferFeeConfig, BigInt(data.maxTotalClaim.toString()));
|
|
86
|
+
ixs.push((0, spl_token_1.createTransferCheckedWithFeeInstruction)(senderTokens, mint, tokenVault, extParams.invoker.publicKey, transferAmount, mintAccount.decimals, feeCharged, undefined, tokenProgramId));
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
ixs.push((0, spl_token_1.createTransferCheckedInstruction)(senderTokens, mint, tokenVault, extParams.invoker.publicKey, BigInt(data.maxTotalClaim.toString()), mintAccount.decimals, undefined, tokenProgramId));
|
|
90
|
+
}
|
|
91
|
+
return { distributorPublicKey, ixs };
|
|
92
|
+
}
|
|
93
|
+
async claim(data, extParams) {
|
|
94
|
+
const ixs = await this.prepareClaimInstructions(data, extParams);
|
|
95
|
+
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
|
|
96
|
+
const signature = await (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
97
|
+
hash,
|
|
98
|
+
context,
|
|
99
|
+
commitment: this.getCommitment(),
|
|
100
|
+
}, { sendThrottler: this.sendThrottler });
|
|
101
|
+
return { ixs, txId: signature };
|
|
102
|
+
}
|
|
103
|
+
async prepareClaimInstructions(data, extParams) {
|
|
104
|
+
if (!extParams.invoker.publicKey) {
|
|
105
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
106
|
+
}
|
|
107
|
+
const distributorPublicKey = new web3_js_1.PublicKey(data.id);
|
|
108
|
+
const distributor = await accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey);
|
|
109
|
+
if (!distributor) {
|
|
110
|
+
throw new Error("Couldn't get account info");
|
|
111
|
+
}
|
|
112
|
+
const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, distributor.mint);
|
|
113
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, extParams);
|
|
114
|
+
ixs.push(...(await (0, solana_1.checkOrCreateAtaBatch)(this.connection, [extParams.invoker.publicKey], distributor.mint, extParams.invoker, tokenProgramId)));
|
|
115
|
+
const invokerTokens = await (0, solana_1.ata)(distributor.mint, extParams.invoker.publicKey, tokenProgramId);
|
|
116
|
+
const claimStatusPublicKey = (0, utils_1.getClaimantStatusPda)(this.programId, distributorPublicKey, extParams.invoker.publicKey);
|
|
117
|
+
const eventAuthorityPublicKey = (0, utils_1.getEventAuthorityPda)(this.programId);
|
|
118
|
+
const claimStatus = await accounts_1.ClaimStatus.fetch(this.connection, claimStatusPublicKey);
|
|
119
|
+
const accounts = {
|
|
120
|
+
distributor: distributorPublicKey,
|
|
121
|
+
claimStatus: claimStatusPublicKey,
|
|
122
|
+
from: distributor.tokenVault,
|
|
123
|
+
to: invokerTokens,
|
|
124
|
+
claimant: extParams.invoker.publicKey,
|
|
125
|
+
mint: distributor.mint,
|
|
126
|
+
tokenProgram: tokenProgramId,
|
|
127
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
128
|
+
eventAuthority: eventAuthorityPublicKey,
|
|
129
|
+
program: this.programId,
|
|
130
|
+
};
|
|
131
|
+
if (!claimStatus) {
|
|
132
|
+
const args = {
|
|
133
|
+
amountLocked: (0, bignumber_js_1.default)(data.amountLocked),
|
|
134
|
+
amountUnlocked: (0, bignumber_js_1.default)(data.amountUnlocked),
|
|
135
|
+
proof: data.proof,
|
|
136
|
+
};
|
|
137
|
+
ixs.push((0, instructions_1.newClaim)(args, accounts, this.programId));
|
|
138
|
+
}
|
|
139
|
+
const nowTs = (0, bignumber_js_1.default)(Math.floor(Date.now() / 1000));
|
|
140
|
+
if (claimStatus ||
|
|
141
|
+
((0, bignumber_js_1.default)(data.amountLocked).gt(0) && nowTs.minus(distributor.startTs).gte(distributor.unlockPeriod))) {
|
|
142
|
+
ixs.push((0, instructions_1.claimLocked)(accounts, this.programId));
|
|
143
|
+
}
|
|
144
|
+
return ixs;
|
|
145
|
+
}
|
|
146
|
+
async clawback(data, extParams) {
|
|
147
|
+
const ixs = await this.prepareClawbackInstructions(data, extParams);
|
|
148
|
+
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
|
|
149
|
+
const signature = await (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
|
|
150
|
+
hash,
|
|
151
|
+
context,
|
|
152
|
+
commitment: this.getCommitment(),
|
|
153
|
+
}, { sendThrottler: this.sendThrottler });
|
|
154
|
+
return { ixs, txId: signature };
|
|
155
|
+
}
|
|
156
|
+
async prepareClawbackInstructions(data, extParams) {
|
|
157
|
+
if (!extParams.invoker.publicKey) {
|
|
158
|
+
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
159
|
+
}
|
|
160
|
+
const distributorPublicKey = new web3_js_1.PublicKey(data.id);
|
|
161
|
+
const distributor = await accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey);
|
|
162
|
+
if (!distributor) {
|
|
163
|
+
throw new Error("Couldn't get account info");
|
|
164
|
+
}
|
|
165
|
+
const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, distributor.mint);
|
|
166
|
+
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, extParams);
|
|
167
|
+
ixs.push(...(await (0, solana_1.checkOrCreateAtaBatch)(this.connection, [extParams.invoker.publicKey], distributor.mint, extParams.invoker, tokenProgramId)));
|
|
168
|
+
const accounts = {
|
|
169
|
+
distributor: distributorPublicKey,
|
|
170
|
+
from: distributor.tokenVault,
|
|
171
|
+
to: distributor.clawbackReceiver,
|
|
172
|
+
admin: extParams.invoker.publicKey,
|
|
173
|
+
mint: distributor.mint,
|
|
174
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
175
|
+
tokenProgram: tokenProgramId,
|
|
176
|
+
};
|
|
177
|
+
ixs.push((0, instructions_1.clawback)(accounts, this.programId));
|
|
178
|
+
return ixs;
|
|
179
|
+
}
|
|
180
|
+
async getClaims(data) {
|
|
181
|
+
const claimStatusPublicKeys = data.map(({ id, recipient }) => {
|
|
182
|
+
return (0, utils_1.getClaimantStatusPda)(this.programId, new web3_js_1.PublicKey(id), new web3_js_1.PublicKey(recipient));
|
|
361
183
|
});
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
184
|
+
return accounts_1.ClaimStatus.fetchMultiple(this.connection, claimStatusPublicKeys, this.programId);
|
|
185
|
+
}
|
|
186
|
+
async getDistributors(data) {
|
|
187
|
+
const distributorPublicKeys = data.ids.map((distributorId) => new web3_js_1.PublicKey(distributorId));
|
|
188
|
+
return accounts_1.MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
365
191
|
exports.default = SolanaDistributorClient;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.DISTRIBUTOR_PROGRAM_ID = exports.ONE_IN_BASIS_POINTS = void 0;
|
|
5
|
-
|
|
4
|
+
const common_1 = require("@streamflow/common");
|
|
6
5
|
exports.ONE_IN_BASIS_POINTS = BigInt(10000);
|
|
7
|
-
exports.DISTRIBUTOR_PROGRAM_ID =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
exports.DISTRIBUTOR_PROGRAM_ID = {
|
|
7
|
+
[common_1.ICluster.Devnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
8
|
+
[common_1.ICluster.Mainnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
9
|
+
[common_1.ICluster.Testnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
10
|
+
[common_1.ICluster.Local]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
11
|
+
};
|