@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.
Files changed (36) hide show
  1. package/README.md +20 -5
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/solana/client.js +199 -347
  4. package/dist/cjs/solana/constants.js +11 -9
  5. package/dist/cjs/solana/generated/accounts/ClaimStatus.js +52 -110
  6. package/dist/cjs/solana/generated/accounts/MerkleDistributor.js +67 -125
  7. package/dist/cjs/solana/generated/errors/anchor.js +540 -717
  8. package/dist/cjs/solana/generated/errors/custom.js +171 -243
  9. package/dist/cjs/solana/generated/errors/index.js +12 -51
  10. package/dist/cjs/solana/generated/instructions/claimLocked.js +7 -8
  11. package/dist/cjs/solana/generated/instructions/clawback.js +8 -9
  12. package/dist/cjs/solana/generated/instructions/closeClaim.js +8 -9
  13. package/dist/cjs/solana/generated/instructions/newClaim.js +10 -11
  14. package/dist/cjs/solana/generated/instructions/newDistributor.js +17 -12
  15. package/dist/cjs/solana/generated/instructions/setAdmin.js +8 -9
  16. package/dist/cjs/solana/generated/instructions/setClawbackReceiver.js +8 -9
  17. package/dist/cjs/solana/generated/programId.js +1 -1
  18. package/dist/cjs/solana/index.js +6 -6
  19. package/dist/cjs/solana/utils.js +38 -92
  20. package/dist/esm/index.d.ts +1 -1
  21. package/dist/esm/index.js +1 -1
  22. package/dist/esm/solana/client.d.ts +3 -1
  23. package/dist/esm/solana/client.js +44 -18
  24. package/dist/esm/solana/constants.d.ts +3 -0
  25. package/dist/esm/solana/constants.js +3 -0
  26. package/dist/esm/solana/generated/accounts/ClaimStatus.d.ts +11 -11
  27. package/dist/esm/solana/generated/accounts/ClaimStatus.js +6 -6
  28. package/dist/esm/solana/generated/accounts/MerkleDistributor.d.ts +19 -19
  29. package/dist/esm/solana/generated/accounts/MerkleDistributor.js +10 -10
  30. package/dist/esm/solana/generated/instructions/newClaim.d.ts +3 -3
  31. package/dist/esm/solana/generated/instructions/newDistributor.d.ts +8 -8
  32. package/dist/esm/solana/generated/instructions/newDistributor.js +6 -0
  33. package/dist/esm/solana/index.d.ts +6 -6
  34. package/dist/esm/solana/index.js +6 -6
  35. package/dist/esm/solana/types.d.ts +9 -5
  36. package/package.json +7 -8
@@ -24,17 +24,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.newClaim = exports.layout = void 0;
27
- var web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
28
- var borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
29
- var programId_1 = require("../programId");
27
+ const web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
28
+ const borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
29
+ const programId_1 = require("../programId");
30
30
  exports.layout = borsh.struct([
31
31
  borsh.u64("amountUnlocked"),
32
32
  borsh.u64("amountLocked"),
33
33
  borsh.vec(borsh.array(borsh.u8(), 32), "proof"),
34
34
  ]);
35
- function newClaim(args, accounts, programId) {
36
- if (programId === void 0) { programId = programId_1.PROGRAM_ID; }
37
- var keys = [
35
+ function newClaim(args, accounts, programId = programId_1.PROGRAM_ID) {
36
+ const keys = [
38
37
  { pubkey: accounts.distributor, isSigner: false, isWritable: true },
39
38
  { pubkey: accounts.claimStatus, isSigner: false, isWritable: true },
40
39
  { pubkey: accounts.from, isSigner: false, isWritable: true },
@@ -46,15 +45,15 @@ function newClaim(args, accounts, programId) {
46
45
  { pubkey: accounts.eventAuthority, isSigner: false, isWritable: false },
47
46
  { pubkey: accounts.program, isSigner: false, isWritable: false },
48
47
  ];
49
- var identifier = Buffer.from([78, 177, 98, 123, 210, 21, 187, 83]);
50
- var buffer = Buffer.alloc(1000);
51
- var len = exports.layout.encode({
48
+ const identifier = Buffer.from([78, 177, 98, 123, 210, 21, 187, 83]);
49
+ const buffer = Buffer.alloc(1000);
50
+ const len = exports.layout.encode({
52
51
  amountUnlocked: args.amountUnlocked,
53
52
  amountLocked: args.amountLocked,
54
53
  proof: args.proof,
55
54
  }, buffer);
56
- var data = Buffer.concat([identifier, buffer]).slice(0, 8 + len);
57
- var ix = new web3_js_1.TransactionInstruction({ keys: keys, programId: programId, data: data });
55
+ const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len);
56
+ const ix = new web3_js_1.TransactionInstruction({ keys, programId, data });
58
57
  return ix;
59
58
  }
60
59
  exports.newClaim = newClaim;
@@ -24,10 +24,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.newDistributor = exports.layout = void 0;
27
- var web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
28
- var borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
29
- var buffer_1 = require("buffer");
30
- var programId_1 = require("../programId");
27
+ const web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
28
+ const borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
29
+ const buffer_1 = require("buffer");
30
+ const programId_1 = require("../programId");
31
31
  exports.layout = borsh.struct([
32
32
  borsh.u64("version"),
33
33
  borsh.array(borsh.u8(), 32, "root"),
@@ -38,6 +38,9 @@ exports.layout = borsh.struct([
38
38
  borsh.u64("endVestingTs"),
39
39
  borsh.u64("clawbackStartTs"),
40
40
  borsh.bool("claimsClosable"),
41
+ borsh.option(borsh.bool(), "canUpdateDuration"),
42
+ borsh.option(borsh.u64(), "totalAmountUnlocked"),
43
+ borsh.option(borsh.u64(), "totalAmountLocked"),
41
44
  ]);
42
45
  /**
43
46
  * READ THE FOLLOWING:
@@ -59,9 +62,8 @@ exports.layout = borsh.struct([
59
62
  * assert the parameters are what you expect, most importantly the clawback_receiver and admin.
60
63
  * - If your transaction fails, double check the value on-chain matches what you expect.
61
64
  */
62
- function newDistributor(args, accounts, programId) {
63
- if (programId === void 0) { programId = programId_1.PROGRAM_ID; }
64
- var keys = [
65
+ function newDistributor(args, accounts, programId = programId_1.PROGRAM_ID) {
66
+ const keys = [
65
67
  { pubkey: accounts.distributor, isSigner: false, isWritable: true },
66
68
  { pubkey: accounts.clawbackReceiver, isSigner: false, isWritable: true },
67
69
  { pubkey: accounts.mint, isSigner: false, isWritable: false },
@@ -75,9 +77,9 @@ function newDistributor(args, accounts, programId) {
75
77
  },
76
78
  { pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
77
79
  ];
78
- var identifier = buffer_1.Buffer.from([32, 139, 112, 171, 0, 2, 225, 155]);
79
- var buffer = buffer_1.Buffer.alloc(1000);
80
- var len = exports.layout.encode({
80
+ const identifier = buffer_1.Buffer.from([32, 139, 112, 171, 0, 2, 225, 155]);
81
+ const buffer = buffer_1.Buffer.alloc(1000);
82
+ const len = exports.layout.encode({
81
83
  version: args.version,
82
84
  root: args.root,
83
85
  maxTotalClaim: args.maxTotalClaim,
@@ -87,9 +89,12 @@ function newDistributor(args, accounts, programId) {
87
89
  endVestingTs: args.endVestingTs,
88
90
  clawbackStartTs: args.clawbackStartTs,
89
91
  claimsClosable: args.claimsClosable,
92
+ canUpdateDuration: null,
93
+ totalAmountUnlocked: null,
94
+ totalAmountLocked: null,
90
95
  }, buffer);
91
- var data = buffer_1.Buffer.concat([identifier, buffer]).slice(0, 8 + len);
92
- var ix = new web3_js_1.TransactionInstruction({ keys: keys, programId: programId, data: data });
96
+ const data = buffer_1.Buffer.concat([identifier, buffer]).slice(0, 8 + len);
97
+ const ix = new web3_js_1.TransactionInstruction({ keys, programId, data });
93
98
  return ix;
94
99
  }
95
100
  exports.newDistributor = newDistributor;
@@ -1,19 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setAdmin = void 0;
4
- var web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
5
- var buffer_1 = require("buffer");
6
- var programId_1 = require("../programId");
7
- function setAdmin(accounts, programId) {
8
- if (programId === void 0) { programId = programId_1.PROGRAM_ID; }
9
- var keys = [
4
+ const web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ const buffer_1 = require("buffer");
6
+ const programId_1 = require("../programId");
7
+ function setAdmin(accounts, programId = programId_1.PROGRAM_ID) {
8
+ const keys = [
10
9
  { pubkey: accounts.distributor, isSigner: false, isWritable: true },
11
10
  { pubkey: accounts.admin, isSigner: true, isWritable: true },
12
11
  { pubkey: accounts.newAdmin, isSigner: false, isWritable: true },
13
12
  ];
14
- var identifier = buffer_1.Buffer.from([251, 163, 0, 52, 91, 194, 187, 92]);
15
- var data = identifier;
16
- var ix = new web3_js_1.TransactionInstruction({ keys: keys, programId: programId, data: data });
13
+ const identifier = buffer_1.Buffer.from([251, 163, 0, 52, 91, 194, 187, 92]);
14
+ const data = identifier;
15
+ const ix = new web3_js_1.TransactionInstruction({ keys, programId, data });
17
16
  return ix;
18
17
  }
19
18
  exports.setAdmin = setAdmin;
@@ -1,19 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setClawbackReceiver = void 0;
4
- var web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
5
- var buffer_1 = require("buffer");
6
- var programId_1 = require("../programId");
7
- function setClawbackReceiver(accounts, programId) {
8
- if (programId === void 0) { programId = programId_1.PROGRAM_ID; }
9
- var keys = [
4
+ const web3_js_1 = require("@solana/web3.js"); // eslint-disable-line @typescript-eslint/no-unused-vars
5
+ const buffer_1 = require("buffer");
6
+ const programId_1 = require("../programId");
7
+ function setClawbackReceiver(accounts, programId = programId_1.PROGRAM_ID) {
8
+ const keys = [
10
9
  { pubkey: accounts.distributor, isSigner: false, isWritable: true },
11
10
  { pubkey: accounts.newClawbackAccount, isSigner: false, isWritable: false },
12
11
  { pubkey: accounts.admin, isSigner: true, isWritable: true },
13
12
  ];
14
- var identifier = buffer_1.Buffer.from([153, 217, 34, 20, 19, 29, 229, 75]);
15
- var data = identifier;
16
- var ix = new web3_js_1.TransactionInstruction({ keys: keys, programId: programId, data: data });
13
+ const identifier = buffer_1.Buffer.from([153, 217, 34, 20, 19, 29, 229, 75]);
14
+ const data = identifier;
15
+ const ix = new web3_js_1.TransactionInstruction({ keys, programId, data });
17
16
  return ix;
18
17
  }
19
18
  exports.setClawbackReceiver = setClawbackReceiver;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROGRAM_ID = exports.PROGRAM_ID_CLI = void 0;
4
- var web3_js_1 = require("@solana/web3.js");
4
+ const web3_js_1 = require("@solana/web3.js");
5
5
  // Program ID passed with the cli --program-id flag when running the code generator. Do not edit, it will get overwritten.
6
6
  exports.PROGRAM_ID_CLI = new web3_js_1.PublicKey("MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N");
7
7
  // This constant will not get overwritten on subsequent code generations and it's safe to modify it's value.
@@ -32,9 +32,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.constants = exports.SolanaDistributorClient = void 0;
33
33
  var client_1 = require("./client");
34
34
  Object.defineProperty(exports, "SolanaDistributorClient", { enumerable: true, get: function () { return __importDefault(client_1).default; } });
35
- __exportStar(require("./generated/accounts"), exports);
36
- __exportStar(require("./generated/errors"), exports);
37
- __exportStar(require("./generated/instructions"), exports);
38
- __exportStar(require("./utils"), exports);
39
- __exportStar(require("./types"), exports);
40
- exports.constants = __importStar(require("./constants"));
35
+ __exportStar(require("./generated/accounts/index.js"), exports);
36
+ __exportStar(require("./generated/errors/index.js"), exports);
37
+ __exportStar(require("./generated/instructions/index.js"), exports);
38
+ __exportStar(require("./utils.js"), exports);
39
+ __exportStar(require("./types.js"), exports);
40
+ exports.constants = __importStar(require("./constants.js"));
@@ -1,53 +1,17 @@
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.calculateAmountWithTransferFees = exports.wrappedSignAndExecuteTransaction = exports.getEventAuthorityPda = exports.getClaimantStatusPda = exports.getDistributorPda = exports.divCeilN = void 0;
40
- var buffer_1 = require("buffer");
41
- var web3_js_1 = require("@solana/web3.js");
42
- var common_1 = require("@streamflow/common");
43
- var solana_1 = require("@streamflow/common/solana");
44
- var errors_1 = require("./generated/errors");
45
- var constants_1 = require("./constants");
46
- var divCeilN = function (n, d) { return n / d + (n % d ? BigInt(1) : BigInt(0)); };
4
+ const buffer_1 = require("buffer");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const common_1 = require("@streamflow/common");
7
+ const solana_1 = require("@streamflow/common/solana");
8
+ const errors_1 = require("./generated/errors");
9
+ const constants_1 = require("./constants");
10
+ const divCeilN = (n, d) => n / d + (n % d ? BigInt(1) : BigInt(0));
47
11
  exports.divCeilN = divCeilN;
48
12
  function getDistributorPda(programId, mint, version) {
49
13
  // Constructing the seed for the PDA
50
- var seeds = [
14
+ const seeds = [
51
15
  buffer_1.Buffer.from("MerkleDistributor"),
52
16
  mint.toBuffer(),
53
17
  buffer_1.Buffer.from(new Uint8Array(new BigUint64Array([BigInt(version)]).buffer)),
@@ -58,66 +22,48 @@ function getDistributorPda(programId, mint, version) {
58
22
  exports.getDistributorPda = getDistributorPda;
59
23
  function getClaimantStatusPda(programId, distributor, claimant) {
60
24
  // Constructing the seed for the PDA
61
- var seeds = [buffer_1.Buffer.from("ClaimStatus"), claimant.toBuffer(), distributor.toBuffer()];
25
+ const seeds = [buffer_1.Buffer.from("ClaimStatus"), claimant.toBuffer(), distributor.toBuffer()];
62
26
  // Finding the PDA
63
27
  return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
64
28
  }
65
29
  exports.getClaimantStatusPda = getClaimantStatusPda;
66
30
  function getEventAuthorityPda(programId) {
67
31
  // Constructing the seed for the PDA
68
- var seeds = [buffer_1.Buffer.from("__event_authority")];
32
+ const seeds = [buffer_1.Buffer.from("__event_authority")];
69
33
  // Finding the PDA
70
34
  return web3_js_1.PublicKey.findProgramAddressSync(seeds, programId)[0];
71
35
  }
72
36
  exports.getEventAuthorityPda = getEventAuthorityPda;
73
- function wrappedSignAndExecuteTransaction(connection, invoker, tx, confirmationParams, throttleParams) {
74
- return __awaiter(this, void 0, void 0, function () {
75
- var err_1, parsed;
76
- return __generator(this, function (_a) {
77
- switch (_a.label) {
78
- case 0:
79
- _a.trys.push([0, 2, , 3]);
80
- return [4 /*yield*/, (0, solana_1.signAndExecuteTransaction)(connection, invoker, tx, confirmationParams, throttleParams)];
81
- case 1: return [2 /*return*/, _a.sent()];
82
- case 2:
83
- err_1 = _a.sent();
84
- if (err_1 instanceof Error) {
85
- parsed = (0, errors_1.fromTxError)(err_1);
86
- if (parsed) {
87
- throw new common_1.ContractError(err_1, parsed.name, parsed.msg);
88
- }
89
- }
90
- throw err_1;
91
- case 3: return [2 /*return*/];
37
+ async function wrappedSignAndExecuteTransaction(connection, invoker, tx, confirmationParams, throttleParams) {
38
+ try {
39
+ return await (0, solana_1.signAndExecuteTransaction)(connection, invoker, tx, confirmationParams, throttleParams);
40
+ }
41
+ catch (err) {
42
+ if (err instanceof Error) {
43
+ const parsed = (0, errors_1.fromTxError)(err);
44
+ if (parsed) {
45
+ throw new common_1.ContractError(err, parsed.name, parsed.msg);
92
46
  }
93
- });
94
- });
47
+ }
48
+ throw err;
49
+ }
95
50
  }
96
51
  exports.wrappedSignAndExecuteTransaction = wrappedSignAndExecuteTransaction;
97
- function calculateAmountWithTransferFees(connection, transferFeeConfig, transferAmount) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- var epoch, transferFee, transferFeeBasisPoints, feeCharged, numerator, denominator, rawPreFeeAmount, fee;
100
- return __generator(this, function (_a) {
101
- switch (_a.label) {
102
- case 0: return [4 /*yield*/, connection.getEpochInfo()];
103
- case 1:
104
- epoch = _a.sent();
105
- transferFee = epoch.epoch >= transferFeeConfig.newerTransferFee.epoch
106
- ? transferFeeConfig.newerTransferFee
107
- : transferFeeConfig.olderTransferFee;
108
- transferFeeBasisPoints = BigInt(transferFee.transferFeeBasisPoints);
109
- feeCharged = BigInt(0);
110
- if (transferFeeBasisPoints !== BigInt(0)) {
111
- numerator = transferAmount * constants_1.ONE_IN_BASIS_POINTS;
112
- denominator = constants_1.ONE_IN_BASIS_POINTS - transferFeeBasisPoints;
113
- rawPreFeeAmount = (0, exports.divCeilN)(numerator, denominator);
114
- fee = rawPreFeeAmount - transferAmount;
115
- transferAmount = rawPreFeeAmount;
116
- feeCharged = fee > transferFee.maximumFee ? transferFee.maximumFee : fee;
117
- }
118
- return [2 /*return*/, { transferAmount: transferAmount, feeCharged: feeCharged }];
119
- }
120
- });
121
- });
52
+ async function calculateAmountWithTransferFees(connection, transferFeeConfig, transferAmount) {
53
+ const epoch = await connection.getEpochInfo();
54
+ const transferFee = epoch.epoch >= transferFeeConfig.newerTransferFee.epoch
55
+ ? transferFeeConfig.newerTransferFee
56
+ : transferFeeConfig.olderTransferFee;
57
+ const transferFeeBasisPoints = BigInt(transferFee.transferFeeBasisPoints);
58
+ let feeCharged = BigInt(0);
59
+ if (transferFeeBasisPoints !== BigInt(0)) {
60
+ const numerator = transferAmount * constants_1.ONE_IN_BASIS_POINTS;
61
+ const denominator = constants_1.ONE_IN_BASIS_POINTS - transferFeeBasisPoints;
62
+ const rawPreFeeAmount = (0, exports.divCeilN)(numerator, denominator);
63
+ const fee = rawPreFeeAmount - transferAmount;
64
+ transferAmount = rawPreFeeAmount;
65
+ feeCharged = fee > transferFee.maximumFee ? transferFee.maximumFee : fee;
66
+ }
67
+ return { transferAmount, feeCharged };
122
68
  }
123
69
  exports.calculateAmountWithTransferFees = calculateAmountWithTransferFees;
@@ -1 +1 @@
1
- export * as StreamflowDistributorSolana from "./solana";
1
+ export * as StreamflowDistributorSolana from "./solana/index.js";
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export * as StreamflowDistributorSolana from "./solana";
1
+ export * as StreamflowDistributorSolana from "./solana/index.js";
@@ -1,7 +1,8 @@
1
1
  import PQueue from "p-queue";
2
2
  import { PublicKey, TransactionInstruction, Commitment, ConnectionConfig } from "@solana/web3.js";
3
3
  import { ICluster, ITransactionResult } from "@streamflow/common";
4
- import { IClaimData, IClawbackData, ICreateDistributorData, ICreateDistributorResult, IGetClaimData, IGetDistributors, ICreateSolanaExt, IInteractSolanaExt } from "./types";
4
+ import { IProgramAccount } from "@streamflow/common/solana";
5
+ import { IClaimData, IClawbackData, ICreateDistributorData, ICreateDistributorResult, IGetClaimData, IGetDistributors, ICreateSolanaExt, IInteractSolanaExt, ISearchDistributors } from "./types";
5
6
  import { ClaimStatus, MerkleDistributor } from "./generated/accounts";
6
7
  interface IInitOptions {
7
8
  clusterUrl: string;
@@ -32,5 +33,6 @@ export default class SolanaDistributorClient {
32
33
  prepareClawbackInstructions(data: IClawbackData, extParams: IInteractSolanaExt): Promise<TransactionInstruction[]>;
33
34
  getClaims(data: IGetClaimData[]): Promise<(ClaimStatus | null)[]>;
34
35
  getDistributors(data: IGetDistributors): Promise<(MerkleDistributor | null)[]>;
36
+ searchDistributors(data: ISearchDistributors): Promise<IProgramAccount<MerkleDistributor>[]>;
35
37
  }
36
38
  export {};
@@ -1,9 +1,10 @@
1
- import BN from "bn.js";
1
+ import bs58 from "bs58";
2
+ import BigNumber from "bignumber.js";
2
3
  import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT, createTransferCheckedInstruction, createTransferCheckedWithFeeInstruction, getTransferFeeConfig, } from "@solana/spl-token";
3
4
  import { Connection, PublicKey, SystemProgram, } from "@solana/web3.js";
4
5
  import { ICluster } from "@streamflow/common";
5
6
  import { ata, checkOrCreateAtaBatch, prepareWrappedAccount, prepareBaseInstructions, prepareTransaction, getMintAndProgram, buildSendThrottler, } from "@streamflow/common/solana";
6
- import { DISTRIBUTOR_PROGRAM_ID } from "./constants";
7
+ import { DISTRIBUTOR_ADMIN_OFFSET, DISTRIBUTOR_MINT_OFFSET, DISTRIBUTOR_PROGRAM_ID } from "./constants";
7
8
  import { claimLocked, clawback, newClaim, newDistributor, } from "./generated/instructions";
8
9
  import { ClaimStatus, MerkleDistributor } from "./generated/accounts";
9
10
  import { calculateAmountWithTransferFees, getClaimantStatusPda, getDistributorPda, getEventAuthorityPda, wrappedSignAndExecuteTransaction, } from "./utils";
@@ -50,14 +51,14 @@ export default class SolanaDistributorClient {
50
51
  const tokenVault = await ata(mint, distributorPublicKey, tokenProgramId);
51
52
  const senderTokens = await ata(mint, extParams.invoker.publicKey, tokenProgramId);
52
53
  const args = {
53
- version: new BN(data.version, 10),
54
+ version: BigNumber(data.version),
54
55
  root: data.root,
55
- maxTotalClaim: data.maxTotalClaim,
56
- maxNumNodes: data.maxNumNodes,
57
- unlockPeriod: new BN(data.unlockPeriod, 10),
58
- startVestingTs: new BN(data.startVestingTs, 10),
59
- endVestingTs: new BN(data.endVestingTs, 10),
60
- clawbackStartTs: new BN(data.clawbackStartTs, 10),
56
+ maxTotalClaim: BigNumber(data.maxTotalClaim),
57
+ maxNumNodes: BigNumber(data.maxNumNodes),
58
+ unlockPeriod: BigNumber(data.unlockPeriod),
59
+ startVestingTs: BigNumber(data.startVestingTs),
60
+ endVestingTs: BigNumber(data.endVestingTs),
61
+ clawbackStartTs: BigNumber(data.clawbackStartTs),
61
62
  claimsClosable: data.claimsClosable,
62
63
  };
63
64
  const accounts = {
@@ -71,12 +72,12 @@ export default class SolanaDistributorClient {
71
72
  tokenProgram: tokenProgramId,
72
73
  };
73
74
  if (extParams.isNative) {
74
- ixs.push(...(await prepareWrappedAccount(this.connection, extParams.invoker.publicKey, data.maxTotalClaim)));
75
+ ixs.push(...(await prepareWrappedAccount(this.connection, extParams.invoker.publicKey, BigNumber(data.maxTotalClaim))));
75
76
  }
76
- const nowTs = new BN(Math.floor(Date.now() / 1000));
77
- const endVestingTs = args.endVestingTs.eqn(0) ? nowTs : args.endVestingTs;
78
- const startVestingTs = args.startVestingTs.eqn(0) ? nowTs : args.startVestingTs;
79
- if (endVestingTs.gt(startVestingTs) && endVestingTs.sub(startVestingTs).lt(args.unlockPeriod)) {
77
+ const nowTs = BigNumber(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)) {
80
81
  throw new Error("The unlock period cannot be longer than the total vesting duration!");
81
82
  }
82
83
  ixs.push(newDistributor(args, accounts, this.programId));
@@ -129,14 +130,15 @@ export default class SolanaDistributorClient {
129
130
  };
130
131
  if (!claimStatus) {
131
132
  const args = {
132
- amountLocked: data.amountLocked,
133
- amountUnlocked: data.amountUnlocked,
133
+ amountLocked: BigNumber(data.amountLocked),
134
+ amountUnlocked: BigNumber(data.amountUnlocked),
134
135
  proof: data.proof,
135
136
  };
136
137
  ixs.push(newClaim(args, accounts, this.programId));
137
138
  }
138
- const nowTs = new BN(Math.floor(Date.now() / 1000));
139
- if (claimStatus || (data.amountLocked.gtn(0) && nowTs.sub(distributor.startTs).gte(distributor.unlockPeriod))) {
139
+ const nowTs = BigNumber(Math.floor(Date.now() / 1000));
140
+ if (claimStatus ||
141
+ (BigNumber(data.amountLocked).gt(0) && nowTs.minus(distributor.startTs).gte(distributor.unlockPeriod))) {
140
142
  ixs.push(claimLocked(accounts, this.programId));
141
143
  }
142
144
  return ixs;
@@ -185,4 +187,28 @@ export default class SolanaDistributorClient {
185
187
  const distributorPublicKeys = data.ids.map((distributorId) => new PublicKey(distributorId));
186
188
  return MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId);
187
189
  }
190
+ async searchDistributors(data) {
191
+ const filters = [{ memcmp: { offset: 0, bytes: bs58.encode(MerkleDistributor.discriminator) } }];
192
+ if (data.mint) {
193
+ filters.push({
194
+ memcmp: {
195
+ offset: DISTRIBUTOR_MINT_OFFSET,
196
+ bytes: data.mint,
197
+ },
198
+ });
199
+ }
200
+ if (data.admin) {
201
+ filters.push({
202
+ memcmp: {
203
+ offset: DISTRIBUTOR_ADMIN_OFFSET,
204
+ bytes: data.admin,
205
+ },
206
+ });
207
+ }
208
+ const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
209
+ return accounts.map(({ pubkey, account }) => ({
210
+ publicKey: pubkey,
211
+ account: MerkleDistributor.decode(account.data),
212
+ }));
213
+ }
188
214
  }
@@ -1,3 +1,6 @@
1
+ export declare const ANCHOR_DISCRIMINATOR_OFFSET = 8;
2
+ export declare const DISTRIBUTOR_MINT_OFFSET: number;
3
+ export declare const DISTRIBUTOR_ADMIN_OFFSET: number;
1
4
  export declare const ONE_IN_BASIS_POINTS: bigint;
2
5
  export declare const DISTRIBUTOR_PROGRAM_ID: {
3
6
  devnet: string;
@@ -1,4 +1,7 @@
1
1
  import { ICluster } from "@streamflow/common";
2
+ export const ANCHOR_DISCRIMINATOR_OFFSET = 8;
3
+ export const DISTRIBUTOR_MINT_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 41;
4
+ export const DISTRIBUTOR_ADMIN_OFFSET = ANCHOR_DISCRIMINATOR_OFFSET + 201;
2
5
  export const ONE_IN_BASIS_POINTS = BigInt(10000);
3
6
  export const DISTRIBUTOR_PROGRAM_ID = {
4
7
  [ICluster.Devnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
@@ -1,19 +1,19 @@
1
1
  /// <reference types="node" />
2
2
  import { PublicKey, Connection } from "@solana/web3.js";
3
- import BN from "bn.js";
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: BN;
8
+ lockedAmount: BigNumber;
9
9
  /** Locked amount withdrawn */
10
- lockedAmountWithdrawn: BN;
10
+ lockedAmountWithdrawn: BigNumber;
11
11
  /** Unlocked amount */
12
- unlockedAmount: BN;
12
+ unlockedAmount: BigNumber;
13
13
  /** Last claim time */
14
- lastClaimTs: BN;
14
+ lastClaimTs: BigNumber;
15
15
  /** Track amount per unlock, can be useful for non-linear vesting */
16
- lastAmountPerUnlock: BN;
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: BN;
49
+ readonly lockedAmount: BigNumber;
50
50
  /** Locked amount withdrawn */
51
- readonly lockedAmountWithdrawn: BN;
51
+ readonly lockedAmountWithdrawn: BigNumber;
52
52
  /** Unlocked amount */
53
- readonly unlockedAmount: BN;
53
+ readonly unlockedAmount: BigNumber;
54
54
  /** Last claim time */
55
- readonly lastClaimTs: BN;
55
+ readonly lastClaimTs: BigNumber;
56
56
  /** Track amount per unlock, can be useful for non-linear vesting */
57
- readonly lastAmountPerUnlock: BN;
57
+ readonly lastAmountPerUnlock: BigNumber;
58
58
  /** Whether claim is closed */
59
59
  readonly closed: boolean;
60
60
  /** Buffer for additional fields */
@@ -1,5 +1,5 @@
1
1
  import { PublicKey } from "@solana/web3.js";
2
- import BN from "bn.js"; // eslint-disable-line @typescript-eslint/no-unused-vars
2
+ import BigNumber from "bignumber.js"; // eslint-disable-line @typescript-eslint/no-unused-vars
3
3
  import * as borsh from "@coral-xyz/borsh"; // eslint-disable-line @typescript-eslint/no-unused-vars
4
4
  import { PROGRAM_ID } from "../programId";
5
5
  /** Holds whether or not a claimant has claimed tokens. */
@@ -100,11 +100,11 @@ export class ClaimStatus {
100
100
  static fromJSON(obj) {
101
101
  return new ClaimStatus({
102
102
  claimant: new PublicKey(obj.claimant),
103
- lockedAmount: new BN(obj.lockedAmount),
104
- lockedAmountWithdrawn: new BN(obj.lockedAmountWithdrawn),
105
- unlockedAmount: new BN(obj.unlockedAmount),
106
- lastClaimTs: new BN(obj.lastClaimTs),
107
- lastAmountPerUnlock: new BN(obj.lastAmountPerUnlock),
103
+ lockedAmount: BigNumber(obj.lockedAmount),
104
+ lockedAmountWithdrawn: BigNumber(obj.lockedAmountWithdrawn),
105
+ unlockedAmount: BigNumber(obj.unlockedAmount),
106
+ lastClaimTs: BigNumber(obj.lastClaimTs),
107
+ lastAmountPerUnlock: BigNumber(obj.lastAmountPerUnlock),
108
108
  closed: obj.closed,
109
109
  buffer1: obj.buffer1,
110
110
  buffer2: obj.buffer2,