rango-sdk
Version:
Rango Exchange SDK for dApps
3 lines (2 loc) • 16.5 kB
JavaScript
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("uuid-random")),r=t(require("axios"));function n(t,e,r,n,i,a,o){try{var s=t[a](o),c=s.value}catch(t){return void r(t)}s.done?e(c):Promise.resolve(c).then(n,i)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(i,a){var o=t.apply(e,r);function s(t){n(o,i,a,s,c,"next",t)}function c(t){n(o,i,a,s,c,"throw",t)}s(void 0)}))}}function a(){return(a=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(null,arguments)}function o(){o=function(){return e};var t,e={},r=Object.prototype,n=r.hasOwnProperty,i=Object.defineProperty||function(t,e,r){t[e]=r.value},a="function"==typeof Symbol?Symbol:{},s=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",u=a.toStringTag||"@@toStringTag";function p(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(t){p=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var a=Object.create((e&&e.prototype instanceof x?e:x).prototype),o=new K(n||[]);return i(a,"_invoke",{value:O(t,r,o)}),a}function f(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}e.wrap=h;var l="suspendedStart",y="executing",v="completed",d={};function x(){}function g(){}function m(){}var T={};p(T,s,(function(){return this}));var w=Object.getPrototypeOf,S=w&&w(w(L([])));S&&S!==r&&n.call(S,s)&&(T=S);var k=m.prototype=x.prototype=Object.create(T);function b(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function E(t,e){function r(i,a,o,s){var c=f(t[i],t,a);if("throw"!==c.type){var u=c.arg,p=u.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,o,s)}),(function(t){r("throw",t,o,s)})):e.resolve(p).then((function(t){u.value=t,o(u)}),(function(t){return r("throw",t,o,s)}))}s(c.arg)}var a;i(this,"_invoke",{value:function(t,n){function i(){return new e((function(e,i){r(t,n,e,i)}))}return a=a?a.then(i,i):i()}})}function O(e,r,n){var i=l;return function(a,o){if(i===y)throw Error("Generator is already running");if(i===v){if("throw"===a)throw o;return{value:t,done:!0}}for(n.method=a,n.arg=o;;){var s=n.delegate;if(s){var c=I(s,n);if(c){if(c===d)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===l)throw i=v,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=y;var u=f(e,r,n);if("normal"===u.type){if(i=n.done?v:"suspendedYield",u.arg===d)continue;return{value:u.arg,done:n.done}}"throw"===u.type&&(i=v,n.method="throw",n.arg=u.arg)}}}function I(e,r){var n=r.method,i=e.iterator[n];if(i===t)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=t,I(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var a=f(i,e.iterator,r.arg);if("throw"===a.type)return r.method="throw",r.arg=a.arg,r.delegate=null,d;var o=a.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=t),r.delegate=null,d):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function N(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 R(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function K(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(N,this),this.reset(!0)}function L(e){if(e||""===e){var r=e[s];if(r)return r.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,a=function r(){for(;++i<e.length;)if(n.call(e,i))return r.value=e[i],r.done=!1,r;return r.value=t,r.done=!0,r};return a.next=a}}throw new TypeError(typeof e+" is not iterable")}return g.prototype=m,i(k,"constructor",{value:m,configurable:!0}),i(m,"constructor",{value:g,configurable:!0}),g.displayName=p(m,u,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,p(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},e.awrap=function(t){return{__await:t}},b(E.prototype),p(E.prototype,c,(function(){return this})),e.AsyncIterator=E,e.async=function(t,r,n,i,a){void 0===a&&(a=Promise);var o=new E(h(t,r,n,i),a);return e.isGeneratorFunction(r)?o:o.next().then((function(t){return t.done?t.value:o.next()}))},b(k),p(k,u,"Generator"),p(k,s,(function(){return this})),p(k,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),r=[];for(var n in e)r.push(n);return r.reverse(),function t(){for(;r.length;){var n=r.pop();if(n in e)return t.value=n,t.done=!1,t}return t.done=!0,t}},e.values=L,K.prototype={constructor:K,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(R),!e)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var r=this;function i(n,i){return s.type="throw",s.arg=e,r.next=n,i&&(r.method="next",r.arg=t),!!i}for(var a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],s=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var c=n.call(o,"catchLoc"),u=n.call(o,"finallyLoc");if(c&&u){if(this.prev<o.catchLoc)return i(o.catchLoc,!0);if(this.prev<o.finallyLoc)return i(o.finallyLoc)}else if(c){if(this.prev<o.catchLoc)return i(o.catchLoc,!0)}else{if(!u)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return i(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var a=i;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=t,o.arg=e,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(o)},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),d},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),R(r),d}},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 i=n.arg;R(r)}return i}}throw Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:L(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),d}},e}var s,c,u,p,h,f=function(){function t(t,n){this.apiUrl=n||"https://api.rango.exchange",this.apiKey=t;try{if("undefined"!=typeof window){var i=localStorage.getItem("deviceId");if(i)this.deviceId=i;else{var a=e();localStorage.setItem("deviceId",a),this.deviceId=a}}else this.deviceId=e()}catch(t){this.deviceId=e()}this.httpService=r.create({baseURL:this.apiUrl})}var n=t.prototype;return n.getAllMetadata=function(){var t=i(o().mark((function t(e,r){var n,i,s,c,u,p,h,f,l;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return u=a({},e,{blockchains:null==e||null==(n=e.blockchains)?void 0:n.join(),swappers:null==e||null==(i=e.swappers)?void 0:i.join(),swappersGroups:null==e||null==(s=e.swappersGroups)?void 0:s.join(),transactionTypes:null==e||null==(c=e.transactionTypes)?void 0:c.join()}),t.next=3,this.httpService.get("/meta/compact?apiKey="+this.apiKey,a({params:u},r));case 3:return h=function(t){return t.map((function(t){return{blockchain:t.b,symbol:t.s,image:t.i,address:t.a||null,usdPrice:t.p||null,isSecondaryCoin:t.is||!1,coinSource:t.c||null,coinSourceUrl:t.cu||null,name:t.n||null,decimals:t.d,isPopular:t.ip||!1,supportedSwappers:t.ss||[]}}))},f=h((p=t.sent).data.tokens),l=h(p.data.popularTokens),t.abrupt("return",a({},p.data,{tokens:f,popularTokens:l}));case 8:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.getBlockchains=function(){var t=i(o().mark((function t(e){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.get("/meta/blockchains?apiKey="+this.apiKey,a({},e));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.getSwappers=function(){var t=i(o().mark((function t(e){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.get("/meta/swappers?apiKey="+this.apiKey,a({},e));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.getCustomToken=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.get("/meta/custom-token?apiKey="+this.apiKey,a({params:e},r));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.searchCustomTokens=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.get("/meta/token/search?apiKey="+this.apiKey,a({params:e},r));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.getBestRoute=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.post("/routing/best?apiKey="+this.apiKey,e,a({headers:{"X-Rango-Id":this.deviceId}},r));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.getAllRoutes=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.post("/routing/bests?apiKey="+this.apiKey,e,a({headers:{"X-Rango-Id":this.deviceId}},r));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.confirmRoute=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.post("/routing/confirm?apiKey="+this.apiKey,e,a({headers:{"X-Rango-Id":this.deviceId}},r));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.confirmRouteRequest=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.post("/routing/confirm?apiKey="+this.apiKey,e,a({headers:{"X-Rango-Id":this.deviceId}},r));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.checkApproval=function(){var t=i(o().mark((function t(e,r,n){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.get("/tx/"+e+"/check-approval?apiKey="+this.apiKey,a({params:{txId:r}},n));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),n.checkStatus=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.post("/tx/check-status?apiKey="+this.apiKey,e,a({},r));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.createTransaction=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.post("/tx/create?apiKey="+this.apiKey,e,a({},r));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.reportFailure=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.post("/tx/report-tx?apiKey="+this.apiKey,e,a({},r));case 2:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.getWalletsDetails=function(){var t=i(o().mark((function t(e,r){var n,i,s;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(n="",i=0;i<e.length;i++)n+="&address="+(s=e[i]).blockchain+"."+s.address;return t.next=4,this.httpService.get("/wallets/details?apiKey="+this.apiKey+n,a({},r));case 4:return t.abrupt("return",t.sent.data);case 6:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.getTokenBalance=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.get("/wallets/token-balance?apiKey="+this.apiKey,a({params:e},r));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.getMultipleTokenBalance=function(){var t=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.httpService.post("/wallets/multiple-token-balance?apiKey="+this.apiKey,e,a({},r));case 2:return t.abrupt("return",t.sent.data);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),t}(),l=function(t){return"EVM"===t.type},y=function(t){return"COSMOS"===t.type},v=function(t){return"SOLANA"===t.type},d=function(t){return"TRON"===t.type},x=function(t){return"TRANSFER"===t.type},g=function(t){return"STARKNET"===t.type},m=function(t){return"TON"===t.type};(s=exports.RoutingResultType||(exports.RoutingResultType={})).OK="OK",s.HIGH_IMPACT="HIGH_IMPACT",s.NO_ROUTE="NO_ROUTE",s.INPUT_LIMIT_ISSUE="INPUT_LIMIT_ISSUE",s.HIGH_IMPACT_FOR_CREATE_TX="HIGH_IMPACT_FOR_CREATE_TX",(c=exports.TransactionType||(exports.TransactionType={})).EVM="EVM",c.TRANSFER="TRANSFER",c.COSMOS="COSMOS",c.SOLANA="SOLANA",c.TRON="TRON",c.STARKNET="STARKNET",c.TON="TON",c.SUI="SUI",(u=exports.GenericTransactionType||(exports.GenericTransactionType={})).EVM="EVM",u.TRANSFER="TRANSFER",u.COSMOS="COSMOS",u.SOLANA="SOLANA",(p=exports.TransactionStatus||(exports.TransactionStatus={})).FAILED="failed",p.RUNNING="running",p.SUCCESS="success",(h=exports.TonChainID||(exports.TonChainID={})).MAINNET="-239",h.TESTNET="-3",exports.RangoClient=f,exports.cosmosBlockchains=function(t){return t.filter(y)},exports.evmBlockchains=function(t){return t.filter(l)},exports.isCosmosBlockchain=y,exports.isCosmosTransaction=function(t){return t.type===exports.TransactionType.COSMOS},exports.isEvmBlockchain=l,exports.isEvmTransaction=function(t){return t.type===exports.TransactionType.EVM},exports.isSolanaBlockchain=v,exports.isSolanaTransaction=function(t){return t.type===exports.TransactionType.SOLANA},exports.isStarknetBlockchain=g,exports.isTonBlockchain=m,exports.isTonTransaction=function(t){return t.type===exports.TransactionType.TON},exports.isTransferBlockchain=x,exports.isTransferTransaction=function(t){return t.type===exports.TransactionType.TRANSFER},exports.isTronBlockchain=d,exports.isTronTransaction=function(t){return t.type===exports.TransactionType.TRON},exports.solanaBlockchain=function(t){return t.filter(v)},exports.starknetBlockchain=function(t){return t.filter(g)},exports.tonBlockchain=function(t){return t.filter(m)},exports.transferBlockchains=function(t){return t.filter(x)},exports.tronBlockchain=function(t){return t.filter(d)};
//# sourceMappingURL=rango-sdk.cjs.production.min.js.map