Skip to content

Commit

Permalink
feat: register and update celo usdc variants
Browse files Browse the repository at this point in the history
  • Loading branch information
mustermeiszer committed Feb 23, 2024
1 parent f60f509 commit c4a3b2b
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 2 deletions.
5 changes: 4 additions & 1 deletion libs/types/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,10 @@ pub mod usdc {
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 CURRENCY_ID_LP_CELO_WORMHOLE: CurrencyId = CurrencyId::ForeignAsset(100_004);
pub const CURRENCY_ID_LP_CELO: CurrencyId = CurrencyId::ForeignAsset(100_006);

pub const LOCAL_ASSET_ID: LocalAssetId = LocalAssetId(1u32);
pub const CURRENCY_ID_LOCAL: CurrencyId = CurrencyId::LocalAsset(LOCAL_ASSET_ID);

Expand Down
6 changes: 5 additions & 1 deletion runtime/centrifuge/src/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use cfg_primitives::{Balance, PoolId};
use cfg_types::tokens::{
usdc::{
CURRENCY_ID_AXELAR, CURRENCY_ID_DOT_NATIVE, CURRENCY_ID_LOCAL, CURRENCY_ID_LP_ARB,
CURRENCY_ID_LP_BASE, CURRENCY_ID_LP_CELO, CURRENCY_ID_LP_ETH, LOCAL_ASSET_ID,
CURRENCY_ID_LP_BASE, CURRENCY_ID_LP_CELO, CURRENCY_ID_LP_CELO_WORMHOLE, CURRENCY_ID_LP_ETH,
LOCAL_ASSET_ID,
},
CurrencyId, LocalAssetId,
};
Expand All @@ -31,6 +32,7 @@ frame_support::parameter_types! {
pub const UsdcEth: CurrencyId = CURRENCY_ID_LP_ETH;
pub const UsdcBase: CurrencyId = CURRENCY_ID_LP_BASE;
pub const UsdcArb: CurrencyId = CURRENCY_ID_LP_ARB;
pub const UsdcCeloWormhole: CurrencyId = CURRENCY_ID_LP_CELO_WORMHOLE;
pub const UsdcCelo: CurrencyId = CURRENCY_ID_LP_CELO;
pub const MinOrderAmount: Balance = 10u128.pow(6);
}
Expand All @@ -50,6 +52,8 @@ pub type UpgradeCentrifuge1025 = (
super::Runtime,
LocalCurrencyIdUsdc,
>,
// Register new canonical USDC on Celo
runtime_common::migrations::update_celo_usdcs::Migration<super::Runtime>,
// Init local representation for all assets
runtime_common::migrations::local_currency::translate_metadata::Migration<
super::Runtime,
Expand Down
114 changes: 114 additions & 0 deletions runtime/common/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,117 @@ pub mod nuke;
pub mod orml_tokens;
pub mod precompile_account_codes;
pub mod transfer_allowlist_currency;

pub mod update_celo_usdcs {
use cfg_primitives::Balance;
#[cfg(feature = "try-runtime")]
use cfg_types::tokens::LocalAssetId;
use cfg_types::tokens::{
usdc::{CURRENCY_ID_LP_CELO, CURRENCY_ID_LP_CELO_WORMHOLE},
CrossChainTransferability, CurrencyId, CustomMetadata,
};
use frame_support::{traits::OnRuntimeUpgrade, weights::Weight};
use hex_literal::hex;
use orml_traits::asset_registry::{AssetMetadata, Mutate};
use sp_runtime::traits::Get;
use xcm::v3::{
Junction::{AccountKey20, GlobalConsensus, PalletInstance},
Junctions::X3,
NetworkId::Ethereum,
};

const LOG_PREFIX: &str = "UpdateCeloUsdcs";

pub struct Migration<T>(sp_std::marker::PhantomData<T>);

impl<T> OnRuntimeUpgrade for Migration<T>
where
T: orml_asset_registry::Config<
CustomMetadata = CustomMetadata,
AssetId = CurrencyId,
Balance = Balance,
>,
{
fn on_runtime_upgrade() -> Weight {
<orml_asset_registry::Pallet<T> as Mutate>::register_asset(
Some(CURRENCY_ID_LP_CELO),
AssetMetadata {
decimals: 6,
name: "LP Celo Wrapped USDC ".as_bytes().to_vec(),
symbol: "LpCeloUSDC".as_bytes().to_vec(),
existential_deposit: 1000u128,
location: Some(
X3(
PalletInstance(103),
GlobalConsensus(Ethereum { chain_id: 42220 }),
AccountKey20 {
// https://www.circle.com/blog/usdc-now-available-on-celo
key: hex!("cebA9300f2b948710d2653dD7B07f33A8B32118C"),
network: None,
},
)
.into(),
),
additional: CustomMetadata {
transferability: CrossChainTransferability::LiquidityPools,
mintable: false,
permissioned: false,
pool_currency: true,
local_representation: None,
},
},
)
.map_err(|e| {
log::error!(
"{LOG_PREFIX} Failed to register new canonical Celo USDC due to error {:?}",
e
);
})
.ok();

log::info!("{LOG_PREFIX} Done registering new canonical Celo USDC currency");

<orml_asset_registry::Pallet<T> as Mutate>::update_asset(
CURRENCY_ID_LP_CELO_WORMHOLE,
None,
Some("LP Celo Wrapped Wormhole USDC ".as_bytes().to_vec()),
Some("LpCeloWormUSDC ".as_bytes().to_vec()),
None,
None,
None,
)
.map_err(|e| {
log::error!(
"{LOG_PREFIX} Failed to update wormhole Celo USDC due to error {:?}",
e
);
})
.ok();

log::info!("{LOG_PREFIX} Done updating wormhole Celo USDC currency");

T::DbWeight::get().writes(2)
}

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, sp_runtime::DispatchError> {
assert!(!orml_asset_registry::Metadata::<T>::contains_key(
CURRENCY_ID_LP_CELO
));

log::info!("{LOG_PREFIX} PRE UPGRADE: Finished");

Ok(vec![])
}

#[cfg(feature = "try-runtime")]
fn post_upgrade(_: Vec<u8>) -> Result<(), sp_runtime::DispatchError> {
assert!(orml_asset_registry::Metadata::<T>::contains_key(
CURRENCY_ID_LP_CELO
));

log::info!("{LOG_PREFIX} POST UPGRADE: Finished");
Ok(())
}
}
}

0 comments on commit c4a3b2b

Please sign in to comment.