@streamflow/distributor 6.3.4 → 6.3.6

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.
@@ -1,5 +1,5 @@
1
1
  import PQueue from "p-queue";
2
- import { Commitment, ConnectionConfig } from "@solana/web3.js";
2
+ import { PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
3
3
  import { ICluster, ITransactionResult } from "@streamflow/common";
4
4
  import { IClaimData, IClawbackData, ICreateDistributorData, ICreateDistributorResult, IGetClaimData, IGetDistributors, ICreateSolanaExt, IInteractSolanaExt } from "./types";
5
5
  import { ClaimStatus, MerkleDistributor } from "./generated/accounts";
@@ -22,8 +22,14 @@ export default class SolanaDistributorClient {
22
22
  constructor({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler, }: IInitOptions);
23
23
  getCommitment(): Commitment | undefined;
24
24
  create(data: ICreateDistributorData, extParams: ICreateSolanaExt): Promise<ICreateDistributorResult>;
25
+ prepareCreateInstructions(data: ICreateDistributorData, extParams: ICreateSolanaExt): Promise<{
26
+ distributorPublicKey: PublicKey;
27
+ ixs: TransactionInstruction[];
28
+ }>;
25
29
  claim(data: IClaimData, extParams: IInteractSolanaExt): Promise<ITransactionResult>;
30
+ prepareClaimInstructions(data: IClaimData, extParams: IInteractSolanaExt): Promise<TransactionInstruction[]>;
26
31
  clawback(data: IClawbackData, extParams: IInteractSolanaExt): Promise<ITransactionResult>;
32
+ prepareClawbackInstructions(data: IClawbackData, extParams: IInteractSolanaExt): Promise<TransactionInstruction[]>;
27
33
  getClaims(data: IGetClaimData[]): Promise<(ClaimStatus | null)[]>;
28
34
  getDistributors(data: IGetDistributors): Promise<(MerkleDistributor | null)[]>;
29
35
  }
@@ -89,9 +89,36 @@ var SolanaDistributorClient = /** @class */ (function () {
89
89
  };
90
90
  SolanaDistributorClient.prototype.create = function (data, extParams) {
91
91
  return __awaiter(this, void 0, void 0, function () {
92
- var ixs, mint, _a, mintAccount, tokenProgramId, distributorPublicKey, tokenVault, senderTokens, args, accounts, _b, _c, _d, _e, nowTs, endVestingTs, startVestingTs, _f, tx, hash, context, signature;
93
- return __generator(this, function (_g) {
94
- switch (_g.label) {
92
+ var _a, ixs, distributorPublicKey, _b, tx, hash, context, signature;
93
+ return __generator(this, function (_c) {
94
+ switch (_c.label) {
95
+ case 0: return [4 /*yield*/, this.prepareCreateInstructions(data, extParams)];
96
+ case 1:
97
+ _a = _c.sent(), ixs = _a.ixs, distributorPublicKey = _a.distributorPublicKey;
98
+ return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
99
+ case 2:
100
+ _b = _c.sent(), tx = _b.tx, hash = _b.hash, context = _b.context;
101
+ return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
102
+ hash: hash,
103
+ context: context,
104
+ commitment: this.getCommitment(),
105
+ }, { sendThrottler: this.sendThrottler })];
106
+ case 3:
107
+ signature = _c.sent();
108
+ return [2 /*return*/, {
109
+ ixs: ixs,
110
+ txId: signature,
111
+ metadataId: distributorPublicKey.toBase58(),
112
+ }];
113
+ }
114
+ });
115
+ });
116
+ };
117
+ SolanaDistributorClient.prototype.prepareCreateInstructions = function (data, extParams) {
118
+ return __awaiter(this, void 0, void 0, function () {
119
+ var ixs, mint, _a, mintAccount, tokenProgramId, distributorPublicKey, tokenVault, senderTokens, args, accounts, _b, _c, _d, _e, nowTs, endVestingTs, startVestingTs;
120
+ return __generator(this, function (_f) {
121
+ switch (_f.label) {
95
122
  case 0:
96
123
  if (!extParams.invoker.publicKey) {
97
124
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
@@ -100,14 +127,14 @@ var SolanaDistributorClient = /** @class */ (function () {
100
127
  mint = extParams.isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(data.mint);
101
128
  return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, mint)];
102
129
  case 1:
103
- _a = _g.sent(), mintAccount = _a.mint, tokenProgramId = _a.tokenProgramId;
130
+ _a = _f.sent(), mintAccount = _a.mint, tokenProgramId = _a.tokenProgramId;
104
131
  distributorPublicKey = (0, utils_1.getDistributorPda)(this.programId, mint, data.version);
105
132
  return [4 /*yield*/, (0, solana_1.ata)(mint, distributorPublicKey, tokenProgramId)];
106
133
  case 2:
107
- tokenVault = _g.sent();
134
+ tokenVault = _f.sent();
108
135
  return [4 /*yield*/, (0, solana_1.ata)(mint, extParams.invoker.publicKey, tokenProgramId)];
109
136
  case 3:
110
- senderTokens = _g.sent();
137
+ senderTokens = _f.sent();
111
138
  args = {
112
139
  version: new bn_js_1.default(data.version, 10),
113
140
  root: data.root,
@@ -135,8 +162,8 @@ var SolanaDistributorClient = /** @class */ (function () {
135
162
  _e = [[]];
136
163
  return [4 /*yield*/, (0, solana_1.prepareWrappedAccount)(this.connection, extParams.invoker.publicKey, data.maxTotalClaim)];
137
164
  case 4:
138
- _c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [(_g.sent())]), false]))]));
139
- _g.label = 5;
165
+ _c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [(_f.sent())]), false]))]));
166
+ _f.label = 5;
140
167
  case 5:
141
168
  nowTs = new bn_js_1.default(Math.floor(Date.now() / 1000));
142
169
  endVestingTs = args.endVestingTs.eqn(0) ? nowTs : args.endVestingTs;
@@ -146,30 +173,39 @@ var SolanaDistributorClient = /** @class */ (function () {
146
173
  }
147
174
  ixs.push((0, instructions_1.newDistributor)(args, accounts, this.programId));
148
175
  ixs.push((0, spl_token_1.createTransferCheckedInstruction)(senderTokens, mint, tokenVault, extParams.invoker.publicKey, BigInt(data.maxTotalClaim.toString()), mintAccount.decimals, undefined, tokenProgramId));
176
+ return [2 /*return*/, { distributorPublicKey: distributorPublicKey, ixs: ixs }];
177
+ }
178
+ });
179
+ });
180
+ };
181
+ SolanaDistributorClient.prototype.claim = function (data, extParams) {
182
+ return __awaiter(this, void 0, void 0, function () {
183
+ var ixs, _a, tx, hash, context, signature;
184
+ return __generator(this, function (_b) {
185
+ switch (_b.label) {
186
+ case 0: return [4 /*yield*/, this.prepareClaimInstructions(data, extParams)];
187
+ case 1:
188
+ ixs = _b.sent();
149
189
  return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
150
- case 6:
151
- _f = _g.sent(), tx = _f.tx, hash = _f.hash, context = _f.context;
190
+ case 2:
191
+ _a = _b.sent(), tx = _a.tx, hash = _a.hash, context = _a.context;
152
192
  return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
153
193
  hash: hash,
154
194
  context: context,
155
195
  commitment: this.getCommitment(),
156
196
  }, { sendThrottler: this.sendThrottler })];
157
- case 7:
158
- signature = _g.sent();
159
- return [2 /*return*/, {
160
- ixs: ixs,
161
- txId: signature,
162
- metadataId: distributorPublicKey.toBase58(),
163
- }];
197
+ case 3:
198
+ signature = _b.sent();
199
+ return [2 /*return*/, { ixs: ixs, txId: signature }];
164
200
  }
165
201
  });
166
202
  });
167
203
  };
168
- SolanaDistributorClient.prototype.claim = function (data, extParams) {
204
+ SolanaDistributorClient.prototype.prepareClaimInstructions = function (data, extParams) {
169
205
  return __awaiter(this, void 0, void 0, function () {
170
- var distributorPublicKey, distributor, tokenProgramId, ixs, _a, _b, _c, _d, invokerTokens, claimStatusPublicKey, eventAuthorityPublicKey, claimStatus, accounts, args, nowTs, _e, tx, hash, context, signature;
171
- return __generator(this, function (_f) {
172
- switch (_f.label) {
206
+ var distributorPublicKey, distributor, tokenProgramId, ixs, _a, _b, _c, _d, invokerTokens, claimStatusPublicKey, eventAuthorityPublicKey, claimStatus, accounts, args, nowTs;
207
+ return __generator(this, function (_e) {
208
+ switch (_e.label) {
173
209
  case 0:
174
210
  if (!extParams.invoker.publicKey) {
175
211
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
@@ -177,28 +213,28 @@ var SolanaDistributorClient = /** @class */ (function () {
177
213
  distributorPublicKey = new web3_js_1.PublicKey(data.id);
178
214
  return [4 /*yield*/, accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey)];
179
215
  case 1:
180
- distributor = _f.sent();
216
+ distributor = _e.sent();
181
217
  if (!distributor) {
182
218
  throw new Error("Couldn't get account info");
183
219
  }
184
220
  return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, distributor.mint)];
185
221
  case 2:
186
- tokenProgramId = (_f.sent()).tokenProgramId;
222
+ tokenProgramId = (_e.sent()).tokenProgramId;
187
223
  ixs = (0, solana_1.prepareBaseInstructions)(this.connection, extParams);
188
224
  _b = (_a = ixs.push).apply;
189
225
  _c = [ixs];
190
226
  _d = [[]];
191
227
  return [4 /*yield*/, (0, solana_1.checkOrCreateAtaBatch)(this.connection, [extParams.invoker.publicKey], distributor.mint, extParams.invoker, tokenProgramId)];
192
228
  case 3:
193
- _b.apply(_a, _c.concat([__spreadArray.apply(void 0, _d.concat([__read.apply(void 0, [(_f.sent())]), false]))]));
229
+ _b.apply(_a, _c.concat([__spreadArray.apply(void 0, _d.concat([__read.apply(void 0, [(_e.sent())]), false]))]));
194
230
  return [4 /*yield*/, (0, solana_1.ata)(distributor.mint, extParams.invoker.publicKey, tokenProgramId)];
195
231
  case 4:
196
- invokerTokens = _f.sent();
232
+ invokerTokens = _e.sent();
197
233
  claimStatusPublicKey = (0, utils_1.getClaimantStatusPda)(this.programId, distributorPublicKey, extParams.invoker.publicKey);
198
234
  eventAuthorityPublicKey = (0, utils_1.getEventAuthorityPda)(this.programId);
199
235
  return [4 /*yield*/, accounts_1.ClaimStatus.fetch(this.connection, claimStatusPublicKey)];
200
236
  case 5:
201
- claimStatus = _f.sent();
237
+ claimStatus = _e.sent();
202
238
  accounts = {
203
239
  distributor: distributorPublicKey,
204
240
  claimStatus: claimStatusPublicKey,
@@ -223,26 +259,39 @@ var SolanaDistributorClient = /** @class */ (function () {
223
259
  if (claimStatus || (data.amountLocked.gtn(0) && nowTs.sub(distributor.startTs).gte(distributor.unlockPeriod))) {
224
260
  ixs.push((0, instructions_1.claimLocked)(accounts, this.programId));
225
261
  }
262
+ return [2 /*return*/, ixs];
263
+ }
264
+ });
265
+ });
266
+ };
267
+ SolanaDistributorClient.prototype.clawback = function (data, extParams) {
268
+ return __awaiter(this, void 0, void 0, function () {
269
+ var ixs, _a, tx, hash, context, signature;
270
+ return __generator(this, function (_b) {
271
+ switch (_b.label) {
272
+ case 0: return [4 /*yield*/, this.prepareClawbackInstructions(data, extParams)];
273
+ case 1:
274
+ ixs = _b.sent();
226
275
  return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
227
- case 6:
228
- _e = _f.sent(), tx = _e.tx, hash = _e.hash, context = _e.context;
276
+ case 2:
277
+ _a = _b.sent(), tx = _a.tx, hash = _a.hash, context = _a.context;
229
278
  return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
230
279
  hash: hash,
231
280
  context: context,
232
281
  commitment: this.getCommitment(),
233
282
  }, { sendThrottler: this.sendThrottler })];
234
- case 7:
235
- signature = _f.sent();
283
+ case 3:
284
+ signature = _b.sent();
236
285
  return [2 /*return*/, { ixs: ixs, txId: signature }];
237
286
  }
238
287
  });
239
288
  });
240
289
  };
241
- SolanaDistributorClient.prototype.clawback = function (data, extParams) {
290
+ SolanaDistributorClient.prototype.prepareClawbackInstructions = function (data, extParams) {
242
291
  return __awaiter(this, void 0, void 0, function () {
243
- var distributorPublicKey, distributor, tokenProgramId, ixs, _a, _b, _c, _d, accounts, _e, tx, hash, context, signature;
244
- return __generator(this, function (_f) {
245
- switch (_f.label) {
292
+ var distributorPublicKey, distributor, tokenProgramId, ixs, _a, _b, _c, _d, accounts;
293
+ return __generator(this, function (_e) {
294
+ switch (_e.label) {
246
295
  case 0:
247
296
  if (!extParams.invoker.publicKey) {
248
297
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
@@ -250,20 +299,20 @@ var SolanaDistributorClient = /** @class */ (function () {
250
299
  distributorPublicKey = new web3_js_1.PublicKey(data.id);
251
300
  return [4 /*yield*/, accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey)];
252
301
  case 1:
253
- distributor = _f.sent();
302
+ distributor = _e.sent();
254
303
  if (!distributor) {
255
304
  throw new Error("Couldn't get account info");
256
305
  }
257
306
  return [4 /*yield*/, (0, solana_1.getMintAndProgram)(this.connection, distributor.mint)];
258
307
  case 2:
259
- tokenProgramId = (_f.sent()).tokenProgramId;
308
+ tokenProgramId = (_e.sent()).tokenProgramId;
260
309
  ixs = (0, solana_1.prepareBaseInstructions)(this.connection, extParams);
261
310
  _b = (_a = ixs.push).apply;
262
311
  _c = [ixs];
263
312
  _d = [[]];
264
313
  return [4 /*yield*/, (0, solana_1.checkOrCreateAtaBatch)(this.connection, [extParams.invoker.publicKey], distributor.mint, extParams.invoker, tokenProgramId)];
265
314
  case 3:
266
- _b.apply(_a, _c.concat([__spreadArray.apply(void 0, _d.concat([__read.apply(void 0, [(_f.sent())]), false]))]));
315
+ _b.apply(_a, _c.concat([__spreadArray.apply(void 0, _d.concat([__read.apply(void 0, [(_e.sent())]), false]))]));
267
316
  accounts = {
268
317
  distributor: distributorPublicKey,
269
318
  from: distributor.tokenVault,
@@ -274,17 +323,7 @@ var SolanaDistributorClient = /** @class */ (function () {
274
323
  tokenProgram: tokenProgramId,
275
324
  };
276
325
  ixs.push((0, instructions_1.clawback)(accounts, this.programId));
277
- return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey)];
278
- case 4:
279
- _e = _f.sent(), tx = _e.tx, hash = _e.hash, context = _e.context;
280
- return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
281
- hash: hash,
282
- context: context,
283
- commitment: this.getCommitment(),
284
- }, { sendThrottler: this.sendThrottler })];
285
- case 5:
286
- signature = _f.sent();
287
- return [2 /*return*/, { ixs: ixs, txId: signature }];
326
+ return [2 /*return*/, ixs];
288
327
  }
289
328
  });
290
329
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/distributor",
3
- "version": "6.3.4",
3
+ "version": "6.3.6",
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/index.js",
@@ -22,9 +22,9 @@
22
22
  "lint": "eslint --fix .",
23
23
  "prepublishOnly": "npm run lint && npm run build"
24
24
  },
25
- "gitHead": "c559d33706f42ff9e0704923376aade789eaa8ce",
25
+ "gitHead": "9b68da58bc858e6e46ed988492abf618e1a4f3ca",
26
26
  "devDependencies": {
27
- "@streamflow/eslint-config": "6.3.4",
27
+ "@streamflow/eslint-config": "6.3.6",
28
28
  "@types/bn.js": "5.1.1",
29
29
  "@types/jest": "29.2.4",
30
30
  "date-fns": "2.28.0",
@@ -38,7 +38,7 @@
38
38
  "@solana/spl-token": "0.3.6",
39
39
  "@solana/wallet-adapter-base": "0.9.19",
40
40
  "@solana/web3.js": "1.70.1",
41
- "@streamflow/common": "6.3.4",
41
+ "@streamflow/common": "6.3.6",
42
42
  "bn.js": "5.2.1",
43
43
  "borsh": "^2.0.0",
44
44
  "bs58": "5.0.0",