Skip to content

Commit ffd74ea

Browse files
committed
feat: use priceoracle of the pool
1 parent 97108f1 commit ffd74ea

File tree

4 files changed

+8
-4
lines changed

4 files changed

+8
-4
lines changed

debts/engine.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ func (eng *DebtEngine) createTvlSnapshots(blockNum int64, marketToTvl MarketToTv
240240
return utils.GetFloat64Decimal(
241241
eng.GetPriceForTvl(
242242
latestOracle,
243+
state.(*schemas.PoolState).PriceOracle,
243244
underlyingToken,
244245
amount.Convert(), version), 8)
245246
}
@@ -528,10 +529,12 @@ func (eng *DebtEngine) CalculateSessionDebt(blockNum int64, session *schemas.Cre
528529
}
529530

530531
// helper methods
531-
func (eng *DebtEngine) GetPriceForTvl(priceOracle schemas.PriceOracleT, tokenAddr string, amount *big.Int, version core.VersionType) *big.Int {
532+
func (eng *DebtEngine) GetPriceForTvl(_po schemas.PriceOracleT, poolPriceOracleT schemas.PriceOracleT, tokenAddr string, amount *big.Int, version core.VersionType) *big.Int {
533+
priceOracle := poolPriceOracleT
532534
tokenPrice := eng.priceHandler.GetTokenLastPF(priceOracle, tokenAddr, version)
533535
tokenDecimals := eng.repo.GetToken(tokenAddr).Decimals
534536
if version.MoreThan(core.NewVersion(1)) { // than decimals 8
537+
// log.Info("GetPriceForTvl", tokenPrice, amount, tokenDecimals, tokenAddr, priceOracle)
535538
return utils.GetInt64(new(big.Int).Mul(tokenPrice.PriceBI.Convert(), amount), tokenDecimals)
536539
}
537540
// for v1

jsonnet/mocks/syncAdapterV2.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
address: '#Pool_1',
124124
dieselToken: '#DieselToken_1',
125125
underlyingToken: '#Token_1',
126-
priceOracle: '#PriceOracle_0',
126+
priceOracle: '#PriceOracle_1',
127127
},
128128
],
129129
cmState: [

models/credit_manager/cm_v3/model.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func NewCMv3(addr string, client core.ClientI, repo ds.RepositoryI, discoveredAt
3939
mdl.addCreditConfiguratorAdapter(mdl.GetDetailsByKey("configurator"))
4040
mdl.Repo.UpdateFees(0, "", mdl.GetDetailsByKey("configurator"), params)
4141
configurator := mdl.GetDetailsByKey("configurator")
42-
ltData, err := core.CallFuncGetSingleValue(mdl.Client, "0x78327438", common.HexToAddress(configurator), discoveredAt, nil)
42+
tokenHash := common.HexToHash(mdl.GetUnderlyingToken())
43+
ltData, err := core.CallFuncGetSingleValue(mdl.Client, "0x78327438", common.HexToAddress(configurator), discoveredAt, tokenHash[:])
4344
if err == nil {
4445
lt := new(big.Int).SetBytes(ltData)
4546
mdl.Repo.AddAllowedTokenV2(0, "", configurator, &schemas.AllowedToken{

repository/token.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (repo *Repository) GetUSD() common.Address {
2727
var t common.Address
2828
if chainid == 146 {
2929
t = core.GetToken(chainid, "USDC_e")
30-
} else if chainid == 1135 {
30+
} else if chainid == 1135 || chainid == 43111 {
3131
t = core.GetToken(chainid, "USDC.e")
3232
} else if chainid == 56 {
3333
t = core.GetToken(chainid, "USDT")

0 commit comments

Comments
 (0)