@kamino-finance/kliquidity-sdk 7.0.2 → 7.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Kamino.d.ts.map +1 -1
- package/dist/Kamino.js +65 -64
- package/dist/Kamino.js.map +1 -1
- package/package.json +1 -1
- package/src/Kamino.ts +191 -64
package/package.json
CHANGED
package/src/Kamino.ts
CHANGED
|
@@ -2330,7 +2330,7 @@ export class Kamino {
|
|
|
2330
2330
|
if (positionPk.equals(PublicKey.default)) {
|
|
2331
2331
|
return { lowerPrice: ZERO, upperPrice: ZERO };
|
|
2332
2332
|
}
|
|
2333
|
-
const position = await Position.fetch(this._connection, positionPk);
|
|
2333
|
+
const position = await Position.fetch(this._connection, positionPk, this._orcaService.getWhirlpoolProgramId());
|
|
2334
2334
|
if (!position) {
|
|
2335
2335
|
return { lowerPrice: ZERO, upperPrice: ZERO };
|
|
2336
2336
|
}
|
|
@@ -2350,7 +2350,11 @@ export class Kamino {
|
|
|
2350
2350
|
if (positionPk.equals(PublicKey.default)) {
|
|
2351
2351
|
return { lowerPrice: ZERO, upperPrice: ZERO };
|
|
2352
2352
|
}
|
|
2353
|
-
const position = await PersonalPositionState.fetch(
|
|
2353
|
+
const position = await PersonalPositionState.fetch(
|
|
2354
|
+
this._connection,
|
|
2355
|
+
positionPk,
|
|
2356
|
+
this._raydiumService.getRaydiumProgramId()
|
|
2357
|
+
);
|
|
2354
2358
|
if (!position) {
|
|
2355
2359
|
return { lowerPrice: ZERO, upperPrice: ZERO };
|
|
2356
2360
|
}
|
|
@@ -2379,7 +2383,7 @@ export class Kamino {
|
|
|
2379
2383
|
if (positionPk.equals(PublicKey.default)) {
|
|
2380
2384
|
return { lowerPrice: ZERO, upperPrice: ZERO };
|
|
2381
2385
|
}
|
|
2382
|
-
const position = await PositionV2.fetch(this._connection, positionPk);
|
|
2386
|
+
const position = await PositionV2.fetch(this._connection, positionPk, this._meteoraService.getMeteoraProgramId());
|
|
2383
2387
|
if (!position) {
|
|
2384
2388
|
return { lowerPrice: ZERO, upperPrice: ZERO };
|
|
2385
2389
|
}
|
|
@@ -2429,7 +2433,9 @@ export class Kamino {
|
|
|
2429
2433
|
whirlpoolMap.set(whirlpools[0], whirlpool);
|
|
2430
2434
|
return whirlpoolMap;
|
|
2431
2435
|
}
|
|
2432
|
-
const fetched = await batchFetch(uniqueWhirlpools, (chunk) =>
|
|
2436
|
+
const fetched = await batchFetch(uniqueWhirlpools, (chunk) =>
|
|
2437
|
+
Whirlpool.fetchMultiple(this._connection, chunk, this._orcaService.getWhirlpoolProgramId())
|
|
2438
|
+
);
|
|
2433
2439
|
fetched.reduce((map: Record<string, Whirlpool | null>, whirlpool, i) => {
|
|
2434
2440
|
whirlpoolMap.set(uniqueWhirlpools[i], whirlpool);
|
|
2435
2441
|
map[uniqueWhirlpools[i].toBase58()] = whirlpool;
|
|
@@ -2444,7 +2450,9 @@ export class Kamino {
|
|
|
2444
2450
|
*/
|
|
2445
2451
|
getOrcaPositions = async (positions: PublicKey[]): Promise<(Position | null)[]> => {
|
|
2446
2452
|
const nonDefaults = positions.filter((value) => value.toBase58() !== PublicKey.default.toBase58());
|
|
2447
|
-
const fetched = await batchFetch(nonDefaults, (chunk) =>
|
|
2453
|
+
const fetched = await batchFetch(nonDefaults, (chunk) =>
|
|
2454
|
+
Position.fetchMultiple(this._connection, chunk, this._orcaService.getWhirlpoolProgramId())
|
|
2455
|
+
);
|
|
2448
2456
|
const fetchedMap: Record<string, Position | null> = fetched.reduce(
|
|
2449
2457
|
(map: Record<string, Position | null>, position, i) => {
|
|
2450
2458
|
map[nonDefaults[i].toBase58()] = position;
|
|
@@ -2462,7 +2470,7 @@ export class Kamino {
|
|
|
2462
2470
|
getRaydiumPositions = async (positions: PublicKey[]): Promise<(PersonalPositionState | null)[]> => {
|
|
2463
2471
|
const nonDefaults = positions.filter((value) => value.toBase58() !== PublicKey.default.toBase58());
|
|
2464
2472
|
const fetched = await batchFetch(nonDefaults, (chunk) =>
|
|
2465
|
-
PersonalPositionState.fetchMultiple(this._connection, chunk)
|
|
2473
|
+
PersonalPositionState.fetchMultiple(this._connection, chunk, this._raydiumService.getRaydiumProgramId())
|
|
2466
2474
|
);
|
|
2467
2475
|
const fetchedMap: Record<string, PersonalPositionState | null> = fetched.reduce(
|
|
2468
2476
|
(map: Record<string, PersonalPositionState | null>, position, i) => {
|
|
@@ -2476,7 +2484,9 @@ export class Kamino {
|
|
|
2476
2484
|
|
|
2477
2485
|
getMeteoraPositions = async (positions: PublicKey[]): Promise<(PositionV2 | null)[]> => {
|
|
2478
2486
|
const nonDefaults = positions.filter((value) => !value.equals(PublicKey.default));
|
|
2479
|
-
const fetched = await batchFetch(nonDefaults, (chunk) =>
|
|
2487
|
+
const fetched = await batchFetch(nonDefaults, (chunk) =>
|
|
2488
|
+
PositionV2.fetchMultiple(this._connection, chunk, this._meteoraService.getMeteoraProgramId())
|
|
2489
|
+
);
|
|
2480
2490
|
const fetchedMap: Record<string, PositionV2 | null> = fetched.reduce(
|
|
2481
2491
|
(map: Record<string, PositionV2 | null>, position, i) => {
|
|
2482
2492
|
map[nonDefaults[i].toBase58()] = position;
|
|
@@ -2491,7 +2501,8 @@ export class Kamino {
|
|
|
2491
2501
|
* Get whirlpool from public key
|
|
2492
2502
|
* @param whirlpool pubkey of the orca whirlpool
|
|
2493
2503
|
*/
|
|
2494
|
-
getWhirlpoolByAddress = (whirlpool: PublicKey) =>
|
|
2504
|
+
getWhirlpoolByAddress = (whirlpool: PublicKey) =>
|
|
2505
|
+
Whirlpool.fetch(this._connection, whirlpool, this._orcaService.getWhirlpoolProgramId());
|
|
2495
2506
|
|
|
2496
2507
|
/**
|
|
2497
2508
|
* Get a list of Raydium pools from public keys
|
|
@@ -2507,7 +2518,9 @@ export class Kamino {
|
|
|
2507
2518
|
const pool = await this.getRaydiumPoolByAddress(pools[0]);
|
|
2508
2519
|
poolsMap.set(pools[0], pool);
|
|
2509
2520
|
}
|
|
2510
|
-
const fetched = await batchFetch(uniquePools, (chunk) =>
|
|
2521
|
+
const fetched = await batchFetch(uniquePools, (chunk) =>
|
|
2522
|
+
PoolState.fetchMultiple(this._connection, chunk, this._raydiumService.getRaydiumProgramId())
|
|
2523
|
+
);
|
|
2511
2524
|
fetched.reduce((map, whirlpool, i) => {
|
|
2512
2525
|
poolsMap.set(uniquePools[i], whirlpool);
|
|
2513
2526
|
return map;
|
|
@@ -2525,7 +2538,9 @@ export class Kamino {
|
|
|
2525
2538
|
const pool = await this.getMeteoraPoolByAddress(pools[0]);
|
|
2526
2539
|
poolsMap.set(pools[0], pool);
|
|
2527
2540
|
}
|
|
2528
|
-
const fetched = await batchFetch(uniquePools, (chunk) =>
|
|
2541
|
+
const fetched = await batchFetch(uniquePools, (chunk) =>
|
|
2542
|
+
LbPair.fetchMultiple(this._connection, chunk, this._meteoraService.getMeteoraProgramId())
|
|
2543
|
+
);
|
|
2529
2544
|
fetched.reduce((map, whirlpool, i) => {
|
|
2530
2545
|
poolsMap.set(uniquePools[i], whirlpool);
|
|
2531
2546
|
return map;
|
|
@@ -2533,15 +2548,18 @@ export class Kamino {
|
|
|
2533
2548
|
return poolsMap;
|
|
2534
2549
|
};
|
|
2535
2550
|
|
|
2536
|
-
getRaydiumAmmConfig = (config: PublicKey) =>
|
|
2551
|
+
getRaydiumAmmConfig = (config: PublicKey) =>
|
|
2552
|
+
AmmConfig.fetch(this._connection, config, this._raydiumService.getRaydiumProgramId());
|
|
2537
2553
|
|
|
2538
2554
|
/**
|
|
2539
2555
|
* Get Raydium pool from public key
|
|
2540
2556
|
* @param pool pubkey of the orca whirlpool
|
|
2541
2557
|
*/
|
|
2542
|
-
getRaydiumPoolByAddress = (pool: PublicKey) =>
|
|
2558
|
+
getRaydiumPoolByAddress = (pool: PublicKey) =>
|
|
2559
|
+
PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
2543
2560
|
|
|
2544
|
-
getMeteoraPoolByAddress = (pool: PublicKey) =>
|
|
2561
|
+
getMeteoraPoolByAddress = (pool: PublicKey) =>
|
|
2562
|
+
LbPair.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
2545
2563
|
|
|
2546
2564
|
getEventAuthorityPDA = (dex: BN): PublicKey => {
|
|
2547
2565
|
if (dex.toNumber() == dexToNumber('ORCA') || dex.toNumber() == dexToNumber('RAYDIUM')) {
|
|
@@ -2644,7 +2662,11 @@ export class Kamino {
|
|
|
2644
2662
|
// add rewards vaults accounts to withdraw
|
|
2645
2663
|
const isRaydium = strategyState.strategy.strategyDex.toNumber() == dexToNumber('RAYDIUM');
|
|
2646
2664
|
if (isRaydium) {
|
|
2647
|
-
const raydiumPosition = await PersonalPositionState.fetch(
|
|
2665
|
+
const raydiumPosition = await PersonalPositionState.fetch(
|
|
2666
|
+
this._connection,
|
|
2667
|
+
strategyState.strategy.position,
|
|
2668
|
+
this._raydiumService.getRaydiumProgramId()
|
|
2669
|
+
);
|
|
2648
2670
|
if (!raydiumPosition) {
|
|
2649
2671
|
throw new Error('Position is not found');
|
|
2650
2672
|
}
|
|
@@ -2871,7 +2893,11 @@ export class Kamino {
|
|
|
2871
2893
|
getAllDepositAccounts = async (strategy: PublicKey | StrategyWithAddress, owner: PublicKey): Promise<PublicKey[]> => {
|
|
2872
2894
|
const strategyState = await this.getStrategyStateIfNotFetched(strategy);
|
|
2873
2895
|
|
|
2874
|
-
const globalConfig = await GlobalConfig.fetch(
|
|
2896
|
+
const globalConfig = await GlobalConfig.fetch(
|
|
2897
|
+
this._connection,
|
|
2898
|
+
strategyState.strategy.globalConfig,
|
|
2899
|
+
this._kaminoProgram.programId
|
|
2900
|
+
);
|
|
2875
2901
|
if (!globalConfig) {
|
|
2876
2902
|
throw Error(`Could not fetch global config with pubkey ${strategyState.strategy.globalConfig.toString()}`);
|
|
2877
2903
|
}
|
|
@@ -3752,21 +3778,25 @@ export class Kamino {
|
|
|
3752
3778
|
let tokenAMint = PublicKey.default;
|
|
3753
3779
|
let tokenBMint = PublicKey.default;
|
|
3754
3780
|
if (dex == 'ORCA') {
|
|
3755
|
-
const whirlpoolState = await Whirlpool.fetch(this._connection, pool);
|
|
3781
|
+
const whirlpoolState = await Whirlpool.fetch(this._connection, pool, this._orcaService.getWhirlpoolProgramId());
|
|
3756
3782
|
if (!whirlpoolState) {
|
|
3757
3783
|
throw Error(`Could not fetch whirlpool state with pubkey ${pool.toString()}`);
|
|
3758
3784
|
}
|
|
3759
3785
|
tokenAMint = whirlpoolState.tokenMintA;
|
|
3760
3786
|
tokenBMint = whirlpoolState.tokenMintB;
|
|
3761
3787
|
} else if (dex == 'RAYDIUM') {
|
|
3762
|
-
const raydiumPoolState = await PoolState.fetch(
|
|
3788
|
+
const raydiumPoolState = await PoolState.fetch(
|
|
3789
|
+
this._connection,
|
|
3790
|
+
pool,
|
|
3791
|
+
this._raydiumService.getRaydiumProgramId()
|
|
3792
|
+
);
|
|
3763
3793
|
if (!raydiumPoolState) {
|
|
3764
3794
|
throw Error(`Could not fetch Raydium pool state with pubkey ${pool.toString()}`);
|
|
3765
3795
|
}
|
|
3766
3796
|
tokenAMint = raydiumPoolState.tokenMint0;
|
|
3767
3797
|
tokenBMint = raydiumPoolState.tokenMint1;
|
|
3768
3798
|
} else if (dex == 'METEORA') {
|
|
3769
|
-
const meteoraPoolState = await LbPair.fetch(this._connection, pool);
|
|
3799
|
+
const meteoraPoolState = await LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
3770
3800
|
if (!meteoraPoolState) {
|
|
3771
3801
|
throw Error(`Could not fetch Meteora pool state with pubkey ${pool.toString()}`);
|
|
3772
3802
|
}
|
|
@@ -4120,8 +4150,12 @@ export class Kamino {
|
|
|
4120
4150
|
let rewardMint0 = PublicKey.default;
|
|
4121
4151
|
let rewardMint1 = PublicKey.default;
|
|
4122
4152
|
let rewardMint2 = PublicKey.default;
|
|
4123
|
-
if (strategyState.strategyDex.toNumber()
|
|
4124
|
-
const whirlpool = await Whirlpool.fetch(
|
|
4153
|
+
if (strategyState.strategyDex.toNumber() === dexToNumber('ORCA')) {
|
|
4154
|
+
const whirlpool = await Whirlpool.fetch(
|
|
4155
|
+
this._connection,
|
|
4156
|
+
strategyState.pool,
|
|
4157
|
+
this._orcaService.getWhirlpoolProgramId()
|
|
4158
|
+
);
|
|
4125
4159
|
if (!whirlpool) {
|
|
4126
4160
|
throw Error(`Could not fetch whirlpool state with pubkey ${strategyState.pool.toString()}`);
|
|
4127
4161
|
}
|
|
@@ -4132,10 +4166,14 @@ export class Kamino {
|
|
|
4132
4166
|
rewardMint0 = whirlpool.rewardInfos[0].mint;
|
|
4133
4167
|
rewardMint1 = whirlpool.rewardInfos[1].mint;
|
|
4134
4168
|
rewardMint2 = whirlpool.rewardInfos[2].mint;
|
|
4135
|
-
} else if (strategyState.strategyDex.toNumber()
|
|
4169
|
+
} else if (strategyState.strategyDex.toNumber() === dexToNumber('RAYDIUM')) {
|
|
4136
4170
|
programId = this._raydiumService.getRaydiumProgramId();
|
|
4137
4171
|
|
|
4138
|
-
const poolState = await PoolState.fetch(
|
|
4172
|
+
const poolState = await PoolState.fetch(
|
|
4173
|
+
this._connection,
|
|
4174
|
+
strategyState.pool,
|
|
4175
|
+
this._raydiumService.getRaydiumProgramId()
|
|
4176
|
+
);
|
|
4139
4177
|
if (!poolState) {
|
|
4140
4178
|
throw Error(`Could not fetch Raydium pool state with pubkey ${strategyState.pool.toString()}`);
|
|
4141
4179
|
}
|
|
@@ -4148,7 +4186,11 @@ export class Kamino {
|
|
|
4148
4186
|
} else if (strategyState.strategyDex.toNumber() == dexToNumber('METEORA')) {
|
|
4149
4187
|
programId = this._meteoraService.getMeteoraProgramId();
|
|
4150
4188
|
|
|
4151
|
-
const poolState = await LbPair.fetch(
|
|
4189
|
+
const poolState = await LbPair.fetch(
|
|
4190
|
+
this._connection,
|
|
4191
|
+
strategyState.pool,
|
|
4192
|
+
this._meteoraService.getMeteoraProgramId()
|
|
4193
|
+
);
|
|
4152
4194
|
if (!poolState) {
|
|
4153
4195
|
throw Error(`Could not fetch Meteora pool state with pubkey ${strategyState.pool.toString()}`);
|
|
4154
4196
|
}
|
|
@@ -4332,8 +4374,8 @@ export class Kamino {
|
|
|
4332
4374
|
};
|
|
4333
4375
|
|
|
4334
4376
|
private readMeteoraPosition = async (poolPk: PublicKey, positionPk: PublicKey): Promise<MeteoraPosition> => {
|
|
4335
|
-
const pool = await LbPair.fetch(this._connection, poolPk);
|
|
4336
|
-
const position = await PositionV2.fetch(this._connection, positionPk);
|
|
4377
|
+
const pool = await LbPair.fetch(this._connection, poolPk, this._meteoraService.getMeteoraProgramId());
|
|
4378
|
+
const position = await PositionV2.fetch(this._connection, positionPk, this._meteoraService.getMeteoraProgramId());
|
|
4337
4379
|
if (!pool || !position) {
|
|
4338
4380
|
return {
|
|
4339
4381
|
publicKey: positionPk,
|
|
@@ -4346,8 +4388,16 @@ export class Kamino {
|
|
|
4346
4388
|
poolPk,
|
|
4347
4389
|
position.lowerBinId
|
|
4348
4390
|
);
|
|
4349
|
-
const lowerBinArray = await BinArray.fetch(
|
|
4350
|
-
|
|
4391
|
+
const lowerBinArray = await BinArray.fetch(
|
|
4392
|
+
this._connection,
|
|
4393
|
+
lowerTickPk,
|
|
4394
|
+
this._meteoraService.getMeteoraProgramId()
|
|
4395
|
+
);
|
|
4396
|
+
const upperBinArray = await BinArray.fetch(
|
|
4397
|
+
this._connection,
|
|
4398
|
+
upperTickPk,
|
|
4399
|
+
this._meteoraService.getMeteoraProgramId()
|
|
4400
|
+
);
|
|
4351
4401
|
if (!lowerBinArray || !upperBinArray) {
|
|
4352
4402
|
return {
|
|
4353
4403
|
publicKey: positionPk,
|
|
@@ -4544,7 +4594,7 @@ export class Kamino {
|
|
|
4544
4594
|
eventAuthority: PublicKey,
|
|
4545
4595
|
status: StrategyStatusKind = new Uninitialized()
|
|
4546
4596
|
): Promise<TransactionInstruction> => {
|
|
4547
|
-
const whirlpool = await Whirlpool.fetch(this._connection, pool);
|
|
4597
|
+
const whirlpool = await Whirlpool.fetch(this._connection, pool, this._orcaService.getWhirlpoolProgramId());
|
|
4548
4598
|
if (!whirlpool) {
|
|
4549
4599
|
throw Error(`Could not fetch whirlpool state with pubkey ${pool.toString()}`);
|
|
4550
4600
|
}
|
|
@@ -4664,7 +4714,7 @@ export class Kamino {
|
|
|
4664
4714
|
strategyReward1Vault?: PublicKey,
|
|
4665
4715
|
strategyReward2Vault?: PublicKey
|
|
4666
4716
|
): Promise<TransactionInstruction> => {
|
|
4667
|
-
const poolState = await PoolState.fetch(this._connection, pool);
|
|
4717
|
+
const poolState = await PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
4668
4718
|
if (!poolState) {
|
|
4669
4719
|
throw Error(`Could not fetch Raydium pool state with pubkey ${pool.toString()}`);
|
|
4670
4720
|
}
|
|
@@ -4822,7 +4872,7 @@ export class Kamino {
|
|
|
4822
4872
|
eventAuthority: PublicKey,
|
|
4823
4873
|
status: StrategyStatusKind = new Uninitialized()
|
|
4824
4874
|
): Promise<TransactionInstruction> => {
|
|
4825
|
-
const lbPair = await LbPair.fetch(this._connection, pool);
|
|
4875
|
+
const lbPair = await LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
4826
4876
|
if (!lbPair) {
|
|
4827
4877
|
throw Error(`Could not fetch meteora lbpair state with pubkey ${pool.toString()}`);
|
|
4828
4878
|
}
|
|
@@ -5324,7 +5374,7 @@ export class Kamino {
|
|
|
5324
5374
|
let tokenMintB: PublicKey;
|
|
5325
5375
|
let tickSpacing: number;
|
|
5326
5376
|
if (dex == 'ORCA') {
|
|
5327
|
-
const whirlpoolState = await Whirlpool.fetch(this._connection, pool);
|
|
5377
|
+
const whirlpoolState = await Whirlpool.fetch(this._connection, pool, this._orcaService.getWhirlpoolProgramId());
|
|
5328
5378
|
if (!whirlpoolState) {
|
|
5329
5379
|
throw Error(`Could not fetch whirlpool state with pubkey ${pool.toString()}`);
|
|
5330
5380
|
}
|
|
@@ -5332,7 +5382,11 @@ export class Kamino {
|
|
|
5332
5382
|
tokenMintB = whirlpoolState.tokenMintB;
|
|
5333
5383
|
tickSpacing = whirlpoolState.tickSpacing;
|
|
5334
5384
|
} else if (dex == 'RAYDIUM') {
|
|
5335
|
-
const raydiumPoolState = await PoolState.fetch(
|
|
5385
|
+
const raydiumPoolState = await PoolState.fetch(
|
|
5386
|
+
this._connection,
|
|
5387
|
+
pool,
|
|
5388
|
+
this._raydiumService.getRaydiumProgramId()
|
|
5389
|
+
);
|
|
5336
5390
|
if (!raydiumPoolState) {
|
|
5337
5391
|
throw Error(`Could not fetch Raydium pool state with pubkey ${pool.toString()}`);
|
|
5338
5392
|
}
|
|
@@ -5340,7 +5394,7 @@ export class Kamino {
|
|
|
5340
5394
|
tokenMintB = raydiumPoolState.tokenMint1;
|
|
5341
5395
|
tickSpacing = raydiumPoolState.tickSpacing;
|
|
5342
5396
|
} else if (dex == 'METEORA') {
|
|
5343
|
-
const meteoraPoolState = await LbPair.fetch(this._connection, pool);
|
|
5397
|
+
const meteoraPoolState = await LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
5344
5398
|
if (!meteoraPoolState) {
|
|
5345
5399
|
throw Error(`Could not fetch Meteora pool state with pubkey ${pool.toString()}`);
|
|
5346
5400
|
}
|
|
@@ -5605,19 +5659,23 @@ export class Kamino {
|
|
|
5605
5659
|
|
|
5606
5660
|
async getPoolTickSpacing(dex: Dex, pool: PublicKey): Promise<number> {
|
|
5607
5661
|
if (dex == 'ORCA') {
|
|
5608
|
-
const whirlpoolState = await Whirlpool.fetch(this._connection, pool);
|
|
5662
|
+
const whirlpoolState = await Whirlpool.fetch(this._connection, pool, this._orcaService.getWhirlpoolProgramId());
|
|
5609
5663
|
if (!whirlpoolState) {
|
|
5610
5664
|
throw Error(`Could not fetch whirlpool state with pubkey ${pool.toString()}`);
|
|
5611
5665
|
}
|
|
5612
5666
|
return whirlpoolState.tickSpacing;
|
|
5613
5667
|
} else if (dex == 'RAYDIUM') {
|
|
5614
|
-
const raydiumPoolState = await PoolState.fetch(
|
|
5668
|
+
const raydiumPoolState = await PoolState.fetch(
|
|
5669
|
+
this._connection,
|
|
5670
|
+
pool,
|
|
5671
|
+
this._raydiumService.getRaydiumProgramId()
|
|
5672
|
+
);
|
|
5615
5673
|
if (!raydiumPoolState) {
|
|
5616
5674
|
throw Error(`Could not fetch Raydium pool state with pubkey ${pool.toString()}`);
|
|
5617
5675
|
}
|
|
5618
5676
|
return raydiumPoolState.tickSpacing;
|
|
5619
5677
|
} else if (dex == 'METEORA') {
|
|
5620
|
-
const meteoraPoolState = await LbPair.fetch(this._connection, pool);
|
|
5678
|
+
const meteoraPoolState = await LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
5621
5679
|
if (!meteoraPoolState) {
|
|
5622
5680
|
throw Error(`Could not fetch Meteora pool state with pubkey ${pool.toString()}`);
|
|
5623
5681
|
}
|
|
@@ -5940,7 +5998,7 @@ export class Kamino {
|
|
|
5940
5998
|
}
|
|
5941
5999
|
|
|
5942
6000
|
async getRaydiumPoolPrice(pool: PublicKey): Promise<Decimal> {
|
|
5943
|
-
const poolState = await PoolState.fetch(this._connection, pool);
|
|
6001
|
+
const poolState = await PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
5944
6002
|
if (!poolState) {
|
|
5945
6003
|
throw new Error(`Raydium poolState ${pool.toString()} is not found`);
|
|
5946
6004
|
}
|
|
@@ -5954,7 +6012,7 @@ export class Kamino {
|
|
|
5954
6012
|
}
|
|
5955
6013
|
|
|
5956
6014
|
async getMeteoraPoolPrice(pool: PublicKey): Promise<Decimal> {
|
|
5957
|
-
const poolState = await LbPair.fetch(this._connection, pool);
|
|
6015
|
+
const poolState = await LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
5958
6016
|
if (!poolState) {
|
|
5959
6017
|
throw new Error(`Meteora poolState ${pool.toString()} is not found`);
|
|
5960
6018
|
}
|
|
@@ -6673,7 +6731,7 @@ export class Kamino {
|
|
|
6673
6731
|
const tokenAAmountToDeposit = new Decimal(100.0);
|
|
6674
6732
|
|
|
6675
6733
|
if (dex == 'RAYDIUM') {
|
|
6676
|
-
const poolState = await PoolState.fetch(this._connection, pool);
|
|
6734
|
+
const poolState = await PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
6677
6735
|
if (!poolState) {
|
|
6678
6736
|
throw new Error(`Raydium poolState ${pool.toString()} is not found`);
|
|
6679
6737
|
}
|
|
@@ -6692,7 +6750,7 @@ export class Kamino {
|
|
|
6692
6750
|
const amountBDecimal = new Decimal(amountB.toString());
|
|
6693
6751
|
return [lamportsToNumberDecimal(amountADecimal, decimalsA), lamportsToNumberDecimal(amountBDecimal, decimalsB)];
|
|
6694
6752
|
} else if (dex == 'ORCA') {
|
|
6695
|
-
const whirlpoolState = await Whirlpool.fetch(this._connection, pool);
|
|
6753
|
+
const whirlpoolState = await Whirlpool.fetch(this._connection, pool, this._orcaService.getWhirlpoolProgramId());
|
|
6696
6754
|
if (!whirlpoolState) {
|
|
6697
6755
|
throw new Error(`Raydium poolState ${pool.toString()} is not found`);
|
|
6698
6756
|
}
|
|
@@ -6728,7 +6786,7 @@ export class Kamino {
|
|
|
6728
6786
|
lamportsToNumberDecimal(addLiqResult.estTokenB.toNumber(), decimalsB),
|
|
6729
6787
|
];
|
|
6730
6788
|
} else if (dex == 'METEORA') {
|
|
6731
|
-
const poolState = await LbPair.fetch(this._connection, pool);
|
|
6789
|
+
const poolState = await LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
6732
6790
|
if (!poolState) {
|
|
6733
6791
|
throw new Error(`Meteora poolState ${pool.toString()} is not found`);
|
|
6734
6792
|
}
|
|
@@ -6841,7 +6899,11 @@ export class Kamino {
|
|
|
6841
6899
|
const isRaydium = dexToNumber('RAYDIUM') === dex;
|
|
6842
6900
|
const isMeteora = dexToNumber('METEORA') === dex;
|
|
6843
6901
|
if (isOrca) {
|
|
6844
|
-
const whirlpool = await Whirlpool.fetch(
|
|
6902
|
+
const whirlpool = await Whirlpool.fetch(
|
|
6903
|
+
this._connection,
|
|
6904
|
+
strategyState.pool,
|
|
6905
|
+
this._orcaService.getWhirlpoolProgramId()
|
|
6906
|
+
);
|
|
6845
6907
|
if (!whirlpool) {
|
|
6846
6908
|
throw new Error(`Unable to get Orca whirlpool for pubkey ${strategyState.pool}`);
|
|
6847
6909
|
}
|
|
@@ -6937,8 +6999,16 @@ export class Kamino {
|
|
|
6937
6999
|
return [new Decimal(0), new Decimal(0)];
|
|
6938
7000
|
}
|
|
6939
7001
|
|
|
6940
|
-
const poolState = await PoolState.fetch(
|
|
6941
|
-
|
|
7002
|
+
const poolState = await PoolState.fetch(
|
|
7003
|
+
this._connection,
|
|
7004
|
+
strategyState.pool,
|
|
7005
|
+
this._raydiumService.getRaydiumProgramId()
|
|
7006
|
+
);
|
|
7007
|
+
const position = await PersonalPositionState.fetch(
|
|
7008
|
+
this._connection,
|
|
7009
|
+
strategyState.position,
|
|
7010
|
+
this._raydiumService.getRaydiumProgramId()
|
|
7011
|
+
);
|
|
6942
7012
|
|
|
6943
7013
|
if (!position) {
|
|
6944
7014
|
throw new Error(`position ${strategyState.position.toString()} is not found`);
|
|
@@ -7008,7 +7078,11 @@ export class Kamino {
|
|
|
7008
7078
|
return [new Decimal(0), new Decimal(0)];
|
|
7009
7079
|
}
|
|
7010
7080
|
|
|
7011
|
-
const poolState = await LbPair.fetch(
|
|
7081
|
+
const poolState = await LbPair.fetch(
|
|
7082
|
+
this._connection,
|
|
7083
|
+
strategyState.pool,
|
|
7084
|
+
this._meteoraService.getMeteoraProgramId()
|
|
7085
|
+
);
|
|
7012
7086
|
if (!poolState) {
|
|
7013
7087
|
throw new Error(`poolState ${strategyState.pool.toString()} is not found`);
|
|
7014
7088
|
}
|
|
@@ -7024,7 +7098,7 @@ export class Kamino {
|
|
|
7024
7098
|
binArrayIndex,
|
|
7025
7099
|
this._meteoraService.getMeteoraProgramId()
|
|
7026
7100
|
);
|
|
7027
|
-
const binArray = await BinArray.fetch(this._connection, binArrayPk);
|
|
7101
|
+
const binArray = await BinArray.fetch(this._connection, binArrayPk, this._meteoraService.getMeteoraProgramId());
|
|
7028
7102
|
if (!binArray) {
|
|
7029
7103
|
throw new Error(`bin array ${binArrayPk.toString()} is not found`);
|
|
7030
7104
|
}
|
|
@@ -7165,12 +7239,20 @@ export class Kamino {
|
|
|
7165
7239
|
): Promise<{ amountSlippageA: BN; amountSlippageB: BN }> {
|
|
7166
7240
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
7167
7241
|
|
|
7168
|
-
const whirlpool = await Whirlpool.fetch(
|
|
7242
|
+
const whirlpool = await Whirlpool.fetch(
|
|
7243
|
+
this._connection,
|
|
7244
|
+
strategyState.pool,
|
|
7245
|
+
this._orcaService.getWhirlpoolProgramId()
|
|
7246
|
+
);
|
|
7169
7247
|
if (!whirlpool) {
|
|
7170
7248
|
throw Error(`Could not fetch whirlpool state with pubkey ${strategyState.pool.toString()}`);
|
|
7171
7249
|
}
|
|
7172
7250
|
|
|
7173
|
-
const position = await Position.fetch(
|
|
7251
|
+
const position = await Position.fetch(
|
|
7252
|
+
this._connection,
|
|
7253
|
+
strategyState.position,
|
|
7254
|
+
this._orcaService.getWhirlpoolProgramId()
|
|
7255
|
+
);
|
|
7174
7256
|
if (!position) {
|
|
7175
7257
|
throw new Error(`Whirlpool position ${strategyState.position} does not exist`);
|
|
7176
7258
|
}
|
|
@@ -7197,8 +7279,16 @@ export class Kamino {
|
|
|
7197
7279
|
): Promise<{ amountSlippageA: BN; amountSlippageB: BN }> {
|
|
7198
7280
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
7199
7281
|
|
|
7200
|
-
const poolStatePromise = LbPair.fetch(
|
|
7201
|
-
|
|
7282
|
+
const poolStatePromise = LbPair.fetch(
|
|
7283
|
+
this._connection,
|
|
7284
|
+
strategyState.pool,
|
|
7285
|
+
this._meteoraService.getMeteoraProgramId()
|
|
7286
|
+
);
|
|
7287
|
+
const positionPromise = PositionV2.fetch(
|
|
7288
|
+
this._connection,
|
|
7289
|
+
strategyState.position,
|
|
7290
|
+
this._meteoraService.getMeteoraProgramId()
|
|
7291
|
+
);
|
|
7202
7292
|
|
|
7203
7293
|
const [poolState, _position] = await Promise.all([poolStatePromise, positionPromise]);
|
|
7204
7294
|
if (!poolState) {
|
|
@@ -7213,9 +7303,10 @@ export class Kamino {
|
|
|
7213
7303
|
): Promise<{ amountSlippageA: BN; amountSlippageB: BN }> {
|
|
7214
7304
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
7215
7305
|
|
|
7216
|
-
const
|
|
7217
|
-
|
|
7218
|
-
|
|
7306
|
+
const [poolState, _position] = await Promise.all([
|
|
7307
|
+
LbPair.fetch(this._connection, strategyState.pool, this._meteoraService.getMeteoraProgramId()),
|
|
7308
|
+
PositionV2.fetch(this._connection, strategyState.position, this._meteoraService.getMeteoraProgramId()),
|
|
7309
|
+
]);
|
|
7219
7310
|
|
|
7220
7311
|
if (!poolState) {
|
|
7221
7312
|
throw Error(`Could not fetch lb pair state with pubkey ${strategyState.pool.toString()}`);
|
|
@@ -7230,12 +7321,20 @@ export class Kamino {
|
|
|
7230
7321
|
): Promise<{ amountSlippageA: BN; amountSlippageB: BN }> => {
|
|
7231
7322
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
7232
7323
|
|
|
7233
|
-
const whirlpool = await Whirlpool.fetch(
|
|
7324
|
+
const whirlpool = await Whirlpool.fetch(
|
|
7325
|
+
this._connection,
|
|
7326
|
+
strategyState.pool,
|
|
7327
|
+
this._orcaService.getWhirlpoolProgramId()
|
|
7328
|
+
);
|
|
7234
7329
|
if (!whirlpool) {
|
|
7235
7330
|
throw Error(`Could not fetch whirlpool state with pubkey ${strategyState.pool.toString()}`);
|
|
7236
7331
|
}
|
|
7237
7332
|
|
|
7238
|
-
const position = await Position.fetch(
|
|
7333
|
+
const position = await Position.fetch(
|
|
7334
|
+
this._connection,
|
|
7335
|
+
strategyState.position,
|
|
7336
|
+
this._orcaService.getWhirlpoolProgramId()
|
|
7337
|
+
);
|
|
7239
7338
|
if (!position) {
|
|
7240
7339
|
throw new Error(`Whirlpool position ${strategyState.position} does not exist`);
|
|
7241
7340
|
}
|
|
@@ -7263,8 +7362,16 @@ export class Kamino {
|
|
|
7263
7362
|
): Promise<{ amountSlippageA: BN; amountSlippageB: BN }> => {
|
|
7264
7363
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
7265
7364
|
|
|
7266
|
-
const poolState = await PoolState.fetch(
|
|
7267
|
-
|
|
7365
|
+
const poolState = await PoolState.fetch(
|
|
7366
|
+
this._connection,
|
|
7367
|
+
strategyState.pool,
|
|
7368
|
+
this._raydiumService.getRaydiumProgramId()
|
|
7369
|
+
);
|
|
7370
|
+
const positionState = await PersonalPositionState.fetch(
|
|
7371
|
+
this._connection,
|
|
7372
|
+
strategyState.position,
|
|
7373
|
+
this._raydiumService.getRaydiumProgramId()
|
|
7374
|
+
);
|
|
7268
7375
|
|
|
7269
7376
|
if (!positionState) {
|
|
7270
7377
|
throw new Error(`Raydium position ${strategyState.position.toString()} could not be found.`);
|
|
@@ -7296,8 +7403,16 @@ export class Kamino {
|
|
|
7296
7403
|
): Promise<{ amountSlippageA: BN; amountSlippageB: BN }> => {
|
|
7297
7404
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
7298
7405
|
|
|
7299
|
-
const poolState = await PoolState.fetch(
|
|
7300
|
-
|
|
7406
|
+
const poolState = await PoolState.fetch(
|
|
7407
|
+
this._connection,
|
|
7408
|
+
strategyState.pool,
|
|
7409
|
+
this._raydiumService.getRaydiumProgramId()
|
|
7410
|
+
);
|
|
7411
|
+
const positionState = await PersonalPositionState.fetch(
|
|
7412
|
+
this._connection,
|
|
7413
|
+
strategyState.position,
|
|
7414
|
+
this._raydiumService.getRaydiumProgramId()
|
|
7415
|
+
);
|
|
7301
7416
|
|
|
7302
7417
|
if (!positionState) {
|
|
7303
7418
|
throw new Error(`Raydium position ${strategyState.position.toString()} could not be found.`);
|
|
@@ -7435,7 +7550,11 @@ export class Kamino {
|
|
|
7435
7550
|
const collateralInfos = await this.getCollateralInfo(globalConfig.tokenInfos);
|
|
7436
7551
|
const result: [TransactionInstruction, Keypair][] = [];
|
|
7437
7552
|
if (strategyState.strategyDex.toNumber() == dexToNumber('ORCA')) {
|
|
7438
|
-
const whirlpool = await Whirlpool.fetch(
|
|
7553
|
+
const whirlpool = await Whirlpool.fetch(
|
|
7554
|
+
this._connection,
|
|
7555
|
+
strategyState.pool,
|
|
7556
|
+
this._orcaService.getWhirlpoolProgramId()
|
|
7557
|
+
);
|
|
7439
7558
|
if (!whirlpool) {
|
|
7440
7559
|
throw Error(`Could not fetch whirlpool state with pubkey ${strategyState.pool.toString()}`);
|
|
7441
7560
|
}
|
|
@@ -7473,7 +7592,11 @@ export class Kamino {
|
|
|
7473
7592
|
}
|
|
7474
7593
|
return result;
|
|
7475
7594
|
} else if (strategyState.strategyDex.toNumber() == dexToNumber('RAYDIUM')) {
|
|
7476
|
-
const poolState = await PoolState.fetch(
|
|
7595
|
+
const poolState = await PoolState.fetch(
|
|
7596
|
+
this._connection,
|
|
7597
|
+
strategyState.pool,
|
|
7598
|
+
this._raydiumService.getRaydiumProgramId()
|
|
7599
|
+
);
|
|
7477
7600
|
if (!poolState) {
|
|
7478
7601
|
throw new Error(`Could not fetch whirlpool state with pubkey ${strategyState.pool.toString()}`);
|
|
7479
7602
|
}
|
|
@@ -7511,7 +7634,11 @@ export class Kamino {
|
|
|
7511
7634
|
}
|
|
7512
7635
|
return result;
|
|
7513
7636
|
} else if (strategyState.strategyDex.toNumber() == dexToNumber('METEORA')) {
|
|
7514
|
-
const poolState = await LbPair.fetch(
|
|
7637
|
+
const poolState = await LbPair.fetch(
|
|
7638
|
+
this._connection,
|
|
7639
|
+
strategyState.pool,
|
|
7640
|
+
this._meteoraService.getMeteoraProgramId()
|
|
7641
|
+
);
|
|
7515
7642
|
if (!poolState) {
|
|
7516
7643
|
throw new Error(`Could not fetch meteora state with pubkey ${strategyState.pool.toString()}`);
|
|
7517
7644
|
}
|
|
@@ -7577,7 +7704,7 @@ export class Kamino {
|
|
|
7577
7704
|
poolAddress,
|
|
7578
7705
|
startTickIndex
|
|
7579
7706
|
);
|
|
7580
|
-
const tick = await TickArray.fetch(this._connection, startTickIndexPk);
|
|
7707
|
+
const tick = await TickArray.fetch(this._connection, startTickIndexPk, this._orcaService.getWhirlpoolProgramId());
|
|
7581
7708
|
// initialize tick if it doesn't exist
|
|
7582
7709
|
if (!tick) {
|
|
7583
7710
|
const initTickArrayArgs: InitializeTickArrayArgs = {
|
|
@@ -7617,7 +7744,7 @@ export class Kamino {
|
|
|
7617
7744
|
binArrayIndex,
|
|
7618
7745
|
this._meteoraService.getMeteoraProgramId()
|
|
7619
7746
|
);
|
|
7620
|
-
const tick = await TickArray.fetch(this._connection, startTickIndexPk);
|
|
7747
|
+
const tick = await TickArray.fetch(this._connection, startTickIndexPk, this._meteoraService.getMeteoraProgramId());
|
|
7621
7748
|
// initialize tick if it doesn't exist
|
|
7622
7749
|
if (!tick) {
|
|
7623
7750
|
const initTickArrayArgs: InitializeBinArrayArgs = {
|