Skip to content

Commit

Permalink
Replace WETH with ETH
Browse files Browse the repository at this point in the history
  • Loading branch information
JuaniRios committed Feb 26, 2025
1 parent 0394eca commit a9d222b
Show file tree
Hide file tree
Showing 30 changed files with 106 additions and 166 deletions.
15 changes: 4 additions & 11 deletions integration-tests/chopsticks/overrides/polimec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,17 @@ const dot_location = {
},
};

export const weth_location = {
export const eth_location = {
parents: 2,
interior: {
x2: [
x1: [
{
globalConsensus: {
ethereum: {
chainId: 1n,
},
},
},
{
accountKey20: {
key: WETH_ADDRESS,
},
},
],
},
};
Expand Down Expand Up @@ -81,7 +76,7 @@ export const polimec_storage = {
// Note: We can remove Asset and Metadata from the storage override as soon we set them on-chain.
Asset: [
[
[weth_location],
[eth_location],
{
owner: Accounts.ALICE,
issuer: Accounts.ALICE,
Expand All @@ -98,8 +93,6 @@ export const polimec_storage = {
},
],
],
Metadata: [
[[weth_location], { symbol: 'Wrapped Ether', name: 'WETH', decimals: 18, isFrozen: false }],
],
Metadata: [[[eth_location], { symbol: 'Ether', name: 'ETH', decimals: 18, isFrozen: false }]],
},
} as const;
4 changes: 2 additions & 2 deletions integration-tests/chopsticks/overrides/polkadot-hub.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { INITIAL_BALANCES } from '@/constants';
import { Accounts, Asset } from '@/types';
import { weth_location } from './polimec';
import { eth_location } from './polimec';

export const polkadot_hub_storage = {
System: {
Expand Down Expand Up @@ -35,7 +35,7 @@ export const polkadot_hub_storage = {
ForeignAssets: {
Account: [
[
[weth_location, Accounts.POLIMEC],
[eth_location, Accounts.POLIMEC],
{
balance: INITIAL_BALANCES.WETH,
},
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/chopsticks/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export const DERIVE_PATHS = {
export const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
export const DEFAULT_TOPIC = FixedSizeBinary.fromArray(Array(32).fill(1));
export const FEE_AMOUNT = 40_000_000_000n;
export const WETH_AMOUNT = 15_000_000_000_000n;
export const ETH_AMOUNT = 15_000_000_000_000n;
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ export class BridgerHubManagaer extends BaseChainManager {
return AssetSourceRelation.Sibling;
case Asset.USDC:
return AssetSourceRelation.Sibling;
case Asset.WETH:
case Asset.ETH:
// TODO: Check it Placeholder
return AssetSourceRelation.Self;
}

return AssetSourceRelation.Self;
}

// Note: On BridgeHub, there should be no balance for any asset.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class PolimecManager extends BaseChainManager {
return AssetSourceRelation.Sibling;
case Asset.USDC:
return AssetSourceRelation.Sibling;
case Asset.WETH:
case Asset.ETH:
// Placeholder
return AssetSourceRelation.Self;
case Asset.PLMC:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class PolkadotHubManager extends BaseChainManager {
return AssetSourceRelation.Self;
case Asset.USDC:
return AssetSourceRelation.Self;
case Asset.WETH:
case Asset.ETH:
// This is not actually used, so we use Self as a placeholder
return AssetSourceRelation.Self;
case Asset.PLMC:
Expand Down
4 changes: 3 additions & 1 deletion integration-tests/chopsticks/src/managers/PolkadotManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ export class PolkadotManager extends BaseChainManager {
case Asset.USDC:
// Placeholder
return AssetSourceRelation.Self;
case Asset.WETH:
case Asset.ETH:
// Placeholder
return AssetSourceRelation.Self;
}

return AssetSourceRelation.Self;
}

async getAssetBalanceOf(account: Accounts, asset: Asset): Promise<bigint> {
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/chopsticks/src/tests/bridge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ describe('Bridge Hub -> Polimec Transfer Tests', () => {
afterAll(async () => await chainSetup.cleanup());

test(
'Send WETH to Polimec',
'Send ETH to Polimec',
() =>
transferTest.testTransfer({
account: Accounts.ALICE,
assets: [[Asset.WETH, TRANSFER_AMOUNTS.BRIDGED, AssetSourceRelation.Self]],
assets: [[Asset.ETH, TRANSFER_AMOUNTS.BRIDGED, AssetSourceRelation.Self]],
}),
{ timeout: 25000 },
{ timeout: 40000 },
);
});
37 changes: 14 additions & 23 deletions integration-tests/chopsticks/src/transfers/BridgeToPolimec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'bun:test';
import { DEFAULT_TOPIC, FEE_AMOUNT, WETH_ADDRESS, WETH_AMOUNT } from '@/constants';
import { DEFAULT_TOPIC, ETH_AMOUNT, FEE_AMOUNT, WETH_ADDRESS } from '@/constants';
import type { BridgerHubManagaer } from '@/managers/BridgeHubManager';
import type { PolimecManager } from '@/managers/PolimecManager';
import type { PolkadotHubManager } from '@/managers/PolkadotHubManager';
Expand Down Expand Up @@ -102,7 +102,10 @@ export class BridgeToPolimecTransfer extends BaseTransferTest {
(event) => event.type === 'ForeignAssets' && event.value.type === 'Issued',
);

// TODO: Check why we have 3 events instead of 2 (WETH + DOT). Curently we have 3 events (WETH + DOT + DOT)
console.log('Issued Events on Destination: \n');
console.dir(issuedEventsOnDest, { depth: null });

// TODO: Check why we have 3 events instead of 2 (ETH + DOT). Curently we have 3 events (ETH + DOT + DOT)
expect(issuedEventsOnDest.length).toBe(3);

return { sourceBlock, destBlock };
Expand Down Expand Up @@ -147,15 +150,11 @@ export class BridgeToPolimecTransfer extends BaseTransferTest {
{
id: XcmV3MultiassetAssetId.Concrete({
parents: 2,
interior: XcmV3Junctions.X2([
interior: XcmV3Junctions.X1(
XcmV3Junction.GlobalConsensus(XcmV3JunctionNetworkId.Ethereum({ chain_id: 1n })),
XcmV3Junction.AccountKey20({
network: undefined,
key: FixedSizeBinary.fromHex(WETH_ADDRESS),
}),
]),
),
}),
fun: XcmV3MultiassetFungibility.Fungible(WETH_AMOUNT),
fun: XcmV3MultiassetFungibility.Fungible(ETH_AMOUNT),
},
]),

Expand Down Expand Up @@ -190,15 +189,11 @@ export class BridgeToPolimecTransfer extends BaseTransferTest {
{
id: XcmV3MultiassetAssetId.Concrete({
parents: 2,
interior: XcmV3Junctions.X2([
interior: XcmV3Junctions.X1(
XcmV3Junction.GlobalConsensus(XcmV3JunctionNetworkId.Ethereum({ chain_id: 1n })),
XcmV3Junction.AccountKey20({
network: undefined,
key: FixedSizeBinary.fromHex(WETH_ADDRESS),
}),
]),
),
}),
fun: XcmV3MultiassetFungibility.Fungible(WETH_AMOUNT),
fun: XcmV3MultiassetFungibility.Fungible(ETH_AMOUNT),
},
]),
dest: {
Expand Down Expand Up @@ -250,15 +245,11 @@ export class BridgeToPolimecTransfer extends BaseTransferTest {
{
id: XcmV3MultiassetAssetId.Concrete({
parents: 2,
interior: XcmV3Junctions.X2([
interior: XcmV3Junctions.X1(
XcmV3Junction.GlobalConsensus(XcmV3JunctionNetworkId.Ethereum({ chain_id: 1n })),
XcmV3Junction.AccountKey20({
network: undefined,
key: FixedSizeBinary.fromHex(WETH_ADDRESS),
}),
]),
),
}),
fun: XcmV3MultiassetFungibility.Fungible(WETH_AMOUNT),
fun: XcmV3MultiassetFungibility.Fungible(ETH_AMOUNT),
},
]),

Expand Down
20 changes: 0 additions & 20 deletions integration-tests/chopsticks/src/transfers/PolimecToHub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,6 @@ export class PolimecToHubTransfer extends BaseTransferTest {
return { asset_balances: [{ source, destination }] };
}

// verifyFinalBalances(
// initialBalances: BalanceCheck[],
// finalBalances: BalanceCheck[],
// options: TransferOptions,
// ) {
// // 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 =
// options.assets[0][0] === Asset.DOT
// ? INITIAL_BALANCES.DOT
// : options.assets[0][0] === Asset.USDT
// ? INITIAL_BALANCES.USDT
// : INITIAL_BALANCES.USDC;
// for (let i = 0; i < options.assets.length; i++) {
// expect(initialBalances[i].destination).toBe(0n);
// expect(initialBalances[i].source).toBe(initialBalance);
// expect(finalBalances[i].source).toBeLessThan(initialBalances[i].source);
// expect(finalBalances[i].destination).toBeGreaterThan(initialBalances[i].destination);
// }
// }

async verifyFinalBalances(
assetInitialBalances: PolimecBalanceCheck[],
assetFinalBalances: PolimecBalanceCheck[],
Expand Down
13 changes: 6 additions & 7 deletions integration-tests/chopsticks/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export enum Asset {
DOT = 10,
USDC = 1337,
USDT = 1984,
WETH = 10000,
ETH = 10000,
PLMC = 3344,
}

Expand Down Expand Up @@ -160,13 +160,12 @@ export function NativeAssetLocation(
}
}

export function EthereumAssetLocation(contract_address: FixedSizeBinary<20>): XcmVersionedLocation {
export function EthereumLocation(): XcmVersionedLocation {
return XcmVersionedLocation.V4({
parents: 2,
interior: XcmV3Junctions.X2([
interior: XcmV3Junctions.X1(
XcmV3Junction.GlobalConsensus(XcmV3JunctionNetworkId.Ethereum({ chain_id: 1n })),
XcmV3Junction.AccountKey20({ network: undefined, key: contract_address }),
]),
),
});
}

Expand All @@ -175,8 +174,8 @@ export function AssetLocation(
assetSourceRelation: AssetSourceRelation,
): XcmVersionedLocation {
const baseLocation =
asset === Asset.WETH
? EthereumAssetLocation(FixedSizeBinary.fromHex(WETH_ADDRESS))
asset === Asset.ETH
? EthereumLocation()
: asset === Asset.DOT || asset === Asset.PLMC
? NativeAssetLocation(assetSourceRelation, asset)
: AssetHubAssetLocation(BigInt(asset), assetSourceRelation);
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub mod polimec {
let usdc = (AcceptedFundingAsset::USDC.id(), prices.usdc);
let usdt = (AcceptedFundingAsset::USDT.id(), prices.usdt);
let plmc = (Location::here(), prices.plmc);
let weth = (AcceptedFundingAsset::WETH.id(), prices.weth);
let weth = (AcceptedFundingAsset::ETH.id(), prices.weth);

let values: BoundedVec<(Location, FixedU128), <PolimecRuntime as orml_oracle::Config>::MaxFeedValues> =
vec![dot, usdc, usdt, plmc, weth].try_into().expect("benchmarks can panic");
Expand Down Expand Up @@ -356,7 +356,7 @@ pub mod polimec {
let dot_asset_id = AcceptedFundingAsset::DOT.id();
let usdt_asset_id = AcceptedFundingAsset::USDT.id();
let usdc_asset_id = AcceptedFundingAsset::USDC.id();
let weth_asset_id = AcceptedFundingAsset::WETH.id();
let weth_asset_id = AcceptedFundingAsset::ETH.id();

let mut funded_accounts = vec![(
PolimecNet::sovereign_account_id_of((Parent, xcm::prelude::Parachain(1000)).into()),
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/src/tests/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ use pallet_funding::{

use macros::generate_accounts;
use polimec_common::{
assets::AcceptedFundingAsset::{DOT, USDC, USDT, WETH},
ProvideAssetPrice, USD_DECIMALS, USD_UNIT,
assets::AcceptedFundingAsset::{DOT, USDC, USDT, ETH},
ProvideAssetPrice, USD_DECIMALS, USD_UNIT,
};
use polimec_runtime::AccountId;
use sp_runtime::traits::ConstU32;
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn default_project_metadata(issuer: AccountId) -> ProjectMetadataOf<polimec_
retail: TicketSize::new(100 * USD_UNIT, None),
phantom: Default::default(),
},
participation_currencies: vec![USDT, USDC, DOT, WETH].try_into().unwrap(),
participation_currencies: vec![USDT, USDC, DOT, ETH].try_into().unwrap(),
funding_destination_account: issuer,
policy_ipfs_cid: Some(ipfs_hash()),
participants_account_type: ParticipantsAccountType::Polkadot,
Expand Down
14 changes: 8 additions & 6 deletions integration-tests/src/tests/evaluator_slash_sideffects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ fn evaluator_slash_reduces_vesting_schedules() {
assert_eq!(ProjectStatus::AuctionRound, inst.go_to_next_state(project_id));
assert_eq!(ProjectStatus::FundingFailed, inst.go_to_next_state(project_id));
assert_eq!(ProjectStatus::SettlementStarted(FundingOutcome::Failure), inst.go_to_next_state(project_id));
assert_eq!(inst.current_block(), BlockNumberFor::<PolimecRuntime>::from(25u32));

// All schedules start at block 5, and funding ended at block 25
const TIME_PASSED: u128 = 20u128;
const END_BLOCK: u32 = 18;
assert_eq!(inst.current_block(), BlockNumberFor::<PolimecRuntime>::from(END_BLOCK));

// All schedules start at block 5, and funding ended at block 18
const TIME_PASSED: u128 = 13u128;

let alice_account_data = Account::<PolimecRuntime>::get(&alice.clone()).data;
assert_eq!(
Expand Down Expand Up @@ -177,9 +179,9 @@ fn evaluator_slash_reduces_vesting_schedules() {
assert_eq!(
alice_schedules,
vec![
VestingInfo::new(new_lock_1, new_per_block_1, 25),
VestingInfo::new(new_lock_3, new_per_block_3, 25),
VestingInfo::new(new_lock_4, new_per_block_4, 25),
VestingInfo::new(new_lock_1, new_per_block_1, END_BLOCK),
VestingInfo::new(new_lock_3, new_per_block_3, END_BLOCK),
VestingInfo::new(new_lock_4, new_per_block_4, END_BLOCK),
]
);
assert_eq!(alice_account_data, AccountData { free, reserved, frozen, flags: Default::default() });
Expand Down
8 changes: 4 additions & 4 deletions integration-tests/src/tests/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use sp_runtime::{bounded_vec, BoundedVec, FixedU128};
use std::collections::BTreeMap;
use tests::defaults::*;

use AcceptedFundingAsset::{DOT, USDC, USDT, WETH};
use AcceptedFundingAsset::{DOT, USDC, USDT, ETH};

fn values(
values: [f64; 5],
Expand All @@ -31,7 +31,7 @@ fn values(
(DOT.id(), FixedU128::from_float(dot)),
(USDC.id(), FixedU128::from_float(usdc)),
(USDT.id(), FixedU128::from_float(usdt)),
(WETH.id(), FixedU128::from_float(weth)),
(ETH.id(), FixedU128::from_float(weth)),
(Location::here(), FixedU128::from_float(plmc))
]
}
Expand All @@ -56,7 +56,7 @@ fn members_can_feed_data() {
(DOT.id(), FixedU128::from_float(4.84)),
(USDC.id(), FixedU128::from_float(1.0)),
(USDT.id(), FixedU128::from_float(1.0)),
(WETH.id(), FixedU128::from_float(2500.0)),
(ETH.id(), FixedU128::from_float(2500.0)),
(Location::here(), FixedU128::from_float(0.4)),
]);

Expand Down Expand Up @@ -102,7 +102,7 @@ fn data_is_correctly_combined() {
(DOT.id(), FixedU128::from_float(2.0)),
(USDC.id(), FixedU128::from_float(1.0)),
(USDT.id(), FixedU128::from_float(1.1)),
(WETH.id(), FixedU128::from_float(2500.0)),
(ETH.id(), FixedU128::from_float(2500.0)),
(Location::here(), FixedU128::from_float(0.22222)),
]);

Expand Down
Loading

0 comments on commit a9d222b

Please sign in to comment.