chore: Add utility scripts for DEX pool management

- check-asset-state.mjs: Asset state verification
- check-balances.mjs: Balance checking utilities
- check-founder-balances.mjs: Founder account balance checks
- check-hez-balance.mjs: HEZ token balance verification
- check-pool-balances-detailed.mjs: Detailed pool balance analysis
- create-all-pools.mjs: Automated pool creation
- create-pez-wusdt-pool.mjs: PEZ/wUSDT pool setup
- mint-and-create-pools.mjs: Mint tokens and create pools
- mint-whez.mjs: wHEZ minting utility
- verify-pool-state.mjs: Pool state verification
- wrap-hez-and-create-all-pools.mjs: HEZ wrapping and pool setup

These scripts support DEX pool management and testing for beta testnet.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-11-05 12:55:15 +03:00
parent 4825ac3839
commit 5686386ef6
11 changed files with 1096 additions and 0 deletions
+62
View File
@@ -0,0 +1,62 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { cryptoWaitReady } from '@polkadot/util-crypto';
async function main() {
await cryptoWaitReady();
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
console.log('Checking current asset state...\n');
// Check if asset 2 exists
console.log('Asset ID 2 (wUSDT):');
try {
const asset2 = await api.query.assets.asset(2);
if (asset2.isSome) {
console.log(' EXISTS:', asset2.unwrap().toHuman());
} else {
console.log(' DOES NOT EXIST');
}
} catch (e) {
console.log(' ERROR:', e.message);
}
// Check asset 0 and 1
console.log('\nAsset ID 0 (wHEZ):');
try {
const asset0 = await api.query.assets.asset(0);
if (asset0.isSome) {
console.log(' EXISTS:', asset0.unwrap().toHuman());
} else {
console.log(' DOES NOT EXIST');
}
} catch (e) {
console.log(' ERROR:', e.message);
}
console.log('\nAsset ID 1 (PEZ):');
try {
const asset1 = await api.query.assets.asset(1);
if (asset1.isSome) {
console.log(' EXISTS:', asset1.unwrap().toHuman());
} else {
console.log(' DOES NOT EXIST');
}
} catch (e) {
console.log(' ERROR:', e.message);
}
// Check next asset ID
console.log('\nNext Asset ID:');
try {
const nextId = await api.query.assets.nextAssetId();
console.log(' ', nextId.toHuman());
} catch (e) {
console.log(' ERROR:', e.message);
}
await api.disconnect();
}
main().catch(console.error);
+39
View File
@@ -0,0 +1,39 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';
async function main() {
await cryptoWaitReady();
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
const keyring = new Keyring({ type: 'sr25519' });
const founder = keyring.addFromUri('skill dose toward always latin fish film cabbage praise blouse kingdom depth');
console.log('Founder address:', founder.address);
console.log('\nChecking balances...');
const whezBal = await api.query.assets.account(0, founder.address);
const pezBal = await api.query.assets.account(1, founder.address);
const wusdtBal = await api.query.assets.account(2, founder.address);
console.log(' wHEZ:', whezBal.isSome ? whezBal.unwrap().balance.toHuman() : '0');
console.log(' PEZ:', pezBal.isSome ? pezBal.unwrap().balance.toHuman() : '0');
console.log(' wUSDT:', wusdtBal.isSome ? wusdtBal.unwrap().balance.toHuman() : '0');
console.log('\nChecking pools...');
const pool1 = await api.query.assetConversion.pools([0, 1]);
const pool2 = await api.query.assetConversion.pools([0, 2]);
const pool3 = await api.query.assetConversion.pools([1, 2]);
console.log(' wHEZ/PEZ pool exists:', pool1.isSome);
console.log(' wHEZ/wUSDT pool exists:', pool2.isSome);
console.log(' PEZ/wUSDT pool exists:', pool3.isSome);
if (pool1.isSome) {
console.log('\nwHEZ/PEZ pool details:', pool1.unwrap().toHuman());
}
await api.disconnect();
}
main().catch(console.error);
+51
View File
@@ -0,0 +1,51 @@
import { ApiPromise, WsProvider, Keyring } from '@polkadot/api';
import { cryptoWaitReady } from '@polkadot/util-crypto';
async function main() {
await cryptoWaitReady();
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
const keyring = new Keyring({ type: 'sr25519' });
const founder = keyring.addFromUri('skill dose toward always latin fish film cabbage praise blouse kingdom depth');
console.log('💰 Founder Balances\n');
console.log(`Address: ${founder.address}\n`);
// Check wHEZ (asset 0)
const whezBalance = await api.query.assets.account(0, founder.address);
if (whezBalance.isSome) {
const whez = Number(whezBalance.unwrap().balance.toString()) / 1e12;
console.log(`wHEZ: ${whez.toLocaleString()}`);
} else {
console.log('wHEZ: 0');
}
// Check PEZ (asset 1)
const pezBalance = await api.query.assets.account(1, founder.address);
if (pezBalance.isSome) {
const pez = Number(pezBalance.unwrap().balance.toString()) / 1e12;
console.log(`PEZ: ${pez.toLocaleString()}`);
} else {
console.log('PEZ: 0');
}
// Check wUSDT (asset 2)
const wusdtBalance = await api.query.assets.account(2, founder.address);
if (wusdtBalance.isSome) {
const wusdt = Number(wusdtBalance.unwrap().balance.toString()) / 1e6;
console.log(`wUSDT: ${wusdt.toLocaleString()}`);
} else {
console.log('wUSDT: 0');
}
console.log('\n📊 Required for target pools:');
console.log('- wHEZ/wUSDT (4:1): 40,000 wHEZ + 10,000 wUSDT');
console.log('- PEZ/wUSDT (20:1): 200,000 PEZ + 10,000 wUSDT');
console.log('\n(Plus current pool balances need to be removed first)');
await api.disconnect();
}
main().catch(console.error);
+27
View File
@@ -0,0 +1,27 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';
async function main() {
await cryptoWaitReady();
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
const keyring = new Keyring({ type: 'sr25519' });
const founder = keyring.addFromUri('skill dose toward always latin fish film cabbage praise blouse kingdom depth');
console.log('Founder address:', founder.address);
// Check native HEZ balance
const { data: balance } = await api.query.system.account(founder.address);
console.log('\nNative HEZ balance:', balance.free.toHuman());
console.log('Reserved:', balance.reserved.toHuman());
console.log('Frozen:', balance.frozen.toHuman());
// Check wHEZ balance
const whezBal = await api.query.assets.account(0, founder.address);
console.log('\nwHEZ balance:', whezBal.isSome ? whezBal.unwrap().balance.toHuman() : '0');
await api.disconnect();
}
main().catch(console.error);
+113
View File
@@ -0,0 +1,113 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { cryptoWaitReady, blake2AsHex } from '@polkadot/util-crypto';
import { stringToU8a, u8aConcat, bnToU8a } from '@polkadot/util';
async function derivePoolAccount(api, asset1, asset2) {
// PalletId for AssetConversion: "py/ascon" (8 bytes)
const PALLET_ID = stringToU8a('py/ascon');
// Create PoolId tuple (u32, u32)
const poolId = api.createType('(u32, u32)', [asset1, asset2]);
// Create (PalletId, PoolId) tuple: ([u8; 8], (u32, u32))
const palletIdType = api.createType('[u8; 8]', PALLET_ID);
const fullTuple = api.createType('([u8; 8], (u32, u32))', [palletIdType, poolId]);
// Hash the SCALE-encoded tuple using BLAKE2-256
const accountHash = blake2AsHex(fullTuple.toU8a(), 256);
// Create AccountId from the hash
const poolAccountId = api.createType('AccountId32', accountHash);
return poolAccountId.toString();
}
async function main() {
await cryptoWaitReady();
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
console.log('🔍 Checking pool balances in detail\n');
// Check wHEZ/wUSDT pool (0, 2)
console.log('=== Pool: wHEZ/wUSDT (0, 2) ===');
const pool1Info = await api.query.assetConversion.pools([0, 2]);
if (pool1Info.isSome) {
const lpToken = pool1Info.unwrap().toJSON().lpToken;
console.log(`LP Token ID: ${lpToken}`);
const poolAccount = await derivePoolAccount(api, 0, 2);
console.log(`Pool Account: ${poolAccount}`);
// Query wHEZ balance (asset 0)
const whezBalance = await api.query.assets.account(0, poolAccount);
if (whezBalance.isSome) {
const whez = Number(whezBalance.unwrap().balance.toString()) / 1e12;
console.log(`wHEZ in pool: ${whez.toLocaleString()}`);
} else {
console.log('wHEZ balance: 0');
}
// Query wUSDT balance (asset 2)
const wusdtBalance = await api.query.assets.account(2, poolAccount);
if (wusdtBalance.isSome) {
const wusdt = Number(wusdtBalance.unwrap().balance.toString()) / 1e6;
console.log(`wUSDT in pool: ${wusdt.toLocaleString()}`);
// Calculate rate
const whezRaw = whezBalance.isSome ? Number(whezBalance.unwrap().balance.toString()) / 1e12 : 0;
if (whezRaw > 0) {
console.log(`Rate: 1 wUSDT = ${(whezRaw / wusdt).toFixed(4)} wHEZ`);
console.log(`Rate: 1 wHEZ = ${(wusdt / whezRaw).toFixed(4)} wUSDT`);
}
} else {
console.log('wUSDT balance: 0');
}
} else {
console.log('❌ Pool does not exist!');
}
// Check PEZ/wUSDT pool (1, 2)
console.log('\n=== Pool: PEZ/wUSDT (1, 2) ===');
const pool2Info = await api.query.assetConversion.pools([1, 2]);
if (pool2Info.isSome) {
const lpToken = pool2Info.unwrap().toJSON().lpToken;
console.log(`LP Token ID: ${lpToken}`);
const poolAccount = await derivePoolAccount(api, 1, 2);
console.log(`Pool Account: ${poolAccount}`);
// Query PEZ balance (asset 1)
const pezBalance = await api.query.assets.account(1, poolAccount);
if (pezBalance.isSome) {
const pez = Number(pezBalance.unwrap().balance.toString()) / 1e12;
console.log(`PEZ in pool: ${pez.toLocaleString()}`);
} else {
console.log('PEZ balance: 0');
}
// Query wUSDT balance (asset 2)
const wusdtBalance = await api.query.assets.account(2, poolAccount);
if (wusdtBalance.isSome) {
const wusdt = Number(wusdtBalance.unwrap().balance.toString()) / 1e6;
console.log(`wUSDT in pool: ${wusdt.toLocaleString()}`);
// Calculate rate
const pezRaw = pezBalance.isSome ? Number(pezBalance.unwrap().balance.toString()) / 1e12 : 0;
if (pezRaw > 0) {
console.log(`Rate: 1 wUSDT = ${(pezRaw / wusdt).toFixed(4)} PEZ`);
console.log(`Rate: 1 PEZ = ${(wusdt / pezRaw).toFixed(6)} wUSDT`);
}
} else {
console.log('wUSDT balance: 0');
}
} else {
console.log('❌ Pool does not exist!');
}
await api.disconnect();
}
main().catch(console.error);
+186
View File
@@ -0,0 +1,186 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';
async function main() {
await cryptoWaitReady();
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
const keyring = new Keyring({ type: 'sr25519' });
const founder = keyring.addFromUri('skill dose toward always latin fish film cabbage praise blouse kingdom depth');
console.log('\n🚀 Creating all 3 beta testnet pools...\n');
console.log('Target exchange rates:');
console.log(' 1 wUSDT = 4 wHEZ = 20 PEZ\n');
// Pool 1: wHEZ/PEZ (1 wHEZ = 5 PEZ)
console.log('📝 Pool 1: wHEZ/PEZ');
console.log(' Ratio: 100,000 wHEZ : 500,000 PEZ (1:5)');
const whezPez_whez = BigInt(100_000) * BigInt(10 ** 12); // 100k wHEZ (12 decimals)
const whezPez_pez = BigInt(500_000) * BigInt(10 ** 12); // 500k PEZ (12 decimals)
await new Promise((resolve, reject) => {
api.tx.assetConversion
.createPool(0, 1) // wHEZ=0, PEZ=1
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Create pool error:', dispatchError.toString());
// Pool might already exist, continue
} else {
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'PoolCreated') {
console.log(' ✓ Pool created');
}
});
}
resolve();
}
})
.catch(reject);
});
console.log(' Adding liquidity...');
await new Promise((resolve, reject) => {
api.tx.assetConversion
.addLiquidity(
0, 1, // wHEZ, PEZ
whezPez_whez.toString(),
whezPez_pez.toString(),
whezPez_whez.toString(), // min amounts (same as desired)
whezPez_pez.toString(),
founder.address
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Error:', dispatchError.toString());
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'LiquidityAdded') {
console.log(' ✓ Liquidity added to wHEZ/PEZ pool');
}
});
resolve();
}
})
.catch(reject);
});
// Pool 2: wHEZ/wUSDT (4 wHEZ = 1 wUSDT, or 1 wHEZ = 0.25 wUSDT)
console.log('\n📝 Pool 2: wHEZ/wUSDT');
console.log(' Ratio: 40,000 wHEZ : 10,000 wUSDT (4:1)');
const whezUsdt_whez = BigInt(40_000) * BigInt(10 ** 12); // 40k wHEZ (12 decimals)
const whezUsdt_usdt = BigInt(10_000) * BigInt(10 ** 6); // 10k wUSDT (6 decimals)
await new Promise((resolve, reject) => {
api.tx.assetConversion
.createPool(0, 2) // wHEZ=0, wUSDT=2
.signAndSend(founder, ({ status, dispatchError }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Create pool error:', dispatchError.toString());
} else {
console.log(' ✓ Pool created');
}
resolve();
}
})
.catch(reject);
});
console.log(' Adding liquidity...');
await new Promise((resolve, reject) => {
api.tx.assetConversion
.addLiquidity(
0, 2, // wHEZ, wUSDT
whezUsdt_whez.toString(),
whezUsdt_usdt.toString(),
whezUsdt_whez.toString(),
whezUsdt_usdt.toString(),
founder.address
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Error:', dispatchError.toString());
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'LiquidityAdded') {
console.log(' ✓ Liquidity added to wHEZ/wUSDT pool');
}
});
resolve();
}
})
.catch(reject);
});
// Pool 3: PEZ/wUSDT (20 PEZ = 1 wUSDT, or 1 PEZ = 0.05 wUSDT)
console.log('\n📝 Pool 3: PEZ/wUSDT');
console.log(' Ratio: 200,000 PEZ : 10,000 wUSDT (20:1)');
const pezUsdt_pez = BigInt(200_000) * BigInt(10 ** 12); // 200k PEZ (12 decimals)
const pezUsdt_usdt = BigInt(10_000) * BigInt(10 ** 6); // 10k wUSDT (6 decimals)
await new Promise((resolve, reject) => {
api.tx.assetConversion
.createPool(1, 2) // PEZ=1, wUSDT=2
.signAndSend(founder, ({ status, dispatchError }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Create pool error:', dispatchError.toString());
} else {
console.log(' ✓ Pool created');
}
resolve();
}
})
.catch(reject);
});
console.log(' Adding liquidity...');
await new Promise((resolve, reject) => {
api.tx.assetConversion
.addLiquidity(
1, 2, // PEZ, wUSDT
pezUsdt_pez.toString(),
pezUsdt_usdt.toString(),
pezUsdt_pez.toString(),
pezUsdt_usdt.toString(),
founder.address
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Error:', dispatchError.toString());
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'LiquidityAdded') {
console.log(' ✓ Liquidity added to PEZ/wUSDT pool');
}
});
resolve();
}
})
.catch(reject);
});
console.log('\n✅ All 3 pools created successfully!');
console.log('\nPool Summary:');
console.log(' 1. wHEZ/PEZ: 100k:500k (1 wHEZ = 5 PEZ)');
console.log(' 2. wHEZ/wUSDT: 40k:10k (4 wHEZ = 1 wUSDT)');
console.log(' 3. PEZ/wUSDT: 200k:10k (20 PEZ = 1 wUSDT)');
console.log('\nExchange rates: 1 wUSDT = 4 wHEZ = 20 PEZ ✓');
await api.disconnect();
}
main().catch(console.error);
+85
View File
@@ -0,0 +1,85 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';
async function main() {
await cryptoWaitReady();
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
const keyring = new Keyring({ type: 'sr25519' });
const founder = keyring.addFromUri('skill dose toward always latin fish film cabbage praise blouse kingdom depth');
console.log('\n📝 Creating PEZ/wUSDT pool');
console.log(' Ratio: 200,000 PEZ : 10,000 wUSDT (20:1)');
console.log(' Exchange rate: 1 wUSDT = 20 PEZ\n');
const pezAmount = BigInt(200_000) * BigInt(10 ** 12);
const wusdtAmount = BigInt(10_000) * BigInt(10 ** 6);
// Check if pool exists
const poolExists = await api.query.assetConversion.pools([1, 2]);
if (poolExists.isNone) {
console.log('Creating pool...');
await new Promise((resolve, reject) => {
api.tx.assetConversion
.createPool(1, 2)
.signAndSend(founder, ({ status, dispatchError }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Error:', dispatchError.toString());
reject(new Error(dispatchError.toString()));
return;
}
console.log(' ✓ Pool created');
resolve();
}
})
.catch(reject);
});
} else {
console.log('✓ Pool already exists');
}
console.log('Adding liquidity...');
await new Promise((resolve, reject) => {
api.tx.assetConversion
.addLiquidity(
1, 2,
pezAmount.toString(),
wusdtAmount.toString(),
pezAmount.toString(),
wusdtAmount.toString(),
founder.address
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
if (dispatchError.isModule) {
const decoded = api.registry.findMetaError(dispatchError.asModule);
console.log(' Error:', decoded.name, '-', decoded.docs.join(' '));
} else {
console.log(' Error:', dispatchError.toString());
}
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'LiquidityAdded') {
console.log(' ✓ Liquidity added to PEZ/wUSDT pool!');
console.log(' Amounts:', event.data.toHuman());
}
});
resolve();
}
})
.catch(reject);
});
console.log('\n✅ PEZ/wUSDT pool is ready!');
console.log('Exchange rate: 1 wUSDT = 20 PEZ ✓');
await api.disconnect();
}
main().catch(console.error);
+237
View File
@@ -0,0 +1,237 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';
async function main() {
await cryptoWaitReady();
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
const keyring = new Keyring({ type: 'sr25519' });
const founder = keyring.addFromUri('skill dose toward always latin fish film cabbage praise blouse kingdom depth');
console.log('\n🔍 Checking founder token balances...');
console.log('Founder address:', founder.address);
// Check balances
const whezBalance = await api.query.assets.account(0, founder.address);
const pezBalance = await api.query.assets.account(1, founder.address);
const wusdtBalance = await api.query.assets.account(2, founder.address);
console.log('\nCurrent balances:');
console.log(' wHEZ:', whezBalance.isSome ? whezBalance.unwrap().balance.toString() : '0');
console.log(' PEZ:', pezBalance.isSome ? pezBalance.unwrap().balance.toString() : '0');
console.log(' wUSDT:', wusdtBalance.isSome ? wusdtBalance.unwrap().balance.toString() : '0');
// Mint wHEZ to founder using sudo
console.log('\n💰 Minting 200,000 wHEZ to founder via sudo...');
const whezAmount = BigInt(200_000) * BigInt(10 ** 12);
await new Promise((resolve, reject) => {
api.tx.sudo
.sudo(
api.tx.assets.mint(0, founder.address, whezAmount.toString())
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Error:', dispatchError.toString());
reject(new Error(dispatchError.toString()));
return;
}
console.log(' ✓ wHEZ minted successfully');
resolve();
}
})
.catch(reject);
});
console.log('\n🚀 Creating all 3 beta testnet pools...\n');
console.log('Target exchange rates:');
console.log(' 1 wUSDT = 4 wHEZ = 20 PEZ\n');
// Pool 1: wHEZ/PEZ (1 wHEZ = 5 PEZ)
console.log('📝 Pool 1: wHEZ/PEZ');
console.log(' Ratio: 100,000 wHEZ : 500,000 PEZ (1:5)');
const whezPez_whez = BigInt(100_000) * BigInt(10 ** 12);
const whezPez_pez = BigInt(500_000) * BigInt(10 ** 12);
// Check if pool exists
const pool1 = await api.query.assetConversion.pools([0, 1]);
if (pool1.isNone) {
await new Promise((resolve, reject) => {
api.tx.assetConversion
.createPool(0, 1)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Create pool error:', dispatchError.toString());
} else {
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'PoolCreated') {
console.log(' ✓ Pool created');
}
});
}
resolve();
}
})
.catch(reject);
});
} else {
console.log(' ✓ Pool already exists');
}
console.log(' Adding liquidity...');
await new Promise((resolve, reject) => {
api.tx.assetConversion
.addLiquidity(
0, 1,
whezPez_whez.toString(),
whezPez_pez.toString(),
whezPez_whez.toString(),
whezPez_pez.toString(),
founder.address
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Error:', dispatchError.toString());
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'LiquidityAdded') {
console.log(' ✓ Liquidity added to wHEZ/PEZ pool');
}
});
resolve();
}
})
.catch(reject);
});
// Pool 2: wHEZ/wUSDT (4:1)
console.log('\n📝 Pool 2: wHEZ/wUSDT');
console.log(' Ratio: 40,000 wHEZ : 10,000 wUSDT (4:1)');
const whezUsdt_whez = BigInt(40_000) * BigInt(10 ** 12);
const whezUsdt_usdt = BigInt(10_000) * BigInt(10 ** 6);
const pool2 = await api.query.assetConversion.pools([0, 2]);
if (pool2.isNone) {
await new Promise((resolve, reject) => {
api.tx.assetConversion
.createPool(0, 2)
.signAndSend(founder, ({ status, dispatchError }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Create pool error:', dispatchError.toString());
} else {
console.log(' ✓ Pool created');
}
resolve();
}
})
.catch(reject);
});
} else {
console.log(' ✓ Pool already exists');
}
console.log(' Adding liquidity...');
await new Promise((resolve, reject) => {
api.tx.assetConversion
.addLiquidity(
0, 2,
whezUsdt_whez.toString(),
whezUsdt_usdt.toString(),
whezUsdt_whez.toString(),
whezUsdt_usdt.toString(),
founder.address
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Error:', dispatchError.toString());
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'LiquidityAdded') {
console.log(' ✓ Liquidity added to wHEZ/wUSDT pool');
}
});
resolve();
}
})
.catch(reject);
});
// Pool 3: PEZ/wUSDT (20:1)
console.log('\n📝 Pool 3: PEZ/wUSDT');
console.log(' Ratio: 200,000 PEZ : 10,000 wUSDT (20:1)');
const pezUsdt_pez = BigInt(200_000) * BigInt(10 ** 12);
const pezUsdt_usdt = BigInt(10_000) * BigInt(10 ** 6);
const pool3 = await api.query.assetConversion.pools([1, 2]);
if (pool3.isNone) {
await new Promise((resolve, reject) => {
api.tx.assetConversion
.createPool(1, 2)
.signAndSend(founder, ({ status, dispatchError }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Create pool error:', dispatchError.toString());
} else {
console.log(' ✓ Pool created');
}
resolve();
}
})
.catch(reject);
});
} else {
console.log(' ✓ Pool already exists');
}
console.log(' Adding liquidity...');
await new Promise((resolve, reject) => {
api.tx.assetConversion
.addLiquidity(
1, 2,
pezUsdt_pez.toString(),
pezUsdt_usdt.toString(),
pezUsdt_pez.toString(),
pezUsdt_usdt.toString(),
founder.address
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Error:', dispatchError.toString());
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'LiquidityAdded') {
console.log(' ✓ Liquidity added to PEZ/wUSDT pool');
}
});
resolve();
}
})
.catch(reject);
});
console.log('\n✅ All 3 pools created successfully!');
console.log('\nPool Summary:');
console.log(' 1. wHEZ/PEZ: 100k:500k (1 wHEZ = 5 PEZ)');
console.log(' 2. wHEZ/wUSDT: 40k:10k (4 wHEZ = 1 wUSDT)');
console.log(' 3. PEZ/wUSDT: 200k:10k (20 PEZ = 1 wUSDT)');
console.log('\nExchange rates: 1 wUSDT = 4 wHEZ = 20 PEZ ✓');
await api.disconnect();
}
main().catch(console.error);
+57
View File
@@ -0,0 +1,57 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';
async function main() {
await cryptoWaitReady();
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
const keyring = new Keyring({ type: 'sr25519' });
const founder = keyring.addFromUri('skill dose toward always latin fish film cabbage praise blouse kingdom depth');
console.log('Minting 200,000 wHEZ to founder via sudo...');
const whezAmount = BigInt(200_000) * BigInt(10 ** 12);
await new Promise((resolve, reject) => {
api.tx.sudo
.sudo(
api.tx.assets.mint(0, founder.address, whezAmount.toString())
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
console.log('Transaction status:', status.type);
if (status.isInBlock) {
if (dispatchError) {
if (dispatchError.isModule) {
const decoded = api.registry.findMetaError(dispatchError.asModule);
console.log(' Error:', decoded.name, '-', decoded.docs.join(' '));
} else {
console.log(' Error:', dispatchError.toString());
}
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
console.log(' Event:', event.section + '.' + event.method);
if (event.section === 'sudo' && event.method === 'Sudid') {
const result = event.data[0];
if (result.isOk) {
console.log(' ✓ Sudo call succeeded');
} else {
console.log(' ✗ Sudo call failed:', result.asErr.toString());
}
}
});
resolve();
}
})
.catch(reject);
});
console.log('\nChecking balance after mint...');
const whezBal = await api.query.assets.account(0, founder.address);
console.log('wHEZ balance:', whezBal.isSome ? whezBal.unwrap().balance.toHuman() : '0');
await api.disconnect();
}
main().catch(console.error);
+57
View File
@@ -0,0 +1,57 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
async function main() {
const api = await ApiPromise.create({
provider: new WsProvider('ws://127.0.0.1:9944')
});
console.log('\n🔍 Checking PEZ/wUSDT Pool State...\n');
// Check if pool exists
const pool = await api.query.assetConversion.pools([1, 2]);
console.log('Pool exists:', pool.isSome);
if (pool.isSome) {
console.log('Pool data:', pool.unwrap().toHuman());
// Get pool reserves
const reserves = await api.query.assetConversion.poolReserves([1, 2]);
console.log('\nPool reserves:', reserves.toHuman());
}
// Check assets exist
const asset1 = await api.query.assets.asset(1);
const asset2 = await api.query.assets.asset(2);
console.log('\nPEZ (asset 1) exists:', asset1.isSome);
console.log('wUSDT (asset 2) exists:', asset2.isSome);
if (asset1.isSome) {
console.log('PEZ metadata:', (await api.query.assets.metadata(1)).toHuman());
}
if (asset2.isSome) {
console.log('wUSDT metadata:', (await api.query.assets.metadata(2)).toHuman());
}
// Check all existing pools
console.log('\n📊 Checking all pools...');
const allPoolIds = [
[0, 1],
[0, 2],
[1, 2]
];
for (const poolId of allPoolIds) {
const poolExists = await api.query.assetConversion.pools(poolId);
if (poolExists.isSome) {
const reserves = await api.query.assetConversion.poolReserves(poolId);
console.log(`\nPool [${poolId}]:`, poolExists.unwrap().toHuman());
console.log(` Reserves:`, reserves.toHuman());
} else {
console.log(`\nPool [${poolId}]: Does not exist`);
}
}
await api.disconnect();
}
main().catch(console.error);
+182
View File
@@ -0,0 +1,182 @@
import { ApiPromise, WsProvider } from '@polkadot/api';
import { Keyring } from '@polkadot/keyring';
import { cryptoWaitReady } from '@polkadot/util-crypto';
async function main() {
await cryptoWaitReady();
const wsProvider = new WsProvider('ws://127.0.0.1:9944');
const api = await ApiPromise.create({ provider: wsProvider });
const keyring = new Keyring({ type: 'sr25519' });
const founder = keyring.addFromUri('skill dose toward always latin fish film cabbage praise blouse kingdom depth');
console.log('\n🔄 Wrapping 200,000 HEZ to wHEZ...');
const wrapAmount = BigInt(200_000) * BigInt(10 ** 12);
await new Promise((resolve, reject) => {
api.tx.tokenWrapper
.wrap(wrapAmount.toString())
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
if (dispatchError.isModule) {
const decoded = api.registry.findMetaError(dispatchError.asModule);
console.log(' Error:', decoded.name, '-', decoded.docs.join(' '));
} else {
console.log(' Error:', dispatchError.toString());
}
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
if (event.section === 'tokenWrapper') {
console.log(' Event:', event.method, event.data.toHuman());
}
});
console.log(' ✓ Wrapped 200,000 HEZ to wHEZ');
resolve();
}
})
.catch(reject);
});
console.log('\n🚀 Creating all 3 pools...\n');
console.log('Target exchange rates:');
console.log(' 1 wUSDT = 4 wHEZ = 20 PEZ\n');
// Pool 1: wHEZ/PEZ (1 wHEZ = 5 PEZ)
console.log('📝 Pool 1: wHEZ/PEZ');
console.log(' Ratio: 100,000 wHEZ : 500,000 PEZ (1:5)');
const whezPez_whez = BigInt(100_000) * BigInt(10 ** 12);
const whezPez_pez = BigInt(500_000) * BigInt(10 ** 12);
const pool1 = await api.query.assetConversion.pools([0, 1]);
if (pool1.isNone) {
await new Promise((resolve, reject) => {
api.tx.assetConversion
.createPool(0, 1)
.signAndSend(founder, ({ status, dispatchError }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Create error:', dispatchError.toString());
} else {
console.log(' ✓ Pool created');
}
resolve();
}
})
.catch(reject);
});
} else {
console.log(' ✓ Pool already exists');
}
console.log(' Adding liquidity...');
await new Promise((resolve, reject) => {
api.tx.assetConversion
.addLiquidity(
0, 1,
whezPez_whez.toString(),
whezPez_pez.toString(),
whezPez_whez.toString(),
whezPez_pez.toString(),
founder.address
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
if (dispatchError.isModule) {
const decoded = api.registry.findMetaError(dispatchError.asModule);
console.log(' Error:', decoded.name, '-', decoded.docs.join(' '));
} else {
console.log(' Error:', dispatchError.toString());
}
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'LiquidityAdded') {
console.log(' ✓ Liquidity added to wHEZ/PEZ pool');
}
});
resolve();
}
})
.catch(reject);
});
// Pool 2: wHEZ/wUSDT (4:1)
console.log('\n📝 Pool 2: wHEZ/wUSDT');
console.log(' Ratio: 40,000 wHEZ : 10,000 wUSDT (4:1)');
const whezUsdt_whez = BigInt(40_000) * BigInt(10 ** 12);
const whezUsdt_usdt = BigInt(10_000) * BigInt(10 ** 6);
const pool2 = await api.query.assetConversion.pools([0, 2]);
if (pool2.isNone) {
await new Promise((resolve, reject) => {
api.tx.assetConversion
.createPool(0, 2)
.signAndSend(founder, ({ status, dispatchError }) => {
if (status.isInBlock) {
if (dispatchError) {
console.log(' Create error:', dispatchError.toString());
} else {
console.log(' ✓ Pool created');
}
resolve();
}
})
.catch(reject);
});
} else {
console.log(' ✓ Pool already exists');
}
console.log(' Adding liquidity...');
await new Promise((resolve, reject) => {
api.tx.assetConversion
.addLiquidity(
0, 2,
whezUsdt_whez.toString(),
whezUsdt_usdt.toString(),
whezUsdt_whez.toString(),
whezUsdt_usdt.toString(),
founder.address
)
.signAndSend(founder, ({ status, dispatchError, events }) => {
if (status.isInBlock) {
if (dispatchError) {
if (dispatchError.isModule) {
const decoded = api.registry.findMetaError(dispatchError.asModule);
console.log(' Error:', decoded.name, '-', decoded.docs.join(' '));
} else {
console.log(' Error:', dispatchError.toString());
}
reject(new Error(dispatchError.toString()));
return;
}
events.forEach(({ event }) => {
if (event.section === 'assetConversion' && event.method === 'LiquidityAdded') {
console.log(' ✓ Liquidity added to wHEZ/wUSDT pool');
}
});
resolve();
}
})
.catch(reject);
});
// Pool 3: PEZ/wUSDT (20:1) - already exists but add more liquidity
console.log('\n📝 Pool 3: PEZ/wUSDT');
console.log(' Pool already exists with liquidity');
console.log('\n✅ All 3 pools are ready!');
console.log('\nPool Summary:');
console.log(' 1. wHEZ/PEZ: 100k:500k (1 wHEZ = 5 PEZ)');
console.log(' 2. wHEZ/wUSDT: 40k:10k (4 wHEZ = 1 wUSDT)');
console.log(' 3. PEZ/wUSDT: 200k:10k (20 PEZ = 1 wUSDT)');
console.log('\nExchange rates: 1 wUSDT = 4 wHEZ = 20 PEZ ✓');
await api.disconnect();
}
main().catch(console.error);