@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.d.ts
CHANGED
|
@@ -4320,6 +4320,10 @@ declare class TransactionUtil {
|
|
|
4320
4320
|
*/
|
|
4321
4321
|
static fixAddLiquidityFixTokenParams(params: AddLiquidityFixTokenParams, slippage: number, curSqrtPrice: BN): AddLiquidityFixTokenParams;
|
|
4322
4322
|
private static buildAddLiquidityFixTokenArgs;
|
|
4323
|
+
static buildAddLiquidityWithProtectionFixTokenForGas(sdk: MagmaClmmSDK, allCoins: CoinAsset[], params: AddLiquidityFixTokenParams, gasEstimateArg: {
|
|
4324
|
+
slippage: number;
|
|
4325
|
+
curSqrtPrice: BN;
|
|
4326
|
+
}, tx?: Transaction, inputCoinA?: TransactionObjectArgument, inputCoinB?: TransactionObjectArgument): Promise<Transaction>;
|
|
4323
4327
|
private static buildAddLiquidityWithProtectionFixTokenArgs;
|
|
4324
4328
|
/**
|
|
4325
4329
|
* build add liquidity transaction
|
package/dist/index.js
CHANGED
|
@@ -3584,6 +3584,72 @@ var _TransactionUtil = class {
|
|
|
3584
3584
|
});
|
|
3585
3585
|
return tx;
|
|
3586
3586
|
}
|
|
3587
|
+
static async buildAddLiquidityWithProtectionFixTokenForGas(sdk, allCoins, params, gasEstimateArg, tx, inputCoinA, inputCoinB) {
|
|
3588
|
+
tx = await _TransactionUtil.buildAddLiquidityFixToken(sdk, allCoins, params, tx, inputCoinA, inputCoinB);
|
|
3589
|
+
const { isAdjustCoinA } = findAdjustCoin(params);
|
|
3590
|
+
const suiAmount = isAdjustCoinA ? params.amount_a : params.amount_b;
|
|
3591
|
+
const newResult = await _TransactionUtil.adjustTransactionForGas(
|
|
3592
|
+
sdk,
|
|
3593
|
+
CoinAssist.getCoinAssets(isAdjustCoinA ? params.coinTypeA : params.coinTypeB, allCoins),
|
|
3594
|
+
BigInt(suiAmount),
|
|
3595
|
+
tx
|
|
3596
|
+
);
|
|
3597
|
+
const { fixAmount } = newResult;
|
|
3598
|
+
const { newTx } = newResult;
|
|
3599
|
+
if (newTx != null) {
|
|
3600
|
+
let primaryCoinAInputs;
|
|
3601
|
+
let primaryCoinBInputs;
|
|
3602
|
+
if (isAdjustCoinA) {
|
|
3603
|
+
params.amount_a = Number(fixAmount);
|
|
3604
|
+
primaryCoinAInputs = _TransactionUtil.buildAddLiquidityFixTokenCoinInput(
|
|
3605
|
+
newTx,
|
|
3606
|
+
!params.fix_amount_a,
|
|
3607
|
+
fixAmount.toString(),
|
|
3608
|
+
params.slippage,
|
|
3609
|
+
params.coinTypeA,
|
|
3610
|
+
allCoins,
|
|
3611
|
+
false,
|
|
3612
|
+
true
|
|
3613
|
+
);
|
|
3614
|
+
primaryCoinBInputs = _TransactionUtil.buildAddLiquidityFixTokenCoinInput(
|
|
3615
|
+
newTx,
|
|
3616
|
+
params.fix_amount_a,
|
|
3617
|
+
params.amount_b,
|
|
3618
|
+
params.slippage,
|
|
3619
|
+
params.coinTypeB,
|
|
3620
|
+
allCoins,
|
|
3621
|
+
false,
|
|
3622
|
+
true
|
|
3623
|
+
);
|
|
3624
|
+
} else {
|
|
3625
|
+
params.amount_b = Number(fixAmount);
|
|
3626
|
+
primaryCoinAInputs = _TransactionUtil.buildAddLiquidityFixTokenCoinInput(
|
|
3627
|
+
newTx,
|
|
3628
|
+
!params.fix_amount_a,
|
|
3629
|
+
params.amount_a,
|
|
3630
|
+
params.slippage,
|
|
3631
|
+
params.coinTypeA,
|
|
3632
|
+
allCoins,
|
|
3633
|
+
false,
|
|
3634
|
+
true
|
|
3635
|
+
);
|
|
3636
|
+
primaryCoinBInputs = _TransactionUtil.buildAddLiquidityFixTokenCoinInput(
|
|
3637
|
+
newTx,
|
|
3638
|
+
params.fix_amount_a,
|
|
3639
|
+
fixAmount.toString(),
|
|
3640
|
+
params.slippage,
|
|
3641
|
+
params.coinTypeB,
|
|
3642
|
+
allCoins,
|
|
3643
|
+
false,
|
|
3644
|
+
true
|
|
3645
|
+
);
|
|
3646
|
+
params = _TransactionUtil.fixAddLiquidityFixTokenParams(params, gasEstimateArg.slippage, gasEstimateArg.curSqrtPrice);
|
|
3647
|
+
tx = _TransactionUtil.buildAddLiquidityWithProtectionFixTokenArgs(newTx, sdk, allCoins, params, primaryCoinAInputs, primaryCoinBInputs);
|
|
3648
|
+
return tx;
|
|
3649
|
+
}
|
|
3650
|
+
}
|
|
3651
|
+
return tx;
|
|
3652
|
+
}
|
|
3587
3653
|
static buildAddLiquidityWithProtectionFixTokenArgs(tx, sdk, allCoinAsset, params, primaryCoinAInputs, primaryCoinBInputs) {
|
|
3588
3654
|
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
3589
3655
|
const functionName = params.is_open ? "open_position_with_liquidity_by_fix_coin_with_protection" : "add_liquidity_by_fix_coin_with_protection";
|
|
@@ -6321,7 +6387,7 @@ var PositionModule = class {
|
|
|
6321
6387
|
const { isAdjustCoinA, isAdjustCoinB } = findAdjustCoin(params);
|
|
6322
6388
|
params = params;
|
|
6323
6389
|
if (params.fix_amount_a && isAdjustCoinA || !params.fix_amount_a && isAdjustCoinB) {
|
|
6324
|
-
tx = await TransactionUtil.
|
|
6390
|
+
tx = await TransactionUtil.buildAddLiquidityWithProtectionFixTokenForGas(
|
|
6325
6391
|
this._sdk,
|
|
6326
6392
|
allCoinAsset,
|
|
6327
6393
|
params,
|
|
@@ -10789,7 +10855,8 @@ var AlmmModule = class {
|
|
|
10789
10855
|
tx.object(global_config_id),
|
|
10790
10856
|
tx.pure.u64(params.base_fee),
|
|
10791
10857
|
tx.pure.u16(params.bin_step),
|
|
10792
|
-
tx.pure.u32(storage_id)
|
|
10858
|
+
tx.pure.u32(storage_id),
|
|
10859
|
+
tx.object(CLOCK_ADDRESS)
|
|
10793
10860
|
];
|
|
10794
10861
|
tx.moveCall({
|
|
10795
10862
|
target: `${integrate.published_at}::${AlmmScript}::create_pair`,
|
|
@@ -11067,13 +11134,20 @@ var AlmmModule = class {
|
|
|
11067
11134
|
async burnPosition(params) {
|
|
11068
11135
|
const tx = new import_transactions12.Transaction();
|
|
11069
11136
|
tx.setSender(this.sdk.senderAddress);
|
|
11070
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
11137
|
+
const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
|
|
11071
11138
|
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
11139
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
11072
11140
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
11073
|
-
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
11141
|
+
let args = [tx.object(almmConfig.factory), tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
11074
11142
|
let target = `${integrate.published_at}::${AlmmScript}::burn_position`;
|
|
11075
11143
|
if (params.rewards_token.length > 0) {
|
|
11076
|
-
args = [
|
|
11144
|
+
args = [
|
|
11145
|
+
tx.object(almmConfig.factory),
|
|
11146
|
+
tx.object(params.pool_id),
|
|
11147
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
11148
|
+
tx.object(params.position_id),
|
|
11149
|
+
tx.object(CLOCK_ADDRESS)
|
|
11150
|
+
];
|
|
11077
11151
|
target = `${integrate.published_at}::${AlmmScript}::burn_position_reward${params.rewards_token.length}`;
|
|
11078
11152
|
}
|
|
11079
11153
|
tx.moveCall({
|
|
@@ -11086,13 +11160,21 @@ var AlmmModule = class {
|
|
|
11086
11160
|
async shrinkPosition(params) {
|
|
11087
11161
|
const tx = new import_transactions12.Transaction();
|
|
11088
11162
|
tx.setSender(this.sdk.senderAddress);
|
|
11089
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
11163
|
+
const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
|
|
11090
11164
|
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
11165
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
11091
11166
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
11092
|
-
let args = [
|
|
11167
|
+
let args = [
|
|
11168
|
+
tx.object(almmConfig.factory),
|
|
11169
|
+
tx.object(params.pool_id),
|
|
11170
|
+
tx.object(params.position_id),
|
|
11171
|
+
tx.pure.u64(params.delta_percentage),
|
|
11172
|
+
tx.object(CLOCK_ADDRESS)
|
|
11173
|
+
];
|
|
11093
11174
|
let target = `${integrate.published_at}::${AlmmScript}::shrink_position`;
|
|
11094
11175
|
if (params.rewards_token.length > 0) {
|
|
11095
11176
|
args = [
|
|
11177
|
+
tx.object(almmConfig.factory),
|
|
11096
11178
|
tx.object(params.pool_id),
|
|
11097
11179
|
tx.object(clmmConfigs.global_vault_id),
|
|
11098
11180
|
tx.object(params.position_id),
|
|
@@ -11129,10 +11211,12 @@ var AlmmModule = class {
|
|
|
11129
11211
|
async collectReward(params, transaction) {
|
|
11130
11212
|
const tx = transaction || new import_transactions12.Transaction();
|
|
11131
11213
|
tx.setSender(this.sdk.senderAddress);
|
|
11132
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
11214
|
+
const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
|
|
11133
11215
|
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
11216
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
11134
11217
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
11135
11218
|
const args = [
|
|
11219
|
+
tx.object(almmConfig.factory),
|
|
11136
11220
|
tx.object(params.pool_id),
|
|
11137
11221
|
tx.object(clmmConfigs.global_vault_id),
|
|
11138
11222
|
tx.object(params.position_id),
|
|
@@ -11152,9 +11236,10 @@ var AlmmModule = class {
|
|
|
11152
11236
|
async collectFees(params, transaction) {
|
|
11153
11237
|
const tx = transaction || new import_transactions12.Transaction();
|
|
11154
11238
|
tx.setSender(this.sdk.senderAddress);
|
|
11155
|
-
const { integrate } = this.sdk.sdkOptions;
|
|
11239
|
+
const { integrate, almm_pool } = this.sdk.sdkOptions;
|
|
11240
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
11156
11241
|
const typeArguments = [params.coin_a, params.coin_b];
|
|
11157
|
-
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
11242
|
+
const args = [tx.object(almmConfig.factory), tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
11158
11243
|
const target = `${integrate.published_at}::${AlmmScript}::collect_fees`;
|
|
11159
11244
|
tx.moveCall({
|
|
11160
11245
|
target,
|
|
@@ -11204,8 +11289,9 @@ var AlmmModule = class {
|
|
|
11204
11289
|
async swap(params) {
|
|
11205
11290
|
const tx = new import_transactions12.Transaction();
|
|
11206
11291
|
tx.setSender(this.sdk.senderAddress);
|
|
11207
|
-
const { clmm_pool, integrate } = this.sdk.sdkOptions;
|
|
11292
|
+
const { clmm_pool, almm_pool, integrate } = this.sdk.sdkOptions;
|
|
11208
11293
|
const { global_config_id } = getPackagerConfigs(clmm_pool);
|
|
11294
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
11209
11295
|
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
11210
11296
|
const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
11211
11297
|
const primaryCoinInputA = TransactionUtil.buildCoinForAmount(
|
|
@@ -11225,6 +11311,7 @@ var AlmmModule = class {
|
|
|
11225
11311
|
true
|
|
11226
11312
|
);
|
|
11227
11313
|
const args = [
|
|
11314
|
+
tx.object(almmConfig.factory),
|
|
11228
11315
|
tx.object(params.pair),
|
|
11229
11316
|
tx.object(global_config_id),
|
|
11230
11317
|
primaryCoinInputA.targetCoin,
|