Skip to content

Commit

Permalink
Merge branch 'tiago/nut-denom' (#1853)
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Aug 30, 2023
2 parents b9cd7b3 + 4ce6079 commit 5bcbcf8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/1853-nut-denom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Denominate non-whitelisted NUT amounts
([\#1853](https://github.com/anoma/namada/pull/1853))
29 changes: 23 additions & 6 deletions core/src/ledger/storage_api/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use super::{StorageRead, StorageWrite};
use crate::ledger::storage_api;
use crate::types::address::Address;
use crate::types::address::{Address, InternalAddress};
use crate::types::token;
pub use crate::types::token::{
balance_key, is_any_minted_balance_key, is_balance_key, minted_balance_key,
Expand Down Expand Up @@ -46,12 +46,29 @@ pub fn read_denom<S>(
where
S: StorageRead,
{
let key = token::denom_key(token);
let (key, nut) = match token {
Address::Internal(InternalAddress::Nut(erc20)) => {
let token = Address::Internal(InternalAddress::Erc20(*erc20));
(token::denom_key(&token), true)
}
token => (token::denom_key(token), false),
};
storage.read(&key).map(|opt_denom| {
Some(
opt_denom
.unwrap_or_else(|| token::NATIVE_MAX_DECIMAL_PLACES.into()),
)
Some(opt_denom.unwrap_or_else(|| {
if nut {
// NB: always use the equivalent ERC20's smallest
// denomination to specify amounts, if we cannot
// find a denom in storage
0u8.into()
} else {
// FIXME: perhaps when we take this branch, we should
// assume the same behavior as NUTs? maybe this branch
// is unreachable, anyway. when would regular tokens
// ever not be denominated?
crate::hints::cold();
token::NATIVE_MAX_DECIMAL_PLACES.into()
}
}))
})
}

Expand Down

0 comments on commit 5bcbcf8

Please sign in to comment.