@magmaprotocol/magma-clmm-sdk 0.5.115 → 0.5.117
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 +33 -13
- package/dist/index.js +102 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1598,7 +1598,7 @@ import BN10 from "bn.js";
|
|
|
1598
1598
|
// src/math/almmWeightToAmounts.ts
|
|
1599
1599
|
import BN9 from "bn.js";
|
|
1600
1600
|
import Decimal3 from "decimal.js";
|
|
1601
|
-
import { get_price_x128_from_real_id } from "@magmaprotocol/
|
|
1601
|
+
import { get_price_x128_from_real_id } from "@magmaprotocol/calc_almm";
|
|
1602
1602
|
function getPriceOfBinByBinId(binId, binStep) {
|
|
1603
1603
|
const twoDec = new Decimal3(2);
|
|
1604
1604
|
const price = new Decimal3(get_price_x128_from_real_id(binId, binStep));
|
|
@@ -2537,7 +2537,7 @@ var SplitSwap = class {
|
|
|
2537
2537
|
|
|
2538
2538
|
// src/math/bin.ts
|
|
2539
2539
|
import Decimal6 from "decimal.js";
|
|
2540
|
-
import { get_price_x128_from_real_id as get_price_x128_from_real_id2, get_real_id_from_price_x128 } from "@magmaprotocol/
|
|
2540
|
+
import { get_price_x128_from_real_id as get_price_x128_from_real_id2, get_real_id_from_price_x128 } from "@magmaprotocol/calc_almm";
|
|
2541
2541
|
var BinMath = class {
|
|
2542
2542
|
static getPriceOfBinByBinId(binId, binStep, decimalsA, decimalsB) {
|
|
2543
2543
|
const twoDec = new Decimal6(2);
|
|
@@ -2547,7 +2547,10 @@ var BinMath = class {
|
|
|
2547
2547
|
static getBinIdFromPrice(price, binStep, decimalsA, decimalsB) {
|
|
2548
2548
|
const twoDec = new Decimal6(2);
|
|
2549
2549
|
const tenDec = new Decimal6(10);
|
|
2550
|
-
const realid = get_real_id_from_price_x128(
|
|
2550
|
+
const realid = get_real_id_from_price_x128(
|
|
2551
|
+
new Decimal6(price).mul(tenDec.pow(decimalsB - decimalsA)).mul(twoDec.pow(128)).toDecimalPlaces(0).toString(),
|
|
2552
|
+
binStep
|
|
2553
|
+
);
|
|
2551
2554
|
return realid;
|
|
2552
2555
|
}
|
|
2553
2556
|
};
|
|
@@ -5178,6 +5181,7 @@ var PoolModule = class {
|
|
|
5178
5181
|
}
|
|
5179
5182
|
return dataPage;
|
|
5180
5183
|
}
|
|
5184
|
+
// TODO: 实现这个方法为almm
|
|
5181
5185
|
/**
|
|
5182
5186
|
* Gets a list of pools.
|
|
5183
5187
|
* @param {string[]} assignPools An array of pool IDs to get.
|
|
@@ -10422,7 +10426,7 @@ import {
|
|
|
10422
10426
|
get_real_id,
|
|
10423
10427
|
get_real_id_from_price_x128 as get_real_id_from_price_x1282,
|
|
10424
10428
|
get_storage_id_from_real_id
|
|
10425
|
-
} from "@magmaprotocol/
|
|
10429
|
+
} from "@magmaprotocol/calc_almm";
|
|
10426
10430
|
import Decimal10 from "decimal.js";
|
|
10427
10431
|
import BN22 from "bn.js";
|
|
10428
10432
|
var AlmmModule = class {
|
|
@@ -10434,6 +10438,37 @@ var AlmmModule = class {
|
|
|
10434
10438
|
get sdk() {
|
|
10435
10439
|
return this._sdk;
|
|
10436
10440
|
}
|
|
10441
|
+
async getPools(paginationArgs = "all", forceRefresh = false) {
|
|
10442
|
+
const { package_id } = this._sdk.sdkOptions.almm_pool;
|
|
10443
|
+
const allPools = [];
|
|
10444
|
+
const cacheKey = `${package_id}_getInitCreatePairEvent`;
|
|
10445
|
+
const cacheData = this.getCache(cacheKey, forceRefresh);
|
|
10446
|
+
if (cacheData !== void 0) {
|
|
10447
|
+
allPools.push(...cacheData);
|
|
10448
|
+
}
|
|
10449
|
+
if (allPools.length === 0) {
|
|
10450
|
+
try {
|
|
10451
|
+
const moveEventType = `${package_id}::almm_pair::EventCreatePair`;
|
|
10452
|
+
const objects = await this._sdk.fullClient.queryEventsByPage({ MoveEventType: moveEventType }, paginationArgs);
|
|
10453
|
+
const dataPage = {
|
|
10454
|
+
data: [],
|
|
10455
|
+
hasNextPage: false
|
|
10456
|
+
};
|
|
10457
|
+
dataPage.hasNextPage = objects.hasNextPage;
|
|
10458
|
+
dataPage.nextCursor = objects.nextCursor;
|
|
10459
|
+
objects.data.forEach((object) => {
|
|
10460
|
+
const fields = object.parsedJson;
|
|
10461
|
+
if (fields) {
|
|
10462
|
+
allPools.push(fields);
|
|
10463
|
+
}
|
|
10464
|
+
});
|
|
10465
|
+
this.updateCache(cacheKey, allPools, cacheTime24h);
|
|
10466
|
+
} catch (error) {
|
|
10467
|
+
console.log("getCreatePairEvents", error);
|
|
10468
|
+
}
|
|
10469
|
+
}
|
|
10470
|
+
return allPools;
|
|
10471
|
+
}
|
|
10437
10472
|
async getPoolInfo(pools) {
|
|
10438
10473
|
const cachePoolList = [];
|
|
10439
10474
|
pools = pools.filter((poolID) => {
|
|
@@ -10475,7 +10510,8 @@ var AlmmModule = class {
|
|
|
10475
10510
|
coinAmountA: fields.reserve_x,
|
|
10476
10511
|
coinAmountB: fields.reserve_y,
|
|
10477
10512
|
liquidity: fields.liquidity,
|
|
10478
|
-
rewarder_infos: rewarders
|
|
10513
|
+
rewarder_infos: rewarders,
|
|
10514
|
+
params: fields.params.fields
|
|
10479
10515
|
};
|
|
10480
10516
|
poolList.push(poolInfo);
|
|
10481
10517
|
this.updateCache(`${fields.id.id}_getPoolObject`, poolInfo, cacheTime24h);
|
|
@@ -10513,7 +10549,8 @@ var AlmmModule = class {
|
|
|
10513
10549
|
index_reference: 0,
|
|
10514
10550
|
time_of_last_update: 0,
|
|
10515
10551
|
oracle_index: 0,
|
|
10516
|
-
active_index: 0
|
|
10552
|
+
active_index: 0,
|
|
10553
|
+
protocol_variable_share: 0
|
|
10517
10554
|
};
|
|
10518
10555
|
simulateRes.events?.forEach((item) => {
|
|
10519
10556
|
console.log(extractStructTagFromType(item.type).name);
|
|
@@ -10539,7 +10576,8 @@ var AlmmModule = class {
|
|
|
10539
10576
|
tx.object(global_config_id),
|
|
10540
10577
|
tx.pure.u64(params.base_fee),
|
|
10541
10578
|
tx.pure.u16(params.bin_step),
|
|
10542
|
-
tx.pure.u32(storage_id)
|
|
10579
|
+
tx.pure.u32(storage_id),
|
|
10580
|
+
tx.object(CLOCK_ADDRESS)
|
|
10543
10581
|
];
|
|
10544
10582
|
tx.moveCall({
|
|
10545
10583
|
target: `${integrate.published_at}::${AlmmScript}::create_pair`,
|
|
@@ -10817,13 +10855,20 @@ var AlmmModule = class {
|
|
|
10817
10855
|
async burnPosition(params) {
|
|
10818
10856
|
const tx = new Transaction12();
|
|
10819
10857
|
tx.setSender(this.sdk.senderAddress);
|
|
10820
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10858
|
+
const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
|
|
10821
10859
|
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10860
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
10822
10861
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10823
|
-
let args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10862
|
+
let args = [tx.object(almmConfig.factory), tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10824
10863
|
let target = `${integrate.published_at}::${AlmmScript}::burn_position`;
|
|
10825
10864
|
if (params.rewards_token.length > 0) {
|
|
10826
|
-
args = [
|
|
10865
|
+
args = [
|
|
10866
|
+
tx.object(almmConfig.factory),
|
|
10867
|
+
tx.object(params.pool_id),
|
|
10868
|
+
tx.object(clmmConfigs.global_vault_id),
|
|
10869
|
+
tx.object(params.position_id),
|
|
10870
|
+
tx.object(CLOCK_ADDRESS)
|
|
10871
|
+
];
|
|
10827
10872
|
target = `${integrate.published_at}::${AlmmScript}::burn_position_reward${params.rewards_token.length}`;
|
|
10828
10873
|
}
|
|
10829
10874
|
tx.moveCall({
|
|
@@ -10836,13 +10881,21 @@ var AlmmModule = class {
|
|
|
10836
10881
|
async shrinkPosition(params) {
|
|
10837
10882
|
const tx = new Transaction12();
|
|
10838
10883
|
tx.setSender(this.sdk.senderAddress);
|
|
10839
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10884
|
+
const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
|
|
10840
10885
|
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10886
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
10841
10887
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10842
|
-
let args = [
|
|
10888
|
+
let args = [
|
|
10889
|
+
tx.object(almmConfig.factory),
|
|
10890
|
+
tx.object(params.pool_id),
|
|
10891
|
+
tx.object(params.position_id),
|
|
10892
|
+
tx.pure.u64(params.delta_percentage),
|
|
10893
|
+
tx.object(CLOCK_ADDRESS)
|
|
10894
|
+
];
|
|
10843
10895
|
let target = `${integrate.published_at}::${AlmmScript}::shrink_position`;
|
|
10844
10896
|
if (params.rewards_token.length > 0) {
|
|
10845
10897
|
args = [
|
|
10898
|
+
tx.object(almmConfig.factory),
|
|
10846
10899
|
tx.object(params.pool_id),
|
|
10847
10900
|
tx.object(clmmConfigs.global_vault_id),
|
|
10848
10901
|
tx.object(params.position_id),
|
|
@@ -10879,10 +10932,12 @@ var AlmmModule = class {
|
|
|
10879
10932
|
async collectReward(params, transaction) {
|
|
10880
10933
|
const tx = transaction || new Transaction12();
|
|
10881
10934
|
tx.setSender(this.sdk.senderAddress);
|
|
10882
|
-
const { integrate, clmm_pool } = this.sdk.sdkOptions;
|
|
10935
|
+
const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
|
|
10883
10936
|
const clmmConfigs = getPackagerConfigs(clmm_pool);
|
|
10937
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
10884
10938
|
const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
|
|
10885
10939
|
const args = [
|
|
10940
|
+
tx.object(almmConfig.factory),
|
|
10886
10941
|
tx.object(params.pool_id),
|
|
10887
10942
|
tx.object(clmmConfigs.global_vault_id),
|
|
10888
10943
|
tx.object(params.position_id),
|
|
@@ -10902,9 +10957,10 @@ var AlmmModule = class {
|
|
|
10902
10957
|
async collectFees(params, transaction) {
|
|
10903
10958
|
const tx = transaction || new Transaction12();
|
|
10904
10959
|
tx.setSender(this.sdk.senderAddress);
|
|
10905
|
-
const { integrate } = this.sdk.sdkOptions;
|
|
10960
|
+
const { integrate, almm_pool } = this.sdk.sdkOptions;
|
|
10961
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
10906
10962
|
const typeArguments = [params.coin_a, params.coin_b];
|
|
10907
|
-
const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10963
|
+
const args = [tx.object(almmConfig.factory), tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
|
|
10908
10964
|
const target = `${integrate.published_at}::${AlmmScript}::collect_fees`;
|
|
10909
10965
|
tx.moveCall({
|
|
10910
10966
|
target,
|
|
@@ -10954,8 +11010,9 @@ var AlmmModule = class {
|
|
|
10954
11010
|
async swap(params) {
|
|
10955
11011
|
const tx = new Transaction12();
|
|
10956
11012
|
tx.setSender(this.sdk.senderAddress);
|
|
10957
|
-
const { clmm_pool, integrate } = this.sdk.sdkOptions;
|
|
11013
|
+
const { clmm_pool, almm_pool, integrate } = this.sdk.sdkOptions;
|
|
10958
11014
|
const { global_config_id } = getPackagerConfigs(clmm_pool);
|
|
11015
|
+
const almmConfig = getPackagerConfigs(almm_pool);
|
|
10959
11016
|
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10960
11017
|
const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10961
11018
|
const primaryCoinInputA = TransactionUtil.buildCoinForAmount(
|
|
@@ -10975,6 +11032,7 @@ var AlmmModule = class {
|
|
|
10975
11032
|
true
|
|
10976
11033
|
);
|
|
10977
11034
|
const args = [
|
|
11035
|
+
tx.object(almmConfig.factory),
|
|
10978
11036
|
tx.object(params.pair),
|
|
10979
11037
|
tx.object(global_config_id),
|
|
10980
11038
|
primaryCoinInputA.targetCoin,
|
|
@@ -11090,7 +11148,7 @@ var AlmmModule = class {
|
|
|
11090
11148
|
* @returns array of Position objects.
|
|
11091
11149
|
*/
|
|
11092
11150
|
async getUserPositionById(positionId, showDisplay = true) {
|
|
11093
|
-
|
|
11151
|
+
const allPosition = [];
|
|
11094
11152
|
const ownerRes = await this._sdk.fullClient.getObject({
|
|
11095
11153
|
id: positionId,
|
|
11096
11154
|
options: { showContent: true, showType: true, showDisplay, showOwner: true }
|
|
@@ -11111,6 +11169,7 @@ var AlmmModule = class {
|
|
|
11111
11169
|
* Gets a list of positions for the given account address.
|
|
11112
11170
|
* @param accountAddress The account address to get positions for.
|
|
11113
11171
|
* @param assignPoolIds An array of pool IDs to filter the positions by.
|
|
11172
|
+
* @param showDisplay When some testnet rpc nodes can't return object's display data, you can set this option to false, avoid returning errors. Default set true.
|
|
11114
11173
|
* @returns array of Position objects.
|
|
11115
11174
|
*/
|
|
11116
11175
|
async getUserPositions(accountAddress, assignPoolIds = [], showDisplay = true) {
|
|
@@ -11863,7 +11922,7 @@ var main_default = MagmaClmmSDK;
|
|
|
11863
11922
|
var SDKConfig = {
|
|
11864
11923
|
clmmConfig: {
|
|
11865
11924
|
pools_id: "0xfa145b9de10fe858be81edd1c6cdffcf27be9d016de02a1345eb1009a68ba8b2",
|
|
11866
|
-
// clmm and
|
|
11925
|
+
// clmm and almm both use this global_config
|
|
11867
11926
|
global_config_id: "0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a",
|
|
11868
11927
|
global_vault_id: "0xa7e1102f222b6eb81ccc8a126e7feb2353342be9df6f6646a77c4519da29c071",
|
|
11869
11928
|
admin_cap_id: "0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"
|
|
@@ -11912,8 +11971,8 @@ var clmmMainnet = {
|
|
|
11912
11971
|
config: SDKConfig.clmmConfig
|
|
11913
11972
|
},
|
|
11914
11973
|
almm_pool: {
|
|
11915
|
-
package_id: "",
|
|
11916
|
-
published_at: "",
|
|
11974
|
+
package_id: "0x17ec44d20706af7f4ca563be7424bfa07c190f7f47bec157fa1eedaeec0bae3d",
|
|
11975
|
+
published_at: "0x17ec44d20706af7f4ca563be7424bfa07c190f7f47bec157fa1eedaeec0bae3d",
|
|
11917
11976
|
config: SDKConfig.almmConfig
|
|
11918
11977
|
},
|
|
11919
11978
|
distribution: {
|
|
@@ -11921,8 +11980,8 @@ var clmmMainnet = {
|
|
|
11921
11980
|
published_at: "0xee4a1f231dc45a303389998fe26c4e39278cf68b404b32e4f0b9769129b8267b"
|
|
11922
11981
|
},
|
|
11923
11982
|
integrate: {
|
|
11924
|
-
package_id: "
|
|
11925
|
-
published_at: "
|
|
11983
|
+
package_id: "0x7701ae515703598d6f2451f4bfec857d3cba994fd3e1968b11110d674e3126c4",
|
|
11984
|
+
published_at: "0x7701ae515703598d6f2451f4bfec857d3cba994fd3e1968b11110d674e3126c4"
|
|
11926
11985
|
},
|
|
11927
11986
|
deepbook: {
|
|
11928
11987
|
package_id: "0x000000000000000000000000000000000000000000000000000000000000dee9",
|