Skip to content

Commit 02cff0d

Browse files
committed
adjust timeout refund tx
1 parent dd6a0c8 commit 02cff0d

4 files changed

Lines changed: 12 additions & 2 deletions

File tree

x/lending/keeper/dlc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (k Keeper) UpdateDLCMeta(ctx sdk.Context, loanId string, depositTxs []*psbt
106106
}
107107

108108
// timeout refund transaction can be generated offchain as needed
109-
timeoutRefundTx, err := types.CreateTimeoutRefundTransaction(depositTxs, vaultPkScript, borrowerPkScript, internalKey, dlcMeta.TimeoutRefundScript, feeRate.Value)
109+
timeoutRefundTx, err := types.CreateTimeoutRefundTransaction(depositTxs, vaultPkScript, borrowerPkScript, internalKey, dlcMeta.TimeoutRefundScript, loan.FinalTimeout, feeRate.Value)
110110
if err != nil {
111111
return err
112112
}

x/lending/types/bitcoin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ const (
1717

1818
// default maximum allowed transaction weight
1919
MaxTransactionWeight = 400000
20+
21+
// default sequence
22+
DefaultSequence = wire.MaxTxInSequenceNum - 1
2023
)
2124

2225
// BuildPsbt builds a psbt from the given params
@@ -84,6 +87,7 @@ func AddUTXOToTx(tx *wire.MsgTx, utxo *btcbridgetypes.UTXO) {
8487
}
8588

8689
txIn.PreviousOutPoint = *wire.NewOutPoint(hash, uint32(utxo.Vout))
90+
txIn.Sequence = DefaultSequence
8791

8892
tx.AddTxIn(txIn)
8993
}

x/lending/types/dlc.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func VerifyRepaymentCet(dlcMeta *DLCMeta, depositTxs []*psbt.Packet, vaultPkScri
295295
}
296296

297297
// CreateTimeoutRefundTransaction creates the timeout refund tx
298-
func CreateTimeoutRefundTransaction(depositTxs []*psbt.Packet, vaultPkScript []byte, borrowerPkScript []byte, internalKeyBytes []byte, leafScript LeafScript, feeRate int64) (string, error) {
298+
func CreateTimeoutRefundTransaction(depositTxs []*psbt.Packet, vaultPkScript []byte, borrowerPkScript []byte, internalKeyBytes []byte, leafScript LeafScript, lockTime int64, feeRate int64) (string, error) {
299299
vaultUtxos, err := GetVaultUtxos(depositTxs, vaultPkScript)
300300
if err != nil {
301301
return "", err
@@ -311,6 +311,8 @@ func CreateTimeoutRefundTransaction(depositTxs []*psbt.Packet, vaultPkScript []b
311311
return "", err
312312
}
313313

314+
p.UnsignedTx.LockTime = uint32(lockTime)
315+
314316
for i := range p.Inputs {
315317
p.Inputs[i].SighashType = DefaultSigHashType
316318
p.Inputs[i].TaprootInternalKey = internalKeyBytes

x/liquidation/types/bitcoin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const (
2323

2424
// default sig hash type
2525
DefaultSigHashType = txscript.SigHashDefault
26+
27+
// default sequence
28+
DefaultSequence = wire.MaxTxInSequenceNum - 1
2629
)
2730

2831
// BuildSettlementTransaction builds the settlement tx for the given liquidation and records
@@ -189,6 +192,7 @@ func AddUTXOToTx(tx *wire.MsgTx, utxo *btcbridgetypes.UTXO) {
189192
}
190193

191194
txIn.PreviousOutPoint = *wire.NewOutPoint(hash, uint32(utxo.Vout))
195+
txIn.Sequence = DefaultSequence
192196

193197
tx.AddTxIn(txIn)
194198
}

0 commit comments

Comments
 (0)