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

Add divergence check and max slippage #105

Merged
merged 22 commits into from
Jul 28, 2021

Conversation

anon-xxs
Copy link
Contributor

No description provided.

@ororopickpocket ororopickpocket added this to Review in progress in Sovryn Jan 24, 2021
@ororopickpocket ororopickpocket moved this from Review in progress to To do in Sovryn Jan 24, 2021
@ororopickpocket ororopickpocket moved this from To do to Review in progress in Sovryn Jan 24, 2021
Copy link
Contributor

@ororopickpocket ororopickpocket left a comment

Choose a reason for hiding this comment

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

It looks good, Wukong, but we'll need some changes, nonetheless.

The frontend is preparing a confirmation window where the user can select the maximum slippage he's allowing from the expected price he's being shown. However, this will not be the oracle price (like it is the case now on the trading page), but the expected price from the AMM. This means, a divergence check between AMM and oracle price is not what we need.

What we need instead is to allow the user to pass the minReturn value, similar to how it is on the oracle based amm. In case of the swap, you can simply pass on the value to the AMM contracts. they will handle it automatically. in case of the margin trade it's a bit more complicated.

one option is to let the user pass the minimum position size in the collateral currency.

there are certainly other options as well. feel free to propose one if you find another one better suited.

@ororopickpocket ororopickpocket moved this from Review in progress to To do in Sovryn Feb 2, 2021
@anon-xxs anon-xxs moved this from To do to In progress in Sovryn Feb 8, 2021
@ororopickpocket ororopickpocket moved this from In progress to Review in progress in Sovryn Feb 21, 2021
contracts/modules/SwapsExternal.sol Outdated Show resolved Hide resolved
contracts/modules/SwapsExternal.sol Outdated Show resolved Hide resolved
tests/test_SwapsExternal.py Outdated Show resolved Hide resolved
tests/test_SwapsExternal.py Outdated Show resolved Hide resolved
contracts/connectors/loantoken/LoanTokenLogicStandard.sol Outdated Show resolved Hide resolved
Copy link

@eMarchenko eMarchenko left a comment

Choose a reason for hiding this comment

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

checkPriceDivergence and priceFeeds_ issues probably deserve additional discussion

contracts/connectors/loantoken/LoanTokenLogicDai.sol Outdated Show resolved Hide resolved
contracts/connectors/loantoken/LoanTokenLogicStandard.sol Outdated Show resolved Hide resolved
contracts/modules/SwapsExternal.sol Outdated Show resolved Hide resolved
contracts/modules/SwapsExternal.sol Outdated Show resolved Hide resolved
contracts/modules/SwapsExternal.sol Outdated Show resolved Hide resolved
contracts/modules/SwapsExternal.sol Outdated Show resolved Hide resolved
@ghost ghost linked an issue Apr 21, 2021 that may be closed by this pull request
@ghost ghost assigned anon-xxs Apr 21, 2021
@tjcloa tjcloa assigned cwsnt and unassigned anon-xxs and cwsnt May 6, 2021
Fix conflict

Move maxSlippage direction to hh
Copy link
Contributor

@jameshowlett977 jameshowlett977 left a comment

Choose a reason for hiding this comment

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

Please add tests for the following functions:

  • checkPriceDivergence
  • marginTrade (minReturn/minPoisitonSize > 0)
  • swapExternal (minReturn > 0)

Passing minReturn/minPoisitonSize = 0 to existing tests is not enough.

interfaces/ISovryn.sol Outdated Show resolved Hide resolved
Copy link

@korepkorep korepkorep left a comment

Choose a reason for hiding this comment

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

Several code quality issues that don't endanger contracts` security

address destToken,
uint256 sourceTokenAmount,
uint256 minReturn
) public view;

Choose a reason for hiding this comment

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

should be external

Comment on lines 63 to 67
function() external {
revert("loan token logic - fallback not allowed");
// Due to contract size issue, need to keep the error message to 32 bytes length / we remove the revert function
// Remove revert function is fine as this fallback function is not payable, but the trade off is we cannot have the custom message for the fallback function error
// revert("loan token-fallback not allowed");
}

Choose a reason for hiding this comment

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

Nothing is executed in this function. Should it be removed?

@@ -707,7 +726,7 @@ contract LoanTokenLogicStandard is LoanTokenSettingsLowerAdmin {
uint256 leverageAmount,
uint256 loanTokenSent,
uint256 collateralTokenSent,
address collateralTokenAddress /// address(0) means rBTC.
address collateralTokenAddress // address(0) means ETH

Choose a reason for hiding this comment

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

Misleading comment since on line 740 this variable is assigned the value wrbtcTokenAddress

uint256 spreadValue = sourceToDestSwapRate > rate ? sourceToDestSwapRate - rate : rate - sourceToDestSwapRate;

if (spreadValue != 0) {
if (rate > sourceToDestSwapRate) {

Choose a reason for hiding this comment

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

Why is the case where rate < sourceToDestSwapRate is not considered anymore?

@cwsnt cwsnt merged commit 2850b7e into development Jul 28, 2021
Sovryn automation moved this from Review in progress to Done Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Sovryn
  
Done
Development

Successfully merging this pull request may close these issues.

divergence check in only one direction
7 participants