From 322cdc521478fd9303a8ab7fecc4559026a92c1b Mon Sep 17 00:00:00 2001 From: gulcinuras Date: Wed, 14 Aug 2024 17:47:34 +0200 Subject: [PATCH 1/3] Include extra app call note data if included --- dist/config.d.ts | 2 +- dist/index.js | 2 +- dist/swap/types.d.ts | 1 + src/config.ts | 9 +++++++-- src/swap/types.ts | 1 + src/swap/v2/index.ts | 5 ++++- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/dist/config.d.ts b/dist/config.d.ts index 698c64bd..be48f145 100644 --- a/dist/config.d.ts +++ b/dist/config.d.ts @@ -8,7 +8,7 @@ declare class TinymanJSSDKConfig { /** * @returns {Uint8Array} - encoded note includings version with client name */ - getAppCallTxnNoteWithClientName(contractVersion: ContractVersionValue): Uint8Array; + getAppCallTxnNoteWithClientName(contractVersion: ContractVersionValue, extraData?: Record): Uint8Array; } export declare const tinymanJSSDKConfig: TinymanJSSDKConfig; export {}; diff --git a/dist/index.js b/dist/index.js index cae02d0f..a051f7c8 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,A(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(x(a),n),a}return p(n)}(),P=Uint8Array.from([1]),S=1e5,D=1e5,O=1e5,N=1e5,L=1e5,B=5e4,C=28500,F=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:""},X={V1:"TM1POOL",V1_1:"TMPOOL11",V2:"TMPOOL2"},G={testnet:258703304,mainnet:22e8},q="- would result negative",Q="logic eval error:",W="exceeds schema integer count",z=/transaction \w+:/,J=function(e){d(n,A(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 $(e,t){var n=[e,t];return[Math.max.apply(Math,n),Math.min.apply(Math,n)]}function Z(e){return Number(e)===j}function ee(e){return Number(e.id)}function te(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 ne(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 re=100000n,ae=100000n,se=100000n,oe=25000n+25000n,ie=25000n+3500n;function ue(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 re+ae*BigInt(o.length)+se*BigInt(s.length+a.length)+ie*r+oe*n}function ce(e){return new Promise((function(t){setTimeout((function(){t(null)}),e)}))}function pe(e,t){return le.apply(this,arguments)}function le(){return(le=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,ce(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 de(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 fe(e,t){var n=Number(e);return me({decimalPlaces:n},Math.pow(10,-n)*Number(t))}function me(e,t){var n=e.decimalPlaces,r=void 0===n?0:n;if(r>0){var a=v(ge(t),2),s=a[0],o=a[1],i=v(ge(Math.round(Number(he(s,o+r)))),2),u=i[0],c=i[1];return Number(he(u,c-r))}return Math.round(t)}function he(e,t){return e+(t<0?"e".concat(t):"e+".concat(t))}function ge(e){if(e.toString().includes("e")){var t=e.toString().split("e");return[parseFloat(t[0]),parseFloat(t[1])]}return[e,0]}function Ae(e,t){return xe.apply(this,arguments)}function xe(){return(xe=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,pe(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 J(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 Ie(e){return e.reduce((function(e,t){return e+t.txn.fee}),0)}function ve(e){return(t=e[0].txn.group)?Buffer.from(t).toString("base64"):"";var t}function we(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 ye(e){return(new TextEncoder).encode(e)}var be,Te=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){var t=e===U.V1_1?"v1":e;return ye("tinyman/".concat(t,':j{"origin":"').concat(this.clientName,'"}'))}}]),e}()),ke=(l(be={},U.V1_1,{testnet:62368684,mainnet:552635992}),l(be,U.V2,{testnet:148607e3,mainnet:1002541853}),be);function _e(e,t){var n=ke[t][e];if(!n)throw new Error("No Validator App exists for ".concat(e," network with ").concat(t," contract version"));return n}function Ee(){return(Ee=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:_e(a,o),note:Te.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Pe(){return(Pe=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:_e(a,o),note:Te.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var Se,De,Oe,Ne=function(e){return e.FixedInput="fixed-input",e.FixedOutput="fixed-output",e}({}),Le=.003,Be=function(e){return e[e.INPUT_TXN=0]="INPUT_TXN",e[e.APP_CALL_TXN=1]="APP_CALL_TXN",e}({}),Ce=(l(Se={},Ne.FixedInput,1),l(Se,Ne.FixedOutput,2),Se),Fe=2,Re=ye("swap"),Me=(l(De={},Ne.FixedInput,ye("fixed-input")),l(De,Ne.FixedOutput,ye("fixed-output")),De),Ue={ASSET_OPT_IN:ye("asset_opt_in")},je={testnet:184778019,mainnet:1083651166},Ve=(l(Oe={},Ne.FixedInput,7),l(Oe,Ne.FixedOutput,8),Oe);function Xe(e){var t=We(e),n=t.assetIn,r=t.assetOut;return fe(r.asset.decimals,Number(r.amount))/fe(n.asset.decimals,Number(n.amount))}function Ge(e){var t=je[e];if(!t)throw new Error("Unknown network or network not supported: ".concat(e));return t}function qe(e){return e[e.length-1].quote.amount_out}function Qe(e){return e[0].quote.amount_in}function We(e){return{assetIn:Qe(e),assetOut:qe(e)}}function ze(e){return Je.apply(this,arguments)}function Je(){return(Je=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:[Ue.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 Ye(e){return Ke.apply(this,arguments)}function Ke(){return(Ke=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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=[ee(u[0].quote.amount_in.asset),ee(u[0].quote.amount_out.asset),ee(u[1].quote.amount_out.asset)],d=l[0],f=l[1],m=l[2],h=[Number(Qe(u).amount),Number(qe(u).amount)],g=h[0],A=h[1],x=[u[0].pool.address,u[1].pool.address],I=x[0],v=x[1],w=i===Ne.FixedInput?g:de("positive",c,g),y=i===Ne.FixedOutput?A:de("negative",c,A),b=Z(d),T=Ge(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:[Re,Me[i],e.encodeUint64(y)],foreignApps:[_e(o,U.V2)],foreignAssets:[d,f,m],accounts:[I,v],suggestedParams:p,note:Te.getAppCallTxnNoteWithClientName(U.V2)})).fee=e.ALGORAND_MIN_TX_FEE*(Ve[i]+1),E=[k,_],t.next=17,He({client:a,network:o,assetIDs:[d,f,m]});case 17:if(!((P=t.sent).length>0)){t.next=23;break}return t.next=21,ze({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 He(e){return $e.apply(this,arguments)}function $e(){return($e=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(Ge(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 Ze(e){return et.apply(this,arguments)}function et(){return(et=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 tt=function(e){return e.Direct="direct",e.Router="router",e}({}),nt=4*e.ALGORAND_MIN_TX_FEE;function rt(t){return(Ce[t]+Fe)*e.ALGORAND_MIN_TX_FEE}function at(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Le;return Math.ceil(1/e)}function st(e){return e1&&void 0!==arguments[1]?arguments[1]:Le)}function ot(t){return(Ce[t]+1)*e.ALGORAND_MIN_TX_FEE}function it(e){var t=e.assetIn,n=e.assetOut;return fe(n.decimals,Number(n.amount))/fe(t.decimals,Number(t.amount))}function ut(e){var t=e.inputSupply,n=e.outputSupply,r=e.assetIn,a=e.assetOut,s=it({assetIn:r,assetOut:a}),o=fe(a.decimals,Number(n))/fe(r.decimals,Number(t));return me({decimalPlaces:5},Math.abs(s/o-1))}function ct(e){if(e.type===tt.Router){var t=Qe(e.data.route);return{id:ee(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetInID,amount:e.data.quote.assetInAmount}}function pt(e){if(e.type===tt.Router){var t=qe(e.data.route);return{id:ee(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetOutID,amount:e.data.quote.assetOutAmount}}function lt(e){return e.type===tt.Direct?e.data.pool.contractVersion:U.V2}function dt(e){return e.type===tt.Direct?e.data.quote.rate:Xe(e.data.route)}function ft(e){for(var t=e[0],n=dt(t),r=1;rn&&(t=a,n=s)}return t}function mt(e){return e instanceof E&&[_.SwapRouterInsufficientReservesError,_.SwapRouterLowSwapAmountError,_.OutputAmountExceedsAvailableLiquidityError,_.LowSwapAmountError].includes(e.type)}var ht={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"},gt={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"},At=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}})),xt=function(n){d(a,At);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=_e(n.network,U.V1_1),a=v($(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:_t(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 kt(e,t){var n=e["apps-local-state"].find((function(e){return e.id===t}));return n?te({stateArray:n["key-value"],shouldDecodeKeys:!0}):null}function _t(e){var t=e["apps-total-schema"];return S+D*(e.assets||[]).length+N*(e["created-apps"]||[]).length+O*(e["apps-local-state"]||[]).length+B*Number(t&&t["num-byte-slice"]||0)+C*Number(t&&t["num-uint"]||0)+L*(e["apps-total-extra-pages"]||0)}var Et=ye("e");function Pt(e){return St.apply(this,arguments)}function St(){return(St=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,A,x,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(A=g["key-value"]){n.next=19;break}return n.abrupt("break",31);case 19:x=te({stateArray:A}),I=t.fromByteArray(ne([e.decodeAddress(f).publicKey,Et,e.encodeUint64(o.asset1ID)])),v=t.fromByteArray(ne([e.decodeAddress(f).publicKey,Et,e.encodeUint64(o.asset2ID)])),w=t.fromByteArray(ne([e.decodeAddress(f).publicKey,Et,e.encodeUint64(o.poolTokenID)])),y=x[I],b=x[v],k=x[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 Dt(){return(Dt=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,A,x,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=te({stateArray:p["key-value"]}),f=0,m=Object.entries(d);fFt)){n.next=48;break}throw new Error("Issued liquidity value is out of the expected range ([0n, ".concat(Ft,"]): ").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 jt(){return jt=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,Tt(n,r);case 6:return i=e.sent,u=kt(i,_e(a,U.V1_1)),c=null,u&&(l=i["created-assets"][0],p=l.index,c={asset1ID:u[Lt[U.V1_1].asset1],asset2ID:u[Lt[U.V1_1].asset2],poolTokenID:p},o[r]=c),e.abrupt("return",c);case 11:case"end":return e.stop()}}),e)}))),jt.apply(this,arguments)}var Vt=Object.freeze({__proto__:null,getPoolAssets:function(e){return jt.apply(this,arguments)},getPoolInfo:Rt,getPoolReserves:function(e,t){return Ut.apply(this,arguments)}});function Xt(e){return Gt.apply(this,arguments)}function Gt(){return(Gt=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=bt(U.V2),u=i.generateLogicSigAccountForPool(t),c=_e(r,U.V2),p=u.address(),l=$(a,o),e.next=8,Tt(n,p);case 8:return d=e.sent,f=kt(d,c),m={account:u,validatorAppID:c,asset1ID:l[0],asset2ID:l[1],status:f?Nt.READY:Nt.NOT_CREATED,contractVersion:U.V2},f&&(m.asset1ProtocolFees=BigInt(f[Lt.v2.asset1ProtocolFees]),m.asset2ProtocolFees=BigInt(f[Lt.v2.asset2ProtocolFees]),m.asset1Reserves=BigInt(f[Lt.v2.asset1Reserves]),m.asset2Reserves=BigInt(f[Lt.v2.asset2Reserves]),m.issuedPoolTokens=BigInt(f[Lt.v2.issuedPoolTokens]),m.cumulativePriceUpdateTimeStamp=Number(f[Lt.v2.cumulativePriceUpdateTimeStamp]),m.protocolFeeRatio=Number(f[Lt.v2.protocolFeeRatio]),m.totalFeeShare=BigInt(f[Lt.v2.totalFeeShare]),m.poolTokenID=Number(f[Lt.v2.poolTokenID]),m.asset1ID=Number(f[Lt.v2.asset1]),m.asset2ID=Number(f[Lt.v2.asset2])),e.abrupt("return",m);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function qt(){return(qt=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,Tt(t,n.account.address());case 2:return r=e.sent,a=kt(r,n.validatorAppID),o={asset1:0n,asset2:0n,issuedLiquidity:0n,round:r.round},a&&(o.asset1=BigInt(a[Lt.v2.asset1Reserves]),o.asset2=BigInt(a[Lt.v2.asset2Reserves]),o.issuedLiquidity=BigInt(a[Lt.v2.issuedPoolTokens])),e.abrupt("return",o);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Qt(){return(Qt=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,Tt(n,r);case 3:return o=e.sent,i=kt(o,_e(a,U.V2)),u=null,i&&(u={asset1ID:i[Lt[U.V2].asset1],asset2ID:i[Lt[U.V2].asset2],poolTokenID:i[Lt[U.V2].poolTokenID]}),e.abrupt("return",u);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Wt=Object.freeze({__proto__:null,getPoolAssets:function(e){return Qt.apply(this,arguments)},getPoolInfo:Xt,getPoolReserves:function(e,t){return qt.apply(this,arguments)}});function zt(e){return Boolean(e&&!(e.asset1+e.asset2))}var Jt,Yt=Object.freeze({__proto__:null,getPoolPairRatio:function(e){var t=zt(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([Rt(e),Xt(e)])},isPoolEmpty:zt,isPoolNotCreated:function(e){return(null==e?void 0:e.status)===Nt.NOT_CREATED},isPoolReady:function(e){return(null==e?void 0:e.status)===Nt.READY}}),Kt=a((l(Jt={},U.V1_1,a(a({},Vt),Yt)),l(Jt,U.V2,a(a({},Wt),Yt)),Jt),Yt),Ht=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}({}),$t={ASA_ALGO:96e4,ASA_ASA:859e3};function Zt(){return(Zt=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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=H(o,i),l=v(p,2),d=l[0],f=d.id,m=d.unit_name,h=l[1],g=h.id,A=h.unit_name,x=Z(g),I=_e(a,U.V1_1),w=It.generateLogicSigAccountForPool({network:a,asset1ID:f,asset2ID:g}),y=w.address(),b=e.makeApplicationOptInTxnFromObject({from:y,appIndex:I,note:Te.getAppCallTxnNoteWithClientName(U.V1_1),appArgs:[ye("bootstrap"),e.encodeUint64(f),e.encodeUint64(g)],foreignAssets:x?[f]:[g],suggestedParams:c}),T=e.makeAssetCreateTxnWithSuggestedParamsFromObject({from:y,total:0xffffffffffffffffn,decimals:6,defaultFrozen:!1,unitName:X.V1_1,assetName:"TinymanPool1.1 ".concat(m,"-").concat(A),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:en(x),suggestedParams:c}),(E=[])[Ht.FUNDING_TXN]=_,E[Ht.VALIDATOR_APP_CALL]=b,E[Ht.POOL_TOKEN_CREATE]=T,E[Ht.ASSET1_OPT_IN]=k,x||(E[Ht.ASSET2_OPT_IN]=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:g,amount:0,suggestedParams:c})),P=e.assignGroupID(E),S=[{txn:P[Ht.FUNDING_TXN],signers:[u]},{txn:P[Ht.VALIDATOR_APP_CALL],signers:[y]},{txn:P[Ht.POOL_TOKEN_CREATE],signers:[y]},{txn:P[Ht.ASSET1_OPT_IN],signers:[y]}],P[Ht.ASSET2_OPT_IN]&&S.push({txn:P[Ht.ASSET2_OPT_IN],signers:[y]}),t.abrupt("return",S);case 23:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function en(e){return e?$t.ASA_ALGO:$t.ASA_ASA}function tn(){return(tn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x;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=$(i,u),f=v(d,2),m=f[0],h=f[1],g=It.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),A=[],x=r.map((function(t,n){if(n===Ht.FUNDING_TXN)return A.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return A.push(a),s})),t.abrupt("return",{signedTxns:x,txnIDs:A});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function nn(e){return rn.apply(this,arguments)}function rn(){return(rn=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,pe(n,a[Ht.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 J(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 an(){return(an=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,nn({client:n,signedTxns:u,txnIDs:c});case 3:return e.abrupt("return",Kt.v1_1.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var sn={generateTxns:function(e){return Zt.apply(this,arguments)},signTxns:function(e){return tn.apply(this,arguments)},execute:function(e){return an.apply(this,arguments)},getBootstrapFundingTxnAmount:en};var on=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e}({}),un={ASA_ALGO:5,ASA_ASA:6};function cn(e,t){return pn.apply(this,arguments)}function pn(){return(pn=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 ln(e,t){return dn.apply(this,arguments)}function dn(){return(dn=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,cn(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 fn(e,t){return mn.apply(this,arguments)}function mn(){return(mn=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,ln(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 hn(){return(hn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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=_e(a,U.V2),l=e.getApplicationAddress(p),d=H(o,i),f=v(d,2),m=f[0].id,h=f[1].id,t.next=9,Kt.v2.getPoolInfo({client:r,network:a,asset1ID:m,asset2ID:h});case 9:if(t.sent.status!==Nt.READY){t.next=12;break}throw new Error("Pool for ".concat(o.unit_name,"-").concat(i.unit_name," already exists"));case 12:return g=yt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),A=g.address(),x=Z(h),(I=e.makeApplicationOptInTxnFromObject({from:A,appIndex:p,appArgs:[ye("bootstrap")],note:Te.getAppCallTxnNoteWithClientName(U.V2),foreignAssets:[m,h],rekeyTo:l,suggestedParams:c})).fee=An(x),w=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:A,amount:gn(x),suggestedParams:c}),(y=[])[on.FUNDING_TXN]=w,y[on.VALIDATOR_APP_CALL]=I,b=e.assignGroupID(y),(T=[])[on.FUNDING_TXN]={txn:b[on.FUNDING_TXN],signers:[u]},T[on.VALIDATOR_APP_CALL]={txn:b[on.VALIDATOR_APP_CALL],signers:[A]},t.abrupt("return",T);case 26:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function gn(e){return function(e,t){var n=bt(e).schema,r=n.numLocalInts,a=n.numLocalByteSlices,s=S+D+D+O+C*r+B*a;return t||(s+=D),s}(U.V2,e)+An(e)+D}function An(t){return((t?un.ASA_ALGO:un.ASA_ASA)+1)*e.ALGORAND_MIN_TX_FEE}function xn(){return(xn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x;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=$(i,u),f=v(d,2),m=f[0],h=f[1],g=yt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),A=[],x=r.map((function(t,n){if(n===on.FUNDING_TXN)return A.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return A.push(a),s})),t.abrupt("return",{signedTxns:x,txnIDs:A});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function In(){return(In=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,cn(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(Lt.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",Kt.v2.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 21:throw e.prev=21,e.t3=e.catch(1),new J(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 vn,wn={generateTxns:function(e){return hn.apply(this,arguments)},signTxns:function(e){return xn.apply(this,arguments)},execute:function(e){return In.apply(this,arguments)},getBootstrapFundingTxnAmount:gn,getTotalCost:function(t){return e.ALGORAND_MIN_TX_FEE+gn(t)}};var yn,bn,Tn,kn,_n=(l(vn={},U.V1_1,sn),l(vn,U.V2,wn),l(vn,"generateTxns",(function(e){return e.contractVersion===U.V1_1?sn.generateTxns(e):wn.generateTxns(e)})),l(vn,"signTxns",(function(e){return e.contractVersion===U.V1_1?sn.signTxns(e):wn.signTxns(e)})),l(vn,"execute",(function(e){return e.contractVersion===U.V1_1?sn.execute(e):wn.execute(e)})),l(vn,"calculateBootstrapFundingTxnAmount",(function(e){var t=e.contractVersion,n=e.isAlgoPool;return t===U.V1_1?sn.getBootstrapFundingTxnAmount(n):wn.getBootstrapFundingTxnAmount(n)})),vn),En=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}({}),Pn=5*e.ALGORAND_MIN_TX_FEE,Sn=function(e){return e.SINGLE="single",e.FLEXIBLE="flexible",e.INITIAL="initial",e}({}),Dn=(l(yn={},Sn.FLEXIBLE,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),l(yn,Sn.SINGLE,{ASSET_IN_TXN:0,VALIDATOR_APP_CALL_TXN:1}),l(yn,Sn.INITIAL,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),yn),On=(l(bn={},Sn.INITIAL,1),l(bn,Sn.SINGLE,2),l(bn,Sn.FLEXIBLE,2),bn),Nn=(l(Tn={},Sn.INITIAL,3),l(Tn,Sn.FLEXIBLE,3),l(Tn,Sn.SINGLE,2),Tn);function Ln(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,A=BigInt(i.amount)-h;if(g>A){var x=g;r=Cn(x,s),t={id:o.id,amount:x+r,decimals:o.decimals,reserves:a.asset1},n={id:i.id,amount:BigInt(Math.abs(Math.min(Number(A),0))),decimals:i.decimals,reserves:a.asset2},f-=r*d/(c*BigInt(2))}else{var I=A;r=Cn(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:ut({inputSupply:t.reserves,outputSupply:n.reserves,assetIn:t,assetOut:n})}}}function Bn(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))-Bt)))}function Cn(e,t){return e*BigInt(t)/(BigInt(1e4)-BigInt(t))}function Fn(t){return(On[t]+1)*e.ALGORAND_MIN_TX_FEE}var Rn=ye("add_liquidity"),Mn=(l(kn={},U.V1_1,[ye("mint")]),l(kn,U.V2,{INITIAL_LIQUIDITY:[ye("add_initial_liquidity")],SINGLE_ASSET_MODE:[Rn,ye("single")],FLEXIBLE_MODE:[Rn,ye("flexible")]}),kn);function Un(){return(Un=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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=de("negative",p,c.amount),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:_e(a,U.V1_1),appArgs:Mn.v1_1,accounts:[l],note:Te.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}),A=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:l,assetIndex:c.id,amount:d,suggestedParams:f}),x=e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:m.fee+A.fee,note:P,suggestedParams:f}),I=e.assignGroupID([x,m,h,g,A]),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 jn(){return(jn=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===En.FEE_TXN?p:n===En.ASSET1_IN_TXN?l:n===En.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 Vn(){return(Vn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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[En.LIQUDITY_OUT_TXN].txn.amount),e.next=5,Pt({client:n,pool:r,accountAddr:i});case 5:return c=e.sent,e.next=8,Ae(n,[o]);case 8:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,h=Ie(a),g=ve(a),e.next=17,Pt({client:n,pool:r,accountAddr:i});case 17:return A=e.sent,(x=A.excessPoolTokens-c.excessPoolTokens)<0n&&(x=0n),e.abrupt("return",{round:f,fees:h,poolTokenID:r.poolTokenID,poolTokenOut:u+x,excessAmount:{excessAmountForAddingLiquidity:x,totalExcessAmount:A.excessPoolTokens},txnID:m,groupID:g});case 23:throw e.prev=23,e.t0=e.catch(1),"SlippageTolerance"===(I=new J(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 Xn=Object.freeze({__proto__:null,execute:function(e){return Vn.apply(this,arguments)},generateTxns:function(e){return Un.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(F))throw new Error("Initial liquidity amount is too small. The amount must be greater than ".concat(F,", 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(F),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(st(Number(t)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{assetInID:i,assetInAmount:l,assetOutID:c,assetOutAmount:m,swapFee:Number(h),rate:fe(p,Number(m))/fe(u,Number(l)),priceImpact:g}}function hr(e){var t=e.amount,n=e.assetIn,r=e.assetOut,a=e.pool;if(!a||!Kt.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=ut({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(st(Number(m)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{type:tt.Direct,data:{pool:a,quote:{assetInID:i,assetInAmount:m,assetOutID:c,assetOutAmount:l,swapFee:Number(h),rate:fe(p,Number(l))/fe(u,Number(m)),priceImpact:g}}}}function gr(e){return Ar.apply(this,arguments)}function Ar(){return(Ar=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=mr({amount:n,assetIn:r,assetOut:a,pool:u});e({type:tt.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(Ze({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ne.FixedInput,network:i}).then((function(e){return{type:tt.Router,data:e}}))),e.next=6,fr(c);case 6:return p=e.sent,e.abrupt("return",ft(p));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function xr(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=[new Promise((function(e,t){try{e(hr({amount:n,assetIn:r,assetOut:a,pool:u}))}catch(e){t(e)}}))],o&&c.push(Ze({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ne.FixedOutput,network:i}).then((function(e){return{type:tt.Router,data:e}}))),e.next=5,fr(c);case 5:return p=e.sent,e.abrupt("return",ft(p));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function vr(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:ut({inputSupply:t,outputSupply:n,assetIn:{amount:r,decimals:s.assetIn},assetOut:{amount:i,decimals:s.assetOut}})}}var wr={getQuote:function(e){return dr.apply(this,arguments)},getFixedInputSwapQuote:gr,getFixedInputDirectSwapQuote:mr,getFixedOutputDirectSwapQuote:hr,getFixedOutputSwapQuote:xr,generateTxns:function(e){return pr.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return lr.apply(this,arguments)},calculateFixedInputSwap:vr};function yr(e,t){var n,r,a=BigInt(e),s=t.issuedLiquidity;return s>a+BigInt(Bt)?(n=a*t.asset1/s,r=a*t.asset2/s):(n=t.asset1,r=t.asset2),{asset1OutputAmount:n,asset2OutputAmount:r}}function br(){return(br=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A;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:Te.getAppCallTxnNoteWithClientName(U.V2),appArgs:[ar,e.encodeUint64(de("negative",p,u)),e.encodeUint64(de("negative",p,c))],accounts:[d],foreignAssets:[a.asset1ID,a.asset2ID],suggestedParams:l})).fee=(rr+1)*e.ALGORAND_MIN_TX_FEE,(g=[])[sr.ASSET_TRANSFER_TXN]=m,g[sr.APP_CALL_TXN]=h,A=e.assignGroupID(g),t.abrupt("return",[{txn:A[sr.ASSET_TRANSFER_TXN],signers:[i]},{txn:A[sr.APP_CALL_TXN],signers:[i]}]);case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Tr(){return(Tr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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,A=0,x=de("negative",p,c),u!==d){t.next=17;break}g=x,A=0,t.next=23;break;case 17:if(u!==f){t.next=22;break}g=0,A=x,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:Te.getAppCallTxnNoteWithClientName(U.V2),appArgs:[ar,e.encodeUint64(g),e.encodeUint64(A)],accounts:[m],foreignAssets:[u],suggestedParams:l})).fee=(rr+1)*e.ALGORAND_MIN_TX_FEE,(w=[])[sr.ASSET_TRANSFER_TXN]=I,w[sr.APP_CALL_TXN]=v,y=e.assignGroupID(w),t.abrupt("return",[{txn:y[sr.ASSET_TRANSFER_TXN],signers:[o]},{txn:y[sr.APP_CALL_TXN],signers:[o]}]);case 31:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function kr(){return(kr=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,Ae(n,[a]);case 3:return o=e.sent,i=v(o,1),u=i[0].txnID,e.prev=6,e.next=9,fn(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 _r,Er={getQuote:function(e){var t=e.pool,n=e.reserves,r=e.poolTokenIn,a=BigInt(r),s=yr(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=yr(i,r),c=u.asset1OutputAmount,p=u.asset2OutputAmount,l=n.totalFeeShare;if(s===n.asset1ID){var d=wr.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=wr.calculateFixedInputSwap({inputSupply:r.asset1-c,outputSupply:r.asset2-p,swapInputAmount:c,totalFeeShare:l,decimals:o}),A=g.swapOutputAmount,x=g.totalFeeAmount,I=g.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:p+A},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:A},swapFees:{assetId:n.asset2ID,amount:x},priceImpact:I}}}return t},generateTxns:function(e){return br.apply(this,arguments)},generateSingleAssetOutTxns:function(e){return Tr.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return kr.apply(this,arguments)}},Pr=(l(_r={},U.V1_1,cr),l(_r,U.V2,Er),_r),Sr=3n,Dr=1000n,Or=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}(Or||{});function Nr(){return(Nr=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===Or.FEE_TXN_INDEX?c:n===Or.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 Lr(){return(Lr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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 J({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=[ye("swap"),o===Ne.FixedInput?ye("fi"):ye("fo")],A=e.makeApplicationNoOpTxnFromObject({from:f,appIndex:c.validatorAppID,appArgs:g,accounts:[u],note:Te.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:c.asset2ID==j?[c.asset1ID,c.poolTokenID]:[c.asset1ID,c.asset2ID,c.poolTokenID],suggestedParams:h}),x=o===Ne.FixedOutput?de("positive",i,p.assetInAmount):p.assetInAmount,I=l===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:x,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:u,to:f,assetIndex:l,amount:x,suggestedParams:h}),v=o===Ne.FixedInput?de("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:A.fee+w.fee,note:P,suggestedParams:h}),b=e.assignGroupID([y,A,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 Br(e){var t=e.pool,n=e.reserves,r=e.assetIn,s=e.decimals;if(t.status!==Nt.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*Sr/Dr,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:it(d),priceImpact:ut(a({inputSupply:i,outputSupply:u},d))};return{type:tt.Direct,data:{pool:t,quote:f}}}function Cr(e){return Fr.apply(this,arguments)}function Fr(){return(Fr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,A,x;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,Pt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ae(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Pt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,i.id===r.asset1ID?(g=c.excessAsset1,A=h.excessAsset1):(g=c.excessAsset2,A=h.excessAsset2),(x=A-g)<0n&&(x=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount),assetOutID:i.id,assetOutAmount:BigInt(i.amount)+x,excessAmount:{assetID:i.id,excessAmountForSwap:x,totalExcessAmount:A},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Rr(e){var t=e.pool,n=e.reserves,r=e.assetOut,a=e.decimals;if(t.status!==Nt.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*Dr/(Dr-Sr),l=p-c,d=fe(a.assetOut,Number(u))/fe(a.assetIn,Number(p)),f=fe(a.assetOut,Number(i))/fe(a.assetIn,Number(o)),m=me({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:tt.Direct,data:{pool:t,quote:h}}}function Mr(e){return Ur.apply(this,arguments)}function Ur(){return(Ur=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,A,x;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,Pt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ae(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Pt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,o.id===r.asset1ID?(g=c.excessAsset1,A=h.excessAsset1):(g=c.excessAsset2,A=h.excessAsset2),(x=A-g)<0n&&(x=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount)-x,assetOutID:i.id,assetOutAmount:BigInt(i.amount),excessAmount:{assetID:o.id,excessAmountForSwap:x,totalExcessAmount:A},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function jr(){return(jr=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===Nt.READY){e.next=3;break}throw new J({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[Or.ASSET_IN_TXN_INDEX].txn.assetIndex||j,amount:i[Or.ASSET_IN_TXN_INDEX].txn.amount},l={id:i[Or.ASSET_OUT_TXN_INDEX].txn.assetIndex||j,amount:i[Or.ASSET_OUT_TXN_INDEX].txn.amount},o!==Ne.FixedInput){e.next=12;break}return e.next=9,Cr({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,Mr({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:ve(i),fees:Ie(i)}));case 18:throw e.prev=18,e.t0=e.catch(3),"SlippageTolerance"===(f=new J(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 Vr,Xr={getQuote:function(e,t,n,r,a){return e===Ne.FixedInput?Br({pool:t,reserves:n,assetIn:r,decimals:a}):Rr({pool:t,reserves:n,assetOut:r,decimals:a})},getFixedInputSwapQuote:Br,getFixedOutputSwapQuote:Rr,generateTxns:function(e){return Lr.apply(this,arguments)},signTxns:function(e){return Nr.apply(this,arguments)},execute:function(e){return jr.apply(this,arguments)},executeFixedOutputSwap:Mr};function Gr(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(mt(n)&&!mt(r))throw n;throw r}return e.filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value}))}))}function qr(){return(qr=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(Xr.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(wr.getFixedInputSwapQuote({amount:r,assetIn:{id:ee(a),decimals:a.decimals},assetOut:{id:ee(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,Gr(c);case 8:return d=e.sent,e.abrupt("return",ft(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Qr(){return(Qr=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(Xr.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(wr.getFixedOutputSwapQuote({amount:r,assetIn:{id:ee(a),decimals:a.decimals},assetOut:{id:ee(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,Gr(c);case 8:return d=e.sent,e.abrupt("return",ft(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Wr=(l(Vr={},U.V1_1,Xr),l(Vr,U.V2,wr),l(Vr,"getQuote",(function(e){var t=e.type;if(t===Ne.FixedInput)return function(e){return qr.apply(this,arguments)}(e);if(t===Ne.FixedOutput)return function(e){return Qr.apply(this,arguments)}(e);throw new E(_.InvalidSwapTypeError,"Invalid swap type")})),l(Vr,"generateTxns",(function(e){return e.quote.type===tt.Direct&<(e.quote)===U.V1_1?Xr.generateTxns(a(a({},e),{},{quoteAndPool:e.quote.data})):wr.generateTxns(e)})),l(Vr,"signTxns",(function(e){if(e.quote.type===tt.Direct&<(e.quote)===U.V1_1){var t=e.quote.data.pool;return Xr.signTxns(a(a({},e),{},{pool:t}))}return wr.signTxns(e)})),l(Vr,"execute",(function(e){return e.contractVersion===U.V1_1?Xr.execute(e):wr.execute(e)})),Vr);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 n=t.client,r=t.pool,a=t.txGroup,o=t.initiatorSigner,e.prev=1,e.next=4,Jr({txGroup:a,pool:r,initiatorSigner:o});case 4:return i=e.sent,e.next=7,Ae(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:Ie(a),confirmedRound:d,txnID:l,groupID:ve(a)});case 15:throw e.prev=15,e.t0=e.catch(1),new J(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 Jr(e){return Yr.apply(this,arguments)}function Yr(){return(Yr=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 Kr(){return Kr=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:Ie(t),groupID:ve(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,Ae(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 J(t.t0,"We encountered something unexpected while redeeming. Try again later.");case 13:case"end":return t.stop()}}),t,null,[[1,10]])}))),Kr.apply(this,arguments)}function Hr(){return(Hr=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:[ye("redeem")],note:Te.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 $r(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 Zr(e,t,n){return e*t/n}var ea=BigInt(31536e3),ta=BigInt(1e14),na=BigInt(1e16),ra={testnet:548587153,mainnet:1385499515},aa=14;function sa(e){return oa.apply(this,arguments)}function oa(){return(oa=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(ra[a]),t.next=4,Tt(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 ia(){return(ia=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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(ra[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],A=h[1],x=Z(A.id),I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:g.id,amount:g.amount,suggestedParams:f}),y=x?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:A.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:A.id,amount:A.amount,suggestedParams:f}),(b=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:ra[a],appArgs:[ye("add_liquidity"),e.decodeAddress(o).publicKey,e.encodeUint64(g.lendingAppId),e.encodeUint64(A.lendingAppId)],foreignAssets:[g.id,A.id,g.fAssetId,A.fAssetId],foreignApps:[g.lendingAppId,A.lendingAppId,u],accounts:[o],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(aa+1),T=_e(a,U.V2),k=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:ra[a],appArgs:[ye("noop")],foreignAssets:[i],foreignApps:[T],accounts:[o],suggestedParams:f}),_=[I,y,b,k],t.next=16,sa({client:r,network:a,assetIDs:[g.id,A.id,g.fAssetId,A.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:ra[a],appArgs:[ye("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 ua(){return(ua=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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(ra[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}),(A=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:ra[l],appArgs:[ye("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*(aa+1),x=_e(l,U.V2),I=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:ra[l],appArgs:[ye("noop")],accounts:[m],foreignAssets:[h,u.fAssetId,c.fAssetId],foreignApps:[x],suggestedParams:f}),v=e.assignGroupID([g,A,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 ca(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 Zr(e,na+t*r/ea,na)}function pa(){return(pa=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=$r(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 la={AddLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return ia.apply(this,arguments)},getAddLiquidityTotalFee:function(t){return e.ALGORAND_MIN_TX_FEE*(4+aa)+(t?(t+1)*e.ALGORAND_MIN_TX_FEE+t*D:0)}}),RemoveLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return ua.apply(this,arguments)},getRemoveLiquidityTotalFee:function(){return e.ALGORAND_MIN_TX_FEE*(3+aa)}}),calculateWithdrawReturn:function(e){var t=e.withdrawAmount,n=ca(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return Zr(BigInt(t),n,ta)},calculateDepositReturn:function(e){var t=e.depositAmount,n=ca(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return BigInt(t)*ta/n},getFolksWrapperAppOptInRequiredAssetIDs:sa};function da(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:[ye("commit"),u],note:ne([ye("tinymanStaking/v1:b"),c,e.encodeUint64(s),u])})}function fa(){return(fa=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=da({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:[ye("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)}function ma(e){if(e instanceof Uint8Array&&"Uint8Array"===e.constructor.name)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}var ha=function(e,t){if(e.length>=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);mma(a(e))})}function Ta({name:e,prefix:t,bitsPerChar:n,alphabet:r}){return ya({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 ka=Ta({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5});Ta({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ta({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ta({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ta({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ta({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ta({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ta({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ta({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});const _a=ba({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"});ba({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ea=function e(t,n,r){n=n||[];var a=r=r||0;for(;t>=Da;)n[r++]=255&t|Pa,t/=128;for(;t&Sa;)n[r++]=255&t|Pa,t>>>=7;return n[r]=0|t,e.bytes=r-a+1,n},Pa=128,Sa=-128,Da=Math.pow(2,31);var Oa=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&La)<=Na);return e.bytes=o-n,a},Na=128,La=127;var Ba=Math.pow(2,7),Ca=Math.pow(2,14),Fa=Math.pow(2,21),Ra=Math.pow(2,28),Ma=Math.pow(2,35),Ua=Math.pow(2,42),ja=Math.pow(2,49),Va=Math.pow(2,56),Xa=Math.pow(2,63),Ga={encode:Ea,decode:Oa,encodingLength:function(e){return e{const[n,r]=qa(e.subarray(t));return t+=r,n};let r=n(),a=Za;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??_a;return[_a.prefix,n.decode(`${_a.prefix}${e}`)]}case _a.prefix:{const n=t??_a;return[_a.prefix,n.decode(e)]}case ka.prefix:{const n=t??ka;return[ka.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=$a.decode(r);if(0===a.version&&"Q"!==e[0])throw Error("Version 0 CID string must not include multibase prefix");return Ha(a).set(n,e),a}}const Za=112,es=18;function ts(e,t,n){const r=Wa(e),a=r+Wa(t),s=new Uint8Array(a+n.byteLength);return Qa(e,s,0),Qa(t,s,r),s.set(n,a),s}const ns=Symbol.for("@ipld/js-cid/CID");class rs{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?za(this.code,t):t.then((e=>za(this.code,e)))}throw Error("Unknown type, must be binary type")}}const as=function({name:e,code:t,encode:n}){return new rs(e,t,n)}({name:"sha2-256",code:18,encode:e=>ma(n.createHash("sha256").update(e).digest())}),ss=85;var os=604800,is={testnet:480164661,mainnet:2200606875},us={testnet:360907790,mainnet:2200609638},cs={testnet:336189106,mainnet:2200608153},ps={testnet:383416252,mainnet:2200608887},ls=2500,ds=400,fs=604800,ms=126144e3,hs=1e7,gs=Math.pow(2,64),As=48,xs=21,Is=48,vs=ye("tp"),ws=ye("sc"),ys=28100,bs=12900,Ts=421700,ks=409700;function _s(e){var t=e/fs;return(arguments.length>1&&void 0!==arguments[1]&&arguments[1]?Math.floor(t):Math.ceil(t))*fs}function Es(e,t){if(e>t)throw new Error("Old timestamp must be less than or equal to new timestamp");for(var n=[],r=_s(e)+fs;re?r=t?e*e*gs/(2*t):0:r=(e+(e-r))*n/2;return r}function Bs(e,t){return Cs.apply(this,arguments)}function Cs(){return(Cs=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",Fs(r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Fs(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 Rs(){for(var e=arguments.length,t=new Array(e),n=0;n1&&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 Gs(e,t){return 0===Buffer.compare(e,t)}function qs(e){for(var t=0n,n=0;n0?xs-e:0}},{key:"lastAccountPowerBoxIndex",get:function(){return eo(this.powerCount)[0]}},{key:"lastAccountPowerArrayIndex",get:function(){return eo(this.powerCount)[1]}}]),e}(),Ws=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+Ls(this.bias,this.slope,t)}}]),e}(),zs=p((function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a})),Js=p((function e(t){u(this,e),this.slopeDelta=t})),Ys=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%xs;return e>0?xs-e:0}},{key:"lastTotalPowerBoxIndex",get:function(){return eo(this.totalPowerCount)[0]}},{key:"lastTotalPowerArrayIndex",get:function(){return eo(this.totalPowerCount)[1]}}]),e}();function Ks(){return(Ks=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=$s(r),e.prev=1,e.next=4,Ps(t,n,a);case 4:if(!(o=e.sent)){e.next=7;break}return e.abrupt("return",Hs(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 Hs(e){var t=Buffer.from(e);return new Qs(t.readUIntBE(0,8),t.readUIntBE(8,8),t.readUIntBE(16,8),t.readUIntBE(24,8))}function $s(t){return e.decodeAddress(t).publicKey}function Zs(e){var t=Xs(e),n=new Uint8Array(vs.length+t.length);return n.set(vs,0),n.set(t,vs.length),n}function eo(e){var t=e-1;return[Math.floor(t/xs),t%xs]}function to(t,n){var r=e.decodeAddress(t).publicKey,a=Xs(n),s=new Uint8Array(r.length+a.length);return s.set(r,0),s.set(a,r.length),s}function no(e,t,n){return ro.apply(this,arguments)}function ro(){return(ro=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=so(r),e.next=3,Ps(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",ao(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ao(t){return new Js(Number(e.bytesToBigInt(t.slice(t.length-16,t.length))))}function so(e){return Rs(ws,Xs(e))}function oo(e,t,n,r){return io.apply(this,arguments)}function io(){return(io=i(s().mark((function e(t,n,r,a){var o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=0,r&&(o=Math.ceil(r/xs)),i=[],u=0;case 4:if(!(u4?d[4]:void 0,i=0,(a=d.length>3&&void 0!==d[3]?d[3]:null)&&(i=Math.ceil(a/xs)),u=[],c=0;case 6:if(!(c=e[r].timestamp))break;n=r}return n}function fo(e){for(var t,n=As,r=[],a=0;ai.freeTotalPowerSpaceCount&&(b+=ks),c||(b+=bs);var k=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({amount:a,assetIndex:G[s],from:o,suggestedParams:u,to:e.getApplicationAddress(l)}),e.makeApplicationNoOpTxnFromObject({appIndex:l,from:o,suggestedParams:u,appArgs:[ye("create_lock"),Xs(r)],boxes:d.slice(0,8),note:p}),wo({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 bo(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+=ks),!n.freeAccountPowerSpaceCount){var w=to(s,n.lastAccountPowerBoxIndex+1);h.push({appIndex:is[a],name:w}),v+=Ts}var y=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:G[a],from:s,to:e.getApplicationAddress(is[a]),amount:r,suggestedParams:i}),e.makeApplicationNoOpTxnFromObject({appIndex:is[a],from:s,suggestedParams:i,appArgs:[ye("increase_lock_amount")],boxes:h,note:u}),wo({sender:s,suggestedParams:i,index:is[a]})];if(v){var b=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,suggestedParams:i,to:e.getApplicationAddress(is[a]),amount:v});y.unshift(b)}return e.assignGroupID(y)}function To(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%fs)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=$s(o),l=to(o,n.lastAccountPowerBoxIndex),d=Zs(i.lastTotalPowerBoxIndex),f=Zs(i.lastTotalPowerBoxIndex+1),m=so(n.lockEndTime),h=so(a),g=[{appIndex:is[r],name:p},{appIndex:is[r],name:l},{appIndex:is[r],name:d},{appIndex:is[r],name:f},{appIndex:is[r],name:m},{appIndex:is[r],name:h}];if(!n.freeAccountPowerSpaceCount){var A=to(o,n.lastAccountPowerBoxIndex+1);g.push({appIndex:is[r],name:A})}var x,I=Es(i.lastTotalPowerTimestamp,Math.floor(Date.now()/1e3)),v=I.length,w=T(I);try{for(w.s();!(x=w.n()).done;){var y=x.value;if(y%fs==0){var b=so(y);g.push({appIndex:is[r],name:b})}}}catch(e){w.e(e)}finally{w.f()}var k=0;s||(k+=bs),n.freeAccountPowerSpaceCount||(k+=Ts),v>i.freeTotalPowerSpaceCount&&(k+=ks);var _=[e.makeApplicationNoOpTxnFromObject({appIndex:is[r],from:o,suggestedParams:u,appArgs:[ye("extend_lock_end_time"),Xs(a)],boxes:g.slice(0,8),note:c}),wo({sender:o,suggestedParams:u,index:is[r],boxes:g.slice(8)})];if(k){var E=e.makePaymentTxnWithSuggestedParamsFromObject({from:o,suggestedParams:u,to:e.getApplicationAddress(is[r]),amount:k});_.unshift(E)}return e.assignGroupID(_)}function ko(t){var n=t.accountState,r=t.network,a=t.sender,s=t.suggestedParams,o=t.appCallNote,i=$s(a),u=to(a,n.lastAccountPowerBoxIndex),c=to(a,n.lastAccountPowerBoxIndex+1),p=[{appIndex:is[r],name:i},{appIndex:is[r],name:u},{appIndex:is[r],name:c}],l=e.makeApplicationNoOpTxnFromObject({appIndex:is[r],from:a,suggestedParams:s,appArgs:[ye("withdraw")],foreignAssets:[G[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(is[r]),amount:Ts});d.unshift(f)}return e.assignGroupID(d)}var _o=8,Eo=ye("p"),Po=ye("a"),So=ye("v"),Do=28500,Oo=12500,No=ye("p"),Lo=ye("a"),Bo=24,Co=111300,Fo=ls+ds*(41+Bo),Ro=function(e){return e[e.Against=0]="Against",e[e.For=1]="For",e[e.Abstain=2]="Abstain",e}(Ro||{}),Mo=new Uint8Array(34),Uo="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ",jo=function(){function e(t,n,r,a,s,o,i,c,p,l,d,f,m,h,g,A,x){u(this,e),this.index=t,this.creationTimestamp=n,this.votingStartTimestamp=r,this.votingEndTimestamp=a,this.snapshotTotalVotingPower=s,this.voteCount=o,this.quorumNumerator=i,this.againstVotingPower=c,this.forVotingPower=p,this.abstainVotingPower=l,this.isApproved=d,this.isCancelled=f,this.isExecuted=m,this.isQuorumReached=h,this.proposerAddress=g,this.executionHash=A,this.executorAddress=x}return p(e,[{key:"snapshotTimestamp",get:function(){return this.creationTimestamp}}]),e}(),Vo=p((function e(t,n,r,a,s,o,i,c,p,l){u(this,e),this.vaultAppId=t,this.proposalIndexCounter=n,this.votingDelay=r,this.votingDuration=a,this.proposalThreshold=s,this.proposalThresholdNumerator=o,this.quorumThreshold=i,this.approvalRequirement=c,this.manager=p,this.proposalManager=l}));function Xo(e){return Rs(No,ye(e))}function Go(t){var n=Buffer.from(t);return new jo(n.readUIntBE(0,8),n.readUIntBE(8,8),n.readUIntBE(16,8),n.readUIntBE(24,8),n.readUIntBE(32,8),n.readUIntBE(40,8),n.readUIntBE(48,8),n.readUIntBE(56,8),n.readUIntBE(64,8),n.readUIntBE(72,8),Boolean(n.readUIntBE(80,1)),Boolean(n.readUIntBE(81,1)),Boolean(n.readUIntBE(82,1)),Boolean(n.readUIntBE(83,1)),e.encodeAddress(n.subarray(84,116)),t.slice(116,150).toString(),e.encodeAddress(n.subarray(150,182)))}function qo(){return(qo=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=Xo(r),e.next=3,Ps(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",Go(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Qo=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 Wo(t,n){return Rs(Po,e.decodeAddress(t).publicKey,Xs(n))}function zo(e){return new Qo(qs(e.slice(0,8)),qs(e.slice(8,16)),qs(e.slice(16,24)),qs(e.slice(24,32)),qs(e.slice(32,40)),qs(e.slice(40,48)),Boolean(qs(e.slice(48,49))))}function Jo(){return(Jo=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=Xo(r),e.next=3,Ps(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",zo(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Yo(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>_o)throw new Error("You cannot cast vote for more than ".concat(_o," 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=Rs.apply(void 0,w(i.map((function(e){return Xs(e)})))),g=Rs.apply(void 0,w(u.map((function(e){return Xs(e)})))),A=function(e){return Rs(Eo,ye(e))}(s),x=Wo(a,Math.floor(o.index/8192)),I=!p.some((function(e){return Gs(e,x)})),v=$s(a),y=Math.floor(c/xs),b=to(a,y),k=to(a,y+1),_=0,E=[],P=T(u);try{var S=function(){var e=m.value,t=function(e,t){return Rs(So,Xs(e),Xs(t))}(o.index,e);E.push({appIndex:n,name:t}),p.some((function(e){return Gs(e,t)}))||(_+=1)};for(P.s();!(m=P.n()).done;)S()}catch(e){P.e(e)}finally{P.f()}var D=[{appIndex:n,name:A},{appIndex:n,name:x}].concat(E,[{appIndex:r,name:v},{appIndex:r,name:b},{appIndex:r,name:k}]),O=[e.makeApplicationNoOpTxnFromObject({from:a,suggestedParams:l,appIndex:n,appArgs:[ye("cast_vote"),ye(s),h,g,Xs(c)],foreignApps:[r],boxes:D.slice(0,7),note:f?ye(f):void 0})];O[0].fee*=2,D.length>=7&&O.push(wo({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(7,14)})),D.length>=14&&O.push(wo({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(14)}));var N=Number(I)*Do+_*Oo;return N&&(O=[e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:l,to:e.getApplicationAddress(n),amount:N})].concat(w(O))),e.assignGroupID(O)}var Ko=ye("rp"),Ho=1012,$o=ye("c"),Zo=42,ei=ls+ds*(41+Ho),ti=p((function e(t,n,r,a,s,o,i){u(this,e),this.tinyAssetId=t,this.vaultAppId=n,this.rewardHistoryCount=r,this.firstPeriodTimestamp=a,this.rewardPeriodCount=s,this.manager=o,this.rewardsManager=i})),ni=p((function e(t){u(this,e),this.value=t}));function ri(t,n){var r=e.decodeAddress(t).publicKey,a=Xs(n),s=new Uint8Array($o.length+r.length+a.length);return s.set($o,0),s.set(r,$o.length),s.set(a,$o.length+r.length),s}function ai(e,t,n,r){return si.apply(this,arguments)}function si(){return(si=i(s().mark((function e(t,n,r,a){var o,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=ri(r,a),e.next=3,Ps(t,n,o);case 3:if(i=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",new ni(i));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function oi(t){for(var n=t.rewardsAppId,r=t.vaultAppId,a=t.tinyAssetId,s=t.sender,o=t.periodIndexStart,i=t.periodCount,u=t.accountPowerIndexes,c=t.suggestedParams,p=t.createRewardClaimSheet,l=t.appCallNote,d=[],f=[],m=[],h=[],g=function(){var e,t,r=Math.floor(A/Zo),a=(e=Xs(r),(t=new Uint8Array(Ko.length+e.length)).set(Ko,0),t.set(e,Ko.length),t);f.find((function(e){return e.name.toString()===a.toString()}))||f.push({appIndex:n,name:a});var o=Math.floor(A/(8*Ho)),i=ri(s,o);m.find((function(e){return e.name.toString()===i.toString()}))||m.push({appIndex:n,name:i})},A=o;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:[ye("claim_rewards"),Xs(o),Xs(i),Rs.apply(void 0,w(u.map((function(e){return Xs(e)}))))],foreignApps:[r],foreignAssets:[a],boxes:y,note:l?ye(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=wo({sender:s,suggestedParams:c,extraAppArgs:[Xs(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:ei,suggestedParams:c});b.unshift(D)}return e.assignGroupID(b)}function ii(t){var n=t.proposalId,r=t.proposalVotingAppId,a=t.sender,s=t.vaultAppId,o=t.vaultAppGlobalState,i=t.executionHash,u=t.executor,c=t.suggestedParams,p=t.appCallNote,l=Xo(n),d=$s(a),f=Zs(o.lastTotalPowerBoxIndex),m=[e.makePaymentTxnWithSuggestedParamsFromObject({from:a,to:e.getApplicationAddress(r),amount:Co,suggestedParams:c}),e.makeApplicationNoOpTxnFromObject({from:a,suggestedParams:c,appIndex:r,appArgs:[ye("create_proposal"),ye(n),i?ye(i):Mo,null!=u?u:e.decodeAddress(Uo).publicKey],foreignApps:[s],boxes:[{appIndex:r,name:l},{appIndex:s,name:d},{appIndex:s,name:f}],note:p?ye(p):void 0})];return m[1].fee*=3,e.assignGroupID(m)}function ui(t){var n=t.accountPowerIndex,r=t.createAttendanceSheetBox,a=t.proposal,s=t.proposalId,o=t.proposalVotingAppId,i=t.sender,u=t.suggestedParams,c=t.vaultAppId,p=t.vote,l=t.appCallNote;if(![Ro.Abstain,Ro.Against,Ro.For].includes(p))throw new Error("Invalid vote");var d,f,m=Math.floor(n/xs),h=Math.floor(a.index/(8*Bo)),g=[{appIndex:o,name:Xo(s)},{appIndex:o,name:(d=i,f=h,Rs(Lo,e.decodeAddress(d).publicKey,Xs(f)))},{appIndex:c,name:$s(i)},{appIndex:c,name:to(i,m)},{appIndex:c,name:to(i,m+1)}],A=[e.makeApplicationNoOpTxnFromObject({from:i,suggestedParams:u,appIndex:o,appArgs:[ye("cast_vote"),ye(s),Xs(p),Xs(n)],foreignApps:[c],boxes:g,note:l?ye(l):void 0})];if(A[0].fee*=2,r){var x=e.makePaymentTxnWithSuggestedParamsFromObject({from:i,suggestedParams:u,to:e.getApplicationAddress(o),amount:Fo});A.unshift(x)}return e.assignGroupID(A)}var ci=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,A,x,I,v,y;return p(t,[{key:"getTinyPower",value:(y=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()/1e3),n=p.length>1?p[1]:void 0,e.next=4,this.fetchAccountState();case 4:if(r=e.sent){e.next=7;break}return e.abrupt("return",0);case 7:return e.next=9,co(this.algodClient,this.userAddress,is[this.network],r.powerCount,n);case 9:if(a=e.sent,null!==(o=lo(a,t))){e.next=13;break}return e.abrupt("return",0);case 13:return i=a[o],u=t-i.timestamp,c=Math.max(i.bias-Ns(i.slope,u),0),e.abrupt("return",c);case 17: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,A,x,I,v,w=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=w.length>0&&void 0!==w[0]?w[0]:Math.floor(Date.now()/1e3),n=w.length>1?w[1]:void 0,e.next=4,this.fetchVaultAppGlobalState();case 4:if(r=e.sent){e.next=7;break}return e.abrupt("return",0);case 7:return e.next=9,oo(this.algodClient,is[this.network],r.totalPowerCount,n);case 9:if(a=e.sent,o=lo(a,t)){e.next=13;break}return e.abrupt("return",0);case 13:i=a[o],u=Math.floor(i.timestamp/fs),c=Math.floor(t/fs)-u,p=Array.from({length:c},(function(e,t){return(u+t)*fs})),l=p.map((function(e,t){return[0===t?i.timestamp:p[t-1],e]})),d=i.slope,f=i.bias,m=T(l),e.prev=20,m.s();case 22:if((h=m.n()).done){e.next=35;break}return g=h.value,A=g[1]-g[0],x=Ns(d,A),f=Math.max(f-x,0),e.next=29,no(this.algodClient,is[this.network],g[1]);case 29:I=e.sent,v=(null==I?void 0:I.slopeDelta)||0,d=Math.max(d-v,0),0!==f&&0!==d||(f=0,d=0);case 33:e.next=22;break;case 35:e.next=40;break;case 37:e.prev=37,e.t0=e.catch(20),m.e(e.t0);case 40:return e.prev=40,m.f(),e.finish(40);case 43:return e.abrupt("return",f);case 44:case"end":return e.stop()}}),e,this,[[20,37,40,43]])}))),function(){return v.apply(this,arguments)})},{key:"getCumulativeTinyPower",value:(I=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=l.length>1&&void 0!==l[1]?l[1]:Math.floor(Date.now()/1e3),e.next=3,this.fetchAccountState();case 3:if(r=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,co(this.algodClient,this.userAddress,is[this.network],r.powerCount,t);case 8:if(a=e.sent,null!==(o=lo(a,n))){e.next=12;break}return e.abrupt("return",0);case 12:return i=a[o],u=n-i.timestamp,c=Ls(i.bias,i.slope,u),p=i.cumulativePower-c,e.abrupt("return",p);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return I.apply(this,arguments)})},{key:"fetchVaultAppGlobalState",value:(x=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,Bs(this.algodClient,is[this.network]);case 3:return t=e.sent,e.abrupt("return",new Ys(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 x.apply(this,arguments)})},{key:"generateCreateLockTransactions",value:(A=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,no(this.algodClient,is[this.network],r);case 17:return l=e.sent,e.abrupt("return",yo({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 A.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",bo({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,no(this.algodClient,is[this.network],n);case 19:return p=e.sent,e.abrupt("return",To({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=bo({accountState:u,lockedAmount:n,network:this.network,sender:i,vaultAppGlobalState:c,suggestedParams:d}),u.powerCount+=1,c.totalPowerCount+=1,e.next=24,no(this.algodClient,is[this.network],r);case 24:return f=e.sent,l=To({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)?Us(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=ko({accountState:o,network:this.network,sender:a,suggestedParams:i,client:this.algodClient}),!n){e.next=17;break}return e.next=15,Y({client:this.algodClient,initiatorAddr:a,assetID:G[this.network]});case 15:c=e.sent,u=Us([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 Ks.apply(this,arguments)}(this.algodClient,is[this.network],this.userAddress)}},{key:"fetchStakingDistributionProposal",value:function(e){return function(e,t,n){return Jo.apply(this,arguments)}(this.algodClient,us[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;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.proposalId,r=t.votes,a=t.assetIds,o=t.userAddress,i=t.suggestedParams,u=null!=o?o:this.userAddress,c=i,e.next=5,this.fetchStakingDistributionProposal(n);case 5:if(p=e.sent){e.next=8;break}throw new Error("There was an error while fetching staking distribution proposal");case 8:if(c){e.next=12;break}return e.next=11,this.algodClient.getTransactionParams().do();case 11:c=e.sent;case 12:return e.next=14,this.fetchAccountState();case 14:return l=e.sent,e.next=17,js(this.algodClient,us[this.network]);case 17:return d=e.sent,e.next=20,co(this.algodClient,u,is[this.network],null==l?void 0:l.powerCount);case 20:if(f=e.sent,null!==(m=lo(f,p.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",Yo({stakingVotingAppId:us[this.network],vaultAppId:is[this.network],sender:u,proposalId:n,proposal:p,votes:r,assetIds:a,accountPowerIndex:m,appBoxNames:d,suggestedParams:c,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,Bs(this.algodClient,cs[this.network]);case 3:return n=t.sent,t.abrupt("return",new ti(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,A,x,I,v,w,y,b,T;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.periodIndexStart,r=t.periodCount,a=t.userAddress,o=t.suggestedParams,i=t.shouldOptIntoTINY,u=null!=a?a:this.userAddress,c=o){e.next=7;break}return e.next=6,this.algodClient.getTransactionParams().do();case 6:c=e.sent;case 7:return e.next=9,this.fetchAccountState();case 9:return p=e.sent,e.next=12,this.fetchRewardsAppGlobalState();case 12:if(l=e.sent){e.next=15;break}throw new Error("There was an error while fetching rewards app global state");case 15:if(!(n+r>l.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,co(this.algodClient,u,is[this.network],null==p?void 0:p.powerCount);case 19:for(d=e.sent,f=l.firstPeriodTimestamp+n*os,m=l.firstPeriodTimestamp+(n+r)*os,h=[],g=f;g=Math.floor(Date.now()/1e3)||c.votingEndTimestamp<=Math.floor(Date.now()/1e3))){e.next=23;break}throw new Error("Voting period is not active");case 23:return e.next=25,co(this.algodClient,i,is[this.network],p.powerCount);case 25:if(l=e.sent,null!==(d=lo(l,c.creationTimestamp))){e.next=29;break}throw new Error("Account power index not found");case 29:return f=Math.floor(c.index/(8*Bo)),m=Wo(i,f),e.next=33,Ds(this.algodClient,ps[this.network],m);case 33:return h=!e.sent,e.abrupt("return",ui({proposalVotingAppId:ps[this.network],vaultAppId:is[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,Bs(this.algodClient,ps[this.network]);case 2:return t=e.sent,e.abrupt("return",new Vo(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(){var t,n,r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.fetchProposalVotingAppGlobalState();case 2:if(t=e.sent,n=t.proposalThreshold,!t.proposalThresholdNumerator){e.next=9;break}return e.next=7,this.getTotalTinyPower();case 7:r=e.sent,n=Math.max(n,Math.floor(r*t.proposalThresholdNumerator/100)+1);case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})}]),t}();exports.ALGO_ASSET=V,exports.ALGO_ASSET_ID=j,exports.ASSET_OPT_IN_PROCESS_TXN_COUNT=1,exports.AccountState=Qs,exports.AddLiquidity=er,exports.BASE_MINIMUM_BALANCE=S,exports.Bootstrap=_n,exports.CONTRACT_VERSION=U,exports.LendingPool=la,exports.MINIMUM_ADD_LIQUIDITY_AMOUNT=F,exports.MINIMUM_BALANCE_REQUIRED_PER_APP=O,exports.MINIMUM_BALANCE_REQUIRED_PER_ASSET=D,exports.MINIMUM_BALANCE_REQUIRED_PER_BYTE_SCHEMA=B,exports.MINIMUM_BALANCE_REQUIRED_PER_INT_SCHEMA_VALUE=C,exports.OPT_IN_VALIDATOR_APP_PROCESS_TXN_COUNT=1,exports.OPT_OUT_VALIDATOR_APP_PROCESS_TXN_COUNT=1,exports.POOL_TOKEN_UNIT_NAME=X,exports.PoolStatus=Nt,exports.ProposalVote=Ro,exports.REDEEM_PROCESS_TXN_COUNT=3,exports.RemoveLiquidity=Pr,exports.Swap=Wr,exports.SwapQuoteError=E,exports.SwapQuoteErrorType=_,exports.SwapQuoteType=tt,exports.SwapType=Ne,exports.TINY_ASSET_ID=G,exports.TinymanGovernanceClient=ci,exports.V1_1AddLiquidityTxnIndices=En,exports.V1_1_ADD_LIQUIDITY_PROCESS_TXN_COUNT=5,exports.V1_1_REMOVE_LIQUIDITY_TXN_COUNT=nr,exports.V2AddLiquidityTxnIndices=Dn,exports.V2AddLiquidityType=Sn,exports.V2_REMOVE_LIQUIDITY_APP_CALL_INNER_TXN_COUNT=rr,exports.applySlippageToAmount=de,exports.calculateAccountMinimumRequiredBalance=_t,exports.calculatePriceImpact=ut,exports.calculateSwapRate=it,exports.calculateTinyPower=function(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Math.floor(Date.now()/1e3),a=(n=e,Math.floor(n*gs/ms)),s=t-r;return s<0?0:Ns(a,s)},exports.combineAndRegroupSignerTxns=function(){for(var t=arguments.length,n=new Array(t),r=0;r=e.minimum_required_balance},exports.intToBytes=Xs,exports.isAccountOptedIntoApp=function(e){var t=e.appID;return e.accountAppsLocalState.some((function(e){return e.id===t}))},exports.isSwapAssetInAmountLow=st,exports.isSwapQuoteErrorCausedByAmount=mt,exports.poolUtils=Kt,exports.prepareCommitTransactions=function(e){return fa.apply(this,arguments)},exports.redeemAllExcessAsset=function(e){return Kr.apply(this,arguments)},exports.redeemExcessAsset=function(e){return zr.apply(this,arguments)},exports.sendAndWaitRawTransaction=Ae,exports.sumUpTxnFees=Ie,exports.tinymanContract_v1_1=It,exports.tinymanContract_v2=yt,exports.tinymanJSSDKConfig=Te; +"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,A(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(x(a),n),a}return p(n)}(),P=Uint8Array.from([1]),S=1e5,D=1e5,O=1e5,N=1e5,L=1e5,B=5e4,C=28500,F=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:""},X={V1:"TM1POOL",V1_1:"TMPOOL11",V2:"TMPOOL2"},G={testnet:258703304,mainnet:22e8},q="- would result negative",Q="logic eval error:",W="exceeds schema integer count",z=/transaction \w+:/,J=function(e){d(n,A(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 $(e,t){var n=[e,t];return[Math.max.apply(Math,n),Math.min.apply(Math,n)]}function Z(e){return Number(e)===j}function ee(e){return Number(e.id)}function te(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 ne(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 re=100000n,ae=100000n,se=100000n,oe=25000n+25000n,ie=25000n+3500n;function ue(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 re+ae*BigInt(o.length)+se*BigInt(s.length+a.length)+ie*r+oe*n}function ce(e){return new Promise((function(t){setTimeout((function(){t(null)}),e)}))}function pe(e,t){return le.apply(this,arguments)}function le(){return(le=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,ce(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 de(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 fe(e,t){var n=Number(e);return me({decimalPlaces:n},Math.pow(10,-n)*Number(t))}function me(e,t){var n=e.decimalPlaces,r=void 0===n?0:n;if(r>0){var a=v(ge(t),2),s=a[0],o=a[1],i=v(ge(Math.round(Number(he(s,o+r)))),2),u=i[0],c=i[1];return Number(he(u,c-r))}return Math.round(t)}function he(e,t){return e+(t<0?"e".concat(t):"e+".concat(t))}function ge(e){if(e.toString().includes("e")){var t=e.toString().split("e");return[parseFloat(t[0]),parseFloat(t[1])]}return[e,0]}function Ae(e,t){return xe.apply(this,arguments)}function xe(){return(xe=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,pe(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 J(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 Ie(e){return e.reduce((function(e,t){return e+t.txn.fee}),0)}function ve(e){return(t=e[0].txn.group)?Buffer.from(t).toString("base64"):"";var t}function we(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 ye(e){return(new TextEncoder).encode(e)}var be,Te=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 ye("tinyman/".concat(n,":j").concat(r))}}]),e}()),ke=(l(be={},U.V1_1,{testnet:62368684,mainnet:552635992}),l(be,U.V2,{testnet:148607e3,mainnet:1002541853}),be);function _e(e,t){var n=ke[t][e];if(!n)throw new Error("No Validator App exists for ".concat(e," network with ").concat(t," contract version"));return n}function Ee(){return(Ee=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:_e(a,o),note:Te.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Pe(){return(Pe=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:_e(a,o),note:Te.getAppCallTxnNoteWithClientName(o),suggestedParams:u}),t.abrupt("return",[{txn:c,signers:[i]}]);case 6:case"end":return t.stop()}}),t)})))).apply(this,arguments)}var Se,De,Oe,Ne=function(e){return e.FixedInput="fixed-input",e.FixedOutput="fixed-output",e}({}),Le=.003,Be=function(e){return e[e.INPUT_TXN=0]="INPUT_TXN",e[e.APP_CALL_TXN=1]="APP_CALL_TXN",e}({}),Ce=(l(Se={},Ne.FixedInput,1),l(Se,Ne.FixedOutput,2),Se),Fe=2,Re=ye("swap"),Me=(l(De={},Ne.FixedInput,ye("fixed-input")),l(De,Ne.FixedOutput,ye("fixed-output")),De),Ue={ASSET_OPT_IN:ye("asset_opt_in")},je={testnet:184778019,mainnet:1083651166},Ve=(l(Oe={},Ne.FixedInput,7),l(Oe,Ne.FixedOutput,8),Oe);function Xe(e){var t=We(e),n=t.assetIn,r=t.assetOut;return fe(r.asset.decimals,Number(r.amount))/fe(n.asset.decimals,Number(n.amount))}function Ge(e){var t=je[e];if(!t)throw new Error("Unknown network or network not supported: ".concat(e));return t}function qe(e){return e[e.length-1].quote.amount_out}function Qe(e){return e[0].quote.amount_in}function We(e){return{assetIn:Qe(e),assetOut:qe(e)}}function ze(e){return Je.apply(this,arguments)}function Je(){return(Je=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:[Ue.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 Ye(e){return Ke.apply(this,arguments)}function Ke(){return(Ke=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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=[ee(u[0].quote.amount_in.asset),ee(u[0].quote.amount_out.asset),ee(u[1].quote.amount_out.asset)],d=l[0],f=l[1],m=l[2],h=[Number(Qe(u).amount),Number(qe(u).amount)],g=h[0],A=h[1],x=[u[0].pool.address,u[1].pool.address],I=x[0],v=x[1],w=i===Ne.FixedInput?g:de("positive",c,g),y=i===Ne.FixedOutput?A:de("negative",c,A),b=Z(d),T=Ge(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:[Re,Me[i],e.encodeUint64(y)],foreignApps:[_e(o,U.V2)],foreignAssets:[d,f,m],accounts:[I,v],suggestedParams:p,note:Te.getAppCallTxnNoteWithClientName(U.V2)})).fee=e.ALGORAND_MIN_TX_FEE*(Ve[i]+1),E=[k,_],t.next=17,He({client:a,network:o,assetIDs:[d,f,m]});case 17:if(!((P=t.sent).length>0)){t.next=23;break}return t.next=21,ze({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 He(e){return $e.apply(this,arguments)}function $e(){return($e=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(Ge(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 Ze(e){return et.apply(this,arguments)}function et(){return(et=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 tt=function(e){return e.Direct="direct",e.Router="router",e}({}),nt=4*e.ALGORAND_MIN_TX_FEE;function rt(t){return(Ce[t]+Fe)*e.ALGORAND_MIN_TX_FEE}function at(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Le;return Math.ceil(1/e)}function st(e){return e1&&void 0!==arguments[1]?arguments[1]:Le)}function ot(t){return(Ce[t]+1)*e.ALGORAND_MIN_TX_FEE}function it(e){var t=e.assetIn,n=e.assetOut;return fe(n.decimals,Number(n.amount))/fe(t.decimals,Number(t.amount))}function ut(e){var t=e.inputSupply,n=e.outputSupply,r=e.assetIn,a=e.assetOut,s=it({assetIn:r,assetOut:a}),o=fe(a.decimals,Number(n))/fe(r.decimals,Number(t));return me({decimalPlaces:5},Math.abs(s/o-1))}function ct(e){if(e.type===tt.Router){var t=Qe(e.data.route);return{id:ee(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetInID,amount:e.data.quote.assetInAmount}}function pt(e){if(e.type===tt.Router){var t=qe(e.data.route);return{id:ee(t.asset),amount:Number(t.amount)}}return{id:e.data.quote.assetOutID,amount:e.data.quote.assetOutAmount}}function lt(e){return e.type===tt.Direct?e.data.pool.contractVersion:U.V2}function dt(e){return e.type===tt.Direct?e.data.quote.rate:Xe(e.data.route)}function ft(e){for(var t=e[0],n=dt(t),r=1;rn&&(t=a,n=s)}return t}function mt(e){return e instanceof E&&[_.SwapRouterInsufficientReservesError,_.SwapRouterLowSwapAmountError,_.OutputAmountExceedsAvailableLiquidityError,_.LowSwapAmountError].includes(e.type)}var ht={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"},gt={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"},At=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}})),xt=function(n){d(a,At);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=_e(n.network,U.V1_1),a=v($(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:_t(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 kt(e,t){var n=e["apps-local-state"].find((function(e){return e.id===t}));return n?te({stateArray:n["key-value"],shouldDecodeKeys:!0}):null}function _t(e){var t=e["apps-total-schema"];return S+D*(e.assets||[]).length+N*(e["created-apps"]||[]).length+O*(e["apps-local-state"]||[]).length+B*Number(t&&t["num-byte-slice"]||0)+C*Number(t&&t["num-uint"]||0)+L*(e["apps-total-extra-pages"]||0)}var Et=ye("e");function Pt(e){return St.apply(this,arguments)}function St(){return(St=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,A,x,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(A=g["key-value"]){n.next=19;break}return n.abrupt("break",31);case 19:x=te({stateArray:A}),I=t.fromByteArray(ne([e.decodeAddress(f).publicKey,Et,e.encodeUint64(o.asset1ID)])),v=t.fromByteArray(ne([e.decodeAddress(f).publicKey,Et,e.encodeUint64(o.asset2ID)])),w=t.fromByteArray(ne([e.decodeAddress(f).publicKey,Et,e.encodeUint64(o.poolTokenID)])),y=x[I],b=x[v],k=x[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 Dt(){return(Dt=i(s().mark((function n(r){var a,o,i,u,c,p,l,d,f,m,h,g,A,x,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=te({stateArray:p["key-value"]}),f=0,m=Object.entries(d);fFt)){n.next=48;break}throw new Error("Issued liquidity value is out of the expected range ([0n, ".concat(Ft,"]): ").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 jt(){return jt=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,Tt(n,r);case 6:return i=e.sent,u=kt(i,_e(a,U.V1_1)),c=null,u&&(l=i["created-assets"][0],p=l.index,c={asset1ID:u[Lt[U.V1_1].asset1],asset2ID:u[Lt[U.V1_1].asset2],poolTokenID:p},o[r]=c),e.abrupt("return",c);case 11:case"end":return e.stop()}}),e)}))),jt.apply(this,arguments)}var Vt=Object.freeze({__proto__:null,getPoolAssets:function(e){return jt.apply(this,arguments)},getPoolInfo:Rt,getPoolReserves:function(e,t){return Ut.apply(this,arguments)}});function Xt(e){return Gt.apply(this,arguments)}function Gt(){return(Gt=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=bt(U.V2),u=i.generateLogicSigAccountForPool(t),c=_e(r,U.V2),p=u.address(),l=$(a,o),e.next=8,Tt(n,p);case 8:return d=e.sent,f=kt(d,c),m={account:u,validatorAppID:c,asset1ID:l[0],asset2ID:l[1],status:f?Nt.READY:Nt.NOT_CREATED,contractVersion:U.V2},f&&(m.asset1ProtocolFees=BigInt(f[Lt.v2.asset1ProtocolFees]),m.asset2ProtocolFees=BigInt(f[Lt.v2.asset2ProtocolFees]),m.asset1Reserves=BigInt(f[Lt.v2.asset1Reserves]),m.asset2Reserves=BigInt(f[Lt.v2.asset2Reserves]),m.issuedPoolTokens=BigInt(f[Lt.v2.issuedPoolTokens]),m.cumulativePriceUpdateTimeStamp=Number(f[Lt.v2.cumulativePriceUpdateTimeStamp]),m.protocolFeeRatio=Number(f[Lt.v2.protocolFeeRatio]),m.totalFeeShare=BigInt(f[Lt.v2.totalFeeShare]),m.poolTokenID=Number(f[Lt.v2.poolTokenID]),m.asset1ID=Number(f[Lt.v2.asset1]),m.asset2ID=Number(f[Lt.v2.asset2])),e.abrupt("return",m);case 13:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function qt(){return(qt=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,Tt(t,n.account.address());case 2:return r=e.sent,a=kt(r,n.validatorAppID),o={asset1:0n,asset2:0n,issuedLiquidity:0n,round:r.round},a&&(o.asset1=BigInt(a[Lt.v2.asset1Reserves]),o.asset2=BigInt(a[Lt.v2.asset2Reserves]),o.issuedLiquidity=BigInt(a[Lt.v2.issuedPoolTokens])),e.abrupt("return",o);case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Qt(){return(Qt=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,Tt(n,r);case 3:return o=e.sent,i=kt(o,_e(a,U.V2)),u=null,i&&(u={asset1ID:i[Lt[U.V2].asset1],asset2ID:i[Lt[U.V2].asset2],poolTokenID:i[Lt[U.V2].poolTokenID]}),e.abrupt("return",u);case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Wt=Object.freeze({__proto__:null,getPoolAssets:function(e){return Qt.apply(this,arguments)},getPoolInfo:Xt,getPoolReserves:function(e,t){return qt.apply(this,arguments)}});function zt(e){return Boolean(e&&!(e.asset1+e.asset2))}var Jt,Yt=Object.freeze({__proto__:null,getPoolPairRatio:function(e){var t=zt(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([Rt(e),Xt(e)])},isPoolEmpty:zt,isPoolNotCreated:function(e){return(null==e?void 0:e.status)===Nt.NOT_CREATED},isPoolReady:function(e){return(null==e?void 0:e.status)===Nt.READY}}),Kt=a((l(Jt={},U.V1_1,a(a({},Vt),Yt)),l(Jt,U.V2,a(a({},Wt),Yt)),Jt),Yt),Ht=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}({}),$t={ASA_ALGO:96e4,ASA_ASA:859e3};function Zt(){return(Zt=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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=H(o,i),l=v(p,2),d=l[0],f=d.id,m=d.unit_name,h=l[1],g=h.id,A=h.unit_name,x=Z(g),I=_e(a,U.V1_1),w=It.generateLogicSigAccountForPool({network:a,asset1ID:f,asset2ID:g}),y=w.address(),b=e.makeApplicationOptInTxnFromObject({from:y,appIndex:I,note:Te.getAppCallTxnNoteWithClientName(U.V1_1),appArgs:[ye("bootstrap"),e.encodeUint64(f),e.encodeUint64(g)],foreignAssets:x?[f]:[g],suggestedParams:c}),T=e.makeAssetCreateTxnWithSuggestedParamsFromObject({from:y,total:0xffffffffffffffffn,decimals:6,defaultFrozen:!1,unitName:X.V1_1,assetName:"TinymanPool1.1 ".concat(m,"-").concat(A),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:en(x),suggestedParams:c}),(E=[])[Ht.FUNDING_TXN]=_,E[Ht.VALIDATOR_APP_CALL]=b,E[Ht.POOL_TOKEN_CREATE]=T,E[Ht.ASSET1_OPT_IN]=k,x||(E[Ht.ASSET2_OPT_IN]=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:y,to:y,assetIndex:g,amount:0,suggestedParams:c})),P=e.assignGroupID(E),S=[{txn:P[Ht.FUNDING_TXN],signers:[u]},{txn:P[Ht.VALIDATOR_APP_CALL],signers:[y]},{txn:P[Ht.POOL_TOKEN_CREATE],signers:[y]},{txn:P[Ht.ASSET1_OPT_IN],signers:[y]}],P[Ht.ASSET2_OPT_IN]&&S.push({txn:P[Ht.ASSET2_OPT_IN],signers:[y]}),t.abrupt("return",S);case 23:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function en(e){return e?$t.ASA_ALGO:$t.ASA_ASA}function tn(){return(tn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x;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=$(i,u),f=v(d,2),m=f[0],h=f[1],g=It.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),A=[],x=r.map((function(t,n){if(n===Ht.FUNDING_TXN)return A.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return A.push(a),s})),t.abrupt("return",{signedTxns:x,txnIDs:A});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function nn(e){return rn.apply(this,arguments)}function rn(){return(rn=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,pe(n,a[Ht.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 J(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 an(){return(an=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,nn({client:n,signedTxns:u,txnIDs:c});case 3:return e.abrupt("return",Kt.v1_1.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var sn={generateTxns:function(e){return Zt.apply(this,arguments)},signTxns:function(e){return tn.apply(this,arguments)},execute:function(e){return an.apply(this,arguments)},getBootstrapFundingTxnAmount:en};var on=function(e){return e[e.FUNDING_TXN=0]="FUNDING_TXN",e[e.VALIDATOR_APP_CALL=1]="VALIDATOR_APP_CALL",e}({}),un={ASA_ALGO:5,ASA_ASA:6};function cn(e,t){return pn.apply(this,arguments)}function pn(){return(pn=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 ln(e,t){return dn.apply(this,arguments)}function dn(){return(dn=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,cn(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 fn(e,t){return mn.apply(this,arguments)}function mn(){return(mn=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,ln(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 hn(){return(hn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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=_e(a,U.V2),l=e.getApplicationAddress(p),d=H(o,i),f=v(d,2),m=f[0].id,h=f[1].id,t.next=9,Kt.v2.getPoolInfo({client:r,network:a,asset1ID:m,asset2ID:h});case 9:if(t.sent.status!==Nt.READY){t.next=12;break}throw new Error("Pool for ".concat(o.unit_name,"-").concat(i.unit_name," already exists"));case 12:return g=yt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),A=g.address(),x=Z(h),(I=e.makeApplicationOptInTxnFromObject({from:A,appIndex:p,appArgs:[ye("bootstrap")],note:Te.getAppCallTxnNoteWithClientName(U.V2),foreignAssets:[m,h],rekeyTo:l,suggestedParams:c})).fee=An(x),w=e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:A,amount:gn(x),suggestedParams:c}),(y=[])[on.FUNDING_TXN]=w,y[on.VALIDATOR_APP_CALL]=I,b=e.assignGroupID(y),(T=[])[on.FUNDING_TXN]={txn:b[on.FUNDING_TXN],signers:[u]},T[on.VALIDATOR_APP_CALL]={txn:b[on.VALIDATOR_APP_CALL],signers:[A]},t.abrupt("return",T);case 26:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function gn(e){return function(e,t){var n=bt(e).schema,r=n.numLocalInts,a=n.numLocalByteSlices,s=S+D+D+O+C*r+B*a;return t||(s+=D),s}(U.V2,e)+An(e)+D}function An(t){return((t?un.ASA_ALGO:un.ASA_ASA)+1)*e.ALGORAND_MIN_TX_FEE}function xn(){return(xn=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x;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=$(i,u),f=v(d,2),m=f[0],h=f[1],g=yt.generateLogicSigAccountForPool({network:a,asset1ID:m,asset2ID:h}),A=[],x=r.map((function(t,n){if(n===on.FUNDING_TXN)return A.push(t.txn.txID().toString()),l;var r=e.signLogicSigTransactionObject(t.txn,g),a=r.txID,s=r.blob;return A.push(a),s})),t.abrupt("return",{signedTxns:x,txnIDs:A});case 11:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function In(){return(In=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,cn(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(Lt.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",Kt.v2.getPoolInfo({client:n,network:r,asset1ID:o,asset2ID:i}));case 21:throw e.prev=21,e.t3=e.catch(1),new J(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 vn,wn={generateTxns:function(e){return hn.apply(this,arguments)},signTxns:function(e){return xn.apply(this,arguments)},execute:function(e){return In.apply(this,arguments)},getBootstrapFundingTxnAmount:gn,getTotalCost:function(t){return e.ALGORAND_MIN_TX_FEE+gn(t)}};var yn,bn,Tn,kn,_n=(l(vn={},U.V1_1,sn),l(vn,U.V2,wn),l(vn,"generateTxns",(function(e){return e.contractVersion===U.V1_1?sn.generateTxns(e):wn.generateTxns(e)})),l(vn,"signTxns",(function(e){return e.contractVersion===U.V1_1?sn.signTxns(e):wn.signTxns(e)})),l(vn,"execute",(function(e){return e.contractVersion===U.V1_1?sn.execute(e):wn.execute(e)})),l(vn,"calculateBootstrapFundingTxnAmount",(function(e){var t=e.contractVersion,n=e.isAlgoPool;return t===U.V1_1?sn.getBootstrapFundingTxnAmount(n):wn.getBootstrapFundingTxnAmount(n)})),vn),En=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}({}),Pn=5*e.ALGORAND_MIN_TX_FEE,Sn=function(e){return e.SINGLE="single",e.FLEXIBLE="flexible",e.INITIAL="initial",e}({}),Dn=(l(yn={},Sn.FLEXIBLE,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),l(yn,Sn.SINGLE,{ASSET_IN_TXN:0,VALIDATOR_APP_CALL_TXN:1}),l(yn,Sn.INITIAL,{ASSET1_IN_TXN:0,ASSET2_IN_TXN:1,VALIDATOR_APP_CALL_TXN:2}),yn),On=(l(bn={},Sn.INITIAL,1),l(bn,Sn.SINGLE,2),l(bn,Sn.FLEXIBLE,2),bn),Nn=(l(Tn={},Sn.INITIAL,3),l(Tn,Sn.FLEXIBLE,3),l(Tn,Sn.SINGLE,2),Tn);function Ln(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,A=BigInt(i.amount)-h;if(g>A){var x=g;r=Cn(x,s),t={id:o.id,amount:x+r,decimals:o.decimals,reserves:a.asset1},n={id:i.id,amount:BigInt(Math.abs(Math.min(Number(A),0))),decimals:i.decimals,reserves:a.asset2},f-=r*d/(c*BigInt(2))}else{var I=A;r=Cn(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:ut({inputSupply:t.reserves,outputSupply:n.reserves,assetIn:t,assetOut:n})}}}function Bn(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))-Bt)))}function Cn(e,t){return e*BigInt(t)/(BigInt(1e4)-BigInt(t))}function Fn(t){return(On[t]+1)*e.ALGORAND_MIN_TX_FEE}var Rn=ye("add_liquidity"),Mn=(l(kn={},U.V1_1,[ye("mint")]),l(kn,U.V2,{INITIAL_LIQUIDITY:[ye("add_initial_liquidity")],SINGLE_ASSET_MODE:[Rn,ye("single")],FLEXIBLE_MODE:[Rn,ye("flexible")]}),kn);function Un(){return(Un=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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=de("negative",p,c.amount),t.next=4,r.getTransactionParams().do();case 4:return f=t.sent,m=e.makeApplicationNoOpTxnFromObject({from:o,appIndex:_e(a,U.V1_1),appArgs:Mn.v1_1,accounts:[l],note:Te.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}),A=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:o,to:l,assetIndex:c.id,amount:d,suggestedParams:f}),x=e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:o,amount:m.fee+A.fee,note:P,suggestedParams:f}),I=e.assignGroupID([x,m,h,g,A]),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 jn(){return(jn=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===En.FEE_TXN?p:n===En.ASSET1_IN_TXN?l:n===En.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 Vn(){return(Vn=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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[En.LIQUDITY_OUT_TXN].txn.amount),e.next=5,Pt({client:n,pool:r,accountAddr:i});case 5:return c=e.sent,e.next=8,Ae(n,[o]);case 8:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,h=Ie(a),g=ve(a),e.next=17,Pt({client:n,pool:r,accountAddr:i});case 17:return A=e.sent,(x=A.excessPoolTokens-c.excessPoolTokens)<0n&&(x=0n),e.abrupt("return",{round:f,fees:h,poolTokenID:r.poolTokenID,poolTokenOut:u+x,excessAmount:{excessAmountForAddingLiquidity:x,totalExcessAmount:A.excessPoolTokens},txnID:m,groupID:g});case 23:throw e.prev=23,e.t0=e.catch(1),"SlippageTolerance"===(I=new J(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 Xn=Object.freeze({__proto__:null,execute:function(e){return Vn.apply(this,arguments)},generateTxns:function(e){return Un.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(F))throw new Error("Initial liquidity amount is too small. The amount must be greater than ".concat(F,", 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(F),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(st(Number(t)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{assetInID:i,assetInAmount:l,assetOutID:c,assetOutAmount:m,swapFee:Number(h),rate:fe(p,Number(m))/fe(u,Number(l)),priceImpact:g}}function hr(e){var t=e.amount,n=e.assetIn,r=e.assetOut,a=e.pool;if(!a||!Kt.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=ut({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(st(Number(m)))throw new E(_.LowSwapAmountError,"Swap amount is too low.");return{type:tt.Direct,data:{pool:a,quote:{assetInID:i,assetInAmount:m,assetOutID:c,assetOutAmount:l,swapFee:Number(h),rate:fe(p,Number(l))/fe(u,Number(m)),priceImpact:g}}}}function gr(e){return Ar.apply(this,arguments)}function Ar(){return(Ar=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=mr({amount:n,assetIn:r,assetOut:a,pool:u});e({type:tt.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(Ze({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ne.FixedInput,network:i}).then((function(e){return{type:tt.Router,data:e}}))),e.next=6,fr(c);case 6:return p=e.sent,e.abrupt("return",ft(p));case 8:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function xr(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=[new Promise((function(e,t){try{e(hr({amount:n,assetIn:r,assetOut:a,pool:u}))}catch(e){t(e)}}))],o&&c.push(Ze({amount:n,assetInID:r.id,assetOutID:a.id,swapType:Ne.FixedOutput,network:i}).then((function(e){return{type:tt.Router,data:e}}))),e.next=5,fr(c);case 5:return p=e.sent,e.abrupt("return",ft(p));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function vr(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:ut({inputSupply:t,outputSupply:n,assetIn:{amount:r,decimals:s.assetIn},assetOut:{amount:i,decimals:s.assetOut}})}}var wr={getQuote:function(e){return dr.apply(this,arguments)},getFixedInputSwapQuote:gr,getFixedInputDirectSwapQuote:mr,getFixedOutputDirectSwapQuote:hr,getFixedOutputSwapQuote:xr,generateTxns:function(e){return pr.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return lr.apply(this,arguments)},calculateFixedInputSwap:vr};function yr(e,t){var n,r,a=BigInt(e),s=t.issuedLiquidity;return s>a+BigInt(Bt)?(n=a*t.asset1/s,r=a*t.asset2/s):(n=t.asset1,r=t.asset2),{asset1OutputAmount:n,asset2OutputAmount:r}}function br(){return(br=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A;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:Te.getAppCallTxnNoteWithClientName(U.V2),appArgs:[ar,e.encodeUint64(de("negative",p,u)),e.encodeUint64(de("negative",p,c))],accounts:[d],foreignAssets:[a.asset1ID,a.asset2ID],suggestedParams:l})).fee=(rr+1)*e.ALGORAND_MIN_TX_FEE,(g=[])[sr.ASSET_TRANSFER_TXN]=m,g[sr.APP_CALL_TXN]=h,A=e.assignGroupID(g),t.abrupt("return",[{txn:A[sr.ASSET_TRANSFER_TXN],signers:[i]},{txn:A[sr.APP_CALL_TXN],signers:[i]}]);case 16:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function Tr(){return(Tr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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,A=0,x=de("negative",p,c),u!==d){t.next=17;break}g=x,A=0,t.next=23;break;case 17:if(u!==f){t.next=22;break}g=0,A=x,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:Te.getAppCallTxnNoteWithClientName(U.V2),appArgs:[ar,e.encodeUint64(g),e.encodeUint64(A)],accounts:[m],foreignAssets:[u],suggestedParams:l})).fee=(rr+1)*e.ALGORAND_MIN_TX_FEE,(w=[])[sr.ASSET_TRANSFER_TXN]=I,w[sr.APP_CALL_TXN]=v,y=e.assignGroupID(w),t.abrupt("return",[{txn:y[sr.ASSET_TRANSFER_TXN],signers:[o]},{txn:y[sr.APP_CALL_TXN],signers:[o]}]);case 31:case"end":return t.stop()}}),t)})))).apply(this,arguments)}function kr(){return(kr=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,Ae(n,[a]);case 3:return o=e.sent,i=v(o,1),u=i[0].txnID,e.prev=6,e.next=9,fn(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 _r,Er={getQuote:function(e){var t=e.pool,n=e.reserves,r=e.poolTokenIn,a=BigInt(r),s=yr(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=yr(i,r),c=u.asset1OutputAmount,p=u.asset2OutputAmount,l=n.totalFeeShare;if(s===n.asset1ID){var d=wr.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=wr.calculateFixedInputSwap({inputSupply:r.asset1-c,outputSupply:r.asset2-p,swapInputAmount:c,totalFeeShare:l,decimals:o}),A=g.swapOutputAmount,x=g.totalFeeAmount,I=g.priceImpact;t={round:r.round,assetOut:{assetId:s,amount:p+A},poolTokenIn:{assetId:n.poolTokenID,amount:i},internalSwapQuote:{amountIn:{assetId:n.asset2ID,amount:p},amountOut:{assetId:n.asset1ID,amount:A},swapFees:{assetId:n.asset2ID,amount:x},priceImpact:I}}}return t},generateTxns:function(e){return br.apply(this,arguments)},generateSingleAssetOutTxns:function(e){return Tr.apply(this,arguments)},signTxns:function(e){var t=e.txGroup;return(0,e.initiatorSigner)([t])},execute:function(e){return kr.apply(this,arguments)}},Pr=(l(_r={},U.V1_1,cr),l(_r,U.V2,Er),_r),Sr=3n,Dr=1000n,Or=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}(Or||{});function Nr(){return(Nr=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===Or.FEE_TXN_INDEX?c:n===Or.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 Lr(){return(Lr=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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 J({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=[ye("swap"),o===Ne.FixedInput?ye("fi"):ye("fo")],A=e.makeApplicationNoOpTxnFromObject({from:f,appIndex:c.validatorAppID,appArgs:g,accounts:[u],note:Te.getAppCallTxnNoteWithClientName(U.V1_1),foreignAssets:c.asset2ID==j?[c.asset1ID,c.poolTokenID]:[c.asset1ID,c.asset2ID,c.poolTokenID],suggestedParams:h}),x=o===Ne.FixedOutput?de("positive",i,p.assetInAmount):p.assetInAmount,I=l===j?e.makePaymentTxnWithSuggestedParamsFromObject({from:u,to:f,amount:x,suggestedParams:h}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:u,to:f,assetIndex:l,amount:x,suggestedParams:h}),v=o===Ne.FixedInput?de("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:A.fee+w.fee,note:P,suggestedParams:h}),b=e.assignGroupID([y,A,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 Br(e){var t=e.pool,n=e.reserves,r=e.assetIn,s=e.decimals;if(t.status!==Nt.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*Sr/Dr,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:it(d),priceImpact:ut(a({inputSupply:i,outputSupply:u},d))};return{type:tt.Direct,data:{pool:t,quote:f}}}function Cr(e){return Fr.apply(this,arguments)}function Fr(){return(Fr=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,A,x;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,Pt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ae(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Pt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,i.id===r.asset1ID?(g=c.excessAsset1,A=h.excessAsset1):(g=c.excessAsset2,A=h.excessAsset2),(x=A-g)<0n&&(x=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount),assetOutID:i.id,assetOutAmount:BigInt(i.amount)+x,excessAmount:{assetID:i.id,excessAmountForSwap:x,totalExcessAmount:A},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Rr(e){var t=e.pool,n=e.reserves,r=e.assetOut,a=e.decimals;if(t.status!==Nt.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*Dr/(Dr-Sr),l=p-c,d=fe(a.assetOut,Number(u))/fe(a.assetIn,Number(p)),f=fe(a.assetOut,Number(i))/fe(a.assetIn,Number(o)),m=me({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:tt.Direct,data:{pool:t,quote:h}}}function Mr(e){return Ur.apply(this,arguments)}function Ur(){return(Ur=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l,d,f,m,h,g,A,x;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,Pt({client:n,pool:r,accountAddr:u});case 3:return c=e.sent,e.next=6,Ae(n,[a]);case 6:return p=e.sent,l=v(p,1),d=l[0],f=d.confirmedRound,m=d.txnID,e.next=13,Pt({client:n,pool:r,accountAddr:u});case 13:return h=e.sent,o.id===r.asset1ID?(g=c.excessAsset1,A=h.excessAsset1):(g=c.excessAsset2,A=h.excessAsset2),(x=A-g)<0n&&(x=0n),e.abrupt("return",{round:f,assetInID:o.id,assetInAmount:BigInt(o.amount)-x,assetOutID:i.id,assetOutAmount:BigInt(i.amount),excessAmount:{assetID:o.id,excessAmountForSwap:x,totalExcessAmount:A},txnID:m});case 18:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function jr(){return(jr=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===Nt.READY){e.next=3;break}throw new J({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[Or.ASSET_IN_TXN_INDEX].txn.assetIndex||j,amount:i[Or.ASSET_IN_TXN_INDEX].txn.amount},l={id:i[Or.ASSET_OUT_TXN_INDEX].txn.assetIndex||j,amount:i[Or.ASSET_OUT_TXN_INDEX].txn.amount},o!==Ne.FixedInput){e.next=12;break}return e.next=9,Cr({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,Mr({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:ve(i),fees:Ie(i)}));case 18:throw e.prev=18,e.t0=e.catch(3),"SlippageTolerance"===(f=new J(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 Vr,Xr={getQuote:function(e,t,n,r,a){return e===Ne.FixedInput?Br({pool:t,reserves:n,assetIn:r,decimals:a}):Rr({pool:t,reserves:n,assetOut:r,decimals:a})},getFixedInputSwapQuote:Br,getFixedOutputSwapQuote:Rr,generateTxns:function(e){return Lr.apply(this,arguments)},signTxns:function(e){return Nr.apply(this,arguments)},execute:function(e){return jr.apply(this,arguments)},executeFixedOutputSwap:Mr};function Gr(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(mt(n)&&!mt(r))throw n;throw r}return e.filter((function(e){return"fulfilled"===e.status&&e.value})).map((function(e){return e.value}))}))}function qr(){return(qr=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(Xr.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(wr.getFixedInputSwapQuote({amount:r,assetIn:{id:ee(a),decimals:a.decimals},assetOut:{id:ee(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,Gr(c);case 8:return d=e.sent,e.abrupt("return",ft(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Qr(){return(Qr=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(Xr.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(wr.getFixedOutputSwapQuote({amount:r,assetIn:{id:ee(a),decimals:a.decimals},assetOut:{id:ee(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,Gr(c);case 8:return d=e.sent,e.abrupt("return",ft(d));case 10:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Wr=(l(Vr={},U.V1_1,Xr),l(Vr,U.V2,wr),l(Vr,"getQuote",(function(e){var t=e.type;if(t===Ne.FixedInput)return function(e){return qr.apply(this,arguments)}(e);if(t===Ne.FixedOutput)return function(e){return Qr.apply(this,arguments)}(e);throw new E(_.InvalidSwapTypeError,"Invalid swap type")})),l(Vr,"generateTxns",(function(e){return e.quote.type===tt.Direct&<(e.quote)===U.V1_1?Xr.generateTxns(a(a({},e),{},{quoteAndPool:e.quote.data})):wr.generateTxns(e)})),l(Vr,"signTxns",(function(e){if(e.quote.type===tt.Direct&<(e.quote)===U.V1_1){var t=e.quote.data.pool;return Xr.signTxns(a(a({},e),{},{pool:t}))}return wr.signTxns(e)})),l(Vr,"execute",(function(e){return e.contractVersion===U.V1_1?Xr.execute(e):wr.execute(e)})),Vr);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 n=t.client,r=t.pool,a=t.txGroup,o=t.initiatorSigner,e.prev=1,e.next=4,Jr({txGroup:a,pool:r,initiatorSigner:o});case 4:return i=e.sent,e.next=7,Ae(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:Ie(a),confirmedRound:d,txnID:l,groupID:ve(a)});case 15:throw e.prev=15,e.t0=e.catch(1),new J(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 Jr(e){return Yr.apply(this,arguments)}function Yr(){return(Yr=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 Kr(){return Kr=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:Ie(t),groupID:ve(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,Ae(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 J(t.t0,"We encountered something unexpected while redeeming. Try again later.");case 13:case"end":return t.stop()}}),t,null,[[1,10]])}))),Kr.apply(this,arguments)}function Hr(){return(Hr=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:[ye("redeem")],note:Te.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 $r(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 Zr(e,t,n){return e*t/n}var ea=BigInt(31536e3),ta=BigInt(1e14),na=BigInt(1e16),ra={testnet:548587153,mainnet:1385499515},aa=14;function sa(e){return oa.apply(this,arguments)}function oa(){return(oa=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(ra[a]),t.next=4,Tt(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 ia(){return(ia=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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(ra[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],A=h[1],x=Z(A.id),I=e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:g.id,amount:g.amount,suggestedParams:f}),y=x?e.makePaymentTxnWithSuggestedParamsFromObject({from:l,to:d,amount:A.amount,suggestedParams:f}):e.makeAssetTransferTxnWithSuggestedParamsFromObject({from:l,to:d,assetIndex:A.id,amount:A.amount,suggestedParams:f}),(b=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:ra[a],appArgs:[ye("add_liquidity"),e.decodeAddress(o).publicKey,e.encodeUint64(g.lendingAppId),e.encodeUint64(A.lendingAppId)],foreignAssets:[g.id,A.id,g.fAssetId,A.fAssetId],foreignApps:[g.lendingAppId,A.lendingAppId,u],accounts:[o],suggestedParams:f})).fee=e.ALGORAND_MIN_TX_FEE*(aa+1),T=_e(a,U.V2),k=e.makeApplicationNoOpTxnFromObject({from:l,appIndex:ra[a],appArgs:[ye("noop")],foreignAssets:[i],foreignApps:[T],accounts:[o],suggestedParams:f}),_=[I,y,b,k],t.next=16,sa({client:r,network:a,assetIDs:[g.id,A.id,g.fAssetId,A.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:ra[a],appArgs:[ye("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 ua(){return(ua=i(s().mark((function t(n){var r,a,o,i,u,c,p,l,d,f,m,h,g,A,x,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(ra[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}),(A=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:ra[l],appArgs:[ye("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*(aa+1),x=_e(l,U.V2),I=e.makeApplicationNoOpTxnFromObject({from:i,appIndex:ra[l],appArgs:[ye("noop")],accounts:[m],foreignAssets:[h,u.fAssetId,c.fAssetId],foreignApps:[x],suggestedParams:f}),v=e.assignGroupID([g,A,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 ca(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 Zr(e,na+t*r/ea,na)}function pa(){return(pa=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=$r(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 la={AddLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return ia.apply(this,arguments)},getAddLiquidityTotalFee:function(t){return e.ALGORAND_MIN_TX_FEE*(4+aa)+(t?(t+1)*e.ALGORAND_MIN_TX_FEE+t*D:0)}}),RemoveLiquidity:Object.freeze({__proto__:null,generateTxns:function(e){return ua.apply(this,arguments)},getRemoveLiquidityTotalFee:function(){return e.ALGORAND_MIN_TX_FEE*(3+aa)}}),calculateWithdrawReturn:function(e){var t=e.withdrawAmount,n=ca(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return Zr(BigInt(t),n,ta)},calculateDepositReturn:function(e){var t=e.depositAmount,n=ca(e.depositInterestIndex,e.depositInterestRate,e.lastUpdate);return BigInt(t)*ta/n},getFolksWrapperAppOptInRequiredAssetIDs:sa};function da(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:[ye("commit"),u],note:ne([ye("tinymanStaking/v1:b"),c,e.encodeUint64(s),u])})}function fa(){return(fa=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=da({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:[ye("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)}function ma(e){if(e instanceof Uint8Array&&"Uint8Array"===e.constructor.name)return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}var ha=function(e,t){if(e.length>=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);mma(a(e))})}function Ta({name:e,prefix:t,bitsPerChar:n,alphabet:r}){return ya({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 ka=Ta({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5});Ta({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ta({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ta({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ta({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Ta({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ta({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Ta({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ta({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});const _a=ba({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"});ba({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ea=function e(t,n,r){n=n||[];var a=r=r||0;for(;t>=Da;)n[r++]=255&t|Pa,t/=128;for(;t&Sa;)n[r++]=255&t|Pa,t>>>=7;return n[r]=0|t,e.bytes=r-a+1,n},Pa=128,Sa=-128,Da=Math.pow(2,31);var Oa=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&La)<=Na);return e.bytes=o-n,a},Na=128,La=127;var Ba=Math.pow(2,7),Ca=Math.pow(2,14),Fa=Math.pow(2,21),Ra=Math.pow(2,28),Ma=Math.pow(2,35),Ua=Math.pow(2,42),ja=Math.pow(2,49),Va=Math.pow(2,56),Xa=Math.pow(2,63),Ga={encode:Ea,decode:Oa,encodingLength:function(e){return e{const[n,r]=qa(e.subarray(t));return t+=r,n};let r=n(),a=Za;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??_a;return[_a.prefix,n.decode(`${_a.prefix}${e}`)]}case _a.prefix:{const n=t??_a;return[_a.prefix,n.decode(e)]}case ka.prefix:{const n=t??ka;return[ka.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=$a.decode(r);if(0===a.version&&"Q"!==e[0])throw Error("Version 0 CID string must not include multibase prefix");return Ha(a).set(n,e),a}}const Za=112,es=18;function ts(e,t,n){const r=Wa(e),a=r+Wa(t),s=new Uint8Array(a+n.byteLength);return Qa(e,s,0),Qa(t,s,r),s.set(n,a),s}const ns=Symbol.for("@ipld/js-cid/CID");class rs{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?za(this.code,t):t.then((e=>za(this.code,e)))}throw Error("Unknown type, must be binary type")}}const as=function({name:e,code:t,encode:n}){return new rs(e,t,n)}({name:"sha2-256",code:18,encode:e=>ma(n.createHash("sha256").update(e).digest())}),ss=85;var os=604800,is={testnet:480164661,mainnet:2200606875},us={testnet:360907790,mainnet:2200609638},cs={testnet:336189106,mainnet:2200608153},ps={testnet:383416252,mainnet:2200608887},ls=2500,ds=400,fs=604800,ms=126144e3,hs=1e7,gs=Math.pow(2,64),As=48,xs=21,Is=48,vs=ye("tp"),ws=ye("sc"),ys=28100,bs=12900,Ts=421700,ks=409700;function _s(e){var t=e/fs;return(arguments.length>1&&void 0!==arguments[1]&&arguments[1]?Math.floor(t):Math.ceil(t))*fs}function Es(e,t){if(e>t)throw new Error("Old timestamp must be less than or equal to new timestamp");for(var n=[],r=_s(e)+fs;re?r=t?e*e*gs/(2*t):0:r=(e+(e-r))*n/2;return r}function Bs(e,t){return Cs.apply(this,arguments)}function Cs(){return(Cs=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",Fs(r));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Fs(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 Rs(){for(var e=arguments.length,t=new Array(e),n=0;n1&&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 Gs(e,t){return 0===Buffer.compare(e,t)}function qs(e){for(var t=0n,n=0;n0?xs-e:0}},{key:"lastAccountPowerBoxIndex",get:function(){return eo(this.powerCount)[0]}},{key:"lastAccountPowerArrayIndex",get:function(){return eo(this.powerCount)[1]}}]),e}(),Ws=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+Ls(this.bias,this.slope,t)}}]),e}(),zs=p((function e(t,n,r,a){u(this,e),this.bias=t,this.timestamp=n,this.slope=r,this.cumulativePower=a})),Js=p((function e(t){u(this,e),this.slopeDelta=t})),Ys=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%xs;return e>0?xs-e:0}},{key:"lastTotalPowerBoxIndex",get:function(){return eo(this.totalPowerCount)[0]}},{key:"lastTotalPowerArrayIndex",get:function(){return eo(this.totalPowerCount)[1]}}]),e}();function Ks(){return(Ks=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=$s(r),e.prev=1,e.next=4,Ps(t,n,a);case 4:if(!(o=e.sent)){e.next=7;break}return e.abrupt("return",Hs(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 Hs(e){var t=Buffer.from(e);return new Qs(t.readUIntBE(0,8),t.readUIntBE(8,8),t.readUIntBE(16,8),t.readUIntBE(24,8))}function $s(t){return e.decodeAddress(t).publicKey}function Zs(e){var t=Xs(e),n=new Uint8Array(vs.length+t.length);return n.set(vs,0),n.set(t,vs.length),n}function eo(e){var t=e-1;return[Math.floor(t/xs),t%xs]}function to(t,n){var r=e.decodeAddress(t).publicKey,a=Xs(n),s=new Uint8Array(r.length+a.length);return s.set(r,0),s.set(a,r.length),s}function no(e,t,n){return ro.apply(this,arguments)}function ro(){return(ro=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=so(r),e.next=3,Ps(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",ao(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ao(t){return new Js(Number(e.bytesToBigInt(t.slice(t.length-16,t.length))))}function so(e){return Rs(ws,Xs(e))}function oo(e,t,n,r){return io.apply(this,arguments)}function io(){return(io=i(s().mark((function e(t,n,r,a){var o,i,u,c,p;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:o=0,r&&(o=Math.ceil(r/xs)),i=[],u=0;case 4:if(!(u4?d[4]:void 0,i=0,(a=d.length>3&&void 0!==d[3]?d[3]:null)&&(i=Math.ceil(a/xs)),u=[],c=0;case 6:if(!(c=e[r].timestamp))break;n=r}return n}function fo(e){for(var t,n=As,r=[],a=0;ai.freeTotalPowerSpaceCount&&(b+=ks),c||(b+=bs);var k=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({amount:a,assetIndex:G[s],from:o,suggestedParams:u,to:e.getApplicationAddress(l)}),e.makeApplicationNoOpTxnFromObject({appIndex:l,from:o,suggestedParams:u,appArgs:[ye("create_lock"),Xs(r)],boxes:d.slice(0,8),note:p}),wo({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 bo(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+=ks),!n.freeAccountPowerSpaceCount){var w=to(s,n.lastAccountPowerBoxIndex+1);h.push({appIndex:is[a],name:w}),v+=Ts}var y=[e.makeAssetTransferTxnWithSuggestedParamsFromObject({assetIndex:G[a],from:s,to:e.getApplicationAddress(is[a]),amount:r,suggestedParams:i}),e.makeApplicationNoOpTxnFromObject({appIndex:is[a],from:s,suggestedParams:i,appArgs:[ye("increase_lock_amount")],boxes:h,note:u}),wo({sender:s,suggestedParams:i,index:is[a]})];if(v){var b=e.makePaymentTxnWithSuggestedParamsFromObject({from:s,suggestedParams:i,to:e.getApplicationAddress(is[a]),amount:v});y.unshift(b)}return e.assignGroupID(y)}function To(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%fs)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=$s(o),l=to(o,n.lastAccountPowerBoxIndex),d=Zs(i.lastTotalPowerBoxIndex),f=Zs(i.lastTotalPowerBoxIndex+1),m=so(n.lockEndTime),h=so(a),g=[{appIndex:is[r],name:p},{appIndex:is[r],name:l},{appIndex:is[r],name:d},{appIndex:is[r],name:f},{appIndex:is[r],name:m},{appIndex:is[r],name:h}];if(!n.freeAccountPowerSpaceCount){var A=to(o,n.lastAccountPowerBoxIndex+1);g.push({appIndex:is[r],name:A})}var x,I=Es(i.lastTotalPowerTimestamp,Math.floor(Date.now()/1e3)),v=I.length,w=T(I);try{for(w.s();!(x=w.n()).done;){var y=x.value;if(y%fs==0){var b=so(y);g.push({appIndex:is[r],name:b})}}}catch(e){w.e(e)}finally{w.f()}var k=0;s||(k+=bs),n.freeAccountPowerSpaceCount||(k+=Ts),v>i.freeTotalPowerSpaceCount&&(k+=ks);var _=[e.makeApplicationNoOpTxnFromObject({appIndex:is[r],from:o,suggestedParams:u,appArgs:[ye("extend_lock_end_time"),Xs(a)],boxes:g.slice(0,8),note:c}),wo({sender:o,suggestedParams:u,index:is[r],boxes:g.slice(8)})];if(k){var E=e.makePaymentTxnWithSuggestedParamsFromObject({from:o,suggestedParams:u,to:e.getApplicationAddress(is[r]),amount:k});_.unshift(E)}return e.assignGroupID(_)}function ko(t){var n=t.accountState,r=t.network,a=t.sender,s=t.suggestedParams,o=t.appCallNote,i=$s(a),u=to(a,n.lastAccountPowerBoxIndex),c=to(a,n.lastAccountPowerBoxIndex+1),p=[{appIndex:is[r],name:i},{appIndex:is[r],name:u},{appIndex:is[r],name:c}],l=e.makeApplicationNoOpTxnFromObject({appIndex:is[r],from:a,suggestedParams:s,appArgs:[ye("withdraw")],foreignAssets:[G[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(is[r]),amount:Ts});d.unshift(f)}return e.assignGroupID(d)}var _o=8,Eo=ye("p"),Po=ye("a"),So=ye("v"),Do=28500,Oo=12500,No=ye("p"),Lo=ye("a"),Bo=24,Co=111300,Fo=ls+ds*(41+Bo),Ro=function(e){return e[e.Against=0]="Against",e[e.For=1]="For",e[e.Abstain=2]="Abstain",e}(Ro||{}),Mo=new Uint8Array(34),Uo="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAY5HFKQ",jo=function(){function e(t,n,r,a,s,o,i,c,p,l,d,f,m,h,g,A,x){u(this,e),this.index=t,this.creationTimestamp=n,this.votingStartTimestamp=r,this.votingEndTimestamp=a,this.snapshotTotalVotingPower=s,this.voteCount=o,this.quorumNumerator=i,this.againstVotingPower=c,this.forVotingPower=p,this.abstainVotingPower=l,this.isApproved=d,this.isCancelled=f,this.isExecuted=m,this.isQuorumReached=h,this.proposerAddress=g,this.executionHash=A,this.executorAddress=x}return p(e,[{key:"snapshotTimestamp",get:function(){return this.creationTimestamp}}]),e}(),Vo=p((function e(t,n,r,a,s,o,i,c,p,l){u(this,e),this.vaultAppId=t,this.proposalIndexCounter=n,this.votingDelay=r,this.votingDuration=a,this.proposalThreshold=s,this.proposalThresholdNumerator=o,this.quorumThreshold=i,this.approvalRequirement=c,this.manager=p,this.proposalManager=l}));function Xo(e){return Rs(No,ye(e))}function Go(t){var n=Buffer.from(t);return new jo(n.readUIntBE(0,8),n.readUIntBE(8,8),n.readUIntBE(16,8),n.readUIntBE(24,8),n.readUIntBE(32,8),n.readUIntBE(40,8),n.readUIntBE(48,8),n.readUIntBE(56,8),n.readUIntBE(64,8),n.readUIntBE(72,8),Boolean(n.readUIntBE(80,1)),Boolean(n.readUIntBE(81,1)),Boolean(n.readUIntBE(82,1)),Boolean(n.readUIntBE(83,1)),e.encodeAddress(n.subarray(84,116)),t.slice(116,150).toString(),e.encodeAddress(n.subarray(150,182)))}function qo(){return(qo=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=Xo(r),e.next=3,Ps(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",Go(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Qo=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 Wo(t,n){return Rs(Po,e.decodeAddress(t).publicKey,Xs(n))}function zo(e){return new Qo(qs(e.slice(0,8)),qs(e.slice(8,16)),qs(e.slice(16,24)),qs(e.slice(24,32)),qs(e.slice(32,40)),qs(e.slice(40,48)),Boolean(qs(e.slice(48,49))))}function Jo(){return(Jo=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=Xo(r),e.next=3,Ps(t,n,a);case 3:if(o=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",zo(o));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Yo(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>_o)throw new Error("You cannot cast vote for more than ".concat(_o," 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=Rs.apply(void 0,w(i.map((function(e){return Xs(e)})))),g=Rs.apply(void 0,w(u.map((function(e){return Xs(e)})))),A=function(e){return Rs(Eo,ye(e))}(s),x=Wo(a,Math.floor(o.index/8192)),I=!p.some((function(e){return Gs(e,x)})),v=$s(a),y=Math.floor(c/xs),b=to(a,y),k=to(a,y+1),_=0,E=[],P=T(u);try{var S=function(){var e=m.value,t=function(e,t){return Rs(So,Xs(e),Xs(t))}(o.index,e);E.push({appIndex:n,name:t}),p.some((function(e){return Gs(e,t)}))||(_+=1)};for(P.s();!(m=P.n()).done;)S()}catch(e){P.e(e)}finally{P.f()}var D=[{appIndex:n,name:A},{appIndex:n,name:x}].concat(E,[{appIndex:r,name:v},{appIndex:r,name:b},{appIndex:r,name:k}]),O=[e.makeApplicationNoOpTxnFromObject({from:a,suggestedParams:l,appIndex:n,appArgs:[ye("cast_vote"),ye(s),h,g,Xs(c)],foreignApps:[r],boxes:D.slice(0,7),note:f?ye(f):void 0})];O[0].fee*=2,D.length>=7&&O.push(wo({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(7,14)})),D.length>=14&&O.push(wo({sender:a,suggestedParams:l,index:r,foreignApps:[n],boxes:D.slice(14)}));var N=Number(I)*Do+_*Oo;return N&&(O=[e.makePaymentTxnWithSuggestedParamsFromObject({from:a,suggestedParams:l,to:e.getApplicationAddress(n),amount:N})].concat(w(O))),e.assignGroupID(O)}var Ko=ye("rp"),Ho=1012,$o=ye("c"),Zo=42,ei=ls+ds*(41+Ho),ti=p((function e(t,n,r,a,s,o,i){u(this,e),this.tinyAssetId=t,this.vaultAppId=n,this.rewardHistoryCount=r,this.firstPeriodTimestamp=a,this.rewardPeriodCount=s,this.manager=o,this.rewardsManager=i})),ni=p((function e(t){u(this,e),this.value=t}));function ri(t,n){var r=e.decodeAddress(t).publicKey,a=Xs(n),s=new Uint8Array($o.length+r.length+a.length);return s.set($o,0),s.set(r,$o.length),s.set(a,$o.length+r.length),s}function ai(e,t,n,r){return si.apply(this,arguments)}function si(){return(si=i(s().mark((function e(t,n,r,a){var o,i;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o=ri(r,a),e.next=3,Ps(t,n,o);case 3:if(i=e.sent){e.next=6;break}return e.abrupt("return",null);case 6:return e.abrupt("return",new ni(i));case 7:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function oi(t){for(var n=t.rewardsAppId,r=t.vaultAppId,a=t.tinyAssetId,s=t.sender,o=t.periodIndexStart,i=t.periodCount,u=t.accountPowerIndexes,c=t.suggestedParams,p=t.createRewardClaimSheet,l=t.appCallNote,d=[],f=[],m=[],h=[],g=function(){var e,t,r=Math.floor(A/Zo),a=(e=Xs(r),(t=new Uint8Array(Ko.length+e.length)).set(Ko,0),t.set(e,Ko.length),t);f.find((function(e){return e.name.toString()===a.toString()}))||f.push({appIndex:n,name:a});var o=Math.floor(A/(8*Ho)),i=ri(s,o);m.find((function(e){return e.name.toString()===i.toString()}))||m.push({appIndex:n,name:i})},A=o;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:[ye("claim_rewards"),Xs(o),Xs(i),Rs.apply(void 0,w(u.map((function(e){return Xs(e)}))))],foreignApps:[r],foreignAssets:[a],boxes:y,note:l?ye(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=wo({sender:s,suggestedParams:c,extraAppArgs:[Xs(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:ei,suggestedParams:c});b.unshift(D)}return e.assignGroupID(b)}function ii(t){var n=t.proposalId,r=t.proposalVotingAppId,a=t.sender,s=t.vaultAppId,o=t.vaultAppGlobalState,i=t.executionHash,u=t.executor,c=t.suggestedParams,p=t.appCallNote,l=Xo(n),d=$s(a),f=Zs(o.lastTotalPowerBoxIndex),m=[e.makePaymentTxnWithSuggestedParamsFromObject({from:a,to:e.getApplicationAddress(r),amount:Co,suggestedParams:c}),e.makeApplicationNoOpTxnFromObject({from:a,suggestedParams:c,appIndex:r,appArgs:[ye("create_proposal"),ye(n),i?ye(i):Mo,null!=u?u:e.decodeAddress(Uo).publicKey],foreignApps:[s],boxes:[{appIndex:r,name:l},{appIndex:s,name:d},{appIndex:s,name:f}],note:p?ye(p):void 0})];return m[1].fee*=3,e.assignGroupID(m)}function ui(t){var n=t.accountPowerIndex,r=t.createAttendanceSheetBox,a=t.proposal,s=t.proposalId,o=t.proposalVotingAppId,i=t.sender,u=t.suggestedParams,c=t.vaultAppId,p=t.vote,l=t.appCallNote;if(![Ro.Abstain,Ro.Against,Ro.For].includes(p))throw new Error("Invalid vote");var d,f,m=Math.floor(n/xs),h=Math.floor(a.index/(8*Bo)),g=[{appIndex:o,name:Xo(s)},{appIndex:o,name:(d=i,f=h,Rs(Lo,e.decodeAddress(d).publicKey,Xs(f)))},{appIndex:c,name:$s(i)},{appIndex:c,name:to(i,m)},{appIndex:c,name:to(i,m+1)}],A=[e.makeApplicationNoOpTxnFromObject({from:i,suggestedParams:u,appIndex:o,appArgs:[ye("cast_vote"),ye(s),Xs(p),Xs(n)],foreignApps:[c],boxes:g,note:l?ye(l):void 0})];if(A[0].fee*=2,r){var x=e.makePaymentTxnWithSuggestedParamsFromObject({from:i,suggestedParams:u,to:e.getApplicationAddress(o),amount:Fo});A.unshift(x)}return e.assignGroupID(A)}var ci=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,A,x,I,v,y;return p(t,[{key:"getTinyPower",value:(y=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()/1e3),n=p.length>1?p[1]:void 0,e.next=4,this.fetchAccountState();case 4:if(r=e.sent){e.next=7;break}return e.abrupt("return",0);case 7:return e.next=9,co(this.algodClient,this.userAddress,is[this.network],r.powerCount,n);case 9:if(a=e.sent,null!==(o=lo(a,t))){e.next=13;break}return e.abrupt("return",0);case 13:return i=a[o],u=t-i.timestamp,c=Math.max(i.bias-Ns(i.slope,u),0),e.abrupt("return",c);case 17: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,A,x,I,v,w=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=w.length>0&&void 0!==w[0]?w[0]:Math.floor(Date.now()/1e3),n=w.length>1?w[1]:void 0,e.next=4,this.fetchVaultAppGlobalState();case 4:if(r=e.sent){e.next=7;break}return e.abrupt("return",0);case 7:return e.next=9,oo(this.algodClient,is[this.network],r.totalPowerCount,n);case 9:if(a=e.sent,o=lo(a,t)){e.next=13;break}return e.abrupt("return",0);case 13:i=a[o],u=Math.floor(i.timestamp/fs),c=Math.floor(t/fs)-u,p=Array.from({length:c},(function(e,t){return(u+t)*fs})),l=p.map((function(e,t){return[0===t?i.timestamp:p[t-1],e]})),d=i.slope,f=i.bias,m=T(l),e.prev=20,m.s();case 22:if((h=m.n()).done){e.next=35;break}return g=h.value,A=g[1]-g[0],x=Ns(d,A),f=Math.max(f-x,0),e.next=29,no(this.algodClient,is[this.network],g[1]);case 29:I=e.sent,v=(null==I?void 0:I.slopeDelta)||0,d=Math.max(d-v,0),0!==f&&0!==d||(f=0,d=0);case 33:e.next=22;break;case 35:e.next=40;break;case 37:e.prev=37,e.t0=e.catch(20),m.e(e.t0);case 40:return e.prev=40,m.f(),e.finish(40);case 43:return e.abrupt("return",f);case 44:case"end":return e.stop()}}),e,this,[[20,37,40,43]])}))),function(){return v.apply(this,arguments)})},{key:"getCumulativeTinyPower",value:(I=i(s().mark((function e(t){var n,r,a,o,i,u,c,p,l=arguments;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=l.length>1&&void 0!==l[1]?l[1]:Math.floor(Date.now()/1e3),e.next=3,this.fetchAccountState();case 3:if(r=e.sent){e.next=6;break}return e.abrupt("return",0);case 6:return e.next=8,co(this.algodClient,this.userAddress,is[this.network],r.powerCount,t);case 8:if(a=e.sent,null!==(o=lo(a,n))){e.next=12;break}return e.abrupt("return",0);case 12:return i=a[o],u=n-i.timestamp,c=Ls(i.bias,i.slope,u),p=i.cumulativePower-c,e.abrupt("return",p);case 17:case"end":return e.stop()}}),e,this)}))),function(e){return I.apply(this,arguments)})},{key:"fetchVaultAppGlobalState",value:(x=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,Bs(this.algodClient,is[this.network]);case 3:return t=e.sent,e.abrupt("return",new Ys(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 x.apply(this,arguments)})},{key:"generateCreateLockTransactions",value:(A=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,no(this.algodClient,is[this.network],r);case 17:return l=e.sent,e.abrupt("return",yo({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 A.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",bo({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,no(this.algodClient,is[this.network],n);case 19:return p=e.sent,e.abrupt("return",To({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=bo({accountState:u,lockedAmount:n,network:this.network,sender:i,vaultAppGlobalState:c,suggestedParams:d}),u.powerCount+=1,c.totalPowerCount+=1,e.next=24,no(this.algodClient,is[this.network],r);case 24:return f=e.sent,l=To({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)?Us(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=ko({accountState:o,network:this.network,sender:a,suggestedParams:i,client:this.algodClient}),!n){e.next=17;break}return e.next=15,Y({client:this.algodClient,initiatorAddr:a,assetID:G[this.network]});case 15:c=e.sent,u=Us([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 Ks.apply(this,arguments)}(this.algodClient,is[this.network],this.userAddress)}},{key:"fetchStakingDistributionProposal",value:function(e){return function(e,t,n){return Jo.apply(this,arguments)}(this.algodClient,us[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;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.proposalId,r=t.votes,a=t.assetIds,o=t.userAddress,i=t.suggestedParams,u=null!=o?o:this.userAddress,c=i,e.next=5,this.fetchStakingDistributionProposal(n);case 5:if(p=e.sent){e.next=8;break}throw new Error("There was an error while fetching staking distribution proposal");case 8:if(c){e.next=12;break}return e.next=11,this.algodClient.getTransactionParams().do();case 11:c=e.sent;case 12:return e.next=14,this.fetchAccountState();case 14:return l=e.sent,e.next=17,js(this.algodClient,us[this.network]);case 17:return d=e.sent,e.next=20,co(this.algodClient,u,is[this.network],null==l?void 0:l.powerCount);case 20:if(f=e.sent,null!==(m=lo(f,p.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",Yo({stakingVotingAppId:us[this.network],vaultAppId:is[this.network],sender:u,proposalId:n,proposal:p,votes:r,assetIds:a,accountPowerIndex:m,appBoxNames:d,suggestedParams:c,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,Bs(this.algodClient,cs[this.network]);case 3:return n=t.sent,t.abrupt("return",new ti(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,A,x,I,v,w,y,b,T;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(n=t.periodIndexStart,r=t.periodCount,a=t.userAddress,o=t.suggestedParams,i=t.shouldOptIntoTINY,u=null!=a?a:this.userAddress,c=o){e.next=7;break}return e.next=6,this.algodClient.getTransactionParams().do();case 6:c=e.sent;case 7:return e.next=9,this.fetchAccountState();case 9:return p=e.sent,e.next=12,this.fetchRewardsAppGlobalState();case 12:if(l=e.sent){e.next=15;break}throw new Error("There was an error while fetching rewards app global state");case 15:if(!(n+r>l.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,co(this.algodClient,u,is[this.network],null==p?void 0:p.powerCount);case 19:for(d=e.sent,f=l.firstPeriodTimestamp+n*os,m=l.firstPeriodTimestamp+(n+r)*os,h=[],g=f;g=Math.floor(Date.now()/1e3)||c.votingEndTimestamp<=Math.floor(Date.now()/1e3))){e.next=23;break}throw new Error("Voting period is not active");case 23:return e.next=25,co(this.algodClient,i,is[this.network],p.powerCount);case 25:if(l=e.sent,null!==(d=lo(l,c.creationTimestamp))){e.next=29;break}throw new Error("Account power index not found");case 29:return f=Math.floor(c.index/(8*Bo)),m=Wo(i,f),e.next=33,Ds(this.algodClient,ps[this.network],m);case 33:return h=!e.sent,e.abrupt("return",ui({proposalVotingAppId:ps[this.network],vaultAppId:is[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,Bs(this.algodClient,ps[this.network]);case 2:return t=e.sent,e.abrupt("return",new Vo(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(){var t,n,r;return s().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.fetchProposalVotingAppGlobalState();case 2:if(t=e.sent,n=t.proposalThreshold,!t.proposalThresholdNumerator){e.next=9;break}return e.next=7,this.getTotalTinyPower();case 7:r=e.sent,n=Math.max(n,Math.floor(r*t.proposalThresholdNumerator/100)+1);case 9:return e.abrupt("return",n);case 10:case"end":return e.stop()}}),e,this)}))),function(){return n.apply(this,arguments)})}]),t}();exports.ALGO_ASSET=V,exports.ALGO_ASSET_ID=j,exports.ASSET_OPT_IN_PROCESS_TXN_COUNT=1,exports.AccountState=Qs,exports.AddLiquidity=er,exports.BASE_MINIMUM_BALANCE=S,exports.Bootstrap=_n,exports.CONTRACT_VERSION=U,exports.LendingPool=la,exports.MINIMUM_ADD_LIQUIDITY_AMOUNT=F,exports.MINIMUM_BALANCE_REQUIRED_PER_APP=O,exports.MINIMUM_BALANCE_REQUIRED_PER_ASSET=D,exports.MINIMUM_BALANCE_REQUIRED_PER_BYTE_SCHEMA=B,exports.MINIMUM_BALANCE_REQUIRED_PER_INT_SCHEMA_VALUE=C,exports.OPT_IN_VALIDATOR_APP_PROCESS_TXN_COUNT=1,exports.OPT_OUT_VALIDATOR_APP_PROCESS_TXN_COUNT=1,exports.POOL_TOKEN_UNIT_NAME=X,exports.PoolStatus=Nt,exports.ProposalVote=Ro,exports.REDEEM_PROCESS_TXN_COUNT=3,exports.RemoveLiquidity=Pr,exports.Swap=Wr,exports.SwapQuoteError=E,exports.SwapQuoteErrorType=_,exports.SwapQuoteType=tt,exports.SwapType=Ne,exports.TINY_ASSET_ID=G,exports.TinymanGovernanceClient=ci,exports.V1_1AddLiquidityTxnIndices=En,exports.V1_1_ADD_LIQUIDITY_PROCESS_TXN_COUNT=5,exports.V1_1_REMOVE_LIQUIDITY_TXN_COUNT=nr,exports.V2AddLiquidityTxnIndices=Dn,exports.V2AddLiquidityType=Sn,exports.V2_REMOVE_LIQUIDITY_APP_CALL_INNER_TXN_COUNT=rr,exports.applySlippageToAmount=de,exports.calculateAccountMinimumRequiredBalance=_t,exports.calculatePriceImpact=ut,exports.calculateSwapRate=it,exports.calculateTinyPower=function(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:Math.floor(Date.now()/1e3),a=(n=e,Math.floor(n*gs/ms)),s=t-r;return s<0?0:Ns(a,s)},exports.combineAndRegroupSignerTxns=function(){for(var t=arguments.length,n=new Array(t),r=0;r=e.minimum_required_balance},exports.intToBytes=Xs,exports.isAccountOptedIntoApp=function(e){var t=e.appID;return e.accountAppsLocalState.some((function(e){return e.id===t}))},exports.isSwapAssetInAmountLow=st,exports.isSwapQuoteErrorCausedByAmount=mt,exports.poolUtils=Kt,exports.prepareCommitTransactions=function(e){return fa.apply(this,arguments)},exports.redeemAllExcessAsset=function(e){return Kr.apply(this,arguments)},exports.redeemExcessAsset=function(e){return zr.apply(this,arguments)},exports.sendAndWaitRawTransaction=Ae,exports.sumUpTxnFees=Ie,exports.tinymanContract_v1_1=It,exports.tinymanContract_v2=yt,exports.tinymanJSSDKConfig=Te; diff --git a/dist/swap/types.d.ts b/dist/swap/types.d.ts index 94143b80..f4bb3fc2 100644 --- a/dist/swap/types.d.ts +++ b/dist/swap/types.d.ts @@ -104,6 +104,7 @@ export interface GenerateSwapTxnsParams { swapType: SwapType; slippage: number; initiatorAddr: string; + appCallNoteExtraData?: Record; } export type GenerateV1_1SwapTxnsParams = Omit & { quoteAndPool: DirectSwapQuoteAndPool; diff --git a/src/config.ts b/src/config.ts index f0839beb..de47aaa8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -21,11 +21,16 @@ class TinymanJSSDKConfig { /** * @returns {Uint8Array} - encoded note includings version with client name */ - getAppCallTxnNoteWithClientName(contractVersion: ContractVersionValue): Uint8Array { + getAppCallTxnNoteWithClientName( + contractVersion: ContractVersionValue, + extraData?: Record + ): Uint8Array { const versionMarker = contractVersion === CONTRACT_VERSION.V1_1 ? "v1" : contractVersion; - return encodeString(`tinyman/${versionMarker}:j{"origin":"${this.clientName}"}`); + let data = JSON.stringify({origin: this.clientName, ...extraData}); + + return encodeString(`tinyman/${versionMarker}:j${data}`); } } diff --git a/src/swap/types.ts b/src/swap/types.ts index 79d60e5f..a1ff193a 100644 --- a/src/swap/types.ts +++ b/src/swap/types.ts @@ -117,6 +117,7 @@ export interface GenerateSwapTxnsParams { swapType: SwapType; slippage: number; initiatorAddr: string; + appCallNoteExtraData?: Record; } export type GenerateV1_1SwapTxnsParams = Omit< diff --git a/src/swap/v2/index.ts b/src/swap/v2/index.ts index 423aec77..f67a08fd 100644 --- a/src/swap/v2/index.ts +++ b/src/swap/v2/index.ts @@ -107,7 +107,10 @@ async function generateTxns( V2_SWAP_APP_CALL_SWAP_TYPE_ARGS_ENCODED[swapType], algosdk.encodeUint64(assetOutAmount) ], - note: tinymanJSSDKConfig.getAppCallTxnNoteWithClientName(CONTRACT_VERSION.V2), + note: tinymanJSSDKConfig.getAppCallTxnNoteWithClientName( + CONTRACT_VERSION.V2, + params.appCallNoteExtraData + ), accounts: [poolAddress], foreignAssets: [pool.asset1ID, pool.asset2ID], suggestedParams From 78f3b4e52e84deaf0d24086d5b8407247fa4ffa6 Mon Sep 17 00:00:00 2001 From: gulcinuras Date: Fri, 30 Aug 2024 14:57:04 +0200 Subject: [PATCH 2/3] Bump up the app version --- 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 719d4e1e..5bd598ae 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tinymanorg/tinyman-js-sdk", - "version": "4.0.4", + "version": "4.0.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@tinymanorg/tinyman-js-sdk", - "version": "4.0.4", + "version": "4.0.5", "license": "MIT", "dependencies": { "algosdk": "^2.8.0", diff --git a/package.json b/package.json index 9b8896a9..0440a6ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tinymanorg/tinyman-js-sdk", - "version": "4.0.4", + "version": "4.0.5", "description": "Tinyman JS SDK", "author": "Tinyman Core Team", "license": "MIT", From 5e1fd04eb92966450e3d3e104e35b8a0c018730d Mon Sep 17 00:00:00 2001 From: gulcinuras Date: Fri, 30 Aug 2024 14:59:53 +0200 Subject: [PATCH 3/3] fix(get-app-call-note): Use const instead of let --- src/config.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index de47aaa8..bfd2d52b 100644 --- a/src/config.ts +++ b/src/config.ts @@ -27,8 +27,7 @@ class TinymanJSSDKConfig { ): Uint8Array { const versionMarker = contractVersion === CONTRACT_VERSION.V1_1 ? "v1" : contractVersion; - - let data = JSON.stringify({origin: this.clientName, ...extraData}); + const data = JSON.stringify({origin: this.clientName, ...extraData}); return encodeString(`tinyman/${versionMarker}:j${data}`); }