Skip to content

Commit

Permalink
feat: add initial TODO for testing WETH
Browse files Browse the repository at this point in the history
  • Loading branch information
lrazovic committed Dec 7, 2024
1 parent f280e68 commit 094babf
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 28 deletions.
1 change: 1 addition & 0 deletions integration-tests/chopsticks/overrides/polkadot-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ export const polkadot_hub_storage = {
],
],
},
// TODO: Add the foreignAssets storage to give to ALICE WETH = INITIAL_BALANCES.WETH
} as const;
14 changes: 8 additions & 6 deletions integration-tests/chopsticks/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Accounts } from '@/types';

export const INITIAL_BALANCES = {
USDT: 52000000000n,
USDC: 66600000000n,
DOT: 10000000000000000n,
PLMC: 10000000000000000n,
USDT: 52000n * 10n ** 6n,
USDC: 66000n * 10n ** 6n,
DOT: 1000000n * 10n ** 10n,
PLMC: 1000000n * 10n ** 10n,
WETH: 2n * 10n ** 18n,
} as const;

export const TRANSFER_AMOUNTS = {
TOKENS: 2000000n,
NATIVE: 20000000000n,
TOKENS: 2n * 10n ** 6n, // e.g. 2 USDC
NATIVE: 2n * 10n ** 10n, // e.g. 2 DOT
BRIDGED: 1n * 10n ** 17n, // e.g. 0.1 WETH
} as const;

export const DERIVE_PATHS = {
Expand Down
1 change: 1 addition & 0 deletions integration-tests/chopsticks/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class ChainSetup {
private async setupPolimec(polimec_storage: unknown) {
const file = Bun.file(POLIMEC_WASM);

// Note: the tests are inteded to use a pre-production, locally compiled runtime, that's why we throw an error.
if (!(await file.exists())) {
throw new Error(
'Polimec runtime not found! Please build it by running `cargo b -r -p polimec-runtime` before executing the tests.',
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/chopsticks/src/transfers/HubToPolimec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class HubToPolimecTransfer extends BaseTransferTest<HubTransferOptions> {
async verifyFinalBalances(
initialBalances: PolimecBalanceCheck,
finalBalances: PolimecBalanceCheck,
{ amount, asset }: HubTransferOptions,
{ asset }: HubTransferOptions,
) {
// TODO: At the moment we exclude fees from the balance check since the PAPI team is wotking on some utilies to calculate fees.
const initialBalance =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export class PolkadotToPolimecTransfer extends BaseTransferTest<PolkadotTransfer
async verifyFinalBalances(
initialBalances: PolimecBalanceCheck,
finalBalances: PolimecBalanceCheck,
{ amount }: PolkadotTransferOptions,
) {
// TODO: At the moment we exclude fees from the balance check since the PAPI team is wotking on some utilies to calculate fees.
expect(initialBalances.destination).toBe(0n);
Expand Down
16 changes: 16 additions & 0 deletions integration-tests/chopsticks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,19 @@ export interface BalanceCheck {
export interface PolimecBalanceCheck extends BalanceCheck {
treasury: bigint;
}

export interface TransferDataParams {
amount: bigint;
toChain: Chains;
assetIndex?: bigint;
recv?: Accounts;
isMultiHop?: boolean;
// TODO: Check if this flag is actually needed.
isFromBridge?: boolean;
}

export interface CreateAssetsParams {
amount: bigint;
assetIndex?: bigint;
isFromBridge?: boolean;
}
45 changes: 25 additions & 20 deletions integration-tests/chopsticks/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { Accounts, Chains, ParaId } from '@/types';
import {
Accounts,
Chains,
type CreateAssetsParams,
ParaId,
type TransferDataParams,
} from '@/types';
import {
XcmV3Instruction,
XcmV3Junction,
Expand Down Expand Up @@ -51,7 +57,12 @@ const custom_xcm_on_dest = (): XcmVersionedXcm => {
]);
};

const createHubAssets = (amount: bigint, assetIndex?: bigint): XcmVersionedAssets =>
// TODO: Modify this function to allow the creation of an XcmVersionedAssets that supports also WETH/bridged assets.
const createHubAssets = ({
amount,
assetIndex,
isFromBridge,
}: CreateAssetsParams): XcmVersionedAssets =>
XcmVersionedAssets.V3([
{
fun: XcmV3MultiassetFungibility.Fungible(amount),
Expand All @@ -67,7 +78,7 @@ const createHubAssets = (amount: bigint, assetIndex?: bigint): XcmVersionedAsset
},
]);

const createDotAssets = (amount: bigint): XcmVersionedAssets =>
const createDotAssets = ({ amount }: CreateAssetsParams): XcmVersionedAssets =>
XcmVersionedAssets.V3([
{
fun: XcmV3MultiassetFungibility.Fungible(amount),
Expand All @@ -78,8 +89,11 @@ const createDotAssets = (amount: bigint): XcmVersionedAssets =>
},
]);

const createPolimecAssets = (amount: bigint, assetIndex = 1984n): XcmVersionedAssets =>
XcmVersionedAssets.V3([
const createPolimecAssets = ({ amount, assetIndex }: CreateAssetsParams): XcmVersionedAssets => {
if (!assetIndex) {
throw new Error('You need to specify an Asset ID while creating an asset for Polimec');
}
return XcmVersionedAssets.V3([
{
id: XcmV3MultiassetAssetId.Concrete({
parents: 1,
Expand All @@ -95,14 +109,7 @@ const createPolimecAssets = (amount: bigint, assetIndex = 1984n): XcmVersionedAs
fun: XcmV3MultiassetFungibility.Fungible(amount),
},
]);

interface TransferDataParams {
amount: bigint;
toChain: Chains;
assetIndex?: bigint;
recv?: Accounts;
isMultiHop?: boolean;
}
};

export const createTransferData = ({ amount, toChain, assetIndex, recv }: TransferDataParams) => {
if (toChain === Chains.Polkadot) {
Expand All @@ -128,24 +135,22 @@ export const createTransferData = ({ amount, toChain, assetIndex, recv }: Transf
beneficiary,
assets:
toChain === Chains.PolkadotHub
? createPolimecAssets(amount, assetIndex)
: createHubAssets(amount, assetIndex),
? createPolimecAssets({ amount, assetIndex })
: createHubAssets({ amount, assetIndex }),
fee_asset_item: 0,
weight_limit: XcmV3WeightLimit.Unlimited(),
};
};

export const createMultiHopTransferData = ({ amount, toChain }: TransferDataParams) => {
if (toChain === Chains.Polkadot) {
throw new Error('The Multi Hop destination cannot be Polkadot');
}
export const createMultiHopTransferData = ({ amount }: TransferDataParams) => {
const dest = XcmVersionedLocation.V3({
parents: 0,
interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(ParaId[Chains.PolkadotHub])),
});

return {
dest,
assets: createDotAssets(amount),
assets: createDotAssets({ amount }),
assets_transfer_type: Enum('Teleport'),
remote_fees_id: XcmVersionedAssetId.V3(
XcmV3MultiassetAssetId.Concrete({
Expand Down

0 comments on commit 094babf

Please sign in to comment.