Skip to content

Commit

Permalink
fix: anemoy migration catalyst + remove USDC suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
wischli committed Sep 29, 2023
1 parent 1698109 commit 0a9ef1c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 58 deletions.
32 changes: 16 additions & 16 deletions libs/types/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,32 +370,32 @@ pub mod usdc {

use super::*;

pub const MIN_SWAP_ORDER_AMOUNT_USDC: Balance = 10_000_000;
pub const DECIMALS_USDC: u32 = 6;
pub const EXISTENTIAL_DEPOSIT_USDC: Balance = 1000;
pub const MIN_SWAP_ORDER_AMOUNT: Balance = 10_000_000;
pub const DECIMALS: u32 = 6;
pub const EXISTENTIAL_DEPOSIT: Balance = 1000;

pub const CURRENCY_ID_DOT_NATIVE_USDC: CurrencyId = CurrencyId::ForeignAsset(6);
pub const CURRENCY_ID_LP_ETH_USDC: CurrencyId = CurrencyId::ForeignAsset(100_001);
pub const CURRENCY_ID_LP_ETH_GOERLI_USDC: CurrencyId = CurrencyId::ForeignAsset(100_001);
pub const CURRENCY_ID_LP_BASE_USDC: CurrencyId = CurrencyId::ForeignAsset(100_002);
pub const CURRENCY_ID_LP_ARB_USDC: CurrencyId = CurrencyId::ForeignAsset(100_004);
pub const CURRENCY_ID_LP_CELO_USDC: CurrencyId = CurrencyId::ForeignAsset(100_005);
pub const CURRENCY_ID_DOT_NATIVE: CurrencyId = CurrencyId::ForeignAsset(6);
pub const CURRENCY_ID_LP_ETH: CurrencyId = CurrencyId::ForeignAsset(100_001);
pub const CURRENCY_ID_LP_ETH_GOERLI: CurrencyId = CurrencyId::ForeignAsset(100_001);
pub const CURRENCY_ID_LP_BASE: CurrencyId = CurrencyId::ForeignAsset(100_002);
pub const CURRENCY_ID_LP_ARB: CurrencyId = CurrencyId::ForeignAsset(100_003);
pub const CURRENCY_ID_LP_CELO: CurrencyId = CurrencyId::ForeignAsset(100_004);

pub const CHAIN_ID_ETHEREUM_MAINNET: EVMChainId = 1;
pub const CHAIN_ID_ETH_GOERLI_TESTNET: EVMChainId = 5;
pub const CHAIN_ID_BASE_MAINNET: EVMChainId = 8453;
pub const CHAIN_ID_ARBITRUM_MAINNET: EVMChainId = 42_161;
pub const CHAIN_ID_CELO_MAINNET: EVMChainId = 42_220;

pub const CONTRACT_ETHEREUM_USDC: [u8; 20] =
pub const CONTRACT_ETHEREUM: [u8; 20] =
hex_literal::hex!("a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48");
pub const CONTRACT_ETH_GOERLI_USDC: [u8; 20] =
pub const CONTRACT_ETH_GOERLI: [u8; 20] =
hex_literal::hex!("07865c6e87b9f70255377e024ace6630c1eaa37f");
pub const CONTRACT_BASE_USDC: [u8; 20] =
pub const CONTRACT_BASE: [u8; 20] =
hex_literal::hex!("833589fCD6eDb6E08f4c7C32D4f71b54bdA02913");
pub const CONTRACT_ARBITRUM_USDC: [u8; 20] =
pub const CONTRACT_ARBITRUM: [u8; 20] =
hex_literal::hex!("af88d065e77c8cC2239327C5EDb3A432268e5831");
pub const CONTRACT_CELO_USDC: [u8; 20] =
pub const CONTRACT_CELO: [u8; 20] =
hex_literal::hex!("37f750B7cC259A2f741AF45294f6a16572CF5cAd");

/// The metadata generator for the LP wrapped USDC currencies
Expand All @@ -410,10 +410,10 @@ pub mod usdc {
pool_currency: bool,
) -> AssetMetadata<Balance, CustomMetadata> {
AssetMetadata {
decimals: DECIMALS_USDC,
decimals: DECIMALS,
name,
symbol,
existential_deposit: EXISTENTIAL_DEPOSIT_USDC,
existential_deposit: EXISTENTIAL_DEPOSIT,
location: Some(VersionedMultiLocation::V3(MultiLocation {
parents: 0,
interior: xcm::v3::Junctions::X3(
Expand Down
75 changes: 37 additions & 38 deletions runtime/centrifuge/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub type UpgradeCentrifuge1021 = (anemoy_pool::Migration, add_wrapped_usdc_varia
mod anemoy_pool {
use cfg_primitives::PoolId;
use cfg_traits::PoolInspect;
use cfg_types::tokens::usdc::{CURRENCY_ID_DOT_NATIVE_USDC, CURRENCY_ID_LP_ETH_USDC};
use cfg_types::tokens::usdc::{CURRENCY_ID_DOT_NATIVE, CURRENCY_ID_LP_ETH};
#[cfg(feature = "try-runtime")]
use codec::{Decode, Encode};
#[cfg(feature = "try-runtime")]
Expand All @@ -44,7 +44,7 @@ mod anemoy_pool {
PoolSystem::pool(ANEMOY_POOL_ID).ok_or("Could not find Anemoy Pool")?;

ensure!(
pool_details.currency == CURRENCY_ID_LP_ETH_USDC,
pool_details.currency == CURRENCY_ID_LP_ETH,
"anemoy_pool::Migration: pre_upgrade failing as Anemoy's currency should be LpEthUSDC"
);

Expand All @@ -66,10 +66,13 @@ mod anemoy_pool {
return weight;
}

pallet_pool_system::Pool::<Runtime>::mutate(ANEMOY_POOL_ID, |details| {
let details = details.as_mut().unwrap();
details.currency = CURRENCY_ID_DOT_NATIVE_USDC;
log::info!("anemoy_pool::Migration: currency set to USDC ✓");
pallet_pool_system::Pool::<Runtime>::mutate(ANEMOY_POOL_ID, |maybe_details| {
if let Some(details) = maybe_details {
details.currency = CURRENCY_ID_DOT_NATIVE;
log::info!("anemoy_pool::Migration: currency set to USDC ✓");
} else {
log::warn!("anemoy_pool::Migration: Pool details empty, skipping migration");
}
});

weight.saturating_add(
Expand All @@ -86,7 +89,7 @@ mod anemoy_pool {
PoolSystem::pool(ANEMOY_POOL_ID).ok_or("Could not find Anemoy Pool")?;

// Ensure the currency set to USDC is the only mutation performed
old_pool_details.currency = CURRENCY_ID_DOT_NATIVE_USDC;
old_pool_details.currency = CURRENCY_ID_DOT_NATIVE;
ensure!(
old_pool_details == pool_details,
"Corrupted migration: Only the currency of the Anemoy pool should have changed"
Expand All @@ -100,7 +103,7 @@ mod anemoy_pool {
fn verify_sanity_checks() -> (bool, Weight) {
let res =
crate::Tokens::balance(
CURRENCY_ID_LP_ETH_USDC,
CURRENCY_ID_LP_ETH,
&<PoolSystem as PoolInspect<_, _>>::account_for(ANEMOY_POOL_ID),
) == 0 && pallet_investments::ActiveInvestOrders::<Runtime>::iter_keys()
.filter(|investment| investment.pool_id == ANEMOY_POOL_ID)
Expand Down Expand Up @@ -136,9 +139,9 @@ pub mod add_wrapped_usdc_variants {
use cfg_types::tokens::{
usdc::{
lp_wrapped_usdc_metadata, CHAIN_ID_ARBITRUM_MAINNET, CHAIN_ID_BASE_MAINNET,
CHAIN_ID_CELO_MAINNET, CONTRACT_ARBITRUM_USDC, CONTRACT_BASE_USDC, CONTRACT_CELO_USDC,
CURRENCY_ID_DOT_NATIVE_USDC, CURRENCY_ID_LP_ARB_USDC, CURRENCY_ID_LP_BASE_USDC,
CURRENCY_ID_LP_CELO_USDC, CURRENCY_ID_LP_ETH_USDC, MIN_SWAP_ORDER_AMOUNT_USDC,
CHAIN_ID_CELO_MAINNET, CONTRACT_ARBITRUM, CONTRACT_BASE, CONTRACT_CELO,
CURRENCY_ID_DOT_NATIVE, CURRENCY_ID_LP_ARB, CURRENCY_ID_LP_BASE, CURRENCY_ID_LP_CELO,
CURRENCY_ID_LP_ETH, MIN_SWAP_ORDER_AMOUNT,
},
CurrencyId, CustomMetadata,
};
Expand Down Expand Up @@ -182,28 +185,28 @@ pub mod add_wrapped_usdc_variants {
currency_id
);
pallet_order_book::TradingPair::<Runtime>::insert(
CURRENCY_ID_DOT_NATIVE_USDC,
CURRENCY_ID_DOT_NATIVE,
currency_id,
MIN_SWAP_ORDER_AMOUNT_USDC,
MIN_SWAP_ORDER_AMOUNT,
);
pallet_order_book::TradingPair::<Runtime>::insert(
currency_id,
CURRENCY_ID_DOT_NATIVE_USDC,
MIN_SWAP_ORDER_AMOUNT_USDC,
CURRENCY_ID_DOT_NATIVE,
MIN_SWAP_ORDER_AMOUNT,
);
})
.ok();
}
// Add trading pair for already registered LpEthUsdc
pallet_order_book::TradingPair::<Runtime>::insert(
CURRENCY_ID_DOT_NATIVE_USDC,
CURRENCY_ID_LP_ETH_USDC,
MIN_SWAP_ORDER_AMOUNT_USDC,
CURRENCY_ID_DOT_NATIVE,
CURRENCY_ID_LP_ETH,
MIN_SWAP_ORDER_AMOUNT,
);
pallet_order_book::TradingPair::<Runtime>::insert(
CURRENCY_ID_LP_ETH_USDC,
CURRENCY_ID_DOT_NATIVE_USDC,
MIN_SWAP_ORDER_AMOUNT_USDC,
CURRENCY_ID_LP_ETH,
CURRENCY_ID_DOT_NATIVE,
MIN_SWAP_ORDER_AMOUNT,
);

log::info!("add_wrapped_usdc_variants::Migration: on_runtime_upgrade succeeded ✓");
Expand Down Expand Up @@ -240,7 +243,7 @@ pub mod add_wrapped_usdc_variants {
Self::get_tradeable_ids()
.into_iter()
.all(|wrapped_usdc_id| {
OrderBook::valid_pair(CURRENCY_ID_DOT_NATIVE_USDC, wrapped_usdc_id)
OrderBook::valid_pair(CURRENCY_ID_DOT_NATIVE, wrapped_usdc_id)
}),
"At least one of the wrapped USDC variants is not enabled as trading pair into DOT native USDC"
);
Expand All @@ -249,7 +252,7 @@ pub mod add_wrapped_usdc_variants {
Self::get_tradeable_ids()
.into_iter()
.all(|wrapped_usdc_id| {
OrderBook::valid_pair(wrapped_usdc_id, CURRENCY_ID_DOT_NATIVE_USDC)
OrderBook::valid_pair(wrapped_usdc_id, CURRENCY_ID_DOT_NATIVE)
}),
"At least one of the wrapped USDC variants is not enabled as trading pair from DOT native USDC"
);
Expand All @@ -261,56 +264,52 @@ pub mod add_wrapped_usdc_variants {

impl Migration {
fn get_unregistered_ids() -> Vec<CurrencyId> {
vec![
CURRENCY_ID_LP_BASE_USDC,
CURRENCY_ID_LP_ARB_USDC,
CURRENCY_ID_LP_CELO_USDC,
]
vec![CURRENCY_ID_LP_BASE, CURRENCY_ID_LP_ARB, CURRENCY_ID_LP_CELO]
}

#[cfg(feature = "try-runtime")]
fn get_tradeable_ids() -> Vec<CurrencyId> {
vec![
CURRENCY_ID_LP_ETH_USDC,
CURRENCY_ID_LP_BASE_USDC,
CURRENCY_ID_LP_ARB_USDC,
CURRENCY_ID_LP_CELO_USDC,
CURRENCY_ID_LP_ETH,
CURRENCY_ID_LP_BASE,
CURRENCY_ID_LP_ARB,
CURRENCY_ID_LP_CELO,
]
}

fn get_unregistered_metadata() -> Vec<(CurrencyId, AssetMetadata<Balance, CustomMetadata>)>
{
vec![
(
CURRENCY_ID_LP_BASE_USDC,
CURRENCY_ID_LP_BASE,
lp_wrapped_usdc_metadata(
"LP Base Wrapped USDC".as_bytes().to_vec(),
"LpBaseUSDC".as_bytes().to_vec(),
LiquidityPoolsPalletIndex::get(),
CHAIN_ID_BASE_MAINNET,
CONTRACT_BASE_USDC,
CONTRACT_BASE,
true,
),
),
(
CURRENCY_ID_LP_ARB_USDC,
CURRENCY_ID_LP_ARB,
lp_wrapped_usdc_metadata(
"LP Arbitrum Wrapped USDC".as_bytes().to_vec(),
"LpArbUSDC".as_bytes().to_vec(),
LiquidityPoolsPalletIndex::get(),
CHAIN_ID_ARBITRUM_MAINNET,
CONTRACT_ARBITRUM_USDC,
CONTRACT_ARBITRUM,
true,
),
),
(
CURRENCY_ID_LP_CELO_USDC,
CURRENCY_ID_LP_CELO,
lp_wrapped_usdc_metadata(
"LP Celo Wrapped USDC".as_bytes().to_vec(),
"LpCeloUSDC".as_bytes().to_vec(),
LiquidityPoolsPalletIndex::get(),
CHAIN_ID_CELO_MAINNET,
CONTRACT_CELO_USDC,
CONTRACT_CELO,
true,
),
),
Expand Down
8 changes: 4 additions & 4 deletions src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ use cfg_types::{
fee_keys::FeeKey,
tokens::{
usdc::{
lp_wrapped_usdc_metadata, CHAIN_ID_ETH_GOERLI_TESTNET, CONTRACT_ETH_GOERLI_USDC,
CURRENCY_ID_LP_ETH_GOERLI_USDC,
lp_wrapped_usdc_metadata, CHAIN_ID_ETH_GOERLI_TESTNET, CONTRACT_ETH_GOERLI,
CURRENCY_ID_LP_ETH_GOERLI,
},
AssetMetadata, CrossChainTransferability, CurrencyId, CustomMetadata,
},
Expand Down Expand Up @@ -1002,13 +1002,13 @@ fn asset_registry_assets() -> Vec<(CurrencyId, Vec<u8>)> {
.encode(),
),
(
CURRENCY_ID_LP_ETH_GOERLI_USDC,
CURRENCY_ID_LP_ETH_GOERLI,
lp_wrapped_usdc_metadata(
"LP Ethereum Wrapped USDC".as_bytes().to_vec(),
"LpEthUSDC".as_bytes().to_vec(),
development_runtime::liquidity_pools::LiquidityPoolsPalletIndex::get(),
CHAIN_ID_ETH_GOERLI_TESTNET,
CONTRACT_ETH_GOERLI_USDC,
CONTRACT_ETH_GOERLI,
true,
)
.encode(),
Expand Down

0 comments on commit 0a9ef1c

Please sign in to comment.