From c7de67fd347aca17968f03f54220da3672e77160 Mon Sep 17 00:00:00 2001 From: Mario J Maurello Date: Mon, 8 Apr 2024 21:42:32 +1200 Subject: [PATCH] fix integrations --- packages/config/src/chains.ts | 2 ++ packages/config/src/configs/moonbaseAlpha.ts | 25 +++++++++++++++---- packages/sdk/src/contract/contract.factory.ts | 14 +++++++++-- .../getTransferData/getTransferData.utils.ts | 21 ++++++++-------- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/packages/config/src/chains.ts b/packages/config/src/chains.ts index 3a629f2d..a69116bc 100644 --- a/packages/config/src/chains.ts +++ b/packages/config/src/chains.ts @@ -747,6 +747,7 @@ export const moonbaseAlpha = new EvmParachain({ { asset: ftmwh, id: '0x566c1cebc6A4AFa1C122E039C4BEBe77043148Ee', + metadataId: 0, // no metadata for ERC20 tokens }, { asset: hdx, @@ -755,6 +756,7 @@ export const moonbaseAlpha = new EvmParachain({ { asset: usdcwh, id: '0xE5dE10C4b744bac6b783fAF8d9B9fDFF14Acc3c9', + metadataId: 0, // no metadata for ERC20 tokens }, ], ecosystem: Ecosystem.AlphanetRelay, diff --git a/packages/config/src/configs/moonbaseAlpha.ts b/packages/config/src/configs/moonbaseAlpha.ts index 2beca035..92277e33 100644 --- a/packages/config/src/configs/moonbaseAlpha.ts +++ b/packages/config/src/configs/moonbaseAlpha.ts @@ -215,8 +215,8 @@ export const moonbaseAlphaConfig = new ChainConfig({ destination: hydraDxAlphanet, destinationFee: { amount: 0.1, - asset: hdx, - balance: BalanceBuilder().substrate().system().account(), + asset: usdcwh, + balance: BalanceBuilder().evm().erc20(), }, fee: { asset: dev, @@ -229,9 +229,9 @@ export const moonbaseAlphaConfig = new ChainConfig({ contract: ContractBuilder().Xtokens().transfer(), destination: hydraDxAlphanet, destinationFee: { - amount: 0.1, - asset: hdx, - balance: BalanceBuilder().substrate().system().account(), + amount: 0.01, + asset: ftmwh, + balance: BalanceBuilder().evm().erc20(), }, fee: { asset: dev, @@ -249,6 +249,21 @@ export const moonbaseAlphaConfig = new ChainConfig({ balance: BalanceBuilder().substrate().system().account(), }, }), + new AssetConfig({ + asset: hdx, + balance: BalanceBuilder().substrate().assets().account(), + contract: ContractBuilder().Xtokens().transfer(), + destination: hydraDxAlphanet, + destinationFee: { + amount: 0.5, + asset: hdx, + balance: BalanceBuilder().substrate().system().account(), + }, + fee: { + asset: dev, + balance: BalanceBuilder().substrate().system().account(), + }, + }), ], chain: moonbaseAlpha, }); diff --git a/packages/sdk/src/contract/contract.factory.ts b/packages/sdk/src/contract/contract.factory.ts index 0ef0be76..2fae09ff 100644 --- a/packages/sdk/src/contract/contract.factory.ts +++ b/packages/sdk/src/contract/contract.factory.ts @@ -1,5 +1,5 @@ import { ContractConfig } from '@moonbeam-network/xcm-builder'; -import { EvmParachain } from '@moonbeam-network/xcm-types'; +import { AnyChain, EvmParachain } from '@moonbeam-network/xcm-types'; import { EvmSigner } from '../sdk.interfaces'; import { BalanceContractInterface, @@ -8,7 +8,7 @@ import { import { Erc20, Xtokens } from './contracts'; import { Erc20Public } from './contracts/Erc20/Erc20Public'; -export function createContract( +export function createContractWithSigner( config: ContractConfig, signer: EvmSigner, ): TransferContractInterface | BalanceContractInterface { @@ -33,3 +33,13 @@ export function createContractWithoutSigner( throw new Error(`Public Contract ${config.module} not found`); } + +export function createContract( + config: ContractConfig, + signer: EvmSigner | undefined, + chain?: AnyChain, +): TransferContractInterface | BalanceContractInterface { + return signer + ? createContractWithSigner(config, signer) + : createContractWithoutSigner(config, chain as EvmParachain); +} diff --git a/packages/sdk/src/getTransferData/getTransferData.utils.ts b/packages/sdk/src/getTransferData/getTransferData.utils.ts index d2a68635..71301846 100644 --- a/packages/sdk/src/getTransferData/getTransferData.utils.ts +++ b/packages/sdk/src/getTransferData/getTransferData.utils.ts @@ -1,11 +1,8 @@ import { CallType, SubstrateQueryConfig } from '@moonbeam-network/xcm-builder'; import { AssetConfig } from '@moonbeam-network/xcm-config'; -import { AnyChain, Asset, EvmParachain } from '@moonbeam-network/xcm-types'; +import { AnyChain, Asset } from '@moonbeam-network/xcm-types'; import { convertDecimals, toBigInt } from '@moonbeam-network/xcm-utils'; -import { - BalanceContractInterface, - createContractWithoutSigner, -} from '../contract'; +import { BalanceContractInterface, createContract } from '../contract'; import { PolkadotService } from '../polkadot'; import { EvmSigner } from '../sdk.interfaces'; @@ -26,13 +23,13 @@ export async function getBalance({ chain, config, decimals, + evmSigner, polkadot, }: GetBalancesParams) { const cfg = config.balance.build({ address, asset: polkadot.chain.getBalanceAssetId(config.asset), }); - if (cfg.type === CallType.Substrate) { const balance = await polkadot.query(cfg as SubstrateQueryConfig); return chain.usesChainDecimals @@ -40,9 +37,10 @@ export async function getBalance({ : balance; } - const contract = createContractWithoutSigner( + const contract = createContract( cfg, - chain as EvmParachain, + evmSigner, + chain, ) as BalanceContractInterface; const balance = await contract.getBalance(); @@ -55,20 +53,21 @@ export async function getDecimals({ asset, config, polkadot, + evmSigner, chain, }: GetDecimalsParams) { const cfg = config.balance.build({ address, asset: polkadot.chain.getBalanceAssetId(asset || config.asset), }); - if (cfg.type === CallType.Substrate) { return polkadot.getAssetDecimals(asset || config.asset); } - const contract = createContractWithoutSigner( + const contract = createContract( cfg, - chain as EvmParachain, + evmSigner, + chain, ) as BalanceContractInterface; return contract.getDecimals();