Skip to content

Commit

Permalink
Fix the denomination of Bridge pool gas fees
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Aug 28, 2023
1 parent ba741a5 commit 27f07c8
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 2 additions & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2817,7 +2817,8 @@ pub mod args {
let recipient = BRIDGE_POOL_TARGET.parse(matches);
let sender = SOURCE.parse(matches);
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
let fee_amount = BRIDGE_POOL_GAS_AMOUNT.parse(matches).amount;
let fee_amount =
InputAmount::Unvalidated(BRIDGE_POOL_GAS_AMOUNT.parse(matches));
let fee_payer = BRIDGE_POOL_GAS_PAYER.parse(matches);
let fee_token = BRIDGE_POOL_GAS_TOKEN.parse(matches);
let code_path = PathBuf::from(TX_BRIDGE_POOL_WASM);
Expand Down
4 changes: 2 additions & 2 deletions shared/src/ledger/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,8 @@ pub struct EthereumBridgePool<C: NamadaTypes = SdkTypes> {
pub sender: C::Address,
/// The amount to be transferred
pub amount: InputAmount,
/// The amount of fees (in NAM)
pub fee_amount: token::Amount,
/// The amount of gas fees
pub fee_amount: InputAmount,
/// The account of fee payer.
///
/// If unset, it is the same as the sender.
Expand Down
22 changes: 16 additions & 6 deletions shared/src/ledger/eth_bridge/bridge_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::sync::Arc;
use borsh::BorshSerialize;
use ethbridge_bridge_contract::Bridge;
use ethers::providers::Middleware;
use namada_core::ledger::eth_bridge::ADDRESS as BRIDGE_ADDRESS;
use namada_core::ledger::eth_bridge::storage::wrapped_erc20s;
use namada_core::types::key::common;
use owo_colors::OwoColorize;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -55,11 +55,21 @@ pub async fn build_bridge_pool_tx<C: crate::ledger::queries::Client + Sync>(
gas_payer: common::PublicKey,
) -> Result<Tx, Error> {
let fee_payer = fee_payer.unwrap_or_else(|| sender.clone());
let DenominatedAmount { amount, .. } =
validate_amount(client, amount, &BRIDGE_ADDRESS, tx_args.force)
.await
.expect("Failed to validate amount");

let DenominatedAmount { amount, .. } = validate_amount(
client,
amount,
&wrapped_erc20s::token(&asset),
tx_args.force,
)
.await
.ok_or_else(|| Error::Other("Failed to validate amount".into()))?;
let DenominatedAmount {
amount: fee_amount, ..
} = validate_amount(client, fee_amount, &fee_token, tx_args.force)
.await
.ok_or_else(|| {
Error::Other("Failed to validate Bridge pool fee amount".into())
})?;
let transfer = PendingTransfer {
transfer: TransferToEthereum {
asset,
Expand Down
1 change: 1 addition & 0 deletions shared/src/ledger/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ pub async fn validate_amount<C: crate::ledger::queries::Client + Sync>(
force: bool,
) -> Option<token::DenominatedAmount> {
let input_amount = match amount {
InputAmount::Unvalidated(amt) if amt.is_zero() => return Some(amt),
InputAmount::Unvalidated(amt) => amt.canonical(),
InputAmount::Validated(amt) => return Some(amt),
};
Expand Down

0 comments on commit 27f07c8

Please sign in to comment.