Skip to content

Commit e296ce7

Browse files
committedNov 29, 2024
WETH from assethub support
1 parent e894641 commit e296ce7

File tree

15 files changed

+111
-30
lines changed

15 files changed

+111
-30
lines changed
 

‎Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎integration-tests/src/constants.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pub struct Prices {
6969
pub usdc: FixedU128,
7070
pub usdt: FixedU128,
7171
pub plmc: FixedU128,
72+
pub weth: FixedU128,
7273
}
7374

7475
// PricesBuilder for optional fields before building Prices
@@ -78,12 +79,13 @@ pub struct PricesBuilder {
7879
usdc: Option<FixedU128>,
7980
usdt: Option<FixedU128>,
8081
plmc: Option<FixedU128>,
82+
weth: Option<FixedU128>,
8183
}
8284

8385
impl PricesBuilder {
8486
// Initialize a new builder with None for each field
8587
pub fn new() -> Self {
86-
Self { dot: None, usdc: None, usdt: None, plmc: None }
88+
Self { dot: None, usdc: None, usdt: None, plmc: None, weth: None }
8789
}
8890

8991
pub fn default() -> Prices {
@@ -92,6 +94,7 @@ impl PricesBuilder {
9294
usdc: FixedU128::from_rational(1, 1),
9395
usdt: FixedU128::from_rational(1, 1),
9496
plmc: FixedU128::from_rational(840, 100),
97+
weth: FixedU128::from_rational(3620, 1),
9598
}
9699
}
97100

@@ -116,13 +119,19 @@ impl PricesBuilder {
116119
self
117120
}
118121

122+
pub fn weth(&mut self, price: FixedU128) -> &mut Self {
123+
self.weth = Some(price);
124+
self
125+
}
126+
119127
// Build Prices using provided values or default values
120128
pub fn build(self) -> Prices {
121129
Prices {
122130
dot: self.dot.unwrap_or(FixedU128::from_rational(69, 1)), // Default DOT price
123131
usdc: self.usdc.unwrap_or(FixedU128::from_rational(1, 1)), // Default USDC price
124132
usdt: self.usdt.unwrap_or(FixedU128::from_rational(1, 1)), // Default USDT price
125133
plmc: self.plmc.unwrap_or(FixedU128::from_rational(840, 100)), // Default PLMC price
134+
weth: self.weth.unwrap_or(FixedU128::from_rational(3620, 1)), // Default WETH price
126135
}
127136
}
128137
}
@@ -446,9 +455,10 @@ pub mod polimec {
446455
let usdc = (AcceptedFundingAsset::USDC.id(), prices.usdc);
447456
let usdt = (AcceptedFundingAsset::USDT.id(), prices.usdt);
448457
let plmc = (polimec_common::PLMC_FOREIGN_ID, prices.plmc);
458+
let weth = (AcceptedFundingAsset::WETH.id(), prices.weth);
449459

450460
let values: BoundedVec<(u32, FixedU128), <PolimecRuntime as orml_oracle::Config>::MaxFeedValues> =
451-
vec![dot, usdc, usdt, plmc].try_into().expect("benchmarks can panic");
461+
vec![dot, usdc, usdt, plmc, weth].try_into().expect("benchmarks can panic");
452462
let alice: [u8; 32] = [
453463
212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205,
454464
227, 154, 86, 132, 231, 165, 109, 162, 125,
@@ -483,6 +493,8 @@ pub mod polimec {
483493
let dot_asset_id = AcceptedFundingAsset::DOT.id();
484494
let usdt_asset_id = AcceptedFundingAsset::USDT.id();
485495
let usdc_asset_id = AcceptedFundingAsset::USDC.id();
496+
let weth_asset_id = AcceptedFundingAsset::WETH.id();
497+
486498
let mut funded_accounts = vec![
487499
(
488500
PolimecNet::sovereign_account_id_of((Parent, xcm::prelude::Parachain(penpal::PARA_ID)).into()),
@@ -515,11 +527,13 @@ pub mod polimec {
515527
(dot_asset_id, alice_account.clone(), true, 100_000_000),
516528
(usdt_asset_id, alice_account.clone(), true, 70_000),
517529
(usdc_asset_id, alice_account.clone(), true, 70_000),
530+
(weth_asset_id, alice_account.clone(), true, 0_000_041_000_000_000_000),
518531
],
519532
metadata: vec![
520533
(dot_asset_id, "Local DOT".as_bytes().to_vec(), "DOT".as_bytes().to_vec(), 10),
521534
(usdt_asset_id, "Local USDT".as_bytes().to_vec(), "USDT".as_bytes().to_vec(), 6),
522535
(usdc_asset_id, "Local USDC".as_bytes().to_vec(), "USDC".as_bytes().to_vec(), 6),
536+
(usdc_asset_id, "Local WETH".as_bytes().to_vec(), "WETH".as_bytes().to_vec(), 18),
523537
],
524538
accounts: vec![],
525539
},

‎integration-tests/src/tests/ethereum_support.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn test_hardcoded_signatures() {
1010
let project_id = 1;
1111

1212
// Values generated with `https://github.com/lrazovic/ethsigner`
13-
let polimec_account_ss58 = polimec_runtime::SS58Converter::convert(polimec_account.clone());
13+
let _polimec_account_ss58 = polimec_runtime::SS58Converter::convert(polimec_account.clone());
1414
let ethereum_account: [u8; 20] = hex!("796afe7b8933ee8cf337f17887e5c19b657f9ab8");
1515
let signature: [u8; 65] = hex!("952e312ac892fefc7c69051521e78a3bc2727fbb495585bdb5fb77e662b8a3de2b1254058d824e85034710e338c2590e2f92d74ce3c60292ed25c7537d94ed621b");
1616

‎pallets/funding/src/instantiator/chain_interactions.rs

+8
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,14 @@ impl<
545545
let mut total_expected_dot: Balance = Zero::zero();
546546
let mut total_expected_usdt: Balance = Zero::zero();
547547
let mut total_expected_usdc: Balance = Zero::zero();
548+
let mut total_expected_weth: Balance = Zero::zero();
548549

549550
for bid in bids {
550551
match bid.funding_asset {
551552
AcceptedFundingAsset::DOT => total_expected_dot += bid.funding_asset_amount_locked,
552553
AcceptedFundingAsset::USDT => total_expected_usdt += bid.funding_asset_amount_locked,
553554
AcceptedFundingAsset::USDC => total_expected_usdc += bid.funding_asset_amount_locked,
555+
AcceptedFundingAsset::WETH => total_expected_weth += bid.funding_asset_amount_locked,
554556
}
555557
}
556558

@@ -559,6 +561,7 @@ impl<
559561
AcceptedFundingAsset::DOT => total_expected_dot += contribution.funding_asset_amount,
560562
AcceptedFundingAsset::USDT => total_expected_usdt += contribution.funding_asset_amount,
561563
AcceptedFundingAsset::USDC => total_expected_usdc += contribution.funding_asset_amount,
564+
AcceptedFundingAsset::WETH => total_expected_weth += contribution.funding_asset_amount,
562565
}
563566
}
564567

@@ -572,12 +575,17 @@ impl<
572575
);
573576
let total_stored_usdc = self.get_free_funding_asset_balance_for(
574577
AcceptedFundingAsset::USDC.id(),
578+
project_metadata.funding_destination_account.clone(),
579+
);
580+
let total_stored_weth = self.get_free_funding_asset_balance_for(
581+
AcceptedFundingAsset::WETH.id(),
575582
project_metadata.funding_destination_account,
576583
);
577584

578585
assert_eq!(total_expected_dot, total_stored_dot, "DOT amount is incorrect");
579586
assert_eq!(total_expected_usdt, total_stored_usdt, "USDT amount is incorrect");
580587
assert_eq!(total_expected_usdc, total_stored_usdc, "USDC amount is incorrect");
588+
assert_eq!(total_expected_weth, total_stored_weth, "WETH amount is incorrect");
581589
}
582590

583591
// Used to check if all evaluations are settled correctly. We cannot check amount of

‎pallets/funding/src/mock.rs

+9
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,7 @@ thread_local! {
362362
(AcceptedFundingAsset::DOT.id(), FixedU128::from_float(69f64)), // DOT
363363
(AcceptedFundingAsset::USDC.id(), FixedU128::from_float(0.97f64)), // USDC
364364
(AcceptedFundingAsset::USDT.id(), FixedU128::from_float(1.0f64)), // USDT
365+
(AcceptedFundingAsset::WETH.id(), FixedU128::from_float(3619.451f64)), // WETH
365366
(PLMC_FOREIGN_ID, FixedU128::from_float(8.4f64)), // PLMC
366367
]));
367368
}
@@ -511,11 +512,19 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
511512
true,
512513
100_000_000,
513514
),
515+
(
516+
AcceptedFundingAsset::WETH.id(),
517+
<TestRuntime as Config>::PalletId::get().into_account_truncating(),
518+
true,
519+
// 0.07 USD = .000041WETH at this moment
520+
0_000_041_000_000_000_000,
521+
),
514522
],
515523
metadata: vec![
516524
(AcceptedFundingAsset::USDT.id(), "USDT".as_bytes().to_vec(), "USDT".as_bytes().to_vec(), 6),
517525
(AcceptedFundingAsset::USDC.id(), "USDC".as_bytes().to_vec(), "USDC".as_bytes().to_vec(), 6),
518526
(AcceptedFundingAsset::DOT.id(), "DOT".as_bytes().to_vec(), "DOT".as_bytes().to_vec(), 10),
527+
(AcceptedFundingAsset::WETH.id(), "WETH".as_bytes().to_vec(), "WETH".as_bytes().to_vec(), 18),
519528
],
520529
accounts: vec![],
521530
},

‎pallets/funding/src/tests/3_auction.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ mod round_flow {
147147
AcceptedFundingAsset::USDT => usdt_price,
148148
AcceptedFundingAsset::USDC => usdc_price,
149149
AcceptedFundingAsset::DOT => dot_price,
150+
AcceptedFundingAsset::WETH => todo!()
150151
};
151152

152153
let mut project_metadata = default_project_metadata.clone();
@@ -2270,19 +2271,19 @@ mod end_auction_extrinsic {
22702271
let mut project_metadata = default_project_metadata(ISSUER_1);
22712272
project_metadata.total_allocation_size = 100_000 * CT_UNIT;
22722273
project_metadata.participation_currencies =
2273-
bounded_vec![AcceptedFundingAsset::USDT, AcceptedFundingAsset::USDC, AcceptedFundingAsset::DOT,];
2274+
bounded_vec![AcceptedFundingAsset::USDT, AcceptedFundingAsset::USDC, AcceptedFundingAsset::DOT, AcceptedFundingAsset::WETH];
22742275

22752276
// overfund with plmc
22762277
let plmc_fundings = accounts
22772278
.iter()
22782279
.map(|acc| UserToPLMCBalance { account: *acc, plmc_amount: PLMC * 1_000_000 })
22792280
.collect_vec();
22802281

2281-
let fundings = [AcceptedFundingAsset::USDT, AcceptedFundingAsset::USDC, AcceptedFundingAsset::DOT];
2282+
let fundings = [AcceptedFundingAsset::USDT, AcceptedFundingAsset::USDC, AcceptedFundingAsset::DOT, AcceptedFundingAsset::WETH];
22822283
assert_eq!(fundings.len(), AcceptedFundingAsset::VARIANT_COUNT);
22832284
let mut fundings = fundings.into_iter().cycle();
22842285

2285-
let usdt_fundings = accounts
2286+
let funding_asset_mints = accounts
22862287
.iter()
22872288
.map(|acc| {
22882289
let accepted_asset = fundings.next().unwrap();
@@ -2293,17 +2294,17 @@ mod end_auction_extrinsic {
22932294
})
22942295
.collect_vec();
22952296
inst.mint_plmc_to(plmc_fundings);
2296-
inst.mint_funding_asset_to(usdt_fundings);
2297+
inst.mint_funding_asset_to(funding_asset_mints);
22972298

22982299
let project_id = inst.create_auctioning_project(project_metadata, ISSUER_1, None, default_evaluations());
22992300

23002301
let bids = vec![
23012302
(ADAM, 10_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDT).into(),
23022303
(TOM, 20_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDC).into(),
23032304
(SOFIA, 20_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::DOT).into(),
2304-
(FRED, 10_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDT).into(),
2305-
(ANNA, 5_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDC).into(),
2306-
(DAMIAN, 5_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::DOT).into(),
2305+
(FRED, 10_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::WETH).into(),
2306+
(ANNA, 5_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDT).into(),
2307+
(DAMIAN, 5_000 * CT_UNIT, ParticipationMode::Classic(1), AcceptedFundingAsset::USDC).into(),
23072308
];
23082309

23092310
inst.bid_for_users(project_id, bids).unwrap();

‎pallets/funding/src/tests/4_contribution.rs

+1
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ mod round_flow {
210210
AcceptedFundingAsset::USDT => usdt_price,
211211
AcceptedFundingAsset::USDC => usdc_price,
212212
AcceptedFundingAsset::DOT => dot_price,
213+
AcceptedFundingAsset::WETH => todo!(),
213214
};
214215

215216
let mut project_metadata = default_project_metadata.clone();

‎pallets/funding/src/tests/misc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use super::*;
44
mod helper_functions {
55
use super::*;
66
use polimec_common::USD_DECIMALS;
7-
use sp_core::{ecdsa, hexdisplay::AsBytesRef, keccak_256, sr25519, Pair};
87

98
#[test]
109
fn test_usd_price_decimal_aware() {

‎pallets/funding/src/types.rs

+3
Original file line numberDiff line numberDiff line change
@@ -652,13 +652,16 @@ pub mod inner {
652652
USDC,
653653
#[codec(index = 2)]
654654
DOT,
655+
#[codec(index = 3)]
656+
WETH,
655657
}
656658
impl AcceptedFundingAsset {
657659
pub const fn id(&self) -> u32 {
658660
match self {
659661
AcceptedFundingAsset::USDT => 1984,
660662
AcceptedFundingAsset::DOT => 10,
661663
AcceptedFundingAsset::USDC => 1337,
664+
AcceptedFundingAsset::WETH => 10_000,
662665
}
663666
}
664667
}

‎pallets/oracle-ocw/src/mock.rs

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl Convert<(AssetName, FixedU128), (OracleKey, OracleValue)> for AssetPriceCon
105105
AssetName::USDC => (1337, price),
106106
AssetName::USDT => (1984, price),
107107
AssetName::PLMC => (3344, price),
108+
AssetName::WETH => (10_000, price),
108109
}
109110
}
110111
}

‎pallets/oracle-ocw/src/types.rs

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ pub enum AssetName {
3030
USDC,
3131
DOT,
3232
PLMC,
33+
WETH,
3334
}
3435

3536
#[derive(Debug, Clone, Copy)]
@@ -131,6 +132,7 @@ impl FetchPrice for KrakenFetcher {
131132
AssetName::DOT => "https://api.kraken.com/0/public/OHLC?pair=DOTUSD&interval=1",
132133
AssetName::USDC => "https://api.kraken.com/0/public/OHLC?pair=USDCUSD&interval=1",
133134
AssetName::PLMC => "",
135+
AssetName::WETH => ""
134136
}
135137
}
136138
}
@@ -224,6 +226,7 @@ impl FetchPrice for BitStampFetcher {
224226
AssetName::DOT => "https://www.bitstamp.net/api/v2/ohlc/dotusd/?step=60&limit=15",
225227
AssetName::USDC => "https://www.bitstamp.net/api/v2/ohlc/usdcusd/?step=60&limit=15",
226228
AssetName::PLMC => "",
229+
AssetName::WETH => ""
227230
}
228231
}
229232
}

‎runtimes/polimec/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ scale-info = { workspace= true, default-features = false, features = [
2525
"derive",
2626
] }
2727

28+
lazy_static = "1.5.0"
29+
2830
# Uncomment this and the std feature below to see variables instead of <wasm:stripped> in the console output
2931
#sp-debug-derive = { workspace = true, features = ["force-debug"]}
3032

‎runtimes/polimec/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ parameter_types! {
837837
pub const ExpiresIn: Moment = 1000 * 60; // 1 mins
838838
pub const MaxHasDispatchedSize: u32 = 20;
839839
pub RootOperatorAccountId: AccountId = AccountId::from([0xffu8; 32]);
840-
pub const MaxFeedValues: u32 = 4; // max 4 values allowd to feed in one call (USDT, USDC, DOT, PLMC).
840+
pub const MaxFeedValues: u32 = AcceptedFundingAsset::VARIANT_COUNT as u32 + 1; // Funding asset prices + PLMC
841841
}
842842

843843
impl orml_oracle::Config for Runtime {
@@ -1708,9 +1708,9 @@ impl_runtime_apis! {
17081708
fn query_acceptable_payment_assets(xcm_version: xcm::Version) -> Result<Vec<VersionedAssetId>, XcmPaymentApiError> {
17091709
let acceptable_assets = vec![
17101710
xcm_config::HereLocation::get().into(),
1711-
xcm_config::DotLocation::get().into(),
1712-
xcm_config::UsdtLocation::get().into(),
1713-
xcm_config::UsdcLocation::get().into()
1711+
xcm_config::DOTLocation::get().into(),
1712+
xcm_config::USDTLocation::get().into(),
1713+
xcm_config::USDCLocation::get().into()
17141714
];
17151715

17161716
PolkadotXcm::query_acceptable_payment_assets(xcm_version, acceptable_assets)

0 commit comments

Comments
 (0)