Skip to content

Commit

Permalink
chore: rename unbondingTimelockScript to timelockScript in the input …
Browse files Browse the repository at this point in the history
…parameter
  • Loading branch information
jrwbabylonlab committed Jan 7, 2025
1 parent 3433c46 commit b4a10cb
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
14 changes: 12 additions & 2 deletions src/staking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,24 @@ export class Staking {
// Reconstruct and validate the slashingOutputIndex
const slashingOutputIndex = findMatchingTxOutputIndex(
slashingTx,
deriveSlashingOutputAddress(scripts, this.network),
deriveSlashingOutputAddress(
{
timelockScript: scripts.unbondingTimelockScript,
},
this.network,
),
this.network,
)

// Create the withdraw slashed transaction
try {
return withdrawSlashingTransaction(
scripts,
{
// Unbonding timelock script is used as the timelock of slashing
// is the same as the unbonding timelock.
timelockScript: scripts.unbondingTimelockScript,
slashingScript: scripts.slashingScript,
},
slashingTx,
this.stakerInfo.address,
this.network,
Expand Down
6 changes: 3 additions & 3 deletions src/staking/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export function withdrawTimelockUnbondedTransaction(
*/
export function withdrawSlashingTransaction(
scripts: {
unbondingTimelockScript: Buffer;
timelockScript: Buffer;
slashingScript: Buffer;
},
slashingTx: Transaction,
Expand All @@ -264,12 +264,12 @@ export function withdrawSlashingTransaction(
{
output: scripts.slashingScript,
},
{ output: scripts.unbondingTimelockScript },
{ output: scripts.timelockScript },
];

return withdrawalTransaction(
{
timelockScript: scripts.unbondingTimelockScript,
timelockScript: scripts.timelockScript,
},
scriptTree,
slashingTx,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/staking/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ export const deriveStakingOutputAddress = (
*/
export const deriveSlashingOutputAddress = (
scripts: {
unbondingTimelockScript: Buffer;
timelockScript: Buffer;
},
network: networks.Network,
) => {
const slashingOutput = payments.p2tr({
internalPubkey,
scriptTree: { output: scripts.unbondingTimelockScript },
scriptTree: { output: scripts.timelockScript },
network,
});

Expand Down
12 changes: 12 additions & 0 deletions tests/helper/datagen/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,18 @@ export class StakingDataGenerator {
}
};

/**
* Generates a random slashing transaction based on the staking transaction
* and staking scripts
* @param network - The network to use
* @param stakingScripts - The staking scripts to use
* @param stakingTx - The staking transaction to use
* @param param - The param used in the staking transaction
* @param keyPair - The key pair to use. This is used to sign the slashing
* psbt to derive the transaction.
* @param type - The type of slashing to use.
* @returns {Object} - A random slashing transaction
*/
generateSlashingTransaction = (
network: bitcoin.networks.Network,
stakingScripts: StakingScripts,
Expand Down
12 changes: 10 additions & 2 deletions tests/staking/transactions/withdrawTransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,20 @@ describe.each(testingNetworks)("withdrawTransaction", (

const outputIndex = findMatchingTxOutputIndex(
slashingTx,
deriveSlashingOutputAddress(testData.stakingScripts, network),
deriveSlashingOutputAddress(
{
timelockScript: testData.stakingScripts.unbondingTimelockScript,
},
network,
),
network,
);

const psbt = withdrawSlashingTransaction(
testData.stakingScripts,
{
timelockScript: testData.stakingScripts.unbondingTimelockScript,
slashingScript: testData.stakingScripts.slashingScript,
},
slashingTx,
testData.stakerInfo.address,
network,
Expand Down

0 comments on commit b4a10cb

Please sign in to comment.