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

Two Part Transactions #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Two Part Transactions #10

wants to merge 2 commits into from

Conversation

xvi10
Copy link
Contributor

@xvi10 xvi10 commented Mar 2, 2022

No description provided.

@@ -126,6 +132,13 @@ contract FastPriceFeed is ISecondaryPriceFeed, Governable {
tokenPrecisions = _tokenPrecisions;
}

// do not call setLastUpdatedAt, if the fast price submitter is not updating then
// the Chainlink price should be used instead since this function does not update all token prices
function setPrice(address _token, uint256 _price) external override onlyAdmin {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what's the usecase for this? without setLastUpdatedAt new price won't be used after some time threshold anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

was meant for the keeper / signer flow, will remove it

@@ -61,7 +64,7 @@ contract FastPriceFeed is ISecondaryPriceFeed, Governable {
}

modifier onlyAdmin() {
require(msg.sender == admin, "FastPriceFeed: forbidden");
require(isAdmin[msg.sender], "FastPriceFeed: forbidden");
Copy link
Collaborator

Choose a reason for hiding this comment

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

if it won't bother you maybe change "admin" to something like oracle/updater/etc.? since this role is only used to update price. but admin sounds like it can do everything here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok i'll call it updater

if (index >= tokens.length) { return; }

uint256 startBit = 32 * j;
uint256 price = (_priceBits >> startBit) & PRICE_BITMASK;
Copy link
Collaborator

Choose a reason for hiding this comment

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

we may add some sanity checks here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

like min / max price?

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes

contracts/peripherals/Timelock.sol Outdated Show resolved Hide resolved
contracts/peripherals/Timelock.sol Outdated Show resolved Hide resolved
address[] memory _path,
function withdrawFees(address _token, address _receiver) external onlyGov {
uint256 amount = feeReserves[_token];
if(amount == 0) { return; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

space after if 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix

uint256 public minBlockDelayKeeper;
uint256 public minBlockDelayPublic;

uint256 public lastCreationBlock;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this var is not used (only updated in create position func), do we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will be checked by the fast price feed to schedule an update, i've added a comment

bool shouldRefundCollateral = false;

if (position.isLong) {
shouldRefundCollateral = IVault(_vault).getMaxPrice(position.indexToken) > position.acceptablePrice;
Copy link
Collaborator

Choose a reason for hiding this comment

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

in this case position won't be open and collateral will be returned to a user?
probably it's not shoudRefundCollateral but more like shouldOpenPosition? since it's just two different branches – open position or cancel it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok will rename

}

function executeIncreasePositionETH() external nonReentrant onlyPositionKeeper {
Copy link
Collaborator

Choose a reason for hiding this comment

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

mmm i guess executeIncreasePosition should handle both cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

uint256 _sizeDelta,
bool _isLong,
uint256 _price
) external nonReentrant onlyPartners {
Copy link
Collaborator

Choose a reason for hiding this comment

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

in case we will implement automatic position opening with e.g. each oracle update we can create IncreaseOrder here as well
that might be more secure

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for partners they might want it to be opened immediately, otherwise they should just call createIncreasePosition

emit Register(msg.sender, _code);
}

function updateAddress(bytes32 _code, address _newAccount) external {
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's not clear wether it's about referrer or owner
maybe updateReferralCodeOwner(_code, _newOwner)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

hm. i guess it should be merged with setReferralCodeOwner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok will change it

emit UpdateAddress(msg.sender, _newAccount, _code);
}

function getReferral(address _account) external override view returns (bytes32, address) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

"referral" is a trader, who used code and "referrer" is the code owner?
better to name it getReferrer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok will change it

return keccak256(abi.encodePacked(_account, _index));
}

function getPendingRequestLenghts() public view returns (uint256, uint256) {
Copy link
Contributor

Choose a reason for hiding this comment

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

i guess it should be "external" instead of "public"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok will change it

IncreasePositionRequest memory request = increasePositionRequests[_key];
require(request.account != address(0), "RouterV2: request does not exist");

bool shouldExecute = _validateCancellation(request.blockNumber, request.blockTime);
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldExecute -> shouldCancel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok will change it

uint256 nextCollateral = collateral.add(collateralDelta);

uint256 prevLeverage = size.mul(BASIS_POINTS_DIVISOR).div(collateral);
uint256 nextLeverage = nextSize.mul(BASIS_POINTS_DIVISOR + 1).div(nextCollateral);
Copy link
Contributor

Choose a reason for hiding this comment

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

we should add 100 here (same logic is in validateIncreaseOrder)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense

if (isKeeperCall) {
return _positionBlockNumber.add(minBlockDelayKeeper) <= block.number;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

should we validate that msg.sender == request.account?

Copy link
Contributor

Choose a reason for hiding this comment

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

theoretical case:

  • keeper doesn't work
  • much time has passed and trader prefers to cancel request
  • some bot will execute it faster to get fee

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok will add it

@xvi10 xvi10 changed the base branch from master to staging March 28, 2022 06:37
@xvi10 xvi10 changed the base branch from staging to master March 28, 2022 06:37
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