-
Notifications
You must be signed in to change notification settings - Fork 139
/
ix.ts
522 lines (491 loc) · 21.2 KB
/
ix.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
import { Program } from "@coral-xyz/anchor";
import { PDA } from "@orca-so/common-sdk";
import { Whirlpool } from "./artifacts/whirlpool";
import * as ix from "./instructions";
/**
* Instruction builders for the Whirlpools program.
*
* @category Core
*/
export class WhirlpoolIx {
/**
* Initializes a WhirlpoolsConfig account that hosts info & authorities
* required to govern a set of Whirlpools.
*
* @param program - program object containing services required to generate the instruction
* @param params - InitConfigParams object
* @returns - Instruction to perform the action.
*/
public static initializeConfigIx(program: Program<Whirlpool>, params: ix.InitConfigParams) {
return ix.initializeConfigIx(program, params);
}
/**
* Initializes a fee tier account usable by Whirlpools in this WhirlpoolsConfig space.
*
* Special Errors
* `FeeRateMaxExceeded` - If the provided default_fee_rate exceeds MAX_FEE_RATE.
*
* @param program - program object containing services required to generate the instruction
* @param params - InitFeeTierParams object
* @returns - Instruction to perform the action.
*/
public static initializeFeeTierIx(program: Program<Whirlpool>, params: ix.InitFeeTierParams) {
return ix.initializeFeeTierIx(program, params);
}
/**
* Initializes a tick_array account to represent a tick-range in a Whirlpool.
*
* Special Errors
* `InvalidTokenMintOrder` - The order of mints have to be ordered by
* `SqrtPriceOutOfBounds` - provided initial_sqrt_price is not between 2^-64 to 2^64
*
* @param program - program object containing services required to generate the instruction
* @param params - InitPoolParams object
* @returns - Instruction to perform the action.
*/
public static initializePoolIx(program: Program<Whirlpool>, params: ix.InitPoolParams) {
return ix.initializePoolIx(program, params);
}
/**
* Initialize reward for a Whirlpool. A pool can only support up to a set number of rewards.
* The initial emissionsPerSecond is set to 0.
*
* #### Special Errors
* - `InvalidRewardIndex` - If the provided reward index doesn't match the lowest uninitialized index in this pool,
* or exceeds NUM_REWARDS, or all reward slots for this pool has been initialized.
*
* @param program - program object containing services required to generate the instruction
* @param params - InitializeRewardParams object
* @returns - Instruction to perform the action.
*/
public static initializeRewardIx(program: Program<Whirlpool>, params: ix.InitializeRewardParams) {
return ix.initializeRewardIx(program, params);
}
/**
* Initializes a TickArray account.
*
* #### Special Errors
* `InvalidStartTick` - if the provided start tick is out of bounds or is not a multiple of TICK_ARRAY_SIZE * tick spacing.
*
* @param program - program object containing services required to generate the instruction
* @param params - InitTickArrayParams object
* @returns - Instruction to perform the action.
*/
public static initTickArrayIx(program: Program<Whirlpool>, params: ix.InitTickArrayParams) {
return ix.initTickArrayIx(program, params);
}
/**
* Open a position in a Whirlpool. A unique token will be minted to represent the position in the users wallet.
* The position will start off with 0 liquidity.
*
* #### Special Errors
* `InvalidTickIndex` - If a provided tick is out of bounds, out of order or not a multiple of the tick-spacing in this pool.
*
* @param program - program object containing services required to generate the instruction
* @param params - OpenPositionParams object
* @returns - Instruction to perform the action.
*/
public static openPositionIx(program: Program<Whirlpool>, params: ix.OpenPositionParams) {
return ix.openPositionIx(program, params);
}
/**
* Open a position in a Whirlpool. A unique token will be minted to represent the position
* in the users wallet. Additional Metaplex metadata is appended to identify the token.
* The position will start off with 0 liquidity.
*
* #### Special Errors
* `InvalidTickIndex` - If a provided tick is out of bounds, out of order or not a multiple of the tick-spacing in this pool.
*
* @param program - program object containing services required to generate the instruction
* @param params - OpenPositionParams object and a derived PDA that hosts the position's metadata.
* @returns - Instruction to perform the action.
*/
public static openPositionWithMetadataIx(
program: Program<Whirlpool>,
params: ix.OpenPositionParams & { metadataPda: PDA }
) {
return ix.openPositionWithMetadataIx(program, params);
}
/**
* Add liquidity to a position in the Whirlpool. This call also updates the position's accrued fees and rewards.
*
* #### Special Errors
* `LiquidityZero` - Provided liquidity amount is zero.
* `LiquidityTooHigh` - Provided liquidity exceeds u128::max.
* `TokenMaxExceeded` - The required token to perform this operation exceeds the user defined amount.
*
* @param program - program object containing services required to generate the instruction
* @param params - IncreaseLiquidityParams object
* @returns - Instruction to perform the action.
*/
public static increaseLiquidityIx(
program: Program<Whirlpool>,
params: ix.IncreaseLiquidityParams
) {
return ix.increaseLiquidityIx(program, params);
}
/**
* Remove liquidity to a position in the Whirlpool. This call also updates the position's accrued fees and rewards.
*
* #### Special Errors
* - `LiquidityZero` - Provided liquidity amount is zero.
* - `LiquidityTooHigh` - Provided liquidity exceeds u128::max.
* - `TokenMinSubceeded` - The required token to perform this operation subceeds the user defined amount.
*
* @param program - program object containing services required to generate the instruction
* @param params - DecreaseLiquidityParams object
* @returns - Instruction to perform the action.
*/
public static decreaseLiquidityIx(
program: Program<Whirlpool>,
params: ix.DecreaseLiquidityParams
) {
return ix.decreaseLiquidityIx(program, params);
}
/**
* Close a position in a Whirlpool. Burns the position token in the owner's wallet.
*
* @param program - program object containing services required to generate the instruction
* @param params - ClosePositionParams object
* @returns - Instruction to perform the action.
*/
public static closePositionIx(program: Program<Whirlpool>, params: ix.ClosePositionParams) {
return ix.closePositionIx(program, params);
}
/**
* Perform a swap in this Whirlpool
*
* #### Special Errors
* - `ZeroTradableAmount` - User provided parameter `amount` is 0.
* - `InvalidSqrtPriceLimitDirection` - User provided parameter `sqrt_price_limit` does not match the direction of the trade.
* - `SqrtPriceOutOfBounds` - User provided parameter `sqrt_price_limit` is over Whirlppool's max/min bounds for sqrt-price.
* - `InvalidTickArraySequence` - User provided tick-arrays are not in sequential order required to proceed in this trade direction.
* - `TickArraySequenceInvalidIndex` - The swap loop attempted to access an invalid array index during the query of the next initialized tick.
* - `TickArrayIndexOutofBounds` - The swap loop attempted to access an invalid array index during tick crossing.
* - `LiquidityOverflow` - Liquidity value overflowed 128bits during tick crossing.
* - `InvalidTickSpacing` - The swap pool was initialized with tick-spacing of 0.
*
* ### Parameters
* @param program - program object containing services required to generate the instruction
* @param params - {@link SwapParams}
* @returns - Instruction to perform the action.
*/
public static swapIx(program: Program<Whirlpool>, params: ix.SwapParams) {
return ix.swapIx(program, params);
}
/**
* Perform a two-hop-swap in this Whirlpool
*
* #### Special Errors
* - `ZeroTradableAmount` - User provided parameter `amount` is 0.
* - `InvalidSqrtPriceLimitDirection` - User provided parameter `sqrt_price_limit` does not match the direction of the trade.
* - `SqrtPriceOutOfBounds` - User provided parameter `sqrt_price_limit` is over Whirlppool's max/min bounds for sqrt-price.
* - `InvalidTickArraySequence` - User provided tick-arrays are not in sequential order required to proceed in this trade direction.
* - `TickArraySequenceInvalidIndex` - The swap loop attempted to access an invalid array index during the query of the next initialized tick.
* - `TickArrayIndexOutofBounds` - The swap loop attempted to access an invalid array index during tick crossing.
* - `LiquidityOverflow` - Liquidity value overflowed 128bits during tick crossing.
* - `InvalidTickSpacing` - The swap pool was initialized with tick-spacing of 0.
* - `DuplicateTwoHopPool` - Swaps on the same pool are not allowed.
* - `InvalidIntermediaryMint` - The first and second leg of the hops do not share a common token.
*
* ### Parameters
* @param program - program object containing services required to generate the instruction
* @param params - TwoHopSwapParams object
* @returns - Instruction to perform the action.
*/
public static twoHopSwapIx(program: Program<Whirlpool>, params: ix.TwoHopSwapParams) {
return ix.twoHopSwapIx(program, params);
}
/**
* Update the accrued fees and rewards for a position.
*
* #### Special Errors
* `TickNotFound` - Provided tick array account does not contain the tick for this position.
* `LiquidityZero` - Position has zero liquidity and therefore already has the most updated fees and reward values.
*
* @param program - program object containing services required to generate the instruction
* @param params - UpdateFeesAndRewardsParams object
* @returns - Instruction to perform the action.
*/
public static updateFeesAndRewardsIx(
program: Program<Whirlpool>,
params: ix.UpdateFeesAndRewardsParams
) {
return ix.updateFeesAndRewardsIx(program, params);
}
/**
* Collect fees accrued for this position.
* Call updateFeesAndRewards before this to update the position to the newest accrued values.
*
* @param program - program object containing services required to generate the instruction
* @param params - CollectFeesParams object
* @returns - Instruction to perform the action.
*/
public static collectFeesIx(program: Program<Whirlpool>, params: ix.CollectFeesParams) {
return ix.collectFeesIx(program, params);
}
/**
* Collect protocol fees accrued in this Whirlpool.
*
* @param program - program object containing services required to generate the instruction
* @param params - CollectProtocolFeesParams object
* @returns - Instruction to perform the action.
*/
public static collectProtocolFeesIx(
program: Program<Whirlpool>,
params: ix.CollectProtocolFeesParams
) {
return ix.collectProtocolFeesIx(program, params);
}
/**
* Collect rewards accrued for this reward index in a position.
* Call updateFeesAndRewards before this to update the position to the newest accrued values.
*
* @param program - program object containing services required to generate the instruction
* @param params - CollectRewardParams object
* @returns - Instruction to perform the action.
*/
public static collectRewardIx(program: Program<Whirlpool>, params: ix.CollectRewardParams) {
return ix.collectRewardIx(program, params);
}
/**
* Sets the fee authority to collect protocol fees for a WhirlpoolsConfig.
* Only the current collect protocol fee authority has permission to invoke this instruction.
*
* @param program - program object containing services required to generate the instruction
* @param params - SetCollectProtocolFeesAuthorityParams object
* @returns - Instruction to perform the action.
*/
public static setCollectProtocolFeesAuthorityIx(
program: Program<Whirlpool>,
params: ix.SetCollectProtocolFeesAuthorityParams
) {
return ix.setCollectProtocolFeesAuthorityIx(program, params);
}
/**
* Updates a fee tier account with a new default fee rate. The new rate will not retroactively update
* initialized pools.
*
* #### Special Errors
* - `FeeRateMaxExceeded` - If the provided default_fee_rate exceeds MAX_FEE_RATE.
*
* @param program - program object containing services required to generate the instruction
* @param params - SetDefaultFeeRateParams object
* @returns - Instruction to perform the action.
*/
public static setDefaultFeeRateIx(
program: Program<Whirlpool>,
params: ix.SetDefaultFeeRateParams
) {
return ix.setDefaultFeeRateIx(program, params);
}
/**
* Updates a WhirlpoolsConfig with a new default protocol fee rate. The new rate will not retroactively update
* initialized pools.
*
* #### Special Errors
* - `ProtocolFeeRateMaxExceeded` - If the provided default_protocol_fee_rate exceeds MAX_PROTOCOL_FEE_RATE.
*
* @param program - program object containing services required to generate the instruction
* @param params - SetDefaultFeeRateParams object
* @returns - Instruction to perform the action.
*/
public static setDefaultProtocolFeeRateIx(
program: Program<Whirlpool>,
params: ix.SetDefaultProtocolFeeRateParams
) {
return ix.setDefaultProtocolFeeRateIx(program, params);
}
/**
* Sets the fee authority for a WhirlpoolsConfig.
* The fee authority can set the fee & protocol fee rate for individual pools or set the default fee rate for newly minted pools.
* Only the current fee authority has permission to invoke this instruction.
*
* @param program - program object containing services required to generate the instruction
* @param params - SetFeeAuthorityParams object
* @returns - Instruction to perform the action.
*/
public static setFeeAuthorityIx(program: Program<Whirlpool>, params: ix.SetFeeAuthorityParams) {
return ix.setFeeAuthorityIx(program, params);
}
/**
* Sets the fee rate for a Whirlpool.
* Only the current fee authority has permission to invoke this instruction.
*
* #### Special Errors
* - `FeeRateMaxExceeded` - If the provided fee_rate exceeds MAX_FEE_RATE.
*
* @param program - program object containing services required to generate the instruction
* @param params - SetFeeRateParams object
* @returns - Instruction to perform the action.
*/
public static setFeeRateIx(program: Program<Whirlpool>, params: ix.SetFeeRateParams) {
return ix.setFeeRateIx(program, params);
}
/**
* Sets the protocol fee rate for a Whirlpool.
* Only the current fee authority has permission to invoke this instruction.
*
* #### Special Errors
* - `ProtocolFeeRateMaxExceeded` - If the provided default_protocol_fee_rate exceeds MAX_PROTOCOL_FEE_RATE.
*
* @param program - program object containing services required to generate the instruction
* @param params - SetFeeRateParams object
* @returns - Instruction to perform the action.
*/
public static setProtocolFeeRateIx(
program: Program<Whirlpool>,
params: ix.SetProtocolFeeRateParams
) {
return ix.setProtocolFeeRateIx(program, params);
}
/**
* Set the whirlpool reward authority at the provided `reward_index`.
* Only the current reward super authority has permission to invoke this instruction.
*
* #### Special Errors
* - `InvalidRewardIndex` - If the provided reward index doesn't match the lowest uninitialized index in this pool,
* or exceeds NUM_REWARDS.
*
* @param program - program object containing services required to generate the instruction
* @param params - SetRewardAuthorityParams object
* @returns - Instruction to perform the action.
*/
public static setRewardAuthorityBySuperAuthorityIx(
program: Program<Whirlpool>,
params: ix.SetRewardAuthorityBySuperAuthorityParams
) {
return ix.setRewardAuthorityBySuperAuthorityIx(program, params);
}
/**
* Set the whirlpool reward authority at the provided `reward_index`.
* Only the current reward authority for this reward index has permission to invoke this instruction.
*
* #### Special Errors
* - `InvalidRewardIndex` - If the provided reward index doesn't match the lowest uninitialized index in this pool,
* or exceeds NUM_REWARDS.
*
* @param program - program object containing services required to generate the instruction
* @param params - SetRewardAuthorityParams object
* @returns - Instruction to perform the action.
*/
public static setRewardAuthorityIx(
program: Program<Whirlpool>,
params: ix.SetRewardAuthorityParams
) {
return ix.setRewardAuthorityIx(program, params);
}
/**
* Set the reward emissions for a reward in a Whirlpool.
*
* #### Special Errors
* - `RewardVaultAmountInsufficient` - The amount of rewards in the reward vault cannot emit more than a day of desired emissions.
* - `InvalidTimestamp` - Provided timestamp is not in order with the previous timestamp.
* - `InvalidRewardIndex` - If the provided reward index doesn't match the lowest uninitialized index in this pool,
* or exceeds NUM_REWARDS.
*
* @param program - program object containing services required to generate the instruction
* @param params - SetRewardEmissionsParams object
* @returns - Instruction to perform the action.
*/
public static setRewardEmissionsIx(
program: Program<Whirlpool>,
params: ix.SetRewardEmissionsParams
) {
return ix.setRewardEmissionsIx(program, params);
}
/**
* Set the whirlpool reward super authority for a WhirlpoolsConfig
* Only the current reward super authority has permission to invoke this instruction.
* This instruction will not change the authority on any `WhirlpoolRewardInfo` whirlpool rewards.
*
* @param program - program object containing services required to generate the instruction
* @param params - SetRewardEmissionsSuperAuthorityParams object
* @returns - Instruction to perform the action.
*/
public static setRewardEmissionsSuperAuthorityIx(
program: Program<Whirlpool>,
params: ix.SetRewardEmissionsSuperAuthorityParams
) {
return ix.setRewardEmissionsSuperAuthorityIx(program, params);
}
/**
* Initializes a PositionBundle account.
*
* @param program - program object containing services required to generate the instruction
* @param params - InitializePositionBundleParams object
* @returns - Instruction to perform the action.
*/
public static initializePositionBundleIx(
program: Program<Whirlpool>,
params: ix.InitializePositionBundleParams
) {
return ix.initializePositionBundleIx(program, params);
}
/**
* Initializes a PositionBundle account.
* Additional Metaplex metadata is appended to identify the token.
*
* @param program - program object containing services required to generate the instruction
* @param params - InitializePositionBundleParams object
* @returns - Instruction to perform the action.
*/
public static initializePositionBundleWithMetadataIx(
program: Program<Whirlpool>,
params: ix.InitializePositionBundleParams & { positionBundleMetadataPda: PDA }
) {
return ix.initializePositionBundleWithMetadataIx(program, params);
}
/**
* Deletes a PositionBundle account.
*
* #### Special Errors
* `PositionBundleNotDeletable` - The provided position bundle has open positions.
*
* @param program - program object containing services required to generate the instruction
* @param params - DeletePositionBundleParams object
* @returns - Instruction to perform the action.
*/
public static deletePositionBundleIx(
program: Program<Whirlpool>,
params: ix.DeletePositionBundleParams
) {
return ix.deletePositionBundleIx(program, params);
}
/**
* Open a bundled position in a Whirlpool.
* No new tokens are issued because the owner of the position bundle becomes the owner of the position.
* The position will start off with 0 liquidity.
*
* #### Special Errors
* `InvalidBundleIndex` - If the provided bundle index is out of bounds.
* `InvalidTickIndex` - If a provided tick is out of bounds, out of order or not a multiple of the tick-spacing in this pool.
*
* @param program - program object containing services required to generate the instruction
* @param params - OpenBundledPositionParams object
* @returns - Instruction to perform the action.
*/
public static openBundledPositionIx(
program: Program<Whirlpool>,
params: ix.OpenBundledPositionParams
) {
return ix.openBundledPositionIx(program, params);
}
/**
* Close a bundled position in a Whirlpool.
*
* #### Special Errors
* `InvalidBundleIndex` - If the provided bundle index is out of bounds.
* `ClosePositionNotEmpty` - The provided position account is not empty.
*
* @param program - program object containing services required to generate the instruction
* @param params - CloseBundledPositionParams object
* @returns - Instruction to perform the action.
*/
public static closeBundledPositionIx(
program: Program<Whirlpool>,
params: ix.CloseBundledPositionParams
) {
return ix.closeBundledPositionIx(program, params);
}
}