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

L02 Rename ResolverMock -> ResolverExample #97

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { IBaseEscrow } from "../interfaces/IBaseEscrow.sol";
/**
* @title Interface for the sample implementation of a Resolver contract for cross-chain swap.
*/
interface IResolverMock {
interface IResolverExample {
error InvalidLength();
error LengthMismatch();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import { RevertReasonForwarder } from "solidity-utils/contracts/libraries/Revert

import { IBaseEscrow } from "../interfaces/IBaseEscrow.sol";
import { IEscrowFactory } from "../interfaces/IEscrowFactory.sol";
import { IResolverMock } from "../interfaces/IResolverMock.sol";
import { IResolverExample } from "../interfaces/IResolverExample.sol";
import { Timelocks } from "../libraries/TimelocksLib.sol";

/**
* @title Sample implementation of a Resolver contract for cross-chain swap.
* @dev It is important when deploying an escrow on the source chain to send the safety deposit and deploy the escrow in the same
* transaction, since the address of the escrow depends on the block.timestamp.
* You can find sample code for this in the {ResolverExample-deploySrc}.
*/
contract ResolverMock is IResolverMock, Ownable {
contract ResolverExample is IResolverExample, Ownable {
IEscrowFactory private immutable _FACTORY;
IOrderMixin private immutable _LOP;

Expand All @@ -28,7 +31,7 @@ contract ResolverMock is IResolverMock, Ownable {
receive() external payable {} // solhint-disable-line no-empty-blocks

/**
* @notice See {IResolverMock-deploySrc}.
* @notice See {IResolverExample-deploySrc}.
*/
function deploySrc(
IBaseEscrow.Immutables calldata immutables,
Expand All @@ -52,14 +55,14 @@ contract ResolverMock is IResolverMock, Ownable {
}

/**
* @notice See {IResolverMock-deployDst}.
* @notice See {IResolverExample-deployDst}.
*/
function deployDst(IBaseEscrow.Immutables calldata dstImmutables, uint256 srcCancellationTimestamp) external onlyOwner payable {
_FACTORY.createDstEscrow{ value: msg.value }(dstImmutables, srcCancellationTimestamp);
}

/**
* @notice See {IResolverMock-arbitraryCalls}.
* @notice See {IResolverExample-arbitraryCalls}.
*/
function arbitraryCalls(address[] calldata targets, bytes[] calldata arguments) external onlyOwner {
uint256 length = targets.length;
Expand Down
48 changes: 24 additions & 24 deletions test/integration/ResolverMock.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { TakerTraits } from "limit-order-protocol/contracts/libraries/TakerTrait
import { IBaseEscrow } from "contracts/interfaces/IBaseEscrow.sol";
import { IEscrowDst } from "contracts/interfaces/IEscrowDst.sol";
import { Timelocks } from "contracts/libraries/TimelocksLib.sol";
import { IResolverMock, ResolverMock } from "contracts/mocks/ResolverMock.sol";
import { IResolverExample, ResolverExample } from "contracts/mocks/ResolverExample.sol";
import { BaseSetup } from "../utils/BaseSetup.sol";
import { CrossChainTestLib } from "../utils/libraries/CrossChainTestLib.sol";

Expand All @@ -16,7 +16,7 @@ contract IntegrationResolverMockTest is BaseSetup {

function setUp() public virtual override {
BaseSetup.setUp();
resolverMock = address(new ResolverMock(escrowFactory, limitOrderProtocol, address(this)));
resolverMock = address(new ResolverExample(escrowFactory, limitOrderProtocol, address(this)));
resolvers[0] = address(resolverMock);
vm.label(resolverMock, "resolverMock");
vm.deal(resolverMock, 100 ether);
Expand Down Expand Up @@ -55,7 +55,7 @@ contract IntegrationResolverMockTest is BaseSetup {
assertEq(usdc.balanceOf(address(swapData.srcClone)), 0);
assertEq(address(swapData.srcClone).balance, 0);

IResolverMock(resolverMock).deploySrc(
IResolverExample(resolverMock).deploySrc(
swapData.immutables,
swapData.order,
r,
Expand Down Expand Up @@ -87,7 +87,7 @@ contract IntegrationResolverMockTest is BaseSetup {
);

// deploy escrow
IResolverMock(resolverMock).deploySrc(
IResolverExample(resolverMock).deploySrc(
swapData.immutables,
swapData.order,
r,
Expand All @@ -109,7 +109,7 @@ contract IntegrationResolverMockTest is BaseSetup {
arguments[0] = abi.encodePacked(swapData.srcClone.withdrawTo.selector, abi.encode(SECRET, alice.addr, swapData.immutables));

skip(srcTimelocks.withdrawal + 10);
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);

assertEq(usdc.balanceOf(alice.addr), aliceBalance + MAKING_AMOUNT);
assertEq(resolverMock.balance, resolverBalanceNative + SRC_SAFETY_DEPOSIT);
Expand All @@ -135,7 +135,7 @@ contract IntegrationResolverMockTest is BaseSetup {
);

// deploy escrow
IResolverMock(resolverMock).deploySrc(
IResolverExample(resolverMock).deploySrc(
swapData.immutables,
swapData.order,
r,
Expand All @@ -158,7 +158,7 @@ contract IntegrationResolverMockTest is BaseSetup {

skip(srcTimelocks.cancellation + 10);
// Cancel escrow
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);

assertEq(usdc.balanceOf(alice.addr), aliceBalance + MAKING_AMOUNT);
assertEq(resolverMock.balance, resolverBalanceNative + SRC_SAFETY_DEPOSIT);
Expand Down Expand Up @@ -213,12 +213,12 @@ contract IntegrationResolverMockTest is BaseSetup {
vm.warp(block.timestamp + srcTimelocks.cancellation + 10);
// Resolver is bob, so unable to cancel escrow
vm.expectRevert(IBaseEscrow.InvalidCaller.selector);
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);

vm.warp(block.timestamp + srcTimelocks.publicCancellation + 10);
arguments[0] = abi.encodePacked(swapData.srcClone.publicCancel.selector, abi.encode(swapData.immutables));
// Now resolver mock is able to cancel escrow
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);

assertEq(usdc.balanceOf(alice.addr), aliceBalance + MAKING_AMOUNT);
assertEq(resolverMock.balance, resolverBalanceNative + SRC_SAFETY_DEPOSIT);
Expand All @@ -244,7 +244,7 @@ contract IntegrationResolverMockTest is BaseSetup {
);

// deploy escrow
IResolverMock(resolverMock).deploySrc(
IResolverExample(resolverMock).deploySrc(
swapData.immutables,
swapData.order,
r,
Expand Down Expand Up @@ -275,7 +275,7 @@ contract IntegrationResolverMockTest is BaseSetup {

skip(RESCUE_DELAY + 10);
// Rescue USDC and native tokens
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);

assertEq(usdc.balanceOf(resolverMock), resolverBalance + MAKING_AMOUNT);
assertEq(resolverMock.balance, resolverBalanceNative + SRC_SAFETY_DEPOSIT);
Expand All @@ -298,8 +298,8 @@ contract IntegrationResolverMockTest is BaseSetup {
assertEq(address(dstClone).balance, 0);

// Approve DAI to escrowFactory
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverMock(resolverMock).deployDst{ value: DST_SAFETY_DEPOSIT }(immutables, srcCancellationTimestamp);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).deployDst{ value: DST_SAFETY_DEPOSIT }(immutables, srcCancellationTimestamp);

assertEq(dai.balanceOf(address(dstClone)), TAKING_AMOUNT);
assertEq(address(dstClone).balance, DST_SAFETY_DEPOSIT);
Expand All @@ -320,8 +320,8 @@ contract IntegrationResolverMockTest is BaseSetup {
assertEq(address(dstClone).balance, 0);

// Approve DAI to escrowFactory
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverMock(resolverMock).deployDst{ value: DST_SAFETY_DEPOSIT }(immutables, srcCancellationTimestamp);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).deployDst{ value: DST_SAFETY_DEPOSIT }(immutables, srcCancellationTimestamp);

assertEq(dai.balanceOf(address(dstClone)), TAKING_AMOUNT);
assertEq(address(dstClone).balance, DST_SAFETY_DEPOSIT);
Expand All @@ -335,7 +335,7 @@ contract IntegrationResolverMockTest is BaseSetup {
arguments[0] = abi.encodePacked(dstClone.withdraw.selector, abi.encode(SECRET, immutables));

skip(dstTimelocks.withdrawal + 10);
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);

assertEq(dai.balanceOf(alice.addr), aliceBalance + TAKING_AMOUNT);
assertEq(resolverMock.balance, resolverBalanceNative + DST_SAFETY_DEPOSIT);
Expand Down Expand Up @@ -367,12 +367,12 @@ contract IntegrationResolverMockTest is BaseSetup {
vm.warp(block.timestamp + dstTimelocks.withdrawal + 10);
// Resolver is bob, so unable to withdraw tokens
vm.expectRevert(IBaseEscrow.InvalidCaller.selector);
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);

vm.warp(block.timestamp + dstTimelocks.publicWithdrawal + 10);
arguments[0] = abi.encodePacked(dstClone.publicWithdraw.selector, abi.encode(SECRET, immutables));
// Now resolver mock is able to withdraw tokens
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);

assertEq(dai.balanceOf(alice.addr), aliceBalance + TAKING_AMOUNT);
assertEq(resolverMock.balance, resolverBalanceNative + DST_SAFETY_DEPOSIT);
Expand All @@ -395,8 +395,8 @@ contract IntegrationResolverMockTest is BaseSetup {
assertEq(address(dstClone).balance, 0);

// Approve DAI to escrowFactory
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverMock(resolverMock).deployDst{ value: DST_SAFETY_DEPOSIT }(immutables, srcCancellationTimestamp);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).deployDst{ value: DST_SAFETY_DEPOSIT }(immutables, srcCancellationTimestamp);

assertEq(dai.balanceOf(address(dstClone)), TAKING_AMOUNT);
assertEq(address(dstClone).balance, DST_SAFETY_DEPOSIT);
Expand All @@ -410,7 +410,7 @@ contract IntegrationResolverMockTest is BaseSetup {
arguments[0] = abi.encodePacked(dstClone.cancel.selector, abi.encode(immutables));

skip(dstTimelocks.cancellation + 10);
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);

assertEq(dai.balanceOf(resolverMock), resolverBalance + TAKING_AMOUNT);
assertEq(resolverMock.balance, resolverBalanceNative + DST_SAFETY_DEPOSIT);
Expand All @@ -433,8 +433,8 @@ contract IntegrationResolverMockTest is BaseSetup {
assertEq(address(dstClone).balance, 0);

// Approve DAI to escrowFactory
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverMock(resolverMock).deployDst{ value: DST_SAFETY_DEPOSIT }(immutables, srcCancellationTimestamp);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).deployDst{ value: DST_SAFETY_DEPOSIT }(immutables, srcCancellationTimestamp);

assertEq(dai.balanceOf(address(dstClone)), TAKING_AMOUNT);
assertEq(address(dstClone).balance, DST_SAFETY_DEPOSIT);
Expand All @@ -451,7 +451,7 @@ contract IntegrationResolverMockTest is BaseSetup {

skip(RESCUE_DELAY + 10);
// Rescue DAI and native tokens
IResolverMock(resolverMock).arbitraryCalls(targets, arguments);
IResolverExample(resolverMock).arbitraryCalls(targets, arguments);

assertEq(dai.balanceOf(resolverMock), resolverBalance + TAKING_AMOUNT);
assertEq(resolverMock.balance, resolverBalanceNative + DST_SAFETY_DEPOSIT);
Expand Down
Loading