@stacks/stacking
Version:
Library for Stacking.
746 lines • 31.8 kB
JavaScript
import { hexToBytes, intToBigInt } from '@stacks/common';
import { ChainId, clientFromNetwork, networkFrom, } from '@stacks/network';
import { ClarityType, broadcastTransaction, bufferCV, cvToString, fetchCallReadOnlyFunction, getFee, makeContractCall, noneCV, principalCV, someCV, stringAsciiCV, uintCV, validateStacksAddress, } from '@stacks/transactions';
import { PoxOperationPeriod, StackingErrors } from './constants';
import { ensureLegacyBtcAddressForPox1, ensurePox2Activated, ensureSignerArgsReadiness, poxAddressToTuple, signPox4SignatureHash, unwrap, unwrapMap, } from './utils';
export * from './utils';
export class StackingClient {
constructor(opts) {
this.address = opts.address;
this.network = networkFrom(opts.network ?? 'mainnet');
this.client = Object.assign({}, clientFromNetwork(this.network), opts.client);
}
get baseUrl() {
return this.client.baseUrl;
}
get fetch() {
return this.client.fetch;
}
getCoreInfo() {
return this.client.fetch(`${this.client.baseUrl}/v2/info`).then(res => res.json());
}
getPoxInfo() {
return this.client.fetch(`${this.client.baseUrl}/v2/pox`).then(res => res.json());
}
async getTargetBlockTime() {
const res = await this.client
.fetch(`${this.client.baseUrl}/extended/v1/info/network_block_times`)
.then((res) => res.json());
if (this.network.chainId === ChainId.Mainnet)
return res.mainnet.target_block_time;
return res.testnet.target_block_time;
}
async getAccountStatus() {
return this.client
.fetch(`${this.client.baseUrl}/v2/accounts/${this.address}?proof=0`)
.then(res => res.json())
.then(json => {
json.balance = BigInt(json.balance);
json.locked = BigInt(json.locked);
return json;
});
}
async getAccountBalance() {
return this.getAccountStatus().then(a => a.balance);
}
async getAccountExtendedBalances() {
return this.client
.fetch(`${this.client.baseUrl}/extended/v1/address/${this.address}/balances`)
.then(res => res.json())
.then(json => {
json.stx.balance = BigInt(json.stx.balance);
json.stx.total_sent = BigInt(json.stx.total_sent);
json.stx.total_received = BigInt(json.stx.total_received);
json.stx.locked = BigInt(json.stx.locked);
return json;
});
}
async getAccountBalanceLocked() {
return this.getAccountStatus().then(a => a.locked);
}
async getCycleDuration() {
const poxInfoPromise = this.getPoxInfo();
const targetBlockTimePromise = await this.getTargetBlockTime();
return Promise.all([poxInfoPromise, targetBlockTimePromise]).then(([poxInfo, targetBlockTime]) => {
return poxInfo.reward_cycle_length * targetBlockTime;
});
}
async getRewardsTotalForBtcAddress() {
return this.client
.fetch(`${this.client.baseUrl}/extended/v1/burnchain/rewards/${this.address}/total`)
.then(res => res.json())
.then(json => {
json.reward_amount = BigInt(json.reward_amount);
return json;
});
}
async getRewardsForBtcAddress(options) {
let url = `${this.client.baseUrl}/extended/v1/burnchain/rewards/${this.address}`;
if (options)
url += `?limit=${options.limit}&offset=${options.offset}`;
return this.client.fetch(url).then(res => res.json());
}
async getRewardHoldersForBtcAddress(options) {
let url = `${this.client.baseUrl}/extended/v1/burnchain/reward_slot_holders/${this.address}`;
if (options)
url += `?limit=${options.limit}&offset=${options.offset}`;
return this.client.fetch(url).then(res => res.json());
}
async getRewardSet(options) {
const [contractAddress, contractName] = this.parseContractId(options?.contractId);
const result = await fetchCallReadOnlyFunction({
client: this.client,
senderAddress: this.address,
contractAddress,
contractName,
functionArgs: [uintCV(options.rewardCyleId), uintCV(options.rewardSetIndex)],
functionName: 'get-reward-set-pox-address',
});
return unwrapMap(result, tuple => ({
pox_address: {
version: hexToBytes(tuple.value['pox-addr'].value['version'].value),
hashbytes: hexToBytes(tuple.value['pox-addr'].value['hashbytes'].value),
},
total_ustx: BigInt(tuple.value['total-ustx'].value),
}));
}
async getSecondsUntilNextCycle() {
const poxInfoPromise = this.getPoxInfo();
const targetBlockTimePromise = this.getTargetBlockTime();
const coreInfoPromise = this.getCoreInfo();
return Promise.all([poxInfoPromise, targetBlockTimePromise, coreInfoPromise]).then(([poxInfo, targetBlockTime, coreInfo]) => {
const blocksToNextCycle = poxInfo.reward_cycle_length -
((coreInfo.burn_block_height - poxInfo.first_burnchain_block_height) %
poxInfo.reward_cycle_length);
return blocksToNextCycle * targetBlockTime;
});
}
async getSecondsUntilStackingDeadline() {
const poxInfoPromise = this.getPoxInfo();
const targetBlockTimePromise = this.getTargetBlockTime();
return Promise.all([poxInfoPromise, targetBlockTimePromise]).then(([poxInfo, targetBlockTime]) => poxInfo.next_cycle.blocks_until_prepare_phase * targetBlockTime);
}
async getPoxOperationInfo(poxInfo) {
poxInfo = poxInfo ?? (await this.getPoxInfo());
const poxContractVersions = [...poxInfo.contract_versions].sort((a, b) => a.activation_burnchain_block_height - b.activation_burnchain_block_height);
const [pox1, pox2, pox3, pox4] = poxContractVersions;
const activatedPoxs = poxContractVersions.filter((c) => poxInfo?.current_burnchain_block_height >= c.activation_burnchain_block_height);
const current = activatedPoxs[activatedPoxs.length - 1];
return { period: PoxOperationPeriod.Period3, pox1, pox2, pox3, pox4, current };
}
async hasMinimumStx() {
const balance = await this.getAccountBalance();
const min = BigInt((await this.getPoxInfo()).min_amount_ustx);
return balance >= min;
}
async canStack({ poxAddress, cycles }) {
const balancePromise = this.getAccountBalance();
const poxInfoPromise = this.getPoxInfo();
return Promise.all([balancePromise, poxInfoPromise])
.then(([balance, poxInfo]) => {
const address = poxAddressToTuple(poxAddress);
const [contractAddress, contractName] = this.parseContractId(poxInfo.contract_id);
return fetchCallReadOnlyFunction({
client: this.client,
contractName,
contractAddress,
functionName: 'can-stack-stx',
senderAddress: this.address,
functionArgs: [
address,
uintCV(balance.toString()),
uintCV(poxInfo.reward_cycle_id),
uintCV(cycles.toString()),
],
});
})
.then((responseCV) => {
if (responseCV.type === ClarityType.ResponseOk) {
return {
eligible: true,
};
}
else {
const errorCV = responseCV;
return {
eligible: false,
reason: StackingErrors[+cvToString(errorCV.value)],
};
}
});
}
async stack({ amountMicroStx, poxAddress, cycles, burnBlockHeight, signerKey, signerSignature, maxAmount, authId, ...txOptions }) {
const poxInfo = await this.getPoxInfo();
const poxOperationInfo = await this.getPoxOperationInfo(poxInfo);
const contract = await this.getStackingContract(poxOperationInfo);
ensureLegacyBtcAddressForPox1({ contract, poxAddress });
ensureSignerArgsReadiness({ contract, signerKey, signerSignature, maxAmount, authId });
const callOptions = this.getStackOptions({
contract,
amountMicroStx,
cycles,
poxAddress,
burnBlockHeight,
signerKey,
signerSignature,
maxAmount,
authId,
});
const tx = await makeContractCall({
...callOptions,
...renamePrivateKey(txOptions),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
async stackExtend({ extendCycles, poxAddress, signerKey, signerSignature, maxAmount, authId, ...txOptions }) {
const poxInfo = await this.getPoxInfo();
const poxOperationInfo = await this.getPoxOperationInfo(poxInfo);
ensurePox2Activated(poxOperationInfo);
ensureSignerArgsReadiness({
contract: poxInfo.contract_id,
signerKey,
signerSignature,
maxAmount,
authId,
});
const callOptions = this.getStackExtendOptions({
contract: poxInfo.contract_id,
extendCycles,
poxAddress,
signerKey,
signerSignature,
maxAmount,
authId,
});
const tx = await makeContractCall({
...callOptions,
...renamePrivateKey(txOptions),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
async stackIncrease({ increaseBy, signerKey, signerSignature, maxAmount, authId, ...txOptions }) {
const poxInfo = await this.getPoxInfo();
const poxOperationInfo = await this.getPoxOperationInfo(poxInfo);
ensurePox2Activated(poxOperationInfo);
ensureSignerArgsReadiness({
contract: poxInfo.contract_id,
signerKey,
signerSignature,
maxAmount,
authId,
});
const callOptions = this.getStackIncreaseOptions({
contract: poxInfo.contract_id,
increaseBy,
signerKey,
signerSignature,
maxAmount,
authId,
});
const tx = await makeContractCall({
...callOptions,
...renamePrivateKey(txOptions),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
async delegateStx({ amountMicroStx, delegateTo, untilBurnBlockHeight, poxAddress, ...txOptions }) {
const poxInfo = await this.getPoxInfo();
const poxOperationInfo = await this.getPoxOperationInfo(poxInfo);
const contract = await this.getStackingContract(poxOperationInfo);
ensureLegacyBtcAddressForPox1({ contract, poxAddress });
const callOptions = this.getDelegateOptions({
contract,
amountMicroStx,
delegateTo,
untilBurnBlockHeight,
poxAddress,
});
const tx = await makeContractCall({
...callOptions,
...renamePrivateKey(txOptions),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
async delegateStackStx({ stacker, amountMicroStx, poxAddress, burnBlockHeight, cycles, ...txOptions }) {
const poxInfo = await this.getPoxInfo();
const poxOperationInfo = await this.getPoxOperationInfo(poxInfo);
const contract = await this.getStackingContract(poxOperationInfo);
ensureLegacyBtcAddressForPox1({ contract, poxAddress });
const callOptions = this.getDelegateStackOptions({
contract,
stacker,
amountMicroStx,
poxAddress,
burnBlockHeight,
cycles,
});
const tx = await makeContractCall({
...callOptions,
...renamePrivateKey(txOptions),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
async delegateStackExtend({ stacker, poxAddress, extendCount, ...txOptions }) {
const poxInfo = await this.getPoxInfo();
const contract = poxInfo.contract_id;
const callOptions = this.getDelegateStackExtendOptions({
contract,
stacker,
poxAddress,
extendCount,
});
const tx = await makeContractCall({
...callOptions,
...renamePrivateKey(txOptions),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
async delegateStackIncrease({ stacker, poxAddress, increaseBy, ...txOptions }) {
const poxInfo = await this.getPoxInfo();
const poxOperationInfo = await this.getPoxOperationInfo(poxInfo);
ensurePox2Activated(poxOperationInfo);
const callOptions = this.getDelegateStackIncreaseOptions({
contract: poxInfo.contract_id,
stacker,
poxAddress,
increaseBy,
});
const tx = await makeContractCall({
...callOptions,
...renamePrivateKey(txOptions),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
async stackAggregationCommit({ poxAddress, rewardCycle, signerKey, signerSignature, maxAmount, authId, ...txOptions }) {
const contract = await this.getStackingContract();
ensureLegacyBtcAddressForPox1({ contract, poxAddress });
ensureSignerArgsReadiness({ contract, signerKey, signerSignature, maxAmount, authId });
const callOptions = this.getStackAggregationCommitOptions({
contract,
poxAddress,
rewardCycle,
signerKey,
signerSignature,
maxAmount,
authId,
});
const tx = await makeContractCall({
...callOptions,
...renamePrivateKey(txOptions),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
async stackAggregationCommitIndexed({ poxAddress, rewardCycle, signerKey, signerSignature, maxAmount, authId, ...txOptions }) {
const contract = await this.getStackingContract();
ensureLegacyBtcAddressForPox1({ contract, poxAddress });
ensureSignerArgsReadiness({ contract, signerKey, signerSignature, maxAmount, authId });
const callOptions = this.getStackAggregationCommitOptionsIndexed({
contract,
poxAddress,
rewardCycle,
signerKey,
signerSignature,
maxAmount,
authId,
});
const tx = await makeContractCall({
...callOptions,
...renamePrivateKey(txOptions),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
async stackAggregationIncrease({ poxAddress, rewardCycle, rewardIndex, signerKey, signerSignature, maxAmount, authId, ...txOptions }) {
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,
...renamePrivateKey(txOptions),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
async revokeDelegateStx(arg) {
if (typeof arg === 'string')
arg = { privateKey: arg };
const poxInfo = await this.getPoxInfo();
const contract = poxInfo.contract_id;
const callOptions = this.getRevokeDelegateStxOptions(contract);
const tx = await makeContractCall({
...callOptions,
...renamePrivateKey(arg),
});
return broadcastTransaction({ transaction: tx, client: this.client });
}
getStackOptions({ amountMicroStx, poxAddress, cycles, contract, burnBlockHeight, signerKey, signerSignature, maxAmount, authId, }) {
const address = poxAddressToTuple(poxAddress);
const [contractAddress, contractName] = this.parseContractId(contract);
const functionArgs = [
uintCV(amountMicroStx),
address,
uintCV(burnBlockHeight),
uintCV(cycles),
];
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 = {
client: this.client,
contractAddress,
contractName,
functionName: 'stack-stx',
functionArgs,
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
getStackExtendOptions({ extendCycles, poxAddress, contract, signerKey, signerSignature, maxAmount, authId, }) {
const address = poxAddressToTuple(poxAddress);
const [contractAddress, contractName] = this.parseContractId(contract);
const functionArgs = [uintCV(extendCycles), address];
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 = {
client: this.client,
contractAddress,
contractName,
functionName: 'stack-extend',
functionArgs,
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
getStackIncreaseOptions({ increaseBy, contract, signerKey, signerSignature, maxAmount, authId, }) {
const [contractAddress, contractName] = this.parseContractId(contract);
const functionArgs = [uintCV(increaseBy)];
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 = {
client: this.client,
contractAddress,
contractName,
functionName: 'stack-increase',
functionArgs,
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
getDelegateOptions({ contract, amountMicroStx, delegateTo, untilBurnBlockHeight, poxAddress, }) {
const address = poxAddress ? someCV(poxAddressToTuple(poxAddress)) : noneCV();
const [contractAddress, contractName] = this.parseContractId(contract);
const callOptions = {
client: this.client,
contractAddress,
contractName,
functionName: 'delegate-stx',
functionArgs: [
uintCV(amountMicroStx),
principalCV(delegateTo),
untilBurnBlockHeight ? someCV(uintCV(untilBurnBlockHeight)) : noneCV(),
address,
],
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
getDelegateStackOptions({ contract, stacker, amountMicroStx, poxAddress, burnBlockHeight, cycles, }) {
const address = poxAddressToTuple(poxAddress);
const [contractAddress, contractName] = this.parseContractId(contract);
const callOptions = {
client: this.client,
contractAddress,
contractName,
functionName: 'delegate-stack-stx',
functionArgs: [
principalCV(stacker),
uintCV(amountMicroStx),
address,
uintCV(burnBlockHeight),
uintCV(cycles),
],
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
getDelegateStackExtendOptions({ contract, stacker, poxAddress, extendCount, }) {
const address = poxAddressToTuple(poxAddress);
const [contractAddress, contractName] = this.parseContractId(contract);
const callOptions = {
client: this.client,
contractAddress,
contractName,
functionName: 'delegate-stack-extend',
functionArgs: [principalCV(stacker), address, uintCV(extendCount)],
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
getDelegateStackIncreaseOptions({ contract, stacker, poxAddress, increaseBy, }) {
const address = poxAddressToTuple(poxAddress);
const [contractAddress, contractName] = this.parseContractId(contract);
const callOptions = {
client: this.client,
contractAddress,
contractName,
functionName: 'delegate-stack-increase',
functionArgs: [principalCV(stacker), address, uintCV(increaseBy)],
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
getStackAggregationCommitOptions({ contract, poxAddress, rewardCycle, signerKey, signerSignature, maxAmount, authId, }) {
const address = poxAddressToTuple(poxAddress);
const [contractAddress, contractName] = this.parseContractId(contract);
const functionArgs = [address, uintCV(rewardCycle)];
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 = {
client: this.client,
contractAddress,
contractName,
functionName: 'stack-aggregation-commit',
functionArgs,
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
getStackAggregationIncreaseOptions({ contract, poxAddress, rewardCycle, rewardCycleIndex, signerKey, signerSignature, maxAmount, authId, }) {
const address = poxAddressToTuple(poxAddress);
const [contractAddress, contractName] = this.parseContractId(contract);
const functionArgs = [address, uintCV(rewardCycle), uintCV(rewardCycleIndex)];
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 = {
client: this.client,
contractAddress,
contractName,
functionName: 'stack-aggregation-increase',
functionArgs,
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
getStackAggregationCommitOptionsIndexed({ contract, poxAddress, rewardCycle, signerKey, signerSignature, maxAmount, authId, }) {
const address = poxAddressToTuple(poxAddress);
const [contractAddress, contractName] = this.parseContractId(contract);
const functionArgs = [address, uintCV(rewardCycle)];
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 = {
client: this.client,
contractAddress,
contractName,
functionName: 'stack-aggregation-commit-indexed',
functionArgs,
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
getRevokeDelegateStxOptions(contract) {
const [contractAddress, contractName] = this.parseContractId(contract);
const callOptions = {
client: this.client,
contractAddress,
contractName,
functionName: 'revoke-delegate-stx',
functionArgs: [],
validateWithAbi: true,
network: this.network,
};
return callOptions;
}
async getStatus() {
const poxInfo = await this.getPoxInfo();
const [contractAddress, contractName] = this.parseContractId(poxInfo.contract_id);
const account = await this.getAccountStatus();
const functionName = 'get-stacker-info';
return fetchCallReadOnlyFunction({
contractAddress,
contractName,
functionName,
senderAddress: this.address,
functionArgs: [principalCV(this.address)],
client: this.client,
}).then((responseCV) => {
if (responseCV.type === ClarityType.OptionalSome) {
const someCV = responseCV;
const tupleCV = someCV.value;
const poxAddress = tupleCV.value['pox-addr'];
const firstRewardCycle = tupleCV.value['first-reward-cycle'];
const lockPeriod = tupleCV.value['lock-period'];
const version = poxAddress.value['version'];
const hashbytes = poxAddress.value['hashbytes'];
return {
stacked: true,
details: {
first_reward_cycle: Number(firstRewardCycle.value),
lock_period: Number(lockPeriod.value),
unlock_height: account.unlock_height,
pox_address: {
version: hexToBytes(version.value),
hashbytes: hexToBytes(hashbytes.value),
},
},
};
}
else if (responseCV.type === ClarityType.OptionalNone) {
return {
stacked: false,
};
}
else {
throw new Error(`Error fetching stacker info`);
}
});
}
async getDelegationStatus() {
const poxInfo = await this.getPoxInfo();
const [contractAddress, contractName] = this.parseContractId(poxInfo.contract_id);
const functionName = 'get-delegation-info';
return fetchCallReadOnlyFunction({
contractAddress,
contractName,
functionName,
functionArgs: [principalCV(this.address)],
senderAddress: this.address,
client: this.client,
}).then((responseCV) => {
if (responseCV.type === ClarityType.OptionalSome) {
const tupleCV = responseCV.value;
const amountMicroStx = tupleCV.value['amount-ustx'];
const delegatedTo = tupleCV.value['delegated-to'];
const poxAddress = unwrapMap(tupleCV.value['pox-addr'], tuple => ({
version: hexToBytes(tuple.value['version'].value)[0],
hashbytes: hexToBytes(tuple.value['hashbytes'].value),
}));
const untilBurnBlockHeight = unwrap(tupleCV.value['until-burn-ht']);
return {
delegated: true,
details: {
amount_micro_stx: BigInt(amountMicroStx.value),
delegated_to: delegatedTo.value,
pox_address: poxAddress,
until_burn_ht: untilBurnBlockHeight ? Number(untilBurnBlockHeight.value) : undefined,
},
};
}
else if (responseCV.type === ClarityType.OptionalNone) {
return {
delegated: false,
};
}
else {
throw new Error(`Error fetching delegation info`);
}
});
}
async verifySignerKeySignature({ topic, poxAddress, rewardCycle, period, signerSignature, signerKey, amount, maxAmount, authId, }) {
const poxInfo = await this.getPoxInfo();
const [contractAddress, contractName] = this.parseContractId(poxInfo.contract_id);
const functionName = 'verify-signer-key-sig';
const functionArgs = [
poxAddressToTuple(poxAddress),
uintCV(rewardCycle),
stringAsciiCV(topic),
uintCV(period),
signerSignature ? someCV(bufferCV(hexToBytes(signerSignature))) : noneCV(),
bufferCV(hexToBytes(signerKey)),
uintCV(amount),
uintCV(maxAmount),
uintCV(authId),
];
return fetchCallReadOnlyFunction({
contractAddress,
contractName,
functionName,
functionArgs,
senderAddress: this.address,
client: this.client,
}).then(responseCV => responseCV.type === ClarityType.ResponseOk);
}
async getStackingContract(poxOperationInfo) {
poxOperationInfo = poxOperationInfo ?? (await this.getPoxOperationInfo());
switch (poxOperationInfo.period) {
case PoxOperationPeriod.Period1:
return poxOperationInfo.pox1.contract_id;
case PoxOperationPeriod.Period2a:
case PoxOperationPeriod.Period2b:
return poxOperationInfo.pox2.contract_id;
case PoxOperationPeriod.Period3:
default:
return poxOperationInfo.current.contract_id;
}
}
modifyLockTxFee({ tx, amountMicroStx, }) {
const fee = getFee(tx.auth);
tx.payload.functionArgs[0] = uintCV(intToBigInt(amountMicroStx) - fee);
return tx;
}
parseContractId(contract) {
const parts = contract.split('.');
if (parts.length === 2 && validateStacksAddress(parts[0]) && parts[1].startsWith('pox')) {
return parts;
}
throw new Error('Stacking contract ID is malformed');
}
signPoxSignature({ topic, poxAddress, rewardCycle, period, signerPrivateKey, authId, maxAmount, }) {
return signPox4SignatureHash({
topic,
poxAddress,
rewardCycle,
period,
network: this.network,
privateKey: signerPrivateKey,
maxAmount,
authId,
});
}
}
function renamePrivateKey(txOptions) {
txOptions.senderKey = txOptions.privateKey;
delete txOptions.privateKey;
return txOptions;
}
//# sourceMappingURL=index.js.map