Skip to content

Commit

Permalink
fix(evm)!: Fungible Token conversions (#2003)
Browse files Browse the repository at this point in the history
* create funtoken_from_coin_test.go

* refactor FunTokenFromCoinSuite

* create funtoken_from_erc20_test.go

* refactor DeployContract

* refactor MsgCreateFunToken ValidateBasic()

* add test case for TestCreateFunTokenFromERC20

* refactor TestERC20Calls

* move TestSendFunTokenToEvm

* refactor CreateFunTokenFromERC20

* add TestSendFromEvmToCosmos

* remove ApplyEvmMsgWithEmptyTxConfig

* Update CHANGELOG.md

* refactor: rename SendFunTokenToEvm to ConvertCoinToEvm

* refactor LoadERC20BigInt

* refactor erc20 Transfer call

* feat: add convertCoinNativeCoin and convertCoinNativeERC20

* refactor(evm); rename EventSendFunTokenToEvm to EventConvertCoinToEvm

* test: TestCreateFunTokenFromCoin

* fix: TestConvertCoinToEvmAndBack

* Update funtoken_from_coin_test.go

* refactor TestCreateFunTokenFromERC20

* fix: send tokens from evm to cosmos and back

* add negative test cases

* add negative test case

* add negative cases for TestConvertCoinToEvmAndBack

* Update CHANGELOG.md

* fix: precompile test

* refactor: rename SendFunTokenToEvm to ConvertCoinToEvm
  • Loading branch information
k-yang authored Aug 15, 2024
1 parent dbf26bb commit ccb4763
Show file tree
Hide file tree
Showing 18 changed files with 831 additions and 660 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1997](https://github.com/NibiruChain/nibiru/pull/1997) - refactor(evm): Remove unnecessary params: "enable_call", "enable_create".
- [#2000](https://github.com/NibiruChain/nibiru/pull/2000) - refactor(evm): simplify ERC-20 keeper methods
- [#2001](https://github.com/NibiruChain/nibiru/pull/2001) - refactor(evm): simplify FunToken methods and tests
- [#2003](https://github.com/NibiruChain/nibiru/pull/2003) - fix(evm): fix FunToken conversions between Cosmos and EVM

#### Dapp modules: perp, spot, oracle, etc

Expand Down
4 changes: 2 additions & 2 deletions proto/eth/evm/v1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ message EventFunTokenCreated {
bool is_made_from_coin = 4;
}

// SendFunTokenToEvm defines sending fun token to erc20 event.
message EventSendFunTokenToEvm {
// ConvertCoinToEvm defines sending fun token to erc20 event.
message EventConvertCoinToEvm {
string sender = 1;
string erc20_contract_address = 2;
string to_eth_addr = 3;
Expand Down
10 changes: 5 additions & 5 deletions proto/eth/evm/v1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ service Msg {
// denomination for a bank coin can be given to create the mapping to an ERC20.
rpc CreateFunToken(MsgCreateFunToken) returns (MsgCreateFunTokenResponse);

// SendFunTokenToEvm: Sends a coin with a valid "FunToken" mapping to the
// ConvertCoinToEvm: Sends a coin with a valid "FunToken" mapping to the
// given recipient address ("to_eth_addr") in the corresponding ERC20
// representation.
rpc SendFunTokenToEvm(MsgSendFunTokenToEvm) returns (MsgSendFunTokenToEvmResponse);
rpc ConvertCoinToEvm(MsgConvertCoinToEvm) returns (MsgConvertCoinToEvmResponse);
}

// MsgEthereumTx encapsulates an Ethereum transaction as an SDK message.
Expand Down Expand Up @@ -210,8 +210,8 @@ message MsgCreateFunTokenResponse {
eth.evm.v1.FunToken funtoken_mapping = 1 [(gogoproto.nullable) = false];
}

// MsgSendFunTokenToEvm: Arguments to send a bank coin to ERC-20 representation
message MsgSendFunTokenToEvm {
// MsgConvertCoinToEvm: Arguments to send a bank coin to ERC-20 representation
message MsgConvertCoinToEvm {
// Hexadecimal address of the ERC20 token to which the `FunToken` maps
string to_eth_addr = 1 [
(gogoproto.customtype) = "github.com/NibiruChain/nibiru/v2/eth.HexAddr",
Expand All @@ -227,4 +227,4 @@ message MsgSendFunTokenToEvm {
(gogoproto.nullable) = false
];
}
message MsgSendFunTokenToEvmResponse {}
message MsgConvertCoinToEvmResponse {}
8 changes: 4 additions & 4 deletions x/evm/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func GetTxCmd() *cobra.Command {
cmds := []*cobra.Command{
CmdCreateFunTokenFromBankCoin(),
CmdCreateFunTokenFromERC20(),
SendFunTokenToEvm(),
ConvertCoinToEvm(),
}
for _, cmd := range cmds {
txCmd.AddCommand(cmd)
Expand Down Expand Up @@ -99,8 +99,8 @@ func CmdCreateFunTokenFromERC20() *cobra.Command {
return cmd
}

// SendFunTokenToEvm broadcast MsgSendFunTokenToEvm
func SendFunTokenToEvm() *cobra.Command {
// ConvertCoinToEvm broadcast MsgConvertCoinToEvm
func ConvertCoinToEvm() *cobra.Command {
cmd := &cobra.Command{
Use: "send-funtoken-to-erc20 [to_eth_addr] [coin] [flags]",
Short: `Send bank [coin] to its erc20 representation for the user [to_eth_addr]"`,
Expand All @@ -122,7 +122,7 @@ func SendFunTokenToEvm() *cobra.Command {
if err != nil {
return err
}
msg := &evm.MsgSendFunTokenToEvm{
msg := &evm.MsgConvertCoinToEvm{
Sender: clientCtx.GetFromAddress().String(),
BankCoin: coin,
ToEthAddr: eth.MustNewHexAddrFromStr(args[0]),
Expand Down
134 changes: 67 additions & 67 deletions x/evm/events.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions x/evm/evmmodule/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ func (s *Suite) TestExportInitGenesis() {
s.Require().NoError(err)

// Send fungible token coins from bank to evm
_, err = deps.EvmKeeper.SendFunTokenToEvm(
_, err = deps.EvmKeeper.ConvertCoinToEvm(
deps.Ctx,
&evm.MsgSendFunTokenToEvm{
&evm.MsgConvertCoinToEvm{
Sender: deps.Sender.NibiruAddr.String(),
BankCoin: sdk.Coin{Denom: "unibi", Amount: math.NewInt(amountToSendC.Int64())},
ToEthAddr: eth.MustNewHexAddrFromStr(toUserC.String()),
Expand Down
2 changes: 1 addition & 1 deletion x/evm/evmtest/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func AssertERC20BalanceEqual(
) {
actualBalance, err := deps.EvmKeeper.ERC20().BalanceOf(erc20, account, deps.Ctx)
assert.NoError(t, err)
assert.Zero(t, expectedBalance.Cmp(actualBalance))
assert.Zero(t, expectedBalance.Cmp(actualBalance), "expected %s, got %s", expectedBalance, actualBalance)
}

// CreateFunTokenForBankCoin: Uses the "TestDeps.Sender" account to create a
Expand Down
Loading

0 comments on commit ccb4763

Please sign in to comment.