@mmt-finance/clmm-sui-sdk 1.0.0 → 1.0.1
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.mts +18 -17
- package/dist/index.d.ts +18 -17
- package/dist/index.js +36 -33
- package/dist/index.mjs +36 -33
- package/package.json +5 -2
- package/src/config.ts +6 -6
- package/src/modules/pool-module.ts +3 -3
- package/src/modules/position-module.ts +2 -2
- package/src/sdk.ts +11 -7
- package/src/utils/coin-utils.ts +7 -5
- package/src/utils/mvr/mvr-named-packages-plugin.ts +3 -2
- package/src/utils/pool-utils.ts +3 -3
- package/tsconfig.json +8 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Decimal$1, { Decimal } from 'decimal.js';
|
|
2
2
|
import * as _mysten_sui_transactions from '@mysten/sui/transactions';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Transaction, TransactionArgument, TransactionObjectArgument, TransactionDataBuilder, BuildTransactionOptions } from '@mysten/sui/transactions';
|
|
4
|
+
import { SuiJsonRpcClient, SuiParsedData } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import BN from 'bn.js';
|
|
6
6
|
|
|
7
7
|
interface PoolParams {
|
|
@@ -367,14 +367,14 @@ declare class PositionModule implements BaseModule {
|
|
|
367
367
|
constructor(sdk: MmtSDK);
|
|
368
368
|
get sdk(): MmtSDK;
|
|
369
369
|
openPosition(params: OpenPositionParams): {
|
|
370
|
-
$kind: "NestedResult";
|
|
371
370
|
NestedResult: [number, number];
|
|
371
|
+
$kind: "NestedResult";
|
|
372
372
|
} | undefined;
|
|
373
373
|
closePosition(params: ClosePositionParams): void;
|
|
374
374
|
private checkTickRangeValidity;
|
|
375
375
|
borrowMutRewardInfoObject(txb: Transaction, positionId: string | TransactionArgument, reward_index: number, useMvr?: boolean): {
|
|
376
|
-
$kind: "NestedResult";
|
|
377
376
|
NestedResult: [number, number];
|
|
377
|
+
$kind: "NestedResult";
|
|
378
378
|
} | undefined;
|
|
379
379
|
fetchPositionRpc(positionId: string): Promise<PositionRpc>;
|
|
380
380
|
getUserPositionsUsdValue(address: string, pools: ExtendedPool[], tokens: TokenSchema[]): Promise<({
|
|
@@ -399,7 +399,7 @@ declare class PositionModule implements BaseModule {
|
|
|
399
399
|
feeAmountX: number;
|
|
400
400
|
feeAmountY: number;
|
|
401
401
|
} | null)[]>;
|
|
402
|
-
fetchRewards(positions: any, pools: ExtendedPool[], address: string, client:
|
|
402
|
+
fetchRewards(positions: any, pools: ExtendedPool[], address: string, client: SuiJsonRpcClient): Promise<Record<string, RewardsData>>;
|
|
403
403
|
getCoinOwedReward(positionId: string | TransactionArgument, reward_index: number): Promise<string>;
|
|
404
404
|
getOwedCoinX(positionId: string | TransactionArgument): Promise<string>;
|
|
405
405
|
getOwedCoinY(positionId: string | TransactionArgument): Promise<string>;
|
|
@@ -441,10 +441,11 @@ interface SdkOptions {
|
|
|
441
441
|
suiClientUrl?: string;
|
|
442
442
|
customHeaders?: HeadersInit;
|
|
443
443
|
mvrEndpoint?: string;
|
|
444
|
-
client?:
|
|
444
|
+
client?: SuiJsonRpcClient;
|
|
445
|
+
customRpcNetwork?: 'mainnet' | 'testnet';
|
|
445
446
|
}
|
|
446
447
|
declare class MmtSDK {
|
|
447
|
-
protected readonly rpcModule:
|
|
448
|
+
protected readonly rpcModule: SuiJsonRpcClient;
|
|
448
449
|
protected readonly poolModule: PoolModule;
|
|
449
450
|
protected readonly positionModule: PositionModule;
|
|
450
451
|
protected readonly routeModule: RouteModule;
|
|
@@ -452,7 +453,7 @@ declare class MmtSDK {
|
|
|
452
453
|
readonly sdkConfig: SdkConfig;
|
|
453
454
|
readonly mvrNamedPackagesPlugin: (transactionData: TransactionDataBuilder, _buildOptions: BuildTransactionOptions, next: () => Promise<void>) => Promise<void>;
|
|
454
455
|
constructor(options?: SdkOptions);
|
|
455
|
-
get rpcClient():
|
|
456
|
+
get rpcClient(): SuiJsonRpcClient;
|
|
456
457
|
get Pool(): PoolModule;
|
|
457
458
|
get Position(): PositionModule;
|
|
458
459
|
get Route(): RouteModule;
|
|
@@ -476,12 +477,12 @@ declare class PoolModule {
|
|
|
476
477
|
} | undefined;
|
|
477
478
|
addLiquidity({ txb, pool, position, coinX, coinY, minAmountX, minAmountY, transferToAddress, useMvr, }: AddLiquidityParams): Promise<{
|
|
478
479
|
coinA: {
|
|
479
|
-
$kind: "NestedResult";
|
|
480
480
|
NestedResult: [number, number];
|
|
481
|
+
$kind: "NestedResult";
|
|
481
482
|
} | undefined;
|
|
482
483
|
coinB: {
|
|
483
|
-
$kind: "NestedResult";
|
|
484
484
|
NestedResult: [number, number];
|
|
485
|
+
$kind: "NestedResult";
|
|
485
486
|
} | undefined;
|
|
486
487
|
} | undefined>;
|
|
487
488
|
/**
|
|
@@ -502,12 +503,12 @@ declare class PoolModule {
|
|
|
502
503
|
} | null>;
|
|
503
504
|
removeLiquidity({ txb, pool, positionId, liquidity, minAmountX, minAmountY, transferToAddress, useMvr, }: RemoveLiquidityParams): {
|
|
504
505
|
removeLpCoinA: {
|
|
505
|
-
$kind: "NestedResult";
|
|
506
506
|
NestedResult: [number, number];
|
|
507
|
+
$kind: "NestedResult";
|
|
507
508
|
} | undefined;
|
|
508
509
|
removeLpCoinB: {
|
|
509
|
-
$kind: "NestedResult";
|
|
510
510
|
NestedResult: [number, number];
|
|
511
|
+
$kind: "NestedResult";
|
|
511
512
|
} | undefined;
|
|
512
513
|
} | undefined;
|
|
513
514
|
calcLiquidityAmounts({ amountA, amountB, decimalsA, decimalsB, currentSqrtPriceD, lowerSqrtPriceD, upperSqrtPriceD, }: {
|
|
@@ -538,19 +539,19 @@ declare class PoolModule {
|
|
|
538
539
|
rewarderApr: RewarderAPR[];
|
|
539
540
|
};
|
|
540
541
|
collectReward({ txb, pool, positionId, rewardCoinType, transferToAddress, useMvr, }: CollectRewardParams): {
|
|
541
|
-
$kind: "NestedResult";
|
|
542
542
|
NestedResult: [number, number];
|
|
543
|
+
$kind: "NestedResult";
|
|
543
544
|
} | undefined;
|
|
544
545
|
private _findRouteAndSwap;
|
|
545
546
|
claimRewardsAs({ txb, pool, positionId, rewarderCoinTypes, targetCoinType, slippage, toAddress, useMvr, pools, }: ClaimRewardsAsParams): Promise<TransactionObjectArgument | undefined>;
|
|
546
547
|
collectFee({ txb, pool, positionId, transferToAddress, useMvr }: CollectFeeParams): {
|
|
547
548
|
feeCoinA: {
|
|
548
|
-
$kind: "NestedResult";
|
|
549
549
|
NestedResult: [number, number];
|
|
550
|
+
$kind: "NestedResult";
|
|
550
551
|
} | undefined;
|
|
551
552
|
feeCoinB: {
|
|
552
|
-
$kind: "NestedResult";
|
|
553
553
|
NestedResult: [number, number];
|
|
554
|
+
$kind: "NestedResult";
|
|
554
555
|
} | undefined;
|
|
555
556
|
} | undefined;
|
|
556
557
|
/**
|
|
@@ -684,9 +685,9 @@ declare function getCoinXYForLiquidity(liquidity: Decimal$1.Instance, reserveInS
|
|
|
684
685
|
declare function estimateLiquidityForCoinA(sqrtPriceX: BN, sqrtPriceY: BN, coinAmount: BN): BN;
|
|
685
686
|
declare function estimateLiquidityForCoinB(sqrtPriceX: BN, sqrtPriceY: BN, coinAmount: BN): BN;
|
|
686
687
|
declare function estLiquidityAndcoinAmountFromOneAmounts(lowerTick: number, upperTick: number, coinAmount: BN, iscoinA: boolean, roundUp: boolean, slippage: number, curSqrtPrice: BN): LiquidityInput;
|
|
687
|
-
declare const fetchUserObjectsByPkg: (client:
|
|
688
|
+
declare const fetchUserObjectsByPkg: (client: SuiJsonRpcClient, packageId: string, address: string) => Promise<SuiParsedData[]>;
|
|
688
689
|
declare function getLimitSqrtPriceUsingSlippage({ currentSqrtPrice, tokenX, tokenY, slippagePercentage, isTokenX, }: Pick<ExtendedPool, 'poolId' | 'tokenX' | 'tokenY'> & {
|
|
689
|
-
client:
|
|
690
|
+
client: SuiJsonRpcClient;
|
|
690
691
|
currentSqrtPrice?: string;
|
|
691
692
|
slippagePercentage: number;
|
|
692
693
|
isTokenX: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Decimal$1, { Decimal } from 'decimal.js';
|
|
2
2
|
import * as _mysten_sui_transactions from '@mysten/sui/transactions';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Transaction, TransactionArgument, TransactionObjectArgument, TransactionDataBuilder, BuildTransactionOptions } from '@mysten/sui/transactions';
|
|
4
|
+
import { SuiJsonRpcClient, SuiParsedData } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import BN from 'bn.js';
|
|
6
6
|
|
|
7
7
|
interface PoolParams {
|
|
@@ -367,14 +367,14 @@ declare class PositionModule implements BaseModule {
|
|
|
367
367
|
constructor(sdk: MmtSDK);
|
|
368
368
|
get sdk(): MmtSDK;
|
|
369
369
|
openPosition(params: OpenPositionParams): {
|
|
370
|
-
$kind: "NestedResult";
|
|
371
370
|
NestedResult: [number, number];
|
|
371
|
+
$kind: "NestedResult";
|
|
372
372
|
} | undefined;
|
|
373
373
|
closePosition(params: ClosePositionParams): void;
|
|
374
374
|
private checkTickRangeValidity;
|
|
375
375
|
borrowMutRewardInfoObject(txb: Transaction, positionId: string | TransactionArgument, reward_index: number, useMvr?: boolean): {
|
|
376
|
-
$kind: "NestedResult";
|
|
377
376
|
NestedResult: [number, number];
|
|
377
|
+
$kind: "NestedResult";
|
|
378
378
|
} | undefined;
|
|
379
379
|
fetchPositionRpc(positionId: string): Promise<PositionRpc>;
|
|
380
380
|
getUserPositionsUsdValue(address: string, pools: ExtendedPool[], tokens: TokenSchema[]): Promise<({
|
|
@@ -399,7 +399,7 @@ declare class PositionModule implements BaseModule {
|
|
|
399
399
|
feeAmountX: number;
|
|
400
400
|
feeAmountY: number;
|
|
401
401
|
} | null)[]>;
|
|
402
|
-
fetchRewards(positions: any, pools: ExtendedPool[], address: string, client:
|
|
402
|
+
fetchRewards(positions: any, pools: ExtendedPool[], address: string, client: SuiJsonRpcClient): Promise<Record<string, RewardsData>>;
|
|
403
403
|
getCoinOwedReward(positionId: string | TransactionArgument, reward_index: number): Promise<string>;
|
|
404
404
|
getOwedCoinX(positionId: string | TransactionArgument): Promise<string>;
|
|
405
405
|
getOwedCoinY(positionId: string | TransactionArgument): Promise<string>;
|
|
@@ -441,10 +441,11 @@ interface SdkOptions {
|
|
|
441
441
|
suiClientUrl?: string;
|
|
442
442
|
customHeaders?: HeadersInit;
|
|
443
443
|
mvrEndpoint?: string;
|
|
444
|
-
client?:
|
|
444
|
+
client?: SuiJsonRpcClient;
|
|
445
|
+
customRpcNetwork?: 'mainnet' | 'testnet';
|
|
445
446
|
}
|
|
446
447
|
declare class MmtSDK {
|
|
447
|
-
protected readonly rpcModule:
|
|
448
|
+
protected readonly rpcModule: SuiJsonRpcClient;
|
|
448
449
|
protected readonly poolModule: PoolModule;
|
|
449
450
|
protected readonly positionModule: PositionModule;
|
|
450
451
|
protected readonly routeModule: RouteModule;
|
|
@@ -452,7 +453,7 @@ declare class MmtSDK {
|
|
|
452
453
|
readonly sdkConfig: SdkConfig;
|
|
453
454
|
readonly mvrNamedPackagesPlugin: (transactionData: TransactionDataBuilder, _buildOptions: BuildTransactionOptions, next: () => Promise<void>) => Promise<void>;
|
|
454
455
|
constructor(options?: SdkOptions);
|
|
455
|
-
get rpcClient():
|
|
456
|
+
get rpcClient(): SuiJsonRpcClient;
|
|
456
457
|
get Pool(): PoolModule;
|
|
457
458
|
get Position(): PositionModule;
|
|
458
459
|
get Route(): RouteModule;
|
|
@@ -476,12 +477,12 @@ declare class PoolModule {
|
|
|
476
477
|
} | undefined;
|
|
477
478
|
addLiquidity({ txb, pool, position, coinX, coinY, minAmountX, minAmountY, transferToAddress, useMvr, }: AddLiquidityParams): Promise<{
|
|
478
479
|
coinA: {
|
|
479
|
-
$kind: "NestedResult";
|
|
480
480
|
NestedResult: [number, number];
|
|
481
|
+
$kind: "NestedResult";
|
|
481
482
|
} | undefined;
|
|
482
483
|
coinB: {
|
|
483
|
-
$kind: "NestedResult";
|
|
484
484
|
NestedResult: [number, number];
|
|
485
|
+
$kind: "NestedResult";
|
|
485
486
|
} | undefined;
|
|
486
487
|
} | undefined>;
|
|
487
488
|
/**
|
|
@@ -502,12 +503,12 @@ declare class PoolModule {
|
|
|
502
503
|
} | null>;
|
|
503
504
|
removeLiquidity({ txb, pool, positionId, liquidity, minAmountX, minAmountY, transferToAddress, useMvr, }: RemoveLiquidityParams): {
|
|
504
505
|
removeLpCoinA: {
|
|
505
|
-
$kind: "NestedResult";
|
|
506
506
|
NestedResult: [number, number];
|
|
507
|
+
$kind: "NestedResult";
|
|
507
508
|
} | undefined;
|
|
508
509
|
removeLpCoinB: {
|
|
509
|
-
$kind: "NestedResult";
|
|
510
510
|
NestedResult: [number, number];
|
|
511
|
+
$kind: "NestedResult";
|
|
511
512
|
} | undefined;
|
|
512
513
|
} | undefined;
|
|
513
514
|
calcLiquidityAmounts({ amountA, amountB, decimalsA, decimalsB, currentSqrtPriceD, lowerSqrtPriceD, upperSqrtPriceD, }: {
|
|
@@ -538,19 +539,19 @@ declare class PoolModule {
|
|
|
538
539
|
rewarderApr: RewarderAPR[];
|
|
539
540
|
};
|
|
540
541
|
collectReward({ txb, pool, positionId, rewardCoinType, transferToAddress, useMvr, }: CollectRewardParams): {
|
|
541
|
-
$kind: "NestedResult";
|
|
542
542
|
NestedResult: [number, number];
|
|
543
|
+
$kind: "NestedResult";
|
|
543
544
|
} | undefined;
|
|
544
545
|
private _findRouteAndSwap;
|
|
545
546
|
claimRewardsAs({ txb, pool, positionId, rewarderCoinTypes, targetCoinType, slippage, toAddress, useMvr, pools, }: ClaimRewardsAsParams): Promise<TransactionObjectArgument | undefined>;
|
|
546
547
|
collectFee({ txb, pool, positionId, transferToAddress, useMvr }: CollectFeeParams): {
|
|
547
548
|
feeCoinA: {
|
|
548
|
-
$kind: "NestedResult";
|
|
549
549
|
NestedResult: [number, number];
|
|
550
|
+
$kind: "NestedResult";
|
|
550
551
|
} | undefined;
|
|
551
552
|
feeCoinB: {
|
|
552
|
-
$kind: "NestedResult";
|
|
553
553
|
NestedResult: [number, number];
|
|
554
|
+
$kind: "NestedResult";
|
|
554
555
|
} | undefined;
|
|
555
556
|
} | undefined;
|
|
556
557
|
/**
|
|
@@ -684,9 +685,9 @@ declare function getCoinXYForLiquidity(liquidity: Decimal$1.Instance, reserveInS
|
|
|
684
685
|
declare function estimateLiquidityForCoinA(sqrtPriceX: BN, sqrtPriceY: BN, coinAmount: BN): BN;
|
|
685
686
|
declare function estimateLiquidityForCoinB(sqrtPriceX: BN, sqrtPriceY: BN, coinAmount: BN): BN;
|
|
686
687
|
declare function estLiquidityAndcoinAmountFromOneAmounts(lowerTick: number, upperTick: number, coinAmount: BN, iscoinA: boolean, roundUp: boolean, slippage: number, curSqrtPrice: BN): LiquidityInput;
|
|
687
|
-
declare const fetchUserObjectsByPkg: (client:
|
|
688
|
+
declare const fetchUserObjectsByPkg: (client: SuiJsonRpcClient, packageId: string, address: string) => Promise<SuiParsedData[]>;
|
|
688
689
|
declare function getLimitSqrtPriceUsingSlippage({ currentSqrtPrice, tokenX, tokenY, slippagePercentage, isTokenX, }: Pick<ExtendedPool, 'poolId' | 'tokenX' | 'tokenY'> & {
|
|
689
|
-
client:
|
|
690
|
+
client: SuiJsonRpcClient;
|
|
690
691
|
currentSqrtPrice?: string;
|
|
691
692
|
slippagePercentage: number;
|
|
692
693
|
isTokenX: boolean;
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var transactions = require('@mysten/sui/transactions');
|
|
|
5
5
|
var utils = require('@mysten/sui/utils');
|
|
6
6
|
var BN3 = require('bn.js');
|
|
7
7
|
var Decimal4 = require('decimal.js');
|
|
8
|
-
var
|
|
8
|
+
var jsonRpc = require('@mysten/sui/jsonRpc');
|
|
9
9
|
var ccGraph = require('@syntsugar/cc-graph');
|
|
10
10
|
|
|
11
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -969,26 +969,6 @@ var ClmmPoolsError = class _ClmmPoolsError extends Error {
|
|
|
969
969
|
return e instanceof _ClmmPoolsError && e.errorCode === code;
|
|
970
970
|
}
|
|
971
971
|
};
|
|
972
|
-
function isSUICoin(coinType) {
|
|
973
|
-
return utils.normalizeStructTag(coinType) === utils.normalizeStructTag(SUI_COIN_TYPE);
|
|
974
|
-
}
|
|
975
|
-
function formatCoinType(coinType) {
|
|
976
|
-
return isSUICoin(coinType) ? SUI_COIN_TYPE_FORMATTED : coinType;
|
|
977
|
-
}
|
|
978
|
-
function mergeCoins(coinObjects, txb) {
|
|
979
|
-
if (coinObjects.length === 1) {
|
|
980
|
-
return typeof coinObjects[0] === "string" ? txb.object(coinObjects[0]) : coinObjects[0];
|
|
981
|
-
}
|
|
982
|
-
const firstCoin = typeof coinObjects[0] === "string" ? txb.object(coinObjects[0]) : coinObjects[0];
|
|
983
|
-
if (!firstCoin) {
|
|
984
|
-
throw new ClmmPoolsError("First coin is not found", "FirstCoinNotFound" /* FirstCoinNotFound */);
|
|
985
|
-
}
|
|
986
|
-
txb.mergeCoins(
|
|
987
|
-
firstCoin,
|
|
988
|
-
coinObjects.slice(1).map((coin) => typeof coin === "string" ? txb.object(coin) : coin)
|
|
989
|
-
);
|
|
990
|
-
return firstCoin;
|
|
991
|
-
}
|
|
992
972
|
|
|
993
973
|
// src/utils/common.ts
|
|
994
974
|
function txnArgument(object, tx) {
|
|
@@ -1014,6 +994,28 @@ function transformPositionRpcObject(initialObject) {
|
|
|
1014
994
|
}))
|
|
1015
995
|
};
|
|
1016
996
|
}
|
|
997
|
+
|
|
998
|
+
// src/utils/coin-utils.ts
|
|
999
|
+
function isSUICoin(coinType) {
|
|
1000
|
+
return utils.normalizeStructTag(coinType) === utils.normalizeStructTag(SUI_COIN_TYPE);
|
|
1001
|
+
}
|
|
1002
|
+
function formatCoinType(coinType) {
|
|
1003
|
+
return isSUICoin(coinType) ? SUI_COIN_TYPE_FORMATTED : coinType;
|
|
1004
|
+
}
|
|
1005
|
+
function mergeCoins(coinObjects, txb) {
|
|
1006
|
+
if (coinObjects.length === 1) {
|
|
1007
|
+
return typeof coinObjects[0] === "string" ? txb.object(coinObjects[0]) : coinObjects[0];
|
|
1008
|
+
}
|
|
1009
|
+
const firstCoin = typeof coinObjects[0] === "string" ? txb.object(coinObjects[0]) : coinObjects[0];
|
|
1010
|
+
if (!firstCoin) {
|
|
1011
|
+
throw new ClmmPoolsError("First coin is not found", "FirstCoinNotFound" /* FirstCoinNotFound */);
|
|
1012
|
+
}
|
|
1013
|
+
txb.mergeCoins(
|
|
1014
|
+
txnArgument(firstCoin, txb),
|
|
1015
|
+
coinObjects.slice(1).map((coin) => txnArgument(coin, txb))
|
|
1016
|
+
);
|
|
1017
|
+
return firstCoin;
|
|
1018
|
+
}
|
|
1017
1019
|
var MathUtil = class {
|
|
1018
1020
|
static toX64_BN(num) {
|
|
1019
1021
|
return num.mul(new BN3__default.default(2).pow(new BN3__default.default(64)));
|
|
@@ -2116,7 +2118,7 @@ var PoolModule = class {
|
|
|
2116
2118
|
arguments: [isXtoY ? txnArgument(receiveB, txb) : txnArgument(receiveA, txb)]
|
|
2117
2119
|
});
|
|
2118
2120
|
if (transferToAddress && utils.isValidSuiAddress(transferToAddress)) {
|
|
2119
|
-
txb.transferObjects([inputCoin], txb.pure.address(transferToAddress));
|
|
2121
|
+
txb.transferObjects([txnArgument(inputCoin, txb)], txb.pure.address(transferToAddress));
|
|
2120
2122
|
txb.transferObjects([outputCoin], txb.pure.address(transferToAddress));
|
|
2121
2123
|
} else {
|
|
2122
2124
|
return {
|
|
@@ -2215,7 +2217,7 @@ var PoolModule = class {
|
|
|
2215
2217
|
isXtoY,
|
|
2216
2218
|
limitSqrtPrice,
|
|
2217
2219
|
useMvr
|
|
2218
|
-
}) || { outputCoin: void 0
|
|
2220
|
+
}) || { outputCoin: void 0};
|
|
2219
2221
|
const outputCoinAmount = txb.moveCall({
|
|
2220
2222
|
target: "0x2::coin::value",
|
|
2221
2223
|
arguments: [txnArgument(outputCoin, txb)],
|
|
@@ -2545,7 +2547,7 @@ var PoolModule = class {
|
|
|
2545
2547
|
useMvr
|
|
2546
2548
|
}) || { outputCoin: void 0, leftoverCoin: void 0 };
|
|
2547
2549
|
if (leftoverCoin) {
|
|
2548
|
-
txb.transferObjects([leftoverCoin], txb.pure.address(toAddress));
|
|
2550
|
+
txb.transferObjects([txnArgument(leftoverCoin, txb)], txb.pure.address(toAddress));
|
|
2549
2551
|
}
|
|
2550
2552
|
currentCoin = outputCoin ?? currentCoin;
|
|
2551
2553
|
currentCoinType = isXtoY ? swapPool.tokenYType : swapPool.tokenXType;
|
|
@@ -3530,13 +3532,13 @@ var MainnetConfig = {
|
|
|
3530
3532
|
};
|
|
3531
3533
|
var TestnetConfig = {
|
|
3532
3534
|
clmm: {
|
|
3533
|
-
packageId: "
|
|
3534
|
-
publishedAt: "
|
|
3535
|
-
aclId: "
|
|
3536
|
-
adminCapId: "
|
|
3535
|
+
packageId: "0xcf548a43151dafca6ed4b7bcbb17698eac0bf5c761d9458c53719a8a004dda02",
|
|
3536
|
+
publishedAt: "0xcf548a43151dafca6ed4b7bcbb17698eac0bf5c761d9458c53719a8a004dda02",
|
|
3537
|
+
aclId: "0x14be48fa41942aa3b40fb23af60a3941ac18ee69ad7ef6816b20d8f44187484c",
|
|
3538
|
+
adminCapId: "0xcd25c030e26ec8dc47e47c1b785572fe33e702f0c029b9bb464081ead5d027fe",
|
|
3537
3539
|
slippageCheckPackageId: "0xfd6a45c396a90811fd93efaf585cc95c29aecd079c87822893f1e97e3fee8c50",
|
|
3538
|
-
globalConfigId: "
|
|
3539
|
-
versionId: "
|
|
3540
|
+
globalConfigId: "0x5c7929a413933b3bcec3cb6352274d358d2eeb7973233fa1e2b60ccf3a33691a",
|
|
3541
|
+
versionId: "0xda7375acbf29ebdf0e8a219db2baf363748882d186927c6f4001681d6251d522",
|
|
3540
3542
|
mvrName: ""
|
|
3541
3543
|
},
|
|
3542
3544
|
mmtApiUrl: "https://api-dev.mmt.finance",
|
|
@@ -4031,10 +4033,11 @@ var MmtSDK = class {
|
|
|
4031
4033
|
sdkConfig;
|
|
4032
4034
|
mvrNamedPackagesPlugin;
|
|
4033
4035
|
constructor(options) {
|
|
4034
|
-
if (options?.network === "custom" && !options?.contractConst) {
|
|
4035
|
-
throw new Error("missing contractConst for custom network");
|
|
4036
|
+
if (options?.network === "custom" && (!options?.contractConst || !options?.customRpcNetwork)) {
|
|
4037
|
+
throw new Error("missing contractConst or customRpcNetwork for custom network");
|
|
4036
4038
|
}
|
|
4037
4039
|
const network = options?.network || "mainnet";
|
|
4040
|
+
const rpcNetwork = options?.customRpcNetwork || network;
|
|
4038
4041
|
const defaultConfig = Config.getDefaultConfig(network);
|
|
4039
4042
|
const suiClientUrl = options?.suiClientUrl || defaultConfig.suiClientUrl;
|
|
4040
4043
|
const mvrEndpoint = options?.mvrEndpoint || defaultConfig.mvrEndpoint;
|
|
@@ -4049,7 +4052,7 @@ var MmtSDK = class {
|
|
|
4049
4052
|
mvrEndpoint,
|
|
4050
4053
|
customHeaders: options?.customHeaders
|
|
4051
4054
|
};
|
|
4052
|
-
this.rpcModule = options?.client ? options?.client : new
|
|
4055
|
+
this.rpcModule = options?.client ? options?.client : new jsonRpc.SuiJsonRpcClient({ url: suiClientUrl, network: rpcNetwork });
|
|
4053
4056
|
this.poolModule = new PoolModule(this);
|
|
4054
4057
|
this.positionModule = new PositionModule(this);
|
|
4055
4058
|
this.routeModule = new RouteModule(this);
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { Transaction } from '@mysten/sui/transactions';
|
|
|
3
3
|
import { parseStructTag, normalizeSuiAddress, normalizeSuiObjectId, isValidSuiAddress, normalizeStructTag, isValidNamedPackage, isValidNamedType } from '@mysten/sui/utils';
|
|
4
4
|
import BN3 from 'bn.js';
|
|
5
5
|
import Decimal4 from 'decimal.js';
|
|
6
|
-
import {
|
|
6
|
+
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
7
7
|
import { Graph, GraphVertex, GraphEdge } from '@syntsugar/cc-graph';
|
|
8
8
|
|
|
9
9
|
var __defProp = Object.defineProperty;
|
|
@@ -962,26 +962,6 @@ var ClmmPoolsError = class _ClmmPoolsError extends Error {
|
|
|
962
962
|
return e instanceof _ClmmPoolsError && e.errorCode === code;
|
|
963
963
|
}
|
|
964
964
|
};
|
|
965
|
-
function isSUICoin(coinType) {
|
|
966
|
-
return normalizeStructTag(coinType) === normalizeStructTag(SUI_COIN_TYPE);
|
|
967
|
-
}
|
|
968
|
-
function formatCoinType(coinType) {
|
|
969
|
-
return isSUICoin(coinType) ? SUI_COIN_TYPE_FORMATTED : coinType;
|
|
970
|
-
}
|
|
971
|
-
function mergeCoins(coinObjects, txb) {
|
|
972
|
-
if (coinObjects.length === 1) {
|
|
973
|
-
return typeof coinObjects[0] === "string" ? txb.object(coinObjects[0]) : coinObjects[0];
|
|
974
|
-
}
|
|
975
|
-
const firstCoin = typeof coinObjects[0] === "string" ? txb.object(coinObjects[0]) : coinObjects[0];
|
|
976
|
-
if (!firstCoin) {
|
|
977
|
-
throw new ClmmPoolsError("First coin is not found", "FirstCoinNotFound" /* FirstCoinNotFound */);
|
|
978
|
-
}
|
|
979
|
-
txb.mergeCoins(
|
|
980
|
-
firstCoin,
|
|
981
|
-
coinObjects.slice(1).map((coin) => typeof coin === "string" ? txb.object(coin) : coin)
|
|
982
|
-
);
|
|
983
|
-
return firstCoin;
|
|
984
|
-
}
|
|
985
965
|
|
|
986
966
|
// src/utils/common.ts
|
|
987
967
|
function txnArgument(object, tx) {
|
|
@@ -1007,6 +987,28 @@ function transformPositionRpcObject(initialObject) {
|
|
|
1007
987
|
}))
|
|
1008
988
|
};
|
|
1009
989
|
}
|
|
990
|
+
|
|
991
|
+
// src/utils/coin-utils.ts
|
|
992
|
+
function isSUICoin(coinType) {
|
|
993
|
+
return normalizeStructTag(coinType) === normalizeStructTag(SUI_COIN_TYPE);
|
|
994
|
+
}
|
|
995
|
+
function formatCoinType(coinType) {
|
|
996
|
+
return isSUICoin(coinType) ? SUI_COIN_TYPE_FORMATTED : coinType;
|
|
997
|
+
}
|
|
998
|
+
function mergeCoins(coinObjects, txb) {
|
|
999
|
+
if (coinObjects.length === 1) {
|
|
1000
|
+
return typeof coinObjects[0] === "string" ? txb.object(coinObjects[0]) : coinObjects[0];
|
|
1001
|
+
}
|
|
1002
|
+
const firstCoin = typeof coinObjects[0] === "string" ? txb.object(coinObjects[0]) : coinObjects[0];
|
|
1003
|
+
if (!firstCoin) {
|
|
1004
|
+
throw new ClmmPoolsError("First coin is not found", "FirstCoinNotFound" /* FirstCoinNotFound */);
|
|
1005
|
+
}
|
|
1006
|
+
txb.mergeCoins(
|
|
1007
|
+
txnArgument(firstCoin, txb),
|
|
1008
|
+
coinObjects.slice(1).map((coin) => txnArgument(coin, txb))
|
|
1009
|
+
);
|
|
1010
|
+
return firstCoin;
|
|
1011
|
+
}
|
|
1010
1012
|
var MathUtil = class {
|
|
1011
1013
|
static toX64_BN(num) {
|
|
1012
1014
|
return num.mul(new BN3(2).pow(new BN3(64)));
|
|
@@ -2109,7 +2111,7 @@ var PoolModule = class {
|
|
|
2109
2111
|
arguments: [isXtoY ? txnArgument(receiveB, txb) : txnArgument(receiveA, txb)]
|
|
2110
2112
|
});
|
|
2111
2113
|
if (transferToAddress && isValidSuiAddress(transferToAddress)) {
|
|
2112
|
-
txb.transferObjects([inputCoin], txb.pure.address(transferToAddress));
|
|
2114
|
+
txb.transferObjects([txnArgument(inputCoin, txb)], txb.pure.address(transferToAddress));
|
|
2113
2115
|
txb.transferObjects([outputCoin], txb.pure.address(transferToAddress));
|
|
2114
2116
|
} else {
|
|
2115
2117
|
return {
|
|
@@ -2208,7 +2210,7 @@ var PoolModule = class {
|
|
|
2208
2210
|
isXtoY,
|
|
2209
2211
|
limitSqrtPrice,
|
|
2210
2212
|
useMvr
|
|
2211
|
-
}) || { outputCoin: void 0
|
|
2213
|
+
}) || { outputCoin: void 0};
|
|
2212
2214
|
const outputCoinAmount = txb.moveCall({
|
|
2213
2215
|
target: "0x2::coin::value",
|
|
2214
2216
|
arguments: [txnArgument(outputCoin, txb)],
|
|
@@ -2538,7 +2540,7 @@ var PoolModule = class {
|
|
|
2538
2540
|
useMvr
|
|
2539
2541
|
}) || { outputCoin: void 0, leftoverCoin: void 0 };
|
|
2540
2542
|
if (leftoverCoin) {
|
|
2541
|
-
txb.transferObjects([leftoverCoin], txb.pure.address(toAddress));
|
|
2543
|
+
txb.transferObjects([txnArgument(leftoverCoin, txb)], txb.pure.address(toAddress));
|
|
2542
2544
|
}
|
|
2543
2545
|
currentCoin = outputCoin ?? currentCoin;
|
|
2544
2546
|
currentCoinType = isXtoY ? swapPool.tokenYType : swapPool.tokenXType;
|
|
@@ -3523,13 +3525,13 @@ var MainnetConfig = {
|
|
|
3523
3525
|
};
|
|
3524
3526
|
var TestnetConfig = {
|
|
3525
3527
|
clmm: {
|
|
3526
|
-
packageId: "
|
|
3527
|
-
publishedAt: "
|
|
3528
|
-
aclId: "
|
|
3529
|
-
adminCapId: "
|
|
3528
|
+
packageId: "0xcf548a43151dafca6ed4b7bcbb17698eac0bf5c761d9458c53719a8a004dda02",
|
|
3529
|
+
publishedAt: "0xcf548a43151dafca6ed4b7bcbb17698eac0bf5c761d9458c53719a8a004dda02",
|
|
3530
|
+
aclId: "0x14be48fa41942aa3b40fb23af60a3941ac18ee69ad7ef6816b20d8f44187484c",
|
|
3531
|
+
adminCapId: "0xcd25c030e26ec8dc47e47c1b785572fe33e702f0c029b9bb464081ead5d027fe",
|
|
3530
3532
|
slippageCheckPackageId: "0xfd6a45c396a90811fd93efaf585cc95c29aecd079c87822893f1e97e3fee8c50",
|
|
3531
|
-
globalConfigId: "
|
|
3532
|
-
versionId: "
|
|
3533
|
+
globalConfigId: "0x5c7929a413933b3bcec3cb6352274d358d2eeb7973233fa1e2b60ccf3a33691a",
|
|
3534
|
+
versionId: "0xda7375acbf29ebdf0e8a219db2baf363748882d186927c6f4001681d6251d522",
|
|
3533
3535
|
mvrName: ""
|
|
3534
3536
|
},
|
|
3535
3537
|
mmtApiUrl: "https://api-dev.mmt.finance",
|
|
@@ -4024,10 +4026,11 @@ var MmtSDK = class {
|
|
|
4024
4026
|
sdkConfig;
|
|
4025
4027
|
mvrNamedPackagesPlugin;
|
|
4026
4028
|
constructor(options) {
|
|
4027
|
-
if (options?.network === "custom" && !options?.contractConst) {
|
|
4028
|
-
throw new Error("missing contractConst for custom network");
|
|
4029
|
+
if (options?.network === "custom" && (!options?.contractConst || !options?.customRpcNetwork)) {
|
|
4030
|
+
throw new Error("missing contractConst or customRpcNetwork for custom network");
|
|
4029
4031
|
}
|
|
4030
4032
|
const network = options?.network || "mainnet";
|
|
4033
|
+
const rpcNetwork = options?.customRpcNetwork || network;
|
|
4031
4034
|
const defaultConfig = Config.getDefaultConfig(network);
|
|
4032
4035
|
const suiClientUrl = options?.suiClientUrl || defaultConfig.suiClientUrl;
|
|
4033
4036
|
const mvrEndpoint = options?.mvrEndpoint || defaultConfig.mvrEndpoint;
|
|
@@ -4042,7 +4045,7 @@ var MmtSDK = class {
|
|
|
4042
4045
|
mvrEndpoint,
|
|
4043
4046
|
customHeaders: options?.customHeaders
|
|
4044
4047
|
};
|
|
4045
|
-
this.rpcModule = options?.client ? options?.client : new
|
|
4048
|
+
this.rpcModule = options?.client ? options?.client : new SuiJsonRpcClient({ url: suiClientUrl, network: rpcNetwork });
|
|
4046
4049
|
this.poolModule = new PoolModule(this);
|
|
4047
4050
|
this.positionModule = new PositionModule(this);
|
|
4048
4051
|
this.routeModule = new RouteModule(this);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mmt-finance/clmm-sui-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Momentum SDK to access the Momentum CLMM",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"author": "Momentum Finance",
|
|
@@ -26,13 +26,16 @@
|
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@anatine/esbuild-decorators": "^0.2.19",
|
|
29
|
+
"@babel/core": "^7.29.0",
|
|
30
|
+
"@babel/preset-env": "^7.29.2",
|
|
29
31
|
"@commitlint/config-conventional": "^19.7.1",
|
|
30
|
-
"@mysten/sui": "
|
|
32
|
+
"@mysten/sui": "2.4.0",
|
|
31
33
|
"@types/bn.js": "^5.1.5",
|
|
32
34
|
"@types/jest": "^29.5.14",
|
|
33
35
|
"@types/node": "^20.14.11",
|
|
34
36
|
"@typescript-eslint/eslint-plugin": "^6.19.1",
|
|
35
37
|
"@typescript-eslint/parser": "^6.19.1",
|
|
38
|
+
"babel-jest": "^30.3.0",
|
|
36
39
|
"bn.js": "^5.2.1",
|
|
37
40
|
"branch-name-lint": "^2.1.1",
|
|
38
41
|
"commitlint": "^19.7.1",
|
package/src/config.ts
CHANGED
|
@@ -16,13 +16,13 @@ export const MainnetConfig = {
|
|
|
16
16
|
|
|
17
17
|
export const TestnetConfig = {
|
|
18
18
|
clmm: {
|
|
19
|
-
packageId: '
|
|
20
|
-
publishedAt: '
|
|
21
|
-
aclId: '
|
|
22
|
-
adminCapId: '
|
|
19
|
+
packageId: '0xcf548a43151dafca6ed4b7bcbb17698eac0bf5c761d9458c53719a8a004dda02',
|
|
20
|
+
publishedAt: '0xcf548a43151dafca6ed4b7bcbb17698eac0bf5c761d9458c53719a8a004dda02',
|
|
21
|
+
aclId: '0x14be48fa41942aa3b40fb23af60a3941ac18ee69ad7ef6816b20d8f44187484c',
|
|
22
|
+
adminCapId: '0xcd25c030e26ec8dc47e47c1b785572fe33e702f0c029b9bb464081ead5d027fe',
|
|
23
23
|
slippageCheckPackageId: '0xfd6a45c396a90811fd93efaf585cc95c29aecd079c87822893f1e97e3fee8c50',
|
|
24
|
-
globalConfigId: '
|
|
25
|
-
versionId: '
|
|
24
|
+
globalConfigId: '0x5c7929a413933b3bcec3cb6352274d358d2eeb7973233fa1e2b60ccf3a33691a',
|
|
25
|
+
versionId: '0xda7375acbf29ebdf0e8a219db2baf363748882d186927c6f4001681d6251d522',
|
|
26
26
|
mvrName: '',
|
|
27
27
|
},
|
|
28
28
|
mmtApiUrl: 'https://api-dev.mmt.finance',
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
-
import { SuiObjectResponse } from '@mysten/sui/
|
|
2
|
+
import { SuiObjectResponse } from '@mysten/sui/jsonRpc';
|
|
3
3
|
import { TransactionArgument, Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
4
4
|
import { isValidSuiAddress, normalizeSuiAddress, normalizeSuiObjectId, parseStructTag } from '@mysten/sui/utils';
|
|
5
5
|
import BN from 'bn.js';
|
|
@@ -277,7 +277,7 @@ export class PoolModule {
|
|
|
277
277
|
});
|
|
278
278
|
|
|
279
279
|
if (transferToAddress && isValidSuiAddress(transferToAddress)) {
|
|
280
|
-
txb.transferObjects([inputCoin], txb.pure.address(transferToAddress));
|
|
280
|
+
txb.transferObjects([txnArgument(inputCoin, txb)], txb.pure.address(transferToAddress));
|
|
281
281
|
txb.transferObjects([outputCoin], txb.pure.address(transferToAddress));
|
|
282
282
|
} else {
|
|
283
283
|
return {
|
|
@@ -835,7 +835,7 @@ export class PoolModule {
|
|
|
835
835
|
}) || { outputCoin: undefined, leftoverCoin: undefined };
|
|
836
836
|
|
|
837
837
|
if (leftoverCoin) {
|
|
838
|
-
txb.transferObjects([leftoverCoin], txb.pure.address(toAddress));
|
|
838
|
+
txb.transferObjects([txnArgument(leftoverCoin, txb)], txb.pure.address(toAddress));
|
|
839
839
|
}
|
|
840
840
|
|
|
841
841
|
currentCoin = outputCoin ?? currentCoin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { bcs } from '@mysten/sui/bcs';
|
|
2
|
-
import {
|
|
2
|
+
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
3
3
|
import { Transaction, TransactionArgument } from '@mysten/sui/transactions';
|
|
4
4
|
import BN from 'bn.js';
|
|
5
5
|
|
|
@@ -289,7 +289,7 @@ export class PositionModule implements BaseModule {
|
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
|
|
292
|
-
public async fetchRewards(positions: any, pools: ExtendedPool[], address: string, client:
|
|
292
|
+
public async fetchRewards(positions: any, pools: ExtendedPool[], address: string, client: SuiJsonRpcClient) {
|
|
293
293
|
const { contractConst } = this.sdk.sdkConfig;
|
|
294
294
|
const allRewards: Record<string, RewardsData> = {};
|
|
295
295
|
const batchSize = 100;
|
package/src/sdk.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
2
2
|
import { BuildTransactionOptions, TransactionDataBuilder } from '@mysten/sui/transactions';
|
|
3
3
|
|
|
4
4
|
import { Config } from './config';
|
|
@@ -16,11 +16,12 @@ export interface SdkOptions {
|
|
|
16
16
|
suiClientUrl?: string;
|
|
17
17
|
customHeaders?: HeadersInit;
|
|
18
18
|
mvrEndpoint?: string;
|
|
19
|
-
client?:
|
|
19
|
+
client?: SuiJsonRpcClient;
|
|
20
|
+
customRpcNetwork?: 'mainnet' | 'testnet';
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
export class MmtSDK {
|
|
23
|
-
protected readonly rpcModule:
|
|
24
|
+
protected readonly rpcModule: SuiJsonRpcClient;
|
|
24
25
|
|
|
25
26
|
protected readonly poolModule: PoolModule;
|
|
26
27
|
|
|
@@ -39,10 +40,11 @@ export class MmtSDK {
|
|
|
39
40
|
) => Promise<void>;
|
|
40
41
|
|
|
41
42
|
constructor(options?: SdkOptions) {
|
|
42
|
-
if (options?.network === 'custom' && !options?.contractConst) {
|
|
43
|
-
throw new Error('missing contractConst for custom network');
|
|
43
|
+
if (options?.network === 'custom' && (!options?.contractConst || !options?.customRpcNetwork)) {
|
|
44
|
+
throw new Error('missing contractConst or customRpcNetwork for custom network');
|
|
44
45
|
}
|
|
45
46
|
const network = options?.network || 'mainnet';
|
|
47
|
+
const rpcNetwork = options?.customRpcNetwork || network;
|
|
46
48
|
const defaultConfig = Config.getDefaultConfig(network);
|
|
47
49
|
const suiClientUrl = options?.suiClientUrl || defaultConfig.suiClientUrl;
|
|
48
50
|
const mvrEndpoint = options?.mvrEndpoint || defaultConfig.mvrEndpoint;
|
|
@@ -57,7 +59,9 @@ export class MmtSDK {
|
|
|
57
59
|
mvrEndpoint,
|
|
58
60
|
customHeaders: options?.customHeaders,
|
|
59
61
|
};
|
|
60
|
-
this.rpcModule = options?.client
|
|
62
|
+
this.rpcModule = options?.client
|
|
63
|
+
? options?.client
|
|
64
|
+
: new SuiJsonRpcClient({ url: suiClientUrl, network: rpcNetwork });
|
|
61
65
|
this.poolModule = new PoolModule(this);
|
|
62
66
|
this.positionModule = new PositionModule(this);
|
|
63
67
|
this.routeModule = new RouteModule(this);
|
|
@@ -67,7 +71,7 @@ export class MmtSDK {
|
|
|
67
71
|
});
|
|
68
72
|
}
|
|
69
73
|
|
|
70
|
-
get rpcClient():
|
|
74
|
+
get rpcClient(): SuiJsonRpcClient {
|
|
71
75
|
return this.rpcModule;
|
|
72
76
|
}
|
|
73
77
|
|
package/src/utils/coin-utils.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { CoinStruct,
|
|
1
|
+
import { CoinStruct, SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
2
2
|
import { TransactionArgument, Transaction } from '@mysten/sui/transactions';
|
|
3
3
|
import { normalizeStructTag } from '@mysten/sui/utils';
|
|
4
4
|
|
|
5
5
|
import { SUI_COIN_TYPE, SUI_COIN_TYPE_FORMATTED } from '@/constants';
|
|
6
6
|
import { ClmmPoolsError, UtilsErrorCode } from '@/errors/errors';
|
|
7
7
|
|
|
8
|
+
import { txnArgument } from './common';
|
|
9
|
+
|
|
8
10
|
export function isSUICoin(coinType: string) {
|
|
9
11
|
return normalizeStructTag(coinType) === normalizeStructTag(SUI_COIN_TYPE);
|
|
10
12
|
}
|
|
@@ -31,8 +33,8 @@ export function mergeCoins(
|
|
|
31
33
|
throw new ClmmPoolsError('First coin is not found', UtilsErrorCode.FirstCoinNotFound);
|
|
32
34
|
}
|
|
33
35
|
txb.mergeCoins(
|
|
34
|
-
firstCoin,
|
|
35
|
-
coinObjects.slice(1).map((coin) => (
|
|
36
|
+
txnArgument(firstCoin, txb),
|
|
37
|
+
coinObjects.slice(1).map((coin) => txnArgument(coin, txb)),
|
|
36
38
|
);
|
|
37
39
|
return firstCoin;
|
|
38
40
|
}
|
|
@@ -90,7 +92,7 @@ export async function getAllUserCoins({
|
|
|
90
92
|
}: {
|
|
91
93
|
address: string;
|
|
92
94
|
type: string;
|
|
93
|
-
suiClient:
|
|
95
|
+
suiClient: SuiJsonRpcClient;
|
|
94
96
|
}) {
|
|
95
97
|
let cursor: string | null = null;
|
|
96
98
|
|
|
@@ -123,7 +125,7 @@ export async function getAllUserCoins({
|
|
|
123
125
|
export async function mergeAllUserCoins(
|
|
124
126
|
coinType: string,
|
|
125
127
|
signerAddress: string,
|
|
126
|
-
suiClient:
|
|
128
|
+
suiClient: SuiJsonRpcClient,
|
|
127
129
|
): Promise<Transaction | undefined> {
|
|
128
130
|
try {
|
|
129
131
|
const coins = await getAllUserCoins({
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import type { NamedPackagesOverrides } from '@mysten/sui/client';
|
|
5
|
+
import { BuildTransactionOptions, TransactionDataBuilder } from '@mysten/sui/transactions';
|
|
5
6
|
import { parseStructTag } from '@mysten/sui/utils';
|
|
6
7
|
|
|
7
8
|
import { mvrCacheLocal } from './mvr-cache-local';
|
|
@@ -40,7 +41,7 @@ export type NamedPackagesPluginOptions = {
|
|
|
40
41
|
* }
|
|
41
42
|
*
|
|
42
43
|
*/
|
|
43
|
-
overrides?:
|
|
44
|
+
overrides?: NamedPackagesOverrides;
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
/**
|
package/src/utils/pool-utils.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SuiJsonRpcClient, SuiParsedData } from '@mysten/sui/jsonRpc';
|
|
2
2
|
import BN from 'bn.js';
|
|
3
3
|
import Decimal from 'decimal.js';
|
|
4
4
|
|
|
@@ -290,7 +290,7 @@ export function estLiquidityAndcoinAmountFromOneAmounts(
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
export const fetchUserObjectsByPkg = async (
|
|
293
|
-
client:
|
|
293
|
+
client: SuiJsonRpcClient,
|
|
294
294
|
packageId: string,
|
|
295
295
|
address: string,
|
|
296
296
|
): Promise<SuiParsedData[]> => {
|
|
@@ -334,7 +334,7 @@ export async function getLimitSqrtPriceUsingSlippage({
|
|
|
334
334
|
slippagePercentage,
|
|
335
335
|
isTokenX,
|
|
336
336
|
}: Pick<ExtendedPool, 'poolId' | 'tokenX' | 'tokenY'> & {
|
|
337
|
-
client:
|
|
337
|
+
client: SuiJsonRpcClient;
|
|
338
338
|
currentSqrtPrice?: string;
|
|
339
339
|
slippagePercentage: number; // 1 = 1% slippage
|
|
340
340
|
isTokenX: boolean;
|
package/tsconfig.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"lib": ["es2022", "esnext", "dom"],
|
|
5
5
|
"experimentalDecorators": true,
|
|
6
6
|
"emitDecoratorMetadata": true,
|
|
7
|
-
"module": "
|
|
8
|
-
"moduleResolution": "
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
9
|
"baseUrl": "./",
|
|
10
10
|
"paths": { "@/*": ["./src/*"] },
|
|
11
11
|
"resolveJsonModule": true,
|
|
@@ -29,6 +29,12 @@
|
|
|
29
29
|
"noFallthroughCasesInSwitch": true,
|
|
30
30
|
"noUncheckedIndexedAccess": true
|
|
31
31
|
},
|
|
32
|
+
"ts-node": {
|
|
33
|
+
"compilerOptions": {
|
|
34
|
+
"module": "CommonJS",
|
|
35
|
+
"moduleResolution": "node"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
32
38
|
"exclude": ["node_modules", "dist"],
|
|
33
39
|
"include": ["./src/**/*", "./test/**/*", "./scripts/**/*", "./examples/**/*", "./*.json", "./*.ts", "./*.js"]
|
|
34
40
|
}
|