Skip to content

Commit

Permalink
move ERC20 address constructors back to core
Browse files Browse the repository at this point in the history
  • Loading branch information
tzemanovic committed Dec 19, 2023
1 parent 14562f3 commit c4f79a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 13 additions & 3 deletions core/src/types/eth_bridge_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use borsh_ext::BorshSerializeExt;
use ethabi::token::Token;
use serde::{Deserialize, Serialize};

use crate::ledger::eth_bridge::storage::wrapped_erc20s;
use super::address::InternalAddress;
use crate::types::address::Address;
use crate::types::eth_abi::Encode;
use crate::types::ethereum_events::{
Expand Down Expand Up @@ -173,16 +173,26 @@ pub struct PendingTransfer {
pub gas_fee: GasFee,
}

/// Construct a token address from an ERC20 address.
pub fn erc20_token_address(address: &EthAddress) -> Address {
Address::Internal(InternalAddress::Erc20(*address))
}

/// Construct a NUT token address from an ERC20 address.
pub fn erc20_nut_address(address: &EthAddress) -> Address {
Address::Internal(InternalAddress::Nut(*address))
}

impl PendingTransfer {
/// Get a token [`Address`] from this [`PendingTransfer`].
#[inline]
pub fn token_address(&self) -> Address {
match &self.transfer.kind {
TransferToEthereumKind::Erc20 => {
wrapped_erc20s::token(&self.transfer.asset)
erc20_token_address(&self.transfer.asset)
}
TransferToEthereumKind::Nut => {
wrapped_erc20s::nut(&self.transfer.asset)
erc20_nut_address(&self.transfer.asset)
}
}
}
Expand Down
10 changes: 0 additions & 10 deletions ethereum_bridge/src/storage/wrapped_erc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@ use crate::types::token::{
balance_key, minted_balance_key, MINTED_STORAGE_KEY,
};

/// Construct a token address from an ERC20 address.
pub fn token(address: &EthAddress) -> Address {
Address::Internal(InternalAddress::Erc20(*address))
}

/// Construct a NUT token address from an ERC20 address.
pub fn nut(address: &EthAddress) -> Address {
Address::Internal(InternalAddress::Nut(*address))
}

/// Represents the type of a key relating to a wrapped ERC20
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone)]
pub enum KeyType {
Expand Down

0 comments on commit c4f79a6

Please sign in to comment.