Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@stacks/stacking

Package Overview
Dependencies
Maintainers
8
Versions
662
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stacks/stacking - npm Package Compare versions

Comparing version 1.3.0 to 1.3.1

8

CHANGELOG.md

@@ -6,2 +6,10 @@ # Change Log

## [1.3.1](https://github.com/blockstack/blockstack.js/compare/v1.3.0...v1.3.1) (2021-03-10)
**Note:** Version bump only for package @stacks/stacking
# [1.3.0](https://github.com/blockstack/blockstack.js/compare/v1.2.4...v1.3.0) (2021-03-08)

@@ -8,0 +16,0 @@

4

dist/index.esm.js

@@ -638,3 +638,3 @@ import { asyncToGenerator as _asyncToGenerator, extends as _extends } from './_virtual/_rollupPluginBabelHelpers.js';

var hashModeBuffer = bufferCV(new BN(hashMode, 10).toBuffer());
var hashModeBuffer = bufferCV(new BN(hashMode, 10).toArrayLike(Buffer));
var hashbytes = bufferCV(data);

@@ -676,3 +676,3 @@ address = someCV(tupleCV({

var hashModeBuffer = bufferCV(new BN(hashMode, 10).toBuffer());
var hashModeBuffer = bufferCV(new BN(hashMode, 10).toArrayLike(Buffer));
var hashbytes = bufferCV(data);

@@ -679,0 +679,0 @@ var address = tupleCV({

@@ -1503,3 +1503,3 @@ 'use strict';

var hashModeBuffer = transactions.bufferCV(new BN__default['default'](hashMode, 10).toBuffer());
var hashModeBuffer = transactions.bufferCV(new BN__default['default'](hashMode, 10).toArrayLike(Buffer));
var hashbytes = transactions.bufferCV(data);

@@ -1541,3 +1541,3 @@ address = transactions.someCV(transactions.tupleCV({

var hashModeBuffer = transactions.bufferCV(new BN__default['default'](hashMode, 10).toBuffer());
var hashModeBuffer = transactions.bufferCV(new BN__default['default'](hashMode, 10).toArrayLike(Buffer));
var hashbytes = transactions.bufferCV(data);

@@ -1544,0 +1544,0 @@ var address = transactions.tupleCV({

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@stacks/transactions"),e=require("bn.js"),r=require("@stacks/common"),n=require("bitcoinjs-lib");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var a=o(e);function i(t,e,r,n,o,a,i){try{var c=t[a](i),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,o)}function c(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function c(t){i(a,n,o,c,s,"next",t)}function s(t){i(a,n,o,c,s,"throw",t)}c(void 0)}))}}function s(){return(s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function u(t,e){return t(e={exports:{}},e.exports),e.exports}var f,h=u((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new x(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var c=m(i,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=u(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function u(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function h(){}function l(){}function d(){}var p={};p[o]=function(){return this};var v=Object.getPrototypeOf,_=v&&v(v(R([])));_&&_!==e&&r.call(_,o)&&(p=_);var g=d.prototype=h.prototype=Object.create(p);function y(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function E(t,e){var n;this._invoke=function(o,a){function i(){return new e((function(n,i){!function n(o,a,i,c){var s=u(t[o],t,a);if("throw"!==s.type){var f=s.arg,h=f.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(h).then((function(t){f.value=t,i(f)}),(function(t){return n("throw",t,i,c)}))}c(s.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function m(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,m(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=u(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function A(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function w(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function R(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,a=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return a.next=a}}return{next:C}}function C(){return{value:void 0,done:!0}}return l.prototype=g.constructor=d,d.constructor=l,l.displayName=c(d,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,c(t,i,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},y(E.prototype),E.prototype[a]=function(){return this},t.AsyncIterator=E,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new E(s(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},y(g),c(g,i,"Generator"),g[o]=function(){return this},g.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=R,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),s=r.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,f):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),w(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;w(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:R(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function l(e){var r=function(e){if(e.startsWith("bc1")||e.startsWith("tb1"))return 32===n.address.fromBech32(e).data.length?t.AddressHashMode.SerializeP2WSH:t.AddressHashMode.SerializeP2WPKH;switch(n.address.fromBase58Check(e).version){case 0:case 111:return t.AddressHashMode.SerializeP2PKH;case 5:case 196:return t.AddressHashMode.SerializeP2SH;default:throw new Error("Invalid pox address version")}}(e);return e.startsWith("bc1")||e.startsWith("tb1")?{hashMode:r,data:n.address.fromBech32(e).data}:{hashMode:r,data:n.address.fromBase58Check(e).hash}}!function(t){t[t.ERR_STACKING_UNREACHABLE=255]="ERR_STACKING_UNREACHABLE",t[t.ERR_STACKING_INSUFFICIENT_FUNDS=1]="ERR_STACKING_INSUFFICIENT_FUNDS",t[t.ERR_STACKING_INVALID_LOCK_PERIOD=2]="ERR_STACKING_INVALID_LOCK_PERIOD",t[t.ERR_STACKING_ALREADY_STACKED=3]="ERR_STACKING_ALREADY_STACKED",t[t.ERR_STACKING_NO_SUCH_PRINCIPAL=4]="ERR_STACKING_NO_SUCH_PRINCIPAL",t[t.ERR_STACKING_EXPIRED=5]="ERR_STACKING_EXPIRED",t[t.ERR_STACKING_STX_LOCKED=6]="ERR_STACKING_STX_LOCKED",t[t.ERR_STACKING_PERMISSION_DENIED=9]="ERR_STACKING_PERMISSION_DENIED",t[t.ERR_STACKING_THRESHOLD_NOT_MET=11]="ERR_STACKING_THRESHOLD_NOT_MET",t[t.ERR_STACKING_POX_ADDRESS_IN_USE=12]="ERR_STACKING_POX_ADDRESS_IN_USE",t[t.ERR_STACKING_INVALID_POX_ADDRESS=13]="ERR_STACKING_INVALID_POX_ADDRESS",t[t.ERR_STACKING_ALREADY_REJECTED=17]="ERR_STACKING_ALREADY_REJECTED",t[t.ERR_STACKING_INVALID_AMOUNT=18]="ERR_STACKING_INVALID_AMOUNT",t[t.ERR_NOT_ALLOWED=19]="ERR_NOT_ALLOWED",t[t.ERR_STACKING_ALREADY_DELEGATED=20]="ERR_STACKING_ALREADY_DELEGATED",t[t.ERR_DELEGATION_EXPIRES_DURING_LOCK=21]="ERR_DELEGATION_EXPIRES_DURING_LOCK",t[t.ERR_DELEGATION_TOO_MUCH_LOCKED=22]="ERR_DELEGATION_TOO_MUCH_LOCKED",t[t.ERR_DELEGATION_POX_ADDR_REQUIRED=23]="ERR_DELEGATION_POX_ADDR_REQUIRED",t[t.ERR_INVALID_START_BURN_HEIGHT=24]="ERR_INVALID_START_BURN_HEIGHT"}(f||(f={})),exports.StackingClient=function(){function e(t,e){this.address=t,this.network=e}var n=e.prototype;return n.getCoreInfo=function(){var t=c(h.mark((function t(){var e;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getInfoUrl(),t.abrupt("return",r.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getPoxInfo=function(){var t=c(h.mark((function t(){var e;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getPoxInfoUrl(),t.abrupt("return",r.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getTargetBlockTime=function(){var t=c(h.mark((function t(){var e,n;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getBlockTimeInfoUrl(),t.next=3,r.fetchPrivate(e).then((function(t){return t.json()}));case 3:if(n=t.sent,!this.network.isMainnet()){t.next=8;break}return t.abrupt("return",n.mainnet.target_block_time);case 8:return t.abrupt("return",n.testnet.target_block_time);case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getAccountStatus=function(){var t=c(h.mark((function t(){var e;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getAccountApiUrl(this.address),t.abrupt("return",r.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getAccountBalance=function(){var t=c(h.mark((function t(){return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getAccountStatus().then((function(t){var e=t.balance;return t.balance.startsWith("0x")&&(e=t.balance.substr(2)),new a.default(e,"hex")})));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getCycleDuration=function(){var t=c(h.mark((function t(){var e;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getPoxInfo(),t.next=3,this.getTargetBlockTime();case 3:return t.abrupt("return",Promise.all([e,t.sent]).then((function(t){return t[0].reward_cycle_length*t[1]})));case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getSecondsUntilNextCycle=function(){var t=c(h.mark((function t(){var e,r,n;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getPoxInfo(),t.next=3,this.getTargetBlockTime();case 3:return r=t.sent,n=this.getCoreInfo(),t.abrupt("return",Promise.all([e,r,n]).then((function(t){var e=t[0];return(e.reward_cycle_length-(t[2].burn_block_height-e.first_burnchain_block_height)%e.reward_cycle_length)*t[1]})));case 6:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.isStackingEnabledNextCycle=function(){var t=c(h.mark((function t(){return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPoxInfo();case 2:return t.t0=t.sent.rejection_votes_left_required,t.abrupt("return",t.t0>0);case 4:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.hasMinimumStx=function(){var t=c(h.mark((function t(){var e,r;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getAccountBalance();case 2:return e=t.sent,t.t0=a.default,t.next=6,this.getPoxInfo();case 6:return t.t1=t.sent.min_amount_ustx.toString(),r=new t.t0(t.t1),t.abrupt("return",e.gte(r));case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.canStack=function(){var e=c(h.mark((function e(r){var n,o,i,c,s=this;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.poxAddress,o=r.cycles,i=this.getAccountBalance(),c=this.getPoxInfo(),e.abrupt("return",Promise.all([i,c]).then((function(e){var r=e[0],i=e[1],c=l(n),u=c.data,f=t.bufferCV(new a.default(c.hashMode,10).toArrayLike(Buffer)),h=t.bufferCV(u),d=t.tupleCV({hashbytes:h,version:f}),p=s.parseContractId(i.contract_id);return t.callReadOnlyFunction({network:s.network,contractName:p[1],contractAddress:p[0],functionName:"can-stack-stx",senderAddress:s.address,functionArgs:[d,t.uintCV(r.toString()),t.uintCV(i.reward_cycle_id),t.uintCV(o.toString())]})})).then((function(e){return e.type===t.ClarityType.ResponseOk?{eligible:!0}:{eligible:!1,reason:f[+t.cvToString(e.value)]}})));case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.stack=function(){var e=c(h.mark((function e(r){var n,o,a,i,c,u;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.amountMicroStx,o=r.poxAddress,a=r.cycles,i=r.privateKey,c=r.burnBlockHeight,e.next=3,this.getPoxInfo();case 3:return u=this.getStackOptions({amountMicroStx:n,cycles:a,poxAddress:o,contract:e.sent.contract_id,burnBlockHeight:c}),e.next=8,t.makeContractCall(s({},u,{senderKey:i}));case 8:return e.abrupt("return",t.broadcastTransaction(e.sent,u.network));case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.delegateStx=function(){var e=c(h.mark((function e(r){var n,o,a,i,c,u;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.amountMicroStx,o=r.delegateTo,a=r.untilBurnBlockHeight,i=r.poxAddress,c=r.privateKey,e.next=3,this.getPoxInfo();case 3:return u=this.getDelegateOptions({contract:e.sent.contract_id,amountMicroStx:n,delegateTo:o,untilBurnBlockHeight:a,poxAddress:i}),e.next=8,t.makeContractCall(s({},u,{senderKey:c}));case 8:return e.abrupt("return",t.broadcastTransaction(e.sent,u.network));case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.delegateStackStx=function(){var e=c(h.mark((function e(r){var n,o,a,i,c,u,f,l;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.stacker,o=r.amountMicroStx,a=r.poxAddress,i=r.burnBlockHeight,c=r.cycles,u=r.privateKey,f=r.nonce,e.next=3,this.getPoxInfo();case 3:return l=this.getDelegateStackOptions({contract:e.sent.contract_id,stacker:n,amountMicroStx:o,poxAddress:a,burnBlockHeight:i,cycles:c,nonce:f}),e.next=8,t.makeContractCall(s({},l,{senderKey:u}));case 8:return e.abrupt("return",t.broadcastTransaction(e.sent,l.network));case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.stackAggregationCommit=function(){var e=c(h.mark((function e(r){var n,o,a,i;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.poxAddress,o=r.rewardCycle,a=r.privateKey,e.next=3,this.getPoxInfo();case 3:return i=this.getStackAggregationCommitOptions({contract:e.sent.contract_id,poxAddress:n,rewardCycle:o}),e.next=8,t.makeContractCall(s({},i,{senderKey:a}));case 8:return e.abrupt("return",t.broadcastTransaction(e.sent,i.network));case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.revokeDelegateStx=function(){var e=c(h.mark((function e(r){var n;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getPoxInfo();case 2:return n=this.getRevokeDelegateStxOptions(e.sent.contract_id),e.next=7,t.makeContractCall(s({},n,{senderKey:r}));case 7:return e.abrupt("return",t.broadcastTransaction(e.sent,n.network));case 9:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.getStackOptions=function(e){var r=e.amountMicroStx,n=e.cycles,o=e.contract,i=e.burnBlockHeight,c=l(e.poxAddress),s=c.data,u=t.bufferCV(new a.default(c.hashMode,10).toArrayLike(Buffer)),f=t.bufferCV(s),h=t.tupleCV({hashbytes:f,version:u}),d=this.parseContractId(o),p=this.network;return{contractAddress:d[0],contractName:d[1],functionName:"stack-stx",functionArgs:[t.uintCV(r.toString(10)),h,t.uintCV(i),t.uintCV(n)],validateWithAbi:!0,network:p}},n.getDelegateOptions=function(e){var r=e.contract,n=e.amountMicroStx,o=e.delegateTo,i=e.untilBurnBlockHeight,c=e.poxAddress,s=void 0;if(c){var u=l(c),f=u.data,h=t.bufferCV(new a.default(u.hashMode,10).toBuffer()),d=t.bufferCV(f);s=t.someCV(t.tupleCV({hashbytes:d,version:h}))}var p=this.parseContractId(r),v=this.network;return{contractAddress:p[0],contractName:p[1],functionName:"delegate-stx",functionArgs:[t.uintCV(n.toString(10)),t.standardPrincipalCV(o),i?t.someCV(t.uintCV(i)):t.noneCV(),s||t.noneCV()],validateWithAbi:!0,network:v}},n.getDelegateStackOptions=function(e){var r=e.contract,n=e.stacker,o=e.amountMicroStx,i=e.burnBlockHeight,c=e.cycles,s=e.nonce,u=l(e.poxAddress),f=u.data,h=t.bufferCV(new a.default(u.hashMode,10).toBuffer()),d=t.bufferCV(f),p=t.tupleCV({hashbytes:d,version:h}),v=this.parseContractId(r),_=this.network,g={contractAddress:v[0],contractName:v[1],functionName:"delegate-stack-stx",functionArgs:[t.standardPrincipalCV(n),t.uintCV(o.toString(10)),p,t.uintCV(i),t.uintCV(c)],validateWithAbi:!0,network:_};return s&&(g.nonce=s),g},n.getStackAggregationCommitOptions=function(e){var r=e.contract,n=e.rewardCycle,o=l(e.poxAddress),i=o.data,c=t.bufferCV(new a.default(o.hashMode,10).toBuffer()),s=t.bufferCV(i),u=t.tupleCV({hashbytes:s,version:c}),f=this.parseContractId(r),h=this.network;return{contractAddress:f[0],contractName:f[1],functionName:"stack-aggregation-commit",functionArgs:[u,t.uintCV(n)],validateWithAbi:!0,network:h}},n.getRevokeDelegateStxOptions=function(t){var e=this.parseContractId(t);return{contractAddress:e[0],contractName:e[1],functionName:"revoke-delegate-stx",functionArgs:[],validateWithAbi:!0,network:this.network}},n.getStatus=function(){var e=c(h.mark((function e(){var r,n,o,a;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getPoxInfo();case 2:return r=this.parseContractId(e.sent.contract_id),n=r[0],o=r[1],e.next=6,this.getAccountStatus();case 6:return a=e.sent,e.abrupt("return",t.callReadOnlyFunction({contractAddress:n,contractName:o,functionName:"get-stacker-info",senderAddress:this.address,functionArgs:[t.standardPrincipalCV(this.address)],network:this.network}).then((function(e){if(e.type===t.ClarityType.OptionalSome){var r=e.value,n=r.data["pox-addr"],o=r.data["first-reward-cycle"],i=r.data["lock-period"],c=n.data.version,s=n.data.hashbytes;return{stacked:!0,details:{amount_microstx:r.data["amount-ustx"].value.toString(),first_reward_cycle:o.value.toNumber(),lock_period:i.value.toNumber(),unlock_height:a.unlock_height,pox_address:{version:c.buffer,hashbytes:s.buffer}}}}if(e.type===t.ClarityType.OptionalNone)return{stacked:!1};throw new Error("Error fetching stacker info")})));case 9:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),n.modifyLockTxFee=function(e){var r=e.tx,n=e.amountMicroStx,o=r.auth.getFee();return r.payload.functionArgs[0]=t.uintCV(new a.default(n.toString(10),10).sub(o).toBuffer()),r},n.parseContractId=function(e){var r=e.split(".");if(2!==r.length||!t.validateStacksAddress(r[0])||"pox"!==r[1])throw new Error("Stacking contract ID is malformed");return r},e}();
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@stacks/transactions"),e=require("bn.js"),r=require("@stacks/common"),n=require("bitcoinjs-lib");function o(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var a=o(e);function i(t,e,r,n,o,a,i){try{var c=t[a](i),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,o)}function c(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function c(t){i(a,n,o,c,s,"next",t)}function s(t){i(a,n,o,c,s,"throw",t)}c(void 0)}))}}function s(){return(s=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function u(t,e){return t(e={exports:{}},e.exports),e.exports}var f,h=u((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new x(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var c=m(i,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=u(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function u(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function h(){}function l(){}function d(){}var p={};p[o]=function(){return this};var v=Object.getPrototypeOf,_=v&&v(v(R([])));_&&_!==e&&r.call(_,o)&&(p=_);var g=d.prototype=h.prototype=Object.create(p);function y(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function E(t,e){var n;this._invoke=function(o,a){function i(){return new e((function(n,i){!function n(o,a,i,c){var s=u(t[o],t,a);if("throw"!==s.type){var f=s.arg,h=f.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(h).then((function(t){f.value=t,i(f)}),(function(t){return n("throw",t,i,c)}))}c(s.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function m(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,m(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=u(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function A(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function w(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function x(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function R(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,a=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return a.next=a}}return{next:C}}function C(){return{value:void 0,done:!0}}return l.prototype=g.constructor=d,d.constructor=l,l.displayName=c(d,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,c(t,i,"GeneratorFunction")),t.prototype=Object.create(g),t},t.awrap=function(t){return{__await:t}},y(E.prototype),E.prototype[a]=function(){return this},t.AsyncIterator=E,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new E(s(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},y(g),c(g,i,"Generator"),g[o]=function(){return this},g.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=R,x.prototype={constructor:x,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(w),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),s=r.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,f):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),w(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;w(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:R(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function l(e){var r=function(e){if(e.startsWith("bc1")||e.startsWith("tb1"))return 32===n.address.fromBech32(e).data.length?t.AddressHashMode.SerializeP2WSH:t.AddressHashMode.SerializeP2WPKH;switch(n.address.fromBase58Check(e).version){case 0:case 111:return t.AddressHashMode.SerializeP2PKH;case 5:case 196:return t.AddressHashMode.SerializeP2SH;default:throw new Error("Invalid pox address version")}}(e);return e.startsWith("bc1")||e.startsWith("tb1")?{hashMode:r,data:n.address.fromBech32(e).data}:{hashMode:r,data:n.address.fromBase58Check(e).hash}}!function(t){t[t.ERR_STACKING_UNREACHABLE=255]="ERR_STACKING_UNREACHABLE",t[t.ERR_STACKING_INSUFFICIENT_FUNDS=1]="ERR_STACKING_INSUFFICIENT_FUNDS",t[t.ERR_STACKING_INVALID_LOCK_PERIOD=2]="ERR_STACKING_INVALID_LOCK_PERIOD",t[t.ERR_STACKING_ALREADY_STACKED=3]="ERR_STACKING_ALREADY_STACKED",t[t.ERR_STACKING_NO_SUCH_PRINCIPAL=4]="ERR_STACKING_NO_SUCH_PRINCIPAL",t[t.ERR_STACKING_EXPIRED=5]="ERR_STACKING_EXPIRED",t[t.ERR_STACKING_STX_LOCKED=6]="ERR_STACKING_STX_LOCKED",t[t.ERR_STACKING_PERMISSION_DENIED=9]="ERR_STACKING_PERMISSION_DENIED",t[t.ERR_STACKING_THRESHOLD_NOT_MET=11]="ERR_STACKING_THRESHOLD_NOT_MET",t[t.ERR_STACKING_POX_ADDRESS_IN_USE=12]="ERR_STACKING_POX_ADDRESS_IN_USE",t[t.ERR_STACKING_INVALID_POX_ADDRESS=13]="ERR_STACKING_INVALID_POX_ADDRESS",t[t.ERR_STACKING_ALREADY_REJECTED=17]="ERR_STACKING_ALREADY_REJECTED",t[t.ERR_STACKING_INVALID_AMOUNT=18]="ERR_STACKING_INVALID_AMOUNT",t[t.ERR_NOT_ALLOWED=19]="ERR_NOT_ALLOWED",t[t.ERR_STACKING_ALREADY_DELEGATED=20]="ERR_STACKING_ALREADY_DELEGATED",t[t.ERR_DELEGATION_EXPIRES_DURING_LOCK=21]="ERR_DELEGATION_EXPIRES_DURING_LOCK",t[t.ERR_DELEGATION_TOO_MUCH_LOCKED=22]="ERR_DELEGATION_TOO_MUCH_LOCKED",t[t.ERR_DELEGATION_POX_ADDR_REQUIRED=23]="ERR_DELEGATION_POX_ADDR_REQUIRED",t[t.ERR_INVALID_START_BURN_HEIGHT=24]="ERR_INVALID_START_BURN_HEIGHT"}(f||(f={})),exports.StackingClient=function(){function e(t,e){this.address=t,this.network=e}var n=e.prototype;return n.getCoreInfo=function(){var t=c(h.mark((function t(){var e;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getInfoUrl(),t.abrupt("return",r.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getPoxInfo=function(){var t=c(h.mark((function t(){var e;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getPoxInfoUrl(),t.abrupt("return",r.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getTargetBlockTime=function(){var t=c(h.mark((function t(){var e,n;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getBlockTimeInfoUrl(),t.next=3,r.fetchPrivate(e).then((function(t){return t.json()}));case 3:if(n=t.sent,!this.network.isMainnet()){t.next=8;break}return t.abrupt("return",n.mainnet.target_block_time);case 8:return t.abrupt("return",n.testnet.target_block_time);case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getAccountStatus=function(){var t=c(h.mark((function t(){var e;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getAccountApiUrl(this.address),t.abrupt("return",r.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getAccountBalance=function(){var t=c(h.mark((function t(){return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getAccountStatus().then((function(t){var e=t.balance;return t.balance.startsWith("0x")&&(e=t.balance.substr(2)),new a.default(e,"hex")})));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getCycleDuration=function(){var t=c(h.mark((function t(){var e;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getPoxInfo(),t.next=3,this.getTargetBlockTime();case 3:return t.abrupt("return",Promise.all([e,t.sent]).then((function(t){return t[0].reward_cycle_length*t[1]})));case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getSecondsUntilNextCycle=function(){var t=c(h.mark((function t(){var e,r,n;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getPoxInfo(),t.next=3,this.getTargetBlockTime();case 3:return r=t.sent,n=this.getCoreInfo(),t.abrupt("return",Promise.all([e,r,n]).then((function(t){var e=t[0];return(e.reward_cycle_length-(t[2].burn_block_height-e.first_burnchain_block_height)%e.reward_cycle_length)*t[1]})));case 6:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.isStackingEnabledNextCycle=function(){var t=c(h.mark((function t(){return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPoxInfo();case 2:return t.t0=t.sent.rejection_votes_left_required,t.abrupt("return",t.t0>0);case 4:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.hasMinimumStx=function(){var t=c(h.mark((function t(){var e,r;return h.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getAccountBalance();case 2:return e=t.sent,t.t0=a.default,t.next=6,this.getPoxInfo();case 6:return t.t1=t.sent.min_amount_ustx.toString(),r=new t.t0(t.t1),t.abrupt("return",e.gte(r));case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.canStack=function(){var e=c(h.mark((function e(r){var n,o,i,c,s=this;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.poxAddress,o=r.cycles,i=this.getAccountBalance(),c=this.getPoxInfo(),e.abrupt("return",Promise.all([i,c]).then((function(e){var r=e[0],i=e[1],c=l(n),u=c.data,f=t.bufferCV(new a.default(c.hashMode,10).toArrayLike(Buffer)),h=t.bufferCV(u),d=t.tupleCV({hashbytes:h,version:f}),p=s.parseContractId(i.contract_id);return t.callReadOnlyFunction({network:s.network,contractName:p[1],contractAddress:p[0],functionName:"can-stack-stx",senderAddress:s.address,functionArgs:[d,t.uintCV(r.toString()),t.uintCV(i.reward_cycle_id),t.uintCV(o.toString())]})})).then((function(e){return e.type===t.ClarityType.ResponseOk?{eligible:!0}:{eligible:!1,reason:f[+t.cvToString(e.value)]}})));case 4:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.stack=function(){var e=c(h.mark((function e(r){var n,o,a,i,c,u;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.amountMicroStx,o=r.poxAddress,a=r.cycles,i=r.privateKey,c=r.burnBlockHeight,e.next=3,this.getPoxInfo();case 3:return u=this.getStackOptions({amountMicroStx:n,cycles:a,poxAddress:o,contract:e.sent.contract_id,burnBlockHeight:c}),e.next=8,t.makeContractCall(s({},u,{senderKey:i}));case 8:return e.abrupt("return",t.broadcastTransaction(e.sent,u.network));case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.delegateStx=function(){var e=c(h.mark((function e(r){var n,o,a,i,c,u;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.amountMicroStx,o=r.delegateTo,a=r.untilBurnBlockHeight,i=r.poxAddress,c=r.privateKey,e.next=3,this.getPoxInfo();case 3:return u=this.getDelegateOptions({contract:e.sent.contract_id,amountMicroStx:n,delegateTo:o,untilBurnBlockHeight:a,poxAddress:i}),e.next=8,t.makeContractCall(s({},u,{senderKey:c}));case 8:return e.abrupt("return",t.broadcastTransaction(e.sent,u.network));case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.delegateStackStx=function(){var e=c(h.mark((function e(r){var n,o,a,i,c,u,f,l;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.stacker,o=r.amountMicroStx,a=r.poxAddress,i=r.burnBlockHeight,c=r.cycles,u=r.privateKey,f=r.nonce,e.next=3,this.getPoxInfo();case 3:return l=this.getDelegateStackOptions({contract:e.sent.contract_id,stacker:n,amountMicroStx:o,poxAddress:a,burnBlockHeight:i,cycles:c,nonce:f}),e.next=8,t.makeContractCall(s({},l,{senderKey:u}));case 8:return e.abrupt("return",t.broadcastTransaction(e.sent,l.network));case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.stackAggregationCommit=function(){var e=c(h.mark((function e(r){var n,o,a,i;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=r.poxAddress,o=r.rewardCycle,a=r.privateKey,e.next=3,this.getPoxInfo();case 3:return i=this.getStackAggregationCommitOptions({contract:e.sent.contract_id,poxAddress:n,rewardCycle:o}),e.next=8,t.makeContractCall(s({},i,{senderKey:a}));case 8:return e.abrupt("return",t.broadcastTransaction(e.sent,i.network));case 10:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.revokeDelegateStx=function(){var e=c(h.mark((function e(r){var n;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getPoxInfo();case 2:return n=this.getRevokeDelegateStxOptions(e.sent.contract_id),e.next=7,t.makeContractCall(s({},n,{senderKey:r}));case 7:return e.abrupt("return",t.broadcastTransaction(e.sent,n.network));case 9:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.getStackOptions=function(e){var r=e.amountMicroStx,n=e.cycles,o=e.contract,i=e.burnBlockHeight,c=l(e.poxAddress),s=c.data,u=t.bufferCV(new a.default(c.hashMode,10).toArrayLike(Buffer)),f=t.bufferCV(s),h=t.tupleCV({hashbytes:f,version:u}),d=this.parseContractId(o),p=this.network;return{contractAddress:d[0],contractName:d[1],functionName:"stack-stx",functionArgs:[t.uintCV(r.toString(10)),h,t.uintCV(i),t.uintCV(n)],validateWithAbi:!0,network:p}},n.getDelegateOptions=function(e){var r=e.contract,n=e.amountMicroStx,o=e.delegateTo,i=e.untilBurnBlockHeight,c=e.poxAddress,s=void 0;if(c){var u=l(c),f=u.data,h=t.bufferCV(new a.default(u.hashMode,10).toArrayLike(Buffer)),d=t.bufferCV(f);s=t.someCV(t.tupleCV({hashbytes:d,version:h}))}var p=this.parseContractId(r),v=this.network;return{contractAddress:p[0],contractName:p[1],functionName:"delegate-stx",functionArgs:[t.uintCV(n.toString(10)),t.standardPrincipalCV(o),i?t.someCV(t.uintCV(i)):t.noneCV(),s||t.noneCV()],validateWithAbi:!0,network:v}},n.getDelegateStackOptions=function(e){var r=e.contract,n=e.stacker,o=e.amountMicroStx,i=e.burnBlockHeight,c=e.cycles,s=e.nonce,u=l(e.poxAddress),f=u.data,h=t.bufferCV(new a.default(u.hashMode,10).toArrayLike(Buffer)),d=t.bufferCV(f),p=t.tupleCV({hashbytes:d,version:h}),v=this.parseContractId(r),_=this.network,g={contractAddress:v[0],contractName:v[1],functionName:"delegate-stack-stx",functionArgs:[t.standardPrincipalCV(n),t.uintCV(o.toString(10)),p,t.uintCV(i),t.uintCV(c)],validateWithAbi:!0,network:_};return s&&(g.nonce=s),g},n.getStackAggregationCommitOptions=function(e){var r=e.contract,n=e.rewardCycle,o=l(e.poxAddress),i=o.data,c=t.bufferCV(new a.default(o.hashMode,10).toBuffer()),s=t.bufferCV(i),u=t.tupleCV({hashbytes:s,version:c}),f=this.parseContractId(r),h=this.network;return{contractAddress:f[0],contractName:f[1],functionName:"stack-aggregation-commit",functionArgs:[u,t.uintCV(n)],validateWithAbi:!0,network:h}},n.getRevokeDelegateStxOptions=function(t){var e=this.parseContractId(t);return{contractAddress:e[0],contractName:e[1],functionName:"revoke-delegate-stx",functionArgs:[],validateWithAbi:!0,network:this.network}},n.getStatus=function(){var e=c(h.mark((function e(){var r,n,o,a;return h.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getPoxInfo();case 2:return r=this.parseContractId(e.sent.contract_id),n=r[0],o=r[1],e.next=6,this.getAccountStatus();case 6:return a=e.sent,e.abrupt("return",t.callReadOnlyFunction({contractAddress:n,contractName:o,functionName:"get-stacker-info",senderAddress:this.address,functionArgs:[t.standardPrincipalCV(this.address)],network:this.network}).then((function(e){if(e.type===t.ClarityType.OptionalSome){var r=e.value,n=r.data["pox-addr"],o=r.data["first-reward-cycle"],i=r.data["lock-period"],c=n.data.version,s=n.data.hashbytes;return{stacked:!0,details:{amount_microstx:r.data["amount-ustx"].value.toString(),first_reward_cycle:o.value.toNumber(),lock_period:i.value.toNumber(),unlock_height:a.unlock_height,pox_address:{version:c.buffer,hashbytes:s.buffer}}}}if(e.type===t.ClarityType.OptionalNone)return{stacked:!1};throw new Error("Error fetching stacker info")})));case 9:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),n.modifyLockTxFee=function(e){var r=e.tx,n=e.amountMicroStx,o=r.auth.getFee();return r.payload.functionArgs[0]=t.uintCV(new a.default(n.toString(10),10).sub(o).toBuffer()),r},n.parseContractId=function(e){var r=e.split(".");if(2!==r.length||!t.validateStacksAddress(r[0])||"pox"!==r[1])throw new Error("Stacking contract ID is malformed");return r},e}();
//# sourceMappingURL=stacking.cjs.production.min.js.map

@@ -1500,3 +1500,3 @@ (function (global, factory) {

var hashModeBuffer = transactions.bufferCV(new BN__default['default'](hashMode, 10).toBuffer());
var hashModeBuffer = transactions.bufferCV(new BN__default['default'](hashMode, 10).toArrayLike(Buffer));
var hashbytes = transactions.bufferCV(data);

@@ -1538,3 +1538,3 @@ address = transactions.someCV(transactions.tupleCV({

var hashModeBuffer = transactions.bufferCV(new BN__default['default'](hashMode, 10).toBuffer());
var hashModeBuffer = transactions.bufferCV(new BN__default['default'](hashMode, 10).toArrayLike(Buffer));
var hashbytes = transactions.bufferCV(data);

@@ -1541,0 +1541,0 @@ var address = transactions.tupleCV({

@@ -1,2 +0,2 @@

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@stacks/transactions"),require("bn.js"),require("@stacks/common"),require("bitcoinjs-lib")):"function"==typeof define&&define.amd?define(["exports","@stacks/transactions","bn.js","@stacks/common","bitcoinjs-lib"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@stacks/stacking"]={},t.transactions,t.BN,t.common,t.bitcoinjsLib)}(this,(function(t,e,r,n,o){"use strict";function a(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=a(r);function c(t,e,r,n,o,a,i){try{var c=t[a](i),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,o)}function s(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function i(t){c(a,n,o,i,s,"next",t)}function s(t){c(a,n,o,i,s,"throw",t)}i(void 0)}))}}function u(){return(u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function f(t,e){return t(e={exports:{}},e.exports),e.exports}var h,l=f((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new w(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var c=E(i,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=u(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function u(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function h(){}function l(){}function d(){}var p={};p[o]=function(){return this};var v=Object.getPrototypeOf,g=v&&v(v(R([])));g&&g!==e&&r.call(g,o)&&(p=g);var _=d.prototype=h.prototype=Object.create(p);function y(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function m(t,e){var n;this._invoke=function(o,a){function i(){return new e((function(n,i){!function n(o,a,i,c){var s=u(t[o],t,a);if("throw"!==s.type){var f=s.arg,h=f.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(h).then((function(t){f.value=t,i(f)}),(function(t){return n("throw",t,i,c)}))}c(s.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function E(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=u(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function A(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function w(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function R(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,a=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return a.next=a}}return{next:C}}function C(){return{value:void 0,done:!0}}return l.prototype=_.constructor=d,d.constructor=l,l.displayName=c(d,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,c(t,i,"GeneratorFunction")),t.prototype=Object.create(_),t},t.awrap=function(t){return{__await:t}},y(m.prototype),m.prototype[a]=function(){return this},t.AsyncIterator=m,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new m(s(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},y(_),c(_,i,"Generator"),_[o]=function(){return this},_.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=R,w.prototype={constructor:w,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),s=r.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,f):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),x(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:R(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function d(t){var r=function(t){if(t.startsWith("bc1")||t.startsWith("tb1"))return 32===o.address.fromBech32(t).data.length?e.AddressHashMode.SerializeP2WSH:e.AddressHashMode.SerializeP2WPKH;switch(o.address.fromBase58Check(t).version){case 0:case 111:return e.AddressHashMode.SerializeP2PKH;case 5:case 196:return e.AddressHashMode.SerializeP2SH;default:throw new Error("Invalid pox address version")}}(t);return t.startsWith("bc1")||t.startsWith("tb1")?{hashMode:r,data:o.address.fromBech32(t).data}:{hashMode:r,data:o.address.fromBase58Check(t).hash}}!function(t){t[t.ERR_STACKING_UNREACHABLE=255]="ERR_STACKING_UNREACHABLE",t[t.ERR_STACKING_INSUFFICIENT_FUNDS=1]="ERR_STACKING_INSUFFICIENT_FUNDS",t[t.ERR_STACKING_INVALID_LOCK_PERIOD=2]="ERR_STACKING_INVALID_LOCK_PERIOD",t[t.ERR_STACKING_ALREADY_STACKED=3]="ERR_STACKING_ALREADY_STACKED",t[t.ERR_STACKING_NO_SUCH_PRINCIPAL=4]="ERR_STACKING_NO_SUCH_PRINCIPAL",t[t.ERR_STACKING_EXPIRED=5]="ERR_STACKING_EXPIRED",t[t.ERR_STACKING_STX_LOCKED=6]="ERR_STACKING_STX_LOCKED",t[t.ERR_STACKING_PERMISSION_DENIED=9]="ERR_STACKING_PERMISSION_DENIED",t[t.ERR_STACKING_THRESHOLD_NOT_MET=11]="ERR_STACKING_THRESHOLD_NOT_MET",t[t.ERR_STACKING_POX_ADDRESS_IN_USE=12]="ERR_STACKING_POX_ADDRESS_IN_USE",t[t.ERR_STACKING_INVALID_POX_ADDRESS=13]="ERR_STACKING_INVALID_POX_ADDRESS",t[t.ERR_STACKING_ALREADY_REJECTED=17]="ERR_STACKING_ALREADY_REJECTED",t[t.ERR_STACKING_INVALID_AMOUNT=18]="ERR_STACKING_INVALID_AMOUNT",t[t.ERR_NOT_ALLOWED=19]="ERR_NOT_ALLOWED",t[t.ERR_STACKING_ALREADY_DELEGATED=20]="ERR_STACKING_ALREADY_DELEGATED",t[t.ERR_DELEGATION_EXPIRES_DURING_LOCK=21]="ERR_DELEGATION_EXPIRES_DURING_LOCK",t[t.ERR_DELEGATION_TOO_MUCH_LOCKED=22]="ERR_DELEGATION_TOO_MUCH_LOCKED",t[t.ERR_DELEGATION_POX_ADDR_REQUIRED=23]="ERR_DELEGATION_POX_ADDR_REQUIRED",t[t.ERR_INVALID_START_BURN_HEIGHT=24]="ERR_INVALID_START_BURN_HEIGHT"}(h||(h={})),t.StackingClient=function(){function t(t,e){this.address=t,this.network=e}var r=t.prototype;return r.getCoreInfo=function(){var t=s(l.mark((function t(){var e;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getInfoUrl(),t.abrupt("return",n.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getPoxInfo=function(){var t=s(l.mark((function t(){var e;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getPoxInfoUrl(),t.abrupt("return",n.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getTargetBlockTime=function(){var t=s(l.mark((function t(){var e,r;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getBlockTimeInfoUrl(),t.next=3,n.fetchPrivate(e).then((function(t){return t.json()}));case 3:if(r=t.sent,!this.network.isMainnet()){t.next=8;break}return t.abrupt("return",r.mainnet.target_block_time);case 8:return t.abrupt("return",r.testnet.target_block_time);case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getAccountStatus=function(){var t=s(l.mark((function t(){var e;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getAccountApiUrl(this.address),t.abrupt("return",n.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getAccountBalance=function(){var t=s(l.mark((function t(){return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getAccountStatus().then((function(t){var e=t.balance;return t.balance.startsWith("0x")&&(e=t.balance.substr(2)),new i.default(e,"hex")})));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getCycleDuration=function(){var t=s(l.mark((function t(){var e;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getPoxInfo(),t.next=3,this.getTargetBlockTime();case 3:return t.abrupt("return",Promise.all([e,t.sent]).then((function(t){return t[0].reward_cycle_length*t[1]})));case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getSecondsUntilNextCycle=function(){var t=s(l.mark((function t(){var e,r,n;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getPoxInfo(),t.next=3,this.getTargetBlockTime();case 3:return r=t.sent,n=this.getCoreInfo(),t.abrupt("return",Promise.all([e,r,n]).then((function(t){var e=t[0];return(e.reward_cycle_length-(t[2].burn_block_height-e.first_burnchain_block_height)%e.reward_cycle_length)*t[1]})));case 6:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.isStackingEnabledNextCycle=function(){var t=s(l.mark((function t(){return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPoxInfo();case 2:return t.t0=t.sent.rejection_votes_left_required,t.abrupt("return",t.t0>0);case 4:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.hasMinimumStx=function(){var t=s(l.mark((function t(){var e,r;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getAccountBalance();case 2:return e=t.sent,t.t0=i.default,t.next=6,this.getPoxInfo();case 6:return t.t1=t.sent.min_amount_ustx.toString(),r=new t.t0(t.t1),t.abrupt("return",e.gte(r));case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.canStack=function(){var t=s(l.mark((function t(r){var n,o,a,c,s=this;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.poxAddress,o=r.cycles,a=this.getAccountBalance(),c=this.getPoxInfo(),t.abrupt("return",Promise.all([a,c]).then((function(t){var r=t[0],a=t[1],c=d(n),u=c.data,f=e.bufferCV(new i.default(c.hashMode,10).toArrayLike(Buffer)),h=e.bufferCV(u),l=e.tupleCV({hashbytes:h,version:f}),p=s.parseContractId(a.contract_id);return e.callReadOnlyFunction({network:s.network,contractName:p[1],contractAddress:p[0],functionName:"can-stack-stx",senderAddress:s.address,functionArgs:[l,e.uintCV(r.toString()),e.uintCV(a.reward_cycle_id),e.uintCV(o.toString())]})})).then((function(t){return t.type===e.ClarityType.ResponseOk?{eligible:!0}:{eligible:!1,reason:h[+e.cvToString(t.value)]}})));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.stack=function(){var t=s(l.mark((function t(r){var n,o,a,i,c,s;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.amountMicroStx,o=r.poxAddress,a=r.cycles,i=r.privateKey,c=r.burnBlockHeight,t.next=3,this.getPoxInfo();case 3:return s=this.getStackOptions({amountMicroStx:n,cycles:a,poxAddress:o,contract:t.sent.contract_id,burnBlockHeight:c}),t.next=8,e.makeContractCall(u({},s,{senderKey:i}));case 8:return t.abrupt("return",e.broadcastTransaction(t.sent,s.network));case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.delegateStx=function(){var t=s(l.mark((function t(r){var n,o,a,i,c,s;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.amountMicroStx,o=r.delegateTo,a=r.untilBurnBlockHeight,i=r.poxAddress,c=r.privateKey,t.next=3,this.getPoxInfo();case 3:return s=this.getDelegateOptions({contract:t.sent.contract_id,amountMicroStx:n,delegateTo:o,untilBurnBlockHeight:a,poxAddress:i}),t.next=8,e.makeContractCall(u({},s,{senderKey:c}));case 8:return t.abrupt("return",e.broadcastTransaction(t.sent,s.network));case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.delegateStackStx=function(){var t=s(l.mark((function t(r){var n,o,a,i,c,s,f,h;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.stacker,o=r.amountMicroStx,a=r.poxAddress,i=r.burnBlockHeight,c=r.cycles,s=r.privateKey,f=r.nonce,t.next=3,this.getPoxInfo();case 3:return h=this.getDelegateStackOptions({contract:t.sent.contract_id,stacker:n,amountMicroStx:o,poxAddress:a,burnBlockHeight:i,cycles:c,nonce:f}),t.next=8,e.makeContractCall(u({},h,{senderKey:s}));case 8:return t.abrupt("return",e.broadcastTransaction(t.sent,h.network));case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.stackAggregationCommit=function(){var t=s(l.mark((function t(r){var n,o,a,i;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.poxAddress,o=r.rewardCycle,a=r.privateKey,t.next=3,this.getPoxInfo();case 3:return i=this.getStackAggregationCommitOptions({contract:t.sent.contract_id,poxAddress:n,rewardCycle:o}),t.next=8,e.makeContractCall(u({},i,{senderKey:a}));case 8:return t.abrupt("return",e.broadcastTransaction(t.sent,i.network));case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.revokeDelegateStx=function(){var t=s(l.mark((function t(r){var n;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPoxInfo();case 2:return n=this.getRevokeDelegateStxOptions(t.sent.contract_id),t.next=7,e.makeContractCall(u({},n,{senderKey:r}));case 7:return t.abrupt("return",e.broadcastTransaction(t.sent,n.network));case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getStackOptions=function(t){var r=t.amountMicroStx,n=t.cycles,o=t.contract,a=t.burnBlockHeight,c=d(t.poxAddress),s=c.data,u=e.bufferCV(new i.default(c.hashMode,10).toArrayLike(Buffer)),f=e.bufferCV(s),h=e.tupleCV({hashbytes:f,version:u}),l=this.parseContractId(o),p=this.network;return{contractAddress:l[0],contractName:l[1],functionName:"stack-stx",functionArgs:[e.uintCV(r.toString(10)),h,e.uintCV(a),e.uintCV(n)],validateWithAbi:!0,network:p}},r.getDelegateOptions=function(t){var r=t.contract,n=t.amountMicroStx,o=t.delegateTo,a=t.untilBurnBlockHeight,c=t.poxAddress,s=void 0;if(c){var u=d(c),f=u.data,h=e.bufferCV(new i.default(u.hashMode,10).toBuffer()),l=e.bufferCV(f);s=e.someCV(e.tupleCV({hashbytes:l,version:h}))}var p=this.parseContractId(r),v=this.network;return{contractAddress:p[0],contractName:p[1],functionName:"delegate-stx",functionArgs:[e.uintCV(n.toString(10)),e.standardPrincipalCV(o),a?e.someCV(e.uintCV(a)):e.noneCV(),s||e.noneCV()],validateWithAbi:!0,network:v}},r.getDelegateStackOptions=function(t){var r=t.contract,n=t.stacker,o=t.amountMicroStx,a=t.burnBlockHeight,c=t.cycles,s=t.nonce,u=d(t.poxAddress),f=u.data,h=e.bufferCV(new i.default(u.hashMode,10).toBuffer()),l=e.bufferCV(f),p=e.tupleCV({hashbytes:l,version:h}),v=this.parseContractId(r),g=this.network,_={contractAddress:v[0],contractName:v[1],functionName:"delegate-stack-stx",functionArgs:[e.standardPrincipalCV(n),e.uintCV(o.toString(10)),p,e.uintCV(a),e.uintCV(c)],validateWithAbi:!0,network:g};return s&&(_.nonce=s),_},r.getStackAggregationCommitOptions=function(t){var r=t.contract,n=t.rewardCycle,o=d(t.poxAddress),a=o.data,c=e.bufferCV(new i.default(o.hashMode,10).toBuffer()),s=e.bufferCV(a),u=e.tupleCV({hashbytes:s,version:c}),f=this.parseContractId(r),h=this.network;return{contractAddress:f[0],contractName:f[1],functionName:"stack-aggregation-commit",functionArgs:[u,e.uintCV(n)],validateWithAbi:!0,network:h}},r.getRevokeDelegateStxOptions=function(t){var e=this.parseContractId(t);return{contractAddress:e[0],contractName:e[1],functionName:"revoke-delegate-stx",functionArgs:[],validateWithAbi:!0,network:this.network}},r.getStatus=function(){var t=s(l.mark((function t(){var r,n,o,a;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPoxInfo();case 2:return r=this.parseContractId(t.sent.contract_id),n=r[0],o=r[1],t.next=6,this.getAccountStatus();case 6:return a=t.sent,t.abrupt("return",e.callReadOnlyFunction({contractAddress:n,contractName:o,functionName:"get-stacker-info",senderAddress:this.address,functionArgs:[e.standardPrincipalCV(this.address)],network:this.network}).then((function(t){if(t.type===e.ClarityType.OptionalSome){var r=t.value,n=r.data["pox-addr"],o=r.data["first-reward-cycle"],i=r.data["lock-period"],c=n.data.version,s=n.data.hashbytes;return{stacked:!0,details:{amount_microstx:r.data["amount-ustx"].value.toString(),first_reward_cycle:o.value.toNumber(),lock_period:i.value.toNumber(),unlock_height:a.unlock_height,pox_address:{version:c.buffer,hashbytes:s.buffer}}}}if(t.type===e.ClarityType.OptionalNone)return{stacked:!1};throw new Error("Error fetching stacker info")})));case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.modifyLockTxFee=function(t){var r=t.tx,n=t.amountMicroStx,o=r.auth.getFee();return r.payload.functionArgs[0]=e.uintCV(new i.default(n.toString(10),10).sub(o).toBuffer()),r},r.parseContractId=function(t){var r=t.split(".");if(2!==r.length||!e.validateStacksAddress(r[0])||"pox"!==r[1])throw new Error("Stacking contract ID is malformed");return r},t}(),Object.defineProperty(t,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@stacks/transactions"),require("bn.js"),require("@stacks/common"),require("bitcoinjs-lib")):"function"==typeof define&&define.amd?define(["exports","@stacks/transactions","bn.js","@stacks/common","bitcoinjs-lib"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self)["@stacks/stacking"]={},t.transactions,t.BN,t.common,t.bitcoinjsLib)}(this,(function(t,e,r,n,o){"use strict";function a(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var i=a(r);function c(t,e,r,n,o,a,i){try{var c=t[a](i),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,o)}function s(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function i(t){c(a,n,o,i,s,"next",t)}function s(t){c(a,n,o,i,s,"throw",t)}i(void 0)}))}}function u(){return(u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}function f(t,e){return t(e={exports:{}},e.exports),e.exports}var h,l=f((function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=Object.create((e&&e.prototype instanceof h?e:h).prototype),a=new w(n||[]);return o._invoke=function(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var c=E(i,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=u(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(t,r,a),o}function u(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var f={};function h(){}function l(){}function d(){}var p={};p[o]=function(){return this};var v=Object.getPrototypeOf,g=v&&v(v(R([])));g&&g!==e&&r.call(g,o)&&(p=g);var _=d.prototype=h.prototype=Object.create(p);function y(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function m(t,e){var n;this._invoke=function(o,a){function i(){return new e((function(n,i){!function n(o,a,i,c){var s=u(t[o],t,a);if("throw"!==s.type){var f=s.arg,h=f.value;return h&&"object"==typeof h&&r.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,i,c)}),(function(t){n("throw",t,i,c)})):e.resolve(h).then((function(t){f.value=t,i(f)}),(function(t){return n("throw",t,i,c)}))}c(s.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}function E(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,E(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=u(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function A(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function w(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function R(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,a=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return a.next=a}}return{next:C}}function C(){return{value:void 0,done:!0}}return l.prototype=_.constructor=d,d.constructor=l,l.displayName=c(d,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,c(t,i,"GeneratorFunction")),t.prototype=Object.create(_),t},t.awrap=function(t){return{__await:t}},y(m.prototype),m.prototype[a]=function(){return this},t.AsyncIterator=m,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new m(s(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},y(_),c(_,i,"Generator"),_[o]=function(){return this},_.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=R,w.prototype={constructor:w,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(x),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),s=r.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,f):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),x(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;x(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:R(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}));function d(t){var r=function(t){if(t.startsWith("bc1")||t.startsWith("tb1"))return 32===o.address.fromBech32(t).data.length?e.AddressHashMode.SerializeP2WSH:e.AddressHashMode.SerializeP2WPKH;switch(o.address.fromBase58Check(t).version){case 0:case 111:return e.AddressHashMode.SerializeP2PKH;case 5:case 196:return e.AddressHashMode.SerializeP2SH;default:throw new Error("Invalid pox address version")}}(t);return t.startsWith("bc1")||t.startsWith("tb1")?{hashMode:r,data:o.address.fromBech32(t).data}:{hashMode:r,data:o.address.fromBase58Check(t).hash}}!function(t){t[t.ERR_STACKING_UNREACHABLE=255]="ERR_STACKING_UNREACHABLE",t[t.ERR_STACKING_INSUFFICIENT_FUNDS=1]="ERR_STACKING_INSUFFICIENT_FUNDS",t[t.ERR_STACKING_INVALID_LOCK_PERIOD=2]="ERR_STACKING_INVALID_LOCK_PERIOD",t[t.ERR_STACKING_ALREADY_STACKED=3]="ERR_STACKING_ALREADY_STACKED",t[t.ERR_STACKING_NO_SUCH_PRINCIPAL=4]="ERR_STACKING_NO_SUCH_PRINCIPAL",t[t.ERR_STACKING_EXPIRED=5]="ERR_STACKING_EXPIRED",t[t.ERR_STACKING_STX_LOCKED=6]="ERR_STACKING_STX_LOCKED",t[t.ERR_STACKING_PERMISSION_DENIED=9]="ERR_STACKING_PERMISSION_DENIED",t[t.ERR_STACKING_THRESHOLD_NOT_MET=11]="ERR_STACKING_THRESHOLD_NOT_MET",t[t.ERR_STACKING_POX_ADDRESS_IN_USE=12]="ERR_STACKING_POX_ADDRESS_IN_USE",t[t.ERR_STACKING_INVALID_POX_ADDRESS=13]="ERR_STACKING_INVALID_POX_ADDRESS",t[t.ERR_STACKING_ALREADY_REJECTED=17]="ERR_STACKING_ALREADY_REJECTED",t[t.ERR_STACKING_INVALID_AMOUNT=18]="ERR_STACKING_INVALID_AMOUNT",t[t.ERR_NOT_ALLOWED=19]="ERR_NOT_ALLOWED",t[t.ERR_STACKING_ALREADY_DELEGATED=20]="ERR_STACKING_ALREADY_DELEGATED",t[t.ERR_DELEGATION_EXPIRES_DURING_LOCK=21]="ERR_DELEGATION_EXPIRES_DURING_LOCK",t[t.ERR_DELEGATION_TOO_MUCH_LOCKED=22]="ERR_DELEGATION_TOO_MUCH_LOCKED",t[t.ERR_DELEGATION_POX_ADDR_REQUIRED=23]="ERR_DELEGATION_POX_ADDR_REQUIRED",t[t.ERR_INVALID_START_BURN_HEIGHT=24]="ERR_INVALID_START_BURN_HEIGHT"}(h||(h={})),t.StackingClient=function(){function t(t,e){this.address=t,this.network=e}var r=t.prototype;return r.getCoreInfo=function(){var t=s(l.mark((function t(){var e;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getInfoUrl(),t.abrupt("return",n.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getPoxInfo=function(){var t=s(l.mark((function t(){var e;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getPoxInfoUrl(),t.abrupt("return",n.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getTargetBlockTime=function(){var t=s(l.mark((function t(){var e,r;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getBlockTimeInfoUrl(),t.next=3,n.fetchPrivate(e).then((function(t){return t.json()}));case 3:if(r=t.sent,!this.network.isMainnet()){t.next=8;break}return t.abrupt("return",r.mainnet.target_block_time);case 8:return t.abrupt("return",r.testnet.target_block_time);case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getAccountStatus=function(){var t=s(l.mark((function t(){var e;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.network.getAccountApiUrl(this.address),t.abrupt("return",n.fetchPrivate(e).then((function(t){return t.json()})));case 2:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getAccountBalance=function(){var t=s(l.mark((function t(){return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",this.getAccountStatus().then((function(t){var e=t.balance;return t.balance.startsWith("0x")&&(e=t.balance.substr(2)),new i.default(e,"hex")})));case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getCycleDuration=function(){var t=s(l.mark((function t(){var e;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getPoxInfo(),t.next=3,this.getTargetBlockTime();case 3:return t.abrupt("return",Promise.all([e,t.sent]).then((function(t){return t[0].reward_cycle_length*t[1]})));case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.getSecondsUntilNextCycle=function(){var t=s(l.mark((function t(){var e,r,n;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return e=this.getPoxInfo(),t.next=3,this.getTargetBlockTime();case 3:return r=t.sent,n=this.getCoreInfo(),t.abrupt("return",Promise.all([e,r,n]).then((function(t){var e=t[0];return(e.reward_cycle_length-(t[2].burn_block_height-e.first_burnchain_block_height)%e.reward_cycle_length)*t[1]})));case 6:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.isStackingEnabledNextCycle=function(){var t=s(l.mark((function t(){return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPoxInfo();case 2:return t.t0=t.sent.rejection_votes_left_required,t.abrupt("return",t.t0>0);case 4:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.hasMinimumStx=function(){var t=s(l.mark((function t(){var e,r;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getAccountBalance();case 2:return e=t.sent,t.t0=i.default,t.next=6,this.getPoxInfo();case 6:return t.t1=t.sent.min_amount_ustx.toString(),r=new t.t0(t.t1),t.abrupt("return",e.gte(r));case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.canStack=function(){var t=s(l.mark((function t(r){var n,o,a,c,s=this;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.poxAddress,o=r.cycles,a=this.getAccountBalance(),c=this.getPoxInfo(),t.abrupt("return",Promise.all([a,c]).then((function(t){var r=t[0],a=t[1],c=d(n),u=c.data,f=e.bufferCV(new i.default(c.hashMode,10).toArrayLike(Buffer)),h=e.bufferCV(u),l=e.tupleCV({hashbytes:h,version:f}),p=s.parseContractId(a.contract_id);return e.callReadOnlyFunction({network:s.network,contractName:p[1],contractAddress:p[0],functionName:"can-stack-stx",senderAddress:s.address,functionArgs:[l,e.uintCV(r.toString()),e.uintCV(a.reward_cycle_id),e.uintCV(o.toString())]})})).then((function(t){return t.type===e.ClarityType.ResponseOk?{eligible:!0}:{eligible:!1,reason:h[+e.cvToString(t.value)]}})));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.stack=function(){var t=s(l.mark((function t(r){var n,o,a,i,c,s;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.amountMicroStx,o=r.poxAddress,a=r.cycles,i=r.privateKey,c=r.burnBlockHeight,t.next=3,this.getPoxInfo();case 3:return s=this.getStackOptions({amountMicroStx:n,cycles:a,poxAddress:o,contract:t.sent.contract_id,burnBlockHeight:c}),t.next=8,e.makeContractCall(u({},s,{senderKey:i}));case 8:return t.abrupt("return",e.broadcastTransaction(t.sent,s.network));case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.delegateStx=function(){var t=s(l.mark((function t(r){var n,o,a,i,c,s;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.amountMicroStx,o=r.delegateTo,a=r.untilBurnBlockHeight,i=r.poxAddress,c=r.privateKey,t.next=3,this.getPoxInfo();case 3:return s=this.getDelegateOptions({contract:t.sent.contract_id,amountMicroStx:n,delegateTo:o,untilBurnBlockHeight:a,poxAddress:i}),t.next=8,e.makeContractCall(u({},s,{senderKey:c}));case 8:return t.abrupt("return",e.broadcastTransaction(t.sent,s.network));case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.delegateStackStx=function(){var t=s(l.mark((function t(r){var n,o,a,i,c,s,f,h;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.stacker,o=r.amountMicroStx,a=r.poxAddress,i=r.burnBlockHeight,c=r.cycles,s=r.privateKey,f=r.nonce,t.next=3,this.getPoxInfo();case 3:return h=this.getDelegateStackOptions({contract:t.sent.contract_id,stacker:n,amountMicroStx:o,poxAddress:a,burnBlockHeight:i,cycles:c,nonce:f}),t.next=8,e.makeContractCall(u({},h,{senderKey:s}));case 8:return t.abrupt("return",e.broadcastTransaction(t.sent,h.network));case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.stackAggregationCommit=function(){var t=s(l.mark((function t(r){var n,o,a,i;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n=r.poxAddress,o=r.rewardCycle,a=r.privateKey,t.next=3,this.getPoxInfo();case 3:return i=this.getStackAggregationCommitOptions({contract:t.sent.contract_id,poxAddress:n,rewardCycle:o}),t.next=8,e.makeContractCall(u({},i,{senderKey:a}));case 8:return t.abrupt("return",e.broadcastTransaction(t.sent,i.network));case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.revokeDelegateStx=function(){var t=s(l.mark((function t(r){var n;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPoxInfo();case 2:return n=this.getRevokeDelegateStxOptions(t.sent.contract_id),t.next=7,e.makeContractCall(u({},n,{senderKey:r}));case 7:return t.abrupt("return",e.broadcastTransaction(t.sent,n.network));case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),r.getStackOptions=function(t){var r=t.amountMicroStx,n=t.cycles,o=t.contract,a=t.burnBlockHeight,c=d(t.poxAddress),s=c.data,u=e.bufferCV(new i.default(c.hashMode,10).toArrayLike(Buffer)),f=e.bufferCV(s),h=e.tupleCV({hashbytes:f,version:u}),l=this.parseContractId(o),p=this.network;return{contractAddress:l[0],contractName:l[1],functionName:"stack-stx",functionArgs:[e.uintCV(r.toString(10)),h,e.uintCV(a),e.uintCV(n)],validateWithAbi:!0,network:p}},r.getDelegateOptions=function(t){var r=t.contract,n=t.amountMicroStx,o=t.delegateTo,a=t.untilBurnBlockHeight,c=t.poxAddress,s=void 0;if(c){var u=d(c),f=u.data,h=e.bufferCV(new i.default(u.hashMode,10).toArrayLike(Buffer)),l=e.bufferCV(f);s=e.someCV(e.tupleCV({hashbytes:l,version:h}))}var p=this.parseContractId(r),v=this.network;return{contractAddress:p[0],contractName:p[1],functionName:"delegate-stx",functionArgs:[e.uintCV(n.toString(10)),e.standardPrincipalCV(o),a?e.someCV(e.uintCV(a)):e.noneCV(),s||e.noneCV()],validateWithAbi:!0,network:v}},r.getDelegateStackOptions=function(t){var r=t.contract,n=t.stacker,o=t.amountMicroStx,a=t.burnBlockHeight,c=t.cycles,s=t.nonce,u=d(t.poxAddress),f=u.data,h=e.bufferCV(new i.default(u.hashMode,10).toArrayLike(Buffer)),l=e.bufferCV(f),p=e.tupleCV({hashbytes:l,version:h}),v=this.parseContractId(r),g=this.network,_={contractAddress:v[0],contractName:v[1],functionName:"delegate-stack-stx",functionArgs:[e.standardPrincipalCV(n),e.uintCV(o.toString(10)),p,e.uintCV(a),e.uintCV(c)],validateWithAbi:!0,network:g};return s&&(_.nonce=s),_},r.getStackAggregationCommitOptions=function(t){var r=t.contract,n=t.rewardCycle,o=d(t.poxAddress),a=o.data,c=e.bufferCV(new i.default(o.hashMode,10).toBuffer()),s=e.bufferCV(a),u=e.tupleCV({hashbytes:s,version:c}),f=this.parseContractId(r),h=this.network;return{contractAddress:f[0],contractName:f[1],functionName:"stack-aggregation-commit",functionArgs:[u,e.uintCV(n)],validateWithAbi:!0,network:h}},r.getRevokeDelegateStxOptions=function(t){var e=this.parseContractId(t);return{contractAddress:e[0],contractName:e[1],functionName:"revoke-delegate-stx",functionArgs:[],validateWithAbi:!0,network:this.network}},r.getStatus=function(){var t=s(l.mark((function t(){var r,n,o,a;return l.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPoxInfo();case 2:return r=this.parseContractId(t.sent.contract_id),n=r[0],o=r[1],t.next=6,this.getAccountStatus();case 6:return a=t.sent,t.abrupt("return",e.callReadOnlyFunction({contractAddress:n,contractName:o,functionName:"get-stacker-info",senderAddress:this.address,functionArgs:[e.standardPrincipalCV(this.address)],network:this.network}).then((function(t){if(t.type===e.ClarityType.OptionalSome){var r=t.value,n=r.data["pox-addr"],o=r.data["first-reward-cycle"],i=r.data["lock-period"],c=n.data.version,s=n.data.hashbytes;return{stacked:!0,details:{amount_microstx:r.data["amount-ustx"].value.toString(),first_reward_cycle:o.value.toNumber(),lock_period:i.value.toNumber(),unlock_height:a.unlock_height,pox_address:{version:c.buffer,hashbytes:s.buffer}}}}if(t.type===e.ClarityType.OptionalNone)return{stacked:!1};throw new Error("Error fetching stacker info")})));case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),r.modifyLockTxFee=function(t){var r=t.tx,n=t.amountMicroStx,o=r.auth.getFee();return r.payload.functionArgs[0]=e.uintCV(new i.default(n.toString(10),10).sub(o).toBuffer()),r},r.parseContractId=function(t){var r=t.split(".");if(2!==r.length||!e.validateStacksAddress(r[0])||"pox"!==r[1])throw new Error("Stacking contract ID is malformed");return r},t}(),Object.defineProperty(t,"__esModule",{value:!0})}));
//# sourceMappingURL=stacking.umd.production.min.js.map
{
"name": "@stacks/stacking",
"version": "1.3.0",
"version": "1.3.1",
"description": "Library for Stacking.",

@@ -68,3 +68,3 @@ "keywords": [

"unpkg": "dist/stacking.cjs.production.min.js",
"gitHead": "3f889aab44fa62c480258213a920e30f29833c2a"
"gitHead": "5dffb80ecb7df7d9c30b381d425b6fd9deb5eb4c"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc