Skip to content
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

Implement ChainflipFacet [ChainflipFacet v1.0.0,IChainflip v1.0.0,ReceiverChainflip v1.0.0] #984

Draft
wants to merge 62 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
9870fed
basic implementation
ezynda3 Feb 10, 2025
dce8824
update demo script
ezynda3 Feb 10, 2025
ccf78b3
handle non-EVM addresses correctly
ezynda3 Feb 10, 2025
e20815f
implement destination calls
ezynda3 Feb 10, 2025
e30c1de
Update docs, add deploy scripts and update deploy requirements
ezynda3 Feb 10, 2025
c8c2988
deploy to staging
ezynda3 Feb 12, 2025
010f168
Merge branch 'main' of github.com:lifinance/contracts into LF-12192-c…
ezynda3 Feb 12, 2025
d81478e
add swap call
ezynda3 Feb 12, 2025
88d291b
fix swap
ezynda3 Feb 13, 2025
2b6cecb
Merge branch 'main' of github.com:lifinance/contracts into LF-12192-c…
ezynda3 Feb 13, 2025
aef020a
Update src/Interfaces/IChainflip.sol
ezynda3 Feb 13, 2025
b79b794
updates
ezynda3 Feb 13, 2025
537cf76
add more tests
ezynda3 Feb 13, 2025
aa8b393
Merge branch 'LF-12192-chainflip' of github.com:lifinance/contracts i…
ezynda3 Feb 13, 2025
c353f90
Fix interface
ezynda3 Feb 13, 2025
7c619a3
Add helper
ezynda3 Feb 13, 2025
9e98ccd
flip the config structure
ezynda3 Feb 13, 2025
61d71b9
fix typo
ezynda3 Feb 14, 2025
78143ee
updates
ezynda3 Feb 14, 2025
3167425
updates
ezynda3 Feb 14, 2025
8a152f4
updates
ezynda3 Feb 14, 2025
ed037ce
updates
ezynda3 Feb 14, 2025
6d22b49
refactor
ezynda3 Feb 14, 2025
45a2f6c
udpate
ezynda3 Feb 14, 2025
6d39d19
fix demo script
ezynda3 Feb 14, 2025
de8e10a
replace testFail_ with testRevert_ pattern due to deprecation
0xDEnYO Feb 17, 2025
b1c9366
added tests for DexManagerFacet
0xDEnYO Feb 17, 2025
3550cd6
added test for AcrossFacetV3
0xDEnYO Feb 17, 2025
d68e3f5
add tests for ownershipfacet
0xDEnYO Feb 17, 2025
bb74650
Merge branch 'fix-failing-tests' into LF-12192-chainflip
ezynda3 Feb 17, 2025
ba8fdf6
improve test coverage
ezynda3 Feb 17, 2025
ba719ff
Merge branch 'main' of github.com:lifinance/contracts into LF-12192-c…
ezynda3 Feb 17, 2025
282629b
redeploy ChainflipFacet to staging
ezynda3 Feb 17, 2025
2704f8b
Update script to include destination calls
ezynda3 Feb 18, 2025
cabbb8c
Refactor
ezynda3 Feb 18, 2025
a9a49b1
Fix
ezynda3 Feb 19, 2025
feccafc
Fixes
ezynda3 Feb 19, 2025
910f61c
Fixes
ezynda3 Feb 19, 2025
676cdf9
Fixes
ezynda3 Feb 19, 2025
1df8a45
Fixes
ezynda3 Feb 19, 2025
a60a539
Fixes
ezynda3 Feb 19, 2025
3ce39a5
Fixes
ezynda3 Feb 19, 2025
f24233d
Merge branch 'main' of github.com:lifinance/contracts into LF-12192-c…
ezynda3 Feb 20, 2025
3858428
remove duplicates
ezynda3 Feb 20, 2025
498d40f
use separate receiver var for dst calls
ezynda3 Feb 21, 2025
0946038
make destination calls more type safe
ezynda3 Feb 21, 2025
0cc3bd9
add docs for ReceiverChainflip
ezynda3 Feb 21, 2025
669b017
update base readme
ezynda3 Feb 21, 2025
db71d41
update config structure
ezynda3 Feb 21, 2025
f4bce45
add return to success block so coverage is calculated correctly.
ezynda3 Feb 21, 2025
0778cc0
validate constructor args
ezynda3 Feb 24, 2025
8e7722c
mark internal
ezynda3 Feb 24, 2025
851c91e
fix
ezynda3 Feb 24, 2025
31aefd8
remove console
ezynda3 Feb 24, 2025
2727c69
validate address
ezynda3 Feb 25, 2025
6d940bb
cleanup
ezynda3 Feb 25, 2025
233571f
Merge branch 'main' into LF-12192-chainflip
ezynda3 Feb 25, 2025
d623247
update nonEVMReceiver from bytes32 to bytes
ezynda3 Mar 4, 2025
9e1c645
use LibAsset helper
ezynda3 Mar 5, 2025
c3473cb
remove unnecessary type conversion
ezynda3 Mar 5, 2025
915e560
cache native asset check result
ezynda3 Mar 5, 2025
fe2691c
gas optimization
ezynda3 Mar 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/chainflip.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"chainflipVault": {
"mainnet": "0xF5e10380213880111522dd0efD3dbb45b9f62Bcc",
"arbitrum": "0x79001a5e762f3bEFC8e5871b42F6734e00498920"
}
}
32 changes: 32 additions & 0 deletions deployments/_deployments_log_file.json
Original file line number Diff line number Diff line change
Expand Up @@ -28928,5 +28928,37 @@
]
}
}
},
"ChainflipFacet": {
"arbitrum": {
"staging": {
"1.0.0": [
{
"ADDRESS": "0xDd661337B48BEA5194F6d26F2C59fF0855E15289",
"OPTIMIZER_RUNS": "1000000",
"TIMESTAMP": "2025-02-17 17:00:59",
"CONSTRUCTOR_ARGS": "0x00000000000000000000000079001a5e762f3befc8e5871b42f6734e00498920",
"SALT": "",
"VERIFIED": "true"
}
]
}
}
},
"ReceiverChainflip": {
"mainnet": {
"staging": {
"1.0.0": [
{
"ADDRESS": "0xf0CfD9A8Fb7954C9F9948b94AD6f1Cc27Faff54c",
"OPTIMIZER_RUNS": "1000000",
"TIMESTAMP": "2025-02-18 12:28:25",
"CONSTRUCTOR_ARGS": "0x000000000000000000000000156cebba59deb2cb23742f70dcb0a11cc775591f000000000000000000000000be27f03c8e6a61e2a4b1ee7940dbcb9204744d1c000000000000000000000000f5e10380213880111522dd0efd3dbb45b9f62bcc",
"SALT": "",
"VERIFIED": "true"
}
]
}
}
}
}
15 changes: 12 additions & 3 deletions deployments/arbitrum.diamond.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,20 @@
"Version": "1.0.0"
},
"0xE15C7585636e62b88bA47A40621287086E0c2E33": {
"Name": "",
"Version": ""
"Name": "DeBridgeDlnFacet",
"Version": "1.0.0"
},
"0x08BfAc22A3B41637edB8A7920754fDb30B18f740": {
"Name": "AcrossFacetV3",
"Version": "1.1.0"
},
"0x3aF0c2dB91f75f05493E51cFcF92eC5276bc85F8": {
"Name": "",
"Version": ""
},
"0xDd661337B48BEA5194F6d26F2C59fF0855E15289": {
"Name": "ChainflipFacet",
"Version": "1.0.0"
}
},
"Periphery": {
Expand All @@ -153,8 +161,9 @@
"GasZipPeriphery": "",
"LiFiDEXAggregator": "",
"LiFuelFeeCollector": "0x94EA56D8049e93E0308B9c7d1418Baf6A7C68280",
"Permit2Proxy": "0x6FC01BC9Ff6Cdab694Ec8Ca41B21a2F04C8c37E5",
"Permit2Proxy": "0xb33Fe241BEd9bf5F694101D7498F63a0d060F999",
"ReceiverAcrossV3": "0xe4F3DEF14D61e47c696374453CD64d438FD277F8",
"ReceiverChainflip": "",
"Receiver": "0x36E9B2E8A627474683eF3b1E9Df26D2bF04396f3",
"ReceiverStargateV2": "",
"RelayerCelerIM": "0xa1Ed8783AC96385482092b82eb952153998e9b70",
Expand Down
4 changes: 2 additions & 2 deletions deployments/arbitrum.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"DeBridgeDlnFacet": "0xE15C7585636e62b88bA47A40621287086E0c2E33",
"MayanFacet": "0xd596C903d78870786c5DB0E448ce7F87A65A0daD",
"StandardizedCallFacet": "0xA7ffe57ee70Ac4998e9E9fC6f17341173E081A8f",
"MayanFacet": "0xd596C903d78870786c5DB0E448ce7F87A65A0daD",
"GenericSwapFacetV3": "0xFf6Fa203573Baaaa4AE375EB7ac2819d539e16FF",
"CalldataVerificationFacet": "0x90B5b319cA20D9E466cB5b843952363C34d1b54E",
"AcrossFacetPacked": "0x7A3770a9504924d99D38BBba4F0116B756393Eb3",
Expand All @@ -51,5 +50,6 @@
"AcrossFacetV3": "0x08BfAc22A3B41637edB8A7920754fDb30B18f740",
"ReceiverAcrossV3": "0xe4F3DEF14D61e47c696374453CD64d438FD277F8",
"AcrossFacetPackedV3": "0x21767081Ff52CE5563A29f27149D01C7127775A2",
"RelayFacet": "0x3cf7dE0e31e13C93c8Aada774ADF1C7eD58157f5"
"RelayFacet": "0x3cf7dE0e31e13C93c8Aada774ADF1C7eD58157f5",
"ChainflipFacet": "0xDd661337B48BEA5194F6d26F2C59fF0855E15289"
}
5 changes: 4 additions & 1 deletion deployments/mainnet.diamond.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@
"ReceiverAcrossV3": "",
"ReceiverStargateV2": "",
"RelayerCelerIM": "",
"TokenWrapper": "0x5215E9fd223BC909083fbdB2860213873046e45d"
"TokenWrapper": "0x5215E9fd223BC909083fbdB2860213873046e45d",
"GasZipPeriphery": "",
"Permit2Proxy": "",
"ReceiverChainflip": "0x5DFcEbB675F3cA2049d4b6791Ce2284EA940204a"
}
}
}
3 changes: 2 additions & 1 deletion deployments/mainnet.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@
"SquidFacet": "0x933A3AfE2087FB8F5c9EE9A033477C42CC14c18E",
"SynapseBridgeFacet": "0x57F98A94AC66e197AF6776D5c094FF0da2C0B198",
"ThorSwapFacet": "0xa696287F37d21D566B9A80AC29b2640FF910C176",
"StandardizedCallFacet": "0x637Ac9AddC9C38b3F52878E11620a9060DC71d8B"
"StandardizedCallFacet": "0x637Ac9AddC9C38b3F52878E11620a9060DC71d8B",
"ReceiverChainflip": "0xf0CfD9A8Fb7954C9F9948b94AD6f1Cc27Faff54c"
}
108 changes: 108 additions & 0 deletions docs/ChainflipFacet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Chainflip Facet

## How it works

The Chainflip Facet enables cross-chain token transfers using Chainflip's protocol. It supports both EVM chains (Ethereum, Arbitrum) and non-EVM chains (Solana, Bitcoin) as destinations.

```mermaid
graph LR;
D{LiFiDiamond}-- DELEGATECALL -->ChainflipFacet;
ChainflipFacet -- CALL --> ChainflipVault[Chainflip Vault]
```

## Public Methods

- `function startBridgeTokensViaChainflip(BridgeData calldata _bridgeData, ChainflipData calldata _chainflipData)`
- Bridges tokens using Chainflip without performing any swaps
- `swapAndStartBridgeTokensViaChainflip(BridgeData memory _bridgeData, LibSwap.SwapData[] calldata _swapData, ChainflipData memory _chainflipData)`
- Performs swap(s) before bridging tokens using Chainflip

## Chainflip Specific Parameters

The methods listed above take a variable labeled `_chainflipData`. This data is specific to Chainflip and is represented as the following struct type:

```solidity
struct ChainflipData {
bytes32 nonEVMReceiver; // Destination address for non-EVM chains (Solana, Bitcoin)
uint32 dstToken; // Token identifier on the destination chain
bytes message; // Message that is passed to the destination address for cross-chain messaging
uint256 gasAmount; // Gas budget for the call on the destination chain
bytes cfParameters; // Additional parameters for future features
}
```

For non-EVM destinations (Solana, Bitcoin), set the `receiver` in `BridgeData` to `LibAsset.NON_EVM_ADDRESS` and provide the destination address in `nonEVMReceiver`.

## Supported Chains

The facet supports the following chains with their respective IDs:

- Ethereum (1)
- Arbitrum (42161)
- Solana (1151111081099710)
- Bitcoin (20000000000001)

[Reference](https://docs.chainflip.io/swapping/integrations/advanced/vault-swaps#supported-chains)

## Swap Data

Some methods accept a `SwapData _swapData` parameter.

Swapping is performed by a swap specific library that expects an array of calldata that 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: 'chainflip', // 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 USDC on Ethereum to USDC on Arbitrum you can execute the following request:

```shell
curl 'https://li.quest/v1/quote?fromChain=ETH&fromAmount=1000000&fromToken=USDC&toChain=ARB&toToken=USDC&slippage=0.03&allowBridges=chainflip&fromAddress={YOUR_WALLET_ADDRESS}'
```

### Swap & Cross

To get a transaction for a transfer from USDT on Ethereum to USDC on Arbitrum you can execute the following request:

```shell
curl 'https://li.quest/v1/quote?fromChain=ETH&fromAmount=1000000&fromToken=USDT&toChain=ARB&toToken=USDC&slippage=0.03&allowBridges=chainflip&fromAddress={YOUR_WALLET_ADDRESS}'
```
Loading
Loading