Skip to content
Verified contractPartialApache-2.0

LifiIntentAdapter

Address0xdcf071a6ed52dd6c1e49d8d52c5cc4c66bc7a75a
Balance

0 ETH

 

Transactions

0

 

Compiler

solc 0.8.30

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 1 runs
EVM version
osaka
License
Apache-2.0
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
26,391,602
Creation transaction
0xa2cbfee6e0…20354526f4

116 files

The source code is large: one file is shown at a time. Choose a file in the list.

src/periphery/adapters/LifiIntentAdapter.sol

// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.27;

import {IERC20} from "@oz/token/ERC20/IERC20.sol";
import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";
import {Address} from "@oz/utils/Address.sol";
import {Errors} from "@periphery/Errors.sol";
import {MultiStepExecutor} from "@periphery/MultiStepExecutor.sol";
import {CoreAdapter} from "@periphery/adapters/CoreAdapter.sol";
import {ILifiInputSettlerEscrow, MandateOutput, StandardOrder} from "@periphery/interfaces/ILifiInputSettlerEscrow.sol";
import {ILifiOutputCallback} from "@periphery/interfaces/ILifiOutputCallback.sol";

contract LifiIntentAdapter is CoreAdapter, ILifiOutputCallback {
  using SafeERC20 for IERC20;

  // solhint-disable oxide/no-comments
  struct Open {
    IERC20 token;
    uint256 amount;
    uint256 destinationChainId;
    ILifiInputSettlerEscrow inputSettler;
    address inputOracle;
    // The oracle on the destination chain that proves the fill to inputOracle.
    bytes32 outputOracle;
    // The settler on the destination chain that the solver fills through.
    bytes32 outputSettler;
    bytes32 outputToken;
    bytes32 recipient;
    uint256 minOutput;
    address refundRecipient;
    uint256 nonce;
    // Seconds after the order opens until a solver can no longer fill it.
    uint32 fillWindow;
    // Seconds after the order opens until anyone can refund it to refundRecipient.
    uint32 expiryWindow;
    // The OIF order type data, for example a Dutch auction. Empty for a limit order.
    bytes context;
  }

  struct OpenWithHook {
    IERC20 token;
    uint256 amount;
    uint256 destinationChainId;
    ILifiInputSettlerEscrow inputSettler;
    address inputOracle;
    // The oracle on the destination chain that proves the fill to inputOracle.
    bytes32 outputOracle;
    // The settler on the destination chain that the solver fills through.
    bytes32 outputSettler;
    bytes32 outputToken;
    bytes32 recipient;
    uint256 minOutput;
    address refundRecipient;
    uint256 nonce;
    // Seconds after the order opens until a solver can no longer fill it.
    uint32 fillWindow;
    // Seconds after the order opens until anyone can refund it to refundRecipient.
    uint32 expiryWindow;
    // The OIF order type data, for example a Dutch auction. Empty for a limit order.
    bytes context;
    bytes callbackData;
  }
  // solhint-enable oxide/no-comments

  event HookFailed(bytes reason);

  function lifiOpen(Open calldata _open) external {
    _openOrder(_open, "");
  }

  function lifiOpenWithHook(OpenWithHook calldata _openWithHook) external {
    _openOrder(
      Open({
        token: _openWithHook.token,
        amount: _openWithHook.amount,
        destinationChainId: _openWithHook.destinationChainId,
        inputSettler: _openWithHook.inputSettler,
        inputOracle: _openWithHook.inputOracle,
        outputOracle: _openWithHook.outputOracle,
        outputSettler: _openWithHook.outputSettler,
        outputToken: _openWithHook.outputToken,
        recipient: _openWithHook.recipient,
        minOutput: _openWithHook.minOutput,
        refundRecipient: _openWithHook.refundRecipient,
        nonce: _openWithHook.nonce,
        fillWindow: _openWithHook.fillWindow,
        expiryWindow: _openWithHook.expiryWindow,
        context: _openWithHook.context
      }),
      _openWithHook.callbackData
    );
  }

  // solhint-disable-next-line oxide/no-comments
  /**
   * @notice LI.FI's output settler calls this when it fills an order with a hook.
   * @dev Runs the steps in `_executionData`. If they revert, it sends the output to the fallback recipient.
   * @dev Anyone can call it. This is safe because the adapter holds funds only during a transaction.
   */
  function outputFilled(bytes32 _token, uint256 _amount, bytes calldata _executionData) external {
    (address target, address fallbackRecipient, MultiStepExecutor.Step[] memory steps) =
      abi.decode(_executionData, (address, address, MultiStepExecutor.Step[]));
    _requireRecipient(fallbackRecipient);
    address token = address(uint160(uint256(_token)));
    try this.lifiRunHook(token, _amount, target, steps) {}
    catch (bytes memory reason) {
      emit HookFailed(reason);
      _transfer(token, _amount, fallbackRecipient);
    }
  }

  function lifiRunHook(address _token, uint256 _amount, address _target, MultiStepExecutor.Step[] calldata _steps)
    external
  {
    require(msg.sender == address(this), Errors.LifiIntentAdapter__NotSelf());
    _transfer(_token, _amount, _target);
    for (uint256 i = 0; i < _steps.length; i++) {
      Address.functionCall(_steps[i].target, _steps[i].data);
    }
  }

  function _openOrder(Open memory _open, bytes memory _callbackData) private {
    _requireRecipient(_open.refundRecipient);
    _requireRecipient(_open.recipient);
    IERC20 token = _open.token;
    uint256 amount = _resolveERC20Amount(token, _open.amount);

    uint256[2][] memory inputs = new uint256[2][](1);
    inputs[0] = [uint256(uint160(address(token))), amount];
    MandateOutput[] memory outputs = new MandateOutput[](1);
    outputs[0] = MandateOutput({
      oracle: _open.outputOracle,
      settler: _open.outputSettler,
      chainId: _open.destinationChainId,
      token: _open.outputToken,
      amount: _open.minOutput,
      recipient: _open.recipient,
      callbackData: _callbackData,
      context: _open.context
    });
    StandardOrder memory order = StandardOrder({
      user: _open.refundRecipient,
      nonce: _open.nonce,
      originChainId: block.chainid,
      expires: uint32(block.timestamp) + _open.expiryWindow,
      fillDeadline: uint32(block.timestamp) + _open.fillWindow,
      inputOracle: _open.inputOracle,
      inputs: inputs,
      outputs: outputs
    });

    token.forceApprove(address(_open.inputSettler), amount);
    _open.inputSettler.open(order);
  }

  function _transfer(address _token, uint256 _amount, address _recipient) private {
    if (_token == address(0)) {
      _transferEth(_amount, _recipient);
    } else {
      _transferERC20(IERC20(_token), _amount, _recipient);
    }
  }
}
Compiler settingsShow
{
  "viaIR": false,
  "metadata": {
    "appendCBOR": true,
    "bytecodeHash": "none",
    "useLiteralContent": false
  },
  "libraries": {},
  "optimizer": {
    "runs": 1,
    "enabled": true
  },
  "evmVersion": "osaka",
  "remappings": [
    "@core/=src/core/",
    "@periphery/=src/periphery/",
    "@generated/=src/generated/",
    "@aztec/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/",
    "@aztec-blob-lib/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/src/mock/libraries/",
    "@zkpassport/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/circuits/src/solidity/src/",
    "@oz/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
    "node_modules/@aztec-foundation/l1-artifacts/l1-contracts/:@openzeppelin/contracts/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/",
    "node_modules/@aztec-foundation/l1-artifacts/l1-contracts/:@openzeppelin/contracts/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/contracts/",
    "@uniswap/universal-router/=node_modules/@uniswap/universal-router/",
    "@uniswap/v4-core/=node_modules/@uniswap/v4-core/",
    "@uniswap/v4-periphery/=node_modules/@uniswap/v4-periphery/",
    "@uniswap/v2-core/=node_modules/@uniswap/v2-core/",
    "@account-abstraction/contracts/=node_modules/@account-abstraction/contracts/",
    "@nitro-validator/=.deps/nitro-validator/src/",
    "@solarity/libs/=.deps/solidity-lib/contracts/libs/",
    "@test/=test/",
    "forge-std/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/forge-std/src/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/",
    "node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/",
    "node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-std/:ds-test/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-std/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/:ds-test/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/:ds-test/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/:ds-test/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/lib/ds-test/",
    "node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "node_modules/@uniswap/v4-core/lib/solmate/:ds-test/=node_modules/@uniswap/v4-core/lib/solmate/lib/ds-test/",
    "node_modules/@uniswap/v4-core/lib/solmate/:ds-test/=node_modules/@uniswap/v4-core/lib/solmate/lib/ds-test/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/:openzeppelin-contracts/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/:openzeppelin-contracts/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/openzeppelin-contracts/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/:solmate/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/",
    "node_modules/@uniswap/v4-periphery/lib/permit2/:solmate/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/solmate/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/:openzeppelin-contracts/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/:openzeppelin-contracts/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/openzeppelin-contracts/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/:solmate/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/",
    "node_modules/@uniswap/v4-periphery/lib/v4-core/:solmate/=node_modules/@uniswap/v4-periphery/lib/v4-core/lib/solmate/",
    "node_modules/@aztec-foundation/l1-artifacts/l1-contracts/:openzeppelin-contracts/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/",
    "node_modules/@aztec-foundation/l1-artifacts/l1-contracts/:openzeppelin-contracts/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/",
    "node_modules/@uniswap/universal-router/:@uniswap/v3-core/=node_modules/@uniswap/universal-router/node_modules/@uniswap/v3-core/",
    "node_modules/@uniswap/universal-router/:@uniswap/v3-core/=node_modules/@uniswap/universal-router/node_modules/@uniswap/v3-core/",
    "node_modules/@uniswap/v4-core/:openzeppelin-contracts/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/",
    "node_modules/@uniswap/v4-core/:openzeppelin-contracts/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/",
    "node_modules/@uniswap/v4-core/:solmate/=node_modules/@uniswap/v4-core/lib/solmate/",
    "node_modules/@uniswap/v4-core/:solmate/=node_modules/@uniswap/v4-core/lib/solmate/",
    "@account-abstraction/=node_modules/@account-abstraction/",
    "@aztec-foundation/=node_modules/@aztec-foundation/",
    "@openzeppelin/=node_modules/@openzeppelin/",
    "@uniswap/=node_modules/@uniswap/",
    "base64-sol/=node_modules/base64-sol/",
    "circuits/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/circuits/",
    "ds-test/=node_modules/@uniswap/v4-core/lib/solmate/lib/ds-test/",
    "erc4626-tests/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
    "forge-gas-snapshot/=node_modules/@uniswap/v4-periphery/lib/permit2/lib/forge-gas-snapshot/",
    "halmos-cheatcodes/=node_modules/@aztec-foundation/l1-artifacts/l1-contracts/lib/openzeppelin-contracts/lib/halmos-cheatcodes/",
    "openzeppelin-contracts/=node_modules/@uniswap/v4-core/lib/openzeppelin-contracts/",
    "permit2/=node_modules/@uniswap/v4-periphery/lib/permit2/",
    "solmate/=node_modules/@uniswap/v4-core/lib/solmate/",
    "v4-core/=node_modules/@uniswap/v4-periphery/lib/v4-core/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.