Skip to content

Commit d3f9bfe

Browse files
committed
fix: line numbers
1 parent 64d02c9 commit d3f9bfe

File tree

2 files changed

+160
-58
lines changed

2 files changed

+160
-58
lines changed

llms-full.txt

Lines changed: 149 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31294,24 +31294,22 @@ main().catch(console.error);
3129431294
9. Define constants and a `main` function where you will implement all the logic:
3129531295

3129631296
```typescript title="teleport-ah-to-bridge-hub.ts"
31297-
// Paseo Asset Hub constants
31297+
// 1 PAS = 10^10 units
31298+
const PAS_UNITS = 10_000_000_000n; // 1 PAS
31299+
const PAS_CENTS = 100_000_000n; // 0.01 PAS
31300+
31301+
// Paseo Asset Hub constants
3129831302
const PASEO_ASSET_HUB_RPC_ENDPOINT = 'ws://localhost:8001';
3129931303
const ASSET_HUB_ACCOUNT = '15oF4uVJwmo4TdGW7VfQxNLavjCXviqxT9S1MgbjMNHr6Sp5'; // Alice (Paseo Asset Hub)
3130031304

3130131305
// Bridge Hub destination
3130231306
const BRIDGE_HUB_RPC_ENDPOINT = 'ws://localhost:8000';
3130331307
const BRIDGE_HUB_PARA_ID = 1002;
3130431308
const BRIDGE_HUB_BENEFICIARY =
31305-
'14E5nqKAp3oAJcmzgZhUD2RcptBeUBScxKHgJKU4HPNcKVf3'; // Bob (Bridge Hub)
31306-
31307-
// Create the XCM message for teleport (Asset Hub → Bridge Hub)
31308-
function createTeleportXcmToBridgeHub(paraId: number) {
3130931309

3131031310
async function main() {
3131131311
// Code will go here
3131231312
}
31313-
31314-
};
3131531313
```
3131631314

3131731315
All the following code explained in the subsequent sections must be added inside the `main` function.
@@ -31323,11 +31321,13 @@ Now you are ready to start implementing the logic for the fee estimation for the
3132331321
Create the API client. You will need to create a client for the Paseo Asset Hub parachain:
3132431322

3132531323
```typescript title="teleport-ah-to-bridge-hub.ts"
31326-
'✓ Remote execution fees:',
31327-
remoteExecutionFees.toString(),
31328-
'PAS units',
31329-
);
31330-
} catch (error) {
31324+
// Connect to the Asset Hub parachain
31325+
const assetHubClient = createClient(
31326+
withPolkadotSdkCompat(getWsProvider(PASEO_ASSET_HUB_RPC_ENDPOINT)),
31327+
);
31328+
31329+
// Get the typed API for Asset Hub
31330+
const assetHubApi = assetHubClient.getTypedApi(paseoAssetHub);
3133131331
```
3133231332

3133331333
Ensure that you replace the endpoint URLs with the actual WebSocket endpoints. This example uses local chopsticks endpoints, but you can use public endpoints or run local nodes.
@@ -31337,7 +31337,9 @@ Ensure that you replace the endpoint URLs with the actual WebSocket endpoints. T
3133731337
Now, you can construct a proper XCM message using the new XCM V5 instructions for teleporting from Asset Hub to the Bridge Hub Chain:
3133831338

3133931339
```typescript title="teleport-ah-to-bridge-hub.ts"
31340-
// Withdraw PAS from Asset Hub (PAS on parachains is parents:1, interior: Here)
31340+
function createTeleportXcmToBridgeHub(paraId: number) {
31341+
return XcmVersionedXcm.V5([
31342+
// Withdraw PAS from Asset Hub (PAS on parachains is parents:1, interior: Here)
3134131343
XcmV5Instruction.WithdrawAsset([
3134231344
{
3134331345
id: { parents: 1, interior: XcmV5Junctions.Here() },
@@ -31387,9 +31389,6 @@ Now, you can construct a proper XCM message using the new XCM V5 instructions fo
3138731389
}),
3138831390
]);
3138931391
}
31390-
31391-
async function estimateXcmFeesFromAssetHubToBridgeHub(
31392-
xcm: any,
3139331392
```
3139431393

3139531394
## Fee Estimation Function
@@ -31399,16 +31398,20 @@ Below is a four-step breakdown of the logic needed to estimate the fees for the
3139931398
First, you need to create the function that will estimate the fees for the teleport:
3140031399

3140131400
```typescript title="teleport-ah-to-bridge-hub.ts"
31401+
async function estimateXcmFeesFromAssetHubToBridgeHub(
31402+
xcm: any,
31403+
assetHubApi: any,
3140231404
) {
31403-
console.log('=== Fee Estimation Process (Asset Hub → Bridge Hub) ===');
3140431405
// Code will go here
3140531406
}
3140631407
```
3140731408

3140831409
1. **Local execution fees on Asset Hub**: Compute the XCM weight locally, then convert that weight to PAS using Asset Hub's view of PAS (`parents: 1, interior: Here`). Add the code to the function:
3140931410

3141031411
```typescript title="teleport-ah-to-bridge-hub.ts"
31411-
// 1. LOCAL EXECUTION FEES on Asset Hub
31412+
console.log('=== Fee Estimation Process (Asset Hub → Bridge Hub) ===');
31413+
31414+
// 1. LOCAL EXECUTION FEES on Asset Hub
3141231415
console.log('1. Calculating local execution fees on Asset Hub...');
3141331416
let localExecutionFees = 0n;
3141431417

@@ -31434,12 +31437,8 @@ First, you need to create the function that will estimate the fees for the telep
3143431437
localExecutionFees.toString(),
3143531438
'PAS units',
3143631439
);
31437-
```
31438-
31439-
2. **Dry-run and delivery fees to Bridge Hub**: Dry-run the XCM on Asset Hub to capture forwarded messages, locate the one targeting Bridge Hub (`parents: 1, interior: Here`), and ask for delivery fees. Add the code to the function:
31440-
31441-
```typescript title="teleport-ah-to-bridge-hub.ts"
31442-
console.log(
31440+
} else {
31441+
console.log(
3144331442
'✗ Failed to calculate local execution fees:',
3144431443
executionFeesResult.value,
3144531444
);
@@ -31450,8 +31449,12 @@ First, you need to create the function that will estimate the fees for the telep
3145031449
weightResult.value,
3145131450
);
3145231451
}
31452+
```
3145331453

31454-
// 2. DELIVERY FEES + REMOTE EXECUTION FEES
31454+
2. **Dry-run and delivery fees to Bridge Hub**: Dry-run the XCM on Asset Hub to capture forwarded messages, locate the one targeting Bridge Hub (`parents: 1, interior: Here`), and ask for delivery fees. Add the code to the function:
31455+
31456+
```typescript title="teleport-ah-to-bridge-hub.ts"
31457+
// 2. DELIVERY FEES + REMOTE EXECUTION FEES
3145531458
console.log('\n2. Calculating delivery and remote execution fees...');
3145631459
let deliveryFees = 0n;
3145731460
let remoteExecutionFees = 0n; // Skipped (Bridge Hub descriptor not available)
@@ -31494,12 +31497,10 @@ First, you need to create the function that will estimate the fees for the telep
3149431497
if (bridgeHubXcmEntry) {
3149531498
const [destination, messages] = bridgeHubXcmEntry;
3149631499
const remoteXcm = messages[0];
31497-
```
3149831500

31499-
3. **Remote execution fees on Bridge Hub**: Connect to Bridge Hub, recompute the forwarded XCM weight there, and convert weight to PAS (`parents: 0, interior: Here`). Add the code to the function:
31501+
console.log('✓ Found XCM message to Bridge Hub');
3150031502

31501-
```typescript title="teleport-ah-to-bridge-hub.ts"
31502-
// Calculate delivery fees from Asset Hub to Bridge Hub
31503+
// Calculate delivery fees from Asset Hub to Bridge Hub
3150331504
const deliveryFeesResult =
3150431505
await assetHubApi.apis.XcmPaymentApi.query_delivery_fees(
3150531506
destination,
@@ -31516,16 +31517,16 @@ First, you need to create the function that will estimate the fees for the telep
3151631517
} else {
3151731518
console.log('✗ Failed to calculate delivery fees:', deliveryFeesResult);
3151831519
}
31519-
31520-
// 3. REMOTE EXECUTION FEES on Bridge Hub
31521-
console.log('\n3. Calculating remote execution fees on Bridge Hub');
31522-
try {
3152331520
```
3152431521

31525-
4. **Sum and return totals**: Aggregate all parts, print a short summary, and return a structured result. Add the code to the function:
31522+
3. **Remote execution fees on Bridge Hub**: Connect to Bridge Hub, recompute the forwarded XCM weight there, and convert weight to PAS (`parents: 0, interior: Here`). Add the code to the function:
3152631523

3152731524
```typescript title="teleport-ah-to-bridge-hub.ts"
31528-
withPolkadotSdkCompat(getWsProvider(BRIDGE_HUB_RPC_ENDPOINT)),
31525+
// 3. REMOTE EXECUTION FEES on Bridge Hub
31526+
console.log('\n3. Calculating remote execution fees on Bridge Hub');
31527+
try {
31528+
const bridgeHubClient = createClient(
31529+
withPolkadotSdkCompat(getWsProvider(BRIDGE_HUB_RPC_ENDPOINT)),
3152931530
);
3153031531
const bridgeHubApi = bridgeHubClient.getTypedApi(paseoBridgeHub);
3153131532
const remoteWeightResult =
@@ -31542,14 +31543,69 @@ First, you need to create the function that will estimate the fees for the telep
3154231543
}),
3154331544
);
3154431545
bridgeHubClient.destroy();
31546+
remoteExecutionFees = remoteFeesResult.value as bigint;
31547+
console.log(
31548+
'✓ Remote execution fees:',
31549+
remoteExecutionFees.toString(),
31550+
'PAS units',
31551+
);
31552+
} catch (error) {
31553+
console.error(
31554+
'Error calculating remote execution fees on Bridge Hub:',
31555+
error,
31556+
);
31557+
}
31558+
} else {
31559+
console.log('✗ No XCM message found to Bridge Hub');
31560+
}
31561+
} else {
31562+
console.log('✗ Local dry run failed on Asset Hub:', dryRunResult.value);
31563+
}
31564+
```
31565+
31566+
4. **Sum and return totals**: Aggregate all parts, print a short summary, and return a structured result. Add the code to the function:
31567+
31568+
```typescript title="teleport-ah-to-bridge-hub.ts"
31569+
// 4. TOTAL FEES
31570+
const totalFees = localExecutionFees + deliveryFees + remoteExecutionFees;
31571+
31572+
console.log('\n=== Fee Summary (Asset Hub → Bridge Hub) ===');
31573+
console.log(
31574+
'Local execution fees:',
31575+
localExecutionFees.toString(),
31576+
'PAS units',
31577+
);
31578+
console.log('Delivery fees:', deliveryFees.toString(), 'PAS units');
31579+
console.log(
31580+
'Remote execution fees:',
31581+
remoteExecutionFees.toString(),
31582+
'PAS units',
31583+
);
31584+
console.log('TOTAL FEES:', totalFees.toString(), 'PAS units');
31585+
console.log(
31586+
'TOTAL FEES:',
31587+
(Number(totalFees) / Number(PAS_UNITS)).toFixed(4),
31588+
'PAS',
31589+
);
31590+
31591+
return {
31592+
localExecutionFees,
31593+
deliveryFees,
31594+
remoteExecutionFees,
31595+
totalFees,
31596+
};
31597+
}
3154531598
```
3154631599

3154731600
The full code for the fee estimation function is the following:
3154831601

3154931602
??? code "Fee Estimation Function"
3155031603

3155131604
```typescript title="teleport-ah-to-bridge-hub.ts"
31552-
) {
31605+
async function estimateXcmFeesFromAssetHubToBridgeHub(
31606+
xcm: any,
31607+
assetHubApi: any,
31608+
) {
3155331609
console.log('=== Fee Estimation Process (Asset Hub → Bridge Hub) ===');
3155431610

3155531611
// 1. LOCAL EXECUTION FEES on Asset Hub
@@ -31676,14 +31732,8 @@ The full code for the fee estimation function is the following:
3167631732
}),
3167731733
);
3167831734
bridgeHubClient.destroy();
31679-
```
31680-
31681-
## Complete Implementation
31682-
31683-
Now put it all together in the main function:
31684-
31685-
```typescript title="teleport-ah-to-bridge-hub.ts"
31686-
console.log(
31735+
remoteExecutionFees = remoteFeesResult.value as bigint;
31736+
console.log(
3168731737
'✓ Remote execution fees:',
3168831738
remoteExecutionFees.toString(),
3168931739
'PAS units',
@@ -31727,7 +31777,62 @@ console.log(
3172731777
localExecutionFees,
3172831778
deliveryFees,
3172931779
remoteExecutionFees,
31780+
totalFees,
31781+
};
31782+
}
31783+
```
31784+
31785+
## Complete Implementation
3173031786

31787+
Now put it all together in the main function:
31788+
31789+
```typescript title="teleport-ah-to-bridge-hub.ts"
31790+
async function main() {
31791+
// Connect to the Asset Hub parachain
31792+
const assetHubClient = createClient(
31793+
withPolkadotSdkCompat(getWsProvider(PASEO_ASSET_HUB_RPC_ENDPOINT)),
31794+
);
31795+
31796+
// Get the typed API for Asset Hub
31797+
const assetHubApi = assetHubClient.getTypedApi(paseoAssetHub);
31798+
31799+
try {
31800+
// Create the XCM message for teleport (Asset Hub → Bridge Hub)
31801+
const xcm = createTeleportXcmToBridgeHub(BRIDGE_HUB_PARA_ID);
31802+
31803+
console.log('=== XCM Teleport: Paseo Asset Hub → Bridge Hub ===');
31804+
console.log('From:', ASSET_HUB_ACCOUNT, '(Alice on Asset Hub)');
31805+
console.log('To:', BRIDGE_HUB_BENEFICIARY, '(Beneficiary on Bridge Hub)');
31806+
console.log('Amount:', '1 PAS');
31807+
console.log('');
31808+
31809+
// Estimate all fees
31810+
const fees = await estimateXcmFeesFromAssetHubToBridgeHub(xcm, assetHubApi);
31811+
void fees; // prevent unused var under isolatedModules
31812+
31813+
// Create the execute transaction on Asset Hub
31814+
const tx = assetHubApi.tx.PolkadotXcm.execute({
31815+
message: xcm,
31816+
max_weight: {
31817+
ref_time: 6000000000n,
31818+
proof_size: 65536n,
31819+
},
31820+
});
31821+
31822+
console.log('\n=== Transaction Details ===');
31823+
console.log('Transaction hex:', (await tx.getEncodedData()).asHex());
31824+
console.log('Ready to submit!');
31825+
} catch (error) {
31826+
console.log('Error stack:', (error as Error).stack);
31827+
console.error('Error occurred:', (error as Error).message);
31828+
if ((error as Error).cause) {
31829+
console.dir((error as Error).cause, { depth: null });
31830+
}
31831+
} finally {
31832+
// Ensure client is always destroyed
31833+
assetHubClient.destroy();
31834+
}
31835+
}
3173131836
```
3173231837

3173331838
## Full Code

0 commit comments

Comments
 (0)