UNPKG

dao-x-app-sdk

Version:

SDK to interact with DAO

3 lines (2 loc) 19.1 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@makerdao/multicall"),r={1:"",56:"",16666e5:"0xcF664087a5bB0237a0BAd6742852ec6c8d69A27a",16667e5:"0x7466d7d0c21fa05f32f5a0fa27e12bdc06348ce2",1337:"0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8"},e={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 n(t,r,e,n,o,a,i){try{var u=t[a](i),s=u.value}catch(t){return void e(t)}u.done?r(s):Promise.resolve(s).then(n,o)}function o(t){return function(){var r=this,e=arguments;return new Promise((function(o,a){var i=t.apply(r,e);function u(t){n(i,o,a,u,s,"next",t)}function s(t){n(i,o,a,u,s,"throw",t)}u(void 0)}))}}var a,i=(function(t){var r=function(t){var r=Object.prototype,e=r.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",a=n.asyncIterator||"@@asyncIterator",i=n.toStringTag||"@@toStringTag";function u(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{u({},"")}catch(t){u=function(t,r,e){return t[r]=e}}function s(t,r,e,n){var o=Object.create((r&&r.prototype instanceof f?r:f).prototype),a=new P(n||[]);return o._invoke=function(t,r,e){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(e.method=o,e.arg=a;;){var i=e.delegate;if(i){var u=b(i,e);if(u){if(u===l)continue;return u}}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 s=c(t,r,e);if("normal"===s.type){if(n=e.done?"completed":"suspendedYield",s.arg===l)continue;return{value:s.arg,done:e.done}}"throw"===s.type&&(n="completed",e.method="throw",e.arg=s.arg)}}}(t,e,a),o}function c(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}t.wrap=s;var l={};function f(){}function h(){}function p(){}var d={};u(d,o,(function(){return this}));var v=Object.getPrototypeOf,g=v&&v(v(D([])));g&&g!==r&&e.call(g,o)&&(d=g);var m=p.prototype=f.prototype=Object.create(d);function y(t){["next","throw","return"].forEach((function(r){u(t,r,(function(t){return this._invoke(r,t)}))}))}function x(t,r){var n;this._invoke=function(o,a){function i(){return new r((function(n,i){!function n(o,a,i,u){var s=c(t[o],t,a);if("throw"!==s.type){var l=s.arg,f=l.value;return f&&"object"==typeof f&&e.call(f,"__await")?r.resolve(f.__await).then((function(t){n("next",t,i,u)}),(function(t){n("throw",t,i,u)})):r.resolve(f).then((function(t){l.value=t,i(l)}),(function(t){return n("throw",t,i,u)}))}u(s.arg)}(o,a,n,i)}))}return n=n?n.then(i,i):i()}}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 w(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 S(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(w,this),this.reset(!0)}function D(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,a=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 a.next=a}}return{next:E}}function E(){return{value:void 0,done:!0}}return h.prototype=p,u(m,"constructor",p),u(p,"constructor",h),h.displayName=u(p,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===h||"GeneratorFunction"===(r.displayName||r.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,u(t,i,"GeneratorFunction")),t.prototype=Object.create(m),t},t.awrap=function(t){return{__await:t}},y(x.prototype),u(x.prototype,a,(function(){return this})),t.AsyncIterator=x,t.async=function(r,e,n,o,a){void 0===a&&(a=Promise);var i=new x(s(r,e,n,o),a);return t.isGeneratorFunction(e)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},y(m),u(m,i,"Generator"),u(m,o,(function(){return this})),u(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=D,P.prototype={constructor:P,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(S),!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 i.type="throw",i.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 a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var u=e.call(a,"catchLoc"),s=e.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(u){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,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 a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=r&&r<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=r,a?(this.method="next",this.next=a.finallyLoc,l):this.complete(i)},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),S(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;S(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:D(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)}}(a={exports:{}}),a.exports),u=function(){function n(t,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.daos=[],this.uris=[],this.chainID=t,this.openDaoContract=e,this.multicall=r[this.chainID],this.daoCount=0,this.uris=[]}var a=n.prototype;return a.getURIs=function(){var r=o(i.mark((function r(){var n,o,a,u,s;return i.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=this.multicall,o=e[this.chainID],(a=[]).push({target:this.openDaoContract,call:["getURIs()(string[])"],returns:[["uri:",function(t){return t}]]}),u=[],(s=t.createWatcher(a,{rpcUrl:o,multicallAddress:n})).subscribe((function(t){u.push(t)})),s.start(),r.next=11,s.awaitInitialFetch();case 11:return s.stop(),this.uris=u[0].value,r.abrupt("return",this.uris);case 14:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),a.loadDao=function(){var t=o(i.mark((function t(r){return i.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.loadDaoData(r);case 2:return t.next=4,this.getDaoSettings(r);case 4:return t.next=6,this.getProposalInternal(r,0,15);case 6:return t.next=8,this.getProposalExternal(r,0,15);case 8:return t.abrupt("return",this.daos[r]);case 9:case"end":return t.stop()}}),t,this)})));return function(r){return t.apply(this,arguments)}}(),a.loadDaoData=function(){var r=o(i.mark((function r(n){var o,a,u,s,c,l;return i.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=this.multicall,a=e[this.chainID],(u=[]).push({target:this.openDaoContract,call:["daos(uint256)(string,string,string,address,address,address,address,address,address,address,address,address)",n],returns:[["name: ",function(t){return t}],["uri: ",function(t){return t}],["url: ",function(t){return t}],["nterc: ",function(t){return t}],["angel: ",function(t){return t}],["dao: ",function(t){return t}],["multi: ",function(t){return t}],["manager: ",function(t){return t}],["addressbook: ",function(t){return t}],["add: ",function(t){return t}],["remove: ",function(t){return t}],["trade: ",function(t){return t}]]}),s=[],(c=t.createWatcher(u,{rpcUrl:a,multicallAddress:o})).subscribe((function(t){s.push(t)})),c.start(),r.next=11,c.awaitInitialFetch();case 11:return c.stop(),l={name:s[0].value.toString(),uri:s[1].value.toString(),img:s[2].value.toString(),nterc20:s[3].value.toString(),erc721:s[4].value.toString(),daoAddress:s[5].value.toString(),multichefAddress:s[6].value.toString(),daoManager:s[7].value.toString(),addressBook:s[8].value.toString(),liquidityAddHelper:s[9].value.toString(),liquidityRemoveHelper:s[10].value.toString(),trader:s[11].value.toString(),proposals:{internal:[],external:[]},settings:{}},this.daos[n]=l,r.abrupt("return",l);case 15:case"end":return r.stop()}}),r,this)})));return function(t){return r.apply(this,arguments)}}(),a.getAllDaos=function(){var r=o(i.mark((function r(){var n,o,a,u,s,c,l,f,h,p;return i.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(n=this.multicall,o=e[this.chainID],a=[],u=0;u<this.daoCount;)console.log(u),a.push({target:this.openDaoContract,call:["daos(uint256)(string,string,string,address,address,address,address,address,address,address,address,address)",u],returns:[["name: "+u,function(t){return t}],["uri: "+u,function(t){return t}],["url: "+u,function(t){return t}],["nterc: "+u,function(t){return t}],["angel: "+u,function(t){return t}],["dao: "+u,function(t){return t}],["multi: "+u,function(t){return t}],["manager: "+u,function(t){return t}],["addressbook: "+u,function(t){return t}],["add: "+u,function(t){return t}],["remove: "+u,function(t){return t}],["trade: "+u,function(t){return t}]]}),u++;return s=[],(c=t.createWatcher(a,{rpcUrl:o,multicallAddress:n})).subscribe((function(t){s.push(t)})),c.start(),r.next=12,c.awaitInitialFetch();case 12:for(c.stop(),l=0,f=s.length;l<f;l+=12)h=s.slice(l,l+12),p={name:h[0].value.toString(),uri:h[1].value.toString(),img:h[2].value.toString(),nterc20:h[3].value.toString(),erc721:h[4].value.toString(),daoAddress:h[5].value.toString(),multichefAddress:h[6].value.toString(),daoManager:h[7].value.toString(),addressBook:h[8].value.toString(),liquidityAddHelper:h[9].value.toString(),liquidityRemoveHelper:h[10].value.toString(),trader:h[11].value.toString(),proposals:[],settings:{}},this.daos.push(p);return r.abrupt("return");case 16:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),a.getDaoCount=function(){var r=o(i.mark((function r(){var n,o,a,u,s;return i.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n=this.multicall,o=e[this.chainID],(a=[]).push({target:this.openDaoContract,call:["getDaoLength()(uint256)"],returns:[["daoLength: ",function(t){return t}]]}),u=[],(s=t.createWatcher(a,{rpcUrl:o,multicallAddress:n})).subscribe((function(t){u.push(t)})),s.start(),r.next=11,s.awaitInitialFetch();case 11:s.stop(),this.daoCount=u[0].value.toString();case 13:case"end":return r.stop()}}),r,this)})));return function(){return r.apply(this,arguments)}}(),a.getDaoSettings=function(){var r=o(i.mark((function r(n){var o,a,u,s,c,l,f;return i.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return o=this.multicall,a=e[this.chainID],u=[],s=this.daos[n].daoAddress,console.log(s),u.push({target:s,call:["proposalTimeout()(uint256)"],returns:[["proposalTimeout : ",function(t){return t}]]}),u.push({target:s,call:["supplyPercentageToPropose()(uint256)"],returns:[["supplyPercentageToPropose : ",function(t){return t}]]}),u.push({target:s,call:["minTotalVoteRatio()(uint256)"],returns:[["minTotalVoteRatio : ",function(t){return t}]]}),u.push({target:s,call:["minQuorumForPass()(uint256)"],returns:[["minQuorumForPass : ",function(t){return t}]]}),u.push({target:s,call:["minQuorumForPass()(uint256)"],returns:[["minQuorumForPass : ",function(t){return t}]]}),u.push({target:s,call:["minQuorumForPass()(uint256)"],returns:[["minQuorumForPass : ",function(t){return t}]]}),u.push({target:s,call:["getProposalCount(uint256)(uint256)",0],returns:[["intproposalCount : ",function(t){return t}]]}),u.push({target:s,call:["getProposalCount(uint256)(uint256)",1],returns:[["extproposalCount : ",function(t){return t}]]}),c=[],(l=t.createWatcher(u,{rpcUrl:a,multicallAddress:o})).subscribe((function(t){c.push(t)})),l.start(),r.next=20,l.awaitInitialFetch();case 20:return l.stop(),f={timeout:c[0].value.toString(),supplyPercentageToPropose:c[1].value.toString(),minTotalVoteRatio:c[2].value.toString(),minQuorumForPass:c[3].value.toString(),internalProposalCount:parseFloat(c[4].value.toString()),externalProposalCount:parseFloat(c[5].value.toString())},this.daos[n].settings=f,r.abrupt("return");case 24:case"end":return r.stop()}}),r,this)})));return function(t){return r.apply(this,arguments)}}(),a.getProposalExternal=function(){var r=o(i.mark((function r(n,o,a){var u,s,c,l,f,h,p,d,v,g,m,y;return i.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(u=[],s=this.multicall,c=e[this.chainID],l=[],f=0,h=this.daos[n].daoAddress,console.log(this.daos[n].settings.externalProposalCount),this.daos[n].settings.externalProposalCount>0)for(;f<this.daos[n].settings.externalProposalCount;)l.push({target:h,call:["getExternalData(uint256)(uint256,address,uint256,string,string,uint256,uint256,address,address[],string[])",f],returns:[["status : "+f,function(t){return t}],["creator : "+f,function(t){return t}],["creationTimestamp : "+f,function(t){return t}],["name : "+f,function(t){return t}],["description : "+f,function(t){return t}],["favorable : "+f,function(t){return t}],["unfavorable : "+f,function(t){return t}],["token2 : "+f,function(t){return t}],["votes : "+f,function(t){return t}],["comments : "+f,function(t){return t}]]}),f++;return p=[],(d=t.createWatcher(l,{rpcUrl:c,multicallAddress:s})).subscribe((function(t){p.push(t)})),d.start(),r.next=16,d.awaitInitialFetch();case 16:for(d.stop(),v=0,g=p.length;v<g;v+=10)m=p.slice(v,v+10),y={proposalStatus:m[0].value.toString(),creator:m[1].value,type:1,creationTimestamp:m[2].value,name:m[3].value,description:m[4].value,favorable:m[5].value.toString(),unfavorable:m[6].value.toString(),token2:m[7].value,votes:m[8].value,comments:m[9].value},this.daos[n].proposals.external.push(y),u.push(y);return r.abrupt("return",0);case 20:case"end":return r.stop()}}),r,this)})));return function(t,e,n){return r.apply(this,arguments)}}(),a.getProposalInternal=function(){var r=o(i.mark((function r(n,o,a){var u,s,c,l,f,h,p,d,v,g,m,y;return i.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(u=[],s=this.multicall,c=e[this.chainID],l=[],f=o,h=this.daos[n].daoAddress,console.log(this.daos[n].settings.externalProposalCount),a>this.daos[n].settings.internalProposalCount&&(a=this.daos[n].settings.internalProposalCount),this.daos[n].settings.internalProposalCount>0)for(;f<a;)l.push({target:h,call:["getInternalDataArrays(uint256)(address[],string[],address[],bytes[],bytes[],string[],uint256[],uint256[])",f],returns:[["votes : "+f,function(t){return t}],["comments : "+f,function(t){return t}],["targets : "+f,function(t){return t}],["callDatas : "+f,function(t){return t}],["returnDatas : "+f,function(t){return t}],["functionStrings : "+f,function(t){return t}],["txValues : "+f,function(t){return t}],["tokenIDsVoted : "+f,function(t){return t}]]}),l.push({target:h,call:["getInternalData(uint256)(uint256,uint256,string,string,uint256,uint256,address,uint256,address)",f],returns:[["proposalStatus : "+f,function(t){return t}],["creationTimestamp : "+f,function(t){return t}],["name : "+f,function(t){return t}],["description : "+f,function(t){return t}],["favorable : "+f,function(t){return t}],["unfavorable : "+f,function(t){return t}],["token : "+f,function(t){return t}],["executionTimestamp : "+f,function(t){return t}],["creator : "+f,function(t){return t}]]}),f++;return p=[],(d=t.createWatcher(l,{rpcUrl:c,multicallAddress:s})).subscribe((function(t){p.push(t)})),d.start(),r.next=16,d.awaitInitialFetch();case 16:for(d.stop(),v=0,g=p.length;v<g;v+=17)m=p.slice(v,v+17),y={status:m[8].value.toString(),creator:m[16].value,type:0,voteToken:m[14].value,creationTimestamp:m[9].value.toNumber(),name:m[10].value,description:m[11].value,favorableVotes:m[12].value.toString(),unfavorableVotes:m[13].value.toString(),voters:m[0].value,tokenIDVotes:m[7].value,numberOfVotes:m[0].value.length,comments:m[1].value,executionData:{functionCall:m[3].value,functionSig:m[5].value,returnData:m[4].value,destination:m[2].value,txValue:m[6].value,executionTimestamp:m[15].value.toString()}},this.daos[n].proposals.internal.push(y),u.push(y),console.log(y);return r.abrupt("return",u);case 20:case"end":return r.stop()}}),r,this)})));return function(t,e,n){return r.apply(this,arguments)}}(),n}();exports.ChainId={ETHEREUM:1,BINANCE:56,HARMONY:16666e5,TESTNET:16667e5,LOCAL:1337},exports.DAO=u,exports.MULTICALL=r,exports.OPENDAO={1:"",56:"",16666e5:"0x01A4b054110d57069c1658AFBC46730529A3E326",16667e5:"0x9580254b12A7289e4b86c30F6a254Be81fD5B8Df",1337:"0xA4899D35897033b927acFCf422bc745916139776"},exports.ProposalType={INTERNAL:1,EXTERNAL:0},exports.RPC_URLS=e,exports.WONE={1:"",56:"",16666e5:"0xcF664087a5bB0237a0BAd6742852ec6c8d69A27a",16667e5:"0x7466d7d0c21fa05f32f5a0fa27e12bdc06348ce2",1337:"0x5FbDB2315678afecb367f032d93F642f64180aa3"}; //# sourceMappingURL=dao-x-app-sdk.cjs.production.min.js.map