@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,87 +0,0 @@
1
- import { ensureBufferPolyfill } from "../_polyfill";
2
- import { bytesToBigInt, bytesToHex, hexToBigInt, hexToBytes, toBytes, toHex, } from "viem";
3
- import { universeFromJSON, universeToJSON, } from "../proto/definition";
4
- import { convertToBufferIfNecessary } from "./utils";
5
- ensureBufferPolyfill();
6
- export function encodeChainID36(universe, chainID) {
7
- let chainIDB;
8
- if (Buffer.isBuffer(chainID) || chainID instanceof Uint8Array) {
9
- chainIDB = chainID;
10
- }
11
- else {
12
- chainIDB = toBytes(chainID);
13
- }
14
- const buf = Buffer.alloc(36);
15
- buf.writeUInt32BE(universe);
16
- buf.set(chainIDB, 4 + (32 - chainIDB.length));
17
- return buf;
18
- }
19
- export class OmniversalChainID {
20
- universe;
21
- chainID;
22
- binaryForm;
23
- constructor(universe, chainID) {
24
- this.universe = universe;
25
- if (typeof chainID === "bigint") {
26
- this.chainID = chainID;
27
- }
28
- else if (typeof chainID === "number" || typeof chainID === "string") {
29
- this.chainID = BigInt(chainID);
30
- }
31
- else if (chainID instanceof Uint8Array) {
32
- this.chainID = bytesToBigInt(chainID);
33
- }
34
- this.binaryForm = encodeChainID36(this.universe, this.chainID);
35
- }
36
- toString() {
37
- return universeToJSON(this.universe) + "_" + this.chainID.toString(10);
38
- }
39
- toJSON() {
40
- return {
41
- universe: universeToJSON(this.universe),
42
- chainID: toHex(this.chainID),
43
- };
44
- }
45
- static fromJSON(input) {
46
- return new OmniversalChainID(universeFromJSON(input.universe), hexToBigInt(input.chainID));
47
- }
48
- static fromChainID36(_input) {
49
- const input = convertToBufferIfNecessary(_input);
50
- const univID = input.readUInt32BE(0);
51
- const rest = input.subarray(4);
52
- return new OmniversalChainID(univID, rest);
53
- }
54
- // Do not modify the returned buffer. Make a copy if necessary.
55
- toBytes() {
56
- return this.binaryForm;
57
- }
58
- equals(rhs) {
59
- return this.universe === rhs.universe && this.chainID === rhs.chainID;
60
- }
61
- static equals(lhs, rhs) {
62
- return lhs.equals(rhs);
63
- }
64
- }
65
- export class ChainIDKeyedMap {
66
- map;
67
- constructor(entries = null) {
68
- this.map = new Map(entries != null
69
- ? entries.map((e) => [bytesToHex(e[0].toBytes()), e[1]])
70
- : null);
71
- }
72
- get(key) {
73
- return this.map.get(bytesToHex(key.toBytes()));
74
- }
75
- set(key, value) {
76
- this.map.set(bytesToHex(key.toBytes()), value);
77
- return this;
78
- }
79
- getFromChainID36(key) {
80
- return this.map.get(bytesToHex(key));
81
- }
82
- *entries() {
83
- for (const [key, value] of this.map.entries()) {
84
- yield [OmniversalChainID.fromChainID36(hexToBytes(key)), value];
85
- }
86
- }
87
- }
@@ -1,73 +0,0 @@
1
- import { bytesToBigInt, toBytes } from "viem";
2
- import Decimal from "decimal.js";
3
- import { zeroExtendBufToGivenSize } from "./utils";
4
- export var CurrencyID;
5
- (function (CurrencyID) {
6
- CurrencyID[CurrencyID["USDC"] = 1] = "USDC";
7
- CurrencyID[CurrencyID["USDT"] = 2] = "USDT";
8
- CurrencyID[CurrencyID["ETH"] = 3] = "ETH";
9
- CurrencyID[CurrencyID["POL"] = 4] = "POL";
10
- CurrencyID[CurrencyID["AVAX"] = 5] = "AVAX";
11
- CurrencyID[CurrencyID["BNB"] = 6] = "BNB";
12
- CurrencyID[CurrencyID["HYPE"] = 16] = "HYPE";
13
- CurrencyID[CurrencyID["KAIA"] = 17] = "KAIA";
14
- CurrencyID[CurrencyID["SOPH"] = 18] = "SOPH";
15
- CurrencyID[CurrencyID["TRX"] = 19] = "TRX";
16
- CurrencyID[CurrencyID["MON"] = 20] = "MON";
17
- CurrencyID[CurrencyID["CBTC"] = 21] = "CBTC";
18
- })(CurrencyID || (CurrencyID = {}));
19
- export class Currency {
20
- currencyID;
21
- decimals;
22
- permitVariant;
23
- permitContractVersion;
24
- isGasToken;
25
- // this is always 32 byte long
26
- tokenAddress;
27
- /* This is the ratio between one unit to the smallest unit used.
28
-
29
- For example, USDC, which has a ‘decimals’ value of 6, is designed so that 1 USDC = 10⁶ μUSDC, which is the smallest indivisible amount representable.
30
- */
31
- oneUnitToAtomicUnitRatio;
32
- constructor(currencyID, tokenAddress, decimals, permitVariant, permitContractVersion = 0, isGasToken) {
33
- this.currencyID = currencyID;
34
- this.decimals = decimals;
35
- this.permitVariant = permitVariant;
36
- this.permitContractVersion = permitContractVersion;
37
- this.isGasToken = isGasToken;
38
- if (typeof tokenAddress === "string") {
39
- this.tokenAddress = zeroExtendBufToGivenSize(toBytes(tokenAddress), 32);
40
- }
41
- else if (tokenAddress instanceof Uint8Array) {
42
- this.tokenAddress = zeroExtendBufToGivenSize(tokenAddress, 32);
43
- }
44
- else if (Array.isArray(tokenAddress) &&
45
- tokenAddress.length >= 1 &&
46
- typeof tokenAddress[0] === "number") {
47
- this.tokenAddress = zeroExtendBufToGivenSize(Buffer.from(tokenAddress), 32);
48
- }
49
- this.oneUnitToAtomicUnitRatio = Decimal.pow(10, decimals);
50
- }
51
- convertUnitsToAmountDecimal(input) {
52
- let rawunits;
53
- if (typeof input === "bigint") {
54
- rawunits = input.toString(10);
55
- }
56
- else if (typeof input === "number") {
57
- rawunits = input.toString();
58
- }
59
- else if (input instanceof Uint8Array) {
60
- rawunits = bytesToBigInt(input).toString(10);
61
- }
62
- else if (typeof input === "string") {
63
- rawunits = input;
64
- }
65
- else {
66
- throw new Error("Invalid input");
67
- }
68
- return Decimal.div(rawunits, this.oneUnitToAtomicUnitRatio);
69
- }
70
- convertAmountToUnitsInBinary(input) {
71
- return Buffer.from(toBytes(input.mul(this.oneUnitToAtomicUnitRatio).ceil().toHex()));
72
- }
73
- }
@@ -1,4 +0,0 @@
1
- export * from './chaindata';
2
- export * from './chainid';
3
- export * from './currency';
4
- export * from './utils';
@@ -1,34 +0,0 @@
1
- import { pad, toHex } from "viem";
2
- import Decimal from "decimal.js";
3
- export function convertToBufferIfNecessary(buf) {
4
- return Buffer.isBuffer(buf) ? buf : Buffer.from(buf);
5
- }
6
- export function zeroExtendBufToGivenSize(buf, size = 32) {
7
- if (buf.length === size) {
8
- return convertToBufferIfNecessary(buf);
9
- }
10
- if (buf.length > size) {
11
- return convertToBufferIfNecessary(buf.subarray(0, size));
12
- }
13
- const out = Buffer.alloc(size);
14
- out.set(buf, size - buf.length);
15
- return out;
16
- }
17
- export function ezPadTo32Hex(input) {
18
- return pad(typeof input !== "string" ? toHex(input) : input, {
19
- dir: "left",
20
- size: 32,
21
- });
22
- }
23
- export function convertDecimalToBigInt(dec) {
24
- return BigInt(dec.ceil().toFixed());
25
- }
26
- export function convertBigIntToDecimal(big) {
27
- return new Decimal(big.toString(10));
28
- }
29
- export function maxByBigInt(items, getValue) {
30
- return items.reduce((m, e) => getValue(e) > getValue(m) ? e : m);
31
- }
32
- export function minByBigInt(items, getValue) {
33
- return items.reduce((m, e) => getValue(e) < getValue(m) ? e : m);
34
- }
@@ -1,346 +0,0 @@
1
- export const ERC20ABI = [
2
- {
3
- constant: true,
4
- inputs: [],
5
- name: "name",
6
- outputs: [
7
- {
8
- name: "",
9
- type: "string",
10
- },
11
- ],
12
- payable: false,
13
- stateMutability: "view",
14
- type: "function",
15
- },
16
- {
17
- constant: false,
18
- inputs: [
19
- {
20
- name: "_spender",
21
- type: "address",
22
- },
23
- {
24
- name: "_value",
25
- type: "uint256",
26
- },
27
- ],
28
- name: "approve",
29
- outputs: [
30
- {
31
- name: "",
32
- type: "bool",
33
- },
34
- ],
35
- payable: false,
36
- stateMutability: "nonpayable",
37
- type: "function",
38
- },
39
- {
40
- constant: true,
41
- inputs: [],
42
- name: "totalSupply",
43
- outputs: [
44
- {
45
- name: "",
46
- type: "uint256",
47
- },
48
- ],
49
- payable: false,
50
- stateMutability: "view",
51
- type: "function",
52
- },
53
- {
54
- constant: false,
55
- inputs: [
56
- {
57
- name: "_from",
58
- type: "address",
59
- },
60
- {
61
- name: "_to",
62
- type: "address",
63
- },
64
- {
65
- name: "_value",
66
- type: "uint256",
67
- },
68
- ],
69
- name: "transferFrom",
70
- outputs: [
71
- {
72
- name: "",
73
- type: "bool",
74
- },
75
- ],
76
- payable: false,
77
- stateMutability: "nonpayable",
78
- type: "function",
79
- },
80
- {
81
- constant: true,
82
- inputs: [],
83
- name: "decimals",
84
- outputs: [
85
- {
86
- name: "",
87
- type: "uint8",
88
- },
89
- ],
90
- payable: false,
91
- stateMutability: "view",
92
- type: "function",
93
- },
94
- {
95
- constant: true,
96
- inputs: [
97
- {
98
- name: "_owner",
99
- type: "address",
100
- },
101
- ],
102
- name: "balanceOf",
103
- outputs: [
104
- {
105
- name: "balance",
106
- type: "uint256",
107
- },
108
- ],
109
- payable: false,
110
- stateMutability: "view",
111
- type: "function",
112
- },
113
- {
114
- constant: true,
115
- inputs: [],
116
- name: "symbol",
117
- outputs: [
118
- {
119
- name: "",
120
- type: "string",
121
- },
122
- ],
123
- payable: false,
124
- stateMutability: "view",
125
- type: "function",
126
- },
127
- {
128
- constant: false,
129
- inputs: [
130
- {
131
- name: "_to",
132
- type: "address",
133
- },
134
- {
135
- name: "_value",
136
- type: "uint256",
137
- },
138
- ],
139
- name: "transfer",
140
- outputs: [
141
- {
142
- name: "",
143
- type: "bool",
144
- },
145
- ],
146
- payable: false,
147
- stateMutability: "nonpayable",
148
- type: "function",
149
- },
150
- {
151
- constant: true,
152
- inputs: [
153
- {
154
- name: "_owner",
155
- type: "address",
156
- },
157
- {
158
- name: "_spender",
159
- type: "address",
160
- },
161
- ],
162
- name: "allowance",
163
- outputs: [
164
- {
165
- name: "",
166
- type: "uint256",
167
- },
168
- ],
169
- payable: false,
170
- stateMutability: "view",
171
- type: "function",
172
- },
173
- {
174
- payable: true,
175
- stateMutability: "payable",
176
- type: "fallback",
177
- },
178
- {
179
- anonymous: false,
180
- inputs: [
181
- {
182
- indexed: true,
183
- name: "owner",
184
- type: "address",
185
- },
186
- {
187
- indexed: true,
188
- name: "spender",
189
- type: "address",
190
- },
191
- {
192
- indexed: false,
193
- name: "value",
194
- type: "uint256",
195
- },
196
- ],
197
- name: "Approval",
198
- type: "event",
199
- },
200
- {
201
- anonymous: false,
202
- inputs: [
203
- {
204
- indexed: true,
205
- name: "from",
206
- type: "address",
207
- },
208
- {
209
- indexed: true,
210
- name: "to",
211
- type: "address",
212
- },
213
- {
214
- indexed: false,
215
- name: "value",
216
- type: "uint256",
217
- },
218
- ],
219
- name: "Transfer",
220
- type: "event",
221
- },
222
- {
223
- comment: "From the EIP-2612 spec.",
224
- inputs: [
225
- {
226
- internalType: "address",
227
- name: "owner",
228
- type: "address",
229
- },
230
- ],
231
- name: "nonces",
232
- outputs: [
233
- {
234
- internalType: "uint256",
235
- name: "",
236
- type: "uint256",
237
- },
238
- ],
239
- stateMutability: "view",
240
- type: "function",
241
- },
242
- {
243
- comment: "From the EIP-2612 spec.",
244
- inputs: [
245
- {
246
- internalType: "address",
247
- name: "owner",
248
- type: "address",
249
- },
250
- {
251
- internalType: "address",
252
- name: "spender",
253
- type: "address",
254
- },
255
- {
256
- internalType: "uint256",
257
- name: "value",
258
- type: "uint256",
259
- },
260
- {
261
- internalType: "uint256",
262
- name: "deadline",
263
- type: "uint256",
264
- },
265
- {
266
- internalType: "uint8",
267
- name: "v",
268
- type: "uint8",
269
- },
270
- {
271
- internalType: "bytes32",
272
- name: "r",
273
- type: "bytes32",
274
- },
275
- {
276
- internalType: "bytes32",
277
- name: "s",
278
- type: "bytes32",
279
- },
280
- ],
281
- name: "permit",
282
- outputs: [],
283
- stateMutability: "nonpayable",
284
- type: "function",
285
- },
286
- {
287
- comment: "Available on bridged tokens on Polygon.",
288
- inputs: [
289
- {
290
- internalType: "address",
291
- name: "userAddress",
292
- type: "address",
293
- },
294
- {
295
- internalType: "bytes",
296
- name: "functionSignature",
297
- type: "bytes",
298
- },
299
- {
300
- internalType: "bytes32",
301
- name: "sigR",
302
- type: "bytes32",
303
- },
304
- {
305
- internalType: "bytes32",
306
- name: "sigS",
307
- type: "bytes32",
308
- },
309
- {
310
- internalType: "uint8",
311
- name: "sigV",
312
- type: "uint8",
313
- },
314
- ],
315
- name: "executeMetaTransaction",
316
- outputs: [
317
- {
318
- internalType: "bytes",
319
- name: "",
320
- type: "bytes",
321
- },
322
- ],
323
- stateMutability: "payable",
324
- type: "function",
325
- },
326
- {
327
- comment: "Available on bridged tokens on Polygon.",
328
- inputs: [
329
- {
330
- internalType: "address",
331
- name: "user",
332
- type: "address",
333
- },
334
- ],
335
- name: "getNonce",
336
- outputs: [
337
- {
338
- internalType: "uint256",
339
- name: "nonce",
340
- type: "uint256",
341
- },
342
- ],
343
- stateMutability: "view",
344
- type: "function",
345
- },
346
- ];
@@ -1,38 +0,0 @@
1
- export const FibrousRouterABI = [
2
- {
3
- inputs: [
4
- {
5
- components: [
6
- { internalType: "address", name: "token_in", type: "address" },
7
- { internalType: "address", name: "token_out", type: "address" },
8
- { internalType: "uint256", name: "amount_in", type: "uint256" },
9
- { internalType: "uint256", name: "amount_out", type: "uint256" },
10
- { internalType: "uint256", name: "min_received", type: "uint256" },
11
- { internalType: "address", name: "destination", type: "address" },
12
- { internalType: "uint8", name: "swap_type", type: "uint8" },
13
- ],
14
- internalType: "struct IFibrousRouter.RouteParam",
15
- name: "route",
16
- type: "tuple",
17
- },
18
- {
19
- components: [
20
- { internalType: "address", name: "token_in", type: "address" },
21
- { internalType: "address", name: "token_out", type: "address" },
22
- { internalType: "uint32", name: "rate", type: "uint32" },
23
- { internalType: "int24", name: "protocol_id", type: "int24" },
24
- { internalType: "address", name: "pool_address", type: "address" },
25
- { internalType: "uint8", name: "swap_type", type: "uint8" },
26
- { internalType: "bytes", name: "extra_data", type: "bytes" },
27
- ],
28
- internalType: "struct IFibrousRouter.SwapParams[]",
29
- name: "swap_parameters",
30
- type: "tuple[]",
31
- },
32
- ],
33
- name: "swap",
34
- outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
35
- stateMutability: "payable",
36
- type: "function",
37
- },
38
- ];
@@ -1,4 +0,0 @@
1
- export * from './erc20.abi';
2
- export * from './vault.abi';
3
- export * from './yakaggregator.abi';
4
- export * from './fibrousrouter.abi';