Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Register
Sign in
Toggle navigation
Menu
Open sidebar
Tiger Ton
osmosis
Commits
cdfad124
Commit
cdfad124
authored
2 years ago
by
Nicolas Lara
Browse files
Options
Download
Email Patches
Plain Diff
handle errors
parent
e8257445
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
x/concentrated-liquidity/fees.go
+29
-9
x/concentrated-liquidity/fees.go
x/concentrated-liquidity/pool.go
+4
-1
x/concentrated-liquidity/pool.go
with
33 additions
and
10 deletions
+33
-10
x/concentrated-liquidity/fees.go
+
29
-
9
View file @
cdfad124
...
...
@@ -23,20 +23,34 @@ func (f *Fee) Sub(fee *Fee) *Fee {
// UpdateFeesForTick updates all initialized ticks below the current tick with the fees accrued in the current tick
// ToDo: Does it matter that we skip uninitialized ticks?
func
(
k
Keeper
)
UpdateFeesForTick
(
ctx
sdk
.
Context
,
poolId
uint64
,
tickIndex
int64
,
fee
sdk
.
Dec
,
firstToken
bool
)
{
func
(
k
Keeper
)
UpdateFeesForTick
(
ctx
sdk
.
Context
,
poolId
uint64
,
tickIndex
int64
,
fee
sdk
.
Dec
,
firstToken
bool
)
error
{
tick
,
initialized
:=
k
.
NextInitializedTick
(
ctx
,
poolId
,
tickIndex
,
true
)
for
initialized
{
tickInfo
:=
k
.
getTickInfo
(
ctx
,
poolId
,
tick
)
tickInfo
,
err
:=
k
.
GetTickInfo
(
ctx
,
poolId
,
tick
)
if
err
!=
nil
{
return
err
}
tickInfo
.
FeesAccruedAboveTick
.
Add
(
firstToken
,
fee
)
k
.
setTickInfo
(
ctx
,
poolId
,
tickIndex
,
tickInfo
)
}
return
nil
}
func
(
k
Keeper
)
ClaimFees
(
ctx
sdk
.
Context
,
poolId
uint64
,
owner
sdk
.
AccAddress
,
lowerTick
,
upperTick
int64
)
*
Fee
{
func
(
k
Keeper
)
ClaimFees
(
ctx
sdk
.
Context
,
poolId
uint64
,
owner
sdk
.
AccAddress
,
lowerTick
,
upperTick
int64
)
(
*
Fee
,
error
)
{
pool
:=
k
.
getPoolbyId
(
ctx
,
poolId
)
position
:=
k
.
getPosition
(
ctx
,
poolId
,
owner
,
lowerTick
,
upperTick
)
upperTickInfo
:=
k
.
getTickInfo
(
ctx
,
poolId
,
upperTick
)
lowerTickInfo
:=
k
.
getTickInfo
(
ctx
,
poolId
,
lowerTick
)
position
,
err
:=
k
.
GetPosition
(
ctx
,
poolId
,
owner
,
lowerTick
,
upperTick
)
if
err
!=
nil
{
return
nil
,
err
}
upperTickInfo
,
err
:=
k
.
GetTickInfo
(
ctx
,
poolId
,
upperTick
)
if
err
!=
nil
{
return
nil
,
err
}
lowerTickInfo
,
err
:=
k
.
GetTickInfo
(
ctx
,
poolId
,
lowerTick
)
if
err
!=
nil
{
return
nil
,
err
}
totalFees
:=
upperTickInfo
.
FeesAccruedAboveTick
.
Sub
(
lowerTickInfo
.
FeesAccruedAboveTick
)
.
Sub
(
position
.
FeesAtCreation
)
...
...
@@ -45,10 +59,16 @@ func (k Keeper) ClaimFees(ctx sdk.Context, poolId uint64, owner sdk.AccAddress,
feeShares
:=
totalFees
// ToDo: .Quo(owner.shares)
// ToDo: Check for tick overflow? is upperTick+1 correct?
k
.
UpdateFeesForTick
(
ctx
,
poolId
,
upperTick
+
1
,
feeShares
.
Token0
.
Neg
(),
true
)
k
.
UpdateFeesForTick
(
ctx
,
poolId
,
upperTick
+
1
,
feeShares
.
Token1
.
Neg
(),
false
)
err
=
k
.
UpdateFeesForTick
(
ctx
,
poolId
,
upperTick
+
1
,
feeShares
.
Token0
.
Neg
(),
true
)
if
err
!=
nil
{
return
nil
,
err
}
err
=
k
.
UpdateFeesForTick
(
ctx
,
poolId
,
upperTick
+
1
,
feeShares
.
Token1
.
Neg
(),
false
)
if
err
!=
nil
{
return
nil
,
err
}
return
feeShares
return
feeShares
,
nil
}
func
ComputeStepFee
(
totalFee
sdk
.
Dec
,
ratio
sdk
.
Dec
)
sdk
.
Dec
{
...
...
This diff is collapsed.
Click to expand it.
x/concentrated-liquidity/pool.go
+
4
-
1
View file @
cdfad124
...
...
@@ -170,7 +170,10 @@ func (k Keeper) CalcOutAmtGivenIn(ctx sdk.Context, tokenIn sdk.Coin, tokenOutDen
)
// compute fees for the ratio of the tokens that have been swapped in this step
stepFee
=
stepFee
.
Add
(
ComputeStepFee
(
swapFee
,
amountIn
.
Quo
(
tokenAmountInAfterFee
)))
// invariant: stepFee <= swapFee
k
.
UpdateFeesForTick
(
ctx
,
poolId
,
nextTick
,
stepFee
,
firstTokenIsInput
)
err
=
k
.
UpdateFeesForTick
(
ctx
,
poolId
,
nextTick
,
stepFee
,
firstTokenIsInput
)
if
err
!=
nil
{
return
sdk
.
Coin
{},
sdk
.
Coin
{},
err
}
swapState
.
amountSpecifiedRemaining
=
swapState
.
amountSpecifiedRemaining
.
Sub
(
amountIn
)
swapState
.
amountCalculated
=
swapState
.
amountCalculated
.
Add
(
amountOut
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets