forked from SetProtocol/set-protocol-v2
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(PerpV2BasisTradingModule): bytecode size limit bug (SetProtocol#200)
* Set allowUnlimitedContractSize to false * Fix PerpV2BasisTradingModule bytecode size limit Add hardhat-contract-sizer as dev dependency Add PerpV2Positions library Add functions to PerpV2 library Modify PerpV2LeverageModuel to use the new libraries Fix existing interfaces * Remove contractSizer config settings * Delete commented stuff * Add PerpV2Positions mock * Fix tests by linking libraries during deployment * Fix failing tests * Fix warnings * Use public getPositionNotionalInfo * Fix failing integration & viewer tests * Update to V2 for every contract; Make PositionsV2 library functions external * Link PositionV2 library and fix PerpV2PositionV2 linking * Fix failing perpV2BasisTradingModule tests * Remove unnecessary todo * Add tests for PositionV2 and ModuleBaseV2; Increase coverage * Fix javadocs; Add changelogs; Add missing test cases; Add PerpV2LeveageModuleV2<>SIM integration tests * Add changelog in PerpV2LeverageModuleV2 * Fix javadocs and hardhat config * Add tests for PerpV2LibraryV2 * Updated version to 0.1.13-basis.0 * Add PerpV2LibraryV2 tests * Add tests for PerpV2Positions library * Move formatAdjustments to PerpV2Positioons library * Remove .only and bump package * Attempt to fix existing flaky test * Fix variable name; Removing trailing whitespaces * Override initalize function * Fix coverage; Add tests for intialize(old) function
- Loading branch information
Sachin
committed
Mar 18, 2022
1 parent
e48e673
commit ddfab38
Showing
32 changed files
with
12,872 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
Copyright 2020 Set Labs Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
SPDX-License-Identifier: Apache License, Version 2.0 | ||
*/ | ||
|
||
pragma solidity 0.6.10; | ||
pragma experimental "ABIEncoderV2"; | ||
|
||
import { ISetToken } from "../interfaces/ISetToken.sol"; | ||
import { PositionV2 } from "../protocol/lib/PositionV2.sol"; | ||
|
||
|
||
// Mock contract implementation of PositionV2 functions | ||
contract PositionV2Mock { | ||
constructor() | ||
public | ||
{} | ||
|
||
function initialize(ISetToken _setToken) external { | ||
_setToken.initializeModule(); | ||
} | ||
|
||
function testHasDefaultPosition(ISetToken _setToken, address _component) external view returns(bool) { | ||
return PositionV2.hasDefaultPosition(_setToken, _component); | ||
} | ||
|
||
function testHasExternalPosition(ISetToken _setToken, address _component) external view returns(bool) { | ||
return PositionV2.hasExternalPosition(_setToken, _component); | ||
} | ||
function testHasSufficientDefaultUnits(ISetToken _setToken, address _component, uint256 _unit) external view returns(bool) { | ||
return PositionV2.hasSufficientDefaultUnits(_setToken, _component, _unit); | ||
} | ||
function testHasSufficientExternalUnits( | ||
ISetToken _setToken, | ||
address _component, | ||
address _module, | ||
uint256 _unit | ||
) | ||
external | ||
view | ||
returns(bool) | ||
{ | ||
return PositionV2.hasSufficientExternalUnits(_setToken, _component, _module, _unit); | ||
} | ||
|
||
function testEditDefaultPosition(ISetToken _setToken, address _component, uint256 _newUnit) external { | ||
return PositionV2.editDefaultPosition(_setToken, _component, _newUnit); | ||
} | ||
|
||
function testEditExternalPosition( | ||
ISetToken _setToken, | ||
address _component, | ||
address _module, | ||
int256 _newUnit, | ||
bytes memory _data | ||
) | ||
external | ||
{ | ||
PositionV2.editExternalPosition(_setToken, _component, _module, _newUnit, _data); | ||
} | ||
|
||
function testGetDefaultTotalNotional( | ||
uint256 _setTokenSupply, | ||
uint256 _positionUnit | ||
) | ||
external | ||
pure | ||
returns (uint256) | ||
{ | ||
return PositionV2.getDefaultTotalNotional(_setTokenSupply, _positionUnit); | ||
} | ||
|
||
function testGetDefaultPositionUnit( | ||
uint256 _setTokenSupply, | ||
uint256 _totalNotional | ||
) | ||
external | ||
pure | ||
returns (uint256) | ||
{ | ||
return PositionV2.getDefaultPositionUnit(_setTokenSupply, _totalNotional); | ||
} | ||
|
||
function testGetDefaultTrackedBalance(ISetToken _setToken, address _component) | ||
external | ||
view | ||
returns (uint256) | ||
{ | ||
return PositionV2.getDefaultTrackedBalance(_setToken, _component); | ||
} | ||
|
||
function testCalculateAndEditDefaultPosition( | ||
ISetToken _setToken, | ||
address _component, | ||
uint256 _setTotalSupply, | ||
uint256 _componentPreviousBalance | ||
) | ||
external | ||
returns (uint256, uint256, uint256) | ||
{ | ||
return PositionV2.calculateAndEditDefaultPosition( | ||
_setToken, | ||
_component, | ||
_setTotalSupply, | ||
_componentPreviousBalance | ||
); | ||
} | ||
|
||
function testCalculateDefaultEditPositionUnit( | ||
uint256 _setTokenSupply, | ||
uint256 _preTotalNotional, | ||
uint256 _postTotalNotional, | ||
uint256 _prePositionUnit | ||
) | ||
external | ||
pure | ||
returns (uint256) | ||
{ | ||
return PositionV2.calculateDefaultEditPositionUnit( | ||
_setTokenSupply, | ||
_preTotalNotional, | ||
_postTotalNotional, | ||
_prePositionUnit | ||
); | ||
} | ||
} |
156 changes: 156 additions & 0 deletions
156
contracts/mocks/protocol/integration/lib/PerpV2LibraryV2Mock.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/* | ||
Copyright 2021 Set Labs Inc. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
SPDX-License-Identifier: Apache License, Version 2.0 | ||
*/ | ||
|
||
pragma solidity 0.6.10; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import { IClearingHouse } from "../../../../interfaces/external/perp-v2/IClearingHouse.sol"; | ||
import { IVault } from "../../../../interfaces/external/perp-v2/IVault.sol"; | ||
import { IQuoter } from "../../../../interfaces/external/perp-v2/IQuoter.sol"; | ||
|
||
import { PerpV2LibraryV2 } from "../../../../protocol/integration/lib/PerpV2LibraryV2.sol"; | ||
import { ISetToken } from "../../../../interfaces/ISetToken.sol"; | ||
|
||
/** | ||
* @title PerpV2LibraryV2Mock | ||
* @author Set Protocol | ||
* | ||
* Mock for PerpV2LibraryV2 Library contract. Used for testing PerpV2LibraryV2 Library contract, as the library | ||
* contract can't be tested directly using ethers.js. | ||
*/ | ||
contract PerpV2LibraryV2Mock { | ||
|
||
/* ============ External ============ */ | ||
|
||
function testGetDepositCalldata( | ||
IVault _vault, | ||
IERC20 _asset, | ||
uint256 _amountNotional | ||
) | ||
public | ||
pure | ||
returns (address, uint256, bytes memory) | ||
{ | ||
return PerpV2LibraryV2.getDepositCalldata(_vault, _asset, _amountNotional); | ||
} | ||
|
||
function testInvokeDeposit( | ||
ISetToken _setToken, | ||
IVault _vault, | ||
IERC20 _asset, | ||
uint256 _amountNotional | ||
) | ||
external | ||
{ | ||
return PerpV2LibraryV2.invokeDeposit(_setToken, _vault, _asset, _amountNotional); | ||
} | ||
|
||
function testGetWithdrawCalldata( | ||
IVault _vault, | ||
IERC20 _asset, | ||
uint256 _amountNotional | ||
) | ||
public | ||
pure | ||
returns (address, uint256, bytes memory) | ||
{ | ||
return PerpV2LibraryV2.getWithdrawCalldata(_vault, _asset, _amountNotional); | ||
} | ||
|
||
function testInvokeWithdraw( | ||
ISetToken _setToken, | ||
IVault _vault, | ||
IERC20 _asset, | ||
uint256 _amountNotional | ||
) | ||
external | ||
{ | ||
return PerpV2LibraryV2.invokeWithdraw(_setToken, _vault, _asset, _amountNotional); | ||
} | ||
|
||
function testGetOpenPositionCalldata( | ||
IClearingHouse _clearingHouse, | ||
IClearingHouse.OpenPositionParams memory _params | ||
) | ||
public | ||
pure | ||
returns (address, uint256, bytes memory) | ||
{ | ||
return PerpV2LibraryV2.getOpenPositionCalldata(_clearingHouse, _params); | ||
} | ||
|
||
function testInvokeOpenPosition( | ||
ISetToken _setToken, | ||
IClearingHouse _clearingHouse, | ||
IClearingHouse.OpenPositionParams memory _params | ||
) | ||
external | ||
returns (uint256 deltaBase, uint256 deltaQuote) | ||
{ | ||
return PerpV2LibraryV2.invokeOpenPosition(_setToken, _clearingHouse, _params); | ||
} | ||
|
||
function testGetSwapCalldata( | ||
IQuoter _quoter, | ||
IQuoter.SwapParams memory _params | ||
) | ||
public | ||
pure | ||
returns (address, uint256, bytes memory) | ||
{ | ||
return PerpV2LibraryV2.getSwapCalldata(_quoter, _params); | ||
} | ||
|
||
function testInvokeSwap( | ||
ISetToken _setToken, | ||
IQuoter _quoter, | ||
IQuoter.SwapParams memory _params | ||
) | ||
external | ||
returns (IQuoter.SwapResponse memory) | ||
{ | ||
return PerpV2LibraryV2.invokeSwap(_setToken, _quoter, _params); | ||
} | ||
|
||
function testSimulateTrade( | ||
PerpV2LibraryV2.ActionInfo memory _actionInfo, | ||
IQuoter _perpQuoter | ||
) | ||
external | ||
returns (uint256, uint256) | ||
{ | ||
return PerpV2LibraryV2.simulateTrade(_actionInfo, _perpQuoter); | ||
} | ||
|
||
function testExecuteTrade( | ||
PerpV2LibraryV2.ActionInfo memory _actionInfo, | ||
IClearingHouse _perpClearingHouse | ||
) | ||
external | ||
returns (uint256, uint256) | ||
{ | ||
return PerpV2LibraryV2.executeTrade(_actionInfo, _perpClearingHouse); | ||
} | ||
|
||
/* ============ Helper Functions ============ */ | ||
|
||
function initializeModuleOnSet(ISetToken _setToken) external { | ||
_setToken.initializeModule(); | ||
} | ||
} |
Oops, something went wrong.