@@ -165,54 +165,29 @@ export function toStakingTransaction(tx: TransactionLike): bitcoinjslib.Transact
165165 *
166166 * The difference is that here we are returning an _unsigned_ delegation message.
167167 */
168- export async function createUnsignedPreStakeRegistrationBabylonTransaction (
168+ export async function createDelegationMessageWithTransaction (
169169 manager : vendor . BabylonBtcStakingManager ,
170- stakingParams : vendor . VersionedStakingParams [ ] ,
171- network : bitcoinjslib . Network ,
172- stakerBtcInfo : vendor . StakerInfo ,
173- stakingInput : vendor . StakingInputs ,
174- babylonBtcTipHeight : number ,
175- inputUTXOs : vendor . UTXO [ ] ,
176- feeRateSatB : number ,
170+ staking : vendor . Staking ,
171+ stakingAmountSat : number ,
172+ transaction : TransactionLike ,
177173 babylonAddress : string
178- ) : Promise < Result > {
179- if ( babylonBtcTipHeight === 0 ) {
180- throw new Error ( 'Babylon BTC tip height cannot be 0' ) ;
181- }
182- if ( inputUTXOs . length === 0 ) {
183- throw new Error ( 'No input UTXOs provided' ) ;
184- }
174+ ) : Promise < ValueWithTypeUrl < babylonProtobuf . btcstakingtx . MsgCreateBTCDelegation > > {
185175 if ( ! vendor . isValidBabylonAddress ( babylonAddress ) ) {
186176 throw new Error ( 'Invalid Babylon address' ) ;
187177 }
188-
189- // Get the Babylon params based on the BTC tip height from Babylon chain
190- const params = vendor . getBabylonParamByBtcHeight ( babylonBtcTipHeight , stakingParams ) ;
191-
192- const staking = new vendor . Staking (
193- network ,
194- stakerBtcInfo ,
195- params ,
196- stakingInput . finalityProviderPkNoCoordHex ,
197- stakingInput . stakingTimelock
198- ) ;
199-
200- // Create unsigned staking transaction
201- const { transaction } = staking . createStakingTransaction ( stakingInput . stakingAmountSat , inputUTXOs , feeRateSatB ) ;
202-
203178 // Create delegation message without including inclusion proof
204- const msg = await manager . createBtcDelegationMsg (
179+ return manager . createBtcDelegationMsg (
205180 staking ,
206- stakingInput ,
207- transaction ,
181+ {
182+ stakingTimelock : staking . stakingTimelock ,
183+ finalityProviderPkNoCoordHex : staking . finalityProviderPkNoCoordHex ,
184+ stakingAmountSat,
185+ } ,
186+ toStakingTransaction ( transaction ) ,
208187 babylonAddress ,
209- stakerBtcInfo ,
210- params
188+ staking . stakerInfo ,
189+ staking . params
211190 ) ;
212- return {
213- unsignedDelegationMsg : msg ,
214- stakingTx : transaction ,
215- } ;
216191}
217192
218193export async function createUnsignedPreStakeRegistrationBabylonTransactionWithBtcProvider (
@@ -226,16 +201,19 @@ export async function createUnsignedPreStakeRegistrationBabylonTransactionWithBt
226201 babylonAddress : string ,
227202 stakingParams : vendor . VersionedStakingParams [ ] = getStakingParams ( network )
228203) : Promise < Result > {
204+ if ( inputUTXOs . length === 0 ) {
205+ throw new Error ( 'No input UTXOs provided' ) ;
206+ }
229207 const manager = createStakingManager ( network , btcProvider , stakingParams ) ;
230- return await createUnsignedPreStakeRegistrationBabylonTransaction (
208+ const staking = createStaking ( network , babylonBtcTipHeight , stakerBtcInfo , stakingInput , stakingParams ) ;
209+ // Create unsigned staking transaction
210+ const { transaction } = staking . createStakingTransaction ( stakingInput . stakingAmountSat , inputUTXOs , feeRateSatB ) ;
211+ const unsignedDelegationMsg = await createDelegationMessageWithTransaction (
231212 manager ,
232- stakingParams ,
233- network ,
234- stakerBtcInfo ,
235- stakingInput ,
236- babylonBtcTipHeight ,
237- inputUTXOs ,
238- feeRateSatB ,
213+ staking ,
214+ stakingInput . stakingAmountSat ,
215+ transaction ,
239216 babylonAddress
240217 ) ;
218+ return { unsignedDelegationMsg, stakingTx : transaction } ;
241219}
0 commit comments