@streamflow/distributor 7.0.0-alpha.8 → 7.0.0
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.
- package/README.md +3 -3
- package/dist/cjs/solana/{client.js → clients/BaseDistributorClient.js} +73 -67
- package/dist/cjs/solana/clients/SolanaAlignedDistributorClient.js +104 -0
- package/dist/cjs/solana/clients/SolanaDistributorClient.js +17 -0
- package/dist/cjs/solana/clients/index.js +10 -0
- package/dist/cjs/solana/constants.js +12 -1
- package/dist/cjs/solana/descriptor/aligned_distributor.js +2 -0
- package/dist/cjs/solana/descriptor/idl/aligned_distributor.json +1242 -0
- package/dist/cjs/solana/generated/accounts/ClaimStatus.js +11 -11
- package/dist/cjs/solana/generated/accounts/MerkleDistributor.js +41 -16
- package/dist/cjs/solana/generated/errors/anchor.js +2 -2
- package/dist/cjs/solana/generated/errors/custom.js +2 -2
- package/dist/cjs/solana/generated/errors/index.js +2 -3
- package/dist/cjs/solana/generated/instructions/claimLocked.js +1 -2
- package/dist/cjs/solana/generated/instructions/clawback.js +1 -2
- package/dist/cjs/solana/generated/instructions/closeClaim.js +1 -2
- package/dist/cjs/solana/generated/instructions/newClaim.js +2 -2
- package/dist/cjs/solana/generated/instructions/newDistributor.js +2 -2
- package/dist/cjs/solana/generated/instructions/setAdmin.js +1 -2
- package/dist/cjs/solana/generated/instructions/setClawbackReceiver.js +1 -2
- package/dist/cjs/solana/index.js +2 -6
- package/dist/cjs/solana/types.js +2 -2
- package/dist/cjs/solana/utils.js +22 -16
- package/dist/esm/solana/clients/BaseDistributorClient.d.ts +39 -0
- package/dist/esm/solana/{client.js → clients/BaseDistributorClient.js} +73 -67
- package/dist/esm/solana/clients/SolanaAlignedDistributorClient.d.ts +14 -0
- package/dist/esm/solana/clients/SolanaAlignedDistributorClient.js +99 -0
- package/dist/esm/solana/clients/SolanaDistributorClient.d.ts +8 -0
- package/dist/esm/solana/clients/SolanaDistributorClient.js +11 -0
- package/dist/esm/solana/clients/index.d.ts +2 -0
- package/dist/esm/solana/clients/index.js +2 -0
- package/dist/esm/solana/constants.d.ts +11 -0
- package/dist/esm/solana/constants.js +12 -1
- package/dist/esm/solana/descriptor/aligned_distributor.d.ts +918 -0
- package/dist/esm/solana/descriptor/aligned_distributor.js +1 -0
- package/dist/esm/solana/descriptor/idl/aligned_distributor.json +1242 -0
- package/dist/esm/solana/generated/accounts/ClaimStatus.d.ts +17 -18
- package/dist/esm/solana/generated/accounts/ClaimStatus.js +13 -13
- package/dist/esm/solana/generated/accounts/MerkleDistributor.d.ts +55 -26
- package/dist/esm/solana/generated/accounts/MerkleDistributor.js +53 -18
- package/dist/esm/solana/generated/instructions/newClaim.d.ts +3 -3
- package/dist/esm/solana/generated/instructions/newDistributor.d.ts +8 -8
- package/dist/esm/solana/index.d.ts +1 -1
- package/dist/esm/solana/index.js +1 -1
- package/dist/esm/solana/types.d.ts +45 -5
- package/dist/esm/solana/utils.d.ts +2 -1
- package/dist/esm/solana/utils.js +11 -6
- package/package.json +11 -9
- package/dist/esm/solana/client.d.ts +0 -38
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ const res = await client.create(
|
|
|
62
62
|
240, 192, 134, 208, 108, 246, 0, 191,
|
|
63
63
|
], // Merkle root
|
|
64
64
|
maxNumNodes: 4, // Number of recipients
|
|
65
|
-
maxTotalClaim: "4000000000", // Total amount to distribute
|
|
65
|
+
maxTotalClaim: new BN("4000000000"), // Total amount to distribute
|
|
66
66
|
unlockPeriod: 1, // Unlock period in seconds
|
|
67
67
|
startVestingTs: 0, // Timestamp when Airdrop starts
|
|
68
68
|
endVestingTs: now + 3600 * 24 * 7, // Timestamp when Airdrop ends
|
|
@@ -93,8 +93,8 @@ const claimRes = await client.claim(
|
|
|
93
93
|
43, 104, 75, 183, 12, 38, 37, 153,
|
|
94
94
|
],
|
|
95
95
|
], // Merkle Proof used to verify claim
|
|
96
|
-
amountUnlocked: "0", // Total amount unlocked for a Recipient
|
|
97
|
-
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
|
|
98
98
|
},
|
|
99
99
|
solanaParams,
|
|
100
100
|
);
|
|
@@ -3,20 +3,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const
|
|
7
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
6
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
9
7
|
const web3_js_1 = require("@solana/web3.js");
|
|
10
8
|
const common_1 = require("@streamflow/common");
|
|
11
9
|
const solana_1 = require("@streamflow/common/solana");
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
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 {
|
|
20
17
|
constructor({ clusterUrl, cluster = common_1.ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler, }) {
|
|
21
18
|
this.commitment = commitment;
|
|
22
19
|
this.connection = new web3_js_1.Connection(clusterUrl, this.commitment);
|
|
@@ -26,46 +23,25 @@ class SolanaDistributorClient {
|
|
|
26
23
|
getCommitment() {
|
|
27
24
|
return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
28
25
|
}
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
};
|
|
26
|
+
getDistributorProgramId() {
|
|
27
|
+
return this.programId;
|
|
42
28
|
}
|
|
43
29
|
async prepareCreateInstructions(data, extParams) {
|
|
44
30
|
if (!extParams.invoker.publicKey) {
|
|
45
31
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
46
32
|
}
|
|
33
|
+
const { version, mint } = data;
|
|
47
34
|
const ixs = (0, solana_1.prepareBaseInstructions)(this.connection, extParams);
|
|
48
|
-
const
|
|
49
|
-
const { mint: mintAccount, tokenProgramId } = await (0, solana_1.getMintAndProgram)(this.connection,
|
|
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);
|
|
50
37
|
const transferFeeConfig = (0, spl_token_1.getTransferFeeConfig)(mintAccount);
|
|
51
|
-
const distributorPublicKey = (0, utils_1.getDistributorPda)(this.programId,
|
|
52
|
-
const tokenVault = await (0, solana_1.ata)(
|
|
53
|
-
const senderTokens = await (0, solana_1.ata)(
|
|
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
|
-
};
|
|
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);
|
|
65
41
|
const accounts = {
|
|
66
42
|
distributor: distributorPublicKey,
|
|
67
43
|
clawbackReceiver: senderTokens,
|
|
68
|
-
mint,
|
|
44
|
+
mint: mintPublicKey,
|
|
69
45
|
tokenVault,
|
|
70
46
|
admin: extParams.invoker.publicKey,
|
|
71
47
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
@@ -73,24 +49,33 @@ class SolanaDistributorClient {
|
|
|
73
49
|
tokenProgram: tokenProgramId,
|
|
74
50
|
};
|
|
75
51
|
if (extParams.isNative) {
|
|
76
|
-
ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, extParams.invoker.publicKey,
|
|
52
|
+
ixs.push(...(await (0, solana_1.prepareWrappedAccount)(this.connection, extParams.invoker.publicKey, new bn_js_1.default(data.maxTotalClaim))));
|
|
77
53
|
}
|
|
78
|
-
const
|
|
79
|
-
|
|
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));
|
|
54
|
+
const newDistributorInstruction = await this.getNewDistributorInstruction(data, accounts);
|
|
55
|
+
ixs.push(newDistributorInstruction);
|
|
85
56
|
if (transferFeeConfig) {
|
|
86
57
|
const { transferAmount, feeCharged } = await (0, utils_1.calculateAmountWithTransferFees)(this.connection, transferFeeConfig, BigInt(data.maxTotalClaim.toString()));
|
|
87
|
-
ixs.push((0, spl_token_1.createTransferCheckedWithFeeInstruction)(senderTokens,
|
|
58
|
+
ixs.push((0, spl_token_1.createTransferCheckedWithFeeInstruction)(senderTokens, mintPublicKey, tokenVault, extParams.invoker.publicKey, transferAmount, mintAccount.decimals, feeCharged, undefined, tokenProgramId));
|
|
88
59
|
}
|
|
89
60
|
else {
|
|
90
|
-
ixs.push((0, spl_token_1.createTransferCheckedInstruction)(senderTokens,
|
|
61
|
+
ixs.push((0, spl_token_1.createTransferCheckedInstruction)(senderTokens, mintPublicKey, tokenVault, extParams.invoker.publicKey, BigInt(data.maxTotalClaim.toString()), mintAccount.decimals, undefined, tokenProgramId));
|
|
91
62
|
}
|
|
92
63
|
return { distributorPublicKey, ixs };
|
|
93
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
|
+
}
|
|
94
79
|
async claim(data, extParams) {
|
|
95
80
|
const ixs = await this.prepareClaimInstructions(data, extParams);
|
|
96
81
|
const { tx, hash, context } = await (0, solana_1.prepareTransaction)(this.connection, ixs, extParams.invoker.publicKey);
|
|
@@ -131,29 +116,19 @@ class SolanaDistributorClient {
|
|
|
131
116
|
};
|
|
132
117
|
if (!claimStatus) {
|
|
133
118
|
const args = {
|
|
134
|
-
amountLocked:
|
|
135
|
-
amountUnlocked:
|
|
119
|
+
amountLocked: new bn_js_1.default(data.amountLocked),
|
|
120
|
+
amountUnlocked: new bn_js_1.default(data.amountUnlocked),
|
|
136
121
|
proof: data.proof,
|
|
137
122
|
};
|
|
138
123
|
ixs.push((0, instructions_1.newClaim)(args, accounts, this.programId));
|
|
139
124
|
}
|
|
140
|
-
const nowTs =
|
|
125
|
+
const nowTs = new bn_js_1.default(Math.floor(Date.now() / 1000));
|
|
141
126
|
if (claimStatus ||
|
|
142
|
-
(
|
|
127
|
+
(new bn_js_1.default(data.amountLocked).gtn(0) && nowTs.sub(distributor.startTs).gte(distributor.unlockPeriod))) {
|
|
143
128
|
ixs.push((0, instructions_1.claimLocked)(accounts, this.programId));
|
|
144
129
|
}
|
|
145
130
|
return ixs;
|
|
146
131
|
}
|
|
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
132
|
async prepareClawbackInstructions(data, extParams) {
|
|
158
133
|
if (!extParams.invoker.publicKey) {
|
|
159
134
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -175,9 +150,20 @@ class SolanaDistributorClient {
|
|
|
175
150
|
systemProgram: web3_js_1.SystemProgram.programId,
|
|
176
151
|
tokenProgram: tokenProgramId,
|
|
177
152
|
};
|
|
178
|
-
|
|
153
|
+
const clawbackInstruction = await this.getClawbackInstruction(accounts);
|
|
154
|
+
ixs.push(clawbackInstruction);
|
|
179
155
|
return ixs;
|
|
180
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
|
+
}
|
|
181
167
|
async getClaims(data) {
|
|
182
168
|
const claimStatusPublicKeys = data.map(({ id, recipient }) => {
|
|
183
169
|
return (0, utils_1.getClaimantStatusPda)(this.programId, new web3_js_1.PublicKey(id), new web3_js_1.PublicKey(recipient));
|
|
@@ -212,5 +198,25 @@ class SolanaDistributorClient {
|
|
|
212
198
|
account: accounts_1.MerkleDistributor.decode(account.data),
|
|
213
199
|
}));
|
|
214
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
|
+
}
|
|
215
221
|
}
|
|
216
|
-
exports.default =
|
|
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,11 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DISTRIBUTOR_PROGRAM_ID = exports.ONE_IN_BASIS_POINTS = exports.DISTRIBUTOR_ADMIN_OFFSET = exports.DISTRIBUTOR_MINT_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET = void 0;
|
|
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
4
|
const common_1 = require("@streamflow/common");
|
|
5
5
|
exports.ANCHOR_DISCRIMINATOR_OFFSET = 8;
|
|
6
6
|
exports.DISTRIBUTOR_MINT_OFFSET = exports.ANCHOR_DISCRIMINATOR_OFFSET + 41;
|
|
7
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;
|
|
8
13
|
exports.ONE_IN_BASIS_POINTS = BigInt(10000);
|
|
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
|
+
};
|
|
9
20
|
exports.DISTRIBUTOR_PROGRAM_ID = {
|
|
10
21
|
[common_1.ICluster.Devnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
11
22
|
[common_1.ICluster.Mainnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|