-
Notifications
You must be signed in to change notification settings - Fork 992
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
Added erc20 token amount type #1233
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might need another review pass, since token whitelists need some changes to allow transfers to ethereum, even if a whitelist update removes a token whose balance is still greater than 0 for some namada client
@@ -336,6 +434,67 @@ where | |||
Ok(changed_key) | |||
} | |||
|
|||
fn act_on_whitelist_updates<D, H>( | |||
wl_storage: &mut WlStorage<D, H>, | |||
whitelist: HashMap<EthAddress, Erc20Amount>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iteration order doesn't seem to matter here, but for the correctness of any potential change to this code, I would make this a BTreeMap
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eventually, we also need to update the token whitelist nonce in storage, I believe
@@ -2274,7 +2277,7 @@ pub mod args { | |||
/// The sender of the transfer | |||
pub sender: WalletAddress, | |||
/// The amount to be transferred | |||
pub amount: Amount, | |||
pub amount: Decimal, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let result: Result<Decimal, _> = "1.000000000012345".parse()
I tested this locally, and parsing worked. what was the issue with parsing amounts with more than 0 decimal places?
let erc20_amount = TOKEN_AMOUNT_OPT.parse(matches); | ||
let amount = AMOUNT_OPT.parse(matches); | ||
if let Some(amt) = erc20_amount { | ||
Self::Erc20(amt) | ||
} else if let Some(amt) = amount { | ||
Self::Native(amt) | ||
} else { | ||
panic!("No amount provided") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if CLI receives two distinct type of amount arguments, only erc20 amounts will be considered. for better UX, perhaps it's better to fail parsing if both of them are Some
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.rs/clap/latest/clap/error/struct.Error.html
maybe we could also use this API instead of panicking
@@ -124,31 +128,34 @@ pub mod eth_events { | |||
block_height: Uint256, | |||
data: &[u8], | |||
min_confirmations: Uint256, | |||
erc20_tokens: &HashMap<EthAddress, u8>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was already heavily refactored here: #1252
shit, what do we do about this?
@@ -157,7 +157,7 @@ where | |||
if let Some(config) = genesis.ethereum_bridge_params { | |||
tracing::debug!("Initializing Ethereum bridge storage."); | |||
config.init_storage(&mut self.wl_storage); | |||
self.update_eth_oracle(); | |||
self.update_eth_oracle(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'm not generally a big fan of these "naked" boolean values. what does it mean for update_eth_oracle
to take a value of true
, without having any context on what the argument's name is?
impl From<Uint> for u64 { | ||
fn from(uint: Uint) -> Self { | ||
// N.B. this will panic if `uint` > `u64::MAX`. | ||
ethUint::from(uint).as_u64() | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a bit odd for a From
implementation to panic. can we do without it? or implement TryFrom
instead
update: impl FnOnce(Option<T>) -> T, | ||
) -> Result<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this change because erc20s don't have a default value?
EthereumEvent::UpdateBridgeWhitelist { whitelist, .. } => { | ||
Ok(act_on_whitelist_updates( | ||
wl_storage, | ||
whitelist | ||
.iter() | ||
.map(|TokenWhitelist { token, cap }| (*token, *cap)) | ||
.collect(), | ||
)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a TODO here, since we need to update the token whitelist nonce in storage (I think?)
self.wl_storage.ethbridge_queries().get_wnam_address() | ||
{ | ||
if addr == *token_address { | ||
return Some(6); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe implement a const fn token::Amount::denomination() -> u8 { 6 }
?
|e| { | ||
eyre!( | ||
"Could not process the amount of NAM to \ | ||
be escrowed into the bridge pool: {:?}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: assuming this implements Error
, it's best to display the actual error string
be escrowed into the bridge pool: {:?}", | |
be escrowed into the bridge pool: {}", |
Yes, but that will be another PR. |
This PR contains an implementation that closes #1290 |
This PR closes #1085, #1089, and #1090.
A new type,
Erc20Amount
has been added for amounts of ERC20 tokens according to the EIP-20 specification. Whitelisted ERC20 tokens must now keep a denomination in storage. These denominations must also be kept in sync with the oracle, which needs them for processing ethereum events.