@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,336 @@
|
|
|
1
|
+
import type { PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import type { LiquidConfig } from "../config.js";
|
|
3
|
+
import { getCachedStateProgram } from "./program-cache.js";
|
|
4
|
+
import { getDealPDA, getUserSnapshotPDA } from "../pda/liquid-state.js";
|
|
5
|
+
|
|
6
|
+
export interface BuildInitializeUserParams {
|
|
7
|
+
user: PublicKey;
|
|
8
|
+
config: LiquidConfig;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Builds an initializeUser instruction.
|
|
13
|
+
* Creates the user properties account in liquid-state.
|
|
14
|
+
*
|
|
15
|
+
* @param params - {@link BuildInitializeUserParams}
|
|
16
|
+
* @returns Transaction instruction
|
|
17
|
+
*/
|
|
18
|
+
export function buildInitializeUser(
|
|
19
|
+
params: BuildInitializeUserParams
|
|
20
|
+
): Promise<TransactionInstruction> {
|
|
21
|
+
const { user, config } = params;
|
|
22
|
+
const program = getCachedStateProgram(config);
|
|
23
|
+
|
|
24
|
+
return program.methods.initializeUser().accounts({ user }).instruction();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface BuildSetReferrerParams {
|
|
28
|
+
user: PublicKey;
|
|
29
|
+
referrer: PublicKey;
|
|
30
|
+
config: LiquidConfig;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Builds a setReferrer instruction.
|
|
35
|
+
* One-time operation — referrer cannot be changed once set.
|
|
36
|
+
*
|
|
37
|
+
* @param params - {@link BuildSetReferrerParams}
|
|
38
|
+
* @returns Transaction instruction
|
|
39
|
+
*/
|
|
40
|
+
export function buildSetReferrer(
|
|
41
|
+
params: BuildSetReferrerParams
|
|
42
|
+
): Promise<TransactionInstruction> {
|
|
43
|
+
const { user, referrer, config } = params;
|
|
44
|
+
const program = getCachedStateProgram(config);
|
|
45
|
+
|
|
46
|
+
return program.methods
|
|
47
|
+
.setReferrer(referrer)
|
|
48
|
+
.accounts({ user })
|
|
49
|
+
.instruction();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface BuildSetCashbackModeParams {
|
|
53
|
+
user: PublicKey;
|
|
54
|
+
config: LiquidConfig;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Builds a setCashbackMode instruction.
|
|
59
|
+
* Toggles user between earning mode (earn credits) and spending mode (spend credits).
|
|
60
|
+
*
|
|
61
|
+
* @param params - {@link BuildSetCashbackModeParams}
|
|
62
|
+
* @returns Transaction instruction
|
|
63
|
+
*/
|
|
64
|
+
export function buildSetCashbackMode(
|
|
65
|
+
params: BuildSetCashbackModeParams
|
|
66
|
+
): Promise<TransactionInstruction> {
|
|
67
|
+
const { user, config } = params;
|
|
68
|
+
const program = getCachedStateProgram(config);
|
|
69
|
+
|
|
70
|
+
return program.methods.setCashbackMode().accounts({ user }).instruction();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface BuildTransferAdminParams {
|
|
74
|
+
admin: PublicKey;
|
|
75
|
+
newAdmin: PublicKey;
|
|
76
|
+
config: LiquidConfig;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Builds a transferAdmin instruction.
|
|
81
|
+
* Proposes transfer of admin authority to a new pubkey (two-step).
|
|
82
|
+
* The new admin must call {@link buildAcceptAdmin} to complete the transfer.
|
|
83
|
+
*
|
|
84
|
+
* @param params - {@link BuildTransferAdminParams}
|
|
85
|
+
* @returns Transaction instruction
|
|
86
|
+
*/
|
|
87
|
+
export function buildTransferAdmin(
|
|
88
|
+
params: BuildTransferAdminParams
|
|
89
|
+
): Promise<TransactionInstruction> {
|
|
90
|
+
const { admin, newAdmin, config } = params;
|
|
91
|
+
const program = getCachedStateProgram(config);
|
|
92
|
+
|
|
93
|
+
return program.methods
|
|
94
|
+
.transferAdmin(newAdmin)
|
|
95
|
+
.accounts({ admin })
|
|
96
|
+
.instruction();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface BuildAcceptAdminParams {
|
|
100
|
+
newAdmin: PublicKey;
|
|
101
|
+
config: LiquidConfig;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Builds an acceptAdmin instruction.
|
|
106
|
+
* Completes a pending admin transfer. Must be called by the pending admin.
|
|
107
|
+
*
|
|
108
|
+
* @param params - {@link BuildAcceptAdminParams}
|
|
109
|
+
* @returns Transaction instruction
|
|
110
|
+
*/
|
|
111
|
+
export function buildAcceptAdmin(
|
|
112
|
+
params: BuildAcceptAdminParams
|
|
113
|
+
): Promise<TransactionInstruction> {
|
|
114
|
+
const { newAdmin, config } = params;
|
|
115
|
+
const program = getCachedStateProgram(config);
|
|
116
|
+
|
|
117
|
+
return program.methods
|
|
118
|
+
.acceptAdmin()
|
|
119
|
+
.accounts({ newAdmin })
|
|
120
|
+
.instruction();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface BuildCancelAdminTransferParams {
|
|
124
|
+
authority: PublicKey;
|
|
125
|
+
config: LiquidConfig;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Builds a cancelAdminTransfer instruction.
|
|
130
|
+
* Cancels a pending admin transfer. Callable by either the current admin or the pending admin.
|
|
131
|
+
*
|
|
132
|
+
* @param params - {@link BuildCancelAdminTransferParams}
|
|
133
|
+
* @returns Transaction instruction
|
|
134
|
+
*/
|
|
135
|
+
export function buildCancelAdminTransfer(
|
|
136
|
+
params: BuildCancelAdminTransferParams
|
|
137
|
+
): Promise<TransactionInstruction> {
|
|
138
|
+
const { authority, config } = params;
|
|
139
|
+
const program = getCachedStateProgram(config);
|
|
140
|
+
|
|
141
|
+
return program.methods
|
|
142
|
+
.cancelAdminTransfer()
|
|
143
|
+
.accounts({ authority })
|
|
144
|
+
.instruction();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export interface BuildCreateDealParams {
|
|
148
|
+
admin: PublicKey;
|
|
149
|
+
owner: PublicKey;
|
|
150
|
+
cashbackMultiplierBps: number;
|
|
151
|
+
payer: PublicKey;
|
|
152
|
+
config: LiquidConfig;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Builds a createDeal instruction.
|
|
157
|
+
* Admin creates an exclusive deal for a pubkey (typically a referrer/influencer).
|
|
158
|
+
*
|
|
159
|
+
* @param params - {@link BuildCreateDealParams}
|
|
160
|
+
* @returns Transaction instruction
|
|
161
|
+
*/
|
|
162
|
+
export function buildCreateDeal(
|
|
163
|
+
params: BuildCreateDealParams
|
|
164
|
+
): Promise<TransactionInstruction> {
|
|
165
|
+
const { admin, owner, cashbackMultiplierBps, payer, config } = params;
|
|
166
|
+
const program = getCachedStateProgram(config);
|
|
167
|
+
|
|
168
|
+
return program.methods
|
|
169
|
+
.createDeal(owner, cashbackMultiplierBps)
|
|
170
|
+
.accounts({ admin, payer })
|
|
171
|
+
.instruction();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface BuildUpdateDealParams {
|
|
175
|
+
admin: PublicKey;
|
|
176
|
+
dealOwner: PublicKey;
|
|
177
|
+
newCashbackMultiplierBps: number;
|
|
178
|
+
config: LiquidConfig;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Builds an updateDeal instruction.
|
|
183
|
+
* Admin updates a deal's cashback multiplier.
|
|
184
|
+
*
|
|
185
|
+
* @param params - {@link BuildUpdateDealParams}
|
|
186
|
+
* @returns Transaction instruction
|
|
187
|
+
*/
|
|
188
|
+
export function buildUpdateDeal(
|
|
189
|
+
params: BuildUpdateDealParams
|
|
190
|
+
): Promise<TransactionInstruction> {
|
|
191
|
+
const { admin, dealOwner, newCashbackMultiplierBps, config } = params;
|
|
192
|
+
const program = getCachedStateProgram(config);
|
|
193
|
+
const [deal] = getDealPDA(dealOwner, config.liquidStateProgramId);
|
|
194
|
+
|
|
195
|
+
return program.methods
|
|
196
|
+
.updateDeal(newCashbackMultiplierBps)
|
|
197
|
+
.accountsPartial({ admin, deal })
|
|
198
|
+
.instruction();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export interface BuildCloseDealParams {
|
|
202
|
+
admin: PublicKey;
|
|
203
|
+
dealOwner: PublicKey;
|
|
204
|
+
config: LiquidConfig;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Builds a closeDeal instruction.
|
|
209
|
+
* Admin closes/deletes a deal, returning rent to admin.
|
|
210
|
+
*
|
|
211
|
+
* @param params - {@link BuildCloseDealParams}
|
|
212
|
+
* @returns Transaction instruction
|
|
213
|
+
*/
|
|
214
|
+
export function buildCloseDeal(
|
|
215
|
+
params: BuildCloseDealParams
|
|
216
|
+
): Promise<TransactionInstruction> {
|
|
217
|
+
const { admin, dealOwner, config } = params;
|
|
218
|
+
const program = getCachedStateProgram(config);
|
|
219
|
+
const [deal] = getDealPDA(dealOwner, config.liquidStateProgramId);
|
|
220
|
+
|
|
221
|
+
return program.methods
|
|
222
|
+
.closeDeal()
|
|
223
|
+
.accountsPartial({ admin, deal })
|
|
224
|
+
.instruction();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export interface BuildRedeemDealParams {
|
|
228
|
+
user: PublicKey;
|
|
229
|
+
dealOwner: PublicKey;
|
|
230
|
+
config: LiquidConfig;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Builds a redeemDeal instruction.
|
|
235
|
+
* User redeems their referrer's deal, copying the multiplier.
|
|
236
|
+
*
|
|
237
|
+
* @param params - {@link BuildRedeemDealParams}
|
|
238
|
+
* @returns Transaction instruction
|
|
239
|
+
*/
|
|
240
|
+
export function buildRedeemDeal(
|
|
241
|
+
params: BuildRedeemDealParams
|
|
242
|
+
): Promise<TransactionInstruction> {
|
|
243
|
+
const { user, dealOwner, config } = params;
|
|
244
|
+
const program = getCachedStateProgram(config);
|
|
245
|
+
const [deal] = getDealPDA(dealOwner, config.liquidStateProgramId);
|
|
246
|
+
|
|
247
|
+
return program.methods
|
|
248
|
+
.redeemDeal()
|
|
249
|
+
.accountsPartial({ user, deal })
|
|
250
|
+
.instruction();
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export interface BuildTakeSnapshotParams {
|
|
254
|
+
admin: PublicKey;
|
|
255
|
+
user: PublicKey;
|
|
256
|
+
payer: PublicKey;
|
|
257
|
+
snapshotIndex: number;
|
|
258
|
+
config: LiquidConfig;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Builds a takeSnapshot instruction.
|
|
263
|
+
* Admin takes a snapshot of a user's volume since last snapshot.
|
|
264
|
+
*
|
|
265
|
+
* The caller must provide the current `snapshotIndex` (from `user_properties.snapshot_count`)
|
|
266
|
+
* because the snapshot PDA seed depends on this value and cannot be resolved without a
|
|
267
|
+
* network fetch.
|
|
268
|
+
*
|
|
269
|
+
* @param params - {@link BuildTakeSnapshotParams}
|
|
270
|
+
* @returns Transaction instruction
|
|
271
|
+
*/
|
|
272
|
+
export function buildTakeSnapshot(
|
|
273
|
+
params: BuildTakeSnapshotParams
|
|
274
|
+
): Promise<TransactionInstruction> {
|
|
275
|
+
const { admin, user, payer, snapshotIndex, config } = params;
|
|
276
|
+
const program = getCachedStateProgram(config);
|
|
277
|
+
const [userSnapshot] = getUserSnapshotPDA(
|
|
278
|
+
user,
|
|
279
|
+
snapshotIndex,
|
|
280
|
+
config.liquidStateProgramId
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
return program.methods
|
|
284
|
+
.takeSnapshot()
|
|
285
|
+
.accountsPartial({ admin, user, payer, userSnapshot })
|
|
286
|
+
.instruction();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export interface BuildAdminUpdateUserParams {
|
|
290
|
+
admin: PublicKey;
|
|
291
|
+
user: PublicKey;
|
|
292
|
+
payer: PublicKey;
|
|
293
|
+
newReferrer: PublicKey | null;
|
|
294
|
+
newCashbackMultiplierBps: number | null;
|
|
295
|
+
snapshotIndex: number;
|
|
296
|
+
config: LiquidConfig;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Builds an adminUpdateUser instruction.
|
|
301
|
+
* Admin updates a user's referrer/multiplier and always takes a snapshot.
|
|
302
|
+
*
|
|
303
|
+
* The caller must provide the current `snapshotIndex` (from `user_properties.snapshot_count`)
|
|
304
|
+
* because the snapshot PDA seed depends on this value and cannot be resolved without a
|
|
305
|
+
* network fetch.
|
|
306
|
+
*
|
|
307
|
+
* @param params - {@link BuildAdminUpdateUserParams}
|
|
308
|
+
* @returns Transaction instruction
|
|
309
|
+
*/
|
|
310
|
+
export function buildAdminUpdateUser(
|
|
311
|
+
params: BuildAdminUpdateUserParams
|
|
312
|
+
): Promise<TransactionInstruction> {
|
|
313
|
+
const {
|
|
314
|
+
admin,
|
|
315
|
+
user,
|
|
316
|
+
payer,
|
|
317
|
+
newReferrer,
|
|
318
|
+
newCashbackMultiplierBps,
|
|
319
|
+
snapshotIndex,
|
|
320
|
+
config,
|
|
321
|
+
} = params;
|
|
322
|
+
const program = getCachedStateProgram(config);
|
|
323
|
+
const [userSnapshot] = getUserSnapshotPDA(
|
|
324
|
+
user,
|
|
325
|
+
snapshotIndex,
|
|
326
|
+
config.liquidStateProgramId
|
|
327
|
+
);
|
|
328
|
+
|
|
329
|
+
return program.methods
|
|
330
|
+
.adminUpdateUser({
|
|
331
|
+
newReferrer: newReferrer ?? null,
|
|
332
|
+
newCashbackMultiplierBps: newCashbackMultiplierBps ?? null,
|
|
333
|
+
})
|
|
334
|
+
.accountsPartial({ admin, user, payer, userSnapshot })
|
|
335
|
+
.instruction();
|
|
336
|
+
}
|