Skip to content

Commit

Permalink
-wip- USDC Polkadot Asset Hub - Moonbeam integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Sep 27, 2023
1 parent e462bce commit 9f39b00
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 28 deletions.
11 changes: 9 additions & 2 deletions packages/config/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,13 @@ export const unit = new Asset({
originSymbol: 'Unit',
});

export const usdc = new Asset({
// TODO mjm rename?
export const usdcAH = new Asset({
key: 'usdc',
originSymbol: 'USDC',
});

export const usdcwh = new Asset({
key: 'usdcwh',
originSymbol: 'USDC.Wh',
});
Expand Down Expand Up @@ -306,7 +312,8 @@ export const assetsList: Asset[] = [
tt1,
tur,
unit,
usdc,
usdcAH,
usdcwh,
usdt,
vbnc,
vdot,
Expand Down
29 changes: 20 additions & 9 deletions packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ import {
tt1,
tur,
unit,
usdc,
usdcAH,
usdcwh,
usdt,
vbnc,
vdot,
Expand Down Expand Up @@ -425,7 +426,7 @@ export const hydraDX = new Parachain({
id: 18,
},
{
asset: usdc,
asset: usdcwh,
id: 21,
},
{
Expand Down Expand Up @@ -830,7 +831,12 @@ export const moonbeam = new EvmParachain({
id: '125699734534028342599692732320197985871',
},
{
asset: usdc,
asset: usdcAH,
id: '0xFFfffffF7D2B0B761Af01Ca8e25242976ac0aD7D',
metadataId: '166377000701797186346254371275954761085', // registered XC20 id for ERC20 tokens
},
{
asset: usdcwh,
id: '0x931715FEE2d06333043d11F658C8CE934aC61D0c',
metadataId: 0, // no metadata for ERC20 tokens
},
Expand All @@ -841,17 +847,17 @@ export const moonbeam = new EvmParachain({
{
asset: vdot,
id: '0xFFFfffFf15e1b7E3dF971DD813Bc394deB899aBf',
metadataId: 0, // no metadata for ERC20 tokens
metadataId: '29085784439601774464560083082574142143', // registered XC20 id for ERC20 tokens
},
{
asset: vfil,
id: '0xFffffFffCd0aD0EA6576B7b285295c85E94cf4c1',
metadataId: 0, // no metadata for ERC20 tokens
metadataId: '272547899416482196831721420898811311297', // registered XC20 id for ERC20 tokens
},
{
asset: vglmr,
id: '0xFfFfFFff99dABE1a8De0EA22bAa6FD48fdE96F6c',
metadataId: 0, // no metadata for ERC20 tokens
metadataId: '204507659831918931608354793288110796652', // registered XC20 id for ERC20 tokens
},
{
asset: wbtc,
Expand Down Expand Up @@ -962,17 +968,17 @@ export const moonriver = new EvmParachain({
{
asset: vbnc,
id: '0xFFffffff3646A00f78caDf8883c5A2791BfCDdc4',
metadataId: 0,
metadataId: '72145018963825376852137222787619937732',
},
{
asset: vksm,
id: '0xFFffffFFC6DEec7Fc8B11A2C8ddE9a59F8c62EFe',
metadataId: 0,
metadataId: '264344629840762281112027368930249420542',
},
{
asset: vmovr,
id: '0xfFfffFfF98e37bF6a393504b5aDC5B53B4D0ba11',
metadataId: 0,
metadataId: '203223821023327994093278529517083736593',
},
],
ecosystem: Ecosystem.Kusama,
Expand Down Expand Up @@ -1131,6 +1137,11 @@ export const polkadotAssetHub = new Parachain({
// NOTE: no meta for native token
metadataId: 9999999,
},
{
asset: usdcAH,
id: 1337,
palletInstance: 50,
},
],
ecosystem: Ecosystem.Polkadot,
genesisHash:
Expand Down
4 changes: 2 additions & 2 deletions packages/config/src/configs/hydraDX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ExtrinsicBuilder,
FeeBuilder,
} from '@moonbeam-network/xcm-builder';
import { dai, glmr, hdx, usdc, wbtc, weth } from '../assets';
import { dai, glmr, hdx, usdcwh, wbtc, weth } from '../assets';
import { hydraDX, moonbeam } from '../chains';
import { AssetConfig } from '../types/AssetConfig';
import { ChainConfig } from '../types/ChainConfig';
Expand Down Expand Up @@ -48,7 +48,7 @@ export const hydraDxConfig = new ChainConfig({
},
}),
new AssetConfig({
asset: usdc,
asset: usdcwh,
balance: BalanceBuilder().substrate().tokens().accounts(),
destination: moonbeam,
destinationFee: {
Expand Down
22 changes: 19 additions & 3 deletions packages/config/src/configs/moonbeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
para,
pha,
ring,
usdc,
usdcAH,
usdcwh,
usdt,
vdot,
vfil,
Expand Down Expand Up @@ -348,6 +349,21 @@ export const moonbeamConfig = new ChainConfig({
balance: BalanceBuilder().substrate().system().account(),
},
}),
new AssetConfig({
asset: usdcAH,
balance: BalanceBuilder().evm().erc20(),
contract: ContractBuilder().Xtokens().transferMultiCurrencies(),
destination: polkadotAssetHub,
destinationFee: {
amount: 0.7, // TODO
asset: dot,
balance: BalanceBuilder().substrate().assets().account(),
},
fee: {
asset: glmr,
balance: BalanceBuilder().substrate().system().account(),
},
}),
new AssetConfig({
asset: hdx,
balance: BalanceBuilder().substrate().assets().account(),
Expand Down Expand Up @@ -379,13 +395,13 @@ export const moonbeamConfig = new ChainConfig({
},
}),
new AssetConfig({
asset: usdc,
asset: usdcwh,
balance: BalanceBuilder().evm().erc20(),
contract: ContractBuilder().Xtokens().transfer(),
destination: hydraDX,
destinationFee: {
amount: 0.004,
asset: usdc,
asset: usdcwh,
balance: BalanceBuilder().evm().erc20(),
},
fee: {
Expand Down
21 changes: 20 additions & 1 deletion packages/config/src/configs/polkadotAssetHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
ExtrinsicBuilder,
FeeBuilder,
} from '@moonbeam-network/xcm-builder';
import { dot, usdt } from '../assets';
import { dot, usdcAH, usdt } from '../assets';
import { moonbeam, polkadotAssetHub } from '../chains';
import { AssetConfig } from '../types/AssetConfig';
import { ChainConfig } from '../types/ChainConfig';
Expand All @@ -30,6 +30,25 @@ export const polkadotAssetHubConfig = new ChainConfig({
},
min: AssetMinBuilder().assets().asset(),
}),
new AssetConfig({
asset: usdcAH,
balance: BalanceBuilder().substrate().assets().account(),
destination: moonbeam,
destinationFee: {
amount: 0.02,
asset: usdcAH,
balance: BalanceBuilder().substrate().assets().account(),
},
extrinsic: ExtrinsicBuilder()
.polkadotXcm()
.limitedReserveTransferAssets()
.X2(),
fee: {
asset: dot,
balance: BalanceBuilder().substrate().system().account(),
},
min: AssetMinBuilder().assets().asset(),
}),
],
chain: polkadotAssetHub,
});
6 changes: 2 additions & 4 deletions packages/sdk/src/getTransferData/getSourceData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export async function getSourceData({
amount: 0n,
decimals: await getDecimals({
address: destinationAddress,
asset: config.fee.asset,
config,
config: config.fee,
evmSigner,
polkadot,
}),
Expand All @@ -61,8 +60,7 @@ export async function getSourceData({
amount: 0n,
decimals: await getDecimals({
address: destinationAddress,
asset: config.destinationFee.asset,
config,
config: config.destinationFee,
evmSigner,
polkadot,
}),
Expand Down
11 changes: 4 additions & 7 deletions packages/sdk/src/getTransferData/getTransferData.utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { CallType, SubstrateQueryConfig } from '@moonbeam-network/xcm-builder';
import { AssetConfig } from '@moonbeam-network/xcm-config';
import { Asset } from '@moonbeam-network/xcm-types';
import { AssetConfig, FeeAssetConfig } from '@moonbeam-network/xcm-config';
import { toBigInt } from '@moonbeam-network/xcm-utils';
import { BalanceContractInterface, createContract } from '../contract';
import { PolkadotService } from '../polkadot';
import { EvmSigner } from '../sdk.interfaces';

export interface GetFeeBalancesParams {
address: string;
config: AssetConfig;
config: AssetConfig | FeeAssetConfig;
evmSigner: EvmSigner;
polkadot: PolkadotService;
asset?: Asset;
}

export async function getBalance({
Expand All @@ -36,18 +34,17 @@ export async function getBalance({

export async function getDecimals({
address,
asset,
config,
evmSigner,
polkadot,
}: GetFeeBalancesParams) {
const cfg = config.balance.build({
address,
asset: polkadot.chain.getBalanceAssetId(asset || config.asset),
asset: polkadot.chain.getBalanceAssetId(config.asset),
});

if (cfg.type === CallType.Substrate) {
return polkadot.getAssetDecimals(asset || config.asset);
return polkadot.getAssetDecimals(config.asset);
}

const contract = createContract(cfg, evmSigner) as BalanceContractInterface;
Expand Down

0 comments on commit 9f39b00

Please sign in to comment.