-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Address some minor issues in the ZRC2->ERC20 proxy, add tests and ver…
…ification. (#729) * (feat) Documentation (feat) Make zrc_proxy and decimals immutable (feat) Pass on the result of gas() and not 21000 (feat) Burnable ERC20s (feat) Tests for ERC20 proxy contract. (feat) Deployment for ERC20 proxy is now via task and auto-verifies the contract * (fix) We can now apparently overload call() - previously the compiler complained at me for this, but it now seems fine! (fix) Don't limit deployment gas. * (fmt) Usual argument with trunk - commented some useful values future authors may want to use. * Update contracts/experimental/ERC20ProxyForZRC2/contracts/ScillaConnector.sol Co-authored-by: Lukasz Kosiak <[email protected]> * Update contracts/experimental/ERC20ProxyForZRC2/README.md Co-authored-by: Lukasz Kosiak <[email protected]> * Update contracts/experimental/ERC20ProxyForZRC2/test/basicProxyTest.ts Co-authored-by: Lukasz Kosiak <[email protected]> * Update contracts/experimental/ERC20ProxyForZRC2/test/basicProxyTest.ts Co-authored-by: Lukasz Kosiak <[email protected]> * (fix) Hopefully fix PR comments --------- Co-authored-by: Lukasz Kosiak <[email protected]>
- Loading branch information
1 parent
3e37cc5
commit dd4a604
Showing
17 changed files
with
6,315 additions
and
1,023 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,3 @@ | ||
[submodule "contracts/experimental/ERC20ProxyForZRC2/lib/openzeppelin-contracts"] | ||
path = contracts/experimental/ERC20ProxyForZRC2/lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,21 +1,66 @@ | ||
# ERC20ProxyForZRC2 Contract | ||
|
||
This is the contract to deploy a ERC20Proxy for a ZRC2 contract living in the scilla environment. It leverages the precompiles available in Zilliqa to interoperate between the 2 environments. | ||
These contracts allow ZRC-2 tokens to look like ERC-20 tokens. | ||
|
||
Make sure to specify the `zrc2_address` on the deployment file for the ERC20Proxy to be correctly deployed. This allows EVM to execute all desired functions on the ZRC2 as if it were a ERC20. Implementing IERC20 means that all existing DApps and wallets should be compatible with this token. | ||
Unless you want to build using the `zilliqa-developer` version of `zilliqa-js`, or you encounter missing modules issues while running tests, install our dependencies with: | ||
|
||
Make sure to also copy `.env.example` into `.env` and fill in the necessarily variables. Also ensure that `pnpm install` to install any necessary dependencies | ||
```shell | ||
pnpm --ignore-workspace i | ||
``` | ||
|
||
The following are the deployment commands: | ||
## Deploying a proxy | ||
|
||
- Zilliqa Mainnet | ||
You can deploy a proxy with: | ||
|
||
```shell | ||
pnpm exec hardhat run scripts/deploy.ts --network zq | ||
``` | ||
```shell | ||
export PRIVATE_KEY=<...> | ||
pnpm exec hardhat deployProxy 0x5DD38E64dA8f7d541d8aF45fe00bF37F6a2c6195 --network zq-testnet | ||
``` | ||
|
||
- Zilliqa Testnet | ||
If your ZRC-2 is burnable (ie. supports the `Burn()` transition), you can use: | ||
|
||
```shell | ||
pnpm exec hardhat run scripts/deploy.ts --network zq-testnet | ||
``` | ||
```shell | ||
export PRIVATE_KEY=<...> | ||
pnpm exec hardhat deployProxyBurnable 0x5DD38E64dA8f7d541d8aF45fe00bF37F6a2c6195 --network zq-testnet | ||
``` | ||
|
||
The task should automatically verify these contracts to sourcify. | ||
|
||
## Networks | ||
|
||
Various networks are available in the `hardhat.conf.ts`: | ||
|
||
- `zq-testnet` - the Zilliqa 1 testnet | ||
- `zq` - the Zilliqa 1 mainnet | ||
- `local-proxy` - a local proxy. | ||
|
||
You can use the `local-proxy` network and run: | ||
|
||
```sh | ||
mitmweb --mode reverse:https://dev-api.zilliqa.com --no-web-open-browser --listen-port 5556 --web-port 5557 | ||
``` | ||
|
||
To monitor requests. | ||
|
||
## Testing | ||
|
||
To run the tests: | ||
|
||
```shell | ||
export PRIVATE_KEY=<...> | ||
export TEST_KEY_1=<...> | ||
export TEST_KEY_2=<...> | ||
pnpm exec hardhat test --network zq-testnet | ||
``` | ||
|
||
Each test has a number prefix so you can select them individually. | ||
|
||
If you set the `CACHED` environment variable, we will use: | ||
|
||
- `CACHED_ZRC2` - address of a ZRC-2 | ||
- `CACHED_ERC20` - address of an ERC-20 | ||
|
||
To run the tests; this saves you having to redeploy each time. | ||
|
||
This allows you to run tests quickly, without waiting for contract | ||
deployment. |
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
43 changes: 43 additions & 0 deletions
43
contracts/experimental/ERC20ProxyForZRC2/contracts/ZRC2ERC20ProxyBurnable.sol
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,43 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity ^0.8.20; | ||
|
||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; | ||
import {ScillaConnector} from "./ScillaConnector.sol"; | ||
import {ZRC2ERC20Proxy} from "./ZRC2ERC20Proxy.sol"; | ||
|
||
contract ZRC2ERC20ProxyBurnable is ZRC2ERC20Proxy { | ||
using ScillaConnector for address; | ||
using SafeCast for uint256; | ||
|
||
/** Just chains down to the base constructor */ | ||
constructor(address zrc2_address) ZRC2ERC20Proxy(zrc2_address) { } | ||
|
||
/** | ||
* @dev Destroys a `value` amount of tokens from the caller. | ||
* | ||
* See {ERC20-_burn}. | ||
*/ | ||
function burn(uint256 value) public virtual { | ||
uint128 value128 = value.toUint128(); | ||
zrc2_proxy.call("Burn", value128); | ||
} | ||
|
||
/** | ||
* @dev Destroys a `value` amount of tokens from `account`, deducting from | ||
* the caller's allowance. | ||
* | ||
* See {ERC20-_burn} and {ERC20-allowance}. | ||
* | ||
* Requirements: | ||
* | ||
* - the caller must have allowance for ``accounts``'s tokens of at least | ||
* `value`. | ||
*/ | ||
function burnFrom(address account, uint256 value) public virtual { | ||
address self = address(msg.sender); | ||
|
||
_transferFrom(account, self, value); | ||
burn(value); | ||
} | ||
} |
Oops, something went wrong.