@magmaprotocol/magma-clmm-sdk 0.5.116 → 0.5.118
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 +4 -0
- package/dist/index.js +98 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +98 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -3364,6 +3364,72 @@ var _TransactionUtil = class {
|
|
|
3364
3364
|
});
|
|
3365
3365
|
return tx;
|
|
3366
3366
|
}
|
|
3367
|
+
static async buildAddLiquidityWithProtectionFixTokenForGas(sdk, allCoins, params, gasEstimateArg, tx, inputCoinA, inputCoinB) {
|
|
3368
|
+
tx = await _TransactionUtil.buildAddLiquidityFixToken(sdk, allCoins, params, tx, inputCoinA, inputCoinB);
|
|
3369
|
+
const { isAdjustCoinA } = findAdjustCoin(params);
|
|
3370
|
+
const suiAmount = isAdjustCoinA ? params.amount_a : params.amount_b;
|
|
3371
|
+
const newResult = await _TransactionUtil.adjustTransactionForGas(
|
|
3372
|
+
sdk,
|
|
3373
|
+
CoinAssist.getCoinAssets(isAdjustCoinA ? params.coinTypeA : params.coinTypeB, allCoins),
|
|
3374
|
+
BigInt(suiAmount),
|
|
3375
|
+
tx
|
|
3376
|
+
);
|
|
3377
|
+
const { fixAmount } = newResult;
|
|
3378
|
+
const { newTx } = newResult;
|
|
3379
|
+
if (newTx != null) {
|
|
3380
|
+
let primaryCoinAInputs;
|
|
3381
|
+
let primaryCoinBInputs;
|
|
3382
|
+
if (isAdjustCoinA) {
|
|
3383
|
+
params.amount_a = Number(fixAmount);
|
|
3384
|
+
primaryCoinAInputs = _TransactionUtil.buildAddLiquidityFixTokenCoinInput(
|
|
3385
|
+
newTx,
|
|
3386
|
+
!params.fix_amount_a,
|
|
3387
|
+
fixAmount.toString(),
|
|
3388
|
+
params.slippage,
|
|
3389
|
+
params.coinTypeA,
|
|
3390
|
+
allCoins,
|
|
3391
|
+
false,
|
|
3392
|
+
true
|
|
3393
|
+
);
|
|
3394
|
+
primaryCoinBInputs = _TransactionUtil.buildAddLiquidityFixTokenCoinInput(
|
|
3395
|
+
newTx,
|
|
3396
|
+
params.fix_amount_a,
|
|
3397
|
+
params.amount_b,
|
|
3398
|
+
params.slippage,
|
|
3399
|
+
params.coinTypeB,
|
|
3400
|
+
allCoins,
|
|
3401
|
+
false,
|
|
3402
|
+
true
|
|
3403
|
+
);
|
|
3404
|
+
} else {
|
|
3405
|
+
params.amount_b = Number(fixAmount);
|
|
3406
|
+
primaryCoinAInputs = _TransactionUtil.buildAddLiquidityFixTokenCoinInput(
|
|
3407
|
+
newTx,
|
|
3408
|
+
!params.fix_amount_a,
|
|
3409
|
+
params.amount_a,
|
|
3410
|
+
params.slippage,
|
|
3411
|
+
params.coinTypeA,
|
|
3412
|
+
allCoins,
|
|
3413
|
+
false,
|
|
3414
|
+
true
|
|
3415
|
+
);
|
|
3416
|
+
primaryCoinBInputs = _TransactionUtil.buildAddLiquidityFixTokenCoinInput(
|
|
3417
|
+
newTx,
|
|
3418
|
+
params.fix_amount_a,
|
|
3419
|
+
fixAmount.toString(),
|
|
3420
|
+
params.slippage,
|
|
3421
|
+
params.coinTypeB,
|
|
3422
|
+
allCoins,
|
|
3423
|
+
false,
|
|
3424
|
+
true
|
|
3425
|
+
);
|
|
3426
|
+
params = _TransactionUtil.fixAddLiquidityFixTokenParams(params, gasEstimateArg.slippage, gasEstimateArg.curSqrtPrice);
|
|
3427
|
+
tx = _TransactionUtil.buildAddLiquidityWithProtectionFixTokenArgs(newTx, sdk, allCoins, params, primaryCoinAInputs, primaryCoinBInputs);
|
|
3428
|
+
return tx;
|
|
3429
|
+
}
|
|
3430
|
+
}
|
|
3431
|
+
return tx;
|
|
3432
|
+
}
|
|
3367
3433
|
static buildAddLiquidityWithProtectionFixTokenArgs(tx, sdk, allCoinAsset, params, primaryCoinAInputs, primaryCoinBInputs) {
|
|
3368
3434
|
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
3369
3435
|
const functionName = params.is_open ? "open_position_with_liquidity_by_fix_coin_with_protection" : "add_liquidity_by_fix_coin_with_protection";
|
|
@@ -6101,7 +6167,7 @@ var PositionModule = class {
|
|
|
6101
6167
|
const { isAdjustCoinA, isAdjustCoinB } = findAdjustCoin(params);
|
|
6102
6168
|
params = params;
|
|
6103
6169
|
if (params.fix_amount_a && isAdjustCoinA || !params.fix_amount_a && isAdjustCoinB) {
|
|
6104
|
-
tx = await TransactionUtil.
|
|
6170
|
+
tx = await TransactionUtil.buildAddLiquidityWithProtectionFixTokenForGas(
|
|
6105
6171
|
this._sdk,
|
|
6106
6172
|
allCoinAsset,
|
|
6107
6173
|
params,
|
|
@@ -10576,7 +10642,8 @@ var AlmmModule = class {
|
|
|
10576
10642
|
tx.object(global_config_id),
|
|
10577
10643
|
tx.pure.u64(params.base_fee),
|
|
10578
10644
|
tx.pure.u16(params.bin_step),
|
|
10579
|
-
tx.pure.u32(storage_id)
|
|
10645
|
+
tx.pure.u32(storage_id),
|
|
10646
|
+
tx.object(CLOCK_ADDRESS)
|
|
10580
10647
|
];
|
|
10581
10648
|
tx.moveCall({
|
|
10582
10649
|
target: `${integrate.published_at}::${AlmmScript}::create_pair`,
|
|
@@ -10854,13 +10921,20 @@ var AlmmModule = class {
|
|
|
10854
10921
|
async burnPosition(params) {
|
|
10855
10922
|
const tx = new Transaction12();
|
|
10856
10923
|
tx.setSender(this.sdk.senderAddress);
|
|
10857
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10924
|
+
const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
|
|
10858
10925
|
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10926
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
10859
10927
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10860
|
-
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10928
|
+
let args = [tx.object(almmConfig.factory), tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10861
10929
|
let target = `${integrate.published_at}::${AlmmScript}::burn_position`;
|
|
10862
10930
|
if (params.rewards_token.length > 0) {
|
|
10863
|
-
args = [
|
|
10931
|
+
args = [
|
|
10932
|
+
tx.object(almmConfig.factory),
|
|
10933
|
+
tx.object(params.pool_id),
|
|
10934
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10935
|
+
tx.object(params.position_id),
|
|
10936
|
+
tx.object(CLOCK_ADDRESS)
|
|
10937
|
+
];
|
|
10864
10938
|
target = `${integrate.published_at}::${AlmmScript}::burn_position_reward${params.rewards_token.length}`;
|
|
10865
10939
|
}
|
|
10866
10940
|
tx.moveCall({
|
|
@@ -10873,13 +10947,21 @@ var AlmmModule = class {
|
|
|
10873
10947
|
async shrinkPosition(params) {
|
|
10874
10948
|
const tx = new Transaction12();
|
|
10875
10949
|
tx.setSender(this.sdk.senderAddress);
|
|
10876
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10950
|
+
const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
|
|
10877
10951
|
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10952
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
10878
10953
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10879
|
-
let args = [
|
|
10954
|
+
let args = [
|
|
10955
|
+
tx.object(almmConfig.factory),
|
|
10956
|
+
tx.object(params.pool_id),
|
|
10957
|
+
tx.object(params.position_id),
|
|
10958
|
+
tx.pure.u64(params.delta_percentage),
|
|
10959
|
+
tx.object(CLOCK_ADDRESS)
|
|
10960
|
+
];
|
|
10880
10961
|
let target = `${integrate.published_at}::${AlmmScript}::shrink_position`;
|
|
10881
10962
|
if (params.rewards_token.length > 0) {
|
|
10882
10963
|
args = [
|
|
10964
|
+
tx.object(almmConfig.factory),
|
|
10883
10965
|
tx.object(params.pool_id),
|
|
10884
10966
|
tx.object(clmmConfigs.global_vault_id),
|
|
10885
10967
|
tx.object(params.position_id),
|
|
@@ -10916,10 +10998,12 @@ var AlmmModule = class {
|
|
|
10916
10998
|
async collectReward(params, transaction) {
|
|
10917
10999
|
const tx = transaction || new Transaction12();
|
|
10918
11000
|
tx.setSender(this.sdk.senderAddress);
|
|
10919
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
11001
|
+
const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
|
|
10920
11002
|
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
11003
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
10921
11004
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10922
11005
|
const args = [
|
|
11006
|
+
tx.object(almmConfig.factory),
|
|
10923
11007
|
tx.object(params.pool_id),
|
|
10924
11008
|
tx.object(clmmConfigs.global_vault_id),
|
|
10925
11009
|
tx.object(params.position_id),
|
|
@@ -10939,9 +11023,10 @@ var AlmmModule = class {
|
|
|
10939
11023
|
async collectFees(params, transaction) {
|
|
10940
11024
|
const tx = transaction || new Transaction12();
|
|
10941
11025
|
tx.setSender(this.sdk.senderAddress);
|
|
10942
|
-
const { integrate } = this.sdk.sdkOptions;
|
|
11026
|
+
const { integrate, almm_pool } = this.sdk.sdkOptions;
|
|
11027
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
10943
11028
|
const typeArguments = [params.coin_a, params.coin_b];
|
|
10944
|
-
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
11029
|
+
const args = [tx.object(almmConfig.factory), tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10945
11030
|
const target = `${integrate.published_at}::${AlmmScript}::collect_fees`;
|
|
10946
11031
|
tx.moveCall({
|
|
10947
11032
|
target,
|
|
@@ -10991,8 +11076,9 @@ var AlmmModule = class {
|
|
|
10991
11076
|
async swap(params) {
|
|
10992
11077
|
const tx = new Transaction12();
|
|
10993
11078
|
tx.setSender(this.sdk.senderAddress);
|
|
10994
|
-
const { clmm_pool, integrate } = this.sdk.sdkOptions;
|
|
11079
|
+
const { clmm_pool, almm_pool, integrate } = this.sdk.sdkOptions;
|
|
10995
11080
|
const { global_config_id } = getPackagerConfigs(clmm_pool);
|
|
11081
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
10996
11082
|
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10997
11083
|
const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10998
11084
|
const primaryCoinInputA = TransactionUtil.buildCoinForAmount(
|
|
@@ -11012,6 +11098,7 @@ var AlmmModule = class {
|
|
|
11012
11098
|
true
|
|
11013
11099
|
);
|
|
11014
11100
|
const args = [
|
|
11101
|
+
tx.object(almmConfig.factory),
|
|
11015
11102
|
tx.object(params.pair),
|
|
11016
11103
|
tx.object(global_config_id),
|
|
11017
11104
|
primaryCoinInputA.targetCoin,
|