@streamflow/distributor 6.0.0-alpha.1 → 6.0.0-alpha.3

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.
@@ -16,9 +16,10 @@ export default class SolanaDistributorClient {
16
16
  * Create Stream instance
17
17
  */
18
18
  constructor({ clusterUrl, cluster, commitment, programId }: IInitOptions);
19
- create(data: ICreateDistributorData, { invoker, isNative }: ICreateSolanaExt): Promise<ICreateDistributorResult>;
20
- claim(data: IClaimData, { invoker }: IInteractSolanaExt): Promise<ITransactionResult>;
21
- clawback(data: IClawbackData, { invoker }: IInteractSolanaExt): Promise<ITransactionResult>;
19
+ getCommitment(): Commitment | undefined;
20
+ create(data: ICreateDistributorData, { invoker, isNative, computePrice, computeLimit }: ICreateSolanaExt): Promise<ICreateDistributorResult>;
21
+ claim(data: IClaimData, { invoker, computePrice, computeLimit }: IInteractSolanaExt): Promise<ITransactionResult>;
22
+ clawback(data: IClawbackData, { invoker, computePrice, computeLimit }: IInteractSolanaExt): Promise<ITransactionResult>;
22
23
  getClaims(data: IGetClaimsData): Promise<(ClaimStatus | null)[]>;
23
24
  getDistributors(data: IGetDistributors): Promise<(MerkleDistributor | null)[]>;
24
25
  }
@@ -83,18 +83,20 @@ var SolanaDistributorClient = /** @class */ (function () {
83
83
  this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
84
84
  this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_1.DISTRIBUTOR_PROGRAM_ID[cluster]);
85
85
  }
86
+ SolanaDistributorClient.prototype.getCommitment = function () {
87
+ return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
88
+ };
86
89
  SolanaDistributorClient.prototype.create = function (data, _a) {
87
- var invoker = _a.invoker, _b = _a.isNative, isNative = _b === void 0 ? false : _b;
90
+ var invoker = _a.invoker, _b = _a.isNative, isNative = _b === void 0 ? false : _b, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
88
91
  return __awaiter(this, void 0, void 0, function () {
89
- var ixs, mint, mintAccount, distributorPublicKey, tokenVault, senderTokens, args, accounts, _c, _d, _e, _f, commitment, hash, tx, signature;
90
- var _g;
92
+ var ixs, mint, mintAccount, distributorPublicKey, tokenVault, senderTokens, args, accounts, _c, _d, _e, _f, _g, tx, hash, signature;
91
93
  return __generator(this, function (_h) {
92
94
  switch (_h.label) {
93
95
  case 0:
94
96
  if (!invoker.publicKey) {
95
97
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
96
98
  }
97
- ixs = [];
99
+ ixs = (0, solana_1.prepareBaseInstructions)(this.connection, { computePrice: computePrice, computeLimit: computeLimit });
98
100
  mint = isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(data.mint);
99
101
  return [4 /*yield*/, (0, spl_token_1.getMint)(this.connection, mint)];
100
102
  case 1:
@@ -138,15 +140,9 @@ var SolanaDistributorClient = /** @class */ (function () {
138
140
  case 5:
139
141
  ixs.push((0, instructions_1.newDistributor)(args, accounts, this.programId));
140
142
  ixs.push((0, spl_token_1.createTransferCheckedInstruction)(senderTokens, mint, tokenVault, invoker.publicKey, BigInt(data.maxTotalClaim.toString()), mintAccount.decimals));
141
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
142
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
143
+ return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, invoker.publicKey, this.getCommitment())];
143
144
  case 6:
144
- hash = _h.sent();
145
- tx = (_g = new web3_js_1.Transaction({
146
- feePayer: invoker.publicKey,
147
- blockhash: hash.blockhash,
148
- lastValidBlockHeight: hash.lastValidBlockHeight,
149
- })).add.apply(_g, __spreadArray([], __read(ixs), false));
145
+ _g = _h.sent(), tx = _g.tx, hash = _g.hash;
150
146
  return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, invoker, tx, hash)];
151
147
  case 7:
152
148
  signature = _h.sent();
@@ -160,12 +156,11 @@ var SolanaDistributorClient = /** @class */ (function () {
160
156
  });
161
157
  };
162
158
  SolanaDistributorClient.prototype.claim = function (data, _a) {
163
- var invoker = _a.invoker;
159
+ var invoker = _a.invoker, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
164
160
  return __awaiter(this, void 0, void 0, function () {
165
- var distributorPublicKey, distributor, ixs, invokerTokens, claimStatusPublicKey, claimStatus, accounts, args, commitment, hash, tx, signature;
166
- var _b;
167
- return __generator(this, function (_c) {
168
- switch (_c.label) {
161
+ var distributorPublicKey, distributor, ixs, _b, _c, _d, _e, invokerTokens, claimStatusPublicKey, claimStatus, accounts, args, _f, tx, hash, signature;
162
+ return __generator(this, function (_g) {
163
+ switch (_g.label) {
169
164
  case 0:
170
165
  if (!invoker.publicKey) {
171
166
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
@@ -173,20 +168,24 @@ var SolanaDistributorClient = /** @class */ (function () {
173
168
  distributorPublicKey = new web3_js_1.PublicKey(data.id);
174
169
  return [4 /*yield*/, accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey)];
175
170
  case 1:
176
- distributor = _c.sent();
171
+ distributor = _g.sent();
177
172
  if (!distributor) {
178
173
  throw new Error("Couldn't get account info");
179
174
  }
175
+ ixs = (0, solana_1.prepareBaseInstructions)(this.connection, { computePrice: computePrice, computeLimit: computeLimit });
176
+ _c = (_b = ixs.push).apply;
177
+ _d = [ixs];
178
+ _e = [[]];
180
179
  return [4 /*yield*/, (0, solana_1.checkOrCreateAtaBatch)(this.connection, [invoker.publicKey], distributor.mint, invoker)];
181
180
  case 2:
182
- ixs = _c.sent();
181
+ _c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [(_g.sent())]), false]))]));
183
182
  return [4 /*yield*/, (0, solana_1.ata)(distributor.mint, invoker.publicKey)];
184
183
  case 3:
185
- invokerTokens = _c.sent();
184
+ invokerTokens = _g.sent();
186
185
  claimStatusPublicKey = (0, utils_1.getClaimantStatusPda)(this.programId, distributorPublicKey, invoker.publicKey);
187
186
  return [4 /*yield*/, accounts_1.ClaimStatus.fetch(this.connection, claimStatusPublicKey)];
188
187
  case 4:
189
- claimStatus = _c.sent();
188
+ claimStatus = _g.sent();
190
189
  accounts = {
191
190
  distributor: distributorPublicKey,
192
191
  claimStatus: claimStatusPublicKey,
@@ -208,30 +207,23 @@ var SolanaDistributorClient = /** @class */ (function () {
208
207
  };
209
208
  ixs.push((0, instructions_1.newClaim)(args, accounts, this.programId));
210
209
  }
211
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
212
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
210
+ return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, invoker.publicKey, this.getCommitment())];
213
211
  case 5:
214
- hash = _c.sent();
215
- tx = (_b = new web3_js_1.Transaction({
216
- feePayer: invoker.publicKey,
217
- blockhash: hash.blockhash,
218
- lastValidBlockHeight: hash.lastValidBlockHeight,
219
- })).add.apply(_b, __spreadArray([], __read(ixs), false));
212
+ _f = _g.sent(), tx = _f.tx, hash = _f.hash;
220
213
  return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, invoker, tx, hash)];
221
214
  case 6:
222
- signature = _c.sent();
215
+ signature = _g.sent();
223
216
  return [2 /*return*/, { ixs: ixs, txId: signature }];
224
217
  }
225
218
  });
226
219
  });
227
220
  };
228
221
  SolanaDistributorClient.prototype.clawback = function (data, _a) {
229
- var invoker = _a.invoker;
222
+ var invoker = _a.invoker, computePrice = _a.computePrice, computeLimit = _a.computeLimit;
230
223
  return __awaiter(this, void 0, void 0, function () {
231
- var distributorPublicKey, distributor, ixs, accounts, commitment, hash, tx, signature;
232
- var _b;
233
- return __generator(this, function (_c) {
234
- switch (_c.label) {
224
+ var distributorPublicKey, distributor, ixs, _b, _c, _d, _e, accounts, _f, tx, hash, signature;
225
+ return __generator(this, function (_g) {
226
+ switch (_g.label) {
235
227
  case 0:
236
228
  if (!invoker.publicKey) {
237
229
  throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
@@ -239,13 +231,17 @@ var SolanaDistributorClient = /** @class */ (function () {
239
231
  distributorPublicKey = new web3_js_1.PublicKey(data.id);
240
232
  return [4 /*yield*/, accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey)];
241
233
  case 1:
242
- distributor = _c.sent();
234
+ distributor = _g.sent();
243
235
  if (!distributor) {
244
236
  throw new Error("Couldn't get account info");
245
237
  }
238
+ ixs = (0, solana_1.prepareBaseInstructions)(this.connection, { computePrice: computePrice, computeLimit: computeLimit });
239
+ _c = (_b = ixs.push).apply;
240
+ _d = [ixs];
241
+ _e = [[]];
246
242
  return [4 /*yield*/, (0, solana_1.checkOrCreateAtaBatch)(this.connection, [invoker.publicKey], distributor.mint, invoker)];
247
243
  case 2:
248
- ixs = _c.sent();
244
+ _c.apply(_b, _d.concat([__spreadArray.apply(void 0, _e.concat([__read.apply(void 0, [(_g.sent())]), false]))]));
249
245
  accounts = {
250
246
  distributor: distributorPublicKey,
251
247
  from: distributor.tokenVault,
@@ -256,18 +252,12 @@ var SolanaDistributorClient = /** @class */ (function () {
256
252
  tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
257
253
  };
258
254
  ixs.push((0, instructions_1.clawback)(accounts, this.programId));
259
- commitment = typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
260
- return [4 /*yield*/, this.connection.getLatestBlockhash(commitment)];
255
+ return [4 /*yield*/, (0, solana_1.prepareTransaction)(this.connection, ixs, invoker.publicKey, this.getCommitment())];
261
256
  case 3:
262
- hash = _c.sent();
263
- tx = (_b = new web3_js_1.Transaction({
264
- feePayer: invoker.publicKey,
265
- blockhash: hash.blockhash,
266
- lastValidBlockHeight: hash.lastValidBlockHeight,
267
- })).add.apply(_b, __spreadArray([], __read(ixs), false));
257
+ _f = _g.sent(), tx = _f.tx, hash = _f.hash;
268
258
  return [4 /*yield*/, (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, invoker, tx, hash)];
269
259
  case 4:
270
- signature = _c.sent();
260
+ signature = _g.sent();
271
261
  return [2 /*return*/, { ixs: ixs, txId: signature }];
272
262
  }
273
263
  });
@@ -2,7 +2,8 @@ import BN from "bn.js";
2
2
  import { SignerWalletAdapter } from "@solana/wallet-adapter-base";
3
3
  import { Keypair } from "@solana/web3.js";
4
4
  import { ITransactionResult } from "@streamflow/common";
5
- export interface IInteractSolanaExt {
5
+ import { ITransactionSolanaExt } from "@streamflow/common/solana";
6
+ export interface IInteractSolanaExt extends ITransactionSolanaExt {
6
7
  invoker: SignerWalletAdapter | Keypair;
7
8
  }
8
9
  export interface ICreateSolanaExt extends IInteractSolanaExt {
@@ -61,15 +61,13 @@ function getClaimantStatusPda(programId, distributor, claimant) {
61
61
  exports.getClaimantStatusPda = getClaimantStatusPda;
62
62
  function wrappedSignAndExecuteTransaction(connection, invoker, tx, hash) {
63
63
  return __awaiter(this, void 0, void 0, function () {
64
- var signature, err_1, parsed;
64
+ var err_1, parsed;
65
65
  return __generator(this, function (_a) {
66
66
  switch (_a.label) {
67
67
  case 0:
68
68
  _a.trys.push([0, 2, , 3]);
69
69
  return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(connection, invoker, tx, hash)];
70
- case 1:
71
- signature = _a.sent();
72
- return [2 /*return*/, signature];
70
+ case 1: return [2 /*return*/, _a.sent()];
73
71
  case 2:
74
72
  err_1 = _a.sent();
75
73
  if (err_1 instanceof Error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamflow/distributor",
3
- "version": "6.0.0-alpha.1",
3
+ "version": "6.0.0-alpha.3",
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": "fe960e0939f41867ce01a7515ec95f22c3fe6cbf",
25
+ "gitHead": "4f5eed327dda8e1c9d5c3ad74046aff4b99a80ed",
26
26
  "devDependencies": {
27
- "@streamflow/eslint-config": "6.0.0-alpha.1",
27
+ "@streamflow/eslint-config": "6.0.0-alpha.3",
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.0.0-alpha.1",
41
+ "@streamflow/common": "6.0.0-alpha.3",
42
42
  "bn.js": "5.2.1",
43
43
  "borsh": "^2.0.0",
44
44
  "bs58": "5.0.0"