Skip to content

Commit

Permalink
fix: remove unnecessary convertions
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoaguirre committed Oct 11, 2024
1 parent aacac9f commit fa73a90
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn set_up_ksm_for_penpal_kusama_through_kah_to_pah(
amount: u128,
) -> (Location, v4::Location) {
let ksm_at_kusama_parachains = ksm_at_ah_kusama();
let ksm_at_asset_hub_polkadot = v4::Location::try_from(bridged_ksm_at_ah_polkadot()).unwrap();
let ksm_at_asset_hub_polkadot = bridged_ksm_at_ah_polkadot();
create_foreign_on_ah_polkadot(ksm_at_asset_hub_polkadot.clone(), true);

let penpal_location = AssetHubKusama::sibling_location_of(PenpalA::para_id());
Expand Down Expand Up @@ -115,8 +115,8 @@ fn send_ksm_from_asset_hub_kusama_to_asset_hub_polkadot() {
let amount = ASSET_HUB_KUSAMA_ED * 1_000;
let sender = AssetHubKusamaSender::get();
let receiver = AssetHubPolkadotReceiver::get();
let ksm_at_asset_hub_kusama = v4::Location::try_from(ksm_at_ah_kusama()).unwrap();
let bridged_ksm_at_ah_polkadot = v4::Location::try_from(bridged_ksm_at_ah_polkadot()).unwrap();
let ksm_at_asset_hub_kusama = ksm_at_ah_kusama();
let bridged_ksm_at_ah_polkadot = bridged_ksm_at_ah_polkadot();

create_foreign_on_ah_polkadot(bridged_ksm_at_ah_polkadot.clone(), true);
set_up_pool_with_dot_on_ah_polkadot(bridged_ksm_at_ah_polkadot.clone(), true);
Expand Down Expand Up @@ -187,7 +187,7 @@ fn send_back_dot_usdt_and_weth_from_asset_hub_kusama_to_asset_hub_polkadot() {
let amount_to_send = ASSET_HUB_POLKADOT_ED * 1_000;
let sender = AssetHubKusamaSender::get();
let receiver = AssetHubPolkadotReceiver::get();
let dot_at_asset_hub_kusama = v4::Location::try_from(bridged_dot_at_ah_kusama()).unwrap();
let dot_at_asset_hub_kusama = bridged_dot_at_ah_kusama();
let prefund_accounts = vec![(sender.clone(), prefund_amount)];
create_foreign_on_ah_kusama(dot_at_asset_hub_kusama.clone(), true, prefund_accounts);

Expand Down Expand Up @@ -259,13 +259,12 @@ fn send_back_dot_usdt_and_weth_from_asset_hub_kusama_to_asset_hub_polkadot() {
//////////////////////////////////////////////////////////////////

// wETH has same relative location on both Polkadot and Kusama AssetHubs
let bridged_weth_at_ah = v4::Location::try_from(weth_at_asset_hubs()).unwrap();
let bridged_usdt_at_asset_hub_kusama =
v4::Location::try_from(bridged_usdt_at_ah_kusama()).unwrap();
let bridged_weth_at_ah = weth_at_asset_hubs();
let bridged_usdt_at_asset_hub_kusama = bridged_usdt_at_ah_kusama();

// set up destination chain AH Polkadot:
// create a DOT/USDT pool to be able to pay fees with USDT (USDT created in genesis)
set_up_pool_with_dot_on_ah_polkadot(usdt_at_ah_polkadot().try_into().unwrap(), false);
set_up_pool_with_dot_on_ah_polkadot(usdt_at_ah_polkadot(), false);
// create wETH on Polkadot (IRL it's already created by Snowbridge)
create_foreign_on_ah_polkadot(bridged_weth_at_ah.clone(), true);
// prefund KAH's sovereign account on PAH to be able to withdraw USDT and wETH from reserves
Expand Down Expand Up @@ -300,11 +299,11 @@ fn send_back_dot_usdt_and_weth_from_asset_hub_kusama_to_asset_hub_polkadot() {
let receiver_weth_before =
foreign_balance_on_ah_polkadot(bridged_weth_at_ah.clone(), &receiver);

let usdt_id: AssetId = Location::try_from(bridged_usdt_at_asset_hub_kusama).unwrap().into();
let usdt_id: AssetId = bridged_usdt_at_asset_hub_kusama.into();
// send USDTs and wETHs
let assets: Assets = vec![
(usdt_id.clone(), amount_to_send).into(),
(Location::try_from(bridged_weth_at_ah.clone()).unwrap(), amount_to_send).into(),
(bridged_weth_at_ah.clone(), amount_to_send).into(),
]
.into();
// use USDT for fees
Expand Down Expand Up @@ -398,7 +397,7 @@ fn send_ksm_from_penpal_kusama_through_asset_hub_kusama_to_asset_hub_polkadot()
vec![
// issue KSMs on PAH
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == v4::Location::try_from(ksm_at_kusama_parachains.clone()).unwrap(),
asset_id: *asset_id == ksm_at_kusama_parachains.clone(),
owner: owner == &receiver,
},
// message processed successfully
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn send_xcm_from_kusama_relay_to_polkadot_asset_hub_should_fail_on_not_applicabl
let xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit, check_origin },
ExportMessage {
network: PolkadotId.into(),
network: PolkadotId,
destination: [Parachain(AssetHubPolkadot::para_id().into())].into(),
xcm: remote_xcm,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn set_up_dot_for_penpal_polkadot_through_pah_to_kah(
amount: u128,
) -> (Location, v4::Location) {
let dot_at_polkadot_parachains = dot_at_ah_polkadot();
let dot_at_asset_hub_kusama = v4::Location::try_from(bridged_dot_at_ah_kusama()).unwrap();
let dot_at_asset_hub_kusama = bridged_dot_at_ah_kusama();
create_foreign_on_ah_kusama(dot_at_asset_hub_kusama.clone(), true);

let penpal_location = AssetHubPolkadot::sibling_location_of(PenpalB::para_id());
Expand Down Expand Up @@ -123,8 +123,7 @@ fn send_dot_usdt_and_weth_from_asset_hub_polkadot_to_asset_hub_kusama() {
let sender = AssetHubPolkadotSender::get();
let receiver = AssetHubKusamaReceiver::get();
let dot_at_asset_hub_polkadot = dot_at_ah_polkadot();
let bridged_dot_at_asset_hub_kusama =
v4::Location::try_from(bridged_dot_at_ah_kusama()).unwrap();
let bridged_dot_at_asset_hub_kusama = bridged_dot_at_ah_kusama();

create_foreign_on_ah_kusama(bridged_dot_at_asset_hub_kusama.clone(), true);
set_up_pool_with_ksm_on_ah_kusama(bridged_dot_at_asset_hub_kusama.clone(), true);
Expand Down Expand Up @@ -186,10 +185,9 @@ fn send_dot_usdt_and_weth_from_asset_hub_polkadot_to_asset_hub_kusama() {
// Now let's send over USDTs + wETH (and pay fees with USDT)
/////////////////////////////////////////////////////////////
let usdt_at_asset_hub_polkadot = usdt_at_ah_polkadot();
let bridged_usdt_at_asset_hub_kusama =
v4::Location::try_from(bridged_usdt_at_ah_kusama()).unwrap();
let bridged_usdt_at_asset_hub_kusama = bridged_usdt_at_ah_kusama();
// wETH has same relative location on both Polkadot and Kusama AssetHubs
let bridged_weth_at_ah = v4::Location::try_from(weth_at_asset_hubs()).unwrap();
let bridged_weth_at_ah = weth_at_asset_hubs();

// mint USDT in sender's account (USDT already created in genesis)
AssetHubPolkadot::mint_asset(
Expand All @@ -215,7 +213,7 @@ fn send_dot_usdt_and_weth_from_asset_hub_polkadot_to_asset_hub_kusama() {
// send USDTs and wETHs
let assets: Assets = vec![
(usdt_at_asset_hub_polkadot.clone(), amount).into(),
(Location::try_from(bridged_weth_at_ah.clone()).unwrap(), amount).into(),
(bridged_weth_at_ah.clone(), amount).into(),
]
.into();
// use USDT for fees
Expand Down Expand Up @@ -263,8 +261,7 @@ fn send_back_ksm_from_asset_hub_polkadot_to_asset_hub_kusama() {
let amount_to_send = ASSET_HUB_KUSAMA_ED * 1_000;
let sender = AssetHubPolkadotSender::get();
let receiver = AssetHubKusamaReceiver::get();
let bridged_ksm_at_asset_hub_polkadot =
v4::Location::try_from(bridged_ksm_at_ah_polkadot()).unwrap();
let bridged_ksm_at_asset_hub_polkadot = bridged_ksm_at_ah_polkadot();
let prefund_accounts = vec![(sender.clone(), prefund_amount)];
create_foreign_on_ah_polkadot(
bridged_ksm_at_asset_hub_polkadot.clone(),
Expand All @@ -291,11 +288,7 @@ fn send_back_ksm_from_asset_hub_polkadot_to_asset_hub_kusama() {
// send back KSMs, use them for fees
send_assets_over_bridge(|| {
let destination = asset_hub_kusama_location();
let assets: Assets = (
Location::try_from(bridged_ksm_at_asset_hub_polkadot.clone()).unwrap(),
amount_to_send,
)
.into();
let assets: Assets = (bridged_ksm_at_asset_hub_polkadot.clone(), amount_to_send).into();
let fee_idx = 0;
assert_ok!(send_assets_from_asset_hub_polkadot(destination, assets, fee_idx));
});
Expand Down Expand Up @@ -389,7 +382,7 @@ fn send_dot_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_kusama(
vec![
// issue DOTs on KAH
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { asset_id, owner, .. }) => {
asset_id: *asset_id == v4::Location::try_from(dot_at_polkadot_parachains.clone()).unwrap(),
asset_id: *asset_id == dot_at_polkadot_parachains.clone(),
owner: owner == &receiver,
},
// message processed successfully
Expand Down Expand Up @@ -419,7 +412,7 @@ fn send_dot_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_kusama(

#[test]
fn send_back_ksm_from_penpal_polkadot_through_asset_hub_polkadot_to_asset_hub_kusama() {
let ksm_at_polkadot_parachains = v4::Location::try_from(bridged_ksm_at_ah_polkadot()).unwrap();
let ksm_at_polkadot_parachains = bridged_ksm_at_ah_polkadot();
let amount = ASSET_HUB_POLKADOT_ED * 10_000_000;
let sender = PenpalBSender::get();
let receiver = AssetHubKusamaReceiver::get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn send_xcm_from_polkadot_relay_to_kusama_asset_hub_should_fail_on_not_applicabl
let xcm = VersionedXcm::from(Xcm(vec![
UnpaidExecution { weight_limit, check_origin },
ExportMessage {
network: KusamaId.into(),
network: KusamaId,
destination: [Parachain(AssetHubKusama::para_id().into())].into(),
xcm: remote_xcm,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ fn send_token_from_ethereum_to_penpal() {
let weth_asset_location: Location =
(Parent, Parent, EthereumNetwork::get(), AccountKey20 { network: None, key: WETH }).into();
// Converts the Weth asset location into an asset ID
let weth_asset_id: v4::Location = weth_asset_location.clone().try_into().unwrap();
let weth_asset_id = weth_asset_location.clone();

// Fund ethereum sovereign on AssetHub
AssetHubPolkadot::fund_accounts(vec![(ethereum_sovereign_account(), INITIAL_FUND)]);
Expand Down Expand Up @@ -853,14 +853,14 @@ fn send_token_from_ethereum_to_asset_hub_with_fee(account_id: [u8; 32], fee: u12

assert_ok!(<AssetHubPolkadot as AssetHubPolkadotPallet>::ForeignAssets::force_create(
RuntimeOrigin::root(),
weth_asset_location.clone().try_into().unwrap(),
weth_asset_location.clone(),
asset_hub_sovereign.into(),
false,
1,
));

assert!(<AssetHubPolkadot as AssetHubPolkadotPallet>::ForeignAssets::asset_exists(
weth_asset_location.clone().try_into().unwrap(),
weth_asset_location.clone(),
));
});

Expand Down

0 comments on commit fa73a90

Please sign in to comment.