@magmaprotocol/magma-clmm-sdk 0.5.78 → 0.5.79
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 +1 -1
- package/dist/index.js +53 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1755,7 +1755,7 @@ function toAmountAskSide(activeId, binStep, totalAmount, distributions) {
|
|
|
1755
1755
|
});
|
|
1756
1756
|
}
|
|
1757
1757
|
function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1758
|
-
if (activeId > distributions[distributions.length - 1].binId) {
|
|
1758
|
+
if (activeId > distributions[distributions.length - 1].binId || amountX.isZero()) {
|
|
1759
1759
|
const amounts = toAmountBidSide(activeId, amountY, distributions);
|
|
1760
1760
|
return amounts.map((bin) => {
|
|
1761
1761
|
return {
|
|
@@ -1765,7 +1765,7 @@ function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBi
|
|
|
1765
1765
|
};
|
|
1766
1766
|
});
|
|
1767
1767
|
}
|
|
1768
|
-
if (activeId < distributions[0].binId) {
|
|
1768
|
+
if (activeId < distributions[0].binId || amountY.isZero()) {
|
|
1769
1769
|
const amounts = toAmountAskSide(activeId, binStep, amountX, distributions);
|
|
1770
1770
|
return amounts.map((bin) => {
|
|
1771
1771
|
return {
|
|
@@ -1880,6 +1880,26 @@ var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
|
|
|
1880
1880
|
StrategyType2[StrategyType2["BidAsk"] = 3] = "BidAsk";
|
|
1881
1881
|
return StrategyType2;
|
|
1882
1882
|
})(StrategyType || {});
|
|
1883
|
+
function toWeightDecendingOrder(minBinId, maxBinId) {
|
|
1884
|
+
const distributions = [];
|
|
1885
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
1886
|
+
distributions.push({
|
|
1887
|
+
binId: i,
|
|
1888
|
+
weight: maxBinId - i + 1
|
|
1889
|
+
});
|
|
1890
|
+
}
|
|
1891
|
+
return distributions;
|
|
1892
|
+
}
|
|
1893
|
+
function toWeightAscendingOrder(minBinId, maxBinId) {
|
|
1894
|
+
const distributions = [];
|
|
1895
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
1896
|
+
distributions.push({
|
|
1897
|
+
binId: i,
|
|
1898
|
+
weight: i - minBinId + 1
|
|
1899
|
+
});
|
|
1900
|
+
}
|
|
1901
|
+
return distributions;
|
|
1902
|
+
}
|
|
1883
1903
|
function toWeightSpotBalanced(minBinId, maxBinId) {
|
|
1884
1904
|
const distributions = [];
|
|
1885
1905
|
for (let i = minBinId; i <= maxBinId; i++) {
|
|
@@ -1996,10 +2016,26 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
1996
2016
|
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
1997
2017
|
}
|
|
1998
2018
|
case 2 /* Curve */: {
|
|
2019
|
+
if (activeId < minBinId) {
|
|
2020
|
+
const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2021
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2022
|
+
}
|
|
2023
|
+
if (activeId > maxBinId) {
|
|
2024
|
+
const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2025
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2026
|
+
}
|
|
1999
2027
|
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2000
2028
|
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2001
2029
|
}
|
|
2002
2030
|
case 3 /* BidAsk */: {
|
|
2031
|
+
if (activeId < minBinId) {
|
|
2032
|
+
const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2033
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2034
|
+
}
|
|
2035
|
+
if (activeId > maxBinId) {
|
|
2036
|
+
const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2037
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2038
|
+
}
|
|
2003
2039
|
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2004
2040
|
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2005
2041
|
}
|
|
@@ -6661,45 +6697,21 @@ var RewarderModule = class {
|
|
|
6661
6697
|
* @param tx
|
|
6662
6698
|
* @returns
|
|
6663
6699
|
*/
|
|
6664
|
-
async batchCollectRewardePayload(params, tx
|
|
6700
|
+
async batchCollectRewardePayload(params, tx) {
|
|
6665
6701
|
if (!checkInvalidSuiAddress(this._sdk.senderAddress)) {
|
|
6666
6702
|
throw new ClmmpoolsError("this config sdk senderAddress is not set right", "InvalidSendAddress" /* InvalidSendAddress */);
|
|
6667
6703
|
}
|
|
6668
6704
|
const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress, null);
|
|
6669
6705
|
tx = tx || new Transaction6();
|
|
6670
|
-
const
|
|
6706
|
+
const coinIdList = [];
|
|
6671
6707
|
params.forEach((item) => {
|
|
6672
6708
|
const coinTypeA = normalizeCoinType(item.coinTypeA);
|
|
6673
6709
|
const coinTypeB = normalizeCoinType(item.coinTypeB);
|
|
6674
6710
|
if (item.collect_fee) {
|
|
6675
|
-
|
|
6676
|
-
|
|
6677
|
-
|
|
6678
|
-
|
|
6679
|
-
} else {
|
|
6680
|
-
coinAInput = {
|
|
6681
|
-
targetCoin: inputCoinA,
|
|
6682
|
-
remainCoins: [],
|
|
6683
|
-
isMintZeroCoin: false,
|
|
6684
|
-
tragetCoinAmount: "0"
|
|
6685
|
-
};
|
|
6686
|
-
}
|
|
6687
|
-
coinIdMaps[coinTypeA] = coinAInput;
|
|
6688
|
-
}
|
|
6689
|
-
let coinBInput = coinIdMaps[coinTypeB];
|
|
6690
|
-
if (coinBInput == null) {
|
|
6691
|
-
if (inputCoinB == null) {
|
|
6692
|
-
coinBInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeB, false);
|
|
6693
|
-
} else {
|
|
6694
|
-
coinBInput = {
|
|
6695
|
-
targetCoin: inputCoinB,
|
|
6696
|
-
remainCoins: [],
|
|
6697
|
-
isMintZeroCoin: false,
|
|
6698
|
-
tragetCoinAmount: "0"
|
|
6699
|
-
};
|
|
6700
|
-
}
|
|
6701
|
-
coinIdMaps[coinTypeB] = coinBInput;
|
|
6702
|
-
}
|
|
6711
|
+
const coinAInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeA, false, true);
|
|
6712
|
+
const coinBInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeB, false, true);
|
|
6713
|
+
coinIdList.push({ coin: coinAInput, coin_addr: coinTypeA });
|
|
6714
|
+
coinIdList.push({ coin: coinBInput, coin_addr: coinTypeB });
|
|
6703
6715
|
tx = this._sdk.Position.createCollectFeeNoSendPaylod(
|
|
6704
6716
|
{
|
|
6705
6717
|
pool_id: item.pool_id,
|
|
@@ -6715,20 +6727,14 @@ var RewarderModule = class {
|
|
|
6715
6727
|
const primaryCoinInputs = [];
|
|
6716
6728
|
item.rewarder_coin_types.forEach((type) => {
|
|
6717
6729
|
const coinType = normalizeCoinType(type);
|
|
6718
|
-
|
|
6719
|
-
if (coinInput === void 0) {
|
|
6720
|
-
coinInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinType, false);
|
|
6721
|
-
coinIdMaps[coinType] = coinInput;
|
|
6722
|
-
}
|
|
6730
|
+
const coinInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinType, false, true);
|
|
6723
6731
|
primaryCoinInputs.push(coinInput.targetCoin);
|
|
6732
|
+
coinIdList.push({ coin: coinInput, coin_addr: coinType });
|
|
6724
6733
|
});
|
|
6725
6734
|
tx = this.createCollectRewarderNoSendPaylod(item, tx, primaryCoinInputs);
|
|
6726
6735
|
});
|
|
6727
|
-
|
|
6728
|
-
|
|
6729
|
-
if (value.isMintZeroCoin) {
|
|
6730
|
-
TransactionUtil.buildTransferCoin(this._sdk, tx, value.targetCoin, key, this._sdk.senderAddress);
|
|
6731
|
-
}
|
|
6736
|
+
coinIdList.forEach((item) => {
|
|
6737
|
+
TransactionUtil.buildTransferCoin(this._sdk, tx, item.coin.targetCoin, item.coin_addr, this._sdk.senderAddress);
|
|
6732
6738
|
});
|
|
6733
6739
|
return tx;
|
|
6734
6740
|
}
|
|
@@ -10447,12 +10453,14 @@ var DlmmModule = class {
|
|
|
10447
10453
|
let primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10448
10454
|
let amount_min = 0;
|
|
10449
10455
|
let amount_max = 0;
|
|
10450
|
-
if (params.fixCoinA) {
|
|
10456
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10457
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeB, false, true);
|
|
10458
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10459
|
+
} else if (params.fixCoinA) {
|
|
10451
10460
|
amount_min = new Decimal10(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10452
10461
|
amount_max = new Decimal10(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10453
10462
|
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10454
|
-
}
|
|
10455
|
-
if (params.fixCoinB) {
|
|
10463
|
+
} else if (params.fixCoinB) {
|
|
10456
10464
|
amount_min = new Decimal10(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10457
10465
|
amount_max = new Decimal10(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10458
10466
|
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|