@avail-project/ca-common 1.0.0-beta.7 → 1.0.0-beta.9

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 (44) hide show
  1. package/dist/cjs/_polyfill.js +147 -0
  2. package/dist/cjs/data/chaindata.js +67 -34
  3. package/dist/cjs/data/chainid.js +4 -2
  4. package/dist/cjs/data/currency.js +1 -2
  5. package/dist/cjs/index.js +4 -4
  6. package/dist/cjs/proto/client.js +48 -0
  7. package/dist/cjs/proto/definition.js +167 -448
  8. package/dist/cjs/proto/grpc.js +4 -9
  9. package/dist/cjs/rff/rff.js +0 -35
  10. package/dist/cjs/vaultcontracts/vaultcontracts.js +79 -30
  11. package/dist/cjs/xcs/autochoice.js +255 -0
  12. package/dist/esm/_polyfill.js +143 -0
  13. package/dist/esm/data/chaindata.js +67 -34
  14. package/dist/esm/data/chainid.js +4 -2
  15. package/dist/esm/data/currency.js +1 -2
  16. package/dist/esm/index.js +13 -12
  17. package/dist/esm/proto/client.js +11 -0
  18. package/dist/esm/proto/definition.js +167 -448
  19. package/dist/esm/proto/grpc.js +4 -9
  20. package/dist/esm/rff/rff.js +0 -35
  21. package/dist/esm/vaultcontracts/vaultcontracts.js +79 -30
  22. package/dist/esm/xcs/autochoice.js +254 -0
  23. package/dist/types/_polyfill.d.ts +1 -0
  24. package/dist/types/data/currency.d.ts +1 -2
  25. package/dist/types/index.d.ts +13 -12
  26. package/dist/types/proto/client.d.ts +2 -0
  27. package/dist/types/rff/rff.d.ts +0 -3
  28. package/dist/types/xcs/autochoice.d.ts +17 -0
  29. package/package.json +16 -10
  30. package/dist/cjs/fuelcontracts/ArcanaVault.js +0 -2407
  31. package/dist/cjs/fuelcontracts/ArcanaVaultFactory.js +0 -18
  32. package/dist/cjs/fuelcontracts/common.js +0 -3
  33. package/dist/cjs/fuelcontracts/index.js +0 -5
  34. package/dist/cjs/rff/fuel.js +0 -27
  35. package/dist/esm/fuelcontracts/ArcanaVault.js +0 -2402
  36. package/dist/esm/fuelcontracts/ArcanaVaultFactory.js +0 -14
  37. package/dist/esm/fuelcontracts/common.js +0 -2
  38. package/dist/esm/fuelcontracts/index.js +0 -2
  39. package/dist/esm/rff/fuel.js +0 -23
  40. package/dist/types/fuelcontracts/ArcanaVault.d.ts +0 -448
  41. package/dist/types/fuelcontracts/ArcanaVaultFactory.d.ts +0 -8
  42. package/dist/types/fuelcontracts/common.d.ts +0 -23
  43. package/dist/types/fuelcontracts/index.d.ts +0 -2
  44. package/dist/types/rff/fuel.d.ts +0 -4
@@ -0,0 +1,143 @@
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();
@@ -533,6 +533,27 @@ const RawData = [
533
533
  },
534
534
  ],
535
535
  },
536
+ {
537
+ Universe: 0,
538
+ ChainID32: "0x000000000000000000000000000000000000000000000000000000000000008f",
539
+ Currencies: [
540
+ {
541
+ CurrencyID: 1,
542
+ TokenContractAddress: "0x000000000000000000000000754704Bc059F8C67012fEd69BC8A327a5aafb603",
543
+ PermitVariant: PermitVariant.EIP2612Canonical,
544
+ PermitContractVersion: 2,
545
+ TokenDecimals: 6,
546
+ IsGasToken: false,
547
+ },
548
+ {
549
+ CurrencyID: 20,
550
+ TokenContractAddress: "0x0000000000000000000000000000000000000000000000000000000000000000",
551
+ PermitVariant: PermitVariant.Unsupported,
552
+ TokenDecimals: 18,
553
+ IsGasToken: true,
554
+ },
555
+ ],
556
+ },
536
557
  {
537
558
  Universe: 3,
538
559
  ChainID32: "0x0000000000000000000000000000000000000000000000000000000094a9059e",
@@ -575,17 +596,32 @@ const RawData = [
575
596
  },
576
597
  {
577
598
  Universe: 0,
578
- ChainID32: "0x0000000000000000000000000000000000000000000000000000000000000237",
599
+ ChainID32: "0x00000000000000000000000000000000000000000000000000000000000010e6",
600
+ Currencies: [
601
+ {
602
+ CurrencyID: 3,
603
+ TokenContractAddress: "0x0000000000000000000000000000000000000000000000000000000000000000",
604
+ PermitVariant: PermitVariant.Unsupported,
605
+ TokenDecimals: 18,
606
+ IsGasToken: true,
607
+ },
608
+ ],
609
+ },
610
+ // Citrea Testnet
611
+ {
612
+ Universe: 0,
613
+ ChainID32: "0x00000000000000000000000000000000000000000000000000000000000013fb",
579
614
  Currencies: [
580
615
  {
581
616
  CurrencyID: 1,
582
- TokenContractAddress: "0x0000000000000000000000008Cf5f629Bb26FC3F92144e72bC4A3719A7DF07F3",
617
+ TokenContractAddress: "0x000000000000000000000000b669dC8cC6D044307Ba45366C0c836eC3c7e31AA",
583
618
  PermitVariant: PermitVariant.EIP2612Canonical,
619
+ PermitContractVersion: 2,
584
620
  TokenDecimals: 6,
585
621
  IsGasToken: false,
586
622
  },
587
623
  {
588
- CurrencyID: 64,
624
+ CurrencyID: 21,
589
625
  TokenContractAddress: "0x0000000000000000000000000000000000000000000000000000000000000000",
590
626
  PermitVariant: PermitVariant.Unsupported,
591
627
  TokenDecimals: 18,
@@ -623,79 +659,76 @@ export const ChaindataMap = new ChainIDKeyedMap(Chaindata.map((ch) => [ch.ChainI
623
659
  export const RPCURLMap = new ChainIDKeyedMap([
624
660
  [
625
661
  new OmniversalChainID(Universe.ETHEREUM, 421614),
626
- "https://arb-sepolia.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
662
+ "https://rpcs.avail.so/arbitrumsepolia",
627
663
  ],
628
664
  [
629
665
  new OmniversalChainID(Universe.ETHEREUM, 11155420),
630
- "https://opt-sepolia.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
666
+ "https://rpcs.avail.so/optimismsepolia",
631
667
  ],
632
668
  [
633
669
  new OmniversalChainID(Universe.ETHEREUM, 80002),
634
- "https://polygon-amoy.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
670
+ "https://rpcs.avail.so/polygonamoy",
635
671
  ],
636
672
  [
637
673
  new OmniversalChainID(Universe.ETHEREUM, 84532),
638
- "https://base-sepolia.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
674
+ "https://rpcs.avail.so/basesepolia",
639
675
  ],
640
676
  [
641
677
  new OmniversalChainID(Universe.ETHEREUM, 11155111),
642
- "https://eth-sepolia.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
678
+ "https://rpcs.avail.so/sepolia",
643
679
  ],
644
680
  [
645
681
  new OmniversalChainID(Universe.ETHEREUM, 137),
646
- "https://polygon-mainnet.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
682
+ "https://rpcs.avail.so/polygon",
647
683
  ],
648
684
  [
649
685
  new OmniversalChainID(Universe.ETHEREUM, 42161),
650
- "https://arb-mainnet.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
686
+ "https://rpcs.avail.so/arbitrum",
651
687
  ],
652
688
  [
653
689
  new OmniversalChainID(Universe.ETHEREUM, 10),
654
- "https://opt-mainnet.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
690
+ "https://rpcs.avail.so/optimism",
655
691
  ],
656
692
  [
657
693
  new OmniversalChainID(Universe.ETHEREUM, 8453),
658
- "https://base-mainnet.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
659
- ],
660
- [
661
- new OmniversalChainID(Universe.ETHEREUM, 1),
662
- "https://eth-mainnet.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
694
+ "https://rpcs.avail.so/base",
663
695
  ],
696
+ [new OmniversalChainID(Universe.ETHEREUM, 1), "https://rpcs.avail.so/eth"],
664
697
  [
665
698
  new OmniversalChainID(Universe.ETHEREUM, 534352),
666
- "https://scroll-mainnet.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
667
- ],
668
- [
669
- new OmniversalChainID(Universe.ETHEREUM, 59144),
670
- "https://linea-mainnet.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
699
+ "https://rpcs.avail.so/scroll",
671
700
  ],
672
701
  [
673
702
  new OmniversalChainID(Universe.ETHEREUM, 43114),
674
- "https://avax-mainnet.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
703
+ "https://rpcs.avail.so/avalanche",
675
704
  ],
676
705
  [
677
706
  new OmniversalChainID(Universe.ETHEREUM, 999),
678
- "https://rpc.hyperliquid.xyz/evm",
679
- ], // Alchemy doesn't support this.
707
+ "https://rpcs.avail.so/hyperevm",
708
+ ],
680
709
  [
681
710
  new OmniversalChainID(Universe.ETHEREUM, 8217),
682
- "https://go.getblock.io/d7094dbd80ab474ba7042603fe912332",
683
- ], // Alchemy doesn't support this.
684
- [new OmniversalChainID(Universe.ETHEREUM, 50104), "https://rpc.sophon.xyz"], // Alchemy doesn't support this.
711
+ "https://rpcs.avail.so/kaia",
712
+ ],
685
713
  [
686
- new OmniversalChainID(Universe.ETHEREUM, 56),
687
- "https://bnb-mainnet.g.alchemy.com/v2/PfaswrKq0rjOrfYWHfE9uLQKhiD4JCdq",
714
+ new OmniversalChainID(Universe.ETHEREUM, 50104),
715
+ "https://sophon.gateway.tenderly.co/1d4STFT7zmG0vM5QowibCw",
688
716
  ],
717
+ [new OmniversalChainID(Universe.ETHEREUM, 56), "https://rpcs.avail.so/bsc"],
689
718
  [
690
719
  new OmniversalChainID(Universe.ETHEREUM, 10143),
691
- "https://lb.drpc.org/monad-testnet/Am5nENoJmEuovqui8_LMxzp4ChJzW7kR8JfPrqRhf0fE",
720
+ "https://rpcs.avail.so/monadtestnet",
721
+ ],
722
+ [
723
+ new OmniversalChainID(Universe.ETHEREUM, 143),
724
+ "https://rpcs.avail.so/monad",
692
725
  ],
693
726
  [
694
- new OmniversalChainID(Universe.ETHEREUM, 567),
695
- "https://testnet.l2.rpc.validium.network",
727
+ new OmniversalChainID(Universe.ETHEREUM, 4326),
728
+ "https://rpcs.avail.so/megeth",
696
729
  ],
697
730
  [
698
- new OmniversalChainID(Universe.FUEL, 9889),
699
- "https://omniscient-fittest-pallet.fuel-mainnet.quiknode.pro/3193ae52f2522af1a4357a482e475e019857f02b/v1/graphql",
731
+ new OmniversalChainID(Universe.ETHEREUM, 5115),
732
+ "https://rpcs.avail.so/citrea-testnet",
700
733
  ],
701
734
  ]);
@@ -1,6 +1,8 @@
1
+ import { ensureBufferPolyfill } from "../_polyfill";
1
2
  import { bytesToBigInt, bytesToHex, hexToBigInt, hexToBytes, toBytes, toHex, } from "viem";
2
3
  import { universeFromJSON, universeToJSON, } from "../proto/definition";
3
4
  import { convertToBufferIfNecessary } from "./utils";
5
+ ensureBufferPolyfill();
4
6
  export function encodeChainID36(universe, chainID) {
5
7
  let chainIDB;
6
8
  if (Buffer.isBuffer(chainID) || chainID instanceof Uint8Array) {
@@ -10,7 +12,7 @@ export function encodeChainID36(universe, chainID) {
10
12
  chainIDB = toBytes(chainID);
11
13
  }
12
14
  const buf = Buffer.alloc(36);
13
- buf.writeUint32BE(universe);
15
+ buf.writeUInt32BE(universe);
14
16
  buf.set(chainIDB, 4 + (32 - chainIDB.length));
15
17
  return buf;
16
18
  }
@@ -45,7 +47,7 @@ export class OmniversalChainID {
45
47
  }
46
48
  static fromChainID36(_input) {
47
49
  const input = convertToBufferIfNecessary(_input);
48
- const univID = input.readUint32BE(0);
50
+ const univID = input.readUInt32BE(0);
49
51
  const rest = input.subarray(4);
50
52
  return new OmniversalChainID(univID, rest);
51
53
  }
@@ -13,8 +13,7 @@ export var CurrencyID;
13
13
  CurrencyID[CurrencyID["KAIA"] = 17] = "KAIA";
14
14
  CurrencyID[CurrencyID["SOPH"] = 18] = "SOPH";
15
15
  CurrencyID[CurrencyID["TRX"] = 19] = "TRX";
16
- CurrencyID[CurrencyID["VLDM"] = 64] = "VLDM";
17
- CurrencyID[CurrencyID["MON"] = 65] = "MON";
16
+ CurrencyID[CurrencyID["MON"] = 20] = "MON";
18
17
  })(CurrencyID || (CurrencyID = {}));
19
18
  export class Currency {
20
19
  currencyID;
package/dist/esm/index.js CHANGED
@@ -1,12 +1,13 @@
1
- export { ArcanaVault, ArcanaVaultFactory } from './fuelcontracts';
2
- export * from './proto/definition';
3
- export { QueryClientImpl, GrpcWebError, GrpcWebImpl } from './proto/grpc';
4
- export * from './data';
5
- export * from './vaultcontracts';
6
- export * from './permitutils';
7
- export * from './xcs';
8
- export * from './cosmos';
9
- export * from './rff/rff';
10
- export * from './types';
11
- export * from './balances/ub-api';
12
- export * from './evmabi';
1
+ import "./_polyfill";
2
+ export * from "./proto/definition";
3
+ export { QueryClientImpl, GrpcWebError, GrpcWebImpl, } from "./proto/grpc";
4
+ export { createGrpcWebImpl } from "./proto/client";
5
+ export * from "./data";
6
+ export * from "./vaultcontracts";
7
+ export * from "./permitutils";
8
+ export * from "./xcs";
9
+ export * from "./cosmos";
10
+ export * from "./rff/rff";
11
+ export * from "./types";
12
+ export * from "./balances/ub-api";
13
+ export * from "./evmabi";
@@ -0,0 +1,11 @@
1
+ import { GrpcWebImpl } from "./grpc";
2
+ export const createGrpcWebImpl = async (url) => {
3
+ const options = {};
4
+ // eslint-disable-next-line no-constant-binary-expression, valid-typeof
5
+ if (typeof window == undefined) {
6
+ const lib = await import("@improbable-eng/grpc-web-node-http-transport");
7
+ options.transport = lib.NodeHttpTransport();
8
+ }
9
+ const impl = new GrpcWebImpl(url, options);
10
+ return impl;
11
+ };