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

Perps changes batch 1 #1780

Merged
merged 17 commits into from May 24, 2022
Merged

Perps changes batch 1 #1780

merged 17 commits into from May 24, 2022

Conversation

artdgn
Copy link
Contributor

@artdgn artdgn commented May 12, 2022

Some small changes to the contracts:

  • better view for liquidation price and liquidation fee
  • better views for iterating over position ids (number of positions, mapping of position to address)
  • positions id persistance through closing / liquidting a position
  • contract name getters
  • remove the maker / taker fee distinction instead of a single fee
  • rename mixins for easier navigation
  • can add margin while market is paused (but not if whole system is paused)
  • pass tracking code into manager for later integration with 203

@codecov
Copy link

codecov bot commented May 12, 2022

Codecov Report

Merging #1780 (4257565) into develop (8c9e3d6) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@             Coverage Diff             @@
##           develop    #1780      +/-   ##
===========================================
- Coverage    94.99%   94.98%   -0.02%     
===========================================
  Files          105      105              
  Lines         2617     2611       -6     
  Branches       791      788       -3     
===========================================
- Hits          2486     2480       -6     
  Misses         131      131              
Impacted Files Coverage Δ
contracts/PerpsV2Market.sol 100.00% <ø> (ø)
contracts/PerpsV2NextPriceMixin.sol 100.00% <ø> (ø)
contracts/FuturesMarketManager.sol 100.00% <100.00%> (ø)
contracts/PerpsV2MarketBase.sol 100.00% <100.00%> (ø)
contracts/PerpsV2Settings.sol 100.00% <100.00%> (ø)
contracts/PerpsV2SettingsMixin.sol 100.00% <100.00%> (ø)
contracts/PerpsV2ViewsMixin.sol 94.11% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c9e3d6...4257565. Read the comment docs.

@artdgn
Copy link
Contributor Author

artdgn commented May 17, 2022

btw, fork-tests are failing because APE & DYDX markets are paused although according to config they shouldn't be, and there's no automated choice for that situation in the deploy script (it asks for a decision).

@@ -82,8 +70,8 @@ contract PerpsV2Settings is Owned, MixinPerpsV2MarketSettings, IPerpsV2Settings
/*
* The maximum allowable notional value on each side of a market.
*/
function maxMarketValueUSD(bytes32 _marketKey) public view returns (uint) {
return _maxMarketValueUSD(_marketKey);
function maxSingleSideValueUSD(bytes32 _marketKey) public view returns (uint) {
Copy link
Member

@barrasso barrasso May 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be declared as external to save some gas

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good point, not sure why these views are public

require(_takerFeeNextPrice <= 1e18, "taker fee greater than 1");
_setParameter(_marketKey, PARAMETER_TAKER_FEE_NEXT_PRICE, _takerFeeNextPrice);
function setBaseFee(bytes32 _marketKey, uint _baseFee) public onlyOwner {
require(_baseFee <= 1e18, "taker fee greater than 1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[np] maybe this should be "base fee greater than 1"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that technically this is the "taker", but I had to look that up 😅
It might be better to just call it exactly what the setting name is just to be more explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, missed when renaming stuff

require(_makerFeeNextPrice <= 1e18, "maker fee greater than 1");
_setParameter(_marketKey, PARAMETER_MAKER_FEE_NEXT_PRICE, _makerFeeNextPrice);
function setBaseFeeNextPrice(bytes32 _marketKey, uint _baseFeeNextPrice) public onlyOwner {
require(_baseFeeNextPrice <= 1e18, "taker fee greater than 1");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[np] same ☝️

* Allows markets to issue exchange fees into the fee pool and notify it that this occurred.
* This function is not callable through the proxy, only underlying contracts interact;
* it reverts if not called by a known market.
*/
function payFee(uint amount, bytes32 trackingCode) external onlyMarkets {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps rename this to something else in order to differentiate it from the futures v1 payFee function below.

e.g. payFeeWithTracking?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the v1 method will be removed with v1 stuff after the migration, so I think it makes more sense to have the default method called just payFee and always expect a tracking code as part of its interface (and it's up to the caller to pass a 0).

// check that market isn't suspended, revert with appropriate message
_systemStatus().requireFuturesMarketActive(marketKey); // asset and market may be different
if (allowMarketPaused) {
// this will check system activbe, exchange active, futures active
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[np] typo activbe => active

@@ -80,19 +80,24 @@ contract PerpsV2MarketBase is MixinPerpsV2MarketSettings, IPerpsV2BaseTypes {
*/
mapping(address => Position) public positions;

/// mapping of position id to account addresses
mapping(uint => address) public positionIdOwner;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[np] "owner" is kind of a sensitive word... could we make it something like accountForPositionId

@artdgn artdgn requested a review from barrasso May 20, 2022 04:05
@barrasso barrasso merged commit 4d2add4 into develop May 24, 2022
@barrasso barrasso deleted the perps-changes-batch1 branch May 24, 2022 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants