Skip to content

Commit 5b6c9f4

Browse files
committed
fix: refactoring to bridge hub
1 parent f6f596f commit 5b6c9f4

File tree

6 files changed

+135
-150
lines changed

6 files changed

+135
-150
lines changed

.snippets/code/tutorials/interoperability/xcm-fee-estimation/paseo.yml renamed to .snippets/code/tutorials/interoperability/xcm-fee-estimation/paseo-bridge-hub.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
endpoint: wss://paseo-rpc.dwellir.com
1+
endpoint: wss://bridge-hub-paseo.dotters.network
22
mock-signature-host: true
3-
block: ${env.PASEO_BLOCK_NUMBER}
3+
block: ${env.PASEO_BRIDGE_HUB_BLOCK_NUMBER}
44
db: ./db.sqlite
55

66
import-storage:
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="termynal" data-termynal>
2-
<span data-ty="input"><span class="file-path"></span>chopsticks --config=.chopsticks/paseo.yml</span>
3-
<span data-ty="output">[15:55:22.770] INFO: Paseo Testnet RPC listening on http://[::]:8000 and ws://[::]:8000</span>
2+
<span data-ty="input"><span class="file-path"></span>chopsticks --config=.chopsticks/paseo-bridge-hub.yml</span>
3+
<span data-ty="output">[15:55:22.770] INFO: Paseo Bridge Hub RPC listening on http://[::]:8000 and ws://[::]:8000</span>
44
<span data-ty="output">app: "chopsticks"</span>
55
</div>

.snippets/code/tutorials/interoperability/xcm-fee-estimation/teleport-ah-to-relay.ts renamed to .snippets/code/tutorials/interoperability/xcm-fee-estimation/teleport-ah-to-bridge-hub.ts

Lines changed: 51 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { paseo, paseoAssetHub } from "@polkadot-api/descriptors";
1+
import { paseoAssetHub, paseoBridgeHub } from "@polkadot-api/descriptors";
22
import {
33
createClient,
44
FixedSizeBinary,
@@ -23,16 +23,17 @@ import {
2323
const PAS_UNITS = 10_000_000_000n; // 1 PAS
2424
const PAS_CENTS = 100_000_000n; // 0.01 PAS
2525

26-
// Paseo Relay Chain constants
27-
const PASEO_RPC_ENDPOINT = "ws://localhost:8000"; // Paseo Relay Chain chopsticks endpoint
28-
const PASEO_ACCOUNT = "15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5"; // Alice (Paseo Relay Chain)
29-
3026
// Paseo Asset Hub constants
31-
const PASEO_ASSET_HUB_RPC_ENDPOINT = "ws://localhost:8001"; // Paseo Asset Hub chopsticks endpoint
32-
const ASSET_HUB_ACCOUNT = "14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3"; // Bob (Paseo Asset Hub)
27+
const PASEO_ASSET_HUB_RPC_ENDPOINT = "ws://localhost:8001";
28+
const ASSET_HUB_ACCOUNT = "15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5"; // Alice (Paseo Asset Hub)
29+
30+
// Bridge Hub destination
31+
const BRIDGE_HUB_RPC_ENDPOINT = "ws://localhost:8000";
32+
const BRIDGE_HUB_PARA_ID = 1002;
33+
const BRIDGE_HUB_BENEFICIARY = "14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3"; // Bob (Bridge Hub)
3334

34-
// Helper function to create XCM for teleport to Relay
35-
function createTeleportXcmToRelay() {
35+
// Create the XCM message for teleport (Asset Hub → Bridge Hub)
36+
function createTeleportXcmToBridgeHub(paraId: number) {
3637
return XcmVersionedXcm.V5([
3738
// Withdraw PAS from Asset Hub (PAS on parachains is parents:1, interior: Here)
3839
XcmV5Instruction.WithdrawAsset([
@@ -48,11 +49,11 @@ function createTeleportXcmToRelay() {
4849
fun: XcmV3MultiassetFungibility.Fungible(10n * PAS_CENTS), // 0.01 PAS
4950
},
5051
}),
51-
// Send to Relay (parents:1, interior: Here)
52+
// Send to Bridge Hub parachain (parents:1, interior: X1(Parachain(paraId)))
5253
XcmV5Instruction.InitiateTransfer({
5354
destination: {
5455
parents: 1,
55-
interior: XcmV5Junctions.Here(),
56+
interior: XcmV5Junctions.X1(XcmV5Junction.Parachain(paraId)),
5657
},
5758
remote_fees: Enum(
5859
"Teleport",
@@ -72,7 +73,7 @@ function createTeleportXcmToRelay() {
7273
interior: XcmV5Junctions.X1(
7374
XcmV5Junction.AccountId32({
7475
network: undefined,
75-
id: FixedSizeBinary.fromAccountId32(PASEO_ACCOUNT),
76+
id: FixedSizeBinary.fromAccountId32(BRIDGE_HUB_BENEFICIARY),
7677
})
7778
),
7879
},
@@ -85,8 +86,8 @@ function createTeleportXcmToRelay() {
8586
]);
8687
}
8788

88-
async function estimateXcmFeesFromAssetHub(xcm: any, assetHubApi: any) {
89-
console.log("=== Fee Estimation Process (Asset Hub → Relay) ===");
89+
async function estimateXcmFeesFromAssetHubToBridgeHub(xcm: any, assetHubApi: any) {
90+
console.log("=== Fee Estimation Process (Asset Hub → Bridge Hub) ===");
9091

9192
// 1. LOCAL EXECUTION FEES on Asset Hub
9293
console.log("1. Calculating local execution fees on Asset Hub...");
@@ -118,7 +119,7 @@ async function estimateXcmFeesFromAssetHub(xcm: any, assetHubApi: any) {
118119
// 2. DELIVERY FEES + REMOTE EXECUTION FEES
119120
console.log("\n2. Calculating delivery and remote execution fees...");
120121
let deliveryFees = 0n;
121-
let remoteExecutionFees = 0n;
122+
let remoteExecutionFees = 0n; // Skipped (Bridge Hub descriptor not available)
122123

123124
// Origin from Asset Hub perspective
124125
const origin = XcmVersionedLocation.V5({
@@ -139,29 +140,31 @@ async function estimateXcmFeesFromAssetHub(xcm: any, assetHubApi: any) {
139140

140141
const { forwarded_xcms: forwardedXcms } = dryRunResult.value;
141142

142-
// Find the XCM message sent to Relay (parents:1, interior: Here)
143-
const relayXcmEntry = forwardedXcms.find(
143+
// Find the XCM message sent to Bridge Hub (parents:1, interior: X1(Parachain(1002)))
144+
const bridgeHubXcmEntry = forwardedXcms.find(
144145
([location, _]: [any, any]) =>
145146
(location.type === "V4" || location.type === "V5") &&
146147
location.value.parents === 1 &&
147-
location.value.interior?.type === "Here"
148+
location.value.interior?.type === "X1" &&
149+
location.value.interior.value?.type === "Parachain" &&
150+
location.value.interior.value.value === BRIDGE_HUB_PARA_ID
148151
);
149152

150-
if (relayXcmEntry) {
151-
const [destination, messages] = relayXcmEntry;
153+
if (bridgeHubXcmEntry) {
154+
const [destination, messages] = bridgeHubXcmEntry;
152155
const remoteXcm = messages[0];
153156

154-
console.log("✓ Found XCM message to Relay");
157+
console.log("✓ Found XCM message to Bridge Hub");
155158

156-
// Calculate delivery fees from Asset Hub to Relay
159+
// Calculate delivery fees from Asset Hub to Bridge Hub
157160
const deliveryFeesResult = await assetHubApi.apis.XcmPaymentApi.query_delivery_fees(
158161
destination,
159162
remoteXcm
160163
);
161164

162165
if (
163166
deliveryFeesResult.success &&
164-
deliveryFeesResult.value.type === "V4" &&
167+
deliveryFeesResult.value.type === "V5" &&
165168
deliveryFeesResult.value.value[0]?.fun?.type === "Fungible"
166169
) {
167170
deliveryFees = deliveryFeesResult.value.value[0].fun.value;
@@ -170,43 +173,24 @@ async function estimateXcmFeesFromAssetHub(xcm: any, assetHubApi: any) {
170173
console.log("✗ Failed to calculate delivery fees:", deliveryFeesResult);
171174
}
172175

173-
// 3. REMOTE EXECUTION FEES on Relay
174-
console.log("\n3. Calculating remote execution fees on Relay...");
175-
try {
176-
const relayClient = createClient(withPolkadotSdkCompat(getWsProvider(PASEO_RPC_ENDPOINT)));
177-
const relayApi = relayClient.getTypedApi(paseo);
178-
179-
// Query weight of the remote XCM on Relay
180-
const remoteWeightResult = await relayApi.apis.XcmPaymentApi.query_xcm_weight(remoteXcm);
181-
182-
if (remoteWeightResult.success) {
183-
console.log("✓ Remote XCM weight (Relay) calculated:", remoteWeightResult.value);
184-
185-
// Convert to fee using PAS on Relay (parents:0, Here)
186-
const remoteFeesResult = await relayApi.apis.XcmPaymentApi.query_weight_to_asset_fee(
187-
remoteWeightResult.value,
188-
XcmVersionedAssetId.V5({
189-
parents: 0,
190-
interior: XcmV5Junctions.Here(),
191-
})
176+
// 3. REMOTE EXECUTION FEES on Bridge Hub
177+
console.log("\n3. Calculating remote execution fees on Bridge Hub");
178+
try {
179+
const bridgeHubClient = createClient(withPolkadotSdkCompat(getWsProvider(BRIDGE_HUB_RPC_ENDPOINT)));
180+
const bridgeHubApi = bridgeHubClient.getTypedApi(paseoBridgeHub);
181+
const remoteWeightResult = await bridgeHubApi.apis.XcmPaymentApi.query_xcm_weight(remoteXcm);
182+
const remoteFeesResult = await bridgeHubApi.apis.XcmPaymentApi.query_weight_to_asset_fee(
183+
remoteWeightResult.value as { ref_time: bigint; proof_size: bigint },
184+
XcmVersionedAssetId.V4({ parents: 1, interior: XcmV3Junctions.Here() })
192185
);
193-
194-
if (remoteFeesResult.success) {
195-
remoteExecutionFees = remoteFeesResult.value;
196-
console.log("✓ Remote execution fees:", remoteExecutionFees.toString(), "PAS units");
197-
} else {
198-
console.log("✗ Failed to calculate remote execution fees:", remoteFeesResult.value);
199-
}
200-
} else {
201-
console.log("✗ Failed to query remote XCM weight:", remoteWeightResult.value);
186+
bridgeHubClient.destroy();
187+
remoteExecutionFees = remoteFeesResult.value as bigint;
188+
console.log("✓ Remote execution fees:", remoteExecutionFees.toString(), "PAS units");
189+
} catch (error) {
190+
console.error("Error calculating remote execution fees on Bridge Hub:", error);
202191
}
203-
204-
relayClient.destroy();
205-
} catch (error) {
206-
console.error("Error calculating remote execution fees on Relay:", error);
207-
}
208192
} else {
209-
console.log("✗ No XCM message found to Relay");
193+
console.log("✗ No XCM message found to Bridge Hub");
210194
}
211195
} else {
212196
console.log("✗ Local dry run failed on Asset Hub:", dryRunResult.value);
@@ -215,7 +199,7 @@ async function estimateXcmFeesFromAssetHub(xcm: any, assetHubApi: any) {
215199
// 4. TOTAL FEES
216200
const totalFees = localExecutionFees + deliveryFees + remoteExecutionFees;
217201

218-
console.log("\n=== Fee Summary (Asset Hub → Relay) ===");
202+
console.log("\n=== Fee Summary (Asset Hub → Bridge Hub) ===");
219203
console.log("Local execution fees:", localExecutionFees.toString(), "PAS units");
220204
console.log("Delivery fees:", deliveryFees.toString(), "PAS units");
221205
console.log("Remote execution fees:", remoteExecutionFees.toString(), "PAS units");
@@ -231,24 +215,24 @@ async function estimateXcmFeesFromAssetHub(xcm: any, assetHubApi: any) {
231215
}
232216

233217
async function main() {
234-
// Connect to the Paseo Asset Hub parachain
218+
// Connect to the Asset Hub parachain
235219
const assetHubClient = createClient(withPolkadotSdkCompat(getWsProvider(PASEO_ASSET_HUB_RPC_ENDPOINT)));
236220

237-
// Get the typed API for Paseo Asset Hub
221+
// Get the typed API for Asset Hub
238222
const assetHubApi = assetHubClient.getTypedApi(paseoAssetHub);
239223

240224
try {
241-
// Create the XCM message for teleport (Paseo Asset Hub → Paseo Relay)
242-
const xcm = createTeleportXcmToRelay();
225+
// Create the XCM message for teleport (Asset Hub → Bridge Hub)
226+
const xcm = createTeleportXcmToBridgeHub(BRIDGE_HUB_PARA_ID);
243227

244-
console.log("=== XCM Teleport: Paseo Asset Hub → Paseo Relay ===");
245-
console.log("From:", ASSET_HUB_ACCOUNT, "(Bob)");
246-
console.log("To:", PASEO_ACCOUNT, "(Alice)");
228+
console.log("=== XCM Teleport: Paseo Asset Hub → Bridge Hub ===");
229+
console.log("From:", ASSET_HUB_ACCOUNT, "(Alice on Asset Hub)");
230+
console.log("To:", BRIDGE_HUB_BENEFICIARY, "(Beneficiary on Bridge Hub)");
247231
console.log("Amount:", "1 PAS");
248232
console.log("");
249233

250234
// Estimate all fees
251-
const fees = await estimateXcmFeesFromAssetHub(xcm, assetHubApi);
235+
const fees = await estimateXcmFeesFromAssetHubToBridgeHub(xcm, assetHubApi);
252236
void fees; // prevent unused var under isolatedModules
253237

254238
// Create the execute transaction on Asset Hub
@@ -264,6 +248,7 @@ async function main() {
264248
console.log("Transaction hex:", (await tx.getEncodedData()).asHex());
265249
console.log("Ready to submit!");
266250
} catch (error) {
251+
console.log("Error stack:", (error as Error).stack);
267252
console.error("Error occurred:", (error as Error).message);
268253
if ((error as Error).cause) {
269254
console.dir((error as Error).cause, { depth: null });
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
<div id="termynal" data-termynal>
2-
<span data-ty="input"><span class="file-path"></span>npx ts-node teleport-ah-to-relay.ts</span>
2+
<span data-ty="input"><span class="file-path"></span>npx ts-node teleport-ah-to-bridge-hub.ts</span>
33
<pre>
4-
=== XCM Teleport: Paseo Asset Hub → Paseo Relay ===
5-
From: 14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3 (Bob)
6-
To: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 (Alice)
7-
Amount: 1 PAS
8-
9-
=== Fee Estimation Process (Asset Hub → Relay) ===
10-
1. Calculating local execution fees on Asset Hub...
11-
✓ XCM weight (Asset Hub): { ref_time: 1462082000n, proof_size: 19578n }
12-
✓ Local execution fees (Asset Hub): 97890000 PAS units
13-
14-
1. Calculating delivery and remote execution fees...
15-
✓ Local dry run on Asset Hub successful
16-
✓ Found XCM message to Relay
17-
✓ Delivery fees: 305150000 PAS units
18-
19-
1. Calculating remote execution fees on Relay...
20-
✓ Remote XCM weight (Relay) calculated: { ref_time: 434130000n, proof_size: 10779n }
21-
✓ Remote execution fees: 34442461 PAS units
22-
23-
=== Fee Summary (Asset Hub → Relay) ===
24-
Local execution fees: 97890000 PAS units
25-
Delivery fees: 305150000 PAS units
26-
Remote execution fees: 34442461 PAS units
27-
TOTAL FEES: 437482461 PAS units
28-
TOTAL FEES: 0.0437 PAS
29-
30-
=== Transaction Details ===
31-
Transaction hex: 0x1f03050c00040100000700e40b54023001000002286bee3101000100000401000002286bee000400010204040d01020400010100d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d0700bca0650102000400
32-
Ready to submit!
33-
</pre
4+
=== XCM Teleport: Paseo Asset Hub → Bridge Hub ===
5+
From: 15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5 (Alice on Asset Hub)
6+
To: 14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3 (Beneficiary on Bridge Hub)
7+
Amount: 1 PAS
8+
9+
=== Fee Estimation Process (Asset Hub → Bridge Hub) ===
10+
1. Calculating local execution fees on Asset Hub...
11+
✓ XCM weight (Asset Hub): { ref_time: 1462082000n, proof_size: 19578n }
12+
✓ Local execution fees (Asset Hub): 97890000 PAS units
13+
14+
2. Calculating delivery and remote execution fees...
15+
✓ Local dry run on Asset Hub successful
16+
✓ Found XCM message to Bridge Hub
17+
✓ Delivery fees: 305150000 PAS units
18+
19+
3. Calculating remote execution fees on Bridge Hub
20+
✓ Remote execution fees: 17965000 PAS units
21+
22+
=== Fee Summary (Asset Hub → Bridge Hub) ===
23+
Local execution fees: 97890000 PAS units
24+
Delivery fees: 305150000 PAS units
25+
Remote execution fees: 17965000 PAS units
26+
TOTAL FEES: 421005000 PAS units
27+
TOTAL FEES: 0.0421 PAS
28+
29+
=== Transaction Details ===
30+
Transaction hex: 0x1f03050c00040100000700e40b54023001000002286bee31010100a90f0100000401000002286bee000400010204040d010204000101008eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a480700bca0650102000400
31+
Ready to submit!
32+
33+
</pre
3434
>
3535
</div>

llms.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
- [Tutorials for Managing XCM Channels](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-channels/index.md): Learn step-by-step how to establish unidirectional and bidirectional HRMP channels between parachains and system parachains using XCM.
183183
- [Opening HRMP Channels Between Parachains](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-channels/para-to-para.md): Learn how to open HRMP channels between parachains on Polkadot. Discover the step-by-step process for establishing uni- and bidirectional communication.
184184
- [Opening HRMP Channels with System Parachains](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-channels/para-to-system.md): Learn how to open HRMP channels with Polkadot system parachains. Discover the process for establishing bi-directional communication using a single XCM message.
185-
- [XCM Fee Estimation](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-fee-estimation.md): This tutorial demonstrates how to estimate the fees for teleporting assets from the Paseo Asset Hub parachain to the Paseo relay chain.
185+
- [XCM Fee Estimation](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-fee-estimation.md): This tutorial demonstrates how to estimate the fees for teleporting assets from the Paseo Asset Hub parachain to the Paseo Bridge Hub chain.
186186
- [XCM Transfers from Relay Chain to Parachain](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-transfers/from-relaychain-to-parachain.md): Learn how to perform a reserve-backed asset transfer between a relay chain and a parachain using XCM for cross-chain interoperability.
187187
- [XCM Transfers](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/interoperability/xcm-transfers/index.md): Explore tutorials on performing transfers between different consensus systems using XCM technology to enable cross-chain interoperability.
188188
- [Fast Track a Governance Proposal](https://raw.githubusercontent.com/polkadot-developers/polkadot-docs/refs/heads/master/tutorials/onchain-governance/fast-track-gov-proposal.md): Learn how to fast-track governance proposals in Polkadot's OpenGov using Chopsticks. Simulate, test, and execute proposals confidently.

0 commit comments

Comments
 (0)