@7kprotocol/sdk-ts 3.4.0 → 3.4.2-beta.0
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/lib/cjs/features/limitDca/placeLimitOrder.js +8 -3
- package/lib/cjs/features/swap/buildTx.js +111 -65
- package/lib/cjs/features/swap/buildTxV2.js +227 -0
- package/lib/cjs/features/swap/getQuote.js +13 -2
- package/lib/cjs/features/swap/index.js +1 -0
- package/lib/cjs/index.js +6 -2
- package/lib/cjs/types/features/limitDca/placeLimitOrder.d.ts +2 -1
- package/lib/cjs/types/features/limitDca/placeLimitOrder.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/buildTx.d.ts +14 -1
- package/lib/cjs/types/features/swap/buildTx.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/buildTxV2.d.ts +20 -0
- package/lib/cjs/types/features/swap/buildTxV2.d.ts.map +1 -0
- package/lib/cjs/types/features/swap/getQuote.d.ts +4 -1
- package/lib/cjs/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/index.d.ts +1 -0
- package/lib/cjs/types/features/swap/index.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +4 -2
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/base.d.ts +4 -5
- package/lib/cjs/types/libs/protocols/base.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/steamm/index.d.ts +3 -12
- package/lib/cjs/types/libs/protocols/steamm/index.d.ts.map +1 -1
- package/lib/cjs/types/libs/swapWithRoute.d.ts +3 -4
- package/lib/cjs/types/libs/swapWithRoute.d.ts.map +1 -1
- package/lib/cjs/types/types/tx.d.ts +13 -0
- package/lib/cjs/types/types/tx.d.ts.map +1 -1
- package/lib/esm/features/limitDca/placeLimitOrder.js +8 -3
- package/lib/esm/features/swap/buildTx.js +105 -65
- package/lib/esm/features/swap/buildTxV2.js +221 -0
- package/lib/esm/features/swap/getQuote.js +12 -1
- package/lib/esm/features/swap/index.js +1 -0
- package/lib/esm/index.mjs +12 -10
- package/lib/esm/types/features/limitDca/placeLimitOrder.d.ts +2 -1
- package/lib/esm/types/features/limitDca/placeLimitOrder.d.ts.map +1 -1
- package/lib/esm/types/features/swap/buildTx.d.ts +14 -1
- package/lib/esm/types/features/swap/buildTx.d.ts.map +1 -1
- package/lib/esm/types/features/swap/buildTxV2.d.ts +20 -0
- package/lib/esm/types/features/swap/buildTxV2.d.ts.map +1 -0
- package/lib/esm/types/features/swap/getQuote.d.ts +4 -1
- package/lib/esm/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/esm/types/features/swap/index.d.ts +1 -0
- package/lib/esm/types/features/swap/index.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +4 -2
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/base.d.ts +4 -5
- package/lib/esm/types/libs/protocols/base.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/steamm/index.d.ts +3 -12
- package/lib/esm/types/libs/protocols/steamm/index.d.ts.map +1 -1
- package/lib/esm/types/libs/swapWithRoute.d.ts +3 -4
- package/lib/esm/types/libs/swapWithRoute.d.ts.map +1 -1
- package/lib/esm/types/types/tx.d.ts +13 -0
- package/lib/esm/types/types/tx.d.ts.map +1 -1
- package/package.json +3 -3
- package/lib/cjs/libs/getCoinOjectIdsByAmount.js +0 -65
- package/lib/cjs/libs/getSplitCoinForTx.js +0 -33
- package/lib/cjs/types/libs/getCoinOjectIdsByAmount.d.ts +0 -7
- package/lib/cjs/types/libs/getCoinOjectIdsByAmount.d.ts.map +0 -1
- package/lib/cjs/types/libs/getSplitCoinForTx.d.ts +0 -6
- package/lib/cjs/types/libs/getSplitCoinForTx.d.ts.map +0 -1
- package/lib/esm/libs/getCoinOjectIdsByAmount.js +0 -61
- package/lib/esm/libs/getSplitCoinForTx.js +0 -29
- package/lib/esm/types/libs/getCoinOjectIdsByAmount.d.ts +0 -7
- package/lib/esm/types/libs/getCoinOjectIdsByAmount.d.ts.map +0 -1
- package/lib/esm/types/libs/getSplitCoinForTx.d.ts +0 -6
- package/lib/esm/types/libs/getSplitCoinForTx.d.ts.map +0 -1
|
@@ -26,7 +26,18 @@ export const DEFAULT_SOURCES = [
|
|
|
26
26
|
"sevenk_v1",
|
|
27
27
|
"fullsail",
|
|
28
28
|
];
|
|
29
|
-
export
|
|
29
|
+
export const ORACLE_BASED_SOURCES = new Set([
|
|
30
|
+
"obric",
|
|
31
|
+
"haedal_pmm",
|
|
32
|
+
"sevenk_v1",
|
|
33
|
+
"steamm_oracle_quoter",
|
|
34
|
+
"steamm_oracle_quoter_v2",
|
|
35
|
+
]);
|
|
36
|
+
export async function getQuote({ tokenIn, tokenOut, amountIn, sources: _sources = DEFAULT_SOURCES, commissionBps, targetPools, excludedPools, taker, isSponsored, }) {
|
|
37
|
+
let sources = _sources;
|
|
38
|
+
if (isSponsored) {
|
|
39
|
+
sources = _sources.filter((s) => !ORACLE_BASED_SOURCES.has(s));
|
|
40
|
+
}
|
|
30
41
|
const params = new URLSearchParams({
|
|
31
42
|
amount: amountIn,
|
|
32
43
|
from: normalizeStructTag(tokenIn),
|
package/lib/esm/index.mjs
CHANGED
|
@@ -2,24 +2,24 @@ export * from "./types/aggregator";
|
|
|
2
2
|
import { Config } from "./config";
|
|
3
3
|
import { getSuiPrice, getTokenPrice, getTokenPrices } from "./features/prices";
|
|
4
4
|
import { executeBluefinTx } from "./libs/protocols/bluefinx/client";
|
|
5
|
-
import { buildTx, estimateGasFee, executeTx, getQuote, getSwapHistory,
|
|
5
|
+
import { buildTx, buildTxV2, DEFAULT_SOURCES, estimateGasFee, executeTx, getQuote, getSwapHistory, multiSwap, } from "./features/swap";
|
|
6
6
|
import { cancelDcaOrder, cancelLimitOrder, claimExpiredLimitOrder, getClosedDcaOrders, getClosedLimitOrders, getDcaOrderExecutions, getOpenDcaOrders, getOpenLimitOrders, placeDcaOrder, placeLimitOrder, } from "./features/limitDca";
|
|
7
7
|
// avoid breaking changes
|
|
8
8
|
const getSuiClient = Config.getSuiClient;
|
|
9
9
|
const setSuiClient = Config.setSuiClient;
|
|
10
|
-
export {
|
|
10
|
+
export { buildTx, buildTxV2, cancelDcaOrder, cancelLimitOrder, claimExpiredLimitOrder,
|
|
11
11
|
// config
|
|
12
|
-
Config,
|
|
12
|
+
Config, DEFAULT_SOURCES, estimateGasFee, executeBluefinTx, executeTx, getClosedDcaOrders, getClosedLimitOrders, getDcaOrderExecutions, getOpenDcaOrders, getOpenLimitOrders,
|
|
13
|
+
// swap
|
|
14
|
+
getQuote,
|
|
13
15
|
// sui client
|
|
14
|
-
getSuiClient,
|
|
16
|
+
getSuiClient, getSuiPrice, getSwapHistory,
|
|
15
17
|
// prices
|
|
16
|
-
getTokenPrice, getTokenPrices,
|
|
17
|
-
// swap
|
|
18
|
-
getQuote, estimateGasFee, buildTx, getSwapHistory, executeTx, executeBluefinTx, DEFAULT_SOURCES,
|
|
19
|
-
// limit order
|
|
20
|
-
placeLimitOrder, getOpenLimitOrders, cancelLimitOrder, claimExpiredLimitOrder, getClosedLimitOrders,
|
|
18
|
+
getTokenPrice, getTokenPrices, multiSwap,
|
|
21
19
|
// dca
|
|
22
|
-
placeDcaOrder,
|
|
20
|
+
placeDcaOrder,
|
|
21
|
+
// limit order
|
|
22
|
+
placeLimitOrder, setSuiClient, };
|
|
23
23
|
export default {
|
|
24
24
|
// config
|
|
25
25
|
Config,
|
|
@@ -34,6 +34,8 @@ export default {
|
|
|
34
34
|
getQuote,
|
|
35
35
|
estimateGasFee,
|
|
36
36
|
buildTx,
|
|
37
|
+
buildTxV2,
|
|
38
|
+
multiSwap,
|
|
37
39
|
getSwapHistory,
|
|
38
40
|
executeTx,
|
|
39
41
|
executeBluefinTx,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
1
2
|
export interface PlaceLimitOrderParams {
|
|
2
3
|
accountAddress: string;
|
|
3
4
|
payCoinType: string;
|
|
@@ -8,5 +9,5 @@ export interface PlaceLimitOrderParams {
|
|
|
8
9
|
expireTs: bigint;
|
|
9
10
|
devInspect?: boolean;
|
|
10
11
|
}
|
|
11
|
-
export declare function placeLimitOrder({ accountAddress, payCoinType, targetCoinType, payCoinAmount, rate, slippage, expireTs, devInspect, }: PlaceLimitOrderParams): Promise<
|
|
12
|
+
export declare function placeLimitOrder({ accountAddress, payCoinType, targetCoinType, payCoinAmount, rate, slippage, expireTs, devInspect, }: PlaceLimitOrderParams): Promise<Transaction>;
|
|
12
13
|
//# sourceMappingURL=placeLimitOrder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placeLimitOrder.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/placeLimitOrder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"placeLimitOrder.d.ts","sourceRoot":"","sources":["../../../../../src/features/limitDca/placeLimitOrder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGxE,MAAM,WAAW,qBAAqB;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAsB,eAAe,CAAC,EACpC,cAAc,EACd,WAAW,EACX,cAAc,EACd,aAAa,EACb,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,UAAU,GACX,EAAE,qBAAqB,wBAyBvB"}
|
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { BluefinXTx } from "../../libs/protocols/bluefinx/types";
|
|
3
|
+
import { BuildTxResult, Commission, QuoteResponse, TxSorSwap } from "../../types/aggregator";
|
|
2
4
|
import { BuildTxParams } from "../../types/tx";
|
|
3
5
|
export declare const buildTx: ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }: BuildTxParams) => Promise<BuildTxResult>;
|
|
6
|
+
export declare const getPythPriceFeeds: (responses: QuoteResponse[]) => string[];
|
|
7
|
+
export declare const updatePythPriceFeedsIfAny: (tx: Transaction, quoteResponse: QuoteResponse[]) => Promise<Record<string, string>>;
|
|
8
|
+
export declare const validateRoutes: (routes: TxSorSwap[][], isSponsored?: boolean) => void;
|
|
9
|
+
export declare const getExpectedReturn: (returnAmount: string, slippageBps: number, commissionBps: number, tipBps?: number) => {
|
|
10
|
+
tipAmount: bigint;
|
|
11
|
+
minAmount: bigint;
|
|
12
|
+
commissionAmount: bigint;
|
|
13
|
+
expectedAmount: string;
|
|
14
|
+
};
|
|
15
|
+
export declare const settle: (coinObjects: TransactionObjectArgument[], quoteResponse: QuoteResponse, slippageBps: number, _commission: Commission) => (tx: Transaction) => TransactionObjectArgument;
|
|
16
|
+
export declare const buildBluefinXTx: (tx: Transaction, accountAddress: string, quoteResponse: QuoteResponse) => Promise<BluefinXTx>;
|
|
4
17
|
//# sourceMappingURL=buildTx.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildTx.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/buildTx.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"buildTx.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/buildTx.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EAAE,UAAU,EAAE,MAAM,qCAAqC,CAAC;AAEjE,OAAO,EACL,aAAa,EACb,UAAU,EAEV,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAK/C,eAAO,MAAM,OAAO,GAAU,2GAQ3B,aAAa,KAAG,OAAO,CAAC,aAAa,CA0FvC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,WAAW,aAAa,EAAE,aAa3D,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,IAAI,WAAW,EACf,eAAe,aAAa,EAAE,oCAmB/B,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,QAAQ,SAAS,EAAE,EAAE,EACrB,cAAc,OAAO,SAWtB,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAC5B,cAAc,MAAM,EACpB,aAAa,MAAM,EACnB,eAAe,MAAM,EACrB,SAAQ,MAAU;;;;;CA8BnB,CAAC;AAEF,eAAO,MAAM,MAAM,GACjB,aAAa,yBAAyB,EAAE,EACxC,eAAe,aAAa,EAC5B,aAAa,MAAM,EACnB,aAAa,UAAU,MAEf,IAAI,WAAW,8BAiCxB,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,IAAI,WAAW,EACf,gBAAgB,MAAM,EACtB,eAAe,aAAa,wBAsB7B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { BuildTxResult, Config, TxSorSwap } from "../../types/aggregator";
|
|
3
|
+
import { BuildTxParams, MultiSwapParams } from "../../types/tx";
|
|
4
|
+
/**
|
|
5
|
+
* Wave-based transaction builder that optimizes swap execution by:
|
|
6
|
+
* 1. Grouping swaps into execution waves based on readiness
|
|
7
|
+
* 2. Merging redundant swaps to the same pool within each wave
|
|
8
|
+
* 3. Processing waves sequentially, passing intermediate tokens between waves
|
|
9
|
+
*/
|
|
10
|
+
export declare const buildTxV2: ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }: BuildTxParams) => Promise<BuildTxResult>;
|
|
11
|
+
export declare const optimize: (pythMap: Record<string, string>, config: Config, routes: TxSorSwap[][], coinData: TransactionObjectArgument[], tx: Transaction, accountAddress: string) => Promise<TransactionObjectArgument[]>;
|
|
12
|
+
/**
|
|
13
|
+
* execute multiple swap in single transaction
|
|
14
|
+
*
|
|
15
|
+
* User must handle the coins from return
|
|
16
|
+
* @param param - MultiSwapParams
|
|
17
|
+
* @returns a map of coinType to coinObject
|
|
18
|
+
*/
|
|
19
|
+
export declare const multiSwap: ({ sender, slippageBps, swaps, tx, commission, }: MultiSwapParams) => Promise<Record<string, TransactionObjectArgument>>;
|
|
20
|
+
//# sourceMappingURL=buildTxV2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildTxV2.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/buildTxV2.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAIlC,OAAO,EACL,aAAa,EACb,MAAM,EAEN,SAAS,EACV,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAUhE;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAU,2GAQ7B,aAAa,KAAG,OAAO,CAAC,aAAa,CAuFvC,CAAC;AAEF,eAAO,MAAM,QAAQ,GACnB,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC/B,QAAQ,MAAM,EACd,QAAQ,SAAS,EAAE,EAAE,EACrB,UAAU,yBAAyB,EAAE,EACrC,IAAI,WAAW,EACf,gBAAgB,MAAM,yCA0JvB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAU,iDAM7B,eAAe,uDAiDjB,CAAC"}
|
|
@@ -15,8 +15,11 @@ interface Params {
|
|
|
15
15
|
excludedPools?: string[];
|
|
16
16
|
/** The taker address, required for bluefinx */
|
|
17
17
|
taker?: string;
|
|
18
|
+
/** If true, excludes all liquidity sources that depend on pyth price feeds - pyth client use tx.gas to pay the fee*/
|
|
19
|
+
isSponsored?: boolean;
|
|
18
20
|
}
|
|
19
21
|
export declare const DEFAULT_SOURCES: SourceDex[];
|
|
20
|
-
export declare
|
|
22
|
+
export declare const ORACLE_BASED_SOURCES: Set<SourceDex>;
|
|
23
|
+
export declare function getQuote({ tokenIn, tokenOut, amountIn, sources: _sources, commissionBps, targetPools, excludedPools, taker, isSponsored, }: Params): Promise<QuoteResponse>;
|
|
21
24
|
export {};
|
|
22
25
|
//# sourceMappingURL=getQuote.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getQuote.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/getQuote.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,UAAU,MAAM;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB;;;kEAG8D;IAC9D,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"getQuote.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/getQuote.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAEhC,UAAU,MAAM;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB;;;kEAG8D;IAC9D,OAAO,CAAC,EAAE,SAAS,EAAE,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,qDAAqD;IACrD,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qHAAqH;IACrH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,eAAO,MAAM,eAAe,EAAE,SAAS,EAuBtC,CAAC;AAEF,eAAO,MAAM,oBAAoB,gBAM/B,CAAC;AAEH,wBAAsB,QAAQ,CAAC,EAC7B,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,EAAE,QAA0B,EACnC,aAAa,EACb,WAAW,EACX,aAAa,EACb,KAAK,EACL,WAAW,GACZ,EAAE,MAAM,0BAyCR"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
package/lib/esm/types/index.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ export * from "./types/aggregator";
|
|
|
2
2
|
import { Config } from "./config";
|
|
3
3
|
import { getSuiPrice, getTokenPrice, getTokenPrices } from "./features/prices";
|
|
4
4
|
import { executeBluefinTx } from "./libs/protocols/bluefinx/client";
|
|
5
|
-
import { buildTx, estimateGasFee, executeTx, getQuote, getSwapHistory,
|
|
5
|
+
import { buildTx, buildTxV2, DEFAULT_SOURCES, estimateGasFee, executeTx, getQuote, getSwapHistory, multiSwap } from "./features/swap";
|
|
6
6
|
import { cancelDcaOrder, cancelLimitOrder, claimExpiredLimitOrder, getClosedDcaOrders, getClosedLimitOrders, getDcaOrderExecutions, getOpenDcaOrders, getOpenLimitOrders, placeDcaOrder, placeLimitOrder } from "./features/limitDca";
|
|
7
7
|
declare const getSuiClient: () => import("@mysten/sui/dist/cjs/client").SuiClient;
|
|
8
8
|
declare const setSuiClient: (client: import("@mysten/sui/dist/cjs/client").SuiClient) => void;
|
|
9
|
-
export {
|
|
9
|
+
export { buildTx, buildTxV2, cancelDcaOrder, cancelLimitOrder, claimExpiredLimitOrder, Config, DEFAULT_SOURCES, estimateGasFee, executeBluefinTx, executeTx, getClosedDcaOrders, getClosedLimitOrders, getDcaOrderExecutions, getOpenDcaOrders, getOpenLimitOrders, getQuote, getSuiClient, getSuiPrice, getSwapHistory, getTokenPrice, getTokenPrices, multiSwap, placeDcaOrder, placeLimitOrder, setSuiClient, };
|
|
10
10
|
declare const _default: {
|
|
11
11
|
Config: {
|
|
12
12
|
setApiKey: (key: string) => void;
|
|
@@ -28,6 +28,8 @@ declare const _default: {
|
|
|
28
28
|
getQuote: typeof getQuote;
|
|
29
29
|
estimateGasFee: typeof estimateGasFee;
|
|
30
30
|
buildTx: ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }: import("./types/tx").BuildTxParams) => Promise<import("./types/aggregator").BuildTxResult>;
|
|
31
|
+
buildTxV2: ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }: import("./types/tx").BuildTxParams) => Promise<import("./types/aggregator").BuildTxResult>;
|
|
32
|
+
multiSwap: ({ sender, slippageBps, swaps, tx, commission, }: import("./types/tx").MultiSwapParams) => Promise<Record<string, import("@mysten/sui/dist/cjs/transactions").TransactionObjectArgument>>;
|
|
31
33
|
getSwapHistory: typeof getSwapHistory;
|
|
32
34
|
executeTx: (tx: import("./types/aggregator").AggregatorTx, signature: string, signedTxBytes: string, options?: import("@mysten/sui/dist/cjs/client").SuiTransactionBlockResponseOptions) => Promise<import("@mysten/sui/dist/cjs/client").SuiTransactionBlockResponse>;
|
|
33
35
|
executeBluefinTx: (tx: import("./types/aggregator").BluefinXTx, signature: string) => Promise<import("./libs/protocols/bluefinx/types").SwapResponse>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEpE,OAAO,EACL,OAAO,EACP,cAAc,EACd,SAAS,EACT,QAAQ,EACR,cAAc,EACd,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEpE,OAAO,EACL,OAAO,EACP,SAAS,EACT,eAAe,EACf,cAAc,EACd,SAAS,EACT,QAAQ,EACR,cAAc,EACd,SAAS,EACV,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAG7B,QAAA,MAAM,YAAY,uDAAsB,CAAC;AACzC,QAAA,MAAM,YAAY,mEAAsB,CAAC;AAEzC,OAAO,EACL,OAAO,EACP,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EAEtB,MAAM,EACN,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAElB,QAAQ,EAER,YAAY,EACZ,WAAW,EACX,cAAc,EAEd,aAAa,EACb,cAAc,EACd,SAAS,EAET,aAAa,EAEb,eAAe,EACf,YAAY,GACb,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,wBAqCE"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
2
|
import { Config, ExtraOracle, TxSorSwap } from "../../types/aggregator";
|
|
3
|
-
import { TransactionResultItem } from "../../types/sui";
|
|
4
3
|
export interface BaseContractParams {
|
|
5
4
|
swapInfo: TxSorSwap;
|
|
6
|
-
inputCoinObject:
|
|
5
|
+
inputCoinObject: TransactionObjectArgument;
|
|
7
6
|
currentAccount: string;
|
|
8
7
|
config: Config;
|
|
9
8
|
/** map price feed id to onchain priceInfoObject id */
|
|
@@ -11,12 +10,12 @@ export interface BaseContractParams {
|
|
|
11
10
|
}
|
|
12
11
|
export declare abstract class BaseContract<T = any> {
|
|
13
12
|
protected swapInfo: TxSorSwap;
|
|
14
|
-
protected inputCoinObject:
|
|
13
|
+
protected inputCoinObject: TransactionObjectArgument;
|
|
15
14
|
protected currentAccount: string;
|
|
16
15
|
protected config: Config;
|
|
17
16
|
protected pythMap: Record<string, string>;
|
|
18
17
|
constructor({ swapInfo, inputCoinObject, currentAccount, config, pythMap, }: BaseContractParams);
|
|
19
|
-
abstract swap(tx: Transaction): Promise<
|
|
18
|
+
abstract swap(tx: Transaction): Promise<TransactionObjectArgument>;
|
|
20
19
|
protected getInputCoinValue(tx: Transaction): import("@mysten/sui/transactions").TransactionArgument;
|
|
21
20
|
protected getTypeParams(): string[];
|
|
22
21
|
protected get extra(): NonNullable<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../../src/libs/protocols/base.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../../src/libs/protocols/base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAGxE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,SAAS,CAAC;IACpB,eAAe,EAAE,yBAAyB,CAAC;IAC3C,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,8BAAsB,YAAY,CAAC,CAAC,GAAG,GAAG;IACxC,SAAS,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC9B,SAAS,CAAC,eAAe,EAAE,yBAAyB,CAAC;IACrD,SAAS,CAAC,cAAc,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAE9B,EACV,QAAQ,EACR,eAAe,EACf,cAAc,EACd,MAAM,EACN,OAAO,GACR,EAAE,kBAAkB;IAQrB,QAAQ,CAAC,IAAI,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAAC,yBAAyB,CAAC;IAElE,SAAS,CAAC,iBAAiB,CAAC,EAAE,EAAE,WAAW;IAQ3C,SAAS,CAAC,aAAa;IAMvB,SAAS,KAAK,KAAK,mBAMlB;IAED,SAAS,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE,WAAW;CAclD"}
|
|
@@ -14,18 +14,9 @@ export type SteamExtra = {
|
|
|
14
14
|
oracleIndexes?: number[];
|
|
15
15
|
};
|
|
16
16
|
export declare class SteammContract extends BaseContract<SteamExtra> {
|
|
17
|
-
swap(tx: Transaction): Promise<
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}>;
|
|
21
|
-
cpmmSwap(tx: Transaction): {
|
|
22
|
-
$kind: "NestedResult";
|
|
23
|
-
NestedResult: [number, number];
|
|
24
|
-
};
|
|
25
|
-
ommSwap(tx: Transaction, version: "v1" | "v2"): {
|
|
26
|
-
$kind: "NestedResult";
|
|
27
|
-
NestedResult: [number, number];
|
|
28
|
-
};
|
|
17
|
+
swap(tx: Transaction): Promise<import("@mysten/sui/transactions").TransactionObjectArgument>;
|
|
18
|
+
cpmmSwap(tx: Transaction): import("@mysten/sui/transactions").TransactionObjectArgument;
|
|
19
|
+
ommSwap(tx: Transaction, version: "v1" | "v2"): import("@mysten/sui/transactions").TransactionObjectArgument;
|
|
29
20
|
getOraclePriceUpdate(tx: Transaction): readonly [{
|
|
30
21
|
$kind: "NestedResult";
|
|
31
22
|
NestedResult: [number, number];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/libs/protocols/steamm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,MAAM,UAAU,GAAG;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AACF,qBAAa,cAAe,SAAQ,YAAY,CAAC,UAAU,CAAC;IACpD,IAAI,CAAC,EAAE,EAAE,WAAW
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/libs/protocols/steamm/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMvD,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,MAAM,UAAU,GAAG;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B,CAAC;AACF,qBAAa,cAAe,SAAQ,YAAY,CAAC,UAAU,CAAC;IACpD,IAAI,CAAC,EAAE,EAAE,WAAW;IAW1B,QAAQ,CAAC,EAAE,EAAE,WAAW;IAmExB,OAAO,CAAC,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,GAAG,IAAI;IAuE7C,oBAAoB,CAAC,EAAE,EAAE,WAAW;;;;;;;CA8BrC"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
2
|
import { Config, TxSorSwap } from "../types/aggregator";
|
|
3
|
-
import { TransactionResultItem } from "../types/sui";
|
|
4
3
|
export declare function swapWithRoute({ route, inputCoinObject, currentAccount, config, pythMap, tx, }: {
|
|
5
4
|
route: TxSorSwap[];
|
|
6
|
-
inputCoinObject:
|
|
5
|
+
inputCoinObject: TransactionObjectArgument;
|
|
7
6
|
currentAccount: string;
|
|
8
7
|
config: Config;
|
|
9
8
|
/** map price feed id to onchain priceInfoObject id */
|
|
10
9
|
pythMap: Record<string, string>;
|
|
11
10
|
tx: Transaction;
|
|
12
|
-
}): Promise<
|
|
11
|
+
}): Promise<TransactionObjectArgument | undefined>;
|
|
13
12
|
//# sourceMappingURL=swapWithRoute.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swapWithRoute.d.ts","sourceRoot":"","sources":["../../../../src/libs/swapWithRoute.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"swapWithRoute.d.ts","sourceRoot":"","sources":["../../../../src/libs/swapWithRoute.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAGxD,wBAAsB,aAAa,CAAC,EAClC,KAAK,EACL,eAAe,EACf,cAAc,EACd,MAAM,EACN,OAAO,EACP,EAAE,GACH,EAAE;IACD,KAAK,EAAE,SAAS,EAAE,CAAC;IACnB,eAAe,EAAE,yBAAyB,CAAC;IAC3C,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,EAAE,EAAE,WAAW,CAAC;CACjB,GAAG,OAAO,CAAC,yBAAyB,GAAG,SAAS,CAAC,CAmBjD"}
|
|
@@ -51,4 +51,17 @@ export interface EstimateGasFeeParams extends CommonParams {
|
|
|
51
51
|
/** Sui price in usd for gas estimation */
|
|
52
52
|
suiPrice?: number;
|
|
53
53
|
}
|
|
54
|
+
export interface SwapInfo {
|
|
55
|
+
quote: QuoteResponse;
|
|
56
|
+
/** @warning this `coinIn` will be consumed completely, no `coinIn` left, user must pass the coinIn object with the balance required for the swap - ie in quote */
|
|
57
|
+
coinIn: TransactionObjectArgument;
|
|
58
|
+
}
|
|
59
|
+
export interface MultiSwapParams {
|
|
60
|
+
swaps: SwapInfo[];
|
|
61
|
+
sender: string;
|
|
62
|
+
slippageBps: number;
|
|
63
|
+
tx: Transaction;
|
|
64
|
+
/** Commission for partner */
|
|
65
|
+
commission: Commission;
|
|
66
|
+
}
|
|
54
67
|
//# sourceMappingURL=tx.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../../../src/types/tx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,WAAW,YAAY;IAC3B,iCAAiC;IACjC,aAAa,EAAE,aAAa,CAAC;IAC7B,mBAAmB;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,6BAA6B;IAC7B,UAAU,EAAE,UAAU,CAAC;IACvB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,QAAQ,CAAC,EAAE;QACT,EAAE,EAAE,WAAW,CAAC;QAChB,MAAM,CAAC,EAAE,yBAAyB,CAAC;KACpC,CAAC;IACF;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,gCAAgC;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB"}
|
|
1
|
+
{"version":3,"file":"tx.d.ts","sourceRoot":"","sources":["../../../../src/types/tx.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAEzD,MAAM,WAAW,YAAY;IAC3B,iCAAiC;IACjC,aAAa,EAAE,aAAa,CAAC;IAC7B,mBAAmB;IACnB,cAAc,EAAE,MAAM,CAAC;IACvB,wCAAwC;IACxC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,6BAA6B;IAC7B,UAAU,EAAE,UAAU,CAAC;IACvB;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,QAAQ,CAAC,EAAE;QACT,EAAE,EAAE,WAAW,CAAC;QAChB,MAAM,CAAC,EAAE,yBAAyB,CAAC;KACpC,CAAC;IACF;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY;IACjD,gCAAgC;IAChC,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACxD,0CAA0C;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,aAAa,CAAC;IACrB,kKAAkK;IAClK,MAAM,EAAE,yBAAyB,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,EAAE,EAAE,WAAW,CAAC;IAChB,6BAA6B;IAC7B,UAAU,EAAE,UAAU,CAAC;CACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@7kprotocol/sdk-ts",
|
|
3
|
-
"version": "3.4.0",
|
|
3
|
+
"version": "3.4.2-beta.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"typescript-eslint": "^8.34.1"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
|
-
"@mysten/sui": "^1.
|
|
75
|
-
"@pythnetwork/pyth-sui-js": "^2.
|
|
74
|
+
"@mysten/sui": "^1.39.0",
|
|
75
|
+
"@pythnetwork/pyth-sui-js": "^2.2.0"
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCoinOjectIdsByAmount = void 0;
|
|
4
|
-
const config_1 = require("../config");
|
|
5
|
-
const orderByKey = (array, key, sortBy) => {
|
|
6
|
-
if (!array?.length) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
let swapped;
|
|
10
|
-
do {
|
|
11
|
-
swapped = false;
|
|
12
|
-
for (let i = 0; i < array.length - 1; i++) {
|
|
13
|
-
const a = BigInt(array[i][key]);
|
|
14
|
-
const b = BigInt(array[i + 1][key]);
|
|
15
|
-
if (sortBy === "desc" ? a < b : a > b) {
|
|
16
|
-
const temp = array[i];
|
|
17
|
-
array[i] = array[i + 1];
|
|
18
|
-
array[i + 1] = temp;
|
|
19
|
-
swapped = true;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
} while (swapped);
|
|
23
|
-
return array;
|
|
24
|
-
};
|
|
25
|
-
const getCoinOjectIdsByAmount = async (address, amount, coinType) => {
|
|
26
|
-
let coinBalances = [];
|
|
27
|
-
let hasNextPage = true;
|
|
28
|
-
let nextCursor = undefined;
|
|
29
|
-
while (hasNextPage) {
|
|
30
|
-
try {
|
|
31
|
-
const coins = await config_1.Config.getSuiClient().getCoins({
|
|
32
|
-
owner: address,
|
|
33
|
-
coinType,
|
|
34
|
-
cursor: nextCursor,
|
|
35
|
-
});
|
|
36
|
-
coinBalances = [...coinBalances, ...coins.data];
|
|
37
|
-
hasNextPage = coins.hasNextPage;
|
|
38
|
-
nextCursor = coins.nextCursor;
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
41
|
-
console.error("Error fetching data:", error);
|
|
42
|
-
hasNextPage = false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
// sort coin balance before get object id
|
|
46
|
-
const coinObj = orderByKey(coinBalances.map((item) => {
|
|
47
|
-
return {
|
|
48
|
-
...item,
|
|
49
|
-
balance: item.balance,
|
|
50
|
-
};
|
|
51
|
-
}), "balance", "desc") ?? [];
|
|
52
|
-
let balance = "0";
|
|
53
|
-
const objectIds = [];
|
|
54
|
-
const objectCoins = [];
|
|
55
|
-
for (const coin of coinObj) {
|
|
56
|
-
balance = (BigInt(coin.balance) + BigInt(balance)).toString(10);
|
|
57
|
-
objectIds.push(coin.coinObjectId);
|
|
58
|
-
objectCoins.push(coin);
|
|
59
|
-
if (BigInt(balance) >= BigInt(amount)) {
|
|
60
|
-
break;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return { objectIds, balance, objectCoins };
|
|
64
|
-
};
|
|
65
|
-
exports.getCoinOjectIdsByAmount = getCoinOjectIdsByAmount;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSplitCoinForTx = void 0;
|
|
4
|
-
const transactions_1 = require("@mysten/sui/transactions");
|
|
5
|
-
const utils_1 = require("@mysten/sui/utils");
|
|
6
|
-
const tokens_1 = require("../constants/tokens");
|
|
7
|
-
const getCoinOjectIdsByAmount_1 = require("./getCoinOjectIdsByAmount");
|
|
8
|
-
const getSplitCoinForTx = async (account, amount, splits, coinType, inheritTx, inspecTransaction, isSponsored = false) => {
|
|
9
|
-
const tx = inheritTx ?? new transactions_1.Transaction();
|
|
10
|
-
const { objectIds } = await (0, getCoinOjectIdsByAmount_1.getCoinOjectIdsByAmount)(account, amount, coinType);
|
|
11
|
-
const coinObjectId = objectIds[0];
|
|
12
|
-
if ((0, utils_1.normalizeStructTag)(coinType) === (0, utils_1.normalizeStructTag)(tokens_1.SUI_TYPE) &&
|
|
13
|
-
!isSponsored) {
|
|
14
|
-
let coin;
|
|
15
|
-
if (inspecTransaction) {
|
|
16
|
-
if (objectIds.length > 1) {
|
|
17
|
-
tx.mergeCoins(tx.object(coinObjectId), objectIds.slice(1).map((item) => tx.object(item)));
|
|
18
|
-
}
|
|
19
|
-
coin = tx.splitCoins(tx.object(coinObjectId), splits);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
coin = tx.splitCoins(tx.gas, splits);
|
|
23
|
-
}
|
|
24
|
-
return { tx, coinData: coin };
|
|
25
|
-
}
|
|
26
|
-
if (objectIds.length > 1) {
|
|
27
|
-
tx.mergeCoins(tx.object(coinObjectId), objectIds.slice(1).map((item) => tx.object(item)));
|
|
28
|
-
}
|
|
29
|
-
// split correct amount to swap
|
|
30
|
-
const coinData = tx.splitCoins(tx.object(coinObjectId), splits);
|
|
31
|
-
return { tx, coinData };
|
|
32
|
-
};
|
|
33
|
-
exports.getSplitCoinForTx = getSplitCoinForTx;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CoinStruct } from "@mysten/sui/client";
|
|
2
|
-
export declare const getCoinOjectIdsByAmount: (address: string, amount: string, coinType: string) => Promise<{
|
|
3
|
-
objectIds: string[];
|
|
4
|
-
objectCoins: CoinStruct[];
|
|
5
|
-
balance: string;
|
|
6
|
-
}>;
|
|
7
|
-
//# sourceMappingURL=getCoinOjectIdsByAmount.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getCoinOjectIdsByAmount.d.ts","sourceRoot":"","sources":["../../../../src/libs/getCoinOjectIdsByAmount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AA4BhE,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,EACf,QAAQ,MAAM,EACd,UAAU,MAAM,KACf,OAAO,CAAC;IACT,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB,CA2CA,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Transaction, TransactionResult } from "@mysten/sui/transactions";
|
|
2
|
-
export declare const getSplitCoinForTx: (account: string, amount: string, splits: string[], coinType: string, inheritTx?: Transaction, inspecTransaction?: boolean, isSponsored?: boolean) => Promise<{
|
|
3
|
-
tx: Transaction;
|
|
4
|
-
coinData: TransactionResult;
|
|
5
|
-
}>;
|
|
6
|
-
//# sourceMappingURL=getSplitCoinForTx.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSplitCoinForTx.d.ts","sourceRoot":"","sources":["../../../../src/libs/getSplitCoinForTx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAK1E,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,EACf,QAAQ,MAAM,EACd,QAAQ,MAAM,EAAE,EAChB,UAAU,MAAM,EAChB,YAAY,WAAW,EACvB,oBAAoB,OAAO,EAC3B,qBAAmB,KAClB,OAAO,CAAC;IACT,EAAE,EAAE,WAAW,CAAC;IAChB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,CAqCA,CAAC"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Config } from "../config";
|
|
2
|
-
const orderByKey = (array, key, sortBy) => {
|
|
3
|
-
if (!array?.length) {
|
|
4
|
-
return;
|
|
5
|
-
}
|
|
6
|
-
let swapped;
|
|
7
|
-
do {
|
|
8
|
-
swapped = false;
|
|
9
|
-
for (let i = 0; i < array.length - 1; i++) {
|
|
10
|
-
const a = BigInt(array[i][key]);
|
|
11
|
-
const b = BigInt(array[i + 1][key]);
|
|
12
|
-
if (sortBy === "desc" ? a < b : a > b) {
|
|
13
|
-
const temp = array[i];
|
|
14
|
-
array[i] = array[i + 1];
|
|
15
|
-
array[i + 1] = temp;
|
|
16
|
-
swapped = true;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
} while (swapped);
|
|
20
|
-
return array;
|
|
21
|
-
};
|
|
22
|
-
export const getCoinOjectIdsByAmount = async (address, amount, coinType) => {
|
|
23
|
-
let coinBalances = [];
|
|
24
|
-
let hasNextPage = true;
|
|
25
|
-
let nextCursor = undefined;
|
|
26
|
-
while (hasNextPage) {
|
|
27
|
-
try {
|
|
28
|
-
const coins = await Config.getSuiClient().getCoins({
|
|
29
|
-
owner: address,
|
|
30
|
-
coinType,
|
|
31
|
-
cursor: nextCursor,
|
|
32
|
-
});
|
|
33
|
-
coinBalances = [...coinBalances, ...coins.data];
|
|
34
|
-
hasNextPage = coins.hasNextPage;
|
|
35
|
-
nextCursor = coins.nextCursor;
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
console.error("Error fetching data:", error);
|
|
39
|
-
hasNextPage = false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
// sort coin balance before get object id
|
|
43
|
-
const coinObj = orderByKey(coinBalances.map((item) => {
|
|
44
|
-
return {
|
|
45
|
-
...item,
|
|
46
|
-
balance: item.balance,
|
|
47
|
-
};
|
|
48
|
-
}), "balance", "desc") ?? [];
|
|
49
|
-
let balance = "0";
|
|
50
|
-
const objectIds = [];
|
|
51
|
-
const objectCoins = [];
|
|
52
|
-
for (const coin of coinObj) {
|
|
53
|
-
balance = (BigInt(coin.balance) + BigInt(balance)).toString(10);
|
|
54
|
-
objectIds.push(coin.coinObjectId);
|
|
55
|
-
objectCoins.push(coin);
|
|
56
|
-
if (BigInt(balance) >= BigInt(amount)) {
|
|
57
|
-
break;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return { objectIds, balance, objectCoins };
|
|
61
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Transaction } from "@mysten/sui/transactions";
|
|
2
|
-
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
3
|
-
import { SUI_TYPE } from "../constants/tokens";
|
|
4
|
-
import { getCoinOjectIdsByAmount } from "./getCoinOjectIdsByAmount";
|
|
5
|
-
export const getSplitCoinForTx = async (account, amount, splits, coinType, inheritTx, inspecTransaction, isSponsored = false) => {
|
|
6
|
-
const tx = inheritTx ?? new Transaction();
|
|
7
|
-
const { objectIds } = await getCoinOjectIdsByAmount(account, amount, coinType);
|
|
8
|
-
const coinObjectId = objectIds[0];
|
|
9
|
-
if (normalizeStructTag(coinType) === normalizeStructTag(SUI_TYPE) &&
|
|
10
|
-
!isSponsored) {
|
|
11
|
-
let coin;
|
|
12
|
-
if (inspecTransaction) {
|
|
13
|
-
if (objectIds.length > 1) {
|
|
14
|
-
tx.mergeCoins(tx.object(coinObjectId), objectIds.slice(1).map((item) => tx.object(item)));
|
|
15
|
-
}
|
|
16
|
-
coin = tx.splitCoins(tx.object(coinObjectId), splits);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
coin = tx.splitCoins(tx.gas, splits);
|
|
20
|
-
}
|
|
21
|
-
return { tx, coinData: coin };
|
|
22
|
-
}
|
|
23
|
-
if (objectIds.length > 1) {
|
|
24
|
-
tx.mergeCoins(tx.object(coinObjectId), objectIds.slice(1).map((item) => tx.object(item)));
|
|
25
|
-
}
|
|
26
|
-
// split correct amount to swap
|
|
27
|
-
const coinData = tx.splitCoins(tx.object(coinObjectId), splits);
|
|
28
|
-
return { tx, coinData };
|
|
29
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { CoinStruct } from "@mysten/sui/client";
|
|
2
|
-
export declare const getCoinOjectIdsByAmount: (address: string, amount: string, coinType: string) => Promise<{
|
|
3
|
-
objectIds: string[];
|
|
4
|
-
objectCoins: CoinStruct[];
|
|
5
|
-
balance: string;
|
|
6
|
-
}>;
|
|
7
|
-
//# sourceMappingURL=getCoinOjectIdsByAmount.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getCoinOjectIdsByAmount.d.ts","sourceRoot":"","sources":["../../../../src/libs/getCoinOjectIdsByAmount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AA4BhE,eAAO,MAAM,uBAAuB,GAClC,SAAS,MAAM,EACf,QAAQ,MAAM,EACd,UAAU,MAAM,KACf,OAAO,CAAC;IACT,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,CAAC;CACjB,CA2CA,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Transaction, TransactionResult } from "@mysten/sui/transactions";
|
|
2
|
-
export declare const getSplitCoinForTx: (account: string, amount: string, splits: string[], coinType: string, inheritTx?: Transaction, inspecTransaction?: boolean, isSponsored?: boolean) => Promise<{
|
|
3
|
-
tx: Transaction;
|
|
4
|
-
coinData: TransactionResult;
|
|
5
|
-
}>;
|
|
6
|
-
//# sourceMappingURL=getSplitCoinForTx.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getSplitCoinForTx.d.ts","sourceRoot":"","sources":["../../../../src/libs/getSplitCoinForTx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAK1E,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,EACf,QAAQ,MAAM,EACd,QAAQ,MAAM,EAAE,EAChB,UAAU,MAAM,EAChB,YAAY,WAAW,EACvB,oBAAoB,OAAO,EAC3B,qBAAmB,KAClB,OAAO,CAAC;IACT,EAAE,EAAE,WAAW,CAAC;IAChB,QAAQ,EAAE,iBAAiB,CAAC;CAC7B,CAqCA,CAAC"}
|