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