@magmaprotocol/magma-clmm-sdk 0.5.49 → 0.5.51
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 +31 -2
- package/dist/index.js +124 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +124 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1824,6 +1824,30 @@ type BinDisplay = {
|
|
|
1824
1824
|
amountX: BN;
|
|
1825
1825
|
amountY: BN;
|
|
1826
1826
|
};
|
|
1827
|
+
type DlmmCreatePairAddLiquidityParams = {
|
|
1828
|
+
baseFee: number;
|
|
1829
|
+
binStep: number;
|
|
1830
|
+
coinTypeA: string;
|
|
1831
|
+
coinTypeB: string;
|
|
1832
|
+
activeId: number;
|
|
1833
|
+
storageIds: number[];
|
|
1834
|
+
amountsX: number[];
|
|
1835
|
+
amountsY: number[];
|
|
1836
|
+
to: string;
|
|
1837
|
+
};
|
|
1838
|
+
type DlmmPosition = {
|
|
1839
|
+
pos_object_id: SuiObjectIdType;
|
|
1840
|
+
owner: SuiObjectIdType;
|
|
1841
|
+
pool: SuiObjectIdType;
|
|
1842
|
+
type: SuiAddressType;
|
|
1843
|
+
bin_ids: number[];
|
|
1844
|
+
};
|
|
1845
|
+
type DlmmPositionInfo = {
|
|
1846
|
+
position: DlmmPosition;
|
|
1847
|
+
liquidity: EventPositionLiquidity;
|
|
1848
|
+
rewards: DlmmEventEarnedRewards;
|
|
1849
|
+
fees: DlmmEventEarnedFees;
|
|
1850
|
+
};
|
|
1827
1851
|
|
|
1828
1852
|
type BigNumber = Decimal.Value | number | string;
|
|
1829
1853
|
|
|
@@ -3707,13 +3731,18 @@ declare class DlmmModule implements IModule {
|
|
|
3707
3731
|
shrinkPosition(params: DlmmShrinkPosition): Promise<Transaction>;
|
|
3708
3732
|
collectReward(params: DlmmCollectRewardParams): Promise<Transaction>;
|
|
3709
3733
|
collectFees(params: DlmmCollectFeeParams): Promise<Transaction>;
|
|
3734
|
+
createPairAddLiquidity(params: DlmmCreatePairAddLiquidityParams): Promise<Transaction>;
|
|
3710
3735
|
swap(params: DLMMSwapParams): Promise<Transaction>;
|
|
3711
3736
|
fetchBins(params: FetchBinsParams): Promise<EventBin[]>;
|
|
3737
|
+
getUserPositions(who: string, showDisplay?: boolean): Promise<DlmmPositionInfo[]>;
|
|
3738
|
+
private buildPosition;
|
|
3739
|
+
private getPoolCoins;
|
|
3740
|
+
private buildPositionType;
|
|
3712
3741
|
getPositionLiquidity(params: GetPositionLiquidityParams): Promise<EventPositionLiquidity>;
|
|
3713
3742
|
getPairLiquidity(params: GetPairLiquidityParams): Promise<EventPairLiquidity>;
|
|
3714
3743
|
getEarnedFees(params: DlmmCollectFeeParams): Promise<DlmmEventEarnedFees>;
|
|
3715
3744
|
getEarnedRewards(params: DlmmRewardsParams): Promise<DlmmEventEarnedRewards>;
|
|
3716
|
-
getPairRewarders(params: GetPairRewarderParams[]): Promise<Map<string,
|
|
3745
|
+
getPairRewarders(params: GetPairRewarderParams[]): Promise<Map<string, string[]>>;
|
|
3717
3746
|
private _getPairRewarders;
|
|
3718
3747
|
private _parsePairRewarders;
|
|
3719
3748
|
}
|
|
@@ -4448,4 +4477,4 @@ interface InitMagmaSDKOptions {
|
|
|
4448
4477
|
*/
|
|
4449
4478
|
declare function initMagmaSDK(options: InitMagmaSDKOptions): MagmaClmmSDK;
|
|
4450
4479
|
|
|
4451
|
-
export { AMM_SWAP_MODULE, AddBribeReward, AddLiquidityCommonParams, AddLiquidityFixTokenParams, AddLiquidityParams, AddLiquidityWithProtectionParams, AddressAndDirection, AdjustResult, AggregatorResult, AmountSpecified, BasePath, BigNumber, BinDisplay, BinLiquidity, BinMath, Bits, BuildCoinResult, CLOCK_ADDRESS, CachedContent, CalculateRatesParams, CalculateRatesResult, ClaimAndLockParams, ClaimFeesParams, ClaimFeesPoolsParams, ClmmConfig, ClmmExpectSwapModule, ClmmFetcherModule, ClmmIntegratePoolModule, ClmmIntegratePoolV2Module, ClmmIntegratePoolV3Module, ClmmIntegrateRouterModule, ClmmIntegrateRouterWithPartnerModule, ClmmIntegrateUtilsModule, ClmmPartnerModule, ClmmPoolConfig, ClmmPoolUtil, ClmmPositionStatus, ClmmpoolData, ClosePositionParams, CoinAmounts, CoinAsset, CoinAssist, CoinConfig, CoinInfoAddress, CoinNode, CoinPairType, CoinProvider, CoinStoreAddress, CollectFeeParams, CollectFeesQuote, CollectFeesQuoteParam, CollectRewarderParams, ConfigModule, CreateLockParams, CreatePairParams, CreatePartnerEvent, CreatePoolAddLiquidityParams, CreatePoolParams, DEFAULT_GAS_BUDGET_FOR_MERGE, DEFAULT_GAS_BUDGET_FOR_SPLIT, DEFAULT_GAS_BUDGET_FOR_STAKE, DEFAULT_GAS_BUDGET_FOR_TRANSFER, DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI, DEFAULT_NFT_TRANSFER_GAS_FEE, DLMMSwapParams, DataPage, DeepbookClobV2Moudle, DeepbookCustodianV2Moudle, DeepbookEndpointsV2Moudle, DeepbookPool, DeepbookUtils, DepositPosition, DlmmAddLiquidityParams, DlmmBurnPositionParams, DlmmCollectFeeParams, DlmmCollectRewardParams, DlmmConfig, DlmmEventEarnedFees, DlmmEventEarnedRewards, DlmmEventPairRewardTypes, DlmmPoolInfo, DlmmRewardsParams, DlmmScript, DlmmShrinkPosition, EpochEmission, EventBin, EventPairLiquidity, EventPairParams, EventPositionLiquidity, FEE_RATE_DENOMINATOR, FaucetCoin, FetchBinsParams, FetchPairParams, FetchParams, GAS_SYMBOL, GAS_TYPE_ARG, GAS_TYPE_ARG_LONG, Gauge, GetPairLiquidityParams, GetPairRewarderParams, GetPositionLiquidityParams, GetRewardByPosition, IncreaseLockAmountParams, IncreaseUnlockTimeParams, LaunchpadPoolConfig, LiquidityAndCoinYResult, LiquidityInput, LockModule, LockPermanentParams, LockVoteEvent, MAX_SQRT_PRICE, MAX_TICK_INDEX, MIN_SQRT_PRICE, MIN_TICK_INDEX, MagmaClmmSDK, MagmaConfigs, MathUtil, MergeLockParams, MintAmountParams, MintPercentParams, Minter, NFT, ONE, OnePath, OpenPositionAddLiquidityWithProtectionParams, OpenPositionParams, Order, POOL_NO_LIQUIDITY, POOL_STRUCT, Package, PageQuery, PaginationArgs, PathLink, PathProvider, Percentage, PokeParams, Pool, PoolImmutables, PoolInfo, PoolModule, Position, PositionModule, PositionReward, PositionStatus, PositionUtil, PreRouterSwapParams, PreSwapLpChangeParams, PreSwapParams, PreSwapResult, PreSwapWithMultiPoolParams, PriceResult, RemoveLiquidityParams, RewardDistributor, Rewarder, RewarderAmountOwed, RouterModule, RouterModuleV2, RpcModule, SUI_SYSTEM_STATE_OBJECT_ID, SdkOptions, SplitPath, SplitSwap, SplitSwapResult, SplitUnit, StakedPositionOfPool, StrategyType, SuiAddressType, SuiBasicTypes, SuiInputTypes, SuiObjectDataWithContent, SuiObjectIdType, SuiResource, SuiStructTag, SuiTxArg, SwapDirection, SwapModule, SwapParams, SwapResult, SwapStepResult, SwapUtils, SwapWithRouterParams, TICK_ARRAY_SIZE, TWO, Tick, TickData, TickMath, TickUtil, TokenConfig, TokenConfigEvent, TokenInfo, TokenModule, TransPreSwapWithMultiPoolParams, TransactionUtil, TransferLockParams, TxBlock, U128, U128_MAX, U64_MAX, VoteParams, Voter, VotingEscrow, WithdrawPosition, ZERO, addHexPrefix, adjustForCoinSlippage, adjustForSlippage, asIntN, asUintN, autoFillXByStrategy, autoFillXByWeight, autoFillYByStrategy, autoFillYByWeight, bufferToHex, buildClmmPositionName, buildNFT, buildPool, buildPosition, buildPositionReward, buildTickData, buildTickDataByEvent, cacheTime24h, cacheTime5min, checkAddress, checkInvalidSuiAddress, clmmMainnet, clmmTestnet, collectFeesQuote, composeType, computeSwap, computeSwapStep, createSplitAmountArray, createSplitArray, createTestTransferTxPayloadParams, d, decimalsMultiplier, MagmaClmmSDK as default, estPoolAPR, estPosAPRResult, estPositionAPRWithDeltaMethod, estPositionAPRWithMultiMethod, estimateLiquidityForCoinA, estimateLiquidityForCoinB, extractAddressFromType, extractStructTagFromType, findAdjustCoin, fixCoinType, fixSuiObjectId, fromDecimalsAmount, getAmountFixedDelta, getAmountUnfixedDelta, getCoinAFromLiquidity, getCoinBFromLiquidity, getCoinXYForLiquidity, getDefaultSuiInputType, getDeltaA, getDeltaB, getDeltaDownFromOutput, getDeltaUpFromInput, getFutureTime, getLiquidityAndCoinYByCoinX, getLiquidityFromCoinA, getLiquidityFromCoinB, getLowerSqrtPriceFromCoinA, getLowerSqrtPriceFromCoinB, getMoveObject, getMoveObjectType, getMovePackageContent, getNearestTickByTick, getNextSqrtPriceAUp, getNextSqrtPriceBDown, getNextSqrtPriceFromInput, getNextSqrtPriceFromOutput, getObjectDeletedResponse, getObjectDisplay, getObjectFields, getObjectId, getObjectNotExistsResponse, getObjectOwner, getObjectPreviousTransactionDigest, getObjectReference, getObjectType, getObjectVersion, getPackagerConfigs, getPriceOfBinByBinId, getRewardInTickRange, getSuiObjectData, getTickDataFromUrlData, getUpperSqrtPriceFromCoinA, getUpperSqrtPriceFromCoinB, hasPublicTransfer, hexToNumber, hexToString, initMagmaSDK, initMainnetSDK, initTestnetSDK, isSortedSymbols, isSuiObjectResponse, newBits, normalizeCoinType, patchFixSuiObjectId, printTransaction, removeHexPrefix, secretKeyToEd25519Keypair, secretKeyToSecp256k1Keypair, shortAddress, shortString, tickScore, toAmountAskSide, toAmountBidSide, toAmountBothSide, toAmountsBothSideByStrategy, toBuffer, toCoinAmount, toDecimalsAmount, transClmmpoolDataWithoutTicks, utf8to16, withLiquiditySlippage };
|
|
4480
|
+
export { AMM_SWAP_MODULE, AddBribeReward, AddLiquidityCommonParams, AddLiquidityFixTokenParams, AddLiquidityParams, AddLiquidityWithProtectionParams, AddressAndDirection, AdjustResult, AggregatorResult, AmountSpecified, BasePath, BigNumber, BinDisplay, BinLiquidity, BinMath, Bits, BuildCoinResult, CLOCK_ADDRESS, CachedContent, CalculateRatesParams, CalculateRatesResult, ClaimAndLockParams, ClaimFeesParams, ClaimFeesPoolsParams, ClmmConfig, ClmmExpectSwapModule, ClmmFetcherModule, ClmmIntegratePoolModule, ClmmIntegratePoolV2Module, ClmmIntegratePoolV3Module, ClmmIntegrateRouterModule, ClmmIntegrateRouterWithPartnerModule, ClmmIntegrateUtilsModule, ClmmPartnerModule, ClmmPoolConfig, ClmmPoolUtil, ClmmPositionStatus, ClmmpoolData, ClosePositionParams, CoinAmounts, CoinAsset, CoinAssist, CoinConfig, CoinInfoAddress, CoinNode, CoinPairType, CoinProvider, CoinStoreAddress, CollectFeeParams, CollectFeesQuote, CollectFeesQuoteParam, CollectRewarderParams, ConfigModule, CreateLockParams, CreatePairParams, CreatePartnerEvent, CreatePoolAddLiquidityParams, CreatePoolParams, DEFAULT_GAS_BUDGET_FOR_MERGE, DEFAULT_GAS_BUDGET_FOR_SPLIT, DEFAULT_GAS_BUDGET_FOR_STAKE, DEFAULT_GAS_BUDGET_FOR_TRANSFER, DEFAULT_GAS_BUDGET_FOR_TRANSFER_SUI, DEFAULT_NFT_TRANSFER_GAS_FEE, DLMMSwapParams, DataPage, DeepbookClobV2Moudle, DeepbookCustodianV2Moudle, DeepbookEndpointsV2Moudle, DeepbookPool, DeepbookUtils, DepositPosition, DlmmAddLiquidityParams, DlmmBurnPositionParams, DlmmCollectFeeParams, DlmmCollectRewardParams, DlmmConfig, DlmmCreatePairAddLiquidityParams, DlmmEventEarnedFees, DlmmEventEarnedRewards, DlmmEventPairRewardTypes, DlmmPoolInfo, DlmmPosition, DlmmPositionInfo, DlmmRewardsParams, DlmmScript, DlmmShrinkPosition, EpochEmission, EventBin, EventPairLiquidity, EventPairParams, EventPositionLiquidity, FEE_RATE_DENOMINATOR, FaucetCoin, FetchBinsParams, FetchPairParams, FetchParams, GAS_SYMBOL, GAS_TYPE_ARG, GAS_TYPE_ARG_LONG, Gauge, GetPairLiquidityParams, GetPairRewarderParams, GetPositionLiquidityParams, GetRewardByPosition, IncreaseLockAmountParams, IncreaseUnlockTimeParams, LaunchpadPoolConfig, LiquidityAndCoinYResult, LiquidityInput, LockModule, LockPermanentParams, LockVoteEvent, MAX_SQRT_PRICE, MAX_TICK_INDEX, MIN_SQRT_PRICE, MIN_TICK_INDEX, MagmaClmmSDK, MagmaConfigs, MathUtil, MergeLockParams, MintAmountParams, MintPercentParams, Minter, NFT, ONE, OnePath, OpenPositionAddLiquidityWithProtectionParams, OpenPositionParams, Order, POOL_NO_LIQUIDITY, POOL_STRUCT, Package, PageQuery, PaginationArgs, PathLink, PathProvider, Percentage, PokeParams, Pool, PoolImmutables, PoolInfo, PoolModule, Position, PositionModule, PositionReward, PositionStatus, PositionUtil, PreRouterSwapParams, PreSwapLpChangeParams, PreSwapParams, PreSwapResult, PreSwapWithMultiPoolParams, PriceResult, RemoveLiquidityParams, RewardDistributor, Rewarder, RewarderAmountOwed, RouterModule, RouterModuleV2, RpcModule, SUI_SYSTEM_STATE_OBJECT_ID, SdkOptions, SplitPath, SplitSwap, SplitSwapResult, SplitUnit, StakedPositionOfPool, StrategyType, SuiAddressType, SuiBasicTypes, SuiInputTypes, SuiObjectDataWithContent, SuiObjectIdType, SuiResource, SuiStructTag, SuiTxArg, SwapDirection, SwapModule, SwapParams, SwapResult, SwapStepResult, SwapUtils, SwapWithRouterParams, TICK_ARRAY_SIZE, TWO, Tick, TickData, TickMath, TickUtil, TokenConfig, TokenConfigEvent, TokenInfo, TokenModule, TransPreSwapWithMultiPoolParams, TransactionUtil, TransferLockParams, TxBlock, U128, U128_MAX, U64_MAX, VoteParams, Voter, VotingEscrow, WithdrawPosition, ZERO, addHexPrefix, adjustForCoinSlippage, adjustForSlippage, asIntN, asUintN, autoFillXByStrategy, autoFillXByWeight, autoFillYByStrategy, autoFillYByWeight, bufferToHex, buildClmmPositionName, buildNFT, buildPool, buildPosition, buildPositionReward, buildTickData, buildTickDataByEvent, cacheTime24h, cacheTime5min, checkAddress, checkInvalidSuiAddress, clmmMainnet, clmmTestnet, collectFeesQuote, composeType, computeSwap, computeSwapStep, createSplitAmountArray, createSplitArray, createTestTransferTxPayloadParams, d, decimalsMultiplier, MagmaClmmSDK as default, estPoolAPR, estPosAPRResult, estPositionAPRWithDeltaMethod, estPositionAPRWithMultiMethod, estimateLiquidityForCoinA, estimateLiquidityForCoinB, extractAddressFromType, extractStructTagFromType, findAdjustCoin, fixCoinType, fixSuiObjectId, fromDecimalsAmount, getAmountFixedDelta, getAmountUnfixedDelta, getCoinAFromLiquidity, getCoinBFromLiquidity, getCoinXYForLiquidity, getDefaultSuiInputType, getDeltaA, getDeltaB, getDeltaDownFromOutput, getDeltaUpFromInput, getFutureTime, getLiquidityAndCoinYByCoinX, getLiquidityFromCoinA, getLiquidityFromCoinB, getLowerSqrtPriceFromCoinA, getLowerSqrtPriceFromCoinB, getMoveObject, getMoveObjectType, getMovePackageContent, getNearestTickByTick, getNextSqrtPriceAUp, getNextSqrtPriceBDown, getNextSqrtPriceFromInput, getNextSqrtPriceFromOutput, getObjectDeletedResponse, getObjectDisplay, getObjectFields, getObjectId, getObjectNotExistsResponse, getObjectOwner, getObjectPreviousTransactionDigest, getObjectReference, getObjectType, getObjectVersion, getPackagerConfigs, getPriceOfBinByBinId, getRewardInTickRange, getSuiObjectData, getTickDataFromUrlData, getUpperSqrtPriceFromCoinA, getUpperSqrtPriceFromCoinB, hasPublicTransfer, hexToNumber, hexToString, initMagmaSDK, initMainnetSDK, initTestnetSDK, isSortedSymbols, isSuiObjectResponse, newBits, normalizeCoinType, patchFixSuiObjectId, printTransaction, removeHexPrefix, secretKeyToEd25519Keypair, secretKeyToSecp256k1Keypair, shortAddress, shortString, tickScore, toAmountAskSide, toAmountBidSide, toAmountBothSide, toAmountsBothSideByStrategy, toBuffer, toCoinAmount, toDecimalsAmount, transClmmpoolDataWithoutTicks, utf8to16, withLiquiditySlippage };
|
package/dist/index.js
CHANGED
|
@@ -10724,8 +10724,8 @@ var GaugeModule = class {
|
|
|
10724
10724
|
|
|
10725
10725
|
// src/modules/dlmm.ts
|
|
10726
10726
|
var import_transactions12 = require("@mysten/sui/transactions");
|
|
10727
|
-
var import_decimal13 = __toESM(require("decimal.js"));
|
|
10728
10727
|
var import_calc_dlmm3 = require("@magmaprotocol/calc_dlmm");
|
|
10728
|
+
var import_decimal13 = __toESM(require("decimal.js"));
|
|
10729
10729
|
var DlmmModule = class {
|
|
10730
10730
|
_sdk;
|
|
10731
10731
|
constructor(sdk) {
|
|
@@ -11032,6 +11032,38 @@ var DlmmModule = class {
|
|
|
11032
11032
|
});
|
|
11033
11033
|
return tx;
|
|
11034
11034
|
}
|
|
11035
|
+
async createPairAddLiquidity(params) {
|
|
11036
|
+
const tx = new import_transactions12.Transaction();
|
|
11037
|
+
tx.setSender(this.sdk.senderAddress);
|
|
11038
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
11039
|
+
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
11040
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
11041
|
+
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
11042
|
+
const amountATotal = params.amountsX.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
11043
|
+
const amountBTotal = params.amountsY.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
|
|
11044
|
+
const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountATotal), params.coinTypeA, false, true);
|
|
11045
|
+
const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amountBTotal), params.coinTypeB, false, true);
|
|
11046
|
+
const args = [
|
|
11047
|
+
tx.object(dlmmConfig.factory),
|
|
11048
|
+
tx.pure.u64(params.baseFee),
|
|
11049
|
+
tx.pure.u16(params.binStep),
|
|
11050
|
+
tx.pure.u32(params.activeId),
|
|
11051
|
+
primaryCoinAInputs.targetCoin,
|
|
11052
|
+
primaryCoinBInputs.targetCoin,
|
|
11053
|
+
tx.pure.vector("u32", params.storageIds),
|
|
11054
|
+
tx.pure.vector("u64", params.amountsX),
|
|
11055
|
+
tx.pure.vector("u64", params.amountsY),
|
|
11056
|
+
tx.pure.address(params.to),
|
|
11057
|
+
tx.object(CLOCK_ADDRESS)
|
|
11058
|
+
];
|
|
11059
|
+
const target = `${integrate.published_at}::${DlmmScript}::create_pair_add_liquidity`;
|
|
11060
|
+
tx.moveCall({
|
|
11061
|
+
target,
|
|
11062
|
+
typeArguments,
|
|
11063
|
+
arguments: args
|
|
11064
|
+
});
|
|
11065
|
+
return tx;
|
|
11066
|
+
}
|
|
11035
11067
|
async swap(params) {
|
|
11036
11068
|
const tx = new import_transactions12.Transaction();
|
|
11037
11069
|
tx.setSender(this.sdk.senderAddress);
|
|
@@ -11082,6 +11114,95 @@ var DlmmModule = class {
|
|
|
11082
11114
|
});
|
|
11083
11115
|
return res;
|
|
11084
11116
|
}
|
|
11117
|
+
async getUserPositions(who, showDisplay = true) {
|
|
11118
|
+
const ownerRes = await this._sdk.fullClient.getOwnedObjectsByPage(who, {
|
|
11119
|
+
options: { showType: true, showContent: true, showDisplay, showOwner: true },
|
|
11120
|
+
filter: { Package: this._sdk.sdkOptions.dlmm_pool.package_id }
|
|
11121
|
+
});
|
|
11122
|
+
const positions = [];
|
|
11123
|
+
const pools = [];
|
|
11124
|
+
for (const item of ownerRes.data) {
|
|
11125
|
+
const type = extractStructTagFromType(item.data.type);
|
|
11126
|
+
if (type.full_address === this.buildPositionType()) {
|
|
11127
|
+
const position = this.buildPosition(item);
|
|
11128
|
+
positions.push(position);
|
|
11129
|
+
if (!pools.includes(position.pool)) {
|
|
11130
|
+
pools.push(position.pool);
|
|
11131
|
+
}
|
|
11132
|
+
}
|
|
11133
|
+
}
|
|
11134
|
+
const pool_coins = await this.getPoolCoins(pools);
|
|
11135
|
+
const _params = [];
|
|
11136
|
+
for (const [key, value] of pool_coins.entries()) {
|
|
11137
|
+
_params.push({
|
|
11138
|
+
pool_id: key,
|
|
11139
|
+
coin_a: value[0],
|
|
11140
|
+
coin_b: value[1]
|
|
11141
|
+
});
|
|
11142
|
+
}
|
|
11143
|
+
const pool_reward_coins = await this.getPairRewarders(_params);
|
|
11144
|
+
const out = [];
|
|
11145
|
+
for (const item of positions) {
|
|
11146
|
+
const coins = pool_coins.get(item.pool) || ["", ""];
|
|
11147
|
+
const positionLiquidity = await this.getPositionLiquidity({
|
|
11148
|
+
pair: item.pool,
|
|
11149
|
+
positionId: item.pos_object_id,
|
|
11150
|
+
coinTypeA: coins[0],
|
|
11151
|
+
coinTypeB: coins[1]
|
|
11152
|
+
});
|
|
11153
|
+
const positionRewards = await this.getEarnedRewards({
|
|
11154
|
+
pool_id: item.pool,
|
|
11155
|
+
position_id: item.pos_object_id,
|
|
11156
|
+
coin_a: coins[0],
|
|
11157
|
+
coin_b: coins[1],
|
|
11158
|
+
rewards_token: pool_reward_coins.get(item.pool) || []
|
|
11159
|
+
});
|
|
11160
|
+
const positionFees = await this.getEarnedFees({
|
|
11161
|
+
pool_id: item.pool,
|
|
11162
|
+
position_id: item.pos_object_id,
|
|
11163
|
+
coin_a: coins[0],
|
|
11164
|
+
coin_b: coins[1]
|
|
11165
|
+
});
|
|
11166
|
+
out.push({
|
|
11167
|
+
position: item,
|
|
11168
|
+
liquidity: positionLiquidity,
|
|
11169
|
+
rewards: positionRewards,
|
|
11170
|
+
fees: positionFees
|
|
11171
|
+
});
|
|
11172
|
+
}
|
|
11173
|
+
return out;
|
|
11174
|
+
}
|
|
11175
|
+
buildPosition(object) {
|
|
11176
|
+
if (object.error != null || object.data?.content?.dataType !== "moveObject") {
|
|
11177
|
+
throw new ClmmpoolsError(`Dlmm Position not exists. Get Position error:${object.error}`, "InvalidPositionObject" /* InvalidPositionObject */);
|
|
11178
|
+
}
|
|
11179
|
+
const fields = getObjectFields(object);
|
|
11180
|
+
const ownerWarp = getObjectOwner(object);
|
|
11181
|
+
return {
|
|
11182
|
+
pos_object_id: fields.id.id,
|
|
11183
|
+
owner: ownerWarp.AddressOwner,
|
|
11184
|
+
pool: fields.pair_id,
|
|
11185
|
+
bin_ids: fields.bin_ids,
|
|
11186
|
+
type: ""
|
|
11187
|
+
};
|
|
11188
|
+
}
|
|
11189
|
+
// return [coin_a, coin_b]
|
|
11190
|
+
async getPoolCoins(pools) {
|
|
11191
|
+
const res = await this._sdk.fullClient.multiGetObjects({ ids: pools, options: { showContent: true } });
|
|
11192
|
+
const poolCoins = /* @__PURE__ */ new Map();
|
|
11193
|
+
res.forEach((item) => {
|
|
11194
|
+
if (item.error != null || item.data?.content?.dataType !== "moveObject") {
|
|
11195
|
+
throw new Error(`Failed to get poolCoins with err: ${item.error}`);
|
|
11196
|
+
}
|
|
11197
|
+
const type = getObjectType(item);
|
|
11198
|
+
const poolTypeFields = extractStructTagFromType(type);
|
|
11199
|
+
poolCoins.set(item.data.objectId, poolTypeFields.type_arguments);
|
|
11200
|
+
});
|
|
11201
|
+
return poolCoins;
|
|
11202
|
+
}
|
|
11203
|
+
buildPositionType() {
|
|
11204
|
+
return `${this._sdk.sdkOptions.dlmm_pool.package_id}::dlmm_position::Position`;
|
|
11205
|
+
}
|
|
11085
11206
|
async getPositionLiquidity(params) {
|
|
11086
11207
|
const tx = new import_transactions12.Transaction();
|
|
11087
11208
|
const { integrate, simulationAccount } = this.sdk.sdkOptions;
|
|
@@ -11240,6 +11361,7 @@ var DlmmModule = class {
|
|
|
11240
11361
|
});
|
|
11241
11362
|
return out;
|
|
11242
11363
|
}
|
|
11364
|
+
// return pool_id => reward_tokens
|
|
11243
11365
|
async getPairRewarders(params) {
|
|
11244
11366
|
let tx = new import_transactions12.Transaction();
|
|
11245
11367
|
for (const param of params) {
|
|
@@ -11279,6 +11401,7 @@ var DlmmModule = class {
|
|
|
11279
11401
|
item.parsedJson.tokens.contents.forEach((token) => {
|
|
11280
11402
|
pairRewards.tokens.push(token.name);
|
|
11281
11403
|
});
|
|
11404
|
+
out.set(pairRewards.pair_id, pairRewards.tokens);
|
|
11282
11405
|
}
|
|
11283
11406
|
});
|
|
11284
11407
|
return out;
|