Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: limit usdc swap inputs to 1000 USDC #4009

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions state-chain/pallets/cf-swapping/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ pub mod pallet {
Self::validate_destination_address(&destination_address, to)?;
let swap_origin = SwapOrigin::Vault { tx_hash };

// LIMIT USDC SWAP DEPOSITS TO 1000 USDC
let deposit_amount = if from == Asset::Usdc {
sp_std::cmp::min(deposit_amount, 1_000 * 1_000_000)
} else {
deposit_amount
};

if let Some(swap_id) = Self::schedule_swap_with_check(
from,
to,
Expand Down Expand Up @@ -958,14 +965,14 @@ pub mod pallet {
deposit_block_height: u64,
from: Asset,
to: Asset,
amount: AssetAmount,
deposit_amount: AssetAmount,
destination_address: ForeignChainAddress,
broker_id: Self::AccountId,
broker_commission_bps: BasisPoints,
channel_id: ChannelId,
) {
let fee = Permill::from_parts(broker_commission_bps as u32 * BASIS_POINTS_PER_MILLION) *
amount;
deposit_amount;

EarnedBrokerFees::<T>::mutate(&broker_id, from, |earned_fees| {
earned_fees.saturating_accrue(fee)
Expand All @@ -979,17 +986,24 @@ pub mod pallet {
deposit_block_height,
};

// LIMIT USDC SWAP DEPOSITS TO 1000 USDC
let deposit_amount = if from == Asset::Usdc {
sp_std::cmp::min(deposit_amount, 1_000 * 1_000_000)
} else {
deposit_amount
};

if let Some(swap_id) = Self::schedule_swap_with_check(
from,
to,
amount,
deposit_amount,
destination_address.clone(),
&swap_origin,
) {
Self::deposit_event(Event::<T>::SwapScheduled {
swap_id,
source_asset: from,
deposit_amount: amount,
deposit_amount,
destination_asset: to,
destination_address: encoded_destination_address,
origin: swap_origin,
Expand All @@ -1014,6 +1028,14 @@ pub mod pallet {
// Caller should ensure that assets and addresses are compatible.
debug_assert!(destination_address.chain() == ForeignChain::from(destination_asset));

// LIMIT USDC SWAP DEPOSITS TO 1000 USDC
let deposit_amount = if source_asset == Asset::Usdc {
sp_std::cmp::min(deposit_amount, 1_000 * 1_000_000)
} else {
deposit_amount
};
// PARTNERNET ONLY

let principal_swap_amount =
deposit_amount.saturating_sub(deposit_metadata.channel_metadata.gas_budget);

Expand Down