Skip to content

Commit

Permalink
fix integrations
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaurello committed Apr 8, 2024
1 parent 64b2a55 commit c7de67f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
2 changes: 2 additions & 0 deletions packages/config/src/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,7 @@ export const moonbaseAlpha = new EvmParachain({
{
asset: ftmwh,
id: '0x566c1cebc6A4AFa1C122E039C4BEBe77043148Ee',
metadataId: 0, // no metadata for ERC20 tokens
},
{
asset: hdx,
Expand All @@ -755,6 +756,7 @@ export const moonbaseAlpha = new EvmParachain({
{
asset: usdcwh,
id: '0xE5dE10C4b744bac6b783fAF8d9B9fDFF14Acc3c9',
metadataId: 0, // no metadata for ERC20 tokens
},
],
ecosystem: Ecosystem.AlphanetRelay,
Expand Down
25 changes: 20 additions & 5 deletions packages/config/src/configs/moonbaseAlpha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
});
14 changes: 12 additions & 2 deletions packages/sdk/src/contract/contract.factory.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand All @@ -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);
}
21 changes: 10 additions & 11 deletions packages/sdk/src/getTransferData/getTransferData.utils.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -26,23 +23,24 @@ 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
? convertDecimals(balance, polkadot.decimals, decimals)
: balance;
}

const contract = createContractWithoutSigner(
const contract = createContract(
cfg,
chain as EvmParachain,
evmSigner,
chain,
) as BalanceContractInterface;

const balance = await contract.getBalance();
Expand All @@ -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();
Expand Down

0 comments on commit c7de67f

Please sign in to comment.