@kamino-finance/kliquidity-sdk 7.0.1 → 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 +91 -92
- package/dist/Kamino.js.map +1 -1
- package/dist/services/MeteoraService.d.ts +3 -2
- package/dist/services/MeteoraService.d.ts.map +1 -1
- package/dist/services/MeteoraService.js +6 -3
- package/dist/services/MeteoraService.js.map +1 -1
- package/dist/services/OrcaService.d.ts +3 -4
- package/dist/services/OrcaService.d.ts.map +1 -1
- package/dist/services/OrcaService.js +6 -8
- package/dist/services/OrcaService.js.map +1 -1
- package/dist/services/RaydiumService.d.ts +3 -3
- package/dist/services/RaydiumService.d.ts.map +1 -1
- package/dist/services/RaydiumService.js +7 -4
- package/dist/services/RaydiumService.js.map +1 -1
- package/package.json +1 -1
- package/src/Kamino.ts +235 -95
- package/src/services/MeteoraService.ts +7 -3
- package/src/services/OrcaService.ts +8 -14
- package/src/services/RaydiumService.ts +8 -5
package/dist/Kamino.js
CHANGED
|
@@ -100,17 +100,15 @@ class Kamino {
|
|
|
100
100
|
if (whirlpoolProgramId) {
|
|
101
101
|
(0, programId_2.setWhirlpoolsProgramId)(whirlpoolProgramId);
|
|
102
102
|
}
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
(0, programId_3.setRaydiumProgramId)(raydiumProgramId);
|
|
106
|
-
}
|
|
103
|
+
if (raydiumProgramId) {
|
|
104
|
+
(0, programId_3.setRaydiumProgramId)(raydiumProgramId);
|
|
107
105
|
}
|
|
108
106
|
if (meteoraProgramId) {
|
|
109
107
|
(0, programId_4.setMeteoraProgramId)(meteoraProgramId);
|
|
110
108
|
}
|
|
111
|
-
this._orcaService = new services_1.OrcaService(connection, cluster,
|
|
112
|
-
this._raydiumService = new services_1.RaydiumService(connection,
|
|
113
|
-
this._meteoraService = new MeteoraService_1.MeteoraService(connection,
|
|
109
|
+
this._orcaService = new services_1.OrcaService(connection, cluster, whirlpoolProgramId);
|
|
110
|
+
this._raydiumService = new services_1.RaydiumService(connection, raydiumProgramId);
|
|
111
|
+
this._meteoraService = new MeteoraService_1.MeteoraService(connection, meteoraProgramId);
|
|
114
112
|
}
|
|
115
113
|
getConnection = () => this._connection;
|
|
116
114
|
getProgramID = () => this._kaminoProgramId;
|
|
@@ -1474,7 +1472,7 @@ class Kamino {
|
|
|
1474
1472
|
if (positionPk.equals(web3_js_1.PublicKey.default)) {
|
|
1475
1473
|
return { lowerPrice: utils_1.ZERO, upperPrice: utils_1.ZERO };
|
|
1476
1474
|
}
|
|
1477
|
-
const position = await whirlpools_client_1.Position.fetch(this._connection, positionPk);
|
|
1475
|
+
const position = await whirlpools_client_1.Position.fetch(this._connection, positionPk, this._orcaService.getWhirlpoolProgramId());
|
|
1478
1476
|
if (!position) {
|
|
1479
1477
|
return { lowerPrice: utils_1.ZERO, upperPrice: utils_1.ZERO };
|
|
1480
1478
|
}
|
|
@@ -1487,7 +1485,7 @@ class Kamino {
|
|
|
1487
1485
|
if (positionPk.equals(web3_js_1.PublicKey.default)) {
|
|
1488
1486
|
return { lowerPrice: utils_1.ZERO, upperPrice: utils_1.ZERO };
|
|
1489
1487
|
}
|
|
1490
|
-
const position = await raydium_client_1.PersonalPositionState.fetch(this._connection, positionPk);
|
|
1488
|
+
const position = await raydium_client_1.PersonalPositionState.fetch(this._connection, positionPk, this._raydiumService.getRaydiumProgramId());
|
|
1491
1489
|
if (!position) {
|
|
1492
1490
|
return { lowerPrice: utils_1.ZERO, upperPrice: utils_1.ZERO };
|
|
1493
1491
|
}
|
|
@@ -1500,7 +1498,7 @@ class Kamino {
|
|
|
1500
1498
|
if (positionPk.equals(web3_js_1.PublicKey.default)) {
|
|
1501
1499
|
return { lowerPrice: utils_1.ZERO, upperPrice: utils_1.ZERO };
|
|
1502
1500
|
}
|
|
1503
|
-
const position = await accounts_2.PositionV2.fetch(this._connection, positionPk);
|
|
1501
|
+
const position = await accounts_2.PositionV2.fetch(this._connection, positionPk, this._meteoraService.getMeteoraProgramId());
|
|
1504
1502
|
if (!position) {
|
|
1505
1503
|
return { lowerPrice: utils_1.ZERO, upperPrice: utils_1.ZERO };
|
|
1506
1504
|
}
|
|
@@ -1544,7 +1542,7 @@ class Kamino {
|
|
|
1544
1542
|
whirlpoolMap.set(whirlpools[0], whirlpool);
|
|
1545
1543
|
return whirlpoolMap;
|
|
1546
1544
|
}
|
|
1547
|
-
const fetched = await (0, utils_1.batchFetch)(uniqueWhirlpools, (chunk) => whirlpools_client_1.Whirlpool.fetchMultiple(this._connection, chunk));
|
|
1545
|
+
const fetched = await (0, utils_1.batchFetch)(uniqueWhirlpools, (chunk) => whirlpools_client_1.Whirlpool.fetchMultiple(this._connection, chunk, this._orcaService.getWhirlpoolProgramId()));
|
|
1548
1546
|
fetched.reduce((map, whirlpool, i) => {
|
|
1549
1547
|
whirlpoolMap.set(uniqueWhirlpools[i], whirlpool);
|
|
1550
1548
|
map[uniqueWhirlpools[i].toBase58()] = whirlpool;
|
|
@@ -1558,7 +1556,7 @@ class Kamino {
|
|
|
1558
1556
|
*/
|
|
1559
1557
|
getOrcaPositions = async (positions) => {
|
|
1560
1558
|
const nonDefaults = positions.filter((value) => value.toBase58() !== web3_js_1.PublicKey.default.toBase58());
|
|
1561
|
-
const fetched = await (0, utils_1.batchFetch)(nonDefaults, (chunk) => whirlpools_client_1.Position.fetchMultiple(this._connection, chunk));
|
|
1559
|
+
const fetched = await (0, utils_1.batchFetch)(nonDefaults, (chunk) => whirlpools_client_1.Position.fetchMultiple(this._connection, chunk, this._orcaService.getWhirlpoolProgramId()));
|
|
1562
1560
|
const fetchedMap = fetched.reduce((map, position, i) => {
|
|
1563
1561
|
map[nonDefaults[i].toBase58()] = position;
|
|
1564
1562
|
return map;
|
|
@@ -1571,7 +1569,7 @@ class Kamino {
|
|
|
1571
1569
|
*/
|
|
1572
1570
|
getRaydiumPositions = async (positions) => {
|
|
1573
1571
|
const nonDefaults = positions.filter((value) => value.toBase58() !== web3_js_1.PublicKey.default.toBase58());
|
|
1574
|
-
const fetched = await (0, utils_1.batchFetch)(nonDefaults, (chunk) => raydium_client_1.PersonalPositionState.fetchMultiple(this._connection, chunk));
|
|
1572
|
+
const fetched = await (0, utils_1.batchFetch)(nonDefaults, (chunk) => raydium_client_1.PersonalPositionState.fetchMultiple(this._connection, chunk, this._raydiumService.getRaydiumProgramId()));
|
|
1575
1573
|
const fetchedMap = fetched.reduce((map, position, i) => {
|
|
1576
1574
|
map[nonDefaults[i].toBase58()] = position;
|
|
1577
1575
|
return map;
|
|
@@ -1580,7 +1578,7 @@ class Kamino {
|
|
|
1580
1578
|
};
|
|
1581
1579
|
getMeteoraPositions = async (positions) => {
|
|
1582
1580
|
const nonDefaults = positions.filter((value) => !value.equals(web3_js_1.PublicKey.default));
|
|
1583
|
-
const fetched = await (0, utils_1.batchFetch)(nonDefaults, (chunk) => accounts_2.PositionV2.fetchMultiple(this._connection, chunk));
|
|
1581
|
+
const fetched = await (0, utils_1.batchFetch)(nonDefaults, (chunk) => accounts_2.PositionV2.fetchMultiple(this._connection, chunk, this._meteoraService.getMeteoraProgramId()));
|
|
1584
1582
|
const fetchedMap = fetched.reduce((map, position, i) => {
|
|
1585
1583
|
map[nonDefaults[i].toBase58()] = position;
|
|
1586
1584
|
return map;
|
|
@@ -1591,7 +1589,7 @@ class Kamino {
|
|
|
1591
1589
|
* Get whirlpool from public key
|
|
1592
1590
|
* @param whirlpool pubkey of the orca whirlpool
|
|
1593
1591
|
*/
|
|
1594
|
-
getWhirlpoolByAddress = (whirlpool) => whirlpools_client_1.Whirlpool.fetch(this._connection, whirlpool);
|
|
1592
|
+
getWhirlpoolByAddress = (whirlpool) => whirlpools_client_1.Whirlpool.fetch(this._connection, whirlpool, this._orcaService.getWhirlpoolProgramId());
|
|
1595
1593
|
/**
|
|
1596
1594
|
* Get a list of Raydium pools from public keys
|
|
1597
1595
|
* @param pools
|
|
@@ -1605,7 +1603,7 @@ class Kamino {
|
|
|
1605
1603
|
const pool = await this.getRaydiumPoolByAddress(pools[0]);
|
|
1606
1604
|
poolsMap.set(pools[0], pool);
|
|
1607
1605
|
}
|
|
1608
|
-
const fetched = await (0, utils_1.batchFetch)(uniquePools, (chunk) => raydium_client_1.PoolState.fetchMultiple(this._connection, chunk));
|
|
1606
|
+
const fetched = await (0, utils_1.batchFetch)(uniquePools, (chunk) => raydium_client_1.PoolState.fetchMultiple(this._connection, chunk, this._raydiumService.getRaydiumProgramId()));
|
|
1609
1607
|
fetched.reduce((map, whirlpool, i) => {
|
|
1610
1608
|
poolsMap.set(uniquePools[i], whirlpool);
|
|
1611
1609
|
return map;
|
|
@@ -1621,26 +1619,26 @@ class Kamino {
|
|
|
1621
1619
|
const pool = await this.getMeteoraPoolByAddress(pools[0]);
|
|
1622
1620
|
poolsMap.set(pools[0], pool);
|
|
1623
1621
|
}
|
|
1624
|
-
const fetched = await (0, utils_1.batchFetch)(uniquePools, (chunk) => accounts_2.LbPair.fetchMultiple(this._connection, chunk));
|
|
1622
|
+
const fetched = await (0, utils_1.batchFetch)(uniquePools, (chunk) => accounts_2.LbPair.fetchMultiple(this._connection, chunk, this._meteoraService.getMeteoraProgramId()));
|
|
1625
1623
|
fetched.reduce((map, whirlpool, i) => {
|
|
1626
1624
|
poolsMap.set(uniquePools[i], whirlpool);
|
|
1627
1625
|
return map;
|
|
1628
1626
|
}, {});
|
|
1629
1627
|
return poolsMap;
|
|
1630
1628
|
};
|
|
1631
|
-
getRaydiumAmmConfig = (config) => raydium_client_1.AmmConfig.fetch(this._connection, config);
|
|
1629
|
+
getRaydiumAmmConfig = (config) => raydium_client_1.AmmConfig.fetch(this._connection, config, this._raydiumService.getRaydiumProgramId());
|
|
1632
1630
|
/**
|
|
1633
1631
|
* Get Raydium pool from public key
|
|
1634
1632
|
* @param pool pubkey of the orca whirlpool
|
|
1635
1633
|
*/
|
|
1636
|
-
getRaydiumPoolByAddress = (pool) => raydium_client_1.PoolState.fetch(this._connection, pool);
|
|
1637
|
-
getMeteoraPoolByAddress = (pool) => accounts_2.LbPair.fetch(this._connection, pool);
|
|
1634
|
+
getRaydiumPoolByAddress = (pool) => raydium_client_1.PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
1635
|
+
getMeteoraPoolByAddress = (pool) => accounts_2.LbPair.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
1638
1636
|
getEventAuthorityPDA = (dex) => {
|
|
1639
1637
|
if (dex.toNumber() == (0, utils_1.dexToNumber)('ORCA') || dex.toNumber() == (0, utils_1.dexToNumber)('RAYDIUM')) {
|
|
1640
1638
|
return this._kaminoProgramId;
|
|
1641
1639
|
}
|
|
1642
1640
|
if (dex.toNumber() == (0, utils_1.dexToNumber)('METEORA')) {
|
|
1643
|
-
const [key, _] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('__event_authority')],
|
|
1641
|
+
const [key, _] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('__event_authority')], this._meteoraService.getMeteoraProgramId());
|
|
1644
1642
|
return key;
|
|
1645
1643
|
}
|
|
1646
1644
|
throw new Error('Invalid dex');
|
|
@@ -1704,7 +1702,7 @@ class Kamino {
|
|
|
1704
1702
|
// add rewards vaults accounts to withdraw
|
|
1705
1703
|
const isRaydium = strategyState.strategy.strategyDex.toNumber() == (0, utils_1.dexToNumber)('RAYDIUM');
|
|
1706
1704
|
if (isRaydium) {
|
|
1707
|
-
const raydiumPosition = await raydium_client_1.PersonalPositionState.fetch(this._connection, strategyState.strategy.position);
|
|
1705
|
+
const raydiumPosition = await raydium_client_1.PersonalPositionState.fetch(this._connection, strategyState.strategy.position, this._raydiumService.getRaydiumProgramId());
|
|
1708
1706
|
if (!raydiumPosition) {
|
|
1709
1707
|
throw new Error('Position is not found');
|
|
1710
1708
|
}
|
|
@@ -1869,7 +1867,7 @@ class Kamino {
|
|
|
1869
1867
|
*/
|
|
1870
1868
|
getAllDepositAccounts = async (strategy, owner) => {
|
|
1871
1869
|
const strategyState = await this.getStrategyStateIfNotFetched(strategy);
|
|
1872
|
-
const globalConfig = await accounts_1.GlobalConfig.fetch(this._connection, strategyState.strategy.globalConfig);
|
|
1870
|
+
const globalConfig = await accounts_1.GlobalConfig.fetch(this._connection, strategyState.strategy.globalConfig, this._kaminoProgram.programId);
|
|
1873
1871
|
if (!globalConfig) {
|
|
1874
1872
|
throw Error(`Could not fetch global config with pubkey ${strategyState.strategy.globalConfig.toString()}`);
|
|
1875
1873
|
}
|
|
@@ -2360,7 +2358,7 @@ class Kamino {
|
|
|
2360
2358
|
let tokenAMint = web3_js_1.PublicKey.default;
|
|
2361
2359
|
let tokenBMint = web3_js_1.PublicKey.default;
|
|
2362
2360
|
if (dex == 'ORCA') {
|
|
2363
|
-
const whirlpoolState = await whirlpools_client_1.Whirlpool.fetch(this._connection, pool);
|
|
2361
|
+
const whirlpoolState = await whirlpools_client_1.Whirlpool.fetch(this._connection, pool, this._orcaService.getWhirlpoolProgramId());
|
|
2364
2362
|
if (!whirlpoolState) {
|
|
2365
2363
|
throw Error(`Could not fetch whirlpool state with pubkey ${pool.toString()}`);
|
|
2366
2364
|
}
|
|
@@ -2368,7 +2366,7 @@ class Kamino {
|
|
|
2368
2366
|
tokenBMint = whirlpoolState.tokenMintB;
|
|
2369
2367
|
}
|
|
2370
2368
|
else if (dex == 'RAYDIUM') {
|
|
2371
|
-
const raydiumPoolState = await raydium_client_1.PoolState.fetch(this._connection, pool);
|
|
2369
|
+
const raydiumPoolState = await raydium_client_1.PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
2372
2370
|
if (!raydiumPoolState) {
|
|
2373
2371
|
throw Error(`Could not fetch Raydium pool state with pubkey ${pool.toString()}`);
|
|
2374
2372
|
}
|
|
@@ -2376,7 +2374,7 @@ class Kamino {
|
|
|
2376
2374
|
tokenBMint = raydiumPoolState.tokenMint1;
|
|
2377
2375
|
}
|
|
2378
2376
|
else if (dex == 'METEORA') {
|
|
2379
|
-
const meteoraPoolState = await accounts_2.LbPair.fetch(this._connection, pool);
|
|
2377
|
+
const meteoraPoolState = await accounts_2.LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
2380
2378
|
if (!meteoraPoolState) {
|
|
2381
2379
|
throw Error(`Could not fetch Meteora pool state with pubkey ${pool.toString()}`);
|
|
2382
2380
|
}
|
|
@@ -2627,15 +2625,15 @@ class Kamino {
|
|
|
2627
2625
|
const { address: strategyPubkey, strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
2628
2626
|
const eventAuthority = this.getEventAuthorityPDA(strategyState.strategyDex);
|
|
2629
2627
|
const { treasuryFeeTokenAVault, treasuryFeeTokenBVault, treasuryFeeVaultAuthority } = this.getTreasuryFeeVaultPDAs(strategyState.tokenAMint, strategyState.tokenBMint);
|
|
2630
|
-
let programId =
|
|
2628
|
+
let programId = this._orcaService.getWhirlpoolProgramId();
|
|
2631
2629
|
let poolRewardVault0 = web3_js_1.PublicKey.default;
|
|
2632
2630
|
let poolRewardVault1 = web3_js_1.PublicKey.default;
|
|
2633
2631
|
let poolRewardVault2 = web3_js_1.PublicKey.default;
|
|
2634
2632
|
let rewardMint0 = web3_js_1.PublicKey.default;
|
|
2635
2633
|
let rewardMint1 = web3_js_1.PublicKey.default;
|
|
2636
2634
|
let rewardMint2 = web3_js_1.PublicKey.default;
|
|
2637
|
-
if (strategyState.strategyDex.toNumber()
|
|
2638
|
-
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, strategyState.pool);
|
|
2635
|
+
if (strategyState.strategyDex.toNumber() === (0, utils_1.dexToNumber)('ORCA')) {
|
|
2636
|
+
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, strategyState.pool, this._orcaService.getWhirlpoolProgramId());
|
|
2639
2637
|
if (!whirlpool) {
|
|
2640
2638
|
throw Error(`Could not fetch whirlpool state with pubkey ${strategyState.pool.toString()}`);
|
|
2641
2639
|
}
|
|
@@ -2646,9 +2644,9 @@ class Kamino {
|
|
|
2646
2644
|
rewardMint1 = whirlpool.rewardInfos[1].mint;
|
|
2647
2645
|
rewardMint2 = whirlpool.rewardInfos[2].mint;
|
|
2648
2646
|
}
|
|
2649
|
-
else if (strategyState.strategyDex.toNumber()
|
|
2650
|
-
programId =
|
|
2651
|
-
const poolState = await raydium_client_1.PoolState.fetch(this._connection, strategyState.pool);
|
|
2647
|
+
else if (strategyState.strategyDex.toNumber() === (0, utils_1.dexToNumber)('RAYDIUM')) {
|
|
2648
|
+
programId = this._raydiumService.getRaydiumProgramId();
|
|
2649
|
+
const poolState = await raydium_client_1.PoolState.fetch(this._connection, strategyState.pool, this._raydiumService.getRaydiumProgramId());
|
|
2652
2650
|
if (!poolState) {
|
|
2653
2651
|
throw Error(`Could not fetch Raydium pool state with pubkey ${strategyState.pool.toString()}`);
|
|
2654
2652
|
}
|
|
@@ -2660,8 +2658,8 @@ class Kamino {
|
|
|
2660
2658
|
rewardMint2 = poolState.rewardInfos[2].tokenMint;
|
|
2661
2659
|
}
|
|
2662
2660
|
else if (strategyState.strategyDex.toNumber() == (0, utils_1.dexToNumber)('METEORA')) {
|
|
2663
|
-
programId =
|
|
2664
|
-
const poolState = await accounts_2.LbPair.fetch(this._connection, strategyState.pool);
|
|
2661
|
+
programId = this._meteoraService.getMeteoraProgramId();
|
|
2662
|
+
const poolState = await accounts_2.LbPair.fetch(this._connection, strategyState.pool, this._meteoraService.getMeteoraProgramId());
|
|
2665
2663
|
if (!poolState) {
|
|
2666
2664
|
throw Error(`Could not fetch Meteora pool state with pubkey ${strategyState.pool.toString()}`);
|
|
2667
2665
|
}
|
|
@@ -2721,7 +2719,7 @@ class Kamino {
|
|
|
2721
2719
|
}
|
|
2722
2720
|
}
|
|
2723
2721
|
if (strategyState.strategyDex.toNumber() == (0, utils_1.dexToNumber)('RAYDIUM')) {
|
|
2724
|
-
const [poolTickArrayBitmap, _poolTickArrayBitmapBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('pool_tick_array_bitmap_extension'), strategyState.pool.toBuffer()],
|
|
2722
|
+
const [poolTickArrayBitmap, _poolTickArrayBitmapBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('pool_tick_array_bitmap_extension'), strategyState.pool.toBuffer()], this._raydiumService.getRaydiumProgramId());
|
|
2725
2723
|
ixn.keys.push({ pubkey: poolTickArrayBitmap, isSigner: false, isWritable: true });
|
|
2726
2724
|
}
|
|
2727
2725
|
return ixn;
|
|
@@ -2731,7 +2729,7 @@ class Kamino {
|
|
|
2731
2729
|
* @param positionMint mint account of the position
|
|
2732
2730
|
*/
|
|
2733
2731
|
getMetadataProgramAddressesOrca = (positionMint) => {
|
|
2734
|
-
const [position, positionBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('position'), positionMint.toBuffer()],
|
|
2732
|
+
const [position, positionBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('position'), positionMint.toBuffer()], this._orcaService.getWhirlpoolProgramId());
|
|
2735
2733
|
const [positionMetadata, positionMetadataBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('metadata'), constants_1.METADATA_PROGRAM_ID.toBuffer(), positionMint.toBuffer()], constants_1.METADATA_PROGRAM_ID);
|
|
2736
2734
|
return {
|
|
2737
2735
|
position,
|
|
@@ -2741,8 +2739,8 @@ class Kamino {
|
|
|
2741
2739
|
};
|
|
2742
2740
|
};
|
|
2743
2741
|
getMetadataProgramAddressesRaydium = (positionMint, pool, tickLowerIndex, tickUpperIndex) => {
|
|
2744
|
-
const { publicKey: protocolPosition, nonce: protocolPositionBump } = (0, raydium_sdk_1.getPdaProtocolPositionAddress)(
|
|
2745
|
-
const [position, positionBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('position'), positionMint.toBuffer()],
|
|
2742
|
+
const { publicKey: protocolPosition, nonce: protocolPositionBump } = (0, raydium_sdk_1.getPdaProtocolPositionAddress)(this._raydiumService.getRaydiumProgramId(), pool, tickLowerIndex, tickUpperIndex);
|
|
2743
|
+
const [position, positionBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('position'), positionMint.toBuffer()], this._raydiumService.getRaydiumProgramId());
|
|
2746
2744
|
const [positionMetadata, positionMetadataBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('metadata'), constants_1.METADATA_PROGRAM_ID.toBuffer(), positionMint.toBuffer()], constants_1.METADATA_PROGRAM_ID);
|
|
2747
2745
|
return {
|
|
2748
2746
|
position,
|
|
@@ -2756,8 +2754,8 @@ class Kamino {
|
|
|
2756
2754
|
getStartEndTicketIndexProgramAddressesOrca = (whirlpool, whirlpoolState, tickLowerIndex, tickUpperIndex) => {
|
|
2757
2755
|
const startTickIndex = (0, whirlpool_sdk_1.getStartTickIndex)(tickLowerIndex, whirlpoolState.tickSpacing, 0);
|
|
2758
2756
|
const endTickIndex = (0, whirlpool_sdk_1.getStartTickIndex)(tickUpperIndex, whirlpoolState.tickSpacing, 0);
|
|
2759
|
-
const [lowerTickPubkey, lowerTickBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('tick_array'), whirlpool.toBuffer(), Buffer.from(startTickIndex.toString())],
|
|
2760
|
-
const [upperTickPubkey, upperTickBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('tick_array'), whirlpool.toBuffer(), Buffer.from(endTickIndex.toString())],
|
|
2757
|
+
const [lowerTickPubkey, lowerTickBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('tick_array'), whirlpool.toBuffer(), Buffer.from(startTickIndex.toString())], this._orcaService.getWhirlpoolProgramId());
|
|
2758
|
+
const [upperTickPubkey, upperTickBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('tick_array'), whirlpool.toBuffer(), Buffer.from(endTickIndex.toString())], this._orcaService.getWhirlpoolProgramId());
|
|
2761
2759
|
return {
|
|
2762
2760
|
lowerTick: lowerTickPubkey,
|
|
2763
2761
|
lowerTickBump,
|
|
@@ -2768,8 +2766,8 @@ class Kamino {
|
|
|
2768
2766
|
getStartEndTicketIndexProgramAddressesRaydium = (pool, poolState, tickLowerIndex, tickUpperIndex) => {
|
|
2769
2767
|
const startTickIndex = raydium_sdk_1.TickUtils.getTickArrayStartIndexByTick(tickLowerIndex, poolState.tickSpacing);
|
|
2770
2768
|
const endTickIndex = raydium_sdk_1.TickUtils.getTickArrayStartIndexByTick(tickUpperIndex, poolState.tickSpacing);
|
|
2771
|
-
const [lowerTickPubkey, lowerTickBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('tick_array'), pool.toBuffer(), (0, raydium_sdk_1.i32ToBytes)(startTickIndex)],
|
|
2772
|
-
const [upperTickPubkey, upperTickBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('tick_array'), pool.toBuffer(), (0, raydium_sdk_1.i32ToBytes)(endTickIndex)],
|
|
2769
|
+
const [lowerTickPubkey, lowerTickBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('tick_array'), pool.toBuffer(), (0, raydium_sdk_1.i32ToBytes)(startTickIndex)], this._raydiumService.getRaydiumProgramId());
|
|
2770
|
+
const [upperTickPubkey, upperTickBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('tick_array'), pool.toBuffer(), (0, raydium_sdk_1.i32ToBytes)(endTickIndex)], this._raydiumService.getRaydiumProgramId());
|
|
2773
2771
|
return {
|
|
2774
2772
|
lowerTick: lowerTickPubkey,
|
|
2775
2773
|
lowerTickBump,
|
|
@@ -2778,8 +2776,8 @@ class Kamino {
|
|
|
2778
2776
|
};
|
|
2779
2777
|
};
|
|
2780
2778
|
readMeteoraPosition = async (poolPk, positionPk) => {
|
|
2781
|
-
const pool = await accounts_2.LbPair.fetch(this._connection, poolPk);
|
|
2782
|
-
const position = await accounts_2.PositionV2.fetch(this._connection, positionPk);
|
|
2779
|
+
const pool = await accounts_2.LbPair.fetch(this._connection, poolPk, this._meteoraService.getMeteoraProgramId());
|
|
2780
|
+
const position = await accounts_2.PositionV2.fetch(this._connection, positionPk, this._meteoraService.getMeteoraProgramId());
|
|
2783
2781
|
if (!pool || !position) {
|
|
2784
2782
|
return {
|
|
2785
2783
|
publicKey: positionPk,
|
|
@@ -2788,8 +2786,8 @@ class Kamino {
|
|
|
2788
2786
|
};
|
|
2789
2787
|
}
|
|
2790
2788
|
const { lowerTick: lowerTickPk, upperTick: upperTickPk } = this.getStartEndTicketIndexProgramAddressesMeteora(poolPk, position.lowerBinId);
|
|
2791
|
-
const lowerBinArray = await accounts_2.BinArray.fetch(this._connection, lowerTickPk);
|
|
2792
|
-
const upperBinArray = await accounts_2.BinArray.fetch(this._connection, upperTickPk);
|
|
2789
|
+
const lowerBinArray = await accounts_2.BinArray.fetch(this._connection, lowerTickPk, this._meteoraService.getMeteoraProgramId());
|
|
2790
|
+
const upperBinArray = await accounts_2.BinArray.fetch(this._connection, upperTickPk, this._meteoraService.getMeteoraProgramId());
|
|
2793
2791
|
if (!lowerBinArray || !upperBinArray) {
|
|
2794
2792
|
return {
|
|
2795
2793
|
publicKey: positionPk,
|
|
@@ -2823,7 +2821,7 @@ class Kamino {
|
|
|
2823
2821
|
};
|
|
2824
2822
|
};
|
|
2825
2823
|
getStartEndTicketIndexProgramAddressesMeteora = (pool, tickLowerIndex) => {
|
|
2826
|
-
const meteoraProgramId =
|
|
2824
|
+
const meteoraProgramId = this._meteoraService.getMeteoraProgramId();
|
|
2827
2825
|
const lowerBinArrayIndex = (0, meteora_1.binIdToBinArrayIndex)(new bn_js_1.default(tickLowerIndex));
|
|
2828
2826
|
const [lowerTick, lowerTickBump] = (0, meteora_1.deriveBinArray)(pool, lowerBinArrayIndex, meteoraProgramId);
|
|
2829
2827
|
const upperBinArrayIndex = lowerBinArrayIndex.add(new bn_js_1.default(1));
|
|
@@ -2883,7 +2881,7 @@ class Kamino {
|
|
|
2883
2881
|
* @param status strategy status
|
|
2884
2882
|
*/
|
|
2885
2883
|
openPositionOrca = async (adminAuthority, strategy, baseVaultAuthority, pool, positionMint, priceLower, priceUpper, tokenAVault, tokenBVault, tokenAMint, tokenBMint, tokenATokenProgram, tokenBTokenProgram, oldPositionOrBaseVaultAuthority, oldPositionMintOrBaseVaultAuthority, oldPositionTokenAccountOrBaseVaultAuthority, oldTickArrayLowerOrBaseVaultAuthority, oldTickArrayUpperOrBaseVaultAuthority, eventAuthority, status = new StrategyStatus_1.Uninitialized()) => {
|
|
2886
|
-
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, pool);
|
|
2884
|
+
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, pool, this._orcaService.getWhirlpoolProgramId());
|
|
2887
2885
|
if (!whirlpool) {
|
|
2888
2886
|
throw Error(`Could not fetch whirlpool state with pubkey ${pool.toString()}`);
|
|
2889
2887
|
}
|
|
@@ -2920,7 +2918,7 @@ class Kamino {
|
|
|
2920
2918
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2921
2919
|
tokenProgram2022: pubkeys_1.TOKEN_2022_PROGRAM_ID,
|
|
2922
2920
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
2923
|
-
poolProgram:
|
|
2921
|
+
poolProgram: this._orcaService.getWhirlpoolProgramId(),
|
|
2924
2922
|
oldPositionOrBaseVaultAuthority: isRebalancing ? oldPositionOrBaseVaultAuthority : baseVaultAuthority,
|
|
2925
2923
|
oldPositionMintOrBaseVaultAuthority: isRebalancing ? oldPositionMintOrBaseVaultAuthority : positionMint,
|
|
2926
2924
|
oldPositionTokenAccountOrBaseVaultAuthority: isRebalancing
|
|
@@ -2957,7 +2955,7 @@ class Kamino {
|
|
|
2957
2955
|
* @param status strategy status
|
|
2958
2956
|
*/
|
|
2959
2957
|
openPositionRaydium = async (adminAuthority, strategy, baseVaultAuthority, pool, positionMint, priceLower, priceUpper, tokenAVault, tokenBVault, tokenAMint, tokenBMint, tokenATokenProgram, tokenBTokenProgram, oldTickArrayLowerOrBaseVaultAuthority, oldTickArrayUpperOrBaseVaultAuthority, oldPositionOrBaseVaultAuthority, oldPositionMintOrBaseVaultAuthority, oldPositionTokenAccountOrBaseVaultAuthority, oldProtocolPositionOrBaseVaultAuthority, eventAuthority, status = new StrategyStatus_1.Uninitialized(), strategyRewardOVault, strategyReward1Vault, strategyReward2Vault) => {
|
|
2960
|
-
const poolState = await raydium_client_1.PoolState.fetch(this._connection, pool);
|
|
2958
|
+
const poolState = await raydium_client_1.PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
2961
2959
|
if (!poolState) {
|
|
2962
2960
|
throw Error(`Could not fetch Raydium pool state with pubkey ${pool.toString()}`);
|
|
2963
2961
|
}
|
|
@@ -2994,7 +2992,7 @@ class Kamino {
|
|
|
2994
2992
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
2995
2993
|
tokenProgram2022: pubkeys_1.TOKEN_2022_PROGRAM_ID,
|
|
2996
2994
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
2997
|
-
poolProgram:
|
|
2995
|
+
poolProgram: this._raydiumService.getRaydiumProgramId(),
|
|
2998
2996
|
oldPositionOrBaseVaultAuthority: isRebalancing ? oldPositionOrBaseVaultAuthority : baseVaultAuthority,
|
|
2999
2997
|
oldPositionMintOrBaseVaultAuthority: isRebalancing ? oldPositionMintOrBaseVaultAuthority : positionMint,
|
|
3000
2998
|
oldPositionTokenAccountOrBaseVaultAuthority: isRebalancing
|
|
@@ -3017,7 +3015,7 @@ class Kamino {
|
|
|
3017
3015
|
tokenBTokenProgram: (0, utils_1.keyOrDefault)(tokenBTokenProgram, spl_token_1.TOKEN_PROGRAM_ID),
|
|
3018
3016
|
memoProgram: pubkeys_1.MEMO_PROGRAM_ID,
|
|
3019
3017
|
};
|
|
3020
|
-
const [poolTickArrayBitmap, _poolTickArrayBitmapBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('pool_tick_array_bitmap_extension'), pool.toBuffer()],
|
|
3018
|
+
const [poolTickArrayBitmap, _poolTickArrayBitmapBump] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('pool_tick_array_bitmap_extension'), pool.toBuffer()], this._raydiumService.getRaydiumProgramId());
|
|
3021
3019
|
const ix = (0, instructions_1.openLiquidityPosition)(args, accounts);
|
|
3022
3020
|
ix.keys = ix.keys.concat([
|
|
3023
3021
|
{ pubkey: protocolPosition, isSigner: false, isWritable: true },
|
|
@@ -3059,7 +3057,7 @@ class Kamino {
|
|
|
3059
3057
|
* @param status strategy status
|
|
3060
3058
|
*/
|
|
3061
3059
|
openPositionMeteora = async (adminAuthority, strategy, baseVaultAuthority, pool, position, priceLower, priceUpper, tokenAVault, tokenBVault, tokenAMint, tokenBMint, tokenATokenProgram, tokenBTokenProgram, oldPositionOrBaseVaultAuthority, oldPositionMintOrBaseVaultAuthority, oldPositionTokenAccountOrBaseVaultAuthority, oldTickArrayLowerOrBaseVaultAuthority, oldTickArrayUpperOrBaseVaultAuthority, eventAuthority, status = new StrategyStatus_1.Uninitialized()) => {
|
|
3062
|
-
const lbPair = await accounts_2.LbPair.fetch(this._connection, pool);
|
|
3060
|
+
const lbPair = await accounts_2.LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
3063
3061
|
if (!lbPair) {
|
|
3064
3062
|
throw Error(`Could not fetch meteora lbpair state with pubkey ${pool.toString()}`);
|
|
3065
3063
|
}
|
|
@@ -3096,7 +3094,7 @@ class Kamino {
|
|
|
3096
3094
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
3097
3095
|
tokenProgram2022: pubkeys_1.TOKEN_2022_PROGRAM_ID,
|
|
3098
3096
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
3099
|
-
poolProgram:
|
|
3097
|
+
poolProgram: this._orcaService.getWhirlpoolProgramId(),
|
|
3100
3098
|
oldPositionOrBaseVaultAuthority: isRebalancing ? oldPositionOrBaseVaultAuthority : baseVaultAuthority,
|
|
3101
3099
|
oldPositionMintOrBaseVaultAuthority: isRebalancing ? oldPositionMintOrBaseVaultAuthority : positionMint,
|
|
3102
3100
|
oldPositionTokenAccountOrBaseVaultAuthority: isRebalancing
|
|
@@ -3429,7 +3427,7 @@ class Kamino {
|
|
|
3429
3427
|
let tokenMintB;
|
|
3430
3428
|
let tickSpacing;
|
|
3431
3429
|
if (dex == 'ORCA') {
|
|
3432
|
-
const whirlpoolState = await whirlpools_client_1.Whirlpool.fetch(this._connection, pool);
|
|
3430
|
+
const whirlpoolState = await whirlpools_client_1.Whirlpool.fetch(this._connection, pool, this._orcaService.getWhirlpoolProgramId());
|
|
3433
3431
|
if (!whirlpoolState) {
|
|
3434
3432
|
throw Error(`Could not fetch whirlpool state with pubkey ${pool.toString()}`);
|
|
3435
3433
|
}
|
|
@@ -3438,7 +3436,7 @@ class Kamino {
|
|
|
3438
3436
|
tickSpacing = whirlpoolState.tickSpacing;
|
|
3439
3437
|
}
|
|
3440
3438
|
else if (dex == 'RAYDIUM') {
|
|
3441
|
-
const raydiumPoolState = await raydium_client_1.PoolState.fetch(this._connection, pool);
|
|
3439
|
+
const raydiumPoolState = await raydium_client_1.PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
3442
3440
|
if (!raydiumPoolState) {
|
|
3443
3441
|
throw Error(`Could not fetch Raydium pool state with pubkey ${pool.toString()}`);
|
|
3444
3442
|
}
|
|
@@ -3447,7 +3445,7 @@ class Kamino {
|
|
|
3447
3445
|
tickSpacing = raydiumPoolState.tickSpacing;
|
|
3448
3446
|
}
|
|
3449
3447
|
else if (dex == 'METEORA') {
|
|
3450
|
-
const meteoraPoolState = await accounts_2.LbPair.fetch(this._connection, pool);
|
|
3448
|
+
const meteoraPoolState = await accounts_2.LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
3451
3449
|
if (!meteoraPoolState) {
|
|
3452
3450
|
throw Error(`Could not fetch Meteora pool state with pubkey ${pool.toString()}`);
|
|
3453
3451
|
}
|
|
@@ -3576,21 +3574,21 @@ class Kamino {
|
|
|
3576
3574
|
}
|
|
3577
3575
|
async getPoolTickSpacing(dex, pool) {
|
|
3578
3576
|
if (dex == 'ORCA') {
|
|
3579
|
-
const whirlpoolState = await whirlpools_client_1.Whirlpool.fetch(this._connection, pool);
|
|
3577
|
+
const whirlpoolState = await whirlpools_client_1.Whirlpool.fetch(this._connection, pool, this._orcaService.getWhirlpoolProgramId());
|
|
3580
3578
|
if (!whirlpoolState) {
|
|
3581
3579
|
throw Error(`Could not fetch whirlpool state with pubkey ${pool.toString()}`);
|
|
3582
3580
|
}
|
|
3583
3581
|
return whirlpoolState.tickSpacing;
|
|
3584
3582
|
}
|
|
3585
3583
|
else if (dex == 'RAYDIUM') {
|
|
3586
|
-
const raydiumPoolState = await raydium_client_1.PoolState.fetch(this._connection, pool);
|
|
3584
|
+
const raydiumPoolState = await raydium_client_1.PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
3587
3585
|
if (!raydiumPoolState) {
|
|
3588
3586
|
throw Error(`Could not fetch Raydium pool state with pubkey ${pool.toString()}`);
|
|
3589
3587
|
}
|
|
3590
3588
|
return raydiumPoolState.tickSpacing;
|
|
3591
3589
|
}
|
|
3592
3590
|
else if (dex == 'METEORA') {
|
|
3593
|
-
const meteoraPoolState = await accounts_2.LbPair.fetch(this._connection, pool);
|
|
3591
|
+
const meteoraPoolState = await accounts_2.LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
3594
3592
|
if (!meteoraPoolState) {
|
|
3595
3593
|
throw Error(`Could not fetch Meteora pool state with pubkey ${pool.toString()}`);
|
|
3596
3594
|
}
|
|
@@ -3844,7 +3842,7 @@ class Kamino {
|
|
|
3844
3842
|
return poolData.price;
|
|
3845
3843
|
}
|
|
3846
3844
|
async getRaydiumPoolPrice(pool) {
|
|
3847
|
-
const poolState = await raydium_client_1.PoolState.fetch(this._connection, pool);
|
|
3845
|
+
const poolState = await raydium_client_1.PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
3848
3846
|
if (!poolState) {
|
|
3849
3847
|
throw new Error(`Raydium poolState ${pool.toString()} is not found`);
|
|
3850
3848
|
}
|
|
@@ -3852,7 +3850,7 @@ class Kamino {
|
|
|
3852
3850
|
return price;
|
|
3853
3851
|
}
|
|
3854
3852
|
async getMeteoraPoolPrice(pool) {
|
|
3855
|
-
const poolState = await accounts_2.LbPair.fetch(this._connection, pool);
|
|
3853
|
+
const poolState = await accounts_2.LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
3856
3854
|
if (!poolState) {
|
|
3857
3855
|
throw new Error(`Meteora poolState ${pool.toString()} is not found`);
|
|
3858
3856
|
}
|
|
@@ -4373,7 +4371,7 @@ class Kamino {
|
|
|
4373
4371
|
calculateAmountsDistributionWithPriceRange = async (dex, pool, lowerPrice, upperPrice) => {
|
|
4374
4372
|
const tokenAAmountToDeposit = new decimal_js_1.default(100.0);
|
|
4375
4373
|
if (dex == 'RAYDIUM') {
|
|
4376
|
-
const poolState = await raydium_client_1.PoolState.fetch(this._connection, pool);
|
|
4374
|
+
const poolState = await raydium_client_1.PoolState.fetch(this._connection, pool, this._raydiumService.getRaydiumProgramId());
|
|
4377
4375
|
if (!poolState) {
|
|
4378
4376
|
throw new Error(`Raydium poolState ${pool.toString()} is not found`);
|
|
4379
4377
|
}
|
|
@@ -4385,7 +4383,7 @@ class Kamino {
|
|
|
4385
4383
|
return [(0, utils_1.lamportsToNumberDecimal)(amountADecimal, decimalsA), (0, utils_1.lamportsToNumberDecimal)(amountBDecimal, decimalsB)];
|
|
4386
4384
|
}
|
|
4387
4385
|
else if (dex == 'ORCA') {
|
|
4388
|
-
const whirlpoolState = await whirlpools_client_1.Whirlpool.fetch(this._connection, pool);
|
|
4386
|
+
const whirlpoolState = await whirlpools_client_1.Whirlpool.fetch(this._connection, pool, this._orcaService.getWhirlpoolProgramId());
|
|
4389
4387
|
if (!whirlpoolState) {
|
|
4390
4388
|
throw new Error(`Raydium poolState ${pool.toString()} is not found`);
|
|
4391
4389
|
}
|
|
@@ -4413,7 +4411,7 @@ class Kamino {
|
|
|
4413
4411
|
];
|
|
4414
4412
|
}
|
|
4415
4413
|
else if (dex == 'METEORA') {
|
|
4416
|
-
const poolState = await accounts_2.LbPair.fetch(this._connection, pool);
|
|
4414
|
+
const poolState = await accounts_2.LbPair.fetch(this._connection, pool, this._meteoraService.getMeteoraProgramId());
|
|
4417
4415
|
if (!poolState) {
|
|
4418
4416
|
throw new Error(`Meteora poolState ${pool.toString()} is not found`);
|
|
4419
4417
|
}
|
|
@@ -4501,7 +4499,7 @@ class Kamino {
|
|
|
4501
4499
|
const isRaydium = (0, utils_1.dexToNumber)('RAYDIUM') === dex;
|
|
4502
4500
|
const isMeteora = (0, utils_1.dexToNumber)('METEORA') === dex;
|
|
4503
4501
|
if (isOrca) {
|
|
4504
|
-
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, strategyState.pool);
|
|
4502
|
+
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, strategyState.pool, this._orcaService.getWhirlpoolProgramId());
|
|
4505
4503
|
if (!whirlpool) {
|
|
4506
4504
|
throw new Error(`Unable to get Orca whirlpool for pubkey ${strategyState.pool}`);
|
|
4507
4505
|
}
|
|
@@ -4529,7 +4527,7 @@ class Kamino {
|
|
|
4529
4527
|
return [new decimal_js_1.default(0), new decimal_js_1.default(0)];
|
|
4530
4528
|
}
|
|
4531
4529
|
// Given A in ATA, calc how much A and B
|
|
4532
|
-
const accessor = new orca_dal_1.OrcaDAL(whirlpoolConfig,
|
|
4530
|
+
const accessor = new orca_dal_1.OrcaDAL(whirlpoolConfig, this._orcaService.getWhirlpoolProgramId(), this._connection);
|
|
4533
4531
|
const orcaPosition = new orca_position_1.OrcaPosition(accessor);
|
|
4534
4532
|
const defaultSlippagePercentage = whirlpool_sdk_1.Percentage.fromFraction(1, 1000); // 0.1%
|
|
4535
4533
|
const primaryTokenAmount = tokenAAmount || tokenBAmount;
|
|
@@ -4569,8 +4567,8 @@ class Kamino {
|
|
|
4569
4567
|
if (!tokenAAmount && !tokenBAmount) {
|
|
4570
4568
|
return [new decimal_js_1.default(0), new decimal_js_1.default(0)];
|
|
4571
4569
|
}
|
|
4572
|
-
const poolState = await raydium_client_1.PoolState.fetch(this._connection, strategyState.pool);
|
|
4573
|
-
const position = await raydium_client_1.PersonalPositionState.fetch(this._connection, strategyState.position);
|
|
4570
|
+
const poolState = await raydium_client_1.PoolState.fetch(this._connection, strategyState.pool, this._raydiumService.getRaydiumProgramId());
|
|
4571
|
+
const position = await raydium_client_1.PersonalPositionState.fetch(this._connection, strategyState.position, this._raydiumService.getRaydiumProgramId());
|
|
4574
4572
|
if (!position) {
|
|
4575
4573
|
throw new Error(`position ${strategyState.position.toString()} is not found`);
|
|
4576
4574
|
}
|
|
@@ -4606,7 +4604,7 @@ class Kamino {
|
|
|
4606
4604
|
if (!tokenAAmount && !tokenBAmount) {
|
|
4607
4605
|
return [new decimal_js_1.default(0), new decimal_js_1.default(0)];
|
|
4608
4606
|
}
|
|
4609
|
-
const poolState = await accounts_2.LbPair.fetch(this._connection, strategyState.pool);
|
|
4607
|
+
const poolState = await accounts_2.LbPair.fetch(this._connection, strategyState.pool, this._meteoraService.getMeteoraProgramId());
|
|
4610
4608
|
if (!poolState) {
|
|
4611
4609
|
throw new Error(`poolState ${strategyState.pool.toString()} is not found`);
|
|
4612
4610
|
}
|
|
@@ -4617,8 +4615,8 @@ class Kamino {
|
|
|
4617
4615
|
}
|
|
4618
4616
|
else {
|
|
4619
4617
|
const binArrayIndex = (0, meteora_1.binIdToBinArrayIndex)(new bn_js_1.default(poolState.activeId));
|
|
4620
|
-
const [binArrayPk] = (0, meteora_1.deriveBinArray)(strategyState.pool, binArrayIndex,
|
|
4621
|
-
const binArray = await accounts_2.BinArray.fetch(this._connection, binArrayPk);
|
|
4618
|
+
const [binArrayPk] = (0, meteora_1.deriveBinArray)(strategyState.pool, binArrayIndex, this._meteoraService.getMeteoraProgramId());
|
|
4619
|
+
const binArray = await accounts_2.BinArray.fetch(this._connection, binArrayPk, this._meteoraService.getMeteoraProgramId());
|
|
4622
4620
|
if (!binArray) {
|
|
4623
4621
|
throw new Error(`bin array ${binArrayPk.toString()} is not found`);
|
|
4624
4622
|
}
|
|
@@ -4731,11 +4729,11 @@ class Kamino {
|
|
|
4731
4729
|
}
|
|
4732
4730
|
async getDepositRatioFromAOrca(strategy, amountA) {
|
|
4733
4731
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
4734
|
-
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, strategyState.pool);
|
|
4732
|
+
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, strategyState.pool, this._orcaService.getWhirlpoolProgramId());
|
|
4735
4733
|
if (!whirlpool) {
|
|
4736
4734
|
throw Error(`Could not fetch whirlpool state with pubkey ${strategyState.pool.toString()}`);
|
|
4737
4735
|
}
|
|
4738
|
-
const position = await whirlpools_client_1.Position.fetch(this._connection, strategyState.position);
|
|
4736
|
+
const position = await whirlpools_client_1.Position.fetch(this._connection, strategyState.position, this._orcaService.getWhirlpoolProgramId());
|
|
4739
4737
|
if (!position) {
|
|
4740
4738
|
throw new Error(`Whirlpool position ${strategyState.position} does not exist`);
|
|
4741
4739
|
}
|
|
@@ -4755,8 +4753,8 @@ class Kamino {
|
|
|
4755
4753
|
}
|
|
4756
4754
|
async getDepositRatioFromAMeteora(strategy) {
|
|
4757
4755
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
4758
|
-
const poolStatePromise = accounts_2.LbPair.fetch(this._connection, strategyState.pool);
|
|
4759
|
-
const positionPromise = accounts_2.PositionV2.fetch(this._connection, strategyState.position);
|
|
4756
|
+
const poolStatePromise = accounts_2.LbPair.fetch(this._connection, strategyState.pool, this._meteoraService.getMeteoraProgramId());
|
|
4757
|
+
const positionPromise = accounts_2.PositionV2.fetch(this._connection, strategyState.position, this._meteoraService.getMeteoraProgramId());
|
|
4760
4758
|
const [poolState, _position] = await Promise.all([poolStatePromise, positionPromise]);
|
|
4761
4759
|
if (!poolState) {
|
|
4762
4760
|
throw Error(`Could not fetch lb pair state with pubkey ${strategyState.pool.toString()}`);
|
|
@@ -4765,9 +4763,10 @@ class Kamino {
|
|
|
4765
4763
|
}
|
|
4766
4764
|
async getDepositRatioFromBMeteora(strategy) {
|
|
4767
4765
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
4768
|
-
const
|
|
4769
|
-
|
|
4770
|
-
|
|
4766
|
+
const [poolState, _position] = await Promise.all([
|
|
4767
|
+
accounts_2.LbPair.fetch(this._connection, strategyState.pool, this._meteoraService.getMeteoraProgramId()),
|
|
4768
|
+
accounts_2.PositionV2.fetch(this._connection, strategyState.position, this._meteoraService.getMeteoraProgramId()),
|
|
4769
|
+
]);
|
|
4771
4770
|
if (!poolState) {
|
|
4772
4771
|
throw Error(`Could not fetch lb pair state with pubkey ${strategyState.pool.toString()}`);
|
|
4773
4772
|
}
|
|
@@ -4775,11 +4774,11 @@ class Kamino {
|
|
|
4775
4774
|
}
|
|
4776
4775
|
getDepositRatioFromBOrca = async (strategy, amountB) => {
|
|
4777
4776
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
4778
|
-
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, strategyState.pool);
|
|
4777
|
+
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, strategyState.pool, this._orcaService.getWhirlpoolProgramId());
|
|
4779
4778
|
if (!whirlpool) {
|
|
4780
4779
|
throw Error(`Could not fetch whirlpool state with pubkey ${strategyState.pool.toString()}`);
|
|
4781
4780
|
}
|
|
4782
|
-
const position = await whirlpools_client_1.Position.fetch(this._connection, strategyState.position);
|
|
4781
|
+
const position = await whirlpools_client_1.Position.fetch(this._connection, strategyState.position, this._orcaService.getWhirlpoolProgramId());
|
|
4783
4782
|
if (!position) {
|
|
4784
4783
|
throw new Error(`Whirlpool position ${strategyState.position} does not exist`);
|
|
4785
4784
|
}
|
|
@@ -4799,8 +4798,8 @@ class Kamino {
|
|
|
4799
4798
|
};
|
|
4800
4799
|
getDepositRatioFromARaydium = async (strategy, amountA) => {
|
|
4801
4800
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
4802
|
-
const poolState = await raydium_client_1.PoolState.fetch(this._connection, strategyState.pool);
|
|
4803
|
-
const positionState = await raydium_client_1.PersonalPositionState.fetch(this._connection, strategyState.position);
|
|
4801
|
+
const poolState = await raydium_client_1.PoolState.fetch(this._connection, strategyState.pool, this._raydiumService.getRaydiumProgramId());
|
|
4802
|
+
const positionState = await raydium_client_1.PersonalPositionState.fetch(this._connection, strategyState.position, this._raydiumService.getRaydiumProgramId());
|
|
4804
4803
|
if (!positionState) {
|
|
4805
4804
|
throw new Error(`Raydium position ${strategyState.position.toString()} could not be found.`);
|
|
4806
4805
|
}
|
|
@@ -4815,8 +4814,8 @@ class Kamino {
|
|
|
4815
4814
|
};
|
|
4816
4815
|
getDepositRatioFromBRaydium = async (strategy, amountB) => {
|
|
4817
4816
|
const { strategy: strategyState } = await this.getStrategyStateIfNotFetched(strategy);
|
|
4818
|
-
const poolState = await raydium_client_1.PoolState.fetch(this._connection, strategyState.pool);
|
|
4819
|
-
const positionState = await raydium_client_1.PersonalPositionState.fetch(this._connection, strategyState.position);
|
|
4817
|
+
const poolState = await raydium_client_1.PoolState.fetch(this._connection, strategyState.pool, this._raydiumService.getRaydiumProgramId());
|
|
4818
|
+
const positionState = await raydium_client_1.PersonalPositionState.fetch(this._connection, strategyState.position, this._raydiumService.getRaydiumProgramId());
|
|
4820
4819
|
if (!positionState) {
|
|
4821
4820
|
throw new Error(`Raydium position ${strategyState.position.toString()} could not be found.`);
|
|
4822
4821
|
}
|
|
@@ -4887,7 +4886,7 @@ class Kamino {
|
|
|
4887
4886
|
const collateralInfos = await this.getCollateralInfo(globalConfig.tokenInfos);
|
|
4888
4887
|
const result = [];
|
|
4889
4888
|
if (strategyState.strategyDex.toNumber() == (0, utils_1.dexToNumber)('ORCA')) {
|
|
4890
|
-
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, strategyState.pool);
|
|
4889
|
+
const whirlpool = await whirlpools_client_1.Whirlpool.fetch(this._connection, strategyState.pool, this._orcaService.getWhirlpoolProgramId());
|
|
4891
4890
|
if (!whirlpool) {
|
|
4892
4891
|
throw Error(`Could not fetch whirlpool state with pubkey ${strategyState.pool.toString()}`);
|
|
4893
4892
|
}
|
|
@@ -4923,7 +4922,7 @@ class Kamino {
|
|
|
4923
4922
|
return result;
|
|
4924
4923
|
}
|
|
4925
4924
|
else if (strategyState.strategyDex.toNumber() == (0, utils_1.dexToNumber)('RAYDIUM')) {
|
|
4926
|
-
const poolState = await raydium_client_1.PoolState.fetch(this._connection, strategyState.pool);
|
|
4925
|
+
const poolState = await raydium_client_1.PoolState.fetch(this._connection, strategyState.pool, this._raydiumService.getRaydiumProgramId());
|
|
4927
4926
|
if (!poolState) {
|
|
4928
4927
|
throw new Error(`Could not fetch whirlpool state with pubkey ${strategyState.pool.toString()}`);
|
|
4929
4928
|
}
|
|
@@ -4959,7 +4958,7 @@ class Kamino {
|
|
|
4959
4958
|
return result;
|
|
4960
4959
|
}
|
|
4961
4960
|
else if (strategyState.strategyDex.toNumber() == (0, utils_1.dexToNumber)('METEORA')) {
|
|
4962
|
-
const poolState = await accounts_2.LbPair.fetch(this._connection, strategyState.pool);
|
|
4961
|
+
const poolState = await accounts_2.LbPair.fetch(this._connection, strategyState.pool, this._meteoraService.getMeteoraProgramId());
|
|
4963
4962
|
if (!poolState) {
|
|
4964
4963
|
throw new Error(`Could not fetch meteora state with pubkey ${strategyState.pool.toString()}`);
|
|
4965
4964
|
}
|
|
@@ -5011,8 +5010,8 @@ class Kamino {
|
|
|
5011
5010
|
const decimalsB = await (0, utils_1.getMintDecimals)(this._connection, whilrpoolState.tokenMintB);
|
|
5012
5011
|
const tickIndex = (0, whirlpool_sdk_1.getNextValidTickIndex)((0, whirlpool_sdk_1.priceToTickIndex)(price, decimalsA, decimalsB), whilrpoolState.tickSpacing);
|
|
5013
5012
|
const startTickIndex = (0, whirlpool_sdk_1.getStartTickIndex)(tickIndex, whilrpoolState.tickSpacing);
|
|
5014
|
-
const [startTickIndexPk, _startTickIndexBump] = (0, utils_1.getTickArray)(
|
|
5015
|
-
const tick = await whirlpools_client_1.TickArray.fetch(this._connection, startTickIndexPk);
|
|
5013
|
+
const [startTickIndexPk, _startTickIndexBump] = (0, utils_1.getTickArray)(this._orcaService.getWhirlpoolProgramId(), poolAddress, startTickIndex);
|
|
5014
|
+
const tick = await whirlpools_client_1.TickArray.fetch(this._connection, startTickIndexPk, this._orcaService.getWhirlpoolProgramId());
|
|
5016
5015
|
// initialize tick if it doesn't exist
|
|
5017
5016
|
if (!tick) {
|
|
5018
5017
|
const initTickArrayArgs = {
|
|
@@ -5040,8 +5039,8 @@ class Kamino {
|
|
|
5040
5039
|
const decimalsB = await (0, utils_1.getMintDecimals)(this._connection, poolState.tokenYMint);
|
|
5041
5040
|
const binArray = (0, meteora_1.getBinIdFromPriceWithDecimals)(price, poolState.binStep, true, decimalsA, decimalsB);
|
|
5042
5041
|
const binArrayIndex = (0, meteora_1.binIdToBinArrayIndex)(new bn_js_1.default(binArray));
|
|
5043
|
-
const [startTickIndexPk, _startTickIndexBump] = (0, meteora_1.deriveBinArray)(poolAddress, binArrayIndex,
|
|
5044
|
-
const tick = await whirlpools_client_1.TickArray.fetch(this._connection, startTickIndexPk);
|
|
5042
|
+
const [startTickIndexPk, _startTickIndexBump] = (0, meteora_1.deriveBinArray)(poolAddress, binArrayIndex, this._meteoraService.getMeteoraProgramId());
|
|
5043
|
+
const tick = await whirlpools_client_1.TickArray.fetch(this._connection, startTickIndexPk, this._meteoraService.getMeteoraProgramId());
|
|
5045
5044
|
// initialize tick if it doesn't exist
|
|
5046
5045
|
if (!tick) {
|
|
5047
5046
|
const initTickArrayArgs = {
|