Skip to content

Commit

Permalink
Merge branch 'main' into ud/evm
Browse files Browse the repository at this point in the history
  • Loading branch information
Unique-Divine committed Jul 1, 2024
2 parents ce59cc7 + 822d838 commit 5a70896
Show file tree
Hide file tree
Showing 8 changed files with 767 additions and 98 deletions.
34 changes: 29 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1776](https://github.com/NibiruChain/nibiru/pull/1776) - feat(inflation): make inflation params a collection and add commands to update them
- [#1872](https://github.com/NibiruChain/nibiru/pull/1872) - chore(math): use cosmossdk.io/math to replace sdk types
- [#1874](https://github.com/NibiruChain/nibiru/pull/1874) - chore(proto): remove the proto stringer as per Cosmos SDK migration guidelines
- [#1906](https://github.com/NibiruChain/nibiru/pull/1906) - feat(wasm): increase contract size limit to 3MB
- [#1908](https://github.com/NibiruChain/nibiru/pull/1908) - chore: make pebbledb the default db backend
- [#1931](https://github.com/NibiruChain/nibiru/pull/1931) - feat(ibc): add `wasm` route to IBC router
- [#1932](https://github.com/NibiruChain/nibiru/pull/1932) - fix(gosdk): fix keyring import functions

#### Nibiru EVM
Expand Down Expand Up @@ -78,6 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#1922](https://github.com/NibiruChain/nibiru/pull/1922) - feat(evm): tracer option is read from the config.
- [#1936](https://github.com/NibiruChain/nibiru/pull/1936) - feat(evm): EVM fungible token protobufs and encoding tests
- [#1947](https://github.com/NibiruChain/nibiru/pull/1947) - fix(evm): fix FunToken state marshalling
- [#1949](https://github.com/NibiruChain/nibiru/pull/1949) - feat(evm): add fungible token mapping queries
- [#1950](https://github.com/NibiruChain/nibiru/pull/1950) - feat(evm): Tx to create FunToken mapping from ERC20, contract embeds, and ERC20 queries.

#### Dapp modules: perp, spot, oracle, etc
Expand All @@ -103,8 +101,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Non-breaking/Compatible Improvements

- [#1818](https://github.com/NibiruChain/nibiru/pull/1818) - feat: add pebbledb support
- [#1859](https://github.com/NibiruChain/nibiru/pull/1859) - refactor(oracle): add oracle slashing events
- [#1893](https://github.com/NibiruChain/nibiru/pull/1893) - feat(gosdk): migrate Go-sdk into the Nibiru blockchain repo.
- [#1899](https://github.com/NibiruChain/nibiru/pull/1899) - build(deps): cometbft v0.37.5, cosmos-sdk v0.47.11, proto-builder v0.14.0
- [#1913](https://github.com/NibiruChain/nibiru/pull/1913) - fix(tests): race condition from heavy Network tests
Expand Down Expand Up @@ -132,6 +128,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Bump `pozetroninc/github-action-get-latest-release` from 0.7.0 to 0.8.0 ([#1863](https://github.com/NibiruChain/nibiru/pull/1863))
- Bump `bufbuild/buf-setup-action` from 1.30.1 to 1.33.0 ([#1891](https://github.com/NibiruChain/nibiru/pull/1891), [#1900](https://github.com/NibiruChain/nibiru/pull/1900), [#1923](https://github.com/NibiruChain/nibiru/pull/1923))

## [v1.5.0](https://github.com/NibiruChain/nibiru/releases/tag/v1.5.0) - 2024-06-21

Nibiru v1.5.0 enables IBC CosmWasm smart contracts.

- [[Release Link](https://github.com/NibiruChain/nibiru/releases/tag/v1.5.0)]
- [[Commits](https://github.com/NibiruChain/nibiru/commits/v1.5.0)]

### Features

- [#1931](https://github.com/NibiruChain/nibiru/pull/1931) - feat(ibc): add `wasm` route to IBC router

## [v1.4.0](https://github.com/NibiruChain/nibiru/releases/tag/v1.4.0) - 2024-06-04

Nibiru v1.4.0 adds PebbleDB support and increases the wasm contract size limit to 3MB.

- [[Release Link](https://github.com/NibiruChain/nibiru/releases/tag/v1.4.0)]
- [[Commits](https://github.com/NibiruChain/nibiru/commits/v1.4.0)]

### State Machine Breaking

- [#1906](https://github.com/NibiruChain/nibiru/pull/1906) - feat(wasm): increase contract size limit to 3MB

### Features

- [#1818](https://github.com/NibiruChain/nibiru/pull/1818) - feat: add pebbledb support
- [#1908](https://github.com/NibiruChain/nibiru/pull/1908) - chore: make pebbledb the default db backend
-

## [v1.3.0](https://github.com/NibiruChain/nibiru/releases/tag/v1.3.0) - 2024-05-07

Nibiru v1.3.0 adds interchain accounts.
Expand Down
30 changes: 30 additions & 0 deletions eth/rpc/backend/mocks/evm_query_client.go

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

20 changes: 20 additions & 0 deletions proto/eth/evm/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ service Query {
rpc BaseFee(QueryBaseFeeRequest) returns (QueryBaseFeeResponse) {
option (google.api.http).get = "/nibiru/evm/v1/base_fee";
}

rpc TokenMapping(QueryTokenMappingRequest) returns (QueryTokenMappingResponse) {
option (google.api.http).get = "/nibiru/evm/v1/token_mapping/{token}";
}
}

// QueryEthAccountRequest is the request type for the Query/Account RPC method.
Expand Down Expand Up @@ -301,3 +305,19 @@ message QueryBaseFeeResponse {
// base_fee is the EIP1559 base fee
string base_fee = 1 [(gogoproto.customtype) = "cosmossdk.io/math.Int"];
}

message QueryTokenMappingRequest {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// either the 0x contract address of the ERC-20 token or the cosmos denom
string token = 1;
}

message QueryTokenMappingResponse {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// fun_token is a mapping between the Cosmos native coin and the ERC20 contract address
FunToken fun_token = 1;
}
2 changes: 1 addition & 1 deletion simapp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ This directory contains the simulation tests for the `simapp` module
### Non-Determinism

```sh
make test-sim-non-determinism
make test-sim-nondeterminism
```

This test case checks that the simulation is deterministic. It does so by
Expand Down
27 changes: 27 additions & 0 deletions x/evm/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,3 +740,30 @@ func (k *Keeper) TraceEthTxMsg(

return &result, txConfig.LogIndex + uint(len(res.Logs)), nil
}

func (k Keeper) TokenMapping(
goCtx context.Context, req *evm.QueryTokenMappingRequest,
) (*evm.QueryTokenMappingResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

// first try lookup by cosmos denom
bankDenomIter := k.FunTokens.Indexes.BankDenom.ExactMatch(ctx, req.Token)
funTokenMappings := k.FunTokens.Collect(ctx, bankDenomIter)
if len(funTokenMappings) > 0 {
// assumes that there is only one mapping for a given denom
return &evm.QueryTokenMappingResponse{
FunToken: &funTokenMappings[0],
}, nil
}

erc20AddrIter := k.FunTokens.Indexes.ERC20Addr.ExactMatch(ctx, gethcommon.HexToAddress(req.Token))
funTokenMappings = k.FunTokens.Collect(ctx, erc20AddrIter)
if len(funTokenMappings) > 0 {
// assumes that there is only one mapping for a given erc20 address
return &evm.QueryTokenMappingResponse{
FunToken: &funTokenMappings[0],
}, nil
}

return nil, grpcstatus.Errorf(grpccodes.NotFound, "token mapping not found for %s", req.Token)
}
88 changes: 88 additions & 0 deletions x/evm/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,3 +896,91 @@ func (s *Suite) TestTestTraceBlock() {
})
}
}

func (s *KeeperSuite) TestQueryTokenMapping() {

Check failure on line 900 in x/evm/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: KeeperSuite (typecheck)

Check failure on line 900 in x/evm/keeper/grpc_query_test.go

View workflow job for this annotation

GitHub Actions / unit-tests

undefined: KeeperSuite
type In = *evm.QueryTokenMappingRequest
type Out = *evm.QueryTokenMappingResponse
testCases := []TestCase[In, Out]{
{
name: "sad: no token mapping",
scenario: func(deps *evmtest.TestDeps) (req In, wantResp Out) {
req = &evm.QueryTokenMappingRequest{
Token: "unibi",
}
wantResp = &evm.QueryTokenMappingResponse{
FunToken: nil,
}
return req, wantResp
},
wantErr: "token mapping not found for unibi",
},
{
name: "happy: token mapping exists from cosmos coin -> ERC20 token",
setup: func(deps *evmtest.TestDeps) {
_ = deps.K.FunTokens.SafeInsert(
deps.Ctx,
gethcommon.HexToAddress("0xAEf9437FF23D48D73271a41a8A094DEc9ac71477"),
"unibi",
true,
)
},
scenario: func(deps *evmtest.TestDeps) (req In, wantResp Out) {
req = &evm.QueryTokenMappingRequest{
Token: "unibi",
}
wantResp = &evm.QueryTokenMappingResponse{
FunToken: &evm.FunToken{
Erc20Addr: "0xAEf9437FF23D48D73271a41a8A094DEc9ac71477",
BankDenom: "unibi",
IsMadeFromCoin: true,
},
}
return req, wantResp
},
wantErr: "",
},
{
name: "happy: token mapping exists from ERC20 token -> cosmos coin",
setup: func(deps *evmtest.TestDeps) {
_ = deps.K.FunTokens.SafeInsert(
deps.Ctx,
gethcommon.HexToAddress("0xAEf9437FF23D48D73271a41a8A094DEc9ac71477"),
"unibi",
true,
)
},
scenario: func(deps *evmtest.TestDeps) (req In, wantResp Out) {
req = &evm.QueryTokenMappingRequest{
Token: "0xAEf9437FF23D48D73271a41a8A094DEc9ac71477",
}
wantResp = &evm.QueryTokenMappingResponse{
FunToken: &evm.FunToken{
Erc20Addr: "0xAEf9437FF23D48D73271a41a8A094DEc9ac71477",
BankDenom: "unibi",
IsMadeFromCoin: true,
},
}
return req, wantResp
},
wantErr: "",
},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
deps := evmtest.NewTestDeps()
if tc.setup != nil {
tc.setup(&deps)
}
req, wantResp := tc.scenario(&deps)
goCtx := sdk.WrapSDKContext(deps.Ctx)
gotResp, err := deps.K.TokenMapping(goCtx, req)
if tc.wantErr != "" {
s.Require().ErrorContains(err, tc.wantErr)
return
}
s.Assert().NoError(err)
s.EqualValues(wantResp, gotResp)
})
}
}
Loading

0 comments on commit 5a70896

Please sign in to comment.