@streamflow/distributor 7.0.0-alpha.2 → 7.0.0-alpha.20

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 (54) hide show
  1. package/README.md +19 -3
  2. package/dist/cjs/index.js +1 -1
  3. package/dist/cjs/solana/clients/BaseDistributorClient.js +222 -0
  4. package/dist/cjs/solana/clients/SolanaAlignedDistributorClient.js +104 -0
  5. package/dist/cjs/solana/clients/SolanaDistributorClient.js +17 -0
  6. package/dist/cjs/solana/clients/index.js +10 -0
  7. package/dist/cjs/solana/constants.js +22 -9
  8. package/dist/cjs/solana/descriptor/aligned_distributor.js +2 -0
  9. package/dist/cjs/solana/descriptor/idl/aligned_distributor.json +1242 -0
  10. package/dist/cjs/solana/generated/accounts/ClaimStatus.js +56 -114
  11. package/dist/cjs/solana/generated/accounts/MerkleDistributor.js +96 -129
  12. package/dist/cjs/solana/generated/errors/anchor.js +540 -717
  13. package/dist/cjs/solana/generated/errors/custom.js +171 -243
  14. package/dist/cjs/solana/generated/errors/index.js +12 -51
  15. package/dist/cjs/solana/generated/instructions/claimLocked.js +7 -8
  16. package/dist/cjs/solana/generated/instructions/clawback.js +8 -9
  17. package/dist/cjs/solana/generated/instructions/closeClaim.js +8 -9
  18. package/dist/cjs/solana/generated/instructions/newClaim.js +10 -11
  19. package/dist/cjs/solana/generated/instructions/newDistributor.js +17 -12
  20. package/dist/cjs/solana/generated/instructions/setAdmin.js +8 -9
  21. package/dist/cjs/solana/generated/instructions/setClawbackReceiver.js +8 -9
  22. package/dist/cjs/solana/generated/programId.js +1 -1
  23. package/dist/cjs/solana/index.js +8 -12
  24. package/dist/cjs/solana/utils.js +46 -94
  25. package/dist/esm/index.d.ts +1 -1
  26. package/dist/esm/index.js +1 -1
  27. package/dist/esm/solana/clients/BaseDistributorClient.d.ts +39 -0
  28. package/dist/esm/solana/{client.js → clients/BaseDistributorClient.js} +97 -66
  29. package/dist/esm/solana/clients/SolanaAlignedDistributorClient.d.ts +14 -0
  30. package/dist/esm/solana/clients/SolanaAlignedDistributorClient.js +99 -0
  31. package/dist/esm/solana/clients/SolanaDistributorClient.d.ts +8 -0
  32. package/dist/esm/solana/clients/SolanaDistributorClient.js +11 -0
  33. package/dist/esm/solana/clients/index.d.ts +2 -0
  34. package/dist/esm/solana/clients/index.js +2 -0
  35. package/dist/esm/solana/constants.d.ts +15 -0
  36. package/dist/esm/solana/constants.js +14 -0
  37. package/dist/esm/solana/descriptor/aligned_distributor.d.ts +918 -0
  38. package/dist/esm/solana/descriptor/aligned_distributor.js +1 -0
  39. package/dist/esm/solana/descriptor/idl/aligned_distributor.json +1242 -0
  40. package/dist/esm/solana/generated/accounts/ClaimStatus.d.ts +17 -17
  41. package/dist/esm/solana/generated/accounts/ClaimStatus.js +13 -13
  42. package/dist/esm/solana/generated/accounts/MerkleDistributor.d.ts +55 -25
  43. package/dist/esm/solana/generated/accounts/MerkleDistributor.js +53 -18
  44. package/dist/esm/solana/generated/instructions/newClaim.d.ts +3 -3
  45. package/dist/esm/solana/generated/instructions/newDistributor.d.ts +8 -8
  46. package/dist/esm/solana/generated/instructions/newDistributor.js +6 -0
  47. package/dist/esm/solana/index.d.ts +7 -7
  48. package/dist/esm/solana/index.js +7 -7
  49. package/dist/esm/solana/types.d.ts +49 -4
  50. package/dist/esm/solana/utils.d.ts +2 -1
  51. package/dist/esm/solana/utils.js +11 -6
  52. package/package.json +9 -7
  53. package/dist/cjs/solana/client.js +0 -365
  54. package/dist/esm/solana/client.d.ts +0 -36
package/README.md CHANGED
@@ -19,6 +19,8 @@ or
19
19
  ## Documentation
20
20
  API Documentation available here: [docs site →](https://streamflow-finance.github.io/js-sdk/)
21
21
 
22
+ Automated Airdrop Creation: [notion doc →](https://streamflow.notion.site/Automated-Airdrop-Creation-45b84bfd2dda4d7196be5dd02eed29c8)
23
+
22
24
  ## Import SDK
23
25
 
24
26
  Most common imports:
@@ -60,7 +62,7 @@ const res = await client.create(
60
62
  240, 192, 134, 208, 108, 246, 0, 191,
61
63
  ], // Merkle root
62
64
  maxNumNodes: 4, // Number of recipients
63
- maxTotalClaim: "4000000000", // Total amount to distribute
65
+ maxTotalClaim: new BN("4000000000"), // Total amount to distribute
64
66
  unlockPeriod: 1, // Unlock period in seconds
65
67
  startVestingTs: 0, // Timestamp when Airdrop starts
66
68
  endVestingTs: now + 3600 * 24 * 7, // Timestamp when Airdrop ends
@@ -91,8 +93,8 @@ const claimRes = await client.claim(
91
93
  43, 104, 75, 183, 12, 38, 37, 153,
92
94
  ],
93
95
  ], // Merkle Proof used to verify claim
94
- amountUnlocked: "0", // Total amount unlocked for a Recipient
95
- amountLocked: "1000000000", // Total amount locked for a Recipient
96
+ amountUnlocked: new BN("0"), // Total amount unlocked for a Recipient
97
+ amountLocked: new BN("1000000000"), // Total amount locked for a Recipient
96
98
  },
97
99
  solanaParams,
98
100
  );
@@ -111,6 +113,20 @@ const solanaParams = {
111
113
  const clawbackRes = await client.clawback({ id: res.metadataId }, solanaParams);
112
114
  ```
113
115
 
116
+ ## Search Airdrops
117
+
118
+ As all the data is stored on-chain you can also search Airdrops with `searchDistributors` method:
119
+
120
+ ```javascript
121
+ // All parameters are optional, so in theory you just fetch all Distributors
122
+ const params = {
123
+ mint: "BZLbGTNCSFfoth2GYDtwr7e4imWzpR5jqcUuGEwr646K",
124
+ admin: "s3pWmY359mDrNRnDBZ3v5TrrqqxvxiW2t4U2WZyxRoA"
125
+ };
126
+ // Return an Array of objects {publicKey: PublicKey, account: Distributor}
127
+ const disributors = await client.searchDistributors(params);
128
+ ```
129
+
114
130
  ## Handling errors
115
131
 
116
132
  `GenericStreamClient` wraps all errors when making on-chain calls with `ContractError` error class:
package/dist/cjs/index.js CHANGED
@@ -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,222 @@
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 bn_js_1 = __importDefault(require("bn.js"));
7
+ const web3_js_1 = require("@solana/web3.js");
8
+ const common_1 = require("@streamflow/common");
9
+ const solana_1 = require("@streamflow/common/solana");
10
+ const spl_token_1 = require("@solana/spl-token");
11
+ const bs58_1 = __importDefault(require("bs58"));
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 BaseDistributorClient {
17
+ constructor({ clusterUrl, cluster = common_1.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler, }) {
18
+ this.commitment = commitment;
19
+ this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
20
+ this.programId = programId !== "" ? new web3_js_1.PublicKey(programId) : new web3_js_1.PublicKey(constants_1.DISTRIBUTOR_PROGRAM_ID[cluster]);
21
+ this.sendThrottler = sendThrottler ?? (0, solana_1.buildSendThrottler)(sendRate);
22
+ }
23
+ getCommitment() {
24
+ return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
25
+ }
26
+ getDistributorProgramId() {
27
+ return this.programId;
28
+ }
29
+ async prepareCreateInstructions(data, extParams) {
30
+ if (!extParams.invoker.publicKey) {
31
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
32
+ }
33
+ const { version, mint } = data;
34
+ const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, extParams);
35
+ const mintPublicKey = extParams.isNative ? spl_token_1.NATIVE_MINT : new web3_js_1.PublicKey(mint);
36
+ const { mint: mintAccount, tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, mintPublicKey);
37
+ const transferFeeConfig = (0, spl_token_1.getTransferFeeConfig)(mintAccount);
38
+ const distributorPublicKey = (0, utils_1.getDistributorPda)(this.programId, mintPublicKey, version);
39
+ const tokenVault = await (0, solana_1.ata)(mintPublicKey, distributorPublicKey, tokenProgramId);
40
+ const senderTokens = await (0, solana_1.ata)(mintPublicKey, extParams.invoker.publicKey, tokenProgramId);
41
+ const accounts = {
42
+ distributor: distributorPublicKey,
43
+ clawbackReceiver: senderTokens,
44
+ mint: mintPublicKey,
45
+ tokenVault,
46
+ admin: extParams.invoker.publicKey,
47
+ systemProgram: web3_js_1.SystemProgram.programId,
48
+ associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
49
+ tokenProgram: tokenProgramId,
50
+ };
51
+ if (extParams.isNative) {
52
+ ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, extParams.invoker.publicKey, new bn_js_1.default(data.maxTotalClaim))));
53
+ }
54
+ const newDistributorInstruction = await this.getNewDistributorInstruction(data, accounts);
55
+ ixs.push(newDistributorInstruction);
56
+ if (transferFeeConfig) {
57
+ const { transferAmount, feeCharged } = await (0, utils_1.calculateAmountWithTransferFees)(this.connection, transferFeeConfig, BigInt(data.maxTotalClaim.toString()));
58
+ ixs.push((0, spl_token_1.createTransferCheckedWithFeeInstruction)(senderTokens, mintPublicKey, tokenVault, extParams.invoker.publicKey, transferAmount, mintAccount.decimals, feeCharged, undefined, tokenProgramId));
59
+ }
60
+ else {
61
+ ixs.push((0, spl_token_1.createTransferCheckedInstruction)(senderTokens, mintPublicKey, tokenVault, extParams.invoker.publicKey, BigInt(data.maxTotalClaim.toString()), mintAccount.decimals, undefined, tokenProgramId));
62
+ }
63
+ return { distributorPublicKey, ixs };
64
+ }
65
+ async create(data, extParams) {
66
+ const { ixs, distributorPublicKey } = await this.prepareCreateInstructions(data, extParams);
67
+ const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
68
+ const signature = await (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
69
+ hash,
70
+ context,
71
+ commitment: this.getCommitment(),
72
+ }, { sendThrottler: this.sendThrottler });
73
+ return {
74
+ ixs,
75
+ txId: signature,
76
+ metadataId: distributorPublicKey.toBase58(),
77
+ };
78
+ }
79
+ async claim(data, extParams) {
80
+ const ixs = await this.prepareClaimInstructions(data, extParams);
81
+ const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
82
+ const signature = await (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
83
+ hash,
84
+ context,
85
+ commitment: this.getCommitment(),
86
+ }, { sendThrottler: this.sendThrottler });
87
+ return { ixs, txId: signature };
88
+ }
89
+ async prepareClaimInstructions(data, extParams) {
90
+ if (!extParams.invoker.publicKey) {
91
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
92
+ }
93
+ const distributorPublicKey = new web3_js_1.PublicKey(data.id);
94
+ const distributor = await accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey);
95
+ if (!distributor) {
96
+ throw new Error("Couldn't get account info");
97
+ }
98
+ const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, distributor.mint);
99
+ const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, extParams);
100
+ ixs.push(...(await (0, solana_1.checkOrCreateAtaBatch)(this.connection, [extParams.invoker.publicKey], distributor.mint, extParams.invoker, tokenProgramId)));
101
+ const invokerTokens = await (0, solana_1.ata)(distributor.mint, extParams.invoker.publicKey, tokenProgramId);
102
+ const claimStatusPublicKey = (0, utils_1.getClaimantStatusPda)(this.programId, distributorPublicKey, extParams.invoker.publicKey);
103
+ const eventAuthorityPublicKey = (0, utils_1.getEventAuthorityPda)(this.programId);
104
+ const claimStatus = await accounts_1.ClaimStatus.fetch(this.connection, claimStatusPublicKey);
105
+ const accounts = {
106
+ distributor: distributorPublicKey,
107
+ claimStatus: claimStatusPublicKey,
108
+ from: distributor.tokenVault,
109
+ to: invokerTokens,
110
+ claimant: extParams.invoker.publicKey,
111
+ mint: distributor.mint,
112
+ tokenProgram: tokenProgramId,
113
+ systemProgram: web3_js_1.SystemProgram.programId,
114
+ eventAuthority: eventAuthorityPublicKey,
115
+ program: this.programId,
116
+ };
117
+ if (!claimStatus) {
118
+ const args = {
119
+ amountLocked: new bn_js_1.default(data.amountLocked),
120
+ amountUnlocked: new bn_js_1.default(data.amountUnlocked),
121
+ proof: data.proof,
122
+ };
123
+ ixs.push((0, instructions_1.newClaim)(args, accounts, this.programId));
124
+ }
125
+ const nowTs = new bn_js_1.default(Math.floor(Date.now() / 1000));
126
+ if (claimStatus ||
127
+ (new bn_js_1.default(data.amountLocked).gtn(0) && nowTs.sub(distributor.startTs).gte(distributor.unlockPeriod))) {
128
+ ixs.push((0, instructions_1.claimLocked)(accounts, this.programId));
129
+ }
130
+ return ixs;
131
+ }
132
+ async prepareClawbackInstructions(data, extParams) {
133
+ if (!extParams.invoker.publicKey) {
134
+ throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
135
+ }
136
+ const distributorPublicKey = new web3_js_1.PublicKey(data.id);
137
+ const distributor = await accounts_1.MerkleDistributor.fetch(this.connection, distributorPublicKey);
138
+ if (!distributor) {
139
+ throw new Error("Couldn't get account info");
140
+ }
141
+ const { tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection, distributor.mint);
142
+ const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, extParams);
143
+ ixs.push(...(await (0, solana_1.checkOrCreateAtaBatch)(this.connection, [extParams.invoker.publicKey], distributor.mint, extParams.invoker, tokenProgramId)));
144
+ const accounts = {
145
+ distributor: distributorPublicKey,
146
+ from: distributor.tokenVault,
147
+ to: distributor.clawbackReceiver,
148
+ admin: extParams.invoker.publicKey,
149
+ mint: distributor.mint,
150
+ systemProgram: web3_js_1.SystemProgram.programId,
151
+ tokenProgram: tokenProgramId,
152
+ };
153
+ const clawbackInstruction = await this.getClawbackInstruction(accounts);
154
+ ixs.push(clawbackInstruction);
155
+ return ixs;
156
+ }
157
+ async clawback(data, extParams) {
158
+ const ixs = await this.prepareClawbackInstructions(data, extParams);
159
+ const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
160
+ const signature = await (0, utils_1.wrappedSignAndExecuteTransaction)(this.connection, extParams.invoker, tx, {
161
+ hash,
162
+ context,
163
+ commitment: this.getCommitment(),
164
+ }, { sendThrottler: this.sendThrottler });
165
+ return { ixs, txId: signature };
166
+ }
167
+ async getClaims(data) {
168
+ const claimStatusPublicKeys = data.map(({ id, recipient }) => {
169
+ return (0, utils_1.getClaimantStatusPda)(this.programId, new web3_js_1.PublicKey(id), new web3_js_1.PublicKey(recipient));
170
+ });
171
+ return accounts_1.ClaimStatus.fetchMultiple(this.connection, claimStatusPublicKeys, this.programId);
172
+ }
173
+ async getDistributors(data) {
174
+ const distributorPublicKeys = data.ids.map((distributorId) => new web3_js_1.PublicKey(distributorId));
175
+ return accounts_1.MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId);
176
+ }
177
+ async searchDistributors(data) {
178
+ const filters = [{ memcmp: { offset: 0, bytes: bs58_1.default.encode(accounts_1.MerkleDistributor.discriminator) } }];
179
+ if (data.mint) {
180
+ filters.push({
181
+ memcmp: {
182
+ offset: constants_1.DISTRIBUTOR_MINT_OFFSET,
183
+ bytes: data.mint,
184
+ },
185
+ });
186
+ }
187
+ if (data.admin) {
188
+ filters.push({
189
+ memcmp: {
190
+ offset: constants_1.DISTRIBUTOR_ADMIN_OFFSET,
191
+ bytes: data.admin,
192
+ },
193
+ });
194
+ }
195
+ const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
196
+ return accounts.map(({ pubkey, account }) => ({
197
+ publicKey: pubkey,
198
+ account: accounts_1.MerkleDistributor.decode(account.data),
199
+ }));
200
+ }
201
+ getNewDistributorArgs(data) {
202
+ const args = {
203
+ version: new bn_js_1.default(data.version),
204
+ root: data.root,
205
+ maxTotalClaim: new bn_js_1.default(data.maxTotalClaim),
206
+ maxNumNodes: new bn_js_1.default(data.maxNumNodes),
207
+ unlockPeriod: new bn_js_1.default(data.unlockPeriod),
208
+ startVestingTs: new bn_js_1.default(data.startVestingTs),
209
+ endVestingTs: new bn_js_1.default(data.endVestingTs),
210
+ clawbackStartTs: new bn_js_1.default(data.clawbackStartTs),
211
+ claimsClosable: data.claimsClosable,
212
+ };
213
+ const nowTs = new bn_js_1.default(Math.floor(Date.now() / 1000));
214
+ const endVestingTs = args.endVestingTs.isZero() ? nowTs : args.endVestingTs;
215
+ const startVestingTs = args.startVestingTs.isZero() ? nowTs : args.startVestingTs;
216
+ if (endVestingTs.gt(startVestingTs) && endVestingTs.sub(startVestingTs).lt(args.unlockPeriod)) {
217
+ throw new Error("The unlock period cannot be longer than the total vesting duration!");
218
+ }
219
+ return args;
220
+ }
221
+ }
222
+ exports.default = BaseDistributorClient;
@@ -0,0 +1,104 @@
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 bn_js_1 = __importDefault(require("bn.js"));
7
+ const web3_js_1 = require("@solana/web3.js");
8
+ const anchor_1 = require("@coral-xyz/anchor");
9
+ const common_1 = require("@streamflow/common");
10
+ const BaseDistributorClient_js_1 = __importDefault(require("./BaseDistributorClient.js"));
11
+ const aligned_distributor_json_1 = __importDefault(require("../descriptor/idl/aligned_distributor.json"));
12
+ const constants_js_1 = require("../constants.js");
13
+ const utils_js_1 = require("../utils.js");
14
+ class SolanaAlignedDistributorClient extends BaseDistributorClient_js_1.default {
15
+ constructor({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler }) {
16
+ super({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler });
17
+ const alignedAirdropsProgram = {
18
+ ...aligned_distributor_json_1.default,
19
+ };
20
+ this.alignedProxyProgram = new anchor_1.Program(alignedAirdropsProgram, { connection: this.connection });
21
+ }
22
+ getAlignedDistributorProgramId() {
23
+ return this.alignedProxyProgram.programId;
24
+ }
25
+ getAlignedDistributorAddress(distributorAddress) {
26
+ const distributorKey = new web3_js_1.PublicKey(distributorAddress);
27
+ return (0, utils_js_1.getAlignedDistributorPda)(this.alignedProxyProgram.programId, distributorKey);
28
+ }
29
+ async getAlignedDistributorData(distributorAddress) {
30
+ const alignedDistributorKey = this.getAlignedDistributorAddress(distributorAddress);
31
+ const alignedProxy = await this.alignedProxyProgram.account.alignedDistributor.fetch(alignedDistributorKey);
32
+ (0, common_1.invariant)(alignedProxy, "Aligned Distributor proxy account not found");
33
+ const oracleType = Object.keys(alignedProxy.priceOracleType).find((key) => !!key);
34
+ return {
35
+ oracleType,
36
+ minPrice: (0, common_1.getNumberFromBN)(alignedProxy.minPrice, constants_js_1.ALIGNED_PRECISION_FACTOR_POW),
37
+ maxPrice: (0, common_1.getNumberFromBN)(alignedProxy.maxPrice, constants_js_1.ALIGNED_PRECISION_FACTOR_POW),
38
+ minPercentage: (0, common_1.getNumberFromBN)(alignedProxy.minPercentage, constants_js_1.ALIGNED_PRECISION_FACTOR_POW),
39
+ maxPercentage: (0, common_1.getNumberFromBN)(alignedProxy.maxPercentage, constants_js_1.ALIGNED_PRECISION_FACTOR_POW),
40
+ priceOracle: oracleType === "none" ? undefined : alignedProxy.priceOracle.toBase58(),
41
+ sender: alignedProxy.admin.toBase58(),
42
+ updatePeriod: (0, common_1.getNumberFromBN)(alignedProxy.updatePeriod, constants_js_1.ALIGNED_PRECISION_FACTOR_POW),
43
+ clawedBack: alignedProxy.distributorClawedBack,
44
+ };
45
+ }
46
+ async getNewDistributorInstruction(data, accounts) {
47
+ const { distributor, mint, clawbackReceiver, tokenProgram, tokenVault, admin } = accounts;
48
+ const baseArgs = this.getNewDistributorArgs(data);
49
+ const alignedArgs = this.getNewAlignedDistributorArgs(data);
50
+ const oracle = data.oracleAddress
51
+ ? new web3_js_1.PublicKey(data.oracleAddress)
52
+ : (0, utils_js_1.getTestOraclePda)(this.alignedProxyProgram.programId, mint, admin);
53
+ const newDistributorIx = await this.alignedProxyProgram.methods
54
+ .newDistributor({
55
+ ...baseArgs,
56
+ ...alignedArgs,
57
+ })
58
+ .accounts({
59
+ admin,
60
+ tokenVault,
61
+ distributor,
62
+ clawbackReceiver,
63
+ mint,
64
+ tokenProgram,
65
+ priceOracle: oracle,
66
+ })
67
+ .instruction();
68
+ return newDistributorIx;
69
+ }
70
+ async getClawbackInstruction(accounts) {
71
+ const { distributor, from, to, mint, tokenProgram, admin } = accounts;
72
+ const alignedDistributorKey = (0, utils_js_1.getAlignedDistributorPda)(this.alignedProxyProgram.programId, distributor);
73
+ const alignedProxy = await this.alignedProxyProgram.account.alignedDistributor.fetch(alignedDistributorKey);
74
+ (0, common_1.invariant)(alignedProxy, "Aligned Distributor proxy account not found");
75
+ const clawbackInstruction = await this.alignedProxyProgram.methods
76
+ .clawback()
77
+ .accounts({
78
+ admin,
79
+ distributor,
80
+ from,
81
+ to,
82
+ mint,
83
+ tokenProgram,
84
+ })
85
+ .instruction();
86
+ return clawbackInstruction;
87
+ }
88
+ getNewAlignedDistributorArgs(data) {
89
+ const { oracleType, minPrice, maxPrice, minPercentage, maxPercentage, tickSize, skipInitial, totalAmountLocked, totalAmountUnlocked, unlockPeriod, } = data;
90
+ return {
91
+ totalAmountLocked: new bn_js_1.default(totalAmountLocked),
92
+ totalAmountUnlocked: new bn_js_1.default(totalAmountUnlocked),
93
+ oracleType: (!!oracleType ? { [oracleType]: {} } : { none: {} }),
94
+ minPrice: (0, common_1.getBN)(minPrice, constants_js_1.ALIGNED_PRECISION_FACTOR_POW),
95
+ maxPrice: (0, common_1.getBN)(maxPrice, constants_js_1.ALIGNED_PRECISION_FACTOR_POW),
96
+ minPercentage: (0, common_1.getBN)(minPercentage, constants_js_1.ALIGNED_PRECISION_FACTOR_POW),
97
+ maxPercentage: (0, common_1.getBN)(maxPercentage, constants_js_1.ALIGNED_PRECISION_FACTOR_POW),
98
+ tickSize: new bn_js_1.default(tickSize || 1),
99
+ skipInitial: skipInitial ?? false,
100
+ updatePeriod: unlockPeriod < 30 ? new bn_js_1.default(30) : new bn_js_1.default(unlockPeriod),
101
+ };
102
+ }
103
+ }
104
+ exports.default = SolanaAlignedDistributorClient;
@@ -0,0 +1,17 @@
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 instructions_1 = require("../generated/instructions");
7
+ const BaseDistributorClient_js_1 = __importDefault(require("./BaseDistributorClient.js"));
8
+ class SolanaDistributorClient extends BaseDistributorClient_js_1.default {
9
+ async getNewDistributorInstruction(data, accounts) {
10
+ const args = this.getNewDistributorArgs(data);
11
+ return (0, instructions_1.newDistributor)(args, accounts, this.programId);
12
+ }
13
+ async getClawbackInstruction(accounts) {
14
+ return (0, instructions_1.clawback)(accounts, this.programId);
15
+ }
16
+ }
17
+ exports.default = SolanaDistributorClient;
@@ -0,0 +1,10 @@
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
+ exports.SolanaAlignedDistributorClient = exports.SolanaDistributorClient = void 0;
7
+ var SolanaDistributorClient_js_1 = require("./SolanaDistributorClient.js");
8
+ Object.defineProperty(exports, "SolanaDistributorClient", { enumerable: true, get: function () { return __importDefault(SolanaDistributorClient_js_1).default; } });
9
+ var SolanaAlignedDistributorClient_js_1 = require("./SolanaAlignedDistributorClient.js");
10
+ Object.defineProperty(exports, "SolanaAlignedDistributorClient", { enumerable: true, get: function () { return __importDefault(SolanaAlignedDistributorClient_js_1).default; } });
@@ -1,12 +1,25 @@
1
1
  "use strict";
2
- var _a;
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.DISTRIBUTOR_PROGRAM_ID = exports.ONE_IN_BASIS_POINTS = void 0;
5
- var common_1 = require("@streamflow/common");
3
+ exports.DISTRIBUTOR_PROGRAM_ID = exports.ALIGNED_DISTRIBUTOR_PROGRAM_ID = exports.ONE_IN_BASIS_POINTS = exports.ALIGNED_PRECISION_FACTOR_POW = exports.CLAIM_STATUS_PREFIX = exports.TEST_ORACLE_PREFIX = exports.ALIGNED_DISTRIBUTOR_PREFIX = exports.DISTRIBUTOR_PREFIX = exports.DISTRIBUTOR_ADMIN_OFFSET = exports.DISTRIBUTOR_MINT_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET = void 0;
4
+ const common_1 = require("@streamflow/common");
5
+ exports.ANCHOR_DISCRIMINATOR_OFFSET = 8;
6
+ exports.DISTRIBUTOR_MINT_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET + 41;
7
+ exports.DISTRIBUTOR_ADMIN_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET + 201;
8
+ exports.DISTRIBUTOR_PREFIX = Buffer.from("MerkleDistributor", "utf-8");
9
+ exports.ALIGNED_DISTRIBUTOR_PREFIX = Buffer.from("aligned-distributor", "utf-8");
10
+ exports.TEST_ORACLE_PREFIX = Buffer.from("test-oracle", "utf-8");
11
+ exports.CLAIM_STATUS_PREFIX = Buffer.from("ClaimStatus", "utf-8");
12
+ exports.ALIGNED_PRECISION_FACTOR_POW = 9;
6
13
  exports.ONE_IN_BASIS_POINTS = BigInt(10000);
7
- exports.DISTRIBUTOR_PROGRAM_ID = (_a = {},
8
- _a[common_1.ICluster.Devnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
9
- _a[common_1.ICluster.Mainnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
10
- _a[common_1.ICluster.Testnet] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
11
- _a[common_1.ICluster.Local] = "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
12
- _a);
14
+ exports.ALIGNED_DISTRIBUTOR_PROGRAM_ID = {
15
+ [common_1.ICluster.Devnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
16
+ [common_1.ICluster.Mainnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
17
+ [common_1.ICluster.Testnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
18
+ [common_1.ICluster.Local]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
19
+ };
20
+ exports.DISTRIBUTOR_PROGRAM_ID = {
21
+ [common_1.ICluster.Devnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
22
+ [common_1.ICluster.Mainnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
23
+ [common_1.ICluster.Testnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
24
+ [common_1.ICluster.Local]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
25
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });