@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.
- package/README.md +19 -3
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/solana/clients/BaseDistributorClient.js +222 -0
- 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 +22 -9
- 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 +56 -114
- package/dist/cjs/solana/generated/accounts/MerkleDistributor.js +96 -129
- package/dist/cjs/solana/generated/errors/anchor.js +540 -717
- package/dist/cjs/solana/generated/errors/custom.js +171 -243
- package/dist/cjs/solana/generated/errors/index.js +12 -51
- package/dist/cjs/solana/generated/instructions/claimLocked.js +7 -8
- package/dist/cjs/solana/generated/instructions/clawback.js +8 -9
- package/dist/cjs/solana/generated/instructions/closeClaim.js +8 -9
- package/dist/cjs/solana/generated/instructions/newClaim.js +10 -11
- package/dist/cjs/solana/generated/instructions/newDistributor.js +17 -12
- package/dist/cjs/solana/generated/instructions/setAdmin.js +8 -9
- package/dist/cjs/solana/generated/instructions/setClawbackReceiver.js +8 -9
- package/dist/cjs/solana/generated/programId.js +1 -1
- package/dist/cjs/solana/index.js +8 -12
- package/dist/cjs/solana/utils.js +46 -94
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/solana/clients/BaseDistributorClient.d.ts +39 -0
- package/dist/esm/solana/{client.js → clients/BaseDistributorClient.js} +97 -66
- 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 +15 -0
- package/dist/esm/solana/constants.js +14 -0
- 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 -17
- package/dist/esm/solana/generated/accounts/ClaimStatus.js +13 -13
- package/dist/esm/solana/generated/accounts/MerkleDistributor.d.ts +55 -25
- 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/generated/instructions/newDistributor.js +6 -0
- package/dist/esm/solana/index.d.ts +7 -7
- package/dist/esm/solana/index.js +7 -7
- package/dist/esm/solana/types.d.ts +49 -4
- package/dist/esm/solana/utils.d.ts +2 -1
- package/dist/esm/solana/utils.js +11 -6
- package/package.json +9 -7
- package/dist/cjs/solana/client.js +0 -365
- package/dist/esm/solana/client.d.ts +0 -36
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { ASSOCIATED_TOKEN_PROGRAM_ID, NATIVE_MINT, createTransferCheckedInstruction, createTransferCheckedWithFeeInstruction, getTransferFeeConfig, } from "@solana/spl-token";
|
|
1
|
+
import BN from "bn.js";
|
|
3
2
|
import { Connection, PublicKey, SystemProgram, } from "@solana/web3.js";
|
|
4
3
|
import { ICluster } from "@streamflow/common";
|
|
5
|
-
import { ata, checkOrCreateAtaBatch,
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
4
|
+
import { ata, checkOrCreateAtaBatch, prepareBaseInstructions, prepareTransaction, getMintAndProgram, buildSendThrottler, prepareWrappedAccount, } from "@streamflow/common/solana";
|
|
5
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, createTransferCheckedInstruction, createTransferCheckedWithFeeInstruction, getTransferFeeConfig, NATIVE_MINT, } from "@solana/spl-token";
|
|
6
|
+
import bs58 from "bs58";
|
|
7
|
+
import { DISTRIBUTOR_ADMIN_OFFSET, DISTRIBUTOR_MINT_OFFSET, DISTRIBUTOR_PROGRAM_ID } from "../constants";
|
|
8
|
+
import { claimLocked, newClaim, } from "../generated/instructions";
|
|
9
|
+
import { ClaimStatus, MerkleDistributor } from "../generated/accounts";
|
|
10
|
+
import { calculateAmountWithTransferFees, getClaimantStatusPda, getDistributorPda, getEventAuthorityPda, wrappedSignAndExecuteTransaction, } from "../utils";
|
|
11
|
+
export default class BaseDistributorClient {
|
|
11
12
|
connection;
|
|
12
13
|
programId;
|
|
13
14
|
commitment;
|
|
14
15
|
sendThrottler;
|
|
15
|
-
/**
|
|
16
|
-
* Create Stream instance
|
|
17
|
-
*/
|
|
18
16
|
constructor({ clusterUrl, cluster = ICluster.Mainnet, commitment = "confirmed", programId = "", sendRate = 1, sendThrottler, }) {
|
|
19
17
|
this.commitment = commitment;
|
|
20
18
|
this.connection = new Connection(clusterUrl, this.commitment);
|
|
@@ -24,46 +22,25 @@ export default class SolanaDistributorClient {
|
|
|
24
22
|
getCommitment() {
|
|
25
23
|
return typeof this.commitment == "string" ? this.commitment : this.commitment.commitment;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
|
|
30
|
-
const signature = await wrappedSignAndExecuteTransaction(this.connection, extParams.invoker, tx, {
|
|
31
|
-
hash,
|
|
32
|
-
context,
|
|
33
|
-
commitment: this.getCommitment(),
|
|
34
|
-
}, { sendThrottler: this.sendThrottler });
|
|
35
|
-
return {
|
|
36
|
-
ixs,
|
|
37
|
-
txId: signature,
|
|
38
|
-
metadataId: distributorPublicKey.toBase58(),
|
|
39
|
-
};
|
|
25
|
+
getDistributorProgramId() {
|
|
26
|
+
return this.programId;
|
|
40
27
|
}
|
|
41
28
|
async prepareCreateInstructions(data, extParams) {
|
|
42
29
|
if (!extParams.invoker.publicKey) {
|
|
43
30
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
44
31
|
}
|
|
32
|
+
const { version, mint } = data;
|
|
45
33
|
const ixs = prepareBaseInstructions(this.connection, extParams);
|
|
46
|
-
const
|
|
47
|
-
const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection,
|
|
34
|
+
const mintPublicKey = extParams.isNative ? NATIVE_MINT : new PublicKey(mint);
|
|
35
|
+
const { mint: mintAccount, tokenProgramId } = await getMintAndProgram(this.connection, mintPublicKey);
|
|
48
36
|
const transferFeeConfig = getTransferFeeConfig(mintAccount);
|
|
49
|
-
const distributorPublicKey = getDistributorPda(this.programId,
|
|
50
|
-
const tokenVault = await ata(
|
|
51
|
-
const senderTokens = await ata(
|
|
52
|
-
const args = {
|
|
53
|
-
version: BigNumber(data.version),
|
|
54
|
-
root: data.root,
|
|
55
|
-
maxTotalClaim: BigNumber(data.maxTotalClaim),
|
|
56
|
-
maxNumNodes: BigNumber(data.maxNumNodes),
|
|
57
|
-
unlockPeriod: BigNumber(data.unlockPeriod),
|
|
58
|
-
startVestingTs: BigNumber(data.startVestingTs),
|
|
59
|
-
endVestingTs: BigNumber(data.endVestingTs),
|
|
60
|
-
clawbackStartTs: BigNumber(data.clawbackStartTs),
|
|
61
|
-
claimsClosable: data.claimsClosable,
|
|
62
|
-
};
|
|
37
|
+
const distributorPublicKey = getDistributorPda(this.programId, mintPublicKey, version);
|
|
38
|
+
const tokenVault = await ata(mintPublicKey, distributorPublicKey, tokenProgramId);
|
|
39
|
+
const senderTokens = await ata(mintPublicKey, extParams.invoker.publicKey, tokenProgramId);
|
|
63
40
|
const accounts = {
|
|
64
41
|
distributor: distributorPublicKey,
|
|
65
42
|
clawbackReceiver: senderTokens,
|
|
66
|
-
mint,
|
|
43
|
+
mint: mintPublicKey,
|
|
67
44
|
tokenVault,
|
|
68
45
|
admin: extParams.invoker.publicKey,
|
|
69
46
|
systemProgram: SystemProgram.programId,
|
|
@@ -71,24 +48,33 @@ export default class SolanaDistributorClient {
|
|
|
71
48
|
tokenProgram: tokenProgramId,
|
|
72
49
|
};
|
|
73
50
|
if (extParams.isNative) {
|
|
74
|
-
ixs.push(...(await prepareWrappedAccount(this.connection, extParams.invoker.publicKey,
|
|
51
|
+
ixs.push(...(await prepareWrappedAccount(this.connection, extParams.invoker.publicKey, new BN(data.maxTotalClaim))));
|
|
75
52
|
}
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
const startVestingTs = args.startVestingTs.isZero() ? nowTs : args.startVestingTs;
|
|
79
|
-
if (endVestingTs.gt(startVestingTs) && endVestingTs.minus(startVestingTs).lt(args.unlockPeriod)) {
|
|
80
|
-
throw new Error("The unlock period cannot be longer than the total vesting duration!");
|
|
81
|
-
}
|
|
82
|
-
ixs.push(newDistributor(args, accounts, this.programId));
|
|
53
|
+
const newDistributorInstruction = await this.getNewDistributorInstruction(data, accounts);
|
|
54
|
+
ixs.push(newDistributorInstruction);
|
|
83
55
|
if (transferFeeConfig) {
|
|
84
56
|
const { transferAmount, feeCharged } = await calculateAmountWithTransferFees(this.connection, transferFeeConfig, BigInt(data.maxTotalClaim.toString()));
|
|
85
|
-
ixs.push(createTransferCheckedWithFeeInstruction(senderTokens,
|
|
57
|
+
ixs.push(createTransferCheckedWithFeeInstruction(senderTokens, mintPublicKey, tokenVault, extParams.invoker.publicKey, transferAmount, mintAccount.decimals, feeCharged, undefined, tokenProgramId));
|
|
86
58
|
}
|
|
87
59
|
else {
|
|
88
|
-
ixs.push(createTransferCheckedInstruction(senderTokens,
|
|
60
|
+
ixs.push(createTransferCheckedInstruction(senderTokens, mintPublicKey, tokenVault, extParams.invoker.publicKey, BigInt(data.maxTotalClaim.toString()), mintAccount.decimals, undefined, tokenProgramId));
|
|
89
61
|
}
|
|
90
62
|
return { distributorPublicKey, ixs };
|
|
91
63
|
}
|
|
64
|
+
async create(data, extParams) {
|
|
65
|
+
const { ixs, distributorPublicKey } = await this.prepareCreateInstructions(data, extParams);
|
|
66
|
+
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
|
|
67
|
+
const signature = await wrappedSignAndExecuteTransaction(this.connection, extParams.invoker, tx, {
|
|
68
|
+
hash,
|
|
69
|
+
context,
|
|
70
|
+
commitment: this.getCommitment(),
|
|
71
|
+
}, { sendThrottler: this.sendThrottler });
|
|
72
|
+
return {
|
|
73
|
+
ixs,
|
|
74
|
+
txId: signature,
|
|
75
|
+
metadataId: distributorPublicKey.toBase58(),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
92
78
|
async claim(data, extParams) {
|
|
93
79
|
const ixs = await this.prepareClaimInstructions(data, extParams);
|
|
94
80
|
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
|
|
@@ -129,29 +115,19 @@ export default class SolanaDistributorClient {
|
|
|
129
115
|
};
|
|
130
116
|
if (!claimStatus) {
|
|
131
117
|
const args = {
|
|
132
|
-
amountLocked:
|
|
133
|
-
amountUnlocked:
|
|
118
|
+
amountLocked: new BN(data.amountLocked),
|
|
119
|
+
amountUnlocked: new BN(data.amountUnlocked),
|
|
134
120
|
proof: data.proof,
|
|
135
121
|
};
|
|
136
122
|
ixs.push(newClaim(args, accounts, this.programId));
|
|
137
123
|
}
|
|
138
|
-
const nowTs =
|
|
124
|
+
const nowTs = new BN(Math.floor(Date.now() / 1000));
|
|
139
125
|
if (claimStatus ||
|
|
140
|
-
(
|
|
126
|
+
(new BN(data.amountLocked).gtn(0) && nowTs.sub(distributor.startTs).gte(distributor.unlockPeriod))) {
|
|
141
127
|
ixs.push(claimLocked(accounts, this.programId));
|
|
142
128
|
}
|
|
143
129
|
return ixs;
|
|
144
130
|
}
|
|
145
|
-
async clawback(data, extParams) {
|
|
146
|
-
const ixs = await this.prepareClawbackInstructions(data, extParams);
|
|
147
|
-
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
|
|
148
|
-
const signature = await wrappedSignAndExecuteTransaction(this.connection, extParams.invoker, tx, {
|
|
149
|
-
hash,
|
|
150
|
-
context,
|
|
151
|
-
commitment: this.getCommitment(),
|
|
152
|
-
}, { sendThrottler: this.sendThrottler });
|
|
153
|
-
return { ixs, txId: signature };
|
|
154
|
-
}
|
|
155
131
|
async prepareClawbackInstructions(data, extParams) {
|
|
156
132
|
if (!extParams.invoker.publicKey) {
|
|
157
133
|
throw new Error("Invoker's PublicKey is not available, check passed wallet adapter!");
|
|
@@ -173,9 +149,20 @@ export default class SolanaDistributorClient {
|
|
|
173
149
|
systemProgram: SystemProgram.programId,
|
|
174
150
|
tokenProgram: tokenProgramId,
|
|
175
151
|
};
|
|
176
|
-
|
|
152
|
+
const clawbackInstruction = await this.getClawbackInstruction(accounts);
|
|
153
|
+
ixs.push(clawbackInstruction);
|
|
177
154
|
return ixs;
|
|
178
155
|
}
|
|
156
|
+
async clawback(data, extParams) {
|
|
157
|
+
const ixs = await this.prepareClawbackInstructions(data, extParams);
|
|
158
|
+
const { tx, hash, context } = await prepareTransaction(this.connection, ixs, extParams.invoker.publicKey);
|
|
159
|
+
const signature = await wrappedSignAndExecuteTransaction(this.connection, extParams.invoker, tx, {
|
|
160
|
+
hash,
|
|
161
|
+
context,
|
|
162
|
+
commitment: this.getCommitment(),
|
|
163
|
+
}, { sendThrottler: this.sendThrottler });
|
|
164
|
+
return { ixs, txId: signature };
|
|
165
|
+
}
|
|
179
166
|
async getClaims(data) {
|
|
180
167
|
const claimStatusPublicKeys = data.map(({ id, recipient }) => {
|
|
181
168
|
return getClaimantStatusPda(this.programId, new PublicKey(id), new PublicKey(recipient));
|
|
@@ -186,4 +173,48 @@ export default class SolanaDistributorClient {
|
|
|
186
173
|
const distributorPublicKeys = data.ids.map((distributorId) => new PublicKey(distributorId));
|
|
187
174
|
return MerkleDistributor.fetchMultiple(this.connection, distributorPublicKeys, this.programId);
|
|
188
175
|
}
|
|
176
|
+
async searchDistributors(data) {
|
|
177
|
+
const filters = [{ memcmp: { offset: 0, bytes: bs58.encode(MerkleDistributor.discriminator) } }];
|
|
178
|
+
if (data.mint) {
|
|
179
|
+
filters.push({
|
|
180
|
+
memcmp: {
|
|
181
|
+
offset: DISTRIBUTOR_MINT_OFFSET,
|
|
182
|
+
bytes: data.mint,
|
|
183
|
+
},
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
if (data.admin) {
|
|
187
|
+
filters.push({
|
|
188
|
+
memcmp: {
|
|
189
|
+
offset: DISTRIBUTOR_ADMIN_OFFSET,
|
|
190
|
+
bytes: data.admin,
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
const accounts = await this.connection.getProgramAccounts(this.programId, { filters });
|
|
195
|
+
return accounts.map(({ pubkey, account }) => ({
|
|
196
|
+
publicKey: pubkey,
|
|
197
|
+
account: MerkleDistributor.decode(account.data),
|
|
198
|
+
}));
|
|
199
|
+
}
|
|
200
|
+
getNewDistributorArgs(data) {
|
|
201
|
+
const args = {
|
|
202
|
+
version: new BN(data.version),
|
|
203
|
+
root: data.root,
|
|
204
|
+
maxTotalClaim: new BN(data.maxTotalClaim),
|
|
205
|
+
maxNumNodes: new BN(data.maxNumNodes),
|
|
206
|
+
unlockPeriod: new BN(data.unlockPeriod),
|
|
207
|
+
startVestingTs: new BN(data.startVestingTs),
|
|
208
|
+
endVestingTs: new BN(data.endVestingTs),
|
|
209
|
+
clawbackStartTs: new BN(data.clawbackStartTs),
|
|
210
|
+
claimsClosable: data.claimsClosable,
|
|
211
|
+
};
|
|
212
|
+
const nowTs = new BN(Math.floor(Date.now() / 1000));
|
|
213
|
+
const endVestingTs = args.endVestingTs.isZero() ? nowTs : args.endVestingTs;
|
|
214
|
+
const startVestingTs = args.startVestingTs.isZero() ? nowTs : args.startVestingTs;
|
|
215
|
+
if (endVestingTs.gt(startVestingTs) && endVestingTs.sub(startVestingTs).lt(args.unlockPeriod)) {
|
|
216
|
+
throw new Error("The unlock period cannot be longer than the total vesting duration!");
|
|
217
|
+
}
|
|
218
|
+
return args;
|
|
219
|
+
}
|
|
189
220
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import { ICreateAlignedDistributorData, AlignedDistributorData, NewAlignedDistributorArgs } from "../types";
|
|
3
|
+
import { ClawbackAccounts, NewDistributorAccounts } from "../generated/instructions";
|
|
4
|
+
import BaseDistributorClient, { IInitOptions } from "./BaseDistributorClient.js";
|
|
5
|
+
export default class SolanaAlignedDistributorClient extends BaseDistributorClient {
|
|
6
|
+
private alignedProxyProgram;
|
|
7
|
+
constructor({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler }: IInitOptions);
|
|
8
|
+
getAlignedDistributorProgramId(): PublicKey;
|
|
9
|
+
getAlignedDistributorAddress(distributorAddress: string): PublicKey;
|
|
10
|
+
getAlignedDistributorData(distributorAddress: string): Promise<AlignedDistributorData>;
|
|
11
|
+
protected getNewDistributorInstruction(data: ICreateAlignedDistributorData, accounts: NewDistributorAccounts): Promise<TransactionInstruction>;
|
|
12
|
+
protected getClawbackInstruction(accounts: ClawbackAccounts): Promise<TransactionInstruction>;
|
|
13
|
+
protected getNewAlignedDistributorArgs(data: ICreateAlignedDistributorData): NewAlignedDistributorArgs;
|
|
14
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
import { Program } from "@coral-xyz/anchor";
|
|
4
|
+
import { getBN, getNumberFromBN, invariant } from "@streamflow/common";
|
|
5
|
+
import BaseDistributorClient from "./BaseDistributorClient.js";
|
|
6
|
+
import StreamflowAlignedAirdropsIDL from "../descriptor/idl/aligned_distributor.json";
|
|
7
|
+
import { ALIGNED_PRECISION_FACTOR_POW } from "../constants.js";
|
|
8
|
+
import { getAlignedDistributorPda, getTestOraclePda } from "../utils.js";
|
|
9
|
+
export default class SolanaAlignedDistributorClient extends BaseDistributorClient {
|
|
10
|
+
alignedProxyProgram;
|
|
11
|
+
constructor({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler }) {
|
|
12
|
+
super({ clusterUrl, cluster, commitment, programId, sendRate, sendThrottler });
|
|
13
|
+
const alignedAirdropsProgram = {
|
|
14
|
+
...StreamflowAlignedAirdropsIDL,
|
|
15
|
+
};
|
|
16
|
+
this.alignedProxyProgram = new Program(alignedAirdropsProgram, { connection: this.connection });
|
|
17
|
+
}
|
|
18
|
+
getAlignedDistributorProgramId() {
|
|
19
|
+
return this.alignedProxyProgram.programId;
|
|
20
|
+
}
|
|
21
|
+
getAlignedDistributorAddress(distributorAddress) {
|
|
22
|
+
const distributorKey = new PublicKey(distributorAddress);
|
|
23
|
+
return getAlignedDistributorPda(this.alignedProxyProgram.programId, distributorKey);
|
|
24
|
+
}
|
|
25
|
+
async getAlignedDistributorData(distributorAddress) {
|
|
26
|
+
const alignedDistributorKey = this.getAlignedDistributorAddress(distributorAddress);
|
|
27
|
+
const alignedProxy = await this.alignedProxyProgram.account.alignedDistributor.fetch(alignedDistributorKey);
|
|
28
|
+
invariant(alignedProxy, "Aligned Distributor proxy account not found");
|
|
29
|
+
const oracleType = Object.keys(alignedProxy.priceOracleType).find((key) => !!key);
|
|
30
|
+
return {
|
|
31
|
+
oracleType,
|
|
32
|
+
minPrice: getNumberFromBN(alignedProxy.minPrice, ALIGNED_PRECISION_FACTOR_POW),
|
|
33
|
+
maxPrice: getNumberFromBN(alignedProxy.maxPrice, ALIGNED_PRECISION_FACTOR_POW),
|
|
34
|
+
minPercentage: getNumberFromBN(alignedProxy.minPercentage, ALIGNED_PRECISION_FACTOR_POW),
|
|
35
|
+
maxPercentage: getNumberFromBN(alignedProxy.maxPercentage, ALIGNED_PRECISION_FACTOR_POW),
|
|
36
|
+
priceOracle: oracleType === "none" ? undefined : alignedProxy.priceOracle.toBase58(),
|
|
37
|
+
sender: alignedProxy.admin.toBase58(),
|
|
38
|
+
updatePeriod: getNumberFromBN(alignedProxy.updatePeriod, ALIGNED_PRECISION_FACTOR_POW),
|
|
39
|
+
clawedBack: alignedProxy.distributorClawedBack,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async getNewDistributorInstruction(data, accounts) {
|
|
43
|
+
const { distributor, mint, clawbackReceiver, tokenProgram, tokenVault, admin } = accounts;
|
|
44
|
+
const baseArgs = this.getNewDistributorArgs(data);
|
|
45
|
+
const alignedArgs = this.getNewAlignedDistributorArgs(data);
|
|
46
|
+
const oracle = data.oracleAddress
|
|
47
|
+
? new PublicKey(data.oracleAddress)
|
|
48
|
+
: getTestOraclePda(this.alignedProxyProgram.programId, mint, admin);
|
|
49
|
+
const newDistributorIx = await this.alignedProxyProgram.methods
|
|
50
|
+
.newDistributor({
|
|
51
|
+
...baseArgs,
|
|
52
|
+
...alignedArgs,
|
|
53
|
+
})
|
|
54
|
+
.accounts({
|
|
55
|
+
admin,
|
|
56
|
+
tokenVault,
|
|
57
|
+
distributor,
|
|
58
|
+
clawbackReceiver,
|
|
59
|
+
mint,
|
|
60
|
+
tokenProgram,
|
|
61
|
+
priceOracle: oracle,
|
|
62
|
+
})
|
|
63
|
+
.instruction();
|
|
64
|
+
return newDistributorIx;
|
|
65
|
+
}
|
|
66
|
+
async getClawbackInstruction(accounts) {
|
|
67
|
+
const { distributor, from, to, mint, tokenProgram, admin } = accounts;
|
|
68
|
+
const alignedDistributorKey = getAlignedDistributorPda(this.alignedProxyProgram.programId, distributor);
|
|
69
|
+
const alignedProxy = await this.alignedProxyProgram.account.alignedDistributor.fetch(alignedDistributorKey);
|
|
70
|
+
invariant(alignedProxy, "Aligned Distributor proxy account not found");
|
|
71
|
+
const clawbackInstruction = await this.alignedProxyProgram.methods
|
|
72
|
+
.clawback()
|
|
73
|
+
.accounts({
|
|
74
|
+
admin,
|
|
75
|
+
distributor,
|
|
76
|
+
from,
|
|
77
|
+
to,
|
|
78
|
+
mint,
|
|
79
|
+
tokenProgram,
|
|
80
|
+
})
|
|
81
|
+
.instruction();
|
|
82
|
+
return clawbackInstruction;
|
|
83
|
+
}
|
|
84
|
+
getNewAlignedDistributorArgs(data) {
|
|
85
|
+
const { oracleType, minPrice, maxPrice, minPercentage, maxPercentage, tickSize, skipInitial, totalAmountLocked, totalAmountUnlocked, unlockPeriod, } = data;
|
|
86
|
+
return {
|
|
87
|
+
totalAmountLocked: new BN(totalAmountLocked),
|
|
88
|
+
totalAmountUnlocked: new BN(totalAmountUnlocked),
|
|
89
|
+
oracleType: (!!oracleType ? { [oracleType]: {} } : { none: {} }),
|
|
90
|
+
minPrice: getBN(minPrice, ALIGNED_PRECISION_FACTOR_POW),
|
|
91
|
+
maxPrice: getBN(maxPrice, ALIGNED_PRECISION_FACTOR_POW),
|
|
92
|
+
minPercentage: getBN(minPercentage, ALIGNED_PRECISION_FACTOR_POW),
|
|
93
|
+
maxPercentage: getBN(maxPercentage, ALIGNED_PRECISION_FACTOR_POW),
|
|
94
|
+
tickSize: new BN(tickSize || 1),
|
|
95
|
+
skipInitial: skipInitial ?? false,
|
|
96
|
+
updatePeriod: unlockPeriod < 30 ? new BN(30) : new BN(unlockPeriod),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import { ICreateDistributorData } from "../types";
|
|
3
|
+
import { ClawbackAccounts, NewDistributorAccounts } from "../generated/instructions";
|
|
4
|
+
import BaseDistributorClient from "./BaseDistributorClient.js";
|
|
5
|
+
export default class SolanaDistributorClient extends BaseDistributorClient {
|
|
6
|
+
protected getNewDistributorInstruction(data: ICreateDistributorData, accounts: NewDistributorAccounts): Promise<TransactionInstruction>;
|
|
7
|
+
protected getClawbackInstruction(accounts: ClawbackAccounts): Promise<TransactionInstruction>;
|
|
8
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { clawback, newDistributor } from "../generated/instructions";
|
|
2
|
+
import BaseDistributorClient from "./BaseDistributorClient.js";
|
|
3
|
+
export default class SolanaDistributorClient extends BaseDistributorClient {
|
|
4
|
+
async getNewDistributorInstruction(data, accounts) {
|
|
5
|
+
const args = this.getNewDistributorArgs(data);
|
|
6
|
+
return newDistributor(args, accounts, this.programId);
|
|
7
|
+
}
|
|
8
|
+
async getClawbackInstruction(accounts) {
|
|
9
|
+
return clawback(accounts, this.programId);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,4 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
export declare const ANCHOR_DISCRIMINATOR_OFFSET = 8;
|
|
3
|
+
export declare const DISTRIBUTOR_MINT_OFFSET: number;
|
|
4
|
+
export declare const DISTRIBUTOR_ADMIN_OFFSET: number;
|
|
5
|
+
export declare const DISTRIBUTOR_PREFIX: Buffer;
|
|
6
|
+
export declare const ALIGNED_DISTRIBUTOR_PREFIX: Buffer;
|
|
7
|
+
export declare const TEST_ORACLE_PREFIX: Buffer;
|
|
8
|
+
export declare const CLAIM_STATUS_PREFIX: Buffer;
|
|
9
|
+
export declare const ALIGNED_PRECISION_FACTOR_POW = 9;
|
|
1
10
|
export declare const ONE_IN_BASIS_POINTS: bigint;
|
|
11
|
+
export declare const ALIGNED_DISTRIBUTOR_PROGRAM_ID: {
|
|
12
|
+
devnet: string;
|
|
13
|
+
mainnet: string;
|
|
14
|
+
testnet: string;
|
|
15
|
+
local: string;
|
|
16
|
+
};
|
|
2
17
|
export declare const DISTRIBUTOR_PROGRAM_ID: {
|
|
3
18
|
devnet: string;
|
|
4
19
|
mainnet: string;
|
|
@@ -1,5 +1,19 @@
|
|
|
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;
|
|
5
|
+
export const DISTRIBUTOR_PREFIX = Buffer.from("MerkleDistributor", "utf-8");
|
|
6
|
+
export const ALIGNED_DISTRIBUTOR_PREFIX = Buffer.from("aligned-distributor", "utf-8");
|
|
7
|
+
export const TEST_ORACLE_PREFIX = Buffer.from("test-oracle", "utf-8");
|
|
8
|
+
export const CLAIM_STATUS_PREFIX = Buffer.from("ClaimStatus", "utf-8");
|
|
9
|
+
export const ALIGNED_PRECISION_FACTOR_POW = 9;
|
|
2
10
|
export const ONE_IN_BASIS_POINTS = BigInt(10000);
|
|
11
|
+
export const ALIGNED_DISTRIBUTOR_PROGRAM_ID = {
|
|
12
|
+
[ICluster.Devnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
|
|
13
|
+
[ICluster.Mainnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
|
|
14
|
+
[ICluster.Testnet]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
|
|
15
|
+
[ICluster.Local]: "aMERKpFAWoChCi5oZwPvgsSCoGpZKBiU7fi76bdZjt2",
|
|
16
|
+
};
|
|
3
17
|
export const DISTRIBUTOR_PROGRAM_ID = {
|
|
4
18
|
[ICluster.Devnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|
|
5
19
|
[ICluster.Mainnet]: "MErKy6nZVoVAkryxAejJz2juifQ4ArgLgHmaJCQkU7N",
|