Skip to content

Commit

Permalink
Merge branch 'eth-rollup-develop' into feature/eth-upd-tests-governance
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexChetverov authored Jun 25, 2024
2 parents 01d6315 + 765c8f3 commit f814040
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 325 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/reusable-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ jobs:
fail-fast: false
matrix:
include:
# - command: "yarn test-parallel --max-workers=10"
# fast: false
- command: "yarn test-parallel --max-workers=10"
fast: false
- command: "yarn test-sequential-no-bootstrap"
fast: false
- command: "yarn test-seqgasless"
Expand All @@ -113,8 +113,8 @@ jobs:
fast: true
- command: "yarn test-sequential-autocompound"
fast: true
# - command: "yarn test-poolliquidity"
# fast: true
- command: "yarn test-poolliquidity"
fast: true
- command: "yarn test-governance"
fast: true
- command: "yarn test-multiswap"
Expand All @@ -128,7 +128,7 @@ jobs:
- command: "yarn test-parallel-3rdPartyRewards"
fast: true


runs-on: [e2e-gke]
timeout-minutes: 180
env:
Expand Down Expand Up @@ -214,7 +214,7 @@ jobs:
env:
NODE_OPTIONS: --max_old_space_size=12288


- name: Test Report
uses: dorny/[email protected]
continue-on-error: true
Expand Down Expand Up @@ -269,14 +269,14 @@ jobs:
with:
workload_identity_provider: '${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}'
service_account: '${{ secrets.GCP_SERVICE_ACCOUNT }}'

- name: Upload node storage data to GCP bucket
if: failure()
uses: google-github-actions/[email protected]
with:
process_gcloudignore: false
destination: mangata-node-ci-cache/${{ github.sha }}/${{ env.MATRIX_COMMAND_PATH }}

- name: Add GCP bucket URL link for stored node data on job failure
if: failure()
run: echo '[GCP Bucket link](https://console.cloud.google.com/storage/browser/mangata-node-ci-cache/${{ github.sha }}/${{ env.MATRIX_COMMAND_PATH }})' >> $GITHUB_STEP_SUMMARY
Expand Down
266 changes: 133 additions & 133 deletions Cargo.lock

Large diffs are not rendered by default.

266 changes: 133 additions & 133 deletions Cargo.toml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pallets/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ pub mod pallet {

ensure!(first_token_id != second_token_id, Error::<T>::SameToken);

ensure!(T::Currency::exists(first_token_id.into()), Error::<T>::TokenIdDoesNotExists);
ensure!(T::Currency::exists(second_token_id.into()), Error::<T>::TokenIdDoesNotExists);
ensure!(T::Currency::exists(first_token_id), Error::<T>::TokenIdDoesNotExists);
ensure!(T::Currency::exists(second_token_id), Error::<T>::TokenIdDoesNotExists);

ensure!(
ido_start > frame_system::Pallet::<T>::block_number(),
Expand Down
2 changes: 1 addition & 1 deletion pallets/issuance/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub mod pallet {
locked,
per_block,
T::TGEReleaseBegin::get().into(),
T::NativeCurrencyId::get().into(),
T::NativeCurrencyId::get(),
)
.is_ok()
{
Expand Down
47 changes: 32 additions & 15 deletions rollup/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,21 +140,38 @@ pub fn rollup_local_config(
// How many liquidity tokens they stake,
],
),
vec![(
RX_TOKEN_ID,
AssetMetadataOf {
decimals: 18,
name: BoundedVec::truncate_from(b"Gasp".to_vec()),
symbol: BoundedVec::truncate_from(b"GASP".to_vec()),
additional: Default::default(),
existential_deposit: Default::default(),
location: None,
},
Some(L1Asset::Ethereum(
array_bytes::hex2array("0x1317106Dd45FF0EB911e9F0aF78D63FBF9076f69")
.unwrap(),
)),
)],
vec![
(
RX_TOKEN_ID,
AssetMetadataOf {
decimals: 18,
name: BoundedVec::truncate_from(b"Gasp".to_vec()),
symbol: BoundedVec::truncate_from(b"GASP".to_vec()),
additional: Default::default(),
existential_deposit: Default::default(),
location: None,
},
Some(L1Asset::Ethereum(
array_bytes::hex2array("0x1317106Dd45FF0EB911e9F0aF78D63FBF9076f69")
.unwrap(),
)),
),
(
1,
AssetMetadataOf {
decimals: 18,
name: BoundedVec::truncate_from(b"Gasp Ethereum".to_vec()),
symbol: BoundedVec::truncate_from(b"GETH".to_vec()),
additional: Default::default(),
existential_deposit: Default::default(),
location: None,
},
Some(L1Asset::Ethereum(
array_bytes::hex2array("0x5748395867463837537395739375937493733457")
.unwrap(),
)),
),
],
initial_collators_as_sequencers,
eth_chain_id,
decode_url.clone(),
Expand Down
9 changes: 6 additions & 3 deletions rollup/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ impl pallet_utility_mangata::Config for Runtime {
}

use cfg::pallet_transaction_payment_mangata::{
FeeHelpers, OnChargeHandler, OneCurrencyOnChargeAdapter, ToAuthor, TriggerEvent,
FeeHelpers, OnChargeHandler, ToAuthor, TriggerEvent, TwoCurrencyOnChargeAdapter,
};

// TODO: renaming foo causes compiler error
Expand All @@ -359,10 +359,11 @@ impl<T> TriggerEvent<T::AccountId> for Foo<T>
where
T: frame_system::Config<AccountId = sp_runtime::AccountId20>,
{
fn trigger(who: T::AccountId, fee: u128, tip: u128) {
fn trigger(who: T::AccountId, token_id: TokenId, fee: u128, tip: u128) {
TransactionPayment::deposit_event(
pallet_transaction_payment_mangata::Event::<Runtime>::TransactionFeePaid {
who,
token_id,
actual_fee: fee,
tip,
},
Expand Down Expand Up @@ -438,10 +439,12 @@ impl ExtendedCall for RuntimeCall {
}
}

pub type OnChargeTransactionHandler<T> = OneCurrencyOnChargeAdapter<
pub type OnChargeTransactionHandler<T> = TwoCurrencyOnChargeAdapter<
orml_tokens::MultiTokenCurrencyAdapter<T>,
ToAuthor<T>,
tokens::RxTokenId,
tokens::EthTokenId,
frame_support::traits::ConstU128<10_000_000>,
Foo<T>,
>;

Expand Down
77 changes: 47 additions & 30 deletions rollup/runtime/src/runtime_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ pub mod types {
pub mod tokens {
use super::*;
pub const RX_TOKEN_ID: TokenId = 0;
pub const ETH_TOKEN_ID: TokenId = 1;

parameter_types! {
pub const RxTokenId: TokenId = RX_TOKEN_ID;
pub const EthTokenId: TokenId = ETH_TOKEN_ID;
}
}

Expand Down Expand Up @@ -924,48 +926,50 @@ pub mod config {
}

#[derive(Encode, Decode, Clone, TypeInfo)]
pub struct OneCurrencyOnChargeAdapter<C, OU, T1, TE>(PhantomData<(C, OU, T1, TE)>);
pub struct TwoCurrencyOnChargeAdapter<C, OU, T1, T2, SF, TE>(
PhantomData<(C, OU, T1, T2, SF, TE)>,
);

type NegativeImbalanceOf<C, T> =
<C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::NegativeImbalance;

pub trait TriggerEvent<AccountIdT> {
fn trigger(who: AccountIdT, fee: u128, tip: u128);
fn trigger(who: AccountIdT, token_id: TokenId, fee: u128, tip: u128);
}

/// Default implementation for a Currency and an OnUnbalanced handler.
///
/// The unbalance handler is given 2 unbalanceds in [`OnUnbalanced::on_unbalanceds`]: fee and
/// then tip.
impl<T, C, OU, T1, TE> OnChargeTransaction<T> for OneCurrencyOnChargeAdapter<C, OU, T1, TE>
impl<T, C, OU, T1, T2, SF, TE> OnChargeTransaction<T> for TwoCurrencyOnChargeAdapter<C, OU, T1, T2, SF, TE>
where
T: pallet_transaction_payment_mangata::Config,
// TE: TriggerEvent<<T as frame_system::Config>::AccountId>,
TE: TriggerEvent<<T as frame_system::Config>::AccountId>,
// <<T as pallet_transaction_payment_mangata::Config>::OnChargeTransaction as OnChargeTransaction<T>>::Balance : From<u128>,
T::LengthToFee: frame_support::weights::WeightToFee<
Balance = <C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance,
>,
C: MultiTokenCurrency<<T as frame_system::Config>::AccountId>,
C::PositiveImbalance: Imbalance<
<C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance,
Opposite = C::NegativeImbalance,
>,
C::NegativeImbalance: Imbalance<
<C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance,
Opposite = C::PositiveImbalance,
>,
OU: OnMultiTokenUnbalanced<C::CurrencyId, NegativeImbalanceOf<C, T>>,
NegativeImbalanceOf<C, T>: MultiTokenImbalanceWithZeroTrait<TokenId>,
<C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance:
scale_info::TypeInfo,
T1: Get<C::CurrencyId>,
// Balance: From<<C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance>,
// Balance: From<TokenId>,
// sp_runtime::AccountId20: From<<T as frame_system::Config>::AccountId>,
T: pallet_transaction_payment_mangata::Config,
TE: TriggerEvent<<T as frame_system::Config>::AccountId>,
<C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance: From<u128>,
C::CurrencyId: Into<u32>,
T::LengthToFee: frame_support::weights::WeightToFee<
Balance = <C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance,
>,
C: MultiTokenCurrency<<T as frame_system::Config>::AccountId>,
C::PositiveImbalance: Imbalance<
<C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance,
Opposite = C::NegativeImbalance,
>,
C::NegativeImbalance: Imbalance<
<C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance,
Opposite = C::PositiveImbalance,
>,
OU: OnMultiTokenUnbalanced<C::CurrencyId, NegativeImbalanceOf<C, T>>,
NegativeImbalanceOf<C, T>: MultiTokenImbalanceWithZeroTrait<TokenId>,
<C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance:
scale_info::TypeInfo,
T1: Get<C::CurrencyId>,
T2: Get<C::CurrencyId>,
SF: Get<u128>,
{
type LiquidityInfo = Option<LiquidityInfoEnum<C, T>>;
type Balance = <C as MultiTokenCurrency<<T as frame_system::Config>::AccountId>>::Balance;

/// Withdraw the predicted fee from the transaction origin.
///
/// Note: The `fee` already includes the `tip`.
Expand Down Expand Up @@ -995,7 +999,16 @@ pub mod config {
) {
Ok(imbalance) => Ok(Some(LiquidityInfoEnum::Imbalance((T1::get(), imbalance)))),
// TODO make sure atleast 1 planck KSM is charged
Err(_) => Err(InvalidTransaction::Payment.into()),
Err(_) => match C::withdraw(
T2::get(),
who,
fee / SF::get().into(),
withdraw_reason,
ExistenceRequirement::KeepAlive,
) {
Ok(imbalance) => Ok(Some(LiquidityInfoEnum::Imbalance((T2::get(), imbalance)))),
Err(_) => Err(InvalidTransaction::Payment.into()),
},
}
}

Expand All @@ -1013,6 +1026,11 @@ pub mod config {
already_withdrawn: Self::LiquidityInfo,
) -> Result<(), TransactionValidityError> {
if let Some(LiquidityInfoEnum::Imbalance((token_id, paid))) = already_withdrawn {
let (corrected_fee, tip) = if token_id == T2::get() {
(corrected_fee / SF::get().into(), tip / SF::get().into())
} else {
(corrected_fee, tip)
};
// Calculate how much refund we should return
let refund_amount = paid.peek().saturating_sub(corrected_fee);
// refund to the the account that paid the fees. If this fails, the
Expand All @@ -1028,8 +1046,7 @@ pub mod config {
// Call someone else to handle the imbalance (fee and tip separately)
let (tip_imb, fee) = adjusted_paid.split(tip);
OU::on_unbalanceds(token_id, Some(fee).into_iter().chain(Some(tip_imb)));

TE::trigger(who.clone(), corrected_fee.into(), tip.into());
TE::trigger(who.clone(), token_id.into(), corrected_fee.into(), tip.into());
}
Ok(())
}
Expand Down

0 comments on commit f814040

Please sign in to comment.