From 4955a1b499056c13decc5f337ec4b13d505366e8 Mon Sep 17 00:00:00 2001 From: gulcinuras Date: Fri, 29 Nov 2024 12:14:19 +0100 Subject: [PATCH 1/4] fix(st-algo-client): Fix fee calculation --- dist/index.js | 2 +- src/folks-lending-pools/constants.ts | 1 - src/liquid-stake/stAlgoClient.ts | 2 +- src/util/client/base/baseClient.ts | 1 - src/util/util.ts | 2 -- 5 files changed, 2 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index 6525fe0b..4b713c34 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -"use strict";var e=require("algosdk"),t=require("base64-js"),n=require("crypto");function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0;--a){var s=this.tryEntries[a],o=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var i=n.call(s,"catchLoc"),u=n.call(s,"finallyLoc");if(i&&u){if(this.prev=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),k(n),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var a=r.arg;k(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:E(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function o(e,t,n,r,a,s,o){try{var i=e[s](o),u=i.value}catch(e){return void n(e)}i.done?t(u):Promise.resolve(u).then(r,a)}function i(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var s=e.apply(t,n);function i(e){o(s,r,a,i,u,"next",e)}function u(e){o(s,r,a,i,u,"throw",e)}i(void 0)}))}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f: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,o=!0,i=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){i=!0,s=e},f:function(){try{o||null==n.return||n.return()}finally{if(i)throw s}}}}function k(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var _=function(e){return e.SwapRouterStaleDataError="SwapRouterStaleDataError",e.SwapRouterNoRouteError="SwapRouterNoRouteError",e.SwapRouterLowSwapAmountError="SwapRouterLowSwapAmountError",e.SwapRouterInsufficientReservesError="SwapRouterInsufficientReservesError",e.SwapRouterPoolHasNoLiquidityError="SwapRouterPoolHasNoLiquidityError",e.NoAvailablePoolError="NoAvailablePoolError",e.OutputAmountExceedsAvailableLiquidityError="OutputAmountExceedsAvailableLiquidityError",e.UnknownError="UnknownError",e.LowSwapAmountError="LowSwapAmountError",e.AssetDoesNotBelongToPoolError="AssetDoesNotBelongToPoolError",e.InvalidSwapTypeError="InvalidSwapTypeError",e}({}),E=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;return u(this,n),(a=t.call(this,r)).type=e,a.message=r,Error.captureStackTrace&&Error.captureStackTrace(A(a),n),a}return p(n)}(),P=Uint8Array.from([1]),S=1e5,D=1e5,O=1e5,N=1e5,B=1e5,C=5e4,F=28500,L=1e3,R=1e3,M={mainnet:{base:"https://mainnet.analytics.tinyman.org/api",v1:"https://mainnet.analytics.tinyman.org/api/v1"},testnet:{base:"https://testnet.analytics.tinyman.org/api",v1:"https://testnet.analytics.tinyman.org/api/v1"}},U={V1_1:"v1_1",V2:"v2"},j=0,V={id:"".concat(j),name:"Algorand",unit_name:"ALGO",decimals:6,url:"https://algorand.org",is_liquidity_token:!1,total_amount:"6615503326932151",clawback_address:""},G={V1:"TM1POOL",V1_1:"TMPOOL11",V2:"TMPOOL2"},X={testnet:258703304,mainnet:22e8},q={testnet:724519992,mainnet:2537013734},Q={testnet:724676936,mainnet:2537023208},W="- would result negative",z="logic eval error:",J="exceeds schema integer count",K=/transaction \w+:/,Y=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;u(this,n);for(var s=arguments.length,o=new Array(s>2?s-2:0),i=2;ir?[a(a({},e),{},{id:n}),a(a({},t),{},{id:r})]:[a(a({},t),{},{id:r}),a(a({},e),{},{id:n})]}function ee(e,t){var n=[e,t];return[Math.max.apply(Math,n),Math.min.apply(Math,n)]}function te(e){return Number(e)===j}function ne(e){return Number(e.id)}function re(e){var t,n=e.stateArray,r=void 0===n?[]:n,a=e.shouldDecodeKeys,s=void 0!==a&&a,o={},i=T(r);try{for(i.s();!(t=i.n()).done;){var u=t.value,c=u.key,p=void 0;if(1==u.value.type)p=u.value.bytes;else{if(2!=u.value.type)throw new Error("Unexpected state type: ".concat(u.value.type));p=u.value.uint}o[s?atob(c):c]=p}}catch(e){i.e(e)}finally{i.f()}return o}function ae(e){var t,n=e.reduce((function(e,t){return e+t.length}),0),r=new Uint8Array(n),a=0,s=T(e);try{for(s.s();!(t=s.n()).done;){var o=t.value;r.set(o,a),a+=o.length}}catch(e){s.e(e)}finally{s.f()}return r}var se=100000n,oe=100000n,ie=100000n,ue=25000n+25000n,ce=25000n+3500n;function pe(e){var t=e["apps-total-schema"],n=0n,r=0n;t&&(t["num-byte-slice"]&&(n=t["num-byte-slice"]),t["num-uint"]&&(r=t["num-uint"]));var a=e["apps-local-state"]||[],s=e["created-apps"]||[],o=e.assets||[];return se+oe*BigInt(o.length)+ie*BigInt(s.length+a.length)+ce*r+ue*n}function le(e){return new Promise((function(t){setTimeout((function(){t(null)}),e)}))}function de(e,t){return fe.apply(this,arguments)}function fe(){return(fe=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=3,le(1e3);case 3:return r=null,e.prev=4,e.next=7,t.pendingTransactionInformation(n).do();case 7:r=e.sent,e.next=12;break;case 10:e.prev=10,e.t0=e.catch(4);case 12:if(!r){e.next=17;break}if(!r["confirmed-round"]){e.next=15;break}return e.abrupt("return",r);case 15:if(!r["pool-error"]){e.next=17;break}throw new Error("Transaction Rejected: ".concat(r["pool-error"]));case 17:e.next=0;break;case 19:case"end":return e.stop()}}),e,null,[[4,10]])})))).apply(this,arguments)}function me(e,t,n){if(t>1||t<0)throw new Error("Invalid slippage value. Must be between 0 and 1, got ".concat(t));var r;try{var a="negative"===e?1-t:1+t;r=BigInt(Math.floor(Number(n)*a))}catch(e){throw new Error(e.message)}return r}function he(e,t){var n=Number(e);return ge({decimalPlaces:n},Math.pow(10,-n)*Number(t))}function ge(e,t){var n=e.decimalPlaces,r=void 0===n?0:n;if(r>0){var a=v(Ae(t),2),s=a[0],o=a[1],i=v(Ae(Math.round(Number(xe(s,o+r)))),2),u=i[0],c=i[1];return Number(xe(u,c-r))}return Math.round(t)}function xe(e,t){return e+(t<0?"e".concat(t):"e+".concat(t))}function Ae(e){if(e.toString().includes("e")){var t=e.toString().split("e");return[parseFloat(t[0]),parseFloat(t[1])]}return[e,0]}function Ie(e,t){return ve.apply(this,arguments)}function ve(){return(ve=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,r=[],a=T(n),e.prev=3,a.s();case 5:if((o=a.n()).done){e.next=18;break}return i=o.value,e.next=9,t.sendRawTransaction(i).do();case 9:return u=e.sent,c=u.txId,e.next=13,de(t,c);case 13:p=e.sent,l=p["confirmed-round"],r.push({confirmedRound:l,txnID:c});case 16:e.next=5;break;case 18:e.next=23;break;case 20:e.prev=20,e.t0=e.catch(3),a.e(e.t0);case 23:return e.prev=23,a.f(),e.finish(23);case 26:return e.abrupt("return",r);case 29:throw e.prev=29,e.t1=e.catch(0),new Y(e.t1,"We encountered an error while processing this transaction. Try again later.");case 32:case"end":return e.stop()}}),e,null,[[0,29],[3,20,23,26]])})))).apply(this,arguments)}function we(e){return e.reduce((function(e,t){return e+t.txn.fee}),0)}function ye(e){return(t=e[0].txn.group)?Buffer.from(t).toString("base64"):"";var t}function be(e){for(var t=[];;){var n=Number(e&BigInt(127));if(!(e>>=BigInt(7))){t.push(n);break}t.push(128|n)}return t}function Te(e){return(new TextEncoder).encode(e)}var ke,_e=new(function(){function e(){u(this,e),this.clientName="tinyman-js-sdk"}return p(e,[{key:"getClientName",value:function(){return this.clientName}},{key:"setClientName",value:function(e){this.clientName=e}},{key:"getAppCallTxnNoteWithClientName",value:function(e,t){var n=e===U.V1_1?"v1":e,r=JSON.stringify(a({origin:this.clientName},t));return Te("tinyman/".concat(n,":j").concat(r))}}]),e}()),Ee=(l(ke={},U.V1_1,{testnet:62368684,mainnet:552635992}),l(ke,U.V2,{testnet:148607e3,mainnet:1002541853}),ke);function Pe(e,t){var n=Ee[t][e];if(!n)throw new Error("No Validator App exists for ".concat(e," network with ").concat(t," contract version"));return n}function Se(){return(Se=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationOptInTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function De(){return(De=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationClearStateTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var Oe,Ne,Be,Ce=function(e){return e.FixedInput="fixed-input",e.FixedOutput="fixed-output",e}({}),Fe=.003,Le=function(e){return e[e.INPUT_TXN=0]="INPUT_TXN",e[e.APP_CALL_TXN=1]="APP_CALL_TXN",e}({}),Re=(l(Oe={},Ce.FixedInput,1),l(Oe,Ce.FixedOutput,2),Oe),Me=2,Ue=Te("swap"),je=(l(Ne={},Ce.FixedInput,Te("fixed-input")),l(Ne,Ce.FixedOutput,Te("fixed-output")),Ne),Ve={ASSET_OPT_IN:Te("asset_opt_in")},Ge={testnet:184778019,mainnet:1083651166},Xe=(l(Be={},Ce.FixedInput,7),l(Be,Ce.FixedOutput,8),Be);function qe(e){var t=Je(e),n=t.assetIn,r=t.assetOut;return he(r.asset.decimals,Number(r.amount))/he(n.asset.decimals,Number(n.amount))}function Qe(e){var t=Ge[e];if(!t)throw new Error("Unknown network or network not supported: ".concat(e));return t}function We(e){return e[e.length-1].quote.amount_out}function ze(e){return e[0].quote.amount_in}function Je(e){return{assetIn:ze(e),assetOut:We(e)}}function Ke(e){return Ye.apply(this,arguments)}function Ye(){return(Ye=i(s().mark((function t(n){var r,a,o,i,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.routerAppID,o=n.assetIDs,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a,appArgs:[Ve.ASSET_OPT_IN],foreignAssets:o,suggestedParams:u}),p=o.length,c.fee=e.ALGORAND_MIN_TX_FEE*(p+1),t.abrupt("return",c);case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function He(e){return $e.apply(this,arguments)}function $e(){return($e=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k,_,E,P,S,D;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.initiatorAddr,a=n.client,o=n.network,i=n.swapType,u=n.route,c=n.slippage,t.next=3,a.getTransactionParams().do();case 3:return p=t.sent,l=[ne(u[0].quote.amount_in.asset),ne(u[0].quote.amount_out.asset),ne(u[1].quote.amount_out.asset)],d=l[0],f=l[1],m=l[2],h=[Number(ze(u).amount),Number(We(u).amount)],g=h[0],x=h[1],A=[u[0].pool.address,u[1].pool.address],I=A[0],v=A[1],w=i===Ce.FixedInput?g:me("positive",c,g),y=i===Ce.FixedOutput?x:me("negative",c,x),b=te(d),T=Qe(o),k=b?e.makePaymentTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,suggestedParams:p}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,assetIndex:d,suggestedParams:p}),(_=e.makeApplicationNoOpTxnFromObject({from:r,appIndex:T,appArgs:[Ue,je[i],e.encodeUint64(y)],foreignApps:[Pe(o,U.V2)],foreignAssets:[d,f,m],accounts:[I,v],suggestedParams:p,note:_e.getAppCallTxnNoteWithClientName(U.V2)})).fee=e.ALGORAND_MIN_TX_FEE*(Xe[i]+1),E=[k,_],t.next=17,Ze({client:a,network:o,assetIDs:[d,f,m]});case 17:if(!((P=t.sent).length>0)){t.next=23;break}return t.next=21,Ke({client:a,initiatorAddr:r,assetIDs:P,routerAppID:T});case 21:S=t.sent,E.unshift(S);case 23:return D=e.assignGroupID(E),t.abrupt("return",D.map((function(e){return{txn:e,signers:[r]}})));case 25:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Ze(e){return et.apply(this,arguments)}function et(){return(et=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(Qe(a)),t.next=4,r.accountInformation(i).do();case 4:return u=t.sent,c=u.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!c.includes(e)})));case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function tt(e){return nt.apply(this,arguments)}function nt(){return(nt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetInID,a=t.assetOutID,o=t.swapType,i=t.network,u={asset_in_id:String(r),asset_out_id:String(a),swap_type:o,amount:String(n)},e.next=4,fetch("".concat(M[i].v1,"/swap-router/quotes/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}).catch((function(){throw new Error("Network error")}));case 4:return c=e.sent,e.next=7,c.json();case 7:if(p=e.sent,c.ok){e.next=14;break}if(s=p,!Boolean(s)||void 0===s.fallback_message){e.next=13;break}throw new E(p.type,p.fallback_message);case 13:throw new E(_.UnknownError,"There was an error while getting a quote from Swap Router");case 14:if(!(p.route.length<2)){e.next=16;break}throw new E(_.SwapRouterNoRouteError,"Swap router couldn't find a route for this swap.");case 16:return e.abrupt("return",p);case 17:case"end":return e.stop()}var s}),e)})))).apply(this,arguments)}var rt=function(e){return e.Direct="direct",e.Router="router",e}({}),at=4*e.ALGORAND_MIN_TX_FEE;function st(t){return(Re[t]+Me)*e.ALGORAND_MIN_TX_FEE}function ot(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Fe;return Math.ceil(1/e)}function it(e){return e1&&void 0!==arguments[1]?arguments[1]:Fe)}function ut(t){return(Re[t]+1)*e.ALGORAND_MIN_TX_FEE}function ct(e){var t=e.assetIn,n=e.assetOut;return he(n.decimals,Number(n.amount))/he(t.decimals,Number(t.amount))}function pt(e){var t=e.inputSupply,n=e.outputSupply,r=e.assetIn,a=e.assetOut,s=ct({assetIn:r,assetOut:a}),o=he(a.decimals,Number(n))/he(r.decimals,Number(t));return ge({decimalPlaces:5},Math.abs(s/o-1))}function lt(e){if(e.type===rt.Router){var t=ze(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetInID,amount:e.data.quote.assetInAmount}}function dt(e){if(e.type===rt.Router){var t=We(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetOutID,amount:e.data.quote.assetOutAmount}}function ft(e){return e.type===rt.Direct?e.data.pool.contractVersion:U.V2}function mt(e){return e.type===rt.Direct?e.data.quote.rate:qe(e.data.route)}function ht(e){for(var t=e[0],n=mt(t),r=1;rn&&(t=a,n=s)}return t}function gt(e){return e instanceof E&&[_.SwapRouterInsufficientReservesError,_.SwapRouterLowSwapAmountError,_.OutputAmountExceedsAvailableLiquidityError,_.LowSwapAmountError].includes(e.type)}var xt={type:"logicsig",logic:{bytecode:"BCAIAQCBgICAgICAgPABgICAgICAgIDwAQMEBQYlJA1EMQkyAxJEMRUyAxJEMSAyAxJEMgQiDUQzAQAxABJEMwEQIQcSRDMBGIGCgICAgICAgPABEkQzARkiEjMBGyEEEhA3ARoAgAlib290c3RyYXASEEAAXDMBGSMSRDMBG4ECEjcBGgCABHN3YXASEEACOzMBGyISRDcBGgCABG1pbnQSQAE7NwEaAIAEYnVybhJAAZg3ARoAgAZyZWRlZW0SQAJbNwEaAIAEZmVlcxJAAnkAIQYhBSQjEk0yBBJENwEaARclEjcBGgIXJBIQRDMCADEAEkQzAhAhBBJEMwIhIxJEMwIiIxwSRDMCIyEHEkQzAiQjEkQzAiWACFRNUE9PTDExEkQzAiZRAA+AD1RpbnltYW5Qb29sMS4xIBJEMwIngBNodHRwczovL3RpbnltYW4ub3JnEkQzAikyAxJEMwIqMgMSRDMCKzIDEkQzAiwyAxJEMwMAMQASRDMDECEFEkQzAxElEkQzAxQxABJEMwMSIxJEJCMTQAAQMwEBMwIBCDMDAQg1AUIBsTMEADEAEkQzBBAhBRJEMwQRJBJEMwQUMQASRDMEEiMSRDMBATMCAQgzAwEIMwQBCDUBQgF8MgQhBhJENwEcATEAE0Q3ARwBMwQUEkQzAgAxABNEMwIUMQASRDMDADMCABJEMwIRJRJEMwMUMwMHMwMQIhJNMQASRDMDESMzAxAiEk0kEkQzBAAxABJEMwQUMwIAEkQzAQEzBAEINQFCAREyBCEGEkQ3ARwBMQATRDcBHAEzAhQSRDMDFDMDBzMDECISTTcBHAESRDMCADEAEkQzAhQzBAASRDMCESUSRDMDADEAEkQzAxQzAwczAxAiEk0zBAASRDMDESMzAxAiEk0kEkQzBAAxABNEMwQUMQASRDMBATMCAQgzAwEINQFCAJAyBCEFEkQ3ARwBMQATRDMCADcBHAESRDMCADEAE0QzAwAxABJEMwIUMwIHMwIQIhJNMQASRDMDFDMDBzMDECISTTMCABJEMwEBMwMBCDUBQgA+MgQhBBJENwEcATEAE0QzAhQzAgczAhAiEk03ARwBEkQzAQEzAgEINQFCABIyBCEEEkQzAQEzAgEINQFCAAAzAAAxABNEMwAHMQASRDMACDQBD0M=",address:"ABUKAXTANWR6K6ZYV75DWJEPVWWOU6SFUVRI6QHO44E4SIDLHBTD2CZ64A",size:881,variables:[{name:"TMPL_ASSET_ID_1",type:"int",index:15,length:10},{name:"TMPL_ASSET_ID_2",type:"int",index:5,length:10},{name:"TMPL_VALIDATOR_APP_ID",type:"int",index:74,length:10}],source:"https://github.com/tinymanorg/tinyman-contracts-v1/tree/dc9ab40c58b85c15d58f63a1507e18be76720dbb/contracts/pool_logicsig.teal.tmpl"},name:"pool_logicsig"},At={type:"app",global_state_schema:{num_uints:0,num_byte_slices:0},local_state_schema:{num_uints:16,num_byte_slices:0},name:"validator_app"},It=p((function e(t){u(this,e),this.schema={numLocalInts:t.local_state_schema.num_uints,numLocalByteSlices:t.local_state_schema.num_byte_slices,numGlobalInts:t.global_state_schema.num_uints,numGlobalByteSlices:t.global_state_schema.num_byte_slices}})),vt=function(n){d(a,It);var r=I(a);function a(e,t){var n;return u(this,a),(n=r.call(this,e)).poolLogicSigContractTemplate=t.logic.bytecode,n.templateVariables=t.logic.variables,n}return p(a,[{key:"generateLogicSigAccountForPool",value:function(n){if(n.asset1ID===n.asset2ID)throw new Error("Assets are the same");var r=Pe(n.network,U.V1_1),a=v(ee(n.asset1ID,n.asset2ID),2),s=a[0],o=a[1],i=Array.from(t.toByteArray(this.poolLogicSigContractTemplate)),u={asset_id_1:s,asset_id_2:o,validator_app_id:r},c=0;this.templateVariables.sort((function(e,t){return e.index-t.index}));for(var p=0;p2&&void 0!==arguments[2]?arguments[2]:e.IntDecoding.DEFAULT;return new Promise(function(){var e=i(s().mark((function e(o,i){var u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.accountInformation(n).setIntDecoding(r).do();case 3:u=e.sent,o(a(a({},u),{},{minimum_required_balance:Pt(u)})),e.next=10;break;case 7:e.prev=7,e.t0=e.catch(0),i(new Error(e.t0.message||"Failed to fetch account information"));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}())}function Et(e,t){var n=e["apps-local-state"].find((function(e){return e.id===t}));return n?re({stateArray:n["key-value"],shouldDecodeKeys:!0}):null}function Pt(e){var t=e["apps-total-schema"];return S+D*(e.assets||[]).length+N*(e["created-apps"]||[]).length+O*(e["apps-local-state"]||[]).length+C*Number(t&&t["num-byte-slice"]||0)+F*Number(t&&t["num-uint"]||0)+B*(e["apps-total-extra-pages"]||0)}var St=Te("e");function Dt(e){return Ot.apply(this,arguments)}function Ot(){return(Ot=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,k,_;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.pool,i=r.accountAddr,n.next=3,a.accountInformation(i).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:u=n.sent,c=u["apps-local-state"]||[],p=0n,l=0n,d=0n,f=o.account.address(),m=T(c),n.prev=10,m.s();case 12:if((h=m.n()).done){n.next=31;break}if((g=h.value).id==o.validatorAppID){n.next=16;break}return n.abrupt("continue",29);case 16:if(x=g["key-value"]){n.next=19;break}return n.abrupt("break",31);case 19:A=re({stateArray:x}),I=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset1ID)])),v=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset2ID)])),w=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.poolTokenID)])),y=A[I],b=A[v],k=A[w],"bigint"==typeof y&&(p=y),"bigint"==typeof b&&(l=b),"bigint"==typeof k&&(d=k);case 29:n.next=12;break;case 31:n.next=36;break;case 33:n.prev=33,n.t0=n.catch(10),m.e(n.t0);case 36:return n.prev=36,m.f(),n.finish(36);case 39:if(!((_={excessAsset1:p,excessAsset2:l,excessPoolTokens:d}).excessAsset1<0n||_.excessAsset2<0n||_.excessPoolTokens<0n)){n.next=42;break}throw new Error("Invalid account excess: ".concat(_));case 42:return n.abrupt("return",_);case 43:case"end":return n.stop()}}),n,null,[[10,33,36,39]])})))).apply(this,arguments)}function Nt(){return(Nt=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.accountAddr,i=r.validatorAppID,n.next=3,a.accountInformation(o).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:if(u=n.sent,c=u["apps-local-state"]||[],p=c.find((function(e){return e.id==i})),l=[],p&&p["key-value"])for(d=re({stateArray:p["key-value"]}),f=0,m=Object.entries(d);fMt)){n.next=48;break}throw new Error("Issued liquidity value is out of the expected range ([0n, ".concat(Mt,"]): ").concat(N.issuedLiquidity));case 48:return n.abrupt("return",N);case 49:case"end":return n.stop()}}),n,null,[[8,31,34,37]])})))).apply(this,arguments)}function Gt(){return Gt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.address,a=t.network,!(o=d.length>1&&void 0!==d[1]?d[1]:{})[r]){e.next=4;break}return e.abrupt("return",o[r]);case 4:return e.next=6,_t(n,r);case 6:return i=e.sent,u=Et(i,Pe(a,U.V1_1)),c=null,u&&(l=i["created-assets"][0],p=l.index,c={asset1ID:u[Ft[U.V1_1].asset1],asset2ID:u[Ft[U.V1_1].asset2],poolTokenID:p},o[r]=c),e.abrupt("return",c);case 11:case"end":return e.stop()}}),e)}))),Gt.apply(this,arguments)}var Xt=Object.freeze({__proto__:null,getPoolAssets:function(e){return Gt.apply(this,arguments)},getPoolInfo:Ut,getPoolReserves:function(e,t){return Vt.apply(this,arguments)}});function qt(e){return Qt.apply(this,arguments)}function Qt(){return(Qt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.asset1ID,o=t.asset2ID,i=kt(U.V2),u=i.generateLogicSigAccountForPool(t),c=Pe(r,U.V2),p=u.address(),l=ee(a,o),e.next=8,_t(n,p);case 8:return d=e.sent,f=Et(d,c),m={account:u,validatorAppID:c,asset1ID:l[0],asset2ID:l[1],status:f?Ct.READY:Ct.NOT_CREATED,contractVersion:U.V2},f&&(m.asset1ProtocolFees=BigInt(f[Ft.v2.asset1ProtocolFees]),m.asset2ProtocolFees=BigInt(f[Ft.v2.asset2ProtocolFees]),m.asset1Reserves=BigInt(f[Ft.v2.asset1Reserves]),m.asset2Reserves=BigInt(f[Ft.v2.asset2Reserves]),m.issuedPoolTokens=BigInt(f[Ft.v2.issuedPoolTokens]),m.cumulativePriceUpdateTimeStamp=Number(f[Ft.v2.cumulativePriceUpdateTimeStamp]),m.protocolFeeRatio=Number(f[Ft.v2.protocolFeeRatio]),m.totalFeeShare=BigInt(f[Ft.v2.totalFeeShare]),m.poolTokenID=Number(f[Ft.v2.poolTokenID]),m.asset1ID=Number(f[Ft.v2.asset1]),m.asset2ID=Number(f[Ft.v2.asset2])),e.abrupt("return",m);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Wt(){return(Wt=i(s().mark((function e(t,n){var r,a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_t(t,n.account.address());case 2:return r=e.sent,a=Et(r,n.validatorAppID),o={asset1:0n,asset2:0n,issuedLiquidity:0n,round:r.round},a&&(o.asset1=BigInt(a[Ft.v2.asset1Reserves]),o.asset2=BigInt(a[Ft.v2.asset2Reserves]),o.issuedLiquidity=BigInt(a[Ft.v2.issuedPoolTokens])),e.abrupt("return",o);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zt(){return(zt=i(s().mark((function e(t){var n,r,a,o,i,u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.address,a=t.network,e.next=3,_t(n,r);case 3:return o=e.sent,i=Et(o,Pe(a,U.V2)),u=null,i&&(u={asset1ID:i[Ft[U.V2].asset1],asset2ID:i[Ft[U.V2].asset2],poolTokenID:i[Ft[U.V2].poolTokenID]}),e.abrupt("return",u);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jt=Object.freeze({__proto__:null,getPoolAssets:function(e){return zt.apply(this,arguments)},getPoolInfo:qt,getPoolReserves:function(e,t){return Wt.apply(this,arguments)}});function Kt(e){return Boolean(e&&!(e.asset1+e.asset2))}var Yt,Ht=Object.freeze({__proto__:null,getPoolPairRatio:function(e){var t=Kt(e),n=null;return e&&!t&&e.asset1&&e.asset2&&(n=Number(e.asset1)/Number(e.asset2)),n},getPoolShare:function(e,t){var n=Number(t)/Number(e);return Number.isFinite(n)||(n=0),n},getPoolsForPair:function(e){return Promise.all([Ut(e),qt(e)])},isPoolEmpty:Kt,isPoolNotCreated:function(e){return(null==e?void 0:e.status)===Ct.NOT_CREATED},isPoolReady:function(e){return(null==e?void 0:e.status)===Ct.READY}}),$t=a((l(Yt={},U.V1_1,a(a({},Xt),Ht)),l(Yt,U.V2,a(a({},Jt),Ht)),Yt),Ht),Zt=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e[e.POOL_TOKEN_CREATE=2]="POOL_TOKEN_CREATE",e[e.ASSET1_OPT_IN=3]="ASSET1_OPT_IN",e[e.ASSET2_OPT_IN=4]="ASSET2_OPT_IN",e}({}),en={ASA_ALGO:96e4,ASA_ASA:859e3};function tn(){return(tn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T,k,_,E,P,S;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Z(o,i),l=v(p,2),d=l[0],f=d.id,m=d.unit_name,h=l[1],g=h.id,x=h.unit_name,A=te(g),I=Pe(a,U.V1_1),w=wt.generateLogicSigAccountForPool({network:a,asset1ID:f,asset2ID:g}),y=w.address(),b=e.makeApplicationOptInTxnFromObject({from:y,appIndex:I,note:_e.getAppCallTxnNoteWithClientName(U.V1_1),appArgs:[Te("bootstrap"),e.encodeUint64(f),e.encodeUint64(g)],foreignAssets:A?[f]:[g],suggestedParams:c}),T=e.makeAssetCreateTxnWithSuggestedParamsFromObject({from:y,total:0xffffffffffffffffn,decimals:6,defaultFrozen:!1,unitName:G.V1_1,assetName:"TinymanPool1.1 ".concat(m,"-").concat(x),assetURL:"https://tinyman.org",suggestedParams:c}),k=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:f,amount:0,suggestedParams:c}),_=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:y,amount:nn(A),suggestedParams:c}),(E=[])[Zt.FUNDING_TXN]=_,E[Zt.VALIDATOR_APP_CALL]=b,E[Zt.POOL_TOKEN_CREATE]=T,E[Zt.ASSET1_OPT_IN]=k,A||(E[Zt.ASSET2_OPT_IN]=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:g,amount:0,suggestedParams:c})),P=e.assignGroupID(E),S=[{txn:P[Zt.FUNDING_TXN],signers:[u]},{txn:P[Zt.VALIDATOR_APP_CALL],signers:[y]},{txn:P[Zt.POOL_TOKEN_CREATE],signers:[y]},{txn:P[Zt.ASSET1_OPT_IN],signers:[y]}],P[Zt.ASSET2_OPT_IN]&&S.push({txn:P[Zt.ASSET2_OPT_IN],signers:[y]}),t.abrupt("return",S);case 23:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function nn(e){return e?en.ASA_ALGO:en.ASA_ASA}function rn(){return(rn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=wt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===Zt.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function an(e){return sn.apply(this,arguments)}function sn(){return(sn=i(s().mark((function e(t){var n,r,a,o,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.signedTxns,a=t.txnIDs,e.prev=1,e.next=4,n.sendRawTransaction(r).do();case 4:return e.next=6,de(n,a[Zt.POOL_TOKEN_CREATE]);case 6:if(o=e.sent,"number"==typeof(i=o["asset-index"])){e.next=10;break}throw new Error("Generated ID is not valid: got ".concat(i));case 10:return e.abrupt("return",{poolTokenID:i});case 13:throw e.prev=13,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while bootstraping the pool. Try again later.");case 16:case"end":return e.stop()}}),e,null,[[1,13]])})))).apply(this,arguments)}function on(){return(on=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.signedTxns,c=t.txnIDs,e.next=3,an({client:n,signedTxns:u,txnIDs:c});case 3:return e.abrupt("return",$t.v1_1.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var un={generateTxns:function(e){return tn.apply(this,arguments)},signTxns:function(e){return rn.apply(this,arguments)},execute:function(e){return on.apply(this,arguments)},getBootstrapFundingTxnAmount:nn};var cn=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e}({}),pn={ASA_ALGO:5,ASA_ASA:6};function ln(e,t){return dn.apply(this,arguments)}function dn(){return(dn=i(s().mark((function t(n,r){var a,o,i;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(o=null===(a=r.find((function(e){return"appl"===e.txn.type})))||void 0===a?void 0:a.txn.txID())){t.next=7;break}return t.next=4,e.waitForConfirmation(n,o,R);case 4:t.t0=t.sent,t.next=8;break;case 7:t.t0=void 0;case 8:return i=t.t0,t.abrupt("return",i);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function fn(e,t){return mn.apply(this,arguments)}function mn(){return(mn=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ln(t,n);case 2:return r=e.sent,e.abrupt("return",null==r?void 0:r["inner-txns"]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function hn(e,t){return gn.apply(this,arguments)}function gn(){return(gn=i(s().mark((function t(n,r){var a,o;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fn(n,r);case 2:return a=t.sent,s=r[0].txn,o=e.encodeAddress(s.from.publicKey),t.abrupt("return",null==a?void 0:a.reduce((function(t,n){var r=t,a=n.txn.txn;return a.type===e.TransactionType.axfer&&e.encodeAddress(a.arcv)===o?r.push({id:a.xaid,amount:a.aamt}):a.type===e.TransactionType.pay&&e.encodeAddress(a.rcv)===o&&r.push({id:j,amount:a.amt}),r}),[]));case 5:case"end":return t.stop()}var s}),t)})))).apply(this,arguments)}function xn(){return(xn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Pe(a,U.V2),l=e.getApplicationAddress(p),d=Z(o,i),f=v(d,2),m=f[0].id,h=f[1].id,t.next=9,$t.v2.getPoolInfo({client:r,network:a,asset1ID:m,asset2ID:h});case 9:if(t.sent.status!==Ct.READY){t.next=12;break}throw new Error("Pool for ".concat(o.unit_name,"-").concat(i.unit_name," already exists"));case 12:return g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=g.address(),A=te(h),(I=e.makeApplicationOptInTxnFromObject({from:x,appIndex:p,appArgs:[Te("bootstrap")],note:_e.getAppCallTxnNoteWithClientName(U.V2),foreignAssets:[m,h],rekeyTo:l,suggestedParams:c})).fee=In(A),w=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:x,amount:An(A),suggestedParams:c}),(y=[])[cn.FUNDING_TXN]=w,y[cn.VALIDATOR_APP_CALL]=I,b=e.assignGroupID(y),(T=[])[cn.FUNDING_TXN]={txn:b[cn.FUNDING_TXN],signers:[u]},T[cn.VALIDATOR_APP_CALL]={txn:b[cn.VALIDATOR_APP_CALL],signers:[x]},t.abrupt("return",T);case 26:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function An(e){return function(e,t){var n=kt(e).schema,r=n.numLocalInts,a=n.numLocalByteSlices,s=S+D+D+O+F*r+C*a;return t||(s+=D),s}(U.V2,e)+In(e)+D}function In(t){return((t?pn.ASA_ALGO:pn.ASA_ASA)+1)*e.ALGORAND_MIN_TX_FEE}function vn(){return(vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===cn.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function wn(){return(wn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.txGroup,c=t.signedTxns,e.prev=1,e.next=4,n.sendRawTransaction(c).do();case 4:return e.next=6,ln(n,u);case 6:if(e.t1=p=e.sent,e.t0=null===e.t1,e.t0){e.next=10;break}e.t0=void 0===p;case 10:if(!e.t0){e.next=14;break}e.t2=void 0,e.next=15;break;case 14:e.t2=null===(l=p["local-state-delta"][0].delta)||void 0===l||null===(d=l.find((function(e){return e.key===btoa(Ft.v2.poolTokenID)})))||void 0===d?void 0:d.value.uint;case 15:if("number"==typeof(f=e.t2)){e.next=18;break}throw new Error("Generated ID is not valid: got ".concat(f));case 18:return e.abrupt("return",$t.v2.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 21:throw e.prev=21,e.t3=e.catch(1),new Y(e.t3,"We encountered something unexpected while bootstraping the pool. Try again later.");case 24:case"end":return e.stop()}}),e,null,[[1,21]])})))).apply(this,arguments)}var yn,bn={generateTxns:function(e){return xn.apply(this,arguments)},signTxns:function(e){return vn.apply(this,arguments)},execute:function(e){return wn.apply(this,arguments)},getBootstrapFundingTxnAmount:An,getTotalCost:function(t){return e.ALGORAND_MIN_TX_FEE+An(t)}};var Tn,kn,_n,En,Pn=(l(yn={},U.V1_1,un),l(yn,U.V2,bn),l(yn,"generateTxns",(function(e){return e.contractVersion===U.V1_1?un.generateTxns(e):bn.generateTxns(e)})),l(yn,"signTxns",(function(e){return e.contractVersion===U.V1_1?un.signTxns(e):bn.signTxns(e)})),l(yn,"execute",(function(e){return e.contractVersion===U.V1_1?un.execute(e):bn.execute(e)})),l(yn,"calculateBootstrapFundingTxnAmount",(function(e){var t=e.contractVersion,n=e.isAlgoPool;return t===U.V1_1?un.getBootstrapFundingTxnAmount(n):bn.getBootstrapFundingTxnAmount(n)})),yn),Sn=function(e){return e[e.FEE_TXN=0]="FEE_TXN",e[e.VALIDATOR_APP_CALL_TXN=1]="VALIDATOR_APP_CALL_TXN",e[e.ASSET1_IN_TXN=2]="ASSET1_IN_TXN",e[e.ASSET2_IN_TXN=3]="ASSET2_IN_TXN",e[e.LIQUDITY_OUT_TXN=4]="LIQUDITY_OUT_TXN",e}({}),Dn=5*e.ALGORAND_MIN_TX_FEE,On=function(e){return e.SINGLE="single",e.FLEXIBLE="flexible",e.INITIAL="initial",e}({}),Nn=(l(Tn={},On.FLEXIBLE,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),l(Tn,On.SINGLE,{ASSET_IN_TXN:0,VALIDATOR_APP_CALL_TXN:1}),l(Tn,On.INITIAL,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),Tn),Bn=(l(kn={},On.INITIAL,1),l(kn,On.SINGLE,2),l(kn,On.FLEXIBLE,2),kn),Cn=(l(_n={},On.INITIAL,3),l(_n,On.FLEXIBLE,3),l(_n,On.SINGLE,2),_n);function Fn(e){var t,n,r,a=e.reserves,s=e.totalFeeShare,o=e.asset1,i=e.asset2,u=a.asset1*a.asset2,c=a.asset1+BigInt(o.amount),p=a.asset2+BigInt(i.amount),l=c*p,d=BigInt(parseInt(String(Math.sqrt(Number(l*a.issuedLiquidity*a.issuedLiquidity/u))))),f=d-a.issuedLiquidity,m=f*c/d,h=f*p/d,g=BigInt(o.amount)-m,x=BigInt(i.amount)-h;if(g>x){var A=g;r=Rn(A,s),t={id:o.id,amount:A+r,decimals:o.decimals,reserves:a.asset1},n={id:i.id,amount:BigInt(Math.abs(Math.min(Number(x),0))),decimals:i.decimals,reserves:a.asset2},f-=r*d/(c*BigInt(2))}else{var I=x;r=Rn(I,s),t={id:i.id,amount:I+r,decimals:i.decimals,reserves:a.asset2},n={id:o.id,amount:BigInt(Math.abs(Math.min(Number(g),0))),decimals:o.decimals,reserves:a.asset1},f-=r*d/(p*BigInt(2))}return{poolTokenOutAmount:f,internalSwapQuote:{assetIn:t,assetOut:n,swapFees:r,priceImpact:pt({inputSupply:t.reserves,outputSupply:n.reserves,assetIn:t,assetOut:n})}}}function Ln(e,t){if(!e.amount||!t.amount)throw new Error("Both assets are required for the initial add liquidity");return BigInt(Math.floor(Math.abs(Math.sqrt(Number(e.amount)*Number(t.amount))-Lt)))}function Rn(e,t){return e*BigInt(t)/(BigInt(1e4)-BigInt(t))}function Mn(t){return(Bn[t]+1)*e.ALGORAND_MIN_TX_FEE}var Un=Te("add_liquidity"),jn=(l(En={},U.V1_1,[Te("mint")]),l(En,U.V2,{INITIAL_LIQUIDITY:[Te("add_initial_liquidity")],SINGLE_ASSET_MODE:[Un,Te("single")],FLEXIBLE_MODE:[Un,Te("flexible")]}),En);function Vn(){return(Vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.asset1In,u=n.asset2In,c=n.poolTokenOut,p=n.slippage,l=n.initiatorAddr,d=me("negative",p,c.amount),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:Pe(a,U.V1_1),appArgs:jn.v1_1,accounts:[l],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:u.id==j?[i.id,c.id]:[i.id,u.id,c.id],suggestedParams:f}),h=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:i.id,amount:i.amount,suggestedParams:f}),g=u.id===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:u.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:u.id,amount:u.amount,suggestedParams:f}),x=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:l,assetIndex:c.id,amount:d,suggestedParams:f}),A=e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:m.fee+x.fee,note:P,suggestedParams:f}),I=e.assignGroupID([A,m,h,g,x]),t.abrupt("return",[{txn:I[0],signers:[l]},{txn:I[1],signers:[o]},{txn:I[2],signers:[l]},{txn:I[3],signers:[l]},{txn:I[4],signers:[o]}]);case 12:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Gn(){return(Gn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,i=r.account,t.next=4,o([a]);case 4:return u=t.sent,c=v(u,3),p=c[0],l=c[1],d=c[2],f=a.map((function(t,n){return n===Sn.FEE_TXN?p:n===Sn.ASSET1_IN_TXN?l:n===Sn.ASSET2_IN_TXN?d:e.signLogicSigTransactionObject(t.txn,i).blob})),t.abrupt("return",f);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Xn(){return(Xn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.signedTxns,i=t.initiatorAddr,e.prev=1,u=BigInt(a[Sn.LIQUDITY_OUT_TXN].txn.amount),e.next=5,Dt({client:n,pool:r,accountAddr:i});case 5:return c=e.sent,e.next=8,Ie(n,[o]);case 8:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,h=we(a),g=ye(a),e.next=17,Dt({client:n,pool:r,accountAddr:i});case 17:return x=e.sent,(A=x.excessPoolTokens-c.excessPoolTokens)<0n&&(A=0n),e.abrupt("return",{round:f,fees:h,poolTokenID:r.poolTokenID,poolTokenOut:u+A,excessAmount:{excessAmountForAddingLiquidity:A,totalExcessAmount:x.excessPoolTokens},txnID:m,groupID:g});case 23:throw e.prev=23,e.t0=e.catch(1),"SlippageTolerance"===(I=new Y(e.t0,"We encountered something unexpected while adding liquidity. Try again later.")).type&&I.setMessage("Adding liquidity failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),I;case 28:case"end":return e.stop()}}),e,null,[[1,23]])})))).apply(this,arguments)}var qn=Object.freeze({__proto__:null,execute:function(e){return Xn.apply(this,arguments)},generateTxns:function(e){return Vn.apply(this,arguments)},getQuote:function(e){var t=e.pool,n=e.reserves,r=e.asset1In,a=e.asset2In;if(0n===n.issuedLiquidity){var s=BigInt(Math.floor(Math.sqrt(Number(r)*Number(a))));if(s<=BigInt(L))throw new Error("Initial liquidity amount is too small. The amount must be greater than ".concat(L,", this quote is for ").concat(s,"."));return{round:n.round,asset1ID:t.asset1ID,asset1In:BigInt(r),asset2ID:t.asset2ID,asset2In:BigInt(a),poolTokenID:t.poolTokenID,poolTokenOut:s-BigInt(L),share:1}}var o=BigInt(r)*n.issuedLiquidity/n.asset1,i=BigInt(a)*n.issuedLiquidity/n.asset2,u=oo)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(t)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{assetInID:i,assetInAmount:l,assetOutID:c,assetOutAmount:m,swapFee:Number(h),rate:he(p,Number(m))/he(u,Number(l)),priceImpact:g}}function xr(e){var t=e.amount,n=e.assetIn,r=e.assetOut,a=e.pool;if(!a||!$t.isPoolReady(a))throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i=n.id,u=n.decimals,c=r.id,p=r.decimals,l=BigInt(t),d=a.totalFeeShare;if(c===a.asset1ID)s=a.asset2Reserves,o=a.asset1Reserves;else{if(c!==a.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(c,") doesn't belong to the pool ").concat(a.account.address(),"."));s=a.asset1Reserves,o=a.asset2Reserves}var f=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapOutputAmount,a=e.totalFeeShare,s=e.decimals,o=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.outputAmount,a=t*n,s=BigInt(a/(n-r))-t;return s+=BigInt(1),s}({inputSupply:t,outputSupply:n,outputAmount:r}),i=function(e){var t=e.swapAmount,n=e.totalFeeShare,r=Math.floor(Number(t*BigInt(1e4)/(BigInt(1e4)-BigInt(n)))),a=BigInt(r)-t;return a}({swapAmount:o,totalFeeShare:a}),u=o+i,c=pt({inputSupply:t,outputSupply:n,assetIn:{amount:u,decimals:s.assetIn},assetOut:{amount:r,decimals:s.assetOut}});return{swapInputAmount:u,totalFeeAmount:i,priceImpact:c}}({inputSupply:s,outputSupply:o,swapOutputAmount:l,totalFeeShare:d,decimals:{assetIn:u,assetOut:p}}),m=f.swapInputAmount,h=f.totalFeeAmount,g=f.priceImpact;if(l>o)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(m)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{type:rt.Direct,data:{pool:a,quote:{assetInID:i,assetInAmount:m,assetOutID:c,assetOutAmount:l,swapFee:Number(h),rate:he(p,Number(l))/he(u,Number(m)),priceImpact:g}}}}function Ar(e){return Ir.apply(this,arguments)}function Ir(){return(Ir=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[],u?c.push(new Promise((function(e,t){try{var s=gr({amount:n,assetIn:r,assetOut:a,pool:u});e({type:rt.Direct,data:{pool:u,quote:s}})}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair"))),o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedInput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=6,hr(c);case 6:return p=e.sent,e.abrupt("return",ht(p));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function vr(e){return wr.apply(this,arguments)}function wr(){return(wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[new Promise((function(e,t){try{e(xr({amount:n,assetIn:r,assetOut:a,pool:u}))}catch(e){t(e)}}))],o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedOutput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=5,hr(c);case 5:return p=e.sent,e.abrupt("return",ht(p));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function yr(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapInputAmount,a=e.totalFeeShare,s=e.decimals,o=BigInt(function(e){var t=e.inputAmount,n=e.totalFeeShare;return Math.floor(Number(t*BigInt(n))/1e4)}({inputAmount:r,totalFeeShare:a})),i=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapAmount,a=t*n,s=n-BigInt(a/(t+BigInt(r)));return s-=BigInt(1)}({inputSupply:t,outputSupply:n,swapAmount:r-o});return{swapOutputAmount:i,totalFeeAmount:o,priceImpact:pt({inputSupply:t,outputSupply:n,assetIn:{amount:r,decimals:s.assetIn},assetOut:{amount:i,decimals:s.assetOut}})}}var br={getQuote:function(e){return mr.apply(this,arguments)},getFixedInputSwapQuote:Ar,getFixedInputDirectSwapQuote:gr,getFixedOutputDirectSwapQuote:xr,getFixedOutputSwapQuote:vr,generateTxns:function(e){return dr.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return fr.apply(this,arguments)},calculateFixedInputSwap:yr};function Tr(e,t){var n,r,a=BigInt(e),s=t.issuedLiquidity;return s>a+BigInt(Lt)?(n=a*t.asset1/s,r=a*t.asset2/s):(n=t.asset1,r=t.asset2),{asset1OutputAmount:n,asset2OutputAmount:r}}function kr(){return(kr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.minAsset1Amount,c=n.minAsset2Amount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.account.address(),f=a.poolTokenID){t.next=8;break}throw new Error("Pool token asset ID is missing");case 8:return m=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:f,amount:o,suggestedParams:l}),(h=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(me("negative",p,u)),e.encodeUint64(me("negative",p,c))],accounts:[d],foreignAssets:[a.asset1ID,a.asset2ID],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(g=[])[ir.ASSET_TRANSFER_TXN]=m,g[ir.APP_CALL_TXN]=h,x=e.assignGroupID(g),t.abrupt("return",[{txn:x[ir.ASSET_TRANSFER_TXN],signers:[i]},{txn:x[ir.APP_CALL_TXN],signers:[i]}]);case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _r(){return(_r=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.initiatorAddr,i=n.poolTokenIn,u=n.outputAssetId,c=n.minOutputAssetAmount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.asset1ID,f=a.asset2ID,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:if(g=0,x=0,A=me("negative",p,c),u!==d){t.next=17;break}g=A,x=0,t.next=23;break;case 17:if(u!==f){t.next=22;break}g=0,x=A,t.next=23;break;case 22:throw new Error("Invalid output asset id. It doesn't match with pool assets");case 23:return I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:m,assetIndex:h,amount:i,suggestedParams:l}),(v=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(g),e.encodeUint64(x)],accounts:[m],foreignAssets:[u],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(w=[])[ir.ASSET_TRANSFER_TXN]=I,w[ir.APP_CALL_TXN]=v,y=e.assignGroupID(w),t.abrupt("return",[{txn:y[ir.ASSET_TRANSFER_TXN],signers:[o]},{txn:y[ir.APP_CALL_TXN],signers:[o]}]);case 31:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Er(){return(Er=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.txGroup,a=t.signedTxns,e.next=3,Ie(n,[a]);case 3:return o=e.sent,i=v(o,1),u=i[0].txnID,e.prev=6,e.next=9,hn(n,r);case 9:c=e.sent,e.next=14;break;case 12:e.prev=12,e.t0=e.catch(6);case 14:return e.abrupt("return",{outputAssets:c,txnID:u});case 15:case"end":return e.stop()}}),e,null,[[6,12]])})))).apply(this,arguments)}var Pr,Sr={getQuote:function(e){var t=e.pool,n=e.reserves,r=e.poolTokenIn,a=BigInt(r),s=Tr(a,n),o=s.asset1OutputAmount,i=s.asset2OutputAmount;return{round:n.round,asset1Out:{assetId:t.asset1ID,amount:o},asset2Out:{assetId:t.asset2ID,amount:i},poolTokenIn:{assetId:t.poolTokenID,amount:a}}},getSingleAssetRemoveLiquidityQuote:function(e){var t,n=e.pool,r=e.reserves,a=e.poolTokenIn,s=e.assetOutID,o=e.decimals,i=BigInt(a),u=Tr(i,r),c=u.asset1OutputAmount,p=u.asset2OutputAmount,l=n.totalFeeShare;if(s===n.asset1ID){var d=br.calculateFixedInputSwap({inputSupply:r.asset2-p,outputSupply:r.asset1-c,swapInputAmount:p,totalFeeShare:l,decimals:o}),f=d.swapOutputAmount,m=d.totalFeeAmount,h=d.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:c+f},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:f},swapFees:{assetId:n.asset2ID,amount:m},priceImpact:h}}}else{if(s!==n.asset2ID)throw new Error("assetOutID must be one of the pool assets");var g=br.calculateFixedInputSwap({inputSupply:r.asset1-c,outputSupply:r.asset2-p,swapInputAmount:c,totalFeeShare:l,decimals:o}),x=g.swapOutputAmount,A=g.totalFeeAmount,I=g.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:p+x},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:x},swapFees:{assetId:n.asset2ID,amount:A},priceImpact:I}}}return t},generateTxns:function(e){return kr.apply(this,arguments)},generateSingleAssetOutTxns:function(e){return _r.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return Er.apply(this,arguments)}},Dr=(l(Pr={},U.V1_1,lr),l(Pr,U.V2,Sr),Pr),Or=3n,Nr=1000n,Br=function(e){return e[e.FEE_TXN_INDEX=0]="FEE_TXN_INDEX",e[e.VALIDATOR_APP_CALL_TXN_INDEX=1]="VALIDATOR_APP_CALL_TXN_INDEX",e[e.ASSET_IN_TXN_INDEX=2]="ASSET_IN_TXN_INDEX",e[e.ASSET_OUT_TXN_INDEX=3]="ASSET_OUT_TXN_INDEX",e}(Br||{});function Cr(){return(Cr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,t.next=3,o([a]);case 3:return i=t.sent,u=v(i,2),c=u[0],p=u[1],l=a.map((function(t,n){return n===Br.FEE_TXN_INDEX?c:n===Br.ASSET_IN_TXN_INDEX?p:e.signLogicSigTransactionObject(t.txn,r.account.lsig).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Fr(){return(Fr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=n.client,a=n.quoteAndPool,o=n.swapType,i=n.slippage,u=n.initiatorAddr,c=a.pool,p=a.quote,l=p.assetInID,d=p.assetOutID,f=c.account.address(),(m=[c.asset1ID,c.asset2ID]).includes(l)&&m.includes(d)&&l!==d){t.next=7;break}throw new Y({pool:c,quote:p},"Input asset (#".concat(l,") and output asset (#").concat(d,") provided to generate transactions do not belong to the pool ").concat(f,"."));case 7:return t.next=9,r.getTransactionParams().do();case 9:return h=t.sent,g=[Te("swap"),o===Ce.FixedInput?Te("fi"):Te("fo")],x=e.makeApplicationNoOpTxnFromObject({from:f,appIndex:c.validatorAppID,appArgs:g,accounts:[u],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:c.asset2ID==j?[c.asset1ID,c.poolTokenID]:[c.asset1ID,c.asset2ID,c.poolTokenID],suggestedParams:h}),A=o===Ce.FixedOutput?me("positive",i,p.assetInAmount):p.assetInAmount,I=l===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:A,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:u,to:f,assetIndex:l,amount:A,suggestedParams:h}),v=o===Ce.FixedInput?me("negative",i,p.assetOutAmount):p.assetOutAmount,w=d===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:f,to:u,amount:v,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:f,to:u,assetIndex:d,amount:v,suggestedParams:h}),y=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:x.fee+w.fee,note:P,suggestedParams:h}),b=e.assignGroupID([y,x,I,w]),t.abrupt("return",[{txn:b[0],signers:[u]},{txn:b[1],signers:[f]},{txn:b[2],signers:[u]},{txn:b[3],signers:[f]}]);case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Lr(e){var t=e.pool,n=e.reserves,r=e.assetIn,s=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var o,i,u,c=BigInt(r.amount);if(r.id===t.asset1ID)o=t.asset2ID,i=n.asset1,u=n.asset2;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Input asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));o=t.asset1ID,i=n.asset2,u=n.asset1}var p=c*Or/Nr,l=u-i*u/(i+(c-p));if(l>u)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var d={assetIn:{amount:c,decimals:s.assetIn},assetOut:{amount:l,decimals:s.assetOut}},f={round:n.round,assetInID:r.id,assetInAmount:c,assetOutID:o,assetOutAmount:l,swapFee:Number(p),rate:ct(d),priceImpact:pt(a({inputSupply:i,outputSupply:u},d))};return{type:rt.Direct,data:{pool:t,quote:f}}}function Rr(e){return Mr.apply(this,arguments)}function Mr(){return(Mr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,i.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount),assetOutID:i.id,assetOutAmount:BigInt(i.amount)+A,excessAmount:{assetID:i.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ur(e){var t=e.pool,n=e.reserves,r=e.assetOut,a=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i,u=BigInt(r.amount);if(r.id===t.asset1ID)s=t.asset2ID,o=n.asset2,i=n.asset1;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));s=t.asset1ID,o=n.asset1,i=n.asset2}if(u>i)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var c=o*i/(i-u)-o,p=c*Nr/(Nr-Or),l=p-c,d=he(a.assetOut,Number(u))/he(a.assetIn,Number(p)),f=he(a.assetOut,Number(i))/he(a.assetIn,Number(o)),m=ge({decimalPlaces:5},Math.abs(d/f-1)),h={round:n.round,assetInID:s,assetInAmount:p,assetOutID:r.id,assetOutAmount:u,swapFee:Number(l),rate:d,priceImpact:m};return{type:rt.Direct,data:{pool:t,quote:h}}}function jr(e){return Vr.apply(this,arguments)}function Vr(){return(Vr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,o.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount)-A,assetOutID:i.id,assetOutAmount:BigInt(i.amount),excessAmount:{assetID:o.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Gr(){return(Gr=i(s().mark((function e(t){var n,r,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.pool,o=t.swapType,i=t.txGroup,u=t.signedTxns,c=t.initiatorAddr,r.status===Ct.READY){e.next=3;break}throw new Y({pool:r,swapType:o,txGroup:i},"There is not an available pool for this asset pair");case 3:if(e.prev=3,p={id:i[Br.ASSET_IN_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_IN_TXN_INDEX].txn.amount},l={id:i[Br.ASSET_OUT_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_OUT_TXN_INDEX].txn.amount},o!==Ce.FixedInput){e.next=12;break}return e.next=9,Rr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 9:d=e.sent,e.next=15;break;case 12:return e.next=14,jr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 14:d=e.sent;case 15:return e.abrupt("return",a(a({},d),{},{groupID:ye(i),fees:we(i)}));case 18:throw e.prev=18,e.t0=e.catch(3),"SlippageTolerance"===(f=new Y(e.t0,"We encountered something unexpected while swapping. Try again later.")).type&&f.setMessage("The swap failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),f;case 23:case"end":return e.stop()}}),e,null,[[3,18]])})))).apply(this,arguments)}var Xr,qr={getQuote:function(e,t,n,r,a){return e===Ce.FixedInput?Lr({pool:t,reserves:n,assetIn:r,decimals:a}):Ur({pool:t,reserves:n,assetOut:r,decimals:a})},getFixedInputSwapQuote:Lr,getFixedOutputSwapQuote:Ur,generateTxns:function(e){return Fr.apply(this,arguments)},signTxns:function(e){return Cr.apply(this,arguments)},execute:function(e){return Gr.apply(this,arguments)},executeFixedOutputSwap:jr};function Qr(e){return Promise.allSettled(e).then((function(e){if(e.every((function(e){return"rejected"===e.status}))){var t=v(e.map((function(e){return e.reason})),2),n=t[0],r=t[1];if(gt(n)&&!gt(r))throw n;throw r}return e.filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value}))}))}function Wr(){return(Wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.isSwapRouterEnabled,u=t.pools,c=[],(p=u.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedInputSwapQuote({pool:p.info,assetIn:{amount:r,id:Number(a.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=u.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedInputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:i,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zr(){return(zr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.pools,u=t.isSwapRouterEnabled,c=[],(p=i.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedOutputSwapQuote({pool:p.info,assetOut:{amount:r,id:Number(o.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=i.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedOutputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:u,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jr=(l(Xr={},U.V1_1,qr),l(Xr,U.V2,br),l(Xr,"getQuote",(function(e){var t=e.type;if(t===Ce.FixedInput)return function(e){return Wr.apply(this,arguments)}(e);if(t===Ce.FixedOutput)return function(e){return zr.apply(this,arguments)}(e);throw new E(_.InvalidSwapTypeError,"Invalid swap type")})),l(Xr,"generateTxns",(function(e){return e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1?qr.generateTxns(a(a({},e),{},{quoteAndPool:e.quote.data})):br.generateTxns(e)})),l(Xr,"signTxns",(function(e){if(e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1){var t=e.quote.data.pool;return qr.signTxns(a(a({},e),{},{pool:t}))}return br.signTxns(e)})),l(Xr,"execute",(function(e){return e.contractVersion===U.V1_1?qr.execute(e):br.execute(e)})),Xr);function Kr(){return(Kr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.initiatorSigner,e.prev=1,e.next=4,Yr({txGroup:a,pool:r,initiatorSigner:o});case 4:return i=e.sent,e.next=7,Ie(n,[i]);case 7:return u=e.sent,c=v(u,1),p=c[0],l=p.txnID,d=p.confirmedRound,e.abrupt("return",{fees:we(a),confirmedRound:d,txnID:l,groupID:ye(a)});case 15:throw e.prev=15,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while redeeming. Try again later.");case 18:case"end":return e.stop()}}),e,null,[[1,15]])})))).apply(this,arguments)}function Yr(e){return Hr.apply(this,arguments)}function Hr(){return(Hr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.pool,o=n.initiatorSigner,t.next=3,o([r]);case 3:return i=t.sent,u=v(i,1),c=u[0],p=a.account.lsig,l=r.map((function(t,n){return 0===n?c:e.signLogicSigTransactionObject(t.txn,p).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function $r(){return $r=i(s().mark((function t(n){var r,a,o,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.data,o=n.initiatorSigner,t.prev=1,u=a.map((function(e){var t=e.txGroup,n=e.pool;return{txns:t,txnFees:we(t),groupID:ye(t),lsig:n.account.lsig}})),t.next=5,o(u.map((function(e){return e.txns})));case 5:return c=t.sent,p=Promise.all(u.map((function(t,n){return new Promise(function(){var a=i(s().mark((function a(o,i){var u,p,l,d,f,m;return s().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,u=t.txns.map((function(r,a){return 0===a?c[n]:e.signLogicSigTransactionObject(r.txn,t.lsig).blob})),a.next=4,Ie(r,[u]);case 4:p=a.sent,l=v(p,1),d=l[0],f=d.txnID,m=d.confirmedRound,o({fees:t.txnFees,groupID:t.groupID,txnID:f,confirmedRound:m}),a.next=15;break;case 12:a.prev=12,a.t0=a.catch(0),i(a.t0);case 15:case"end":return a.stop()}}),a,null,[[0,12]])})));return function(e,t){return a.apply(this,arguments)}}())}))),t.abrupt("return",p);case 10:throw t.prev=10,t.t0=t.catch(1),new Y(t.t0,"We encountered something unexpected while redeeming. Try again later.");case 13:case"end":return t.stop()}}),t,null,[[1,10]])}))),$r.apply(this,arguments)}function Zr(){return(Zr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.assetID,i=n.assetOut,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=a.account.address(),l=e.makeApplicationNoOpTxnFromObject({from:p,appIndex:a.validatorAppID,appArgs:[Te("redeem")],note:_e.getAppCallTxnNoteWithClientName(a.contractVersion),accounts:[u],foreignAssets:0==a.asset2ID?[a.asset1ID,a.poolTokenID]:[a.asset1ID,a.asset2ID,a.poolTokenID],suggestedParams:c}),d=0===o?e.makePaymentTxnWithSuggestedParamsFromObject({from:p,to:u,amount:BigInt(i),suggestedParams:c}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:p,to:u,assetIndex:o,amount:BigInt(i),suggestedParams:c}),f=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:p,amount:l.fee+d.fee,note:P,suggestedParams:c}),m=e.assignGroupID([f,l,d]),t.abrupt("return",[{txn:m[0],signers:[u]},{txn:m[1],signers:[p]},{txn:m[2],signers:[p]}]);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ea(e){var t,n={},r=T(e);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=(new TextDecoder).decode(Buffer.from(a.key,"base64")),o=void 0;o=1===a.value.type?a.value.bytes:a.value.uint,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function ta(e,t,n){return e*t/n}var na=BigInt(31536e3),ra=BigInt(1e14),aa=BigInt(1e16),sa={testnet:548587153,mainnet:1385499515},oa=14;function ia(e){return ua.apply(this,arguments)}function ua(){return(ua=i(s().mark((function t(n){var r,a,o,i,u;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(sa[a]),t.next=4,_t(r,i);case 4:return u=t.sent.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!u.includes(e)})));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ca(){return(ca=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,y,b,T,k,_,E,P;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.poolTokenId,u=n.lendingManagerId,c=n.asset1In,p=n.asset2In,l=n.initiatorAddr,d=e.getApplicationAddress(sa[a]),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=[c,p].sort((function(e,t){return t.fAssetId-e.fAssetId})),h=v(m,2),g=h[0],x=h[1],A=te(x.id),I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:g.id,amount:g.amount,suggestedParams:f}),y=A?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:x.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:x.id,amount:x.amount,suggestedParams:f}),(b=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("add_liquidity"),e.decodeAddress(o).publicKey,e.encodeUint64(g.lendingAppId),e.encodeUint64(x.lendingAppId)],foreignAssets:[g.id,x.id,g.fAssetId,x.fAssetId],foreignApps:[g.lendingAppId,x.lendingAppId,u],accounts:[o],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),T=Pe(a,U.V2),k=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("noop")],foreignAssets:[i],foreignApps:[T],accounts:[o],suggestedParams:f}),_=[I,y,b,k],t.next=16,ia({client:r,network:a,assetIDs:[g.id,x.id,g.fAssetId,x.fAssetId,i]});case 16:return(E=t.sent).length&&((P=[e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:D*E.length,suggestedParams:f}),e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("asset_optin")].concat(w(E.map((function(t){return e.encodeUint64(t)})))),foreignAssets:w(E),suggestedParams:f})])[1].fee=(E.length+1)*e.ALGORAND_MIN_TX_FEE,_.unshift.apply(_,P)),t.abrupt("return",e.assignGroupID(_).map((function(e){return{txn:e,signers:[l]}})));case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function pa(){return(pa=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.asset1Out,c=n.asset2Out,p=n.lendingManagerId,l=n.network,d=e.getApplicationAddress(sa[l]),t.next=4,r.getTransactionParams().do();case 4:if(f=t.sent,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:return g=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:h,amount:o,suggestedParams:f}),(x=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("remove_liquidity"),e.decodeAddress(m).publicKey,e.encodeUint64(u.lendingAppId),e.encodeUint64(c.lendingAppId)],accounts:[m],foreignAssets:[u.id,c.id,u.fAssetId,c.fAssetId],foreignApps:[u.lendingAppId,c.lendingAppId,p],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),A=Pe(l,U.V2),I=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("noop")],accounts:[m],foreignAssets:[h,u.fAssetId,c.fAssetId],foreignApps:[A],suggestedParams:f}),v=e.assignGroupID([g,x,I]),t.abrupt("return",v.map((function(e){return{txn:e,signers:[i]}})));case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function la(e,t,n){var r=BigInt(Math.floor((new Date).getTime()/1e3)-function(e){return null!=e?e:Math.floor((new Date).getTime()/1e3)}(n));return ta(e,aa+t*r/na,aa)}function da(){return(da=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,a=r.params["global-state"],o=ea(a),i=Number(Buffer.from(o.pm,"base64").readBigUInt64BE(0)),u=Buffer.from(o.i,"base64"),c=u.readBigUInt64BE(32),p=u.readBigUInt64BE(40),l=Number(u.readBigUInt64BE(48)),e.abrupt("return",{appId:n,managerAppId:i,depositInterestRate:c,depositInterestIndex:p,lastUpdate:l});case 11:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var fa={AddLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return ca.apply(this,arguments)},getAddLiquidityTotalFee:function(t){return e.ALGORAND_MIN_TX_FEE*(4+oa)+(t?(t+1)*e.ALGORAND_MIN_TX_FEE+t*D:0)}}),RemoveLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return pa.apply(this,arguments)},getRemoveLiquidityTotalFee:function(){return e.ALGORAND_MIN_TX_FEE*(3+oa)}}),calculateWithdrawReturn:function(e){var t=e.withdrawAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return ta(BigInt(t),n,ra)},calculateDepositReturn:function(e){var t=e.depositAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return BigInt(t)*ra/n},getFolksWrapperAppOptInRequiredAssetIDs:ia};function ma(t){var n=t.suggestedParams,r=t.stakingAppID,a=t.initiatorAddr,s=t.liquidityAssetID,o=t.program,i=t.amount,u=e.encodeUint64(i),c=e.encodeUint64(o.id);return e.makeApplicationNoOpTxnFromObject({appIndex:r,from:a,suggestedParams:n,foreignAssets:[s],accounts:[o.accountAddress],appArgs:[Te("commit"),u],note:ae([Te("tinymanStaking/v1:b"),c,e.encodeUint64(s),u])})}function ha(){return(ha=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.stakingAppID,o=n.program,i=n.requiredAssetID,u=n.liquidityAssetID,c=n.amount,p=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=ma({suggestedParams:l,stakingAppID:a,program:o,liquidityAssetID:u,initiatorAddr:p,amount:c}),f=[d],"number"!=typeof i){t.next=10;break}return m=e.makeApplicationNoOpTxnFromObject({appIndex:a,from:p,suggestedParams:l,foreignAssets:[i],accounts:[o.accountAddress],appArgs:[Te("log_balance")]}),f=e.assignGroupID([d,m]),t.abrupt("return",[{txn:f[0],signers:[p]},{txn:f[1],signers:[p]}]);case 10:return t.abrupt("return",[{txn:f[0],signers:[p]}]);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var ga=604800,xa=1e3,Aa={testnet:480164661,mainnet:2200606875},Ia={testnet:360907790,mainnet:2200609638},va={testnet:336189106,mainnet:2200608153},wa={testnet:383416252,mainnet:2200608887},ya=2500,ba=400,Ta=604800,ka=Te("p"),_a=Te("a"),Ea=24,Pa=111300,Sa=ya+ba*(41+Ea),Da=function(e){return e[e.Against=0]="Against",e[e.For=1]="For",e[e.Abstain=2]="Abstain",e}(Da||{}),Oa=new Uint8Array(34),Na="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ";function Ba(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,n=new Uint8Array(t),r=BigInt(e),a=t-1;a>=0;a--)n[a]=Number(r&BigInt(255)),r>>=BigInt(8);return n}function Ca(e,t){return 0===Buffer.compare(e,t)}function Fa(e){for(var t=0n,n=0;n=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r>>0,o=new Uint8Array(s);e[t];){var p=n[e.charCodeAt(t)];if(255===p)return;for(var l=0,d=s-1;(0!==p||l>>0,o[d]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");a=l,t++}if(" "!==e[t]){for(var f=s-a;f!==s&&0===o[f];)f++;for(var m=new Uint8Array(r+(s-f)),h=r;f!==s;)m[h++]=o[f++];return m}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var n=0,r=0,a=0,s=t.length;a!==s&&0===t[a];)a++,n++;for(var o=(s-a)*p+1>>>0,c=new Uint8Array(o);a!==s;){for(var l=t[a],d=0,f=o-1;(0!==l||d>>0,c[f]=l%i>>>0,l=l/i>>>0;if(0!==l)throw new Error("Non-zero carry");r=d,a++}for(var m=o-r;m!==o&&0===c[m];)m++;for(var h=u.repeat(n);mLa(a(e))})}function Wa({name:e,prefix:t,bitsPerChar:n,alphabet:r}){return qa({prefix:t,name:e,encode:e=>function(e,t,n){const r="="===t[t.length-1],a=(1<n;)o-=n,s+=t[a&i>>o];if(0!==o&&(s+=t[a&i<function(e,t,n,r){const a={};for(let e=0;e=8&&(i-=8,o[c++]=255&u>>i)}if(i>=n||0!=(255&u<<8-i))throw new SyntaxError("Unexpected end of data");return o}(t,r,n,e)})}const za=Wa({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5});Wa({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wa({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wa({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wa({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wa({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wa({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wa({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wa({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});const Ja=Qa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"});Qa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ka=function e(t,n,r){n=n||[];var a=r=r||0;for(;t>=$a;)n[r++]=255&t|Ya,t/=128;for(;t&Ha;)n[r++]=255&t|Ya,t>>>=7;return n[r]=0|t,e.bytes=r-a+1,n},Ya=128,Ha=-128,$a=Math.pow(2,31);var Za=function e(t,n){var r,a=0,s=0,o=n=n||0,i=t.length;do{if(o>=i)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],a+=s<28?(r&ts)<=es);return e.bytes=o-n,a},es=128,ts=127;var ns=Math.pow(2,7),rs=Math.pow(2,14),as=Math.pow(2,21),ss=Math.pow(2,28),os=Math.pow(2,35),is=Math.pow(2,42),us=Math.pow(2,49),cs=Math.pow(2,56),ps=Math.pow(2,63),ls={encode:Ka,decode:Za,encodingLength:function(e){return e{const[n,r]=ds(e.subarray(t));return t+=r,n};let r=n(),a=ws;if(18===r?(r=0,t=0):a=n(),0!==r&&1!==r)throw new RangeError(`Invalid CID version ${r}`);const s=t,o=n(),i=n(),u=t+i;return{version:r,codec:a,multihashCode:o,digestSize:i,multihashSize:u-s,size:u}}static parse(e,t){const[n,r]=function(e,t){switch(e[0]){case"Q":{const n=t??Ja;return[Ja.prefix,n.decode(`${Ja.prefix}${e}`)]}case Ja.prefix:{const n=t??Ja;return[Ja.prefix,n.decode(e)]}case za.prefix:{const n=t??za;return[za.prefix,n.decode(e)]}default:if(null==t)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}(e,t),a=vs.decode(r);if(0===a.version&&"Q"!==e[0])throw Error("Version 0 CID string must not include multibase prefix");return Is(a).set(n,e),a}}const ws=112,ys=18;function bs(e,t,n){const r=ms(e),a=r+ms(t),s=new Uint8Array(a+n.byteLength);return fs(e,s,0),fs(t,s,r),s.set(n,a),s}const Ts=Symbol.for("@ipld/js-cid/CID");class ks{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){const t=this.encode(e);return t instanceof Uint8Array?hs(this.code,t):t.then((e=>hs(this.code,e)))}throw Error("Unknown type, must be binary type")}}const _s=85,Es=function({name:e,code:t,encode:n}){return new ks(e,t,n)}({name:"sha2-256",code:18,encode:e=>La(n.createHash("sha256").update(e).digest())});var Ps=126144e3,Ss=1e7,Ds=Math.pow(2,64),Os=48,Ns=21,Bs=48,Cs=Te("tp"),Fs=Te("sc"),Ls=28100,Rs=12900,Ms=421700,Us=409700;function js(e){var t=e/Ta;return(arguments.length>1&&void 0!==arguments[1]&&arguments[1]?Math.floor(t):Math.ceil(t))*Ta}function Vs(e,t){if(e>t)throw new Error("Old timestamp must be less than or equal to new timestamp");for(var n=[],r=js(e)+Ta;re?r=t?e*e*Ds/(2*t):0:r=(e+(e-r))*n/2;return r}function Js(e,t){return Ks.apply(this,arguments)}function Ks(){return(Ks=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,e.abrupt("return",Ys(r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ys(e){var t,n={},r=T(e.params["global-state"]);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=Buffer.from(a.key,"base64").toString(),o=void 0;o=1===a.value.type?Buffer.from(a.value.bytes||"","base64"):a.value.uint||0,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function Hs(){for(var e=arguments.length,t=new Array(e),n=0;n0?Ns-e:0}},{key:"lastAccountPowerBoxIndex",get:function(){return xo(this.powerCount)[0]}},{key:"lastAccountPowerArrayIndex",get:function(){return xo(this.powerCount)[1]}}]),e}(),uo=function(){function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a}return p(e,[{key:"lockEndTimestamp",get:function(){var e=this.bias*Math.pow(2,64)/this.slope;return this.timestamp+e}},{key:"cumulativePowerAt",value:function(e){var t=e-this.timestamp;if(t<0)throw new Error("Time delta must be greater than or equal to 0");return this.cumulativePower+zs(this.bias,this.slope,t)}}]),e}(),co=p((function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a})),po=p((function e(t){u(this,e),this.slopeDelta=t})),lo=function(){function e(t,n,r,a){u(this,e),this.tinyAssetId=t,this.totalLockedAmount=n,this.totalPowerCount=r,this.lastTotalPowerTimestamp=a}return p(e,[{key:"freeTotalPowerSpaceCount",get:function(){var e=this.totalPowerCount%Ns;return e>0?Ns-e:0}},{key:"lastTotalPowerBoxIndex",get:function(){return xo(this.totalPowerCount)[0]}},{key:"lastTotalPowerArrayIndex",get:function(){return xo(this.totalPowerCount)[1]}}]),e}();function fo(){return(fo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ho(r),e.prev=1,e.next=4,Gs(t,n,a);case 4:if(!(o=e.sent)){e.next=7;break}return e.abrupt("return",mo(o));case 7:return e.abrupt("return",null);case 10:return e.prev=10,e.t0=e.catch(1),console.log(e.t0),e.abrupt("return",null);case 14:case"end":return e.stop()}}),e,null,[[1,10]])})))).apply(this,arguments)}function mo(e){var t=Buffer.from(e);return new io(t.readUIntBE(0,8),t.readUIntBE(8,8),t.readUIntBE(16,8),t.readUIntBE(24,8))}function ho(t){return e.decodeAddress(t).publicKey}function go(e){var t=Ba(e),n=new Uint8Array(Cs.length+t.length);return n.set(Cs,0),n.set(t,Cs.length),n}function xo(e){var t=e-1;return[Math.floor(t/Ns),t%Ns]}function Ao(t,n){var r=e.decodeAddress(t).publicKey,a=Ba(n),s=new Uint8Array(r.length+a.length);return s.set(r,0),s.set(a,r.length),s}function Io(e,t,n){return vo.apply(this,arguments)}function vo(){return(vo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=yo(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",wo(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function wo(t){return new po(Number(e.bytesToBigInt(t.slice(t.length-16,t.length))))}function yo(e){return Hs(Fs,Ba(e))}function bo(e,t,n){return To.apply(this,arguments)}function To(){return(To=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=0,r&&(a=Math.ceil(r/Ns)),o=[],i=0;case 4:if(!(i=e[r].timestamp))break;n=r}return n}function So(e){for(var t,n=Os,r=[],a=0;a=11)throw new Error("Boxes' length cannot be larger than 10");var y=d.slice(0,6),b=[e.makeApplicationNoOpTxnFromObject({from:s,suggestedParams:c,appIndex:n,appArgs:[Te("claim_rewards"),Ba(o),Ba(i),Hs.apply(void 0,w(u.map((function(e){return Ba(e)}))))],foreignApps:[r],foreignAssets:[a],boxes:y,note:l?Te(l):void 0})];b[0].fee=b[0].fee*(i+2);var k=0,_=92+865*i,E=700+700*i;if(_>E&&(k=Math.floor((_-E)/666)+1),k||d.length>6){var P=d.slice(6),S=Ko({sender:s,suggestedParams:c,extraAppArgs:[Ba(Math.max(k-1,0))],index:n,foreignApps:[r],boxes:P});S.fee*=Math.max(k,1),b.unshift(S)}if(p){var D=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,to:e.getApplicationAddress(n),amount:Lo,suggestedParams:c});b.unshift(D)}return e.assignGroupID(b)}var Ho=8,$o=Te("p"),Zo=Te("a"),ei=Te("v"),ti=28500,ni=12500,ri=p((function e(t,n,r,a,s,o,i){u(this,e),this.index=t,this.creationTimestamp=n,this.votingStartTimestamp=r,this.votingEndTimestamp=a,this.votingPower=s,this.voteCount=o,this.isCancelled=i}));function ai(t,n){return Hs(Zo,e.decodeAddress(t).publicKey,Ba(n))}function si(e){return new ri(Fa(e.slice(0,8)),Fa(e.slice(8,16)),Fa(e.slice(16,24)),Fa(e.slice(24,32)),Fa(e.slice(32,40)),Fa(e.slice(40,48)),Boolean(Fa(e.slice(48,49))))}function oi(){return(oi=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ao(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",si(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ii(t){var n=t.stakingVotingAppId,r=t.vaultAppId,a=t.sender,s=t.proposalId,o=t.proposal,i=t.votes,u=t.assetIds,c=t.accountPowerIndex,p=t.appBoxNames,l=t.suggestedParams,d=t.appCallNote,f=void 0===d?null:d;if(i.length!==u.length)throw new Error("The number of votes must be equal to the number of asset ids");if(u.length>Ho)throw new Error("You cannot cast vote for more than ".concat(Ho," different pools"));if(100!==i.reduce((function(e,t){return e+t}),0))throw new Error("The sum of the votes must equal 100%");var m,h=Hs.apply(void 0,w(i.map((function(e){return Ba(e)})))),g=Hs.apply(void 0,w(u.map((function(e){return Ba(e)})))),x=function(e){return Hs($o,Te(e))}(s),A=ai(a,Math.floor(o.index/8192)),I=!p.some((function(e){return Ca(e,A)})),v=ho(a),y=Math.floor(c/Ns),b=Ao(a,y),k=Ao(a,y+1),_=0,E=[],P=T(u);try{var S=function(){var e=m.value,t=function(e,t){return Hs(ei,Ba(e),Ba(t))}(o.index,e);E.push({appIndex:n,name:t}),p.some((function(e){return Ca(e,t)}))||(_+=1)};for(P.s();!(m=P.n()).done;)S()}catch(e){P.e(e)}finally{P.f()}var D=[{appIndex:n,name:x},{appIndex:n,name:A}].concat(E,[{appIndex:r,name:v},{appIndex:r,name:b},{appIndex:r,name:k}]),O=[e.makeApplicationNoOpTxnFromObject({from:a,suggestedParams:l,appIndex:n,appArgs:[Te("cast_vote"),Te(s),h,g,Ba(c)],foreignApps:[r],boxes:D.slice(0,7),note:f?Te(f):void 0})];O[0].fee*=2,D.length>=7&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(7,14)})),D.length>=14&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(14)}));var N=Number(I)*ti+_*ni;return N&&(O=[e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:l,to:e.getApplicationAddress(n),amount:N})].concat(w(O))),e.assignGroupID(O)}function ui(t){var n=t.accountState,r=t.lockEndTime,a=t.lockedAmount,s=t.network,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.slopeChangeAtLockEndTime,p=t.appCallNote;if(ai.freeTotalPowerSpaceCount&&(b+=Us),c||(b+=Rs);var k=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({amount:a,assetIndex:X[s],from:o,suggestedParams:u,to:e.getApplicationAddress(l)}),e.makeApplicationNoOpTxnFromObject({appIndex:l,from:o,suggestedParams:u,appArgs:[Te("create_lock"),Ba(r)],boxes:d.slice(0,8),note:p}),Ko({sender:o,suggestedParams:u,index:l,boxes:d.slice(8)})];if(b){var _=e.makePaymentTxnWithSuggestedParamsFromObject({amount:b,from:o,suggestedParams:u,to:e.getApplicationAddress(l)});k.unshift(_)}return e.assignGroupID(k)}function ci(t){var n=t.accountState,r=t.lockedAmount,a=t.network,s=t.sender,o=t.vaultAppGlobalState,i=t.suggestedParams,u=t.appCallNote;if(ro.freeTotalPowerSpaceCount&&(v+=Us),!n.freeAccountPowerSpaceCount){var w=Ao(s,n.lastAccountPowerBoxIndex+1);h.push({appIndex:Aa[a],name:w}),v+=Ms}var y=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:X[a],from:s,to:e.getApplicationAddress(Aa[a]),amount:r,suggestedParams:i}),e.makeApplicationNoOpTxnFromObject({appIndex:Aa[a],from:s,suggestedParams:i,appArgs:[Te("increase_lock_amount")],boxes:h,note:u}),Ko({sender:s,suggestedParams:i,index:Aa[a]})];if(v){var b=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,suggestedParams:i,to:e.getApplicationAddress(Aa[a]),amount:v});y.unshift(b)}return e.assignGroupID(y)}function pi(t){var n=t.accountState,r=t.network,a=t.newLockEndTime,s=t.slopeChangeAtNewLockEndTime,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.appCallNote;if(a%Ta)throw new Error("Invalid lock end time");if(a<=n.lockEndTime)throw new Error("New lock end time must be greater than current lock end time");var p=ho(o),l=Ao(o,n.lastAccountPowerBoxIndex),d=go(i.lastTotalPowerBoxIndex),f=go(i.lastTotalPowerBoxIndex+1),m=yo(n.lockEndTime),h=yo(a),g=[{appIndex:Aa[r],name:p},{appIndex:Aa[r],name:l},{appIndex:Aa[r],name:d},{appIndex:Aa[r],name:f},{appIndex:Aa[r],name:m},{appIndex:Aa[r],name:h}];if(!n.freeAccountPowerSpaceCount){var x=Ao(o,n.lastAccountPowerBoxIndex+1);g.push({appIndex:Aa[r],name:x})}var A,I=Vs(i.lastTotalPowerTimestamp,Math.floor(Date.now()/1e3)),v=I.length,w=T(I);try{for(w.s();!(A=w.n()).done;){var y=A.value;if(y%Ta==0){var b=yo(y);g.push({appIndex:Aa[r],name:b})}}}catch(e){w.e(e)}finally{w.f()}var k=0;s||(k+=Rs),n.freeAccountPowerSpaceCount||(k+=Ms),v>i.freeTotalPowerSpaceCount&&(k+=Us);var _=[e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:o,suggestedParams:u,appArgs:[Te("extend_lock_end_time"),Ba(a)],boxes:g.slice(0,8),note:c}),Ko({sender:o,suggestedParams:u,index:Aa[r],boxes:g.slice(8)})];if(k){var E=e.makePaymentTxnWithSuggestedParamsFromObject({from:o,suggestedParams:u,to:e.getApplicationAddress(Aa[r]),amount:k});_.unshift(E)}return e.assignGroupID(_)}function li(t){var n=t.accountState,r=t.network,a=t.sender,s=t.suggestedParams,o=t.appCallNote,i=ho(a),u=Ao(a,n.lastAccountPowerBoxIndex),c=Ao(a,n.lastAccountPowerBoxIndex+1),p=[{appIndex:Aa[r],name:i},{appIndex:Aa[r],name:u},{appIndex:Aa[r],name:c}],l=e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:a,suggestedParams:s,appArgs:[Te("withdraw")],foreignAssets:[X[r]],boxes:p,note:o});l.fee*=2;var d=[l];if(!n.freeAccountPowerSpaceCount){var f=e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:s,to:e.getApplicationAddress(Aa[r]),amount:Ms});d.unshift(f)}return e.assignGroupID(d)}var di=function(){function t(e,n,r){u(this,t),this.algodClient=e,this.userAddress=n,this.network=r}var n,r,a,o,c,l,d,f,m,h,g,x,A,I,v,y;return p(t,[{key:"getTinyPower",value:(y=i(s().mark((function e(){var t,n,r,a,o,i,u,c=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=c.length>0&&void 0!==c[0]?c[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=Math.max(o.bias-Ws(o.slope,i),0),e.abrupt("return",u);case 16:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getTotalTinyPower",value:(v=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=v.length>0&&void 0!==v[0]?v[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchVaultAppGlobalState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,bo(this.algodClient,Aa[this.network],n.totalPowerCount);case 8:if(r=e.sent,a=Po(r,t)){e.next=12;break}return e.abrupt("return",0);case 12:o=r[a],i=Math.floor(o.timestamp/Ta),u=Math.floor(t/Ta)-i,c=Array.from({length:u},(function(e,t){return(i+t)*Ta})),p=c.map((function(e,t){return[0===t?o.timestamp:c[t-1],e]})),l=o.slope,d=o.bias,f=T(p),e.prev=19,f.s();case 21:if((m=f.n()).done){e.next=34;break}return h=m.value,g=h[1]-h[0],x=Ws(l,g),d=Math.max(d-x,0),e.next=28,Io(this.algodClient,Aa[this.network],h[1]);case 28:A=e.sent,I=(null==A?void 0:A.slopeDelta)||0,l=Math.max(l-I,0),0!==d&&0!==l||(d=0,l=0);case 32:e.next=21;break;case 34:e.next=39;break;case 36:e.prev=36,e.t0=e.catch(19),f.e(e.t0);case 39:return e.prev=39,f.f(),e.finish(39);case 42:return e.abrupt("return",d);case 43:case"end":return e.stop()}}),e,this,[[19,36,39,42]])}))),function(){return v.apply(this,arguments)})},{key:"getCumulativeTinyPower",value:(I=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=p.length>0&&void 0!==p[0]?p[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=zs(o.bias,o.slope,i),c=o.cumulativePower-u,e.abrupt("return",c);case 17:case"end":return e.stop()}}),e,this)}))),function(){return I.apply(this,arguments)})},{key:"fetchVaultAppGlobalState",value:(A=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,Js(this.algodClient,Aa[this.network]);case 3:return t=e.sent,e.abrupt("return",new lo(t.tiny_asset_id,t.total_locked_amount,t.total_power_count,t.last_total_power_timestamp));case 7:return e.prev=7,e.t0=e.catch(0),console.error(e.t0),e.abrupt("return",null);case 11:case"end":return e.stop()}}),e,this,[[0,7]])}))),function(){return A.apply(this,arguments)})},{key:"generateCreateLockTransactions",value:(x=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=o,c){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(p){e.next=15;break}return e.next=14,this.algodClient.getTransactionParams().do();case 14:p=e.sent;case 15:return e.next=17,Io(this.algodClient,Aa[this.network],r);case 17:return l=e.sent,e.abrupt("return",ui({lockedAmount:n,lockEndTime:r,vaultAppGlobalState:c,slopeChangeAtLockEndTime:l,sender:i,network:this.network,accountState:u,suggestedParams:p}));case 19:case"end":return e.stop()}}),e,this)}))),function(e){return x.apply(this,arguments)})},{key:"generateIncreaseLockAmountTransactions",value:(g=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.abrupt("return",ci({accountState:i,lockedAmount:n,network:this.network,sender:o,vaultAppGlobalState:u,suggestedParams:c}));case 18:case"end":return e.stop()}}),e,this)}))),function(e){return g.apply(this,arguments)})},{key:"generateExtendLockTimeTransactions",value:(h=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.newLockEndTime,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.next=19,Io(this.algodClient,Aa[this.network],n);case 19:return p=e.sent,e.abrupt("return",pi({accountState:i,network:this.network,newLockEndTime:n,sender:o,vaultAppGlobalState:u,suggestedParams:c,slopeChangeAtNewLockEndTime:null==p?void 0:p.slopeDelta}));case 21:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"generateIncreaseLockAmountAndExtendLockEndTimeTransactions",value:(m=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=[],l=[],d=o,c){e.next=13;break}throw new Error("There was an error while fetching vault app global state");case 13:if(u){e.next=15;break}throw new Error("There was an error while fetcing the account state");case 15:if(d){e.next=19;break}return e.next=18,this.algodClient.getTransactionParams().do();case 18:d=e.sent;case 19:return p=ci({accountState:u,lockedAmount:n,network:this.network,sender:i,vaultAppGlobalState:c,suggestedParams:d}),u.powerCount+=1,c.totalPowerCount+=1,e.next=24,Io(this.algodClient,Aa[this.network],r);case 24:return f=e.sent,l=pi({accountState:u,network:this.network,newLockEndTime:r,sender:i,vaultAppGlobalState:c,suggestedParams:d,slopeChangeAtNewLockEndTime:null==f?void 0:f.slopeDelta}),m=[].concat(w(p),w(l)),e.abrupt("return",Boolean(p.length)&&Boolean(l.length)?Zs(p,l):m);case 28:case"end":return e.stop()}}),e,this)}))),function(e){return m.apply(this,arguments)})},{key:"generateWithdrawTransactions",value:(f=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t||this.userAddress,e.next=3,this.fetchAccountState();case 3:if(o=e.sent,i=r,o){e.next=7;break}throw new Error("There was an error while fetcing the account state");case 7:if(i){e.next=11;break}return e.next=10,this.algodClient.getTransactionParams().do();case 10:i=e.sent;case 11:if(u=li({accountState:o,network:this.network,sender:a,suggestedParams:i,client:this.algodClient}),!n){e.next=17;break}return e.next=15,H({client:this.algodClient,initiatorAddr:a,assetID:X[this.network]});case 15:c=e.sent,u=Zs([c[0].txn],u);case 17:return e.abrupt("return",u);case 18:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"fetchAccountState",value:function(){return function(e,t,n){return fo.apply(this,arguments)}(this.algodClient,Aa[this.network],this.userAddress)}},{key:"fetchStakingDistributionProposal",value:function(e){return function(e,t,n){return oi.apply(this,arguments)}(this.algodClient,Ia[this.network],e)}},{key:"generateCastVoteForStakingDistributionProposalTransactions",value:(d=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.proposalId,a=t.votes,o=t.assetIds,i=t.userAddress,u=t.suggestedParams,c=null!=i?i:this.userAddress,p=u,e.next=5,this.fetchStakingDistributionProposal(r);case 5:if(l=e.sent){e.next=8;break}throw new Error("There was an error while fetching staking distribution proposal");case 8:if(p){e.next=12;break}return e.next=11,this.algodClient.getTransactionParams().do();case 11:p=e.sent;case 12:return e.next=14,this.fetchAccountState();case 14:return d=e.sent,e.next=17,eo(this.algodClient,Ia[this.network]);case 17:return f=e.sent,e.next=20,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==d?void 0:d.powerCount)&&void 0!==n?n:null});case 20:if(m=e.sent,null!==(h=Po(m,l.creationTimestamp))){e.next=24;break}throw new Error("It is required to have an account power at the staking distribution proposal creation timestamp");case 24:return e.abrupt("return",ii({stakingVotingAppId:Ia[this.network],vaultAppId:Aa[this.network],sender:c,proposalId:r,proposal:l,votes:a,assetIds:o,accountPowerIndex:h,appBoxNames:f,suggestedParams:p,appCallNote:null}));case 25:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"fetchRewardsAppGlobalState",value:(l=i(s().mark((function t(){var n;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,Js(this.algodClient,va[this.network]);case 3:return n=t.sent,t.abrupt("return",new Ro(n.tiny_asset_id,n.vault_app_id,n.reward_history_count,n.first_period_timestamp,n.reward_period_count,e.encodeAddress(n.manager),e.encodeAddress(n.rewards_manager)));case 7:return t.prev=7,t.t0=t.catch(0),console.error(t.t0),t.abrupt("return",null);case 11:case"end":return t.stop()}}),t,this,[[0,7]])}))),function(){return l.apply(this,arguments)})},{key:"generateClaimRewardTransactions",value:(c=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.periodIndexStart,a=t.periodCount,o=t.userAddress,i=t.suggestedParams,u=t.shouldOptIntoTINY,c=null!=o?o:this.userAddress,p=i){e.next=7;break}return e.next=6,this.algodClient.getTransactionParams().do();case 6:p=e.sent;case 7:return e.next=9,this.fetchAccountState();case 9:return l=e.sent,e.next=12,this.fetchRewardsAppGlobalState();case 12:if(d=e.sent){e.next=15;break}throw new Error("There was an error while fetching rewards app global state");case 15:if(!(r+a>d.rewardPeriodCount)){e.next=17;break}throw new Error("The reward period index to be claimed cannot be larger than the latest reward period index");case 17:return e.next=19,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==l?void 0:l.powerCount)&&void 0!==n?n:null});case 19:for(f=e.sent,m=d.firstPeriodTimestamp+r*ga,h=d.firstPeriodTimestamp+(r+a)*ga,g=[],x=m;x=Math.floor(Date.now()/xa)||c.votingEndTimestamp<=Math.floor(Date.now()/xa))){e.next=23;break}throw new Error("Voting period is not active");case 23:return e.next=25,_o({algodClient:this.algodClient,address:i,appId:Aa[this.network],powerCount:p.powerCount});case 25:if(l=e.sent,null!==(d=Po(l,c.creationTimestamp))){e.next=29;break}throw new Error("Account power index not found");case 29:return f=Math.floor(c.index/(8*Ea)),m=ai(i,f),e.next=33,qs(this.algodClient,wa[this.network],m);case 33:return h=!e.sent,e.abrupt("return",Oo({proposalVotingAppId:wa[this.network],vaultAppId:Aa[this.network],sender:i,proposalId:n,proposal:c,vote:a,accountPowerIndex:d,createAttendanceSheetBox:h,suggestedParams:u}));case 35:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"fetchProposalVotingAppGlobalState",value:(r=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Js(this.algodClient,wa[this.network]);case 2:return t=e.sent,e.abrupt("return",new ro(t.vault_app_id,t.proposal_index_counter,t.voting_delay,t.voting_duration,t.proposal_threshold,t.proposal_threshold_numerator,t.quorum_threshold,t.approval_requirement,t.manager,t.proposal_manager));case 4:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getRequiredTinyPowerToCreateProposal",value:(n=i(s().mark((function e(t){var n,r,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==t){e.next=4;break}e.t0=t,e.next=7;break;case 4:return e.next=6,this.getTotalTinyPower();case 6:e.t0=e.sent;case 7:return n=e.t0,e.next=10,this.fetchProposalVotingAppGlobalState();case 10:return r=e.sent,a=r.proposalThreshold,r.proposalThresholdNumerator&&(a=Math.max(a,Math.floor(n*r.proposalThresholdNumerator/100)+1)),e.abrupt("return",a);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})}]),t}(),fi=2500,mi=400,hi=function(){function e(t,n){u(this,e),l(this,"data",null),this.name=t,this.structReference=n,this.size=n[t].size,this.fields=n[t].fields}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.size)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t;if(!this.data)throw new Error("Data is not initialized");var n=this.fields[e];if(!n)throw new Error("Field ".concat(e," does not exist in struct ").concat(this.name));var r=n.offset,a=n.offset+n.size,s=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(r,a);return Ii(n.type,this.structReference).apply(Buffer.from(s))}}]),e}(),gi=function(){function e(t,n){u(this,e),l(this,"data",null),this.struct=t,this.length=n}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.struct.size*this.length)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t,n=this.struct.size*e,r=n+this.struct.size,a=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(n,r);return this.struct.apply(a?Buffer.from(a):void 0)}}]),e}(),xi=function(){function e(){u(this,e)}return p(e,[{key:"apply",value:function(e){for(var t=BigInt(0),n=0;n2&&void 0!==arguments[2]?arguments[2]:Math.floor(Date.now()/1e3),a=(n=e,Math.floor(n*Ds/Ps)),s=t-r;return s<0?0:Ws(a,s)},exports.combineAndRegroupSignerTxns=function(){for(var t=arguments.length,n=new Array(t),r=0;r=e.minimum_required_balance},exports.intToBytes=Ba,exports.isAccountOptedIntoApp=function(e){var t=e.appID;return e.accountAppsLocalState.some((function(e){return e.id===t}))},exports.isSwapAssetInAmountLow=it,exports.isSwapQuoteErrorCausedByAmount=gt,exports.poolUtils=$t,exports.prepareCommitTransactions=function(e){return ha.apply(this,arguments)},exports.redeemAllExcessAsset=function(e){return $r.apply(this,arguments)},exports.redeemExcessAsset=function(e){return Kr.apply(this,arguments)},exports.sendAndWaitRawTransaction=Ie,exports.sumUpTxnFees=we,exports.tinymanContract_v1_1=wt,exports.tinymanContract_v2=Tt,exports.tinymanJSSDKConfig=_e; +"use strict";var e=require("algosdk"),t=require("base64-js"),n=require("crypto");function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0;--a){var s=this.tryEntries[a],o=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var i=n.call(s,"catchLoc"),u=n.call(s,"finallyLoc");if(i&&u){if(this.prev=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),k(n),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var a=r.arg;k(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:E(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function o(e,t,n,r,a,s,o){try{var i=e[s](o),u=i.value}catch(e){return void n(e)}i.done?t(u):Promise.resolve(u).then(r,a)}function i(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var s=e.apply(t,n);function i(e){o(s,r,a,i,u,"next",e)}function u(e){o(s,r,a,i,u,"throw",e)}i(void 0)}))}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f: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,o=!0,i=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){i=!0,s=e},f:function(){try{o||null==n.return||n.return()}finally{if(i)throw s}}}}function k(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var _=function(e){return e.SwapRouterStaleDataError="SwapRouterStaleDataError",e.SwapRouterNoRouteError="SwapRouterNoRouteError",e.SwapRouterLowSwapAmountError="SwapRouterLowSwapAmountError",e.SwapRouterInsufficientReservesError="SwapRouterInsufficientReservesError",e.SwapRouterPoolHasNoLiquidityError="SwapRouterPoolHasNoLiquidityError",e.NoAvailablePoolError="NoAvailablePoolError",e.OutputAmountExceedsAvailableLiquidityError="OutputAmountExceedsAvailableLiquidityError",e.UnknownError="UnknownError",e.LowSwapAmountError="LowSwapAmountError",e.AssetDoesNotBelongToPoolError="AssetDoesNotBelongToPoolError",e.InvalidSwapTypeError="InvalidSwapTypeError",e}({}),E=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;return u(this,n),(a=t.call(this,r)).type=e,a.message=r,Error.captureStackTrace&&Error.captureStackTrace(A(a),n),a}return p(n)}(),P=Uint8Array.from([1]),S=1e5,D=1e5,O=1e5,N=1e5,B=1e5,C=5e4,F=28500,L=1e3,R=1e3,M={mainnet:{base:"https://mainnet.analytics.tinyman.org/api",v1:"https://mainnet.analytics.tinyman.org/api/v1"},testnet:{base:"https://testnet.analytics.tinyman.org/api",v1:"https://testnet.analytics.tinyman.org/api/v1"}},U={V1_1:"v1_1",V2:"v2"},j=0,V={id:"".concat(j),name:"Algorand",unit_name:"ALGO",decimals:6,url:"https://algorand.org",is_liquidity_token:!1,total_amount:"6615503326932151",clawback_address:""},G={V1:"TM1POOL",V1_1:"TMPOOL11",V2:"TMPOOL2"},X={testnet:258703304,mainnet:22e8},q={testnet:724519992,mainnet:2537013734},Q={testnet:724676936,mainnet:2537023208},W="- would result negative",z="logic eval error:",J="exceeds schema integer count",K=/transaction \w+:/,Y=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;u(this,n);for(var s=arguments.length,o=new Array(s>2?s-2:0),i=2;ir?[a(a({},e),{},{id:n}),a(a({},t),{},{id:r})]:[a(a({},t),{},{id:r}),a(a({},e),{},{id:n})]}function ee(e,t){var n=[e,t];return[Math.max.apply(Math,n),Math.min.apply(Math,n)]}function te(e){return Number(e)===j}function ne(e){return Number(e.id)}function re(e){var t,n=e.stateArray,r=void 0===n?[]:n,a=e.shouldDecodeKeys,s=void 0!==a&&a,o={},i=T(r);try{for(i.s();!(t=i.n()).done;){var u=t.value,c=u.key,p=void 0;if(1==u.value.type)p=u.value.bytes;else{if(2!=u.value.type)throw new Error("Unexpected state type: ".concat(u.value.type));p=u.value.uint}o[s?atob(c):c]=p}}catch(e){i.e(e)}finally{i.f()}return o}function ae(e){var t,n=e.reduce((function(e,t){return e+t.length}),0),r=new Uint8Array(n),a=0,s=T(e);try{for(s.s();!(t=s.n()).done;){var o=t.value;r.set(o,a),a+=o.length}}catch(e){s.e(e)}finally{s.f()}return r}var se=100000n,oe=100000n,ie=100000n,ue=25000n+25000n,ce=25000n+3500n;function pe(e){var t=e["apps-total-schema"],n=0n,r=0n;t&&(t["num-byte-slice"]&&(n=t["num-byte-slice"]),t["num-uint"]&&(r=t["num-uint"]));var a=e["apps-local-state"]||[],s=e["created-apps"]||[],o=e.assets||[];return se+oe*BigInt(o.length)+ie*BigInt(s.length+a.length)+ce*r+ue*n}function le(e){return new Promise((function(t){setTimeout((function(){t(null)}),e)}))}function de(e,t){return fe.apply(this,arguments)}function fe(){return(fe=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=3,le(1e3);case 3:return r=null,e.prev=4,e.next=7,t.pendingTransactionInformation(n).do();case 7:r=e.sent,e.next=12;break;case 10:e.prev=10,e.t0=e.catch(4);case 12:if(!r){e.next=17;break}if(!r["confirmed-round"]){e.next=15;break}return e.abrupt("return",r);case 15:if(!r["pool-error"]){e.next=17;break}throw new Error("Transaction Rejected: ".concat(r["pool-error"]));case 17:e.next=0;break;case 19:case"end":return e.stop()}}),e,null,[[4,10]])})))).apply(this,arguments)}function me(e,t,n){if(t>1||t<0)throw new Error("Invalid slippage value. Must be between 0 and 1, got ".concat(t));var r;try{var a="negative"===e?1-t:1+t;r=BigInt(Math.floor(Number(n)*a))}catch(e){throw new Error(e.message)}return r}function he(e,t){var n=Number(e);return ge({decimalPlaces:n},Math.pow(10,-n)*Number(t))}function ge(e,t){var n=e.decimalPlaces,r=void 0===n?0:n;if(r>0){var a=v(Ae(t),2),s=a[0],o=a[1],i=v(Ae(Math.round(Number(xe(s,o+r)))),2),u=i[0],c=i[1];return Number(xe(u,c-r))}return Math.round(t)}function xe(e,t){return e+(t<0?"e".concat(t):"e+".concat(t))}function Ae(e){if(e.toString().includes("e")){var t=e.toString().split("e");return[parseFloat(t[0]),parseFloat(t[1])]}return[e,0]}function Ie(e,t){return ve.apply(this,arguments)}function ve(){return(ve=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,r=[],a=T(n),e.prev=3,a.s();case 5:if((o=a.n()).done){e.next=18;break}return i=o.value,e.next=9,t.sendRawTransaction(i).do();case 9:return u=e.sent,c=u.txId,e.next=13,de(t,c);case 13:p=e.sent,l=p["confirmed-round"],r.push({confirmedRound:l,txnID:c});case 16:e.next=5;break;case 18:e.next=23;break;case 20:e.prev=20,e.t0=e.catch(3),a.e(e.t0);case 23:return e.prev=23,a.f(),e.finish(23);case 26:return e.abrupt("return",r);case 29:throw e.prev=29,e.t1=e.catch(0),new Y(e.t1,"We encountered an error while processing this transaction. Try again later.");case 32:case"end":return e.stop()}}),e,null,[[0,29],[3,20,23,26]])})))).apply(this,arguments)}function we(e){return e.reduce((function(e,t){return e+t.txn.fee}),0)}function ye(e){return(t=e[0].txn.group)?Buffer.from(t).toString("base64"):"";var t}function be(e){for(var t=[];;){var n=Number(e&BigInt(127));if(!(e>>=BigInt(7))){t.push(n);break}t.push(128|n)}return t}function Te(e){return(new TextEncoder).encode(e)}var ke,_e=new(function(){function e(){u(this,e),this.clientName="tinyman-js-sdk"}return p(e,[{key:"getClientName",value:function(){return this.clientName}},{key:"setClientName",value:function(e){this.clientName=e}},{key:"getAppCallTxnNoteWithClientName",value:function(e,t){var n=e===U.V1_1?"v1":e,r=JSON.stringify(a({origin:this.clientName},t));return Te("tinyman/".concat(n,":j").concat(r))}}]),e}()),Ee=(l(ke={},U.V1_1,{testnet:62368684,mainnet:552635992}),l(ke,U.V2,{testnet:148607e3,mainnet:1002541853}),ke);function Pe(e,t){var n=Ee[t][e];if(!n)throw new Error("No Validator App exists for ".concat(e," network with ").concat(t," contract version"));return n}function Se(){return(Se=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationOptInTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function De(){return(De=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationClearStateTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var Oe,Ne,Be,Ce=function(e){return e.FixedInput="fixed-input",e.FixedOutput="fixed-output",e}({}),Fe=.003,Le=function(e){return e[e.INPUT_TXN=0]="INPUT_TXN",e[e.APP_CALL_TXN=1]="APP_CALL_TXN",e}({}),Re=(l(Oe={},Ce.FixedInput,1),l(Oe,Ce.FixedOutput,2),Oe),Me=2,Ue=Te("swap"),je=(l(Ne={},Ce.FixedInput,Te("fixed-input")),l(Ne,Ce.FixedOutput,Te("fixed-output")),Ne),Ve={ASSET_OPT_IN:Te("asset_opt_in")},Ge={testnet:184778019,mainnet:1083651166},Xe=(l(Be={},Ce.FixedInput,7),l(Be,Ce.FixedOutput,8),Be);function qe(e){var t=Je(e),n=t.assetIn,r=t.assetOut;return he(r.asset.decimals,Number(r.amount))/he(n.asset.decimals,Number(n.amount))}function Qe(e){var t=Ge[e];if(!t)throw new Error("Unknown network or network not supported: ".concat(e));return t}function We(e){return e[e.length-1].quote.amount_out}function ze(e){return e[0].quote.amount_in}function Je(e){return{assetIn:ze(e),assetOut:We(e)}}function Ke(e){return Ye.apply(this,arguments)}function Ye(){return(Ye=i(s().mark((function t(n){var r,a,o,i,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.routerAppID,o=n.assetIDs,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a,appArgs:[Ve.ASSET_OPT_IN],foreignAssets:o,suggestedParams:u}),p=o.length,c.fee=e.ALGORAND_MIN_TX_FEE*(p+1),t.abrupt("return",c);case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function He(e){return $e.apply(this,arguments)}function $e(){return($e=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k,_,E,P,S,D;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.initiatorAddr,a=n.client,o=n.network,i=n.swapType,u=n.route,c=n.slippage,t.next=3,a.getTransactionParams().do();case 3:return p=t.sent,l=[ne(u[0].quote.amount_in.asset),ne(u[0].quote.amount_out.asset),ne(u[1].quote.amount_out.asset)],d=l[0],f=l[1],m=l[2],h=[Number(ze(u).amount),Number(We(u).amount)],g=h[0],x=h[1],A=[u[0].pool.address,u[1].pool.address],I=A[0],v=A[1],w=i===Ce.FixedInput?g:me("positive",c,g),y=i===Ce.FixedOutput?x:me("negative",c,x),b=te(d),T=Qe(o),k=b?e.makePaymentTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,suggestedParams:p}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,assetIndex:d,suggestedParams:p}),(_=e.makeApplicationNoOpTxnFromObject({from:r,appIndex:T,appArgs:[Ue,je[i],e.encodeUint64(y)],foreignApps:[Pe(o,U.V2)],foreignAssets:[d,f,m],accounts:[I,v],suggestedParams:p,note:_e.getAppCallTxnNoteWithClientName(U.V2)})).fee=e.ALGORAND_MIN_TX_FEE*(Xe[i]+1),E=[k,_],t.next=17,Ze({client:a,network:o,assetIDs:[d,f,m]});case 17:if(!((P=t.sent).length>0)){t.next=23;break}return t.next=21,Ke({client:a,initiatorAddr:r,assetIDs:P,routerAppID:T});case 21:S=t.sent,E.unshift(S);case 23:return D=e.assignGroupID(E),t.abrupt("return",D.map((function(e){return{txn:e,signers:[r]}})));case 25:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Ze(e){return et.apply(this,arguments)}function et(){return(et=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(Qe(a)),t.next=4,r.accountInformation(i).do();case 4:return u=t.sent,c=u.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!c.includes(e)})));case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function tt(e){return nt.apply(this,arguments)}function nt(){return(nt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetInID,a=t.assetOutID,o=t.swapType,i=t.network,u={asset_in_id:String(r),asset_out_id:String(a),swap_type:o,amount:String(n)},e.next=4,fetch("".concat(M[i].v1,"/swap-router/quotes/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}).catch((function(){throw new Error("Network error")}));case 4:return c=e.sent,e.next=7,c.json();case 7:if(p=e.sent,c.ok){e.next=14;break}if(s=p,!Boolean(s)||void 0===s.fallback_message){e.next=13;break}throw new E(p.type,p.fallback_message);case 13:throw new E(_.UnknownError,"There was an error while getting a quote from Swap Router");case 14:if(!(p.route.length<2)){e.next=16;break}throw new E(_.SwapRouterNoRouteError,"Swap router couldn't find a route for this swap.");case 16:return e.abrupt("return",p);case 17:case"end":return e.stop()}var s}),e)})))).apply(this,arguments)}var rt=function(e){return e.Direct="direct",e.Router="router",e}({}),at=4*e.ALGORAND_MIN_TX_FEE;function st(t){return(Re[t]+Me)*e.ALGORAND_MIN_TX_FEE}function ot(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Fe;return Math.ceil(1/e)}function it(e){return e1&&void 0!==arguments[1]?arguments[1]:Fe)}function ut(t){return(Re[t]+1)*e.ALGORAND_MIN_TX_FEE}function ct(e){var t=e.assetIn,n=e.assetOut;return he(n.decimals,Number(n.amount))/he(t.decimals,Number(t.amount))}function pt(e){var t=e.inputSupply,n=e.outputSupply,r=e.assetIn,a=e.assetOut,s=ct({assetIn:r,assetOut:a}),o=he(a.decimals,Number(n))/he(r.decimals,Number(t));return ge({decimalPlaces:5},Math.abs(s/o-1))}function lt(e){if(e.type===rt.Router){var t=ze(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetInID,amount:e.data.quote.assetInAmount}}function dt(e){if(e.type===rt.Router){var t=We(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetOutID,amount:e.data.quote.assetOutAmount}}function ft(e){return e.type===rt.Direct?e.data.pool.contractVersion:U.V2}function mt(e){return e.type===rt.Direct?e.data.quote.rate:qe(e.data.route)}function ht(e){for(var t=e[0],n=mt(t),r=1;rn&&(t=a,n=s)}return t}function gt(e){return e instanceof E&&[_.SwapRouterInsufficientReservesError,_.SwapRouterLowSwapAmountError,_.OutputAmountExceedsAvailableLiquidityError,_.LowSwapAmountError].includes(e.type)}var xt={type:"logicsig",logic:{bytecode:"BCAIAQCBgICAgICAgPABgICAgICAgIDwAQMEBQYlJA1EMQkyAxJEMRUyAxJEMSAyAxJEMgQiDUQzAQAxABJEMwEQIQcSRDMBGIGCgICAgICAgPABEkQzARkiEjMBGyEEEhA3ARoAgAlib290c3RyYXASEEAAXDMBGSMSRDMBG4ECEjcBGgCABHN3YXASEEACOzMBGyISRDcBGgCABG1pbnQSQAE7NwEaAIAEYnVybhJAAZg3ARoAgAZyZWRlZW0SQAJbNwEaAIAEZmVlcxJAAnkAIQYhBSQjEk0yBBJENwEaARclEjcBGgIXJBIQRDMCADEAEkQzAhAhBBJEMwIhIxJEMwIiIxwSRDMCIyEHEkQzAiQjEkQzAiWACFRNUE9PTDExEkQzAiZRAA+AD1RpbnltYW5Qb29sMS4xIBJEMwIngBNodHRwczovL3RpbnltYW4ub3JnEkQzAikyAxJEMwIqMgMSRDMCKzIDEkQzAiwyAxJEMwMAMQASRDMDECEFEkQzAxElEkQzAxQxABJEMwMSIxJEJCMTQAAQMwEBMwIBCDMDAQg1AUIBsTMEADEAEkQzBBAhBRJEMwQRJBJEMwQUMQASRDMEEiMSRDMBATMCAQgzAwEIMwQBCDUBQgF8MgQhBhJENwEcATEAE0Q3ARwBMwQUEkQzAgAxABNEMwIUMQASRDMDADMCABJEMwIRJRJEMwMUMwMHMwMQIhJNMQASRDMDESMzAxAiEk0kEkQzBAAxABJEMwQUMwIAEkQzAQEzBAEINQFCAREyBCEGEkQ3ARwBMQATRDcBHAEzAhQSRDMDFDMDBzMDECISTTcBHAESRDMCADEAEkQzAhQzBAASRDMCESUSRDMDADEAEkQzAxQzAwczAxAiEk0zBAASRDMDESMzAxAiEk0kEkQzBAAxABNEMwQUMQASRDMBATMCAQgzAwEINQFCAJAyBCEFEkQ3ARwBMQATRDMCADcBHAESRDMCADEAE0QzAwAxABJEMwIUMwIHMwIQIhJNMQASRDMDFDMDBzMDECISTTMCABJEMwEBMwMBCDUBQgA+MgQhBBJENwEcATEAE0QzAhQzAgczAhAiEk03ARwBEkQzAQEzAgEINQFCABIyBCEEEkQzAQEzAgEINQFCAAAzAAAxABNEMwAHMQASRDMACDQBD0M=",address:"ABUKAXTANWR6K6ZYV75DWJEPVWWOU6SFUVRI6QHO44E4SIDLHBTD2CZ64A",size:881,variables:[{name:"TMPL_ASSET_ID_1",type:"int",index:15,length:10},{name:"TMPL_ASSET_ID_2",type:"int",index:5,length:10},{name:"TMPL_VALIDATOR_APP_ID",type:"int",index:74,length:10}],source:"https://github.com/tinymanorg/tinyman-contracts-v1/tree/dc9ab40c58b85c15d58f63a1507e18be76720dbb/contracts/pool_logicsig.teal.tmpl"},name:"pool_logicsig"},At={type:"app",global_state_schema:{num_uints:0,num_byte_slices:0},local_state_schema:{num_uints:16,num_byte_slices:0},name:"validator_app"},It=p((function e(t){u(this,e),this.schema={numLocalInts:t.local_state_schema.num_uints,numLocalByteSlices:t.local_state_schema.num_byte_slices,numGlobalInts:t.global_state_schema.num_uints,numGlobalByteSlices:t.global_state_schema.num_byte_slices}})),vt=function(n){d(a,It);var r=I(a);function a(e,t){var n;return u(this,a),(n=r.call(this,e)).poolLogicSigContractTemplate=t.logic.bytecode,n.templateVariables=t.logic.variables,n}return p(a,[{key:"generateLogicSigAccountForPool",value:function(n){if(n.asset1ID===n.asset2ID)throw new Error("Assets are the same");var r=Pe(n.network,U.V1_1),a=v(ee(n.asset1ID,n.asset2ID),2),s=a[0],o=a[1],i=Array.from(t.toByteArray(this.poolLogicSigContractTemplate)),u={asset_id_1:s,asset_id_2:o,validator_app_id:r},c=0;this.templateVariables.sort((function(e,t){return e.index-t.index}));for(var p=0;p2&&void 0!==arguments[2]?arguments[2]:e.IntDecoding.DEFAULT;return new Promise(function(){var e=i(s().mark((function e(o,i){var u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.accountInformation(n).setIntDecoding(r).do();case 3:u=e.sent,o(a(a({},u),{},{minimum_required_balance:Pt(u)})),e.next=10;break;case 7:e.prev=7,e.t0=e.catch(0),i(new Error(e.t0.message||"Failed to fetch account information"));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}())}function Et(e,t){var n=e["apps-local-state"].find((function(e){return e.id===t}));return n?re({stateArray:n["key-value"],shouldDecodeKeys:!0}):null}function Pt(e){var t=e["apps-total-schema"];return S+D*(e.assets||[]).length+N*(e["created-apps"]||[]).length+O*(e["apps-local-state"]||[]).length+C*Number(t&&t["num-byte-slice"]||0)+F*Number(t&&t["num-uint"]||0)+B*(e["apps-total-extra-pages"]||0)}var St=Te("e");function Dt(e){return Ot.apply(this,arguments)}function Ot(){return(Ot=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,k,_;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.pool,i=r.accountAddr,n.next=3,a.accountInformation(i).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:u=n.sent,c=u["apps-local-state"]||[],p=0n,l=0n,d=0n,f=o.account.address(),m=T(c),n.prev=10,m.s();case 12:if((h=m.n()).done){n.next=31;break}if((g=h.value).id==o.validatorAppID){n.next=16;break}return n.abrupt("continue",29);case 16:if(x=g["key-value"]){n.next=19;break}return n.abrupt("break",31);case 19:A=re({stateArray:x}),I=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset1ID)])),v=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset2ID)])),w=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.poolTokenID)])),y=A[I],b=A[v],k=A[w],"bigint"==typeof y&&(p=y),"bigint"==typeof b&&(l=b),"bigint"==typeof k&&(d=k);case 29:n.next=12;break;case 31:n.next=36;break;case 33:n.prev=33,n.t0=n.catch(10),m.e(n.t0);case 36:return n.prev=36,m.f(),n.finish(36);case 39:if(!((_={excessAsset1:p,excessAsset2:l,excessPoolTokens:d}).excessAsset1<0n||_.excessAsset2<0n||_.excessPoolTokens<0n)){n.next=42;break}throw new Error("Invalid account excess: ".concat(_));case 42:return n.abrupt("return",_);case 43:case"end":return n.stop()}}),n,null,[[10,33,36,39]])})))).apply(this,arguments)}function Nt(){return(Nt=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.accountAddr,i=r.validatorAppID,n.next=3,a.accountInformation(o).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:if(u=n.sent,c=u["apps-local-state"]||[],p=c.find((function(e){return e.id==i})),l=[],p&&p["key-value"])for(d=re({stateArray:p["key-value"]}),f=0,m=Object.entries(d);fMt)){n.next=48;break}throw new Error("Issued liquidity value is out of the expected range ([0n, ".concat(Mt,"]): ").concat(N.issuedLiquidity));case 48:return n.abrupt("return",N);case 49:case"end":return n.stop()}}),n,null,[[8,31,34,37]])})))).apply(this,arguments)}function Gt(){return Gt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.address,a=t.network,!(o=d.length>1&&void 0!==d[1]?d[1]:{})[r]){e.next=4;break}return e.abrupt("return",o[r]);case 4:return e.next=6,_t(n,r);case 6:return i=e.sent,u=Et(i,Pe(a,U.V1_1)),c=null,u&&(l=i["created-assets"][0],p=l.index,c={asset1ID:u[Ft[U.V1_1].asset1],asset2ID:u[Ft[U.V1_1].asset2],poolTokenID:p},o[r]=c),e.abrupt("return",c);case 11:case"end":return e.stop()}}),e)}))),Gt.apply(this,arguments)}var Xt=Object.freeze({__proto__:null,getPoolAssets:function(e){return Gt.apply(this,arguments)},getPoolInfo:Ut,getPoolReserves:function(e,t){return Vt.apply(this,arguments)}});function qt(e){return Qt.apply(this,arguments)}function Qt(){return(Qt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.asset1ID,o=t.asset2ID,i=kt(U.V2),u=i.generateLogicSigAccountForPool(t),c=Pe(r,U.V2),p=u.address(),l=ee(a,o),e.next=8,_t(n,p);case 8:return d=e.sent,f=Et(d,c),m={account:u,validatorAppID:c,asset1ID:l[0],asset2ID:l[1],status:f?Ct.READY:Ct.NOT_CREATED,contractVersion:U.V2},f&&(m.asset1ProtocolFees=BigInt(f[Ft.v2.asset1ProtocolFees]),m.asset2ProtocolFees=BigInt(f[Ft.v2.asset2ProtocolFees]),m.asset1Reserves=BigInt(f[Ft.v2.asset1Reserves]),m.asset2Reserves=BigInt(f[Ft.v2.asset2Reserves]),m.issuedPoolTokens=BigInt(f[Ft.v2.issuedPoolTokens]),m.cumulativePriceUpdateTimeStamp=Number(f[Ft.v2.cumulativePriceUpdateTimeStamp]),m.protocolFeeRatio=Number(f[Ft.v2.protocolFeeRatio]),m.totalFeeShare=BigInt(f[Ft.v2.totalFeeShare]),m.poolTokenID=Number(f[Ft.v2.poolTokenID]),m.asset1ID=Number(f[Ft.v2.asset1]),m.asset2ID=Number(f[Ft.v2.asset2])),e.abrupt("return",m);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Wt(){return(Wt=i(s().mark((function e(t,n){var r,a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_t(t,n.account.address());case 2:return r=e.sent,a=Et(r,n.validatorAppID),o={asset1:0n,asset2:0n,issuedLiquidity:0n,round:r.round},a&&(o.asset1=BigInt(a[Ft.v2.asset1Reserves]),o.asset2=BigInt(a[Ft.v2.asset2Reserves]),o.issuedLiquidity=BigInt(a[Ft.v2.issuedPoolTokens])),e.abrupt("return",o);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zt(){return(zt=i(s().mark((function e(t){var n,r,a,o,i,u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.address,a=t.network,e.next=3,_t(n,r);case 3:return o=e.sent,i=Et(o,Pe(a,U.V2)),u=null,i&&(u={asset1ID:i[Ft[U.V2].asset1],asset2ID:i[Ft[U.V2].asset2],poolTokenID:i[Ft[U.V2].poolTokenID]}),e.abrupt("return",u);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jt=Object.freeze({__proto__:null,getPoolAssets:function(e){return zt.apply(this,arguments)},getPoolInfo:qt,getPoolReserves:function(e,t){return Wt.apply(this,arguments)}});function Kt(e){return Boolean(e&&!(e.asset1+e.asset2))}var Yt,Ht=Object.freeze({__proto__:null,getPoolPairRatio:function(e){var t=Kt(e),n=null;return e&&!t&&e.asset1&&e.asset2&&(n=Number(e.asset1)/Number(e.asset2)),n},getPoolShare:function(e,t){var n=Number(t)/Number(e);return Number.isFinite(n)||(n=0),n},getPoolsForPair:function(e){return Promise.all([Ut(e),qt(e)])},isPoolEmpty:Kt,isPoolNotCreated:function(e){return(null==e?void 0:e.status)===Ct.NOT_CREATED},isPoolReady:function(e){return(null==e?void 0:e.status)===Ct.READY}}),$t=a((l(Yt={},U.V1_1,a(a({},Xt),Ht)),l(Yt,U.V2,a(a({},Jt),Ht)),Yt),Ht),Zt=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e[e.POOL_TOKEN_CREATE=2]="POOL_TOKEN_CREATE",e[e.ASSET1_OPT_IN=3]="ASSET1_OPT_IN",e[e.ASSET2_OPT_IN=4]="ASSET2_OPT_IN",e}({}),en={ASA_ALGO:96e4,ASA_ASA:859e3};function tn(){return(tn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T,k,_,E,P,S;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Z(o,i),l=v(p,2),d=l[0],f=d.id,m=d.unit_name,h=l[1],g=h.id,x=h.unit_name,A=te(g),I=Pe(a,U.V1_1),w=wt.generateLogicSigAccountForPool({network:a,asset1ID:f,asset2ID:g}),y=w.address(),b=e.makeApplicationOptInTxnFromObject({from:y,appIndex:I,note:_e.getAppCallTxnNoteWithClientName(U.V1_1),appArgs:[Te("bootstrap"),e.encodeUint64(f),e.encodeUint64(g)],foreignAssets:A?[f]:[g],suggestedParams:c}),T=e.makeAssetCreateTxnWithSuggestedParamsFromObject({from:y,total:0xffffffffffffffffn,decimals:6,defaultFrozen:!1,unitName:G.V1_1,assetName:"TinymanPool1.1 ".concat(m,"-").concat(x),assetURL:"https://tinyman.org",suggestedParams:c}),k=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:f,amount:0,suggestedParams:c}),_=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:y,amount:nn(A),suggestedParams:c}),(E=[])[Zt.FUNDING_TXN]=_,E[Zt.VALIDATOR_APP_CALL]=b,E[Zt.POOL_TOKEN_CREATE]=T,E[Zt.ASSET1_OPT_IN]=k,A||(E[Zt.ASSET2_OPT_IN]=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:g,amount:0,suggestedParams:c})),P=e.assignGroupID(E),S=[{txn:P[Zt.FUNDING_TXN],signers:[u]},{txn:P[Zt.VALIDATOR_APP_CALL],signers:[y]},{txn:P[Zt.POOL_TOKEN_CREATE],signers:[y]},{txn:P[Zt.ASSET1_OPT_IN],signers:[y]}],P[Zt.ASSET2_OPT_IN]&&S.push({txn:P[Zt.ASSET2_OPT_IN],signers:[y]}),t.abrupt("return",S);case 23:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function nn(e){return e?en.ASA_ALGO:en.ASA_ASA}function rn(){return(rn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=wt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===Zt.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function an(e){return sn.apply(this,arguments)}function sn(){return(sn=i(s().mark((function e(t){var n,r,a,o,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.signedTxns,a=t.txnIDs,e.prev=1,e.next=4,n.sendRawTransaction(r).do();case 4:return e.next=6,de(n,a[Zt.POOL_TOKEN_CREATE]);case 6:if(o=e.sent,"number"==typeof(i=o["asset-index"])){e.next=10;break}throw new Error("Generated ID is not valid: got ".concat(i));case 10:return e.abrupt("return",{poolTokenID:i});case 13:throw e.prev=13,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while bootstraping the pool. Try again later.");case 16:case"end":return e.stop()}}),e,null,[[1,13]])})))).apply(this,arguments)}function on(){return(on=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.signedTxns,c=t.txnIDs,e.next=3,an({client:n,signedTxns:u,txnIDs:c});case 3:return e.abrupt("return",$t.v1_1.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var un={generateTxns:function(e){return tn.apply(this,arguments)},signTxns:function(e){return rn.apply(this,arguments)},execute:function(e){return on.apply(this,arguments)},getBootstrapFundingTxnAmount:nn};var cn=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e}({}),pn={ASA_ALGO:5,ASA_ASA:6};function ln(e,t){return dn.apply(this,arguments)}function dn(){return(dn=i(s().mark((function t(n,r){var a,o,i;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(o=null===(a=r.find((function(e){return"appl"===e.txn.type})))||void 0===a?void 0:a.txn.txID())){t.next=7;break}return t.next=4,e.waitForConfirmation(n,o,R);case 4:t.t0=t.sent,t.next=8;break;case 7:t.t0=void 0;case 8:return i=t.t0,t.abrupt("return",i);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function fn(e,t){return mn.apply(this,arguments)}function mn(){return(mn=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ln(t,n);case 2:return r=e.sent,e.abrupt("return",null==r?void 0:r["inner-txns"]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function hn(e,t){return gn.apply(this,arguments)}function gn(){return(gn=i(s().mark((function t(n,r){var a,o;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fn(n,r);case 2:return a=t.sent,s=r[0].txn,o=e.encodeAddress(s.from.publicKey),t.abrupt("return",null==a?void 0:a.reduce((function(t,n){var r=t,a=n.txn.txn;return a.type===e.TransactionType.axfer&&e.encodeAddress(a.arcv)===o?r.push({id:a.xaid,amount:a.aamt}):a.type===e.TransactionType.pay&&e.encodeAddress(a.rcv)===o&&r.push({id:j,amount:a.amt}),r}),[]));case 5:case"end":return t.stop()}var s}),t)})))).apply(this,arguments)}function xn(){return(xn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Pe(a,U.V2),l=e.getApplicationAddress(p),d=Z(o,i),f=v(d,2),m=f[0].id,h=f[1].id,t.next=9,$t.v2.getPoolInfo({client:r,network:a,asset1ID:m,asset2ID:h});case 9:if(t.sent.status!==Ct.READY){t.next=12;break}throw new Error("Pool for ".concat(o.unit_name,"-").concat(i.unit_name," already exists"));case 12:return g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=g.address(),A=te(h),(I=e.makeApplicationOptInTxnFromObject({from:x,appIndex:p,appArgs:[Te("bootstrap")],note:_e.getAppCallTxnNoteWithClientName(U.V2),foreignAssets:[m,h],rekeyTo:l,suggestedParams:c})).fee=In(A),w=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:x,amount:An(A),suggestedParams:c}),(y=[])[cn.FUNDING_TXN]=w,y[cn.VALIDATOR_APP_CALL]=I,b=e.assignGroupID(y),(T=[])[cn.FUNDING_TXN]={txn:b[cn.FUNDING_TXN],signers:[u]},T[cn.VALIDATOR_APP_CALL]={txn:b[cn.VALIDATOR_APP_CALL],signers:[x]},t.abrupt("return",T);case 26:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function An(e){return function(e,t){var n=kt(e).schema,r=n.numLocalInts,a=n.numLocalByteSlices,s=S+D+D+O+F*r+C*a;return t||(s+=D),s}(U.V2,e)+In(e)+D}function In(t){return((t?pn.ASA_ALGO:pn.ASA_ASA)+1)*e.ALGORAND_MIN_TX_FEE}function vn(){return(vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===cn.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function wn(){return(wn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.txGroup,c=t.signedTxns,e.prev=1,e.next=4,n.sendRawTransaction(c).do();case 4:return e.next=6,ln(n,u);case 6:if(e.t1=p=e.sent,e.t0=null===e.t1,e.t0){e.next=10;break}e.t0=void 0===p;case 10:if(!e.t0){e.next=14;break}e.t2=void 0,e.next=15;break;case 14:e.t2=null===(l=p["local-state-delta"][0].delta)||void 0===l||null===(d=l.find((function(e){return e.key===btoa(Ft.v2.poolTokenID)})))||void 0===d?void 0:d.value.uint;case 15:if("number"==typeof(f=e.t2)){e.next=18;break}throw new Error("Generated ID is not valid: got ".concat(f));case 18:return e.abrupt("return",$t.v2.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 21:throw e.prev=21,e.t3=e.catch(1),new Y(e.t3,"We encountered something unexpected while bootstraping the pool. Try again later.");case 24:case"end":return e.stop()}}),e,null,[[1,21]])})))).apply(this,arguments)}var yn,bn={generateTxns:function(e){return xn.apply(this,arguments)},signTxns:function(e){return vn.apply(this,arguments)},execute:function(e){return wn.apply(this,arguments)},getBootstrapFundingTxnAmount:An,getTotalCost:function(t){return e.ALGORAND_MIN_TX_FEE+An(t)}};var Tn,kn,_n,En,Pn=(l(yn={},U.V1_1,un),l(yn,U.V2,bn),l(yn,"generateTxns",(function(e){return e.contractVersion===U.V1_1?un.generateTxns(e):bn.generateTxns(e)})),l(yn,"signTxns",(function(e){return e.contractVersion===U.V1_1?un.signTxns(e):bn.signTxns(e)})),l(yn,"execute",(function(e){return e.contractVersion===U.V1_1?un.execute(e):bn.execute(e)})),l(yn,"calculateBootstrapFundingTxnAmount",(function(e){var t=e.contractVersion,n=e.isAlgoPool;return t===U.V1_1?un.getBootstrapFundingTxnAmount(n):bn.getBootstrapFundingTxnAmount(n)})),yn),Sn=function(e){return e[e.FEE_TXN=0]="FEE_TXN",e[e.VALIDATOR_APP_CALL_TXN=1]="VALIDATOR_APP_CALL_TXN",e[e.ASSET1_IN_TXN=2]="ASSET1_IN_TXN",e[e.ASSET2_IN_TXN=3]="ASSET2_IN_TXN",e[e.LIQUDITY_OUT_TXN=4]="LIQUDITY_OUT_TXN",e}({}),Dn=5*e.ALGORAND_MIN_TX_FEE,On=function(e){return e.SINGLE="single",e.FLEXIBLE="flexible",e.INITIAL="initial",e}({}),Nn=(l(Tn={},On.FLEXIBLE,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),l(Tn,On.SINGLE,{ASSET_IN_TXN:0,VALIDATOR_APP_CALL_TXN:1}),l(Tn,On.INITIAL,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),Tn),Bn=(l(kn={},On.INITIAL,1),l(kn,On.SINGLE,2),l(kn,On.FLEXIBLE,2),kn),Cn=(l(_n={},On.INITIAL,3),l(_n,On.FLEXIBLE,3),l(_n,On.SINGLE,2),_n);function Fn(e){var t,n,r,a=e.reserves,s=e.totalFeeShare,o=e.asset1,i=e.asset2,u=a.asset1*a.asset2,c=a.asset1+BigInt(o.amount),p=a.asset2+BigInt(i.amount),l=c*p,d=BigInt(parseInt(String(Math.sqrt(Number(l*a.issuedLiquidity*a.issuedLiquidity/u))))),f=d-a.issuedLiquidity,m=f*c/d,h=f*p/d,g=BigInt(o.amount)-m,x=BigInt(i.amount)-h;if(g>x){var A=g;r=Rn(A,s),t={id:o.id,amount:A+r,decimals:o.decimals,reserves:a.asset1},n={id:i.id,amount:BigInt(Math.abs(Math.min(Number(x),0))),decimals:i.decimals,reserves:a.asset2},f-=r*d/(c*BigInt(2))}else{var I=x;r=Rn(I,s),t={id:i.id,amount:I+r,decimals:i.decimals,reserves:a.asset2},n={id:o.id,amount:BigInt(Math.abs(Math.min(Number(g),0))),decimals:o.decimals,reserves:a.asset1},f-=r*d/(p*BigInt(2))}return{poolTokenOutAmount:f,internalSwapQuote:{assetIn:t,assetOut:n,swapFees:r,priceImpact:pt({inputSupply:t.reserves,outputSupply:n.reserves,assetIn:t,assetOut:n})}}}function Ln(e,t){if(!e.amount||!t.amount)throw new Error("Both assets are required for the initial add liquidity");return BigInt(Math.floor(Math.abs(Math.sqrt(Number(e.amount)*Number(t.amount))-Lt)))}function Rn(e,t){return e*BigInt(t)/(BigInt(1e4)-BigInt(t))}function Mn(t){return(Bn[t]+1)*e.ALGORAND_MIN_TX_FEE}var Un=Te("add_liquidity"),jn=(l(En={},U.V1_1,[Te("mint")]),l(En,U.V2,{INITIAL_LIQUIDITY:[Te("add_initial_liquidity")],SINGLE_ASSET_MODE:[Un,Te("single")],FLEXIBLE_MODE:[Un,Te("flexible")]}),En);function Vn(){return(Vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.asset1In,u=n.asset2In,c=n.poolTokenOut,p=n.slippage,l=n.initiatorAddr,d=me("negative",p,c.amount),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:Pe(a,U.V1_1),appArgs:jn.v1_1,accounts:[l],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:u.id==j?[i.id,c.id]:[i.id,u.id,c.id],suggestedParams:f}),h=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:i.id,amount:i.amount,suggestedParams:f}),g=u.id===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:u.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:u.id,amount:u.amount,suggestedParams:f}),x=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:l,assetIndex:c.id,amount:d,suggestedParams:f}),A=e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:m.fee+x.fee,note:P,suggestedParams:f}),I=e.assignGroupID([A,m,h,g,x]),t.abrupt("return",[{txn:I[0],signers:[l]},{txn:I[1],signers:[o]},{txn:I[2],signers:[l]},{txn:I[3],signers:[l]},{txn:I[4],signers:[o]}]);case 12:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Gn(){return(Gn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,i=r.account,t.next=4,o([a]);case 4:return u=t.sent,c=v(u,3),p=c[0],l=c[1],d=c[2],f=a.map((function(t,n){return n===Sn.FEE_TXN?p:n===Sn.ASSET1_IN_TXN?l:n===Sn.ASSET2_IN_TXN?d:e.signLogicSigTransactionObject(t.txn,i).blob})),t.abrupt("return",f);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Xn(){return(Xn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.signedTxns,i=t.initiatorAddr,e.prev=1,u=BigInt(a[Sn.LIQUDITY_OUT_TXN].txn.amount),e.next=5,Dt({client:n,pool:r,accountAddr:i});case 5:return c=e.sent,e.next=8,Ie(n,[o]);case 8:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,h=we(a),g=ye(a),e.next=17,Dt({client:n,pool:r,accountAddr:i});case 17:return x=e.sent,(A=x.excessPoolTokens-c.excessPoolTokens)<0n&&(A=0n),e.abrupt("return",{round:f,fees:h,poolTokenID:r.poolTokenID,poolTokenOut:u+A,excessAmount:{excessAmountForAddingLiquidity:A,totalExcessAmount:x.excessPoolTokens},txnID:m,groupID:g});case 23:throw e.prev=23,e.t0=e.catch(1),"SlippageTolerance"===(I=new Y(e.t0,"We encountered something unexpected while adding liquidity. Try again later.")).type&&I.setMessage("Adding liquidity failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),I;case 28:case"end":return e.stop()}}),e,null,[[1,23]])})))).apply(this,arguments)}var qn=Object.freeze({__proto__:null,execute:function(e){return Xn.apply(this,arguments)},generateTxns:function(e){return Vn.apply(this,arguments)},getQuote:function(e){var t=e.pool,n=e.reserves,r=e.asset1In,a=e.asset2In;if(0n===n.issuedLiquidity){var s=BigInt(Math.floor(Math.sqrt(Number(r)*Number(a))));if(s<=BigInt(L))throw new Error("Initial liquidity amount is too small. The amount must be greater than ".concat(L,", this quote is for ").concat(s,"."));return{round:n.round,asset1ID:t.asset1ID,asset1In:BigInt(r),asset2ID:t.asset2ID,asset2In:BigInt(a),poolTokenID:t.poolTokenID,poolTokenOut:s-BigInt(L),share:1}}var o=BigInt(r)*n.issuedLiquidity/n.asset1,i=BigInt(a)*n.issuedLiquidity/n.asset2,u=oo)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(t)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{assetInID:i,assetInAmount:l,assetOutID:c,assetOutAmount:m,swapFee:Number(h),rate:he(p,Number(m))/he(u,Number(l)),priceImpact:g}}function xr(e){var t=e.amount,n=e.assetIn,r=e.assetOut,a=e.pool;if(!a||!$t.isPoolReady(a))throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i=n.id,u=n.decimals,c=r.id,p=r.decimals,l=BigInt(t),d=a.totalFeeShare;if(c===a.asset1ID)s=a.asset2Reserves,o=a.asset1Reserves;else{if(c!==a.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(c,") doesn't belong to the pool ").concat(a.account.address(),"."));s=a.asset1Reserves,o=a.asset2Reserves}var f=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapOutputAmount,a=e.totalFeeShare,s=e.decimals,o=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.outputAmount,a=t*n,s=BigInt(a/(n-r))-t;return s+=BigInt(1),s}({inputSupply:t,outputSupply:n,outputAmount:r}),i=function(e){var t=e.swapAmount,n=e.totalFeeShare,r=Math.floor(Number(t*BigInt(1e4)/(BigInt(1e4)-BigInt(n)))),a=BigInt(r)-t;return a}({swapAmount:o,totalFeeShare:a}),u=o+i,c=pt({inputSupply:t,outputSupply:n,assetIn:{amount:u,decimals:s.assetIn},assetOut:{amount:r,decimals:s.assetOut}});return{swapInputAmount:u,totalFeeAmount:i,priceImpact:c}}({inputSupply:s,outputSupply:o,swapOutputAmount:l,totalFeeShare:d,decimals:{assetIn:u,assetOut:p}}),m=f.swapInputAmount,h=f.totalFeeAmount,g=f.priceImpact;if(l>o)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(m)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{type:rt.Direct,data:{pool:a,quote:{assetInID:i,assetInAmount:m,assetOutID:c,assetOutAmount:l,swapFee:Number(h),rate:he(p,Number(l))/he(u,Number(m)),priceImpact:g}}}}function Ar(e){return Ir.apply(this,arguments)}function Ir(){return(Ir=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[],u?c.push(new Promise((function(e,t){try{var s=gr({amount:n,assetIn:r,assetOut:a,pool:u});e({type:rt.Direct,data:{pool:u,quote:s}})}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair"))),o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedInput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=6,hr(c);case 6:return p=e.sent,e.abrupt("return",ht(p));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function vr(e){return wr.apply(this,arguments)}function wr(){return(wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[new Promise((function(e,t){try{e(xr({amount:n,assetIn:r,assetOut:a,pool:u}))}catch(e){t(e)}}))],o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedOutput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=5,hr(c);case 5:return p=e.sent,e.abrupt("return",ht(p));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function yr(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapInputAmount,a=e.totalFeeShare,s=e.decimals,o=BigInt(function(e){var t=e.inputAmount,n=e.totalFeeShare;return Math.floor(Number(t*BigInt(n))/1e4)}({inputAmount:r,totalFeeShare:a})),i=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapAmount,a=t*n,s=n-BigInt(a/(t+BigInt(r)));return s-=BigInt(1)}({inputSupply:t,outputSupply:n,swapAmount:r-o});return{swapOutputAmount:i,totalFeeAmount:o,priceImpact:pt({inputSupply:t,outputSupply:n,assetIn:{amount:r,decimals:s.assetIn},assetOut:{amount:i,decimals:s.assetOut}})}}var br={getQuote:function(e){return mr.apply(this,arguments)},getFixedInputSwapQuote:Ar,getFixedInputDirectSwapQuote:gr,getFixedOutputDirectSwapQuote:xr,getFixedOutputSwapQuote:vr,generateTxns:function(e){return dr.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return fr.apply(this,arguments)},calculateFixedInputSwap:yr};function Tr(e,t){var n,r,a=BigInt(e),s=t.issuedLiquidity;return s>a+BigInt(Lt)?(n=a*t.asset1/s,r=a*t.asset2/s):(n=t.asset1,r=t.asset2),{asset1OutputAmount:n,asset2OutputAmount:r}}function kr(){return(kr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.minAsset1Amount,c=n.minAsset2Amount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.account.address(),f=a.poolTokenID){t.next=8;break}throw new Error("Pool token asset ID is missing");case 8:return m=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:f,amount:o,suggestedParams:l}),(h=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(me("negative",p,u)),e.encodeUint64(me("negative",p,c))],accounts:[d],foreignAssets:[a.asset1ID,a.asset2ID],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(g=[])[ir.ASSET_TRANSFER_TXN]=m,g[ir.APP_CALL_TXN]=h,x=e.assignGroupID(g),t.abrupt("return",[{txn:x[ir.ASSET_TRANSFER_TXN],signers:[i]},{txn:x[ir.APP_CALL_TXN],signers:[i]}]);case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _r(){return(_r=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.initiatorAddr,i=n.poolTokenIn,u=n.outputAssetId,c=n.minOutputAssetAmount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.asset1ID,f=a.asset2ID,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:if(g=0,x=0,A=me("negative",p,c),u!==d){t.next=17;break}g=A,x=0,t.next=23;break;case 17:if(u!==f){t.next=22;break}g=0,x=A,t.next=23;break;case 22:throw new Error("Invalid output asset id. It doesn't match with pool assets");case 23:return I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:m,assetIndex:h,amount:i,suggestedParams:l}),(v=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(g),e.encodeUint64(x)],accounts:[m],foreignAssets:[u],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(w=[])[ir.ASSET_TRANSFER_TXN]=I,w[ir.APP_CALL_TXN]=v,y=e.assignGroupID(w),t.abrupt("return",[{txn:y[ir.ASSET_TRANSFER_TXN],signers:[o]},{txn:y[ir.APP_CALL_TXN],signers:[o]}]);case 31:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Er(){return(Er=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.txGroup,a=t.signedTxns,e.next=3,Ie(n,[a]);case 3:return o=e.sent,i=v(o,1),u=i[0].txnID,e.prev=6,e.next=9,hn(n,r);case 9:c=e.sent,e.next=14;break;case 12:e.prev=12,e.t0=e.catch(6);case 14:return e.abrupt("return",{outputAssets:c,txnID:u});case 15:case"end":return e.stop()}}),e,null,[[6,12]])})))).apply(this,arguments)}var Pr,Sr={getQuote:function(e){var t=e.pool,n=e.reserves,r=e.poolTokenIn,a=BigInt(r),s=Tr(a,n),o=s.asset1OutputAmount,i=s.asset2OutputAmount;return{round:n.round,asset1Out:{assetId:t.asset1ID,amount:o},asset2Out:{assetId:t.asset2ID,amount:i},poolTokenIn:{assetId:t.poolTokenID,amount:a}}},getSingleAssetRemoveLiquidityQuote:function(e){var t,n=e.pool,r=e.reserves,a=e.poolTokenIn,s=e.assetOutID,o=e.decimals,i=BigInt(a),u=Tr(i,r),c=u.asset1OutputAmount,p=u.asset2OutputAmount,l=n.totalFeeShare;if(s===n.asset1ID){var d=br.calculateFixedInputSwap({inputSupply:r.asset2-p,outputSupply:r.asset1-c,swapInputAmount:p,totalFeeShare:l,decimals:o}),f=d.swapOutputAmount,m=d.totalFeeAmount,h=d.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:c+f},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:f},swapFees:{assetId:n.asset2ID,amount:m},priceImpact:h}}}else{if(s!==n.asset2ID)throw new Error("assetOutID must be one of the pool assets");var g=br.calculateFixedInputSwap({inputSupply:r.asset1-c,outputSupply:r.asset2-p,swapInputAmount:c,totalFeeShare:l,decimals:o}),x=g.swapOutputAmount,A=g.totalFeeAmount,I=g.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:p+x},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:x},swapFees:{assetId:n.asset2ID,amount:A},priceImpact:I}}}return t},generateTxns:function(e){return kr.apply(this,arguments)},generateSingleAssetOutTxns:function(e){return _r.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return Er.apply(this,arguments)}},Dr=(l(Pr={},U.V1_1,lr),l(Pr,U.V2,Sr),Pr),Or=3n,Nr=1000n,Br=function(e){return e[e.FEE_TXN_INDEX=0]="FEE_TXN_INDEX",e[e.VALIDATOR_APP_CALL_TXN_INDEX=1]="VALIDATOR_APP_CALL_TXN_INDEX",e[e.ASSET_IN_TXN_INDEX=2]="ASSET_IN_TXN_INDEX",e[e.ASSET_OUT_TXN_INDEX=3]="ASSET_OUT_TXN_INDEX",e}(Br||{});function Cr(){return(Cr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,t.next=3,o([a]);case 3:return i=t.sent,u=v(i,2),c=u[0],p=u[1],l=a.map((function(t,n){return n===Br.FEE_TXN_INDEX?c:n===Br.ASSET_IN_TXN_INDEX?p:e.signLogicSigTransactionObject(t.txn,r.account.lsig).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Fr(){return(Fr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=n.client,a=n.quoteAndPool,o=n.swapType,i=n.slippage,u=n.initiatorAddr,c=a.pool,p=a.quote,l=p.assetInID,d=p.assetOutID,f=c.account.address(),(m=[c.asset1ID,c.asset2ID]).includes(l)&&m.includes(d)&&l!==d){t.next=7;break}throw new Y({pool:c,quote:p},"Input asset (#".concat(l,") and output asset (#").concat(d,") provided to generate transactions do not belong to the pool ").concat(f,"."));case 7:return t.next=9,r.getTransactionParams().do();case 9:return h=t.sent,g=[Te("swap"),o===Ce.FixedInput?Te("fi"):Te("fo")],x=e.makeApplicationNoOpTxnFromObject({from:f,appIndex:c.validatorAppID,appArgs:g,accounts:[u],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:c.asset2ID==j?[c.asset1ID,c.poolTokenID]:[c.asset1ID,c.asset2ID,c.poolTokenID],suggestedParams:h}),A=o===Ce.FixedOutput?me("positive",i,p.assetInAmount):p.assetInAmount,I=l===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:A,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:u,to:f,assetIndex:l,amount:A,suggestedParams:h}),v=o===Ce.FixedInput?me("negative",i,p.assetOutAmount):p.assetOutAmount,w=d===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:f,to:u,amount:v,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:f,to:u,assetIndex:d,amount:v,suggestedParams:h}),y=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:x.fee+w.fee,note:P,suggestedParams:h}),b=e.assignGroupID([y,x,I,w]),t.abrupt("return",[{txn:b[0],signers:[u]},{txn:b[1],signers:[f]},{txn:b[2],signers:[u]},{txn:b[3],signers:[f]}]);case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Lr(e){var t=e.pool,n=e.reserves,r=e.assetIn,s=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var o,i,u,c=BigInt(r.amount);if(r.id===t.asset1ID)o=t.asset2ID,i=n.asset1,u=n.asset2;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Input asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));o=t.asset1ID,i=n.asset2,u=n.asset1}var p=c*Or/Nr,l=u-i*u/(i+(c-p));if(l>u)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var d={assetIn:{amount:c,decimals:s.assetIn},assetOut:{amount:l,decimals:s.assetOut}},f={round:n.round,assetInID:r.id,assetInAmount:c,assetOutID:o,assetOutAmount:l,swapFee:Number(p),rate:ct(d),priceImpact:pt(a({inputSupply:i,outputSupply:u},d))};return{type:rt.Direct,data:{pool:t,quote:f}}}function Rr(e){return Mr.apply(this,arguments)}function Mr(){return(Mr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,i.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount),assetOutID:i.id,assetOutAmount:BigInt(i.amount)+A,excessAmount:{assetID:i.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ur(e){var t=e.pool,n=e.reserves,r=e.assetOut,a=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i,u=BigInt(r.amount);if(r.id===t.asset1ID)s=t.asset2ID,o=n.asset2,i=n.asset1;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));s=t.asset1ID,o=n.asset1,i=n.asset2}if(u>i)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var c=o*i/(i-u)-o,p=c*Nr/(Nr-Or),l=p-c,d=he(a.assetOut,Number(u))/he(a.assetIn,Number(p)),f=he(a.assetOut,Number(i))/he(a.assetIn,Number(o)),m=ge({decimalPlaces:5},Math.abs(d/f-1)),h={round:n.round,assetInID:s,assetInAmount:p,assetOutID:r.id,assetOutAmount:u,swapFee:Number(l),rate:d,priceImpact:m};return{type:rt.Direct,data:{pool:t,quote:h}}}function jr(e){return Vr.apply(this,arguments)}function Vr(){return(Vr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,o.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount)-A,assetOutID:i.id,assetOutAmount:BigInt(i.amount),excessAmount:{assetID:o.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Gr(){return(Gr=i(s().mark((function e(t){var n,r,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.pool,o=t.swapType,i=t.txGroup,u=t.signedTxns,c=t.initiatorAddr,r.status===Ct.READY){e.next=3;break}throw new Y({pool:r,swapType:o,txGroup:i},"There is not an available pool for this asset pair");case 3:if(e.prev=3,p={id:i[Br.ASSET_IN_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_IN_TXN_INDEX].txn.amount},l={id:i[Br.ASSET_OUT_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_OUT_TXN_INDEX].txn.amount},o!==Ce.FixedInput){e.next=12;break}return e.next=9,Rr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 9:d=e.sent,e.next=15;break;case 12:return e.next=14,jr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 14:d=e.sent;case 15:return e.abrupt("return",a(a({},d),{},{groupID:ye(i),fees:we(i)}));case 18:throw e.prev=18,e.t0=e.catch(3),"SlippageTolerance"===(f=new Y(e.t0,"We encountered something unexpected while swapping. Try again later.")).type&&f.setMessage("The swap failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),f;case 23:case"end":return e.stop()}}),e,null,[[3,18]])})))).apply(this,arguments)}var Xr,qr={getQuote:function(e,t,n,r,a){return e===Ce.FixedInput?Lr({pool:t,reserves:n,assetIn:r,decimals:a}):Ur({pool:t,reserves:n,assetOut:r,decimals:a})},getFixedInputSwapQuote:Lr,getFixedOutputSwapQuote:Ur,generateTxns:function(e){return Fr.apply(this,arguments)},signTxns:function(e){return Cr.apply(this,arguments)},execute:function(e){return Gr.apply(this,arguments)},executeFixedOutputSwap:jr};function Qr(e){return Promise.allSettled(e).then((function(e){if(e.every((function(e){return"rejected"===e.status}))){var t=v(e.map((function(e){return e.reason})),2),n=t[0],r=t[1];if(gt(n)&&!gt(r))throw n;throw r}return e.filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value}))}))}function Wr(){return(Wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.isSwapRouterEnabled,u=t.pools,c=[],(p=u.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedInputSwapQuote({pool:p.info,assetIn:{amount:r,id:Number(a.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=u.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedInputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:i,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zr(){return(zr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.pools,u=t.isSwapRouterEnabled,c=[],(p=i.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedOutputSwapQuote({pool:p.info,assetOut:{amount:r,id:Number(o.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=i.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedOutputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:u,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jr=(l(Xr={},U.V1_1,qr),l(Xr,U.V2,br),l(Xr,"getQuote",(function(e){var t=e.type;if(t===Ce.FixedInput)return function(e){return Wr.apply(this,arguments)}(e);if(t===Ce.FixedOutput)return function(e){return zr.apply(this,arguments)}(e);throw new E(_.InvalidSwapTypeError,"Invalid swap type")})),l(Xr,"generateTxns",(function(e){return e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1?qr.generateTxns(a(a({},e),{},{quoteAndPool:e.quote.data})):br.generateTxns(e)})),l(Xr,"signTxns",(function(e){if(e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1){var t=e.quote.data.pool;return qr.signTxns(a(a({},e),{},{pool:t}))}return br.signTxns(e)})),l(Xr,"execute",(function(e){return e.contractVersion===U.V1_1?qr.execute(e):br.execute(e)})),Xr);function Kr(){return(Kr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.initiatorSigner,e.prev=1,e.next=4,Yr({txGroup:a,pool:r,initiatorSigner:o});case 4:return i=e.sent,e.next=7,Ie(n,[i]);case 7:return u=e.sent,c=v(u,1),p=c[0],l=p.txnID,d=p.confirmedRound,e.abrupt("return",{fees:we(a),confirmedRound:d,txnID:l,groupID:ye(a)});case 15:throw e.prev=15,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while redeeming. Try again later.");case 18:case"end":return e.stop()}}),e,null,[[1,15]])})))).apply(this,arguments)}function Yr(e){return Hr.apply(this,arguments)}function Hr(){return(Hr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.pool,o=n.initiatorSigner,t.next=3,o([r]);case 3:return i=t.sent,u=v(i,1),c=u[0],p=a.account.lsig,l=r.map((function(t,n){return 0===n?c:e.signLogicSigTransactionObject(t.txn,p).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function $r(){return $r=i(s().mark((function t(n){var r,a,o,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.data,o=n.initiatorSigner,t.prev=1,u=a.map((function(e){var t=e.txGroup,n=e.pool;return{txns:t,txnFees:we(t),groupID:ye(t),lsig:n.account.lsig}})),t.next=5,o(u.map((function(e){return e.txns})));case 5:return c=t.sent,p=Promise.all(u.map((function(t,n){return new Promise(function(){var a=i(s().mark((function a(o,i){var u,p,l,d,f,m;return s().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,u=t.txns.map((function(r,a){return 0===a?c[n]:e.signLogicSigTransactionObject(r.txn,t.lsig).blob})),a.next=4,Ie(r,[u]);case 4:p=a.sent,l=v(p,1),d=l[0],f=d.txnID,m=d.confirmedRound,o({fees:t.txnFees,groupID:t.groupID,txnID:f,confirmedRound:m}),a.next=15;break;case 12:a.prev=12,a.t0=a.catch(0),i(a.t0);case 15:case"end":return a.stop()}}),a,null,[[0,12]])})));return function(e,t){return a.apply(this,arguments)}}())}))),t.abrupt("return",p);case 10:throw t.prev=10,t.t0=t.catch(1),new Y(t.t0,"We encountered something unexpected while redeeming. Try again later.");case 13:case"end":return t.stop()}}),t,null,[[1,10]])}))),$r.apply(this,arguments)}function Zr(){return(Zr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.assetID,i=n.assetOut,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=a.account.address(),l=e.makeApplicationNoOpTxnFromObject({from:p,appIndex:a.validatorAppID,appArgs:[Te("redeem")],note:_e.getAppCallTxnNoteWithClientName(a.contractVersion),accounts:[u],foreignAssets:0==a.asset2ID?[a.asset1ID,a.poolTokenID]:[a.asset1ID,a.asset2ID,a.poolTokenID],suggestedParams:c}),d=0===o?e.makePaymentTxnWithSuggestedParamsFromObject({from:p,to:u,amount:BigInt(i),suggestedParams:c}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:p,to:u,assetIndex:o,amount:BigInt(i),suggestedParams:c}),f=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:p,amount:l.fee+d.fee,note:P,suggestedParams:c}),m=e.assignGroupID([f,l,d]),t.abrupt("return",[{txn:m[0],signers:[u]},{txn:m[1],signers:[p]},{txn:m[2],signers:[p]}]);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ea(e){var t,n={},r=T(e);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=(new TextDecoder).decode(Buffer.from(a.key,"base64")),o=void 0;o=1===a.value.type?a.value.bytes:a.value.uint,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function ta(e,t,n){return e*t/n}var na=BigInt(31536e3),ra=BigInt(1e14),aa=BigInt(1e16),sa={testnet:548587153,mainnet:1385499515},oa=14;function ia(e){return ua.apply(this,arguments)}function ua(){return(ua=i(s().mark((function t(n){var r,a,o,i,u;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(sa[a]),t.next=4,_t(r,i);case 4:return u=t.sent.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!u.includes(e)})));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ca(){return(ca=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,y,b,T,k,_,E,P;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.poolTokenId,u=n.lendingManagerId,c=n.asset1In,p=n.asset2In,l=n.initiatorAddr,d=e.getApplicationAddress(sa[a]),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=[c,p].sort((function(e,t){return t.fAssetId-e.fAssetId})),h=v(m,2),g=h[0],x=h[1],A=te(x.id),I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:g.id,amount:g.amount,suggestedParams:f}),y=A?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:x.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:x.id,amount:x.amount,suggestedParams:f}),(b=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("add_liquidity"),e.decodeAddress(o).publicKey,e.encodeUint64(g.lendingAppId),e.encodeUint64(x.lendingAppId)],foreignAssets:[g.id,x.id,g.fAssetId,x.fAssetId],foreignApps:[g.lendingAppId,x.lendingAppId,u],accounts:[o],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),T=Pe(a,U.V2),k=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("noop")],foreignAssets:[i],foreignApps:[T],accounts:[o],suggestedParams:f}),_=[I,y,b,k],t.next=16,ia({client:r,network:a,assetIDs:[g.id,x.id,g.fAssetId,x.fAssetId,i]});case 16:return(E=t.sent).length&&((P=[e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:D*E.length,suggestedParams:f}),e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("asset_optin")].concat(w(E.map((function(t){return e.encodeUint64(t)})))),foreignAssets:w(E),suggestedParams:f})])[1].fee=(E.length+1)*e.ALGORAND_MIN_TX_FEE,_.unshift.apply(_,P)),t.abrupt("return",e.assignGroupID(_).map((function(e){return{txn:e,signers:[l]}})));case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function pa(){return(pa=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.asset1Out,c=n.asset2Out,p=n.lendingManagerId,l=n.network,d=e.getApplicationAddress(sa[l]),t.next=4,r.getTransactionParams().do();case 4:if(f=t.sent,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:return g=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:h,amount:o,suggestedParams:f}),(x=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("remove_liquidity"),e.decodeAddress(m).publicKey,e.encodeUint64(u.lendingAppId),e.encodeUint64(c.lendingAppId)],accounts:[m],foreignAssets:[u.id,c.id,u.fAssetId,c.fAssetId],foreignApps:[u.lendingAppId,c.lendingAppId,p],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),A=Pe(l,U.V2),I=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("noop")],accounts:[m],foreignAssets:[h,u.fAssetId,c.fAssetId],foreignApps:[A],suggestedParams:f}),v=e.assignGroupID([g,x,I]),t.abrupt("return",v.map((function(e){return{txn:e,signers:[i]}})));case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function la(e,t,n){var r=BigInt(Math.floor((new Date).getTime()/1e3)-function(e){return null!=e?e:Math.floor((new Date).getTime()/1e3)}(n));return ta(e,aa+t*r/na,aa)}function da(){return(da=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,a=r.params["global-state"],o=ea(a),i=Number(Buffer.from(o.pm,"base64").readBigUInt64BE(0)),u=Buffer.from(o.i,"base64"),c=u.readBigUInt64BE(32),p=u.readBigUInt64BE(40),l=Number(u.readBigUInt64BE(48)),e.abrupt("return",{appId:n,managerAppId:i,depositInterestRate:c,depositInterestIndex:p,lastUpdate:l});case 11:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var fa={AddLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return ca.apply(this,arguments)},getAddLiquidityTotalFee:function(t){return e.ALGORAND_MIN_TX_FEE*(4+oa)+(t?(t+1)*e.ALGORAND_MIN_TX_FEE+t*D:0)}}),RemoveLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return pa.apply(this,arguments)},getRemoveLiquidityTotalFee:function(){return e.ALGORAND_MIN_TX_FEE*(3+oa)}}),calculateWithdrawReturn:function(e){var t=e.withdrawAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return ta(BigInt(t),n,ra)},calculateDepositReturn:function(e){var t=e.depositAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return BigInt(t)*ra/n},getFolksWrapperAppOptInRequiredAssetIDs:ia};function ma(t){var n=t.suggestedParams,r=t.stakingAppID,a=t.initiatorAddr,s=t.liquidityAssetID,o=t.program,i=t.amount,u=e.encodeUint64(i),c=e.encodeUint64(o.id);return e.makeApplicationNoOpTxnFromObject({appIndex:r,from:a,suggestedParams:n,foreignAssets:[s],accounts:[o.accountAddress],appArgs:[Te("commit"),u],note:ae([Te("tinymanStaking/v1:b"),c,e.encodeUint64(s),u])})}function ha(){return(ha=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.stakingAppID,o=n.program,i=n.requiredAssetID,u=n.liquidityAssetID,c=n.amount,p=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=ma({suggestedParams:l,stakingAppID:a,program:o,liquidityAssetID:u,initiatorAddr:p,amount:c}),f=[d],"number"!=typeof i){t.next=10;break}return m=e.makeApplicationNoOpTxnFromObject({appIndex:a,from:p,suggestedParams:l,foreignAssets:[i],accounts:[o.accountAddress],appArgs:[Te("log_balance")]}),f=e.assignGroupID([d,m]),t.abrupt("return",[{txn:f[0],signers:[p]},{txn:f[1],signers:[p]}]);case 10:return t.abrupt("return",[{txn:f[0],signers:[p]}]);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var ga=604800,xa=1e3,Aa={testnet:480164661,mainnet:2200606875},Ia={testnet:360907790,mainnet:2200609638},va={testnet:336189106,mainnet:2200608153},wa={testnet:383416252,mainnet:2200608887},ya=2500,ba=400,Ta=604800,ka=Te("p"),_a=Te("a"),Ea=24,Pa=111300,Sa=ya+ba*(41+Ea),Da=function(e){return e[e.Against=0]="Against",e[e.For=1]="For",e[e.Abstain=2]="Abstain",e}(Da||{}),Oa=new Uint8Array(34),Na="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ";function Ba(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,n=new Uint8Array(t),r=BigInt(e),a=t-1;a>=0;a--)n[a]=Number(r&BigInt(255)),r>>=BigInt(8);return n}function Ca(e,t){return 0===Buffer.compare(e,t)}function Fa(e){for(var t=0n,n=0;n=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r>>0,o=new Uint8Array(s);e[t];){var p=n[e.charCodeAt(t)];if(255===p)return;for(var l=0,d=s-1;(0!==p||l>>0,o[d]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");a=l,t++}if(" "!==e[t]){for(var f=s-a;f!==s&&0===o[f];)f++;for(var m=new Uint8Array(r+(s-f)),h=r;f!==s;)m[h++]=o[f++];return m}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var n=0,r=0,a=0,s=t.length;a!==s&&0===t[a];)a++,n++;for(var o=(s-a)*p+1>>>0,c=new Uint8Array(o);a!==s;){for(var l=t[a],d=0,f=o-1;(0!==l||d>>0,c[f]=l%i>>>0,l=l/i>>>0;if(0!==l)throw new Error("Non-zero carry");r=d,a++}for(var m=o-r;m!==o&&0===c[m];)m++;for(var h=u.repeat(n);mLa(a(e))})}function Wa({name:e,prefix:t,bitsPerChar:n,alphabet:r}){return qa({prefix:t,name:e,encode:e=>function(e,t,n){const r="="===t[t.length-1],a=(1<n;)o-=n,s+=t[a&i>>o];if(0!==o&&(s+=t[a&i<function(e,t,n,r){const a={};for(let e=0;e=8&&(i-=8,o[c++]=255&u>>i)}if(i>=n||0!=(255&u<<8-i))throw new SyntaxError("Unexpected end of data");return o}(t,r,n,e)})}const za=Wa({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5});Wa({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wa({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wa({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wa({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wa({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wa({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wa({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wa({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});const Ja=Qa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"});Qa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ka=function e(t,n,r){n=n||[];var a=r=r||0;for(;t>=$a;)n[r++]=255&t|Ya,t/=128;for(;t&Ha;)n[r++]=255&t|Ya,t>>>=7;return n[r]=0|t,e.bytes=r-a+1,n},Ya=128,Ha=-128,$a=Math.pow(2,31);var Za=function e(t,n){var r,a=0,s=0,o=n=n||0,i=t.length;do{if(o>=i)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],a+=s<28?(r&ts)<=es);return e.bytes=o-n,a},es=128,ts=127;var ns=Math.pow(2,7),rs=Math.pow(2,14),as=Math.pow(2,21),ss=Math.pow(2,28),os=Math.pow(2,35),is=Math.pow(2,42),us=Math.pow(2,49),cs=Math.pow(2,56),ps=Math.pow(2,63),ls={encode:Ka,decode:Za,encodingLength:function(e){return e{const[n,r]=ds(e.subarray(t));return t+=r,n};let r=n(),a=ws;if(18===r?(r=0,t=0):a=n(),0!==r&&1!==r)throw new RangeError(`Invalid CID version ${r}`);const s=t,o=n(),i=n(),u=t+i;return{version:r,codec:a,multihashCode:o,digestSize:i,multihashSize:u-s,size:u}}static parse(e,t){const[n,r]=function(e,t){switch(e[0]){case"Q":{const n=t??Ja;return[Ja.prefix,n.decode(`${Ja.prefix}${e}`)]}case Ja.prefix:{const n=t??Ja;return[Ja.prefix,n.decode(e)]}case za.prefix:{const n=t??za;return[za.prefix,n.decode(e)]}default:if(null==t)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}(e,t),a=vs.decode(r);if(0===a.version&&"Q"!==e[0])throw Error("Version 0 CID string must not include multibase prefix");return Is(a).set(n,e),a}}const ws=112,ys=18;function bs(e,t,n){const r=ms(e),a=r+ms(t),s=new Uint8Array(a+n.byteLength);return fs(e,s,0),fs(t,s,r),s.set(n,a),s}const Ts=Symbol.for("@ipld/js-cid/CID");class ks{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){const t=this.encode(e);return t instanceof Uint8Array?hs(this.code,t):t.then((e=>hs(this.code,e)))}throw Error("Unknown type, must be binary type")}}const _s=85,Es=function({name:e,code:t,encode:n}){return new ks(e,t,n)}({name:"sha2-256",code:18,encode:e=>La(n.createHash("sha256").update(e).digest())});var Ps=126144e3,Ss=1e7,Ds=Math.pow(2,64),Os=48,Ns=21,Bs=48,Cs=Te("tp"),Fs=Te("sc"),Ls=28100,Rs=12900,Ms=421700,Us=409700;function js(e){var t=e/Ta;return(arguments.length>1&&void 0!==arguments[1]&&arguments[1]?Math.floor(t):Math.ceil(t))*Ta}function Vs(e,t){if(e>t)throw new Error("Old timestamp must be less than or equal to new timestamp");for(var n=[],r=js(e)+Ta;re?r=t?e*e*Ds/(2*t):0:r=(e+(e-r))*n/2;return r}function Js(e,t){return Ks.apply(this,arguments)}function Ks(){return(Ks=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,e.abrupt("return",Ys(r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ys(e){var t,n={},r=T(e.params["global-state"]);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=Buffer.from(a.key,"base64").toString(),o=void 0;o=1===a.value.type?Buffer.from(a.value.bytes||"","base64"):a.value.uint||0,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function Hs(){for(var e=arguments.length,t=new Array(e),n=0;n0?Ns-e:0}},{key:"lastAccountPowerBoxIndex",get:function(){return xo(this.powerCount)[0]}},{key:"lastAccountPowerArrayIndex",get:function(){return xo(this.powerCount)[1]}}]),e}(),uo=function(){function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a}return p(e,[{key:"lockEndTimestamp",get:function(){var e=this.bias*Math.pow(2,64)/this.slope;return this.timestamp+e}},{key:"cumulativePowerAt",value:function(e){var t=e-this.timestamp;if(t<0)throw new Error("Time delta must be greater than or equal to 0");return this.cumulativePower+zs(this.bias,this.slope,t)}}]),e}(),co=p((function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a})),po=p((function e(t){u(this,e),this.slopeDelta=t})),lo=function(){function e(t,n,r,a){u(this,e),this.tinyAssetId=t,this.totalLockedAmount=n,this.totalPowerCount=r,this.lastTotalPowerTimestamp=a}return p(e,[{key:"freeTotalPowerSpaceCount",get:function(){var e=this.totalPowerCount%Ns;return e>0?Ns-e:0}},{key:"lastTotalPowerBoxIndex",get:function(){return xo(this.totalPowerCount)[0]}},{key:"lastTotalPowerArrayIndex",get:function(){return xo(this.totalPowerCount)[1]}}]),e}();function fo(){return(fo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ho(r),e.prev=1,e.next=4,Gs(t,n,a);case 4:if(!(o=e.sent)){e.next=7;break}return e.abrupt("return",mo(o));case 7:return e.abrupt("return",null);case 10:return e.prev=10,e.t0=e.catch(1),console.log(e.t0),e.abrupt("return",null);case 14:case"end":return e.stop()}}),e,null,[[1,10]])})))).apply(this,arguments)}function mo(e){var t=Buffer.from(e);return new io(t.readUIntBE(0,8),t.readUIntBE(8,8),t.readUIntBE(16,8),t.readUIntBE(24,8))}function ho(t){return e.decodeAddress(t).publicKey}function go(e){var t=Ba(e),n=new Uint8Array(Cs.length+t.length);return n.set(Cs,0),n.set(t,Cs.length),n}function xo(e){var t=e-1;return[Math.floor(t/Ns),t%Ns]}function Ao(t,n){var r=e.decodeAddress(t).publicKey,a=Ba(n),s=new Uint8Array(r.length+a.length);return s.set(r,0),s.set(a,r.length),s}function Io(e,t,n){return vo.apply(this,arguments)}function vo(){return(vo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=yo(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",wo(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function wo(t){return new po(Number(e.bytesToBigInt(t.slice(t.length-16,t.length))))}function yo(e){return Hs(Fs,Ba(e))}function bo(e,t,n){return To.apply(this,arguments)}function To(){return(To=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=0,r&&(a=Math.ceil(r/Ns)),o=[],i=0;case 4:if(!(i=e[r].timestamp))break;n=r}return n}function So(e){for(var t,n=Os,r=[],a=0;a=11)throw new Error("Boxes' length cannot be larger than 10");var y=d.slice(0,6),b=[e.makeApplicationNoOpTxnFromObject({from:s,suggestedParams:c,appIndex:n,appArgs:[Te("claim_rewards"),Ba(o),Ba(i),Hs.apply(void 0,w(u.map((function(e){return Ba(e)}))))],foreignApps:[r],foreignAssets:[a],boxes:y,note:l?Te(l):void 0})];b[0].fee=b[0].fee*(i+2);var k=0,_=92+865*i,E=700+700*i;if(_>E&&(k=Math.floor((_-E)/666)+1),k||d.length>6){var P=d.slice(6),S=Ko({sender:s,suggestedParams:c,extraAppArgs:[Ba(Math.max(k-1,0))],index:n,foreignApps:[r],boxes:P});S.fee*=Math.max(k,1),b.unshift(S)}if(p){var D=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,to:e.getApplicationAddress(n),amount:Lo,suggestedParams:c});b.unshift(D)}return e.assignGroupID(b)}var Ho=8,$o=Te("p"),Zo=Te("a"),ei=Te("v"),ti=28500,ni=12500,ri=p((function e(t,n,r,a,s,o,i){u(this,e),this.index=t,this.creationTimestamp=n,this.votingStartTimestamp=r,this.votingEndTimestamp=a,this.votingPower=s,this.voteCount=o,this.isCancelled=i}));function ai(t,n){return Hs(Zo,e.decodeAddress(t).publicKey,Ba(n))}function si(e){return new ri(Fa(e.slice(0,8)),Fa(e.slice(8,16)),Fa(e.slice(16,24)),Fa(e.slice(24,32)),Fa(e.slice(32,40)),Fa(e.slice(40,48)),Boolean(Fa(e.slice(48,49))))}function oi(){return(oi=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ao(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",si(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ii(t){var n=t.stakingVotingAppId,r=t.vaultAppId,a=t.sender,s=t.proposalId,o=t.proposal,i=t.votes,u=t.assetIds,c=t.accountPowerIndex,p=t.appBoxNames,l=t.suggestedParams,d=t.appCallNote,f=void 0===d?null:d;if(i.length!==u.length)throw new Error("The number of votes must be equal to the number of asset ids");if(u.length>Ho)throw new Error("You cannot cast vote for more than ".concat(Ho," different pools"));if(100!==i.reduce((function(e,t){return e+t}),0))throw new Error("The sum of the votes must equal 100%");var m,h=Hs.apply(void 0,w(i.map((function(e){return Ba(e)})))),g=Hs.apply(void 0,w(u.map((function(e){return Ba(e)})))),x=function(e){return Hs($o,Te(e))}(s),A=ai(a,Math.floor(o.index/8192)),I=!p.some((function(e){return Ca(e,A)})),v=ho(a),y=Math.floor(c/Ns),b=Ao(a,y),k=Ao(a,y+1),_=0,E=[],P=T(u);try{var S=function(){var e=m.value,t=function(e,t){return Hs(ei,Ba(e),Ba(t))}(o.index,e);E.push({appIndex:n,name:t}),p.some((function(e){return Ca(e,t)}))||(_+=1)};for(P.s();!(m=P.n()).done;)S()}catch(e){P.e(e)}finally{P.f()}var D=[{appIndex:n,name:x},{appIndex:n,name:A}].concat(E,[{appIndex:r,name:v},{appIndex:r,name:b},{appIndex:r,name:k}]),O=[e.makeApplicationNoOpTxnFromObject({from:a,suggestedParams:l,appIndex:n,appArgs:[Te("cast_vote"),Te(s),h,g,Ba(c)],foreignApps:[r],boxes:D.slice(0,7),note:f?Te(f):void 0})];O[0].fee*=2,D.length>=7&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(7,14)})),D.length>=14&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(14)}));var N=Number(I)*ti+_*ni;return N&&(O=[e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:l,to:e.getApplicationAddress(n),amount:N})].concat(w(O))),e.assignGroupID(O)}function ui(t){var n=t.accountState,r=t.lockEndTime,a=t.lockedAmount,s=t.network,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.slopeChangeAtLockEndTime,p=t.appCallNote;if(ai.freeTotalPowerSpaceCount&&(b+=Us),c||(b+=Rs);var k=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({amount:a,assetIndex:X[s],from:o,suggestedParams:u,to:e.getApplicationAddress(l)}),e.makeApplicationNoOpTxnFromObject({appIndex:l,from:o,suggestedParams:u,appArgs:[Te("create_lock"),Ba(r)],boxes:d.slice(0,8),note:p}),Ko({sender:o,suggestedParams:u,index:l,boxes:d.slice(8)})];if(b){var _=e.makePaymentTxnWithSuggestedParamsFromObject({amount:b,from:o,suggestedParams:u,to:e.getApplicationAddress(l)});k.unshift(_)}return e.assignGroupID(k)}function ci(t){var n=t.accountState,r=t.lockedAmount,a=t.network,s=t.sender,o=t.vaultAppGlobalState,i=t.suggestedParams,u=t.appCallNote;if(ro.freeTotalPowerSpaceCount&&(v+=Us),!n.freeAccountPowerSpaceCount){var w=Ao(s,n.lastAccountPowerBoxIndex+1);h.push({appIndex:Aa[a],name:w}),v+=Ms}var y=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:X[a],from:s,to:e.getApplicationAddress(Aa[a]),amount:r,suggestedParams:i}),e.makeApplicationNoOpTxnFromObject({appIndex:Aa[a],from:s,suggestedParams:i,appArgs:[Te("increase_lock_amount")],boxes:h,note:u}),Ko({sender:s,suggestedParams:i,index:Aa[a]})];if(v){var b=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,suggestedParams:i,to:e.getApplicationAddress(Aa[a]),amount:v});y.unshift(b)}return e.assignGroupID(y)}function pi(t){var n=t.accountState,r=t.network,a=t.newLockEndTime,s=t.slopeChangeAtNewLockEndTime,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.appCallNote;if(a%Ta)throw new Error("Invalid lock end time");if(a<=n.lockEndTime)throw new Error("New lock end time must be greater than current lock end time");var p=ho(o),l=Ao(o,n.lastAccountPowerBoxIndex),d=go(i.lastTotalPowerBoxIndex),f=go(i.lastTotalPowerBoxIndex+1),m=yo(n.lockEndTime),h=yo(a),g=[{appIndex:Aa[r],name:p},{appIndex:Aa[r],name:l},{appIndex:Aa[r],name:d},{appIndex:Aa[r],name:f},{appIndex:Aa[r],name:m},{appIndex:Aa[r],name:h}];if(!n.freeAccountPowerSpaceCount){var x=Ao(o,n.lastAccountPowerBoxIndex+1);g.push({appIndex:Aa[r],name:x})}var A,I=Vs(i.lastTotalPowerTimestamp,Math.floor(Date.now()/1e3)),v=I.length,w=T(I);try{for(w.s();!(A=w.n()).done;){var y=A.value;if(y%Ta==0){var b=yo(y);g.push({appIndex:Aa[r],name:b})}}}catch(e){w.e(e)}finally{w.f()}var k=0;s||(k+=Rs),n.freeAccountPowerSpaceCount||(k+=Ms),v>i.freeTotalPowerSpaceCount&&(k+=Us);var _=[e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:o,suggestedParams:u,appArgs:[Te("extend_lock_end_time"),Ba(a)],boxes:g.slice(0,8),note:c}),Ko({sender:o,suggestedParams:u,index:Aa[r],boxes:g.slice(8)})];if(k){var E=e.makePaymentTxnWithSuggestedParamsFromObject({from:o,suggestedParams:u,to:e.getApplicationAddress(Aa[r]),amount:k});_.unshift(E)}return e.assignGroupID(_)}function li(t){var n=t.accountState,r=t.network,a=t.sender,s=t.suggestedParams,o=t.appCallNote,i=ho(a),u=Ao(a,n.lastAccountPowerBoxIndex),c=Ao(a,n.lastAccountPowerBoxIndex+1),p=[{appIndex:Aa[r],name:i},{appIndex:Aa[r],name:u},{appIndex:Aa[r],name:c}],l=e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:a,suggestedParams:s,appArgs:[Te("withdraw")],foreignAssets:[X[r]],boxes:p,note:o});l.fee*=2;var d=[l];if(!n.freeAccountPowerSpaceCount){var f=e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:s,to:e.getApplicationAddress(Aa[r]),amount:Ms});d.unshift(f)}return e.assignGroupID(d)}var di=function(){function t(e,n,r){u(this,t),this.algodClient=e,this.userAddress=n,this.network=r}var n,r,a,o,c,l,d,f,m,h,g,x,A,I,v,y;return p(t,[{key:"getTinyPower",value:(y=i(s().mark((function e(){var t,n,r,a,o,i,u,c=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=c.length>0&&void 0!==c[0]?c[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=Math.max(o.bias-Ws(o.slope,i),0),e.abrupt("return",u);case 16:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getTotalTinyPower",value:(v=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=v.length>0&&void 0!==v[0]?v[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchVaultAppGlobalState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,bo(this.algodClient,Aa[this.network],n.totalPowerCount);case 8:if(r=e.sent,a=Po(r,t)){e.next=12;break}return e.abrupt("return",0);case 12:o=r[a],i=Math.floor(o.timestamp/Ta),u=Math.floor(t/Ta)-i,c=Array.from({length:u},(function(e,t){return(i+t)*Ta})),p=c.map((function(e,t){return[0===t?o.timestamp:c[t-1],e]})),l=o.slope,d=o.bias,f=T(p),e.prev=19,f.s();case 21:if((m=f.n()).done){e.next=34;break}return h=m.value,g=h[1]-h[0],x=Ws(l,g),d=Math.max(d-x,0),e.next=28,Io(this.algodClient,Aa[this.network],h[1]);case 28:A=e.sent,I=(null==A?void 0:A.slopeDelta)||0,l=Math.max(l-I,0),0!==d&&0!==l||(d=0,l=0);case 32:e.next=21;break;case 34:e.next=39;break;case 36:e.prev=36,e.t0=e.catch(19),f.e(e.t0);case 39:return e.prev=39,f.f(),e.finish(39);case 42:return e.abrupt("return",d);case 43:case"end":return e.stop()}}),e,this,[[19,36,39,42]])}))),function(){return v.apply(this,arguments)})},{key:"getCumulativeTinyPower",value:(I=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=p.length>0&&void 0!==p[0]?p[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=zs(o.bias,o.slope,i),c=o.cumulativePower-u,e.abrupt("return",c);case 17:case"end":return e.stop()}}),e,this)}))),function(){return I.apply(this,arguments)})},{key:"fetchVaultAppGlobalState",value:(A=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,Js(this.algodClient,Aa[this.network]);case 3:return t=e.sent,e.abrupt("return",new lo(t.tiny_asset_id,t.total_locked_amount,t.total_power_count,t.last_total_power_timestamp));case 7:return e.prev=7,e.t0=e.catch(0),console.error(e.t0),e.abrupt("return",null);case 11:case"end":return e.stop()}}),e,this,[[0,7]])}))),function(){return A.apply(this,arguments)})},{key:"generateCreateLockTransactions",value:(x=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=o,c){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(p){e.next=15;break}return e.next=14,this.algodClient.getTransactionParams().do();case 14:p=e.sent;case 15:return e.next=17,Io(this.algodClient,Aa[this.network],r);case 17:return l=e.sent,e.abrupt("return",ui({lockedAmount:n,lockEndTime:r,vaultAppGlobalState:c,slopeChangeAtLockEndTime:l,sender:i,network:this.network,accountState:u,suggestedParams:p}));case 19:case"end":return e.stop()}}),e,this)}))),function(e){return x.apply(this,arguments)})},{key:"generateIncreaseLockAmountTransactions",value:(g=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.abrupt("return",ci({accountState:i,lockedAmount:n,network:this.network,sender:o,vaultAppGlobalState:u,suggestedParams:c}));case 18:case"end":return e.stop()}}),e,this)}))),function(e){return g.apply(this,arguments)})},{key:"generateExtendLockTimeTransactions",value:(h=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.newLockEndTime,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.next=19,Io(this.algodClient,Aa[this.network],n);case 19:return p=e.sent,e.abrupt("return",pi({accountState:i,network:this.network,newLockEndTime:n,sender:o,vaultAppGlobalState:u,suggestedParams:c,slopeChangeAtNewLockEndTime:null==p?void 0:p.slopeDelta}));case 21:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"generateIncreaseLockAmountAndExtendLockEndTimeTransactions",value:(m=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=[],l=[],d=o,c){e.next=13;break}throw new Error("There was an error while fetching vault app global state");case 13:if(u){e.next=15;break}throw new Error("There was an error while fetcing the account state");case 15:if(d){e.next=19;break}return e.next=18,this.algodClient.getTransactionParams().do();case 18:d=e.sent;case 19:return p=ci({accountState:u,lockedAmount:n,network:this.network,sender:i,vaultAppGlobalState:c,suggestedParams:d}),u.powerCount+=1,c.totalPowerCount+=1,e.next=24,Io(this.algodClient,Aa[this.network],r);case 24:return f=e.sent,l=pi({accountState:u,network:this.network,newLockEndTime:r,sender:i,vaultAppGlobalState:c,suggestedParams:d,slopeChangeAtNewLockEndTime:null==f?void 0:f.slopeDelta}),m=[].concat(w(p),w(l)),e.abrupt("return",Boolean(p.length)&&Boolean(l.length)?Zs(p,l):m);case 28:case"end":return e.stop()}}),e,this)}))),function(e){return m.apply(this,arguments)})},{key:"generateWithdrawTransactions",value:(f=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t||this.userAddress,e.next=3,this.fetchAccountState();case 3:if(o=e.sent,i=r,o){e.next=7;break}throw new Error("There was an error while fetcing the account state");case 7:if(i){e.next=11;break}return e.next=10,this.algodClient.getTransactionParams().do();case 10:i=e.sent;case 11:if(u=li({accountState:o,network:this.network,sender:a,suggestedParams:i,client:this.algodClient}),!n){e.next=17;break}return e.next=15,H({client:this.algodClient,initiatorAddr:a,assetID:X[this.network]});case 15:c=e.sent,u=Zs([c[0].txn],u);case 17:return e.abrupt("return",u);case 18:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"fetchAccountState",value:function(){return function(e,t,n){return fo.apply(this,arguments)}(this.algodClient,Aa[this.network],this.userAddress)}},{key:"fetchStakingDistributionProposal",value:function(e){return function(e,t,n){return oi.apply(this,arguments)}(this.algodClient,Ia[this.network],e)}},{key:"generateCastVoteForStakingDistributionProposalTransactions",value:(d=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.proposalId,a=t.votes,o=t.assetIds,i=t.userAddress,u=t.suggestedParams,c=null!=i?i:this.userAddress,p=u,e.next=5,this.fetchStakingDistributionProposal(r);case 5:if(l=e.sent){e.next=8;break}throw new Error("There was an error while fetching staking distribution proposal");case 8:if(p){e.next=12;break}return e.next=11,this.algodClient.getTransactionParams().do();case 11:p=e.sent;case 12:return e.next=14,this.fetchAccountState();case 14:return d=e.sent,e.next=17,eo(this.algodClient,Ia[this.network]);case 17:return f=e.sent,e.next=20,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==d?void 0:d.powerCount)&&void 0!==n?n:null});case 20:if(m=e.sent,null!==(h=Po(m,l.creationTimestamp))){e.next=24;break}throw new Error("It is required to have an account power at the staking distribution proposal creation timestamp");case 24:return e.abrupt("return",ii({stakingVotingAppId:Ia[this.network],vaultAppId:Aa[this.network],sender:c,proposalId:r,proposal:l,votes:a,assetIds:o,accountPowerIndex:h,appBoxNames:f,suggestedParams:p,appCallNote:null}));case 25:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"fetchRewardsAppGlobalState",value:(l=i(s().mark((function t(){var n;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,Js(this.algodClient,va[this.network]);case 3:return n=t.sent,t.abrupt("return",new Ro(n.tiny_asset_id,n.vault_app_id,n.reward_history_count,n.first_period_timestamp,n.reward_period_count,e.encodeAddress(n.manager),e.encodeAddress(n.rewards_manager)));case 7:return t.prev=7,t.t0=t.catch(0),console.error(t.t0),t.abrupt("return",null);case 11:case"end":return t.stop()}}),t,this,[[0,7]])}))),function(){return l.apply(this,arguments)})},{key:"generateClaimRewardTransactions",value:(c=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.periodIndexStart,a=t.periodCount,o=t.userAddress,i=t.suggestedParams,u=t.shouldOptIntoTINY,c=null!=o?o:this.userAddress,p=i){e.next=7;break}return e.next=6,this.algodClient.getTransactionParams().do();case 6:p=e.sent;case 7:return e.next=9,this.fetchAccountState();case 9:return l=e.sent,e.next=12,this.fetchRewardsAppGlobalState();case 12:if(d=e.sent){e.next=15;break}throw new Error("There was an error while fetching rewards app global state");case 15:if(!(r+a>d.rewardPeriodCount)){e.next=17;break}throw new Error("The reward period index to be claimed cannot be larger than the latest reward period index");case 17:return e.next=19,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==l?void 0:l.powerCount)&&void 0!==n?n:null});case 19:for(f=e.sent,m=d.firstPeriodTimestamp+r*ga,h=d.firstPeriodTimestamp+(r+a)*ga,g=[],x=m;x=Math.floor(Date.now()/xa)||c.votingEndTimestamp<=Math.floor(Date.now()/xa))){e.next=23;break}throw new Error("Voting period is not active");case 23:return e.next=25,_o({algodClient:this.algodClient,address:i,appId:Aa[this.network],powerCount:p.powerCount});case 25:if(l=e.sent,null!==(d=Po(l,c.creationTimestamp))){e.next=29;break}throw new Error("Account power index not found");case 29:return f=Math.floor(c.index/(8*Ea)),m=ai(i,f),e.next=33,qs(this.algodClient,wa[this.network],m);case 33:return h=!e.sent,e.abrupt("return",Oo({proposalVotingAppId:wa[this.network],vaultAppId:Aa[this.network],sender:i,proposalId:n,proposal:c,vote:a,accountPowerIndex:d,createAttendanceSheetBox:h,suggestedParams:u}));case 35:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"fetchProposalVotingAppGlobalState",value:(r=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Js(this.algodClient,wa[this.network]);case 2:return t=e.sent,e.abrupt("return",new ro(t.vault_app_id,t.proposal_index_counter,t.voting_delay,t.voting_duration,t.proposal_threshold,t.proposal_threshold_numerator,t.quorum_threshold,t.approval_requirement,t.manager,t.proposal_manager));case 4:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getRequiredTinyPowerToCreateProposal",value:(n=i(s().mark((function e(t){var n,r,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==t){e.next=4;break}e.t0=t,e.next=7;break;case 4:return e.next=6,this.getTotalTinyPower();case 6:e.t0=e.sent;case 7:return n=e.t0,e.next=10,this.fetchProposalVotingAppGlobalState();case 10:return r=e.sent,a=r.proposalThreshold,r.proposalThresholdNumerator&&(a=Math.max(a,Math.floor(n*r.proposalThresholdNumerator/100)+1)),e.abrupt("return",a);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})}]),t}(),fi=2500,mi=400,hi=function(){function e(t,n){u(this,e),l(this,"data",null),this.name=t,this.structReference=n,this.size=n[t].size,this.fields=n[t].fields}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.size)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t;if(!this.data)throw new Error("Data is not initialized");var n=this.fields[e];if(!n)throw new Error("Field ".concat(e," does not exist in struct ").concat(this.name));var r=n.offset,a=n.offset+n.size,s=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(r,a);return Ii(n.type,this.structReference).apply(Buffer.from(s))}}]),e}(),gi=function(){function e(t,n){u(this,e),l(this,"data",null),this.struct=t,this.length=n}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.struct.size*this.length)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t,n=this.struct.size*e,r=n+this.struct.size,a=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(n,r);return this.struct.apply(a?Buffer.from(a):void 0)}}]),e}(),xi=function(){function e(){u(this,e)}return p(e,[{key:"apply",value:function(e){for(var t=BigInt(0),n=0;n2&&void 0!==arguments[2]?arguments[2]:Math.floor(Date.now()/1e3),a=(n=e,Math.floor(n*Ds/Ps)),s=t-r;return s<0?0:Ws(a,s)},exports.combineAndRegroupSignerTxns=function(){for(var t=arguments.length,n=new Array(t),r=0;r=e.minimum_required_balance},exports.intToBytes=Ba,exports.isAccountOptedIntoApp=function(e){var t=e.appID;return e.accountAppsLocalState.some((function(e){return e.id===t}))},exports.isSwapAssetInAmountLow=it,exports.isSwapQuoteErrorCausedByAmount=gt,exports.poolUtils=$t,exports.prepareCommitTransactions=function(e){return ha.apply(this,arguments)},exports.redeemAllExcessAsset=function(e){return $r.apply(this,arguments)},exports.redeemExcessAsset=function(e){return Kr.apply(this,arguments)},exports.sendAndWaitRawTransaction=Ie,exports.sumUpTxnFees=we,exports.tinymanContract_v1_1=wt,exports.tinymanContract_v2=Tt,exports.tinymanJSSDKConfig=_e; diff --git a/src/folks-lending-pools/constants.ts b/src/folks-lending-pools/constants.ts index c8ced171..988a8a4d 100644 --- a/src/folks-lending-pools/constants.ts +++ b/src/folks-lending-pools/constants.ts @@ -1,6 +1,5 @@ import {SupportedNetwork} from "../util/commonTypes"; -// eslint-disable-next-line no-magic-numbers const SECONDS_IN_YEAR = BigInt(365 * 24 * 60 * 60); const ONE_14_DP = BigInt(1e14); const ONE_16_DP = BigInt(1e16); diff --git a/src/liquid-stake/stAlgoClient.ts b/src/liquid-stake/stAlgoClient.ts index 55c7f91c..9c912df1 100644 --- a/src/liquid-stake/stAlgoClient.ts +++ b/src/liquid-stake/stAlgoClient.ts @@ -133,7 +133,7 @@ class TinymanSTAlgoClient extends TinymanBaseClient { const doesUserBoxExist = await this.boxExists( this.getUserStateBoxName(accountAddress) ); - const initialTxnCount = 3; + const initialTxnCount = 4; const totalTxnCount = initialTxnCount + Number(shouldApplyRateChange) + diff --git a/src/util/client/base/baseClient.ts b/src/util/client/base/baseClient.ts index 2acaf7d0..9fd02ff6 100644 --- a/src/util/client/base/baseClient.ts +++ b/src/util/client/base/baseClient.ts @@ -63,7 +63,6 @@ abstract class TinymanBaseClient { )?.value; if (searchValue) { - // eslint-disable-next-line no-magic-numbers if (searchValue.type === 2) { return searchValue.uint; } diff --git a/src/util/util.ts b/src/util/util.ts index f726171e..26fccbae 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -178,7 +178,6 @@ export function convertFromBaseUnits( return roundNumber( {decimalPlaces: decimals}, - // eslint-disable-next-line no-magic-numbers Math.pow(10, -decimals) * Number(quantity) ); } @@ -190,7 +189,6 @@ export function convertToBaseUnits( assetDecimals: number | bigint, quantity: number | bigint ) { - // eslint-disable-next-line no-magic-numbers const baseAmount = Math.pow(10, Number(assetDecimals)) * Number(quantity); // make sure the final value is an integer. This prevents this kind of computation errors: 0.0012 * 100000 = 119.99999999999999 and rounds this result into 120 From 5b0d11cb9c97c7933fb1dde7a8f52deb07577176 Mon Sep 17 00:00:00 2001 From: gulcinuras Date: Fri, 29 Nov 2024 12:36:16 +0100 Subject: [PATCH 2/4] refactor(st-algo-client): Improve increase stake method --- dist/index.js | 2 +- dist/liquid-stake/stAlgoClient.d.ts | 1 + src/liquid-stake/stAlgoClient.ts | 50 +++++++++++++++++++---------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/dist/index.js b/dist/index.js index 4b713c34..03db43ba 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -"use strict";var e=require("algosdk"),t=require("base64-js"),n=require("crypto");function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0;--a){var s=this.tryEntries[a],o=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var i=n.call(s,"catchLoc"),u=n.call(s,"finallyLoc");if(i&&u){if(this.prev=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),k(n),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var a=r.arg;k(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:E(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function o(e,t,n,r,a,s,o){try{var i=e[s](o),u=i.value}catch(e){return void n(e)}i.done?t(u):Promise.resolve(u).then(r,a)}function i(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var s=e.apply(t,n);function i(e){o(s,r,a,i,u,"next",e)}function u(e){o(s,r,a,i,u,"throw",e)}i(void 0)}))}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f: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,o=!0,i=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){i=!0,s=e},f:function(){try{o||null==n.return||n.return()}finally{if(i)throw s}}}}function k(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var _=function(e){return e.SwapRouterStaleDataError="SwapRouterStaleDataError",e.SwapRouterNoRouteError="SwapRouterNoRouteError",e.SwapRouterLowSwapAmountError="SwapRouterLowSwapAmountError",e.SwapRouterInsufficientReservesError="SwapRouterInsufficientReservesError",e.SwapRouterPoolHasNoLiquidityError="SwapRouterPoolHasNoLiquidityError",e.NoAvailablePoolError="NoAvailablePoolError",e.OutputAmountExceedsAvailableLiquidityError="OutputAmountExceedsAvailableLiquidityError",e.UnknownError="UnknownError",e.LowSwapAmountError="LowSwapAmountError",e.AssetDoesNotBelongToPoolError="AssetDoesNotBelongToPoolError",e.InvalidSwapTypeError="InvalidSwapTypeError",e}({}),E=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;return u(this,n),(a=t.call(this,r)).type=e,a.message=r,Error.captureStackTrace&&Error.captureStackTrace(A(a),n),a}return p(n)}(),P=Uint8Array.from([1]),S=1e5,D=1e5,O=1e5,N=1e5,B=1e5,C=5e4,F=28500,L=1e3,R=1e3,M={mainnet:{base:"https://mainnet.analytics.tinyman.org/api",v1:"https://mainnet.analytics.tinyman.org/api/v1"},testnet:{base:"https://testnet.analytics.tinyman.org/api",v1:"https://testnet.analytics.tinyman.org/api/v1"}},U={V1_1:"v1_1",V2:"v2"},j=0,V={id:"".concat(j),name:"Algorand",unit_name:"ALGO",decimals:6,url:"https://algorand.org",is_liquidity_token:!1,total_amount:"6615503326932151",clawback_address:""},G={V1:"TM1POOL",V1_1:"TMPOOL11",V2:"TMPOOL2"},X={testnet:258703304,mainnet:22e8},q={testnet:724519992,mainnet:2537013734},Q={testnet:724676936,mainnet:2537023208},W="- would result negative",z="logic eval error:",J="exceeds schema integer count",K=/transaction \w+:/,Y=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;u(this,n);for(var s=arguments.length,o=new Array(s>2?s-2:0),i=2;ir?[a(a({},e),{},{id:n}),a(a({},t),{},{id:r})]:[a(a({},t),{},{id:r}),a(a({},e),{},{id:n})]}function ee(e,t){var n=[e,t];return[Math.max.apply(Math,n),Math.min.apply(Math,n)]}function te(e){return Number(e)===j}function ne(e){return Number(e.id)}function re(e){var t,n=e.stateArray,r=void 0===n?[]:n,a=e.shouldDecodeKeys,s=void 0!==a&&a,o={},i=T(r);try{for(i.s();!(t=i.n()).done;){var u=t.value,c=u.key,p=void 0;if(1==u.value.type)p=u.value.bytes;else{if(2!=u.value.type)throw new Error("Unexpected state type: ".concat(u.value.type));p=u.value.uint}o[s?atob(c):c]=p}}catch(e){i.e(e)}finally{i.f()}return o}function ae(e){var t,n=e.reduce((function(e,t){return e+t.length}),0),r=new Uint8Array(n),a=0,s=T(e);try{for(s.s();!(t=s.n()).done;){var o=t.value;r.set(o,a),a+=o.length}}catch(e){s.e(e)}finally{s.f()}return r}var se=100000n,oe=100000n,ie=100000n,ue=25000n+25000n,ce=25000n+3500n;function pe(e){var t=e["apps-total-schema"],n=0n,r=0n;t&&(t["num-byte-slice"]&&(n=t["num-byte-slice"]),t["num-uint"]&&(r=t["num-uint"]));var a=e["apps-local-state"]||[],s=e["created-apps"]||[],o=e.assets||[];return se+oe*BigInt(o.length)+ie*BigInt(s.length+a.length)+ce*r+ue*n}function le(e){return new Promise((function(t){setTimeout((function(){t(null)}),e)}))}function de(e,t){return fe.apply(this,arguments)}function fe(){return(fe=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=3,le(1e3);case 3:return r=null,e.prev=4,e.next=7,t.pendingTransactionInformation(n).do();case 7:r=e.sent,e.next=12;break;case 10:e.prev=10,e.t0=e.catch(4);case 12:if(!r){e.next=17;break}if(!r["confirmed-round"]){e.next=15;break}return e.abrupt("return",r);case 15:if(!r["pool-error"]){e.next=17;break}throw new Error("Transaction Rejected: ".concat(r["pool-error"]));case 17:e.next=0;break;case 19:case"end":return e.stop()}}),e,null,[[4,10]])})))).apply(this,arguments)}function me(e,t,n){if(t>1||t<0)throw new Error("Invalid slippage value. Must be between 0 and 1, got ".concat(t));var r;try{var a="negative"===e?1-t:1+t;r=BigInt(Math.floor(Number(n)*a))}catch(e){throw new Error(e.message)}return r}function he(e,t){var n=Number(e);return ge({decimalPlaces:n},Math.pow(10,-n)*Number(t))}function ge(e,t){var n=e.decimalPlaces,r=void 0===n?0:n;if(r>0){var a=v(Ae(t),2),s=a[0],o=a[1],i=v(Ae(Math.round(Number(xe(s,o+r)))),2),u=i[0],c=i[1];return Number(xe(u,c-r))}return Math.round(t)}function xe(e,t){return e+(t<0?"e".concat(t):"e+".concat(t))}function Ae(e){if(e.toString().includes("e")){var t=e.toString().split("e");return[parseFloat(t[0]),parseFloat(t[1])]}return[e,0]}function Ie(e,t){return ve.apply(this,arguments)}function ve(){return(ve=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,r=[],a=T(n),e.prev=3,a.s();case 5:if((o=a.n()).done){e.next=18;break}return i=o.value,e.next=9,t.sendRawTransaction(i).do();case 9:return u=e.sent,c=u.txId,e.next=13,de(t,c);case 13:p=e.sent,l=p["confirmed-round"],r.push({confirmedRound:l,txnID:c});case 16:e.next=5;break;case 18:e.next=23;break;case 20:e.prev=20,e.t0=e.catch(3),a.e(e.t0);case 23:return e.prev=23,a.f(),e.finish(23);case 26:return e.abrupt("return",r);case 29:throw e.prev=29,e.t1=e.catch(0),new Y(e.t1,"We encountered an error while processing this transaction. Try again later.");case 32:case"end":return e.stop()}}),e,null,[[0,29],[3,20,23,26]])})))).apply(this,arguments)}function we(e){return e.reduce((function(e,t){return e+t.txn.fee}),0)}function ye(e){return(t=e[0].txn.group)?Buffer.from(t).toString("base64"):"";var t}function be(e){for(var t=[];;){var n=Number(e&BigInt(127));if(!(e>>=BigInt(7))){t.push(n);break}t.push(128|n)}return t}function Te(e){return(new TextEncoder).encode(e)}var ke,_e=new(function(){function e(){u(this,e),this.clientName="tinyman-js-sdk"}return p(e,[{key:"getClientName",value:function(){return this.clientName}},{key:"setClientName",value:function(e){this.clientName=e}},{key:"getAppCallTxnNoteWithClientName",value:function(e,t){var n=e===U.V1_1?"v1":e,r=JSON.stringify(a({origin:this.clientName},t));return Te("tinyman/".concat(n,":j").concat(r))}}]),e}()),Ee=(l(ke={},U.V1_1,{testnet:62368684,mainnet:552635992}),l(ke,U.V2,{testnet:148607e3,mainnet:1002541853}),ke);function Pe(e,t){var n=Ee[t][e];if(!n)throw new Error("No Validator App exists for ".concat(e," network with ").concat(t," contract version"));return n}function Se(){return(Se=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationOptInTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function De(){return(De=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationClearStateTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var Oe,Ne,Be,Ce=function(e){return e.FixedInput="fixed-input",e.FixedOutput="fixed-output",e}({}),Fe=.003,Le=function(e){return e[e.INPUT_TXN=0]="INPUT_TXN",e[e.APP_CALL_TXN=1]="APP_CALL_TXN",e}({}),Re=(l(Oe={},Ce.FixedInput,1),l(Oe,Ce.FixedOutput,2),Oe),Me=2,Ue=Te("swap"),je=(l(Ne={},Ce.FixedInput,Te("fixed-input")),l(Ne,Ce.FixedOutput,Te("fixed-output")),Ne),Ve={ASSET_OPT_IN:Te("asset_opt_in")},Ge={testnet:184778019,mainnet:1083651166},Xe=(l(Be={},Ce.FixedInput,7),l(Be,Ce.FixedOutput,8),Be);function qe(e){var t=Je(e),n=t.assetIn,r=t.assetOut;return he(r.asset.decimals,Number(r.amount))/he(n.asset.decimals,Number(n.amount))}function Qe(e){var t=Ge[e];if(!t)throw new Error("Unknown network or network not supported: ".concat(e));return t}function We(e){return e[e.length-1].quote.amount_out}function ze(e){return e[0].quote.amount_in}function Je(e){return{assetIn:ze(e),assetOut:We(e)}}function Ke(e){return Ye.apply(this,arguments)}function Ye(){return(Ye=i(s().mark((function t(n){var r,a,o,i,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.routerAppID,o=n.assetIDs,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a,appArgs:[Ve.ASSET_OPT_IN],foreignAssets:o,suggestedParams:u}),p=o.length,c.fee=e.ALGORAND_MIN_TX_FEE*(p+1),t.abrupt("return",c);case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function He(e){return $e.apply(this,arguments)}function $e(){return($e=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k,_,E,P,S,D;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.initiatorAddr,a=n.client,o=n.network,i=n.swapType,u=n.route,c=n.slippage,t.next=3,a.getTransactionParams().do();case 3:return p=t.sent,l=[ne(u[0].quote.amount_in.asset),ne(u[0].quote.amount_out.asset),ne(u[1].quote.amount_out.asset)],d=l[0],f=l[1],m=l[2],h=[Number(ze(u).amount),Number(We(u).amount)],g=h[0],x=h[1],A=[u[0].pool.address,u[1].pool.address],I=A[0],v=A[1],w=i===Ce.FixedInput?g:me("positive",c,g),y=i===Ce.FixedOutput?x:me("negative",c,x),b=te(d),T=Qe(o),k=b?e.makePaymentTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,suggestedParams:p}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,assetIndex:d,suggestedParams:p}),(_=e.makeApplicationNoOpTxnFromObject({from:r,appIndex:T,appArgs:[Ue,je[i],e.encodeUint64(y)],foreignApps:[Pe(o,U.V2)],foreignAssets:[d,f,m],accounts:[I,v],suggestedParams:p,note:_e.getAppCallTxnNoteWithClientName(U.V2)})).fee=e.ALGORAND_MIN_TX_FEE*(Xe[i]+1),E=[k,_],t.next=17,Ze({client:a,network:o,assetIDs:[d,f,m]});case 17:if(!((P=t.sent).length>0)){t.next=23;break}return t.next=21,Ke({client:a,initiatorAddr:r,assetIDs:P,routerAppID:T});case 21:S=t.sent,E.unshift(S);case 23:return D=e.assignGroupID(E),t.abrupt("return",D.map((function(e){return{txn:e,signers:[r]}})));case 25:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Ze(e){return et.apply(this,arguments)}function et(){return(et=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(Qe(a)),t.next=4,r.accountInformation(i).do();case 4:return u=t.sent,c=u.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!c.includes(e)})));case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function tt(e){return nt.apply(this,arguments)}function nt(){return(nt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetInID,a=t.assetOutID,o=t.swapType,i=t.network,u={asset_in_id:String(r),asset_out_id:String(a),swap_type:o,amount:String(n)},e.next=4,fetch("".concat(M[i].v1,"/swap-router/quotes/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}).catch((function(){throw new Error("Network error")}));case 4:return c=e.sent,e.next=7,c.json();case 7:if(p=e.sent,c.ok){e.next=14;break}if(s=p,!Boolean(s)||void 0===s.fallback_message){e.next=13;break}throw new E(p.type,p.fallback_message);case 13:throw new E(_.UnknownError,"There was an error while getting a quote from Swap Router");case 14:if(!(p.route.length<2)){e.next=16;break}throw new E(_.SwapRouterNoRouteError,"Swap router couldn't find a route for this swap.");case 16:return e.abrupt("return",p);case 17:case"end":return e.stop()}var s}),e)})))).apply(this,arguments)}var rt=function(e){return e.Direct="direct",e.Router="router",e}({}),at=4*e.ALGORAND_MIN_TX_FEE;function st(t){return(Re[t]+Me)*e.ALGORAND_MIN_TX_FEE}function ot(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Fe;return Math.ceil(1/e)}function it(e){return e1&&void 0!==arguments[1]?arguments[1]:Fe)}function ut(t){return(Re[t]+1)*e.ALGORAND_MIN_TX_FEE}function ct(e){var t=e.assetIn,n=e.assetOut;return he(n.decimals,Number(n.amount))/he(t.decimals,Number(t.amount))}function pt(e){var t=e.inputSupply,n=e.outputSupply,r=e.assetIn,a=e.assetOut,s=ct({assetIn:r,assetOut:a}),o=he(a.decimals,Number(n))/he(r.decimals,Number(t));return ge({decimalPlaces:5},Math.abs(s/o-1))}function lt(e){if(e.type===rt.Router){var t=ze(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetInID,amount:e.data.quote.assetInAmount}}function dt(e){if(e.type===rt.Router){var t=We(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetOutID,amount:e.data.quote.assetOutAmount}}function ft(e){return e.type===rt.Direct?e.data.pool.contractVersion:U.V2}function mt(e){return e.type===rt.Direct?e.data.quote.rate:qe(e.data.route)}function ht(e){for(var t=e[0],n=mt(t),r=1;rn&&(t=a,n=s)}return t}function gt(e){return e instanceof E&&[_.SwapRouterInsufficientReservesError,_.SwapRouterLowSwapAmountError,_.OutputAmountExceedsAvailableLiquidityError,_.LowSwapAmountError].includes(e.type)}var xt={type:"logicsig",logic:{bytecode:"BCAIAQCBgICAgICAgPABgICAgICAgIDwAQMEBQYlJA1EMQkyAxJEMRUyAxJEMSAyAxJEMgQiDUQzAQAxABJEMwEQIQcSRDMBGIGCgICAgICAgPABEkQzARkiEjMBGyEEEhA3ARoAgAlib290c3RyYXASEEAAXDMBGSMSRDMBG4ECEjcBGgCABHN3YXASEEACOzMBGyISRDcBGgCABG1pbnQSQAE7NwEaAIAEYnVybhJAAZg3ARoAgAZyZWRlZW0SQAJbNwEaAIAEZmVlcxJAAnkAIQYhBSQjEk0yBBJENwEaARclEjcBGgIXJBIQRDMCADEAEkQzAhAhBBJEMwIhIxJEMwIiIxwSRDMCIyEHEkQzAiQjEkQzAiWACFRNUE9PTDExEkQzAiZRAA+AD1RpbnltYW5Qb29sMS4xIBJEMwIngBNodHRwczovL3RpbnltYW4ub3JnEkQzAikyAxJEMwIqMgMSRDMCKzIDEkQzAiwyAxJEMwMAMQASRDMDECEFEkQzAxElEkQzAxQxABJEMwMSIxJEJCMTQAAQMwEBMwIBCDMDAQg1AUIBsTMEADEAEkQzBBAhBRJEMwQRJBJEMwQUMQASRDMEEiMSRDMBATMCAQgzAwEIMwQBCDUBQgF8MgQhBhJENwEcATEAE0Q3ARwBMwQUEkQzAgAxABNEMwIUMQASRDMDADMCABJEMwIRJRJEMwMUMwMHMwMQIhJNMQASRDMDESMzAxAiEk0kEkQzBAAxABJEMwQUMwIAEkQzAQEzBAEINQFCAREyBCEGEkQ3ARwBMQATRDcBHAEzAhQSRDMDFDMDBzMDECISTTcBHAESRDMCADEAEkQzAhQzBAASRDMCESUSRDMDADEAEkQzAxQzAwczAxAiEk0zBAASRDMDESMzAxAiEk0kEkQzBAAxABNEMwQUMQASRDMBATMCAQgzAwEINQFCAJAyBCEFEkQ3ARwBMQATRDMCADcBHAESRDMCADEAE0QzAwAxABJEMwIUMwIHMwIQIhJNMQASRDMDFDMDBzMDECISTTMCABJEMwEBMwMBCDUBQgA+MgQhBBJENwEcATEAE0QzAhQzAgczAhAiEk03ARwBEkQzAQEzAgEINQFCABIyBCEEEkQzAQEzAgEINQFCAAAzAAAxABNEMwAHMQASRDMACDQBD0M=",address:"ABUKAXTANWR6K6ZYV75DWJEPVWWOU6SFUVRI6QHO44E4SIDLHBTD2CZ64A",size:881,variables:[{name:"TMPL_ASSET_ID_1",type:"int",index:15,length:10},{name:"TMPL_ASSET_ID_2",type:"int",index:5,length:10},{name:"TMPL_VALIDATOR_APP_ID",type:"int",index:74,length:10}],source:"https://github.com/tinymanorg/tinyman-contracts-v1/tree/dc9ab40c58b85c15d58f63a1507e18be76720dbb/contracts/pool_logicsig.teal.tmpl"},name:"pool_logicsig"},At={type:"app",global_state_schema:{num_uints:0,num_byte_slices:0},local_state_schema:{num_uints:16,num_byte_slices:0},name:"validator_app"},It=p((function e(t){u(this,e),this.schema={numLocalInts:t.local_state_schema.num_uints,numLocalByteSlices:t.local_state_schema.num_byte_slices,numGlobalInts:t.global_state_schema.num_uints,numGlobalByteSlices:t.global_state_schema.num_byte_slices}})),vt=function(n){d(a,It);var r=I(a);function a(e,t){var n;return u(this,a),(n=r.call(this,e)).poolLogicSigContractTemplate=t.logic.bytecode,n.templateVariables=t.logic.variables,n}return p(a,[{key:"generateLogicSigAccountForPool",value:function(n){if(n.asset1ID===n.asset2ID)throw new Error("Assets are the same");var r=Pe(n.network,U.V1_1),a=v(ee(n.asset1ID,n.asset2ID),2),s=a[0],o=a[1],i=Array.from(t.toByteArray(this.poolLogicSigContractTemplate)),u={asset_id_1:s,asset_id_2:o,validator_app_id:r},c=0;this.templateVariables.sort((function(e,t){return e.index-t.index}));for(var p=0;p2&&void 0!==arguments[2]?arguments[2]:e.IntDecoding.DEFAULT;return new Promise(function(){var e=i(s().mark((function e(o,i){var u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.accountInformation(n).setIntDecoding(r).do();case 3:u=e.sent,o(a(a({},u),{},{minimum_required_balance:Pt(u)})),e.next=10;break;case 7:e.prev=7,e.t0=e.catch(0),i(new Error(e.t0.message||"Failed to fetch account information"));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}())}function Et(e,t){var n=e["apps-local-state"].find((function(e){return e.id===t}));return n?re({stateArray:n["key-value"],shouldDecodeKeys:!0}):null}function Pt(e){var t=e["apps-total-schema"];return S+D*(e.assets||[]).length+N*(e["created-apps"]||[]).length+O*(e["apps-local-state"]||[]).length+C*Number(t&&t["num-byte-slice"]||0)+F*Number(t&&t["num-uint"]||0)+B*(e["apps-total-extra-pages"]||0)}var St=Te("e");function Dt(e){return Ot.apply(this,arguments)}function Ot(){return(Ot=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,k,_;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.pool,i=r.accountAddr,n.next=3,a.accountInformation(i).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:u=n.sent,c=u["apps-local-state"]||[],p=0n,l=0n,d=0n,f=o.account.address(),m=T(c),n.prev=10,m.s();case 12:if((h=m.n()).done){n.next=31;break}if((g=h.value).id==o.validatorAppID){n.next=16;break}return n.abrupt("continue",29);case 16:if(x=g["key-value"]){n.next=19;break}return n.abrupt("break",31);case 19:A=re({stateArray:x}),I=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset1ID)])),v=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset2ID)])),w=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.poolTokenID)])),y=A[I],b=A[v],k=A[w],"bigint"==typeof y&&(p=y),"bigint"==typeof b&&(l=b),"bigint"==typeof k&&(d=k);case 29:n.next=12;break;case 31:n.next=36;break;case 33:n.prev=33,n.t0=n.catch(10),m.e(n.t0);case 36:return n.prev=36,m.f(),n.finish(36);case 39:if(!((_={excessAsset1:p,excessAsset2:l,excessPoolTokens:d}).excessAsset1<0n||_.excessAsset2<0n||_.excessPoolTokens<0n)){n.next=42;break}throw new Error("Invalid account excess: ".concat(_));case 42:return n.abrupt("return",_);case 43:case"end":return n.stop()}}),n,null,[[10,33,36,39]])})))).apply(this,arguments)}function Nt(){return(Nt=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.accountAddr,i=r.validatorAppID,n.next=3,a.accountInformation(o).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:if(u=n.sent,c=u["apps-local-state"]||[],p=c.find((function(e){return e.id==i})),l=[],p&&p["key-value"])for(d=re({stateArray:p["key-value"]}),f=0,m=Object.entries(d);fMt)){n.next=48;break}throw new Error("Issued liquidity value is out of the expected range ([0n, ".concat(Mt,"]): ").concat(N.issuedLiquidity));case 48:return n.abrupt("return",N);case 49:case"end":return n.stop()}}),n,null,[[8,31,34,37]])})))).apply(this,arguments)}function Gt(){return Gt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.address,a=t.network,!(o=d.length>1&&void 0!==d[1]?d[1]:{})[r]){e.next=4;break}return e.abrupt("return",o[r]);case 4:return e.next=6,_t(n,r);case 6:return i=e.sent,u=Et(i,Pe(a,U.V1_1)),c=null,u&&(l=i["created-assets"][0],p=l.index,c={asset1ID:u[Ft[U.V1_1].asset1],asset2ID:u[Ft[U.V1_1].asset2],poolTokenID:p},o[r]=c),e.abrupt("return",c);case 11:case"end":return e.stop()}}),e)}))),Gt.apply(this,arguments)}var Xt=Object.freeze({__proto__:null,getPoolAssets:function(e){return Gt.apply(this,arguments)},getPoolInfo:Ut,getPoolReserves:function(e,t){return Vt.apply(this,arguments)}});function qt(e){return Qt.apply(this,arguments)}function Qt(){return(Qt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.asset1ID,o=t.asset2ID,i=kt(U.V2),u=i.generateLogicSigAccountForPool(t),c=Pe(r,U.V2),p=u.address(),l=ee(a,o),e.next=8,_t(n,p);case 8:return d=e.sent,f=Et(d,c),m={account:u,validatorAppID:c,asset1ID:l[0],asset2ID:l[1],status:f?Ct.READY:Ct.NOT_CREATED,contractVersion:U.V2},f&&(m.asset1ProtocolFees=BigInt(f[Ft.v2.asset1ProtocolFees]),m.asset2ProtocolFees=BigInt(f[Ft.v2.asset2ProtocolFees]),m.asset1Reserves=BigInt(f[Ft.v2.asset1Reserves]),m.asset2Reserves=BigInt(f[Ft.v2.asset2Reserves]),m.issuedPoolTokens=BigInt(f[Ft.v2.issuedPoolTokens]),m.cumulativePriceUpdateTimeStamp=Number(f[Ft.v2.cumulativePriceUpdateTimeStamp]),m.protocolFeeRatio=Number(f[Ft.v2.protocolFeeRatio]),m.totalFeeShare=BigInt(f[Ft.v2.totalFeeShare]),m.poolTokenID=Number(f[Ft.v2.poolTokenID]),m.asset1ID=Number(f[Ft.v2.asset1]),m.asset2ID=Number(f[Ft.v2.asset2])),e.abrupt("return",m);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Wt(){return(Wt=i(s().mark((function e(t,n){var r,a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_t(t,n.account.address());case 2:return r=e.sent,a=Et(r,n.validatorAppID),o={asset1:0n,asset2:0n,issuedLiquidity:0n,round:r.round},a&&(o.asset1=BigInt(a[Ft.v2.asset1Reserves]),o.asset2=BigInt(a[Ft.v2.asset2Reserves]),o.issuedLiquidity=BigInt(a[Ft.v2.issuedPoolTokens])),e.abrupt("return",o);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zt(){return(zt=i(s().mark((function e(t){var n,r,a,o,i,u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.address,a=t.network,e.next=3,_t(n,r);case 3:return o=e.sent,i=Et(o,Pe(a,U.V2)),u=null,i&&(u={asset1ID:i[Ft[U.V2].asset1],asset2ID:i[Ft[U.V2].asset2],poolTokenID:i[Ft[U.V2].poolTokenID]}),e.abrupt("return",u);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jt=Object.freeze({__proto__:null,getPoolAssets:function(e){return zt.apply(this,arguments)},getPoolInfo:qt,getPoolReserves:function(e,t){return Wt.apply(this,arguments)}});function Kt(e){return Boolean(e&&!(e.asset1+e.asset2))}var Yt,Ht=Object.freeze({__proto__:null,getPoolPairRatio:function(e){var t=Kt(e),n=null;return e&&!t&&e.asset1&&e.asset2&&(n=Number(e.asset1)/Number(e.asset2)),n},getPoolShare:function(e,t){var n=Number(t)/Number(e);return Number.isFinite(n)||(n=0),n},getPoolsForPair:function(e){return Promise.all([Ut(e),qt(e)])},isPoolEmpty:Kt,isPoolNotCreated:function(e){return(null==e?void 0:e.status)===Ct.NOT_CREATED},isPoolReady:function(e){return(null==e?void 0:e.status)===Ct.READY}}),$t=a((l(Yt={},U.V1_1,a(a({},Xt),Ht)),l(Yt,U.V2,a(a({},Jt),Ht)),Yt),Ht),Zt=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e[e.POOL_TOKEN_CREATE=2]="POOL_TOKEN_CREATE",e[e.ASSET1_OPT_IN=3]="ASSET1_OPT_IN",e[e.ASSET2_OPT_IN=4]="ASSET2_OPT_IN",e}({}),en={ASA_ALGO:96e4,ASA_ASA:859e3};function tn(){return(tn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T,k,_,E,P,S;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Z(o,i),l=v(p,2),d=l[0],f=d.id,m=d.unit_name,h=l[1],g=h.id,x=h.unit_name,A=te(g),I=Pe(a,U.V1_1),w=wt.generateLogicSigAccountForPool({network:a,asset1ID:f,asset2ID:g}),y=w.address(),b=e.makeApplicationOptInTxnFromObject({from:y,appIndex:I,note:_e.getAppCallTxnNoteWithClientName(U.V1_1),appArgs:[Te("bootstrap"),e.encodeUint64(f),e.encodeUint64(g)],foreignAssets:A?[f]:[g],suggestedParams:c}),T=e.makeAssetCreateTxnWithSuggestedParamsFromObject({from:y,total:0xffffffffffffffffn,decimals:6,defaultFrozen:!1,unitName:G.V1_1,assetName:"TinymanPool1.1 ".concat(m,"-").concat(x),assetURL:"https://tinyman.org",suggestedParams:c}),k=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:f,amount:0,suggestedParams:c}),_=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:y,amount:nn(A),suggestedParams:c}),(E=[])[Zt.FUNDING_TXN]=_,E[Zt.VALIDATOR_APP_CALL]=b,E[Zt.POOL_TOKEN_CREATE]=T,E[Zt.ASSET1_OPT_IN]=k,A||(E[Zt.ASSET2_OPT_IN]=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:g,amount:0,suggestedParams:c})),P=e.assignGroupID(E),S=[{txn:P[Zt.FUNDING_TXN],signers:[u]},{txn:P[Zt.VALIDATOR_APP_CALL],signers:[y]},{txn:P[Zt.POOL_TOKEN_CREATE],signers:[y]},{txn:P[Zt.ASSET1_OPT_IN],signers:[y]}],P[Zt.ASSET2_OPT_IN]&&S.push({txn:P[Zt.ASSET2_OPT_IN],signers:[y]}),t.abrupt("return",S);case 23:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function nn(e){return e?en.ASA_ALGO:en.ASA_ASA}function rn(){return(rn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=wt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===Zt.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function an(e){return sn.apply(this,arguments)}function sn(){return(sn=i(s().mark((function e(t){var n,r,a,o,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.signedTxns,a=t.txnIDs,e.prev=1,e.next=4,n.sendRawTransaction(r).do();case 4:return e.next=6,de(n,a[Zt.POOL_TOKEN_CREATE]);case 6:if(o=e.sent,"number"==typeof(i=o["asset-index"])){e.next=10;break}throw new Error("Generated ID is not valid: got ".concat(i));case 10:return e.abrupt("return",{poolTokenID:i});case 13:throw e.prev=13,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while bootstraping the pool. Try again later.");case 16:case"end":return e.stop()}}),e,null,[[1,13]])})))).apply(this,arguments)}function on(){return(on=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.signedTxns,c=t.txnIDs,e.next=3,an({client:n,signedTxns:u,txnIDs:c});case 3:return e.abrupt("return",$t.v1_1.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var un={generateTxns:function(e){return tn.apply(this,arguments)},signTxns:function(e){return rn.apply(this,arguments)},execute:function(e){return on.apply(this,arguments)},getBootstrapFundingTxnAmount:nn};var cn=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e}({}),pn={ASA_ALGO:5,ASA_ASA:6};function ln(e,t){return dn.apply(this,arguments)}function dn(){return(dn=i(s().mark((function t(n,r){var a,o,i;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(o=null===(a=r.find((function(e){return"appl"===e.txn.type})))||void 0===a?void 0:a.txn.txID())){t.next=7;break}return t.next=4,e.waitForConfirmation(n,o,R);case 4:t.t0=t.sent,t.next=8;break;case 7:t.t0=void 0;case 8:return i=t.t0,t.abrupt("return",i);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function fn(e,t){return mn.apply(this,arguments)}function mn(){return(mn=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ln(t,n);case 2:return r=e.sent,e.abrupt("return",null==r?void 0:r["inner-txns"]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function hn(e,t){return gn.apply(this,arguments)}function gn(){return(gn=i(s().mark((function t(n,r){var a,o;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fn(n,r);case 2:return a=t.sent,s=r[0].txn,o=e.encodeAddress(s.from.publicKey),t.abrupt("return",null==a?void 0:a.reduce((function(t,n){var r=t,a=n.txn.txn;return a.type===e.TransactionType.axfer&&e.encodeAddress(a.arcv)===o?r.push({id:a.xaid,amount:a.aamt}):a.type===e.TransactionType.pay&&e.encodeAddress(a.rcv)===o&&r.push({id:j,amount:a.amt}),r}),[]));case 5:case"end":return t.stop()}var s}),t)})))).apply(this,arguments)}function xn(){return(xn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Pe(a,U.V2),l=e.getApplicationAddress(p),d=Z(o,i),f=v(d,2),m=f[0].id,h=f[1].id,t.next=9,$t.v2.getPoolInfo({client:r,network:a,asset1ID:m,asset2ID:h});case 9:if(t.sent.status!==Ct.READY){t.next=12;break}throw new Error("Pool for ".concat(o.unit_name,"-").concat(i.unit_name," already exists"));case 12:return g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=g.address(),A=te(h),(I=e.makeApplicationOptInTxnFromObject({from:x,appIndex:p,appArgs:[Te("bootstrap")],note:_e.getAppCallTxnNoteWithClientName(U.V2),foreignAssets:[m,h],rekeyTo:l,suggestedParams:c})).fee=In(A),w=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:x,amount:An(A),suggestedParams:c}),(y=[])[cn.FUNDING_TXN]=w,y[cn.VALIDATOR_APP_CALL]=I,b=e.assignGroupID(y),(T=[])[cn.FUNDING_TXN]={txn:b[cn.FUNDING_TXN],signers:[u]},T[cn.VALIDATOR_APP_CALL]={txn:b[cn.VALIDATOR_APP_CALL],signers:[x]},t.abrupt("return",T);case 26:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function An(e){return function(e,t){var n=kt(e).schema,r=n.numLocalInts,a=n.numLocalByteSlices,s=S+D+D+O+F*r+C*a;return t||(s+=D),s}(U.V2,e)+In(e)+D}function In(t){return((t?pn.ASA_ALGO:pn.ASA_ASA)+1)*e.ALGORAND_MIN_TX_FEE}function vn(){return(vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===cn.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function wn(){return(wn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.txGroup,c=t.signedTxns,e.prev=1,e.next=4,n.sendRawTransaction(c).do();case 4:return e.next=6,ln(n,u);case 6:if(e.t1=p=e.sent,e.t0=null===e.t1,e.t0){e.next=10;break}e.t0=void 0===p;case 10:if(!e.t0){e.next=14;break}e.t2=void 0,e.next=15;break;case 14:e.t2=null===(l=p["local-state-delta"][0].delta)||void 0===l||null===(d=l.find((function(e){return e.key===btoa(Ft.v2.poolTokenID)})))||void 0===d?void 0:d.value.uint;case 15:if("number"==typeof(f=e.t2)){e.next=18;break}throw new Error("Generated ID is not valid: got ".concat(f));case 18:return e.abrupt("return",$t.v2.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 21:throw e.prev=21,e.t3=e.catch(1),new Y(e.t3,"We encountered something unexpected while bootstraping the pool. Try again later.");case 24:case"end":return e.stop()}}),e,null,[[1,21]])})))).apply(this,arguments)}var yn,bn={generateTxns:function(e){return xn.apply(this,arguments)},signTxns:function(e){return vn.apply(this,arguments)},execute:function(e){return wn.apply(this,arguments)},getBootstrapFundingTxnAmount:An,getTotalCost:function(t){return e.ALGORAND_MIN_TX_FEE+An(t)}};var Tn,kn,_n,En,Pn=(l(yn={},U.V1_1,un),l(yn,U.V2,bn),l(yn,"generateTxns",(function(e){return e.contractVersion===U.V1_1?un.generateTxns(e):bn.generateTxns(e)})),l(yn,"signTxns",(function(e){return e.contractVersion===U.V1_1?un.signTxns(e):bn.signTxns(e)})),l(yn,"execute",(function(e){return e.contractVersion===U.V1_1?un.execute(e):bn.execute(e)})),l(yn,"calculateBootstrapFundingTxnAmount",(function(e){var t=e.contractVersion,n=e.isAlgoPool;return t===U.V1_1?un.getBootstrapFundingTxnAmount(n):bn.getBootstrapFundingTxnAmount(n)})),yn),Sn=function(e){return e[e.FEE_TXN=0]="FEE_TXN",e[e.VALIDATOR_APP_CALL_TXN=1]="VALIDATOR_APP_CALL_TXN",e[e.ASSET1_IN_TXN=2]="ASSET1_IN_TXN",e[e.ASSET2_IN_TXN=3]="ASSET2_IN_TXN",e[e.LIQUDITY_OUT_TXN=4]="LIQUDITY_OUT_TXN",e}({}),Dn=5*e.ALGORAND_MIN_TX_FEE,On=function(e){return e.SINGLE="single",e.FLEXIBLE="flexible",e.INITIAL="initial",e}({}),Nn=(l(Tn={},On.FLEXIBLE,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),l(Tn,On.SINGLE,{ASSET_IN_TXN:0,VALIDATOR_APP_CALL_TXN:1}),l(Tn,On.INITIAL,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),Tn),Bn=(l(kn={},On.INITIAL,1),l(kn,On.SINGLE,2),l(kn,On.FLEXIBLE,2),kn),Cn=(l(_n={},On.INITIAL,3),l(_n,On.FLEXIBLE,3),l(_n,On.SINGLE,2),_n);function Fn(e){var t,n,r,a=e.reserves,s=e.totalFeeShare,o=e.asset1,i=e.asset2,u=a.asset1*a.asset2,c=a.asset1+BigInt(o.amount),p=a.asset2+BigInt(i.amount),l=c*p,d=BigInt(parseInt(String(Math.sqrt(Number(l*a.issuedLiquidity*a.issuedLiquidity/u))))),f=d-a.issuedLiquidity,m=f*c/d,h=f*p/d,g=BigInt(o.amount)-m,x=BigInt(i.amount)-h;if(g>x){var A=g;r=Rn(A,s),t={id:o.id,amount:A+r,decimals:o.decimals,reserves:a.asset1},n={id:i.id,amount:BigInt(Math.abs(Math.min(Number(x),0))),decimals:i.decimals,reserves:a.asset2},f-=r*d/(c*BigInt(2))}else{var I=x;r=Rn(I,s),t={id:i.id,amount:I+r,decimals:i.decimals,reserves:a.asset2},n={id:o.id,amount:BigInt(Math.abs(Math.min(Number(g),0))),decimals:o.decimals,reserves:a.asset1},f-=r*d/(p*BigInt(2))}return{poolTokenOutAmount:f,internalSwapQuote:{assetIn:t,assetOut:n,swapFees:r,priceImpact:pt({inputSupply:t.reserves,outputSupply:n.reserves,assetIn:t,assetOut:n})}}}function Ln(e,t){if(!e.amount||!t.amount)throw new Error("Both assets are required for the initial add liquidity");return BigInt(Math.floor(Math.abs(Math.sqrt(Number(e.amount)*Number(t.amount))-Lt)))}function Rn(e,t){return e*BigInt(t)/(BigInt(1e4)-BigInt(t))}function Mn(t){return(Bn[t]+1)*e.ALGORAND_MIN_TX_FEE}var Un=Te("add_liquidity"),jn=(l(En={},U.V1_1,[Te("mint")]),l(En,U.V2,{INITIAL_LIQUIDITY:[Te("add_initial_liquidity")],SINGLE_ASSET_MODE:[Un,Te("single")],FLEXIBLE_MODE:[Un,Te("flexible")]}),En);function Vn(){return(Vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.asset1In,u=n.asset2In,c=n.poolTokenOut,p=n.slippage,l=n.initiatorAddr,d=me("negative",p,c.amount),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:Pe(a,U.V1_1),appArgs:jn.v1_1,accounts:[l],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:u.id==j?[i.id,c.id]:[i.id,u.id,c.id],suggestedParams:f}),h=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:i.id,amount:i.amount,suggestedParams:f}),g=u.id===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:u.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:u.id,amount:u.amount,suggestedParams:f}),x=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:l,assetIndex:c.id,amount:d,suggestedParams:f}),A=e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:m.fee+x.fee,note:P,suggestedParams:f}),I=e.assignGroupID([A,m,h,g,x]),t.abrupt("return",[{txn:I[0],signers:[l]},{txn:I[1],signers:[o]},{txn:I[2],signers:[l]},{txn:I[3],signers:[l]},{txn:I[4],signers:[o]}]);case 12:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Gn(){return(Gn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,i=r.account,t.next=4,o([a]);case 4:return u=t.sent,c=v(u,3),p=c[0],l=c[1],d=c[2],f=a.map((function(t,n){return n===Sn.FEE_TXN?p:n===Sn.ASSET1_IN_TXN?l:n===Sn.ASSET2_IN_TXN?d:e.signLogicSigTransactionObject(t.txn,i).blob})),t.abrupt("return",f);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Xn(){return(Xn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.signedTxns,i=t.initiatorAddr,e.prev=1,u=BigInt(a[Sn.LIQUDITY_OUT_TXN].txn.amount),e.next=5,Dt({client:n,pool:r,accountAddr:i});case 5:return c=e.sent,e.next=8,Ie(n,[o]);case 8:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,h=we(a),g=ye(a),e.next=17,Dt({client:n,pool:r,accountAddr:i});case 17:return x=e.sent,(A=x.excessPoolTokens-c.excessPoolTokens)<0n&&(A=0n),e.abrupt("return",{round:f,fees:h,poolTokenID:r.poolTokenID,poolTokenOut:u+A,excessAmount:{excessAmountForAddingLiquidity:A,totalExcessAmount:x.excessPoolTokens},txnID:m,groupID:g});case 23:throw e.prev=23,e.t0=e.catch(1),"SlippageTolerance"===(I=new Y(e.t0,"We encountered something unexpected while adding liquidity. Try again later.")).type&&I.setMessage("Adding liquidity failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),I;case 28:case"end":return e.stop()}}),e,null,[[1,23]])})))).apply(this,arguments)}var qn=Object.freeze({__proto__:null,execute:function(e){return Xn.apply(this,arguments)},generateTxns:function(e){return Vn.apply(this,arguments)},getQuote:function(e){var t=e.pool,n=e.reserves,r=e.asset1In,a=e.asset2In;if(0n===n.issuedLiquidity){var s=BigInt(Math.floor(Math.sqrt(Number(r)*Number(a))));if(s<=BigInt(L))throw new Error("Initial liquidity amount is too small. The amount must be greater than ".concat(L,", this quote is for ").concat(s,"."));return{round:n.round,asset1ID:t.asset1ID,asset1In:BigInt(r),asset2ID:t.asset2ID,asset2In:BigInt(a),poolTokenID:t.poolTokenID,poolTokenOut:s-BigInt(L),share:1}}var o=BigInt(r)*n.issuedLiquidity/n.asset1,i=BigInt(a)*n.issuedLiquidity/n.asset2,u=oo)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(t)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{assetInID:i,assetInAmount:l,assetOutID:c,assetOutAmount:m,swapFee:Number(h),rate:he(p,Number(m))/he(u,Number(l)),priceImpact:g}}function xr(e){var t=e.amount,n=e.assetIn,r=e.assetOut,a=e.pool;if(!a||!$t.isPoolReady(a))throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i=n.id,u=n.decimals,c=r.id,p=r.decimals,l=BigInt(t),d=a.totalFeeShare;if(c===a.asset1ID)s=a.asset2Reserves,o=a.asset1Reserves;else{if(c!==a.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(c,") doesn't belong to the pool ").concat(a.account.address(),"."));s=a.asset1Reserves,o=a.asset2Reserves}var f=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapOutputAmount,a=e.totalFeeShare,s=e.decimals,o=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.outputAmount,a=t*n,s=BigInt(a/(n-r))-t;return s+=BigInt(1),s}({inputSupply:t,outputSupply:n,outputAmount:r}),i=function(e){var t=e.swapAmount,n=e.totalFeeShare,r=Math.floor(Number(t*BigInt(1e4)/(BigInt(1e4)-BigInt(n)))),a=BigInt(r)-t;return a}({swapAmount:o,totalFeeShare:a}),u=o+i,c=pt({inputSupply:t,outputSupply:n,assetIn:{amount:u,decimals:s.assetIn},assetOut:{amount:r,decimals:s.assetOut}});return{swapInputAmount:u,totalFeeAmount:i,priceImpact:c}}({inputSupply:s,outputSupply:o,swapOutputAmount:l,totalFeeShare:d,decimals:{assetIn:u,assetOut:p}}),m=f.swapInputAmount,h=f.totalFeeAmount,g=f.priceImpact;if(l>o)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(m)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{type:rt.Direct,data:{pool:a,quote:{assetInID:i,assetInAmount:m,assetOutID:c,assetOutAmount:l,swapFee:Number(h),rate:he(p,Number(l))/he(u,Number(m)),priceImpact:g}}}}function Ar(e){return Ir.apply(this,arguments)}function Ir(){return(Ir=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[],u?c.push(new Promise((function(e,t){try{var s=gr({amount:n,assetIn:r,assetOut:a,pool:u});e({type:rt.Direct,data:{pool:u,quote:s}})}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair"))),o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedInput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=6,hr(c);case 6:return p=e.sent,e.abrupt("return",ht(p));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function vr(e){return wr.apply(this,arguments)}function wr(){return(wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[new Promise((function(e,t){try{e(xr({amount:n,assetIn:r,assetOut:a,pool:u}))}catch(e){t(e)}}))],o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedOutput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=5,hr(c);case 5:return p=e.sent,e.abrupt("return",ht(p));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function yr(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapInputAmount,a=e.totalFeeShare,s=e.decimals,o=BigInt(function(e){var t=e.inputAmount,n=e.totalFeeShare;return Math.floor(Number(t*BigInt(n))/1e4)}({inputAmount:r,totalFeeShare:a})),i=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapAmount,a=t*n,s=n-BigInt(a/(t+BigInt(r)));return s-=BigInt(1)}({inputSupply:t,outputSupply:n,swapAmount:r-o});return{swapOutputAmount:i,totalFeeAmount:o,priceImpact:pt({inputSupply:t,outputSupply:n,assetIn:{amount:r,decimals:s.assetIn},assetOut:{amount:i,decimals:s.assetOut}})}}var br={getQuote:function(e){return mr.apply(this,arguments)},getFixedInputSwapQuote:Ar,getFixedInputDirectSwapQuote:gr,getFixedOutputDirectSwapQuote:xr,getFixedOutputSwapQuote:vr,generateTxns:function(e){return dr.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return fr.apply(this,arguments)},calculateFixedInputSwap:yr};function Tr(e,t){var n,r,a=BigInt(e),s=t.issuedLiquidity;return s>a+BigInt(Lt)?(n=a*t.asset1/s,r=a*t.asset2/s):(n=t.asset1,r=t.asset2),{asset1OutputAmount:n,asset2OutputAmount:r}}function kr(){return(kr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.minAsset1Amount,c=n.minAsset2Amount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.account.address(),f=a.poolTokenID){t.next=8;break}throw new Error("Pool token asset ID is missing");case 8:return m=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:f,amount:o,suggestedParams:l}),(h=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(me("negative",p,u)),e.encodeUint64(me("negative",p,c))],accounts:[d],foreignAssets:[a.asset1ID,a.asset2ID],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(g=[])[ir.ASSET_TRANSFER_TXN]=m,g[ir.APP_CALL_TXN]=h,x=e.assignGroupID(g),t.abrupt("return",[{txn:x[ir.ASSET_TRANSFER_TXN],signers:[i]},{txn:x[ir.APP_CALL_TXN],signers:[i]}]);case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _r(){return(_r=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.initiatorAddr,i=n.poolTokenIn,u=n.outputAssetId,c=n.minOutputAssetAmount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.asset1ID,f=a.asset2ID,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:if(g=0,x=0,A=me("negative",p,c),u!==d){t.next=17;break}g=A,x=0,t.next=23;break;case 17:if(u!==f){t.next=22;break}g=0,x=A,t.next=23;break;case 22:throw new Error("Invalid output asset id. It doesn't match with pool assets");case 23:return I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:m,assetIndex:h,amount:i,suggestedParams:l}),(v=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(g),e.encodeUint64(x)],accounts:[m],foreignAssets:[u],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(w=[])[ir.ASSET_TRANSFER_TXN]=I,w[ir.APP_CALL_TXN]=v,y=e.assignGroupID(w),t.abrupt("return",[{txn:y[ir.ASSET_TRANSFER_TXN],signers:[o]},{txn:y[ir.APP_CALL_TXN],signers:[o]}]);case 31:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Er(){return(Er=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.txGroup,a=t.signedTxns,e.next=3,Ie(n,[a]);case 3:return o=e.sent,i=v(o,1),u=i[0].txnID,e.prev=6,e.next=9,hn(n,r);case 9:c=e.sent,e.next=14;break;case 12:e.prev=12,e.t0=e.catch(6);case 14:return e.abrupt("return",{outputAssets:c,txnID:u});case 15:case"end":return e.stop()}}),e,null,[[6,12]])})))).apply(this,arguments)}var Pr,Sr={getQuote:function(e){var t=e.pool,n=e.reserves,r=e.poolTokenIn,a=BigInt(r),s=Tr(a,n),o=s.asset1OutputAmount,i=s.asset2OutputAmount;return{round:n.round,asset1Out:{assetId:t.asset1ID,amount:o},asset2Out:{assetId:t.asset2ID,amount:i},poolTokenIn:{assetId:t.poolTokenID,amount:a}}},getSingleAssetRemoveLiquidityQuote:function(e){var t,n=e.pool,r=e.reserves,a=e.poolTokenIn,s=e.assetOutID,o=e.decimals,i=BigInt(a),u=Tr(i,r),c=u.asset1OutputAmount,p=u.asset2OutputAmount,l=n.totalFeeShare;if(s===n.asset1ID){var d=br.calculateFixedInputSwap({inputSupply:r.asset2-p,outputSupply:r.asset1-c,swapInputAmount:p,totalFeeShare:l,decimals:o}),f=d.swapOutputAmount,m=d.totalFeeAmount,h=d.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:c+f},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:f},swapFees:{assetId:n.asset2ID,amount:m},priceImpact:h}}}else{if(s!==n.asset2ID)throw new Error("assetOutID must be one of the pool assets");var g=br.calculateFixedInputSwap({inputSupply:r.asset1-c,outputSupply:r.asset2-p,swapInputAmount:c,totalFeeShare:l,decimals:o}),x=g.swapOutputAmount,A=g.totalFeeAmount,I=g.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:p+x},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:x},swapFees:{assetId:n.asset2ID,amount:A},priceImpact:I}}}return t},generateTxns:function(e){return kr.apply(this,arguments)},generateSingleAssetOutTxns:function(e){return _r.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return Er.apply(this,arguments)}},Dr=(l(Pr={},U.V1_1,lr),l(Pr,U.V2,Sr),Pr),Or=3n,Nr=1000n,Br=function(e){return e[e.FEE_TXN_INDEX=0]="FEE_TXN_INDEX",e[e.VALIDATOR_APP_CALL_TXN_INDEX=1]="VALIDATOR_APP_CALL_TXN_INDEX",e[e.ASSET_IN_TXN_INDEX=2]="ASSET_IN_TXN_INDEX",e[e.ASSET_OUT_TXN_INDEX=3]="ASSET_OUT_TXN_INDEX",e}(Br||{});function Cr(){return(Cr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,t.next=3,o([a]);case 3:return i=t.sent,u=v(i,2),c=u[0],p=u[1],l=a.map((function(t,n){return n===Br.FEE_TXN_INDEX?c:n===Br.ASSET_IN_TXN_INDEX?p:e.signLogicSigTransactionObject(t.txn,r.account.lsig).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Fr(){return(Fr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=n.client,a=n.quoteAndPool,o=n.swapType,i=n.slippage,u=n.initiatorAddr,c=a.pool,p=a.quote,l=p.assetInID,d=p.assetOutID,f=c.account.address(),(m=[c.asset1ID,c.asset2ID]).includes(l)&&m.includes(d)&&l!==d){t.next=7;break}throw new Y({pool:c,quote:p},"Input asset (#".concat(l,") and output asset (#").concat(d,") provided to generate transactions do not belong to the pool ").concat(f,"."));case 7:return t.next=9,r.getTransactionParams().do();case 9:return h=t.sent,g=[Te("swap"),o===Ce.FixedInput?Te("fi"):Te("fo")],x=e.makeApplicationNoOpTxnFromObject({from:f,appIndex:c.validatorAppID,appArgs:g,accounts:[u],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:c.asset2ID==j?[c.asset1ID,c.poolTokenID]:[c.asset1ID,c.asset2ID,c.poolTokenID],suggestedParams:h}),A=o===Ce.FixedOutput?me("positive",i,p.assetInAmount):p.assetInAmount,I=l===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:A,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:u,to:f,assetIndex:l,amount:A,suggestedParams:h}),v=o===Ce.FixedInput?me("negative",i,p.assetOutAmount):p.assetOutAmount,w=d===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:f,to:u,amount:v,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:f,to:u,assetIndex:d,amount:v,suggestedParams:h}),y=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:x.fee+w.fee,note:P,suggestedParams:h}),b=e.assignGroupID([y,x,I,w]),t.abrupt("return",[{txn:b[0],signers:[u]},{txn:b[1],signers:[f]},{txn:b[2],signers:[u]},{txn:b[3],signers:[f]}]);case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Lr(e){var t=e.pool,n=e.reserves,r=e.assetIn,s=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var o,i,u,c=BigInt(r.amount);if(r.id===t.asset1ID)o=t.asset2ID,i=n.asset1,u=n.asset2;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Input asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));o=t.asset1ID,i=n.asset2,u=n.asset1}var p=c*Or/Nr,l=u-i*u/(i+(c-p));if(l>u)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var d={assetIn:{amount:c,decimals:s.assetIn},assetOut:{amount:l,decimals:s.assetOut}},f={round:n.round,assetInID:r.id,assetInAmount:c,assetOutID:o,assetOutAmount:l,swapFee:Number(p),rate:ct(d),priceImpact:pt(a({inputSupply:i,outputSupply:u},d))};return{type:rt.Direct,data:{pool:t,quote:f}}}function Rr(e){return Mr.apply(this,arguments)}function Mr(){return(Mr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,i.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount),assetOutID:i.id,assetOutAmount:BigInt(i.amount)+A,excessAmount:{assetID:i.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ur(e){var t=e.pool,n=e.reserves,r=e.assetOut,a=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i,u=BigInt(r.amount);if(r.id===t.asset1ID)s=t.asset2ID,o=n.asset2,i=n.asset1;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));s=t.asset1ID,o=n.asset1,i=n.asset2}if(u>i)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var c=o*i/(i-u)-o,p=c*Nr/(Nr-Or),l=p-c,d=he(a.assetOut,Number(u))/he(a.assetIn,Number(p)),f=he(a.assetOut,Number(i))/he(a.assetIn,Number(o)),m=ge({decimalPlaces:5},Math.abs(d/f-1)),h={round:n.round,assetInID:s,assetInAmount:p,assetOutID:r.id,assetOutAmount:u,swapFee:Number(l),rate:d,priceImpact:m};return{type:rt.Direct,data:{pool:t,quote:h}}}function jr(e){return Vr.apply(this,arguments)}function Vr(){return(Vr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,o.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount)-A,assetOutID:i.id,assetOutAmount:BigInt(i.amount),excessAmount:{assetID:o.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Gr(){return(Gr=i(s().mark((function e(t){var n,r,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.pool,o=t.swapType,i=t.txGroup,u=t.signedTxns,c=t.initiatorAddr,r.status===Ct.READY){e.next=3;break}throw new Y({pool:r,swapType:o,txGroup:i},"There is not an available pool for this asset pair");case 3:if(e.prev=3,p={id:i[Br.ASSET_IN_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_IN_TXN_INDEX].txn.amount},l={id:i[Br.ASSET_OUT_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_OUT_TXN_INDEX].txn.amount},o!==Ce.FixedInput){e.next=12;break}return e.next=9,Rr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 9:d=e.sent,e.next=15;break;case 12:return e.next=14,jr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 14:d=e.sent;case 15:return e.abrupt("return",a(a({},d),{},{groupID:ye(i),fees:we(i)}));case 18:throw e.prev=18,e.t0=e.catch(3),"SlippageTolerance"===(f=new Y(e.t0,"We encountered something unexpected while swapping. Try again later.")).type&&f.setMessage("The swap failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),f;case 23:case"end":return e.stop()}}),e,null,[[3,18]])})))).apply(this,arguments)}var Xr,qr={getQuote:function(e,t,n,r,a){return e===Ce.FixedInput?Lr({pool:t,reserves:n,assetIn:r,decimals:a}):Ur({pool:t,reserves:n,assetOut:r,decimals:a})},getFixedInputSwapQuote:Lr,getFixedOutputSwapQuote:Ur,generateTxns:function(e){return Fr.apply(this,arguments)},signTxns:function(e){return Cr.apply(this,arguments)},execute:function(e){return Gr.apply(this,arguments)},executeFixedOutputSwap:jr};function Qr(e){return Promise.allSettled(e).then((function(e){if(e.every((function(e){return"rejected"===e.status}))){var t=v(e.map((function(e){return e.reason})),2),n=t[0],r=t[1];if(gt(n)&&!gt(r))throw n;throw r}return e.filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value}))}))}function Wr(){return(Wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.isSwapRouterEnabled,u=t.pools,c=[],(p=u.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedInputSwapQuote({pool:p.info,assetIn:{amount:r,id:Number(a.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=u.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedInputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:i,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zr(){return(zr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.pools,u=t.isSwapRouterEnabled,c=[],(p=i.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedOutputSwapQuote({pool:p.info,assetOut:{amount:r,id:Number(o.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=i.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedOutputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:u,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jr=(l(Xr={},U.V1_1,qr),l(Xr,U.V2,br),l(Xr,"getQuote",(function(e){var t=e.type;if(t===Ce.FixedInput)return function(e){return Wr.apply(this,arguments)}(e);if(t===Ce.FixedOutput)return function(e){return zr.apply(this,arguments)}(e);throw new E(_.InvalidSwapTypeError,"Invalid swap type")})),l(Xr,"generateTxns",(function(e){return e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1?qr.generateTxns(a(a({},e),{},{quoteAndPool:e.quote.data})):br.generateTxns(e)})),l(Xr,"signTxns",(function(e){if(e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1){var t=e.quote.data.pool;return qr.signTxns(a(a({},e),{},{pool:t}))}return br.signTxns(e)})),l(Xr,"execute",(function(e){return e.contractVersion===U.V1_1?qr.execute(e):br.execute(e)})),Xr);function Kr(){return(Kr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.initiatorSigner,e.prev=1,e.next=4,Yr({txGroup:a,pool:r,initiatorSigner:o});case 4:return i=e.sent,e.next=7,Ie(n,[i]);case 7:return u=e.sent,c=v(u,1),p=c[0],l=p.txnID,d=p.confirmedRound,e.abrupt("return",{fees:we(a),confirmedRound:d,txnID:l,groupID:ye(a)});case 15:throw e.prev=15,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while redeeming. Try again later.");case 18:case"end":return e.stop()}}),e,null,[[1,15]])})))).apply(this,arguments)}function Yr(e){return Hr.apply(this,arguments)}function Hr(){return(Hr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.pool,o=n.initiatorSigner,t.next=3,o([r]);case 3:return i=t.sent,u=v(i,1),c=u[0],p=a.account.lsig,l=r.map((function(t,n){return 0===n?c:e.signLogicSigTransactionObject(t.txn,p).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function $r(){return $r=i(s().mark((function t(n){var r,a,o,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.data,o=n.initiatorSigner,t.prev=1,u=a.map((function(e){var t=e.txGroup,n=e.pool;return{txns:t,txnFees:we(t),groupID:ye(t),lsig:n.account.lsig}})),t.next=5,o(u.map((function(e){return e.txns})));case 5:return c=t.sent,p=Promise.all(u.map((function(t,n){return new Promise(function(){var a=i(s().mark((function a(o,i){var u,p,l,d,f,m;return s().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,u=t.txns.map((function(r,a){return 0===a?c[n]:e.signLogicSigTransactionObject(r.txn,t.lsig).blob})),a.next=4,Ie(r,[u]);case 4:p=a.sent,l=v(p,1),d=l[0],f=d.txnID,m=d.confirmedRound,o({fees:t.txnFees,groupID:t.groupID,txnID:f,confirmedRound:m}),a.next=15;break;case 12:a.prev=12,a.t0=a.catch(0),i(a.t0);case 15:case"end":return a.stop()}}),a,null,[[0,12]])})));return function(e,t){return a.apply(this,arguments)}}())}))),t.abrupt("return",p);case 10:throw t.prev=10,t.t0=t.catch(1),new Y(t.t0,"We encountered something unexpected while redeeming. Try again later.");case 13:case"end":return t.stop()}}),t,null,[[1,10]])}))),$r.apply(this,arguments)}function Zr(){return(Zr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.assetID,i=n.assetOut,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=a.account.address(),l=e.makeApplicationNoOpTxnFromObject({from:p,appIndex:a.validatorAppID,appArgs:[Te("redeem")],note:_e.getAppCallTxnNoteWithClientName(a.contractVersion),accounts:[u],foreignAssets:0==a.asset2ID?[a.asset1ID,a.poolTokenID]:[a.asset1ID,a.asset2ID,a.poolTokenID],suggestedParams:c}),d=0===o?e.makePaymentTxnWithSuggestedParamsFromObject({from:p,to:u,amount:BigInt(i),suggestedParams:c}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:p,to:u,assetIndex:o,amount:BigInt(i),suggestedParams:c}),f=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:p,amount:l.fee+d.fee,note:P,suggestedParams:c}),m=e.assignGroupID([f,l,d]),t.abrupt("return",[{txn:m[0],signers:[u]},{txn:m[1],signers:[p]},{txn:m[2],signers:[p]}]);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ea(e){var t,n={},r=T(e);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=(new TextDecoder).decode(Buffer.from(a.key,"base64")),o=void 0;o=1===a.value.type?a.value.bytes:a.value.uint,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function ta(e,t,n){return e*t/n}var na=BigInt(31536e3),ra=BigInt(1e14),aa=BigInt(1e16),sa={testnet:548587153,mainnet:1385499515},oa=14;function ia(e){return ua.apply(this,arguments)}function ua(){return(ua=i(s().mark((function t(n){var r,a,o,i,u;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(sa[a]),t.next=4,_t(r,i);case 4:return u=t.sent.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!u.includes(e)})));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ca(){return(ca=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,y,b,T,k,_,E,P;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.poolTokenId,u=n.lendingManagerId,c=n.asset1In,p=n.asset2In,l=n.initiatorAddr,d=e.getApplicationAddress(sa[a]),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=[c,p].sort((function(e,t){return t.fAssetId-e.fAssetId})),h=v(m,2),g=h[0],x=h[1],A=te(x.id),I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:g.id,amount:g.amount,suggestedParams:f}),y=A?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:x.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:x.id,amount:x.amount,suggestedParams:f}),(b=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("add_liquidity"),e.decodeAddress(o).publicKey,e.encodeUint64(g.lendingAppId),e.encodeUint64(x.lendingAppId)],foreignAssets:[g.id,x.id,g.fAssetId,x.fAssetId],foreignApps:[g.lendingAppId,x.lendingAppId,u],accounts:[o],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),T=Pe(a,U.V2),k=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("noop")],foreignAssets:[i],foreignApps:[T],accounts:[o],suggestedParams:f}),_=[I,y,b,k],t.next=16,ia({client:r,network:a,assetIDs:[g.id,x.id,g.fAssetId,x.fAssetId,i]});case 16:return(E=t.sent).length&&((P=[e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:D*E.length,suggestedParams:f}),e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("asset_optin")].concat(w(E.map((function(t){return e.encodeUint64(t)})))),foreignAssets:w(E),suggestedParams:f})])[1].fee=(E.length+1)*e.ALGORAND_MIN_TX_FEE,_.unshift.apply(_,P)),t.abrupt("return",e.assignGroupID(_).map((function(e){return{txn:e,signers:[l]}})));case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function pa(){return(pa=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.asset1Out,c=n.asset2Out,p=n.lendingManagerId,l=n.network,d=e.getApplicationAddress(sa[l]),t.next=4,r.getTransactionParams().do();case 4:if(f=t.sent,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:return g=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:h,amount:o,suggestedParams:f}),(x=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("remove_liquidity"),e.decodeAddress(m).publicKey,e.encodeUint64(u.lendingAppId),e.encodeUint64(c.lendingAppId)],accounts:[m],foreignAssets:[u.id,c.id,u.fAssetId,c.fAssetId],foreignApps:[u.lendingAppId,c.lendingAppId,p],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),A=Pe(l,U.V2),I=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("noop")],accounts:[m],foreignAssets:[h,u.fAssetId,c.fAssetId],foreignApps:[A],suggestedParams:f}),v=e.assignGroupID([g,x,I]),t.abrupt("return",v.map((function(e){return{txn:e,signers:[i]}})));case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function la(e,t,n){var r=BigInt(Math.floor((new Date).getTime()/1e3)-function(e){return null!=e?e:Math.floor((new Date).getTime()/1e3)}(n));return ta(e,aa+t*r/na,aa)}function da(){return(da=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,a=r.params["global-state"],o=ea(a),i=Number(Buffer.from(o.pm,"base64").readBigUInt64BE(0)),u=Buffer.from(o.i,"base64"),c=u.readBigUInt64BE(32),p=u.readBigUInt64BE(40),l=Number(u.readBigUInt64BE(48)),e.abrupt("return",{appId:n,managerAppId:i,depositInterestRate:c,depositInterestIndex:p,lastUpdate:l});case 11:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var fa={AddLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return ca.apply(this,arguments)},getAddLiquidityTotalFee:function(t){return e.ALGORAND_MIN_TX_FEE*(4+oa)+(t?(t+1)*e.ALGORAND_MIN_TX_FEE+t*D:0)}}),RemoveLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return pa.apply(this,arguments)},getRemoveLiquidityTotalFee:function(){return e.ALGORAND_MIN_TX_FEE*(3+oa)}}),calculateWithdrawReturn:function(e){var t=e.withdrawAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return ta(BigInt(t),n,ra)},calculateDepositReturn:function(e){var t=e.depositAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return BigInt(t)*ra/n},getFolksWrapperAppOptInRequiredAssetIDs:ia};function ma(t){var n=t.suggestedParams,r=t.stakingAppID,a=t.initiatorAddr,s=t.liquidityAssetID,o=t.program,i=t.amount,u=e.encodeUint64(i),c=e.encodeUint64(o.id);return e.makeApplicationNoOpTxnFromObject({appIndex:r,from:a,suggestedParams:n,foreignAssets:[s],accounts:[o.accountAddress],appArgs:[Te("commit"),u],note:ae([Te("tinymanStaking/v1:b"),c,e.encodeUint64(s),u])})}function ha(){return(ha=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.stakingAppID,o=n.program,i=n.requiredAssetID,u=n.liquidityAssetID,c=n.amount,p=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=ma({suggestedParams:l,stakingAppID:a,program:o,liquidityAssetID:u,initiatorAddr:p,amount:c}),f=[d],"number"!=typeof i){t.next=10;break}return m=e.makeApplicationNoOpTxnFromObject({appIndex:a,from:p,suggestedParams:l,foreignAssets:[i],accounts:[o.accountAddress],appArgs:[Te("log_balance")]}),f=e.assignGroupID([d,m]),t.abrupt("return",[{txn:f[0],signers:[p]},{txn:f[1],signers:[p]}]);case 10:return t.abrupt("return",[{txn:f[0],signers:[p]}]);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var ga=604800,xa=1e3,Aa={testnet:480164661,mainnet:2200606875},Ia={testnet:360907790,mainnet:2200609638},va={testnet:336189106,mainnet:2200608153},wa={testnet:383416252,mainnet:2200608887},ya=2500,ba=400,Ta=604800,ka=Te("p"),_a=Te("a"),Ea=24,Pa=111300,Sa=ya+ba*(41+Ea),Da=function(e){return e[e.Against=0]="Against",e[e.For=1]="For",e[e.Abstain=2]="Abstain",e}(Da||{}),Oa=new Uint8Array(34),Na="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ";function Ba(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,n=new Uint8Array(t),r=BigInt(e),a=t-1;a>=0;a--)n[a]=Number(r&BigInt(255)),r>>=BigInt(8);return n}function Ca(e,t){return 0===Buffer.compare(e,t)}function Fa(e){for(var t=0n,n=0;n=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r>>0,o=new Uint8Array(s);e[t];){var p=n[e.charCodeAt(t)];if(255===p)return;for(var l=0,d=s-1;(0!==p||l>>0,o[d]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");a=l,t++}if(" "!==e[t]){for(var f=s-a;f!==s&&0===o[f];)f++;for(var m=new Uint8Array(r+(s-f)),h=r;f!==s;)m[h++]=o[f++];return m}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var n=0,r=0,a=0,s=t.length;a!==s&&0===t[a];)a++,n++;for(var o=(s-a)*p+1>>>0,c=new Uint8Array(o);a!==s;){for(var l=t[a],d=0,f=o-1;(0!==l||d>>0,c[f]=l%i>>>0,l=l/i>>>0;if(0!==l)throw new Error("Non-zero carry");r=d,a++}for(var m=o-r;m!==o&&0===c[m];)m++;for(var h=u.repeat(n);mLa(a(e))})}function Wa({name:e,prefix:t,bitsPerChar:n,alphabet:r}){return qa({prefix:t,name:e,encode:e=>function(e,t,n){const r="="===t[t.length-1],a=(1<n;)o-=n,s+=t[a&i>>o];if(0!==o&&(s+=t[a&i<function(e,t,n,r){const a={};for(let e=0;e=8&&(i-=8,o[c++]=255&u>>i)}if(i>=n||0!=(255&u<<8-i))throw new SyntaxError("Unexpected end of data");return o}(t,r,n,e)})}const za=Wa({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5});Wa({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wa({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wa({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wa({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wa({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wa({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wa({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wa({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});const Ja=Qa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"});Qa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ka=function e(t,n,r){n=n||[];var a=r=r||0;for(;t>=$a;)n[r++]=255&t|Ya,t/=128;for(;t&Ha;)n[r++]=255&t|Ya,t>>>=7;return n[r]=0|t,e.bytes=r-a+1,n},Ya=128,Ha=-128,$a=Math.pow(2,31);var Za=function e(t,n){var r,a=0,s=0,o=n=n||0,i=t.length;do{if(o>=i)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],a+=s<28?(r&ts)<=es);return e.bytes=o-n,a},es=128,ts=127;var ns=Math.pow(2,7),rs=Math.pow(2,14),as=Math.pow(2,21),ss=Math.pow(2,28),os=Math.pow(2,35),is=Math.pow(2,42),us=Math.pow(2,49),cs=Math.pow(2,56),ps=Math.pow(2,63),ls={encode:Ka,decode:Za,encodingLength:function(e){return e{const[n,r]=ds(e.subarray(t));return t+=r,n};let r=n(),a=ws;if(18===r?(r=0,t=0):a=n(),0!==r&&1!==r)throw new RangeError(`Invalid CID version ${r}`);const s=t,o=n(),i=n(),u=t+i;return{version:r,codec:a,multihashCode:o,digestSize:i,multihashSize:u-s,size:u}}static parse(e,t){const[n,r]=function(e,t){switch(e[0]){case"Q":{const n=t??Ja;return[Ja.prefix,n.decode(`${Ja.prefix}${e}`)]}case Ja.prefix:{const n=t??Ja;return[Ja.prefix,n.decode(e)]}case za.prefix:{const n=t??za;return[za.prefix,n.decode(e)]}default:if(null==t)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}(e,t),a=vs.decode(r);if(0===a.version&&"Q"!==e[0])throw Error("Version 0 CID string must not include multibase prefix");return Is(a).set(n,e),a}}const ws=112,ys=18;function bs(e,t,n){const r=ms(e),a=r+ms(t),s=new Uint8Array(a+n.byteLength);return fs(e,s,0),fs(t,s,r),s.set(n,a),s}const Ts=Symbol.for("@ipld/js-cid/CID");class ks{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){const t=this.encode(e);return t instanceof Uint8Array?hs(this.code,t):t.then((e=>hs(this.code,e)))}throw Error("Unknown type, must be binary type")}}const _s=85,Es=function({name:e,code:t,encode:n}){return new ks(e,t,n)}({name:"sha2-256",code:18,encode:e=>La(n.createHash("sha256").update(e).digest())});var Ps=126144e3,Ss=1e7,Ds=Math.pow(2,64),Os=48,Ns=21,Bs=48,Cs=Te("tp"),Fs=Te("sc"),Ls=28100,Rs=12900,Ms=421700,Us=409700;function js(e){var t=e/Ta;return(arguments.length>1&&void 0!==arguments[1]&&arguments[1]?Math.floor(t):Math.ceil(t))*Ta}function Vs(e,t){if(e>t)throw new Error("Old timestamp must be less than or equal to new timestamp");for(var n=[],r=js(e)+Ta;re?r=t?e*e*Ds/(2*t):0:r=(e+(e-r))*n/2;return r}function Js(e,t){return Ks.apply(this,arguments)}function Ks(){return(Ks=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,e.abrupt("return",Ys(r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ys(e){var t,n={},r=T(e.params["global-state"]);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=Buffer.from(a.key,"base64").toString(),o=void 0;o=1===a.value.type?Buffer.from(a.value.bytes||"","base64"):a.value.uint||0,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function Hs(){for(var e=arguments.length,t=new Array(e),n=0;n0?Ns-e:0}},{key:"lastAccountPowerBoxIndex",get:function(){return xo(this.powerCount)[0]}},{key:"lastAccountPowerArrayIndex",get:function(){return xo(this.powerCount)[1]}}]),e}(),uo=function(){function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a}return p(e,[{key:"lockEndTimestamp",get:function(){var e=this.bias*Math.pow(2,64)/this.slope;return this.timestamp+e}},{key:"cumulativePowerAt",value:function(e){var t=e-this.timestamp;if(t<0)throw new Error("Time delta must be greater than or equal to 0");return this.cumulativePower+zs(this.bias,this.slope,t)}}]),e}(),co=p((function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a})),po=p((function e(t){u(this,e),this.slopeDelta=t})),lo=function(){function e(t,n,r,a){u(this,e),this.tinyAssetId=t,this.totalLockedAmount=n,this.totalPowerCount=r,this.lastTotalPowerTimestamp=a}return p(e,[{key:"freeTotalPowerSpaceCount",get:function(){var e=this.totalPowerCount%Ns;return e>0?Ns-e:0}},{key:"lastTotalPowerBoxIndex",get:function(){return xo(this.totalPowerCount)[0]}},{key:"lastTotalPowerArrayIndex",get:function(){return xo(this.totalPowerCount)[1]}}]),e}();function fo(){return(fo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ho(r),e.prev=1,e.next=4,Gs(t,n,a);case 4:if(!(o=e.sent)){e.next=7;break}return e.abrupt("return",mo(o));case 7:return e.abrupt("return",null);case 10:return e.prev=10,e.t0=e.catch(1),console.log(e.t0),e.abrupt("return",null);case 14:case"end":return e.stop()}}),e,null,[[1,10]])})))).apply(this,arguments)}function mo(e){var t=Buffer.from(e);return new io(t.readUIntBE(0,8),t.readUIntBE(8,8),t.readUIntBE(16,8),t.readUIntBE(24,8))}function ho(t){return e.decodeAddress(t).publicKey}function go(e){var t=Ba(e),n=new Uint8Array(Cs.length+t.length);return n.set(Cs,0),n.set(t,Cs.length),n}function xo(e){var t=e-1;return[Math.floor(t/Ns),t%Ns]}function Ao(t,n){var r=e.decodeAddress(t).publicKey,a=Ba(n),s=new Uint8Array(r.length+a.length);return s.set(r,0),s.set(a,r.length),s}function Io(e,t,n){return vo.apply(this,arguments)}function vo(){return(vo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=yo(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",wo(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function wo(t){return new po(Number(e.bytesToBigInt(t.slice(t.length-16,t.length))))}function yo(e){return Hs(Fs,Ba(e))}function bo(e,t,n){return To.apply(this,arguments)}function To(){return(To=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=0,r&&(a=Math.ceil(r/Ns)),o=[],i=0;case 4:if(!(i=e[r].timestamp))break;n=r}return n}function So(e){for(var t,n=Os,r=[],a=0;a=11)throw new Error("Boxes' length cannot be larger than 10");var y=d.slice(0,6),b=[e.makeApplicationNoOpTxnFromObject({from:s,suggestedParams:c,appIndex:n,appArgs:[Te("claim_rewards"),Ba(o),Ba(i),Hs.apply(void 0,w(u.map((function(e){return Ba(e)}))))],foreignApps:[r],foreignAssets:[a],boxes:y,note:l?Te(l):void 0})];b[0].fee=b[0].fee*(i+2);var k=0,_=92+865*i,E=700+700*i;if(_>E&&(k=Math.floor((_-E)/666)+1),k||d.length>6){var P=d.slice(6),S=Ko({sender:s,suggestedParams:c,extraAppArgs:[Ba(Math.max(k-1,0))],index:n,foreignApps:[r],boxes:P});S.fee*=Math.max(k,1),b.unshift(S)}if(p){var D=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,to:e.getApplicationAddress(n),amount:Lo,suggestedParams:c});b.unshift(D)}return e.assignGroupID(b)}var Ho=8,$o=Te("p"),Zo=Te("a"),ei=Te("v"),ti=28500,ni=12500,ri=p((function e(t,n,r,a,s,o,i){u(this,e),this.index=t,this.creationTimestamp=n,this.votingStartTimestamp=r,this.votingEndTimestamp=a,this.votingPower=s,this.voteCount=o,this.isCancelled=i}));function ai(t,n){return Hs(Zo,e.decodeAddress(t).publicKey,Ba(n))}function si(e){return new ri(Fa(e.slice(0,8)),Fa(e.slice(8,16)),Fa(e.slice(16,24)),Fa(e.slice(24,32)),Fa(e.slice(32,40)),Fa(e.slice(40,48)),Boolean(Fa(e.slice(48,49))))}function oi(){return(oi=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ao(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",si(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ii(t){var n=t.stakingVotingAppId,r=t.vaultAppId,a=t.sender,s=t.proposalId,o=t.proposal,i=t.votes,u=t.assetIds,c=t.accountPowerIndex,p=t.appBoxNames,l=t.suggestedParams,d=t.appCallNote,f=void 0===d?null:d;if(i.length!==u.length)throw new Error("The number of votes must be equal to the number of asset ids");if(u.length>Ho)throw new Error("You cannot cast vote for more than ".concat(Ho," different pools"));if(100!==i.reduce((function(e,t){return e+t}),0))throw new Error("The sum of the votes must equal 100%");var m,h=Hs.apply(void 0,w(i.map((function(e){return Ba(e)})))),g=Hs.apply(void 0,w(u.map((function(e){return Ba(e)})))),x=function(e){return Hs($o,Te(e))}(s),A=ai(a,Math.floor(o.index/8192)),I=!p.some((function(e){return Ca(e,A)})),v=ho(a),y=Math.floor(c/Ns),b=Ao(a,y),k=Ao(a,y+1),_=0,E=[],P=T(u);try{var S=function(){var e=m.value,t=function(e,t){return Hs(ei,Ba(e),Ba(t))}(o.index,e);E.push({appIndex:n,name:t}),p.some((function(e){return Ca(e,t)}))||(_+=1)};for(P.s();!(m=P.n()).done;)S()}catch(e){P.e(e)}finally{P.f()}var D=[{appIndex:n,name:x},{appIndex:n,name:A}].concat(E,[{appIndex:r,name:v},{appIndex:r,name:b},{appIndex:r,name:k}]),O=[e.makeApplicationNoOpTxnFromObject({from:a,suggestedParams:l,appIndex:n,appArgs:[Te("cast_vote"),Te(s),h,g,Ba(c)],foreignApps:[r],boxes:D.slice(0,7),note:f?Te(f):void 0})];O[0].fee*=2,D.length>=7&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(7,14)})),D.length>=14&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(14)}));var N=Number(I)*ti+_*ni;return N&&(O=[e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:l,to:e.getApplicationAddress(n),amount:N})].concat(w(O))),e.assignGroupID(O)}function ui(t){var n=t.accountState,r=t.lockEndTime,a=t.lockedAmount,s=t.network,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.slopeChangeAtLockEndTime,p=t.appCallNote;if(ai.freeTotalPowerSpaceCount&&(b+=Us),c||(b+=Rs);var k=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({amount:a,assetIndex:X[s],from:o,suggestedParams:u,to:e.getApplicationAddress(l)}),e.makeApplicationNoOpTxnFromObject({appIndex:l,from:o,suggestedParams:u,appArgs:[Te("create_lock"),Ba(r)],boxes:d.slice(0,8),note:p}),Ko({sender:o,suggestedParams:u,index:l,boxes:d.slice(8)})];if(b){var _=e.makePaymentTxnWithSuggestedParamsFromObject({amount:b,from:o,suggestedParams:u,to:e.getApplicationAddress(l)});k.unshift(_)}return e.assignGroupID(k)}function ci(t){var n=t.accountState,r=t.lockedAmount,a=t.network,s=t.sender,o=t.vaultAppGlobalState,i=t.suggestedParams,u=t.appCallNote;if(ro.freeTotalPowerSpaceCount&&(v+=Us),!n.freeAccountPowerSpaceCount){var w=Ao(s,n.lastAccountPowerBoxIndex+1);h.push({appIndex:Aa[a],name:w}),v+=Ms}var y=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:X[a],from:s,to:e.getApplicationAddress(Aa[a]),amount:r,suggestedParams:i}),e.makeApplicationNoOpTxnFromObject({appIndex:Aa[a],from:s,suggestedParams:i,appArgs:[Te("increase_lock_amount")],boxes:h,note:u}),Ko({sender:s,suggestedParams:i,index:Aa[a]})];if(v){var b=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,suggestedParams:i,to:e.getApplicationAddress(Aa[a]),amount:v});y.unshift(b)}return e.assignGroupID(y)}function pi(t){var n=t.accountState,r=t.network,a=t.newLockEndTime,s=t.slopeChangeAtNewLockEndTime,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.appCallNote;if(a%Ta)throw new Error("Invalid lock end time");if(a<=n.lockEndTime)throw new Error("New lock end time must be greater than current lock end time");var p=ho(o),l=Ao(o,n.lastAccountPowerBoxIndex),d=go(i.lastTotalPowerBoxIndex),f=go(i.lastTotalPowerBoxIndex+1),m=yo(n.lockEndTime),h=yo(a),g=[{appIndex:Aa[r],name:p},{appIndex:Aa[r],name:l},{appIndex:Aa[r],name:d},{appIndex:Aa[r],name:f},{appIndex:Aa[r],name:m},{appIndex:Aa[r],name:h}];if(!n.freeAccountPowerSpaceCount){var x=Ao(o,n.lastAccountPowerBoxIndex+1);g.push({appIndex:Aa[r],name:x})}var A,I=Vs(i.lastTotalPowerTimestamp,Math.floor(Date.now()/1e3)),v=I.length,w=T(I);try{for(w.s();!(A=w.n()).done;){var y=A.value;if(y%Ta==0){var b=yo(y);g.push({appIndex:Aa[r],name:b})}}}catch(e){w.e(e)}finally{w.f()}var k=0;s||(k+=Rs),n.freeAccountPowerSpaceCount||(k+=Ms),v>i.freeTotalPowerSpaceCount&&(k+=Us);var _=[e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:o,suggestedParams:u,appArgs:[Te("extend_lock_end_time"),Ba(a)],boxes:g.slice(0,8),note:c}),Ko({sender:o,suggestedParams:u,index:Aa[r],boxes:g.slice(8)})];if(k){var E=e.makePaymentTxnWithSuggestedParamsFromObject({from:o,suggestedParams:u,to:e.getApplicationAddress(Aa[r]),amount:k});_.unshift(E)}return e.assignGroupID(_)}function li(t){var n=t.accountState,r=t.network,a=t.sender,s=t.suggestedParams,o=t.appCallNote,i=ho(a),u=Ao(a,n.lastAccountPowerBoxIndex),c=Ao(a,n.lastAccountPowerBoxIndex+1),p=[{appIndex:Aa[r],name:i},{appIndex:Aa[r],name:u},{appIndex:Aa[r],name:c}],l=e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:a,suggestedParams:s,appArgs:[Te("withdraw")],foreignAssets:[X[r]],boxes:p,note:o});l.fee*=2;var d=[l];if(!n.freeAccountPowerSpaceCount){var f=e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:s,to:e.getApplicationAddress(Aa[r]),amount:Ms});d.unshift(f)}return e.assignGroupID(d)}var di=function(){function t(e,n,r){u(this,t),this.algodClient=e,this.userAddress=n,this.network=r}var n,r,a,o,c,l,d,f,m,h,g,x,A,I,v,y;return p(t,[{key:"getTinyPower",value:(y=i(s().mark((function e(){var t,n,r,a,o,i,u,c=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=c.length>0&&void 0!==c[0]?c[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=Math.max(o.bias-Ws(o.slope,i),0),e.abrupt("return",u);case 16:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getTotalTinyPower",value:(v=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=v.length>0&&void 0!==v[0]?v[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchVaultAppGlobalState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,bo(this.algodClient,Aa[this.network],n.totalPowerCount);case 8:if(r=e.sent,a=Po(r,t)){e.next=12;break}return e.abrupt("return",0);case 12:o=r[a],i=Math.floor(o.timestamp/Ta),u=Math.floor(t/Ta)-i,c=Array.from({length:u},(function(e,t){return(i+t)*Ta})),p=c.map((function(e,t){return[0===t?o.timestamp:c[t-1],e]})),l=o.slope,d=o.bias,f=T(p),e.prev=19,f.s();case 21:if((m=f.n()).done){e.next=34;break}return h=m.value,g=h[1]-h[0],x=Ws(l,g),d=Math.max(d-x,0),e.next=28,Io(this.algodClient,Aa[this.network],h[1]);case 28:A=e.sent,I=(null==A?void 0:A.slopeDelta)||0,l=Math.max(l-I,0),0!==d&&0!==l||(d=0,l=0);case 32:e.next=21;break;case 34:e.next=39;break;case 36:e.prev=36,e.t0=e.catch(19),f.e(e.t0);case 39:return e.prev=39,f.f(),e.finish(39);case 42:return e.abrupt("return",d);case 43:case"end":return e.stop()}}),e,this,[[19,36,39,42]])}))),function(){return v.apply(this,arguments)})},{key:"getCumulativeTinyPower",value:(I=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=p.length>0&&void 0!==p[0]?p[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=zs(o.bias,o.slope,i),c=o.cumulativePower-u,e.abrupt("return",c);case 17:case"end":return e.stop()}}),e,this)}))),function(){return I.apply(this,arguments)})},{key:"fetchVaultAppGlobalState",value:(A=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,Js(this.algodClient,Aa[this.network]);case 3:return t=e.sent,e.abrupt("return",new lo(t.tiny_asset_id,t.total_locked_amount,t.total_power_count,t.last_total_power_timestamp));case 7:return e.prev=7,e.t0=e.catch(0),console.error(e.t0),e.abrupt("return",null);case 11:case"end":return e.stop()}}),e,this,[[0,7]])}))),function(){return A.apply(this,arguments)})},{key:"generateCreateLockTransactions",value:(x=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=o,c){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(p){e.next=15;break}return e.next=14,this.algodClient.getTransactionParams().do();case 14:p=e.sent;case 15:return e.next=17,Io(this.algodClient,Aa[this.network],r);case 17:return l=e.sent,e.abrupt("return",ui({lockedAmount:n,lockEndTime:r,vaultAppGlobalState:c,slopeChangeAtLockEndTime:l,sender:i,network:this.network,accountState:u,suggestedParams:p}));case 19:case"end":return e.stop()}}),e,this)}))),function(e){return x.apply(this,arguments)})},{key:"generateIncreaseLockAmountTransactions",value:(g=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.abrupt("return",ci({accountState:i,lockedAmount:n,network:this.network,sender:o,vaultAppGlobalState:u,suggestedParams:c}));case 18:case"end":return e.stop()}}),e,this)}))),function(e){return g.apply(this,arguments)})},{key:"generateExtendLockTimeTransactions",value:(h=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.newLockEndTime,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.next=19,Io(this.algodClient,Aa[this.network],n);case 19:return p=e.sent,e.abrupt("return",pi({accountState:i,network:this.network,newLockEndTime:n,sender:o,vaultAppGlobalState:u,suggestedParams:c,slopeChangeAtNewLockEndTime:null==p?void 0:p.slopeDelta}));case 21:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"generateIncreaseLockAmountAndExtendLockEndTimeTransactions",value:(m=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=[],l=[],d=o,c){e.next=13;break}throw new Error("There was an error while fetching vault app global state");case 13:if(u){e.next=15;break}throw new Error("There was an error while fetcing the account state");case 15:if(d){e.next=19;break}return e.next=18,this.algodClient.getTransactionParams().do();case 18:d=e.sent;case 19:return p=ci({accountState:u,lockedAmount:n,network:this.network,sender:i,vaultAppGlobalState:c,suggestedParams:d}),u.powerCount+=1,c.totalPowerCount+=1,e.next=24,Io(this.algodClient,Aa[this.network],r);case 24:return f=e.sent,l=pi({accountState:u,network:this.network,newLockEndTime:r,sender:i,vaultAppGlobalState:c,suggestedParams:d,slopeChangeAtNewLockEndTime:null==f?void 0:f.slopeDelta}),m=[].concat(w(p),w(l)),e.abrupt("return",Boolean(p.length)&&Boolean(l.length)?Zs(p,l):m);case 28:case"end":return e.stop()}}),e,this)}))),function(e){return m.apply(this,arguments)})},{key:"generateWithdrawTransactions",value:(f=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t||this.userAddress,e.next=3,this.fetchAccountState();case 3:if(o=e.sent,i=r,o){e.next=7;break}throw new Error("There was an error while fetcing the account state");case 7:if(i){e.next=11;break}return e.next=10,this.algodClient.getTransactionParams().do();case 10:i=e.sent;case 11:if(u=li({accountState:o,network:this.network,sender:a,suggestedParams:i,client:this.algodClient}),!n){e.next=17;break}return e.next=15,H({client:this.algodClient,initiatorAddr:a,assetID:X[this.network]});case 15:c=e.sent,u=Zs([c[0].txn],u);case 17:return e.abrupt("return",u);case 18:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"fetchAccountState",value:function(){return function(e,t,n){return fo.apply(this,arguments)}(this.algodClient,Aa[this.network],this.userAddress)}},{key:"fetchStakingDistributionProposal",value:function(e){return function(e,t,n){return oi.apply(this,arguments)}(this.algodClient,Ia[this.network],e)}},{key:"generateCastVoteForStakingDistributionProposalTransactions",value:(d=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.proposalId,a=t.votes,o=t.assetIds,i=t.userAddress,u=t.suggestedParams,c=null!=i?i:this.userAddress,p=u,e.next=5,this.fetchStakingDistributionProposal(r);case 5:if(l=e.sent){e.next=8;break}throw new Error("There was an error while fetching staking distribution proposal");case 8:if(p){e.next=12;break}return e.next=11,this.algodClient.getTransactionParams().do();case 11:p=e.sent;case 12:return e.next=14,this.fetchAccountState();case 14:return d=e.sent,e.next=17,eo(this.algodClient,Ia[this.network]);case 17:return f=e.sent,e.next=20,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==d?void 0:d.powerCount)&&void 0!==n?n:null});case 20:if(m=e.sent,null!==(h=Po(m,l.creationTimestamp))){e.next=24;break}throw new Error("It is required to have an account power at the staking distribution proposal creation timestamp");case 24:return e.abrupt("return",ii({stakingVotingAppId:Ia[this.network],vaultAppId:Aa[this.network],sender:c,proposalId:r,proposal:l,votes:a,assetIds:o,accountPowerIndex:h,appBoxNames:f,suggestedParams:p,appCallNote:null}));case 25:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"fetchRewardsAppGlobalState",value:(l=i(s().mark((function t(){var n;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,Js(this.algodClient,va[this.network]);case 3:return n=t.sent,t.abrupt("return",new Ro(n.tiny_asset_id,n.vault_app_id,n.reward_history_count,n.first_period_timestamp,n.reward_period_count,e.encodeAddress(n.manager),e.encodeAddress(n.rewards_manager)));case 7:return t.prev=7,t.t0=t.catch(0),console.error(t.t0),t.abrupt("return",null);case 11:case"end":return t.stop()}}),t,this,[[0,7]])}))),function(){return l.apply(this,arguments)})},{key:"generateClaimRewardTransactions",value:(c=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.periodIndexStart,a=t.periodCount,o=t.userAddress,i=t.suggestedParams,u=t.shouldOptIntoTINY,c=null!=o?o:this.userAddress,p=i){e.next=7;break}return e.next=6,this.algodClient.getTransactionParams().do();case 6:p=e.sent;case 7:return e.next=9,this.fetchAccountState();case 9:return l=e.sent,e.next=12,this.fetchRewardsAppGlobalState();case 12:if(d=e.sent){e.next=15;break}throw new Error("There was an error while fetching rewards app global state");case 15:if(!(r+a>d.rewardPeriodCount)){e.next=17;break}throw new Error("The reward period index to be claimed cannot be larger than the latest reward period index");case 17:return e.next=19,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==l?void 0:l.powerCount)&&void 0!==n?n:null});case 19:for(f=e.sent,m=d.firstPeriodTimestamp+r*ga,h=d.firstPeriodTimestamp+(r+a)*ga,g=[],x=m;x=Math.floor(Date.now()/xa)||c.votingEndTimestamp<=Math.floor(Date.now()/xa))){e.next=23;break}throw new Error("Voting period is not active");case 23:return e.next=25,_o({algodClient:this.algodClient,address:i,appId:Aa[this.network],powerCount:p.powerCount});case 25:if(l=e.sent,null!==(d=Po(l,c.creationTimestamp))){e.next=29;break}throw new Error("Account power index not found");case 29:return f=Math.floor(c.index/(8*Ea)),m=ai(i,f),e.next=33,qs(this.algodClient,wa[this.network],m);case 33:return h=!e.sent,e.abrupt("return",Oo({proposalVotingAppId:wa[this.network],vaultAppId:Aa[this.network],sender:i,proposalId:n,proposal:c,vote:a,accountPowerIndex:d,createAttendanceSheetBox:h,suggestedParams:u}));case 35:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"fetchProposalVotingAppGlobalState",value:(r=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Js(this.algodClient,wa[this.network]);case 2:return t=e.sent,e.abrupt("return",new ro(t.vault_app_id,t.proposal_index_counter,t.voting_delay,t.voting_duration,t.proposal_threshold,t.proposal_threshold_numerator,t.quorum_threshold,t.approval_requirement,t.manager,t.proposal_manager));case 4:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getRequiredTinyPowerToCreateProposal",value:(n=i(s().mark((function e(t){var n,r,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==t){e.next=4;break}e.t0=t,e.next=7;break;case 4:return e.next=6,this.getTotalTinyPower();case 6:e.t0=e.sent;case 7:return n=e.t0,e.next=10,this.fetchProposalVotingAppGlobalState();case 10:return r=e.sent,a=r.proposalThreshold,r.proposalThresholdNumerator&&(a=Math.max(a,Math.floor(n*r.proposalThresholdNumerator/100)+1)),e.abrupt("return",a);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})}]),t}(),fi=2500,mi=400,hi=function(){function e(t,n){u(this,e),l(this,"data",null),this.name=t,this.structReference=n,this.size=n[t].size,this.fields=n[t].fields}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.size)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t;if(!this.data)throw new Error("Data is not initialized");var n=this.fields[e];if(!n)throw new Error("Field ".concat(e," does not exist in struct ").concat(this.name));var r=n.offset,a=n.offset+n.size,s=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(r,a);return Ii(n.type,this.structReference).apply(Buffer.from(s))}}]),e}(),gi=function(){function e(t,n){u(this,e),l(this,"data",null),this.struct=t,this.length=n}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.struct.size*this.length)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t,n=this.struct.size*e,r=n+this.struct.size,a=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(n,r);return this.struct.apply(a?Buffer.from(a):void 0)}}]),e}(),xi=function(){function e(){u(this,e)}return p(e,[{key:"apply",value:function(e){for(var t=BigInt(0),n=0;n2&&void 0!==arguments[2]?arguments[2]:Math.floor(Date.now()/1e3),a=(n=e,Math.floor(n*Ds/Ps)),s=t-r;return s<0?0:Ws(a,s)},exports.combineAndRegroupSignerTxns=function(){for(var t=arguments.length,n=new Array(t),r=0;r=e.minimum_required_balance},exports.intToBytes=Ba,exports.isAccountOptedIntoApp=function(e){var t=e.appID;return e.accountAppsLocalState.some((function(e){return e.id===t}))},exports.isSwapAssetInAmountLow=it,exports.isSwapQuoteErrorCausedByAmount=gt,exports.poolUtils=$t,exports.prepareCommitTransactions=function(e){return ha.apply(this,arguments)},exports.redeemAllExcessAsset=function(e){return $r.apply(this,arguments)},exports.redeemExcessAsset=function(e){return Kr.apply(this,arguments)},exports.sendAndWaitRawTransaction=Ie,exports.sumUpTxnFees=we,exports.tinymanContract_v1_1=wt,exports.tinymanContract_v2=Tt,exports.tinymanJSSDKConfig=_e; +"use strict";var e=require("algosdk"),t=require("base64-js"),n=require("crypto");function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0;--a){var s=this.tryEntries[a],o=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var i=n.call(s,"catchLoc"),u=n.call(s,"finallyLoc");if(i&&u){if(this.prev=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),k(n),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var a=r.arg;k(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:E(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function o(e,t,n,r,a,s,o){try{var i=e[s](o),u=i.value}catch(e){return void n(e)}i.done?t(u):Promise.resolve(u).then(r,a)}function i(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var s=e.apply(t,n);function i(e){o(s,r,a,i,u,"next",e)}function u(e){o(s,r,a,i,u,"throw",e)}i(void 0)}))}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f: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,o=!0,i=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){i=!0,s=e},f:function(){try{o||null==n.return||n.return()}finally{if(i)throw s}}}}function k(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var _=function(e){return e.SwapRouterStaleDataError="SwapRouterStaleDataError",e.SwapRouterNoRouteError="SwapRouterNoRouteError",e.SwapRouterLowSwapAmountError="SwapRouterLowSwapAmountError",e.SwapRouterInsufficientReservesError="SwapRouterInsufficientReservesError",e.SwapRouterPoolHasNoLiquidityError="SwapRouterPoolHasNoLiquidityError",e.NoAvailablePoolError="NoAvailablePoolError",e.OutputAmountExceedsAvailableLiquidityError="OutputAmountExceedsAvailableLiquidityError",e.UnknownError="UnknownError",e.LowSwapAmountError="LowSwapAmountError",e.AssetDoesNotBelongToPoolError="AssetDoesNotBelongToPoolError",e.InvalidSwapTypeError="InvalidSwapTypeError",e}({}),E=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;return u(this,n),(a=t.call(this,r)).type=e,a.message=r,Error.captureStackTrace&&Error.captureStackTrace(A(a),n),a}return p(n)}(),P=Uint8Array.from([1]),S=1e5,D=1e5,O=1e5,N=1e5,B=1e5,C=5e4,F=28500,L=1e3,R=1e3,M={mainnet:{base:"https://mainnet.analytics.tinyman.org/api",v1:"https://mainnet.analytics.tinyman.org/api/v1"},testnet:{base:"https://testnet.analytics.tinyman.org/api",v1:"https://testnet.analytics.tinyman.org/api/v1"}},U={V1_1:"v1_1",V2:"v2"},j=0,V={id:"".concat(j),name:"Algorand",unit_name:"ALGO",decimals:6,url:"https://algorand.org",is_liquidity_token:!1,total_amount:"6615503326932151",clawback_address:""},G={V1:"TM1POOL",V1_1:"TMPOOL11",V2:"TMPOOL2"},X={testnet:258703304,mainnet:22e8},q={testnet:724519992,mainnet:2537013734},Q={testnet:724676936,mainnet:2537023208},W="- would result negative",z="logic eval error:",J="exceeds schema integer count",K=/transaction \w+:/,Y=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;u(this,n);for(var s=arguments.length,o=new Array(s>2?s-2:0),i=2;ir?[a(a({},e),{},{id:n}),a(a({},t),{},{id:r})]:[a(a({},t),{},{id:r}),a(a({},e),{},{id:n})]}function ee(e,t){var n=[e,t];return[Math.max.apply(Math,n),Math.min.apply(Math,n)]}function te(e){return Number(e)===j}function ne(e){return Number(e.id)}function re(e){var t,n=e.stateArray,r=void 0===n?[]:n,a=e.shouldDecodeKeys,s=void 0!==a&&a,o={},i=T(r);try{for(i.s();!(t=i.n()).done;){var u=t.value,c=u.key,p=void 0;if(1==u.value.type)p=u.value.bytes;else{if(2!=u.value.type)throw new Error("Unexpected state type: ".concat(u.value.type));p=u.value.uint}o[s?atob(c):c]=p}}catch(e){i.e(e)}finally{i.f()}return o}function ae(e){var t,n=e.reduce((function(e,t){return e+t.length}),0),r=new Uint8Array(n),a=0,s=T(e);try{for(s.s();!(t=s.n()).done;){var o=t.value;r.set(o,a),a+=o.length}}catch(e){s.e(e)}finally{s.f()}return r}var se=100000n,oe=100000n,ie=100000n,ue=25000n+25000n,ce=25000n+3500n;function pe(e){var t=e["apps-total-schema"],n=0n,r=0n;t&&(t["num-byte-slice"]&&(n=t["num-byte-slice"]),t["num-uint"]&&(r=t["num-uint"]));var a=e["apps-local-state"]||[],s=e["created-apps"]||[],o=e.assets||[];return se+oe*BigInt(o.length)+ie*BigInt(s.length+a.length)+ce*r+ue*n}function le(e){return new Promise((function(t){setTimeout((function(){t(null)}),e)}))}function de(e,t){return fe.apply(this,arguments)}function fe(){return(fe=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=3,le(1e3);case 3:return r=null,e.prev=4,e.next=7,t.pendingTransactionInformation(n).do();case 7:r=e.sent,e.next=12;break;case 10:e.prev=10,e.t0=e.catch(4);case 12:if(!r){e.next=17;break}if(!r["confirmed-round"]){e.next=15;break}return e.abrupt("return",r);case 15:if(!r["pool-error"]){e.next=17;break}throw new Error("Transaction Rejected: ".concat(r["pool-error"]));case 17:e.next=0;break;case 19:case"end":return e.stop()}}),e,null,[[4,10]])})))).apply(this,arguments)}function me(e,t,n){if(t>1||t<0)throw new Error("Invalid slippage value. Must be between 0 and 1, got ".concat(t));var r;try{var a="negative"===e?1-t:1+t;r=BigInt(Math.floor(Number(n)*a))}catch(e){throw new Error(e.message)}return r}function he(e,t){var n=Number(e);return ge({decimalPlaces:n},Math.pow(10,-n)*Number(t))}function ge(e,t){var n=e.decimalPlaces,r=void 0===n?0:n;if(r>0){var a=v(Ae(t),2),s=a[0],o=a[1],i=v(Ae(Math.round(Number(xe(s,o+r)))),2),u=i[0],c=i[1];return Number(xe(u,c-r))}return Math.round(t)}function xe(e,t){return e+(t<0?"e".concat(t):"e+".concat(t))}function Ae(e){if(e.toString().includes("e")){var t=e.toString().split("e");return[parseFloat(t[0]),parseFloat(t[1])]}return[e,0]}function Ie(e,t){return ve.apply(this,arguments)}function ve(){return(ve=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,r=[],a=T(n),e.prev=3,a.s();case 5:if((o=a.n()).done){e.next=18;break}return i=o.value,e.next=9,t.sendRawTransaction(i).do();case 9:return u=e.sent,c=u.txId,e.next=13,de(t,c);case 13:p=e.sent,l=p["confirmed-round"],r.push({confirmedRound:l,txnID:c});case 16:e.next=5;break;case 18:e.next=23;break;case 20:e.prev=20,e.t0=e.catch(3),a.e(e.t0);case 23:return e.prev=23,a.f(),e.finish(23);case 26:return e.abrupt("return",r);case 29:throw e.prev=29,e.t1=e.catch(0),new Y(e.t1,"We encountered an error while processing this transaction. Try again later.");case 32:case"end":return e.stop()}}),e,null,[[0,29],[3,20,23,26]])})))).apply(this,arguments)}function we(e){return e.reduce((function(e,t){return e+t.txn.fee}),0)}function ye(e){return(t=e[0].txn.group)?Buffer.from(t).toString("base64"):"";var t}function be(e){for(var t=[];;){var n=Number(e&BigInt(127));if(!(e>>=BigInt(7))){t.push(n);break}t.push(128|n)}return t}function Te(e){return(new TextEncoder).encode(e)}var ke,_e=new(function(){function e(){u(this,e),this.clientName="tinyman-js-sdk"}return p(e,[{key:"getClientName",value:function(){return this.clientName}},{key:"setClientName",value:function(e){this.clientName=e}},{key:"getAppCallTxnNoteWithClientName",value:function(e,t){var n=e===U.V1_1?"v1":e,r=JSON.stringify(a({origin:this.clientName},t));return Te("tinyman/".concat(n,":j").concat(r))}}]),e}()),Ee=(l(ke={},U.V1_1,{testnet:62368684,mainnet:552635992}),l(ke,U.V2,{testnet:148607e3,mainnet:1002541853}),ke);function Pe(e,t){var n=Ee[t][e];if(!n)throw new Error("No Validator App exists for ".concat(e," network with ").concat(t," contract version"));return n}function Se(){return(Se=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationOptInTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function De(){return(De=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationClearStateTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var Oe,Ne,Be,Ce=function(e){return e.FixedInput="fixed-input",e.FixedOutput="fixed-output",e}({}),Fe=.003,Le=function(e){return e[e.INPUT_TXN=0]="INPUT_TXN",e[e.APP_CALL_TXN=1]="APP_CALL_TXN",e}({}),Re=(l(Oe={},Ce.FixedInput,1),l(Oe,Ce.FixedOutput,2),Oe),Me=2,Ue=Te("swap"),je=(l(Ne={},Ce.FixedInput,Te("fixed-input")),l(Ne,Ce.FixedOutput,Te("fixed-output")),Ne),Ve={ASSET_OPT_IN:Te("asset_opt_in")},Ge={testnet:184778019,mainnet:1083651166},Xe=(l(Be={},Ce.FixedInput,7),l(Be,Ce.FixedOutput,8),Be);function qe(e){var t=Je(e),n=t.assetIn,r=t.assetOut;return he(r.asset.decimals,Number(r.amount))/he(n.asset.decimals,Number(n.amount))}function Qe(e){var t=Ge[e];if(!t)throw new Error("Unknown network or network not supported: ".concat(e));return t}function We(e){return e[e.length-1].quote.amount_out}function ze(e){return e[0].quote.amount_in}function Je(e){return{assetIn:ze(e),assetOut:We(e)}}function Ke(e){return Ye.apply(this,arguments)}function Ye(){return(Ye=i(s().mark((function t(n){var r,a,o,i,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.routerAppID,o=n.assetIDs,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a,appArgs:[Ve.ASSET_OPT_IN],foreignAssets:o,suggestedParams:u}),p=o.length,c.fee=e.ALGORAND_MIN_TX_FEE*(p+1),t.abrupt("return",c);case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function He(e){return $e.apply(this,arguments)}function $e(){return($e=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k,_,E,P,S,D;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.initiatorAddr,a=n.client,o=n.network,i=n.swapType,u=n.route,c=n.slippage,t.next=3,a.getTransactionParams().do();case 3:return p=t.sent,l=[ne(u[0].quote.amount_in.asset),ne(u[0].quote.amount_out.asset),ne(u[1].quote.amount_out.asset)],d=l[0],f=l[1],m=l[2],h=[Number(ze(u).amount),Number(We(u).amount)],g=h[0],x=h[1],A=[u[0].pool.address,u[1].pool.address],I=A[0],v=A[1],w=i===Ce.FixedInput?g:me("positive",c,g),y=i===Ce.FixedOutput?x:me("negative",c,x),b=te(d),T=Qe(o),k=b?e.makePaymentTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,suggestedParams:p}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,assetIndex:d,suggestedParams:p}),(_=e.makeApplicationNoOpTxnFromObject({from:r,appIndex:T,appArgs:[Ue,je[i],e.encodeUint64(y)],foreignApps:[Pe(o,U.V2)],foreignAssets:[d,f,m],accounts:[I,v],suggestedParams:p,note:_e.getAppCallTxnNoteWithClientName(U.V2)})).fee=e.ALGORAND_MIN_TX_FEE*(Xe[i]+1),E=[k,_],t.next=17,Ze({client:a,network:o,assetIDs:[d,f,m]});case 17:if(!((P=t.sent).length>0)){t.next=23;break}return t.next=21,Ke({client:a,initiatorAddr:r,assetIDs:P,routerAppID:T});case 21:S=t.sent,E.unshift(S);case 23:return D=e.assignGroupID(E),t.abrupt("return",D.map((function(e){return{txn:e,signers:[r]}})));case 25:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Ze(e){return et.apply(this,arguments)}function et(){return(et=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(Qe(a)),t.next=4,r.accountInformation(i).do();case 4:return u=t.sent,c=u.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!c.includes(e)})));case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function tt(e){return nt.apply(this,arguments)}function nt(){return(nt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetInID,a=t.assetOutID,o=t.swapType,i=t.network,u={asset_in_id:String(r),asset_out_id:String(a),swap_type:o,amount:String(n)},e.next=4,fetch("".concat(M[i].v1,"/swap-router/quotes/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}).catch((function(){throw new Error("Network error")}));case 4:return c=e.sent,e.next=7,c.json();case 7:if(p=e.sent,c.ok){e.next=14;break}if(s=p,!Boolean(s)||void 0===s.fallback_message){e.next=13;break}throw new E(p.type,p.fallback_message);case 13:throw new E(_.UnknownError,"There was an error while getting a quote from Swap Router");case 14:if(!(p.route.length<2)){e.next=16;break}throw new E(_.SwapRouterNoRouteError,"Swap router couldn't find a route for this swap.");case 16:return e.abrupt("return",p);case 17:case"end":return e.stop()}var s}),e)})))).apply(this,arguments)}var rt=function(e){return e.Direct="direct",e.Router="router",e}({}),at=4*e.ALGORAND_MIN_TX_FEE;function st(t){return(Re[t]+Me)*e.ALGORAND_MIN_TX_FEE}function ot(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Fe;return Math.ceil(1/e)}function it(e){return e1&&void 0!==arguments[1]?arguments[1]:Fe)}function ut(t){return(Re[t]+1)*e.ALGORAND_MIN_TX_FEE}function ct(e){var t=e.assetIn,n=e.assetOut;return he(n.decimals,Number(n.amount))/he(t.decimals,Number(t.amount))}function pt(e){var t=e.inputSupply,n=e.outputSupply,r=e.assetIn,a=e.assetOut,s=ct({assetIn:r,assetOut:a}),o=he(a.decimals,Number(n))/he(r.decimals,Number(t));return ge({decimalPlaces:5},Math.abs(s/o-1))}function lt(e){if(e.type===rt.Router){var t=ze(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetInID,amount:e.data.quote.assetInAmount}}function dt(e){if(e.type===rt.Router){var t=We(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetOutID,amount:e.data.quote.assetOutAmount}}function ft(e){return e.type===rt.Direct?e.data.pool.contractVersion:U.V2}function mt(e){return e.type===rt.Direct?e.data.quote.rate:qe(e.data.route)}function ht(e){for(var t=e[0],n=mt(t),r=1;rn&&(t=a,n=s)}return t}function gt(e){return e instanceof E&&[_.SwapRouterInsufficientReservesError,_.SwapRouterLowSwapAmountError,_.OutputAmountExceedsAvailableLiquidityError,_.LowSwapAmountError].includes(e.type)}var xt={type:"logicsig",logic:{bytecode:"BCAIAQCBgICAgICAgPABgICAgICAgIDwAQMEBQYlJA1EMQkyAxJEMRUyAxJEMSAyAxJEMgQiDUQzAQAxABJEMwEQIQcSRDMBGIGCgICAgICAgPABEkQzARkiEjMBGyEEEhA3ARoAgAlib290c3RyYXASEEAAXDMBGSMSRDMBG4ECEjcBGgCABHN3YXASEEACOzMBGyISRDcBGgCABG1pbnQSQAE7NwEaAIAEYnVybhJAAZg3ARoAgAZyZWRlZW0SQAJbNwEaAIAEZmVlcxJAAnkAIQYhBSQjEk0yBBJENwEaARclEjcBGgIXJBIQRDMCADEAEkQzAhAhBBJEMwIhIxJEMwIiIxwSRDMCIyEHEkQzAiQjEkQzAiWACFRNUE9PTDExEkQzAiZRAA+AD1RpbnltYW5Qb29sMS4xIBJEMwIngBNodHRwczovL3RpbnltYW4ub3JnEkQzAikyAxJEMwIqMgMSRDMCKzIDEkQzAiwyAxJEMwMAMQASRDMDECEFEkQzAxElEkQzAxQxABJEMwMSIxJEJCMTQAAQMwEBMwIBCDMDAQg1AUIBsTMEADEAEkQzBBAhBRJEMwQRJBJEMwQUMQASRDMEEiMSRDMBATMCAQgzAwEIMwQBCDUBQgF8MgQhBhJENwEcATEAE0Q3ARwBMwQUEkQzAgAxABNEMwIUMQASRDMDADMCABJEMwIRJRJEMwMUMwMHMwMQIhJNMQASRDMDESMzAxAiEk0kEkQzBAAxABJEMwQUMwIAEkQzAQEzBAEINQFCAREyBCEGEkQ3ARwBMQATRDcBHAEzAhQSRDMDFDMDBzMDECISTTcBHAESRDMCADEAEkQzAhQzBAASRDMCESUSRDMDADEAEkQzAxQzAwczAxAiEk0zBAASRDMDESMzAxAiEk0kEkQzBAAxABNEMwQUMQASRDMBATMCAQgzAwEINQFCAJAyBCEFEkQ3ARwBMQATRDMCADcBHAESRDMCADEAE0QzAwAxABJEMwIUMwIHMwIQIhJNMQASRDMDFDMDBzMDECISTTMCABJEMwEBMwMBCDUBQgA+MgQhBBJENwEcATEAE0QzAhQzAgczAhAiEk03ARwBEkQzAQEzAgEINQFCABIyBCEEEkQzAQEzAgEINQFCAAAzAAAxABNEMwAHMQASRDMACDQBD0M=",address:"ABUKAXTANWR6K6ZYV75DWJEPVWWOU6SFUVRI6QHO44E4SIDLHBTD2CZ64A",size:881,variables:[{name:"TMPL_ASSET_ID_1",type:"int",index:15,length:10},{name:"TMPL_ASSET_ID_2",type:"int",index:5,length:10},{name:"TMPL_VALIDATOR_APP_ID",type:"int",index:74,length:10}],source:"https://github.com/tinymanorg/tinyman-contracts-v1/tree/dc9ab40c58b85c15d58f63a1507e18be76720dbb/contracts/pool_logicsig.teal.tmpl"},name:"pool_logicsig"},At={type:"app",global_state_schema:{num_uints:0,num_byte_slices:0},local_state_schema:{num_uints:16,num_byte_slices:0},name:"validator_app"},It=p((function e(t){u(this,e),this.schema={numLocalInts:t.local_state_schema.num_uints,numLocalByteSlices:t.local_state_schema.num_byte_slices,numGlobalInts:t.global_state_schema.num_uints,numGlobalByteSlices:t.global_state_schema.num_byte_slices}})),vt=function(n){d(a,It);var r=I(a);function a(e,t){var n;return u(this,a),(n=r.call(this,e)).poolLogicSigContractTemplate=t.logic.bytecode,n.templateVariables=t.logic.variables,n}return p(a,[{key:"generateLogicSigAccountForPool",value:function(n){if(n.asset1ID===n.asset2ID)throw new Error("Assets are the same");var r=Pe(n.network,U.V1_1),a=v(ee(n.asset1ID,n.asset2ID),2),s=a[0],o=a[1],i=Array.from(t.toByteArray(this.poolLogicSigContractTemplate)),u={asset_id_1:s,asset_id_2:o,validator_app_id:r},c=0;this.templateVariables.sort((function(e,t){return e.index-t.index}));for(var p=0;p2&&void 0!==arguments[2]?arguments[2]:e.IntDecoding.DEFAULT;return new Promise(function(){var e=i(s().mark((function e(o,i){var u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.accountInformation(n).setIntDecoding(r).do();case 3:u=e.sent,o(a(a({},u),{},{minimum_required_balance:Pt(u)})),e.next=10;break;case 7:e.prev=7,e.t0=e.catch(0),i(new Error(e.t0.message||"Failed to fetch account information"));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}())}function Et(e,t){var n=e["apps-local-state"].find((function(e){return e.id===t}));return n?re({stateArray:n["key-value"],shouldDecodeKeys:!0}):null}function Pt(e){var t=e["apps-total-schema"];return S+D*(e.assets||[]).length+N*(e["created-apps"]||[]).length+O*(e["apps-local-state"]||[]).length+C*Number(t&&t["num-byte-slice"]||0)+F*Number(t&&t["num-uint"]||0)+B*(e["apps-total-extra-pages"]||0)}var St=Te("e");function Dt(e){return Ot.apply(this,arguments)}function Ot(){return(Ot=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,k,_;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.pool,i=r.accountAddr,n.next=3,a.accountInformation(i).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:u=n.sent,c=u["apps-local-state"]||[],p=0n,l=0n,d=0n,f=o.account.address(),m=T(c),n.prev=10,m.s();case 12:if((h=m.n()).done){n.next=31;break}if((g=h.value).id==o.validatorAppID){n.next=16;break}return n.abrupt("continue",29);case 16:if(x=g["key-value"]){n.next=19;break}return n.abrupt("break",31);case 19:A=re({stateArray:x}),I=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset1ID)])),v=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset2ID)])),w=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.poolTokenID)])),y=A[I],b=A[v],k=A[w],"bigint"==typeof y&&(p=y),"bigint"==typeof b&&(l=b),"bigint"==typeof k&&(d=k);case 29:n.next=12;break;case 31:n.next=36;break;case 33:n.prev=33,n.t0=n.catch(10),m.e(n.t0);case 36:return n.prev=36,m.f(),n.finish(36);case 39:if(!((_={excessAsset1:p,excessAsset2:l,excessPoolTokens:d}).excessAsset1<0n||_.excessAsset2<0n||_.excessPoolTokens<0n)){n.next=42;break}throw new Error("Invalid account excess: ".concat(_));case 42:return n.abrupt("return",_);case 43:case"end":return n.stop()}}),n,null,[[10,33,36,39]])})))).apply(this,arguments)}function Nt(){return(Nt=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.accountAddr,i=r.validatorAppID,n.next=3,a.accountInformation(o).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:if(u=n.sent,c=u["apps-local-state"]||[],p=c.find((function(e){return e.id==i})),l=[],p&&p["key-value"])for(d=re({stateArray:p["key-value"]}),f=0,m=Object.entries(d);fMt)){n.next=48;break}throw new Error("Issued liquidity value is out of the expected range ([0n, ".concat(Mt,"]): ").concat(N.issuedLiquidity));case 48:return n.abrupt("return",N);case 49:case"end":return n.stop()}}),n,null,[[8,31,34,37]])})))).apply(this,arguments)}function Gt(){return Gt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.address,a=t.network,!(o=d.length>1&&void 0!==d[1]?d[1]:{})[r]){e.next=4;break}return e.abrupt("return",o[r]);case 4:return e.next=6,_t(n,r);case 6:return i=e.sent,u=Et(i,Pe(a,U.V1_1)),c=null,u&&(l=i["created-assets"][0],p=l.index,c={asset1ID:u[Ft[U.V1_1].asset1],asset2ID:u[Ft[U.V1_1].asset2],poolTokenID:p},o[r]=c),e.abrupt("return",c);case 11:case"end":return e.stop()}}),e)}))),Gt.apply(this,arguments)}var Xt=Object.freeze({__proto__:null,getPoolAssets:function(e){return Gt.apply(this,arguments)},getPoolInfo:Ut,getPoolReserves:function(e,t){return Vt.apply(this,arguments)}});function qt(e){return Qt.apply(this,arguments)}function Qt(){return(Qt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.asset1ID,o=t.asset2ID,i=kt(U.V2),u=i.generateLogicSigAccountForPool(t),c=Pe(r,U.V2),p=u.address(),l=ee(a,o),e.next=8,_t(n,p);case 8:return d=e.sent,f=Et(d,c),m={account:u,validatorAppID:c,asset1ID:l[0],asset2ID:l[1],status:f?Ct.READY:Ct.NOT_CREATED,contractVersion:U.V2},f&&(m.asset1ProtocolFees=BigInt(f[Ft.v2.asset1ProtocolFees]),m.asset2ProtocolFees=BigInt(f[Ft.v2.asset2ProtocolFees]),m.asset1Reserves=BigInt(f[Ft.v2.asset1Reserves]),m.asset2Reserves=BigInt(f[Ft.v2.asset2Reserves]),m.issuedPoolTokens=BigInt(f[Ft.v2.issuedPoolTokens]),m.cumulativePriceUpdateTimeStamp=Number(f[Ft.v2.cumulativePriceUpdateTimeStamp]),m.protocolFeeRatio=Number(f[Ft.v2.protocolFeeRatio]),m.totalFeeShare=BigInt(f[Ft.v2.totalFeeShare]),m.poolTokenID=Number(f[Ft.v2.poolTokenID]),m.asset1ID=Number(f[Ft.v2.asset1]),m.asset2ID=Number(f[Ft.v2.asset2])),e.abrupt("return",m);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Wt(){return(Wt=i(s().mark((function e(t,n){var r,a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_t(t,n.account.address());case 2:return r=e.sent,a=Et(r,n.validatorAppID),o={asset1:0n,asset2:0n,issuedLiquidity:0n,round:r.round},a&&(o.asset1=BigInt(a[Ft.v2.asset1Reserves]),o.asset2=BigInt(a[Ft.v2.asset2Reserves]),o.issuedLiquidity=BigInt(a[Ft.v2.issuedPoolTokens])),e.abrupt("return",o);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zt(){return(zt=i(s().mark((function e(t){var n,r,a,o,i,u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.address,a=t.network,e.next=3,_t(n,r);case 3:return o=e.sent,i=Et(o,Pe(a,U.V2)),u=null,i&&(u={asset1ID:i[Ft[U.V2].asset1],asset2ID:i[Ft[U.V2].asset2],poolTokenID:i[Ft[U.V2].poolTokenID]}),e.abrupt("return",u);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jt=Object.freeze({__proto__:null,getPoolAssets:function(e){return zt.apply(this,arguments)},getPoolInfo:qt,getPoolReserves:function(e,t){return Wt.apply(this,arguments)}});function Kt(e){return Boolean(e&&!(e.asset1+e.asset2))}var Yt,Ht=Object.freeze({__proto__:null,getPoolPairRatio:function(e){var t=Kt(e),n=null;return e&&!t&&e.asset1&&e.asset2&&(n=Number(e.asset1)/Number(e.asset2)),n},getPoolShare:function(e,t){var n=Number(t)/Number(e);return Number.isFinite(n)||(n=0),n},getPoolsForPair:function(e){return Promise.all([Ut(e),qt(e)])},isPoolEmpty:Kt,isPoolNotCreated:function(e){return(null==e?void 0:e.status)===Ct.NOT_CREATED},isPoolReady:function(e){return(null==e?void 0:e.status)===Ct.READY}}),$t=a((l(Yt={},U.V1_1,a(a({},Xt),Ht)),l(Yt,U.V2,a(a({},Jt),Ht)),Yt),Ht),Zt=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e[e.POOL_TOKEN_CREATE=2]="POOL_TOKEN_CREATE",e[e.ASSET1_OPT_IN=3]="ASSET1_OPT_IN",e[e.ASSET2_OPT_IN=4]="ASSET2_OPT_IN",e}({}),en={ASA_ALGO:96e4,ASA_ASA:859e3};function tn(){return(tn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T,k,_,E,P,S;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Z(o,i),l=v(p,2),d=l[0],f=d.id,m=d.unit_name,h=l[1],g=h.id,x=h.unit_name,A=te(g),I=Pe(a,U.V1_1),w=wt.generateLogicSigAccountForPool({network:a,asset1ID:f,asset2ID:g}),y=w.address(),b=e.makeApplicationOptInTxnFromObject({from:y,appIndex:I,note:_e.getAppCallTxnNoteWithClientName(U.V1_1),appArgs:[Te("bootstrap"),e.encodeUint64(f),e.encodeUint64(g)],foreignAssets:A?[f]:[g],suggestedParams:c}),T=e.makeAssetCreateTxnWithSuggestedParamsFromObject({from:y,total:0xffffffffffffffffn,decimals:6,defaultFrozen:!1,unitName:G.V1_1,assetName:"TinymanPool1.1 ".concat(m,"-").concat(x),assetURL:"https://tinyman.org",suggestedParams:c}),k=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:f,amount:0,suggestedParams:c}),_=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:y,amount:nn(A),suggestedParams:c}),(E=[])[Zt.FUNDING_TXN]=_,E[Zt.VALIDATOR_APP_CALL]=b,E[Zt.POOL_TOKEN_CREATE]=T,E[Zt.ASSET1_OPT_IN]=k,A||(E[Zt.ASSET2_OPT_IN]=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:g,amount:0,suggestedParams:c})),P=e.assignGroupID(E),S=[{txn:P[Zt.FUNDING_TXN],signers:[u]},{txn:P[Zt.VALIDATOR_APP_CALL],signers:[y]},{txn:P[Zt.POOL_TOKEN_CREATE],signers:[y]},{txn:P[Zt.ASSET1_OPT_IN],signers:[y]}],P[Zt.ASSET2_OPT_IN]&&S.push({txn:P[Zt.ASSET2_OPT_IN],signers:[y]}),t.abrupt("return",S);case 23:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function nn(e){return e?en.ASA_ALGO:en.ASA_ASA}function rn(){return(rn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=wt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===Zt.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function an(e){return sn.apply(this,arguments)}function sn(){return(sn=i(s().mark((function e(t){var n,r,a,o,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.signedTxns,a=t.txnIDs,e.prev=1,e.next=4,n.sendRawTransaction(r).do();case 4:return e.next=6,de(n,a[Zt.POOL_TOKEN_CREATE]);case 6:if(o=e.sent,"number"==typeof(i=o["asset-index"])){e.next=10;break}throw new Error("Generated ID is not valid: got ".concat(i));case 10:return e.abrupt("return",{poolTokenID:i});case 13:throw e.prev=13,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while bootstraping the pool. Try again later.");case 16:case"end":return e.stop()}}),e,null,[[1,13]])})))).apply(this,arguments)}function on(){return(on=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.signedTxns,c=t.txnIDs,e.next=3,an({client:n,signedTxns:u,txnIDs:c});case 3:return e.abrupt("return",$t.v1_1.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var un={generateTxns:function(e){return tn.apply(this,arguments)},signTxns:function(e){return rn.apply(this,arguments)},execute:function(e){return on.apply(this,arguments)},getBootstrapFundingTxnAmount:nn};var cn=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e}({}),pn={ASA_ALGO:5,ASA_ASA:6};function ln(e,t){return dn.apply(this,arguments)}function dn(){return(dn=i(s().mark((function t(n,r){var a,o,i;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(o=null===(a=r.find((function(e){return"appl"===e.txn.type})))||void 0===a?void 0:a.txn.txID())){t.next=7;break}return t.next=4,e.waitForConfirmation(n,o,R);case 4:t.t0=t.sent,t.next=8;break;case 7:t.t0=void 0;case 8:return i=t.t0,t.abrupt("return",i);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function fn(e,t){return mn.apply(this,arguments)}function mn(){return(mn=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ln(t,n);case 2:return r=e.sent,e.abrupt("return",null==r?void 0:r["inner-txns"]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function hn(e,t){return gn.apply(this,arguments)}function gn(){return(gn=i(s().mark((function t(n,r){var a,o;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fn(n,r);case 2:return a=t.sent,s=r[0].txn,o=e.encodeAddress(s.from.publicKey),t.abrupt("return",null==a?void 0:a.reduce((function(t,n){var r=t,a=n.txn.txn;return a.type===e.TransactionType.axfer&&e.encodeAddress(a.arcv)===o?r.push({id:a.xaid,amount:a.aamt}):a.type===e.TransactionType.pay&&e.encodeAddress(a.rcv)===o&&r.push({id:j,amount:a.amt}),r}),[]));case 5:case"end":return t.stop()}var s}),t)})))).apply(this,arguments)}function xn(){return(xn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Pe(a,U.V2),l=e.getApplicationAddress(p),d=Z(o,i),f=v(d,2),m=f[0].id,h=f[1].id,t.next=9,$t.v2.getPoolInfo({client:r,network:a,asset1ID:m,asset2ID:h});case 9:if(t.sent.status!==Ct.READY){t.next=12;break}throw new Error("Pool for ".concat(o.unit_name,"-").concat(i.unit_name," already exists"));case 12:return g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=g.address(),A=te(h),(I=e.makeApplicationOptInTxnFromObject({from:x,appIndex:p,appArgs:[Te("bootstrap")],note:_e.getAppCallTxnNoteWithClientName(U.V2),foreignAssets:[m,h],rekeyTo:l,suggestedParams:c})).fee=In(A),w=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:x,amount:An(A),suggestedParams:c}),(y=[])[cn.FUNDING_TXN]=w,y[cn.VALIDATOR_APP_CALL]=I,b=e.assignGroupID(y),(T=[])[cn.FUNDING_TXN]={txn:b[cn.FUNDING_TXN],signers:[u]},T[cn.VALIDATOR_APP_CALL]={txn:b[cn.VALIDATOR_APP_CALL],signers:[x]},t.abrupt("return",T);case 26:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function An(e){return function(e,t){var n=kt(e).schema,r=n.numLocalInts,a=n.numLocalByteSlices,s=S+D+D+O+F*r+C*a;return t||(s+=D),s}(U.V2,e)+In(e)+D}function In(t){return((t?pn.ASA_ALGO:pn.ASA_ASA)+1)*e.ALGORAND_MIN_TX_FEE}function vn(){return(vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===cn.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function wn(){return(wn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.txGroup,c=t.signedTxns,e.prev=1,e.next=4,n.sendRawTransaction(c).do();case 4:return e.next=6,ln(n,u);case 6:if(e.t1=p=e.sent,e.t0=null===e.t1,e.t0){e.next=10;break}e.t0=void 0===p;case 10:if(!e.t0){e.next=14;break}e.t2=void 0,e.next=15;break;case 14:e.t2=null===(l=p["local-state-delta"][0].delta)||void 0===l||null===(d=l.find((function(e){return e.key===btoa(Ft.v2.poolTokenID)})))||void 0===d?void 0:d.value.uint;case 15:if("number"==typeof(f=e.t2)){e.next=18;break}throw new Error("Generated ID is not valid: got ".concat(f));case 18:return e.abrupt("return",$t.v2.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 21:throw e.prev=21,e.t3=e.catch(1),new Y(e.t3,"We encountered something unexpected while bootstraping the pool. Try again later.");case 24:case"end":return e.stop()}}),e,null,[[1,21]])})))).apply(this,arguments)}var yn,bn={generateTxns:function(e){return xn.apply(this,arguments)},signTxns:function(e){return vn.apply(this,arguments)},execute:function(e){return wn.apply(this,arguments)},getBootstrapFundingTxnAmount:An,getTotalCost:function(t){return e.ALGORAND_MIN_TX_FEE+An(t)}};var Tn,kn,_n,En,Pn=(l(yn={},U.V1_1,un),l(yn,U.V2,bn),l(yn,"generateTxns",(function(e){return e.contractVersion===U.V1_1?un.generateTxns(e):bn.generateTxns(e)})),l(yn,"signTxns",(function(e){return e.contractVersion===U.V1_1?un.signTxns(e):bn.signTxns(e)})),l(yn,"execute",(function(e){return e.contractVersion===U.V1_1?un.execute(e):bn.execute(e)})),l(yn,"calculateBootstrapFundingTxnAmount",(function(e){var t=e.contractVersion,n=e.isAlgoPool;return t===U.V1_1?un.getBootstrapFundingTxnAmount(n):bn.getBootstrapFundingTxnAmount(n)})),yn),Sn=function(e){return e[e.FEE_TXN=0]="FEE_TXN",e[e.VALIDATOR_APP_CALL_TXN=1]="VALIDATOR_APP_CALL_TXN",e[e.ASSET1_IN_TXN=2]="ASSET1_IN_TXN",e[e.ASSET2_IN_TXN=3]="ASSET2_IN_TXN",e[e.LIQUDITY_OUT_TXN=4]="LIQUDITY_OUT_TXN",e}({}),Dn=5*e.ALGORAND_MIN_TX_FEE,On=function(e){return e.SINGLE="single",e.FLEXIBLE="flexible",e.INITIAL="initial",e}({}),Nn=(l(Tn={},On.FLEXIBLE,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),l(Tn,On.SINGLE,{ASSET_IN_TXN:0,VALIDATOR_APP_CALL_TXN:1}),l(Tn,On.INITIAL,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),Tn),Bn=(l(kn={},On.INITIAL,1),l(kn,On.SINGLE,2),l(kn,On.FLEXIBLE,2),kn),Cn=(l(_n={},On.INITIAL,3),l(_n,On.FLEXIBLE,3),l(_n,On.SINGLE,2),_n);function Fn(e){var t,n,r,a=e.reserves,s=e.totalFeeShare,o=e.asset1,i=e.asset2,u=a.asset1*a.asset2,c=a.asset1+BigInt(o.amount),p=a.asset2+BigInt(i.amount),l=c*p,d=BigInt(parseInt(String(Math.sqrt(Number(l*a.issuedLiquidity*a.issuedLiquidity/u))))),f=d-a.issuedLiquidity,m=f*c/d,h=f*p/d,g=BigInt(o.amount)-m,x=BigInt(i.amount)-h;if(g>x){var A=g;r=Rn(A,s),t={id:o.id,amount:A+r,decimals:o.decimals,reserves:a.asset1},n={id:i.id,amount:BigInt(Math.abs(Math.min(Number(x),0))),decimals:i.decimals,reserves:a.asset2},f-=r*d/(c*BigInt(2))}else{var I=x;r=Rn(I,s),t={id:i.id,amount:I+r,decimals:i.decimals,reserves:a.asset2},n={id:o.id,amount:BigInt(Math.abs(Math.min(Number(g),0))),decimals:o.decimals,reserves:a.asset1},f-=r*d/(p*BigInt(2))}return{poolTokenOutAmount:f,internalSwapQuote:{assetIn:t,assetOut:n,swapFees:r,priceImpact:pt({inputSupply:t.reserves,outputSupply:n.reserves,assetIn:t,assetOut:n})}}}function Ln(e,t){if(!e.amount||!t.amount)throw new Error("Both assets are required for the initial add liquidity");return BigInt(Math.floor(Math.abs(Math.sqrt(Number(e.amount)*Number(t.amount))-Lt)))}function Rn(e,t){return e*BigInt(t)/(BigInt(1e4)-BigInt(t))}function Mn(t){return(Bn[t]+1)*e.ALGORAND_MIN_TX_FEE}var Un=Te("add_liquidity"),jn=(l(En={},U.V1_1,[Te("mint")]),l(En,U.V2,{INITIAL_LIQUIDITY:[Te("add_initial_liquidity")],SINGLE_ASSET_MODE:[Un,Te("single")],FLEXIBLE_MODE:[Un,Te("flexible")]}),En);function Vn(){return(Vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.asset1In,u=n.asset2In,c=n.poolTokenOut,p=n.slippage,l=n.initiatorAddr,d=me("negative",p,c.amount),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:Pe(a,U.V1_1),appArgs:jn.v1_1,accounts:[l],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:u.id==j?[i.id,c.id]:[i.id,u.id,c.id],suggestedParams:f}),h=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:i.id,amount:i.amount,suggestedParams:f}),g=u.id===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:u.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:u.id,amount:u.amount,suggestedParams:f}),x=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:l,assetIndex:c.id,amount:d,suggestedParams:f}),A=e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:m.fee+x.fee,note:P,suggestedParams:f}),I=e.assignGroupID([A,m,h,g,x]),t.abrupt("return",[{txn:I[0],signers:[l]},{txn:I[1],signers:[o]},{txn:I[2],signers:[l]},{txn:I[3],signers:[l]},{txn:I[4],signers:[o]}]);case 12:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Gn(){return(Gn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,i=r.account,t.next=4,o([a]);case 4:return u=t.sent,c=v(u,3),p=c[0],l=c[1],d=c[2],f=a.map((function(t,n){return n===Sn.FEE_TXN?p:n===Sn.ASSET1_IN_TXN?l:n===Sn.ASSET2_IN_TXN?d:e.signLogicSigTransactionObject(t.txn,i).blob})),t.abrupt("return",f);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Xn(){return(Xn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.signedTxns,i=t.initiatorAddr,e.prev=1,u=BigInt(a[Sn.LIQUDITY_OUT_TXN].txn.amount),e.next=5,Dt({client:n,pool:r,accountAddr:i});case 5:return c=e.sent,e.next=8,Ie(n,[o]);case 8:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,h=we(a),g=ye(a),e.next=17,Dt({client:n,pool:r,accountAddr:i});case 17:return x=e.sent,(A=x.excessPoolTokens-c.excessPoolTokens)<0n&&(A=0n),e.abrupt("return",{round:f,fees:h,poolTokenID:r.poolTokenID,poolTokenOut:u+A,excessAmount:{excessAmountForAddingLiquidity:A,totalExcessAmount:x.excessPoolTokens},txnID:m,groupID:g});case 23:throw e.prev=23,e.t0=e.catch(1),"SlippageTolerance"===(I=new Y(e.t0,"We encountered something unexpected while adding liquidity. Try again later.")).type&&I.setMessage("Adding liquidity failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),I;case 28:case"end":return e.stop()}}),e,null,[[1,23]])})))).apply(this,arguments)}var qn=Object.freeze({__proto__:null,execute:function(e){return Xn.apply(this,arguments)},generateTxns:function(e){return Vn.apply(this,arguments)},getQuote:function(e){var t=e.pool,n=e.reserves,r=e.asset1In,a=e.asset2In;if(0n===n.issuedLiquidity){var s=BigInt(Math.floor(Math.sqrt(Number(r)*Number(a))));if(s<=BigInt(L))throw new Error("Initial liquidity amount is too small. The amount must be greater than ".concat(L,", this quote is for ").concat(s,"."));return{round:n.round,asset1ID:t.asset1ID,asset1In:BigInt(r),asset2ID:t.asset2ID,asset2In:BigInt(a),poolTokenID:t.poolTokenID,poolTokenOut:s-BigInt(L),share:1}}var o=BigInt(r)*n.issuedLiquidity/n.asset1,i=BigInt(a)*n.issuedLiquidity/n.asset2,u=oo)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(t)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{assetInID:i,assetInAmount:l,assetOutID:c,assetOutAmount:m,swapFee:Number(h),rate:he(p,Number(m))/he(u,Number(l)),priceImpact:g}}function xr(e){var t=e.amount,n=e.assetIn,r=e.assetOut,a=e.pool;if(!a||!$t.isPoolReady(a))throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i=n.id,u=n.decimals,c=r.id,p=r.decimals,l=BigInt(t),d=a.totalFeeShare;if(c===a.asset1ID)s=a.asset2Reserves,o=a.asset1Reserves;else{if(c!==a.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(c,") doesn't belong to the pool ").concat(a.account.address(),"."));s=a.asset1Reserves,o=a.asset2Reserves}var f=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapOutputAmount,a=e.totalFeeShare,s=e.decimals,o=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.outputAmount,a=t*n,s=BigInt(a/(n-r))-t;return s+=BigInt(1),s}({inputSupply:t,outputSupply:n,outputAmount:r}),i=function(e){var t=e.swapAmount,n=e.totalFeeShare,r=Math.floor(Number(t*BigInt(1e4)/(BigInt(1e4)-BigInt(n)))),a=BigInt(r)-t;return a}({swapAmount:o,totalFeeShare:a}),u=o+i,c=pt({inputSupply:t,outputSupply:n,assetIn:{amount:u,decimals:s.assetIn},assetOut:{amount:r,decimals:s.assetOut}});return{swapInputAmount:u,totalFeeAmount:i,priceImpact:c}}({inputSupply:s,outputSupply:o,swapOutputAmount:l,totalFeeShare:d,decimals:{assetIn:u,assetOut:p}}),m=f.swapInputAmount,h=f.totalFeeAmount,g=f.priceImpact;if(l>o)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(m)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{type:rt.Direct,data:{pool:a,quote:{assetInID:i,assetInAmount:m,assetOutID:c,assetOutAmount:l,swapFee:Number(h),rate:he(p,Number(l))/he(u,Number(m)),priceImpact:g}}}}function Ar(e){return Ir.apply(this,arguments)}function Ir(){return(Ir=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[],u?c.push(new Promise((function(e,t){try{var s=gr({amount:n,assetIn:r,assetOut:a,pool:u});e({type:rt.Direct,data:{pool:u,quote:s}})}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair"))),o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedInput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=6,hr(c);case 6:return p=e.sent,e.abrupt("return",ht(p));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function vr(e){return wr.apply(this,arguments)}function wr(){return(wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[new Promise((function(e,t){try{e(xr({amount:n,assetIn:r,assetOut:a,pool:u}))}catch(e){t(e)}}))],o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedOutput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=5,hr(c);case 5:return p=e.sent,e.abrupt("return",ht(p));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function yr(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapInputAmount,a=e.totalFeeShare,s=e.decimals,o=BigInt(function(e){var t=e.inputAmount,n=e.totalFeeShare;return Math.floor(Number(t*BigInt(n))/1e4)}({inputAmount:r,totalFeeShare:a})),i=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapAmount,a=t*n,s=n-BigInt(a/(t+BigInt(r)));return s-=BigInt(1)}({inputSupply:t,outputSupply:n,swapAmount:r-o});return{swapOutputAmount:i,totalFeeAmount:o,priceImpact:pt({inputSupply:t,outputSupply:n,assetIn:{amount:r,decimals:s.assetIn},assetOut:{amount:i,decimals:s.assetOut}})}}var br={getQuote:function(e){return mr.apply(this,arguments)},getFixedInputSwapQuote:Ar,getFixedInputDirectSwapQuote:gr,getFixedOutputDirectSwapQuote:xr,getFixedOutputSwapQuote:vr,generateTxns:function(e){return dr.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return fr.apply(this,arguments)},calculateFixedInputSwap:yr};function Tr(e,t){var n,r,a=BigInt(e),s=t.issuedLiquidity;return s>a+BigInt(Lt)?(n=a*t.asset1/s,r=a*t.asset2/s):(n=t.asset1,r=t.asset2),{asset1OutputAmount:n,asset2OutputAmount:r}}function kr(){return(kr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.minAsset1Amount,c=n.minAsset2Amount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.account.address(),f=a.poolTokenID){t.next=8;break}throw new Error("Pool token asset ID is missing");case 8:return m=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:f,amount:o,suggestedParams:l}),(h=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(me("negative",p,u)),e.encodeUint64(me("negative",p,c))],accounts:[d],foreignAssets:[a.asset1ID,a.asset2ID],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(g=[])[ir.ASSET_TRANSFER_TXN]=m,g[ir.APP_CALL_TXN]=h,x=e.assignGroupID(g),t.abrupt("return",[{txn:x[ir.ASSET_TRANSFER_TXN],signers:[i]},{txn:x[ir.APP_CALL_TXN],signers:[i]}]);case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _r(){return(_r=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.initiatorAddr,i=n.poolTokenIn,u=n.outputAssetId,c=n.minOutputAssetAmount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.asset1ID,f=a.asset2ID,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:if(g=0,x=0,A=me("negative",p,c),u!==d){t.next=17;break}g=A,x=0,t.next=23;break;case 17:if(u!==f){t.next=22;break}g=0,x=A,t.next=23;break;case 22:throw new Error("Invalid output asset id. It doesn't match with pool assets");case 23:return I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:m,assetIndex:h,amount:i,suggestedParams:l}),(v=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(g),e.encodeUint64(x)],accounts:[m],foreignAssets:[u],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(w=[])[ir.ASSET_TRANSFER_TXN]=I,w[ir.APP_CALL_TXN]=v,y=e.assignGroupID(w),t.abrupt("return",[{txn:y[ir.ASSET_TRANSFER_TXN],signers:[o]},{txn:y[ir.APP_CALL_TXN],signers:[o]}]);case 31:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Er(){return(Er=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.txGroup,a=t.signedTxns,e.next=3,Ie(n,[a]);case 3:return o=e.sent,i=v(o,1),u=i[0].txnID,e.prev=6,e.next=9,hn(n,r);case 9:c=e.sent,e.next=14;break;case 12:e.prev=12,e.t0=e.catch(6);case 14:return e.abrupt("return",{outputAssets:c,txnID:u});case 15:case"end":return e.stop()}}),e,null,[[6,12]])})))).apply(this,arguments)}var Pr,Sr={getQuote:function(e){var t=e.pool,n=e.reserves,r=e.poolTokenIn,a=BigInt(r),s=Tr(a,n),o=s.asset1OutputAmount,i=s.asset2OutputAmount;return{round:n.round,asset1Out:{assetId:t.asset1ID,amount:o},asset2Out:{assetId:t.asset2ID,amount:i},poolTokenIn:{assetId:t.poolTokenID,amount:a}}},getSingleAssetRemoveLiquidityQuote:function(e){var t,n=e.pool,r=e.reserves,a=e.poolTokenIn,s=e.assetOutID,o=e.decimals,i=BigInt(a),u=Tr(i,r),c=u.asset1OutputAmount,p=u.asset2OutputAmount,l=n.totalFeeShare;if(s===n.asset1ID){var d=br.calculateFixedInputSwap({inputSupply:r.asset2-p,outputSupply:r.asset1-c,swapInputAmount:p,totalFeeShare:l,decimals:o}),f=d.swapOutputAmount,m=d.totalFeeAmount,h=d.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:c+f},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:f},swapFees:{assetId:n.asset2ID,amount:m},priceImpact:h}}}else{if(s!==n.asset2ID)throw new Error("assetOutID must be one of the pool assets");var g=br.calculateFixedInputSwap({inputSupply:r.asset1-c,outputSupply:r.asset2-p,swapInputAmount:c,totalFeeShare:l,decimals:o}),x=g.swapOutputAmount,A=g.totalFeeAmount,I=g.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:p+x},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:x},swapFees:{assetId:n.asset2ID,amount:A},priceImpact:I}}}return t},generateTxns:function(e){return kr.apply(this,arguments)},generateSingleAssetOutTxns:function(e){return _r.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return Er.apply(this,arguments)}},Dr=(l(Pr={},U.V1_1,lr),l(Pr,U.V2,Sr),Pr),Or=3n,Nr=1000n,Br=function(e){return e[e.FEE_TXN_INDEX=0]="FEE_TXN_INDEX",e[e.VALIDATOR_APP_CALL_TXN_INDEX=1]="VALIDATOR_APP_CALL_TXN_INDEX",e[e.ASSET_IN_TXN_INDEX=2]="ASSET_IN_TXN_INDEX",e[e.ASSET_OUT_TXN_INDEX=3]="ASSET_OUT_TXN_INDEX",e}(Br||{});function Cr(){return(Cr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,t.next=3,o([a]);case 3:return i=t.sent,u=v(i,2),c=u[0],p=u[1],l=a.map((function(t,n){return n===Br.FEE_TXN_INDEX?c:n===Br.ASSET_IN_TXN_INDEX?p:e.signLogicSigTransactionObject(t.txn,r.account.lsig).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Fr(){return(Fr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=n.client,a=n.quoteAndPool,o=n.swapType,i=n.slippage,u=n.initiatorAddr,c=a.pool,p=a.quote,l=p.assetInID,d=p.assetOutID,f=c.account.address(),(m=[c.asset1ID,c.asset2ID]).includes(l)&&m.includes(d)&&l!==d){t.next=7;break}throw new Y({pool:c,quote:p},"Input asset (#".concat(l,") and output asset (#").concat(d,") provided to generate transactions do not belong to the pool ").concat(f,"."));case 7:return t.next=9,r.getTransactionParams().do();case 9:return h=t.sent,g=[Te("swap"),o===Ce.FixedInput?Te("fi"):Te("fo")],x=e.makeApplicationNoOpTxnFromObject({from:f,appIndex:c.validatorAppID,appArgs:g,accounts:[u],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:c.asset2ID==j?[c.asset1ID,c.poolTokenID]:[c.asset1ID,c.asset2ID,c.poolTokenID],suggestedParams:h}),A=o===Ce.FixedOutput?me("positive",i,p.assetInAmount):p.assetInAmount,I=l===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:A,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:u,to:f,assetIndex:l,amount:A,suggestedParams:h}),v=o===Ce.FixedInput?me("negative",i,p.assetOutAmount):p.assetOutAmount,w=d===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:f,to:u,amount:v,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:f,to:u,assetIndex:d,amount:v,suggestedParams:h}),y=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:x.fee+w.fee,note:P,suggestedParams:h}),b=e.assignGroupID([y,x,I,w]),t.abrupt("return",[{txn:b[0],signers:[u]},{txn:b[1],signers:[f]},{txn:b[2],signers:[u]},{txn:b[3],signers:[f]}]);case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Lr(e){var t=e.pool,n=e.reserves,r=e.assetIn,s=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var o,i,u,c=BigInt(r.amount);if(r.id===t.asset1ID)o=t.asset2ID,i=n.asset1,u=n.asset2;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Input asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));o=t.asset1ID,i=n.asset2,u=n.asset1}var p=c*Or/Nr,l=u-i*u/(i+(c-p));if(l>u)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var d={assetIn:{amount:c,decimals:s.assetIn},assetOut:{amount:l,decimals:s.assetOut}},f={round:n.round,assetInID:r.id,assetInAmount:c,assetOutID:o,assetOutAmount:l,swapFee:Number(p),rate:ct(d),priceImpact:pt(a({inputSupply:i,outputSupply:u},d))};return{type:rt.Direct,data:{pool:t,quote:f}}}function Rr(e){return Mr.apply(this,arguments)}function Mr(){return(Mr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,i.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount),assetOutID:i.id,assetOutAmount:BigInt(i.amount)+A,excessAmount:{assetID:i.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ur(e){var t=e.pool,n=e.reserves,r=e.assetOut,a=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i,u=BigInt(r.amount);if(r.id===t.asset1ID)s=t.asset2ID,o=n.asset2,i=n.asset1;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));s=t.asset1ID,o=n.asset1,i=n.asset2}if(u>i)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var c=o*i/(i-u)-o,p=c*Nr/(Nr-Or),l=p-c,d=he(a.assetOut,Number(u))/he(a.assetIn,Number(p)),f=he(a.assetOut,Number(i))/he(a.assetIn,Number(o)),m=ge({decimalPlaces:5},Math.abs(d/f-1)),h={round:n.round,assetInID:s,assetInAmount:p,assetOutID:r.id,assetOutAmount:u,swapFee:Number(l),rate:d,priceImpact:m};return{type:rt.Direct,data:{pool:t,quote:h}}}function jr(e){return Vr.apply(this,arguments)}function Vr(){return(Vr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,o.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount)-A,assetOutID:i.id,assetOutAmount:BigInt(i.amount),excessAmount:{assetID:o.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Gr(){return(Gr=i(s().mark((function e(t){var n,r,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.pool,o=t.swapType,i=t.txGroup,u=t.signedTxns,c=t.initiatorAddr,r.status===Ct.READY){e.next=3;break}throw new Y({pool:r,swapType:o,txGroup:i},"There is not an available pool for this asset pair");case 3:if(e.prev=3,p={id:i[Br.ASSET_IN_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_IN_TXN_INDEX].txn.amount},l={id:i[Br.ASSET_OUT_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_OUT_TXN_INDEX].txn.amount},o!==Ce.FixedInput){e.next=12;break}return e.next=9,Rr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 9:d=e.sent,e.next=15;break;case 12:return e.next=14,jr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 14:d=e.sent;case 15:return e.abrupt("return",a(a({},d),{},{groupID:ye(i),fees:we(i)}));case 18:throw e.prev=18,e.t0=e.catch(3),"SlippageTolerance"===(f=new Y(e.t0,"We encountered something unexpected while swapping. Try again later.")).type&&f.setMessage("The swap failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),f;case 23:case"end":return e.stop()}}),e,null,[[3,18]])})))).apply(this,arguments)}var Xr,qr={getQuote:function(e,t,n,r,a){return e===Ce.FixedInput?Lr({pool:t,reserves:n,assetIn:r,decimals:a}):Ur({pool:t,reserves:n,assetOut:r,decimals:a})},getFixedInputSwapQuote:Lr,getFixedOutputSwapQuote:Ur,generateTxns:function(e){return Fr.apply(this,arguments)},signTxns:function(e){return Cr.apply(this,arguments)},execute:function(e){return Gr.apply(this,arguments)},executeFixedOutputSwap:jr};function Qr(e){return Promise.allSettled(e).then((function(e){if(e.every((function(e){return"rejected"===e.status}))){var t=v(e.map((function(e){return e.reason})),2),n=t[0],r=t[1];if(gt(n)&&!gt(r))throw n;throw r}return e.filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value}))}))}function Wr(){return(Wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.isSwapRouterEnabled,u=t.pools,c=[],(p=u.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedInputSwapQuote({pool:p.info,assetIn:{amount:r,id:Number(a.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=u.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedInputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:i,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zr(){return(zr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.pools,u=t.isSwapRouterEnabled,c=[],(p=i.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedOutputSwapQuote({pool:p.info,assetOut:{amount:r,id:Number(o.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=i.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedOutputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:u,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jr=(l(Xr={},U.V1_1,qr),l(Xr,U.V2,br),l(Xr,"getQuote",(function(e){var t=e.type;if(t===Ce.FixedInput)return function(e){return Wr.apply(this,arguments)}(e);if(t===Ce.FixedOutput)return function(e){return zr.apply(this,arguments)}(e);throw new E(_.InvalidSwapTypeError,"Invalid swap type")})),l(Xr,"generateTxns",(function(e){return e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1?qr.generateTxns(a(a({},e),{},{quoteAndPool:e.quote.data})):br.generateTxns(e)})),l(Xr,"signTxns",(function(e){if(e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1){var t=e.quote.data.pool;return qr.signTxns(a(a({},e),{},{pool:t}))}return br.signTxns(e)})),l(Xr,"execute",(function(e){return e.contractVersion===U.V1_1?qr.execute(e):br.execute(e)})),Xr);function Kr(){return(Kr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.initiatorSigner,e.prev=1,e.next=4,Yr({txGroup:a,pool:r,initiatorSigner:o});case 4:return i=e.sent,e.next=7,Ie(n,[i]);case 7:return u=e.sent,c=v(u,1),p=c[0],l=p.txnID,d=p.confirmedRound,e.abrupt("return",{fees:we(a),confirmedRound:d,txnID:l,groupID:ye(a)});case 15:throw e.prev=15,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while redeeming. Try again later.");case 18:case"end":return e.stop()}}),e,null,[[1,15]])})))).apply(this,arguments)}function Yr(e){return Hr.apply(this,arguments)}function Hr(){return(Hr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.pool,o=n.initiatorSigner,t.next=3,o([r]);case 3:return i=t.sent,u=v(i,1),c=u[0],p=a.account.lsig,l=r.map((function(t,n){return 0===n?c:e.signLogicSigTransactionObject(t.txn,p).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function $r(){return $r=i(s().mark((function t(n){var r,a,o,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.data,o=n.initiatorSigner,t.prev=1,u=a.map((function(e){var t=e.txGroup,n=e.pool;return{txns:t,txnFees:we(t),groupID:ye(t),lsig:n.account.lsig}})),t.next=5,o(u.map((function(e){return e.txns})));case 5:return c=t.sent,p=Promise.all(u.map((function(t,n){return new Promise(function(){var a=i(s().mark((function a(o,i){var u,p,l,d,f,m;return s().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,u=t.txns.map((function(r,a){return 0===a?c[n]:e.signLogicSigTransactionObject(r.txn,t.lsig).blob})),a.next=4,Ie(r,[u]);case 4:p=a.sent,l=v(p,1),d=l[0],f=d.txnID,m=d.confirmedRound,o({fees:t.txnFees,groupID:t.groupID,txnID:f,confirmedRound:m}),a.next=15;break;case 12:a.prev=12,a.t0=a.catch(0),i(a.t0);case 15:case"end":return a.stop()}}),a,null,[[0,12]])})));return function(e,t){return a.apply(this,arguments)}}())}))),t.abrupt("return",p);case 10:throw t.prev=10,t.t0=t.catch(1),new Y(t.t0,"We encountered something unexpected while redeeming. Try again later.");case 13:case"end":return t.stop()}}),t,null,[[1,10]])}))),$r.apply(this,arguments)}function Zr(){return(Zr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.assetID,i=n.assetOut,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=a.account.address(),l=e.makeApplicationNoOpTxnFromObject({from:p,appIndex:a.validatorAppID,appArgs:[Te("redeem")],note:_e.getAppCallTxnNoteWithClientName(a.contractVersion),accounts:[u],foreignAssets:0==a.asset2ID?[a.asset1ID,a.poolTokenID]:[a.asset1ID,a.asset2ID,a.poolTokenID],suggestedParams:c}),d=0===o?e.makePaymentTxnWithSuggestedParamsFromObject({from:p,to:u,amount:BigInt(i),suggestedParams:c}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:p,to:u,assetIndex:o,amount:BigInt(i),suggestedParams:c}),f=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:p,amount:l.fee+d.fee,note:P,suggestedParams:c}),m=e.assignGroupID([f,l,d]),t.abrupt("return",[{txn:m[0],signers:[u]},{txn:m[1],signers:[p]},{txn:m[2],signers:[p]}]);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ea(e){var t,n={},r=T(e);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=(new TextDecoder).decode(Buffer.from(a.key,"base64")),o=void 0;o=1===a.value.type?a.value.bytes:a.value.uint,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function ta(e,t,n){return e*t/n}var na=BigInt(31536e3),ra=BigInt(1e14),aa=BigInt(1e16),sa={testnet:548587153,mainnet:1385499515},oa=14;function ia(e){return ua.apply(this,arguments)}function ua(){return(ua=i(s().mark((function t(n){var r,a,o,i,u;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(sa[a]),t.next=4,_t(r,i);case 4:return u=t.sent.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!u.includes(e)})));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ca(){return(ca=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,y,b,T,k,_,E,P;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.poolTokenId,u=n.lendingManagerId,c=n.asset1In,p=n.asset2In,l=n.initiatorAddr,d=e.getApplicationAddress(sa[a]),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=[c,p].sort((function(e,t){return t.fAssetId-e.fAssetId})),h=v(m,2),g=h[0],x=h[1],A=te(x.id),I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:g.id,amount:g.amount,suggestedParams:f}),y=A?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:x.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:x.id,amount:x.amount,suggestedParams:f}),(b=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("add_liquidity"),e.decodeAddress(o).publicKey,e.encodeUint64(g.lendingAppId),e.encodeUint64(x.lendingAppId)],foreignAssets:[g.id,x.id,g.fAssetId,x.fAssetId],foreignApps:[g.lendingAppId,x.lendingAppId,u],accounts:[o],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),T=Pe(a,U.V2),k=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("noop")],foreignAssets:[i],foreignApps:[T],accounts:[o],suggestedParams:f}),_=[I,y,b,k],t.next=16,ia({client:r,network:a,assetIDs:[g.id,x.id,g.fAssetId,x.fAssetId,i]});case 16:return(E=t.sent).length&&((P=[e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:D*E.length,suggestedParams:f}),e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("asset_optin")].concat(w(E.map((function(t){return e.encodeUint64(t)})))),foreignAssets:w(E),suggestedParams:f})])[1].fee=(E.length+1)*e.ALGORAND_MIN_TX_FEE,_.unshift.apply(_,P)),t.abrupt("return",e.assignGroupID(_).map((function(e){return{txn:e,signers:[l]}})));case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function pa(){return(pa=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.asset1Out,c=n.asset2Out,p=n.lendingManagerId,l=n.network,d=e.getApplicationAddress(sa[l]),t.next=4,r.getTransactionParams().do();case 4:if(f=t.sent,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:return g=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:h,amount:o,suggestedParams:f}),(x=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("remove_liquidity"),e.decodeAddress(m).publicKey,e.encodeUint64(u.lendingAppId),e.encodeUint64(c.lendingAppId)],accounts:[m],foreignAssets:[u.id,c.id,u.fAssetId,c.fAssetId],foreignApps:[u.lendingAppId,c.lendingAppId,p],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),A=Pe(l,U.V2),I=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("noop")],accounts:[m],foreignAssets:[h,u.fAssetId,c.fAssetId],foreignApps:[A],suggestedParams:f}),v=e.assignGroupID([g,x,I]),t.abrupt("return",v.map((function(e){return{txn:e,signers:[i]}})));case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function la(e,t,n){var r=BigInt(Math.floor((new Date).getTime()/1e3)-function(e){return null!=e?e:Math.floor((new Date).getTime()/1e3)}(n));return ta(e,aa+t*r/na,aa)}function da(){return(da=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,a=r.params["global-state"],o=ea(a),i=Number(Buffer.from(o.pm,"base64").readBigUInt64BE(0)),u=Buffer.from(o.i,"base64"),c=u.readBigUInt64BE(32),p=u.readBigUInt64BE(40),l=Number(u.readBigUInt64BE(48)),e.abrupt("return",{appId:n,managerAppId:i,depositInterestRate:c,depositInterestIndex:p,lastUpdate:l});case 11:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var fa={AddLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return ca.apply(this,arguments)},getAddLiquidityTotalFee:function(t){return e.ALGORAND_MIN_TX_FEE*(4+oa)+(t?(t+1)*e.ALGORAND_MIN_TX_FEE+t*D:0)}}),RemoveLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return pa.apply(this,arguments)},getRemoveLiquidityTotalFee:function(){return e.ALGORAND_MIN_TX_FEE*(3+oa)}}),calculateWithdrawReturn:function(e){var t=e.withdrawAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return ta(BigInt(t),n,ra)},calculateDepositReturn:function(e){var t=e.depositAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return BigInt(t)*ra/n},getFolksWrapperAppOptInRequiredAssetIDs:ia};function ma(t){var n=t.suggestedParams,r=t.stakingAppID,a=t.initiatorAddr,s=t.liquidityAssetID,o=t.program,i=t.amount,u=e.encodeUint64(i),c=e.encodeUint64(o.id);return e.makeApplicationNoOpTxnFromObject({appIndex:r,from:a,suggestedParams:n,foreignAssets:[s],accounts:[o.accountAddress],appArgs:[Te("commit"),u],note:ae([Te("tinymanStaking/v1:b"),c,e.encodeUint64(s),u])})}function ha(){return(ha=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.stakingAppID,o=n.program,i=n.requiredAssetID,u=n.liquidityAssetID,c=n.amount,p=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=ma({suggestedParams:l,stakingAppID:a,program:o,liquidityAssetID:u,initiatorAddr:p,amount:c}),f=[d],"number"!=typeof i){t.next=10;break}return m=e.makeApplicationNoOpTxnFromObject({appIndex:a,from:p,suggestedParams:l,foreignAssets:[i],accounts:[o.accountAddress],appArgs:[Te("log_balance")]}),f=e.assignGroupID([d,m]),t.abrupt("return",[{txn:f[0],signers:[p]},{txn:f[1],signers:[p]}]);case 10:return t.abrupt("return",[{txn:f[0],signers:[p]}]);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var ga=604800,xa=1e3,Aa={testnet:480164661,mainnet:2200606875},Ia={testnet:360907790,mainnet:2200609638},va={testnet:336189106,mainnet:2200608153},wa={testnet:383416252,mainnet:2200608887},ya=2500,ba=400,Ta=604800,ka=Te("p"),_a=Te("a"),Ea=24,Pa=111300,Sa=ya+ba*(41+Ea),Da=function(e){return e[e.Against=0]="Against",e[e.For=1]="For",e[e.Abstain=2]="Abstain",e}(Da||{}),Oa=new Uint8Array(34),Na="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ";function Ba(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,n=new Uint8Array(t),r=BigInt(e),a=t-1;a>=0;a--)n[a]=Number(r&BigInt(255)),r>>=BigInt(8);return n}function Ca(e,t){return 0===Buffer.compare(e,t)}function Fa(e){for(var t=0n,n=0;n=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r>>0,o=new Uint8Array(s);e[t];){var p=n[e.charCodeAt(t)];if(255===p)return;for(var l=0,d=s-1;(0!==p||l>>0,o[d]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");a=l,t++}if(" "!==e[t]){for(var f=s-a;f!==s&&0===o[f];)f++;for(var m=new Uint8Array(r+(s-f)),h=r;f!==s;)m[h++]=o[f++];return m}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var n=0,r=0,a=0,s=t.length;a!==s&&0===t[a];)a++,n++;for(var o=(s-a)*p+1>>>0,c=new Uint8Array(o);a!==s;){for(var l=t[a],d=0,f=o-1;(0!==l||d>>0,c[f]=l%i>>>0,l=l/i>>>0;if(0!==l)throw new Error("Non-zero carry");r=d,a++}for(var m=o-r;m!==o&&0===c[m];)m++;for(var h=u.repeat(n);mLa(a(e))})}function Wa({name:e,prefix:t,bitsPerChar:n,alphabet:r}){return qa({prefix:t,name:e,encode:e=>function(e,t,n){const r="="===t[t.length-1],a=(1<n;)o-=n,s+=t[a&i>>o];if(0!==o&&(s+=t[a&i<function(e,t,n,r){const a={};for(let e=0;e=8&&(i-=8,o[c++]=255&u>>i)}if(i>=n||0!=(255&u<<8-i))throw new SyntaxError("Unexpected end of data");return o}(t,r,n,e)})}const za=Wa({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5});Wa({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wa({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wa({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wa({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wa({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wa({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wa({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wa({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});const Ja=Qa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"});Qa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ka=function e(t,n,r){n=n||[];var a=r=r||0;for(;t>=$a;)n[r++]=255&t|Ya,t/=128;for(;t&Ha;)n[r++]=255&t|Ya,t>>>=7;return n[r]=0|t,e.bytes=r-a+1,n},Ya=128,Ha=-128,$a=Math.pow(2,31);var Za=function e(t,n){var r,a=0,s=0,o=n=n||0,i=t.length;do{if(o>=i)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],a+=s<28?(r&ts)<=es);return e.bytes=o-n,a},es=128,ts=127;var ns=Math.pow(2,7),rs=Math.pow(2,14),as=Math.pow(2,21),ss=Math.pow(2,28),os=Math.pow(2,35),is=Math.pow(2,42),us=Math.pow(2,49),cs=Math.pow(2,56),ps=Math.pow(2,63),ls={encode:Ka,decode:Za,encodingLength:function(e){return e{const[n,r]=ds(e.subarray(t));return t+=r,n};let r=n(),a=ws;if(18===r?(r=0,t=0):a=n(),0!==r&&1!==r)throw new RangeError(`Invalid CID version ${r}`);const s=t,o=n(),i=n(),u=t+i;return{version:r,codec:a,multihashCode:o,digestSize:i,multihashSize:u-s,size:u}}static parse(e,t){const[n,r]=function(e,t){switch(e[0]){case"Q":{const n=t??Ja;return[Ja.prefix,n.decode(`${Ja.prefix}${e}`)]}case Ja.prefix:{const n=t??Ja;return[Ja.prefix,n.decode(e)]}case za.prefix:{const n=t??za;return[za.prefix,n.decode(e)]}default:if(null==t)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}(e,t),a=vs.decode(r);if(0===a.version&&"Q"!==e[0])throw Error("Version 0 CID string must not include multibase prefix");return Is(a).set(n,e),a}}const ws=112,ys=18;function bs(e,t,n){const r=ms(e),a=r+ms(t),s=new Uint8Array(a+n.byteLength);return fs(e,s,0),fs(t,s,r),s.set(n,a),s}const Ts=Symbol.for("@ipld/js-cid/CID");class ks{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){const t=this.encode(e);return t instanceof Uint8Array?hs(this.code,t):t.then((e=>hs(this.code,e)))}throw Error("Unknown type, must be binary type")}}const _s=85,Es=function({name:e,code:t,encode:n}){return new ks(e,t,n)}({name:"sha2-256",code:18,encode:e=>La(n.createHash("sha256").update(e).digest())});var Ps=126144e3,Ss=1e7,Ds=Math.pow(2,64),Os=48,Ns=21,Bs=48,Cs=Te("tp"),Fs=Te("sc"),Ls=28100,Rs=12900,Ms=421700,Us=409700;function js(e){var t=e/Ta;return(arguments.length>1&&void 0!==arguments[1]&&arguments[1]?Math.floor(t):Math.ceil(t))*Ta}function Vs(e,t){if(e>t)throw new Error("Old timestamp must be less than or equal to new timestamp");for(var n=[],r=js(e)+Ta;re?r=t?e*e*Ds/(2*t):0:r=(e+(e-r))*n/2;return r}function Js(e,t){return Ks.apply(this,arguments)}function Ks(){return(Ks=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,e.abrupt("return",Ys(r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ys(e){var t,n={},r=T(e.params["global-state"]);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=Buffer.from(a.key,"base64").toString(),o=void 0;o=1===a.value.type?Buffer.from(a.value.bytes||"","base64"):a.value.uint||0,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function Hs(){for(var e=arguments.length,t=new Array(e),n=0;n0?Ns-e:0}},{key:"lastAccountPowerBoxIndex",get:function(){return xo(this.powerCount)[0]}},{key:"lastAccountPowerArrayIndex",get:function(){return xo(this.powerCount)[1]}}]),e}(),uo=function(){function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a}return p(e,[{key:"lockEndTimestamp",get:function(){var e=this.bias*Math.pow(2,64)/this.slope;return this.timestamp+e}},{key:"cumulativePowerAt",value:function(e){var t=e-this.timestamp;if(t<0)throw new Error("Time delta must be greater than or equal to 0");return this.cumulativePower+zs(this.bias,this.slope,t)}}]),e}(),co=p((function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a})),po=p((function e(t){u(this,e),this.slopeDelta=t})),lo=function(){function e(t,n,r,a){u(this,e),this.tinyAssetId=t,this.totalLockedAmount=n,this.totalPowerCount=r,this.lastTotalPowerTimestamp=a}return p(e,[{key:"freeTotalPowerSpaceCount",get:function(){var e=this.totalPowerCount%Ns;return e>0?Ns-e:0}},{key:"lastTotalPowerBoxIndex",get:function(){return xo(this.totalPowerCount)[0]}},{key:"lastTotalPowerArrayIndex",get:function(){return xo(this.totalPowerCount)[1]}}]),e}();function fo(){return(fo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ho(r),e.prev=1,e.next=4,Gs(t,n,a);case 4:if(!(o=e.sent)){e.next=7;break}return e.abrupt("return",mo(o));case 7:return e.abrupt("return",null);case 10:return e.prev=10,e.t0=e.catch(1),console.log(e.t0),e.abrupt("return",null);case 14:case"end":return e.stop()}}),e,null,[[1,10]])})))).apply(this,arguments)}function mo(e){var t=Buffer.from(e);return new io(t.readUIntBE(0,8),t.readUIntBE(8,8),t.readUIntBE(16,8),t.readUIntBE(24,8))}function ho(t){return e.decodeAddress(t).publicKey}function go(e){var t=Ba(e),n=new Uint8Array(Cs.length+t.length);return n.set(Cs,0),n.set(t,Cs.length),n}function xo(e){var t=e-1;return[Math.floor(t/Ns),t%Ns]}function Ao(t,n){var r=e.decodeAddress(t).publicKey,a=Ba(n),s=new Uint8Array(r.length+a.length);return s.set(r,0),s.set(a,r.length),s}function Io(e,t,n){return vo.apply(this,arguments)}function vo(){return(vo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=yo(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",wo(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function wo(t){return new po(Number(e.bytesToBigInt(t.slice(t.length-16,t.length))))}function yo(e){return Hs(Fs,Ba(e))}function bo(e,t,n){return To.apply(this,arguments)}function To(){return(To=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=0,r&&(a=Math.ceil(r/Ns)),o=[],i=0;case 4:if(!(i=e[r].timestamp))break;n=r}return n}function So(e){for(var t,n=Os,r=[],a=0;a=11)throw new Error("Boxes' length cannot be larger than 10");var y=d.slice(0,6),b=[e.makeApplicationNoOpTxnFromObject({from:s,suggestedParams:c,appIndex:n,appArgs:[Te("claim_rewards"),Ba(o),Ba(i),Hs.apply(void 0,w(u.map((function(e){return Ba(e)}))))],foreignApps:[r],foreignAssets:[a],boxes:y,note:l?Te(l):void 0})];b[0].fee=b[0].fee*(i+2);var k=0,_=92+865*i,E=700+700*i;if(_>E&&(k=Math.floor((_-E)/666)+1),k||d.length>6){var P=d.slice(6),S=Ko({sender:s,suggestedParams:c,extraAppArgs:[Ba(Math.max(k-1,0))],index:n,foreignApps:[r],boxes:P});S.fee*=Math.max(k,1),b.unshift(S)}if(p){var D=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,to:e.getApplicationAddress(n),amount:Lo,suggestedParams:c});b.unshift(D)}return e.assignGroupID(b)}var Ho=8,$o=Te("p"),Zo=Te("a"),ei=Te("v"),ti=28500,ni=12500,ri=p((function e(t,n,r,a,s,o,i){u(this,e),this.index=t,this.creationTimestamp=n,this.votingStartTimestamp=r,this.votingEndTimestamp=a,this.votingPower=s,this.voteCount=o,this.isCancelled=i}));function ai(t,n){return Hs(Zo,e.decodeAddress(t).publicKey,Ba(n))}function si(e){return new ri(Fa(e.slice(0,8)),Fa(e.slice(8,16)),Fa(e.slice(16,24)),Fa(e.slice(24,32)),Fa(e.slice(32,40)),Fa(e.slice(40,48)),Boolean(Fa(e.slice(48,49))))}function oi(){return(oi=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ao(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",si(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ii(t){var n=t.stakingVotingAppId,r=t.vaultAppId,a=t.sender,s=t.proposalId,o=t.proposal,i=t.votes,u=t.assetIds,c=t.accountPowerIndex,p=t.appBoxNames,l=t.suggestedParams,d=t.appCallNote,f=void 0===d?null:d;if(i.length!==u.length)throw new Error("The number of votes must be equal to the number of asset ids");if(u.length>Ho)throw new Error("You cannot cast vote for more than ".concat(Ho," different pools"));if(100!==i.reduce((function(e,t){return e+t}),0))throw new Error("The sum of the votes must equal 100%");var m,h=Hs.apply(void 0,w(i.map((function(e){return Ba(e)})))),g=Hs.apply(void 0,w(u.map((function(e){return Ba(e)})))),x=function(e){return Hs($o,Te(e))}(s),A=ai(a,Math.floor(o.index/8192)),I=!p.some((function(e){return Ca(e,A)})),v=ho(a),y=Math.floor(c/Ns),b=Ao(a,y),k=Ao(a,y+1),_=0,E=[],P=T(u);try{var S=function(){var e=m.value,t=function(e,t){return Hs(ei,Ba(e),Ba(t))}(o.index,e);E.push({appIndex:n,name:t}),p.some((function(e){return Ca(e,t)}))||(_+=1)};for(P.s();!(m=P.n()).done;)S()}catch(e){P.e(e)}finally{P.f()}var D=[{appIndex:n,name:x},{appIndex:n,name:A}].concat(E,[{appIndex:r,name:v},{appIndex:r,name:b},{appIndex:r,name:k}]),O=[e.makeApplicationNoOpTxnFromObject({from:a,suggestedParams:l,appIndex:n,appArgs:[Te("cast_vote"),Te(s),h,g,Ba(c)],foreignApps:[r],boxes:D.slice(0,7),note:f?Te(f):void 0})];O[0].fee*=2,D.length>=7&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(7,14)})),D.length>=14&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(14)}));var N=Number(I)*ti+_*ni;return N&&(O=[e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:l,to:e.getApplicationAddress(n),amount:N})].concat(w(O))),e.assignGroupID(O)}function ui(t){var n=t.accountState,r=t.lockEndTime,a=t.lockedAmount,s=t.network,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.slopeChangeAtLockEndTime,p=t.appCallNote;if(ai.freeTotalPowerSpaceCount&&(b+=Us),c||(b+=Rs);var k=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({amount:a,assetIndex:X[s],from:o,suggestedParams:u,to:e.getApplicationAddress(l)}),e.makeApplicationNoOpTxnFromObject({appIndex:l,from:o,suggestedParams:u,appArgs:[Te("create_lock"),Ba(r)],boxes:d.slice(0,8),note:p}),Ko({sender:o,suggestedParams:u,index:l,boxes:d.slice(8)})];if(b){var _=e.makePaymentTxnWithSuggestedParamsFromObject({amount:b,from:o,suggestedParams:u,to:e.getApplicationAddress(l)});k.unshift(_)}return e.assignGroupID(k)}function ci(t){var n=t.accountState,r=t.lockedAmount,a=t.network,s=t.sender,o=t.vaultAppGlobalState,i=t.suggestedParams,u=t.appCallNote;if(ro.freeTotalPowerSpaceCount&&(v+=Us),!n.freeAccountPowerSpaceCount){var w=Ao(s,n.lastAccountPowerBoxIndex+1);h.push({appIndex:Aa[a],name:w}),v+=Ms}var y=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:X[a],from:s,to:e.getApplicationAddress(Aa[a]),amount:r,suggestedParams:i}),e.makeApplicationNoOpTxnFromObject({appIndex:Aa[a],from:s,suggestedParams:i,appArgs:[Te("increase_lock_amount")],boxes:h,note:u}),Ko({sender:s,suggestedParams:i,index:Aa[a]})];if(v){var b=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,suggestedParams:i,to:e.getApplicationAddress(Aa[a]),amount:v});y.unshift(b)}return e.assignGroupID(y)}function pi(t){var n=t.accountState,r=t.network,a=t.newLockEndTime,s=t.slopeChangeAtNewLockEndTime,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.appCallNote;if(a%Ta)throw new Error("Invalid lock end time");if(a<=n.lockEndTime)throw new Error("New lock end time must be greater than current lock end time");var p=ho(o),l=Ao(o,n.lastAccountPowerBoxIndex),d=go(i.lastTotalPowerBoxIndex),f=go(i.lastTotalPowerBoxIndex+1),m=yo(n.lockEndTime),h=yo(a),g=[{appIndex:Aa[r],name:p},{appIndex:Aa[r],name:l},{appIndex:Aa[r],name:d},{appIndex:Aa[r],name:f},{appIndex:Aa[r],name:m},{appIndex:Aa[r],name:h}];if(!n.freeAccountPowerSpaceCount){var x=Ao(o,n.lastAccountPowerBoxIndex+1);g.push({appIndex:Aa[r],name:x})}var A,I=Vs(i.lastTotalPowerTimestamp,Math.floor(Date.now()/1e3)),v=I.length,w=T(I);try{for(w.s();!(A=w.n()).done;){var y=A.value;if(y%Ta==0){var b=yo(y);g.push({appIndex:Aa[r],name:b})}}}catch(e){w.e(e)}finally{w.f()}var k=0;s||(k+=Rs),n.freeAccountPowerSpaceCount||(k+=Ms),v>i.freeTotalPowerSpaceCount&&(k+=Us);var _=[e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:o,suggestedParams:u,appArgs:[Te("extend_lock_end_time"),Ba(a)],boxes:g.slice(0,8),note:c}),Ko({sender:o,suggestedParams:u,index:Aa[r],boxes:g.slice(8)})];if(k){var E=e.makePaymentTxnWithSuggestedParamsFromObject({from:o,suggestedParams:u,to:e.getApplicationAddress(Aa[r]),amount:k});_.unshift(E)}return e.assignGroupID(_)}function li(t){var n=t.accountState,r=t.network,a=t.sender,s=t.suggestedParams,o=t.appCallNote,i=ho(a),u=Ao(a,n.lastAccountPowerBoxIndex),c=Ao(a,n.lastAccountPowerBoxIndex+1),p=[{appIndex:Aa[r],name:i},{appIndex:Aa[r],name:u},{appIndex:Aa[r],name:c}],l=e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:a,suggestedParams:s,appArgs:[Te("withdraw")],foreignAssets:[X[r]],boxes:p,note:o});l.fee*=2;var d=[l];if(!n.freeAccountPowerSpaceCount){var f=e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:s,to:e.getApplicationAddress(Aa[r]),amount:Ms});d.unshift(f)}return e.assignGroupID(d)}var di=function(){function t(e,n,r){u(this,t),this.algodClient=e,this.userAddress=n,this.network=r}var n,r,a,o,c,l,d,f,m,h,g,x,A,I,v,y;return p(t,[{key:"getTinyPower",value:(y=i(s().mark((function e(){var t,n,r,a,o,i,u,c=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=c.length>0&&void 0!==c[0]?c[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=Math.max(o.bias-Ws(o.slope,i),0),e.abrupt("return",u);case 16:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getTotalTinyPower",value:(v=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=v.length>0&&void 0!==v[0]?v[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchVaultAppGlobalState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,bo(this.algodClient,Aa[this.network],n.totalPowerCount);case 8:if(r=e.sent,a=Po(r,t)){e.next=12;break}return e.abrupt("return",0);case 12:o=r[a],i=Math.floor(o.timestamp/Ta),u=Math.floor(t/Ta)-i,c=Array.from({length:u},(function(e,t){return(i+t)*Ta})),p=c.map((function(e,t){return[0===t?o.timestamp:c[t-1],e]})),l=o.slope,d=o.bias,f=T(p),e.prev=19,f.s();case 21:if((m=f.n()).done){e.next=34;break}return h=m.value,g=h[1]-h[0],x=Ws(l,g),d=Math.max(d-x,0),e.next=28,Io(this.algodClient,Aa[this.network],h[1]);case 28:A=e.sent,I=(null==A?void 0:A.slopeDelta)||0,l=Math.max(l-I,0),0!==d&&0!==l||(d=0,l=0);case 32:e.next=21;break;case 34:e.next=39;break;case 36:e.prev=36,e.t0=e.catch(19),f.e(e.t0);case 39:return e.prev=39,f.f(),e.finish(39);case 42:return e.abrupt("return",d);case 43:case"end":return e.stop()}}),e,this,[[19,36,39,42]])}))),function(){return v.apply(this,arguments)})},{key:"getCumulativeTinyPower",value:(I=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=p.length>0&&void 0!==p[0]?p[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=zs(o.bias,o.slope,i),c=o.cumulativePower-u,e.abrupt("return",c);case 17:case"end":return e.stop()}}),e,this)}))),function(){return I.apply(this,arguments)})},{key:"fetchVaultAppGlobalState",value:(A=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,Js(this.algodClient,Aa[this.network]);case 3:return t=e.sent,e.abrupt("return",new lo(t.tiny_asset_id,t.total_locked_amount,t.total_power_count,t.last_total_power_timestamp));case 7:return e.prev=7,e.t0=e.catch(0),console.error(e.t0),e.abrupt("return",null);case 11:case"end":return e.stop()}}),e,this,[[0,7]])}))),function(){return A.apply(this,arguments)})},{key:"generateCreateLockTransactions",value:(x=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=o,c){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(p){e.next=15;break}return e.next=14,this.algodClient.getTransactionParams().do();case 14:p=e.sent;case 15:return e.next=17,Io(this.algodClient,Aa[this.network],r);case 17:return l=e.sent,e.abrupt("return",ui({lockedAmount:n,lockEndTime:r,vaultAppGlobalState:c,slopeChangeAtLockEndTime:l,sender:i,network:this.network,accountState:u,suggestedParams:p}));case 19:case"end":return e.stop()}}),e,this)}))),function(e){return x.apply(this,arguments)})},{key:"generateIncreaseLockAmountTransactions",value:(g=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.abrupt("return",ci({accountState:i,lockedAmount:n,network:this.network,sender:o,vaultAppGlobalState:u,suggestedParams:c}));case 18:case"end":return e.stop()}}),e,this)}))),function(e){return g.apply(this,arguments)})},{key:"generateExtendLockTimeTransactions",value:(h=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.newLockEndTime,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.next=19,Io(this.algodClient,Aa[this.network],n);case 19:return p=e.sent,e.abrupt("return",pi({accountState:i,network:this.network,newLockEndTime:n,sender:o,vaultAppGlobalState:u,suggestedParams:c,slopeChangeAtNewLockEndTime:null==p?void 0:p.slopeDelta}));case 21:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"generateIncreaseLockAmountAndExtendLockEndTimeTransactions",value:(m=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=[],l=[],d=o,c){e.next=13;break}throw new Error("There was an error while fetching vault app global state");case 13:if(u){e.next=15;break}throw new Error("There was an error while fetcing the account state");case 15:if(d){e.next=19;break}return e.next=18,this.algodClient.getTransactionParams().do();case 18:d=e.sent;case 19:return p=ci({accountState:u,lockedAmount:n,network:this.network,sender:i,vaultAppGlobalState:c,suggestedParams:d}),u.powerCount+=1,c.totalPowerCount+=1,e.next=24,Io(this.algodClient,Aa[this.network],r);case 24:return f=e.sent,l=pi({accountState:u,network:this.network,newLockEndTime:r,sender:i,vaultAppGlobalState:c,suggestedParams:d,slopeChangeAtNewLockEndTime:null==f?void 0:f.slopeDelta}),m=[].concat(w(p),w(l)),e.abrupt("return",Boolean(p.length)&&Boolean(l.length)?Zs(p,l):m);case 28:case"end":return e.stop()}}),e,this)}))),function(e){return m.apply(this,arguments)})},{key:"generateWithdrawTransactions",value:(f=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t||this.userAddress,e.next=3,this.fetchAccountState();case 3:if(o=e.sent,i=r,o){e.next=7;break}throw new Error("There was an error while fetcing the account state");case 7:if(i){e.next=11;break}return e.next=10,this.algodClient.getTransactionParams().do();case 10:i=e.sent;case 11:if(u=li({accountState:o,network:this.network,sender:a,suggestedParams:i,client:this.algodClient}),!n){e.next=17;break}return e.next=15,H({client:this.algodClient,initiatorAddr:a,assetID:X[this.network]});case 15:c=e.sent,u=Zs([c[0].txn],u);case 17:return e.abrupt("return",u);case 18:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"fetchAccountState",value:function(){return function(e,t,n){return fo.apply(this,arguments)}(this.algodClient,Aa[this.network],this.userAddress)}},{key:"fetchStakingDistributionProposal",value:function(e){return function(e,t,n){return oi.apply(this,arguments)}(this.algodClient,Ia[this.network],e)}},{key:"generateCastVoteForStakingDistributionProposalTransactions",value:(d=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.proposalId,a=t.votes,o=t.assetIds,i=t.userAddress,u=t.suggestedParams,c=null!=i?i:this.userAddress,p=u,e.next=5,this.fetchStakingDistributionProposal(r);case 5:if(l=e.sent){e.next=8;break}throw new Error("There was an error while fetching staking distribution proposal");case 8:if(p){e.next=12;break}return e.next=11,this.algodClient.getTransactionParams().do();case 11:p=e.sent;case 12:return e.next=14,this.fetchAccountState();case 14:return d=e.sent,e.next=17,eo(this.algodClient,Ia[this.network]);case 17:return f=e.sent,e.next=20,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==d?void 0:d.powerCount)&&void 0!==n?n:null});case 20:if(m=e.sent,null!==(h=Po(m,l.creationTimestamp))){e.next=24;break}throw new Error("It is required to have an account power at the staking distribution proposal creation timestamp");case 24:return e.abrupt("return",ii({stakingVotingAppId:Ia[this.network],vaultAppId:Aa[this.network],sender:c,proposalId:r,proposal:l,votes:a,assetIds:o,accountPowerIndex:h,appBoxNames:f,suggestedParams:p,appCallNote:null}));case 25:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"fetchRewardsAppGlobalState",value:(l=i(s().mark((function t(){var n;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,Js(this.algodClient,va[this.network]);case 3:return n=t.sent,t.abrupt("return",new Ro(n.tiny_asset_id,n.vault_app_id,n.reward_history_count,n.first_period_timestamp,n.reward_period_count,e.encodeAddress(n.manager),e.encodeAddress(n.rewards_manager)));case 7:return t.prev=7,t.t0=t.catch(0),console.error(t.t0),t.abrupt("return",null);case 11:case"end":return t.stop()}}),t,this,[[0,7]])}))),function(){return l.apply(this,arguments)})},{key:"generateClaimRewardTransactions",value:(c=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.periodIndexStart,a=t.periodCount,o=t.userAddress,i=t.suggestedParams,u=t.shouldOptIntoTINY,c=null!=o?o:this.userAddress,p=i){e.next=7;break}return e.next=6,this.algodClient.getTransactionParams().do();case 6:p=e.sent;case 7:return e.next=9,this.fetchAccountState();case 9:return l=e.sent,e.next=12,this.fetchRewardsAppGlobalState();case 12:if(d=e.sent){e.next=15;break}throw new Error("There was an error while fetching rewards app global state");case 15:if(!(r+a>d.rewardPeriodCount)){e.next=17;break}throw new Error("The reward period index to be claimed cannot be larger than the latest reward period index");case 17:return e.next=19,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==l?void 0:l.powerCount)&&void 0!==n?n:null});case 19:for(f=e.sent,m=d.firstPeriodTimestamp+r*ga,h=d.firstPeriodTimestamp+(r+a)*ga,g=[],x=m;x=Math.floor(Date.now()/xa)||c.votingEndTimestamp<=Math.floor(Date.now()/xa))){e.next=23;break}throw new Error("Voting period is not active");case 23:return e.next=25,_o({algodClient:this.algodClient,address:i,appId:Aa[this.network],powerCount:p.powerCount});case 25:if(l=e.sent,null!==(d=Po(l,c.creationTimestamp))){e.next=29;break}throw new Error("Account power index not found");case 29:return f=Math.floor(c.index/(8*Ea)),m=ai(i,f),e.next=33,qs(this.algodClient,wa[this.network],m);case 33:return h=!e.sent,e.abrupt("return",Oo({proposalVotingAppId:wa[this.network],vaultAppId:Aa[this.network],sender:i,proposalId:n,proposal:c,vote:a,accountPowerIndex:d,createAttendanceSheetBox:h,suggestedParams:u}));case 35:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"fetchProposalVotingAppGlobalState",value:(r=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Js(this.algodClient,wa[this.network]);case 2:return t=e.sent,e.abrupt("return",new ro(t.vault_app_id,t.proposal_index_counter,t.voting_delay,t.voting_duration,t.proposal_threshold,t.proposal_threshold_numerator,t.quorum_threshold,t.approval_requirement,t.manager,t.proposal_manager));case 4:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getRequiredTinyPowerToCreateProposal",value:(n=i(s().mark((function e(t){var n,r,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==t){e.next=4;break}e.t0=t,e.next=7;break;case 4:return e.next=6,this.getTotalTinyPower();case 6:e.t0=e.sent;case 7:return n=e.t0,e.next=10,this.fetchProposalVotingAppGlobalState();case 10:return r=e.sent,a=r.proposalThreshold,r.proposalThresholdNumerator&&(a=Math.max(a,Math.floor(n*r.proposalThresholdNumerator/100)+1)),e.abrupt("return",a);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})}]),t}(),fi=2500,mi=400,hi=function(){function e(t,n){u(this,e),l(this,"data",null),this.name=t,this.structReference=n,this.size=n[t].size,this.fields=n[t].fields}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.size)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t;if(!this.data)throw new Error("Data is not initialized");var n=this.fields[e];if(!n)throw new Error("Field ".concat(e," does not exist in struct ").concat(this.name));var r=n.offset,a=n.offset+n.size,s=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(r,a);return Ii(n.type,this.structReference).apply(Buffer.from(s))}}]),e}(),gi=function(){function e(t,n){u(this,e),l(this,"data",null),this.struct=t,this.length=n}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.struct.size*this.length)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t,n=this.struct.size*e,r=n+this.struct.size,a=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(n,r);return this.struct.apply(a?Buffer.from(a):void 0)}}]),e}(),xi=function(){function e(){u(this,e)}return p(e,[{key:"apply",value:function(e){for(var t=BigInt(0),n=0;n2&&void 0!==arguments[2]?arguments[2]:Math.floor(Date.now()/1e3),a=(n=e,Math.floor(n*Ds/Ps)),s=t-r;return s<0?0:Ws(a,s)},exports.combineAndRegroupSignerTxns=function(){for(var t=arguments.length,n=new Array(t),r=0;r=e.minimum_required_balance},exports.intToBytes=Ba,exports.isAccountOptedIntoApp=function(e){var t=e.appID;return e.accountAppsLocalState.some((function(e){return e.id===t}))},exports.isSwapAssetInAmountLow=it,exports.isSwapQuoteErrorCausedByAmount=gt,exports.poolUtils=$t,exports.prepareCommitTransactions=function(e){return ha.apply(this,arguments)},exports.redeemAllExcessAsset=function(e){return $r.apply(this,arguments)},exports.redeemExcessAsset=function(e){return Kr.apply(this,arguments)},exports.sendAndWaitRawTransaction=Ie,exports.sumUpTxnFees=we,exports.tinymanContract_v1_1=wt,exports.tinymanContract_v2=Tt,exports.tinymanJSSDKConfig=_e; diff --git a/dist/liquid-stake/stAlgoClient.d.ts b/dist/liquid-stake/stAlgoClient.d.ts index b9b0ce3c..a503c229 100644 --- a/dist/liquid-stake/stAlgoClient.d.ts +++ b/dist/liquid-stake/stAlgoClient.d.ts @@ -11,6 +11,7 @@ declare class TinymanSTAlgoClient extends TinymanBaseClient { calculateDecreaseStakeFee(accountAddress: string): Promise; private getUserStateBoxName; private getApplyRateChangeTxnIfNeeded; + private getUserBoxPaymentTxnIfNeeded; private shouldApplyRateChange; private getApplyRateChangeTxn; } diff --git a/src/liquid-stake/stAlgoClient.ts b/src/liquid-stake/stAlgoClient.ts index 9c912df1..fccce9d7 100644 --- a/src/liquid-stake/stAlgoClient.ts +++ b/src/liquid-stake/stAlgoClient.ts @@ -33,10 +33,9 @@ class TinymanSTAlgoClient extends TinymanBaseClient { const suggestedParams = await this.getSuggestedParams(); const userStateBoxName = this.getUserStateBoxName(userAddress); - let newBox: Record = {}; - const txns = [ ...(await this.getApplyRateChangeTxnIfNeeded()), + ...(await this.getUserBoxPaymentTxnIfNeeded(userAddress, suggestedParams)), ...(await this.getOptinTxnIfNeeded(userAddress, STALGO_ASSET_ID[this.network])), algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({ from: userAddress, @@ -59,21 +58,6 @@ class TinymanSTAlgoClient extends TinymanBaseClient { }) ]; - if (!(await this.boxExists(userStateBoxName))) { - newBox = { - [fromByteArray(userStateBoxName)]: USER_STATE - }; - - const boxPaymentTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ - from: userAddress, - to: this.applicationAddress, - suggestedParams, - amount: this.calculateMinBalance({boxes: newBox}) - }); - - txns.splice(1, 0, boxPaymentTxn); - } - return this.setupTxnFeeAndAssignGroupId({ txns, additionalFeeCount: 2 @@ -168,6 +152,38 @@ class TinymanSTAlgoClient extends TinymanBaseClient { return []; } + private async getUserBoxPaymentTxnIfNeeded( + userAddress: string, + suggestedParams: algosdk.SuggestedParams + ) { + const userStateBoxName = this.getUserStateBoxName(userAddress); + + if (!(await this.boxExists(userStateBoxName))) { + return this.getUserBoxPaymentTxn(userStateBoxName, userAddress, suggestedParams); + } + + return []; + } + + private getUserBoxPaymentTxn( + userStateBoxName: Uint8Array, + userAddress: string, + suggestedParams: algosdk.SuggestedParams + ) { + const newBox: Record = { + [fromByteArray(userStateBoxName)]: USER_STATE + }; + + const boxPaymentTxn = algosdk.makePaymentTxnWithSuggestedParamsFromObject({ + from: userAddress, + to: this.applicationAddress, + suggestedParams, + amount: this.calculateMinBalance({boxes: newBox}) + }); + + return [boxPaymentTxn]; + } + private async shouldApplyRateChange() { const now = Math.floor(Date.now() / SECOND_IN_MS); From 57140dc2edf2760339eb65d07fab2e6671be020f Mon Sep 17 00:00:00 2001 From: gulcinuras Date: Tue, 3 Dec 2024 12:36:54 +0100 Subject: [PATCH 3/4] fix(liquid-restake): Wait for all promises to be resolved before sending txn array --- dist/index.js | 2 +- dist/liquid-stake/stAlgoClient.d.ts | 1 + src/liquid-stake/stAlgoClient.ts | 14 ++++++++------ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index 03db43ba..e2f95da3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1 +1 @@ -"use strict";var e=require("algosdk"),t=require("base64-js"),n=require("crypto");function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0;--a){var s=this.tryEntries[a],o=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var i=n.call(s,"catchLoc"),u=n.call(s,"finallyLoc");if(i&&u){if(this.prev=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),k(n),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var a=r.arg;k(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:E(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function o(e,t,n,r,a,s,o){try{var i=e[s](o),u=i.value}catch(e){return void n(e)}i.done?t(u):Promise.resolve(u).then(r,a)}function i(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var s=e.apply(t,n);function i(e){o(s,r,a,i,u,"next",e)}function u(e){o(s,r,a,i,u,"throw",e)}i(void 0)}))}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f: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,o=!0,i=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){i=!0,s=e},f:function(){try{o||null==n.return||n.return()}finally{if(i)throw s}}}}function k(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var _=function(e){return e.SwapRouterStaleDataError="SwapRouterStaleDataError",e.SwapRouterNoRouteError="SwapRouterNoRouteError",e.SwapRouterLowSwapAmountError="SwapRouterLowSwapAmountError",e.SwapRouterInsufficientReservesError="SwapRouterInsufficientReservesError",e.SwapRouterPoolHasNoLiquidityError="SwapRouterPoolHasNoLiquidityError",e.NoAvailablePoolError="NoAvailablePoolError",e.OutputAmountExceedsAvailableLiquidityError="OutputAmountExceedsAvailableLiquidityError",e.UnknownError="UnknownError",e.LowSwapAmountError="LowSwapAmountError",e.AssetDoesNotBelongToPoolError="AssetDoesNotBelongToPoolError",e.InvalidSwapTypeError="InvalidSwapTypeError",e}({}),E=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;return u(this,n),(a=t.call(this,r)).type=e,a.message=r,Error.captureStackTrace&&Error.captureStackTrace(A(a),n),a}return p(n)}(),P=Uint8Array.from([1]),S=1e5,D=1e5,O=1e5,N=1e5,B=1e5,C=5e4,F=28500,L=1e3,R=1e3,M={mainnet:{base:"https://mainnet.analytics.tinyman.org/api",v1:"https://mainnet.analytics.tinyman.org/api/v1"},testnet:{base:"https://testnet.analytics.tinyman.org/api",v1:"https://testnet.analytics.tinyman.org/api/v1"}},U={V1_1:"v1_1",V2:"v2"},j=0,V={id:"".concat(j),name:"Algorand",unit_name:"ALGO",decimals:6,url:"https://algorand.org",is_liquidity_token:!1,total_amount:"6615503326932151",clawback_address:""},G={V1:"TM1POOL",V1_1:"TMPOOL11",V2:"TMPOOL2"},X={testnet:258703304,mainnet:22e8},q={testnet:724519992,mainnet:2537013734},Q={testnet:724676936,mainnet:2537023208},W="- would result negative",z="logic eval error:",J="exceeds schema integer count",K=/transaction \w+:/,Y=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;u(this,n);for(var s=arguments.length,o=new Array(s>2?s-2:0),i=2;ir?[a(a({},e),{},{id:n}),a(a({},t),{},{id:r})]:[a(a({},t),{},{id:r}),a(a({},e),{},{id:n})]}function ee(e,t){var n=[e,t];return[Math.max.apply(Math,n),Math.min.apply(Math,n)]}function te(e){return Number(e)===j}function ne(e){return Number(e.id)}function re(e){var t,n=e.stateArray,r=void 0===n?[]:n,a=e.shouldDecodeKeys,s=void 0!==a&&a,o={},i=T(r);try{for(i.s();!(t=i.n()).done;){var u=t.value,c=u.key,p=void 0;if(1==u.value.type)p=u.value.bytes;else{if(2!=u.value.type)throw new Error("Unexpected state type: ".concat(u.value.type));p=u.value.uint}o[s?atob(c):c]=p}}catch(e){i.e(e)}finally{i.f()}return o}function ae(e){var t,n=e.reduce((function(e,t){return e+t.length}),0),r=new Uint8Array(n),a=0,s=T(e);try{for(s.s();!(t=s.n()).done;){var o=t.value;r.set(o,a),a+=o.length}}catch(e){s.e(e)}finally{s.f()}return r}var se=100000n,oe=100000n,ie=100000n,ue=25000n+25000n,ce=25000n+3500n;function pe(e){var t=e["apps-total-schema"],n=0n,r=0n;t&&(t["num-byte-slice"]&&(n=t["num-byte-slice"]),t["num-uint"]&&(r=t["num-uint"]));var a=e["apps-local-state"]||[],s=e["created-apps"]||[],o=e.assets||[];return se+oe*BigInt(o.length)+ie*BigInt(s.length+a.length)+ce*r+ue*n}function le(e){return new Promise((function(t){setTimeout((function(){t(null)}),e)}))}function de(e,t){return fe.apply(this,arguments)}function fe(){return(fe=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=3,le(1e3);case 3:return r=null,e.prev=4,e.next=7,t.pendingTransactionInformation(n).do();case 7:r=e.sent,e.next=12;break;case 10:e.prev=10,e.t0=e.catch(4);case 12:if(!r){e.next=17;break}if(!r["confirmed-round"]){e.next=15;break}return e.abrupt("return",r);case 15:if(!r["pool-error"]){e.next=17;break}throw new Error("Transaction Rejected: ".concat(r["pool-error"]));case 17:e.next=0;break;case 19:case"end":return e.stop()}}),e,null,[[4,10]])})))).apply(this,arguments)}function me(e,t,n){if(t>1||t<0)throw new Error("Invalid slippage value. Must be between 0 and 1, got ".concat(t));var r;try{var a="negative"===e?1-t:1+t;r=BigInt(Math.floor(Number(n)*a))}catch(e){throw new Error(e.message)}return r}function he(e,t){var n=Number(e);return ge({decimalPlaces:n},Math.pow(10,-n)*Number(t))}function ge(e,t){var n=e.decimalPlaces,r=void 0===n?0:n;if(r>0){var a=v(Ae(t),2),s=a[0],o=a[1],i=v(Ae(Math.round(Number(xe(s,o+r)))),2),u=i[0],c=i[1];return Number(xe(u,c-r))}return Math.round(t)}function xe(e,t){return e+(t<0?"e".concat(t):"e+".concat(t))}function Ae(e){if(e.toString().includes("e")){var t=e.toString().split("e");return[parseFloat(t[0]),parseFloat(t[1])]}return[e,0]}function Ie(e,t){return ve.apply(this,arguments)}function ve(){return(ve=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,r=[],a=T(n),e.prev=3,a.s();case 5:if((o=a.n()).done){e.next=18;break}return i=o.value,e.next=9,t.sendRawTransaction(i).do();case 9:return u=e.sent,c=u.txId,e.next=13,de(t,c);case 13:p=e.sent,l=p["confirmed-round"],r.push({confirmedRound:l,txnID:c});case 16:e.next=5;break;case 18:e.next=23;break;case 20:e.prev=20,e.t0=e.catch(3),a.e(e.t0);case 23:return e.prev=23,a.f(),e.finish(23);case 26:return e.abrupt("return",r);case 29:throw e.prev=29,e.t1=e.catch(0),new Y(e.t1,"We encountered an error while processing this transaction. Try again later.");case 32:case"end":return e.stop()}}),e,null,[[0,29],[3,20,23,26]])})))).apply(this,arguments)}function we(e){return e.reduce((function(e,t){return e+t.txn.fee}),0)}function ye(e){return(t=e[0].txn.group)?Buffer.from(t).toString("base64"):"";var t}function be(e){for(var t=[];;){var n=Number(e&BigInt(127));if(!(e>>=BigInt(7))){t.push(n);break}t.push(128|n)}return t}function Te(e){return(new TextEncoder).encode(e)}var ke,_e=new(function(){function e(){u(this,e),this.clientName="tinyman-js-sdk"}return p(e,[{key:"getClientName",value:function(){return this.clientName}},{key:"setClientName",value:function(e){this.clientName=e}},{key:"getAppCallTxnNoteWithClientName",value:function(e,t){var n=e===U.V1_1?"v1":e,r=JSON.stringify(a({origin:this.clientName},t));return Te("tinyman/".concat(n,":j").concat(r))}}]),e}()),Ee=(l(ke={},U.V1_1,{testnet:62368684,mainnet:552635992}),l(ke,U.V2,{testnet:148607e3,mainnet:1002541853}),ke);function Pe(e,t){var n=Ee[t][e];if(!n)throw new Error("No Validator App exists for ".concat(e," network with ").concat(t," contract version"));return n}function Se(){return(Se=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationOptInTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function De(){return(De=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationClearStateTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var Oe,Ne,Be,Ce=function(e){return e.FixedInput="fixed-input",e.FixedOutput="fixed-output",e}({}),Fe=.003,Le=function(e){return e[e.INPUT_TXN=0]="INPUT_TXN",e[e.APP_CALL_TXN=1]="APP_CALL_TXN",e}({}),Re=(l(Oe={},Ce.FixedInput,1),l(Oe,Ce.FixedOutput,2),Oe),Me=2,Ue=Te("swap"),je=(l(Ne={},Ce.FixedInput,Te("fixed-input")),l(Ne,Ce.FixedOutput,Te("fixed-output")),Ne),Ve={ASSET_OPT_IN:Te("asset_opt_in")},Ge={testnet:184778019,mainnet:1083651166},Xe=(l(Be={},Ce.FixedInput,7),l(Be,Ce.FixedOutput,8),Be);function qe(e){var t=Je(e),n=t.assetIn,r=t.assetOut;return he(r.asset.decimals,Number(r.amount))/he(n.asset.decimals,Number(n.amount))}function Qe(e){var t=Ge[e];if(!t)throw new Error("Unknown network or network not supported: ".concat(e));return t}function We(e){return e[e.length-1].quote.amount_out}function ze(e){return e[0].quote.amount_in}function Je(e){return{assetIn:ze(e),assetOut:We(e)}}function Ke(e){return Ye.apply(this,arguments)}function Ye(){return(Ye=i(s().mark((function t(n){var r,a,o,i,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.routerAppID,o=n.assetIDs,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a,appArgs:[Ve.ASSET_OPT_IN],foreignAssets:o,suggestedParams:u}),p=o.length,c.fee=e.ALGORAND_MIN_TX_FEE*(p+1),t.abrupt("return",c);case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function He(e){return $e.apply(this,arguments)}function $e(){return($e=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k,_,E,P,S,D;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.initiatorAddr,a=n.client,o=n.network,i=n.swapType,u=n.route,c=n.slippage,t.next=3,a.getTransactionParams().do();case 3:return p=t.sent,l=[ne(u[0].quote.amount_in.asset),ne(u[0].quote.amount_out.asset),ne(u[1].quote.amount_out.asset)],d=l[0],f=l[1],m=l[2],h=[Number(ze(u).amount),Number(We(u).amount)],g=h[0],x=h[1],A=[u[0].pool.address,u[1].pool.address],I=A[0],v=A[1],w=i===Ce.FixedInput?g:me("positive",c,g),y=i===Ce.FixedOutput?x:me("negative",c,x),b=te(d),T=Qe(o),k=b?e.makePaymentTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,suggestedParams:p}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,assetIndex:d,suggestedParams:p}),(_=e.makeApplicationNoOpTxnFromObject({from:r,appIndex:T,appArgs:[Ue,je[i],e.encodeUint64(y)],foreignApps:[Pe(o,U.V2)],foreignAssets:[d,f,m],accounts:[I,v],suggestedParams:p,note:_e.getAppCallTxnNoteWithClientName(U.V2)})).fee=e.ALGORAND_MIN_TX_FEE*(Xe[i]+1),E=[k,_],t.next=17,Ze({client:a,network:o,assetIDs:[d,f,m]});case 17:if(!((P=t.sent).length>0)){t.next=23;break}return t.next=21,Ke({client:a,initiatorAddr:r,assetIDs:P,routerAppID:T});case 21:S=t.sent,E.unshift(S);case 23:return D=e.assignGroupID(E),t.abrupt("return",D.map((function(e){return{txn:e,signers:[r]}})));case 25:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Ze(e){return et.apply(this,arguments)}function et(){return(et=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(Qe(a)),t.next=4,r.accountInformation(i).do();case 4:return u=t.sent,c=u.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!c.includes(e)})));case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function tt(e){return nt.apply(this,arguments)}function nt(){return(nt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetInID,a=t.assetOutID,o=t.swapType,i=t.network,u={asset_in_id:String(r),asset_out_id:String(a),swap_type:o,amount:String(n)},e.next=4,fetch("".concat(M[i].v1,"/swap-router/quotes/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}).catch((function(){throw new Error("Network error")}));case 4:return c=e.sent,e.next=7,c.json();case 7:if(p=e.sent,c.ok){e.next=14;break}if(s=p,!Boolean(s)||void 0===s.fallback_message){e.next=13;break}throw new E(p.type,p.fallback_message);case 13:throw new E(_.UnknownError,"There was an error while getting a quote from Swap Router");case 14:if(!(p.route.length<2)){e.next=16;break}throw new E(_.SwapRouterNoRouteError,"Swap router couldn't find a route for this swap.");case 16:return e.abrupt("return",p);case 17:case"end":return e.stop()}var s}),e)})))).apply(this,arguments)}var rt=function(e){return e.Direct="direct",e.Router="router",e}({}),at=4*e.ALGORAND_MIN_TX_FEE;function st(t){return(Re[t]+Me)*e.ALGORAND_MIN_TX_FEE}function ot(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Fe;return Math.ceil(1/e)}function it(e){return e1&&void 0!==arguments[1]?arguments[1]:Fe)}function ut(t){return(Re[t]+1)*e.ALGORAND_MIN_TX_FEE}function ct(e){var t=e.assetIn,n=e.assetOut;return he(n.decimals,Number(n.amount))/he(t.decimals,Number(t.amount))}function pt(e){var t=e.inputSupply,n=e.outputSupply,r=e.assetIn,a=e.assetOut,s=ct({assetIn:r,assetOut:a}),o=he(a.decimals,Number(n))/he(r.decimals,Number(t));return ge({decimalPlaces:5},Math.abs(s/o-1))}function lt(e){if(e.type===rt.Router){var t=ze(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetInID,amount:e.data.quote.assetInAmount}}function dt(e){if(e.type===rt.Router){var t=We(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetOutID,amount:e.data.quote.assetOutAmount}}function ft(e){return e.type===rt.Direct?e.data.pool.contractVersion:U.V2}function mt(e){return e.type===rt.Direct?e.data.quote.rate:qe(e.data.route)}function ht(e){for(var t=e[0],n=mt(t),r=1;rn&&(t=a,n=s)}return t}function gt(e){return e instanceof E&&[_.SwapRouterInsufficientReservesError,_.SwapRouterLowSwapAmountError,_.OutputAmountExceedsAvailableLiquidityError,_.LowSwapAmountError].includes(e.type)}var xt={type:"logicsig",logic:{bytecode:"BCAIAQCBgICAgICAgPABgICAgICAgIDwAQMEBQYlJA1EMQkyAxJEMRUyAxJEMSAyAxJEMgQiDUQzAQAxABJEMwEQIQcSRDMBGIGCgICAgICAgPABEkQzARkiEjMBGyEEEhA3ARoAgAlib290c3RyYXASEEAAXDMBGSMSRDMBG4ECEjcBGgCABHN3YXASEEACOzMBGyISRDcBGgCABG1pbnQSQAE7NwEaAIAEYnVybhJAAZg3ARoAgAZyZWRlZW0SQAJbNwEaAIAEZmVlcxJAAnkAIQYhBSQjEk0yBBJENwEaARclEjcBGgIXJBIQRDMCADEAEkQzAhAhBBJEMwIhIxJEMwIiIxwSRDMCIyEHEkQzAiQjEkQzAiWACFRNUE9PTDExEkQzAiZRAA+AD1RpbnltYW5Qb29sMS4xIBJEMwIngBNodHRwczovL3RpbnltYW4ub3JnEkQzAikyAxJEMwIqMgMSRDMCKzIDEkQzAiwyAxJEMwMAMQASRDMDECEFEkQzAxElEkQzAxQxABJEMwMSIxJEJCMTQAAQMwEBMwIBCDMDAQg1AUIBsTMEADEAEkQzBBAhBRJEMwQRJBJEMwQUMQASRDMEEiMSRDMBATMCAQgzAwEIMwQBCDUBQgF8MgQhBhJENwEcATEAE0Q3ARwBMwQUEkQzAgAxABNEMwIUMQASRDMDADMCABJEMwIRJRJEMwMUMwMHMwMQIhJNMQASRDMDESMzAxAiEk0kEkQzBAAxABJEMwQUMwIAEkQzAQEzBAEINQFCAREyBCEGEkQ3ARwBMQATRDcBHAEzAhQSRDMDFDMDBzMDECISTTcBHAESRDMCADEAEkQzAhQzBAASRDMCESUSRDMDADEAEkQzAxQzAwczAxAiEk0zBAASRDMDESMzAxAiEk0kEkQzBAAxABNEMwQUMQASRDMBATMCAQgzAwEINQFCAJAyBCEFEkQ3ARwBMQATRDMCADcBHAESRDMCADEAE0QzAwAxABJEMwIUMwIHMwIQIhJNMQASRDMDFDMDBzMDECISTTMCABJEMwEBMwMBCDUBQgA+MgQhBBJENwEcATEAE0QzAhQzAgczAhAiEk03ARwBEkQzAQEzAgEINQFCABIyBCEEEkQzAQEzAgEINQFCAAAzAAAxABNEMwAHMQASRDMACDQBD0M=",address:"ABUKAXTANWR6K6ZYV75DWJEPVWWOU6SFUVRI6QHO44E4SIDLHBTD2CZ64A",size:881,variables:[{name:"TMPL_ASSET_ID_1",type:"int",index:15,length:10},{name:"TMPL_ASSET_ID_2",type:"int",index:5,length:10},{name:"TMPL_VALIDATOR_APP_ID",type:"int",index:74,length:10}],source:"https://github.com/tinymanorg/tinyman-contracts-v1/tree/dc9ab40c58b85c15d58f63a1507e18be76720dbb/contracts/pool_logicsig.teal.tmpl"},name:"pool_logicsig"},At={type:"app",global_state_schema:{num_uints:0,num_byte_slices:0},local_state_schema:{num_uints:16,num_byte_slices:0},name:"validator_app"},It=p((function e(t){u(this,e),this.schema={numLocalInts:t.local_state_schema.num_uints,numLocalByteSlices:t.local_state_schema.num_byte_slices,numGlobalInts:t.global_state_schema.num_uints,numGlobalByteSlices:t.global_state_schema.num_byte_slices}})),vt=function(n){d(a,It);var r=I(a);function a(e,t){var n;return u(this,a),(n=r.call(this,e)).poolLogicSigContractTemplate=t.logic.bytecode,n.templateVariables=t.logic.variables,n}return p(a,[{key:"generateLogicSigAccountForPool",value:function(n){if(n.asset1ID===n.asset2ID)throw new Error("Assets are the same");var r=Pe(n.network,U.V1_1),a=v(ee(n.asset1ID,n.asset2ID),2),s=a[0],o=a[1],i=Array.from(t.toByteArray(this.poolLogicSigContractTemplate)),u={asset_id_1:s,asset_id_2:o,validator_app_id:r},c=0;this.templateVariables.sort((function(e,t){return e.index-t.index}));for(var p=0;p2&&void 0!==arguments[2]?arguments[2]:e.IntDecoding.DEFAULT;return new Promise(function(){var e=i(s().mark((function e(o,i){var u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.accountInformation(n).setIntDecoding(r).do();case 3:u=e.sent,o(a(a({},u),{},{minimum_required_balance:Pt(u)})),e.next=10;break;case 7:e.prev=7,e.t0=e.catch(0),i(new Error(e.t0.message||"Failed to fetch account information"));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}())}function Et(e,t){var n=e["apps-local-state"].find((function(e){return e.id===t}));return n?re({stateArray:n["key-value"],shouldDecodeKeys:!0}):null}function Pt(e){var t=e["apps-total-schema"];return S+D*(e.assets||[]).length+N*(e["created-apps"]||[]).length+O*(e["apps-local-state"]||[]).length+C*Number(t&&t["num-byte-slice"]||0)+F*Number(t&&t["num-uint"]||0)+B*(e["apps-total-extra-pages"]||0)}var St=Te("e");function Dt(e){return Ot.apply(this,arguments)}function Ot(){return(Ot=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,k,_;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.pool,i=r.accountAddr,n.next=3,a.accountInformation(i).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:u=n.sent,c=u["apps-local-state"]||[],p=0n,l=0n,d=0n,f=o.account.address(),m=T(c),n.prev=10,m.s();case 12:if((h=m.n()).done){n.next=31;break}if((g=h.value).id==o.validatorAppID){n.next=16;break}return n.abrupt("continue",29);case 16:if(x=g["key-value"]){n.next=19;break}return n.abrupt("break",31);case 19:A=re({stateArray:x}),I=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset1ID)])),v=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset2ID)])),w=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.poolTokenID)])),y=A[I],b=A[v],k=A[w],"bigint"==typeof y&&(p=y),"bigint"==typeof b&&(l=b),"bigint"==typeof k&&(d=k);case 29:n.next=12;break;case 31:n.next=36;break;case 33:n.prev=33,n.t0=n.catch(10),m.e(n.t0);case 36:return n.prev=36,m.f(),n.finish(36);case 39:if(!((_={excessAsset1:p,excessAsset2:l,excessPoolTokens:d}).excessAsset1<0n||_.excessAsset2<0n||_.excessPoolTokens<0n)){n.next=42;break}throw new Error("Invalid account excess: ".concat(_));case 42:return n.abrupt("return",_);case 43:case"end":return n.stop()}}),n,null,[[10,33,36,39]])})))).apply(this,arguments)}function Nt(){return(Nt=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.accountAddr,i=r.validatorAppID,n.next=3,a.accountInformation(o).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:if(u=n.sent,c=u["apps-local-state"]||[],p=c.find((function(e){return e.id==i})),l=[],p&&p["key-value"])for(d=re({stateArray:p["key-value"]}),f=0,m=Object.entries(d);fMt)){n.next=48;break}throw new Error("Issued liquidity value is out of the expected range ([0n, ".concat(Mt,"]): ").concat(N.issuedLiquidity));case 48:return n.abrupt("return",N);case 49:case"end":return n.stop()}}),n,null,[[8,31,34,37]])})))).apply(this,arguments)}function Gt(){return Gt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.address,a=t.network,!(o=d.length>1&&void 0!==d[1]?d[1]:{})[r]){e.next=4;break}return e.abrupt("return",o[r]);case 4:return e.next=6,_t(n,r);case 6:return i=e.sent,u=Et(i,Pe(a,U.V1_1)),c=null,u&&(l=i["created-assets"][0],p=l.index,c={asset1ID:u[Ft[U.V1_1].asset1],asset2ID:u[Ft[U.V1_1].asset2],poolTokenID:p},o[r]=c),e.abrupt("return",c);case 11:case"end":return e.stop()}}),e)}))),Gt.apply(this,arguments)}var Xt=Object.freeze({__proto__:null,getPoolAssets:function(e){return Gt.apply(this,arguments)},getPoolInfo:Ut,getPoolReserves:function(e,t){return Vt.apply(this,arguments)}});function qt(e){return Qt.apply(this,arguments)}function Qt(){return(Qt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.asset1ID,o=t.asset2ID,i=kt(U.V2),u=i.generateLogicSigAccountForPool(t),c=Pe(r,U.V2),p=u.address(),l=ee(a,o),e.next=8,_t(n,p);case 8:return d=e.sent,f=Et(d,c),m={account:u,validatorAppID:c,asset1ID:l[0],asset2ID:l[1],status:f?Ct.READY:Ct.NOT_CREATED,contractVersion:U.V2},f&&(m.asset1ProtocolFees=BigInt(f[Ft.v2.asset1ProtocolFees]),m.asset2ProtocolFees=BigInt(f[Ft.v2.asset2ProtocolFees]),m.asset1Reserves=BigInt(f[Ft.v2.asset1Reserves]),m.asset2Reserves=BigInt(f[Ft.v2.asset2Reserves]),m.issuedPoolTokens=BigInt(f[Ft.v2.issuedPoolTokens]),m.cumulativePriceUpdateTimeStamp=Number(f[Ft.v2.cumulativePriceUpdateTimeStamp]),m.protocolFeeRatio=Number(f[Ft.v2.protocolFeeRatio]),m.totalFeeShare=BigInt(f[Ft.v2.totalFeeShare]),m.poolTokenID=Number(f[Ft.v2.poolTokenID]),m.asset1ID=Number(f[Ft.v2.asset1]),m.asset2ID=Number(f[Ft.v2.asset2])),e.abrupt("return",m);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Wt(){return(Wt=i(s().mark((function e(t,n){var r,a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_t(t,n.account.address());case 2:return r=e.sent,a=Et(r,n.validatorAppID),o={asset1:0n,asset2:0n,issuedLiquidity:0n,round:r.round},a&&(o.asset1=BigInt(a[Ft.v2.asset1Reserves]),o.asset2=BigInt(a[Ft.v2.asset2Reserves]),o.issuedLiquidity=BigInt(a[Ft.v2.issuedPoolTokens])),e.abrupt("return",o);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zt(){return(zt=i(s().mark((function e(t){var n,r,a,o,i,u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.address,a=t.network,e.next=3,_t(n,r);case 3:return o=e.sent,i=Et(o,Pe(a,U.V2)),u=null,i&&(u={asset1ID:i[Ft[U.V2].asset1],asset2ID:i[Ft[U.V2].asset2],poolTokenID:i[Ft[U.V2].poolTokenID]}),e.abrupt("return",u);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jt=Object.freeze({__proto__:null,getPoolAssets:function(e){return zt.apply(this,arguments)},getPoolInfo:qt,getPoolReserves:function(e,t){return Wt.apply(this,arguments)}});function Kt(e){return Boolean(e&&!(e.asset1+e.asset2))}var Yt,Ht=Object.freeze({__proto__:null,getPoolPairRatio:function(e){var t=Kt(e),n=null;return e&&!t&&e.asset1&&e.asset2&&(n=Number(e.asset1)/Number(e.asset2)),n},getPoolShare:function(e,t){var n=Number(t)/Number(e);return Number.isFinite(n)||(n=0),n},getPoolsForPair:function(e){return Promise.all([Ut(e),qt(e)])},isPoolEmpty:Kt,isPoolNotCreated:function(e){return(null==e?void 0:e.status)===Ct.NOT_CREATED},isPoolReady:function(e){return(null==e?void 0:e.status)===Ct.READY}}),$t=a((l(Yt={},U.V1_1,a(a({},Xt),Ht)),l(Yt,U.V2,a(a({},Jt),Ht)),Yt),Ht),Zt=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e[e.POOL_TOKEN_CREATE=2]="POOL_TOKEN_CREATE",e[e.ASSET1_OPT_IN=3]="ASSET1_OPT_IN",e[e.ASSET2_OPT_IN=4]="ASSET2_OPT_IN",e}({}),en={ASA_ALGO:96e4,ASA_ASA:859e3};function tn(){return(tn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T,k,_,E,P,S;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Z(o,i),l=v(p,2),d=l[0],f=d.id,m=d.unit_name,h=l[1],g=h.id,x=h.unit_name,A=te(g),I=Pe(a,U.V1_1),w=wt.generateLogicSigAccountForPool({network:a,asset1ID:f,asset2ID:g}),y=w.address(),b=e.makeApplicationOptInTxnFromObject({from:y,appIndex:I,note:_e.getAppCallTxnNoteWithClientName(U.V1_1),appArgs:[Te("bootstrap"),e.encodeUint64(f),e.encodeUint64(g)],foreignAssets:A?[f]:[g],suggestedParams:c}),T=e.makeAssetCreateTxnWithSuggestedParamsFromObject({from:y,total:0xffffffffffffffffn,decimals:6,defaultFrozen:!1,unitName:G.V1_1,assetName:"TinymanPool1.1 ".concat(m,"-").concat(x),assetURL:"https://tinyman.org",suggestedParams:c}),k=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:f,amount:0,suggestedParams:c}),_=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:y,amount:nn(A),suggestedParams:c}),(E=[])[Zt.FUNDING_TXN]=_,E[Zt.VALIDATOR_APP_CALL]=b,E[Zt.POOL_TOKEN_CREATE]=T,E[Zt.ASSET1_OPT_IN]=k,A||(E[Zt.ASSET2_OPT_IN]=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:g,amount:0,suggestedParams:c})),P=e.assignGroupID(E),S=[{txn:P[Zt.FUNDING_TXN],signers:[u]},{txn:P[Zt.VALIDATOR_APP_CALL],signers:[y]},{txn:P[Zt.POOL_TOKEN_CREATE],signers:[y]},{txn:P[Zt.ASSET1_OPT_IN],signers:[y]}],P[Zt.ASSET2_OPT_IN]&&S.push({txn:P[Zt.ASSET2_OPT_IN],signers:[y]}),t.abrupt("return",S);case 23:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function nn(e){return e?en.ASA_ALGO:en.ASA_ASA}function rn(){return(rn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=wt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===Zt.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function an(e){return sn.apply(this,arguments)}function sn(){return(sn=i(s().mark((function e(t){var n,r,a,o,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.signedTxns,a=t.txnIDs,e.prev=1,e.next=4,n.sendRawTransaction(r).do();case 4:return e.next=6,de(n,a[Zt.POOL_TOKEN_CREATE]);case 6:if(o=e.sent,"number"==typeof(i=o["asset-index"])){e.next=10;break}throw new Error("Generated ID is not valid: got ".concat(i));case 10:return e.abrupt("return",{poolTokenID:i});case 13:throw e.prev=13,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while bootstraping the pool. Try again later.");case 16:case"end":return e.stop()}}),e,null,[[1,13]])})))).apply(this,arguments)}function on(){return(on=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.signedTxns,c=t.txnIDs,e.next=3,an({client:n,signedTxns:u,txnIDs:c});case 3:return e.abrupt("return",$t.v1_1.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var un={generateTxns:function(e){return tn.apply(this,arguments)},signTxns:function(e){return rn.apply(this,arguments)},execute:function(e){return on.apply(this,arguments)},getBootstrapFundingTxnAmount:nn};var cn=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e}({}),pn={ASA_ALGO:5,ASA_ASA:6};function ln(e,t){return dn.apply(this,arguments)}function dn(){return(dn=i(s().mark((function t(n,r){var a,o,i;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(o=null===(a=r.find((function(e){return"appl"===e.txn.type})))||void 0===a?void 0:a.txn.txID())){t.next=7;break}return t.next=4,e.waitForConfirmation(n,o,R);case 4:t.t0=t.sent,t.next=8;break;case 7:t.t0=void 0;case 8:return i=t.t0,t.abrupt("return",i);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function fn(e,t){return mn.apply(this,arguments)}function mn(){return(mn=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ln(t,n);case 2:return r=e.sent,e.abrupt("return",null==r?void 0:r["inner-txns"]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function hn(e,t){return gn.apply(this,arguments)}function gn(){return(gn=i(s().mark((function t(n,r){var a,o;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fn(n,r);case 2:return a=t.sent,s=r[0].txn,o=e.encodeAddress(s.from.publicKey),t.abrupt("return",null==a?void 0:a.reduce((function(t,n){var r=t,a=n.txn.txn;return a.type===e.TransactionType.axfer&&e.encodeAddress(a.arcv)===o?r.push({id:a.xaid,amount:a.aamt}):a.type===e.TransactionType.pay&&e.encodeAddress(a.rcv)===o&&r.push({id:j,amount:a.amt}),r}),[]));case 5:case"end":return t.stop()}var s}),t)})))).apply(this,arguments)}function xn(){return(xn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Pe(a,U.V2),l=e.getApplicationAddress(p),d=Z(o,i),f=v(d,2),m=f[0].id,h=f[1].id,t.next=9,$t.v2.getPoolInfo({client:r,network:a,asset1ID:m,asset2ID:h});case 9:if(t.sent.status!==Ct.READY){t.next=12;break}throw new Error("Pool for ".concat(o.unit_name,"-").concat(i.unit_name," already exists"));case 12:return g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=g.address(),A=te(h),(I=e.makeApplicationOptInTxnFromObject({from:x,appIndex:p,appArgs:[Te("bootstrap")],note:_e.getAppCallTxnNoteWithClientName(U.V2),foreignAssets:[m,h],rekeyTo:l,suggestedParams:c})).fee=In(A),w=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:x,amount:An(A),suggestedParams:c}),(y=[])[cn.FUNDING_TXN]=w,y[cn.VALIDATOR_APP_CALL]=I,b=e.assignGroupID(y),(T=[])[cn.FUNDING_TXN]={txn:b[cn.FUNDING_TXN],signers:[u]},T[cn.VALIDATOR_APP_CALL]={txn:b[cn.VALIDATOR_APP_CALL],signers:[x]},t.abrupt("return",T);case 26:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function An(e){return function(e,t){var n=kt(e).schema,r=n.numLocalInts,a=n.numLocalByteSlices,s=S+D+D+O+F*r+C*a;return t||(s+=D),s}(U.V2,e)+In(e)+D}function In(t){return((t?pn.ASA_ALGO:pn.ASA_ASA)+1)*e.ALGORAND_MIN_TX_FEE}function vn(){return(vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===cn.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function wn(){return(wn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.txGroup,c=t.signedTxns,e.prev=1,e.next=4,n.sendRawTransaction(c).do();case 4:return e.next=6,ln(n,u);case 6:if(e.t1=p=e.sent,e.t0=null===e.t1,e.t0){e.next=10;break}e.t0=void 0===p;case 10:if(!e.t0){e.next=14;break}e.t2=void 0,e.next=15;break;case 14:e.t2=null===(l=p["local-state-delta"][0].delta)||void 0===l||null===(d=l.find((function(e){return e.key===btoa(Ft.v2.poolTokenID)})))||void 0===d?void 0:d.value.uint;case 15:if("number"==typeof(f=e.t2)){e.next=18;break}throw new Error("Generated ID is not valid: got ".concat(f));case 18:return e.abrupt("return",$t.v2.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 21:throw e.prev=21,e.t3=e.catch(1),new Y(e.t3,"We encountered something unexpected while bootstraping the pool. Try again later.");case 24:case"end":return e.stop()}}),e,null,[[1,21]])})))).apply(this,arguments)}var yn,bn={generateTxns:function(e){return xn.apply(this,arguments)},signTxns:function(e){return vn.apply(this,arguments)},execute:function(e){return wn.apply(this,arguments)},getBootstrapFundingTxnAmount:An,getTotalCost:function(t){return e.ALGORAND_MIN_TX_FEE+An(t)}};var Tn,kn,_n,En,Pn=(l(yn={},U.V1_1,un),l(yn,U.V2,bn),l(yn,"generateTxns",(function(e){return e.contractVersion===U.V1_1?un.generateTxns(e):bn.generateTxns(e)})),l(yn,"signTxns",(function(e){return e.contractVersion===U.V1_1?un.signTxns(e):bn.signTxns(e)})),l(yn,"execute",(function(e){return e.contractVersion===U.V1_1?un.execute(e):bn.execute(e)})),l(yn,"calculateBootstrapFundingTxnAmount",(function(e){var t=e.contractVersion,n=e.isAlgoPool;return t===U.V1_1?un.getBootstrapFundingTxnAmount(n):bn.getBootstrapFundingTxnAmount(n)})),yn),Sn=function(e){return e[e.FEE_TXN=0]="FEE_TXN",e[e.VALIDATOR_APP_CALL_TXN=1]="VALIDATOR_APP_CALL_TXN",e[e.ASSET1_IN_TXN=2]="ASSET1_IN_TXN",e[e.ASSET2_IN_TXN=3]="ASSET2_IN_TXN",e[e.LIQUDITY_OUT_TXN=4]="LIQUDITY_OUT_TXN",e}({}),Dn=5*e.ALGORAND_MIN_TX_FEE,On=function(e){return e.SINGLE="single",e.FLEXIBLE="flexible",e.INITIAL="initial",e}({}),Nn=(l(Tn={},On.FLEXIBLE,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),l(Tn,On.SINGLE,{ASSET_IN_TXN:0,VALIDATOR_APP_CALL_TXN:1}),l(Tn,On.INITIAL,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),Tn),Bn=(l(kn={},On.INITIAL,1),l(kn,On.SINGLE,2),l(kn,On.FLEXIBLE,2),kn),Cn=(l(_n={},On.INITIAL,3),l(_n,On.FLEXIBLE,3),l(_n,On.SINGLE,2),_n);function Fn(e){var t,n,r,a=e.reserves,s=e.totalFeeShare,o=e.asset1,i=e.asset2,u=a.asset1*a.asset2,c=a.asset1+BigInt(o.amount),p=a.asset2+BigInt(i.amount),l=c*p,d=BigInt(parseInt(String(Math.sqrt(Number(l*a.issuedLiquidity*a.issuedLiquidity/u))))),f=d-a.issuedLiquidity,m=f*c/d,h=f*p/d,g=BigInt(o.amount)-m,x=BigInt(i.amount)-h;if(g>x){var A=g;r=Rn(A,s),t={id:o.id,amount:A+r,decimals:o.decimals,reserves:a.asset1},n={id:i.id,amount:BigInt(Math.abs(Math.min(Number(x),0))),decimals:i.decimals,reserves:a.asset2},f-=r*d/(c*BigInt(2))}else{var I=x;r=Rn(I,s),t={id:i.id,amount:I+r,decimals:i.decimals,reserves:a.asset2},n={id:o.id,amount:BigInt(Math.abs(Math.min(Number(g),0))),decimals:o.decimals,reserves:a.asset1},f-=r*d/(p*BigInt(2))}return{poolTokenOutAmount:f,internalSwapQuote:{assetIn:t,assetOut:n,swapFees:r,priceImpact:pt({inputSupply:t.reserves,outputSupply:n.reserves,assetIn:t,assetOut:n})}}}function Ln(e,t){if(!e.amount||!t.amount)throw new Error("Both assets are required for the initial add liquidity");return BigInt(Math.floor(Math.abs(Math.sqrt(Number(e.amount)*Number(t.amount))-Lt)))}function Rn(e,t){return e*BigInt(t)/(BigInt(1e4)-BigInt(t))}function Mn(t){return(Bn[t]+1)*e.ALGORAND_MIN_TX_FEE}var Un=Te("add_liquidity"),jn=(l(En={},U.V1_1,[Te("mint")]),l(En,U.V2,{INITIAL_LIQUIDITY:[Te("add_initial_liquidity")],SINGLE_ASSET_MODE:[Un,Te("single")],FLEXIBLE_MODE:[Un,Te("flexible")]}),En);function Vn(){return(Vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.asset1In,u=n.asset2In,c=n.poolTokenOut,p=n.slippage,l=n.initiatorAddr,d=me("negative",p,c.amount),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:Pe(a,U.V1_1),appArgs:jn.v1_1,accounts:[l],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:u.id==j?[i.id,c.id]:[i.id,u.id,c.id],suggestedParams:f}),h=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:i.id,amount:i.amount,suggestedParams:f}),g=u.id===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:u.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:u.id,amount:u.amount,suggestedParams:f}),x=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:l,assetIndex:c.id,amount:d,suggestedParams:f}),A=e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:m.fee+x.fee,note:P,suggestedParams:f}),I=e.assignGroupID([A,m,h,g,x]),t.abrupt("return",[{txn:I[0],signers:[l]},{txn:I[1],signers:[o]},{txn:I[2],signers:[l]},{txn:I[3],signers:[l]},{txn:I[4],signers:[o]}]);case 12:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Gn(){return(Gn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,i=r.account,t.next=4,o([a]);case 4:return u=t.sent,c=v(u,3),p=c[0],l=c[1],d=c[2],f=a.map((function(t,n){return n===Sn.FEE_TXN?p:n===Sn.ASSET1_IN_TXN?l:n===Sn.ASSET2_IN_TXN?d:e.signLogicSigTransactionObject(t.txn,i).blob})),t.abrupt("return",f);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Xn(){return(Xn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.signedTxns,i=t.initiatorAddr,e.prev=1,u=BigInt(a[Sn.LIQUDITY_OUT_TXN].txn.amount),e.next=5,Dt({client:n,pool:r,accountAddr:i});case 5:return c=e.sent,e.next=8,Ie(n,[o]);case 8:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,h=we(a),g=ye(a),e.next=17,Dt({client:n,pool:r,accountAddr:i});case 17:return x=e.sent,(A=x.excessPoolTokens-c.excessPoolTokens)<0n&&(A=0n),e.abrupt("return",{round:f,fees:h,poolTokenID:r.poolTokenID,poolTokenOut:u+A,excessAmount:{excessAmountForAddingLiquidity:A,totalExcessAmount:x.excessPoolTokens},txnID:m,groupID:g});case 23:throw e.prev=23,e.t0=e.catch(1),"SlippageTolerance"===(I=new Y(e.t0,"We encountered something unexpected while adding liquidity. Try again later.")).type&&I.setMessage("Adding liquidity failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),I;case 28:case"end":return e.stop()}}),e,null,[[1,23]])})))).apply(this,arguments)}var qn=Object.freeze({__proto__:null,execute:function(e){return Xn.apply(this,arguments)},generateTxns:function(e){return Vn.apply(this,arguments)},getQuote:function(e){var t=e.pool,n=e.reserves,r=e.asset1In,a=e.asset2In;if(0n===n.issuedLiquidity){var s=BigInt(Math.floor(Math.sqrt(Number(r)*Number(a))));if(s<=BigInt(L))throw new Error("Initial liquidity amount is too small. The amount must be greater than ".concat(L,", this quote is for ").concat(s,"."));return{round:n.round,asset1ID:t.asset1ID,asset1In:BigInt(r),asset2ID:t.asset2ID,asset2In:BigInt(a),poolTokenID:t.poolTokenID,poolTokenOut:s-BigInt(L),share:1}}var o=BigInt(r)*n.issuedLiquidity/n.asset1,i=BigInt(a)*n.issuedLiquidity/n.asset2,u=oo)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(t)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{assetInID:i,assetInAmount:l,assetOutID:c,assetOutAmount:m,swapFee:Number(h),rate:he(p,Number(m))/he(u,Number(l)),priceImpact:g}}function xr(e){var t=e.amount,n=e.assetIn,r=e.assetOut,a=e.pool;if(!a||!$t.isPoolReady(a))throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i=n.id,u=n.decimals,c=r.id,p=r.decimals,l=BigInt(t),d=a.totalFeeShare;if(c===a.asset1ID)s=a.asset2Reserves,o=a.asset1Reserves;else{if(c!==a.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(c,") doesn't belong to the pool ").concat(a.account.address(),"."));s=a.asset1Reserves,o=a.asset2Reserves}var f=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapOutputAmount,a=e.totalFeeShare,s=e.decimals,o=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.outputAmount,a=t*n,s=BigInt(a/(n-r))-t;return s+=BigInt(1),s}({inputSupply:t,outputSupply:n,outputAmount:r}),i=function(e){var t=e.swapAmount,n=e.totalFeeShare,r=Math.floor(Number(t*BigInt(1e4)/(BigInt(1e4)-BigInt(n)))),a=BigInt(r)-t;return a}({swapAmount:o,totalFeeShare:a}),u=o+i,c=pt({inputSupply:t,outputSupply:n,assetIn:{amount:u,decimals:s.assetIn},assetOut:{amount:r,decimals:s.assetOut}});return{swapInputAmount:u,totalFeeAmount:i,priceImpact:c}}({inputSupply:s,outputSupply:o,swapOutputAmount:l,totalFeeShare:d,decimals:{assetIn:u,assetOut:p}}),m=f.swapInputAmount,h=f.totalFeeAmount,g=f.priceImpact;if(l>o)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(m)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{type:rt.Direct,data:{pool:a,quote:{assetInID:i,assetInAmount:m,assetOutID:c,assetOutAmount:l,swapFee:Number(h),rate:he(p,Number(l))/he(u,Number(m)),priceImpact:g}}}}function Ar(e){return Ir.apply(this,arguments)}function Ir(){return(Ir=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[],u?c.push(new Promise((function(e,t){try{var s=gr({amount:n,assetIn:r,assetOut:a,pool:u});e({type:rt.Direct,data:{pool:u,quote:s}})}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair"))),o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedInput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=6,hr(c);case 6:return p=e.sent,e.abrupt("return",ht(p));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function vr(e){return wr.apply(this,arguments)}function wr(){return(wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[new Promise((function(e,t){try{e(xr({amount:n,assetIn:r,assetOut:a,pool:u}))}catch(e){t(e)}}))],o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedOutput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=5,hr(c);case 5:return p=e.sent,e.abrupt("return",ht(p));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function yr(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapInputAmount,a=e.totalFeeShare,s=e.decimals,o=BigInt(function(e){var t=e.inputAmount,n=e.totalFeeShare;return Math.floor(Number(t*BigInt(n))/1e4)}({inputAmount:r,totalFeeShare:a})),i=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapAmount,a=t*n,s=n-BigInt(a/(t+BigInt(r)));return s-=BigInt(1)}({inputSupply:t,outputSupply:n,swapAmount:r-o});return{swapOutputAmount:i,totalFeeAmount:o,priceImpact:pt({inputSupply:t,outputSupply:n,assetIn:{amount:r,decimals:s.assetIn},assetOut:{amount:i,decimals:s.assetOut}})}}var br={getQuote:function(e){return mr.apply(this,arguments)},getFixedInputSwapQuote:Ar,getFixedInputDirectSwapQuote:gr,getFixedOutputDirectSwapQuote:xr,getFixedOutputSwapQuote:vr,generateTxns:function(e){return dr.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return fr.apply(this,arguments)},calculateFixedInputSwap:yr};function Tr(e,t){var n,r,a=BigInt(e),s=t.issuedLiquidity;return s>a+BigInt(Lt)?(n=a*t.asset1/s,r=a*t.asset2/s):(n=t.asset1,r=t.asset2),{asset1OutputAmount:n,asset2OutputAmount:r}}function kr(){return(kr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.minAsset1Amount,c=n.minAsset2Amount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.account.address(),f=a.poolTokenID){t.next=8;break}throw new Error("Pool token asset ID is missing");case 8:return m=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:f,amount:o,suggestedParams:l}),(h=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(me("negative",p,u)),e.encodeUint64(me("negative",p,c))],accounts:[d],foreignAssets:[a.asset1ID,a.asset2ID],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(g=[])[ir.ASSET_TRANSFER_TXN]=m,g[ir.APP_CALL_TXN]=h,x=e.assignGroupID(g),t.abrupt("return",[{txn:x[ir.ASSET_TRANSFER_TXN],signers:[i]},{txn:x[ir.APP_CALL_TXN],signers:[i]}]);case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _r(){return(_r=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.initiatorAddr,i=n.poolTokenIn,u=n.outputAssetId,c=n.minOutputAssetAmount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.asset1ID,f=a.asset2ID,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:if(g=0,x=0,A=me("negative",p,c),u!==d){t.next=17;break}g=A,x=0,t.next=23;break;case 17:if(u!==f){t.next=22;break}g=0,x=A,t.next=23;break;case 22:throw new Error("Invalid output asset id. It doesn't match with pool assets");case 23:return I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:m,assetIndex:h,amount:i,suggestedParams:l}),(v=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(g),e.encodeUint64(x)],accounts:[m],foreignAssets:[u],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(w=[])[ir.ASSET_TRANSFER_TXN]=I,w[ir.APP_CALL_TXN]=v,y=e.assignGroupID(w),t.abrupt("return",[{txn:y[ir.ASSET_TRANSFER_TXN],signers:[o]},{txn:y[ir.APP_CALL_TXN],signers:[o]}]);case 31:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Er(){return(Er=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.txGroup,a=t.signedTxns,e.next=3,Ie(n,[a]);case 3:return o=e.sent,i=v(o,1),u=i[0].txnID,e.prev=6,e.next=9,hn(n,r);case 9:c=e.sent,e.next=14;break;case 12:e.prev=12,e.t0=e.catch(6);case 14:return e.abrupt("return",{outputAssets:c,txnID:u});case 15:case"end":return e.stop()}}),e,null,[[6,12]])})))).apply(this,arguments)}var Pr,Sr={getQuote:function(e){var t=e.pool,n=e.reserves,r=e.poolTokenIn,a=BigInt(r),s=Tr(a,n),o=s.asset1OutputAmount,i=s.asset2OutputAmount;return{round:n.round,asset1Out:{assetId:t.asset1ID,amount:o},asset2Out:{assetId:t.asset2ID,amount:i},poolTokenIn:{assetId:t.poolTokenID,amount:a}}},getSingleAssetRemoveLiquidityQuote:function(e){var t,n=e.pool,r=e.reserves,a=e.poolTokenIn,s=e.assetOutID,o=e.decimals,i=BigInt(a),u=Tr(i,r),c=u.asset1OutputAmount,p=u.asset2OutputAmount,l=n.totalFeeShare;if(s===n.asset1ID){var d=br.calculateFixedInputSwap({inputSupply:r.asset2-p,outputSupply:r.asset1-c,swapInputAmount:p,totalFeeShare:l,decimals:o}),f=d.swapOutputAmount,m=d.totalFeeAmount,h=d.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:c+f},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:f},swapFees:{assetId:n.asset2ID,amount:m},priceImpact:h}}}else{if(s!==n.asset2ID)throw new Error("assetOutID must be one of the pool assets");var g=br.calculateFixedInputSwap({inputSupply:r.asset1-c,outputSupply:r.asset2-p,swapInputAmount:c,totalFeeShare:l,decimals:o}),x=g.swapOutputAmount,A=g.totalFeeAmount,I=g.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:p+x},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:x},swapFees:{assetId:n.asset2ID,amount:A},priceImpact:I}}}return t},generateTxns:function(e){return kr.apply(this,arguments)},generateSingleAssetOutTxns:function(e){return _r.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return Er.apply(this,arguments)}},Dr=(l(Pr={},U.V1_1,lr),l(Pr,U.V2,Sr),Pr),Or=3n,Nr=1000n,Br=function(e){return e[e.FEE_TXN_INDEX=0]="FEE_TXN_INDEX",e[e.VALIDATOR_APP_CALL_TXN_INDEX=1]="VALIDATOR_APP_CALL_TXN_INDEX",e[e.ASSET_IN_TXN_INDEX=2]="ASSET_IN_TXN_INDEX",e[e.ASSET_OUT_TXN_INDEX=3]="ASSET_OUT_TXN_INDEX",e}(Br||{});function Cr(){return(Cr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,t.next=3,o([a]);case 3:return i=t.sent,u=v(i,2),c=u[0],p=u[1],l=a.map((function(t,n){return n===Br.FEE_TXN_INDEX?c:n===Br.ASSET_IN_TXN_INDEX?p:e.signLogicSigTransactionObject(t.txn,r.account.lsig).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Fr(){return(Fr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=n.client,a=n.quoteAndPool,o=n.swapType,i=n.slippage,u=n.initiatorAddr,c=a.pool,p=a.quote,l=p.assetInID,d=p.assetOutID,f=c.account.address(),(m=[c.asset1ID,c.asset2ID]).includes(l)&&m.includes(d)&&l!==d){t.next=7;break}throw new Y({pool:c,quote:p},"Input asset (#".concat(l,") and output asset (#").concat(d,") provided to generate transactions do not belong to the pool ").concat(f,"."));case 7:return t.next=9,r.getTransactionParams().do();case 9:return h=t.sent,g=[Te("swap"),o===Ce.FixedInput?Te("fi"):Te("fo")],x=e.makeApplicationNoOpTxnFromObject({from:f,appIndex:c.validatorAppID,appArgs:g,accounts:[u],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:c.asset2ID==j?[c.asset1ID,c.poolTokenID]:[c.asset1ID,c.asset2ID,c.poolTokenID],suggestedParams:h}),A=o===Ce.FixedOutput?me("positive",i,p.assetInAmount):p.assetInAmount,I=l===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:A,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:u,to:f,assetIndex:l,amount:A,suggestedParams:h}),v=o===Ce.FixedInput?me("negative",i,p.assetOutAmount):p.assetOutAmount,w=d===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:f,to:u,amount:v,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:f,to:u,assetIndex:d,amount:v,suggestedParams:h}),y=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:x.fee+w.fee,note:P,suggestedParams:h}),b=e.assignGroupID([y,x,I,w]),t.abrupt("return",[{txn:b[0],signers:[u]},{txn:b[1],signers:[f]},{txn:b[2],signers:[u]},{txn:b[3],signers:[f]}]);case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Lr(e){var t=e.pool,n=e.reserves,r=e.assetIn,s=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var o,i,u,c=BigInt(r.amount);if(r.id===t.asset1ID)o=t.asset2ID,i=n.asset1,u=n.asset2;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Input asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));o=t.asset1ID,i=n.asset2,u=n.asset1}var p=c*Or/Nr,l=u-i*u/(i+(c-p));if(l>u)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var d={assetIn:{amount:c,decimals:s.assetIn},assetOut:{amount:l,decimals:s.assetOut}},f={round:n.round,assetInID:r.id,assetInAmount:c,assetOutID:o,assetOutAmount:l,swapFee:Number(p),rate:ct(d),priceImpact:pt(a({inputSupply:i,outputSupply:u},d))};return{type:rt.Direct,data:{pool:t,quote:f}}}function Rr(e){return Mr.apply(this,arguments)}function Mr(){return(Mr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,i.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount),assetOutID:i.id,assetOutAmount:BigInt(i.amount)+A,excessAmount:{assetID:i.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ur(e){var t=e.pool,n=e.reserves,r=e.assetOut,a=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i,u=BigInt(r.amount);if(r.id===t.asset1ID)s=t.asset2ID,o=n.asset2,i=n.asset1;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));s=t.asset1ID,o=n.asset1,i=n.asset2}if(u>i)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var c=o*i/(i-u)-o,p=c*Nr/(Nr-Or),l=p-c,d=he(a.assetOut,Number(u))/he(a.assetIn,Number(p)),f=he(a.assetOut,Number(i))/he(a.assetIn,Number(o)),m=ge({decimalPlaces:5},Math.abs(d/f-1)),h={round:n.round,assetInID:s,assetInAmount:p,assetOutID:r.id,assetOutAmount:u,swapFee:Number(l),rate:d,priceImpact:m};return{type:rt.Direct,data:{pool:t,quote:h}}}function jr(e){return Vr.apply(this,arguments)}function Vr(){return(Vr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,o.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount)-A,assetOutID:i.id,assetOutAmount:BigInt(i.amount),excessAmount:{assetID:o.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Gr(){return(Gr=i(s().mark((function e(t){var n,r,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.pool,o=t.swapType,i=t.txGroup,u=t.signedTxns,c=t.initiatorAddr,r.status===Ct.READY){e.next=3;break}throw new Y({pool:r,swapType:o,txGroup:i},"There is not an available pool for this asset pair");case 3:if(e.prev=3,p={id:i[Br.ASSET_IN_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_IN_TXN_INDEX].txn.amount},l={id:i[Br.ASSET_OUT_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_OUT_TXN_INDEX].txn.amount},o!==Ce.FixedInput){e.next=12;break}return e.next=9,Rr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 9:d=e.sent,e.next=15;break;case 12:return e.next=14,jr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 14:d=e.sent;case 15:return e.abrupt("return",a(a({},d),{},{groupID:ye(i),fees:we(i)}));case 18:throw e.prev=18,e.t0=e.catch(3),"SlippageTolerance"===(f=new Y(e.t0,"We encountered something unexpected while swapping. Try again later.")).type&&f.setMessage("The swap failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),f;case 23:case"end":return e.stop()}}),e,null,[[3,18]])})))).apply(this,arguments)}var Xr,qr={getQuote:function(e,t,n,r,a){return e===Ce.FixedInput?Lr({pool:t,reserves:n,assetIn:r,decimals:a}):Ur({pool:t,reserves:n,assetOut:r,decimals:a})},getFixedInputSwapQuote:Lr,getFixedOutputSwapQuote:Ur,generateTxns:function(e){return Fr.apply(this,arguments)},signTxns:function(e){return Cr.apply(this,arguments)},execute:function(e){return Gr.apply(this,arguments)},executeFixedOutputSwap:jr};function Qr(e){return Promise.allSettled(e).then((function(e){if(e.every((function(e){return"rejected"===e.status}))){var t=v(e.map((function(e){return e.reason})),2),n=t[0],r=t[1];if(gt(n)&&!gt(r))throw n;throw r}return e.filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value}))}))}function Wr(){return(Wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.isSwapRouterEnabled,u=t.pools,c=[],(p=u.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedInputSwapQuote({pool:p.info,assetIn:{amount:r,id:Number(a.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=u.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedInputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:i,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zr(){return(zr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.pools,u=t.isSwapRouterEnabled,c=[],(p=i.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedOutputSwapQuote({pool:p.info,assetOut:{amount:r,id:Number(o.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=i.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedOutputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:u,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jr=(l(Xr={},U.V1_1,qr),l(Xr,U.V2,br),l(Xr,"getQuote",(function(e){var t=e.type;if(t===Ce.FixedInput)return function(e){return Wr.apply(this,arguments)}(e);if(t===Ce.FixedOutput)return function(e){return zr.apply(this,arguments)}(e);throw new E(_.InvalidSwapTypeError,"Invalid swap type")})),l(Xr,"generateTxns",(function(e){return e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1?qr.generateTxns(a(a({},e),{},{quoteAndPool:e.quote.data})):br.generateTxns(e)})),l(Xr,"signTxns",(function(e){if(e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1){var t=e.quote.data.pool;return qr.signTxns(a(a({},e),{},{pool:t}))}return br.signTxns(e)})),l(Xr,"execute",(function(e){return e.contractVersion===U.V1_1?qr.execute(e):br.execute(e)})),Xr);function Kr(){return(Kr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.initiatorSigner,e.prev=1,e.next=4,Yr({txGroup:a,pool:r,initiatorSigner:o});case 4:return i=e.sent,e.next=7,Ie(n,[i]);case 7:return u=e.sent,c=v(u,1),p=c[0],l=p.txnID,d=p.confirmedRound,e.abrupt("return",{fees:we(a),confirmedRound:d,txnID:l,groupID:ye(a)});case 15:throw e.prev=15,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while redeeming. Try again later.");case 18:case"end":return e.stop()}}),e,null,[[1,15]])})))).apply(this,arguments)}function Yr(e){return Hr.apply(this,arguments)}function Hr(){return(Hr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.pool,o=n.initiatorSigner,t.next=3,o([r]);case 3:return i=t.sent,u=v(i,1),c=u[0],p=a.account.lsig,l=r.map((function(t,n){return 0===n?c:e.signLogicSigTransactionObject(t.txn,p).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function $r(){return $r=i(s().mark((function t(n){var r,a,o,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.data,o=n.initiatorSigner,t.prev=1,u=a.map((function(e){var t=e.txGroup,n=e.pool;return{txns:t,txnFees:we(t),groupID:ye(t),lsig:n.account.lsig}})),t.next=5,o(u.map((function(e){return e.txns})));case 5:return c=t.sent,p=Promise.all(u.map((function(t,n){return new Promise(function(){var a=i(s().mark((function a(o,i){var u,p,l,d,f,m;return s().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,u=t.txns.map((function(r,a){return 0===a?c[n]:e.signLogicSigTransactionObject(r.txn,t.lsig).blob})),a.next=4,Ie(r,[u]);case 4:p=a.sent,l=v(p,1),d=l[0],f=d.txnID,m=d.confirmedRound,o({fees:t.txnFees,groupID:t.groupID,txnID:f,confirmedRound:m}),a.next=15;break;case 12:a.prev=12,a.t0=a.catch(0),i(a.t0);case 15:case"end":return a.stop()}}),a,null,[[0,12]])})));return function(e,t){return a.apply(this,arguments)}}())}))),t.abrupt("return",p);case 10:throw t.prev=10,t.t0=t.catch(1),new Y(t.t0,"We encountered something unexpected while redeeming. Try again later.");case 13:case"end":return t.stop()}}),t,null,[[1,10]])}))),$r.apply(this,arguments)}function Zr(){return(Zr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.assetID,i=n.assetOut,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=a.account.address(),l=e.makeApplicationNoOpTxnFromObject({from:p,appIndex:a.validatorAppID,appArgs:[Te("redeem")],note:_e.getAppCallTxnNoteWithClientName(a.contractVersion),accounts:[u],foreignAssets:0==a.asset2ID?[a.asset1ID,a.poolTokenID]:[a.asset1ID,a.asset2ID,a.poolTokenID],suggestedParams:c}),d=0===o?e.makePaymentTxnWithSuggestedParamsFromObject({from:p,to:u,amount:BigInt(i),suggestedParams:c}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:p,to:u,assetIndex:o,amount:BigInt(i),suggestedParams:c}),f=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:p,amount:l.fee+d.fee,note:P,suggestedParams:c}),m=e.assignGroupID([f,l,d]),t.abrupt("return",[{txn:m[0],signers:[u]},{txn:m[1],signers:[p]},{txn:m[2],signers:[p]}]);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ea(e){var t,n={},r=T(e);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=(new TextDecoder).decode(Buffer.from(a.key,"base64")),o=void 0;o=1===a.value.type?a.value.bytes:a.value.uint,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function ta(e,t,n){return e*t/n}var na=BigInt(31536e3),ra=BigInt(1e14),aa=BigInt(1e16),sa={testnet:548587153,mainnet:1385499515},oa=14;function ia(e){return ua.apply(this,arguments)}function ua(){return(ua=i(s().mark((function t(n){var r,a,o,i,u;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(sa[a]),t.next=4,_t(r,i);case 4:return u=t.sent.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!u.includes(e)})));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ca(){return(ca=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,y,b,T,k,_,E,P;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.poolTokenId,u=n.lendingManagerId,c=n.asset1In,p=n.asset2In,l=n.initiatorAddr,d=e.getApplicationAddress(sa[a]),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=[c,p].sort((function(e,t){return t.fAssetId-e.fAssetId})),h=v(m,2),g=h[0],x=h[1],A=te(x.id),I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:g.id,amount:g.amount,suggestedParams:f}),y=A?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:x.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:x.id,amount:x.amount,suggestedParams:f}),(b=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("add_liquidity"),e.decodeAddress(o).publicKey,e.encodeUint64(g.lendingAppId),e.encodeUint64(x.lendingAppId)],foreignAssets:[g.id,x.id,g.fAssetId,x.fAssetId],foreignApps:[g.lendingAppId,x.lendingAppId,u],accounts:[o],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),T=Pe(a,U.V2),k=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("noop")],foreignAssets:[i],foreignApps:[T],accounts:[o],suggestedParams:f}),_=[I,y,b,k],t.next=16,ia({client:r,network:a,assetIDs:[g.id,x.id,g.fAssetId,x.fAssetId,i]});case 16:return(E=t.sent).length&&((P=[e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:D*E.length,suggestedParams:f}),e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("asset_optin")].concat(w(E.map((function(t){return e.encodeUint64(t)})))),foreignAssets:w(E),suggestedParams:f})])[1].fee=(E.length+1)*e.ALGORAND_MIN_TX_FEE,_.unshift.apply(_,P)),t.abrupt("return",e.assignGroupID(_).map((function(e){return{txn:e,signers:[l]}})));case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function pa(){return(pa=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.asset1Out,c=n.asset2Out,p=n.lendingManagerId,l=n.network,d=e.getApplicationAddress(sa[l]),t.next=4,r.getTransactionParams().do();case 4:if(f=t.sent,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:return g=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:h,amount:o,suggestedParams:f}),(x=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("remove_liquidity"),e.decodeAddress(m).publicKey,e.encodeUint64(u.lendingAppId),e.encodeUint64(c.lendingAppId)],accounts:[m],foreignAssets:[u.id,c.id,u.fAssetId,c.fAssetId],foreignApps:[u.lendingAppId,c.lendingAppId,p],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),A=Pe(l,U.V2),I=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("noop")],accounts:[m],foreignAssets:[h,u.fAssetId,c.fAssetId],foreignApps:[A],suggestedParams:f}),v=e.assignGroupID([g,x,I]),t.abrupt("return",v.map((function(e){return{txn:e,signers:[i]}})));case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function la(e,t,n){var r=BigInt(Math.floor((new Date).getTime()/1e3)-function(e){return null!=e?e:Math.floor((new Date).getTime()/1e3)}(n));return ta(e,aa+t*r/na,aa)}function da(){return(da=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,a=r.params["global-state"],o=ea(a),i=Number(Buffer.from(o.pm,"base64").readBigUInt64BE(0)),u=Buffer.from(o.i,"base64"),c=u.readBigUInt64BE(32),p=u.readBigUInt64BE(40),l=Number(u.readBigUInt64BE(48)),e.abrupt("return",{appId:n,managerAppId:i,depositInterestRate:c,depositInterestIndex:p,lastUpdate:l});case 11:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var fa={AddLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return ca.apply(this,arguments)},getAddLiquidityTotalFee:function(t){return e.ALGORAND_MIN_TX_FEE*(4+oa)+(t?(t+1)*e.ALGORAND_MIN_TX_FEE+t*D:0)}}),RemoveLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return pa.apply(this,arguments)},getRemoveLiquidityTotalFee:function(){return e.ALGORAND_MIN_TX_FEE*(3+oa)}}),calculateWithdrawReturn:function(e){var t=e.withdrawAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return ta(BigInt(t),n,ra)},calculateDepositReturn:function(e){var t=e.depositAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return BigInt(t)*ra/n},getFolksWrapperAppOptInRequiredAssetIDs:ia};function ma(t){var n=t.suggestedParams,r=t.stakingAppID,a=t.initiatorAddr,s=t.liquidityAssetID,o=t.program,i=t.amount,u=e.encodeUint64(i),c=e.encodeUint64(o.id);return e.makeApplicationNoOpTxnFromObject({appIndex:r,from:a,suggestedParams:n,foreignAssets:[s],accounts:[o.accountAddress],appArgs:[Te("commit"),u],note:ae([Te("tinymanStaking/v1:b"),c,e.encodeUint64(s),u])})}function ha(){return(ha=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.stakingAppID,o=n.program,i=n.requiredAssetID,u=n.liquidityAssetID,c=n.amount,p=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=ma({suggestedParams:l,stakingAppID:a,program:o,liquidityAssetID:u,initiatorAddr:p,amount:c}),f=[d],"number"!=typeof i){t.next=10;break}return m=e.makeApplicationNoOpTxnFromObject({appIndex:a,from:p,suggestedParams:l,foreignAssets:[i],accounts:[o.accountAddress],appArgs:[Te("log_balance")]}),f=e.assignGroupID([d,m]),t.abrupt("return",[{txn:f[0],signers:[p]},{txn:f[1],signers:[p]}]);case 10:return t.abrupt("return",[{txn:f[0],signers:[p]}]);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var ga=604800,xa=1e3,Aa={testnet:480164661,mainnet:2200606875},Ia={testnet:360907790,mainnet:2200609638},va={testnet:336189106,mainnet:2200608153},wa={testnet:383416252,mainnet:2200608887},ya=2500,ba=400,Ta=604800,ka=Te("p"),_a=Te("a"),Ea=24,Pa=111300,Sa=ya+ba*(41+Ea),Da=function(e){return e[e.Against=0]="Against",e[e.For=1]="For",e[e.Abstain=2]="Abstain",e}(Da||{}),Oa=new Uint8Array(34),Na="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ";function Ba(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,n=new Uint8Array(t),r=BigInt(e),a=t-1;a>=0;a--)n[a]=Number(r&BigInt(255)),r>>=BigInt(8);return n}function Ca(e,t){return 0===Buffer.compare(e,t)}function Fa(e){for(var t=0n,n=0;n=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r>>0,o=new Uint8Array(s);e[t];){var p=n[e.charCodeAt(t)];if(255===p)return;for(var l=0,d=s-1;(0!==p||l>>0,o[d]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");a=l,t++}if(" "!==e[t]){for(var f=s-a;f!==s&&0===o[f];)f++;for(var m=new Uint8Array(r+(s-f)),h=r;f!==s;)m[h++]=o[f++];return m}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var n=0,r=0,a=0,s=t.length;a!==s&&0===t[a];)a++,n++;for(var o=(s-a)*p+1>>>0,c=new Uint8Array(o);a!==s;){for(var l=t[a],d=0,f=o-1;(0!==l||d>>0,c[f]=l%i>>>0,l=l/i>>>0;if(0!==l)throw new Error("Non-zero carry");r=d,a++}for(var m=o-r;m!==o&&0===c[m];)m++;for(var h=u.repeat(n);mLa(a(e))})}function Wa({name:e,prefix:t,bitsPerChar:n,alphabet:r}){return qa({prefix:t,name:e,encode:e=>function(e,t,n){const r="="===t[t.length-1],a=(1<n;)o-=n,s+=t[a&i>>o];if(0!==o&&(s+=t[a&i<function(e,t,n,r){const a={};for(let e=0;e=8&&(i-=8,o[c++]=255&u>>i)}if(i>=n||0!=(255&u<<8-i))throw new SyntaxError("Unexpected end of data");return o}(t,r,n,e)})}const za=Wa({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5});Wa({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wa({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wa({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wa({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wa({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wa({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wa({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wa({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});const Ja=Qa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"});Qa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ka=function e(t,n,r){n=n||[];var a=r=r||0;for(;t>=$a;)n[r++]=255&t|Ya,t/=128;for(;t&Ha;)n[r++]=255&t|Ya,t>>>=7;return n[r]=0|t,e.bytes=r-a+1,n},Ya=128,Ha=-128,$a=Math.pow(2,31);var Za=function e(t,n){var r,a=0,s=0,o=n=n||0,i=t.length;do{if(o>=i)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],a+=s<28?(r&ts)<=es);return e.bytes=o-n,a},es=128,ts=127;var ns=Math.pow(2,7),rs=Math.pow(2,14),as=Math.pow(2,21),ss=Math.pow(2,28),os=Math.pow(2,35),is=Math.pow(2,42),us=Math.pow(2,49),cs=Math.pow(2,56),ps=Math.pow(2,63),ls={encode:Ka,decode:Za,encodingLength:function(e){return e{const[n,r]=ds(e.subarray(t));return t+=r,n};let r=n(),a=ws;if(18===r?(r=0,t=0):a=n(),0!==r&&1!==r)throw new RangeError(`Invalid CID version ${r}`);const s=t,o=n(),i=n(),u=t+i;return{version:r,codec:a,multihashCode:o,digestSize:i,multihashSize:u-s,size:u}}static parse(e,t){const[n,r]=function(e,t){switch(e[0]){case"Q":{const n=t??Ja;return[Ja.prefix,n.decode(`${Ja.prefix}${e}`)]}case Ja.prefix:{const n=t??Ja;return[Ja.prefix,n.decode(e)]}case za.prefix:{const n=t??za;return[za.prefix,n.decode(e)]}default:if(null==t)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}(e,t),a=vs.decode(r);if(0===a.version&&"Q"!==e[0])throw Error("Version 0 CID string must not include multibase prefix");return Is(a).set(n,e),a}}const ws=112,ys=18;function bs(e,t,n){const r=ms(e),a=r+ms(t),s=new Uint8Array(a+n.byteLength);return fs(e,s,0),fs(t,s,r),s.set(n,a),s}const Ts=Symbol.for("@ipld/js-cid/CID");class ks{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){const t=this.encode(e);return t instanceof Uint8Array?hs(this.code,t):t.then((e=>hs(this.code,e)))}throw Error("Unknown type, must be binary type")}}const _s=85,Es=function({name:e,code:t,encode:n}){return new ks(e,t,n)}({name:"sha2-256",code:18,encode:e=>La(n.createHash("sha256").update(e).digest())});var Ps=126144e3,Ss=1e7,Ds=Math.pow(2,64),Os=48,Ns=21,Bs=48,Cs=Te("tp"),Fs=Te("sc"),Ls=28100,Rs=12900,Ms=421700,Us=409700;function js(e){var t=e/Ta;return(arguments.length>1&&void 0!==arguments[1]&&arguments[1]?Math.floor(t):Math.ceil(t))*Ta}function Vs(e,t){if(e>t)throw new Error("Old timestamp must be less than or equal to new timestamp");for(var n=[],r=js(e)+Ta;re?r=t?e*e*Ds/(2*t):0:r=(e+(e-r))*n/2;return r}function Js(e,t){return Ks.apply(this,arguments)}function Ks(){return(Ks=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,e.abrupt("return",Ys(r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ys(e){var t,n={},r=T(e.params["global-state"]);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=Buffer.from(a.key,"base64").toString(),o=void 0;o=1===a.value.type?Buffer.from(a.value.bytes||"","base64"):a.value.uint||0,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function Hs(){for(var e=arguments.length,t=new Array(e),n=0;n0?Ns-e:0}},{key:"lastAccountPowerBoxIndex",get:function(){return xo(this.powerCount)[0]}},{key:"lastAccountPowerArrayIndex",get:function(){return xo(this.powerCount)[1]}}]),e}(),uo=function(){function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a}return p(e,[{key:"lockEndTimestamp",get:function(){var e=this.bias*Math.pow(2,64)/this.slope;return this.timestamp+e}},{key:"cumulativePowerAt",value:function(e){var t=e-this.timestamp;if(t<0)throw new Error("Time delta must be greater than or equal to 0");return this.cumulativePower+zs(this.bias,this.slope,t)}}]),e}(),co=p((function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a})),po=p((function e(t){u(this,e),this.slopeDelta=t})),lo=function(){function e(t,n,r,a){u(this,e),this.tinyAssetId=t,this.totalLockedAmount=n,this.totalPowerCount=r,this.lastTotalPowerTimestamp=a}return p(e,[{key:"freeTotalPowerSpaceCount",get:function(){var e=this.totalPowerCount%Ns;return e>0?Ns-e:0}},{key:"lastTotalPowerBoxIndex",get:function(){return xo(this.totalPowerCount)[0]}},{key:"lastTotalPowerArrayIndex",get:function(){return xo(this.totalPowerCount)[1]}}]),e}();function fo(){return(fo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ho(r),e.prev=1,e.next=4,Gs(t,n,a);case 4:if(!(o=e.sent)){e.next=7;break}return e.abrupt("return",mo(o));case 7:return e.abrupt("return",null);case 10:return e.prev=10,e.t0=e.catch(1),console.log(e.t0),e.abrupt("return",null);case 14:case"end":return e.stop()}}),e,null,[[1,10]])})))).apply(this,arguments)}function mo(e){var t=Buffer.from(e);return new io(t.readUIntBE(0,8),t.readUIntBE(8,8),t.readUIntBE(16,8),t.readUIntBE(24,8))}function ho(t){return e.decodeAddress(t).publicKey}function go(e){var t=Ba(e),n=new Uint8Array(Cs.length+t.length);return n.set(Cs,0),n.set(t,Cs.length),n}function xo(e){var t=e-1;return[Math.floor(t/Ns),t%Ns]}function Ao(t,n){var r=e.decodeAddress(t).publicKey,a=Ba(n),s=new Uint8Array(r.length+a.length);return s.set(r,0),s.set(a,r.length),s}function Io(e,t,n){return vo.apply(this,arguments)}function vo(){return(vo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=yo(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",wo(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function wo(t){return new po(Number(e.bytesToBigInt(t.slice(t.length-16,t.length))))}function yo(e){return Hs(Fs,Ba(e))}function bo(e,t,n){return To.apply(this,arguments)}function To(){return(To=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=0,r&&(a=Math.ceil(r/Ns)),o=[],i=0;case 4:if(!(i=e[r].timestamp))break;n=r}return n}function So(e){for(var t,n=Os,r=[],a=0;a=11)throw new Error("Boxes' length cannot be larger than 10");var y=d.slice(0,6),b=[e.makeApplicationNoOpTxnFromObject({from:s,suggestedParams:c,appIndex:n,appArgs:[Te("claim_rewards"),Ba(o),Ba(i),Hs.apply(void 0,w(u.map((function(e){return Ba(e)}))))],foreignApps:[r],foreignAssets:[a],boxes:y,note:l?Te(l):void 0})];b[0].fee=b[0].fee*(i+2);var k=0,_=92+865*i,E=700+700*i;if(_>E&&(k=Math.floor((_-E)/666)+1),k||d.length>6){var P=d.slice(6),S=Ko({sender:s,suggestedParams:c,extraAppArgs:[Ba(Math.max(k-1,0))],index:n,foreignApps:[r],boxes:P});S.fee*=Math.max(k,1),b.unshift(S)}if(p){var D=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,to:e.getApplicationAddress(n),amount:Lo,suggestedParams:c});b.unshift(D)}return e.assignGroupID(b)}var Ho=8,$o=Te("p"),Zo=Te("a"),ei=Te("v"),ti=28500,ni=12500,ri=p((function e(t,n,r,a,s,o,i){u(this,e),this.index=t,this.creationTimestamp=n,this.votingStartTimestamp=r,this.votingEndTimestamp=a,this.votingPower=s,this.voteCount=o,this.isCancelled=i}));function ai(t,n){return Hs(Zo,e.decodeAddress(t).publicKey,Ba(n))}function si(e){return new ri(Fa(e.slice(0,8)),Fa(e.slice(8,16)),Fa(e.slice(16,24)),Fa(e.slice(24,32)),Fa(e.slice(32,40)),Fa(e.slice(40,48)),Boolean(Fa(e.slice(48,49))))}function oi(){return(oi=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ao(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",si(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ii(t){var n=t.stakingVotingAppId,r=t.vaultAppId,a=t.sender,s=t.proposalId,o=t.proposal,i=t.votes,u=t.assetIds,c=t.accountPowerIndex,p=t.appBoxNames,l=t.suggestedParams,d=t.appCallNote,f=void 0===d?null:d;if(i.length!==u.length)throw new Error("The number of votes must be equal to the number of asset ids");if(u.length>Ho)throw new Error("You cannot cast vote for more than ".concat(Ho," different pools"));if(100!==i.reduce((function(e,t){return e+t}),0))throw new Error("The sum of the votes must equal 100%");var m,h=Hs.apply(void 0,w(i.map((function(e){return Ba(e)})))),g=Hs.apply(void 0,w(u.map((function(e){return Ba(e)})))),x=function(e){return Hs($o,Te(e))}(s),A=ai(a,Math.floor(o.index/8192)),I=!p.some((function(e){return Ca(e,A)})),v=ho(a),y=Math.floor(c/Ns),b=Ao(a,y),k=Ao(a,y+1),_=0,E=[],P=T(u);try{var S=function(){var e=m.value,t=function(e,t){return Hs(ei,Ba(e),Ba(t))}(o.index,e);E.push({appIndex:n,name:t}),p.some((function(e){return Ca(e,t)}))||(_+=1)};for(P.s();!(m=P.n()).done;)S()}catch(e){P.e(e)}finally{P.f()}var D=[{appIndex:n,name:x},{appIndex:n,name:A}].concat(E,[{appIndex:r,name:v},{appIndex:r,name:b},{appIndex:r,name:k}]),O=[e.makeApplicationNoOpTxnFromObject({from:a,suggestedParams:l,appIndex:n,appArgs:[Te("cast_vote"),Te(s),h,g,Ba(c)],foreignApps:[r],boxes:D.slice(0,7),note:f?Te(f):void 0})];O[0].fee*=2,D.length>=7&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(7,14)})),D.length>=14&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(14)}));var N=Number(I)*ti+_*ni;return N&&(O=[e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:l,to:e.getApplicationAddress(n),amount:N})].concat(w(O))),e.assignGroupID(O)}function ui(t){var n=t.accountState,r=t.lockEndTime,a=t.lockedAmount,s=t.network,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.slopeChangeAtLockEndTime,p=t.appCallNote;if(ai.freeTotalPowerSpaceCount&&(b+=Us),c||(b+=Rs);var k=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({amount:a,assetIndex:X[s],from:o,suggestedParams:u,to:e.getApplicationAddress(l)}),e.makeApplicationNoOpTxnFromObject({appIndex:l,from:o,suggestedParams:u,appArgs:[Te("create_lock"),Ba(r)],boxes:d.slice(0,8),note:p}),Ko({sender:o,suggestedParams:u,index:l,boxes:d.slice(8)})];if(b){var _=e.makePaymentTxnWithSuggestedParamsFromObject({amount:b,from:o,suggestedParams:u,to:e.getApplicationAddress(l)});k.unshift(_)}return e.assignGroupID(k)}function ci(t){var n=t.accountState,r=t.lockedAmount,a=t.network,s=t.sender,o=t.vaultAppGlobalState,i=t.suggestedParams,u=t.appCallNote;if(ro.freeTotalPowerSpaceCount&&(v+=Us),!n.freeAccountPowerSpaceCount){var w=Ao(s,n.lastAccountPowerBoxIndex+1);h.push({appIndex:Aa[a],name:w}),v+=Ms}var y=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:X[a],from:s,to:e.getApplicationAddress(Aa[a]),amount:r,suggestedParams:i}),e.makeApplicationNoOpTxnFromObject({appIndex:Aa[a],from:s,suggestedParams:i,appArgs:[Te("increase_lock_amount")],boxes:h,note:u}),Ko({sender:s,suggestedParams:i,index:Aa[a]})];if(v){var b=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,suggestedParams:i,to:e.getApplicationAddress(Aa[a]),amount:v});y.unshift(b)}return e.assignGroupID(y)}function pi(t){var n=t.accountState,r=t.network,a=t.newLockEndTime,s=t.slopeChangeAtNewLockEndTime,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.appCallNote;if(a%Ta)throw new Error("Invalid lock end time");if(a<=n.lockEndTime)throw new Error("New lock end time must be greater than current lock end time");var p=ho(o),l=Ao(o,n.lastAccountPowerBoxIndex),d=go(i.lastTotalPowerBoxIndex),f=go(i.lastTotalPowerBoxIndex+1),m=yo(n.lockEndTime),h=yo(a),g=[{appIndex:Aa[r],name:p},{appIndex:Aa[r],name:l},{appIndex:Aa[r],name:d},{appIndex:Aa[r],name:f},{appIndex:Aa[r],name:m},{appIndex:Aa[r],name:h}];if(!n.freeAccountPowerSpaceCount){var x=Ao(o,n.lastAccountPowerBoxIndex+1);g.push({appIndex:Aa[r],name:x})}var A,I=Vs(i.lastTotalPowerTimestamp,Math.floor(Date.now()/1e3)),v=I.length,w=T(I);try{for(w.s();!(A=w.n()).done;){var y=A.value;if(y%Ta==0){var b=yo(y);g.push({appIndex:Aa[r],name:b})}}}catch(e){w.e(e)}finally{w.f()}var k=0;s||(k+=Rs),n.freeAccountPowerSpaceCount||(k+=Ms),v>i.freeTotalPowerSpaceCount&&(k+=Us);var _=[e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:o,suggestedParams:u,appArgs:[Te("extend_lock_end_time"),Ba(a)],boxes:g.slice(0,8),note:c}),Ko({sender:o,suggestedParams:u,index:Aa[r],boxes:g.slice(8)})];if(k){var E=e.makePaymentTxnWithSuggestedParamsFromObject({from:o,suggestedParams:u,to:e.getApplicationAddress(Aa[r]),amount:k});_.unshift(E)}return e.assignGroupID(_)}function li(t){var n=t.accountState,r=t.network,a=t.sender,s=t.suggestedParams,o=t.appCallNote,i=ho(a),u=Ao(a,n.lastAccountPowerBoxIndex),c=Ao(a,n.lastAccountPowerBoxIndex+1),p=[{appIndex:Aa[r],name:i},{appIndex:Aa[r],name:u},{appIndex:Aa[r],name:c}],l=e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:a,suggestedParams:s,appArgs:[Te("withdraw")],foreignAssets:[X[r]],boxes:p,note:o});l.fee*=2;var d=[l];if(!n.freeAccountPowerSpaceCount){var f=e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:s,to:e.getApplicationAddress(Aa[r]),amount:Ms});d.unshift(f)}return e.assignGroupID(d)}var di=function(){function t(e,n,r){u(this,t),this.algodClient=e,this.userAddress=n,this.network=r}var n,r,a,o,c,l,d,f,m,h,g,x,A,I,v,y;return p(t,[{key:"getTinyPower",value:(y=i(s().mark((function e(){var t,n,r,a,o,i,u,c=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=c.length>0&&void 0!==c[0]?c[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=Math.max(o.bias-Ws(o.slope,i),0),e.abrupt("return",u);case 16:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getTotalTinyPower",value:(v=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=v.length>0&&void 0!==v[0]?v[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchVaultAppGlobalState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,bo(this.algodClient,Aa[this.network],n.totalPowerCount);case 8:if(r=e.sent,a=Po(r,t)){e.next=12;break}return e.abrupt("return",0);case 12:o=r[a],i=Math.floor(o.timestamp/Ta),u=Math.floor(t/Ta)-i,c=Array.from({length:u},(function(e,t){return(i+t)*Ta})),p=c.map((function(e,t){return[0===t?o.timestamp:c[t-1],e]})),l=o.slope,d=o.bias,f=T(p),e.prev=19,f.s();case 21:if((m=f.n()).done){e.next=34;break}return h=m.value,g=h[1]-h[0],x=Ws(l,g),d=Math.max(d-x,0),e.next=28,Io(this.algodClient,Aa[this.network],h[1]);case 28:A=e.sent,I=(null==A?void 0:A.slopeDelta)||0,l=Math.max(l-I,0),0!==d&&0!==l||(d=0,l=0);case 32:e.next=21;break;case 34:e.next=39;break;case 36:e.prev=36,e.t0=e.catch(19),f.e(e.t0);case 39:return e.prev=39,f.f(),e.finish(39);case 42:return e.abrupt("return",d);case 43:case"end":return e.stop()}}),e,this,[[19,36,39,42]])}))),function(){return v.apply(this,arguments)})},{key:"getCumulativeTinyPower",value:(I=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=p.length>0&&void 0!==p[0]?p[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=zs(o.bias,o.slope,i),c=o.cumulativePower-u,e.abrupt("return",c);case 17:case"end":return e.stop()}}),e,this)}))),function(){return I.apply(this,arguments)})},{key:"fetchVaultAppGlobalState",value:(A=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,Js(this.algodClient,Aa[this.network]);case 3:return t=e.sent,e.abrupt("return",new lo(t.tiny_asset_id,t.total_locked_amount,t.total_power_count,t.last_total_power_timestamp));case 7:return e.prev=7,e.t0=e.catch(0),console.error(e.t0),e.abrupt("return",null);case 11:case"end":return e.stop()}}),e,this,[[0,7]])}))),function(){return A.apply(this,arguments)})},{key:"generateCreateLockTransactions",value:(x=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=o,c){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(p){e.next=15;break}return e.next=14,this.algodClient.getTransactionParams().do();case 14:p=e.sent;case 15:return e.next=17,Io(this.algodClient,Aa[this.network],r);case 17:return l=e.sent,e.abrupt("return",ui({lockedAmount:n,lockEndTime:r,vaultAppGlobalState:c,slopeChangeAtLockEndTime:l,sender:i,network:this.network,accountState:u,suggestedParams:p}));case 19:case"end":return e.stop()}}),e,this)}))),function(e){return x.apply(this,arguments)})},{key:"generateIncreaseLockAmountTransactions",value:(g=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.abrupt("return",ci({accountState:i,lockedAmount:n,network:this.network,sender:o,vaultAppGlobalState:u,suggestedParams:c}));case 18:case"end":return e.stop()}}),e,this)}))),function(e){return g.apply(this,arguments)})},{key:"generateExtendLockTimeTransactions",value:(h=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.newLockEndTime,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.next=19,Io(this.algodClient,Aa[this.network],n);case 19:return p=e.sent,e.abrupt("return",pi({accountState:i,network:this.network,newLockEndTime:n,sender:o,vaultAppGlobalState:u,suggestedParams:c,slopeChangeAtNewLockEndTime:null==p?void 0:p.slopeDelta}));case 21:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"generateIncreaseLockAmountAndExtendLockEndTimeTransactions",value:(m=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=[],l=[],d=o,c){e.next=13;break}throw new Error("There was an error while fetching vault app global state");case 13:if(u){e.next=15;break}throw new Error("There was an error while fetcing the account state");case 15:if(d){e.next=19;break}return e.next=18,this.algodClient.getTransactionParams().do();case 18:d=e.sent;case 19:return p=ci({accountState:u,lockedAmount:n,network:this.network,sender:i,vaultAppGlobalState:c,suggestedParams:d}),u.powerCount+=1,c.totalPowerCount+=1,e.next=24,Io(this.algodClient,Aa[this.network],r);case 24:return f=e.sent,l=pi({accountState:u,network:this.network,newLockEndTime:r,sender:i,vaultAppGlobalState:c,suggestedParams:d,slopeChangeAtNewLockEndTime:null==f?void 0:f.slopeDelta}),m=[].concat(w(p),w(l)),e.abrupt("return",Boolean(p.length)&&Boolean(l.length)?Zs(p,l):m);case 28:case"end":return e.stop()}}),e,this)}))),function(e){return m.apply(this,arguments)})},{key:"generateWithdrawTransactions",value:(f=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t||this.userAddress,e.next=3,this.fetchAccountState();case 3:if(o=e.sent,i=r,o){e.next=7;break}throw new Error("There was an error while fetcing the account state");case 7:if(i){e.next=11;break}return e.next=10,this.algodClient.getTransactionParams().do();case 10:i=e.sent;case 11:if(u=li({accountState:o,network:this.network,sender:a,suggestedParams:i,client:this.algodClient}),!n){e.next=17;break}return e.next=15,H({client:this.algodClient,initiatorAddr:a,assetID:X[this.network]});case 15:c=e.sent,u=Zs([c[0].txn],u);case 17:return e.abrupt("return",u);case 18:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"fetchAccountState",value:function(){return function(e,t,n){return fo.apply(this,arguments)}(this.algodClient,Aa[this.network],this.userAddress)}},{key:"fetchStakingDistributionProposal",value:function(e){return function(e,t,n){return oi.apply(this,arguments)}(this.algodClient,Ia[this.network],e)}},{key:"generateCastVoteForStakingDistributionProposalTransactions",value:(d=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.proposalId,a=t.votes,o=t.assetIds,i=t.userAddress,u=t.suggestedParams,c=null!=i?i:this.userAddress,p=u,e.next=5,this.fetchStakingDistributionProposal(r);case 5:if(l=e.sent){e.next=8;break}throw new Error("There was an error while fetching staking distribution proposal");case 8:if(p){e.next=12;break}return e.next=11,this.algodClient.getTransactionParams().do();case 11:p=e.sent;case 12:return e.next=14,this.fetchAccountState();case 14:return d=e.sent,e.next=17,eo(this.algodClient,Ia[this.network]);case 17:return f=e.sent,e.next=20,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==d?void 0:d.powerCount)&&void 0!==n?n:null});case 20:if(m=e.sent,null!==(h=Po(m,l.creationTimestamp))){e.next=24;break}throw new Error("It is required to have an account power at the staking distribution proposal creation timestamp");case 24:return e.abrupt("return",ii({stakingVotingAppId:Ia[this.network],vaultAppId:Aa[this.network],sender:c,proposalId:r,proposal:l,votes:a,assetIds:o,accountPowerIndex:h,appBoxNames:f,suggestedParams:p,appCallNote:null}));case 25:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"fetchRewardsAppGlobalState",value:(l=i(s().mark((function t(){var n;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,Js(this.algodClient,va[this.network]);case 3:return n=t.sent,t.abrupt("return",new Ro(n.tiny_asset_id,n.vault_app_id,n.reward_history_count,n.first_period_timestamp,n.reward_period_count,e.encodeAddress(n.manager),e.encodeAddress(n.rewards_manager)));case 7:return t.prev=7,t.t0=t.catch(0),console.error(t.t0),t.abrupt("return",null);case 11:case"end":return t.stop()}}),t,this,[[0,7]])}))),function(){return l.apply(this,arguments)})},{key:"generateClaimRewardTransactions",value:(c=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.periodIndexStart,a=t.periodCount,o=t.userAddress,i=t.suggestedParams,u=t.shouldOptIntoTINY,c=null!=o?o:this.userAddress,p=i){e.next=7;break}return e.next=6,this.algodClient.getTransactionParams().do();case 6:p=e.sent;case 7:return e.next=9,this.fetchAccountState();case 9:return l=e.sent,e.next=12,this.fetchRewardsAppGlobalState();case 12:if(d=e.sent){e.next=15;break}throw new Error("There was an error while fetching rewards app global state");case 15:if(!(r+a>d.rewardPeriodCount)){e.next=17;break}throw new Error("The reward period index to be claimed cannot be larger than the latest reward period index");case 17:return e.next=19,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==l?void 0:l.powerCount)&&void 0!==n?n:null});case 19:for(f=e.sent,m=d.firstPeriodTimestamp+r*ga,h=d.firstPeriodTimestamp+(r+a)*ga,g=[],x=m;x=Math.floor(Date.now()/xa)||c.votingEndTimestamp<=Math.floor(Date.now()/xa))){e.next=23;break}throw new Error("Voting period is not active");case 23:return e.next=25,_o({algodClient:this.algodClient,address:i,appId:Aa[this.network],powerCount:p.powerCount});case 25:if(l=e.sent,null!==(d=Po(l,c.creationTimestamp))){e.next=29;break}throw new Error("Account power index not found");case 29:return f=Math.floor(c.index/(8*Ea)),m=ai(i,f),e.next=33,qs(this.algodClient,wa[this.network],m);case 33:return h=!e.sent,e.abrupt("return",Oo({proposalVotingAppId:wa[this.network],vaultAppId:Aa[this.network],sender:i,proposalId:n,proposal:c,vote:a,accountPowerIndex:d,createAttendanceSheetBox:h,suggestedParams:u}));case 35:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"fetchProposalVotingAppGlobalState",value:(r=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Js(this.algodClient,wa[this.network]);case 2:return t=e.sent,e.abrupt("return",new ro(t.vault_app_id,t.proposal_index_counter,t.voting_delay,t.voting_duration,t.proposal_threshold,t.proposal_threshold_numerator,t.quorum_threshold,t.approval_requirement,t.manager,t.proposal_manager));case 4:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getRequiredTinyPowerToCreateProposal",value:(n=i(s().mark((function e(t){var n,r,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==t){e.next=4;break}e.t0=t,e.next=7;break;case 4:return e.next=6,this.getTotalTinyPower();case 6:e.t0=e.sent;case 7:return n=e.t0,e.next=10,this.fetchProposalVotingAppGlobalState();case 10:return r=e.sent,a=r.proposalThreshold,r.proposalThresholdNumerator&&(a=Math.max(a,Math.floor(n*r.proposalThresholdNumerator/100)+1)),e.abrupt("return",a);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})}]),t}(),fi=2500,mi=400,hi=function(){function e(t,n){u(this,e),l(this,"data",null),this.name=t,this.structReference=n,this.size=n[t].size,this.fields=n[t].fields}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.size)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t;if(!this.data)throw new Error("Data is not initialized");var n=this.fields[e];if(!n)throw new Error("Field ".concat(e," does not exist in struct ").concat(this.name));var r=n.offset,a=n.offset+n.size,s=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(r,a);return Ii(n.type,this.structReference).apply(Buffer.from(s))}}]),e}(),gi=function(){function e(t,n){u(this,e),l(this,"data",null),this.struct=t,this.length=n}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.struct.size*this.length)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t,n=this.struct.size*e,r=n+this.struct.size,a=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(n,r);return this.struct.apply(a?Buffer.from(a):void 0)}}]),e}(),xi=function(){function e(){u(this,e)}return p(e,[{key:"apply",value:function(e){for(var t=BigInt(0),n=0;n2&&void 0!==arguments[2]?arguments[2]:Math.floor(Date.now()/1e3),a=(n=e,Math.floor(n*Ds/Ps)),s=t-r;return s<0?0:Ws(a,s)},exports.combineAndRegroupSignerTxns=function(){for(var t=arguments.length,n=new Array(t),r=0;r=e.minimum_required_balance},exports.intToBytes=Ba,exports.isAccountOptedIntoApp=function(e){var t=e.appID;return e.accountAppsLocalState.some((function(e){return e.id===t}))},exports.isSwapAssetInAmountLow=it,exports.isSwapQuoteErrorCausedByAmount=gt,exports.poolUtils=$t,exports.prepareCommitTransactions=function(e){return ha.apply(this,arguments)},exports.redeemAllExcessAsset=function(e){return $r.apply(this,arguments)},exports.redeemExcessAsset=function(e){return Kr.apply(this,arguments)},exports.sendAndWaitRawTransaction=Ie,exports.sumUpTxnFees=we,exports.tinymanContract_v1_1=wt,exports.tinymanContract_v2=Tt,exports.tinymanJSSDKConfig=_e; +"use strict";var e=require("algosdk"),t=require("base64-js"),n=require("crypto");function r(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function a(e){for(var t=1;t=0;--a){var s=this.tryEntries[a],o=s.completion;if("root"===s.tryLoc)return r("end");if(s.tryLoc<=this.prev){var i=n.call(s,"catchLoc"),u=n.call(s,"finallyLoc");if(i&&u){if(this.prev=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev=0;--t){var n=this.tryEntries[t];if(n.finallyLoc===e)return this.complete(n.completion,n.afterLoc),k(n),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var n=this.tryEntries[t];if(n.tryLoc===e){var r=n.completion;if("throw"===r.type){var a=r.arg;k(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:E(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=void 0),d}},e}function o(e,t,n,r,a,s,o){try{var i=e[s](o),u=i.value}catch(e){return void n(e)}i.done?t(u):Promise.resolve(u).then(r,a)}function i(e){return function(){var t=this,n=arguments;return new Promise((function(r,a){var s=e.apply(t,n);function i(e){o(s,r,a,i,u,"next",e)}function u(e){o(s,r,a,i,u,"throw",e)}i(void 0)}))}}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function c(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f: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,o=!0,i=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return o=e.done,e},e:function(e){i=!0,s=e},f:function(){try{o||null==n.return||n.return()}finally{if(i)throw s}}}}function k(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}var _=function(e){return e.SwapRouterStaleDataError="SwapRouterStaleDataError",e.SwapRouterNoRouteError="SwapRouterNoRouteError",e.SwapRouterLowSwapAmountError="SwapRouterLowSwapAmountError",e.SwapRouterInsufficientReservesError="SwapRouterInsufficientReservesError",e.SwapRouterPoolHasNoLiquidityError="SwapRouterPoolHasNoLiquidityError",e.NoAvailablePoolError="NoAvailablePoolError",e.OutputAmountExceedsAvailableLiquidityError="OutputAmountExceedsAvailableLiquidityError",e.UnknownError="UnknownError",e.LowSwapAmountError="LowSwapAmountError",e.AssetDoesNotBelongToPoolError="AssetDoesNotBelongToPoolError",e.InvalidSwapTypeError="InvalidSwapTypeError",e}({}),E=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;return u(this,n),(a=t.call(this,r)).type=e,a.message=r,Error.captureStackTrace&&Error.captureStackTrace(A(a),n),a}return p(n)}(),P=Uint8Array.from([1]),S=1e5,D=1e5,O=1e5,N=1e5,B=1e5,C=5e4,F=28500,L=1e3,R=1e3,M={mainnet:{base:"https://mainnet.analytics.tinyman.org/api",v1:"https://mainnet.analytics.tinyman.org/api/v1"},testnet:{base:"https://testnet.analytics.tinyman.org/api",v1:"https://testnet.analytics.tinyman.org/api/v1"}},U={V1_1:"v1_1",V2:"v2"},j=0,V={id:"".concat(j),name:"Algorand",unit_name:"ALGO",decimals:6,url:"https://algorand.org",is_liquidity_token:!1,total_amount:"6615503326932151",clawback_address:""},G={V1:"TM1POOL",V1_1:"TMPOOL11",V2:"TMPOOL2"},X={testnet:258703304,mainnet:22e8},q={testnet:724519992,mainnet:2537013734},Q={testnet:724676936,mainnet:2537023208},W="- would result negative",z="logic eval error:",J="exceeds schema integer count",K=/transaction \w+:/,Y=function(e){d(n,x(Error));var t=I(n);function n(e,r){var a;u(this,n);for(var s=arguments.length,o=new Array(s>2?s-2:0),i=2;ir?[a(a({},e),{},{id:n}),a(a({},t),{},{id:r})]:[a(a({},t),{},{id:r}),a(a({},e),{},{id:n})]}function ee(e,t){var n=[e,t];return[Math.max.apply(Math,n),Math.min.apply(Math,n)]}function te(e){return Number(e)===j}function ne(e){return Number(e.id)}function re(e){var t,n=e.stateArray,r=void 0===n?[]:n,a=e.shouldDecodeKeys,s=void 0!==a&&a,o={},i=T(r);try{for(i.s();!(t=i.n()).done;){var u=t.value,c=u.key,p=void 0;if(1==u.value.type)p=u.value.bytes;else{if(2!=u.value.type)throw new Error("Unexpected state type: ".concat(u.value.type));p=u.value.uint}o[s?atob(c):c]=p}}catch(e){i.e(e)}finally{i.f()}return o}function ae(e){var t,n=e.reduce((function(e,t){return e+t.length}),0),r=new Uint8Array(n),a=0,s=T(e);try{for(s.s();!(t=s.n()).done;){var o=t.value;r.set(o,a),a+=o.length}}catch(e){s.e(e)}finally{s.f()}return r}var se=100000n,oe=100000n,ie=100000n,ue=25000n+25000n,ce=25000n+3500n;function pe(e){var t=e["apps-total-schema"],n=0n,r=0n;t&&(t["num-byte-slice"]&&(n=t["num-byte-slice"]),t["num-uint"]&&(r=t["num-uint"]));var a=e["apps-local-state"]||[],s=e["created-apps"]||[],o=e.assets||[];return se+oe*BigInt(o.length)+ie*BigInt(s.length+a.length)+ce*r+ue*n}function le(e){return new Promise((function(t){setTimeout((function(){t(null)}),e)}))}function de(e,t){return fe.apply(this,arguments)}function fe(){return(fe=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=3,le(1e3);case 3:return r=null,e.prev=4,e.next=7,t.pendingTransactionInformation(n).do();case 7:r=e.sent,e.next=12;break;case 10:e.prev=10,e.t0=e.catch(4);case 12:if(!r){e.next=17;break}if(!r["confirmed-round"]){e.next=15;break}return e.abrupt("return",r);case 15:if(!r["pool-error"]){e.next=17;break}throw new Error("Transaction Rejected: ".concat(r["pool-error"]));case 17:e.next=0;break;case 19:case"end":return e.stop()}}),e,null,[[4,10]])})))).apply(this,arguments)}function me(e,t,n){if(t>1||t<0)throw new Error("Invalid slippage value. Must be between 0 and 1, got ".concat(t));var r;try{var a="negative"===e?1-t:1+t;r=BigInt(Math.floor(Number(n)*a))}catch(e){throw new Error(e.message)}return r}function he(e,t){var n=Number(e);return ge({decimalPlaces:n},Math.pow(10,-n)*Number(t))}function ge(e,t){var n=e.decimalPlaces,r=void 0===n?0:n;if(r>0){var a=v(Ae(t),2),s=a[0],o=a[1],i=v(Ae(Math.round(Number(xe(s,o+r)))),2),u=i[0],c=i[1];return Number(xe(u,c-r))}return Math.round(t)}function xe(e,t){return e+(t<0?"e".concat(t):"e+".concat(t))}function Ae(e){if(e.toString().includes("e")){var t=e.toString().split("e");return[parseFloat(t[0]),parseFloat(t[1])]}return[e,0]}function Ie(e,t){return ve.apply(this,arguments)}function ve(){return(ve=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:e.prev=0,r=[],a=T(n),e.prev=3,a.s();case 5:if((o=a.n()).done){e.next=18;break}return i=o.value,e.next=9,t.sendRawTransaction(i).do();case 9:return u=e.sent,c=u.txId,e.next=13,de(t,c);case 13:p=e.sent,l=p["confirmed-round"],r.push({confirmedRound:l,txnID:c});case 16:e.next=5;break;case 18:e.next=23;break;case 20:e.prev=20,e.t0=e.catch(3),a.e(e.t0);case 23:return e.prev=23,a.f(),e.finish(23);case 26:return e.abrupt("return",r);case 29:throw e.prev=29,e.t1=e.catch(0),new Y(e.t1,"We encountered an error while processing this transaction. Try again later.");case 32:case"end":return e.stop()}}),e,null,[[0,29],[3,20,23,26]])})))).apply(this,arguments)}function we(e){return e.reduce((function(e,t){return e+t.txn.fee}),0)}function ye(e){return(t=e[0].txn.group)?Buffer.from(t).toString("base64"):"";var t}function be(e){for(var t=[];;){var n=Number(e&BigInt(127));if(!(e>>=BigInt(7))){t.push(n);break}t.push(128|n)}return t}function Te(e){return(new TextEncoder).encode(e)}var ke,_e=new(function(){function e(){u(this,e),this.clientName="tinyman-js-sdk"}return p(e,[{key:"getClientName",value:function(){return this.clientName}},{key:"setClientName",value:function(e){this.clientName=e}},{key:"getAppCallTxnNoteWithClientName",value:function(e,t){var n=e===U.V1_1?"v1":e,r=JSON.stringify(a({origin:this.clientName},t));return Te("tinyman/".concat(n,":j").concat(r))}}]),e}()),Ee=(l(ke={},U.V1_1,{testnet:62368684,mainnet:552635992}),l(ke,U.V2,{testnet:148607e3,mainnet:1002541853}),ke);function Pe(e,t){var n=Ee[t][e];if(!n)throw new Error("No Validator App exists for ".concat(e," network with ").concat(t," contract version"));return n}function Se(){return(Se=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationOptInTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function De(){return(De=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.contractVersion,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationClearStateTxnFromObject({from:i,appIndex:Pe(a,o),note:_e.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var Oe,Ne,Be,Ce=function(e){return e.FixedInput="fixed-input",e.FixedOutput="fixed-output",e}({}),Fe=.003,Le=function(e){return e[e.INPUT_TXN=0]="INPUT_TXN",e[e.APP_CALL_TXN=1]="APP_CALL_TXN",e}({}),Re=(l(Oe={},Ce.FixedInput,1),l(Oe,Ce.FixedOutput,2),Oe),Me=2,Ue=Te("swap"),je=(l(Ne={},Ce.FixedInput,Te("fixed-input")),l(Ne,Ce.FixedOutput,Te("fixed-output")),Ne),Ve={ASSET_OPT_IN:Te("asset_opt_in")},Ge={testnet:184778019,mainnet:1083651166},Xe=(l(Be={},Ce.FixedInput,7),l(Be,Ce.FixedOutput,8),Be);function qe(e){var t=Je(e),n=t.assetIn,r=t.assetOut;return he(r.asset.decimals,Number(r.amount))/he(n.asset.decimals,Number(n.amount))}function Qe(e){var t=Ge[e];if(!t)throw new Error("Unknown network or network not supported: ".concat(e));return t}function We(e){return e[e.length-1].quote.amount_out}function ze(e){return e[0].quote.amount_in}function Je(e){return{assetIn:ze(e),assetOut:We(e)}}function Ke(e){return Ye.apply(this,arguments)}function Ye(){return(Ye=i(s().mark((function t(n){var r,a,o,i,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.routerAppID,o=n.assetIDs,i=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return u=t.sent,c=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a,appArgs:[Ve.ASSET_OPT_IN],foreignAssets:o,suggestedParams:u}),p=o.length,c.fee=e.ALGORAND_MIN_TX_FEE*(p+1),t.abrupt("return",c);case 8:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function He(e){return $e.apply(this,arguments)}function $e(){return($e=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k,_,E,P,S,D;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.initiatorAddr,a=n.client,o=n.network,i=n.swapType,u=n.route,c=n.slippage,t.next=3,a.getTransactionParams().do();case 3:return p=t.sent,l=[ne(u[0].quote.amount_in.asset),ne(u[0].quote.amount_out.asset),ne(u[1].quote.amount_out.asset)],d=l[0],f=l[1],m=l[2],h=[Number(ze(u).amount),Number(We(u).amount)],g=h[0],x=h[1],A=[u[0].pool.address,u[1].pool.address],I=A[0],v=A[1],w=i===Ce.FixedInput?g:me("positive",c,g),y=i===Ce.FixedOutput?x:me("negative",c,x),b=te(d),T=Qe(o),k=b?e.makePaymentTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,suggestedParams:p}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:r,to:e.getApplicationAddress(T),amount:w,assetIndex:d,suggestedParams:p}),(_=e.makeApplicationNoOpTxnFromObject({from:r,appIndex:T,appArgs:[Ue,je[i],e.encodeUint64(y)],foreignApps:[Pe(o,U.V2)],foreignAssets:[d,f,m],accounts:[I,v],suggestedParams:p,note:_e.getAppCallTxnNoteWithClientName(U.V2)})).fee=e.ALGORAND_MIN_TX_FEE*(Xe[i]+1),E=[k,_],t.next=17,Ze({client:a,network:o,assetIDs:[d,f,m]});case 17:if(!((P=t.sent).length>0)){t.next=23;break}return t.next=21,Ke({client:a,initiatorAddr:r,assetIDs:P,routerAppID:T});case 21:S=t.sent,E.unshift(S);case 23:return D=e.assignGroupID(E),t.abrupt("return",D.map((function(e){return{txn:e,signers:[r]}})));case 25:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Ze(e){return et.apply(this,arguments)}function et(){return(et=i(s().mark((function t(n){var r,a,o,i,u,c;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(Qe(a)),t.next=4,r.accountInformation(i).do();case 4:return u=t.sent,c=u.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!c.includes(e)})));case 7:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function tt(e){return nt.apply(this,arguments)}function nt(){return(nt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetInID,a=t.assetOutID,o=t.swapType,i=t.network,u={asset_in_id:String(r),asset_out_id:String(a),swap_type:o,amount:String(n)},e.next=4,fetch("".concat(M[i].v1,"/swap-router/quotes/"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)}).catch((function(){throw new Error("Network error")}));case 4:return c=e.sent,e.next=7,c.json();case 7:if(p=e.sent,c.ok){e.next=14;break}if(s=p,!Boolean(s)||void 0===s.fallback_message){e.next=13;break}throw new E(p.type,p.fallback_message);case 13:throw new E(_.UnknownError,"There was an error while getting a quote from Swap Router");case 14:if(!(p.route.length<2)){e.next=16;break}throw new E(_.SwapRouterNoRouteError,"Swap router couldn't find a route for this swap.");case 16:return e.abrupt("return",p);case 17:case"end":return e.stop()}var s}),e)})))).apply(this,arguments)}var rt=function(e){return e.Direct="direct",e.Router="router",e}({}),at=4*e.ALGORAND_MIN_TX_FEE;function st(t){return(Re[t]+Me)*e.ALGORAND_MIN_TX_FEE}function ot(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Fe;return Math.ceil(1/e)}function it(e){return e1&&void 0!==arguments[1]?arguments[1]:Fe)}function ut(t){return(Re[t]+1)*e.ALGORAND_MIN_TX_FEE}function ct(e){var t=e.assetIn,n=e.assetOut;return he(n.decimals,Number(n.amount))/he(t.decimals,Number(t.amount))}function pt(e){var t=e.inputSupply,n=e.outputSupply,r=e.assetIn,a=e.assetOut,s=ct({assetIn:r,assetOut:a}),o=he(a.decimals,Number(n))/he(r.decimals,Number(t));return ge({decimalPlaces:5},Math.abs(s/o-1))}function lt(e){if(e.type===rt.Router){var t=ze(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetInID,amount:e.data.quote.assetInAmount}}function dt(e){if(e.type===rt.Router){var t=We(e.data.route);return{id:ne(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetOutID,amount:e.data.quote.assetOutAmount}}function ft(e){return e.type===rt.Direct?e.data.pool.contractVersion:U.V2}function mt(e){return e.type===rt.Direct?e.data.quote.rate:qe(e.data.route)}function ht(e){for(var t=e[0],n=mt(t),r=1;rn&&(t=a,n=s)}return t}function gt(e){return e instanceof E&&[_.SwapRouterInsufficientReservesError,_.SwapRouterLowSwapAmountError,_.OutputAmountExceedsAvailableLiquidityError,_.LowSwapAmountError].includes(e.type)}var xt={type:"logicsig",logic:{bytecode:"BCAIAQCBgICAgICAgPABgICAgICAgIDwAQMEBQYlJA1EMQkyAxJEMRUyAxJEMSAyAxJEMgQiDUQzAQAxABJEMwEQIQcSRDMBGIGCgICAgICAgPABEkQzARkiEjMBGyEEEhA3ARoAgAlib290c3RyYXASEEAAXDMBGSMSRDMBG4ECEjcBGgCABHN3YXASEEACOzMBGyISRDcBGgCABG1pbnQSQAE7NwEaAIAEYnVybhJAAZg3ARoAgAZyZWRlZW0SQAJbNwEaAIAEZmVlcxJAAnkAIQYhBSQjEk0yBBJENwEaARclEjcBGgIXJBIQRDMCADEAEkQzAhAhBBJEMwIhIxJEMwIiIxwSRDMCIyEHEkQzAiQjEkQzAiWACFRNUE9PTDExEkQzAiZRAA+AD1RpbnltYW5Qb29sMS4xIBJEMwIngBNodHRwczovL3RpbnltYW4ub3JnEkQzAikyAxJEMwIqMgMSRDMCKzIDEkQzAiwyAxJEMwMAMQASRDMDECEFEkQzAxElEkQzAxQxABJEMwMSIxJEJCMTQAAQMwEBMwIBCDMDAQg1AUIBsTMEADEAEkQzBBAhBRJEMwQRJBJEMwQUMQASRDMEEiMSRDMBATMCAQgzAwEIMwQBCDUBQgF8MgQhBhJENwEcATEAE0Q3ARwBMwQUEkQzAgAxABNEMwIUMQASRDMDADMCABJEMwIRJRJEMwMUMwMHMwMQIhJNMQASRDMDESMzAxAiEk0kEkQzBAAxABJEMwQUMwIAEkQzAQEzBAEINQFCAREyBCEGEkQ3ARwBMQATRDcBHAEzAhQSRDMDFDMDBzMDECISTTcBHAESRDMCADEAEkQzAhQzBAASRDMCESUSRDMDADEAEkQzAxQzAwczAxAiEk0zBAASRDMDESMzAxAiEk0kEkQzBAAxABNEMwQUMQASRDMBATMCAQgzAwEINQFCAJAyBCEFEkQ3ARwBMQATRDMCADcBHAESRDMCADEAE0QzAwAxABJEMwIUMwIHMwIQIhJNMQASRDMDFDMDBzMDECISTTMCABJEMwEBMwMBCDUBQgA+MgQhBBJENwEcATEAE0QzAhQzAgczAhAiEk03ARwBEkQzAQEzAgEINQFCABIyBCEEEkQzAQEzAgEINQFCAAAzAAAxABNEMwAHMQASRDMACDQBD0M=",address:"ABUKAXTANWR6K6ZYV75DWJEPVWWOU6SFUVRI6QHO44E4SIDLHBTD2CZ64A",size:881,variables:[{name:"TMPL_ASSET_ID_1",type:"int",index:15,length:10},{name:"TMPL_ASSET_ID_2",type:"int",index:5,length:10},{name:"TMPL_VALIDATOR_APP_ID",type:"int",index:74,length:10}],source:"https://github.com/tinymanorg/tinyman-contracts-v1/tree/dc9ab40c58b85c15d58f63a1507e18be76720dbb/contracts/pool_logicsig.teal.tmpl"},name:"pool_logicsig"},At={type:"app",global_state_schema:{num_uints:0,num_byte_slices:0},local_state_schema:{num_uints:16,num_byte_slices:0},name:"validator_app"},It=p((function e(t){u(this,e),this.schema={numLocalInts:t.local_state_schema.num_uints,numLocalByteSlices:t.local_state_schema.num_byte_slices,numGlobalInts:t.global_state_schema.num_uints,numGlobalByteSlices:t.global_state_schema.num_byte_slices}})),vt=function(n){d(a,It);var r=I(a);function a(e,t){var n;return u(this,a),(n=r.call(this,e)).poolLogicSigContractTemplate=t.logic.bytecode,n.templateVariables=t.logic.variables,n}return p(a,[{key:"generateLogicSigAccountForPool",value:function(n){if(n.asset1ID===n.asset2ID)throw new Error("Assets are the same");var r=Pe(n.network,U.V1_1),a=v(ee(n.asset1ID,n.asset2ID),2),s=a[0],o=a[1],i=Array.from(t.toByteArray(this.poolLogicSigContractTemplate)),u={asset_id_1:s,asset_id_2:o,validator_app_id:r},c=0;this.templateVariables.sort((function(e,t){return e.index-t.index}));for(var p=0;p2&&void 0!==arguments[2]?arguments[2]:e.IntDecoding.DEFAULT;return new Promise(function(){var e=i(s().mark((function e(o,i){var u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,t.accountInformation(n).setIntDecoding(r).do();case 3:u=e.sent,o(a(a({},u),{},{minimum_required_balance:Pt(u)})),e.next=10;break;case 7:e.prev=7,e.t0=e.catch(0),i(new Error(e.t0.message||"Failed to fetch account information"));case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(t,n){return e.apply(this,arguments)}}())}function Et(e,t){var n=e["apps-local-state"].find((function(e){return e.id===t}));return n?re({stateArray:n["key-value"],shouldDecodeKeys:!0}):null}function Pt(e){var t=e["apps-total-schema"];return S+D*(e.assets||[]).length+N*(e["created-apps"]||[]).length+O*(e["apps-local-state"]||[]).length+C*Number(t&&t["num-byte-slice"]||0)+F*Number(t&&t["num-uint"]||0)+B*(e["apps-total-extra-pages"]||0)}var St=Te("e");function Dt(e){return Ot.apply(this,arguments)}function Ot(){return(Ot=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,k,_;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.pool,i=r.accountAddr,n.next=3,a.accountInformation(i).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:u=n.sent,c=u["apps-local-state"]||[],p=0n,l=0n,d=0n,f=o.account.address(),m=T(c),n.prev=10,m.s();case 12:if((h=m.n()).done){n.next=31;break}if((g=h.value).id==o.validatorAppID){n.next=16;break}return n.abrupt("continue",29);case 16:if(x=g["key-value"]){n.next=19;break}return n.abrupt("break",31);case 19:A=re({stateArray:x}),I=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset1ID)])),v=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.asset2ID)])),w=t.fromByteArray(ae([e.decodeAddress(f).publicKey,St,e.encodeUint64(o.poolTokenID)])),y=A[I],b=A[v],k=A[w],"bigint"==typeof y&&(p=y),"bigint"==typeof b&&(l=b),"bigint"==typeof k&&(d=k);case 29:n.next=12;break;case 31:n.next=36;break;case 33:n.prev=33,n.t0=n.catch(10),m.e(n.t0);case 36:return n.prev=36,m.f(),n.finish(36);case 39:if(!((_={excessAsset1:p,excessAsset2:l,excessPoolTokens:d}).excessAsset1<0n||_.excessAsset2<0n||_.excessPoolTokens<0n)){n.next=42;break}throw new Error("Invalid account excess: ".concat(_));case 42:return n.abrupt("return",_);case 43:case"end":return n.stop()}}),n,null,[[10,33,36,39]])})))).apply(this,arguments)}function Nt(){return(Nt=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return a=r.client,o=r.accountAddr,i=r.validatorAppID,n.next=3,a.accountInformation(o).setIntDecoding(e.IntDecoding.BIGINT).do();case 3:if(u=n.sent,c=u["apps-local-state"]||[],p=c.find((function(e){return e.id==i})),l=[],p&&p["key-value"])for(d=re({stateArray:p["key-value"]}),f=0,m=Object.entries(d);fMt)){n.next=48;break}throw new Error("Issued liquidity value is out of the expected range ([0n, ".concat(Mt,"]): ").concat(N.issuedLiquidity));case 48:return n.abrupt("return",N);case 49:case"end":return n.stop()}}),n,null,[[8,31,34,37]])})))).apply(this,arguments)}function Gt(){return Gt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.address,a=t.network,!(o=d.length>1&&void 0!==d[1]?d[1]:{})[r]){e.next=4;break}return e.abrupt("return",o[r]);case 4:return e.next=6,_t(n,r);case 6:return i=e.sent,u=Et(i,Pe(a,U.V1_1)),c=null,u&&(l=i["created-assets"][0],p=l.index,c={asset1ID:u[Ft[U.V1_1].asset1],asset2ID:u[Ft[U.V1_1].asset2],poolTokenID:p},o[r]=c),e.abrupt("return",c);case 11:case"end":return e.stop()}}),e)}))),Gt.apply(this,arguments)}var Xt=Object.freeze({__proto__:null,getPoolAssets:function(e){return Gt.apply(this,arguments)},getPoolInfo:Ut,getPoolReserves:function(e,t){return Vt.apply(this,arguments)}});function qt(e){return Qt.apply(this,arguments)}function Qt(){return(Qt=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.asset1ID,o=t.asset2ID,i=kt(U.V2),u=i.generateLogicSigAccountForPool(t),c=Pe(r,U.V2),p=u.address(),l=ee(a,o),e.next=8,_t(n,p);case 8:return d=e.sent,f=Et(d,c),m={account:u,validatorAppID:c,asset1ID:l[0],asset2ID:l[1],status:f?Ct.READY:Ct.NOT_CREATED,contractVersion:U.V2},f&&(m.asset1ProtocolFees=BigInt(f[Ft.v2.asset1ProtocolFees]),m.asset2ProtocolFees=BigInt(f[Ft.v2.asset2ProtocolFees]),m.asset1Reserves=BigInt(f[Ft.v2.asset1Reserves]),m.asset2Reserves=BigInt(f[Ft.v2.asset2Reserves]),m.issuedPoolTokens=BigInt(f[Ft.v2.issuedPoolTokens]),m.cumulativePriceUpdateTimeStamp=Number(f[Ft.v2.cumulativePriceUpdateTimeStamp]),m.protocolFeeRatio=Number(f[Ft.v2.protocolFeeRatio]),m.totalFeeShare=BigInt(f[Ft.v2.totalFeeShare]),m.poolTokenID=Number(f[Ft.v2.poolTokenID]),m.asset1ID=Number(f[Ft.v2.asset1]),m.asset2ID=Number(f[Ft.v2.asset2])),e.abrupt("return",m);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Wt(){return(Wt=i(s().mark((function e(t,n){var r,a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,_t(t,n.account.address());case 2:return r=e.sent,a=Et(r,n.validatorAppID),o={asset1:0n,asset2:0n,issuedLiquidity:0n,round:r.round},a&&(o.asset1=BigInt(a[Ft.v2.asset1Reserves]),o.asset2=BigInt(a[Ft.v2.asset2Reserves]),o.issuedLiquidity=BigInt(a[Ft.v2.issuedPoolTokens])),e.abrupt("return",o);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zt(){return(zt=i(s().mark((function e(t){var n,r,a,o,i,u;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.address,a=t.network,e.next=3,_t(n,r);case 3:return o=e.sent,i=Et(o,Pe(a,U.V2)),u=null,i&&(u={asset1ID:i[Ft[U.V2].asset1],asset2ID:i[Ft[U.V2].asset2],poolTokenID:i[Ft[U.V2].poolTokenID]}),e.abrupt("return",u);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jt=Object.freeze({__proto__:null,getPoolAssets:function(e){return zt.apply(this,arguments)},getPoolInfo:qt,getPoolReserves:function(e,t){return Wt.apply(this,arguments)}});function Kt(e){return Boolean(e&&!(e.asset1+e.asset2))}var Yt,Ht=Object.freeze({__proto__:null,getPoolPairRatio:function(e){var t=Kt(e),n=null;return e&&!t&&e.asset1&&e.asset2&&(n=Number(e.asset1)/Number(e.asset2)),n},getPoolShare:function(e,t){var n=Number(t)/Number(e);return Number.isFinite(n)||(n=0),n},getPoolsForPair:function(e){return Promise.all([Ut(e),qt(e)])},isPoolEmpty:Kt,isPoolNotCreated:function(e){return(null==e?void 0:e.status)===Ct.NOT_CREATED},isPoolReady:function(e){return(null==e?void 0:e.status)===Ct.READY}}),$t=a((l(Yt={},U.V1_1,a(a({},Xt),Ht)),l(Yt,U.V2,a(a({},Jt),Ht)),Yt),Ht),Zt=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e[e.POOL_TOKEN_CREATE=2]="POOL_TOKEN_CREATE",e[e.ASSET1_OPT_IN=3]="ASSET1_OPT_IN",e[e.ASSET2_OPT_IN=4]="ASSET2_OPT_IN",e}({}),en={ASA_ALGO:96e4,ASA_ASA:859e3};function tn(){return(tn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T,k,_,E,P,S;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Z(o,i),l=v(p,2),d=l[0],f=d.id,m=d.unit_name,h=l[1],g=h.id,x=h.unit_name,A=te(g),I=Pe(a,U.V1_1),w=wt.generateLogicSigAccountForPool({network:a,asset1ID:f,asset2ID:g}),y=w.address(),b=e.makeApplicationOptInTxnFromObject({from:y,appIndex:I,note:_e.getAppCallTxnNoteWithClientName(U.V1_1),appArgs:[Te("bootstrap"),e.encodeUint64(f),e.encodeUint64(g)],foreignAssets:A?[f]:[g],suggestedParams:c}),T=e.makeAssetCreateTxnWithSuggestedParamsFromObject({from:y,total:0xffffffffffffffffn,decimals:6,defaultFrozen:!1,unitName:G.V1_1,assetName:"TinymanPool1.1 ".concat(m,"-").concat(x),assetURL:"https://tinyman.org",suggestedParams:c}),k=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:f,amount:0,suggestedParams:c}),_=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:y,amount:nn(A),suggestedParams:c}),(E=[])[Zt.FUNDING_TXN]=_,E[Zt.VALIDATOR_APP_CALL]=b,E[Zt.POOL_TOKEN_CREATE]=T,E[Zt.ASSET1_OPT_IN]=k,A||(E[Zt.ASSET2_OPT_IN]=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:g,amount:0,suggestedParams:c})),P=e.assignGroupID(E),S=[{txn:P[Zt.FUNDING_TXN],signers:[u]},{txn:P[Zt.VALIDATOR_APP_CALL],signers:[y]},{txn:P[Zt.POOL_TOKEN_CREATE],signers:[y]},{txn:P[Zt.ASSET1_OPT_IN],signers:[y]}],P[Zt.ASSET2_OPT_IN]&&S.push({txn:P[Zt.ASSET2_OPT_IN],signers:[y]}),t.abrupt("return",S);case 23:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function nn(e){return e?en.ASA_ALGO:en.ASA_ASA}function rn(){return(rn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=wt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===Zt.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function an(e){return sn.apply(this,arguments)}function sn(){return(sn=i(s().mark((function e(t){var n,r,a,o,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.signedTxns,a=t.txnIDs,e.prev=1,e.next=4,n.sendRawTransaction(r).do();case 4:return e.next=6,de(n,a[Zt.POOL_TOKEN_CREATE]);case 6:if(o=e.sent,"number"==typeof(i=o["asset-index"])){e.next=10;break}throw new Error("Generated ID is not valid: got ".concat(i));case 10:return e.abrupt("return",{poolTokenID:i});case 13:throw e.prev=13,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while bootstraping the pool. Try again later.");case 16:case"end":return e.stop()}}),e,null,[[1,13]])})))).apply(this,arguments)}function on(){return(on=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.signedTxns,c=t.txnIDs,e.next=3,an({client:n,signedTxns:u,txnIDs:c});case 3:return e.abrupt("return",$t.v1_1.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var un={generateTxns:function(e){return tn.apply(this,arguments)},signTxns:function(e){return rn.apply(this,arguments)},execute:function(e){return on.apply(this,arguments)},getBootstrapFundingTxnAmount:nn};var cn=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e}({}),pn={ASA_ALGO:5,ASA_ASA:6};function ln(e,t){return dn.apply(this,arguments)}function dn(){return(dn=i(s().mark((function t(n,r){var a,o,i;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!(o=null===(a=r.find((function(e){return"appl"===e.txn.type})))||void 0===a?void 0:a.txn.txID())){t.next=7;break}return t.next=4,e.waitForConfirmation(n,o,R);case 4:t.t0=t.sent,t.next=8;break;case 7:t.t0=void 0;case 8:return i=t.t0,t.abrupt("return",i);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function fn(e,t){return mn.apply(this,arguments)}function mn(){return(mn=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,ln(t,n);case 2:return r=e.sent,e.abrupt("return",null==r?void 0:r["inner-txns"]);case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function hn(e,t){return gn.apply(this,arguments)}function gn(){return(gn=i(s().mark((function t(n,r){var a,o;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fn(n,r);case 2:return a=t.sent,s=r[0].txn,o=e.encodeAddress(s.from.publicKey),t.abrupt("return",null==a?void 0:a.reduce((function(t,n){var r=t,a=n.txn.txn;return a.type===e.TransactionType.axfer&&e.encodeAddress(a.arcv)===o?r.push({id:a.xaid,amount:a.aamt}):a.type===e.TransactionType.pay&&e.encodeAddress(a.rcv)===o&&r.push({id:j,amount:a.amt}),r}),[]));case 5:case"end":return t.stop()}var s}),t)})))).apply(this,arguments)}function xn(){return(xn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,w,y,b,T;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.asset_1,i=n.asset_2,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=Pe(a,U.V2),l=e.getApplicationAddress(p),d=Z(o,i),f=v(d,2),m=f[0].id,h=f[1].id,t.next=9,$t.v2.getPoolInfo({client:r,network:a,asset1ID:m,asset2ID:h});case 9:if(t.sent.status!==Ct.READY){t.next=12;break}throw new Error("Pool for ".concat(o.unit_name,"-").concat(i.unit_name," already exists"));case 12:return g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=g.address(),A=te(h),(I=e.makeApplicationOptInTxnFromObject({from:x,appIndex:p,appArgs:[Te("bootstrap")],note:_e.getAppCallTxnNoteWithClientName(U.V2),foreignAssets:[m,h],rekeyTo:l,suggestedParams:c})).fee=In(A),w=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:x,amount:An(A),suggestedParams:c}),(y=[])[cn.FUNDING_TXN]=w,y[cn.VALIDATOR_APP_CALL]=I,b=e.assignGroupID(y),(T=[])[cn.FUNDING_TXN]={txn:b[cn.FUNDING_TXN],signers:[u]},T[cn.VALIDATOR_APP_CALL]={txn:b[cn.VALIDATOR_APP_CALL],signers:[x]},t.abrupt("return",T);case 26:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function An(e){return function(e,t){var n=kt(e).schema,r=n.numLocalInts,a=n.numLocalByteSlices,s=S+D+D+O+F*r+C*a;return t||(s+=D),s}(U.V2,e)+In(e)+D}function In(t){return((t?pn.ASA_ALGO:pn.ASA_ASA)+1)*e.ALGORAND_MIN_TX_FEE}function vn(){return(vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.network,o=n.initiatorSigner,i=n.asset1ID,u=n.asset2ID,t.next=3,o([r]);case 3:return c=t.sent,p=v(c,1),l=p[0],d=ee(i,u),f=v(d,2),m=f[0],h=f[1],g=Tt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),x=[],A=r.map((function(t,n){if(n===cn.FUNDING_TXN)return x.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return x.push(a),s})),t.abrupt("return",{signedTxns:A,txnIDs:x});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function wn(){return(wn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.network,a=t.pool,o=a.asset1ID,i=a.asset2ID,u=t.txGroup,c=t.signedTxns,e.prev=1,e.next=4,n.sendRawTransaction(c).do();case 4:return e.next=6,ln(n,u);case 6:if(e.t1=p=e.sent,e.t0=null===e.t1,e.t0){e.next=10;break}e.t0=void 0===p;case 10:if(!e.t0){e.next=14;break}e.t2=void 0,e.next=15;break;case 14:e.t2=null===(l=p["local-state-delta"][0].delta)||void 0===l||null===(d=l.find((function(e){return e.key===btoa(Ft.v2.poolTokenID)})))||void 0===d?void 0:d.value.uint;case 15:if("number"==typeof(f=e.t2)){e.next=18;break}throw new Error("Generated ID is not valid: got ".concat(f));case 18:return e.abrupt("return",$t.v2.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 21:throw e.prev=21,e.t3=e.catch(1),new Y(e.t3,"We encountered something unexpected while bootstraping the pool. Try again later.");case 24:case"end":return e.stop()}}),e,null,[[1,21]])})))).apply(this,arguments)}var yn,bn={generateTxns:function(e){return xn.apply(this,arguments)},signTxns:function(e){return vn.apply(this,arguments)},execute:function(e){return wn.apply(this,arguments)},getBootstrapFundingTxnAmount:An,getTotalCost:function(t){return e.ALGORAND_MIN_TX_FEE+An(t)}};var Tn,kn,_n,En,Pn=(l(yn={},U.V1_1,un),l(yn,U.V2,bn),l(yn,"generateTxns",(function(e){return e.contractVersion===U.V1_1?un.generateTxns(e):bn.generateTxns(e)})),l(yn,"signTxns",(function(e){return e.contractVersion===U.V1_1?un.signTxns(e):bn.signTxns(e)})),l(yn,"execute",(function(e){return e.contractVersion===U.V1_1?un.execute(e):bn.execute(e)})),l(yn,"calculateBootstrapFundingTxnAmount",(function(e){var t=e.contractVersion,n=e.isAlgoPool;return t===U.V1_1?un.getBootstrapFundingTxnAmount(n):bn.getBootstrapFundingTxnAmount(n)})),yn),Sn=function(e){return e[e.FEE_TXN=0]="FEE_TXN",e[e.VALIDATOR_APP_CALL_TXN=1]="VALIDATOR_APP_CALL_TXN",e[e.ASSET1_IN_TXN=2]="ASSET1_IN_TXN",e[e.ASSET2_IN_TXN=3]="ASSET2_IN_TXN",e[e.LIQUDITY_OUT_TXN=4]="LIQUDITY_OUT_TXN",e}({}),Dn=5*e.ALGORAND_MIN_TX_FEE,On=function(e){return e.SINGLE="single",e.FLEXIBLE="flexible",e.INITIAL="initial",e}({}),Nn=(l(Tn={},On.FLEXIBLE,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),l(Tn,On.SINGLE,{ASSET_IN_TXN:0,VALIDATOR_APP_CALL_TXN:1}),l(Tn,On.INITIAL,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),Tn),Bn=(l(kn={},On.INITIAL,1),l(kn,On.SINGLE,2),l(kn,On.FLEXIBLE,2),kn),Cn=(l(_n={},On.INITIAL,3),l(_n,On.FLEXIBLE,3),l(_n,On.SINGLE,2),_n);function Fn(e){var t,n,r,a=e.reserves,s=e.totalFeeShare,o=e.asset1,i=e.asset2,u=a.asset1*a.asset2,c=a.asset1+BigInt(o.amount),p=a.asset2+BigInt(i.amount),l=c*p,d=BigInt(parseInt(String(Math.sqrt(Number(l*a.issuedLiquidity*a.issuedLiquidity/u))))),f=d-a.issuedLiquidity,m=f*c/d,h=f*p/d,g=BigInt(o.amount)-m,x=BigInt(i.amount)-h;if(g>x){var A=g;r=Rn(A,s),t={id:o.id,amount:A+r,decimals:o.decimals,reserves:a.asset1},n={id:i.id,amount:BigInt(Math.abs(Math.min(Number(x),0))),decimals:i.decimals,reserves:a.asset2},f-=r*d/(c*BigInt(2))}else{var I=x;r=Rn(I,s),t={id:i.id,amount:I+r,decimals:i.decimals,reserves:a.asset2},n={id:o.id,amount:BigInt(Math.abs(Math.min(Number(g),0))),decimals:o.decimals,reserves:a.asset1},f-=r*d/(p*BigInt(2))}return{poolTokenOutAmount:f,internalSwapQuote:{assetIn:t,assetOut:n,swapFees:r,priceImpact:pt({inputSupply:t.reserves,outputSupply:n.reserves,assetIn:t,assetOut:n})}}}function Ln(e,t){if(!e.amount||!t.amount)throw new Error("Both assets are required for the initial add liquidity");return BigInt(Math.floor(Math.abs(Math.sqrt(Number(e.amount)*Number(t.amount))-Lt)))}function Rn(e,t){return e*BigInt(t)/(BigInt(1e4)-BigInt(t))}function Mn(t){return(Bn[t]+1)*e.ALGORAND_MIN_TX_FEE}var Un=Te("add_liquidity"),jn=(l(En={},U.V1_1,[Te("mint")]),l(En,U.V2,{INITIAL_LIQUIDITY:[Te("add_initial_liquidity")],SINGLE_ASSET_MODE:[Un,Te("single")],FLEXIBLE_MODE:[Un,Te("flexible")]}),En);function Vn(){return(Vn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.asset1In,u=n.asset2In,c=n.poolTokenOut,p=n.slippage,l=n.initiatorAddr,d=me("negative",p,c.amount),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:Pe(a,U.V1_1),appArgs:jn.v1_1,accounts:[l],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:u.id==j?[i.id,c.id]:[i.id,u.id,c.id],suggestedParams:f}),h=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:i.id,amount:i.amount,suggestedParams:f}),g=u.id===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:u.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:o,assetIndex:u.id,amount:u.amount,suggestedParams:f}),x=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:l,assetIndex:c.id,amount:d,suggestedParams:f}),A=e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:m.fee+x.fee,note:P,suggestedParams:f}),I=e.assignGroupID([A,m,h,g,x]),t.abrupt("return",[{txn:I[0],signers:[l]},{txn:I[1],signers:[o]},{txn:I[2],signers:[l]},{txn:I[3],signers:[l]},{txn:I[4],signers:[o]}]);case 12:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Gn(){return(Gn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,i=r.account,t.next=4,o([a]);case 4:return u=t.sent,c=v(u,3),p=c[0],l=c[1],d=c[2],f=a.map((function(t,n){return n===Sn.FEE_TXN?p:n===Sn.ASSET1_IN_TXN?l:n===Sn.ASSET2_IN_TXN?d:e.signLogicSigTransactionObject(t.txn,i).blob})),t.abrupt("return",f);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Xn(){return(Xn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.signedTxns,i=t.initiatorAddr,e.prev=1,u=BigInt(a[Sn.LIQUDITY_OUT_TXN].txn.amount),e.next=5,Dt({client:n,pool:r,accountAddr:i});case 5:return c=e.sent,e.next=8,Ie(n,[o]);case 8:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,h=we(a),g=ye(a),e.next=17,Dt({client:n,pool:r,accountAddr:i});case 17:return x=e.sent,(A=x.excessPoolTokens-c.excessPoolTokens)<0n&&(A=0n),e.abrupt("return",{round:f,fees:h,poolTokenID:r.poolTokenID,poolTokenOut:u+A,excessAmount:{excessAmountForAddingLiquidity:A,totalExcessAmount:x.excessPoolTokens},txnID:m,groupID:g});case 23:throw e.prev=23,e.t0=e.catch(1),"SlippageTolerance"===(I=new Y(e.t0,"We encountered something unexpected while adding liquidity. Try again later.")).type&&I.setMessage("Adding liquidity failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),I;case 28:case"end":return e.stop()}}),e,null,[[1,23]])})))).apply(this,arguments)}var qn=Object.freeze({__proto__:null,execute:function(e){return Xn.apply(this,arguments)},generateTxns:function(e){return Vn.apply(this,arguments)},getQuote:function(e){var t=e.pool,n=e.reserves,r=e.asset1In,a=e.asset2In;if(0n===n.issuedLiquidity){var s=BigInt(Math.floor(Math.sqrt(Number(r)*Number(a))));if(s<=BigInt(L))throw new Error("Initial liquidity amount is too small. The amount must be greater than ".concat(L,", this quote is for ").concat(s,"."));return{round:n.round,asset1ID:t.asset1ID,asset1In:BigInt(r),asset2ID:t.asset2ID,asset2In:BigInt(a),poolTokenID:t.poolTokenID,poolTokenOut:s-BigInt(L),share:1}}var o=BigInt(r)*n.issuedLiquidity/n.asset1,i=BigInt(a)*n.issuedLiquidity/n.asset2,u=oo)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(t)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{assetInID:i,assetInAmount:l,assetOutID:c,assetOutAmount:m,swapFee:Number(h),rate:he(p,Number(m))/he(u,Number(l)),priceImpact:g}}function xr(e){var t=e.amount,n=e.assetIn,r=e.assetOut,a=e.pool;if(!a||!$t.isPoolReady(a))throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i=n.id,u=n.decimals,c=r.id,p=r.decimals,l=BigInt(t),d=a.totalFeeShare;if(c===a.asset1ID)s=a.asset2Reserves,o=a.asset1Reserves;else{if(c!==a.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(c,") doesn't belong to the pool ").concat(a.account.address(),"."));s=a.asset1Reserves,o=a.asset2Reserves}var f=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapOutputAmount,a=e.totalFeeShare,s=e.decimals,o=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.outputAmount,a=t*n,s=BigInt(a/(n-r))-t;return s+=BigInt(1),s}({inputSupply:t,outputSupply:n,outputAmount:r}),i=function(e){var t=e.swapAmount,n=e.totalFeeShare,r=Math.floor(Number(t*BigInt(1e4)/(BigInt(1e4)-BigInt(n)))),a=BigInt(r)-t;return a}({swapAmount:o,totalFeeShare:a}),u=o+i,c=pt({inputSupply:t,outputSupply:n,assetIn:{amount:u,decimals:s.assetIn},assetOut:{amount:r,decimals:s.assetOut}});return{swapInputAmount:u,totalFeeAmount:i,priceImpact:c}}({inputSupply:s,outputSupply:o,swapOutputAmount:l,totalFeeShare:d,decimals:{assetIn:u,assetOut:p}}),m=f.swapInputAmount,h=f.totalFeeAmount,g=f.priceImpact;if(l>o)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");if(it(Number(m)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{type:rt.Direct,data:{pool:a,quote:{assetInID:i,assetInAmount:m,assetOutID:c,assetOutAmount:l,swapFee:Number(h),rate:he(p,Number(l))/he(u,Number(m)),priceImpact:g}}}}function Ar(e){return Ir.apply(this,arguments)}function Ir(){return(Ir=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[],u?c.push(new Promise((function(e,t){try{var s=gr({amount:n,assetIn:r,assetOut:a,pool:u});e({type:rt.Direct,data:{pool:u,quote:s}})}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair"))),o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedInput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=6,hr(c);case 6:return p=e.sent,e.abrupt("return",ht(p));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function vr(e){return wr.apply(this,arguments)}function wr(){return(wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.amount,r=t.assetIn,a=t.assetOut,o=t.isSwapRouterEnabled,i=t.network,u=t.pool,c=[new Promise((function(e,t){try{e(xr({amount:n,assetIn:r,assetOut:a,pool:u}))}catch(e){t(e)}}))],o&&c.push(tt({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ce.FixedOutput,network:i}).then((function(e){return{type:rt.Router,data:e}}))),e.next=5,hr(c);case 5:return p=e.sent,e.abrupt("return",ht(p));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function yr(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapInputAmount,a=e.totalFeeShare,s=e.decimals,o=BigInt(function(e){var t=e.inputAmount,n=e.totalFeeShare;return Math.floor(Number(t*BigInt(n))/1e4)}({inputAmount:r,totalFeeShare:a})),i=function(e){var t=e.inputSupply,n=e.outputSupply,r=e.swapAmount,a=t*n,s=n-BigInt(a/(t+BigInt(r)));return s-=BigInt(1)}({inputSupply:t,outputSupply:n,swapAmount:r-o});return{swapOutputAmount:i,totalFeeAmount:o,priceImpact:pt({inputSupply:t,outputSupply:n,assetIn:{amount:r,decimals:s.assetIn},assetOut:{amount:i,decimals:s.assetOut}})}}var br={getQuote:function(e){return mr.apply(this,arguments)},getFixedInputSwapQuote:Ar,getFixedInputDirectSwapQuote:gr,getFixedOutputDirectSwapQuote:xr,getFixedOutputSwapQuote:vr,generateTxns:function(e){return dr.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return fr.apply(this,arguments)},calculateFixedInputSwap:yr};function Tr(e,t){var n,r,a=BigInt(e),s=t.issuedLiquidity;return s>a+BigInt(Lt)?(n=a*t.asset1/s,r=a*t.asset2/s):(n=t.asset1,r=t.asset2),{asset1OutputAmount:n,asset2OutputAmount:r}}function kr(){return(kr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.minAsset1Amount,c=n.minAsset2Amount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.account.address(),f=a.poolTokenID){t.next=8;break}throw new Error("Pool token asset ID is missing");case 8:return m=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:f,amount:o,suggestedParams:l}),(h=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(me("negative",p,u)),e.encodeUint64(me("negative",p,c))],accounts:[d],foreignAssets:[a.asset1ID,a.asset2ID],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(g=[])[ir.ASSET_TRANSFER_TXN]=m,g[ir.APP_CALL_TXN]=h,x=e.assignGroupID(g),t.abrupt("return",[{txn:x[ir.ASSET_TRANSFER_TXN],signers:[i]},{txn:x[ir.APP_CALL_TXN],signers:[i]}]);case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function _r(){return(_r=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.initiatorAddr,i=n.poolTokenIn,u=n.outputAssetId,c=n.minOutputAssetAmount,p=n.slippage,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=a.asset1ID,f=a.asset2ID,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:if(g=0,x=0,A=me("negative",p,c),u!==d){t.next=17;break}g=A,x=0,t.next=23;break;case 17:if(u!==f){t.next=22;break}g=0,x=A,t.next=23;break;case 22:throw new Error("Invalid output asset id. It doesn't match with pool assets");case 23:return I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:m,assetIndex:h,amount:i,suggestedParams:l}),(v=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:a.validatorAppID,note:_e.getAppCallTxnNoteWithClientName(U.V2),appArgs:[or,e.encodeUint64(g),e.encodeUint64(x)],accounts:[m],foreignAssets:[u],suggestedParams:l})).fee=(sr+1)*e.ALGORAND_MIN_TX_FEE,(w=[])[ir.ASSET_TRANSFER_TXN]=I,w[ir.APP_CALL_TXN]=v,y=e.assignGroupID(w),t.abrupt("return",[{txn:y[ir.ASSET_TRANSFER_TXN],signers:[o]},{txn:y[ir.APP_CALL_TXN],signers:[o]}]);case 31:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Er(){return(Er=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.txGroup,a=t.signedTxns,e.next=3,Ie(n,[a]);case 3:return o=e.sent,i=v(o,1),u=i[0].txnID,e.prev=6,e.next=9,hn(n,r);case 9:c=e.sent,e.next=14;break;case 12:e.prev=12,e.t0=e.catch(6);case 14:return e.abrupt("return",{outputAssets:c,txnID:u});case 15:case"end":return e.stop()}}),e,null,[[6,12]])})))).apply(this,arguments)}var Pr,Sr={getQuote:function(e){var t=e.pool,n=e.reserves,r=e.poolTokenIn,a=BigInt(r),s=Tr(a,n),o=s.asset1OutputAmount,i=s.asset2OutputAmount;return{round:n.round,asset1Out:{assetId:t.asset1ID,amount:o},asset2Out:{assetId:t.asset2ID,amount:i},poolTokenIn:{assetId:t.poolTokenID,amount:a}}},getSingleAssetRemoveLiquidityQuote:function(e){var t,n=e.pool,r=e.reserves,a=e.poolTokenIn,s=e.assetOutID,o=e.decimals,i=BigInt(a),u=Tr(i,r),c=u.asset1OutputAmount,p=u.asset2OutputAmount,l=n.totalFeeShare;if(s===n.asset1ID){var d=br.calculateFixedInputSwap({inputSupply:r.asset2-p,outputSupply:r.asset1-c,swapInputAmount:p,totalFeeShare:l,decimals:o}),f=d.swapOutputAmount,m=d.totalFeeAmount,h=d.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:c+f},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:f},swapFees:{assetId:n.asset2ID,amount:m},priceImpact:h}}}else{if(s!==n.asset2ID)throw new Error("assetOutID must be one of the pool assets");var g=br.calculateFixedInputSwap({inputSupply:r.asset1-c,outputSupply:r.asset2-p,swapInputAmount:c,totalFeeShare:l,decimals:o}),x=g.swapOutputAmount,A=g.totalFeeAmount,I=g.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:p+x},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:x},swapFees:{assetId:n.asset2ID,amount:A},priceImpact:I}}}return t},generateTxns:function(e){return kr.apply(this,arguments)},generateSingleAssetOutTxns:function(e){return _r.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return Er.apply(this,arguments)}},Dr=(l(Pr={},U.V1_1,lr),l(Pr,U.V2,Sr),Pr),Or=3n,Nr=1000n,Br=function(e){return e[e.FEE_TXN_INDEX=0]="FEE_TXN_INDEX",e[e.VALIDATOR_APP_CALL_TXN_INDEX=1]="VALIDATOR_APP_CALL_TXN_INDEX",e[e.ASSET_IN_TXN_INDEX=2]="ASSET_IN_TXN_INDEX",e[e.ASSET_OUT_TXN_INDEX=3]="ASSET_OUT_TXN_INDEX",e}(Br||{});function Cr(){return(Cr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.pool,a=n.txGroup,o=n.initiatorSigner,t.next=3,o([a]);case 3:return i=t.sent,u=v(i,2),c=u[0],p=u[1],l=a.map((function(t,n){return n===Br.FEE_TXN_INDEX?c:n===Br.ASSET_IN_TXN_INDEX?p:e.signLogicSigTransactionObject(t.txn,r.account.lsig).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Fr(){return(Fr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(r=n.client,a=n.quoteAndPool,o=n.swapType,i=n.slippage,u=n.initiatorAddr,c=a.pool,p=a.quote,l=p.assetInID,d=p.assetOutID,f=c.account.address(),(m=[c.asset1ID,c.asset2ID]).includes(l)&&m.includes(d)&&l!==d){t.next=7;break}throw new Y({pool:c,quote:p},"Input asset (#".concat(l,") and output asset (#").concat(d,") provided to generate transactions do not belong to the pool ").concat(f,"."));case 7:return t.next=9,r.getTransactionParams().do();case 9:return h=t.sent,g=[Te("swap"),o===Ce.FixedInput?Te("fi"):Te("fo")],x=e.makeApplicationNoOpTxnFromObject({from:f,appIndex:c.validatorAppID,appArgs:g,accounts:[u],note:_e.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:c.asset2ID==j?[c.asset1ID,c.poolTokenID]:[c.asset1ID,c.asset2ID,c.poolTokenID],suggestedParams:h}),A=o===Ce.FixedOutput?me("positive",i,p.assetInAmount):p.assetInAmount,I=l===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:A,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:u,to:f,assetIndex:l,amount:A,suggestedParams:h}),v=o===Ce.FixedInput?me("negative",i,p.assetOutAmount):p.assetOutAmount,w=d===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:f,to:u,amount:v,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:f,to:u,assetIndex:d,amount:v,suggestedParams:h}),y=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:x.fee+w.fee,note:P,suggestedParams:h}),b=e.assignGroupID([y,x,I,w]),t.abrupt("return",[{txn:b[0],signers:[u]},{txn:b[1],signers:[f]},{txn:b[2],signers:[u]},{txn:b[3],signers:[f]}]);case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Lr(e){var t=e.pool,n=e.reserves,r=e.assetIn,s=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var o,i,u,c=BigInt(r.amount);if(r.id===t.asset1ID)o=t.asset2ID,i=n.asset1,u=n.asset2;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Input asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));o=t.asset1ID,i=n.asset2,u=n.asset1}var p=c*Or/Nr,l=u-i*u/(i+(c-p));if(l>u)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var d={assetIn:{amount:c,decimals:s.assetIn},assetOut:{amount:l,decimals:s.assetOut}},f={round:n.round,assetInID:r.id,assetInAmount:c,assetOutID:o,assetOutAmount:l,swapFee:Number(p),rate:ct(d),priceImpact:pt(a({inputSupply:i,outputSupply:u},d))};return{type:rt.Direct,data:{pool:t,quote:f}}}function Rr(e){return Mr.apply(this,arguments)}function Mr(){return(Mr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,i.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount),assetOutID:i.id,assetOutAmount:BigInt(i.amount)+A,excessAmount:{assetID:i.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ur(e){var t=e.pool,n=e.reserves,r=e.assetOut,a=e.decimals;if(t.status!==Ct.READY)throw new E(_.NoAvailablePoolError,"There is not an available pool for this asset pair");var s,o,i,u=BigInt(r.amount);if(r.id===t.asset1ID)s=t.asset2ID,o=n.asset2,i=n.asset1;else{if(r.id!==t.asset2ID)throw new E(_.AssetDoesNotBelongToPoolError,"Output asset (#".concat(r.id,") doesn't belong to the pool ").concat(t.account.address(),"."));s=t.asset1ID,o=n.asset1,i=n.asset2}if(u>i)throw new E(_.OutputAmountExceedsAvailableLiquidityError,"Output amount exceeds available liquidity.");var c=o*i/(i-u)-o,p=c*Nr/(Nr-Or),l=p-c,d=he(a.assetOut,Number(u))/he(a.assetIn,Number(p)),f=he(a.assetOut,Number(i))/he(a.assetIn,Number(o)),m=ge({decimalPlaces:5},Math.abs(d/f-1)),h={round:n.round,assetInID:s,assetInAmount:p,assetOutID:r.id,assetOutAmount:u,swapFee:Number(l),rate:d,priceImpact:m};return{type:rt.Direct,data:{pool:t,quote:h}}}function jr(e){return Vr.apply(this,arguments)}function Vr(){return(Vr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.signedTxns,o=t.assetIn,i=t.assetOut,u=t.initiatorAddr,e.next=3,Dt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ie(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Dt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,o.id===r.asset1ID?(g=c.excessAsset1,x=h.excessAsset1):(g=c.excessAsset2,x=h.excessAsset2),(A=x-g)<0n&&(A=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount)-A,assetOutID:i.id,assetOutAmount:BigInt(i.amount),excessAmount:{assetID:o.id,excessAmountForSwap:A,totalExcessAmount:x},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Gr(){return(Gr=i(s().mark((function e(t){var n,r,o,i,u,c,p,l,d,f;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.client,r=t.pool,o=t.swapType,i=t.txGroup,u=t.signedTxns,c=t.initiatorAddr,r.status===Ct.READY){e.next=3;break}throw new Y({pool:r,swapType:o,txGroup:i},"There is not an available pool for this asset pair");case 3:if(e.prev=3,p={id:i[Br.ASSET_IN_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_IN_TXN_INDEX].txn.amount},l={id:i[Br.ASSET_OUT_TXN_INDEX].txn.assetIndex||j,amount:i[Br.ASSET_OUT_TXN_INDEX].txn.amount},o!==Ce.FixedInput){e.next=12;break}return e.next=9,Rr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 9:d=e.sent,e.next=15;break;case 12:return e.next=14,jr({client:n,pool:r,signedTxns:u,assetIn:p,assetOut:l,initiatorAddr:c});case 14:d=e.sent;case 15:return e.abrupt("return",a(a({},d),{},{groupID:ye(i),fees:we(i)}));case 18:throw e.prev=18,e.t0=e.catch(3),"SlippageTolerance"===(f=new Y(e.t0,"We encountered something unexpected while swapping. Try again later.")).type&&f.setMessage("The swap failed due to too much slippage in the price. Please adjust the slippage tolerance and try again."),f;case 23:case"end":return e.stop()}}),e,null,[[3,18]])})))).apply(this,arguments)}var Xr,qr={getQuote:function(e,t,n,r,a){return e===Ce.FixedInput?Lr({pool:t,reserves:n,assetIn:r,decimals:a}):Ur({pool:t,reserves:n,assetOut:r,decimals:a})},getFixedInputSwapQuote:Lr,getFixedOutputSwapQuote:Ur,generateTxns:function(e){return Fr.apply(this,arguments)},signTxns:function(e){return Cr.apply(this,arguments)},execute:function(e){return Gr.apply(this,arguments)},executeFixedOutputSwap:jr};function Qr(e){return Promise.allSettled(e).then((function(e){if(e.every((function(e){return"rejected"===e.status}))){var t=v(e.map((function(e){return e.reason})),2),n=t[0],r=t[1];if(gt(n)&&!gt(r))throw n;throw r}return e.filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value}))}))}function Wr(){return(Wr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.isSwapRouterEnabled,u=t.pools,c=[],(p=u.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedInputSwapQuote({pool:p.info,assetIn:{amount:r,id:Number(a.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=u.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedInputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:i,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function zr(){return(zr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.amount,a=t.assetIn,o=t.assetOut,i=t.pools,u=t.isSwapRouterEnabled,c=[],(p=i.find((function(e){return e.info.contractVersion===U.V1_1})))?c.push(new Promise((function(e,t){try{e(qr.getFixedOutputSwapQuote({pool:p.info,assetOut:{amount:r,id:Number(o.id)},decimals:{assetIn:a.decimals,assetOut:o.decimals},reserves:p.reserves}))}catch(e){t(e)}}))):c.push(Promise.reject(new E(_.NoAvailablePoolError,"Trying to swap from non-existent pool"))),l=i.find((function(e){return e.info.contractVersion===U.V2})),c.push(br.getFixedOutputSwapQuote({amount:r,assetIn:{id:ne(a),decimals:a.decimals},assetOut:{id:ne(o),decimals:o.decimals},pool:null!==(n=null==l?void 0:l.info)&&void 0!==n?n:null,isSwapRouterEnabled:u,network:t.network})),e.next=8,Qr(c);case 8:return d=e.sent,e.abrupt("return",ht(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Jr=(l(Xr={},U.V1_1,qr),l(Xr,U.V2,br),l(Xr,"getQuote",(function(e){var t=e.type;if(t===Ce.FixedInput)return function(e){return Wr.apply(this,arguments)}(e);if(t===Ce.FixedOutput)return function(e){return zr.apply(this,arguments)}(e);throw new E(_.InvalidSwapTypeError,"Invalid swap type")})),l(Xr,"generateTxns",(function(e){return e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1?qr.generateTxns(a(a({},e),{},{quoteAndPool:e.quote.data})):br.generateTxns(e)})),l(Xr,"signTxns",(function(e){if(e.quote.type===rt.Direct&&ft(e.quote)===U.V1_1){var t=e.quote.data.pool;return qr.signTxns(a(a({},e),{},{pool:t}))}return br.signTxns(e)})),l(Xr,"execute",(function(e){return e.contractVersion===U.V1_1?qr.execute(e):br.execute(e)})),Xr);function Kr(){return(Kr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.client,r=t.pool,a=t.txGroup,o=t.initiatorSigner,e.prev=1,e.next=4,Yr({txGroup:a,pool:r,initiatorSigner:o});case 4:return i=e.sent,e.next=7,Ie(n,[i]);case 7:return u=e.sent,c=v(u,1),p=c[0],l=p.txnID,d=p.confirmedRound,e.abrupt("return",{fees:we(a),confirmedRound:d,txnID:l,groupID:ye(a)});case 15:throw e.prev=15,e.t0=e.catch(1),new Y(e.t0,"We encountered something unexpected while redeeming. Try again later.");case 18:case"end":return e.stop()}}),e,null,[[1,15]])})))).apply(this,arguments)}function Yr(e){return Hr.apply(this,arguments)}function Hr(){return(Hr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.txGroup,a=n.pool,o=n.initiatorSigner,t.next=3,o([r]);case 3:return i=t.sent,u=v(i,1),c=u[0],p=a.account.lsig,l=r.map((function(t,n){return 0===n?c:e.signLogicSigTransactionObject(t.txn,p).blob})),t.abrupt("return",l);case 9:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function $r(){return $r=i(s().mark((function t(n){var r,a,o,u,c,p;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.data,o=n.initiatorSigner,t.prev=1,u=a.map((function(e){var t=e.txGroup,n=e.pool;return{txns:t,txnFees:we(t),groupID:ye(t),lsig:n.account.lsig}})),t.next=5,o(u.map((function(e){return e.txns})));case 5:return c=t.sent,p=Promise.all(u.map((function(t,n){return new Promise(function(){var a=i(s().mark((function a(o,i){var u,p,l,d,f,m;return s().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return a.prev=0,u=t.txns.map((function(r,a){return 0===a?c[n]:e.signLogicSigTransactionObject(r.txn,t.lsig).blob})),a.next=4,Ie(r,[u]);case 4:p=a.sent,l=v(p,1),d=l[0],f=d.txnID,m=d.confirmedRound,o({fees:t.txnFees,groupID:t.groupID,txnID:f,confirmedRound:m}),a.next=15;break;case 12:a.prev=12,a.t0=a.catch(0),i(a.t0);case 15:case"end":return a.stop()}}),a,null,[[0,12]])})));return function(e,t){return a.apply(this,arguments)}}())}))),t.abrupt("return",p);case 10:throw t.prev=10,t.t0=t.catch(1),new Y(t.t0,"We encountered something unexpected while redeeming. Try again later.");case 13:case"end":return t.stop()}}),t,null,[[1,10]])}))),$r.apply(this,arguments)}function Zr(){return(Zr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.assetID,i=n.assetOut,u=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:return c=t.sent,p=a.account.address(),l=e.makeApplicationNoOpTxnFromObject({from:p,appIndex:a.validatorAppID,appArgs:[Te("redeem")],note:_e.getAppCallTxnNoteWithClientName(a.contractVersion),accounts:[u],foreignAssets:0==a.asset2ID?[a.asset1ID,a.poolTokenID]:[a.asset1ID,a.asset2ID,a.poolTokenID],suggestedParams:c}),d=0===o?e.makePaymentTxnWithSuggestedParamsFromObject({from:p,to:u,amount:BigInt(i),suggestedParams:c}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:p,to:u,assetIndex:o,amount:BigInt(i),suggestedParams:c}),f=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:p,amount:l.fee+d.fee,note:P,suggestedParams:c}),m=e.assignGroupID([f,l,d]),t.abrupt("return",[{txn:m[0],signers:[u]},{txn:m[1],signers:[p]},{txn:m[2],signers:[p]}]);case 10:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ea(e){var t,n={},r=T(e);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=(new TextDecoder).decode(Buffer.from(a.key,"base64")),o=void 0;o=1===a.value.type?a.value.bytes:a.value.uint,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function ta(e,t,n){return e*t/n}var na=BigInt(31536e3),ra=BigInt(1e14),aa=BigInt(1e16),sa={testnet:548587153,mainnet:1385499515},oa=14;function ia(e){return ua.apply(this,arguments)}function ua(){return(ua=i(s().mark((function t(n){var r,a,o,i,u;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.assetIDs,i=e.getApplicationAddress(sa[a]),t.next=4,_t(r,i);case 4:return u=t.sent.assets.map((function(e){return e["asset-id"]})),t.abrupt("return",o.filter((function(e){return e!==j&&!u.includes(e)})));case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function ca(){return(ca=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,y,b,T,k,_,E,P;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.network,o=n.poolAddress,i=n.poolTokenId,u=n.lendingManagerId,c=n.asset1In,p=n.asset2In,l=n.initiatorAddr,d=e.getApplicationAddress(sa[a]),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=[c,p].sort((function(e,t){return t.fAssetId-e.fAssetId})),h=v(m,2),g=h[0],x=h[1],A=te(x.id),I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:g.id,amount:g.amount,suggestedParams:f}),y=A?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:x.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:x.id,amount:x.amount,suggestedParams:f}),(b=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("add_liquidity"),e.decodeAddress(o).publicKey,e.encodeUint64(g.lendingAppId),e.encodeUint64(x.lendingAppId)],foreignAssets:[g.id,x.id,g.fAssetId,x.fAssetId],foreignApps:[g.lendingAppId,x.lendingAppId,u],accounts:[o],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),T=Pe(a,U.V2),k=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("noop")],foreignAssets:[i],foreignApps:[T],accounts:[o],suggestedParams:f}),_=[I,y,b,k],t.next=16,ia({client:r,network:a,assetIDs:[g.id,x.id,g.fAssetId,x.fAssetId,i]});case 16:return(E=t.sent).length&&((P=[e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:D*E.length,suggestedParams:f}),e.makeApplicationNoOpTxnFromObject({from:l,appIndex:sa[a],appArgs:[Te("asset_optin")].concat(w(E.map((function(t){return e.encodeUint64(t)})))),foreignAssets:w(E),suggestedParams:f})])[1].fee=(E.length+1)*e.ALGORAND_MIN_TX_FEE,_.unshift.apply(_,P)),t.abrupt("return",e.assignGroupID(_).map((function(e){return{txn:e,signers:[l]}})));case 19:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function pa(){return(pa=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.pool,o=n.poolTokenIn,i=n.initiatorAddr,u=n.asset1Out,c=n.asset2Out,p=n.lendingManagerId,l=n.network,d=e.getApplicationAddress(sa[l]),t.next=4,r.getTransactionParams().do();case 4:if(f=t.sent,m=a.account.address(),h=a.poolTokenID){t.next=9;break}throw new Error("Pool token asset ID is missing");case 9:return g=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:i,to:d,assetIndex:h,amount:o,suggestedParams:f}),(x=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("remove_liquidity"),e.decodeAddress(m).publicKey,e.encodeUint64(u.lendingAppId),e.encodeUint64(c.lendingAppId)],accounts:[m],foreignAssets:[u.id,c.id,u.fAssetId,c.fAssetId],foreignApps:[u.lendingAppId,c.lendingAppId,p],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(oa+1),A=Pe(l,U.V2),I=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:sa[l],appArgs:[Te("noop")],accounts:[m],foreignAssets:[h,u.fAssetId,c.fAssetId],foreignApps:[A],suggestedParams:f}),v=e.assignGroupID([g,x,I]),t.abrupt("return",v.map((function(e){return{txn:e,signers:[i]}})));case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function la(e,t,n){var r=BigInt(Math.floor((new Date).getTime()/1e3)-function(e){return null!=e?e:Math.floor((new Date).getTime()/1e3)}(n));return ta(e,aa+t*r/na,aa)}function da(){return(da=i(s().mark((function e(t,n){var r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,a=r.params["global-state"],o=ea(a),i=Number(Buffer.from(o.pm,"base64").readBigUInt64BE(0)),u=Buffer.from(o.i,"base64"),c=u.readBigUInt64BE(32),p=u.readBigUInt64BE(40),l=Number(u.readBigUInt64BE(48)),e.abrupt("return",{appId:n,managerAppId:i,depositInterestRate:c,depositInterestIndex:p,lastUpdate:l});case 11:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var fa={AddLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return ca.apply(this,arguments)},getAddLiquidityTotalFee:function(t){return e.ALGORAND_MIN_TX_FEE*(4+oa)+(t?(t+1)*e.ALGORAND_MIN_TX_FEE+t*D:0)}}),RemoveLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return pa.apply(this,arguments)},getRemoveLiquidityTotalFee:function(){return e.ALGORAND_MIN_TX_FEE*(3+oa)}}),calculateWithdrawReturn:function(e){var t=e.withdrawAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return ta(BigInt(t),n,ra)},calculateDepositReturn:function(e){var t=e.depositAmount,n=la(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return BigInt(t)*ra/n},getFolksWrapperAppOptInRequiredAssetIDs:ia};function ma(t){var n=t.suggestedParams,r=t.stakingAppID,a=t.initiatorAddr,s=t.liquidityAssetID,o=t.program,i=t.amount,u=e.encodeUint64(i),c=e.encodeUint64(o.id);return e.makeApplicationNoOpTxnFromObject({appIndex:r,from:a,suggestedParams:n,foreignAssets:[s],accounts:[o.accountAddress],appArgs:[Te("commit"),u],note:ae([Te("tinymanStaking/v1:b"),c,e.encodeUint64(s),u])})}function ha(){return(ha=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=n.client,a=n.stakingAppID,o=n.program,i=n.requiredAssetID,u=n.liquidityAssetID,c=n.amount,p=n.initiatorAddr,t.next=3,r.getTransactionParams().do();case 3:if(l=t.sent,d=ma({suggestedParams:l,stakingAppID:a,program:o,liquidityAssetID:u,initiatorAddr:p,amount:c}),f=[d],"number"!=typeof i){t.next=10;break}return m=e.makeApplicationNoOpTxnFromObject({appIndex:a,from:p,suggestedParams:l,foreignAssets:[i],accounts:[o.accountAddress],appArgs:[Te("log_balance")]}),f=e.assignGroupID([d,m]),t.abrupt("return",[{txn:f[0],signers:[p]},{txn:f[1],signers:[p]}]);case 10:return t.abrupt("return",[{txn:f[0],signers:[p]}]);case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var ga=604800,xa=1e3,Aa={testnet:480164661,mainnet:2200606875},Ia={testnet:360907790,mainnet:2200609638},va={testnet:336189106,mainnet:2200608153},wa={testnet:383416252,mainnet:2200608887},ya=2500,ba=400,Ta=604800,ka=Te("p"),_a=Te("a"),Ea=24,Pa=111300,Sa=ya+ba*(41+Ea),Da=function(e){return e[e.Against=0]="Against",e[e.For=1]="For",e[e.Abstain=2]="Abstain",e}(Da||{}),Oa=new Uint8Array(34),Na="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ";function Ba(e){for(var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8,n=new Uint8Array(t),r=BigInt(e),a=t-1;a>=0;a--)n[a]=Number(r&BigInt(255)),r>>=BigInt(8);return n}function Ca(e,t){return 0===Buffer.compare(e,t)}function Fa(e){for(var t=0n,n=0;n=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r>>0,o=new Uint8Array(s);e[t];){var p=n[e.charCodeAt(t)];if(255===p)return;for(var l=0,d=s-1;(0!==p||l>>0,o[d]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");a=l,t++}if(" "!==e[t]){for(var f=s-a;f!==s&&0===o[f];)f++;for(var m=new Uint8Array(r+(s-f)),h=r;f!==s;)m[h++]=o[f++];return m}}}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var n=0,r=0,a=0,s=t.length;a!==s&&0===t[a];)a++,n++;for(var o=(s-a)*p+1>>>0,c=new Uint8Array(o);a!==s;){for(var l=t[a],d=0,f=o-1;(0!==l||d>>0,c[f]=l%i>>>0,l=l/i>>>0;if(0!==l)throw new Error("Non-zero carry");r=d,a++}for(var m=o-r;m!==o&&0===c[m];)m++;for(var h=u.repeat(n);mLa(a(e))})}function Wa({name:e,prefix:t,bitsPerChar:n,alphabet:r}){return qa({prefix:t,name:e,encode:e=>function(e,t,n){const r="="===t[t.length-1],a=(1<n;)o-=n,s+=t[a&i>>o];if(0!==o&&(s+=t[a&i<function(e,t,n,r){const a={};for(let e=0;e=8&&(i-=8,o[c++]=255&u>>i)}if(i>=n||0!=(255&u<<8-i))throw new SyntaxError("Unexpected end of data");return o}(t,r,n,e)})}const za=Wa({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5});Wa({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Wa({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wa({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Wa({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Wa({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Wa({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Wa({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Wa({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});const Ja=Qa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"});Qa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ka=function e(t,n,r){n=n||[];var a=r=r||0;for(;t>=$a;)n[r++]=255&t|Ya,t/=128;for(;t&Ha;)n[r++]=255&t|Ya,t>>>=7;return n[r]=0|t,e.bytes=r-a+1,n},Ya=128,Ha=-128,$a=Math.pow(2,31);var Za=function e(t,n){var r,a=0,s=0,o=n=n||0,i=t.length;do{if(o>=i)throw e.bytes=0,new RangeError("Could not decode varint");r=t[o++],a+=s<28?(r&ts)<=es);return e.bytes=o-n,a},es=128,ts=127;var ns=Math.pow(2,7),rs=Math.pow(2,14),as=Math.pow(2,21),ss=Math.pow(2,28),os=Math.pow(2,35),is=Math.pow(2,42),us=Math.pow(2,49),cs=Math.pow(2,56),ps=Math.pow(2,63),ls={encode:Ka,decode:Za,encodingLength:function(e){return e{const[n,r]=ds(e.subarray(t));return t+=r,n};let r=n(),a=ws;if(18===r?(r=0,t=0):a=n(),0!==r&&1!==r)throw new RangeError(`Invalid CID version ${r}`);const s=t,o=n(),i=n(),u=t+i;return{version:r,codec:a,multihashCode:o,digestSize:i,multihashSize:u-s,size:u}}static parse(e,t){const[n,r]=function(e,t){switch(e[0]){case"Q":{const n=t??Ja;return[Ja.prefix,n.decode(`${Ja.prefix}${e}`)]}case Ja.prefix:{const n=t??Ja;return[Ja.prefix,n.decode(e)]}case za.prefix:{const n=t??za;return[za.prefix,n.decode(e)]}default:if(null==t)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}(e,t),a=vs.decode(r);if(0===a.version&&"Q"!==e[0])throw Error("Version 0 CID string must not include multibase prefix");return Is(a).set(n,e),a}}const ws=112,ys=18;function bs(e,t,n){const r=ms(e),a=r+ms(t),s=new Uint8Array(a+n.byteLength);return fs(e,s,0),fs(t,s,r),s.set(n,a),s}const Ts=Symbol.for("@ipld/js-cid/CID");class ks{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){const t=this.encode(e);return t instanceof Uint8Array?hs(this.code,t):t.then((e=>hs(this.code,e)))}throw Error("Unknown type, must be binary type")}}const _s=85,Es=function({name:e,code:t,encode:n}){return new ks(e,t,n)}({name:"sha2-256",code:18,encode:e=>La(n.createHash("sha256").update(e).digest())});var Ps=126144e3,Ss=1e7,Ds=Math.pow(2,64),Os=48,Ns=21,Bs=48,Cs=Te("tp"),Fs=Te("sc"),Ls=28100,Rs=12900,Ms=421700,Us=409700;function js(e){var t=e/Ta;return(arguments.length>1&&void 0!==arguments[1]&&arguments[1]?Math.floor(t):Math.ceil(t))*Ta}function Vs(e,t){if(e>t)throw new Error("Old timestamp must be less than or equal to new timestamp");for(var n=[],r=js(e)+Ta;re?r=t?e*e*Ds/(2*t):0:r=(e+(e-r))*n/2;return r}function Js(e,t){return Ks.apply(this,arguments)}function Ks(){return(Ks=i(s().mark((function e(t,n){var r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,t.getApplicationByID(n).do();case 2:return r=e.sent,e.abrupt("return",Ys(r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ys(e){var t,n={},r=T(e.params["global-state"]);try{for(r.s();!(t=r.n()).done;){var a=t.value,s=Buffer.from(a.key,"base64").toString(),o=void 0;o=1===a.value.type?Buffer.from(a.value.bytes||"","base64"):a.value.uint||0,n[s]=o}}catch(e){r.e(e)}finally{r.f()}return n}function Hs(){for(var e=arguments.length,t=new Array(e),n=0;n0?Ns-e:0}},{key:"lastAccountPowerBoxIndex",get:function(){return xo(this.powerCount)[0]}},{key:"lastAccountPowerArrayIndex",get:function(){return xo(this.powerCount)[1]}}]),e}(),uo=function(){function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a}return p(e,[{key:"lockEndTimestamp",get:function(){var e=this.bias*Math.pow(2,64)/this.slope;return this.timestamp+e}},{key:"cumulativePowerAt",value:function(e){var t=e-this.timestamp;if(t<0)throw new Error("Time delta must be greater than or equal to 0");return this.cumulativePower+zs(this.bias,this.slope,t)}}]),e}(),co=p((function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a})),po=p((function e(t){u(this,e),this.slopeDelta=t})),lo=function(){function e(t,n,r,a){u(this,e),this.tinyAssetId=t,this.totalLockedAmount=n,this.totalPowerCount=r,this.lastTotalPowerTimestamp=a}return p(e,[{key:"freeTotalPowerSpaceCount",get:function(){var e=this.totalPowerCount%Ns;return e>0?Ns-e:0}},{key:"lastTotalPowerBoxIndex",get:function(){return xo(this.totalPowerCount)[0]}},{key:"lastTotalPowerArrayIndex",get:function(){return xo(this.totalPowerCount)[1]}}]),e}();function fo(){return(fo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ho(r),e.prev=1,e.next=4,Gs(t,n,a);case 4:if(!(o=e.sent)){e.next=7;break}return e.abrupt("return",mo(o));case 7:return e.abrupt("return",null);case 10:return e.prev=10,e.t0=e.catch(1),console.log(e.t0),e.abrupt("return",null);case 14:case"end":return e.stop()}}),e,null,[[1,10]])})))).apply(this,arguments)}function mo(e){var t=Buffer.from(e);return new io(t.readUIntBE(0,8),t.readUIntBE(8,8),t.readUIntBE(16,8),t.readUIntBE(24,8))}function ho(t){return e.decodeAddress(t).publicKey}function go(e){var t=Ba(e),n=new Uint8Array(Cs.length+t.length);return n.set(Cs,0),n.set(t,Cs.length),n}function xo(e){var t=e-1;return[Math.floor(t/Ns),t%Ns]}function Ao(t,n){var r=e.decodeAddress(t).publicKey,a=Ba(n),s=new Uint8Array(r.length+a.length);return s.set(r,0),s.set(a,r.length),s}function Io(e,t,n){return vo.apply(this,arguments)}function vo(){return(vo=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=yo(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",wo(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function wo(t){return new po(Number(e.bytesToBigInt(t.slice(t.length-16,t.length))))}function yo(e){return Hs(Fs,Ba(e))}function bo(e,t,n){return To.apply(this,arguments)}function To(){return(To=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=0,r&&(a=Math.ceil(r/Ns)),o=[],i=0;case 4:if(!(i=e[r].timestamp))break;n=r}return n}function So(e){for(var t,n=Os,r=[],a=0;a=11)throw new Error("Boxes' length cannot be larger than 10");var y=d.slice(0,6),b=[e.makeApplicationNoOpTxnFromObject({from:s,suggestedParams:c,appIndex:n,appArgs:[Te("claim_rewards"),Ba(o),Ba(i),Hs.apply(void 0,w(u.map((function(e){return Ba(e)}))))],foreignApps:[r],foreignAssets:[a],boxes:y,note:l?Te(l):void 0})];b[0].fee=b[0].fee*(i+2);var k=0,_=92+865*i,E=700+700*i;if(_>E&&(k=Math.floor((_-E)/666)+1),k||d.length>6){var P=d.slice(6),S=Ko({sender:s,suggestedParams:c,extraAppArgs:[Ba(Math.max(k-1,0))],index:n,foreignApps:[r],boxes:P});S.fee*=Math.max(k,1),b.unshift(S)}if(p){var D=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,to:e.getApplicationAddress(n),amount:Lo,suggestedParams:c});b.unshift(D)}return e.assignGroupID(b)}var Ho=8,$o=Te("p"),Zo=Te("a"),ei=Te("v"),ti=28500,ni=12500,ri=p((function e(t,n,r,a,s,o,i){u(this,e),this.index=t,this.creationTimestamp=n,this.votingStartTimestamp=r,this.votingEndTimestamp=a,this.votingPower=s,this.voteCount=o,this.isCancelled=i}));function ai(t,n){return Hs(Zo,e.decodeAddress(t).publicKey,Ba(n))}function si(e){return new ri(Fa(e.slice(0,8)),Fa(e.slice(8,16)),Fa(e.slice(16,24)),Fa(e.slice(24,32)),Fa(e.slice(32,40)),Fa(e.slice(40,48)),Boolean(Fa(e.slice(48,49))))}function oi(){return(oi=i(s().mark((function e(t,n,r){var a,o;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=ao(r),e.next=3,Gs(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",si(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ii(t){var n=t.stakingVotingAppId,r=t.vaultAppId,a=t.sender,s=t.proposalId,o=t.proposal,i=t.votes,u=t.assetIds,c=t.accountPowerIndex,p=t.appBoxNames,l=t.suggestedParams,d=t.appCallNote,f=void 0===d?null:d;if(i.length!==u.length)throw new Error("The number of votes must be equal to the number of asset ids");if(u.length>Ho)throw new Error("You cannot cast vote for more than ".concat(Ho," different pools"));if(100!==i.reduce((function(e,t){return e+t}),0))throw new Error("The sum of the votes must equal 100%");var m,h=Hs.apply(void 0,w(i.map((function(e){return Ba(e)})))),g=Hs.apply(void 0,w(u.map((function(e){return Ba(e)})))),x=function(e){return Hs($o,Te(e))}(s),A=ai(a,Math.floor(o.index/8192)),I=!p.some((function(e){return Ca(e,A)})),v=ho(a),y=Math.floor(c/Ns),b=Ao(a,y),k=Ao(a,y+1),_=0,E=[],P=T(u);try{var S=function(){var e=m.value,t=function(e,t){return Hs(ei,Ba(e),Ba(t))}(o.index,e);E.push({appIndex:n,name:t}),p.some((function(e){return Ca(e,t)}))||(_+=1)};for(P.s();!(m=P.n()).done;)S()}catch(e){P.e(e)}finally{P.f()}var D=[{appIndex:n,name:x},{appIndex:n,name:A}].concat(E,[{appIndex:r,name:v},{appIndex:r,name:b},{appIndex:r,name:k}]),O=[e.makeApplicationNoOpTxnFromObject({from:a,suggestedParams:l,appIndex:n,appArgs:[Te("cast_vote"),Te(s),h,g,Ba(c)],foreignApps:[r],boxes:D.slice(0,7),note:f?Te(f):void 0})];O[0].fee*=2,D.length>=7&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(7,14)})),D.length>=14&&O.push(Ko({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(14)}));var N=Number(I)*ti+_*ni;return N&&(O=[e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:l,to:e.getApplicationAddress(n),amount:N})].concat(w(O))),e.assignGroupID(O)}function ui(t){var n=t.accountState,r=t.lockEndTime,a=t.lockedAmount,s=t.network,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.slopeChangeAtLockEndTime,p=t.appCallNote;if(ai.freeTotalPowerSpaceCount&&(b+=Us),c||(b+=Rs);var k=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({amount:a,assetIndex:X[s],from:o,suggestedParams:u,to:e.getApplicationAddress(l)}),e.makeApplicationNoOpTxnFromObject({appIndex:l,from:o,suggestedParams:u,appArgs:[Te("create_lock"),Ba(r)],boxes:d.slice(0,8),note:p}),Ko({sender:o,suggestedParams:u,index:l,boxes:d.slice(8)})];if(b){var _=e.makePaymentTxnWithSuggestedParamsFromObject({amount:b,from:o,suggestedParams:u,to:e.getApplicationAddress(l)});k.unshift(_)}return e.assignGroupID(k)}function ci(t){var n=t.accountState,r=t.lockedAmount,a=t.network,s=t.sender,o=t.vaultAppGlobalState,i=t.suggestedParams,u=t.appCallNote;if(ro.freeTotalPowerSpaceCount&&(v+=Us),!n.freeAccountPowerSpaceCount){var w=Ao(s,n.lastAccountPowerBoxIndex+1);h.push({appIndex:Aa[a],name:w}),v+=Ms}var y=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:X[a],from:s,to:e.getApplicationAddress(Aa[a]),amount:r,suggestedParams:i}),e.makeApplicationNoOpTxnFromObject({appIndex:Aa[a],from:s,suggestedParams:i,appArgs:[Te("increase_lock_amount")],boxes:h,note:u}),Ko({sender:s,suggestedParams:i,index:Aa[a]})];if(v){var b=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,suggestedParams:i,to:e.getApplicationAddress(Aa[a]),amount:v});y.unshift(b)}return e.assignGroupID(y)}function pi(t){var n=t.accountState,r=t.network,a=t.newLockEndTime,s=t.slopeChangeAtNewLockEndTime,o=t.sender,i=t.vaultAppGlobalState,u=t.suggestedParams,c=t.appCallNote;if(a%Ta)throw new Error("Invalid lock end time");if(a<=n.lockEndTime)throw new Error("New lock end time must be greater than current lock end time");var p=ho(o),l=Ao(o,n.lastAccountPowerBoxIndex),d=go(i.lastTotalPowerBoxIndex),f=go(i.lastTotalPowerBoxIndex+1),m=yo(n.lockEndTime),h=yo(a),g=[{appIndex:Aa[r],name:p},{appIndex:Aa[r],name:l},{appIndex:Aa[r],name:d},{appIndex:Aa[r],name:f},{appIndex:Aa[r],name:m},{appIndex:Aa[r],name:h}];if(!n.freeAccountPowerSpaceCount){var x=Ao(o,n.lastAccountPowerBoxIndex+1);g.push({appIndex:Aa[r],name:x})}var A,I=Vs(i.lastTotalPowerTimestamp,Math.floor(Date.now()/1e3)),v=I.length,w=T(I);try{for(w.s();!(A=w.n()).done;){var y=A.value;if(y%Ta==0){var b=yo(y);g.push({appIndex:Aa[r],name:b})}}}catch(e){w.e(e)}finally{w.f()}var k=0;s||(k+=Rs),n.freeAccountPowerSpaceCount||(k+=Ms),v>i.freeTotalPowerSpaceCount&&(k+=Us);var _=[e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:o,suggestedParams:u,appArgs:[Te("extend_lock_end_time"),Ba(a)],boxes:g.slice(0,8),note:c}),Ko({sender:o,suggestedParams:u,index:Aa[r],boxes:g.slice(8)})];if(k){var E=e.makePaymentTxnWithSuggestedParamsFromObject({from:o,suggestedParams:u,to:e.getApplicationAddress(Aa[r]),amount:k});_.unshift(E)}return e.assignGroupID(_)}function li(t){var n=t.accountState,r=t.network,a=t.sender,s=t.suggestedParams,o=t.appCallNote,i=ho(a),u=Ao(a,n.lastAccountPowerBoxIndex),c=Ao(a,n.lastAccountPowerBoxIndex+1),p=[{appIndex:Aa[r],name:i},{appIndex:Aa[r],name:u},{appIndex:Aa[r],name:c}],l=e.makeApplicationNoOpTxnFromObject({appIndex:Aa[r],from:a,suggestedParams:s,appArgs:[Te("withdraw")],foreignAssets:[X[r]],boxes:p,note:o});l.fee*=2;var d=[l];if(!n.freeAccountPowerSpaceCount){var f=e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:s,to:e.getApplicationAddress(Aa[r]),amount:Ms});d.unshift(f)}return e.assignGroupID(d)}var di=function(){function t(e,n,r){u(this,t),this.algodClient=e,this.userAddress=n,this.network=r}var n,r,a,o,c,l,d,f,m,h,g,x,A,I,v,y;return p(t,[{key:"getTinyPower",value:(y=i(s().mark((function e(){var t,n,r,a,o,i,u,c=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=c.length>0&&void 0!==c[0]?c[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=Math.max(o.bias-Ws(o.slope,i),0),e.abrupt("return",u);case 16:case"end":return e.stop()}}),e,this)}))),function(){return y.apply(this,arguments)})},{key:"getTotalTinyPower",value:(v=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=v.length>0&&void 0!==v[0]?v[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchVaultAppGlobalState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,bo(this.algodClient,Aa[this.network],n.totalPowerCount);case 8:if(r=e.sent,a=Po(r,t)){e.next=12;break}return e.abrupt("return",0);case 12:o=r[a],i=Math.floor(o.timestamp/Ta),u=Math.floor(t/Ta)-i,c=Array.from({length:u},(function(e,t){return(i+t)*Ta})),p=c.map((function(e,t){return[0===t?o.timestamp:c[t-1],e]})),l=o.slope,d=o.bias,f=T(p),e.prev=19,f.s();case 21:if((m=f.n()).done){e.next=34;break}return h=m.value,g=h[1]-h[0],x=Ws(l,g),d=Math.max(d-x,0),e.next=28,Io(this.algodClient,Aa[this.network],h[1]);case 28:A=e.sent,I=(null==A?void 0:A.slopeDelta)||0,l=Math.max(l-I,0),0!==d&&0!==l||(d=0,l=0);case 32:e.next=21;break;case 34:e.next=39;break;case 36:e.prev=36,e.t0=e.catch(19),f.e(e.t0);case 39:return e.prev=39,f.f(),e.finish(39);case 42:return e.abrupt("return",d);case 43:case"end":return e.stop()}}),e,this,[[19,36,39,42]])}))),function(){return v.apply(this,arguments)})},{key:"getCumulativeTinyPower",value:(I=i(s().mark((function e(){var t,n,r,a,o,i,u,c,p=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=p.length>0&&void 0!==p[0]?p[0]:Math.floor(Date.now()/xa),e.next=3,this.fetchAccountState();case 3:if(n=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,_o({algodClient:this.algodClient,address:this.userAddress,appId:Aa[this.network],powerCount:n.powerCount});case 8:if(r=e.sent,null!==(a=Po(r,t))){e.next=12;break}return e.abrupt("return",0);case 12:return o=r[a],i=t-o.timestamp,u=zs(o.bias,o.slope,i),c=o.cumulativePower-u,e.abrupt("return",c);case 17:case"end":return e.stop()}}),e,this)}))),function(){return I.apply(this,arguments)})},{key:"fetchVaultAppGlobalState",value:(A=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,Js(this.algodClient,Aa[this.network]);case 3:return t=e.sent,e.abrupt("return",new lo(t.tiny_asset_id,t.total_locked_amount,t.total_power_count,t.last_total_power_timestamp));case 7:return e.prev=7,e.t0=e.catch(0),console.error(e.t0),e.abrupt("return",null);case 11:case"end":return e.stop()}}),e,this,[[0,7]])}))),function(){return A.apply(this,arguments)})},{key:"generateCreateLockTransactions",value:(x=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=o,c){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(p){e.next=15;break}return e.next=14,this.algodClient.getTransactionParams().do();case 14:p=e.sent;case 15:return e.next=17,Io(this.algodClient,Aa[this.network],r);case 17:return l=e.sent,e.abrupt("return",ui({lockedAmount:n,lockEndTime:r,vaultAppGlobalState:c,slopeChangeAtLockEndTime:l,sender:i,network:this.network,accountState:u,suggestedParams:p}));case 19:case"end":return e.stop()}}),e,this)}))),function(e){return x.apply(this,arguments)})},{key:"generateIncreaseLockAmountTransactions",value:(g=i(s().mark((function e(t){var n,r,a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockedAmount,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.abrupt("return",ci({accountState:i,lockedAmount:n,network:this.network,sender:o,vaultAppGlobalState:u,suggestedParams:c}));case 18:case"end":return e.stop()}}),e,this)}))),function(e){return g.apply(this,arguments)})},{key:"generateExtendLockTimeTransactions",value:(h=i(s().mark((function e(t){var n,r,a,o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.newLockEndTime,r=t.userAddress,a=t.suggestedParams,o=r||this.userAddress,e.next=4,this.fetchAccountState();case 4:return i=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(u=e.sent,c=a,u){e.next=11;break}throw new Error("There was an error while fetching vault app global state");case 11:if(i){e.next=13;break}throw new Error("There was an error while fetcing the account state");case 13:if(c){e.next=17;break}return e.next=16,this.algodClient.getTransactionParams().do();case 16:c=e.sent;case 17:return e.next=19,Io(this.algodClient,Aa[this.network],n);case 19:return p=e.sent,e.abrupt("return",pi({accountState:i,network:this.network,newLockEndTime:n,sender:o,vaultAppGlobalState:u,suggestedParams:c,slopeChangeAtNewLockEndTime:null==p?void 0:p.slopeDelta}));case 21:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"generateIncreaseLockAmountAndExtendLockEndTimeTransactions",value:(m=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.lockAmount,r=t.lockEndTime,a=t.userAddress,o=t.suggestedParams,i=a||this.userAddress,e.next=4,this.fetchAccountState();case 4:return u=e.sent,e.next=7,this.fetchVaultAppGlobalState();case 7:if(c=e.sent,p=[],l=[],d=o,c){e.next=13;break}throw new Error("There was an error while fetching vault app global state");case 13:if(u){e.next=15;break}throw new Error("There was an error while fetcing the account state");case 15:if(d){e.next=19;break}return e.next=18,this.algodClient.getTransactionParams().do();case 18:d=e.sent;case 19:return p=ci({accountState:u,lockedAmount:n,network:this.network,sender:i,vaultAppGlobalState:c,suggestedParams:d}),u.powerCount+=1,c.totalPowerCount+=1,e.next=24,Io(this.algodClient,Aa[this.network],r);case 24:return f=e.sent,l=pi({accountState:u,network:this.network,newLockEndTime:r,sender:i,vaultAppGlobalState:c,suggestedParams:d,slopeChangeAtNewLockEndTime:null==f?void 0:f.slopeDelta}),m=[].concat(w(p),w(l)),e.abrupt("return",Boolean(p.length)&&Boolean(l.length)?Zs(p,l):m);case 28:case"end":return e.stop()}}),e,this)}))),function(e){return m.apply(this,arguments)})},{key:"generateWithdrawTransactions",value:(f=i(s().mark((function e(t,n,r){var a,o,i,u,c;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return a=t||this.userAddress,e.next=3,this.fetchAccountState();case 3:if(o=e.sent,i=r,o){e.next=7;break}throw new Error("There was an error while fetcing the account state");case 7:if(i){e.next=11;break}return e.next=10,this.algodClient.getTransactionParams().do();case 10:i=e.sent;case 11:if(u=li({accountState:o,network:this.network,sender:a,suggestedParams:i,client:this.algodClient}),!n){e.next=17;break}return e.next=15,H({client:this.algodClient,initiatorAddr:a,assetID:X[this.network]});case 15:c=e.sent,u=Zs([c[0].txn],u);case 17:return e.abrupt("return",u);case 18:case"end":return e.stop()}}),e,this)}))),function(e,t,n){return f.apply(this,arguments)})},{key:"fetchAccountState",value:function(){return function(e,t,n){return fo.apply(this,arguments)}(this.algodClient,Aa[this.network],this.userAddress)}},{key:"fetchStakingDistributionProposal",value:function(e){return function(e,t,n){return oi.apply(this,arguments)}(this.algodClient,Ia[this.network],e)}},{key:"generateCastVoteForStakingDistributionProposalTransactions",value:(d=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.proposalId,a=t.votes,o=t.assetIds,i=t.userAddress,u=t.suggestedParams,c=null!=i?i:this.userAddress,p=u,e.next=5,this.fetchStakingDistributionProposal(r);case 5:if(l=e.sent){e.next=8;break}throw new Error("There was an error while fetching staking distribution proposal");case 8:if(p){e.next=12;break}return e.next=11,this.algodClient.getTransactionParams().do();case 11:p=e.sent;case 12:return e.next=14,this.fetchAccountState();case 14:return d=e.sent,e.next=17,eo(this.algodClient,Ia[this.network]);case 17:return f=e.sent,e.next=20,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==d?void 0:d.powerCount)&&void 0!==n?n:null});case 20:if(m=e.sent,null!==(h=Po(m,l.creationTimestamp))){e.next=24;break}throw new Error("It is required to have an account power at the staking distribution proposal creation timestamp");case 24:return e.abrupt("return",ii({stakingVotingAppId:Ia[this.network],vaultAppId:Aa[this.network],sender:c,proposalId:r,proposal:l,votes:a,assetIds:o,accountPowerIndex:h,appBoxNames:f,suggestedParams:p,appCallNote:null}));case 25:case"end":return e.stop()}}),e,this)}))),function(e){return d.apply(this,arguments)})},{key:"fetchRewardsAppGlobalState",value:(l=i(s().mark((function t(){var n;return s().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.prev=0,t.next=3,Js(this.algodClient,va[this.network]);case 3:return n=t.sent,t.abrupt("return",new Ro(n.tiny_asset_id,n.vault_app_id,n.reward_history_count,n.first_period_timestamp,n.reward_period_count,e.encodeAddress(n.manager),e.encodeAddress(n.rewards_manager)));case 7:return t.prev=7,t.t0=t.catch(0),console.error(t.t0),t.abrupt("return",null);case 11:case"end":return t.stop()}}),t,this,[[0,7]])}))),function(){return l.apply(this,arguments)})},{key:"generateClaimRewardTransactions",value:(c=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,x,A,I,v,w,y,b,T,k;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(r=t.periodIndexStart,a=t.periodCount,o=t.userAddress,i=t.suggestedParams,u=t.shouldOptIntoTINY,c=null!=o?o:this.userAddress,p=i){e.next=7;break}return e.next=6,this.algodClient.getTransactionParams().do();case 6:p=e.sent;case 7:return e.next=9,this.fetchAccountState();case 9:return l=e.sent,e.next=12,this.fetchRewardsAppGlobalState();case 12:if(d=e.sent){e.next=15;break}throw new Error("There was an error while fetching rewards app global state");case 15:if(!(r+a>d.rewardPeriodCount)){e.next=17;break}throw new Error("The reward period index to be claimed cannot be larger than the latest reward period index");case 17:return e.next=19,_o({algodClient:this.algodClient,address:c,appId:Aa[this.network],powerCount:null!==(n=null==l?void 0:l.powerCount)&&void 0!==n?n:null});case 19:for(f=e.sent,m=d.firstPeriodTimestamp+r*ga,h=d.firstPeriodTimestamp+(r+a)*ga,g=[],x=m;x=Math.floor(Date.now()/xa)||c.votingEndTimestamp<=Math.floor(Date.now()/xa))){e.next=23;break}throw new Error("Voting period is not active");case 23:return e.next=25,_o({algodClient:this.algodClient,address:i,appId:Aa[this.network],powerCount:p.powerCount});case 25:if(l=e.sent,null!==(d=Po(l,c.creationTimestamp))){e.next=29;break}throw new Error("Account power index not found");case 29:return f=Math.floor(c.index/(8*Ea)),m=ai(i,f),e.next=33,qs(this.algodClient,wa[this.network],m);case 33:return h=!e.sent,e.abrupt("return",Oo({proposalVotingAppId:wa[this.network],vaultAppId:Aa[this.network],sender:i,proposalId:n,proposal:c,vote:a,accountPowerIndex:d,createAttendanceSheetBox:h,suggestedParams:u}));case 35:case"end":return e.stop()}}),e,this)}))),function(e){return a.apply(this,arguments)})},{key:"fetchProposalVotingAppGlobalState",value:(r=i(s().mark((function e(){var t;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Js(this.algodClient,wa[this.network]);case 2:return t=e.sent,e.abrupt("return",new ro(t.vault_app_id,t.proposal_index_counter,t.voting_delay,t.voting_duration,t.proposal_threshold,t.proposal_threshold_numerator,t.quorum_threshold,t.approval_requirement,t.manager,t.proposal_manager));case 4:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"getRequiredTinyPowerToCreateProposal",value:(n=i(s().mark((function e(t){var n,r,a;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null==t){e.next=4;break}e.t0=t,e.next=7;break;case 4:return e.next=6,this.getTotalTinyPower();case 6:e.t0=e.sent;case 7:return n=e.t0,e.next=10,this.fetchProposalVotingAppGlobalState();case 10:return r=e.sent,a=r.proposalThreshold,r.proposalThresholdNumerator&&(a=Math.max(a,Math.floor(n*r.proposalThresholdNumerator/100)+1)),e.abrupt("return",a);case 14:case"end":return e.stop()}}),e,this)}))),function(e){return n.apply(this,arguments)})}]),t}(),fi=2500,mi=400,hi=function(){function e(t,n){u(this,e),l(this,"data",null),this.name=t,this.structReference=n,this.size=n[t].size,this.fields=n[t].fields}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.size)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t;if(!this.data)throw new Error("Data is not initialized");var n=this.fields[e];if(!n)throw new Error("Field ".concat(e," does not exist in struct ").concat(this.name));var r=n.offset,a=n.offset+n.size,s=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(r,a);return Ii(n.type,this.structReference).apply(Buffer.from(s))}}]),e}(),gi=function(){function e(t,n){u(this,e),l(this,"data",null),this.struct=t,this.length=n}return p(e,[{key:"apply",value:function(e){var t=e;return t||(t=Buffer.alloc(this.struct.size*this.length)),this.data=new DataView(t.buffer,t.byteOffset,t.byteLength),this}},{key:"getField",value:function(e){var t,n=this.struct.size*e,r=n+this.struct.size,a=null===(t=this.data)||void 0===t?void 0:t.buffer.slice(n,r);return this.struct.apply(a?Buffer.from(a):void 0)}}]),e}(),xi=function(){function e(){u(this,e)}return p(e,[{key:"apply",value:function(e){for(var t=BigInt(0),n=0;n2&&void 0!==arguments[2]?arguments[2]:Math.floor(Date.now()/1e3),a=(n=e,Math.floor(n*Ds/Ps)),s=t-r;return s<0?0:Ws(a,s)},exports.combineAndRegroupSignerTxns=function(){for(var t=arguments.length,n=new Array(t),r=0;r=e.minimum_required_balance},exports.intToBytes=Ba,exports.isAccountOptedIntoApp=function(e){var t=e.appID;return e.accountAppsLocalState.some((function(e){return e.id===t}))},exports.isSwapAssetInAmountLow=it,exports.isSwapQuoteErrorCausedByAmount=gt,exports.poolUtils=$t,exports.prepareCommitTransactions=function(e){return ha.apply(this,arguments)},exports.redeemAllExcessAsset=function(e){return $r.apply(this,arguments)},exports.redeemExcessAsset=function(e){return Kr.apply(this,arguments)},exports.sendAndWaitRawTransaction=Ie,exports.sumUpTxnFees=we,exports.tinymanContract_v1_1=wt,exports.tinymanContract_v2=Tt,exports.tinymanJSSDKConfig=_e; diff --git a/dist/liquid-stake/stAlgoClient.d.ts b/dist/liquid-stake/stAlgoClient.d.ts index a503c229..7e8a281c 100644 --- a/dist/liquid-stake/stAlgoClient.d.ts +++ b/dist/liquid-stake/stAlgoClient.d.ts @@ -12,6 +12,7 @@ declare class TinymanSTAlgoClient extends TinymanBaseClient { private getUserStateBoxName; private getApplyRateChangeTxnIfNeeded; private getUserBoxPaymentTxnIfNeeded; + private getUserBoxPaymentTxn; private shouldApplyRateChange; private getApplyRateChangeTxn; } diff --git a/src/liquid-stake/stAlgoClient.ts b/src/liquid-stake/stAlgoClient.ts index fccce9d7..7966962c 100644 --- a/src/liquid-stake/stAlgoClient.ts +++ b/src/liquid-stake/stAlgoClient.ts @@ -58,10 +58,12 @@ class TinymanSTAlgoClient extends TinymanBaseClient { }) ]; - return this.setupTxnFeeAndAssignGroupId({ - txns, - additionalFeeCount: 2 - }); + return Promise.all( + this.setupTxnFeeAndAssignGroupId({ + txns, + additionalFeeCount: 2 + }) + ); } async decreaseStake(amount: number, userAddress: string) { @@ -81,7 +83,7 @@ class TinymanSTAlgoClient extends TinymanBaseClient { }) ]; - return this.setupTxnFeeAndAssignGroupId({txns, additionalFeeCount: 2}); + return Promise.all(this.setupTxnFeeAndAssignGroupId({txns, additionalFeeCount: 2})); } async claimRewards(userAddress: string) { @@ -105,7 +107,7 @@ class TinymanSTAlgoClient extends TinymanBaseClient { }) ]; - return this.setupTxnFeeAndAssignGroupId({txns, additionalFeeCount: 3}); + return Promise.all(this.setupTxnFeeAndAssignGroupId({txns, additionalFeeCount: 3})); } async calculateIncreaseStakeFee(accountAddress: string) { From 8b200b392a0c81d89f55f9bcc2f01efffe5f20f8 Mon Sep 17 00:00:00 2001 From: gulcinuras Date: Fri, 6 Dec 2024 15:11:48 +0100 Subject: [PATCH 4/4] Bump up the version for new release --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9eb1faef..2a3829e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tinymanorg/tinyman-js-sdk", - "version": "4.1.0", + "version": "4.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@tinymanorg/tinyman-js-sdk", - "version": "4.1.0", + "version": "4.1.1", "license": "MIT", "dependencies": { "algosdk": "^2.8.0", diff --git a/package.json b/package.json index d0728173..212ef6d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tinymanorg/tinyman-js-sdk", - "version": "4.1.0", + "version": "4.1.1", "description": "Tinyman JS SDK", "author": "Tinyman Core Team", "license": "MIT",