Skip to content

Commit 382b982

Browse files
avkr003Amit Yadav
andauthored
auto deploy to devnet (#1241)
* auto deploy to devnet * fixing taker fees and weight balance reward queries * join pool fees * fix * add comment --------- Co-authored-by: Amit Yadav <ay@Mac.lan>
1 parent 34b4f88 commit 382b982

File tree

13 files changed

+1081
-650
lines changed

13 files changed

+1081
-650
lines changed

.github/workflows/devnet-deploy.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: DevNet deploy
22
on:
3-
workflow_dispatch:
3+
push:
4+
branches:
5+
- devnet
6+
- main
47

58
jobs:
69
deploy:

api/elys/amm/query.pulsar.go

Lines changed: 158 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/elys/leveragelp/query.pulsar.go

Lines changed: 449 additions & 355 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

proto/elys/amm/query.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ message QuerySwapEstimationResponse {
274274
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
275275
(gogoproto.nullable) = false
276276
];
277+
string taker_fee = 8 [
278+
(cosmos_proto.scalar) = "cosmos.Dec",
279+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
280+
(gogoproto.nullable) = false
281+
];
277282
}
278283

279284
message QuerySwapEstimationExactAmountOutResponse {
@@ -389,6 +394,11 @@ message QuerySwapEstimationByDenomResponse {
389394
];
390395
cosmos.base.v1beta1.Coin weight_balance_reward_amount = 11
391396
[ (gogoproto.nullable) = false ];
397+
string taker_fee = 12 [
398+
(cosmos_proto.scalar) = "cosmos.Dec",
399+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
400+
(gogoproto.nullable) = false
401+
];
392402
}
393403

394404
message QueryAMMPriceRequest {

proto/elys/leveragelp/query.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ message QueryOpenEstResponse {
250250
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
251251
(gogoproto.nullable) = false
252252
];
253+
cosmos.base.v1beta1.Coin weight_balance_reward_amount = 7
254+
[ (gogoproto.nullable) = false ];
253255
}
254256

255257
message QueryCloseEstRequest {

x/amm/keeper/query_join_pool_estimation.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ func (k Keeper) JoinPoolEst(
7171
// on oracle pool, full tokenInMaxs are used regardless shareOutAmount
7272
snapshot := k.GetAccountedPoolSnapshotOrSet(ctx, pool)
7373
cacheCtx, _ := ctx.CacheContext()
74-
tokensJoined, sharesOut, slippage, weightBalanceBonus, swapFee, _, err := pool.JoinPool(cacheCtx, &snapshot, k.oracleKeeper, k.accountedPoolKeeper, tokenInMaxs, params, takerFees)
74+
tokensJoined := sdk.Coins{}
75+
tokensJoined, sharesOut, slippage, weightBalanceBonus, swapFee, takerFeesFinal, err = pool.JoinPool(cacheCtx, &snapshot, k.oracleKeeper, k.accountedPoolKeeper, tokenInMaxs, params, takerFees)
7576
if err != nil {
7677
return nil, math.ZeroInt(), math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec(), math.LegacyZeroDec(), sdk.Coin{}, err
7778
}

x/amm/keeper/query_swap_estimation.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ func (k Keeper) SwapEstimation(goCtx context.Context, req *types.QuerySwapEstima
1717

1818
ctx := sdk.UnwrapSDKContext(goCtx)
1919

20+
// Even when multiple routes, taker Fee per route is params.TakerFee/TotalRoutes, so net taker fee will be params.TakerFee
21+
takerFees := k.parameterKeeper.GetParams(ctx).TakerFees
22+
2023
spotPrice, _, tokenOut, swapFee, discount, availableLiquidity, slippage, weightBonus, err := k.CalcInRouteSpotPrice(ctx, req.TokenIn, req.Routes, req.Discount, sdkmath.LegacyZeroDec())
2124
if err != nil {
2225
return nil, err
@@ -26,6 +29,7 @@ func (k Keeper) SwapEstimation(goCtx context.Context, req *types.QuerySwapEstima
2629
SpotPrice: spotPrice,
2730
TokenOut: tokenOut,
2831
SwapFee: swapFee,
32+
TakerFee: takerFees,
2933
Discount: discount,
3034
AvailableLiquidity: availableLiquidity,
3135
Slippage: slippage,

x/amm/keeper/query_swap_estimation_by_denom.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func (k Keeper) SwapEstimationByDenom(goCtx context.Context, req *types.QuerySwa
4444
// Add weight balance amount here, not added in execution as out amount will be changed and that will impact the transfers
4545
amount.Amount = amount.Amount.Add(recoveryReward)
4646

47+
// Even when multiple routes, taker Fee per route is params.TakerFee/TotalRoutes, so net taker fee will be params.TakerFee
48+
takerFees := k.parameterKeeper.GetParams(ctx).TakerFees
49+
4750
return &types.QuerySwapEstimationByDenomResponse{
4851
InRoute: inRoute,
4952
OutRoute: outRoute,
@@ -55,6 +58,7 @@ func (k Keeper) SwapEstimationByDenom(goCtx context.Context, req *types.QuerySwa
5558
Slippage: slippage,
5659
WeightBalanceRatio: weightBonus,
5760
PriceImpact: priceImpact,
61+
TakerFee: takerFees,
5862
// sdk.NewCoin() will panic in case of negative weightBonus
5963
WeightBalanceRewardAmount: sdk.Coin{Denom: amount.Denom, Amount: recoveryReward},
6064
}, nil

x/amm/types/pool_calc_join_pool_shares.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (p *Pool) calcSingleAssetJoin(tokenIn sdk.Coin, spreadFactor sdkmath.Legacy
3434
//
3535
// It returns the number of shares created, the amount of coins actually joined into the pool
3636
// (in case of not being able to fully join), or an error.
37-
func (p *Pool) CalcSingleAssetJoinPoolShares(tokensIn sdk.Coins) (numShares sdkmath.Int, tokensJoined sdk.Coins, err error) {
37+
func (p *Pool) CalcSingleAssetJoinPoolShares(tokensIn sdk.Coins, takerFees sdkmath.LegacyDec) (numShares sdkmath.Int, tokensJoined sdk.Coins, err error) {
3838
// get all 'pool assets' (aka current pool liquidity + balancer weight)
3939
poolAssetsByDenom, err := GetPoolAssetsByDenom(p.GetAllPoolAssets())
4040
if err != nil {
@@ -53,7 +53,7 @@ func (p *Pool) CalcSingleAssetJoinPoolShares(tokensIn sdk.Coins) (numShares sdkm
5353

5454
// 2) Single token provided, so do single asset join and exit.
5555
totalShares := p.GetTotalShares()
56-
numShares, err = p.calcSingleAssetJoin(tokensIn[0], p.PoolParams.SwapFee, poolAssetsByDenom[tokensIn[0].Denom], totalShares.Amount)
56+
numShares, err = p.calcSingleAssetJoin(tokensIn[0], p.PoolParams.SwapFee.Add(takerFees), poolAssetsByDenom[tokensIn[0].Denom], totalShares.Amount)
5757
if err != nil {
5858
return sdkmath.ZeroInt(), sdk.NewCoins(), err
5959
}

x/amm/types/pool_join_pool.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (p *Pool) JoinPool(
9292
oracleKeeper OracleKeeper,
9393
accountedPoolKeeper AccountedPoolKeeper, tokensIn sdk.Coins,
9494
params Params,
95-
takerfees sdkmath.LegacyDec,
95+
takerFees sdkmath.LegacyDec,
9696
) (tokensJoined sdk.Coins, numShares sdkmath.Int, slippage sdkmath.LegacyDec, weightBalanceBonus sdkmath.LegacyDec, swapFee sdkmath.LegacyDec, takerFeesFinal sdkmath.LegacyDec, err error) {
9797
// if it's not single sided liquidity, add at pool ratio
9898
if len(tokensIn) != 1 {
@@ -122,17 +122,26 @@ func (p *Pool) JoinPool(
122122
}
123123
}
124124

125-
numShares, tokensJoined, err := p.CalcSingleAssetJoinPoolShares(tokensIn)
125+
numShares, tokensJoined, err := p.CalcSingleAssetJoinPoolShares(tokensIn, takerFees)
126126
if err != nil {
127127
return sdk.NewCoins(), sdkmath.Int{}, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), err
128128
}
129+
poolAssetsByDenom, err := GetPoolAssetsByDenom(p.GetAllPoolAssets())
130+
if err != nil {
131+
return sdk.NewCoins(), sdkmath.Int{}, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), err
132+
}
133+
totalWeight := p.TotalWeight
134+
normalizedWeight := poolAssetsByDenom[tokenIn.Denom].Weight.ToLegacyDec().Quo(totalWeight.ToLegacyDec())
135+
// We multiply the swap fee and taker fees by the normalized weight because it is calculated like this later in CalcSingleAssetJoinPoolShares function
136+
swapFee := feeRatio(normalizedWeight, p.PoolParams.SwapFee)
137+
takerFee := feeRatio(normalizedWeight, takerFees)
129138

130139
// update pool with the calculated share and liquidity needed to join pool
131140
err = p.IncreaseLiquidity(numShares, tokensJoined)
132141
if err != nil {
133142
return sdk.NewCoins(), sdkmath.Int{}, sdkmath.LegacyDec{}, sdkmath.LegacyDec{}, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), err
134143
}
135-
return tokensJoined, numShares, totalSlippage, sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), sdkmath.LegacyZeroDec(), nil
144+
return tokensJoined, numShares, totalSlippage, sdkmath.LegacyZeroDec(), swapFee, takerFee, nil
136145
}
137146

138147
accountedAssets := p.GetAccountedBalance(ctx, accountedPoolKeeper, p.PoolAssets)
@@ -171,7 +180,7 @@ func (p *Pool) JoinPool(
171180
swapFee = p.GetPoolParams().SwapFee.Mul(initialWeightOut)
172181
}
173182

174-
takerFeesFinal = takerfees.Mul(initialWeightOut)
183+
takerFeesFinal = takerFees.Mul(initialWeightOut)
175184

176185
totalShares := p.GetTotalShares()
177186
numSharesDec := sdkmath.LegacyNewDecFromInt(totalShares.Amount).

0 commit comments

Comments
 (0)