-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
7,431 additions
and
0 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,6 @@ | ||
.yarn | ||
artifacts | ||
cache | ||
coverage | ||
node_modules | ||
typechain-types |
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,47 @@ | ||
const path = require("path"); | ||
|
||
/** | ||
* @type {import("eslint").Linter.Config} | ||
*/ | ||
module.exports = { | ||
env: { | ||
browser: false, | ||
es2021: true, | ||
mocha: true, | ||
node: true, | ||
}, | ||
extends: ["plugin:prettier/recommended"], | ||
parser: "@typescript-eslint/parser", | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
}, | ||
plugins: [ | ||
"@typescript-eslint", | ||
"prettier", | ||
"simple-import-sort", | ||
"sort-keys-fix", | ||
"typescript-sort-keys", | ||
], | ||
rules: { | ||
"@typescript-eslint/sort-type-union-intersection-members": "error", | ||
camelcase: "off", | ||
"simple-import-sort/exports": "error", | ||
"simple-import-sort/imports": "error", | ||
"sort-keys-fix/sort-keys-fix": "error", | ||
"typescript-sort-keys/interface": "error", | ||
"typescript-sort-keys/string-enum": "error", | ||
}, | ||
settings: { | ||
"import/parsers": { | ||
"@typescript-eslint/parser": [".js", ".jsx", ".ts", ".tsx", ".d.ts"], | ||
}, | ||
"import/resolver": { | ||
node: { | ||
extensions: [".js", ".jsx", ".ts", ".tsx", ".d.ts"], | ||
}, | ||
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,12 @@ | ||
node_modules | ||
.env | ||
coverage | ||
coverage.json | ||
typechain | ||
typechain-types | ||
|
||
# Hardhat files | ||
cache | ||
artifacts | ||
|
||
access_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 ZetaChain | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,30 @@ | ||
# Hardhat Template for ZetaChain | ||
|
||
This is a simple Hardhat template that provides a starting point for developing | ||
smart contract applications on ZetaChain. | ||
|
||
## Prerequisites | ||
|
||
Before getting started, ensure that you have | ||
[Node.js](https://nodejs.org/en/download) (version 18 or above) and | ||
[Yarn](https://yarnpkg.com/) installed on your system. | ||
|
||
## Getting Started | ||
|
||
To get started, install the necessary dependencies: | ||
|
||
``` | ||
yarn | ||
``` | ||
|
||
## Hardhat Tasks | ||
|
||
This template includes Hardhat tasks that streamline smart contract development. | ||
Learn more about the template and the functionality it provides | ||
[in the docs](https://www.zetachain.com/docs/developers/template/). | ||
|
||
## Next Steps | ||
|
||
To learn more about building decentralized apps on ZetaChain, follow the | ||
tutorials available in | ||
[the introduction to ZetaChain](https://www.zetachain.com/docs/developers/overview/). |
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,96 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.7; | ||
|
||
import "@openzeppelin/contracts/interfaces/IERC20.sol"; | ||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "@zetachain/protocol-contracts/contracts/evm/tools/ZetaInteractor.sol"; | ||
import "@zetachain/protocol-contracts/contracts/evm/interfaces/ZetaInterfaces.sol"; | ||
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; | ||
|
||
contract UniCCM is ZetaInteractor, ZetaReceiver { | ||
event UniCCMEvent(address recipient, address target); | ||
event UniCCMRevertedEvent(address recipient, address target); | ||
|
||
ZetaTokenConsumer private immutable _zetaConsumer; | ||
IERC20 internal immutable _zetaToken; | ||
ISwapRouter private immutable _swapRouter; | ||
|
||
uint24 public constant poolFee = 3000; | ||
|
||
constructor( | ||
address connectorAddress, | ||
address zetaTokenAddress, | ||
address zetaConsumerAddress, | ||
address swapRouterAddress | ||
) ZetaInteractor(connectorAddress) { | ||
_zetaToken = IERC20(zetaTokenAddress); | ||
_zetaConsumer = ZetaTokenConsumer(zetaConsumerAddress); | ||
_swapRouter = ISwapRouter(swapRouterAddress); | ||
} | ||
|
||
function sendMessage( | ||
uint256 destinationChainId, | ||
address recipient, | ||
address target | ||
) external payable { | ||
if (!_isValidChainId(destinationChainId)) | ||
revert InvalidDestinationChainId(); | ||
|
||
uint256 crossChainGas = 2 * (10 ** 18); | ||
uint256 zetaValueAndGas = _zetaConsumer.getZetaFromEth{ | ||
value: msg.value | ||
}(address(this), crossChainGas); | ||
_zetaToken.approve(address(connector), zetaValueAndGas); | ||
|
||
connector.send( | ||
ZetaInterfaces.SendInput({ | ||
destinationChainId: destinationChainId, | ||
destinationAddress: interactorsByChainId[destinationChainId], | ||
destinationGasLimit: 300000, | ||
message: abi.encode(recipient, target), | ||
zetaValueAndGas: zetaValueAndGas, | ||
zetaParams: abi.encode("") | ||
}) | ||
); | ||
} | ||
|
||
function onZetaMessage( | ||
ZetaInterfaces.ZetaMessage calldata zetaMessage | ||
) external override isValidMessageCall(zetaMessage) { | ||
(address recipient, address target) = abi.decode( | ||
zetaMessage.message, | ||
(address, address) | ||
); | ||
|
||
uint256 zetaAmount = zetaMessage.zetaValue; | ||
|
||
_zetaToken.approve(address(_swapRouter), zetaAmount); | ||
|
||
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter | ||
.ExactInputSingleParams({ | ||
tokenIn: address(_zetaToken), | ||
tokenOut: target, | ||
fee: poolFee, | ||
recipient: recipient, | ||
deadline: block.timestamp + 60, | ||
amountIn: zetaAmount, | ||
amountOutMinimum: 0, | ||
sqrtPriceLimitX96: 0 | ||
}); | ||
|
||
_swapRouter.exactInputSingle(params); | ||
|
||
emit UniCCMEvent(recipient, target); | ||
} | ||
|
||
function onZetaRevert( | ||
ZetaInterfaces.ZetaRevert calldata zetaRevert | ||
) external override isValidRevertCall(zetaRevert) { | ||
(address recipient, address target) = abi.decode( | ||
zetaRevert.message, | ||
(address, address) | ||
); | ||
|
||
emit UniCCMRevertedEvent(recipient, target); | ||
} | ||
} |
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 @@ | ||
import "./tasks/interact"; | ||
import "./tasks/deploy"; | ||
import "@nomicfoundation/hardhat-toolbox"; | ||
import "@zetachain/toolkit/tasks"; | ||
|
||
import { getHardhatConfigNetworks } from "@zetachain/networks"; | ||
import { HardhatUserConfig } from "hardhat/config"; | ||
|
||
const config: HardhatUserConfig = { | ||
networks: { | ||
...getHardhatConfigNetworks(), | ||
}, | ||
solidity: "0.8.7", | ||
}; | ||
|
||
export default config; |
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,52 @@ | ||
{ | ||
"name": "example-template", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1", | ||
"lint:fix": "npx eslint . --ext .js,.ts --fix", | ||
"lint": "npx eslint . --ext .js,.ts" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"@ethersproject/abi": "^5.4.7", | ||
"@ethersproject/providers": "^5.4.7", | ||
"@nomicfoundation/hardhat-chai-matchers": "^1.0.0", | ||
"@nomicfoundation/hardhat-foundry": "^1.1.1", | ||
"@nomicfoundation/hardhat-network-helpers": "^1.0.0", | ||
"@nomicfoundation/hardhat-toolbox": "^2.0.0", | ||
"@nomiclabs/hardhat-ethers": "^2.0.0", | ||
"@nomiclabs/hardhat-etherscan": "^3.0.0", | ||
"@typechain/ethers-v5": "^10.1.0", | ||
"@typechain/hardhat": "^6.1.2", | ||
"@types/chai": "^4.2.0", | ||
"@types/mocha": ">=9.1.0", | ||
"@types/node": ">=12.0.0", | ||
"@typescript-eslint/eslint-plugin": "^5.59.9", | ||
"@typescript-eslint/parser": "^5.59.9", | ||
"@zetachain/toolkit": "7.0.0-rc3", | ||
"axios": "^1.3.6", | ||
"chai": "^4.2.0", | ||
"dotenv": "^16.0.3", | ||
"envfile": "^6.18.0", | ||
"eslint": "^8.42.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-import-resolver-typescript": "^3.5.5", | ||
"eslint-plugin-import": "^2.27.5", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"eslint-plugin-simple-import-sort": "^10.0.0", | ||
"eslint-plugin-sort-keys-fix": "^1.1.2", | ||
"eslint-plugin-typescript-sort-keys": "^2.3.0", | ||
"ethers": "^5.4.7", | ||
"hardhat": "^2.17.2", | ||
"hardhat-gas-reporter": "^1.0.8", | ||
"prettier": "^2.8.8", | ||
"solidity-coverage": "^0.8.0", | ||
"ts-node": ">=8.0.0", | ||
"typechain": "^8.1.0", | ||
"typescript": ">=4.5.0" | ||
} | ||
} |
Oops, something went wrong.