@7kprotocol/sdk-ts 3.5.2-beta.0 → 3.5.2
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/config/index.js +0 -9
- package/lib/cjs/constants/apiEndpoints.js +1 -1
- package/lib/cjs/features/metaAg/index.js +93 -88
- package/lib/cjs/features/metaAg/providers/bluefin.js +6 -6
- package/lib/cjs/features/metaAg/providers/cetus.js +4 -4
- package/lib/cjs/features/metaAg/providers/flowx.js +4 -4
- package/lib/cjs/features/swap/buildTx.js +0 -3
- package/lib/cjs/features/swap/buildTxV2.js +6 -10
- package/lib/cjs/features/swap/config.js +1 -2
- package/lib/cjs/features/swap/getQuote.js +2 -3
- package/lib/cjs/libs/protocols/bluefinx/client.js +1 -1
- package/lib/cjs/types/config/index.d.ts +0 -4
- package/lib/cjs/types/config/index.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/index.d.ts +2 -11
- package/lib/cjs/types/features/metaAg/index.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/bluefin.d.ts +3 -3
- package/lib/cjs/types/features/metaAg/providers/bluefin.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/cetus.d.ts +5 -4
- package/lib/cjs/types/features/metaAg/providers/cetus.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/flowx.d.ts +3 -3
- package/lib/cjs/types/features/metaAg/providers/flowx.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/buildTx.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/buildTxV2.d.ts +3 -3
- package/lib/cjs/types/features/swap/buildTxV2.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/config.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/getQuote.d.ts +3 -1
- package/lib/cjs/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +1 -3
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/metaAg.js +4 -11
- package/lib/cjs/types/types/metaAg.d.ts +8 -60
- package/lib/cjs/types/types/metaAg.d.ts.map +1 -1
- package/lib/cjs/types/utils/condition.d.ts +1 -1
- package/lib/cjs/types/utils/condition.d.ts.map +1 -1
- package/lib/esm/config/index.js +0 -9
- package/lib/esm/constants/apiEndpoints.js +1 -1
- package/lib/esm/features/metaAg/index.js +94 -89
- package/lib/esm/features/metaAg/providers/bluefin.js +6 -6
- package/lib/esm/features/metaAg/providers/cetus.js +4 -4
- package/lib/esm/features/metaAg/providers/flowx.js +4 -4
- package/lib/esm/features/swap/buildTx.js +0 -3
- package/lib/esm/features/swap/buildTxV2.js +2 -6
- package/lib/esm/features/swap/config.js +1 -2
- package/lib/esm/features/swap/getQuote.js +2 -3
- package/lib/esm/libs/protocols/bluefinx/client.js +1 -1
- package/lib/esm/types/config/index.d.ts +0 -4
- package/lib/esm/types/config/index.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/index.d.ts +2 -11
- package/lib/esm/types/features/metaAg/index.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/bluefin.d.ts +3 -3
- package/lib/esm/types/features/metaAg/providers/bluefin.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/cetus.d.ts +5 -4
- package/lib/esm/types/features/metaAg/providers/cetus.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/flowx.d.ts +3 -3
- package/lib/esm/types/features/metaAg/providers/flowx.d.ts.map +1 -1
- package/lib/esm/types/features/swap/buildTx.d.ts.map +1 -1
- package/lib/esm/types/features/swap/buildTxV2.d.ts +3 -3
- package/lib/esm/types/features/swap/buildTxV2.d.ts.map +1 -1
- package/lib/esm/types/features/swap/config.d.ts.map +1 -1
- package/lib/esm/types/features/swap/getQuote.d.ts +3 -1
- package/lib/esm/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +1 -3
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/metaAg.js +2 -8
- package/lib/esm/types/types/metaAg.d.ts +8 -60
- package/lib/esm/types/types/metaAg.d.ts.map +1 -1
- package/lib/esm/types/utils/condition.d.ts +1 -1
- package/lib/esm/types/utils/condition.d.ts.map +1 -1
- package/package.json +2 -3
- package/lib/cjs/features/metaAg/common.js +0 -117
- package/lib/cjs/features/metaAg/providers/astro.js +0 -42
- package/lib/cjs/features/metaAg/providers/bluefinx.js +0 -87
- package/lib/cjs/features/metaAg/providers/okx.js +0 -181
- package/lib/cjs/types/features/metaAg/common.d.ts +0 -33
- package/lib/cjs/types/features/metaAg/common.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/providers/astro.d.ts +0 -9
- package/lib/cjs/types/features/metaAg/providers/astro.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/providers/bluefinx.d.ts +0 -10
- package/lib/cjs/types/features/metaAg/providers/bluefinx.d.ts.map +0 -1
- package/lib/cjs/types/features/metaAg/providers/okx.d.ts +0 -21
- package/lib/cjs/types/features/metaAg/providers/okx.d.ts.map +0 -1
- package/lib/cjs/types/okx.js +0 -6
- package/lib/cjs/types/types/okx.d.ts +0 -193
- package/lib/cjs/types/types/okx.d.ts.map +0 -1
- package/lib/esm/features/metaAg/common.js +0 -109
- package/lib/esm/features/metaAg/providers/astro.js +0 -39
- package/lib/esm/features/metaAg/providers/bluefinx.js +0 -84
- package/lib/esm/features/metaAg/providers/okx.js +0 -146
- package/lib/esm/types/features/metaAg/common.d.ts +0 -33
- package/lib/esm/types/features/metaAg/common.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/providers/astro.d.ts +0 -9
- package/lib/esm/types/features/metaAg/providers/astro.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/providers/bluefinx.d.ts +0 -10
- package/lib/esm/types/features/metaAg/providers/bluefinx.d.ts.map +0 -1
- package/lib/esm/types/features/metaAg/providers/okx.d.ts +0 -21
- package/lib/esm/types/features/metaAg/providers/okx.d.ts.map +0 -1
- package/lib/esm/types/okx.js +0 -5
- package/lib/esm/types/types/okx.d.ts +0 -193
- package/lib/esm/types/types/okx.d.ts.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SuiClient } from "@mysten/sui/client";
|
|
2
2
|
import { TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
3
|
-
import {
|
|
4
|
-
export declare class FlowxProvider implements
|
|
3
|
+
import { AgProvider, EProvider, FlowxProviderOptions, MetaQuote, MetaQuoteOptions, MetaSwapOptions } from "../../../types/metaAg";
|
|
4
|
+
export declare class FlowxProvider implements AgProvider {
|
|
5
5
|
private readonly options;
|
|
6
6
|
private readonly client;
|
|
7
|
-
|
|
7
|
+
kind: EProvider;
|
|
8
8
|
private quoter;
|
|
9
9
|
constructor(options: FlowxProviderOptions, client: SuiClient);
|
|
10
10
|
quote(quoteOptions: MetaQuoteOptions): Promise<MetaQuote>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flowx.d.ts","sourceRoot":"","sources":["../../../../../../src/features/metaAg/providers/flowx.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAGrE,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"flowx.d.ts","sourceRoot":"","sources":["../../../../../../src/features/metaAg/providers/flowx.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAGrE,OAAO,EACL,UAAU,EACV,SAAS,EACT,oBAAoB,EACpB,SAAS,EACT,gBAAgB,EAChB,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAG/B,qBAAa,aAAc,YAAW,UAAU;IAI5C,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,IAAI,YAAmB;IACvB,OAAO,CAAC,MAAM,CAAmB;gBAEd,OAAO,EAAE,oBAAoB,EAC7B,MAAM,EAAE,SAAS;IAK9B,KAAK,CAAC,YAAY,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC;IAuBzD,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,yBAAyB,CAAC;CAqBzE"}
|
|
@@ -1 +1 @@
|
|
|
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,CA+FvC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,WAAW,aAAa,EAAE,aAa3D,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,IAAI,WAAW,EACf,eAAe,aAAa,EAAE,
|
|
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,CA+FvC,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,WAAW,aAAa,EAAE,aAa3D,CAAC;AAEF,eAAO,MAAM,yBAAyB,GACpC,IAAI,WAAW,EACf,eAAe,aAAa,EAAE,oCAkB/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"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
-
import { BuildTxResult } from "../../types/aggregator";
|
|
2
|
+
import { BuildTxResult, Config, TxSorSwap } from "../../types/aggregator";
|
|
3
3
|
import { BuildTxParams, MultiSwapParams } from "../../types/tx";
|
|
4
4
|
/**
|
|
5
5
|
* Wave-based transaction builder that optimizes swap execution by:
|
|
@@ -7,8 +7,8 @@ import { BuildTxParams, MultiSwapParams } from "../../types/tx";
|
|
|
7
7
|
* 2. Merging redundant swaps to the same pool within each wave
|
|
8
8
|
* 3. Processing waves sequentially, passing intermediate tokens between waves
|
|
9
9
|
*/
|
|
10
|
-
export declare const buildTxV2: (
|
|
11
|
-
export declare const
|
|
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
12
|
/**
|
|
13
13
|
* execute multiple swap in single transaction
|
|
14
14
|
*
|
|
@@ -1 +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,
|
|
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,yCAuJvB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAU,iDAM7B,eAAe,uDAiDjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,eAAO,MAAM,cAAc,EAAE,MAqL5B,CAAC;AAIF,wBAAsB,SAAS,oBAe9B"}
|
|
@@ -17,11 +17,13 @@ interface Params {
|
|
|
17
17
|
taker?: string;
|
|
18
18
|
/** If true, excludes all liquidity sources that depend on pyth price feeds - pyth client use tx.gas to pay the fee*/
|
|
19
19
|
isSponsored?: boolean;
|
|
20
|
+
/** Custom API endpoint */
|
|
21
|
+
api?: string;
|
|
20
22
|
/** Maximum number of paths to consider for the quote */
|
|
21
23
|
maxPaths?: number;
|
|
22
24
|
}
|
|
23
25
|
export declare const DEFAULT_SOURCES: SourceDex[];
|
|
24
26
|
export declare const ORACLE_BASED_SOURCES: Set<SourceDex>;
|
|
25
|
-
export declare function getQuote({ tokenIn, tokenOut, amountIn, sources: _sources, commissionBps, targetPools, excludedPools, taker, isSponsored, maxPaths, }: Params): Promise<QuoteResponse>;
|
|
27
|
+
export declare function getQuote({ tokenIn, tokenOut, amountIn, sources: _sources, commissionBps, targetPools, excludedPools, taker, isSponsored, api, maxPaths, }: Params): Promise<QuoteResponse>;
|
|
26
28
|
export {};
|
|
27
29
|
//# sourceMappingURL=getQuote.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getQuote.d.ts","sourceRoot":"","sources":["../../../../../src/features/swap/getQuote.ts"],"names":[],"mappings":"
|
|
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;IACtB,0BAA0B;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,eAAO,MAAM,eAAe,EAAE,SAAS,EA0BtC,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,EACX,GAAG,EACH,QAAQ,GACT,EAAE,MAAM,0BA8CR"}
|
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -11,8 +11,6 @@ declare const setSuiClient: (client: import("@mysten/sui/dist/cjs/client").SuiCl
|
|
|
11
11
|
export { buildTx, buildTxV2, cancelDcaOrder, cancelLimitOrder, claimExpiredLimitOrder, Config, DEFAULT_SOURCES, estimateGasFee, executeBluefinTx, executeTx, getClosedDcaOrders, getClosedLimitOrders, getDcaOrderExecutions, getOpenDcaOrders, getOpenLimitOrders, getQuote, getSuiClient, getSuiPrice, getSwapHistory, getTokenPrice, getTokenPrices, MetaAg, multiSwap, placeDcaOrder, placeLimitOrder, setSuiClient, };
|
|
12
12
|
declare const _default: {
|
|
13
13
|
Config: {
|
|
14
|
-
setApi: (url: string) => void;
|
|
15
|
-
getApi: () => string;
|
|
16
14
|
setApiKey: (key: string) => void;
|
|
17
15
|
getApiKey: () => string;
|
|
18
16
|
setBluefinXApiKey: (key: string) => void;
|
|
@@ -32,7 +30,7 @@ declare const _default: {
|
|
|
32
30
|
getQuote: typeof getQuote;
|
|
33
31
|
estimateGasFee: typeof estimateGasFee;
|
|
34
32
|
buildTx: ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }: import("./types/tx").BuildTxParams) => Promise<import("./types/aggregator").BuildTxResult>;
|
|
35
|
-
buildTxV2: (
|
|
33
|
+
buildTxV2: ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }: import("./types/tx").BuildTxParams) => Promise<import("./types/aggregator").BuildTxResult>;
|
|
36
34
|
multiSwap: ({ sender, slippageBps, swaps, tx, commission, }: import("./types/tx").MultiSwapParams) => Promise<Record<string, import("@mysten/sui/dist/cjs/transactions").TransactionObjectArgument>>;
|
|
37
35
|
getSwapHistory: typeof getSwapHistory;
|
|
38
36
|
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>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,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,MAAM,EACN,SAAS,EAET,aAAa,EAEb,eAAe,EACf,YAAY,GACb,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,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,MAAM,EACN,SAAS,EAET,aAAa,EAEb,eAAe,EACf,YAAY,GACb,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,wBAwCE"}
|
package/lib/cjs/types/metaAg.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AgProvider = exports.EProvider = void 0;
|
|
4
4
|
var EProvider;
|
|
5
5
|
(function (EProvider) {
|
|
6
6
|
EProvider["BLUEFIN7K"] = "bluefin7k";
|
|
7
7
|
EProvider["CETUS"] = "cetus";
|
|
8
8
|
EProvider["FLOWX"] = "flowx";
|
|
9
|
-
EProvider["OKX"] = "okx";
|
|
10
|
-
EProvider["BLUEFINX"] = "bluefinx";
|
|
11
|
-
EProvider["ASTRO"] = "astro";
|
|
12
9
|
})(EProvider || (exports.EProvider = EProvider = {}));
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
provider.kind === EProvider.ASTRO;
|
|
17
|
-
exports.isAggregatorProvider = isAggregatorProvider;
|
|
18
|
-
const isSwapAPIProvider = (provider) => provider.kind === EProvider.OKX || provider.kind === EProvider.BLUEFINX;
|
|
19
|
-
exports.isSwapAPIProvider = isSwapAPIProvider;
|
|
10
|
+
class AgProvider {
|
|
11
|
+
}
|
|
12
|
+
exports.AgProvider = AgProvider;
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import type { PreSwapLpChangeParams, RouterDataV3 } from "@cetusprotocol/aggregator-sdk";
|
|
2
2
|
import type { AggregatorQuoter, Protocol } from "@flowx-finance/sdk";
|
|
3
3
|
import type { GasCostSummary } from "@mysten/sui/client";
|
|
4
|
-
import { SignatureWithBytes } from "@mysten/sui/cryptography";
|
|
5
4
|
import type { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
6
|
-
import type { Quote, SwapOptions } from "@naviprotocol/astros-aggregator-sdk";
|
|
7
5
|
import { QuoteResponse, SourceDex } from "./aggregator";
|
|
8
|
-
import { OkxSwapResponseData } from "./okx";
|
|
9
6
|
export declare enum EProvider {
|
|
10
7
|
BLUEFIN7K = "bluefin7k",
|
|
11
8
|
CETUS = "cetus",
|
|
12
|
-
FLOWX = "flowx"
|
|
13
|
-
OKX = "okx",
|
|
14
|
-
BLUEFINX = "bluefinx",
|
|
15
|
-
ASTRO = "astro"
|
|
9
|
+
FLOWX = "flowx"
|
|
16
10
|
}
|
|
17
11
|
type ProviderBaseOptions = {
|
|
18
12
|
api?: string;
|
|
@@ -40,23 +34,12 @@ export type CetusProviderOptions = ProviderBaseOptions & {
|
|
|
40
34
|
depth?: number;
|
|
41
35
|
liquidityChanges?: PreSwapLpChangeParams[];
|
|
42
36
|
};
|
|
43
|
-
export type OkxProviderOptions = Required<Omit<ProviderBaseOptions, "api">> & {
|
|
44
|
-
api?: string;
|
|
45
|
-
secretKey: string;
|
|
46
|
-
apiPassphrase: string;
|
|
47
|
-
projectId: string;
|
|
48
|
-
};
|
|
49
|
-
export type BluefinXProviderOptions = ProviderBaseOptions;
|
|
50
|
-
export type AstroProviderOptions = ProviderBaseOptions & Pick<SwapOptions, "dexList" | "depth">;
|
|
51
37
|
export interface MetaAgOptions {
|
|
52
38
|
/**If not specified, all providers will be used */
|
|
53
39
|
providers?: {
|
|
54
40
|
[EProvider.BLUEFIN7K]?: BluefinProviderOptions;
|
|
55
41
|
[EProvider.FLOWX]?: FlowxProviderOptions;
|
|
56
42
|
[EProvider.CETUS]?: CetusProviderOptions;
|
|
57
|
-
[EProvider.OKX]?: OkxProviderOptions;
|
|
58
|
-
[EProvider.BLUEFINX]?: BluefinXProviderOptions;
|
|
59
|
-
[EProvider.ASTRO]?: AstroProviderOptions;
|
|
60
43
|
};
|
|
61
44
|
/**Mainnet Json Rpc url, if not specified, the default mainnet url will be used */
|
|
62
45
|
fullnodeUrl?: string;
|
|
@@ -74,11 +57,9 @@ export interface MetaAgOptions {
|
|
|
74
57
|
tipBps?: number;
|
|
75
58
|
}
|
|
76
59
|
export interface MetaQuoteOptions {
|
|
77
|
-
|
|
78
|
-
|
|
60
|
+
coinInType: string;
|
|
61
|
+
coinOutType: string;
|
|
79
62
|
amountIn: string;
|
|
80
|
-
/** Required for RFQ providers (ie: BluefinX) */
|
|
81
|
-
signer?: string;
|
|
82
63
|
/**
|
|
83
64
|
* Timeout for quote operation in milliseconds
|
|
84
65
|
* @default 2000ms
|
|
@@ -95,22 +76,7 @@ export interface MetaSimulationOptions {
|
|
|
95
76
|
/** If specify, defer the simulation that could reduce the time to display quote result, you must update the quote via the id on callback
|
|
96
77
|
* else await all quote and simulation before return
|
|
97
78
|
*/
|
|
98
|
-
onSimulated?: (payload: MetaQuote) => void;
|
|
99
|
-
}
|
|
100
|
-
export interface MetaFastSwapOptions {
|
|
101
|
-
/** Quote object from the quote operation */
|
|
102
|
-
quote: MetaQuote;
|
|
103
|
-
/** Signer address (owner of `coinIn`) */
|
|
104
|
-
signer: string;
|
|
105
|
-
/** If true, use the gas coin for the swap
|
|
106
|
-
* @default true */
|
|
107
|
-
useGasCoin?: boolean;
|
|
108
|
-
/**
|
|
109
|
-
* Sign the transaction bytes
|
|
110
|
-
* @param txBytes - base64 transaction bytes
|
|
111
|
-
* @returns - signature with bytes
|
|
112
|
-
*/
|
|
113
|
-
signTransaction: (txBytes: string) => Promise<SignatureWithBytes>;
|
|
79
|
+
onSimulated?: (payload: Pick<MetaQuote, "simulatedAmountOut" | "gasUsed" | "id" | "provider">) => void;
|
|
114
80
|
}
|
|
115
81
|
export interface MetaSwapOptions {
|
|
116
82
|
/** Quote object from the quote operation */
|
|
@@ -134,15 +100,6 @@ export type MetaQuote = ({
|
|
|
134
100
|
} | {
|
|
135
101
|
provider: EProvider.FLOWX;
|
|
136
102
|
quote: FlowxQuoteResponse;
|
|
137
|
-
} | {
|
|
138
|
-
provider: EProvider.OKX;
|
|
139
|
-
quote: OkxSwapResponseData;
|
|
140
|
-
} | {
|
|
141
|
-
provider: EProvider.BLUEFINX;
|
|
142
|
-
quote: QuoteResponse;
|
|
143
|
-
} | {
|
|
144
|
-
provider: EProvider.ASTRO;
|
|
145
|
-
quote: Quote;
|
|
146
103
|
}) & {
|
|
147
104
|
/** uuid to keep track the quote result, used to apply simulation result on quote on callback `onSimulated`*/
|
|
148
105
|
id: string;
|
|
@@ -161,19 +118,10 @@ export type MetaQuote = ({
|
|
|
161
118
|
/** Estimate gas consumption if the transaction is executed */
|
|
162
119
|
gasUsed?: GasCostSummary;
|
|
163
120
|
};
|
|
164
|
-
export
|
|
165
|
-
|
|
166
|
-
quote(
|
|
167
|
-
|
|
168
|
-
export interface SwapAPIProvider extends QuoteProvider {
|
|
169
|
-
readonly kind: EProvider.OKX | EProvider.BLUEFINX;
|
|
170
|
-
fastSwap(options: MetaFastSwapOptions): Promise<string>;
|
|
171
|
-
}
|
|
172
|
-
export interface AggregatorProvider extends QuoteProvider {
|
|
173
|
-
readonly kind: EProvider.BLUEFIN7K | EProvider.CETUS | EProvider.FLOWX | EProvider.ASTRO;
|
|
174
|
-
swap(options: MetaSwapOptions): Promise<TransactionObjectArgument>;
|
|
121
|
+
export declare abstract class AgProvider {
|
|
122
|
+
abstract kind: EProvider;
|
|
123
|
+
abstract quote(quoteOptions: MetaQuoteOptions): Promise<MetaQuote>;
|
|
124
|
+
abstract swap(options: MetaSwapOptions): Promise<TransactionObjectArgument>;
|
|
175
125
|
}
|
|
176
|
-
export declare const isAggregatorProvider: (provider: QuoteProvider) => provider is AggregatorProvider;
|
|
177
|
-
export declare const isSwapAPIProvider: (provider: QuoteProvider) => provider is SwapAPIProvider;
|
|
178
126
|
export {};
|
|
179
127
|
//# sourceMappingURL=metaAg.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metaAg.d.ts","sourceRoot":"","sources":["../../../../src/types/metaAg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,YAAY,EACb,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,
|
|
1
|
+
{"version":3,"file":"metaAg.d.ts","sourceRoot":"","sources":["../../../../src/types/metaAg.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function assert(condition:
|
|
1
|
+
export declare function assert(condition: boolean, message?: string | null): asserts condition;
|
|
2
2
|
//# sourceMappingURL=condition.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../../src/utils/condition.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CACpB,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"condition.d.ts","sourceRoot":"","sources":["../../../../src/utils/condition.ts"],"names":[],"mappings":"AAAA,wBAAgB,MAAM,CACpB,SAAS,EAAE,OAAO,EAClB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,OAAO,CAAC,SAAS,CAInB"}
|
package/lib/esm/config/index.js
CHANGED
|
@@ -3,7 +3,6 @@ import { SuiPriceServiceConnection, SuiPythClient, } from "@pythnetwork/pyth-sui
|
|
|
3
3
|
const HERMES_API = "https://hermes.pyth.network";
|
|
4
4
|
const WORMHOLE_STATE_ID = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
|
|
5
5
|
const PYTH_STATE_ID = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
|
|
6
|
-
let api = "";
|
|
7
6
|
let apiKey = "";
|
|
8
7
|
let bluefinXApiKey = "";
|
|
9
8
|
let suiClient = new SuiClient({
|
|
@@ -11,12 +10,6 @@ let suiClient = new SuiClient({
|
|
|
11
10
|
});
|
|
12
11
|
let pythClient = new SuiPythClient(suiClient, PYTH_STATE_ID, WORMHOLE_STATE_ID);
|
|
13
12
|
let pythConnection = new SuiPriceServiceConnection(HERMES_API);
|
|
14
|
-
function setApi(url) {
|
|
15
|
-
api = url;
|
|
16
|
-
}
|
|
17
|
-
function getApi() {
|
|
18
|
-
return api;
|
|
19
|
-
}
|
|
20
13
|
function setApiKey(key) {
|
|
21
14
|
apiKey = key;
|
|
22
15
|
}
|
|
@@ -48,8 +41,6 @@ function getPythConnection() {
|
|
|
48
41
|
return pythConnection;
|
|
49
42
|
}
|
|
50
43
|
const Config = {
|
|
51
|
-
setApi,
|
|
52
|
-
getApi,
|
|
53
44
|
setApiKey,
|
|
54
45
|
getApiKey,
|
|
55
46
|
setBluefinXApiKey,
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { getFullnodeUrl, SuiClient
|
|
1
|
+
import { getFullnodeUrl, SuiClient } from "@mysten/sui/client";
|
|
2
2
|
import { coinWithBalance, Transaction, } from "@mysten/sui/transactions";
|
|
3
|
-
import { normalizeStructTag
|
|
3
|
+
import { normalizeStructTag } from "@mysten/sui/utils";
|
|
4
|
+
import { _7K_META_CONFIG, _7K_META_PACKAGE_ID, _7K_META_PUBLISHED_AT, _7K_META_VAULT, } from "../../constants/_7k";
|
|
4
5
|
import { SUI_ADDRESS_ZERO } from "../../constants/sui";
|
|
5
|
-
import { EProvider,
|
|
6
|
+
import { EProvider, } from "../../types/metaAg";
|
|
6
7
|
import { assert } from "../../utils/condition";
|
|
7
8
|
import { SuiClientUtils } from "../../utils/SuiClientUtils";
|
|
8
9
|
import { getExpectedReturn } from "../swap/buildTx";
|
|
9
|
-
import { metaSettle, simulateAggregator, simulateBluefinX, timeout, } from "./common";
|
|
10
10
|
import { BluefinProvider } from "./providers/bluefin";
|
|
11
|
-
import { BluefinXProvider } from "./providers/bluefinx";
|
|
12
|
-
import { OkxProvider, simulateOKXSwap } from "./providers/okx";
|
|
13
11
|
const HERMES_API = "https://hermes.pyth.network";
|
|
14
12
|
const DEFAULT_PROVIDERS = {
|
|
15
13
|
[EProvider.BLUEFIN7K]: {},
|
|
16
14
|
[EProvider.FLOWX]: {},
|
|
17
15
|
[EProvider.CETUS]: {},
|
|
18
|
-
[EProvider.ASTRO]: {},
|
|
19
|
-
[EProvider.BLUEFINX]: {},
|
|
20
16
|
};
|
|
21
17
|
export class MetaAg {
|
|
22
18
|
client;
|
|
@@ -56,16 +52,6 @@ export class MetaAg {
|
|
|
56
52
|
const { CetusProvider } = await import("./providers/cetus").catch(catchImportError(EProvider.CETUS));
|
|
57
53
|
this.providers[EProvider.CETUS] = new CetusProvider(providerOptions, this.options, this.client);
|
|
58
54
|
break;
|
|
59
|
-
case EProvider.OKX:
|
|
60
|
-
this.providers[EProvider.OKX] = new OkxProvider(providerOptions, this.options, this.client);
|
|
61
|
-
break;
|
|
62
|
-
case EProvider.BLUEFINX:
|
|
63
|
-
this.providers[EProvider.BLUEFINX] = new BluefinXProvider(providerOptions);
|
|
64
|
-
break;
|
|
65
|
-
case EProvider.ASTRO:
|
|
66
|
-
const { AstroProvider } = await import("./providers/astro").catch(catchImportError(EProvider.ASTRO));
|
|
67
|
-
this.providers[EProvider.ASTRO] = new AstroProvider(providerOptions);
|
|
68
|
-
break;
|
|
69
55
|
default:
|
|
70
56
|
throw new Error(`Provider not supported: ${provider}`);
|
|
71
57
|
}
|
|
@@ -73,40 +59,51 @@ export class MetaAg {
|
|
|
73
59
|
}
|
|
74
60
|
async _simulate(provider, quote, simulation) {
|
|
75
61
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
62
|
+
const tx = new Transaction();
|
|
63
|
+
const id = quote.id;
|
|
64
|
+
const coinOut = await provider.swap({
|
|
65
|
+
quote,
|
|
66
|
+
coinIn: coinWithBalance({
|
|
67
|
+
balance: BigInt(quote.amountIn),
|
|
68
|
+
type: quote.coinTypeIn,
|
|
69
|
+
useGasCoin: false,
|
|
70
|
+
}),
|
|
71
|
+
signer: simulation.sender,
|
|
72
|
+
tx,
|
|
73
|
+
});
|
|
74
|
+
tx.add(metaSettle(quote, coinOut, 10000, this.options.tipBps, this.options.partner, this.options.partnerCommissionBps));
|
|
75
|
+
tx.transferObjects([coinOut], simulation.sender);
|
|
76
|
+
const res = await timeout(() => this.inspector.devInspectTransactionBlock({
|
|
77
|
+
sender: simulation.sender,
|
|
78
|
+
transactionBlock: tx,
|
|
79
|
+
}), simulation.timeout ?? 2000, `simulation for ${provider.kind} provider with id ${id}`);
|
|
80
|
+
if (res.effects.status.status === "failure") {
|
|
81
|
+
throw new Error(res.error ?? "Simulation failed");
|
|
86
82
|
}
|
|
83
|
+
const amountOut = extractAmountOutWrapper(res.events);
|
|
84
|
+
return {
|
|
85
|
+
id,
|
|
86
|
+
simulatedAmountOut: amountOut,
|
|
87
|
+
gasUsed: res.effects.gasUsed,
|
|
88
|
+
provider: provider.kind,
|
|
89
|
+
};
|
|
87
90
|
}
|
|
88
91
|
catch (error) {
|
|
89
|
-
console.warn(
|
|
92
|
+
console.warn(`Failed to simulate ${provider.kind}: `, error);
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
async _quote(provider, options, simulation) {
|
|
93
96
|
const quote = await timeout(async () => {
|
|
94
97
|
const quote = await provider.quote(options);
|
|
95
|
-
if (!quote)
|
|
96
|
-
return null;
|
|
97
98
|
const { expectedAmount } = getExpectedReturn(quote.rawAmountOut, 0, this.options.partnerCommissionBps, this.options.tipBps);
|
|
98
99
|
quote.amountOut = expectedAmount;
|
|
99
100
|
return quote;
|
|
100
|
-
}, options.timeout ?? 2000, `quote for ${provider.kind} provider from ${options.
|
|
101
|
-
if (
|
|
101
|
+
}, options.timeout ?? 2000, `quote for ${provider.kind} provider from ${options.coinInType} to ${options.coinOutType}`);
|
|
102
|
+
if (simulation) {
|
|
102
103
|
if (simulation.onSimulated) {
|
|
103
104
|
this._simulate(provider, quote, simulation).then((payload) => {
|
|
104
105
|
if (payload) {
|
|
105
|
-
|
|
106
|
-
quote.simulatedAmountOut = payload.simulatedAmountOut;
|
|
107
|
-
quote.gasUsed = payload.gasUsed;
|
|
108
|
-
simulation.onSimulated?.({ ...quote });
|
|
109
|
-
});
|
|
106
|
+
simulation.onSimulated?.(payload);
|
|
110
107
|
}
|
|
111
108
|
});
|
|
112
109
|
}
|
|
@@ -118,29 +115,6 @@ export class MetaAg {
|
|
|
118
115
|
}
|
|
119
116
|
return quote;
|
|
120
117
|
}
|
|
121
|
-
async _fastSwap({ quote, signer, useGasCoin, signTransaction }, getTransactionBlockParams) {
|
|
122
|
-
const tx = new Transaction();
|
|
123
|
-
const coin = await this.swap({
|
|
124
|
-
quote,
|
|
125
|
-
signer,
|
|
126
|
-
tx,
|
|
127
|
-
coinIn: coinWithBalance({
|
|
128
|
-
type: quote.coinTypeIn,
|
|
129
|
-
balance: BigInt(quote.amountIn),
|
|
130
|
-
useGasCoin,
|
|
131
|
-
}),
|
|
132
|
-
});
|
|
133
|
-
tx.transferObjects([coin], signer);
|
|
134
|
-
tx.setSenderIfNotSet(signer);
|
|
135
|
-
const txBytes = await tx.build({ client: this.client });
|
|
136
|
-
const { signature, bytes } = await signTransaction(toBase64(txBytes));
|
|
137
|
-
return this.client.executeTransactionBlock({
|
|
138
|
-
transactionBlock: bytes,
|
|
139
|
-
signature,
|
|
140
|
-
options: getTransactionBlockParams?.options,
|
|
141
|
-
signal: getTransactionBlockParams?.signal,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
118
|
/**
|
|
145
119
|
* Get quotes from all providers
|
|
146
120
|
* @param options - quote options
|
|
@@ -150,8 +124,8 @@ export class MetaAg {
|
|
|
150
124
|
async quote(options, simulation) {
|
|
151
125
|
const opts = {
|
|
152
126
|
...options,
|
|
153
|
-
|
|
154
|
-
|
|
127
|
+
coinInType: normalizeStructTag(options.coinInType),
|
|
128
|
+
coinOutType: normalizeStructTag(options.coinOutType),
|
|
155
129
|
};
|
|
156
130
|
const quotes = await Promise.allSettled(Object.entries(this.options.providers)
|
|
157
131
|
.filter(([_k, v]) => !v.disabled)
|
|
@@ -167,8 +141,6 @@ export class MetaAg {
|
|
|
167
141
|
}
|
|
168
142
|
/**
|
|
169
143
|
* Build transaction from quote
|
|
170
|
-
* @info Use this function to build composable transaction (ie: add more commands after the swap, consume the coin out object)
|
|
171
|
-
* @warning Providers that build transaction on the fly (typically RFQ, Swap-API providers ie: BluefinX, Okx, ...) are not supported, please use `fastSwap` instead
|
|
172
144
|
* @param options - build tx options
|
|
173
145
|
* @param slippageBps - slippage bps if not specified, fallback to global slippage bps, if none of them specified, default to 100
|
|
174
146
|
* @returns coin out object, you must consume it by transferObjects, or other sub sequence commands
|
|
@@ -176,32 +148,11 @@ export class MetaAg {
|
|
|
176
148
|
async swap(options, slippageBps) {
|
|
177
149
|
const provider = await this._getProvider(options.quote.provider);
|
|
178
150
|
assert(!!provider, `Provider not found: ${options.quote.provider}`);
|
|
179
|
-
assert(isAggregatorProvider(provider), `Provider does not support swap: ${provider.kind}`);
|
|
180
151
|
const coinOut = await provider.swap(options);
|
|
181
152
|
options.tx.add(metaSettle(options.quote, coinOut, slippageBps ?? this.options.slippageBps ?? 100, this.options.tipBps, this.options.partner, this.options.partnerCommissionBps));
|
|
182
153
|
options.tx.setSenderIfNotSet(options.signer);
|
|
183
154
|
return coinOut;
|
|
184
155
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Build, Sign, and Execute transaction in one step
|
|
187
|
-
* @param options - fast swap options
|
|
188
|
-
* @returns - txDigest of the transaction
|
|
189
|
-
*/
|
|
190
|
-
async fastSwap(options, getTransactionBlockParams) {
|
|
191
|
-
const provider = await this._getProvider(options.quote.provider);
|
|
192
|
-
if (isAggregatorProvider(provider)) {
|
|
193
|
-
return this._fastSwap(options, getTransactionBlockParams);
|
|
194
|
-
}
|
|
195
|
-
else if (isSwapAPIProvider(provider)) {
|
|
196
|
-
return this.client.waitForTransaction({
|
|
197
|
-
...getTransactionBlockParams,
|
|
198
|
-
digest: await provider.fastSwap(options),
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
throw new Error(`Provider not supported: ${provider.kind}`);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
156
|
/**
|
|
206
157
|
* Update meta aggregator options
|
|
207
158
|
* @param options - update options payload
|
|
@@ -234,17 +185,71 @@ export class MetaAg {
|
|
|
234
185
|
}
|
|
235
186
|
}
|
|
236
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner
|
|
190
|
+
* @param quote Meta Aggregator Quote
|
|
191
|
+
* @param coinOut Coin Out Object
|
|
192
|
+
* @param slippageBps Slippage Bps
|
|
193
|
+
* @param tipBps Tip Bps default = 0
|
|
194
|
+
* @param partner address of partner for analytic default is zero address
|
|
195
|
+
*/
|
|
196
|
+
const metaSettle = (quote, coinOut, slippageBps = 100, tipBps = 0, partner, commissionBps = 0) => {
|
|
197
|
+
return (tx) => {
|
|
198
|
+
const { minAmount, expectedAmount } = getExpectedReturn(quote.rawAmountOut, slippageBps, commissionBps, tipBps);
|
|
199
|
+
if (tipBps > 0) {
|
|
200
|
+
tx.moveCall({
|
|
201
|
+
target: `${_7K_META_PUBLISHED_AT}::vault::collect_tip`,
|
|
202
|
+
typeArguments: [quote.coinTypeOut],
|
|
203
|
+
arguments: [
|
|
204
|
+
tx.object(_7K_META_VAULT),
|
|
205
|
+
tx.object(_7K_META_CONFIG),
|
|
206
|
+
coinOut,
|
|
207
|
+
tx.pure.u64(tipBps),
|
|
208
|
+
],
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
tx.moveCall({
|
|
212
|
+
target: `${_7K_META_PUBLISHED_AT}::settle::settle`,
|
|
213
|
+
typeArguments: [quote.coinTypeIn, quote.coinTypeOut],
|
|
214
|
+
arguments: [
|
|
215
|
+
tx.object(_7K_META_CONFIG),
|
|
216
|
+
tx.object(_7K_META_VAULT),
|
|
217
|
+
tx.pure.u64(quote.amountIn),
|
|
218
|
+
coinOut,
|
|
219
|
+
tx.pure.u64(minAmount),
|
|
220
|
+
tx.pure.u64(expectedAmount),
|
|
221
|
+
tx.pure.option("address", partner),
|
|
222
|
+
tx.pure.u64(commissionBps),
|
|
223
|
+
tx.pure.u64(0), // ps
|
|
224
|
+
],
|
|
225
|
+
});
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
const extractAmountOutWrapper = (events) => {
|
|
229
|
+
const swapEvent = events
|
|
230
|
+
.filter((event) => event.type === `${_7K_META_PACKAGE_ID}::settle::Swap`)
|
|
231
|
+
?.pop();
|
|
232
|
+
return swapEvent?.parsedJson?.amount_out;
|
|
233
|
+
};
|
|
237
234
|
const catchImportError = (provider) => {
|
|
238
235
|
return (e) => {
|
|
239
236
|
const map = {
|
|
240
237
|
[EProvider.CETUS]: "@cetusprotocol/aggregator-sdk",
|
|
241
238
|
[EProvider.FLOWX]: "@flowx-finance/sdk",
|
|
242
239
|
[EProvider.BLUEFIN7K]: "@7kprotocol/sdk-ts",
|
|
243
|
-
[EProvider.ASTRO]: "@naviprotocol/astros-aggregator-sdk",
|
|
244
|
-
[EProvider.OKX]: "",
|
|
245
|
-
[EProvider.BLUEFINX]: "",
|
|
246
240
|
};
|
|
247
241
|
console.warn(`Please install ${map[provider]} to use ${provider} provider`);
|
|
248
242
|
throw e;
|
|
249
243
|
};
|
|
250
244
|
};
|
|
245
|
+
const timeout = async (fn, timeout, msg) => {
|
|
246
|
+
if (timeout <= 0)
|
|
247
|
+
return fn();
|
|
248
|
+
return new Promise((resolve, reject) => {
|
|
249
|
+
const timer = setTimeout(() => reject(new Error(`Timeout ${msg ?? "operation"}`)), timeout);
|
|
250
|
+
fn()
|
|
251
|
+
.then(resolve)
|
|
252
|
+
.catch(reject)
|
|
253
|
+
.finally(() => clearTimeout(timer));
|
|
254
|
+
});
|
|
255
|
+
};
|
|
@@ -2,6 +2,7 @@ import { SuiPriceServiceConnection, SuiPythClient, } from "@pythnetwork/pyth-sui
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { Config } from "../../../config";
|
|
4
4
|
import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
|
|
5
|
+
import { API_ENDPOINTS } from "../../../constants/apiEndpoints";
|
|
5
6
|
import { EProvider, } from "../../../types/metaAg";
|
|
6
7
|
import { assert } from "../../../utils/condition";
|
|
7
8
|
import { buildTxV2 } from "../../swap/buildTxV2";
|
|
@@ -19,8 +20,6 @@ export class BluefinProvider {
|
|
|
19
20
|
const pythConnection = new SuiPriceServiceConnection(this.metaOptions.hermesApi);
|
|
20
21
|
if (options.apiKey)
|
|
21
22
|
Config.setApiKey(options.apiKey);
|
|
22
|
-
if (options.api)
|
|
23
|
-
Config.setApi(options.api);
|
|
24
23
|
Config.setSuiClient(client);
|
|
25
24
|
Config.setPythClient(pythClient);
|
|
26
25
|
Config.setPythConnection(pythConnection);
|
|
@@ -28,8 +27,9 @@ export class BluefinProvider {
|
|
|
28
27
|
async quote(options) {
|
|
29
28
|
const quote = await getQuote({
|
|
30
29
|
amountIn: options.amountIn,
|
|
31
|
-
tokenIn: options.
|
|
32
|
-
tokenOut: options.
|
|
30
|
+
tokenIn: options.coinInType,
|
|
31
|
+
tokenOut: options.coinOutType,
|
|
32
|
+
api: this.options.api || API_ENDPOINTS.MAIN,
|
|
33
33
|
sources: this.options.sources,
|
|
34
34
|
maxPaths: this.options.maxPaths,
|
|
35
35
|
excludedPools: this.options.excludedPools,
|
|
@@ -42,8 +42,8 @@ export class BluefinProvider {
|
|
|
42
42
|
amountIn: quote.swapAmountWithDecimal,
|
|
43
43
|
rawAmountOut: quote.returnAmountWithDecimal,
|
|
44
44
|
amountOut: quote.returnAmountWithDecimal,
|
|
45
|
-
coinTypeIn: options.
|
|
46
|
-
coinTypeOut: options.
|
|
45
|
+
coinTypeIn: options.coinInType,
|
|
46
|
+
coinTypeOut: options.coinOutType,
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
async swap({ quote, signer, tx, coinIn }) {
|