@algofi/lend
Version:
The official JavaScript SDK for the Algofi Lending Protocol
1 lines • 71 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("algosdk");function e(t,e,r,n,a,s,i){try{var o=t[s](i),u=o.value}catch(t){return void r(t)}o.done?e(u):Promise.resolve(u).then(n,a)}function r(t){return function(){var r=this,n=arguments;return new Promise((function(a,s){var i=t.apply(r,n);function o(t){e(i,a,s,o,u,"next",t)}function u(t){e(i,a,s,o,u,"throw",t)}o(void 0)}))}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}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 n(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)?n(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var a=0;return function(){return a>=t.length?{done:!0}:{done:!1,value:t[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,i,o=(function(t){var e=function(t){var e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},a=n.iterator||"@@iterator",s=n.asyncIterator||"@@asyncIterator",i=n.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 u(t,e,r,n){var a=Object.create((e&&e.prototype instanceof d?e:d).prototype),s=new w(n||[]);return a._invoke=function(t,e,r){var n="suspendedStart";return function(a,s){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===a)throw s;return{value:void 0,done:!0}}for(r.method=a,r.arg=s;;){var i=r.delegate;if(i){var o=I(i,r);if(o){if(o===p)continue;return o}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=c(t,e,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}(t,r,s),a}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var p={};function d(){}function l(){}function g(){}var h={};o(h,a,(function(){return this}));var f=Object.getPrototypeOf,A=f&&f(f(y([])));A&&A!==e&&r.call(A,a)&&(h=A);var m=g.prototype=d.prototype=Object.create(h);function v(t){["next","throw","return"].forEach((function(e){o(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){var n;this._invoke=function(a,s){function i(){return new e((function(n,i){!function n(a,s,i,o){var u=c(t[a],t,s);if("throw"!==u.type){var p=u.arg,d=p.value;return d&&"object"==typeof d&&r.call(d,"__await")?e.resolve(d.__await).then((function(t){n("next",t,i,o)}),(function(t){n("throw",t,i,o)})):e.resolve(d).then((function(t){p.value=t,i(p)}),(function(t){return n("throw",t,i,o)}))}o(u.arg)}(a,s,n,i)}))}return n=n?n.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 p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=c(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,p;var a=n.arg;return a?a.done?(e[t.resultName]=a.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function _(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 x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function w(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(_,this),this.reset(!0)}function y(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,s=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return s.next=s}}return{next:b}}function b(){return{value:void 0,done:!0}}return l.prototype=g,o(m,"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(m),t},t.awrap=function(t){return{__await:t}},v(k.prototype),o(k.prototype,s,(function(){return this})),t.AsyncIterator=k,t.async=function(e,r,n,a,s){void 0===s&&(s=Promise);var i=new k(u(e,r,n,a),s);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},v(m),o(m,i,"Generator"),o(m,a,(function(){return this})),o(m,"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 n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=y,w.prototype={constructor:w,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(x),!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 n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var a=this.tryEntries.length-1;a>=0;--a){var s=this.tryEntries[a],i=s.completion;if("root"===s.tryLoc)return n("end");if(s.tryLoc<=this.prev){var o=r.call(s,"catchLoc"),u=r.call(s,"finallyLoc");if(o&&u){if(this.prev<s.catchLoc)return n(s.catchLoc,!0);if(this.prev<s.finallyLoc)return n(s.finallyLoc)}else if(o){if(this.prev<s.catchLoc)return n(s.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return n(s.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n];if(a.tryLoc<=this.prev&&r.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var s=a;break}}s&&("break"===t||"continue"===t)&&s.tryLoc<=e&&e<=s.finallyLoc&&(s=null);var i=s?s.completion:{};return i.type=t,i.arg=e,s?(this.method="next",this.next=s.finallyLoc,p):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),p},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),x(r),p}},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 a=n.arg;x(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:y(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(i={exports:{}}),i.exports),u={testnet:{SYMBOLS:["ALGO","USDC","goBTC","goETH","STBL","vALGO","SEVN","EGHT","NINE","TENN","ELVN","TWLV","TRTN","FRTN","FVTN","SXTN"],SYMBOL_INFO:{ALGO:{marketCounter:1,marketAppId:51422140,bankAssetId:51422936,underlyingAssetId:1},USDC:{marketCounter:2,marketAppId:51422142,bankAssetId:51422937,underlyingAssetId:51435943},goBTC:{marketCounter:3,marketAppId:51422146,bankAssetId:51422938,underlyingAssetId:51436723},goETH:{marketCounter:4,marketAppId:51422149,bankAssetId:51422939,underlyingAssetId:51437163},STBL:{marketCounter:5,marketAppId:51422151,bankAssetId:51422940,underlyingAssetId:51437956},vALGO:{marketCounter:6,marketAppId:465814318,bankAssetId:680408335,bankAssetDecimals:6,underlyingAssetId:1},SEVN:{marketCounter:7,marketAppId:51422155},EGHT:{marketCounter:8,marketAppId:51422158},NINE:{marketCounter:9,marketAppId:51422161},TENN:{marketCounter:10,marketAppId:51422164},ELVN:{marketCounter:11,marketAppId:51422170},TWLV:{marketCounter:12,marketAppId:51422172},TRTN:{marketCounter:13,marketAppId:51422175},FRTN:{marketCounter:14,marketAppId:51422177},FVTN:{marketCounter:15,marketAppId:51422179},SXTN:{marketCounter:16,marketAppId:51422186}},managerAppId:51422788,supportedMarketCount:6,maxAtomicOptInMarketCount:13,maxMarketCount:16,initRound:18484796,STAKING_CONTRACTS:{STBL:{marketAppId:53570045,managerAppId:53570235,bankAssetId:53593283,underlyingAssetId:51437956}}},mainnet:{SYMBOLS:["ALGO","USDC","goBTC","goETH","STBL","vALGO","SEVN","EGHT","NINE","TENN","ELVN","TWLV","TRTN","FRTN","FVTN","SXTN"],SYMBOL_INFO:{ALGO:{marketCounter:1,marketAppId:465814065,bankAssetId:465818547,underlyingAssetId:1},USDC:{marketCounter:2,marketAppId:465814103,bankAssetId:465818553,underlyingAssetId:31566704},goBTC:{marketCounter:3,marketAppId:465814149,bankAssetId:465818554,underlyingAssetId:386192725},goETH:{marketCounter:4,marketAppId:465814222,bankAssetId:465818555,underlyingAssetId:386195940},STBL:{marketCounter:5,marketAppId:465814278,bankAssetId:465818563,underlyingAssetId:465865291},vALGO:{marketCounter:6,marketAppId:465814318,bankAssetId:680408335,underlyingAssetId:1},SEVN:{marketCounter:7,marketAppId:465814371},EGHT:{marketCounter:8,marketAppId:465814435},NINE:{marketCounter:9,marketAppId:465814472},TENN:{marketCounter:10,marketAppId:465814527},ELVN:{marketCounter:11,marketAppId:465814582},TWLV:{marketCounter:12,marketAppId:465814620},TRTN:{marketCounter:13,marketAppId:465814664},FRTN:{marketCounter:14,marketAppId:465814701},FVTN:{marketCounter:15,marketAppId:465814744},SXTN:{marketCounter:16,marketAppId:465814807}},supportedMarketCount:6,maxMarketCount:16,maxAtomicOptInMarketCount:13,managerAppId:465818260,initRound:18011265,STAKING_CONTRACTS:{STBL:{marketAppId:482608867,managerAppId:482625868,bankAssetId:482653551,underlyingAssetId:465865291},"STBL-USDC-LP-V2":{marketAppId:553866305,managerAppId:553869413,bankAssetId:553898734,underlyingAssetId:552737686}}}};function c(t,e){return p.apply(this,arguments)}function p(){return(p=r(o.mark((function t(e,r){var n,a;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.status().do();case 2:n=t.sent["last-round"];case 4:return t.next=7,e.pendingTransactionInformation(r).do();case 7:if(!(null!==(a=t.sent)["confirmed-round"]&&a["confirmed-round"]>0)){t.next=11;break}return console.log("Transaction "+r+" confirmed in round "+a["confirmed-round"]),t.abrupt("break",16);case 11:return n+=1,t.next=14,e.statusAfterBlock(n).do();case 14:t.next=4;break;case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}(s=exports.Transactions||(exports.Transactions={}))[s.MINT=1]="MINT",s[s.MINT_TO_COLLATERAL=2]="MINT_TO_COLLATERAL",s[s.ADD_COLLATERAL=3]="ADD_COLLATERAL",s[s.REMOVE_COLLATERAL=4]="REMOVE_COLLATERAL",s[s.BURN=5]="BURN",s[s.REMOVE_COLLATERAL_UNDERLYING=6]="REMOVE_COLLATERAL_UNDERLYING",s[s.BORROW=7]="BORROW",s[s.REPAY_BORROW=8]="REPAY_BORROW",s[s.LIQUIDATE=9]="LIQUIDATE",s[s.CLAIM_REWARDS=10]="CLAIM_REWARDS";var d=function(){function e(e){this.transactions=t.assignGroupID(e);for(var r=[],n=a(this.transactions);!n().done;)r.push(null);this.signedTransactions=r}var n=e.prototype;return n.signWithPrivateKey=function(t,e){for(var r=0,n=Object.entries(this.transactions);r<n.length;r++){var a=n[r];this.signedTransactions[a[0]]=a[1].signTxn(e)}},n.signWithPrivateKeys=function(t){if(t.length!==this.transactions.length)throw new Error("Different number of private keys and transactions");for(var e=0,r=Object.entries(this.transactions);e<r.length;e++){var n=r[e],a=n[0];this.signedTransactions[a]=n[1].signTxn(t[a])}},n.submit=function(){var t=r(o.mark((function t(e,r){var n;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r=!1),t.prev=1,t.next=4,e.sendRawTransaction(this.signedTransactions).do();case 4:n=t.sent,t.next=10;break;case 7:throw t.prev=7,t.t0=t.catch(1),new Error(t.t0);case 10:if(!r){t.next=13;break}return t.next=13,c(e,n.txId);case 13:return t.abrupt("return",{txid:n.txId});case 14:case"end":return t.stop()}}),t,this,[[1,7]])})));return function(e,r){return t.apply(this,arguments)}}(),e}();function l(t){return Math.floor(Math.random()*t)}function g(t,e,r){var n=t[e];return void 0!==n?n:r}function h(e){return t.encodeUint64(e)}function f(t){for(var e,r={},n=a(t);!(e=n()).done;){var s=e.value,i=s.key,o=s.value,u=void 0,c=void 0;try{u=Buffer.from(i,"base64").toString()}catch(t){u=Buffer.from(i).toString()}1===o.type?(c=""!==o.bytes?o.bytes:Buffer.from(o.bytes,"base64").toString(),r[u]=c):r[u]=o.uint}return r}function A(t,e,r){return m.apply(this,arguments)}function m(){return(m=r(o.mark((function t(e,r,n){var s,i,u;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.accountInformation(r).do();case 2:s=a(t.sent["apps-local-state"]);case 4:if((i=s()).done){t.next=12;break}if((u=i.value).id!==n){t.next=10;break}if(Object.keys(u).includes("key-value")){t.next=9;break}return t.abrupt("return",{});case 9:return t.abrupt("return",f(u["key-value"]));case 10:t.next=4;break;case 12:return t.abrupt("return",{});case 13:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function v(){return(v=r(o.mark((function t(e,r,n){var s,i,u;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.accountInformation(r).do();case 2:s=a(t.sent["created-apps"]);case 5:if((i=s()).done){t.next=11;break}if((u=i.value).id!==n){t.next=9;break}return t.abrupt("return",f(u.params["global-state"]));case 9:t.next=5;break;case 11:return t.abrupt("return",{});case 12:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function k(t,e){return I.apply(this,arguments)}function I(){return(I=r(o.mark((function t(e,r){var n;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,e.getApplicationByID(r).do();case 2:return n=f(t.sent.params["global-state"]),t.abrupt("return",n);case 5:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _(t){return u[t].STAKING_CONTRACTS}function x(t,e,r){return void 0===e&&(e=!1),void 0===r&&(r=!1),u[t].SYMBOLS.slice(0,e?u[t].maxMarketCount:r?u[t].maxAtomicOptInMarketCount:u[t].supportedMarketCount)}function w(t){return u[t].managerAppId}function y(t,e){return u[t].SYMBOL_INFO[e].marketAppId}function b(t){return u[t].initRound}function T(t,e){for(var r,n=a(t);!(r=n()).done;){var s=r.value,i=s.value;if(e===Buffer.from(s.key,"base64").toString())return 2==i.type?i.uint:i.bytes}throw new Error("Key not found")}var S={admin:"a",active_collateral:"acc",activate_market:"am",asset_id:"ai",bank_asset_id:"ba",bank_circulation:"bc",bank_to_underlying_exchange:"bt",borrow_index:"bi",base_interest_rate:"bir",contract_update_time:"cut",collateral_factor:"cf",implied_borrow_index:"i",increase_param_update_delay:"ipud",is_active:"ia",is_disabled_supply:"ids",is_disabled_borrow:"idb",is_final_params:"ifp",is_final_contract:"ifc",latest_time:"lt",liquidation_incentive:"li",manager_id:"mi",manager_market_counter_var:"mm",market_activation_time:"ma",market_supply_cap_in_dollars:"msc",market_borrow_cap_in_dollars:"mbc",min_scheduled_param_update_delay:"mpud",outstanding_borrow_shares:"ob",oracle_app_id:"o",oracle_price_field:"op",oracle_price_scale_factor:"ops",reserve_factor:"rf",new_collateral_factor:"ncf",new_liquidation_incentive:"nl",new_reserve_factor:"nr",new_utilization_optimal:"nu",new_base_interest_rate:"nb",new_slope_1:"ns",new_slope_2:"ns2",new_oracle_app_id:"no",new_oracle_price_field:"nop",new_oracle_price_scale_factor:"nops",new_market_supply_cap_in_dollars:"nmsc",new_market_borrow_cap_in_dollars:"nmbc",param_update_time:"put",remove_reserves:"rr",schedule_contract_update:"scu",schedule_market_params_update:"sm",set_market_params:"smp",set_is_final_params:"sifp",set_is_final_contract:"sifc",set_is_disabled_supply:"sids",set_is_enabled_supply:"sies",set_is_disabled_borrow:"sidb",set_is_enabled_borrow:"sieb",slope_1:"s1",slope_2:"s2",total_borrow_interest_rate:"tbir",transfer_admin:"ta",underlying_cash:"uc",underlying_borrowed:"ub",underlying_reserves:"ur",utilization_optimal:"uo",variable_interest_rate:"vir",update_market_params:"ump",user_active_collateral:"uac",user_borrow_shares:"ubs"},O={add_collateral:"ac",admin:"a",borrow:"b",burn:"bu",contract_update_time:"cut",counter_indexed_rewards_coefficient:"_ci",claim_rewards:"cr",disable_rewards_program:"drp",fetch_market_variables:"fmv",is_finalized:"if",latest_rewards_time:"lrt",liquidate:"l",mint:"m",mint_to_collateral:"mt",n_rewards_programs:"nrp",opt_into_asset:"oia",rewards_amount:"ra",rewards_asset_id:"rai",rewards_bitmap:"rbm",rewards_per_second:"rp",rewards_secondary_asset_id:"rsai",rewards_secondary_ratio:"rsr",rewards_start_time:"rst",supported_market_count:"smc",price_string:"_p",remove_collateral:"rc",remove_collateral_underlying:"rcu",repay_borrow:"rb",schedule_contract_update:"scu",storage_opt_in:"so",set_is_final:"sif",set_rewards_program:"srp",set_supported_market_count:"ssmc",transfer_admin:"ta",update_prices:"up",update_protocol_data:"upd",update_rewards_program:"urp",user_global_max_borrow_in_dollars:"ug",user_global_borrowed_in_dollars:"ugb",user_address:"ua",user_storage_address:"usa",user_rewards_latest_time:"urlt",user_rewards_program_number:"urpn",user_pending_rewards:"upr",user_secondary_pending_rewards:"us",counter_to_user_rewards_coefficient_initial:"_uc"},C={1:"one",2:"two",3:"three",4:"four",5:"five",6:"six",7:"seven",8:"eight",9:"nine",10:"ten"};function M(e,r,n,a,s,i,o){var u=JSON.parse(JSON.stringify(n));[exports.Transactions.MINT,exports.Transactions.BURN,exports.Transactions.REMOVE_COLLATERAL,exports.Transactions.REMOVE_COLLATERAL_UNDERLYING,exports.Transactions.BORROW,exports.Transactions.REPAY_BORROW,exports.Transactions.LIQUIDATE,exports.Transactions.CLAIM_REWARDS].includes(e)&&(u.fee=2e3);for(var c=new TextEncoder,p=t.makeApplicationNoOpTxn(r,n,a,[c.encode(O.fetch_market_variables)],void 0,s,void 0,h(l(1e6))),d=t.makeApplicationNoOpTxn(r,u,a,[c.encode(O.update_prices)],void 0,i),g=t.makeApplicationNoOpTxn(r,n,a,[c.encode(O.update_protocol_data)],[o],s),f=[],A=1;A<10;A++){var m=t.makeApplicationNoOpTxn(r,n,a,[c.encode("dummy_"+C[A])],void 0,s);f.push(m)}return[p,d,g].concat(f)}var L=new TextEncoder;function E(e,r,n,a,s,i,o,u,c,p){var l=M(exports.Transactions.ADD_COLLATERAL,e,r,i,c,p,n),g=t.makeApplicationNoOpTxn(e,r,i,[L.encode(O.add_collateral)]),h=t.makeApplicationNoOpTxn(e,r,o,[L.encode(O.add_collateral)],[n],[i]),f=t.makeAssetTransferTxnWithSuggestedParams(e,u,void 0,void 0,a,void 0,s,r);return new d([].concat(l,[g,h,f]))}for(var R=["ALGO","USDC","goBTC","goETH","STBL","vALGO"],N=["BANK"],P=["ALGO","USDC","goBTC","goETH","STBL","vALGO","SEVN","EGHT","NINE","TENN","ELVN","TWLV","TRTN","FRTN","FVTN","SXTN","STBL-ALGO-LP","STBL-USDC-LP","STBL-USDC-LP-V2","STBL-YLDY-LP"],U={ALGO:{decimals:6,marketCounter:1,marketAppId:465814065,marketAddress:"TY5N6G67JWHSMWFFFZ252FXWKLRO5UZLBEJ4LGV7TPR5PVSKPLDWH3YRXU",managerAppId:465818260,bankAssetId:465818547,bankAssetDecimals:6,underlyingAssetId:1,oracleAppId:531724540,oracleFieldName:"latest_twap_price"},USDC:{decimals:6,marketCounter:2,marketAppId:465814103,marketAddress:"ABQHZLNGGPWWZVA5SOQO3HBEECVJSE3OHYLKACOTC7TC4BS52ZHREPF7QY",managerAppId:465818260,bankAssetId:465818553,bankAssetDecimals:6,underlyingAssetId:31566704,oracleAppId:451327550,oracleFieldName:"price"},goBTC:{decimals:8,marketCounter:3,marketAppId:465814149,marketAddress:"W5UCMHDSTGKWBOV6YVLDVPJGPE4L4ISTU6TGXC7WRF63Y7GOVFOBUNJB5Q",managerAppId:465818260,bankAssetId:465818554,bankAssetDecimals:8,underlyingAssetId:386192725,oracleAppId:531725044,oracleFieldName:"latest_twap_price"},goETH:{decimals:8,marketCounter:4,marketAppId:465814222,marketAddress:"KATD43XBJJIDXB3U5UCPIFUDU3CZ3YQNVWA5PDDMZVGKSR4E3QWPJX67CY",managerAppId:465818260,bankAssetId:465818555,bankAssetDecimals:8,underlyingAssetId:386195940,oracleAppId:531725449,oracleFieldName:"latest_twap_price"},STBL:{decimals:6,marketCounter:5,marketAppId:465814278,marketAddress:"OPY7XNB5LVMECF3PHJGQV2U33LZPM5FBUXA3JJPHANAG5B7GEYUPZJVYRE",managerAppId:465818260,bankAssetId:465818563,bankAssetDecimals:6,underlyingAssetId:465865291,oracleAppId:451327550,oracleFieldName:"price"},vALGO:{decimals:6,marketCounter:6,marketAppId:465814318,marketAddress:"DAUL5I34T4C4U5OMXS7YBPJIERQ2NH3O7XPZCIJEGKP4NO3LK4UWDCHAG4",managerAppId:465818260,bankAssetId:680408335,bankAssetDecimals:6,underlyingAssetId:1,oracleAppId:531724540,oracleFieldName:"latest_twap_price"},"STBL-STAKE":{decimals:6,marketCounter:5,marketAppId:482608867,managerAppId:482625868,marketAddress:"DYLJJES76YQCOUK6D4RALIPJ76U5QT7L6A2KP6QTOH63OBLFKLTER2J6IA",bankAssetId:465818563,bankAssetDecimals:6,underlyingAssetId:465865291,oracleAppId:451327550,oracleFieldName:"price"},"STBL-ALGO-LP":{decimals:6,managerAppId:514458901,managerAddress:"JZYVXQLRZ2TEI6XMIQN5KEHEVA5EA3LQVZUS24SGKLVIBQZTRSP3PTCRJQ",marketAppId:514439598,marketAddress:"UMTL7D6YMN463FSG3JN572CFD6VTKRKNSK5KSQYIUK67N7CR3XLDFM42Y4",underlyingAssetId:468634109,bankAssetId:514473977,oracleAppId:451327550,bankAssetDecimals:6,oracleFieldName:"price"},"STBL-USDC-LP":{decimals:6,marketAppId:485244022,managerAppId:485247444,managerAddress:"IG3KDYTH7IB46DC5K4ME4Z3R46VJEFXFPHRHVV3KKBTULW5ODHPJL7ZFU4",marketAddress:"Z3GWRL5HGCJQYIXP4MINCRWCKWDHZ5VSYJHDLIDLEIOARIZWJX6GLAWWEI",creatorAddress:"TFONT6HASLUUWDRE3MEEC4GS5PIMLEKNCE7Z2JMGNBFIHVZZ2QEJ7MODZE",oracleAppId:451327550,bankAssetId:485254141,bankAssetDecimals:6,underlyingAssetId:467020179,oracleFieldName:"price"},"STBL-USDC-LP-V2":{decimals:6,managerAppId:514599129,managerAddress:"SFSV2PM3724DUZGIQVLZ5XOUKSQBDALYI7UZ23YLGYFDLM3WH2AMWHBNTE",marketAppId:514596716,marketAddress:"RLXSNIDRFIDMKJILBMDKHACY7YFEV2N65T6D3YGKKM2LAKHNK4XCOEVYIQ",underlyingAssetId:467020179,bankAssetId:514619644,creatorAddress:"TFONT6HASLUUWDRE3MEEC4GS5PIMLEKNCE7Z2JMGNBFIHVZZ2QEJ7MODZE",oracleAppId:451327550,bankAssetDecimals:6,oracleFieldName:"price"},"STBL-YLDY-LP":{decimals:6,managerAppId:514601080,managerAddress:"S53YDCHH3JGJKZWLNLUFDAQKSUZCAWOVNYHWAGMVCOFK2NNROS7NCLDK64",marketAppId:514599409,marketAddress:"3VNLTSYGAMVBRSCSAF7PP7KSBAV5AQQIUM2TJXIDVOXX573AW7LMH6RARY",underlyingAssetId:468695586,bankAssetId:514624374,bankAssetDecimals:6,oracleFieldName:"price"},BANK:{decimals:6,underlyingAssetId:51642940},SIIX:{marketCounter:6,marketAppId:465814318,marketAddress:"DAUL5I34T4C4U5OMXS7YBPJIERQ2NH3O7XPZCIJEGKP4NO3LK4UWDCHAG4"},SEVN:{marketCounter:7,marketAppId:465814371,marketAddress:"K75YX4ZN3J43R2JTRWB6M3KXNPWAJJVPFSMIRAGQO77TKXKHKBFKSRZGGA"},EGHT:{marketCounter:8,marketAppId:465814435,marketAddress:"P6B5MK2FMN24IVRYMQMEPZHJPCNN6OUKFI5OSTOUREC47HPQNUXAUKF4TY"},NINE:{marketCounter:9,marketAppId:465814472,marketAddress:"PWVB7SHASD5XJNQFZHC5UAR5UYY33TW62YA6JVOW6PMYNZ7KMARPXKMFRU"},TENN:{marketCounter:10,marketAppId:465814527,marketAddress:"K7TNWBPCKLJKX3KHUZ5VA7YKGWNPHM4E6HQ5HGD7VFVYZ3232RJFGATMTM"},ELVN:{marketCounter:11,marketAppId:465814582,marketAddress:"LEHVWIH62DHSXLXFBPAXHYZZYGO7ONJ4HJHQLX4LJSIXSM66FPN5BXRCPU"},TWLV:{marketCounter:12,marketAppId:465814620,marketAddress:"S6LBCGD4UFECPY3P67QFURVDXCBPWZXG56VJ43UVBK7ODIODF6UOX6BX4A"},TRTN:{marketCounter:13,marketAppId:465814664,marketAddress:"HHHROS6MPEFEXJ7JQOKASR67EEPRM3NRGWLREW54XBUHF6AQ3HYGQQIGCY"},FRTN:{marketCounter:14,marketAppId:465814701,marketAddress:"XFWV3BF47DBLJ2GY2WUUIIA3W4VTOFOALKKEJJNCWFG6DLHWZ6SFUQXPJA"},FVTN:{marketCounter:15,marketAppId:465814744,marketAddress:"BTC4OBXRM53F3WT3YXK5LEP2JYB6OIDGQHM4EOHYPOYORKR4QHY7CMD35M"},SXTN:{marketCounter:16,marketAppId:465814807,marketAddress:"F253XGHUENH36WTAVWR2DE6VPAF2FV7L7H3QESM5Q7QXQTEX5T2C2HT3NU"}},B=[],D=[],F=[],G={},V={},W=0,H=R;W<H.length;W++){var Y=H[W];B.push(U[Y].oracleAppId),F.push(U[Y].marketAppId),G[U[Y].marketCounter]=Y,V[U[Y].underlyingAssetId]=Y,V[U[Y].bankAssetId]="b"+Y}for(var K=0,X=N;K<X.length;K++){var J=X[K];V[U[J].underlyingAssetId]=J}for(var Q=0,Z=P;Q<Z.length;Q++)D.push(U[Z[Q]].marketAppId);var j=function(){function t(t,e,r,n,a,s){if(void 0===n&&(n=null),void 0===a&&(a=null),void 0===s&&(s=null),this.algod=t,this.underlyingAssetId=e,this.bankAssetId=r,null!==n){if(null===a)throw Error("oracle price field must be specified");if(null===s)throw Error("oracle price scale factor must be specified")}this.oracleAppId=n,this.oraclePriceField=a,this.oraclePriceScaleFactor=s}t.init=function(){var e=r(o.mark((function e(r,n,a,s,i,u){var c,p,d,l;return o.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(void 0===s&&(s=null),void 0===i&&(i=null),void 0===u&&(u=null),c=new t(r,n,a,s,i,u),p=0,d=Object.keys(U);p<d.length;p++)U[l=d[p]].underlyingAssetId===n&&(c.underlyingAssetInfo=U[l]);return e.abrupt("return",c);case 6:case"end":return e.stop()}}),e)})));return function(t,r,n,a,s,i){return e.apply(this,arguments)}}();var e=t.prototype;return e.getUnderlyingAssetId=function(){return this.underlyingAssetId},e.getUnderlyingAssetInfo=function(){return this.underlyingAssetInfo},e.getBankAssetId=function(){return this.bankAssetId},e.getBankAssetInfo=function(){return this.bankAssetInfo},e.getOracleAppId=function(){return this.oracleAppId},e.getOraclePriceField=function(){return this.oraclePriceField},e.getOraclePriceScaleFactor=function(){return this.oraclePriceScaleFactor},e.getRawPrice=function(){var t=r(o.mark((function t(){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(null!==this.oracleAppId){t.next=2;break}throw Error("no oracle app id for asset");case 2:return t.next=4,k(this.algod,this.oracleAppId);case 4:return t.t0=Buffer.from(this.oraclePriceField,"base64").toString(),t.abrupt("return",t.sent[t.t0]);case 7:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.getUnderlyingDecimals=function(){return this.underlyingAssetInfo.decimals},e.getPrice=function(){var t=r(o.mark((function t(){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(null!=this.oracleAppId){t.next=2;break}throw Error("no oracle app id for asset");case 2:return t.next=4,this.getRawPrice();case 4:return t.abrupt("return",t.sent*Math.pow(10,this.getUnderlyingDecimals())/(1e3*this.getOraclePriceScaleFactor()));case 6:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.toUSD=function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getPrice();case 2:return t.abrupt("return",e*t.sent/Math.pow(10,this.getUnderlyingDecimals()));case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(),q=new TextEncoder;function z(e,r,n,a,s,i,o,u,c){var p=M(exports.Transactions.BORROW,e,r,i,u,c,n),l=t.makeApplicationNoOpTxn(e,r,i,[q.encode(O.borrow),h(a)]),g=t.makeApplicationNoOpTxn(e,r,o,[q.encode(O.borrow)],[n],[i],[s]);return new d([].concat(p,[l,g]))}var $=new TextEncoder;function tt(e,r,n,a,s,i,o,u,c,p,l){var g=M(exports.Transactions.BURN,e,r,o,p,l,n),h=t.makeApplicationNoOpTxn(e,r,o,[$.encode(O.burn)]),f=t.makeApplicationNoOpTxn(e,r,u,[$.encode(O.burn)],[n],[o],[s]),A=t.makeAssetTransferTxnWithSuggestedParams(e,c,void 0,void 0,a,void 0,i,r);return new d([].concat(g,[h,f,A]))}var et=new TextEncoder;function rt(e,r,n,a,s,i,o){var u=M(exports.Transactions.CLAIM_REWARDS,e,r,a,s,i,n),c=t.makeApplicationNoOpTxn(e,r,a,[et.encode(O.claim_rewards)],[n],void 0,o);return new d([].concat(u,[c]))}var nt=new TextEncoder;function at(e,r,n,a,s,i,o,u,c){void 0===c&&(c=null);var p,l=M(exports.Transactions.MINT_TO_COLLATERAL,e,r,s,[i],[u],n),g=t.makeApplicationNoOpTxn(e,r,s,[nt.encode(O.mint_to_collateral)]),h=t.makeApplicationNoOpTxn(e,r,i,[nt.encode(O.mint_to_collateral)],[n],[s]);return p=c?t.makeAssetTransferTxnWithSuggestedParams(e,o,void 0,void 0,a,void 0,c,r):t.makePaymentTxnWithSuggestedParams(e,o,a,void 0,void 0,r),new d([].concat(l,[g,h,p]))}function st(e,r,n,a,s,i,o,u){void 0===u&&(u=null);var c,p=M(exports.Transactions.REMOVE_COLLATERAL_UNDERLYING,e,r,s,[i],[o],n),l=t.makeApplicationNoOpTxn(e,r,s,[nt.encode(O.remove_collateral_underlying),h(a)]);return c=u?t.makeApplicationNoOpTxn(e,r,i,[nt.encode(O.remove_collateral_underlying)],[n],[s],[u]):t.makeApplicationNoOpTxn(e,r,i,[nt.encode(O.remove_collateral_underlying)],[n],[s]),new d([].concat(p,[l,c]))}function it(e,r,n,a,s,i,o){var u=M(exports.Transactions.CLAIM_REWARDS,e,r,a,[s],[i],n),c=t.makeApplicationNoOpTxn(e,r,a,[nt.encode(O.claim_rewards)],[n],void 0,o);return new d([].concat(u,[c]))}var ot=new TextEncoder;function ut(e,r,n,a,s,i,o,u,c){var p=M(exports.Transactions.REMOVE_COLLATERAL_UNDERLYING,e,r,i,u,c,n),l=t.makeApplicationNoOpTxn(e,r,i,[ot.encode(O.remove_collateral_underlying),h(a)]),g=t.makeApplicationNoOpTxn(e,r,o,[ot.encode(O.remove_collateral_underlying)],[n],[i],[s]);return new d([].concat(p,[l,g]))}var ct=new TextEncoder;function pt(e,r,n,a,s,i,o,u,c,p){void 0===p&&(p=null);var l,g=M(exports.Transactions.MINT_TO_COLLATERAL,e,r,s,u,c,n),h=t.makeApplicationNoOpTxn(e,r,s,[ct.encode(O.mint_to_collateral)]),f=t.makeApplicationNoOpTxn(e,r,i,[ct.encode(O.mint_to_collateral)],[n],[s]);return l=p?t.makeAssetTransferTxnWithSuggestedParams(e,o,void 0,void 0,a,void 0,p,r):t.makePaymentTxnWithSuggestedParams(e,o,a,void 0,void 0,r),new d([].concat(g,[h,f,l]))}var dt=new TextEncoder;function lt(e,r,n,a,s,i,o,u,c){var p=M(exports.Transactions.REMOVE_COLLATERAL,e,r,i,u,c,n),l=t.makeApplicationNoOpTxn(e,r,i,[dt.encode(O.remove_collateral),h(a)]),g=t.makeApplicationNoOpTxn(e,r,o,[dt.encode(O.remove_collateral)],[n],[i],[s]);return new d([].concat(p,[l,g]))}var gt=new TextEncoder;function ht(e,r,n,a,s,i,o,u,c,p){void 0===p&&(p=null);var l,g=M(exports.Transactions.REPAY_BORROW,e,r,s,u,c,n),h=t.makeApplicationNoOpTxn(e,r,s,[gt.encode(O.repay_borrow)]),f=t.makeApplicationNoOpTxn(e,r,i,[gt.encode(O.repay_borrow)],[n],[s],p?[p]:[]);return l=p?t.makeAssetTransferTxnWithSuggestedParams(e,o,void 0,void 0,a,void 0,p,r):t.makePaymentTxnWithSuggestedParams(e,o,a,void 0,void 0,r),new d([].concat(g,[h,f,l]))}function ft(e,r,n,s,i){for(var o,u=t.makePaymentTxnWithSuggestedParams(n,s,Math.floor(3569500),void 0,void 0,i),c=[],p=a(r);!(o=p()).done;)c.push(t.makeApplicationOptInTxn(n,i,o.value));var l=t.makeApplicationOptInTxn(n,i,e),g=t.getApplicationAddress(e),h=t.makeApplicationOptInTxn(s,i,e,void 0,void 0,void 0,void 0,void 0,void 0,g);return new d([u].concat(c,[l,h]))}var At=new TextEncoder;function mt(e,r,n,a,s,i,o,u,c,p,l,g,h){void 0===h&&(h=null);var f,A=M(exports.Transactions.LIQUIDATE,e,r,i,p,l,a),m=t.makeApplicationNoOpTxn(e,r,i,[At.encode(O.liquidate)],void 0,p),v=t.makeApplicationNoOpTxn(e,r,o,[At.encode(O.liquidate)],[a],[i,c]);f=h?t.makeAssetTransferTxnWithSuggestedParams(e,u,void 0,void 0,s,void 0,h,r):t.makePaymentTxnWithSuggestedParams(e,u,s,void 0,void 0,r);var k=t.makeApplicationNoOpTxn(e,r,c,[At.encode(O.liquidate)],[a,n],[i,o],[g]);return new d([].concat(A,[m,v,f,k]))}var vt=function(){function t(t,e){this.algod=t,this.latestRewardsTime=g(e,O.latest_rewards_time,0),this.rewardsProgramNumber=g(e,O.n_rewards_programs,0),this.rewardsAmount=g(e,O.rewards_amount,0),this.rewardsPerSecond=g(e,O.rewards_per_second,0),this.rewardsAssetId=g(e,O.rewards_asset_id,0),this.rewardsSecondaryRatio=g(e,O.rewards_secondary_ratio,0),this.rewardsSecondaryAssetId=g(e,O.rewards_secondary_asset_id,0)}var e=t.prototype;return e.getRewardsAssetIds=function(){var t=[];return this.rewardsAssetId>1&&t.push(this.rewardsAssetId),this.rewardsSecondaryAssetId>1&&t.push(this.rewardsSecondaryAssetId),t},e.getLatestRewardsTime=function(){return this.latestRewardsTime},e.getRewardsProgramNumber=function(){return this.rewardsProgramNumber},e.getRewardsAmount=function(){return this.rewardsAmount},e.getRewardsPerSecond=function(){return this.rewardsPerSecond},e.getRewardsAssetId=function(){return this.rewardsAssetId},e.getRewardsSecondaryRatio=function(){return this.rewardsSecondaryRatio},e.getRewardsSecondaryAssetId=function(){return this.rewardsSecondaryAssetId},e.getStorageUnrealizedRewards=function(){var t=r(o.mark((function t(e,r,n){var s,i,u,c,p,d,l,f,m,v,I,_,x,w,y,b,T,S,C,M,L,E,R;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,k(this.algod,r.getManagerAppId());case 2:return s=t.sent,t.next=5,A(this.algod,e,r.getManagerAppId());case 5:i=t.sent,u=this.getRewardsProgramNumber()===g(i,O.user_rewards_program_number,0),c=u?g(i,O.user_pending_rewards,0):0,p=u?g(i,O.user_secondary_pending_rewards,0):0,d=0,l=a(n);case 11:if((f=l()).done){t.next=23;break}return m=f.value,t.t0=d,t.t1=m.getAsset(),t.next=17,m.getUnderlyingBorrowed();case 17:return t.t2=t.sent,t.next=20,t.t1.toUSD.call(t.t1,t.t2);case 20:d=t.t0+=t.sent;case 21:t.next=11;break;case 23:v=new Date,I=Math.floor(v.getTime()/1e3-this.getLatestRewardsTime()),_=this.getRewardsAmount()>0?I*this.getRewardsPerSecond():0,x=a(n);case 27:if((w=x()).done){t.next=61;break}return y=w.value,b=Buffer.from(h(y.getMarketCounter())).toString("utf-8"),T=g(s,b+O.counter_indexed_rewards_coefficient,0),S=u?i[b+O.counter_to_user_rewards_coefficient_initial]:0,t.next=34,y.getUnderlyingBorrowed();case 34:return t.t3=t.sent,t.t4=y.getActiveCollateral()*y.getBankToUnderlyingExchange()/1e9,C=t.t3+t.t4,t.t5=T,t.t6=Math,t.t7=1e14*_,t.t8=y.getAsset(),t.next=43,y.getUnderlyingBorrowed();case 43:return t.t9=t.sent,t.next=46,t.t8.toUSD.call(t.t8,t.t9);case 46:return t.t10=t.sent,t.t11=t.t7*t.t10,t.t12=d*C,t.t13=t.t11/t.t12,t.t14=t.t6.floor.call(t.t6,t.t13),M=t.t5+t.t14,t.next=54,y.getStorageState(e);case 54:L=t.sent,E=Math.floor((M-S)*(L.activeCollateralUnderlying+L.borrowUnderlying)/1e14),R=Math.floor(E*this.getRewardsSecondaryRatio()/1e3),c+=E,p+=R;case 59:t.next=27;break;case 61:return t.abrupt("return",[c,p]);case 62:case"end":return t.stop()}}),t,this)})));return function(e,r,n){return t.apply(this,arguments)}}(),t}(),kt=function(){function e(e,r){this.algod=e,this.managerAppId=r,this.managerAddress=t.getApplicationAddress(this.managerAppId)}e.init=function(){var t=r(o.mark((function t(r,n){var a;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return a=new e(r,n),t.next=3,a.updateGlobalState();case 3:return t.abrupt("return",a);case 4:case"end":return t.stop()}}),t)})));return function(e,r){return t.apply(this,arguments)}}();var n=e.prototype;return n.updateGlobalState=function(){var t=r(o.mark((function t(){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,k(this.algod,this.managerAppId);case 2:this.rewardsProgram=new vt(this.algod,t.sent);case 4:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getManagerAppId=function(){return this.managerAppId},n.getManagerAddress=function(){return this.managerAddress},n.getRewardsProgram=function(){return this.rewardsProgram},n.getStorageAddress=function(){var e=r(o.mark((function e(r){var n;return o.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,A(this.algod,r,this.managerAppId);case 2:if(n=g(e.sent,O.user_storage_address,null)){e.next=6;break}throw new Error("No storage address found");case 6:return e.abrupt("return",t.encodeAddress(Buffer.from(n.trim(),"base64")));case 7:case"end":return e.stop()}}),e,this)})));return function(t){return e.apply(this,arguments)}}(),n.getUserState=function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=this,t.next=3,this.getStorageAddress(e);case 3:return t.t1=t.sent,t.next=6,t.t0.getStorageState.call(t.t0,t.t1);case 6:return t.abrupt("return",t.sent);case 8:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.getStorageState=function(){var t=r(o.mark((function t(e){var r,n;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r={},t.next=3,A(this.algod,e,this.managerAppId);case 3:return r.user_global_max_borrow_in_dollars=g(n=t.sent,O.user_global_max_borrow_in_dollars,0),r.user_global_borrowed_in_dollars=g(n,O.user_global_borrowed_in_dollars,0),t.abrupt("return",r);case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.getUserUnrealizedRewards=function(){var t=r(o.mark((function t(e,r){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.t0=this,t.next=3,this.getStorageAddress(e);case 3:return t.t1=t.sent,t.t2=r,t.abrupt("return",t.t0.getStorageUnrealizedRewards.call(t.t0,t.t1,t.t2));case 6:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),n.getStorageUnrealizedRewards=function(){var t=r(o.mark((function t(e,r){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getRewardsProgram().getStorageUnrealizedRewards(e,this,r);case 2:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)})));return function(e,r){return t.apply(this,arguments)}}(),e}(),It=function(){function e(e,r,n){this.algod=e,this.historicalIndexer=r,this.marketAppId=n,this.marketAddress=t.getApplicationAddress(this.marketAppId)}e.init=function(){var t=r(o.mark((function t(r,n,a,s){var i;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===s&&(s=!0),i=new e(r,n,a),t.next=4,i.updateGlobalState(s);case 4:return t.abrupt("return",i);case 5:case"end":return t.stop()}}),t)})));return function(e,r,n,a){return t.apply(this,arguments)}}();var n=e.prototype;return n.updateGlobalState=function(){var t=r(o.mark((function t(e){var r;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===e&&(e=!0),t.next=3,k(this.algod,this.marketAppId);case 3:if(this.marketCounter=(r=t.sent)[S.manager_market_counter_var],this.underlyingAssetId=g(r,S.asset_id,null),this.bankAssetId=g(r,S.bank_asset_id,null),this.oracleAppId=g(r,S.oracle_app_id,null),this.oraclePriceField=g(r,S.oracle_price_field,null),this.oraclePriceScaleFactor=g(r,S.oracle_price_scale_factor,null),this.collateralFactor=g(r,S.collateral_factor,null),this.liquidationIncentive=g(r,S.liquidation_incentive,null),this.reserveFactor=g(r,S.reserve_factor,null),this.baseInterestRate=g(r,S.base_interest_rate,null),this.slope1=g(r,S.slope_1,null),this.slope2=g(r,S.slope_2,null),this.utilizationOptimal=g(r,S.utilization_optimal,null),this.marketSupplyCapInDollars=g(r,S.market_supply_cap_in_dollars,null),this.marketBorrowCapInDollars=g(r,S.market_borrow_cap_in_dollars,null),this.activeCollateral=g(r,S.active_collateral,0),this.bankCirculation=g(r,S.bank_circulation,0),this.bankToUnderlyingExchange=g(r,S.bank_to_underlying_exchange,0),this.underlyingBorrowed=g(r,S.underlying_borrowed,0),this.outstandingBorrowShares=g(r,S.outstanding_borrow_shares,0),this.underlyingCash=g(r,S.underlying_cash,0),this.underlyingReserves=g(r,S.underlying_reserves,0),this.borrowUtil=this.underlyingBorrowed/(this.underlyingBorrowed+this.underlyingCash+this.underlyingReserves),this.totalBorrowInterestRate=g(r,S.total_borrow_interest_rate,0),this.totalSupplyInterestRate=this.totalBorrowInterestRate*this.borrowUtil,!e){t.next=41;break}if(!this.underlyingAssetId){t.next=36;break}return t.next=33,j.init(this.algod,this.underlyingAssetId,this.bankAssetId,this.oracleAppId,this.oraclePriceField,this.oraclePriceScaleFactor);case 33:t.t0=t.sent,t.next=37;break;case 36:t.t0=null;case 37:return this.asset=t.t0,t.next=40,this.asset.getPrice();case 40:this.assetPrice=t.sent;case 41:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.getMarketAppId=function(){return this.marketAppId},n.getMarketAddress=function(){return this.marketAddress},n.getMarketCounter=function(){return this.marketCounter},n.getAsset=function(){return this.asset},n.getActiveCollateral=function(){return this.activeCollateral},n.getBankCirculation=function(){return this.bankCirculation},n.getBankToUnderlyingExchange=function(){return this.bankToUnderlyingExchange},n.getUnderlyingBorrowed=function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e=null),!e){t.next=14;break}return t.prev=2,t.next=5,this.historicalIndexer.lookupApplications(this.marketAppId).do();case 5:return t.abrupt("return",T(t.sent.application.params["global-state"],S.underlying_borrowed));case 9:throw t.prev=9,t.t0=t.catch(2),new Error("Issue getting data");case 12:t.next=15;break;case 14:return t.abrupt("return",this.underlyingBorrowed);case 15:case"end":return t.stop()}}),t,this,[[2,9]])})));return function(e){return t.apply(this,arguments)}}(),n.getOutstandingBorrowShares=function(){return this.outstandingBorrowShares},n.getUnderlyingCash=function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e=null),!e){t.next=14;break}return t.prev=2,t.next=5,this.historicalIndexer.lookupApplications(this.marketAppId).do();case 5:return t.abrupt("return",T(t.sent.application.params["global-state"],S.underlying_cash));case 9:throw t.prev=9,t.t0=t.catch(2),new Error("Issue getting data");case 12:t.next=15;break;case 14:return t.abrupt("return",this.underlyingCash);case 15:case"end":return t.stop()}}),t,this,[[2,9]])})));return function(e){return t.apply(this,arguments)}}(),n.getUnderlyingReserves=function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e=null),!e){t.next=14;break}return t.prev=2,t.next=5,this.historicalIndexer.lookupApplications(this.marketAppId).do();case 5:return t.abrupt("return",T(t.sent.application.params["global-state"],S.underlying_reserves));case 9:throw t.prev=9,t.t0=t.catch(2),new Error("Issue getting data");case 12:t.next=15;break;case 14:return t.abrupt("return",this.underlyingReserves);case 15:case"end":return t.stop()}}),t,this,[[2,9]])})));return function(e){return t.apply(this,arguments)}}(),n.getTotalBorrowInterestRate=function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(void 0===e&&(e=null),!e){t.next=14;break}return t.prev=2,t.next=5,this.historicalIndexer.lookupApplications(this.marketAppId).do();case 5:return t.abrupt("return",T(t.sent.application.params["global-state"],S.total_borrow_interest_rate));case 9:throw t.prev=9,t.t0=t.catch(2),new Error("Issue getting data");case 12:t.next=15;break;case 14:return t.abrupt("return",this.totalBorrowInterestRate);case 15:case"end":return t.stop()}}),t,this,[[2,9]])})));return function(e){return t.apply(this,arguments)}}(),n.getCollateralFactor=function(){return this.collateralFactor},n.getLiquidationIncentive=function(){return this.liquidationIncentive},n.getStorageState=function(){var t=r(o.mark((function t(e){var r,n,a;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r={},t.next=3,A(this.algod,e,this.marketAppId);case 3:return n=t.sent,a=this.getAsset(),r.activeCollateralBank=g(n,S.user_active_collateral,0),r.activeCollateralUnderlying=Math.floor(r.activeCollateralBank*this.bankToUnderlyingExchange/1e9),t.next=9,a.toUSD(r.activeCollateralUnderlying);case 9:return r.activeCollateralUsd=t.sent,r.activeCollateralMaxBorrowUsd=r.activeCollateralUsd*this.collateralFactor/1e3,r.borrowShares=g(n,S.user_borrow_shares,0),r.borrowUnderlying=Math.floor(this.underlyingBorrowed*r.borrowShares/this.outstandingBorrowShares),t.next=15,a.toUSD(r.borrowUnderlying);case 15:return r.borrowUsd=t.sent,t.abrupt("return",r);case 17:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e}(),_t=function(){function t(t,e){this.algodClient=t,this.historicalIndexerClient=e}t.init=function(){var e=r(o.mark((function e(r,n,a){var s;return o.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return s=new t(r,n),e.next=3,kt.init(s.algodClient,a.managerAppId);case 3:return s.manager=e.sent,e.next=6,It.init(r,n,a.marketAppId);case 6:return s.market=e.sent,e.next=9,s.updateGlobalState();case 9:return e.abrupt("return",s);case 10:case"end":return e.stop()}}),e)})));return function(t,r,n){return e.apply(this,arguments)}}();var e=t.prototype;return e.updateGlobalState=function(){var t=r(o.mark((function t(){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getManager().updateGlobalState();case 2:return t.next=4,this.getMarket().updateGlobalState();case 4:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),e.getManager=function(){return this.manager},e.getMarket=function(){return this.market},e.getAsset=function(){return this.getMarket().getAsset()},e.getManagerAppId=function(){return this.getManager().getManagerAppId()},e.getManagerAddress=function(){return this.getManager().getManagerAddress()},e.getMarketAppId=function(){return this.getMarket().getMarketAppId()},e.getMarketAddress=function(){return this.getMarket().getMarketAddress()},e.getOracleAppId=function(){return this.getMarket().getAsset().getOracleAppId()},e.getStaked=function(){return this.getMarket().getActiveCollateral()},e.getRewardsProgram=function(){return this.getManager().getRewardsProgram()},e.getStorageAddress=function(){var t=r(o.mark((function t(e){return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getManager().getStorageAddress(e);case 2:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getUserState=function(){var t=r(o.mark((function t(e){var r;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getStorageAddress(e);case 2:if(r=t.sent){t.next=5;break}throw new Error("no storage address found");case 5:return t.next=7,this.getStorageState(r);case 7:return t.abrupt("return",t.sent);case 9:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.getStorageState=function(){var t=r(o.mark((function t(e){var r,n,a,s;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r={},t.next=3,this.getManager().getStorageUnrealizedRewards(e,[this.getMarket()]);case 3:return a=(n=t.sent)[1],r.unrealized_rewards=n[0],r.secondary_unrealized_rewards=a,t.next=10,this.getMarket().getStorageState(e);case 10:return r.staked_bank=(s=t.sent).activeCollateralBank,r.stake_underlying=s.activeCollateralUnderlying,t.abrupt("return",r);case 14:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),t}(),xt=new TextEncoder;function wt(e,r,n,a,s,i,o,u,c,p,l){void 0===l&&(l=null);var g,h=M(exports.Transactions.MINT,e,r,i,c,p,n),f=t.makeApplicationNoOpTxn(e,r,i,[xt.encode(O.mint)]),A=t.makeApplicationNoOpTxn(e,r,o,[xt.encode(O.mint)],[n],[i],[s]);return g=l?t.makeAssetTransferTxnWithSuggestedParams(e,u,void 0,void 0,a,void 0,l,r):t.makePaymentTxnWithSuggestedParams(e,u,a,void 0,void 0,r),new d([].concat(h,[f,A,g]))}var yt=function(){function e(t,e,r,n,a){this.scaleFactor=1e9,this.borrowSharesInit=1e3,this.parameterScaleFactor=1e3,this.algod=t,this.indexerClient=e,this.historicalIndexer=r,this.chain=a,this.userAddress=n,this.initRound=b(this.chain),this.activeOrderedSymbols=x(this.chain),this.maxOrderedSymbols=x(this.chain,!0),this.maxAtomicOptInOrderedSymbols=x(this.chain,void 0,!0),this.stakingContractInfo=_(this.chain)}e.init=function(){var t=r(o.mark((function t(r,n,s,i,u,c){var p,d,l,g,h,f,A;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:void 0===c&&(c=!1),(p=new e(r,n,s,i,u)).markets={},d=a(p.activeOrderedSymbols);case 4:if((l=d()).done){t.next=11;break}return g=l.value,t.next=8,It.init(r,s,y(p.chain,g));case 8:p.markets[g]=t.sent;case 9:t.next=4;break;case 11:if(p.stakingContracts={},!c){t.next=22;break}h=0,f=Object.keys(p.stakingContractInfo);case 14:if(!(h<f.length)){t.next=22;break}return A=f[h],t.next=18,_t.init(p.algod,p.historicalIndexer,p.stakingContractInfo[A]);case 18:p.stakingContracts[A]=t.sent;case 19:h++,t.next=14;break;case 22:return t.next=24,kt.init(p.algod,w(p.chain));case 24:return p.manager=t.sent,t.abrupt("return",p);case 26:case"end":return t.stop()}}),t)})));return function(e,r,n,a,s,i){return t.apply(this,arguments)}}();var n=e.prototype;return n.getDefaultParams=function(){var t=r(o.mark((function t(){var e;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.algod.getTransactionParams().do();case 2:return(e=t.sent).flatFee=!0,e.fee=1e3,t.abrupt("return",e);case 6:case"end":return t.stop()}}),t,this)})));return function(){return t.apply(this,arguments)}}(),n.getUserInfo=function(){var t=r(o.mark((function t(e){var r;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===e&&(e=null),(r=e)||(r=this.userAddress),t.next=5,this.algod.accountInformation(r).do();case 5:return t.abrupt("return",t.sent);case 7:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),n.isOptedIntoApp=function(){var t=r(o.mark((function t(e,r){var n,s,i,u;return o.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return void 0===r&&(r=null),(n=r)||(n=this.userAddress),t.next=5,this.getUserInfo(n);case 5:for(s=[],i=a(t.sent["apps-local-state"]);!(u=i()).done;)s.push(u.value.id);return t.abrupt("return",s.includes(e));case 9:case"end":return t.stop()}}),t,