@avail-project/ca-common 1.0.1-beta1 → 2.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.
@@ -7,6 +7,7 @@ const viem_1 = require("viem");
7
7
  const iface_1 = require("./iface");
8
8
  const definition_1 = require("../proto/definition");
9
9
  const data_1 = require("../data");
10
+ const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
10
11
  // https://api.bebop.xyz/{jam|pmm}/chains
11
12
  const ChainNameMapping = new Map(Object.entries({
12
13
  ethereum: 1,
@@ -42,6 +43,7 @@ class BebopAggregator {
42
43
  params: {
43
44
  source: "arcana",
44
45
  },
46
+ timeout: 10_000,
45
47
  });
46
48
  }
47
49
  async getQuotes(requests) {
@@ -104,12 +106,39 @@ class BebopAggregator {
104
106
  return null;
105
107
  }
106
108
  const buyT = bestRoute.quote.buyTokens[outputTokenAddr];
109
+ const sellT = bestRoute.quote.sellTokens[inputTokenAddr];
110
+ const outputAmountInDecimal = new decimal_js_1.default(buyT.minimumAmount)
111
+ .div(decimal_js_1.default.pow(10, buyT.decimals))
112
+ .toFixed(buyT.decimals);
113
+ const inputAmountInDecimal = new decimal_js_1.default(sellT.amount)
114
+ .div(decimal_js_1.default.pow(10, sellT.decimals))
115
+ .toFixed(sellT.decimals);
107
116
  return {
108
- type: r.type,
109
- inputAmount: BigInt(bestRoute.quote.sellTokens[inputTokenAddr].amount),
110
- outputAmountMinimum: BigInt(buyT.minimumAmount),
111
- outputAmountLikely: BigInt(buyT.amount),
112
- originalResponse: bestRoute,
117
+ expiry: bestRoute.quote.expiry,
118
+ input: {
119
+ amount: inputAmountInDecimal,
120
+ amountRaw: BigInt(sellT.amount),
121
+ contractAddress: inputTokenAddr,
122
+ decimals: sellT.decimals,
123
+ value: decimal_js_1.default.mul(inputAmountInDecimal, sellT.priceUsd).toNumber(),
124
+ symbol: sellT.symbol,
125
+ },
126
+ output: {
127
+ amount: outputAmountInDecimal,
128
+ amountRaw: BigInt(buyT.minimumAmount),
129
+ contractAddress: outputTokenAddr,
130
+ decimals: buyT.decimals,
131
+ value: decimal_js_1.default.mul(buyT.priceUsd, outputAmountInDecimal).toNumber(),
132
+ symbol: buyT.symbol,
133
+ },
134
+ txData: {
135
+ approvalAddress: bestRoute.quote.approvalTarget,
136
+ tx: {
137
+ to: bestRoute.quote.tx.to,
138
+ value: bestRoute.quote.tx.value,
139
+ data: bestRoute.quote.tx.data,
140
+ },
141
+ },
113
142
  };
114
143
  }));
115
144
  return list.map((item) => {
@@ -3,6 +3,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./iface"), exports);
5
5
  tslib_1.__exportStar(require("./lifi-agg"), exports);
6
- tslib_1.__exportStar(require("./yieldyak-agg"), exports);
7
6
  tslib_1.__exportStar(require("./bebop-agg"), exports);
8
7
  tslib_1.__exportStar(require("./autochoice"), exports);
@@ -6,11 +6,13 @@ const axios_1 = tslib_1.__importStar(require("axios"));
6
6
  const viem_1 = require("viem");
7
7
  const iface_1 = require("./iface");
8
8
  const definition_1 = require("../proto/definition");
9
+ const decimal_js_1 = tslib_1.__importDefault(require("decimal.js"));
9
10
  class LiFiAggregator {
10
11
  static BASE_URL_V1 = "https://li.quest/v1";
11
12
  static COMMON_OPTIONS = {
12
13
  denyExchanges: "openocean",
13
14
  slippage: "0.01",
15
+ skipSimulation: true,
14
16
  };
15
17
  axios;
16
18
  constructor(apiKey) {
@@ -19,6 +21,7 @@ class LiFiAggregator {
19
21
  headers: {
20
22
  "x-lifi-api-key": apiKey,
21
23
  },
24
+ timeout: 10_000,
22
25
  });
23
26
  }
24
27
  async getQuotes(requests) {
@@ -80,12 +83,38 @@ class LiFiAggregator {
80
83
  }
81
84
  throw e;
82
85
  }
86
+ const { estimate, transactionRequest: { to, value, data }, action: { fromToken, toToken }, } = resp.data;
87
+ const inputAmountInDecimal = new decimal_js_1.default(estimate.fromAmount)
88
+ .div(decimal_js_1.default.pow(10, fromToken.decimals))
89
+ .toFixed(fromToken.decimals);
90
+ const outputAmountInDecimal = new decimal_js_1.default(estimate.toAmountMin)
91
+ .div(decimal_js_1.default.pow(10, toToken.decimals))
92
+ .toFixed(toToken.decimals);
83
93
  return {
84
- type: r.type,
85
- inputAmount: BigInt(resp.data.estimate.fromAmount),
86
- outputAmountMinimum: BigInt(resp.data.estimate.toAmountMin),
87
- outputAmountLikely: BigInt(resp.data.estimate.toAmount),
88
- originalResponse: resp.data,
94
+ input: {
95
+ amount: inputAmountInDecimal,
96
+ amountRaw: BigInt(estimate.fromAmount),
97
+ contractAddress: inputTokenAddr,
98
+ decimals: fromToken.decimals,
99
+ value: decimal_js_1.default.mul(inputAmountInDecimal, fromToken.priceUSD).toNumber(),
100
+ symbol: fromToken.symbol,
101
+ },
102
+ output: {
103
+ amount: outputAmountInDecimal,
104
+ amountRaw: BigInt(estimate.toAmountMin),
105
+ contractAddress: outputTokenAddr,
106
+ decimals: toToken.decimals,
107
+ value: decimal_js_1.default.mul(outputAmountInDecimal, toToken.priceUSD).toNumber(),
108
+ symbol: toToken.symbol,
109
+ },
110
+ txData: {
111
+ approvalAddress: estimate.approvalAddress,
112
+ tx: {
113
+ to,
114
+ value,
115
+ data,
116
+ },
117
+ },
89
118
  };
90
119
  }));
91
120
  return list.map((item) => {
@@ -601,10 +601,10 @@ const RawData = [
601
601
  Currencies: [
602
602
  {
603
603
  CurrencyID: 1,
604
- TokenContractAddress: "0x000000000000000000000000590cb8868c6DeBc12CCd42E837042659cfB91504",
604
+ TokenContractAddress: "0x000000000000000000000000FAfDdbb3FC7688494971a79cc65DCa3EF82079E7",
605
605
  PermitVariant: PermitVariant.EIP2612Canonical,
606
- PermitContractVersion: 2,
607
- TokenDecimals: 6,
606
+ PermitContractVersion: 1,
607
+ TokenDecimals: 18,
608
608
  IsGasToken: false,
609
609
  },
610
610
  {
@@ -614,6 +614,14 @@ const RawData = [
614
614
  TokenDecimals: 18,
615
615
  IsGasToken: true,
616
616
  },
617
+ {
618
+ CurrencyID: 2,
619
+ TokenContractAddress: "0x000000000000000000000000B8CE59FC3717ada4C02eaDF9682A9e934F625ebb",
620
+ PermitVariant: PermitVariant.EIP2612Canonical,
621
+ PermitContractVersion: 1,
622
+ TokenDecimals: 6,
623
+ IsGasToken: false,
624
+ },
617
625
  ],
618
626
  },
619
627
  //citrea mainnet
@@ -638,7 +646,7 @@ const RawData = [
638
646
  IsGasToken: false,
639
647
  },
640
648
  {
641
- CurrencyID: 3,
649
+ CurrencyID: 21,
642
650
  TokenContractAddress: "0x0000000000000000000000000000000000000000000000000000000000000000",
643
651
  PermitVariant: PermitVariant.Unsupported,
644
652
  TokenDecimals: 18,
@@ -753,10 +761,7 @@ export const RPCURLMap = new ChainIDKeyedMap([
753
761
  new OmniversalChainID(Universe.ETHEREUM, 50104),
754
762
  "https://sophon.gateway.tenderly.co/1d4STFT7zmG0vM5QowibCw",
755
763
  ],
756
- [
757
- new OmniversalChainID(Universe.ETHEREUM, 56),
758
- "https://rpcs.avail.so/bsc",
759
- ],
764
+ [new OmniversalChainID(Universe.ETHEREUM, 56), "https://rpcs.avail.so/bsc"],
760
765
  [
761
766
  new OmniversalChainID(Universe.ETHEREUM, 10143),
762
767
  "https://rpcs.avail.so/monadtestnet",
@@ -14,6 +14,7 @@ export var CurrencyID;
14
14
  CurrencyID[CurrencyID["SOPH"] = 18] = "SOPH";
15
15
  CurrencyID[CurrencyID["TRX"] = 19] = "TRX";
16
16
  CurrencyID[CurrencyID["MON"] = 20] = "MON";
17
+ CurrencyID[CurrencyID["CBTC"] = 21] = "CBTC";
17
18
  })(CurrencyID || (CurrencyID = {}));
18
19
  export class Currency {
19
20
  currencyID;
@@ -65,6 +65,10 @@ const dataSets = new Map([
65
65
  new OmniversalChainID(Universe.ETHEREUM, 4326),
66
66
  "0x10B69f0E3c21C1187526940A615959E9ee6012F9",
67
67
  ],
68
+ [
69
+ new OmniversalChainID(Universe.ETHEREUM, 4114),
70
+ "0x10B69f0E3c21C1187526940A615959E9ee6012F9",
71
+ ],
68
72
  [
69
73
  new OmniversalChainID(Universe.ETHEREUM, 534352),
70
74
  "0x111111eA4f8BdfB5AE22c37ebC3eE17b82072F57",
@@ -77,6 +81,22 @@ const dataSets = new Map([
77
81
  new OmniversalChainID(Universe.TRON, 728126428),
78
82
  "0x46de8c7e6f1da4dd851b62c20b78971f230fca5b",
79
83
  ],
84
+ [
85
+ new OmniversalChainID(Universe.ETHEREUM, 1),
86
+ "0xAc73E77b4FE9BBAAA35C7147DC3Fd5286929A746",
87
+ ],
88
+ [
89
+ new OmniversalChainID(Universe.ETHEREUM, 143),
90
+ "0xAc73E77b4FE9BBAAA35C7147DC3Fd5286929A746",
91
+ ],
92
+ [
93
+ new OmniversalChainID(Universe.ETHEREUM, 999),
94
+ "0xAc73E77b4FE9BBAAA35C7147DC3Fd5286929A746",
95
+ ],
96
+ [
97
+ new OmniversalChainID(Universe.ETHEREUM, 43114),
98
+ "0xAc73E77b4FE9BBAAA35C7147DC3Fd5286929A746",
99
+ ],
80
100
  ],
81
101
  ],
82
102
  [
@@ -130,6 +150,14 @@ const dataSets = new Map([
130
150
  new OmniversalChainID(Universe.ETHEREUM, 143),
131
151
  "0xC0DED5d7F424276c821AF21F68E1e663bC671C3D",
132
152
  ],
153
+ [
154
+ new OmniversalChainID(Universe.ETHEREUM, 4114),
155
+ "0xAc73E77b4FE9BBAAA35C7147DC3Fd5286929A746",
156
+ ],
157
+ [
158
+ new OmniversalChainID(Universe.ETHEREUM, 4326),
159
+ "0x5f02ED27A20BbDbB90EEf98670fA36c36fc02D12",
160
+ ],
133
161
  ],
134
162
  ],
135
163
  [