Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add signer opts to agg increase #1669

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion packages/stacking/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ export interface StackAggregationIncreaseOptions {
rewardCycle: number;
rewardIndex: number;
privateKey: string;
/** hex-encoded signer key `(buff 33)`, required for >= PoX-4 */
signerKey?: string;
/** hex-encoded signature `(buff 65)`, required for >= PoX-4 */
signerSignature?: string;
/** Maximum amount of STX that can be locked in this transaction, required for >= PoX-4 */
maxAmount?: IntegerType;
/** Random integer to prevent re-use of signer signature, required for >= PoX-4 */
authId?: IntegerType;
}

export class StackingClient {
Expand Down Expand Up @@ -988,17 +996,26 @@ export class StackingClient {
poxAddress,
rewardCycle,
rewardIndex,
signerKey,
signerSignature,
maxAmount,
authId,
...txOptions
}: StackAggregationIncreaseOptions & BaseTxOptions): Promise<TxBroadcastResult> {
// todo: deprecate this method in favor of Indexed as soon as PoX-2 is live
const contract = await this.getStackingContract();
ensureLegacyBtcAddressForPox1({ contract, poxAddress });
ensureSignerArgsReadiness({ contract, signerKey, signerSignature, maxAmount, authId });

const callOptions = this.getStackAggregationIncreaseOptions({
contract,
poxAddress,
rewardCycle,
rewardCycleIndex: rewardIndex,
signerKey,
signerSignature,
maxAmount,
authId,
});
const tx = await makeContractCall({
...callOptions,
Expand Down Expand Up @@ -1333,19 +1350,37 @@ export class StackingClient {
poxAddress,
rewardCycle,
rewardCycleIndex,
signerKey,
signerSignature,
maxAmount,
authId,
}: {
contract: string;
poxAddress: string;
rewardCycle: number;
rewardCycleIndex: number;
signerKey?: string;
signerSignature?: string;
maxAmount?: IntegerType;
authId?: IntegerType;
}) {
const address = poxAddressToTuple(poxAddress);
const [contractAddress, contractName] = this.parseContractId(contract);

const functionArgs = [address, uintCV(rewardCycle), uintCV(rewardCycleIndex)] as ClarityValue[];

if (signerKey && maxAmount && typeof authId !== 'undefined') {
functionArgs.push(signerSignature ? someCV(bufferCV(hexToBytes(signerSignature))) : noneCV());
functionArgs.push(bufferCV(hexToBytes(signerKey)));
functionArgs.push(uintCV(maxAmount));
functionArgs.push(uintCV(authId));
}

const callOptions: ContractCallOptions = {
contractAddress,
contractName,
functionName: 'stack-aggregation-increase',
functionArgs: [address, uintCV(rewardCycle), uintCV(rewardCycleIndex)],
functionArgs,
validateWithAbi: true,
network: this.network,
anchorMode: AnchorMode.Any,
Expand Down
Loading