From 7e98598bdb24482731f2e7dcc6568f374d8b7ab6 Mon Sep 17 00:00:00 2001 From: adu Date: Fri, 13 Dec 2024 10:29:39 +0800 Subject: [PATCH] test: integration test pass --- package-lock.json | 258 ++++++++++++++++++- package.json | 8 +- script/10_DeployExocoreGatewayOnly.s.sol | 2 +- script/11_SetPeers.s.sol | 2 +- script/12_RedeployClientChainGateway.s.sol | 2 +- script/13_DepositValidator.s.sol | 4 +- script/14_CorrectBootstrapErrors.s.sol | 2 +- script/17_WithdrawalValidator.s.sol | 4 +- script/18_SimulateReceive.s.sol | 2 +- script/3_Setup.s.sol | 4 +- script/4_Deposit.s.sol | 4 +- script/5_Withdraw.s.sol | 4 +- script/6_CreateExoCapsule.s.sol | 4 +- script/7_DeployBootstrap.s.sol | 2 +- script/BaseScript.sol | 2 +- script/TestPrecompileErrorFixed.s.sol | 4 +- script/TestPrecompileErrorFixed_Deploy.s.sol | 4 +- script/deployBeaconOracle.s.sol | 2 +- src/interfaces/precompiles/IAssets.sol | 22 +- test/foundry/Delegation.t.sol | 4 +- test/foundry/DepositThenDelegateTo.t.sol | 4 +- test/foundry/DepositWithdrawPrinciple.t.sol | 2 +- test/foundry/ExocoreDeployer.t.sol | 4 +- test/foundry/Governance.t.sol | 4 +- test/foundry/TvlLimits.t.sol | 2 +- test/foundry/WithdrawReward.t.sol | 2 +- test/foundry/unit/ClientChainGateway.t.sol | 6 +- test/foundry/unit/ExocoreGateway.t.sol | 2 +- test/hardhat/integration/btc-stake.test.js | 137 ++++++++++ test/mocks/AssetsMock.sol | 37 +++ test/mocks/ExocoreGatewayMock.sol | 6 +- 31 files changed, 491 insertions(+), 55 deletions(-) diff --git a/package-lock.json b/package-lock.json index 192f4c6d..2a2f9de2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,12 +10,15 @@ "license": "ISC", "devDependencies": { "@cosmjs/proto-signing": "^0.32.4", - "@cosmjs/stargate": "^0.32.4", + "@cosmjs/stargate": "^0.32.2", "@evmos/address-converter": "^0.1.9", + "@evmos/evmosjs": "github:evmos/evmosjs#main", + "@evmos/proto": "^0.2.1", "@nomicfoundation/hardhat-foundry": "^1.1.3", "@nomicfoundation/hardhat-toolbox": "^5.0.0", "bip39": "^3.1.0", "dotenv": "^16.4.7", + "esm": "^3.2.25", "ethereumjs-wallet": "^1.0.2", "hardhat": "^2.22.17" } @@ -27,6 +30,197 @@ "dev": true, "peer": true }, + "node_modules/@buf/cosmos_cosmos-proto.bufbuild_es": { + "version": "1.0.0-20211202220400-1935555c206d.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_cosmos-proto.bufbuild_es/-/cosmos_cosmos-proto.bufbuild_es-1.0.0-20211202220400-1935555c206d.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/cosmos_cosmos-sdk.bufbuild_es": { + "version": "1.0.0-20240220165237-05419252bcc2.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_cosmos-sdk.bufbuild_es/-/cosmos_cosmos-sdk.bufbuild_es-1.0.0-20240220165237-05419252bcc2.1.tgz", + "dev": true, + "dependencies": { + "@buf/cosmos_cosmos-proto.bufbuild_es": "1.0.0-20211202220400-1935555c206d.1", + "@buf/cosmos_gogo-proto.bufbuild_es": "1.0.0-20240130113600-88ef6483f90f.1", + "@buf/googleapis_googleapis.bufbuild_es": "1.0.0-20240207202044-7e6f6e774e29.1", + "@buf/protocolbuffers_wellknowntypes.bufbuild_es": "1.0.0-20230509212704-657250e6a396.1", + "@buf/tendermint_tendermint.bufbuild_es": "1.0.0-20231117195010-33ed361a9051.1" + }, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/cosmos_gogo-proto.bufbuild_es": { + "version": "1.0.0-20240130113600-88ef6483f90f.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_gogo-proto.bufbuild_es/-/cosmos_gogo-proto.bufbuild_es-1.0.0-20240130113600-88ef6483f90f.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/cosmos_ibc.bufbuild_es": { + "version": "1.0.0-20241210102225-a7af51c19a5c.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_ibc.bufbuild_es/-/cosmos_ibc.bufbuild_es-1.0.0-20241210102225-a7af51c19a5c.1.tgz", + "dev": true, + "dependencies": { + "@buf/cosmos_cosmos-proto.bufbuild_es": "1.0.0-20211202220400-1935555c206d.1", + "@buf/cosmos_cosmos-sdk.bufbuild_es": "1.0.0-20230719110346-aa25660f4ff7.1", + "@buf/cosmos_gogo-proto.bufbuild_es": "1.0.0-20221020125208-34d970b699f8.1", + "@buf/cosmos_ics23.bufbuild_es": "1.0.0-20221207100654-55085f7c710a.1", + "@buf/googleapis_googleapis.bufbuild_es": "1.0.0-20220908150232-8d7204855ec1.1" + }, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/cosmos_ibc.bufbuild_es/node_modules/@buf/cosmos_cosmos-sdk.bufbuild_es": { + "version": "1.0.0-20230719110346-aa25660f4ff7.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_cosmos-sdk.bufbuild_es/-/cosmos_cosmos-sdk.bufbuild_es-1.0.0-20230719110346-aa25660f4ff7.1.tgz", + "dev": true, + "dependencies": { + "@buf/cosmos_cosmos-proto.bufbuild_es": "1.0.0-20211202220400-1935555c206d.1", + "@buf/cosmos_gogo-proto.bufbuild_es": "1.0.0-20230509103710-5e5b9fdd0180.1", + "@buf/googleapis_googleapis.bufbuild_es": "1.0.0-20230502210827-cc916c318597.1" + }, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/cosmos_ibc.bufbuild_es/node_modules/@buf/cosmos_cosmos-sdk.bufbuild_es/node_modules/@buf/cosmos_gogo-proto.bufbuild_es": { + "version": "1.0.0-20230509103710-5e5b9fdd0180.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_gogo-proto.bufbuild_es/-/cosmos_gogo-proto.bufbuild_es-1.0.0-20230509103710-5e5b9fdd0180.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/cosmos_ibc.bufbuild_es/node_modules/@buf/cosmos_cosmos-sdk.bufbuild_es/node_modules/@buf/googleapis_googleapis.bufbuild_es": { + "version": "1.0.0-20230502210827-cc916c318597.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/googleapis_googleapis.bufbuild_es/-/googleapis_googleapis.bufbuild_es-1.0.0-20230502210827-cc916c318597.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/cosmos_ibc.bufbuild_es/node_modules/@buf/cosmos_gogo-proto.bufbuild_es": { + "version": "1.0.0-20221020125208-34d970b699f8.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_gogo-proto.bufbuild_es/-/cosmos_gogo-proto.bufbuild_es-1.0.0-20221020125208-34d970b699f8.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/cosmos_ibc.bufbuild_es/node_modules/@buf/googleapis_googleapis.bufbuild_es": { + "version": "1.0.0-20220908150232-8d7204855ec1.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/googleapis_googleapis.bufbuild_es/-/googleapis_googleapis.bufbuild_es-1.0.0-20220908150232-8d7204855ec1.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/cosmos_ics23.bufbuild_es": { + "version": "1.0.0-20221207100654-55085f7c710a.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_ics23.bufbuild_es/-/cosmos_ics23.bufbuild_es-1.0.0-20221207100654-55085f7c710a.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/evmos_evmos.bufbuild_es": { + "version": "1.2.0-20241008121741-fda6f6b3cb58.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/evmos_evmos.bufbuild_es/-/evmos_evmos.bufbuild_es-1.2.0-20241008121741-fda6f6b3cb58.1.tgz", + "dev": true, + "dependencies": { + "@buf/cosmos_cosmos-proto.bufbuild_es": "1.2.0-20211202220400-1935555c206d.1", + "@buf/cosmos_cosmos-sdk.bufbuild_es": "1.2.0-20221115045553-508e19f5f375.1", + "@buf/cosmos_gogo-proto.bufbuild_es": "1.2.0-20221020125208-34d970b699f8.1", + "@buf/googleapis_googleapis.bufbuild_es": "1.2.0-20221025150512-783e4b5374fa.1" + }, + "peerDependencies": { + "@bufbuild/protobuf": "^1.2.0" + } + }, + "node_modules/@buf/evmos_evmos.bufbuild_es/node_modules/@buf/cosmos_cosmos-proto.bufbuild_es": { + "version": "1.2.0-20211202220400-1935555c206d.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_cosmos-proto.bufbuild_es/-/cosmos_cosmos-proto.bufbuild_es-1.2.0-20211202220400-1935555c206d.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.2.0" + } + }, + "node_modules/@buf/evmos_evmos.bufbuild_es/node_modules/@buf/cosmos_cosmos-sdk.bufbuild_es": { + "version": "1.2.0-20221115045553-508e19f5f375.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_cosmos-sdk.bufbuild_es/-/cosmos_cosmos-sdk.bufbuild_es-1.2.0-20221115045553-508e19f5f375.1.tgz", + "dev": true, + "dependencies": { + "@buf/cosmos_cosmos-proto.bufbuild_es": "1.2.0-20211202220400-1935555c206d.1", + "@buf/cosmos_gogo-proto.bufbuild_es": "1.2.0-20221020125208-34d970b699f8.1", + "@buf/googleapis_googleapis.bufbuild_es": "1.2.0-20221025150512-783e4b5374fa.1" + }, + "peerDependencies": { + "@bufbuild/protobuf": "^1.2.0" + } + }, + "node_modules/@buf/evmos_evmos.bufbuild_es/node_modules/@buf/cosmos_gogo-proto.bufbuild_es": { + "version": "1.2.0-20221020125208-34d970b699f8.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_gogo-proto.bufbuild_es/-/cosmos_gogo-proto.bufbuild_es-1.2.0-20221020125208-34d970b699f8.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.2.0" + } + }, + "node_modules/@buf/evmos_evmos.bufbuild_es/node_modules/@buf/googleapis_googleapis.bufbuild_es": { + "version": "1.2.0-20221025150512-783e4b5374fa.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/googleapis_googleapis.bufbuild_es/-/googleapis_googleapis.bufbuild_es-1.2.0-20221025150512-783e4b5374fa.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.2.0" + } + }, + "node_modules/@buf/googleapis_googleapis.bufbuild_es": { + "version": "1.0.0-20240207202044-7e6f6e774e29.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/googleapis_googleapis.bufbuild_es/-/googleapis_googleapis.bufbuild_es-1.0.0-20240207202044-7e6f6e774e29.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/protocolbuffers_wellknowntypes.bufbuild_es": { + "version": "1.0.0-20230509212704-657250e6a396.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/protocolbuffers_wellknowntypes.bufbuild_es/-/protocolbuffers_wellknowntypes.bufbuild_es-1.0.0-20230509212704-657250e6a396.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/tendermint_tendermint.bufbuild_es": { + "version": "1.0.0-20231117195010-33ed361a9051.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/tendermint_tendermint.bufbuild_es/-/tendermint_tendermint.bufbuild_es-1.0.0-20231117195010-33ed361a9051.1.tgz", + "dev": true, + "dependencies": { + "@buf/cosmos_gogo-proto.bufbuild_es": "1.0.0-20230509103710-5e5b9fdd0180.1" + }, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@buf/tendermint_tendermint.bufbuild_es/node_modules/@buf/cosmos_gogo-proto.bufbuild_es": { + "version": "1.0.0-20230509103710-5e5b9fdd0180.1", + "resolved": "https://buf.build/gen/npm/v1/@buf/cosmos_gogo-proto.bufbuild_es/-/cosmos_gogo-proto.bufbuild_es-1.0.0-20230509103710-5e5b9fdd0180.1.tgz", + "dev": true, + "peerDependencies": { + "@bufbuild/protobuf": "^1.0.0" + } + }, + "node_modules/@bufbuild/protobuf": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@bufbuild/protobuf/-/protobuf-1.10.0.tgz", + "integrity": "sha512-QDdVFLoN93Zjg36NoQPZfsVH9tZew7wKDKyV5qRdj8ntT4wQCOradQjRaTdwMhWUYsgKsvCINKKm87FdEk96Ag==", + "dev": true + }, "node_modules/@confio/ics23": { "version": "0.6.8", "resolved": "https://registry.npmjs.org/@confio/ics23/-/ics23-0.6.8.tgz", @@ -142,19 +336,19 @@ } }, "node_modules/@cosmjs/stargate": { - "version": "0.32.4", - "resolved": "https://registry.npmjs.org/@cosmjs/stargate/-/stargate-0.32.4.tgz", - "integrity": "sha512-usj08LxBSsPRq9sbpCeVdyLx2guEcOHfJS9mHGCLCXpdAPEIEQEtWLDpEUc0LEhWOx6+k/ChXTc5NpFkdrtGUQ==", + "version": "0.32.2", + "resolved": "https://registry.npmjs.org/@cosmjs/stargate/-/stargate-0.32.2.tgz", + "integrity": "sha512-AsJa29fT7Jd4xt9Ai+HMqhyj7UQu7fyYKdXj/8+/9PD74xe6lZSYhQPcitUmMLJ1ckKPgXSk5Dd2LbsQT0IhZg==", "dev": true, "dependencies": { "@confio/ics23": "^0.6.8", - "@cosmjs/amino": "^0.32.4", - "@cosmjs/encoding": "^0.32.4", - "@cosmjs/math": "^0.32.4", - "@cosmjs/proto-signing": "^0.32.4", - "@cosmjs/stream": "^0.32.4", - "@cosmjs/tendermint-rpc": "^0.32.4", - "@cosmjs/utils": "^0.32.4", + "@cosmjs/amino": "^0.32.2", + "@cosmjs/encoding": "^0.32.2", + "@cosmjs/math": "^0.32.2", + "@cosmjs/proto-signing": "^0.32.2", + "@cosmjs/stream": "^0.32.2", + "@cosmjs/tendermint-rpc": "^0.32.2", + "@cosmjs/utils": "^0.32.2", "cosmjs-types": "^0.9.0", "xstream": "^11.14.0" } @@ -1033,6 +1227,39 @@ "integrity": "sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==", "dev": true }, + "node_modules/@evmos/evmosjs": { + "version": "0.1.0", + "resolved": "git+ssh://git@github.com/evmos/evmosjs.git#e47e44b1683ffa57737cee2f6abbd138436d9fc3", + "dev": true, + "workspaces": { + "packages": [ + "packages/*" + ] + } + }, + "node_modules/@evmos/proto": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/@evmos/proto/-/proto-0.2.1.tgz", + "integrity": "sha512-FvloeY4LqLn7p9s7MY32lhpTiiNItlBySxLANUgpx/08rWR8wXo3CBYay/oFbbDVwgaxhQyjsVx2M3vGoEfLow==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "@buf/cosmos_cosmos-sdk.bufbuild_es": "^1.0.0-20230125164018-54d184078b88.1", + "@buf/cosmos_ibc.bufbuild_es": "^1.0.0-20230127093016-72d4bdec25a0.1", + "@buf/evmos_evmos.bufbuild_es": "^1.2.0-20230315212311-c66c6f141d04.1", + "@bufbuild/protobuf": "^1.0.0", + "@types/node": "^17.0.21", + "link-module-alias": "^1.2.0", + "sha3": "^2.1.4", + "shx": "^0.3.4" + } + }, + "node_modules/@evmos/proto/node_modules/@types/node": { + "version": "17.0.45", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.45.tgz", + "integrity": "sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==", + "dev": true + }, "node_modules/@fastify/busboy": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.0.tgz", @@ -3439,6 +3666,15 @@ "source-map": "~0.2.0" } }, + "node_modules/esm": { + "version": "3.2.25", + "resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz", + "integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/esprima": { "version": "2.7.3", "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz", diff --git a/package.json b/package.json index 96cf9c52..8ad66122 100644 --- a/package.json +++ b/package.json @@ -16,13 +16,19 @@ "license": "ISC", "devDependencies": { "@cosmjs/proto-signing": "^0.32.4", - "@cosmjs/stargate": "^0.32.4", + "@cosmjs/stargate": "^0.32.2", "@evmos/address-converter": "^0.1.9", + "@evmos/evmosjs": "github:evmos/evmosjs#main", + "@evmos/proto": "^0.2.1", "@nomicfoundation/hardhat-foundry": "^1.1.3", "@nomicfoundation/hardhat-toolbox": "^5.0.0", "bip39": "^3.1.0", "dotenv": "^16.4.7", + "esm": "^3.2.25", "ethereumjs-wallet": "^1.0.2", "hardhat": "^2.22.17" + }, + "resolutions": { + "@buf/cosmos_cosmos-sdk.bufbuild_es": "1.0.0-20230125164018-54d184078b88.1" } } diff --git a/script/10_DeployExocoreGatewayOnly.s.sol b/script/10_DeployExocoreGatewayOnly.s.sol index 2fe48330..a842bcba 100644 --- a/script/10_DeployExocoreGatewayOnly.s.sol +++ b/script/10_DeployExocoreGatewayOnly.s.sol @@ -1,6 +1,6 @@ pragma solidity ^0.8.19; -import {ILayerZeroEndpointV2} from "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import {ILayerZeroEndpointV2} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; import {ProxyAdmin} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; diff --git a/script/11_SetPeers.s.sol b/script/11_SetPeers.s.sol index 9ddce3d8..7e8a167c 100644 --- a/script/11_SetPeers.s.sol +++ b/script/11_SetPeers.s.sol @@ -7,7 +7,7 @@ import {Action, GatewayStorage} from "../src/storage/GatewayStorage.sol"; import {BaseScript} from "./BaseScript.sol"; import "forge-std/Script.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; contract SetPeersAndUpgrade is BaseScript { diff --git a/script/12_RedeployClientChainGateway.s.sol b/script/12_RedeployClientChainGateway.s.sol index 0e58543d..919ce3c5 100644 --- a/script/12_RedeployClientChainGateway.s.sol +++ b/script/12_RedeployClientChainGateway.s.sol @@ -17,7 +17,7 @@ import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; import {BaseScript} from "./BaseScript.sol"; import "@beacon-oracle/contracts/src/EigenLayerBeaconOracle.sol"; -import {ILayerZeroEndpointV2} from "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import {ILayerZeroEndpointV2} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/script/13_DepositValidator.s.sol b/script/13_DepositValidator.s.sol index c5bceac0..bcbc6ba0 100644 --- a/script/13_DepositValidator.s.sol +++ b/script/13_DepositValidator.s.sol @@ -7,8 +7,8 @@ import "../src/interfaces/IVault.sol"; import {Action, GatewayStorage} from "../src/storage/GatewayStorage.sol"; import "@beacon-oracle/contracts/src/EigenLayerBeaconOracle.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/script/14_CorrectBootstrapErrors.s.sol b/script/14_CorrectBootstrapErrors.s.sol index a128d035..bef77160 100644 --- a/script/14_CorrectBootstrapErrors.s.sol +++ b/script/14_CorrectBootstrapErrors.s.sol @@ -15,7 +15,7 @@ import {Vault} from "../src/core/Vault.sol"; import {ICustomProxyAdmin} from "../src/interfaces/ICustomProxyAdmin.sol"; import {BaseScript} from "./BaseScript.sol"; -import {ILayerZeroEndpointV2} from "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import {ILayerZeroEndpointV2} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/script/17_WithdrawalValidator.s.sol b/script/17_WithdrawalValidator.s.sol index 607ae531..c8f7d9e0 100644 --- a/script/17_WithdrawalValidator.s.sol +++ b/script/17_WithdrawalValidator.s.sol @@ -9,8 +9,8 @@ import "../src/interfaces/IVault.sol"; import "../src/storage/GatewayStorage.sol"; import "@beacon-oracle/contracts/src/EigenLayerBeaconOracle.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/script/18_SimulateReceive.s.sol b/script/18_SimulateReceive.s.sol index 65fd03be..2268a4ff 100644 --- a/script/18_SimulateReceive.s.sol +++ b/script/18_SimulateReceive.s.sol @@ -11,7 +11,7 @@ import {Script, console} from "forge-std/Script.sol"; import {StdCheats} from "forge-std/StdCheats.sol"; import "forge-std/StdJson.sol"; -import {IOAppCore} from "@layerzero-v2/oapp/contracts/oapp/interfaces/IOAppCore.sol"; +import {IOAppCore} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/interfaces/IOAppCore.sol"; import {Origin} from "../src/lzApp/OAppReceiverUpgradeable.sol"; diff --git a/script/3_Setup.s.sol b/script/3_Setup.s.sol index 84ca88e7..ae4e6c02 100644 --- a/script/3_Setup.s.sol +++ b/script/3_Setup.s.sol @@ -9,8 +9,8 @@ import "../src/interfaces/IVault.sol"; import {NonShortCircuitEndpointV2Mock} from "../test/mocks/NonShortCircuitEndpointV2Mock.sol"; import {BaseScript} from "./BaseScript.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/script/4_Deposit.s.sol b/script/4_Deposit.s.sol index e3c81492..52eff2fc 100644 --- a/script/4_Deposit.s.sol +++ b/script/4_Deposit.s.sol @@ -7,8 +7,8 @@ import "../src/interfaces/IVault.sol"; import {Action, GatewayStorage} from "../src/storage/GatewayStorage.sol"; import {BaseScript} from "./BaseScript.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/script/5_Withdraw.s.sol b/script/5_Withdraw.s.sol index 92011269..987e5e62 100644 --- a/script/5_Withdraw.s.sol +++ b/script/5_Withdraw.s.sol @@ -8,8 +8,8 @@ import "../src/interfaces/IVault.sol"; import {Action, GatewayStorage} from "../src/storage/GatewayStorage.sol"; import {BaseScript} from "./BaseScript.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/script/6_CreateExoCapsule.s.sol b/script/6_CreateExoCapsule.s.sol index 0b1b05e4..7f6afa92 100644 --- a/script/6_CreateExoCapsule.s.sol +++ b/script/6_CreateExoCapsule.s.sol @@ -8,8 +8,8 @@ import "../src/interfaces/IVault.sol"; import "../src/storage/GatewayStorage.sol"; import {BaseScript} from "./BaseScript.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/script/7_DeployBootstrap.s.sol b/script/7_DeployBootstrap.s.sol index d28df780..9353d93b 100644 --- a/script/7_DeployBootstrap.s.sol +++ b/script/7_DeployBootstrap.s.sol @@ -14,7 +14,7 @@ import "../src/utils/BeaconProxyBytecode.sol"; import {CustomProxyAdmin} from "../src/utils/CustomProxyAdmin.sol"; import {BaseScript} from "./BaseScript.sol"; -import {ILayerZeroEndpointV2} from "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import {ILayerZeroEndpointV2} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/script/BaseScript.sol b/script/BaseScript.sol index 2d251a56..2810a341 100644 --- a/script/BaseScript.sol +++ b/script/BaseScript.sol @@ -15,7 +15,7 @@ import "../src/interfaces/precompiles/IDelegation.sol"; import "../src/interfaces/precompiles/IReward.sol"; import "@beacon-oracle/contracts/src/EigenLayerBeaconOracle.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; import {IBeacon} from "@openzeppelin/contracts/proxy/beacon/IBeacon.sol"; import {ERC20PresetFixedSupply, IERC20} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/script/TestPrecompileErrorFixed.s.sol b/script/TestPrecompileErrorFixed.s.sol index a119899b..02a83695 100644 --- a/script/TestPrecompileErrorFixed.s.sol +++ b/script/TestPrecompileErrorFixed.s.sol @@ -13,8 +13,8 @@ import {Action, GatewayStorage} from "../src/storage/GatewayStorage.sol"; import {NonShortCircuitEndpointV2Mock} from "../test/mocks/NonShortCircuitEndpointV2Mock.sol"; import {BaseScript} from "./BaseScript.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; diff --git a/script/TestPrecompileErrorFixed_Deploy.s.sol b/script/TestPrecompileErrorFixed_Deploy.s.sol index 83bbaca4..5d457e6e 100644 --- a/script/TestPrecompileErrorFixed_Deploy.s.sol +++ b/script/TestPrecompileErrorFixed_Deploy.s.sol @@ -9,8 +9,8 @@ import {Action, GatewayStorage} from "../src/storage/GatewayStorage.sol"; import {NonShortCircuitEndpointV2Mock} from "../test/mocks/NonShortCircuitEndpointV2Mock.sol"; import {BaseScript} from "./BaseScript.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; diff --git a/script/deployBeaconOracle.s.sol b/script/deployBeaconOracle.s.sol index 425d855d..b17009a4 100644 --- a/script/deployBeaconOracle.s.sol +++ b/script/deployBeaconOracle.s.sol @@ -2,7 +2,7 @@ pragma solidity ^0.8.19; import "./BaseScript.sol"; import "@beacon-oracle/contracts/src/EigenLayerBeaconOracle.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; import {ERC20PresetFixedSupply} from "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol"; import "forge-std/Script.sol"; diff --git a/src/interfaces/precompiles/IAssets.sol b/src/interfaces/precompiles/IAssets.sol index 00c1a2be..ff6508d0 100644 --- a/src/interfaces/precompiles/IAssets.sol +++ b/src/interfaces/precompiles/IAssets.sol @@ -7,6 +7,16 @@ address constant ASSETS_PRECOMPILE_ADDRESS = 0x000000000000000000000000000000000 /// @dev The Assets contract's instance. IAssets constant ASSETS_CONTRACT = IAssets(ASSETS_PRECOMPILE_ADDRESS); +/// @dev The TokenInfo struct. +struct TokenInfo { + string name; + string symbol; + uint32 clientChainID; + bytes tokenID; + uint8 decimals; + uint256 totalStaked; +} + /// @author Exocore Team /// @title Assets Precompile Contract /// @dev The interface through which solidity contracts will interact with assets module @@ -118,7 +128,7 @@ interface IAssets { function updateToken(uint32 clientChainId, bytes calldata token, string calldata metaData) external returns (bool success); - + /// @dev update the authorized gateways, only the authorized gateways can call precompile functions /// @dev If it is the mainnet, only the authority can call this function /// @param gateways the authorized gateways @@ -141,4 +151,14 @@ interface IAssets { /// @return isAuthorized true if the gateway is authorized function isAuthorizedGateway(address gateway) external view returns (bool success, bool isAuthorized); + /// @dev Returns the asset info for a given asset ID. + /// @param clientChainId is the ID of the client chain + /// @param tokenId is the ID of the token, typically the token address + /// @return success true if the query is successful + /// @return assetInfo the asset info + function getTokenInfo(uint32 clientChainId, bytes calldata tokenId) + external + view + returns (bool success, TokenInfo memory assetInfo); + } diff --git a/test/foundry/Delegation.t.sol b/test/foundry/Delegation.t.sol index d2f45c0c..9f88586a 100644 --- a/test/foundry/Delegation.t.sol +++ b/test/foundry/Delegation.t.sol @@ -7,8 +7,8 @@ import {Action, GatewayStorage} from "../../src/storage/GatewayStorage.sol"; import "../mocks/DelegationMock.sol"; import "./ExocoreDeployer.t.sol"; -import {OptionsBuilder} from "@layerzero-v2/oapp/contracts/oapp/libs/OptionsBuilder.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import {OptionsBuilder} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import "forge-std/Test.sol"; diff --git a/test/foundry/DepositThenDelegateTo.t.sol b/test/foundry/DepositThenDelegateTo.t.sol index 39904ccb..ebce8a42 100644 --- a/test/foundry/DepositThenDelegateTo.t.sol +++ b/test/foundry/DepositThenDelegateTo.t.sol @@ -9,8 +9,8 @@ import "../mocks/AssetsMock.sol"; import "../mocks/DelegationMock.sol"; import "./ExocoreDeployer.t.sol"; -import {OptionsBuilder} from "@layerzero-v2/oapp/contracts/oapp/libs/OptionsBuilder.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import {OptionsBuilder} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "forge-std/Test.sol"; diff --git a/test/foundry/DepositWithdrawPrinciple.t.sol b/test/foundry/DepositWithdrawPrinciple.t.sol index 4a2e6406..09eac3fb 100644 --- a/test/foundry/DepositWithdrawPrinciple.t.sol +++ b/test/foundry/DepositWithdrawPrinciple.t.sol @@ -11,7 +11,7 @@ import {Action, GatewayStorage} from "../../src/storage/GatewayStorage.sol"; import "./ExocoreDeployer.t.sol"; import "forge-std/Test.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import "@openzeppelin/contracts/utils/Create2.sol"; diff --git a/test/foundry/ExocoreDeployer.t.sol b/test/foundry/ExocoreDeployer.t.sol index 0938b916..54fdd255 100644 --- a/test/foundry/ExocoreDeployer.t.sol +++ b/test/foundry/ExocoreDeployer.t.sol @@ -1,8 +1,8 @@ pragma solidity ^0.8.19; import "@beacon-oracle/contracts/src/EigenLayerBeaconOracle.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import "@openzeppelin/contracts/proxy/beacon/IBeacon.sol"; import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol"; diff --git a/test/foundry/Governance.t.sol b/test/foundry/Governance.t.sol index ea7ca693..6c411910 100644 --- a/test/foundry/Governance.t.sol +++ b/test/foundry/Governance.t.sol @@ -10,9 +10,9 @@ import "src/utils/CustomTimelockController.sol"; import "@beacon-oracle/contracts/src/EigenLayerBeaconOracle.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@openzeppelin/contracts/proxy/beacon/IBeacon.sol"; import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol"; diff --git a/test/foundry/TvlLimits.t.sol b/test/foundry/TvlLimits.t.sol index 26a2eddb..23ef83eb 100644 --- a/test/foundry/TvlLimits.t.sol +++ b/test/foundry/TvlLimits.t.sol @@ -10,7 +10,7 @@ import "../../src/storage/GatewayStorage.sol"; import "./ExocoreDeployer.t.sol"; import "forge-std/Test.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import "@openzeppelin/contracts/utils/Create2.sol"; diff --git a/test/foundry/WithdrawReward.t.sol b/test/foundry/WithdrawReward.t.sol index f064d72d..12bc2f15 100644 --- a/test/foundry/WithdrawReward.t.sol +++ b/test/foundry/WithdrawReward.t.sol @@ -7,7 +7,7 @@ import {Action, GatewayStorage} from "../../src/storage/GatewayStorage.sol"; import "../mocks/RewardMock.sol"; import "./ExocoreDeployer.t.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import "forge-std/Test.sol"; import "forge-std/console.sol"; diff --git a/test/foundry/unit/ClientChainGateway.t.sol b/test/foundry/unit/ClientChainGateway.t.sol index 76835a85..8baadebf 100644 --- a/test/foundry/unit/ClientChainGateway.t.sol +++ b/test/foundry/unit/ClientChainGateway.t.sol @@ -2,10 +2,10 @@ pragma solidity ^0.8.19; import "@beacon-oracle/contracts/src/EigenLayerBeaconOracle.sol"; -import "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import {Origin} from "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroEndpointV2.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import {Origin} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; diff --git a/test/foundry/unit/ExocoreGateway.t.sol b/test/foundry/unit/ExocoreGateway.t.sol index b5303f41..7bcbfe5b 100644 --- a/test/foundry/unit/ExocoreGateway.t.sol +++ b/test/foundry/unit/ExocoreGateway.t.sol @@ -13,7 +13,7 @@ import "test/mocks/AssetsMock.sol"; import "test/mocks/DelegationMock.sol"; import "test/mocks/RewardMock.sol"; -import "@layerzero-v2/protocol/contracts/libs/AddressCast.sol"; +import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol"; import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/GUID.sol"; import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol"; import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; diff --git a/test/hardhat/integration/btc-stake.test.js b/test/hardhat/integration/btc-stake.test.js index 52d94bb9..58eabbe9 100644 --- a/test/hardhat/integration/btc-stake.test.js +++ b/test/hardhat/integration/btc-stake.test.js @@ -16,6 +16,29 @@ describe("BTC Stake", () => { let witness3; const ASSETS_PRECOMPILE_ADDRESS = "0x0000000000000000000000000000000000000804"; + const STAKER_BTC_ADDR = "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh"; + + // enum representing client chain + const CLIENT_CHAIN = { + NONE: 0, + BTC: 1, + }; + + // enum representing tokens + const TOKEN = { + NONE: 0, + BTC: 1, + }; + + const TX_STATUS = { + NotStartedOrProcessed: 0, // 0: Default state - transaction hasn't started collecting proofs + Pending: 1, // 1: Currently collecting witness proofs + Expired: 2, // 2: Failed due to timeout, but can be retried + }; + + const VIRTUAL_BTC_ADDR = "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"; + const BTC_ID = ethers.toUtf8Bytes(VIRTUAL_BTC_ADDR); + const OPERATOR = "exo18cggcpvwspnd5c6ny8wrqxpffj5zmhklprtnph"; // Run once before all tests before(async () => { @@ -82,10 +105,124 @@ describe("BTC Stake", () => { // assert threshold is set expect(await utxoGateway.requiredProofs()).to.equal(2); + expect(await utxoGateway.isConsensusRequired()).to.be.true; // assert the utxo gateway is authorized const [success, authorized] = await assetsPrecompile.isAuthorizedGateway(utxoGateway.target); expect(success).to.be.true; expect(authorized).to.be.true; }); + + it("should successfully activate staking for BTC", async () => { + const tx = await utxoGateway.connect(owner).activateStakingForClientChain(CLIENT_CHAIN.BTC); + const receipt = await tx.wait(); + expect(receipt.status).to.be.equal(1); + + // assert the client chain is registered + const [success1, registered] = await assetsPrecompile.isRegisteredClientChain(CLIENT_CHAIN.BTC); + expect(success1).to.be.true; + expect(registered).to.be.true; + + // assert the BTC asset is registered + const [success2, tokenInfo] = await assetsPrecompile.getTokenInfo(CLIENT_CHAIN.BTC, BTC_ID); + expect(success2).to.be.true; + // Access array elements directly since tokenInfo is returned as an array + expect(tokenInfo[0]).to.equal("BTC"); // name + expect(tokenInfo[1]).to.equal(""); // symbol + expect(Number(tokenInfo[2])).to.equal(CLIENT_CHAIN.BTC); // clientChainId + + // Convert the returned tokenId bytes to UTF-8 string for comparison + const returnedTokenId = ethers.toUtf8String(tokenInfo[3]); // tokenId + expect(returnedTokenId).to.equal(ethers.toUtf8String(BTC_ID)); + expect(Number(tokenInfo[4])).to.equal(8); // decimals + expect(Number(tokenInfo[5])).to.equal(0); // totalStaked + }); + + it("should successfully stake BTC", async () => { + // construct the stake message for staker + const stakeMsg = { + clientChainId: CLIENT_CHAIN.BTC, // enum value, probably 1 + clientAddress: ethers.toUtf8Bytes(STAKER_BTC_ADDR), // convert address to bytes + exocoreAddress: staker.address, // use signer's address + operator: OPERATOR, + amount: ethers.parseUnits("1.0", 8), + nonce: BigInt(1), + txTag: ethers.toUtf8Bytes("test-1") + }; + + // Create the message hash using the same format as the contract + const messageHash = ethers.keccak256( + ethers.AbiCoder.defaultAbiCoder().encode( + [ + 'uint8', // clientChainId (enum is uint8) + 'bytes', // clientAddress + 'address', // exocoreAddress + 'string', // operator + 'uint256', // amount + 'uint64', // nonce + 'bytes' // txTag + ], + [ + stakeMsg.clientChainId, + stakeMsg.clientAddress, + stakeMsg.exocoreAddress, + stakeMsg.operator, + stakeMsg.amount, + stakeMsg.nonce, + stakeMsg.txTag + ] + ) + ); + + // construct proofs for the stake message, with each witness signing the message + const proofs = []; + for (const witness of [witness1, witness2, witness3]) { + const proof = await witness.signMessage(ethers.getBytes(messageHash)); + proofs.push(proof); + } + + // consensus is required, so we need to submit the proofs + expect(await utxoGateway.isConsensusRequired()).to.be.true; + expect(await utxoGateway.requiredProofs()).to.equal(2); + + // submit the first proof + try { + // First simulate the transaction to get revert reason + const simulated = await utxoGateway.connect(relayer).submitProofForStakeMsg.staticCall( + witness1.address, + stakeMsg, + proofs[0] + ); + console.log("Simulation result:", simulated); + + // If simulation succeeds, send the actual transaction + const tx = await utxoGateway.connect(relayer).submitProofForStakeMsg( + witness1.address, + stakeMsg, + proofs[0] + ); + + // Wait for transaction with more details + const receipt = await tx.wait(); + console.log("Transaction receipt:", { + status: receipt.status, + gasUsed: receipt.gasUsed.toString(), + events: receipt.events?.map(e => e.event) + }); + } catch (error) { + console.error("Error submitting proof:", error); + } + // assert the transaction is created and pending to be processed + expect(await utxoGateway.getTransactionStatus(messageHash)).to.equal(TX_STATUS.Pending); + expect(await utxoGateway.getTransactionProofCount(messageHash)).to.equal(1); + + // submit the second proof + const tx2 = await utxoGateway.connect(relayer).submitProofForStakeMsg(witness2.address, stakeMsg, proofs[1]); + const receipt2 = await tx2.wait(); + expect(receipt2.status).to.be.equal(1); + // assert we should have met with required proofs to process the transaction + expect(await utxoGateway.getTransactionStatus(messageHash)).to.equal(TX_STATUS.NotStartedOrProcessed); + expect(await utxoGateway.getTransactionProofCount(messageHash)).to.equal(0); + + }); }); diff --git a/test/mocks/AssetsMock.sol b/test/mocks/AssetsMock.sol index e364a823..e250b078 100644 --- a/test/mocks/AssetsMock.sol +++ b/test/mocks/AssetsMock.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.19; // import "forge-std/console.sol"; import {IAssets} from "src/interfaces/precompiles/IAssets.sol"; +import {TokenInfo} from "src/interfaces/precompiles/IAssets.sol"; contract AssetsMock is IAssets { @@ -12,10 +13,12 @@ contract AssetsMock is IAssets { mapping(uint32 => mapping(bytes => mapping(bytes => uint256))) public principalBalances; mapping(bytes => mapping(bytes => bool)) public inValidatorSet; + mapping(address => bool) public authorizedGateways; uint32[] internal chainIds; mapping(uint32 chainId => bool registered) public isRegisteredChain; mapping(uint32 chainId => mapping(bytes token => bool registered)) public isRegisteredToken; + mapping(uint32 chainId => mapping(bytes token => TokenInfo)) public registeredTokens; constructor(uint32 clientChainId) { isRegisteredChain[clientChainId] = true; @@ -142,6 +145,14 @@ contract AssetsMock is IAssets { return false; } isRegisteredToken[clientChainId][token] = true; + registeredTokens[clientChainId][token] = TokenInfo({ + name: name, + symbol: "", + clientChainID: clientChainId, + tokenID: token, + decimals: decimals, + totalStaked: 0 + }); return true; } @@ -162,6 +173,17 @@ contract AssetsMock is IAssets { return true; } + function updateAuthorizedGateways(address[] calldata gateways) external returns (bool) { + if (gateways.length == 0) { + return false; + } + + for (uint256 i = 0; i < gateways.length; i++) { + authorizedGateways[gateways[i]] = true; + } + return true; + } + function getPrincipalBalance(uint32 clientChainLzId, bytes memory token, bytes memory staker) public view @@ -178,4 +200,19 @@ contract AssetsMock is IAssets { return (true, isRegisteredChain[clientChainID]); } + function isAuthorizedGateway(address gateway) external view returns (bool, bool) { + return (true, authorizedGateways[gateway]); + } + + function getTokenInfo(uint32 clientChainId, bytes calldata tokenId) + external + view + returns (bool, TokenInfo memory) + { + if (!isRegisteredToken[clientChainId][tokenId]) { + return (false, TokenInfo("", "", 0, bytes(""), 0, 0)); + } + return (true, registeredTokens[clientChainId][tokenId]); + } + } diff --git a/test/mocks/ExocoreGatewayMock.sol b/test/mocks/ExocoreGatewayMock.sol index 23c91b4f..e891388a 100644 --- a/test/mocks/ExocoreGatewayMock.sol +++ b/test/mocks/ExocoreGatewayMock.sol @@ -17,9 +17,9 @@ import { } from "src/lzApp/OAppUpgradeable.sol"; import {ExocoreGatewayStorage} from "src/storage/ExocoreGatewayStorage.sol"; -import {IOAppCore} from "@layerzero-v2/oapp/contracts/oapp/interfaces/IOAppCore.sol"; -import {OptionsBuilder} from "@layerzero-v2/oapp/contracts/oapp/libs/OptionsBuilder.sol"; -import {ILayerZeroReceiver} from "@layerzero-v2/protocol/contracts/interfaces/ILayerZeroReceiver.sol"; +import {IOAppCore} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/interfaces/IOAppCore.sol"; +import {OptionsBuilder} from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/libs/OptionsBuilder.sol"; +import {ILayerZeroReceiver} from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroReceiver.sol"; import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol"; import {PausableUpgradeable} from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";