Skip to content

Conversation

@0xSachinK
Copy link
Contributor

@0xSachinK 0xSachinK commented Feb 1, 2022

No description provided.

@0xSachinK 0xSachinK requested review from bweick and cgewecke February 1, 2022 20:12
// PerpV2 contract which provides a getter for baseToken UniswapV3 pools
IMarketRegistry public immutable perpMarketRegistry;

// Max perpetual positions per SetToken
Copy link
Contributor

Choose a reason for hiding this comment

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

Provide some context on why this is necessary

Copy link
Contributor Author

@0xSachinK 0xSachinK Feb 2, 2022

Choose a reason for hiding this comment

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

Done in 33005

onlyManagerAndValidSet(_setToken)
{
ActionInfo memory actionInfo = _createAndValidateActionInfo(
_validateTrade(_baseToken, _baseQuantityUnits);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why get rid of createAndValidateActionInfo? Idk what the gas optimization is but unless it's significant I'd prefer the more readable code structure

Copy link
Contributor Author

@0xSachinK 0xSachinK Feb 2, 2022

Choose a reason for hiding this comment

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

Done in bde695.

ActionInfo memory actionInfo = _createAndValidateActionInfo(
_validateTrade(_baseToken, _baseQuantityUnits);

int256 baseBalance = perpAccountBalance.getBase(address(_setToken), _baseToken);
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be nice to put lines 327-333 into it's own function. Perhaps you can pass in the totalSupply so that it doesn't have to get queried twice.

Copy link
Contributor Author

@0xSachinK 0xSachinK Feb 2, 2022

Choose a reason for hiding this comment

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

Done in bde695. Basically brought back the createAndValidateActionInfo function and added those lines to that function.

positions[_setToken].removeStorage(_baseToken);
}
} else {
require(positions[_setToken].length < maxPerpPositionsPerSet, "Exceeds max perpetual positions per set");
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally we could check this before executing the trade (since this is only called in trade). Is there a way that we can determine the hasBaseToken variable earlier for a validation and then pass it down to the _updatePositionList function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would decrease "separation of concerns" between the external and internal function. Also, it is on L2, where computation is cheap, so it shouldn't be a major problem.

});
});

// todo: a test case which tries to flip the position?
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need a test for closing the position. We should check to make sure that when the exact negation of a baseToken position unit is passed in that it will completely zero out our vAsset position

Copy link
Contributor Author

@0xSachinK 0xSachinK Feb 2, 2022

Choose a reason for hiding this comment

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

Tests for closing a position already exist. Added checks to ensure the base balance is zero to those tests in 597a16

@0xSachinK 0xSachinK force-pushed the sachin/perpv2-module-bug-fixes branch from 6df45c4 to 7019cfe Compare February 2, 2022 11:42
This implementation also prevents the user from entering into a state where the module treats the base token position as closed while perp still considers it to be open because the module didn't close the entire position and a small non-negligible dust amount exists in perp protocol
@0xSachinK 0xSachinK force-pushed the sachin/perpv2-module-bug-fixes branch from 4efcabf to 6a46c8a Compare February 2, 2022 13:03
@0xSachinK 0xSachinK merged commit e749052 into master Feb 2, 2022
@0xSachinK 0xSachinK deleted the sachin/perpv2-module-bug-fixes branch February 2, 2022 19:04
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.

3 participants