opendao-sdk
Version:
SDK to interact with DAO
3 lines (2 loc) • 14.1 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@makerdao/multicall"),r={1:"",56:"",16666e5:"https://harmony-0.gateway.pokt.network/v1/lb/618a63ac7335c800360b4ce3",16667e5:"https://api.s0.pops.one/",1337:"http://127.0.0.1:8545"};function e(t,r,e,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void e(t)}s.done?r(u):Promise.resolve(u).then(n,o)}function n(t){return function(){var r=this,n=arguments;return new Promise((function(o,i){var a=t.apply(r,n);function s(t){e(a,o,i,s,u,"next",t)}function u(t){e(a,o,i,s,u,"throw",t)}s(void 0)}))}}var o,i=(function(t){var r=function(t){var r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",a=n.toStringTag||"@@toStringTag";function s(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{s({},"")}catch(t){s=function(t,r,e){return t[r]=e}}function u(t,r,e,n){var o=Object.create((r&&r.prototype instanceof h?r:h).prototype),i=new S(n||[]);return o._invoke=function(t,r,e){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return{value:void 0,done:!0}}for(e.method=o,e.arg=i;;){var a=e.delegate;if(a){var s=b(a,e);if(s){if(s===l)continue;return s}}if("next"===e.method)e.sent=e._sent=e.arg;else if("throw"===e.method){if("suspendedStart"===n)throw n="completed",e.arg;e.dispatchException(e.arg)}else"return"===e.method&&e.abrupt("return",e.arg);n="executing";var u=c(t,r,e);if("normal"===u.type){if(n=e.done?"completed":"suspendedYield",u.arg===l)continue;return{value:u.arg,done:e.done}}"throw"===u.type&&(n="completed",e.method="throw",e.arg=u.arg)}}}(t,e,i),o}function c(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l={};function h(){}function p(){}function f(){}var d={};s(d,o,(function(){return this}));var g=Object.getPrototypeOf,v=g&&g(g(O([])));v&&v!==r&&e.call(v,o)&&(d=v);var m=f.prototype=h.prototype=Object.create(d);function y(t){["next","throw","return"].forEach((function(r){s(t,r,(function(t){return this._invoke(r,t)}))}))}function w(t,r){var n;this._invoke=function(o,i){function a(){return new r((function(n,a){!function n(o,i,a,s){var u=c(t[o],t,i);if("throw"!==u.type){var l=u.arg,h=l.value;return h&&"object"==typeof h&&e.call(h,"__await")?r.resolve(h.__await).then((function(t){n("next",t,a,s)}),(function(t){n("throw",t,a,s)})):r.resolve(h).then((function(t){l.value=t,a(l)}),(function(t){return n("throw",t,a,s)}))}s(u.arg)}(o,i,n,a)}))}return n=n?n.then(a,a):a()}}function b(t,r){var e=t.iterator[r.method];if(void 0===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=void 0,b(t,r),"throw"===r.method))return l;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var n=c(e,t.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,l;var o=n.arg;return o?o.done?(r[t.resultName]=o.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,l):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,l)}function x(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function A(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function S(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function O(t){if(t){var r=t[o];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,i=function r(){for(;++n<t.length;)if(e.call(t,n))return r.value=t[n],r.done=!1,r;return r.value=void 0,r.done=!0,r};return i.next=i}}return{next:P}}function P(){return{value:void 0,done:!0}}return p.prototype=f,s(m,"constructor",f),s(f,"constructor",p),p.displayName=s(f,a,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===p||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,f):(t.__proto__=f,s(t,a,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},y(w.prototype),s(w.prototype,i,(function(){return this})),t.AsyncIterator=w,t.async=function(r,e,n,o,i){void 0===i&&(i=Promise);var a=new w(u(r,e,n,o),i);return t.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},y(m),s(m,a,"Generator"),s(m,o,(function(){return this})),s(m,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},t.values=O,S.prototype={constructor:S,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(A),!t)for(var r in this)"t"===r.charAt(0)&&e.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=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 r=this;function n(e,n){return a.type="throw",a.arg=t,r.next=e,n&&(r.method="next",r.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],a=i.completion;if("root"===i.tryLoc)return n("end");if(i.tryLoc<=this.prev){var s=e.call(i,"catchLoc"),u=e.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return n(i.catchLoc,!0);if(this.prev<i.finallyLoc)return n(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return n(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return n(i.finallyLoc)}}}},abrupt:function(t,r){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&e.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,l):this.complete(a)},complete:function(t,r){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&&r&&(this.next=r),l},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),A(e),l}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;A(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:O(t),resultName:r,nextLoc:e},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=r}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=r:Function("r","regeneratorRuntime = r")(r)}}(o={exports:{}}),o.exports),a=function(){function e(t,r,e){this.daoSettings={proposalTimeout:0,supplyPercentageToPropose:0,minTotalVoteRatio:0,minQuorumForPass:0,opinion:"",angel:"",encoder:""},this.actions={functionCalls:"",functionSelectors:""},this.proposal={type:0,status:0,action:0,creator:"0x0000000000000000000000000000000000000000",creationTimestamp:0,name:"",description:"",favorableVotes:"",unfavorableVotes:"",voters:[],numberOfVotes:"",comments:[],executionData:{bytes:"0x",functionCall:"null()",destination:"0x0000000000000000000000000000000000000000",argCount:0}},this.proposals=[],this.chainID=t,this.DAOContractAddress=r,this.multicall=e}var o=e.prototype;return o.initializeDao=function(){var t=n(i.mark((function t(){return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getProposalCount();case 2:return t.next=4,this.getDaoSettings();case 4:return t.next=6,this.getProposals();case 6:return t.next=8,this.getActions();case 8:return t.abrupt("return");case 9:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),o.getDaoSettings=function(){var e=n(i.mark((function e(){var n,o,a,s,u;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.multicall,o=r[this.chainID],(a=[]).push({target:this.DAOContractAddress,call:["proposalTimeout()(uint256)"],returns:[["proposalTimeout : ",function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["supplyPercentageToPropose()(uint256)"],returns:[["supplyPercentageToPropose : ",function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["minTotalVoteRatio()(uint256)"],returns:[["minTotalVoteRatio : ",function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["minQuorumForPass()(uint256)"],returns:[["minQuorumForPass : ",function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["minQuorumForPass()(uint256)"],returns:[["minQuorumForPass : ",function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["minQuorumForPass()(uint256)"],returns:[["minQuorumForPass : ",function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["Opinion()(address)"],returns:[["opaddr : ",function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["Angel()(address)"],returns:[["angAddr : ",function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["encodedFunctionStore()(address)"],returns:[["encoderAddr : ",function(t){return t}]]}),s=[],(u=t.createWatcher(a,{rpcUrl:o,multicallAddress:n})).subscribe((function(t){s.push(t)})),u.start(),e.next=19,u.awaitInitialFetch();case 19:this.daoSettings.proposalTimeout=s[0].value.toString(),this.daoSettings.supplyPercentageToPropose=s[1].value.toString(),this.daoSettings.minTotalVoteRatio=s[2].value.toString(),this.daoSettings.minQuorumForPass=s[3].value.toString(),this.daoSettings.opinion=s[4].value.toString(),this.daoSettings.angel=s[5].value.toString(),this.daoSettings.encoder=s[6].value.toString(),u.stop();case 27:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),o.getProposals=function(){var e=n(i.mark((function e(){var n,o,a,s,u,c,l,h,p,f;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(n=this.multicall,o=r[this.chainID],a=[],s=0;s<this.proposalCount;)a.push({target:this.DAOContractAddress,call:["getProposalCreator(uint256)(address)",s],returns:[["NumberOfProposals : "+s,function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["getProposalIntInfo(uint256)(uint256[7])",s],returns:[["INTS: "+s,function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["getProposalName(uint256)(string)",s],returns:[["name : "+s,function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["getProposalDescription(uint256)(string)",s],returns:[["desc : "+s,function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["getExecutionData(uint256)(bytes,string,address,uint256)",s],returns:[["bytes : "+s,function(t){return t}],["functionName : "+s,function(t){return t}],["callDestination "+s,function(t){return t}],["argCount : "+s,function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["getProposalVoters(uint256)(address[])",s],returns:[["adresses : "+s,function(t){return t}]]}),a.push({target:this.DAOContractAddress,call:["getProposalComments(uint256)(string[])",s],returns:[["comments : "+s,function(t){return t}]]}),s++;return u=[],(c=t.createWatcher(a,{rpcUrl:o,multicallAddress:n})).subscribe((function(t){u.push(t)})),c.start(),e.next=12,c.awaitInitialFetch();case 12:for(c.stop(),l=0,h=u.length;l<h;l+=10)p=u.slice(l,l+10),f={type:p[1].value[0].toNumber(),status:p[1].value[1].toNumber(),action:p[1].value[2].toNumber(),creator:p[0].value,creationTimestamp:p[1].value[3].toNumber(),name:p[2].value,description:p[3].value,favorableVotes:p[1].value[6].toString(),unfavorableVotes:p[1].value[4].toString(),voters:p[8].value,numberOfVotes:p[1].value[5].toString(),comments:p[9].value,executionData:{bytes:p[4].value.toString(),functionCall:p[5].value.toString(),destination:p[6].value.toString(),argCount:p[7].value.toString()}},this.proposals.push(f);return e.abrupt("return",0);case 16:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),o.getActions=function(){var e=n(i.mark((function e(){var n,o,a,s,u;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.multicall,o=r[this.chainID],(a=[]).push({target:this.daoSettings.encoder,call:["getFunctionStrings()(string[])"],returns:[["func : ",function(t){return t}]]}),a.push({target:this.daoSettings.encoder,call:["getFunctionSelectors()(bytes4[])"],returns:[["selec : ",function(t){return t}]]}),s=[],(u=t.createWatcher(a,{rpcUrl:o,multicallAddress:n})).subscribe((function(t){s.push(t)})),u.start(),e.next=12,u.awaitInitialFetch();case 12:this.actions.functionCalls=s[0].value,this.actions.functionSelectors=s[1].value,u.stop();case 15:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),o.getProposalCount=function(){var e=n(i.mark((function e(){var n,o,a,s,u;return i.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=this.multicall,o=r[this.chainID],(a=[]).push({target:this.DAOContractAddress,call:["proposalCount()(uint256)"],returns:[["NumberOfProposals : ",function(t){return t}]]}),s=[],(u=t.createWatcher(a,{rpcUrl:o,multicallAddress:n})).subscribe((function(t){s.push(t)})),u.start(),e.next=11,u.awaitInitialFetch();case 11:u.stop(),this.proposalCount=s[0].value.toString()/1;case 13:case"end":return e.stop()}}),e,this)})));return function(){return e.apply(this,arguments)}}(),e}();exports.ChainId={ETHEREUM:1,BINANCE:56,HARMONY:16666e5,TESTNET:16667e5,LOCAL:1337},exports.DAO=a,exports.ProposalType={INTERNAL:1,EXTERNAL:0},exports.RPC_URLS=r;
//# sourceMappingURL=opendao-sdk.cjs.production.min.js.map