Skip to content

Commit

Permalink
Problem: gravity bridge hooks and native token wrapping not connected (
Browse files Browse the repository at this point in the history
…#59)

Closes #58

add denom-by-contract query cmd

test send back to ethereum

fix bidirectional e2e test

fix proto-lint

changelog

make proto-gen

Update x/cronos/client/cli/query.go

Co-authored-by: Thomas Nguy <81727899+thomas-nguy@users.noreply.github.com>

Update x/cronos/client/cli/query.go

Co-authored-by: Thomas Nguy <81727899+thomas-nguy@users.noreply.github.com>

Update x/cronos/keeper/grpc_query.go

Co-authored-by: Thomas Nguy <81727899+thomas-nguy@users.noreply.github.com>

fix contract not found error

Update integration_tests/utils.py

fix integration test

update contract
  • Loading branch information
yihuang authored Sep 13, 2021
1 parent da4bd2b commit 66d9e40
Show file tree
Hide file tree
Showing 26 changed files with 1,711 additions and 158 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ release/
/build
/coverage.txt
__pycache__
/dist

# nix
/result
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
- [cronos#11](https://github.com/crypto-org-chain/cronos/pull/11) embed gravity bridge module
- [cronos#35](https://github.com/crypto-org-chain/cronos/pull/35) add support for ibc hook
- [cronos#55](https://github.com/crypto-org-chain/cronos/pull/55) add support for ibc token conversion to crc20

- [cronos#45](https://github.com/crypto-org-chain/cronos/pull/45) Allow evm contract to call bank send and gravity send
- [cronos#45](https://github.com/crypto-org-chain/cronos/pull/45) Allow evm contract to call bank send and gravity send
- [cronos#59](https://github.com/crypto-org-chain/cronos/pull/59) gravity bridged tokens are converted to crc20
automatically

*August 19, 2021*

Expand Down
22 changes: 11 additions & 11 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,16 @@ func New(
tracer, bApp.Trace(), // debug EVM based on Baseapp options
)

gravityKeeper := gravitykeeper.NewKeeper(
appCodec,
keys[gravitytypes.StoreKey],
app.GetSubspace(gravitytypes.ModuleName),
app.AccountKeeper,
stakingKeeper,
app.BankKeeper,
app.SlashingKeeper,
sdk.DefaultPowerReduction,
)
// this line is used by starport scaffolding # stargate/app/keeperDefinition

app.CronosKeeper = *cronosmodulekeeper.NewKeeper(
Expand All @@ -400,6 +410,7 @@ func New(
app.GetSubspace(cronosmoduletypes.ModuleName),
app.BankKeeper,
app.TransferKeeper,
gravityKeeper,
app.EvmKeeper,
)
cronosModule := cronosmodule.NewAppModule(appCodec, app.CronosKeeper)
Expand All @@ -413,17 +424,6 @@ func New(
&stakingKeeper, govRouter,
)

gravityKeeper := gravitykeeper.NewKeeper(
appCodec,
keys[gravitytypes.StoreKey],
app.GetSubspace(gravitytypes.ModuleName),
app.AccountKeeper,
stakingKeeper,
app.BankKeeper,
app.SlashingKeeper,
sdk.DefaultPowerReduction,
)

app.GravityKeeper = *gravityKeeper.SetHooks(app.CronosKeeper)

app.EvmKeeper.SetHooks(cronosmodulekeeper.NewLogProcessEvmHook(
Expand Down
19 changes: 12 additions & 7 deletions contracts/src/ModuleCRC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ contract ModuleCRC20 is DSToken {
denom = denom_;
}

// unsafe_burn burn tokens without user's approval and authentication, used internally
function unsafe_burn(address addr, uint amount) private {
// Deduct user's balance without approval
require(balanceOf[addr] >= amount, "ds-token-insufficient-balance");
balanceOf[addr] = sub(balanceOf[addr], amount);
totalSupply = sub(totalSupply, amount);
emit Burn(addr, amount);
}

function native_denom() public view returns (string memory) {
return denom;
}
Expand All @@ -25,16 +34,12 @@ contract ModuleCRC20 is DSToken {

function burn_by_cronos_module(address addr, uint amount) public {
require(msg.sender == module_address);
// Deduct user's balance without approval
require(balanceOf[addr] >= amount, "ds-token-insufficient-balance");
balanceOf[addr] = sub(balanceOf[addr], amount);
totalSupply = sub(totalSupply, amount);
emit Burn(addr, amount);
unsafe_burn(addr, amount);
}

// send to ethereum through gravity bridge
function send_to_ethereum(address recipient, uint amount, uint bridge_fee) public {
burn(msg.sender, add(amount, bridge_fee));
function send_to_ethereum(address recipient, uint amount, uint bridge_fee) external {
unsafe_burn(msg.sender, add(amount, bridge_fee));
emit __CronosSendToEthereum(recipient, amount, bridge_fee);
}
}
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ go 1.16
require (
github.com/armon/go-metrics v0.3.9
github.com/cosmos/cosmos-sdk v0.44.0
github.com/cosmos/ibc-go v1.0.1
github.com/cosmos/ibc-go v1.1.0
github.com/ethereum/go-ethereum v1.10.3
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/peggyjv/gravity-bridge/module v0.2.0
Expand All @@ -18,8 +19,8 @@ require (
github.com/tendermint/spm v0.0.0-20210524110815-6d7452d2dc4a
github.com/tendermint/tendermint v0.34.12
github.com/tendermint/tm-db v0.6.4
github.com/tharsis/ethermint v0.4.2-0.20210902174739-5fac39db38ed
google.golang.org/genproto v0.0.0-20210825212027-de86158e7fda
github.com/tharsis/ethermint v0.4.2-0.20210905110306-26c5eabb1893
google.golang.org/genproto v0.0.0-20210903162649-d08c68adba83
google.golang.org/grpc v1.40.0
gopkg.in/yaml.v2 v2.4.0
)
Expand All @@ -33,3 +34,6 @@ replace github.com/99designs/keyring => github.com/crypto-org-chain/keyring v1.1

// TODO: remove when middleware will be implemented
replace github.com/cosmos/ibc-go => github.com/crypto-org-chain/ibc-go v1.0.1-hooks

// FIXME: update after PR merged: https://github.com/PeggyJV/gravity-bridge/pull/182
replace github.com/peggyjv/gravity-bridge/module => github.com/yihuang/gravity-bridge/module v0.1.22-0.20210908191543-71021d1bfff2
Loading

0 comments on commit 66d9e40

Please sign in to comment.