@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
@@ -1,9 +1,4 @@
1
- import { AssetRegistry, EthereumChain, Parachain, Path, Source, TransferLocation } from "@snowbridge/base-types";
2
- export declare function transferSourcesFor(env: "polkadot_mainnet" | "westend_sepolia" | "paseo_sepolia" | (string & {})): Source[];
3
- export declare function getEthereumTransferLocation(registry: AssetRegistry, ethChain: EthereumChain): TransferLocation;
4
- export declare function getSubstrateTransferLocation(parachain: Parachain): TransferLocation;
5
- export declare function getTransferLocation(registry: AssetRegistry, sourceType: string, sourceKey: string): TransferLocation;
6
- export declare function getTransferLocationKusama(registry: AssetRegistry, network: string, parachainId: string): TransferLocation;
7
- export declare function getTransferLocations(registry: AssetRegistry, filter?: (path: Path) => boolean): Source[];
8
- export declare function defaultPathFilter(envName: string): (_: Path) => boolean;
1
+ import { AssetRegistry, TransferLocation, Source, ChainId, TransferRoute } from "@snowbridge/base-types";
2
+ export declare function getTransferLocation(registry: AssetRegistry, chain: ChainId): TransferLocation;
3
+ export declare function getTransferLocations(routes: readonly TransferRoute[]): Source[];
9
4
  //# sourceMappingURL=transfers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transfers.d.ts","sourceRoot":"","sources":["../src/transfers.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAEb,aAAa,EACb,SAAS,EACT,IAAI,EACJ,MAAM,EAEN,gBAAgB,EACnB,MAAM,wBAAwB,CAAA;AAK/B,wBAAgB,kBAAkB,CAC9B,GAAG,EAAE,kBAAkB,GAAG,iBAAiB,GAAG,eAAe,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,GAC9E,MAAM,EAAE,CAKV;AAED,wBAAgB,2BAA2B,CACvC,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE,aAAa,GACxB,gBAAgB,CAoBlB;AAED,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,SAAS,GAAG,gBAAgB,CAQnF;AAED,wBAAgB,mBAAmB,CAC/B,QAAQ,EAAE,aAAa,EACvB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,GAClB,gBAAgB,CAMlB;AAED,wBAAgB,yBAAyB,CACrC,QAAQ,EAAE,aAAa,EACvB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,GACpB,gBAAgB,CAMlB;AAED,wBAAgB,oBAAoB,CAChC,QAAQ,EAAE,aAAa,EACvB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,GACjC,MAAM,EAAE,CA2HV;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,IAAI,KAAK,OAAO,CA+EvE"}
1
+ {"version":3,"file":"transfers.d.ts","sourceRoot":"","sources":["../src/transfers.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EACb,gBAAgB,EAChB,MAAM,EAGN,OAAO,EACP,aAAa,EAChB,MAAM,wBAAwB,CAAA;AAE/B,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,GAAG,gBAAgB,CA6D7F;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,GAAG,MAAM,EAAE,CAuB/E"}
package/dist/transfers.js CHANGED
@@ -1,238 +1,96 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.transferSourcesFor = transferSourcesFor;
4
- exports.getEthereumTransferLocation = getEthereumTransferLocation;
5
- exports.getSubstrateTransferLocation = getSubstrateTransferLocation;
6
3
  exports.getTransferLocation = getTransferLocation;
7
- exports.getTransferLocationKusama = getTransferLocationKusama;
8
4
  exports.getTransferLocations = getTransferLocations;
9
- exports.defaultPathFilter = defaultPathFilter;
10
- const registry_1 = require("./registry");
11
- const cache = {};
12
- function transferSourcesFor(env) {
13
- if (env in cache) {
14
- return cache[env];
15
- }
16
- return getTransferLocations((0, registry_1.assetRegistryFor)(env));
17
- }
18
- function getEthereumTransferLocation(registry, ethChain) {
19
- if (!ethChain.evmParachainId) {
20
- return {
21
- id: "ethereum",
22
- name: "Ethereum",
23
- type: "ethereum",
24
- key: ethChain.chainId.toString(),
25
- ethChain,
26
- };
27
- }
28
- else {
29
- const evmChain = registry.parachains[ethChain.evmParachainId];
30
- return {
31
- id: ethChain.id,
32
- name: `${evmChain.info.name} (EVM)`,
33
- key: ethChain.chainId.toString(),
34
- type: "ethereum",
35
- ethChain,
36
- parachain: evmChain,
37
- };
38
- }
39
- }
40
- function getSubstrateTransferLocation(parachain) {
41
- return {
42
- id: parachain.info.specName,
43
- name: parachain.info.name,
44
- key: parachain.parachainId.toString(),
45
- type: "substrate",
46
- parachain,
47
- };
48
- }
49
- function getTransferLocation(registry, sourceType, sourceKey) {
50
- if (sourceType === "ethereum") {
51
- return getEthereumTransferLocation(registry, registry.ethereumChains[sourceKey]);
52
- }
53
- else {
54
- return getSubstrateTransferLocation(registry.parachains[sourceKey]);
55
- }
56
- }
57
- function getTransferLocationKusama(registry, network, parachainId) {
58
- if (network === "kusama" && registry.kusama) {
59
- return getSubstrateTransferLocation(registry.kusama?.parachains[parachainId]);
60
- }
61
- else {
62
- return getSubstrateTransferLocation(registry.parachains[parachainId]);
63
- }
64
- }
65
- function getTransferLocations(registry, filter) {
66
- const ethChain = registry.ethereumChains[registry.ethChainId];
67
- const parachains = Object.keys(registry.parachains)
68
- .filter((p) => p !== registry.bridgeHubParaId.toString())
69
- .map((p) => registry.parachains[p]);
70
- const pathFilter = filter ?? defaultPathFilter(registry.environment);
71
- const locations = [];
72
- const ethAssets = Object.keys(ethChain.assets);
73
- // Bridged paths
74
- for (const parachain of parachains) {
75
- const destinationAssets = Object.keys(parachain.assets);
76
- const commonAssets = new Set(ethAssets.filter((sa) => destinationAssets.find((da) => da === sa)));
77
- for (const asset of commonAssets) {
78
- const p1 = {
79
- type: "ethereum",
80
- id: "ethereum",
81
- source: ethChain.chainId,
82
- destinationType: "substrate",
83
- destination: parachain.parachainId,
84
- asset,
5
+ function getTransferLocation(registry, chain) {
6
+ switch (chain.kind) {
7
+ case "kusama": {
8
+ if (!registry.kusama)
9
+ throw Error(`Kusama not configured.`);
10
+ const key = `${chain.kind}_${chain.id}`;
11
+ const parachain = registry.kusama.parachains[key];
12
+ if (!parachain)
13
+ throw Error(`Cannot find chain ${key}`);
14
+ return {
15
+ id: parachain.id,
16
+ kind: parachain.kind,
17
+ key: parachain.key,
18
+ parachain,
85
19
  };
86
- if (pathFilter(p1)) {
87
- locations.push(p1);
88
- }
89
- const p2 = {
90
- type: "substrate",
91
- id: parachain.info.specName,
92
- source: parachain.parachainId,
93
- destinationType: "ethereum",
94
- destination: ethChain.chainId,
95
- asset,
20
+ }
21
+ case "polkadot": {
22
+ const key = `${chain.kind}_${chain.id}`;
23
+ const parachain = registry.parachains[key];
24
+ if (!parachain)
25
+ throw Error(`Cannot find chain ${key}`);
26
+ return {
27
+ id: parachain.id,
28
+ kind: parachain.kind,
29
+ key: parachain.key,
30
+ parachain,
96
31
  };
97
- if (pathFilter(p2)) {
98
- locations.push(p2);
32
+ }
33
+ case "ethereum": {
34
+ const key = `${chain.kind}_${chain.id}`;
35
+ const ethChain = registry.ethereumChains[key];
36
+ if (!ethChain)
37
+ throw Error(`Cannot find chain ${key}`);
38
+ if (!ethChain.evmParachainId) {
39
+ return {
40
+ kind: ethChain.kind,
41
+ id: ethChain.id,
42
+ key: ethChain.key,
43
+ ethChain,
44
+ };
99
45
  }
100
- if (parachain.info.evmChainId && registry.ethereumChains[parachain.info.evmChainId]) {
101
- const p3 = {
102
- type: "ethereum",
103
- id: `${parachain.info.specName}_evm`,
104
- source: parachain.info.evmChainId,
105
- destinationType: "ethereum",
106
- destination: ethChain.chainId,
107
- asset,
46
+ else {
47
+ const evmChain = registry.parachains[`polkadot_${ethChain.evmParachainId}`];
48
+ return {
49
+ kind: ethChain.kind,
50
+ id: ethChain.id,
51
+ key: ethChain.key,
52
+ ethChain,
53
+ parachain: evmChain,
108
54
  };
109
- if (pathFilter(p3)) {
110
- locations.push(p3);
111
- }
112
55
  }
113
56
  }
114
- }
115
- // Local paths
116
- const assetHub = registry.parachains[registry.assetHubParaId];
117
- for (const parachain of parachains) {
118
- if (parachain.parachainId === assetHub.parachainId)
119
- continue;
120
- const assetHubAssets = Object.keys(assetHub.assets);
121
- const destinationAssets = Object.keys(parachain.assets);
122
- // The asset exists on ethereum, parachain and asset hub
123
- const commonAssets = new Set(ethAssets.filter((sa) => assetHubAssets.find((da) => da === sa) &&
124
- destinationAssets.find((da) => da === sa)));
125
- for (const asset of commonAssets) {
126
- const p1 = {
127
- type: "substrate",
128
- id: assetHub.info.specName,
129
- source: assetHub.parachainId,
130
- destinationType: "substrate",
131
- destination: parachain.parachainId,
132
- asset,
57
+ case "ethereum_l2": {
58
+ const key = `${chain.kind}_${chain.id}`;
59
+ const ethChain = registry.ethereumChains[key];
60
+ if (!ethChain)
61
+ throw Error(`Cannot find chain ${key}`);
62
+ return {
63
+ kind: ethChain.kind,
64
+ id: ethChain.id,
65
+ key: ethChain.key,
66
+ ethChain,
133
67
  };
134
- if (pathFilter(p1)) {
135
- locations.push(p1);
136
- }
137
- const p2 = {
138
- type: "substrate",
139
- id: parachain.info.specName,
140
- source: parachain.parachainId,
141
- destinationType: "substrate",
142
- destination: assetHub.parachainId,
143
- asset,
144
- };
145
- if (pathFilter(p2)) {
146
- locations.push(p2);
147
- }
148
68
  }
69
+ default:
70
+ throw Error(`Unknown ${chain.kind} chain ${chain.id}.`);
149
71
  }
150
- const results = [];
151
- for (const location of locations) {
152
- let source = results.find((s) => s.type === location.type &&
153
- s.id === location.id &&
154
- s.key === location.source.toString());
72
+ }
73
+ function getTransferLocations(routes) {
74
+ let sources = [];
75
+ for (const route of routes) {
76
+ let source = sources.find((s) => s.id === route.from.id && s.kind === route.from.kind);
155
77
  if (!source) {
156
78
  source = {
157
- type: location.type,
158
- id: location.id,
159
- key: location.source.toString(),
79
+ key: `${route.from.kind}_${route.from.id}`,
80
+ ...route.from,
160
81
  destinations: {},
161
82
  };
162
- results.push(source);
83
+ sources.push(source);
163
84
  }
164
- let destination = source.destinations[location.destination];
85
+ const destId = `${route.to.kind}_${route.to.id}`;
86
+ let destination = source.destinations[destId];
165
87
  if (!destination) {
166
- destination = { type: location.destinationType, assets: [] };
167
- source.destinations[location.destination] = destination;
168
- }
169
- destination.assets.push(location.asset);
170
- }
171
- return results;
172
- }
173
- function defaultPathFilter(envName) {
174
- switch (envName) {
175
- case "westend_sepolia": {
176
- return (path) => {
177
- // Frequency
178
- if (path.asset === "0x72c610e05eaafcdf1fa7a2da15374ee90edb1620") {
179
- return false;
180
- }
181
- // Disable para to para transfers
182
- if (path.type === "substrate" && path.destinationType === "substrate") {
183
- return false;
184
- }
185
- return true;
88
+ source.destinations[destId] = {
89
+ key: destId,
90
+ ...route.to,
91
+ assets: [...route.assets],
186
92
  };
187
93
  }
188
- case "paseo_sepolia":
189
- return (path) => {
190
- // Disallow MUSE to any location but 3369
191
- if (path.asset === "0xb34a6924a02100ba6ef12af1c798285e8f7a16ee" &&
192
- ((path.destination !== 3369 && path.type === "ethereum") ||
193
- (path.source !== 3369 && path.type === "substrate"))) {
194
- return false;
195
- }
196
- // Disable para to para transfers
197
- if (path.type === "substrate" && path.destinationType === "substrate") {
198
- return false;
199
- }
200
- return true;
201
- };
202
- case "polkadot_mainnet":
203
- return (path) => {
204
- // Disallow MYTH to any location but 3369
205
- if (path.asset === "0xba41ddf06b7ffd89d1267b5a93bfef2424eb2003" &&
206
- ((path.destination !== 3369 && path.type === "ethereum") ||
207
- (path.source !== 3369 && path.type === "substrate"))) {
208
- return false;
209
- }
210
- // Allow TRAC to go to Hydration (2034) and Neuroweb (2043) only
211
- if (path.asset === "0xaa7a9ca87d3694b5755f213b5d04094b8d0f0a6f" &&
212
- ((path.destination !== 2034 &&
213
- path.destination !== 2043 &&
214
- path.type === "ethereum") ||
215
- (path.source !== 2034 && path.source !== 2043 && path.type === "substrate"))) {
216
- return false;
217
- }
218
- // Disable stable coins in the UI from Ethereum to Polkadot
219
- if ((path.asset === "0x9d39a5de30e57443bff2a8307a4256c8797a3497" || // Staked USDe
220
- path.asset === "0xa3931d71877c0e7a3148cb7eb4463524fec27fbd" || // Savings USD
221
- path.asset === "0x6b175474e89094c44da98b954eedeac495271d0f") && // DAI
222
- path.destination === 2034 // Hydration
223
- ) {
224
- return false;
225
- }
226
- // Disable para to para transfers except for hydration
227
- if (path.type === "substrate" &&
228
- path.destinationType === "substrate" &&
229
- !((path.source === 2034 && path.destination == 1000) ||
230
- (path.source === 1000 && path.destination === 2034))) {
231
- return false;
232
- }
233
- return true;
234
- };
235
- default:
236
- return (_) => true;
237
94
  }
95
+ return sources;
238
96
  }