-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Address ERC2 wrapper improvements #727
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9f1506a
Start of swinging ERC20 proxy over to foundry.
rrw-zilliqa 03306e7
(feat) Add openzeppelin-contracts to ERC20ProxyForZRC2
rrw-zilliqa 29d9b64
(feat) Cut back over to hardhat so we can test.
rrw-zilliqa df8530f
(feat) Can now start running tests (hopefully). WIP for transit
rrw-zilliqa d2727ba
(feat) A test suite at last!
rrw-zilliqa f1d3346
(feat) Documentation
rrw-zilliqa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,64 @@ | ||
# 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`, 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 a built-in | ||
cached contract deployment whose addresses appear in the source - | ||
please update it if you change the contracts. | ||
|
||
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.callu128("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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW Solidity allows function overloading based on parameter types, so we could still name this
call
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could, but when I try it, it fails to resolve .. I'll try again, but :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmph. It works now - sorry & thanks for the spot! Will update - confusingly, the other PR .. sorry!