Skip to content

Commit

Permalink
Merge branch 'main' into upgrade-gh-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
gpmayorga authored Jun 13, 2024
2 parents e6ba502 + 3b6a8c9 commit 8950949
Show file tree
Hide file tree
Showing 53 changed files with 5,070 additions and 831 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/sanity-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ concurrency:
group: 'tests-${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
permissions:
id-token: write
contents: read
id-token: write
contents: read
jobs:
test-n-lint:
name: ${{ matrix.target }}
runs-on: ubuntu-latest-8-cores
strategy:
matrix:
target: [test-general, test-integration,
lint-fmt, lint-clippy, cargo-build, docs-build, lint-taplo]
target: [ test-general, test-integration,
lint-fmt, lint-clippy, cargo-build, docs-build, lint-taplo ]
steps:
- name: Check out code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4
with:
submodules: 'recursive'

- name: Prep build
uses: ./.github/actions/prep-ubuntu
Expand All @@ -27,6 +29,10 @@ jobs:
GWIP: ${{ secrets.GWIP_SCCACHE }}
GSA: ${{ secrets.GSA_SCCACHE }}

# Required for integration tests evm interaction
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1

- name: Runing cargo ${{ matrix.target }}
run: ./ci/run-check.sh
env:
Expand All @@ -38,10 +44,12 @@ jobs:
runs-on: ubuntu-latest #-4-cores
strategy:
matrix:
runtime: [altair, centrifuge]
runtime: [ altair, centrifuge ]
steps:
- name: Check out code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b #4.1.4
with:
submodules: 'recursive'

- name: Prep build
uses: ./.github/actions/prep-ubuntu
Expand All @@ -50,6 +58,7 @@ jobs:
GWIP: ${{ secrets.GWIP_SCCACHE }}
GSA: ${{ secrets.GSA_SCCACHE }}


- name: Runing cargo ${{ matrix.target }}
run: ./ci/run-check.sh
env:
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "runtime/integration-tests/submodules/liquidity-pools"]
path = runtime/integration-tests/submodules/liquidity-pools
url = [email protected]:centrifuge/liquidity-pools.git
branch = centrifuge-chain/release-v1.0
19 changes: 13 additions & 6 deletions Cargo.lock

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

12 changes: 11 additions & 1 deletion libs/types/src/domain_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ pub enum DomainAddress {
EVM(EVMChainId, [u8; 20]),
}

impl DomainAddress {
pub fn evm(chain_id: EVMChainId, address: [u8; 20]) -> Self {
Self::EVM(chain_id, address)
}

pub fn centrifuge(address: [u8; 32]) -> Self {
Self::Centrifuge(address)
}
}

impl From<DomainAddress> for Domain {
fn from(x: DomainAddress) -> Self {
match x {
Expand All @@ -100,7 +110,7 @@ impl DomainAddress {
pub fn address(&self) -> [u8; 32] {
match self.clone() {
Self::Centrifuge(x) => x,
Self::EVM(_, x) => vec_to_fixed_array(x.to_vec()),
Self::EVM(_, x) => vec_to_fixed_array(x),
}
}

Expand Down
6 changes: 3 additions & 3 deletions libs/types/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,18 @@ pub struct GeneralCurrencyIndex<Index, Prefix> {
_phantom: PhantomData<Prefix>,
}

impl<Index, Prefix> TryInto<GeneralCurrencyIndex<Index, Prefix>> for CurrencyId
impl<Index, Prefix> TryFrom<CurrencyId> for GeneralCurrencyIndex<Index, Prefix>
where
Index: From<u128>,
Prefix: Get<[u8; 12]>,
{
type Error = DispatchError;

fn try_into(self) -> Result<GeneralCurrencyIndex<Index, Prefix>, Self::Error> {
fn try_from(value: CurrencyId) -> Result<GeneralCurrencyIndex<Index, Prefix>, Self::Error> {
let mut bytes = [0u8; 16];
bytes[..12].copy_from_slice(&Prefix::get());

let currency_bytes: [u8; 4] = match &self {
let currency_bytes: [u8; 4] = match &value {
CurrencyId::ForeignAsset(id32) => Ok(id32.to_be_bytes()),
_ => Err(DispatchError::Token(TokenError::Unsupported)),
}?;
Expand Down
6 changes: 3 additions & 3 deletions libs/utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ use sp_std::{cmp::min, vec::Vec};
/// Build a fixed-size array using as many elements from `src` as possible
/// without overflowing and ensuring that the array is 0 padded in the case
/// where `src.len()` is smaller than S.
pub fn vec_to_fixed_array<const S: usize>(src: Vec<u8>) -> [u8; S] {
pub fn vec_to_fixed_array<const S: usize>(src: impl AsRef<[u8]>) -> [u8; S] {
let mut dest = [0; S];
let len = min(src.len(), S);
dest[..len].copy_from_slice(&src.as_slice()[..len]);
let len = min(src.as_ref().len(), S);
dest[..len].copy_from_slice(&src.as_ref()[..len]);

dest
}
Expand Down
34 changes: 6 additions & 28 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
// module level.
#![allow(clippy::derive_partial_eq_without_eq)]

use std::collections::BTreeMap;

use altair_runtime::constants::currency::{AIR, MILLI_AIR};
use cfg_primitives::{
currency_decimals, parachains, AccountId, AuraId, Balance, BlockNumber, CFG, MILLI_CFG,
Expand All @@ -36,11 +34,11 @@ use cfg_types::{
use cfg_utils::vec_to_fixed_array;
use cumulus_primitives_core::ParaId;
use hex_literal::hex;
use runtime_common::{account_conversion::AccountConverter, evm::precompile::H160Addresses};
use runtime_common::account_conversion::AccountConverter;
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::{ChainType, Properties};
use serde::{Deserialize, Serialize};
use sp_core::{sr25519, Encode, Pair, Public, H160};
use sp_core::{sr25519, Encode, Pair, Public};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
FixedPointNumber,
Expand All @@ -58,10 +56,7 @@ pub type CentrifugeChainSpec =
pub type DevelopmentChainSpec =
sc_service::GenericChainSpec<development_runtime::RuntimeGenesisConfig, Extensions>;

use altair_runtime::AltairPrecompiles;
use centrifuge_runtime::CentrifugePrecompiles;
use cfg_types::fixed_point::Rate;
use development_runtime::DevelopmentPrecompiles;

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
Expand Down Expand Up @@ -357,7 +352,7 @@ fn centrifuge_genesis(
"chainId": Into::<u32>::into(chain_id),
},
"evm": {
"accounts": precompile_account_genesis::<CentrifugePrecompiles>(),
"accounts": runtime_common::evm::precompile::utils::precompile_account_genesis::<centrifuge_runtime::Precompiles>(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
Expand Down Expand Up @@ -451,7 +446,7 @@ fn altair_genesis(
"chainId": Into::<u32>::into(chain_id),
},
"evm": {
"accounts": precompile_account_genesis::<AltairPrecompiles>(),
"accounts": runtime_common::evm::precompile::utils::precompile_account_genesis::<altair_runtime::Precompiles>(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
Expand Down Expand Up @@ -594,7 +589,7 @@ fn development_genesis(
"chainId": Into::<u32>::into(chain_id),
},
"evm": {
"accounts": precompile_account_genesis::<DevelopmentPrecompiles>(),
"accounts": runtime_common::evm::precompile::utils::precompile_account_genesis::<development_runtime::Precompiles>(),
},
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
Expand Down Expand Up @@ -648,7 +643,7 @@ fn asset_registry_assets() -> Vec<(CurrencyId, Vec<u8>)> {
Parachain(parachains::rococo::acala::ID),
GeneralKey {
length: parachains::rococo::acala::AUSD_KEY.to_vec().len() as u8,
data: vec_to_fixed_array(parachains::rococo::acala::AUSD_KEY.to_vec()),
data: vec_to_fixed_array(parachains::rococo::acala::AUSD_KEY),
},
],
))),
Expand Down Expand Up @@ -724,20 +719,3 @@ fn asset_registry_assets() -> Vec<(CurrencyId, Vec<u8>)> {
),
]
}

fn precompile_account_genesis<PrecompileSet: H160Addresses>(
) -> BTreeMap<H160, fp_evm::GenesisAccount> {
PrecompileSet::h160_addresses()
.map(|addr| {
(
addr,
fp_evm::GenesisAccount {
nonce: Default::default(),
balance: Default::default(),
storage: Default::default(),
code: runtime_common::evm::precompile::utils::REVERT_BYTECODE.to_vec(),
},
)
})
.collect()
}
2 changes: 1 addition & 1 deletion pallets/ethereum-transaction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub mod pallet {
}),
})?;

// NOTE: The Ethereuem side of things never returns a DispatchError
// NOTE: The Ethereum side of things never returns a DispatchError
// if the execution failed. But we can check that manually by
// querying the `Pending` storage of the pallet-ethereum.
let pending = pallet_ethereum::Pending::<T>::get();
Expand Down
6 changes: 4 additions & 2 deletions pallets/investments/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2510,15 +2510,17 @@ fn collecting_fully_works() {
#[allow(non_snake_case)]
let SINGLE_REDEEM_AMOUNT_C = 50 * CURRENCY;
#[allow(non_snake_case)]
let TOTAL_REDEEM_AMOUNT = SINGLE_REDEEM_AMOUNT_A + SINGLE_REDEEM_AMOUNT_B + SINGLE_REDEEM_AMOUNT_C;
let TOTAL_REDEEM_AMOUNT =
SINGLE_REDEEM_AMOUNT_A + SINGLE_REDEEM_AMOUNT_B + SINGLE_REDEEM_AMOUNT_C;
#[allow(non_snake_case)]
let SINGLE_INVEST_AMOUNT_A = 50 * CURRENCY;
#[allow(non_snake_case)]
let SINGLE_INVEST_AMOUNT_B = 50 * CURRENCY;
#[allow(non_snake_case)]
let SINGLE_INVEST_AMOUNT_C = 50 * CURRENCY;
#[allow(non_snake_case)]
let TOTAL_INVEST_AMOUNT = SINGLE_INVEST_AMOUNT_A + SINGLE_INVEST_AMOUNT_B + SINGLE_INVEST_AMOUNT_C;
let TOTAL_INVEST_AMOUNT =
SINGLE_INVEST_AMOUNT_A + SINGLE_INVEST_AMOUNT_B + SINGLE_INVEST_AMOUNT_C;
#[allow(non_snake_case)]
let FULL_FULFILL = FulfillmentWithPrice {
of_amount: Perquintill::one(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ pub struct SourceConverter {
pub domain: Domain,
}

impl SourceConverter {
pub fn new(domain: Domain) -> Self {
Self { domain }
}
}

impl SourceConverter {
pub fn try_convert(&self, maybe_address: &[u8]) -> Option<DomainAddress> {
match self.domain {
Expand Down
14 changes: 14 additions & 0 deletions pallets/liquidity-pools-gateway/routers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ where
pub _marker: PhantomData<T>,
}

impl<T> EVMRouter<T>
where
T: frame_system::Config + pallet_ethereum_transaction::Config + pallet_evm::Config,
OriginFor<T>:
From<pallet_ethereum::Origin> + Into<Result<pallet_ethereum::Origin, OriginFor<T>>>,
{
pub fn new(evm_domain: EVMDomain) -> Self {
Self {
evm_domain,
_marker: Default::default(),
}
}
}

impl<T> EVMRouter<T>
where
T: frame_system::Config + pallet_ethereum_transaction::Config + pallet_evm::Config,
Expand Down
13 changes: 13 additions & 0 deletions pallets/liquidity-pools-gateway/routers/src/routers/axelar_evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ where
OriginFor<T>:
From<pallet_ethereum::Origin> + Into<Result<pallet_ethereum::Origin, OriginFor<T>>>,
{
pub fn new(
router: EVMRouter<T>,
evm_chain: BoundedVec<u8, ConstU32<MAX_AXELAR_EVM_CHAIN_SIZE>>,
liquidity_pools_contract_address: H160,
) -> Self {
Self {
router,
evm_chain,
liquidity_pools_contract_address,
_marker: Default::default(),
}
}

/// Calls the init function on the EVM router.
pub fn do_init(&self) -> DispatchResult {
self.router.do_init()
Expand Down
8 changes: 4 additions & 4 deletions pallets/liquidity-pools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ pub mod pallet {
let investment_id = Self::derive_invest_id(pool_id, tranche_id)?;
let metadata = T::AssetRegistry::metadata(&investment_id.into())
.ok_or(Error::<T>::TrancheMetadataNotFound)?;
let token_name = vec_to_fixed_array(metadata.name.into_inner());
let token_symbol = vec_to_fixed_array(metadata.symbol.into_inner());
let token_name = vec_to_fixed_array(metadata.name);
let token_symbol = vec_to_fixed_array(metadata.symbol);

// Send the message to the domain
T::OutboundQueue::submit(
Expand Down Expand Up @@ -793,8 +793,8 @@ pub mod pallet {
let investment_id = Self::derive_invest_id(pool_id, tranche_id)?;
let metadata = T::AssetRegistry::metadata(&investment_id.into())
.ok_or(Error::<T>::TrancheMetadataNotFound)?;
let token_name = vec_to_fixed_array(metadata.name.into_inner());
let token_symbol = vec_to_fixed_array(metadata.symbol.into_inner());
let token_name = vec_to_fixed_array(metadata.name);
let token_symbol = vec_to_fixed_array(metadata.symbol);

T::OutboundQueue::submit(
who,
Expand Down
Loading

0 comments on commit 8950949

Please sign in to comment.