This repository contains examples of the smart contracts that interact with LI.FI Diamond.
LI.FI is a cross-chain bridge aggregation protocol that supports any-2-any swaps by aggregating bridges and connecting them to DEX aggregators. For more information about LI.FI
- Send request to the LI.FI API.
For more information about LI.FI API, you can check here. - Get calldata from the LI.FI API.
You can check how to get a quote for a token transfer here.
Once you request the quote for a token transfer, you can find the calldata in thetransactionRequest
in response. - Pass the calldata, the address of LI.FI Diamond contract and token information to demo contracts.
- Custom logics can be implemented(as ForwardWithCustomLogic) to do some actions such as swaps, unstaking, etc before forwarding calldata.
- In the contracts, they set approval for the LI.FI Diamond.
- Execute the call data on the LI.FI contracts.
graph TD;
U{dApp}-- 1. Request -->A([LI.FI API])-- 2. calldata -->U;
U-- 3. Call -->F{Forward Contract};
F-- 4. Forward calldata -->D{LiFiDiamond};
D-- DELEGATECALL -->AcrossFacet;
D-- DELEGATECALL -->HopFacet;
D-- DELEGATECALL -->HyphenFacet;
D-- DELEGATECALL -->StargateFacet;
subgraph Facets
AcrossFacet
HopFacet
HyphenFacet
StargateFacet
end
F{Forward Contract}<-.->C(Custom Logic)<-->P1[Protocol 1] & Pn[Protocol n]
subgraph Protocols
P1
...:::transparent
classDef transparent fill:#0000
classDef transparent stroke:#0000
Pn
end
To learn more about LI.FI contracts, please check here.
contracts
│ README.md // you are here
│ ... // setup and development configuration files
│
├─── src // the contract code
│ ├── interfaces // interface definitions
│ ├── utils // utility contracts
│ ├── Forward.sol // example contract to forward calldata
│ └── ForwardWithCustomLogic.sol // example contract to forward calldata with custom logic
│
└─── test // contract unit tests
├─── Forward // tests for Forward contract
└─── ForwardWithCustomLogic // tests for ForwardWithCustomLogic contract