@omnipair/dusk-sdk 2.0.0 → 2.0.1
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 +44 -0
- package/dist/idl_v2.json +14 -4
- package/dist/referral.d.ts.map +1 -1
- package/dist/referral.js +11 -1
- package/dist/referral.js.map +1 -1
- package/dist/types_v2.d.ts +14 -4
- package/dist/types_v2.d.ts.map +1 -1
- package/dist/write.d.ts +10 -0
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +29 -8
- package/dist/write.js.map +1 -1
- package/package.json +1 -1
- package/src/idl_v2.json +14 -4
- package/src/referral.ts +14 -0
- package/src/types_v2.ts +14 -4
- package/src/write.ts +52 -7
package/dist/write.d.ts
CHANGED
|
@@ -50,12 +50,22 @@ export declare class DuskWrite {
|
|
|
50
50
|
authority: AddressLike;
|
|
51
51
|
recipient: AddressLike;
|
|
52
52
|
}): Promise<TransactionInstruction>;
|
|
53
|
+
setReferralRecipientTransaction(params: {
|
|
54
|
+
authority: AddressLike;
|
|
55
|
+
recipient: AddressLike;
|
|
56
|
+
}): Promise<Transaction>;
|
|
53
57
|
claimReferralFeesInstruction(params: {
|
|
54
58
|
authority: AddressLike;
|
|
55
59
|
mint: AddressLike;
|
|
56
60
|
recipientTokenAccount: AddressLike;
|
|
57
61
|
remainingAccounts?: AccountMeta[];
|
|
58
62
|
}): Promise<TransactionInstruction>;
|
|
63
|
+
claimReferralFeesTransaction(params: {
|
|
64
|
+
authority: AddressLike;
|
|
65
|
+
mint: AddressLike;
|
|
66
|
+
recipientTokenAccount: AddressLike;
|
|
67
|
+
remainingAccounts?: AccountMeta[];
|
|
68
|
+
}): Promise<Transaction>;
|
|
59
69
|
}
|
|
60
70
|
export {};
|
|
61
71
|
//# sourceMappingURL=write.d.ts.map
|
package/dist/write.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names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B,IAAI,EAAE,WAAW,CAAC;QAClB,qBAAqB,EAAE,WAAW,CAAC;QACnC,iBAAiB,CAAC,EAAE,WAAW,EAAE,CAAC;KACnC,GAAG,OAAO,CAAC,WAAW,CAAC;CAGzB"}
|
package/dist/write.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
1
|
+
import { getAccount, getMint, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
2
2
|
import { SystemProgram, Transaction } from "@solana/web3.js";
|
|
3
3
|
import { address, normalizeAccountKeys } from "./address.js";
|
|
4
4
|
import { deriveReferralProfileAddress } from "./constants.js";
|
|
5
|
-
import { buildReferralVaultSetupInstruction, resolveTransferHookAccountMetas, } from "./referral.js";
|
|
5
|
+
import { buildReferralVaultSetupInstruction, referralVaultAddresses, resolveTransferHookAccountMetas, } from "./referral.js";
|
|
6
6
|
export class DuskWrite {
|
|
7
7
|
program;
|
|
8
8
|
constructor(program) {
|
|
@@ -83,27 +83,48 @@ export class DuskWrite {
|
|
|
83
83
|
},
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
|
+
async setReferralRecipientTransaction(params) {
|
|
87
|
+
return new Transaction().add(await this.setReferralRecipientInstruction(params));
|
|
88
|
+
}
|
|
86
89
|
async claimReferralFeesInstruction(params) {
|
|
87
90
|
const authority = address(params.authority);
|
|
88
|
-
const
|
|
91
|
+
const addresses = await referralVaultAddresses({
|
|
89
92
|
connection: this.program.provider.connection,
|
|
90
|
-
payer: authority,
|
|
91
93
|
referrer: authority,
|
|
92
94
|
mint: params.mint,
|
|
93
95
|
});
|
|
96
|
+
const recipientTokenAccount = address(params.recipientTokenAccount);
|
|
97
|
+
const [vaultAccount, mint] = await Promise.all([
|
|
98
|
+
getAccount(this.program.provider.connection, addresses.referralVault, undefined, addresses.tokenProgram),
|
|
99
|
+
getMint(this.program.provider.connection, address(params.mint), undefined, addresses.tokenProgram),
|
|
100
|
+
]);
|
|
101
|
+
const hookAccounts = await resolveTransferHookAccountMetas(this.program.provider.connection, [
|
|
102
|
+
{
|
|
103
|
+
source: addresses.referralVault,
|
|
104
|
+
mint: params.mint,
|
|
105
|
+
destination: recipientTokenAccount,
|
|
106
|
+
authority: addresses.referralProfile,
|
|
107
|
+
amount: vaultAccount.amount,
|
|
108
|
+
decimals: mint.decimals,
|
|
109
|
+
tokenProgram: addresses.tokenProgram,
|
|
110
|
+
},
|
|
111
|
+
]);
|
|
94
112
|
return this.instruction("claimReferralFees", undefined, {
|
|
95
113
|
accounts: {
|
|
96
114
|
authority,
|
|
97
|
-
referralProfile:
|
|
115
|
+
referralProfile: addresses.referralProfile,
|
|
98
116
|
assetMint: address(params.mint),
|
|
99
|
-
referralVault:
|
|
100
|
-
recipientTokenAccount
|
|
117
|
+
referralVault: addresses.referralVault,
|
|
118
|
+
recipientTokenAccount,
|
|
101
119
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
102
120
|
token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
103
121
|
},
|
|
104
|
-
remainingAccounts: params.remainingAccounts,
|
|
122
|
+
remainingAccounts: mergeAccountMetas(params.remainingAccounts ?? [], hookAccounts),
|
|
105
123
|
});
|
|
106
124
|
}
|
|
125
|
+
async claimReferralFeesTransaction(params) {
|
|
126
|
+
return new Transaction().add(await this.claimReferralFeesInstruction(params));
|
|
127
|
+
}
|
|
107
128
|
}
|
|
108
129
|
function normalizeArgs(args) {
|
|
109
130
|
if (args === undefined) {
|
package/dist/write.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.js","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"write.js","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AACA,OAAO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AAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;gBACrD,UAAU,EAAE,OAAO,CAAC,OAAO,EAAE,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC;aAC5D,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AAC9B,CAAC"}
|
package/package.json
CHANGED
package/src/idl_v2.json
CHANGED
|
@@ -8277,7 +8277,9 @@
|
|
|
8277
8277
|
},
|
|
8278
8278
|
{
|
|
8279
8279
|
"name": "max_acceptable_referral_fee_bps",
|
|
8280
|
-
"type":
|
|
8280
|
+
"type": {
|
|
8281
|
+
"option": "u16"
|
|
8282
|
+
}
|
|
8281
8283
|
}
|
|
8282
8284
|
]
|
|
8283
8285
|
}
|
|
@@ -8348,7 +8350,11 @@
|
|
|
8348
8350
|
"type": "u64"
|
|
8349
8351
|
},
|
|
8350
8352
|
{
|
|
8351
|
-
"name": "
|
|
8353
|
+
"name": "projected_referral_fee_debit",
|
|
8354
|
+
"type": "u64"
|
|
8355
|
+
},
|
|
8356
|
+
{
|
|
8357
|
+
"name": "projected_referral_vault_credit",
|
|
8352
8358
|
"type": "u64"
|
|
8353
8359
|
},
|
|
8354
8360
|
{
|
|
@@ -9179,7 +9185,9 @@
|
|
|
9179
9185
|
},
|
|
9180
9186
|
{
|
|
9181
9187
|
"name": "max_acceptable_referral_fee_bps",
|
|
9182
|
-
"type":
|
|
9188
|
+
"type": {
|
|
9189
|
+
"option": "u16"
|
|
9190
|
+
}
|
|
9183
9191
|
}
|
|
9184
9192
|
]
|
|
9185
9193
|
}
|
|
@@ -10762,7 +10770,9 @@
|
|
|
10762
10770
|
},
|
|
10763
10771
|
{
|
|
10764
10772
|
"name": "max_acceptable_referral_fee_bps",
|
|
10765
|
-
"type":
|
|
10773
|
+
"type": {
|
|
10774
|
+
"option": "u16"
|
|
10775
|
+
}
|
|
10766
10776
|
}
|
|
10767
10777
|
]
|
|
10768
10778
|
}
|
package/src/referral.ts
CHANGED
|
@@ -2,6 +2,8 @@ import {
|
|
|
2
2
|
createAssociatedTokenAccountIdempotentInstruction,
|
|
3
3
|
createTransferCheckedWithTransferHookInstruction,
|
|
4
4
|
getAssociatedTokenAddressSync,
|
|
5
|
+
getMint,
|
|
6
|
+
getTransferHook,
|
|
5
7
|
TOKEN_2022_PROGRAM_ID,
|
|
6
8
|
TOKEN_PROGRAM_ID,
|
|
7
9
|
} from "@solana/spl-token";
|
|
@@ -158,6 +160,9 @@ export async function resolveTransferHookAccountMetas(
|
|
|
158
160
|
commitment,
|
|
159
161
|
tokenProgram
|
|
160
162
|
);
|
|
163
|
+
const transferHook = getTransferHook(
|
|
164
|
+
await getMint(connection, mint, commitment, tokenProgram)
|
|
165
|
+
);
|
|
161
166
|
for (const meta of instruction.keys.slice(4)) {
|
|
162
167
|
const key = meta.pubkey.toBase58();
|
|
163
168
|
const current = merged.get(key);
|
|
@@ -167,6 +172,15 @@ export async function resolveTransferHookAccountMetas(
|
|
|
167
172
|
isWritable: Boolean(current?.isWritable || meta.isWritable),
|
|
168
173
|
});
|
|
169
174
|
}
|
|
175
|
+
if (transferHook) {
|
|
176
|
+
const key = transferHook.programId.toBase58();
|
|
177
|
+
const current = merged.get(key);
|
|
178
|
+
merged.set(key, {
|
|
179
|
+
pubkey: transferHook.programId,
|
|
180
|
+
isSigner: Boolean(current?.isSigner),
|
|
181
|
+
isWritable: Boolean(current?.isWritable),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
170
184
|
}
|
|
171
185
|
return [...merged.values()];
|
|
172
186
|
}
|
package/src/types_v2.ts
CHANGED
|
@@ -8283,7 +8283,9 @@ export type Dusk = {
|
|
|
8283
8283
|
},
|
|
8284
8284
|
{
|
|
8285
8285
|
"name": "maxAcceptableReferralFeeBps",
|
|
8286
|
-
"type":
|
|
8286
|
+
"type": {
|
|
8287
|
+
"option": "u16"
|
|
8288
|
+
}
|
|
8287
8289
|
}
|
|
8288
8290
|
]
|
|
8289
8291
|
}
|
|
@@ -8354,7 +8356,11 @@ export type Dusk = {
|
|
|
8354
8356
|
"type": "u64"
|
|
8355
8357
|
},
|
|
8356
8358
|
{
|
|
8357
|
-
"name": "
|
|
8359
|
+
"name": "projectedReferralFeeDebit",
|
|
8360
|
+
"type": "u64"
|
|
8361
|
+
},
|
|
8362
|
+
{
|
|
8363
|
+
"name": "projectedReferralVaultCredit",
|
|
8358
8364
|
"type": "u64"
|
|
8359
8365
|
},
|
|
8360
8366
|
{
|
|
@@ -9185,7 +9191,9 @@ export type Dusk = {
|
|
|
9185
9191
|
},
|
|
9186
9192
|
{
|
|
9187
9193
|
"name": "maxAcceptableReferralFeeBps",
|
|
9188
|
-
"type":
|
|
9194
|
+
"type": {
|
|
9195
|
+
"option": "u16"
|
|
9196
|
+
}
|
|
9189
9197
|
}
|
|
9190
9198
|
]
|
|
9191
9199
|
}
|
|
@@ -10768,7 +10776,9 @@ export type Dusk = {
|
|
|
10768
10776
|
},
|
|
10769
10777
|
{
|
|
10770
10778
|
"name": "maxAcceptableReferralFeeBps",
|
|
10771
|
-
"type":
|
|
10779
|
+
"type": {
|
|
10780
|
+
"option": "u16"
|
|
10781
|
+
}
|
|
10772
10782
|
}
|
|
10773
10783
|
]
|
|
10774
10784
|
}
|
package/src/write.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { Program } from "@coral-xyz/anchor";
|
|
2
|
-
import { TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
2
|
+
import { getAccount, getMint, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
3
3
|
import { SystemProgram, Transaction, type AccountMeta, type TransactionInstruction } from "@solana/web3.js";
|
|
4
4
|
|
|
5
5
|
import { address, normalizeAccountKeys, type AddressLike } from "./address.js";
|
|
6
6
|
import { deriveReferralProfileAddress } from "./constants.js";
|
|
7
7
|
import {
|
|
8
8
|
buildReferralVaultSetupInstruction,
|
|
9
|
+
referralVaultAddresses,
|
|
9
10
|
resolveTransferHookAccountMetas,
|
|
10
11
|
type TransferHookTransfer,
|
|
11
12
|
} from "./referral.js";
|
|
@@ -167,6 +168,13 @@ export class DuskWrite {
|
|
|
167
168
|
);
|
|
168
169
|
}
|
|
169
170
|
|
|
171
|
+
async setReferralRecipientTransaction(params: {
|
|
172
|
+
authority: AddressLike;
|
|
173
|
+
recipient: AddressLike;
|
|
174
|
+
}): Promise<Transaction> {
|
|
175
|
+
return new Transaction().add(await this.setReferralRecipientInstruction(params));
|
|
176
|
+
}
|
|
177
|
+
|
|
170
178
|
async claimReferralFeesInstruction(params: {
|
|
171
179
|
authority: AddressLike;
|
|
172
180
|
mint: AddressLike;
|
|
@@ -174,25 +182,62 @@ export class DuskWrite {
|
|
|
174
182
|
remainingAccounts?: AccountMeta[];
|
|
175
183
|
}): Promise<TransactionInstruction> {
|
|
176
184
|
const authority = address(params.authority);
|
|
177
|
-
const
|
|
185
|
+
const addresses = await referralVaultAddresses({
|
|
178
186
|
connection: this.program.provider.connection,
|
|
179
|
-
payer: authority,
|
|
180
187
|
referrer: authority,
|
|
181
188
|
mint: params.mint,
|
|
182
189
|
});
|
|
190
|
+
const recipientTokenAccount = address(params.recipientTokenAccount);
|
|
191
|
+
const [vaultAccount, mint] = await Promise.all([
|
|
192
|
+
getAccount(
|
|
193
|
+
this.program.provider.connection,
|
|
194
|
+
addresses.referralVault,
|
|
195
|
+
undefined,
|
|
196
|
+
addresses.tokenProgram
|
|
197
|
+
),
|
|
198
|
+
getMint(
|
|
199
|
+
this.program.provider.connection,
|
|
200
|
+
address(params.mint),
|
|
201
|
+
undefined,
|
|
202
|
+
addresses.tokenProgram
|
|
203
|
+
),
|
|
204
|
+
]);
|
|
205
|
+
const hookAccounts = await resolveTransferHookAccountMetas(
|
|
206
|
+
this.program.provider.connection,
|
|
207
|
+
[
|
|
208
|
+
{
|
|
209
|
+
source: addresses.referralVault,
|
|
210
|
+
mint: params.mint,
|
|
211
|
+
destination: recipientTokenAccount,
|
|
212
|
+
authority: addresses.referralProfile,
|
|
213
|
+
amount: vaultAccount.amount,
|
|
214
|
+
decimals: mint.decimals,
|
|
215
|
+
tokenProgram: addresses.tokenProgram,
|
|
216
|
+
},
|
|
217
|
+
]
|
|
218
|
+
);
|
|
183
219
|
return this.instruction("claimReferralFees", undefined, {
|
|
184
220
|
accounts: {
|
|
185
221
|
authority,
|
|
186
|
-
referralProfile:
|
|
222
|
+
referralProfile: addresses.referralProfile,
|
|
187
223
|
assetMint: address(params.mint),
|
|
188
|
-
referralVault:
|
|
189
|
-
recipientTokenAccount
|
|
224
|
+
referralVault: addresses.referralVault,
|
|
225
|
+
recipientTokenAccount,
|
|
190
226
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
191
227
|
token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
192
228
|
},
|
|
193
|
-
remainingAccounts: params.remainingAccounts,
|
|
229
|
+
remainingAccounts: mergeAccountMetas(params.remainingAccounts ?? [], hookAccounts),
|
|
194
230
|
});
|
|
195
231
|
}
|
|
232
|
+
|
|
233
|
+
async claimReferralFeesTransaction(params: {
|
|
234
|
+
authority: AddressLike;
|
|
235
|
+
mint: AddressLike;
|
|
236
|
+
recipientTokenAccount: AddressLike;
|
|
237
|
+
remainingAccounts?: AccountMeta[];
|
|
238
|
+
}): Promise<Transaction> {
|
|
239
|
+
return new Transaction().add(await this.claimReferralFeesInstruction(params));
|
|
240
|
+
}
|
|
196
241
|
}
|
|
197
242
|
|
|
198
243
|
function normalizeArgs(args: DuskInstructionArgs): unknown[] {
|