Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fungibles API #433

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ polkadot-parachain-primitives.workspace = true
pallet-collective.workspace = true
pallet-elections-phragmen.workspace = true
pallet-message-queue.workspace = true

cumulus-primitives-core.workspace = true
cumulus-pallet-xcm.workspace = true

Expand Down Expand Up @@ -84,6 +83,7 @@ pallet-skip-feeless-payment.workspace = true
xcm-fee-payment-runtime-api.workspace = true
hex-literal.workspace = true
hex.workspace = true
assets-common.workspace = true

# Runtimes
polkadot-runtime.workspace = true
Expand Down
16 changes: 8 additions & 8 deletions integration-tests/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use frame_support::BoundedVec;
use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
use pallet_parachain_staking::inflation::{perbill_annual_to_perbill_round, BLOCKS_PER_YEAR};
pub use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber};
use polimec_common::assets::AcceptedFundingAsset;
use polimec_runtime::{pallet_parachain_staking::Range, PLMC};
use polkadot_primitives::{AssignmentId, ValidatorId};
pub use polkadot_runtime_parachains::configuration::HostConfiguration;
Expand Down Expand Up @@ -436,9 +437,8 @@ pub mod penpal {
pub mod polimec {
use super::*;
use crate::{PolimecNet, PolimecOrigin, PolimecRuntime};
use pallet_funding::AcceptedFundingAsset;
use polimec_runtime::{BlockchainOperationTreasury, TreasuryAccount};
use xcm::v4::Parent;
use xcm::v4::{Location, Parent};
use xcm_emulator::TestExt;

pub const PARA_ID: u32 = 3344;
Expand All @@ -454,10 +454,10 @@ pub mod polimec {
let dot = (AcceptedFundingAsset::DOT.id(), prices.dot);
let usdc = (AcceptedFundingAsset::USDC.id(), prices.usdc);
let usdt = (AcceptedFundingAsset::USDT.id(), prices.usdt);
let plmc = (polimec_common::PLMC_FOREIGN_ID, prices.plmc);
let plmc = (Location::here(), prices.plmc);
let weth = (AcceptedFundingAsset::WETH.id(), prices.weth);

let values: BoundedVec<(u32, FixedU128), <PolimecRuntime as orml_oracle::Config>::MaxFeedValues> =
let values: BoundedVec<(Location, FixedU128), <PolimecRuntime as orml_oracle::Config>::MaxFeedValues> =
vec![dot, usdc, usdt, plmc, weth].try_into().expect("benchmarks can panic");
let alice: [u8; 32] = [
212, 53, 147, 199, 21, 253, 211, 28, 97, 20, 26, 189, 4, 169, 159, 214, 130, 44, 133, 88, 133, 76, 205,
Expand Down Expand Up @@ -524,15 +524,15 @@ pub mod polimec {
contribution_tokens: Default::default(),
foreign_assets: polimec_runtime::ForeignAssetsConfig {
assets: vec![
(dot_asset_id, alice_account.clone(), true, 100_000_000),
(usdt_asset_id, alice_account.clone(), true, 70_000),
(usdc_asset_id, alice_account.clone(), true, 70_000),
(dot_asset_id.clone(), alice_account.clone(), true, 100_000_000),
(usdt_asset_id.clone(), alice_account.clone(), true, 70_000),
(usdc_asset_id.clone(), alice_account.clone(), true, 70_000),
(weth_asset_id, alice_account.clone(), true, 0_000_041_000_000_000_000),
],
metadata: vec![
(dot_asset_id, "Local DOT".as_bytes().to_vec(), "DOT".as_bytes().to_vec(), 10),
(usdt_asset_id, "Local USDT".as_bytes().to_vec(), "USDT".as_bytes().to_vec(), 6),
(usdc_asset_id, "Local USDC".as_bytes().to_vec(), "USDC".as_bytes().to_vec(), 6),
(usdc_asset_id.clone(), "Local USDC".as_bytes().to_vec(), "USDC".as_bytes().to_vec(), 6),
(usdc_asset_id, "Local WETH".as_bytes().to_vec(), "WETH".as_bytes().to_vec(), 18),
],
accounts: vec![],
Expand Down
1 change: 1 addition & 0 deletions integration-tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ pub mod shortcuts {

pub type PenpalAssets = <PenNet as PenpalParaPallet>::Assets;
pub type AssetHubAssets = <AssetNet as AssetHubParaPallet>::LocalAssets;
pub type AssetHubForeignAssets = <AssetNet as AssetHubParaPallet>::ForeignAssets;
pub type PolimecForeignAssets = <PolimecNet as PolimecParaPallet>::ForeignAssets;

pub type PolkadotOrigin = <PolkaNet as Chain>::RuntimeOrigin;
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 @@ -17,13 +17,13 @@ use crate::PolimecRuntime;
use frame_support::BoundedVec;
pub use pallet_funding::instantiator::{BidParams, ContributionParams, EvaluationParams};
use pallet_funding::{
AcceptedFundingAsset, BiddingTicketSizes, ContributingTicketSizes, CurrencyMetadata, ParticipantsAccountType,
ParticipationMode, PriceProviderOf, ProjectMetadata, ProjectMetadataOf, TicketSize,
BiddingTicketSizes, ContributingTicketSizes, CurrencyMetadata, ParticipantsAccountType, ParticipationMode,
PriceProviderOf, ProjectMetadata, ProjectMetadataOf, TicketSize,
};
use sp_arithmetic::{FixedPointNumber, Percent};

use macros::generate_accounts;
use polimec_common::{ProvideAssetPrice, USD_DECIMALS, USD_UNIT};
use polimec_common::{assets::AcceptedFundingAsset, ProvideAssetPrice, USD_DECIMALS, USD_UNIT};
use polimec_runtime::{AccountId, PLMC};
use sp_runtime::{traits::ConstU32, Perquintill};
use ParticipationMode::{Classic, OTM};
Expand Down
5 changes: 4 additions & 1 deletion integration-tests/src/tests/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ use itertools::Itertools;
use macros::generate_accounts;
use pallet_funding::{traits::VestingDurationCalculation, *};
use polimec_common::{
assets::{
AcceptedFundingAsset,
AcceptedFundingAsset::{DOT, USDC, USDT},
},
credentials::InvestorType,
migration_types::{MigrationStatus, ParticipationType},
ProvideAssetPrice, USD_DECIMALS, USD_UNIT,
Expand All @@ -35,7 +39,6 @@ use polimec_common_test_utils::{generate_did_from_account, get_mock_jwt, get_moc
use polimec_runtime::PLMC;
use sp_arithmetic::{FixedPointNumber, Percent, Perquintill};
use sp_runtime::FixedU128;
use AcceptedFundingAsset::{DOT, USDC, USDT};
use InvestorType::{Institutional, Professional, Retail};
use ParticipationMode::{Classic, OTM};

Expand Down
16 changes: 8 additions & 8 deletions integration-tests/src/tests/oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use crate::*;
use pallet_funding::AcceptedFundingAsset;
/// Tests for the oracle pallet integration.
/// Alice, Bob, Charlie are members of the OracleProvidersMembers.
/// Only members should be able to feed data into the oracle.
use parity_scale_codec::alloc::collections::HashMap;
use polimec_common::PLMC_FOREIGN_ID;
use polimec_common::assets::AcceptedFundingAsset;
use polimec_runtime::{Oracle, RuntimeOrigin};
use sp_runtime::{bounded_vec, BoundedVec, FixedU128};
use std::collections::BTreeMap;
use tests::defaults::*;

use AcceptedFundingAsset::{DOT, USDC, USDT, WETH};
fn values(
values: [f64; 5],
) -> BoundedVec<(u32, FixedU128), <polimec_runtime::Runtime as orml_oracle::Config<()>>::MaxFeedValues> {
) -> BoundedVec<(Location, FixedU128), <polimec_runtime::Runtime as orml_oracle::Config<()>>::MaxFeedValues> {
let [dot, usdc, usdt, weth, plmc] = values;
bounded_vec![
(DOT.id(), FixedU128::from_float(dot)),
(USDC.id(), FixedU128::from_float(usdc)),
(USDT.id(), FixedU128::from_float(usdt)),
(WETH.id(), FixedU128::from_float(weth)),
(PLMC_FOREIGN_ID, FixedU128::from_float(plmc))
(Location::here(), FixedU128::from_float(plmc))
]
}

Expand All @@ -55,12 +55,12 @@ fn members_can_feed_data() {
let charlie = PolimecNet::account_id_of(CHARLIE);
assert_ok!(Oracle::feed_values(RuntimeOrigin::signed(charlie.clone()), values([4.84, 1.0, 1.0, 2500.0, 0.4])));

let expected_values = HashMap::from([
let expected_values = BTreeMap::from([
(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)),
(PLMC_FOREIGN_ID, FixedU128::from_float(0.4)),
(Location::here(), FixedU128::from_float(0.4)),
]);

for (key, value) in Oracle::get_all_values() {
Expand Down Expand Up @@ -101,12 +101,12 @@ fn data_is_correctly_combined() {
));

// Default CombineData implementation is the median value
let expected_values = HashMap::from([
let expected_values = BTreeMap::from([
(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)),
(PLMC_FOREIGN_ID, FixedU128::from_float(0.22222)),
(Location::here(), FixedU128::from_float(0.22222)),
]);

for (key, value) in Oracle::get_all_values() {
Expand Down
10 changes: 6 additions & 4 deletions integration-tests/src/tests/otm_edge_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use crate::{
};
use frame_support::traits::fungibles::Inspect;
use macros::generate_accounts;
use pallet_funding::{traits::BondingRequirementCalculation, AcceptedFundingAsset, MultiplierOf, ParticipationMode};
use polimec_common::{credentials::InvestorType, ProvideAssetPrice, PLMC_DECIMALS, PLMC_FOREIGN_ID, USD_UNIT};
use pallet_funding::{traits::BondingRequirementCalculation, MultiplierOf, ParticipationMode};
use polimec_common::{
assets::AcceptedFundingAsset, credentials::InvestorType, ProvideAssetPrice, PLMC_DECIMALS, USD_UNIT,
};
use polimec_common_test_utils::{generate_did_from_account, get_mock_jwt_with_cid};
use sp_arithmetic::{FixedPointNumber, FixedU128};
use sp_core::bounded_vec;
Expand Down Expand Up @@ -42,7 +44,7 @@ fn otm_fee_below_min_amount_reverts() {
.unwrap();

let plmc_price = <PolimecRuntime as pallet_funding::Config>::PriceProvider::get_decimals_aware_price(
PLMC_FOREIGN_ID,
Location::here(),
6,
PLMC_DECIMALS,
)
Expand Down Expand Up @@ -132,7 +134,7 @@ fn after_otm_fee_user_goes_under_ed_reverts() {
);

let plmc_price = <PolimecRuntime as pallet_funding::Config>::PriceProvider::get_decimals_aware_price(
PLMC_FOREIGN_ID,
Location::here(),
6,
PLMC_DECIMALS,
)
Expand Down
Loading