difftreelog
fix set correct shiden/astar values for our chain
in: master
5 files changed
tests/src/util/playgrounds/unique.xcm.tsdiffbeforeafterboth1import {ApiPromise, WsProvider} from '@polkadot/api';2import {IKeyringPair} from '@polkadot/types/types';3import {ChainHelperBase, EthereumBalanceGroup, HelperGroup, SubstrateBalanceGroup, UniqueHelper} from './unique';4import {ILogger, TSigner, TSubstrateAccount} from './types';5import {AcalaAssetMetadata, DemocracyStandardAccountVote, IForeignAssetMetadata, MoonbeamAssetInfo} from './types.xcm';678export class XcmChainHelper extends ChainHelperBase {9 async connect(wsEndpoint: string, _listeners?: any): Promise<void> {10 const wsProvider = new WsProvider(wsEndpoint);11 this.api = new ApiPromise({12 provider: wsProvider,13 });14 await this.api.isReadyOrError;15 this.network = await UniqueHelper.detectNetwork(this.api);16 }17}1819class AcalaAssetRegistryGroup extends HelperGroup<AcalaHelper> {20 async registerForeignAsset(signer: TSigner, destination: any, metadata: AcalaAssetMetadata) {21 await this.helper.executeExtrinsic(signer, 'api.tx.assetRegistry.registerForeignAsset', [destination, metadata], true);22 }23}2425class MoonbeamAssetManagerGroup extends HelperGroup<MoonbeamHelper> {26 makeRegisterForeignAssetProposal(assetInfo: MoonbeamAssetInfo) {27 const apiPrefix = 'api.tx.assetManager.';2829 const registerTx = this.helper.constructApiCall(30 apiPrefix + 'registerForeignAsset',31 [assetInfo.location, assetInfo.metadata, assetInfo.existentialDeposit, assetInfo.isSufficient],32 );3334 const setUnitsTx = this.helper.constructApiCall(35 apiPrefix + 'setAssetUnitsPerSecond',36 [assetInfo.location, assetInfo.unitsPerSecond, assetInfo.numAssetsWeightHint],37 );3839 const batchCall = this.helper.getApi().tx.utility.batchAll([registerTx, setUnitsTx]);40 const encodedProposal = batchCall?.method.toHex() || '';41 return encodedProposal;42 }4344 async assetTypeId(location: any) {45 return await this.helper.callRpc('api.query.assetManager.assetTypeId', [location]);46 }47}4849class MoonbeamDemocracyGroup extends HelperGroup<MoonbeamHelper> {50 notePreimagePallet: string;5152 constructor(helper: MoonbeamHelper, options: { [key: string]: any } = {}) {53 super(helper);54 this.notePreimagePallet = options.notePreimagePallet;55 }5657 async notePreimage(signer: TSigner, encodedProposal: string) {58 await this.helper.executeExtrinsic(signer, `api.tx.${this.notePreimagePallet}.notePreimage`, [encodedProposal], true);59 }6061 externalProposeMajority(proposal: any) {62 return this.helper.constructApiCall('api.tx.democracy.externalProposeMajority', [proposal]);63 }6465 fastTrack(proposalHash: string, votingPeriod: number, delayPeriod: number) {66 return this.helper.constructApiCall('api.tx.democracy.fastTrack', [proposalHash, votingPeriod, delayPeriod]);67 }6869 async referendumVote(signer: TSigner, referendumIndex: number, accountVote: DemocracyStandardAccountVote) {70 await this.helper.executeExtrinsic(signer, 'api.tx.democracy.vote', [referendumIndex, {Standard: accountVote}], true);71 }72}7374class MoonbeamCollectiveGroup extends HelperGroup<MoonbeamHelper> {75 collective: string;7677 constructor(helper: MoonbeamHelper, collective: string) {78 super(helper);7980 this.collective = collective;81 }8283 async propose(signer: TSigner, threshold: number, proposalHash: string, lengthBound: number) {84 await this.helper.executeExtrinsic(signer, `api.tx.${this.collective}.propose`, [threshold, proposalHash, lengthBound], true);85 }8687 async vote(signer: TSigner, proposalHash: string, proposalIndex: number, approve: boolean) {88 await this.helper.executeExtrinsic(signer, `api.tx.${this.collective}.vote`, [proposalHash, proposalIndex, approve], true);89 }9091 async close(signer: TSigner, proposalHash: string, proposalIndex: number, weightBound: any, lengthBound: number) {92 await this.helper.executeExtrinsic(signer, `api.tx.${this.collective}.close`, [proposalHash, proposalIndex, weightBound, lengthBound], true);93 }9495 async proposalCount() {96 return Number(await this.helper.callRpc(`api.query.${this.collective}.proposalCount`, []));97 }98}99100class PolkadexXcmHelperGroup<T extends ChainHelperBase> extends HelperGroup<T> {101 async whitelistToken(signer: TSigner, assetId: any) {102 await this.helper.executeExtrinsic(signer, 'api.tx.xcmHelper.whitelistToken', [assetId], true);103 }104}105106export class ForeignAssetsGroup extends HelperGroup<UniqueHelper> {107 async register(signer: TSigner, ownerAddress: TSubstrateAccount, location: any, metadata: IForeignAssetMetadata) {108 await this.helper.executeExtrinsic(109 signer,110 'api.tx.foreignAssets.registerForeignAsset',111 [ownerAddress, location, metadata],112 true,113 );114 }115116 async update(signer: TSigner, foreignAssetId: number, location: any, metadata: IForeignAssetMetadata) {117 await this.helper.executeExtrinsic(118 signer,119 'api.tx.foreignAssets.updateForeignAsset',120 [foreignAssetId, location, metadata],121 true,122 );123 }124}125126export class XcmGroup<T extends ChainHelperBase> extends HelperGroup<T> {127 palletName: string;128129 constructor(helper: T, palletName: string) {130 super(helper);131132 this.palletName = palletName;133 }134135 async limitedReserveTransferAssets(signer: TSigner, destination: any, beneficiary: any, assets: any, feeAssetItem: number, weightLimit: any) {136 await this.helper.executeExtrinsic(signer, `api.tx.${this.palletName}.limitedReserveTransferAssets`, [destination, beneficiary, assets, feeAssetItem, weightLimit], true);137 }138139 async setSafeXcmVersion(signer: TSigner, version: number) {140 await this.helper.executeExtrinsic(signer, `api.tx.${this.palletName}.forceDefaultXcmVersion`, [version], true);141 }142143 async teleportAssets(signer: TSigner, destination: any, beneficiary: any, assets: any, feeAssetItem: number) {144 await this.helper.executeExtrinsic(signer, `api.tx.${this.palletName}.teleportAssets`, [destination, beneficiary, assets, feeAssetItem], true);145 }146147 async teleportNativeAsset(signer: TSigner, destinationParaId: number, targetAccount: Uint8Array, amount: bigint, xcmVersion = 3) {148 const destinationContent = {149 parents: 0,150 interior: {151 X1: {152 Parachain: destinationParaId,153 },154 },155 };156157 const beneficiaryContent = {158 parents: 0,159 interior: {160 X1: {161 AccountId32: {162 network: 'Any',163 id: targetAccount,164 },165 },166 },167 };168169 const assetsContent = [170 {171 id: {172 Concrete: {173 parents: 0,174 interior: 'Here',175 },176 },177 fun: {178 Fungible: amount,179 },180 },181 ];182183 let destination;184 let beneficiary;185 let assets;186187 if(xcmVersion == 2) {188 destination = {V1: destinationContent};189 beneficiary = {V1: beneficiaryContent};190 assets = {V1: assetsContent};191192 } else if(xcmVersion == 3) {193 destination = {V2: destinationContent};194 beneficiary = {V2: beneficiaryContent};195 assets = {V2: assetsContent};196197 } else {198 throw Error('Unknown XCM version: ' + xcmVersion);199 }200201 const feeAssetItem = 0;202203 await this.teleportAssets(signer, destination, beneficiary, assets, feeAssetItem);204 }205206 async send(signer: IKeyringPair, destination: any, message: any) {207 await this.helper.executeExtrinsic(208 signer,209 `api.tx.${this.palletName}.send`,210 [211 destination,212 message,213 ],214 true,215 );216 }217}218219export class XTokensGroup<T extends ChainHelperBase> extends HelperGroup<T> {220 async transfer(signer: TSigner, currencyId: any, amount: bigint, destination: any, destWeight: any) {221 await this.helper.executeExtrinsic(signer, 'api.tx.xTokens.transfer', [currencyId, amount, destination, destWeight], true);222 }223224 async transferMultiasset(signer: TSigner, asset: any, destination: any, destWeight: any) {225 await this.helper.executeExtrinsic(signer, 'api.tx.xTokens.transferMultiasset', [asset, destination, destWeight], true);226 }227228 async transferMulticurrencies(signer: TSigner, currencies: any[], feeItem: number, destLocation: any, destWeight: any) {229 await this.helper.executeExtrinsic(signer, 'api.tx.xTokens.transferMulticurrencies', [currencies, feeItem, destLocation, destWeight], true);230 }231}232233234235export class TokensGroup<T extends ChainHelperBase> extends HelperGroup<T> {236 async accounts(address: string, currencyId: any) {237 const {free} = (await this.helper.callRpc('api.query.tokens.accounts', [address, currencyId])).toJSON() as any;238 return BigInt(free);239 }240}241242export class AssetsGroup<T extends ChainHelperBase> extends HelperGroup<T> {243 async create(signer: TSigner, assetId: number | bigint, admin: string, minimalBalance: bigint) {244 await this.helper.executeExtrinsic(signer, 'api.tx.assets.create', [assetId, admin, minimalBalance], true);245 }246247 async setMetadata(signer: TSigner, assetId: number | bigint, name: string, symbol: string, decimals: number) {248 await this.helper.executeExtrinsic(signer, 'api.tx.assets.setMetadata', [assetId, name, symbol, decimals], true);249 }250251 async mint(signer: TSigner, assetId: number | bigint, beneficiary: string, amount: bigint) {252 await this.helper.executeExtrinsic(signer, 'api.tx.assets.mint', [assetId, beneficiary, amount], true);253 }254255 async account(assetId: string | number | bigint, address: string) {256 const accountAsset = (257 await this.helper.callRpc('api.query.assets.account', [assetId, address])258 ).toJSON()! as any;259260 if(accountAsset !== null) {261 return BigInt(accountAsset['balance']);262 } else {263 return null;264 }265 }266}267268export class RelayHelper extends XcmChainHelper {269 balance: SubstrateBalanceGroup<RelayHelper>;270 xcm: XcmGroup<RelayHelper>;271272 constructor(logger?: ILogger, options: { [key: string]: any } = {}) {273 super(logger, options.helperBase ?? RelayHelper);274275 this.balance = new SubstrateBalanceGroup(this);276 this.xcm = new XcmGroup(this, 'xcmPallet');277 }278}279280export class WestmintHelper extends XcmChainHelper {281 balance: SubstrateBalanceGroup<WestmintHelper>;282 xcm: XcmGroup<WestmintHelper>;283 assets: AssetsGroup<WestmintHelper>;284 xTokens: XTokensGroup<WestmintHelper>;285286 constructor(logger?: ILogger, options: { [key: string]: any } = {}) {287 super(logger, options.helperBase ?? WestmintHelper);288289 this.balance = new SubstrateBalanceGroup(this);290 this.xcm = new XcmGroup(this, 'polkadotXcm');291 this.assets = new AssetsGroup(this);292 this.xTokens = new XTokensGroup(this);293 }294}295296export class MoonbeamHelper extends XcmChainHelper {297 balance: EthereumBalanceGroup<MoonbeamHelper>;298 assetManager: MoonbeamAssetManagerGroup;299 assets: AssetsGroup<MoonbeamHelper>;300 xTokens: XTokensGroup<MoonbeamHelper>;301 democracy: MoonbeamDemocracyGroup;302 collective: {303 council: MoonbeamCollectiveGroup,304 techCommittee: MoonbeamCollectiveGroup,305 };306307 constructor(logger?: ILogger, options: { [key: string]: any } = {}) {308 super(logger, options.helperBase ?? MoonbeamHelper);309310 this.balance = new EthereumBalanceGroup(this);311 this.assetManager = new MoonbeamAssetManagerGroup(this);312 this.assets = new AssetsGroup(this);313 this.xTokens = new XTokensGroup(this);314 this.democracy = new MoonbeamDemocracyGroup(this, options);315 this.collective = {316 council: new MoonbeamCollectiveGroup(this, 'councilCollective'),317 techCommittee: new MoonbeamCollectiveGroup(this, 'techCommitteeCollective'),318 };319 }320}321322export class AstarHelper extends XcmChainHelper {323 balance: SubstrateBalanceGroup<AstarHelper>;324 assets: AssetsGroup<AstarHelper>;325 xcm: XcmGroup<AstarHelper>;326327 constructor(logger?: ILogger, options: { [key: string]: any } = {}) {328 super(logger, options.helperBase ?? AstarHelper);329330 this.balance = new SubstrateBalanceGroup(this);331 this.assets = new AssetsGroup(this);332 this.xcm = new XcmGroup(this, 'polkadotXcm');333 }334}335336export class AcalaHelper extends XcmChainHelper {337 balance: SubstrateBalanceGroup<AcalaHelper>;338 assetRegistry: AcalaAssetRegistryGroup;339 xTokens: XTokensGroup<AcalaHelper>;340 tokens: TokensGroup<AcalaHelper>;341 xcm: XcmGroup<AcalaHelper>;342343 constructor(logger?: ILogger, options: { [key: string]: any } = {}) {344 super(logger, options.helperBase ?? AcalaHelper);345346 this.balance = new SubstrateBalanceGroup(this);347 this.assetRegistry = new AcalaAssetRegistryGroup(this);348 this.xTokens = new XTokensGroup(this);349 this.tokens = new TokensGroup(this);350 this.xcm = new XcmGroup(this, 'polkadotXcm');351 }352}353354export class PolkadexHelper extends XcmChainHelper {355 assets: AssetsGroup<PolkadexHelper>;356 balance: SubstrateBalanceGroup<PolkadexHelper>;357 xTokens: XTokensGroup<PolkadexHelper>;358 xcm: XcmGroup<PolkadexHelper>;359 xcmHelper: PolkadexXcmHelperGroup<PolkadexHelper>;360361 constructor(logger?: ILogger, options: { [key: string]: any } = {}) {362 super(logger, options.helperBase ?? PolkadexHelper);363364 this.assets = new AssetsGroup(this);365 this.balance = new SubstrateBalanceGroup(this);366 this.xTokens = new XTokensGroup(this);367 this.xcm = new XcmGroup(this, 'polkadotXcm');368 this.xcmHelper = new PolkadexXcmHelperGroup(this);369 }370}371tests/src/xcm/lowLevelXcmQuartz.test.tsdiffbeforeafterboth--- a/tests/src/xcm/lowLevelXcmQuartz.test.ts
+++ b/tests/src/xcm/lowLevelXcmQuartz.test.ts
@@ -222,14 +222,12 @@
let alice: IKeyringPair;
let randomAccount: IKeyringPair;
- const QTZ_ASSET_ID_ON_SHIDEN = 1;
- const QTZ_MINIMAL_BALANCE_ON_SHIDEN = 1n;
+ const QTZ_ASSET_ID_ON_SHIDEN = 18_446_744_073_709_551_633n; // The value is taken from the live Shiden
+ const QTZ_MINIMAL_BALANCE_ON_SHIDEN = 1n; // The value is taken from the live Shiden
// Quartz -> Shiden
const shidenInitialBalance = 1n * (10n ** SHIDEN_DECIMALS); // 1 SHD, existential deposit required to actually create the account on Shiden
- const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?
-
-
+ const unitsPerSecond = 500_451_000_000_000_000_000n; // The value is taken from the live Shiden
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
@@ -245,7 +243,6 @@
await usingShidenPlaygrounds(shidenUrl, async (helper) => {
if(!(await helper.callRpc('api.query.assets.asset', [QTZ_ASSET_ID_ON_SHIDEN])).toJSON()) {
console.log('1. Create foreign asset and metadata');
- // TODO update metadata with values from production
await helper.assets.create(
alice,
QTZ_ASSET_ID_ON_SHIDEN,
@@ -256,8 +253,8 @@
await helper.assets.setMetadata(
alice,
QTZ_ASSET_ID_ON_SHIDEN,
- 'Cross chain QTZ',
- 'xcQTZ',
+ 'Quartz',
+ 'QTZ',
Number(QTZ_DECIMALS),
);
tests/src/xcm/lowLevelXcmUnique.test.tsdiffbeforeafterboth--- a/tests/src/xcm/lowLevelXcmUnique.test.ts
+++ b/tests/src/xcm/lowLevelXcmUnique.test.ts
@@ -288,12 +288,12 @@
let alice: IKeyringPair;
let randomAccount: IKeyringPair;
- const UNQ_ASSET_ID_ON_ASTAR = 1;
- const UNQ_MINIMAL_BALANCE_ON_ASTAR = 1n;
+ const UNQ_ASSET_ID_ON_ASTAR = 18_446_744_073_709_551_631n; // The value is taken from the live Astar
+ const UNQ_MINIMAL_BALANCE_ON_ASTAR = 1n; // The value is taken from the live Astar
// Unique -> Astar
const astarInitialBalance = 1n * (10n ** ASTAR_DECIMALS); // 1 ASTR, existential deposit required to actually create the account on Astar.
- const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?
+ const unitsPerSecond = 9_451_000_000_000_000_000n; // The value is taken from the live Astar
before(async () => {
await usingPlaygrounds(async (helper, privateKey) => {
@@ -309,7 +309,6 @@
await usingAstarPlaygrounds(astarUrl, async (helper) => {
if(!(await helper.callRpc('api.query.assets.asset', [UNQ_ASSET_ID_ON_ASTAR])).toJSON()) {
console.log('1. Create foreign asset and metadata');
- // TODO update metadata with values from production
await helper.assets.create(
alice,
UNQ_ASSET_ID_ON_ASTAR,
@@ -320,8 +319,8 @@
await helper.assets.setMetadata(
alice,
UNQ_ASSET_ID_ON_ASTAR,
- 'Cross chain UNQ',
- 'xcUNQ',
+ 'Unique Network',
+ 'UNQ',
Number(UNQ_DECIMALS),
);
tests/src/xcm/xcmQuartz.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmQuartz.test.ts
+++ b/tests/src/xcm/xcmQuartz.test.ts
@@ -1283,12 +1283,12 @@
let alice: IKeyringPair;
let sender: IKeyringPair;
- const QTZ_ASSET_ID_ON_SHIDEN = 1;
- const QTZ_MINIMAL_BALANCE_ON_SHIDEN = 1n;
+ const QTZ_ASSET_ID_ON_SHIDEN = 18_446_744_073_709_551_633n; // The value is taken from the live Shiden
+ const QTZ_MINIMAL_BALANCE_ON_SHIDEN = 1n; // The value is taken from the live Shiden
// Quartz -> Shiden
const shidenInitialBalance = 1n * (10n ** SHIDEN_DECIMALS); // 1 SHD, existential deposit required to actually create the account on Shiden
- const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?
+ const unitsPerSecond = 500_451_000_000_000_000_000n; // The value is taken from the live Shiden
const qtzToShidenTransferred = 10n * (10n ** QTZ_DECIMALS); // 10 QTZ
const qtzToShidenArrived = 9_999_999_999_088_000_000n; // 9.999 ... QTZ, Shiden takes a commision in foreign tokens
@@ -1311,7 +1311,6 @@
await usingShidenPlaygrounds(shidenUrl, async (helper) => {
if(!(await helper.callRpc('api.query.assets.asset', [QTZ_ASSET_ID_ON_SHIDEN])).toJSON()) {
console.log('1. Create foreign asset and metadata');
- // TODO update metadata with values from production
await helper.assets.create(
alice,
QTZ_ASSET_ID_ON_SHIDEN,
@@ -1322,8 +1321,8 @@
await helper.assets.setMetadata(
alice,
QTZ_ASSET_ID_ON_SHIDEN,
- 'Cross chain QTZ',
- 'xcQTZ',
+ 'Quartz',
+ 'QTZ',
Number(QTZ_DECIMALS),
);
tests/src/xcm/xcmUnique.test.tsdiffbeforeafterboth--- a/tests/src/xcm/xcmUnique.test.ts
+++ b/tests/src/xcm/xcmUnique.test.ts
@@ -1511,12 +1511,12 @@
let alice: IKeyringPair;
let randomAccount: IKeyringPair;
- const UNQ_ASSET_ID_ON_ASTAR = 1;
- const UNQ_MINIMAL_BALANCE_ON_ASTAR = 1n;
+ const UNQ_ASSET_ID_ON_ASTAR = 18_446_744_073_709_551_631n; // The value is taken from the live Astar
+ const UNQ_MINIMAL_BALANCE_ON_ASTAR = 1n; // The value is taken from the live Astar
// Unique -> Astar
const astarInitialBalance = 1n * (10n ** ASTAR_DECIMALS); // 1 ASTR, existential deposit required to actually create the account on Astar.
- const unitsPerSecond = 228_000_000_000n; // This is Phala's value. What will be ours?
+ const unitsPerSecond = 9_451_000_000_000_000_000n; // The value is taken from the live Astar
const unqToAstarTransferred = 10n * (10n ** UNQ_DECIMALS); // 10 UNQ
const unqToAstarArrived = 9_999_999_999_088_000_000n; // 9.999 ... UNQ, Astar takes a commision in foreign tokens
@@ -1539,7 +1539,6 @@
await usingAstarPlaygrounds(astarUrl, async (helper) => {
if(!(await helper.callRpc('api.query.assets.asset', [UNQ_ASSET_ID_ON_ASTAR])).toJSON()) {
console.log('1. Create foreign asset and metadata');
- // TODO update metadata with values from production
await helper.assets.create(
alice,
UNQ_ASSET_ID_ON_ASTAR,
@@ -1550,8 +1549,8 @@
await helper.assets.setMetadata(
alice,
UNQ_ASSET_ID_ON_ASTAR,
- 'Cross chain UNQ',
- 'xcUNQ',
+ 'Unique Network',
+ 'UNQ',
Number(UNQ_DECIMALS),
);