@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,483 @@
|
|
|
1
|
+
import { getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID, } from "@solana/spl-token";
|
|
2
|
+
import { WSOL_MINT } from "../config.js";
|
|
3
|
+
import { getBondingCurvePDA, getBondingCurveTokenAccount, getStableBondingCurvePDA, } from "../pda/liquid.js";
|
|
4
|
+
import { getUserPropertiesPDA, getTokenVolumePDA } from "../pda/liquid-state.js";
|
|
5
|
+
import { getPoolPDA, getPoolLpMintPDA, getPoolVaultPDA, getObservationPDA, getSwapGlobalConfigPDA, getSwapAuthorityPDA, getSwapBuybackVaultPDA, } from "../pda/liquid-swap.js";
|
|
6
|
+
import { getCachedLiquidProgram } from "./program-cache.js";
|
|
7
|
+
import { fetchNativeBondingCurve, fetchStableBondingCurve, } from "../accounts/liquid.js";
|
|
8
|
+
/**
|
|
9
|
+
* Builds a createNativeCurve instruction.
|
|
10
|
+
* The mint Keypair must be passed as a signer when sending the transaction.
|
|
11
|
+
* Atomically initializes the fee configuration via CPI to liquid-fees
|
|
12
|
+
* with the creator as the sole recipient (100%). Use `buildUpdateFeeConfig`
|
|
13
|
+
* to set custom recipients afterward.
|
|
14
|
+
*
|
|
15
|
+
* @param params - {@link BuildCreateNativeCurveParams}
|
|
16
|
+
* @returns Transaction instruction
|
|
17
|
+
*/
|
|
18
|
+
export function buildCreateNativeCurve(params) {
|
|
19
|
+
const { creator, mint, pythPriceFeed, name, symbol, uri, config } = params;
|
|
20
|
+
const program = getCachedLiquidProgram(config);
|
|
21
|
+
const bondingCurveTokenAccount = getBondingCurveTokenAccount(mint, config.liquidProgramId);
|
|
22
|
+
return program.methods
|
|
23
|
+
.createNativeCurve({
|
|
24
|
+
name,
|
|
25
|
+
symbol,
|
|
26
|
+
uri,
|
|
27
|
+
})
|
|
28
|
+
.accounts({
|
|
29
|
+
creator,
|
|
30
|
+
mint,
|
|
31
|
+
pythPriceFeed,
|
|
32
|
+
bondingCurveTokenAccount,
|
|
33
|
+
})
|
|
34
|
+
.instruction();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Builds a bumpNative instruction.
|
|
38
|
+
* Re-evaluates a native bonding curve's market cap against the current oracle price
|
|
39
|
+
* and marks it as complete if the threshold is exceeded. Permissionless.
|
|
40
|
+
*
|
|
41
|
+
* @param params - {@link BuildBumpNativeParams}
|
|
42
|
+
* @returns Transaction instruction
|
|
43
|
+
*/
|
|
44
|
+
export function buildBumpNative(params) {
|
|
45
|
+
const { mint, pythPriceFeed, config } = params;
|
|
46
|
+
const program = getCachedLiquidProgram(config);
|
|
47
|
+
return program.methods
|
|
48
|
+
.bumpNative()
|
|
49
|
+
.accounts({
|
|
50
|
+
mint,
|
|
51
|
+
pythPriceFeed,
|
|
52
|
+
})
|
|
53
|
+
.instruction();
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Builds a buyNative instruction.
|
|
57
|
+
* Requires the bonding curve creator and Pyth price feed to be known.
|
|
58
|
+
*
|
|
59
|
+
* @param params - {@link BuildBuyNativeParams}
|
|
60
|
+
* @returns Transaction instruction
|
|
61
|
+
*/
|
|
62
|
+
export function buildBuyNative(params) {
|
|
63
|
+
const { user, mint, creator, pythPriceFeed, amountIn, minAmountOut, feeRecipient, creatorReferralVault, traderReferralVault, config, } = params;
|
|
64
|
+
const program = getCachedLiquidProgram(config);
|
|
65
|
+
// Derive creator-related accounts that Anchor can't auto-resolve
|
|
66
|
+
const [creatorUserProperties] = getUserPropertiesPDA(creator, config.liquidStateProgramId);
|
|
67
|
+
return program.methods
|
|
68
|
+
.buyNative(amountIn, minAmountOut)
|
|
69
|
+
.accountsPartial({
|
|
70
|
+
user,
|
|
71
|
+
feeRecipient,
|
|
72
|
+
mint,
|
|
73
|
+
pythPriceFeed,
|
|
74
|
+
creatorUserProperties,
|
|
75
|
+
creatorReferralVault: creatorReferralVault ?? null,
|
|
76
|
+
traderReferralVault: traderReferralVault ?? null,
|
|
77
|
+
liquidState: {
|
|
78
|
+
user,
|
|
79
|
+
tokenMint: mint,
|
|
80
|
+
},
|
|
81
|
+
})
|
|
82
|
+
.instruction();
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Builds a buyNative instruction, automatically fetching the bonding curve
|
|
86
|
+
* creator from chain. Convenience wrapper around `buildBuyNative`.
|
|
87
|
+
*
|
|
88
|
+
* @param connection - Solana RPC connection
|
|
89
|
+
* @param params - {@link BuildBuyNativeParams} without `creator`
|
|
90
|
+
* @returns Transaction instruction
|
|
91
|
+
*/
|
|
92
|
+
export async function buildBuyNativeAutoResolve(connection, params) {
|
|
93
|
+
const curve = await fetchNativeBondingCurve(connection, params.mint, params.config);
|
|
94
|
+
return buildBuyNative({
|
|
95
|
+
...params,
|
|
96
|
+
creator: curve.creator,
|
|
97
|
+
pythPriceFeed: params.pythPriceFeed,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Builds a sellNative instruction.
|
|
102
|
+
* Requires the bonding curve creator and Pyth price feed to be known.
|
|
103
|
+
*
|
|
104
|
+
* @param params - {@link BuildSellNativeParams}
|
|
105
|
+
* @returns Transaction instruction
|
|
106
|
+
*/
|
|
107
|
+
export function buildSellNative(params) {
|
|
108
|
+
const { user, mint, creator, pythPriceFeed, amountIn, minAmountOut, feeRecipient, creatorReferralVault, traderReferralVault, config, } = params;
|
|
109
|
+
const program = getCachedLiquidProgram(config);
|
|
110
|
+
// Derive creator-related accounts that Anchor can't auto-resolve
|
|
111
|
+
const [creatorUserProperties] = getUserPropertiesPDA(creator, config.liquidStateProgramId);
|
|
112
|
+
return program.methods
|
|
113
|
+
.sellNative(amountIn, minAmountOut)
|
|
114
|
+
.accountsPartial({
|
|
115
|
+
user,
|
|
116
|
+
feeRecipient,
|
|
117
|
+
mint,
|
|
118
|
+
pythPriceFeed,
|
|
119
|
+
creatorUserProperties,
|
|
120
|
+
creatorReferralVault: creatorReferralVault ?? null,
|
|
121
|
+
traderReferralVault: traderReferralVault ?? null,
|
|
122
|
+
liquidState: {
|
|
123
|
+
user,
|
|
124
|
+
tokenMint: mint,
|
|
125
|
+
},
|
|
126
|
+
})
|
|
127
|
+
.instruction();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Builds a sellNative instruction, automatically fetching the bonding curve
|
|
131
|
+
* creator from chain. Convenience wrapper around `buildSellNative`.
|
|
132
|
+
*
|
|
133
|
+
* @param connection - Solana RPC connection
|
|
134
|
+
* @param params - {@link BuildSellNativeParams} without `creator`
|
|
135
|
+
* @returns Transaction instruction
|
|
136
|
+
*/
|
|
137
|
+
export async function buildSellNativeAutoResolve(connection, params) {
|
|
138
|
+
const curve = await fetchNativeBondingCurve(connection, params.mint, params.config);
|
|
139
|
+
return buildSellNative({
|
|
140
|
+
...params,
|
|
141
|
+
creator: curve.creator,
|
|
142
|
+
pythPriceFeed: params.pythPriceFeed,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Builds a migrate instruction (bonding curve -> AMM pool).
|
|
147
|
+
* Permissionless — anyone can trigger migration once the curve is complete.
|
|
148
|
+
*
|
|
149
|
+
* @param params - {@link BuildMigrateNativeParams}
|
|
150
|
+
* @returns Transaction instruction
|
|
151
|
+
*/
|
|
152
|
+
export function buildMigrateNative(params) {
|
|
153
|
+
const { migrator, mint, config } = params;
|
|
154
|
+
const program = getCachedLiquidProgram(config);
|
|
155
|
+
// Derive AMM PDAs
|
|
156
|
+
const [bondingCurve] = getBondingCurvePDA(mint, config.liquidProgramId);
|
|
157
|
+
const [ammPoolState] = getPoolPDA(mint, WSOL_MINT, config.liquidSwapProgramId);
|
|
158
|
+
const [ammLpMint] = getPoolLpMintPDA(ammPoolState, config.liquidSwapProgramId);
|
|
159
|
+
const [ammBaseVault] = getPoolVaultPDA(ammPoolState, mint, config.liquidSwapProgramId);
|
|
160
|
+
const [ammQuoteVault] = getPoolVaultPDA(ammPoolState, WSOL_MINT, config.liquidSwapProgramId);
|
|
161
|
+
const [ammObservationState] = getObservationPDA(ammPoolState, config.liquidSwapProgramId);
|
|
162
|
+
const [ammGlobalConfig] = getSwapGlobalConfigPDA(config.liquidSwapProgramId);
|
|
163
|
+
const [ammAuthority] = getSwapAuthorityPDA(config.liquidSwapProgramId);
|
|
164
|
+
const [tokenVolume] = getTokenVolumePDA(mint, config.liquidStateProgramId);
|
|
165
|
+
const bondingCurveLpToken = getAssociatedTokenAddressSync(ammLpMint, bondingCurve, true, TOKEN_PROGRAM_ID);
|
|
166
|
+
const [ammBuybackVault] = getSwapBuybackVaultPDA(ammPoolState, WSOL_MINT, config.liquidSwapProgramId);
|
|
167
|
+
return program.methods
|
|
168
|
+
.migrate()
|
|
169
|
+
.accounts({
|
|
170
|
+
signer: migrator,
|
|
171
|
+
mint,
|
|
172
|
+
ammPoolState,
|
|
173
|
+
ammLpMint,
|
|
174
|
+
ammBaseVault,
|
|
175
|
+
ammQuoteVault,
|
|
176
|
+
ammObservationState,
|
|
177
|
+
ammGlobalConfig,
|
|
178
|
+
ammAuthority,
|
|
179
|
+
bondingCurveLpToken,
|
|
180
|
+
tokenVolume,
|
|
181
|
+
ammBuybackVault,
|
|
182
|
+
})
|
|
183
|
+
.instruction();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Builds an initializeNativeReferralVault instruction (creates native SOL referral vault).
|
|
187
|
+
*
|
|
188
|
+
* @param params - {@link BuildInitializeNativeReferralVaultParams}
|
|
189
|
+
* @returns Transaction instruction
|
|
190
|
+
*/
|
|
191
|
+
export function buildInitializeNativeReferralVault(params) {
|
|
192
|
+
const { user, config } = params;
|
|
193
|
+
const program = getCachedLiquidProgram(config);
|
|
194
|
+
return program.methods
|
|
195
|
+
.initializeNativeReferralVault()
|
|
196
|
+
.accounts({ user })
|
|
197
|
+
.instruction();
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Builds a withdrawReferralRewards instruction.
|
|
201
|
+
*
|
|
202
|
+
* @param params - {@link BuildWithdrawReferralRewardsParams}
|
|
203
|
+
* @returns Transaction instruction
|
|
204
|
+
*/
|
|
205
|
+
export function buildWithdrawReferralRewards(params) {
|
|
206
|
+
const { user, config } = params;
|
|
207
|
+
const program = getCachedLiquidProgram(config);
|
|
208
|
+
return program.methods
|
|
209
|
+
.withdrawReferralRewards()
|
|
210
|
+
.accounts({ user })
|
|
211
|
+
.instruction();
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Builds an executeBuybackNative instruction for a native SOL bonding curve.
|
|
215
|
+
* Permissionless — anyone can trigger. Only works when fee config is Revoked.
|
|
216
|
+
*
|
|
217
|
+
* @param params - {@link BuildExecuteBuybackNativeParams}
|
|
218
|
+
* @returns Transaction instruction
|
|
219
|
+
*/
|
|
220
|
+
export function buildExecuteBuybackNative(params) {
|
|
221
|
+
const { payer, mint, pythPriceFeed, config } = params;
|
|
222
|
+
const program = getCachedLiquidProgram(config);
|
|
223
|
+
return program.methods
|
|
224
|
+
.executeBuybackNative()
|
|
225
|
+
.accountsPartial({
|
|
226
|
+
payer,
|
|
227
|
+
mint,
|
|
228
|
+
pythPriceFeed,
|
|
229
|
+
})
|
|
230
|
+
.instruction();
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Builds an executeBuybackToken instruction for a token-based bonding curve.
|
|
234
|
+
* Permissionless — anyone can trigger. Only works when fee config is Revoked.
|
|
235
|
+
*
|
|
236
|
+
* @param params - {@link BuildExecuteBuybackTokenParams}
|
|
237
|
+
* @returns Transaction instruction
|
|
238
|
+
*/
|
|
239
|
+
export function buildExecuteBuybackToken(params) {
|
|
240
|
+
const { payer, mint, quoteMint, config } = params;
|
|
241
|
+
const program = getCachedLiquidProgram(config);
|
|
242
|
+
return program.methods
|
|
243
|
+
.executeBuybackToken()
|
|
244
|
+
.accountsPartial({
|
|
245
|
+
payer,
|
|
246
|
+
mint,
|
|
247
|
+
quoteMint,
|
|
248
|
+
})
|
|
249
|
+
.instruction();
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Builds a createStableCurve instruction.
|
|
253
|
+
* Creates a token-based bonding curve (e.g., using USDC as quote).
|
|
254
|
+
* The mint Keypair must be passed as a signer when sending the transaction.
|
|
255
|
+
* Atomically initializes the fee configuration via CPI to liquid-fees
|
|
256
|
+
* with the creator as the sole recipient (100%). Use `buildUpdateFeeConfig`
|
|
257
|
+
* to set custom recipients afterward.
|
|
258
|
+
*
|
|
259
|
+
* @param params - {@link BuildCreateStableCurveParams}
|
|
260
|
+
* @returns Transaction instruction
|
|
261
|
+
*/
|
|
262
|
+
export function buildCreateStableCurve(params) {
|
|
263
|
+
const { creator, mint, quoteMint, name, symbol, uri, config } = params;
|
|
264
|
+
const program = getCachedLiquidProgram(config);
|
|
265
|
+
return program.methods
|
|
266
|
+
.createStableCurve({
|
|
267
|
+
name,
|
|
268
|
+
symbol,
|
|
269
|
+
uri,
|
|
270
|
+
})
|
|
271
|
+
.accounts({
|
|
272
|
+
creator,
|
|
273
|
+
mint,
|
|
274
|
+
quoteMint,
|
|
275
|
+
})
|
|
276
|
+
.instruction();
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Builds a buyStable instruction.
|
|
280
|
+
* Buys tokens from a token-based bonding curve using quote tokens (e.g., USDC).
|
|
281
|
+
*
|
|
282
|
+
* @param params - {@link BuildBuyStableParams}
|
|
283
|
+
* @returns Transaction instruction
|
|
284
|
+
*/
|
|
285
|
+
export function buildBuyStable(params) {
|
|
286
|
+
const { user, mint, quoteMint, creator, amountIn, minAmountOut, feeRecipient, creatorReferralVault, traderReferralVault, config, } = params;
|
|
287
|
+
const program = getCachedLiquidProgram(config);
|
|
288
|
+
// Fee recipient quote token account
|
|
289
|
+
const feeRecipientQuoteAccount = getAssociatedTokenAddressSync(quoteMint, feeRecipient, true, TOKEN_PROGRAM_ID);
|
|
290
|
+
// Derive creator-related accounts that Anchor can't auto-resolve
|
|
291
|
+
const [creatorUserProperties] = getUserPropertiesPDA(creator, config.liquidStateProgramId);
|
|
292
|
+
return program.methods
|
|
293
|
+
.buyStable(amountIn, minAmountOut)
|
|
294
|
+
.accountsPartial({
|
|
295
|
+
user,
|
|
296
|
+
mint,
|
|
297
|
+
quoteMint,
|
|
298
|
+
feeRecipient: feeRecipientQuoteAccount,
|
|
299
|
+
creatorUserProperties,
|
|
300
|
+
creatorReferralVault: creatorReferralVault ?? null,
|
|
301
|
+
traderReferralVault: traderReferralVault ?? null,
|
|
302
|
+
liquidState: {
|
|
303
|
+
user,
|
|
304
|
+
tokenMint: mint,
|
|
305
|
+
},
|
|
306
|
+
})
|
|
307
|
+
.instruction();
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Builds a buyStable instruction, automatically fetching the bonding curve
|
|
311
|
+
* creator from chain. Convenience wrapper around `buildBuyStable`.
|
|
312
|
+
*
|
|
313
|
+
* @param connection - Solana RPC connection
|
|
314
|
+
* @param params - {@link BuildBuyStableParams} without `creator`
|
|
315
|
+
* @returns Transaction instruction
|
|
316
|
+
*/
|
|
317
|
+
export async function buildBuyStableAutoResolve(connection, params) {
|
|
318
|
+
const curve = await fetchStableBondingCurve(connection, params.mint, params.quoteMint, params.config);
|
|
319
|
+
return buildBuyStable({ ...params, creator: curve.creator });
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Builds a sellStable instruction.
|
|
323
|
+
* Sells tokens to a token-based bonding curve for quote tokens (e.g., USDC).
|
|
324
|
+
*
|
|
325
|
+
* @param params - {@link BuildSellStableParams}
|
|
326
|
+
* @returns Transaction instruction
|
|
327
|
+
*/
|
|
328
|
+
export function buildSellStable(params) {
|
|
329
|
+
const { user, mint, quoteMint, creator, amountIn, minAmountOut, feeRecipient, creatorReferralVault, traderReferralVault, config, } = params;
|
|
330
|
+
const program = getCachedLiquidProgram(config);
|
|
331
|
+
// Fee recipient quote token account
|
|
332
|
+
const feeRecipientQuoteAccount = getAssociatedTokenAddressSync(quoteMint, feeRecipient, true, TOKEN_PROGRAM_ID);
|
|
333
|
+
// Derive creator-related accounts that Anchor can't auto-resolve
|
|
334
|
+
const [creatorUserProperties] = getUserPropertiesPDA(creator, config.liquidStateProgramId);
|
|
335
|
+
return program.methods
|
|
336
|
+
.sellStable(amountIn, minAmountOut)
|
|
337
|
+
.accountsPartial({
|
|
338
|
+
user,
|
|
339
|
+
mint,
|
|
340
|
+
quoteMint,
|
|
341
|
+
feeRecipient: feeRecipientQuoteAccount,
|
|
342
|
+
creatorUserProperties,
|
|
343
|
+
creatorReferralVault: creatorReferralVault ?? null,
|
|
344
|
+
traderReferralVault: traderReferralVault ?? null,
|
|
345
|
+
liquidState: {
|
|
346
|
+
user,
|
|
347
|
+
tokenMint: mint,
|
|
348
|
+
},
|
|
349
|
+
})
|
|
350
|
+
.instruction();
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Builds a sellStable instruction, automatically fetching the bonding curve
|
|
354
|
+
* creator from chain. Convenience wrapper around `buildSellStable`.
|
|
355
|
+
*
|
|
356
|
+
* @param connection - Solana RPC connection
|
|
357
|
+
* @param params - {@link BuildSellStableParams} without `creator`
|
|
358
|
+
* @returns Transaction instruction
|
|
359
|
+
*/
|
|
360
|
+
export async function buildSellStableAutoResolve(connection, params) {
|
|
361
|
+
const curve = await fetchStableBondingCurve(connection, params.mint, params.quoteMint, params.config);
|
|
362
|
+
return buildSellStable({ ...params, creator: curve.creator });
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Builds a migrateStable instruction (token bonding curve -> AMM pool).
|
|
366
|
+
* Permissionless — anyone can trigger migration once the curve is complete.
|
|
367
|
+
*
|
|
368
|
+
* @param params - {@link BuildMigrateStableParams}
|
|
369
|
+
* @returns Transaction instruction
|
|
370
|
+
*/
|
|
371
|
+
export function buildMigrateStable(params) {
|
|
372
|
+
const { migrator, mint, quoteMint, config } = params;
|
|
373
|
+
const program = getCachedLiquidProgram(config);
|
|
374
|
+
// Derive AMM PDAs
|
|
375
|
+
const [bondingCurve] = getStableBondingCurvePDA(mint, quoteMint, config.liquidProgramId);
|
|
376
|
+
const [ammPoolState] = getPoolPDA(mint, quoteMint, config.liquidSwapProgramId);
|
|
377
|
+
const [ammLpMint] = getPoolLpMintPDA(ammPoolState, config.liquidSwapProgramId);
|
|
378
|
+
const [ammBaseVault] = getPoolVaultPDA(ammPoolState, mint, config.liquidSwapProgramId);
|
|
379
|
+
const [ammQuoteVault] = getPoolVaultPDA(ammPoolState, quoteMint, config.liquidSwapProgramId);
|
|
380
|
+
const [ammObservationState] = getObservationPDA(ammPoolState, config.liquidSwapProgramId);
|
|
381
|
+
const [ammGlobalConfig] = getSwapGlobalConfigPDA(config.liquidSwapProgramId);
|
|
382
|
+
const [ammAuthority] = getSwapAuthorityPDA(config.liquidSwapProgramId);
|
|
383
|
+
const [tokenVolume] = getTokenVolumePDA(mint, config.liquidStateProgramId);
|
|
384
|
+
const bondingCurveLpToken = getAssociatedTokenAddressSync(ammLpMint, bondingCurve, true, TOKEN_PROGRAM_ID);
|
|
385
|
+
const [ammBuybackVault] = getSwapBuybackVaultPDA(ammPoolState, quoteMint, config.liquidSwapProgramId);
|
|
386
|
+
return program.methods
|
|
387
|
+
.migrateStable()
|
|
388
|
+
.accounts({
|
|
389
|
+
signer: migrator,
|
|
390
|
+
mint,
|
|
391
|
+
quoteMint,
|
|
392
|
+
ammPoolState,
|
|
393
|
+
ammLpMint,
|
|
394
|
+
ammBaseVault,
|
|
395
|
+
ammQuoteVault,
|
|
396
|
+
ammObservationState,
|
|
397
|
+
ammGlobalConfig,
|
|
398
|
+
ammAuthority,
|
|
399
|
+
bondingCurveLpToken,
|
|
400
|
+
tokenVolume,
|
|
401
|
+
ammBuybackVault,
|
|
402
|
+
})
|
|
403
|
+
.instruction();
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Builds a setFeeRecipients instruction.
|
|
407
|
+
* Admin-only instruction to set/update the protocol fee recipients.
|
|
408
|
+
*
|
|
409
|
+
* @param params - {@link BuildSetFeeRecipientsParams}
|
|
410
|
+
* @returns Transaction instruction
|
|
411
|
+
*/
|
|
412
|
+
export function buildSetFeeRecipients(params) {
|
|
413
|
+
const { admin, feeRecipients, config } = params;
|
|
414
|
+
if (feeRecipients.length !== 8) {
|
|
415
|
+
throw new Error("feeRecipients must have exactly 8 elements");
|
|
416
|
+
}
|
|
417
|
+
const program = getCachedLiquidProgram(config);
|
|
418
|
+
return program.methods
|
|
419
|
+
.setFeeRecipients(feeRecipients)
|
|
420
|
+
.accounts({
|
|
421
|
+
admin,
|
|
422
|
+
feeRecipient1: feeRecipients[0],
|
|
423
|
+
feeRecipient2: feeRecipients[1],
|
|
424
|
+
feeRecipient3: feeRecipients[2],
|
|
425
|
+
feeRecipient4: feeRecipients[3],
|
|
426
|
+
feeRecipient5: feeRecipients[4],
|
|
427
|
+
feeRecipient6: feeRecipients[5],
|
|
428
|
+
feeRecipient7: feeRecipients[6],
|
|
429
|
+
feeRecipient8: feeRecipients[7],
|
|
430
|
+
})
|
|
431
|
+
.instruction();
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Builds an initializeFeeRecipientVaults instruction.
|
|
435
|
+
* Permissionless instruction to create token accounts for all fee recipients
|
|
436
|
+
* for a given quote mint. Call this before trading stable curves.
|
|
437
|
+
*
|
|
438
|
+
* @param params - {@link BuildInitializeFeeRecipientVaultsParams}
|
|
439
|
+
* @returns Transaction instruction
|
|
440
|
+
*/
|
|
441
|
+
export function buildInitializeFeeRecipientVaults(params) {
|
|
442
|
+
const { payer, quoteMint, feeRecipients, config } = params;
|
|
443
|
+
if (feeRecipients.length !== 8) {
|
|
444
|
+
throw new Error("feeRecipients must have exactly 8 elements");
|
|
445
|
+
}
|
|
446
|
+
const program = getCachedLiquidProgram(config);
|
|
447
|
+
return program.methods
|
|
448
|
+
.initializeFeeRecipientVaults()
|
|
449
|
+
.accounts({
|
|
450
|
+
payer,
|
|
451
|
+
quoteMint,
|
|
452
|
+
feeRecipient1: feeRecipients[0],
|
|
453
|
+
feeRecipient2: feeRecipients[1],
|
|
454
|
+
feeRecipient3: feeRecipients[2],
|
|
455
|
+
feeRecipient4: feeRecipients[3],
|
|
456
|
+
feeRecipient5: feeRecipients[4],
|
|
457
|
+
feeRecipient6: feeRecipients[5],
|
|
458
|
+
feeRecipient7: feeRecipients[6],
|
|
459
|
+
feeRecipient8: feeRecipients[7],
|
|
460
|
+
})
|
|
461
|
+
.instruction();
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Builds an initializeReferralTokenVault instruction.
|
|
465
|
+
* Creates a referral token vault (ATA) for the user for a specific quote mint.
|
|
466
|
+
* Users must call this for each quote mint they want to receive referral rewards for.
|
|
467
|
+
* If not initialized, referral fees will be redirected to protocol fees.
|
|
468
|
+
*
|
|
469
|
+
* @param params - {@link BuildInitializeReferralTokenVaultParams}
|
|
470
|
+
* @returns Transaction instruction
|
|
471
|
+
*/
|
|
472
|
+
export function buildInitializeReferralTokenVault(params) {
|
|
473
|
+
const { user, quoteMint, config } = params;
|
|
474
|
+
const program = getCachedLiquidProgram(config);
|
|
475
|
+
return program.methods
|
|
476
|
+
.initializeReferralTokenVault()
|
|
477
|
+
.accounts({
|
|
478
|
+
user,
|
|
479
|
+
quoteMint,
|
|
480
|
+
})
|
|
481
|
+
.instruction();
|
|
482
|
+
}
|
|
483
|
+
//# sourceMappingURL=liquid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquid.js","sourceRoot":"","sources":["../../src/instructions/liquid.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,6BAA6B,EAC7B,gBAAgB,GAChB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAqB,MAAM,cAAc,CAAC;AAC5D,OAAO,EACN,kBAAkB,EAClB,2BAA2B,EAC3B,wBAAwB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACjF,OAAO,EACN,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,sBAAsB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EACN,uBAAuB,EAC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E,aAAa,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAE3D,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IAC/D,CAAC;IAED,MAAM,OAAO,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAE/C,OAAO,OAAO,CAAC,OAAO;SACpB,4BAA4B,EAAE;SAC9B,QAAQ,CAAC;QACT,KAAK;QACL,SAAS;QACT,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;QAC/B,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;QAC/B,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;QAC/B,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;QAC/B,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;QAC/B,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;QAC/B,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;QAC/B,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC;KAC/B,CAAC;SACD,WAAW,EAAE,CAAC;AACjB,CAAC;AAQD;;;;;;;;GAQG;AACH,MAAM,UAAU,iCAAiC,CAChD,MAA+C;IAE/C,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,OAAO,GAAG,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAE/C,OAAO,OAAO,CAAC,OAAO;SACpB,4BAA4B,EAAE;SAC9B,QAAQ,CAAC;QACT,IAAI;QACJ,SAAS;KACT,CAAC;SACD,WAAW,EAAE,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Program } from "@coral-xyz/anchor";
|
|
2
|
+
import type { LiquidConfig } from "../config.js";
|
|
3
|
+
import type { Liquid } from "../idl/liquid.js";
|
|
4
|
+
import type { LiquidSwap } from "../idl/liquid_swap.js";
|
|
5
|
+
import type { LiquidFees } from "../idl/liquid_fees.js";
|
|
6
|
+
import type { LiquidState } from "../idl/liquid_state.js";
|
|
7
|
+
/**
|
|
8
|
+
* Returns a cached Liquid bonding curve program instance for instruction building.
|
|
9
|
+
*
|
|
10
|
+
* @param config - Liquid protocol configuration
|
|
11
|
+
* @returns Cached Program instance typed as Liquid
|
|
12
|
+
*/
|
|
13
|
+
export declare function getCachedLiquidProgram(config: LiquidConfig): Program<Liquid>;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a cached Liquid Swap AMM program instance for instruction building.
|
|
16
|
+
*
|
|
17
|
+
* @param config - Liquid protocol configuration
|
|
18
|
+
* @returns Cached Program instance typed as LiquidSwap
|
|
19
|
+
*/
|
|
20
|
+
export declare function getCachedSwapProgram(config: LiquidConfig): Program<LiquidSwap>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns a cached Liquid Fees program instance for instruction building.
|
|
23
|
+
*
|
|
24
|
+
* @param config - Liquid protocol configuration
|
|
25
|
+
* @returns Cached Program instance typed as LiquidFees
|
|
26
|
+
*/
|
|
27
|
+
export declare function getCachedFeesProgram(config: LiquidConfig): Program<LiquidFees>;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a cached Liquid State program instance for instruction building.
|
|
30
|
+
*
|
|
31
|
+
* @param config - Liquid protocol configuration
|
|
32
|
+
* @returns Cached Program instance typed as LiquidState
|
|
33
|
+
*/
|
|
34
|
+
export declare function getCachedStateProgram(config: LiquidConfig): Program<LiquidState>;
|
|
35
|
+
//# sourceMappingURL=program-cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program-cache.d.ts","sourceRoot":"","sources":["../../src/instructions/program-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAQjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAiC1D;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAM5E;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,YAAY,GAClB,OAAO,CAAC,UAAU,CAAC,CAMrB;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,YAAY,GAClB,OAAO,CAAC,UAAU,CAAC,CAMrB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,YAAY,GAClB,OAAO,CAAC,WAAW,CAAC,CAMtB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Program } from "@coral-xyz/anchor";
|
|
2
|
+
import { createStubProvider } from "../provider.js";
|
|
3
|
+
import liquidIdl from "../idl/liquid.json" with { type: "json" };
|
|
4
|
+
import liquidSwapIdl from "../idl/liquid_swap.json" with { type: "json" };
|
|
5
|
+
import liquidFeesIdl from "../idl/liquid_fees.json" with { type: "json" };
|
|
6
|
+
import liquidStateIdl from "../idl/liquid_state.json" with { type: "json" };
|
|
7
|
+
/**
|
|
8
|
+
* Cached stub Program instances for instruction building.
|
|
9
|
+
* Instruction building via `.instruction()` never hits the network,
|
|
10
|
+
* so these programs use a shared stub provider with no real Connection.
|
|
11
|
+
*/
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
|
+
const cache = new Map();
|
|
14
|
+
/**
|
|
15
|
+
* Returns a cached Program instance or creates one if it doesn't exist.
|
|
16
|
+
*
|
|
17
|
+
* @param key - Cache key prefix (e.g., "liquid", "swap")
|
|
18
|
+
* @param idl - Raw IDL JSON object
|
|
19
|
+
* @param address - Program address as a base58 string
|
|
20
|
+
* @returns Cached or newly created Program instance
|
|
21
|
+
*/
|
|
22
|
+
function getOrCreate(key, idl, address) {
|
|
23
|
+
const cacheKey = `${key}:${address}`;
|
|
24
|
+
let prog = cache.get(cacheKey);
|
|
25
|
+
if (!prog) {
|
|
26
|
+
const patchedIdl = { ...idl, address };
|
|
27
|
+
prog = new Program(patchedIdl, createStubProvider());
|
|
28
|
+
cache.set(cacheKey, prog);
|
|
29
|
+
}
|
|
30
|
+
return prog;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns a cached Liquid bonding curve program instance for instruction building.
|
|
34
|
+
*
|
|
35
|
+
* @param config - Liquid protocol configuration
|
|
36
|
+
* @returns Cached Program instance typed as Liquid
|
|
37
|
+
*/
|
|
38
|
+
export function getCachedLiquidProgram(config) {
|
|
39
|
+
return getOrCreate("liquid", liquidIdl, config.liquidProgramId.toBase58());
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns a cached Liquid Swap AMM program instance for instruction building.
|
|
43
|
+
*
|
|
44
|
+
* @param config - Liquid protocol configuration
|
|
45
|
+
* @returns Cached Program instance typed as LiquidSwap
|
|
46
|
+
*/
|
|
47
|
+
export function getCachedSwapProgram(config) {
|
|
48
|
+
return getOrCreate("swap", liquidSwapIdl, config.liquidSwapProgramId.toBase58());
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns a cached Liquid Fees program instance for instruction building.
|
|
52
|
+
*
|
|
53
|
+
* @param config - Liquid protocol configuration
|
|
54
|
+
* @returns Cached Program instance typed as LiquidFees
|
|
55
|
+
*/
|
|
56
|
+
export function getCachedFeesProgram(config) {
|
|
57
|
+
return getOrCreate("fees", liquidFeesIdl, config.liquidFeesProgramId.toBase58());
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Returns a cached Liquid State program instance for instruction building.
|
|
61
|
+
*
|
|
62
|
+
* @param config - Liquid protocol configuration
|
|
63
|
+
* @returns Cached Program instance typed as LiquidState
|
|
64
|
+
*/
|
|
65
|
+
export function getCachedStateProgram(config) {
|
|
66
|
+
return getOrCreate("state", liquidStateIdl, config.liquidStateProgramId.toBase58());
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=program-cache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"program-cache.js","sourceRoot":"","sources":["../../src/instructions/program-cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAEpD,OAAO,SAAS,MAAM,oBAAoB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACjE,OAAO,aAAa,MAAM,yBAAyB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1E,OAAO,aAAa,MAAM,yBAAyB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1E,OAAO,cAAc,MAAM,0BAA0B,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AAO5E;;;;GAIG;AACH,8DAA8D;AAC9D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAwB,CAAC;AAE9C;;;;;;;GAOG;AACH,SAAS,WAAW,CACnB,GAAW,EACX,GAA4B,EAC5B,OAAe;IAEf,MAAM,QAAQ,GAAG,GAAG,GAAG,IAAI,OAAO,EAAE,CAAC;IACrC,IAAI,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAA2B,CAAC;IACzD,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,MAAM,UAAU,GAAG,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,CAAC;QACvC,IAAI,GAAG,IAAI,OAAO,CAAC,UAAe,EAAE,kBAAkB,EAAE,CAAC,CAAC;QAC1D,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAoB;IAC1D,OAAO,WAAW,CACjB,QAAQ,EACR,SAAS,EACT,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,CACjC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CACnC,MAAoB;IAEpB,OAAO,WAAW,CACjB,MAAM,EACN,aAAa,EACb,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CACrC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CACnC,MAAoB;IAEpB,OAAO,WAAW,CACjB,MAAM,EACN,aAAa,EACb,MAAM,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CACrC,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACpC,MAAoB;IAEpB,OAAO,WAAW,CACjB,OAAO,EACP,cAAc,EACd,MAAM,CAAC,oBAAoB,CAAC,QAAQ,EAAE,CACtC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import BN from "bn.js";
|
|
2
|
+
import type { AmmSellOutput, AmmBuyInput, LpTokenAmounts } from "../types.js";
|
|
3
|
+
/** AMM fee rates in basis points */
|
|
4
|
+
export interface AmmFeeRates {
|
|
5
|
+
lpFeeRate: number;
|
|
6
|
+
creatorFeeRate: number;
|
|
7
|
+
protocolFeeRate: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Calculates expected output for selling base tokens on the AMM.
|
|
11
|
+
* Uses constant product formula: quoteOut = (amountIn * quoteVault) / (baseVault + amountIn)
|
|
12
|
+
*
|
|
13
|
+
* @param amountIn - Base tokens to sell
|
|
14
|
+
* @param baseVault - Current base vault balance
|
|
15
|
+
* @param quoteVault - Current quote vault balance
|
|
16
|
+
* @param fees - Fee rates in basis points
|
|
17
|
+
* @returns Sell output with gross/net quote amounts and fee breakdown
|
|
18
|
+
*/
|
|
19
|
+
export declare const calculateAmmSellOutput: (amountIn: BN, baseVault: BN, quoteVault: BN, fees: AmmFeeRates) => AmmSellOutput;
|
|
20
|
+
/**
|
|
21
|
+
* Calculates required quote input for buying base tokens on the AMM.
|
|
22
|
+
* Reverse calculation: how much quote is needed for the desired base output.
|
|
23
|
+
*
|
|
24
|
+
* @param amountOut - Base tokens to buy
|
|
25
|
+
* @param baseVault - Current base vault balance
|
|
26
|
+
* @param quoteVault - Current quote vault balance
|
|
27
|
+
* @param fees - Fee rates in basis points
|
|
28
|
+
* @returns Buy input with gross/net quote amounts and fee breakdown
|
|
29
|
+
*/
|
|
30
|
+
export declare const calculateAmmBuyInput: (amountOut: BN, baseVault: BN, quoteVault: BN, fees: AmmFeeRates) => AmmBuyInput;
|
|
31
|
+
/**
|
|
32
|
+
* Converts LP tokens to the equivalent base and quote token amounts.
|
|
33
|
+
*
|
|
34
|
+
* @param lpAmount - LP tokens to convert
|
|
35
|
+
* @param lpSupply - Total LP supply
|
|
36
|
+
* @param baseVault - Base vault balance
|
|
37
|
+
* @param quoteVault - Quote vault balance
|
|
38
|
+
* @param roundUp - Use ceiling division (for deposits) vs floor division (for withdrawals)
|
|
39
|
+
* @returns Equivalent base and quote token amounts for the given LP tokens
|
|
40
|
+
*/
|
|
41
|
+
export declare const calculateLpToTokens: (lpAmount: BN, lpSupply: BN, baseVault: BN, quoteVault: BN, roundUp?: boolean) => LpTokenAmounts;
|
|
42
|
+
//# sourceMappingURL=amm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amm.d.ts","sourceRoot":"","sources":["../../src/math/amm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvB,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE9E,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,sBAAsB,GAClC,UAAU,EAAE,EACZ,WAAW,EAAE,EACb,YAAY,EAAE,EACd,MAAM,WAAW,KACf,aAwBF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,GAChC,WAAW,EAAE,EACb,WAAW,EAAE,EACb,YAAY,EAAE,EACd,MAAM,WAAW,KACf,WAqCF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAC/B,UAAU,EAAE,EACZ,UAAU,EAAE,EACZ,WAAW,EAAE,EACb,YAAY,EAAE,EACd,UAAS,OAAe,KACtB,cAuBF,CAAC"}
|