-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix Review #1
base: main
Are you sure you want to change the base?
Fix Review #1
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import params as Params | |
import pools as Pools | ||
import fees as Fees | ||
import positions as Positions | ||
import ERC20Plus as ERC20Plus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
|
||
######################################################################## | ||
# This is the entry-point contract. | ||
|
@@ -55,10 +56,10 @@ def CONTEXT( | |
quote_token: address, | ||
desired : uint256, | ||
slippage : uint256, | ||
payload : Bytes[224] | ||
payload : Bytes[512] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
) -> Ctx: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
base_decimals : uint256 = convert(ERC20Plus(base_token).decimals(), uint256) | ||
quote_decimals: uint256 = convert(ERC20Plus(quote_token).decimals(), uint256) | ||
base_decimals : uint256 = ERC20Plus(base_token).decimals() | ||
quote_decimals: uint256 = ERC20Plus(quote_token).decimals() | ||
Comment on lines
+62
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
# this will revert on error | ||
Comment on lines
+63
to
64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
price : uint256 = self.ORACLE.price(quote_decimals, | ||
desired, | ||
|
@@ -72,6 +73,7 @@ def CONTEXT( | |
|
||
######################################################################## | ||
@external | ||
@nonreentrant("lock") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
def mint( | ||
base_token : address, #ERC20 | ||
quote_token : address, #ERC20 | ||
|
@@ -80,7 +82,7 @@ def mint( | |
quote_amt : uint256, | ||
desired : uint256, | ||
slippage : uint256, | ||
payload : Bytes[224] | ||
payload : Bytes[512] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
) -> uint256: | ||
""" | ||
@notice Provide liquidity to the pool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
|
@@ -101,14 +103,15 @@ def mint( | |
return self.CORE.mint(1, base_token, quote_token, lp_token, base_amt, quote_amt, ctx) | ||
|
||
@external | ||
@nonreentrant("lock") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
def burn( | ||
base_token : address, | ||
quote_token : address, | ||
lp_token : address, | ||
lp_amt : uint256, | ||
desired : uint256, | ||
slippage : uint256, | ||
payload : Bytes[224] | ||
payload : Bytes[512] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
) -> Tokens: | ||
""" | ||
@notice Withdraw liquidity from the pool | ||
|
@@ -128,6 +131,7 @@ def burn( | |
return self.CORE.burn(1, base_token, quote_token, lp_token, lp_amt, ctx) | ||
|
||
@external | ||
@nonreentrant("lock") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
def open( | ||
base_token : address, | ||
quote_token : address, | ||
|
@@ -136,7 +140,7 @@ def open( | |
leverage : uint256, | ||
desired : uint256, | ||
slippage : uint256, | ||
payload : Bytes[224] | ||
payload : Bytes[512] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
) -> PositionState: | ||
""" | ||
@notice Open a position | ||
|
@@ -158,13 +162,14 @@ def open( | |
return self.CORE.open(1, base_token, quote_token, long, collateral0, leverage, ctx) | ||
|
||
@external | ||
@nonreentrant("lock") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
def close( | ||
base_token : address, | ||
quote_token : address, | ||
position_id : uint256, | ||
desired : uint256, | ||
slippage : uint256, | ||
payload : Bytes[224] | ||
payload : Bytes[512] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
) -> PositionValue: | ||
""" | ||
@notice Close a position | ||
|
@@ -183,13 +188,14 @@ def close( | |
return self.CORE.close(1, base_token, quote_token, position_id, ctx) | ||
|
||
@external | ||
@nonreentrant("lock") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
def liquidate( | ||
base_token : address, | ||
quote_token: address, | ||
position_id: uint256, | ||
desired : uint256, | ||
slippage : uint256, | ||
payload : Bytes[224] | ||
payload : Bytes[512] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/1. Fixes issues: #94 |
||
) -> PositionValue: | ||
""" | ||
@notice Liquidate a position | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,7 +160,7 @@ def balanced(state: Value, burn_value: uint256, ctx: Ctx) -> Tokens: | |
# Magic number which depends on the smallest fee one wants to support | ||
# and the blocktime (since fees are per block). See types.vy/Parameters | ||
# for an example. | ||
DENOM: constant(uint256) = 1_000_000_000 | ||
DENOM: constant(uint256) = 1_000_000_000_000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/3. Fixes issues: #66 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/3. Fixes issues: #66 |
||
|
||
@external | ||
@pure | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,12 +60,12 @@ def utilization(reserves: uint256, interest: uint256) -> uint256: | |
""" | ||
Reserve utilization in percent (rounded down). | ||
""" | ||
return 0 if (reserves == 0 or interest == 0) else (interest / (reserves / 100)) | ||
return 0 if (reserves == 0 or interest == 0) else (interest / (reserves / 100_000)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/3. Fixes issues: #66 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/3. Fixes issues: #66 |
||
|
||
@internal | ||
@pure | ||
def scale(fee: uint256, utilization: uint256) -> uint256: | ||
return (fee * utilization) / 100 | ||
return (fee * utilization) / 100_000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/3. Fixes issues: #66 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/3. Fixes issues: #66 |
||
|
||
@internal | ||
@view | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -192,6 +192,10 @@ def value(id: uint256, ctx: Ctx) -> PositionValue: | |
# | ||
# Positions which go negative due to price fluctuations cost the pool | ||
# EV profits since the most it can make is available collateral. | ||
pool : PoolState = self.POOLS.lookup(pos.pool) | ||
bc : uint256 = pool.base_collateral | ||
qc : uint256 = pool.quote_collateral | ||
|
||
Comment on lines
+195
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96
Comment on lines
+195
to
+198
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 |
||
deltas: Deltas = Deltas({ | ||
base_interest : [self.MATH.MINUS(pos.interest)], | ||
quote_interest : [], | ||
|
@@ -206,19 +210,19 @@ def value(id: uint256, ctx: Ctx) -> PositionValue: | |
quote_transfer : [], | ||
# in the worst case describe above, reserves | ||
# dont change | ||
quote_reserves : [self.MATH.PLUS(pos.collateral), #does not need min() | ||
quote_reserves : [self.MATH.PLUS(min(pos.collateral, qc)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 |
||
self.MATH.MINUS(fees.funding_paid)], | ||
quote_collateral: [self.MATH.PLUS(fees.funding_paid), | ||
self.MATH.MINUS(pos.collateral)], | ||
self.MATH.MINUS(min(pos.collateral, qc))], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 |
||
}) if pos.long else Deltas({ | ||
base_interest : [], | ||
quote_interest : [self.MATH.MINUS(pos.interest)], | ||
|
||
base_transfer : [], | ||
base_reserves : [self.MATH.PLUS(pos.collateral), | ||
base_reserves : [self.MATH.PLUS(min(pos.collateral, bc)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 |
||
self.MATH.MINUS(fees.funding_paid)], | ||
base_collateral : [self.MATH.PLUS(fees.funding_paid), # <- | ||
self.MATH.MINUS(pos.collateral)], | ||
self.MATH.MINUS(min(pos.collateral, bc))], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 |
||
|
||
quote_transfer : [self.MATH.PLUS(pnl.payout), | ||
self.MATH.PLUS(fees.funding_received)], | ||
|
@@ -250,8 +254,13 @@ def calc_fees(id: uint256) -> FeesPaid: | |
c1 : Val = self.deduct(c0, fees.funding_paid) | ||
c2 : Val = self.deduct(c1.remaining, fees.borrowing_paid) | ||
# Funding fees prioritized over borrowing fees. | ||
funding_paid : uint256 = c1.deducted | ||
avail_pay : uint256 = pool.quote_collateral if pos.long else ( | ||
pool.base_collateral ) | ||
funding_paid : uint256 = min(c1.deducted, avail_pay) | ||
# borrowing_paid is for informational purposes only, could also say | ||
# min(c2.deducted, avail_pay - funding_paid). | ||
Comment on lines
+257
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96
Comment on lines
+257
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 |
||
borrowing_paid : uint256 = c2.deducted | ||
# other users' bad positions do not affect liquidatability | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to https://github.com/Velar-co/gl-sherlock/pull/2. Fixes issues: #96 |
||
remaining : uint256 = c2.remaining | ||
# When there are negative positions (liquidation bot failure): | ||
avail : uint256 = pool.base_collateral if pos.long else ( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to https://github.com/Velar-co/gl-sherlock/pull/1.
Fixes issues: #94