-
Notifications
You must be signed in to change notification settings - Fork 202
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
feat(evm-funtoken-precompile): Implement "balance", "bankBalance", and "whoAmI" methods #2107
Changes from all commits
3aef202
d349166
5ed7cf4
e748b3c
4360ae2
08c0b20
06f46f3
9d15c07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,53 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.19; | ||
|
||
/// @dev Implements the "bankSend" functionality for sending ERC20 tokens as bank | ||
/// coins to a Nibiru bech32 address using the "FunToken" mapping between the | ||
/// ERC20 and bank. | ||
address constant FUNTOKEN_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000800; | ||
IFunToken constant FUNTOKEN_PRECOMPILE = IFunToken(FUNTOKEN_PRECOMPILE_ADDRESS); | ||
|
||
/// @dev Implements the functionality for sending ERC20 tokens and bank | ||
/// coins to various Nibiru accounts using either the Nibiru Bech32 address | ||
/// using the "FunToken" mapping between the ERC20 and bank. | ||
interface IFunToken { | ||
/// @dev bankSend sends ERC20 tokens as coins to a Nibiru base account | ||
/// @dev sendToBank sends ERC20 tokens as coins to a Nibiru base account | ||
/// @param erc20 - the address of the ERC20 token contract | ||
/// @param amount - the amount of tokens to send | ||
/// @param to - the receiving Nibiru base account address as a string | ||
/// @return sentAmount - amount of tokens received by the recipient. This may | ||
/// not be equal to `amount` if the corresponding ERC20 contract has a fee or | ||
/// deduction on transfer. | ||
function bankSend( | ||
function sendToBank( | ||
address erc20, | ||
uint256 amount, | ||
string memory to | ||
string calldata to | ||
) external returns (uint256 sentAmount); | ||
} | ||
|
||
address constant FUNTOKEN_PRECOMPILE_ADDRESS = 0x0000000000000000000000000000000000000800; | ||
struct NibiruAccount { | ||
address ethAddr; | ||
string bech32Addr; | ||
} | ||
struct FunToken { | ||
address erc20; | ||
string bankDenom; | ||
} | ||
|
||
IFunToken constant FUNTOKEN_PRECOMPILE = IFunToken(FUNTOKEN_PRECOMPILE_ADDRESS); | ||
function balance( | ||
address who, | ||
address funtoken | ||
) | ||
external | ||
returns ( | ||
uint256 erc20Balance, | ||
uint256 bankBalance, | ||
FunToken memory token, | ||
NibiruAccount memory whoAddrs | ||
); | ||
|
||
function bankBalance( | ||
address who, | ||
string calldata bankDenom | ||
) external returns (uint256 bankBalance, NibiruAccount memory whoAddrs); | ||
|
||
function whoAmI( | ||
string calldata who | ||
) external returns (NibiruAccount memory whoAddrs); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,16 +40,16 @@ contract TestPrecompileSelfCallRevert { | |
) external { | ||
require(nativeRecipient.send(nativeAmount), "ETH transfer failed"); // wei | ||
|
||
uint256 sentAmount = FUNTOKEN_PRECOMPILE.bankSend( | ||
uint256 sentAmount = FUNTOKEN_PRECOMPILE.sendToBank( | ||
erc20, | ||
precompileAmount, // micro-WNIBI | ||
precompileRecipient | ||
precompileAmount, // micro-WNIBI | ||
precompileRecipient | ||
Comment on lines
+43
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Based on the search results, I can generate the final response: Method renaming has been consistently applied across the codebase The only remaining instance of
🔗 Analysis chainLGTM! Verify consistent method renaming across the codebase. The method renaming from Let's verify the consistent renaming across the codebase: 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check for any remaining instances of 'bankSend' that might have been missed
# and confirm all occurrences have been updated to 'sendToBank'
echo "Checking for any remaining 'bankSend' instances:"
rg "bankSend"
echo -e "\nVerifying 'sendToBank' implementations:"
rg "sendToBank"
Length of output: 4729 |
||
); | ||
|
||
require( | ||
sentAmount == precompileAmount, | ||
string.concat( | ||
"IFunToken.bankSend succeeded but transferred the wrong amount", | ||
"IFunToken.sendToBank succeeded but transferred the wrong amount", | ||
"sentAmount ", | ||
Strings.toString(nativeAmount), | ||
"expected ", | ||
|
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.
🛠️ Refactor suggestion
Consider changing state mutability to
view
.The
bankBalance
function is well-designed for querying bank balances with proper denomination support. However, since this is a read-only operation, it should be marked asview
instead ofnonpayable
to save gas and better reflect its behavior.