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

Relay Bridge (v1.0.0) [RelayFacet v1.0.0,LibAsset v1.0.1] #843

Merged
merged 49 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
2e55975
Scaffold Relay Facet
ezynda3 Oct 29, 2024
37e76b0
Add verification modifier
ezynda3 Oct 29, 2024
c970202
Add calldata
ezynda3 Oct 29, 2024
9c85cf6
Implement ERC20
ezynda3 Oct 29, 2024
119b8b5
Implement tests
ezynda3 Oct 29, 2024
d669597
Deploy to staging
ezynda3 Oct 30, 2024
7622a00
Add deployment requirements
ezynda3 Oct 30, 2024
7d14117
Implement demo for Relay
ezynda3 Oct 31, 2024
8695c5e
Update documentation
ezynda3 Oct 31, 2024
0a0fa7e
Update doc link
ezynda3 Oct 31, 2024
e0d7f1c
Deploy to POL and OP staging
ezynda3 Oct 31, 2024
458674f
Remove unneeded comment
ezynda3 Oct 31, 2024
eb6d35f
Fixes
ezynda3 Oct 31, 2024
674e253
Fixes
ezynda3 Oct 31, 2024
edc0ddc
Merge branch 'main' into LF10073-relay-bridge
ezynda3 Oct 31, 2024
7049a82
Add swap and bridge TX to demo
ezynda3 Oct 31, 2024
2bae776
Add params needed to handle non EVM addresses
ezynda3 Nov 1, 2024
ecc49ce
Update tests to handle non-evm
ezynda3 Nov 1, 2024
ad145c0
Redeploy to staging
ezynda3 Nov 4, 2024
bc4295f
Update Relay Demo
ezynda3 Nov 4, 2024
a91b204
add revert case
ezynda3 Nov 5, 2024
c09b84d
use standardized method for creating hash
ezynda3 Nov 5, 2024
0da22f7
add comments for clarity
ezynda3 Nov 5, 2024
09c6be5
Merge branch 'main' into LF10073-relay-bridge
ezynda3 Nov 5, 2024
1f10049
add URL for listing chain ids
ezynda3 Nov 5, 2024
e104a62
fix typo
ezynda3 Nov 5, 2024
634a261
add explicit test for non-evm chains
ezynda3 Nov 7, 2024
4c1100f
add comments fix typo
ezynda3 Nov 7, 2024
250469b
add NON_EVM_ADDRESS constant to LibAsset
ezynda3 Nov 7, 2024
03f1711
update name
ezynda3 Nov 7, 2024
26c1ee7
fix typo
ezynda3 Nov 7, 2024
4e9b7d4
remove unused imports
ezynda3 Nov 7, 2024
54463f1
Update and redeploy to staging
ezynda3 Nov 7, 2024
d4bee97
Use floating pragma
ezynda3 Nov 11, 2024
0d4a6d8
Merge branch 'main' into LF10073-relay-bridge
ezynda3 Nov 11, 2024
aa4d0e6
Update version
ezynda3 Nov 11, 2024
5c18202
Add more tests
ezynda3 Nov 11, 2024
7f3f8d8
Add even more tests
ezynda3 Nov 11, 2024
c8de86d
Use mock to surgically make call fail
ezynda3 Nov 11, 2024
291d0a7
Add explicit test for _getMappedChainId()
ezynda3 Nov 12, 2024
2efd99e
update event
ezynda3 Nov 26, 2024
4b3535f
prevent replay
ezynda3 Nov 26, 2024
f285130
prevent empty non-evm addresses
ezynda3 Nov 26, 2024
a1fcd9a
remove unused import
ezynda3 Nov 26, 2024
fb3c383
Update audit log
ezynda3 Dec 12, 2024
e35fbd8
Merge branch 'main' into LF10073-relay-bridge
ezynda3 Dec 12, 2024
254de71
Update audit log
ezynda3 Dec 12, 2024
816030a
Test constructor
ezynda3 Dec 12, 2024
7968629
sort audited contracts
ezynda3 Dec 13, 2024
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
46 changes: 46 additions & 0 deletions config/relay.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"mainnet": {
"relayReceiver": "0xa5f565650890fba1824ee0f21ebbbf660a179934",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
},
"optimism": {
"relayReceiver": "0xa5f565650890fba1824ee0f21ebbbf660a179934",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
},
"polygon": {
"relayReceiver": "0xa5f565650890fba1824ee0f21ebbbf660a179934",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
},
"boba": {
"relayReceiver": "0xa06e1351e2fd2d45b5d35633ca7ecf328684a109",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
},
"arbitrum": {
"relayReceiver": "0xa5f565650890fba1824ee0f21ebbbf660a179934",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
},
"avalanche": {
"relayReceiver": "0xa5f565650890fba1824ee0f21ebbbf660a179934",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
},
"blast": {
"relayReceiver": "0xa5f565650890fba1824ee0f21ebbbf660a179934",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
},
"mode": {
"relayReceiver": "0xa5f565650890fba1824ee0f21ebbbf660a179934",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
},
"linea": {
"relayReceiver": "0x00000000aa467eba42a3d604b3d74d63b2b6c6cb",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
},
"taiko": {
"relayReceiver": "0xa5f565650890fba1824ee0f21ebbbf660a179934",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
},
"scroll": {
"relayReceiver": "0xa5f565650890fba1824ee0f21ebbbf660a179934",
"relaySolver": "0xf70da97812CB96acDF810712Aa562db8dfA3dbEF"
}
}
ezynda3 marked this conversation as resolved.
Show resolved Hide resolved
44 changes: 44 additions & 0 deletions deployments/_deployments_log_file.json
Original file line number Diff line number Diff line change
Expand Up @@ -24358,5 +24358,49 @@
]
}
}
},
"RelayFacet": {
"arbitrum": {
"staging": {
"1.0.0": [
{
"ADDRESS": "0x74763722d92832d247cFa92825b06098cf72BAA2",
ezynda3 marked this conversation as resolved.
Show resolved Hide resolved
"OPTIMIZER_RUNS": "1000000",
"TIMESTAMP": "2024-10-31 10:21:46",
"CONSTRUCTOR_ARGS": "0x000000000000000000000000a5f565650890fba1824ee0f21ebbbf660a179934000000000000000000000000f70da97812cb96acdf810712aa562db8dfa3dbef",
"SALT": "",
"VERIFIED": "true"
}
]
}
},
"polygon": {
"staging": {
"1.0.0": [
{
"ADDRESS": "0x74763722d92832d247cFa92825b06098cf72BAA2",
"OPTIMIZER_RUNS": "1000000",
"TIMESTAMP": "2024-10-31 11:59:26",
"CONSTRUCTOR_ARGS": "0x000000000000000000000000a5f565650890fba1824ee0f21ebbbf660a179934000000000000000000000000f70da97812cb96acdf810712aa562db8dfa3dbef",
"SALT": "",
"VERIFIED": "true"
}
]
}
},
"optimism": {
"staging": {
"1.0.0": [
{
"ADDRESS": "0x74763722d92832d247cFa92825b06098cf72BAA2",
"OPTIMIZER_RUNS": "1000000",
"TIMESTAMP": "2024-10-31 12:02:46",
"CONSTRUCTOR_ARGS": "0x000000000000000000000000a5f565650890fba1824ee0f21ebbbf660a179934000000000000000000000000f70da97812cb96acdf810712aa562db8dfa3dbef",
"SALT": "",
"VERIFIED": "true"
}
]
}
}
}
}
8 changes: 4 additions & 4 deletions deployments/arbitrum.diamond.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@
"Name": "",
"Version": ""
},
"0x2b64B62cbCfB38560222eBcfbbc4e65eC34c8Ce8": {
"Name": "",
"Version": ""
"0x74763722d92832d247cFa92825b06098cf72BAA2": {
"Name": "RelayFacet",
"Version": "1.0.0"
},
"0x6124C65B6264bE13f059b7C3A891a5b77DA8Bd95": {
"Name": "AcrossFacetV3",
Expand Down Expand Up @@ -160,8 +160,8 @@
"FeeCollector": "0x7F8E9bEBd1Dea263A36a6916B99bd84405B9654a",
"LiFiDEXAggregator": "",
"LiFuelFeeCollector": "0x94EA56D8049e93E0308B9c7d1418Baf6A7C68280",
"Receiver": "0x36E9B2E8A627474683eF3b1E9Df26D2bF04396f3",
"ReceiverAcrossV3": "0x3877f47B560819E96BBD7e7700a02dfACe36D696",
"Receiver": "0x36E9B2E8A627474683eF3b1E9Df26D2bF04396f3",
"ReceiverStargateV2": "",
"RelayerCelerIM": "0xa1Ed8783AC96385482092b82eb952153998e9b70",
"TokenWrapper": "0xF63b27AE2Dc887b88f82E2Cc597d07fBB2E78E70"
Expand Down
5 changes: 3 additions & 2 deletions deployments/arbitrum.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@
"EmergencyPauseFacet": "0x17Bb203F42d8e404ac7E8dB6ff972B7E8473850b",
"AcrossFacetV3": "0x6124C65B6264bE13f059b7C3A891a5b77DA8Bd95",
"ReceiverAcrossV3": "0x3877f47B560819E96BBD7e7700a02dfACe36D696",
"AcrossFacetPackedV3": "0x4352459F6BE1C7D1278F8c34Bb598b0feeB50f8b"
}
"AcrossFacetPackedV3": "0x4352459F6BE1C7D1278F8c34Bb598b0feeB50f8b",
"RelayFacet": "0x74763722d92832d247cFa92825b06098cf72BAA2"
}
6 changes: 5 additions & 1 deletion deployments/optimism.diamond.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@
"0x4352459F6BE1C7D1278F8c34Bb598b0feeB50f8b": {
"Name": "AcrossFacetPackedV3",
"Version": "1.0.0"
},
"0x74763722d92832d247cFa92825b06098cf72BAA2": {
"Name": "RelayFacet",
"Version": "1.0.0"
}
},
"Periphery": {
Expand All @@ -132,8 +136,8 @@
"FeeCollector": "0x7F8E9bEBd1Dea263A36a6916B99bd84405B9654a",
"LiFiDEXAggregator": "",
"LiFuelFeeCollector": "0x94EA56D8049e93E0308B9c7d1418Baf6A7C68280",
"Receiver": "0x36E9B2E8A627474683eF3b1E9Df26D2bF04396f3",
"ReceiverAcrossV3": "0x3877f47B560819E96BBD7e7700a02dfACe36D696",
"Receiver": "0x36E9B2E8A627474683eF3b1E9Df26D2bF04396f3",
"ReceiverStargateV2": "",
"RelayerCelerIM": "0xa1Ed8783AC96385482092b82eb952153998e9b70",
"TokenWrapper": "0xF63b27AE2Dc887b88f82E2Cc597d07fBB2E78E70"
Expand Down
5 changes: 3 additions & 2 deletions deployments/optimism.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@
"EmergencyPauseFacet": "0x17Bb203F42d8e404ac7E8dB6ff972B7E8473850b",
"AcrossFacetV3": "0x6124C65B6264bE13f059b7C3A891a5b77DA8Bd95",
"ReceiverAcrossV3": "0x3877f47B560819E96BBD7e7700a02dfACe36D696",
"AcrossFacetPackedV3": "0x4352459F6BE1C7D1278F8c34Bb598b0feeB50f8b"
}
"AcrossFacetPackedV3": "0x4352459F6BE1C7D1278F8c34Bb598b0feeB50f8b",
"RelayFacet": "0x74763722d92832d247cFa92825b06098cf72BAA2"
}
6 changes: 5 additions & 1 deletion deployments/polygon.diamond.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@
"0xE15C7585636e62b88bA47A40621287086E0c2E33": {
"Name": "",
"Version": ""
},
"0x74763722d92832d247cFa92825b06098cf72BAA2": {
"Name": "RelayFacet",
"Version": "1.0.0"
}
},
"Periphery": {
Expand All @@ -128,8 +132,8 @@
"FeeCollector": "0x7F8E9bEBd1Dea263A36a6916B99bd84405B9654a",
"LiFiDEXAggregator": "",
"LiFuelFeeCollector": "0x94EA56D8049e93E0308B9c7d1418Baf6A7C68280",
"Receiver": "0x36E9B2E8A627474683eF3b1E9Df26D2bF04396f3",
"ReceiverAcrossV3": "",
"Receiver": "0x36E9B2E8A627474683eF3b1E9Df26D2bF04396f3",
"ReceiverStargateV2": "",
"ReceiverAcrossV3": "",
"RelayerCelerIM": "0xa1Ed8783AC96385482092b82eb952153998e9b70",
Expand Down
5 changes: 3 additions & 2 deletions deployments/polygon.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
"CelerCircleBridgeFacet": "0x371E073f6A09DCBEE1D2Ac56E940F878a0Ba9DAE",
"HopFacetOptimized": "0xf82135385765f1324257ffF74489F16382EBBb8A",
"SymbiosisFacet": "0x21571D628B0bCBeb954D5933A604eCac35bAF2c7",
"AcrossFacetV3": "0xe2e5428F972d9C0a5Ba433e0c402752b472dB248"
}
"AcrossFacetV3": "0xe2e5428F972d9C0a5Ba433e0c402752b472dB248",
"RelayFacet": "0x74763722d92832d247cFa92825b06098cf72BAA2"
}
1 change: 1 addition & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- [Optimism Bridge Facet](./OptimismBridgeFacet.md)
- [Periphery Registry Facet](./PeripheryRegistryFacet.md)
- [Polygon Bridge Facet](./PolygonBridgeFacet.md)
- [Relay Facet](./RelayFacet.md)
- [Ronin Bridge Facet](./RoninBridgeFacet.md)
- [Squid Facet](./SquidFacet.md)
- [Standardized Call Facet](./StandardizedCallFacet.md)
Expand Down
100 changes: 100 additions & 0 deletions docs/RelayFacet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Relay Facet

Relay is a cross-chain payments system enabling instant, low-cost bridging and cross-chain execution using relayers as financial agents.

## How it works

The Relay Facet works by sending funds directly to the RelayReceiver contract in the case of Native tokens or sending tokens directly
to the official Relay solver EOA along with extra calldata bytes that reference a prefecthed quote id

```mermaid
graph LR;
D{LiFiDiamond}-- DELEGATECALL -->RelayFacet;
RelayFacet -- CALL --> C(Relay)
```

## Public Methods

- `function startBridgeTokensViaRelay(BridgeData calldata _bridgeData, RelayData calldata _relayData)`
- Simply bridges tokens using relay
- `swapAndStartBridgeTokensViaRelay(BridgeData memory _bridgeData, LibSwap.SwapData[] calldata _swapData, relayData memory _relayData)`
- Performs swap(s) before bridging tokens using relay

## relay Specific Parameters

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

```solidity
/// @param requestId the id of the quote request.
/// @param receivingAssetId
/// @param callData the bridging calldata generated by the relay api
ezynda3 marked this conversation as resolved.
Show resolved Hide resolved
struct RelayData {
bytes32 requestId;
address receivingAssetId;
bytes callData;
bytes signature;
}
```

## 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: 'relay', // 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 30 USDC.e on Avalanche to USDC on Binance you can execute the following request:

```shell
curl 'https://li.quest/v1/quote?fromChain=AVA&fromAmount=30000000&fromToken=USDC&toChain=BSC&toToken=USDC&slippage=0.03&allowBridges=relay&fromAddress={YOUR_WALLET_ADDRESS}'
```

### Swap & Cross

To get a transaction for a transfer from 30 USDT on Avalanche to USDC on Binance you can execute the following request:

```shell
curl 'https://li.quest/v1/quote?fromChain=AVA&fromAmount=30000000&fromToken=USDT&toChain=BSC&toToken=USDC&slippage=0.03&allowBridges=relay&fromAddress={YOUR_WALLET_ADDRESS}'
```
Loading
Loading