UNPKG

@starkware-industries/starkex-js

Version:

`starkex-js` is a JavaScript wrapper around the [StarkEx API](https://starkware.co/starkex/api/) that can be used in both NodeJS and Browser environments.

1 lines 16.5 kB
(()=>{"use strict";var t={211:t=>{t.exports=require("https")}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var i=e[r]={exports:{}};return t[r](i,i.exports,n),i.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var r={};(()=>{n.d(r,{default:()=>k});const t=require("js-logger");var e=n.n(t);e().useDefaults({defaultLevel:e().ERROR});var o=function(t){return t?e().get(t):e()},i=function(t,e){o(e).setLevel(t)},a=function(t){var e={};return Object.keys(t).forEach((function(n){var r,o=t[n];Array.isArray(o)?o=o.map((function(t){return a(t)})):"object"==typeof o&&(o=a(o)),e[(r=n,r.replace(/([A-Z])/g,"_$1").toLowerCase())]=o})),e};const _=require("axios");var u=n.n(_),s=function(){return(s=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},c=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function _(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,_)}u((r=r.apply(t,e||[])).next())}))},E=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:_(0),throw:_(1),return:_(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function _(i){return function(_){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,_])}}},T={"Content-Type":"application/json"};u().interceptors.request.use((function(t){return Object.assign(t.headers,{}),t}),(function(t){return Promise.reject(t)})),u().interceptors.response.use((function(t){return t}),(function(t){return Promise.reject(t)}));var A,l,I=function(t){var e=t.path,r=t.method,o=void 0===r?"GET":r,i=t.data,a=t.headers,_=void 0===a?{}:a,A=t.certs;return c(void 0,void 0,void 0,(function(){var t,r;return E(this,(function(a){return A&&(r=n(211),t=new r.Agent(s({rejectUnauthorized:!1},A))),[2,u()({url:e,method:o,data:i||{},headers:Object.assign({},T,_),httpsAgent:t})]}))}))};!function(t){t.V1="v1",t.V2="v2"}(l||(l={}));var R,f,p=((A={})[l.V1]="",A[l.V2]="v2",A),N="This function is deprecated and will be deleted in the next version.",O=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function _(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,_)}u((r=r.apply(t,e||[])).next())}))},h=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:_(0),throw:_(1),return:_(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function _(i){return function(_){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,_])}}},d=function(){function t(t,e){this.path=e;var n=t.endpoint,r=t.certs;this.endpoint=n,this.certs=r,this.initLogger(this.getEndpoint())}return t.prototype.getEndpoint=function(t){return[this.endpoint,p[t||this.path.defaultVersion],this.path.gatewayRoute].filter((function(t){return!!t})).join("/")},t.prototype.initLogger=function(t){var e=t.split("/"),n=e[e.length-1].split("_").map((function(t){return function(t){return"string"!=typeof t?"":t.charAt(0).toUpperCase()+t.slice(1)}(t)})).join(" ");this.logger=o(n),this.logger.debug("Initialized")},t.prototype.makeRequest=function(t,e,n,r){var o,i,a;return O(this,void 0,void 0,(function(){var _,u;return h(this,(function(s){switch(s.label){case 0:return s.trys.push([0,2,,3]),this.logger.debug("Sending request to "+t,n),[4,I({path:this.getEndpoint(r)+"/"+t,method:e,data:n,certs:this.certs})];case 1:return _=s.sent(),this.logger.debug("Response success:",_.data),[2,_.data];case 2:return u=s.sent(),this.logger.error("Error in response:",null===(i=null===(o=u.response)||void 0===o?void 0:o.data)||void 0===i?void 0:i.message),[2,Promise.reject(null===(a=u.response)||void 0===a?void 0:a.data)];case 3:return[2]}}))}))},t}();!function(t){t.SETTLEMENT_REQUEST="SettlementRequest",t.TRANSFER_REQUEST="TransferRequest",t.CONDITIONAL_TRANSFER_REQUEST="ConditionalTransferRequest",t.DEPOSIT_REQUEST="DepositRequest",t.MINT_REQUEST="MintRequest",t.WITHDRAWAL_REQUEST="WithdrawalRequest",t.FULL_WITHDRAWAL_REQUEST="FullWithdrawalRequest",t.FALSE_FULL_WITHDRAWAL_REQUEST="FalseFullWithdrawalRequest",t.MULTI_TRANSACTION_REQUEST="MultiTransactionRequest"}(R||(R={})),function(t){t.ADD_TRANSACTION="add_transaction",t.GET_TRANSACTION="get_transaction",t.IS_ALIVE="is_alive",t.GET_FIRST_UNUSED_TX_ID="testing/get_first_unused_tx_id",t.GET_STARK_DEX_ADDRESS="testing/get_stark_dex_address",t.MARK_TRANSACTION_FOR_REPLACEMENT="mark_transaction_for_replacement"}(f||(f={}));var S,D,y,L=(S=function(t,e){return(S=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}S(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),C=function(){return(C=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},v=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{u(r.next(t))}catch(t){i(t)}}function _(t){try{u(r.throw(t))}catch(t){i(t)}}function u(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,_)}u((r=r.apply(t,e||[])).next())}))},U=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:_(0),throw:_(1),return:_(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function _(i){return function(_){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,_])}}},g=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},b=function(t){function e(e){return t.call(this,e,{gatewayRoute:"gateway",defaultVersion:l.V2})||this}return L(e,t),e.prototype.getTransaction=function(t){return this.makeRequest(f.GET_TRANSACTION+"?tx_id="+t)},e.prototype.getStarkDexAddress=function(){return this.makeRequest(f.GET_STARK_DEX_ADDRESS)},e.prototype.getFirstUnusedTxId=function(){return this.makeRequest(f.GET_FIRST_UNUSED_TX_ID)},e.prototype.markTransactionForReplacement=function(t){return this.makeRequest(f.MARK_TRANSACTION_FOR_REPLACEMENT+"?tx_id="+t,"POST")},e.prototype.isAlive=function(){return this.makeRequest(f.IS_ALIVE)},e.prototype.withdrawal=function(t){return this.addTransaction(R.WITHDRAWAL_REQUEST,t)},e.prototype.deposit=function(t){return this.addTransaction(R.DEPOSIT_REQUEST,t)},e.prototype.mint=function(t){return this.addTransaction(R.MINT_REQUEST,t)},e.prototype.settlement=function(t){return this.addTransaction(R.SETTLEMENT_REQUEST,t)},e.prototype.transfer=function(t){return this.addTransaction(R.TRANSFER_REQUEST,t)},e.prototype.conditionalTransfer=function(t){return this.addTransaction(R.CONDITIONAL_TRANSFER_REQUEST,t)},e.prototype.fullWithdrawal=function(t){return this.addTransaction(R.FULL_WITHDRAWAL_REQUEST,t)},e.prototype.falseFullWithdrawal=function(t){return this.addTransaction(R.FALSE_FULL_WITHDRAWAL_REQUEST,t)},e.prototype.multiTransaction=function(t){return this.addTransaction(R.MULTI_TRANSACTION_REQUEST,t)},e.prototype.addTransaction=function(t,e){return v(this,void 0,void 0,(function(){var n,r,o,i,_;return U(this,(function(u){switch(u.label){case 0:n=e.txId,r=g(e,["txId"]),o=a(r),u.label=1;case 1:return u.trys.push([1,3,,4]),[4,this.makeRequest(f.ADD_TRANSACTION,"POST",{tx:C({type:t},o),tx_id:n})];case 2:return i=u.sent(),[2,C({txId:n},i)];case 3:return _=u.sent(),[2,Promise.reject(C(C({},_),{txId:n}))];case 4:return[2]}}))}))},e}(d);!function(t){t[t.SETTLEMENT=0]="SETTLEMENT",t[t.TRANSFER=1]="TRANSFER"}(D||(D={})),function(t){t.IS_READY="is_ready",t.IS_ALIVE="is_alive",t.GET_BATCH_ENCLOSING_IDS="get_batch_enclosing_ids",t.GET_BATCH_IDS="get_batch_ids",t.GET_BATCH_INFO="get_batch_info",t.GET_LAST_BATCH_ID="get_last_batch_id",t.GET_PREV_BATCH_ID="get_prev_batch_id"}(y||(y={}));var F,w=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),G=function(t){function e(e){return t.call(this,e,{gatewayRoute:"feeder_gateway",defaultVersion:l.V2})||this}return w(e,t),e.prototype.isAlive=function(){return this.makeRequest(""+y.IS_ALIVE)},e.prototype.isReady=function(){return this.makeRequest(""+y.IS_READY)},e.prototype.getBatchEnclosingIds=function(t){return this.makeRequest(y.GET_BATCH_ENCLOSING_IDS+"?batch_id="+t)},e.prototype.DEPRECATED_getBatchIds=function(t){this.logger.error("DEPRECATED_getBatchIds: "+N);var e=t.vaultRoot,n=t.orderRoot,r=t.sequenceNumber;return this.makeRequest(y.GET_BATCH_IDS+"?vault_root="+e+"&order_root="+n+"&sequence_number="+r,"GET",void 0,l.V1)},e.prototype.DEPRECATED_getBatchInfo=function(t){return this.logger.error("DEPRECATED_getBatchInfo: "+N),this.makeRequest(y.GET_BATCH_INFO+"?batch_id="+t,"GET",void 0,l.V1)},e.prototype.getBatchInfo=function(t){return this.makeRequest(y.GET_BATCH_INFO+"?batch_id="+t)},e.prototype.getLastBatchId=function(){return this.makeRequest(""+y.GET_LAST_BATCH_ID)},e.prototype.getPrevBatchId=function(t){return this.makeRequest(y.GET_PREV_BATCH_ID+"?batch_id="+t)},e}(d);!function(t){t.APPROVE_NEW_ROOTS="approve_new_roots",t.GET_BATCH_DATA="get_batch_data"}(F||(F={}));var V,P=function(){var t=function(e,n){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}();!function(t){function e(e){return t.call(this,e,{gatewayRoute:"availability_gateway",defaultVersion:l.V1})||this}P(e,t),e.prototype.approveNewRoots=function(t){var e=a(t);return this.makeRequest(F.APPROVE_NEW_ROOTS,"POST",e)},e.prototype.getBatchData=function(t){return this.makeRequest(F.GET_BATCH_DATA+"?batch_id="+t)}}(d);!function(t){t[t.API_FUNCTION_TEMPORARILY_DISABLED=0]="API_FUNCTION_TEMPORARILY_DISABLED",t[t.BATCH_CREATION_FAILURE=1]="BATCH_CREATION_FAILURE",t[t.BATCH_FULL=2]="BATCH_FULL",t[t.BATCH_NOT_READY=3]="BATCH_NOT_READY",t[t.CONFLICTING_ORDER_AMOUNTS=4]="CONFLICTING_ORDER_AMOUNTS",t[t.FACT_NOT_REGISTERED=5]="FACT_NOT_REGISTERED",t[t.INSUFFICIENT_ONCHAIN_BALANCE=6]="INSUFFICIENT_ONCHAIN_BALANCE",t[t.INVALID_BATCH_ID=7]="INVALID_BATCH_ID",t[t.INVALID_CLAIM_HASH=8]="INVALID_CLAIM_HASH",t[t.INVALID_COMMITTEE_MEMBER=9]="INVALID_COMMITTEE_MEMBER",t[t.INVALID_CONTRACT_ADDRESS=10]="INVALID_CONTRACT_ADDRESS",t[t.INVALID_CONTRACT_RESPONSE=11]="INVALID_CONTRACT_RESPONSE",t[t.INVALID_DEPLOYMENT_INFO=12]="INVALID_DEPLOYMENT_INFO",t[t.INVALID_ETH_ADDRESS=13]="INVALID_ETH_ADDRESS",t[t.INVALID_FACT=14]="INVALID_FACT",t[t.INVALID_FEE_TAKEN=15]="INVALID_FEE_TAKEN",t[t.INVALID_ORDER_ID=16]="INVALID_ORDER_ID",t[t.INVALID_ORDER_TYPE=17]="INVALID_ORDER_TYPE",t[t.INVALID_REQUEST=18]="INVALID_REQUEST",t[t.INVALID_REQUEST_PARAMETERS=19]="INVALID_REQUEST_PARAMETERS",t[t.INVALID_SETTLEMENT_INFO=20]="INVALID_SETTLEMENT_INFO",t[t.INVALID_SETTLEMENT_RATIO=21]="INVALID_SETTLEMENT_RATIO",t[t.INVALID_SETTLEMENT_TOKENS=22]="INVALID_SETTLEMENT_TOKENS",t[t.INVALID_SIGNATURE=23]="INVALID_SIGNATURE",t[t.INVALID_TRANSACTION=24]="INVALID_TRANSACTION",t[t.INVALID_TRANSACTION_ID=25]="INVALID_TRANSACTION_ID",t[t.INVALID_VAULT=26]="INVALID_VAULT",t[t.MALFORMED_REQUEST=27]="MALFORMED_REQUEST",t[t.MIGRATED_PIPELINE_OBJECT_MISSING=28]="MIGRATED_PIPELINE_OBJECT_MISSING",t[t.MISSING_FEE_OBJECT=29]="MISSING_FEE_OBJECT",t[t.ORDER_OVERDUE=30]="ORDER_OVERDUE",t[t.OUT_OF_RANGE_AMOUNT=32]="OUT_OF_RANGE_AMOUNT",t[t.OUT_OF_RANGE_BALANCE=33]="OUT_OF_RANGE_BALANCE",t[t.OUT_OF_RANGE_BATCH_ID=34]="OUT_OF_RANGE_BATCH_ID",t[t.OUT_OF_RANGE_ETH_ADDRESS=35]="OUT_OF_RANGE_ETH_ADDRESS",t[t.OUT_OF_RANGE_EXPIRATION_TIMESTAMP=36]="OUT_OF_RANGE_EXPIRATION_TIMESTAMP",t[t.OUT_OF_RANGE_NONCE=37]="OUT_OF_RANGE_NONCE",t[t.OUT_OF_RANGE_ORACLE_PRICE_QUORUM=38]="OUT_OF_RANGE_ORACLE_PRICE_QUORUM",t[t.OUT_OF_RANGE_ORDER_ID=39]="OUT_OF_RANGE_ORDER_ID",t[t.OUT_OF_RANGE_POSITIVE_AMOUNT=31]="OUT_OF_RANGE_POSITIVE_AMOUNT",t[t.OUT_OF_RANGE_PUBLIC_KEY=40]="OUT_OF_RANGE_PUBLIC_KEY",t[t.OUT_OF_RANGE_SIGNATURE_SUBFIELD=41]="OUT_OF_RANGE_SIGNATURE_SUBFIELD",t[t.OUT_OF_RANGE_TOKEN_ID=42]="OUT_OF_RANGE_TOKEN_ID",t[t.OUT_OF_RANGE_VAULT_ID=43]="OUT_OF_RANGE_VAULT_ID",t[t.REPLACED_BEFORE=44]="REPLACED_BEFORE",t[t.REQUEST_FAILED=45]="REQUEST_FAILED",t[t.SCHEMA_VALIDATION_ERROR=46]="SCHEMA_VALIDATION_ERROR",t[t.TRANSACTION_CANCELLED=47]="TRANSACTION_CANCELLED",t[t.TRANSACTION_PENDING=48]="TRANSACTION_PENDING"}(V||(V={}));var M,m,B,x,H=function(){function t(t){this.gateway=new b(t),this.feederGateway=new G(t)}return t.StarkErrorCode=V,t.GatewayRequestType=R,t}();M="@starkware-industries/starkex-js",m="0.1.0",B="#734d7e",x=function(t){return o(t).getLevel()}(),i(o().INFO),o().log("%c "+M+" v"+m,"color: "+(B||"#ff98f9")+"; font-size: large"),i(x);const k=H})(),module.exports=r.default})();