UNPKG

@algofi/js-sdk

Version:

The official Algofi JavaScript SDK

1 lines 205 kB
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e,r,s=require("algosdk"),n=t(s),a=t(require("superagent")),i={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(t){var e,r,s,n,a,o,p,d="",u=0;for(t=i._utf8_encode(t);u<t.length;)n=(e=t.charCodeAt(u++))>>2,a=(3&e)<<4|(r=t.charCodeAt(u++))>>4,o=(15&r)<<2|(s=t.charCodeAt(u++))>>6,p=63&s,isNaN(r)?o=p=64:isNaN(s)&&(p=64),d=d+this._keyStr.charAt(n)+this._keyStr.charAt(a)+this._keyStr.charAt(o)+this._keyStr.charAt(p);return d},decode:function(t){var e,r,s,n,a,o,p="",d=0;for(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");d<t.length;)s=this._keyStr.indexOf(t.charAt(d++)),e=(15&(n=this._keyStr.indexOf(t.charAt(d++))))<<4|(a=this._keyStr.indexOf(t.charAt(d++)))>>2,r=(3&a)<<6|(o=this._keyStr.indexOf(t.charAt(d++))),p+=String.fromCharCode(s<<2|n>>4),64!=a&&(p+=String.fromCharCode(e)),64!=o&&(p+=String.fromCharCode(r));return i._utf8_decode(p)},_utf8_encode:function(t){t=t.replace(/\r\n/g,"\n");for(var e="",r=0;r<t.length;r++){var s=t.charCodeAt(r);s<128?e+=String.fromCharCode(s):s>127&&s<2048?(e+=String.fromCharCode(s>>6|192),e+=String.fromCharCode(63&s|128)):(e+=String.fromCharCode(s>>12|224),e+=String.fromCharCode(s>>6&63|128),e+=String.fromCharCode(63&s|128))}return e},_utf8_decode:function(t){for(var e="",r=0,s=0,n=0,a=0;r<t.length;)(s=t.charCodeAt(r))<128?(e+=String.fromCharCode(s),r++):s>191&&s<224?(n=t.charCodeAt(r+1),e+=String.fromCharCode((31&s)<<6|63&n),r+=2):(n=t.charCodeAt(r+1),a=t.charCodeAt(r+2),e+=String.fromCharCode((15&s)<<12|(63&n)<<6|63&a),r+=3);return e}},o=BigInt(1e18),p=new s.LogicSigAccount(new Uint8Array([6,49,16,129,6,18,68,49,25,129,0,18,68,49,9,50,3,18,68,49,32,50,3,18,68,129,1,67])),d=new TextEncoder;function u(t){return t==exports.Network.MAINNET?"https://api.algofi.org":"https://api-dev.algofi.org"}function c(t){if(t==exports.Network.MAINNET)return"mainnet";if(t==exports.Network.TESTNET)return"testnet";throw"bad network"}function h(){h=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,s="function"==typeof Symbol?Symbol:{},n=s.iterator||"@@iterator",a=s.asyncIterator||"@@asyncIterator",i=s.toStringTag||"@@toStringTag";function o(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{o({},"")}catch(t){o=function(t,e,r){return t[e]=r}}function p(t,e,r,s){var n=Object.create((e&&e.prototype instanceof c?e:c).prototype),a=new y(s||[]);return n._invoke=function(t,e,r){var s="suspendedStart";return function(n,a){if("executing"===s)throw new Error("Generator is already running");if("completed"===s){if("throw"===n)throw a;return{value:void 0,done:!0}}for(r.method=n,r.arg=a;;){var i=r.delegate;if(i){var o=I(i,r);if(o){if(o===u)continue;return o}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===s)throw s="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);s="executing";var p=d(t,e,r);if("normal"===p.type){if(s=r.done?"completed":"suspendedYield",p.arg===u)continue;return{value:p.arg,done:r.done}}"throw"===p.type&&(s="completed",r.method="throw",r.arg=p.arg)}}}(t,r,a),n}function d(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=p;var u={};function c(){}function l(){}function g(){}var f={};o(f,n,(function(){return this}));var A=Object.getPrototypeOf,m=A&&A(A(S([])));m&&m!==e&&r.call(m,n)&&(f=m);var v=g.prototype=c.prototype=Object.create(f);function w(t){["next","throw","return"].forEach((function(e){o(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){var s;this._invoke=function(n,a){function i(){return new e((function(s,i){!function s(n,a,i,o){var p=d(t[n],t,a);if("throw"!==p.type){var u=p.arg,c=u.value;return c&&"object"==typeof c&&r.call(c,"__await")?e.resolve(c.__await).then((function(t){s("next",t,i,o)}),(function(t){s("throw",t,i,o)})):e.resolve(c).then((function(t){u.value=t,i(u)}),(function(t){return s("throw",t,i,o)}))}o(p.arg)}(n,a,s,i)}))}return s=s?s.then(i,i):i()}}function I(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,I(t,e),"throw"===e.method))return u;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return u}var s=d(r,t.iterator,e.arg);if("throw"===s.type)return e.method="throw",e.arg=s.arg,e.delegate=null,u;var n=s.arg;return n?n.done?(e[t.resultName]=n.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,u):n:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,u)}function x(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 T(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function y(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function S(t){if(t){var e=t[n];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var s=-1,a=function e(){for(;++s<t.length;)if(r.call(t,s))return e.value=t[s],e.done=!1,e;return e.value=void 0,e.done=!0,e};return a.next=a}}return{next:P}}function P(){return{value:void 0,done:!0}}return l.prototype=g,o(v,"constructor",g),o(g,"constructor",l),l.displayName=o(g,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,g):(t.__proto__=g,o(t,i,"GeneratorFunction")),t.prototype=Object.create(v),t},t.awrap=function(t){return{__await:t}},w(k.prototype),o(k.prototype,a,(function(){return this})),t.AsyncIterator=k,t.async=function(e,r,s,n,a){void 0===a&&(a=Promise);var i=new k(p(e,r,s,n),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},w(v),o(v,i,"Generator"),o(v,n,(function(){return this})),o(v,"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 s=e.pop();if(s in t)return r.value=s,r.done=!1,r}return r.done=!0,r}},t.values=S,y.prototype={constructor:y,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(T),!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 s(r,s){return i.type="throw",i.arg=t,e.next=r,s&&(e.method="next",e.arg=void 0),!!s}for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n],i=a.completion;if("root"===a.tryLoc)return s("end");if(a.tryLoc<=this.prev){var o=r.call(a,"catchLoc"),p=r.call(a,"finallyLoc");if(o&&p){if(this.prev<a.catchLoc)return s(a.catchLoc,!0);if(this.prev<a.finallyLoc)return s(a.finallyLoc)}else if(o){if(this.prev<a.catchLoc)return s(a.catchLoc,!0)}else{if(!p)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return s(a.finallyLoc)}}}},abrupt:function(t,e){for(var s=this.tryEntries.length-1;s>=0;--s){var n=this.tryEntries[s];if(n.tryLoc<=this.prev&&r.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var a=n;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,u):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),u},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),T(r),u}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var s=r.completion;if("throw"===s.type){var n=s.arg;T(r)}return n}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:S(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),u}},t}function l(t,e,r,s,n,a,i){try{var o=t[a](i),p=o.value}catch(t){return void r(t)}o.done?e(p):Promise.resolve(p).then(s,n)}function g(t){return function(){var e=this,r=arguments;return new Promise((function(s,n){var a=t.apply(e,r);function i(t){l(a,s,n,i,o,"next",t)}function o(t){l(a,s,n,i,o,"throw",t)}i(void 0)}))}}function f(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,s=new Array(e);r<e;r++)s[r]=t[r];return s}function A(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(r)return(r=r.call(t)).next.bind(r);if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return f(t,void 0);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?f(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var s=0;return function(){return s>=t.length?{done:!0}:{done:!1,value:t[s++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function m(t,e){return Math.ceil(t*Math.pow(10,e))/Math.pow(10,e)}function v(t){var e=t.reduce((function(t,e){return t+e.length}),0);if(!t.length)return null;for(var r,s=new Uint8Array(e),n=0,a=A(t);!(r=a()).done;){var i=r.value;s.set(i,n),n+=i.length}return s}function w(t){for(var e={},r=0,s=Object.entries(t);r<s.length;r++){var n=s[r],a=n[0],i=n[1],o=a.indexOf("_");if(o>0){var p=a.substring(0,o+1),d=a.substring(o+1);e[p+Uint8Array.from(d,(function(t){return t.charCodeAt(0)}))[7].toString()]=i}else e[a]=i}return e}function k(t){return s.encodeAddress(Buffer.from(t,"base64"))}function I(t){for(var e=new Uint8Array(t.length),r=0;r<t.length;++r)e[r]=t.charCodeAt(r);return e}function x(t){for(var e,r=[],n=A(t);!(e=n()).done;)for(var a,i=A(e.value);!(a=i()).done;)r.push(a.value);for(var o=0,p=r;o<p.length;o++)p[o].group=void 0;return s.assignGroupID(r)}(e=exports.Network||(exports.Network={}))[e.MAINNET=0]="MAINNET",e[e.TESTNET=1]="TESTNET",(r=exports.TxnLoadMode||(exports.TxnLoadMode={}))[r.REFRESH=0]="REFRESH",r[r.REVERSE=1]="REVERSE";var T=function(t,e,r,s,n,a,i){this.transactionId=t.id,this.groupId=t.group,this.block=t["confirmed-round"],this.time=t["round-time"],this.protocol=e,this.app=r,this.action=s,this.params=n;for(var o=0,p=Object.entries(a);o<p.length;o++){var d=p[o],u=d[0];u in i&&d[1]>i[u]&&(a[u]-=i[u],delete i[u])}this.assetsIn=a,this.assetsOut=i};function y(t,e){return S.apply(this,arguments)}function S(){return(S=g(h().mark((function t(e,r){var s,n;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.getApplicationByID(r).do();case 2:return s=t.sent,n={},t.next=6,Promise.all(s.params["global-state"].map(function(){var t=g(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:n[i.decode(e.key)]=1==e.value.type?e.value.bytes:e.value.uint;case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 6:return t.abrupt("return",n);case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function P(t){return b.apply(this,arguments)}function b(){return(b=g(h().mark((function t(e){var r;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r={},t.next=3,Promise.all(e["apps-local-state"].map(function(){var t=g(h().mark((function t(e){var s;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e["key-value"]){t.next=7;break}return s={},t.next=4,Promise.all(e["key-value"].map(function(){var t=g(h().mark((function t(e){var r;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r=i.decode(e.key),s[r]=1==e.value.type?e.value.bytes:e.value.uint;case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 4:r[e.id]=s,t.next=8;break;case 7:r[e.id]={};case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 3:return t.abrupt("return",r);case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function O(t,e){return C.apply(this,arguments)}function C(){return(C=g(h().mark((function t(e,r){var s,n;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return s={},t.next=3,e.accountInformation(r).do();case 3:return n=t.sent,t.next=6,Promise.all(n["apps-local-state"].map(function(){var t=g(h().mark((function t(e){var r;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!e["key-value"]){t.next=7;break}return r={},t.next=4,Promise.all(e["key-value"].map(function(){var t=g(h().mark((function t(e){var s;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:s=i.decode(e.key),r[s]=1==e.value.type?e.value.bytes:e.value.uint;case 2:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 4:s[e.id]=r,t.next=8;break;case 7:s[e.id]={};case 8:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 6:return t.abrupt("return",s);case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function N(t){return L.apply(this,arguments)}function L(){return(L=g(h().mark((function t(e){var r;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return(r={})[1]=e.amount,t.next=4,Promise.all(e.assets.map(function(){var t=g(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:r[e["asset-id"]]=e.amount;case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 4:return t.abrupt("return",r);case 5:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function D(t,e){return F.apply(this,arguments)}function F(){return(F=g(h().mark((function t(e,r){var s,n;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return s={},t.next=3,e.accountInformation(r).do();case 3:return s[1]=(n=t.sent).amount,t.next=7,Promise.all(n.assets.map(function(){var t=g(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:s[e["asset-id"]]=e.amount;case 1:case"end":return t.stop()}}),t)})));return function(e){return t.apply(this,arguments)}}()));case 7:return t.abrupt("return",s);case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function B(t){return E.apply(this,arguments)}function E(){return(E=g(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e["min-balance"]);case 1:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function M(t,e){return R.apply(this,arguments)}function R(){return(R=g(h().mark((function t(e,r){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.accountInformation(r).do();case 2:return t.abrupt("return",t.sent["min-balance"]);case 4:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function U(t,e){"pay"==t["tx-type"]?e[1]=t["payment-transaction"].amount:"axfer"==t["tx-type"]&&(e[t["asset-transfer-transaction"]["asset-id"]]=t["asset-transfer-transaction"].amount)}var _,j,G,V=function(){function t(t,e){this.v2=t.lending.v2.getUser(e)}return t.prototype.loadState=function(){var t=g(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.v2.loadState(e);case 2:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(),K=function(){function t(t,e){this.v1=t.staking.v1.getUser(e),this.v2=t.staking.v2.getUser(e)}return t.prototype.loadState=function(){var t=g(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.v1.loadState(e);case 2:return t.next=4,this.v2.loadState(e);case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(),Q=function(){function t(t,e){this.v1=t.governance.v1.getUser(e),this.network=t.network}return t.prototype.loadState=function(){var t=g(h().mark((function t(e){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.v1.loadState(e);case 2:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(),W=function(){function t(t,e){this.balances={},this.algofiClient=t,this.algod=this.algofiClient.algod,this.indexer=this.algofiClient.indexer,this.address=e,this.lending=new V(this.algofiClient,this.address),this.staking=new K(this.algofiClient,this.address),this.governance=new Q(this.algofiClient,this.address)}var e=t.prototype;return e.loadState=function(){var t=g(h().mark((function t(){var e,r,s,n,a;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.algod.accountInformation(this.address).do();case 2:return e=t.sent,t.next=5,P(e);case 5:return r=t.sent,t.next=8,N(e);case 8:return this.balances=t.sent,t.next=11,B(e);case 11:return this.minBalance=t.sent,s=this.lending.loadState(r),n=this.staking.loadState(r),a=this.governance.loadState(r),t.next=17,Promise.all([s,n,a]);case 17:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.isOptedInToAsset=function(t){return t in this.balances},e.getTransactionHistory=function(){var t=g(h().mark((function t(e){var r,s,n;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r={},e==exports.TxnLoadMode.REFRESH&&(this.transactions=[]),!(e==exports.TxnLoadMode.REVERSE&&this.transactions.length>0)){t.next=9;break}return t.next=6,this.indexer.lookupAccountTransactions(this.address).maxRound(this.transactions.slice(-1)[0].block).limit(500).do();case 6:r=t.sent,t.next=12;break;case 9:return t.next=11,this.indexer.lookupAccountTransactions(this.address).limit(500).do();case 11:r=t.sent;case 12:for(s=0;s<r.transactions.length;s++)"appl"==(n=r.transactions[s])["tx-type"]&&(this.algofiClient.lending.v2.isLendingTransaction(n)?this.lending.v2.parseTransaction(r.transactions,s,this.transactions):this.algofiClient.amm.v1.isAMMTransaction(n)&&this.algofiClient.amm.v1.parseTransaction(r.transactions,s,this.transactions));case 13:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(),Y=function(t,e,r,s,n){this.name=t,this.unitName=e,this.assetId=r,this.decimals=s,this.defaultPrice=n},H=((_={})[exports.Network.MAINNET]={1:new Y("ALGO","ALGO",1,6,void 0),818179690:new Y("AF-BANK-ALGO-STANDARD","AF-BANK",818179690,6,void 0),31566704:new Y("USDC","USDC",31566704,6,1),818182311:new Y("AF-BANK-USDC-STANDARD","AF-BANK",818182311,6,void 0),386192725:new Y("goBTC","goBTC",386192725,8,void 0),818184214:new Y("AF-BANK-GOBTC-STANDARD","AF-BANK",818184214,6,void 0),386195940:new Y("goETH","goETH",386195940,8,void 0),818188553:new Y("AF-BANK-GOETH-STANDARD","AF-BANK",818188553,6,void 0),312769:new Y("USDT","USDT",312769,6,1),818190568:new Y("AF-BANK-USDT-STANDARD","AF-BANK",818190568,6,void 0),841126810:new Y("STBL2","STBL2",841126810,6,1),841157954:new Y("AF-BANK_STBL2-STABLE","AF-BANK",841157954,6,void 0),879951266:new Y("AF-BANK-ALGO-VAULT","AF-BANK",879951266,6,void 0),900652777:new Y("BANK","BANK",900652777,6,void 0),900919286:new Y("AF-BANK-BANK-STANDARD","AF-BANK",900919286,6,void 0),841171328:new Y("AF-USDC-STBL2-NANO-LP","AF-POOL",841171328,6,void 0),841462373:new Y("AF-BANK-AF-POOL-LP","AF-BANK",841462373,6,void 0),855717054:new Y("AF-ALGO-STBL2-0.25%-LP","AF-POOL",855717054,6,void 0),856217307:new Y("AF-BANK-AF-POOL-LP","AF-POOL",856217307,6,void 0),870151164:new Y("AF-goBTC-STBL2-0.25%-LP","AF-POOL",870151164,6,void 0),870380101:new Y("AF-BANK-AF-POOL-LP","AF-POOL",870380101,6,void 0),870150187:new Y("AF-goETH-STBL2-0.25%-LP","AF-POOL",870150187,6,void 0),870391958:new Y("AF-BANK-AF-POOL-LP","AF-POOL",870391958,6,void 0),465865291:new Y("STBL","STBL",465865291,6,void 0),470842789:new Y("DEFLY","DEFLY",470842789,6,void 0),283820866:new Y("XET","XET",283820866,9,void 0),287867876:new Y("OPUL","OPUL",287867876,10,void 0),444035862:new Y("ZONE","ZONE",444035862,6,void 0),467020179:new Y("TM-STBL-USDC-v1-LP","TM1POOL",467020179,6,1),552737686:new Y("TM-STBL-USDC-v1.1-LP","TMPOOL11",552737686,6,1),607645566:new Y("AF-STBL-ALGO-0.25%-LP","AF-BANK",607645566,6,void 0),609172718:new Y("AF-STBL-USDC-0.25%-LP","AF-BANK",609172718,6,void 0),658337286:new Y("AF-STBL-USDC-NANO-LP","AF-BANK",658337286,6,void 0),659678778:new Y("AF-USDC-USDT-NANO-LP","AF-BANK",659678778,6,void 0),659677515:new Y("AF-STBL-USDT-NANO-LP","AF-BANK",659677515,6,void 0),635256863:new Y("AF-STBL-XET-0.75%-LP","AF-BANK",635256863,6,void 0),647801343:new Y("AF-STBL-ZONE-0.75%-LP","AF-BANK",647801343,6,void 0),624956449:new Y("AF-STBL-DEFLY-0.75%-LP","AF-BANK",624956449,6,void 0),635846733:new Y("AF-STBL-goBTC-0.25%-LP","AF-BANK",635846733,6,void 0),635854339:new Y("AF-STBL-goETH-0.25%-LP","AF-BANK",635854339,6,void 0),637802380:new Y("AF-STBL-OPUL-0.75%-LP","AF-BANK",637802380,6,void 0),900924035:new Y("AF-STBL2-BANK-0.25%-LP","AF-BANK",900924035,6,void 0),919950894:new Y("AF-ALGO-USDC-0.25%-LP","AF-BANK",919950894,6,void 0),962367827:new Y("AF-ALGO-BANK-0.25%-LP","AF-BANK",962367827,6,void 0)},_[exports.Network.TESTNET]={1:new Y("ALGO","ALGO",1,6,void 0),107212062:new Y("BANK","BANK",107212062,6,.2),104193939:new Y("AF-BANK-ALGO-STANDARD","AF-BANK",104193939,6,void 0),104194013:new Y("USDC","USDC",104194013,6,void 0),104207173:new Y("AF-BANK-USDC-STANDARD","AF-BANK",104207173,6,void 0),104207287:new Y("goBTC","goBTC",104207287,8,void 0),104207503:new Y("AF-BANK-GOBTC-STANDARD","AF-BANK",104207503,6,void 0),104207533:new Y("goETH","goETH",104207533,8,void 0),104207983:new Y("AF-BANK-GOETH-STANDARD","AF-BANK",104207983,6,void 0),104208050:new Y("USDT","USDT",104208050,6,void 0),104222974:new Y("AF-BANK-USDT-STANDARD","AF-BANK",104222974,6,void 0),104210500:new Y("STBL2","STBL2",104210500,6,void 0),104217422:new Y("AF-BANK-STBL2-STABLE","AF-BANK",104217422,6,void 0),104228491:new Y("AF-bUSDC-bSTBL2-NANO-LP","AF-POOL",104228491,6,void 0),104238470:new Y("AF-BANK-AF-bUSDC-bSTBL2-NANO-LP-LP","AF-BANK",104238470,6,void 0)},_),X=function(t,e,r,s,n){this.assetId=t,this.name=e,this.unitName=r,this.decimals=s,this.price=n},z=function(){function t(t,e){this.amount=t,this.assetData=e}var e=t.prototype;return e.toUSD=function(){return this.assetData.price&&0!=this.assetData.price?this.amount*this.assetData.price/Math.pow(10,this.assetData.decimals):(console.log("Error: unable to get dollarized price for asset:",this.assetData),0)},e.toDisplayAmount=function(t){return void 0===t&&(t=!1),t?m(this.amount/Math.pow(10,this.assetData.decimals),this.assetData.decimals):(e=this.amount/Math.pow(10,this.assetData.decimals),r=this.assetData.decimals,Math.floor(e*Math.pow(10,r))/Math.pow(10,r));var e,r},t}(),q=function(){function t(t){this.assets={},this.algofiClient=t,this.algod=this.algofiClient.algod,this.network=this.algofiClient.network,this.assetConfigs=H[this.network]}var e=t.prototype;return e.loadState=function(){var t=g(h().mark((function t(){var e,r,s,n,i,o,p,d=this;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(e=0,r=Object.values(this.assetConfigs);e<r.length;e++)(s=r[e]).assetId in this.assets||(this.assets[s.assetId]=new X(s.assetId,s.name,s.unitName,s.decimals,s.defaultPrice));return n=u(this.network),i=c(this.network),o=a.get(n+"/assets?network="+i).then((function(t){if(200==t.status)for(var e,r=A(t.body);!(e=r()).done;){var s=e.value;d.assets[s.asset_id]=new X(s.asset_id,s.name,s.unit_name,s.decimals,s.price)}else console.log("Bad Response")})).catch((function(t){console.log(t.message)})),p=a.get(n+"/ammLPTokens?network="+i).then((function(t){if(200==t.status)for(var e,r=A(t.body);!(e=r()).done;){var s=e.value;s.asset_id in d.assets?d.assets[s.asset_id].price=s.price:d.assets[s.asset_id]=new X(s.asset_id,s.name,s.unit_name,s.decimals,s.price)}else console.log("Bad Response")})).catch((function(t){console.log(t.message)})),t.next=7,Promise.all([o,p]);case 7:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.loadLendingAssetState=function(){var t=g(h().mark((function t(){var e,r,s,n,a;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:for(e=0,r=Object.entries(this.algofiClient.lending.v2.markets);e<r.length;e++)900652777!=(n=this.assetConfigs[(s=r[e][1]).underlyingAssetId]).assetId&&(this.assets[n.assetId]=new X(n.assetId,n.name,n.unitName,n.decimals,s.oracle.price)),this.assets[(a=this.assetConfigs[s.bAssetId]).assetId]=new X(a.assetId,a.name,a.unitName,a.decimals,s.bAssetToUnderlying(Math.pow(10,a.decimals)).toUSD());case 1:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.getAsset=function(t,e){return new z(t,this.assets[e])},e.getAssetFromDisplayAmount=function(t,e){var r=this.assets[e];return new z(Math.floor(t*Math.pow(10,r.decimals)),r)},e.getAssetFromUSDAmount=function(t,e){var r=this.assets[e];return new z(Math.floor(t*Math.pow(10,r.decimals)/r.price),r)},e.loadAsset=function(){var t=g(h().mark((function t(e,r){var s;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r in this.assets){t.next=5;break}return t.next=3,this.algod.getAssetByID(r).do();case 3:this.assets[r]=new X(r,(s=t.sent).params.name,s.params["unit-name"],s.params.decimals,0);case 5:return t.abrupt("return",this.getAsset(e,r));case 6:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),t}(),Z=function(t){this.appId=t},J=((j={})[exports.Network.MAINNET]=new Z(818176933),j[exports.Network.TESTNET]=new Z(104184985),j);(G=exports.MarketType||(exports.MarketType={}))[G.STANDARD=0]="STANDARD",G[G.STBL=1]="STBL",G[G.VAULT=2]="VAULT",G[G.LP=3]="LP";var $,tt=function(t,e,r,s){this.appId=t,this.underlyingAssetId=e,this.bAssetId=r,this.marketType=s},et=(($={})[exports.Network.MAINNET]=[new tt(818179346,1,818179690,exports.MarketType.STANDARD),new tt(818182048,31566704,818182311,exports.MarketType.STANDARD),new tt(818183964,386192725,818184214,exports.MarketType.STANDARD),new tt(818188286,386195940,818188553,exports.MarketType.STANDARD),new tt(818190205,312769,818190568,exports.MarketType.STANDARD),new tt(841145020,841126810,841157954,exports.MarketType.STBL),new tt(841194726,841171328,841462373,exports.MarketType.LP),new tt(856183130,855717054,856217307,exports.MarketType.LP),new tt(870271921,870151164,870380101,exports.MarketType.LP),new tt(870275741,870150187,870391958,exports.MarketType.LP),new tt(879935316,1,879951266,exports.MarketType.VAULT),new tt(900883415,900652777,900919286,exports.MarketType.STANDARD)],$[exports.Network.TESTNET]=[new tt(104193717,1,104193939,exports.MarketType.STANDARD),new tt(104207076,104194013,104207173,exports.MarketType.STANDARD),new tt(104209685,104208050,104222974,exports.MarketType.STANDARD),new tt(104207403,104207287,104207503,exports.MarketType.STANDARD),new tt(104207719,104207533,104207983,exports.MarketType.STANDARD),new tt(104213311,104210500,104217422,exports.MarketType.STBL),new tt(104238373,104228491,104238470,exports.MarketType.LP)],$);function rt(t){return st.apply(this,arguments)}function st(){return(st=g(h().mark((function t(e){var r;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.getTransactionParams().do();case 2:return(r=t.sent).fee=1e3,r.flatFee=!0,t.abrupt("return",r);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function nt(t,e,r,s,a){return 1==s?n.makePaymentTxnWithSuggestedParamsFromObject({from:e,to:r,amount:a,suggestedParams:t,rekeyTo:void 0}):n.makeAssetTransferTxnWithSuggestedParamsFromObject({from:e,to:r,amount:a,assetIndex:s,suggestedParams:t,rekeyTo:void 0,revocationTarget:void 0})}var at,it,ot,pt,dt=function(){function t(t,e){this.localMinBalance=614e3,this.algod=t,this.appId=e,this.address=s.getApplicationAddress(this.appId)}var e=t.prototype;return e.getOptInTxns=function(){var t=g(h().mark((function t(e,r){var a,i,o,p;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,rt(this.algod);case 2:return i=nt(a=t.sent,e.address,r.addr,1,this.localMinBalance+101e3),o=n.makeApplicationOptInTxnFromObject({from:r.addr,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("saoi")],accounts:void 0,foreignApps:void 0,foreignAssets:void 0,rekeyTo:this.address}),p=n.makeApplicationOptInTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("uoi")],accounts:[r.addr],foreignApps:void 0,foreignAssets:void 0,rekeyTo:void 0}),t.abrupt("return",s.assignGroupID([i,o,p]));case 7:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getOptOutTxns=function(){var t=g(h().mark((function t(e){var r,a,i,o;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,rt(this.algod);case 2:return(r=t.sent).fee=2e3,a=n.makeApplicationCloseOutTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:r,appArgs:void 0,accounts:[e.lending.v2.storageAddress],foreignApps:void 0,foreignAssets:void 0,rekeyTo:void 0}),r.fee=1e3,i=n.makeApplicationClearStateTxnFromObject({from:e.lending.v2.storageAddress,appIndex:this.appId,suggestedParams:r,appArgs:void 0,accounts:void 0,foreignApps:void 0,foreignAssets:void 0,rekeyTo:void 0}),r.fee=1e3,o=n.makePaymentTxnWithSuggestedParamsFromObject({from:e.lending.v2.storageAddress,to:e.lending.v2.storageAddress,amount:0,suggestedParams:r,rekeyTo:void 0,closeRemainderTo:e.address}),t.abrupt("return",s.assignGroupID([a,i,o]));case 10:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getMarketOptInTxns=function(){var t=g(h().mark((function t(e,r){var a,i,o,p;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,rt(this.algod);case 2:return i=nt(a=t.sent,e.address,e.lending.v2.storageAddress,1,r.localMinBalance),o=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("vm")],accounts:[r.address],foreignApps:[r.appId],foreignAssets:void 0,rekeyTo:void 0}),a.fee=2e3,p=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("umoi")],accounts:[e.lending.v2.storageAddress],foreignApps:[r.appId],foreignAssets:void 0,rekeyTo:void 0}),t.abrupt("return",s.assignGroupID([i,o,p]));case 8:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getMarketOptOutTxns=function(){var t=g(h().mark((function t(e,r){var a,i,o,p,u;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,rt(this.algod);case 2:return a=t.sent,i=e.lending.v2.getMarketPageOffset(r.appId),o=i[0],p=i[1],a.fee=3e3,u=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("umco"),v([s.encodeUint64(o),s.encodeUint64(p)])],accounts:[e.lending.v2.storageAddress],foreignApps:[r.appId],foreignAssets:void 0,rekeyTo:void 0}),t.abrupt("return",[u]);case 7:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getGovernanceTxns=function(){var t=g(h().mark((function t(e,r,a){var i,o;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,rt(this.algod);case 2:return(i=t.sent).fee=2e3,o=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:i,appArgs:[d.encode("sgt")],accounts:[e.lending.v2.storageAddress,r],foreignApps:void 0,foreignAssets:void 0,rekeyTo:void 0,note:d.encode(a)}),t.abrupt("return",s.assignGroupID([o]));case 6:case"end":return t.stop()}}),t,this)})));return function(e,r,s){return t.apply(this,arguments)}}(),e.getKeyregTxns=function(){var t=g(h().mark((function t(e,r,a,i,o,u,c){var l,g,f;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,rt(this.algod);case 2:return(l=t.sent).fee=3e3,g=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:l,appArgs:[d.encode("vsat")],accounts:[e.lending.v2.storageAddress],foreignApps:void 0,foreignAssets:void 0,rekeyTo:void 0}),l.fee=0,f=n.makeApplicationNoOpTxnFromObject({from:p.lsig.address(),appIndex:this.appId,suggestedParams:l,appArgs:[d.encode("skt"),new Uint8Array(Buffer.from(r,"base64")),new Uint8Array(Buffer.from(a,"base64")),new Uint8Array(Buffer.from(i,"base64")),s.encodeUint64(o),s.encodeUint64(u),s.encodeUint64(c)],accounts:[e.lending.v2.storageAddress],foreignApps:void 0,foreignAssets:void 0,rekeyTo:void 0}),t.abrupt("return",s.assignGroupID([g,f]));case 8:case"end":return t.stop()}}),t,this)})));return function(e,r,s,n,a,i,o){return t.apply(this,arguments)}}(),e.getKeyregOfflineTxns=function(){var t=g(h().mark((function t(e){var r,a;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,rt(this.algod);case 2:return(r=t.sent).fee=2e3,a=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:r,appArgs:[d.encode("skot")],accounts:[e.lending.v2.storageAddress],foreignApps:void 0,foreignAssets:void 0,rekeyTo:void 0}),t.abrupt("return",s.assignGroupID([a]));case 6:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(),ut=function(){function t(t,e,r,s,n){this.algod=t,this.appId=e,this.priceFieldName=r,this.scaleFactor=s,this.underlyingAssetDecimals=n}return t.prototype.loadPrice=function(){var t=g(h().mark((function t(){return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,y(this.algod,this.appId);case 2:this.rawPrice=t.sent[this.priceFieldName],this.price=this.rawPrice*this.underlyingAssetDecimals/(1e3*this.scaleFactor);case 5:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),t}(),ct=function(){function t(t,e,r){this.market=t;var n=Buffer.from(e["rps_"+String.fromCharCode.apply(null,s.encodeUint64(r))],"base64").toString("binary");this.programNumber=s.decodeUint64(I(n.substr(0,8)),"safe"),this.rewardsPerSecond=s.decodeUint64(I(n.substr(8,8)),"safe"),this.assetID=s.decodeUint64(I(n.substr(16,8)),"safe"),this.issued=s.decodeUint64(I(n.substr(24,8)),"safe"),this.claimed=s.decodeUint64(I(n.substr(32,8)),"safe");var a=new Uint8Array(Buffer.from(e["ri_"+String.fromCharCode.apply(null,s.encodeUint64(r))],"base64"));this.index=s.bytesToBigInt(a),this.projectedIndex=t.marketType==exports.MarketType.VAULT||t.marketType==exports.MarketType.LP?this.index+(t.activeBAssetCollateral>0?BigInt((Math.floor(Date.now()/1e3)-t.rewardsLatestTime)*this.rewardsPerSecond)*o/BigInt(t.activeBAssetCollateral):BigInt(0)):this.index+(t.borrowShareCirculation>0?BigInt((Math.floor(Date.now()/1e3)-t.rewardsLatestTime)*this.rewardsPerSecond)*o/BigInt(t.borrowShareCirculation):BigInt(0))}var e=t.prototype;return e.getAnnualRewards=function(){return this.market.assetDataClient.getAsset(31536e3*this.rewardsPerSecond,this.assetID)},e.getSupplyRewardsAPR=function(){return 0==this.assetID||this.market.marketType!=exports.MarketType.VAULT&&this.market.marketType!=exports.MarketType.LP?0:this.getAnnualRewards().toUSD()/this.market.getTotalSupplied().toUSD()},e.getBorrowRewardsAPR=function(){return 0==this.assetID||this.market.marketType==exports.MarketType.VAULT||this.market.marketType==exports.MarketType.LP?0:this.getAnnualRewards().toUSD()/this.market.getTotalBorrowed().toUSD()},e.getSupplyRewardsPer1k=function(){return 0==this.assetID||this.market.marketType!=exports.MarketType.VAULT&&this.market.marketType!=exports.MarketType.LP?0:this.getAnnualRewards().toDisplayAmount()/(this.market.getTotalSupplied().toUSD()/1e3)},e.getBorrowRewardsPer1k=function(){return 0==this.assetID||this.market.marketType==exports.MarketType.VAULT||this.market.marketType==exports.MarketType.LP?0:this.getAnnualRewards().toDisplayAmount()/(this.market.getTotalBorrowed().toUSD()/1e3)},t}(),ht=function(){function t(t,e,r,n){this.localMinBalance=471e3,this.rewardsPrograms=[],this.algod=t,this.lendingClient=e,this.assetDataClient=e.algofiClient.assetData,this.managerAppId=r,this.appId=n.appId,this.address=s.getApplicationAddress(this.appId),this.marketType=n.marketType,this.underlyingAssetId=n.underlyingAssetId,this.bAssetId=n.bAssetId}var e=t.prototype;return e.loadState=function(){var t=g(h().mark((function t(){var e,r;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,y(this.algod,this.appId);case 2:return this.borrowFactor=(e=t.sent).bf,this.collateralFactor=e.cf,this.flashLoanFee=e.flf,this.flashLoanProtocolFee=e.flpf,this.maxFlashLoanRatio=e.mflr,this.liquidationIncentive=e.li,this.liquidationFee=e.lf,this.reserveFactor=e.rf,this.underlyingSupplyCap=e.usc,this.underlyingBorrowCap=e.ubc,this.baseInterestRate=e.bir,this.baseInterestSlope=e.bis,this.quadraticInterestAmplificationFactor=e.eiaf,this.targetUtilizationRatio=e.tur,this.oracle||(this.oracle=new ut(this.algod,e.oai,i.decode(e.opfn),e.opsf,Math.pow(10,this.lendingClient.algofiClient.assetData.assetConfigs[this.underlyingAssetId].decimals))),t.next=20,this.oracle.loadPrice();case 20:for(this.underlyingCash=e.uc,this.underlyingBorrowed=e.ub,this.underlyingReserves=e.ur,this.borrowShareCirculation=e.bsc,this.bAssetCirculation=e.bac,this.activeBAssetCollateral=e.ac,this.underlyingProtocolReserve=e.upr||0,this.latestTime=e.lt,this.rewardsLatestTime=e.rlt,this.borrowIndex=e.bi,this.impliedBorrowIndex=e.ibi,this.rewardsPrograms=[],r=0;r<2;r++)this.rewardsPrograms.push(new ct(this,e,r));this.rewardsEscrowAccount=k(e.rea);case 34:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.getBorrowAPR=function(t,e){if(void 0===t&&(t=this.getUnderlyingSupplied()),void 0===e&&(e=this.underlyingBorrowed),this.marketType==exports.MarketType.STBL)return this.baseInterestRate/1e6;if(this.marketType==exports.MarketType.LP)return 0;var r=e/t||0,s=this.targetUtilizationRatio/1e6,n=this.baseInterestRate/1e6;return s>0&&(n+=this.baseInterestSlope*(r/s)/1e6),r>this.targetUtilizationRatio/1e6&&(n+=this.quadraticInterestAmplificationFactor*Math.pow(r-this.targetUtilizationRatio/1e6,2)),n},e.getSupplyAPR=function(){var t=g(h().mark((function t(e,r){var s,n;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e=this.getUnderlyingSupplied()),void 0===r&&(r=this.underlyingBorrowed),s=this.getBorrowAPR(e,r),this.marketType!=exports.MarketType.STBL){t.next=5;break}return t.abrupt("return",s);case 5:if(this.marketType!=exports.MarketType.LP){t.next=23;break}if(!this.lendingClient.algofiClient.interfaces.hasLendingPoolForLP(this.underlyingAssetId)){t.next=15;break}return t.next=9,this.lendingClient.algofiClient.interfaces.getLendingPoolFromLP(this.underlyingAssetId);case 9:return n=t.sent,t.next=12,n.getAPR();case 12:return t.abrupt("return",t.sent);case 15:if(!this.lendingClient.algofiClient.amm.v1.hasPoolForLPAsset(this.underlyingAssetId)){t.next=22;break}return t.next=18,this.lendingClient.algofiClient.amm.v1.getPoolByAppId(this.underlyingAssetId);case 18:return t.abrupt("return",t.sent.getAPR());case 22:return t.abrupt("return",0);case 23:return t.abrupt("return",s*(r/e||0)*(1-this.reserveFactor/1e3));case 26:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getUnderlyingSupplied=function(t){if(void 0===t&&(t=!1),this.marketType==exports.MarketType.STBL)return this.underlyingCash;if(t){var e=Math.floor(Date.now()/1e3),r=Math.floor((e-this.latestTime)*this.getBorrowAPR()*1e6*1e6/31536e3),s=Math.floor(this.borrowIndex*r/1e12),n=Math.floor(this.underlyingBorrowed*(this.borrowIndex+s)/this.impliedBorrowIndex),a=Math.floor((n-this.underlyingBorrowed)*this.reserveFactor/1e3);return this.underlyingCash+n-(this.underlyingReserves+a)}return this.underlyingBorrowed+this.underlyingCash-this.underlyingReserves},e.getTotalSupplied=function(){return this.assetDataClient.getAsset(this.getUnderlyingSupplied(),this.underlyingAssetId)},e.getTotalBorrowed=function(){return this.assetDataClient.getAsset(this.underlyingBorrowed,this.underlyingAssetId)},e.getSupplyRewardsAPR=function(){for(var t,e=0,r=A(this.rewardsPrograms);!(t=r()).done;)e+=t.value.getSupplyRewardsAPR();return e},e.getBorrowRewardsAPR=function(){for(var t,e=0,r=A(this.rewardsPrograms);!(t=r()).done;)e+=t.value.getBorrowRewardsAPR();return e},e.convertUnderlyingToUSD=function(t){return t*this.oracle.rawPrice/(1e3*this.oracle.scaleFactor)},e.bAssetToUnderlying=function(t){var e=Math.floor(0!=this.bAssetCirculation?t*this.getUnderlyingSupplied()/this.bAssetCirculation:0);return this.assetDataClient.getAsset(e,this.underlyingAssetId)},e.borrowSharesToUnderlying=function(t,e){void 0===e&&(e=!1);var r=e?Math.ceil(0!=this.borrowShareCirculation?t*this.underlyingBorrowed/this.borrowShareCirculation:0):Math.floor(0!=this.borrowShareCirculation?t*this.underlyingBorrowed/this.borrowShareCirculation:0);return this.assetDataClient.getAsset(r,this.underlyingAssetId)},e.underlyingToBAsset=function(t,e){if(void 0===e&&(e=!1),e){var r=this.getUnderlyingSupplied(e=!0);return this.assetDataClient.getAsset(Math.floor(t.amount*this.bAssetCirculation/r),this.bAssetId)}return this.assetDataClient.getAsset(Math.floor(t.amount*this.bAssetCirculation/this.getUnderlyingSupplied()),this.bAssetId)},e.getMaximumWithdrawAmount=function(t,e){var r,s;void 0===e&&(e=.9);var n,a,i=t.lending.v2.netScaledCollateral-m(t.lending.v2.netScaledBorrow/e,3),o=this.assetDataClient.getAssetFromUSDAmount(1e3*i/this.collateralFactor,this.underlyingAssetId),p=Math.min(o.amount,(null==(r=t.lending.v2.userMarketStates)||null==(s=r[this.appId])?void 0:s.suppliedAmount.amount)||0);return 0==t.lending.v2.netScaledBorrow&&(p=(null==(n=t.lending.v2.userMarketStates)||null==(a=n[this.appId])?void 0:a.suppliedAmount.amount)||0),this.assetDataClient.getAsset(p,this.underlyingAssetId)},e.getMaximumWithdrawBAsset=function(t,e){var r;void 0===e&&(e=.9);var s,n=t.lending.v2.netScaledCollateral-m(t.lending.v2.netScaledBorrow/e,3),a=this.assetDataClient.getAssetFromUSDAmount(1e3*n/this.collateralFactor,this.bAssetId),i=Math.min(a.amount,(null==(r=t.lending.v2.userMarketStates[this.appId])?void 0:r.bAssetCollateral)||0);return 0==t.lending.v2.netScaledBorrow&&(i=(null==(s=t.lending.v2.userMarketStates[this.appId])?void 0:s.bAssetCollateral)||0),this.assetDataClient.getAsset(i,this.bAssetId)},e.getMaximumBorrowAmount=function(t,e){void 0===e&&(e=.9);var r=t.lending.v2.netScaledCollateral*e-t.lending.v2.netScaledBorrow;return this.assetDataClient.getAssetFromUSDAmount(1e3*(r-=.001)/this.borrowFactor,this.underlyingAssetId)},e.getNewBorrowUtilQuote=function(t,e,r){var s,n,a=t.lending.v2.netScaledCollateral+e.toUSD()*this.collateralFactor/1e3,i=(t.lending.v2.netScaledBorrow||0)+r.toUSD()*this.borrowFactor/1e3;return r.amount>0&&0==((null==(s=t.lending.v2.userMarketStates[this.appId])?void 0:s.borrowedAmount.amount)||0)&&(i+=.001),(r.amount+(null==(n=t.lending.v2.userMarketStates[this.appId])?void 0:n.borrowedAmount.amount)||0)<=0&&(i-=.001),i<=0?0:a<=0?Infinity:i/a},e.getPreambleTransactions=function(){var t=g(h().mark((function t(e,r,s){var n,a,i,o,p;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n=[],r.isOptedInToAsset(this.underlyingAssetId)||n.push(nt(e,r.address,r.address,this.underlyingAssetId,0)),r.isOptedInToAsset(this.bAssetId)||n.push(nt(e,r.address,r.address,this.bAssetId,0)),a=0,!s){t.next=10;break}return t.next=7,r.lending.v2.getCalcUserPositionTransactions(this.appId);case 7:for(a=1e3*(i=t.sent).length,o=A(i);!(p=o()).done;)n.push(p.value);case 10:return t.abrupt("return",[n,a]);case 11:case"end":return t.stop()}}),t,this)})));return function(e,r,s){return t.apply(this,arguments)}}(),e.getMintTxns=function(){var t=g(h().mark((function t(e,r){var a,i,o,p;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.marketType!=exports.MarketType.VAULT){t.next=2;break}throw"Mint action not supported by vault market";case 2:return t.next=4,rt(this.algod);case 4:return a=t.sent,t.next=8,this.getPreambleTransactions(a,e,!1);case 8:return i=t.sent[0],o=nt(a,e.address,this.address,this.underlyingAssetId,r.amount),a.fee=3e3,p=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("mba")],accounts:void 0,foreignApps:[this.managerAppId],foreignAssets:[this.bAssetId],rekeyTo:void 0}),t.abrupt("return",s.assignGroupID(i.concat([o,p])));case 15:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getAddUnderlyingCollateralTxns=function(){var t=g(h().mark((function t(e,r){var a,i,o,p,u;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,rt(this.algod);case 2:return a=t.sent,t.next=6,this.getPreambleTransactions(a,e,!1);case 6:return i=t.sent[0],o=this.marketType!=exports.MarketType.VAULT?this.address:e.lending.v2.storageAddress,p=nt(a,e.address,o,this.underlyingAssetId,r.amount),a.fee=2e3,u=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("auc")],accounts:[e.lending.v2.storageAddress],foreignApps:[this.managerAppId],foreignAssets:void 0,rekeyTo:void 0}),t.abrupt("return",s.assignGroupID(i.concat([p,u])));case 14:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getAddBAssetCollateralTxns=function(){var t=g(h().mark((function t(e,r){var a,i,o,p;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.marketType!=exports.MarketType.VAULT){t.next=2;break}throw"Add b asset collateral action not supported by vault market";case 2:return t.next=4,rt(this.algod);case 4:return a=t.sent,t.next=8,this.getPreambleTransactions(a,e,!1);case 8:return i=t.sent[0],o=nt(a,e.address,this.address,this.bAssetId,r.amount),a.fee=2e3,p=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("abc")],accounts:[e.lending.v2.storageAddress],foreignApps:[this.managerAppId],foreignAssets:void 0,rekeyTo:void 0}),t.abrupt("return",s.assignGroupID(i.concat([o,p])));case 15:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getRemoveUnderlyingCollateralTxns=function(){var t=g(h().mark((function t(e,r,a){var i,o,p,u,c,l;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===a&&(a=!1),i=Math.min(this.underlyingToBAsset(r).amount,e.lending.v2.userMarketStates[this.appId].bAssetCollateral),a&&(i=this.getMaximumWithdrawBAsset(e).amount),t.next=5,rt(this.algod);case 5:return o=t.sent,t.next=9,this.getPreambleTransactions(o,e,!0);case 9:return u=(p=t.sent)[0],c=p[1],o.fee=this.marketType!=exports.MarketType.VAULT?3e3+c:4e3+c,l=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:o,appArgs:[d.encode("ruc"),s.encodeUint64(i)],accounts:[e.lending.v2.storageAddress],foreignApps:[this.managerAppId],foreignAssets:[this.underlyingAssetId],rekeyTo:void 0}),t.abrupt("return",s.assignGroupID(u.concat([l])));case 15:case"end":return t.stop()}}),t,this)})));return function(e,r,s){return t.apply(this,arguments)}}(),e.getRemoveBAssetCollateralTxns=function(){var t=g(h().mark((function t(e,r){var a,i,o,p;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.marketType!=exports.MarketType.VAULT){t.next=2;break}throw"Remove b asset collateral action not supported by vault market";case 2:return t.next=4,rt(this.algod);case 4:return a=t.sent,t.next=8,this.getPreambleTransactions(a,e,!0);case 8:return o=(i=t.sent)[0],a.fee=3e3+i[1],p=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("rbc"),s.encodeUint64(r.amount)],accounts:[e.lending.v2.storageAddress],foreignApps:[this.managerAppId],foreignAssets:[this.bAssetId],rekeyTo:void 0}),t.abrupt("return",s.assignGroupID(o.concat([p])));case 14:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getBurnTxns=function(){var t=g(h().mark((function t(e,r){var a,i,o,p;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.marketType!=exports.MarketType.VAULT){t.next=2;break}throw"Burn action not supported by vault market";case 2:return t.next=4,rt(this.algod);case 4:return a=t.sent,t.next=8,this.getPreambleTransactions(a,e,!1);case 8:return i=t.sent[0],o=nt(a,e.address,this.address,this.bAssetId,r.amount),a.fee=3e3,p=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("br")],accounts:void 0,foreignApps:[this.managerAppId],foreignAssets:[this.underlyingAssetId],rekeyTo:void 0}),t.abrupt("return",s.assignGroupID(i.concat([o,p])));case 15:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e.getBorrowTxns=function(){var t=g(h().mark((function t(e,r){var a,i,o,p;return h().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.marketType!=exports.MarketType.VAULT){t.next=4;break}throw"Borrow action not supported by vault market";case 4:if(this.marketType!=exports.MarketType.LP){t.next=6;break}throw"Borrow action not supported by lp market";case 6:return t.next=8,rt(this.algod);case 8:return a=t.sent,t.next=12,this.getPreambleTransactions(a,e,!0);case 12:return o=(i=t.sent)[0],a.fee=3e3+i[1],p=n.makeApplicationNoOpTxnFromObject({from:e.address,appIndex:this.appId,suggestedParams:a,appArgs:[d.encode("b"),s.encodeUint64(r.amount)],accounts:[