Merge bad-datatype commit

This commit is contained in:
Owen
2022-04-04 13:55:46 -07:00
16 changed files with 78 additions and 76 deletions
+5 -8
View File
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;
import {ERC20} from "solmate/tokens/ERC20.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {Ownable} from "./lib/Ownable.sol";
import {ReentrancyGuard} from "./lib/ReentrancyGuard.sol";
@@ -22,10 +23,6 @@ abstract contract LSSVMPair is Ownable, ReentrancyGuard {
// 90%, must <= 1 - MAX_PROTOCOL_FEE (set in LSSVMPairFactory)
uint256 internal constant MAX_FEE = 0.90e18;
// NOTE: We use uint128 here for spotPrice and delta to pack them into one storage slot, but
// treat them as uint256 during math calculations. LPs should be aware of potential
// overflow when setting very large spot price and/or delta!
// The current price of the NFT
// @dev This is generally used to mean the immediate sell price for the next marginal NFT.
// However, this should NOT be assumed! Use getBuyNFTQuote and getSellNFTQuote for accurate pricing info.
@@ -72,7 +69,7 @@ abstract contract LSSVMPair is Ownable, ReentrancyGuard {
address _owner,
address payable _assetRecipient,
uint128 _delta,
uint256 _fee,
uint96 _fee,
uint128 _spotPrice
) external payable {
require(owner() == address(0), "Initialized");
@@ -91,7 +88,7 @@ abstract contract LSSVMPair is Ownable, ReentrancyGuard {
_assetRecipient == address(0),
"Trade pools can't set asset recipient"
);
fee = uint96(_fee);
fee = _fee;
}
require(_bondingCurve.validateDelta(_delta), "Invalid delta for curve");
require(
@@ -606,7 +603,7 @@ abstract contract LSSVMPair is Ownable, ReentrancyGuard {
@param a The address of the NFT to transfer
@param nftIds The list of IDs of the NFTs to send to the owner
*/
function withdrawERC721(address a, uint256[] calldata nftIds)
function withdrawERC721(IERC721 a, uint256[] calldata nftIds)
external
virtual;
@@ -615,7 +612,7 @@ abstract contract LSSVMPair is Ownable, ReentrancyGuard {
@param a The address of the token to transfer
@param amount The amount of tokens to send to the owner
*/
function withdrawERC20(address a, uint256 amount) external virtual;
function withdrawERC20(ERC20 a, uint256 amount) external virtual;
/**
@notice Updates the selling spot price. Only callable by the owner.
+6 -4
View File
@@ -17,6 +17,8 @@ import {CurveErrorCodes} from "./bonding-curves/CurveErrorCodes.sol";
abstract contract LSSVMPairERC20 is LSSVMPair {
using SafeTransferLib for ERC20;
uint256 internal constant IMMUTABLE_PARAMS_LENGTH = 81;
/**
@notice Returns the ERC20 token associated with the pair
@dev See LSSVMPairCloner for an explanation on how this works
@@ -139,18 +141,18 @@ abstract contract LSSVMPairERC20 is LSSVMPair {
/// @inheritdoc LSSVMPair
// @dev see LSSVMPairCloner for params length calculation
function _immutableParamsLength() internal pure override returns (uint256) {
return 81;
return IMMUTABLE_PARAMS_LENGTH;
}
/// @inheritdoc LSSVMPair
function withdrawERC20(address a, uint256 amount)
function withdrawERC20(ERC20 a, uint256 amount)
external
override
onlyOwner
{
ERC20(a).safeTransfer(msg.sender, amount);
a.safeTransfer(msg.sender, amount);
if (a == address(token())) {
if (a == token()) {
// emit event since it is the pair token
emit TokenWithdrawal(amount);
}
+5 -3
View File
@@ -16,6 +16,8 @@ abstract contract LSSVMPairETH is LSSVMPair {
using SafeTransferLib for address payable;
using SafeTransferLib for ERC20;
uint256 internal constant IMMUTABLE_PARAMS_LENGTH = 61;
/// @inheritdoc LSSVMPair
function _pullTokenInputAndPayProtocolFee(
uint256 inputAmount,
@@ -85,7 +87,7 @@ abstract contract LSSVMPairETH is LSSVMPair {
/// @inheritdoc LSSVMPair
// @dev see LSSVMPairCloner for params length calculation
function _immutableParamsLength() internal pure override returns (uint256) {
return 61;
return IMMUTABLE_PARAMS_LENGTH;
}
/**
@@ -110,12 +112,12 @@ abstract contract LSSVMPairETH is LSSVMPair {
}
/// @inheritdoc LSSVMPair
function withdrawERC20(address a, uint256 amount)
function withdrawERC20(ERC20 a, uint256 amount)
external
override
onlyOwner
{
ERC20(a).safeTransfer(owner(), amount);
a.safeTransfer(msg.sender, amount);
}
/**
+2 -2
View File
@@ -63,13 +63,13 @@ abstract contract LSSVMPairEnumerable is LSSVMPair {
}
/// @inheritdoc LSSVMPair
function withdrawERC721(address a, uint256[] calldata nftIds)
function withdrawERC721(IERC721 a, uint256[] calldata nftIds)
external
override
onlyOwner
{
for (uint256 i = 0; i < nftIds.length; i++) {
IERC721(a).safeTransferFrom(address(this), msg.sender, nftIds[i]);
a.safeTransferFrom(address(this), msg.sender, nftIds[i]);
}
}
}
+17 -12
View File
@@ -18,6 +18,10 @@ import {ICurve} from "./bonding-curves/ICurve.sol";
import {LSSVMPairERC20} from "./LSSVMPairERC20.sol";
import {LSSVMPairCloner} from "./lib/LSSVMPairCloner.sol";
import {ILSSVMPairFactoryLike} from "./ILSSVMPairFactoryLike.sol";
import {LSSVMPairEnumerableETH} from "./LSSVMPairEnumerableETH.sol";
import {LSSVMPairEnumerableERC20} from "./LSSVMPairEnumerableERC20.sol";
import {LSSVMPairMissingEnumerableETH} from "./LSSVMPairMissingEnumerableETH.sol";
import {LSSVMPairMissingEnumerableERC20} from "./LSSVMPairMissingEnumerableERC20.sol";
contract LSSVMPairFactory is Ownable, ILSSVMPairFactoryLike {
using LSSVMPairCloner for address;
@@ -29,10 +33,11 @@ contract LSSVMPairFactory is Ownable, ILSSVMPairFactoryLike {
uint256 internal constant MAX_PROTOCOL_FEE = 0.10e18; // 10%, must <= 1 - MAX_FEE
LSSVMPairETH public immutable enumerableETHTemplate;
LSSVMPairETH public immutable missingEnumerableETHTemplate;
LSSVMPairERC20 public immutable enumerableERC20Template;
LSSVMPairERC20 public immutable missingEnumerableERC20Template;
LSSVMPairEnumerableETH public immutable enumerableETHTemplate;
LSSVMPairMissingEnumerableETH public immutable missingEnumerableETHTemplate;
LSSVMPairEnumerableERC20 public immutable enumerableERC20Template;
LSSVMPairMissingEnumerableERC20
public immutable missingEnumerableERC20Template;
address payable public override protocolFeeRecipient;
// Units are in base 1e18
@@ -56,10 +61,10 @@ contract LSSVMPairFactory is Ownable, ILSSVMPairFactoryLike {
event RouterStatusUpdate(LSSVMRouter router, bool isAllowed);
constructor(
LSSVMPairETH _enumerableETHTemplate,
LSSVMPairETH _missingEnumerableETHTemplate,
LSSVMPairERC20 _enumerableERC20Template,
LSSVMPairERC20 _missingEnumerableERC20Template,
LSSVMPairEnumerableETH _enumerableETHTemplate,
LSSVMPairMissingEnumerableETH _missingEnumerableETHTemplate,
LSSVMPairEnumerableERC20 _enumerableERC20Template,
LSSVMPairMissingEnumerableERC20 _missingEnumerableERC20Template,
address payable _protocolFeeRecipient,
uint256 _protocolFeeMultiplier
) {
@@ -98,7 +103,7 @@ contract LSSVMPairFactory is Ownable, ILSSVMPairFactoryLike {
address payable _assetRecipient,
LSSVMPair.PoolType _poolType,
uint128 _delta,
uint256 _fee,
uint96 _fee,
uint128 _spotPrice,
uint256[] calldata _initialNFTIDs
) external payable returns (LSSVMPairETH pair) {
@@ -160,7 +165,7 @@ contract LSSVMPairFactory is Ownable, ILSSVMPairFactoryLike {
address payable assetRecipient;
LSSVMPair.PoolType poolType;
uint128 delta;
uint256 fee;
uint96 fee;
uint128 spotPrice;
uint256[] initialNFTIDs;
uint256 initialTokenBalance;
@@ -374,7 +379,7 @@ contract LSSVMPairFactory is Ownable, ILSSVMPairFactoryLike {
IERC721 _nft,
address payable _assetRecipient,
uint128 _delta,
uint256 _fee,
uint96 _fee,
uint128 _spotPrice,
uint256[] calldata _initialNFTIDs
) internal {
@@ -400,7 +405,7 @@ contract LSSVMPairFactory is Ownable, ILSSVMPairFactoryLike {
IERC721 _nft,
address payable _assetRecipient,
uint128 _delta,
uint256 _fee,
uint96 _fee,
uint128 _spotPrice,
uint256[] calldata _initialNFTIDs,
uint256 _initialTokenBalance
+4 -8
View File
@@ -31,7 +31,7 @@ abstract contract LSSVMPairMissingEnumerable is LSSVMPair {
unchecked {
uint256 nftId = idSet.at(lastIndex--);
_nft.safeTransferFrom(address(this), nftRecipient, nftId);
idSet.remove(nftId);
idSet.remove(nftId);
}
}
}
@@ -80,7 +80,7 @@ abstract contract LSSVMPairMissingEnumerable is LSSVMPair {
}
/// @inheritdoc LSSVMPair
function withdrawERC721(address a, uint256[] calldata nftIds)
function withdrawERC721(IERC721 a, uint256[] calldata nftIds)
external
override
onlyOwner
@@ -88,13 +88,9 @@ abstract contract LSSVMPairMissingEnumerable is LSSVMPair {
IERC721 _nft = nft();
// If it's not the pair's NFT, just withdraw normally
if (a != address(_nft)) {
if (a != _nft) {
for (uint256 i = 0; i < nftIds.length; i++) {
IERC721(a).safeTransferFrom(
address(this),
msg.sender,
nftIds[i]
);
a.safeTransferFrom(address(this), msg.sender, nftIds[i]);
}
}
// Otherwise, withdraw and also remove the ID from the ID set
+4 -4
View File
@@ -30,10 +30,10 @@ abstract contract NoArbBondingCurve is DSTest, ERC721Holder, Configurable {
function setUp() public {
bondingCurve = setupCurve();
test721 = setup721();
LSSVMPairETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
LSSVMPairEnumerableETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairMissingEnumerableETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairEnumerableERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairMissingEnumerableERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
factory = new LSSVMPairFactory(
enumerableETHTemplate,
missingEnumerableETHTemplate,
+11 -11
View File
@@ -3,7 +3,7 @@ pragma solidity ^0.8.0;
import {DSTest} from "ds-test/test.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {ERC20} from "solmate/tokens/ERC20.sol";
import {ICurve} from "../../bonding-curves/ICurve.sol";
import {IERC721Mintable} from "../interfaces/IERC721Mintable.sol";
import {IMintable} from "../interfaces/IMintable.sol";
@@ -27,7 +27,7 @@ abstract contract PairAndFactory is DSTest, ERC721Holder, Configurable {
uint256 numItems = 2;
uint256[] idList;
IERC721 test721;
IERC20 testERC20;
ERC20 testERC20;
ICurve bondingCurve;
LSSVMPairFactory factory;
address payable constant feeRecipient = payable(address(69));
@@ -37,10 +37,10 @@ abstract contract PairAndFactory is DSTest, ERC721Holder, Configurable {
function setUp() public {
bondingCurve = setupCurve();
test721 = setup721();
LSSVMPairETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
LSSVMPairEnumerableETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairMissingEnumerableETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairEnumerableERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairMissingEnumerableERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
factory = new LSSVMPairFactory(
enumerableETHTemplate,
missingEnumerableETHTemplate,
@@ -70,7 +70,7 @@ abstract contract PairAndFactory is DSTest, ERC721Holder, Configurable {
address(0)
);
testERC20 = IERC20(address(new Test20()));
testERC20 = ERC20(address(new Test20()));
IMintable(address(testERC20)).mint(address(pair), 1 ether);
}
@@ -105,8 +105,8 @@ abstract contract PairAndFactory is DSTest, ERC721Holder, Configurable {
}
function test_rescueTokens() public {
pair.withdrawERC721(address(test721), idList);
pair.withdrawERC20(address(testERC20), 1 ether);
pair.withdrawERC721(test721, idList);
pair.withdrawERC20(testERC20, 1 ether);
}
function testFail_tradePoolChangeAssetRecipient() public {
@@ -197,8 +197,8 @@ abstract contract PairAndFactory is DSTest, ERC721Holder, Configurable {
function testFail_rescueTokensNotOwner() public {
pair.transferOwnership(address(1000));
pair.withdrawERC721(address(test721), idList);
pair.withdrawERC20(address(testERC20), 1 ether);
pair.withdrawERC721(test721, idList);
pair.withdrawERC20(testERC20, 1 ether);
}
function testFail_changeAssetRecipientForTrade() public {
+4 -4
View File
@@ -38,10 +38,10 @@ abstract contract RouterMultiPool is
function setUp() public {
bondingCurve = setupCurve();
test721 = setup721();
LSSVMPairETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
LSSVMPairEnumerableETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairMissingEnumerableETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairEnumerableERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairMissingEnumerableERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
factory = new LSSVMPairFactory(
enumerableETHTemplate,
missingEnumerableETHTemplate,
+4 -4
View File
@@ -46,10 +46,10 @@ abstract contract RouterRobustSwap is
// Create contracts
bondingCurve = setupCurve();
test721 = setup721();
LSSVMPairETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
LSSVMPairEnumerableETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairMissingEnumerableETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairEnumerableERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairMissingEnumerableERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
factory = new LSSVMPairFactory(
enumerableETHTemplate,
missingEnumerableETHTemplate,
@@ -49,10 +49,10 @@ abstract contract RouterRobustSwapWithAssetRecipient is
function setUp() public {
bondingCurve = setupCurve();
test721 = setup721();
LSSVMPairETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
LSSVMPairEnumerableETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairMissingEnumerableETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairEnumerableERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairMissingEnumerableERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
factory = new LSSVMPairFactory(
enumerableETHTemplate,
missingEnumerableETHTemplate,
+4 -4
View File
@@ -37,10 +37,10 @@ abstract contract RouterSinglePool is
function setUp() public {
bondingCurve = setupCurve();
test721 = setup721();
LSSVMPairETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
LSSVMPairEnumerableETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairMissingEnumerableETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairEnumerableERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairMissingEnumerableERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
factory = new LSSVMPairFactory(
enumerableETHTemplate,
missingEnumerableETHTemplate,
@@ -40,10 +40,10 @@ abstract contract RouterSinglePoolWithAssetRecipient is
function setUp() public {
bondingCurve = setupCurve();
test721 = setup721();
LSSVMPairETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
LSSVMPairEnumerableETH enumerableETHTemplate = new LSSVMPairEnumerableETH();
LSSVMPairMissingEnumerableETH missingEnumerableETHTemplate = new LSSVMPairMissingEnumerableETH();
LSSVMPairEnumerableERC20 enumerableERC20Template = new LSSVMPairEnumerableERC20();
LSSVMPairMissingEnumerableERC20 missingEnumerableERC20Template = new LSSVMPairMissingEnumerableERC20();
factory = new LSSVMPairFactory(
enumerableETHTemplate,
missingEnumerableETHTemplate,
+1 -1
View File
@@ -17,7 +17,7 @@ abstract contract Configurable {
address payable assetRecipient,
LSSVMPair.PoolType poolType,
uint128 delta,
uint256 fee,
uint96 fee,
uint128 spotPrice,
uint256[] memory _idList,
uint256 initialTokenBalance,
+2 -2
View File
@@ -40,7 +40,7 @@ abstract contract UsingERC20 is Configurable, RouterCaller {
address payable assetRecipient,
LSSVMPair.PoolType poolType,
uint128 delta,
uint256 fee,
uint96 fee,
uint128 spotPrice,
uint256[] memory _idList,
uint256 initialTokenBalance,
@@ -82,7 +82,7 @@ abstract contract UsingERC20 is Configurable, RouterCaller {
function withdrawTokens(LSSVMPair pair) public override {
uint256 total = test20.balanceOf(address(pair));
LSSVMPairERC20(address(pair)).withdrawERC20(address(test20), total);
LSSVMPairERC20(address(pair)).withdrawERC20(test20, total);
}
function withdrawProtocolFees(LSSVMPairFactory factory) public override {
+1 -1
View File
@@ -35,7 +35,7 @@ abstract contract UsingETH is Configurable, RouterCaller {
address payable assetRecipient,
LSSVMPair.PoolType poolType,
uint128 delta,
uint256 fee,
uint96 fee,
uint128 spotPrice,
uint256[] memory _idList,
uint256,