Skip to content

Commit b6334e5

Browse files
lrazovicJuaniRios
authored andcommitted
feat: add initial TODO for testing WETH
1 parent 931e2bb commit b6334e5

File tree

7 files changed

+52
-28
lines changed

7 files changed

+52
-28
lines changed

integration-tests/chopsticks/overrides/polkadot-hub.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,5 @@ export const polkadot_hub_storage = {
3737
],
3838
],
3939
},
40+
// TODO: Add the foreignAssets storage to give to ALICE WETH = INITIAL_BALANCES.WETH
4041
} as const;

integration-tests/chopsticks/src/constants.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { Accounts } from '@/types';
22

33
export const INITIAL_BALANCES = {
4-
USDT: 52000000000n,
5-
USDC: 66600000000n,
6-
DOT: 10000000000000000n,
7-
PLMC: 10000000000000000n,
4+
USDT: 52000n * 10n ** 6n,
5+
USDC: 66000n * 10n ** 6n,
6+
DOT: 1000000n * 10n ** 10n,
7+
PLMC: 1000000n * 10n ** 10n,
8+
WETH: 2n * 10n ** 18n,
89
} as const;
910

1011
export const TRANSFER_AMOUNTS = {
11-
TOKENS: 2000000n,
12-
NATIVE: 20000000000n,
12+
TOKENS: 2n * 10n ** 6n, // e.g. 2 USDC
13+
NATIVE: 2n * 10n ** 10n, // e.g. 2 DOT
14+
BRIDGED: 1n * 10n ** 17n, // e.g. 0.1 WETH
1315
} as const;
1416

1517
export const DERIVE_PATHS = {

integration-tests/chopsticks/src/setup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export class ChainSetup {
6060
private async setupPolimec(polimec_storage: unknown) {
6161
const file = Bun.file(POLIMEC_WASM);
6262

63+
// Note: the tests are inteded to use a pre-production, locally compiled runtime, that's why we throw an error.
6364
if (!(await file.exists())) {
6465
throw new Error(
6566
'Polimec runtime not found! Please build it by running `cargo b -r -p polimec-runtime` before executing the tests.',

integration-tests/chopsticks/src/transfers/HubToPolimec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class HubToPolimecTransfer extends BaseTransferTest<HubTransferOptions> {
6262
async verifyFinalBalances(
6363
initialBalances: PolimecBalanceCheck,
6464
finalBalances: PolimecBalanceCheck,
65-
{ amount, asset }: HubTransferOptions,
65+
{ asset }: HubTransferOptions,
6666
) {
6767
// TODO: At the moment we exclude fees from the balance check since the PAPI team is wotking on some utilies to calculate fees.
6868
const initialBalance =

integration-tests/chopsticks/src/transfers/PolkadotToPolimec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ export class PolkadotToPolimecTransfer extends BaseTransferTest<PolkadotTransfer
5454
async verifyFinalBalances(
5555
initialBalances: PolimecBalanceCheck,
5656
finalBalances: PolimecBalanceCheck,
57-
{ amount }: PolkadotTransferOptions,
5857
) {
5958
// TODO: At the moment we exclude fees from the balance check since the PAPI team is wotking on some utilies to calculate fees.
6059
expect(initialBalances.destination).toBe(0n);

integration-tests/chopsticks/src/types.ts

+16
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,19 @@ export interface BalanceCheck {
5252
export interface PolimecBalanceCheck extends BalanceCheck {
5353
treasury: bigint;
5454
}
55+
56+
export interface TransferDataParams {
57+
amount: bigint;
58+
toChain: Chains;
59+
assetIndex?: bigint;
60+
recv?: Accounts;
61+
isMultiHop?: boolean;
62+
// TODO: Check if this flag is actually needed.
63+
isFromBridge?: boolean;
64+
}
65+
66+
export interface CreateAssetsParams {
67+
amount: bigint;
68+
assetIndex?: bigint;
69+
isFromBridge?: boolean;
70+
}

integration-tests/chopsticks/src/utils.ts

+25-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Accounts, Chains, ParaId } from '@/types';
1+
import {
2+
Accounts,
3+
Chains,
4+
type CreateAssetsParams,
5+
ParaId,
6+
type TransferDataParams,
7+
} from '@/types';
28
import {
39
XcmV3Instruction,
410
XcmV3Junction,
@@ -51,7 +57,12 @@ const custom_xcm_on_dest = (): XcmVersionedXcm => {
5157
]);
5258
};
5359

54-
const createHubAssets = (amount: bigint, assetIndex?: bigint): XcmVersionedAssets =>
60+
// TODO: Modify this function to allow the creation of an XcmVersionedAssets that supports also WETH/bridged assets.
61+
const createHubAssets = ({
62+
amount,
63+
assetIndex,
64+
isFromBridge,
65+
}: CreateAssetsParams): XcmVersionedAssets =>
5566
XcmVersionedAssets.V3([
5667
{
5768
fun: XcmV3MultiassetFungibility.Fungible(amount),
@@ -67,7 +78,7 @@ const createHubAssets = (amount: bigint, assetIndex?: bigint): XcmVersionedAsset
6778
},
6879
]);
6980

70-
const createDotAssets = (amount: bigint): XcmVersionedAssets =>
81+
const createDotAssets = ({ amount }: CreateAssetsParams): XcmVersionedAssets =>
7182
XcmVersionedAssets.V3([
7283
{
7384
fun: XcmV3MultiassetFungibility.Fungible(amount),
@@ -78,8 +89,11 @@ const createDotAssets = (amount: bigint): XcmVersionedAssets =>
7889
},
7990
]);
8091

81-
const createPolimecAssets = (amount: bigint, assetIndex = 1984n): XcmVersionedAssets =>
82-
XcmVersionedAssets.V3([
92+
const createPolimecAssets = ({ amount, assetIndex }: CreateAssetsParams): XcmVersionedAssets => {
93+
if (!assetIndex) {
94+
throw new Error('You need to specify an Asset ID while creating an asset for Polimec');
95+
}
96+
return XcmVersionedAssets.V3([
8397
{
8498
id: XcmV3MultiassetAssetId.Concrete({
8599
parents: 1,
@@ -95,14 +109,7 @@ const createPolimecAssets = (amount: bigint, assetIndex = 1984n): XcmVersionedAs
95109
fun: XcmV3MultiassetFungibility.Fungible(amount),
96110
},
97111
]);
98-
99-
interface TransferDataParams {
100-
amount: bigint;
101-
toChain: Chains;
102-
assetIndex?: bigint;
103-
recv?: Accounts;
104-
isMultiHop?: boolean;
105-
}
112+
};
106113

107114
export const createTransferData = ({ amount, toChain, assetIndex, recv }: TransferDataParams) => {
108115
if (toChain === Chains.Polkadot) {
@@ -128,24 +135,22 @@ export const createTransferData = ({ amount, toChain, assetIndex, recv }: Transf
128135
beneficiary,
129136
assets:
130137
toChain === Chains.PolkadotHub
131-
? createPolimecAssets(amount, assetIndex)
132-
: createHubAssets(amount, assetIndex),
138+
? createPolimecAssets({ amount, assetIndex })
139+
: createHubAssets({ amount, assetIndex }),
133140
fee_asset_item: 0,
134141
weight_limit: XcmV3WeightLimit.Unlimited(),
135142
};
136143
};
137144

138-
export const createMultiHopTransferData = ({ amount, toChain }: TransferDataParams) => {
139-
if (toChain === Chains.Polkadot) {
140-
throw new Error('The Multi Hop destination cannot be Polkadot');
141-
}
145+
export const createMultiHopTransferData = ({ amount }: TransferDataParams) => {
142146
const dest = XcmVersionedLocation.V3({
143147
parents: 0,
144148
interior: XcmV3Junctions.X1(XcmV3Junction.Parachain(ParaId[Chains.PolkadotHub])),
145149
});
150+
146151
return {
147152
dest,
148-
assets: createDotAssets(amount),
153+
assets: createDotAssets({ amount }),
149154
assets_transfer_type: Enum('Teleport'),
150155
remote_fees_id: XcmVersionedAssetId.V3(
151156
XcmV3MultiassetAssetId.Concrete({

0 commit comments

Comments
 (0)