From 6806e8b562ddce5b3d703fcc7b68366376f415d4 Mon Sep 17 00:00:00 2001 From: Ed Zynda Date: Wed, 5 Apr 2023 11:30:10 +0300 Subject: [PATCH] Spearbit audit march 2023 (#300) * Synapse bridge facet doc (#235) * add interface of SynapseRouter * add SynapseBridge facet contract * add SynpaseBridge configuration * add deployment and update scripts of SynapseBridge facet * add SynpaseBridge foundry test * make synapseRouter variable public * add SynapseBridge facet doc * fix issue with setting receiver address for relayer * run prettier for CeleIMFacet * update comments in CelerIMFacet * update CelerIMFacet foundry test with destination call * add fee check to DeBridgeFacet * add test for invalid fee rate of DeBridgeFacet * add comments to CelerIMFacet * rename the test function * #73 check circle swap result * update _depositAndSwap function to not include nativeReserve in newBalance * update ArbitrumBridge and DeBridge facets with updated _depositAndSwap * update CelerIMFacet to use right _depositAndSwap function * add swap test with destination call to CelerIMFacet test * update minAmount conversion in MakerTeleportFacet with SafeCast * update SquidFacet with source swap flag check * update SquidFacet test * remove feeAmount param from collectNativeInsuranceFees and collectNativeGasFees * update LIFuelFacet with updated ServiceFeeCollector functions * update ServiceFeeCollector test * update refundExcessNative modifier to save gas * remove unused imports from ThorSwapFacet * LF-2637 remove noNativeAsset modifier from startBridgeTokensViaCircleBridge * update ArbitrumBridgeFacet * update facets with validateDestinationCallFlag function * remove unused imports from LIFuelFacet * add WithdrawFailed error to GenericErrors * update RelayerCelerIM with generic error * remove unused reentrancy guard from RelayerCelerIM * add doesNotContainDestinationCalls modifier to LIFuelFacet * update LibAsset and AcrossFacet with isNativeAsset function * remove destination chain id check from CBridgeFacet * LF-2607 LF-2605 #52 #50 remove swap data checks (#276) * remove swapData check from CircleBridgeFacet * add recipient check to transferERC20 * update variable visibilities to private * update maxApproveERC20 of LibAsset * remove LibMappings * use calldata instead of memory to save gas (#268) * remove duplicated validateBridgeData modifier from ArbitrumBridgeFacet * add validation for token symbol (#282) * Check return value (#244) * Restrict approval method to owner (#245) * Add explicit revert (#248) * Only approve once we know we have enough gas (#247) * remove unneeded parameter (#263) * update comment (#264) * remove unneeded modifiers (#265) * remove unneeded events/errors (#266) * check amount != 0 in all cases (#279) * add missing refundExcessNative (#280) * track chain id (#289) * update dstNativeAddr in quoteLayerZeroFee of StargateFacet * update dstNativeAddr in _startBridge of StargateFacet * remove unused imports from CircleBridgeFacet * Use temp variable in _startBridge function of MultichainFacet (#293) * Update cfUSDC check in CelerIMFacet (#254) * update CelerIMFacet with cfUSDC * add cfUSDC to cBridge config * update DeployCelerIMFacet with cfUSDC * update CelerIMFacet test with cfUSDC * LF-2638 83 add cfUSDC check to swapAndStartBridgeTokensViaCelerIM * refactor LibBytes (#267) * Add missing test case (#296) * add missing emit (#281) * check for sufficient expiration time (#278) * check for sufficient expiration time * Update ThorSwapFacet.sol Fix typo * Update ThorSwapFacet.sol Fix typo * fix tests * Make function more readable (#290) * Allow executor to receive ERC1155 tokens (#295) * fix solidity version (#277) * clear out penging owner if any (#250) * feat: Add HopFacetPacked (#283) * feat: Add HopFacetPacked * add gas comparisson with HopFacetOptimized * formatting * add gas test for other polygon * add packed version of cbridge * add testcase to ensure callData extraction works the same when forwarded via another contract * cbridge: order arguments add pure encode functions * hop: order arguments and add pure encode functions * fix test * add optimized functions for hop on L1 as well * update hoppacked documentation * add gas cost comparrison for cbridge optimizations * rename encodeBridge... functions to encoder_startBridge... * replace hardcoded strings with function selectors * replace assembly parsing with solidity * add validation to encoder functions * fix typos and documentation * add validation tests * Remove unusable permit param (#291) * chore: build types for audit branch * chore: build using forge only * chore: update generateDiamond * Test Stargate Pool Validation (#297) * fix: passing pool data as calldata (#237) * test: add stargate poolId validation tests --------- Co-authored-by: Leonardo Cascianelli Co-authored-by: Ed Zynda * Auto format code and configure husky to do so on every commit (#298) * chore: autoformat code * chore: update husky * fix compiler warnings * #31 cache gasleft to prevent underflow (#249) * cache gasleft to prevent underflow * add missing cachGasLeft * Fix issue with unused code for setting pool id in StargateFacet (#299) * remove unused code from StargateFacet * update UpdateStargateFacet script * Fix issue of native bridging test with SquidFacet (#303) * Add version numbers (#302) * Add version numbers to facets and periphery contracts * Formatting --------- Co-authored-by: satoshi-lifi <112938295+satoshi-lifi@users.noreply.github.com> Co-authored-by: Satoshi Naoki Co-authored-by: Max Klenk Co-authored-by: Leonardo Cascianelli --- .eslintignore | 1 + .github/workflows/types.yml | 109 +++ .husky/pre-commit | 2 +- .prettierrc.js | 1 - .solhintignore | 1 + config/cbridge.json | 3 +- hardhat.config.ts | 12 +- package.json | 1 + script/DeployCBridgeFacet.s.sol | 24 +- script/DeployCelerIMFacet.s.sol | 9 +- script/DeployHopFacetPacked.s.sol | 4 +- script/DeployLIFuelFacet.s.sol | 5 +- script/DeployLiFiDiamondImmutable.s.sol | 7 +- script/DeployMakerTeleportFacet.s.sol | 32 +- script/MakeLiFiDiamondImmutable.s.sol | 23 + script/UpdateAmarokFacet.s.sol | 2 +- script/UpdateCBridgeFacet.s.sol | 18 +- script/UpdateCelerIMFacet.s.sol | 2 +- script/UpdateConfigForStargate.s.sol | 2 - script/UpdateGenericSwapFacet.s.sol | 1 - script/UpdateLIFuelFacet.s.sol | 2 +- script/UpdateMakerTeleportFacet.s.sol | 14 +- script/UpdateStargateFacet.s.sol | 15 - script/utils/UpdateScriptBase.sol | 15 +- scripts/demoArbitrumBridge.ts | 25 +- scripts/demoSquid.ts | 53 +- scripts/demoThorSwap.ts | 29 +- src/Errors/GenericErrors.sol | 1 + src/Facets/AccessManagerFacet.sol | 10 +- src/Facets/AcrossFacet.sol | 40 +- src/Facets/AllBridgeFacet.sol | 5 +- src/Facets/AmarokFacet.sol | 35 +- src/Facets/ArbitrumBridgeFacet.sol | 102 +-- src/Facets/AxelarFacet.sol | 12 +- src/Facets/CBridgeFacet.sol | 9 +- src/Facets/CBridgeFacetPacked.sol | 150 ++-- src/Facets/CelerIMFacet.sol | 141 +-- src/Facets/CircleBridgeFacet.sol | 7 +- src/Facets/DeBridgeFacet.sol | 24 +- src/Facets/DexManagerFacet.sol | 16 +- src/Facets/DiamondLoupeFacet.sol | 22 +- src/Facets/GenericSwapFacet.sol | 1 + src/Facets/GnosisBridgeFacet.sol | 9 +- src/Facets/GnosisBridgeL2Facet.sol | 18 +- src/Facets/GravityFacet.sol | 7 +- src/Facets/HopFacet.sol | 5 +- src/Facets/HopFacetOptimized.sol | 7 +- src/Facets/HopFacetPacked.sol | 242 +++-- src/Facets/HyphenFacet.sol | 5 +- src/Facets/LIFuelFacet.sol | 42 +- src/Facets/MakerTeleportFacet.sol | 15 +- src/Facets/MultichainFacet.sol | 45 +- src/Facets/NXTPFacet.sol | 30 +- src/Facets/OmniBridgeFacet.sol | 1 + src/Facets/OptimismBridgeFacet.sol | 1 + src/Facets/OwnershipFacet.sol | 1 + src/Facets/PeripheryRegistryFacet.sol | 35 +- src/Facets/PolygonBridgeFacet.sol | 1 + src/Facets/RoninBridgeFacet.sol | 1 + src/Facets/SquidFacet.sol | 64 +- src/Facets/StargateFacet.sol | 73 +- src/Facets/SynapseBridgeFacet.sol | 3 +- src/Facets/ThorSwapFacet.sol | 19 +- src/Facets/WithdrawFacet.sol | 3 + src/Facets/WormholeFacet.sol | 45 +- src/Helpers/ExcessivelySafeCall.sol | 11 +- src/Helpers/SwapperV2.sol | 20 +- src/Interfaces/IDeBridgeGate.sol | 7 +- src/Interfaces/IDiamondLoupe.sol | 14 +- src/Interfaces/IERC165.sol | 7 +- src/Interfaces/IGatewayRouter.sol | 7 +- src/Interfaces/IRootChainManager.sol | 7 +- src/Interfaces/IStargateRouter.sol | 1 + src/Interfaces/ITransactionManager.sol | 7 +- src/Libraries/LibAllowList.sol | 8 +- src/Libraries/LibAsset.sol | 58 +- src/Libraries/LibBytes.sol | 502 +---------- src/Libraries/LibDiamond.sol | 18 +- src/Libraries/LibMappings.sol | 92 -- src/Libraries/LibUtil.sol | 8 +- src/Periphery/AxelarExecutor.sol | 5 +- src/Periphery/ERC20Proxy.sol | 9 +- src/Periphery/Executor.sol | 45 +- src/Periphery/FeeCollector.sol | 33 +- src/Periphery/FusePoolZap.sol | 2 + src/Periphery/Receiver.sol | 35 +- src/Periphery/RelayerCelerIM.sol | 54 +- src/Periphery/ServiceFeeCollector.sol | 61 +- tasks/generateDiamondABI.ts | 18 +- test/solidity/Facets/AcrossFacet.t.sol | 15 +- test/solidity/Facets/AllBridgeFacet.t.sol | 7 +- test/solidity/Facets/AmarokFacet.t.sol | 17 +- .../solidity/Facets/ArbitrumBridgeFacet.t.sol | 14 +- test/solidity/Facets/CBridge.t.sol | 102 ++- .../Facets/CBridgeAndFeeCollection.t.sol | 26 +- test/solidity/Facets/CBridgeFacetPacked.t.sol | 57 +- test/solidity/Facets/CelerIMFacet.t.sol | 76 +- test/solidity/Facets/CircleBridgeFacet.t.sol | 34 +- test/solidity/Facets/DeBridgeFacet.t.sol | 21 +- test/solidity/Facets/GenericSwapFacet.t.sol | 8 +- test/solidity/Facets/GnosisBridgeFacet.t.sol | 24 +- .../solidity/Facets/GnosisBridgeL2Facet.t.sol | 12 +- test/solidity/Facets/GravityFacet.t.sol | 7 +- test/solidity/Facets/HopFacet.t.sol | 7 +- .../solidity/Facets/HopFacetOptimizedL1.t.sol | 9 +- .../solidity/Facets/HopFacetOptimizedL2.t.sol | 9 +- test/solidity/Facets/HopFacetPacked.t.sol | 89 +- test/solidity/Facets/HyphenFacet.t.sol | 7 +- test/solidity/Facets/LIFuelFacet.t.sol | 36 +- test/solidity/Facets/MakerTeleportFacet.t.sol | 31 +- test/solidity/Facets/MultiChainFacet.t.sol | 11 +- test/solidity/Facets/NXTPFacet.t.sol | 11 +- test/solidity/Facets/OmniBridgeFacet.t.sol | 14 +- test/solidity/Facets/OmniBridgeL2Facet.t.sol | 14 +- .../solidity/Facets/OptimismBridgeFacet.t.sol | 33 +- test/solidity/Facets/PolygonBridgeFacet.t.sol | 14 +- test/solidity/Facets/RoninBridgeFacet.t.sol | 7 +- test/solidity/Facets/SquidFacet.t.sol | 44 +- test/solidity/Facets/StargateFacet.t.sol | 49 +- test/solidity/Facets/ThorSwapFacet.t.sol | 9 +- test/solidity/Facets/WormholeFacet.t.sol | 7 +- .../Gas/CBridgeFacetPackedARB.gas.t.sol | 94 +- .../Gas/CBridgeFacetPackedETH.gas.t.sol | 100 ++- test/solidity/Gas/Hop.t.sol | 8 +- test/solidity/Gas/HopFacetPackedARB.gas.t.sol | 135 +-- test/solidity/Gas/HopFacetPackedETH.gas.t.sol | 53 +- test/solidity/Gas/HopFacetPackedPOL.gas.t.sol | 135 +-- test/solidity/Periphery/AxelarExecutor.t.sol | 7 +- test/solidity/Periphery/Executor.t.sol | 9 +- test/solidity/Periphery/FusePoolZap.t.sol | 4 +- test/solidity/Periphery/RelayerCelerIM.t.sol | 33 + .../Periphery/ServiceFeeCollector.t.sol | 13 +- test/solidity/utils/Console.sol | 833 +++--------------- test/solidity/utils/Interfaces.sol | 16 +- test/solidity/utils/TestBase.sol | 17 +- test/solidity/utils/Utilities.sol | 7 +- 136 files changed, 2299 insertions(+), 2674 deletions(-) create mode 100644 .github/workflows/types.yml delete mode 100644 src/Libraries/LibMappings.sol diff --git a/.eslintignore b/.eslintignore index 061cf13e2..bcd9020d7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,3 +6,4 @@ coverage/ node_modules/ package.json typechain/ +lib/ diff --git a/.github/workflows/types.yml b/.github/workflows/types.yml new file mode 100644 index 000000000..77cf99f78 --- /dev/null +++ b/.github/workflows/types.yml @@ -0,0 +1,109 @@ +name: Types Bindings + +on: + push: + branches: + - "master" + - "staging" + - "spearbit-audit-march-2023" + +env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + +jobs: + generate-tag: + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout contracts repository + uses: actions/checkout@v3 + with: + ref: ${{ env.BRANCH_NAME }} + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + + - name: Install Node deps + run: yarn install + + - name: Generate ABI + run: yarn abi:generate + + - name: Generate types bindings + run: yarn typechain + + - name: Checkout lifi-contract-types repository + uses: actions/checkout@v3 + with: + repository: lifinance/lifi-contract-types + path: lifi-contract-types + ssh-key: ${{ secrets.SSH_REPO_TOKEN }} + ref: master + + - name: Copy types bindings + run: | + rm -r lifi-contract-types/src/ + mv typechain lifi-contract-types/src + cp diamondABI/diamond.json lifi-contract-types/dist/ + - name: Build contract types + run: cd lifi-contract-types && yarn install && yarn build + + - name: Retrieve latest Tag + id: latest_release + run: | + # fetch tag releases + release_json=$(curl https://api.github.com/repos/lifinance/lifi-contract-types/tags) + # get the latest tag + LATEST_TAG=$(echo "$release_json" | jq -r '.[0].name') + # we need to make sure that on staging we're going to update a -beta version, if any + if [[ "$BRANCH_NAME" != "master" ]]; then + # if it has already "-beta", no other action is required, since it means + # that we're already going to update the latest staging release + if [[ "$LATEST_TAG" != *"beta"* ]]; then + # otherwise, start looping through the tags and search for the latest -beta tag + while read item; do + tag_name=$(jq -r '.name' <<< "$item") + # check if there's already a latest tag beta release + # and, if present, use it instead of the main one + # if we end up without any latest beta tag, we will create a beta release from the latest tag + if [[ "$tag_name" == "$LATEST_TAG-$beta"* ]]; then + LATEST_TAG=$tag_name + break + fi + done <<<$(echo "$release_json" | jq -c -r '.[]') + fi + fi + echo "latest tag: $LATEST_TAG" + echo "LATEST_TAG=${LATEST_TAG}" >> $GITHUB_ENV + - name: Update version + id: bump_version + uses: christian-draeger/increment-semantic-version@1.1.0 + with: + current-version: "${{ env.LATEST_TAG }}" + version-fragment: "${{ env.BRANCH_NAME == 'master' && (contains(github.event.head_commit.message, 'major') && 'major' || contains(github.event.head_commit.message, 'feat') && 'feature' || 'bug') || 'beta' }}" + + - name: Push tag + if: steps.bump_version.outputs.next-version + run: | + cd lifi-contract-types + tmp=$(mktemp) + jq '.version="${{ steps.bump_version.outputs.next-version }}"' package.json > "$tmp" && mv "$tmp" package.json + git config user.name github-actions + git config user.email github-actions@github.com + echo "Updating version from ${{ env.LATEST_TAG }} to ${{ steps.bump_version.outputs.next-version }}" + git add src/* + git add dist/* + git add package.json + git commit -m "actions: new contracts version ${{ steps.bump_version.outputs.next-version }}" + git tag -a v${{ steps.bump_version.outputs.next-version }} -m "${{ github.event.head_commit.message }}" + git push origin tag v${{ steps.bump_version.outputs.next-version }} + if [[ "$BRANCH_NAME" == "master" ]]; then + git push -u origin $BRANCH_NAME + fi diff --git a/.husky/pre-commit b/.husky/pre-commit index 1b8d1939f..a7df7fe50 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -yarn lint:fix +yarn format:fix && yarn lint:fix diff --git a/.prettierrc.js b/.prettierrc.js index 5f62843b4..e47ab1177 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -9,7 +9,6 @@ module.exports = { printWidth: 79, tabWidth: 4, singleQuote: false, - explicitTypes: 'always', }, }, ], diff --git a/.solhintignore b/.solhintignore index b45499ac9..05933e6c5 100644 --- a/.solhintignore +++ b/.solhintignore @@ -5,3 +5,4 @@ cache/ coverage/ node_modules/ typechain/ +lib/ diff --git a/config/cbridge.json b/config/cbridge.json index 786b6aefd..36f1675ad 100644 --- a/config/cbridge.json +++ b/config/cbridge.json @@ -4,7 +4,8 @@ }, "mainnet": { "cBridge": "0x5427FEFA711Eff984124bFBB1AB6fbf5E3DA1820", - "messageBus": "0x4066D196A423b2b3B8B054f4F40efB47a74E200C" + "messageBus": "0x4066D196A423b2b3B8B054f4F40efB47a74E200C", + "cfUSDC": "0x317F8d18FB16E49a958Becd0EA72f8E153d25654" }, "optimism": { "cBridge": "0x9D39Fc627A6d9d9F8C831c16995b209548cc3401", diff --git a/hardhat.config.ts b/hardhat.config.ts index 6137c9b5f..0bce46928 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -34,12 +34,12 @@ const config: HardhatUserConfig = { accounts: accounts(process.env.HARDHAT_FORK), forking: process.env.HARDHAT_FORK ? { - // TODO once PR merged : network: process.env.HARDHAT_FORK, - url: node_url(process.env.HARDHAT_FORK), - blockNumber: process.env.HARDHAT_FORK_NUMBER - ? parseInt(process.env.HARDHAT_FORK_NUMBER) - : undefined, - } + // TODO once PR merged : network: process.env.HARDHAT_FORK, + url: node_url(process.env.HARDHAT_FORK), + blockNumber: process.env.HARDHAT_FORK_NUMBER + ? parseInt(process.env.HARDHAT_FORK_NUMBER) + : undefined, + } : undefined, }, }, diff --git a/package.json b/package.json index 6c2adf58e..59d4174c6 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ }, "scripts": { "postinstall": "patch-package", + "prepare": "yarn prepare:husky", "prepare:husky": "husky install", "lint": "eslint \"**/*.{js,ts}\" && solhint src/**/*.sol", "lint:fix": "eslint --fix \"**/*.{js,ts}\" && solhint --fix src/**/*.sol", diff --git a/script/DeployCBridgeFacet.s.sol b/script/DeployCBridgeFacet.s.sol index 5fc733668..93f0ef149 100644 --- a/script/DeployCBridgeFacet.s.sol +++ b/script/DeployCBridgeFacet.s.sol @@ -10,10 +10,18 @@ contract DeployScript is DeployScriptBase { constructor() DeployScriptBase("CBridgeFacet") {} - function run() public returns (CBridgeFacet deployed, bytes memory constructorArgs) { - string memory path = string.concat(vm.projectRoot(), "/config/cbridge.json"); + function run() + public + returns (CBridgeFacet deployed, bytes memory constructorArgs) + { + string memory path = string.concat( + vm.projectRoot(), + "/config/cbridge.json" + ); string memory json = vm.readFile(path); - address cBridge = json.readAddress(string.concat(".", network, ".cBridge")); + address cBridge = json.readAddress( + string.concat(".", network, ".cBridge") + ); constructorArgs = abi.encode(cBridge); @@ -24,7 +32,15 @@ contract DeployScript is DeployScriptBase { } deployed = CBridgeFacet( - payable(factory.deploy(salt, bytes.concat(type(CBridgeFacet).creationCode, constructorArgs))) + payable( + factory.deploy( + salt, + bytes.concat( + type(CBridgeFacet).creationCode, + constructorArgs + ) + ) + ) ); vm.stopBroadcast(); diff --git a/script/DeployCelerIMFacet.s.sol b/script/DeployCelerIMFacet.s.sol index 549f80add..8dbb5a71a 100644 --- a/script/DeployCelerIMFacet.s.sol +++ b/script/DeployCelerIMFacet.s.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.17; import { DeployScriptBase } from "./utils/DeployScriptBase.sol"; import { stdJson } from "forge-std/Script.sol"; -import {CelerIMFacet} from "lifi/Facets/CelerIMFacet.sol"; +import { CelerIMFacet } from "lifi/Facets/CelerIMFacet.sol"; contract DeployScript is DeployScriptBase { using stdJson for string; @@ -23,7 +23,10 @@ contract DeployScript is DeployScriptBase { address messageBus = json.readAddress( string.concat(".", network, ".messageBus") ); - if (messageBus == address(0)) + address cfUSDC = json.readAddress( + string.concat(".", network, ".cfUSDC") + ); + if (messageBus == address(32)) revert( string.concat( "MessageBus address not found in deployment file for network ", @@ -49,7 +52,7 @@ contract DeployScript is DeployScriptBase { ) ); - constructorArgs = abi.encode(messageBus, relayer); + constructorArgs = abi.encode(messageBus, relayer, cfUSDC); vm.startBroadcast(deployerPrivateKey); diff --git a/script/DeployHopFacetPacked.s.sol b/script/DeployHopFacetPacked.s.sol index 7b24989c0..10c035641 100644 --- a/script/DeployHopFacetPacked.s.sol +++ b/script/DeployHopFacetPacked.s.sol @@ -14,7 +14,9 @@ contract DeployScript is DeployScriptBase { return HopFacetPacked(predicted); } - deployed = HopFacetPacked(factory.deploy(salt, type(HopFacetPacked).creationCode)); + deployed = HopFacetPacked( + factory.deploy(salt, type(HopFacetPacked).creationCode) + ); vm.stopBroadcast(); } diff --git a/script/DeployLIFuelFacet.s.sol b/script/DeployLIFuelFacet.s.sol index 3f3da986b..945d435ea 100644 --- a/script/DeployLIFuelFacet.s.sol +++ b/script/DeployLIFuelFacet.s.sol @@ -21,10 +21,7 @@ contract DeployScript is DeployScriptBase { } deployed = LIFuelFacet( - factory.deploy( - salt, - type(LIFuelFacet).creationCode - ) + factory.deploy(salt, type(LIFuelFacet).creationCode) ); vm.stopBroadcast(); diff --git a/script/DeployLiFiDiamondImmutable.s.sol b/script/DeployLiFiDiamondImmutable.s.sol index eac248062..df734a93e 100644 --- a/script/DeployLiFiDiamondImmutable.s.sol +++ b/script/DeployLiFiDiamondImmutable.s.sol @@ -6,7 +6,6 @@ import { stdJson } from "forge-std/Script.sol"; import { LiFiDiamondImmutableV1 } from "lifi/LiFiDiamondImmutable.sol"; import { DiamondCutFacet, IDiamondCut } from "lifi/Facets/DiamondCutFacet.sol"; - contract DeployScript is DeployScriptBase { using stdJson for string; @@ -15,7 +14,6 @@ contract DeployScript is DeployScriptBase { DiamondCutFacet internal cutter; constructor() DeployScriptBase("LiFiDiamondImmutableV1") { - network = vm.envString("NETWORK"); fileSuffix = vm.envString("FILE_SUFFIX"); @@ -52,7 +50,10 @@ contract DeployScript is DeployScriptBase { vm.startBroadcast(deployerPrivateKey); if (isDeployed()) { - return (LiFiDiamondImmutableV1(payable(predicted)), constructorArgs); + return ( + LiFiDiamondImmutableV1(payable(predicted)), + constructorArgs + ); } deployed = LiFiDiamondImmutableV1( diff --git a/script/DeployMakerTeleportFacet.s.sol b/script/DeployMakerTeleportFacet.s.sol index 307d4ebe5..c0f4bc755 100644 --- a/script/DeployMakerTeleportFacet.s.sol +++ b/script/DeployMakerTeleportFacet.s.sol @@ -10,13 +10,25 @@ contract DeployScript is DeployScriptBase { constructor() DeployScriptBase("MakerTeleportFacet") {} - function run() public returns (MakerTeleportFacet deployed, bytes memory constructorArgs) { - string memory path = string.concat(vm.projectRoot(), "/config/maker.json"); + function run() + public + returns (MakerTeleportFacet deployed, bytes memory constructorArgs) + { + string memory path = string.concat( + vm.projectRoot(), + "/config/maker.json" + ); string memory json = vm.readFile(path); - address makerTeleport = json.readAddress(string.concat(".", network, ".makerTeleport")); + address makerTeleport = json.readAddress( + string.concat(".", network, ".makerTeleport") + ); address dai = json.readAddress(string.concat(".", network, ".dai")); - uint256 dstChainId = json.readUint(string.concat(".", network, ".dstChainId")); - bytes32 l1Domain = json.readBytes32(string.concat(".", network, ".l1Domain")); + uint256 dstChainId = json.readUint( + string.concat(".", network, ".dstChainId") + ); + bytes32 l1Domain = json.readBytes32( + string.concat(".", network, ".l1Domain") + ); constructorArgs = abi.encode(makerTeleport, dai, dstChainId, l1Domain); @@ -27,7 +39,15 @@ contract DeployScript is DeployScriptBase { } deployed = MakerTeleportFacet( - payable(factory.deploy(salt, bytes.concat(type(MakerTeleportFacet).creationCode, constructorArgs))) + payable( + factory.deploy( + salt, + bytes.concat( + type(MakerTeleportFacet).creationCode, + constructorArgs + ) + ) + ) ); vm.stopBroadcast(); diff --git a/script/MakeLiFiDiamondImmutable.s.sol b/script/MakeLiFiDiamondImmutable.s.sol index 00fa92d09..264aafd8e 100644 --- a/script/MakeLiFiDiamondImmutable.s.sol +++ b/script/MakeLiFiDiamondImmutable.s.sol @@ -10,11 +10,34 @@ import { CREATE3Factory } from "create3-factory/CREATE3Factory.sol"; import "./utils/UpdateScriptBase.sol"; contract ImmutableDiamondOwnershipTransfer { + /// Storage /// + + bytes32 internal constant NAMESPACE = + keccak256("com.lifi.facets.ownership"); + + /// Types /// + + struct Storage { + address newOwner; + } + /// @notice Transfers ownership of diamond to address(0) (for immutable diamond) function transferOwnershipToZeroAddress() external { + Storage storage s = getStorage(); + // Clear out pending ownership if any. + s.newOwner = address(0); // transfer ownership to 0 address LibDiamond.setContractOwner(address(0)); } + + /// @dev fetch local storage + function getStorage() private pure returns (Storage storage s) { + bytes32 namespace = NAMESPACE; + // solhint-disable-next-line no-inline-assembly + assembly { + s.slot := namespace + } + } } contract DeployScript is UpdateScriptBase { diff --git a/script/UpdateAmarokFacet.s.sol b/script/UpdateAmarokFacet.s.sol index 7b3b3b548..2ddc50902 100644 --- a/script/UpdateAmarokFacet.s.sol +++ b/script/UpdateAmarokFacet.s.sol @@ -6,7 +6,7 @@ import { stdJson } from "forge-std/StdJson.sol"; import { DiamondCutFacet, IDiamondCut } from "lifi/Facets/DiamondCutFacet.sol"; import { OwnershipFacet } from "lifi/Facets/OwnershipFacet.sol"; import { AmarokFacet } from "lifi/Facets/AmarokFacet.sol"; -import {DSTest} from "ds-test/test.sol"; +import { DSTest } from "ds-test/test.sol"; contract DeployScript is UpdateScriptBase { using stdJson for string; diff --git a/script/UpdateCBridgeFacet.s.sol b/script/UpdateCBridgeFacet.s.sol index e29fe07d8..d2538af3d 100644 --- a/script/UpdateCBridgeFacet.s.sol +++ b/script/UpdateCBridgeFacet.s.sol @@ -7,7 +7,7 @@ import { DiamondCutFacet, IDiamondCut } from "lifi/Facets/DiamondCutFacet.sol"; import { CBridgeFacet } from "lifi/Facets/CBridgeFacet.sol"; contract DeployScript is UpdateScriptBase { -using stdJson for string; + using stdJson for string; function run() public returns (address[] memory facets) { address facet = json.readAddress(".CBridgeFacet"); @@ -18,17 +18,17 @@ using stdJson for string; if (loupe.facetFunctionSelectors(facet).length == 0) { bytes4[] memory exclude; cut.push( - IDiamondCut.FacetCut({ - facetAddress: address(facet), - action: IDiamondCut.FacetCutAction.Add, - functionSelectors: getSelectors("CBridgeFacet", exclude) + IDiamondCut.FacetCut({ + facetAddress: address(facet), + action: IDiamondCut.FacetCutAction.Add, + functionSelectors: getSelectors("CBridgeFacet", exclude) }) ); - cutter.diamondCut(cut, address(0), ""); - } + cutter.diamondCut(cut, address(0), ""); + } - facets = loupe.facetAddresses(); + facets = loupe.facetAddresses(); - vm.stopBroadcast(); + vm.stopBroadcast(); } } diff --git a/script/UpdateCelerIMFacet.s.sol b/script/UpdateCelerIMFacet.s.sol index 2dbe241aa..064986df3 100644 --- a/script/UpdateCelerIMFacet.s.sol +++ b/script/UpdateCelerIMFacet.s.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.17; import { UpdateScriptBase } from "./utils/UpdateScriptBase.sol"; import { stdJson } from "forge-std/StdJson.sol"; import { DiamondCutFacet, IDiamondCut } from "lifi/Facets/DiamondCutFacet.sol"; -import {CelerIMFacet} from "lifi/Facets/CelerIMFacet.sol"; +import { CelerIMFacet } from "lifi/Facets/CelerIMFacet.sol"; contract DeployScript is UpdateScriptBase { using stdJson for string; diff --git a/script/UpdateConfigForStargate.s.sol b/script/UpdateConfigForStargate.s.sol index 6a11bec4f..059789aa6 100644 --- a/script/UpdateConfigForStargate.s.sol +++ b/script/UpdateConfigForStargate.s.sol @@ -20,8 +20,6 @@ contract DeployScript is UpdateScriptBase { } function run() public { - address facet = json.readAddress(".StargateFacet"); - path = string.concat(root, "/config/stargate.json"); json = vm.readFile(path); bytes memory rawChains = json.parseRaw(string.concat(".chains")); diff --git a/script/UpdateGenericSwapFacet.s.sol b/script/UpdateGenericSwapFacet.s.sol index 38acf952d..ea68e2463 100644 --- a/script/UpdateGenericSwapFacet.s.sol +++ b/script/UpdateGenericSwapFacet.s.sol @@ -10,7 +10,6 @@ contract DeployScript is UpdateScriptBase { using stdJson for string; function run() public returns (address[] memory facets) { - address facet = json.readAddress(".GenericSwapFacet"); vm.startBroadcast(deployerPrivateKey); diff --git a/script/UpdateLIFuelFacet.s.sol b/script/UpdateLIFuelFacet.s.sol index a3dbd263a..5760ef059 100644 --- a/script/UpdateLIFuelFacet.s.sol +++ b/script/UpdateLIFuelFacet.s.sol @@ -6,7 +6,7 @@ import { stdJson } from "forge-std/StdJson.sol"; import { DiamondCutFacet, IDiamondCut } from "lifi/Facets/DiamondCutFacet.sol"; import { OwnershipFacet } from "lifi/Facets/OwnershipFacet.sol"; import { LIFuelFacet } from "lifi/Facets/LIFuelFacet.sol"; -import {DSTest} from "ds-test/test.sol"; +import { DSTest } from "ds-test/test.sol"; contract DeployScript is UpdateScriptBase { using stdJson for string; diff --git a/script/UpdateMakerTeleportFacet.s.sol b/script/UpdateMakerTeleportFacet.s.sol index c3612cc82..37b5c6a51 100644 --- a/script/UpdateMakerTeleportFacet.s.sol +++ b/script/UpdateMakerTeleportFacet.s.sol @@ -10,7 +10,14 @@ contract DeployScript is UpdateScriptBase { using stdJson for string; function run() public returns (address[] memory facets) { - string memory path = string.concat(root, "/deployments/", network, ".", fileSuffix, "json"); + string memory path = string.concat( + root, + "/deployments/", + network, + ".", + fileSuffix, + "json" + ); string memory json = vm.readFile(path); address facet = json.readAddress(".MakerTeleportFacet"); @@ -23,7 +30,10 @@ contract DeployScript is UpdateScriptBase { IDiamondCut.FacetCut({ facetAddress: address(facet), action: IDiamondCut.FacetCutAction.Add, - functionSelectors: getSelectors("MakerTeleportFacet", exclude) + functionSelectors: getSelectors( + "MakerTeleportFacet", + exclude + ) }) ); cutter.diamondCut(cut, address(0), ""); diff --git a/script/UpdateStargateFacet.s.sol b/script/UpdateStargateFacet.s.sol index 297cd89d2..812dba34d 100644 --- a/script/UpdateStargateFacet.s.sol +++ b/script/UpdateStargateFacet.s.sol @@ -10,11 +10,6 @@ import { StargateFacet } from "lifi/Facets/StargateFacet.sol"; contract DeployScript is UpdateScriptBase { using stdJson for string; - struct PoolIdConfig { - address token; - uint16 poolId; - } - struct ChainIdConfig { uint256 chainId; uint16 layerZeroChainId; @@ -31,21 +26,11 @@ contract DeployScript is UpdateScriptBase { (ChainIdConfig[]) ); - bytes memory rawPools = json.parseRaw( - string.concat(".pools.", network) - ); - PoolIdConfig[] memory poolCfg = abi.decode(rawPools, (PoolIdConfig[])); - bytes memory callData = abi.encodeWithSelector( StargateFacet.initStargate.selector, - poolCfg, cidCfg ); - for (uint256 i = 0; i < poolCfg.length; i++) { - console.log(poolCfg[i].poolId); - console.log(poolCfg[i].token); - } vm.startBroadcast(deployerPrivateKey); // Stargate diff --git a/script/utils/UpdateScriptBase.sol b/script/utils/UpdateScriptBase.sol index fe6f5a3a4..e91ff8aab 100644 --- a/script/utils/UpdateScriptBase.sol +++ b/script/utils/UpdateScriptBase.sol @@ -37,18 +37,17 @@ contract UpdateScriptBase is Script { "json" ); json = vm.readFile(path); - diamond = useDefaultDiamond ? - json.readAddress(".LiFiDiamond") : - json.readAddress(".LiFiDiamondImmutableV1") - ; + diamond = useDefaultDiamond + ? json.readAddress(".LiFiDiamond") + : json.readAddress(".LiFiDiamondImmutableV1"); cutter = DiamondCutFacet(diamond); loupe = DiamondLoupeFacet(diamond); } - function getSelectors(string memory _facetName, bytes4[] memory _exclude) - internal - returns (bytes4[] memory selectors) - { + function getSelectors( + string memory _facetName, + bytes4[] memory _exclude + ) internal returns (bytes4[] memory selectors) { string[] memory cmd = new string[](3); cmd[0] = "scripts/contract-selectors.sh"; cmd[1] = _facetName; diff --git a/scripts/demoArbitrumBridge.ts b/scripts/demoArbitrumBridge.ts index eefada36f..1acb80cfc 100644 --- a/scripts/demoArbitrumBridge.ts +++ b/scripts/demoArbitrumBridge.ts @@ -35,8 +35,8 @@ const LIFI_ADDRESS = '0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE' // LiFiDiamond const USDC_ADDRESS = '0x98339D8C260052B7ad81c28c16C0b98420f2B46a' // USDC address on Goerli const TEST_TOKEN_ADDRESS = '0x7ea6eA49B0b0Ae9c5db7907d139D9Cd3439862a1' // TEST Token address on Goerli const UNISWAP_ADDRESS = '0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D' // Uniswap router address on Goerli -const WETH_ADDRESS = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'; // WETH address -const ZERO_ADDRESS = constants.AddressZero; +const WETH_ADDRESS = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2' // WETH address +const ZERO_ADDRESS = constants.AddressZero const destinationChainId = 421613 // Arbitrum Goerli chain id const amountIn = utils.parseEther('1050') const amountOut = utils.parseUnits('1000', 6) @@ -258,10 +258,10 @@ async function main() { // Swap Non-Native Asset into Native Asset and Bridge Native Asset { // Swap amount - const erc20AmountIn = utils.parseUnits('1.5', 6); + const erc20AmountIn = utils.parseUnits('1.5', 6) // Bridge amount - const ethAmountOut = utils.parseEther('0.001'); + const ethAmountOut = utils.parseEther('0.001') const usdc = ERC20__factory.connect(USDC_ADDRESS, wallet) @@ -274,14 +274,13 @@ async function main() { const to = lifi.address // should be a checksummed recipient address const deadline = Math.floor(Date.now() / 1000) + 60 * 20 // 20 minutes from the current Unix time - const dexSwapData = - await uniswap.populateTransaction.swapTokensForExactETH( - ethAmountOut, - erc20AmountIn, - path, - to, - deadline - ) + const dexSwapData = await uniswap.populateTransaction.swapTokensForExactETH( + ethAmountOut, + erc20AmountIn, + path, + to, + deadline + ) const swapData = [ { @@ -328,7 +327,7 @@ async function main() { // ============================================================= const { maxSubmissionCost, gasLimit, maxFeePerGas } = estimates - const maxGasLimit = gasLimit; + const maxGasLimit = gasLimit // Bridge Data const arbitrumData = { diff --git a/scripts/demoSquid.ts b/scripts/demoSquid.ts index 817466329..41a172caf 100644 --- a/scripts/demoSquid.ts +++ b/scripts/demoSquid.ts @@ -1,5 +1,11 @@ import deployments from '../deployments/polygon.staging.json' -import { SquidFacet__factory, ILiFi, SquidFacet, ERC20__factory, ISquidRouter__factory } from '../typechain' +import { + SquidFacet__factory, + ILiFi, + SquidFacet, + ERC20__factory, + ISquidRouter__factory, +} from '../typechain' import { ethers, utils } from 'ethers' import dotenv from 'dotenv' dotenv.config() @@ -7,7 +13,7 @@ dotenv.config() const ROUTE_TYPES: Record = { CALL_BRIDGE: 0, BRIDGE_CALL: 1, - CALL_BRIDGE_CALL: 2 + CALL_BRIDGE_CALL: 2, } const main = async () => { @@ -20,22 +26,36 @@ const main = async () => { const squidFacet = SquidFacet__factory.connect(LIFI_ADDRESS, provider) // Get a route from the Squid API (https://squidrouter.readme.io/reference/get_route) - const route = await fetch('https://api.0xsquid.com/v1/route?fromChain=56&toChain=42161&fromToken=0x55d398326f99059fF775485246999027B3197955&toToken=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&fromAmount=5000000000000000000&toAddress=0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0&slippage=1') + const route = await fetch( + 'https://api.0xsquid.com/v1/route?fromChain=56&toChain=42161&fromToken=0x55d398326f99059fF775485246999027B3197955&toToken=0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE&fromAmount=5000000000000000000&toAddress=0x552008c0f6870c2f77e5cC1d2eb9bdff03e30Ea0&slippage=1' + ) const routeJson = await route.json() - const token = ERC20__factory.connect(routeJson.route.params.fromToken.address, provider) + const token = ERC20__factory.connect( + routeJson.route.params.fromToken.address, + provider + ) const iface = ISquidRouter__factory.createInterface() let decodedData switch (routeJson.route.transactionRequest.routeType) { case 'CALL_BRIDGE': - decodedData = iface.decodeFunctionData('callBridge', routeJson.route.transactionRequest.data) + decodedData = iface.decodeFunctionData( + 'callBridge', + routeJson.route.transactionRequest.data + ) break case 'BRIDGE_CALL': - decodedData = iface.decodeFunctionData('bridgeCall', routeJson.route.transactionRequest.data) + decodedData = iface.decodeFunctionData( + 'bridgeCall', + routeJson.route.transactionRequest.data + ) break case 'CALL_BRIDGE_CALL': - decodedData = iface.decodeFunctionData('callBridgeCall', routeJson.route.transactionRequest.data) + decodedData = iface.decodeFunctionData( + 'callBridgeCall', + routeJson.route.transactionRequest.data + ) break } @@ -52,7 +72,6 @@ const main = async () => { hasDestinationCall: decodedData?.destinationCalls.length > 0, } - const squidData: SquidFacet.SquidDataStruct = { routeType: ROUTE_TYPES[routeJson.route.transactionRequest.routeType], destinationChain: decodedData?.destinationChain, @@ -64,12 +83,22 @@ const main = async () => { } const txRequest = routeJson.route.transactionRequest - let { value, gasLimit, maxFeePerGas, maxPriorityFeePerGas } = txRequest - gasLimit = (parseInt(gasLimit) + 200000).toString() + const { value, maxFeePerGas, maxPriorityFeePerGas } = txRequest - let tx = await token.connect(signer).approve(LIFI_ADDRESS, bridgeData.minAmount, { maxFeePerGas, maxPriorityFeePerGas }) + let tx = await token + .connect(signer) + .approve(LIFI_ADDRESS, bridgeData.minAmount, { + maxFeePerGas, + maxPriorityFeePerGas, + }) await tx.wait() - tx = await squidFacet.connect(signer).startBridgeTokensViaSquid(bridgeData, squidData, { value, maxFeePerGas, maxPriorityFeePerGas }) + tx = await squidFacet + .connect(signer) + .startBridgeTokensViaSquid(bridgeData, squidData, { + value, + maxFeePerGas, + maxPriorityFeePerGas, + }) await tx.wait() } diff --git a/scripts/demoThorSwap.ts b/scripts/demoThorSwap.ts index 8b9d9a7d3..b4a5a0a5e 100644 --- a/scripts/demoThorSwap.ts +++ b/scripts/demoThorSwap.ts @@ -1,5 +1,10 @@ import deployments from '../deployments/mainnet.staging.json' -import { ThorSwapFacet__factory, ILiFi, ThorSwapFacet, ERC20__factory } from '../typechain' +import { + ThorSwapFacet__factory, + ILiFi, + ThorSwapFacet, + ERC20__factory, +} from '../typechain' import { ethers, utils } from 'ethers' import dotenv from 'dotenv' dotenv.config() @@ -13,15 +18,14 @@ const main = async () => { const signer = new ethers.Wallet(PRIVATE_KEY as string, provider) const thorSwapFacet = ThorSwapFacet__factory.connect(LIFI_ADDRESS, provider) - let resp - let quote - let route let tx - resp = await fetch('https://dev-api.thorswap.net/aggregator/tokens/quote?sellAsset=ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&buyAsset=LTC.LTC&sellAmount=10&recipientAddress=ltc1qpl20tgr56q6wk7t6gug0z77dhk80ppw728mvzx&providers=THORCHAIN') - quote = await resp.json() + const resp = await fetch( + 'https://dev-api.thorswap.net/aggregator/tokens/quote?sellAsset=ETH.USDC-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&buyAsset=LTC.LTC&sellAmount=10&recipientAddress=ltc1qpl20tgr56q6wk7t6gug0z77dhk80ppw728mvzx&providers=THORCHAIN' + ) + const quote = await resp.json() // @ts-ignore - route = quote.routes.filter(r => r.optimal === true)[0] + const route = quote.routes.filter((r) => r.optimal === true)[0] const token = ERC20__factory.connect(route.calldata.assetAddress, provider) @@ -41,13 +45,16 @@ const main = async () => { const thorSwapData: ThorSwapFacet.ThorSwapDataStruct = { vault: route.calldata.tcVault, memo: route.calldata.memo, - expiration: route.calldata.expiration + expiration: route.calldata.expiration, } - - tx = await token.connect(signer).approve(LIFI_ADDRESS, route.calldata.amountIn) + tx = await token + .connect(signer) + .approve(LIFI_ADDRESS, route.calldata.amountIn) await tx.wait() - tx = await thorSwapFacet.connect(signer).startBridgeTokensViaThorSwap(bridgeData, thorSwapData) + tx = await thorSwapFacet + .connect(signer) + .startBridgeTokensViaThorSwap(bridgeData, thorSwapData) await tx.wait() } diff --git a/src/Errors/GenericErrors.sol b/src/Errors/GenericErrors.sol index 66b1f0285..a5d1121b4 100644 --- a/src/Errors/GenericErrors.sol +++ b/src/Errors/GenericErrors.sol @@ -32,4 +32,5 @@ error ReentrancyError(); error TokenNotSupported(); error UnAuthorized(); error UnsupportedChainId(uint256 chainId); +error WithdrawFailed(); error ZeroAmount(); diff --git a/src/Facets/AccessManagerFacet.sol b/src/Facets/AccessManagerFacet.sol index 2a4a11d5e..92f9035ab 100644 --- a/src/Facets/AccessManagerFacet.sol +++ b/src/Facets/AccessManagerFacet.sol @@ -8,6 +8,7 @@ import { CannotAuthoriseSelf } from "../Errors/GenericErrors.sol"; /// @title Access Manager Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for managing method level access control +/// @custom:version 1.0.0 contract AccessManagerFacet { /// Events /// @@ -42,11 +43,10 @@ contract AccessManagerFacet { /// @notice Check if a method can be executed by a specific address /// @param _selector The method selector to check /// @param _executor The address to check - function addressCanExecuteMethod(bytes4 _selector, address _executor) - external - view - returns (bool) - { + function addressCanExecuteMethod( + bytes4 _selector, + address _executor + ) external view returns (bool) { return LibAccess.accessStorage().execAccess[_selector][_executor]; } } diff --git a/src/Facets/AcrossFacet.sol b/src/Facets/AcrossFacet.sol index 228dd04bd..d067f1a20 100644 --- a/src/Facets/AcrossFacet.sol +++ b/src/Facets/AcrossFacet.sol @@ -13,6 +13,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title Across Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Across Protocol +/// @custom:version 1.0.0 contract AcrossFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -22,9 +23,6 @@ contract AcrossFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @notice The WETH address on the current chain. address private immutable wrappedNative; - /// Errors - error QuoteTimeout(); - /// Types /// /// @param relayerFeePct The relayer fee in token percentage with 18 decimals. @@ -75,7 +73,7 @@ contract AcrossFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { function swapAndStartBridgeTokensViaAcross( ILiFi.BridgeData memory _bridgeData, LibSwap.SwapData[] calldata _swapData, - AcrossData memory _acrossData + AcrossData calldata _acrossData ) external payable @@ -101,26 +99,32 @@ contract AcrossFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @param _acrossData data specific to Across function _startBridge( ILiFi.BridgeData memory _bridgeData, - AcrossData memory _acrossData + AcrossData calldata _acrossData ) internal { - bool isNative = _bridgeData.sendingAssetId == LibAsset.NATIVE_ASSETID; - address sendingAsset = _bridgeData.sendingAssetId; - if (isNative) sendingAsset = wrappedNative; - else + if (LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) { + spokePool.deposit{ value: _bridgeData.minAmount }( + _bridgeData.receiver, + wrappedNative, + _bridgeData.minAmount, + _bridgeData.destinationChainId, + _acrossData.relayerFeePct, + _acrossData.quoteTimestamp + ); + } else { LibAsset.maxApproveERC20( IERC20(_bridgeData.sendingAssetId), address(spokePool), _bridgeData.minAmount ); - - spokePool.deposit{ value: isNative ? _bridgeData.minAmount : 0 }( - _bridgeData.receiver, - sendingAsset, - _bridgeData.minAmount, - _bridgeData.destinationChainId, - _acrossData.relayerFeePct, - _acrossData.quoteTimestamp - ); + spokePool.deposit( + _bridgeData.receiver, + _bridgeData.sendingAssetId, + _bridgeData.minAmount, + _bridgeData.destinationChainId, + _acrossData.relayerFeePct, + _acrossData.quoteTimestamp + ); + } emit LiFiTransferStarted(_bridgeData); } diff --git a/src/Facets/AllBridgeFacet.sol b/src/Facets/AllBridgeFacet.sol index 1cae970b9..895254c3c 100644 --- a/src/Facets/AllBridgeFacet.sol +++ b/src/Facets/AllBridgeFacet.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.7; +pragma solidity 0.8.17; import { ILiFi } from "../Interfaces/ILiFi.sol"; import { IAllBridge } from "../Interfaces/IAllBridge.sol"; @@ -12,9 +12,10 @@ import { LibSwap } from "../Libraries/LibSwap.sol"; /// @title Allbridge Facet /// @author Li.Finance (https://li.finance) /// @notice Provides functionality for bridging through AllBridge +/// @custom:version 1.0.0 contract AllBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @notice The contract address of the AllBridge router on the source chain. - IAllBridge public immutable allBridge; + IAllBridge private immutable allBridge; /// @notice The struct for the AllBridge data. /// @param fees The amount of token to pay the messenger and the bridge diff --git a/src/Facets/AmarokFacet.sol b/src/Facets/AmarokFacet.sol index e45c2e62b..96f1ce7e3 100644 --- a/src/Facets/AmarokFacet.sol +++ b/src/Facets/AmarokFacet.sol @@ -12,6 +12,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title Amarok Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Connext Amarok +/// @custom:version 1.0.0 contract AmarokFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -26,7 +27,6 @@ contract AmarokFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @param destChainDomainId The Amarok-specific domainId of the destination chain struct AmarokData { bytes callData; - address callTo; uint256 relayerFee; uint256 slippageTol; address delegate; @@ -58,11 +58,7 @@ contract AmarokFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { validateBridgeData(_bridgeData) noNativeAsset(_bridgeData) { - if ( - hasDestinationCall(_amarokData) != _bridgeData.hasDestinationCall - ) { - revert InformationMismatch(); - } + validateDestinationCallFlag(_bridgeData, _amarokData); LibAsset.depositAsset( _bridgeData.sendingAssetId, @@ -88,11 +84,7 @@ contract AmarokFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { validateBridgeData(_bridgeData) noNativeAsset(_bridgeData) { - if ( - hasDestinationCall(_amarokData) != _bridgeData.hasDestinationCall - ) { - revert InformationMismatch(); - } + validateDestinationCallFlag(_bridgeData, _amarokData); _bridgeData.minAmount = _depositAndSwap( _bridgeData.transactionId, @@ -119,14 +111,10 @@ contract AmarokFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { _bridgeData.minAmount ); - address receiver = _bridgeData.hasDestinationCall - ? _amarokData.callTo - : _bridgeData.receiver; - // initiate bridge transaction connextHandler.xcall{ value: _amarokData.relayerFee }( _amarokData.destChainDomainId, - receiver, + _bridgeData.receiver, _bridgeData.sendingAssetId, _amarokData.delegate, _bridgeData.minAmount, @@ -137,11 +125,14 @@ contract AmarokFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { emit LiFiTransferStarted(_bridgeData); } - function hasDestinationCall(AmarokData calldata _amarokData) - private - pure - returns (bool) - { - return _amarokData.callData.length > 0; + function validateDestinationCallFlag( + ILiFi.BridgeData memory _bridgeData, + AmarokData calldata _amarokData + ) private pure { + if ( + (_amarokData.callData.length > 0) != _bridgeData.hasDestinationCall + ) { + revert InformationMismatch(); + } } } diff --git a/src/Facets/ArbitrumBridgeFacet.sol b/src/Facets/ArbitrumBridgeFacet.sol index 208698b93..62d570121 100644 --- a/src/Facets/ArbitrumBridgeFacet.sol +++ b/src/Facets/ArbitrumBridgeFacet.sol @@ -12,6 +12,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title Arbitrum Bridge Facet /// @author Li.Finance (https://li.finance) /// @notice Provides functionality for bridging through Arbitrum Bridge +/// @custom:version 1.0.0 contract ArbitrumBridgeFacet is ILiFi, ReentrancyGuard, @@ -67,11 +68,13 @@ contract ArbitrumBridgeFacet is uint256 cost = _arbitrumData.maxSubmissionCost + _arbitrumData.maxGas * _arbitrumData.maxGasPrice; + LibAsset.depositAsset( _bridgeData.sendingAssetId, _bridgeData.minAmount ); - _startBridge(_bridgeData, _arbitrumData, cost, msg.value); + + _startBridge(_bridgeData, _arbitrumData, cost); } /// @notice Performs a swap before bridging via Arbitrum Bridge @@ -95,7 +98,6 @@ contract ArbitrumBridgeFacet is _arbitrumData.maxGas * _arbitrumData.maxGasPrice; - uint256 ethBalance = address(this).balance - msg.value; _bridgeData.minAmount = _depositAndSwap( _bridgeData.transactionId, _bridgeData.minAmount, @@ -104,16 +106,7 @@ contract ArbitrumBridgeFacet is cost ); - if (LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) { - _bridgeData.minAmount -= cost; - } - - _startBridge( - _bridgeData, - _arbitrumData, - cost, - address(this).balance - ethBalance - ); + _startBridge(_bridgeData, _arbitrumData, cost); } /// Private Methods /// @@ -122,69 +115,40 @@ contract ArbitrumBridgeFacet is /// @param _bridgeData Data containing core information for bridging /// @param _arbitrumData Data for gateway router address, asset id and amount /// @param _cost Additional amount of native asset for the fee - /// @param _receivedEther Amount of ether received from function _startBridge( ILiFi.BridgeData memory _bridgeData, ArbitrumData calldata _arbitrumData, - uint256 _cost, - uint256 _receivedEther - ) private validateBridgeData(_bridgeData) { - bool isNativeTransfer = LibAsset.isNativeAsset( - _bridgeData.sendingAssetId - ); - - uint256 requiredEther = isNativeTransfer - ? _cost + _bridgeData.minAmount - : _cost; - if (_receivedEther < requiredEther) { - revert InvalidAmount(); - } - - if (isNativeTransfer) { - _startNativeBridge(_bridgeData, _arbitrumData, _cost); + uint256 _cost + ) private { + if (LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) { + inbox.unsafeCreateRetryableTicket{ + value: _bridgeData.minAmount + _cost + }( + _bridgeData.receiver, + _bridgeData.minAmount, // l2CallValue + _arbitrumData.maxSubmissionCost, + _bridgeData.receiver, // excessFeeRefundAddress + _bridgeData.receiver, // callValueRefundAddress + _arbitrumData.maxGas, + _arbitrumData.maxGasPrice, + "" + ); } else { - _startTokenBridge(_bridgeData, _arbitrumData, _cost); + LibAsset.maxApproveERC20( + IERC20(_bridgeData.sendingAssetId), + gatewayRouter.getGateway(_bridgeData.sendingAssetId), + _bridgeData.minAmount + ); + gatewayRouter.outboundTransfer{ value: _cost }( + _bridgeData.sendingAssetId, + _bridgeData.receiver, + _bridgeData.minAmount, + _arbitrumData.maxGas, + _arbitrumData.maxGasPrice, + abi.encode(_arbitrumData.maxSubmissionCost, "") + ); } emit LiFiTransferStarted(_bridgeData); } - - function _startTokenBridge( - ILiFi.BridgeData memory _bridgeData, - ArbitrumData calldata _arbitrumData, - uint256 cost - ) private { - LibAsset.maxApproveERC20( - IERC20(_bridgeData.sendingAssetId), - gatewayRouter.getGateway(_bridgeData.sendingAssetId), - _bridgeData.minAmount - ); - gatewayRouter.outboundTransfer{ value: cost }( - _bridgeData.sendingAssetId, - _bridgeData.receiver, - _bridgeData.minAmount, - _arbitrumData.maxGas, - _arbitrumData.maxGasPrice, - abi.encode(_arbitrumData.maxSubmissionCost, "") - ); - } - - function _startNativeBridge( - ILiFi.BridgeData memory _bridgeData, - ArbitrumData calldata _arbitrumData, - uint256 cost - ) private { - inbox.unsafeCreateRetryableTicket{ - value: _bridgeData.minAmount + cost - }( - _bridgeData.receiver, - _bridgeData.minAmount, // l2CallValue - _arbitrumData.maxSubmissionCost, - _bridgeData.receiver, // excessFeeRefundAddress - _bridgeData.receiver, // callValueRefundAddress - _arbitrumData.maxGas, - _arbitrumData.maxGasPrice, - "" - ); - } } diff --git a/src/Facets/AxelarFacet.sol b/src/Facets/AxelarFacet.sol index 8a78341f2..790e46e34 100644 --- a/src/Facets/AxelarFacet.sol +++ b/src/Facets/AxelarFacet.sol @@ -11,6 +11,10 @@ import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol"; +/// @title Axelar Facet +/// @author Li.Finance (https://li.finance) +/// @notice Provides functionality for cross-chain contract calls via Axelar Network +/// @custom:version 1.0.0 contract AxelarFacet is ReentrancyGuard { /// Storage /// @@ -76,11 +80,9 @@ contract AxelarFacet is ReentrancyGuard { /// @notice Initiates a cross-chain contract call via Axelar Network /// @param params the parameters for the cross-chain call - function executeCallViaAxelar(AxelarCallParameters calldata params) - external - payable - nonReentrant - { + function executeCallViaAxelar( + AxelarCallParameters calldata params + ) external payable nonReentrant { Storage storage s = getStorage(); bytes memory payload = abi.encodePacked( params.callTo, diff --git a/src/Facets/CBridgeFacet.sol b/src/Facets/CBridgeFacet.sol index 5d90a51fc..291775e64 100644 --- a/src/Facets/CBridgeFacet.sol +++ b/src/Facets/CBridgeFacet.sol @@ -16,6 +16,7 @@ import { ContractCallNotAllowed, ExternalCallFailed } from "../Errors/GenericErr /// @title CBridge Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through CBridge +/// @custom:version 1.0.0 contract CBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -78,7 +79,7 @@ contract CBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { function swapAndStartBridgeTokensViaCBridge( ILiFi.BridgeData memory _bridgeData, LibSwap.SwapData[] calldata _swapData, - CBridgeData memory _cBridgeData + CBridgeData calldata _cBridgeData ) external payable @@ -132,7 +133,6 @@ contract CBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { emit CBridgeRefund(_assetAddress, sendTo, _amount); } - /// Private Methods /// /// @dev Contains the business logic for the bridge via CBridge @@ -140,11 +140,8 @@ contract CBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @param _cBridgeData data specific to CBridge function _startBridge( ILiFi.BridgeData memory _bridgeData, - CBridgeData memory _cBridgeData + CBridgeData calldata _cBridgeData ) private { - if (uint64(block.chainid) == _bridgeData.destinationChainId) - revert CannotBridgeToSameNetwork(); - if (LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) { cBridge.sendNative{ value: _bridgeData.minAmount }( _bridgeData.receiver, diff --git a/src/Facets/CBridgeFacetPacked.sol b/src/Facets/CBridgeFacetPacked.sol index a8476e2fe..4d5f26ef0 100644 --- a/src/Facets/CBridgeFacetPacked.sol +++ b/src/Facets/CBridgeFacetPacked.sol @@ -9,6 +9,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /// @title CBridge Facet Packed /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through CBridge +/// @custom:version 1.0.0 contract CBridgeFacetPacked is ILiFi { /// Storage /// @@ -27,9 +28,11 @@ contract CBridgeFacetPacked is ILiFi { /// @notice Bridges Native tokens via cBridge (packed) /// No params, all data will be extracted from manually encoded callData - function startBridgeTokensViaCBridgeNativePacked( - ) external payable { - require(msg.data.length >= 60, "callData length smaller than required"); + function startBridgeTokensViaCBridgeNativePacked() external payable { + require( + msg.data.length >= 60, + "callData length smaller than required" + ); _startBridgeTokensViaCBridgeNative({ // first 4 bytes are function signature @@ -58,7 +61,7 @@ contract CBridgeFacetPacked is ILiFi { uint64 nonce, uint32 maxSlippage ) external payable { - _startBridgeTokensViaCBridgeNative( + _startBridgeTokensViaCBridgeNative( transactionId, integrator, receiver, @@ -83,25 +86,36 @@ contract CBridgeFacetPacked is ILiFi { uint64 nonce, uint32 maxSlippage ) external pure returns (bytes memory) { - require(destinationChainId <= type(uint32).max, "destinationChainId value passed too big to fit in uint32"); - require(nonce <= type(uint32).max, "nonce value passed too big to fit in uint32"); - - return bytes.concat( - CBridgeFacetPacked.startBridgeTokensViaCBridgeNativePacked.selector, - bytes8(transactionId), - bytes16(bytes(integrator)), - bytes20(receiver), - bytes4(uint32(destinationChainId)), - bytes4(uint32(nonce)), - bytes4(maxSlippage) + require( + destinationChainId <= type(uint32).max, + "destinationChainId value passed too big to fit in uint32" + ); + require( + nonce <= type(uint32).max, + "nonce value passed too big to fit in uint32" ); + + return + bytes.concat( + CBridgeFacetPacked + .startBridgeTokensViaCBridgeNativePacked + .selector, + bytes8(transactionId), + bytes16(bytes(integrator)), + bytes20(receiver), + bytes4(uint32(destinationChainId)), + bytes4(uint32(nonce)), + bytes4(maxSlippage) + ); } /// @notice Bridges ERC20 tokens via cBridge /// No params, all data will be extracted from manually encoded callData - function startBridgeTokensViaCBridgeERC20Packed( - ) external { - require(msg.data.length >= 96, "callData length smaller than required"); + function startBridgeTokensViaCBridgeERC20Packed() external { + require( + msg.data.length >= 96, + "callData length smaller than required" + ); _startBridgeTokensViaCBridgeERC20({ // first 4 bytes are function signature @@ -167,21 +181,33 @@ contract CBridgeFacetPacked is ILiFi { uint64 nonce, uint32 maxSlippage ) external pure returns (bytes memory) { - require(destinationChainId <= type(uint32).max, "destinationChainId value passed too big to fit in uint32"); - require(amount <= type(uint128).max, "amount value passed too big to fit in uint128"); - require(nonce <= type(uint32).max, "nonce value passed too big to fit in uint32"); - - return bytes.concat( - CBridgeFacetPacked.startBridgeTokensViaCBridgeERC20Packed.selector, - bytes8(transactionId), - bytes16(bytes(integrator)), - bytes20(receiver), - bytes4(uint32(destinationChainId)), - bytes20(sendingAssetId), - bytes16(uint128(amount)), - bytes4(uint32(nonce)), - bytes4(maxSlippage) + require( + destinationChainId <= type(uint32).max, + "destinationChainId value passed too big to fit in uint32" + ); + require( + amount <= type(uint128).max, + "amount value passed too big to fit in uint128" ); + require( + nonce <= type(uint32).max, + "nonce value passed too big to fit in uint32" + ); + + return + bytes.concat( + CBridgeFacetPacked + .startBridgeTokensViaCBridgeERC20Packed + .selector, + bytes8(transactionId), + bytes16(bytes(integrator)), + bytes20(receiver), + bytes4(uint32(destinationChainId)), + bytes20(sendingAssetId), + bytes16(uint128(amount)), + bytes4(uint32(nonce)), + bytes4(maxSlippage) + ); } /// Internal Methods /// @@ -203,18 +229,20 @@ contract CBridgeFacetPacked is ILiFi { maxSlippage ); - emit LiFiTransferStarted(BridgeData({ - transactionId: transactionId, - bridge: "cbridge", - integrator: integrator, - referrer: address(0), - sendingAssetId: address(0), - receiver: receiver, - minAmount: msg.value, - destinationChainId: destinationChainId, - hasSourceSwaps: false, - hasDestinationCall: false - })); + emit LiFiTransferStarted( + BridgeData({ + transactionId: transactionId, + bridge: "cbridge", + integrator: integrator, + referrer: address(0), + sendingAssetId: address(0), + receiver: receiver, + minAmount: msg.value, + destinationChainId: destinationChainId, + hasSourceSwaps: false, + hasDestinationCall: false + }) + ); } function _startBridgeTokensViaCBridgeERC20( @@ -228,9 +256,15 @@ contract CBridgeFacetPacked is ILiFi { uint32 maxSlippage ) private { // Deposit assets - SafeERC20.safeTransferFrom(IERC20(sendingAssetId), msg.sender, address(this), amount); + SafeERC20.safeTransferFrom( + IERC20(sendingAssetId), + msg.sender, + address(this), + amount + ); // Bridge assets + // solhint-disable-next-line check-send-result cBridge.send( receiver, sendingAssetId, @@ -240,17 +274,19 @@ contract CBridgeFacetPacked is ILiFi { maxSlippage ); - emit LiFiTransferStarted(BridgeData({ - transactionId: transactionId, - bridge: "cbridge", - integrator: integrator, - referrer: address(0), - sendingAssetId: sendingAssetId, - receiver: receiver, - minAmount: amount, - destinationChainId: destinationChainId, - hasSourceSwaps: false, - hasDestinationCall: false - })); + emit LiFiTransferStarted( + BridgeData({ + transactionId: transactionId, + bridge: "cbridge", + integrator: integrator, + referrer: address(0), + sendingAssetId: sendingAssetId, + receiver: receiver, + minAmount: amount, + destinationChainId: destinationChainId, + hasSourceSwaps: false, + hasDestinationCall: false + }) + ); } } diff --git a/src/Facets/CelerIMFacet.sol b/src/Facets/CelerIMFacet.sol index 7e3413480..486699e96 100644 --- a/src/Facets/CelerIMFacet.sol +++ b/src/Facets/CelerIMFacet.sol @@ -19,6 +19,7 @@ interface CelerToken { /// @title CelerIM Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging tokens and data through CBridge +/// @custom:version 1.0.0 contract CelerIMFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -28,14 +29,21 @@ contract CelerIMFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @dev The contract address of the RelayerCelerIM RelayerCelerIM private immutable relayer; + /// @dev The contract address of the Celer Flow USDC + address private immutable cfUSDC; + /// Types /// /// @param maxSlippage The max slippage accepted, given as percentage in point (pip). /// @param nonce A number input to guarantee uniqueness of transferId. Can be timestamp in practice. - /// @param callTo the address of the contract to be called at destination - /// @param callData the encoded calldata (bytes32 transactionId, LibSwap.SwapData[] memory swapData, address receiver, address refundAddress) - /// @param messageBusFee the fee to be paid to CBridge message bus for relaying the message - /// @param bridgeType defines the bridge operation type (must be one of the values of CBridge library MsgDataTypes.BridgeSendType) + /// @param callTo The address of the contract to be called at destination. + /// @param callData The encoded calldata with below data + /// bytes32 transactionId, + /// LibSwap.SwapData[] memory swapData, + /// address receiver, + /// address refundAddress + /// @param messageBusFee The fee to be paid to CBridge message bus for relaying the message + /// @param bridgeType Defines the bridge operation type (must be one of the values of CBridge library MsgDataTypes.BridgeSendType) struct CelerIMData { uint32 maxSlippage; uint64 nonce; @@ -50,16 +58,22 @@ contract CelerIMFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @notice Initialize the contract. /// @param _messageBus The contract address of the cBridge Message Bus /// @param _relayer The contract address of the RelayerCelerIM - constructor(IMessageBus _messageBus, RelayerCelerIM _relayer) { + /// @param _cfUSDC The contract address of the Celer Flow USDC + constructor( + IMessageBus _messageBus, + RelayerCelerIM _relayer, + address _cfUSDC + ) { cBridgeMessageBus = _messageBus; relayer = _relayer; + cfUSDC = _cfUSDC; } /// External Methods /// /// @notice Bridges tokens via CBridge - /// @param _bridgeData the core information needed for bridging - /// @param _celerIMData data specific to CelerIM + /// @param _bridgeData The core information needed for bridging + /// @param _celerIMData Data specific to CelerIM function startBridgeTokensViaCelerIM( ILiFi.BridgeData memory _bridgeData, CelerIMData calldata _celerIMData @@ -73,24 +87,10 @@ contract CelerIMFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { { validateDestinationCallFlag(_bridgeData, _celerIMData); if (!LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) { - // transfer ERC20 tokens directly to relayer - IERC20 asset; - if ( - keccak256( - abi.encodePacked( - ERC20(_bridgeData.sendingAssetId).symbol() - ) - ) == keccak256(abi.encodePacked(("cfUSDC"))) - ) { - // special case for cfUSDC token - asset = IERC20( - CelerToken(_bridgeData.sendingAssetId).canonical() - ); - } else { - // any other ERC20 token - asset = IERC20(_bridgeData.sendingAssetId); - } - // deposit ERC20 token + // Transfer ERC20 tokens directly to relayer + IERC20 asset = _getRightAsset(_bridgeData.sendingAssetId); + + // Deposit ERC20 token uint256 prevBalance = asset.balanceOf(address(relayer)); SafeERC20.safeTransferFrom( asset, @@ -98,22 +98,26 @@ contract CelerIMFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { address(relayer), _bridgeData.minAmount ); + if ( asset.balanceOf(address(relayer)) - prevBalance != _bridgeData.minAmount - ) revert InvalidAmount(); + ) { + revert InvalidAmount(); + } } + _startBridge(_bridgeData, _celerIMData); } /// @notice Performs a swap before bridging via CBridge - /// @param _bridgeData the core information needed for bridging - /// @param _swapData an array of swap related data for performing swaps before bridging - /// @param _celerIMData data specific to CelerIM + /// @param _bridgeData The core information needed for bridging + /// @param _swapData An array of swap related data for performing swaps before bridging + /// @param _celerIMData Data specific to CelerIM function swapAndStartBridgeTokensViaCelerIM( ILiFi.BridgeData memory _bridgeData, LibSwap.SwapData[] calldata _swapData, - CelerIMData memory _celerIMData + CelerIMData calldata _celerIMData ) external payable @@ -128,21 +132,28 @@ contract CelerIMFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { _bridgeData.transactionId, _bridgeData.minAmount, _swapData, - payable(msg.sender) + payable(msg.sender), + _celerIMData.messageBusFee ); + if (!LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) { - // transfer ERC20 tokens directly to relayer - IERC20 asset = IERC20(_bridgeData.sendingAssetId); + // Transfer ERC20 tokens directly to relayer + IERC20 asset = _getRightAsset(_bridgeData.sendingAssetId); + + // Deposit ERC20 token uint256 prevBalance = asset.balanceOf(address(relayer)); SafeERC20.safeTransfer( asset, address(relayer), _bridgeData.minAmount ); + if ( asset.balanceOf(address(relayer)) - prevBalance != _bridgeData.minAmount - ) revert InvalidAmount(); + ) { + revert InvalidAmount(); + } } _startBridge(_bridgeData, _celerIMData); @@ -151,44 +162,74 @@ contract CelerIMFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Private Methods /// /// @dev Contains the business logic for the bridge via CBridge - /// @param _bridgeData the core information needed for bridging - /// @param _celerIMData data specific to CBridge + /// @param _bridgeData The core information needed for bridging + /// @param _celerIMData Data specific to CBridge function _startBridge( ILiFi.BridgeData memory _bridgeData, - CelerIMData memory _celerIMData + CelerIMData calldata _celerIMData ) private { - // assuming messageBusFee is pre-calculated off-chain and available in _celerIMData - // determine correct native asset amount to be forwarded (if so) and send funds to relayer + // Assuming messageBusFee is pre-calculated off-chain and available in _celerIMData + // Determine correct native asset amount to be forwarded (if so) and send funds to relayer uint256 msgValue = LibAsset.isNativeAsset(_bridgeData.sendingAssetId) ? _bridgeData.minAmount : 0; - // check if transaction contains a destination call + + // Check if transaction contains a destination call if (!_bridgeData.hasDestinationCall) { - // case 'no': simple bridge transfer - send to receiver - relayer.sendTokenTransfer{ value: msgValue }(_bridgeData, _celerIMData); + // Case 'no': Simple bridge transfer - Send to receiver + relayer.sendTokenTransfer{ value: msgValue }( + _bridgeData, + _celerIMData + ); } else { - // case 'yes': bridge + dest call - send to relayer - ILiFi.BridgeData memory bridgeDataAdjusted = _bridgeData; - bridgeDataAdjusted.receiver = address(relayer); + // Case 'yes': Bridge + Destination call - Send to relayer + address receiver = _bridgeData.receiver; + // Set relayer as a receiver + _bridgeData.receiver = address(relayer); + (bytes32 transferId, address bridgeAddress) = relayer - .sendTokenTransfer{ value: msgValue }(bridgeDataAdjusted, _celerIMData); - // call message bus via relayer incl messageBusFee - relayer.forwardSendMessageWithTransfer{value: _celerIMData.messageBusFee}( - _bridgeData.receiver, + .sendTokenTransfer{ value: msgValue }( + _bridgeData, + _celerIMData + ); + + // Call message bus via relayer incl messageBusFee + relayer.forwardSendMessageWithTransfer{ + value: _celerIMData.messageBusFee + }( + receiver, uint64(_bridgeData.destinationChainId), bridgeAddress, transferId, _celerIMData.callData ); + + // Reset receiver of bridge data for event emission + _bridgeData.receiver = receiver; } // emit LiFi event emit LiFiTransferStarted(_bridgeData); } + /// @dev Get right asset to transfer to relayer. + /// @param _sendingAssetId The address of asset to bridge. + /// @return _asset The address of asset to transfer to relayer. + function _getRightAsset( + address _sendingAssetId + ) private returns (IERC20 _asset) { + if (_sendingAssetId == cfUSDC) { + // special case for cfUSDC token + _asset = IERC20(CelerToken(_sendingAssetId).canonical()); + } else { + // any other ERC20 token + _asset = IERC20(_sendingAssetId); + } + } + function validateDestinationCallFlag( ILiFi.BridgeData memory _bridgeData, - CelerIMData memory _celerIMData + CelerIMData calldata _celerIMData ) private pure { if ( (_celerIMData.callData.length > 0) != diff --git a/src/Facets/CircleBridgeFacet.sol b/src/Facets/CircleBridgeFacet.sol index 60fa32ea1..7328ae2eb 100644 --- a/src/Facets/CircleBridgeFacet.sol +++ b/src/Facets/CircleBridgeFacet.sol @@ -11,6 +11,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title CircleBridge Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through CircleBridge +/// @custom:version 1.0.0 contract CircleBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -29,7 +30,7 @@ contract CircleBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @notice Initialize the contract. /// @param _tokenMessenger The address of the TokenMessenger on the source chain. - /// @param _usdc The address of DAI on the source chain. + /// @param _usdc The address of USDC on the source chain. constructor(ITokenMessenger _tokenMessenger, address _usdc) { tokenMessenger = _tokenMessenger; usdc = _usdc; @@ -45,13 +46,10 @@ contract CircleBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { CircleBridgeData calldata _circleBridgeData ) external - payable nonReentrant - refundExcessNative(payable(msg.sender)) doesNotContainSourceSwaps(_bridgeData) doesNotContainDestinationCalls(_bridgeData) validateBridgeData(_bridgeData) - noNativeAsset(_bridgeData) onlyAllowSourceToken(_bridgeData, usdc) { LibAsset.depositAsset(usdc, _bridgeData.minAmount); @@ -74,7 +72,6 @@ contract CircleBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { containsSourceSwaps(_bridgeData) doesNotContainDestinationCalls(_bridgeData) validateBridgeData(_bridgeData) - noNativeAsset(_bridgeData) onlyAllowSourceToken(_bridgeData, usdc) { _bridgeData.minAmount = _depositAndSwap( diff --git a/src/Facets/DeBridgeFacet.sol b/src/Facets/DeBridgeFacet.sol index e0f6eeccd..356196ee2 100644 --- a/src/Facets/DeBridgeFacet.sol +++ b/src/Facets/DeBridgeFacet.sol @@ -6,16 +6,17 @@ import { IDeBridgeGate } from "../Interfaces/IDeBridgeGate.sol"; import { LibAsset, IERC20 } from "../Libraries/LibAsset.sol"; import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol"; import { SwapperV2, LibSwap } from "../Helpers/SwapperV2.sol"; -import { InformationMismatch } from "../Errors/GenericErrors.sol"; +import { InformationMismatch, InvalidAmount } from "../Errors/GenericErrors.sol"; import { Validatable } from "../Helpers/Validatable.sol"; /// @title DeBridge Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through DeBridge Protocol +/// @custom:version 1.0.0 contract DeBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// - /// @notice The contract address of the spoke pool on the source chain. + /// @notice The contract address of the DeBridge Gate on the source chain. IDeBridgeGate private immutable deBridgeGate; /// Types /// @@ -32,13 +33,11 @@ contract DeBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { bytes data; } - /// @param permit deadline + signature for approving the spender by signature. /// @param nativeFee Native fee for the bridging when useAssetFee is false. /// @param useAssetFee Use assets fee for pay protocol fix (work only for specials token) /// @param referralCode Referral code. /// @param autoParams Structure that enables passing arbitrary messages and call data. struct DeBridgeData { - bytes permit; uint256 nativeFee; bool useAssetFee; uint32 referralCode; @@ -104,10 +103,6 @@ contract DeBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { _deBridgeData.nativeFee ); - if (LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) { - _bridgeData.minAmount -= _deBridgeData.nativeFee; - } - _startBridge(_bridgeData, _deBridgeData); } @@ -120,6 +115,16 @@ contract DeBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { ILiFi.BridgeData memory _bridgeData, DeBridgeData calldata _deBridgeData ) internal { + IDeBridgeGate.ChainSupportInfo memory config = deBridgeGate + .getChainToConfig(_bridgeData.destinationChainId); + uint256 nativeFee = config.fixedNativeFee == 0 + ? deBridgeGate.globalFixedNativeFee() + : config.fixedNativeFee; + + if (_deBridgeData.nativeFee != nativeFee) { + revert InvalidAmount(); + } + bool isNative = LibAsset.isNativeAsset(_bridgeData.sendingAssetId); uint256 nativeAssetAmount = _deBridgeData.nativeFee; @@ -133,12 +138,13 @@ contract DeBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { ); } + // solhint-disable-next-line check-send-result deBridgeGate.send{ value: nativeAssetAmount }( _bridgeData.sendingAssetId, _bridgeData.minAmount, _bridgeData.destinationChainId, abi.encodePacked(_bridgeData.receiver), - _deBridgeData.permit, + "", _deBridgeData.useAssetFee, _deBridgeData.referralCode, abi.encode(_deBridgeData.autoParams) diff --git a/src/Facets/DexManagerFacet.sol b/src/Facets/DexManagerFacet.sol index d0699bf42..ea73e9be0 100644 --- a/src/Facets/DexManagerFacet.sol +++ b/src/Facets/DexManagerFacet.sol @@ -9,6 +9,7 @@ import { CannotAuthoriseSelf } from "../Errors/GenericErrors.sol"; /// @title Dex Manager Facet /// @author LI.FI (https://li.fi) /// @notice Facet contract for managing approved DEXs to be used in swaps. +/// @custom:version 1.0.0 contract DexManagerFacet { /// Events /// @@ -88,9 +89,10 @@ contract DexManagerFacet { /// @notice Adds/removes a specific function signature to/from the allowlist /// @param _signature the function signature to allow/disallow /// @param _approval whether the function signature should be allowed - function setFunctionApprovalBySignature(bytes4 _signature, bool _approval) - external - { + function setFunctionApprovalBySignature( + bytes4 _signature, + bool _approval + ) external { if (msg.sender != LibDiamond.contractOwner()) { LibAccess.enforceAccessControl(); } @@ -132,11 +134,9 @@ contract DexManagerFacet { /// @notice Returns whether a function signature is approved /// @param _signature the function signature to query /// @return approved Approved or not - function isFunctionApproved(bytes4 _signature) - public - view - returns (bool approved) - { + function isFunctionApproved( + bytes4 _signature + ) public view returns (bool approved) { return LibAllowList.selectorIsAllowed(_signature); } diff --git a/src/Facets/DiamondLoupeFacet.sol b/src/Facets/DiamondLoupeFacet.sol index 227e0d6ba..19bef0eaf 100644 --- a/src/Facets/DiamondLoupeFacet.sol +++ b/src/Facets/DiamondLoupeFacet.sol @@ -36,7 +36,9 @@ contract DiamondLoupeFacet is IDiamondLoupe, IERC165 { /// @notice Gets all the function selectors provided by a facet. /// @param _facet The facet address. /// @return facetFunctionSelectors_ - function facetFunctionSelectors(address _facet) + function facetFunctionSelectors( + address _facet + ) external view override @@ -64,12 +66,9 @@ contract DiamondLoupeFacet is IDiamondLoupe, IERC165 { /// @dev If facet is not found return address(0). /// @param _functionSelector The function selector. /// @return facetAddress_ The facet address. - function facetAddress(bytes4 _functionSelector) - external - view - override - returns (address facetAddress_) - { + function facetAddress( + bytes4 _functionSelector + ) external view override returns (address facetAddress_) { LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); facetAddress_ = ds .selectorToFacetAndPosition[_functionSelector] @@ -77,12 +76,9 @@ contract DiamondLoupeFacet is IDiamondLoupe, IERC165 { } // This implements ERC-165. - function supportsInterface(bytes4 _interfaceId) - external - view - override - returns (bool) - { + function supportsInterface( + bytes4 _interfaceId + ) external view override returns (bool) { LibDiamond.DiamondStorage storage ds = LibDiamond.diamondStorage(); return ds.supportedInterfaces[_interfaceId]; } diff --git a/src/Facets/GenericSwapFacet.sol b/src/Facets/GenericSwapFacet.sol index 2fc2b6591..374d1cb4c 100644 --- a/src/Facets/GenericSwapFacet.sol +++ b/src/Facets/GenericSwapFacet.sol @@ -13,6 +13,7 @@ import { InvalidReceiver } from "../Errors/GenericErrors.sol"; /// @author LI.FI (https://li.fi) /// @notice Provides functionality for swapping through ANY APPROVED DEX /// @dev Uses calldata to execute APPROVED arbitrary methods on DEXs +/// @custom:version 1.0.0 contract GenericSwapFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// External Methods /// diff --git a/src/Facets/GnosisBridgeFacet.sol b/src/Facets/GnosisBridgeFacet.sol index ee7cc0d1b..f58a8b1f2 100644 --- a/src/Facets/GnosisBridgeFacet.sol +++ b/src/Facets/GnosisBridgeFacet.sol @@ -12,6 +12,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title Gnosis Bridge Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through XDaiBridge +/// @custom:version 1.0.0 contract GnosisBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -40,9 +41,7 @@ contract GnosisBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { ILiFi.BridgeData memory _bridgeData ) external - payable nonReentrant - refundExcessNative(payable(msg.sender)) doesNotContainSourceSwaps(_bridgeData) doesNotContainDestinationCalls(_bridgeData) validateBridgeData(_bridgeData) @@ -63,22 +62,20 @@ contract GnosisBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { external payable nonReentrant + refundExcessNative(payable(msg.sender)) containsSourceSwaps(_bridgeData) doesNotContainDestinationCalls(_bridgeData) validateBridgeData(_bridgeData) onlyAllowDestinationChain(_bridgeData, GNOSIS_CHAIN_ID) onlyAllowSourceToken(_bridgeData, DAI) { - if (_swapData.length == 0) revert NoSwapDataProvided(); - if (_swapData[_swapData.length - 1].receivingAssetId != DAI) { - revert InvalidSendingToken(); - } _bridgeData.minAmount = _depositAndSwap( _bridgeData.transactionId, _bridgeData.minAmount, _swapData, payable(msg.sender) ); + _startBridge(_bridgeData); } diff --git a/src/Facets/GnosisBridgeL2Facet.sol b/src/Facets/GnosisBridgeL2Facet.sol index ee3472213..528519d80 100644 --- a/src/Facets/GnosisBridgeL2Facet.sol +++ b/src/Facets/GnosisBridgeL2Facet.sol @@ -12,7 +12,13 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title Gnosis Bridge Facet on Gnosis Chain /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through XDaiBridge -contract GnosisBridgeL2Facet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { +/// @custom:version 1.0.0 +contract GnosisBridgeL2Facet is + ILiFi, + ReentrancyGuard, + SwapperV2, + Validatable +{ /// Storage /// /// @notice The xDAI address on the source chain. @@ -62,22 +68,20 @@ contract GnosisBridgeL2Facet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { external payable nonReentrant + refundExcessNative(payable(msg.sender)) containsSourceSwaps(_bridgeData) doesNotContainDestinationCalls(_bridgeData) validateBridgeData(_bridgeData) onlyAllowDestinationChain(_bridgeData, ETHEREUM_CHAIN_ID) onlyAllowSourceToken(_bridgeData, XDAI) { - if (_swapData.length == 0) revert NoSwapDataProvided(); - if (_swapData[_swapData.length - 1].receivingAssetId != XDAI) { - revert InvalidSendingToken(); - } _bridgeData.minAmount = _depositAndSwap( _bridgeData.transactionId, _bridgeData.minAmount, _swapData, payable(msg.sender) ); + _startBridge(_bridgeData); } @@ -86,7 +90,9 @@ contract GnosisBridgeL2Facet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @dev Contains the business logic for the bridge via XDaiBridge /// @param _bridgeData the core information needed for bridging function _startBridge(ILiFi.BridgeData memory _bridgeData) private { - xDaiBridge.relayTokens{value: _bridgeData.minAmount}(_bridgeData.receiver); + xDaiBridge.relayTokens{ value: _bridgeData.minAmount }( + _bridgeData.receiver + ); emit LiFiTransferStarted(_bridgeData); } } diff --git a/src/Facets/GravityFacet.sol b/src/Facets/GravityFacet.sol index 03b1d843f..7bd5ef9c5 100644 --- a/src/Facets/GravityFacet.sol +++ b/src/Facets/GravityFacet.sol @@ -11,6 +11,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title Gravity Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Gravity +/// @custom:version 1.0.0 contract GravityFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -37,7 +38,7 @@ contract GravityFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @param _bridgeData the core information needed for bridging function startBridgeTokensViaGravity( ILiFi.BridgeData memory _bridgeData, - GravityData memory _gravityData + GravityData calldata _gravityData ) external payable @@ -61,7 +62,7 @@ contract GravityFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { function swapAndStartBridgeTokensViaGravity( ILiFi.BridgeData memory _bridgeData, LibSwap.SwapData[] calldata _swapData, - GravityData memory _gravityData + GravityData calldata _gravityData ) external payable @@ -87,7 +88,7 @@ contract GravityFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @param _bridgeData the core information needed for bridging function _startBridge( ILiFi.BridgeData memory _bridgeData, - GravityData memory _gravityData + GravityData calldata _gravityData ) private { // Give the Gravity router approval to bridge tokens LibAsset.maxApproveERC20( diff --git a/src/Facets/HopFacet.sol b/src/Facets/HopFacet.sol index 655ee40f5..3f1d149ea 100644 --- a/src/Facets/HopFacet.sol +++ b/src/Facets/HopFacet.sol @@ -13,6 +13,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title Hop Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Hop +/// @custom:version 1.0.0 contract HopFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -120,7 +121,7 @@ contract HopFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { function swapAndStartBridgeTokensViaHop( ILiFi.BridgeData memory _bridgeData, LibSwap.SwapData[] calldata _swapData, - HopData memory _hopData + HopData calldata _hopData ) external payable @@ -146,7 +147,7 @@ contract HopFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @param _hopData data specific to Hop Protocol function _startBridge( ILiFi.BridgeData memory _bridgeData, - HopData memory _hopData + HopData calldata _hopData ) private { address sendingAssetId = _bridgeData.sendingAssetId; Storage storage s = getStorage(); diff --git a/src/Facets/HopFacetOptimized.sol b/src/Facets/HopFacetOptimized.sol index 28b66f54b..d1c614b56 100644 --- a/src/Facets/HopFacetOptimized.sol +++ b/src/Facets/HopFacetOptimized.sol @@ -5,10 +5,12 @@ import { ILiFi } from "../Interfaces/ILiFi.sol"; import { IHopBridge } from "../Interfaces/IHopBridge.sol"; import { LibAsset, IERC20 } from "../Libraries/LibAsset.sol"; import { SwapperV2, LibSwap } from "../Helpers/SwapperV2.sol"; +import { LibDiamond } from "../Libraries/LibDiamond.sol"; /// @title Hop Facet (Optimized) /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Hop +/// @custom:version 1.0.0 contract HopFacetOptimized is ILiFi, SwapperV2 { /// Types /// @@ -21,10 +23,6 @@ contract HopFacetOptimized is ILiFi, SwapperV2 { IHopBridge hopBridge; } - /// Events /// - - event HopBridgeRegistered(address indexed assetId, address bridge); - /// External Methods /// /// @notice Sets approval for the Hop Bridge to spend the specified token @@ -34,6 +32,7 @@ contract HopFacetOptimized is ILiFi, SwapperV2 { address[] calldata bridges, address[] calldata tokensToApprove ) external { + LibDiamond.enforceIsContractOwner(); for (uint256 i; i < bridges.length; i++) { // Give Hop approval to bridge tokens LibAsset.maxApproveERC20( diff --git a/src/Facets/HopFacetPacked.sol b/src/Facets/HopFacetPacked.sol index 07dabc60c..22dc07d0e 100644 --- a/src/Facets/HopFacetPacked.sol +++ b/src/Facets/HopFacetPacked.sol @@ -8,15 +8,17 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /// @title Hop Facet (Optimized for Rollups) /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Hop +/// @custom:version 1.0.0 contract HopFacetPacked is ILiFi { - /// External Methods /// /// @notice Bridges Native tokens via Hop Protocol from L2 /// No params, all data will be extracted from manually encoded callData - function startBridgeTokensViaHopL2NativePacked( - ) external payable { - require(msg.data.length >= 120, "callData length smaller than required"); + function startBridgeTokensViaHopL2NativePacked() external payable { + require( + msg.data.length >= 120, + "callData length smaller than required" + ); _startBridgeTokensViaHopL2Native({ // first 4 bytes are function signature @@ -26,7 +28,9 @@ contract HopFacetPacked is ILiFi { destinationChainId: uint256(uint32(bytes4(msg.data[48:52]))), bonderFee: uint256(uint128(bytes16(msg.data[52:68]))), amountOutMin: uint256(uint128(bytes16(msg.data[68:84]))), - destinationAmountOutMin: uint256(uint128(bytes16(msg.data[84:100]))), + destinationAmountOutMin: uint256( + uint128(bytes16(msg.data[84:100])) + ), hopBridge: address(bytes20(msg.data[100:120])) // => total calldata length required: 120 }); @@ -82,29 +86,44 @@ contract HopFacetPacked is ILiFi { uint256 destinationAmountOutMin, address hopBridge ) external pure returns (bytes memory) { - require(destinationChainId <= type(uint32).max, "destinationChainId value passed too big to fit in uint32"); - require(bonderFee <= type(uint128).max, "bonderFee value passed too big to fit in uint128"); - require(amountOutMin <= type(uint128).max, "amountOutMin value passed too big to fit in uint128"); - require(destinationAmountOutMin <= type(uint128).max, "destinationAmountOutMin value passed too big to fit in uint128"); - - return bytes.concat( - HopFacetPacked.startBridgeTokensViaHopL2NativePacked.selector, - bytes8(transactionId), - bytes16(bytes(integrator)), - bytes20(receiver), - bytes4(uint32(destinationChainId)), - bytes16(uint128(bonderFee)), - bytes16(uint128(amountOutMin)), - bytes16(uint128(destinationAmountOutMin)), - bytes20(hopBridge) + require( + destinationChainId <= type(uint32).max, + "destinationChainId value passed too big to fit in uint32" + ); + require( + bonderFee <= type(uint128).max, + "bonderFee value passed too big to fit in uint128" + ); + require( + amountOutMin <= type(uint128).max, + "amountOutMin value passed too big to fit in uint128" ); + require( + destinationAmountOutMin <= type(uint128).max, + "destinationAmountOutMin value passed too big to fit in uint128" + ); + + return + bytes.concat( + HopFacetPacked.startBridgeTokensViaHopL2NativePacked.selector, + bytes8(transactionId), + bytes16(bytes(integrator)), + bytes20(receiver), + bytes4(uint32(destinationChainId)), + bytes16(uint128(bonderFee)), + bytes16(uint128(amountOutMin)), + bytes16(uint128(destinationAmountOutMin)), + bytes20(hopBridge) + ); } /// @notice Bridges ERC20 tokens via Hop Protocol from L2 /// No params, all data will be extracted from manually encoded callData - function startBridgeTokensViaHopL2ERC20Packed( - ) external { - require(msg.data.length >= 156, "callData length smaller than required"); + function startBridgeTokensViaHopL2ERC20Packed() external { + require( + msg.data.length >= 156, + "callData length smaller than required" + ); _startBridgeTokensViaHopL2ERC20({ // first 4 bytes are function signature @@ -112,11 +131,13 @@ contract HopFacetPacked is ILiFi { integrator: string(msg.data[12:28]), // bytes16 > string receiver: address(bytes20(msg.data[28:48])), destinationChainId: uint256(uint32(bytes4(msg.data[48:52]))), - sendingAssetId: address(bytes20(msg.data[52:72])), + sendingAssetId: address(bytes20(msg.data[52:72])), amount: uint256(uint128(bytes16(msg.data[72:88]))), bonderFee: uint256(uint128(bytes16(msg.data[88:104]))), amountOutMin: uint256(uint128(bytes16(msg.data[104:120]))), - destinationAmountOutMin: uint256(uint128(bytes16(msg.data[120:136]))), + destinationAmountOutMin: uint256( + uint128(bytes16(msg.data[120:136])) + ), hopBridge: address(bytes20(msg.data[136:156])) // => total calldata length required: 156 }); @@ -182,25 +203,41 @@ contract HopFacetPacked is ILiFi { uint256 destinationAmountOutMin, address hopBridge ) external pure returns (bytes memory) { - require(destinationChainId <= type(uint32).max, "destinationChainId value passed too big to fit in uint32"); - require(amount <= type(uint128).max, "amount value passed too big to fit in uint128"); - require(bonderFee <= type(uint128).max, "bonderFee value passed too big to fit in uint128"); - require(amountOutMin <= type(uint128).max, "amountOutMin value passed too big to fit in uint128"); - require(destinationAmountOutMin <= type(uint128).max, "destinationAmountOutMin value passed too big to fit in uint128"); - - return bytes.concat( - HopFacetPacked.startBridgeTokensViaHopL2ERC20Packed.selector, - bytes8(transactionId), - bytes16(bytes(integrator)), - bytes20(receiver), - bytes4(uint32(destinationChainId)), - bytes20(sendingAssetId), - bytes16(uint128(amount)), - bytes16(uint128(bonderFee)), - bytes16(uint128(amountOutMin)), - bytes16(uint128(destinationAmountOutMin)), - bytes20(hopBridge) + require( + destinationChainId <= type(uint32).max, + "destinationChainId value passed too big to fit in uint32" + ); + require( + amount <= type(uint128).max, + "amount value passed too big to fit in uint128" ); + require( + bonderFee <= type(uint128).max, + "bonderFee value passed too big to fit in uint128" + ); + require( + amountOutMin <= type(uint128).max, + "amountOutMin value passed too big to fit in uint128" + ); + require( + destinationAmountOutMin <= type(uint128).max, + "destinationAmountOutMin value passed too big to fit in uint128" + ); + + return + bytes.concat( + HopFacetPacked.startBridgeTokensViaHopL2ERC20Packed.selector, + bytes8(transactionId), + bytes16(bytes(integrator)), + bytes20(receiver), + bytes4(uint32(destinationChainId)), + bytes20(sendingAssetId), + bytes16(uint128(amount)), + bytes16(uint128(bonderFee)), + bytes16(uint128(amountOutMin)), + bytes16(uint128(destinationAmountOutMin)), + bytes20(hopBridge) + ); } /// @notice Bridges Native tokens via Hop Protocol from L1 @@ -284,18 +321,20 @@ contract HopFacetPacked is ILiFi { deadline ); - emit LiFiTransferStarted(BridgeData({ - transactionId: transactionId, - bridge: "hop", - integrator: integrator, - referrer: address(0), - sendingAssetId: address(0), - receiver: receiver, - minAmount: msg.value, - destinationChainId: destinationChainId, - hasSourceSwaps: false, - hasDestinationCall: false - })); + emit LiFiTransferStarted( + BridgeData({ + transactionId: transactionId, + bridge: "hop", + integrator: integrator, + referrer: address(0), + sendingAssetId: address(0), + receiver: receiver, + minAmount: msg.value, + destinationChainId: destinationChainId, + hasSourceSwaps: false, + hasDestinationCall: false + }) + ); } function _startBridgeTokensViaHopL2ERC20( @@ -311,7 +350,12 @@ contract HopFacetPacked is ILiFi { address hopBridge ) private { // Deposit assets - SafeERC20.safeTransferFrom(IERC20(sendingAssetId), msg.sender, address(this), amount); + SafeERC20.safeTransferFrom( + IERC20(sendingAssetId), + msg.sender, + address(this), + amount + ); // Bridge assets uint256 deadline = block.timestamp + 60 * 20; @@ -326,18 +370,20 @@ contract HopFacetPacked is ILiFi { deadline ); - emit LiFiTransferStarted(BridgeData({ - transactionId: transactionId, - bridge: "hop", - integrator: integrator, - referrer: address(0), - sendingAssetId: sendingAssetId, - receiver: receiver, - minAmount: amount, - destinationChainId: destinationChainId, - hasSourceSwaps: false, - hasDestinationCall: false - })); + emit LiFiTransferStarted( + BridgeData({ + transactionId: transactionId, + bridge: "hop", + integrator: integrator, + referrer: address(0), + sendingAssetId: sendingAssetId, + receiver: receiver, + minAmount: amount, + destinationChainId: destinationChainId, + hasSourceSwaps: false, + hasDestinationCall: false + }) + ); } function _startBridgeTokensViaHopL1Native( @@ -360,18 +406,20 @@ contract HopFacetPacked is ILiFi { 0 ); - emit LiFiTransferStarted(BridgeData({ - transactionId: transactionId, - bridge: "hop", - integrator: integrator, - referrer: address(0), - sendingAssetId: address(0), - receiver: receiver, - minAmount: msg.value, - destinationChainId: destinationChainId, - hasSourceSwaps: false, - hasDestinationCall: false - })); + emit LiFiTransferStarted( + BridgeData({ + transactionId: transactionId, + bridge: "hop", + integrator: integrator, + referrer: address(0), + sendingAssetId: address(0), + receiver: receiver, + minAmount: msg.value, + destinationChainId: destinationChainId, + hasSourceSwaps: false, + hasDestinationCall: false + }) + ); } function _startBridgeTokensViaHopL1ERC20( @@ -385,7 +433,12 @@ contract HopFacetPacked is ILiFi { address hopBridge ) private { // Deposit assets - SafeERC20.safeTransferFrom(IERC20(sendingAssetId), msg.sender, address(this), amount); + SafeERC20.safeTransferFrom( + IERC20(sendingAssetId), + msg.sender, + address(this), + amount + ); // Bridge assets uint256 deadline = block.timestamp + 60 * 20; @@ -399,18 +452,19 @@ contract HopFacetPacked is ILiFi { 0 ); - emit LiFiTransferStarted(BridgeData({ - transactionId: transactionId, - bridge: "hop", - integrator: integrator, - referrer: address(0), - sendingAssetId: sendingAssetId, - receiver: receiver, - minAmount: amount, - destinationChainId: destinationChainId, - hasSourceSwaps: false, - hasDestinationCall: false - })); + emit LiFiTransferStarted( + BridgeData({ + transactionId: transactionId, + bridge: "hop", + integrator: integrator, + referrer: address(0), + sendingAssetId: sendingAssetId, + receiver: receiver, + minAmount: amount, + destinationChainId: destinationChainId, + hasSourceSwaps: false, + hasDestinationCall: false + }) + ); } - } diff --git a/src/Facets/HyphenFacet.sol b/src/Facets/HyphenFacet.sol index 7b89ea3df..3bf515ad1 100644 --- a/src/Facets/HyphenFacet.sol +++ b/src/Facets/HyphenFacet.sol @@ -11,6 +11,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title Hyphen Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Hyphen +/// @custom:version 1.0.0 contract HyphenFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -29,7 +30,9 @@ contract HyphenFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @notice Bridges tokens via Hyphen /// @param _bridgeData the core information needed for bridging - function startBridgeTokensViaHyphen(ILiFi.BridgeData memory _bridgeData) + function startBridgeTokensViaHyphen( + ILiFi.BridgeData memory _bridgeData + ) external payable nonReentrant diff --git a/src/Facets/LIFuelFacet.sol b/src/Facets/LIFuelFacet.sol index 9a85fadee..49ee53b5a 100644 --- a/src/Facets/LIFuelFacet.sol +++ b/src/Facets/LIFuelFacet.sol @@ -4,22 +4,27 @@ pragma solidity 0.8.17; import { ILiFi } from "../Interfaces/ILiFi.sol"; import { ServiceFeeCollector } from "../Periphery/ServiceFeeCollector.sol"; import { LibAsset, IERC20 } from "../Libraries/LibAsset.sol"; -import { LibDiamond } from "../Libraries/LibDiamond.sol"; import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol"; -import { InformationMismatch, InvalidConfig, AlreadyInitialized, NotInitialized } from "../Errors/GenericErrors.sol"; import { SwapperV2, LibSwap } from "../Helpers/SwapperV2.sol"; -import { LibMappings } from "../Libraries/LibMappings.sol"; import { Validatable } from "../Helpers/Validatable.sol"; -import { LibMappings } from "../Libraries/LibMappings.sol"; /// @title LIFuel Facet /// @author Li.Finance (https://li.finance) /// @notice Provides functionality for bridging gas through LIFuel +/// @custom:version 1.0.0 contract LIFuelFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { - /// Storage /// + + bytes32 internal constant NAMESPACE = + keccak256("com.lifi.facets.periphery_registry"); string internal constant FEE_COLLECTOR_NAME = "ServiceFeeCollector"; + /// Types /// + + struct Storage { + mapping(string => address) contracts; + } + /// External Methods /// /// @notice Bridges tokens via LIFuel Bridge @@ -32,6 +37,7 @@ contract LIFuelFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { nonReentrant refundExcessNative(payable(msg.sender)) doesNotContainSourceSwaps(_bridgeData) + doesNotContainDestinationCalls(_bridgeData) validateBridgeData(_bridgeData) { LibAsset.depositAsset( @@ -53,6 +59,7 @@ contract LIFuelFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { nonReentrant refundExcessNative(payable(msg.sender)) containsSourceSwaps(_bridgeData) + doesNotContainDestinationCalls(_bridgeData) validateBridgeData(_bridgeData) { _bridgeData.minAmount = _depositAndSwap( @@ -69,21 +76,16 @@ contract LIFuelFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @dev Contains the business logic for the bridge via LIFuel Bridge /// @param _bridgeData Data used purely for tracking and analytics - function _startBridge( - ILiFi.BridgeData memory _bridgeData - ) private { - + function _startBridge(ILiFi.BridgeData memory _bridgeData) private { ServiceFeeCollector serviceFeeCollector = ServiceFeeCollector( - LibMappings.getPeripheryRegistryMappings().contracts[FEE_COLLECTOR_NAME] + getStorage().contracts[FEE_COLLECTOR_NAME] ); if (LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) { - serviceFeeCollector.collectNativeGasFees{value: _bridgeData.minAmount}( - _bridgeData.minAmount, - _bridgeData.receiver - ); + serviceFeeCollector.collectNativeGasFees{ + value: _bridgeData.minAmount + }(_bridgeData.destinationChainId, _bridgeData.receiver); } else { - LibAsset.maxApproveERC20( IERC20(_bridgeData.sendingAssetId), address(serviceFeeCollector), @@ -93,10 +95,20 @@ contract LIFuelFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { serviceFeeCollector.collectTokenGasFees( _bridgeData.sendingAssetId, _bridgeData.minAmount, + _bridgeData.destinationChainId, _bridgeData.receiver ); } emit LiFiTransferStarted(_bridgeData); } + + /// @dev fetch local storage + function getStorage() private pure returns (Storage storage s) { + bytes32 namespace = NAMESPACE; + // solhint-disable-next-line no-inline-assembly + assembly { + s.slot := namespace + } + } } diff --git a/src/Facets/MakerTeleportFacet.sol b/src/Facets/MakerTeleportFacet.sol index 1fb6dfa0d..f2a3962bb 100644 --- a/src/Facets/MakerTeleportFacet.sol +++ b/src/Facets/MakerTeleportFacet.sol @@ -2,6 +2,7 @@ pragma solidity 0.8.17; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; +import "@openzeppelin/contracts/utils/math/SafeCast.sol"; import { ILiFi } from "../Interfaces/ILiFi.sol"; import { ITeleportGateway } from "../Interfaces/ITeleportGateway.sol"; import { LibAsset } from "../Libraries/LibAsset.sol"; @@ -14,7 +15,10 @@ import { InvalidSendingToken, NoSwapDataProvided } from "../Errors/GenericErrors /// @title MakerTeleport Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Maker Teleport +/// @custom:version 1.0.0 contract MakerTeleportFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { + using SafeCast for uint256; + /// Storage /// /// @notice The address of Teleport Gateway. @@ -56,9 +60,7 @@ contract MakerTeleportFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { ILiFi.BridgeData memory _bridgeData ) external - payable nonReentrant - refundExcessNative(payable(msg.sender)) validateBridgeData(_bridgeData) doesNotContainSourceSwaps(_bridgeData) doesNotContainDestinationCalls(_bridgeData) @@ -86,18 +88,13 @@ contract MakerTeleportFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { onlyAllowDestinationChain(_bridgeData, dstChainId) onlyAllowSourceToken(_bridgeData, dai) { - if (_swapData.length == 0) { - revert NoSwapDataProvided(); - } - if (_swapData[_swapData.length - 1].receivingAssetId != dai) { - revert InvalidSendingToken(); - } _bridgeData.minAmount = _depositAndSwap( _bridgeData.transactionId, _bridgeData.minAmount, _swapData, payable(msg.sender) ); + _startBridge(_bridgeData); } @@ -115,7 +112,7 @@ contract MakerTeleportFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { teleportGateway.initiateTeleport( l1Domain, _bridgeData.receiver, - uint128(_bridgeData.minAmount) + _bridgeData.minAmount.toUint128() ); emit LiFiTransferStarted(_bridgeData); diff --git a/src/Facets/MultichainFacet.sol b/src/Facets/MultichainFacet.sol index 083b2370d..8236f2b23 100644 --- a/src/Facets/MultichainFacet.sol +++ b/src/Facets/MultichainFacet.sol @@ -17,6 +17,7 @@ interface IMultichainERC20 { /// @title Multichain Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Multichain (Prev. AnySwap) +/// @custom:version 1.0.0 contract MultichainFacet is ILiFi, SwapperV2, ReentrancyGuard, Validatable { /// Storage /// @@ -56,14 +57,18 @@ contract MultichainFacet is ILiFi, SwapperV2, ReentrancyGuard, Validatable { /// @notice Initialize local variables for the Multichain Facet /// @param anyNative The address of the anyNative (e.g. anyETH) token /// @param routers Allowed Multichain Routers - function initMultichain(address anyNative, address[] calldata routers) - external - { + function initMultichain( + address anyNative, + address[] calldata routers + ) external { LibDiamond.enforceIsContractOwner(); Storage storage s = getStorage(); - if (anyNative == address(0)) revert InvalidConfig(); + if (anyNative == address(0)) { + revert InvalidConfig(); + } + s.anyNative = anyNative; if (s.initialized) { @@ -155,7 +160,9 @@ contract MultichainFacet is ILiFi, SwapperV2, ReentrancyGuard, Validatable { validateBridgeData(_bridgeData) { Storage storage s = getStorage(); - if (!s.allowedRouters[_multichainData.router]) revert InvalidRouter(); + if (!s.allowedRouters[_multichainData.router]) { + revert InvalidRouter(); + } if (!LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) LibAsset.depositAsset( _bridgeData.sendingAssetId, @@ -172,7 +179,7 @@ contract MultichainFacet is ILiFi, SwapperV2, ReentrancyGuard, Validatable { function swapAndStartBridgeTokensViaMultichain( ILiFi.BridgeData memory _bridgeData, LibSwap.SwapData[] calldata _swapData, - MultichainData memory _multichainData + MultichainData calldata _multichainData ) external payable @@ -184,7 +191,9 @@ contract MultichainFacet is ILiFi, SwapperV2, ReentrancyGuard, Validatable { { Storage storage s = getStorage(); - if (!s.allowedRouters[_multichainData.router]) revert InvalidRouter(); + if (!s.allowedRouters[_multichainData.router]) { + revert InvalidRouter(); + } _bridgeData.minAmount = _depositAndSwap( _bridgeData.transactionId, @@ -202,7 +211,7 @@ contract MultichainFacet is ILiFi, SwapperV2, ReentrancyGuard, Validatable { /// @param _multichainData data specific to Multichain function _startBridge( ILiFi.BridgeData memory _bridgeData, - MultichainData memory _multichainData + MultichainData calldata _multichainData ) private { // check if sendingAsset is a Multichain token that needs to be called directly in order to bridge it if (_multichainData.router == _bridgeData.sendingAssetId) { @@ -228,16 +237,20 @@ contract MultichainFacet is ILiFi, SwapperV2, ReentrancyGuard, Validatable { _multichainData.router, _bridgeData.minAmount ); + + address anyToken = s.anyTokenAddresses[ + _bridgeData.sendingAssetId + ]; + // replace tokenAddress with anyTokenAddress (if mapping found) and call ERC20 asset bridge function IMultichainRouter(_multichainData.router).anySwapOutUnderlying( - s.anyTokenAddresses[_bridgeData.sendingAssetId] != - address(0) - ? s.anyTokenAddresses[_bridgeData.sendingAssetId] - : _bridgeData.sendingAssetId, - _bridgeData.receiver, - _bridgeData.minAmount, - _bridgeData.destinationChainId - ); + anyToken != address(0) + ? anyToken + : _bridgeData.sendingAssetId, + _bridgeData.receiver, + _bridgeData.minAmount, + _bridgeData.destinationChainId + ); } } diff --git a/src/Facets/NXTPFacet.sol b/src/Facets/NXTPFacet.sol index 821043575..f8b1c7376 100644 --- a/src/Facets/NXTPFacet.sol +++ b/src/Facets/NXTPFacet.sol @@ -13,6 +13,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title NXTP (Connext) Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through NXTP (Connext) +/// @custom:version 1.0.0 contract NXTPFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -58,14 +59,14 @@ contract NXTPFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { doesNotContainSourceSwaps(_bridgeData) validateBridgeData(_bridgeData) { - if (hasDestinationCall(_nxtpData) != _bridgeData.hasDestinationCall) { - revert InformationMismatch(); - } + validateDestinationCallFlag(_bridgeData, _nxtpData); validateInvariantData(_nxtpData.invariantData, _bridgeData); + LibAsset.depositAsset( _nxtpData.invariantData.sendingAssetId, _bridgeData.minAmount ); + _startBridge(_bridgeData, _nxtpData); } @@ -86,17 +87,16 @@ contract NXTPFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { containsSourceSwaps(_bridgeData) validateBridgeData(_bridgeData) { - if (hasDestinationCall(_nxtpData) != _bridgeData.hasDestinationCall) { - revert InformationMismatch(); - } - + validateDestinationCallFlag(_bridgeData, _nxtpData); validateInvariantData(_nxtpData.invariantData, _bridgeData); + _bridgeData.minAmount = _depositAndSwap( _bridgeData.transactionId, _bridgeData.minAmount, _swapData, payable(msg.sender) ); + _startBridge(_bridgeData, _nxtpData); } @@ -170,11 +170,15 @@ contract NXTPFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { } } - function hasDestinationCall(NXTPData memory _nxtpData) - private - pure - returns (bool) - { - return _nxtpData.encryptedCallData.length > 0; + function validateDestinationCallFlag( + ILiFi.BridgeData memory _bridgeData, + NXTPData calldata _nxtpData + ) private pure { + if ( + (_nxtpData.encryptedCallData.length > 0) != + _bridgeData.hasDestinationCall + ) { + revert InformationMismatch(); + } } } diff --git a/src/Facets/OmniBridgeFacet.sol b/src/Facets/OmniBridgeFacet.sol index 577ac555d..b532ed561 100644 --- a/src/Facets/OmniBridgeFacet.sol +++ b/src/Facets/OmniBridgeFacet.sol @@ -11,6 +11,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title OmniBridge Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through OmniBridge +/// @custom:version 1.0.0 contract OmniBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// diff --git a/src/Facets/OptimismBridgeFacet.sol b/src/Facets/OptimismBridgeFacet.sol index 0db8ed878..fc87932bc 100644 --- a/src/Facets/OptimismBridgeFacet.sol +++ b/src/Facets/OptimismBridgeFacet.sol @@ -14,6 +14,7 @@ import { LibUtil } from "../Libraries/LibUtil.sol"; /// @title Optimism Bridge Facet /// @author Li.Finance (https://li.finance) /// @notice Provides functionality for bridging through Optimism Bridge +/// @custom:version 1.0.0 contract OptimismBridgeFacet is ILiFi, ReentrancyGuard, diff --git a/src/Facets/OwnershipFacet.sol b/src/Facets/OwnershipFacet.sol index dcbd8f579..eb48e1c48 100644 --- a/src/Facets/OwnershipFacet.sol +++ b/src/Facets/OwnershipFacet.sol @@ -9,6 +9,7 @@ import { LibAsset } from "../Libraries/LibAsset.sol"; /// @title Ownership Facet /// @author LI.FI (https://li.fi) /// @notice Manages ownership of the LiFi Diamond contract for admin purposes +/// @custom:version 1.0.0 contract OwnershipFacet is IERC173 { /// Storage /// diff --git a/src/Facets/PeripheryRegistryFacet.sol b/src/Facets/PeripheryRegistryFacet.sol index fd72b2bde..c20643f69 100644 --- a/src/Facets/PeripheryRegistryFacet.sol +++ b/src/Facets/PeripheryRegistryFacet.sol @@ -2,12 +2,22 @@ pragma solidity 0.8.17; import { LibDiamond } from "../Libraries/LibDiamond.sol"; -import { LibMappings } from "../Libraries/LibMappings.sol"; /// @title Periphery Registry Facet /// @author LI.FI (https://li.fi) /// @notice A simple registry to track LIFI periphery contracts +/// @custom:version 1.0.0 contract PeripheryRegistryFacet { + /// Storage /// + + bytes32 internal constant NAMESPACE = + keccak256("com.lifi.facets.periphery_registry"); + + /// Types /// + + struct Storage { + mapping(string => address) contracts; + } /// Events /// @@ -23,20 +33,25 @@ contract PeripheryRegistryFacet { address _contractAddress ) external { LibDiamond.enforceIsContractOwner(); - LibMappings.PeripheryRegistryMappings storage s = LibMappings - .getPeripheryRegistryMappings(); + Storage storage s = getStorage(); s.contracts[_name] = _contractAddress; emit PeripheryContractRegistered(_name, _contractAddress); } /// @notice Returns the registered contract address by its name /// @param _name the registered name of the contract - function getPeripheryContract(string calldata _name) - external - view - returns (address) - { - return LibMappings - .getPeripheryRegistryMappings().contracts[_name]; + function getPeripheryContract( + string calldata _name + ) external view returns (address) { + return getStorage().contracts[_name]; + } + + /// @dev fetch local storage + function getStorage() private pure returns (Storage storage s) { + bytes32 namespace = NAMESPACE; + // solhint-disable-next-line no-inline-assembly + assembly { + s.slot := namespace + } } } diff --git a/src/Facets/PolygonBridgeFacet.sol b/src/Facets/PolygonBridgeFacet.sol index 1de75b826..74db34065 100644 --- a/src/Facets/PolygonBridgeFacet.sol +++ b/src/Facets/PolygonBridgeFacet.sol @@ -11,6 +11,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title Polygon Bridge Facet /// @author Li.Finance (https://li.finance) /// @notice Provides functionality for bridging through Polygon Bridge +/// @custom:version 1.0.0 contract PolygonBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// diff --git a/src/Facets/RoninBridgeFacet.sol b/src/Facets/RoninBridgeFacet.sol index 73133d929..0f509e9ab 100644 --- a/src/Facets/RoninBridgeFacet.sol +++ b/src/Facets/RoninBridgeFacet.sol @@ -11,6 +11,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title Ronin Bridge Facet /// @author Li.Finance (https://li.finance) /// @notice Provides functionality for bridging through Ronin Bridge +/// @custom:version 1.0.0 contract RoninBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// diff --git a/src/Facets/SquidFacet.sol b/src/Facets/SquidFacet.sol index 8df6cfd7b..488b5a4ec 100644 --- a/src/Facets/SquidFacet.sol +++ b/src/Facets/SquidFacet.sol @@ -9,12 +9,14 @@ import { LibSwap } from "../Libraries/LibSwap.sol"; import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol"; import { SwapperV2 } from "../Helpers/SwapperV2.sol"; import { Validatable } from "../Helpers/Validatable.sol"; -import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; +import { LibBytes } from "../Libraries/LibBytes.sol"; import { InformationMismatch } from "../Errors/GenericErrors.sol"; +import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; /// @title Squid Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Squid Router +/// @custom:version 1.0.0 contract SquidFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Types /// @@ -42,10 +44,15 @@ contract SquidFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { bool forecallEnabled; } + /// Errors /// + error InvalidRouteType(); + /// State /// - ISquidRouter public immutable squidRouter; + + ISquidRouter private immutable squidRouter; /// Constructor /// + constructor(ISquidRouter _squidRouter) { squidRouter = _squidRouter; } @@ -57,26 +64,26 @@ contract SquidFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @param _squidData Data specific to Squid Router function startBridgeTokensViaSquid( ILiFi.BridgeData memory _bridgeData, - SquidData memory _squidData + SquidData calldata _squidData ) external payable nonReentrant refundExcessNative(payable(msg.sender)) + doesNotContainSourceSwaps(_bridgeData) validateBridgeData(_bridgeData) { if ( - (_squidData.sourceCalls.length > 0) != _bridgeData.hasSourceSwaps + !LibAsset.isNativeAsset(address(_bridgeData.sendingAssetId)) && + keccak256(abi.encodePacked(_squidData.bridgedTokenSymbol)) != + keccak256( + abi.encodePacked(ERC20(_bridgeData.sendingAssetId).symbol()) + ) ) { revert InformationMismatch(); } - if ( - (_squidData.destinationCalls.length > 0) != - _bridgeData.hasDestinationCall - ) { - revert InformationMismatch(); - } + validateDestinationCallFlag(_bridgeData, _squidData); LibAsset.depositAsset( _bridgeData.sendingAssetId, @@ -93,7 +100,7 @@ contract SquidFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { function swapAndStartBridgeTokensViaSquid( ILiFi.BridgeData memory _bridgeData, LibSwap.SwapData[] calldata _swapData, - SquidData memory _squidData + SquidData calldata _squidData ) external payable @@ -103,18 +110,24 @@ contract SquidFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { validateBridgeData(_bridgeData) { if ( - (_squidData.destinationCalls.length > 0) != - _bridgeData.hasDestinationCall + !LibAsset.isNativeAsset(address(_bridgeData.sendingAssetId)) && + keccak256(abi.encodePacked(_squidData.bridgedTokenSymbol)) != + keccak256( + abi.encodePacked(ERC20(_bridgeData.sendingAssetId).symbol()) + ) ) { revert InformationMismatch(); } + validateDestinationCallFlag(_bridgeData, _squidData); + _bridgeData.minAmount = _depositAndSwap( _bridgeData.transactionId, _bridgeData.minAmount, _swapData, payable(msg.sender) ); + _startBridge(_bridgeData, _squidData); } @@ -125,16 +138,15 @@ contract SquidFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @param _squidData Data specific to Squid Router function _startBridge( ILiFi.BridgeData memory _bridgeData, - SquidData memory _squidData + SquidData calldata _squidData ) internal { - IERC20 sendingAssetId = IERC20(_bridgeData.sendingAssetId); - uint256 msgValue = _squidData.fee; - if (LibAsset.isNativeAsset(address(sendingAssetId))) { + + if (LibAsset.isNativeAsset(_bridgeData.sendingAssetId)) { msgValue += _bridgeData.minAmount; } else { LibAsset.maxApproveERC20( - sendingAssetId, + IERC20(_bridgeData.sendingAssetId), address(squidRouter), _bridgeData.minAmount ); @@ -154,7 +166,7 @@ contract SquidFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { _bridgeData.sendingAssetId, _bridgeData.minAmount, _squidData.destinationChain, - Strings.toHexString(uint160(_bridgeData.receiver), 20), + LibBytes.toHexString(uint160(_bridgeData.receiver), 20), _squidData.bridgedTokenSymbol, _squidData.sourceCalls ); @@ -169,8 +181,22 @@ contract SquidFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { _bridgeData.receiver, _squidData.forecallEnabled ); + } else { + revert InvalidRouteType(); } emit LiFiTransferStarted(_bridgeData); } + + function validateDestinationCallFlag( + ILiFi.BridgeData memory _bridgeData, + SquidData calldata _squidData + ) private pure { + if ( + (_squidData.destinationCalls.length > 0) != + _bridgeData.hasDestinationCall + ) { + revert InformationMismatch(); + } + } } diff --git a/src/Facets/StargateFacet.sol b/src/Facets/StargateFacet.sol index e7aabc9b6..971626f75 100644 --- a/src/Facets/StargateFacet.sol +++ b/src/Facets/StargateFacet.sol @@ -8,19 +8,33 @@ import { LibDiamond } from "../Libraries/LibDiamond.sol"; import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol"; import { InformationMismatch, InvalidConfig, AlreadyInitialized, NotInitialized } from "../Errors/GenericErrors.sol"; import { SwapperV2, LibSwap } from "../Helpers/SwapperV2.sol"; -import { LibMappings } from "../Libraries/LibMappings.sol"; import { Validatable } from "../Helpers/Validatable.sol"; /// @title Stargate Facet /// @author Li.Finance (https://li.finance) /// @notice Provides functionality for bridging through Stargate +/// @custom:version 1.0.0 contract StargateFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// + bytes32 internal constant NAMESPACE = + keccak256("com.lifi.facets.stargate"); + /// @notice The contract address of the stargate router on the source chain. IStargateRouter private immutable router; /// Types /// + + struct Storage { + mapping(uint256 => uint16) layerZeroChainId; + bool initialized; + } + + struct PoolIdConfig { + address token; + uint16 poolId; + } + struct ChainIdConfig { uint256 chainId; uint16 layerZeroChainId; @@ -52,9 +66,7 @@ contract StargateFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Events /// - event StargateInitialized( - ChainIdConfig[] chainIdConfigs - ); + event StargateInitialized(ChainIdConfig[] chainIdConfigs); event LayerZeroChainIdSet( uint256 indexed chainId, @@ -73,13 +85,10 @@ contract StargateFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @notice Initialize local variables for the Stargate Facet /// @param chainIdConfigs Chain Id configuration data - function initStargate( - ChainIdConfig[] calldata chainIdConfigs - ) external { + function initStargate(ChainIdConfig[] calldata chainIdConfigs) external { LibDiamond.enforceIsContractOwner(); - LibMappings.StargateMappings storage sm = LibMappings - .getStargateMappings(); + Storage storage sm = getStorage(); if (sm.initialized) { revert AlreadyInitialized(); @@ -162,7 +171,7 @@ contract StargateFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { IStargateRouter.lzTxObj( _stargateData.dstGasForCall, 0, - toBytes(msg.sender) + toBytes(address(0)) ) ); } @@ -192,7 +201,7 @@ contract StargateFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { IStargateRouter.lzTxObj( _stargateData.dstGasForCall, 0, - toBytes(_bridgeData.receiver) + toBytes(address(0)) ), _stargateData.callTo, _stargateData.callData @@ -219,12 +228,12 @@ contract StargateFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @param _chainId uint16 of the chain ID /// @param _layerZeroChainId uint16 of the Layer 0 chain ID /// @dev This is used to map a chain ID to its Layer 0 chain ID - function setLayerZeroChainId(uint256 _chainId, uint16 _layerZeroChainId) - external - { + function setLayerZeroChainId( + uint256 _chainId, + uint16 _layerZeroChainId + ) external { LibDiamond.enforceIsContractOwner(); - LibMappings.StargateMappings storage sm = LibMappings - .getStargateMappings(); + Storage storage sm = getStorage(); if (!sm.initialized) { revert NotInitialized(); @@ -237,35 +246,25 @@ contract StargateFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @notice Gets the Layer 0 chain ID for a given chain ID /// @param _chainId uint256 of the chain ID /// @return uint16 of the Layer 0 chain ID - function getLayerZeroChainId(uint256 _chainId) - private - view - returns (uint16) - { - LibMappings.StargateMappings storage sm = LibMappings - .getStargateMappings(); + function getLayerZeroChainId( + uint256 _chainId + ) private view returns (uint16) { + Storage storage sm = getStorage(); uint16 chainId = sm.layerZeroChainId[_chainId]; if (chainId == 0) revert UnknownLayerZeroChain(); return chainId; } function toBytes(address _address) private pure returns (bytes memory) { - bytes memory tempBytes; + return abi.encodePacked(_address); + } + /// @dev fetch local storage + function getStorage() private pure returns (Storage storage s) { + bytes32 namespace = NAMESPACE; + // solhint-disable-next-line no-inline-assembly assembly { - let m := mload(0x40) - _address := and( - _address, - 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - ) - mstore( - add(m, 20), - xor(0x140000000000000000000000000000000000000000, _address) - ) - mstore(0x40, add(m, 52)) - tempBytes := m + s.slot := namespace } - - return tempBytes; } } diff --git a/src/Facets/SynapseBridgeFacet.sol b/src/Facets/SynapseBridgeFacet.sol index 564f7b955..179f9c10f 100644 --- a/src/Facets/SynapseBridgeFacet.sol +++ b/src/Facets/SynapseBridgeFacet.sol @@ -11,6 +11,7 @@ import { Validatable } from "../Helpers/Validatable.sol"; /// @title SynapseBridge Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through SynapseBridge +/// @custom:version 1.0.0 contract SynapseBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// @@ -18,7 +19,7 @@ contract SynapseBridgeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; /// @notice The contract address of the SynapseRouter on the source chain. - ISynapseRouter public immutable synapseRouter; + ISynapseRouter private immutable synapseRouter; /// Types /// diff --git a/src/Facets/ThorSwapFacet.sol b/src/Facets/ThorSwapFacet.sol index b9aa2c97d..c6ede0f61 100644 --- a/src/Facets/ThorSwapFacet.sol +++ b/src/Facets/ThorSwapFacet.sol @@ -1,22 +1,20 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.7; +pragma solidity 0.8.17; import { ILiFi } from "../Interfaces/ILiFi.sol"; import { IThorSwap } from "../Interfaces/IThorSwap.sol"; import { LibAsset, IERC20 } from "../Libraries/LibAsset.sol"; import { SwapperV2 } from "../Helpers/SwapperV2.sol"; -import { LibDiamond } from "../Libraries/LibDiamond.sol"; import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol"; -import { AlreadyInitialized, NotInitialized } from "../Errors/GenericErrors.sol"; import { Validatable } from "../Helpers/Validatable.sol"; import { LibSwap } from "../Libraries/LibSwap.sol"; -import { console } from "../../test/solidity/utils/Console.sol"; /// @title ThorSwap Facet /// @author Li.Finance (https://li.finance) /// @notice Provides functionality for bridging through ThorSwap +/// @custom:version 1.0.0 contract ThorSwapFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { - address public immutable thorchainRouter; + address private immutable thorchainRouter; /// @notice The struct for the ThorSwap data. /// @param vault The Thorchain vault address @@ -28,6 +26,9 @@ contract ThorSwapFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { uint256 expiration; } + /// Errors /// + error InvalidExpiration(); + /// @notice Initializes the ThorSwap contract constructor(address _thorchainRouter) { thorchainRouter = _thorchainRouter; @@ -48,6 +49,10 @@ contract ThorSwapFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { doesNotContainSourceSwaps(_bridgeData) doesNotContainDestinationCalls(_bridgeData) { + // Check that expiration is at least 60 minutes from now + if (_thorSwapData.expiration < block.timestamp + 60 minutes) { + revert InvalidExpiration(); + } LibAsset.depositAsset( _bridgeData.sendingAssetId, _bridgeData.minAmount @@ -72,6 +77,10 @@ contract ThorSwapFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { doesNotContainDestinationCalls(_bridgeData) validateBridgeData(_bridgeData) { + // Check that expiration is at least 60 minutes from now + if (_thorSwapData.expiration < block.timestamp + 60 minutes) { + revert InvalidExpiration(); + } _bridgeData.minAmount = _depositAndSwap( _bridgeData.transactionId, _bridgeData.minAmount, diff --git a/src/Facets/WithdrawFacet.sol b/src/Facets/WithdrawFacet.sol index ba71d6140..785fbdee3 100644 --- a/src/Facets/WithdrawFacet.sol +++ b/src/Facets/WithdrawFacet.sol @@ -10,6 +10,7 @@ import { NotAContract } from "../Errors/GenericErrors.sol"; /// @title Withdraw Facet /// @author LI.FI (https://li.fi) /// @notice Allows admin to withdraw funds that are kept in the contract by accident +/// @custom:version 1.0.0 contract WithdrawFacet { /// Errors /// @@ -46,6 +47,8 @@ contract WithdrawFacet { bool success; bool isContract = LibAsset.isContract(_callTo); if (!isContract) revert NotAContract(); + + // solhint-disable-next-line avoid-low-level-calls (success, ) = _callTo.call(_callData); if (success) { diff --git a/src/Facets/WormholeFacet.sol b/src/Facets/WormholeFacet.sol index 781b06715..1be269798 100644 --- a/src/Facets/WormholeFacet.sol +++ b/src/Facets/WormholeFacet.sol @@ -11,14 +11,16 @@ import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol"; import { UnsupportedChainId, AlreadyInitialized, NotInitialized } from "../Errors/GenericErrors.sol"; import { SwapperV2 } from "../Helpers/SwapperV2.sol"; import { Validatable } from "../Helpers/Validatable.sol"; -import { LibMappings } from "../Libraries/LibMappings.sol"; /// @title Wormhole Facet /// @author LI.FI (https://li.fi) /// @notice Provides functionality for bridging through Wormhole +/// @custom:version 1.0.0 contract WormholeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Storage /// + bytes32 internal constant NAMESPACE = + keccak256("com.lifi.facets.wormhole"); address internal constant NON_EVM_ADDRESS = 0x11f111f111f111F111f111f111F111f111f111F1; @@ -27,6 +29,11 @@ contract WormholeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// Types /// + struct Storage { + mapping(uint256 => uint16) wormholeChainId; + bool initialized; + } + struct Config { uint256 chainId; uint16 wormholeChainId; @@ -70,8 +77,7 @@ contract WormholeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { function initWormhole(Config[] calldata configs) external { LibDiamond.enforceIsContractOwner(); - LibMappings.WormholeMappings storage sm = LibMappings - .getWormholeMappings(); + Storage storage sm = getStorage(); if (sm.initialized) { revert AlreadyInitialized(); @@ -141,12 +147,12 @@ contract WormholeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @notice Creates a mapping between a lifi chain id and a wormhole chain id /// @param _lifiChainId lifi chain id /// @param _wormholeChainId wormhole chain id - function setWormholeChainId(uint256 _lifiChainId, uint16 _wormholeChainId) - external - { + function setWormholeChainId( + uint256 _lifiChainId, + uint16 _wormholeChainId + ) external { LibDiamond.enforceIsContractOwner(); - LibMappings.WormholeMappings storage sm = LibMappings - .getWormholeMappings(); + Storage storage sm = getStorage(); sm.wormholeChainId[_lifiChainId] = _wormholeChainId; emit WormholeChainIdMapped(_lifiChainId, _wormholeChainId); } @@ -156,8 +162,7 @@ contract WormholeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { function setWormholeChainIds(Config[] calldata configs) external { LibDiamond.enforceIsContractOwner(); - LibMappings.WormholeMappings storage sm = LibMappings - .getWormholeMappings(); + Storage storage sm = getStorage(); if (!sm.initialized) { revert NotInitialized(); @@ -231,15 +236,21 @@ contract WormholeFacet is ILiFi, ReentrancyGuard, SwapperV2, Validatable { /// @notice Gets the wormhole chain id for a given lifi chain id /// @param _lifiChainId uint256 of the lifi chain ID /// @return uint16 of the wormhole chain id - function getWormholeChainId(uint256 _lifiChainId) - private - view - returns (uint16) - { - LibMappings.WormholeMappings storage sm = LibMappings - .getWormholeMappings(); + function getWormholeChainId( + uint256 _lifiChainId + ) private view returns (uint16) { + Storage storage sm = getStorage(); uint16 wormholeChainId = sm.wormholeChainId[_lifiChainId]; if (wormholeChainId == 0) revert UnsupportedChainId(_lifiChainId); return wormholeChainId; } + + /// @dev fetch local storage + function getStorage() private pure returns (Storage storage s) { + bytes32 namespace = NAMESPACE; + // solhint-disable-next-line no-inline-assembly + assembly { + s.slot := namespace + } + } } diff --git a/src/Helpers/ExcessivelySafeCall.sol b/src/Helpers/ExcessivelySafeCall.sol index da59a4e29..7532a319f 100644 --- a/src/Helpers/ExcessivelySafeCall.sol +++ b/src/Helpers/ExcessivelySafeCall.sol @@ -4,8 +4,9 @@ pragma solidity 0.8.17; import { InvalidCallData } from "../Errors/GenericErrors.sol"; +// solhint-disable no-inline-assembly library ExcessivelySafeCall { - uint256 constant LOW_28_MASK = + uint256 private constant LOW_28_MASK = 0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff; /// @notice Use when you _really_ really _really_ don't trust the called @@ -122,10 +123,10 @@ library ExcessivelySafeCall { * @param _newSelector The new 4-byte selector * @param _buf The encoded contract args */ - function swapSelector(bytes4 _newSelector, bytes memory _buf) - internal - pure - { + function swapSelector( + bytes4 _newSelector, + bytes memory _buf + ) internal pure { if (_buf.length < 4) { revert InvalidCallData(); } diff --git a/src/Helpers/SwapperV2.sol b/src/Helpers/SwapperV2.sol index 1bbc71a6a..85920d7e0 100644 --- a/src/Helpers/SwapperV2.sol +++ b/src/Helpers/SwapperV2.sol @@ -115,14 +115,12 @@ contract SwapperV2 is ILiFi { uint256 initialBalance = address(this).balance - msg.value; _; uint256 finalBalance = address(this).balance; - uint256 excess = finalBalance > initialBalance - ? finalBalance - initialBalance - : 0; - if (excess > 0) { + + if (finalBalance > initialBalance) { LibAsset.transferAsset( LibAsset.NATIVE_ASSETID, _refundReceiver, - excess + finalBalance - initialBalance ); } } @@ -213,6 +211,10 @@ contract SwapperV2 is ILiFi { uint256 newBalance = LibAsset.getOwnBalance(finalTokenId) - initialBalance; + if (LibAsset.isNativeAsset(finalTokenId)) { + newBalance -= _nativeReserve; + } + if (newBalance < _minAmount) { revert CumulativeSlippageTooHigh(_minAmount, newBalance); } @@ -294,11 +296,9 @@ contract SwapperV2 is ILiFi { /// @dev Fetches balances of tokens to be swapped before swapping. /// @param _swaps Array of data used to execute swaps /// @return uint256[] Array of token balances. - function _fetchBalances(LibSwap.SwapData[] calldata _swaps) - private - view - returns (uint256[] memory) - { + function _fetchBalances( + LibSwap.SwapData[] calldata _swaps + ) private view returns (uint256[] memory) { uint256 numSwaps = _swaps.length; uint256[] memory balances = new uint256[](numSwaps); address asset; diff --git a/src/Interfaces/IDeBridgeGate.sol b/src/Interfaces/IDeBridgeGate.sol index f1d970ceb..8829dbaca 100644 --- a/src/Interfaces/IDeBridgeGate.sol +++ b/src/Interfaces/IDeBridgeGate.sol @@ -16,10 +16,9 @@ interface IDeBridgeGate { function globalFixedNativeFee() external view returns (uint256); /// @dev Whether the chain for the asset is supported to send - function getChainToConfig(uint256) - external - view - returns (ChainSupportInfo memory); + function getChainToConfig( + uint256 + ) external view returns (ChainSupportInfo memory); /// @dev This method is used for the transfer of assets. /// It locks an asset in the smart contract in the native chain diff --git a/src/Interfaces/IDiamondLoupe.sol b/src/Interfaces/IDiamondLoupe.sol index 5d7385640..ee6ee5589 100644 --- a/src/Interfaces/IDiamondLoupe.sol +++ b/src/Interfaces/IDiamondLoupe.sol @@ -19,10 +19,9 @@ interface IDiamondLoupe { /// @notice Gets all the function selectors supported by a specific facet. /// @param _facet The facet address. /// @return facetFunctionSelectors_ - function facetFunctionSelectors(address _facet) - external - view - returns (bytes4[] memory facetFunctionSelectors_); + function facetFunctionSelectors( + address _facet + ) external view returns (bytes4[] memory facetFunctionSelectors_); /// @notice Get all the facet addresses used by a diamond. /// @return facetAddresses_ @@ -35,8 +34,7 @@ interface IDiamondLoupe { /// @dev If facet is not found return address(0). /// @param _functionSelector The function selector. /// @return facetAddress_ The facet address. - function facetAddress(bytes4 _functionSelector) - external - view - returns (address facetAddress_); + function facetAddress( + bytes4 _functionSelector + ) external view returns (address facetAddress_); } diff --git a/src/Interfaces/IERC165.sol b/src/Interfaces/IERC165.sol index 27df40f8e..15cad26b6 100644 --- a/src/Interfaces/IERC165.sol +++ b/src/Interfaces/IERC165.sol @@ -8,8 +8,7 @@ interface IERC165 { /// uses less than 30,000 gas. /// @return `true` if the contract implements `interfaceID` and /// `interfaceID` is not 0xffffffff, `false` otherwise - function supportsInterface(bytes4 interfaceId) - external - view - returns (bool); + function supportsInterface( + bytes4 interfaceId + ) external view returns (bool); } diff --git a/src/Interfaces/IGatewayRouter.sol b/src/Interfaces/IGatewayRouter.sol index de3d55065..95dc7a665 100644 --- a/src/Interfaces/IGatewayRouter.sol +++ b/src/Interfaces/IGatewayRouter.sol @@ -42,10 +42,9 @@ interface IGatewayRouter { /// @notice Returns receiving token address on L2 /// @param _token Sending token address on L1 /// @return Receiving token address on L2 - function calculateL2TokenAddress(address _token) - external - view - returns (address); + function calculateL2TokenAddress( + address _token + ) external view returns (address); /// @notice Returns exact gateway router address for token /// @param _token Sending token address on L1 diff --git a/src/Interfaces/IRootChainManager.sol b/src/Interfaces/IRootChainManager.sol index 37d5b16c1..49ac21539 100644 --- a/src/Interfaces/IRootChainManager.sol +++ b/src/Interfaces/IRootChainManager.sol @@ -24,8 +24,7 @@ interface IRootChainManager { /// @notice Returns child token address for root token /// @param rootToken Root token address /// @return childToken Child token address - function rootToChildToken(address rootToken) - external - view - returns (address childToken); + function rootToChildToken( + address rootToken + ) external view returns (address childToken); } diff --git a/src/Interfaces/IStargateRouter.sol b/src/Interfaces/IStargateRouter.sol index 4f1ca234c..46c92a211 100644 --- a/src/Interfaces/IStargateRouter.sol +++ b/src/Interfaces/IStargateRouter.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.8.17; +// solhint-disable contract-name-camelcase interface IStargateRouter { struct lzTxObj { uint256 dstGasForCall; diff --git a/src/Interfaces/ITransactionManager.sol b/src/Interfaces/ITransactionManager.sol index 9e5f1b8c7..b585a75fa 100644 --- a/src/Interfaces/ITransactionManager.sol +++ b/src/Interfaces/ITransactionManager.sol @@ -78,8 +78,7 @@ interface ITransactionManager { // called in the following order (in happy case) // 1. prepare by user on sending chain - function prepare(PrepareArgs calldata args) - external - payable - returns (TransactionData memory); + function prepare( + PrepareArgs calldata args + ) external payable returns (TransactionData memory); } diff --git a/src/Libraries/LibAllowList.sol b/src/Libraries/LibAllowList.sol index 1f2c13c92..7e2794e5a 100644 --- a/src/Libraries/LibAllowList.sol +++ b/src/Libraries/LibAllowList.sol @@ -32,11 +32,9 @@ library LibAllowList { /// @dev Checks whether a contract address has been added to the allow list /// @param _contract the contract address to check - function contractIsAllowed(address _contract) - internal - view - returns (bool) - { + function contractIsAllowed( + address _contract + ) internal view returns (bool) { return _getStorage().allowlist[_contract]; } diff --git a/src/Libraries/LibAsset.sol b/src/Libraries/LibAsset.sol index 3fa77fa6d..910d13aca 100644 --- a/src/Libraries/LibAsset.sol +++ b/src/Libraries/LibAsset.sol @@ -24,7 +24,7 @@ library LibAsset { /// @return Balance held by contracts using this library function getOwnBalance(address assetId) internal view returns (uint256) { return - assetId == NATIVE_ASSETID + isNativeAsset(assetId) ? address(this).balance : IERC20(assetId).balanceOf(address(this)); } @@ -33,9 +33,10 @@ library LibAsset { /// recipient /// @param recipient Address to send ether to /// @param amount Amount to send to given recipient - function transferNativeAsset(address payable recipient, uint256 amount) - private - { + function transferNativeAsset( + address payable recipient, + uint256 amount + ) private { if (recipient == NULL_ADDRESS) revert NoTransferToNullAddress(); if (amount > address(this).balance) revert InsufficientBalance(amount, address(this).balance); @@ -54,16 +55,17 @@ library LibAsset { address spender, uint256 amount ) internal { - if (address(assetId) == NATIVE_ASSETID) return; - if (spender == NULL_ADDRESS) revert NullAddrIsNotAValidSpender(); - uint256 allowance = assetId.allowance(address(this), spender); - - if (allowance < amount) - SafeERC20.safeIncreaseAllowance( - IERC20(assetId), - spender, - MAX_UINT - allowance - ); + if (isNativeAsset(address(assetId))) { + return; + } + if (spender == NULL_ADDRESS) { + revert NullAddrIsNotAValidSpender(); + } + + if (assetId.allowance(address(this), spender) < amount) { + SafeERC20.safeApprove(IERC20(assetId), spender, 0); + SafeERC20.safeApprove(IERC20(assetId), spender, MAX_UINT); + } } /// @notice Transfers tokens from the inheriting contract to a given @@ -76,10 +78,17 @@ library LibAsset { address recipient, uint256 amount ) private { - if (isNativeAsset(assetId)) revert NullAddrIsNotAnERC20Token(); + if (isNativeAsset(assetId)) { + revert NullAddrIsNotAnERC20Token(); + } + if (recipient == NULL_ADDRESS) { + revert NoTransferToNullAddress(); + } + uint256 assetBalance = IERC20(assetId).balanceOf(address(this)); - if (amount > assetBalance) + if (amount > assetBalance) { revert InsufficientBalance(amount, assetBalance); + } SafeERC20.safeTransfer(IERC20(assetId), recipient, amount); } @@ -94,21 +103,26 @@ library LibAsset { address to, uint256 amount ) internal { - if (assetId == NATIVE_ASSETID) revert NullAddrIsNotAnERC20Token(); - if (to == NULL_ADDRESS) revert NoTransferToNullAddress(); + if (isNativeAsset(assetId)) { + revert NullAddrIsNotAnERC20Token(); + } + if (to == NULL_ADDRESS) { + revert NoTransferToNullAddress(); + } IERC20 asset = IERC20(assetId); uint256 prevBalance = asset.balanceOf(to); SafeERC20.safeTransferFrom(asset, from, to, amount); - if (asset.balanceOf(to) - prevBalance != amount) + if (asset.balanceOf(to) - prevBalance != amount) { revert InvalidAmount(); + } } function depositAsset(address assetId, uint256 amount) internal { + if (amount == 0) revert InvalidAmount(); if (isNativeAsset(assetId)) { if (msg.value < amount) revert InvalidAmount(); } else { - if (amount == 0) revert InvalidAmount(); uint256 balance = IERC20(assetId).balanceOf(msg.sender); if (balance < amount) revert InsufficientBalance(amount, balance); transferFromERC20(assetId, msg.sender, address(this), amount); @@ -117,7 +131,7 @@ library LibAsset { function depositAssets(LibSwap.SwapData[] calldata swaps) internal { for (uint256 i = 0; i < swaps.length; ) { - LibSwap.SwapData memory swap = swaps[i]; + LibSwap.SwapData calldata swap = swaps[i]; if (swap.requiresDeposit) { depositAsset(swap.sendingAssetId, swap.fromAmount); } @@ -146,7 +160,7 @@ library LibAsset { address payable recipient, uint256 amount ) internal { - (assetId == NATIVE_ASSETID) + isNativeAsset(assetId) ? transferNativeAsset(recipient, amount) : transferERC20(assetId, recipient, amount); } diff --git a/src/Libraries/LibBytes.sol b/src/Libraries/LibBytes.sol index a2519d9f4..d79b34812 100644 --- a/src/Libraries/LibBytes.sol +++ b/src/Libraries/LibBytes.sol @@ -8,228 +8,10 @@ library LibBytes { error SliceOverflow(); error SliceOutOfBounds(); error AddressOutOfBounds(); - error UintOutOfBounds(); - // ------------------------- - - function concat(bytes memory _preBytes, bytes memory _postBytes) - internal - pure - returns (bytes memory) - { - bytes memory tempBytes; - - assembly { - // Get a location of some free memory and store it in tempBytes as - // Solidity does for memory variables. - tempBytes := mload(0x40) - - // Store the length of the first bytes array at the beginning of - // the memory for tempBytes. - let length := mload(_preBytes) - mstore(tempBytes, length) - - // Maintain a memory counter for the current write location in the - // temp bytes array by adding the 32 bytes for the array length to - // the starting location. - let mc := add(tempBytes, 0x20) - // Stop copying when the memory counter reaches the length of the - // first bytes array. - let end := add(mc, length) - - for { - // Initialize a copy counter to the start of the _preBytes data, - // 32 bytes into its memory. - let cc := add(_preBytes, 0x20) - } lt(mc, end) { - // Increase both counters by 32 bytes each iteration. - mc := add(mc, 0x20) - cc := add(cc, 0x20) - } { - // Write the _preBytes data into the tempBytes memory 32 bytes - // at a time. - mstore(mc, mload(cc)) - } - - // Add the length of _postBytes to the current length of tempBytes - // and store it as the new length in the first 32 bytes of the - // tempBytes memory. - length := mload(_postBytes) - mstore(tempBytes, add(length, mload(tempBytes))) - - // Move the memory counter back from a multiple of 0x20 to the - // actual end of the _preBytes data. - mc := end - // Stop copying when the memory counter reaches the new combined - // length of the arrays. - end := add(mc, length) - - for { - let cc := add(_postBytes, 0x20) - } lt(mc, end) { - mc := add(mc, 0x20) - cc := add(cc, 0x20) - } { - mstore(mc, mload(cc)) - } - - // Update the free-memory pointer by padding our last write location - // to 32 bytes: add 31 bytes to the end of tempBytes to move to the - // next 32 byte block, then round down to the nearest multiple of - // 32. If the sum of the length of the two arrays is zero then add - // one before rounding down to leave a blank 32 bytes (the length block with 0). - mstore( - 0x40, - and( - add(add(end, iszero(add(length, mload(_preBytes)))), 31), - not(31) // Round down to the nearest 32 bytes. - ) - ) - } - - return tempBytes; - } - - function concatStorage(bytes storage _preBytes, bytes memory _postBytes) - internal - { - assembly { - // Read the first 32 bytes of _preBytes storage, which is the length - // of the array. (We don't need to use the offset into the slot - // because arrays use the entire slot.) - let fslot := sload(_preBytes.slot) - // Arrays of 31 bytes or less have an even value in their slot, - // while longer arrays have an odd value. The actual length is - // the slot divided by two for odd values, and the lowest order - // byte divided by two for even values. - // If the slot is even, bitwise and the slot with 255 and divide by - // two to get the length. If the slot is odd, bitwise and the slot - // with -1 and divide by two. - let slength := div( - and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), - 2 - ) - let mlength := mload(_postBytes) - let newlength := add(slength, mlength) - // slength can contain both the length and contents of the array - // if length < 32 bytes so let's prepare for that - // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage - switch add(lt(slength, 32), lt(newlength, 32)) - case 2 { - // Since the new array still fits in the slot, we just need to - // update the contents of the slot. - // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length - sstore( - _preBytes.slot, - // all the modifications to the slot are inside this - // next block - add( - // we can just add to the slot contents because the - // bytes we want to change are the LSBs - fslot, - add( - mul( - div( - // load the bytes from memory - mload(add(_postBytes, 0x20)), - // zero all bytes to the right - exp(0x100, sub(32, mlength)) - ), - // and now shift left the number of bytes to - // leave space for the length in the slot - exp(0x100, sub(32, newlength)) - ), - // increase length by the double of the memory - // bytes length - mul(mlength, 2) - ) - ) - ) - } - case 1 { - // The stored value fits in the slot, but the combined value - // will exceed it. - // get the keccak hash to get the contents of the array - mstore(0x0, _preBytes.slot) - let sc := add(keccak256(0x0, 0x20), div(slength, 32)) - - // save new length - sstore(_preBytes.slot, add(mul(newlength, 2), 1)) - - // The contents of the _postBytes array start 32 bytes into - // the structure. Our first read should obtain the `submod` - // bytes that can fit into the unused space in the last word - // of the stored array. To get this, we read 32 bytes starting - // from `submod`, so the data we read overlaps with the array - // contents by `submod` bytes. Masking the lowest-order - // `submod` bytes allows us to add that value directly to the - // stored value. + bytes16 private constant _SYMBOLS = "0123456789abcdef"; - let submod := sub(32, slength) - let mc := add(_postBytes, submod) - let end := add(_postBytes, mlength) - let mask := sub(exp(0x100, submod), 1) - - sstore( - sc, - add( - and( - fslot, - 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00 - ), - and(mload(mc), mask) - ) - ) - - for { - mc := add(mc, 0x20) - sc := add(sc, 1) - } lt(mc, end) { - sc := add(sc, 1) - mc := add(mc, 0x20) - } { - sstore(sc, mload(mc)) - } - - mask := exp(0x100, sub(mc, end)) - - sstore(sc, mul(div(mload(mc), mask), mask)) - } - default { - // get the keccak hash to get the contents of the array - mstore(0x0, _preBytes.slot) - // Start copying to the last used word of the stored array. - let sc := add(keccak256(0x0, 0x20), div(slength, 32)) - - // save new length - sstore(_preBytes.slot, add(mul(newlength, 2), 1)) - - // Copy over the first `submod` bytes of the new data as in - // case 1 above. - let slengthmod := mod(slength, 32) - let submod := sub(32, slengthmod) - let mc := add(_postBytes, submod) - let end := add(_postBytes, mlength) - let mask := sub(exp(0x100, submod), 1) - - sstore(sc, add(sload(sc), and(mload(mc), mask))) - - for { - sc := add(sc, 1) - mc := add(mc, 0x20) - } lt(mc, end) { - sc := add(sc, 1) - mc := add(mc, 0x20) - } { - sstore(sc, mload(mc)) - } - - mask := exp(0x100, sub(mc, end)) - - sstore(sc, mul(div(mload(mc), mask), mask)) - } - } - } + // ------------------------- function slice( bytes memory _bytes, @@ -305,11 +87,10 @@ library LibBytes { return tempBytes; } - function toAddress(bytes memory _bytes, uint256 _start) - internal - pure - returns (address) - { + function toAddress( + bytes memory _bytes, + uint256 _start + ) internal pure returns (address) { if (_bytes.length < _start + 20) { revert AddressOutOfBounds(); } @@ -325,261 +106,20 @@ library LibBytes { return tempAddress; } - function toUint8(bytes memory _bytes, uint256 _start) - internal - pure - returns (uint8) - { - if (_bytes.length < _start + 1) { - revert UintOutOfBounds(); - } - uint8 tempUint; - - assembly { - tempUint := mload(add(add(_bytes, 0x1), _start)) - } - - return tempUint; - } - - function toUint16(bytes memory _bytes, uint256 _start) - internal - pure - returns (uint16) - { - if (_bytes.length < _start + 2) { - revert UintOutOfBounds(); - } - uint16 tempUint; - - assembly { - tempUint := mload(add(add(_bytes, 0x2), _start)) - } - - return tempUint; - } - - function toUint32(bytes memory _bytes, uint256 _start) - internal - pure - returns (uint32) - { - if (_bytes.length < _start + 4) { - revert UintOutOfBounds(); - } - uint32 tempUint; - - assembly { - tempUint := mload(add(add(_bytes, 0x4), _start)) - } - - return tempUint; - } - - function toUint64(bytes memory _bytes, uint256 _start) - internal - pure - returns (uint64) - { - if (_bytes.length < _start + 8) { - revert UintOutOfBounds(); - } - uint64 tempUint; - - assembly { - tempUint := mload(add(add(_bytes, 0x8), _start)) - } - - return tempUint; - } - - function toUint96(bytes memory _bytes, uint256 _start) - internal - pure - returns (uint96) - { - if (_bytes.length < _start + 12) { - revert UintOutOfBounds(); - } - uint96 tempUint; - - assembly { - tempUint := mload(add(add(_bytes, 0xc), _start)) - } - - return tempUint; - } - - function toUint128(bytes memory _bytes, uint256 _start) - internal - pure - returns (uint128) - { - if (_bytes.length < _start + 16) { - revert UintOutOfBounds(); - } - uint128 tempUint; - - assembly { - tempUint := mload(add(add(_bytes, 0x10), _start)) - } - - return tempUint; - } - - function toUint256(bytes memory _bytes, uint256 _start) - internal - pure - returns (uint256) - { - if (_bytes.length < _start + 32) { - revert UintOutOfBounds(); - } - uint256 tempUint; - - assembly { - tempUint := mload(add(add(_bytes, 0x20), _start)) - } - - return tempUint; - } - - function toBytes32(bytes memory _bytes, uint256 _start) - internal - pure - returns (bytes32) - { - if (_bytes.length < _start + 32) { - revert UintOutOfBounds(); - } - bytes32 tempBytes32; - - assembly { - tempBytes32 := mload(add(add(_bytes, 0x20), _start)) - } - - return tempBytes32; - } - - function equal(bytes memory _preBytes, bytes memory _postBytes) - internal - pure - returns (bool) - { - bool success = true; - - assembly { - let length := mload(_preBytes) - - // if lengths don't match the arrays are not equal - switch eq(length, mload(_postBytes)) - case 1 { - // cb is a circuit breaker in the for loop since there's - // no said feature for inline assembly loops - // cb = 1 - don't breaker - // cb = 0 - break - let cb := 1 - - let mc := add(_preBytes, 0x20) - let end := add(mc, length) - - for { - let cc := add(_postBytes, 0x20) - // the next line is the loop condition: - // while(uint256(mc < end) + cb == 2) - } eq(add(lt(mc, end), cb), 2) { - mc := add(mc, 0x20) - cc := add(cc, 0x20) - } { - // if any of these checks fails then arrays are not equal - if iszero(eq(mload(mc), mload(cc))) { - // unsuccess: - success := 0 - cb := 0 - } - } - } - default { - // unsuccess: - success := 0 - } - } - - return success; - } - - function equalStorage(bytes storage _preBytes, bytes memory _postBytes) - internal - view - returns (bool) - { - bool success = true; - - assembly { - // we know _preBytes_offset is 0 - let fslot := sload(_preBytes.slot) - // Decode the length of the stored array like in concatStorage(). - let slength := div( - and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), - 2 - ) - let mlength := mload(_postBytes) - - // if lengths don't match the arrays are not equal - switch eq(slength, mlength) - case 1 { - // slength can contain both the length and contents of the array - // if length < 32 bytes so let's prepare for that - // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage - if iszero(iszero(slength)) { - switch lt(slength, 32) - case 1 { - // blank the last byte which is the length - fslot := mul(div(fslot, 0x100), 0x100) - - if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) { - // unsuccess: - success := 0 - } - } - default { - // cb is a circuit breaker in the for loop since there's - // no said feature for inline assembly loops - // cb = 1 - don't breaker - // cb = 0 - break - let cb := 1 - - // get the keccak hash to get the contents of the array - mstore(0x0, _preBytes.slot) - let sc := keccak256(0x0, 0x20) - - let mc := add(_postBytes, 0x20) - let end := add(mc, mlength) - - // the next line is the loop condition: - // while(uint256(mc < end) + cb == 2) - // solhint-disable-next-line no-empty-blocks - for { - - } eq(add(lt(mc, end), cb), 2) { - sc := add(sc, 1) - mc := add(mc, 0x20) - } { - if iszero(eq(sload(sc), mload(mc))) { - // unsuccess: - success := 0 - cb := 0 - } - } - } - } - } - default { - // unsuccess: - success := 0 - } - } - - return success; + /// Copied from OpenZeppelin's `Strings.sol` utility library. + /// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/8335676b0e99944eef6a742e16dcd9ff6e68e609/contracts/utils/Strings.sol + function toHexString( + uint256 value, + uint256 length + ) internal pure returns (string memory) { + bytes memory buffer = new bytes(2 * length + 2); + buffer[0] = "0"; + buffer[1] = "x"; + for (uint256 i = 2 * length + 1; i > 1; --i) { + buffer[i] = _SYMBOLS[value & 0xf]; + value >>= 4; + } + require(value == 0, "Strings: hex length insufficient"); + return string(buffer); } } diff --git a/src/Libraries/LibDiamond.sol b/src/Libraries/LibDiamond.sol index 901d3781b..f6adcb109 100644 --- a/src/Libraries/LibDiamond.sol +++ b/src/Libraries/LibDiamond.sol @@ -228,9 +228,10 @@ library LibDiamond { } } - function addFacet(DiamondStorage storage ds, address _facetAddress) - internal - { + function addFacet( + DiamondStorage storage ds, + address _facetAddress + ) internal { enforceHasContractCode(_facetAddress); ds.facetFunctionSelectors[_facetAddress].facetAddressPosition = ds .facetAddresses @@ -279,8 +280,8 @@ library LibDiamond { .facetFunctionSelectors[_facetAddress] .functionSelectors[lastSelectorPosition]; ds.facetFunctionSelectors[_facetAddress].functionSelectors[ - selectorPosition - ] = lastSelector; + selectorPosition + ] = lastSelector; ds .selectorToFacetAndPosition[lastSelector] .functionSelectorPosition = uint96(selectorPosition); @@ -312,9 +313,10 @@ library LibDiamond { } } - function initializeDiamondCut(address _init, bytes memory _calldata) - internal - { + function initializeDiamondCut( + address _init, + bytes memory _calldata + ) internal { if (LibUtil.isZeroAddress(_init)) { if (_calldata.length != 0) { revert InitZeroButCalldataNotEmpty(); diff --git a/src/Libraries/LibMappings.sol b/src/Libraries/LibMappings.sol deleted file mode 100644 index baa42aff7..000000000 --- a/src/Libraries/LibMappings.sol +++ /dev/null @@ -1,92 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity 0.8.17; - -import { CannotAuthoriseSelf, UnAuthorized } from "../Errors/GenericErrors.sol"; -import { LibAccess } from "../Libraries/LibAccess.sol"; - -/// @title Mappings Library -/// @author LI.FI (https://li.fi) -/// @notice Provides mappings for all facets that may need them -library LibMappings { - /// Types /// - bytes32 internal constant STARGATE_NAMESPACE = - keccak256("com.lifi.library.mappings.stargate"); - bytes32 internal constant WORMHOLE_NAMESPACE = - keccak256("com.lifi.library.mappings.wormhole"); - bytes32 internal constant AMAROK_NAMESPACE = - keccak256("com.lifi.library.mappings.amarok"); - bytes32 internal constant PERIPHERY_REGISTRY_NAMESPACE = - keccak256("com.lifi.facets.periphery_registry"); - - /// Storage /// - struct StargateMappings { - mapping(address => uint16) stargatePoolId; - mapping(uint256 => uint16) layerZeroChainId; - bool initialized; - } - - struct WormholeMappings { - mapping(uint256 => uint16) wormholeChainId; - bool initialized; - } - - struct AmarokMappings { - mapping(uint256 => uint32) amarokDomain; - } - - struct PeripheryRegistryMappings { - mapping(string => address) contracts; - } - - /// @dev Fetch local storage for Stargate - function getStargateMappings() - internal - pure - returns (StargateMappings storage ms) - { - bytes32 position = STARGATE_NAMESPACE; - // solhint-disable-next-line no-inline-assembly - assembly { - ms.slot := position - } - } - - /// @dev Fetch local storage for Wormhole - function getWormholeMappings() - internal - pure - returns (WormholeMappings storage ms) - { - bytes32 position = WORMHOLE_NAMESPACE; - // solhint-disable-next-line no-inline-assembly - assembly { - ms.slot := position - } - } - - /// @dev Fetch local storage for Amarok - function getAmarokMappings() - internal - pure - returns (AmarokMappings storage ms) - { - bytes32 position = AMAROK_NAMESPACE; - // solhint-disable-next-line no-inline-assembly - assembly { - ms.slot := position - } - } - - /// @dev Fetch local storage for Periphery Registry - function getPeripheryRegistryMappings() - internal - pure - returns (PeripheryRegistryMappings storage ms) - { - bytes32 position = PERIPHERY_REGISTRY_NAMESPACE; - // solhint-disable-next-line no-inline-assembly - assembly { - ms.slot := position - } - } -} diff --git a/src/Libraries/LibUtil.sol b/src/Libraries/LibUtil.sol index de886c9b9..aac43aabc 100644 --- a/src/Libraries/LibUtil.sol +++ b/src/Libraries/LibUtil.sol @@ -6,11 +6,9 @@ import "./LibBytes.sol"; library LibUtil { using LibBytes for bytes; - function getRevertMsg(bytes memory _res) - internal - pure - returns (string memory) - { + function getRevertMsg( + bytes memory _res + ) internal pure returns (string memory) { // If the _res length is less than 68, then the transaction failed silently (without a revert message) if (_res.length < 68) return "Transaction reverted silently"; bytes memory revertData = _res.slice(4, _res.length - 4); // Remove the selector which is the first 4 bytes diff --git a/src/Periphery/AxelarExecutor.sol b/src/Periphery/AxelarExecutor.sol index b45f3e829..69f49699d 100644 --- a/src/Periphery/AxelarExecutor.sol +++ b/src/Periphery/AxelarExecutor.sol @@ -13,6 +13,7 @@ import { ExcessivelySafeCall } from "../Helpers/ExcessivelySafeCall.sol"; /// @title Axelar Executor /// @author LI.FI (https://li.fi) /// @notice Arbitrary execution contract used for cross-chain swaps and message passing using Axelar +/// @custom:version 1.0.0 contract AxelarExecutor is IAxelarExecutable, Ownable, ReentrancyGuard { using LibBytes for bytes; using SafeERC20 for IERC20; @@ -64,7 +65,7 @@ contract AxelarExecutor is IAxelarExecutable, Ownable, ReentrancyGuard { if (!LibAsset.isContract(callTo)) revert NotAContract(); // The remaining bytes should be calldata - bytes memory callData = payload.slice(20, payload.length - 20); + bytes memory callData = payload[20:]; (bool success, ) = callTo.excessivelySafeCall( gasleft(), @@ -92,7 +93,7 @@ contract AxelarExecutor is IAxelarExecutable, Ownable, ReentrancyGuard { address callTo = payload.toAddress(0); address recoveryAddress = payload.toAddress(20); // The remaining bytes should be calldata - bytes memory callData = payload.slice(40, payload.length - 40); + bytes memory callData = payload[40:]; // get ERC-20 address from gateway address tokenAddress = gateway.tokenAddresses(tokenSymbol); diff --git a/src/Periphery/ERC20Proxy.sol b/src/Periphery/ERC20Proxy.sol index 060467b43..6fe52d34c 100644 --- a/src/Periphery/ERC20Proxy.sol +++ b/src/Periphery/ERC20Proxy.sol @@ -7,6 +7,7 @@ import { LibAsset } from "../Libraries/LibAsset.sol"; /// @title ERC20 Proxy /// @author LI.FI (https://li.fi) /// @notice Proxy contract for safely transferring ERC20 tokens for swaps/executions +/// @custom:version 1.0.0 contract ERC20Proxy is Ownable { /// Storage /// mapping(address => bool) public authorizedCallers; @@ -25,10 +26,10 @@ contract ERC20Proxy is Ownable { /// @notice Sets whether or not a specified caller is authorized to call this contract /// @param caller the caller to change authorization for /// @param authorized specifies whether the caller is authorized (true/false) - function setAuthorizedCaller(address caller, bool authorized) - external - onlyOwner - { + function setAuthorizedCaller( + address caller, + bool authorized + ) external onlyOwner { authorizedCallers[caller] = authorized; emit AuthorizationChanged(caller, authorized); } diff --git a/src/Periphery/Executor.sol b/src/Periphery/Executor.sol index 0577cef9c..15cee8113 100644 --- a/src/Periphery/Executor.sol +++ b/src/Periphery/Executor.sol @@ -8,21 +8,25 @@ import { LibAsset } from "../Libraries/LibAsset.sol"; import { ILiFi } from "../Interfaces/ILiFi.sol"; import { IERC20Proxy } from "../Interfaces/IERC20Proxy.sol"; import { TransferrableOwnership } from "../Helpers/TransferrableOwnership.sol"; -import { IERC721Receiver } from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol"; +import { ERC1155Holder } from "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol"; +import { ERC721Holder } from "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol"; /// @title Executor /// @author LI.FI (https://li.fi) /// @notice Arbitrary execution contract used for cross-chain swaps and message passing -contract Executor is ILiFi, ReentrancyGuard, TransferrableOwnership, IERC721Receiver { +/// @custom:version 1.0.0 +contract Executor is + ILiFi, + ReentrancyGuard, + TransferrableOwnership, + ERC1155Holder, + ERC721Holder +{ /// Storage /// /// @notice The address of the ERC20Proxy contract IERC20Proxy public erc20Proxy; - /// Errors /// - error ExecutionFailed(); - error InvalidCaller(); - /// Events /// event ERC20ProxySet(address indexed proxy); @@ -67,9 +71,10 @@ contract Executor is ILiFi, ReentrancyGuard, TransferrableOwnership, IERC721Rece /// @notice Initialize local variables for the Executor /// @param _owner The address of owner /// @param _erc20Proxy The address of the ERC20Proxy contract - constructor(address _owner, address _erc20Proxy) - TransferrableOwnership(_owner) - { + constructor( + address _owner, + address _erc20Proxy + ) TransferrableOwnership(_owner) { owner = _owner; erc20Proxy = IERC20Proxy(_erc20Proxy); @@ -238,11 +243,9 @@ contract Executor is ILiFi, ReentrancyGuard, TransferrableOwnership, IERC721Rece /// @dev Fetches balances of tokens to be swapped before swapping. /// @param _swapData Array of data used to execute swaps /// @return uint256[] Array of token balances. - function _fetchBalances(LibSwap.SwapData[] calldata _swapData) - private - view - returns (uint256[] memory) - { + function _fetchBalances( + LibSwap.SwapData[] calldata _swapData + ) private view returns (uint256[] memory) { uint256 numSwaps = _swapData.length; uint256[] memory balances = new uint256[](numSwaps); address asset; @@ -262,20 +265,6 @@ contract Executor is ILiFi, ReentrancyGuard, TransferrableOwnership, IERC721Rece return balances; } - /// @dev Will be called as part of an ERC721 token transfer to this contract (see IERC721Receiver for more details) - /// @param operator The address of the tx initiator - /// @param from The address from which the ERC721 token was transferred to this contract - /// @param tokenId The ID of the token that was transferred - /// @return The selector of its own function (onERC721Received) - function onERC721Received( - address operator, - address from, - uint256 tokenId, - bytes calldata - ) external returns (bytes4) { - return this.onERC721Received.selector; - } - /// @dev required for receiving native assets from destination swaps // solhint-disable-next-line no-empty-blocks receive() external payable {} diff --git a/src/Periphery/FeeCollector.sol b/src/Periphery/FeeCollector.sol index fee4c255e..c98e16d70 100644 --- a/src/Periphery/FeeCollector.sol +++ b/src/Periphery/FeeCollector.sol @@ -7,6 +7,7 @@ import { TransferrableOwnership } from "../Helpers/TransferrableOwnership.sol"; /// @title Fee Collector /// @author LI.FI (https://li.fi) /// @notice Provides functionality for collecting integrator fees +/// @custom:version 1.0.0 contract FeeCollector is TransferrableOwnership { /// State /// @@ -39,6 +40,7 @@ contract FeeCollector is TransferrableOwnership { /// Constructor /// + // solhint-disable-next-line no-empty-blocks constructor(address _owner) TransferrableOwnership(_owner) {} /// External Methods /// @@ -81,6 +83,7 @@ contract FeeCollector is TransferrableOwnership { uint256 remaining = msg.value - (integratorFee + lifiFee); // Prevent extra native token from being locked in the contract if (remaining > 0) { + // solhint-disable-next-line avoid-low-level-calls (bool success, ) = payable(msg.sender).call{ value: remaining }( "" ); @@ -110,9 +113,9 @@ contract FeeCollector is TransferrableOwnership { /// @notice Batch withdraw fees and sends to the integrator /// @param tokenAddresses addresses of the tokens to withdraw fees for - function batchWithdrawIntegratorFees(address[] memory tokenAddresses) - external - { + function batchWithdrawIntegratorFees( + address[] memory tokenAddresses + ) external { uint256 length = tokenAddresses.length; uint256 balance; for (uint256 i = 0; i < length; ) { @@ -146,10 +149,9 @@ contract FeeCollector is TransferrableOwnership { /// @notice Batch withdraws fees and sends to lifi /// @param tokenAddresses addresses of the tokens to withdraw fees for - function batchWithdrawLifiFees(address[] memory tokenAddresses) - external - onlyOwner - { + function batchWithdrawLifiFees( + address[] memory tokenAddresses + ) external onlyOwner { uint256 length = tokenAddresses.length; uint256 balance; for (uint256 i = 0; i < length; ) { @@ -170,21 +172,18 @@ contract FeeCollector is TransferrableOwnership { /// @notice Returns the balance of the integrator /// @param integratorAddress address of the integrator /// @param tokenAddress address of the token to get the balance of - function getTokenBalance(address integratorAddress, address tokenAddress) - external - view - returns (uint256) - { + function getTokenBalance( + address integratorAddress, + address tokenAddress + ) external view returns (uint256) { return _balances[integratorAddress][tokenAddress]; } /// @notice Returns the balance of lifi /// @param tokenAddress address of the token to get the balance of - function getLifiTokenBalance(address tokenAddress) - external - view - returns (uint256) - { + function getLifiTokenBalance( + address tokenAddress + ) external view returns (uint256) { return _lifiBalances[tokenAddress]; } } diff --git a/src/Periphery/FusePoolZap.sol b/src/Periphery/FusePoolZap.sol index b15d0e4c2..048dda2bc 100644 --- a/src/Periphery/FusePoolZap.sol +++ b/src/Periphery/FusePoolZap.sol @@ -23,6 +23,7 @@ interface IFusePoolDirectory { /// @title Fuse Pool Zap /// @author LI.FI (https://li.fi) /// @notice Allows anyone to quickly zap into a Rari Fuse Pool +/// @custom:version 1.0.0 contract FusePoolZap is ReentrancyGuard { using SafeERC20 for IERC20; @@ -127,6 +128,7 @@ contract FusePoolZap is ReentrancyGuard { ); // Use call because method can succeed with partial revert + // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory res) = address(fToken).call{ value: msg.value }(abi.encodeWithSignature("mint()")); diff --git a/src/Periphery/Receiver.sol b/src/Periphery/Receiver.sol index 877ecbe64..4dc22d388 100644 --- a/src/Periphery/Receiver.sol +++ b/src/Periphery/Receiver.sol @@ -13,6 +13,7 @@ import { UnAuthorized } from "../Errors/GenericErrors.sol"; /// @title Executor /// @author LI.FI (https://li.fi) /// @notice Arbitrary execution contract used for cross-chain swaps and message passing +/// @custom:version 1.0.0 contract Receiver is ILiFi, ReentrancyGuard, TransferrableOwnership { using SafeERC20 for IERC20; @@ -23,6 +24,7 @@ contract Receiver is ILiFi, ReentrancyGuard, TransferrableOwnership { address public amarokRouter; /// Errors /// + error ExternalCallFailed(); /// Events /// event StargateRouterSet(address indexed router); @@ -206,7 +208,9 @@ contract Receiver is ILiFi, ReentrancyGuard, TransferrableOwnership { uint256 amount ) external onlyOwner { if (LibAsset.isNativeAsset(assetId)) { - receiver.call{ value: amount }(""); + // solhint-disable-next-line avoid-low-level-calls + (bool success, ) = receiver.call{ value: amount }(""); + if (!success) revert ExternalCallFailed(); } else { IERC20(assetId).safeTransfer(receiver, amount); } @@ -233,9 +237,12 @@ contract Receiver is ILiFi, ReentrancyGuard, TransferrableOwnership { if (LibAsset.isNativeAsset(assetId)) { // case 1: native asset - if (reserveRecoverGas && gasleft() < _recoverGas) { + uint256 cacheGasLeft = gasleft(); + if (reserveRecoverGas && cacheGasLeft < _recoverGas) { // case 1a: not enough gas left to execute calls - receiver.call{ value: amount }(""); + // solhint-disable-next-line avoid-low-level-calls + (bool success, ) = receiver.call{ value: amount }(""); + if (!success) revert ExternalCallFailed(); emit LiFiTransferRecovered( _transactionId, @@ -248,21 +255,32 @@ contract Receiver is ILiFi, ReentrancyGuard, TransferrableOwnership { } // case 1b: enough gas left to execute calls + // solhint-disable no-empty-blocks try executor.swapAndCompleteBridgeTokens{ value: amount, - gas: gasleft() - _recoverGas + gas: cacheGasLeft - _recoverGas }(_transactionId, _swapData, assetId, receiver) {} catch { - receiver.call{ value: amount }(""); + // solhint-disable-next-line avoid-low-level-calls + (bool success, ) = receiver.call{ value: amount }(""); + if (!success) revert ExternalCallFailed(); + + emit LiFiTransferRecovered( + _transactionId, + assetId, + receiver, + amount, + block.timestamp + ); } } else { // case 2: ERC20 asset + uint256 cacheGasLeft = gasleft(); IERC20 token = IERC20(assetId); token.safeApprove(address(executor), 0); - token.safeIncreaseAllowance(address(executor), amount); - if (reserveRecoverGas && gasleft() < _recoverGas) { + if (reserveRecoverGas && cacheGasLeft < _recoverGas) { // case 2a: not enough gas left to execute calls token.safeTransfer(receiver, amount); @@ -277,9 +295,10 @@ contract Receiver is ILiFi, ReentrancyGuard, TransferrableOwnership { } // case 2b: enough gas left to execute calls + token.safeIncreaseAllowance(address(executor), amount); try executor.swapAndCompleteBridgeTokens{ - gas: gasleft() - _recoverGas + gas: cacheGasLeft - _recoverGas }(_transactionId, _swapData, assetId, receiver) {} catch { token.safeTransfer(receiver, amount); diff --git a/src/Periphery/RelayerCelerIM.sol b/src/Periphery/RelayerCelerIM.sol index eda5a7f43..708a24033 100644 --- a/src/Periphery/RelayerCelerIM.sol +++ b/src/Periphery/RelayerCelerIM.sol @@ -2,34 +2,33 @@ pragma solidity 0.8.17; import { IERC20, SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; -import { ReentrancyGuard } from "../Helpers/ReentrancyGuard.sol"; import { LibSwap } from "../Libraries/LibSwap.sol"; -import { UnAuthorized, InvalidConfig, InsufficientBalance, NotAContract, ContractCallNotAllowed, ExternalCallFailed } from "../Errors/GenericErrors.sol"; +import { ContractCallNotAllowed, ExternalCallFailed, InvalidConfig, UnAuthorized, WithdrawFailed } from "../Errors/GenericErrors.sol"; import { LibAsset } from "../Libraries/LibAsset.sol"; import { LibUtil } from "../Libraries/LibUtil.sol"; import { ILiFi } from "../Interfaces/ILiFi.sol"; import { IExecutor } from "../Interfaces/IExecutor.sol"; import { TransferrableOwnership } from "../Helpers/TransferrableOwnership.sol"; import { IMessageReceiverApp } from "celer-network/contracts/message/interfaces/IMessageReceiverApp.sol"; -import {CelerIMFacet} from "lifi/Facets/CelerIMFacet.sol"; +import { CelerIMFacet } from "lifi/Facets/CelerIMFacet.sol"; import { MessageSenderLib, MsgDataTypes, IMessageBus, IOriginalTokenVault, IPeggedTokenBridge, IOriginalTokenVaultV2, IPeggedTokenBridgeV2 } from "celer-network/contracts/message/libraries/MessageSenderLib.sol"; import { IBridge as ICBridge } from "celer-network/contracts/interfaces/IBridge.sol"; /// @title RelayerCelerIM /// @author LI.FI (https://li.fi) /// @notice Relayer contract for CelerIM that forwards calls and handles refunds on src side and acts receiver on dest -contract RelayerCelerIM is ILiFi, ReentrancyGuard, TransferrableOwnership { +/// @custom:version 1.0.0 +contract RelayerCelerIM is ILiFi, TransferrableOwnership { using SafeERC20 for IERC20; /// Storage /// + IMessageBus public cBridgeMessageBus; address public diamondAddress; IExecutor public executor; - /// Errors /// - error WithdrawFailed(); - /// Events /// + event LogWithdraw( address indexed _assetAddress, address indexed _to, @@ -40,6 +39,7 @@ contract RelayerCelerIM is ILiFi, ReentrancyGuard, TransferrableOwnership { event ExecutorSet(address indexed executorAddress); /// Modifiers /// + modifier onlyCBridgeMessageBus() { if (msg.sender != address(cBridgeMessageBus)) revert UnAuthorized(); _; @@ -50,6 +50,7 @@ contract RelayerCelerIM is ILiFi, ReentrancyGuard, TransferrableOwnership { } /// Constructor + constructor( address _owner, address _cBridgeMessageBusAddress, @@ -153,9 +154,10 @@ contract RelayerCelerIM is ILiFi, ReentrancyGuard, TransferrableOwnership { * @param _bridgeData the core information needed for bridging * @param _celerIMData data specific to CelerIM */ + // solhint-disable-next-line code-complexity function sendTokenTransfer( ILiFi.BridgeData memory _bridgeData, - CelerIMFacet.CelerIMData memory _celerIMData + CelerIMFacet.CelerIMData calldata _celerIMData ) external payable @@ -184,6 +186,7 @@ contract RelayerCelerIM is ILiFi, ReentrancyGuard, TransferrableOwnership { bridgeAddress, _bridgeData.minAmount ); + // solhint-disable-next-line check-send-result ICBridge(bridgeAddress).send( _bridgeData.receiver, _bridgeData.sendingAssetId, @@ -337,10 +340,9 @@ contract RelayerCelerIM is ILiFi, ReentrancyGuard, TransferrableOwnership { /// @notice sets the CBridge MessageBus address /// @param _messageBusAddress the MessageBus address - function setCBridgeMessageBus(address _messageBusAddress) - external - onlyOwner - { + function setCBridgeMessageBus( + address _messageBusAddress + ) external onlyOwner { cBridgeMessageBus = IMessageBus(_messageBusAddress); emit CBridgeMessageBusSet(_messageBusAddress); } @@ -389,8 +391,11 @@ contract RelayerCelerIM is ILiFi, ReentrancyGuard, TransferrableOwnership { { success = true; } catch { + // solhint-disable-next-line avoid-low-level-calls (bool fundsSent, ) = refundAddress.call{ value: amount }(""); - if (!fundsSent) revert ExternalCallFailed(); + if (!fundsSent) { + revert ExternalCallFailed(); + } } } else { IERC20 token = IERC20(assetId); @@ -433,7 +438,11 @@ contract RelayerCelerIM is ILiFi, ReentrancyGuard, TransferrableOwnership { uint256 amount ) external onlyOwner { if (LibAsset.isNativeAsset(assetId)) { - receiver.call{ value: amount }(""); + // solhint-disable-next-line avoid-low-level-calls + (bool success, ) = receiver.call{ value: amount }(""); + if (!success) { + revert WithdrawFailed(); + } } else { IERC20(assetId).safeTransfer(receiver, amount); } @@ -456,14 +465,18 @@ contract RelayerCelerIM is ILiFi, ReentrancyGuard, TransferrableOwnership { bool success; // make sure that callTo address is either of the cBridge addresses - if(cBridgeMessageBus.liquidityBridge() != _callTo && - cBridgeMessageBus.pegBridge() != _callTo && - cBridgeMessageBus.pegBridgeV2() != _callTo && - cBridgeMessageBus.pegVault() != _callTo && - cBridgeMessageBus.pegVaultV2() != _callTo) - revert ContractCallNotAllowed(); + if ( + cBridgeMessageBus.liquidityBridge() != _callTo && + cBridgeMessageBus.pegBridge() != _callTo && + cBridgeMessageBus.pegBridgeV2() != _callTo && + cBridgeMessageBus.pegVault() != _callTo && + cBridgeMessageBus.pegVaultV2() != _callTo + ) { + revert ContractCallNotAllowed(); + } // call contract + // solhint-disable-next-line avoid-low-level-calls (success, ) = _callTo.call(_callData); // forward funds to _to address and emit event, if cBridge refund successful @@ -477,5 +490,6 @@ contract RelayerCelerIM is ILiFi, ReentrancyGuard, TransferrableOwnership { } // required in order to receive native tokens from cBridge facet + // solhint-disable-next-line no-empty-blocks receive() external payable {} } diff --git a/src/Periphery/ServiceFeeCollector.sol b/src/Periphery/ServiceFeeCollector.sol index 00dd45ef4..6cc34ce73 100644 --- a/src/Periphery/ServiceFeeCollector.sol +++ b/src/Periphery/ServiceFeeCollector.sol @@ -7,6 +7,7 @@ import { TransferrableOwnership } from "../Helpers/TransferrableOwnership.sol"; /// @title Service Fee Collector /// @author LI.FI (https://li.fi) /// @notice Provides functionality for collecting service fees (gas/insurance) +/// @custom:version 1.0.0 contract ServiceFeeCollector is TransferrableOwnership { /// Errors /// error TransferFailure(); @@ -15,6 +16,7 @@ contract ServiceFeeCollector is TransferrableOwnership { /// Events /// event GasFeesCollected( address indexed token, + uint256 indexed chainId, address indexed receiver, uint256 feeAmount ); @@ -33,6 +35,7 @@ contract ServiceFeeCollector is TransferrableOwnership { /// Constructor /// + // solhint-disable-next-line no-empty-blocks constructor(address _owner) TransferrableOwnership(_owner) {} /// External Methods /// @@ -40,35 +43,31 @@ contract ServiceFeeCollector is TransferrableOwnership { /// @notice Collects gas fees /// @param tokenAddress The address of the token to collect /// @param feeAmount The amount of fees to collect + /// @param chainId The chain id of the destination chain /// @param receiver The address to send gas to on the destination chain function collectTokenGasFees( address tokenAddress, uint256 feeAmount, + uint256 chainId, address receiver ) external { LibAsset.depositAsset(tokenAddress, feeAmount); - emit GasFeesCollected(tokenAddress, receiver, feeAmount); + emit GasFeesCollected(tokenAddress, chainId, receiver, feeAmount); } /// @notice Collects gas fees in native token - /// @param feeAmount The amount of native token to collect + /// @param chainId The chain id of the destination chain /// @param receiver The address to send gas to on destination chain - function collectNativeGasFees(uint256 feeAmount, address receiver) - external - payable - { - if (msg.value < feeAmount) revert NotEnoughNativeForFees(); - uint256 remaining = msg.value - (feeAmount); - // Prevent extra native token from being locked in the contract - if (remaining > 0) { - (bool success, ) = payable(msg.sender).call{ value: remaining }( - "" - ); - if (!success) { - revert TransferFailure(); - } - } - emit GasFeesCollected(LibAsset.NULL_ADDRESS, receiver, feeAmount); + function collectNativeGasFees( + uint256 chainId, + address receiver + ) external payable { + emit GasFeesCollected( + LibAsset.NULL_ADDRESS, + chainId, + receiver, + msg.value + ); } /// @notice Collects insurance fees @@ -85,27 +84,12 @@ contract ServiceFeeCollector is TransferrableOwnership { } /// @notice Collects insurance fees in native token - /// @param feeAmount The amount of native token to collect /// @param receiver The address to insure - function collectNativeInsuranceFees(uint256 feeAmount, address receiver) - external - payable - { - if (msg.value < feeAmount) revert NotEnoughNativeForFees(); - uint256 remaining = msg.value - (feeAmount); - // Prevent extra native token from being locked in the contract - if (remaining > 0) { - (bool success, ) = payable(msg.sender).call{ value: remaining }( - "" - ); - if (!success) { - revert TransferFailure(); - } - } + function collectNativeInsuranceFees(address receiver) external payable { emit InsuranceFeesCollected( LibAsset.NULL_ADDRESS, receiver, - feeAmount + msg.value ); } @@ -119,10 +103,9 @@ contract ServiceFeeCollector is TransferrableOwnership { /// @notice Batch withdraws fees /// @param tokenAddresses The addresses of the tokens to withdraw fees for - function batchWithdrawFees(address[] memory tokenAddresses) - external - onlyOwner - { + function batchWithdrawFees( + address[] calldata tokenAddresses + ) external onlyOwner { uint256 length = tokenAddresses.length; uint256 balance; for (uint256 i = 0; i < length; ) { diff --git a/tasks/generateDiamondABI.ts b/tasks/generateDiamondABI.ts index 49aaed00c..302f68eea 100644 --- a/tasks/generateDiamondABI.ts +++ b/tasks/generateDiamondABI.ts @@ -10,7 +10,6 @@ task( 'diamondABI', 'Generates ABI file for diamond, includes all ABIs of facets' ).setAction(async () => { - // Create an empty array to store the ABI fragments const abi: Fragment[] = [] @@ -35,10 +34,7 @@ task( for (const file of files) { const jsonFile = file.replace('sol', 'json') const data = fs.readFileSync( - path.resolve( - __dirname, - `../out/${file}/${jsonFile}` - ) + path.resolve(__dirname, `../out/${file}/${jsonFile}`) ) // eslint-disable-next-line @typescript-eslint/no-explicit-any const json: any = JSON.parse(data.toString()) @@ -46,12 +42,14 @@ task( } // Remove duplicates from the combined ABI object - // Filters by checking if the name and type of the + // Filters by checking if the name and type of the // function already exists in another ABI fragment - const cleanAbi = abi.filter( - (item, index, self) => - index === - self.findIndex((t) => t.name === item.name && t.type === item.type) + const cleanAbi = ( + abi.filter( + (item, index, self) => + index === + self.findIndex((t) => t.name === item.name && t.type === item.type) + ) ) // Write the final ABI to a file diff --git a/test/solidity/Facets/AcrossFacet.t.sol b/test/solidity/Facets/AcrossFacet.t.sol index a07944ca0..4af86dcce 100644 --- a/test/solidity/Facets/AcrossFacet.t.sol +++ b/test/solidity/Facets/AcrossFacet.t.sol @@ -10,9 +10,9 @@ contract TestAcrossFacet is AcrossFacet { address internal constant ADDRESS_WETH = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; - constructor(IAcrossSpokePool _spokePool) - AcrossFacet(_spokePool, ADDRESS_WETH) - {} + constructor( + IAcrossSpokePool _spokePool + ) AcrossFacet(_spokePool, ADDRESS_WETH) {} function addDex(address _dex) external { LibAllowList.addAllowedContract(_dex); @@ -88,10 +88,9 @@ contract AcrossFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { acrossFacet.swapAndStartBridgeTokensViaAcross{ value: swapData[0].fromAmount @@ -108,7 +107,7 @@ contract AcrossFacetTest is TestBaseFacet { function testFailsToBridgeERC20TokensDueToQuoteTimeout() public { vm.startPrank(WETH_HOLDER); ERC20 weth = ERC20(ADDRESS_WETH); - weth.approve(address(acrossFacet), 10_000 * 10**weth.decimals()); + weth.approve(address(acrossFacet), 10_000 * 10 ** weth.decimals()); AcrossFacet.AcrossData memory data = AcrossFacet.AcrossData( 0, // Relayer fee diff --git a/test/solidity/Facets/AllBridgeFacet.t.sol b/test/solidity/Facets/AllBridgeFacet.t.sol index 863f689f2..3550e40ba 100644 --- a/test/solidity/Facets/AllBridgeFacet.t.sol +++ b/test/solidity/Facets/AllBridgeFacet.t.sol @@ -99,10 +99,9 @@ contract AllBridgeFacetTest is TestBaseFacet { // facet does not support bridging of native assets } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { allBridgeFacet.swapAndStartBridgeTokensViaAllBridge{ value: swapData[0].fromAmount + addToMessageValue diff --git a/test/solidity/Facets/AmarokFacet.t.sol b/test/solidity/Facets/AmarokFacet.t.sol index 37383c133..ca09352f4 100644 --- a/test/solidity/Facets/AmarokFacet.t.sol +++ b/test/solidity/Facets/AmarokFacet.t.sol @@ -8,9 +8,9 @@ import { OnlyContractOwner, InvalidConfig, NotInitialized, AlreadyInitialized, I // Stub AmarokFacet Contract contract TestAmarokFacet is AmarokFacet { - constructor(IConnextHandler _connextHandler) - AmarokFacet(_connextHandler) - {} + constructor( + IConnextHandler _connextHandler + ) AmarokFacet(_connextHandler) {} function addDex(address _dex) external { LibAllowList.addAllowedContract(_dex); @@ -70,11 +70,9 @@ contract AmarokFacetTest is TestBaseFacet { bridgeData.destinationChainId = 137; // produce valid AmarokData - address receiver = address(0x0BAEE5700179d87FabAd13022447Bd4E160374DD); address delegate = USER_RECEIVER; amarokData = AmarokFacet.AmarokData({ callData: "", - callTo: receiver, relayerFee: 0, slippageTol: 9995, delegate: delegate, @@ -82,7 +80,7 @@ contract AmarokFacetTest is TestBaseFacet { }); // make sure relayerFee is sent with every transaction - addToMessageValue = 1 * 10**15; + addToMessageValue = 1 * 10 ** 15; } function initiateBridgeTxWithFacet(bool isNative) internal override { @@ -95,10 +93,9 @@ contract AmarokFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { amarokFacet.swapAndStartBridgeTokensViaAmarok{ value: swapData[0].fromAmount diff --git a/test/solidity/Facets/ArbitrumBridgeFacet.t.sol b/test/solidity/Facets/ArbitrumBridgeFacet.t.sol index bd18ab7dc..e917f2a10 100644 --- a/test/solidity/Facets/ArbitrumBridgeFacet.t.sol +++ b/test/solidity/Facets/ArbitrumBridgeFacet.t.sol @@ -7,9 +7,10 @@ import { IGatewayRouter } from "lifi/Interfaces/IGatewayRouter.sol"; // Stub ArbitrumBridgeFacet Contract contract TestArbitrumBridgeFacet is ArbitrumBridgeFacet { - constructor(IGatewayRouter _gatewayRouter, IGatewayRouter _inbox) - ArbitrumBridgeFacet(_gatewayRouter, _inbox) - {} + constructor( + IGatewayRouter _gatewayRouter, + IGatewayRouter _inbox + ) ArbitrumBridgeFacet(_gatewayRouter, _inbox) {} function addDex(address _dex) external { LibAllowList.addAllowedContract(_dex); @@ -102,10 +103,9 @@ contract ArbitrumBridgeFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { arbitrumBridgeFacet.swapAndStartBridgeTokensViaArbitrumBridge{ value: swapData[0].fromAmount + addToMessageValue diff --git a/test/solidity/Facets/CBridge.t.sol b/test/solidity/Facets/CBridge.t.sol index 14fa265ee..800a21e41 100644 --- a/test/solidity/Facets/CBridge.t.sol +++ b/test/solidity/Facets/CBridge.t.sol @@ -23,30 +23,48 @@ interface Ownable { } contract CBridgeFacetTest is TestBaseFacet { - address internal constant CBRIDGE_ROUTER = 0x5427FEFA711Eff984124bFBB1AB6fbf5E3DA1820; + address internal constant CBRIDGE_ROUTER = + 0x5427FEFA711Eff984124bFBB1AB6fbf5E3DA1820; TestCBridgeFacet internal cBridge; function initiateBridgeTxWithFacet(bool isNative) internal override { // a) prepare the facet-specific data - CBridgeFacet.CBridgeData memory data = CBridgeFacet.CBridgeData(5000, currentTxId++); + CBridgeFacet.CBridgeData memory data = CBridgeFacet.CBridgeData( + 5000, + currentTxId++ + ); // b) call the correct function selectors (as they differ for each facet) if (isNative) { - cBridge.startBridgeTokensViaCBridge{ value: bridgeData.minAmount }(bridgeData, data); + cBridge.startBridgeTokensViaCBridge{ value: bridgeData.minAmount }( + bridgeData, + data + ); } else { cBridge.startBridgeTokensViaCBridge(bridgeData, data); } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) internal override { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { // a) prepare the facet-specific data - CBridgeFacet.CBridgeData memory data = CBridgeFacet.CBridgeData(5000, currentTxId++); + CBridgeFacet.CBridgeData memory data = CBridgeFacet.CBridgeData( + 5000, + currentTxId++ + ); // b) call the correct function selectors (as they differ for each facet) if (isNative) { - cBridge.swapAndStartBridgeTokensViaCBridge{ value: swapData[0].fromAmount }(bridgeData, swapData, data); + cBridge.swapAndStartBridgeTokensViaCBridge{ + value: swapData[0].fromAmount + }(bridgeData, swapData, data); } else { - cBridge.swapAndStartBridgeTokensViaCBridge(bridgeData, swapData, data); + cBridge.swapAndStartBridgeTokensViaCBridge( + bridgeData, + swapData, + data + ); } } @@ -55,7 +73,9 @@ contract CBridgeFacetTest is TestBaseFacet { cBridge = new TestCBridgeFacet(ICBridge(CBRIDGE_ROUTER)); bytes4[] memory functionSelectors = new bytes4[](4); functionSelectors[0] = cBridge.startBridgeTokensViaCBridge.selector; - functionSelectors[1] = cBridge.swapAndStartBridgeTokensViaCBridge.selector; + functionSelectors[1] = cBridge + .swapAndStartBridgeTokensViaCBridge + .selector; functionSelectors[2] = cBridge.addDex.selector; functionSelectors[3] = cBridge.setFunctionApprovalBySignature.selector; @@ -63,15 +83,24 @@ contract CBridgeFacetTest is TestBaseFacet { cBridge = TestCBridgeFacet(address(diamond)); cBridge.addDex(address(uniswap)); - cBridge.setFunctionApprovalBySignature(uniswap.swapExactTokensForTokens.selector); - cBridge.setFunctionApprovalBySignature(uniswap.swapTokensForExactETH.selector); - cBridge.setFunctionApprovalBySignature(uniswap.swapETHForExactTokens.selector); + cBridge.setFunctionApprovalBySignature( + uniswap.swapExactTokensForTokens.selector + ); + cBridge.setFunctionApprovalBySignature( + uniswap.swapTokensForExactETH.selector + ); + cBridge.setFunctionApprovalBySignature( + uniswap.swapETHForExactTokens.selector + ); setFacetAddressInTestBase(address(cBridge), "cBridgeFacet"); } function testFail_ReentrantCallBridge() internal { // prepare facet-specific data - CBridgeFacet.CBridgeData memory cBridgeData = CBridgeFacet.CBridgeData(5000, currentTxId++); + CBridgeFacet.CBridgeData memory cBridgeData = CBridgeFacet.CBridgeData( + 5000, + currentTxId++ + ); // prepare bridge data for native bridging setDefaultBridgeData(); @@ -80,7 +109,11 @@ contract CBridgeFacetTest is TestBaseFacet { // call testcase with correct call data (i.e. function selector) for this facet super.failReentrantCall( - abi.encodeWithSelector(cBridge.startBridgeTokensViaCBridge.selector, bridgeData, cBridgeData) + abi.encodeWithSelector( + cBridge.startBridgeTokensViaCBridge.selector, + bridgeData, + cBridgeData + ) ); } @@ -88,7 +121,10 @@ contract CBridgeFacetTest is TestBaseFacet { vm.startPrank(USER_SENDER); // prepare facet-specific data - CBridgeFacet.CBridgeData memory cBridgeData = CBridgeFacet.CBridgeData(5000, currentTxId++); + CBridgeFacet.CBridgeData memory cBridgeData = CBridgeFacet.CBridgeData( + 5000, + currentTxId++ + ); // prepare bridge data for native bridging setDefaultBridgeData(); @@ -110,20 +146,20 @@ contract CBridgeFacetTest is TestBaseFacet { delete swapData; swapData.push( LibSwap.SwapData({ - callTo: address(uniswap), - approveTo: address(uniswap), - sendingAssetId: address(0), - receivingAssetId: ADDRESS_USDC, - fromAmount: amountIn, - callData: abi.encodeWithSelector( - uniswap.swapETHForExactTokens.selector, - amountOut, - path, - address(cBridge), - block.timestamp + 20 minutes - ), - requiresDeposit: true - }) + callTo: address(uniswap), + approveTo: address(uniswap), + sendingAssetId: address(0), + receivingAssetId: ADDRESS_USDC, + fromAmount: amountIn, + callData: abi.encodeWithSelector( + uniswap.swapETHForExactTokens.selector, + amountOut, + path, + address(cBridge), + block.timestamp + 20 minutes + ), + requiresDeposit: true + }) ); // call testcase with correct call data (i.e. function selector) for this facet @@ -144,11 +180,17 @@ contract CBridgeFacetTest is TestBaseFacet { bridgeData.sendingAssetId = address(0); bridgeData.minAmount = 1 ether; - CBridgeFacet.CBridgeData memory data = CBridgeFacet.CBridgeData(5000, currentTxId++); + CBridgeFacet.CBridgeData memory data = CBridgeFacet.CBridgeData( + 5000, + currentTxId++ + ); vm.expectRevert(InvalidAmount.selector); - cBridge.startBridgeTokensViaCBridge{ value: bridgeData.minAmount - 1 }(bridgeData, data); + cBridge.startBridgeTokensViaCBridge{ value: bridgeData.minAmount - 1 }( + bridgeData, + data + ); vm.stopPrank(); } diff --git a/test/solidity/Facets/CBridgeAndFeeCollection.t.sol b/test/solidity/Facets/CBridgeAndFeeCollection.t.sol index 1a8bf0648..66d0307c9 100644 --- a/test/solidity/Facets/CBridgeAndFeeCollection.t.sol +++ b/test/solidity/Facets/CBridgeAndFeeCollection.t.sol @@ -105,9 +105,9 @@ contract CBridgeAndFeeCollectionTest is DSTest, DiamondTest { function testCanCollectTokenFeesAndBridgeTokens() public { vm.startPrank(WHALE); - uint256 amount = 1_000 * 10**usdc.decimals(); - uint256 fee = 10 * 10**usdc.decimals(); - uint256 lifiFee = 5 * 10**usdc.decimals(); + uint256 amount = 1_000 * 10 ** usdc.decimals(); + uint256 fee = 10 * 10 ** usdc.decimals(); + uint256 lifiFee = 5 * 10 ** usdc.decimals(); ILiFi.BridgeData memory bridgeData = ILiFi.BridgeData( "", @@ -211,9 +211,9 @@ contract CBridgeAndFeeCollectionTest is DSTest, DiamondTest { function testCanCollectTokenFeesSwapAndBridgeTokens() public { vm.startPrank(WHALE); - uint256 amountToBridge = 1_000 * 10**dai.decimals(); - uint256 fee = 10 * 10**usdc.decimals(); - uint256 lifiFee = 5 * 10**usdc.decimals(); + uint256 amountToBridge = 1_000 * 10 ** dai.decimals(); + uint256 fee = 10 * 10 ** usdc.decimals(); + uint256 lifiFee = 5 * 10 ** usdc.decimals(); ILiFi.BridgeData memory bridgeData = ILiFi.BridgeData( "", @@ -290,7 +290,7 @@ contract CBridgeAndFeeCollectionTest is DSTest, DiamondTest { function testCanCollectNativeFeesSwapAndBridgeTokens() public { vm.startPrank(WHALE); - uint256 amountToBridge = 1000 * 10**usdc.decimals(); + uint256 amountToBridge = 1000 * 10 ** usdc.decimals(); uint256 fee = 0.01 ether; uint256 lifiFee = 0.0015 ether; @@ -367,9 +367,9 @@ contract CBridgeAndFeeCollectionTest is DSTest, DiamondTest { function testCanSwapCollectTokenFeesAndBridgeTokens() public { vm.startPrank(WHALE); - uint256 amountToBridge = 1_000 * 10**dai.decimals(); - uint256 fee = 10 * 10**dai.decimals(); - uint256 lifiFee = 5 * 10**dai.decimals(); + uint256 amountToBridge = 1_000 * 10 ** dai.decimals(); + uint256 fee = 10 * 10 ** dai.decimals(); + uint256 lifiFee = 5 * 10 ** dai.decimals(); ILiFi.BridgeData memory bridgeData = ILiFi.BridgeData( "", @@ -450,9 +450,9 @@ contract CBridgeAndFeeCollectionTest is DSTest, DiamondTest { function testCanSwapCollectNativeFeesAndBridgeTokens() public { vm.startPrank(WHALE); - uint256 amountToBridge = 1000 * 10**usdc.decimals(); - uint256 fee = 10 * 10**usdc.decimals(); - uint256 lifiFee = 5 * 10**usdc.decimals(); + uint256 amountToBridge = 1000 * 10 ** usdc.decimals(); + uint256 fee = 10 * 10 ** usdc.decimals(); + uint256 lifiFee = 5 * 10 ** usdc.decimals(); ILiFi.BridgeData memory bridgeData = ILiFi.BridgeData( "", diff --git a/test/solidity/Facets/CBridgeFacetPacked.t.sol b/test/solidity/Facets/CBridgeFacetPacked.t.sol index 506348fde..33f8d3dcd 100644 --- a/test/solidity/Facets/CBridgeFacetPacked.t.sol +++ b/test/solidity/Facets/CBridgeFacetPacked.t.sol @@ -52,14 +52,25 @@ contract CBridgeGasTest is Test, DiamondTest { cBridgeFacetPacked = new CBridgeFacetPacked(cbridge); usdc = ERC20(USDC_ADDRESS); - bytes4[] memory functionSelectors = new bytes4[](6); - functionSelectors[0] = cBridgeFacetPacked.startBridgeTokensViaCBridgeNativePacked.selector; - functionSelectors[1] = cBridgeFacetPacked.startBridgeTokensViaCBridgeNativeMin.selector; - functionSelectors[2] = cBridgeFacetPacked.startBridgeTokensViaCBridgeERC20Packed.selector; - functionSelectors[3] = cBridgeFacetPacked.startBridgeTokensViaCBridgeERC20Min.selector; - functionSelectors[4] = cBridgeFacetPacked.encoder_startBridgeTokensViaCBridgeNativePacked.selector; - functionSelectors[5] = cBridgeFacetPacked.encoder_startBridgeTokensViaCBridgeERC20Packed.selector; + functionSelectors[0] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeNativePacked + .selector; + functionSelectors[1] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeNativeMin + .selector; + functionSelectors[2] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeERC20Packed + .selector; + functionSelectors[3] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeERC20Min + .selector; + functionSelectors[4] = cBridgeFacetPacked + .encoder_startBridgeTokensViaCBridgeNativePacked + .selector; + functionSelectors[5] = cBridgeFacetPacked + .encoder_startBridgeTokensViaCBridgeERC20Packed + .selector; addFacet(diamond, address(cBridgeFacetPacked), functionSelectors); cBridgeFacetPacked = CBridgeFacetPacked(address(diamond)); @@ -67,9 +78,15 @@ contract CBridgeGasTest is Test, DiamondTest { /// Perpare Approval HopFacetOptimized hopFacetOptimized = new HopFacetOptimized(); bytes4[] memory functionSelectorsApproval = new bytes4[](1); - functionSelectorsApproval[0] = hopFacetOptimized.setApprovalForBridges.selector; + functionSelectorsApproval[0] = hopFacetOptimized + .setApprovalForBridges + .selector; - addFacet(diamond, address(hopFacetOptimized), functionSelectorsApproval); + addFacet( + diamond, + address(hopFacetOptimized), + functionSelectorsApproval + ); hopFacetOptimized = HopFacetOptimized(address(diamond)); address[] memory bridges = new address[](1); @@ -78,7 +95,6 @@ contract CBridgeGasTest is Test, DiamondTest { tokens[0] = USDC_ADDRESS; hopFacetOptimized.setApprovalForBridges(bridges, tokens); - /// Perpare parameters transactionId = "someID"; integrator = "demo-partner"; @@ -86,7 +102,8 @@ contract CBridgeGasTest is Test, DiamondTest { maxSlippage = 5000; // Native params - amountNative = 1 * 10**18; + amountNative = 1 * 10 ** 18; + bytes memory packedNativeParams = bytes.concat( bytes8(transactionId), // transactionId bytes16(bytes(integrator)), // integrator @@ -96,12 +113,14 @@ contract CBridgeGasTest is Test, DiamondTest { bytes4(maxSlippage) // maxSlippage ); packedNative = bytes.concat( - abi.encodeWithSignature("startBridgeTokensViaCBridgeNativePacked()"), + abi.encodeWithSignature( + "startBridgeTokensViaCBridgeNativePacked()" + ), packedNativeParams ); // USDC params - amountUSDC = 100 * 10**usdc.decimals(); + amountUSDC = 100 * 10 ** usdc.decimals(); bytes memory packedUSDCParams = bytes.concat( bytes8(transactionId), // transactionId bytes16(bytes(integrator)), // integrator @@ -113,14 +132,18 @@ contract CBridgeGasTest is Test, DiamondTest { bytes4(maxSlippage) // maxSlippage ); packedUSDC = bytes.concat( - abi.encodeWithSignature("startBridgeTokensViaCBridgeERC20Packed()"), + abi.encodeWithSignature( + "startBridgeTokensViaCBridgeERC20Packed()" + ), packedUSDCParams ); } function testStartBridgeTokensViaCBridgeNativePacked() public { vm.startPrank(WHALE); - (bool success, ) = address(diamond).call{value: amountNative}(packedNative); + (bool success, ) = address(diamond).call{ value: amountNative }( + packedNative + ); if (!success) { revert(); } @@ -129,7 +152,9 @@ contract CBridgeGasTest is Test, DiamondTest { function testStartBridgeTokensViaCBridgeNativeMin() public { vm.startPrank(WHALE); - cBridgeFacetPacked.startBridgeTokensViaCBridgeNativeMin{value: amountNative}( + cBridgeFacetPacked.startBridgeTokensViaCBridgeNativeMin{ + value: amountNative + }( transactionId, integrator, RECEIVER, diff --git a/test/solidity/Facets/CelerIMFacet.t.sol b/test/solidity/Facets/CelerIMFacet.t.sol index 525b66176..6bbe76c03 100644 --- a/test/solidity/Facets/CelerIMFacet.t.sol +++ b/test/solidity/Facets/CelerIMFacet.t.sol @@ -10,9 +10,11 @@ import { Executor } from "lifi/Periphery/Executor.sol"; // Stub CelerIMFacet Contract contract TestCelerIMFacet is CelerIMFacet { - constructor(IMessageBus _messageBus, RelayerCelerIM _relayer) - CelerIMFacet(_messageBus, _relayer) - {} + constructor( + IMessageBus _messageBus, + RelayerCelerIM _relayer, + address _cfUSDC + ) CelerIMFacet(_messageBus, _relayer, _cfUSDC) {} function addDex(address _dex) external { LibAllowList.addAllowedContract(_dex); @@ -76,6 +78,8 @@ contract CelerIMFacetTest is TestBaseFacet { 0x16365b45EB269B5B5dACB34B4a15399Ec79b95eB; address internal constant CBRIDGE_PEG_BRIDGE_V2 = 0x52E4f244f380f8fA51816c8a10A63105dd4De084; + address internal constant CFUSDC = + 0x317F8d18FB16E49a958Becd0EA72f8E153d25654; TestCelerIMFacet internal celerIMFacet; CelerIMFacet.CelerIMData internal celerIMData; @@ -99,7 +103,8 @@ contract CelerIMFacetTest is TestBaseFacet { celerIMFacet = new TestCelerIMFacet( IMessageBus(CBRIDGE_MESSAGEBUS_ETH), - relayer + relayer, + CFUSDC ); bytes4[] memory functionSelectors = new bytes4[](4); functionSelectors[0] = celerIMFacet @@ -147,27 +152,26 @@ contract CelerIMFacetTest is TestBaseFacet { function initiateBridgeTxWithFacet(bool isNative) internal override { if (isNative) { celerIMFacet.startBridgeTokensViaCelerIM{ - value: bridgeData.minAmount + value: bridgeData.minAmount + addToMessageValue }(bridgeData, celerIMData); } else { - celerIMFacet.startBridgeTokensViaCelerIM(bridgeData, celerIMData); + celerIMFacet.startBridgeTokensViaCelerIM{ + value: addToMessageValue + }(bridgeData, celerIMData); } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { celerIMFacet.swapAndStartBridgeTokensViaCelerIM{ - value: swapData[0].fromAmount + value: swapData[0].fromAmount + addToMessageValue }(bridgeData, swapData, celerIMData); } else { - celerIMFacet.swapAndStartBridgeTokensViaCelerIM( - bridgeData, - swapData, - celerIMData - ); + celerIMFacet.swapAndStartBridgeTokensViaCelerIM{ + value: addToMessageValue + }(bridgeData, swapData, celerIMData); } } @@ -261,6 +265,46 @@ contract CelerIMFacetTest is TestBaseFacet { vm.stopPrank(); } + function test_CanBridgeNativeTokens_DestinationCall() public { + addToMessageValue = 1e17; + celerIMData = CelerIMFacet.CelerIMData({ + maxSlippage: 5000, + nonce: 1, + callTo: abi.encodePacked(address(1)), + callData: abi.encode( + bytes32(""), + swapData, + USER_SENDER, + USER_SENDER + ), + messageBusFee: addToMessageValue, + bridgeType: MsgDataTypes.BridgeSendType.Liquidity + }); + bridgeData.hasDestinationCall = true; + + super.testBase_CanBridgeNativeTokens(); + } + + function test_CanSwapAndBridgeNativeTokens_DestinationCall() public { + addToMessageValue = 1e17; + celerIMData = CelerIMFacet.CelerIMData({ + maxSlippage: 5000, + nonce: 1, + callTo: abi.encodePacked(address(1)), + callData: abi.encode( + bytes32(""), + swapData, + USER_SENDER, + USER_SENDER + ), + messageBusFee: addToMessageValue, + bridgeType: MsgDataTypes.BridgeSendType.Liquidity + }); + bridgeData.hasDestinationCall = true; + + super.testBase_CanSwapAndBridgeNativeTokens(); + } + function testBase_CanBridgeTokens_fuzzed(uint256 amount) public override { vm.assume(amount > 100 && amount < 100_000); super.testBase_CanBridgeTokens_fuzzed(amount); diff --git a/test/solidity/Facets/CircleBridgeFacet.t.sol b/test/solidity/Facets/CircleBridgeFacet.t.sol index 317bd76a1..4ac066940 100644 --- a/test/solidity/Facets/CircleBridgeFacet.t.sol +++ b/test/solidity/Facets/CircleBridgeFacet.t.sol @@ -10,9 +10,10 @@ import { ITokenMessenger } from "lifi/Interfaces/ITokenMessenger.sol"; // Stub CircleBridgeFacet Contract contract TestCircleBridgeFacet is CircleBridgeFacet { - constructor(ITokenMessenger _xDaiBridge, address _usdc) - CircleBridgeFacet(_xDaiBridge, _usdc) - {} + constructor( + ITokenMessenger _xDaiBridge, + address _usdc + ) CircleBridgeFacet(_xDaiBridge, _usdc) {} function addDex(address _dex) external { LibAllowList.addAllowedContract(_dex); @@ -43,8 +44,8 @@ contract CircleBridgeFacetTest is TestBaseFacet { initTestBase(); - defaultDAIAmount = 5 * 10**dai.decimals(); - defaultUSDCAmount = 5 * 10**usdc.decimals(); + defaultDAIAmount = 5 * 10 ** dai.decimals(); + defaultUSDCAmount = 5 * 10 ** usdc.decimals(); circleBridgeFacet = new TestCircleBridgeFacet( ITokenMessenger(TOKEN_MESSENGER), @@ -91,23 +92,16 @@ contract CircleBridgeFacetTest is TestBaseFacet { circleBridgeData = CircleBridgeFacet.CircleBridgeData(DST_DOMAIN); } - function initiateBridgeTxWithFacet(bool isNative) internal override { - if (isNative) { - circleBridgeFacet.startBridgeTokensViaCircleBridge{ - value: bridgeData.minAmount - }(bridgeData, circleBridgeData); - } else { - circleBridgeFacet.startBridgeTokensViaCircleBridge( - bridgeData, - circleBridgeData - ); - } + function initiateBridgeTxWithFacet(bool) internal override { + circleBridgeFacet.startBridgeTokensViaCircleBridge( + bridgeData, + circleBridgeData + ); } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { circleBridgeFacet.swapAndStartBridgeTokensViaCircleBridge{ value: swapData[0].fromAmount diff --git a/test/solidity/Facets/DeBridgeFacet.t.sol b/test/solidity/Facets/DeBridgeFacet.t.sol index bd989486c..5dd3826a2 100644 --- a/test/solidity/Facets/DeBridgeFacet.t.sol +++ b/test/solidity/Facets/DeBridgeFacet.t.sol @@ -40,10 +40,9 @@ contract DeBridgeFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { deBridgeFacet.swapAndStartBridgeTokensViaDeBridge{ value: swapData[0].fromAmount + addToMessageValue @@ -101,10 +100,9 @@ contract DeBridgeFacetTest is TestBaseFacet { uint256 nativeFee = addToMessageValue = chainConfig.fixedNativeFee == 0 ? IDeBridgeGate(DEBRIDGE_GATE).globalFixedNativeFee() : chainConfig.fixedNativeFee; - uint256 executionFee = 1 * 10**usdc.decimals(); + uint256 executionFee = 1 * 10 ** usdc.decimals(); deBridgeData = DeBridgeFacet.DeBridgeData( - "", nativeFee, false, 0, @@ -117,6 +115,17 @@ contract DeBridgeFacetTest is TestBaseFacet { ); } + function test_Revert_BridgeWithInvalidAmount() public { + vm.startPrank(USER_SENDER); + + deBridgeData.nativeFee--; + + vm.expectRevert(); + + initiateBridgeTxWithFacet(false); + vm.stopPrank(); + } + function testBase_CanBridgeTokens_fuzzed(uint256 amount) public override { // amount should be greater than execution fee vm.assume(amount > 1); diff --git a/test/solidity/Facets/GenericSwapFacet.t.sol b/test/solidity/Facets/GenericSwapFacet.t.sol index c9d4bf818..b6a5f8096 100644 --- a/test/solidity/Facets/GenericSwapFacet.t.sol +++ b/test/solidity/Facets/GenericSwapFacet.t.sol @@ -23,7 +23,6 @@ contract TestGenericSwapFacet is GenericSwapFacet { } contract GenericSwapFacetTest is DSTest, DiamondTest { - event LiFiGenericSwapCompleted( bytes32 indexed transactionId, string integrator, @@ -89,14 +88,17 @@ contract GenericSwapFacetTest is DSTest, DiamondTest { function testCanSwapERC20() public { vm.startPrank(USDC_HOLDER); - usdc.approve(address(genericSwapFacet), 10_000 * 10**usdc.decimals()); + usdc.approve( + address(genericSwapFacet), + 10_000 * 10 ** usdc.decimals() + ); // Swap USDC to DAI address[] memory path = new address[](2); path[0] = USDC_ADDRESS; path[1] = DAI_ADDRESS; - uint256 amountOut = 10 * 10**dai.decimals(); + uint256 amountOut = 10 * 10 ** dai.decimals(); // Calculate DAI amount uint256[] memory amounts = uniswap.getAmountsIn(amountOut, path); diff --git a/test/solidity/Facets/GnosisBridgeFacet.t.sol b/test/solidity/Facets/GnosisBridgeFacet.t.sol index 34c87e561..6c53aa8bf 100644 --- a/test/solidity/Facets/GnosisBridgeFacet.t.sol +++ b/test/solidity/Facets/GnosisBridgeFacet.t.sol @@ -108,20 +108,13 @@ contract GnosisBridgeFacetTest is TestBaseFacet { ); } - function initiateBridgeTxWithFacet(bool isNative) internal override { - if (isNative) { - gnosisBridgeFacet.startBridgeTokensViaXDaiBridge{ - value: bridgeData.minAmount - }(bridgeData); - } else { - gnosisBridgeFacet.startBridgeTokensViaXDaiBridge(bridgeData); - } + function initiateBridgeTxWithFacet(bool) internal override { + gnosisBridgeFacet.startBridgeTokensViaXDaiBridge(bridgeData); } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { gnosisBridgeFacet.swapAndStartBridgeTokensViaXDaiBridge{ value: swapData[0].fromAmount @@ -166,7 +159,10 @@ contract GnosisBridgeFacetTest is TestBaseFacet { function testBase_CanSwapAndBridgeTokens() public override { vm.startPrank(USER_SENDER); - usdc.approve(address(gnosisBridgeFacet), 10_000 * 10**usdc.decimals()); + usdc.approve( + address(gnosisBridgeFacet), + 10_000 * 10 ** usdc.decimals() + ); setDefaultSwapData(); bridgeData.hasSourceSwaps = true; @@ -218,7 +214,7 @@ contract GnosisBridgeFacetTest is TestBaseFacet { vm.startPrank(USER_SENDER); vm.assume(amount > 0 && amount < 100_000); - amount = amount * 10**dai.decimals(); + amount = amount * 10 ** dai.decimals(); // approval dai.approve(address(gnosisBridgeFacet), amount); diff --git a/test/solidity/Facets/GnosisBridgeL2Facet.t.sol b/test/solidity/Facets/GnosisBridgeL2Facet.t.sol index 684924c37..114201c0a 100644 --- a/test/solidity/Facets/GnosisBridgeL2Facet.t.sol +++ b/test/solidity/Facets/GnosisBridgeL2Facet.t.sol @@ -124,10 +124,9 @@ contract GnosisBridgeL2FacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { gnosisBridgeL2Facet.swapAndStartBridgeTokensViaXDaiBridge{ value: swapData[0].fromAmount @@ -172,7 +171,10 @@ contract GnosisBridgeL2FacetTest is TestBaseFacet { function testBase_CanSwapAndBridgeTokens() public override { vm.startPrank(USER_SENDER); - usdc.approve(address(gnosisBridgeL2Facet), 10_000 * 10**usdc.decimals()); + usdc.approve( + address(gnosisBridgeL2Facet), + 10_000 * 10 ** usdc.decimals() + ); setDefaultSwapData(); bridgeData.hasSourceSwaps = true; diff --git a/test/solidity/Facets/GravityFacet.t.sol b/test/solidity/Facets/GravityFacet.t.sol index e3becef22..a5b957385 100644 --- a/test/solidity/Facets/GravityFacet.t.sol +++ b/test/solidity/Facets/GravityFacet.t.sol @@ -75,10 +75,9 @@ contract GravityFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { revert NativeAssetNotSupported(); } else { diff --git a/test/solidity/Facets/HopFacet.t.sol b/test/solidity/Facets/HopFacet.t.sol index 67acebe35..4868a6f48 100644 --- a/test/solidity/Facets/HopFacet.t.sol +++ b/test/solidity/Facets/HopFacet.t.sol @@ -102,10 +102,9 @@ contract HopFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { hopFacet.swapAndStartBridgeTokensViaHop{ value: swapData[0].fromAmount diff --git a/test/solidity/Facets/HopFacetOptimizedL1.t.sol b/test/solidity/Facets/HopFacetOptimizedL1.t.sol index 2170b5446..e7119ffb8 100644 --- a/test/solidity/Facets/HopFacetOptimizedL1.t.sol +++ b/test/solidity/Facets/HopFacetOptimizedL1.t.sol @@ -111,10 +111,9 @@ contract HopFacetOptimizedL1Test is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative || bridgeData.sendingAssetId == address(0)) { validHopData.hopBridge = IHopBridge(NATIVE_BRIDGE); hopFacet.swapAndStartBridgeTokensViaHopL1Native{ @@ -165,6 +164,7 @@ contract HopFacetOptimizedL1Test is TestBaseFacet { function testBase_Revert_BridgeWithInvalidDestinationCallFlag() public + view override { console.log("Not applicable for HopFacetOptimized"); @@ -172,6 +172,7 @@ contract HopFacetOptimizedL1Test is TestBaseFacet { function testBase_Revert_CallBridgeOnlyFunctionWithSourceSwapFlag() public + view override { console.log("Not applicable for HopFacetOptimized"); diff --git a/test/solidity/Facets/HopFacetOptimizedL2.t.sol b/test/solidity/Facets/HopFacetOptimizedL2.t.sol index 1e071f837..9a4c078c6 100644 --- a/test/solidity/Facets/HopFacetOptimizedL2.t.sol +++ b/test/solidity/Facets/HopFacetOptimizedL2.t.sol @@ -120,10 +120,9 @@ contract HopFacetOptimizedL2Test is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { validHopData.bonderFee = (bridgeData.minAmount * 1) / 100; if (isNative || bridgeData.sendingAssetId == address(0)) { validHopData.hopBridge = IHopBridge(NATIVE_BRIDGE); @@ -176,6 +175,7 @@ contract HopFacetOptimizedL2Test is TestBaseFacet { function testBase_Revert_BridgeWithInvalidDestinationCallFlag() public + view override { console.log("Not applicable for HopFacetOptimized"); @@ -183,6 +183,7 @@ contract HopFacetOptimizedL2Test is TestBaseFacet { function testBase_Revert_CallBridgeOnlyFunctionWithSourceSwapFlag() public + view override { console.log("Not applicable for HopFacetOptimized"); diff --git a/test/solidity/Facets/HopFacetPacked.t.sol b/test/solidity/Facets/HopFacetPacked.t.sol index d1fa57166..33bb99c9d 100644 --- a/test/solidity/Facets/HopFacetPacked.t.sol +++ b/test/solidity/Facets/HopFacetPacked.t.sol @@ -11,8 +11,14 @@ import { DiamondTest, LiFiDiamond } from "../utils/DiamondTest.sol"; import { console } from "../utils/Console.sol"; contract CallForwarder { - function callDiamond(uint256 nativeAmount, address contractAddress, bytes calldata callData) external payable { - (bool success, ) = contractAddress.call{value: nativeAmount}(callData); + function callDiamond( + uint256 nativeAmount, + address contractAddress, + bytes calldata callData + ) external payable { + (bool success, ) = contractAddress.call{ value: nativeAmount }( + callData + ); if (!success) { revert(); } @@ -73,25 +79,46 @@ contract HopFacetPackedTest is Test, DiamondTest { callForwarder = new CallForwarder(); bytes4[] memory functionSelectors = new bytes4[](6); - functionSelectors[0] = hopFacetPacked.startBridgeTokensViaHopL2NativePacked.selector; - functionSelectors[1] = hopFacetPacked.startBridgeTokensViaHopL2NativeMin.selector; - functionSelectors[2] = hopFacetPacked.encoder_startBridgeTokensViaHopL2NativePacked.selector; - functionSelectors[3] = hopFacetPacked.startBridgeTokensViaHopL2ERC20Packed.selector; - functionSelectors[4] = hopFacetPacked.startBridgeTokensViaHopL2ERC20Min.selector; - functionSelectors[5] = hopFacetPacked.encoder_startBridgeTokensViaHopL2ERC20Packed.selector; + functionSelectors[0] = hopFacetPacked + .startBridgeTokensViaHopL2NativePacked + .selector; + functionSelectors[1] = hopFacetPacked + .startBridgeTokensViaHopL2NativeMin + .selector; + functionSelectors[2] = hopFacetPacked + .encoder_startBridgeTokensViaHopL2NativePacked + .selector; + functionSelectors[3] = hopFacetPacked + .startBridgeTokensViaHopL2ERC20Packed + .selector; + functionSelectors[4] = hopFacetPacked + .startBridgeTokensViaHopL2ERC20Min + .selector; + functionSelectors[5] = hopFacetPacked + .encoder_startBridgeTokensViaHopL2ERC20Packed + .selector; addFacet(diamond, address(hopFacetPacked), functionSelectors); hopFacetPacked = HopFacetPacked(address(diamond)); - /// Perpare HopFacetOptimized & Approval hopFacetOptimized = new HopFacetOptimized(); bytes4[] memory functionSelectorsApproval = new bytes4[](3); - functionSelectorsApproval[0] = hopFacetOptimized.setApprovalForBridges.selector; - functionSelectorsApproval[1] = hopFacetOptimized.startBridgeTokensViaHopL2Native.selector; - functionSelectorsApproval[2] = hopFacetOptimized.startBridgeTokensViaHopL2ERC20.selector; - - addFacet(diamond, address(hopFacetOptimized), functionSelectorsApproval); + functionSelectorsApproval[0] = hopFacetOptimized + .setApprovalForBridges + .selector; + functionSelectorsApproval[1] = hopFacetOptimized + .startBridgeTokensViaHopL2Native + .selector; + functionSelectorsApproval[2] = hopFacetOptimized + .startBridgeTokensViaHopL2ERC20 + .selector; + + addFacet( + diamond, + address(hopFacetOptimized), + functionSelectorsApproval + ); hopFacetOptimized = HopFacetOptimized(address(diamond)); address[] memory bridges = new address[](1); @@ -100,15 +127,14 @@ contract HopFacetPackedTest is Test, DiamondTest { tokens[0] = USDC_ADDRESS; hopFacetOptimized.setApprovalForBridges(bridges, tokens); - /// Perpare parameters transactionId = "someID"; integrator = "demo-partner"; // Native params - amountNative = 1 * 10**18; - amountBonderFeeNative = amountNative / 100 * 1; - amountOutMinNative = amountNative / 100 * 99; + amountNative = 1 * 10 ** 18; + amountBonderFeeNative = (amountNative / 100) * 1; + amountOutMinNative = (amountNative / 100) * 99; bytes memory packedNativeParams = bytes.concat( bytes8(transactionId), // transactionId @@ -126,9 +152,9 @@ contract HopFacetPackedTest is Test, DiamondTest { ); // USDC params - amountUSDC = 100 * 10**usdc.decimals(); - amountBonderFeeUSDC = amountUSDC / 100 * 1; - amountOutMinUSDC = amountUSDC / 100 * 99; + amountUSDC = 100 * 10 ** usdc.decimals(); + amountBonderFeeUSDC = (amountUSDC / 100) * 1; + amountOutMinUSDC = (amountUSDC / 100) * 99; bytes memory packedUSDCParams = bytes.concat( bytes8(transactionId), // transactionId @@ -195,7 +221,9 @@ contract HopFacetPackedTest is Test, DiamondTest { function testStartBridgeTokensViaHopL2NativePacked() public { vm.startPrank(WHALE); - (bool success, ) = address(diamond).call{value: amountNative}(packedNative); + (bool success, ) = address(diamond).call{ value: amountNative }( + packedNative + ); if (!success) { revert(); } @@ -204,13 +232,19 @@ contract HopFacetPackedTest is Test, DiamondTest { function testStartBridgeTokensViaHopL2NativePackedForwarded() public { vm.startPrank(WHALE); - callForwarder.callDiamond{value: 2 * amountNative}(amountNative, address(diamond), packedNative); + callForwarder.callDiamond{ value: 2 * amountNative }( + amountNative, + address(diamond), + packedNative + ); vm.stopPrank(); } function testStartBridgeTokensViaHopL2NativeMin() public { vm.startPrank(WHALE); - hopFacetPacked.startBridgeTokensViaHopL2NativeMin{value: amountNative}( + hopFacetPacked.startBridgeTokensViaHopL2NativeMin{ + value: amountNative + }( transactionId, integrator, RECEIVER, @@ -253,10 +287,9 @@ contract HopFacetPackedTest is Test, DiamondTest { function testStartBridgeTokensViaHopL2Native() public { vm.startPrank(WHALE); - hopFacetOptimized.startBridgeTokensViaHopL2Native{value: amountNative}( - bridgeDataNative, - hopDataNative - ); + hopFacetOptimized.startBridgeTokensViaHopL2Native{ + value: amountNative + }(bridgeDataNative, hopDataNative); vm.stopPrank(); } diff --git a/test/solidity/Facets/HyphenFacet.t.sol b/test/solidity/Facets/HyphenFacet.t.sol index b4ad418cd..c49fdcc5d 100644 --- a/test/solidity/Facets/HyphenFacet.t.sol +++ b/test/solidity/Facets/HyphenFacet.t.sol @@ -68,10 +68,9 @@ contract HyphenFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { hyphenFacet.swapAndStartBridgeTokensViaHyphen{ value: swapData[0].fromAmount diff --git a/test/solidity/Facets/LIFuelFacet.t.sol b/test/solidity/Facets/LIFuelFacet.t.sol index 07fc94ae7..25781bf1e 100644 --- a/test/solidity/Facets/LIFuelFacet.t.sol +++ b/test/solidity/Facets/LIFuelFacet.t.sol @@ -20,7 +20,6 @@ contract TestLIFuelFacet is LIFuelFacet { } contract LIFuelFacetTest is TestBaseFacet { - TestLIFuelFacet internal lifuelFacet; ILiFi.BridgeData internal validBridgeData; @@ -28,13 +27,13 @@ contract LIFuelFacetTest is TestBaseFacet { initTestBase(); lifuelFacet = new TestLIFuelFacet(); - ServiceFeeCollector feeCollector = new ServiceFeeCollector(address(this)); + ServiceFeeCollector feeCollector = new ServiceFeeCollector( + address(this) + ); PeripheryRegistryFacet peripheryRegistry = new PeripheryRegistryFacet(); bytes4[] memory functionSelectors = new bytes4[](4); - functionSelectors[0] = lifuelFacet - .startBridgeTokensViaLIFuel - .selector; + functionSelectors[0] = lifuelFacet.startBridgeTokensViaLIFuel.selector; functionSelectors[1] = lifuelFacet .swapAndStartBridgeTokensViaLIFuel .selector; @@ -49,8 +48,12 @@ contract LIFuelFacetTest is TestBaseFacet { .selector; addFacet(diamond, address(lifuelFacet), functionSelectors); - addFacet(diamond, address(peripheryRegistry), peripheryRegistryFunctionSelectors); - + addFacet( + diamond, + address(peripheryRegistry), + peripheryRegistryFunctionSelectors + ); + lifuelFacet = TestLIFuelFacet(address(diamond)); peripheryRegistry = PeripheryRegistryFacet(address(diamond)); @@ -62,8 +65,10 @@ contract LIFuelFacetTest is TestBaseFacet { uniswap.swapTokensForExactETH.selector ); - - peripheryRegistry.registerPeripheryContract("ServiceFeeCollector", address(feeCollector)); + peripheryRegistry.registerPeripheryContract( + "ServiceFeeCollector", + address(feeCollector) + ); setFacetAddressInTestBase(address(lifuelFacet), "LIFuelFacet"); vm.makePersistent(address(lifuelFacet)); @@ -84,10 +89,9 @@ contract LIFuelFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { lifuelFacet.swapAndStartBridgeTokensViaLIFuel{ value: swapData[0].fromAmount @@ -101,10 +105,10 @@ contract LIFuelFacetTest is TestBaseFacet { } function testBase_Revert_BridgeWithInvalidDestinationCallFlag() - public - override + public + view + override { console.log("Not applicable for LIFuelFacet"); } - } diff --git a/test/solidity/Facets/MakerTeleportFacet.t.sol b/test/solidity/Facets/MakerTeleportFacet.t.sol index 420ea7c9d..7d7660eda 100644 --- a/test/solidity/Facets/MakerTeleportFacet.t.sol +++ b/test/solidity/Facets/MakerTeleportFacet.t.sol @@ -24,11 +24,13 @@ contract TestMakerTeleportFacet is MakerTeleportFacet { } contract MockArbSys { - function sendTxToL1(address _destination, bytes calldata _callDataForL1) - external - returns (uint256) - { + function sendTxToL1( + address _destination, + bytes calldata _callDataForL1 + ) external view returns (uint256) { console.log("sendTxToL1 called"); + console.logAddress(_destination); + console.logBytes(_callDataForL1); return 1; } } @@ -137,20 +139,13 @@ contract MakerTeleportFacetTest is TestBaseFacet { ); } - function initiateBridgeTxWithFacet(bool isNative) internal override { - if (isNative) { - makerTeleportFacet.startBridgeTokensViaMakerTeleport{ - value: bridgeData.minAmount - }(bridgeData); - } else { - makerTeleportFacet.startBridgeTokensViaMakerTeleport(bridgeData); - } + function initiateBridgeTxWithFacet(bool) internal override { + makerTeleportFacet.startBridgeTokensViaMakerTeleport(bridgeData); } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { makerTeleportFacet.swapAndStartBridgeTokensViaMakerTeleport{ value: swapData[0].fromAmount @@ -190,7 +185,7 @@ contract MakerTeleportFacetTest is TestBaseFacet { usdc.approve( address(makerTeleportFacet), - 10_000 * 10**usdc.decimals() + 10_000 * 10 ** usdc.decimals() ); setDefaultSwapData(); @@ -205,7 +200,7 @@ contract MakerTeleportFacetTest is TestBaseFacet { vm.startPrank(USER_SENDER); vm.assume(amount > 0 && amount < 100_000); - amount = amount * 10**dai.decimals(); + amount = amount * 10 ** dai.decimals(); // approval dai.approve(address(makerTeleportFacet), amount); diff --git a/test/solidity/Facets/MultiChainFacet.t.sol b/test/solidity/Facets/MultiChainFacet.t.sol index e52566a42..8f1368102 100644 --- a/test/solidity/Facets/MultiChainFacet.t.sol +++ b/test/solidity/Facets/MultiChainFacet.t.sol @@ -161,10 +161,9 @@ contract MultichainFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { multichainFacet.swapAndStartBridgeTokensViaMultichain{ value: swapData[0].fromAmount @@ -200,7 +199,7 @@ contract MultichainFacetTest is TestBaseFacet { // token contract itself (instead of going through a router contract) ERC20 testToken3 = ERC20(0x55aF5865807b196bD0197e0902746F31FBcCFa58); // BOO token address testToken3Whale = 0x27F82c89b5380Da1A39A8f4F2b56145256A98D34; - uint256 amountToBeBridged = 10_000 * 10**testToken3.decimals(); + uint256 amountToBeBridged = 10_000 * 10 ** testToken3.decimals(); vm.startPrank(testToken3Whale); testToken3.approve(address(multichainFacet), amountToBeBridged); @@ -263,7 +262,7 @@ contract MultichainFacetTest is TestBaseFacet { vm.startPrank(USER_SENDER); vm.assume(amount > 0 && amount < 100_000); - amount = amount * 10**testToken.decimals(); + amount = amount * 10 ** testToken.decimals(); // approval underlyingToken.approve(address(multichainFacet), amount); diff --git a/test/solidity/Facets/NXTPFacet.t.sol b/test/solidity/Facets/NXTPFacet.t.sol index 497b3cbec..06fe56b3d 100644 --- a/test/solidity/Facets/NXTPFacet.t.sol +++ b/test/solidity/Facets/NXTPFacet.t.sol @@ -71,8 +71,8 @@ contract NXTPFacetTest is TestBaseFacet { bridgeData.bridge = "connext"; // prepare valid NXTP data - ITransactionManager.InvariantTransactionData memory txData = ITransactionManager - .InvariantTransactionData({ + ITransactionManager.InvariantTransactionData + memory txData = ITransactionManager.InvariantTransactionData({ receivingChainTxManagerAddress: TRANSACTION_MANAGER_POLYGON, user: USER_SENDER, router: ROUTER_ETH, @@ -109,10 +109,9 @@ contract NXTPFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { nxtpFacet.swapAndStartBridgeTokensViaNXTP{ value: swapData[0].fromAmount diff --git a/test/solidity/Facets/OmniBridgeFacet.t.sol b/test/solidity/Facets/OmniBridgeFacet.t.sol index c066957ef..efbc64def 100644 --- a/test/solidity/Facets/OmniBridgeFacet.t.sol +++ b/test/solidity/Facets/OmniBridgeFacet.t.sol @@ -7,9 +7,10 @@ import { IOmniBridge } from "lifi/Interfaces/IOmniBridge.sol"; // Stub OmniBridgeFacet Contract contract TestOmniBridgeFacet is OmniBridgeFacet { - constructor(IOmniBridge _foreignOmniBridge, IOmniBridge _wethOmniBridge) - OmniBridgeFacet(_foreignOmniBridge, _wethOmniBridge) - {} + constructor( + IOmniBridge _foreignOmniBridge, + IOmniBridge _wethOmniBridge + ) OmniBridgeFacet(_foreignOmniBridge, _wethOmniBridge) {} function addDex(address _dex) external { LibAllowList.addAllowedContract(_dex); @@ -81,10 +82,9 @@ contract OmniBridgeFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { omniBridgeFacet.swapAndStartBridgeTokensViaOmniBridge{ value: swapData[0].fromAmount diff --git a/test/solidity/Facets/OmniBridgeL2Facet.t.sol b/test/solidity/Facets/OmniBridgeL2Facet.t.sol index da8add012..a601159e9 100644 --- a/test/solidity/Facets/OmniBridgeL2Facet.t.sol +++ b/test/solidity/Facets/OmniBridgeL2Facet.t.sol @@ -7,9 +7,10 @@ import { IOmniBridge } from "lifi/Interfaces/IOmniBridge.sol"; // Stub OmniBridgeFacet Contract contract TestOmniBridgeFacet is OmniBridgeFacet { - constructor(IOmniBridge _foreignOmniBridge, IOmniBridge _wethOmniBridge) - OmniBridgeFacet(_foreignOmniBridge, _wethOmniBridge) - {} + constructor( + IOmniBridge _foreignOmniBridge, + IOmniBridge _wethOmniBridge + ) OmniBridgeFacet(_foreignOmniBridge, _wethOmniBridge) {} function addDex(address _dex) external { LibAllowList.addAllowedContract(_dex); @@ -89,10 +90,9 @@ contract OmniBridgeL2FacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { omniBridgeFacet.swapAndStartBridgeTokensViaOmniBridge{ value: swapData[0].fromAmount diff --git a/test/solidity/Facets/OptimismBridgeFacet.t.sol b/test/solidity/Facets/OptimismBridgeFacet.t.sol index 980035bab..9eb79808e 100644 --- a/test/solidity/Facets/OptimismBridgeFacet.t.sol +++ b/test/solidity/Facets/OptimismBridgeFacet.t.sol @@ -111,7 +111,7 @@ contract OptimismBridgeFacetTest is DSTest, DiamondTest { referrer: address(0), sendingAssetId: DAI_L1_ADDRESS, receiver: DAI_L1_HOLDER, - minAmount: 10 * 10**dai.decimals(), + minAmount: 10 * 10 ** dai.decimals(), destinationChainId: DSTCHAIN_ID, hasSourceSwaps: false, hasDestinationCall: false @@ -126,7 +126,10 @@ contract OptimismBridgeFacetTest is DSTest, DiamondTest { function testRevertToBridgeTokensWhenSendingAmountIsZero() public { vm.startPrank(DAI_L1_HOLDER); - dai.approve(address(optimismBridgeFacet), 10_000 * 10**dai.decimals()); + dai.approve( + address(optimismBridgeFacet), + 10_000 * 10 ** dai.decimals() + ); ILiFi.BridgeData memory bridgeData = validBridgeData; bridgeData.minAmount = 0; @@ -143,7 +146,10 @@ contract OptimismBridgeFacetTest is DSTest, DiamondTest { function testRevertToBridgeTokensWhenReceiverIsZeroAddress() public { vm.startPrank(DAI_L1_HOLDER); - dai.approve(address(optimismBridgeFacet), 10_000 * 10**dai.decimals()); + dai.approve( + address(optimismBridgeFacet), + 10_000 * 10 ** dai.decimals() + ); ILiFi.BridgeData memory bridgeData = validBridgeData; bridgeData.receiver = address(0); @@ -160,14 +166,17 @@ contract OptimismBridgeFacetTest is DSTest, DiamondTest { function testRevertToBridgeTokensWhenSenderHasNoEnoughAmount() public { vm.startPrank(DAI_L1_HOLDER); - dai.approve(address(optimismBridgeFacet), 10_000 * 10**dai.decimals()); + dai.approve( + address(optimismBridgeFacet), + 10_000 * 10 ** dai.decimals() + ); dai.transfer(USDC_HOLDER, dai.balanceOf(DAI_L1_HOLDER)); vm.expectRevert( abi.encodeWithSelector( InsufficientBalance.selector, - 10 * 10**dai.decimals(), + 10 * 10 ** dai.decimals(), 0 ) ); @@ -198,7 +207,10 @@ contract OptimismBridgeFacetTest is DSTest, DiamondTest { function testRevertToBridgeTokensWhenInformationMismatch() public { vm.startPrank(DAI_L1_HOLDER); - dai.approve(address(optimismBridgeFacet), 10_000 * 10**dai.decimals()); + dai.approve( + address(optimismBridgeFacet), + 10_000 * 10 ** dai.decimals() + ); ILiFi.BridgeData memory bridgeData = validBridgeData; bridgeData.hasSourceSwaps = true; @@ -214,7 +226,10 @@ contract OptimismBridgeFacetTest is DSTest, DiamondTest { function testCanBridgeERC20Tokens() public { vm.startPrank(DAI_L1_HOLDER); - dai.approve(address(optimismBridgeFacet), 10_000 * 10**dai.decimals()); + dai.approve( + address(optimismBridgeFacet), + 10_000 * 10 ** dai.decimals() + ); optimismBridgeFacet.startBridgeTokensViaOptimismBridge( validBridgeData, @@ -228,7 +243,7 @@ contract OptimismBridgeFacetTest is DSTest, DiamondTest { usdc.approve( address(optimismBridgeFacet), - 10_000 * 10**usdc.decimals() + 10_000 * 10 ** usdc.decimals() ); // Swap USDC to DAI @@ -236,7 +251,7 @@ contract OptimismBridgeFacetTest is DSTest, DiamondTest { path[0] = USDC_ADDRESS; path[1] = DAI_L1_ADDRESS; - uint256 amountOut = 1000 * 10**dai.decimals(); + uint256 amountOut = 1000 * 10 ** dai.decimals(); // Calculate DAI amount uint256[] memory amounts = uniswap.getAmountsIn(amountOut, path); diff --git a/test/solidity/Facets/PolygonBridgeFacet.t.sol b/test/solidity/Facets/PolygonBridgeFacet.t.sol index 3cdc193be..1d1d9ac3c 100644 --- a/test/solidity/Facets/PolygonBridgeFacet.t.sol +++ b/test/solidity/Facets/PolygonBridgeFacet.t.sol @@ -7,9 +7,10 @@ import { IRootChainManager } from "lifi/Interfaces/IRootChainManager.sol"; // Stub PolygonBridgeFacet Contract contract TestPolygonBridgeFacet is PolygonBridgeFacet { - constructor(IRootChainManager _rootChainManager, address _erc20Predicate) - PolygonBridgeFacet(_rootChainManager, _erc20Predicate) - {} + constructor( + IRootChainManager _rootChainManager, + address _erc20Predicate + ) PolygonBridgeFacet(_rootChainManager, _erc20Predicate) {} function addDex(address _dex) external { LibAllowList.addAllowedContract(_dex); @@ -81,10 +82,9 @@ contract PolygonBridgeFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { polygonBridgeFacet.swapAndStartBridgeTokensViaPolygonBridge{ value: swapData[0].fromAmount diff --git a/test/solidity/Facets/RoninBridgeFacet.t.sol b/test/solidity/Facets/RoninBridgeFacet.t.sol index 6c98c2fba..0a20c54e4 100644 --- a/test/solidity/Facets/RoninBridgeFacet.t.sol +++ b/test/solidity/Facets/RoninBridgeFacet.t.sol @@ -80,10 +80,9 @@ contract RoninBridgeFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { roninBridgeFacet.swapAndStartBridgeTokensViaRoninBridge{ value: swapData[0].fromAmount diff --git a/test/solidity/Facets/SquidFacet.t.sol b/test/solidity/Facets/SquidFacet.t.sol index b15bb2140..82dfcaa45 100644 --- a/test/solidity/Facets/SquidFacet.t.sol +++ b/test/solidity/Facets/SquidFacet.t.sol @@ -81,7 +81,7 @@ contract SquidFacetTest is TestBaseFacet { } function initiateBridgeTxWithFacet(bool isNative) internal override { - if (bridgeData.sendingAssetId == address(0)) { + if (isNative) { SquidFacet.SquidData memory squidData = setNativeBridgeSquidData(); squidFacet.startBridgeTokensViaSquid{ @@ -92,11 +92,10 @@ contract SquidFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { - if (bridgeData.sendingAssetId == address(0)) { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { + if (isNative) { SquidFacet.SquidData memory squidData = setNativeBridgeSquidData(); squidFacet.swapAndStartBridgeTokensViaSquid{ @@ -116,34 +115,17 @@ contract SquidFacetTest is TestBaseFacet { super.testBase_CanBridgeTokens_fuzzed(amount); } - function testBase_CanBridgeNativeTokens() - public - override - assertBalanceChange( - address(0), - USER_SENDER, - -int256((1 ether + addToMessageValue)) - ) - assertBalanceChange(address(0), USER_RECEIVER, 0) - assertBalanceChange(ADDRESS_USDC, USER_SENDER, 0) - assertBalanceChange(ADDRESS_DAI, USER_SENDER, 0) - { - vm.startPrank(USER_SENDER); - // customize bridgeData - bridgeData.sendingAssetId = address(0); - bridgeData.minAmount = 1 ether; - bridgeData.hasSourceSwaps = true; - - //prepare check for events - vm.expectEmit(true, true, true, true, _facetTestContractAddress); - emit LiFiTransferStarted(bridgeData); - - initiateBridgeTxWithFacet(true); - vm.stopPrank(); + function testBase_CanBridgeNativeTokens() public override { + // facet does not support native bridging + } + + function testBase_CanSwapAndBridgeNativeTokens() public override { + // facet does not support native bridging } function setNativeBridgeSquidData() internal + view returns (SquidFacet.SquidData memory) { SquidFacet.SquidData memory squidData = validSquidData; @@ -159,8 +141,6 @@ contract SquidFacetTest is TestBaseFacet { .callData = hex"7ff36ab500000000000000000000000000000000000000000000000000000000093aa1390000000000000000000000000000000000000000000000000000000000000080000000000000000000000000ce16f69375520ab01377ce7b88f5ba8c48f8d66600000000000000000000000000000000000000000000000000000186b6a684d00000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"; sourceCalls[0].payload = ""; - ISquidMulticall.Call[] memory destinationCalls; - squidData.routeType = SquidFacet.RouteType.CallBridge; squidData.destinationChain = "Polygon"; squidData.bridgedTokenSymbol = "USDC"; diff --git a/test/solidity/Facets/StargateFacet.t.sol b/test/solidity/Facets/StargateFacet.t.sol index 9317b6b77..09d6bef54 100644 --- a/test/solidity/Facets/StargateFacet.t.sol +++ b/test/solidity/Facets/StargateFacet.t.sol @@ -6,6 +6,7 @@ import { OnlyContractOwner, InvalidConfig, AlreadyInitialized } from "src/Errors import { StargateFacet } from "lifi/Facets/StargateFacet.sol"; import { IStargateRouter } from "lifi/Interfaces/IStargateRouter.sol"; import { FeeCollector } from "lifi/Periphery/FeeCollector.sol"; +import { ILiFi } from "lifi/Interfaces/ILiFi.sol"; // Stub CBridgeFacet Contract contract TestStargateFacet is StargateFacet { @@ -127,10 +128,9 @@ contract StargateFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { stargateFacet.swapAndStartBridgeTokensViaStargate{ value: swapData[0].fromAmount + addToMessageValue @@ -165,7 +165,8 @@ contract StargateFacetTest is TestBaseFacet { function test_revert_InitializeAgain() public { vm.startPrank(USER_DIAMOND_OWNER); - StargateFacet.ChainIdConfig[] memory chainIdConfig = new StargateFacet.ChainIdConfig[](2); + StargateFacet.ChainIdConfig[] + memory chainIdConfig = new StargateFacet.ChainIdConfig[](2); chainIdConfig[0] = StargateFacet.ChainIdConfig(1, 101); chainIdConfig[1] = StargateFacet.ChainIdConfig(137, 109); @@ -213,4 +214,42 @@ contract StargateFacetTest is TestBaseFacet { vm.assume(amount > 100); super.testBase_CanBridgeTokens_fuzzed(amount); } + + function test_revert_invalidSrcPool() public { + vm.startPrank(USER_SENDER); + + // approval + usdc.approve(_facetTestContractAddress, bridgeData.minAmount); + + // invalid data + stargateData.srcPoolId = 100; + + vm.expectRevert(); + + stargateFacet.startBridgeTokensViaStargate{ value: addToMessageValue }( + bridgeData, + stargateData + ); + + vm.stopPrank(); + } + + function test_revert_invalidDestPool() public { + vm.startPrank(USER_SENDER); + + // approval + usdc.approve(_facetTestContractAddress, bridgeData.minAmount); + + // invalid data + stargateData.dstPoolId = 100; + + vm.expectRevert(); + + stargateFacet.startBridgeTokensViaStargate{ value: addToMessageValue }( + bridgeData, + stargateData + ); + + vm.stopPrank(); + } } diff --git a/test/solidity/Facets/ThorSwapFacet.t.sol b/test/solidity/Facets/ThorSwapFacet.t.sol index c05401988..5b33bb3de 100644 --- a/test/solidity/Facets/ThorSwapFacet.t.sol +++ b/test/solidity/Facets/ThorSwapFacet.t.sol @@ -66,7 +66,7 @@ contract ThorSwapFacetTest is TestBaseFacet { validThorSwapData = ThorSwapFacet.ThorSwapData( 0xeFa100c7821e68765b074dFF0670ae4F516181ee, "=:BTC.BTC:bc1qr930z62t42mnqy25h2tgcu7knpngjtxld33maa:10808311:t:15", - block.timestamp + 20 minutes + block.timestamp + 60 minutes ); vm.label(THORCHAIN_ROUTER, "THORCHAIN_ROUTER"); @@ -85,10 +85,9 @@ contract ThorSwapFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { thorSwapFacet.swapAndStartBridgeTokensViaThorSwap{ value: swapData[0].fromAmount diff --git a/test/solidity/Facets/WormholeFacet.t.sol b/test/solidity/Facets/WormholeFacet.t.sol index 2495ffdfc..f7598fbec 100644 --- a/test/solidity/Facets/WormholeFacet.t.sol +++ b/test/solidity/Facets/WormholeFacet.t.sol @@ -105,10 +105,9 @@ contract WormholeFacetTest is TestBaseFacet { } } - function initiateSwapAndBridgeTxWithFacet(bool isNative) - internal - override - { + function initiateSwapAndBridgeTxWithFacet( + bool isNative + ) internal override { if (isNative) { wormholeFacet.swapAndStartBridgeTokensViaWormhole{ value: swapData[0].fromAmount diff --git a/test/solidity/Gas/CBridgeFacetPackedARB.gas.t.sol b/test/solidity/Gas/CBridgeFacetPackedARB.gas.t.sol index f5495e7c8..0742ce027 100644 --- a/test/solidity/Gas/CBridgeFacetPackedARB.gas.t.sol +++ b/test/solidity/Gas/CBridgeFacetPackedARB.gas.t.sol @@ -53,12 +53,24 @@ contract CBridgeGasTest is Test, DiamondTest { usdc = ERC20(USDC_ADDRESS); bytes4[] memory functionSelectors = new bytes4[](6); - functionSelectors[0] = cBridgeFacetPacked.startBridgeTokensViaCBridgeNativePacked.selector; - functionSelectors[1] = cBridgeFacetPacked.startBridgeTokensViaCBridgeNativeMin.selector; - functionSelectors[2] = cBridgeFacetPacked.encoder_startBridgeTokensViaCBridgeNativePacked.selector; - functionSelectors[3] = cBridgeFacetPacked.startBridgeTokensViaCBridgeERC20Packed.selector; - functionSelectors[4] = cBridgeFacetPacked.startBridgeTokensViaCBridgeERC20Min.selector; - functionSelectors[5] = cBridgeFacetPacked.encoder_startBridgeTokensViaCBridgeERC20Packed.selector; + functionSelectors[0] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeNativePacked + .selector; + functionSelectors[1] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeNativeMin + .selector; + functionSelectors[2] = cBridgeFacetPacked + .encoder_startBridgeTokensViaCBridgeNativePacked + .selector; + functionSelectors[3] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeERC20Packed + .selector; + functionSelectors[4] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeERC20Min + .selector; + functionSelectors[5] = cBridgeFacetPacked + .encoder_startBridgeTokensViaCBridgeERC20Packed + .selector; addFacet(diamond, address(cBridgeFacetPacked), functionSelectors); cBridgeFacetPacked = CBridgeFacetPacked(address(diamond)); @@ -66,9 +78,15 @@ contract CBridgeGasTest is Test, DiamondTest { /// Perpare Approval HopFacetOptimized hopFacetOptimized = new HopFacetOptimized(); bytes4[] memory functionSelectorsApproval = new bytes4[](1); - functionSelectorsApproval[0] = hopFacetOptimized.setApprovalForBridges.selector; - - addFacet(diamond, address(hopFacetOptimized), functionSelectorsApproval); + functionSelectorsApproval[0] = hopFacetOptimized + .setApprovalForBridges + .selector; + + addFacet( + diamond, + address(hopFacetOptimized), + functionSelectorsApproval + ); hopFacetOptimized = HopFacetOptimized(address(diamond)); address[] memory bridges = new address[](1); @@ -84,7 +102,7 @@ contract CBridgeGasTest is Test, DiamondTest { maxSlippage = 5000; // Native params - amountNative = 1 * 10**18; + amountNative = 1 * 10 ** 18; bytes memory packedNativeParams = bytes.concat( bytes8(transactionId), // transactionId bytes16(bytes(integrator)), // integrator @@ -94,12 +112,14 @@ contract CBridgeGasTest is Test, DiamondTest { bytes4(maxSlippage) // maxSlippage ); packedNative = bytes.concat( - abi.encodeWithSignature("startBridgeTokensViaCBridgeNativePacked()"), + abi.encodeWithSignature( + "startBridgeTokensViaCBridgeNativePacked()" + ), packedNativeParams ); // USDC params - amountUSDC = 100 * 10**usdc.decimals(); + amountUSDC = 100 * 10 ** usdc.decimals(); bytes memory packedUSDCParams = bytes.concat( bytes8(transactionId), // transactionId bytes16(bytes(integrator)), // integrator @@ -111,7 +131,9 @@ contract CBridgeGasTest is Test, DiamondTest { bytes4(maxSlippage) // maxSlippage ); packedUSDC = bytes.concat( - abi.encodeWithSignature("startBridgeTokensViaCBridgeERC20Packed()"), + abi.encodeWithSignature( + "startBridgeTokensViaCBridgeERC20Packed()" + ), packedUSDCParams ); } @@ -119,36 +141,40 @@ contract CBridgeGasTest is Test, DiamondTest { function testCallData() public view { console.logString("startBridgeTokensViaCBridgeNativePacked"); console.logBytes(packedNative); - bytes memory encodedNative = cBridgeFacetPacked.encoder_startBridgeTokensViaCBridgeNativePacked( - transactionId, - integrator, - RECEIVER, - uint64(destinationChainId), - nonce, - maxSlippage - ); + bytes memory encodedNative = cBridgeFacetPacked + .encoder_startBridgeTokensViaCBridgeNativePacked( + transactionId, + integrator, + RECEIVER, + uint64(destinationChainId), + nonce, + maxSlippage + ); console.logString("encodedNative"); console.logBytes(encodedNative); console.logString("startBridgeTokensViaCBridgeERC20Packed"); console.logBytes(packedUSDC); - bytes memory encodedUSDC = cBridgeFacetPacked.encoder_startBridgeTokensViaCBridgeERC20Packed( - transactionId, - integrator, - RECEIVER, - uint64(destinationChainId), - USDC_ADDRESS, - amountUSDC, - nonce, - maxSlippage - ); + bytes memory encodedUSDC = cBridgeFacetPacked + .encoder_startBridgeTokensViaCBridgeERC20Packed( + transactionId, + integrator, + RECEIVER, + uint64(destinationChainId), + USDC_ADDRESS, + amountUSDC, + nonce, + maxSlippage + ); console.logString("encodedUSDC"); console.logBytes(encodedUSDC); } function testStartBridgeTokensViaCBridgeNativePacked() public { vm.startPrank(WHALE); - (bool success, ) = address(diamond).call{value: amountNative}(packedNative); + (bool success, ) = address(diamond).call{ value: amountNative }( + packedNative + ); if (!success) { revert(); } @@ -157,7 +183,9 @@ contract CBridgeGasTest is Test, DiamondTest { function testStartBridgeTokensViaCBridgeNativeMin() public { vm.startPrank(WHALE); - cBridgeFacetPacked.startBridgeTokensViaCBridgeNativeMin{value: amountNative}( + cBridgeFacetPacked.startBridgeTokensViaCBridgeNativeMin{ + value: amountNative + }( transactionId, integrator, RECEIVER, diff --git a/test/solidity/Gas/CBridgeFacetPackedETH.gas.t.sol b/test/solidity/Gas/CBridgeFacetPackedETH.gas.t.sol index 39128ba08..ecb96bd94 100644 --- a/test/solidity/Gas/CBridgeFacetPackedETH.gas.t.sol +++ b/test/solidity/Gas/CBridgeFacetPackedETH.gas.t.sol @@ -62,12 +62,24 @@ contract CBridgeGasTest is Test, DiamondTest { cBridgeFacetPacked = new CBridgeFacetPacked(cbridge); bytes4[] memory functionSelectors = new bytes4[](6); - functionSelectors[0] = cBridgeFacetPacked.startBridgeTokensViaCBridgeNativePacked.selector; - functionSelectors[1] = cBridgeFacetPacked.startBridgeTokensViaCBridgeNativeMin.selector; - functionSelectors[2] = cBridgeFacetPacked.encoder_startBridgeTokensViaCBridgeNativePacked.selector; - functionSelectors[3] = cBridgeFacetPacked.startBridgeTokensViaCBridgeERC20Packed.selector; - functionSelectors[4] = cBridgeFacetPacked.startBridgeTokensViaCBridgeERC20Min.selector; - functionSelectors[5] = cBridgeFacetPacked.encoder_startBridgeTokensViaCBridgeERC20Packed.selector; + functionSelectors[0] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeNativePacked + .selector; + functionSelectors[1] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeNativeMin + .selector; + functionSelectors[2] = cBridgeFacetPacked + .encoder_startBridgeTokensViaCBridgeNativePacked + .selector; + functionSelectors[3] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeERC20Packed + .selector; + functionSelectors[4] = cBridgeFacetPacked + .startBridgeTokensViaCBridgeERC20Min + .selector; + functionSelectors[5] = cBridgeFacetPacked + .encoder_startBridgeTokensViaCBridgeERC20Packed + .selector; addFacet(diamond, address(cBridgeFacetPacked), functionSelectors); cBridgeFacetPacked = CBridgeFacetPacked(address(diamond)); @@ -76,7 +88,9 @@ contract CBridgeGasTest is Test, DiamondTest { cBridgeFacet = new CBridgeFacet(cbridge); bytes4[] memory functionSelectors2 = new bytes4[](1); - functionSelectors2[0] = cBridgeFacet.startBridgeTokensViaCBridge.selector; + functionSelectors2[0] = cBridgeFacet + .startBridgeTokensViaCBridge + .selector; addFacet(diamond, address(cBridgeFacet), functionSelectors2); cBridgeFacet = CBridgeFacet(address(diamond)); @@ -84,9 +98,15 @@ contract CBridgeGasTest is Test, DiamondTest { /// Perpare Approval HopFacetOptimized hopFacetOptimized = new HopFacetOptimized(); bytes4[] memory functionSelectorsApproval = new bytes4[](1); - functionSelectorsApproval[0] = hopFacetOptimized.setApprovalForBridges.selector; - - addFacet(diamond, address(hopFacetOptimized), functionSelectorsApproval); + functionSelectorsApproval[0] = hopFacetOptimized + .setApprovalForBridges + .selector; + + addFacet( + diamond, + address(hopFacetOptimized), + functionSelectorsApproval + ); hopFacetOptimized = HopFacetOptimized(address(diamond)); address[] memory bridges = new address[](1); @@ -102,7 +122,7 @@ contract CBridgeGasTest is Test, DiamondTest { maxSlippage = 5000; // Native params - amountNative = 1 * 10**18; + amountNative = 1 * 10 ** 18; bytes memory packedNativeParams = bytes.concat( bytes8(transactionId), // transactionId bytes16(bytes(integrator)), // integrator @@ -112,12 +132,14 @@ contract CBridgeGasTest is Test, DiamondTest { bytes4(maxSlippage) // maxSlippage ); packedNative = bytes.concat( - abi.encodeWithSignature("startBridgeTokensViaCBridgeNativePacked()"), + abi.encodeWithSignature( + "startBridgeTokensViaCBridgeNativePacked()" + ), packedNativeParams ); // USDC params - amountUSDC = 100 * 10**usdc.decimals(); + amountUSDC = 100 * 10 ** usdc.decimals(); bytes memory packedUSDCParams = bytes.concat( bytes8(transactionId), // transactionId bytes16(bytes(integrator)), // integrator @@ -129,7 +151,9 @@ contract CBridgeGasTest is Test, DiamondTest { bytes4(maxSlippage) // maxSlippage ); packedUSDC = bytes.concat( - abi.encodeWithSignature("startBridgeTokensViaCBridgeERC20Packed()"), + abi.encodeWithSignature( + "startBridgeTokensViaCBridgeERC20Packed()" + ), packedUSDCParams ); @@ -174,36 +198,40 @@ contract CBridgeGasTest is Test, DiamondTest { function testCallData() public view { console.logString("startBridgeTokensViaCBridgeNativePacked"); console.logBytes(packedNative); - bytes memory encodedNative = cBridgeFacetPacked.encoder_startBridgeTokensViaCBridgeNativePacked( - transactionId, - integrator, - RECEIVER, - uint64(destinationChainId), - nonce, - maxSlippage - ); + bytes memory encodedNative = cBridgeFacetPacked + .encoder_startBridgeTokensViaCBridgeNativePacked( + transactionId, + integrator, + RECEIVER, + uint64(destinationChainId), + nonce, + maxSlippage + ); console.logString("encodedNative"); console.logBytes(encodedNative); console.logString("startBridgeTokensViaCBridgeERC20Packed"); console.logBytes(packedUSDC); - bytes memory encodedUSDC = cBridgeFacetPacked.encoder_startBridgeTokensViaCBridgeERC20Packed( - transactionId, - integrator, - RECEIVER, - uint64(destinationChainId), - USDC_ADDRESS, - amountUSDC, - nonce, - maxSlippage - ); + bytes memory encodedUSDC = cBridgeFacetPacked + .encoder_startBridgeTokensViaCBridgeERC20Packed( + transactionId, + integrator, + RECEIVER, + uint64(destinationChainId), + USDC_ADDRESS, + amountUSDC, + nonce, + maxSlippage + ); console.logString("encodedUSDC"); console.logBytes(encodedUSDC); } function testStartBridgeTokensViaCBridgeNativePacked() public { vm.startPrank(WHALE); - (bool success, ) = address(diamond).call{value: amountNative}(packedNative); + (bool success, ) = address(diamond).call{ value: amountNative }( + packedNative + ); if (!success) { revert(); } @@ -212,7 +240,9 @@ contract CBridgeGasTest is Test, DiamondTest { function testStartBridgeTokensViaCBridgeNativeMin() public { vm.startPrank(WHALE); - cBridgeFacetPacked.startBridgeTokensViaCBridgeNativeMin{value: amountNative}( + cBridgeFacetPacked.startBridgeTokensViaCBridgeNativeMin{ + value: amountNative + }( transactionId, integrator, RECEIVER, @@ -251,7 +281,7 @@ contract CBridgeGasTest is Test, DiamondTest { function testStartBridgeTokensViaCBridgeNative() public { vm.startPrank(WHALE); - cBridgeFacet.startBridgeTokensViaCBridge{value: amountNative}( + cBridgeFacet.startBridgeTokensViaCBridge{ value: amountNative }( bridgeDataNative, cbridgeDataNative ); diff --git a/test/solidity/Gas/Hop.t.sol b/test/solidity/Gas/Hop.t.sol index 3b7133a9d..87cecc7c3 100644 --- a/test/solidity/Gas/Hop.t.sol +++ b/test/solidity/Gas/Hop.t.sol @@ -52,8 +52,8 @@ contract HopGasTest is Test, DiamondTest { } function testDirectBridge() public { - uint256 amount = 100 * 10**usdc.decimals(); - uint256 amountOutMin = 99 * 10**usdc.decimals(); + uint256 amount = 100 * 10 ** usdc.decimals(); + uint256 amountOutMin = 99 * 10 ** usdc.decimals(); uint256 deadline = block.timestamp + 20 minutes; vm.startPrank(WHALE); @@ -71,8 +71,8 @@ contract HopGasTest is Test, DiamondTest { } function testLifiBridge() public { - uint256 amount = 100 * 10**usdc.decimals(); - uint256 amountOutMin = 99 * 10**usdc.decimals(); + uint256 amount = 100 * 10 ** usdc.decimals(); + uint256 amountOutMin = 99 * 10 ** usdc.decimals(); uint256 deadline = block.timestamp + 20 minutes; ILiFi.BridgeData memory bridgeData = ILiFi.BridgeData( diff --git a/test/solidity/Gas/HopFacetPackedARB.gas.t.sol b/test/solidity/Gas/HopFacetPackedARB.gas.t.sol index 8e2f09f39..ef6851601 100644 --- a/test/solidity/Gas/HopFacetPackedARB.gas.t.sol +++ b/test/solidity/Gas/HopFacetPackedARB.gas.t.sol @@ -11,8 +11,14 @@ import { DiamondTest, LiFiDiamond } from "../utils/DiamondTest.sol"; import { console } from "../utils/Console.sol"; contract CallForwarder { - function callDiamond(uint256 nativeAmount, address contractAddress, bytes calldata callData) external payable { - (bool success, ) = contractAddress.call{value: nativeAmount}(callData); + function callDiamond( + uint256 nativeAmount, + address contractAddress, + bytes calldata callData + ) external payable { + (bool success, ) = contractAddress.call{ value: nativeAmount }( + callData + ); if (!success) { revert(); } @@ -73,25 +79,46 @@ contract HopGasTest is Test, DiamondTest { callForwarder = new CallForwarder(); bytes4[] memory functionSelectors = new bytes4[](6); - functionSelectors[0] = hopFacetPacked.startBridgeTokensViaHopL2NativePacked.selector; - functionSelectors[1] = hopFacetPacked.startBridgeTokensViaHopL2NativeMin.selector; - functionSelectors[2] = hopFacetPacked.encoder_startBridgeTokensViaHopL2NativePacked.selector; - functionSelectors[3] = hopFacetPacked.startBridgeTokensViaHopL2ERC20Packed.selector; - functionSelectors[4] = hopFacetPacked.startBridgeTokensViaHopL2ERC20Min.selector; - functionSelectors[5] = hopFacetPacked.encoder_startBridgeTokensViaHopL2ERC20Packed.selector; + functionSelectors[0] = hopFacetPacked + .startBridgeTokensViaHopL2NativePacked + .selector; + functionSelectors[1] = hopFacetPacked + .startBridgeTokensViaHopL2NativeMin + .selector; + functionSelectors[2] = hopFacetPacked + .encoder_startBridgeTokensViaHopL2NativePacked + .selector; + functionSelectors[3] = hopFacetPacked + .startBridgeTokensViaHopL2ERC20Packed + .selector; + functionSelectors[4] = hopFacetPacked + .startBridgeTokensViaHopL2ERC20Min + .selector; + functionSelectors[5] = hopFacetPacked + .encoder_startBridgeTokensViaHopL2ERC20Packed + .selector; addFacet(diamond, address(hopFacetPacked), functionSelectors); hopFacetPacked = HopFacetPacked(address(diamond)); - /// Perpare HopFacetOptimized & Approval hopFacetOptimized = new HopFacetOptimized(); bytes4[] memory functionSelectorsApproval = new bytes4[](3); - functionSelectorsApproval[0] = hopFacetOptimized.setApprovalForBridges.selector; - functionSelectorsApproval[1] = hopFacetOptimized.startBridgeTokensViaHopL2Native.selector; - functionSelectorsApproval[2] = hopFacetOptimized.startBridgeTokensViaHopL2ERC20.selector; - - addFacet(diamond, address(hopFacetOptimized), functionSelectorsApproval); + functionSelectorsApproval[0] = hopFacetOptimized + .setApprovalForBridges + .selector; + functionSelectorsApproval[1] = hopFacetOptimized + .startBridgeTokensViaHopL2Native + .selector; + functionSelectorsApproval[2] = hopFacetOptimized + .startBridgeTokensViaHopL2ERC20 + .selector; + + addFacet( + diamond, + address(hopFacetOptimized), + functionSelectorsApproval + ); hopFacetOptimized = HopFacetOptimized(address(diamond)); address[] memory bridges = new address[](1); @@ -100,15 +127,14 @@ contract HopGasTest is Test, DiamondTest { tokens[0] = USDC_ADDRESS; hopFacetOptimized.setApprovalForBridges(bridges, tokens); - /// Perpare parameters transactionId = "someID"; integrator = "demo-partner"; // Native params - amountNative = 1 * 10**18; - amountBonderFeeNative = amountNative / 100 * 1; - amountOutMinNative = amountNative / 100 * 99; + amountNative = 1 * 10 ** 18; + amountBonderFeeNative = (amountNative / 100) * 1; + amountOutMinNative = (amountNative / 100) * 99; bytes memory packedNativeParams = bytes.concat( bytes8(transactionId), // transactionId @@ -126,9 +152,9 @@ contract HopGasTest is Test, DiamondTest { ); // USDC params - amountUSDC = 100 * 10**usdc.decimals(); - amountBonderFeeUSDC = amountUSDC / 100 * 1; - amountOutMinUSDC = amountUSDC / 100 * 99; + amountUSDC = 100 * 10 ** usdc.decimals(); + amountBonderFeeUSDC = (amountUSDC / 100) * 1; + amountOutMinUSDC = (amountUSDC / 100) * 99; bytes memory packedUSDCParams = bytes.concat( bytes8(transactionId), // transactionId @@ -196,40 +222,44 @@ contract HopGasTest is Test, DiamondTest { function testCallData() public view { console.logString("startBridgeTokensViaHopL2NativePacked"); console.logBytes(packedNative); - bytes memory encodedNative = hopFacetPacked.encoder_startBridgeTokensViaHopL2NativePacked( - transactionId, - integrator, - RECEIVER, - 137, - amountBonderFeeNative, - amountOutMinNative, - amountOutMinNative, - HOP_NATIVE_BRIDGE - ); + bytes memory encodedNative = hopFacetPacked + .encoder_startBridgeTokensViaHopL2NativePacked( + transactionId, + integrator, + RECEIVER, + 137, + amountBonderFeeNative, + amountOutMinNative, + amountOutMinNative, + HOP_NATIVE_BRIDGE + ); console.logString("encodedNative"); console.logBytes(encodedNative); console.logString("startBridgeTokensViaHopL2ERC20Packed"); console.logBytes(packedUSDC); - bytes memory encodedUSDC = hopFacetPacked.encoder_startBridgeTokensViaHopL2ERC20Packed( - transactionId, - integrator, - RECEIVER, - 137, - USDC_ADDRESS, - amountUSDC, - amountBonderFeeUSDC, - amountOutMinUSDC, - amountOutMinUSDC, - HOP_USDC_BRIDGE - ); + bytes memory encodedUSDC = hopFacetPacked + .encoder_startBridgeTokensViaHopL2ERC20Packed( + transactionId, + integrator, + RECEIVER, + 137, + USDC_ADDRESS, + amountUSDC, + amountBonderFeeUSDC, + amountOutMinUSDC, + amountOutMinUSDC, + HOP_USDC_BRIDGE + ); console.logString("encodedUSDC"); console.logBytes(encodedUSDC); } function testStartBridgeTokensViaHopL2NativePacked() public { vm.startPrank(WHALE); - (bool success, ) = address(diamond).call{value: amountNative}(packedNative); + (bool success, ) = address(diamond).call{ value: amountNative }( + packedNative + ); if (!success) { revert(); } @@ -238,13 +268,19 @@ contract HopGasTest is Test, DiamondTest { function testStartBridgeTokensViaHopL2NativePackedForwarded() public { vm.startPrank(WHALE); - callForwarder.callDiamond{value: 2 * amountNative}(amountNative, address(diamond), packedNative); + callForwarder.callDiamond{ value: 2 * amountNative }( + amountNative, + address(diamond), + packedNative + ); vm.stopPrank(); } function testStartBridgeTokensViaHopL2NativeMin() public { vm.startPrank(WHALE); - hopFacetPacked.startBridgeTokensViaHopL2NativeMin{value: amountNative}( + hopFacetPacked.startBridgeTokensViaHopL2NativeMin{ + value: amountNative + }( transactionId, integrator, RECEIVER, @@ -287,10 +323,9 @@ contract HopGasTest is Test, DiamondTest { function testStartBridgeTokensViaHopL2Native() public { vm.startPrank(WHALE); - hopFacetOptimized.startBridgeTokensViaHopL2Native{value: amountNative}( - bridgeDataNative, - hopDataNative - ); + hopFacetOptimized.startBridgeTokensViaHopL2Native{ + value: amountNative + }(bridgeDataNative, hopDataNative); vm.stopPrank(); } diff --git a/test/solidity/Gas/HopFacetPackedETH.gas.t.sol b/test/solidity/Gas/HopFacetPackedETH.gas.t.sol index cacd8802a..cb4092f1f 100644 --- a/test/solidity/Gas/HopFacetPackedETH.gas.t.sol +++ b/test/solidity/Gas/HopFacetPackedETH.gas.t.sol @@ -63,21 +63,34 @@ contract HopGasTest is Test, DiamondTest { hop = IHopBridge(HOP_USDC_BRIDGE); bytes4[] memory functionSelectors = new bytes4[](2); - functionSelectors[0] = hopFacetPacked.startBridgeTokensViaHopL1NativeMin.selector; - functionSelectors[1] = hopFacetPacked.startBridgeTokensViaHopL1ERC20Min.selector; + functionSelectors[0] = hopFacetPacked + .startBridgeTokensViaHopL1NativeMin + .selector; + functionSelectors[1] = hopFacetPacked + .startBridgeTokensViaHopL1ERC20Min + .selector; addFacet(diamond, address(hopFacetPacked), functionSelectors); hopFacetPacked = HopFacetPacked(address(diamond)); - /// Perpare HopFacetOptimized & Approval hopFacetOptimized = new HopFacetOptimized(); bytes4[] memory functionSelectorsApproval = new bytes4[](3); - functionSelectorsApproval[0] = hopFacetOptimized.setApprovalForBridges.selector; - functionSelectorsApproval[1] = hopFacetOptimized.startBridgeTokensViaHopL1Native.selector; - functionSelectorsApproval[2] = hopFacetOptimized.startBridgeTokensViaHopL1ERC20.selector; - - addFacet(diamond, address(hopFacetOptimized), functionSelectorsApproval); + functionSelectorsApproval[0] = hopFacetOptimized + .setApprovalForBridges + .selector; + functionSelectorsApproval[1] = hopFacetOptimized + .startBridgeTokensViaHopL1Native + .selector; + functionSelectorsApproval[2] = hopFacetOptimized + .startBridgeTokensViaHopL1ERC20 + .selector; + + addFacet( + diamond, + address(hopFacetOptimized), + functionSelectorsApproval + ); hopFacetOptimized = HopFacetOptimized(address(diamond)); address[] memory bridges = new address[](1); @@ -86,21 +99,20 @@ contract HopGasTest is Test, DiamondTest { tokens[0] = USDC_ADDRESS; hopFacetOptimized.setApprovalForBridges(bridges, tokens); - /// Perpare parameters transactionId = "someID"; integrator = "demo-partner"; destinationChainId = 137; // Native params - amountNative = 1 * 10**18; - amountBonderFeeNative = amountNative / 100 * 1; - amountOutMinNative = amountNative / 100 * 99; + amountNative = 1 * 10 ** 18; + amountBonderFeeNative = (amountNative / 100) * 1; + amountOutMinNative = (amountNative / 100) * 99; // USDC params - amountUSDC = 100 * 10**usdc.decimals(); - amountBonderFeeUSDC = amountUSDC / 100 * 1; - amountOutMinUSDC = amountUSDC / 100 * 99; + amountUSDC = 100 * 10 ** usdc.decimals(); + amountBonderFeeUSDC = (amountUSDC / 100) * 1; + amountOutMinUSDC = (amountUSDC / 100) * 99; // same data for HopFacetOptimized bridgeDataNative = ILiFi.BridgeData( @@ -150,7 +162,9 @@ contract HopGasTest is Test, DiamondTest { function testStartBridgeTokensViaHopL1NativeMin() public { vm.startPrank(WHALE); - hopFacetPacked.startBridgeTokensViaHopL1NativeMin{value: amountNative}( + hopFacetPacked.startBridgeTokensViaHopL1NativeMin{ + value: amountNative + }( transactionId, integrator, RECEIVER, @@ -179,10 +193,9 @@ contract HopGasTest is Test, DiamondTest { function testStartBridgeTokensViaHopL1Native() public { vm.startPrank(WHALE); - hopFacetOptimized.startBridgeTokensViaHopL1Native{value: amountNative}( - bridgeDataNative, - hopDataNative - ); + hopFacetOptimized.startBridgeTokensViaHopL1Native{ + value: amountNative + }(bridgeDataNative, hopDataNative); vm.stopPrank(); } diff --git a/test/solidity/Gas/HopFacetPackedPOL.gas.t.sol b/test/solidity/Gas/HopFacetPackedPOL.gas.t.sol index 0dfcc3f53..ea5c5e2dd 100644 --- a/test/solidity/Gas/HopFacetPackedPOL.gas.t.sol +++ b/test/solidity/Gas/HopFacetPackedPOL.gas.t.sol @@ -12,8 +12,14 @@ import { DiamondTest, LiFiDiamond } from "../utils/DiamondTest.sol"; import { console } from "../utils/Console.sol"; contract CallForwarder { - function callDiamond(uint256 nativeAmount, address contractAddress, bytes calldata callData) external payable { - (bool success, ) = contractAddress.call{value: nativeAmount}(callData); + function callDiamond( + uint256 nativeAmount, + address contractAddress, + bytes calldata callData + ) external payable { + (bool success, ) = contractAddress.call{ value: nativeAmount }( + callData + ); if (!success) { revert(); } @@ -74,25 +80,46 @@ contract HopGasTest is Test, DiamondTest { callForwarder = new CallForwarder(); bytes4[] memory functionSelectors = new bytes4[](6); - functionSelectors[0] = hopFacetPacked.startBridgeTokensViaHopL2NativePacked.selector; - functionSelectors[1] = hopFacetPacked.startBridgeTokensViaHopL2NativeMin.selector; - functionSelectors[2] = hopFacetPacked.encoder_startBridgeTokensViaHopL2NativePacked.selector; - functionSelectors[3] = hopFacetPacked.startBridgeTokensViaHopL2ERC20Packed.selector; - functionSelectors[4] = hopFacetPacked.startBridgeTokensViaHopL2ERC20Min.selector; - functionSelectors[5] = hopFacetPacked.encoder_startBridgeTokensViaHopL2ERC20Packed.selector; + functionSelectors[0] = hopFacetPacked + .startBridgeTokensViaHopL2NativePacked + .selector; + functionSelectors[1] = hopFacetPacked + .startBridgeTokensViaHopL2NativeMin + .selector; + functionSelectors[2] = hopFacetPacked + .encoder_startBridgeTokensViaHopL2NativePacked + .selector; + functionSelectors[3] = hopFacetPacked + .startBridgeTokensViaHopL2ERC20Packed + .selector; + functionSelectors[4] = hopFacetPacked + .startBridgeTokensViaHopL2ERC20Min + .selector; + functionSelectors[5] = hopFacetPacked + .encoder_startBridgeTokensViaHopL2ERC20Packed + .selector; addFacet(diamond, address(hopFacetPacked), functionSelectors); hopFacetPacked = HopFacetPacked(address(diamond)); - /// Perpare HopFacetOptimized & Approval hopFacetOptimized = new HopFacetOptimized(); bytes4[] memory functionSelectorsApproval = new bytes4[](3); - functionSelectorsApproval[0] = hopFacetOptimized.setApprovalForBridges.selector; - functionSelectorsApproval[1] = hopFacetOptimized.startBridgeTokensViaHopL2Native.selector; - functionSelectorsApproval[2] = hopFacetOptimized.startBridgeTokensViaHopL2ERC20.selector; - - addFacet(diamond, address(hopFacetOptimized), functionSelectorsApproval); + functionSelectorsApproval[0] = hopFacetOptimized + .setApprovalForBridges + .selector; + functionSelectorsApproval[1] = hopFacetOptimized + .startBridgeTokensViaHopL2Native + .selector; + functionSelectorsApproval[2] = hopFacetOptimized + .startBridgeTokensViaHopL2ERC20 + .selector; + + addFacet( + diamond, + address(hopFacetOptimized), + functionSelectorsApproval + ); hopFacetOptimized = HopFacetOptimized(address(diamond)); address[] memory bridges = new address[](1); @@ -101,15 +128,14 @@ contract HopGasTest is Test, DiamondTest { tokens[0] = USDC_ADDRESS; hopFacetOptimized.setApprovalForBridges(bridges, tokens); - /// Perpare parameters transactionId = "someID"; integrator = "demo-partner"; // Native params - amountNative = 1 * 10**18; - amountBonderFeeNative = amountNative / 100 * 1; - amountOutMinNative = amountNative / 100 * 99; + amountNative = 1 * 10 ** 18; + amountBonderFeeNative = (amountNative / 100) * 1; + amountOutMinNative = (amountNative / 100) * 99; bytes memory packedNativeParams = bytes.concat( bytes8(transactionId), // transactionId @@ -127,9 +153,9 @@ contract HopGasTest is Test, DiamondTest { ); // USDC params - amountUSDC = 100 * 10**usdc.decimals(); - amountBonderFeeUSDC = amountUSDC / 100 * 1; - amountOutMinUSDC = amountUSDC / 100 * 99; + amountUSDC = 100 * 10 ** usdc.decimals(); + amountBonderFeeUSDC = (amountUSDC / 100) * 1; + amountOutMinUSDC = (amountUSDC / 100) * 99; bytes memory packedUSDCParams = bytes.concat( bytes8(transactionId), // transactionId @@ -197,40 +223,44 @@ contract HopGasTest is Test, DiamondTest { function testCallData() public view { console.logString("startBridgeTokensViaHopL2NativePacked"); console.logBytes(packedNative); - bytes memory encodedNative = hopFacetPacked.encoder_startBridgeTokensViaHopL2NativePacked( - "someID", - integrator, - RECEIVER, - 10, - amountBonderFeeNative, - amountOutMinNative, - amountOutMinNative, - HOP_NATIVE_BRIDGE - ); + bytes memory encodedNative = hopFacetPacked + .encoder_startBridgeTokensViaHopL2NativePacked( + "someID", + integrator, + RECEIVER, + 10, + amountBonderFeeNative, + amountOutMinNative, + amountOutMinNative, + HOP_NATIVE_BRIDGE + ); console.logString("encodedNative"); console.logBytes(encodedNative); console.logString("startBridgeTokensViaHopL2ERC20Packed"); console.logBytes(packedUSDC); - bytes memory encodedUSDC = hopFacetPacked.encoder_startBridgeTokensViaHopL2ERC20Packed( - "someID", - integrator, - RECEIVER, - 10, - USDC_ADDRESS, - amountUSDC, - amountBonderFeeUSDC, - amountOutMinUSDC, - amountOutMinUSDC, - HOP_USDC_BRIDGE - ); + bytes memory encodedUSDC = hopFacetPacked + .encoder_startBridgeTokensViaHopL2ERC20Packed( + "someID", + integrator, + RECEIVER, + 10, + USDC_ADDRESS, + amountUSDC, + amountBonderFeeUSDC, + amountOutMinUSDC, + amountOutMinUSDC, + HOP_USDC_BRIDGE + ); console.logString("encodedUSDC"); console.logBytes(encodedUSDC); } function testStartBridgeTokensViaHopL2NativePacked() public { vm.startPrank(WHALE); - (bool success, ) = address(diamond).call{value: amountNative}(packedNative); + (bool success, ) = address(diamond).call{ value: amountNative }( + packedNative + ); if (!success) { revert(); } @@ -239,13 +269,19 @@ contract HopGasTest is Test, DiamondTest { function testStartBridgeTokensViaHopL2NativePackedForwarded() public { vm.startPrank(WHALE); - callForwarder.callDiamond{value: 2 * amountNative}(amountNative, address(diamond), packedNative); + callForwarder.callDiamond{ value: 2 * amountNative }( + amountNative, + address(diamond), + packedNative + ); vm.stopPrank(); } function testStartBridgeTokensViaHopL2NativeMin() public { vm.startPrank(WHALE); - hopFacetPacked.startBridgeTokensViaHopL2NativeMin{value: amountNative}( + hopFacetPacked.startBridgeTokensViaHopL2NativeMin{ + value: amountNative + }( "someID", integrator, RECEIVER, @@ -288,10 +324,9 @@ contract HopGasTest is Test, DiamondTest { function testStartBridgeTokensViaHopL2Native() public { vm.startPrank(WHALE); - hopFacetOptimized.startBridgeTokensViaHopL2Native{value: amountNative}( - bridgeDataNative, - hopDataNative - ); + hopFacetOptimized.startBridgeTokensViaHopL2Native{ + value: amountNative + }(bridgeDataNative, hopDataNative); vm.stopPrank(); } diff --git a/test/solidity/Periphery/AxelarExecutor.t.sol b/test/solidity/Periphery/AxelarExecutor.t.sol index c82ebddb4..645614be0 100644 --- a/test/solidity/Periphery/AxelarExecutor.t.sol +++ b/test/solidity/Periphery/AxelarExecutor.t.sol @@ -46,9 +46,10 @@ contract MockGateway { return true; } - function setTokenAddress(string memory _symbol, address _tokenAddress) - external - { + function setTokenAddress( + string memory _symbol, + address _tokenAddress + ) external { tokenAddresses[_symbol] = _tokenAddress; } } diff --git a/test/solidity/Periphery/Executor.t.sol b/test/solidity/Periphery/Executor.t.sol index 95ddbcaf5..86b431f01 100644 --- a/test/solidity/Periphery/Executor.t.sol +++ b/test/solidity/Periphery/Executor.t.sol @@ -50,9 +50,10 @@ contract MockGateway { return true; } - function setTokenAddress(string memory _symbol, address _tokenAddress) - external - { + function setTokenAddress( + string memory _symbol, + address _tokenAddress + ) external { tokenAddresses[_symbol] = _tokenAddress; } } @@ -229,7 +230,7 @@ contract ExecutorTest is DSTest { path[0] = DAI_ADDRESS; path[1] = WETH_ADDRESS; - uint256 amountOut = 1_000 * 10**weth.decimals(); + uint256 amountOut = 1_000 * 10 ** weth.decimals(); // Calculate DAI amount uint256[] memory amounts = uniswap.getAmountsIn(amountOut, path); diff --git a/test/solidity/Periphery/FusePoolZap.t.sol b/test/solidity/Periphery/FusePoolZap.t.sol index aa6ca982e..007f0b083 100644 --- a/test/solidity/Periphery/FusePoolZap.t.sol +++ b/test/solidity/Periphery/FusePoolZap.t.sol @@ -40,7 +40,7 @@ contract FusePoolZapTest is DSTest { function testCanZapIn() public { vm.startPrank(DEPOSITOR); - uint256 amount = 1000 * 10**ERC20(FRAX3CRV).decimals(); + uint256 amount = 1000 * 10 ** ERC20(FRAX3CRV).decimals(); ERC20(FRAX3CRV).approve(address(zap), amount); zap.zapIn(TRIBE_FUSE_POOL, FRAX3CRV, amount); @@ -48,7 +48,7 @@ contract FusePoolZapTest is DSTest { // Should get 5000 fTokens back assertEq( ERC20(FTOKEN).balanceOf(DEPOSITOR), - 5000 * 10**ERC20(FTOKEN).decimals() + 5000 * 10 ** ERC20(FTOKEN).decimals() ); ERC20(FRAX3CRV).approve(address(zap), amount); diff --git a/test/solidity/Periphery/RelayerCelerIM.t.sol b/test/solidity/Periphery/RelayerCelerIM.t.sol index 1b93aac39..abae92528 100644 --- a/test/solidity/Periphery/RelayerCelerIM.t.sol +++ b/test/solidity/Periphery/RelayerCelerIM.t.sol @@ -14,6 +14,12 @@ interface Ownable { function owner() external returns (address); } +contract MockLiquidityBridge is TestBase { + function mockWithdraw(uint256 _amount) external { + deal(msg.sender, _amount); + } +} + contract RelayerCelerIMTest is TestBase { /// Events /// event CBridgeMessageBusSet(address indexed messageBusAddress); @@ -355,4 +361,31 @@ contract RelayerCelerIMTest is TestBase { (bool success, ) = address(relayer).call{ value: 1 }(""); if (!success) revert ExternalCallFailed(); } + + function test_CanTriggerRefund() public { + address BRIDGE_ADDRESS = 0x5427FEFA711Eff984124bFBB1AB6fbf5E3DA1820; + uint256 REFUND_AMOUNT = 0.1 ether; + + vm.allowCheatcodes(BRIDGE_ADDRESS); + MockLiquidityBridge lb = new MockLiquidityBridge(); + vm.etch(BRIDGE_ADDRESS, address(lb).code); + + uint256 preRefundBalance = address(USER_RECEIVER).balance; + relayer.triggerRefund( + payable(BRIDGE_ADDRESS), // Celer Liquidity Bridge + abi.encodeWithSelector( + MockLiquidityBridge.mockWithdraw.selector, + REFUND_AMOUNT + ), // Calldata + address(0), // Native asset + payable(USER_RECEIVER), // Address to refund to + REFUND_AMOUNT + ); + uint256 postRefundBalance = address(USER_RECEIVER).balance; + assertEq( + postRefundBalance - preRefundBalance, + REFUND_AMOUNT, + "Refund amount should be correct" + ); + } } diff --git a/test/solidity/Periphery/ServiceFeeCollector.t.sol b/test/solidity/Periphery/ServiceFeeCollector.t.sol index 79803017c..79b79951a 100644 --- a/test/solidity/Periphery/ServiceFeeCollector.t.sol +++ b/test/solidity/Periphery/ServiceFeeCollector.t.sol @@ -37,6 +37,7 @@ contract ServiceFeeCollectorTest is DSTest { feeCollector.collectTokenGasFees( address(feeToken), fee, + 137, address(0xb33f) ); @@ -49,7 +50,7 @@ contract ServiceFeeCollectorTest is DSTest { uint256 fee = 0.015 ether; // Act - feeCollector.collectNativeGasFees{ value: fee }(fee, address(0xb33f)); + feeCollector.collectNativeGasFees{ value: fee }(137, address(0xb33f)); // Assert assert(address(feeCollector).balance == fee); @@ -76,10 +77,7 @@ contract ServiceFeeCollectorTest is DSTest { uint256 fee = 0.015 ether; // Act - feeCollector.collectNativeInsuranceFees{ value: fee }( - fee, - address(0xb33f) - ); + feeCollector.collectNativeInsuranceFees{ value: fee }(address(0xb33f)); // Assert assert(address(feeCollector).balance == fee); @@ -92,6 +90,7 @@ contract ServiceFeeCollectorTest is DSTest { feeCollector.collectTokenGasFees( address(feeToken), fee, + 137, address(0xb33f) ); uint256 startingBalance = feeToken.balanceOf(address(this)); @@ -113,9 +112,10 @@ contract ServiceFeeCollectorTest is DSTest { feeCollector.collectTokenGasFees( address(feeToken), fee, + 137, address(0xb33f) ); - feeCollector.collectNativeGasFees{ value: fee }(fee, address(0xb33f)); + feeCollector.collectNativeGasFees{ value: fee }(137, address(0xb33f)); uint256 startingTokenBalance = feeToken.balanceOf(address(this)); uint256 startingETHBalance = address(this).balance; @@ -141,6 +141,7 @@ contract ServiceFeeCollectorTest is DSTest { feeCollector.collectTokenGasFees( address(feeToken), fee, + 137, address(0xb33f) ); diff --git a/test/solidity/utils/Console.sol b/test/solidity/utils/Console.sol index 4446fc948..1787b3342 100644 --- a/test/solidity/utils/Console.sol +++ b/test/solidity/utils/Console.sol @@ -309,51 +309,31 @@ library console { ); } - function log( - uint256 p0, - uint256 p1, - uint256 p2 - ) internal view { + function log(uint256 p0, uint256 p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,uint,uint)", p0, p1, p2) ); } - function log( - uint256 p0, - uint256 p1, - string memory p2 - ) internal view { + function log(uint256 p0, uint256 p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,uint,string)", p0, p1, p2) ); } - function log( - uint256 p0, - uint256 p1, - bool p2 - ) internal view { + function log(uint256 p0, uint256 p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,uint,bool)", p0, p1, p2) ); } - function log( - uint256 p0, - uint256 p1, - address p2 - ) internal view { + function log(uint256 p0, uint256 p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,uint,address)", p0, p1, p2) ); } - function log( - uint256 p0, - string memory p1, - uint256 p2 - ) internal view { + function log(uint256 p0, string memory p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,string,uint)", p0, p1, p2) ); @@ -369,111 +349,67 @@ library console { ); } - function log( - uint256 p0, - string memory p1, - bool p2 - ) internal view { + function log(uint256 p0, string memory p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,string,bool)", p0, p1, p2) ); } - function log( - uint256 p0, - string memory p1, - address p2 - ) internal view { + function log(uint256 p0, string memory p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,string,address)", p0, p1, p2) ); } - function log( - uint256 p0, - bool p1, - uint256 p2 - ) internal view { + function log(uint256 p0, bool p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,bool,uint)", p0, p1, p2) ); } - function log( - uint256 p0, - bool p1, - string memory p2 - ) internal view { + function log(uint256 p0, bool p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,bool,string)", p0, p1, p2) ); } - function log( - uint256 p0, - bool p1, - bool p2 - ) internal view { + function log(uint256 p0, bool p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,bool,bool)", p0, p1, p2) ); } - function log( - uint256 p0, - bool p1, - address p2 - ) internal view { + function log(uint256 p0, bool p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,bool,address)", p0, p1, p2) ); } - function log( - uint256 p0, - address p1, - uint256 p2 - ) internal view { + function log(uint256 p0, address p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,address,uint)", p0, p1, p2) ); } - function log( - uint256 p0, - address p1, - string memory p2 - ) internal view { + function log(uint256 p0, address p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,address,string)", p0, p1, p2) ); } - function log( - uint256 p0, - address p1, - bool p2 - ) internal view { + function log(uint256 p0, address p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,address,bool)", p0, p1, p2) ); } - function log( - uint256 p0, - address p1, - address p2 - ) internal view { + function log(uint256 p0, address p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,address,address)", p0, p1, p2) ); } - function log( - string memory p0, - uint256 p1, - uint256 p2 - ) internal view { + function log(string memory p0, uint256 p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,uint,uint)", p0, p1, p2) ); @@ -489,21 +425,13 @@ library console { ); } - function log( - string memory p0, - uint256 p1, - bool p2 - ) internal view { + function log(string memory p0, uint256 p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,uint,bool)", p0, p1, p2) ); } - function log( - string memory p0, - uint256 p1, - address p2 - ) internal view { + function log(string memory p0, uint256 p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,uint,address)", p0, p1, p2) ); @@ -529,11 +457,7 @@ library console { ); } - function log( - string memory p0, - string memory p1, - bool p2 - ) internal view { + function log(string memory p0, string memory p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2) ); @@ -549,51 +473,31 @@ library console { ); } - function log( - string memory p0, - bool p1, - uint256 p2 - ) internal view { + function log(string memory p0, bool p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,bool,uint)", p0, p1, p2) ); } - function log( - string memory p0, - bool p1, - string memory p2 - ) internal view { + function log(string memory p0, bool p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2) ); } - function log( - string memory p0, - bool p1, - bool p2 - ) internal view { + function log(string memory p0, bool p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2) ); } - function log( - string memory p0, - bool p1, - address p2 - ) internal view { + function log(string memory p0, bool p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2) ); } - function log( - string memory p0, - address p1, - uint256 p2 - ) internal view { + function log(string memory p0, address p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,address,uint)", p0, p1, p2) ); @@ -609,231 +513,139 @@ library console { ); } - function log( - string memory p0, - address p1, - bool p2 - ) internal view { + function log(string memory p0, address p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2) ); } - function log( - string memory p0, - address p1, - address p2 - ) internal view { + function log(string memory p0, address p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(string,address,address)", p0, p1, p2) ); } - function log( - bool p0, - uint256 p1, - uint256 p2 - ) internal view { + function log(bool p0, uint256 p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,uint,uint)", p0, p1, p2) ); } - function log( - bool p0, - uint256 p1, - string memory p2 - ) internal view { + function log(bool p0, uint256 p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,uint,string)", p0, p1, p2) ); } - function log( - bool p0, - uint256 p1, - bool p2 - ) internal view { + function log(bool p0, uint256 p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,uint,bool)", p0, p1, p2) ); } - function log( - bool p0, - uint256 p1, - address p2 - ) internal view { + function log(bool p0, uint256 p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,uint,address)", p0, p1, p2) ); } - function log( - bool p0, - string memory p1, - uint256 p2 - ) internal view { + function log(bool p0, string memory p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,string,uint)", p0, p1, p2) ); } - function log( - bool p0, - string memory p1, - string memory p2 - ) internal view { + function log(bool p0, string memory p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2) ); } - function log( - bool p0, - string memory p1, - bool p2 - ) internal view { + function log(bool p0, string memory p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2) ); } - function log( - bool p0, - string memory p1, - address p2 - ) internal view { + function log(bool p0, string memory p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2) ); } - function log( - bool p0, - bool p1, - uint256 p2 - ) internal view { + function log(bool p0, bool p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,bool,uint)", p0, p1, p2) ); } - function log( - bool p0, - bool p1, - string memory p2 - ) internal view { + function log(bool p0, bool p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2) ); } - function log( - bool p0, - bool p1, - bool p2 - ) internal view { + function log(bool p0, bool p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2) ); } - function log( - bool p0, - bool p1, - address p2 - ) internal view { + function log(bool p0, bool p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2) ); } - function log( - bool p0, - address p1, - uint256 p2 - ) internal view { + function log(bool p0, address p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,address,uint)", p0, p1, p2) ); } - function log( - bool p0, - address p1, - string memory p2 - ) internal view { + function log(bool p0, address p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2) ); } - function log( - bool p0, - address p1, - bool p2 - ) internal view { + function log(bool p0, address p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2) ); } - function log( - bool p0, - address p1, - address p2 - ) internal view { + function log(bool p0, address p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2) ); } - function log( - address p0, - uint256 p1, - uint256 p2 - ) internal view { + function log(address p0, uint256 p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,uint,uint)", p0, p1, p2) ); } - function log( - address p0, - uint256 p1, - string memory p2 - ) internal view { + function log(address p0, uint256 p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,uint,string)", p0, p1, p2) ); } - function log( - address p0, - uint256 p1, - bool p2 - ) internal view { + function log(address p0, uint256 p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,uint,bool)", p0, p1, p2) ); } - function log( - address p0, - uint256 p1, - address p2 - ) internal view { + function log(address p0, uint256 p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,uint,address)", p0, p1, p2) ); } - function log( - address p0, - string memory p1, - uint256 p2 - ) internal view { + function log(address p0, string memory p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,string,uint)", p0, p1, p2) ); @@ -849,101 +661,61 @@ library console { ); } - function log( - address p0, - string memory p1, - bool p2 - ) internal view { + function log(address p0, string memory p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2) ); } - function log( - address p0, - string memory p1, - address p2 - ) internal view { + function log(address p0, string memory p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,string,address)", p0, p1, p2) ); } - function log( - address p0, - bool p1, - uint256 p2 - ) internal view { + function log(address p0, bool p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,bool,uint)", p0, p1, p2) ); } - function log( - address p0, - bool p1, - string memory p2 - ) internal view { + function log(address p0, bool p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2) ); } - function log( - address p0, - bool p1, - bool p2 - ) internal view { + function log(address p0, bool p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2) ); } - function log( - address p0, - bool p1, - address p2 - ) internal view { + function log(address p0, bool p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2) ); } - function log( - address p0, - address p1, - uint256 p2 - ) internal view { + function log(address p0, address p1, uint256 p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,address,uint)", p0, p1, p2) ); } - function log( - address p0, - address p1, - string memory p2 - ) internal view { + function log(address p0, address p1, string memory p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,address,string)", p0, p1, p2) ); } - function log( - address p0, - address p1, - bool p2 - ) internal view { + function log(address p0, address p1, bool p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2) ); } - function log( - address p0, - address p1, - address p2 - ) internal view { + function log(address p0, address p1, address p2) internal view { _sendLogPayload( abi.encodeWithSignature("log(address,address,address)", p0, p1, p2) ); @@ -977,12 +749,7 @@ library console { ); } - function log( - uint256 p0, - uint256 p1, - uint256 p2, - bool p3 - ) internal view { + function log(uint256 p0, uint256 p1, uint256 p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,uint,uint,bool)", p0, p1, p2, p3) ); @@ -1073,12 +840,7 @@ library console { ); } - function log( - uint256 p0, - uint256 p1, - bool p2, - uint256 p3 - ) internal view { + function log(uint256 p0, uint256 p1, bool p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,uint,bool,uint)", p0, p1, p2, p3) ); @@ -1101,23 +863,13 @@ library console { ); } - function log( - uint256 p0, - uint256 p1, - bool p2, - bool p3 - ) internal view { + function log(uint256 p0, uint256 p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,uint,bool,bool)", p0, p1, p2, p3) ); } - function log( - uint256 p0, - uint256 p1, - bool p2, - address p3 - ) internal view { + function log(uint256 p0, uint256 p1, bool p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,uint,bool,address)", @@ -1163,12 +915,7 @@ library console { ); } - function log( - uint256 p0, - uint256 p1, - address p2, - bool p3 - ) internal view { + function log(uint256 p0, uint256 p1, address p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,uint,address,bool)", @@ -1469,12 +1216,7 @@ library console { ); } - function log( - uint256 p0, - bool p1, - uint256 p2, - uint256 p3 - ) internal view { + function log(uint256 p0, bool p1, uint256 p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,bool,uint,uint)", p0, p1, p2, p3) ); @@ -1497,23 +1239,13 @@ library console { ); } - function log( - uint256 p0, - bool p1, - uint256 p2, - bool p3 - ) internal view { + function log(uint256 p0, bool p1, uint256 p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,bool,uint,bool)", p0, p1, p2, p3) ); } - function log( - uint256 p0, - bool p1, - uint256 p2, - address p3 - ) internal view { + function log(uint256 p0, bool p1, uint256 p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,bool,uint,address)", @@ -1593,12 +1325,7 @@ library console { ); } - function log( - uint256 p0, - bool p1, - bool p2, - uint256 p3 - ) internal view { + function log(uint256 p0, bool p1, bool p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,bool,bool,uint)", p0, p1, p2, p3) ); @@ -1621,23 +1348,13 @@ library console { ); } - function log( - uint256 p0, - bool p1, - bool p2, - bool p3 - ) internal view { + function log(uint256 p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(uint,bool,bool,bool)", p0, p1, p2, p3) ); } - function log( - uint256 p0, - bool p1, - bool p2, - address p3 - ) internal view { + function log(uint256 p0, bool p1, bool p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,bool,bool,address)", @@ -1649,12 +1366,7 @@ library console { ); } - function log( - uint256 p0, - bool p1, - address p2, - uint256 p3 - ) internal view { + function log(uint256 p0, bool p1, address p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,bool,address,uint)", @@ -1683,12 +1395,7 @@ library console { ); } - function log( - uint256 p0, - bool p1, - address p2, - bool p3 - ) internal view { + function log(uint256 p0, bool p1, address p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,bool,address,bool)", @@ -1700,12 +1407,7 @@ library console { ); } - function log( - uint256 p0, - bool p1, - address p2, - address p3 - ) internal view { + function log(uint256 p0, bool p1, address p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,bool,address,address)", @@ -1751,12 +1453,7 @@ library console { ); } - function log( - uint256 p0, - address p1, - uint256 p2, - bool p3 - ) internal view { + function log(uint256 p0, address p1, uint256 p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,address,uint,bool)", @@ -1853,12 +1550,7 @@ library console { ); } - function log( - uint256 p0, - address p1, - bool p2, - uint256 p3 - ) internal view { + function log(uint256 p0, address p1, bool p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,address,bool,uint)", @@ -1887,12 +1579,7 @@ library console { ); } - function log( - uint256 p0, - address p1, - bool p2, - bool p3 - ) internal view { + function log(uint256 p0, address p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,address,bool,bool)", @@ -1904,12 +1591,7 @@ library console { ); } - function log( - uint256 p0, - address p1, - bool p2, - address p3 - ) internal view { + function log(uint256 p0, address p1, bool p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,address,bool,address)", @@ -1955,12 +1637,7 @@ library console { ); } - function log( - uint256 p0, - address p1, - address p2, - bool p3 - ) internal view { + function log(uint256 p0, address p1, address p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(uint,address,address,bool)", @@ -2703,12 +2380,7 @@ library console { ); } - function log( - string memory p0, - bool p1, - bool p2, - bool p3 - ) internal view { + function log(string memory p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(string,bool,bool,bool)", @@ -3077,12 +2749,7 @@ library console { ); } - function log( - bool p0, - uint256 p1, - uint256 p2, - uint256 p3 - ) internal view { + function log(bool p0, uint256 p1, uint256 p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,uint,uint,uint)", p0, p1, p2, p3) ); @@ -3105,23 +2772,13 @@ library console { ); } - function log( - bool p0, - uint256 p1, - uint256 p2, - bool p3 - ) internal view { + function log(bool p0, uint256 p1, uint256 p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,uint,uint,bool)", p0, p1, p2, p3) ); } - function log( - bool p0, - uint256 p1, - uint256 p2, - address p3 - ) internal view { + function log(bool p0, uint256 p1, uint256 p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,uint,uint,address)", @@ -3201,12 +2858,7 @@ library console { ); } - function log( - bool p0, - uint256 p1, - bool p2, - uint256 p3 - ) internal view { + function log(bool p0, uint256 p1, bool p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,uint,bool,uint)", p0, p1, p2, p3) ); @@ -3229,23 +2881,13 @@ library console { ); } - function log( - bool p0, - uint256 p1, - bool p2, - bool p3 - ) internal view { + function log(bool p0, uint256 p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,uint,bool,bool)", p0, p1, p2, p3) ); } - function log( - bool p0, - uint256 p1, - bool p2, - address p3 - ) internal view { + function log(bool p0, uint256 p1, bool p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,uint,bool,address)", @@ -3253,16 +2895,11 @@ library console { p1, p2, p3 - ) - ); - } - - function log( - bool p0, - uint256 p1, - address p2, - uint256 p3 - ) internal view { + ) + ); + } + + function log(bool p0, uint256 p1, address p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,uint,address,uint)", @@ -3291,12 +2928,7 @@ library console { ); } - function log( - bool p0, - uint256 p1, - address p2, - bool p3 - ) internal view { + function log(bool p0, uint256 p1, address p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,uint,address,bool)", @@ -3308,12 +2940,7 @@ library console { ); } - function log( - bool p0, - uint256 p1, - address p2, - address p3 - ) internal view { + function log(bool p0, uint256 p1, address p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,uint,address,address)", @@ -3495,12 +3122,7 @@ library console { ); } - function log( - bool p0, - string memory p1, - bool p2, - bool p3 - ) internal view { + function log(bool p0, string memory p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,string,bool,bool)", @@ -3597,12 +3219,7 @@ library console { ); } - function log( - bool p0, - bool p1, - uint256 p2, - uint256 p3 - ) internal view { + function log(bool p0, bool p1, uint256 p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,bool,uint,uint)", p0, p1, p2, p3) ); @@ -3625,23 +3242,13 @@ library console { ); } - function log( - bool p0, - bool p1, - uint256 p2, - bool p3 - ) internal view { + function log(bool p0, bool p1, uint256 p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,bool,uint,bool)", p0, p1, p2, p3) ); } - function log( - bool p0, - bool p1, - uint256 p2, - address p3 - ) internal view { + function log(bool p0, bool p1, uint256 p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,bool,uint,address)", @@ -3687,12 +3294,7 @@ library console { ); } - function log( - bool p0, - bool p1, - string memory p2, - bool p3 - ) internal view { + function log(bool p0, bool p1, string memory p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,bool,string,bool)", @@ -3721,23 +3323,13 @@ library console { ); } - function log( - bool p0, - bool p1, - bool p2, - uint256 p3 - ) internal view { + function log(bool p0, bool p1, bool p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,bool,bool,uint)", p0, p1, p2, p3) ); } - function log( - bool p0, - bool p1, - bool p2, - string memory p3 - ) internal view { + function log(bool p0, bool p1, bool p2, string memory p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,bool,bool,string)", @@ -3749,23 +3341,13 @@ library console { ); } - function log( - bool p0, - bool p1, - bool p2, - bool p3 - ) internal view { + function log(bool p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3) ); } - function log( - bool p0, - bool p1, - bool p2, - address p3 - ) internal view { + function log(bool p0, bool p1, bool p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,bool,bool,address)", @@ -3777,12 +3359,7 @@ library console { ); } - function log( - bool p0, - bool p1, - address p2, - uint256 p3 - ) internal view { + function log(bool p0, bool p1, address p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,bool,address,uint)", @@ -3811,12 +3388,7 @@ library console { ); } - function log( - bool p0, - bool p1, - address p2, - bool p3 - ) internal view { + function log(bool p0, bool p1, address p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,bool,address,bool)", @@ -3828,12 +3400,7 @@ library console { ); } - function log( - bool p0, - bool p1, - address p2, - address p3 - ) internal view { + function log(bool p0, bool p1, address p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,bool,address,address)", @@ -3845,12 +3412,7 @@ library console { ); } - function log( - bool p0, - address p1, - uint256 p2, - uint256 p3 - ) internal view { + function log(bool p0, address p1, uint256 p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,address,uint,uint)", @@ -3879,12 +3441,7 @@ library console { ); } - function log( - bool p0, - address p1, - uint256 p2, - bool p3 - ) internal view { + function log(bool p0, address p1, uint256 p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,address,uint,bool)", @@ -3896,12 +3453,7 @@ library console { ); } - function log( - bool p0, - address p1, - uint256 p2, - address p3 - ) internal view { + function log(bool p0, address p1, uint256 p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,address,uint,address)", @@ -3981,12 +3533,7 @@ library console { ); } - function log( - bool p0, - address p1, - bool p2, - uint256 p3 - ) internal view { + function log(bool p0, address p1, bool p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,address,bool,uint)", @@ -4015,12 +3562,7 @@ library console { ); } - function log( - bool p0, - address p1, - bool p2, - bool p3 - ) internal view { + function log(bool p0, address p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,address,bool,bool)", @@ -4032,12 +3574,7 @@ library console { ); } - function log( - bool p0, - address p1, - bool p2, - address p3 - ) internal view { + function log(bool p0, address p1, bool p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,address,bool,address)", @@ -4049,12 +3586,7 @@ library console { ); } - function log( - bool p0, - address p1, - address p2, - uint256 p3 - ) internal view { + function log(bool p0, address p1, address p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,address,address,uint)", @@ -4083,12 +3615,7 @@ library console { ); } - function log( - bool p0, - address p1, - address p2, - bool p3 - ) internal view { + function log(bool p0, address p1, address p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,address,address,bool)", @@ -4100,12 +3627,7 @@ library console { ); } - function log( - bool p0, - address p1, - address p2, - address p3 - ) internal view { + function log(bool p0, address p1, address p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(bool,address,address,address)", @@ -4151,12 +3673,7 @@ library console { ); } - function log( - address p0, - uint256 p1, - uint256 p2, - bool p3 - ) internal view { + function log(address p0, uint256 p1, uint256 p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,uint,uint,bool)", @@ -4253,12 +3770,7 @@ library console { ); } - function log( - address p0, - uint256 p1, - bool p2, - uint256 p3 - ) internal view { + function log(address p0, uint256 p1, bool p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,uint,bool,uint)", @@ -4287,12 +3799,7 @@ library console { ); } - function log( - address p0, - uint256 p1, - bool p2, - bool p3 - ) internal view { + function log(address p0, uint256 p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,uint,bool,bool)", @@ -4304,12 +3811,7 @@ library console { ); } - function log( - address p0, - uint256 p1, - bool p2, - address p3 - ) internal view { + function log(address p0, uint256 p1, bool p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,uint,bool,address)", @@ -4355,12 +3857,7 @@ library console { ); } - function log( - address p0, - uint256 p1, - address p2, - bool p3 - ) internal view { + function log(address p0, uint256 p1, address p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,uint,address,bool)", @@ -4661,12 +4158,7 @@ library console { ); } - function log( - address p0, - bool p1, - uint256 p2, - uint256 p3 - ) internal view { + function log(address p0, bool p1, uint256 p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,bool,uint,uint)", @@ -4695,12 +4187,7 @@ library console { ); } - function log( - address p0, - bool p1, - uint256 p2, - bool p3 - ) internal view { + function log(address p0, bool p1, uint256 p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,bool,uint,bool)", @@ -4712,12 +4199,7 @@ library console { ); } - function log( - address p0, - bool p1, - uint256 p2, - address p3 - ) internal view { + function log(address p0, bool p1, uint256 p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,bool,uint,address)", @@ -4797,12 +4279,7 @@ library console { ); } - function log( - address p0, - bool p1, - bool p2, - uint256 p3 - ) internal view { + function log(address p0, bool p1, bool p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,bool,bool,uint)", @@ -4831,12 +4308,7 @@ library console { ); } - function log( - address p0, - bool p1, - bool p2, - bool p3 - ) internal view { + function log(address p0, bool p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,bool,bool,bool)", @@ -4848,12 +4320,7 @@ library console { ); } - function log( - address p0, - bool p1, - bool p2, - address p3 - ) internal view { + function log(address p0, bool p1, bool p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,bool,bool,address)", @@ -4865,12 +4332,7 @@ library console { ); } - function log( - address p0, - bool p1, - address p2, - uint256 p3 - ) internal view { + function log(address p0, bool p1, address p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,bool,address,uint)", @@ -4899,12 +4361,7 @@ library console { ); } - function log( - address p0, - bool p1, - address p2, - bool p3 - ) internal view { + function log(address p0, bool p1, address p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,bool,address,bool)", @@ -4916,12 +4373,7 @@ library console { ); } - function log( - address p0, - bool p1, - address p2, - address p3 - ) internal view { + function log(address p0, bool p1, address p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,bool,address,address)", @@ -4967,12 +4419,7 @@ library console { ); } - function log( - address p0, - address p1, - uint256 p2, - bool p3 - ) internal view { + function log(address p0, address p1, uint256 p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,address,uint,bool)", @@ -5069,12 +4516,7 @@ library console { ); } - function log( - address p0, - address p1, - bool p2, - uint256 p3 - ) internal view { + function log(address p0, address p1, bool p2, uint256 p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,address,bool,uint)", @@ -5103,12 +4545,7 @@ library console { ); } - function log( - address p0, - address p1, - bool p2, - bool p3 - ) internal view { + function log(address p0, address p1, bool p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,address,bool,bool)", @@ -5120,12 +4557,7 @@ library console { ); } - function log( - address p0, - address p1, - bool p2, - address p3 - ) internal view { + function log(address p0, address p1, bool p2, address p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,address,bool,address)", @@ -5171,12 +4603,7 @@ library console { ); } - function log( - address p0, - address p1, - address p2, - bool p3 - ) internal view { + function log(address p0, address p1, address p2, bool p3) internal view { _sendLogPayload( abi.encodeWithSignature( "log(address,address,address,bool)", diff --git a/test/solidity/utils/Interfaces.sol b/test/solidity/utils/Interfaces.sol index a1d536a00..d97661b7b 100644 --- a/test/solidity/utils/Interfaces.sol +++ b/test/solidity/utils/Interfaces.sol @@ -40,13 +40,13 @@ interface UniswapV2Router02 { uint256 deadline ) external returns (uint256[] memory amounts); - function getAmountsIn(uint256 amountOut, address[] calldata path) - external - view - returns (uint256[] memory amounts); + function getAmountsIn( + uint256 amountOut, + address[] calldata path + ) external view returns (uint256[] memory amounts); - function getAmountsOut(uint256 amountIn, address[] calldata path) - external - view - returns (uint256[] memory amounts); + function getAmountsOut( + uint256 amountIn, + address[] calldata path + ) external view returns (uint256[] memory amounts); } diff --git a/test/solidity/utils/TestBase.sol b/test/solidity/utils/TestBase.sol index e2f8fee87..b4466f7ef 100644 --- a/test/solidity/utils/TestBase.sol +++ b/test/solidity/utils/TestBase.sol @@ -197,16 +197,16 @@ abstract contract TestBase is Test, DiamondTest, ILiFi { diamond = createDiamond(); // transfer initial DAI/USDC/WETH balance to USER_SENDER - deal(ADDRESS_USDC, USER_SENDER, 100_000 * 10**usdc.decimals()); - deal(ADDRESS_DAI, USER_SENDER, 100_000 * 10**dai.decimals()); - deal(ADDRESS_WETH, USER_SENDER, 100_000 * 10**weth.decimals()); + deal(ADDRESS_USDC, USER_SENDER, 100_000 * 10 ** usdc.decimals()); + deal(ADDRESS_DAI, USER_SENDER, 100_000 * 10 ** dai.decimals()); + deal(ADDRESS_WETH, USER_SENDER, 100_000 * 10 ** weth.decimals()); // fund USER_SENDER with 1000 ether vm.deal(USER_SENDER, 1000 ether); // initiate variables - defaultDAIAmount = 100 * 10**dai.decimals(); - defaultUSDCAmount = 100 * 10**usdc.decimals(); + defaultDAIAmount = 100 * 10 ** dai.decimals(); + defaultUSDCAmount = 100 * 10 ** usdc.decimals(); // set path for logfile (esp. interesting for fuzzing tests) logFilePath = "./test/logs/"; @@ -427,10 +427,9 @@ abstract contract TestBase is Test, DiamondTest, ILiFi { } //create users with 100 ether balance - function createUsers(uint256 userNum) - external - returns (address payable[] memory) - { + function createUsers( + uint256 userNum + ) external returns (address payable[] memory) { address payable[] memory users = new address payable[](userNum); for (uint256 i = 0; i < userNum; i++) { address payable user = this.getNextUserAddress(); diff --git a/test/solidity/utils/Utilities.sol b/test/solidity/utils/Utilities.sol index 1fb260371..515e6af4b 100644 --- a/test/solidity/utils/Utilities.sol +++ b/test/solidity/utils/Utilities.sol @@ -17,10 +17,9 @@ contract Utilities is DSTest { } //create users with 100 ether balance - function createUsers(uint256 userNum) - external - returns (address payable[] memory) - { + function createUsers( + uint256 userNum + ) external returns (address payable[] memory) { address payable[] memory users = new address payable[](userNum); for (uint256 i = 0; i < userNum; i++) { address payable user = this.getNextUserAddress();