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