@@ -10,12 +10,12 @@ import (
10
10
"github.com/btcsuite/btcd/btcec/v2"
11
11
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
12
12
13
- "github.com/babylonlabs-io/babylon/client/babylonclient"
14
- bbnclient "github.com/babylonlabs-io/babylon/client/client"
15
- bbntypes "github.com/babylonlabs-io/babylon/types"
16
- btcctypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types"
17
- btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types"
18
- btcstakingtypes "github.com/babylonlabs-io/babylon/x/btcstaking/types"
13
+ "github.com/babylonlabs-io/babylon/v3/ client/babylonclient"
14
+ bbnclient "github.com/babylonlabs-io/babylon/v3/ client/client"
15
+ bbntypes "github.com/babylonlabs-io/babylon/v3/ types"
16
+ btcctypes "github.com/babylonlabs-io/babylon/v3/ x/btccheckpoint/types"
17
+ btclctypes "github.com/babylonlabs-io/babylon/v3/ x/btclightclient/types"
18
+ btcstakingtypes "github.com/babylonlabs-io/babylon/v3/ x/btcstaking/types"
19
19
"github.com/btcsuite/btcd/btcutil"
20
20
"github.com/btcsuite/btcd/chaincfg"
21
21
sdkclient "github.com/cosmos/cosmos-sdk/client"
@@ -165,14 +165,22 @@ func (bc *BabylonController) SubmitCovenantSigs(covSigs []*types.CovenantSigs) (
165
165
msgs := make ([]sdk.Msg , 0 , len (covSigs ))
166
166
for _ , covSig := range covSigs {
167
167
bip340UnbondingSig := bbntypes .NewBIP340SignatureFromBTCSig (covSig .UnbondingSig )
168
- msgs = append ( msgs , & btcstakingtypes.MsgAddCovenantSigs {
168
+ msg := & btcstakingtypes.MsgAddCovenantSigs {
169
169
Signer : bc .mustGetTxSigner (),
170
170
Pk : bbntypes .NewBIP340PubKeyFromBTCPK (covSig .PublicKey ),
171
171
StakingTxHash : covSig .StakingTxHash .String (),
172
172
SlashingTxSigs : covSig .SlashingSigs ,
173
173
UnbondingTxSig : bip340UnbondingSig ,
174
174
SlashingUnbondingTxSigs : covSig .SlashingUnbondingSigs ,
175
- })
175
+ StakeExpansionTxSig : nil ,
176
+ }
177
+
178
+ if covSig .StkExpSig != nil {
179
+ stkExpSig := bbntypes .NewBIP340SignatureFromBTCSig (covSig .StkExpSig )
180
+ msg .StakeExpansionTxSig = stkExpSig
181
+ }
182
+
183
+ msgs = append (msgs , msg )
176
184
}
177
185
res , err := bc .reliablySendMsgs (msgs )
178
186
if err != nil {
@@ -198,6 +206,15 @@ func (bc *BabylonController) QueryVerifiedDelegations(limit uint64) ([]*types.De
198
206
return bc .queryDelegationsWithStatus (btcstakingtypes .BTCDelegationStatus_VERIFIED , limit , nil )
199
207
}
200
208
209
+ // QueryBTCDelegation queries the BTC delegation by the tx hash
210
+ func (bc * BabylonController ) QueryBTCDelegation (stakingTxHashHex string ) (* types.Delegation , error ) {
211
+ resp , err := bc .bbnClient .QueryClient .BTCDelegation (stakingTxHashHex )
212
+ if err != nil {
213
+ return nil , fmt .Errorf ("failed to query BTC delegation %s: %v" , stakingTxHashHex , err )
214
+ }
215
+ return DelegationRespToDelegation (resp .BtcDelegation )
216
+ }
217
+
201
218
// queryDelegationsWithStatus queries BTC delegations that need a Covenant signature
202
219
// with the given status (either pending or unbonding)
203
220
// it is only used when the program is running in Covenant mode
@@ -308,7 +325,7 @@ func DelegationRespToDelegation(del *btcstakingtypes.BTCDelegationResponse) (*ty
308
325
return nil , fmt .Errorf ("total sat (%d) is larger than the maximum int64" , del .TotalSat )
309
326
}
310
327
311
- return & types.Delegation {
328
+ respDel := & types.Delegation {
312
329
BtcPk : del .BtcPk .MustToBTCPK (),
313
330
FpBtcPks : fpBtcPks ,
314
331
TotalSat : btcutil .Amount (del .TotalSat ),
@@ -322,7 +339,17 @@ func DelegationRespToDelegation(del *btcstakingtypes.BTCDelegationResponse) (*ty
322
339
UnbondingTime : uint16 (del .UnbondingTime ),
323
340
BtcUndelegation : undelegation ,
324
341
ParamsVersion : del .ParamsVersion ,
325
- }, nil
342
+ StakeExpansion : nil ,
343
+ }
344
+
345
+ if del .StkExp != nil {
346
+ respDel .StakeExpansion = & types.DelegationStakeExpansion {
347
+ PreviousStakingTxHashHex : del .StkExp .PreviousStakingTxHashHex ,
348
+ OtherFundingTxOutHex : del .StkExp .OtherFundingTxOutHex ,
349
+ }
350
+ }
351
+
352
+ return respDel , nil
326
353
}
327
354
328
355
func UndelegationRespToUndelegation (undel * btcstakingtypes.BTCUndelegationResponse ) (* types.Undelegation , error ) {
@@ -426,6 +453,57 @@ func (bc *BabylonController) CreateBTCDelegation(
426
453
return & types.TxResponse {TxHash : res .TxHash }, nil
427
454
}
428
455
456
+ // CreateStakeExpansionDelegation creates a BTC stake expansion delegation using MsgBtcStakeExpand
457
+ // Currently this is only used for e2e tests, probably does not need to add it into the interface
458
+ func (bc * BabylonController ) CreateStakeExpansionDelegation (
459
+ delBtcPk * bbntypes.BIP340PubKey ,
460
+ fpPks []* btcec.PublicKey ,
461
+ pop * btcstakingtypes.ProofOfPossessionBTC ,
462
+ stakingTime uint32 ,
463
+ stakingValue int64 ,
464
+ stakingTxInfo * btcctypes.TransactionInfo ,
465
+ slashingTx * btcstakingtypes.BTCSlashingTx ,
466
+ delSlashingSig * bbntypes.BIP340Signature ,
467
+ unbondingTx []byte ,
468
+ unbondingTime uint32 ,
469
+ unbondingValue int64 ,
470
+ unbondingSlashingTx * btcstakingtypes.BTCSlashingTx ,
471
+ delUnbondingSlashingSig * bbntypes.BIP340Signature ,
472
+ previousStakingTxHash string ,
473
+ fundingTx []byte ,
474
+ ) (* types.TxResponse , error ) {
475
+ fpBtcPks := make ([]bbntypes.BIP340PubKey , 0 , len (fpPks ))
476
+ for _ , v := range fpPks {
477
+ fpBtcPks = append (fpBtcPks , * bbntypes .NewBIP340PubKeyFromBTCPK (v ))
478
+ }
479
+
480
+ msg := & btcstakingtypes.MsgBtcStakeExpand {
481
+ StakerAddr : bc .mustGetTxSigner (),
482
+ Pop : pop ,
483
+ BtcPk : delBtcPk ,
484
+ FpBtcPkList : fpBtcPks ,
485
+ StakingTime : stakingTime ,
486
+ StakingValue : stakingValue ,
487
+ StakingTx : stakingTxInfo .Transaction ,
488
+ SlashingTx : slashingTx ,
489
+ DelegatorSlashingSig : delSlashingSig ,
490
+ UnbondingTx : unbondingTx ,
491
+ UnbondingTime : unbondingTime ,
492
+ UnbondingValue : unbondingValue ,
493
+ UnbondingSlashingTx : unbondingSlashingTx ,
494
+ DelegatorUnbondingSlashingSig : delUnbondingSlashingSig ,
495
+ PreviousStakingTxHash : previousStakingTxHash ,
496
+ FundingTx : fundingTx ,
497
+ }
498
+
499
+ res , err := bc .reliablySendMsg (msg )
500
+ if err != nil {
501
+ return nil , err
502
+ }
503
+
504
+ return & types.TxResponse {TxHash : res .TxHash }, nil
505
+ }
506
+
429
507
// Register a finality provider to Babylon
430
508
// Currently this is only used for e2e tests, probably does not need to add it into the interface
431
509
func (bc * BabylonController ) RegisterFinalityProvider (
0 commit comments