@snowbridge/registry 0.3.3 → 0.4.1-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 (43) hide show
  1. package/.turbo/turbo-build.log +1 -2
  2. package/dist/index.d.ts +6 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +27 -2
  5. package/dist/local_e2e_bridge_info.g.d.ts +141 -0
  6. package/dist/local_e2e_bridge_info.g.d.ts.map +1 -0
  7. package/dist/local_e2e_bridge_info.g.js +142 -0
  8. package/dist/paseo_sepolia_bridge_info.g.d.ts +331 -0
  9. package/dist/paseo_sepolia_bridge_info.g.d.ts.map +1 -0
  10. package/dist/paseo_sepolia_bridge_info.g.js +351 -0
  11. package/dist/polkadot_mainnet_bridge_info.g.d.ts +2137 -0
  12. package/dist/polkadot_mainnet_bridge_info.g.d.ts.map +1 -0
  13. package/dist/polkadot_mainnet_bridge_info.g.js +2454 -0
  14. package/dist/transfers.d.ts +3 -8
  15. package/dist/transfers.d.ts.map +1 -1
  16. package/dist/transfers.js +73 -215
  17. package/dist/westend_sepolia_bridge_info.g.d.ts +432 -0
  18. package/dist/westend_sepolia_bridge_info.g.d.ts.map +1 -0
  19. package/dist/westend_sepolia_bridge_info.g.js +487 -0
  20. package/package.json +7 -7
  21. package/scripts/buildRegistry.ts +609 -37
  22. package/src/index.ts +27 -2
  23. package/src/local_e2e_bridge_info.g.ts +140 -0
  24. package/src/paseo_sepolia_bridge_info.g.ts +350 -0
  25. package/src/polkadot_mainnet_bridge_info.g.ts +2477 -0
  26. package/src/transfers.ts +72 -265
  27. package/src/westend_sepolia_bridge_info.g.ts +495 -0
  28. package/dist/environment.d.ts +0 -3
  29. package/dist/environment.d.ts.map +0 -1
  30. package/dist/environment.js +0 -181
  31. package/dist/local_e2e.registry.json +0 -391
  32. package/dist/paseo_sepolia.registry.json +0 -231
  33. package/dist/polkadot_mainnet.registry.json +0 -1805
  34. package/dist/registry.d.ts +0 -3
  35. package/dist/registry.d.ts.map +0 -1
  36. package/dist/registry.js +0 -61
  37. package/dist/westend_sepolia.registry.json +0 -283
  38. package/src/environment.ts +0 -185
  39. package/src/local_e2e.registry.json +0 -391
  40. package/src/paseo_sepolia.registry.json +0 -231
  41. package/src/polkadot_mainnet.registry.json +0 -1805
  42. package/src/registry.ts +0 -63
  43. package/src/westend_sepolia.registry.json +0 -283
package/src/transfers.ts CHANGED
@@ -1,290 +1,97 @@
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
-
24
- export function getEthereumTransferLocation(
25
- registry: AssetRegistry,
26
- ethChain: EthereumChain,
27
- ): TransferLocation {
28
- if (!ethChain.evmParachainId) {
29
- return {
30
- id: "ethereum",
31
- name: "Ethereum",
32
- type: "ethereum",
33
- key: ethChain.chainId.toString(),
34
- ethChain,
35
- }
36
- } else {
37
- const evmChain = registry.parachains[ethChain.evmParachainId]
38
- return {
39
- id: ethChain.id,
40
- name: `${evmChain.info.name} (EVM)`,
41
- key: ethChain.chainId.toString(),
42
- type: "ethereum",
43
- ethChain,
44
- parachain: evmChain,
45
- }
46
- }
47
- }
48
-
49
- export function getSubstrateTransferLocation(parachain: Parachain): TransferLocation {
50
- return {
51
- id: parachain.info.specName,
52
- name: parachain.info.name,
53
- key: parachain.parachainId.toString(),
54
- type: "substrate",
55
- parachain,
56
- }
57
- }
58
10
 
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,
111
- }
112
- if (pathFilter(p1)) {
113
- locations.push(p1)
11
+ export function getTransferLocation(registry: AssetRegistry, chain: ChainId): TransferLocation {
12
+ switch (chain.kind) {
13
+ case "kusama": {
14
+ if (!registry.kusama) throw Error(`Kusama not configured.`)
15
+ const key = `${chain.kind}_${chain.id}` as const
16
+ const parachain = registry.kusama.parachains[key]
17
+ if (!parachain) throw Error(`Cannot find chain ${key}`)
18
+ return {
19
+ id: parachain.id,
20
+ kind: parachain.kind,
21
+ key: parachain.key,
22
+ parachain,
114
23
  }
115
- const p2: Path = {
116
- type: "substrate",
117
- id: parachain.info.specName,
118
- source: parachain.parachainId,
119
- destinationType: "ethereum",
120
- destination: ethChain.chainId,
121
- asset,
122
- }
123
- if (pathFilter(p2)) {
124
- locations.push(p2)
24
+ }
25
+ case "polkadot": {
26
+ const key = `${chain.kind}_${chain.id}` as const
27
+ const parachain = registry.parachains[key]
28
+ if (!parachain) throw Error(`Cannot find chain ${key}`)
29
+ return {
30
+ id: parachain.id,
31
+ kind: parachain.kind,
32
+ key: parachain.key,
33
+ parachain,
125
34
  }
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,
35
+ }
36
+ case "ethereum": {
37
+ const key = `${chain.kind}_${chain.id}` as const
38
+ const ethChain = registry.ethereumChains[key]
39
+ if (!ethChain) throw Error(`Cannot find chain ${key}`)
40
+ if (!ethChain.evmParachainId) {
41
+ return {
42
+ kind: ethChain.kind,
43
+ id: ethChain.id,
44
+ key: ethChain.key,
45
+ ethChain,
134
46
  }
135
- if (pathFilter(p3)) {
136
- locations.push(p3)
47
+ } else {
48
+ const evmChain = registry.parachains[`polkadot_${ethChain.evmParachainId}`]
49
+ return {
50
+ kind: ethChain.kind,
51
+ id: ethChain.id,
52
+ key: ethChain.key,
53
+ ethChain,
54
+ parachain: evmChain,
137
55
  }
138
56
  }
139
57
  }
140
- }
141
-
142
- // Local paths
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)
148
-
149
- // The asset exists on ethereum, parachain and asset hub
150
- const commonAssets = new Set(
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)
58
+ case "ethereum_l2": {
59
+ const key = `${chain.kind}_${chain.id}` as const
60
+ const ethChain = registry.ethereumChains[key]
61
+ if (!ethChain) throw Error(`Cannot find chain ${key}`)
62
+ return {
63
+ kind: ethChain.kind,
64
+ id: ethChain.id,
65
+ key: ethChain.key,
66
+ ethChain,
179
67
  }
180
68
  }
69
+ default:
70
+ throw Error(`Unknown ${chain.kind} chain ${chain.id}.`)
181
71
  }
72
+ }
182
73
 
183
- const results: Source[] = []
184
- for (const location of locations) {
185
- let source = results.find(
186
- (s) =>
187
- s.type === location.type &&
188
- s.id === location.id &&
189
- s.key === location.source.toString(),
190
- )
74
+ export function getTransferLocations(routes: readonly TransferRoute[]): Source[] {
75
+ let sources: Source[] = []
76
+ for (const route of routes) {
77
+ let source = sources.find((s) => s.id === route.from.id && s.kind === route.from.kind)
191
78
  if (!source) {
192
79
  source = {
193
- type: location.type,
194
- id: location.id,
195
- key: location.source.toString(),
80
+ key: `${route.from.kind}_${route.from.id}`,
81
+ ...route.from,
196
82
  destinations: {},
197
83
  }
198
- results.push(source)
84
+ sources.push(source)
199
85
  }
200
- let destination: { type: SourceType; assets: string[] } =
201
- source.destinations[location.destination]
86
+ const destId: ChainKey<ChainKind> = `${route.to.kind}_${route.to.id}`
87
+ let destination = source.destinations[destId]
202
88
  if (!destination) {
203
- destination = { type: location.destinationType, assets: [] }
204
- source.destinations[location.destination] = destination
205
- }
206
- destination.assets.push(location.asset)
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
89
+ source.destinations[destId] = {
90
+ key: destId,
91
+ ...route.to,
92
+ assets: [...route.assets],
224
93
  }
225
94
  }
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
95
  }
96
+ return sources
290
97
  }