Skip to content

Commit

Permalink
chore: update submodule (#1957)
Browse files Browse the repository at this point in the history
* chore: update submodule

* fix: sync deploy setup

* fix: add market ratio setup necessary for investments

* fix: ITs

* docs: fix
  • Loading branch information
wischli authored Aug 13, 2024
1 parent ffed149 commit 3def5e9
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 46 deletions.
7 changes: 3 additions & 4 deletions runtime/common/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND;
// block_gas_limit.saturating_div(MAX_POV_SIZE)
// };
//
// NOTE: The above results in a value of 2. AS this factor is a divisor
// generating a a storage limit we are conservative and use the value that
// moonbeam is using in their staging environment
// (https://github.com/moonbeam-foundation/moonbeam/blob/973015c376e8741073013094be88e7c58c716a70/runtime/moonriver/src/lib.rs#L408)
// NOTE: The above results in a value of 2. As this factor is a divisor
// generating a storage limit we are conservative and use the value that
// moonbeam is using in their staging environment <https://github.com/moonbeam-foundation/moonbeam/blob/973015c376e8741073013094be88e7c58c716a70/runtime/moonriver/src/lib.rs#L408>
pub const GAS_LIMIT_POV_SIZE_RATIO: u64 = 4;

// pub const GasLimitStorageGrowthRatio: u64 =
Expand Down
24 changes: 23 additions & 1 deletion runtime/integration-tests/src/cases/liquidity_pools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub const DEFAULT_OTHER_DOMAIN_ADDRESS: DomainAddress =

pub type LiquidityPoolMessage = Message;

mod utils {
pub mod utils {
use cfg_types::oracles::OracleKey;
use runtime_common::oracle::Feeder;

Expand Down Expand Up @@ -608,6 +608,28 @@ mod utils {
amount_foreign_denominated
}

/// Adds bidirectional trading pairs with conversion ratio one.
pub fn enable_symmetric_trading_pair<T: Runtime>(
currency_1: CurrencyId,
currency_2: CurrencyId,
pool_admin: AccountId,
pool_id: PoolId,
) {
assert_ok!(pallet_order_book::Pallet::<T>::set_market_feeder(
<T as frame_system::Config>::RuntimeOrigin::root(),
Feeder::root(),
));
crate::utils::oracle::update_feeders::<T>(pool_admin, pool_id, [Feeder::root()]);
crate::utils::oracle::feed_from_root::<T>(
OracleKey::ConversionRatio(currency_1, currency_2),
Ratio::one(),
);
crate::utils::oracle::feed_from_root::<T>(
OracleKey::ConversionRatio(currency_2, currency_1),
Ratio::one(),
);
}

pub fn outbound_message_dispatched<T: Runtime>(f: impl Fn() -> ()) -> bool {
let events_before = frame_system::Pallet::<T>::events();

Expand Down
2 changes: 2 additions & 0 deletions runtime/integration-tests/src/cases/lp/investments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ mod with_pool_currency {

env.state_mut(|evm| {
utils::cancel(evm, Keyring::TrancheInvestor(1), names::POOL_C_T_1_USDC);

lp_utils::process_gateway_message::<T>(lp_utils::verify_gateway_message_success::<T>);
});

env.pass(Blocks::ByNumber(1));
Expand Down
36 changes: 6 additions & 30 deletions runtime/integration-tests/src/cases/lp/pool_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// GNU General Public License for more details.

use cfg_primitives::{AccountId, Balance, PoolId, SECONDS_PER_YEAR};
use cfg_traits::{PoolMetadata, TimeAsSecs, TrancheTokenPrice};
use cfg_traits::{PoolMetadata, TrancheTokenPrice};
use cfg_types::{
domain_address::{Domain, DomainAddress},
permissions::PoolRole,
Expand Down Expand Up @@ -147,20 +147,16 @@ fn add_pool<T: Runtime>() {

utils::process_gateway_message::<T>(utils::verify_gateway_message_success::<T>);

let creation_time = <pallet_timestamp::Pallet<T> as TimeAsSecs>::now();

// Compare the pool.created_at field that is returned
let evm_pool_time = Decoder::<Uint>::decode(
assert!(Decoder::<bool>::decode(
&evm.view(
Keyring::Alice,
names::POOL_MANAGER,
"pools",
"isPoolActive",
Some(&[Token::Uint(Uint::from(POOL))]),
)
.unwrap()
.value,
);
assert_eq!(evm_pool_time, Uint::from(creation_time));
.value
));
});

env.state_mut(|evm| {
Expand Down Expand Up @@ -466,6 +462,7 @@ fn update_tranche_token_metadata<T: Runtime>() {
super::setup_currencies(evm);
super::setup_pools(evm);
super::setup_tranches(evm);
super::setup_market_ratios::<T>();
});

let decimals_new = 42;
Expand Down Expand Up @@ -563,27 +560,6 @@ fn update_tranche_token_price<T: Runtime>() {
super::setup_tranches(evm);
});

// Neither price nor computed exists yet
env.state(|evm| {
let (price_evm, computed_evm) = Decoder::<(u128, u64)>::decode(
&evm.view(
Keyring::Alice,
names::POOL_MANAGER,
"getTranchePrice",
Some(&[
Token::Uint(Uint::from(POOL_A)),
Token::FixedBytes(pool_a_tranche_1_id::<T>().to_vec()),
Token::Address(evm.deployed(names::USDC).address()),
]),
)
.unwrap()
.value,
);

assert_eq!(price_evm, 0);
assert_eq!(computed_evm, 0);
});

let (price, last_updated) = env.state_mut(|_evm| {
let price =
<pallet_pool_system::Pallet<T> as TrancheTokenPrice<AccountId, CurrencyId>>::get_price(
Expand Down
53 changes: 44 additions & 9 deletions runtime/integration-tests/src/cases/lp/setup_evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ pub fn rely<T: Runtime>(evm: &mut <RuntimeEnv<T> as EnvEvmExtension<T>>::EvmEnv)
.unwrap(); */

// Rely on pool manager
evm.call(
Keyring::Alice,
Default::default(),
names::GAS_SERVICE,
"rely",
Some(&[Token::Address(evm.deployed(names::POOL_MANAGER).address())]),
)
.unwrap();
evm.call(
Keyring::Alice,
Default::default(),
Expand Down Expand Up @@ -124,6 +116,14 @@ pub fn rely<T: Runtime>(evm: &mut <RuntimeEnv<T> as EnvEvmExtension<T>>::EvmEnv)
Some(&[Token::Address(evm.deployed(names::ROOT).address())]),
)
.unwrap();
evm.call(
Keyring::Alice,
Default::default(),
names::TRANSFER_PROXY_FACTORY,
"rely",
Some(&[Token::Address(evm.deployed(names::ROOT).address())]),
)
.unwrap();
evm.call(
Keyring::Alice,
Default::default(),
Expand Down Expand Up @@ -278,6 +278,30 @@ pub fn file<T: Runtime>(evm: &mut <RuntimeEnv<T> as EnvEvmExtension<T>>::EvmEnv)
]),
)
.unwrap();

evm.call(
Keyring::Alice,
Default::default(),
names::GATEWAY,
"file",
Some(&[
Token::FixedBytes("payers".as_bytes().to_vec()),
Token::Address(evm.deployed(names::ROUTER).address()),
Token::Bool(true),
]),
)
.unwrap();
evm.call(
Keyring::Alice,
Default::default(),
names::TRANSFER_PROXY_FACTORY,
"file",
Some(&[
Token::FixedBytes("poolManager".as_bytes().to_vec()),
Token::Address(evm.deployed(names::POOL_MANAGER).address()),
]),
)
.unwrap();
}

/// Replicate Deployer.sol function `wire`
Expand Down Expand Up @@ -353,6 +377,14 @@ pub fn remove_deployer_access<T: Runtime>(evm: &mut <RuntimeEnv<T> as EnvEvmExte
Some(&[Token::Address(Keyring::Alice.into())]),
)
.unwrap();
evm.call(
Keyring::Alice,
Default::default(),
names::TRANSFER_PROXY_FACTORY,
"deny",
Some(&[Token::Address(Keyring::Alice.into())]),
)
.unwrap();
evm.call(
Keyring::Alice,
Default::default(),
Expand Down Expand Up @@ -530,7 +562,10 @@ pub fn deployer_script<T: Runtime>(evm: &mut <RuntimeEnv<T> as EnvEvmExtension<T
contracts::TRANSFER_PROXY_FACTORY,
names::TRANSFER_PROXY_FACTORY,
Keyring::Alice,
Some(&[Token::Address(evm.deployed(names::POOL_MANAGER).address())]),
Some(&[
Token::Address(evm.deployed(names::ROOT).address()),
Token::Address(Keyring::Alice.into()),
]),
);
evm.deploy(
contracts::GAS_SERVICE,
Expand Down
71 changes: 70 additions & 1 deletion runtime/integration-tests/src/cases/lp/setup_lp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// GNU General Public License for more details.

use super::*;
use crate::cases::lp::utils::pool_c_tranche_1_id;

pub fn setup_full<T: Runtime>() -> impl EnvEvmExtension<T> {
setup::<T, _>(|evm| {
Expand All @@ -19,7 +20,8 @@ pub fn setup_full<T: Runtime>() -> impl EnvEvmExtension<T> {
setup_tranches(evm);
setup_investment_currencies(evm);
setup_deploy_lps(evm);
setup_investors(evm)
setup_investors(evm);
setup_market_ratios::<T>();
})
}

Expand Down Expand Up @@ -642,6 +644,7 @@ pub fn setup_currencies<T: Runtime>(evm: &mut impl EvmEnv<T>) {
meta.location = Some(utils::lp_asset_location::<T>(
evm.deployed(names::USDC).address(),
));
meta.additional.local_representation = Some(LocalUSDC.id().try_into().unwrap())
});

register_currency::<T>(DAI, |meta| {
Expand Down Expand Up @@ -930,3 +933,69 @@ pub fn setup_investors<T: Runtime>(evm: &mut impl EvmEnv<T>) {

utils::process_gateway_message::<T>(utils::verify_gateway_message_success::<T>);
}

/// Setup symmetric trading pairs and market ratios
///
/// NOTE: Necessary in order to be able to invest
pub fn setup_market_ratios<T: Runtime>() {
for currency_id in [USDC.id(), FRAX.id(), DAI.id()] {
crate::cases::liquidity_pools::utils::enable_symmetric_trading_pair::<T>(
pallet_foreign_investments::pool_currency_of::<T>((POOL_A, pool_a_tranche_1_id::<T>()))
.unwrap(),
currency_id,
Keyring::Admin.id(),
POOL_A,
);
assert_ok!(pallet_liquidity_pools::Pallet::<T>::update_token_price(
OriginFor::<T>::signed(Keyring::Alice.into()),
POOL_A,
pool_a_tranche_1_id::<T>(),
currency_id,
Domain::EVM(EVM_DOMAIN_CHAIN_ID)
));

crate::cases::liquidity_pools::utils::enable_symmetric_trading_pair::<T>(
pallet_foreign_investments::pool_currency_of::<T>((POOL_B, pool_b_tranche_1_id::<T>()))
.unwrap(),
currency_id,
Keyring::Admin.id(),
POOL_B,
);
assert_ok!(pallet_liquidity_pools::Pallet::<T>::update_token_price(
OriginFor::<T>::signed(Keyring::Alice.into()),
POOL_B,
pool_b_tranche_1_id::<T>(),
currency_id,
Domain::EVM(EVM_DOMAIN_CHAIN_ID)
));
crate::cases::liquidity_pools::utils::enable_symmetric_trading_pair::<T>(
pallet_foreign_investments::pool_currency_of::<T>((POOL_B, pool_b_tranche_2_id::<T>()))
.unwrap(),
currency_id,
Keyring::Admin.id(),
POOL_B,
);
assert_ok!(pallet_liquidity_pools::Pallet::<T>::update_token_price(
OriginFor::<T>::signed(Keyring::Alice.into()),
POOL_B,
pool_b_tranche_2_id::<T>(),
currency_id,
Domain::EVM(EVM_DOMAIN_CHAIN_ID)
));

crate::cases::liquidity_pools::utils::enable_symmetric_trading_pair::<T>(
pallet_foreign_investments::pool_currency_of::<T>((POOL_C, pool_c_tranche_1_id::<T>()))
.unwrap(),
currency_id,
Keyring::Admin.id(),
POOL_C,
);
assert_ok!(pallet_liquidity_pools::Pallet::<T>::update_token_price(
OriginFor::<T>::signed(Keyring::Alice.into()),
POOL_C,
pool_c_tranche_1_id::<T>(),
currency_id,
Domain::EVM(EVM_DOMAIN_CHAIN_ID)
));
}
}
2 changes: 1 addition & 1 deletion runtime/integration-tests/submodules/liquidity-pools
Submodule liquidity-pools updated 123 files

0 comments on commit 3def5e9

Please sign in to comment.