@liquid-af/sdk 0.1.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 +776 -0
- package/dist/accounts/index.d.ts +5 -0
- package/dist/accounts/index.d.ts.map +1 -0
- package/dist/accounts/index.js +5 -0
- package/dist/accounts/index.js.map +1 -0
- package/dist/accounts/liquid-fees.d.ts +63 -0
- package/dist/accounts/liquid-fees.d.ts.map +1 -0
- package/dist/accounts/liquid-fees.js +27 -0
- package/dist/accounts/liquid-fees.js.map +1 -0
- package/dist/accounts/liquid-state.d.ts +112 -0
- package/dist/accounts/liquid-state.d.ts.map +1 -0
- package/dist/accounts/liquid-state.js +92 -0
- package/dist/accounts/liquid-state.js.map +1 -0
- package/dist/accounts/liquid-swap.d.ts +97 -0
- package/dist/accounts/liquid-swap.d.ts.map +1 -0
- package/dist/accounts/liquid-swap.js +54 -0
- package/dist/accounts/liquid-swap.js.map +1 -0
- package/dist/accounts/liquid.d.ts +175 -0
- package/dist/accounts/liquid.d.ts.map +1 -0
- package/dist/accounts/liquid.js +66 -0
- package/dist/accounts/liquid.js.map +1 -0
- package/dist/client.d.ts +621 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +511 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +56 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +44 -0
- package/dist/config.js.map +1 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +63 -0
- package/dist/errors.js.map +1 -0
- package/dist/events/index.d.ts +4 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +2 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/parser.d.ts +40 -0
- package/dist/events/parser.d.ts.map +1 -0
- package/dist/events/parser.js +67 -0
- package/dist/events/parser.js.map +1 -0
- package/dist/events/types.d.ts +286 -0
- package/dist/events/types.d.ts.map +1 -0
- package/dist/events/types.js +2 -0
- package/dist/events/types.js.map +1 -0
- package/dist/helpers/index.d.ts +4 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +3 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/preview.d.ts +259 -0
- package/dist/helpers/preview.d.ts.map +1 -0
- package/dist/helpers/preview.js +458 -0
- package/dist/helpers/preview.js.map +1 -0
- package/dist/helpers/user.d.ts +11 -0
- package/dist/helpers/user.d.ts.map +1 -0
- package/dist/helpers/user.js +20 -0
- package/dist/helpers/user.js.map +1 -0
- package/dist/idl/index.d.ts +53 -0
- package/dist/idl/index.d.ts.map +1 -0
- package/dist/idl/index.js +64 -0
- package/dist/idl/index.js.map +1 -0
- package/dist/idl/liquid.d.ts +10523 -0
- package/dist/idl/liquid.d.ts.map +1 -0
- package/dist/idl/liquid.js +2 -0
- package/dist/idl/liquid.js.map +1 -0
- package/dist/idl/liquid.json +10516 -0
- package/dist/idl/liquid_fees.d.ts +1520 -0
- package/dist/idl/liquid_fees.d.ts.map +1 -0
- package/dist/idl/liquid_fees.js +2 -0
- package/dist/idl/liquid_fees.js.map +1 -0
- package/dist/idl/liquid_fees.json +1513 -0
- package/dist/idl/liquid_state.d.ts +2936 -0
- package/dist/idl/liquid_state.d.ts.map +1 -0
- package/dist/idl/liquid_state.js +2 -0
- package/dist/idl/liquid_state.js.map +1 -0
- package/dist/idl/liquid_state.json +2929 -0
- package/dist/idl/liquid_swap.d.ts +5849 -0
- package/dist/idl/liquid_swap.d.ts.map +1 -0
- package/dist/idl/liquid_swap.js +2 -0
- package/dist/idl/liquid_swap.js.map +1 -0
- package/dist/idl/liquid_swap.json +5842 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/instructions/index.d.ts +9 -0
- package/dist/instructions/index.d.ts.map +1 -0
- package/dist/instructions/index.js +9 -0
- package/dist/instructions/index.js.map +1 -0
- package/dist/instructions/liquid-fees.d.ts +111 -0
- package/dist/instructions/liquid-fees.d.ts.map +1 -0
- package/dist/instructions/liquid-fees.js +169 -0
- package/dist/instructions/liquid-fees.js.map +1 -0
- package/dist/instructions/liquid-state.d.ts +173 -0
- package/dist/instructions/liquid-state.d.ts.map +1 -0
- package/dist/instructions/liquid-state.js +194 -0
- package/dist/instructions/liquid-state.js.map +1 -0
- package/dist/instructions/liquid-swap.d.ts +122 -0
- package/dist/instructions/liquid-swap.d.ts.map +1 -0
- package/dist/instructions/liquid-swap.js +167 -0
- package/dist/instructions/liquid-swap.js.map +1 -0
- package/dist/instructions/liquid.d.ts +297 -0
- package/dist/instructions/liquid.d.ts.map +1 -0
- package/dist/instructions/liquid.js +483 -0
- package/dist/instructions/liquid.js.map +1 -0
- package/dist/instructions/program-cache.d.ts +35 -0
- package/dist/instructions/program-cache.d.ts.map +1 -0
- package/dist/instructions/program-cache.js +68 -0
- package/dist/instructions/program-cache.js.map +1 -0
- package/dist/math/amm.d.ts +42 -0
- package/dist/math/amm.d.ts.map +1 -0
- package/dist/math/amm.js +109 -0
- package/dist/math/amm.js.map +1 -0
- package/dist/math/bonding-curve.d.ts +34 -0
- package/dist/math/bonding-curve.d.ts.map +1 -0
- package/dist/math/bonding-curve.js +80 -0
- package/dist/math/bonding-curve.js.map +1 -0
- package/dist/math/constants.d.ts +14 -0
- package/dist/math/constants.d.ts.map +1 -0
- package/dist/math/constants.js +14 -0
- package/dist/math/constants.js.map +1 -0
- package/dist/math/fees.d.ts +88 -0
- package/dist/math/fees.d.ts.map +1 -0
- package/dist/math/fees.js +135 -0
- package/dist/math/fees.js.map +1 -0
- package/dist/math/index.d.ts +8 -0
- package/dist/math/index.d.ts.map +1 -0
- package/dist/math/index.js +6 -0
- package/dist/math/index.js.map +1 -0
- package/dist/math/tiered-fees.d.ts +80 -0
- package/dist/math/tiered-fees.d.ts.map +1 -0
- package/dist/math/tiered-fees.js +129 -0
- package/dist/math/tiered-fees.js.map +1 -0
- package/dist/oracle.d.ts +53 -0
- package/dist/oracle.d.ts.map +1 -0
- package/dist/oracle.js +70 -0
- package/dist/oracle.js.map +1 -0
- package/dist/pda/index.d.ts +89 -0
- package/dist/pda/index.d.ts.map +1 -0
- package/dist/pda/index.js +127 -0
- package/dist/pda/index.js.map +1 -0
- package/dist/pda/liquid-fees.d.ts +27 -0
- package/dist/pda/liquid-fees.d.ts.map +1 -0
- package/dist/pda/liquid-fees.js +36 -0
- package/dist/pda/liquid-fees.js.map +1 -0
- package/dist/pda/liquid-state.d.ts +56 -0
- package/dist/pda/liquid-state.d.ts.map +1 -0
- package/dist/pda/liquid-state.js +79 -0
- package/dist/pda/liquid-state.js.map +1 -0
- package/dist/pda/liquid-swap.d.ts +76 -0
- package/dist/pda/liquid-swap.d.ts.map +1 -0
- package/dist/pda/liquid-swap.js +103 -0
- package/dist/pda/liquid-swap.js.map +1 -0
- package/dist/pda/liquid.d.ts +67 -0
- package/dist/pda/liquid.d.ts.map +1 -0
- package/dist/pda/liquid.js +91 -0
- package/dist/pda/liquid.js.map +1 -0
- package/dist/provider.d.ts +26 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +47 -0
- package/dist/provider.js.map +1 -0
- package/dist/transaction/builder.d.ts +30 -0
- package/dist/transaction/builder.d.ts.map +1 -0
- package/dist/transaction/builder.js +48 -0
- package/dist/transaction/builder.js.map +1 -0
- package/dist/transaction/index.d.ts +3 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/index.js +3 -0
- package/dist/transaction/index.js.map +1 -0
- package/dist/transaction/send.d.ts +25 -0
- package/dist/transaction/send.d.ts.map +1 -0
- package/dist/transaction/send.js +52 -0
- package/dist/transaction/send.js.map +1 -0
- package/dist/types.d.ts +311 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +46 -0
- package/dist/types.js.map +1 -0
- package/package.json +112 -0
- package/src/accounts/index.ts +26 -0
- package/src/accounts/liquid-fees.ts +38 -0
- package/src/accounts/liquid-state.ts +134 -0
- package/src/accounts/liquid-swap.ts +79 -0
- package/src/accounts/liquid.ts +100 -0
- package/src/client.ts +1001 -0
- package/src/config.ts +91 -0
- package/src/errors.ts +94 -0
- package/src/events/index.ts +42 -0
- package/src/events/parser.ts +90 -0
- package/src/events/types.ts +310 -0
- package/src/helpers/index.ts +23 -0
- package/src/helpers/preview.ts +798 -0
- package/src/helpers/user.ts +24 -0
- package/src/idl/index.ts +94 -0
- package/src/idl/liquid.json +10516 -0
- package/src/idl/liquid.ts +10522 -0
- package/src/idl/liquid_fees.json +1513 -0
- package/src/idl/liquid_fees.ts +1519 -0
- package/src/idl/liquid_state.json +2929 -0
- package/src/idl/liquid_state.ts +2935 -0
- package/src/idl/liquid_swap.json +5842 -0
- package/src/idl/liquid_swap.ts +5848 -0
- package/src/index.ts +98 -0
- package/src/instructions/index.ts +109 -0
- package/src/instructions/liquid-fees.ts +289 -0
- package/src/instructions/liquid-state.ts +336 -0
- package/src/instructions/liquid-swap.ts +414 -0
- package/src/instructions/liquid.ts +884 -0
- package/src/instructions/program-cache.ts +106 -0
- package/src/math/amm.ts +146 -0
- package/src/math/bonding-curve.ts +122 -0
- package/src/math/constants.ts +19 -0
- package/src/math/fees.ts +191 -0
- package/src/math/index.ts +40 -0
- package/src/math/tiered-fees.ts +165 -0
- package/src/oracle.ts +97 -0
- package/src/pda/index.ts +331 -0
- package/src/pda/liquid-fees.ts +58 -0
- package/src/pda/liquid-state.ts +123 -0
- package/src/pda/liquid-swap.ts +162 -0
- package/src/pda/liquid.ts +152 -0
- package/src/provider.ts +60 -0
- package/src/transaction/builder.ts +80 -0
- package/src/transaction/index.ts +6 -0
- package/src/transaction/send.ts +72 -0
- package/src/types.ts +354 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import type { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import {
|
|
3
|
+
getAssociatedTokenAddressSync,
|
|
4
|
+
TOKEN_PROGRAM_ID,
|
|
5
|
+
} from "@solana/spl-token";
|
|
6
|
+
import type BN from "bn.js";
|
|
7
|
+
import type { LiquidConfig } from "../config.js";
|
|
8
|
+
import { getCachedSwapProgram } from "./program-cache.js";
|
|
9
|
+
|
|
10
|
+
export interface BuildCreatePoolParams {
|
|
11
|
+
signer: PublicKey;
|
|
12
|
+
payer?: PublicKey;
|
|
13
|
+
baseMint: PublicKey;
|
|
14
|
+
quoteMint: PublicKey;
|
|
15
|
+
baseTokenProgram: PublicKey;
|
|
16
|
+
quoteTokenProgram: PublicKey;
|
|
17
|
+
initAmountBase: BN;
|
|
18
|
+
initAmountQuote: BN;
|
|
19
|
+
config: LiquidConfig;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Builds a create pool instruction.
|
|
24
|
+
*
|
|
25
|
+
* @param params - {@link BuildCreatePoolParams}
|
|
26
|
+
* @returns Transaction instruction
|
|
27
|
+
*/
|
|
28
|
+
export function buildCreatePool(
|
|
29
|
+
params: BuildCreatePoolParams
|
|
30
|
+
): Promise<TransactionInstruction> {
|
|
31
|
+
const {
|
|
32
|
+
signer,
|
|
33
|
+
payer,
|
|
34
|
+
baseMint,
|
|
35
|
+
quoteMint,
|
|
36
|
+
baseTokenProgram,
|
|
37
|
+
quoteTokenProgram,
|
|
38
|
+
initAmountBase,
|
|
39
|
+
initAmountQuote,
|
|
40
|
+
config,
|
|
41
|
+
} = params;
|
|
42
|
+
|
|
43
|
+
const program = getCachedSwapProgram(config);
|
|
44
|
+
|
|
45
|
+
const creatorBase = getAssociatedTokenAddressSync(
|
|
46
|
+
baseMint,
|
|
47
|
+
signer,
|
|
48
|
+
false,
|
|
49
|
+
baseTokenProgram
|
|
50
|
+
);
|
|
51
|
+
const creatorQuote = getAssociatedTokenAddressSync(
|
|
52
|
+
quoteMint,
|
|
53
|
+
signer,
|
|
54
|
+
false,
|
|
55
|
+
quoteTokenProgram
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return program.methods
|
|
59
|
+
.create(initAmountBase, initAmountQuote, null)
|
|
60
|
+
.accounts({
|
|
61
|
+
signer,
|
|
62
|
+
payer: payer ?? signer,
|
|
63
|
+
baseMint,
|
|
64
|
+
quoteMint,
|
|
65
|
+
creatorBase,
|
|
66
|
+
creatorQuote,
|
|
67
|
+
baseTokenProgram,
|
|
68
|
+
quoteTokenProgram,
|
|
69
|
+
})
|
|
70
|
+
.instruction();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface BuildSwapBuyParams {
|
|
74
|
+
payer: PublicKey;
|
|
75
|
+
creator: PublicKey;
|
|
76
|
+
baseMint: PublicKey;
|
|
77
|
+
quoteMint: PublicKey;
|
|
78
|
+
baseTokenProgram: PublicKey;
|
|
79
|
+
quoteTokenProgram: PublicKey;
|
|
80
|
+
maxAmountIn: BN;
|
|
81
|
+
amountOut: BN;
|
|
82
|
+
feeRecipient: PublicKey;
|
|
83
|
+
oraclePriceFeed?: PublicKey;
|
|
84
|
+
config: LiquidConfig;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Builds a buy swap instruction (quote -> base).
|
|
89
|
+
*
|
|
90
|
+
* @param params - {@link BuildSwapBuyParams}
|
|
91
|
+
* @returns Transaction instruction
|
|
92
|
+
*/
|
|
93
|
+
export function buildSwapBuy(
|
|
94
|
+
params: BuildSwapBuyParams
|
|
95
|
+
): Promise<TransactionInstruction> {
|
|
96
|
+
const {
|
|
97
|
+
payer,
|
|
98
|
+
creator,
|
|
99
|
+
baseMint,
|
|
100
|
+
quoteMint,
|
|
101
|
+
baseTokenProgram,
|
|
102
|
+
quoteTokenProgram,
|
|
103
|
+
maxAmountIn,
|
|
104
|
+
amountOut,
|
|
105
|
+
feeRecipient,
|
|
106
|
+
oraclePriceFeed,
|
|
107
|
+
config,
|
|
108
|
+
} = params;
|
|
109
|
+
|
|
110
|
+
const program = getCachedSwapProgram(config);
|
|
111
|
+
|
|
112
|
+
const baseTokenAccount = getAssociatedTokenAddressSync(
|
|
113
|
+
baseMint,
|
|
114
|
+
payer,
|
|
115
|
+
false,
|
|
116
|
+
baseTokenProgram
|
|
117
|
+
);
|
|
118
|
+
const quoteTokenAccount = getAssociatedTokenAddressSync(
|
|
119
|
+
quoteMint,
|
|
120
|
+
payer,
|
|
121
|
+
false,
|
|
122
|
+
quoteTokenProgram
|
|
123
|
+
);
|
|
124
|
+
return program.methods
|
|
125
|
+
.buy(maxAmountIn, amountOut)
|
|
126
|
+
.accountsPartial({
|
|
127
|
+
payer,
|
|
128
|
+
creator,
|
|
129
|
+
baseTokenAccount,
|
|
130
|
+
quoteTokenAccount,
|
|
131
|
+
baseTokenProgram,
|
|
132
|
+
quoteTokenProgram,
|
|
133
|
+
baseMint,
|
|
134
|
+
quoteMint,
|
|
135
|
+
feeRecipient,
|
|
136
|
+
liquidState: {
|
|
137
|
+
user: payer,
|
|
138
|
+
tokenMint: baseMint,
|
|
139
|
+
},
|
|
140
|
+
...(oraclePriceFeed ? { oraclePriceFeed } : {}),
|
|
141
|
+
})
|
|
142
|
+
.instruction();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface BuildSwapSellParams {
|
|
146
|
+
payer: PublicKey;
|
|
147
|
+
creator: PublicKey;
|
|
148
|
+
baseMint: PublicKey;
|
|
149
|
+
quoteMint: PublicKey;
|
|
150
|
+
baseTokenProgram: PublicKey;
|
|
151
|
+
quoteTokenProgram: PublicKey;
|
|
152
|
+
amountIn: BN;
|
|
153
|
+
minimumAmountOut: BN;
|
|
154
|
+
feeRecipient: PublicKey;
|
|
155
|
+
oraclePriceFeed?: PublicKey;
|
|
156
|
+
config: LiquidConfig;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Builds a sell swap instruction (base -> quote).
|
|
161
|
+
*
|
|
162
|
+
* @param params - {@link BuildSwapSellParams}
|
|
163
|
+
* @returns Transaction instruction
|
|
164
|
+
*/
|
|
165
|
+
export function buildSwapSell(
|
|
166
|
+
params: BuildSwapSellParams
|
|
167
|
+
): Promise<TransactionInstruction> {
|
|
168
|
+
const {
|
|
169
|
+
payer,
|
|
170
|
+
creator,
|
|
171
|
+
baseMint,
|
|
172
|
+
quoteMint,
|
|
173
|
+
baseTokenProgram,
|
|
174
|
+
quoteTokenProgram,
|
|
175
|
+
amountIn,
|
|
176
|
+
minimumAmountOut,
|
|
177
|
+
feeRecipient,
|
|
178
|
+
oraclePriceFeed,
|
|
179
|
+
config,
|
|
180
|
+
} = params;
|
|
181
|
+
|
|
182
|
+
const program = getCachedSwapProgram(config);
|
|
183
|
+
|
|
184
|
+
const baseTokenAccount = getAssociatedTokenAddressSync(
|
|
185
|
+
baseMint,
|
|
186
|
+
payer,
|
|
187
|
+
false,
|
|
188
|
+
baseTokenProgram
|
|
189
|
+
);
|
|
190
|
+
const quoteTokenAccount = getAssociatedTokenAddressSync(
|
|
191
|
+
quoteMint,
|
|
192
|
+
payer,
|
|
193
|
+
false,
|
|
194
|
+
quoteTokenProgram
|
|
195
|
+
);
|
|
196
|
+
return program.methods
|
|
197
|
+
.sell(amountIn, minimumAmountOut)
|
|
198
|
+
.accountsPartial({
|
|
199
|
+
payer,
|
|
200
|
+
creator,
|
|
201
|
+
baseTokenAccount,
|
|
202
|
+
quoteTokenAccount,
|
|
203
|
+
baseTokenProgram,
|
|
204
|
+
quoteTokenProgram,
|
|
205
|
+
baseMint,
|
|
206
|
+
quoteMint,
|
|
207
|
+
feeRecipient,
|
|
208
|
+
liquidState: {
|
|
209
|
+
user: payer,
|
|
210
|
+
tokenMint: baseMint,
|
|
211
|
+
},
|
|
212
|
+
...(oraclePriceFeed ? { oraclePriceFeed } : {}),
|
|
213
|
+
})
|
|
214
|
+
.instruction();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export interface BuildDepositParams {
|
|
218
|
+
owner: PublicKey;
|
|
219
|
+
poolAddress: PublicKey;
|
|
220
|
+
baseMint: PublicKey;
|
|
221
|
+
quoteMint: PublicKey;
|
|
222
|
+
baseTokenProgram: PublicKey;
|
|
223
|
+
quoteTokenProgram: PublicKey;
|
|
224
|
+
baseVault: PublicKey;
|
|
225
|
+
quoteVault: PublicKey;
|
|
226
|
+
lpMint: PublicKey;
|
|
227
|
+
lpTokenAmount: BN;
|
|
228
|
+
maximumBaseAmount: BN;
|
|
229
|
+
maximumQuoteAmount: BN;
|
|
230
|
+
config: LiquidConfig;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Builds a deposit (add liquidity) instruction.
|
|
235
|
+
*
|
|
236
|
+
* @param params - {@link BuildDepositParams}
|
|
237
|
+
* @returns Transaction instruction
|
|
238
|
+
*/
|
|
239
|
+
export function buildDeposit(
|
|
240
|
+
params: BuildDepositParams
|
|
241
|
+
): Promise<TransactionInstruction> {
|
|
242
|
+
const {
|
|
243
|
+
owner,
|
|
244
|
+
poolAddress,
|
|
245
|
+
baseMint,
|
|
246
|
+
quoteMint,
|
|
247
|
+
baseTokenProgram,
|
|
248
|
+
quoteTokenProgram,
|
|
249
|
+
baseVault,
|
|
250
|
+
quoteVault,
|
|
251
|
+
lpMint,
|
|
252
|
+
lpTokenAmount,
|
|
253
|
+
maximumBaseAmount,
|
|
254
|
+
maximumQuoteAmount,
|
|
255
|
+
config,
|
|
256
|
+
} = params;
|
|
257
|
+
|
|
258
|
+
const program = getCachedSwapProgram(config);
|
|
259
|
+
|
|
260
|
+
const ownerLpToken = getAssociatedTokenAddressSync(
|
|
261
|
+
lpMint,
|
|
262
|
+
owner,
|
|
263
|
+
false,
|
|
264
|
+
TOKEN_PROGRAM_ID
|
|
265
|
+
);
|
|
266
|
+
const baseAccount = getAssociatedTokenAddressSync(
|
|
267
|
+
baseMint,
|
|
268
|
+
owner,
|
|
269
|
+
false,
|
|
270
|
+
baseTokenProgram
|
|
271
|
+
);
|
|
272
|
+
const quoteAccount = getAssociatedTokenAddressSync(
|
|
273
|
+
quoteMint,
|
|
274
|
+
owner,
|
|
275
|
+
false,
|
|
276
|
+
quoteTokenProgram
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
return program.methods
|
|
280
|
+
.deposit(lpTokenAmount, maximumBaseAmount, maximumQuoteAmount)
|
|
281
|
+
.accounts({
|
|
282
|
+
owner,
|
|
283
|
+
poolState: poolAddress,
|
|
284
|
+
ownerLpToken,
|
|
285
|
+
baseAccount,
|
|
286
|
+
quoteAccount,
|
|
287
|
+
baseMint,
|
|
288
|
+
quoteMint,
|
|
289
|
+
baseVault,
|
|
290
|
+
quoteVault,
|
|
291
|
+
lpMint,
|
|
292
|
+
})
|
|
293
|
+
.instruction();
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface BuildWithdrawParams {
|
|
297
|
+
owner: PublicKey;
|
|
298
|
+
poolAddress: PublicKey;
|
|
299
|
+
baseMint: PublicKey;
|
|
300
|
+
quoteMint: PublicKey;
|
|
301
|
+
baseTokenProgram: PublicKey;
|
|
302
|
+
quoteTokenProgram: PublicKey;
|
|
303
|
+
baseVault: PublicKey;
|
|
304
|
+
quoteVault: PublicKey;
|
|
305
|
+
lpMint: PublicKey;
|
|
306
|
+
lpTokenAmount: BN;
|
|
307
|
+
minimumBaseAmount: BN;
|
|
308
|
+
minimumQuoteAmount: BN;
|
|
309
|
+
config: LiquidConfig;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Builds a withdraw (remove liquidity) instruction.
|
|
314
|
+
*
|
|
315
|
+
* @param params - {@link BuildWithdrawParams}
|
|
316
|
+
* @returns Transaction instruction
|
|
317
|
+
*/
|
|
318
|
+
export function buildWithdraw(
|
|
319
|
+
params: BuildWithdrawParams
|
|
320
|
+
): Promise<TransactionInstruction> {
|
|
321
|
+
const {
|
|
322
|
+
owner,
|
|
323
|
+
poolAddress,
|
|
324
|
+
baseMint,
|
|
325
|
+
quoteMint,
|
|
326
|
+
baseTokenProgram,
|
|
327
|
+
quoteTokenProgram,
|
|
328
|
+
baseVault,
|
|
329
|
+
quoteVault,
|
|
330
|
+
lpMint,
|
|
331
|
+
lpTokenAmount,
|
|
332
|
+
minimumBaseAmount,
|
|
333
|
+
minimumQuoteAmount,
|
|
334
|
+
config,
|
|
335
|
+
} = params;
|
|
336
|
+
|
|
337
|
+
const program = getCachedSwapProgram(config);
|
|
338
|
+
|
|
339
|
+
const ownerLpToken = getAssociatedTokenAddressSync(
|
|
340
|
+
lpMint,
|
|
341
|
+
owner,
|
|
342
|
+
false,
|
|
343
|
+
TOKEN_PROGRAM_ID
|
|
344
|
+
);
|
|
345
|
+
const baseAccount = getAssociatedTokenAddressSync(
|
|
346
|
+
baseMint,
|
|
347
|
+
owner,
|
|
348
|
+
false,
|
|
349
|
+
baseTokenProgram
|
|
350
|
+
);
|
|
351
|
+
const quoteAccount = getAssociatedTokenAddressSync(
|
|
352
|
+
quoteMint,
|
|
353
|
+
owner,
|
|
354
|
+
false,
|
|
355
|
+
quoteTokenProgram
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
return program.methods
|
|
359
|
+
.withdraw(lpTokenAmount, minimumBaseAmount, minimumQuoteAmount)
|
|
360
|
+
.accounts({
|
|
361
|
+
owner,
|
|
362
|
+
poolState: poolAddress,
|
|
363
|
+
ownerLpToken,
|
|
364
|
+
baseAccount,
|
|
365
|
+
quoteAccount,
|
|
366
|
+
baseMint,
|
|
367
|
+
quoteMint,
|
|
368
|
+
baseVault,
|
|
369
|
+
quoteVault,
|
|
370
|
+
lpMint,
|
|
371
|
+
})
|
|
372
|
+
.instruction();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export interface BuildSwapExecuteBuybackParams {
|
|
376
|
+
payer: PublicKey;
|
|
377
|
+
baseMint: PublicKey;
|
|
378
|
+
quoteMint: PublicKey;
|
|
379
|
+
baseTokenProgram: PublicKey;
|
|
380
|
+
quoteTokenProgram: PublicKey;
|
|
381
|
+
config: LiquidConfig;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Builds an executeBuyback instruction for an AMM pool.
|
|
386
|
+
* Permissionless. Only works when fee config is Revoked.
|
|
387
|
+
*
|
|
388
|
+
* @param params - {@link BuildSwapExecuteBuybackParams}
|
|
389
|
+
* @returns Transaction instruction
|
|
390
|
+
*/
|
|
391
|
+
export function buildSwapExecuteBuyback(
|
|
392
|
+
params: BuildSwapExecuteBuybackParams
|
|
393
|
+
): Promise<TransactionInstruction> {
|
|
394
|
+
const {
|
|
395
|
+
payer,
|
|
396
|
+
baseMint,
|
|
397
|
+
quoteMint,
|
|
398
|
+
baseTokenProgram,
|
|
399
|
+
quoteTokenProgram,
|
|
400
|
+
config,
|
|
401
|
+
} = params;
|
|
402
|
+
const program = getCachedSwapProgram(config);
|
|
403
|
+
|
|
404
|
+
return program.methods
|
|
405
|
+
.executeBuyback()
|
|
406
|
+
.accounts({
|
|
407
|
+
payer,
|
|
408
|
+
baseMint,
|
|
409
|
+
quoteMint,
|
|
410
|
+
baseTokenProgram,
|
|
411
|
+
quoteTokenProgram,
|
|
412
|
+
})
|
|
413
|
+
.instruction();
|
|
414
|
+
}
|