@wonderland/interop 0.2.0 → 0.3.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 +103 -38
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -10,15 +10,15 @@ This package combines two powerful functionalities:
|
|
|
10
10
|
|
|
11
11
|
```mermaid
|
|
12
12
|
graph LR
|
|
13
|
-
A[
|
|
13
|
+
A[interoperableName]
|
|
14
14
|
C[binaryRepresentation]
|
|
15
15
|
D[chainId]
|
|
16
16
|
E[address]
|
|
17
17
|
F[Cross-Chain Operations]
|
|
18
18
|
G[Token Transfers]
|
|
19
19
|
|
|
20
|
-
A -->|
|
|
21
|
-
C -->|
|
|
20
|
+
A -->|nameToBinary| C
|
|
21
|
+
C -->|binaryToName| A
|
|
22
22
|
C -->|getChainId| D
|
|
23
23
|
C -->|getAddress| E
|
|
24
24
|
F -->|Transfer| G
|
|
@@ -49,38 +49,74 @@ Available scripts that can be run using `pnpm`:
|
|
|
49
49
|
### Interoperable Addresses
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
|
-
|
|
53
|
-
import { InteropAddressProvider } from '@wonderland/interop';
|
|
52
|
+
import { InteropAddressProvider, nameToBinary } from "@wonderland/interop";
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
const
|
|
54
|
+
// Using the Provider
|
|
55
|
+
const interoperableName = "alice.eth@eip155:1#ABCD1234";
|
|
56
|
+
const binaryAddress = await InteropAddressProvider.nameToBinary(interoperableName);
|
|
57
57
|
|
|
58
|
-
// Or just importing the method
|
|
59
|
-
|
|
60
|
-
const binaryAddress = humanReadableToBinary(humanReadableAddress)
|
|
58
|
+
// Or just importing the method directly
|
|
59
|
+
const binaryAddress2 = await nameToBinary("alice.eth@eip155:1#ABCD1234");
|
|
61
60
|
```
|
|
62
61
|
|
|
63
62
|
### Cross-Chain Operations
|
|
64
63
|
|
|
65
64
|
```typescript
|
|
66
65
|
import { createCrossChainProvider } from "@wonderland/interop";
|
|
66
|
+
import { createPublicClient, createWalletClient, http } from "viem";
|
|
67
|
+
import { mainnet } from "viem/chains";
|
|
67
68
|
|
|
68
|
-
// Create a provider
|
|
69
|
+
// Create a provider - Across works with no config (defaults to mainnet)
|
|
70
|
+
// Mainnet: https://app.across.to/api
|
|
71
|
+
// Testnet: https://testnet.across.to/api
|
|
69
72
|
const provider = createCrossChainProvider("across");
|
|
70
73
|
|
|
71
|
-
//
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
74
|
+
// Or with testnet config
|
|
75
|
+
const testnetProvider = createCrossChainProvider("across", { isTestnet: true });
|
|
76
|
+
|
|
77
|
+
// Get quotes using OIF format (addresses must be EIP-7930 binary format: 0x0001...)
|
|
78
|
+
// Use nameToBinary() from @wonderland/interop-addresses to convert human-readable addresses
|
|
79
|
+
const quotes = await provider.getQuotes({
|
|
80
|
+
user: "0x0001000aa36a7114...", // binary format address
|
|
81
|
+
intent: {
|
|
82
|
+
intentType: "oif-swap",
|
|
83
|
+
inputs: [
|
|
84
|
+
{
|
|
85
|
+
user: "0x0001000aa36a7114...",
|
|
86
|
+
asset: "0x0001000aa36a7114...",
|
|
87
|
+
amount: "1000000000000000000",
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
outputs: [
|
|
91
|
+
{
|
|
92
|
+
receiver: "0x0001000149d4114...",
|
|
93
|
+
asset: "0x0001000149d4114...",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
swapType: "exact-input",
|
|
97
|
+
},
|
|
98
|
+
supportedTypes: ["oif-escrow-v0"],
|
|
80
99
|
});
|
|
81
100
|
|
|
82
|
-
//
|
|
83
|
-
const
|
|
101
|
+
// Execute the quote
|
|
102
|
+
const quote = quotes[0];
|
|
103
|
+
const walletClient = createWalletClient({
|
|
104
|
+
chain: mainnet,
|
|
105
|
+
transport: http("https://..."),
|
|
106
|
+
account: "0x...",
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Option 1 - User Mode: send transaction directly (Across, OIF user-open)
|
|
110
|
+
if (quote?.preparedTransaction) {
|
|
111
|
+
const hash = await walletClient.sendTransaction(quote.preparedTransaction);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Option 2 - Protocol Mode: sign and submit order (OIF escrow - gasless for user)
|
|
115
|
+
if (quote?.order.type === "oif-escrow-v0") {
|
|
116
|
+
const { domain, primaryType, message, types } = quote.order.payload;
|
|
117
|
+
const signature = await walletClient.signTypedData({ domain, primaryType, message, types });
|
|
118
|
+
await provider.submitSignedOrder(quote, signature);
|
|
119
|
+
}
|
|
84
120
|
```
|
|
85
121
|
|
|
86
122
|
## API
|
|
@@ -91,41 +127,70 @@ const transactions = await provider.simulateOpen(quote.openParams);
|
|
|
91
127
|
|
|
92
128
|
Available methods:
|
|
93
129
|
|
|
94
|
-
- `
|
|
95
|
-
- `
|
|
96
|
-
- `getChainId(
|
|
97
|
-
- `getAddress(
|
|
98
|
-
- `
|
|
99
|
-
- `computeChecksum(
|
|
130
|
+
- `nameToBinary(interoperableName: string)` – Convert human-readable address to binary format
|
|
131
|
+
- `binaryToName(binaryAddress: Hex)` – Convert binary address to human-readable format
|
|
132
|
+
- `getChainId(address: string)` – Extract chain ID from an address
|
|
133
|
+
- `getAddress(address: string)` – Extract the underlying address
|
|
134
|
+
- `encodeAddress(payload: InteroperableAddress, opts?: { format: "hex" | "bytes" })` – Create binary address from components
|
|
135
|
+
- `computeChecksum(interoperableName: string)` – Compute checksum for an address
|
|
100
136
|
|
|
101
137
|
### Cross-Chain Operations
|
|
102
138
|
|
|
103
|
-
#### [
|
|
139
|
+
#### [createCrossChainProvider](./src/services/crossChainProviderFactory.ts)
|
|
104
140
|
|
|
105
|
-
|
|
141
|
+
Creates a provider for the specified protocol:
|
|
106
142
|
|
|
107
|
-
|
|
143
|
+
```typescript
|
|
144
|
+
// Across - config optional (defaults to mainnet)
|
|
145
|
+
const acrossProvider = createCrossChainProvider("across");
|
|
146
|
+
const testnetProvider = createCrossChainProvider("across", { isTestnet: true });
|
|
147
|
+
|
|
148
|
+
// OIF - config required
|
|
149
|
+
const oifProvider = createCrossChainProvider("oif", {
|
|
150
|
+
solverId: "my-solver",
|
|
151
|
+
url: "https://solver.example.com",
|
|
152
|
+
});
|
|
153
|
+
```
|
|
108
154
|
|
|
109
|
-
|
|
110
|
-
- `createCrossChainProvider<Protocol>(protocolName: Protocol, config?: Config, dependencies?: Dependencies)`: Helper function to create a provider instance
|
|
155
|
+
#### CrossChainProvider
|
|
111
156
|
|
|
112
|
-
|
|
157
|
+
All providers implement these methods:
|
|
113
158
|
|
|
114
|
-
|
|
159
|
+
- `.getQuotes(params)` – Returns `ExecutableQuote[]`. Fetch quotes for a cross-chain request (OIF GetQuoteRequest format).
|
|
160
|
+
- `.submitSignedOrder(quote, signature)` – Submit a signed order (OIF escrow mode). Throws for Across.
|
|
161
|
+
- `.getProtocolName()` – Returns the protocol name.
|
|
162
|
+
- `.getProviderId()` – Returns the provider identifier.
|
|
163
|
+
- `.getTrackingConfig()` – Get configuration for intent tracking.
|
|
115
164
|
|
|
116
|
-
|
|
165
|
+
#### [ProviderExecutor](./src/services/providerExecutor.ts)
|
|
117
166
|
|
|
118
|
-
|
|
119
|
-
|
|
167
|
+
For comparing quotes across multiple providers:
|
|
168
|
+
|
|
169
|
+
```typescript
|
|
170
|
+
import { createProviderExecutor } from "@wonderland/interop";
|
|
171
|
+
|
|
172
|
+
const executor = createProviderExecutor({
|
|
173
|
+
providers: [acrossProvider, oifProvider],
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Returns { quotes: ExecutableQuote[], errors: GetQuotesError[] }
|
|
177
|
+
const response = await executor.getQuotes({
|
|
178
|
+
/* ... */
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const bestQuote = response.quotes[0]; // Sorted by best output
|
|
182
|
+
```
|
|
120
183
|
|
|
121
184
|
Supported protocols:
|
|
122
185
|
|
|
123
186
|
- Across Protocol
|
|
187
|
+
- OIF (Open Intents Framework)
|
|
124
188
|
- More protocols coming soon...
|
|
125
189
|
|
|
126
190
|
## References
|
|
127
191
|
|
|
128
192
|
- [ERC 7930: Interoperable Addresses](https://ethereum-magicians.org/t/erc-7930-interoperable-addresses/23365)
|
|
193
|
+
- [Open Intents Framework](https://docs.openintents.xyz/) - OIF API specification
|
|
129
194
|
- [Viem Documentation](https://viem.sh/) - Low-level Ethereum interface used for transaction handling
|
|
130
195
|
- [Zod Documentation](https://zod.dev/) - TypeScript-first schema validation used for input validation
|
|
131
196
|
- [Cross-Chain Interoperability Standards](https://ethereum.org/en/developers/docs/bridges/) - Overview of cross-chain bridge concepts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wonderland/interop",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Complete SDK for blockchain interoperability with cross-chain operations and address utilities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"test:cov": "vitest run --config vitest.config.ts --coverage"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@wonderland/interop-addresses": "0.
|
|
36
|
-
"@wonderland/interop-cross-chain": "0.
|
|
35
|
+
"@wonderland/interop-addresses": "0.4.0",
|
|
36
|
+
"@wonderland/interop-cross-chain": "0.3.0"
|
|
37
37
|
}
|
|
38
38
|
}
|