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

[SC-1213] Add support for new matcha contracts #20

Merged
merged 69 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
0eaa19b
update hardhat to support cancun
belactriple9 Jul 25, 2024
fabc0ac
add contract's for matcha's new router support
belactriple9 Jul 25, 2024
b346cff
add ABI for encoding usage
belactriple9 Jul 25, 2024
7c0224d
add MATCHA2 protocol key
belactriple9 Jul 25, 2024
816156a
Add first matcha v2 test
belactriple9 Jul 25, 2024
7f97eae
Add permit2 permit to fixtures for re-use
belactriple9 Jul 31, 2024
bb5e22e
add notice since matcha's settler contract may change
belactriple9 Jul 31, 2024
01debff
include matcha's new 0xsettler
belactriple9 Jul 31, 2024
40a7664
commit local changes
belactriple9 Aug 5, 2024
f736ca9
update hardhat
belactriple9 Aug 29, 2024
90533a4
add better description
belactriple9 Aug 29, 2024
ef0e42e
update matcha2 contract address
belactriple9 Aug 29, 2024
a6ecdc8
add re-usable function for matcha2 contract
belactriple9 Aug 29, 2024
d7feaa4
apply new uniswap v3 tests with matcha2
belactriple9 Aug 29, 2024
3525dec
final tests
belactriple9 Aug 29, 2024
13a523f
update yarn.lock
belactriple9 Aug 30, 2024
f72b3f7
Merge remote-tracking branch '1inch/master' into feature/SC-1213
belactriple9 Aug 30, 2024
90b1bec
add new compiler
belactriple9 Sep 10, 2024
a5a5a1d
update some dependencies to fix issues
belactriple9 Sep 10, 2024
fcc06d2
update mainnet settler
belactriple9 Sep 11, 2024
7913663
upgrade hardhat
belactriple9 Sep 12, 2024
ffda163
update solidity versions
belactriple9 Sep 12, 2024
2964080
matcha 0x settler tests
belactriple9 Sep 12, 2024
b813ece
matcha 0x settler tests
belactriple9 Sep 12, 2024
2bcfaaf
features for 0x settler
belactriple9 Sep 12, 2024
6d65c79
lint
belactriple9 Sep 12, 2024
86d1235
update yarn.lock
belactriple9 Sep 12, 2024
b5c1405
add mixed pool tests
belactriple9 Sep 16, 2024
89e447b
set base fee to 0 to avoid transaction underpriced errors
belactriple9 Sep 16, 2024
1834b07
update deps (except @uniswap/router-sdk 1.9.3)
SevenSwen Sep 19, 2024
9b0fd28
remove unused
SevenSwen Sep 24, 2024
ddfd1e3
refactor iface
SevenSwen Sep 24, 2024
8759f2a
update eslint and fix linter
SevenSwen Sep 24, 2024
899792b
remove enableAllOpcodes for tracer
SevenSwen Sep 24, 2024
54058c0
refactor constats
SevenSwen Sep 24, 2024
86b9b94
remove fixed compile version for external interfaces
SevenSwen Sep 24, 2024
30ff205
remove solhint default rule
SevenSwen Sep 24, 2024
09f6805
Merge pull request #21 from 1inch/refactor/SC-1213
belactriple9 Sep 24, 2024
3598b20
spilt tests for permit2 and without it
SevenSwen Oct 4, 2024
a789675
update deps
SevenSwen Oct 7, 2024
0f3bc79
fix double using of permits
SevenSwen Oct 9, 2024
15cd726
split tests into those using Permit2 and those not using it
SevenSwen Oct 9, 2024
e0682d4
remove Permit2 section for tests started from Eth
SevenSwen Oct 10, 2024
1ae1299
fix readme
SevenSwen Oct 10, 2024
cbfe6cc
Merge commit '199536440bc123ed006e434091f1ba83017c0ce4' into feature/…
SevenSwen Oct 10, 2024
678d0d5
fix after merge
SevenSwen Oct 10, 2024
9138459
fix lint
SevenSwen Oct 10, 2024
1e60070
small fixes
SevenSwen Oct 10, 2024
205c730
lint a bit
ZumZoom Oct 14, 2024
13eb281
run CI on all PRs
ZumZoom Oct 14, 2024
e5048b3
remove useless header
ZumZoom Oct 14, 2024
0b220b0
fix borders
ZumZoom Oct 14, 2024
f31ae79
make some use of fixtures
ZumZoom Oct 14, 2024
9595383
linter
ZumZoom Oct 14, 2024
d5a97ff
rename matcha2 -> settler
ZumZoom Oct 14, 2024
d889a3e
use separate tables for Permit2 flow
ZumZoom Oct 14, 2024
6bbf0e2
linter
ZumZoom Oct 14, 2024
f6a19e0
add tests for 0xSettler using AllowanceHolder
SevenSwen Oct 15, 2024
90bbce9
fix readme
SevenSwen Oct 15, 2024
d8985a9
fix lint
SevenSwen Oct 15, 2024
7954357
gas optimize 0xSettle permit txs
SevenSwen Oct 15, 2024
7e2d8a4
fix Univ3 test
ZumZoom Oct 15, 2024
40e13d1
fix uniV2 test
ZumZoom Oct 15, 2024
b6bda10
Merge pull request #23 from 1inch/feature/optimize_settle
ZumZoom Oct 15, 2024
03e4b1d
lower default deadline
ZumZoom Oct 15, 2024
e5a657f
fix BASIC
ZumZoom Oct 15, 2024
0737d9e
Merge pull request #22 from 1inch/feature/SC-1281
ZumZoom Oct 15, 2024
2fbdc17
use consisntent amount for permit2 swaps
ZumZoom Oct 15, 2024
37acae3
update tables
ZumZoom Oct 15, 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
6 changes: 6 additions & 0 deletions contracts/interfaces/IEIP712.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IEIP712 {
function DOMAIN_SEPARATOR() external view returns (bytes32);
ZumZoom marked this conversation as resolved.
Show resolved Hide resolved
}
134 changes: 134 additions & 0 deletions contracts/interfaces/ISignatureTransfer.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import { IEIP712 } from "./IEIP712.sol";

/// @title SignatureTransfer
/// @notice Handles ERC20 token transfers through signature based actions
/// @dev Requires user's token approval on the Permit2 contract
interface ISignatureTransfer is IEIP712 {
/// @notice Thrown when the requested amount for a transfer is larger than the permissioned amount
/// @param maxAmount The maximum amount a spender can request to transfer
error InvalidAmount(uint256 maxAmount);

/// @notice Thrown when the number of tokens permissioned to a spender does not match the number of tokens being transferred
/// @dev If the spender does not need to transfer the number of tokens permitted, the spender can request amount 0 to be transferred
error LengthMismatch();

/// @notice Emits an event when the owner successfully invalidates an unordered nonce.
event UnorderedNonceInvalidation(address indexed owner, uint256 word, uint256 mask);

/// @notice The token and amount details for a transfer signed in the permit transfer signature
struct TokenPermissions {
// ERC20 token address
address token;
// the maximum amount that can be spent
uint256 amount;
}

/// @notice The signed permit message for a single token transfer
struct PermitTransferFrom {
TokenPermissions permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}

/// @notice Specifies the recipient address and amount for batched transfers.
/// @dev Recipients and amounts correspond to the index of the signed token permissions array.
/// @dev Reverts if the requested amount is greater than the permitted signed amount.
struct SignatureTransferDetails {
// recipient address
address to;
// spender requested amount
uint256 requestedAmount;
}

/// @notice Used to reconstruct the signed permit message for multiple token transfers
/// @dev Do not need to pass in spender address as it is required that it is msg.sender
/// @dev Note that a user still signs over a spender address
struct PermitBatchTransferFrom {
// the tokens and corresponding amounts permitted for a transfer
TokenPermissions[] permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}

/// @notice A map from token owner address and a caller specified word index to a bitmap. Used to set bits in the bitmap to prevent against signature replay protection
/// @dev Uses unordered nonces so that permit messages do not need to be spent in a certain order
/// @dev The mapping is indexed first by the token owner, then by an index specified in the nonce
/// @dev It returns a uint256 bitmap
/// @dev The index, or wordPosition is capped at type(uint248).max
function nonceBitmap(address, uint256) external view returns (uint256);

/// @notice Transfers a token using a signed permit message
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param signature The signature to verify
function permitTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
) external;

/// @notice Transfers a token using a signed permit message
/// @notice Includes extra data provided by the caller to verify signature over
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param witness Extra data to include when checking the user signature
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
/// @param signature The signature to verify
function permitWitnessTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;

/// @notice Transfers multiple tokens using a signed permit message
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
/// @param signature The signature to verify
function permitTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes calldata signature
) external;

/// @notice Transfers multiple tokens using a signed permit message
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
/// @notice Includes extra data provided by the caller to verify signature over
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
/// @param witness Extra data to include when checking the user signature
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
/// @param signature The signature to verify
function permitWitnessTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;

/// @notice Invalidates the bits specified in mask for the bitmap at the word position
/// @dev The wordPos is maxed at type(uint248).max
/// @param wordPos A number to index the nonceBitmap at
/// @param mask A bitmap masked against msg.sender's current bitmap at the word position
function invalidateUnorderedNonces(uint256 wordPos, uint256 mask) external;
}
2 changes: 1 addition & 1 deletion contracts/interfaces/router/IMatchaRouter.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: Apache-2.0

pragma solidity 0.8.23;
pragma solidity 0.8.25;

interface IMatchaRouter {
function sellToUniswap(address[] calldata tokens, uint256 sellAmount, uint256 minBuyAmount, bool isSushi) external payable;
Expand Down
27 changes: 27 additions & 0 deletions contracts/interfaces/router/ISettler.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";
import { ISignatureTransfer } from "../ISignatureTransfer.sol";

interface ISettler {
struct AllowedSlippage {
address recipient;
IERC20 buyToken;
uint256 minAmountOut;
}

function execute(
AllowedSlippage calldata slippage,
bytes[] calldata actions,
bytes32 affiliate
) external payable returns (bool);

function _hasMetaTxn() external pure returns (bool);

function _msgSender() external view returns (address);

function _isRestrictedTarget(address target) external pure returns (bool);

function _dispatchVIP(bytes4 action, bytes calldata data) external returns (bool);
}
108 changes: 108 additions & 0 deletions contracts/interfaces/router/ISettlerActions.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import { ISignatureTransfer } from "../ISignatureTransfer.sol";

interface ISettlerActions {
/// @dev Transfer funds from msg.sender Permit2.
function TRANSFER_FROM(address recipient, ISignatureTransfer.PermitTransferFrom memory permit, bytes memory sig)
external;

/// @dev Transfer funds from metatransaction requestor into the Settler contract using Permit2. Only for use in `Settler.executeMetaTxn` where the signature is provided as calldata
function METATXN_TRANSFER_FROM(address recipient, ISignatureTransfer.PermitTransferFrom memory permit) external;

/// @dev Settle an RfqOrder between maker and taker transfering funds directly between the parties
// Post-req: Payout if recipient != taker
function RFQ_VIP(
address recipient,
ISignatureTransfer.PermitTransferFrom memory makerPermit,
address maker,
bytes memory makerSig,
ISignatureTransfer.PermitTransferFrom memory takerPermit,
bytes memory takerSig
) external;

/// @dev Settle an RfqOrder between maker and taker transfering funds directly between the parties for the entire amount
function METATXN_RFQ_VIP(
address recipient,
ISignatureTransfer.PermitTransferFrom memory makerPermit,
address maker,
bytes memory makerSig,
ISignatureTransfer.PermitTransferFrom memory takerPermit
) external;

/// @dev Settle an RfqOrder between Maker and Settler. Transfering funds from the Settler contract to maker.
/// Retaining funds in the settler contract.
// Pre-req: Funded
// Post-req: Payout
function RFQ(
address recipient,
ISignatureTransfer.PermitTransferFrom memory permit,
address maker,
bytes memory makerSig,
address takerToken,
uint256 maxTakerAmount
) external;

/// @dev Trades against UniswapV3 using the contracts balance for funding
// Pre-req: Funded
// Post-req: Payout
function UNISWAPV3(address recipient, uint256 bps, bytes memory path, uint256 amountOutMin) external;

/// @dev Trades against UniswapV3 using user funds via Permit2 for funding
function UNISWAPV3_VIP(
address recipient,
bytes memory path,
ISignatureTransfer.PermitTransferFrom memory permit,
bytes memory sig,
uint256 amountOutMin
) external;

function MAKERPSM(address recipient, address gemToken, uint256 bps, address psm, bool buyGem) external;

function CURVE_TRICRYPTO_VIP(
address recipient,
uint80 poolInfo,
ISignatureTransfer.PermitTransferFrom memory permit,
bytes memory sig,
uint256 minBuyAmount
) external;
function METATXN_CURVE_TRICRYPTO_VIP(
address recipient,
uint80 poolInfo,
ISignatureTransfer.PermitTransferFrom memory permit,
uint256 minBuyAmount
) external;

function DODOV1(address sellToken, uint256 bps, address pool, bool quoteForBase, uint256 minBuyAmount) external;

function VELODROME(address recipient, uint256 bps, address pool, uint24 swapInfo, uint256 minBuyAmount) external;

/// @dev Trades against UniswapV3 using user funds via Permit2 for funding. Metatransaction variant. Signature is over all actions.
function METATXN_UNISWAPV3_VIP(
address recipient,
bytes memory path,
ISignatureTransfer.PermitTransferFrom memory permit,
uint256 amountOutMin
) external;

/// @dev Trades against UniswapV2 using the contracts balance for funding
/// @param swapInfo is encoded as the upper 16 bits as the fee of the pool in bps, the second
/// lowest bit as "sell token has transfer fee", and the lowest bit as the
/// "token0 for token1" flag.
function UNISWAPV2(
address recipient,
address sellToken,
uint256 bps,
address pool,
uint24 swapInfo,
uint256 amountOutMin
) external;

function POSITIVE_SLIPPAGE(address recipient, address token, uint256 expectedAmount) external;

/// @dev Trades against a basic AMM which follows the approval, transferFrom(msg.sender) interaction
// Pre-req: Funded
// Post-req: Payout
function BASIC(address sellToken, uint256 bps, address pool, uint256 offset, bytes calldata data) external;
}
11 changes: 11 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ module.exports = {
viaIR: true,
},
},
{
version: '0.8.25',
settings: {
optimizer: {
enabled: true,
runs: 1000000,
},
evmVersion: (networks[getNetwork()])?.hardfork || 'cancun',
viaIR: true,
},
},
],
},
namedAccounts: {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"@1inch/limit-order-settlement": "2.0.1",
"@1inch/solidity-utils": "5.2.2",
"@openzeppelin/contracts": "5.0.2",
"@uniswap/universal-router": "1.6.0",
"@uniswap/universal-router-sdk": "2.2.2",
"solmate": "6.2.0"
},
Expand All @@ -33,7 +32,7 @@
"eslint-plugin-n": "17.7.0",
"eslint-plugin-promise": "6.1.1",
"ethers": "6.12.1",
"hardhat": "2.19.5",
"hardhat": "2.22.10",
"hardhat-dependency-compiler": "1.1.4",
"hardhat-deploy": "0.12.4",
"hardhat-gas-reporter": "2.1.1",
Expand Down
Loading