-
Notifications
You must be signed in to change notification settings - Fork 94
Added helpful scripts #1596
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mirooon
wants to merge
30
commits into
main
Choose a base branch
from
deploy-gaszipperiphery
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Added helpful scripts #1596
Changes from 32 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
3fdf1cb
added deploy logs
mirooon d88f594
added viction
mirooon 9908e5a
updated whitelist
mirooon 385ae19
update
mirooon 9a930ba
updated avalanche and viction
mirooon 35a9349
added deployments
mirooon 711d45e
added deploy logs for celo and fraxtal
mirooon 853d65d
merged with smar-123 branch
mirooon ace70af
added verify proposal
mirooon 2864640
merge main
mirooon 0043b1e
added new whitelist
mirooon ecf2c22
added check script
mirooon 619ed62
updates
mirooon 131736a
added sophon logs
mirooon 893c7f1
updated -Execute with Deployer
mirooon 1c27264
updated script
mirooon 85b6204
updates
mirooon 37bd201
added megaeth logs
mirooon 87dde1f
Merge branch 'deploy-gaszipperiphery-megaeth' into deploy-gaszipperip…
mirooon ff9bf4f
updated whitelist
mirooon bb488d1
fix confirm-safe-tx
mirooon 1829c2e
Merge branch 'main' into deploy-gaszipperiphery
mirooon 0bd3a69
Merge branch 'deploy-gaszipperiphery' of github.com:lifinance/contrac…
mirooon e5dceb1
added diamond deploy logs
mirooon 5ccaeb6
updates
mirooon d6e01a0
Merge branch 'SMAR-123-Fix-automatic-contract-verification' into depl…
mirooon 1df9c32
updates
mirooon 2f694af
updates
mirooon ac2b8ab
updates
mirooon e8f2fc8
Merge branch 'main' into deploy-gaszipperiphery
mirooon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| { | ||
| "language": "Solidity", | ||
| "sources": { | ||
| "src/Periphery/GasZipPeriphery.sol": { | ||
| "content": "// SPDX-License-Identifier: LGPL-3.0-only\npragma solidity ^0.8.17;\n\nimport { ILiFi } from \"../Interfaces/ILiFi.sol\";\nimport { IGasZip } from \"../Interfaces/IGasZip.sol\";\nimport { IWhitelistManagerFacet } from \"../Interfaces/IWhitelistManagerFacet.sol\";\nimport { LibSwap } from \"../Libraries/LibSwap.sol\";\nimport { LibAsset, IERC20 } from \"../Libraries/LibAsset.sol\";\nimport { LibUtil } from \"../Libraries/LibUtil.sol\";\nimport { WithdrawablePeriphery } from \"../Helpers/WithdrawablePeriphery.sol\";\nimport { SafeTransferLib } from \"solady/utils/SafeTransferLib.sol\";\nimport { InvalidCallData, ContractCallNotAllowed, InvalidConfig } from \"../Errors/GenericErrors.sol\";\n\n/// @title GasZipPeriphery\n/// @author LI.FI (https://li.fi)\n/// @notice Provides functionality to swap ERC20 tokens to use the gas.zip protocol as a pre-bridge step (https://www.gas.zip/)\n/// @custom:version 1.0.2\ncontract GasZipPeriphery is ILiFi, WithdrawablePeriphery {\n using SafeTransferLib for address;\n\n /// State ///\n IGasZip public immutable GAS_ZIP_ROUTER;\n address public immutable LIFI_DIAMOND;\n uint256 internal constant MAX_CHAINID_LENGTH_ALLOWED = 16;\n\n bytes4 internal constant APPROVE_TO_ONLY_SELECTOR = 0xffffffff;\n\n /// Errors ///\n error TooManyChainIds();\n error SwapOutputMustBeNative();\n\n /// Constructor ///\n constructor(\n address _gasZipRouter,\n address _liFiDiamond,\n address _owner\n ) WithdrawablePeriphery(_owner) {\n if (\n _gasZipRouter == address(0) ||\n _liFiDiamond == address(0) ||\n _owner == address(0)\n ) {\n revert InvalidConfig();\n }\n GAS_ZIP_ROUTER = IGasZip(_gasZipRouter);\n LIFI_DIAMOND = _liFiDiamond;\n }\n\n /// @notice Swaps ERC20 tokens to native and deposits these native tokens in the GasZip router contract\n /// Swaps are allowed via any whitelisted contract from the Diamond's WhitelistManagerFacet\n /// @dev this function can be used as a LibSwap.SwapData protocol step to combine it with any other bridge\n /// @param _swapData The swap data that executes the swap from ERC20 to native\n /// @param _gasZipData contains information about which chains gas should be sent to\n function depositToGasZipERC20(\n LibSwap.SwapData calldata _swapData,\n IGasZip.GasZipData calldata _gasZipData\n ) public {\n if (_swapData.receivingAssetId != address(0)) {\n revert SwapOutputMustBeNative();\n }\n\n IWhitelistManagerFacet whitelistManager = IWhitelistManagerFacet(\n LIFI_DIAMOND\n );\n\n /// This check ensures that either the swap execution contract (_swapData.callTo)\n /// is whitelisted for the specific call or the token spender (_swapData.approveTo)\n /// is whitelisted using the APPROVE_TO_ONLY_SELECTOR (0xffffffff).\n /// This prevents allowance leaks while supporting DEXs where the spender and\n /// the caller addresses are different.\n if (\n !whitelistManager.isContractSelectorWhitelisted(\n _swapData.callTo,\n bytes4(_swapData.callData[:4])\n ) ||\n (_swapData.approveTo != _swapData.callTo &&\n !whitelistManager.isContractSelectorWhitelisted(\n _swapData.approveTo,\n APPROVE_TO_ONLY_SELECTOR\n ))\n ) {\n revert ContractCallNotAllowed();\n }\n\n // deposit ERC20 asset from diamond\n LibAsset.depositAsset(_swapData.sendingAssetId, _swapData.fromAmount);\n\n // max approve to DEX, if not already done\n LibAsset.maxApproveERC20(\n IERC20(_swapData.sendingAssetId),\n _swapData.approveTo,\n _swapData.fromAmount\n );\n\n uint256 preSwapBal = address(this).balance;\n\n // execute swap using the whitelisted DEX\n // Note on slippage protection:\n // 1. Individual swap slippage is protected via minAmountOut parameter in _swapData.callData\n // 2. Final output amount slippage is checked at diamond contract level in SwapperV2._depositAndSwap()\n // solhint-disable-next-line avoid-low-level-calls\n (bool success, bytes memory res) = _swapData.callTo.call(\n _swapData.callData\n );\n if (!success) {\n LibUtil.revertWith(res);\n }\n\n uint256 swapOutputAmount = address(this).balance - preSwapBal;\n\n // deposit native tokens to Gas.zip protocol\n depositToGasZipNative(_gasZipData, swapOutputAmount);\n }\n\n /// @notice Deposits native tokens to the GasZip router contract\n /// @dev this function can be used as a LibSwap.SwapData protocol step to combine it with any other bridge\n /// @param _gasZipData contains information which chains and address gas should be sent to\n /// @param _amount the total amount to be deposited (will be split equally across all chains)\n function depositToGasZipNative(\n IGasZip.GasZipData calldata _gasZipData,\n uint256 _amount\n ) public payable {\n // make sure that receiverAddress is not 0\n if (_gasZipData.receiverAddress == bytes32(0))\n revert InvalidCallData();\n\n // We are depositing to a new contract that supports deposits for EVM chains + Solana (therefore 'receiver' address is bytes32)\n GAS_ZIP_ROUTER.deposit{ value: _amount }(\n _gasZipData.destinationChains,\n _gasZipData.receiverAddress\n );\n\n // return unused native value to msg.sender, if any\n // this is required due to LI.FI backend-internal requirements (money flow)\n uint256 remainingNativeBalance = address(this).balance;\n if (remainingNativeBalance > 0) {\n msg.sender.safeTransferETH(remainingNativeBalance);\n }\n }\n\n /// @dev Returns a value that signals to Gas.zip to which chains gas should be sent in equal parts\n /// @param _chainIds a list of Gas.zip-specific chainIds (not the original chainIds),\n /// see https://dev.gas.zip/gas/chain-support/outbound\n function getDestinationChainsValue(\n uint8[] calldata _chainIds\n ) external pure returns (uint256 destinationChains) {\n uint256 length = _chainIds.length;\n\n if (length > MAX_CHAINID_LENGTH_ALLOWED) revert TooManyChainIds();\n\n for (uint256 i; i < length; ++i) {\n // Shift destinationChains left by 16 bits and add the next chainID\n destinationChains =\n (destinationChains << 16) |\n uint256(_chainIds[i]);\n }\n }\n\n // Required to receive ETH from ERC20-to-Native swaps\n receive() external payable {}\n}" | ||
| } | ||
| }, | ||
| "settings": { | ||
| "remappings": [ | ||
| "lifi/=src/", | ||
| "solady/=lib/solady/src/", | ||
| "@openzeppelin/=lib/openzeppelin-contracts/", | ||
| "solmate/=lib/solmate/src/", | ||
| "permit2/=lib/Permit2/src/", | ||
| "forge-std/=lib/forge-std/src/", | ||
| "test/=test/" | ||
| ], | ||
| "optimizer": { | ||
| "enabled": true, | ||
| "runs": 1000000 | ||
| }, | ||
| "evmVersion": "cancun", | ||
| "viaIR": false, | ||
| "outputSelection": { | ||
| "*": { | ||
| "*": [ | ||
| "abi", | ||
| "evm.bytecode", | ||
| "evm.deployedBytecode", | ||
| "evm.bytecode.sourceMap", | ||
| "evm.deployedBytecode.sourceMap", | ||
| "metadata" | ||
| ], | ||
| "": [ | ||
| "ast" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.