@snowbridge/registry 0.3.3 → 0.4.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.
- package/.turbo/turbo-build.log +1 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -2
- package/dist/paseo_sepolia_bridge_info.g.d.ts +330 -0
- package/dist/paseo_sepolia_bridge_info.g.d.ts.map +1 -0
- package/dist/paseo_sepolia_bridge_info.g.js +350 -0
- package/dist/polkadot_mainnet_bridge_info.g.d.ts +1983 -0
- package/dist/polkadot_mainnet_bridge_info.g.d.ts.map +1 -0
- package/dist/polkadot_mainnet_bridge_info.g.js +2264 -0
- package/dist/transfers.d.ts +3 -8
- package/dist/transfers.d.ts.map +1 -1
- package/dist/transfers.js +54 -215
- package/dist/westend_sepolia_bridge_info.g.d.ts +344 -0
- package/dist/westend_sepolia_bridge_info.g.d.ts.map +1 -0
- package/dist/westend_sepolia_bridge_info.g.js +376 -0
- package/package.json +5 -5
- package/scripts/buildRegistry.ts +466 -29
- package/src/index.ts +24 -2
- package/src/paseo_sepolia_bridge_info.g.ts +349 -0
- package/src/polkadot_mainnet_bridge_info.g.ts +2287 -0
- package/src/transfers.ts +58 -266
- package/src/westend_sepolia_bridge_info.g.ts +384 -0
- package/dist/environment.d.ts +0 -3
- package/dist/environment.d.ts.map +0 -1
- package/dist/environment.js +0 -181
- package/dist/local_e2e.registry.json +0 -391
- package/dist/paseo_sepolia.registry.json +0 -231
- package/dist/polkadot_mainnet.registry.json +0 -1805
- package/dist/registry.d.ts +0 -3
- package/dist/registry.d.ts.map +0 -1
- package/dist/registry.js +0 -61
- package/dist/westend_sepolia.registry.json +0 -283
- package/src/environment.ts +0 -185
- package/src/local_e2e.registry.json +0 -391
- package/src/paseo_sepolia.registry.json +0 -231
- package/src/polkadot_mainnet.registry.json +0 -1805
- package/src/registry.ts +0 -63
- package/src/westend_sepolia.registry.json +0 -283
package/src/transfers.ts
CHANGED
|
@@ -1,290 +1,82 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AssetRegistry,
|
|
3
|
-
Environment,
|
|
4
|
-
EthereumChain,
|
|
5
|
-
Parachain,
|
|
6
|
-
Path,
|
|
7
|
-
Source,
|
|
8
|
-
SourceType,
|
|
9
3
|
TransferLocation,
|
|
4
|
+
Source,
|
|
5
|
+
ChainKey,
|
|
6
|
+
ChainKind,
|
|
7
|
+
ChainId,
|
|
8
|
+
TransferRoute,
|
|
10
9
|
} from "@snowbridge/base-types"
|
|
11
|
-
import { environmentFor } from "./environment"
|
|
12
|
-
import { assetRegistryFor } from "./registry"
|
|
13
|
-
|
|
14
|
-
const cache: { [env: string]: Source[] } = {}
|
|
15
|
-
export function transferSourcesFor(
|
|
16
|
-
env: "polkadot_mainnet" | "westend_sepolia" | "paseo_sepolia" | (string & {}),
|
|
17
|
-
): Source[] {
|
|
18
|
-
if (env in cache) {
|
|
19
|
-
return cache[env]
|
|
20
|
-
}
|
|
21
|
-
return getTransferLocations(assetRegistryFor(env))
|
|
22
|
-
}
|
|
23
10
|
|
|
24
|
-
export function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
name:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
ethChain,
|
|
11
|
+
export function getTransferLocation(registry: AssetRegistry, chain: ChainId): TransferLocation {
|
|
12
|
+
let location: TransferLocation | null = null
|
|
13
|
+
if (chain.kind === "kusama" && registry.kusama) {
|
|
14
|
+
const parachain = registry.kusama.parachains[`${chain.kind}_${chain.id}`]
|
|
15
|
+
location = {
|
|
16
|
+
id: parachain.id,
|
|
17
|
+
kind: parachain.kind,
|
|
18
|
+
name: parachain.info.name,
|
|
19
|
+
key: parachain.key,
|
|
20
|
+
parachain,
|
|
35
21
|
}
|
|
36
|
-
} else {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
id:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
parachain: evmChain,
|
|
22
|
+
} else if (chain.kind === "polkadot") {
|
|
23
|
+
const parachain = registry.parachains[`${chain.kind}_${chain.id}`]
|
|
24
|
+
location = {
|
|
25
|
+
id: parachain.id,
|
|
26
|
+
kind: parachain.kind,
|
|
27
|
+
name: parachain.info.name,
|
|
28
|
+
key: parachain.key,
|
|
29
|
+
parachain,
|
|
45
30
|
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
parachain,
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function getTransferLocation(
|
|
60
|
-
registry: AssetRegistry,
|
|
61
|
-
sourceType: string,
|
|
62
|
-
sourceKey: string,
|
|
63
|
-
): TransferLocation {
|
|
64
|
-
if (sourceType === "ethereum") {
|
|
65
|
-
return getEthereumTransferLocation(registry, registry.ethereumChains[sourceKey])
|
|
66
|
-
} else {
|
|
67
|
-
return getSubstrateTransferLocation(registry.parachains[sourceKey])
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function getTransferLocationKusama(
|
|
72
|
-
registry: AssetRegistry,
|
|
73
|
-
network: string,
|
|
74
|
-
parachainId: string,
|
|
75
|
-
): TransferLocation {
|
|
76
|
-
if (network === "kusama" && registry.kusama) {
|
|
77
|
-
return getSubstrateTransferLocation(registry.kusama?.parachains[parachainId])
|
|
78
|
-
} else {
|
|
79
|
-
return getSubstrateTransferLocation(registry.parachains[parachainId])
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function getTransferLocations(
|
|
84
|
-
registry: AssetRegistry,
|
|
85
|
-
filter?: (path: Path) => boolean,
|
|
86
|
-
): Source[] {
|
|
87
|
-
const ethChain = registry.ethereumChains[registry.ethChainId]
|
|
88
|
-
const parachains = Object.keys(registry.parachains)
|
|
89
|
-
.filter((p) => p !== registry.bridgeHubParaId.toString())
|
|
90
|
-
.map((p) => registry.parachains[p])
|
|
91
|
-
|
|
92
|
-
const pathFilter = filter ?? defaultPathFilter(registry.environment)
|
|
93
|
-
|
|
94
|
-
const locations: Path[] = []
|
|
95
|
-
|
|
96
|
-
const ethAssets = Object.keys(ethChain.assets)
|
|
97
|
-
// Bridged paths
|
|
98
|
-
for (const parachain of parachains) {
|
|
99
|
-
const destinationAssets = Object.keys(parachain.assets)
|
|
100
|
-
const commonAssets = new Set(
|
|
101
|
-
ethAssets.filter((sa) => destinationAssets.find((da) => da === sa)),
|
|
102
|
-
)
|
|
103
|
-
for (const asset of commonAssets) {
|
|
104
|
-
const p1: Path = {
|
|
105
|
-
type: "ethereum",
|
|
106
|
-
id: "ethereum",
|
|
107
|
-
source: ethChain.chainId,
|
|
108
|
-
destinationType: "substrate",
|
|
109
|
-
destination: parachain.parachainId,
|
|
110
|
-
asset,
|
|
31
|
+
} else if (chain.kind === "ethereum") {
|
|
32
|
+
const ethChain = registry.ethereumChains[`${chain.kind}_${chain.id}`]
|
|
33
|
+
if (!ethChain.evmParachainId) {
|
|
34
|
+
location = {
|
|
35
|
+
kind: ethChain.kind,
|
|
36
|
+
id: ethChain.id,
|
|
37
|
+
key: ethChain.key,
|
|
38
|
+
name: "Ethereum",
|
|
39
|
+
ethChain,
|
|
111
40
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
asset,
|
|
122
|
-
}
|
|
123
|
-
if (pathFilter(p2)) {
|
|
124
|
-
locations.push(p2)
|
|
125
|
-
}
|
|
126
|
-
if (parachain.info.evmChainId && registry.ethereumChains[parachain.info.evmChainId]) {
|
|
127
|
-
const p3: Path = {
|
|
128
|
-
type: "ethereum",
|
|
129
|
-
id: `${parachain.info.specName}_evm`,
|
|
130
|
-
source: parachain.info.evmChainId,
|
|
131
|
-
destinationType: "ethereum",
|
|
132
|
-
destination: ethChain.chainId,
|
|
133
|
-
asset,
|
|
134
|
-
}
|
|
135
|
-
if (pathFilter(p3)) {
|
|
136
|
-
locations.push(p3)
|
|
137
|
-
}
|
|
41
|
+
} else {
|
|
42
|
+
const evmChain = registry.parachains[`polkadot_${ethChain.evmParachainId}`]
|
|
43
|
+
location = {
|
|
44
|
+
kind: ethChain.kind,
|
|
45
|
+
id: ethChain.id,
|
|
46
|
+
key: ethChain.key,
|
|
47
|
+
name: `${evmChain.info.name} (EVM)`,
|
|
48
|
+
ethChain,
|
|
49
|
+
parachain: evmChain,
|
|
138
50
|
}
|
|
139
51
|
}
|
|
140
52
|
}
|
|
141
53
|
|
|
142
|
-
|
|
143
|
-
const assetHub = registry.parachains[registry.assetHubParaId]
|
|
144
|
-
for (const parachain of parachains) {
|
|
145
|
-
if (parachain.parachainId === assetHub.parachainId) continue
|
|
146
|
-
const assetHubAssets = Object.keys(assetHub.assets)
|
|
147
|
-
const destinationAssets = Object.keys(parachain.assets)
|
|
54
|
+
if (location === null) throw Error(`Unknown ${chain.kind} chain ${chain.id}.`)
|
|
148
55
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
ethAssets.filter(
|
|
152
|
-
(sa) =>
|
|
153
|
-
assetHubAssets.find((da) => da === sa) &&
|
|
154
|
-
destinationAssets.find((da) => da === sa),
|
|
155
|
-
),
|
|
156
|
-
)
|
|
157
|
-
for (const asset of commonAssets) {
|
|
158
|
-
const p1: Path = {
|
|
159
|
-
type: "substrate",
|
|
160
|
-
id: assetHub.info.specName,
|
|
161
|
-
source: assetHub.parachainId,
|
|
162
|
-
destinationType: "substrate",
|
|
163
|
-
destination: parachain.parachainId,
|
|
164
|
-
asset,
|
|
165
|
-
}
|
|
166
|
-
if (pathFilter(p1)) {
|
|
167
|
-
locations.push(p1)
|
|
168
|
-
}
|
|
169
|
-
const p2: Path = {
|
|
170
|
-
type: "substrate",
|
|
171
|
-
id: parachain.info.specName,
|
|
172
|
-
source: parachain.parachainId,
|
|
173
|
-
destinationType: "substrate",
|
|
174
|
-
destination: assetHub.parachainId,
|
|
175
|
-
asset,
|
|
176
|
-
}
|
|
177
|
-
if (pathFilter(p2)) {
|
|
178
|
-
locations.push(p2)
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
56
|
+
return location
|
|
57
|
+
}
|
|
182
58
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
s.type === location.type &&
|
|
188
|
-
s.id === location.id &&
|
|
189
|
-
s.key === location.source.toString(),
|
|
190
|
-
)
|
|
59
|
+
export function getTransferLocations(routes: readonly TransferRoute[]): Source[] {
|
|
60
|
+
let sources: Source[] = []
|
|
61
|
+
for (const route of routes) {
|
|
62
|
+
let source = sources.find((s) => s.id === route.from.id && s.kind === route.from.kind)
|
|
191
63
|
if (!source) {
|
|
192
64
|
source = {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
key: location.source.toString(),
|
|
65
|
+
key: `${route.from.kind}_${route.from.id}`,
|
|
66
|
+
...route.from,
|
|
196
67
|
destinations: {},
|
|
197
68
|
}
|
|
198
|
-
|
|
69
|
+
sources.push(source)
|
|
199
70
|
}
|
|
200
|
-
|
|
201
|
-
|
|
71
|
+
const destId: ChainKey<ChainKind> = `${route.to.kind}_${route.to.id}`
|
|
72
|
+
let destination = source.destinations[destId]
|
|
202
73
|
if (!destination) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
return results
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
export function defaultPathFilter(envName: string): (_: Path) => boolean {
|
|
212
|
-
switch (envName) {
|
|
213
|
-
case "westend_sepolia": {
|
|
214
|
-
return (path: Path) => {
|
|
215
|
-
// Frequency
|
|
216
|
-
if (path.asset === "0x72c610e05eaafcdf1fa7a2da15374ee90edb1620") {
|
|
217
|
-
return false
|
|
218
|
-
}
|
|
219
|
-
// Disable para to para transfers
|
|
220
|
-
if (path.type === "substrate" && path.destinationType === "substrate") {
|
|
221
|
-
return false
|
|
222
|
-
}
|
|
223
|
-
return true
|
|
74
|
+
source.destinations[destId] = {
|
|
75
|
+
key: destId,
|
|
76
|
+
...route.to,
|
|
77
|
+
assets: [...route.assets],
|
|
224
78
|
}
|
|
225
79
|
}
|
|
226
|
-
case "paseo_sepolia":
|
|
227
|
-
return (path: Path) => {
|
|
228
|
-
// Disallow MUSE to any location but 3369
|
|
229
|
-
if (
|
|
230
|
-
path.asset === "0xb34a6924a02100ba6ef12af1c798285e8f7a16ee" &&
|
|
231
|
-
((path.destination !== 3369 && path.type === "ethereum") ||
|
|
232
|
-
(path.source !== 3369 && path.type === "substrate"))
|
|
233
|
-
) {
|
|
234
|
-
return false
|
|
235
|
-
}
|
|
236
|
-
// Disable para to para transfers
|
|
237
|
-
if (path.type === "substrate" && path.destinationType === "substrate") {
|
|
238
|
-
return false
|
|
239
|
-
}
|
|
240
|
-
return true
|
|
241
|
-
}
|
|
242
|
-
case "polkadot_mainnet":
|
|
243
|
-
return (path: Path) => {
|
|
244
|
-
// Disallow MYTH to any location but 3369
|
|
245
|
-
if (
|
|
246
|
-
path.asset === "0xba41ddf06b7ffd89d1267b5a93bfef2424eb2003" &&
|
|
247
|
-
((path.destination !== 3369 && path.type === "ethereum") ||
|
|
248
|
-
(path.source !== 3369 && path.type === "substrate"))
|
|
249
|
-
) {
|
|
250
|
-
return false
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
// Allow TRAC to go to Hydration (2034) and Neuroweb (2043) only
|
|
254
|
-
if (
|
|
255
|
-
path.asset === "0xaa7a9ca87d3694b5755f213b5d04094b8d0f0a6f" &&
|
|
256
|
-
((path.destination !== 2034 &&
|
|
257
|
-
path.destination !== 2043 &&
|
|
258
|
-
path.type === "ethereum") ||
|
|
259
|
-
(path.source !== 2034 && path.source !== 2043 && path.type === "substrate"))
|
|
260
|
-
) {
|
|
261
|
-
return false
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Disable stable coins in the UI from Ethereum to Polkadot
|
|
265
|
-
if (
|
|
266
|
-
(path.asset === "0x9d39a5de30e57443bff2a8307a4256c8797a3497" || // Staked USDe
|
|
267
|
-
path.asset === "0xa3931d71877c0e7a3148cb7eb4463524fec27fbd" || // Savings USD
|
|
268
|
-
path.asset === "0x6b175474e89094c44da98b954eedeac495271d0f") && // DAI
|
|
269
|
-
path.destination === 2034 // Hydration
|
|
270
|
-
) {
|
|
271
|
-
return false
|
|
272
|
-
}
|
|
273
|
-
// Disable para to para transfers except for hydration
|
|
274
|
-
if (
|
|
275
|
-
path.type === "substrate" &&
|
|
276
|
-
path.destinationType === "substrate" &&
|
|
277
|
-
!(
|
|
278
|
-
(path.source === 2034 && path.destination == 1000) ||
|
|
279
|
-
(path.source === 1000 && path.destination === 2034)
|
|
280
|
-
)
|
|
281
|
-
) {
|
|
282
|
-
return false
|
|
283
|
-
}
|
|
284
|
-
return true
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
default:
|
|
288
|
-
return (_: Path) => true
|
|
289
80
|
}
|
|
81
|
+
return sources
|
|
290
82
|
}
|