forked from crypto-org-chain/cronos
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wrapping native tokens in erc20 (crypto-org-chain#34)
* wrapping native tokens in erc20 Closes crypto-org-chain#24 - add dapp tools to nixpkgs - create CronosERC20 contract - embed CronosERC20 in native module - add keeper methods to transfer tokens between native and contract - unit test cleanup cleanup check contract artifacts up-to-date in CI add gomod2nix check make auto-deploy optional update submodule rename CronosERC20 to ModuleERC20 add external contract mapping fix unit tests fix contract test in CI fix upload-artifacts test ConvertERC20ToNative fix unit test, burn shouldn't need approval rename try to fix integration test fix misleading comments change magic number to constant validate native token denom make GetExternalContractByDenom/GetAutoContractByDenom private * ERC20 -> CRC20 * SendCoin -> ConvertCoin * fix unit test * reuse ibc denom validation logic * fix ibc denom in unit test * remove ConvertCoinsFromCRC20ToNative * rename mint_by_native -> mint_by_cronos_module * emit burn event * fix burn and unit test * store contract to denom reversed index
- Loading branch information
Showing
36 changed files
with
1,354 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eval "$(lorri direnv --shell-file integration_tests/shell.nix)" | ||
TMPDIR=/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,8 +47,7 @@ jobs: | |
.mod | ||
.sum | ||
- name: test & coverage report creation | ||
run: | | ||
make test | ||
run: make test | ||
if: "env.GIT_DIFF != ''" | ||
- name: filter out proto files | ||
run: | | ||
|
@@ -75,3 +74,20 @@ jobs: | |
run: nix run -f ./nix gomod2nix -c gomod2nix | ||
- name: check working directory is clean | ||
uses: numtide/clean-git-action@v1 | ||
|
||
contracts: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/[email protected] | ||
- uses: cachix/install-nix-action@v12 | ||
- uses: cachix/cachix-action@v8 | ||
with: | ||
name: cronos | ||
extraPullNames: dapp | ||
signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}" | ||
- name: test contracts | ||
run: make test-cronos-contracts | ||
- name: build contracts | ||
run: make gen-cronos-contracts | ||
- name: check working directory is clean | ||
uses: numtide/clean-git-action@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "contracts/lib/ds-test"] | ||
path = contracts/lib/ds-test | ||
url = https://github.com/dapphub/ds-test | ||
[submodule "contracts/lib/ds-token"] | ||
path = contracts/lib/ds-token | ||
url = https://github.com/dapphub/ds-token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.sol linguist-language=Solidity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
SOLC_VERSION := solc-0.6.11 | ||
all :; dapp --use ${SOLC_VERSION} build | ||
clean :; dapp clean | ||
test :; dapp --use ${SOLC_VERSION} test | ||
deploy :; dapp create CronosERC20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ system ? builtins.currentSystem, pkgs ? import ../nix { inherit system; } }: | ||
pkgs.mkShell { | ||
buildInputs = [ | ||
pkgs.jq | ||
pkgs.dapp | ||
pkgs.solc-static-versions.solc_0_6_11 | ||
]; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pragma solidity ^0.6.11; | ||
|
||
import "ds-token/token.sol"; | ||
|
||
contract ModuleCRC20 is DSToken { | ||
// sha256('cronos')[:20] | ||
address constant module_address = 0x6526B48f897f6e08067dF00A1821d783cbC2af8b; | ||
|
||
constructor(string memory denom, uint8 decimals_) DSToken(denom) public { | ||
decimals = decimals_; | ||
} | ||
|
||
function mint_by_cronos_module(address addr, uint amount) public { | ||
require(msg.sender == module_address); | ||
mint(addr, amount); | ||
} | ||
|
||
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pragma solidity ^0.6.11; | ||
|
||
import "ds-test/test.sol"; | ||
|
||
import "./ModuleCRC20.sol"; | ||
|
||
contract ModuleCRC20Test is DSTest { | ||
ModuleCRC20 token; | ||
|
||
function setUp() public { | ||
token = new ModuleCRC20("gravity0x0", 0); | ||
} | ||
|
||
function test_basic_sanity() public { | ||
assertEq(uint(token.decimals()), uint(0)); | ||
} | ||
|
||
function testFail_mint_by_cronos_module() public { | ||
token.mint_by_cronos_module(0x208AE63c976d145AB328afdcE251c7051D8E452D, 100); | ||
} | ||
|
||
function testFail_burn_by_cronos_module() public { | ||
token.burn_by_cronos_module(0x208AE63c976d145AB328afdcE251c7051D8E452D, 100); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.