Skip to content
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

New Example (Swap to ZETA) and update to toolkit v8 #176

Merged
merged 14 commits into from
May 14, 2024
2 changes: 1 addition & 1 deletion messaging/erc20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@types/node": ">=12.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/toolkit": "7.0.0",
"@zetachain/toolkit": "8.0.0",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand Down
8 changes: 4 additions & 4 deletions messaging/erc20/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1711,10 +1711,10 @@
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-7.0.0-rc1.tgz#588483d1ec70e572b7e40e84ef5b34282b0ab375"
integrity sha512-vgS+Pjh4MysOyw8WbqTQVBsHJYqKvMcdV7cNVqxaTJd/dl2ak7NNvsIeaeUnxQrp8XfQol2B8GXJpVLM6MK/dg==

"@zetachain/toolkit@7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-7.0.0.tgz#7301ccab40c37d3fd8fcc347f99c831ec31b1bd3"
integrity sha512-5cOJVBIEcosF2A2TJbNGFfh4Bob8UcodQII1RdHRstqvV3toZ18r1gVWpLGQ8w2N6T2FCPE8ueN4Q5zH68q20Q==
"@zetachain/toolkit@8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-8.0.0.tgz#e8a582104a84b649b54a9e230d9be44aebc1399f"
integrity sha512-PZ6emUAvypDuU0gCFMFh7UfsBeSwTi2E0zt2is2ezjdQ00OyMWDE2T5pMTvib6EDV5bquONfmJG4rExdx8+gEg==
dependencies:
"@inquirer/prompts" "^2.1.1"
"@inquirer/select" "1.1.3"
Expand Down
2 changes: 1 addition & 1 deletion messaging/message/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@types/node": ">=12.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/toolkit": "7.0.0",
"@zetachain/toolkit": "8.0.0",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand Down
8 changes: 4 additions & 4 deletions messaging/message/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1711,10 +1711,10 @@
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-7.0.0-rc1.tgz#588483d1ec70e572b7e40e84ef5b34282b0ab375"
integrity sha512-vgS+Pjh4MysOyw8WbqTQVBsHJYqKvMcdV7cNVqxaTJd/dl2ak7NNvsIeaeUnxQrp8XfQol2B8GXJpVLM6MK/dg==

"@zetachain/toolkit@7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-7.0.0.tgz#7301ccab40c37d3fd8fcc347f99c831ec31b1bd3"
integrity sha512-5cOJVBIEcosF2A2TJbNGFfh4Bob8UcodQII1RdHRstqvV3toZ18r1gVWpLGQ8w2N6T2FCPE8ueN4Q5zH68q20Q==
"@zetachain/toolkit@8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-8.0.0.tgz#e8a582104a84b649b54a9e230d9be44aebc1399f"
integrity sha512-PZ6emUAvypDuU0gCFMFh7UfsBeSwTi2E0zt2is2ezjdQ00OyMWDE2T5pMTvib6EDV5bquONfmJG4rExdx8+gEg==
dependencies:
"@inquirer/prompts" "^2.1.1"
"@inquirer/select" "1.1.3"
Expand Down
2 changes: 1 addition & 1 deletion messaging/nft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@types/node": ">=12.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/toolkit": "7.0.0",
"@zetachain/toolkit": "8.0.0",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand Down
8 changes: 4 additions & 4 deletions messaging/nft/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1711,10 +1711,10 @@
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-7.0.0-rc1.tgz#588483d1ec70e572b7e40e84ef5b34282b0ab375"
integrity sha512-vgS+Pjh4MysOyw8WbqTQVBsHJYqKvMcdV7cNVqxaTJd/dl2ak7NNvsIeaeUnxQrp8XfQol2B8GXJpVLM6MK/dg==

"@zetachain/toolkit@7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-7.0.0.tgz#7301ccab40c37d3fd8fcc347f99c831ec31b1bd3"
integrity sha512-5cOJVBIEcosF2A2TJbNGFfh4Bob8UcodQII1RdHRstqvV3toZ18r1gVWpLGQ8w2N6T2FCPE8ueN4Q5zH68q20Q==
"@zetachain/toolkit@8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-8.0.0.tgz#e8a582104a84b649b54a9e230d9be44aebc1399f"
integrity sha512-PZ6emUAvypDuU0gCFMFh7UfsBeSwTi2E0zt2is2ezjdQ00OyMWDE2T5pMTvib6EDV5bquONfmJG4rExdx8+gEg==
dependencies:
"@inquirer/prompts" "^2.1.1"
"@inquirer/select" "1.1.3"
Expand Down
2 changes: 1 addition & 1 deletion messaging/zeta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@types/node": ">=12.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/toolkit": "7.0.0",
"@zetachain/toolkit": "8.0.0",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand Down
8 changes: 4 additions & 4 deletions messaging/zeta/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1711,10 +1711,10 @@
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-7.0.0-rc1.tgz#588483d1ec70e572b7e40e84ef5b34282b0ab375"
integrity sha512-vgS+Pjh4MysOyw8WbqTQVBsHJYqKvMcdV7cNVqxaTJd/dl2ak7NNvsIeaeUnxQrp8XfQol2B8GXJpVLM6MK/dg==

"@zetachain/toolkit@7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-7.0.0.tgz#7301ccab40c37d3fd8fcc347f99c831ec31b1bd3"
integrity sha512-5cOJVBIEcosF2A2TJbNGFfh4Bob8UcodQII1RdHRstqvV3toZ18r1gVWpLGQ8w2N6T2FCPE8ueN4Q5zH68q20Q==
"@zetachain/toolkit@8.0.0":
version "8.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-8.0.0.tgz#e8a582104a84b649b54a9e230d9be44aebc1399f"
integrity sha512-PZ6emUAvypDuU0gCFMFh7UfsBeSwTi2E0zt2is2ezjdQ00OyMWDE2T5pMTvib6EDV5bquONfmJG4rExdx8+gEg==
dependencies:
"@inquirer/prompts" "^2.1.1"
"@inquirer/select" "1.1.3"
Expand Down
31 changes: 10 additions & 21 deletions omnichain/multioutput/contracts/Multioutput.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,31 @@ import "@zetachain/protocol-contracts/contracts/zevm/interfaces/zContract.sol";
import "@zetachain/toolkit/contracts/BytesHelperLib.sol";
import "@zetachain/toolkit/contracts/SwapHelperLib.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@zetachain/toolkit/contracts/OnlySystem.sol";

contract Multioutput is zContract, Ownable {
contract Multioutput is zContract, Ownable, OnlySystem {
error NoAvailableTransfers();
error InvalidRecipient();
error FetchingBTCZRC20Failed();

event Withdrawal(address, uint256, bytes);

SystemContract public immutable systemContract;
SystemContract public systemContract;

uint256 constant BITCOIN = 18332;

constructor(address systemContractAddress) {
systemContract = SystemContract(systemContractAddress);
}

modifier onlySystem() {
require(
msg.sender == address(systemContract),
"Only system contract can call this function"
);
_;
}

function onCrossChainCall(
zContext calldata context,
address zrc20,
uint256 amount,
bytes calldata message
) external virtual override onlySystem {
address btcToken = systemContract.gasCoinZRC20ByChainId(BITCOIN);
if (btcToken == address(0)) revert FetchingBTCZRC20Failed();
) external virtual override onlySystem(systemContract) {
if (systemContract.gasCoinZRC20ByChainId(BITCOIN) == address(0))
revert FetchingBTCZRC20Failed();

(
address evmRecipient,
Expand Down Expand Up @@ -69,7 +62,7 @@ contract Multioutput is zContract, Ownable {
BytesHelperLib.addressToBytes(evmRecipient)
);

if (targetZRC20 == btcToken) {
if (targetZRC20 == systemContract.gasCoinZRC20ByChainId(BITCOIN)) {
if (btcRecipient.length == 0) revert InvalidRecipient();
recipient = abi.encodePacked(btcRecipient);
}
Expand All @@ -88,19 +81,15 @@ contract Multioutput is zContract, Ownable {
.withdrawGasFee();

uint256 inputForGas = SwapHelperLib.swapTokensForExactTokens(
systemContract.wZetaContractAddress(),
systemContract.uniswapv2FactoryAddress(),
systemContract.uniswapv2Router02Address(),
systemContract,
zrc20,
gasFee,
gasZRC20,
amountToTransfer
);

uint256 outputAmount = SwapHelperLib._doSwap(
systemContract.wZetaContractAddress(),
systemContract.uniswapv2FactoryAddress(),
systemContract.uniswapv2Router02Address(),
uint256 outputAmount = SwapHelperLib.swapExactTokensForTokens(
systemContract,
zrc20,
amountToTransfer - inputForGas,
targetZRC20,
Expand Down
4 changes: 2 additions & 2 deletions omnichain/multioutput/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/node": ">=12.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/toolkit": "7.0.0",
"@zetachain/toolkit": "8.0.0",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand All @@ -41,7 +41,7 @@
"eslint-plugin-sort-keys-fix": "^1.1.2",
"eslint-plugin-typescript-sort-keys": "^2.3.0",
"ethers": "^5.4.7",
"hardhat": "^2.14.0",
"hardhat": "^2.17.2",
"hardhat-gas-reporter": "^1.0.8",
"prettier": "^2.8.8",
"solidity-coverage": "^0.8.0",
Expand Down
Loading
Loading