@liquid-af/sdk 0.2.0 → 0.3.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/dist/accounts/liquid-swap.d.ts +2 -0
- package/dist/accounts/liquid-swap.d.ts.map +1 -1
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/helpers/preview.js.map +1 -1
- package/dist/idl/index.d.ts +1 -0
- package/dist/idl/index.d.ts.map +1 -1
- package/dist/idl/index.js +15 -4
- package/dist/idl/index.js.map +1 -1
- package/dist/idl/liquid.d.ts +1359 -1359
- package/dist/idl/liquid.d.ts.map +1 -1
- package/dist/idl/liquid.json +1359 -1359
- package/dist/idl/liquid_fees.d.ts +1 -1
- package/dist/idl/liquid_fees.json +1 -1
- package/dist/idl/liquid_state.d.ts +62 -62
- package/dist/idl/liquid_state.d.ts.map +1 -1
- package/dist/idl/liquid_state.json +62 -62
- package/dist/idl/liquid_swap.d.ts +597 -494
- package/dist/idl/liquid_swap.d.ts.map +1 -1
- package/dist/idl/liquid_swap.json +597 -494
- package/dist/idl/patch-idl.d.ts +10 -0
- package/dist/idl/patch-idl.d.ts.map +1 -0
- package/dist/idl/patch-idl.js +62 -0
- package/dist/idl/patch-idl.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/instructions/program-cache.d.ts.map +1 -1
- package/dist/instructions/program-cache.js +10 -6
- package/dist/instructions/program-cache.js.map +1 -1
- package/package.json +4 -4
- package/src/accounts/liquid-fees.ts +2 -2
- package/src/accounts/liquid-state.ts +7 -7
- package/src/accounts/liquid-swap.ts +4 -4
- package/src/accounts/liquid.ts +6 -6
- package/src/client.ts +31 -31
- package/src/config.ts +10 -10
- package/src/errors.ts +6 -6
- package/src/events/parser.ts +5 -5
- package/src/helpers/preview.ts +31 -31
- package/src/helpers/user.ts +1 -1
- package/src/idl/index.ts +31 -8
- package/src/idl/liquid.json +1359 -1359
- package/src/idl/liquid.ts +1359 -1359
- package/src/idl/liquid_fees.json +1 -1
- package/src/idl/liquid_fees.ts +1 -1
- package/src/idl/liquid_state.json +62 -62
- package/src/idl/liquid_state.ts +62 -62
- package/src/idl/liquid_swap.json +597 -494
- package/src/idl/liquid_swap.ts +597 -494
- package/src/idl/patch-idl.ts +80 -0
- package/src/index.ts +1 -0
- package/src/instructions/liquid-fees.ts +14 -14
- package/src/instructions/liquid-state.ts +4 -4
- package/src/instructions/liquid-swap.ts +18 -18
- package/src/instructions/liquid.ts +47 -47
- package/src/instructions/program-cache.ts +18 -9
- package/src/math/amm.ts +3 -3
- package/src/math/bonding-curve.ts +6 -6
- package/src/math/fees.ts +9 -9
- package/src/math/tiered-fees.ts +5 -5
- package/src/oracle.ts +3 -3
- package/src/pda/index.ts +27 -27
- package/src/pda/liquid-fees.ts +6 -6
- package/src/pda/liquid-state.ts +13 -13
- package/src/pda/liquid-swap.ts +16 -16
- package/src/pda/liquid.ts +15 -15
- package/src/provider.ts +2 -2
- package/src/transaction/builder.ts +4 -4
- package/src/transaction/send.ts +4 -4
- package/src/types.ts +2 -2
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { MAINNET_CONFIG, type LiquidConfig } from "../config.js";
|
|
3
|
+
|
|
4
|
+
interface ProgramReplacement {
|
|
5
|
+
mainnetAddress: string;
|
|
6
|
+
mainnetBytes: number[];
|
|
7
|
+
targetAddress: string;
|
|
8
|
+
targetBytes: number[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function buildReplacementMap(config: LiquidConfig): ProgramReplacement[] {
|
|
12
|
+
const pairs: [PublicKey, PublicKey][] = [
|
|
13
|
+
[MAINNET_CONFIG.liquidProgramId, config.liquidProgramId],
|
|
14
|
+
[MAINNET_CONFIG.liquidSwapProgramId, config.liquidSwapProgramId],
|
|
15
|
+
[MAINNET_CONFIG.liquidFeesProgramId, config.liquidFeesProgramId],
|
|
16
|
+
[MAINNET_CONFIG.liquidStateProgramId, config.liquidStateProgramId],
|
|
17
|
+
];
|
|
18
|
+
return pairs
|
|
19
|
+
.filter(([mainnet, target]) => !mainnet.equals(target))
|
|
20
|
+
.map(([mainnet, target]) => ({
|
|
21
|
+
mainnetAddress: mainnet.toBase58(),
|
|
22
|
+
mainnetBytes: Array.from(mainnet.toBytes()),
|
|
23
|
+
targetAddress: target.toBase58(),
|
|
24
|
+
targetBytes: Array.from(target.toBytes()),
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function deepPatch(
|
|
29
|
+
node: unknown,
|
|
30
|
+
stringMap: Map<string, string>,
|
|
31
|
+
byteMap: Map<string, number[]>,
|
|
32
|
+
): unknown {
|
|
33
|
+
if (node === null || node === undefined) return node;
|
|
34
|
+
if (typeof node !== "object") return node;
|
|
35
|
+
|
|
36
|
+
if (Array.isArray(node)) {
|
|
37
|
+
if (node.length === 32 && typeof node[0] === "number") {
|
|
38
|
+
const key = JSON.stringify(node);
|
|
39
|
+
const replacement = byteMap.get(key);
|
|
40
|
+
if (replacement) return replacement;
|
|
41
|
+
}
|
|
42
|
+
return node.map((item) => deepPatch(item, stringMap, byteMap));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const result: Record<string, unknown> = {};
|
|
46
|
+
for (const [key, value] of Object.entries(
|
|
47
|
+
node as Record<string, unknown>,
|
|
48
|
+
)) {
|
|
49
|
+
if (key === "address" && typeof value === "string") {
|
|
50
|
+
result[key] = stringMap.get(value) ?? value;
|
|
51
|
+
} else {
|
|
52
|
+
result[key] = deepPatch(value, stringMap, byteMap);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Deep-patches an Anchor IDL JSON object, replacing all embedded mainnet
|
|
60
|
+
* program addresses (both string and byte-array forms) with the addresses
|
|
61
|
+
* from the provided config.
|
|
62
|
+
*
|
|
63
|
+
* Returns the original IDL unchanged if config matches mainnet.
|
|
64
|
+
*/
|
|
65
|
+
export function patchIdl<T extends Record<string, unknown>>(
|
|
66
|
+
idl: T,
|
|
67
|
+
config: LiquidConfig,
|
|
68
|
+
): T {
|
|
69
|
+
const replacements = buildReplacementMap(config);
|
|
70
|
+
if (replacements.length === 0) return idl;
|
|
71
|
+
|
|
72
|
+
const stringMap = new Map<string, string>();
|
|
73
|
+
const byteMap = new Map<string, number[]>();
|
|
74
|
+
for (const r of replacements) {
|
|
75
|
+
stringMap.set(r.mainnetAddress, r.targetAddress);
|
|
76
|
+
byteMap.set(JSON.stringify(r.mainnetBytes), r.targetBytes);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return deepPatch(idl, stringMap, byteMap) as T;
|
|
80
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface BuildUpdateFeeConfigParams {
|
|
|
27
27
|
* @returns Transaction instruction
|
|
28
28
|
*/
|
|
29
29
|
export function buildUpdateFeeConfig(
|
|
30
|
-
params: BuildUpdateFeeConfigParams
|
|
30
|
+
params: BuildUpdateFeeConfigParams,
|
|
31
31
|
): Promise<TransactionInstruction> {
|
|
32
32
|
const {
|
|
33
33
|
authority,
|
|
@@ -50,16 +50,16 @@ export function buildUpdateFeeConfig(
|
|
|
50
50
|
if (recipients && quoteMint) {
|
|
51
51
|
const [feeConfig] = getFeeConfigPDA(
|
|
52
52
|
tokenMint,
|
|
53
|
-
config.liquidFeesProgramId
|
|
53
|
+
config.liquidFeesProgramId,
|
|
54
54
|
);
|
|
55
55
|
const [feeVault] = getFeeVaultPDA(
|
|
56
56
|
feeConfig,
|
|
57
|
-
config.liquidFeesProgramId
|
|
57
|
+
config.liquidFeesProgramId,
|
|
58
58
|
);
|
|
59
59
|
tokenFeeVault = getAssociatedTokenAddressSync(
|
|
60
60
|
quoteMint,
|
|
61
61
|
feeVault,
|
|
62
|
-
true
|
|
62
|
+
true,
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -92,7 +92,7 @@ export interface BuildRevokeFeeConfigParams {
|
|
|
92
92
|
* @returns Transaction instruction
|
|
93
93
|
*/
|
|
94
94
|
export function buildRevokeFeeConfig(
|
|
95
|
-
params: BuildRevokeFeeConfigParams
|
|
95
|
+
params: BuildRevokeFeeConfigParams,
|
|
96
96
|
): Promise<TransactionInstruction> {
|
|
97
97
|
const { authority, tokenMint, quoteMint, config } = params;
|
|
98
98
|
const program = getCachedFeesProgram(config);
|
|
@@ -103,7 +103,7 @@ export function buildRevokeFeeConfig(
|
|
|
103
103
|
const tokenFeeVault = getAssociatedTokenAddressSync(
|
|
104
104
|
quoteMint,
|
|
105
105
|
feeVault,
|
|
106
|
-
true
|
|
106
|
+
true,
|
|
107
107
|
);
|
|
108
108
|
|
|
109
109
|
return program.methods
|
|
@@ -133,7 +133,7 @@ export interface BuildDistributeFeesParams {
|
|
|
133
133
|
* @returns Transaction instruction
|
|
134
134
|
*/
|
|
135
135
|
export function buildDistributeFees(
|
|
136
|
-
params: BuildDistributeFeesParams
|
|
136
|
+
params: BuildDistributeFeesParams,
|
|
137
137
|
): Promise<TransactionInstruction> {
|
|
138
138
|
const { payer, tokenMint, recipientVaults, config } = params;
|
|
139
139
|
const program = getCachedFeesProgram(config);
|
|
@@ -149,7 +149,7 @@ export function buildDistributeFees(
|
|
|
149
149
|
pubkey: vault,
|
|
150
150
|
isSigner: false,
|
|
151
151
|
isWritable: true,
|
|
152
|
-
}))
|
|
152
|
+
})),
|
|
153
153
|
)
|
|
154
154
|
.instruction();
|
|
155
155
|
}
|
|
@@ -177,7 +177,7 @@ export interface BuildDistributeTokenFeesParams {
|
|
|
177
177
|
* @returns Transaction instruction
|
|
178
178
|
*/
|
|
179
179
|
export function buildDistributeTokenFees(
|
|
180
|
-
params: BuildDistributeTokenFeesParams
|
|
180
|
+
params: BuildDistributeTokenFeesParams,
|
|
181
181
|
): Promise<TransactionInstruction> {
|
|
182
182
|
const { payer, tokenMint, quoteMint, recipientVaultPairs, config } = params;
|
|
183
183
|
const program = getCachedFeesProgram(config);
|
|
@@ -213,7 +213,7 @@ export interface BuildClaimFeesParams {
|
|
|
213
213
|
* @returns Transaction instruction
|
|
214
214
|
*/
|
|
215
215
|
export function buildClaimFees(
|
|
216
|
-
params: BuildClaimFeesParams
|
|
216
|
+
params: BuildClaimFeesParams,
|
|
217
217
|
): Promise<TransactionInstruction> {
|
|
218
218
|
const { recipient, tokenMint, config } = params;
|
|
219
219
|
const program = getCachedFeesProgram(config);
|
|
@@ -244,7 +244,7 @@ export interface BuildClaimTokenFeesParams {
|
|
|
244
244
|
* @returns Transaction instruction
|
|
245
245
|
*/
|
|
246
246
|
export function buildClaimTokenFees(
|
|
247
|
-
params: BuildClaimTokenFeesParams
|
|
247
|
+
params: BuildClaimTokenFeesParams,
|
|
248
248
|
): Promise<TransactionInstruction> {
|
|
249
249
|
const { recipient, tokenMint, quoteMint, config } = params;
|
|
250
250
|
const program = getCachedFeesProgram(config);
|
|
@@ -273,19 +273,19 @@ export function deriveRecipientVaultPairs(
|
|
|
273
273
|
tokenMint: PublicKey,
|
|
274
274
|
recipients: PublicKey[],
|
|
275
275
|
quoteMint: PublicKey,
|
|
276
|
-
config: LiquidConfig
|
|
276
|
+
config: LiquidConfig,
|
|
277
277
|
): RecipientVaultPair[] {
|
|
278
278
|
const [feeConfig] = getFeeConfigPDA(tokenMint, config.liquidFeesProgramId);
|
|
279
279
|
return recipients.map((recipient) => {
|
|
280
280
|
const [vaultPda] = getRecipientVaultPDA(
|
|
281
281
|
feeConfig,
|
|
282
282
|
recipient,
|
|
283
|
-
config.liquidFeesProgramId
|
|
283
|
+
config.liquidFeesProgramId,
|
|
284
284
|
);
|
|
285
285
|
const vaultAta = getAssociatedTokenAddressSync(
|
|
286
286
|
quoteMint,
|
|
287
287
|
vaultPda,
|
|
288
|
-
true
|
|
288
|
+
true,
|
|
289
289
|
);
|
|
290
290
|
return { vaultPda, vaultAta };
|
|
291
291
|
});
|
|
@@ -16,7 +16,7 @@ export interface BuildInitializeUserParams {
|
|
|
16
16
|
* @returns Transaction instruction
|
|
17
17
|
*/
|
|
18
18
|
export function buildInitializeUser(
|
|
19
|
-
params: BuildInitializeUserParams
|
|
19
|
+
params: BuildInitializeUserParams,
|
|
20
20
|
): Promise<TransactionInstruction> {
|
|
21
21
|
const { user, config } = params;
|
|
22
22
|
const program = getCachedStateProgram(config);
|
|
@@ -38,7 +38,7 @@ export interface BuildSetReferrerParams {
|
|
|
38
38
|
* @returns Transaction instruction
|
|
39
39
|
*/
|
|
40
40
|
export function buildSetReferrer(
|
|
41
|
-
params: BuildSetReferrerParams
|
|
41
|
+
params: BuildSetReferrerParams,
|
|
42
42
|
): Promise<TransactionInstruction> {
|
|
43
43
|
const { user, referrer, config } = params;
|
|
44
44
|
const program = getCachedStateProgram(config);
|
|
@@ -62,7 +62,7 @@ export interface BuildSetCashbackModeParams {
|
|
|
62
62
|
* @returns Transaction instruction
|
|
63
63
|
*/
|
|
64
64
|
export function buildSetCashbackMode(
|
|
65
|
-
params: BuildSetCashbackModeParams
|
|
65
|
+
params: BuildSetCashbackModeParams,
|
|
66
66
|
): Promise<TransactionInstruction> {
|
|
67
67
|
const { user, config } = params;
|
|
68
68
|
const program = getCachedStateProgram(config);
|
|
@@ -84,7 +84,7 @@ export interface BuildRedeemDealParams {
|
|
|
84
84
|
* @returns Transaction instruction
|
|
85
85
|
*/
|
|
86
86
|
export function buildRedeemDeal(
|
|
87
|
-
params: BuildRedeemDealParams
|
|
87
|
+
params: BuildRedeemDealParams,
|
|
88
88
|
): Promise<TransactionInstruction> {
|
|
89
89
|
const { user, dealOwner, config } = params;
|
|
90
90
|
const program = getCachedStateProgram(config);
|
|
@@ -26,7 +26,7 @@ export interface BuildCreatePoolParams {
|
|
|
26
26
|
* @returns Transaction instruction
|
|
27
27
|
*/
|
|
28
28
|
export function buildCreatePool(
|
|
29
|
-
params: BuildCreatePoolParams
|
|
29
|
+
params: BuildCreatePoolParams,
|
|
30
30
|
): Promise<TransactionInstruction> {
|
|
31
31
|
const {
|
|
32
32
|
signer,
|
|
@@ -46,13 +46,13 @@ export function buildCreatePool(
|
|
|
46
46
|
baseMint,
|
|
47
47
|
signer,
|
|
48
48
|
false,
|
|
49
|
-
baseTokenProgram
|
|
49
|
+
baseTokenProgram,
|
|
50
50
|
);
|
|
51
51
|
const creatorQuote = getAssociatedTokenAddressSync(
|
|
52
52
|
quoteMint,
|
|
53
53
|
signer,
|
|
54
54
|
false,
|
|
55
|
-
quoteTokenProgram
|
|
55
|
+
quoteTokenProgram,
|
|
56
56
|
);
|
|
57
57
|
|
|
58
58
|
return program.methods
|
|
@@ -91,7 +91,7 @@ export interface BuildSwapBuyParams {
|
|
|
91
91
|
* @returns Transaction instruction
|
|
92
92
|
*/
|
|
93
93
|
export function buildSwapBuy(
|
|
94
|
-
params: BuildSwapBuyParams
|
|
94
|
+
params: BuildSwapBuyParams,
|
|
95
95
|
): Promise<TransactionInstruction> {
|
|
96
96
|
const {
|
|
97
97
|
payer,
|
|
@@ -113,13 +113,13 @@ export function buildSwapBuy(
|
|
|
113
113
|
baseMint,
|
|
114
114
|
payer,
|
|
115
115
|
false,
|
|
116
|
-
baseTokenProgram
|
|
116
|
+
baseTokenProgram,
|
|
117
117
|
);
|
|
118
118
|
const quoteTokenAccount = getAssociatedTokenAddressSync(
|
|
119
119
|
quoteMint,
|
|
120
120
|
payer,
|
|
121
121
|
false,
|
|
122
|
-
quoteTokenProgram
|
|
122
|
+
quoteTokenProgram,
|
|
123
123
|
);
|
|
124
124
|
return program.methods
|
|
125
125
|
.buy(maxAmountIn, amountOut)
|
|
@@ -163,7 +163,7 @@ export interface BuildSwapSellParams {
|
|
|
163
163
|
* @returns Transaction instruction
|
|
164
164
|
*/
|
|
165
165
|
export function buildSwapSell(
|
|
166
|
-
params: BuildSwapSellParams
|
|
166
|
+
params: BuildSwapSellParams,
|
|
167
167
|
): Promise<TransactionInstruction> {
|
|
168
168
|
const {
|
|
169
169
|
payer,
|
|
@@ -185,13 +185,13 @@ export function buildSwapSell(
|
|
|
185
185
|
baseMint,
|
|
186
186
|
payer,
|
|
187
187
|
false,
|
|
188
|
-
baseTokenProgram
|
|
188
|
+
baseTokenProgram,
|
|
189
189
|
);
|
|
190
190
|
const quoteTokenAccount = getAssociatedTokenAddressSync(
|
|
191
191
|
quoteMint,
|
|
192
192
|
payer,
|
|
193
193
|
false,
|
|
194
|
-
quoteTokenProgram
|
|
194
|
+
quoteTokenProgram,
|
|
195
195
|
);
|
|
196
196
|
return program.methods
|
|
197
197
|
.sell(amountIn, minimumAmountOut)
|
|
@@ -237,7 +237,7 @@ export interface BuildDepositParams {
|
|
|
237
237
|
* @returns Transaction instruction
|
|
238
238
|
*/
|
|
239
239
|
export function buildDeposit(
|
|
240
|
-
params: BuildDepositParams
|
|
240
|
+
params: BuildDepositParams,
|
|
241
241
|
): Promise<TransactionInstruction> {
|
|
242
242
|
const {
|
|
243
243
|
owner,
|
|
@@ -261,19 +261,19 @@ export function buildDeposit(
|
|
|
261
261
|
lpMint,
|
|
262
262
|
owner,
|
|
263
263
|
false,
|
|
264
|
-
TOKEN_PROGRAM_ID
|
|
264
|
+
TOKEN_PROGRAM_ID,
|
|
265
265
|
);
|
|
266
266
|
const baseAccount = getAssociatedTokenAddressSync(
|
|
267
267
|
baseMint,
|
|
268
268
|
owner,
|
|
269
269
|
false,
|
|
270
|
-
baseTokenProgram
|
|
270
|
+
baseTokenProgram,
|
|
271
271
|
);
|
|
272
272
|
const quoteAccount = getAssociatedTokenAddressSync(
|
|
273
273
|
quoteMint,
|
|
274
274
|
owner,
|
|
275
275
|
false,
|
|
276
|
-
quoteTokenProgram
|
|
276
|
+
quoteTokenProgram,
|
|
277
277
|
);
|
|
278
278
|
|
|
279
279
|
return program.methods
|
|
@@ -316,7 +316,7 @@ export interface BuildWithdrawParams {
|
|
|
316
316
|
* @returns Transaction instruction
|
|
317
317
|
*/
|
|
318
318
|
export function buildWithdraw(
|
|
319
|
-
params: BuildWithdrawParams
|
|
319
|
+
params: BuildWithdrawParams,
|
|
320
320
|
): Promise<TransactionInstruction> {
|
|
321
321
|
const {
|
|
322
322
|
owner,
|
|
@@ -340,19 +340,19 @@ export function buildWithdraw(
|
|
|
340
340
|
lpMint,
|
|
341
341
|
owner,
|
|
342
342
|
false,
|
|
343
|
-
TOKEN_PROGRAM_ID
|
|
343
|
+
TOKEN_PROGRAM_ID,
|
|
344
344
|
);
|
|
345
345
|
const baseAccount = getAssociatedTokenAddressSync(
|
|
346
346
|
baseMint,
|
|
347
347
|
owner,
|
|
348
348
|
false,
|
|
349
|
-
baseTokenProgram
|
|
349
|
+
baseTokenProgram,
|
|
350
350
|
);
|
|
351
351
|
const quoteAccount = getAssociatedTokenAddressSync(
|
|
352
352
|
quoteMint,
|
|
353
353
|
owner,
|
|
354
354
|
false,
|
|
355
|
-
quoteTokenProgram
|
|
355
|
+
quoteTokenProgram,
|
|
356
356
|
);
|
|
357
357
|
|
|
358
358
|
return program.methods
|
|
@@ -389,7 +389,7 @@ export interface BuildSwapExecuteBuybackParams {
|
|
|
389
389
|
* @returns Transaction instruction
|
|
390
390
|
*/
|
|
391
391
|
export function buildSwapExecuteBuyback(
|
|
392
|
-
params: BuildSwapExecuteBuybackParams
|
|
392
|
+
params: BuildSwapExecuteBuybackParams,
|
|
393
393
|
): Promise<TransactionInstruction> {
|
|
394
394
|
const {
|
|
395
395
|
payer,
|