zerc20-client-sdk 0.1.15 → 0.2.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.
- package/README.md +275 -25
- package/dist/chain/__tests__/metadata.test.d.ts +2 -0
- package/dist/chain/__tests__/metadata.test.d.ts.map +1 -0
- package/dist/chain/__tests__/metadata.test.js +162 -0
- package/dist/chain/__tests__/metadata.test.js.map +1 -0
- package/dist/chain/index.d.ts +3 -0
- package/dist/chain/index.d.ts.map +1 -0
- package/dist/chain/index.js +2 -0
- package/dist/chain/index.js.map +1 -0
- package/dist/chain/metadata.d.ts +38 -0
- package/dist/chain/metadata.d.ts.map +1 -0
- package/dist/chain/metadata.js +158 -0
- package/dist/chain/metadata.js.map +1 -0
- package/dist/chain/types.d.ts +18 -0
- package/dist/chain/types.d.ts.map +1 -0
- package/dist/chain/types.js +2 -0
- package/dist/chain/types.js.map +1 -0
- package/dist/constants.d.ts +3 -3
- package/dist/constants.js +3 -3
- package/dist/ic/__tests__/connections.test.js +16 -152
- package/dist/ic/__tests__/connections.test.js.map +1 -1
- package/dist/ic/__tests__/recipient.test.d.ts +2 -0
- package/dist/ic/__tests__/recipient.test.d.ts.map +1 -0
- package/dist/ic/__tests__/recipient.test.js +47 -0
- package/dist/ic/__tests__/recipient.test.js.map +1 -0
- package/dist/ic/authorization.js +2 -2
- package/dist/ic/authorization.js.map +1 -1
- package/dist/ic/connections.d.ts +0 -50
- package/dist/ic/connections.d.ts.map +1 -1
- package/dist/ic/connections.js +0 -127
- package/dist/ic/connections.js.map +1 -1
- package/dist/ic/index.d.ts +4 -8
- package/dist/ic/index.d.ts.map +1 -1
- package/dist/ic/index.js +3 -8
- package/dist/ic/index.js.map +1 -1
- package/dist/ic/recipient.d.ts +10 -0
- package/dist/ic/recipient.d.ts.map +1 -1
- package/dist/ic/recipient.js +21 -1
- package/dist/ic/recipient.js.map +1 -1
- package/dist/index.d.ts +14 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/index.js.map +1 -1
- package/dist/onchain/__tests__/contracts.test.js +2 -32
- package/dist/onchain/__tests__/contracts.test.js.map +1 -1
- package/dist/onchain/__tests__/decode.test.d.ts +2 -0
- package/dist/onchain/__tests__/decode.test.d.ts.map +1 -0
- package/dist/onchain/__tests__/decode.test.js +155 -0
- package/dist/onchain/__tests__/decode.test.js.map +1 -0
- package/dist/onchain/__tests__/tokenReads.test.d.ts +2 -0
- package/dist/onchain/__tests__/tokenReads.test.d.ts.map +1 -0
- package/dist/onchain/__tests__/tokenReads.test.js +60 -0
- package/dist/onchain/__tests__/tokenReads.test.js.map +1 -0
- package/dist/onchain/contracts.d.ts +3 -29734
- package/dist/onchain/contracts.d.ts.map +1 -1
- package/dist/onchain/contracts.js +3 -59
- package/dist/onchain/contracts.js.map +1 -1
- package/dist/onchain/decode.d.ts +39 -0
- package/dist/onchain/decode.d.ts.map +1 -0
- package/dist/onchain/decode.js +100 -0
- package/dist/onchain/decode.js.map +1 -0
- package/dist/onchain/tokenReads.d.ts +30 -0
- package/dist/onchain/tokenReads.d.ts.map +1 -0
- package/dist/onchain/tokenReads.js +51 -0
- package/dist/onchain/tokenReads.js.map +1 -0
- package/dist/operations/__tests__/invoice.test.js +52 -1
- package/dist/operations/__tests__/invoice.test.js.map +1 -1
- package/dist/operations/__tests__/privateSendTransfer.test.d.ts +2 -0
- package/dist/operations/__tests__/privateSendTransfer.test.d.ts.map +1 -0
- package/dist/operations/__tests__/privateSendTransfer.test.js +60 -0
- package/dist/operations/__tests__/privateSendTransfer.test.js.map +1 -0
- package/dist/operations/__tests__/reexports.test.js +1 -1
- package/dist/operations/__tests__/reexports.test.js.map +1 -1
- package/dist/operations/__tests__/teleportProof.test.js +35 -75
- package/dist/operations/__tests__/teleportProof.test.js.map +1 -1
- package/dist/operations/invoice.d.ts +14 -0
- package/dist/operations/invoice.d.ts.map +1 -1
- package/dist/operations/invoice.js +22 -0
- package/dist/operations/invoice.js.map +1 -1
- package/dist/operations/layerzeroScan/__tests__/codec.decode.test.d.ts +2 -0
- package/dist/operations/layerzeroScan/__tests__/codec.decode.test.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/codec.decode.test.js +57 -0
- package/dist/operations/layerzeroScan/__tests__/codec.decode.test.js.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/codec.test.d.ts +2 -0
- package/dist/operations/layerzeroScan/__tests__/codec.test.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/codec.test.js +120 -0
- package/dist/operations/layerzeroScan/__tests__/codec.test.js.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/formatters.test.d.ts +2 -0
- package/dist/operations/layerzeroScan/__tests__/formatters.test.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/formatters.test.js +164 -0
- package/dist/operations/layerzeroScan/__tests__/formatters.test.js.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/integration.test.d.ts +2 -0
- package/dist/operations/layerzeroScan/__tests__/integration.test.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/integration.test.js +164 -0
- package/dist/operations/layerzeroScan/__tests__/integration.test.js.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/scan.test.d.ts +2 -0
- package/dist/operations/layerzeroScan/__tests__/scan.test.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/scan.test.js +103 -0
- package/dist/operations/layerzeroScan/__tests__/scan.test.js.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/status.test.d.ts +2 -0
- package/dist/operations/layerzeroScan/__tests__/status.test.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/__tests__/status.test.js +153 -0
- package/dist/operations/layerzeroScan/__tests__/status.test.js.map +1 -0
- package/dist/operations/layerzeroScan/codec.d.ts +34 -0
- package/dist/operations/layerzeroScan/codec.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/codec.js +79 -0
- package/dist/operations/layerzeroScan/codec.js.map +1 -0
- package/dist/operations/layerzeroScan/formatters.d.ts +26 -0
- package/dist/operations/layerzeroScan/formatters.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/formatters.js +75 -0
- package/dist/operations/layerzeroScan/formatters.js.map +1 -0
- package/dist/operations/layerzeroScan/index.d.ts +9 -0
- package/dist/operations/layerzeroScan/index.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/index.js +12 -0
- package/dist/operations/layerzeroScan/index.js.map +1 -0
- package/dist/operations/layerzeroScan/scan.d.ts +21 -0
- package/dist/operations/layerzeroScan/scan.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/scan.js +70 -0
- package/dist/operations/layerzeroScan/scan.js.map +1 -0
- package/dist/operations/layerzeroScan/status.d.ts +17 -0
- package/dist/operations/layerzeroScan/status.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/status.js +178 -0
- package/dist/operations/layerzeroScan/status.js.map +1 -0
- package/dist/operations/layerzeroScan/types.d.ts +181 -0
- package/dist/operations/layerzeroScan/types.d.ts.map +1 -0
- package/dist/operations/layerzeroScan/types.js +5 -0
- package/dist/operations/layerzeroScan/types.js.map +1 -0
- package/dist/operations/layerzeroScan.d.ts +5 -0
- package/dist/operations/layerzeroScan.d.ts.map +1 -0
- package/dist/operations/layerzeroScan.js +5 -0
- package/dist/operations/layerzeroScan.js.map +1 -0
- package/dist/operations/liquidityManager/__tests__/adaptorWithdraw.test.d.ts +2 -0
- package/dist/operations/liquidityManager/__tests__/adaptorWithdraw.test.d.ts.map +1 -0
- package/dist/operations/liquidityManager/__tests__/adaptorWithdraw.test.js +157 -0
- package/dist/operations/liquidityManager/__tests__/adaptorWithdraw.test.js.map +1 -0
- package/dist/operations/liquidityManager/__tests__/balance.test.js +24 -37
- package/dist/operations/liquidityManager/__tests__/balance.test.js.map +1 -1
- package/dist/operations/liquidityManager/__tests__/crossUnwrap.test.js +51 -31
- package/dist/operations/liquidityManager/__tests__/crossUnwrap.test.js.map +1 -1
- package/dist/operations/liquidityManager/__tests__/helpers.test.js +11 -8
- package/dist/operations/liquidityManager/__tests__/helpers.test.js.map +1 -1
- package/dist/operations/liquidityManager/__tests__/unwrap.test.js +68 -82
- package/dist/operations/liquidityManager/__tests__/unwrap.test.js.map +1 -1
- package/dist/operations/liquidityManager/__tests__/wrap.test.js +55 -64
- package/dist/operations/liquidityManager/__tests__/wrap.test.js.map +1 -1
- package/dist/operations/liquidityManager/abi.d.ts +57 -0
- package/dist/operations/liquidityManager/abi.d.ts.map +1 -0
- package/dist/operations/liquidityManager/abi.js +41 -0
- package/dist/operations/liquidityManager/abi.js.map +1 -0
- package/dist/operations/liquidityManager/adaptorWithdraw.d.ts +82 -0
- package/dist/operations/liquidityManager/adaptorWithdraw.d.ts.map +1 -0
- package/dist/operations/liquidityManager/adaptorWithdraw.js +107 -0
- package/dist/operations/liquidityManager/adaptorWithdraw.js.map +1 -0
- package/dist/operations/liquidityManager/balance.d.ts +3 -3
- package/dist/operations/liquidityManager/balance.d.ts.map +1 -1
- package/dist/operations/liquidityManager/balance.js +22 -15
- package/dist/operations/liquidityManager/balance.js.map +1 -1
- package/dist/operations/liquidityManager/crossUnwrap.d.ts +13 -11
- package/dist/operations/liquidityManager/crossUnwrap.d.ts.map +1 -1
- package/dist/operations/liquidityManager/crossUnwrap.js +44 -20
- package/dist/operations/liquidityManager/crossUnwrap.js.map +1 -1
- package/dist/operations/liquidityManager/helpers.d.ts +10 -15474
- package/dist/operations/liquidityManager/helpers.d.ts.map +1 -1
- package/dist/operations/liquidityManager/helpers.js +28 -18
- package/dist/operations/liquidityManager/helpers.js.map +1 -1
- package/dist/operations/liquidityManager/index.d.ts +3 -0
- package/dist/operations/liquidityManager/index.d.ts.map +1 -1
- package/dist/operations/liquidityManager/index.js +3 -0
- package/dist/operations/liquidityManager/index.js.map +1 -1
- package/dist/operations/liquidityManager/types.d.ts +1 -1
- package/dist/operations/liquidityManager/types.d.ts.map +1 -1
- package/dist/operations/liquidityManager/unwrap.d.ts +9 -9
- package/dist/operations/liquidityManager/unwrap.d.ts.map +1 -1
- package/dist/operations/liquidityManager/unwrap.js +48 -24
- package/dist/operations/liquidityManager/unwrap.js.map +1 -1
- package/dist/operations/liquidityManager/wrap.d.ts +7 -7
- package/dist/operations/liquidityManager/wrap.d.ts.map +1 -1
- package/dist/operations/liquidityManager/wrap.js +35 -16
- package/dist/operations/liquidityManager/wrap.js.map +1 -1
- package/dist/operations/privateSend.d.ts +33 -0
- package/dist/operations/privateSend.d.ts.map +1 -1
- package/dist/operations/privateSend.js +26 -0
- package/dist/operations/privateSend.js.map +1 -1
- package/dist/operations/receive/__tests__/announcementStatus.test.js +34 -11
- package/dist/operations/receive/__tests__/announcementStatus.test.js.map +1 -1
- package/dist/operations/receive/__tests__/cache.test.js +55 -161
- package/dist/operations/receive/__tests__/cache.test.js.map +1 -1
- package/dist/operations/receive/__tests__/createVerifierReader.test.d.ts +2 -0
- package/dist/operations/receive/__tests__/createVerifierReader.test.d.ts.map +1 -0
- package/dist/operations/receive/__tests__/createVerifierReader.test.js +28 -0
- package/dist/operations/receive/__tests__/createVerifierReader.test.js.map +1 -0
- package/dist/operations/receive/__tests__/helpers.test.js +9 -9
- package/dist/operations/receive/__tests__/helpers.test.js.map +1 -1
- package/dist/operations/receive/__tests__/redeemTransaction.test.d.ts +2 -0
- package/dist/operations/receive/__tests__/redeemTransaction.test.d.ts.map +1 -0
- package/dist/operations/receive/__tests__/redeemTransaction.test.js +258 -0
- package/dist/operations/receive/__tests__/redeemTransaction.test.js.map +1 -0
- package/dist/operations/receive/__tests__/submitRedeem.test.d.ts +2 -0
- package/dist/operations/receive/__tests__/submitRedeem.test.d.ts.map +1 -0
- package/dist/operations/receive/__tests__/submitRedeem.test.js +58 -0
- package/dist/operations/receive/__tests__/submitRedeem.test.js.map +1 -0
- package/dist/operations/receive/announcementStatus.d.ts +1 -1
- package/dist/operations/receive/announcementStatus.d.ts.map +1 -1
- package/dist/operations/receive/announcementStatus.js +7 -5
- package/dist/operations/receive/announcementStatus.js.map +1 -1
- package/dist/operations/receive/cache.d.ts +1 -19
- package/dist/operations/receive/cache.d.ts.map +1 -1
- package/dist/operations/receive/cache.js +6 -35
- package/dist/operations/receive/cache.js.map +1 -1
- package/dist/operations/receive/helpers.d.ts +14 -3
- package/dist/operations/receive/helpers.d.ts.map +1 -1
- package/dist/operations/receive/helpers.js +33 -3
- package/dist/operations/receive/helpers.js.map +1 -1
- package/dist/operations/receive/index.d.ts +6 -2
- package/dist/operations/receive/index.d.ts.map +1 -1
- package/dist/operations/receive/index.js +6 -1
- package/dist/operations/receive/index.js.map +1 -1
- package/dist/operations/receive/redeemTransaction.d.ts +30 -0
- package/dist/operations/receive/redeemTransaction.d.ts.map +1 -0
- package/dist/operations/receive/redeemTransaction.js +104 -0
- package/dist/operations/receive/redeemTransaction.js.map +1 -0
- package/dist/operations/receive/submitRedeem.d.ts +32 -0
- package/dist/operations/receive/submitRedeem.d.ts.map +1 -0
- package/dist/operations/receive/submitRedeem.js +27 -0
- package/dist/operations/receive/submitRedeem.js.map +1 -0
- package/dist/operations/receive/types.d.ts +53 -5
- package/dist/operations/receive/types.d.ts.map +1 -1
- package/dist/operations/teleportProof.d.ts +10 -31
- package/dist/operations/teleportProof.d.ts.map +1 -1
- package/dist/operations/teleportProof.js +14 -26
- package/dist/operations/teleportProof.js.map +1 -1
- package/dist/registry/__tests__/helpers.test.js +2 -44
- package/dist/registry/__tests__/helpers.test.js.map +1 -1
- package/dist/registry/__tests__/loader.test.js +17 -191
- package/dist/registry/__tests__/loader.test.js.map +1 -1
- package/dist/registry/__tests__/normalize.test.js +109 -1
- package/dist/registry/__tests__/normalize.test.js.map +1 -1
- package/dist/registry/helpers.d.ts +0 -7
- package/dist/registry/helpers.d.ts.map +1 -1
- package/dist/registry/helpers.js +0 -14
- package/dist/registry/helpers.js.map +1 -1
- package/dist/registry/index.d.ts +5 -5
- package/dist/registry/index.d.ts.map +1 -1
- package/dist/registry/index.js +4 -4
- package/dist/registry/index.js.map +1 -1
- package/dist/registry/loader.d.ts +0 -25
- package/dist/registry/loader.d.ts.map +1 -1
- package/dist/registry/loader.js +0 -68
- package/dist/registry/loader.js.map +1 -1
- package/dist/registry/normalize.d.ts +13 -1
- package/dist/registry/normalize.d.ts.map +1 -1
- package/dist/registry/normalize.js +43 -0
- package/dist/registry/normalize.js.map +1 -1
- package/dist/registry/types.d.ts +13 -2
- package/dist/registry/types.d.ts.map +1 -1
- package/dist/types/__tests__/evm.test.d.ts +2 -0
- package/dist/types/__tests__/evm.test.d.ts.map +1 -0
- package/dist/types/__tests__/evm.test.js +15 -0
- package/dist/types/__tests__/evm.test.js.map +1 -0
- package/dist/types/evm.d.ts +95 -0
- package/dist/types/evm.d.ts.map +1 -0
- package/dist/types/evm.js +11 -0
- package/dist/types/evm.js.map +1 -0
- package/dist/types.d.ts +15 -13
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/__tests__/fees.test.js +66 -29
- package/dist/utils/__tests__/fees.test.js.map +1 -1
- package/dist/utils/__tests__/hex.test.js +64 -1
- package/dist/utils/__tests__/hex.test.js.map +1 -1
- package/dist/utils/__tests__/http.test.js +2 -64
- package/dist/utils/__tests__/http.test.js.map +1 -1
- package/dist/utils/fees.d.ts +7 -2
- package/dist/utils/fees.d.ts.map +1 -1
- package/dist/utils/fees.js +32 -16
- package/dist/utils/fees.js.map +1 -1
- package/dist/utils/hex.d.ts +11 -0
- package/dist/utils/hex.d.ts.map +1 -1
- package/dist/utils/hex.js +16 -1
- package/dist/utils/hex.js.map +1 -1
- package/dist/utils/http.d.ts +0 -27
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/http.js +0 -36
- package/dist/utils/http.js.map +1 -1
- package/dist/wasm/__tests__/functions.test.js +56 -1
- package/dist/wasm/__tests__/functions.test.js.map +1 -1
- package/dist/wasm/functions.d.ts +6 -0
- package/dist/wasm/functions.d.ts.map +1 -1
- package/dist/wasm/functions.js +17 -0
- package/dist/wasm/functions.js.map +1 -1
- package/dist/wasm/index.d.ts +1 -1
- package/dist/wasm/index.d.ts.map +1 -1
- package/dist/wasm/index.js +1 -1
- package/dist/wasm/index.js.map +1 -1
- package/dist/zkp/__tests__/proofService.test.js +34 -52
- package/dist/zkp/__tests__/proofService.test.js.map +1 -1
- package/dist/zkp/__tests__/workerClient.test.js +1 -40
- package/dist/zkp/__tests__/workerClient.test.js.map +1 -1
- package/dist/zkp/index.d.ts +1 -1
- package/dist/zkp/index.d.ts.map +1 -1
- package/dist/zkp/index.js +1 -1
- package/dist/zkp/index.js.map +1 -1
- package/dist/zkp/proofService.d.ts +6 -2
- package/dist/zkp/proofService.d.ts.map +1 -1
- package/dist/zkp/proofService.js +12 -15
- package/dist/zkp/proofService.js.map +1 -1
- package/dist/zkp/worker.js +13 -137
- package/dist/zkp/worker.js.map +1 -1
- package/dist/zkp/workerClient.d.ts +0 -24
- package/dist/zkp/workerClient.d.ts.map +1 -1
- package/dist/zkp/workerClient.js +0 -36
- package/dist/zkp/workerClient.js.map +1 -1
- package/package.json +3 -4
package/README.md
CHANGED
|
@@ -23,6 +23,27 @@ npm install zerc20-client-sdk
|
|
|
23
23
|
- Node.js >= 18
|
|
24
24
|
- Browser with WebAssembly support
|
|
25
25
|
|
|
26
|
+
## Compatibility Notes
|
|
27
|
+
|
|
28
|
+
- This package is **ESM-only** (`"type": "module"`). CommonJS (`require`) is not supported.
|
|
29
|
+
- HTTP-based modules (e.g. Decider client, LayerZero Scan) rely on `fetch`.
|
|
30
|
+
- Node.js 18+ includes `fetch` globally.
|
|
31
|
+
- In custom runtimes, provide a compatible `fetch` implementation where needed.
|
|
32
|
+
|
|
33
|
+
## Provider Abstraction (Library/Framework Agnostic)
|
|
34
|
+
|
|
35
|
+
The SDK public API is designed to be wallet/provider agnostic:
|
|
36
|
+
|
|
37
|
+
- Read paths accept `EvmReadProvider`
|
|
38
|
+
- Write paths accept `EvmWriteProvider`
|
|
39
|
+
- UI frameworks are not part of the SDK surface
|
|
40
|
+
|
|
41
|
+
This lets integrators use viem, ethers, web3.js, or custom adapters without depending on React/Vue internals.
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import type { EvmReadProvider, EvmWriteProvider } from "zerc20-client-sdk";
|
|
45
|
+
```
|
|
46
|
+
|
|
26
47
|
## Quick Start
|
|
27
48
|
|
|
28
49
|
```typescript
|
|
@@ -73,35 +94,31 @@ src/
|
|
|
73
94
|
│ ├── invoice.ts # Invoice creation
|
|
74
95
|
│ ├── teleport.ts # Single teleport proof
|
|
75
96
|
│ ├── teleportProof.ts # Batch teleport proof (Nova + Decider)
|
|
76
|
-
│
|
|
97
|
+
│ ├── liquidityManager/ # Wrap/unwrap with slippage protection
|
|
98
|
+
│ └── layerzeroScan/ # LayerZero message tracking & decoding
|
|
77
99
|
├── wasm/ # WASM runtime & bindings
|
|
78
100
|
│ ├── index.ts # WasmRuntime class
|
|
79
101
|
│ ├── loader.ts # WASM bindings loader (browser/Node.js)
|
|
80
102
|
│ └── serialization.ts # Type conversion utilities
|
|
81
103
|
├── zkp/ # Zero-knowledge proof orchestration
|
|
82
104
|
├── decider/ # Decider proof generation (HTTP client)
|
|
105
|
+
├── chain/ # Chain metadata (names, explorers, aliases)
|
|
83
106
|
├── registry/ # Token & hub configuration
|
|
84
|
-
├── onchain/ #
|
|
107
|
+
├── onchain/ # Contract interaction (ABI decoding, token reads)
|
|
85
108
|
└── utils/ # Shared utilities
|
|
86
109
|
```
|
|
87
110
|
|
|
88
111
|
## Key Modules
|
|
89
112
|
|
|
90
|
-
###
|
|
113
|
+
### WASM Configuration
|
|
91
114
|
|
|
92
|
-
|
|
115
|
+
Configure the WASM runtime for cryptographic operations:
|
|
93
116
|
|
|
94
117
|
```typescript
|
|
95
|
-
import {
|
|
118
|
+
import { configureWasmLocator } from "zerc20-client-sdk";
|
|
96
119
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
await runtime.ready();
|
|
100
|
-
|
|
101
|
-
// Or create a custom instance
|
|
102
|
-
const customRuntime = new WasmRuntime({
|
|
103
|
-
url: "https://example.com/zerc20_wasm_bg.wasm",
|
|
104
|
-
});
|
|
120
|
+
// Point to your hosted WASM binary
|
|
121
|
+
configureWasmLocator({ url: "/zerc20_wasm_bg.wasm" });
|
|
105
122
|
```
|
|
106
123
|
|
|
107
124
|
### StealthCanisterClient
|
|
@@ -133,7 +150,8 @@ import {
|
|
|
133
150
|
|
|
134
151
|
// Local unwrap with slippage protection
|
|
135
152
|
await unwrapWithLiquidityManager({
|
|
136
|
-
|
|
153
|
+
writeProvider,
|
|
154
|
+
readProvider,
|
|
137
155
|
liquidityManagerAddress,
|
|
138
156
|
zerc20TokenAddress,
|
|
139
157
|
amount: 1000n,
|
|
@@ -146,33 +164,265 @@ const quote = await buildCrossUnwrapQuote({
|
|
|
146
164
|
destinationToken,
|
|
147
165
|
amount: 1000n,
|
|
148
166
|
account,
|
|
167
|
+
readProviderSource: sourceReadProvider,
|
|
168
|
+
readProviderDestination: destReadProvider,
|
|
149
169
|
slippageBps: 50, // 0.5% slippage tolerance
|
|
150
170
|
});
|
|
151
171
|
```
|
|
152
172
|
|
|
153
|
-
###
|
|
173
|
+
### Adaptor Withdraw (Stuck Fund Recovery)
|
|
174
|
+
|
|
175
|
+
When a cross-chain unwrap fails (e.g. due to Stargate liquidity shortage), user funds may remain in the destination chain's Adaptor contract. The SDK provides functions to detect and recover these stuck funds:
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import {
|
|
179
|
+
fetchAdaptorBalances,
|
|
180
|
+
hasStuckFunds,
|
|
181
|
+
withdrawFromAdaptor,
|
|
182
|
+
NATIVE_TOKEN_ADDRESS,
|
|
183
|
+
} from "zerc20-client-sdk";
|
|
184
|
+
|
|
185
|
+
// Check if a user has stuck funds in an adaptor
|
|
186
|
+
const stuck = await hasStuckFunds({
|
|
187
|
+
provider: readProvider,
|
|
188
|
+
account: "0xUser...",
|
|
189
|
+
adaptorAddress: "0xAdaptor...",
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Fetch detailed balances
|
|
193
|
+
const balances = await fetchAdaptorBalances({
|
|
194
|
+
provider: readProvider,
|
|
195
|
+
account: "0xUser...",
|
|
196
|
+
adaptorAddress: "0xAdaptor...",
|
|
197
|
+
});
|
|
198
|
+
// balances.underlyingTokenBalance, balances.zerc20Balance, balances.nativeBalance
|
|
199
|
+
|
|
200
|
+
// Withdraw stuck funds
|
|
201
|
+
const result = await withdrawFromAdaptor({
|
|
202
|
+
writeProvider,
|
|
203
|
+
adaptorAddress: "0xAdaptor...",
|
|
204
|
+
token: balances.underlyingTokenAddress, // or zerc20TokenAddress, or NATIVE_TOKEN_ADDRESS
|
|
205
|
+
amount: balances.underlyingTokenBalance,
|
|
206
|
+
});
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### LayerZero Scan
|
|
210
|
+
|
|
211
|
+
Track and decode LayerZero cross-chain messages. Configuration and providers are injected as parameters, making this module framework-agnostic:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import {
|
|
215
|
+
fetchWalletStatus,
|
|
216
|
+
type FetchWalletStatusParams,
|
|
217
|
+
type LayerZeroScanConfig,
|
|
218
|
+
} from "zerc20-client-sdk";
|
|
219
|
+
|
|
220
|
+
const scanConfig: LayerZeroScanConfig = {
|
|
221
|
+
baseUrl: "https://scan.layerzero-api.com/v1/",
|
|
222
|
+
apiKey: "your-api-key", // optional
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const result = await fetchWalletStatus({
|
|
226
|
+
address: "0xuser",
|
|
227
|
+
tokens,
|
|
228
|
+
scanConfig,
|
|
229
|
+
createReadProvider: (token) => createPublicClient({ chain: ... }),
|
|
230
|
+
limit: 10,
|
|
231
|
+
filterByToken: true,
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// result.items: LayerZeroMessageSummary[]
|
|
235
|
+
// result.walletUrl: string (link to LZ Scan)
|
|
236
|
+
// result.nextToken: string | undefined (pagination cursor)
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Notes:
|
|
240
|
+
- `fetchWalletStatus` can use transaction input (`getTransaction`) and receipt logs (`getTransactionReceipt`) when available.
|
|
241
|
+
- If those methods are unavailable, decoding still falls back to payload-based paths where possible.
|
|
242
|
+
|
|
243
|
+
### Seed Derivation
|
|
244
|
+
|
|
245
|
+
Derive a seed from a wallet signature. The SDK handles the message retrieval, signature validation, and keccak256 hashing internally, while accepting a wallet-agnostic sign function:
|
|
246
|
+
|
|
247
|
+
```typescript
|
|
248
|
+
import { deriveSeed } from "zerc20-client-sdk";
|
|
249
|
+
|
|
250
|
+
// Works with any wallet library (wagmi, ethers.js, web3.js, etc.)
|
|
251
|
+
const seed = await deriveSeed(async (message) => {
|
|
252
|
+
// Return the signature as a 0x-prefixed hex string (65 bytes for personal_sign)
|
|
253
|
+
return wallet.signMessage(message);
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
The function validates that the returned signature is a valid hex string of exactly 65 bytes before hashing. Invalid signatures throw descriptive errors to prevent silent seed misderivation.
|
|
258
|
+
|
|
259
|
+
### Chain Metadata
|
|
260
|
+
|
|
261
|
+
Look up chain display names, short labels, block explorer URLs, and resolve chain name aliases — all from a single source of truth shared across products:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
import {
|
|
265
|
+
getChainMetadata,
|
|
266
|
+
getChainDisplayName,
|
|
267
|
+
getExplorerTxUrl,
|
|
268
|
+
resolveChainId,
|
|
269
|
+
resolveNetworkDisplayName,
|
|
270
|
+
} from "zerc20-client-sdk";
|
|
271
|
+
|
|
272
|
+
getChainDisplayName(42161); // "Arbitrum"
|
|
273
|
+
getChainDisplayName(999999); // "Chain 999999"
|
|
274
|
+
|
|
275
|
+
getExplorerTxUrl(42161, "0xabc..."); // "https://arbiscan.io/tx/0xabc..."
|
|
276
|
+
|
|
277
|
+
resolveChainId("arb-sepolia"); // 421614
|
|
278
|
+
resolveNetworkDisplayName("arb-sepolia"); // "Arbitrum Sepolia"
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Token Loading with RPC Overrides
|
|
282
|
+
|
|
283
|
+
Load and normalize token configuration with runtime RPC URL overrides (e.g. environment-specific Alchemy/Infura endpoints):
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import { normalizeTokensWithOverrides } from "zerc20-client-sdk";
|
|
287
|
+
import tokensJson from "./tokens.json";
|
|
288
|
+
|
|
289
|
+
const tokens = normalizeTokensWithOverrides(
|
|
290
|
+
tokensJson as TokensFile, // snake_case JSON is accepted as-is
|
|
291
|
+
{
|
|
292
|
+
tokens: {
|
|
293
|
+
"arb-mainnet": ["https://arb-mainnet.g.alchemy.com/v2/KEY"],
|
|
294
|
+
"base-mainnet": ["https://base-mainnet.g.alchemy.com/v2/KEY"],
|
|
295
|
+
},
|
|
296
|
+
hub: ["https://base-mainnet.g.alchemy.com/v2/KEY"],
|
|
297
|
+
},
|
|
298
|
+
);
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
Without overrides, `normalizeTokensWithOverrides(file)` behaves identically to `normalizeTokens(file)`.
|
|
302
|
+
|
|
303
|
+
### Redeem Flow
|
|
304
|
+
|
|
305
|
+
Prepare a redeem transaction from a collected redeem context. The SDK handles single vs batch proof selection, `GeneralRecipient` construction, and contract call parameter assembly internally:
|
|
154
306
|
|
|
155
307
|
```typescript
|
|
156
308
|
import {
|
|
309
|
+
collectRedeemContext,
|
|
310
|
+
prepareRedeemTransaction,
|
|
311
|
+
createTeleportProofClient,
|
|
157
312
|
HttpDeciderClient,
|
|
313
|
+
} from "zerc20-client-sdk";
|
|
314
|
+
|
|
315
|
+
// Initialize proof client and decider
|
|
316
|
+
const teleportProofClient = createTeleportProofClient();
|
|
317
|
+
const decider = new HttpDeciderClient("https://decider.example.com");
|
|
318
|
+
|
|
319
|
+
// 1. Collect redeem context (eligible events, proofs, etc.)
|
|
320
|
+
const redeemContext = await collectRedeemContext({ burn, tokens, hub, verifierContract, indexerUrl });
|
|
321
|
+
|
|
322
|
+
// 2. Prepare the transaction (SDK picks single vs batch automatically)
|
|
323
|
+
const tx = await prepareRedeemTransaction({
|
|
324
|
+
redeemContext,
|
|
325
|
+
burn,
|
|
326
|
+
teleportProofClient,
|
|
327
|
+
decider, // required only when eligible.length > 1
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
// 3. Submit via your wallet library
|
|
331
|
+
const hash = await walletClient.writeContract({
|
|
332
|
+
address: tx.address as `0x${string}`,
|
|
333
|
+
abi: tx.abi,
|
|
334
|
+
functionName: tx.functionName,
|
|
335
|
+
args: tx.args,
|
|
336
|
+
account,
|
|
337
|
+
chain,
|
|
338
|
+
});
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
The returned `RedeemTransaction` is pure data (`{ address, abi, functionName, args, mode }`) with no wallet dependency.
|
|
342
|
+
|
|
343
|
+
#### Manual batch flow with UI progress
|
|
344
|
+
|
|
345
|
+
For batch redeems, callers can use the 2-step proof API to insert UI updates between Nova and Decider steps:
|
|
346
|
+
|
|
347
|
+
```typescript
|
|
348
|
+
import {
|
|
349
|
+
collectRedeemContext,
|
|
350
|
+
buildBatchRedeemTransaction,
|
|
158
351
|
createTeleportProofClient,
|
|
159
|
-
|
|
352
|
+
HttpDeciderClient,
|
|
160
353
|
} from "zerc20-client-sdk";
|
|
161
354
|
|
|
162
|
-
const
|
|
163
|
-
|
|
355
|
+
const teleportProofClient = createTeleportProofClient();
|
|
356
|
+
const decider = new HttpDeciderClient("https://decider.example.com");
|
|
357
|
+
const redeemContext = await collectRedeemContext({ burn, tokens, hub, verifierContract, indexerUrl });
|
|
358
|
+
|
|
359
|
+
// Step 1: Nova proof
|
|
360
|
+
const novaResult = await teleportProofClient.createNovaProof({
|
|
361
|
+
aggregationState: redeemContext.aggregationState,
|
|
362
|
+
recipientFr: burn.generalRecipient.fr,
|
|
363
|
+
secretHex: burn.secret,
|
|
364
|
+
events: redeemContext.events.eligible,
|
|
365
|
+
proofs: redeemContext.globalProofs,
|
|
366
|
+
});
|
|
164
367
|
|
|
165
|
-
|
|
368
|
+
updateUI("Requesting decider proof…"); // ← insert UI update here
|
|
369
|
+
|
|
370
|
+
// Step 2: Decider proof
|
|
371
|
+
const deciderProof = await teleportProofClient.requestDeciderProof(decider, novaResult.ivcProof);
|
|
372
|
+
|
|
373
|
+
// Step 3: Build transaction
|
|
374
|
+
const tx = buildBatchRedeemTransaction({ redeemContext, burn, deciderProof });
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### LayerZero Decode Utilities
|
|
378
|
+
|
|
379
|
+
Decode LayerZero OFT transaction data — `send()` calldata, `OFTSent` event logs, and BridgeRequest compose messages:
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
import {
|
|
383
|
+
decodeSendPayload,
|
|
384
|
+
extractOftSentAmount,
|
|
385
|
+
decodeBridgeRequest,
|
|
386
|
+
} from "zerc20-client-sdk";
|
|
387
|
+
|
|
388
|
+
// Decode send() transaction input
|
|
389
|
+
const payload = decodeSendPayload(txData);
|
|
390
|
+
// → { dstEid, to, amountLD, minAmountLD, composeMsg }
|
|
391
|
+
|
|
392
|
+
// Extract amountReceivedLD from OFTSent event logs
|
|
393
|
+
const amount = extractOftSentAmount(receipt.logs);
|
|
394
|
+
|
|
395
|
+
// Decode a BridgeRequest compose message (returns null on failure)
|
|
396
|
+
const bridgeReq = decodeBridgeRequest(payload.composeMsg);
|
|
397
|
+
// → { dstEid, to, refundAddress, minAmountOut } | null
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
### Proof Generation
|
|
401
|
+
|
|
402
|
+
```typescript
|
|
403
|
+
import {
|
|
404
|
+
HttpDeciderClient,
|
|
405
|
+
createTeleportProofClient,
|
|
406
|
+
} from "zerc20-client-sdk";
|
|
407
|
+
|
|
408
|
+
const proofClient = createTeleportProofClient();
|
|
166
409
|
|
|
167
410
|
// Single teleport proof (Groth16)
|
|
168
411
|
const singleProof = await proofClient.createSingleTeleportProof(/* ... */);
|
|
169
412
|
|
|
170
|
-
// Batch teleport proof (Nova + Decider)
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
413
|
+
// Batch teleport proof (Nova + Decider) — two-step API
|
|
414
|
+
const novaResult = await proofClient.createNovaProof({
|
|
415
|
+
aggregationState,
|
|
416
|
+
recipientFr,
|
|
417
|
+
secretHex,
|
|
418
|
+
events,
|
|
419
|
+
proofs,
|
|
175
420
|
});
|
|
421
|
+
|
|
422
|
+
// Callers can update UI between steps (e.g. progress indicators)
|
|
423
|
+
|
|
424
|
+
const decider = new HttpDeciderClient("https://decider.example.com");
|
|
425
|
+
const deciderProof = await proofClient.requestDeciderProof(decider, novaResult.ivcProof);
|
|
176
426
|
```
|
|
177
427
|
|
|
178
428
|
## Development
|
|
@@ -201,7 +451,7 @@ npm run typecheck
|
|
|
201
451
|
npm test
|
|
202
452
|
```
|
|
203
453
|
|
|
204
|
-
**Current (as of 2026-
|
|
454
|
+
**Current (as of 2026-03-05): 943 passed, 2 skipped**
|
|
205
455
|
Note: This number will drift over time; treat `npm test` output as the source of truth.
|
|
206
456
|
|
|
207
457
|
### Skipped Tests
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.test.d.ts","sourceRoot":"","sources":["../../../src/chain/__tests__/metadata.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { getChainMetadata, getChainDisplayName, getChainShortName, getExplorerTxUrl, resolveChainId, resolveNetworkDisplayName, } from "../metadata.js";
|
|
3
|
+
// ── getChainMetadata ────────────────────────────────────────────────
|
|
4
|
+
describe("getChainMetadata", () => {
|
|
5
|
+
it.each([
|
|
6
|
+
[1, "Ethereum"],
|
|
7
|
+
[42161, "Arbitrum"],
|
|
8
|
+
[10, "Optimism"],
|
|
9
|
+
[8453, "Base"],
|
|
10
|
+
[56, "BNB Chain"],
|
|
11
|
+
[11155111, "Ethereum Sepolia"],
|
|
12
|
+
[421614, "Arbitrum Sepolia"],
|
|
13
|
+
[11155420, "Optimism Sepolia"],
|
|
14
|
+
[84532, "Base Sepolia"],
|
|
15
|
+
[97, "BNB Testnet"],
|
|
16
|
+
])("returns metadata for chain %i (%s)", (chainId, expectedName) => {
|
|
17
|
+
const meta = getChainMetadata(chainId);
|
|
18
|
+
expect(meta).toBeDefined();
|
|
19
|
+
expect(meta.name).toBe(expectedName);
|
|
20
|
+
expect(meta.shortName).toBeTruthy();
|
|
21
|
+
expect(meta.explorerUrl).toMatch(/^https:\/\//);
|
|
22
|
+
});
|
|
23
|
+
it("returns undefined for an unknown chain", () => {
|
|
24
|
+
expect(getChainMetadata(999999)).toBeUndefined();
|
|
25
|
+
});
|
|
26
|
+
it("accepts bigint chain IDs", () => {
|
|
27
|
+
expect(getChainMetadata(42161n)?.name).toBe("Arbitrum");
|
|
28
|
+
expect(getChainMetadata(999999n)).toBeUndefined();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
// ── getChainDisplayName ─────────────────────────────────────────────
|
|
32
|
+
describe("getChainDisplayName", () => {
|
|
33
|
+
it("returns the display name for known chains", () => {
|
|
34
|
+
expect(getChainDisplayName(42161)).toBe("Arbitrum");
|
|
35
|
+
expect(getChainDisplayName(11155111)).toBe("Ethereum Sepolia");
|
|
36
|
+
});
|
|
37
|
+
it("falls back to 'Chain {id}' for unknown chains", () => {
|
|
38
|
+
expect(getChainDisplayName(123456)).toBe("Chain 123456");
|
|
39
|
+
});
|
|
40
|
+
it("accepts bigint chain IDs", () => {
|
|
41
|
+
expect(getChainDisplayName(42161n)).toBe("Arbitrum");
|
|
42
|
+
expect(getChainDisplayName(123456n)).toBe("Chain 123456");
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
// ── getChainShortName ───────────────────────────────────────────────
|
|
46
|
+
describe("getChainShortName", () => {
|
|
47
|
+
it("returns short name for known chains", () => {
|
|
48
|
+
expect(getChainShortName(42161)).toBe("ARB");
|
|
49
|
+
expect(getChainShortName(10)).toBe("OP");
|
|
50
|
+
expect(getChainShortName(8453)).toBe("BASE");
|
|
51
|
+
});
|
|
52
|
+
it("returns undefined for unknown chains", () => {
|
|
53
|
+
expect(getChainShortName(999999)).toBeUndefined();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
// ── getExplorerTxUrl ────────────────────────────────────────────────
|
|
57
|
+
describe("getExplorerTxUrl", () => {
|
|
58
|
+
const txHash = "0xabc123";
|
|
59
|
+
it.each([
|
|
60
|
+
[1, "https://etherscan.io/tx/0xabc123"],
|
|
61
|
+
[42161, "https://arbiscan.io/tx/0xabc123"],
|
|
62
|
+
[10, "https://optimistic.etherscan.io/tx/0xabc123"],
|
|
63
|
+
[8453, "https://basescan.org/tx/0xabc123"],
|
|
64
|
+
[56, "https://bscscan.com/tx/0xabc123"],
|
|
65
|
+
[11155111, "https://sepolia.etherscan.io/tx/0xabc123"],
|
|
66
|
+
[421614, "https://sepolia.arbiscan.io/tx/0xabc123"],
|
|
67
|
+
[11155420, "https://sepolia-optimism.etherscan.io/tx/0xabc123"],
|
|
68
|
+
[84532, "https://sepolia.basescan.org/tx/0xabc123"],
|
|
69
|
+
[97, "https://testnet.bscscan.com/tx/0xabc123"],
|
|
70
|
+
])("builds correct URL for chain %i", (chainId, expectedUrl) => {
|
|
71
|
+
expect(getExplorerTxUrl(chainId, txHash)).toBe(expectedUrl);
|
|
72
|
+
});
|
|
73
|
+
it("returns undefined for unknown chain", () => {
|
|
74
|
+
expect(getExplorerTxUrl(999999, txHash)).toBeUndefined();
|
|
75
|
+
});
|
|
76
|
+
it("accepts bigint chain IDs", () => {
|
|
77
|
+
expect(getExplorerTxUrl(42161n, txHash)).toBe("https://arbiscan.io/tx/0xabc123");
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
// ── resolveChainId ──────────────────────────────────────────────────
|
|
81
|
+
describe("resolveChainId", () => {
|
|
82
|
+
it.each([
|
|
83
|
+
// mainnet names
|
|
84
|
+
["ethereum", 1],
|
|
85
|
+
["eth", 1],
|
|
86
|
+
["eth-mainnet", 1],
|
|
87
|
+
["arbitrum", 42161],
|
|
88
|
+
["arb", 42161],
|
|
89
|
+
["arb-mainnet", 42161],
|
|
90
|
+
["optimism", 10],
|
|
91
|
+
["op", 10],
|
|
92
|
+
["op-mainnet", 10],
|
|
93
|
+
["base", 8453],
|
|
94
|
+
["base-mainnet", 8453],
|
|
95
|
+
["bnb", 56],
|
|
96
|
+
["bsc", 56],
|
|
97
|
+
// testnet names
|
|
98
|
+
["sepolia", 11155111],
|
|
99
|
+
["ethereum-sepolia", 11155111],
|
|
100
|
+
["arb-sepolia", 421614],
|
|
101
|
+
["arbitrum-sepolia", 421614],
|
|
102
|
+
["op-sepolia", 11155420],
|
|
103
|
+
["optimism-sepolia", 11155420],
|
|
104
|
+
["base-sepolia", 84532],
|
|
105
|
+
["bnb-testnet", 97],
|
|
106
|
+
["bsc-testnet", 97],
|
|
107
|
+
])("resolves '%s' → %i", (name, expectedId) => {
|
|
108
|
+
expect(resolveChainId(name)).toBe(expectedId);
|
|
109
|
+
});
|
|
110
|
+
it("is case-insensitive", () => {
|
|
111
|
+
expect(resolveChainId("Ethereum")).toBe(1);
|
|
112
|
+
expect(resolveChainId("ARB-SEPOLIA")).toBe(421614);
|
|
113
|
+
expect(resolveChainId(" Base ")).toBe(8453);
|
|
114
|
+
});
|
|
115
|
+
it("returns undefined for unknown names", () => {
|
|
116
|
+
expect(resolveChainId("solana")).toBeUndefined();
|
|
117
|
+
expect(resolveChainId("")).toBeUndefined();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
// ── resolveNetworkDisplayName ───────────────────────────────────────
|
|
121
|
+
describe("resolveNetworkDisplayName", () => {
|
|
122
|
+
it.each([
|
|
123
|
+
["sepolia", "Ethereum Sepolia"],
|
|
124
|
+
["arb-sepolia", "Arbitrum Sepolia"],
|
|
125
|
+
["op-sepolia", "Optimism Sepolia"],
|
|
126
|
+
["base-sepolia", "Base Sepolia"],
|
|
127
|
+
["bnb-testnet", "BNB Testnet"],
|
|
128
|
+
["bsc-testnet", "BNB Testnet"],
|
|
129
|
+
["ethereum-sepolia", "Ethereum Sepolia"],
|
|
130
|
+
["arbitrum-sepolia", "Arbitrum Sepolia"],
|
|
131
|
+
["optimism-sepolia", "Optimism Sepolia"],
|
|
132
|
+
["eth-mainnet", "Ethereum"],
|
|
133
|
+
["arb-mainnet", "Arbitrum"],
|
|
134
|
+
["op-mainnet", "Optimism"],
|
|
135
|
+
["base-mainnet", "Base"],
|
|
136
|
+
["ethereum", "Ethereum"],
|
|
137
|
+
["arbitrum", "Arbitrum"],
|
|
138
|
+
["optimism", "Optimism"],
|
|
139
|
+
["base", "Base"],
|
|
140
|
+
["bsc", "BNB Chain"],
|
|
141
|
+
["arb", "Arbitrum"],
|
|
142
|
+
["op", "Optimism"],
|
|
143
|
+
["bnb", "BNB Chain"],
|
|
144
|
+
])("resolves '%s' → '%s'", (label, expected) => {
|
|
145
|
+
expect(resolveNetworkDisplayName(label)).toBe(expected);
|
|
146
|
+
});
|
|
147
|
+
it("is case-insensitive", () => {
|
|
148
|
+
expect(resolveNetworkDisplayName("ETHEREUM")).toBe("Ethereum");
|
|
149
|
+
expect(resolveNetworkDisplayName("Arb-Sepolia")).toBe("Arbitrum Sepolia");
|
|
150
|
+
});
|
|
151
|
+
it("capitalizes unknown labels as fallback", () => {
|
|
152
|
+
expect(resolveNetworkDisplayName("polygon")).toBe("Polygon");
|
|
153
|
+
expect(resolveNetworkDisplayName("mychain")).toBe("Mychain");
|
|
154
|
+
});
|
|
155
|
+
it("trims whitespace and preserves original casing in fallback", () => {
|
|
156
|
+
expect(resolveNetworkDisplayName(" polygon ")).toBe("Polygon");
|
|
157
|
+
expect(resolveNetworkDisplayName("POLYGON")).toBe("POLYGON");
|
|
158
|
+
expect(resolveNetworkDisplayName(" MYCHAIN ")).toBe("MYCHAIN");
|
|
159
|
+
expect(resolveNetworkDisplayName("FOOBar")).toBe("FOOBar");
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
//# sourceMappingURL=metadata.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.test.js","sourceRoot":"","sources":["../../../src/chain/__tests__/metadata.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAExB,uEAAuE;AAEvE,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,EAAE,CAAC,IAAI,CAAC;QACN,CAAC,CAAC,EAAE,UAAU,CAAC;QACf,CAAC,KAAK,EAAE,UAAU,CAAC;QACnB,CAAC,EAAE,EAAE,UAAU,CAAC;QAChB,CAAC,IAAI,EAAE,MAAM,CAAC;QACd,CAAC,EAAE,EAAE,WAAW,CAAC;QACjB,CAAC,QAAQ,EAAE,kBAAkB,CAAC;QAC9B,CAAC,MAAM,EAAE,kBAAkB,CAAC;QAC5B,CAAC,QAAQ,EAAE,kBAAkB,CAAC;QAC9B,CAAC,KAAK,EAAE,cAAc,CAAC;QACvB,CAAC,EAAE,EAAE,aAAa,CAAC;KACpB,CAAC,CAAC,oCAAoC,EAAE,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE;QACjE,MAAM,IAAI,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;QAC3B,MAAM,CAAC,IAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtC,MAAM,CAAC,IAAK,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;QACrC,MAAM,CAAC,IAAK,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC,CAAC,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AC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC7D,MAAM,CAAC,yBAAyB,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACjE,MAAM,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/chain/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,yBAAyB,GAC1B,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chain/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,yBAAyB,GAC1B,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ChainMetadata } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Returns chain metadata for the given chain ID, or `undefined` if unknown.
|
|
4
|
+
* Accepts both `number` and `bigint` to align with SDK's `TokenEntry.chainId`.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getChainMetadata(chainId: number | bigint): ChainMetadata | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Returns a human-readable chain name.
|
|
9
|
+
* Falls back to `"Chain {chainId}"` when the chain is not recognised.
|
|
10
|
+
*/
|
|
11
|
+
export declare function getChainDisplayName(chainId: number | bigint): string;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the short label for a chain (e.g. "ARB", "ETH").
|
|
14
|
+
* Falls back to `undefined` when the chain is not recognised.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getChainShortName(chainId: number | bigint): string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Builds a block-explorer transaction URL.
|
|
19
|
+
* Returns `undefined` when the chain is not recognised.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getExplorerTxUrl(chainId: number | bigint, txHash: string): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Resolves a chain name or token label to an EVM chain ID.
|
|
24
|
+
* The lookup is case-insensitive.
|
|
25
|
+
* Returns `undefined` when the name is not recognised.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveChainId(name: string): number | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Converts a token / network label (e.g. "arb-sepolia", "ethereum")
|
|
30
|
+
* to a user-friendly display name (e.g. "Arbitrum Sepolia", "Ethereum").
|
|
31
|
+
*
|
|
32
|
+
* Resolution order:
|
|
33
|
+
* 1. Override table ({@link LABEL_DISPLAY_OVERRIDES})
|
|
34
|
+
* 2. Resolve label → chainId → metadata name
|
|
35
|
+
* 3. Capitalize the first letter of the label as a last resort
|
|
36
|
+
*/
|
|
37
|
+
export declare function resolveNetworkDisplayName(label: string): string;
|
|
38
|
+
//# sourceMappingURL=metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../../src/chain/metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAmGhD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,aAAa,GAAG,SAAS,CAEpF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAGpE;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAE9E;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAI7F;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAE/D;AAED;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAgB/D"}
|