@avail-project/ca-common 2.3.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +10593 -20
- package/dist/esm/index.mjs +10603 -0
- package/dist/types/index.d.ts +2608 -13
- package/package.json +41 -37
- package/dist/cjs/_polyfill.js +0 -147
- package/dist/cjs/balances/ub-api.js +0 -25
- package/dist/cjs/cosmos/index.js +0 -31
- package/dist/cjs/data/chaindata.js +0 -788
- package/dist/cjs/data/chainid.js +0 -93
- package/dist/cjs/data/currency.js +0 -78
- package/dist/cjs/data/index.js +0 -7
- package/dist/cjs/data/utils.js +0 -44
- package/dist/cjs/evmabi/erc20.abi.js +0 -349
- package/dist/cjs/evmabi/fibrousrouter.abi.js +0 -41
- package/dist/cjs/evmabi/index.js +0 -7
- package/dist/cjs/evmabi/vault.abi.js +0 -1021
- package/dist/cjs/evmabi/yakaggregator.abi.js +0 -275
- package/dist/cjs/permitutils/index.js +0 -186
- package/dist/cjs/proto/client.js +0 -48
- package/dist/cjs/proto/definition.js +0 -4131
- package/dist/cjs/proto/grpc.js +0 -298
- package/dist/cjs/rff/rff.js +0 -42
- package/dist/cjs/types/binarytypes.js +0 -2
- package/dist/cjs/types/index.js +0 -5
- package/dist/cjs/types/msgpack-axios.js +0 -22
- package/dist/cjs/vaultcontracts/index.js +0 -4
- package/dist/cjs/vaultcontracts/vaultcontracts.js +0 -222
- package/dist/cjs/xcs/autochoice.js +0 -575
- package/dist/cjs/xcs/bebop-agg.js +0 -156
- package/dist/cjs/xcs/fibrous-agg.js +0 -155
- package/dist/cjs/xcs/iface.js +0 -13
- package/dist/cjs/xcs/index.js +0 -9
- package/dist/cjs/xcs/lifi-agg.js +0 -177
- package/dist/cjs/xcs/selectsources.js +0 -255
- package/dist/esm/_polyfill.js +0 -143
- package/dist/esm/balances/ub-api.js +0 -21
- package/dist/esm/cosmos/index.js +0 -26
- package/dist/esm/data/chaindata.js +0 -785
- package/dist/esm/data/chainid.js +0 -87
- package/dist/esm/data/currency.js +0 -73
- package/dist/esm/data/index.js +0 -4
- package/dist/esm/data/utils.js +0 -34
- package/dist/esm/evmabi/erc20.abi.js +0 -346
- package/dist/esm/evmabi/fibrousrouter.abi.js +0 -38
- package/dist/esm/evmabi/index.js +0 -4
- package/dist/esm/evmabi/vault.abi.js +0 -1018
- package/dist/esm/evmabi/yakaggregator.abi.js +0 -272
- package/dist/esm/index.js +0 -13
- package/dist/esm/permitutils/index.js +0 -181
- package/dist/esm/proto/client.js +0 -11
- package/dist/esm/proto/definition.js +0 -4122
- package/dist/esm/proto/grpc.js +0 -292
- package/dist/esm/rff/rff.js +0 -38
- package/dist/esm/types/binarytypes.js +0 -1
- package/dist/esm/types/index.js +0 -2
- package/dist/esm/types/msgpack-axios.js +0 -18
- package/dist/esm/vaultcontracts/index.js +0 -1
- package/dist/esm/vaultcontracts/vaultcontracts.js +0 -218
- package/dist/esm/xcs/autochoice.js +0 -559
- package/dist/esm/xcs/bebop-agg.js +0 -151
- package/dist/esm/xcs/fibrous-agg.js +0 -150
- package/dist/esm/xcs/iface.js +0 -10
- package/dist/esm/xcs/index.js +0 -6
- package/dist/esm/xcs/lifi-agg.js +0 -172
- package/dist/esm/xcs/selectsources.js +0 -251
- package/dist/types/_polyfill.d.ts +0 -1
- package/dist/types/balances/ub-api.d.ts +0 -14
- package/dist/types/cosmos/index.d.ts +0 -6
- package/dist/types/data/chaindata.d.ts +0 -20
- package/dist/types/data/chainid.d.ts +0 -31
- package/dist/types/data/currency.d.ts +0 -30
- package/dist/types/data/index.d.ts +0 -4
- package/dist/types/data/utils.d.ts +0 -10
- package/dist/types/evmabi/erc20.abi.d.ts +0 -264
- package/dist/types/evmabi/fibrousrouter.abi.d.ts +0 -77
- package/dist/types/evmabi/index.d.ts +0 -4
- package/dist/types/evmabi/vault.abi.d.ts +0 -785
- package/dist/types/evmabi/yakaggregator.abi.d.ts +0 -298
- package/dist/types/permitutils/index.d.ts +0 -13
- package/dist/types/proto/client.d.ts +0 -2
- package/dist/types/proto/definition.d.ts +0 -382
- package/dist/types/proto/grpc.d.ts +0 -75
- package/dist/types/rff/rff.d.ts +0 -9
- package/dist/types/types/binarytypes.d.ts +0 -1
- package/dist/types/types/index.d.ts +0 -2
- package/dist/types/types/msgpack-axios.d.ts +0 -1
- package/dist/types/vaultcontracts/index.d.ts +0 -22
- package/dist/types/vaultcontracts/vaultcontracts.d.ts +0 -8
- package/dist/types/xcs/autochoice.d.ts +0 -104
- package/dist/types/xcs/bebop-agg.d.ts +0 -104
- package/dist/types/xcs/fibrous-agg.d.ts +0 -56
- package/dist/types/xcs/iface.d.ts +0 -69
- package/dist/types/xcs/index.d.ts +0 -6
- package/dist/types/xcs/lifi-agg.d.ts +0 -42
- package/dist/types/xcs/selectsources.d.ts +0 -27
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BebopAggregator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const axios_1 = tslib_1.__importStar(require("axios"));
|
|
6
|
-
const viem_1 = require("viem");
|
|
7
|
-
const iface_1 = require("./iface");
|
|
8
|
-
const definition_1 = require("../proto/definition");
|
|
9
|
-
const data_1 = require("../data");
|
|
10
|
-
const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
|
|
11
|
-
// https://api.bebop.xyz/{jam|pmm}/chains
|
|
12
|
-
const ChainNameMapping = new Map(Object.entries({
|
|
13
|
-
ethereum: 1,
|
|
14
|
-
arbitrum: 42161,
|
|
15
|
-
optimism: 10,
|
|
16
|
-
base: 8453,
|
|
17
|
-
bsc: 56,
|
|
18
|
-
avalanche: 43114,
|
|
19
|
-
polygon: 137,
|
|
20
|
-
scroll: 534352,
|
|
21
|
-
hyperevm: 999,
|
|
22
|
-
}).map(([k, v]) => [(0, viem_1.bytesToHex)((0, data_1.encodeChainID36)(definition_1.Universe.ETHEREUM, v)), k]));
|
|
23
|
-
class BebopAggregator {
|
|
24
|
-
static BASE_URL = "https://api.bebop.xyz/router";
|
|
25
|
-
static COMMON_OPTIONS = {
|
|
26
|
-
approval_type: "Standard",
|
|
27
|
-
skip_validation: "true",
|
|
28
|
-
gasless: false,
|
|
29
|
-
};
|
|
30
|
-
axios;
|
|
31
|
-
constructor(apiKey) {
|
|
32
|
-
this.axios = axios_1.default.create({
|
|
33
|
-
baseURL: BebopAggregator.BASE_URL,
|
|
34
|
-
headers: {
|
|
35
|
-
"Source-Auth": apiKey,
|
|
36
|
-
},
|
|
37
|
-
params: {
|
|
38
|
-
source: "arcana",
|
|
39
|
-
},
|
|
40
|
-
timeout: 10_000,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async getQuotes(requests) {
|
|
44
|
-
const list = await Promise.allSettled(requests.map(async (r) => {
|
|
45
|
-
const chainName = ChainNameMapping.get((0, viem_1.bytesToHex)(r.chain.toBytes()));
|
|
46
|
-
if (chainName == null) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
let respPromise;
|
|
50
|
-
const inputTokenAddr = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.inputToken.subarray(12)));
|
|
51
|
-
const outputTokenAddr = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.outputToken.subarray(12)));
|
|
52
|
-
const userAddrHex = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.userAddress.subarray(12)));
|
|
53
|
-
const receiverAddrHex = r.receiverAddress != null
|
|
54
|
-
? (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.receiverAddress.subarray(12)))
|
|
55
|
-
: userAddrHex;
|
|
56
|
-
switch (r.type) {
|
|
57
|
-
case iface_1.QuoteType.EXACT_IN: {
|
|
58
|
-
respPromise = this.axios({
|
|
59
|
-
method: "GET",
|
|
60
|
-
url: `/${chainName}/v1/quote`,
|
|
61
|
-
params: {
|
|
62
|
-
sell_tokens: inputTokenAddr,
|
|
63
|
-
buy_tokens: outputTokenAddr,
|
|
64
|
-
taker_address: userAddrHex,
|
|
65
|
-
receiver_address: receiverAddrHex,
|
|
66
|
-
sell_amounts: r.inputAmount.toString(),
|
|
67
|
-
...BebopAggregator.COMMON_OPTIONS,
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
case iface_1.QuoteType.EXACT_OUT: {
|
|
73
|
-
respPromise = this.axios({
|
|
74
|
-
method: "GET",
|
|
75
|
-
url: `/${chainName}/v1/quote`,
|
|
76
|
-
params: {
|
|
77
|
-
sell_tokens: inputTokenAddr,
|
|
78
|
-
buy_tokens: outputTokenAddr,
|
|
79
|
-
taker_address: userAddrHex,
|
|
80
|
-
receiver_address: receiverAddrHex,
|
|
81
|
-
buy_amounts: r.outputAmount.toString(),
|
|
82
|
-
...BebopAggregator.COMMON_OPTIONS,
|
|
83
|
-
},
|
|
84
|
-
});
|
|
85
|
-
break;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
let resp;
|
|
89
|
-
try {
|
|
90
|
-
resp = await respPromise;
|
|
91
|
-
}
|
|
92
|
-
catch (e) {
|
|
93
|
-
if (e instanceof axios_1.AxiosError && e.isAxiosError) {
|
|
94
|
-
if (e.response?.status === 404 &&
|
|
95
|
-
e.response.data.code === 1002 &&
|
|
96
|
-
e.response.data.message ===
|
|
97
|
-
"No available quotes for the requested transfer") {
|
|
98
|
-
return null;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
throw e;
|
|
102
|
-
}
|
|
103
|
-
const bestRoute = resp.data.routes?.at(0);
|
|
104
|
-
if (bestRoute == null) {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
const buyT = bestRoute.quote.buyTokens[outputTokenAddr];
|
|
108
|
-
const sellT = bestRoute.quote.sellTokens[inputTokenAddr];
|
|
109
|
-
const outputAmountInDecimal = new decimal_js_1.default(buyT.minimumAmount)
|
|
110
|
-
.div(decimal_js_1.default.pow(10, buyT.decimals))
|
|
111
|
-
.toFixed(buyT.decimals);
|
|
112
|
-
const inputAmountInDecimal = new decimal_js_1.default(sellT.amount)
|
|
113
|
-
.div(decimal_js_1.default.pow(10, sellT.decimals))
|
|
114
|
-
.toFixed(sellT.decimals);
|
|
115
|
-
return {
|
|
116
|
-
expiry: bestRoute.quote.expiry,
|
|
117
|
-
input: {
|
|
118
|
-
amount: inputAmountInDecimal,
|
|
119
|
-
amountRaw: BigInt(sellT.amount),
|
|
120
|
-
contractAddress: inputTokenAddr,
|
|
121
|
-
decimals: sellT.decimals,
|
|
122
|
-
value: decimal_js_1.default.mul(inputAmountInDecimal, sellT.priceUsd ?? 0).toNumber(),
|
|
123
|
-
symbol: sellT.symbol,
|
|
124
|
-
},
|
|
125
|
-
output: {
|
|
126
|
-
amount: outputAmountInDecimal,
|
|
127
|
-
amountRaw: BigInt(buyT.minimumAmount),
|
|
128
|
-
contractAddress: outputTokenAddr,
|
|
129
|
-
decimals: buyT.decimals,
|
|
130
|
-
value: decimal_js_1.default.mul(outputAmountInDecimal, buyT.priceUsd ?? 0).toNumber(),
|
|
131
|
-
symbol: buyT.symbol,
|
|
132
|
-
},
|
|
133
|
-
txData: {
|
|
134
|
-
approvalAddress: bestRoute.quote.approvalTarget,
|
|
135
|
-
tx: {
|
|
136
|
-
to: bestRoute.quote.tx.to,
|
|
137
|
-
value: bestRoute.quote.tx.value,
|
|
138
|
-
data: bestRoute.quote.tx.data,
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
}));
|
|
143
|
-
return list.map((item) => {
|
|
144
|
-
switch (item.status) {
|
|
145
|
-
case "fulfilled": {
|
|
146
|
-
return item.value;
|
|
147
|
-
}
|
|
148
|
-
case "rejected": {
|
|
149
|
-
console.error("Caught error in fetching Bebop quotes:", item.reason);
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
exports.BebopAggregator = BebopAggregator;
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FibrousAggregator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const axios_1 = tslib_1.__importStar(require("axios"));
|
|
6
|
-
const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
|
|
7
|
-
const viem_1 = require("viem");
|
|
8
|
-
const data_1 = require("../data");
|
|
9
|
-
const evmabi_1 = require("../evmabi");
|
|
10
|
-
const definition_1 = require("../proto/definition");
|
|
11
|
-
const iface_1 = require("./iface");
|
|
12
|
-
const ChainNameMapping = new data_1.ChainIDKeyedMap([
|
|
13
|
-
// [new OmniversalChainID(Universe.ETHEREUM, 8453), "base"], // Disabled because of few liquidity issues
|
|
14
|
-
[new data_1.OmniversalChainID(definition_1.Universe.ETHEREUM, 999), "hyperevm"],
|
|
15
|
-
[new data_1.OmniversalChainID(definition_1.Universe.ETHEREUM, 143), "monad"],
|
|
16
|
-
[new data_1.OmniversalChainID(definition_1.Universe.ETHEREUM, 4114), "citrea"],
|
|
17
|
-
]);
|
|
18
|
-
class FibrousAggregator {
|
|
19
|
-
static BASE_URL = "https://api.fibrous.finance";
|
|
20
|
-
axios;
|
|
21
|
-
slippage;
|
|
22
|
-
excludeProtocols;
|
|
23
|
-
constructor(options = {}) {
|
|
24
|
-
const { apiKey, slippage = 0.5, excludeProtocols = "3" } = options;
|
|
25
|
-
this.slippage = slippage;
|
|
26
|
-
this.excludeProtocols = excludeProtocols;
|
|
27
|
-
this.axios = axios_1.default.create({
|
|
28
|
-
baseURL: FibrousAggregator.BASE_URL,
|
|
29
|
-
headers: apiKey != null ? { "X-API-Key": apiKey } : undefined,
|
|
30
|
-
timeout: 10_000,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
async getQuotes(requests) {
|
|
34
|
-
const list = await Promise.allSettled(requests.map(async (r) => {
|
|
35
|
-
if (r.type === iface_1.QuoteType.EXACT_OUT) {
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
if (r.chain.universe !== definition_1.Universe.ETHEREUM) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
const chainName = ChainNameMapping.get(r.chain);
|
|
42
|
-
if (chainName == null) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
const inputTokenAddr = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.inputToken.subarray(12)));
|
|
46
|
-
const outputTokenAddr = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.outputToken.subarray(12)));
|
|
47
|
-
const userAddrHex = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.userAddress.subarray(12)));
|
|
48
|
-
const receiverAddrHex = r.receiverAddress != null
|
|
49
|
-
? (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.receiverAddress.subarray(12)))
|
|
50
|
-
: userAddrHex;
|
|
51
|
-
let resp;
|
|
52
|
-
try {
|
|
53
|
-
resp = await this.axios({
|
|
54
|
-
method: "GET",
|
|
55
|
-
url: `/${chainName}/v2/routeAndCallData`,
|
|
56
|
-
params: {
|
|
57
|
-
amount: r.inputAmount.toString(),
|
|
58
|
-
tokenInAddress: inputTokenAddr,
|
|
59
|
-
tokenOutAddress: outputTokenAddr,
|
|
60
|
-
slippage: this.slippage,
|
|
61
|
-
destination: receiverAddrHex,
|
|
62
|
-
excludeProtocols: this.excludeProtocols,
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
catch (e) {
|
|
67
|
-
if (e instanceof axios_1.AxiosError && e.isAxiosError) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
throw e;
|
|
71
|
-
}
|
|
72
|
-
if (!resp.data.route.success) {
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
if (resp.data.calldata.swap_parameters.length === 0) {
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
const inputAmountInDecimal = new decimal_js_1.default(resp.data.route.inputAmount)
|
|
79
|
-
.div(decimal_js_1.default.pow(10, resp.data.route.inputToken.decimals))
|
|
80
|
-
.toFixed(resp.data.route.inputToken.decimals);
|
|
81
|
-
const outputAmountInDecimal = new decimal_js_1.default(resp.data.calldata.route.min_received)
|
|
82
|
-
.div(decimal_js_1.default.pow(10, resp.data.route.outputToken.decimals))
|
|
83
|
-
.toFixed(resp.data.route.outputToken.decimals);
|
|
84
|
-
const routerAddress = (0, viem_1.getAddress)(resp.data.router_address);
|
|
85
|
-
const isNativeInput = resp.data.calldata.route.swap_type === 0;
|
|
86
|
-
const quote = {
|
|
87
|
-
originalResponse: resp.data,
|
|
88
|
-
input: {
|
|
89
|
-
amount: inputAmountInDecimal,
|
|
90
|
-
amountRaw: BigInt(resp.data.route.inputAmount),
|
|
91
|
-
contractAddress: inputTokenAddr,
|
|
92
|
-
decimals: resp.data.route.inputToken.decimals,
|
|
93
|
-
value: decimal_js_1.default.mul(inputAmountInDecimal, resp.data.route.inputToken.price ?? 0).toNumber(),
|
|
94
|
-
symbol: resp.data.route.inputToken.symbol ??
|
|
95
|
-
resp.data.route.inputToken.name,
|
|
96
|
-
},
|
|
97
|
-
output: {
|
|
98
|
-
amount: outputAmountInDecimal,
|
|
99
|
-
amountRaw: BigInt(resp.data.calldata.route.min_received),
|
|
100
|
-
contractAddress: outputTokenAddr,
|
|
101
|
-
decimals: resp.data.route.outputToken.decimals,
|
|
102
|
-
value: decimal_js_1.default.mul(outputAmountInDecimal, resp.data.route.outputToken.price ?? 0).toNumber(),
|
|
103
|
-
symbol: resp.data.route.outputToken.symbol ??
|
|
104
|
-
resp.data.route.outputToken.name,
|
|
105
|
-
},
|
|
106
|
-
txData: {
|
|
107
|
-
approvalAddress: isNativeInput ? viem_1.zeroAddress : routerAddress,
|
|
108
|
-
tx: {
|
|
109
|
-
to: routerAddress,
|
|
110
|
-
value: isNativeInput
|
|
111
|
-
? (0, viem_1.toHex)(BigInt(resp.data.calldata.route.amount_in))
|
|
112
|
-
: (0, viem_1.toHex)(0),
|
|
113
|
-
data: (0, viem_1.encodeFunctionData)({
|
|
114
|
-
abi: evmabi_1.FibrousRouterABI,
|
|
115
|
-
functionName: "swap",
|
|
116
|
-
args: [
|
|
117
|
-
{
|
|
118
|
-
token_in: (0, viem_1.getAddress)(resp.data.calldata.route.token_in),
|
|
119
|
-
token_out: (0, viem_1.getAddress)(resp.data.calldata.route.token_out),
|
|
120
|
-
amount_in: BigInt(resp.data.calldata.route.amount_in),
|
|
121
|
-
amount_out: BigInt(resp.data.calldata.route.amount_out),
|
|
122
|
-
min_received: BigInt(resp.data.calldata.route.min_received),
|
|
123
|
-
destination: (0, viem_1.getAddress)(resp.data.calldata.route.destination),
|
|
124
|
-
swap_type: resp.data.calldata.route.swap_type,
|
|
125
|
-
},
|
|
126
|
-
resp.data.calldata.swap_parameters.map((swapParameter) => ({
|
|
127
|
-
token_in: (0, viem_1.getAddress)(swapParameter.token_in),
|
|
128
|
-
token_out: (0, viem_1.getAddress)(swapParameter.token_out),
|
|
129
|
-
rate: Number.parseInt(swapParameter.rate, 10),
|
|
130
|
-
protocol_id: Number.parseInt(swapParameter.protocol_id, 10),
|
|
131
|
-
pool_address: (0, viem_1.getAddress)(swapParameter.pool_address),
|
|
132
|
-
swap_type: swapParameter.swap_type,
|
|
133
|
-
extra_data: swapParameter.extra_data,
|
|
134
|
-
})),
|
|
135
|
-
],
|
|
136
|
-
}),
|
|
137
|
-
},
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
return quote;
|
|
141
|
-
}));
|
|
142
|
-
return list.map((item) => {
|
|
143
|
-
switch (item.status) {
|
|
144
|
-
case "fulfilled": {
|
|
145
|
-
return item.value;
|
|
146
|
-
}
|
|
147
|
-
case "rejected": {
|
|
148
|
-
console.error("Caught error in fetching Fibrous quotes:", item.reason);
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
exports.FibrousAggregator = FibrousAggregator;
|
package/dist/cjs/xcs/iface.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QuoteSeriousness = exports.QuoteType = void 0;
|
|
4
|
-
var QuoteType;
|
|
5
|
-
(function (QuoteType) {
|
|
6
|
-
QuoteType[QuoteType["EXACT_IN"] = 0] = "EXACT_IN";
|
|
7
|
-
QuoteType[QuoteType["EXACT_OUT"] = 1] = "EXACT_OUT";
|
|
8
|
-
})(QuoteType || (exports.QuoteType = QuoteType = {}));
|
|
9
|
-
var QuoteSeriousness;
|
|
10
|
-
(function (QuoteSeriousness) {
|
|
11
|
-
QuoteSeriousness[QuoteSeriousness["PRICE_SURVEY"] = 0] = "PRICE_SURVEY";
|
|
12
|
-
QuoteSeriousness[QuoteSeriousness["SERIOUS"] = 1] = "SERIOUS";
|
|
13
|
-
})(QuoteSeriousness || (exports.QuoteSeriousness = QuoteSeriousness = {}));
|
package/dist/cjs/xcs/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
tslib_1.__exportStar(require("./iface"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./lifi-agg"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./bebop-agg"), exports);
|
|
7
|
-
tslib_1.__exportStar(require("./fibrous-agg"), exports);
|
|
8
|
-
tslib_1.__exportStar(require("./autochoice"), exports);
|
|
9
|
-
tslib_1.__exportStar(require("./selectsources"), exports);
|
package/dist/cjs/xcs/lifi-agg.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LiFiAggregator = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const axios_1 = tslib_1.__importStar(require("axios"));
|
|
6
|
-
const viem_1 = require("viem");
|
|
7
|
-
const iface_1 = require("./iface");
|
|
8
|
-
const definition_1 = require("../proto/definition");
|
|
9
|
-
const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
|
|
10
|
-
const ALLOWED_CHAINS = new Set([
|
|
11
|
-
1, // Ethereum
|
|
12
|
-
10, // Optimism
|
|
13
|
-
56, // BSC
|
|
14
|
-
137, // Polygon
|
|
15
|
-
143, // Monad
|
|
16
|
-
999, // HyperEVM
|
|
17
|
-
4326, // MegaETH
|
|
18
|
-
8453, // Base
|
|
19
|
-
42161, // Arbitrum
|
|
20
|
-
43114, // Avalanche
|
|
21
|
-
8217, // Kaia
|
|
22
|
-
534352, // Scroll
|
|
23
|
-
]);
|
|
24
|
-
class LiFiAggregator {
|
|
25
|
-
static BASE_URL_V1 = "https://li.quest/v1";
|
|
26
|
-
// Params that don't depend on chain — spread into every quote request.
|
|
27
|
-
// `denyExchanges` is built per-call via `denyExchangesFor(chainId)`.
|
|
28
|
-
static COMMON_OPTIONS = {
|
|
29
|
-
slippage: "0.01",
|
|
30
|
-
skipSimulation: true,
|
|
31
|
-
};
|
|
32
|
-
// Tools denied on every chain.
|
|
33
|
-
static GLOBAL_DENY = ["openocean"];
|
|
34
|
-
// Tools denied only on specific chains. Add an entry here when a tool quotes
|
|
35
|
-
// well on most chains but mis-quotes on a specific one — global-denying it
|
|
36
|
-
// would needlessly disable healthy routes elsewhere.
|
|
37
|
-
//
|
|
38
|
-
// 999 (HyperEVM): fly/hyperflow/liquidswap all share the same on-chain entry
|
|
39
|
-
// (0x0a0758d937d1059c356d4714e57f5df0239bce1a) and systematically over-quote
|
|
40
|
-
// native HYPE -> USDC routes by 5-11% (LI.FI /quote toAmountMin vs on-chain
|
|
41
|
-
// delivery, observed via InsufficientAmountOut(0xe52970aa) failures in
|
|
42
|
-
// HyperEVM Safe-mode swaps). They quote within ±0.2% of other tools on
|
|
43
|
-
// Ethereum/Base/Arbitrum/Polygon/Optimism, so the deny is chain-local.
|
|
44
|
-
static PER_CHAIN_DENY = {
|
|
45
|
-
999: ["fly", "hyperflow", "liquidswap"],
|
|
46
|
-
};
|
|
47
|
-
denyExchangesFor(chainId) {
|
|
48
|
-
const perChain = LiFiAggregator.PER_CHAIN_DENY[chainId] ?? [];
|
|
49
|
-
return [...LiFiAggregator.GLOBAL_DENY, ...perChain].join(",");
|
|
50
|
-
}
|
|
51
|
-
axios;
|
|
52
|
-
constructor(apiKey) {
|
|
53
|
-
this.axios = axios_1.default.create({
|
|
54
|
-
baseURL: LiFiAggregator.BASE_URL_V1,
|
|
55
|
-
headers: {
|
|
56
|
-
"x-lifi-api-key": apiKey,
|
|
57
|
-
},
|
|
58
|
-
timeout: 10_000,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
async getQuotes(requests) {
|
|
62
|
-
const list = await Promise.allSettled(requests.map(async (r) => {
|
|
63
|
-
if (r.chain.universe !== definition_1.Universe.ETHEREUM) {
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
if (!ALLOWED_CHAINS.has(Number(r.chain.chainID))) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
let respPromise;
|
|
70
|
-
const chIDStr = r.chain.chainID.toString();
|
|
71
|
-
const inputTokenAddr = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.inputToken.subarray(12)));
|
|
72
|
-
const outputTokenAddr = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.outputToken.subarray(12)));
|
|
73
|
-
const userAddrHex = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.userAddress.subarray(12)));
|
|
74
|
-
const receiverAddrHex = r.receiverAddress != null
|
|
75
|
-
? (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.receiverAddress.subarray(12)))
|
|
76
|
-
: userAddrHex;
|
|
77
|
-
switch (r.type) {
|
|
78
|
-
case iface_1.QuoteType.EXACT_IN: {
|
|
79
|
-
respPromise = this.axios({
|
|
80
|
-
method: "GET",
|
|
81
|
-
url: "/quote",
|
|
82
|
-
params: {
|
|
83
|
-
fromChain: chIDStr,
|
|
84
|
-
toChain: chIDStr,
|
|
85
|
-
fromToken: inputTokenAddr,
|
|
86
|
-
toToken: outputTokenAddr,
|
|
87
|
-
fromAddress: userAddrHex,
|
|
88
|
-
toAddress: receiverAddrHex,
|
|
89
|
-
fromAmount: r.inputAmount.toString(),
|
|
90
|
-
...LiFiAggregator.COMMON_OPTIONS,
|
|
91
|
-
denyExchanges: this.denyExchangesFor(Number(r.chain.chainID)),
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
case iface_1.QuoteType.EXACT_OUT: {
|
|
97
|
-
respPromise = this.axios({
|
|
98
|
-
method: "GET",
|
|
99
|
-
url: "/quote/toAmount",
|
|
100
|
-
params: {
|
|
101
|
-
fromChain: chIDStr,
|
|
102
|
-
toChain: chIDStr,
|
|
103
|
-
fromToken: inputTokenAddr,
|
|
104
|
-
toToken: outputTokenAddr,
|
|
105
|
-
fromAddress: userAddrHex,
|
|
106
|
-
toAddress: receiverAddrHex,
|
|
107
|
-
toAmount: r.outputAmount.toString(),
|
|
108
|
-
...LiFiAggregator.COMMON_OPTIONS,
|
|
109
|
-
denyExchanges: this.denyExchangesFor(Number(r.chain.chainID)),
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
let resp;
|
|
116
|
-
try {
|
|
117
|
-
resp = await respPromise;
|
|
118
|
-
}
|
|
119
|
-
catch (e) {
|
|
120
|
-
if (e instanceof axios_1.AxiosError && e.isAxiosError) {
|
|
121
|
-
if (e.response?.status === 404 &&
|
|
122
|
-
e.response.data.code === 1002 &&
|
|
123
|
-
e.response.data.message ===
|
|
124
|
-
"No available quotes for the requested transfer") {
|
|
125
|
-
return null;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
throw e;
|
|
129
|
-
}
|
|
130
|
-
const { estimate, transactionRequest: { to, value, data }, action: { fromToken, toToken }, } = resp.data;
|
|
131
|
-
const inputAmountInDecimal = new decimal_js_1.default(estimate.fromAmount)
|
|
132
|
-
.div(decimal_js_1.default.pow(10, fromToken.decimals))
|
|
133
|
-
.toFixed(fromToken.decimals);
|
|
134
|
-
const outputAmountInDecimal = new decimal_js_1.default(estimate.toAmountMin)
|
|
135
|
-
.div(decimal_js_1.default.pow(10, toToken.decimals))
|
|
136
|
-
.toFixed(toToken.decimals);
|
|
137
|
-
return {
|
|
138
|
-
input: {
|
|
139
|
-
amount: inputAmountInDecimal,
|
|
140
|
-
amountRaw: BigInt(estimate.fromAmount),
|
|
141
|
-
contractAddress: inputTokenAddr,
|
|
142
|
-
decimals: fromToken.decimals,
|
|
143
|
-
value: decimal_js_1.default.mul(inputAmountInDecimal, fromToken.priceUSD).toNumber(),
|
|
144
|
-
symbol: fromToken.symbol,
|
|
145
|
-
},
|
|
146
|
-
output: {
|
|
147
|
-
amount: outputAmountInDecimal,
|
|
148
|
-
amountRaw: BigInt(estimate.toAmountMin),
|
|
149
|
-
contractAddress: outputTokenAddr,
|
|
150
|
-
decimals: toToken.decimals,
|
|
151
|
-
value: decimal_js_1.default.mul(outputAmountInDecimal, toToken.priceUSD).toNumber(),
|
|
152
|
-
symbol: toToken.symbol,
|
|
153
|
-
},
|
|
154
|
-
txData: {
|
|
155
|
-
approvalAddress: estimate.approvalAddress,
|
|
156
|
-
tx: {
|
|
157
|
-
to,
|
|
158
|
-
value,
|
|
159
|
-
data,
|
|
160
|
-
},
|
|
161
|
-
},
|
|
162
|
-
};
|
|
163
|
-
}));
|
|
164
|
-
return list.map((item) => {
|
|
165
|
-
switch (item.status) {
|
|
166
|
-
case "fulfilled": {
|
|
167
|
-
return item.value;
|
|
168
|
-
}
|
|
169
|
-
case "rejected": {
|
|
170
|
-
console.error("Caught error in fetching LiFi quotes:", item.reason);
|
|
171
|
-
return null;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
exports.LiFiAggregator = LiFiAggregator;
|