-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Develop cross chain swap * add deploy script * improve swap * deploy to athens2 * remove unsed code * renames * update readme
- Loading branch information
1 parent
16b56c7
commit 07e33f1
Showing
19 changed files
with
599 additions
and
8 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
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
Empty file.
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,23 @@ | ||
const path = require("path"); | ||
|
||
const OFF = 0; | ||
|
||
module.exports = { | ||
env: { | ||
browser: false, | ||
es2021: true, | ||
mocha: true, | ||
node: true, | ||
}, | ||
extends: ["../../.eslintrc.js"], | ||
rules: { | ||
"no-console": OFF, | ||
}, | ||
settings: { | ||
"import/resolver": { | ||
typescript: { | ||
project: path.join(__dirname, "tsconfig.json"), | ||
}, | ||
}, | ||
}, | ||
}; |
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,16 @@ | ||
# ZetaEVM contracts | ||
|
||
> ⚠️ The contracts **are not audited yet**, use at your own risk. | ||
## Environment variables | ||
|
||
Follow the template in `.env.example`. | ||
|
||
* The private key should **not** include `0x`. | ||
* To verify your contracts, you'll need api keys both in BSCScan and Etherscan. | ||
|
||
## Running Tests | ||
|
||
```bash | ||
yarn test | ||
``` |
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,31 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.7; | ||
|
||
interface IZRC4 { | ||
function totalSupply() external view returns (uint256); | ||
|
||
function balanceOf(address account) external view returns (uint256); | ||
|
||
function transfer(address recipient, uint256 amount) external returns (bool); | ||
|
||
function allowance(address owner, address spender) external view returns (uint256); | ||
|
||
function approve(address spender, uint256 amount) external returns (bool); | ||
|
||
function transferFrom( | ||
address sender, | ||
address recipient, | ||
uint256 amount | ||
) external returns (bool); | ||
|
||
function deposit(address to, uint256 amount) external returns (bool); | ||
|
||
function withdraw(bytes memory to, uint256 amount) external returns (bool); | ||
|
||
function withdrawGasFee() external view returns (address, uint256); | ||
|
||
event Transfer(address indexed from, address indexed to, uint256 value); | ||
event Approval(address indexed owner, address indexed spender, uint256 value); | ||
event Deposit(bytes from, address indexed to, uint256 value); | ||
event Withdrawal(address indexed from, bytes to, uint256 value); | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/zevm-contracts/contracts/interfaces/zContract.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,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.7; | ||
|
||
interface zContract { | ||
function onCrossChainCall( | ||
address zrc4, | ||
uint256 amount, | ||
bytes calldata message | ||
) external; | ||
} |
115 changes: 115 additions & 0 deletions
115
packages/zevm-contracts/contracts/system/SystemContract.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,115 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.7; | ||
|
||
import "../interfaces/zContract.sol"; | ||
import "../interfaces/IZRC4.sol"; | ||
|
||
interface SystemContractErrors { | ||
error CallerIsNotFungibleModule(); | ||
|
||
error InvalidTarget(); | ||
|
||
error CantBeIdenticalAddresses(); | ||
|
||
error CantBeZeroAddress(); | ||
} | ||
|
||
contract SystemContract is SystemContractErrors { | ||
mapping(uint256 => uint256) public gasPriceByChainId; | ||
mapping(uint256 => address) public gasCoinZRC4ByChainId; | ||
mapping(uint256 => address) public gasZetaPoolByChainId; | ||
|
||
address public constant FUNGIBLE_MODULE_ADDRESS = 0x735b14BB79463307AAcBED86DAf3322B1e6226aB; | ||
address public wZetaContractAddress; | ||
address public uniswapv2FactoryAddress; | ||
address public uniswapv2Router02Address; | ||
|
||
event SystemContractDeployed(); | ||
event SetGasPrice(uint256, uint256); | ||
event SetGasCoin(uint256, address); | ||
event SetGasZetaPool(uint256, address); | ||
event SetWZeta(address); | ||
|
||
constructor( | ||
address wzeta_, | ||
address uniswapv2Factory_, | ||
address uniswapv2Router02_ | ||
) { | ||
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule(); | ||
wZetaContractAddress = wzeta_; | ||
uniswapv2FactoryAddress = uniswapv2Factory_; | ||
uniswapv2Router02Address = uniswapv2Router02_; | ||
emit SystemContractDeployed(); | ||
} | ||
|
||
// deposit foreign coins into ZRC4 and call user specified contract on zEVM | ||
function depositAndCall( | ||
address zrc4, | ||
uint256 amount, | ||
address target, | ||
bytes calldata message | ||
) external { | ||
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule(); | ||
if (target == FUNGIBLE_MODULE_ADDRESS || target == address(this)) revert InvalidTarget(); | ||
|
||
IZRC4(zrc4).deposit(target, amount); | ||
zContract(target).onCrossChainCall(zrc4, amount, message); | ||
} | ||
|
||
// returns sorted token addresses, used to handle return values from pairs sorted in this order | ||
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) { | ||
if (tokenA == tokenB) revert CantBeIdenticalAddresses(); | ||
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA); | ||
if (token0 == address(0)) revert CantBeZeroAddress(); | ||
} | ||
|
||
// calculates the CREATE2 address for a pair without making any external calls | ||
function uniswapv2PairFor( | ||
address factory, | ||
address tokenA, | ||
address tokenB | ||
) public pure returns (address pair) { | ||
(address token0, address token1) = sortTokens(tokenA, tokenB); | ||
pair = address( | ||
uint160( | ||
uint256( | ||
keccak256( | ||
abi.encodePacked( | ||
hex"ff", | ||
factory, | ||
keccak256(abi.encodePacked(token0, token1)), | ||
hex"96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f" // init code hash | ||
) | ||
) | ||
) | ||
) | ||
); | ||
} | ||
|
||
// fungible module updates the gas price oracle periodically | ||
function setGasPrice(uint256 chainID, uint256 price) external { | ||
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule(); | ||
gasPriceByChainId[chainID] = price; | ||
emit SetGasPrice(chainID, price); | ||
} | ||
|
||
function setGasCoinZRC4(uint256 chainID, address zrc4) external { | ||
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule(); | ||
gasCoinZRC4ByChainId[chainID] = zrc4; | ||
emit SetGasCoin(chainID, zrc4); | ||
} | ||
|
||
// set the pool wzeta/erc20 address | ||
function setGasZetaPool(uint256 chainID, address erc20) external { | ||
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule(); | ||
address pool = uniswapv2PairFor(uniswapv2FactoryAddress, wZetaContractAddress, erc20); | ||
gasZetaPoolByChainId[chainID] = pool; | ||
emit SetGasZetaPool(chainID, pool); | ||
} | ||
|
||
function setWZETAContractAddress(address addr) external { | ||
if (msg.sender != FUNGIBLE_MODULE_ADDRESS) revert CallerIsNotFungibleModule(); | ||
wZetaContractAddress = addr; | ||
emit SetWZeta(wZetaContractAddress); | ||
} | ||
} |
Oops, something went wrong.