@avail-project/ca-common 1.0.0-beta.1

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 (97) hide show
  1. package/dist/cjs/balances/ub-api.js +25 -0
  2. package/dist/cjs/cosmos/index.js +31 -0
  3. package/dist/cjs/data/chaindata.js +680 -0
  4. package/dist/cjs/data/chainid.js +91 -0
  5. package/dist/cjs/data/currency.js +77 -0
  6. package/dist/cjs/data/index.js +7 -0
  7. package/dist/cjs/data/utils.js +44 -0
  8. package/dist/cjs/evmabi/erc20.abi.js +349 -0
  9. package/dist/cjs/evmabi/index.js +6 -0
  10. package/dist/cjs/evmabi/vault.abi.js +1021 -0
  11. package/dist/cjs/evmabi/yakaggregator.abi.js +275 -0
  12. package/dist/cjs/fuelcontracts/ArcanaVault.js +2407 -0
  13. package/dist/cjs/fuelcontracts/ArcanaVaultFactory.js +18 -0
  14. package/dist/cjs/fuelcontracts/common.js +3 -0
  15. package/dist/cjs/fuelcontracts/index.js +5 -0
  16. package/dist/cjs/index.js +21 -0
  17. package/dist/cjs/permitutils/index.js +186 -0
  18. package/dist/cjs/proto/definition.js +4263 -0
  19. package/dist/cjs/proto/grpc.js +303 -0
  20. package/dist/cjs/rff/fuel.js +27 -0
  21. package/dist/cjs/rff/rff.js +77 -0
  22. package/dist/cjs/types/binarytypes.js +2 -0
  23. package/dist/cjs/types/index.js +5 -0
  24. package/dist/cjs/types/msgpack-axios.js +22 -0
  25. package/dist/cjs/vaultcontracts/index.js +4 -0
  26. package/dist/cjs/vaultcontracts/vaultcontracts.js +145 -0
  27. package/dist/cjs/xcs/autochoice.js +374 -0
  28. package/dist/cjs/xcs/bebop-agg.js +128 -0
  29. package/dist/cjs/xcs/iface.js +13 -0
  30. package/dist/cjs/xcs/index.js +8 -0
  31. package/dist/cjs/xcs/lifi-agg.js +104 -0
  32. package/dist/cjs/xcs/yieldyak-agg.js +113 -0
  33. package/dist/esm/balances/ub-api.js +21 -0
  34. package/dist/esm/cosmos/index.js +26 -0
  35. package/dist/esm/data/chaindata.js +677 -0
  36. package/dist/esm/data/chainid.js +85 -0
  37. package/dist/esm/data/currency.js +72 -0
  38. package/dist/esm/data/index.js +4 -0
  39. package/dist/esm/data/utils.js +34 -0
  40. package/dist/esm/evmabi/erc20.abi.js +346 -0
  41. package/dist/esm/evmabi/index.js +3 -0
  42. package/dist/esm/evmabi/vault.abi.js +1018 -0
  43. package/dist/esm/evmabi/yakaggregator.abi.js +272 -0
  44. package/dist/esm/fuelcontracts/ArcanaVault.js +2402 -0
  45. package/dist/esm/fuelcontracts/ArcanaVaultFactory.js +14 -0
  46. package/dist/esm/fuelcontracts/common.js +2 -0
  47. package/dist/esm/fuelcontracts/index.js +2 -0
  48. package/dist/esm/index.js +12 -0
  49. package/dist/esm/permitutils/index.js +181 -0
  50. package/dist/esm/proto/definition.js +4255 -0
  51. package/dist/esm/proto/grpc.js +297 -0
  52. package/dist/esm/rff/fuel.js +23 -0
  53. package/dist/esm/rff/rff.js +73 -0
  54. package/dist/esm/types/binarytypes.js +1 -0
  55. package/dist/esm/types/index.js +2 -0
  56. package/dist/esm/types/msgpack-axios.js +18 -0
  57. package/dist/esm/vaultcontracts/index.js +1 -0
  58. package/dist/esm/vaultcontracts/vaultcontracts.js +141 -0
  59. package/dist/esm/xcs/autochoice.js +364 -0
  60. package/dist/esm/xcs/bebop-agg.js +123 -0
  61. package/dist/esm/xcs/iface.js +10 -0
  62. package/dist/esm/xcs/index.js +5 -0
  63. package/dist/esm/xcs/lifi-agg.js +99 -0
  64. package/dist/esm/xcs/yieldyak-agg.js +109 -0
  65. package/dist/types/balances/ub-api.d.ts +14 -0
  66. package/dist/types/cosmos/index.d.ts +6 -0
  67. package/dist/types/data/chaindata.d.ts +20 -0
  68. package/dist/types/data/chainid.d.ts +31 -0
  69. package/dist/types/data/currency.d.ts +29 -0
  70. package/dist/types/data/index.d.ts +4 -0
  71. package/dist/types/data/utils.d.ts +10 -0
  72. package/dist/types/evmabi/erc20.abi.d.ts +264 -0
  73. package/dist/types/evmabi/index.d.ts +3 -0
  74. package/dist/types/evmabi/vault.abi.d.ts +785 -0
  75. package/dist/types/evmabi/yakaggregator.abi.d.ts +298 -0
  76. package/dist/types/fuelcontracts/ArcanaVault.d.ts +448 -0
  77. package/dist/types/fuelcontracts/ArcanaVaultFactory.d.ts +8 -0
  78. package/dist/types/fuelcontracts/common.d.ts +23 -0
  79. package/dist/types/fuelcontracts/index.d.ts +2 -0
  80. package/dist/types/index.d.ts +12 -0
  81. package/dist/types/permitutils/index.d.ts +13 -0
  82. package/dist/types/proto/definition.d.ts +373 -0
  83. package/dist/types/proto/grpc.d.ts +75 -0
  84. package/dist/types/rff/fuel.d.ts +4 -0
  85. package/dist/types/rff/rff.d.ts +12 -0
  86. package/dist/types/types/binarytypes.d.ts +1 -0
  87. package/dist/types/types/index.d.ts +2 -0
  88. package/dist/types/types/msgpack-axios.d.ts +1 -0
  89. package/dist/types/vaultcontracts/index.d.ts +22 -0
  90. package/dist/types/vaultcontracts/vaultcontracts.d.ts +8 -0
  91. package/dist/types/xcs/autochoice.d.ts +57 -0
  92. package/dist/types/xcs/bebop-agg.d.ts +104 -0
  93. package/dist/types/xcs/iface.d.ts +36 -0
  94. package/dist/types/xcs/index.d.ts +5 -0
  95. package/dist/types/xcs/lifi-agg.d.ts +35 -0
  96. package/dist/types/xcs/yieldyak-agg.d.ts +21 -0
  97. package/package.json +63 -0
@@ -0,0 +1,85 @@
1
+ import { bytesToBigInt, bytesToHex, hexToBigInt, hexToBytes, toBytes, toHex, } from "viem";
2
+ import { universeFromJSON, universeToJSON, } from "../proto/definition";
3
+ import { convertToBufferIfNecessary } from "./utils";
4
+ export function encodeChainID36(universe, chainID) {
5
+ let chainIDB;
6
+ if (Buffer.isBuffer(chainID) || chainID instanceof Uint8Array) {
7
+ chainIDB = chainID;
8
+ }
9
+ else {
10
+ chainIDB = toBytes(chainID);
11
+ }
12
+ const buf = Buffer.alloc(36);
13
+ buf.writeUint32BE(universe);
14
+ buf.set(chainIDB, 4 + (32 - chainIDB.length));
15
+ return buf;
16
+ }
17
+ export class OmniversalChainID {
18
+ universe;
19
+ chainID;
20
+ binaryForm;
21
+ constructor(universe, chainID) {
22
+ this.universe = universe;
23
+ if (typeof chainID === "bigint") {
24
+ this.chainID = chainID;
25
+ }
26
+ else if (typeof chainID === "number" || typeof chainID === "string") {
27
+ this.chainID = BigInt(chainID);
28
+ }
29
+ else if (chainID instanceof Uint8Array) {
30
+ this.chainID = bytesToBigInt(chainID);
31
+ }
32
+ this.binaryForm = encodeChainID36(this.universe, this.chainID);
33
+ }
34
+ toString() {
35
+ return universeToJSON(this.universe) + "_" + this.chainID.toString(10);
36
+ }
37
+ toJSON() {
38
+ return {
39
+ universe: universeToJSON(this.universe),
40
+ chainID: toHex(this.chainID),
41
+ };
42
+ }
43
+ static fromJSON(input) {
44
+ return new OmniversalChainID(universeFromJSON(input.universe), hexToBigInt(input.chainID));
45
+ }
46
+ static fromChainID36(_input) {
47
+ const input = convertToBufferIfNecessary(_input);
48
+ const univID = input.readUint32BE(0);
49
+ const rest = input.subarray(4);
50
+ return new OmniversalChainID(univID, rest);
51
+ }
52
+ // Do not modify the returned buffer. Make a copy if necessary.
53
+ toBytes() {
54
+ return this.binaryForm;
55
+ }
56
+ equals(rhs) {
57
+ return this.universe === rhs.universe && this.chainID === rhs.chainID;
58
+ }
59
+ static equals(lhs, rhs) {
60
+ return lhs.equals(rhs);
61
+ }
62
+ }
63
+ export class ChainIDKeyedMap {
64
+ map;
65
+ constructor(entries = null) {
66
+ this.map = new Map(entries != null
67
+ ? entries.map((e) => [bytesToHex(e[0].toBytes()), e[1]])
68
+ : null);
69
+ }
70
+ get(key) {
71
+ return this.map.get(bytesToHex(key.toBytes()));
72
+ }
73
+ set(key, value) {
74
+ this.map.set(bytesToHex(key.toBytes()), value);
75
+ return this;
76
+ }
77
+ getFromChainID36(key) {
78
+ return this.map.get(bytesToHex(key));
79
+ }
80
+ *entries() {
81
+ for (const [key, value] of this.map.entries()) {
82
+ yield [OmniversalChainID.fromChainID36(hexToBytes(key)), value];
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,72 @@
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 = {}));
18
+ export class Currency {
19
+ currencyID;
20
+ decimals;
21
+ permitVariant;
22
+ permitContractVersion;
23
+ isGasToken;
24
+ // this is always 32 byte long
25
+ tokenAddress;
26
+ /* This is the ratio between one unit to the smallest unit used.
27
+
28
+ 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.
29
+ */
30
+ oneUnitToAtomicUnitRatio;
31
+ constructor(currencyID, tokenAddress, decimals, permitVariant, permitContractVersion = 0, isGasToken) {
32
+ this.currencyID = currencyID;
33
+ this.decimals = decimals;
34
+ this.permitVariant = permitVariant;
35
+ this.permitContractVersion = permitContractVersion;
36
+ this.isGasToken = isGasToken;
37
+ if (typeof tokenAddress === "string") {
38
+ this.tokenAddress = zeroExtendBufToGivenSize(toBytes(tokenAddress), 32);
39
+ }
40
+ else if (tokenAddress instanceof Uint8Array) {
41
+ this.tokenAddress = zeroExtendBufToGivenSize(tokenAddress, 32);
42
+ }
43
+ else if (Array.isArray(tokenAddress) &&
44
+ tokenAddress.length >= 1 &&
45
+ typeof tokenAddress[0] === "number") {
46
+ this.tokenAddress = zeroExtendBufToGivenSize(Buffer.from(tokenAddress), 32);
47
+ }
48
+ this.oneUnitToAtomicUnitRatio = Decimal.pow(10, decimals);
49
+ }
50
+ convertUnitsToAmountDecimal(input) {
51
+ let rawunits;
52
+ if (typeof input === "bigint") {
53
+ rawunits = input.toString(10);
54
+ }
55
+ else if (typeof input === "number") {
56
+ rawunits = input.toString();
57
+ }
58
+ else if (input instanceof Uint8Array) {
59
+ rawunits = bytesToBigInt(input).toString(10);
60
+ }
61
+ else if (typeof input === "string") {
62
+ rawunits = input;
63
+ }
64
+ else {
65
+ throw new Error("Invalid input");
66
+ }
67
+ return Decimal.div(rawunits, this.oneUnitToAtomicUnitRatio);
68
+ }
69
+ convertAmountToUnitsInBinary(input) {
70
+ return Buffer.from(toBytes(input.mul(this.oneUnitToAtomicUnitRatio).ceil().toHex()));
71
+ }
72
+ }
@@ -0,0 +1,4 @@
1
+ export * from './chaindata';
2
+ export * from './chainid';
3
+ export * from './currency';
4
+ export * from './utils';
@@ -0,0 +1,34 @@
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
+ }
@@ -0,0 +1,346 @@
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
+ ];
@@ -0,0 +1,3 @@
1
+ export * from './erc20.abi';
2
+ export * from './vault.abi';
3
+ export * from './yakaggregator.abi';