@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,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.timeout = exports.metaSettle = exports.simulateAggregator = exports.simulateSwapTx = exports.simulateBluefinX = void 0;
|
|
4
|
-
const transactions_1 = require("@mysten/sui/transactions");
|
|
5
|
-
const _7k_1 = require("../../constants/_7k");
|
|
6
|
-
const buildTx_1 = require("../swap/buildTx");
|
|
7
|
-
const DEFAULT_GAS_USED = {
|
|
8
|
-
computationCost: "0",
|
|
9
|
-
nonRefundableStorageFee: "0",
|
|
10
|
-
storageCost: "0",
|
|
11
|
-
storageRebate: "0",
|
|
12
|
-
};
|
|
13
|
-
const simulateBluefinX = (quote) => {
|
|
14
|
-
return {
|
|
15
|
-
id: quote.id,
|
|
16
|
-
simulatedAmountOut: quote.amountOut,
|
|
17
|
-
gasUsed: DEFAULT_GAS_USED,
|
|
18
|
-
provider: quote.provider,
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
exports.simulateBluefinX = simulateBluefinX;
|
|
22
|
-
const simulateSwapTx = async (tx, inspector, simulation) => {
|
|
23
|
-
const res = await (0, exports.timeout)(() => inspector.devInspectTransactionBlock({
|
|
24
|
-
sender: simulation.sender,
|
|
25
|
-
transactionBlock: tx,
|
|
26
|
-
}), simulation.timeout ?? 2000);
|
|
27
|
-
if (res.effects.status.status === "failure") {
|
|
28
|
-
throw new Error(res.error ?? "Simulation failed");
|
|
29
|
-
}
|
|
30
|
-
const amountOut = extractAmountOutWrapper(res.events);
|
|
31
|
-
return {
|
|
32
|
-
simulatedAmountOut: amountOut,
|
|
33
|
-
gasUsed: res.effects.gasUsed,
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
exports.simulateSwapTx = simulateSwapTx;
|
|
37
|
-
const simulateAggregator = async (provider, quote, simulation, inspector, options) => {
|
|
38
|
-
const tx = new transactions_1.Transaction();
|
|
39
|
-
const coinOut = await provider.swap({
|
|
40
|
-
quote,
|
|
41
|
-
coinIn: (0, transactions_1.coinWithBalance)({
|
|
42
|
-
balance: BigInt(quote.amountIn),
|
|
43
|
-
type: quote.coinTypeIn,
|
|
44
|
-
useGasCoin: false,
|
|
45
|
-
}),
|
|
46
|
-
signer: simulation.sender,
|
|
47
|
-
tx,
|
|
48
|
-
});
|
|
49
|
-
tx.add((0, exports.metaSettle)(quote, coinOut, 10000, options.tipBps, options.partner, options.partnerCommissionBps));
|
|
50
|
-
tx.transferObjects([coinOut], simulation.sender);
|
|
51
|
-
const res = await (0, exports.simulateSwapTx)(tx, inspector, simulation);
|
|
52
|
-
return {
|
|
53
|
-
id: quote.id,
|
|
54
|
-
provider: provider.kind,
|
|
55
|
-
...res,
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
exports.simulateAggregator = simulateAggregator;
|
|
59
|
-
/**
|
|
60
|
-
* this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner
|
|
61
|
-
* @param quote Meta Aggregator Quote
|
|
62
|
-
* @param coinOut Coin Out Object
|
|
63
|
-
* @param slippageBps Slippage Bps
|
|
64
|
-
* @param tipBps Tip Bps default = 0
|
|
65
|
-
* @param partner address of partner for analytic default is zero address
|
|
66
|
-
*/
|
|
67
|
-
const metaSettle = (quote, coinOut, slippageBps = 100, tipBps = 0, partner, commissionBps = 0) => {
|
|
68
|
-
return (tx) => {
|
|
69
|
-
const { minAmount, expectedAmount } = (0, buildTx_1.getExpectedReturn)(quote.rawAmountOut, slippageBps, commissionBps, tipBps);
|
|
70
|
-
if (tipBps > 0) {
|
|
71
|
-
tx.moveCall({
|
|
72
|
-
target: `${_7k_1._7K_META_PUBLISHED_AT}::vault::collect_tip`,
|
|
73
|
-
typeArguments: [quote.coinTypeOut],
|
|
74
|
-
arguments: [
|
|
75
|
-
tx.object(_7k_1._7K_META_VAULT),
|
|
76
|
-
tx.object(_7k_1._7K_META_CONFIG),
|
|
77
|
-
coinOut,
|
|
78
|
-
tx.pure.u64(tipBps),
|
|
79
|
-
],
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
tx.moveCall({
|
|
83
|
-
target: `${_7k_1._7K_META_PUBLISHED_AT}::settle::settle`,
|
|
84
|
-
typeArguments: [quote.coinTypeIn, quote.coinTypeOut],
|
|
85
|
-
arguments: [
|
|
86
|
-
tx.object(_7k_1._7K_META_CONFIG),
|
|
87
|
-
tx.object(_7k_1._7K_META_VAULT),
|
|
88
|
-
tx.pure.u64(quote.amountIn),
|
|
89
|
-
coinOut,
|
|
90
|
-
tx.pure.u64(minAmount),
|
|
91
|
-
tx.pure.u64(expectedAmount),
|
|
92
|
-
tx.pure.option("address", partner),
|
|
93
|
-
tx.pure.u64(commissionBps),
|
|
94
|
-
tx.pure.u64(0), // ps
|
|
95
|
-
],
|
|
96
|
-
});
|
|
97
|
-
};
|
|
98
|
-
};
|
|
99
|
-
exports.metaSettle = metaSettle;
|
|
100
|
-
const extractAmountOutWrapper = (events) => {
|
|
101
|
-
const swapEvent = events
|
|
102
|
-
.filter((event) => event.type === `${_7k_1._7K_META_PACKAGE_ID}::settle::Swap`)
|
|
103
|
-
?.pop();
|
|
104
|
-
return swapEvent?.parsedJson?.amount_out;
|
|
105
|
-
};
|
|
106
|
-
const timeout = async (fn, timeout, msg) => {
|
|
107
|
-
if (timeout <= 0)
|
|
108
|
-
return fn();
|
|
109
|
-
return new Promise((resolve, reject) => {
|
|
110
|
-
const timer = setTimeout(() => reject(new Error(`Timeout ${msg ?? "operation"}`)), timeout);
|
|
111
|
-
fn()
|
|
112
|
-
.then(resolve)
|
|
113
|
-
.catch(reject)
|
|
114
|
-
.finally(() => clearTimeout(timer));
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
exports.timeout = timeout;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AstroProvider = void 0;
|
|
4
|
-
const astros_aggregator_sdk_1 = require("@naviprotocol/astros-aggregator-sdk");
|
|
5
|
-
const uuid_1 = require("uuid");
|
|
6
|
-
const _7k_1 = require("../../../constants/_7k");
|
|
7
|
-
const metaAg_1 = require("../../../types/metaAg");
|
|
8
|
-
const condition_1 = require("../../../utils/condition");
|
|
9
|
-
class AstroProvider {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
this.options = options;
|
|
12
|
-
this.kind = metaAg_1.EProvider.ASTRO;
|
|
13
|
-
}
|
|
14
|
-
async quote({ amountIn, coinTypeIn, coinTypeOut, }) {
|
|
15
|
-
const quote = await (0, astros_aggregator_sdk_1.getQuote)(coinTypeIn, coinTypeOut, amountIn, this.options.api, {
|
|
16
|
-
baseUrl: this.options.api,
|
|
17
|
-
byAmountIn: true,
|
|
18
|
-
depth: this.options.depth,
|
|
19
|
-
dexList: this.options.dexList,
|
|
20
|
-
serviceFee: {
|
|
21
|
-
fee: 0,
|
|
22
|
-
receiverAddress: _7k_1._7K_PARTNER_ADDRESS,
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
return {
|
|
26
|
-
id: (0, uuid_1.v4)(),
|
|
27
|
-
provider: this.kind,
|
|
28
|
-
quote,
|
|
29
|
-
amountIn,
|
|
30
|
-
rawAmountOut: quote.amount_out.toString(),
|
|
31
|
-
amountOut: quote.amount_out.toString(),
|
|
32
|
-
coinTypeIn,
|
|
33
|
-
coinTypeOut,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async swap({ signer, quote, coinIn, tx }) {
|
|
37
|
-
(0, condition_1.assert)(quote.provider === metaAg_1.EProvider.ASTRO, "Invalid quote");
|
|
38
|
-
const coin = await (0, astros_aggregator_sdk_1.buildSwapPTBFromQuote)(signer, tx, 0, coinIn, quote.quote);
|
|
39
|
-
return coin;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.AstroProvider = AstroProvider;
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BluefinXProvider = void 0;
|
|
4
|
-
const transactions_1 = require("@mysten/sui/transactions");
|
|
5
|
-
const utils_1 = require("@mysten/sui/utils");
|
|
6
|
-
const uuid_1 = require("uuid");
|
|
7
|
-
const config_1 = require("../../../config");
|
|
8
|
-
const _7k_1 = require("../../../constants/_7k");
|
|
9
|
-
const client_1 = require("../../../libs/protocols/bluefinx/client");
|
|
10
|
-
const aggregator_1 = require("../../../types/aggregator");
|
|
11
|
-
const metaAg_1 = require("../../../types/metaAg");
|
|
12
|
-
const condition_1 = require("../../../utils/condition");
|
|
13
|
-
const buildTxV2_1 = require("../../swap/buildTxV2");
|
|
14
|
-
const getQuote_1 = require("../../swap/getQuote");
|
|
15
|
-
const common_1 = require("../common");
|
|
16
|
-
const SUPPORT_COINS = [
|
|
17
|
-
"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
|
|
18
|
-
"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
|
|
19
|
-
];
|
|
20
|
-
class BluefinXProvider {
|
|
21
|
-
constructor(options) {
|
|
22
|
-
this.options = options;
|
|
23
|
-
this.kind = metaAg_1.EProvider.BLUEFINX;
|
|
24
|
-
if (options.apiKey)
|
|
25
|
-
config_1.Config.setApiKey(options.apiKey);
|
|
26
|
-
if (options.api)
|
|
27
|
-
config_1.Config.setApi(options.api);
|
|
28
|
-
}
|
|
29
|
-
async quote(options) {
|
|
30
|
-
if (!this.canQuote(options))
|
|
31
|
-
return null;
|
|
32
|
-
const quote = await (0, getQuote_1.getQuote)({
|
|
33
|
-
amountIn: options.amountIn,
|
|
34
|
-
tokenIn: options.coinTypeIn,
|
|
35
|
-
tokenOut: options.coinTypeOut,
|
|
36
|
-
sources: ["bluefinx"],
|
|
37
|
-
taker: options.signer,
|
|
38
|
-
});
|
|
39
|
-
return {
|
|
40
|
-
id: (0, uuid_1.v4)(),
|
|
41
|
-
provider: this.kind,
|
|
42
|
-
quote,
|
|
43
|
-
amountIn: quote.swapAmountWithDecimal,
|
|
44
|
-
rawAmountOut: quote.returnAmountWithDecimal,
|
|
45
|
-
amountOut: quote.returnAmountWithDecimal,
|
|
46
|
-
coinTypeIn: options.coinTypeIn,
|
|
47
|
-
coinTypeOut: options.coinTypeOut,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
canQuote(options) {
|
|
51
|
-
return (!!options.signer &&
|
|
52
|
-
(0, utils_1.isValidSuiAddress)(options.signer) &&
|
|
53
|
-
SUPPORT_COINS.includes(options.coinTypeIn) &&
|
|
54
|
-
SUPPORT_COINS.includes(options.coinTypeOut));
|
|
55
|
-
}
|
|
56
|
-
async fastSwap(options) {
|
|
57
|
-
(0, condition_1.assert)(options.quote.provider === this.kind, "Invalid BluefinX quote");
|
|
58
|
-
const quote = options.quote.quote;
|
|
59
|
-
const tx = new transactions_1.Transaction();
|
|
60
|
-
const { tx: bluefinTx } = await (0, buildTxV2_1.buildTxV2Int)({
|
|
61
|
-
quoteResponse: quote,
|
|
62
|
-
accountAddress: options.signer,
|
|
63
|
-
commission: { commissionBps: 0, partner: _7k_1._7K_PARTNER_ADDRESS },
|
|
64
|
-
slippage: 0,
|
|
65
|
-
extendTx: {
|
|
66
|
-
tx,
|
|
67
|
-
coinIn: (0, transactions_1.coinWithBalance)({
|
|
68
|
-
type: options.quote.coinTypeIn,
|
|
69
|
-
balance: BigInt(options.quote.amountIn),
|
|
70
|
-
useGasCoin: false,
|
|
71
|
-
}),
|
|
72
|
-
},
|
|
73
|
-
}, (tx, coinOut) => {
|
|
74
|
-
if (coinOut) {
|
|
75
|
-
tx.add((0, common_1.metaSettle)(options.quote, coinOut, 0, 0));
|
|
76
|
-
tx.transferObjects([coinOut], options.signer);
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
(0, condition_1.assert)(bluefinTx instanceof aggregator_1.BluefinXTx, "BluefinX transaction not found");
|
|
80
|
-
const { signature } = await options.signTransaction(bluefinTx.txBytes);
|
|
81
|
-
const res = await (0, client_1.executeBluefinTx)(bluefinTx, signature);
|
|
82
|
-
(0, condition_1.assert)(res.approved, "BluefinX transaction not approved");
|
|
83
|
-
(0, condition_1.assert)(res.txDigest, "BluefinX transaction digest not found");
|
|
84
|
-
return res.txDigest;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
exports.BluefinXProvider = BluefinXProvider;
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.simulateOKXSwap = exports.OkxProvider = void 0;
|
|
37
|
-
const transactions_1 = require("@mysten/sui/transactions");
|
|
38
|
-
const utils_1 = require("@mysten/sui/utils");
|
|
39
|
-
const uuid_1 = require("uuid");
|
|
40
|
-
const tokens_1 = require("../../../constants/tokens");
|
|
41
|
-
const metaAg_1 = require("../../../types/metaAg");
|
|
42
|
-
const condition_1 = require("../../../utils/condition");
|
|
43
|
-
const common_1 = require("../common");
|
|
44
|
-
const API = "https://web3.okx.com";
|
|
45
|
-
const SWAP_PATH = "/api/v5/dex/aggregator/swap";
|
|
46
|
-
const CHAIN_ID = "784";
|
|
47
|
-
const NORMALIZED_SUI_TYPE = (0, utils_1.normalizeStructTag)(tokens_1.SUI_TYPE);
|
|
48
|
-
class OkxProvider {
|
|
49
|
-
constructor(options, metaOptions, client) {
|
|
50
|
-
this.options = options;
|
|
51
|
-
this.metaOptions = metaOptions;
|
|
52
|
-
this.client = client;
|
|
53
|
-
this.kind = metaAg_1.EProvider.OKX;
|
|
54
|
-
}
|
|
55
|
-
async quote({ amountIn, coinTypeIn, coinTypeOut, signer, }) {
|
|
56
|
-
if (!signer)
|
|
57
|
-
return null;
|
|
58
|
-
const request = {
|
|
59
|
-
chainId: CHAIN_ID,
|
|
60
|
-
amount: amountIn,
|
|
61
|
-
fromTokenAddress: coinTypeIn === NORMALIZED_SUI_TYPE ? tokens_1.SUI_TYPE : coinTypeIn,
|
|
62
|
-
toTokenAddress: coinTypeOut === NORMALIZED_SUI_TYPE ? tokens_1.SUI_TYPE : coinTypeOut,
|
|
63
|
-
slippage: (this.metaOptions.slippageBps / 10000).toString(),
|
|
64
|
-
userWalletAddress: signer,
|
|
65
|
-
};
|
|
66
|
-
const queryString = "?" + new URLSearchParams(request).toString();
|
|
67
|
-
const url = `${this.options.api ?? API}${SWAP_PATH}${queryString}`;
|
|
68
|
-
const response = await fetch(url, {
|
|
69
|
-
headers: await getHeaders(this.options, "GET", SWAP_PATH, queryString),
|
|
70
|
-
});
|
|
71
|
-
const quote = (await response.json());
|
|
72
|
-
(0, condition_1.assert)(quote.code === "0" && quote.data.length > 0, "No quote found");
|
|
73
|
-
return {
|
|
74
|
-
id: (0, uuid_1.v4)(),
|
|
75
|
-
provider: this.kind,
|
|
76
|
-
coinTypeIn,
|
|
77
|
-
coinTypeOut,
|
|
78
|
-
amountIn,
|
|
79
|
-
amountOut: quote.data[0].routerResult.toTokenAmount,
|
|
80
|
-
rawAmountOut: quote.data[0].routerResult.toTokenAmount,
|
|
81
|
-
quote: quote.data[0],
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
async fastSwap(options) {
|
|
85
|
-
const { quote, signer, signTransaction } = options;
|
|
86
|
-
(0, condition_1.assert)(quote.provider === metaAg_1.EProvider.OKX, "Invalid quote");
|
|
87
|
-
const { tx, coin } = buildTx({ quote, signer });
|
|
88
|
-
tx.add((0, common_1.metaSettle)(quote, coin, this.metaOptions.slippageBps, this.metaOptions.tipBps, this.metaOptions.partner, this.metaOptions.partnerCommissionBps));
|
|
89
|
-
tx.transferObjects([coin], signer);
|
|
90
|
-
const txBytes = await tx.build({ client: this.client });
|
|
91
|
-
const { bytes, signature } = await signTransaction((0, utils_1.toBase64)(txBytes));
|
|
92
|
-
const res = await this.client.executeTransactionBlock({
|
|
93
|
-
signature,
|
|
94
|
-
transactionBlock: bytes,
|
|
95
|
-
});
|
|
96
|
-
return res.digest;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
exports.OkxProvider = OkxProvider;
|
|
100
|
-
async function generateHmacSha256(message, secretKey) {
|
|
101
|
-
const encoder = new TextEncoder();
|
|
102
|
-
const encodeBase64 = (bytes) => {
|
|
103
|
-
if (typeof Buffer !== "undefined") {
|
|
104
|
-
return Buffer.from(bytes).toString("base64");
|
|
105
|
-
}
|
|
106
|
-
let binary = "";
|
|
107
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
108
|
-
binary += String.fromCharCode(bytes[i]);
|
|
109
|
-
}
|
|
110
|
-
if (typeof btoa !== "undefined") {
|
|
111
|
-
return btoa(binary);
|
|
112
|
-
}
|
|
113
|
-
throw new Error("Base64 encoder not available in this environment");
|
|
114
|
-
};
|
|
115
|
-
if (typeof globalThis !== "undefined" && globalThis.crypto?.subtle) {
|
|
116
|
-
const key = await globalThis.crypto.subtle.importKey("raw", encoder.encode(secretKey), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
117
|
-
const signature = await globalThis.crypto.subtle.sign("HMAC", key, encoder.encode(message));
|
|
118
|
-
return encodeBase64(new Uint8Array(signature));
|
|
119
|
-
}
|
|
120
|
-
const { createHmac } = await Promise.resolve().then(() => __importStar(require("node:crypto")));
|
|
121
|
-
return createHmac("sha256", secretKey).update(message).digest("base64");
|
|
122
|
-
}
|
|
123
|
-
async function getHeaders(options, method, requestPath, queryString = "") {
|
|
124
|
-
const { apiKey, secretKey, apiPassphrase, projectId } = options;
|
|
125
|
-
if (!apiKey || !secretKey || !apiPassphrase || !projectId) {
|
|
126
|
-
throw new Error("Missing required environment variables");
|
|
127
|
-
}
|
|
128
|
-
const timestamp = new Date().toISOString();
|
|
129
|
-
const stringToSign = timestamp + method + requestPath + queryString;
|
|
130
|
-
return {
|
|
131
|
-
"Content-Type": "application/json",
|
|
132
|
-
"OK-ACCESS-KEY": apiKey,
|
|
133
|
-
"OK-ACCESS-SIGN": await generateHmacSha256(stringToSign, secretKey),
|
|
134
|
-
"OK-ACCESS-TIMESTAMP": timestamp,
|
|
135
|
-
"OK-ACCESS-PASSPHRASE": apiPassphrase,
|
|
136
|
-
"OK-ACCESS-PROJECT": projectId,
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
const replaceFinalizeCommand = (tx, packageId) => {
|
|
140
|
-
const builder = transactions_1.TransactionDataBuilder.restore(tx.getData());
|
|
141
|
-
const i = builder.commands.findIndex((cmd) => cmd.$kind === "MoveCall" &&
|
|
142
|
-
(0, utils_1.normalizeSuiAddress)(cmd.MoveCall.package) ===
|
|
143
|
-
(0, utils_1.normalizeSuiAddress)(packageId) &&
|
|
144
|
-
cmd.MoveCall.module === "router" &&
|
|
145
|
-
cmd.MoveCall.function === "finalize");
|
|
146
|
-
const cmd = builder.commands[i];
|
|
147
|
-
(0, condition_1.assert)(cmd.MoveCall, "OKX: Finalize command not found");
|
|
148
|
-
builder.replaceCommand(i, transactions_1.Commands.MoveCall({
|
|
149
|
-
package: packageId,
|
|
150
|
-
module: "router",
|
|
151
|
-
function: "finalize_without_transfer",
|
|
152
|
-
typeArguments: cmd.MoveCall.typeArguments,
|
|
153
|
-
arguments: [
|
|
154
|
-
cmd.MoveCall.arguments[0],
|
|
155
|
-
cmd.MoveCall.arguments[5],
|
|
156
|
-
cmd.MoveCall.arguments[6],
|
|
157
|
-
],
|
|
158
|
-
}));
|
|
159
|
-
const tx2 = transactions_1.Transaction.from(builder.build());
|
|
160
|
-
return { tx: tx2, coin: { NestedResult: [i, 0] } };
|
|
161
|
-
};
|
|
162
|
-
const buildTx = (options) => {
|
|
163
|
-
const { quote, signer } = options;
|
|
164
|
-
(0, condition_1.assert)(quote.provider === metaAg_1.EProvider.OKX, "Invalid quote");
|
|
165
|
-
const tx = transactions_1.Transaction.from(quote.quote.tx.data);
|
|
166
|
-
tx.setSenderIfNotSet(signer);
|
|
167
|
-
const { tx: tx2, coin } = replaceFinalizeCommand(tx, quote.quote.tx.to);
|
|
168
|
-
return { tx: tx2, coin };
|
|
169
|
-
};
|
|
170
|
-
const simulateOKXSwap = async (quote, inspector, simulation, metaOptions) => {
|
|
171
|
-
const { tx, coin } = buildTx({ quote, signer: quote.quote.tx.from });
|
|
172
|
-
tx.add((0, common_1.metaSettle)(quote, coin, 10000, metaOptions.tipBps, metaOptions.partner, metaOptions.partnerCommissionBps));
|
|
173
|
-
tx.transferObjects([coin], quote.quote.tx.from);
|
|
174
|
-
const res = await (0, common_1.simulateSwapTx)(tx, inspector, simulation);
|
|
175
|
-
return {
|
|
176
|
-
id: quote.id,
|
|
177
|
-
provider: quote.provider,
|
|
178
|
-
...res,
|
|
179
|
-
};
|
|
180
|
-
};
|
|
181
|
-
exports.simulateOKXSwap = simulateOKXSwap;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { GasCostSummary } from "@mysten/sui/client";
|
|
2
|
-
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
3
|
-
import { AggregatorProvider, EProvider, MetaAgOptions, MetaQuote, MetaSimulationOptions } from "../../types/metaAg";
|
|
4
|
-
import { SuiClientUtils } from "../../utils/SuiClientUtils";
|
|
5
|
-
export declare const simulateBluefinX: <T extends MetaQuote & {
|
|
6
|
-
provider: EProvider.BLUEFINX;
|
|
7
|
-
}>(quote: T) => {
|
|
8
|
-
id: string;
|
|
9
|
-
simulatedAmountOut: string;
|
|
10
|
-
gasUsed: GasCostSummary;
|
|
11
|
-
provider: EProvider.BLUEFINX;
|
|
12
|
-
};
|
|
13
|
-
export declare const simulateSwapTx: (tx: Transaction, inspector: SuiClientUtils, simulation: MetaSimulationOptions) => Promise<{
|
|
14
|
-
simulatedAmountOut: string;
|
|
15
|
-
gasUsed: GasCostSummary;
|
|
16
|
-
}>;
|
|
17
|
-
export declare const simulateAggregator: (provider: AggregatorProvider, quote: MetaQuote, simulation: MetaSimulationOptions, inspector: SuiClientUtils, options: Required<MetaAgOptions>) => Promise<{
|
|
18
|
-
simulatedAmountOut: string;
|
|
19
|
-
gasUsed: GasCostSummary;
|
|
20
|
-
id: string;
|
|
21
|
-
provider: EProvider.BLUEFIN7K | EProvider.CETUS | EProvider.FLOWX | EProvider.ASTRO;
|
|
22
|
-
}>;
|
|
23
|
-
/**
|
|
24
|
-
* this settlement does not charge commission fee for partner, since all integrated aggregators already charge commission fee for partner
|
|
25
|
-
* @param quote Meta Aggregator Quote
|
|
26
|
-
* @param coinOut Coin Out Object
|
|
27
|
-
* @param slippageBps Slippage Bps
|
|
28
|
-
* @param tipBps Tip Bps default = 0
|
|
29
|
-
* @param partner address of partner for analytic default is zero address
|
|
30
|
-
*/
|
|
31
|
-
export declare const metaSettle: (quote: MetaQuote, coinOut: TransactionObjectArgument, slippageBps?: number, tipBps?: number, partner?: string, commissionBps?: number) => (tx: Transaction) => void;
|
|
32
|
-
export declare const timeout: <T = any>(fn: () => Promise<T>, timeout: number, msg?: string) => Promise<T>;
|
|
33
|
-
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../../src/features/metaAg/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAY,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAEL,WAAW,EACX,yBAAyB,EAC1B,MAAM,0BAA0B,CAAC;AAOlC,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,aAAa,EACb,SAAS,EACT,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAS5D,eAAO,MAAM,gBAAgB,GAC3B,CAAC,SAAS,SAAS,GAAG;IAAE,QAAQ,EAAE,SAAS,CAAC,QAAQ,CAAA;CAAE,EAEtD,OAAO,CAAC;;;;;CAQT,CAAC;AACF,eAAO,MAAM,cAAc,GACzB,IAAI,WAAW,EACf,WAAW,cAAc,EACzB,YAAY,qBAAqB;wBAeE,MAAM;;EAG1C,CAAC;AACF,eAAO,MAAM,kBAAkB,GAC7B,UAAU,kBAAkB,EAC5B,OAAO,SAAS,EAChB,YAAY,qBAAqB,EACjC,WAAW,cAAc,EACzB,SAAS,QAAQ,CAAC,aAAa,CAAC;wBATG,MAAM;;;;EAuC1C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,GACrB,OAAO,SAAS,EAChB,SAAS,yBAAyB,EAClC,oBAAiB,EACjB,eAAU,EACV,UAAU,MAAM,EAChB,sBAAiB,MAET,IAAI,WAAW,SAqCxB,CAAC;AASF,eAAO,MAAM,OAAO,GAAU,CAAC,GAAG,GAAG,EACnC,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,SAAS,MAAM,EACf,MAAM,MAAM,eAab,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AggregatorProvider, AstroProviderOptions, EProvider, MetaQuote, MetaQuoteOptions, MetaSwapOptions, QuoteProvider } from "../../../types/metaAg";
|
|
2
|
-
export declare class AstroProvider implements QuoteProvider, AggregatorProvider {
|
|
3
|
-
private readonly options;
|
|
4
|
-
readonly kind = EProvider.ASTRO;
|
|
5
|
-
constructor(options: AstroProviderOptions);
|
|
6
|
-
quote({ amountIn, coinTypeIn, coinTypeOut, }: MetaQuoteOptions): Promise<MetaQuote | null>;
|
|
7
|
-
swap({ signer, quote, coinIn, tx }: MetaSwapOptions): Promise<import("@mysten/sui/dist/cjs/transactions").TransactionResult>;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=astro.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"astro.d.ts","sourceRoot":"","sources":["../../../../../../src/features/metaAg/providers/astro.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,aAAa,EACd,MAAM,uBAAuB,CAAC;AAG/B,qBAAa,aAAc,YAAW,aAAa,EAAE,kBAAkB;IAEzD,OAAO,CAAC,QAAQ,CAAC,OAAO;IADpC,QAAQ,CAAC,IAAI,mBAAmB;gBACH,OAAO,EAAE,oBAAoB;IAEpD,KAAK,CAAC,EACV,QAAQ,EACR,UAAU,EACV,WAAW,GACZ,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IA6BzC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,eAAe;CAW1D"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { BluefinXProviderOptions, EProvider, MetaFastSwapOptions, MetaQuote, MetaQuoteOptions, QuoteProvider, SwapAPIProvider } from "../../../types/metaAg";
|
|
2
|
-
export declare class BluefinXProvider implements QuoteProvider, SwapAPIProvider {
|
|
3
|
-
private readonly options;
|
|
4
|
-
readonly kind = EProvider.BLUEFINX;
|
|
5
|
-
constructor(options: BluefinXProviderOptions);
|
|
6
|
-
quote(options: MetaQuoteOptions): Promise<MetaQuote | null>;
|
|
7
|
-
canQuote(options: MetaQuoteOptions): boolean;
|
|
8
|
-
fastSwap(options: MetaFastSwapOptions): Promise<string>;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=bluefinx.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bluefinx.d.ts","sourceRoot":"","sources":["../../../../../../src/features/metaAg/providers/bluefinx.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,uBAAuB,EACvB,SAAS,EACT,mBAAmB,EACnB,SAAS,EACT,gBAAgB,EAChB,aAAa,EACb,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAU/B,qBAAa,gBAAiB,YAAW,aAAa,EAAE,eAAe;IAEzD,OAAO,CAAC,QAAQ,CAAC,OAAO;IADpC,QAAQ,CAAC,IAAI,sBAAsB;gBACN,OAAO,EAAE,uBAAuB;IAKvD,KAAK,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAqBjE,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO;IAStC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;CAiC9D"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { SuiClient } from "@mysten/sui/client";
|
|
2
|
-
import { EProvider, MetaAgOptions, MetaFastSwapOptions, MetaQuote, MetaQuoteOptions, MetaSimulationOptions, OkxProviderOptions, QuoteProvider, SwapAPIProvider } from "../../../types/metaAg";
|
|
3
|
-
import { SuiClientUtils } from "../../../utils/SuiClientUtils";
|
|
4
|
-
export declare class OkxProvider implements QuoteProvider, SwapAPIProvider {
|
|
5
|
-
private readonly options;
|
|
6
|
-
private readonly metaOptions;
|
|
7
|
-
private readonly client;
|
|
8
|
-
readonly kind = EProvider.OKX;
|
|
9
|
-
constructor(options: OkxProviderOptions, metaOptions: Required<MetaAgOptions>, client: SuiClient);
|
|
10
|
-
quote({ amountIn, coinTypeIn, coinTypeOut, signer, }: MetaQuoteOptions): Promise<MetaQuote | null>;
|
|
11
|
-
fastSwap(options: MetaFastSwapOptions): Promise<string>;
|
|
12
|
-
}
|
|
13
|
-
export declare const simulateOKXSwap: <T extends MetaQuote & {
|
|
14
|
-
provider: EProvider.OKX;
|
|
15
|
-
}>(quote: T, inspector: SuiClientUtils, simulation: MetaSimulationOptions, metaOptions: Required<MetaAgOptions>) => Promise<{
|
|
16
|
-
simulatedAmountOut: string;
|
|
17
|
-
gasUsed: import("@mysten/sui/client").GasCostSummary;
|
|
18
|
-
id: string;
|
|
19
|
-
provider: EProvider.OKX;
|
|
20
|
-
}>;
|
|
21
|
-
//# sourceMappingURL=okx.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"okx.d.ts","sourceRoot":"","sources":["../../../../../../src/features/metaAg/providers/okx.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAc/C,OAAO,EACL,SAAS,EACT,aAAa,EACb,mBAAmB,EACnB,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EAErB,kBAAkB,EAClB,aAAa,EACb,eAAe,EAChB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAO/D,qBAAa,WAAY,YAAW,aAAa,EAAE,eAAe;IAG9D,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,QAAQ,CAAC,IAAI,iBAAiB;gBAEX,OAAO,EAAE,kBAAkB,EAC3B,WAAW,EAAE,QAAQ,CAAC,aAAa,CAAC,EACpC,MAAM,EAAE,SAAS;IAG9B,KAAK,CAAC,EACV,QAAQ,EACR,UAAU,EACV,WAAW,EACX,MAAM,GACP,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IA+BzC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;CAuB9D;AAyGD,eAAO,MAAM,eAAe,GAC1B,CAAC,SAAS,SAAS,GAAG;IAAE,QAAQ,EAAE,SAAS,CAAC,GAAG,CAAA;CAAE,EAEjD,OAAO,CAAC,EACR,WAAW,cAAc,EACzB,YAAY,qBAAqB,EACjC,aAAa,QAAQ,CAAC,aAAa,CAAC;;;;;EAoBrC,CAAC"}
|