@streamflow/distributor 6.5.0 → 7.0.0-alpha.10

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 (76) hide show
  1. package/README.md +4 -5
  2. package/dist/{index.js → cjs/index.js} +1 -1
  3. package/dist/cjs/solana/client.js +216 -0
  4. package/dist/{solana → cjs/solana}/constants.js +7 -8
  5. package/dist/cjs/solana/generated/accounts/ClaimStatus.js +125 -0
  6. package/dist/cjs/solana/generated/accounts/MerkleDistributor.js +180 -0
  7. package/dist/cjs/solana/generated/errors/anchor.js +712 -0
  8. package/dist/cjs/solana/generated/errors/custom.js +256 -0
  9. package/dist/cjs/solana/generated/errors/index.js +65 -0
  10. package/dist/{solana → cjs/solana}/generated/instructions/claimLocked.js +7 -8
  11. package/dist/{solana → cjs/solana}/generated/instructions/clawback.js +8 -8
  12. package/dist/{solana → cjs/solana}/generated/instructions/closeClaim.js +8 -8
  13. package/dist/{solana → cjs/solana}/generated/instructions/newClaim.js +10 -11
  14. package/dist/{solana → cjs/solana}/generated/instructions/newDistributor.js +11 -11
  15. package/dist/cjs/solana/generated/instructions/setAdmin.js +18 -0
  16. package/dist/cjs/solana/generated/instructions/setClawbackReceiver.js +18 -0
  17. package/dist/{solana → cjs/solana}/generated/programId.js +1 -1
  18. package/dist/{solana → cjs/solana}/index.js +6 -6
  19. package/dist/cjs/solana/utils.js +69 -0
  20. package/dist/esm/index.d.ts +1 -0
  21. package/dist/esm/index.js +1 -0
  22. package/dist/esm/solana/client.js +214 -0
  23. package/dist/esm/solana/constants.js +11 -0
  24. package/dist/{solana → esm/solana}/generated/accounts/ClaimStatus.d.ts +11 -11
  25. package/dist/esm/solana/generated/accounts/ClaimStatus.js +113 -0
  26. package/dist/{solana → esm/solana}/generated/accounts/MerkleDistributor.d.ts +19 -19
  27. package/dist/esm/solana/generated/accounts/MerkleDistributor.js +190 -0
  28. package/dist/esm/solana/generated/accounts/index.js +2 -0
  29. package/dist/esm/solana/generated/errors/anchor.js +707 -0
  30. package/dist/esm/solana/generated/errors/custom.js +252 -0
  31. package/dist/esm/solana/generated/errors/index.js +37 -0
  32. package/dist/esm/solana/generated/instructions/claimLocked.js +19 -0
  33. package/dist/esm/solana/generated/instructions/clawback.js +18 -0
  34. package/dist/esm/solana/generated/instructions/closeClaim.js +18 -0
  35. package/dist/esm/solana/generated/instructions/index.js +7 -0
  36. package/dist/{solana → esm/solana}/generated/instructions/newClaim.d.ts +3 -3
  37. package/dist/esm/solana/generated/instructions/newClaim.js +32 -0
  38. package/dist/{solana → esm/solana}/generated/instructions/newDistributor.d.ts +8 -8
  39. package/dist/esm/solana/generated/instructions/newDistributor.js +73 -0
  40. package/dist/esm/solana/generated/instructions/setAdmin.js +14 -0
  41. package/dist/esm/solana/generated/instructions/setClawbackReceiver.js +14 -0
  42. package/dist/esm/solana/generated/programId.js +5 -0
  43. package/dist/esm/solana/index.d.ts +7 -0
  44. package/dist/esm/solana/index.js +7 -0
  45. package/dist/{solana → esm/solana}/types.d.ts +5 -5
  46. package/dist/esm/solana/types.js +156 -0
  47. package/dist/esm/solana/utils.js +60 -0
  48. package/package.json +21 -21
  49. package/dist/index.d.ts +0 -1
  50. package/dist/solana/client.js +0 -402
  51. package/dist/solana/generated/accounts/ClaimStatus.js +0 -183
  52. package/dist/solana/generated/accounts/MerkleDistributor.js +0 -238
  53. package/dist/solana/generated/errors/anchor.js +0 -889
  54. package/dist/solana/generated/errors/custom.js +0 -328
  55. package/dist/solana/generated/errors/index.js +0 -104
  56. package/dist/solana/generated/instructions/setAdmin.js +0 -18
  57. package/dist/solana/generated/instructions/setClawbackReceiver.js +0 -18
  58. package/dist/solana/index.d.ts +0 -7
  59. package/dist/solana/utils.js +0 -122
  60. /package/dist/{solana → cjs/solana}/generated/accounts/index.js +0 -0
  61. /package/dist/{solana → cjs/solana}/generated/instructions/index.js +0 -0
  62. /package/dist/{solana → cjs/solana}/types.js +0 -0
  63. /package/dist/{solana → esm/solana}/client.d.ts +0 -0
  64. /package/dist/{solana → esm/solana}/constants.d.ts +0 -0
  65. /package/dist/{solana → esm/solana}/generated/accounts/index.d.ts +0 -0
  66. /package/dist/{solana → esm/solana}/generated/errors/anchor.d.ts +0 -0
  67. /package/dist/{solana → esm/solana}/generated/errors/custom.d.ts +0 -0
  68. /package/dist/{solana → esm/solana}/generated/errors/index.d.ts +0 -0
  69. /package/dist/{solana → esm/solana}/generated/instructions/claimLocked.d.ts +0 -0
  70. /package/dist/{solana → esm/solana}/generated/instructions/clawback.d.ts +0 -0
  71. /package/dist/{solana → esm/solana}/generated/instructions/closeClaim.d.ts +0 -0
  72. /package/dist/{solana → esm/solana}/generated/instructions/index.d.ts +0 -0
  73. /package/dist/{solana → esm/solana}/generated/instructions/setAdmin.d.ts +0 -0
  74. /package/dist/{solana → esm/solana}/generated/instructions/setClawbackReceiver.d.ts +0 -0
  75. /package/dist/{solana → esm/solana}/generated/programId.d.ts +0 -0
  76. /package/dist/{solana → esm/solana}/utils.d.ts +0 -0
package/README.md CHANGED
@@ -26,7 +26,6 @@ Automated Airdrop Creation: [notion doc →](https://streamflow.notion.site/Auto
26
26
  Most common imports:
27
27
 
28
28
  ```javascript
29
- import { BN } from "bn.js";
30
29
  import { ICluster } from "@streamflow/common";
31
30
  import { SolanaDistributorClient } from "@streamflow/distributor/solana";
32
31
  ```
@@ -62,8 +61,8 @@ const res = await client.create(
62
61
  54, 218, 49, 68, 131, 214, 250, 113, 37, 143, 167, 73, 17, 54, 233, 26, 141, 93, 28, 186, 137, 211, 251, 205,
63
62
  240, 192, 134, 208, 108, 246, 0, 191,
64
63
  ], // Merkle root
65
- maxNumNodes: new BN("4"), // Number of recipients
66
- maxTotalClaim: new BN("4000000000"), // Total amount to distribute
64
+ maxNumNodes: 4, // Number of recipients
65
+ maxTotalClaim: "4000000000", // Total amount to distribute
67
66
  unlockPeriod: 1, // Unlock period in seconds
68
67
  startVestingTs: 0, // Timestamp when Airdrop starts
69
68
  endVestingTs: now + 3600 * 24 * 7, // Timestamp when Airdrop ends
@@ -94,8 +93,8 @@ const claimRes = await client.claim(
94
93
  43, 104, 75, 183, 12, 38, 37, 153,
95
94
  ],
96
95
  ], // Merkle Proof used to verify claim
97
- amountUnlocked: new BN("0"), // Total amount unlocked for a Recipient
98
- amountLocked: new BN("1000000000"), // Total amount locked for a Recipient
96
+ amountUnlocked: "0", // Total amount unlocked for a Recipient
97
+ amountLocked: "1000000000", // Total amount locked for a Recipient
99
98
  },
100
99
  solanaParams,
101
100
  );
@@ -24,4 +24,4 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.StreamflowDistributorSolana = void 0;
27
- exports.StreamflowDistributorSolana = __importStar(require("./solana"));
27
+ exports.StreamflowDistributorSolana = __importStar(require("./solana/index.js"));
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
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 {
17
+ /**
18
+ * Create Stream instance
19
+ */
20
+ constructor({ clusterUrl, cluster = common_1.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler, }) {
21
+ this.commitment = commitment;
22
+ this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
23
+ this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_1.DISTRIBUTOR_PROGRAM_ID[cluster]);
24
+ this.sendThrottler = sendThrottler ?? (0, solana_1.buildSendThrottler)(sendRate);
25
+ }
26
+ getCommitment() {
27
+ return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
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));
184
+ });
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
+ },
199
+ });
200
+ }
201
+ if (data.admin) {
202
+ filters.push({
203
+ memcmp: {
204
+ offset: constants_1.DISTRIBUTOR_ADMIN_OFFSET,
205
+ bytes: data.admin,
206
+ },
207
+ });
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
+ }
216
+ exports.default = SolanaDistributorClient;
@@ -1,15 +1,14 @@
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 = exports.DISTRIBUTOR_ADMIN_OFFSET = exports.DISTRIBUTOR_MINT_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET = void 0;
5
- var common_1 = require("@streamflow/common");
4
+ const common_1 = require("@streamflow/common");
6
5
  exports.ANCHOR_DISCRIMINATOR_OFFSET = 8;
7
6
  exports.DISTRIBUTOR_MINT_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET + 41;
8
7
  exports.DISTRIBUTOR_ADMIN_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET + 201;
9
8
  exports.ONE_IN_BASIS_POINTS = BigInt(10000);
10
- exports.DISTRIBUTOR_PROGRAM_ID = (_a = {},
11
- _a[common_1.ICluster.Devnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
12
- _a[common_1.ICluster.Mainnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
13
- _a[common_1.ICluster.Testnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
14
- _a[common_1.ICluster.Local] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
15
- _a);
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
+ };
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.ClaimStatus = void 0;
30
+ const web3_js_1 = require("@solana/web3.js");
31
+ const bignumber_js_1 = __importDefault(require("bignumber.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
32
+ const borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
33
+ const programId_1 = require("../programId");
34
+ /** Holds whether or not a claimant has claimed tokens. */
35
+ class ClaimStatus {
36
+ constructor(fields) {
37
+ this.claimant = fields.claimant;
38
+ this.lockedAmount = fields.lockedAmount;
39
+ this.lockedAmountWithdrawn = fields.lockedAmountWithdrawn;
40
+ this.unlockedAmount = fields.unlockedAmount;
41
+ this.lastClaimTs = fields.lastClaimTs;
42
+ this.lastAmountPerUnlock = fields.lastAmountPerUnlock;
43
+ this.closed = fields.closed;
44
+ this.buffer1 = fields.buffer1;
45
+ this.buffer2 = fields.buffer2;
46
+ }
47
+ static async fetch(c, address, programId = programId_1.PROGRAM_ID) {
48
+ const info = await c.getAccountInfo(address);
49
+ if (info === null) {
50
+ return null;
51
+ }
52
+ if (!info.owner.equals(programId)) {
53
+ throw new Error("account doesn't belong to this program");
54
+ }
55
+ return this.decode(info.data);
56
+ }
57
+ static async fetchMultiple(c, addresses, programId = programId_1.PROGRAM_ID) {
58
+ const infos = await c.getMultipleAccountsInfo(addresses);
59
+ return infos.map((info) => {
60
+ if (info === null) {
61
+ return null;
62
+ }
63
+ if (!info.owner.equals(programId)) {
64
+ throw new Error("account doesn't belong to this program");
65
+ }
66
+ return this.decode(info.data);
67
+ });
68
+ }
69
+ static decode(data) {
70
+ if (!data.slice(0, 8).equals(ClaimStatus.discriminator)) {
71
+ throw new Error("invalid account discriminator");
72
+ }
73
+ const dec = ClaimStatus.layout.decode(data.slice(8));
74
+ return new ClaimStatus({
75
+ claimant: dec.claimant,
76
+ lockedAmount: dec.lockedAmount,
77
+ lockedAmountWithdrawn: dec.lockedAmountWithdrawn,
78
+ unlockedAmount: dec.unlockedAmount,
79
+ lastClaimTs: dec.lastClaimTs,
80
+ lastAmountPerUnlock: dec.lastAmountPerUnlock,
81
+ closed: dec.closed,
82
+ buffer1: dec.buffer1,
83
+ buffer2: dec.buffer2,
84
+ });
85
+ }
86
+ toJSON() {
87
+ return {
88
+ claimant: this.claimant.toString(),
89
+ lockedAmount: this.lockedAmount.toString(),
90
+ lockedAmountWithdrawn: this.lockedAmountWithdrawn.toString(),
91
+ unlockedAmount: this.unlockedAmount.toString(),
92
+ lastClaimTs: this.lastClaimTs.toString(),
93
+ lastAmountPerUnlock: this.lastAmountPerUnlock.toString(),
94
+ closed: this.closed,
95
+ buffer1: this.buffer1,
96
+ buffer2: this.buffer2,
97
+ };
98
+ }
99
+ static fromJSON(obj) {
100
+ return new ClaimStatus({
101
+ claimant: new web3_js_1.PublicKey(obj.claimant),
102
+ lockedAmount: (0, bignumber_js_1.default)(obj.lockedAmount),
103
+ lockedAmountWithdrawn: (0, bignumber_js_1.default)(obj.lockedAmountWithdrawn),
104
+ unlockedAmount: (0, bignumber_js_1.default)(obj.unlockedAmount),
105
+ lastClaimTs: (0, bignumber_js_1.default)(obj.lastClaimTs),
106
+ lastAmountPerUnlock: (0, bignumber_js_1.default)(obj.lastAmountPerUnlock),
107
+ closed: obj.closed,
108
+ buffer1: obj.buffer1,
109
+ buffer2: obj.buffer2,
110
+ });
111
+ }
112
+ }
113
+ exports.ClaimStatus = ClaimStatus;
114
+ ClaimStatus.discriminator = Buffer.from([22, 183, 249, 157, 247, 95, 150, 96]);
115
+ ClaimStatus.layout = borsh.struct([
116
+ borsh.publicKey("claimant"),
117
+ borsh.u64("lockedAmount"),
118
+ borsh.u64("lockedAmountWithdrawn"),
119
+ borsh.u64("unlockedAmount"),
120
+ borsh.u64("lastClaimTs"),
121
+ borsh.u64("lastAmountPerUnlock"),
122
+ borsh.bool("closed"),
123
+ borsh.array(borsh.u8(), 32, "buffer1"),
124
+ borsh.array(borsh.u8(), 32, "buffer2"),
125
+ ]);
@@ -0,0 +1,180 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.MerkleDistributor = void 0;
30
+ const web3_js_1 = require("@solana/web3.js");
31
+ const bignumber_js_1 = __importDefault(require("bignumber.js")); // eslint-disable-line @typescript-eslint/no-unused-vars
32
+ const borsh = __importStar(require("@coral-xyz/borsh")); // eslint-disable-line @typescript-eslint/no-unused-vars
33
+ const programId_1 = require("../programId");
34
+ /** State for the account which distributes tokens. */
35
+ class MerkleDistributor {
36
+ constructor(fields) {
37
+ this.bump = fields.bump;
38
+ this.version = fields.version;
39
+ this.root = fields.root;
40
+ this.mint = fields.mint;
41
+ this.tokenVault = fields.tokenVault;
42
+ this.maxTotalClaim = fields.maxTotalClaim;
43
+ this.maxNumNodes = fields.maxNumNodes;
44
+ this.unlockPeriod = fields.unlockPeriod;
45
+ this.totalAmountClaimed = fields.totalAmountClaimed;
46
+ this.numNodesClaimed = fields.numNodesClaimed;
47
+ this.startTs = fields.startTs;
48
+ this.endTs = fields.endTs;
49
+ this.clawbackStartTs = fields.clawbackStartTs;
50
+ this.clawbackReceiver = fields.clawbackReceiver;
51
+ this.admin = fields.admin;
52
+ this.clawedBack = fields.clawedBack;
53
+ this.claimsClosable = fields.claimsClosable;
54
+ this.buffer1 = fields.buffer1;
55
+ this.buffer2 = fields.buffer2;
56
+ this.buffer3 = fields.buffer3;
57
+ }
58
+ static async fetch(c, address, programId = programId_1.PROGRAM_ID) {
59
+ const info = await c.getAccountInfo(address);
60
+ if (info === null) {
61
+ return null;
62
+ }
63
+ if (!info.owner.equals(programId)) {
64
+ throw new Error("account doesn't belong to this program");
65
+ }
66
+ return this.decode(info.data);
67
+ }
68
+ static async fetchMultiple(c, addresses, programId = programId_1.PROGRAM_ID) {
69
+ const infos = await c.getMultipleAccountsInfo(addresses);
70
+ return infos.map((info) => {
71
+ if (info === null) {
72
+ return null;
73
+ }
74
+ if (!info.owner.equals(programId)) {
75
+ throw new Error("account doesn't belong to this program");
76
+ }
77
+ return this.decode(info.data);
78
+ });
79
+ }
80
+ static decode(data) {
81
+ if (!data.slice(0, 8).equals(MerkleDistributor.discriminator)) {
82
+ throw new Error("invalid account discriminator");
83
+ }
84
+ const dec = MerkleDistributor.layout.decode(data.slice(8));
85
+ return new MerkleDistributor({
86
+ bump: dec.bump,
87
+ version: dec.version,
88
+ root: dec.root,
89
+ mint: dec.mint,
90
+ tokenVault: dec.tokenVault,
91
+ maxTotalClaim: dec.maxTotalClaim,
92
+ maxNumNodes: dec.maxNumNodes,
93
+ unlockPeriod: dec.unlockPeriod,
94
+ totalAmountClaimed: dec.totalAmountClaimed,
95
+ numNodesClaimed: dec.numNodesClaimed,
96
+ startTs: dec.startTs,
97
+ endTs: dec.endTs,
98
+ clawbackStartTs: dec.clawbackStartTs,
99
+ clawbackReceiver: dec.clawbackReceiver,
100
+ admin: dec.admin,
101
+ clawedBack: dec.clawedBack,
102
+ claimsClosable: dec.claimsClosable,
103
+ buffer1: dec.buffer1,
104
+ buffer2: dec.buffer2,
105
+ buffer3: dec.buffer3,
106
+ });
107
+ }
108
+ toJSON() {
109
+ return {
110
+ bump: this.bump,
111
+ version: this.version.toString(),
112
+ root: this.root,
113
+ mint: this.mint.toString(),
114
+ tokenVault: this.tokenVault.toString(),
115
+ maxTotalClaim: this.maxTotalClaim.toString(),
116
+ maxNumNodes: this.maxNumNodes.toString(),
117
+ unlockPeriod: this.unlockPeriod.toString(),
118
+ totalAmountClaimed: this.totalAmountClaimed.toString(),
119
+ numNodesClaimed: this.numNodesClaimed.toString(),
120
+ startTs: this.startTs.toString(),
121
+ endTs: this.endTs.toString(),
122
+ clawbackStartTs: this.clawbackStartTs.toString(),
123
+ clawbackReceiver: this.clawbackReceiver.toString(),
124
+ admin: this.admin.toString(),
125
+ clawedBack: this.clawedBack,
126
+ claimsClosable: this.claimsClosable,
127
+ buffer1: this.buffer1,
128
+ buffer2: this.buffer2,
129
+ buffer3: this.buffer3,
130
+ };
131
+ }
132
+ static fromJSON(obj) {
133
+ return new MerkleDistributor({
134
+ bump: obj.bump,
135
+ version: (0, bignumber_js_1.default)(obj.version),
136
+ root: obj.root,
137
+ mint: new web3_js_1.PublicKey(obj.mint),
138
+ tokenVault: new web3_js_1.PublicKey(obj.tokenVault),
139
+ maxTotalClaim: (0, bignumber_js_1.default)(obj.maxTotalClaim),
140
+ maxNumNodes: (0, bignumber_js_1.default)(obj.maxNumNodes),
141
+ unlockPeriod: (0, bignumber_js_1.default)(obj.unlockPeriod),
142
+ totalAmountClaimed: (0, bignumber_js_1.default)(obj.totalAmountClaimed),
143
+ numNodesClaimed: (0, bignumber_js_1.default)(obj.numNodesClaimed),
144
+ startTs: (0, bignumber_js_1.default)(obj.startTs),
145
+ endTs: (0, bignumber_js_1.default)(obj.endTs),
146
+ clawbackStartTs: (0, bignumber_js_1.default)(obj.clawbackStartTs),
147
+ clawbackReceiver: new web3_js_1.PublicKey(obj.clawbackReceiver),
148
+ admin: new web3_js_1.PublicKey(obj.admin),
149
+ clawedBack: obj.clawedBack,
150
+ claimsClosable: obj.claimsClosable,
151
+ buffer1: obj.buffer1,
152
+ buffer2: obj.buffer2,
153
+ buffer3: obj.buffer3,
154
+ });
155
+ }
156
+ }
157
+ exports.MerkleDistributor = MerkleDistributor;
158
+ MerkleDistributor.discriminator = Buffer.from([77, 119, 139, 70, 84, 247, 12, 26]);
159
+ MerkleDistributor.layout = borsh.struct([
160
+ borsh.u8("bump"),
161
+ borsh.u64("version"),
162
+ borsh.array(borsh.u8(), 32, "root"),
163
+ borsh.publicKey("mint"),
164
+ borsh.publicKey("tokenVault"),
165
+ borsh.u64("maxTotalClaim"),
166
+ borsh.u64("maxNumNodes"),
167
+ borsh.u64("unlockPeriod"),
168
+ borsh.u64("totalAmountClaimed"),
169
+ borsh.u64("numNodesClaimed"),
170
+ borsh.u64("startTs"),
171
+ borsh.u64("endTs"),
172
+ borsh.u64("clawbackStartTs"),
173
+ borsh.publicKey("clawbackReceiver"),
174
+ borsh.publicKey("admin"),
175
+ borsh.bool("clawedBack"),
176
+ borsh.bool("claimsClosable"),
177
+ borsh.array(borsh.u8(), 32, "buffer1"),
178
+ borsh.array(borsh.u8(), 32, "buffer2"),
179
+ borsh.array(borsh.u8(), 32, "buffer3"),
180
+ ]);