Skip to content

Commit

Permalink
- Update assets value calculation script on external liquidity feed f…
Browse files Browse the repository at this point in the history
…unction

- Update config.yml to be able to feed external liquidity info locally
  • Loading branch information
jelysn committed Sep 15, 2023
1 parent 5b0d3dc commit b65ca7d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
24 changes: 24 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ version: 1
accounts:
- name: treasury
coins:
- 100000000uatom
- 100000000uusdt
- 9000000000000000uelys
- 100000000ueden
mnemonic: olympic slide park figure frost benefit deer reform fly pull price airport submit monitor silk insect uphold convince pupil project ignore roof warfare slight
Expand Down Expand Up @@ -301,10 +303,22 @@ genesis:
display: "BTC"
bandTicker: "BTC"
elysTicker: "BTC"
decimal: 9
- denom: "wei"
display: "ETH"
bandTicker: "ETH"
elysTicker: "ETH"
decimal: 18
- denom: "uatom"
display: "ATOM"
bandTicker: "ATOM"
elysTicker: "ATOM"
decimal: 6
- denom: "uusdt"
display: "USDT"
bandTicker: "USDT"
elysTicker: "USDT"
decimal: 6
params:
ask_count: "4"
band_channel_source: "channel-0"
Expand All @@ -324,6 +338,16 @@ genesis:
- feeder: "elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w"
is_active: true
prices:
- asset: USDT
price: "1.00"
provider: elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w
source: elys
timestamp: "1694743319"
- asset: USDC
price: "1.00"
provider: elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w
source: elys
timestamp: "1694743319"
burner:
params:
epochIdentifier: day
Expand Down
13 changes: 9 additions & 4 deletions x/amm/keeper/msg_server_feed_multiple_external_liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
func AssetsValue(ctx sdk.Context, oracleKeeper types.OracleKeeper, elCoins sdk.DecCoins) (sdk.Dec, error) {
totalValue := sdk.ZeroDec()
for _, asset := range elCoins {
tokenPrice := oracleKeeper.GetAssetPriceFromDenom(ctx, asset.Denom)
if tokenPrice.IsZero() {
return sdk.ZeroDec(), fmt.Errorf("token price not set: %s", asset.Denom)
price, found := oracleKeeper.GetAssetPrice(ctx, asset.Denom)
if !found {
return sdk.ZeroDec(), fmt.Errorf("asset price not set: %s", asset.Denom)
} else {
v := tokenPrice.Mul(asset.Amount)
v := price.Price.Mul(asset.Amount)
totalValue = totalValue.Add(v)
}
}
Expand Down Expand Up @@ -62,8 +62,13 @@ func (k msgServer) FeedMultipleExternalLiquidity(goCtx context.Context, msg *typ
return nil, err
}

fmt.Println("tvl", tvl.String())
fmt.Println("elValue", elValue.String())

elRatio := elValue.Quo(tvl)
fmt.Println("elRatio1", elRatio.String(), el.Depth)
elRatio = elRatio.Quo(LiquidityRatioFromPriceDepth(el.Depth))
fmt.Println("elRatio2", elRatio.String())
if elRatio.LT(sdk.OneDec()) {
elRatio = sdk.OneDec()
}
Expand Down
1 change: 1 addition & 0 deletions x/amm/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type BankKeeper interface {

// OracleKeeper defines the expected interface needed to retrieve price info
type OracleKeeper interface {
GetAssetPrice(ctx sdk.Context, asset string) (oracletypes.Price, bool)
GetAssetPriceFromDenom(ctx sdk.Context, denom string) sdk.Dec
GetPriceFeeder(ctx sdk.Context, feeder string) (val oracletypes.PriceFeeder, found bool)
}
Expand Down
1 change: 1 addition & 0 deletions x/incentive/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type AmmKeeper interface {

// OracleKeeper defines the expected interface needed to retrieve price info
type OracleKeeper interface {
GetAssetPrice(ctx sdk.Context, asset string) (oracletypes.Price, bool)
GetAssetPriceFromDenom(ctx sdk.Context, denom string) sdk.Dec
GetPriceFeeder(ctx sdk.Context, feeder string) (val oracletypes.PriceFeeder, found bool)
}

0 comments on commit b65ca7d

Please sign in to comment.