-
Notifications
You must be signed in to change notification settings - Fork 79
Implement EcoFacet [EcoFacet v1.0.0,IEcoPortal v1.0.0] #1324
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
7a62df2
config: whitelist new OKX contract
mathiasmoeller 7144e4e
bootstrap
ezynda3 300f188
real fork test
ezynda3 38e383f
refactor
ezynda3 1d74e8b
deploy to staging
ezynda3 d045ad9
simple demo
ezynda3 12b2a21
fix
ezynda3 abfcb1d
docs
ezynda3 9265a47
revert
ezynda3 581bac1
update
ezynda3 b1ff9d1
fix tests
ezynda3 5267d2c
redeploy to staging + update demo script
ezynda3 acd28da
update demo script
ezynda3 4129082
Merge branch 'main' of github.com:lifinance/contracts into LF-14918-E…
ezynda3 2630da7
update contract, test, demo to work with updated Eco interface
ezynda3 1d7d661
redeploy to staging and update demo
ezynda3 40d63fe
Upgrade EcoFacet to use Portal V2 contract (#1379)
carlosfebres d5765bb
conflicts
ezynda3 fac7bef
Merge branch 'main' of github.com:lifinance/contracts into LF-14918-E…
ezynda3 3fc361d
update demo script
ezynda3 2698753
handle solana
ezynda3 9997cd5
add swap demo
ezynda3 7fd3fe7
Merge branch 'main' into LF-14918-Eco-Facet
ezynda3 4fdaf57
update docs
ezynda3 2b7bc42
update constants
ezynda3 811282d
boost coverage
ezynda3 d122c06
update
ezynda3 a397da1
update
ezynda3 19147bb
fix: address PR review comments for EcoFacet
ezynda3 4bc4cf2
validate
ezynda3 9155e02
validate
ezynda3 1c093fe
cleanup
ezynda3 16edd39
verify solana
ezynda3 a770146
update portal
ezynda3 531129f
fix: improve Solana recipient extraction from Borsh-encoded routes (#…
carlosfebres 5e981e7
update to properly validate
ezynda3 b7c793a
Merge branch 'LF-14918-Eco-Facet' of github.com:lifinance/contracts i…
ezynda3 82d9d5f
fix
ezynda3 1e10a72
Merge branch 'main' into LF-14918-Eco-Facet
ezynda3 9146f94
update docs
ezynda3 06385fb
update tests
ezynda3 62c430e
fix
ezynda3 40be564
fix coverage
ezynda3 92547fc
validate ATA vs solana address
ezynda3 39b7daa
Update script/demoScripts/demoEco.ts
ezynda3 839f548
Merge branch 'main' into LF-14918-Eco-Facet
ezynda3 61b8061
eliminate redundant checks
ezynda3 c5259e4
remove useless internal func
ezynda3 3614694
update docs
ezynda3 acc7520
remove changelog
ezynda3 644d9de
fixes
ezynda3 f1b2678
update helper func names
ezynda3 ecc2d09
validate solana dst against NON_EVM_RECEIVER
ezynda3 aac20d8
document known issue with positive slippage
ezynda3 85a99c7
update tests
ezynda3 15f5101
optimizations
ezynda3 5745732
redeploy to staging
ezynda3 62fe5c9
add clarification
ezynda3 aa85867
remove
ezynda3 d2c99d4
combine helpers
ezynda3 c323eeb
remove extra checks
ezynda3 4b5fb4d
refactor
ezynda3 f6b2ab9
remove native token support
ezynda3 8d0e66a
Merge branch 'main' into LF-14918-Eco-Facet
ezynda3 ca999e8
fix: reject NON_EVM_ADDRESS for non-Solana destinations
ezynda3 8ee81f6
fix: prevent native token loss and refund excess
ezynda3 94b00df
fix: add lower bound validation for Solana address length
ezynda3 0c8f825
fix: validate prover and rewardDeadline parameters
ezynda3 e3249ef
fix: emit BridgeToNonEVMChain only for Solana destinations
ezynda3 50e26d5
refactor: inline depositAmount calculation for gas savings
ezynda3 dd905c0
refactor: replace magic numbers with named constants
ezynda3 82fbf2b
refactor: remove redundant explicit zero value in portal call
ezynda3 967d424
refactor: remove redundant receiverAddress from EcoData
ezynda3 29c9af4
fix: update demoEco.ts to use new EcoData structure
ezynda3 5bc35be
redeploy to staging
ezynda3 3ec6f57
add inline doc about native refunds
ezynda3 68e1008
fix typo
ezynda3 d8a2390
redeploy to staging
ezynda3 a391b5a
update internal calculations to deduct fee from passed minAmount
ezynda3 1bc03bc
remove unneeded var
ezynda3 cc74e99
Merge branch 'main' of github.com:lifinance/contracts into LF-14918-E…
ezynda3 f45a34a
chore: add EcoFacet and IEcoPortal v1.0.0 audit entry
ezynda3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "optimism": { | ||
| "portal": "0x90F0c8aCC1E083Bcb4F487f84FC349ae8d5e28D7" | ||
| }, | ||
| "base": { | ||
| "portal": "0x90F0c8aCC1E083Bcb4F487f84FC349ae8d5e28D7" | ||
| } | ||
| } |
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
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,118 @@ | ||
| # Eco Facet | ||
|
|
||
| ## How it works | ||
|
|
||
| The Eco Facet enables cross-chain token transfers using the Eco Protocol's intent-based bridging system. It creates an intent that specifies the desired outcome on the destination chain, which solvers then fulfill in exchange for a reward. The facet supports both EVM and non-EVM destination chains, as well as optional destination calls for complex cross-chain workflows. | ||
|
|
||
| ```mermaid | ||
| graph LR; | ||
| D{LiFiDiamond}-- DELEGATECALL -->EcoFacet; | ||
| EcoFacet -- CALL --> EcoPortal[Eco Portal] | ||
| ``` | ||
|
|
||
| ## Public Methods | ||
|
|
||
| - `function startBridgeTokensViaEco(BridgeData calldata _bridgeData, EcoData calldata _ecoData)` | ||
| - Bridges tokens using Eco Protocol without performing any swaps | ||
| - `swapAndStartBridgeTokensViaEco(BridgeData memory _bridgeData, LibSwap.SwapData[] calldata _swapData, EcoData memory _ecoData)` | ||
| - Performs swap(s) before bridging tokens using Eco Protocol | ||
|
|
||
| ## Eco Specific Parameters | ||
|
|
||
| The methods listed above take a variable labeled `_ecoData`. This data is specific to Eco Protocol and is represented as the following struct type: | ||
|
|
||
| ```solidity | ||
| /// @dev Eco specific parameters | ||
| /// @param receiverAddress Address that will receive tokens on destination chain | ||
| /// @param nonEVMReceiver Destination address for non-EVM chains (bytes format) | ||
| /// @param receivingAssetId Address of the token to receive on destination | ||
| /// @param salt Unique identifier for the intent (prevents duplicates) | ||
| /// @param routeDeadline Timestamp by which route must be executed | ||
| /// @param destinationPortal Portal address on destination chain | ||
| /// @param prover Address of the prover contract for validation | ||
| /// @param rewardDeadline Timestamp for reward claim eligibility | ||
| /// @param solverReward Native token amount to reward the solver | ||
| /// @param destinationCalls Optional calls to execute on destination | ||
| struct EcoData { | ||
| address receiverAddress; | ||
| bytes nonEVMReceiver; | ||
| address receivingAssetId; | ||
| bytes32 salt; | ||
| uint64 routeDeadline; | ||
| address destinationPortal; | ||
| address prover; | ||
| uint64 rewardDeadline; | ||
| uint256 solverReward; | ||
| IEcoPortal.Call[] destinationCalls; | ||
| } | ||
| ``` | ||
|
|
||
| ### Important Notes | ||
|
|
||
| - **Solver Reward**: The `solverReward` must be sent as `msg.value` with the transaction. This incentivizes solvers to fulfill the intent on the destination chain. | ||
| - **Non-EVM Destinations**: For non-EVM chains, set `receiver` in `BridgeData` to `NON_EVM_ADDRESS` (inherit from src/Helpers/LiFiData.sol) and provide the destination address in `nonEVMReceiver`. | ||
| - **Native Token Bridging**: When bridging native tokens, the bridge amount plus the solver reward must be sent as `msg.value`. | ||
| - **Token Approvals**: For ERC20 tokens, the facet will automatically approve the Eco Portal to spend the required amount. | ||
|
|
||
| ## Swap Data | ||
|
|
||
| Some methods accept a `SwapData _swapData` parameter. | ||
|
|
||
| Swapping is performed by a swap specific library that expects an array of calldata to can be run on various DEXs (i.e. Uniswap) to make one or multiple swaps before performing another action. | ||
|
|
||
| The swap library can be found [here](../src/Libraries/LibSwap.sol). | ||
|
|
||
| ## LiFi Data | ||
|
|
||
| Some methods accept a `BridgeData _bridgeData` parameter. | ||
|
|
||
| This parameter is strictly for analytics purposes. It's used to emit events that we can later track and index in our subgraphs and provide data on how our contracts are being used. `BridgeData` and the events we can emit can be found [here](../src/Interfaces/ILiFi.sol). | ||
|
|
||
| ## Getting Sample Calls to interact with the Facet | ||
|
|
||
| In the following some sample calls are shown that allow you to retrieve a populated transaction that can be sent to our contract via your wallet. | ||
|
|
||
| All examples use our [/quote endpoint](https://apidocs.li.fi/reference/get_quote) to retrieve a quote which contains a `transactionRequest`. This request can directly be sent to your wallet to trigger the transaction. | ||
|
|
||
| The quote result looks like the following: | ||
|
|
||
| ```javascript | ||
| const quoteResult = { | ||
| id: '0x...', // quote id | ||
| type: 'lifi', // the type of the quote (all lifi contract calls have the type "lifi") | ||
| tool: 'eco', // the bridge tool used for the transaction | ||
| action: {}, // information about what is going to happen | ||
| estimate: {}, // information about the estimated outcome of the call | ||
| includedSteps: [], // steps that are executed by the contract as part of this transaction, e.g. a swap step and a cross step | ||
| transactionRequest: { | ||
| // the transaction that can be sent using a wallet | ||
| data: '0x...', | ||
| to: '0x...', | ||
| value: '0x00', | ||
| from: '{YOUR_WALLET_ADDRESS}', | ||
| chainId: 100, | ||
| gasLimit: '0x...', | ||
| gasPrice: '0x...', | ||
| }, | ||
| } | ||
| ``` | ||
|
|
||
| A detailed explanation on how to use the /quote endpoint and how to trigger the transaction can be found [here](https://docs.li.fi/products/more-integration-options/li.fi-api/transferring-tokens-example). | ||
|
|
||
| **Hint**: Don't forget to replace `{YOUR_WALLET_ADDRESS}` with your real wallet address in the examples. | ||
|
|
||
| ### Cross Only | ||
|
|
||
| To get a transaction for a transfer from 5 USDC on Optimism to USDC on Base you can execute the following request: | ||
|
|
||
| ```shell | ||
| curl 'https://li.quest/v1/quote?fromChain=OPT&fromAmount=5000000&fromToken=USDC&toChain=BAS&toToken=USDC&slippage=0.03&allowBridges=eco&fromAddress={YOUR_WALLET_ADDRESS}' | ||
| ``` | ||
|
|
||
| ### Swap & Cross | ||
|
|
||
| To get a transaction for a transfer from 5 USDT on Optimism to USDC on Base you can execute the following request: | ||
|
|
||
| ```shell | ||
| curl 'https://li.quest/v1/quote?fromChain=OPT&fromAmount=5000000&fromToken=USDT&toChain=BAS&toToken=USDC&slippage=0.03&allowBridges=eco&fromAddress={YOUR_WALLET_ADDRESS}' | ||
| ``` | ||
ezynda3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.