Skip to content

Commit d38d02f

Browse files
committed
use actual fee rate to build settlement tx
1 parent 98aa4d0 commit d38d02f

6 files changed

Lines changed: 41 additions & 12 deletions

File tree

app/app.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ func New(
705705
app.BankKeeper,
706706
app.OracleKeeper,
707707
app.TSSKeeper,
708+
app.BtcBridgeKeeper,
708709
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
709710
)
710711

testutil/keeper/liquidation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func LiquidationKeeper(t testing.TB) (keeper.Keeper, sdk.Context) {
4848
app.BankKeeper,
4949
app.OracleKeeper,
5050
app.TSSKeeper,
51+
app.BtcBridgeKeeper,
5152
authority,
5253
)
5354

x/lending/types/expected_keepers.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ type DLCKeeper interface {
8585
type BtcBridgeKeeper interface {
8686
DepositConfirmationDepth(ctx sdk.Context) int32
8787
ValidateTransaction(ctx sdk.Context, tx string, prevTx string, blockHash string, proof []string, confirmationDepth int32) (*btcutil.Tx, *btcutil.Tx, error)
88+
8889
GetFeeRate(ctx sdk.Context) *btcbridgetypes.FeeRate
90+
CheckFeeRate(ctx sdk.Context, feeRate *btcbridgetypes.FeeRate) error
8991
}
9092

9193
// TSSKeeper defines the expected TSS keeper interface

x/liquidation/keeper/keeper.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ type Keeper struct {
1414
storeKey storetypes.StoreKey
1515
memKey storetypes.StoreKey
1616

17-
bankKeeper types.BankKeeper
18-
oracleKeeper types.OracleKeeper
19-
tssKeeper types.TSSKeeper
17+
bankKeeper types.BankKeeper
18+
oracleKeeper types.OracleKeeper
19+
tssKeeper types.TSSKeeper
20+
btcbridgeKeeper types.BtcBridgeKeeper
2021

2122
liquidatedDebtHandler types.LiquidatedDebtHandler
2223

@@ -30,16 +31,18 @@ func NewKeeper(
3031
bankKeeper types.BankKeeper,
3132
oracleKeeper types.OracleKeeper,
3233
tssKeeper types.TSSKeeper,
34+
btcbridgeKeeper types.BtcBridgeKeeper,
3335
authority string,
3436
) *Keeper {
3537
k := &Keeper{
36-
cdc: cdc,
37-
storeKey: storeKey,
38-
memKey: memKey,
39-
bankKeeper: bankKeeper,
40-
oracleKeeper: oracleKeeper,
41-
tssKeeper: tssKeeper,
42-
authority: authority,
38+
cdc: cdc,
39+
storeKey: storeKey,
40+
memKey: memKey,
41+
bankKeeper: bankKeeper,
42+
oracleKeeper: oracleKeeper,
43+
tssKeeper: tssKeeper,
44+
btcbridgeKeeper: btcbridgeKeeper,
45+
authority: authority,
4346
}
4447

4548
// register signing request completed handler
@@ -81,6 +84,10 @@ func (k Keeper) TSSKeeper() types.TSSKeeper {
8184
return k.tssKeeper
8285
}
8386

87+
func (k Keeper) BtcBridgeKeeper() types.BtcBridgeKeeper {
88+
return k.btcbridgeKeeper
89+
}
90+
8491
func (k Keeper) LiquidatedDebtHandler() types.LiquidatedDebtHandler {
8592
return k.liquidatedDebtHandler
8693
}

x/liquidation/module/abci.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
1717
func handleCompletedLiquidations(ctx sdk.Context, k keeper.Keeper) {
1818
// get completed liquidations
1919
liquidations := k.GetLiquidations(ctx, types.LiquidationStatus_LIQUIDATION_STATUS_LIQUIDATED)
20+
if len(liquidations) == 0 {
21+
return
22+
}
23+
24+
// get fee rate
25+
feeRate := k.BtcBridgeKeeper().GetFeeRate(ctx)
26+
if err := k.BtcBridgeKeeper().CheckFeeRate(ctx, feeRate); err != nil {
27+
k.Logger(ctx).Info("Failed to get fee rate to handle liquidation", "err", err)
28+
29+
return
30+
}
2031

2132
for _, liquidation := range liquidations {
2233
// handle liquidated debt(repay the lending pool)
@@ -28,9 +39,9 @@ func handleCompletedLiquidations(ctx sdk.Context, k keeper.Keeper) {
2839
}
2940

3041
// build settlement tx
31-
settlementTx, txHash, sigHashes, changeAmount, err := types.BuildSettlementTransaction(liquidation, k.GetLiquidationRecords(ctx, liquidation.Id), k.ProtocolLiquidationFeeCollector(ctx), 5)
42+
settlementTx, txHash, sigHashes, changeAmount, err := types.BuildSettlementTransaction(liquidation, k.GetLiquidationRecords(ctx, liquidation.Id), k.ProtocolLiquidationFeeCollector(ctx), feeRate.Value)
3243
if err != nil {
33-
k.Logger(ctx).Info("Failed to build settlement transaction", "liquidation id", liquidation.Id, "err", err)
44+
k.Logger(ctx).Info("Failed to build settlement transaction", "liquidation id", liquidation.Id, "fee rate", feeRate.Value, "err", err)
3445

3546
continue
3647
}

x/liquidation/types/expected_keepers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
sdk "github.com/cosmos/cosmos-sdk/types"
88
banktype "github.com/cosmos/cosmos-sdk/x/bank/types"
99

10+
btcbridgetypes "github.com/sideprotocol/side/x/btcbridge/types"
1011
tsstypes "github.com/sideprotocol/side/x/tss/types"
1112
)
1213

@@ -40,3 +41,9 @@ type TSSKeeper interface {
4041

4142
RegisterSigningRequestCompletedHandler(module string, handler tsstypes.SigningRequestCompletedHandler)
4243
}
44+
45+
// BtcBridgeKeeper defines the expected BtcBridge keeper interface
46+
type BtcBridgeKeeper interface {
47+
GetFeeRate(ctx sdk.Context) *btcbridgetypes.FeeRate
48+
CheckFeeRate(ctx sdk.Context, feeRate *btcbridgetypes.FeeRate) error
49+
}

0 commit comments

Comments
 (0)