@avail-project/ca-common 2.2.1 → 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 (92) 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 -570
  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 -8
  33. package/dist/cjs/xcs/lifi-agg.js +0 -155
  34. package/dist/esm/_polyfill.js +0 -143
  35. package/dist/esm/balances/ub-api.js +0 -21
  36. package/dist/esm/cosmos/index.js +0 -26
  37. package/dist/esm/data/chaindata.js +0 -785
  38. package/dist/esm/data/chainid.js +0 -87
  39. package/dist/esm/data/currency.js +0 -73
  40. package/dist/esm/data/index.js +0 -4
  41. package/dist/esm/data/utils.js +0 -34
  42. package/dist/esm/evmabi/erc20.abi.js +0 -346
  43. package/dist/esm/evmabi/fibrousrouter.abi.js +0 -38
  44. package/dist/esm/evmabi/index.js +0 -4
  45. package/dist/esm/evmabi/vault.abi.js +0 -1018
  46. package/dist/esm/evmabi/yakaggregator.abi.js +0 -272
  47. package/dist/esm/index.js +0 -13
  48. package/dist/esm/permitutils/index.js +0 -181
  49. package/dist/esm/proto/client.js +0 -11
  50. package/dist/esm/proto/definition.js +0 -4122
  51. package/dist/esm/proto/grpc.js +0 -292
  52. package/dist/esm/rff/rff.js +0 -38
  53. package/dist/esm/types/binarytypes.js +0 -1
  54. package/dist/esm/types/index.js +0 -2
  55. package/dist/esm/types/msgpack-axios.js +0 -18
  56. package/dist/esm/vaultcontracts/index.js +0 -1
  57. package/dist/esm/vaultcontracts/vaultcontracts.js +0 -218
  58. package/dist/esm/xcs/autochoice.js +0 -554
  59. package/dist/esm/xcs/bebop-agg.js +0 -151
  60. package/dist/esm/xcs/fibrous-agg.js +0 -150
  61. package/dist/esm/xcs/iface.js +0 -10
  62. package/dist/esm/xcs/index.js +0 -5
  63. package/dist/esm/xcs/lifi-agg.js +0 -150
  64. package/dist/types/_polyfill.d.ts +0 -1
  65. package/dist/types/balances/ub-api.d.ts +0 -14
  66. package/dist/types/cosmos/index.d.ts +0 -6
  67. package/dist/types/data/chaindata.d.ts +0 -20
  68. package/dist/types/data/chainid.d.ts +0 -31
  69. package/dist/types/data/currency.d.ts +0 -30
  70. package/dist/types/data/index.d.ts +0 -4
  71. package/dist/types/data/utils.d.ts +0 -10
  72. package/dist/types/evmabi/erc20.abi.d.ts +0 -264
  73. package/dist/types/evmabi/fibrousrouter.abi.d.ts +0 -77
  74. package/dist/types/evmabi/index.d.ts +0 -4
  75. package/dist/types/evmabi/vault.abi.d.ts +0 -785
  76. package/dist/types/evmabi/yakaggregator.abi.d.ts +0 -298
  77. package/dist/types/permitutils/index.d.ts +0 -13
  78. package/dist/types/proto/client.d.ts +0 -2
  79. package/dist/types/proto/definition.d.ts +0 -382
  80. package/dist/types/proto/grpc.d.ts +0 -75
  81. package/dist/types/rff/rff.d.ts +0 -9
  82. package/dist/types/types/binarytypes.d.ts +0 -1
  83. package/dist/types/types/index.d.ts +0 -2
  84. package/dist/types/types/msgpack-axios.d.ts +0 -1
  85. package/dist/types/vaultcontracts/index.d.ts +0 -22
  86. package/dist/types/vaultcontracts/vaultcontracts.d.ts +0 -8
  87. package/dist/types/xcs/autochoice.d.ts +0 -105
  88. package/dist/types/xcs/bebop-agg.d.ts +0 -104
  89. package/dist/types/xcs/fibrous-agg.d.ts +0 -56
  90. package/dist/types/xcs/iface.d.ts +0 -69
  91. package/dist/types/xcs/index.d.ts +0 -5
  92. package/dist/types/xcs/lifi-agg.d.ts +0 -39
@@ -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).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(buyT.priceUsd, outputAmountInDecimal).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;
@@ -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 = {}));
@@ -1,8 +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);
@@ -1,155 +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
- static COMMON_OPTIONS = {
27
- denyExchanges: "openocean",
28
- slippage: "0.01",
29
- skipSimulation: true,
30
- };
31
- axios;
32
- constructor(apiKey) {
33
- this.axios = axios_1.default.create({
34
- baseURL: LiFiAggregator.BASE_URL_V1,
35
- headers: {
36
- "x-lifi-api-key": apiKey,
37
- },
38
- timeout: 10_000,
39
- });
40
- }
41
- async getQuotes(requests) {
42
- const list = await Promise.allSettled(requests.map(async (r) => {
43
- if (r.chain.universe !== definition_1.Universe.ETHEREUM) {
44
- return null;
45
- }
46
- if (!ALLOWED_CHAINS.has(Number(r.chain.chainID))) {
47
- return null;
48
- }
49
- let respPromise;
50
- const chIDStr = r.chain.chainID.toString();
51
- const inputTokenAddr = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.inputToken.subarray(12)));
52
- const outputTokenAddr = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.outputToken.subarray(12)));
53
- const userAddrHex = (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.userAddress.subarray(12)));
54
- const receiverAddrHex = r.receiverAddress != null
55
- ? (0, viem_1.getAddress)((0, viem_1.bytesToHex)(r.receiverAddress.subarray(12)))
56
- : userAddrHex;
57
- switch (r.type) {
58
- case iface_1.QuoteType.EXACT_IN: {
59
- respPromise = this.axios({
60
- method: "GET",
61
- url: "/quote",
62
- params: {
63
- fromChain: chIDStr,
64
- toChain: chIDStr,
65
- fromToken: inputTokenAddr,
66
- toToken: outputTokenAddr,
67
- fromAddress: userAddrHex,
68
- toAddress: receiverAddrHex,
69
- fromAmount: r.inputAmount.toString(),
70
- ...LiFiAggregator.COMMON_OPTIONS,
71
- },
72
- });
73
- break;
74
- }
75
- case iface_1.QuoteType.EXACT_OUT: {
76
- respPromise = this.axios({
77
- method: "GET",
78
- url: "/quote/toAmount",
79
- params: {
80
- fromChain: chIDStr,
81
- toChain: chIDStr,
82
- fromToken: inputTokenAddr,
83
- toToken: outputTokenAddr,
84
- fromAddress: userAddrHex,
85
- toAddress: receiverAddrHex,
86
- toAmount: r.outputAmount.toString(),
87
- ...LiFiAggregator.COMMON_OPTIONS,
88
- },
89
- });
90
- break;
91
- }
92
- }
93
- let resp;
94
- try {
95
- resp = await respPromise;
96
- }
97
- catch (e) {
98
- if (e instanceof axios_1.AxiosError && e.isAxiosError) {
99
- if (e.response?.status === 404 &&
100
- e.response.data.code === 1002 &&
101
- e.response.data.message ===
102
- "No available quotes for the requested transfer") {
103
- return null;
104
- }
105
- }
106
- throw e;
107
- }
108
- const { estimate, transactionRequest: { to, value, data }, action: { fromToken, toToken }, } = resp.data;
109
- const inputAmountInDecimal = new decimal_js_1.default(estimate.fromAmount)
110
- .div(decimal_js_1.default.pow(10, fromToken.decimals))
111
- .toFixed(fromToken.decimals);
112
- const outputAmountInDecimal = new decimal_js_1.default(estimate.toAmountMin)
113
- .div(decimal_js_1.default.pow(10, toToken.decimals))
114
- .toFixed(toToken.decimals);
115
- return {
116
- input: {
117
- amount: inputAmountInDecimal,
118
- amountRaw: BigInt(estimate.fromAmount),
119
- contractAddress: inputTokenAddr,
120
- decimals: fromToken.decimals,
121
- value: decimal_js_1.default.mul(inputAmountInDecimal, fromToken.priceUSD).toNumber(),
122
- symbol: fromToken.symbol,
123
- },
124
- output: {
125
- amount: outputAmountInDecimal,
126
- amountRaw: BigInt(estimate.toAmountMin),
127
- contractAddress: outputTokenAddr,
128
- decimals: toToken.decimals,
129
- value: decimal_js_1.default.mul(outputAmountInDecimal, toToken.priceUSD).toNumber(),
130
- symbol: toToken.symbol,
131
- },
132
- txData: {
133
- approvalAddress: estimate.approvalAddress,
134
- tx: {
135
- to,
136
- value,
137
- data,
138
- },
139
- },
140
- };
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 LiFi quotes:", item.reason);
149
- return null;
150
- }
151
- }
152
- });
153
- }
154
- }
155
- exports.LiFiAggregator = LiFiAggregator;
@@ -1,143 +0,0 @@
1
- import * as bufferModule from "buffer";
2
- import { Buffer as DefaultBuffer } from "buffer";
3
- const globalScope = globalThis;
4
- let patched = false;
5
- function collectBufferCtors() {
6
- const candidates = new Set();
7
- if (typeof DefaultBuffer === "function") {
8
- candidates.add(DefaultBuffer);
9
- }
10
- const mod = bufferModule;
11
- if (typeof mod?.Buffer === "function") {
12
- candidates.add(mod.Buffer);
13
- }
14
- const defaultExport = mod?.default;
15
- if (typeof defaultExport === "function") {
16
- candidates.add(defaultExport);
17
- }
18
- else if (defaultExport &&
19
- typeof defaultExport === "object" &&
20
- typeof defaultExport.Buffer === "function") {
21
- candidates.add(defaultExport.Buffer);
22
- }
23
- if (typeof globalScope.Buffer === "function") {
24
- candidates.add(globalScope.Buffer);
25
- }
26
- return Array.from(candidates);
27
- }
28
- function assertOffset(buffer, offset) {
29
- const numericOffset = Number(offset);
30
- if (!Number.isFinite(numericOffset)) {
31
- throw new TypeError("Offset must be a finite number");
32
- }
33
- const normalized = numericOffset >>> 0;
34
- if (normalized !== numericOffset) {
35
- throw new RangeError("Offset must be a non-negative integer");
36
- }
37
- if (normalized + 4 > buffer.length) {
38
- throw new RangeError("Offset out of bounds");
39
- }
40
- return normalized;
41
- }
42
- function fallbackWriteUint32BE(value, offset = 0) {
43
- const o = assertOffset(this, offset);
44
- const normalized = Number(value) >>> 0;
45
- this[o] = (normalized >>> 24) & 0xff;
46
- this[o + 1] =
47
- (normalized >>> 16) & 0xff;
48
- this[o + 2] =
49
- (normalized >>> 8) & 0xff;
50
- this[o + 3] = normalized & 0xff;
51
- return o + 4;
52
- }
53
- function fallbackWriteUint32LE(value, offset = 0) {
54
- const o = assertOffset(this, offset);
55
- const normalized = Number(value) >>> 0;
56
- this[o] = normalized & 0xff;
57
- this[o + 1] =
58
- (normalized >>> 8) & 0xff;
59
- this[o + 2] =
60
- (normalized >>> 16) & 0xff;
61
- this[o + 3] =
62
- (normalized >>> 24) & 0xff;
63
- return o + 4;
64
- }
65
- function fallbackReadUint32BE(offset = 0) {
66
- const o = assertOffset(this, offset);
67
- const store = this;
68
- return ((store[o] * 0x1000000 +
69
- ((store[o + 1] << 16) | (store[o + 2] << 8) | store[o + 3])) >>>
70
- 0);
71
- }
72
- function fallbackReadUint32LE(offset = 0) {
73
- const o = assertOffset(this, offset);
74
- const store = this;
75
- return ((store[o] |
76
- (store[o + 1] << 8) |
77
- (store[o + 2] << 16) |
78
- (store[o + 3] * 0x1000000)) >>>
79
- 0);
80
- }
81
- function aliasOrDefine(proto, alias, canonical, fallback) {
82
- const aliasKey = alias;
83
- const canonicalKey = canonical;
84
- const existingAlias = proto[aliasKey];
85
- if (typeof existingAlias === "function") {
86
- return;
87
- }
88
- const canonicalFn = proto[canonicalKey];
89
- if (typeof canonicalFn === "function") {
90
- Object.defineProperty(proto, aliasKey, {
91
- value: canonicalFn,
92
- writable: true,
93
- configurable: true,
94
- });
95
- return;
96
- }
97
- Object.defineProperty(proto, aliasKey, {
98
- value: fallback,
99
- writable: true,
100
- configurable: true,
101
- });
102
- }
103
- function patchPrototype(bufferCtor) {
104
- const proto = bufferCtor.prototype;
105
- if (!proto) {
106
- return;
107
- }
108
- aliasOrDefine(proto, "writeUint32BE", "writeUInt32BE", fallbackWriteUint32BE);
109
- aliasOrDefine(proto, "writeUint32LE", "writeUInt32LE", fallbackWriteUint32LE);
110
- aliasOrDefine(proto, "readUint32BE", "readUInt32BE", fallbackReadUint32BE);
111
- aliasOrDefine(proto, "readUint32LE", "readUInt32LE", fallbackReadUint32LE);
112
- }
113
- function ensureProcessEnv() {
114
- if (!globalScope.process) {
115
- globalScope.process = { env: { NODE_ENV: "production" } };
116
- return;
117
- }
118
- const processValue = globalScope.process;
119
- if (!processValue.env) {
120
- processValue.env = { NODE_ENV: "production" };
121
- return;
122
- }
123
- if (typeof processValue.env.NODE_ENV === "undefined") {
124
- processValue.env.NODE_ENV = "production";
125
- }
126
- }
127
- export function ensureBufferPolyfill() {
128
- if (patched) {
129
- return;
130
- }
131
- const candidates = collectBufferCtors();
132
- candidates.forEach(patchPrototype);
133
- const preferred = candidates[0];
134
- if (preferred &&
135
- (typeof globalScope.Buffer !== "function" ||
136
- typeof globalScope.Buffer.prototype?.writeUint32BE !==
137
- "function")) {
138
- globalScope.Buffer = preferred;
139
- }
140
- ensureProcessEnv();
141
- patched = true;
142
- }
143
- ensureBufferPolyfill();
@@ -1,21 +0,0 @@
1
- import Decimal from "decimal.js";
2
- import { Universe } from "../proto/definition";
3
- import { msgpackableAxios } from "../types";
4
- import { OmniversalChainID } from "../data";
5
- import { bytesToHex } from "viem";
6
- export async function getBalances(vscURL, universe, address) {
7
- const resp = await msgpackableAxios({
8
- baseURL: vscURL,
9
- url: `/api/v1/get-balance/${Universe[universe]}/${bytesToHex(address)}`,
10
- });
11
- const { data } = resp;
12
- return data.balances.map(bal => ({
13
- chainID: new OmniversalChainID(bal.universe, bal.chain_id),
14
- totalValue: new Decimal(bal.total_usd),
15
- currencywise: bal.currencies.map(cur => ({
16
- tokenAddress: cur.token_address,
17
- amount: new Decimal(cur.balance),
18
- value: new Decimal(cur.value)
19
- }))
20
- }));
21
- }
@@ -1,26 +0,0 @@
1
- import { Registry as CosmosRegistry, DirectSecp256k1Wallet, } from "@cosmjs/proto-signing";
2
- import { defaultRegistryTypes, SigningStargateClient, } from "@cosmjs/stargate";
3
- import { hexToBytes } from "viem";
4
- import { MsgCreateRequestForFunds, MsgCreateRequestForFundsResponse, MsgCreateSolverData, MsgCreateSolverDataResponse, MsgDoubleCheckTx, MsgRefundReq, MsgRefundReqResponse, MsgUpdateSolverData, } from "../proto/definition";
5
- export const Registry = new CosmosRegistry(defaultRegistryTypes);
6
- {
7
- Registry.register("/xarchain.chainabstraction.MsgCreateSolverData", MsgCreateSolverData);
8
- Registry.register("/xarchain.chainabstraction.MsgCreateSolverDataResponse", MsgCreateSolverDataResponse);
9
- Registry.register("/xarchain.chainabstraction.MsgUpdateSolverData", MsgUpdateSolverData);
10
- Registry.register("/xarchain.chainabstraction.MsgUpdateSolverDataResponse", MsgCreateSolverDataResponse);
11
- Registry.register("/xarchain.chainabstraction.MsgCreateRequestForFunds", MsgCreateRequestForFunds);
12
- Registry.register("/xarchain.chainabstraction.MsgCreateRequestForFundsResponse", MsgCreateRequestForFundsResponse);
13
- Registry.register("/xarchain.chainabstraction.MsgRefundReq", MsgRefundReq);
14
- Registry.register("/xarchain.chainabstraction.MsgRefundReqResponse", MsgRefundReqResponse);
15
- Registry.register("/xarchain.chainabstraction.MsgDoubleCheckTx", MsgDoubleCheckTx);
16
- }
17
- export function createCosmosWallet(privateKey) {
18
- const pkBytes = typeof privateKey === "string" ? hexToBytes(privateKey) : privateKey;
19
- return DirectSecp256k1Wallet.fromKey(pkBytes, "arcana");
20
- }
21
- export function createCosmosClient(signer, endpoint, options) {
22
- return SigningStargateClient.connectWithSigner(endpoint, signer, {
23
- registry: Registry,
24
- ...options,
25
- });
26
- }