Files
protocol/contracts/zero-ex/contracts/test/TestUniswapV3Pool.sol
Lawrence Forman 901d400d62 Address spot check feedback (#251)
* UniswapV3 VIP (#237)

* `@0x/contracts-zero-ex`: Add UniswapV3Feature

* `@0x/contracts-zero-ex`: Add UniswapV3 VIP
`@0x/contract-artifacts`: Regenerate.
`@0x/contract-wrappers`: Regenerate.
`@0x/asset-swapper`: Add UniswapV3 VIP support.

* address review comments and appease linter

* `@0x/contracts-zero-ex`: Add UniswapV3Feature tests

* Multiplex UniswapV3 (#241)

* Add UniswapV3 support to Multiplex batchFill

* Add AssetSwapper support for Multiplex UniswapV3

* fix repo scripts that use PKG= env var (#242)

Co-authored-by: Lawrence Forman <me@merklejerk.com>

* `@0x/asset-swapper`: Adjust uniswap gas overhead

Co-authored-by: Lawrence Forman <me@merklejerk.com>
Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com>

* OTC orders feature (#244)

* Add OTC orders feature contracts

* Address PR feedback

* Remove partial fills for takerSigned variant

* Add function to query the min valid nonce

* Add ETH support

* Tightly pack expiry, nonceBucket, and nonce

* Address PR feedback

* OTC orders unit tests

* Bump prettier version

* Skip unnecessary math if takerTokenFillAmount == order.takerAmount

* appease CI

* Update contract-artifacts and contract-wrappers and CHANGELOGs

* `@0x/contracts-zero-ex`: Address spot check feedback

* `regen wrappers

* prettier

* `@0x/asset-swapper`: prettier and tweak gas schedule slightly for uni3

Co-authored-by: Lawrence Forman <me@merklejerk.com>
Co-authored-by: mzhu25 <mchl.zhu.96@gmail.com>
2021-06-02 14:21:14 +10:00

76 lines
2.3 KiB
Solidity

// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.6;
pragma experimental ABIEncoderV2;
import "@0x/contracts-erc20/contracts/src/v06/IERC20TokenV06.sol";
import "../src/vendor/IUniswapV3Pool.sol";
interface IUniswapV3PoolDeployer {
struct CreationParameters {
IERC20TokenV06 token0;
IERC20TokenV06 token1;
uint24 fee;
}
function creationParameters() external view returns (CreationParameters memory);
}
interface IUniswapV3SwapCallback {
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
)
external;
}
contract TestUniswapV3Pool is IUniswapV3Pool {
IERC20TokenV06 public immutable token0;
IERC20TokenV06 public immutable token1;
uint24 public immutable fee;
constructor() public {
IUniswapV3PoolDeployer.CreationParameters memory params =
IUniswapV3PoolDeployer(msg.sender).creationParameters();
(token0, token1, fee) = (params.token0, params.token1, params.fee);
}
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160,
bytes calldata data
)
external
override
returns (int256 amount0, int256 amount1)
{
uint256 balance0Before = token0.balanceOf(address(this));
uint256 balance1Before = token1.balanceOf(address(this));
if (zeroForOne) {
amount0 = int256(amountSpecified);
// Always buy 100% of other token balance.
amount1 = -int256(balance1Before);
token1.transfer(recipient, balance1Before);
} else {
amount0 = -int256(balance0Before);
// Always buy 100% of other token balance.
amount1 = int256(amountSpecified);
token0.transfer(recipient, balance0Before);
}
IUniswapV3SwapCallback(msg.sender).uniswapV3SwapCallback(
amount0,
amount1,
data
);
int256 balance0Change = int256(token0.balanceOf(address(this))) -
int256(balance0Before);
int256 balance1Change = int256(token1.balanceOf(address(this))) -
int256(balance1Before);
require(
balance0Change >= amount0 && balance1Change >= amount1,
"TestUniswapV3Pool/SWAP_NOT_PAID"
);
}
}