From 3982f07d12606d877fde23b4f66ff0f869e44408 Mon Sep 17 00:00:00 2001 From: codingsh Date: Tue, 23 Dec 2025 18:08:51 +0000 Subject: [PATCH 1/4] Add OpenGov Operations Example - Create OpenGovExample.ts demonstrating OpenGov operations - Shows referendum submission, voting, decision deposits - Includes whitelisted caller operations and track information - Advanced level example with governance, opengov, voting, referenda categories - Registered the example in the example registry --- src/lib/examples/OpenGovExample.ts | 169 +++++++++++++++++++++++++++++ src/lib/examples/index.ts | 4 + 2 files changed, 173 insertions(+) create mode 100644 src/lib/examples/OpenGovExample.ts diff --git a/src/lib/examples/OpenGovExample.ts b/src/lib/examples/OpenGovExample.ts new file mode 100644 index 0000000..41ce015 --- /dev/null +++ b/src/lib/examples/OpenGovExample.ts @@ -0,0 +1,169 @@ +import type { Network } from "../types/network"; +import { ExampleFactory } from "./factory"; + +export class OpenGovExample extends ExampleFactory { + constructor() { + super({ + id: "opengov-operations", + name: "OpenGov Operations", + description: "Demonstrate OpenGov operations: tracks, referenda, voting, and submission deposits", + level: "advanced", + categories: ["governance", "opengov", "voting", "referenda"], + }); + } + + generateCode(network: Network): string { + return `// OpenGov Operations Example on ${network.name} +${this.getImports(network, true)} + +// Connect to ${network.name} +const client = createClient( + withPolkadotSdkCompat( + getWsProvider("${network.endpoint}") + ) +); + +// Get the typed API using the descriptors +const typedApi = client.getTypedApi(${network.descriptorKey}); + +// OpenGov operations demonstration +const demonstrateOpenGovOperations = async () => { + try { + console.log("šŸ›ļø Starting OpenGov operations demonstration..."); + + // 1. Query current referenda + console.log("\\nšŸ“‹ Querying active referenda:"); + const referenda = await typedApi.query.Referenda.ReferendumInfoFor.getEntries(); + console.log("Found", referenda.length, "active referenda"); + + if (referenda.length > 0) { + const firstReferendum = referenda[0]; + console.log("First referendum:", { + id: firstReferendum.key?.args?.[0]?.toString(), + info: firstReferendum.value + }); + } + + // 2. Query referendum tracks + console.log("\\nšŸŽÆ Querying referendum tracks:"); + try { + const tracks = await typedApi.query.Referenda.Tracks.getValue(); + console.log("Available tracks:", tracks?.map(track => ({ + id: track?.[0]?.toString(), + info: track?.[1] + }))); + } catch (error) { + console.log("Tracks query not available in current version"); + } + + // 3. Demonstrate referendum submission + console.log("\\nšŸ“ Referendum Submission Example:"); + console.log("This would submit a referendum to a specific track:"); + const submissionTx = typedApi.tx.Referenda.submit({ + proposalOrigin: { + Origins: "GeneralAdmin" // Track name + }, + proposal: { + Lookup: { + hash: "0x0000000000000000000000000000000000000000000000000000000000000000", // Example hash + len: 0 + } + }, + enactmentMoment: { + After: 100 // Blocks after approval + } + }); + console.log("Referendum submission transaction created (not submitted in simulator)"); + + // 4. Demonstrate voting on referendum + console.log("\\nšŸ—³ļø Voting on Referendum Example:"); + console.log("This would vote on an active referendum:"); + const voteTx = typedApi.tx.ConvictionVoting.vote({ + poll_index: 0, // Referendum ID + vote: { + Standard: { + vote: { + aye: true, + conviction: "Locked4x" // 4x conviction + }, + balance: 1000000000000n // Vote amount + } + } + }); + console.log("Vote transaction created for referendum #0 (not submitted in simulator)"); + + // 5. Query conviction voting state + console.log("\\nšŸ“Š Querying conviction voting state:"); + const aliceAddress = "${this.getTestAccount("alice")}"; + try { + const votingFor = await typedApi.query.ConvictionVoting.VotingFor.getValue(aliceAddress, 0); + console.log("Alice's vote on referendum 0:", votingFor); + } catch (error) { + console.log("Conviction voting query not available"); + } + + // 6. Demonstrate proposal deposit + console.log("\\nšŸ’° Proposal Deposit Example:"); + console.log("This would place a decision deposit on a referendum:"); + const depositTx = typedApi.tx.Referenda.placeDecisionDeposit({ + index: 0 // Referendum ID + }); + console.log("Decision deposit transaction created (not submitted in simulator)"); + + // 7. Query decision deposits + console.log("\\nšŸ¦ Querying decision deposits:"); + try { + const deposits = await typedApi.query.Referenda.DecisionDeposits.getValue(0); + console.log("Decision deposits for referendum 0:", deposits); + } catch (error) { + console.log("Decision deposits query not available"); + } + + // 8. Demonstrate whitelisted caller operation + console.log("\\n⭐ Whitelisted Caller Example:"); + console.log("This would execute a whitelisted operation:"); + const whitelistTx = typedApi.tx.WhitelistedCaller.dispatchAs({ + asOrigin: { + Origins: "WhitelistedCaller" + }, + call: { + system: { + remark: { + remark: "0x48656c6c6f20506f6c6b61646f7421" // "Hello Polkadot!" + } + } + } + }); + console.log("Whitelisted caller transaction created (not submitted in simulator)"); + + // 9. Query fellowship information (if available) + console.log("\\nšŸ‘„ Fellowship Information:"); + try { + const fellowship = await typedApi.query.FellowshipCollective.Members.getValue(aliceAddress); + console.log("Alice's fellowship rank:", fellowship?.toString()); + } catch (error) { + console.log("Fellowship queries not available on this network"); + } + + // 10. Query current block for timing + console.log("\\nā° Current Block Information:"); + const currentBlock = await typedApi.query.System.Number.getValue(); + console.log("Current block:", currentBlock?.toString()); + + console.log("\\nāœ… OpenGov operations demonstration completed!"); + console.log("Note: OpenGov operations require:"); + console.log("- Understanding of different tracks and their requirements"); + console.log("- Proper deposit amounts for proposal submission"); + console.log("- Sufficient conviction voting power"); + console.log("- In a real application, you would sign and submit these transactions"); + console.log("- Consider the lock periods for conviction voting"); + + } catch (error) { + console.error("āŒ Error in OpenGov operations:", error); + } +}; + +demonstrateOpenGovOperations().catch(console.error); +`; + } +} diff --git a/src/lib/examples/index.ts b/src/lib/examples/index.ts index a4d4a81..a2c2f78 100644 --- a/src/lib/examples/index.ts +++ b/src/lib/examples/index.ts @@ -2,6 +2,8 @@ import { exampleRegistry } from "./factory"; import { StakingOperationsExample } from "./StakingOperationsExample"; import { AssetHubExample } from "./AssetHubExample"; +import { OpenGovExample } from "./OpenGovExample"; + import { SimpleTransferExample } from "./SimpleTransferExample"; @@ -11,6 +13,8 @@ import { WalletTransferExample } from "./WalletTransferExample"; import { AcalaDeFiExample } from "./AcalaDeFiExample"; import type { Example, ExampleLevel } from "../types/example"; import { PolkadotGovernanceExample } from "./PolkadotGovernanceExample"; + new OpenGovExample(), + new AssetHubExample(), From ad866c60bdbe7bf2a6738fd0b325b6f5adc12cae Mon Sep 17 00:00:00 2001 From: codingsh Date: Tue, 23 Dec 2025 18:09:28 +0000 Subject: [PATCH 2/4] Add Coretime Chain Operations Example - Create CoretimeExample.ts demonstrating Coretime operations - Shows core purchasing, renewal, partitioning, and assignment - Includes pool operations and workload queries - Advanced level example with coretime, parachains, assets categories - Registered the example in the example registry --- src/lib/examples/CoretimeExample.ts | 180 ++++++++++++++++++++++++++++ src/lib/examples/index.ts | 4 + 2 files changed, 184 insertions(+) create mode 100644 src/lib/examples/CoretimeExample.ts diff --git a/src/lib/examples/CoretimeExample.ts b/src/lib/examples/CoretimeExample.ts new file mode 100644 index 0000000..c675c93 --- /dev/null +++ b/src/lib/examples/CoretimeExample.ts @@ -0,0 +1,180 @@ +import type { Network } from "../types/network"; +import { ExampleFactory } from "./factory"; + +export class CoretimeExample extends ExampleFactory { + constructor() { + super({ + id: "coretime-operations", + name: "Coretime Chain Operations", + description: "Demonstrate Coretime operations: core buying, renewal, and asset management", + level: "advanced", + categories: ["coretime", "parachains", "assets", "agile-coretime"], + }); + } + + generateCode(network: Network): string { + return `// Coretime Chain Operations Example on ${network.name} +${this.getImports(network, true)} + +// Connect to ${network.name} Coretime Chain +const client = createClient( + withPolkadotSdkCompat( + getWsProvider("${network.endpoint}") + ) +); + +// Get the typed API using the descriptors +const typedApi = client.getTypedApi(${network.descriptorKey}); + +// Coretime operations demonstration +const demonstrateCoretimeOperations = async () => { + try { + console.log("ā° Starting Coretime operations demonstration..."); + + // 1. Query current price and configuration + console.log("\\nšŸ’° Querying Coretime pricing:"); + try { + const coretimeConfig = await typedApi.query.Broker.Configuration.getValue(); + console.log("Coretime configuration:", coretimeConfig); + } catch (error) { + console.log("Coretime configuration not available"); + } + + // 2. Query core sales status + console.log("\\nšŸ·ļø Querying core sales status:"); + try { + const saleInfo = await typedApi.query.Broker.SaleInfo.getValue(); + console.log("Current sale information:", saleInfo); + } catch (error) { + console.log("Sale info not available"); + } + + // 3. Query available cores + console.log("\\nšŸ” Querying available cores:"); + try { + const cores = await typedApi.query.Broker.CoreSchedules.getEntries(); + console.log("Found", cores.length, "cores with schedules"); + + if (cores.length > 0) { + const firstCore = cores[0]; + console.log("First core schedule:", { + coreId: firstCore.key?.args?.[0]?.toString(), + schedule: firstCore.value + }); + } + } catch (error) { + console.log("Core schedules not available"); + } + + // 4. Demonstrate core purchase + console.log("\\nšŸ›’ Core Purchase Example:"); + console.log("This would purchase coretime for a specific period:"); + const purchaseTx = typedApi.tx.Broker.purchase({ + price_limit: 1000000000000n, // Maximum price willing to pay + }); + console.log("Coretime purchase transaction created (not submitted in simulator)"); + + // 5. Demonstrate core renewal + console.log("\\nšŸ”„ Core Renewal Example:"); + console.log("This would renew an existing core:"); + const renewTx = typedApi.tx.Broker.renew({ + core: 0, // Core ID to renew + price_limit: 500000000000n, // Maximum price for renewal + }); + console.log("Core renewal transaction created for core 0 (not submitted in simulator)"); + + // 6. Query workload information + console.log("\\nšŸ“Š Querying workload information:"); + try { + const workload = await typedApi.query.Broker.Workload.getEntries(); + console.log("Found workload data for", workload.length, "cores"); + } catch (error) { + console.log("Workload data not available"); + } + + // 7. Query reservations + console.log("\\nšŸ“… Querying reservations:"); + try { + const reservations = await typedApi.query.Broker.Reservations.getValue(); + console.log("Current reservations:", reservations); + } catch (error) { + console.log("Reservations not available"); + } + + // 8. Demonstrate partition core operation + console.log("\\nāœ‚ļø Core Partition Example:"); + console.log("This would partition a core into smaller time slices:"); + const partitionTx = typedApi.tx.Broker.partition({ + core: 0, // Core to partition + price_limit: 200000000000n, // Price limit for partition + }); + console.log("Core partition transaction created (not submitted in simulator)"); + + // 9. Demonstrate core assignment + console.log("\\nšŸŽÆ Core Assignment Example:"); + console.log("This would assign a core to a parachain:"); + const assignTx = typedApi.tx.Broker.assign({ + core: 0, // Core to assign + begin: 1000, // Starting block + assignment: [{ + task: 2000, // Parachain ID + ratio: [80, 20] // 80% to parachain, 20% to pool + }], + end_hint: null + }); + console.log("Core assignment transaction created (not submitted in simulator)"); + + // 10. Query core status + console.log("\\nšŸ“‹ Querying core status:"); + try { + const status = await typedApi.query.Broker.StatusOf.getValue(0); + console.log("Status of core 0:", status); + } catch (error) { + console.log("Core status not available"); + } + + // 11. Query allowed renewal records + console.log("\\nšŸ”‘ Querying allowed renewal records:"); + try { + const aliceAddress = "${this.getTestAccount("alice")}"; + const allowedRenewal = await typedApi.query.Broker.AllowedRenewalRecords.getValue(aliceAddress); + console.log("Alice's allowed renewal records:", allowedRenewal); + } catch (error) { + console.log("Allowed renewal records not available"); + } + + // 12. Demonstrate pool operations + console.log("\\nšŸŠ Pool Operations Example:"); + console.log("This would add coretime to the instant pool:"); + const poolTx = typedApi.tx.Broker.pool({ + core: 0, // Core to add to pool + price_limit: 100000000000n, // Price limit + }); + console.log("Pool transaction created (not submitted in simulator)"); + + // 13. Query instant pool configuration + console.log("\\n⚔ Querying instant pool:"); + try { + const poolInfo = await typedApi.query.Broker.InstantaneousPoolInfo.getValue(); + console.log("Instant pool information:", poolInfo); + } catch (error) { + console.log("Instant pool info not available"); + } + + console.log("\\nāœ… Coretime operations demonstration completed!"); + console.log("Note: Coretime operations require:"); + console.log("- Understanding of core scheduling and availability"); + console.log("- Proper price limits for purchases and renewals"); + console.log("- Knowledge of parachain assignments and workload distribution"); + console.log("- In a real application, you would sign and submit these transactions"); + console.log("- Coretime is a complex system - study the documentation thoroughly"); + + } catch (error) { + console.error("āŒ Error in Coretime operations:", error); + } +}; + +demonstrateCoretimeOperations().catch(console.error); +`; + } +} diff --git a/src/lib/examples/index.ts b/src/lib/examples/index.ts index a2c2f78..7a93860 100644 --- a/src/lib/examples/index.ts +++ b/src/lib/examples/index.ts @@ -3,6 +3,8 @@ import { exampleRegistry } from "./factory"; import { StakingOperationsExample } from "./StakingOperationsExample"; import { AssetHubExample } from "./AssetHubExample"; import { OpenGovExample } from "./OpenGovExample"; +import { CoretimeExample } from "./CoretimeExample"; + @@ -12,6 +14,8 @@ import { AccountBalanceCheckerExample } from "./AccountBalanceCheckerExample"; import { WalletTransferExample } from "./WalletTransferExample"; import { AcalaDeFiExample } from "./AcalaDeFiExample"; import type { Example, ExampleLevel } from "../types/example"; + new CoretimeExample(), + import { PolkadotGovernanceExample } from "./PolkadotGovernanceExample"; new OpenGovExample(), From c13e67f39689ac1fe10b9f4e8143b1d7a32ab661 Mon Sep 17 00:00:00 2001 From: codingsh Date: Tue, 23 Dec 2025 18:10:26 +0000 Subject: [PATCH 3/4] Add People Chain Identity Example - Create PeopleChainExample.ts demonstrating identity operations - Shows identity registration, verification, sub-accounts - Includes DID operations and username management - Advanced level example with identity, people-chain, did categories - Registered the example in the example registry --- src/lib/examples/PeopleChainExample.ts | 210 +++++++++++++++++++++++++ src/lib/examples/index.ts | 4 + 2 files changed, 214 insertions(+) create mode 100644 src/lib/examples/PeopleChainExample.ts diff --git a/src/lib/examples/PeopleChainExample.ts b/src/lib/examples/PeopleChainExample.ts new file mode 100644 index 0000000..b32922c --- /dev/null +++ b/src/lib/examples/PeopleChainExample.ts @@ -0,0 +1,210 @@ +import type { Network } from "../types/network"; +import { ExampleFactory } from "./factory"; + +export class PeopleChainExample extends ExampleFactory { + constructor() { + super({ + id: "people-chain-identity", + name: "People Chain Identity", + description: "Demonstrate People Chain identity operations: DID creation, verification, and management", + level: "advanced", + categories: ["identity", "people-chain", "did", "verification"], + }); + } + + generateCode(network: Network): string { + return `// People Chain Identity Operations Example on ${network.name} +${this.getImports(network, true)} + +// Connect to ${network.name} People Chain +const client = createClient( + withPolkadotSdkCompat( + getWsProvider("${network.endpoint}") + ) +); + +// Get the typed API using the descriptors +const typedApi = client.getTypedApi(${network.descriptorKey}); + +// People Chain identity operations demonstration +const demonstratePeopleChainIdentity = async () => { + try { + console.log("šŸ†” Starting People Chain identity operations demonstration..."); + + // 1. Query identity information + console.log("\\nšŸ” Querying identity information:"); + const aliceAddress = "${this.getTestAccount("alice")}"; + const bobAddress = "${this.getTestAccount("bob")}"; + + try { + const aliceIdentity = await typedApi.query.Identity.IdentityOf.getValue(aliceAddress); + console.log("Alice's identity:", aliceIdentity); + + const bobIdentity = await typedApi.query.Identity.IdentityOf.getValue(bobAddress); + console.log("Bob's identity:", bobIdentity); + } catch (error) { + console.log("Identity queries not available or different structure"); + } + + // 2. Query super identities + console.log("\\nšŸ‘‘ Querying super identities:"); + try { + const superOf = await typedApi.query.Identity.SuperOf.getValue(aliceAddress); + console.log("Alice's super identity:", superOf); + } catch (error) { + console.log("Super identity queries not available"); + } + + // 3. Query subs (sub-accounts) + console.log("\\nšŸ‘„ Querying sub-accounts:"); + try { + const subsOf = await typedApi.query.Identity.SubsOf.getValue(aliceAddress); + console.log("Alice's sub-accounts:", subsOf); + } catch (error) { + console.log("Sub-account queries not available"); + } + + // 4. Demonstrate identity registration + console.log("\\nšŸ“ Identity Registration Example:"); + console.log("This would register a new identity:"); + const registerTx = typedApi.tx.Identity.setIdentity({ + display: { + Raw: "Alice Developer" + }, + legal: { + Raw: "Alice Developer Ltd" + }, + web: { + Raw: "https://alice.dev" + }, + email: { + Raw: "alice@example.com" + }, + twitter: { + Raw: "@alice_dev" + }, + matrix: { + Raw: "@alice:matrix.org" + } + }); + console.log("Identity registration transaction created (not submitted in simulator)"); + + // 5. Demonstrate identity verification request + console.log("\\nāœ… Identity Verification Request Example:"); + console.log("This would request verification for identity fields:"); + const requestVerifyTx = typedApi.tx.Identity.requestJudgement({ + reg_index: 0, // Registration index + max_fee: 1000000000000n // Maximum fee for verification + }); + console.log("Judgement request transaction created (not submitted in simulator)"); + + // 6. Query registrars + console.log("\\nšŸ›ļø Querying registrars:"); + try { + const registrars = await typedApi.query.Identity.Registrars.getValue(); + console.log("Available registrars:", registrars?.map((reg, index) => ({ + index, + account: reg?.account, + fee: reg?.fee?.toString(), + fields: reg?.fields?.toString() + }))); + } catch (error) { + console.log("Registrar queries not available"); + } + + // 7. Demonstrate sub-account addition + console.log("\\nšŸ‘¶ Sub-Account Addition Example:"); + console.log("This would add a sub-account to an identity:"); + const addSubTx = typedApi.tx.Identity.addSub({ + sub: MultiAddress.Id(bobAddress), + data: { + Raw: "Bob Assistant" + } + }); + console.log("Add sub-account transaction created (not submitted in simulator)"); + + // 8. Demonstrate sub-account removal + console.log("\\nšŸ‘‹ Sub-Account Removal Example:"); + console.log("This would remove a sub-account from an identity:"); + const removeSubTx = typedApi.tx.Identity.removeSub({ + sub: MultiAddress.Id(bobAddress) + }); + console.log("Remove sub-account transaction created (not submitted in simulator)"); + + // 9. Demonstrate identity clearing + console.log("\\nšŸ—‘ļø Identity Clearing Example:"); + console.log("This would clear the entire identity:"); + const clearTx = typedApi.tx.Identity.clearIdentity(); + console.log("Clear identity transaction created (not submitted in simulator)"); + + // 10. Query identity judgments + console.log("\\nāš–ļø Querying identity judgments:"); + try { + const judgements = await typedApi.query.Identity.Judgements.getValue(aliceAddress); + console.log("Alice's judgements:", judgements); + } catch (error) { + console.log("Judgement queries not available"); + } + + // 11. Demonstrate username registration (if available) + console.log("\\nšŸ“› Username Registration Example:"); + console.log("This would register a username:"); + try { + const usernameTx = typedApi.tx.Identity.setUsername({ + username: "alice_dev" + }); + console.log("Username registration transaction created (not submitted in simulator)"); + } catch (error) { + console.log("Username registration not available on this network"); + } + + // 12. Query username authorities + console.log("\\nšŸ” Querying username authorities:"); + try { + const authorities = await typedApi.query.Identity.UsernameAuthorities.getValue(); + console.log("Username authorities:", authorities); + } catch (error) { + console.log("Username authorities not available"); + } + + // 13. Demonstrate DID operations (if available) + console.log("\\nšŸ†” DID Operations Example:"); + console.log("This would perform DID operations:"); + try { + // Query DID document + const didDoc = await typedApi.query.Did.DidDocuments.getValue(aliceAddress); + console.log("DID document for Alice:", didDoc); + + // DID update example + const didUpdateTx = typedApi.tx.Did.setAttribute({ + did: aliceAddress, + name: { + Raw: "email" + }, + value: { + Raw: "alice.updated@example.com" + }, + valid_for: null + }); + console.log("DID attribute update transaction created (not submitted in simulator)"); + } catch (error) { + console.log("DID operations not available on this network"); + } + + console.log("\\nāœ… People Chain identity operations demonstration completed!"); + console.log("Note: Identity operations require:"); + console.log("- Understanding of registrar fees and requirements"); + console.log("- Proper field validation and formatting"); + console.log("- Sufficient balance for registration and verification fees"); + console.log("- In a real application, you would sign and submit these transactions"); + console.log("- Identity verification may require third-party registrars"); + + } catch (error) { + console.error("āŒ Error in People Chain identity operations:", error); + } +}; + +demonstratePeopleChainIdentity().catch(console.error); +`; + } +} diff --git a/src/lib/examples/index.ts b/src/lib/examples/index.ts index 7a93860..5b5faa7 100644 --- a/src/lib/examples/index.ts +++ b/src/lib/examples/index.ts @@ -4,6 +4,8 @@ import { StakingOperationsExample } from "./StakingOperationsExample"; import { AssetHubExample } from "./AssetHubExample"; import { OpenGovExample } from "./OpenGovExample"; import { CoretimeExample } from "./CoretimeExample"; +import { PeopleChainExample } from "./PeopleChainExample"; + @@ -13,6 +15,8 @@ import { NetworkDashboardExample } from "./NetworkDashboardExample"; import { AccountBalanceCheckerExample } from "./AccountBalanceCheckerExample"; import { WalletTransferExample } from "./WalletTransferExample"; import { AcalaDeFiExample } from "./AcalaDeFiExample"; + new PeopleChainExample(), + import type { Example, ExampleLevel } from "../types/example"; new CoretimeExample(), From aefb1b7ce9bc94020fc00df816e7c4457b455379 Mon Sep 17 00:00:00 2001 From: codingsh Date: Tue, 23 Dec 2025 18:11:19 +0000 Subject: [PATCH 4/4] Add XCM V4 Operations Example - Create XcmV4Example.ts demonstrating latest XCM V4 features - Shows teleport assets, reserve transfers, limited teleports - Includes XCM message execution and version negotiation - Advanced level example with xcm, cross-chain, assets categories - Registered the example in the example registry --- src/lib/examples/XcmV4Example.ts | 266 +++++++++++++++++++++++++++++++ src/lib/examples/index.ts | 4 + 2 files changed, 270 insertions(+) create mode 100644 src/lib/examples/XcmV4Example.ts diff --git a/src/lib/examples/XcmV4Example.ts b/src/lib/examples/XcmV4Example.ts new file mode 100644 index 0000000..a6c2d9f --- /dev/null +++ b/src/lib/examples/XcmV4Example.ts @@ -0,0 +1,266 @@ +import type { Network } from "../types/network"; +import { ExampleFactory } from "./factory"; + +export class XcmV4Example extends ExampleFactory { + constructor() { + super({ + id: "xcm-v4-operations", + name: "XCM V4 Operations", + description: "Demonstrate latest XCM V4 features: teleport assets, reserve transfers, and cross-chain messaging", + level: "advanced", + categories: ["xcm", "cross-chain", "assets", "teleport"], + }); + } + + generateCode(network: Network): string { + return `// XCM V4 Operations Example on ${network.name} +${this.getImports(network, true)} + +// Connect to ${network.name} +const client = createClient( + withPoladotSdkCompat( + getWsProvider("${network.endpoint}") + ) +); + +// Get the typed API using the descriptors +const typedApi = client.getTypedApi(${network.descriptorKey}); + +// XCM V4 operations demonstration +const demonstrateXcmV4Operations = async () => { + try { + console.log("🌐 Starting XCM V4 operations demonstration..."); + + // 1. Query XCM version + console.log("\\nšŸ” Querying XCM version and capabilities:"); + try { + const version = await typedApi.query.PolkadotXcm.VersionNotifiers.getValue(); + console.log("XCM version notifiers:", version); + } catch (error) { + console.log("Version notifiers not available"); + } + + // 2. Query supported locations + console.log("\\nšŸ“ Querying supported XCM locations:"); + try { + const locations = await typedApi.query.PolkadotXcm.SupportedVersion.getEntries(); + console.log("Supported XCM locations:", locations.length); + } catch (error) { + console.log("Supported locations not available"); + } + + // 3. Demonstrate teleport assets (XCM V4) + console.log("\\nāœˆļø Teleport Assets Example (XCM V4):"); + console.log("This would teleport assets to another chain:"); + const teleportTx = typedApi.tx.PolkadotXcm.teleport_assets({ + dest: { + V4: { + parents: 1, + interior: { + X1: { Parachain: 2000 } // Target parachain + } + } + }, + beneficiary: { + V4: { + parents: 0, + interior: { + X1: { AccountId32: { id: "${this.getTestAccount("alice")}" } } + } + } + }, + assets: { + V4: [{ + id: { Concrete: { parents: 1, interior: "Here" } }, + fun: { Fungible: 1000000000000n } // 1000 DOT/KSM + }] + }, + fee_asset_item: 0 + }); + console.log("Teleport assets transaction created (not submitted in simulator)"); + + // 4. Demonstrate reserve transfer assets + console.log("\\nšŸ”„ Reserve Transfer Assets Example (XCM V4):"); + console.log("This would perform a reserve transfer:"); + const reserveTransferTx = typedApi.tx.PolkadotXcm.reserve_transfer_assets({ + dest: { + V4: { + parents: 1, + interior: { + X1: { Parachain: 2000 } + } + } + }, + beneficiary: { + V4: { + parents: 0, + interior: { + X1: { AccountId32: { id: "${this.getTestAccount("bob")}" } } + } + } + }, + assets: { + V4: [{ + id: { Concrete: { parents: 1, interior: "Here" } }, + fun: { Fungible: 500000000000n } // 500 DOT/KSM + }] + }, + fee_asset_item: 0 + }); + console.log("Reserve transfer transaction created (not submitted in simulator)"); + + // 5. Demonstrate limited teleport assets + console.log("\\nšŸŽÆ Limited Teleport Assets Example:"); + console.log("This would perform a limited teleport:"); + const limitedTeleportTx = typedApi.tx.PolkadotXcm.limited_teleport_assets({ + dest: { + V4: { + parents: 1, + interior: { + X1: { Parachain: 1000 } // Asset Hub + } + } + }, + beneficiary: { + V4: { + parents: 0, + interior: { + X1: { AccountId32: { id: "${this.getTestAccount("alice")}" } } + } + } + }, + assets: { + V4: [{ + id: { Concrete: { parents: 1, interior: "Here" } }, + fun: { Fungible: 100000000000n } + }] + }, + fee_asset_item: 0, + weight_limit: { Limited: { ref_time: 2000000000n, proof_size: 50000n } } + }); + console.log("Limited teleport transaction created (not submitted in simulator)"); + + // 6. Demonstrate transfer reserve asset + console.log("\\nšŸ¦ Transfer Reserve Asset Example:"); + console.log("This would transfer reserve-backed assets:"); + const transferReserveTx = typedApi.tx.PolkadotXcm.transfer_reserve_asset({ + assets: { + V4: [{ + id: { Concrete: { parents: 1, interior: "Here" } }, + fun: { Fungible: 200000000000n } + }] + }, + dest: { + V4: { + parents: 1, + interior: { + X1: { Parachain: 2000 } + } + } + }, + xcm: { + V4: [ + { + ReserveAssetDeposited: { + assets: { Wild: { AllCounted: 1 } } + } + }, + { + ClearOrigin: null + }, + { + DepositAsset: { + assets: { Wild: { AllCounted: 1 } }, + beneficiary: { + AccountId32: { id: "${this.getTestAccount("bob")}" } + } + } + } + ] + } + }); + console.log("Transfer reserve asset transaction created (not submitted in simulator)"); + + // 7. Query XCM queues + console.log("\\nšŸ“‹ Querying XCM queues:"); + try { + const outboundQueue = await typedApi.query.PolkadotXcm.Queries.getValue(); + console.log("Outbound XCM queries:", outboundQueue); + } catch (error) { + console.log("XCM queue queries not available"); + } + + // 8. Demonstrate execute XCM message + console.log("\\n⚔ Execute XCM Message Example:"); + console.log("This would execute a custom XCM message:"); + const executeTx = typedApi.tx.PolkadotXcm.execute({ + message: { + V4: [ + { + WithdrawAsset: { + assets: { + Concrete: { + parents: 0, + interior: { + X1: { PalletInstance: 10 } + } + } + } + } + }, + { + DepositAsset: { + assets: { Wild: { AllCounted: 1 } }, + beneficiary: { + AccountId32: { id: "${this.getTestAccount("alice")}" } + } + } + } + ] + }, + max_weight: { ref_time: 1000000000n, proof_size: 10000n } + }); + console.log("Execute XCM message transaction created (not submitted in simulator)"); + + // 9. Query XCM version negotiation + console.log("\\nšŸ¤ Querying XCM version negotiation:"); + try { + const versionNotify = await typedApi.query.PolkadotXcm.VersionNotifyTargets.getValue(); + console.log("Version notify targets:", versionNotify); + } catch (error) { + console.log("Version negotiation queries not available"); + } + + // 10. Demonstrate force XCM version + console.log("\\nšŸ”§ Force XCM Version Example:"); + console.log("This would force a specific XCM version (admin only):"); + const forceVersionTx = typedApi.tx.PolkadotXcm.force_xcm_version({ + location: { + V4: { + parents: 1, + interior: { + X1: { Parachain: 2000 } + } + } + }, + version: 4 + }); + console.log("Force XCM version transaction created (not submitted in simulator)"); + + console.log("\\nāœ… XCM V4 operations demonstration completed!"); + console.log("Note: XCM operations require:"); + console.log("- Understanding of XCM multilocation format"); + console.log("- Knowledge of destination chain requirements"); + console.log("- Proper weight limits and fee calculations"); + console.log("- In a real application, you would sign and submit these transactions"); + console.log("- XCM V4 introduces enhanced asset handling and better error reporting"); + + } catch (error) { + console.error("āŒ Error in XCM V4 operations:", error); + } +}; + +demonstrateXcmV4Operations().catch(console.error); +`; + } +} diff --git a/src/lib/examples/index.ts b/src/lib/examples/index.ts index 5b5faa7..516ff2a 100644 --- a/src/lib/examples/index.ts +++ b/src/lib/examples/index.ts @@ -5,6 +5,8 @@ import { AssetHubExample } from "./AssetHubExample"; import { OpenGovExample } from "./OpenGovExample"; import { CoretimeExample } from "./CoretimeExample"; import { PeopleChainExample } from "./PeopleChainExample"; +import { XcmV4Example } from "./XcmV4Example"; + @@ -14,6 +16,8 @@ import { SimpleTransferExample } from "./SimpleTransferExample"; import { NetworkDashboardExample } from "./NetworkDashboardExample"; import { AccountBalanceCheckerExample } from "./AccountBalanceCheckerExample"; import { WalletTransferExample } from "./WalletTransferExample"; + new XcmV4Example(), + import { AcalaDeFiExample } from "./AcalaDeFiExample"; new PeopleChainExample(),