Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New XC Asset Registration Process #1013

Merged
merged 65 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
0c08cb2
rev
themacexpert Sep 30, 2024
1b4b1af
Merge branch 'master' into themacexpert/ups
themacexpert Oct 23, 2024
6e8beb0
rev
themacexpert Oct 23, 2024
3e0c659
rev
themacexpert Oct 23, 2024
446028d
rev
themacexpert Oct 23, 2024
e24eac7
rev
themacexpert Oct 23, 2024
8e60218
rev
themacexpert Oct 23, 2024
563698e
add
themacexpert Oct 23, 2024
5499060
run grammarly
themacexpert Oct 23, 2024
54470e9
run prettier
themacexpert Oct 23, 2024
0a7cca0
rev
themacexpert Oct 23, 2024
e1f2dd1
revision
themacexpert Dec 13, 2024
faa5e73
revisions
themacexpert Dec 13, 2024
0561cd7
add
themacexpert Jan 15, 2025
33c1390
rev
themacexpert Jan 23, 2025
e01b316
clarify asset ID creation process
themacexpert Jan 23, 2025
a1aff3e
update relative price
themacexpert Jan 24, 2025
ca00d3a
clarify relative price etc
themacexpert Jan 24, 2025
e58fc11
rev
themacexpert Jan 24, 2025
ac80547
rev
themacexpert Jan 24, 2025
41df3b7
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Jan 29, 2025
8086a12
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Jan 29, 2025
cfdea79
update relative price script
themacexpert Jan 29, 2025
b463579
clarify relative price calculation with steps etc
themacexpert Jan 30, 2025
2eb4e22
progress
themacexpert Jan 30, 2025
a747f91
add
themacexpert Jan 31, 2025
020cb72
run grammarly
themacexpert Jan 31, 2025
2eabe59
additional grammar etc
themacexpert Jan 31, 2025
4af094d
Update .snippets/code/builders/interoperability/xcm/xc-registration/a…
themacexpert Feb 7, 2025
da2a5f3
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 7, 2025
234d455
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 7, 2025
be3d061
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 7, 2025
5a396d6
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 7, 2025
68e2c6b
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 7, 2025
4b54698
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 7, 2025
4966320
remove how relative price is calculated
themacexpert Feb 7, 2025
ae66ffc
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 7, 2025
b07a1ca
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 7, 2025
231dd39
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 7, 2025
aacef73
clarify commands
themacexpert Feb 7, 2025
53591ef
add generic call propose info
themacexpert Feb 7, 2025
16a1be4
revise relative price examples
themacexpert Feb 7, 2025
f877a22
revise image diagram
themacexpert Feb 7, 2025
25b908e
rev
themacexpert Feb 7, 2025
2345876
Update .snippets/code/builders/interoperability/xcm/xc-registration/a…
themacexpert Feb 11, 2025
5f4137e
Update .snippets/code/builders/interoperability/xcm/xc-registration/a…
themacexpert Feb 11, 2025
35737ad
Update .snippets/code/builders/interoperability/xcm/xc-registration/a…
themacexpert Feb 11, 2025
69b0fa1
Update .snippets/code/builders/interoperability/xcm/xc-registration/i…
themacexpert Feb 11, 2025
9c87ad7
Update .snippets/code/builders/interoperability/xcm/xc-registration/i…
themacexpert Feb 11, 2025
ea67718
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
d61d611
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
ae90244
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
27cba57
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
39d8b3a
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
07dbbc4
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
64a4bd2
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
07bbaf3
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
bdaa52b
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
a451f9f
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
2611503
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
7a620de
Update builders/interoperability/xcm/xc-registration/assets.md
themacexpert Feb 11, 2025
654c3c1
make bold lists
themacexpert Feb 11, 2025
5cba02d
rev
themacexpert Feb 11, 2025
868c61f
prettier
themacexpert Feb 11, 2025
1a29184
rev
themacexpert Feb 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { encodeAddress } from '@polkadot/util-crypto';
import { u8aToHex } from '@polkadot/util';

async function getEncodedBatchCallData() {
// Connect to Moonbase Alpha
const provider = new WsProvider('wss://moonbase-alpha.public.blastapi.io');
const api = await ApiPromise.create({ provider });

try {
// Parameters for createForeignAsset
const assetId = '340282366920938463463374607431768211455';
const xcmLocation = {
parents: 1,
interior: {
X1: [{ Parachain: 888 }],
},
};
const assetName = Array.from(Buffer.from('My Foreign Asset'));
const assetSymbol = Array.from(Buffer.from('xcMFA'));
const decimals = 18;

// Parameters for xcmWeightTrader.addAsset
const relativePrice = '5000';

// Create individual calls
const createAssetCall = api.tx.evmForeignAssets.createForeignAsset(
assetId,
xcmLocation,
decimals,
assetSymbol,
assetName
);

const addAssetCall = api.tx.xcmWeightTrader.addAsset(
xcmLocation,
relativePrice
);

// Combine calls into a batch
const batchCall = api.tx.utility.batch([createAssetCall, addAssetCall]);

// Get the encoded call data for the batch
const encodedBatchData = batchCall.method.toHex();

console.log('Individual Calls:');
console.log('Create Asset Call:', createAssetCall.method.toHex());
console.log('Add Asset Call:', addAssetCall.method.toHex());
console.log('\nBatch Call:');
console.log('Encoded Batch Call Data:', encodedBatchData);

await api.disconnect();
return encodedBatchData;
} catch (error) {
console.error('Error details:', error);
await api.disconnect();
throw error;
}
}

// Execute the function
getEncodedBatchCallData()
.catch(console.error)
.finally(() => process.exit());
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { encodeAddress } from '@polkadot/util-crypto';
import { u8aToHex } from '@polkadot/util';

async function getEncodedCallData() {
// Connect to Moonbase Alpha
const provider = new WsProvider('wss://moonbase-alpha.public.blastapi.io');
const api = await ApiPromise.create({ provider });

// Example parameters with correct types
const assetId = '340282366920938463463374607431768211455';

// XCM V4 Multilocation structured according to Moonbeam's format
const xcmLocation = {
parents: 1,
interior: {
X1: [
{ Parachain: 888 }, // Replace with actual parachain ID
],
},
};

// Convert strings to Uint8Array for Bytes type
const assetName = Array.from(Buffer.from('My Foreign Asset'));
const assetSymbol = Array.from(Buffer.from('xcMFA'));

// Decimals as a number (not string)
const decimals = 18;

try {
// Create the call
const call = api.tx.evmForeignAssets.createForeignAsset(
assetId,
xcmLocation,
decimals,
assetSymbol,
assetName
);

// Get the encoded call data
const encodedData = call.method.toHex();
console.log('Encoded Call Data:', encodedData);

await api.disconnect();
return encodedData;
} catch (error) {
console.error('Error details:', error);
await api.disconnect();
throw error;
}
}

// Execute the function
getEncodedCallData()
.catch(console.error)
.finally(() => process.exit());
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';
import { u8aToHex } from '@polkadot/util';

async function submitPreimage() {
// Wait for the crypto libraries to be ready
await cryptoWaitReady();

// Connect to Moonbase Alpha
const provider = new WsProvider('wss://moonbase-alpha.public.blastapi.io');
const api = await ApiPromise.create({ provider });

// Initialize keyring and add account
const keyring = new Keyring({ type: 'ethereum' }); // Use ethereum type for Moonbeam

// IMPORTANT: Replace with your private key
const PRIVATE_KEY = 'INSERT-PRIVATE-KEY'; // e.g., '0x1234...'
const account = keyring.addFromUri(PRIVATE_KEY);

console.log('Account address:', account.address);

// The encoded call data to be submitted as preimage
const encodedCallData =
'0x0100083800ffffffffffffffffffffffffffffffff010100e10d121478634d4641404d7920466f726569676e2041737365743a00010100e10d88130000000000000000000000000000';

try {
// Create the notePreimage call
const preimageCall = api.tx.preimage.notePreimage(encodedCallData);

// Calculate the hash of the preimage
const preimageHash = await api.registry.hash(encodedCallData);

console.log('Submitting preimage for encoded call data:');
console.log('Original Call Data:', encodedCallData);
console.log('Note Preimage Encoded Call:', preimageCall.method.toHex());
console.log('Preimage Hash:', preimageHash.toHex());

// Get the account's current nonce
const nonce = await api.rpc.system.accountNextIndex(account.address);

// Submit and wait for transaction
const txHash = await new Promise((resolve, reject) => {
preimageCall
.signAndSend(
account,
{ nonce },
({ status, dispatchError, events }) => {
if (dispatchError) {
if (dispatchError.isModule) {
// Handle module error
const decoded = api.registry.findMetaError(
dispatchError.asModule
);
const { docs, name, section } = decoded;
reject(new Error(`${section}.${name}: ${docs.join(' ')}`));
} else {
// Handle other errors
reject(new Error(dispatchError.toString()));
}
}

if (status.isInBlock) {
console.log(
`Transaction included in blockHash ${status.asInBlock}`
);
} else if (status.isFinalized) {
console.log(
`Transaction finalized in blockHash ${status.asFinalized}`
);
resolve(status.asFinalized);
}
}
)
.catch(reject);
});

console.log('Transaction successful! Hash:', txHash.toHex());
console.log(
'Preimage hash (save this for reference):',
preimageHash.toHex()
);

await api.disconnect();
return {
transactionHash: txHash.toHex(),
preimageHash: preimageHash.toHex(),
};
} catch (error) {
console.error('Error details:', error);
await api.disconnect();
throw error;
}
}

// Execute the function
submitPreimage()
.catch(console.error)
.finally(() => process.exit());
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';

async function submitReferendum() {
// Wait for the crypto libraries to be ready
await cryptoWaitReady();

// Connect to Moonbase Alpha
const provider = new WsProvider('wss://moonbase-alpha.public.blastapi.io');
const api = await ApiPromise.create({ provider });

// Initialize keyring and add account
const keyring = new Keyring({ type: 'ethereum' });

// IMPORTANT: Replace with your private key
const PRIVATE_KEY = 'INSERT-PRIVATE-KEY';
const account = keyring.addFromUri(PRIVATE_KEY);

console.log('Account address:', account.address);

try {
// Get current block number for enactment calculation
const currentBlock = await api.query.system.number();
const enactmentBlock = currentBlock.toNumber() + 100;

// The preimage data and hash
const preimageHash =
'0x2ac24641cebeff3827ba10eb264d2db2990607c89a3fa2c8b2fef6b1e37e35e3';

// Length of the original batch call data
// This should match the length of your original encoded call data
const preimageLength = 73; // This is the length of your batch call encoded data

// Parameters for the referendum
const origin = { Origins: 'FastGeneralAdmin' };
const proposal = {
Lookup: {
hash: preimageHash,
len: preimageLength,
},
};
const enactment = { After: 100 };

// Create the referendum submission call
const referendumCall = api.tx.referenda.submit(origin, proposal, enactment);

// Get the encoded call data
const encodedCall = referendumCall.method.toHex();
console.log('\nReferendum submission details:');
console.log('Encoded Call:', encodedCall);
console.log('Current Block:', currentBlock.toString());
console.log('Enactment Block:', enactmentBlock);
console.log('Preimage Hash:', preimageHash);
console.log('Preimage Length:', preimageLength);

// Get the account's current nonce
const nonce = await api.rpc.system.accountNextIndex(account.address);

// Submit and wait for transaction
const txHash = await new Promise((resolve, reject) => {
referendumCall
.signAndSend(
account,
{ nonce },
({ status, dispatchError, events }) => {
if (dispatchError) {
if (dispatchError.isModule) {
const decoded = api.registry.findMetaError(
dispatchError.asModule
);
const { docs, name, section } = decoded;
reject(new Error(`${section}.${name}: ${docs.join(' ')}`));
} else {
reject(new Error(dispatchError.toString()));
}
}

if (status.isInBlock) {
console.log(
`Transaction included in blockHash ${status.asInBlock}`
);
// Try to find the referendum index from events
events.forEach(({ event }) => {
if (
event.section === 'referenda' &&
event.method === 'Submitted'
) {
const [referendumIndex] = event.data;
console.log(
`Referendum submitted with index: ${referendumIndex}`
);
}
});
} else if (status.isFinalized) {
console.log(
`Transaction finalized in blockHash ${status.asFinalized}`
);
resolve(status.asFinalized);
}
}
)
.catch(reject);
});

console.log('Transaction successful! Hash:', txHash.toHex());

await api.disconnect();
return {
transactionHash: txHash.toHex(),
};
} catch (error) {
console.error('Error details:', error);
await api.disconnect();
throw error;
}
}

// Execute the function
submitReferendum()
.catch(console.error)
.finally(() => process.exit());
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>node batch-calls.js</span>
<span data-ty>Individual Calls:</span>
<span data-ty>Create Asset Call: 0x3800ffffffffffffffffffffffffffffffff010100e10d121478634d4641404d7920466f726569676e204173736574</span>
<span data-ty>Add Asset Call: 0x3a00010100e10d88130000000000000000000000000000</span>
<span data-ty>Batch Call:</span>
<span data-ty>Encoded Batch Call Data: 0x0100083800ffffffffffffffffffffffffffffffff010100e10d121478634d4641404d7920466f726569676e2041737365743a00010100e10d88130000000000000000000000000000</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>node createForeignAsset.js</span>
<span data-ty>Encoded Call Data: 0x3800ffffffffffffffffffffffffffffffff010100e10d121478634d4641404d7920466f726569676e204173736574</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>node submit-preimage.js</span>
<span data-ty>Account address: 0x569BE8d8b04538318e1722f6e375FD381D2da865</span>
<span data-ty>Submitting preimage for encoded call data:</span>
<span data-ty>Original Call Data: 0x0100083800ffffffffffffffffffffffffffffffff010100e10d121478634d4641404d7920466f726569676e2041737365743a00010100e10d88130000000000000000000000000000</span>
<span data-ty>Note Preimage Encoded Call: 0x2c0025010100083800ffffffffffffffffffffffffffffffff010100e10d121478634d4641404d7920466f726569676e2041737365743a00010100e10d88130000000000000000000000000000</span>
<span data-ty>Preimage Hash: 0x2ac24641cebeff3827ba10eb264d2db2990607c89a3fa2c8b2fef6b1e37e35e3</span>
<span data-ty>Transaction included in blockHash 0xf84ef0d3238cbc656e482494778acc9d849f14b5173d34c727a720aee48a6e69</span>
<span data-ty>Transaction finalized in blockHash 0xf84ef0d3238cbc656e482494778acc9d849f14b5173d34c727a720aee48a6e69</span>
<span data-ty>Transaction successful! Hash: 0xf84ef0d3238cbc656e482494778acc9d849f14b5173d34c727a720aee48a6e69</span>
<span data-ty>Preimage hash (save this for reference): 0x2ac24641cebeff3827ba10eb264d2db2990607c89a3fa2c8b2fef6b1e37e35e3</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>node submit-referendum.js</span>
<span data-ty>Account address: 0x569BE8d8b04538318e1722f6e375FD381D2da865</span>
<span data-ty>Referendum submission details:</span>
<span data-ty>Encoded Call: 0x2a002b04022ac24641cebeff3827ba10eb264d2db2990607c89a3fa2c8b2fef6b1e37e35e3490000000164000000</span>
<span data-ty>Current Block: 9150304</span>
<span data-ty>Enactment Block: 9150404</span>
<span data-ty>Preimage Hash: 0x2ac24641cebeff3827ba10eb264d2db2990607c89a3fa2c8b2fef6b1e37e35e3</span>
<span data-ty>Preimage Length: 73</span>
<span data-ty>Transaction included in blockHash 0x13d7f729af6fc803c863b6beba9e2e788f1d85114f5165c41f96b80dfdf49844</span>
<span data-ty>Referendum submitted with index: 79</span>
<span data-ty>Transaction finalized in blockHash 0x13d7f729af6fc803c863b6beba9e2e788f1d85114f5165c41f96b80dfdf49844</span>
<span data-ty>Transaction successful! Hash: 0x13d7f729af6fc803c863b6beba9e2e788f1d85114f5165c41f96b80dfdf49844</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div id="termynal" data-termynal>
<span data-ty="input"><span class="file-path"></span>node xcmWeightTrader.js</span>
<span data-ty>Encoded Call Data: 0x3a00010100e10d88130000000000000000000000000000</span>
</div>
Loading
Loading