Skip to content

Commit e2ac395

Browse files
committed
Add v1.5 contracts
1 parent 0530cbd commit e2ac395

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3634
-583
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.0;
3+
4+
import {
5+
ExecuteArgs,
6+
TransferInfo,
7+
DestinationTransferStatus
8+
} from "../libraries/LibConnextStorage.sol";
9+
import { TokenId } from "../libraries/TokenId.sol";
10+
11+
interface IConnext {
12+
// ============ BRIDGE ==============
13+
14+
function xcall(
15+
uint32 _destination,
16+
address _to,
17+
address _asset,
18+
address _delegate,
19+
uint256 _amount,
20+
uint256 _slippage,
21+
bytes calldata _callData
22+
) external payable returns (bytes32);
23+
24+
function xcall(
25+
uint32 _destination,
26+
address _to,
27+
address _asset,
28+
address _delegate,
29+
uint256 _amount,
30+
uint256 _slippage,
31+
bytes calldata _callData,
32+
uint256 _relayerFee
33+
) external returns (bytes32);
34+
35+
function xcallIntoLocal(
36+
uint32 _destination,
37+
address _to,
38+
address _asset,
39+
address _delegate,
40+
uint256 _amount,
41+
uint256 _slippage,
42+
bytes calldata _callData
43+
) external payable returns (bytes32);
44+
45+
function execute(ExecuteArgs calldata _args) external returns (bytes32 transferId);
46+
47+
function forceUpdateSlippage(TransferInfo calldata _params, uint256 _slippage) external;
48+
49+
function forceReceiveLocal(TransferInfo calldata _params) external;
50+
51+
function bumpTransfer(bytes32 _transferId) external payable;
52+
53+
function routedTransfers(bytes32 _transferId) external view returns (address[] memory);
54+
55+
function transferStatus(bytes32 _transferId) external view returns (DestinationTransferStatus);
56+
57+
function remote(uint32 _domain) external view returns (address);
58+
59+
function domain() external view returns (uint256);
60+
61+
function nonce() external view returns (uint256);
62+
63+
function approvedSequencers(address _sequencer) external view returns (bool);
64+
65+
function xAppConnectionManager() external view returns (address);
66+
67+
// ============ ROUTERS ==============
68+
69+
function LIQUIDITY_FEE_NUMERATOR() external view returns (uint256);
70+
71+
function LIQUIDITY_FEE_DENOMINATOR() external view returns (uint256);
72+
73+
function getRouterApproval(address _router) external view returns (bool);
74+
75+
function getRouterRecipient(address _router) external view returns (address);
76+
77+
function getRouterOwner(address _router) external view returns (address);
78+
79+
function getProposedRouterOwner(address _router) external view returns (address);
80+
81+
function getProposedRouterOwnerTimestamp(address _router) external view returns (uint256);
82+
83+
function maxRoutersPerTransfer() external view returns (uint256);
84+
85+
function routerBalances(address _router, address _asset) external view returns (uint256);
86+
87+
function getRouterApprovalForPortal(address _router) external view returns (bool);
88+
89+
function initializeRouter(address _owner, address _recipient) external;
90+
91+
function setRouterRecipient(address _router, address _recipient) external;
92+
93+
function proposeRouterOwner(address _router, address _proposed) external;
94+
95+
function acceptProposedRouterOwner(address _router) external;
96+
97+
function addRouterLiquidityFor(
98+
uint256 _amount,
99+
address _local,
100+
address _router
101+
) external payable;
102+
103+
function addRouterLiquidity(uint256 _amount, address _local) external payable;
104+
105+
function removeRouterLiquidityFor(
106+
TokenId memory _canonical,
107+
uint256 _amount,
108+
address payable _to,
109+
address _router
110+
) external;
111+
112+
function removeRouterLiquidity(
113+
TokenId memory _canonical,
114+
uint256 _amount,
115+
address payable _to
116+
) external;
117+
118+
// ============ TOKEN_FACET ==============
119+
function adoptedToCanonical(address _adopted) external view returns (TokenId memory);
120+
121+
function approvedAssets(TokenId calldata _canonical) external view returns (bool);
122+
123+
// ============ Functions added to the min interface by Renzo ==============
124+
125+
// used by the smart contract to swap tokens
126+
function swapExact(
127+
bytes32 canonicalId,
128+
uint256 amountIn,
129+
address assetIn,
130+
address assetOut,
131+
uint256 minAmountOut,
132+
uint256 deadline
133+
) external payable returns (uint256);
134+
135+
// Used by the UI to calculate slippage
136+
function calculateSwap(
137+
bytes32 canonicalId,
138+
uint8 tokenIndexFrom,
139+
uint8 tokenIndexTo,
140+
uint256 dx
141+
) external view returns (uint256);
142+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.0;
3+
4+
interface IWeth {
5+
function deposit() external payable;
6+
7+
function withdraw(uint256 value) external;
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.0;
3+
4+
interface IXReceiver {
5+
function xReceive(
6+
bytes32 _transferId,
7+
uint256 _amount,
8+
address _asset,
9+
address _originSender,
10+
uint32 _origin,
11+
bytes memory _callData
12+
) external returns (bytes memory);
13+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.13;
3+
4+
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
5+
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
6+
import { IXERC20 } from "../../xERC20/interfaces/IXERC20.sol";
7+
import { IXERC20Lockbox } from "../../xERC20/interfaces/IXERC20Lockbox.sol";
8+
9+
interface IXERC20Registry {
10+
function getXERC20(address erc20) external view returns (address xerc20);
11+
12+
function getERC20(address xerc20) external view returns (address erc20);
13+
14+
function getLockbox(address erc20) external view returns (address xerc20);
15+
}
16+
17+
interface L1StandardBridge {
18+
function bridgeERC20To(
19+
address _localToken,
20+
address _remoteToken,
21+
address _to,
22+
uint256 _amount,
23+
uint32 _minGasLimit,
24+
bytes calldata _extraData
25+
) external;
26+
}
27+
28+
/// @notice This adapter is only used for sending assets from Ethereum mainnet to Blast.
29+
/// @dev Combines Lockbox deposit and Blast bridge's BridgeERC20 call to minimize user transactions.
30+
contract LockboxAdapterBlast {
31+
address immutable blastStandardBridge;
32+
address immutable registry;
33+
34+
// ERRORS
35+
error InvalidRemoteToken(address _remoteToken);
36+
error AmountLessThanZero();
37+
error InvalidAddress();
38+
39+
constructor(address _blastStandardBridge, address _registry) {
40+
// Sanity check
41+
if (_blastStandardBridge == address(0) || _registry == address(0)) {
42+
revert InvalidAddress();
43+
}
44+
45+
blastStandardBridge = _blastStandardBridge;
46+
registry = _registry;
47+
}
48+
49+
/// @dev Combines Lockbox deposit and Blast bridge's BridgeERC20To call.
50+
/// @param _to The recipient or contract address on destination.
51+
/// @param _erc20 The address of the adopted ERC20 on the origin chain.
52+
/// @param _remoteToken The address of the asset to be received on the destination chain.
53+
/// @param _amount The amount of asset to bridge.
54+
/// @param _minGasLimit Minimum amount of gas that the bridge can be relayed with.
55+
/// @param _extraData Extra data to be sent with the transaction.
56+
function bridgeTo(
57+
address _to,
58+
address _erc20,
59+
address _remoteToken,
60+
uint256 _amount,
61+
uint32 _minGasLimit,
62+
bytes calldata _extraData
63+
) external {
64+
// Sanity check
65+
if (_amount <= 0) {
66+
revert AmountLessThanZero();
67+
}
68+
69+
address xerc20 = IXERC20Registry(registry).getXERC20(_erc20);
70+
address lockbox = IXERC20Registry(registry).getLockbox(xerc20);
71+
72+
// Sanity check
73+
if (xerc20 == address(0) || lockbox == address(0)) {
74+
revert InvalidAddress();
75+
}
76+
77+
// If using xERC20, the assumption is that the contract should be deployed at same address
78+
// on both networks.
79+
if (xerc20 != _remoteToken) {
80+
revert InvalidRemoteToken(_remoteToken);
81+
}
82+
83+
SafeERC20.safeTransferFrom(IERC20(_erc20), msg.sender, address(this), _amount);
84+
SafeERC20.safeApprove(IERC20(_erc20), lockbox, _amount);
85+
IXERC20Lockbox(lockbox).deposit(_amount);
86+
SafeERC20.safeApprove(IERC20(xerc20), blastStandardBridge, _amount);
87+
L1StandardBridge(blastStandardBridge).bridgeERC20To(
88+
xerc20,
89+
_remoteToken,
90+
_to,
91+
_amount,
92+
_minGasLimit,
93+
_extraData
94+
);
95+
}
96+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.0;
3+
4+
/**
5+
* @notice Enum representing status of destination transfer
6+
* @dev Status is only assigned on the destination domain, will always be "none" for the
7+
* origin domains
8+
* @return uint - Index of value in enum
9+
*/
10+
enum DestinationTransferStatus {
11+
None, // 0
12+
Reconciled, // 1
13+
Executed, // 2
14+
Completed // 3 - executed + reconciled
15+
}
16+
17+
/**
18+
* @notice These are the parameters that will remain constant between the
19+
* two chains. They are supplied on `xcall` and should be asserted on `execute`
20+
* @property to - The account that receives funds, in the event of a crosschain call,
21+
* will receive funds if the call fails.
22+
*
23+
* @param originDomain - The originating domain (i.e. where `xcall` is called)
24+
* @param destinationDomain - The final domain (i.e. where `execute` / `reconcile` are called)\
25+
* @param canonicalDomain - The canonical domain of the asset you are bridging
26+
* @param to - The address you are sending funds (and potentially data) to
27+
* @param delegate - An address who can execute txs on behalf of `to`, in addition to allowing relayers
28+
* @param receiveLocal - If true, will use the local asset on the destination instead of adopted.
29+
* @param callData - The data to execute on the receiving chain. If no crosschain call is needed, then leave empty.
30+
* @param slippage - Slippage user is willing to accept from original amount in expressed in BPS (i.e. if
31+
* a user takes 1% slippage, this is expressed as 1_000)
32+
* @param originSender - The msg.sender of the xcall
33+
* @param bridgedAmt - The amount sent over the bridge (after potential AMM on xcall)
34+
* @param normalizedIn - The amount sent to `xcall`, normalized to 18 decimals
35+
* @param nonce - The nonce on the origin domain used to ensure the transferIds are unique
36+
* @param canonicalId - The unique identifier of the canonical token corresponding to bridge assets
37+
*/
38+
struct TransferInfo {
39+
uint32 originDomain;
40+
uint32 destinationDomain;
41+
uint32 canonicalDomain;
42+
address to;
43+
address delegate;
44+
bool receiveLocal;
45+
bytes callData;
46+
uint256 slippage;
47+
address originSender;
48+
uint256 bridgedAmt;
49+
uint256 normalizedIn;
50+
uint256 nonce;
51+
bytes32 canonicalId;
52+
}
53+
54+
/**
55+
* @notice
56+
* @param params - The TransferInfo. These are consistent across sending and receiving chains.
57+
* @param routers - The routers who you are sending the funds on behalf of.
58+
* @param routerSignatures - Signatures belonging to the routers indicating permission to use funds
59+
* for the signed transfer ID.
60+
* @param sequencer - The sequencer who assigned the router path to this transfer.
61+
* @param sequencerSignature - Signature produced by the sequencer for path assignment accountability
62+
* for the path that was signed.
63+
*/
64+
struct ExecuteArgs {
65+
TransferInfo params;
66+
address[] routers;
67+
bytes[] routerSignatures;
68+
address sequencer;
69+
bytes sequencerSignature;
70+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-License-Identifier: MIT OR Apache-2.0
2+
pragma solidity ^0.8.0;
3+
4+
// ============= Structs =============
5+
6+
// Tokens are identified by a TokenId:
7+
// domain - 4 byte chain ID of the chain from which the token originates
8+
// id - 32 byte identifier of the token address on the origin chain, in that chain's address format
9+
struct TokenId {
10+
uint32 domain;
11+
bytes32 id;
12+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// SPDX-License-Identifier: BUSL-1.1
2+
pragma solidity 0.8.19;
3+
4+
interface IxRenzoBridge {
5+
/**
6+
* @notice Contains destination data for CCIP call
7+
*
8+
* @param destinationChainSelector chainlink CCIP destination chain selector ID
9+
* @param _renzoReceiver xRenzoDeposit receiver contract
10+
*/
11+
struct CCIPDestinationParam {
12+
uint64 destinationChainSelector;
13+
address _renzoReceiver;
14+
}
15+
16+
/**
17+
* @notice Contains destination data for Connext xCall
18+
*
19+
* @param destinationChainSelector chainlink Connext destination chain domain ID
20+
* @param _renzoReceiver xRenzoDeposit receiver contract
21+
* @param relayerFee relayer Fee required for xCall
22+
*/
23+
struct ConnextDestinationParam {
24+
uint32 destinationDomainId;
25+
address _renzoReceiver;
26+
uint256 relayerFee;
27+
}
28+
29+
function sendPrice(
30+
CCIPDestinationParam[] calldata _destinationParam,
31+
ConnextDestinationParam[] calldata _connextDestinationParam
32+
) external payable;
33+
}

0 commit comments

Comments
 (0)