Skip to content

Commit

Permalink
Picasso integration with Moonbase Alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Oct 23, 2023
1 parent 794f904 commit abc8d53
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 3 deletions.
12 changes: 12 additions & 0 deletions packages/config/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -274,6 +284,7 @@ export const assetsList: Asset[] = [
aca,
alan,
astr,
atom,
auq,
aseed,
bnc,
Expand Down Expand Up @@ -304,6 +315,7 @@ export const assetsList: Asset[] = [
para,
paring,
pha,
pica,
ring,
rmrk,
sdn,
Expand Down
38 changes: 38 additions & 0 deletions packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
alan,
aseed,
astr,
atom,
auq,
betaDEV,
bnc,
Expand Down Expand Up @@ -39,6 +40,7 @@ import {
para,
paring,
pha,
pica,
ring,
rmrk,
sdn,
Expand Down Expand Up @@ -199,6 +201,7 @@ export const bifrostPolkadot = new Parachain({
{
asset: vdot,
id: { VToken2: 0 },
metadataId: { VToken2: 0 },
},
{
asset: vfil,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -702,6 +709,10 @@ export const moonbaseAlpha = new EvmParachain({
asset: paring,
id: '173481220575862801646329923366065693029',
},
{
asset: pica,
id: '22417088946346045371238623691600461855',
},
{
asset: soon,
id: '205153165378836428058230526014907639736',
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -1306,6 +1343,7 @@ export const chainsList: AnyChain[] = [
parallel,
parallelHeiko,
phala,
picassoAlphanet,
polkadot,
robonomics,
shiden,
Expand Down
2 changes: 2 additions & 0 deletions packages/config/src/configs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -78,6 +79,7 @@ export const chainsConfigList: ChainConfig[] = [
parallelConfig,
parallelHeikoConfig,
phalaConfig,
picassoAlphanetConfig,
polkadotConfig,
robonomicsConfig,
shidenConfig,
Expand Down
44 changes: 44 additions & 0 deletions packages/config/src/configs/moonbaseAlpha.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -21,6 +23,7 @@ import {
moonbaseAlpha,
moonbaseBeta,
originTrailAlphanet,
picassoAlphanet,
subsocialAlphanet,
turingAlphanet,
} from '../chains';
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
56 changes: 56 additions & 0 deletions packages/config/src/configs/picassoAlphanet.ts
Original file line number Diff line number Diff line change
@@ -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,
});
21 changes: 18 additions & 3 deletions packages/sdk/src/polkadot/PolkadotService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -135,10 +135,25 @@ export class PolkadotService {
};
}

async getAssetDecimalsFromQuery(
asset: ChainAssetId,
): Promise<number | undefined> {
const fn = this.api.query.assetsRegistry?.assetDecimals;

if (!fn) {
return undefined;
}

const data = (await fn(asset)) as Option<u8>;

return data.unwrapOrDefault().toNumber();
}

async getAssetDecimals(asset: Asset): Promise<number> {
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
);
Expand Down

0 comments on commit abc8d53

Please sign in to comment.