Skip to content

Commit b92db0d

Browse files
committed
feat: fix number format
1 parent 1ecd5fc commit b92db0d

File tree

7 files changed

+17
-31
lines changed

7 files changed

+17
-31
lines changed

debts/debt_db.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (eng *DebtEngine) liquidationCheck(debt *schemas.Debt, cmAddr, borrower str
2525
(debt.BlockNumber-eng.liquidableBlockTracker[debt.SessionId].BlockNum) >= sendMsgAfterXBlocks {
2626
eng.repo.RecentMsgf(log.RiskHeader{
2727
BlockNumber: debt.BlockNumber,
28-
EventCode: "AMQP",
28+
EventCode: "WARN",
2929
}, `HealthFactor safe again:
3030
SessionId:%s
3131
HF: %s@(block:%d) -> %s@(block:%d)`,
@@ -48,7 +48,7 @@ func (eng *DebtEngine) liquidationCheck(debt *schemas.Debt, cmAddr, borrower str
4848
eng.notifiedIfLiquidable(debt.SessionId, true)
4949
eng.repo.RecentMsgf(log.RiskHeader{
5050
BlockNumber: debt.BlockNumber,
51-
EventCode: "INV-LOW-HF-NOT-LIQUIDATED",
51+
EventCode: "WARN",
5252
}, `After %d blocks:
5353
Session: %s
5454
HF: %s

models/credit_manager/cm_v1/on_change.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func OnDirectTokenTransfer(repo ds.RepositoryI, tx *schemas.TokenTransfer, sessi
1414
}
1515
repo.RecentMsgf(log.RiskHeader{
1616
BlockNumber: tx.BlockNum,
17-
EventCode: "AMQP",
17+
EventCode: "WARN",
1818
}, "Deposit: %s", cm_common.DirecTokenTransferString(repo, tx))
1919
amount := tx.Amount.Convert()
2020
repo.AddAccountOperation(&schemas.AccountOperation{

models/pool/pool_common/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ func CheckIfAmountMoreThan1Mil(client core.ClientI, repo ds.RepositoryI, state *
2222
repo.RecentMsgf(log.RiskHeader{
2323
BlockNumber: blockNum,
2424
EventCode: "AMQP",
25-
}, "Pool %s in %s is more than 1Million USD, calculated value is %f", operation, urls.ExplorerHashUrl(txHash), value)
25+
}, "Pool %s in %s is more than 1Million USD, calculated value is %.2f", operation, urls.ExplorerHashUrl(txHash), value/1_000_000)
2626
}
2727
}

models/pool/pool_v2/on_log.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pool_v2
22

33
import (
4+
"fmt"
45
"math/big"
56

67
"github.com/Gearbox-protocol/sdk-go/core"
@@ -48,7 +49,8 @@ func (mdl *Poolv2) OnLog(txLog types.Log) {
4849
AmountBI: (*core.BigInt)(addLiquidityEvent.Amount),
4950
Amount: utils.GetFloat64Decimal(addLiquidityEvent.Amount, mdl.Repo.GetToken(mdl.State.UnderlyingToken).Decimals),
5051
})
51-
pool_common.CheckIfAmountMoreThan1Mil(mdl.Client, mdl.Repo, mdl.State, addLiquidityEvent.Amount, blockNum, txLog.TxHash.Hex(), "deposit")
52+
pool_common.CheckIfAmountMoreThan1Mil(mdl.Client, mdl.Repo, mdl.State, addLiquidityEvent.Amount, blockNum, txLog.TxHash.Hex(),
53+
fmt.Sprintf("%s deposit", mdl.Repo.GetToken(mdl.State.UnderlyingToken).Symbol))
5254
mdl.updateBorrowRate(blockNum)
5355
case core.Topic("RemoveLiquidity(address,address,uint256)"):
5456
removeLiquidityEvent, err := mdl.contractETH.ParseRemoveLiquidity(txLog)
@@ -67,7 +69,8 @@ func (mdl *Poolv2) OnLog(txLog types.Log) {
6769
Receiver: removeLiquidityEvent.To.Hex(),
6870
AmountBI: (*core.BigInt)(removeLiquidityEvent.Amount),
6971
})
70-
pool_common.CheckIfAmountMoreThan1Mil(mdl.Client, mdl.Repo, mdl.State, removeLiquidityEvent.Amount, blockNum, txLog.TxHash.Hex(), "withdrawn")
72+
pool_common.CheckIfAmountMoreThan1Mil(mdl.Client, mdl.Repo, mdl.State, removeLiquidityEvent.Amount, blockNum, txLog.TxHash.Hex(),
73+
fmt.Sprintf("%s withdrawal", mdl.Repo.GetToken(mdl.State.UnderlyingToken).Symbol))
7174

7275
mdl.updateBorrowRate(blockNum)
7376
case core.Topic("Borrow(address,address,uint256)"):
@@ -175,19 +178,3 @@ func (mdl *Poolv2) OnLog(txLog types.Log) {
175178
mdl.gatewayHandler.CheckWithdrawETH(txLog.TxHash.Hex(), blockNum, int64(ind), mdl.Address, to)
176179
}
177180
}
178-
179-
func (mdl Poolv2) checkIfAmountMoreThan1Mil(amount *big.Int, blockNum int64, txHash string, operation string) {
180-
token := mdl.State.UnderlyingToken
181-
priceInUSD := mdl.Repo.GetPrice(token)
182-
if priceInUSD == nil {
183-
return
184-
}
185-
value := utils.GetFloat64Decimal(new(big.Int).Mul(priceInUSD, amount), mdl.Repo.GetToken(token).Decimals+8)
186-
if value > 1_000_000 {
187-
urls := log.NetworkUIUrl(core.GetChainId(mdl.Client))
188-
mdl.Repo.RecentMsgf(log.RiskHeader{
189-
BlockNumber: blockNum,
190-
EventCode: "AMQP",
191-
}, "Pool %s in %s is more than 1Million USD, calculated value is %f", operation, urls.ExplorerHashUrl(txHash), value)
192-
}
193-
}

models/pool/pool_v3/on_log.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package pool_v3
22

33
import (
4+
"fmt"
45
"math/big"
56

67
"github.com/Gearbox-protocol/sdk-go/core"
@@ -69,7 +70,8 @@ func (mdl *Poolv3) OnLog(txLog types.Log) {
6970
} else {
7071
mdl.Repo.AddPoolLedger(event)
7172
}
72-
pool_common.CheckIfAmountMoreThan1Mil(mdl.Client, mdl.Repo, mdl.State, deposit.Assets, blockNum, txLog.TxHash.Hex(), "deposit")
73+
pool_common.CheckIfAmountMoreThan1Mil(mdl.Client, mdl.Repo, mdl.State, deposit.Assets, blockNum, txLog.TxHash.Hex(),
74+
fmt.Sprintf("%s deposit", mdl.Repo.GetToken(mdl.State.UnderlyingToken).Symbol))
7375
mdl.updateBorrowRate(blockNum)
7476
// while processing withdrawal event, add to receiver and sub from User
7577
case core.Topic("Withdraw(address,address,address,uint256,uint256)"):
@@ -97,7 +99,8 @@ func (mdl *Poolv3) OnLog(txLog types.Log) {
9799
mdl.Repo.AddPoolLedger(event)
98100
}
99101
//
100-
pool_common.CheckIfAmountMoreThan1Mil(mdl.Client, mdl.Repo, mdl.State, withdrawal.Assets, blockNum, txLog.TxHash.Hex(), "withdraw")
102+
pool_common.CheckIfAmountMoreThan1Mil(mdl.Client, mdl.Repo, mdl.State, withdrawal.Assets, blockNum, txLog.TxHash.Hex(),
103+
fmt.Sprintf("%s withdrawal", mdl.Repo.GetToken(mdl.State.UnderlyingToken).Symbol))
101104
mdl.updateBorrowRate(blockNum)
102105
case core.Topic("Borrow(address,address,uint256)"):
103106
mdl.updateBorrowRate(blockNum)

repository/handlers/blocks.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package handlers
22

33
import (
44
"context"
5-
"fmt"
65
"math/big"
76
"strings"
87
"time"
@@ -184,11 +183,8 @@ func (repo *BlocksRepo) RecentMsgf(header log.RiskHeader, msg string, args ...in
184183
}
185184
if header.EventCode == "AMQP" {
186185
log.AMQPMsgf(msg, args...)
187-
} else {
188-
log.SendRiskAlert(log.RiskAlert{
189-
Msg: fmt.Sprintf(msg, args...),
190-
RiskHeader: header,
191-
})
186+
} else if header.EventCode == "WARN" {
187+
log.Warnf(msg, args...)
192188
}
193189
}
194190

repository/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func (repo *Repository) AfterSync(syncTill int64) {
168168
for _, tx := range txs {
169169
repo.RecentMsgf(log.RiskHeader{
170170
BlockNumber: tx.BlockNum,
171-
EventCode: "AMQP",
171+
EventCode: "WARN",
172172
}, "No session account token transfer: %v", tx)
173173
repo.SetAndGetBlock(tx.BlockNum).AddNoSessionTx(tx)
174174
}

0 commit comments

Comments
 (0)