Skip to content
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
48 changes: 38 additions & 10 deletions contracts/mocks/external/ZeroExMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ contract ZeroExMock {
bytes data;
}

struct BatchSellSubcall {
uint8 subcall;
uint256 sellAmount;
bytes data;
}

struct MultiHopSellSubcall {
uint8 subcall;
bytes data;
}

address public mockReceiveToken;
address public mockSendToken;
uint256 public mockReceiveAmount;
Expand Down Expand Up @@ -91,6 +102,20 @@ contract ZeroExMock {
_transferTokens();
}

function transformERC20Staging(
address /* inputToken */,
address /* outputToken */,
uint256 /* inputTokenAmount */,
uint256 /* minOutputTokenAmount */,
Transformation[] calldata /* transformations */
)
external
payable
returns (uint256)
{
_transferTokens();
}

function sellToUniswap(
address[] calldata /* tokens */,
uint256 /* sellAmount */,
Expand Down Expand Up @@ -142,37 +167,40 @@ contract ZeroExMock {
_transferTokens();
}

function sellEthForTokenToUniswapV3(
function sellTokenForTokenToUniswapV3(
bytes memory /* encodedPath */,
uint256 /* sellAmount */,
uint256 /* minBuyAmount */,
address /* recipient */
)
external
payable
returns (uint256)
{
_transferTokens();
}

function sellTokenForEthToUniswapV3(
bytes memory /* encodedPath */,
function multiplexBatchSellTokenForToken(
address /* inputToken */,
address /* outputToken */,
BatchSellSubcall[] memory /* calls */,
uint256 /* sellAmount */,
uint256 /* minBuyAmount */,
address payable /* recipient */
uint256 /* minBuyAmount */
)
external
payable
returns (uint256)
{
_transferTokens();
}

function sellTokenForTokenToUniswapV3(
bytes memory /* encodedPath */,
function multiplexMultiHopSellTokenForToken(
address[] memory /* tokens */,
MultiHopSellSubcall[] memory /* calls */,
uint256 /* sellAmount */,
uint256 /* minBuyAmount */,
address /* recipient */
uint256 /* minBuyAmount */
)
external
payable
returns (uint256)
{
_transferTokens();
Expand Down
44 changes: 16 additions & 28 deletions contracts/protocol/integration/exchange/ZeroExApiAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ contract ZeroExApiAdapter {
)
}

if (selector == 0x415565b0) {
// transformERC20()
if (selector == 0x415565b0 || selector == 0x8182b61f) {
// transformERC20(), transformERC20Staging()
(inputToken, outputToken, inputTokenAmount, minOutputTokenAmount) =
abi.decode(_data[4:], (address, address, uint256, uint256));
} else if (selector == 0xf7fcd384) {
Expand Down Expand Up @@ -176,36 +176,24 @@ contract ZeroExApiAdapter {
recipient = _destinationAddress;
}
(inputToken, outputToken) = _decodeTokensFromUniswapV3EncodedPath(encodedPath);
} else if (selector == 0x803ba26d) {
// sellTokenForEthToUniswapV3()
bytes memory encodedPath;
(encodedPath, inputTokenAmount, minOutputTokenAmount, recipient) =
abi.decode(_data[4:], (bytes, uint256, uint256, address));
supportsRecipient = true;
if (recipient == address(0)) {
recipient = _destinationAddress;
}
(inputToken, outputToken) = _decodeTokensFromUniswapV3EncodedPath(encodedPath);
require(outputToken == wethAddress, "Last token must be WETH");
outputToken = ETH_ADDRESS;
} else if (selector == 0x3598d8ab) {
// sellEthForTokenToUniswapV3()
inputTokenAmount = _sourceQuantity;
bytes memory encodedPath;
(encodedPath, minOutputTokenAmount, recipient) =
abi.decode(_data[4:], (bytes, uint256, address));
supportsRecipient = true;
if (recipient == address(0)) {
recipient = _destinationAddress;
}
(inputToken, outputToken) = _decodeTokensFromUniswapV3EncodedPath(encodedPath);
require(inputToken == wethAddress, "First token must be WETH");
inputToken = ETH_ADDRESS;
} else if (selector == 0x7a1eb1b9) {
// multiplexBatchSellTokenForToken()
(inputToken, outputToken, , inputTokenAmount, minOutputTokenAmount) =
abi.decode(_data[4:], (address, address, uint256, uint256, uint256));
} else if (selector == 0x0f3b31b2) {
// multiplexMultiHopSellTokenForToken()
address[] memory tokens;
(tokens, , inputTokenAmount, minOutputTokenAmount) =
abi.decode(_data[4:], (address[], uint256, uint256, uint256));
require(tokens.length > 1, "Multihop token path too short");
inputToken = tokens[0];
outputToken = tokens[tokens.length - 1];
} else {
revert("Unsupported 0xAPI function selector");
}
}

require(inputToken != ETH_ADDRESS && outputToken != ETH_ADDRESS, "ETH not supported");
require(inputToken == _sourceToken, "Mismatched input token");
require(outputToken == _destinationToken, "Mismatched output token");
require(!supportsRecipient || recipient == _destinationAddress, "Mismatched recipient");
Expand All @@ -215,7 +203,7 @@ contract ZeroExApiAdapter {
return (
zeroExAddress,
// Note: Does not account for limit order protocol fees.
inputToken == ETH_ADDRESS ? inputTokenAmount : 0,
0,
_data
);
}
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@setprotocol/set-protocol-v2",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"main": "dist",
"types": "dist/types",
Expand Down Expand Up @@ -66,7 +66,7 @@
"coveralls": "^3.0.1",
"dotenv": "^8.2.0",
"ethereum-waffle": "^3.4.0",
"hardhat": "^2.6.1",
"hardhat": "^2.6.4",
"husky": "^4.2.5",
"istanbul-combine-updated": "^0.3.0",
"lint-staged": "^10.2.11",
Expand All @@ -75,11 +75,11 @@
"solhint": "^3.1.0",
"solidity-coverage": "^0.7.17",
"ts-generator": "^0.1.1",
"ts-node": "^8.10.1",
"ts-node": "^8.10.2",
"tslint": "^5.8.0",
"tslint-eslint-rules": "^5.3.1",
"typechain": "5.1.2",
"typescript": "4",
"typescript": "^4.4.3",
"web3": "^1.2.9"
},
"dependencies": {
Expand Down
Loading