@7kprotocol/sdk-ts 3.5.2-beta.2 → 3.5.2-beta.4
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/metaAg/common.js +3 -2
- package/lib/cjs/features/metaAg/error.js +35 -0
- package/lib/cjs/features/metaAg/index.js +10 -7
- package/lib/cjs/features/metaAg/providers/astro.js +2 -2
- package/lib/cjs/features/metaAg/providers/bluefin7k.js +3 -8
- package/lib/cjs/features/metaAg/providers/bluefin7kLegacy.js +2 -2
- package/lib/cjs/features/metaAg/providers/bluefinx.js +5 -5
- package/lib/cjs/features/metaAg/providers/cetus.js +3 -3
- package/lib/cjs/features/metaAg/providers/flowx.js +2 -2
- package/lib/cjs/features/metaAg/providers/okx.js +12 -11
- package/lib/cjs/types/features/metaAg/common.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/error.d.ts +60 -0
- package/lib/cjs/types/features/metaAg/error.d.ts.map +1 -0
- package/lib/cjs/types/features/metaAg/index.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/astro.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/bluefin7k.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/bluefin7kLegacy.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/bluefinx.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/cetus.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/flowx.d.ts.map +1 -1
- package/lib/cjs/types/features/metaAg/providers/okx.d.ts.map +1 -1
- package/lib/cjs/types/okx.js +1 -1
- package/lib/cjs/types/types/okx.d.ts +61 -48
- package/lib/cjs/types/types/okx.d.ts.map +1 -1
- package/lib/cjs/types/utils/sui.d.ts +1 -0
- package/lib/cjs/types/utils/sui.d.ts.map +1 -1
- package/lib/cjs/utils/sui.js +17 -1
- package/lib/esm/features/metaAg/common.js +3 -2
- package/lib/esm/features/metaAg/error.js +33 -0
- package/lib/esm/features/metaAg/index.js +10 -7
- package/lib/esm/features/metaAg/providers/astro.js +2 -2
- package/lib/esm/features/metaAg/providers/bluefin7k.js +4 -9
- package/lib/esm/features/metaAg/providers/bluefin7kLegacy.js +2 -2
- package/lib/esm/features/metaAg/providers/bluefinx.js +5 -5
- package/lib/esm/features/metaAg/providers/cetus.js +3 -3
- package/lib/esm/features/metaAg/providers/flowx.js +2 -2
- package/lib/esm/features/metaAg/providers/okx.js +12 -11
- package/lib/esm/types/features/metaAg/common.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/error.d.ts +60 -0
- package/lib/esm/types/features/metaAg/error.d.ts.map +1 -0
- package/lib/esm/types/features/metaAg/index.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/astro.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/bluefin7k.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/bluefin7kLegacy.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/bluefinx.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/cetus.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/flowx.d.ts.map +1 -1
- package/lib/esm/types/features/metaAg/providers/okx.d.ts.map +1 -1
- package/lib/esm/types/okx.js +1 -1
- package/lib/esm/types/types/okx.d.ts +61 -48
- package/lib/esm/types/types/okx.d.ts.map +1 -1
- package/lib/esm/types/utils/sui.d.ts +1 -0
- package/lib/esm/types/utils/sui.d.ts.map +1 -1
- package/lib/esm/utils/sui.js +16 -1
- package/package.json +1 -1
- package/lib/cjs/types/utils/condition.d.ts +0 -2
- package/lib/cjs/types/utils/condition.d.ts.map +0 -1
- package/lib/cjs/utils/condition.js +0 -8
- package/lib/esm/types/utils/condition.d.ts +0 -2
- package/lib/esm/types/utils/condition.d.ts.map +0 -1
- package/lib/esm/utils/condition.js +0 -5
|
@@ -1,57 +1,57 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* OKX DEX Swap API Types
|
|
3
|
-
* Documentation: https://web3.okx.com/vi/build/docs/
|
|
3
|
+
* Documentation: https://web3.okx.com/vi/build/dev-docs/wallet-api/dex-swap
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Gas level options for swap transactions
|
|
7
7
|
*/
|
|
8
8
|
export type GasLevel = "average" | "fast" | "slow";
|
|
9
9
|
/**
|
|
10
|
-
* Swap
|
|
10
|
+
* Swap mode options
|
|
11
|
+
*/
|
|
12
|
+
export type SwapMode = "exactIn" | "exactOut";
|
|
13
|
+
/**
|
|
14
|
+
* Swap API Request Parameters (v6)
|
|
11
15
|
*/
|
|
12
16
|
export interface OkxSwapRequest {
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
/** The input amount of a token to be sold (set in minimal divisible units) */
|
|
17
|
+
/** Unique identifier for the chain */
|
|
18
|
+
chainIndex?: string;
|
|
19
|
+
/** The input amount of a token to be sold (set in minimal divisible units, e.g., 1.00 USDT set as 1000000) */
|
|
16
20
|
amount: string;
|
|
21
|
+
/** Swap mode: "exactIn" or "exactOut" (default: "exactIn"). exactOut only supports Ethereum, Base, BSC, Arbitrum chains and Uni v3 protocols */
|
|
22
|
+
swapMode?: SwapMode;
|
|
17
23
|
/** The contract address of a token you want to send (e.g., 0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee for native token) */
|
|
18
24
|
fromTokenAddress: string;
|
|
19
25
|
/** The contract address of a token you want to receive */
|
|
20
26
|
toTokenAddress: string;
|
|
21
|
-
/** Slippage limit
|
|
22
|
-
|
|
27
|
+
/** Slippage limit. For EVM: 0-100. For Solana: 0-less than 100 (e.g., 0.5 means 0.5%) */
|
|
28
|
+
slippagePercent: string;
|
|
23
29
|
/** User's wallet address */
|
|
24
30
|
userWalletAddress: string;
|
|
25
31
|
/** Recipient address of a purchased token (if not set, userWalletAddress will receive the token) */
|
|
26
32
|
swapReceiverAddress?: string;
|
|
27
|
-
/** The percentage of fromTokenAmount
|
|
33
|
+
/** The percentage of fromTokenAmount sent to referrer. Min > 0, max 10 for Solana, 3 for all other chains. Maximum of nine decimal places */
|
|
28
34
|
feePercent?: string;
|
|
29
|
-
/** Wallet address to receive commission fee
|
|
35
|
+
/** Wallet address to receive commission fee for fromToken. Must set feePercent together. Can only choose either fromToken or toToken commission per transaction */
|
|
30
36
|
fromTokenReferrerWalletAddress?: string;
|
|
31
|
-
/** Wallet address to receive commission fee
|
|
37
|
+
/** Wallet address to receive commission fee for toToken. Must set feePercent together. Can only choose either fromToken or toToken commission per transaction */
|
|
32
38
|
toTokenReferrerWalletAddress?: string;
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
|
|
37
|
-
/**
|
|
39
|
+
/** Positive slippage percentage (0-10, max 1 decimal point). Solana only, whitelist/enterprise clients only */
|
|
40
|
+
positiveSlippagePercent?: string;
|
|
41
|
+
/** Wallet address that receives positive slippage. Must set positiveSlippagePercent together. Solana only, whitelist/enterprise clients only */
|
|
42
|
+
positiveSlippageFeeAddress?: string;
|
|
43
|
+
/** The gas (in wei) for the swap transaction. EVM only. If too low, an error will be returned */
|
|
44
|
+
gasLimit?: string;
|
|
45
|
+
/** Target gas price level (defaults to "average"). EVM only */
|
|
38
46
|
gasLevel?: GasLevel;
|
|
39
|
-
/**
|
|
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 */
|
|
47
|
+
/** Used for Solana transactions, similar to gasPrice on Ethereum. Determines transaction priority */
|
|
48
48
|
computeUnitPrice?: string;
|
|
49
|
-
/** Used for Solana transactions, similar to gasLimit on Ethereum */
|
|
49
|
+
/** Used for Solana transactions, similar to gasLimit on Ethereum. If tips is not 0, computeUnitPrice should be set to 0 */
|
|
50
50
|
computeUnitLimit?: string;
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
|
|
51
|
+
/** Jito tips in SOL. Maximum is "2", minimum is "0.0000000001". Used for MEV protection. Solana only */
|
|
52
|
+
tips?: string;
|
|
53
|
+
/** DexId of liquidity pool for limited quotes, multiple separated by comma (e.g., "1,50,180") */
|
|
54
|
+
dexIds?: string;
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Token information
|
|
@@ -83,15 +83,20 @@ export interface OkxDexProtocol {
|
|
|
83
83
|
* Sub-router information
|
|
84
84
|
*/
|
|
85
85
|
export interface OkxSubRouter {
|
|
86
|
-
/** Liquidity
|
|
87
|
-
dexProtocol: OkxDexProtocol
|
|
86
|
+
/** Liquidity protocol used on the path */
|
|
87
|
+
dexProtocol: OkxDexProtocol;
|
|
88
|
+
/** Index of the from token */
|
|
89
|
+
fromTokenIndex: string;
|
|
90
|
+
/** Index of the to token */
|
|
91
|
+
toTokenIndex: string;
|
|
88
92
|
/** Information of token to be sold */
|
|
89
93
|
fromToken: OkxTokenInfo;
|
|
90
94
|
/** Information of token to be bought */
|
|
91
95
|
toToken: OkxTokenInfo;
|
|
92
96
|
}
|
|
93
97
|
/**
|
|
94
|
-
* Main router information
|
|
98
|
+
* Main router information (deprecated in v6, kept for backward compatibility)
|
|
99
|
+
* In v6, dexRouterList is an array of OkxSubRouter directly
|
|
95
100
|
*/
|
|
96
101
|
export interface OkxRouter {
|
|
97
102
|
/** One of the main paths for the token swap */
|
|
@@ -120,11 +125,11 @@ export interface OkxQuoteCompare {
|
|
|
120
125
|
* Transaction data model
|
|
121
126
|
*/
|
|
122
127
|
export interface OkxTransactionData {
|
|
123
|
-
/** Additional signing data (if required) */
|
|
128
|
+
/** Additional signing data (if required). When tips is specified, represents calldata of jito tips transfer */
|
|
124
129
|
signatureData?: string[];
|
|
125
130
|
/** User's wallet address */
|
|
126
131
|
from: string;
|
|
127
|
-
/** Estimated amount of the gas limit */
|
|
132
|
+
/** Estimated amount of the gas limit (increase by 50% for accurate data) */
|
|
128
133
|
gas: string;
|
|
129
134
|
/** Gas price in wei */
|
|
130
135
|
gasPrice?: string;
|
|
@@ -134,35 +139,43 @@ export interface OkxTransactionData {
|
|
|
134
139
|
to: string;
|
|
135
140
|
/** The amount of native tokens (in wei) to be sent to the contract */
|
|
136
141
|
value: string;
|
|
137
|
-
/**
|
|
142
|
+
/** The maximum amount of a token to spend when price reaches upper limit of slippage (applies to exactOut mode) */
|
|
143
|
+
maxSpendAmount?: string;
|
|
144
|
+
/** The minimum amount of a token to buy when price reaches upper limit of slippage */
|
|
138
145
|
minReceiveAmount: string;
|
|
139
146
|
/** Call data */
|
|
140
147
|
data: string;
|
|
141
148
|
/** Current transaction slippage value */
|
|
142
|
-
|
|
149
|
+
slippagePercent: string;
|
|
143
150
|
}
|
|
144
151
|
/**
|
|
145
152
|
* Router result data
|
|
146
153
|
*/
|
|
147
154
|
export interface OkxRouterResult {
|
|
148
|
-
/**
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
|
|
154
|
-
/** Estimated network fee (USD) of the quote route */
|
|
155
|
-
tradeFee: string;
|
|
155
|
+
/** Unique identifier for the chain */
|
|
156
|
+
chainIndex: string;
|
|
157
|
+
/** Context slot (for Solana) */
|
|
158
|
+
contextSlot?: number;
|
|
159
|
+
/** Quote path data set - array of sub-routers */
|
|
160
|
+
dexRouterList: OkxSubRouter[];
|
|
156
161
|
/** Estimated gas consumption in smallest units (e.g., wei) */
|
|
157
162
|
estimateGasFee: string;
|
|
158
|
-
/** Quote path data set */
|
|
159
|
-
dexRouterList: OkxRouter[];
|
|
160
163
|
/** Information of token to be sold */
|
|
161
164
|
fromToken: OkxTokenInfo;
|
|
165
|
+
/** The input amount of a token to be sold */
|
|
166
|
+
fromTokenAmount: string;
|
|
167
|
+
/** Price impact percentage = (Received value – Paid value) / Paid value. Can be positive if received value exceeds paid value */
|
|
168
|
+
priceImpactPercent: string;
|
|
169
|
+
/** Router identifier */
|
|
170
|
+
router: string;
|
|
171
|
+
/** Swap mode: "exactIn" or "exactOut" */
|
|
172
|
+
swapMode: SwapMode;
|
|
162
173
|
/** Information of token to be bought */
|
|
163
174
|
toToken: OkxTokenInfo;
|
|
164
|
-
/**
|
|
165
|
-
|
|
175
|
+
/** The resulting amount of a token to be bought */
|
|
176
|
+
toTokenAmount: string;
|
|
177
|
+
/** Estimated network fee (USD) of the quote route */
|
|
178
|
+
tradeFee: string;
|
|
166
179
|
/** Comparison of quote routes */
|
|
167
180
|
quoteCompareList?: OkxQuoteCompare[];
|
|
168
181
|
}
|
|
@@ -1 +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,
|
|
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,MAAM,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,sCAAsC;IACtC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8GAA8G;IAC9G,MAAM,EAAE,MAAM,CAAC;IACf,gJAAgJ;IAChJ,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,2HAA2H;IAC3H,gBAAgB,EAAE,MAAM,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Argument): void;
|
|
54
54
|
transferOrDestroyZeroCoin(tx: Transaction, coinType: string, coin: TransactionArgument, address: string): void;
|
|
55
55
|
};
|
|
56
|
+
export declare const isSystemAddress: (address: string) => boolean;
|
|
56
57
|
export {};
|
|
57
58
|
//# sourceMappingURL=sui.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sui.d.ts","sourceRoot":"","sources":["../../../../src/utils/sui.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sui.d.ts","sourceRoot":"","sources":["../../../../src/utils/sui.ts"],"names":[],"mappings":"AACA,OAAO,EACL,UAAU,EAEV,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAc5E,KAAK,QAAQ,CAAC,CAAC,IAAI;IACjB,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF,KAAK,SAAS,GAAG;IACf,MAAM,CAAC,EAAE,GAAG,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAEF,KAAK,cAAc,GAAG,KAAK,GAAG,SAAS,CAAC;AAExC,eAAO,MAAM,QAAQ;uBAET,MAAM,GAAG,mBAAmB,OAC/B,WAAW,GACf,mBAAmB;4BAMP,KAAK,CAAC,MAAM,GAAG,mBAAmB,CAAC,OAC3C,WAAW,GACf,mBAAmB,GAAG,SAAS;2BAsBtB,MAAM,cACJ,MAAM,GAAG,mBAAmB,OACnC,WAAW,GACf,mBAAmB;mCAYV,MAAM,SACT;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE,UACtC,MAAM,OACT,WAAW;;;;gCAoBgB,MAAM,iBAAiB,MAAM;qCAoCtD,UAAU,EAAE,YACT,MAAM,OACX,WAAW;uCAsBuB;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE;sCA8BhE,MAAM,SACP;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,EAAE;iCA6BvC,MAAM,SACN,sBAAsB,mBACb,cAAc,GAC7B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;4BAyBD,MAAM;oBAQd,WAAW,YAAY,MAAM;;;;iBAQhC,WAAW,YAAY,MAAM;;;;wBASpC,WAAW,YACL,MAAM,cACJ,mBAAmB;;;;wBAU3B,WAAW,YACL,MAAM,WACP,mBAAmB;;;;2BAUxB,WAAW,YACL,MAAM,WACP,mBAAmB;oBASd,WAAW,YAAY,MAAM,QAAQ,mBAAmB;kCASlE,WAAW,YACL,MAAM,QACV,mBAAmB,WAChB,MAAM;CAQlB,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,SAAS,MAAM,YAY9C,CAAC"}
|
package/lib/cjs/utils/sui.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SuiUtils = void 0;
|
|
3
|
+
exports.isSystemAddress = exports.SuiUtils = void 0;
|
|
4
|
+
const aggregator_sdk_1 = require("@cetusprotocol/aggregator-sdk");
|
|
4
5
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
5
6
|
const utils_1 = require("@mysten/sui/utils");
|
|
6
7
|
const config_1 = require("../config");
|
|
@@ -217,3 +218,18 @@ exports.SuiUtils = {
|
|
|
217
218
|
});
|
|
218
219
|
},
|
|
219
220
|
};
|
|
221
|
+
const isSystemAddress = (address) => {
|
|
222
|
+
const addr = (0, utils_1.normalizeSuiAddress)(address);
|
|
223
|
+
const addresses = [
|
|
224
|
+
utils_1.SUI_SYSTEM_ADDRESS,
|
|
225
|
+
utils_1.MOVE_STDLIB_ADDRESS,
|
|
226
|
+
utils_1.SUI_FRAMEWORK_ADDRESS,
|
|
227
|
+
utils_1.SUI_CLOCK_OBJECT_ID,
|
|
228
|
+
utils_1.SUI_RANDOM_OBJECT_ID,
|
|
229
|
+
aggregator_sdk_1.SUI_SYSTEM_STATE_OBJECT_ID,
|
|
230
|
+
"0x0",
|
|
231
|
+
].map((v) => (0, utils_1.normalizeSuiAddress)(v));
|
|
232
|
+
return addresses.includes(addr);
|
|
233
|
+
};
|
|
234
|
+
exports.isSystemAddress = isSystemAddress;
|
|
235
|
+
console.log((0, exports.isSystemAddress)("0x0"));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { coinWithBalance, Transaction, } from "@mysten/sui/transactions";
|
|
2
2
|
import { _7K_META_CONFIG, _7K_META_PACKAGE_ID, _7K_META_PUBLISHED_AT, _7K_META_VAULT, } from "../../constants/_7k";
|
|
3
3
|
import { getExpectedReturn } from "../swap/buildTx";
|
|
4
|
+
import { MetaAgError, MetaAgErrorCode } from "./error";
|
|
4
5
|
const DEFAULT_GAS_USED = {
|
|
5
6
|
computationCost: "0",
|
|
6
7
|
nonRefundableStorageFee: "0",
|
|
@@ -21,7 +22,7 @@ export const simulateSwapTx = async (tx, inspector, simulation) => {
|
|
|
21
22
|
transactionBlock: tx,
|
|
22
23
|
}), simulation.timeout ?? 2000);
|
|
23
24
|
if (res.effects.status.status === "failure") {
|
|
24
|
-
throw new
|
|
25
|
+
throw new MetaAgError(res.error ?? "Simulation failed", MetaAgErrorCode.SIMULATION_FAILED, { error: res.error });
|
|
25
26
|
}
|
|
26
27
|
const amountOut = extractAmountOutWrapper(res.events);
|
|
27
28
|
return {
|
|
@@ -100,7 +101,7 @@ export const timeout = async (fn, timeout, msg) => {
|
|
|
100
101
|
if (timeout <= 0)
|
|
101
102
|
return fn();
|
|
102
103
|
return new Promise((resolve, reject) => {
|
|
103
|
-
const timer = setTimeout(() => reject(new
|
|
104
|
+
const timer = setTimeout(() => reject(new MetaAgError(`Timeout ${msg ?? "operation"}`, MetaAgErrorCode.TIMEOUT, { timeout })), timeout);
|
|
104
105
|
fn()
|
|
105
106
|
.then(resolve)
|
|
106
107
|
.catch(reject)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export var MetaAgErrorCode;
|
|
2
|
+
(function (MetaAgErrorCode) {
|
|
3
|
+
MetaAgErrorCode[MetaAgErrorCode["UNKNOWN"] = 1000] = "UNKNOWN";
|
|
4
|
+
MetaAgErrorCode[MetaAgErrorCode["TIMEOUT"] = 1001] = "TIMEOUT";
|
|
5
|
+
MetaAgErrorCode[MetaAgErrorCode["PROVIDER_NOT_FOUND"] = 1002] = "PROVIDER_NOT_FOUND";
|
|
6
|
+
MetaAgErrorCode[MetaAgErrorCode["PROVIDER_NOT_SUPPORTED"] = 1003] = "PROVIDER_NOT_SUPPORTED";
|
|
7
|
+
MetaAgErrorCode[MetaAgErrorCode["INVALID_QUOTE"] = 1004] = "INVALID_QUOTE";
|
|
8
|
+
MetaAgErrorCode[MetaAgErrorCode["QUOTE_NOT_FOUND"] = 1005] = "QUOTE_NOT_FOUND";
|
|
9
|
+
MetaAgErrorCode[MetaAgErrorCode["INVALID_SIGNER_ADDRESS"] = 1006] = "INVALID_SIGNER_ADDRESS";
|
|
10
|
+
MetaAgErrorCode[MetaAgErrorCode["PROVIDER_NOT_SUPPORT_SWAP"] = 1007] = "PROVIDER_NOT_SUPPORT_SWAP";
|
|
11
|
+
MetaAgErrorCode[MetaAgErrorCode["SIMULATION_FAILED"] = 1008] = "SIMULATION_FAILED";
|
|
12
|
+
// OKX error
|
|
13
|
+
MetaAgErrorCode[MetaAgErrorCode["OKX_FINALIZE_COMMAND_NOT_FOUND"] = 1100] = "OKX_FINALIZE_COMMAND_NOT_FOUND";
|
|
14
|
+
// BluefinX error
|
|
15
|
+
MetaAgErrorCode[MetaAgErrorCode["BLUEFINX_TRANSACTION_NOT_FOUND"] = 1200] = "BLUEFINX_TRANSACTION_NOT_FOUND";
|
|
16
|
+
MetaAgErrorCode[MetaAgErrorCode["BLUEFINX_TRANSACTION_NOT_APPROVED"] = 1201] = "BLUEFINX_TRANSACTION_NOT_APPROVED";
|
|
17
|
+
MetaAgErrorCode[MetaAgErrorCode["BLUEFINX_TRANSACTION_DIGEST_NOT_FOUND"] = 1202] = "BLUEFINX_TRANSACTION_DIGEST_NOT_FOUND";
|
|
18
|
+
})(MetaAgErrorCode || (MetaAgErrorCode = {}));
|
|
19
|
+
export class MetaAgError extends Error {
|
|
20
|
+
code;
|
|
21
|
+
details;
|
|
22
|
+
constructor(message, code, details) {
|
|
23
|
+
super(message);
|
|
24
|
+
this.name = "MetaAgError";
|
|
25
|
+
this.code = code ?? MetaAgErrorCode.UNKNOWN;
|
|
26
|
+
this.details = details;
|
|
27
|
+
}
|
|
28
|
+
static assert(condition, message, code, details) {
|
|
29
|
+
if (!condition) {
|
|
30
|
+
throw new MetaAgError(message ?? "Assertion failed", code, details);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -3,10 +3,11 @@ import { coinWithBalance, Transaction, } from "@mysten/sui/transactions";
|
|
|
3
3
|
import { normalizeStructTag, toBase64 } from "@mysten/sui/utils";
|
|
4
4
|
import { SUI_ADDRESS_ZERO } from "../../constants/sui";
|
|
5
5
|
import { EProvider, isAggregatorProvider, isSwapAPIProvider, } from "../../types/metaAg";
|
|
6
|
-
import {
|
|
6
|
+
import { isSystemAddress } from "../../utils/sui";
|
|
7
7
|
import { SuiClientUtils } from "../../utils/SuiClientUtils";
|
|
8
8
|
import { getExpectedReturn } from "../swap/buildTx";
|
|
9
9
|
import { metaSettle, simulateAggregator, simulateBluefinX, timeout, } from "./common";
|
|
10
|
+
import { MetaAgError, MetaAgErrorCode } from "./error";
|
|
10
11
|
import { BluefinLegacyProvider } from "./providers/bluefin7kLegacy";
|
|
11
12
|
import { BluefinXProvider } from "./providers/bluefinx";
|
|
12
13
|
import { OkxProvider, simulateOKXSwap } from "./providers/okx";
|
|
@@ -43,7 +44,7 @@ export class MetaAg {
|
|
|
43
44
|
if (p)
|
|
44
45
|
return p;
|
|
45
46
|
const providerOptions = this.options.providers[provider];
|
|
46
|
-
assert(!!providerOptions, `Provider not found: ${provider}
|
|
47
|
+
MetaAgError.assert(!!providerOptions, `Provider not found: ${provider}`, MetaAgErrorCode.PROVIDER_NOT_FOUND, { provider });
|
|
47
48
|
switch (provider) {
|
|
48
49
|
case EProvider.BLUEFIN7K_LEGACY:
|
|
49
50
|
this.providers[EProvider.BLUEFIN7K_LEGACY] = new BluefinLegacyProvider(providerOptions, this.options, this.client);
|
|
@@ -71,7 +72,7 @@ export class MetaAg {
|
|
|
71
72
|
this.providers[EProvider.ASTRO] = new AstroProvider(providerOptions);
|
|
72
73
|
break;
|
|
73
74
|
default:
|
|
74
|
-
throw new
|
|
75
|
+
throw new MetaAgError(`Provider not supported: ${provider}`, MetaAgErrorCode.PROVIDER_NOT_SUPPORTED, { provider });
|
|
75
76
|
}
|
|
76
77
|
return this.providers[provider];
|
|
77
78
|
}
|
|
@@ -86,7 +87,7 @@ export class MetaAg {
|
|
|
86
87
|
case EProvider.OKX:
|
|
87
88
|
return simulateOKXSwap(quote, this.inspector, simulation, this.options);
|
|
88
89
|
default:
|
|
89
|
-
throw new
|
|
90
|
+
throw new MetaAgError(`Provider not supported: ${provider.kind}`, MetaAgErrorCode.PROVIDER_NOT_SUPPORTED, { provider: provider.kind });
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
catch (error) {
|
|
@@ -174,8 +175,9 @@ export class MetaAg {
|
|
|
174
175
|
*/
|
|
175
176
|
async swap(options, slippageBps) {
|
|
176
177
|
const provider = await this._getProvider(options.quote.provider);
|
|
177
|
-
assert(!!provider, `Provider not found: ${options.quote.provider}
|
|
178
|
-
assert(isAggregatorProvider(provider), `Provider does not support swap: ${provider.kind}
|
|
178
|
+
MetaAgError.assert(!!provider, `Provider not found: ${options.quote.provider}`, MetaAgErrorCode.PROVIDER_NOT_FOUND, { provider: options.quote.provider });
|
|
179
|
+
MetaAgError.assert(isAggregatorProvider(provider), `Provider does not support swap: ${provider.kind}, use fastSwap instead`, MetaAgErrorCode.PROVIDER_NOT_SUPPORT_SWAP, { provider: provider.kind });
|
|
180
|
+
MetaAgError.assert(!isSystemAddress(options.signer), "Invalid signer address", MetaAgErrorCode.INVALID_SIGNER_ADDRESS, { signer: options.signer });
|
|
179
181
|
const coinOut = await provider.swap(options);
|
|
180
182
|
options.tx.add(metaSettle(options.quote, coinOut, slippageBps ?? this.options.slippageBps ?? 100, this.options.tipBps, this.options.partner, this.options.partnerCommissionBps));
|
|
181
183
|
options.tx.setSenderIfNotSet(options.signer);
|
|
@@ -187,6 +189,7 @@ export class MetaAg {
|
|
|
187
189
|
* @returns - txDigest of the transaction
|
|
188
190
|
*/
|
|
189
191
|
async fastSwap(options, getTransactionBlockParams) {
|
|
192
|
+
MetaAgError.assert(!isSystemAddress(options.signer), "Invalid signer address", MetaAgErrorCode.INVALID_SIGNER_ADDRESS, { signer: options.signer });
|
|
190
193
|
const provider = await this._getProvider(options.quote.provider);
|
|
191
194
|
if (isAggregatorProvider(provider)) {
|
|
192
195
|
return this._fastSwap(options, getTransactionBlockParams);
|
|
@@ -198,7 +201,7 @@ export class MetaAg {
|
|
|
198
201
|
});
|
|
199
202
|
}
|
|
200
203
|
else {
|
|
201
|
-
throw new
|
|
204
|
+
throw new MetaAgError(`Provider not supported: ${provider.kind}`, MetaAgErrorCode.PROVIDER_NOT_SUPPORTED, { provider: provider.kind });
|
|
202
205
|
}
|
|
203
206
|
}
|
|
204
207
|
/**
|
|
@@ -2,7 +2,7 @@ import { buildSwapPTBFromQuote, getQuote, } from "@naviprotocol/astros-aggregato
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
|
|
4
4
|
import { EProvider, } from "../../../types/metaAg";
|
|
5
|
-
import {
|
|
5
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
6
6
|
export class AstroProvider {
|
|
7
7
|
options;
|
|
8
8
|
kind = EProvider.ASTRO;
|
|
@@ -33,7 +33,7 @@ export class AstroProvider {
|
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
async swap({ signer, quote, coinIn, tx }) {
|
|
36
|
-
assert(quote.provider === EProvider.ASTRO, "Invalid quote");
|
|
36
|
+
MetaAgError.assert(quote.provider === EProvider.ASTRO, "Invalid quote", MetaAgErrorCode.INVALID_QUOTE, { quote, expectedProvider: EProvider.ASTRO });
|
|
37
37
|
const coin = await buildSwapPTBFromQuote(signer, tx, 0, coinIn, quote.quote);
|
|
38
38
|
return coin;
|
|
39
39
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { buildTx, Config, getQuote, } from "@bluefin-exchange/bluefin7k-aggregator-sdk";
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
|
|
4
4
|
import { EProvider, } from "../../../types/metaAg";
|
|
5
|
-
import {
|
|
5
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
6
6
|
export class Bluefin7kProvider {
|
|
7
7
|
options;
|
|
8
8
|
metaOptions;
|
|
@@ -12,11 +12,6 @@ export class Bluefin7kProvider {
|
|
|
12
12
|
this.metaOptions = metaOptions;
|
|
13
13
|
if (options.apiKey)
|
|
14
14
|
Config.setApiKey(options.apiKey);
|
|
15
|
-
if (options.api &&
|
|
16
|
-
"setApi" in Config &&
|
|
17
|
-
typeof Config.setApi === "function") {
|
|
18
|
-
Config.setApi(options.api);
|
|
19
|
-
}
|
|
20
15
|
Config.setSuiClient(client);
|
|
21
16
|
}
|
|
22
17
|
async quote(quoteOptions) {
|
|
@@ -28,7 +23,7 @@ export class Bluefin7kProvider {
|
|
|
28
23
|
excludedPools: this.options.excludedPools,
|
|
29
24
|
targetPools: this.options.targetPools,
|
|
30
25
|
});
|
|
31
|
-
assert(!!quote, "No quote found");
|
|
26
|
+
MetaAgError.assert(!!quote, "No quote found", MetaAgErrorCode.QUOTE_NOT_FOUND, { provider: this.kind });
|
|
32
27
|
return {
|
|
33
28
|
id: v4(),
|
|
34
29
|
provider: EProvider.BLUEFIN7K,
|
|
@@ -41,7 +36,7 @@ export class Bluefin7kProvider {
|
|
|
41
36
|
};
|
|
42
37
|
}
|
|
43
38
|
async swap({ quote, signer, tx, coinIn }) {
|
|
44
|
-
assert(quote.provider === EProvider.BLUEFIN7K, "Invalid quote");
|
|
39
|
+
MetaAgError.assert(quote.provider === EProvider.BLUEFIN7K, "Invalid quote", MetaAgErrorCode.INVALID_QUOTE, { quote, expectedProvider: EProvider.BLUEFIN7K });
|
|
45
40
|
const { coinOut } = await buildTx({
|
|
46
41
|
quoteResponse: quote.quote,
|
|
47
42
|
accountAddress: signer,
|
|
@@ -3,9 +3,9 @@ import { v4 } from "uuid";
|
|
|
3
3
|
import { Config } from "../../../config";
|
|
4
4
|
import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
|
|
5
5
|
import { EProvider, } from "../../../types/metaAg";
|
|
6
|
-
import { assert } from "../../../utils/condition";
|
|
7
6
|
import { buildTxV2 } from "../../swap/buildTxV2";
|
|
8
7
|
import { getQuote } from "../../swap/getQuote";
|
|
8
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
9
9
|
const WORMHOLE_STATE_ID = "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c";
|
|
10
10
|
const PYTH_STATE_ID = "0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8";
|
|
11
11
|
export class BluefinLegacyProvider {
|
|
@@ -47,7 +47,7 @@ export class BluefinLegacyProvider {
|
|
|
47
47
|
};
|
|
48
48
|
}
|
|
49
49
|
async swap({ quote, signer, tx, coinIn }) {
|
|
50
|
-
assert(quote.provider === EProvider.BLUEFIN7K_LEGACY, "Invalid quote");
|
|
50
|
+
MetaAgError.assert(quote.provider === EProvider.BLUEFIN7K_LEGACY, "Invalid quote", MetaAgErrorCode.INVALID_QUOTE, { quote, expectedProvider: EProvider.BLUEFIN7K_LEGACY });
|
|
51
51
|
const { coinOut } = await buildTxV2({
|
|
52
52
|
quoteResponse: quote.quote,
|
|
53
53
|
accountAddress: signer,
|
|
@@ -6,10 +6,10 @@ import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
|
|
|
6
6
|
import { executeBluefinTx } from "../../../libs/protocols/bluefinx/client";
|
|
7
7
|
import { BluefinXTx } from "../../../types/aggregator";
|
|
8
8
|
import { EProvider, } from "../../../types/metaAg";
|
|
9
|
-
import { assert } from "../../../utils/condition";
|
|
10
9
|
import { buildTxV2Int } from "../../swap/buildTxV2";
|
|
11
10
|
import { getQuote } from "../../swap/getQuote";
|
|
12
11
|
import { metaSettle } from "../common";
|
|
12
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
13
13
|
const SUPPORT_COINS = [
|
|
14
14
|
"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
|
|
15
15
|
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
@@ -52,7 +52,7 @@ export class BluefinXProvider {
|
|
|
52
52
|
SUPPORT_COINS.includes(options.coinTypeOut));
|
|
53
53
|
}
|
|
54
54
|
async fastSwap(options) {
|
|
55
|
-
assert(options.quote.provider === this.kind, "Invalid BluefinX quote");
|
|
55
|
+
MetaAgError.assert(options.quote.provider === this.kind, "Invalid BluefinX quote", MetaAgErrorCode.INVALID_QUOTE, { quote: options.quote, expectedProvider: this.kind });
|
|
56
56
|
const quote = options.quote.quote;
|
|
57
57
|
const tx = new Transaction();
|
|
58
58
|
const { tx: bluefinTx } = await buildTxV2Int({
|
|
@@ -74,11 +74,11 @@ export class BluefinXProvider {
|
|
|
74
74
|
tx.transferObjects([coinOut], options.signer);
|
|
75
75
|
}
|
|
76
76
|
});
|
|
77
|
-
assert(bluefinTx instanceof BluefinXTx, "BluefinX transaction not found");
|
|
77
|
+
MetaAgError.assert(bluefinTx instanceof BluefinXTx, "BluefinX transaction not found", MetaAgErrorCode.BLUEFINX_TRANSACTION_NOT_FOUND, {});
|
|
78
78
|
const { signature } = await options.signTransaction(bluefinTx.txBytes);
|
|
79
79
|
const res = await executeBluefinTx(bluefinTx, signature);
|
|
80
|
-
assert(res.approved, "BluefinX transaction not approved");
|
|
81
|
-
assert(res.txDigest, "BluefinX transaction digest not found");
|
|
80
|
+
MetaAgError.assert(res.approved, "BluefinX transaction not approved", MetaAgErrorCode.BLUEFINX_TRANSACTION_NOT_APPROVED, {});
|
|
81
|
+
MetaAgError.assert(res.txDigest, "BluefinX transaction digest not found", MetaAgErrorCode.BLUEFINX_TRANSACTION_DIGEST_NOT_FOUND, {});
|
|
82
82
|
return res.txDigest;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -2,7 +2,7 @@ import { AggregatorClient, Env } from "@cetusprotocol/aggregator-sdk";
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
|
|
4
4
|
import { EProvider, } from "../../../types/metaAg";
|
|
5
|
-
import {
|
|
5
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
6
6
|
export class CetusProvider {
|
|
7
7
|
options;
|
|
8
8
|
kind = EProvider.CETUS;
|
|
@@ -32,7 +32,7 @@ export class CetusProvider {
|
|
|
32
32
|
depth: this.options.depth,
|
|
33
33
|
liquidityChanges: this.options.liquidityChanges,
|
|
34
34
|
});
|
|
35
|
-
assert(!!quote, "No quote found");
|
|
35
|
+
MetaAgError.assert(!!quote, "No quote found", MetaAgErrorCode.QUOTE_NOT_FOUND, { provider: this.kind });
|
|
36
36
|
return {
|
|
37
37
|
id: v4(),
|
|
38
38
|
provider: EProvider.CETUS,
|
|
@@ -45,7 +45,7 @@ export class CetusProvider {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
async swap(options) {
|
|
48
|
-
assert(options.quote.provider === EProvider.CETUS, "Expect Cetus quote");
|
|
48
|
+
MetaAgError.assert(options.quote.provider === EProvider.CETUS, "Expect Cetus quote", MetaAgErrorCode.INVALID_QUOTE, { quote: options.quote, expectedProvider: EProvider.CETUS });
|
|
49
49
|
const coinOut = await this.cetusClient.routerSwap({
|
|
50
50
|
inputCoin: options.coinIn,
|
|
51
51
|
router: options.quote.quote,
|
|
@@ -2,7 +2,7 @@ import { AggregatorQuoter, Commission, CommissionType, TradeBuilder, } from "@fl
|
|
|
2
2
|
import { v4 } from "uuid";
|
|
3
3
|
import { _7K_PARTNER_ADDRESS } from "../../../constants/_7k";
|
|
4
4
|
import { EProvider, } from "../../../types/metaAg";
|
|
5
|
-
import {
|
|
5
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
6
6
|
export class FlowxProvider {
|
|
7
7
|
options;
|
|
8
8
|
client;
|
|
@@ -36,7 +36,7 @@ export class FlowxProvider {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
async swap(options) {
|
|
39
|
-
assert(options.quote.provider === EProvider.FLOWX, "Invalid quote");
|
|
39
|
+
MetaAgError.assert(options.quote.provider === EProvider.FLOWX, "Invalid quote", MetaAgErrorCode.INVALID_QUOTE, { quote: options.quote, expectedProvider: EProvider.FLOWX });
|
|
40
40
|
const builder = new TradeBuilder("mainnet", options.quote.quote.routes);
|
|
41
41
|
builder.sender(options.signer);
|
|
42
42
|
builder.slippage(10000 * 100);
|
|
@@ -3,10 +3,11 @@ import { normalizeStructTag, normalizeSuiAddress, toBase64, } from "@mysten/sui/
|
|
|
3
3
|
import { v4 } from "uuid";
|
|
4
4
|
import { SUI_TYPE } from "../../../constants/tokens";
|
|
5
5
|
import { EProvider, } from "../../../types/metaAg";
|
|
6
|
-
import {
|
|
6
|
+
import { isSystemAddress } from "../../../utils/sui";
|
|
7
7
|
import { metaSettle, simulateSwapTx } from "../common";
|
|
8
|
+
import { MetaAgError, MetaAgErrorCode } from "../error";
|
|
8
9
|
const API = "https://web3.okx.com";
|
|
9
|
-
const SWAP_PATH = "/api/
|
|
10
|
+
const SWAP_PATH = "/api/v6/dex/aggregator/swap";
|
|
10
11
|
const CHAIN_ID = "784";
|
|
11
12
|
const NORMALIZED_SUI_TYPE = normalizeStructTag(SUI_TYPE);
|
|
12
13
|
export class OkxProvider {
|
|
@@ -20,14 +21,14 @@ export class OkxProvider {
|
|
|
20
21
|
this.client = client;
|
|
21
22
|
}
|
|
22
23
|
async quote({ amountIn, coinTypeIn, coinTypeOut, signer, }) {
|
|
23
|
-
if (!signer)
|
|
24
|
+
if (!signer || isSystemAddress(signer))
|
|
24
25
|
return null;
|
|
25
26
|
const request = {
|
|
26
|
-
|
|
27
|
+
chainIndex: CHAIN_ID,
|
|
27
28
|
amount: amountIn,
|
|
28
29
|
fromTokenAddress: coinTypeIn === NORMALIZED_SUI_TYPE ? SUI_TYPE : coinTypeIn,
|
|
29
30
|
toTokenAddress: coinTypeOut === NORMALIZED_SUI_TYPE ? SUI_TYPE : coinTypeOut,
|
|
30
|
-
|
|
31
|
+
slippagePercent: (this.metaOptions.slippageBps / 100).toString(),
|
|
31
32
|
userWalletAddress: signer,
|
|
32
33
|
};
|
|
33
34
|
const queryString = "?" + new URLSearchParams(request).toString();
|
|
@@ -36,7 +37,7 @@ export class OkxProvider {
|
|
|
36
37
|
headers: await getHeaders(this.options, "GET", SWAP_PATH, queryString),
|
|
37
38
|
});
|
|
38
39
|
const quote = (await response.json());
|
|
39
|
-
assert(quote.code === "0" && quote.data.length > 0, "No quote found");
|
|
40
|
+
MetaAgError.assert(quote.code === "0" && quote.data.length > 0, "No quote found", MetaAgErrorCode.QUOTE_NOT_FOUND, { provider: this.kind });
|
|
40
41
|
return {
|
|
41
42
|
id: v4(),
|
|
42
43
|
provider: this.kind,
|
|
@@ -50,7 +51,7 @@ export class OkxProvider {
|
|
|
50
51
|
}
|
|
51
52
|
async fastSwap(options) {
|
|
52
53
|
const { quote, signer, signTransaction } = options;
|
|
53
|
-
assert(quote.provider === EProvider.OKX, "Invalid quote");
|
|
54
|
+
MetaAgError.assert(quote.provider === EProvider.OKX, "Invalid quote", MetaAgErrorCode.INVALID_QUOTE, { quote, expectedProvider: EProvider.OKX });
|
|
54
55
|
const { tx, coin } = buildTx({ quote, signer });
|
|
55
56
|
tx.add(metaSettle(quote, coin, this.metaOptions.slippageBps, this.metaOptions.tipBps, this.metaOptions.partner, this.metaOptions.partnerCommissionBps));
|
|
56
57
|
tx.transferObjects([coin], signer);
|
|
@@ -76,7 +77,7 @@ async function generateHmacSha256(message, secretKey) {
|
|
|
76
77
|
if (typeof btoa !== "undefined") {
|
|
77
78
|
return btoa(binary);
|
|
78
79
|
}
|
|
79
|
-
throw new
|
|
80
|
+
throw new MetaAgError("Base64 encoder not available in this environment");
|
|
80
81
|
};
|
|
81
82
|
if (typeof globalThis !== "undefined" && globalThis.crypto?.subtle) {
|
|
82
83
|
const key = await globalThis.crypto.subtle.importKey("raw", encoder.encode(secretKey), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
@@ -89,7 +90,7 @@ async function generateHmacSha256(message, secretKey) {
|
|
|
89
90
|
async function getHeaders(options, method, requestPath, queryString = "") {
|
|
90
91
|
const { apiKey, secretKey, apiPassphrase, projectId } = options;
|
|
91
92
|
if (!apiKey || !secretKey || !apiPassphrase || !projectId) {
|
|
92
|
-
throw new
|
|
93
|
+
throw new MetaAgError("Missing required environment variables");
|
|
93
94
|
}
|
|
94
95
|
const timestamp = new Date().toISOString();
|
|
95
96
|
const stringToSign = timestamp + method + requestPath + queryString;
|
|
@@ -110,7 +111,7 @@ const replaceFinalizeCommand = (tx, packageId) => {
|
|
|
110
111
|
cmd.MoveCall.module === "router" &&
|
|
111
112
|
cmd.MoveCall.function === "finalize");
|
|
112
113
|
const cmd = builder.commands[i];
|
|
113
|
-
assert(cmd.MoveCall, "OKX: Finalize command not found");
|
|
114
|
+
MetaAgError.assert(cmd.MoveCall, "OKX: Finalize command not found", MetaAgErrorCode.OKX_FINALIZE_COMMAND_NOT_FOUND, { packageId });
|
|
114
115
|
builder.replaceCommand(i, Commands.MoveCall({
|
|
115
116
|
package: packageId,
|
|
116
117
|
module: "router",
|
|
@@ -127,7 +128,7 @@ const replaceFinalizeCommand = (tx, packageId) => {
|
|
|
127
128
|
};
|
|
128
129
|
const buildTx = (options) => {
|
|
129
130
|
const { quote, signer } = options;
|
|
130
|
-
assert(quote.provider === EProvider.OKX, "Invalid quote");
|
|
131
|
+
MetaAgError.assert(quote.provider === EProvider.OKX, "Invalid quote", MetaAgErrorCode.INVALID_QUOTE, { quote, expectedProvider: EProvider.OKX });
|
|
131
132
|
const tx = Transaction.from(quote.quote.tx.data);
|
|
132
133
|
tx.setSenderIfNotSet(signer);
|
|
133
134
|
const { tx: tx2, coin } = replaceFinalizeCommand(tx, quote.quote.tx.to);
|