-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test coverage on local vault bridge requests and attestation flow * e2e permissioned vault test coverage with fork-test * add setup for fork-testing eigenlayer bridge
- Loading branch information
Showing
5 changed files
with
223 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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,55 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Test, console} from "forge-std/Test.sol"; | ||
|
||
import {BridgeServiceManager} from "../src/EigenLayerBridge.sol"; | ||
import "../src/Events.sol"; | ||
import {Structs} from "../src/Structs.sol"; | ||
|
||
import "openzeppelin/contracts/utils/cryptography/EIP712.sol"; | ||
|
||
contract BridgeServiceManagerTest is Test, EIP712("BridgeServiceManager", "1") { | ||
BridgeServiceManager public localVault; | ||
BridgeServiceManager public remoteVault; | ||
|
||
address usdc = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); | ||
|
||
uint256 bridgeFee = 0.005 ether; | ||
uint256 crankGasCost = 100_000; | ||
|
||
address bob = address(0x123); | ||
address alice = address(0x456); | ||
address operator; | ||
uint256 operatorPrivateKey; | ||
|
||
// MAINNET EIGENLAYER CONTRACTS | ||
// https://github.com/Layr-Labs/eigenlayer-contracts?tab=readme-ov-file#deployments | ||
address delegationManager = address(0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A); | ||
address aVSDirectory = address(0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A); | ||
///https://github.com/Layr-Labs/eigenlayer-middleware/tree/mainnet | ||
address rewardsCoordinator = address(0x0BAAc79acD45A023E19345c352d8a7a83C4e5656); | ||
address stakeRegistry = address(0x006124Ae7976137266feeBFb3F4D2BE4C073139D); | ||
|
||
function setUp() public { | ||
(operator, operatorPrivateKey) = makeAddrAndKey("operator"); | ||
|
||
localVault = new BridgeServiceManager( | ||
aVSDirectory, stakeRegistry, rewardsCoordinator, delegationManager, | ||
crankGasCost, 0, bridgeFee, "PermissionedBridge", "1" | ||
); | ||
localVault.initialize(); | ||
|
||
remoteVault = new BridgeServiceManager( | ||
aVSDirectory, stakeRegistry, rewardsCoordinator, delegationManager, | ||
crankGasCost, 0, bridgeFee, "PermissionedBridge", "1" | ||
); | ||
remoteVault.initialize(); | ||
|
||
deal(bob, 1 ether); | ||
deal(usdc, bob, 1000 * 10**6); | ||
deal(usdc, address(remoteVault), 1000 * 10**6); | ||
|
||
deal(operator, 1 ether); | ||
} | ||
} |
This file contains 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,153 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Test, console} from "forge-std/Test.sol"; | ||
|
||
import "../src/PermissionedBridge.sol"; | ||
import "../src/Events.sol"; | ||
import {Structs} from "../src/Structs.sol"; | ||
|
||
import "openzeppelin/contracts/utils/cryptography/EIP712.sol"; | ||
|
||
contract PermissionedBridgeTest is Test, EIP712("PermissionedBridge", "1") { | ||
PermissionedBridge public localVault; | ||
PermissionedBridge public remoteVault; | ||
|
||
address usdc = address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48); | ||
|
||
uint256 bridgeFee = 0.005 ether; | ||
uint256 crankGasCost = 100_000; | ||
|
||
address bob = address(0x123); | ||
address alice = address(0x456); | ||
address operator; | ||
uint256 operatorPrivateKey; | ||
|
||
function setUp() public { | ||
(operator, operatorPrivateKey) = makeAddrAndKey("operator"); | ||
|
||
localVault = new PermissionedBridge(crankGasCost, 0, bridgeFee, "PermissionedBridge", "1"); | ||
localVault.initialize(); | ||
remoteVault = new PermissionedBridge(crankGasCost, 0, bridgeFee, "PermissionedBridge", "1"); | ||
remoteVault.initialize(); | ||
|
||
deal(bob, 1 ether); | ||
deal(usdc, bob, 1000 * 10**6); | ||
deal(usdc, address(remoteVault), 1000 * 10**6); | ||
|
||
deal(operator, 1 ether); | ||
localVault.setOperatorWeight(operator, 1000 ether); | ||
remoteVault.setOperatorWeight(operator, 1000 ether); | ||
} | ||
|
||
/// @dev Util function for signing bridge request data. This should be mirrored on frontends and operator implementations. | ||
function signBridgeRequestData( | ||
PermissionedBridge forVault, Structs.BridgeRequestData memory data, uint256 pkey | ||
) public returns (bytes memory) { | ||
bytes32 digest = forVault.getDigest(data); | ||
|
||
(uint8 v1, bytes32 r1, bytes32 s1) = vm.sign( | ||
pkey, | ||
digest | ||
); | ||
|
||
return abi.encodePacked(r1, s1, v1); | ||
} | ||
|
||
function testBridgeRequestEmitEvents() public returns (Structs.BridgeRequestData memory) { | ||
vm.startPrank(bob); | ||
|
||
IERC20(usdc).approve(address(localVault), 1000 * 10**6); | ||
|
||
vm.expectEmit(true, true, true, true); | ||
emit Events.BridgeRequest(bob, usdc, 0, 1000 * 10**6, 1000 * 10**6, address(remoteVault), alice, 0); | ||
|
||
localVault.bridge{value: bridgeFee}(usdc, 1000 * 10**6, 1000 * 10**6, address(remoteVault), alice); | ||
|
||
vm.stopPrank(); | ||
|
||
return Structs.BridgeRequestData( | ||
bob, | ||
usdc, | ||
1000 * 10**6, | ||
1000 * 10**6, | ||
address(remoteVault), | ||
alice, | ||
0 | ||
); | ||
} | ||
|
||
function testOperatorCanSubmitAttestation() public { | ||
testBridgeRequestEmitEvents(); | ||
|
||
( | ||
address user, | ||
address tokenAddress, | ||
uint256 amountIn, | ||
uint256 amountOut, | ||
address destinationVault, | ||
address destinationAddress, | ||
uint256 transferIndex | ||
) = localVault.bridgeRequests(0); | ||
|
||
Structs.BridgeRequestData memory bridgeRequest = Structs.BridgeRequestData( | ||
user, | ||
tokenAddress, | ||
amountIn, | ||
amountOut, | ||
destinationVault, | ||
destinationAddress, | ||
transferIndex | ||
); | ||
|
||
// NOTE: This is signed against the local vault in this example, but for cross-chain swaps this would need to | ||
// be signed against the remoteVault as the chainId is part of the EIP712 signing domain!! | ||
bytes memory attestation = signBridgeRequestData(localVault, bridgeRequest, operatorPrivateKey); | ||
|
||
|
||
vm.prank(operator); | ||
vm.expectEmit(true, true, true, true); | ||
emit Events.AVSAttestation(attestation, 0); | ||
|
||
localVault.publishAttestation(attestation, 0); | ||
} | ||
|
||
function testBridgeCompletesReleaseFunds() public { | ||
testBridgeRequestEmitEvents(); | ||
|
||
( | ||
address user, | ||
address tokenAddress, | ||
uint256 amountIn, | ||
uint256 amountOut, | ||
address destinationVault, | ||
address destinationAddress, | ||
uint256 transferIndex | ||
) = localVault.bridgeRequests(0); | ||
|
||
Structs.BridgeRequestData memory bridgeRequest = Structs.BridgeRequestData( | ||
user, | ||
tokenAddress, | ||
amountIn, | ||
amountOut, | ||
destinationVault, | ||
destinationAddress, | ||
transferIndex | ||
); | ||
|
||
// NOTE: This is signed against the local vault in this example, but for cross-chain swaps this would need to | ||
// be signed against the remoteVault as the chainId is part of the EIP712 signing domain!! | ||
bytes memory attestation = signBridgeRequestData(remoteVault, bridgeRequest, operatorPrivateKey); | ||
bytes[] memory bridgeRequestSignatures = new bytes[](1); | ||
bridgeRequestSignatures[0] = attestation; | ||
|
||
assertEq(IERC20(usdc).balanceOf(address(remoteVault)), 1000 * 10**6); | ||
assertEq(IERC20(usdc).balanceOf(alice), 0); | ||
|
||
vm.prank(alice); | ||
remoteVault.releaseFunds(bridgeRequestSignatures, bridgeRequest); | ||
|
||
assertEq(IERC20(usdc).balanceOf(address(remoteVault)), 0); | ||
assertEq(IERC20(usdc).balanceOf(alice), 1000 * 10**6); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.