@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.d.ts
CHANGED
|
@@ -2917,7 +2917,7 @@ declare class RewarderModule implements IModule {
|
|
|
2917
2917
|
* @param tx
|
|
2918
2918
|
* @returns
|
|
2919
2919
|
*/
|
|
2920
|
-
batchCollectRewardePayload(params: CollectRewarderParams[], tx?: Transaction
|
|
2920
|
+
batchCollectRewardePayload(params: CollectRewarderParams[], tx?: Transaction): Promise<Transaction>;
|
|
2921
2921
|
createCollectRewarderPaylod(params: CollectRewarderParams, tx: Transaction, primaryCoinInputs: TransactionArgument[]): Transaction;
|
|
2922
2922
|
createCollectRewarderNoSendPaylod(params: CollectRewarderParams, tx: Transaction, primaryCoinInputs: TransactionArgument[]): Transaction;
|
|
2923
2923
|
}
|
package/dist/index.js
CHANGED
|
@@ -1975,7 +1975,7 @@ function toAmountAskSide(activeId, binStep, totalAmount, distributions) {
|
|
|
1975
1975
|
});
|
|
1976
1976
|
}
|
|
1977
1977
|
function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, distributions) {
|
|
1978
|
-
if (activeId > distributions[distributions.length - 1].binId) {
|
|
1978
|
+
if (activeId > distributions[distributions.length - 1].binId || amountX.isZero()) {
|
|
1979
1979
|
const amounts = toAmountBidSide(activeId, amountY, distributions);
|
|
1980
1980
|
return amounts.map((bin) => {
|
|
1981
1981
|
return {
|
|
@@ -1985,7 +1985,7 @@ function toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBi
|
|
|
1985
1985
|
};
|
|
1986
1986
|
});
|
|
1987
1987
|
}
|
|
1988
|
-
if (activeId < distributions[0].binId) {
|
|
1988
|
+
if (activeId < distributions[0].binId || amountY.isZero()) {
|
|
1989
1989
|
const amounts = toAmountAskSide(activeId, binStep, amountX, distributions);
|
|
1990
1990
|
return amounts.map((bin) => {
|
|
1991
1991
|
return {
|
|
@@ -2100,6 +2100,26 @@ var StrategyType = /* @__PURE__ */ ((StrategyType2) => {
|
|
|
2100
2100
|
StrategyType2[StrategyType2["BidAsk"] = 3] = "BidAsk";
|
|
2101
2101
|
return StrategyType2;
|
|
2102
2102
|
})(StrategyType || {});
|
|
2103
|
+
function toWeightDecendingOrder(minBinId, maxBinId) {
|
|
2104
|
+
const distributions = [];
|
|
2105
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
2106
|
+
distributions.push({
|
|
2107
|
+
binId: i,
|
|
2108
|
+
weight: maxBinId - i + 1
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
return distributions;
|
|
2112
|
+
}
|
|
2113
|
+
function toWeightAscendingOrder(minBinId, maxBinId) {
|
|
2114
|
+
const distributions = [];
|
|
2115
|
+
for (let i = minBinId; i <= maxBinId; i++) {
|
|
2116
|
+
distributions.push({
|
|
2117
|
+
binId: i,
|
|
2118
|
+
weight: i - minBinId + 1
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
return distributions;
|
|
2122
|
+
}
|
|
2103
2123
|
function toWeightSpotBalanced(minBinId, maxBinId) {
|
|
2104
2124
|
const distributions = [];
|
|
2105
2125
|
for (let i = minBinId; i <= maxBinId; i++) {
|
|
@@ -2216,10 +2236,26 @@ function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amou
|
|
|
2216
2236
|
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2217
2237
|
}
|
|
2218
2238
|
case 2 /* Curve */: {
|
|
2239
|
+
if (activeId < minBinId) {
|
|
2240
|
+
const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2241
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2242
|
+
}
|
|
2243
|
+
if (activeId > maxBinId) {
|
|
2244
|
+
const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2245
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2246
|
+
}
|
|
2219
2247
|
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2220
2248
|
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2221
2249
|
}
|
|
2222
2250
|
case 3 /* BidAsk */: {
|
|
2251
|
+
if (activeId < minBinId) {
|
|
2252
|
+
const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2253
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2254
|
+
}
|
|
2255
|
+
if (activeId > maxBinId) {
|
|
2256
|
+
const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2257
|
+
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2258
|
+
}
|
|
2223
2259
|
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2224
2260
|
return toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2225
2261
|
}
|
|
@@ -6881,45 +6917,21 @@ var RewarderModule = class {
|
|
|
6881
6917
|
* @param tx
|
|
6882
6918
|
* @returns
|
|
6883
6919
|
*/
|
|
6884
|
-
async batchCollectRewardePayload(params, tx
|
|
6920
|
+
async batchCollectRewardePayload(params, tx) {
|
|
6885
6921
|
if (!checkInvalidSuiAddress(this._sdk.senderAddress)) {
|
|
6886
6922
|
throw new ClmmpoolsError("this config sdk senderAddress is not set right", "InvalidSendAddress" /* InvalidSendAddress */);
|
|
6887
6923
|
}
|
|
6888
6924
|
const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress, null);
|
|
6889
6925
|
tx = tx || new import_transactions6.Transaction();
|
|
6890
|
-
const
|
|
6926
|
+
const coinIdList = [];
|
|
6891
6927
|
params.forEach((item) => {
|
|
6892
6928
|
const coinTypeA = normalizeCoinType(item.coinTypeA);
|
|
6893
6929
|
const coinTypeB = normalizeCoinType(item.coinTypeB);
|
|
6894
6930
|
if (item.collect_fee) {
|
|
6895
|
-
|
|
6896
|
-
|
|
6897
|
-
|
|
6898
|
-
|
|
6899
|
-
} else {
|
|
6900
|
-
coinAInput = {
|
|
6901
|
-
targetCoin: inputCoinA,
|
|
6902
|
-
remainCoins: [],
|
|
6903
|
-
isMintZeroCoin: false,
|
|
6904
|
-
tragetCoinAmount: "0"
|
|
6905
|
-
};
|
|
6906
|
-
}
|
|
6907
|
-
coinIdMaps[coinTypeA] = coinAInput;
|
|
6908
|
-
}
|
|
6909
|
-
let coinBInput = coinIdMaps[coinTypeB];
|
|
6910
|
-
if (coinBInput == null) {
|
|
6911
|
-
if (inputCoinB == null) {
|
|
6912
|
-
coinBInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeB, false);
|
|
6913
|
-
} else {
|
|
6914
|
-
coinBInput = {
|
|
6915
|
-
targetCoin: inputCoinB,
|
|
6916
|
-
remainCoins: [],
|
|
6917
|
-
isMintZeroCoin: false,
|
|
6918
|
-
tragetCoinAmount: "0"
|
|
6919
|
-
};
|
|
6920
|
-
}
|
|
6921
|
-
coinIdMaps[coinTypeB] = coinBInput;
|
|
6922
|
-
}
|
|
6931
|
+
const coinAInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeA, false, true);
|
|
6932
|
+
const coinBInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinTypeB, false, true);
|
|
6933
|
+
coinIdList.push({ coin: coinAInput, coin_addr: coinTypeA });
|
|
6934
|
+
coinIdList.push({ coin: coinBInput, coin_addr: coinTypeB });
|
|
6923
6935
|
tx = this._sdk.Position.createCollectFeeNoSendPaylod(
|
|
6924
6936
|
{
|
|
6925
6937
|
pool_id: item.pool_id,
|
|
@@ -6935,20 +6947,14 @@ var RewarderModule = class {
|
|
|
6935
6947
|
const primaryCoinInputs = [];
|
|
6936
6948
|
item.rewarder_coin_types.forEach((type) => {
|
|
6937
6949
|
const coinType = normalizeCoinType(type);
|
|
6938
|
-
|
|
6939
|
-
if (coinInput === void 0) {
|
|
6940
|
-
coinInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinType, false);
|
|
6941
|
-
coinIdMaps[coinType] = coinInput;
|
|
6942
|
-
}
|
|
6950
|
+
const coinInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), coinType, false, true);
|
|
6943
6951
|
primaryCoinInputs.push(coinInput.targetCoin);
|
|
6952
|
+
coinIdList.push({ coin: coinInput, coin_addr: coinType });
|
|
6944
6953
|
});
|
|
6945
6954
|
tx = this.createCollectRewarderNoSendPaylod(item, tx, primaryCoinInputs);
|
|
6946
6955
|
});
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
if (value.isMintZeroCoin) {
|
|
6950
|
-
TransactionUtil.buildTransferCoin(this._sdk, tx, value.targetCoin, key, this._sdk.senderAddress);
|
|
6951
|
-
}
|
|
6956
|
+
coinIdList.forEach((item) => {
|
|
6957
|
+
TransactionUtil.buildTransferCoin(this._sdk, tx, item.coin.targetCoin, item.coin_addr, this._sdk.senderAddress);
|
|
6952
6958
|
});
|
|
6953
6959
|
return tx;
|
|
6954
6960
|
}
|
|
@@ -10660,12 +10666,14 @@ var DlmmModule = class {
|
|
|
10660
10666
|
let primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10661
10667
|
let amount_min = 0;
|
|
10662
10668
|
let amount_max = 0;
|
|
10663
|
-
if (params.fixCoinA) {
|
|
10669
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10670
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeB, false, true);
|
|
10671
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10672
|
+
} else if (params.fixCoinA) {
|
|
10664
10673
|
amount_min = new import_decimal13.default(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10665
10674
|
amount_max = new import_decimal13.default(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10666
10675
|
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10667
|
-
}
|
|
10668
|
-
if (params.fixCoinB) {
|
|
10676
|
+
} else if (params.fixCoinB) {
|
|
10669
10677
|
amount_min = new import_decimal13.default(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10670
10678
|
amount_max = new import_decimal13.default(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10671
10679
|
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|