@magmaprotocol/magma-clmm-sdk 0.5.84 → 0.5.85
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/index.d.ts +20 -4
- package/dist/index.js +154 -82
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +154 -82
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2012,6 +2012,9 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
|
|
|
2012
2012
|
}
|
|
2013
2013
|
}
|
|
2014
2014
|
function assignLeftAmountX(activeId, binStep, maxBinId, amountX, strategyType) {
|
|
2015
|
+
if (maxBinId < activeId) {
|
|
2016
|
+
return [];
|
|
2017
|
+
}
|
|
2015
2018
|
let weights = [];
|
|
2016
2019
|
switch (strategyType) {
|
|
2017
2020
|
case 1 /* Spot */: {
|
|
@@ -2037,6 +2040,9 @@ function assignLeftAmountX(activeId, binStep, maxBinId, amountX, strategyType) {
|
|
|
2037
2040
|
});
|
|
2038
2041
|
}
|
|
2039
2042
|
function assignLeftAmountY(activeId, minBinId, amountY, strategyType) {
|
|
2043
|
+
if (minBinId > activeId) {
|
|
2044
|
+
return [];
|
|
2045
|
+
}
|
|
2040
2046
|
let weights = [];
|
|
2041
2047
|
switch (strategyType) {
|
|
2042
2048
|
case 1 /* Spot */: {
|
|
@@ -10590,65 +10596,65 @@ var DlmmModule = class {
|
|
|
10590
10596
|
});
|
|
10591
10597
|
return tx;
|
|
10592
10598
|
}
|
|
10593
|
-
// Create a position by percent
|
|
10594
|
-
async mintPercent(params) {
|
|
10595
|
-
|
|
10596
|
-
|
|
10597
|
-
|
|
10598
|
-
|
|
10599
|
-
|
|
10600
|
-
|
|
10601
|
-
|
|
10602
|
-
|
|
10603
|
-
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10608
|
-
|
|
10609
|
-
|
|
10610
|
-
|
|
10611
|
-
|
|
10612
|
-
|
|
10613
|
-
|
|
10614
|
-
|
|
10615
|
-
|
|
10616
|
-
|
|
10617
|
-
|
|
10618
|
-
|
|
10619
|
-
|
|
10620
|
-
|
|
10621
|
-
|
|
10622
|
-
}
|
|
10623
|
-
// Create a position by amount
|
|
10624
|
-
async createPositionByAmount(params) {
|
|
10625
|
-
|
|
10626
|
-
|
|
10627
|
-
|
|
10628
|
-
|
|
10629
|
-
|
|
10630
|
-
|
|
10631
|
-
|
|
10632
|
-
|
|
10633
|
-
|
|
10634
|
-
|
|
10635
|
-
|
|
10636
|
-
|
|
10637
|
-
|
|
10638
|
-
|
|
10639
|
-
|
|
10640
|
-
|
|
10641
|
-
|
|
10642
|
-
|
|
10643
|
-
|
|
10644
|
-
|
|
10645
|
-
|
|
10646
|
-
|
|
10647
|
-
|
|
10648
|
-
|
|
10649
|
-
|
|
10650
|
-
}
|
|
10651
|
-
async
|
|
10599
|
+
// // Create a position by percent
|
|
10600
|
+
// async mintPercent(params: MintPercentParams): Promise<Transaction> {
|
|
10601
|
+
// const tx = new Transaction()
|
|
10602
|
+
// tx.setSender(this.sdk.senderAddress)
|
|
10603
|
+
// const { dlmm_pool, integrate } = this.sdk.sdkOptions
|
|
10604
|
+
// const dlmmConfig = getPackagerConfigs(dlmm_pool)
|
|
10605
|
+
// const typeArguments = [params.coinTypeA, params.coinTypeB]
|
|
10606
|
+
// const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress)
|
|
10607
|
+
// const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true)
|
|
10608
|
+
// const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true)
|
|
10609
|
+
// const args = [
|
|
10610
|
+
// tx.object(params.pair),
|
|
10611
|
+
// tx.object(dlmmConfig.factory),
|
|
10612
|
+
// primaryCoinAInputs.targetCoin,
|
|
10613
|
+
// primaryCoinBInputs.targetCoin,
|
|
10614
|
+
// tx.pure.u64(params.amountATotal),
|
|
10615
|
+
// tx.pure.u64(params.amountBTotal),
|
|
10616
|
+
// tx.pure.vector('u32', params.storageIds),
|
|
10617
|
+
// tx.pure.vector('u64', params.binsAPercent),
|
|
10618
|
+
// tx.pure.vector('u64', params.binsBPercent),
|
|
10619
|
+
// tx.pure.address(params.to),
|
|
10620
|
+
// tx.object(CLOCK_ADDRESS),
|
|
10621
|
+
// ]
|
|
10622
|
+
// tx.moveCall({
|
|
10623
|
+
// target: `${integrate.published_at}::${DlmmScript}::mint_percent`,
|
|
10624
|
+
// typeArguments,
|
|
10625
|
+
// arguments: args,
|
|
10626
|
+
// })
|
|
10627
|
+
// return tx
|
|
10628
|
+
// }
|
|
10629
|
+
// // Create a position by amount
|
|
10630
|
+
// async createPositionByAmount(params: MintAmountParams): Promise<Transaction> {
|
|
10631
|
+
// const tx = new Transaction()
|
|
10632
|
+
// tx.setSender(this.sdk.senderAddress)
|
|
10633
|
+
// const { dlmm_pool, integrate } = this.sdk.sdkOptions
|
|
10634
|
+
// const dlmmConfig = getPackagerConfigs(dlmm_pool)
|
|
10635
|
+
// const typeArguments = [params.coinTypeA, params.coinTypeB]
|
|
10636
|
+
// const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress)
|
|
10637
|
+
// const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true)
|
|
10638
|
+
// const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true)
|
|
10639
|
+
// const args = [
|
|
10640
|
+
// tx.object(params.pair),
|
|
10641
|
+
// tx.object(dlmmConfig.factory),
|
|
10642
|
+
// primaryCoinAInputs.targetCoin,
|
|
10643
|
+
// primaryCoinBInputs.targetCoin,
|
|
10644
|
+
// tx.pure.vector('u32', params.storageIds),
|
|
10645
|
+
// tx.pure.vector('u64', params.amountsA),
|
|
10646
|
+
// tx.pure.vector('u64', params.amountsB),
|
|
10647
|
+
// tx.pure.address(params.to),
|
|
10648
|
+
// tx.object(CLOCK_ADDRESS),
|
|
10649
|
+
// ]
|
|
10650
|
+
// tx.moveCall({
|
|
10651
|
+
// target: `${integrate.published_at}::${DlmmScript}::mint_amounts`,
|
|
10652
|
+
// typeArguments,
|
|
10653
|
+
// arguments: args,
|
|
10654
|
+
// })
|
|
10655
|
+
// return tx
|
|
10656
|
+
// }
|
|
10657
|
+
async addLiquidityByStrategy(params) {
|
|
10652
10658
|
if (params.rewards_token.length === 0) {
|
|
10653
10659
|
return this._raisePositionByAmounts(params);
|
|
10654
10660
|
}
|
|
@@ -10656,24 +10662,58 @@ var DlmmModule = class {
|
|
|
10656
10662
|
}
|
|
10657
10663
|
async _raisePositionByAmounts(params) {
|
|
10658
10664
|
const tx = new Transaction12();
|
|
10665
|
+
const slippage = new Decimal10(params.slippage);
|
|
10666
|
+
const lower_slippage = new Decimal10(1).sub(slippage.div(new Decimal10(1e4)));
|
|
10667
|
+
const upper_slippage = new Decimal10(1).plus(slippage.div(new Decimal10(1e4)));
|
|
10659
10668
|
tx.setSender(this.sdk.senderAddress);
|
|
10660
10669
|
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10661
10670
|
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10662
|
-
const
|
|
10671
|
+
const price = get_price_x128_from_real_id3(params.active_bin, params.bin_step);
|
|
10672
|
+
const min_price = new Decimal10(price).mul(lower_slippage);
|
|
10673
|
+
const max_price = new Decimal10(price).mul(upper_slippage);
|
|
10674
|
+
const active_min = get_storage_id_from_real_id(get_real_id_from_price_x1282(min_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10675
|
+
const active_max = get_storage_id_from_real_id(get_real_id_from_price_x1282(max_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10676
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10663
10677
|
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10664
|
-
|
|
10665
|
-
|
|
10666
|
-
|
|
10667
|
-
|
|
10678
|
+
let amount_min = 0;
|
|
10679
|
+
let amount_max = 0;
|
|
10680
|
+
let primaryCoinAInputs;
|
|
10681
|
+
let primaryCoinBInputs;
|
|
10682
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10683
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10684
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10685
|
+
} else if (params.fixCoinA) {
|
|
10686
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10687
|
+
amount_min = new Decimal10(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10688
|
+
amount_max = new Decimal10(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10689
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10690
|
+
} else if (params.fixCoinB) {
|
|
10691
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10692
|
+
amount_min = new Decimal10(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10693
|
+
amount_max = new Decimal10(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10694
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true);
|
|
10695
|
+
}
|
|
10696
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10697
|
+
} else if (params.fixCoinA) {
|
|
10698
|
+
params.amountBTotal = 0;
|
|
10699
|
+
} else if (params.fixCoinB) {
|
|
10700
|
+
params.amountATotal = 0;
|
|
10701
|
+
}
|
|
10668
10702
|
const args = [
|
|
10669
|
-
tx.object(params.
|
|
10703
|
+
tx.object(params.pair),
|
|
10670
10704
|
tx.object(dlmmConfig.factory),
|
|
10671
|
-
tx.object(params.
|
|
10705
|
+
tx.object(params.positionId),
|
|
10672
10706
|
primaryCoinAInputs.targetCoin,
|
|
10673
10707
|
primaryCoinBInputs.targetCoin,
|
|
10674
|
-
tx.pure.
|
|
10675
|
-
tx.pure.
|
|
10676
|
-
tx.pure.
|
|
10708
|
+
tx.pure.bool(params.fixCoinA),
|
|
10709
|
+
tx.pure.u64(params.amountATotal),
|
|
10710
|
+
tx.pure.bool(params.fixCoinB),
|
|
10711
|
+
tx.pure.u64(params.amountBTotal),
|
|
10712
|
+
tx.pure.u8(params.strategy),
|
|
10713
|
+
tx.pure.u32(active_min),
|
|
10714
|
+
tx.pure.u32(active_max),
|
|
10715
|
+
tx.pure.u64(amount_min),
|
|
10716
|
+
tx.pure.u64(amount_max),
|
|
10677
10717
|
tx.object(CLOCK_ADDRESS)
|
|
10678
10718
|
];
|
|
10679
10719
|
tx.moveCall({
|
|
@@ -10685,26 +10725,58 @@ var DlmmModule = class {
|
|
|
10685
10725
|
}
|
|
10686
10726
|
async _raisePositionByAmountsReward(params) {
|
|
10687
10727
|
const tx = new Transaction12();
|
|
10728
|
+
const slippage = new Decimal10(params.slippage);
|
|
10729
|
+
const lower_slippage = new Decimal10(1).sub(slippage.div(new Decimal10(1e4)));
|
|
10730
|
+
const upper_slippage = new Decimal10(1).plus(slippage.div(new Decimal10(1e4)));
|
|
10688
10731
|
tx.setSender(this.sdk.senderAddress);
|
|
10689
|
-
const { dlmm_pool, integrate
|
|
10732
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10690
10733
|
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10691
|
-
const
|
|
10692
|
-
const
|
|
10734
|
+
const price = get_price_x128_from_real_id3(params.active_bin, params.bin_step);
|
|
10735
|
+
const min_price = new Decimal10(price).mul(lower_slippage);
|
|
10736
|
+
const max_price = new Decimal10(price).mul(upper_slippage);
|
|
10737
|
+
const active_min = get_storage_id_from_real_id(get_real_id_from_price_x1282(min_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10738
|
+
const active_max = get_storage_id_from_real_id(get_real_id_from_price_x1282(max_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10739
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB, ...params.rewards_token];
|
|
10693
10740
|
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
|
|
10697
|
-
|
|
10741
|
+
let amount_min = 0;
|
|
10742
|
+
let amount_max = 0;
|
|
10743
|
+
let primaryCoinAInputs;
|
|
10744
|
+
let primaryCoinBInputs;
|
|
10745
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10746
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10747
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10748
|
+
} else if (params.fixCoinA) {
|
|
10749
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10750
|
+
amount_min = new Decimal10(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10751
|
+
amount_max = new Decimal10(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10752
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10753
|
+
} else if (params.fixCoinB) {
|
|
10754
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10755
|
+
amount_min = new Decimal10(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10756
|
+
amount_max = new Decimal10(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10757
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true);
|
|
10758
|
+
}
|
|
10759
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10760
|
+
} else if (params.fixCoinA) {
|
|
10761
|
+
params.amountBTotal = 0;
|
|
10762
|
+
} else if (params.fixCoinB) {
|
|
10763
|
+
params.amountATotal = 0;
|
|
10764
|
+
}
|
|
10698
10765
|
const args = [
|
|
10699
|
-
tx.object(params.
|
|
10766
|
+
tx.object(params.pair),
|
|
10700
10767
|
tx.object(dlmmConfig.factory),
|
|
10701
|
-
tx.object(
|
|
10702
|
-
tx.object(params.position_id),
|
|
10768
|
+
tx.object(params.positionId),
|
|
10703
10769
|
primaryCoinAInputs.targetCoin,
|
|
10704
10770
|
primaryCoinBInputs.targetCoin,
|
|
10705
|
-
tx.pure.
|
|
10706
|
-
tx.pure.
|
|
10707
|
-
tx.pure.
|
|
10771
|
+
tx.pure.bool(params.fixCoinA),
|
|
10772
|
+
tx.pure.u64(params.amountATotal),
|
|
10773
|
+
tx.pure.bool(params.fixCoinB),
|
|
10774
|
+
tx.pure.u64(params.amountBTotal),
|
|
10775
|
+
tx.pure.u8(params.strategy),
|
|
10776
|
+
tx.pure.u32(active_min),
|
|
10777
|
+
tx.pure.u32(active_max),
|
|
10778
|
+
tx.pure.u64(amount_min),
|
|
10779
|
+
tx.pure.u64(amount_max),
|
|
10708
10780
|
tx.object(CLOCK_ADDRESS)
|
|
10709
10781
|
];
|
|
10710
10782
|
tx.moveCall({
|