From abc8d53e7701b7c2459c39561b91da19de4f279a Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Mon, 23 Oct 2023 13:39:29 +0200 Subject: [PATCH] Picasso integration with Moonbase Alpha --- packages/config/src/assets.ts | 12 ++++ packages/config/src/chains.ts | 38 +++++++++++++ packages/config/src/configs/index.ts | 2 + packages/config/src/configs/moonbaseAlpha.ts | 44 +++++++++++++++ .../config/src/configs/picassoAlphanet.ts | 56 +++++++++++++++++++ packages/sdk/src/polkadot/PolkadotService.ts | 21 ++++++- 6 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 packages/config/src/configs/picassoAlphanet.ts diff --git a/packages/config/src/assets.ts b/packages/config/src/assets.ts index cd0dd3bf..be9d0812 100644 --- a/packages/config/src/assets.ts +++ b/packages/config/src/assets.ts @@ -15,6 +15,11 @@ export const astr = new Asset({ originSymbol: 'ASTR', }); +export const atom = new Asset({ + key: 'atom', + originSymbol: 'ATOM', +}); + export const auq = new Asset({ key: 'auq', originSymbol: 'AUQ', @@ -170,6 +175,11 @@ export const pha = new Asset({ originSymbol: 'PHA', }); +export const pica = new Asset({ + key: 'pica', + originSymbol: 'PICA', +}); + export const ring = new Asset({ key: 'ring', originSymbol: 'RING', @@ -274,6 +284,7 @@ export const assetsList: Asset[] = [ aca, alan, astr, + atom, auq, aseed, bnc, @@ -304,6 +315,7 @@ export const assetsList: Asset[] = [ para, paring, pha, + pica, ring, rmrk, sdn, diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index d3d07dbf..84cffb84 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -9,6 +9,7 @@ import { alan, aseed, astr, + atom, auq, betaDEV, bnc, @@ -39,6 +40,7 @@ import { para, paring, pha, + pica, ring, rmrk, sdn, @@ -199,6 +201,7 @@ export const bifrostPolkadot = new Parachain({ { asset: vdot, id: { VToken2: 0 }, + metadataId: { VToken2: 0 }, }, { asset: vfil, @@ -672,6 +675,10 @@ export const moonbaseAlpha = new EvmParachain({ id: '0x9133c5a22024118804089f1fB752b7B2ce2a6351', metadataId: 0, // no metadata for ERC20 tokens }, + { + asset: atom, + id: '244316754493307480955066032215622931381', + }, { asset: auq, id: '69536036667157951501899290870203586130', @@ -702,6 +709,10 @@ export const moonbaseAlpha = new EvmParachain({ asset: paring, id: '173481220575862801646329923366065693029', }, + { + asset: pica, + id: '22417088946346045371238623691600461855', + }, { asset: soon, id: '205153165378836428058230526014907639736', @@ -1122,6 +1133,32 @@ export const phala = new Parachain({ ws: 'wss://api.phala.network/ws', }); +export const picassoAlphanet = new Parachain({ + assetsData: [ + { + asset: pica, + id: 1, + }, + { + asset: atom, + id: 7, + }, + { + asset: dev, + id: 10, + }, + ], + ecosystem: Ecosystem.AlphanetRelay, + genesisHash: + '0x3db2074093ab964732631d842b99d6612a6dc75a379738a660642b05ccad59c8', + isTestChain: true, + key: 'picasso-alphanet', + name: 'Picasso Alphanet', + parachainId: 2019, + ss58Format: 49, + ws: 'wss://boot-01.picasso2270.composablenodes.tech/', +}); + export const polkadot = new Parachain({ ecosystem: Ecosystem.Polkadot, genesisHash: @@ -1306,6 +1343,7 @@ export const chainsList: AnyChain[] = [ parallel, parallelHeiko, phala, + picassoAlphanet, polkadot, robonomics, shiden, diff --git a/packages/config/src/configs/index.ts b/packages/config/src/configs/index.ts index f34e8852..90853821 100644 --- a/packages/config/src/configs/index.ts +++ b/packages/config/src/configs/index.ts @@ -35,6 +35,7 @@ import { originTrailAlphanetConfig } from './originTrailAlphanet'; import { parallelConfig } from './parallel'; import { parallelHeikoConfig } from './parallelHeiko'; import { phalaConfig } from './phala'; +import { picassoAlphanetConfig } from './picassoAlphanet'; import { polkadotConfig } from './polkadot'; import { polkadotAssetHubConfig } from './polkadotAssetHub'; import { robonomicsConfig } from './robonomics'; @@ -78,6 +79,7 @@ export const chainsConfigList: ChainConfig[] = [ parallelConfig, parallelHeikoConfig, phalaConfig, + picassoAlphanetConfig, polkadotConfig, robonomicsConfig, shidenConfig, diff --git a/packages/config/src/configs/moonbaseAlpha.ts b/packages/config/src/configs/moonbaseAlpha.ts index 20c44e93..4483648e 100644 --- a/packages/config/src/configs/moonbaseAlpha.ts +++ b/packages/config/src/configs/moonbaseAlpha.ts @@ -1,12 +1,14 @@ import { BalanceBuilder, ContractBuilder } from '@moonbeam-network/xcm-builder'; import { alan, + atom, dev, eq, eqd, lit, otp, paring, + pica, soon, tt1, tur, @@ -21,6 +23,7 @@ import { moonbaseAlpha, moonbaseBeta, originTrailAlphanet, + picassoAlphanet, subsocialAlphanet, turingAlphanet, } from '../chains'; @@ -62,6 +65,17 @@ export const moonbaseAlphaConfig = new ChainConfig({ balance: BalanceBuilder().substrate().system().account(), }, }), + new AssetConfig({ + asset: dev, + balance: BalanceBuilder().substrate().system().account(), + contract: ContractBuilder().Xtokens().transfer(), + destination: picassoAlphanet, + destinationFee: { + amount: 0.00000001, + asset: dev, + balance: BalanceBuilder().substrate().system().account(), + }, + }), new AssetConfig({ asset: alan, balance: BalanceBuilder().evm().erc20(), @@ -167,6 +181,36 @@ export const moonbaseAlphaConfig = new ChainConfig({ balance: BalanceBuilder().substrate().system().account(), }, }), + new AssetConfig({ + asset: atom, + balance: BalanceBuilder().substrate().assets().account(), + contract: ContractBuilder().Xtokens().transfer(), + destination: picassoAlphanet, + destinationFee: { + amount: 0.0001, + asset: atom, + balance: BalanceBuilder().substrate().assets().account(), + }, + fee: { + asset: dev, + balance: BalanceBuilder().substrate().system().account(), + }, + }), + new AssetConfig({ + asset: pica, + balance: BalanceBuilder().substrate().assets().account(), + contract: ContractBuilder().Xtokens().transfer(), + destination: picassoAlphanet, + destinationFee: { + amount: 0.01, + asset: pica, + balance: BalanceBuilder().substrate().assets().account(), + }, + fee: { + asset: dev, + balance: BalanceBuilder().substrate().system().account(), + }, + }), new AssetConfig({ asset: soon, balance: BalanceBuilder().substrate().assets().account(), diff --git a/packages/config/src/configs/picassoAlphanet.ts b/packages/config/src/configs/picassoAlphanet.ts new file mode 100644 index 00000000..f22ce37a --- /dev/null +++ b/packages/config/src/configs/picassoAlphanet.ts @@ -0,0 +1,56 @@ +import { + BalanceBuilder, + ExtrinsicBuilder, + FeeBuilder, +} from '@moonbeam-network/xcm-builder'; +import { atom, dev, pica } from '../assets'; +import { moonbaseAlpha, picassoAlphanet } from '../chains'; +import { AssetConfig } from '../types/AssetConfig'; +import { ChainConfig } from '../types/ChainConfig'; + +export const picassoAlphanetConfig = new ChainConfig({ + assets: [ + new AssetConfig({ + asset: pica, + balance: BalanceBuilder().substrate().system().account(), + destination: moonbaseAlpha, + destinationFee: { + amount: FeeBuilder().assetManager().assetTypeUnitsPerSecond(), + asset: pica, + balance: BalanceBuilder().substrate().system().account(), + }, + extrinsic: ExtrinsicBuilder().xTokens().transfer(), + }), + new AssetConfig({ + asset: atom, + balance: BalanceBuilder().substrate().tokens().accounts(), + destination: moonbaseAlpha, + destinationFee: { + amount: FeeBuilder().assetManager().assetTypeUnitsPerSecond(), + asset: pica, + balance: BalanceBuilder().substrate().system().account(), + }, + extrinsic: ExtrinsicBuilder().xTokens().transferMultiCurrencies(), + fee: { + asset: pica, + balance: BalanceBuilder().substrate().system().account(), + }, + }), + new AssetConfig({ + asset: dev, + balance: BalanceBuilder().substrate().tokens().accounts(), + destination: moonbaseAlpha, + destinationFee: { + amount: 0.0001, + asset: dev, + balance: BalanceBuilder().substrate().tokens().accounts(), + }, + extrinsic: ExtrinsicBuilder().xTokens().transfer(), + fee: { + asset: pica, + balance: BalanceBuilder().substrate().system().account(), + }, + }), + ], + chain: picassoAlphanet, +}); diff --git a/packages/sdk/src/polkadot/PolkadotService.ts b/packages/sdk/src/polkadot/PolkadotService.ts index 1d2b7643..f61fef9b 100644 --- a/packages/sdk/src/polkadot/PolkadotService.ts +++ b/packages/sdk/src/polkadot/PolkadotService.ts @@ -21,7 +21,7 @@ import { import { getPolkadotApi } from '@moonbeam-network/xcm-utils'; import { ApiPromise } from '@polkadot/api'; import type { Signer as PolkadotSigner } from '@polkadot/api/types'; -import { Option, u128 } from '@polkadot/types'; +import { Option, u128, u8 } from '@polkadot/types'; import { IKeyringPair } from '@polkadot/types/types'; import { AssetMetadata } from './PolkadotService.interfaces'; @@ -135,10 +135,25 @@ export class PolkadotService { }; } + async getAssetDecimalsFromQuery( + asset: ChainAssetId, + ): Promise { + const fn = this.api.query.assetsRegistry?.assetDecimals; + + if (!fn) { + return undefined; + } + + const data = (await fn(asset)) as Option; + + return data.unwrapOrDefault().toNumber(); + } + async getAssetDecimals(asset: Asset): Promise { + const metaId = this.chain.getMetadataAssetId(asset); return ( - (await this.getAssetMeta(this.chain.getMetadataAssetId(asset))) - ?.decimals || + (await this.getAssetDecimalsFromQuery(metaId)) || + (await this.getAssetMeta(metaId))?.decimals || this.chain.getAssetDecimals(asset) || this.decimals );