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 11, 2023
1 parent 520f5cc commit 19c3f47
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2726,7 +2726,8 @@ pub mod args {
let recipient = BRIDGE_POOL_TARGET.parse(matches);
let sender = SOURCE.parse(matches);
let amount = InputAmount::Unvalidated(AMOUNT.parse(matches));
let gas_amount = BRIDGE_POOL_GAS_AMOUNT.parse(matches).amount;
let gas_amount =
InputAmount::Unvalidated(BRIDGE_POOL_GAS_AMOUNT.parse(matches));
let gas_payer = BRIDGE_POOL_GAS_PAYER.parse(matches);
let gas_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 @@ -637,8 +637,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 gas_amount: token::Amount,
/// The amount of gas fees
pub gas_amount: InputAmount,
/// The account of fee payer.
///
/// If unset, it is the same as the sender.
Expand Down
19 changes: 14 additions & 5 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 @@ -62,10 +62,19 @@ pub async fn build_bridge_pool_tx<
code_path: wasm_code,
} = args;
let gas_payer = gas_payer.unwrap_or_else(|| sender.clone());
let DenominatedAmount { amount, .. } =
validate_amount(client, amount, &BRIDGE_ADDRESS, tx.force)
.await
.expect("Failed to validate amount");
let DenominatedAmount { amount, .. } = validate_amount(
client,
amount,
&wrapped_erc20s::token(&asset),
tx.force,
)
.await
.ok_or_else(|| Error::Other("Failed to validate amount".into()))?;
let DenominatedAmount {
amount: gas_amount, ..
} = validate_amount(client, gas_amount, &gas_token, tx.force)
.await
.ok_or_else(|| Error::Other("Failed to validate gas 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 @@ -980,6 +980,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 19c3f47

Please sign in to comment.