@7kprotocol/sdk-ts 3.5.1 → 3.5.2-beta.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/lib/cjs/config/index.js +9 -0
- package/lib/cjs/features/metaAg/common.js +117 -0
- package/lib/cjs/features/metaAg/index.js +98 -108
- package/lib/cjs/features/metaAg/providers/astro.js +43 -0
- package/lib/cjs/features/metaAg/providers/bluefin.js +6 -6
- package/lib/cjs/features/metaAg/providers/bluefinx.js +87 -0
- package/lib/cjs/features/metaAg/providers/cetus.js +4 -4
- package/lib/cjs/features/metaAg/providers/flowx.js +4 -4
- package/lib/cjs/features/metaAg/providers/okx.js +181 -0
- package/lib/cjs/features/swap/buildTx.js +3 -0
- package/lib/cjs/features/swap/buildTxV2.js +10 -6
- package/lib/cjs/features/swap/config.js +2 -1
- package/lib/cjs/features/swap/getQuote.js +3 -2
- package/lib/cjs/libs/protocols/bluefinx/client.js +1 -1
- package/lib/cjs/types/config/index.d.ts +4 -0
- package/lib/cjs/types/config/index.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/common.d.ts +33 -0
- package/lib/cjs/types/features/metaAg/common.d.ts.map +1 -0
- package/lib/cjs/types/features/metaAg/index.d.ts +11 -2
- package/lib/cjs/types/features/metaAg/index.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/astro.d.ts +9 -0
- package/lib/cjs/types/features/metaAg/providers/astro.d.ts.map +1 -0
- 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/bluefinx.d.ts +10 -0
- package/lib/cjs/types/features/metaAg/providers/bluefinx.d.ts.map +1 -0
- package/lib/cjs/types/features/metaAg/providers/cetus.d.ts +4 -5
- 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/metaAg/providers/okx.d.ts +21 -0
- package/lib/cjs/types/features/metaAg/providers/okx.d.ts.map +1 -0
- 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 +1 -3
- package/lib/cjs/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +3 -1
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/metaAg.js +11 -4
- package/lib/cjs/types/okx.js +6 -0
- package/lib/cjs/types/types/metaAg.d.ts +60 -8
- package/lib/cjs/types/types/metaAg.d.ts.map +1 -1
- package/lib/cjs/types/types/okx.d.ts +193 -0
- package/lib/cjs/types/types/okx.d.ts.map +1 -0
- 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 +9 -0
- package/lib/esm/features/metaAg/common.js +109 -0
- package/lib/esm/features/metaAg/index.js +99 -109
- package/lib/esm/features/metaAg/providers/astro.js +40 -0
- package/lib/esm/features/metaAg/providers/bluefin.js +6 -6
- package/lib/esm/features/metaAg/providers/bluefinx.js +84 -0
- package/lib/esm/features/metaAg/providers/cetus.js +4 -4
- package/lib/esm/features/metaAg/providers/flowx.js +4 -4
- package/lib/esm/features/metaAg/providers/okx.js +146 -0
- package/lib/esm/features/swap/buildTx.js +3 -0
- package/lib/esm/features/swap/buildTxV2.js +6 -2
- package/lib/esm/features/swap/config.js +2 -1
- package/lib/esm/features/swap/getQuote.js +3 -2
- package/lib/esm/libs/protocols/bluefinx/client.js +1 -1
- package/lib/esm/types/config/index.d.ts +4 -0
- package/lib/esm/types/config/index.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/common.d.ts +33 -0
- package/lib/esm/types/features/metaAg/common.d.ts.map +1 -0
- package/lib/esm/types/features/metaAg/index.d.ts +11 -2
- package/lib/esm/types/features/metaAg/index.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/astro.d.ts +9 -0
- package/lib/esm/types/features/metaAg/providers/astro.d.ts.map +1 -0
- 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/bluefinx.d.ts +10 -0
- package/lib/esm/types/features/metaAg/providers/bluefinx.d.ts.map +1 -0
- package/lib/esm/types/features/metaAg/providers/cetus.d.ts +4 -5
- 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/metaAg/providers/okx.d.ts +21 -0
- package/lib/esm/types/features/metaAg/providers/okx.d.ts.map +1 -0
- 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 +1 -3
- package/lib/esm/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +3 -1
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/metaAg.js +8 -2
- package/lib/esm/types/okx.js +5 -0
- package/lib/esm/types/types/metaAg.d.ts +60 -8
- package/lib/esm/types/types/metaAg.d.ts.map +1 -1
- package/lib/esm/types/types/okx.d.ts +193 -0
- package/lib/esm/types/types/okx.d.ts.map +1 -0
- package/lib/esm/types/utils/condition.d.ts +1 -1
- package/lib/esm/types/utils/condition.d.ts.map +1 -1
- package/package.json +3 -2
package/lib/cjs/types/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ 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;
|
|
14
16
|
setApiKey: (key: string) => void;
|
|
15
17
|
getApiKey: () => string;
|
|
16
18
|
setBluefinXApiKey: (key: string) => void;
|
|
@@ -30,7 +32,7 @@ declare const _default: {
|
|
|
30
32
|
getQuote: typeof getQuote;
|
|
31
33
|
estimateGasFee: typeof estimateGasFee;
|
|
32
34
|
buildTx: ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }: import("./types/tx").BuildTxParams) => Promise<import("./types/aggregator").BuildTxResult>;
|
|
33
|
-
buildTxV2: (
|
|
35
|
+
buildTxV2: (params: import("./types/tx").BuildTxParams) => Promise<import("./types/aggregator").BuildTxResult>;
|
|
34
36
|
multiSwap: ({ sender, slippageBps, swaps, tx, commission, }: import("./types/tx").MultiSwapParams) => Promise<Record<string, import("@mysten/sui/dist/cjs/transactions").TransactionObjectArgument>>;
|
|
35
37
|
getSwapHistory: typeof getSwapHistory;
|
|
36
38
|
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,12 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isSwapAPIProvider = exports.isAggregatorProvider = 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";
|
|
9
12
|
})(EProvider || (exports.EProvider = EProvider = {}));
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
const isAggregatorProvider = (provider) => provider.kind === EProvider.BLUEFIN7K ||
|
|
14
|
+
provider.kind === EProvider.CETUS ||
|
|
15
|
+
provider.kind === EProvider.FLOWX ||
|
|
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;
|
|
@@ -1,12 +1,18 @@
|
|
|
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";
|
|
4
5
|
import type { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
6
|
+
import type { Quote, SwapOptions } from "@naviprotocol/astros-aggregator-sdk";
|
|
5
7
|
import { QuoteResponse, SourceDex } from "./aggregator";
|
|
8
|
+
import { OkxSwapResponseData } from "./okx";
|
|
6
9
|
export declare enum EProvider {
|
|
7
10
|
BLUEFIN7K = "bluefin7k",
|
|
8
11
|
CETUS = "cetus",
|
|
9
|
-
FLOWX = "flowx"
|
|
12
|
+
FLOWX = "flowx",
|
|
13
|
+
OKX = "okx",
|
|
14
|
+
BLUEFINX = "bluefinx",
|
|
15
|
+
ASTRO = "astro"
|
|
10
16
|
}
|
|
11
17
|
type ProviderBaseOptions = {
|
|
12
18
|
api?: string;
|
|
@@ -34,12 +40,23 @@ export type CetusProviderOptions = ProviderBaseOptions & {
|
|
|
34
40
|
depth?: number;
|
|
35
41
|
liquidityChanges?: PreSwapLpChangeParams[];
|
|
36
42
|
};
|
|
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">;
|
|
37
51
|
export interface MetaAgOptions {
|
|
38
52
|
/**If not specified, all providers will be used */
|
|
39
53
|
providers?: {
|
|
40
54
|
[EProvider.BLUEFIN7K]?: BluefinProviderOptions;
|
|
41
55
|
[EProvider.FLOWX]?: FlowxProviderOptions;
|
|
42
56
|
[EProvider.CETUS]?: CetusProviderOptions;
|
|
57
|
+
[EProvider.OKX]?: OkxProviderOptions;
|
|
58
|
+
[EProvider.BLUEFINX]?: BluefinXProviderOptions;
|
|
59
|
+
[EProvider.ASTRO]?: AstroProviderOptions;
|
|
43
60
|
};
|
|
44
61
|
/**Mainnet Json Rpc url, if not specified, the default mainnet url will be used */
|
|
45
62
|
fullnodeUrl?: string;
|
|
@@ -57,9 +74,11 @@ export interface MetaAgOptions {
|
|
|
57
74
|
tipBps?: number;
|
|
58
75
|
}
|
|
59
76
|
export interface MetaQuoteOptions {
|
|
60
|
-
|
|
61
|
-
|
|
77
|
+
coinTypeIn: string;
|
|
78
|
+
coinTypeOut: string;
|
|
62
79
|
amountIn: string;
|
|
80
|
+
/** Required for RFQ providers (ie: BluefinX) */
|
|
81
|
+
signer?: string;
|
|
63
82
|
/**
|
|
64
83
|
* Timeout for quote operation in milliseconds
|
|
65
84
|
* @default 2000ms
|
|
@@ -76,7 +95,22 @@ export interface MetaSimulationOptions {
|
|
|
76
95
|
/** If specify, defer the simulation that could reduce the time to display quote result, you must update the quote via the id on callback
|
|
77
96
|
* else await all quote and simulation before return
|
|
78
97
|
*/
|
|
79
|
-
onSimulated?: (payload:
|
|
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>;
|
|
80
114
|
}
|
|
81
115
|
export interface MetaSwapOptions {
|
|
82
116
|
/** Quote object from the quote operation */
|
|
@@ -100,6 +134,15 @@ export type MetaQuote = ({
|
|
|
100
134
|
} | {
|
|
101
135
|
provider: EProvider.FLOWX;
|
|
102
136
|
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;
|
|
103
146
|
}) & {
|
|
104
147
|
/** uuid to keep track the quote result, used to apply simulation result on quote on callback `onSimulated`*/
|
|
105
148
|
id: string;
|
|
@@ -118,10 +161,19 @@ export type MetaQuote = ({
|
|
|
118
161
|
/** Estimate gas consumption if the transaction is executed */
|
|
119
162
|
gasUsed?: GasCostSummary;
|
|
120
163
|
};
|
|
121
|
-
export
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
164
|
+
export interface QuoteProvider {
|
|
165
|
+
readonly kind: EProvider;
|
|
166
|
+
quote(_quoteOptions: MetaQuoteOptions): Promise<MetaQuote | null>;
|
|
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>;
|
|
125
175
|
}
|
|
176
|
+
export declare const isAggregatorProvider: (provider: QuoteProvider) => provider is AggregatorProvider;
|
|
177
|
+
export declare const isSwapAPIProvider: (provider: QuoteProvider) => provider is SwapAPIProvider;
|
|
126
178
|
export {};
|
|
127
179
|
//# 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,KAAK,EACV,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"metaAg.d.ts","sourceRoot":"","sources":["../../../../src/types/metaAg.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,Y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OAAO,CAAC,MAAM,CAAC,CAAC;CACzD;AAED,MAAM,WAAW,kBAAmB,SAAQ,aAAa;IACvD,QAAQ,CAAC,IAAI,EACT,SAAS,CAAC,SAAS,GACnB,SAAS,CAAC,KAAK,GACf,SAAS,CAAC,KAAK,GACf,SAAS,CAAC,KAAK,CAAC;IACpB,IAAI,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;CACpE;AAED,eAAO,MAAM,oBAAoB,GAC/B,UAAU,aAAa,KACtB,QAAQ,IAAI,kBAIoB,CAAC;AAEpC,eAAO,MAAM,iBAAiB,GAC5B,UAAU,aAAa,KACtB,QAAQ,IAAI,eAC0D,CAAC"}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OKX DEX Swap API Types
|
|
3
|
+
* Documentation: https://web3.okx.com/vi/build/docs/waas/dex-swap
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Gas level options for swap transactions
|
|
7
|
+
*/
|
|
8
|
+
export type GasLevel = "average" | "fast" | "slow";
|
|
9
|
+
/**
|
|
10
|
+
* Swap API Request Parameters
|
|
11
|
+
*/
|
|
12
|
+
export interface OkxSwapRequest {
|
|
13
|
+
/** Chain ID (e.g., 1 for Ethereum) */
|
|
14
|
+
chainId: string;
|
|
15
|
+
/** The input amount of a token to be sold (set in minimal divisible units) */
|
|
16
|
+
amount: string;
|
|
17
|
+
/** The contract address of a token you want to send (e.g., 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee for native token) */
|
|
18
|
+
fromTokenAddress: string;
|
|
19
|
+
/** The contract address of a token you want to receive */
|
|
20
|
+
toTokenAddress: string;
|
|
21
|
+
/** Slippage limit (0-1 for EVM, 0-less than 1 for Solana) */
|
|
22
|
+
slippage: string;
|
|
23
|
+
/** User's wallet address */
|
|
24
|
+
userWalletAddress: string;
|
|
25
|
+
/** Recipient address of a purchased token (if not set, userWalletAddress will receive the token) */
|
|
26
|
+
swapReceiverAddress?: string;
|
|
27
|
+
/** The percentage of fromTokenAmount or toTokenAmount sent to referrer (0-3, max 2 decimal points) */
|
|
28
|
+
feePercent?: string;
|
|
29
|
+
/** Wallet address to receive commission fee from fromToken */
|
|
30
|
+
fromTokenReferrerWalletAddress?: string;
|
|
31
|
+
/** Wallet address to receive commission fee from toToken */
|
|
32
|
+
toTokenReferrerWalletAddress?: string;
|
|
33
|
+
/** When true, positive slippage revenue sent to referrer's address (default: false) */
|
|
34
|
+
enablePositiveSlippage?: boolean;
|
|
35
|
+
/** The gas (in wei) for the swap transaction */
|
|
36
|
+
gaslimit?: string;
|
|
37
|
+
/** Target gas price level (defaults to "average") */
|
|
38
|
+
gasLevel?: GasLevel;
|
|
39
|
+
/** DexId of liquidity pool for limited quotes, multiple separated by comma (e.g., "1,50,180") */
|
|
40
|
+
dexIds?: string;
|
|
41
|
+
/** When enabled, restricts routing to single liquidity pool (Solana only, default: false) */
|
|
42
|
+
directRoute?: boolean;
|
|
43
|
+
/** Percentage (0-1.0) of price impact allowed (default: 0.9) */
|
|
44
|
+
priceImpactProtectionPercentage?: string;
|
|
45
|
+
/** Custom parameters encoded as 128-character 64-bytes hexadecimal string (must start with "0x") */
|
|
46
|
+
callDataMemo?: string;
|
|
47
|
+
/** Used for Solana transactions, similar to gasPrice on Ethereum */
|
|
48
|
+
computeUnitPrice?: string;
|
|
49
|
+
/** Used for Solana transactions, similar to gasLimit on Ethereum */
|
|
50
|
+
computeUnitLimit?: string;
|
|
51
|
+
/** When true, API calculates auto slippage recommendations (default: false) */
|
|
52
|
+
autoSlippage?: boolean;
|
|
53
|
+
/** Maximum auto slippage when autoSlippage is true */
|
|
54
|
+
maxAutoSlippage?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Token information
|
|
58
|
+
*/
|
|
59
|
+
export interface OkxTokenInfo {
|
|
60
|
+
/** Token contract address */
|
|
61
|
+
tokenContractAddress: string;
|
|
62
|
+
/** Token symbol (e.g., "USDC") */
|
|
63
|
+
tokenSymbol: string;
|
|
64
|
+
/** Token unit price in USD (may be null for special cases) */
|
|
65
|
+
tokenUnitPrice: string | null;
|
|
66
|
+
/** Decimal number defining smallest unit */
|
|
67
|
+
decimal: string;
|
|
68
|
+
/** Whether the token is a honeypot token */
|
|
69
|
+
isHoneyPot: boolean;
|
|
70
|
+
/** Token tax rate (0-1, where 0.01 = 1%) */
|
|
71
|
+
taxRate: string;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* DEX Protocol information
|
|
75
|
+
*/
|
|
76
|
+
export interface OkxDexProtocol {
|
|
77
|
+
/** Name of the liquidity protocol (e.g., "Uniswap V3") */
|
|
78
|
+
dexName: string;
|
|
79
|
+
/** Percentage of assets handled by the protocol */
|
|
80
|
+
percent: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Sub-router information
|
|
84
|
+
*/
|
|
85
|
+
export interface OkxSubRouter {
|
|
86
|
+
/** Liquidity protocols used on the path */
|
|
87
|
+
dexProtocol: OkxDexProtocol[];
|
|
88
|
+
/** Information of token to be sold */
|
|
89
|
+
fromToken: OkxTokenInfo;
|
|
90
|
+
/** Information of token to be bought */
|
|
91
|
+
toToken: OkxTokenInfo;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Main router information
|
|
95
|
+
*/
|
|
96
|
+
export interface OkxRouter {
|
|
97
|
+
/** One of the main paths for the token swap */
|
|
98
|
+
router: string;
|
|
99
|
+
/** Percentage of assets handled by the main path */
|
|
100
|
+
routerPercent: string;
|
|
101
|
+
/** Quote path sub data set */
|
|
102
|
+
subRouterList: OkxSubRouter[];
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Quote comparison information
|
|
106
|
+
*/
|
|
107
|
+
export interface OkxQuoteCompare {
|
|
108
|
+
/** DEX name of the quote route */
|
|
109
|
+
dexName: string;
|
|
110
|
+
/** DEX logo of the quote route */
|
|
111
|
+
dexLogo: string;
|
|
112
|
+
/** Estimated network fee (USD) of the quote route */
|
|
113
|
+
tradeFee: string;
|
|
114
|
+
/** Received amount of the quote route */
|
|
115
|
+
amountOut: string;
|
|
116
|
+
/** Price impact percentage */
|
|
117
|
+
priceImpactPercentage: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Transaction data model
|
|
121
|
+
*/
|
|
122
|
+
export interface OkxTransactionData {
|
|
123
|
+
/** Additional signing data (if required) */
|
|
124
|
+
signatureData?: string[];
|
|
125
|
+
/** User's wallet address */
|
|
126
|
+
from: string;
|
|
127
|
+
/** Estimated amount of the gas limit */
|
|
128
|
+
gas: string;
|
|
129
|
+
/** Gas price in wei */
|
|
130
|
+
gasPrice?: string;
|
|
131
|
+
/** EIP-1559: Recommended priority cost of gas per unit */
|
|
132
|
+
maxPriorityFeePerGas?: string;
|
|
133
|
+
/** The contract address of OKX DEX router */
|
|
134
|
+
to: string;
|
|
135
|
+
/** The amount of native tokens (in wei) to be sent to the contract */
|
|
136
|
+
value: string;
|
|
137
|
+
/** Minimum amount of token to buy when price reaches slippage limit */
|
|
138
|
+
minReceiveAmount: string;
|
|
139
|
+
/** Call data */
|
|
140
|
+
data: string;
|
|
141
|
+
/** Current transaction slippage value */
|
|
142
|
+
slippage: string;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Router result data
|
|
146
|
+
*/
|
|
147
|
+
export interface OkxRouterResult {
|
|
148
|
+
/** Chain ID */
|
|
149
|
+
chainId: string;
|
|
150
|
+
/** The input amount of a token to be sold */
|
|
151
|
+
fromTokenAmount: string;
|
|
152
|
+
/** The resulting amount of a token to be bought */
|
|
153
|
+
toTokenAmount: string;
|
|
154
|
+
/** Estimated network fee (USD) of the quote route */
|
|
155
|
+
tradeFee: string;
|
|
156
|
+
/** Estimated gas consumption in smallest units (e.g., wei) */
|
|
157
|
+
estimateGasFee: string;
|
|
158
|
+
/** Quote path data set */
|
|
159
|
+
dexRouterList: OkxRouter[];
|
|
160
|
+
/** Information of token to be sold */
|
|
161
|
+
fromToken: OkxTokenInfo;
|
|
162
|
+
/** Information of token to be bought */
|
|
163
|
+
toToken: OkxTokenInfo;
|
|
164
|
+
/** Price impact percentage */
|
|
165
|
+
priceImpactPercentage?: string;
|
|
166
|
+
/** Comparison of quote routes */
|
|
167
|
+
quoteCompareList?: OkxQuoteCompare[];
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Swap API Response Data
|
|
171
|
+
*/
|
|
172
|
+
export interface OkxSwapResponseData {
|
|
173
|
+
/** Quote path data */
|
|
174
|
+
routerResult: OkxRouterResult;
|
|
175
|
+
/** Contract data model */
|
|
176
|
+
tx: OkxTransactionData;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* OKX API Standard Response Wrapper
|
|
180
|
+
*/
|
|
181
|
+
export interface OkxApiResponse<T> {
|
|
182
|
+
/** Response code ("0" indicates success) */
|
|
183
|
+
code: string;
|
|
184
|
+
/** Response data array */
|
|
185
|
+
data: T[];
|
|
186
|
+
/** Response message */
|
|
187
|
+
msg: string;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Complete Swap API Response
|
|
191
|
+
*/
|
|
192
|
+
export type OkxSwapResponse = OkxApiResponse<OkxSwapResponseData>;
|
|
193
|
+
//# sourceMappingURL=okx.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"okx.d.ts","sourceRoot":"","sources":["../../../../src/types/okx.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,2HAA2H;IAC3H,gBAAgB,EAAE,MAAM,CAAC;IACzB,0DAA0D;IAC1D,cAAc,E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AE,MAAM,CAAC;IACb,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,eAAe;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,eAAe,EAAE,MAAM,CAAC;IACxB,mDAAmD;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,qDAAqD;IACrD,QAAQ,EAAE,MAAM,CAAC;IACjB,8DAA8D;IAC9D,cAAc,EAAE,MAAM,CAAC;IACvB,0BAA0B;IAC1B,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,sCAAsC;IACtC,SAAS,EAAE,YAAY,CAAC;IACxB,wCAAwC;IACxC,OAAO,EAAE,YAAY,CAAC;IACtB,8BAA8B;IAC9B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,iCAAiC;IACjC,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,sBAAsB;IACtB,YAAY,EAAE,eAAe,CAAC;IAC9B,0BAA0B;IAC1B,EAAE,EAAE,kBAAkB,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,0BAA0B;IAC1B,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,cAAc,CAAC,mBAAmB,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function assert(condition:
|
|
1
|
+
export declare function assert(condition: any, 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,GAAG,EACd,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,OAAO,CAAC,SAAS,CAInB"}
|
package/lib/esm/config/index.js
CHANGED
|
@@ -3,6 +3,7 @@ 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 = "";
|
|
6
7
|
let apiKey = "";
|
|
7
8
|
let bluefinXApiKey = "";
|
|
8
9
|
let suiClient = new SuiClient({
|
|
@@ -10,6 +11,12 @@ let suiClient = new SuiClient({
|
|
|
10
11
|
});
|
|
11
12
|
let pythClient = new SuiPythClient(suiClient, PYTH_STATE_ID, WORMHOLE_STATE_ID);
|
|
12
13
|
let pythConnection = new SuiPriceServiceConnection(HERMES_API);
|
|
14
|
+
function setApi(url) {
|
|
15
|
+
api = url;
|
|
16
|
+
}
|
|
17
|
+
function getApi() {
|
|
18
|
+
return api;
|
|
19
|
+
}
|
|
13
20
|
function setApiKey(key) {
|
|
14
21
|
apiKey = key;
|
|
15
22
|
}
|
|
@@ -41,6 +48,8 @@ function getPythConnection() {
|
|
|
41
48
|
return pythConnection;
|
|
42
49
|
}
|
|
43
50
|
const Config = {
|
|
51
|
+
setApi,
|
|
52
|
+
getApi,
|
|
44
53
|
setApiKey,
|
|
45
54
|
getApiKey,
|
|
46
55
|
setBluefinXApiKey,
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { coinWithBalance, Transaction, } from "@mysten/sui/transactions";
|
|
2
|
+
import { _7K_META_CONFIG, _7K_META_PACKAGE_ID, _7K_META_PUBLISHED_AT, _7K_META_VAULT, } from "../../constants/_7k";
|
|
3
|
+
import { getExpectedReturn } from "../swap/buildTx";
|
|
4
|
+
const DEFAULT_GAS_USED = {
|
|
5
|
+
computationCost: "0",
|
|
6
|
+
nonRefundableStorageFee: "0",
|
|
7
|
+
storageCost: "0",
|
|
8
|
+
storageRebate: "0",
|
|
9
|
+
};
|
|
10
|
+
export const simulateBluefinX = (quote) => {
|
|
11
|
+
return {
|
|
12
|
+
id: quote.id,
|
|
13
|
+
simulatedAmountOut: quote.amountOut,
|
|
14
|
+
gasUsed: DEFAULT_GAS_USED,
|
|
15
|
+
provider: quote.provider,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const simulateSwapTx = async (tx, inspector, simulation) => {
|
|
19
|
+
const res = await timeout(() => inspector.devInspectTransactionBlock({
|
|
20
|
+
sender: simulation.sender,
|
|
21
|
+
transactionBlock: tx,
|
|
22
|
+
}), simulation.timeout ?? 2000);
|
|
23
|
+
if (res.effects.status.status === "failure") {
|
|
24
|
+
throw new Error(res.error ?? "Simulation failed");
|
|
25
|
+
}
|
|
26
|
+
const amountOut = extractAmountOutWrapper(res.events);
|
|
27
|
+
return {
|
|
28
|
+
simulatedAmountOut: amountOut,
|
|
29
|
+
gasUsed: res.effects.gasUsed,
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export const simulateAggregator = async (provider, quote, simulation, inspector, options) => {
|
|
33
|
+
const tx = new Transaction();
|
|
34
|
+
const coinOut = await provider.swap({
|
|
35
|
+
quote,
|
|
36
|
+
coinIn: coinWithBalance({
|
|
37
|
+
balance: BigInt(quote.amountIn),
|
|
38
|
+
type: quote.coinTypeIn,
|
|
39
|
+
useGasCoin: false,
|
|
40
|
+
}),
|
|
41
|
+
signer: simulation.sender,
|
|
42
|
+
tx,
|
|
43
|
+
});
|
|
44
|
+
tx.add(metaSettle(quote, coinOut, 10000, options.tipBps, options.partner, options.partnerCommissionBps));
|
|
45
|
+
tx.transferObjects([coinOut], simulation.sender);
|
|
46
|
+
const res = await simulateSwapTx(tx, inspector, simulation);
|
|
47
|
+
return {
|
|
48
|
+
id: quote.id,
|
|
49
|
+
provider: provider.kind,
|
|
50
|
+
...res,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner
|
|
55
|
+
* @param quote Meta Aggregator Quote
|
|
56
|
+
* @param coinOut Coin Out Object
|
|
57
|
+
* @param slippageBps Slippage Bps
|
|
58
|
+
* @param tipBps Tip Bps default = 0
|
|
59
|
+
* @param partner address of partner for analytic default is zero address
|
|
60
|
+
*/
|
|
61
|
+
export const metaSettle = (quote, coinOut, slippageBps = 100, tipBps = 0, partner, commissionBps = 0) => {
|
|
62
|
+
return (tx) => {
|
|
63
|
+
const { minAmount, expectedAmount } = getExpectedReturn(quote.rawAmountOut, slippageBps, commissionBps, tipBps);
|
|
64
|
+
if (tipBps > 0) {
|
|
65
|
+
tx.moveCall({
|
|
66
|
+
target: `${_7K_META_PUBLISHED_AT}::vault::collect_tip`,
|
|
67
|
+
typeArguments: [quote.coinTypeOut],
|
|
68
|
+
arguments: [
|
|
69
|
+
tx.object(_7K_META_VAULT),
|
|
70
|
+
tx.object(_7K_META_CONFIG),
|
|
71
|
+
coinOut,
|
|
72
|
+
tx.pure.u64(tipBps),
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
tx.moveCall({
|
|
77
|
+
target: `${_7K_META_PUBLISHED_AT}::settle::settle`,
|
|
78
|
+
typeArguments: [quote.coinTypeIn, quote.coinTypeOut],
|
|
79
|
+
arguments: [
|
|
80
|
+
tx.object(_7K_META_CONFIG),
|
|
81
|
+
tx.object(_7K_META_VAULT),
|
|
82
|
+
tx.pure.u64(quote.amountIn),
|
|
83
|
+
coinOut,
|
|
84
|
+
tx.pure.u64(minAmount),
|
|
85
|
+
tx.pure.u64(expectedAmount),
|
|
86
|
+
tx.pure.option("address", partner),
|
|
87
|
+
tx.pure.u64(commissionBps),
|
|
88
|
+
tx.pure.u64(0), // ps
|
|
89
|
+
],
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const extractAmountOutWrapper = (events) => {
|
|
94
|
+
const swapEvent = events
|
|
95
|
+
.filter((event) => event.type === `${_7K_META_PACKAGE_ID}::settle::Swap`)
|
|
96
|
+
?.pop();
|
|
97
|
+
return swapEvent?.parsedJson?.amount_out;
|
|
98
|
+
};
|
|
99
|
+
export const timeout = async (fn, timeout, msg) => {
|
|
100
|
+
if (timeout <= 0)
|
|
101
|
+
return fn();
|
|
102
|
+
return new Promise((resolve, reject) => {
|
|
103
|
+
const timer = setTimeout(() => reject(new Error(`Timeout ${msg ?? "operation"}`)), timeout);
|
|
104
|
+
fn()
|
|
105
|
+
.then(resolve)
|
|
106
|
+
.catch(reject)
|
|
107
|
+
.finally(() => clearTimeout(timer));
|
|
108
|
+
});
|
|
109
|
+
};
|