@msafe/sui-app-store 0.0.225 → 0.0.227
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Yl=Object.create;var Oe=Object.defineProperty;var Xl=Object.getOwnPropertyDescriptor;var Zl=Object.getOwnPropertyNames;var td=Object.getPrototypeOf,ed=Object.prototype.hasOwnProperty;var tr=(o,e)=>{for(var t in e)Oe(o,t,{get:e[t],enumerable:!0})},Qr=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Zl(e))!ed.call(o,a)&&a!==t&&Oe(o,a,{get:()=>e[a],enumerable:!(n=Xl(e,a))||n.enumerable});return o};var q=(o,e,t)=>(t=o!=null?Yl(td(o)):{},Qr(e||!o||!o.__esModule?Oe(t,"default",{value:o,enumerable:!0}):t,o)),nd=o=>Qr(Oe({},"__esModule",{value:!0}),o);var iu={};tr(iu,{appHelpers:()=>ru});module.exports=nd(iu);var ei=require("@msafe/sui3-utils");var z=require("@alphafi/alphafi-sdk"),At=require("@msafe/sui3-utils"),K=require("@mysten/bcs");var Pe=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isClaimRewardTransaction())return this.decodeClaimReward();let e=this.getLiquidityChangeEvent();if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson,n=t.pool_id,a=z.poolIdPoolNameMap[n];if(console.log("Decoder event data - ",t),console.log("Decoder poolName - ",a),this.isWithdrawAlphaEvent(e))return this.decodeWithdrawAlpha(t);if(this.isWithdrawEvent(t))return this.decodeWithdraw(a);if(this.isDoubleAssetDepositEvent(t,a))return this.decodeDoubleAssetDeposit(a,t);if(this.isSingleAssetDepositEvent(t,a))return this.decodeSingleAssetDeposit(a,t);throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getLiquidityChangeEvent(){return this.simResult.events.find(e=>this.isLiquidityChangeEventType(e.type))}isClaimRewardTransaction(){return!!this.getMoveCallCommand("get_user_rewards_all")}isLiquidityChangeEventType(e){return e.includes("LiquidityChangeEvent")||e.includes("LiquidityChangeNewNewEvent")||e.includes("WithdrawEventV2")}isWithdrawAlphaEvent(e){return e.type.includes("WithdrawEventV2")}isWithdrawEvent(e){return e.event_type===1}isDoubleAssetDepositEvent(e,t){return e.event_type===0&&z.poolInfo[t].assetTypes.length===2}isSingleAssetDepositEvent(e,t){return e.event_type===0&&z.poolInfo[t].assetTypes.length===1}extractXTokensAmount(){let e=this.inputs.find(a=>a.Pure!==void 0);if(!e||!e.Pure?.bytes)throw new Error("Unable to extract xTokensAmount from inputs");let{bytes:t}=e.Pure,n;return t.length===12?n=K.bcs.u64().parse((0,K.fromBase64)(t)):t.length===24?n=K.bcs.u128().parse((0,K.fromBase64)(t)):t.length===44?n=K.bcs.u256().parse((0,K.fromBase64)(t)):n=K.bcs.u64().parse((0,K.fromBase64)(t)),n}decodeDoubleAssetDeposit(e,t){let{amount_a:n,amount_b:a}=t,r=Number(n)>0;return console.log("Decoder.decodeDoubleAssetDeposit",n,a,r),{txType:At.TransactionType.Other,type:"depositDoubleAsset",intentionData:{poolName:e,amount:r?n:a,isAmountA:r}}}decodeSingleAssetDeposit(e,t){let{amount:n}=t;if(console.log("Decoder.decodeSingleAssetDeposit",n),this.getLiquidityChangeEvent().type.includes(":alphafi_navi_pool:")){let{coin:r}=z.singleAssetPoolCoinMap[e],{expo:i}=z.coinsList[r];n=Math.floor(Number(n)/10**(9-i)).toString()}return{txType:At.TransactionType.Other,type:"depositSingleAsset",intentionData:{poolName:e,amount:n}}}decodeWithdraw(e){let t=this.extractXTokensAmount();return console.log("Decoder.decodeWithdraw",t),{txType:At.TransactionType.Other,type:"withdraw",intentionData:{poolName:e,xTokensAmount:t}}}decodeWithdrawAlpha(e){let t=this.extractXTokensAmount(),{amount_withdrawn_from_locked:n}=e;return console.log("Decoder.decodeWithdrawAlpha",t,n),{txType:At.TransactionType.Other,type:"withdrawAlpha",intentionData:{withdrawFromLocked:Number(n)>0,xTokensAmount:t}}}decodeClaimReward(){return{txType:At.TransactionType.Other,type:"claimReward",intentionData:{}}}};var Jr=require("@alphafi/alphafi-sdk");var zr=q(require("sort-keys-recursive")),u=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,zr.default)(this.data))}};var Re=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t;return await(0,Jr.claimRewardTxb)(n.address)}static fromData(t){return new o(t)}};var Yr=require("@alphafi/alphafi-sdk");var Be=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:a,amount:r,isAmountA:i}=this.data;return await(0,Yr.depositDoubleAssetTxb)(a,n.address,r,i)}static fromData(t){return console.log("DepositDoubleAssetIntention.fromData",t),new o(t)}};var Xr=require("@alphafi/alphafi-sdk");var _e=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:a,amount:r}=this.data;return await(0,Xr.depositSingleAssetTxb)(a,n.address,r)}static fromData(t){return console.log("DepositSingleAssetIntention.fromData",t),new o(t)}};var Zr=require("@alphafi/alphafi-sdk");var Ee=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:a,xTokensAmount:r}=this.data;return await(0,Zr.withdrawTxb)(r,a,n.address)}static fromData(t){return console.log("WithdrawIntention.fromData",t),new o(t)}};var ti=require("@alphafi/alphafi-sdk");var Me=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{withdrawFromLocked:a,xTokensAmount:r}=this.data;return await(0,ti.withdrawAlphaTxb)(r,a,n.address)}static fromData(t){return console.log("WithdrawAlphaIntention.fromData",t),new o(t)}};var We=class{application="alphafi";supportSDK="@mysten/sui";async deserialize(e){let{transaction:t,suiClient:n,account:a}=e,r=await n.devInspectTransactionBlock({sender:t.getData().sender,transactionBlock:t});console.log("AlphaFiHelper Sim result - ",r);let s=new Pe(t,r).decode();return{txType:ei.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{account:t}=e;console.log("AlphaFi build transaction type",e.txSubType);let n;switch(e.txSubType){case"depositSingleAsset":n=_e.fromData(e.intentionData);break;case"depositDoubleAsset":n=Be.fromData(e.intentionData);break;case"withdraw":n=Ee.fromData(e.intentionData);break;case"withdrawAlpha":n=Me.fromData(e.intentionData);break;case"claimReward":n=Re.fromData(e.intentionData);break;default:throw new Error("not implemented")}return n.build({account:t})}};var Di=require("@msafe/sui3-utils");var P=require("@msafe/sui3-utils"),Ne=require("@mysten/sui/bcs"),Le=require("bucket-protocol-sdk");var je=class{constructor(e){this.transaction=e}decode(){if(this.isSBUCKDepositTransaction())return this.decodeSBUCKDeposit();if(this.isSBUCKUnstakeTransaction())return this.decodeSBUCKUnstake();if(this.isSBUCKWithdrawTransaction())return this.decodeSBUCKWithdraw();if(this.isSBUCKClaimTransaction())return this.decodeSBUCKClaim();if(this.isLockedClaimTransaction())return this.decodeLockedClaim();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayTransaction())return this.decodeRepay();if(this.isWithdrawTransaction())return this.decodeWithdraw();if(this.isCloseTransaction())return this.decodeClose();if(this.isTankDepositTransaction())return this.decodeTankDeposit();if(this.isTankWithdrawTransaction())return this.decodeTankWithdraw();if(this.isTankClaimTransaction())return this.decodeTankClaim();if(this.isPsmTransaction())return this.decodePsm();throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getMoveCallModuleCommand(e,t){return this.commands.find(n=>n.$kind==="MoveCall"&&n.MoveCall.module===e&&n.MoveCall.function===t)}getMoveCallPackageModuleCommand(e,t,n){return this.commands.find(a=>a.$kind==="MoveCall"&&a.MoveCall.package===e&&a.MoveCall.module===t&&a.MoveCall.function===n)}getMoveCallModuleCommands(e,t){return this.commands.filter(n=>n.$kind==="MoveCall"&&n.MoveCall.module===e&&n.MoveCall.function===t)}getSplitCoinsCommands(){return this.commands.filter(e=>e.$kind==="SplitCoins")}getTransferCommands(){return this.commands.filter(e=>e.$kind==="TransferObjects")}isPsmTransaction(){return!!this.getMoveCallCommand("charge_reservoir")||!!this.getMoveCallCommand("discharge_reservoir")}isStrapNewTransaction(){return!!this.getMoveCallModuleCommand("strap","new")}isBorrowTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","high_top_up")||!!this.getMoveCallModuleCommand("bucket_operations","high_borrow")||!!this.getMoveCallModuleCommand("bucket_operations","high_borrow_with_strap")}isRepayTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","fully_repay")||!!this.getMoveCallModuleCommand("bucket_operations","fully_repay_with_strap")||!!this.getMoveCallModuleCommand("bucket_operations","repay_and_withdraw")||!!this.getMoveCallModuleCommand("bucket_operations","repay_and_withdraw_with_strap")}isWithdrawTransaction(){return!!this.getMoveCallModuleCommand("buck","withdraw")||!!this.getMoveCallModuleCommand("buck","withdraw_with_strap")}isCloseTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","destroy_empty_strap")}isTankDepositTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","deposit")}isTankWithdrawTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","withdraw")}isTankClaimTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","claim")}isSBUCKDepositTransaction(){return!!this.getMoveCallModuleCommand("buck","buck_to_sbuck")}isSBUCKWithdrawTransaction(){return!!this.getMoveCallModuleCommand("buck","sbuck_to_buck")}isSBUCKStakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Le.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","stake")}isSBUCKUnstakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Le.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","force_unstake")}isSBUCKClaimTransaction(){return!!this.getMoveCallPackageModuleCommand(Le.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","claim")}isLockedClaimTransaction(){return!!this.getMoveCallModuleCommand("proof_rule","claim")||!!this.getMoveCallModuleCommand("lst_proof_rule","claim")}isLstUnlockTransaction(){return!!this.getMoveCallModuleCommand("lst_proof_rule","unlock")}decodePsm(){let e,t,n="0",a=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];return a.$kind==="Input"&&(n=this.getPureInputU64(a.Input)),this.getMoveCallCommand("charge_reservoir")?([e]=this.getMoveCallCommand("charge_reservoir").MoveCall.typeArguments,t=!1):([e]=this.getMoveCallCommand("discharge_reservoir").MoveCall.typeArguments,t=!0),console.log("Decoder.decodePsm",e,n,t),{txType:P.TransactionType.Other,type:"psm",intentionData:{coinType:e,amount:n,buckToCoin:t}}}decodeBorrow(){let e="",t="0",n,a=this.getStrapId(),r="0",i=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];if(i.$kind==="Input"&&(r=this.getPureInputU64(i.Input)),this.getMoveCallCommand("high_top_up")){let s=this.getMoveCallCommand("high_top_up").MoveCall;[e]=s.typeArguments;let c=s.arguments[1];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let l=s.arguments[3];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}else if(this.getMoveCallCommand("high_borrow")){let s=this.getMoveCallCommand("high_borrow").MoveCall;[e]=s.typeArguments;let c=s.arguments[4];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let l=s.arguments[5];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}else if(this.getMoveCallCommand("high_borrow_with_strap")){let s=this.getMoveCallCommand("high_borrow_with_strap").MoveCall;[e]=s.typeArguments;let c=s.arguments[5];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let l=s.arguments[6];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}return{txType:P.TransactionType.Other,type:"borrow",intentionData:{collateralType:e,collateralAmount:r,borrowAmount:t,insertionPlace:n,strapId:a}}}decodeRepay(){let e="",t="0",n="0",r,i=this.getStrapId();if(this.getMoveCallCommand("fully_repay"))[e]=this.getMoveCallCommand("fully_repay").MoveCall.typeArguments;else if(this.getMoveCallCommand("fully_repay_with_strap"))[e]=this.getMoveCallCommand("fully_repay_with_strap").MoveCall.typeArguments;else if(this.getMoveCallCommand("repay_and_withdraw")){let s=this.getMoveCallCommand("repay_and_withdraw").MoveCall;[e]=s.typeArguments;let c=s.arguments[4];c.$kind==="Input"&&(n=this.getPureInputU64(c.Input));let l=s.arguments[5];if(l.$kind==="Input"){let m=this.getPureAddresses(l.Input);m.length===1&&([r]=m)}let d=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input))}else if(this.getMoveCallCommand("repay_and_withdraw_with_strap")){let s=this.getMoveCallCommand("repay_and_withdraw_with_strap").MoveCall;[e]=s.typeArguments;let c=s.arguments[5];c.$kind==="Input"&&(n=this.getPureInputU64(c.Input));let l=s.arguments[6];if(l.$kind==="Input"){let m=this.getPureAddresses(l.Input);m.length===1&&([r]=m)}let d=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input))}return{txType:P.TransactionType.Other,type:"repay",intentionData:{collateralType:e,repayAmount:t,withdrawAmount:n,isSurplus:!1,insertionPlace:r,strapId:i}}}decodeWithdraw(){let e="",t="0",n,a=this.getStrapId();if(this.getMoveCallCommand("withdraw_with_strap")){let r=this.getMoveCallCommand("withdraw_with_strap").MoveCall;[e]=r.typeArguments;let i=r.arguments[4];i.$kind==="Input"&&(t=this.getPureInputU64(i.Input));let s=r.arguments[5];if(s.$kind==="Input"){let c=this.getPureAddresses(s.Input);c.length===1&&([n]=c)}}else if(this.getMoveCallCommand("withdraw")){let r=this.getMoveCallCommand("withdraw").MoveCall;[e]=r.typeArguments;let i=r.arguments[3];i.$kind==="Input"&&(t=this.getPureInputU64(i.Input));let s=r.arguments[4];if(s.$kind==="Input"){let c=this.getPureAddresses(s.Input);c.length===1&&([n]=c)}}return{txType:P.TransactionType.Other,type:"withdraw",intentionData:{collateralType:e,withdrawAmount:t,insertionPlace:n,strapId:a}}}decodeClose(){let e="",t=this.getStrapId();return this.getMoveCallCommand("destroy_empty_strap")&&([e]=this.getMoveCallCommand("destroy_empty_strap").MoveCall.typeArguments),{txType:P.TransactionType.Other,type:"close",intentionData:{collateralType:e,strapId:t}}}decodeSBUCKDeposit(){let t=this.getMoveCallCommand("into_balance").MoveCall.typeArguments[0],n="0",r=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];r.$kind==="Input"&&(n=this.getPureInputU64(r.Input));let i=this.isSBUCKStakeTransaction();return console.log("Decoder.decodeSBUCKDeposit",t,n,i),{txType:P.TransactionType.Other,type:"sbuck-deposit",intentionData:{coinType:t,amount:n,isStake:i}}}decodeSBUCKUnstake(){let e="0",t=this.isSBUCKStakeTransaction();if(t){let c=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];c.$kind==="Input"&&(e=this.getPureInputU64(c.Input))}let n=[],a=this.getMoveCallModuleCommands("proof_rule","unlock");if(a.length>0)for(let s=0;s<a.length;s++){let c=a[s];n.push("")}else{let s=this.getMoveCallModuleCommands("fountain_core","force_unstake");for(let c=0;c<s.length;c++){let d=s[c].MoveCall.arguments[2];if(d.$kind==="Input"){let{objectId:m}=this.inputs[d.Input].UnresolvedObject;n.push(m)}}}let r=this.isSBUCKWithdrawTransaction(),i={stakeProofs:n,amount:e,isStake:t,toBuck:r};return console.log("Decoder.decodeSBUCKUnstake",i),{txType:P.TransactionType.Other,type:"sbuck-unstake",intentionData:i}}decodeSBUCKWithdraw(){let e="0",n=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];return n.$kind==="Input"&&(e=this.getPureInputU64(n.Input)),console.log("Decoder.SBUCKWithdraw",e),{txType:P.TransactionType.Other,type:"sbuck-withdraw",intentionData:{amount:e}}}decodeSBUCKClaim(){let e=[],t=this.getMoveCallModuleCommands("fountain_core","claim");for(let n=0;n<t.length;n++){let r=t[n].MoveCall.arguments[2];if(r.$kind==="Input"){let{objectId:i}=this.inputs[r.Input].UnresolvedObject;e.push(i)}}return console.log("Decoder.decodeSBUCKClaim",e),{txType:P.TransactionType.Other,type:"sbuck-claim",intentionData:{stakeProofs:e}}}decodeTankDeposit(){let e="0",n=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];n.$kind==="Input"&&(e=this.getPureInputU64(n.Input));let r=this.getMoveCallModuleCommand("tank_operations","deposit").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankDeposit",r,e),{txType:P.TransactionType.Other,type:"tank-deposit",intentionData:{coinType:r,amount:e}}}decodeTankWithdraw(){let e=this.getMoveCallModuleCommand("tank_operations","withdraw").MoveCall,t=e.typeArguments[0],n="0",a=e.arguments[5];return a.$kind==="Input"&&(n=this.getPureInputU64(a.Input)),console.log("Decoder.decodeTankWithdraw",t,n),{txType:P.TransactionType.Other,type:"tank-withdraw",intentionData:{coinType:t,amount:n}}}decodeTankClaim(){let t=this.getMoveCallModuleCommand("tank_operations","claim").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankClaim",t),{txType:P.TransactionType.Other,type:"tank-claim",intentionData:{coinType:t}}}decodeLockedClaim(){let e="",t=0,n=this.getMoveCallModuleCommands("proof_rule","claim");for(let r=0;r<n.length;r++)[e]=n[r].MoveCall.typeArguments,t++;let a=this.getMoveCallModuleCommands("lst_proof_rule","claim");for(let r=0;r<a.length;r++)[e]=a[r].MoveCall.typeArguments,t++;return console.log("Decoder.decodeLockedClaim",e,t),{txType:P.TransactionType.Other,type:"lock-claim",intentionData:{coinType:e,proofCount:t}}}getCoinInput(e){if(this.inputs[e].$kind!=="Object")throw new Error("not Object argument")}getStrapId(){let e;if(this.isStrapNewTransaction()?e="new":this.isLstUnlockTransaction()&&(e="locked"),!e){let t=this.getMoveCallModuleCommand("fountain","unstake");if(t){let n=t.MoveCall.arguments[2];n.$kind==="Input"&&(e=this.inputs[n.Input].UnresolvedObject.objectId)}}return e}getPureInputU64(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return Ne.bcs.U64.fromBase64(t.Pure.bytes)}getPureAddresses(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return Ne.bcs.vector(Ne.bcs.Address).fromBase64(t.Pure.bytes)}};var ii=require("@msafe/sui3-utils");var ai=require("@mysten/sui/transactions"),oi=require("bucket-protocol-sdk");var ni=require("bucket-protocol-sdk"),D=(o,e)=>{let t=o==="sui:mainnet"?"mainnet":"testnet";return new ni.BucketClient(t,e.address)};var ri=async(o,e,t)=>{let{coinType:n,amount:a,buckToCoin:r}=o,i=new ai.Transaction,s=D(t,e);return await(0,oi.buildPsmTx)(s,i,n,a,r,e.address),i};var Ue=class o extends u{constructor(t){super(t);this.data=t}txType=ii.TransactionType.Other;txSubType="psm";async build(t){let{account:n,network:a}=t;return await ri(this.data,n,a)}static fromData(t){return new o(t)}};var ui=require("@msafe/sui3-utils");var Xt=require("@mysten/sui/transactions"),Z=require("bucket-protocol-sdk");var si=async(o,e,t)=>{let{collateralType:n,collateralAmount:a,borrowAmount:r,insertionPlace:i,strapId:s}=o,c=new Xt.Transaction,l=D(t,e);return await(0,Z.buildBorrowTx)(l,c,n,a,r,e.address,i,s),c},ci=async(o,e,t)=>{let{collateralType:n,withdrawAmount:a,insertionPlace:r,strapId:i}=o,s=new Xt.Transaction,c=D(t,e);return await(0,Z.buildWithdrawTx)(c,s,n,a,e.address,r,i),s},li=async(o,e,t)=>{let{collateralType:n,repayAmount:a,withdrawAmount:r,isSurplus:i,insertionPlace:s,strapId:c}=o,l=new Xt.Transaction,d=D(t,e);return await(0,Z.buildRepayTx)(d,l,n,a,r,e.address,i,s,c),l},di=async(o,e,t)=>{let{collateralType:n,recipient:a,strapId:r}=o,i=new Xt.Transaction,s=D(t,e);return await(0,Z.buildCloseTx)(s,i,n,a,r),i};var Fe=class o extends u{constructor(t){super(t);this.data=t}txType=ui.TransactionType.Other;txSubType="borrow";async build(t){let{account:n,network:a}=t;return await si(this.data,n,a)}static fromData(t){return new o(t)}};var mi=require("@msafe/sui3-utils");var qe=class o extends u{constructor(t){super(t);this.data=t}txType=mi.TransactionType.Other;txSubType="repay";async build(t){let{account:n,network:a}=t;return await li(this.data,n,a)}static fromData(t){return new o(t)}};var pi=require("@msafe/sui3-utils");var Ke=class o extends u{constructor(t){super(t);this.data=t}txType=pi.TransactionType.Other;txSubType="withdraw";async build(t){let{account:n,network:a}=t;return await ci(this.data,n,a)}static fromData(t){return new o(t)}};var fi=require("@msafe/sui3-utils");var $e=class o extends u{constructor(t){super(t);this.data=t}txType=fi.TransactionType.Other;txSubType="close";async build(t){let{account:n,network:a}=t;return await di(this.data,n,a)}static fromData(t){return new o(t)}};var te=require("@msafe/sui3-utils");var Zt=require("@mysten/sui/transactions"),tt=require("bucket-protocol-sdk");var bi=async(o,e,t)=>{let{coinType:n,amount:a,isStake:r}=o,i=new Zt.Transaction,s=D(t,e);return await(0,tt.buildSBUCKDepositTx)(s,i,n,a,e.address,r),i},hi=async(o,e,t)=>{let{stakeProofs:n,amount:a,isStake:r,toBuck:i}=o,s=new Zt.Transaction,c=D(t,e);return await(0,tt.buildSBUCKUnstakeTx)(c,s,n,a,e.address,r,i),s},gi=async(o,e,t)=>{let{amount:n}=o,a=new Zt.Transaction,r=D(t,e);return await(0,tt.buildSBUCKWithdrawTx)(r,a,n,e.address),a},yi=async(o,e,t)=>{let{stakeProofs:n}=o,a=new Zt.Transaction,r=D(t,e);return await(0,tt.buildSBUCKClaimTx)(r,a,n,e.address),a};var Ve=class o extends u{constructor(t){super(t);this.data=t}txType=te.TransactionType.Other;txSubType="sbuck-deposit";async build(t){let{account:n,network:a}=t;return await bi(this.data,n,a)}static fromData(t){return new o(t)}},He=class o extends u{constructor(t){super(t);this.data=t}txType=te.TransactionType.Other;txSubType="sbuck-unstake";async build(t){let{account:n,network:a}=t;return await hi(this.data,n,a)}static fromData(t){return new o(t)}},Ge=class o extends u{constructor(t){super(t);this.data=t}txType=te.TransactionType.Other;txSubType="sbuck-withdraw";async build(t){let{account:n,network:a}=t;return await gi(this.data,n,a)}static fromData(t){return new o(t)}},Qe=class o extends u{constructor(t){super(t);this.data=t}txType=te.TransactionType.Other;txSubType="sbuck-claim";async build(t){let{account:n,network:a}=t;return await yi(this.data,n,a)}static fromData(t){return new o(t)}};var Ze=require("@msafe/sui3-utils");var ze=require("@mysten/sui/transactions"),Ot=require("bucket-protocol-sdk");var Ti=async(o,e,t)=>{let{coinType:n,amount:a}=o,r=new ze.Transaction,i=D(t,e);return await(0,Ot.buildTankDepositTx)(i,r,n,a,e.address),r},Ci=async(o,e,t)=>{let{coinType:n,amount:a}=o,r=new ze.Transaction,i=D(t,e);return await(0,Ot.buildTankWithdrawTx)(i,r,n,a,e.address),r},Ii=async(o,e,t)=>{let{coinType:n}=o,a=new ze.Transaction,r=D(t,e);return await(0,Ot.buildTankClaimTx)(r,a,n,e.address),a};var Si=require("@mysten/sui/transactions"),wi=require("bucket-protocol-sdk");var ki=async(o,e,t)=>{let{coinType:n,proofCount:a}=o,r=new Si.Transaction,i=D(t,e);return await(0,wi.buildLockedClaimTx)(i,r,n,a,e.address),r};var Je=class o extends u{constructor(t){super(t);this.data=t}txType=Ze.TransactionType.Other;txSubType="tank-deposit";async build(t){let{account:n,network:a}=t;return await Ti(this.data,n,a)}static fromData(t){return new o(t)}},Ye=class o extends u{constructor(t){super(t);this.data=t}txType=Ze.TransactionType.Other;txSubType="tank-withdraw";async build(t){let{account:n,network:a}=t;return await Ci(this.data,n,a)}static fromData(t){return new o(t)}},Xe=class o extends u{constructor(t){super(t);this.data=t}txType=Ze.TransactionType.Other;txSubType="tank-claim";async build(t){let{account:n,network:a}=t;return await Ii(this.data,n,a)}static fromData(t){return new o(t)}};var xi=require("@msafe/sui3-utils");var tn=class o extends u{constructor(t){super(t);this.data=t}txType=xi.TransactionType.Other;txSubType="lock-claim";async build(t){let{account:n,network:a}=t;return await ki(this.data,n,a)}static fromData(t){return new o(t)}};var en=class{application="bucket";supportSDK="@mysten/sui";async deserialize(e){console.log("Bucket helper deserialize input: ",e);let{transaction:t}=e,a=new je(t).decode();return{txType:Di.TransactionType.Other,txSubType:a.type,intentionData:a.intentionData}}async build(e){let{suiClient:t,account:n,network:a}=e,r;switch(e.txSubType){case"psm":r=Ue.fromData(e.intentionData);break;case"borrow":r=Fe.fromData(e.intentionData);break;case"withdraw":r=Ke.fromData(e.intentionData);break;case"repay":r=qe.fromData(e.intentionData);break;case"close":r=$e.fromData(e.intentionData);break;case"tank-deposit":r=Je.fromData(e.intentionData);break;case"tank-withdraw":r=Ye.fromData(e.intentionData);break;case"tank-claim":r=Xe.fromData(e.intentionData);break;case"sbuck-deposit":r=Ve.fromData(e.intentionData);break;case"sbuck-unstake":r=He.fromData(e.intentionData);break;case"sbuck-withdraw":r=Ge.fromData(e.intentionData);break;case"sbuck-claim":r=Qe.fromData(e.intentionData);break;case"lock-claim":r=tn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:a})}};var As=require("@msafe/sui3-utils");var Ni=require("@msafe/sui3-utils");var ee=require("@cetusprotocol/aggregator-sdk"),vi=require("@cetusprotocol/cetus-periphery-sdk"),Ai=require("@cetusprotocol/cetus-sui-clmm-sdk"),Oi=require("@cetusprotocol/cetus-xcetus-sdk"),Pi=q(require("@cetusprotocol/vaults-sdk")),ne=require("@mysten/sui/client"),od={fullRpcUrl:(0,ne.getFullnodeUrl)("mainnet"),simulationAccount:{address:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"},cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",config:{coin_list_id:"0x8cbc11d9e10140db3d230f50b4d30e9b721201c0083615441707ffec1ef77b23",launchpad_pools_id:"0x1098fac992eab3a0ab7acf15bb654fc1cf29b5a6142c4ef1058e6c408dd15115",clmm_pools_id:"0x15b6a27dd9ae03eb455aba03b39e29aad74abd3757b8e18c0755651b2ae5b71e",admin_cap_id:"0x39d78781750e193ce35c45ff32c6c0c3f2941fa3ddaf8595c90c555589ddb113",global_config_id:"0x0408fa4e4a4c03cc0de8f23d0c2bbfe8913d178713c9a271ed4080973fe42d8f",coin_list_handle:"0x49136005e90e28c4695419ed4194cc240603f1ea8eb84e62275eaff088a71063",launchpad_pools_handle:"0x5e194a8efcf653830daf85a85b52e3ae8f65dc39481d54b2382acda25068375c",clmm_pools_handle:"0x37f60eb2d9d227949b95da8fea810db3c32d1e1fa8ed87434fc51664f87d83cb"}},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0xc6faf3703b0e8ba9ed06b7851134bbbe7565eb35ff823fd78432baa4cbeaa12e",version:4,config:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:""}},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0x2d8c2e0fc6dd25b0214b3fa747e0fd27fd54608142cd2e4f64c1cd350cc4add4",version:6},deepbook:{package_id:"0x000000000000000000000000000000000000000000000000000000000000dee9",published_at:"0x000000000000000000000000000000000000000000000000000000000000dee9"},deepbook_endpoint_v2:{package_id:"0x92aee86c01c79146d23938a00c7fff725ee0688c389be36d1bcbe03761b466c6",published_at:"0x92aee86c01c79146d23938a00c7fff725ee0688c389be36d1bcbe03761b466c6"},aggregatorUrl:"https://api-sui.cetus.zone/router",swapCountUrl:"https://api-sui.cetus.zone/v2/sui/swap/count"},rd={launchpad:{package_id:"0x80d114c5d474eabc2eb2fcd1a0903f1eb5b5096a8dc4184d72453f7a9be728e4",published_at:"0x80d114c5d474eabc2eb2fcd1a0903f1eb5b5096a8dc4184d72453f7a9be728e4",config:{pools_id:"0xfd8d37f7a1276878972d240302c8efe32f577220c1bbc6c8984d8b60dddfcab3",admin_cap_id:"0x66c70d58c69353714cc6fe2d3a62492d605a96a9821e2bd8274de17219c69980",config_cap_id:"0x02b8d23f033687579966e182c776fe0287cacdbb18bff56c29f141e29a18a4d1"}},ido:{package_id:"0x1192c9e20b4b0a8848a73a8c711b43e38f7ea1f307b556aab6ffab4e982e9c59",published_at:"0x1192c9e20b4b0a8848a73a8c711b43e38f7ea1f307b556aab6ffab4e982e9c59",config:{pools_id:"0xefc209b47acf1f23b29d166440904600229e520ad36228aaf2329b7c16be9762",admin_cap_id:"0x281859d366951830aeeda90779aa170d8ee6845875545470d33ecb890e78c8ce",package_version_id:"0xc93dc996106770af5f4e979b6808518f8cee080f22f35b936f071f59d834bb22"}},xcetus:{package_id:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",published_at:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",config:{xcetus_manager_id:"0x838b3dbade12b1e602efcaf8c8b818fae643e43176462bf14fd196afa59d1d9d",lock_manager_id:"0x288b59d9dedb51d0bb6cb5e13bfb30885ecf44f8c9076b6f5221c5ef6644fd28",lock_handle_id:"0x7c534bb7b8a2cc21538d0dbedd2437cc64f47106cb4c259b9ff921b5c3cb1a49"}},xcetus_dividends:{package_id:"0x785248249ac457dfd378bdc6d2fbbfec9d1daf65e9d728b820eb4888c8da2c10",published_at:"0x5aa58e1623885bd93de2331d05c29bf4930e54e56beeabcab8fe5385de2d31dc",config:{dividend_manager_id:"0x721c990bfc031d074341c6059a113a59c1febfbd2faeb62d49dcead8408fa6b5",dividend_admin_id:"0x682ba823134f156eac2bcfb27d85a284954a0e61998dc628c40b9bcb4a46ff30",dividend_settle_id:"0xade40abe9f6dd10b83b11085be18f07b63b681cf1c169b041fa16854403388c5",venft_dividends_id:"0x9dcdb97b4307684bedaeaf803d381b12321a31ecbb9dad7df2cd5f64384f9456",venft_dividends_id_v2:"0xaa21fbc1707786d56302952f8327362f4eb9a431a5bc574834e6d46125390de3"}},cetus_faucet:{package_id:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",published_at:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b"},xtoken:{package_id:"",published_at:"",config:{xtoken_manager_id:"",lock_manager_id:"",lock_handle_id:""}},xtoken_dividends:{package_id:"",published_at:"",config:{dividend_manager_id:"",dividend_admin_id:"",dividend_settle_id:""}},token_faucet:{package_id:"",published_at:""},booster:{package_id:"",published_at:"",config:{booster_config_id:"",booster_pool_handle:""}},maker_bonus:{package_id:"",published_at:"",config:{maker_config_id:"",maker_pool_handle:""}},liquidity_stratefy:{package_id:"",published_at:"",version:void 0,config:void 0},vaults:{package_id:"0xd3453d9be7e35efe222f78a810bb3af1859fd1600926afced8b4936d825c9a05",published_at:"0x58e5de6e425397eeaf952d55c0f94637bee91b25d6138ce222f89cda0aefec03",version:1,config:{admin_cap_id:"0x78a42978709c4032fab7b33b782b5bcef64c1c6603250bf23644650b72144375",vaults_manager_id:"0x25b82dd2f5ee486ed1c8af144b89a8931cd9c29dee3a86a1bfe194fdea9d04a6",vaults_pool_handle:"0x9036bcc5aa7fd2cceec1659a6a1082871f45bc400c743f50063363457d1738bd",haedal:{package_id:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",published_at:"0xaabf0856070391df81fad9240049d69c5a51c3d376cc0885eeedd516526cc79b",version:1,config:{staking_id:"0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",coin_type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"}},volo:{package_id:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",published_at:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",version:1,config:{native_pool:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",vsui_metadata:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",coin_type:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"}},aftermath:{package_id:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",published_at:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",version:1,config:{staked_sui_vault:"0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",referral_vault:"0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",safe:"0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",validator_address:"0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2",coin_type:"0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"}}}},limit_order:{package_id:"",published_at:"",version:1,config:{rate_orders_indexer_id:"",rate_orders_indexer_handle:"",global_config_id:"",token_list_handle:"",user_orders_indexer_id:"",user_orders_indexer_handle:""}},frams:{package_id:"0x11ea791d82b5742cc8cab0bf7946035c97d9001d7c3803a93f119753da66f526",published_at:"0x7e4ca066f06a1132ab0499c8c0b87f847a0d90684afa902e52501a44dbd81992",version:1,config:{global_config_id:"0x21215f2f6de04b57dd87d9be7bb4e15499aec935e36078e2488f36436d64996e",rewarder_manager_id:"0xe0e155a88c77025056da08db5b1701a91b79edb6167462f768e387c3ed6614d5",rewarder_manager_handle:"0xb32e312cbb3367d6f3d2b4e57c9225e903d29b7b9f612dae2ddf75bdeb26a5aa",admin_cap_id:"0xf10fbf1fea5b7aeaa524b87769461a28c5c977613046360093673991f26d886c"}},dca:{package_id:"",published_at:"",version:0,config:{admin_cap_id:"",global_config_id:"",indexer_id:"",user_indexer_id:"",in_coin_whitelist_id:"",out_coin_whitelist_id:""}}},id={fullRpcUrl:(0,ne.getFullnodeUrl)("mainnet"),simulationAccount:{address:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"},xcetus:{package_id:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",published_at:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",config:{xcetus_manager_id:"0x838b3dbade12b1e602efcaf8c8b818fae643e43176462bf14fd196afa59d1d9d",lock_manager_id:"0x288b59d9dedb51d0bb6cb5e13bfb30885ecf44f8c9076b6f5221c5ef6644fd28",lock_handle_id:"0x7c534bb7b8a2cc21538d0dbedd2437cc64f47106cb4c259b9ff921b5c3cb1a49"}},xcetus_dividends:{package_id:"0x785248249ac457dfd378bdc6d2fbbfec9d1daf65e9d728b820eb4888c8da2c10",published_at:"0x5aa58e1623885bd93de2331d05c29bf4930e54e56beeabcab8fe5385de2d31dc",version:4,config:{dividend_manager_id:"0x721c990bfc031d074341c6059a113a59c1febfbd2faeb62d49dcead8408fa6b5",dividend_admin_id:"0x682ba823134f156eac2bcfb27d85a284954a0e61998dc628c40b9bcb4a46ff30",dividend_settle_id:"0xade40abe9f6dd10b83b11085be18f07b63b681cf1c169b041fa16854403388c5",venft_dividends_id:"0x9dcdb97b4307684bedaeaf803d381b12321a31ecbb9dad7df2cd5f64384f9456",venft_dividends_id_v2:"0xaa21fbc1707786d56302952f8327362f4eb9a431a5bc574834e6d46125390de3"}},cetus_faucet:{package_id:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",published_at:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b"}},St=(o,e)=>{let t=od,n=new Ai.CetusClmmSDK(t);return n.senderAddress=e.address,n},$=(o,e)=>{let t=St(o,e),n=rd;return new vi.CetusPeripherySDK(n,t)},sd="https://api-sui.cetus.zone/router_v2/find_routes",Ri=(o,e)=>{let t=new ne.SuiClient({url:"https://fullnode.mainnet.sui.io/"});return new ee.AggregatorClient(sd,e.address,t,ee.Env.Mainnet)},cd={fullRpcUrl:"https://fullnode.mainnet.sui.io/",simulationAccount:{address:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0xc6faf3703b0e8ba9ed06b7851134bbbe7565eb35ff823fd78432baa4cbeaa12e",config:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:""}},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0x2d8c2e0fc6dd25b0214b3fa747e0fd27fd54608142cd2e4f64c1cd350cc4add4"},frams:{package_id:"0x11ea791d82b5742cc8cab0bf7946035c97d9001d7c3803a93f119753da66f526",published_at:"0x7e4ca066f06a1132ab0499c8c0b87f847a0d90684afa902e52501a44dbd81992",config:{global_config_id:"0x21215f2f6de04b57dd87d9be7bb4e15499aec935e36078e2488f36436d64996e",rewarder_manager_id:"0xe0e155a88c77025056da08db5b1701a91b79edb6167462f768e387c3ed6614d5",rewarder_manager_handle:"0xb32e312cbb3367d6f3d2b4e57c9225e903d29b7b9f612dae2ddf75bdeb26a5aa",admin_cap_id:"0xf10fbf1fea5b7aeaa524b87769461a28c5c977613046360093673991f26d886c"}},vaults:{package_id:"0xd3453d9be7e35efe222f78a810bb3af1859fd1600926afced8b4936d825c9a05",published_at:"0x58e5de6e425397eeaf952d55c0f94637bee91b25d6138ce222f89cda0aefec03",config:{admin_cap_id:"0x78a42978709c4032fab7b33b782b5bcef64c1c6603250bf23644650b72144375",vaults_manager_id:"0x25b82dd2f5ee486ed1c8af144b89a8931cd9c29dee3a86a1bfe194fdea9d04a6",vaults_pool_handle:"0x9036bcc5aa7fd2cceec1659a6a1082871f45bc400c743f50063363457d1738bd",haedal:{package_id:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",published_at:"0xaabf0856070391df81fad9240049d69c5a51c3d376cc0885eeedd516526cc79b",version:1,config:{staking_id:"0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",coin_type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"}},volo:{package_id:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",published_at:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",version:1,config:{native_pool:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",vsui_metadata:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",coin_type:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"}},aftermath:{package_id:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",published_at:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",version:1,config:{staked_sui_vault:"0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",referral_vault:"0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",safe:"0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",validator_address:"0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2",coin_type:"0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"}}}},aggregator:{endPoint:"https://api-sui.cetus.zone/router_v2/find_routes",fullNodeurl:"https://fullnode.mainnet.sui.io/",walletAddress:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb",env:ee.Env.Mainnet,providers:["CETUS","DEEPBOOK","KRIYA","KRIYAV3","FLOWX","FLOWXV3","AFTERMATH","TURBOS","HAEDAL","VOLO","AFSUI"]}},er=(o,e)=>{let t=new Pi.default(cd);return t.senderAddress=e.address,t},Pt=(o,e)=>{let t=new Oi.CetusXcetusSDK(id);return t.senderAddress=e.address,t};var Bi=async(o,e,t)=>await St(t,e).Position.createAddLiquidityFixTokenPayload(o?.parameter,o?.gasEstimateArg),_i=async(o,e,t)=>await St(t,e).Position.createAddLiquidityFixTokenPayload(o?.parameter,o?.gasEstimateArg),Ei=async(o,e,t)=>await St(t,e).Position.closePositionTransactionPayload(o),Mi=async(o,e,t)=>await St(t,e).Position.removeLiquidityTransactionPayload(o),Wi=async(o,e,t)=>await St(t,e).Rewarder.collectRewarderTransactionPayload(o);var nn=class o extends u{constructor(t){super(t);this.data=t}txType=Ni.TransactionType.Other;txSubType="OpenAndAddLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Bi(r,n,a)}static fromData(t){return new o(t)}};var Li=require("@msafe/sui3-utils");var an=class o extends u{constructor(t){super(t);this.data=t}txType=Li.TransactionType.Other;txSubType="ClaimFeeAndMining";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Wi(r,n,a)}static fromData(t){return new o(t)}};var ji=require("@msafe/sui3-utils");var on=class o extends u{constructor(t){super(t);this.data=t}txType=ji.TransactionType.Other;txSubType="DecreaseLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Mi(r,n,a)}static fromData(t){return new o(t)}};var zi=require("@msafe/sui3-utils");var Ui=async(o,e,t)=>await $(t,e).Farms.openPositionAddLiquidityStakePaylod(o),Fi=async(o,e,t)=>await $(t,e).Farms.addLiquidityFixCoinPayload(o),qi=async(o,e,t)=>await $(t,e).Farms.removeLiquidityPayload(o),Ki=async(o,e,t)=>await $(t,e).Farms.removeLiquidityPayload(o),$i=async(o,e,t)=>await $(t,e).Farms.claimFeeAndClmmReward(o),Vi=async(o,e,t)=>await $(t,e).Farms.harvestPayload(o),Hi=async(o,e,t)=>{let n=$(t,e),a=Object.values(o);return await n.Farms.batchHarvestPayload(a)},Gi=async(o,e,t)=>await $(t,e).Farms.depositPayload(o),Qi=async(o,e,t)=>await $(t,e).Farms.withdrawPayload(o);var rn=class o extends u{constructor(t){super(t);this.data=t}txType=zi.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Ui(r,n,a)}static fromData(t){return new o(t)}};var Ji=require("@msafe/sui3-utils");var sn=class o extends u{constructor(t){super(t);this.data=t}txType=Ji.TransactionType.Other;txSubType="FarmingBatchHarvest";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Hi(r,n,a)}static fromData(t){return new o(t)}};var Yi=require("@msafe/sui3-utils");var cn=class o extends u{constructor(t){super(t);this.data=t}txType=Yi.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await $i(r,n,a)}static fromData(t){return new o(t)}};var Xi=require("@msafe/sui3-utils");var ln=class o extends u{constructor(t){super(t);this.data=t}txType=Xi.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await qi(r,n,a)}static fromData(t){return new o(t)}};var Zi=require("@msafe/sui3-utils");var dn=class o extends u{constructor(t){super(t);this.data=t}txType=Zi.TransactionType.Other;txSubType="FarmingHarvest";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Vi(r,n,a)}static fromData(t){return new o(t)}};var ts=require("@msafe/sui3-utils");var un=class o extends u{constructor(t){super(t);this.data=t}txType=ts.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Fi(r,n,a)}static fromData(t){return new o(t)}};var es=require("@msafe/sui3-utils");var mn=class o extends u{constructor(t){super(t);this.data=t}txType=es.TransactionType.Other;txSubType="FarmingRemoveLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Ki(r,n,a)}static fromData(t){return new o(t)}};var ns=require("@msafe/sui3-utils");var pn=class o extends u{constructor(t){super(t);this.data=t}txType=ns.TransactionType.Other;txSubType="FarmingStake";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Gi(r,n,a)}static fromData(t){return new o(t)}};var as=require("@msafe/sui3-utils");var fn=class o extends u{constructor(t){super(t);this.data=t}txType=as.TransactionType.Other;txSubType="FarmingUnstake";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Qi(r,n,a)}static fromData(t){return new o(t)}};var os=require("@msafe/sui3-utils");var bn=class o extends u{constructor(t){super(t);this.data=t}txType=os.TransactionType.Other;txSubType="IncreaseLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await _i(r,n,a)}static fromData(t){return new o(t)}};var rs=require("@msafe/sui3-utils");var hn=class o extends u{constructor(t){super(t);this.data=t}txType=rs.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Ei(r,n,a)}static fromData(t){return new o(t)}};var ls=require("@msafe/sui3-utils");var is=require("@cetusprotocol/aggregator-sdk"),ss=require("@mysten/sui/transactions");var cs=async(o,e,t)=>{let n=Ri(t,e),a=new ss.Transaction;return await n.fastRouterSwap({...o,routers:(0,is.restituteMsafeFastRouterSwapParams)(o.routers),txb:a}),a};var gn=class o extends u{constructor(t){super(t);this.data=t}txType=ls.TransactionType.Other;txSubType="AggregatorSwap";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await cs(r,n,a)}static fromData(t){return new o(t)}};var ms=require("@msafe/sui3-utils");var ds=async(o,e,t)=>await er(t,e).Vaults.deposit(o),us=async(o,e,t)=>await er(t,e).Vaults.withdraw(o);var yn=class o extends u{constructor(t){super(t);this.data=t}txType=ms.TransactionType.Other;txSubType="AddVaultsPosition";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await ds(r,n,a)}static fromData(t){return new o(t)}};var ps=require("@msafe/sui3-utils");var Tn=class o extends u{constructor(t){super(t);this.data=t}txType=ps.TransactionType.Other;txSubType="RemoveVaultsPosition";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await us(r,n,a)}static fromData(t){return new o(t)}};var gs=require("@msafe/sui3-utils");var bs=require("@mysten/sui/transactions"),fs={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},hs=async(o,e,t)=>{console.log("getVestingRedeemTxb txbParams: ",o),console.log("getVestingRedeemTxb account: ",e),console.log("getVestingRedeemTxb network: ",t);let{pool:n,nftId:a,periods:r,CLOCK_ADDRESS:i}=o,s=new bs.Transaction;return r.forEach(c=>{s.moveCall({target:`${fs.published_at}::router::redeem`,typeArguments:[fs.cetus_coin_type],arguments:[s.object(n),s.object(a),s.pure(c),s.object(i)]})}),s};var Cn=class o extends u{constructor(t){super(t);this.data=t}txType=gs.TransactionType.Other;txSubType="VestingRedeem";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await hs(r,n,a)}static fromData(t){return new o(t)}};var ws=require("@msafe/sui3-utils");var ys=async(o,e,t)=>await Pt(t,e).XCetusModule.convertPayload(o),Ts=async(o,e,t)=>await Pt(t,e).XCetusModule.redeemLockPayload(o),Cs=async(o,e,t)=>await Pt(t,e).XCetusModule.redeemDividendV3Payload(o.veNftId,o.rewardList),Is=async(o,e,t)=>await Pt(t,e).XCetusModule.cancelRedeemPayload(o),Ss=async(o,e,t)=>await Pt(t,e).XCetusModule.redeemPayload(o);var In=class o extends u{constructor(t){super(t);this.data=t}txType=ws.TransactionType.Other;txSubType="xCETUSCancelRedeem";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Is(r,n,a)}static fromData(t){return new o(t)}};var ks=require("@msafe/sui3-utils");var Sn=class o extends u{constructor(t){super(t);this.data=t}txType=ks.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Cs(r,n,a)}static fromData(t){return new o(t)}};var xs=require("@msafe/sui3-utils");var wn=class o extends u{constructor(t){super(t);this.data=t}txType=xs.TransactionType.Other;txSubType="xCETUSConvert";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await ys(r,n,a)}static fromData(t){return new o(t)}};var Ds=require("@msafe/sui3-utils");var kn=class o extends u{constructor(t){super(t);this.data=t}txType=Ds.TransactionType.Other;txSubType="xCETUSRedeem";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Ss(r,n,a)}static fromData(t){return new o(t)}};var vs=require("@msafe/sui3-utils");var xn=class o extends u{constructor(t){super(t);this.data=t}txType=vs.TransactionType.Other;txSubType="xCETUSRedeemLock";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Ts(r,n,a)}static fromData(t){return new o(t)}};var Dn=class{application="cetus";supportSDK="@mysten/sui";async deserialize(e){console.log("Cetus helper deserialize input: ",e);let{txbParams:t,action:n}=e;return{txType:As.TransactionType.Other,txSubType:n,intentionData:{txbParams:{...t},action:n}}}async build(e){let{suiClient:t,account:n,network:a}=e,r;switch(e.txSubType){case"OpenAndAddLiquidity":r=nn.fromData(e.intentionData);break;case"IncreaseLiquidity":r=bn.fromData(e.intentionData);break;case"DecreaseLiquidity":r=on.fromData(e.intentionData);break;case"RemoveLiquidity":r=hn.fromData(e.intentionData);break;case"ClaimFeeAndMining":r=an.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":r=rn.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":r=un.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":r=ln.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":r=mn.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":r=cn.fromData(e.intentionData);break;case"FarmingHarvest":r=dn.fromData(e.intentionData);break;case"FarmingBatchHarvest":r=sn.fromData(e.intentionData);break;case"FarmingStake":r=pn.fromData(e.intentionData);break;case"FarmingUnstake":r=fn.fromData(e.intentionData);break;case"xCETUSConvert":r=wn.fromData(e.intentionData);break;case"xCETUSRedeemLock":r=xn.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":r=Sn.fromData(e.intentionData);break;case"xCETUSCancelRedeem":r=In.fromData(e.intentionData);break;case"xCETUSRedeem":r=kn.fromData(e.intentionData);break;case"VestingRedeem":r=Cn.fromData(e.intentionData);break;case"AggregatorSwap":r=gn.fromData(e.intentionData);break;case"AddVaultsPosition":r=yn.fromData(e.intentionData);break;case"RemoveVaultsPosition":r=Tn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:a})}};var Ys=require("@msafe/sui3-utils");var Os=q(require("sort-keys-recursive")),h=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Os.default)(this.data))}};var ae=require("@mysten/sui.js/client");var nr={};tr(nr,{contractId:()=>ud,default:()=>hd,feeObjId:()=>fd,roleObjId:()=>md,status:()=>dd,transaction:()=>ld,upgradeCapObjId:()=>bd,vaultObjId:()=>pd});var ld="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",dd="success",ud="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",md="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",pd="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",fd="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",bd="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",hd={transaction:ld,status:dd,contractId:ud,roleObjId:md,vaultObjId:pd,feeObjId:fd,upgradeCapObjId:bd};var ar={};tr(ar,{contractId:()=>Td,default:()=>kd,feeObjId:()=>Sd,roleObjId:()=>Cd,status:()=>yd,transaction:()=>gd,upgradeCapObjId:()=>wd,vaultObjId:()=>Id});var gd="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",yd="success",Td="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",Cd="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",Id="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",Sd="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",wd="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",kd={transaction:gd,status:yd,contractId:Td,roleObjId:Cd,vaultObjId:Id,feeObjId:Sd,upgradeCapObjId:wd};var xd=(0,ae.getFullnodeUrl)("testnet"),Dd=(0,ae.getFullnodeUrl)("testnet"),vd=(0,ae.getFullnodeUrl)("mainnet"),Ad=(0,ae.getFullnodeUrl)("mainnet"),Od="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",Pd="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",Rd="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",Bd="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",Ps=nr,Rs=ar,_d=new Map([["dev",{env:"dev",rpc:{url:xd},backend:{url:Od},contract:Ps}],["stg",{env:"stg",rpc:{url:Dd},backend:{url:Pd},contract:Ps}],["prev",{env:"prev",rpc:{url:vd},backend:{url:Rd},contract:Rs}],["prod",{env:"prod",rpc:{url:Ad},backend:{url:Bd},contract:Rs}]]);function Bs(o,e){let t=_d.get(o);if(!t)throw new Error(`Env not supported: ${o}`);return e&&e.rpc&&(t.rpc=e.rpc),e&&e.backend&&(t.backend=e.backend),e&&e.contract&&(t.contract=e.contract),t}var _s=require("@mysten/sui.js/client");var C=class extends Error{mpayErrorCode;context;constructor(e,t,n={}){let{cause:a,context:r}=n;a?super(`[MPay] ${t}: ${a}`):super(`[MPay] ${t}`),this.mpayErrorCode=e,this.context=r}};var vn=class extends C{constructor(){super(11,"Backend is not specified")}};var An=class extends C{constructor(){super(1,"Wallet not connected")}};var Y=q(require("axios"));var Rt=class extends C{constructor(e,t){super(10,e,{context:t})}};var On=class o{constructor(e){this.apiURL=e}static parseResponseData(e){if(e instanceof Y.AxiosError)throw new Rt(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new Rt(e.data.code)}throw new Rt(e.status.toString())}async getIncomingStreams(e,t){let n=await Y.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return o.parseResponseData(n)}async getOutgoingStreams(e,t){let n=await Y.default.post(`${this.apiURL}/stream`,{sender:e,...t});return o.parseResponseData(n)}async getStreamHistory(e){let t=await Y.default.post(`${this.apiURL}/stream-events`,e),n=o.parseResponseData(t);return n.data.forEach(a=>{let r=a;return r.data.type==="create_stream"?r.data.balance=BigInt(r.data.balance):r.data.type==="cancel_stream"?r.data.withdrawAmount=BigInt(r.data.withdrawAmount):r.data.type==="claim"||r.data.type==="auto_claim"?r.data.claimAmount=BigInt(r.data.claimAmount):r.data.type==="set_auto_claim"&&(r.data.enabled=!!r.data.enabled),r.createdAt=new Date(r.createdAt),r}),n}async getAllCoinTypes(e){let t=await Y.default.post(`${this.apiURL}/stream-info`,{address:e});return o.parseResponseData(t)}async getAllRecipients(e,t){let n=await Y.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return o.parseResponseData(n)}async getAllSenders(e,t){let n=await Y.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return o.parseResponseData(n)}};var Bt=class o{signer;suiClient;envConfig;_backend;constructor(e){this.envConfig=e,this.suiClient=new _s.SuiClient({url:e.rpc.url}),e.backend&&(this._backend=new On(e.backend.url))}static new(e,t){let n=Bs(e,t);return new o(n)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new vn;return this._backend}set backend(e){this._backend=e}connectWallet(e){this.signer=e}disconnect(){this.signer=void 0}get wallet(){if(!this.signer)throw new An;return this.signer}async walletAddress(){return this.wallet.address()}};var kt=require("@mysten/sui.js/utils");var le=require("@mysten/sui.js/transactions");var cr=require("@mysten/sui.js/transactions"),ce=require("@mysten/sui.js/utils");var or=50n,Pn=10000n,Es=25n,rr=100000000n;var V=class{constructor(e){this.object=e}moveArg(e){return e.object(this.object)}},oe=class{constructor(e){this.objects=e}moveArgs(e){return e.makeMoveVec({objects:this.objects.map(t=>e.object(t))})}},at=class o{constructor(e){this.result=e;return new Proxy(this,{set(){throw new Error("The transaction result is a proxy, and does not support setting properties directly")},get(t,n){if(n in t)return Reflect.get(t,n);let a=i=>new o(t.result[i]);if(n===Symbol.iterator)return function*(){let i=0;for(;;)yield a(i),i++};if(typeof n=="symbol")return;let r=parseInt(n,10);if(!(Number.isNaN(r)||r<0))return a(r)}})}moveArg(){return this.result}};var ir=require("buffer"),Ms=require("@mysten/sui.js/utils");var re=class extends C{constructor(e,t){super(3,e,{context:t})}};var Rn=class{constructor(e){this.results=e}callResult(e){return this.results.results[e]}returnValue(e,t){return e.returnValues[t]}getValue(e=0,t=0){let n=this.callResult(e);return this.returnValue(n,t)}getAddress(e=0,t=0){let[n,a]=this.getValue(e,t);if(a!=="address")throw new re("Invalid contract return type.",{ctx:{expectType:"address",gotType:a}});return(0,Ms.normalizeSuiAddress)(ir.Buffer.from(n).toString("hex"))}getU64(e=0,t=0){let[n,a]=this.getValue(e,t);if(a!=="u64")throw new re("Invalid contract return type.",{ctx:{expectType:"u64",gotType:a}});return ir.Buffer.from(n).readBigInt64LE()}};var sr=require("@mysten/sui.js/bcs");var S=class extends C{constructor(e,t,n){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:n}})}};var Ns={groupId:"string",name:"string"},Ed=64;function Ls(o){return js(o),sr.bcs.ser(Ns,o).toString("base64")}function ie(o){let e=sr.bcs.de(Ns,o,"base64");return js(e),e}function js(o){if(!Ws(o.name))throw new S("Invalid metadata: Name contains unknown character");if(!Ws(o.groupId))throw new S("Invalid metadata: Group ID contains unknown character");if(o.name.length>Ed)throw new S("Invalid metadata: Name exceed max length 64")}function Ws(o){return/^[\x00-\x7F]+$/.test(o)}var se=require("@mysten/sui.js/utils");function Bn(o,e){return(0,se.normalizeStructTag)(o)===(0,se.normalizeStructTag)(e)}function ot(o,e){return(0,se.normalizeStructTag)(o)===(0,se.normalizeStructTag)(e)}var _n="txn.gas";var Us=require("nanoid");function Fs(){return(0,Us.nanoid)()}var wt=class o{constructor(e,t,n){this.globals=e;this.feeContract=t;this.streamContract=n}static convertCreateStreamInfoToInternal(e){return{metadata:Ls({name:e.name,groupId:Fs()}),coinType:(0,ce.normalizeStructTag)(e.coinType),recipients:e.recipients.map(t=>({address:t.address,cliffAmount:t.cliffAmount,amountPerEpoch:t.amountPerStep})),epochInterval:e.interval,numberEpoch:e.steps,startTime:e.startTimeMs,cancelable:e.cancelable}}async buildCreateStreamTransactionBlock(e){let t=new cr.TransactionBlock,n=this.calculateFeesInternal(e),a=this.getCreateStreamCoinRequests(e,n),r=await this.wallet.requestCoins(a),i=await this.addMergeCoins(t,r[0]),s;a.length>1?s=await this.addMergeCoins(t,r[1]):s=i;for(let c=0;c<e.recipients.length;c++){let l=e.recipients[c],d=this.amountForRecipient(l,e.numberEpoch),m=this.getStreamFeeLocal(d),[p]=t.splitCoins(i,[t.pure(d+m,"u64")]),[f]=t.splitCoins(s,[t.pure(this.flatSuiFee,"u64")]);this.streamContract.createStream(t,{paymentCoin:new at(p),flatFeeCoin:new at(f),metadata:e.metadata,recipient:l.address,timeStart:e.startTime,cliff:l.cliffAmount,epochInterval:e.epochInterval,numEpoch:e.numberEpoch,amountPerEpoch:l.amountPerEpoch,cancelable:e.cancelable,coinType:e.coinType})}return t}calculateCreateStreamFees(e){let t=o.convertCreateStreamInfoToInternal(e);return this.calculateFeesInternal(t)}feeParams(){return{createFeePercent:{numerator:or,denominator:Pn},claimFeePercent:{numerator:Es,denominator:Pn},flatFeePerStream:rr}}async addMergeCoins(e,t){let n;return t.mergedCoins&&t.mergedCoins.length?(e.mergeCoins(e.object(t.primaryCoin),t.mergedCoins.map(a=>e.object(a))),n=e.object(t.primaryCoin)):t.primaryCoin===_n?n=e.gas:n=e.object(t.primaryCoin),n}getCreateStreamCoinRequests(e,t){let n=e.coinType;return Bn(n,ce.SUI_TYPE_ARG)?[{coinType:n,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:n,amount:t.totalAmount+t.streamFeeAmount},{coinType:ce.SUI_TYPE_ARG,amount:t.flatFeeAmount}]}calculateFeesInternal(e){let t=e.recipients.reduce((a,r)=>{let i=this.amountForRecipient(r,e.numberEpoch),s=this.getStreamFeeLocal(i);return{totalAmount:a.totalAmount+i,streamFeeAmount:a.streamFeeAmount+s}},{totalAmount:0n,streamFeeAmount:0n});return{flatFeeAmount:BigInt(e.recipients.length)*this.flatSuiFee,...t}}amountForRecipient(e,t){return BigInt(e.amountPerEpoch)*BigInt(t)+BigInt(e.cliffAmount)}get flatSuiFee(){return rr}getStreamFeeLocal(e){return e*or/Pn}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new cr.TransactionBlock,e),n=await this.globals.suiClient.devInspectTransactionBlock({sender:await this.globals.walletAddress(),transactionBlock:t});return new Rn(n).getU64()}get wallet(){return this.globals.wallet}};var lr=require("@mysten/sui.js/transactions");var qs="0x0000000000000000000000000000000000000000000000000000000000000006";var _t=class{constructor(e,t,n){this.moduleName=e;this.config=t;this.globals=n}addContractCall(e,t){let n=`${this.config.contractId}::${this.moduleName}::${t.method}`;return e.add(lr.Transactions.MoveCall({target:n,arguments:t.arguments.map(a=>a instanceof oe?a.moveArgs(e):a instanceof V?a.moveArg(e):a instanceof at?a.moveArg():e.pure(a)),typeArguments:t.typeArgs})),e}addTransactionBlock(e,t,n=[],a=[]){e.add(lr.Transactions.MoveCall({target:t,arguments:n.map(r=>r instanceof oe?r.moveArgs(e):r instanceof V?r.moveArg(e):r instanceof at?r.moveArg():e.pure(r)),typeArguments:a}))}makeObject(e){return typeof e=="string"?new V(e):e}vaultObject(){return new V(this.config.vaultObjId)}roleObject(){return new V(this.config.roleObjId)}feeObject(){return new V(this.config.feeObjId)}clockObject(){return new V(qs)}};var Et=class o extends _t{constructor(t,n){super(o.ModuleName,t,n);this.config=t;this.globals=n}static ModuleName="fee_module";static MethodName={set_streaming_fee:"set_streaming_fee",set_claim_fee:"set_claim_fee",set_streaming_flat_fee:"set_streaming_flat_fee",streaming_flat_fee:"streaming_flat_fee",streaming_fee:"streaming_fee",claim_fee:"claim_fee",fee_denominator:"fee_denominator"};setStreamingFee(t,n){let a=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:o.MethodName.set_streaming_fee,arguments:[a,r,n],typeArgs:[]})}setStreamingFlatFee(t,n){let a=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:o.MethodName.set_streaming_flat_fee,arguments:[a,r,n],typeArgs:[]})}setClaimFee(t,n){let a=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:o.MethodName.set_claim_fee,arguments:[a,r,n],typeArgs:[]})}streamingFee(t,n){let a=this.feeObject();return this.addContractCall(t,{method:o.MethodName.streaming_fee,arguments:[a,n],typeArgs:[]})}claimFee(t,n){return this.addContractCall(t,{method:o.MethodName.claim_fee,arguments:[this.feeObject(),n],typeArgs:[]})}feeDenominator(t){return this.addContractCall(t,{method:o.MethodName.fee_denominator,arguments:[this.feeObject()],typeArgs:[]})}};var H=class o extends _t{constructor(t,n){super(o.ModuleName,t,n);this.config=t;this.globals=n}static ModuleName="stream";static MethodName={create_stream:"create_stream",set_auto_claim:"set_auto_claim",cancel_stream:"cancel_stream",claim_stream:"claim_stream",claim_stream_by_proxy:"claim_stream_by_proxy",stream_current_epoch:"stream_current_epoch",now_milli_seconds:"now_milli_seconds"};createStream(t,n){let a=this.feeObject(),r=this.vaultObject(),i=this.makeObject(n.paymentCoin),s=this.makeObject(n.flatFeeCoin),c=this.clockObject();return this.addContractCall(t,{method:o.MethodName.create_stream,arguments:[a,r,i,s,n.metadata,n.recipient,n.timeStart,n.cliff,n.epochInterval,n.numEpoch,n.amountPerEpoch,n.cancelable,c],typeArgs:[n.coinType]})}setAutoClaim(t,n){let a=this.makeObject(n.streamId);return this.addContractCall(t,{method:o.MethodName.set_auto_claim,arguments:[a,n.enabled],typeArgs:[n.coinType]})}cancelStream(t,n){let a=this.makeObject(n.streamId),r=this.clockObject();return this.addContractCall(t,{method:o.MethodName.cancel_stream,arguments:[a,r],typeArgs:[n.coinType]})}claimStream(t,n){let a=this.makeObject(n.streamId),r=this.clockObject();return this.addContractCall(t,{method:o.MethodName.claim_stream,arguments:[a,r],typeArgs:[n.coinType]})}claimStreamByProxy(t,n){let a=this.makeObject(n.streamId),r=this.vaultObject(),i=this.feeObject(),s=this.clockObject();return this.addContractCall(t,{method:o.MethodName.claim_stream_by_proxy,arguments:[a,r,i,s],typeArgs:[n.coinType]})}get createStreamTarget(){return`${this.config.contractId}::${o.ModuleName}::${o.MethodName.create_stream}`}get setAutoClaimTarget(){return`${this.config.contractId}::${o.ModuleName}::${o.MethodName.set_auto_claim}`}get cancelStreamTarget(){return`${this.config.contractId}::${o.ModuleName}::${o.MethodName.cancel_stream}`}get claimStreamTarget(){return`${this.config.contractId}::${o.ModuleName}::${o.MethodName.claim_stream}`}get claimStreamByProxyTarget(){return`${this.config.contractId}::${o.ModuleName}::${o.MethodName.claim_stream_by_proxy}`}};var Mt=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new Et(t,e),this.streamContract=new H(t,e)}feeContract;streamContract;async createStreams(e){let t=wt.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new wt(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,n){let a=new le.TransactionBlock;return this.streamContract.setAutoClaim(a,{streamId:e,enabled:t,coinType:n})}claimStream(e,t){let n=new le.TransactionBlock;return this.streamContract.claimStream(n,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let n=new le.TransactionBlock;return this.streamContract.claimStreamByProxy(n,{streamId:e,coinType:t})}cancelStream(e,t){let n=new le.TransactionBlock;return this.streamContract.cancelStream(n,{streamId:e,coinType:t}),n}};var Wt=require("@mysten/sui.js/utils"),dr=require("luxon");var En=class extends C{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var Md=1e3,Mn=class{constructor(e){this.globals=e;this.coinMetaHelper=new ur(e.suiClient),this.createStreamHelper=new Mt(e).createStreamHelper()}coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new En(e.effects?.status.status,e.effects?.status.error);return e.objectChanges.filter(t=>t.type==="created"&&t.objectType.startsWith(`${this.globals.envConfig.contract.contractId}::stream::Stream`)).map(t=>t.objectId)}calculateCreateStreamFees(e){return this.createStreamHelper.calculateCreateStreamFees(e)}feeParams(){return this.createStreamHelper.feeParams()}calculateStreamAmount(e){if(e.steps===0n)throw new S("Invalid stream steps: 0");let t=e.cliff?e.cliff:{numerator:0n,denominator:100n},n=e.totalAmount*t.numerator/t.denominator,a=(e.totalAmount-n)/e.steps,i={realTotalAmount:a*e.steps+n,cliffAmount:n,amountPerStep:a};return this.validateStreamAmount(i,e.totalAmount),i}calculateTimelineByInterval(e){if(e.steps===0n)throw new S("Invalid stream steps: 0");let t=e.timeStart.plus(e.interval.toMillis()*Number(e.steps)),n={timeStart:e.timeStart,timeEnd:t,interval:e.interval,steps:e.steps};return this.validateTimeline(n),n}calculateTimelineByTotalDuration(e){if(e.steps===0n)throw new S("Invalid stream steps: 0");let t=BigInt(e.total.toMillis())/e.steps,n=e.timeStart.plus(dr.Duration.fromMillis(Number(t*e.steps))),a={timeStart:e.timeStart,timeEnd:n,interval:dr.Duration.fromMillis(Number(t)),steps:e.steps};return this.validateTimeline(a),a}async getBalance(e,t){let n=await this.globals.suiClient.getBalance({owner:e,coinType:t}),a=await this.getCoinMeta(t);return{...n,coinType:(0,Wt.normalizeStructTag)(n.coinType),coinMeta:a}}async getAllBalance(e){let t=await this.globals.suiClient.getAllBalances({owner:e}),n=await Promise.all(t.map(a=>this.getCoinMeta(a.coinType)));return t.map((a,r)=>({...a,coinType:(0,Wt.normalizeStructTag)(a.coinType),coinMeta:n[r]}))}async getCoinMeta(e){return this.coinMetaHelper.getCoinMeta(e)}async simulateTransactionBlock(e){return this.globals.suiClient.devInspectTransactionBlock({transactionBlock:e,sender:await this.globals.wallet.address()})}validateStreamAmount(e,t){if(e.amountPerStep===0n)throw new S("Stream amount too small","totalAmount",t);if(e.cliffAmount>e.realTotalAmount)throw new S("Invalid cliff settings")}validateTimeline(e){if(e.interval.toMillis()<Md)throw new S("Interval shall be at least 1 second","interval",e.interval)}},ur=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}coinMetaReg;async getCoinMeta(e){let t=(0,Wt.normalizeStructTag)(e||Wt.SUI_TYPE_ARG);if(this.coinMetaReg.has(t))return this.coinMetaReg.get(t);let n=await this.queryCoinMeta(t);return n&&this.coinMetaReg.set(t,n),n}async queryCoinMeta(e){return await this.suiClient.getCoinMetadata({coinType:e})||void 0}};var it=require("@mysten/sui.js/utils"),yr=require("luxon");var me=require("@mysten/sui.js/transactions"),pe=require("@mysten/sui.js/utils"),$s=require("luxon");var Wn=class extends C{constructor(){super(7,"Connected wallet is not creator")}};var de=class extends C{constructor(){super(8,"Connected wallet is not recipient")}};var ue=class extends C{constructor(e,t){super(6,e,{context:t})}};var k=class extends C{constructor(e,t={}){super(0,e,t)}};var Nn=class extends C{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var jn=require("luxon"),Ks=(1n<<64n)-1n,Ln=1e3;function mr(o){let e;typeof o=="number"?e=o:typeof o=="bigint"?e=Number(o):e=o.toMillis();let t=Math.round(e/Ln);return jn.DateTime.fromMillis(t*Ln)}function pr(o){let e;typeof o=="number"?e=o:typeof o=="bigint"?e=Number(o):e=o.toMillis();let t=Math.round(e/Ln);return jn.Duration.fromMillis(t*Ln)}var rt=class o{constructor(e,t,n){this.globals=e;this.streamId=t;this.rawData=n;this.streamContract=new H(e.envConfig.contract,e)}streamContract;type="Stream";static async new(e,t){let n=await o.fetchStreamData(e,t);return new o(e,t,n)}static fromObjectData(e,t,n){let a=o.parseRawStreamData(t,n);return new o(e,t,a)}get info(){return{name:this.name,creator:this.creator,coinType:this.coinType,totalAmount:this.totalAmount,start:this.timeStart,end:this.timeEnd,cancelable:this.cancelable,cliffAmount:this.cliff,duration:this.duration,interval:this.interval,steps:this.totalSteps,nextReleaseDate:this.nextReleaseDate,nextReleaseAmount:this.nextReleaseAmount,groupId:this.groupId,streamId:this.streamId,recipient:this.recipient,progress:this.progress,autoClaim:this.autoClaim}}get groupCommonInfo(){return{name:this.name,groupId:this.groupId,creator:this.creator,start:this.timeStart,interval:this.interval,steps:this.totalSteps,cancelable:this.cancelable}}async refresh(){this.rawData=await o.fetchStreamData(this.globals,this.streamId)}refreshWithData(e){if(e.data?.objectId!==this.streamId)throw new k("Object Id does not align");this.rawData=o.parseRawStreamData(this.streamId,e)}async historyEvents(e){return this.globals.backend.getStreamHistory({streamId:this.streamId,pagination:e})}async cancel(){if(await this.globals.walletAddress()!==this.creator)throw new Wn;let e=new me.TransactionBlock;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new de;let e=new me.TransactionBlock;return this.streamContract.claimStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async setAutoClaim(e){if(await this.globals.walletAddress()!==this.recipient)throw new de;let t=new me.TransactionBlock;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new me.TransactionBlock;return this.streamContract.claimStreamByProxy(e,{streamId:this.streamId,coinType:this.coinType}),e}get wallet(){return this.globals.wallet}get client(){return this.globals.suiClient}get coinType(){return(0,pe.normalizeStructTag)(this.rawData.coinType)}get progress(){return{status:this.streamStatus,total:this.totalAmount,streamed:this.streamedAmount,claimed:this.claimedAmount,claimable:this.claimable,canceled:this.canceledAmount}}get balance(){return this.rawData.balance}get autoClaim(){return this.rawData.autoClaim}get amountPerEpoch(){return this.rawData.config.amountPerEpoch}get cancelable(){return this.rawData.config.cancelable}get cliff(){return this.rawData.config.cliff}get creator(){return this.rawData.config.creator}get interval(){return pr(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return ie(e).groupId}get name(){let{metadata:e}=this.rawData.config;return ie(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return mr(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return pr(t)}get timeEnd(){return this.timeStart.plus(this.duration)}get totalSteps(){return this.rawData.config.totalEpoch}get claimable(){return this.streamedAmount-this.claimedAmount}get nextReleaseDate(){return this.currentEpoch===-1n?this.timeStart:this.currentEpoch>=this.totalSteps||this.isCanceled?null:mr((this.currentEpoch+1n)*this.rawData.config.epochInterval+this.rawData.config.timeStart)}get nextReleaseAmount(){return this.currentEpoch===-1n?this.cliff:this.currentEpoch>=this.totalSteps||this.isCanceled?null:this.amountPerEpoch}get streamStatus(){let e=this.rawData.status.status;return e===16?"CANCELED":e===17?"SETTLED":e===1?"COMPLETED":this.currentEpoch>=this.totalSteps?"STREAMED":"STREAMING"}get streamedAmount(){return this.currentEpoch===-1n?0n:this.isCanceled?this.rawData.status.epochCanceled*this.amountPerEpoch+this.cliff:this.currentEpoch*this.amountPerEpoch+this.cliff}get claimedAmount(){return this.rawData.status.epochClaimed===Ks?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=$s.DateTime.now().toMillis(),t=this.timeStart.toMillis();if(e<t)return-1n;let n=Math.floor((e-t)/Number(this.rawData.config.epochInterval));return BigInt(n)>Number(this.rawData.config.totalEpoch)?this.rawData.config.totalEpoch:BigInt(n)}get totalAmount(){let e=this.rawData.config;return e.amountPerEpoch*e.totalEpoch+e.cliff}get isCanceled(){let e=this.rawData.status.status;return e===16||e===17}get canceledAmount(){return this.isCanceled?this.totalAmount-this.streamedAmount:0n}static async fetchStreamData(e,t){let n=await e.suiClient.getObject({id:t,options:{showContent:!0,showType:!0}});return o.parseRawStreamData(t,n)}static parseRawStreamData(e,t){if(t.error)throw t.error.code==="notExists"?new Nn(e):new ue(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let n=t.data.content;if(n.dataType!=="moveObject")throw new ue("Unexpected object type",{gotType:n.dataType});let{typeParams:a}=(0,pe.parseStructTag)(n.type),r=(0,pe.normalizeStructTag)(a[0]),i=n.fields,s=i.config.fields,c=i.status.fields;return{coinType:r,autoClaim:i.auto_claim,balance:BigInt(i.balance.fields.balance),config:{amountPerEpoch:BigInt(s.amount_per_epoch),cancelable:s.cancelable,cliff:BigInt(s.cliff),creator:s.creator,epochInterval:BigInt(s.epoch_interval),metadata:s.metadata,recipient:s.recipient,timeStart:BigInt(s.time_start),totalEpoch:BigInt(s.total_epoch)},status:{status:c.status,epochCanceled:BigInt(c.epoch_canceled),epochClaimed:BigInt(c.epoch_claimed)}}}};var Nt=class extends C{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};async function br(o){let e=[];for(;await o.hasNext();){let t=await o.next();e.push(t)}return e&&Array.isArray(e[0])?e.flat(1):e}var fr=class{constructor(e){this.requester=e;this.curPage=void 0,this.init=!0}curPage;init;async hasNext(){if(this.init)return this.curPage||(this.curPage=await this.requester.doNextRequest()),!!this.curPage.data?.length||this.curPage.hasNext;if(!this.curPage)throw new Error("invalid implementation of iterator");return this.curPage.hasNext}async next(){return this.init?(this.init=!1,this.curPage||(this.curPage=await this.requester.doNextRequest()),this.curPage.data):(this.curPage=await this.requester.doNextRequest(),this.curPage.data)}},Lt=class{constructor(e){this.requester=e;this.pager=new fr(e),this.curData=[],this.cursor=0}cursor;pager;curData;async hasNext(){return this.cursor<this.curData.length-1?!0:this.pager.hasNext()}async next(){for(this.cursor+=1;this.cursor>=this.curData.length;)if(await this.pager.hasNext())this.curData=await this.pager.next(),this.cursor=0;else throw new Error("not more data");return this.curData[this.cursor]}};var Wd=25;async function gr(o,e,t){let n=new fe(e),a=new be(o,n,t);return await br(a)}var fe=class{constructor(e){this.ids=e;this.cursor=-1}cursor;async hasNext(){return this.cursor<this.ids.length-1}async next(){if(this.cursor+=1,this.cursor>=this.ids.length)throw new Error("invalid iterator implementation");return this.ids[this.cursor]}},be=class extends Lt{constructor(t,n,a){super(new hr(t,n,a));this.suiClient=t;this.idIter=n;this.options=a}},hr=class{constructor(e,t,n){this.suiClient=e;this.stringIter=t;this.options=n;this.filter=n?.filter,this.pageSize=n?.pageSize||Wd,this.objectOptions=n?.objectOptions||{showType:!0,showContent:!0}}filter;pageSize;objectOptions;async doNextRequest(){let e=[];for(;e.length<this.pageSize&&await this.stringIter.hasNext();){let r=await this.stringIter.next();r&&e.push(r)}let t=await this.suiClient.multiGetObjects({ids:e,options:this.objectOptions}),n;if(this.filter){let{filter:a}=this;n=t.filter(r=>a?.(r))}else n=t;return{data:n,hasNext:await this.stringIter.hasNext()}}};var Un=class o{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new Nt("stream size 0");let n=t.map(r=>r.groupId);if(new Set(n).size!==1)throw new S("Stream does not have same group ID")}type="StreamGroup";static async new(e,t){let n=await gr(e.suiClient,t);return n.forEach(a=>{if(!a)throw new k("stream group object data undefined")}),o.newFromObjectResponse(e,t,n)}static async newFromObjectResponse(e,t,n){let a=await o.parseGroupStreams(e,t,n);return new o(e,a)}static checkStreamGroup(e){let t=e.map(r=>r.groupCommonInfo),n=t[0],a=!0;return t.forEach(r=>{Nd(n,r)||(a=!1)}),a}async refresh(){let e=await gr(this.globals.suiClient,this.streams.map(t=>t.streamId));this.streams.forEach((t,n)=>{t.refreshWithData(e[n])})}get groupId(){return this.streams[0].groupId}get creator(){return this.streams[0].creator}get info(){return{groupId:this.groupId,streamIds:this.streams.map(e=>e.streamId),progress:this.progress,name:this.streams[0].name,creator:this.creator,coinType:this.streams[0].coinType,totalAmount:this.streams.reduce((e,t)=>e+t.totalAmount,0n),start:this.streams[0].timeStart,end:this.streams[0].timeEnd,cancelable:this.streams[0].cancelable,cliffAmount:this.streams.reduce((e,t)=>e+t.cliff,0n),duration:this.streams[0].duration,interval:this.streams[0].interval,steps:this.streams[0].totalSteps,nextReleaseAmount:this.streams.reduce((e,t)=>t.nextReleaseAmount===null?e:e+t.nextReleaseAmount,0n),nextReleaseDate:this.streams[0].nextReleaseDate}}get progress(){return{total:this.streams.reduce((e,t)=>e+t.totalAmount,0n),streamed:this.streams.reduce((e,t)=>e+t.streamedAmount,0n),claimed:this.streams.reduce((e,t)=>e+t.claimedAmount,0n),claimable:this.streams.reduce((e,t)=>e+t.claimable,0n),canceled:this.streams.reduce((e,t)=>e+t.canceledAmount,0n)}}async historyEvents(e){return this.globals.backend.getStreamHistory({groupId:this.groupId,pagination:e})}static async parseGroupStreams(e,t,n){let a=n.map((r,i)=>rt.fromObjectData(e,t[i],r)).filter(r=>!!r);if(new Set(a.map(r=>r.groupId)).size!==1)throw new Nt("Not same group ID");if(!this.checkStreamGroup(a))throw new Nt("Not same stream settings");return a}};function Nd(o,e){return o.name===e.name&&o.groupId===e.groupId&&o.creator===e.creator&&o.start.toMillis()===e.start.toMillis()&&o.interval.toMillis()===e.interval.toMillis()&&o.steps===e.steps&&o.cancelable===e.cancelable}var he=class o{constructor(e,t){this.it=e;this.pageSize=t}static async newIncoming(e){let t=await Fn.newIncoming(e);return new o(t,e.pageSize)}static async newOutgoing(e){let t=await Fn.newOutgoing(e);return new o(t,e.pageSize)}async hasNext(){return this.it.hasNext()}async next(){let e=[];for(;e.length<this.pageSize&&await this.it.hasNext();)e.push(await this.it.next());return e}},Fn=class o{constructor(e){this.requester=e}cachedNext;static async newIncoming(e){let t=await qn.newIncomingQuery(e);return new o(t)}static async newOutgoing(e){let t=await qn.newOutgoingQuery(e);return new o(t)}async hasNext(){return this.cachedNext===void 0&&(this.cachedNext=await this.requester.doNextRequest()),this.cachedNext!==null}async next(){if(this.cachedNext===void 0){let t=await this.requester.doNextRequest();if(t===null)throw new k("No more results");return t}let e=this.cachedNext;if(this.cachedNext=void 0,e===null)throw new k("No more results");return e}},qn=class o{constructor(e,t,n,a){this.globals=e;this.recipient=t;this.groupRefs=n;this.query=a;this.current=0;let r=new fe(n.flat().map(i=>i.streamId));this.objectIter=new be(e.suiClient,r)}current=0;objectIter;static async newIncomingQuery(e){let t=qd(e.query),n=await e.globals.walletAddress(),r=(await e.globals.backend.getIncomingStreams(n,t)).filter(s=>(0,it.normalizeSuiAddress)(s.recipient)===(0,it.normalizeSuiAddress)(n)),i=Vs(r);return new o(e.globals,n,i,e.query)}static async newOutgoingQuery(e){let t=Kd(e.query),n=await e.globals.walletAddress(),a=await e.globals.backend.getOutgoingStreams(n,t),r=Vs(a);return new o(e.globals,n,r,e.query)}async doNextRequest(){if(this.current>=this.groupRefs.length)return null;let e=this.groupRefs[this.current];if(e.length===1){let t=await Ud(this.globals,e[0].streamId,this.objectIter);return this.current++,Hs(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await Fd(this.globals,e.map(n=>n.streamId),this.objectIter);return this.current++,jd(t,this.query)?t:this.doNextRequest()}throw new k("Stream group with no stream")}};function Vs(o){let e=new Map;return o.forEach(t=>{let n=e.get(t.groupId);n?(n.push(t),e.set(t.groupId,n)):e.set(t.groupId,[t])}),Array.from(e.values()).sort((t,n)=>yr.DateTime.fromISO(n[0].createDate).toMillis()-yr.DateTime.fromISO(t[0].createDate).toMillis())}function Hs(o,e){if(e===void 0)return!0;let t=Ld(o,e.status);if(e&&"claimable"in e&&e.claimable!==void 0){let n=e.claimable?o.progress.claimable!==0n:o.progress.claimable===0n;return t&&n}return t}function Ld(o,e){return e===void 0?!0:Array.isArray(e)?e.includes(o.progress.status):o.progress.status===e}function jd(o,e){if(!e)return!0;let t=!1;return o.streams.forEach(n=>{Hs(n,e)&&(t=!0)}),t}async function Ud(o,e,t){let n=await Gs(t,e);return rt.fromObjectData(o,e,n)}async function Fd(o,e,t){let n=[];for(;n.length<e.length;){let a=await Gs(t,e[n.length]);n.push(a)}return Un.newFromObjectResponse(o,e,n)}async function Gs(o,e){if(!await o.hasNext())throw new k("object iterator has been consumed");let t=await o.next();if(!t||t.error||t.data===void 0||t.data===null)throw new k("object iterator undefined response",{cause:t?.error});if(t?.data?.objectId!==e)throw new k("stream id not aligned");return t}function qd(o){return{status:Tr(o?.status),coinType:Qs(o?.coinType),sender:zs(o?.sender)}}function Kd(o){return{status:Tr(o?.status),coinType:Qs(o?.coinType),recipient:zs(o?.recipient)}}function Tr(o){return o===void 0||o.length===0?"all":Array.isArray(o)?o.reduce((e,t)=>{let n=Tr(t);return!e||e===n?n:"all"},void 0):$d(o)}function $d(o){switch(o){case"STREAMING":case"STREAMED":case"CANCELED":return"active";case"COMPLETED":case"SETTLED":return"inactive";default:throw new S("Unknown stream filtered status")}}function Qs(o){if(o)return Array.isArray(o)?o.length!==0?o.map(e=>(0,it.normalizeStructTag)(e)):void 0:(0,it.normalizeStructTag)(o)}function zs(o){if(o)return Array.isArray(o)?o.length!==0?o.map(e=>(0,it.normalizeSuiAddress)(e)):void 0:(0,it.normalizeSuiAddress)(o)}var Kn=class extends C{constructor(t,n,a){super(4,`Not enough balance: ${t}`,{context:{coinType:t,requestAmount:n,gotAmount:a}});this.coinType=t;this.requestAmount=n;this.gotAmount=a}};var Vd=25;async function Js(o,e,t,n="0x2::sui::SUI",a=Vd){let r=new Cr(o,e,n,a),i=BigInt(0),s=[];for(;await r.hasNext()&&i<t;){let c=await r.next();c&&(s.push(c),i+=BigInt(c.balance))}if(i<t)throw new Kn(n,t,i);return s}var Cr=class extends Lt{constructor(t,n,a,r){super(new Ir(t,n,a,r));this.suiClient=t;this.owner=n;this.coinType=a;this.reqPageSize=r}},Ir=class{constructor(e,t,n,a){this.suiClient=e;this.owner=t;this.coinType=n;this.reqPageSize=a;if(a<=0)throw new k("Invalid reqPageSize")}nextCursor;async doNextRequest(){let e=await this.suiClient.getCoins({owner:this.owner,coinType:this.coinType,cursor:this.nextCursor,limit:this.reqPageSize});return this.nextCursor=e.nextCursor,{data:e.data,hasNext:e.hasNextPage}}};var Sr=class{constructor(e){this.msafe=e}get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},$n=class{constructor(e){this.account=e}async address(){return this.account.address}},wr=class{constructor(e,t){this.singleWallet=e;this.suiClient=t}get type(){return"single"}async address(){return this.singleWallet.address()}async requestCoins(e){return Promise.all(e.map(t=>this.requestCoin(t)))}async requestCoin(e){if(Bn(e.coinType,kt.SUI_TYPE_ARG))return{primaryCoin:_n};if(e.amount<=0)throw new S("Invalid coin request","coinAmount",e.amount);let t=await Js(this.suiClient,await this.address(),e.amount,e.coinType);if(t.length===0)throw new k("no coins available");return{primaryCoin:t[0].coinObjectId,mergedCoins:t.slice(1).map(n=>n.coinObjectId)}}},Vn=class{globals;helper;constructor(e,t){this.globals=Bt.new(e,t),this.helper=new Mn(this.globals)}connectSingleWallet(e){let t=new wr(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new Sr(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return rt.new(this.globals,e)}async getIncomingStreams(e,t=10){return he.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return he.newOutgoing({globals:this.globals,query:e,pageSize:t})}async getCoinTypesForStreamFilter(){let e=await this.wallet.address();return(await this.globals.backend.getAllCoinTypes(e)).map(n=>(0,kt.normalizeStructTag)(n))}async getRecipientsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllRecipients(t,e)).map(a=>(0,kt.normalizeSuiAddress)(a))}async getCreatorsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllSenders(t,e)).map(a=>(0,kt.normalizeSuiAddress)(a))}get wallet(){return this.globals.wallet}builder(){return new Mt(this.globals)}};var M=class extends h{application="mpay";getClient(e,t){let n=new Vn(e==="sui:mainnet"?"prod":"dev");return n.connectSingleWallet(new $n(t)),n}};var ge=class extends M{constructor(t){super(t);this.data=t}txType=Ys.TransactionType.Stream;txSubType="Cancel";async build(t){let{network:n,account:a}=t;return(await this.getClient(n,a).getStream(this.data.streamId)).cancel()}};var Xs=require("@msafe/sui3-utils");var ye=class extends M{constructor(t){super(t);this.data=t}txType=Xs.TransactionType.Stream;txSubType="ClaimByProxy";async build(t){let{network:n,account:a}=t;return(await this.getClient(n,a).getStream(this.data.streamId)).claimByProxy()}};var Zs=require("@msafe/sui3-utils");var Te=class extends M{constructor(t){super(t);this.data=t}txType=Zs.TransactionType.Stream;txSubType="Claim";async build(t){let{network:n,account:a}=t;return(await this.getClient(n,a).getStream(this.data.streamId)).claim()}};var tc=require("@msafe/sui3-utils");var Ce=class extends M{constructor(t){super(t);this.data=t}txType=tc.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:n,account:a}=t;return this.getClient(n,a).createStream(this.data)}};var kr=require("@mysten/sui.js/bcs"),st=require("@mysten/sui.js/utils"),jt=class o{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return o.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return o.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return BigInt(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,st.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return o.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return kr.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,st.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,st.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,st.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,st.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return kr.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,st.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Hn=class{constructor(e,t){this.globals=e;this.txb=t}decode(){let e=this.decodeCreateStreamInfo(),t=this.createStreamHelper().calculateCreateStreamFees(e);return{type:"CreateStream",info:e,fees:t}}decodeCreateStreamInfo(){let t=this.createStreamTransactions().map(n=>this.getCreationInfoFromMoveCall(n));return this.aggregateGroupStreamInfo(t)}createStreamTransactions(){let e=this.transactions.filter(t=>t.kind==="MoveCall"&&ot(t.target,this.contract.createStreamTarget));if(e.length===0)throw new k("No create stream transactions");return e.map(t=>new jt(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:n,groupId:a}=ie(t),r=e.decodeInputAddress(5),i=e.decodeInputU64(6),s=e.decodeInputU64(7),c=e.decodeInputU64(8),l=e.decodeInputU64(9),d=e.decodeInputU64(10),m=e.decodeInputBool(11),p=e.typeArg(0);return{name:n,groupId:a,recipient:r,timeStart:i,cliff:s,epochInterval:c,totalEpoch:l,amountPerEpoch:d,cancelable:m,coinType:p}}aggregateGroupStreamInfo(e){if(new Set(e.map(a=>JSON.stringify({name:a.name,groupId:a.groupId,timeStart:String(a.timeStart),epochInterval:String(a.epochInterval),totalEpoch:String(a.totalEpoch),cancelable:a.cancelable,coinType:a.coinType}))).size!==1)throw new S("Stream group not have common info");let n=e.map(a=>({address:a.recipient,amountPerStep:a.amountPerEpoch,cliffAmount:a.cliff}));return{name:e[0].name,coinType:e[0].coinType,recipients:n,interval:e[0].epochInterval,steps:e[0].totalEpoch,startTimeMs:e[0].timeStart,cancelable:e[0].cancelable}}mergeCoinTransactions(){return this.transactions.filter(e=>e.kind==="MergeCoins")}get transactions(){return this.txb.blockData.transactions}get contract(){return new H(this.globals.envConfig.contract,this.globals)}get feeContract(){return new Et(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new wt(this.globals,this.feeContract,this.contract)}getInputArg(e){if(e.kind!=="Input")throw new Error("not input type");return"value"in e?e:this.txb.blockData.inputs[e.index]}};var Gn=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new H(e.envConfig.contract,e)}contract;decode(){if(this.isCreateStreamTransaction())return this.decodeCreateStreamTransaction();if(this.isClaimByProxyTransaction())return this.decodeClaimByProxyTransaction();if(this.isSetAutoClaimTransaction())return this.decodeSetAutoClaimTransaction();if(this.isCancelStreamTransaction())return this.decodeCancelStreamTransaction();if(this.isClaimStreamTransaction())return this.decodeClaimTransaction();throw new Error("Unknown stream transaction type")}get transactions(){return this.txb.blockData.transactions}isCreateStreamTransaction(){return this.transactions.findIndex(t=>t.kind==="MoveCall"&&ot(t.target,this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ot(this.transactions[0].target,this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ot(this.transactions[0].target,this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ot(this.transactions[0].target,this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ot(this.transactions[0].target,this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new Hn(this.globals,this.txb).decode()}decodeSetAutoClaimTransaction(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeInputBool(1);return{type:"SetAutoClaim",streamId:e,enabled:t}}decodeClaimTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"Claim",streamId:e}}decodeClaimByProxyTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"ClaimByProxy",streamId:e}}decodeCancelStreamTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"Cancel",streamId:e}}get helper(){let e=this.transactions[0];return new jt(e,this.txb)}};var ec=require("@msafe/sui3-utils");var Ie=class extends M{constructor(t){super(t);this.data=t}txType=ec.TransactionType.Stream;txSubType="SetAutoClaim";async build(t){let{network:n,account:a}=t;return(await this.getClient(n,a).getStream(this.data.streamId)).setAutoClaim(this.data.enabled)}};var Qn=class{application="mpay";supportSDK="@mysten/sui.js";async deserialize(e){let{network:t,transactionBlock:n}=e,a=Bt.new(t==="sui:mainnet"?"prod":"dev"),i=new Gn(a,n).decode(),s;switch(i.type){case"CreateStream":s=new Ce(i.info);break;case"SetAutoClaim":s=new Ie({streamId:i.streamId,enabled:i.enabled});break;case"Claim":s=new Te({streamId:i.streamId});break;case"ClaimByProxy":s=new ye({streamId:i.streamId});break;case"Cancel":s=new ge({streamId:i.streamId});break;default:throw new Error(`Unknown transaction type: ${i}`)}return{txType:s.txType,txSubType:s.txSubType,intentionData:s.data}}async build(e){let{intentionData:t}=e,n;switch(e.txSubType){case"CreateStream":n=new Ce(t);break;case"Claim":n=new Te(t);break;case"ClaimByProxy":n=new ye(t);break;case"SetAutoClaim":n=new Ie(t);break;case"Cancel":n=new ge(t);break;default:throw new Error("not implemented")}return n.build({...e})}};var Se=require("@msafe/sui3-utils");var nc=require("@msafe/sui3-utils");var zn=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a}=t;return(0,nc.buildCoinTransferTxb)(n,this.data,a.address)}static fromData(t){return new o(t)}};var ac=require("@msafe/sui3-utils");var Jn=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a}=t;return(0,ac.buildObjectTransferTxb)(n,this.data,a.address)}static fromData(t){return new o(t)}};var Yn=class{application="msafe-core";supportSDK="@mysten/sui.js";constructor(){this.application=Se.TransactionDefaultApplication}deserialize(){throw new Error("MSafe core transaction intention should be build from API")}async build(e){let{suiClient:t,account:n}=e,a;switch(e.txSubType){case Se.TransactionSubTypes.assets.coin.send:a=zn.fromData(e.intentionData);break;case Se.TransactionSubTypes.assets.object.send:a=Jn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n})}};var bc=require("@msafe/sui3-utils");var oc=!1,we={ProtocolPackage:"0x81c408448d0d57b3e371ea94de1d40bf852784d3e225de1e74acab3e8395c18f",StorageId:"0xbb4e2f4b6205c2e2a2db47aeb4f830796ec7c005f88537ee775986639bc442fe",Incentive:"0xaaf735bf83ff564e1b219a0d644de894ef5bdc4b2250b126b2a46dd002331821",IncentiveV2:"0xf87a8acb8b81d14307894d12595541a73f19933f88e1326d5be349c7a6f7559c",gasBudget:5e7,PriceOracle:"0x1568865ed9a0b5ec414220e8f79b3d04c77acc82358f6e5ae4635687392ffbef",ReserveParentId:"0xe6d4c6610b86ce7735ea754596d71d72d10c7980b5052fc3c8cdf8d09fea9b4b",pool:{sui:{name:"SUI",assetId:0,poolId:"0x96df0fce3c471489f4debaaa762cf960b3d97820bd1f3f025ff8190730e958c5",fondPoolId:"0xf975bc2d4cca10e3ace8887e20afd77b46c383b4465eac694c4688344955dea4",type:"0x2::sui::SUI",coinType:"sui",reserveObjectId:"0xab644b5fd11aa11e930d1c7bc903ef609a9feaf9ffe1b23532ad8441854fbfaf",borrowBalanceParentId:"0xe7ff0daa9d090727210abe6a8b6c0c5cd483f3692a10610386e4dc9c57871ba7",supplyBalanceParentId:"0x589c83af4b035a3bc64c40d9011397b539b97ea47edf7be8f33d643606bf96f8"},wusdc:{name:"wUSDC",assetId:1,coinType:"wusdc",poolId:"0xa02a98f9c88db51c6f5efaaf2261c81f34dd56d86073387e0ef1805ca22e39c8",type:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",reserveObjectId:"0xeb3903f7748ace73429bd52a70fff278aac1725d3b58afa781f25ce3450ac203",borrowBalanceParentId:"0x8a3aaa817a811131c624658f6e77cba04ab5829293d2c49c1a9cce8ac9c8dec4",supplyBalanceParentId:"0x8d0a4467806458052d577c8cd2be6031e972f2b8f5f77fce98aa12cd85330da9"},usdt:{name:"USDT",coinType:"usdt",assetId:2,poolId:"0x0e060c3b5b8de00fb50511b7a45188c8e34b6995c01f69d98ea5a466fe10d103",type:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",reserveObjectId:"0xb8c5eab02a0202f638958cc79a69a2d30055565caad1684b3c8bbca3bddcb322",borrowBalanceParentId:"0xc14d8292a7d69ae31164bafab7ca8a5bfda11f998540fe976a674ed0673e448f",supplyBalanceParentId:"0x7e2a49ff9d2edd875f82b76a9b21e2a5a098e7130abfd510a203b6ea08ab9257"},weth:{name:"WETH",coinType:"weth",assetId:3,poolId:"0x71b9f6e822c48ce827bceadce82201d6a7559f7b0350ed1daa1dc2ba3ac41b56",type:"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN",reserveObjectId:"0xafecf4b57899d377cc8c9de75854c68925d9f512d0c47150ca52a0d3a442b735",borrowBalanceParentId:"0x7568d06a1b6ffc416a36c82791e3daf0e621cf19d4a2724fc6f74842661b6323",supplyBalanceParentId:"0xa668905b1ad445a3159b4d29b1181c4a62d864861b463dd9106cc0d97ffe8f7f"},cetus:{name:"CETUS",coinType:"cetus",assetId:4,poolId:"0x3c376f857ec4247b8ee456c1db19e9c74e0154d4876915e54221b5052d5b1e2e",type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS",reserveObjectId:"0x66a807c06212537fe46aa6719a00e4fa1e85a932d0b53ce7c4b1041983645133",borrowBalanceParentId:"0x4c3da45ffff6432b4592a39cdb3ce12f4a28034cbcb804bb071facc81fdd923d",supplyBalanceParentId:"0x6adc72faf2a9a15a583c9fb04f457c6a5f0b456bc9b4832413a131dfd4faddae"},voloSui:{name:"VoloSui",coinType:"voloSui",assetId:5,poolId:"0x9790c2c272e15b6bf9b341eb531ef16bcc8ed2b20dfda25d060bf47f5dd88d01",fondPoolId:"0xe2b5ada45273676e0da8ae10f8fe079a7cec3d0f59187d3d20b1549c275b07ea",type:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",reserveObjectId:"0xd4fd7e094af9819b06ea3136c13a6ae8da184016b78cf19773ac26d2095793e2",borrowBalanceParentId:"0x8fa5eccbca2c4ba9aae3b87fd44aa75aa5f5b41ea2d9be4d5321379384974984",supplyBalanceParentId:"0xe6457d247b6661b1cac123351998f88f3e724ff6e9ea542127b5dcb3176b3841"},haSui:{name:"HaedalSui",coinType:"haSui",assetId:6,poolId:"0x6fd9cb6ebd76bc80340a9443d72ea0ae282ee20e2fd7544f6ffcd2c070d9557a",fondPoolId:"0xa20e18085ce04be8aa722fbe85423f1ad6b1ae3b1be81ffac00a30f1d6d6ab51",type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI",reserveObjectId:"0x0c9f7a6ca561dc566bd75744bcc71a6af1dc3caf7bd32c099cd640bb5f3bb0e3",borrowBalanceParentId:"0x01f36898e020be6c3423e5c95d9f348868813cd4d0be39b0c8df9d8de4722b00",supplyBalanceParentId:"0x278b8e3d09c3548c60c51ed2f8eed281876ea58c392f71b7ff650cc9286d095b"},navx:{name:"NAVX",coinType:"navx",assetId:7,poolId:"0xc0e02e7a245e855dd365422faf76f87d9f5b2148a26d48dda6e8253c3fe9fa60",fondPoolId:"0x9dae0cf104a193217904f88a48ce2cf0221e8cd9073878edd05101d6b771fa09",type:"0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX",reserveObjectId:"0x2e13b2f1f714c0c5fa72264f147ef7632b48ec2501f810c07df3ccb59d6fdc81",borrowBalanceParentId:"0xa5bf13075aa400cbdd4690a617c5f008e1fae0511dcd4f7121f09817df6c8d8b",supplyBalanceParentId:"0x59dedca8dc44e8df50b190f8b5fe673098c1273ac6168c0a4addf3613afcdee5"},wbtc:{name:"WBTC",coinType:"wbtc",assetId:8,poolId:"0xd162cbe40f8829ce71c9b3d3bf3a83859689a79fa220b23d70dc0300b777ae6e",type:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN",reserveObjectId:"0x8b4d81f004e4e9faf4540951a896b6d96e42598a270e6375f598b99742db767e",borrowBalanceParentId:"0x55e1f3c9e6e5cf9fff563bdd61db07a3826458c56ef72c455e049ab3b1b0e99c",supplyBalanceParentId:"0x821e505a0091b089edba94deaa14c2f2230d026bbaa7b85680554441aad447e0"},ausd:{name:"AUSD",coinType:"ausd",assetId:9,poolId:"0xc9208c1e75f990b2c814fa3a45f1bf0e85bb78404cfdb2ae6bb97de58bb30932",type:"0x2053d08c1e2bd02791056171aab0fd12bd7cd7efad2ab8f6b9c8902f14df2ff2::ausd::AUSD",reserveObjectId:"0x918889c6a9d9b93108531d4d59a4ebb9cc4d41689798ffc1d4aed6e1ae816ec0",borrowBalanceParentId:"0x551300b9441c9a3a16ca1d7972c1dbb4715e15004ccd5f001b2c2eee22fd92c1",supplyBalanceParentId:"0xe151af690355de8be1c0281fbd0d483c099ea51920a57c4bf8c9666fd36808fd"},nusdc:{name:"USDC",assetId:10,coinType:"nusdc",poolId:"0xa3582097b4c57630046c0c49a88bfc6b202a3ec0a9db5597c31765f7563755a8",type:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",reserveObjectId:"0x4c8a2c72a22ae8da803a8519798d312c86e74a9e0d6ec0eec2bfcf7e4b3fef5e",borrowBalanceParentId:"0xb0b0c7470e96cabbb4f1e8d06bef2fbea65f4dbac52afae8635d9286b1ea9a09",supplyBalanceParentId:"0x08b5ce8574ac3bc9327e66ad5decd34d07ee798f724ad01058e8855ac9acb605"},eth:{name:"ETH",assetId:11,coinType:"eth",poolId:"0x78ba01c21d8301be15690d3c30dc9f111871e38cfb0b2dd4b70cc6052fba41bb",type:"0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH",reserveObjectId:"0x376faea6dfbffab9ea808474cb751d91222b6d664f38c0f1d23de442a8edb1ce",borrowBalanceParentId:"0xf0c6ce5cfaee96073876a5fab7426043f3a798b79502c4caeb6d9772cd35af1f",supplyBalanceParentId:"0xc0a0cb43620eb8a84d5a4a50a85650e7fa7ba81e660f9cc2863404fd84591d4b"},usdy:{name:"USDY",assetId:12,coinType:"usdy",poolId:"0x4b6253a9f8cf7f5d31e6d04aed4046b9e325a1681d34e0eff11a8441525d4563",type:"0x960b531667636f39e85867775f52f6b1f220a058c4de786905bdf761e06a56bb::usdy::USDY",reserveObjectId:"",borrowBalanceParentId:"",supplyBalanceParentId:""}},borrowFee:.003,borrowFeeAddress:"0x70b9b10704263cf53392849e33b1f5fd16005869b4198ed5524836bad1234ea2"};async function xr(){if(!oc)try{let o=await fetch("https://open-api.naviprotocol.io/api/msafe").then(r=>r.json()),{packageId:e,borrowFee:t,borrowFeeAddress:n,pool:a}=o;e&&(we.ProtocolPackage=e),t&&(we.borrowFee=t),n&&(we.borrowFeeAddress=n),a&&(we.pool=a),oc=!0}catch(o){console.error(o.message)}}var j=we;var ct=require("@msafe/sui3-utils"),Dr=require("@mysten/sui.js/bcs"),lt=require("@mysten/sui.js/utils");var Xn=class{constructor(e){this.txb=e}decode(){if(console.log("txb",this.txb),this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isEntryBorrowTransaction())return this.decodeEntryBorrow();if(this.isEntryBorrowWithFeeTransaction())return this.decodeEntryBorrow();if(this.isEntryMultiDepositTransaction())return this.decodeEntryMultiDeposit();if(this.isEntryDepositTransaction())return this.decodeEntryDeposit();if(this.isEntryRepayTransaction())return this.decodeEntryRepay();if(this.isEntryWithdrawTransaction())return this.decodeEntryWithdraw();if(this.isEntryClaimAndDepositTransaction())return this.decodeEntryClaimAndDeposit();throw new Error("Unknown transaction type")}get transactions(){return this.txb.blockData.transactions}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isClaimRewardTransaction(){return!!this.transactions.find(t=>!!(t.kind==="MoveCall"&&t.target.includes("claim_reward")))}isEntryBorrowTransaction(){return!!this.getMoveCallTransaction(`${j.ProtocolPackage}::incentive_v3::entry_borrow`)}isEntryBorrowWithFeeTransaction(){return!!this.getMoveCallTransaction(`${j.ProtocolPackage}::incentive_v3::borrow`)}isEntryMultiDepositTransaction(){let e=`${j.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.transactions.filter(a=>a.kind==="MoveCall"&&a.target===e);return this.transactions.find(a=>a.kind==="MoveCall"&&a.target.includes("claim_reward"))?!1:t.length>1}isEntryClaimAndDepositTransaction(){let e=`${j.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.transactions.filter(a=>a.kind==="MoveCall"&&a.target===e);return!!(this.transactions.find(a=>a.kind==="MoveCall"&&a.target.includes("claim_reward"))&&t.length>0)}isEntryDepositTransaction(){return!!this.getMoveCallTransaction(`${j.ProtocolPackage}::incentive_v3::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallTransaction(`${j.ProtocolPackage}::incentive_v3::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallTransaction(`${j.ProtocolPackage}::incentive_v3::withdraw`)}findPoolByAssetId(e){let t=Object.values(j.pool).find(n=>n.assetId===e);if(!t)throw new Error("Pool not found");return t}decodeEntryClaimAndDeposit(){return{txType:ct.TransactionType.Other,type:"EntryClaimAndDeposit",intentionData:{type:"entry_claim_and_deposit"}}}decodeClaimReward(){return console.log("decode claims"),{txType:ct.TransactionType.Other,type:"ClaimReward",intentionData:{type:"claim_reward"}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:ct.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,assetId:e}}}decodeEntryMultiDeposit(){let e=[],t=`${j.ProtocolPackage}::incentive_v3::entry_deposit`;return this.transactions.forEach(n=>{if(n.kind==="MoveCall"&&n.target===t){let a=new Zn(n,this.txb),r=a.decodeInputU8(3),i=a.decodeInputU64(5);e.push({assetId:r,amount:i})}}),{txType:ct.TransactionType.Other,type:"EntryMultiDeposit",intentionData:{list:e}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5);return{txType:ct.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,assetId:e}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6);return{txType:ct.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,assetId:e}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:ct.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,assetId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(j.ProtocolPackage));return new Zn(e,this.txb)}},Zn=class o{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return o.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return o.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,lt.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return o.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return Dr.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,lt.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,lt.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,lt.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,lt.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return Dr.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,lt.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var W=require("navi-sdk");async function Ut(o,e,t,n){return await(0,W.depositCoin)(o,e,t,n),o}async function rc(o,e,t,n){let[a]=await(0,W.withdrawCoin)(o,e,t);return o.transferObjects([a],o.pure(n)),o}async function ic(o,e,t,n){let[a]=await(0,W.borrowCoin)(o,e,t);return o.transferObjects([a],o.pure.address(n)),o}async function vr(o,e,t,n){return await(0,W.repayDebt)(o,e,t,n),o}async function sc(o,e){return await(0,W.claimAllRewardsPTB)(o,e)}async function cc(o,e){return await(0,W.claimAllRewardsResupplyPTB)(o,e)}var ta=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward",n),await sc(t.suiClient,t.account.address)}static fromData(t){return new o(t)}};var ea=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward and supply",n),await cc(t.suiClient,t.account.address)}static fromData(t){return new o(t)}};var dc=require("@mysten/sui.js/transactions");var lc=require("navi-sdk");function G(o){return Object.values(lc.pool).find(e=>String(e.assetId)===String(o))}var na=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:a}=this.data,r=new dc.TransactionBlock;console.log("build",this.data);let i=G(n);return await ic(r,i,a,t.account.address)}static fromData(t){return new o(t)}};var uc=require("@mysten/sui.js/transactions");async function Ft(o,e,t){let n=await o.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,n),n}var aa=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a}=t,{assetId:r,amount:i}=this.data,s=new uc.TransactionBlock;console.log("build",this.data);let c=G(r);if(r===0){let[p]=s.splitCoins(s.gas,[i]);return await Ut(s,c,p,i)}let l=await Ft(n,a.address,c.type);if(!l.data[0])throw new Error(`Insufficient balance for ${c.name} Token`);let d=l.data[0].coinObjectId;if(l.data.length>=2){let p=1;for(;p<l.data.length;)s.mergeCoins(d,[l.data[p].coinObjectId]),p++}return await Ut(s,c,s.object(d),i)}static fromData(t){return new o(t)}};var mc=require("@mysten/sui.js/transactions");var oa=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a}=t,{assetId:r,amount:i}=this.data,s=new mc.TransactionBlock;console.log("build",this.data);let c=G(r);if(r===0){let[m]=s.splitCoins(s.gas,[i]);return vr(s,c,m,i)}let l=await Ft(n,a.address,c.type);if(!l.data[0])throw new Error(`Insufficient balance for ${c.name} Token`);let d=l.data[0].coinObjectId;if(l.data.length>=2){let m=1;for(;m<l.data.length;)s.mergeCoins(d,[l.data[m].coinObjectId]),m++}return vr(s,c,s.object(d),i)}static fromData(t){return new o(t)}};var pc=require("@mysten/sui.js/transactions");var ra=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:a}=this.data,r=new pc.TransactionBlock;console.log("build",this.data);let i=G(n);return await rc(r,i,a,t.account.address)}static fromData(t){return new o(t)}};var fc=require("@mysten/sui.js/transactions");var ia=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a}=t,{list:r}=this.data,i=new fc.TransactionBlock;console.log("build",this.data);for(let s=0;s<r.length;s++){let{assetId:c,amount:l}=r[s],d=G(c);if(c===0){let[f]=i.splitCoins(i.gas,[l]);await Ut(i,d,f,l);continue}let m=await Ft(n,a.address,d.type);if(!m.data[0])throw new Error(`Insufficient balance for ${d.name} Token`);let p=m.data[0].coinObjectId;if(m.data.length>=2){let f=1;for(;f<m.data.length;)i.mergeCoins(p,[m.data[f].coinObjectId]),f++}await Ut(i,d,i.object(p),l)}return i}static fromData(t){return new o(t)}};var sa=class{application="navi";supportSDK="@mysten/sui.js";async deserialize(e){await xr();let{transactionBlock:t}=e,a=new Xn(t).decode();return{txType:bc.TransactionType.Other,txSubType:a.type,intentionData:a.intentionData}}async build(e){let{suiClient:t,account:n}=e,a;switch(await xr(),e.txSubType){case"EntryDeposit":a=aa.fromData(e.intentionData);break;case"EntryBorrow":a=na.fromData(e.intentionData);break;case"EntryRepay":a=oa.fromData(e.intentionData);break;case"EntryWithdraw":a=ra.fromData(e.intentionData);break;case"EntryMultiDeposit":a=ia.fromData(e.intentionData);break;case"ClaimReward":a=ta.fromData(e.intentionData);break;case"EntryClaimAndDeposit":a=ea.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n})}};var ke=require("@msafe/sui3-utils"),hc=require("@mysten/bcs"),gc=require("@mysten/sui/transactions"),yc=q(require("sort-keys-recursive")),Tc="msafe-plain-tx",Cc=ke.TransactionSubTypes.others.plain,Ar=class o{constructor(e){this.data=e}application=Tc;txType=ke.TransactionType.Other;txSubType=Cc;serialize(){return JSON.stringify((0,yc.default)(this.data))}async build(e){return gc.Transaction.from((0,hc.fromHex)(this.data.content))}static fromData(e){return new o(e)}},ca=class{application;supportSDK="@mysten/sui";constructor(){this.application=Tc}async deserialize(e){let{content:t}=e.appContext;return{txType:ke.TransactionType.Other,txSubType:Cc,intentionData:{content:t}}}async build(e){let{suiClient:t,network:n,account:a}=e;return Ar.fromData(e.intentionData).build({suiClient:t,network:n,account:a})}};var Rr=require("@mysten/sui/client"),Ic=require("@mysten/sui/transactions"),ua=require("@mysten/sui.js/client"),Sc=require("@mysten/sui.js/transactions");var qt=require("@open-rpc/client-js");var Qd={"-32700":"ParseError","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError"},Or=class extends Error{},la=class extends Or{code;type;constructor(e,t){super(e),this.code=t,this.type=Qd[t]??"ServerError"}};function zd(o){let e=new URL(o);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var Jd={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},da=class{endpoint;options;#n=0;#o=0;#t=null;#e=null;#r=new Set;#a=new Map;constructor(e,t={}){this.endpoint=e,this.options={...Jd,...t},this.endpoint&&this.endpoint.startsWith("http")&&(this.endpoint=zd(this.endpoint))}async makeRequest(e,t){let n=await this.#i();return new Promise((a,r)=>{this.#n+=1,this.#a.set(this.#n,{resolve:a,reject:r,timeout:setTimeout(()=>{this.#a.delete(this.#n),r(new Error(`Request timeout: ${e}`))},this.options.callTimeout)}),n.send(JSON.stringify({jsonrpc:"2.0",id:this.#n,method:e,params:t}))}).then(({error:a,result:r})=>{if(a)throw new la(a.message,a.code);return r})}#i(){return this.#e?this.#e:(this.#e=new Promise(e=>{this.#t?.close(),this.#t=new this.options.WebSocketConstructor(this.endpoint),this.#t.addEventListener("open",()=>{this.#o=0,e(this.#t)}),this.#t.addEventListener("close",()=>{this.#o++,this.#o<=this.options.maxReconnects&&setTimeout(()=>{this.#s()},this.options.reconnectTimeout)}),this.#t.addEventListener("message",({data:t})=>{let n;try{n=JSON.parse(t)}catch(a){console.error(new Error(`Failed to parse RPC message: ${t}`,{cause:a}));return}if("id"in n&&n.id!=null&&this.#a.has(n.id)){let{resolve:a,timeout:r}=this.#a.get(n.id);clearTimeout(r),a(n)}else if("params"in n){let{params:a}=n;this.#r.forEach(r=>{r.subscriptionId===a.subscription&&a.subscription===r.subscriptionId&&r.onMessage(a.result)})}})}),this.#e)}async#s(){return this.#t?.close(),this.#e=null,Promise.allSettled([...this.#r].map(e=>e.subscribe(this)))}async subscribe(e){let t=new Pr(e);return this.#r.add(t),await t.subscribe(this),()=>t.unsubscribe(this)}},Pr=class{subscriptionId=null;input;subscribed=!1;constructor(e){this.input=e}onMessage(e){this.subscribed&&this.input.onMessage(e)}async unsubscribe(e){let{subscriptionId:t}=this;return this.subscribed=!1,t==null?!1:(this.subscriptionId=null,e.makeRequest(this.input.unsubscribe,[t]))}async subscribe(e){this.subscriptionId=null,this.subscribed=!0;let t=await e.makeRequest(this.input.method,this.input.params);this.subscribed&&(this.subscriptionId=t)}};var dt=class{rpcClient;websocketClient;constructor({url:e,websocket:{url:t,...n}={},rpc:a}){let r=new qt.HTTPTransport(a?.url??e,{headers:{"Content-Type":"application/json",...a?.headers}});this.rpcClient=new qt.Client(new qt.RequestManager([r])),this.websocketClient=new da(t??e,n)}async request(e){return await this.rpcClient.request(e)}async subscribe(e){let t=await this.websocketClient.subscribe(e);return async()=>!!await t()}};var ma=class o{apps;constructor(){this.apps=new Map}static fromHelpers(e){let t=new o;for(let n=0;n<e.length;n++){let a=e[n];switch(a.supportSDK){case"@mysten/sui.js":t.addLegacyHelper(a);break;case"@mysten/sui":t.addHelper(a);break;default:throw new Error(`${a.application}: ${a.supportSDK} SDK not supported`)}}return t}addLegacyHelper(e){this.apps.set(e.application,new _r(e))}addHelper(e){this.apps.set(e.application,new Br(e))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}},Br=class{constructor(e){this.helper=e}async deserialize(e){let t=new Rr.SuiClient({transport:new dt({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=new ua.SuiClient({transport:new dt({url:e.clientUrl,rpc:{url:e.clientUrl}})}),a=await e.transactionBlock.build({client:n}),r=Ic.Transaction.from(a);return this.helper.deserialize({...e,suiClient:t,transaction:r})}async build(e){let t=new Rr.SuiClient({transport:new dt({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<1e8)throw new Error("Insufficient gas fee");let a=await this.helper.build({...e,suiClient:t});a.setSender(e.account.address);let r=await a.build({client:t});return Sc.TransactionBlock.from(r)}},_r=class{constructor(e){this.helper=e}async deserialize(e){let t=new ua.SuiClient({transport:new dt({url:e.clientUrl,rpc:{url:e.clientUrl}})});return this.helper.deserialize({...e,transactionBlock:e.transactionBlock,suiClient:t})}async build(e){let t=new ua.SuiClient({transport:new dt({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<1e8)throw new Error("Insufficient gas fee");return this.helper.build({...e,suiClient:t})}};var Rc=require("@msafe/sui3-utils"),Lr=require("@scallop-io/sui-scallop-sdk");var x=require("@msafe/sui3-utils"),Wr=require("@scallop-io/sui-scallop-sdk");var wc=require("@mysten/sui/utils"),ut=class{constructor(e,t){this.transaction=e;this.scallopClient=t;this.scallopClient=t,this.inputs=e.getData().inputs,this.commands=e.getData().commands,this.movecallsAsSet=new Set(this.commands.filter(this.isMoveCall).map(n=>`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`))}inputs;commands;movecallsAsSet;get address(){return this.scallopClient.address}get utils(){return this.scallopClient.utils}get coreId(){return{protocolPkg:this.address.get("core.packages.protocol.id"),market:this.address.get("core.market"),version:this.address.get("core.version"),coinDecimalsRegistry:this.address.get("core.coinDecimalsRegistry"),xOracle:this.address.get("core.oracles.xOracle"),spoolPkg:this.address.get("spool.id"),borrowIncentivePkg:this.address.get("borrowIncentive.id"),veScaPkgId:this.address.get("vesca.id"),scoin:this.address.get("scoin.id"),referral:this.address.get("referral.id")}}matchMoveCallCommand(e,t){let{address:n,module:a,name:r}=(0,wc.parseStructTag)(t);return e?e.package===n&&e.module===a&&e.function===r:!1}isMoveCall(e){return e.$kind==="MoveCall"&&!!e.MoveCall}filterMoveCallCommands(e,t){return this.isMoveCall(e)&&this.matchMoveCallCommand(e.MoveCall,t)}getMoveCallCommands(e){let t=new Set(e),n=e.reduce((r,i,s)=>(r[i]=s,r),{}),a=[];return this.commands.forEach(r=>{this.isMoveCall(r)&&r.MoveCall&&t.has(r.MoveCall.package)&&(a[n[r.MoveCall.package]]=r.MoveCall)}),a}hasMoveCallCommand(e){return this.movecallsAsSet.has(e)}};var pa=require("@mysten/sui/bcs"),mt=require("@mysten/sui/utils"),Er=class o{constructor(e,t){this.moveCall=e;this.transaction=t;this.cmdIdx=e?.MoveCall?t.getData().commands.findIndex(n=>{if(n.$kind==="MoveCall"){let a=`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`,r=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;return a===r}return!1}):-1}cmdIdx;get txBlockTransactions(){return this.transaction.blockData.transactions[this.cmdIdx]}decodeSharedObjectId(e){let t=this.getInputParam(e);return o.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return o.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"U64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"U8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"Address");return(0,mt.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"String")}decodeInputBool(e){return this.decodePureArg(e,"Bool")}decodePureArg(e,t){let n=this.getInputParam(e);return o.getPureInputValue(n,t)}getInputParam(e){let t=this.txBlockTransactions.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return t}getNestedInputParam(e){let t=this.txBlockTransactions.arguments[e];if(t.kind!=="NestedResult")throw new Error("not input type");return this.transaction.blockData.transactions[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure,a=pa.bcs[t];return pa.bcs[t].parse(new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,mt.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,mt.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,mt.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,mt.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let t=e.value.Pure;return pa.bcs.U64.parse(new Uint8Array(t))}typeArg(e){return(0,mt.normalizeStructTag)(this.txBlockTransactions.typeArguments[e])}txArg(e){return this.transaction.blockData.inputs[e]}},T=Er;var Mr=class{constructor(e,t){this.splitCoin=e;this.txb=t}getAmountInput(){return this.splitCoin.amounts.map(e=>{if(e.kind==="Input")return Number(T.getPureInputValue(e,"U64"))}).filter(e=>e!==void 0)}},O=Mr;var pt=require("@mysten/sui/utils"),kc=async(o,e)=>{let t=await o.suiKit.client().getObject({id:e,options:{showContent:!0}});if(t?.data?.content?.dataType!=="moveObject")return!1;let a=t.data.content.fields.lock_key?.fields.name;if(!a)return!1;let r=o.address.get("borrowIncentive.object");return a===`${r.slice(2)}::incentive_account::IncentiveProgramLockKey`},Kt={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},N={unstakeObligation:(o,e,t)=>o.moveCall(`${Kt.id}::user::unstake`,[Kt.incentivePools,Kt.incentiveAccounts,o.object(e),o.object(t),pt.SUI_CLOCK_OBJECT_ID],[(0,pt.normalizeStructTag)(pt.SUI_TYPE_ARG)]),redeem_rewards:(o,e,t,n)=>o.moveCall(`${Kt.id}::user::redeem_rewards`,[Kt.incentivePools,Kt.incentiveAccounts,o.object(e),o.object(t),pt.SUI_CLOCK_OBJECT_ID],[(0,pt.normalizeStructTag)(n)])};var fa=class extends ut{decode(){if(this.isSupplyWithStakeSpoolTransaction())return this.decodeSupplyWithStakeSpool();if(this.isUnstakeAndWithdrawTransaction())return this.decodeUnstakeAndWithdraw();if(this.isStakeSpoolTransaction())return this.decodeStakeSpool();if(this.isDepositCollateralTransaction())return this.decodeDepositCollateral();if(this.isWithdrawCollateralTransaction())return this.decodeWithdrawCollateral();if(this.isWithdrawLendingScoinTransaction())return this.decodeWithdrawLendingScoin();if(this.isWithdrawLendingTransaction())return this.decodeWithdrawLending();if(this.isSupplyLendingTransaction())return this.decodeSupplyLending();if(this.isBorrowWithReferralTransaction())return this.decodeBorrowWithReferral();if(this.isBorrowWithBoostTransaction())return this.decodeBorrowWithBoost();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayWithBoostTransaction())return this.decodeRepayWithBoost();if(this.isRepayTransaction())return this.decodeRepay();if(this.isUnstakeSpoolTransaction())return this.decodeUnstakeSpool();if(this.isMigrateAndClaim())return this.decodeMigrateAndClaim();if(this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isOpenObligationTransaction())return this.decodeOpenObligation();if(this.isMigrateScoinTransaction())return this.decodeMigrateScoin()}isMigrateScoinTransaction(){return this.hasMoveCallCommand(`${this.coreId.scoin}::s_coin_converter::mint_s_coin`)}isSupplyLendingTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::mint::mint`)}isSupplyWithStakeSpoolTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::mint::mint`),t=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::stake`);return e&&t}isUnstakeAndWithdrawTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::unstake`),t=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`);return e&&t}isStakeSpoolTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::stake`)}isWithdrawLendingTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`)}isWithdrawLendingScoinTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`),t=this.hasMoveCallCommand(`${this.coreId.scoin}::s_coin_converter::burn_s_coin`);return e&&t}isDepositCollateralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`)}isWithdrawCollateralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`)}isBorrowTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow`)}isBorrowWithBoostTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`);return e&&t}isBorrowWithReferralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow_with_referral`)}isRepayTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::repay::repay`)}isRepayWithBoostTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::repay::repay`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`);return e&&t}isUnstakeSpoolTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::unstake`)}isCreateStakeAccountTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::new_spool_account`)}isClaimRewardTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::redeem_rewards`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`);return e||t}isOpenObligationTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::open_obligation::open_obligation`)}isMigrateAndClaim(){let e=this.hasMoveCallCommand(`${Wr.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::redeem_rewards`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`),n=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake`);return e&&(t||n)}get helperClaimLendingReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::redeem_rewards`)).map(t=>new T(t,this.transaction))}get helperClaimBorrowV2Reward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`)).map(t=>new T(t,this.transaction))}get helperStakeObligationWithVeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`));return new T(e,this.transaction)}get helperClaimBorrowReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${Wr.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::redeem_rewards`)).map(t=>new T(t,this.transaction))}get helperMint(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::mint::mint`));return new T(e,this.transaction)}get helperUnstakes(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::unstake`)).map(t=>new T(t,this.transaction))}get helperRedeems(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::redeem::redeem`)).map(t=>new T(t,this.transaction))}get helperRedeem(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::redeem::redeem`));return new T(e,this.transaction)}get helperBurnScoin(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.scoin}::s_coin_converter::burn_s_coin`));return new T(e,this.transaction)}get helperStake(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::stake`));return new T(e,this.transaction)}get helperUnstake(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::unstake`));return new T(e,this.transaction)}get helperDepositCollateral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`));return new T(e,this.transaction)}get helperWithdrawCollateral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`));return new T(e,this.transaction)}get helperBorrow(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::borrow::borrow`));return new T(e,this.transaction)}get helperBorrowWithReferral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::borrow::borrow_with_referral`));return new T(e,this.transaction)}get helperRepay(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::repay::repay`));return new T(e,this.transaction)}decodeMigrateScoin(){return{txType:x.TransactionType.Other,type:"MigrateScoin",intentionData:{}}}decodeMigrateAndClaim(){let e;this.helperStakeObligationWithVeSca.moveCall&&(e=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9));let t=this.helperClaimBorrowReward[0].decodeOwnedObjectId(2),n=this.helperClaimBorrowReward[0].decodeSharedObjectId(3),a=this.utils.parseCoinNameFromType(this.helperClaimBorrowReward[0].typeArg(0));return{txType:x.TransactionType.Other,type:"MigrateAndClaim",intentionData:{obligationKey:t,obligationId:n,rewardCoinName:a,veScaKey:e}}}decodeOpenObligation(){return{txType:x.TransactionType.Other,type:"OpenObligation",intentionData:{}}}decodeSupplyLending(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new O(t,this.transaction).getAmountInput().reduce((a,r)=>a+r,0);return{txType:x.TransactionType.Other,type:"SupplyLending",intentionData:{amount:n,coinName:e}}}decodeWithdrawLending(){let e=this.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0)),t=this.helperRedeem.getNestedInputParam(2),n=new O(t,this.transaction).getAmountInput().reduce((a,r)=>a+r,0);return{txType:x.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:n,coinName:e}}}decodeWithdrawLendingScoin(){let e=this.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0));console.log({coinName:e});let t=this.helperBurnScoin.getNestedInputParam(1),n=new O(t,this.transaction).getAmountInput().reduce((a,r)=>a+r,0);return{txType:x.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:n,coinName:e}}}decodeDepositCollateral(){let e=this.utils.parseCoinNameFromType(this.helperDepositCollateral.typeArg(0)),t=this.helperDepositCollateral.getNestedInputParam(3),n=new O(t,this.transaction).getAmountInput().reduce((r,i)=>r+i,0),a=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:x.TransactionType.Other,type:"DepositCollateral",intentionData:{amount:n,obligationId:a,collateralCoinName:e}}}decodeWithdrawCollateral(){let e=this.utils.parseCoinNameFromType(this.helperWithdrawCollateral.typeArg(0)),t=this.helperWithdrawCollateral.decodeInputU64(5),n=this.helperWithdrawCollateral.decodeSharedObjectId(1),a=this.helperWithdrawCollateral.decodeOwnedObjectId(2);return{txType:x.TransactionType.Other,type:"WithdrawCollateral",intentionData:{amount:t,collateralCoinName:e,obligationKey:a,obligationId:n}}}decodeBorrow(){let e=this.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperBorrow.decodeInputU64(5),n=this.helperBorrow.decodeSharedObjectId(1),a=this.helperBorrow.decodeOwnedObjectId(2);return{txType:x.TransactionType.Other,type:"Borrow",intentionData:{amount:t,coinName:e,obligationKey:a,obligationId:n}}}decodeBorrowWithBoost(){let e=this.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),n=this.helperBorrow.decodeInputU64(5),a=this.helperBorrow.decodeSharedObjectId(1),r=this.helperBorrow.decodeOwnedObjectId(2);return{txType:x.TransactionType.Other,type:"BorrowWithBoost",intentionData:{amount:n,coinName:e,obligationKey:r,obligationId:a,veScaKey:t}}}decodeBorrowWithReferral(){let e=this.utils.parseCoinNameFromType(this.helperBorrowWithReferral.typeArg(0)),t;this.helperStakeObligationWithVeSca.moveCall&&(t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9));let n=this.helperBorrowWithReferral.decodeInputU64(6),a=this.helperBorrowWithReferral.decodeSharedObjectId(1),r=this.helperBorrowWithReferral.decodeOwnedObjectId(2);return{txType:x.TransactionType.Other,type:"BorrowWithReferral",intentionData:{amount:n,coinName:e,obligationKey:r,obligationId:a,veScaKey:t}}}decodeRepay(){let e=this.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperRepay.getNestedInputParam(3),n=new O(t,this.transaction).getAmountInput().reduce((r,i)=>r+i,0),a=this.helperRepay.decodeSharedObjectId(1);return{txType:x.TransactionType.Other,type:"Repay",intentionData:{amount:n,obligationId:a,coinName:e}}}decodeRepayWithBoost(){let e=this.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),n=this.helperRepay.getNestedInputParam(3),a=new O(n,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),r=this.helperRepay.decodeSharedObjectId(1);return{txType:x.TransactionType.Other,type:"RepayWithBoost",intentionData:{amount:a,obligationId:r,coinName:e,veScaKey:t}}}decodeStakeSpool(){let e;this.isCreateStakeAccountTransaction()||(e=this.helperStake.decodeOwnedObjectId(1));let t=0;if(this.helperBurnScoin.moveCall){let r=this.helperBurnScoin.getNestedInputParam(1);t=new O(r,this.transaction).getAmountInput().reduce((i,s)=>i+s,0)}if(this.helperStake.moveCall&&t===0){let r=this.helperStake.getNestedInputParam(2);t=new O(r,this.transaction).getAmountInput().reduce((i,s)=>i+s,0)}let n=this.helperStake.typeArg(0),a=this.utils.parseCoinNameFromType(n);return{txType:x.TransactionType.Other,type:"StakeSpool",intentionData:{amount:t,marketCoinName:a,stakeAccountId:e}}}decodeUnstakeSpool(){let e=this.helperUnstake.decodeOwnedObjectId(1),t=this.helperUnstake.decodeInputU64(2),n=this.helperUnstake.typeArg(0),a=this.utils.parseCoinNameFromType(n);return{txType:x.TransactionType.Other,type:"UnstakeSpool",intentionData:{amount:t,marketCoinName:a,stakeAccountId:e}}}decodeSupplyWithStakeSpool(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new O(t,this.transaction).getAmountInput().reduce((r,i)=>r+i,0),a;return this.isCreateStakeAccountTransaction()||(a=this.helperStake.decodeOwnedObjectId(1)),{txType:x.TransactionType.Other,type:"SupplyAndStakeLending",intentionData:{amount:n,coinName:e,stakeAccountId:a}}}decodeUnstakeAndWithdraw(){let e=[];this.helperUnstakes.forEach(a=>{let r=a.decodeOwnedObjectId(1),i=a.decodeInputU64(2);e.push({id:r,coin:i})});let t=this.utils.parseCoinNameFromType(this.helperRedeems[0].typeArg(0)),n=0;if(this.helperBurnScoin.moveCall){let a=this.helperBurnScoin.getNestedInputParam(1);n=new O(a,this.transaction).getAmountInput().reduce((r,i)=>r+i,0)}return{txType:x.TransactionType.Other,type:"WithdrawAndUnstakeLending",intentionData:{amount:n,coinName:t,stakeAccountId:e}}}decodeClaimReward(){let e=[],t=[],n=[];return this.helperClaimLendingReward.forEach(a=>{let r=a.decodeOwnedObjectId(2),i=a.typeArg(0),s=this.utils.parseCoinNameFromType(i);e.push({stakeMarketCoinName:s,stakeAccountId:r})}),this.helperClaimBorrowV2Reward.forEach(a=>{let r=a.decodeSharedObjectId(3),i=a.decodeOwnedObjectId(4),s=this.utils.parseCoinNameFromType(a.typeArg(0));t.push({obligationId:i,obligationKey:r,rewardCoinName:s})}),this.helperClaimBorrowReward.forEach(a=>{let r=a.decodeSharedObjectId(2),i=a.decodeOwnedObjectId(3),s=this.utils.parseCoinNameFromType(a.typeArg(0));n.push({obligationId:i,obligationKey:r,rewardCoinName:s})}),{txType:x.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:n}}}};var ba=require("@msafe/sui3-utils");var ha=class extends ut{decode(){if(this.isCreateReferralLink())return this.decodeCreateReferralLink();if(this.isClaimRevenueReferral())return this.decodeClaimRevenueReferral();if(this.isBindReferral())return this.decodeBindReferral()}isClaimRevenueReferral(){return this.hasMoveCallCommand(`${this.coreId.referral}::referral_revenue_pool::claim_revenue_with_ve_sca_key`)}isCreateReferralLink(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_placeholder_key`)}isBindReferral(){return this.hasMoveCallCommand(`${this.coreId.referral}::referral_bindings::bind_ve_sca_referrer`)}get helperClaimRevenueReferral(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.referral}::referral_revenue_pool::claim_revenue_with_ve_sca_key`)).map(t=>new T(t,this.transaction))}get helperBindReferral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.referral}::referral_bindings::bind_ve_sca_referrer`));return new T(e,this.transaction)}decodeCreateReferralLink(){return{txType:ba.TransactionType.Other,type:"CreateReferralLink",intentionData:{}}}decodeClaimRevenueReferral(){let e=this.helperClaimRevenueReferral[0].decodeOwnedObjectId(2),t=this.helperClaimRevenueReferral.map(n=>n.typeArg(0));return{txType:ba.TransactionType.Other,type:"ClaimRevenueReferral",intentionData:{veScaKey:e,coins:t}}}decodeBindReferral(){let e=this.helperBindReferral.decodePureArg(1,"Address");return{txType:ba.TransactionType.Other,type:"BindReferral",intentionData:{veScaKey:e}}}};var $t=require("@msafe/sui3-utils"),xc=require("@scallop-io/sui-scallop-sdk");var ga=class extends ut{decode(){if(this.isExtendPeriodAndStakeMoreSca())return this.decodePeriodAndStakeMoreSca();if(this.isStakeScaFirsTime()||this.isStakeMoreSca())return this.decodeStakeSca();if(this.isRenewExpiredVeSca())return this.decodeRenewExpiredVeSca();if(this.isExtendPeriod())return this.decodeExtendStakePeriod();if(this.isRedeemSca())return this.decodeRedeemSca()}isStakeScaFirsTime(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`)}isExtendPeriodAndStakeMoreSca(){let e=this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`),t=this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`);return!!e&&!!t}isRedeemSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::redeem`)}isStakeMoreSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`)}isExtendPeriod(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`)}isRenewExpiredVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`)}get helperStakeMoreSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`));return new T(e,this.transaction)}get helperStakeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`));return new T(e,this.transaction)}get helperExtendStakePeriod(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`));return new T(e,this.transaction)}get helperRedeemSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::redeem`));return new T(e,this.transaction)}get helperRenewExpired(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`));return new T(e,this.transaction)}get helperOldUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${xc.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake`));return new T(e,this.transaction)}get helperUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::unstake`));return new T(e,this.transaction)}get helperStakeObligationWithVeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`));return new T(e,this.transaction)}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:$t.TransactionType.Other,type:"RedeemSca",intentionData:{veScaKey:e}}}decodeRenewExpiredVeSca(){let e=this.helperRenewExpired.getNestedInputParam(4),t=this.helperRenewExpired.decodeInputU64(5),n=new O(e,this.transaction).getAmountInput().reduce((b,y)=>b+y,0),a=this.helperRenewExpired.decodeOwnedObjectId(1),r=!!this.helperRedeemSca.moveCall,i=[],s=[],c=[];this.helperOldUnstakeObligation.moveCall&&(i=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(s=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(c=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let l=!1,d=!1,m,p,f=[{condition:i,isOld:!0},{condition:s,isOld:!1},{condition:c,isOld:!1}];for(let b=0;b<f.length;b++)f[b].condition.length>1&&([p,m]=f[b].condition,l=!0,d=f[b].isOld);return{txType:$t.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:n,unlockTime:t,obligationId:m,obligationKey:p,veScaKey:a,isHaveRedeem:r,isObligationLocked:l,isOldBorrowIncentive:d}}}decodeExtendStakePeriod(){let e=this.helperExtendStakePeriod.decodeInputU64(4),t=this.helperExtendStakePeriod.decodeOwnedObjectId(1),n=[],a=[],r=[];this.helperOldUnstakeObligation.moveCall&&(n=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(a=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(r=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let i=!1,s=!1,c,l,d=[{condition:n,isOld:!0},{condition:a,isOld:!1},{condition:r,isOld:!1}];for(let m=0;m<d.length;m++)d[m].condition.length>1&&([l,c]=d[m].condition,i=!0,s=d[m].isOld);return{txType:$t.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{unlockTime:e,obligationId:c,obligationKey:l,veScaKey:t,isObligationLocked:i,isOldBorrowIncentive:s}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),n=new O(e,this.transaction).getAmountInput().reduce((f,b)=>f+b,0),a=[],r=[],i,s=[];this.helperOldUnstakeObligation.moveCall&&(a=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(r=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(i=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(s=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,l=!1,d,m,p=[{condition:a,isOld:!0},{condition:r,isOld:!1},{condition:s,isOld:!1}];for(let f=0;f<p.length;f++)p[f].condition.length>1&&([m,d]=p[f].condition,c=!0,l=p[f].isOld);return{txType:$t.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:n,veScaKey:i,unlockTime:t,obligationId:d,obligationKey:m,isOldBorrowIncentive:l,isObligationLocked:c}}}decodeStakeSca(){let e,t;this.helperStakeSca.moveCall&&this.helperStakeMoreSca.moveCall===void 0?(e=this.helperStakeSca.getNestedInputParam(3),t=this.helperStakeSca.decodeInputU64(4)):e=this.helperStakeMoreSca.getNestedInputParam(4);let n=new O(e,this.transaction).getAmountInput().reduce((f,b)=>f+b,0),a=[],r=[],i,s=[];this.helperOldUnstakeObligation.moveCall&&(a=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(r=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(i=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(s=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,l=!1,d,m,p=[{condition:a,isOld:!0},{condition:r,isOld:!1},{condition:s,isOld:!1}];for(let f=0;f<p.length;f++)p[f].condition.length>1&&([m,d]=p[f].condition,c=!0,l=p[f].isOld);return{txType:$t.TransactionType.Other,type:"StakeSca",intentionData:{amount:n,unlockTime:t,obligationId:d,obligationKey:m,veScaKey:i,isObligationLocked:c,isOldBorrowIncentive:l}}}};var Dc=q(require("sort-keys-recursive")),g=class{constructor(e){this.data=e}get application(){return"msafe-core"}serialize(){return JSON.stringify((0,Dc.default)(this.data))}isObligationLocked=async(e,t)=>{let n=await e.getObject({id:typeof t=="string"?t:t.objectId,options:{showContent:!0}}),a=!1;return n&&n?.data.content?.dataType==="moveObject"&&"lock_key"in n.data.content.fields&&(a=!!n.data.content.fields.lock_key),a};async buildTxWithRefreshObligation(e,t,n){let a=e.builder.createTxBlock();a.setSender(t.walletAddress);let{obligationId:r,obligationKey:i}=t;return await this.isObligationLocked(e.suiKit.client(),r)?(await a.unstakeObligationQuick(r,i),await n(e,a,t),await a.stakeObligationWithVeScaQuick(r,i,t.veScaKey)):await n(e,a,t),a}};var ya=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async borrow({account:t,scallopClient:n}){let{coinName:a,amount:r,obligationId:i,obligationKey:s}=this.data,c=t.address;return(await this.buildTxWithRefreshObligation(n,{walletAddress:c,obligationId:i,obligationKey:s},async(d,m)=>{let p=await m.borrowQuick(+r,a,i,s);m.transferObjects([p],c)})).txBlock}async build(t){return this.borrow(t)}static fromData(t){return new o(t)}};var Ta=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithBoost(t,n,a){let{obligationId:r,obligationKey:i,veScaKey:s,amount:c,coinName:l}=this.data;return(await this.buildTxWithRefreshObligation(t,{walletAddress:a,obligationId:r,obligationKey:i,veScaKey:s},async(m,p)=>{let f=await p.borrowQuick(+c,l,r,i);p.transferObjects([f],a)})).txBlock}async build(t){return this.borrowWithBoost(t.scallopClient,this.data,t.account.address)}static fromData(t){return new o(t)}};var Ca=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithReferral({account:t,scallopClient:n}){let a=t.address,{obligationId:r,obligationKey:i,veScaKey:s,coinName:c,amount:l}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:a,obligationId:r,obligationKey:i,veScaKey:s},async(m,p)=>{let f=p.claimReferralTicket(c),b=await p.borrowWithReferralQuick(+l,c,f,r,i);p.burnReferralTicket(f,c),p.transferObjects([b],a)})).txBlock}async build(t){return this.borrowWithReferral(t)}static fromData(t){return new o(t)}};var vc=require("@mysten/sui/utils");var Ia=class o extends g{txType;txSubType;constructor(e={}){super(e)}async claimIncentiveRewards(e,t){let n=e.builder.createTxBlock();n.setSender(t);let a=await e.query.getAllStakeAccounts(t),r=await e.query.getLendings(void 0,t),i=await e.query.getObligations(t),s=Object.values(await e.query.getObligationAccounts(t)??[]),c=(()=>{let p=[...e.constants.whitelist.spool].map(f=>e.utils.parseCoinName(f));return Object.values(r??[]).filter(f=>!!f&&p.includes(f.coinName)).reduce((f,b)=>{let y=e.utils.parseMarketCoinName(b.coinName);return f[y]||(f[y]=0),f[y]+=b.availableClaimCoin,f},{})})(),l={};Object.entries(a).forEach(([p,f])=>{for(let b=0;b<f.length;b++){let y=f[b];if(!c[p])continue;let A=n.claim(y.id,p);l.sui?l.sui.push(A):l.sui=[A]}});let d=(()=>{let p={};return p.sui=Object.values(c).reduce((f,b)=>f+b,0),s.forEach(f=>{Object.values(f.borrowIncentives).forEach(b=>{b&&b.rewards.forEach(y=>{p[y.coinName]||(p[y.coinName]=0),p[y.coinName]?p[y.coinName]+=y.availableClaimCoin:p[y.coinName]=y.availableClaimCoin})})}),p})();if(i.length>0&&s.length>0)for(let p=0;p<s.length;p++){let f=s[p],b=!1,y=i.find(B=>B.id===f.obligationId)?.keyId,A={};if(y){if(Object.values(f.borrowIncentives).forEach(B=>{if(B){let Yt=B.rewards.filter(X=>{let Ae=X.coinName;return X.availableClaimCoin>0&&!A[Ae]});b=Yt.length>0,Yt.forEach(X=>{let Ae=n.claimBorrowIncentive(f.obligationId,y,X.coinName);A[X.coinName]=!0,l[X.coinName]?l[X.coinName].push(Ae):l[X.coinName]=[Ae]})}}),d.sui>0){let B=N.redeem_rewards(n,y,f.obligationId,vc.SUI_TYPE_ARG);l.sui?l.sui.push(B):l.sui=[B]}if(b&&await kc(e.query,f.obligationId)){n.unstakeObligation(f.obligationId,y);let Yt=await e.query.getBindedVeScaKey(f.obligationId);Yt?n.stakeObligationWithVesca(f.obligationId,y,Yt):n.stakeObligation(f.obligationId,y)}}}let m=(await Promise.all(Object.entries(l).map(async([p,f])=>{let b=f[0];if(f.length>1&&n.mergeCoins(b,f.slice(1)),p==="sui"){n.mergeCoins(n.gas,[b]);return}return await e.builder.utils.mergeSimilarCoins(n,b,e.utils.parseCoinType(p),t),b}))).filter(p=>!!p);return m.length>0&&n.transferObjects(m,t),n.txBlock}async build(e){return this.claimIncentiveRewards(e.scallopClient,e.account.address)}static fromData(e={}){return new o(e)}};var Sa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.depositCollateral(this.data.collateralCoinName,+this.data.amount,!1,this.data.obligationId)}static fromData(t){return new o(t)}};var wa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async migrateAndClaim({account:t,scallopClient:n}){let a=t.address,{obligationKey:r,obligationId:i,rewardCoinName:s,veScaKey:c}=this.data,l=n.builder.createTxBlock();l.setSender(a);let d=N.redeem_rewards(l,r,i,n.utils.parseCoinType(s));return l.transferObjects([d],a),await l.unstakeObligationQuick(i,r),c?await l.stakeObligationWithVeScaQuick(i,r,c):await l.stakeObligationQuick(i,r),l.txBlock}async build(t){return this.migrateAndClaim(t)}static fromData(t){return new o(t)}};var ka=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.migrateAllMarketCoin(!1,!1)}static fromData(t){return new o(t)}};var xa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.openObligation(!1)}static fromData(t){return new o(t)}};var Da=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async repay({account:t,scallopClient:n}){let a=t.address,{coinName:r,amount:i,obligationId:s,obligationKey:c}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:a,obligationId:s,obligationKey:c},async(d,m)=>{await m.repayQuick(+i,r,s)})).txBlock}async build(t){return this.repay(t)}static fromData(t){return new o(t)}};var va=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async repayWithBoost({account:t,scallopClient:n}){let a=t.address,{coinName:r,amount:i,obligationId:s,veScaKey:c}=this.data,l=n.builder.createTxBlock();l.setSender(a);let d=n.constants.whitelist.borrowing.has(r);return d&&await l.unstakeObligationQuick(s,void 0),await l.repayQuick(+i,r,s),d&&await l.stakeObligationWithVeScaQuick(s,void 0,c),l.txBlock}async build(t){return this.repayWithBoost(t)}static fromData(t){return new o(t)}};var Aa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.deposit(this.data.coinName,+this.data.amount,!1,t.account.address)}static fromData(t){return new o(t)}};var Oa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.unstake(this.data.marketCoinName,+this.data.amount,!1)}static fromData(t){return new o(t)}};var Pa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async unstakeAndWithdraw(t,n,a){let r=t.builder.createTxBlock();r.setSender(a);let{stakeAccountId:i,amount:s,coinName:c}=this.data,l=[];for(let d=0;d<i.length;d++){let{id:m,coin:p}=i[d],f=t.utils.parseMarketCoinName(c),[b]=await r.unstakeQuick(p,f,m);if(b){let y=r.withdraw(b,c);l.push(y)}}if(s>0){let d=await r.withdrawQuick(s,c);l.push(d)}return l.length>1&&r.mergeCoins(l[0],l.slice(1)),r.transferObjects(l,a),r.txBlock}async build(t){return this.unstakeAndWithdraw(t.scallopClient,this.data,t.account.address)}static fromData(t){return new o(t)}};var Ra=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.withdrawCollateral(this.data.collateralCoinName,Number(this.data.amount),!1,this.data.obligationId,this.data.obligationKey,t.account.address)}static fromData(t){return new o(t)}};var Ba=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.withdraw(this.data.coinName,Number(this.data.amount),!1,t.account.address)}static fromData(t){return new o(t)}};var _a=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async bindReferral({account:t,scallopClient:n}){let a=t.address,r=n.builder.createTxBlock();return r.setSender(a),r.bindToReferral(this.data.veScaKey),r.txBlock}async build(t){return this.bindReferral(t)}static fromData(t){return new o(t)}};var Ea=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async claimRevenueReferral({account:t,scallopClient:n}){let{veScaKey:a,coins:r}=this.data,i=t.address,s=n.builder.createTxBlock();s.setSender(i);let c=r.map(l=>n.utils.parseCoinNameFromType(l));return await s.claimReferralRevenueQuick(a,c),s.txBlock}async build(t){return this.claimRevenueReferral(t)}static fromData(t){return new o(t)}};var Ma=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async createReferralLink({account:t,scallopClient:n}){let a=t.address,r=n.builder.createTxBlock();r.setSender(a);let i=r.mintEmptyVeSca();return r.transferObjects([i],a),r.txBlock}async build(t){return this.createReferralLink(t)}static fromData(t){return new o(t)}};var Ac=require("@scallop-io/sui-scallop-sdk");var Wa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async extendPeriodAndStakeMoreSca({account:t,scallopClient:n}){let{amount:a,veScaKey:r,unlockTime:i,obligationId:s,obligationKey:c,isOldBorrowIncentive:l,isObligationLocked:d}=this.data,m=t.address,p=n.builder.createTxBlock();p.setSender(m);let f=await n.utils.selectCoins(a,Ac.SCA_COIN_TYPE,m),[b,y]=p.takeAmountFromCoins(f,a);return p.extendLockPeriod(r,i),p.extendLockAmount(r,b),p.transferObjects([y],m),!s||!c||(d&&(l?N.unstakeObligation(p,s,c):p.unstakeObligation(s,c)),p.stakeObligationWithVesca(s,c,r)),p.txBlock}async build(t){return this.extendPeriodAndStakeMoreSca(t)}static fromData(t){return new o(t)}};var Na=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async extendStakeScaLockPeriod({account:t,scallopClient:n}){let a=t.address,{veScaKey:r,unlockTime:i,obligationId:s,obligationKey:c,isObligationLocked:l,isOldBorrowIncentive:d}=this.data,m=n.builder.createTxBlock();return m.setSender(a),m.extendLockPeriod(r,i),s&&c&&(l&&(d?N.unstakeObligation(m,c,s):m.unstakeObligation(s,c)),m.stakeObligationWithVesca(s,c,r)),m.txBlock}async build(t){return this.extendStakeScaLockPeriod(t)}static fromData(t){return new o(t)}};var La=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async redeemSca({account:t,scallopClient:n}){let{veScaKey:a}=this.data,r=t.address,i=n.builder.createTxBlock();return i.setSender(r),await i.redeemScaQuick(a),i.txBlock}async build(t){return this.redeemSca(t)}static fromData(t){return new o(t)}};var Oc=require("@scallop-io/sui-scallop-sdk");var ja=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async renewExpiredStakeSca({account:t,scallopClient:n}){let a=t.address,{amount:r,unlockTime:i,vescaKey:s,isHaveRedeem:c,obligation:l,obligationKey:d,isObligationLocked:m,isOldBorrowIncentive:p}=this.data,f=n.builder.createTxBlock();if(f.setSender(a),c){let B=f.redeemSca(s);f.transferObjects([B],a)}let b=await n.builder.utils.selectCoins(r,Oc.SCA_COIN_TYPE,a),[y,A]=f.takeAmountFromCoins(b,r);return f.transferObjects([A],a),f.renewExpiredVeSca(s,y,i),!l||!d||(m&&(p?N.unstakeObligation(f,d,l):f.unstakeObligation(l,d)),f.stakeObligationWithVesca(l,d,s)),f.txBlock}async build(t){return this.renewExpiredStakeSca(t)}static fromData(t){return new o(t)}};var Pc=require("@scallop-io/sui-scallop-sdk");var Ua=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async stakeSca({account:t,scallopClient:n}){let a=t.address,{amount:r,isObligationLocked:i,isOldBorrowIncentive:s,obligationId:c,obligationKey:l,unlockTime:d,veScaKey:m}=this.data,p=n.builder.createTxBlock();p.setSender(a);let f=await n.utils.selectCoins(r,Pc.SCA_COIN_TYPE,a),[b,y]=p.takeAmountFromCoins(f,r),A;return m?p.extendLockAmount(m,b):A=p.lockSca(b,d),c&&l&&(i&&(s?N.unstakeObligation(p,l,c):p.unstakeObligation(c,l)),p.stakeObligationWithVesca(c,l,m||A)),m||p.transferObjects([A,y],a),p.txBlock}async build(t){return this.stakeSca(t)}static fromData(t){return new o(t)}};var Fa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async supplyAndStake({account:t,scallopClient:n}){let a=t.address,{amount:r,coinName:i,stakeAccountId:s}=this.data,c=n.builder.createTxBlock();c.setSender(a);let l=await c.depositQuick(+r,i),d=n.utils.parseMarketCoinName(i);if(n.constants.whitelist.spool.has(d))return c.txBlock;let m=await n.query.getStakeAccounts(d,a),p=s||(m.length>0?m[0].id:void 0);if(p)await c.stakeQuick(l,d,p);else{let f=c.createStakeAccount(d);await c.stakeQuick(l,d,f),c.transferObjects([f],a)}return c.txBlock}async build(t){return this.supplyAndStake(t)}static fromData(t){return new o(t)}};var qa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async withdrawUnlockedSca({account:t,scallopClient:n}){let{vescaKey:a}=this.data,r=t.address,i=n.builder.createTxBlock();return i.setSender(r),await i.redeemScaQuick(a),i.txBlock}async build(t){return this.withdrawUnlockedSca(t)}static fromData(t){return new o(t)}};var Ka=class{application="scallop";supportSDK="@mysten/sui";scallopClient;async deserialize(e){if(!this.scallopClient){let s=new Lr.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e.account.address,suiClients:[e.suiClient]});this.scallopClient=await s.createScallopClient()}let{transaction:t}=e;console.log("transaction",t);let n=new fa(t,this.scallopClient),a=new ha(t,this.scallopClient),r=new ga(t,this.scallopClient),i=n.decode()||a.decode()||r.decode();if(!i)throw new Error("Unknown transaction type");return{txType:Rc.TransactionType.Other,txSubType:i.type,intentionData:i.intentionData}}async build(e){let{suiClient:t,account:n,network:a,txSubType:r,intentionData:i}=e;if(!this.scallopClient){let c=new Lr.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e.account.address,suiClients:[e.suiClient]});this.scallopClient=await c.createScallopClient()}let s;switch(r){case"SupplyLending":s=Aa.fromData(i);break;case"WithdrawLending":s=Ba.fromData(i);break;case"Borrow":s=ya.fromData(i);break;case"Repay":s=Da.fromData(i);break;case"DepositCollateral":s=Sa.fromData(i);break;case"WithdrawCollateral":s=Ra.fromData(i);break;case"OpenObligation":s=xa.fromData(i);break;case"UnstakeSpool":s=Oa.fromData(i);break;case"ClaimIncentiveReward":s=Ia.fromData(i);break;case"BorrowWithBoost":s=Ta.fromData(i);break;case"StakeSca":s=Ua.fromData(i);break;case"ExtendStakePeriod":s=Na.fromData(i);break;case"ExtendPeriodAndStakeMore":s=Wa.fromData(i);break;case"RenewExpStakePeriod":s=ja.fromData(i);break;case"WithdrawStakedSca":s=qa.fromData(i);break;case"SupplyAndStakeLending":s=Fa.fromData(i);break;case"WithdrawAndUnstakeLending":s=Pa.fromData(i);break;case"RedeemSca":s=La.fromData(i);break;case"MigrateAndClaim":s=wa.fromData(i);break;case"BorrowWithReferral":s=Ca.fromData(i);break;case"CreateReferralLink":s=Ma.fromData(i);break;case"ClaimRevenueReferral":s=Ea.fromData(i);break;case"BindReferral":s=_a.fromData(i);break;case"MigrateScoin":s=ka.fromData(i);break;case"RepayWithBoost":s=va.fromData(i);break;default:throw new Error("not implemented")}return s.build({suiClient:t,account:n,network:a,scallopClient:this.scallopClient})}};var Zc=require("@msafe/sui3-utils");var Qt=require("@msafe/sui3-utils"),bt=require("@mysten/sui/utils");var Bc="https://suilend-assets.s3.us-east-2.amazonaws.com/springsui";var Kc=require("@msafe/sui3-utils"),ft=require("@suilend/sdk");var Dt=require("@msafe/sui3-utils"),Ht=require("@mysten/bcs"),Vt=require("@mysten/sui/utils"),vt=require("@suilend/frontend-sui"),jr=q(require("bignumber.js"));var $a=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isDepositTransaction())return this.decodeDeposit();if(this.isWithdrawTransaction())return this.decodeWithdraw();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayTransaction())return this.decodeRepay();if(this.isClaimTransaction())return this.decodeClaim();if(this.isClaimAndDepositTransaction())return this.decodeClaimAndDeposit();throw new Error("Unknown transaction type")}get inputs(){return console.log("this.transaction.getData().inputs",this.transaction.getData().inputs),this.transaction.getData().inputs}get commands(){return console.log("this.transaction.getData().commands",this.transaction.getData().commands),this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}hasDepositTransactionMoveCallCommands(){return!!this.getMoveCallCommand("deposit_liquidity_and_mint_ctokens")&&!!this.getMoveCallCommand("deposit_ctokens_into_obligation")}hasClaimTransactionMoveCallCommands(){return!!this.getMoveCallCommand("claim_rewards")}isDepositTransaction(){return!this.hasClaimTransactionMoveCallCommands()&&this.hasDepositTransactionMoveCallCommands()}isWithdrawTransaction(){return!!this.getMoveCallCommand("withdraw_ctokens")&&!!this.getMoveCallCommand("redeem_ctokens_and_withdraw_liquidity_request")}isBorrowTransaction(){return!!this.getMoveCallCommand("borrow_request")}isRepayTransaction(){return!!this.getMoveCallCommand("repay")}isClaimTransaction(){return this.hasClaimTransactionMoveCallCommands()&&!this.hasDepositTransactionMoveCallCommands()}isClaimAndDepositTransaction(){return this.hasClaimTransactionMoveCallCommands()&&this.hasDepositTransactionMoveCallCommands()}decodeDeposit(){let e={MintEvent:this.simResult.events.find(a=>a.type.includes("lending_market::MintEvent"))},t=(0,Vt.normalizeStructTag)(e.MintEvent.parsedJson.coin_type.name),n=e.MintEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeDeposit",t,n),{txType:Dt.TransactionType.Other,type:"deposit",intentionData:{coinType:t,value:n}}}decodeWithdraw(){let e={withdraw_ctokens:this.getMoveCallCommand("withdraw_ctokens")},t={RedeemEvent:this.simResult.events.find(c=>c.type.includes("lending_market::RedeemEvent"))},n=(0,Vt.normalizeStructTag)(t.RedeemEvent.parsedJson.coin_type.name),a=t.RedeemEvent.parsedJson.liquidity_amount;console.log("Decoder.decodeWithdraw",n,a);let r=e.withdraw_ctokens.MoveCall.arguments[4].Input,i=new jr.default((0,Ht.toHex)((0,Ht.fromBase64)(this.inputs[r].Pure.bytes)),16).toString(),s=i===vt.MAX_U64.toString();return console.log("decodeWithdraw - isMax:",s,"inputIndex:",r,"inputValue:",i,"MAX_U64.toString():",vt.MAX_U64.toString()),s&&(a=vt.MAX_U64.toString()),{txType:Dt.TransactionType.Other,type:"withdraw",intentionData:{coinType:n,value:a}}}decodeBorrow(){let e={borrow_request:this.getMoveCallCommand("borrow_request")},t={BorrowEvent:this.simResult.events.find(c=>c.type.includes("lending_market::BorrowEvent"))},n=(0,Vt.normalizeStructTag)(t.BorrowEvent.parsedJson.coin_type.name),a=`${+t.BorrowEvent.parsedJson.liquidity_amount-+t.BorrowEvent.parsedJson.origination_fee_amount}`;console.log("Decoder.decodeBorrow",n,a);let r=e.borrow_request.MoveCall.arguments[4].Input,i=new jr.default((0,Ht.toHex)((0,Ht.fromBase64)(this.inputs[r].Pure.bytes)),16).toString(),s=i===vt.MAX_U64.toString();return console.log("decodeBorrow - isMax:",s,"inputIndex:",r,"inputValue:",i,"MAX_U64.toString():",vt.MAX_U64.toString()),s&&(a=vt.MAX_U64.toString()),{txType:Dt.TransactionType.Other,type:"borrow",intentionData:{coinType:n,value:a}}}decodeRepay(){let e={RepayEvent:this.simResult.events.find(a=>a.type.includes("lending_market::RepayEvent"))},t=(0,Vt.normalizeStructTag)(e.RepayEvent.parsedJson.coin_type.name),n=e.RepayEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeRepay",t,n),{txType:Dt.TransactionType.Other,type:"repay",intentionData:{coinType:t,value:n}}}decodeClaim(){let e={ClaimReward:this.simResult.events.filter(n=>n.type.includes("lending_market::ClaimReward"))},t={};for(let n=0;n<e.ClaimReward.length;n++){let a=e.ClaimReward[n],r=(0,Vt.normalizeStructTag)(a.parsedJson.coin_type.name),i=a.parsedJson.liquidity_amount;t[r]=`${+(t[r]??"0")+ +i}`}return console.log("Decoder.decodeClaimRewards",t),{txType:Dt.TransactionType.Other,type:"claim",intentionData:{value:t}}}decodeClaimAndDeposit(){return{txType:Dt.TransactionType.Other,type:"claimAndDeposit",intentionData:this.decodeClaim().intentionData}}};var Ec=require("@mysten/sui/transactions");var _c=q(require("sort-keys-recursive")),R=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,_c.default)(this.data))}};var Va=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;if(console.log("BorrowIntention.build",n,a,r,i,s),!i||!s)throw new Error("Obligation not found");let c=new Ec.Transaction;return await r.borrowAndSendToUser(a.address,i.id,s.id,this.data.coinType,this.data.value,c),c}static fromData(t){return console.log("BorrowIntention.fromData",t),new o(t)}};var Lc=require("@mysten/sui/transactions");var Mc=require("@mysten/sui/utils"),Wc=require("@suilend/frontend-sui"),Gt=require("@suilend/sdk"),Nc=q(require("bignumber.js")),Xd=(o,e)=>{let t={[Gt.Side.DEPOSIT]:[],[Gt.Side.BORROW]:[]};return o.lendingMarket.reserves.forEach(n=>{[Gt.Side.DEPOSIT,Gt.Side.BORROW].forEach(a=>{let r=a===Gt.Side.DEPOSIT?n.depositsPoolRewardManager:n.borrowsPoolRewardManager,i=e.userRewardManagers.find(s=>s.poolRewardManagerId===r.id);i&&(t[a]=r.poolRewards.map((s,c)=>({reserveArrayIndex:n.arrayIndex,rewardIndex:BigInt(c),rewardCoinType:(0,Mc.normalizeStructTag)(s.coinType.name),side:a})).filter(s=>!(0,Wc.isSendPoints)(s.rewardCoinType)&&!!i.rewards[Number(s.rewardIndex)]&&new Nc.default(i.rewards[Number(s.rewardIndex)].earnedRewards.value.toString()).gt(0)))})}),Object.values(t).flat()},Ha=Xd;var Ga=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;if(console.log("ClaimIntention.build",n,a,r,i,s),!i||!s)throw new Error("Obligation not found");let c=new Lc.Transaction;return r.claimRewardsAndSendToUser(a.address,i.id,Ha(r,s),c),c}static fromData(t){return console.log("ClaimIntention.fromData",t),new o(t)}};var jc=require("@mysten/sui/transactions");var Qa=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;if(console.log("ClaimAndDepositIntention.build",n,a,r,i,s),!i||!s)throw new Error("Obligation not found");let c=new jc.Transaction;return r.claimRewardsAndDeposit(a.address,i.id,Ha(r,s),c),c}static fromData(t){return console.log("ClaimAndDepositIntention.fromData",t),new o(t)}};var Uc=require("@mysten/sui/transactions");var za=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;console.log("DepositIntention.build",n,a,r,i,s);let c=new Uc.Transaction;return await r.depositIntoObligation(a.address,this.data.coinType,this.data.value,c,i?.id),c}static fromData(t){return console.log("DepositIntention.fromData",t),new o(t)}};var Fc=require("@mysten/sui/transactions");var Ja=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;if(console.log("RepayIntention.build",n,a,r,i,s),!i||!s)throw new Error("Obligation not found");let c=new Fc.Transaction;return await r.repayIntoObligation(a.address,s.id,this.data.coinType,this.data.value,c),c}static fromData(t){return console.log("RepayIntention.fromData",t),new o(t)}};var qc=require("@mysten/sui/transactions");var Ya=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;if(console.log("WithdrawIntention.build",n,a,r,i,s),!i||!s)throw new Error("Obligation not found");let c=new qc.Transaction;return await r.withdrawAndSendToUser(a.address,i.id,s.id,this.data.coinType,this.data.value,c),c}static fromData(t){return console.log("WithdrawIntention.fromData",t),new o(t)}};var Xa=async(o,e)=>{let t=await ft.SuilendClient.initialize(ft.LENDING_MARKET_ID,ft.LENDING_MARKET_TYPE,o),n=await ft.SuilendClient.getObligationOwnerCaps(e.address,t.lendingMarket.$typeArgs,o),a=await Promise.all(n.map(r=>ft.SuilendClient.getObligation(r.obligationId,t.lendingMarket.$typeArgs,o)));return console.log("XXX getUtils - suilendClient:",t,"obligations:",a,"obligationOwnerCaps:",n),{suilendClient:t,obligationOwnerCaps:n,obligations:a}},Za=class{application="Suilend";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:a}=e;this.utils||(this.utils=await Xa(n,a));let r=await n.devInspectTransactionBlock({sender:a.address,transactionBlock:t});console.log("SuilendAppHelper.deserialize - simResult:",r,"utils:",this.utils,"suiClient:",n);let s=new $a(t,r).decode();return{txType:Kc.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:a,suiClient:r,account:i}=e;this.utils||(this.utils=await Xa(r,i));let s;switch(n){case"deposit":s=za.fromData(a);break;case"withdraw":s=Ya.fromData(a);break;case"borrow":s=Va.fromData(a);break;case"repay":s=Ja.fromData(a);break;case"claim":s=Ga.fromData(a);break;case"claimAndDeposit":s=Qa.fromData(a);break;default:throw new Error("not implemented")}let c=window.localStorage.getItem("obligationId"),l=this.utils.obligations?.find(m=>m.id===c)??this.utils.obligations?.[0],d=this.utils.obligationOwnerCaps?.find(m=>m.obligationId===l?.id);return s.build({network:t,suiClient:r,account:i,suilendClient:this.utils.suilendClient,obligationOwnerCap:d,obligation:l})}};var Ur=async(o,e)=>{let t=await Xa(o,e),n=await(await fetch(`${Bc}/liquid-staking-info-map.json`)).json();return{...t,LIQUID_STAKING_INFO_MAP:n}};var to=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isStakeTransaction())return this.decodeStake();if(this.isStakeAndDepositTransaction())return this.decodeStakeAndDeposit();if(this.isConvertTransaction())return this.decodeConvert();if(this.isConvertAndDepositTransaction())return this.decodeConvertAndDeposit();if(this.isUnstakeTransaction())return this.decodeUnstake();throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}hasSuilendDepositTransactionMoveCallCommands(){return!!this.getMoveCallCommand("deposit_liquidity_and_mint_ctokens")&&!!this.getMoveCallCommand("deposit_ctokens_into_obligation")}hasMintMoveCallCommands(){return!!this.getMoveCallCommand("mint")}hasRedeemMoveCallCommands(){return!!this.getMoveCallCommand("redeem")}isStakeTransaction(){return this.hasMintMoveCallCommands()&&!this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}isStakeAndDepositTransaction(){return this.hasMintMoveCallCommands()&&!this.hasRedeemMoveCallCommands()&&this.hasSuilendDepositTransactionMoveCallCommands()}isConvertTransaction(){return this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}isConvertAndDepositTransaction(){return this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&this.hasSuilendDepositTransactionMoveCallCommands()}isUnstakeTransaction(){return!this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}decodeStake(){let e={MintEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::MintEvent"))},t=(0,bt.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStake",n),{txType:Qt.TransactionType.Other,type:"stake",intentionData:{amount:n,outCoinType:t}}}decodeStakeAndDeposit(){let e={MintEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::MintEvent"))},t=(0,bt.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStakeAndDeposit",n),{txType:Qt.TransactionType.Other,type:"stakeAndDeposit",intentionData:{amount:n,outCoinType:t}}}decodeConvert(){let e={RedeemEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::MintEvent"))},t=(0,bt.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,bt.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),a=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvert",a),{txType:Qt.TransactionType.Other,type:"convert",intentionData:{amount:a,inCoinType:t,outCoinType:n}}}decodeConvertAndDeposit(){let e={RedeemEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::MintEvent"))},t=(0,bt.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,bt.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),a=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvertAndDeposit",a),{txType:Qt.TransactionType.Other,type:"convertAndDeposit",intentionData:{amount:a,inCoinType:t,outCoinType:n}}}decodeUnstake(){let e={RedeemEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::RedeemEvent"))},t=(0,bt.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeUnstake",n),{txType:Qt.TransactionType.Other,type:"unstake",intentionData:{amount:n,inCoinType:t}}}};var Vc=require("@mysten/sui/transactions"),xe=require("@suilend/springsui-sdk");var $c=q(require("sort-keys-recursive")),L=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,$c.default)(this.data))}};var eo=class o extends L{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,LIQUID_STAKING_INFO_MAP:i,obligationOwnerCap:s,obligation:c}=t;console.log("ConvertIntention.build",n,a,r,i,s,c);let l=await xe.LstClient.initialize(n,Object.values(i).find(p=>p.type===this.data.inCoinType)),d=await xe.LstClient.initialize(n,Object.values(i).find(p=>p.type===this.data.outCoinType)),m=new Vc.Transaction;return(0,xe.convertLstsAndSendToUser)(l,d,m,a.address,this.data.amount),m}static fromData(t){return console.log("ConvertIntention.fromData",t),new o(t)}};var Hc=require("@mysten/sui/transactions"),ao=require("@suilend/sdk"),De=require("@suilend/springsui-sdk");var no=class o extends L{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,LIQUID_STAKING_INFO_MAP:i,obligationOwnerCap:s,obligation:c}=t;console.log("ConvertAndDepositIntention.build",n,a,r,i,s,c);let l=await De.LstClient.initialize(n,Object.values(i).find(y=>y.type===this.data.inCoinType)),d=await De.LstClient.initialize(n,Object.values(i).find(y=>y.type===this.data.outCoinType)),m=new Hc.Transaction,{obligationOwnerCapId:p,didCreate:f}=(0,ao.createObligationIfNoneExists)(r,m,s),b=(0,De.convertLsts)(l,d,m,a.address,this.data.amount);return r.deposit(b,this.data.outCoinType,p,m),f&&(0,ao.sendObligationToUser)(p,a.address,m),m}static fromData(t){return console.log("ConvertAndDepositIntention.fromData",t),new o(t)}};var Gc=require("@mysten/sui/transactions"),Qc=require("@suilend/springsui-sdk");var oo=class o extends L{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,LIQUID_STAKING_INFO_MAP:i,obligationOwnerCap:s,obligation:c}=t;console.log("StakeIntention.build",n,a,r,i,s,c);let l=await Qc.LstClient.initialize(n,Object.values(i).find(m=>m.type===this.data.outCoinType)),d=new Gc.Transaction;return l.mintAmountAndRebalanceAndSendToUser(d,a.address,this.data.amount),d}static fromData(t){return console.log("StakeIntention.fromData",t),new o(t)}};var zc=require("@mysten/sui/transactions"),io=require("@suilend/sdk"),Jc=require("@suilend/springsui-sdk");var ro=class o extends L{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,LIQUID_STAKING_INFO_MAP:i,obligationOwnerCap:s,obligation:c}=t;console.log("StakeAndDepositIntention.build",n,a,r,i,s,c);let l=await Jc.LstClient.initialize(n,Object.values(i).find(b=>b.type===this.data.outCoinType)),d=new zc.Transaction,{obligationOwnerCapId:m,didCreate:p}=(0,io.createObligationIfNoneExists)(r,d,s),f=l.mintAmountAndRebalance(d,a.address,this.data.amount);return r.deposit(f,this.data.outCoinType,m,d),p&&(0,io.sendObligationToUser)(m,a.address,d),d}static fromData(t){return console.log("StakeAndDepositIntention.fromData",t),new o(t)}};var Yc=require("@mysten/sui/transactions"),Xc=require("@suilend/springsui-sdk");var so=class o extends L{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,LIQUID_STAKING_INFO_MAP:i,obligationOwnerCap:s,obligation:c}=t;console.log("UnstakeIntention.build",n,a,r,i,s,c);let l=await Xc.LstClient.initialize(n,Object.values(i).find(m=>m.type===this.data.inCoinType)),d=new Yc.Transaction;return l.redeemAmountAndSendToUser(d,a.address,this.data.amount),d}static fromData(t){return console.log("UnstakeIntention.fromData",t),new o(t)}};var co=class{application="SpringSui";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:a}=e;this.utils||(this.utils=await Ur(n,a));let r=await n.devInspectTransactionBlock({sender:a.address,transactionBlock:t});console.log("SpringSuiAppHelper.deserialize",r);let s=new to(t,r).decode();return{txType:Zc.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:a,suiClient:r,account:i}=e;this.utils||(this.utils=await Ur(r,i));let s;switch(n){case"stake":s=oo.fromData(a);break;case"stakeAndDeposit":s=ro.fromData(a);break;case"convert":s=eo.fromData(a);break;case"convertAndDeposit":s=no.fromData(a);break;case"unstake":s=so.fromData(a);break;default:throw new Error("not implemented")}return s.build({network:t,suiClient:r,account:i,suilendClient:this.utils.suilendClient,LIQUID_STAKING_INFO_MAP:this.utils.LIQUID_STAKING_INFO_MAP,obligationOwnerCap:this.utils.obligationOwnerCaps?.[0],obligation:this.utils.obligations?.[0]})}};var nl=require("@msafe/sui3-utils");var Fr=require("@msafe/sui3-utils");var lo=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isMintTransaction()){let e=this.getLiquidityChangeEvent("MintEvent");if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson;return console.log("Decoder event data - ",t),this.decodeMint(t)}if(this.isRedeemTransaction()){let e=this.getLiquidityChangeEvent("RedeemEvent");if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson;return console.log("Decoder event data - ",t),this.decodeRedeem(t)}throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getLiquidityChangeEvent(e){return this.simResult.events.find(t=>this.isLiquidityChangeEventType(t.type,e))}isLiquidityChangeEventType(e,t){return e.includes(t)}isMintTransaction(){return!!this.getMoveCallCommand("mint")}isRedeemTransaction(){return!!this.getMoveCallCommand("redeem")}decodeMint(e){let{event:{sui_amount_in:t}}=e;return console.log("Decoder.decodeMint",t),{txType:Fr.TransactionType.Other,type:"mint",intentionData:{amount:t}}}decodeRedeem(e){let{event:{lst_amount_in:t}}=e;return console.log("Decoder.decodeRedeem",t),{txType:Fr.TransactionType.Other,type:"redeem",intentionData:{amount:t}}}};var tl=require("@alphafi/stsui-sdk");var uo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:a}=this.data,r={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},s=await new tl.LST(r).mint(a,n.address);return s.setGasBudget(1e8),s}static fromData(t){return console.log("MintIntention.fromData",t),new o(t)}};var el=require("@alphafi/stsui-sdk");var mo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:a}=this.data,r={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},s=await new el.LST(r).redeem(a,n.address);return s.setGasBudget(1e8),s}static fromData(t){return console.log("RedeemIntention.fromData",t),new o(t)}};var po=class{application="stsui";supportSDK="@mysten/sui";async deserialize(e){let{transaction:t,suiClient:n}=e,a=await n.devInspectTransactionBlock({sender:t.getData().sender,transactionBlock:t});console.log("StSuiHelper Sim result - ",a);let i=new lo(t,a).decode();return{txType:nl.TransactionType.Other,txSubType:i.type,intentionData:i.intentionData}}async build(e){let{account:t}=e;console.log("StSui build transaction type",e.txSubType);let n;switch(e.txSubType){case"mint":n=uo.fromData(e.intentionData);break;case"redeem":n=mo.fromData(e.intentionData);break;default:throw new Error("build not implemented")}return n.build({account:t})}};var kl=require("@msafe/sui3-utils"),xl=require("turbos-clmm-sdk");var _=require("@msafe/sui3-utils"),qr=require("@mysten/sui.js/bcs"),gt=require("@mysten/sui.js/utils"),al=require("turbos-clmm-sdk");var U={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},F={PackageId:"0xdee9"};var nu=(o,e,t,n)=>{if(o===1)switch(n.findIndex(i=>i===e)){case 0:return[!0,!0];case 1:return[!0,!1];case 2:return[!1,!0];case 3:return[!1,!1];default:throw new Error(`not target: ${e}`)}switch(t.findIndex(r=>r===e)){case 0:return[!0];case 1:return[!1];default:throw new Error(`not target: ${e}`)}},fo=class{constructor(e,t,n){this.txb=e;this.turbosSdk=t;this.config=n}get transactions(){return this.txb.blockData.transactions}get swap1Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b`,`${this.config.PackageId}::swap_router::swap_b_a`]}get swap2Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b_b_c`,`${this.config.PackageId}::swap_router::swap_a_b_c_b`,`${this.config.PackageId}::swap_router::swap_b_a_b_c`,`${this.config.PackageId}::swap_router::swap_b_a_c_b`]}async decode(e){if(this.isSwapTransaction())return this.decodeSwap();if(this.isAddLiquidityTransaction())return this.decodeAddLiquidity();if(this.isIncreaseLiquidityTransaction())return this.decodeIncreaseLiquidity(e);if(this.isRemoveLiquidityTransaction())return this.decodeRemoveLiquidity(e);if(this.isDecreaseLiquidityTransaction())return this.decodeDecreaseLiquidity(e);if(this.isCollectFeeTransaction())return this.decodeCollectFee();if(this.isCollectRewardTransaction())return this.decodeCollectReward();if(this.isBurnTransaction())return this.decodeBurn();if(this.isPrixClaimTransaction())return this.decodePrixClaim();if(this.isPrixJoinTransaction())return this.decodePrixJoin();if(this.isSwapExactBaseForQuoteTransaction())return this.decodeSwapExactBaseForQuote();if(this.isSwapExactQuoteForBaseTransaction())return this.decodeSwapExactQuoteForBase();throw new Error("Unknown transaction type")}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}getMoveCallsTransaction(e){return e.every(t=>this.transactions.find(n=>n.kind==="MoveCall"&&n.target===t))}getSwapMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&e.includes(t.target))}isSwapTransaction(){return!!this.getSwapMoveCallTransaction([...this.swap1Layer,...this.swap2Layer])}isAddLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::mint`)}isIncreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::increase_liquidity`)}isDecreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::decrease_liquidity`)}isCollectFeeTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect`)}isCollectRewardTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect_reward`)}isBurnTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::burn`)}isPrixJoinTransaction(){return!!this.getMoveCallTransaction(`${U.PackageId}::claim::join`)}isPrixClaimTransaction(){return!!this.getMoveCallTransaction(`${U.PackageId}::claim::claim`)}isRemoveLiquidityTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity`,`${this.config.PackageId}::position_manager::burn`])}isSwapExactBaseForQuoteTransaction(){return!!this.getMoveCallTransaction(`${F.PackageId}::clob_v2::swap_exact_base_for_quote`)}isSwapExactQuoteForBaseTransaction(){return!!this.getMoveCallTransaction(`${F.PackageId}::clob_v2::swap_exact_quote_for_base`)}async decodeSwap(){let e=this.transactions.find(f=>f.kind==="MoveCall"),t=0;this.swap2Layer.includes(e.target)&&(t=1);let n=nu(t,e.target,this.swap1Layer,this.swap2Layer),a=n.map((f,b)=>{let y=this.helper.decodeSharedObjectId(b),A=this.helper.decodeInputU128(4+b+t),B=this.turbosSdk.math.sqrtPriceX64ToTickIndex(new al.BN(A.toString()));return{pool:y,a2b:f,nextTickIndex:B}}),r=n[0]||t===1?e.typeArguments[0]:e.typeArguments[1],i=t===1?e.typeArguments[4]:n[0]?e.typeArguments[1]:e.typeArguments[0],s=this.helper.decodeInputAddress(6+2*t),c=this.helper.decodeInputU64(7+2*t),l=this.helper.decodeInputBool(5+2*t),d=this.helper.decodeInputU64(2+t),m=this.helper.decodeInputU64(3+t),p=await this.turbosSdk.trade.computeSwapResultV2({pools:[{pool:a[0].pool,a2b:a[0].a2b,amountSpecified:d}],address:s,amountSpecifiedIsInput:l});return{txType:_.TransactionType.Other,type:"Swap",intentionData:{routes:a,coinTypeA:r,coinTypeB:i,address:s,amountA:l?d:m,amountB:l?m:d,amountSpecifiedIsInput:l,slippage:"0.1",deadline:c}}}decodeAddLiquidity(){console.log(this.helper,"decodeAddLiquidity this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeInputAddress(12),n=this.helper.decodeInputU64(8),a=this.helper.decodeInputU64(9),r=this.helper.decodeInputU32(4),i=this.helper.decodeInputBool(5),s=this.helper.decodeInputU32(6),c=this.helper.decodeInputBool(7),l=this.helper.decodeInputU64(13);return{txType:_.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:10,address:t,amountA:n,amountB:a,tickLower:i?-r:r,tickUpper:c?-s:s,deadline:l}}}decodeIncreaseLiquidity(e){console.log(this.helper,"decodeIncreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(0),n=this.helper.decodeSharedObjectId(4),a=this.helper.decodeInputU64(5),r=this.helper.decodeInputU64(6),i=this.helper.decodeInputU64(9);return{txType:_.TransactionType.Other,type:"IncreaseLiquidity",intentionData:{pool:t,slippage:10,address:e,amountA:a,amountB:r,nft:n,deadline:i}}}decodeDecreaseLiquidity(e){console.log(this.helper,"decodeDecreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(0),n=this.helper.decodeSharedObjectId(2),a=this.helper.decodeInputU64(3),r=this.helper.decodeInputU64(4),i=this.helper.decodeInputU64(5),s=this.helper.decodeInputU64(6);return{txType:_.TransactionType.Other,type:"DecreaseLiquidity",intentionData:{pool:t,decreaseLiquidity:a,nft:n,amountA:r,amountB:i,slippage:10,address:e,deadline:s}}}decodeCollectFee(){console.log(this.helper,"decodeCollectFee this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2),n=this.helper.decodeInputAddress(5),a=this.helper.decodeInputU64(3),r=this.helper.decodeInputU64(4),i=this.helper.decodeInputU64(6);return{txType:_.TransactionType.Other,type:"CollectFee",intentionData:{pool:e,address:n,collectAmountA:a,collectAmountB:r,nft:t,deadline:i}}}decodeCollectReward(){console.log(this.helper,"decodeCollectReward this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2),n=this.helper.decodeInputAddress(6),a=this.collectRewardHelper.map(i=>i.decodeInputU64(5)),r=this.helper.decodeInputU64(7);return{txType:_.TransactionType.Other,type:"CollectReward",intentionData:{pool:e,address:n,rewardAmounts:a,nft:t,deadline:r}}}decodeBurn(){console.log(this.helper,"decodeBurn this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2);return{txType:_.TransactionType.Other,type:"Burn",intentionData:{pool:e,nft:t}}}decodeRemoveLiquidity(e){console.log(this.helper,"decodeRemoveLiquidity this.helper");let t=this.decreaseLiquidityHelper.decodeSharedObjectId(0),n=this.decreaseLiquidityHelper.decodeSharedObjectId(2),a=this.decreaseLiquidityHelper.decodeInputU64(3),r=this.decreaseLiquidityHelper.decodeInputU64(4),i=this.decreaseLiquidityHelper.decodeInputU64(5),s=this.decreaseLiquidityHelper.decodeInputU64(6),c=this.collectRewardHelper.map(m=>m.decodeInputU64(5)),l=this.collectFeeHelper.decodeInputU64(3)||0,d=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:_.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:t,decreaseLiquidity:a,nft:n,amountA:r,amountB:i,slippage:10,address:e,collectAmountA:l,collectAmountB:d,rewardAmounts:c,deadline:s}}}decodePrixClaim(){return{txType:_.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:_.TransactionType.Other,type:"PrixJoin",intentionData:{}}}decodeSwapExactBaseForQuote(){let e=this.swapExactBaseForQuoteHelper.decodeSharedObjectId(0),t=this.swapExactBaseForQuoteHelper.decodeInputU64(3),n=this.swapExactBaseForQuoteHelper.shortTypeArg(0),a=this.swapExactBaseForQuoteHelper.shortTypeArg(1);return{txType:_.TransactionType.Other,type:"SwapExactBaseForQuote",intentionData:{poolId:e,amountIn:t,token1:n,token2:a}}}decodeSwapExactQuoteForBase(){let e=this.swapExactQuoteForBaseHelper.decodeSharedObjectId(0),t=this.swapExactQuoteForBaseHelper.decodeInputU64(3),n=this.swapExactQuoteForBaseHelper.shortTypeArg(0),a=this.swapExactQuoteForBaseHelper.shortTypeArg(1);return{txType:_.TransactionType.Other,type:"SwapExactQuoteForBase",intentionData:{poolId:e,amountIn:t,token1:n,token2:a}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target!=="0x2::coin::zero"&&t.target!=="0x0000000000000000000000000000000000000000000000000000000000000002::coin::zero");return new ht(e,this.txb)}get collectRewardHelper(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::collect_reward`).map(t=>new ht(t,this.txb))}get collectFeeHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::collect`);return new ht(e,this.txb)}get decreaseLiquidityHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::decrease_liquidity`);return new ht(e,this.txb)}get swapExactBaseForQuoteHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${F.PackageId}::clob_v2::swap_exact_base_for_quote`);return new ht(e,this.txb)}get swapExactQuoteForBaseHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${F.PackageId}::clob_v2::swap_exact_quote_for_base`);return new ht(e,this.txb)}},ht=class o{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return o.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return o.getOwnedObjectId(t)}decodeInputU128(e){let t=this.decodePureArg(e,"u128");return Number(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU32(e){let t=this.decodePureArg(e,"u32");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,gt.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return o.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return qr.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,gt.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,gt.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,gt.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,gt.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return qr.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,gt.normalizeStructTag)(this.moveCall.typeArguments[e])}shortTypeArg(e){return this.moveCall.typeArguments[e]}txArg(e){return this.moveCall.arguments[e]}};var ol=require("turbos-clmm-sdk");var bo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ol.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,address:r,amountA:i,amountB:s,slippage:c,tickLower:l,tickUpper:d,deadline:m,txb:p}=this.data;return n.pool.addLiquidity({pool:a,slippage:c,address:r,amountA:i,amountB:s,tickLower:l,tickUpper:d,deadline:m,txb:p})}static fromData(t){return new o(t)}};var rl=require("turbos-clmm-sdk");var ho=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new rl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,nft:r,txb:i}=this.data;return n.nft.burn({pool:a,nft:r,txb:i})}static fromData(t){return new o(t)}};var il=require("turbos-clmm-sdk");var go=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new il.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,address:r,nft:i,collectAmountA:s,collectAmountB:c,deadline:l,txb:d}=this.data;return n.pool.collectFee({pool:a,address:r,collectAmountA:s,collectAmountB:c,nft:i,deadline:l,txb:d})}static fromData(t){return new o(t)}};var sl=require("turbos-clmm-sdk");var yo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new sl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,address:r,nft:i,rewardAmounts:s,deadline:c,txb:l}=this.data;return n.pool.collectReward({pool:a,address:r,rewardAmounts:s,nft:i,deadline:c,txb:l})}static fromData(t){return new o(t)}};var cl=require("turbos-clmm-sdk");var To=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new cl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:a,address:r,tickLower:i,tickUpper:s,sqrtPrice:c,slippage:l,coinTypeA:d,coinTypeB:m,amountA:p,amountB:f,deadline:b,txb:y}=this.data;return n.pool.createPool({fee:a,amountA:p,amountB:f,address:r,tickLower:i,tickUpper:s,sqrtPrice:c,slippage:l,coinTypeA:d,coinTypeB:m,deadline:b,txb:y})}static fromData(t){return new o(t)}};var ll=require("turbos-clmm-sdk");var Co=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ll.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,address:r,amountA:i,amountB:s,slippage:c,nft:l,decreaseLiquidity:d,deadline:m,txb:p}=this.data;return n.pool.decreaseLiquidity({pool:a,slippage:c,address:r,amountA:i,amountB:s,nft:l,decreaseLiquidity:d,deadline:m,txb:p})}static fromData(t){return new o(t)}};var dl=require("turbos-clmm-sdk");var Io=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new dl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,address:r,amountA:i,amountB:s,slippage:c,nft:l,deadline:d,txb:m}=this.data;return n.pool.increaseLiquidity({pool:a,slippage:c,address:r,amountA:i,amountB:s,nft:l,deadline:d,txb:m})}static fromData(t){return new o(t)}};var ul=require("@mysten/sui.js/transactions"),ml=require("@mysten/sui.js/utils");var So=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ul.TransactionBlock;return n.moveCall({target:`${U.PackageId}::claim::claim`,typeArguments:[U.turbosCoinType],arguments:[n.object(U.Claim),n.object(ml.SUI_CLOCK_OBJECT_ID)]}),n}static fromData(t){return new o(t)}};var pl=require("@mysten/sui.js/transactions");var wo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new pl.TransactionBlock;return n.moveCall({target:`${U.PackageId}::claim::join`,typeArguments:[U.turbosCoinType],arguments:[n.object(U.Claim)]}),n}static fromData(t){return new o(t)}};var fl=require("@mysten/sui.js/transactions"),bl=require("turbos-clmm-sdk");var ko=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new bl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),a=new fl.TransactionBlock;return a=await n.pool.collectFee({txb:a,...this.data}),a=await n.pool.collectReward({txb:a,...this.data}),a=await n.pool.decreaseLiquidity({txb:a,...this.data}),a=await n.nft.burn({txb:a,nft:this.data.nft,pool:this.data.pool}),a}static fromData(t){return new o(t)}};var hl=require("turbos-clmm-sdk");var xo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(this.data,"this.data");let n=new hl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:a,coinTypeA:r,coinTypeB:i,address:s,amountA:c,amountB:l,slippage:d,amountSpecifiedIsInput:m,deadline:p,txb:f}=this.data;return n.trade.swap({routes:a,coinTypeA:r,coinTypeB:i,address:s,amountA:c,amountB:l,amountSpecifiedIsInput:m,slippage:d,deadline:p,txb:f})}static fromData(t){return new o(t)}};var Sl=require("turbos-clmm-sdk");var Kr=require("@mysten/sui.js/transactions"),$r=require("@mysten/sui.js/utils");var gl=require("turbos-clmm-sdk");var ve=class{constructor(e){this.turbosSdk=e}async getCoinsData(e,t,n){let a=[],r;do r=await this.turbosSdk.provider.getCoins({owner:e,coinType:t,cursor:r?.nextCursor}),a.push(...r.data);while(r.hasNextPage);let i=[],s=0;return a.sort((c,l)=>Number(l.balance)-Number(c.balance)).some(c=>s>=n?!0:(s+=Number(c.balance),i.push(c),!1)),i}splitAndMergeCoin(e,t,n){if(!e||e.length<1)return[void 0,void 0];if(this.isSuiCoinAddress(e[0].coinType)){let[i]=n.splitCoins(n.gas,[n.pure(t)]);return[i,void 0]}let a=n.object(e[0].coinObjectId);e.length>1&&n.mergeCoins(a,e.slice(1).map(i=>n.object(i.coinObjectId)));let[r]=n.splitCoins(a,[n.pure(t)]);return[r,a]}isSuiCoinAddress(e){return e.toLocaleLowerCase()==="0x2::sui::sui"}async IsAccountCap(e){let t=await this.turbosSdk.provider.getOwnedObjects({owner:e,options:{showContent:!0,showType:!0,showOwner:!0},filter:{StructType:`${F.PackageId}::custodian_v2::AccountCap`}});return t.data[0]?.data?(0,gl.unstable_getObjectId)(t.data[0].data):void 0}createAccount(e){let[t]=e.moveCall({typeArguments:[],target:`${F.PackageId}::clob_v2::create_account`,arguments:[]});return t}zero(e,t){return t.moveCall({typeArguments:[e],target:"0x2::coin::zero",arguments:[]})}};var yl=89,Tl=1e6,Cl=async o=>{let{token1:e,token2:t,poolId:n,amountIn:a,currentAddress:r,turbosSdk:i}=o,s=new Kr.TransactionBlock,c=new ve(i),l=await c.getCoinsData(r,t,a),[d,m]=c.splitAndMergeCoin(l,a,s);if(!d)throw new Error(`Not enough balance: ${t}`);let p=await c.IsAccountCap(r),f=p?s.object(p):c.createAccount(s),[b,y,A]=s.moveCall({typeArguments:[e,t],target:`${F.PackageId}::clob_v2::swap_exact_quote_for_base`,arguments:[s.object(String(n)),s.pure(yl),f,s.pure(a),s.object((0,$r.normalizeSuiObjectId)("0x6")),d]});return m&&s.transferObjects([m],s.pure(r)),s.transferObjects([b],s.pure(r)),s.transferObjects([y],s.pure(r)),p||s.transferObjects([f],s.pure(r)),s.setSenderIfNotSet(r),s.setGasBudget(Tl),s},Il=async o=>{let{token1:e,token2:t,poolId:n,amountIn:a,currentAddress:r,turbosSdk:i}=o,s=new Kr.TransactionBlock,c=new ve(i),l=await c.getCoinsData(r,e,a),[d,m]=c.splitAndMergeCoin(l,a,s);if(!d)throw new Error(`Not enough balance: ${e}`);let p=await c.IsAccountCap(r),f=p?s.object(p):c.createAccount(s),b=c.zero(t,s),[y,A,B]=s.moveCall({typeArguments:[e,t],target:`${F.PackageId}::clob_v2::swap_exact_base_for_quote`,arguments:[s.object(String(n)),s.pure(yl),f,s.pure(a),d,b,s.object((0,$r.normalizeSuiObjectId)("0x6"))]});return m&&s.transferObjects([m],s.pure(r)),s.transferObjects([y],s.pure(r)),s.transferObjects([A],s.pure(r)),p||s.transferObjects([f],s.pure(r)),s.setSenderIfNotSet(r),s.setGasBudget(Tl),s};var Do=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Sl.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Il({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new o(t)}};var wl=require("turbos-clmm-sdk");var vo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new wl.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Cl({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new o(t)}};var Ao=class{application="turbos";supportSDK="@mysten/sui.js";async deserialize(e){let t=new xl.TurbosSdk(e.network.replace("sui:",""),e.suiClient),n=await t.contract.getConfig(),{transactionBlock:a,account:r}=e;console.log(e,"input");let s=await new fo(a,t,n).decode(r.address);return{txType:kl.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{suiClient:t,account:n,network:a}=e,r;switch(console.log(e.intentionData,"intentionData"),e.txSubType){case"CreatePool":r=To.fromData(e.intentionData);break;case"AddLiquidity":r=bo.fromData(e.intentionData);break;case"IncreaseLiquidity":r=Io.fromData(e.intentionData);break;case"DecreaseLiquidity":r=Co.fromData(e.intentionData);break;case"RemoveLiquidity":r=ko.fromData(e.intentionData);break;case"CollectFee":r=go.fromData(e.intentionData);break;case"CollectReward":r=yo.fromData(e.intentionData);break;case"Burn":r=ho.fromData(e.intentionData);break;case"Swap":r=xo.fromData(e.intentionData);break;case"PrixJoin":r=wo.fromData(e.intentionData);break;case"PrixClaim":r=So.fromData(e.intentionData);break;case"SwapExactBaseForQuote":r=Do.fromData(e.intentionData);break;case"SwapExactQuoteForBase":r=vo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:a})}};var Ol=require("@msafe/sui3-utils");var Oo=require("@msafe/sui3-utils"),Vr=require("@mysten/sui.js/bcs"),yt=require("@mysten/sui.js/utils");var au={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},w=au;var Po=class{constructor(e){this.txb=e}decode(){if(console.log("txb",this.txb),this.isStakeTransaction())return this.decodeStake();if(this.isUnStakeTransaction())return this.decodeUnStake();if(this.isClaimTicketTransaction())return this.decodeClaimTicket();throw new Error("Unknown transaction type")}get transactions(){return this.txb.blockData.transactions}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isStakeTransaction(){return!!this.getMoveCallTransaction(`${w.packageId}::native_pool::stake`)}isUnStakeTransaction(){return!!this.getMoveCallTransaction(`${w.packageId}::native_pool::unstake`)}isClaimTicketTransaction(){return!!this.getMoveCallTransaction(`${w.packageId}::native_pool::burn_ticket`)}decodeStake(){let e=this.transactions[0].amounts[0].value.toNumber();return{txType:Oo.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(n=>n.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:Oo.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:Oo.TransactionType.Other,type:"ClaimTicket",intentionData:{ticketId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(w.packageId));return new Hr(e,this.txb)}},Hr=class o{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return o.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return o.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,yt.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return o.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return Vr.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,yt.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,yt.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,yt.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,yt.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return Vr.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,yt.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Dl=require("@mysten/sui.js/transactions");var Ro=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Dl.TransactionBlock,{ticketId:a}=this.data;return n.moveCall({target:`${w.packageId}::native_pool::burn_ticket`,arguments:[n.object(w.poolObjectId),n.object(w.systemStateObjectId),n.object(a)]}),n}static fromData(t){return new o(t)}};var vl=require("@mysten/sui.js/transactions");var Bo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new vl.TransactionBlock,{amount:a}=this.data,[r]=n.splitCoins(n.gas,[n.pure(a)]);return n.moveCall({target:`${w.packageId}::native_pool::stake`,arguments:[n.object(w.poolObjectId),n.object(w.metadataObjectId),n.object(w.systemStateObjectId),r]}),n}static fromData(t){return new o(t)}};var Al=require("@mysten/sui.js/transactions");var _o=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Al.TransactionBlock,{amount:a}=this.data,r=(await t.suiClient.getAllCoins({owner:t.account.address,limit:100})).data,[i,...s]=r.filter(d=>d.coinType.split("::")[0]===w.certType.split("::")[0]),c=n.object(i.coinObjectId);s.length&&n.mergeCoins(c,s.map(d=>n.object(d.coinObjectId)));let l=n.splitCoins(n.object(i.coinObjectId),[n.pure(a)]);return n.moveCall({target:`${w.packageId}::native_pool::unstake`,arguments:[n.object(w.poolObjectId),n.object(w.metadataObjectId),n.object(w.systemStateObjectId),l]}),n}static fromData(t){return new o(t)}};var Eo=class{application="volo";supportSDK="@mysten/sui.js";async deserialize(e){let{transactionBlock:t}=e,a=new Po(t).decode();return{txType:Ol.TransactionType.Other,txSubType:a.type,intentionData:a.intentionData}}async build(e){let{suiClient:t,account:n}=e,a;switch(e.txSubType){case"Stake":a=Bo.fromData(e.intentionData);break;case"UnStake":a=_o.fromData(e.intentionData);break;case"ClaimTicket":a=Ro.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n})}};var Ul=require("@msafe/sui3-utils");var Gr=require("@cetusprotocol/cetus-sui-clmm-sdk"),Tt=require("@msafe/sui3-utils"),zt=require("@mysten/bcs"),Jt=require("@mysten/sui/bcs");var Mo=class{constructor(e){this.transaction=e}decode(){if(this.isOpenPositionTx())return this.decodeOpenPositionTx();if(this.isClosePositionTx())return this.decodeClosePositionTx();if(this.isProvideLiquidityTx())return this.decodeProvideLiquidityTx();if(this.isRemoveLiquidityTx())return this.decodeRemoveLiquidityTx();if(this.isCollectRewardsAndFeeTx())return this.decodeCollectRewardsAndFeeTx();if(this.isCollectRewardsTx())return this.decodeCollectRewardsTx();if(this.isCollectFeeTx())return this.decodeCollectFeeTx();throw new Error("Unknown transaction type")}decodeOpenPositionTx(){let e=this.getMoveCallCommand("open_position"),t=this.getMoveCallCommand("provide_liquidity_with_fixed_amount");return{txType:Tt.TransactionType.Other,type:"OpenPosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,1)),lowerTick:Number((0,Gr.asIntN)(BigInt(this.getU32(this.getInputIndex(e,2)))).toString()),upperTick:Number((0,Gr.asIntN)(BigInt(this.getU32(this.getInputIndex(e,3)))).toString()),tokenAmount:this.getU64(this.getInputIndex(t,6)),maxAmountTokenA:this.getU64(this.getInputIndex(t,7)),maxAmountTokenB:this.getU64(this.getInputIndex(t,8)),isTokenAFixed:this.getBoolean(this.getInputIndex(t,9))}}}decodeClosePositionTx(){let e=this.getMoveCallCommand("close_position"),t=this.getCollectRewardCallData();return{txType:Tt.TransactionType.Other,type:"ClosePosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),transferTokensTo:this.getAddress(this.getInputIndex(e,4)),collectRewardTokens:t.map(n=>n.rewardCoinType),collectFeeTokens:this.getTypeArguments(e)}}}decodeProvideLiquidityTx(){let e=this.getMoveCallCommand("provide_liquidity_with_fixed_amount");return{txType:Tt.TransactionType.Other,type:"ProvideLiquidity",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),tokenAmount:this.getU64(this.getInputIndex(e,6)),maxAmountTokenA:this.getU64(this.getInputIndex(e,7)),maxAmountTokenB:this.getU64(this.getInputIndex(e,8)),isTokenAFixed:this.getBoolean(this.getInputIndex(e,9))}}}decodeRemoveLiquidityTx(){let e=this.getMoveCallCommand("remove_liquidity");return{txType:Tt.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),liquidity:this.getU128(this.getInputIndex(e,4)),maxAmountTokenA:this.getU64(this.getInputIndex(e,5)),maxAmountTokenB:this.getU64(this.getInputIndex(e,6)),transferTokensTo:this.getAddress(this.getInputIndex(e,7)),...this.collectTokens()}}}decodeCollectRewardsTx(){let e=this.getCollectRewardCallData();return{txType:Tt.TransactionType.Other,type:"CollectRewards",intentionData:{pool:e[0].pool,position:e[0].position,collectRewardTokens:e.map(t=>t.rewardCoinType)}}}decodeCollectFeeTx(){return{txType:Tt.TransactionType.Other,type:"CollectFee",intentionData:this.getFeeCallData()}}decodeCollectRewardsAndFeeTx(){let e=this.getFeeCallData();return{txType:Tt.TransactionType.Other,type:"CollectRewardsAndFee",intentionData:{pool:e.pool,position:e.position,...this.collectTokens()}}}getFeeCallData(){let e=this.getMoveCallCommand("collect_fee");return{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),collectFeeTokens:this.getTypeArguments(e)}}getCollectRewardCallData(){let e=[];return this.commands.forEach(t=>{t.$kind==="MoveCall"&&t.MoveCall.function==="collect_reward"&&e.push({pool:this.getSharedObjectID(this.getInputIndex(t,2)),position:this.getOwnedObjectID(this.getInputIndex(t,3)),rewardCoinType:this.getTypeArguments(t)[2]})}),e}collectTokens(){let e=this.getFeeCallData(),t=this.getCollectRewardCallData();return{collectFeeTokens:e.collectFeeTokens,collectRewardTokens:t.map(n=>n.rewardCoinType)}}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}isOpenPositionTx(){return!!this.getMoveCallCommand("open_position")}isProvideLiquidityTx(){return!!this.getMoveCallCommand("provide_liquidity_with_fixed_amount")}isRemoveLiquidityTx(){return!!this.getMoveCallCommand("remove_liquidity")}isCollectRewardsTx(){return!!this.getMoveCallCommand("collect_reward")}isCollectFeeTx(){return!!this.getMoveCallCommand("collect_fee")}isCollectRewardsAndFeeTx(){return this.isCollectRewardsTx()&&this.isCollectFeeTx()}isClosePositionTx(){return!!this.getMoveCallCommand("close_position")}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getSharedObjectID(e){return this.inputs[e].Object.SharedObject.objectId}getOwnedObjectID(e){return this.inputs[e].Object.ImmOrOwnedObject.objectId}getU32(e){return String(Jt.bcs.u32().parse(Uint8Array.from((0,zt.fromBase64)(this.inputs[e].Pure.bytes))))}getU64(e){return Jt.bcs.u64().parse(Uint8Array.from((0,zt.fromBase64)(this.inputs[e].Pure.bytes)))}getU128(e){return Jt.bcs.u128().parse(Uint8Array.from((0,zt.fromBase64)(this.inputs[e].Pure.bytes)))}getBoolean(e){return Jt.bcs.bool().parse(Uint8Array.from((0,zt.fromBase64)(this.inputs[e].Pure.bytes)))}getAddress(e){return Jt.bcs.Address.parse(Uint8Array.from((0,zt.fromBase64)(this.inputs[e].Pure.bytes)))}getTypeArguments(e){return e.MoveCall.typeArguments||[]}getInputIndex(e,t){return e.MoveCall.arguments[t].Input}};var _l=require("@msafe/sui3-utils");var Q=require("@firefly-exchange/library-sui");var Rl=require("@firefly-exchange/library-sui"),Bl=require("@firefly-exchange/library-sui/dist/src/spot"),Pl={rpc:"https://fullnode.mainnet.sui.io/",objects:{GlobalConfig:"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",BasePackage:"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267",CurrentPackage:"0x6c796c3ab3421a68158e0df18e4657b2827b1f8fed5ed4b82dba9c935988711b"}},It=(o,e)=>{if(o!=="sui:mainnet")throw new Error("Bluefin spot protocol is only available on sui::mainnet");let t=new Rl.SuiClient({url:Pl.rpc});return new Bl.OnChainCalls(t,Pl.objects,{address:e.address,isUIWallet:!1})};var v=class{static async OpenPosition(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool),i=this.prototype.buildLiqInput(r,{...e,slippage:0});return await a.openPositionWithFixedAmount(r,e.lowerTick,e.upperTick,i,{returnTx:!0,sender:t.address})}static async provideLiquidity(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool),i=this.prototype.buildLiqInput(r,e);return await a.provideLiquidityWithFixedAmount(r,e.position,i,{returnTx:!0,sender:t.address})}static async removeLiquidity(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool);return await a.removeLiquidity(r,e.position,{liquidityAmount:new Q.BN(e.liquidity),tokenMaxA:new Q.BN(e.maxAmountTokenA),tokenMaxB:new Q.BN(e.maxAmountTokenB)},{returnTx:!0,sender:t.address})}static async closePosition(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool);return await a.closePosition(r,e.position,{returnTx:!0,sender:t.address})}static async collectRewards(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool);return await a.collectRewards(r,e.position,{rewardCoinsType:e.collectRewardTokens,returnTx:!0,sender:t.address})}static async collectFee(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool);return await a.collectFee(r,e.position,{returnTx:!0,sender:t.address})}static async collectRewardsAndFee(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool);return console.log(e.position),await a.collectFeeAndRewards(r,e.position,{returnTx:!0,sender:t.address})}buildLiqInput(e,t){return{...Q.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(t.lowerTick,t.upperTick,new Q.BN(t.tokenAmount),t.isTokenAFixed,!0,0,new Q.BN(e.current_sqrt_price)),tokenMaxA:new Q.BN(t.maxAmountTokenA),tokenMaxB:new Q.BN(t.maxAmountTokenB)}}};var Wo=class o extends u{constructor(t){super(t);this.data=t}txType=_l.TransactionType.Other;txSubType="ClosePosition";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.closePosition(this.data,n,a)}static fromData(t){return new o(t)}};var El=require("@msafe/sui3-utils");var No=class o extends u{constructor(t){super(t);this.data=t}txType=El.TransactionType.Other;txSubType="CollectFee";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.collectFee(this.data,n,a)}static fromData(t){return new o(t)}};var Ml=require("@msafe/sui3-utils");var Lo=class o extends u{constructor(t){super(t);this.data=t}txType=Ml.TransactionType.Other;txSubType="CollectRewards";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.collectRewards(this.data,n,a)}static fromData(t){return new o(t)}};var Wl=require("@msafe/sui3-utils");var jo=class o extends u{constructor(t){super(t);this.data=t}txType=Wl.TransactionType.Other;txSubType="CollectRewardsAndFee";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.collectRewardsAndFee(this.data,n,a)}static fromData(t){return new o(t)}};var Nl=require("@msafe/sui3-utils");var Uo=class o extends u{constructor(t){super(t);this.data=t}txType=Nl.TransactionType.Other;txSubType="OpenPosition";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.OpenPosition(this.data,n,a)}static fromData(t){return new o(t)}};var Ll=require("@msafe/sui3-utils");var Fo=class o extends u{constructor(t){super(t);this.data=t}txType=Ll.TransactionType.Other;txSubType="ProvideLiquidity";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.provideLiquidity(this.data,n,a)}static fromData(t){return new o(t)}};var jl=require("@msafe/sui3-utils");var qo=class o extends u{constructor(t){super(t);this.data=t}txType=jl.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.removeLiquidity(this.data,n,a)}static fromData(t){return new o(t)}};var Ko=class{application="bluefin";supportSDK="@mysten/sui";async deserialize(e){console.log("Bluefin helper deserialize input: ",e);let{transaction:t}=e,a=new Mo(t).decode();return{txType:Ul.TransactionType.Other,txSubType:a.type,intentionData:a.intentionData}}async build(e){let{suiClient:t,account:n,network:a}=e;console.log(e.txSubType);let r;switch(e.txSubType){case"OpenPosition":r=Uo.fromData(e.intentionData);break;case"ProvideLiquidity":r=Fo.fromData(e.intentionData);break;case"RemoveLiquidity":r=qo.fromData(e.intentionData);break;case"ClosePosition":r=Wo.fromData(e.intentionData);break;case"CollectFee":r=No.fromData(e.intentionData);break;case"CollectRewards":r=Lo.fromData(e.intentionData);break;case"CollectRewardsAndFee":r=jo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:a})}};var Jl=require("@msafe/sui3-utils");var Fl=require("kriya-dev-sdk");var $o=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Fl.KriyaSDK,{params:n}=this.data;return t.Amm.getTxbAddLiquidity(n)}static fromData(t){return new o(t)}};var ql=require("kriya-dev-sdk");var Vo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new ql.KriyaSDK,{params:n}=this.data;return t.Amm.getTxbAddLiquiditySingleSided(n)}static fromData(t){return new o(t)}};var Kl=require("kriya-dev-sdk");var Ho=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Kl.KriyaSDK,{params:n}=this.data;return t.Amm.getTxbClaimRewards(n)}static fromData(t){return new o(t)}};var $l=require("kriya-dev-sdk");var Go=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new $l.KriyaSDK,{params:n}=this.data;return t.Amm.getTxbRemoveLiquidity(n)}static fromData(t){return new o(t)}};var Vl=require("kriya-dev-sdk");var Qo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Vl.KriyaSDK,{params:n}=this.data;return t.Clmm.getTxbAddLiquiditySingleSided(n)}static fromData(t){return new o(t)}};var Hl=require("kriya-dev-sdk");var zo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Hl.KriyaSDK,{params:n}=this.data;return t.Clmm.getTxbAddLiquidity(n)}static fromData(t){return new o(t)}};var Gl=require("kriya-dev-sdk");var Jo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Gl.KriyaSDK,{params:n}=this.data;return t.Clmm.getTxbClaimMayaRewards(n)}static fromData(t){return new o(t)}};var Ql=require("kriya-dev-sdk");var Yo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Ql.KriyaSDK,{params:n}=this.data;return t.Clmm.getTxbClaimRewards(n)}static fromData(t){return new o(t)}};var zl=require("kriya-dev-sdk");var Xo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new zl.KriyaSDK,{params:n}=this.data;return t.Clmm.getTxbRemoveLiquidity(n)}static fromData(t){return new o(t)}};var Zo=class{application="kriya";supportSDK="@mysten/sui";async deserialize(e){let{appContext:t}=e;return{txType:Jl.TransactionType.Other,txSubType:t.action,intentionData:t}}async build(e){let t;switch(e.txSubType){case"AddLiquidity":t=$o.fromData(e.intentionData);break;case"AddLiquiditySingleSided":t=Vo.fromData(e.intentionData);break;case"RemoveLiquidity":t=Go.fromData(e.intentionData);break;case"ClaimRewards":t=Ho.fromData(e.intentionData);break;case"ClaimRewardsV3":t=Yo.fromData(e.intentionData);break;case"ClaimV3MayaRewards":t=Jo.fromData(e.intentionData);break;case"AddLiquidityV3":t=zo.fromData(e.intentionData);break;case"AddLiquiditySingleSideV3":t=Qo.fromData(e.intentionData);break;case"RemoveLiquidityV3":t=Xo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return t.build()}};var ru=ma.fromHelpers([new Yn,new sa,new Qn,new ca,new Dn,new Ao,new Zo,new Ka,new Eo,new en,new Za,new co,new We,new Ko,new po]);
|
|
1
|
+
"use strict";var Yl=Object.create;var Oe=Object.defineProperty;var Xl=Object.getOwnPropertyDescriptor;var Zl=Object.getOwnPropertyNames;var td=Object.getPrototypeOf,ed=Object.prototype.hasOwnProperty;var tr=(o,e)=>{for(var t in e)Oe(o,t,{get:e[t],enumerable:!0})},Qr=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of Zl(e))!ed.call(o,a)&&a!==t&&Oe(o,a,{get:()=>e[a],enumerable:!(n=Xl(e,a))||n.enumerable});return o};var q=(o,e,t)=>(t=o!=null?Yl(td(o)):{},Qr(e||!o||!o.__esModule?Oe(t,"default",{value:o,enumerable:!0}):t,o)),nd=o=>Qr(Oe({},"__esModule",{value:!0}),o);var iu={};tr(iu,{appHelpers:()=>ru});module.exports=nd(iu);var ei=require("@msafe/sui3-utils");var z=require("@alphafi/alphafi-sdk"),At=require("@msafe/sui3-utils"),K=require("@mysten/bcs");var Pe=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isClaimRewardTransaction())return this.decodeClaimReward();let e=this.getLiquidityChangeEvent();if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson,n=t.pool_id,a=z.poolIdPoolNameMap[n];if(console.log("Decoder event data - ",t),console.log("Decoder poolName - ",a),this.isWithdrawAlphaEvent(e))return this.decodeWithdrawAlpha(t);if(this.isWithdrawEvent(t))return this.decodeWithdraw(a);if(this.isDoubleAssetDepositEvent(t,a))return this.decodeDoubleAssetDeposit(a,t);if(this.isSingleAssetDepositEvent(t,a))return this.decodeSingleAssetDeposit(a,t);throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getLiquidityChangeEvent(){return this.simResult.events.find(e=>this.isLiquidityChangeEventType(e.type))}isClaimRewardTransaction(){return!!this.getMoveCallCommand("get_user_rewards_all")}isLiquidityChangeEventType(e){return e.includes("LiquidityChangeEvent")||e.includes("LiquidityChangeNewNewEvent")||e.includes("WithdrawEventV2")}isWithdrawAlphaEvent(e){return e.type.includes("WithdrawEventV2")}isWithdrawEvent(e){return e.event_type===1}isDoubleAssetDepositEvent(e,t){return e.event_type===0&&z.poolInfo[t].assetTypes.length===2}isSingleAssetDepositEvent(e,t){return e.event_type===0&&z.poolInfo[t].assetTypes.length===1}extractXTokensAmount(){let e=this.inputs.find(a=>a.Pure!==void 0);if(!e||!e.Pure?.bytes)throw new Error("Unable to extract xTokensAmount from inputs");let{bytes:t}=e.Pure,n;return t.length===12?n=K.bcs.u64().parse((0,K.fromBase64)(t)):t.length===24?n=K.bcs.u128().parse((0,K.fromBase64)(t)):t.length===44?n=K.bcs.u256().parse((0,K.fromBase64)(t)):n=K.bcs.u64().parse((0,K.fromBase64)(t)),n}decodeDoubleAssetDeposit(e,t){let{amount_a:n,amount_b:a}=t,r=Number(n)>0;return console.log("Decoder.decodeDoubleAssetDeposit",n,a,r),{txType:At.TransactionType.Other,type:"depositDoubleAsset",intentionData:{poolName:e,amount:r?n:a,isAmountA:r}}}decodeSingleAssetDeposit(e,t){let{amount:n}=t;if(console.log("Decoder.decodeSingleAssetDeposit",n),this.getLiquidityChangeEvent().type.includes(":alphafi_navi_pool:")){let{coin:r}=z.singleAssetPoolCoinMap[e],{expo:i}=z.coinsList[r];n=Math.floor(Number(n)/10**(9-i)).toString()}return{txType:At.TransactionType.Other,type:"depositSingleAsset",intentionData:{poolName:e,amount:n}}}decodeWithdraw(e){let t=this.extractXTokensAmount();return console.log("Decoder.decodeWithdraw",t),{txType:At.TransactionType.Other,type:"withdraw",intentionData:{poolName:e,xTokensAmount:t}}}decodeWithdrawAlpha(e){let t=this.extractXTokensAmount(),{amount_withdrawn_from_locked:n}=e;return console.log("Decoder.decodeWithdrawAlpha",t,n),{txType:At.TransactionType.Other,type:"withdrawAlpha",intentionData:{withdrawFromLocked:Number(n)>0,xTokensAmount:t}}}decodeClaimReward(){return{txType:At.TransactionType.Other,type:"claimReward",intentionData:{}}}};var Jr=require("@alphafi/alphafi-sdk");var zr=q(require("sort-keys-recursive")),u=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,zr.default)(this.data))}};var Re=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t;return await(0,Jr.claimRewardTxb)(n.address)}static fromData(t){return new o(t)}};var Yr=require("@alphafi/alphafi-sdk");var Be=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:a,amount:r,isAmountA:i}=this.data;return await(0,Yr.depositDoubleAssetTxb)(a,n.address,r,i)}static fromData(t){return console.log("DepositDoubleAssetIntention.fromData",t),new o(t)}};var Xr=require("@alphafi/alphafi-sdk");var _e=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:a,amount:r}=this.data;return await(0,Xr.depositSingleAssetTxb)(a,n.address,r)}static fromData(t){return console.log("DepositSingleAssetIntention.fromData",t),new o(t)}};var Zr=require("@alphafi/alphafi-sdk");var Ee=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{poolName:a,xTokensAmount:r}=this.data;return await(0,Zr.withdrawTxb)(r,a,n.address)}static fromData(t){return console.log("WithdrawIntention.fromData",t),new o(t)}};var ti=require("@alphafi/alphafi-sdk");var Me=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{withdrawFromLocked:a,xTokensAmount:r}=this.data;return await(0,ti.withdrawAlphaTxb)(r,a,n.address)}static fromData(t){return console.log("WithdrawAlphaIntention.fromData",t),new o(t)}};var We=class{application="alphafi";supportSDK="@mysten/sui";async deserialize(e){let{transaction:t,suiClient:n,account:a}=e,r=await n.devInspectTransactionBlock({sender:t.getData().sender,transactionBlock:t});console.log("AlphaFiHelper Sim result - ",r);let s=new Pe(t,r).decode();return{txType:ei.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{account:t}=e;console.log("AlphaFi build transaction type",e.txSubType);let n;switch(e.txSubType){case"depositSingleAsset":n=_e.fromData(e.intentionData);break;case"depositDoubleAsset":n=Be.fromData(e.intentionData);break;case"withdraw":n=Ee.fromData(e.intentionData);break;case"withdrawAlpha":n=Me.fromData(e.intentionData);break;case"claimReward":n=Re.fromData(e.intentionData);break;default:throw new Error("not implemented")}return n.build({account:t})}};var Di=require("@msafe/sui3-utils");var P=require("@msafe/sui3-utils"),Ne=require("@mysten/sui/bcs"),Le=require("bucket-protocol-sdk");var je=class{constructor(e){this.transaction=e}decode(){if(this.isSBUCKDepositTransaction())return this.decodeSBUCKDeposit();if(this.isSBUCKUnstakeTransaction())return this.decodeSBUCKUnstake();if(this.isSBUCKWithdrawTransaction())return this.decodeSBUCKWithdraw();if(this.isSBUCKClaimTransaction())return this.decodeSBUCKClaim();if(this.isLockedClaimTransaction())return this.decodeLockedClaim();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayTransaction())return this.decodeRepay();if(this.isWithdrawTransaction())return this.decodeWithdraw();if(this.isCloseTransaction())return this.decodeClose();if(this.isTankDepositTransaction())return this.decodeTankDeposit();if(this.isTankWithdrawTransaction())return this.decodeTankWithdraw();if(this.isTankClaimTransaction())return this.decodeTankClaim();if(this.isPsmTransaction())return this.decodePsm();throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getMoveCallModuleCommand(e,t){return this.commands.find(n=>n.$kind==="MoveCall"&&n.MoveCall.module===e&&n.MoveCall.function===t)}getMoveCallPackageModuleCommand(e,t,n){return this.commands.find(a=>a.$kind==="MoveCall"&&a.MoveCall.package===e&&a.MoveCall.module===t&&a.MoveCall.function===n)}getMoveCallModuleCommands(e,t){return this.commands.filter(n=>n.$kind==="MoveCall"&&n.MoveCall.module===e&&n.MoveCall.function===t)}getSplitCoinsCommands(){return this.commands.filter(e=>e.$kind==="SplitCoins")}getTransferCommands(){return this.commands.filter(e=>e.$kind==="TransferObjects")}isPsmTransaction(){return!!this.getMoveCallCommand("charge_reservoir")||!!this.getMoveCallCommand("discharge_reservoir")}isStrapNewTransaction(){return!!this.getMoveCallModuleCommand("strap","new")}isBorrowTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","high_top_up")||!!this.getMoveCallModuleCommand("bucket_operations","high_borrow")||!!this.getMoveCallModuleCommand("bucket_operations","high_borrow_with_strap")}isRepayTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","fully_repay")||!!this.getMoveCallModuleCommand("bucket_operations","fully_repay_with_strap")||!!this.getMoveCallModuleCommand("bucket_operations","repay_and_withdraw")||!!this.getMoveCallModuleCommand("bucket_operations","repay_and_withdraw_with_strap")}isWithdrawTransaction(){return!!this.getMoveCallModuleCommand("buck","withdraw")||!!this.getMoveCallModuleCommand("buck","withdraw_with_strap")}isCloseTransaction(){return!!this.getMoveCallModuleCommand("bucket_operations","destroy_empty_strap")}isTankDepositTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","deposit")}isTankWithdrawTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","withdraw")}isTankClaimTransaction(){return!!this.getMoveCallModuleCommand("tank_operations","claim")}isSBUCKDepositTransaction(){return!!this.getMoveCallModuleCommand("buck","buck_to_sbuck")}isSBUCKWithdrawTransaction(){return!!this.getMoveCallModuleCommand("buck","sbuck_to_buck")}isSBUCKStakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Le.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","stake")}isSBUCKUnstakeTransaction(){return!!this.getMoveCallPackageModuleCommand(Le.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","force_unstake")}isSBUCKClaimTransaction(){return!!this.getMoveCallPackageModuleCommand(Le.SBUCK_FOUNTAIN_PACKAGE_ID,"fountain_core","claim")}isLockedClaimTransaction(){return!!this.getMoveCallModuleCommand("proof_rule","claim")||!!this.getMoveCallModuleCommand("lst_proof_rule","claim")}isLstUnlockTransaction(){return!!this.getMoveCallModuleCommand("lst_proof_rule","unlock")}decodePsm(){let e,t,n="0",a=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];return a.$kind==="Input"&&(n=this.getPureInputU64(a.Input)),this.getMoveCallCommand("charge_reservoir")?([e]=this.getMoveCallCommand("charge_reservoir").MoveCall.typeArguments,t=!1):([e]=this.getMoveCallCommand("discharge_reservoir").MoveCall.typeArguments,t=!0),console.log("Decoder.decodePsm",e,n,t),{txType:P.TransactionType.Other,type:"psm",intentionData:{coinType:e,amount:n,buckToCoin:t}}}decodeBorrow(){let e="",t="0",n,a=this.getStrapId(),r="0",i=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];if(i.$kind==="Input"&&(r=this.getPureInputU64(i.Input)),this.getMoveCallCommand("high_top_up")){let s=this.getMoveCallCommand("high_top_up").MoveCall;[e]=s.typeArguments;let c=s.arguments[1];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let l=s.arguments[3];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}else if(this.getMoveCallCommand("high_borrow")){let s=this.getMoveCallCommand("high_borrow").MoveCall;[e]=s.typeArguments;let c=s.arguments[4];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let l=s.arguments[5];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}else if(this.getMoveCallCommand("high_borrow_with_strap")){let s=this.getMoveCallCommand("high_borrow_with_strap").MoveCall;[e]=s.typeArguments;let c=s.arguments[5];c.$kind==="Input"&&(t=this.getPureInputU64(c.Input));let l=s.arguments[6];if(l.$kind==="Input"){let d=this.getPureAddresses(l.Input);d.length===1&&([n]=d)}}return{txType:P.TransactionType.Other,type:"borrow",intentionData:{collateralType:e,collateralAmount:r,borrowAmount:t,insertionPlace:n,strapId:a}}}decodeRepay(){let e="",t="0",n="0",r,i=this.getStrapId();if(this.getMoveCallCommand("fully_repay"))[e]=this.getMoveCallCommand("fully_repay").MoveCall.typeArguments;else if(this.getMoveCallCommand("fully_repay_with_strap"))[e]=this.getMoveCallCommand("fully_repay_with_strap").MoveCall.typeArguments;else if(this.getMoveCallCommand("repay_and_withdraw")){let s=this.getMoveCallCommand("repay_and_withdraw").MoveCall;[e]=s.typeArguments;let c=s.arguments[4];c.$kind==="Input"&&(n=this.getPureInputU64(c.Input));let l=s.arguments[5];if(l.$kind==="Input"){let m=this.getPureAddresses(l.Input);m.length===1&&([r]=m)}let d=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input))}else if(this.getMoveCallCommand("repay_and_withdraw_with_strap")){let s=this.getMoveCallCommand("repay_and_withdraw_with_strap").MoveCall;[e]=s.typeArguments;let c=s.arguments[5];c.$kind==="Input"&&(n=this.getPureInputU64(c.Input));let l=s.arguments[6];if(l.$kind==="Input"){let m=this.getPureAddresses(l.Input);m.length===1&&([r]=m)}let d=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];d.$kind==="Input"&&(t=this.getPureInputU64(d.Input))}return{txType:P.TransactionType.Other,type:"repay",intentionData:{collateralType:e,repayAmount:t,withdrawAmount:n,isSurplus:!1,insertionPlace:r,strapId:i}}}decodeWithdraw(){let e="",t="0",n,a=this.getStrapId();if(this.getMoveCallCommand("withdraw_with_strap")){let r=this.getMoveCallCommand("withdraw_with_strap").MoveCall;[e]=r.typeArguments;let i=r.arguments[4];i.$kind==="Input"&&(t=this.getPureInputU64(i.Input));let s=r.arguments[5];if(s.$kind==="Input"){let c=this.getPureAddresses(s.Input);c.length===1&&([n]=c)}}else if(this.getMoveCallCommand("withdraw")){let r=this.getMoveCallCommand("withdraw").MoveCall;[e]=r.typeArguments;let i=r.arguments[3];i.$kind==="Input"&&(t=this.getPureInputU64(i.Input));let s=r.arguments[4];if(s.$kind==="Input"){let c=this.getPureAddresses(s.Input);c.length===1&&([n]=c)}}return{txType:P.TransactionType.Other,type:"withdraw",intentionData:{collateralType:e,withdrawAmount:t,insertionPlace:n,strapId:a}}}decodeClose(){let e="",t=this.getStrapId();return this.getMoveCallCommand("destroy_empty_strap")&&([e]=this.getMoveCallCommand("destroy_empty_strap").MoveCall.typeArguments),{txType:P.TransactionType.Other,type:"close",intentionData:{collateralType:e,strapId:t}}}decodeSBUCKDeposit(){let t=this.getMoveCallCommand("into_balance").MoveCall.typeArguments[0],n="0",r=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];r.$kind==="Input"&&(n=this.getPureInputU64(r.Input));let i=this.isSBUCKStakeTransaction();return console.log("Decoder.decodeSBUCKDeposit",t,n,i),{txType:P.TransactionType.Other,type:"sbuck-deposit",intentionData:{coinType:t,amount:n,isStake:i}}}decodeSBUCKUnstake(){let e="0",t=this.isSBUCKStakeTransaction();if(t){let c=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];c.$kind==="Input"&&(e=this.getPureInputU64(c.Input))}let n=[],a=this.getMoveCallModuleCommands("proof_rule","unlock");if(a.length>0)for(let s=0;s<a.length;s++){let c=a[s];n.push("")}else{let s=this.getMoveCallModuleCommands("fountain_core","force_unstake");for(let c=0;c<s.length;c++){let d=s[c].MoveCall.arguments[2];if(d.$kind==="Input"){let{objectId:m}=this.inputs[d.Input].UnresolvedObject;n.push(m)}}}let r=this.isSBUCKWithdrawTransaction(),i={stakeProofs:n,amount:e,isStake:t,toBuck:r};return console.log("Decoder.decodeSBUCKUnstake",i),{txType:P.TransactionType.Other,type:"sbuck-unstake",intentionData:i}}decodeSBUCKWithdraw(){let e="0",n=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];return n.$kind==="Input"&&(e=this.getPureInputU64(n.Input)),console.log("Decoder.SBUCKWithdraw",e),{txType:P.TransactionType.Other,type:"sbuck-withdraw",intentionData:{amount:e}}}decodeSBUCKClaim(){let e=[],t=this.getMoveCallModuleCommands("fountain_core","claim");for(let n=0;n<t.length;n++){let r=t[n].MoveCall.arguments[2];if(r.$kind==="Input"){let{objectId:i}=this.inputs[r.Input].UnresolvedObject;e.push(i)}}return console.log("Decoder.decodeSBUCKClaim",e),{txType:P.TransactionType.Other,type:"sbuck-claim",intentionData:{stakeProofs:e}}}decodeTankDeposit(){let e="0",n=this.getSplitCoinsCommands()[0].SplitCoins.amounts[0];n.$kind==="Input"&&(e=this.getPureInputU64(n.Input));let r=this.getMoveCallModuleCommand("tank_operations","deposit").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankDeposit",r,e),{txType:P.TransactionType.Other,type:"tank-deposit",intentionData:{coinType:r,amount:e}}}decodeTankWithdraw(){let e=this.getMoveCallModuleCommand("tank_operations","withdraw").MoveCall,t=e.typeArguments[0],n="0",a=e.arguments[5];return a.$kind==="Input"&&(n=this.getPureInputU64(a.Input)),console.log("Decoder.decodeTankWithdraw",t,n),{txType:P.TransactionType.Other,type:"tank-withdraw",intentionData:{coinType:t,amount:n}}}decodeTankClaim(){let t=this.getMoveCallModuleCommand("tank_operations","claim").MoveCall.typeArguments[0];return console.log("Decoder.decodeTankClaim",t),{txType:P.TransactionType.Other,type:"tank-claim",intentionData:{coinType:t}}}decodeLockedClaim(){let e="",t=0,n=this.getMoveCallModuleCommands("proof_rule","claim");for(let r=0;r<n.length;r++)[e]=n[r].MoveCall.typeArguments,t++;let a=this.getMoveCallModuleCommands("lst_proof_rule","claim");for(let r=0;r<a.length;r++)[e]=a[r].MoveCall.typeArguments,t++;return console.log("Decoder.decodeLockedClaim",e,t),{txType:P.TransactionType.Other,type:"lock-claim",intentionData:{coinType:e,proofCount:t}}}getCoinInput(e){if(this.inputs[e].$kind!=="Object")throw new Error("not Object argument")}getStrapId(){let e;if(this.isStrapNewTransaction()?e="new":this.isLstUnlockTransaction()&&(e="locked"),!e){let t=this.getMoveCallModuleCommand("fountain","unstake");if(t){let n=t.MoveCall.arguments[2];n.$kind==="Input"&&(e=this.inputs[n.Input].UnresolvedObject.objectId)}}return e}getPureInputU64(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return Ne.bcs.U64.fromBase64(t.Pure.bytes)}getPureAddresses(e){let t=this.inputs[e];if(t.$kind!=="Pure")throw new Error("not pure argument");return Ne.bcs.vector(Ne.bcs.Address).fromBase64(t.Pure.bytes)}};var ii=require("@msafe/sui3-utils");var ai=require("@mysten/sui/transactions"),oi=require("bucket-protocol-sdk");var ni=require("bucket-protocol-sdk"),D=(o,e)=>{let t=o==="sui:mainnet"?"mainnet":"testnet";return new ni.BucketClient(t,e.address)};var ri=async(o,e,t)=>{let{coinType:n,amount:a,buckToCoin:r}=o,i=new ai.Transaction,s=D(t,e);return await(0,oi.buildPsmTx)(s,i,n,a,r,e.address),i};var Ue=class o extends u{constructor(t){super(t);this.data=t}txType=ii.TransactionType.Other;txSubType="psm";async build(t){let{account:n,network:a}=t;return await ri(this.data,n,a)}static fromData(t){return new o(t)}};var ui=require("@msafe/sui3-utils");var Xt=require("@mysten/sui/transactions"),Z=require("bucket-protocol-sdk");var si=async(o,e,t)=>{let{collateralType:n,collateralAmount:a,borrowAmount:r,insertionPlace:i,strapId:s}=o,c=new Xt.Transaction,l=D(t,e);return await(0,Z.buildBorrowTx)(l,c,n,a,r,e.address,i,s),c},ci=async(o,e,t)=>{let{collateralType:n,withdrawAmount:a,insertionPlace:r,strapId:i}=o,s=new Xt.Transaction,c=D(t,e);return await(0,Z.buildWithdrawTx)(c,s,n,a,e.address,r,i),s},li=async(o,e,t)=>{let{collateralType:n,repayAmount:a,withdrawAmount:r,isSurplus:i,insertionPlace:s,strapId:c}=o,l=new Xt.Transaction,d=D(t,e);return await(0,Z.buildRepayTx)(d,l,n,a,r,e.address,i,s,c),l},di=async(o,e,t)=>{let{collateralType:n,recipient:a,strapId:r}=o,i=new Xt.Transaction,s=D(t,e);return await(0,Z.buildCloseTx)(s,i,n,a,r),i};var Fe=class o extends u{constructor(t){super(t);this.data=t}txType=ui.TransactionType.Other;txSubType="borrow";async build(t){let{account:n,network:a}=t;return await si(this.data,n,a)}static fromData(t){return new o(t)}};var mi=require("@msafe/sui3-utils");var qe=class o extends u{constructor(t){super(t);this.data=t}txType=mi.TransactionType.Other;txSubType="repay";async build(t){let{account:n,network:a}=t;return await li(this.data,n,a)}static fromData(t){return new o(t)}};var pi=require("@msafe/sui3-utils");var Ke=class o extends u{constructor(t){super(t);this.data=t}txType=pi.TransactionType.Other;txSubType="withdraw";async build(t){let{account:n,network:a}=t;return await ci(this.data,n,a)}static fromData(t){return new o(t)}};var fi=require("@msafe/sui3-utils");var $e=class o extends u{constructor(t){super(t);this.data=t}txType=fi.TransactionType.Other;txSubType="close";async build(t){let{account:n,network:a}=t;return await di(this.data,n,a)}static fromData(t){return new o(t)}};var te=require("@msafe/sui3-utils");var Zt=require("@mysten/sui/transactions"),tt=require("bucket-protocol-sdk");var bi=async(o,e,t)=>{let{coinType:n,amount:a,isStake:r}=o,i=new Zt.Transaction,s=D(t,e);return await(0,tt.buildSBUCKDepositTx)(s,i,n,a,e.address,r),i},hi=async(o,e,t)=>{let{stakeProofs:n,amount:a,isStake:r,toBuck:i}=o,s=new Zt.Transaction,c=D(t,e);return await(0,tt.buildSBUCKUnstakeTx)(c,s,n,a,e.address,r,i),s},gi=async(o,e,t)=>{let{amount:n}=o,a=new Zt.Transaction,r=D(t,e);return await(0,tt.buildSBUCKWithdrawTx)(r,a,n,e.address),a},yi=async(o,e,t)=>{let{stakeProofs:n}=o,a=new Zt.Transaction,r=D(t,e);return await(0,tt.buildSBUCKClaimTx)(r,a,n,e.address),a};var Ve=class o extends u{constructor(t){super(t);this.data=t}txType=te.TransactionType.Other;txSubType="sbuck-deposit";async build(t){let{account:n,network:a}=t;return await bi(this.data,n,a)}static fromData(t){return new o(t)}},He=class o extends u{constructor(t){super(t);this.data=t}txType=te.TransactionType.Other;txSubType="sbuck-unstake";async build(t){let{account:n,network:a}=t;return await hi(this.data,n,a)}static fromData(t){return new o(t)}},Ge=class o extends u{constructor(t){super(t);this.data=t}txType=te.TransactionType.Other;txSubType="sbuck-withdraw";async build(t){let{account:n,network:a}=t;return await gi(this.data,n,a)}static fromData(t){return new o(t)}},Qe=class o extends u{constructor(t){super(t);this.data=t}txType=te.TransactionType.Other;txSubType="sbuck-claim";async build(t){let{account:n,network:a}=t;return await yi(this.data,n,a)}static fromData(t){return new o(t)}};var Ze=require("@msafe/sui3-utils");var ze=require("@mysten/sui/transactions"),Ot=require("bucket-protocol-sdk");var Ti=async(o,e,t)=>{let{coinType:n,amount:a}=o,r=new ze.Transaction,i=D(t,e);return await(0,Ot.buildTankDepositTx)(i,r,n,a,e.address),r},Ci=async(o,e,t)=>{let{coinType:n,amount:a}=o,r=new ze.Transaction,i=D(t,e);return await(0,Ot.buildTankWithdrawTx)(i,r,n,a,e.address),r},Ii=async(o,e,t)=>{let{coinType:n}=o,a=new ze.Transaction,r=D(t,e);return await(0,Ot.buildTankClaimTx)(r,a,n,e.address),a};var Si=require("@mysten/sui/transactions"),wi=require("bucket-protocol-sdk");var ki=async(o,e,t)=>{let{coinType:n,proofCount:a}=o,r=new Si.Transaction,i=D(t,e);return await(0,wi.buildLockedClaimTx)(i,r,n,a,e.address),r};var Je=class o extends u{constructor(t){super(t);this.data=t}txType=Ze.TransactionType.Other;txSubType="tank-deposit";async build(t){let{account:n,network:a}=t;return await Ti(this.data,n,a)}static fromData(t){return new o(t)}},Ye=class o extends u{constructor(t){super(t);this.data=t}txType=Ze.TransactionType.Other;txSubType="tank-withdraw";async build(t){let{account:n,network:a}=t;return await Ci(this.data,n,a)}static fromData(t){return new o(t)}},Xe=class o extends u{constructor(t){super(t);this.data=t}txType=Ze.TransactionType.Other;txSubType="tank-claim";async build(t){let{account:n,network:a}=t;return await Ii(this.data,n,a)}static fromData(t){return new o(t)}};var xi=require("@msafe/sui3-utils");var tn=class o extends u{constructor(t){super(t);this.data=t}txType=xi.TransactionType.Other;txSubType="lock-claim";async build(t){let{account:n,network:a}=t;return await ki(this.data,n,a)}static fromData(t){return new o(t)}};var en=class{application="bucket";supportSDK="@mysten/sui";async deserialize(e){console.log("Bucket helper deserialize input: ",e);let{transaction:t}=e,a=new je(t).decode();return{txType:Di.TransactionType.Other,txSubType:a.type,intentionData:a.intentionData}}async build(e){let{suiClient:t,account:n,network:a}=e,r;switch(e.txSubType){case"psm":r=Ue.fromData(e.intentionData);break;case"borrow":r=Fe.fromData(e.intentionData);break;case"withdraw":r=Ke.fromData(e.intentionData);break;case"repay":r=qe.fromData(e.intentionData);break;case"close":r=$e.fromData(e.intentionData);break;case"tank-deposit":r=Je.fromData(e.intentionData);break;case"tank-withdraw":r=Ye.fromData(e.intentionData);break;case"tank-claim":r=Xe.fromData(e.intentionData);break;case"sbuck-deposit":r=Ve.fromData(e.intentionData);break;case"sbuck-unstake":r=He.fromData(e.intentionData);break;case"sbuck-withdraw":r=Ge.fromData(e.intentionData);break;case"sbuck-claim":r=Qe.fromData(e.intentionData);break;case"lock-claim":r=tn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:a})}};var As=require("@msafe/sui3-utils");var Ni=require("@msafe/sui3-utils");var ee=require("@cetusprotocol/aggregator-sdk"),vi=require("@cetusprotocol/cetus-periphery-sdk"),Ai=require("@cetusprotocol/cetus-sui-clmm-sdk"),Oi=require("@cetusprotocol/cetus-xcetus-sdk"),Pi=q(require("@cetusprotocol/vaults-sdk")),ne=require("@mysten/sui/client"),od={fullRpcUrl:(0,ne.getFullnodeUrl)("mainnet"),simulationAccount:{address:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"},cetus_config:{package_id:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",published_at:"0x95b8d278b876cae22206131fb9724f701c9444515813042f54f0a426c9a3bc2f",config:{coin_list_id:"0x8cbc11d9e10140db3d230f50b4d30e9b721201c0083615441707ffec1ef77b23",launchpad_pools_id:"0x1098fac992eab3a0ab7acf15bb654fc1cf29b5a6142c4ef1058e6c408dd15115",clmm_pools_id:"0x15b6a27dd9ae03eb455aba03b39e29aad74abd3757b8e18c0755651b2ae5b71e",admin_cap_id:"0x39d78781750e193ce35c45ff32c6c0c3f2941fa3ddaf8595c90c555589ddb113",global_config_id:"0x0408fa4e4a4c03cc0de8f23d0c2bbfe8913d178713c9a271ed4080973fe42d8f",coin_list_handle:"0x49136005e90e28c4695419ed4194cc240603f1ea8eb84e62275eaff088a71063",launchpad_pools_handle:"0x5e194a8efcf653830daf85a85b52e3ae8f65dc39481d54b2382acda25068375c",clmm_pools_handle:"0x37f60eb2d9d227949b95da8fea810db3c32d1e1fa8ed87434fc51664f87d83cb"}},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0xc6faf3703b0e8ba9ed06b7851134bbbe7565eb35ff823fd78432baa4cbeaa12e",version:4,config:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:""}},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0x2d8c2e0fc6dd25b0214b3fa747e0fd27fd54608142cd2e4f64c1cd350cc4add4",version:6},deepbook:{package_id:"0x000000000000000000000000000000000000000000000000000000000000dee9",published_at:"0x000000000000000000000000000000000000000000000000000000000000dee9"},deepbook_endpoint_v2:{package_id:"0x92aee86c01c79146d23938a00c7fff725ee0688c389be36d1bcbe03761b466c6",published_at:"0x92aee86c01c79146d23938a00c7fff725ee0688c389be36d1bcbe03761b466c6"},aggregatorUrl:"https://api-sui.cetus.zone/router",swapCountUrl:"https://api-sui.cetus.zone/v2/sui/swap/count"},rd={launchpad:{package_id:"0x80d114c5d474eabc2eb2fcd1a0903f1eb5b5096a8dc4184d72453f7a9be728e4",published_at:"0x80d114c5d474eabc2eb2fcd1a0903f1eb5b5096a8dc4184d72453f7a9be728e4",config:{pools_id:"0xfd8d37f7a1276878972d240302c8efe32f577220c1bbc6c8984d8b60dddfcab3",admin_cap_id:"0x66c70d58c69353714cc6fe2d3a62492d605a96a9821e2bd8274de17219c69980",config_cap_id:"0x02b8d23f033687579966e182c776fe0287cacdbb18bff56c29f141e29a18a4d1"}},ido:{package_id:"0x1192c9e20b4b0a8848a73a8c711b43e38f7ea1f307b556aab6ffab4e982e9c59",published_at:"0x1192c9e20b4b0a8848a73a8c711b43e38f7ea1f307b556aab6ffab4e982e9c59",config:{pools_id:"0xefc209b47acf1f23b29d166440904600229e520ad36228aaf2329b7c16be9762",admin_cap_id:"0x281859d366951830aeeda90779aa170d8ee6845875545470d33ecb890e78c8ce",package_version_id:"0xc93dc996106770af5f4e979b6808518f8cee080f22f35b936f071f59d834bb22"}},xcetus:{package_id:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",published_at:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",config:{xcetus_manager_id:"0x838b3dbade12b1e602efcaf8c8b818fae643e43176462bf14fd196afa59d1d9d",lock_manager_id:"0x288b59d9dedb51d0bb6cb5e13bfb30885ecf44f8c9076b6f5221c5ef6644fd28",lock_handle_id:"0x7c534bb7b8a2cc21538d0dbedd2437cc64f47106cb4c259b9ff921b5c3cb1a49"}},xcetus_dividends:{package_id:"0x785248249ac457dfd378bdc6d2fbbfec9d1daf65e9d728b820eb4888c8da2c10",published_at:"0x5aa58e1623885bd93de2331d05c29bf4930e54e56beeabcab8fe5385de2d31dc",config:{dividend_manager_id:"0x721c990bfc031d074341c6059a113a59c1febfbd2faeb62d49dcead8408fa6b5",dividend_admin_id:"0x682ba823134f156eac2bcfb27d85a284954a0e61998dc628c40b9bcb4a46ff30",dividend_settle_id:"0xade40abe9f6dd10b83b11085be18f07b63b681cf1c169b041fa16854403388c5",venft_dividends_id:"0x9dcdb97b4307684bedaeaf803d381b12321a31ecbb9dad7df2cd5f64384f9456",venft_dividends_id_v2:"0xaa21fbc1707786d56302952f8327362f4eb9a431a5bc574834e6d46125390de3"}},cetus_faucet:{package_id:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",published_at:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b"},xtoken:{package_id:"",published_at:"",config:{xtoken_manager_id:"",lock_manager_id:"",lock_handle_id:""}},xtoken_dividends:{package_id:"",published_at:"",config:{dividend_manager_id:"",dividend_admin_id:"",dividend_settle_id:""}},token_faucet:{package_id:"",published_at:""},booster:{package_id:"",published_at:"",config:{booster_config_id:"",booster_pool_handle:""}},maker_bonus:{package_id:"",published_at:"",config:{maker_config_id:"",maker_pool_handle:""}},liquidity_stratefy:{package_id:"",published_at:"",version:void 0,config:void 0},vaults:{package_id:"0xd3453d9be7e35efe222f78a810bb3af1859fd1600926afced8b4936d825c9a05",published_at:"0x58e5de6e425397eeaf952d55c0f94637bee91b25d6138ce222f89cda0aefec03",version:1,config:{admin_cap_id:"0x78a42978709c4032fab7b33b782b5bcef64c1c6603250bf23644650b72144375",vaults_manager_id:"0x25b82dd2f5ee486ed1c8af144b89a8931cd9c29dee3a86a1bfe194fdea9d04a6",vaults_pool_handle:"0x9036bcc5aa7fd2cceec1659a6a1082871f45bc400c743f50063363457d1738bd",haedal:{package_id:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",published_at:"0xaabf0856070391df81fad9240049d69c5a51c3d376cc0885eeedd516526cc79b",version:1,config:{staking_id:"0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",coin_type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"}},volo:{package_id:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",published_at:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",version:1,config:{native_pool:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",vsui_metadata:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",coin_type:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"}},aftermath:{package_id:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",published_at:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",version:1,config:{staked_sui_vault:"0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",referral_vault:"0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",safe:"0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",validator_address:"0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2",coin_type:"0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"}}}},limit_order:{package_id:"",published_at:"",version:1,config:{rate_orders_indexer_id:"",rate_orders_indexer_handle:"",global_config_id:"",token_list_handle:"",user_orders_indexer_id:"",user_orders_indexer_handle:""}},frams:{package_id:"0x11ea791d82b5742cc8cab0bf7946035c97d9001d7c3803a93f119753da66f526",published_at:"0x7e4ca066f06a1132ab0499c8c0b87f847a0d90684afa902e52501a44dbd81992",version:1,config:{global_config_id:"0x21215f2f6de04b57dd87d9be7bb4e15499aec935e36078e2488f36436d64996e",rewarder_manager_id:"0xe0e155a88c77025056da08db5b1701a91b79edb6167462f768e387c3ed6614d5",rewarder_manager_handle:"0xb32e312cbb3367d6f3d2b4e57c9225e903d29b7b9f612dae2ddf75bdeb26a5aa",admin_cap_id:"0xf10fbf1fea5b7aeaa524b87769461a28c5c977613046360093673991f26d886c"}},dca:{package_id:"",published_at:"",version:0,config:{admin_cap_id:"",global_config_id:"",indexer_id:"",user_indexer_id:"",in_coin_whitelist_id:"",out_coin_whitelist_id:""}}},id={fullRpcUrl:(0,ne.getFullnodeUrl)("mainnet"),simulationAccount:{address:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"},xcetus:{package_id:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",published_at:"0x9e69acc50ca03bc943c4f7c5304c2a6002d507b51c11913b247159c60422c606",config:{xcetus_manager_id:"0x838b3dbade12b1e602efcaf8c8b818fae643e43176462bf14fd196afa59d1d9d",lock_manager_id:"0x288b59d9dedb51d0bb6cb5e13bfb30885ecf44f8c9076b6f5221c5ef6644fd28",lock_handle_id:"0x7c534bb7b8a2cc21538d0dbedd2437cc64f47106cb4c259b9ff921b5c3cb1a49"}},xcetus_dividends:{package_id:"0x785248249ac457dfd378bdc6d2fbbfec9d1daf65e9d728b820eb4888c8da2c10",published_at:"0x5aa58e1623885bd93de2331d05c29bf4930e54e56beeabcab8fe5385de2d31dc",version:4,config:{dividend_manager_id:"0x721c990bfc031d074341c6059a113a59c1febfbd2faeb62d49dcead8408fa6b5",dividend_admin_id:"0x682ba823134f156eac2bcfb27d85a284954a0e61998dc628c40b9bcb4a46ff30",dividend_settle_id:"0xade40abe9f6dd10b83b11085be18f07b63b681cf1c169b041fa16854403388c5",venft_dividends_id:"0x9dcdb97b4307684bedaeaf803d381b12321a31ecbb9dad7df2cd5f64384f9456",venft_dividends_id_v2:"0xaa21fbc1707786d56302952f8327362f4eb9a431a5bc574834e6d46125390de3"}},cetus_faucet:{package_id:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",published_at:"0x6864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b"}},St=(o,e)=>{let t=od,n=new Ai.CetusClmmSDK(t);return n.senderAddress=e.address,n},$=(o,e)=>{let t=St(o,e),n=rd;return new vi.CetusPeripherySDK(n,t)},sd="https://api-sui.cetus.zone/router_v2/find_routes",Ri=(o,e)=>{let t=new ne.SuiClient({url:"https://fullnode.mainnet.sui.io/"});return new ee.AggregatorClient({endpoint:sd,signer:e.address,client:t,env:ee.Env.Mainnet})},cd={fullRpcUrl:"https://fullnode.mainnet.sui.io/",simulationAccount:{address:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb"},clmm_pool:{package_id:"0x1eabed72c53feb3805120a081dc15963c204dc8d091542592abaf7a35689b2fb",published_at:"0xc6faf3703b0e8ba9ed06b7851134bbbe7565eb35ff823fd78432baa4cbeaa12e",config:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:""}},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0x2d8c2e0fc6dd25b0214b3fa747e0fd27fd54608142cd2e4f64c1cd350cc4add4"},frams:{package_id:"0x11ea791d82b5742cc8cab0bf7946035c97d9001d7c3803a93f119753da66f526",published_at:"0x7e4ca066f06a1132ab0499c8c0b87f847a0d90684afa902e52501a44dbd81992",config:{global_config_id:"0x21215f2f6de04b57dd87d9be7bb4e15499aec935e36078e2488f36436d64996e",rewarder_manager_id:"0xe0e155a88c77025056da08db5b1701a91b79edb6167462f768e387c3ed6614d5",rewarder_manager_handle:"0xb32e312cbb3367d6f3d2b4e57c9225e903d29b7b9f612dae2ddf75bdeb26a5aa",admin_cap_id:"0xf10fbf1fea5b7aeaa524b87769461a28c5c977613046360093673991f26d886c"}},vaults:{package_id:"0xd3453d9be7e35efe222f78a810bb3af1859fd1600926afced8b4936d825c9a05",published_at:"0x58e5de6e425397eeaf952d55c0f94637bee91b25d6138ce222f89cda0aefec03",config:{admin_cap_id:"0x78a42978709c4032fab7b33b782b5bcef64c1c6603250bf23644650b72144375",vaults_manager_id:"0x25b82dd2f5ee486ed1c8af144b89a8931cd9c29dee3a86a1bfe194fdea9d04a6",vaults_pool_handle:"0x9036bcc5aa7fd2cceec1659a6a1082871f45bc400c743f50063363457d1738bd",haedal:{package_id:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",published_at:"0xaabf0856070391df81fad9240049d69c5a51c3d376cc0885eeedd516526cc79b",version:1,config:{staking_id:"0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",coin_type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"}},volo:{package_id:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",published_at:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",version:1,config:{native_pool:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",vsui_metadata:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",coin_type:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT"}},aftermath:{package_id:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",published_at:"0x7f6ce7ade63857c4fd16ef7783fed2dfc4d7fb7e40615abdb653030b76aef0c6",version:1,config:{staked_sui_vault:"0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d",referral_vault:"0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef",safe:"0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610",validator_address:"0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2",coin_type:"0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI"}}}},aggregator:{endPoint:"https://api-sui.cetus.zone/router_v2/find_routes",fullNodeurl:"https://fullnode.mainnet.sui.io/",walletAddress:"0x326ce9894f08dcaa337fa232641cc34db957aec9ff6614c1186bc9a7508df0bb",env:ee.Env.Mainnet,providers:["CETUS","DEEPBOOK","KRIYA","KRIYAV3","FLOWX","FLOWXV3","AFTERMATH","TURBOS","HAEDAL","VOLO","AFSUI"]}},er=(o,e)=>{let t=new Pi.default(cd);return t.senderAddress=e.address,t},Pt=(o,e)=>{let t=new Oi.CetusXcetusSDK(id);return t.senderAddress=e.address,t};var Bi=async(o,e,t)=>await St(t,e).Position.createAddLiquidityFixTokenPayload(o?.parameter,o?.gasEstimateArg),_i=async(o,e,t)=>await St(t,e).Position.createAddLiquidityFixTokenPayload(o?.parameter,o?.gasEstimateArg),Ei=async(o,e,t)=>await St(t,e).Position.closePositionTransactionPayload(o),Mi=async(o,e,t)=>await St(t,e).Position.removeLiquidityTransactionPayload(o),Wi=async(o,e,t)=>await St(t,e).Rewarder.collectRewarderTransactionPayload(o);var nn=class o extends u{constructor(t){super(t);this.data=t}txType=Ni.TransactionType.Other;txSubType="OpenAndAddLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Bi(r,n,a)}static fromData(t){return new o(t)}};var Li=require("@msafe/sui3-utils");var an=class o extends u{constructor(t){super(t);this.data=t}txType=Li.TransactionType.Other;txSubType="ClaimFeeAndMining";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Wi(r,n,a)}static fromData(t){return new o(t)}};var ji=require("@msafe/sui3-utils");var on=class o extends u{constructor(t){super(t);this.data=t}txType=ji.TransactionType.Other;txSubType="DecreaseLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Mi(r,n,a)}static fromData(t){return new o(t)}};var zi=require("@msafe/sui3-utils");var Ui=async(o,e,t)=>await $(t,e).Farms.openPositionAddLiquidityStakePaylod(o),Fi=async(o,e,t)=>await $(t,e).Farms.addLiquidityFixCoinPayload(o),qi=async(o,e,t)=>await $(t,e).Farms.removeLiquidityPayload(o),Ki=async(o,e,t)=>await $(t,e).Farms.removeLiquidityPayload(o),$i=async(o,e,t)=>await $(t,e).Farms.claimFeeAndClmmReward(o),Vi=async(o,e,t)=>await $(t,e).Farms.harvestPayload(o),Hi=async(o,e,t)=>{let n=$(t,e),a=Object.values(o);return await n.Farms.batchHarvestPayload(a)},Gi=async(o,e,t)=>await $(t,e).Farms.depositPayload(o),Qi=async(o,e,t)=>await $(t,e).Farms.withdrawPayload(o);var rn=class o extends u{constructor(t){super(t);this.data=t}txType=zi.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Ui(r,n,a)}static fromData(t){return new o(t)}};var Ji=require("@msafe/sui3-utils");var sn=class o extends u{constructor(t){super(t);this.data=t}txType=Ji.TransactionType.Other;txSubType="FarmingBatchHarvest";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Hi(r,n,a)}static fromData(t){return new o(t)}};var Yi=require("@msafe/sui3-utils");var cn=class o extends u{constructor(t){super(t);this.data=t}txType=Yi.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await $i(r,n,a)}static fromData(t){return new o(t)}};var Xi=require("@msafe/sui3-utils");var ln=class o extends u{constructor(t){super(t);this.data=t}txType=Xi.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await qi(r,n,a)}static fromData(t){return new o(t)}};var Zi=require("@msafe/sui3-utils");var dn=class o extends u{constructor(t){super(t);this.data=t}txType=Zi.TransactionType.Other;txSubType="FarmingHarvest";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Vi(r,n,a)}static fromData(t){return new o(t)}};var ts=require("@msafe/sui3-utils");var un=class o extends u{constructor(t){super(t);this.data=t}txType=ts.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Fi(r,n,a)}static fromData(t){return new o(t)}};var es=require("@msafe/sui3-utils");var mn=class o extends u{constructor(t){super(t);this.data=t}txType=es.TransactionType.Other;txSubType="FarmingRemoveLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Ki(r,n,a)}static fromData(t){return new o(t)}};var ns=require("@msafe/sui3-utils");var pn=class o extends u{constructor(t){super(t);this.data=t}txType=ns.TransactionType.Other;txSubType="FarmingStake";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Gi(r,n,a)}static fromData(t){return new o(t)}};var as=require("@msafe/sui3-utils");var fn=class o extends u{constructor(t){super(t);this.data=t}txType=as.TransactionType.Other;txSubType="FarmingUnstake";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Qi(r,n,a)}static fromData(t){return new o(t)}};var os=require("@msafe/sui3-utils");var bn=class o extends u{constructor(t){super(t);this.data=t}txType=os.TransactionType.Other;txSubType="IncreaseLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await _i(r,n,a)}static fromData(t){return new o(t)}};var rs=require("@msafe/sui3-utils");var hn=class o extends u{constructor(t){super(t);this.data=t}txType=rs.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Ei(r,n,a)}static fromData(t){return new o(t)}};var ls=require("@msafe/sui3-utils");var is=require("@cetusprotocol/aggregator-sdk"),ss=require("@mysten/sui/transactions");var cs=async(o,e,t)=>{let n=Ri(t,e),a=new ss.Transaction;return await n.fastRouterSwap({...o,routers:(0,is.restituteMsafeFastRouterSwapParams)(o.routers),txb:a}),a};var gn=class o extends u{constructor(t){super(t);this.data=t}txType=ls.TransactionType.Other;txSubType="AggregatorSwap";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await cs(r,n,a)}static fromData(t){return new o(t)}};var ms=require("@msafe/sui3-utils");var ds=async(o,e,t)=>await er(t,e).Vaults.deposit(o),us=async(o,e,t)=>await er(t,e).Vaults.withdraw(o);var yn=class o extends u{constructor(t){super(t);this.data=t}txType=ms.TransactionType.Other;txSubType="AddVaultsPosition";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await ds(r,n,a)}static fromData(t){return new o(t)}};var ps=require("@msafe/sui3-utils");var Tn=class o extends u{constructor(t){super(t);this.data=t}txType=ps.TransactionType.Other;txSubType="RemoveVaultsPosition";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await us(r,n,a)}static fromData(t){return new o(t)}};var gs=require("@msafe/sui3-utils");var bs=require("@mysten/sui/transactions"),fs={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},hs=async(o,e,t)=>{console.log("getVestingRedeemTxb txbParams: ",o),console.log("getVestingRedeemTxb account: ",e),console.log("getVestingRedeemTxb network: ",t);let{pool:n,nftId:a,periods:r,CLOCK_ADDRESS:i}=o,s=new bs.Transaction;return r.forEach(c=>{s.moveCall({target:`${fs.published_at}::router::redeem`,typeArguments:[fs.cetus_coin_type],arguments:[s.object(n),s.object(a),s.pure(c),s.object(i)]})}),s};var Cn=class o extends u{constructor(t){super(t);this.data=t}txType=gs.TransactionType.Other;txSubType="VestingRedeem";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await hs(r,n,a)}static fromData(t){return new o(t)}};var ws=require("@msafe/sui3-utils");var ys=async(o,e,t)=>await Pt(t,e).XCetusModule.convertPayload(o),Ts=async(o,e,t)=>await Pt(t,e).XCetusModule.redeemLockPayload(o),Cs=async(o,e,t)=>await Pt(t,e).XCetusModule.redeemDividendV3Payload(o.veNftId,o.rewardList),Is=async(o,e,t)=>await Pt(t,e).XCetusModule.cancelRedeemPayload(o),Ss=async(o,e,t)=>await Pt(t,e).XCetusModule.redeemPayload(o);var In=class o extends u{constructor(t){super(t);this.data=t}txType=ws.TransactionType.Other;txSubType="xCETUSCancelRedeem";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Is(r,n,a)}static fromData(t){return new o(t)}};var ks=require("@msafe/sui3-utils");var Sn=class o extends u{constructor(t){super(t);this.data=t}txType=ks.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Cs(r,n,a)}static fromData(t){return new o(t)}};var xs=require("@msafe/sui3-utils");var wn=class o extends u{constructor(t){super(t);this.data=t}txType=xs.TransactionType.Other;txSubType="xCETUSConvert";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await ys(r,n,a)}static fromData(t){return new o(t)}};var Ds=require("@msafe/sui3-utils");var kn=class o extends u{constructor(t){super(t);this.data=t}txType=Ds.TransactionType.Other;txSubType="xCETUSRedeem";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Ss(r,n,a)}static fromData(t){return new o(t)}};var vs=require("@msafe/sui3-utils");var xn=class o extends u{constructor(t){super(t);this.data=t}txType=vs.TransactionType.Other;txSubType="xCETUSRedeemLock";async build(t){let{account:n,network:a}=t,{txbParams:r}=this.data;return await Ts(r,n,a)}static fromData(t){return new o(t)}};var Dn=class{application="cetus";supportSDK="@mysten/sui";async deserialize(e){console.log("Cetus helper deserialize input: ",e);let{txbParams:t,action:n}=e;return{txType:As.TransactionType.Other,txSubType:n,intentionData:{txbParams:{...t},action:n}}}async build(e){let{suiClient:t,account:n,network:a}=e,r;switch(e.txSubType){case"OpenAndAddLiquidity":r=nn.fromData(e.intentionData);break;case"IncreaseLiquidity":r=bn.fromData(e.intentionData);break;case"DecreaseLiquidity":r=on.fromData(e.intentionData);break;case"RemoveLiquidity":r=hn.fromData(e.intentionData);break;case"ClaimFeeAndMining":r=an.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":r=rn.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":r=un.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":r=ln.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":r=mn.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":r=cn.fromData(e.intentionData);break;case"FarmingHarvest":r=dn.fromData(e.intentionData);break;case"FarmingBatchHarvest":r=sn.fromData(e.intentionData);break;case"FarmingStake":r=pn.fromData(e.intentionData);break;case"FarmingUnstake":r=fn.fromData(e.intentionData);break;case"xCETUSConvert":r=wn.fromData(e.intentionData);break;case"xCETUSRedeemLock":r=xn.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":r=Sn.fromData(e.intentionData);break;case"xCETUSCancelRedeem":r=In.fromData(e.intentionData);break;case"xCETUSRedeem":r=kn.fromData(e.intentionData);break;case"VestingRedeem":r=Cn.fromData(e.intentionData);break;case"AggregatorSwap":r=gn.fromData(e.intentionData);break;case"AddVaultsPosition":r=yn.fromData(e.intentionData);break;case"RemoveVaultsPosition":r=Tn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:a})}};var Ys=require("@msafe/sui3-utils");var Os=q(require("sort-keys-recursive")),h=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Os.default)(this.data))}};var ae=require("@mysten/sui.js/client");var nr={};tr(nr,{contractId:()=>ud,default:()=>hd,feeObjId:()=>fd,roleObjId:()=>md,status:()=>dd,transaction:()=>ld,upgradeCapObjId:()=>bd,vaultObjId:()=>pd});var ld="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",dd="success",ud="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",md="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",pd="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",fd="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",bd="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",hd={transaction:ld,status:dd,contractId:ud,roleObjId:md,vaultObjId:pd,feeObjId:fd,upgradeCapObjId:bd};var ar={};tr(ar,{contractId:()=>Td,default:()=>kd,feeObjId:()=>Sd,roleObjId:()=>Cd,status:()=>yd,transaction:()=>gd,upgradeCapObjId:()=>wd,vaultObjId:()=>Id});var gd="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",yd="success",Td="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",Cd="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",Id="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",Sd="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",wd="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",kd={transaction:gd,status:yd,contractId:Td,roleObjId:Cd,vaultObjId:Id,feeObjId:Sd,upgradeCapObjId:wd};var xd=(0,ae.getFullnodeUrl)("testnet"),Dd=(0,ae.getFullnodeUrl)("testnet"),vd=(0,ae.getFullnodeUrl)("mainnet"),Ad=(0,ae.getFullnodeUrl)("mainnet"),Od="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",Pd="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",Rd="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",Bd="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",Ps=nr,Rs=ar,_d=new Map([["dev",{env:"dev",rpc:{url:xd},backend:{url:Od},contract:Ps}],["stg",{env:"stg",rpc:{url:Dd},backend:{url:Pd},contract:Ps}],["prev",{env:"prev",rpc:{url:vd},backend:{url:Rd},contract:Rs}],["prod",{env:"prod",rpc:{url:Ad},backend:{url:Bd},contract:Rs}]]);function Bs(o,e){let t=_d.get(o);if(!t)throw new Error(`Env not supported: ${o}`);return e&&e.rpc&&(t.rpc=e.rpc),e&&e.backend&&(t.backend=e.backend),e&&e.contract&&(t.contract=e.contract),t}var _s=require("@mysten/sui.js/client");var C=class extends Error{mpayErrorCode;context;constructor(e,t,n={}){let{cause:a,context:r}=n;a?super(`[MPay] ${t}: ${a}`):super(`[MPay] ${t}`),this.mpayErrorCode=e,this.context=r}};var vn=class extends C{constructor(){super(11,"Backend is not specified")}};var An=class extends C{constructor(){super(1,"Wallet not connected")}};var Y=q(require("axios"));var Rt=class extends C{constructor(e,t){super(10,e,{context:t})}};var On=class o{constructor(e){this.apiURL=e}static parseResponseData(e){if(e instanceof Y.AxiosError)throw new Rt(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new Rt(e.data.code)}throw new Rt(e.status.toString())}async getIncomingStreams(e,t){let n=await Y.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return o.parseResponseData(n)}async getOutgoingStreams(e,t){let n=await Y.default.post(`${this.apiURL}/stream`,{sender:e,...t});return o.parseResponseData(n)}async getStreamHistory(e){let t=await Y.default.post(`${this.apiURL}/stream-events`,e),n=o.parseResponseData(t);return n.data.forEach(a=>{let r=a;return r.data.type==="create_stream"?r.data.balance=BigInt(r.data.balance):r.data.type==="cancel_stream"?r.data.withdrawAmount=BigInt(r.data.withdrawAmount):r.data.type==="claim"||r.data.type==="auto_claim"?r.data.claimAmount=BigInt(r.data.claimAmount):r.data.type==="set_auto_claim"&&(r.data.enabled=!!r.data.enabled),r.createdAt=new Date(r.createdAt),r}),n}async getAllCoinTypes(e){let t=await Y.default.post(`${this.apiURL}/stream-info`,{address:e});return o.parseResponseData(t)}async getAllRecipients(e,t){let n=await Y.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return o.parseResponseData(n)}async getAllSenders(e,t){let n=await Y.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return o.parseResponseData(n)}};var Bt=class o{signer;suiClient;envConfig;_backend;constructor(e){this.envConfig=e,this.suiClient=new _s.SuiClient({url:e.rpc.url}),e.backend&&(this._backend=new On(e.backend.url))}static new(e,t){let n=Bs(e,t);return new o(n)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new vn;return this._backend}set backend(e){this._backend=e}connectWallet(e){this.signer=e}disconnect(){this.signer=void 0}get wallet(){if(!this.signer)throw new An;return this.signer}async walletAddress(){return this.wallet.address()}};var kt=require("@mysten/sui.js/utils");var le=require("@mysten/sui.js/transactions");var cr=require("@mysten/sui.js/transactions"),ce=require("@mysten/sui.js/utils");var or=50n,Pn=10000n,Es=25n,rr=100000000n;var V=class{constructor(e){this.object=e}moveArg(e){return e.object(this.object)}},oe=class{constructor(e){this.objects=e}moveArgs(e){return e.makeMoveVec({objects:this.objects.map(t=>e.object(t))})}},at=class o{constructor(e){this.result=e;return new Proxy(this,{set(){throw new Error("The transaction result is a proxy, and does not support setting properties directly")},get(t,n){if(n in t)return Reflect.get(t,n);let a=i=>new o(t.result[i]);if(n===Symbol.iterator)return function*(){let i=0;for(;;)yield a(i),i++};if(typeof n=="symbol")return;let r=parseInt(n,10);if(!(Number.isNaN(r)||r<0))return a(r)}})}moveArg(){return this.result}};var ir=require("buffer"),Ms=require("@mysten/sui.js/utils");var re=class extends C{constructor(e,t){super(3,e,{context:t})}};var Rn=class{constructor(e){this.results=e}callResult(e){return this.results.results[e]}returnValue(e,t){return e.returnValues[t]}getValue(e=0,t=0){let n=this.callResult(e);return this.returnValue(n,t)}getAddress(e=0,t=0){let[n,a]=this.getValue(e,t);if(a!=="address")throw new re("Invalid contract return type.",{ctx:{expectType:"address",gotType:a}});return(0,Ms.normalizeSuiAddress)(ir.Buffer.from(n).toString("hex"))}getU64(e=0,t=0){let[n,a]=this.getValue(e,t);if(a!=="u64")throw new re("Invalid contract return type.",{ctx:{expectType:"u64",gotType:a}});return ir.Buffer.from(n).readBigInt64LE()}};var sr=require("@mysten/sui.js/bcs");var S=class extends C{constructor(e,t,n){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:n}})}};var Ns={groupId:"string",name:"string"},Ed=64;function Ls(o){return js(o),sr.bcs.ser(Ns,o).toString("base64")}function ie(o){let e=sr.bcs.de(Ns,o,"base64");return js(e),e}function js(o){if(!Ws(o.name))throw new S("Invalid metadata: Name contains unknown character");if(!Ws(o.groupId))throw new S("Invalid metadata: Group ID contains unknown character");if(o.name.length>Ed)throw new S("Invalid metadata: Name exceed max length 64")}function Ws(o){return/^[\x00-\x7F]+$/.test(o)}var se=require("@mysten/sui.js/utils");function Bn(o,e){return(0,se.normalizeStructTag)(o)===(0,se.normalizeStructTag)(e)}function ot(o,e){return(0,se.normalizeStructTag)(o)===(0,se.normalizeStructTag)(e)}var _n="txn.gas";var Us=require("nanoid");function Fs(){return(0,Us.nanoid)()}var wt=class o{constructor(e,t,n){this.globals=e;this.feeContract=t;this.streamContract=n}static convertCreateStreamInfoToInternal(e){return{metadata:Ls({name:e.name,groupId:Fs()}),coinType:(0,ce.normalizeStructTag)(e.coinType),recipients:e.recipients.map(t=>({address:t.address,cliffAmount:t.cliffAmount,amountPerEpoch:t.amountPerStep})),epochInterval:e.interval,numberEpoch:e.steps,startTime:e.startTimeMs,cancelable:e.cancelable}}async buildCreateStreamTransactionBlock(e){let t=new cr.TransactionBlock,n=this.calculateFeesInternal(e),a=this.getCreateStreamCoinRequests(e,n),r=await this.wallet.requestCoins(a),i=await this.addMergeCoins(t,r[0]),s;a.length>1?s=await this.addMergeCoins(t,r[1]):s=i;for(let c=0;c<e.recipients.length;c++){let l=e.recipients[c],d=this.amountForRecipient(l,e.numberEpoch),m=this.getStreamFeeLocal(d),[p]=t.splitCoins(i,[t.pure(d+m,"u64")]),[f]=t.splitCoins(s,[t.pure(this.flatSuiFee,"u64")]);this.streamContract.createStream(t,{paymentCoin:new at(p),flatFeeCoin:new at(f),metadata:e.metadata,recipient:l.address,timeStart:e.startTime,cliff:l.cliffAmount,epochInterval:e.epochInterval,numEpoch:e.numberEpoch,amountPerEpoch:l.amountPerEpoch,cancelable:e.cancelable,coinType:e.coinType})}return t}calculateCreateStreamFees(e){let t=o.convertCreateStreamInfoToInternal(e);return this.calculateFeesInternal(t)}feeParams(){return{createFeePercent:{numerator:or,denominator:Pn},claimFeePercent:{numerator:Es,denominator:Pn},flatFeePerStream:rr}}async addMergeCoins(e,t){let n;return t.mergedCoins&&t.mergedCoins.length?(e.mergeCoins(e.object(t.primaryCoin),t.mergedCoins.map(a=>e.object(a))),n=e.object(t.primaryCoin)):t.primaryCoin===_n?n=e.gas:n=e.object(t.primaryCoin),n}getCreateStreamCoinRequests(e,t){let n=e.coinType;return Bn(n,ce.SUI_TYPE_ARG)?[{coinType:n,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:n,amount:t.totalAmount+t.streamFeeAmount},{coinType:ce.SUI_TYPE_ARG,amount:t.flatFeeAmount}]}calculateFeesInternal(e){let t=e.recipients.reduce((a,r)=>{let i=this.amountForRecipient(r,e.numberEpoch),s=this.getStreamFeeLocal(i);return{totalAmount:a.totalAmount+i,streamFeeAmount:a.streamFeeAmount+s}},{totalAmount:0n,streamFeeAmount:0n});return{flatFeeAmount:BigInt(e.recipients.length)*this.flatSuiFee,...t}}amountForRecipient(e,t){return BigInt(e.amountPerEpoch)*BigInt(t)+BigInt(e.cliffAmount)}get flatSuiFee(){return rr}getStreamFeeLocal(e){return e*or/Pn}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new cr.TransactionBlock,e),n=await this.globals.suiClient.devInspectTransactionBlock({sender:await this.globals.walletAddress(),transactionBlock:t});return new Rn(n).getU64()}get wallet(){return this.globals.wallet}};var lr=require("@mysten/sui.js/transactions");var qs="0x0000000000000000000000000000000000000000000000000000000000000006";var _t=class{constructor(e,t,n){this.moduleName=e;this.config=t;this.globals=n}addContractCall(e,t){let n=`${this.config.contractId}::${this.moduleName}::${t.method}`;return e.add(lr.Transactions.MoveCall({target:n,arguments:t.arguments.map(a=>a instanceof oe?a.moveArgs(e):a instanceof V?a.moveArg(e):a instanceof at?a.moveArg():e.pure(a)),typeArguments:t.typeArgs})),e}addTransactionBlock(e,t,n=[],a=[]){e.add(lr.Transactions.MoveCall({target:t,arguments:n.map(r=>r instanceof oe?r.moveArgs(e):r instanceof V?r.moveArg(e):r instanceof at?r.moveArg():e.pure(r)),typeArguments:a}))}makeObject(e){return typeof e=="string"?new V(e):e}vaultObject(){return new V(this.config.vaultObjId)}roleObject(){return new V(this.config.roleObjId)}feeObject(){return new V(this.config.feeObjId)}clockObject(){return new V(qs)}};var Et=class o extends _t{constructor(t,n){super(o.ModuleName,t,n);this.config=t;this.globals=n}static ModuleName="fee_module";static MethodName={set_streaming_fee:"set_streaming_fee",set_claim_fee:"set_claim_fee",set_streaming_flat_fee:"set_streaming_flat_fee",streaming_flat_fee:"streaming_flat_fee",streaming_fee:"streaming_fee",claim_fee:"claim_fee",fee_denominator:"fee_denominator"};setStreamingFee(t,n){let a=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:o.MethodName.set_streaming_fee,arguments:[a,r,n],typeArgs:[]})}setStreamingFlatFee(t,n){let a=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:o.MethodName.set_streaming_flat_fee,arguments:[a,r,n],typeArgs:[]})}setClaimFee(t,n){let a=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:o.MethodName.set_claim_fee,arguments:[a,r,n],typeArgs:[]})}streamingFee(t,n){let a=this.feeObject();return this.addContractCall(t,{method:o.MethodName.streaming_fee,arguments:[a,n],typeArgs:[]})}claimFee(t,n){return this.addContractCall(t,{method:o.MethodName.claim_fee,arguments:[this.feeObject(),n],typeArgs:[]})}feeDenominator(t){return this.addContractCall(t,{method:o.MethodName.fee_denominator,arguments:[this.feeObject()],typeArgs:[]})}};var H=class o extends _t{constructor(t,n){super(o.ModuleName,t,n);this.config=t;this.globals=n}static ModuleName="stream";static MethodName={create_stream:"create_stream",set_auto_claim:"set_auto_claim",cancel_stream:"cancel_stream",claim_stream:"claim_stream",claim_stream_by_proxy:"claim_stream_by_proxy",stream_current_epoch:"stream_current_epoch",now_milli_seconds:"now_milli_seconds"};createStream(t,n){let a=this.feeObject(),r=this.vaultObject(),i=this.makeObject(n.paymentCoin),s=this.makeObject(n.flatFeeCoin),c=this.clockObject();return this.addContractCall(t,{method:o.MethodName.create_stream,arguments:[a,r,i,s,n.metadata,n.recipient,n.timeStart,n.cliff,n.epochInterval,n.numEpoch,n.amountPerEpoch,n.cancelable,c],typeArgs:[n.coinType]})}setAutoClaim(t,n){let a=this.makeObject(n.streamId);return this.addContractCall(t,{method:o.MethodName.set_auto_claim,arguments:[a,n.enabled],typeArgs:[n.coinType]})}cancelStream(t,n){let a=this.makeObject(n.streamId),r=this.clockObject();return this.addContractCall(t,{method:o.MethodName.cancel_stream,arguments:[a,r],typeArgs:[n.coinType]})}claimStream(t,n){let a=this.makeObject(n.streamId),r=this.clockObject();return this.addContractCall(t,{method:o.MethodName.claim_stream,arguments:[a,r],typeArgs:[n.coinType]})}claimStreamByProxy(t,n){let a=this.makeObject(n.streamId),r=this.vaultObject(),i=this.feeObject(),s=this.clockObject();return this.addContractCall(t,{method:o.MethodName.claim_stream_by_proxy,arguments:[a,r,i,s],typeArgs:[n.coinType]})}get createStreamTarget(){return`${this.config.contractId}::${o.ModuleName}::${o.MethodName.create_stream}`}get setAutoClaimTarget(){return`${this.config.contractId}::${o.ModuleName}::${o.MethodName.set_auto_claim}`}get cancelStreamTarget(){return`${this.config.contractId}::${o.ModuleName}::${o.MethodName.cancel_stream}`}get claimStreamTarget(){return`${this.config.contractId}::${o.ModuleName}::${o.MethodName.claim_stream}`}get claimStreamByProxyTarget(){return`${this.config.contractId}::${o.ModuleName}::${o.MethodName.claim_stream_by_proxy}`}};var Mt=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new Et(t,e),this.streamContract=new H(t,e)}feeContract;streamContract;async createStreams(e){let t=wt.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new wt(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,n){let a=new le.TransactionBlock;return this.streamContract.setAutoClaim(a,{streamId:e,enabled:t,coinType:n})}claimStream(e,t){let n=new le.TransactionBlock;return this.streamContract.claimStream(n,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let n=new le.TransactionBlock;return this.streamContract.claimStreamByProxy(n,{streamId:e,coinType:t})}cancelStream(e,t){let n=new le.TransactionBlock;return this.streamContract.cancelStream(n,{streamId:e,coinType:t}),n}};var Wt=require("@mysten/sui.js/utils"),dr=require("luxon");var En=class extends C{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var Md=1e3,Mn=class{constructor(e){this.globals=e;this.coinMetaHelper=new ur(e.suiClient),this.createStreamHelper=new Mt(e).createStreamHelper()}coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new En(e.effects?.status.status,e.effects?.status.error);return e.objectChanges.filter(t=>t.type==="created"&&t.objectType.startsWith(`${this.globals.envConfig.contract.contractId}::stream::Stream`)).map(t=>t.objectId)}calculateCreateStreamFees(e){return this.createStreamHelper.calculateCreateStreamFees(e)}feeParams(){return this.createStreamHelper.feeParams()}calculateStreamAmount(e){if(e.steps===0n)throw new S("Invalid stream steps: 0");let t=e.cliff?e.cliff:{numerator:0n,denominator:100n},n=e.totalAmount*t.numerator/t.denominator,a=(e.totalAmount-n)/e.steps,i={realTotalAmount:a*e.steps+n,cliffAmount:n,amountPerStep:a};return this.validateStreamAmount(i,e.totalAmount),i}calculateTimelineByInterval(e){if(e.steps===0n)throw new S("Invalid stream steps: 0");let t=e.timeStart.plus(e.interval.toMillis()*Number(e.steps)),n={timeStart:e.timeStart,timeEnd:t,interval:e.interval,steps:e.steps};return this.validateTimeline(n),n}calculateTimelineByTotalDuration(e){if(e.steps===0n)throw new S("Invalid stream steps: 0");let t=BigInt(e.total.toMillis())/e.steps,n=e.timeStart.plus(dr.Duration.fromMillis(Number(t*e.steps))),a={timeStart:e.timeStart,timeEnd:n,interval:dr.Duration.fromMillis(Number(t)),steps:e.steps};return this.validateTimeline(a),a}async getBalance(e,t){let n=await this.globals.suiClient.getBalance({owner:e,coinType:t}),a=await this.getCoinMeta(t);return{...n,coinType:(0,Wt.normalizeStructTag)(n.coinType),coinMeta:a}}async getAllBalance(e){let t=await this.globals.suiClient.getAllBalances({owner:e}),n=await Promise.all(t.map(a=>this.getCoinMeta(a.coinType)));return t.map((a,r)=>({...a,coinType:(0,Wt.normalizeStructTag)(a.coinType),coinMeta:n[r]}))}async getCoinMeta(e){return this.coinMetaHelper.getCoinMeta(e)}async simulateTransactionBlock(e){return this.globals.suiClient.devInspectTransactionBlock({transactionBlock:e,sender:await this.globals.wallet.address()})}validateStreamAmount(e,t){if(e.amountPerStep===0n)throw new S("Stream amount too small","totalAmount",t);if(e.cliffAmount>e.realTotalAmount)throw new S("Invalid cliff settings")}validateTimeline(e){if(e.interval.toMillis()<Md)throw new S("Interval shall be at least 1 second","interval",e.interval)}},ur=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}coinMetaReg;async getCoinMeta(e){let t=(0,Wt.normalizeStructTag)(e||Wt.SUI_TYPE_ARG);if(this.coinMetaReg.has(t))return this.coinMetaReg.get(t);let n=await this.queryCoinMeta(t);return n&&this.coinMetaReg.set(t,n),n}async queryCoinMeta(e){return await this.suiClient.getCoinMetadata({coinType:e})||void 0}};var it=require("@mysten/sui.js/utils"),yr=require("luxon");var me=require("@mysten/sui.js/transactions"),pe=require("@mysten/sui.js/utils"),$s=require("luxon");var Wn=class extends C{constructor(){super(7,"Connected wallet is not creator")}};var de=class extends C{constructor(){super(8,"Connected wallet is not recipient")}};var ue=class extends C{constructor(e,t){super(6,e,{context:t})}};var k=class extends C{constructor(e,t={}){super(0,e,t)}};var Nn=class extends C{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var jn=require("luxon"),Ks=(1n<<64n)-1n,Ln=1e3;function mr(o){let e;typeof o=="number"?e=o:typeof o=="bigint"?e=Number(o):e=o.toMillis();let t=Math.round(e/Ln);return jn.DateTime.fromMillis(t*Ln)}function pr(o){let e;typeof o=="number"?e=o:typeof o=="bigint"?e=Number(o):e=o.toMillis();let t=Math.round(e/Ln);return jn.Duration.fromMillis(t*Ln)}var rt=class o{constructor(e,t,n){this.globals=e;this.streamId=t;this.rawData=n;this.streamContract=new H(e.envConfig.contract,e)}streamContract;type="Stream";static async new(e,t){let n=await o.fetchStreamData(e,t);return new o(e,t,n)}static fromObjectData(e,t,n){let a=o.parseRawStreamData(t,n);return new o(e,t,a)}get info(){return{name:this.name,creator:this.creator,coinType:this.coinType,totalAmount:this.totalAmount,start:this.timeStart,end:this.timeEnd,cancelable:this.cancelable,cliffAmount:this.cliff,duration:this.duration,interval:this.interval,steps:this.totalSteps,nextReleaseDate:this.nextReleaseDate,nextReleaseAmount:this.nextReleaseAmount,groupId:this.groupId,streamId:this.streamId,recipient:this.recipient,progress:this.progress,autoClaim:this.autoClaim}}get groupCommonInfo(){return{name:this.name,groupId:this.groupId,creator:this.creator,start:this.timeStart,interval:this.interval,steps:this.totalSteps,cancelable:this.cancelable}}async refresh(){this.rawData=await o.fetchStreamData(this.globals,this.streamId)}refreshWithData(e){if(e.data?.objectId!==this.streamId)throw new k("Object Id does not align");this.rawData=o.parseRawStreamData(this.streamId,e)}async historyEvents(e){return this.globals.backend.getStreamHistory({streamId:this.streamId,pagination:e})}async cancel(){if(await this.globals.walletAddress()!==this.creator)throw new Wn;let e=new me.TransactionBlock;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new de;let e=new me.TransactionBlock;return this.streamContract.claimStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async setAutoClaim(e){if(await this.globals.walletAddress()!==this.recipient)throw new de;let t=new me.TransactionBlock;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new me.TransactionBlock;return this.streamContract.claimStreamByProxy(e,{streamId:this.streamId,coinType:this.coinType}),e}get wallet(){return this.globals.wallet}get client(){return this.globals.suiClient}get coinType(){return(0,pe.normalizeStructTag)(this.rawData.coinType)}get progress(){return{status:this.streamStatus,total:this.totalAmount,streamed:this.streamedAmount,claimed:this.claimedAmount,claimable:this.claimable,canceled:this.canceledAmount}}get balance(){return this.rawData.balance}get autoClaim(){return this.rawData.autoClaim}get amountPerEpoch(){return this.rawData.config.amountPerEpoch}get cancelable(){return this.rawData.config.cancelable}get cliff(){return this.rawData.config.cliff}get creator(){return this.rawData.config.creator}get interval(){return pr(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return ie(e).groupId}get name(){let{metadata:e}=this.rawData.config;return ie(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return mr(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return pr(t)}get timeEnd(){return this.timeStart.plus(this.duration)}get totalSteps(){return this.rawData.config.totalEpoch}get claimable(){return this.streamedAmount-this.claimedAmount}get nextReleaseDate(){return this.currentEpoch===-1n?this.timeStart:this.currentEpoch>=this.totalSteps||this.isCanceled?null:mr((this.currentEpoch+1n)*this.rawData.config.epochInterval+this.rawData.config.timeStart)}get nextReleaseAmount(){return this.currentEpoch===-1n?this.cliff:this.currentEpoch>=this.totalSteps||this.isCanceled?null:this.amountPerEpoch}get streamStatus(){let e=this.rawData.status.status;return e===16?"CANCELED":e===17?"SETTLED":e===1?"COMPLETED":this.currentEpoch>=this.totalSteps?"STREAMED":"STREAMING"}get streamedAmount(){return this.currentEpoch===-1n?0n:this.isCanceled?this.rawData.status.epochCanceled*this.amountPerEpoch+this.cliff:this.currentEpoch*this.amountPerEpoch+this.cliff}get claimedAmount(){return this.rawData.status.epochClaimed===Ks?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=$s.DateTime.now().toMillis(),t=this.timeStart.toMillis();if(e<t)return-1n;let n=Math.floor((e-t)/Number(this.rawData.config.epochInterval));return BigInt(n)>Number(this.rawData.config.totalEpoch)?this.rawData.config.totalEpoch:BigInt(n)}get totalAmount(){let e=this.rawData.config;return e.amountPerEpoch*e.totalEpoch+e.cliff}get isCanceled(){let e=this.rawData.status.status;return e===16||e===17}get canceledAmount(){return this.isCanceled?this.totalAmount-this.streamedAmount:0n}static async fetchStreamData(e,t){let n=await e.suiClient.getObject({id:t,options:{showContent:!0,showType:!0}});return o.parseRawStreamData(t,n)}static parseRawStreamData(e,t){if(t.error)throw t.error.code==="notExists"?new Nn(e):new ue(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let n=t.data.content;if(n.dataType!=="moveObject")throw new ue("Unexpected object type",{gotType:n.dataType});let{typeParams:a}=(0,pe.parseStructTag)(n.type),r=(0,pe.normalizeStructTag)(a[0]),i=n.fields,s=i.config.fields,c=i.status.fields;return{coinType:r,autoClaim:i.auto_claim,balance:BigInt(i.balance.fields.balance),config:{amountPerEpoch:BigInt(s.amount_per_epoch),cancelable:s.cancelable,cliff:BigInt(s.cliff),creator:s.creator,epochInterval:BigInt(s.epoch_interval),metadata:s.metadata,recipient:s.recipient,timeStart:BigInt(s.time_start),totalEpoch:BigInt(s.total_epoch)},status:{status:c.status,epochCanceled:BigInt(c.epoch_canceled),epochClaimed:BigInt(c.epoch_claimed)}}}};var Nt=class extends C{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};async function br(o){let e=[];for(;await o.hasNext();){let t=await o.next();e.push(t)}return e&&Array.isArray(e[0])?e.flat(1):e}var fr=class{constructor(e){this.requester=e;this.curPage=void 0,this.init=!0}curPage;init;async hasNext(){if(this.init)return this.curPage||(this.curPage=await this.requester.doNextRequest()),!!this.curPage.data?.length||this.curPage.hasNext;if(!this.curPage)throw new Error("invalid implementation of iterator");return this.curPage.hasNext}async next(){return this.init?(this.init=!1,this.curPage||(this.curPage=await this.requester.doNextRequest()),this.curPage.data):(this.curPage=await this.requester.doNextRequest(),this.curPage.data)}},Lt=class{constructor(e){this.requester=e;this.pager=new fr(e),this.curData=[],this.cursor=0}cursor;pager;curData;async hasNext(){return this.cursor<this.curData.length-1?!0:this.pager.hasNext()}async next(){for(this.cursor+=1;this.cursor>=this.curData.length;)if(await this.pager.hasNext())this.curData=await this.pager.next(),this.cursor=0;else throw new Error("not more data");return this.curData[this.cursor]}};var Wd=25;async function gr(o,e,t){let n=new fe(e),a=new be(o,n,t);return await br(a)}var fe=class{constructor(e){this.ids=e;this.cursor=-1}cursor;async hasNext(){return this.cursor<this.ids.length-1}async next(){if(this.cursor+=1,this.cursor>=this.ids.length)throw new Error("invalid iterator implementation");return this.ids[this.cursor]}},be=class extends Lt{constructor(t,n,a){super(new hr(t,n,a));this.suiClient=t;this.idIter=n;this.options=a}},hr=class{constructor(e,t,n){this.suiClient=e;this.stringIter=t;this.options=n;this.filter=n?.filter,this.pageSize=n?.pageSize||Wd,this.objectOptions=n?.objectOptions||{showType:!0,showContent:!0}}filter;pageSize;objectOptions;async doNextRequest(){let e=[];for(;e.length<this.pageSize&&await this.stringIter.hasNext();){let r=await this.stringIter.next();r&&e.push(r)}let t=await this.suiClient.multiGetObjects({ids:e,options:this.objectOptions}),n;if(this.filter){let{filter:a}=this;n=t.filter(r=>a?.(r))}else n=t;return{data:n,hasNext:await this.stringIter.hasNext()}}};var Un=class o{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new Nt("stream size 0");let n=t.map(r=>r.groupId);if(new Set(n).size!==1)throw new S("Stream does not have same group ID")}type="StreamGroup";static async new(e,t){let n=await gr(e.suiClient,t);return n.forEach(a=>{if(!a)throw new k("stream group object data undefined")}),o.newFromObjectResponse(e,t,n)}static async newFromObjectResponse(e,t,n){let a=await o.parseGroupStreams(e,t,n);return new o(e,a)}static checkStreamGroup(e){let t=e.map(r=>r.groupCommonInfo),n=t[0],a=!0;return t.forEach(r=>{Nd(n,r)||(a=!1)}),a}async refresh(){let e=await gr(this.globals.suiClient,this.streams.map(t=>t.streamId));this.streams.forEach((t,n)=>{t.refreshWithData(e[n])})}get groupId(){return this.streams[0].groupId}get creator(){return this.streams[0].creator}get info(){return{groupId:this.groupId,streamIds:this.streams.map(e=>e.streamId),progress:this.progress,name:this.streams[0].name,creator:this.creator,coinType:this.streams[0].coinType,totalAmount:this.streams.reduce((e,t)=>e+t.totalAmount,0n),start:this.streams[0].timeStart,end:this.streams[0].timeEnd,cancelable:this.streams[0].cancelable,cliffAmount:this.streams.reduce((e,t)=>e+t.cliff,0n),duration:this.streams[0].duration,interval:this.streams[0].interval,steps:this.streams[0].totalSteps,nextReleaseAmount:this.streams.reduce((e,t)=>t.nextReleaseAmount===null?e:e+t.nextReleaseAmount,0n),nextReleaseDate:this.streams[0].nextReleaseDate}}get progress(){return{total:this.streams.reduce((e,t)=>e+t.totalAmount,0n),streamed:this.streams.reduce((e,t)=>e+t.streamedAmount,0n),claimed:this.streams.reduce((e,t)=>e+t.claimedAmount,0n),claimable:this.streams.reduce((e,t)=>e+t.claimable,0n),canceled:this.streams.reduce((e,t)=>e+t.canceledAmount,0n)}}async historyEvents(e){return this.globals.backend.getStreamHistory({groupId:this.groupId,pagination:e})}static async parseGroupStreams(e,t,n){let a=n.map((r,i)=>rt.fromObjectData(e,t[i],r)).filter(r=>!!r);if(new Set(a.map(r=>r.groupId)).size!==1)throw new Nt("Not same group ID");if(!this.checkStreamGroup(a))throw new Nt("Not same stream settings");return a}};function Nd(o,e){return o.name===e.name&&o.groupId===e.groupId&&o.creator===e.creator&&o.start.toMillis()===e.start.toMillis()&&o.interval.toMillis()===e.interval.toMillis()&&o.steps===e.steps&&o.cancelable===e.cancelable}var he=class o{constructor(e,t){this.it=e;this.pageSize=t}static async newIncoming(e){let t=await Fn.newIncoming(e);return new o(t,e.pageSize)}static async newOutgoing(e){let t=await Fn.newOutgoing(e);return new o(t,e.pageSize)}async hasNext(){return this.it.hasNext()}async next(){let e=[];for(;e.length<this.pageSize&&await this.it.hasNext();)e.push(await this.it.next());return e}},Fn=class o{constructor(e){this.requester=e}cachedNext;static async newIncoming(e){let t=await qn.newIncomingQuery(e);return new o(t)}static async newOutgoing(e){let t=await qn.newOutgoingQuery(e);return new o(t)}async hasNext(){return this.cachedNext===void 0&&(this.cachedNext=await this.requester.doNextRequest()),this.cachedNext!==null}async next(){if(this.cachedNext===void 0){let t=await this.requester.doNextRequest();if(t===null)throw new k("No more results");return t}let e=this.cachedNext;if(this.cachedNext=void 0,e===null)throw new k("No more results");return e}},qn=class o{constructor(e,t,n,a){this.globals=e;this.recipient=t;this.groupRefs=n;this.query=a;this.current=0;let r=new fe(n.flat().map(i=>i.streamId));this.objectIter=new be(e.suiClient,r)}current=0;objectIter;static async newIncomingQuery(e){let t=qd(e.query),n=await e.globals.walletAddress(),r=(await e.globals.backend.getIncomingStreams(n,t)).filter(s=>(0,it.normalizeSuiAddress)(s.recipient)===(0,it.normalizeSuiAddress)(n)),i=Vs(r);return new o(e.globals,n,i,e.query)}static async newOutgoingQuery(e){let t=Kd(e.query),n=await e.globals.walletAddress(),a=await e.globals.backend.getOutgoingStreams(n,t),r=Vs(a);return new o(e.globals,n,r,e.query)}async doNextRequest(){if(this.current>=this.groupRefs.length)return null;let e=this.groupRefs[this.current];if(e.length===1){let t=await Ud(this.globals,e[0].streamId,this.objectIter);return this.current++,Hs(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await Fd(this.globals,e.map(n=>n.streamId),this.objectIter);return this.current++,jd(t,this.query)?t:this.doNextRequest()}throw new k("Stream group with no stream")}};function Vs(o){let e=new Map;return o.forEach(t=>{let n=e.get(t.groupId);n?(n.push(t),e.set(t.groupId,n)):e.set(t.groupId,[t])}),Array.from(e.values()).sort((t,n)=>yr.DateTime.fromISO(n[0].createDate).toMillis()-yr.DateTime.fromISO(t[0].createDate).toMillis())}function Hs(o,e){if(e===void 0)return!0;let t=Ld(o,e.status);if(e&&"claimable"in e&&e.claimable!==void 0){let n=e.claimable?o.progress.claimable!==0n:o.progress.claimable===0n;return t&&n}return t}function Ld(o,e){return e===void 0?!0:Array.isArray(e)?e.includes(o.progress.status):o.progress.status===e}function jd(o,e){if(!e)return!0;let t=!1;return o.streams.forEach(n=>{Hs(n,e)&&(t=!0)}),t}async function Ud(o,e,t){let n=await Gs(t,e);return rt.fromObjectData(o,e,n)}async function Fd(o,e,t){let n=[];for(;n.length<e.length;){let a=await Gs(t,e[n.length]);n.push(a)}return Un.newFromObjectResponse(o,e,n)}async function Gs(o,e){if(!await o.hasNext())throw new k("object iterator has been consumed");let t=await o.next();if(!t||t.error||t.data===void 0||t.data===null)throw new k("object iterator undefined response",{cause:t?.error});if(t?.data?.objectId!==e)throw new k("stream id not aligned");return t}function qd(o){return{status:Tr(o?.status),coinType:Qs(o?.coinType),sender:zs(o?.sender)}}function Kd(o){return{status:Tr(o?.status),coinType:Qs(o?.coinType),recipient:zs(o?.recipient)}}function Tr(o){return o===void 0||o.length===0?"all":Array.isArray(o)?o.reduce((e,t)=>{let n=Tr(t);return!e||e===n?n:"all"},void 0):$d(o)}function $d(o){switch(o){case"STREAMING":case"STREAMED":case"CANCELED":return"active";case"COMPLETED":case"SETTLED":return"inactive";default:throw new S("Unknown stream filtered status")}}function Qs(o){if(o)return Array.isArray(o)?o.length!==0?o.map(e=>(0,it.normalizeStructTag)(e)):void 0:(0,it.normalizeStructTag)(o)}function zs(o){if(o)return Array.isArray(o)?o.length!==0?o.map(e=>(0,it.normalizeSuiAddress)(e)):void 0:(0,it.normalizeSuiAddress)(o)}var Kn=class extends C{constructor(t,n,a){super(4,`Not enough balance: ${t}`,{context:{coinType:t,requestAmount:n,gotAmount:a}});this.coinType=t;this.requestAmount=n;this.gotAmount=a}};var Vd=25;async function Js(o,e,t,n="0x2::sui::SUI",a=Vd){let r=new Cr(o,e,n,a),i=BigInt(0),s=[];for(;await r.hasNext()&&i<t;){let c=await r.next();c&&(s.push(c),i+=BigInt(c.balance))}if(i<t)throw new Kn(n,t,i);return s}var Cr=class extends Lt{constructor(t,n,a,r){super(new Ir(t,n,a,r));this.suiClient=t;this.owner=n;this.coinType=a;this.reqPageSize=r}},Ir=class{constructor(e,t,n,a){this.suiClient=e;this.owner=t;this.coinType=n;this.reqPageSize=a;if(a<=0)throw new k("Invalid reqPageSize")}nextCursor;async doNextRequest(){let e=await this.suiClient.getCoins({owner:this.owner,coinType:this.coinType,cursor:this.nextCursor,limit:this.reqPageSize});return this.nextCursor=e.nextCursor,{data:e.data,hasNext:e.hasNextPage}}};var Sr=class{constructor(e){this.msafe=e}get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},$n=class{constructor(e){this.account=e}async address(){return this.account.address}},wr=class{constructor(e,t){this.singleWallet=e;this.suiClient=t}get type(){return"single"}async address(){return this.singleWallet.address()}async requestCoins(e){return Promise.all(e.map(t=>this.requestCoin(t)))}async requestCoin(e){if(Bn(e.coinType,kt.SUI_TYPE_ARG))return{primaryCoin:_n};if(e.amount<=0)throw new S("Invalid coin request","coinAmount",e.amount);let t=await Js(this.suiClient,await this.address(),e.amount,e.coinType);if(t.length===0)throw new k("no coins available");return{primaryCoin:t[0].coinObjectId,mergedCoins:t.slice(1).map(n=>n.coinObjectId)}}},Vn=class{globals;helper;constructor(e,t){this.globals=Bt.new(e,t),this.helper=new Mn(this.globals)}connectSingleWallet(e){let t=new wr(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new Sr(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return rt.new(this.globals,e)}async getIncomingStreams(e,t=10){return he.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return he.newOutgoing({globals:this.globals,query:e,pageSize:t})}async getCoinTypesForStreamFilter(){let e=await this.wallet.address();return(await this.globals.backend.getAllCoinTypes(e)).map(n=>(0,kt.normalizeStructTag)(n))}async getRecipientsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllRecipients(t,e)).map(a=>(0,kt.normalizeSuiAddress)(a))}async getCreatorsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllSenders(t,e)).map(a=>(0,kt.normalizeSuiAddress)(a))}get wallet(){return this.globals.wallet}builder(){return new Mt(this.globals)}};var M=class extends h{application="mpay";getClient(e,t){let n=new Vn(e==="sui:mainnet"?"prod":"dev");return n.connectSingleWallet(new $n(t)),n}};var ge=class extends M{constructor(t){super(t);this.data=t}txType=Ys.TransactionType.Stream;txSubType="Cancel";async build(t){let{network:n,account:a}=t;return(await this.getClient(n,a).getStream(this.data.streamId)).cancel()}};var Xs=require("@msafe/sui3-utils");var ye=class extends M{constructor(t){super(t);this.data=t}txType=Xs.TransactionType.Stream;txSubType="ClaimByProxy";async build(t){let{network:n,account:a}=t;return(await this.getClient(n,a).getStream(this.data.streamId)).claimByProxy()}};var Zs=require("@msafe/sui3-utils");var Te=class extends M{constructor(t){super(t);this.data=t}txType=Zs.TransactionType.Stream;txSubType="Claim";async build(t){let{network:n,account:a}=t;return(await this.getClient(n,a).getStream(this.data.streamId)).claim()}};var tc=require("@msafe/sui3-utils");var Ce=class extends M{constructor(t){super(t);this.data=t}txType=tc.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:n,account:a}=t;return this.getClient(n,a).createStream(this.data)}};var kr=require("@mysten/sui.js/bcs"),st=require("@mysten/sui.js/utils"),jt=class o{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return o.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return o.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return BigInt(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,st.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return o.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return kr.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,st.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,st.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,st.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,st.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return kr.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,st.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Hn=class{constructor(e,t){this.globals=e;this.txb=t}decode(){let e=this.decodeCreateStreamInfo(),t=this.createStreamHelper().calculateCreateStreamFees(e);return{type:"CreateStream",info:e,fees:t}}decodeCreateStreamInfo(){let t=this.createStreamTransactions().map(n=>this.getCreationInfoFromMoveCall(n));return this.aggregateGroupStreamInfo(t)}createStreamTransactions(){let e=this.transactions.filter(t=>t.kind==="MoveCall"&&ot(t.target,this.contract.createStreamTarget));if(e.length===0)throw new k("No create stream transactions");return e.map(t=>new jt(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:n,groupId:a}=ie(t),r=e.decodeInputAddress(5),i=e.decodeInputU64(6),s=e.decodeInputU64(7),c=e.decodeInputU64(8),l=e.decodeInputU64(9),d=e.decodeInputU64(10),m=e.decodeInputBool(11),p=e.typeArg(0);return{name:n,groupId:a,recipient:r,timeStart:i,cliff:s,epochInterval:c,totalEpoch:l,amountPerEpoch:d,cancelable:m,coinType:p}}aggregateGroupStreamInfo(e){if(new Set(e.map(a=>JSON.stringify({name:a.name,groupId:a.groupId,timeStart:String(a.timeStart),epochInterval:String(a.epochInterval),totalEpoch:String(a.totalEpoch),cancelable:a.cancelable,coinType:a.coinType}))).size!==1)throw new S("Stream group not have common info");let n=e.map(a=>({address:a.recipient,amountPerStep:a.amountPerEpoch,cliffAmount:a.cliff}));return{name:e[0].name,coinType:e[0].coinType,recipients:n,interval:e[0].epochInterval,steps:e[0].totalEpoch,startTimeMs:e[0].timeStart,cancelable:e[0].cancelable}}mergeCoinTransactions(){return this.transactions.filter(e=>e.kind==="MergeCoins")}get transactions(){return this.txb.blockData.transactions}get contract(){return new H(this.globals.envConfig.contract,this.globals)}get feeContract(){return new Et(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new wt(this.globals,this.feeContract,this.contract)}getInputArg(e){if(e.kind!=="Input")throw new Error("not input type");return"value"in e?e:this.txb.blockData.inputs[e.index]}};var Gn=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new H(e.envConfig.contract,e)}contract;decode(){if(this.isCreateStreamTransaction())return this.decodeCreateStreamTransaction();if(this.isClaimByProxyTransaction())return this.decodeClaimByProxyTransaction();if(this.isSetAutoClaimTransaction())return this.decodeSetAutoClaimTransaction();if(this.isCancelStreamTransaction())return this.decodeCancelStreamTransaction();if(this.isClaimStreamTransaction())return this.decodeClaimTransaction();throw new Error("Unknown stream transaction type")}get transactions(){return this.txb.blockData.transactions}isCreateStreamTransaction(){return this.transactions.findIndex(t=>t.kind==="MoveCall"&&ot(t.target,this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ot(this.transactions[0].target,this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ot(this.transactions[0].target,this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ot(this.transactions[0].target,this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ot(this.transactions[0].target,this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new Hn(this.globals,this.txb).decode()}decodeSetAutoClaimTransaction(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeInputBool(1);return{type:"SetAutoClaim",streamId:e,enabled:t}}decodeClaimTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"Claim",streamId:e}}decodeClaimByProxyTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"ClaimByProxy",streamId:e}}decodeCancelStreamTransaction(){let e=this.helper.decodeSharedObjectId(0);return{type:"Cancel",streamId:e}}get helper(){let e=this.transactions[0];return new jt(e,this.txb)}};var ec=require("@msafe/sui3-utils");var Ie=class extends M{constructor(t){super(t);this.data=t}txType=ec.TransactionType.Stream;txSubType="SetAutoClaim";async build(t){let{network:n,account:a}=t;return(await this.getClient(n,a).getStream(this.data.streamId)).setAutoClaim(this.data.enabled)}};var Qn=class{application="mpay";supportSDK="@mysten/sui.js";async deserialize(e){let{network:t,transactionBlock:n}=e,a=Bt.new(t==="sui:mainnet"?"prod":"dev"),i=new Gn(a,n).decode(),s;switch(i.type){case"CreateStream":s=new Ce(i.info);break;case"SetAutoClaim":s=new Ie({streamId:i.streamId,enabled:i.enabled});break;case"Claim":s=new Te({streamId:i.streamId});break;case"ClaimByProxy":s=new ye({streamId:i.streamId});break;case"Cancel":s=new ge({streamId:i.streamId});break;default:throw new Error(`Unknown transaction type: ${i}`)}return{txType:s.txType,txSubType:s.txSubType,intentionData:s.data}}async build(e){let{intentionData:t}=e,n;switch(e.txSubType){case"CreateStream":n=new Ce(t);break;case"Claim":n=new Te(t);break;case"ClaimByProxy":n=new ye(t);break;case"SetAutoClaim":n=new Ie(t);break;case"Cancel":n=new ge(t);break;default:throw new Error("not implemented")}return n.build({...e})}};var Se=require("@msafe/sui3-utils");var nc=require("@msafe/sui3-utils");var zn=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a}=t;return(0,nc.buildCoinTransferTxb)(n,this.data,a.address)}static fromData(t){return new o(t)}};var ac=require("@msafe/sui3-utils");var Jn=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a}=t;return(0,ac.buildObjectTransferTxb)(n,this.data,a.address)}static fromData(t){return new o(t)}};var Yn=class{application="msafe-core";supportSDK="@mysten/sui.js";constructor(){this.application=Se.TransactionDefaultApplication}deserialize(){throw new Error("MSafe core transaction intention should be build from API")}async build(e){let{suiClient:t,account:n}=e,a;switch(e.txSubType){case Se.TransactionSubTypes.assets.coin.send:a=zn.fromData(e.intentionData);break;case Se.TransactionSubTypes.assets.object.send:a=Jn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n})}};var bc=require("@msafe/sui3-utils");var oc=!1,we={ProtocolPackage:"0x81c408448d0d57b3e371ea94de1d40bf852784d3e225de1e74acab3e8395c18f",StorageId:"0xbb4e2f4b6205c2e2a2db47aeb4f830796ec7c005f88537ee775986639bc442fe",Incentive:"0xaaf735bf83ff564e1b219a0d644de894ef5bdc4b2250b126b2a46dd002331821",IncentiveV2:"0xf87a8acb8b81d14307894d12595541a73f19933f88e1326d5be349c7a6f7559c",gasBudget:5e7,PriceOracle:"0x1568865ed9a0b5ec414220e8f79b3d04c77acc82358f6e5ae4635687392ffbef",ReserveParentId:"0xe6d4c6610b86ce7735ea754596d71d72d10c7980b5052fc3c8cdf8d09fea9b4b",pool:{sui:{name:"SUI",assetId:0,poolId:"0x96df0fce3c471489f4debaaa762cf960b3d97820bd1f3f025ff8190730e958c5",fondPoolId:"0xf975bc2d4cca10e3ace8887e20afd77b46c383b4465eac694c4688344955dea4",type:"0x2::sui::SUI",coinType:"sui",reserveObjectId:"0xab644b5fd11aa11e930d1c7bc903ef609a9feaf9ffe1b23532ad8441854fbfaf",borrowBalanceParentId:"0xe7ff0daa9d090727210abe6a8b6c0c5cd483f3692a10610386e4dc9c57871ba7",supplyBalanceParentId:"0x589c83af4b035a3bc64c40d9011397b539b97ea47edf7be8f33d643606bf96f8"},wusdc:{name:"wUSDC",assetId:1,coinType:"wusdc",poolId:"0xa02a98f9c88db51c6f5efaaf2261c81f34dd56d86073387e0ef1805ca22e39c8",type:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf::coin::COIN",reserveObjectId:"0xeb3903f7748ace73429bd52a70fff278aac1725d3b58afa781f25ce3450ac203",borrowBalanceParentId:"0x8a3aaa817a811131c624658f6e77cba04ab5829293d2c49c1a9cce8ac9c8dec4",supplyBalanceParentId:"0x8d0a4467806458052d577c8cd2be6031e972f2b8f5f77fce98aa12cd85330da9"},usdt:{name:"USDT",coinType:"usdt",assetId:2,poolId:"0x0e060c3b5b8de00fb50511b7a45188c8e34b6995c01f69d98ea5a466fe10d103",type:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",reserveObjectId:"0xb8c5eab02a0202f638958cc79a69a2d30055565caad1684b3c8bbca3bddcb322",borrowBalanceParentId:"0xc14d8292a7d69ae31164bafab7ca8a5bfda11f998540fe976a674ed0673e448f",supplyBalanceParentId:"0x7e2a49ff9d2edd875f82b76a9b21e2a5a098e7130abfd510a203b6ea08ab9257"},weth:{name:"WETH",coinType:"weth",assetId:3,poolId:"0x71b9f6e822c48ce827bceadce82201d6a7559f7b0350ed1daa1dc2ba3ac41b56",type:"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN",reserveObjectId:"0xafecf4b57899d377cc8c9de75854c68925d9f512d0c47150ca52a0d3a442b735",borrowBalanceParentId:"0x7568d06a1b6ffc416a36c82791e3daf0e621cf19d4a2724fc6f74842661b6323",supplyBalanceParentId:"0xa668905b1ad445a3159b4d29b1181c4a62d864861b463dd9106cc0d97ffe8f7f"},cetus:{name:"CETUS",coinType:"cetus",assetId:4,poolId:"0x3c376f857ec4247b8ee456c1db19e9c74e0154d4876915e54221b5052d5b1e2e",type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS",reserveObjectId:"0x66a807c06212537fe46aa6719a00e4fa1e85a932d0b53ce7c4b1041983645133",borrowBalanceParentId:"0x4c3da45ffff6432b4592a39cdb3ce12f4a28034cbcb804bb071facc81fdd923d",supplyBalanceParentId:"0x6adc72faf2a9a15a583c9fb04f457c6a5f0b456bc9b4832413a131dfd4faddae"},voloSui:{name:"VoloSui",coinType:"voloSui",assetId:5,poolId:"0x9790c2c272e15b6bf9b341eb531ef16bcc8ed2b20dfda25d060bf47f5dd88d01",fondPoolId:"0xe2b5ada45273676e0da8ae10f8fe079a7cec3d0f59187d3d20b1549c275b07ea",type:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",reserveObjectId:"0xd4fd7e094af9819b06ea3136c13a6ae8da184016b78cf19773ac26d2095793e2",borrowBalanceParentId:"0x8fa5eccbca2c4ba9aae3b87fd44aa75aa5f5b41ea2d9be4d5321379384974984",supplyBalanceParentId:"0xe6457d247b6661b1cac123351998f88f3e724ff6e9ea542127b5dcb3176b3841"},haSui:{name:"HaedalSui",coinType:"haSui",assetId:6,poolId:"0x6fd9cb6ebd76bc80340a9443d72ea0ae282ee20e2fd7544f6ffcd2c070d9557a",fondPoolId:"0xa20e18085ce04be8aa722fbe85423f1ad6b1ae3b1be81ffac00a30f1d6d6ab51",type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI",reserveObjectId:"0x0c9f7a6ca561dc566bd75744bcc71a6af1dc3caf7bd32c099cd640bb5f3bb0e3",borrowBalanceParentId:"0x01f36898e020be6c3423e5c95d9f348868813cd4d0be39b0c8df9d8de4722b00",supplyBalanceParentId:"0x278b8e3d09c3548c60c51ed2f8eed281876ea58c392f71b7ff650cc9286d095b"},navx:{name:"NAVX",coinType:"navx",assetId:7,poolId:"0xc0e02e7a245e855dd365422faf76f87d9f5b2148a26d48dda6e8253c3fe9fa60",fondPoolId:"0x9dae0cf104a193217904f88a48ce2cf0221e8cd9073878edd05101d6b771fa09",type:"0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX",reserveObjectId:"0x2e13b2f1f714c0c5fa72264f147ef7632b48ec2501f810c07df3ccb59d6fdc81",borrowBalanceParentId:"0xa5bf13075aa400cbdd4690a617c5f008e1fae0511dcd4f7121f09817df6c8d8b",supplyBalanceParentId:"0x59dedca8dc44e8df50b190f8b5fe673098c1273ac6168c0a4addf3613afcdee5"},wbtc:{name:"WBTC",coinType:"wbtc",assetId:8,poolId:"0xd162cbe40f8829ce71c9b3d3bf3a83859689a79fa220b23d70dc0300b777ae6e",type:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN",reserveObjectId:"0x8b4d81f004e4e9faf4540951a896b6d96e42598a270e6375f598b99742db767e",borrowBalanceParentId:"0x55e1f3c9e6e5cf9fff563bdd61db07a3826458c56ef72c455e049ab3b1b0e99c",supplyBalanceParentId:"0x821e505a0091b089edba94deaa14c2f2230d026bbaa7b85680554441aad447e0"},ausd:{name:"AUSD",coinType:"ausd",assetId:9,poolId:"0xc9208c1e75f990b2c814fa3a45f1bf0e85bb78404cfdb2ae6bb97de58bb30932",type:"0x2053d08c1e2bd02791056171aab0fd12bd7cd7efad2ab8f6b9c8902f14df2ff2::ausd::AUSD",reserveObjectId:"0x918889c6a9d9b93108531d4d59a4ebb9cc4d41689798ffc1d4aed6e1ae816ec0",borrowBalanceParentId:"0x551300b9441c9a3a16ca1d7972c1dbb4715e15004ccd5f001b2c2eee22fd92c1",supplyBalanceParentId:"0xe151af690355de8be1c0281fbd0d483c099ea51920a57c4bf8c9666fd36808fd"},nusdc:{name:"USDC",assetId:10,coinType:"nusdc",poolId:"0xa3582097b4c57630046c0c49a88bfc6b202a3ec0a9db5597c31765f7563755a8",type:"0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",reserveObjectId:"0x4c8a2c72a22ae8da803a8519798d312c86e74a9e0d6ec0eec2bfcf7e4b3fef5e",borrowBalanceParentId:"0xb0b0c7470e96cabbb4f1e8d06bef2fbea65f4dbac52afae8635d9286b1ea9a09",supplyBalanceParentId:"0x08b5ce8574ac3bc9327e66ad5decd34d07ee798f724ad01058e8855ac9acb605"},eth:{name:"ETH",assetId:11,coinType:"eth",poolId:"0x78ba01c21d8301be15690d3c30dc9f111871e38cfb0b2dd4b70cc6052fba41bb",type:"0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH",reserveObjectId:"0x376faea6dfbffab9ea808474cb751d91222b6d664f38c0f1d23de442a8edb1ce",borrowBalanceParentId:"0xf0c6ce5cfaee96073876a5fab7426043f3a798b79502c4caeb6d9772cd35af1f",supplyBalanceParentId:"0xc0a0cb43620eb8a84d5a4a50a85650e7fa7ba81e660f9cc2863404fd84591d4b"},usdy:{name:"USDY",assetId:12,coinType:"usdy",poolId:"0x4b6253a9f8cf7f5d31e6d04aed4046b9e325a1681d34e0eff11a8441525d4563",type:"0x960b531667636f39e85867775f52f6b1f220a058c4de786905bdf761e06a56bb::usdy::USDY",reserveObjectId:"",borrowBalanceParentId:"",supplyBalanceParentId:""}},borrowFee:.003,borrowFeeAddress:"0x70b9b10704263cf53392849e33b1f5fd16005869b4198ed5524836bad1234ea2"};async function xr(){if(!oc)try{let o=await fetch("https://open-api.naviprotocol.io/api/msafe").then(r=>r.json()),{packageId:e,borrowFee:t,borrowFeeAddress:n,pool:a}=o;e&&(we.ProtocolPackage=e),t&&(we.borrowFee=t),n&&(we.borrowFeeAddress=n),a&&(we.pool=a),oc=!0}catch(o){console.error(o.message)}}var j=we;var ct=require("@msafe/sui3-utils"),Dr=require("@mysten/sui.js/bcs"),lt=require("@mysten/sui.js/utils");var Xn=class{constructor(e){this.txb=e}decode(){if(console.log("txb",this.txb),this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isEntryBorrowTransaction())return this.decodeEntryBorrow();if(this.isEntryBorrowWithFeeTransaction())return this.decodeEntryBorrow();if(this.isEntryMultiDepositTransaction())return this.decodeEntryMultiDeposit();if(this.isEntryDepositTransaction())return this.decodeEntryDeposit();if(this.isEntryRepayTransaction())return this.decodeEntryRepay();if(this.isEntryWithdrawTransaction())return this.decodeEntryWithdraw();if(this.isEntryClaimAndDepositTransaction())return this.decodeEntryClaimAndDeposit();throw new Error("Unknown transaction type")}get transactions(){return this.txb.blockData.transactions}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isClaimRewardTransaction(){return!!this.transactions.find(t=>!!(t.kind==="MoveCall"&&t.target.includes("claim_reward")))}isEntryBorrowTransaction(){return!!this.getMoveCallTransaction(`${j.ProtocolPackage}::incentive_v3::entry_borrow`)}isEntryBorrowWithFeeTransaction(){return!!this.getMoveCallTransaction(`${j.ProtocolPackage}::incentive_v3::borrow`)}isEntryMultiDepositTransaction(){let e=`${j.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.transactions.filter(a=>a.kind==="MoveCall"&&a.target===e);return this.transactions.find(a=>a.kind==="MoveCall"&&a.target.includes("claim_reward"))?!1:t.length>1}isEntryClaimAndDepositTransaction(){let e=`${j.ProtocolPackage}::incentive_v3::entry_deposit`,t=this.transactions.filter(a=>a.kind==="MoveCall"&&a.target===e);return!!(this.transactions.find(a=>a.kind==="MoveCall"&&a.target.includes("claim_reward"))&&t.length>0)}isEntryDepositTransaction(){return!!this.getMoveCallTransaction(`${j.ProtocolPackage}::incentive_v3::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallTransaction(`${j.ProtocolPackage}::incentive_v3::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallTransaction(`${j.ProtocolPackage}::incentive_v3::withdraw`)}findPoolByAssetId(e){let t=Object.values(j.pool).find(n=>n.assetId===e);if(!t)throw new Error("Pool not found");return t}decodeEntryClaimAndDeposit(){return{txType:ct.TransactionType.Other,type:"EntryClaimAndDeposit",intentionData:{type:"entry_claim_and_deposit"}}}decodeClaimReward(){return console.log("decode claims"),{txType:ct.TransactionType.Other,type:"ClaimReward",intentionData:{type:"claim_reward"}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:ct.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,assetId:e}}}decodeEntryMultiDeposit(){let e=[],t=`${j.ProtocolPackage}::incentive_v3::entry_deposit`;return this.transactions.forEach(n=>{if(n.kind==="MoveCall"&&n.target===t){let a=new Zn(n,this.txb),r=a.decodeInputU8(3),i=a.decodeInputU64(5);e.push({assetId:r,amount:i})}}),{txType:ct.TransactionType.Other,type:"EntryMultiDeposit",intentionData:{list:e}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5);return{txType:ct.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,assetId:e}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6);return{txType:ct.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,assetId:e}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5);return{txType:ct.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,assetId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(j.ProtocolPackage));return new Zn(e,this.txb)}},Zn=class o{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return o.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return o.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,lt.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return o.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return Dr.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,lt.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,lt.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,lt.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,lt.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return Dr.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,lt.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var W=require("navi-sdk");async function Ut(o,e,t,n){return await(0,W.depositCoin)(o,e,t,n),o}async function rc(o,e,t,n){let[a]=await(0,W.withdrawCoin)(o,e,t);return o.transferObjects([a],o.pure(n)),o}async function ic(o,e,t,n){let[a]=await(0,W.borrowCoin)(o,e,t);return o.transferObjects([a],o.pure.address(n)),o}async function vr(o,e,t,n){return await(0,W.repayDebt)(o,e,t,n),o}async function sc(o,e){return await(0,W.claimAllRewardsPTB)(o,e)}async function cc(o,e){return await(0,W.claimAllRewardsResupplyPTB)(o,e)}var ta=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward",n),await sc(t.suiClient,t.account.address)}static fromData(t){return new o(t)}};var ea=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{type:n}=this.data;return console.log("claim reward and supply",n),await cc(t.suiClient,t.account.address)}static fromData(t){return new o(t)}};var dc=require("@mysten/sui.js/transactions");var lc=require("navi-sdk");function G(o){return Object.values(lc.pool).find(e=>String(e.assetId)===String(o))}var na=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:a}=this.data,r=new dc.TransactionBlock;console.log("build",this.data);let i=G(n);return await ic(r,i,a,t.account.address)}static fromData(t){return new o(t)}};var uc=require("@mysten/sui.js/transactions");async function Ft(o,e,t){let n=await o.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,n),n}var aa=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a}=t,{assetId:r,amount:i}=this.data,s=new uc.TransactionBlock;console.log("build",this.data);let c=G(r);if(r===0){let[p]=s.splitCoins(s.gas,[i]);return await Ut(s,c,p,i)}let l=await Ft(n,a.address,c.type);if(!l.data[0])throw new Error(`Insufficient balance for ${c.name} Token`);let d=l.data[0].coinObjectId;if(l.data.length>=2){let p=1;for(;p<l.data.length;)s.mergeCoins(d,[l.data[p].coinObjectId]),p++}return await Ut(s,c,s.object(d),i)}static fromData(t){return new o(t)}};var mc=require("@mysten/sui.js/transactions");var oa=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a}=t,{assetId:r,amount:i}=this.data,s=new mc.TransactionBlock;console.log("build",this.data);let c=G(r);if(r===0){let[m]=s.splitCoins(s.gas,[i]);return vr(s,c,m,i)}let l=await Ft(n,a.address,c.type);if(!l.data[0])throw new Error(`Insufficient balance for ${c.name} Token`);let d=l.data[0].coinObjectId;if(l.data.length>=2){let m=1;for(;m<l.data.length;)s.mergeCoins(d,[l.data[m].coinObjectId]),m++}return vr(s,c,s.object(d),i)}static fromData(t){return new o(t)}};var pc=require("@mysten/sui.js/transactions");var ra=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{assetId:n,amount:a}=this.data,r=new pc.TransactionBlock;console.log("build",this.data);let i=G(n);return await rc(r,i,a,t.account.address)}static fromData(t){return new o(t)}};var fc=require("@mysten/sui.js/transactions");var ia=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a}=t,{list:r}=this.data,i=new fc.TransactionBlock;console.log("build",this.data);for(let s=0;s<r.length;s++){let{assetId:c,amount:l}=r[s],d=G(c);if(c===0){let[f]=i.splitCoins(i.gas,[l]);await Ut(i,d,f,l);continue}let m=await Ft(n,a.address,d.type);if(!m.data[0])throw new Error(`Insufficient balance for ${d.name} Token`);let p=m.data[0].coinObjectId;if(m.data.length>=2){let f=1;for(;f<m.data.length;)i.mergeCoins(p,[m.data[f].coinObjectId]),f++}await Ut(i,d,i.object(p),l)}return i}static fromData(t){return new o(t)}};var sa=class{application="navi";supportSDK="@mysten/sui.js";async deserialize(e){await xr();let{transactionBlock:t}=e,a=new Xn(t).decode();return{txType:bc.TransactionType.Other,txSubType:a.type,intentionData:a.intentionData}}async build(e){let{suiClient:t,account:n}=e,a;switch(await xr(),e.txSubType){case"EntryDeposit":a=aa.fromData(e.intentionData);break;case"EntryBorrow":a=na.fromData(e.intentionData);break;case"EntryRepay":a=oa.fromData(e.intentionData);break;case"EntryWithdraw":a=ra.fromData(e.intentionData);break;case"EntryMultiDeposit":a=ia.fromData(e.intentionData);break;case"ClaimReward":a=ta.fromData(e.intentionData);break;case"EntryClaimAndDeposit":a=ea.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n})}};var ke=require("@msafe/sui3-utils"),hc=require("@mysten/bcs"),gc=require("@mysten/sui/transactions"),yc=q(require("sort-keys-recursive")),Tc="msafe-plain-tx",Cc=ke.TransactionSubTypes.others.plain,Ar=class o{constructor(e){this.data=e}application=Tc;txType=ke.TransactionType.Other;txSubType=Cc;serialize(){return JSON.stringify((0,yc.default)(this.data))}async build(e){return gc.Transaction.from((0,hc.fromHex)(this.data.content))}static fromData(e){return new o(e)}},ca=class{application;supportSDK="@mysten/sui";constructor(){this.application=Tc}async deserialize(e){let{content:t}=e.appContext;return{txType:ke.TransactionType.Other,txSubType:Cc,intentionData:{content:t}}}async build(e){let{suiClient:t,network:n,account:a}=e;return Ar.fromData(e.intentionData).build({suiClient:t,network:n,account:a})}};var Rr=require("@mysten/sui/client"),Ic=require("@mysten/sui/transactions"),ua=require("@mysten/sui.js/client"),Sc=require("@mysten/sui.js/transactions");var qt=require("@open-rpc/client-js");var Qd={"-32700":"ParseError","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError"},Or=class extends Error{},la=class extends Or{code;type;constructor(e,t){super(e),this.code=t,this.type=Qd[t]??"ServerError"}};function zd(o){let e=new URL(o);return e.protocol=e.protocol.replace("http","ws"),e.toString()}var Jd={WebSocketConstructor:typeof WebSocket<"u"?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5},da=class{endpoint;options;#n=0;#o=0;#t=null;#e=null;#r=new Set;#a=new Map;constructor(e,t={}){this.endpoint=e,this.options={...Jd,...t},this.endpoint&&this.endpoint.startsWith("http")&&(this.endpoint=zd(this.endpoint))}async makeRequest(e,t){let n=await this.#i();return new Promise((a,r)=>{this.#n+=1,this.#a.set(this.#n,{resolve:a,reject:r,timeout:setTimeout(()=>{this.#a.delete(this.#n),r(new Error(`Request timeout: ${e}`))},this.options.callTimeout)}),n.send(JSON.stringify({jsonrpc:"2.0",id:this.#n,method:e,params:t}))}).then(({error:a,result:r})=>{if(a)throw new la(a.message,a.code);return r})}#i(){return this.#e?this.#e:(this.#e=new Promise(e=>{this.#t?.close(),this.#t=new this.options.WebSocketConstructor(this.endpoint),this.#t.addEventListener("open",()=>{this.#o=0,e(this.#t)}),this.#t.addEventListener("close",()=>{this.#o++,this.#o<=this.options.maxReconnects&&setTimeout(()=>{this.#s()},this.options.reconnectTimeout)}),this.#t.addEventListener("message",({data:t})=>{let n;try{n=JSON.parse(t)}catch(a){console.error(new Error(`Failed to parse RPC message: ${t}`,{cause:a}));return}if("id"in n&&n.id!=null&&this.#a.has(n.id)){let{resolve:a,timeout:r}=this.#a.get(n.id);clearTimeout(r),a(n)}else if("params"in n){let{params:a}=n;this.#r.forEach(r=>{r.subscriptionId===a.subscription&&a.subscription===r.subscriptionId&&r.onMessage(a.result)})}})}),this.#e)}async#s(){return this.#t?.close(),this.#e=null,Promise.allSettled([...this.#r].map(e=>e.subscribe(this)))}async subscribe(e){let t=new Pr(e);return this.#r.add(t),await t.subscribe(this),()=>t.unsubscribe(this)}},Pr=class{subscriptionId=null;input;subscribed=!1;constructor(e){this.input=e}onMessage(e){this.subscribed&&this.input.onMessage(e)}async unsubscribe(e){let{subscriptionId:t}=this;return this.subscribed=!1,t==null?!1:(this.subscriptionId=null,e.makeRequest(this.input.unsubscribe,[t]))}async subscribe(e){this.subscriptionId=null,this.subscribed=!0;let t=await e.makeRequest(this.input.method,this.input.params);this.subscribed&&(this.subscriptionId=t)}};var dt=class{rpcClient;websocketClient;constructor({url:e,websocket:{url:t,...n}={},rpc:a}){let r=new qt.HTTPTransport(a?.url??e,{headers:{"Content-Type":"application/json",...a?.headers}});this.rpcClient=new qt.Client(new qt.RequestManager([r])),this.websocketClient=new da(t??e,n)}async request(e){return await this.rpcClient.request(e)}async subscribe(e){let t=await this.websocketClient.subscribe(e);return async()=>!!await t()}};var ma=class o{apps;constructor(){this.apps=new Map}static fromHelpers(e){let t=new o;for(let n=0;n<e.length;n++){let a=e[n];switch(a.supportSDK){case"@mysten/sui.js":t.addLegacyHelper(a);break;case"@mysten/sui":t.addHelper(a);break;default:throw new Error(`${a.application}: ${a.supportSDK} SDK not supported`)}}return t}addLegacyHelper(e){this.apps.set(e.application,new _r(e))}addHelper(e){this.apps.set(e.application,new Br(e))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}},Br=class{constructor(e){this.helper=e}async deserialize(e){let t=new Rr.SuiClient({transport:new dt({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=new ua.SuiClient({transport:new dt({url:e.clientUrl,rpc:{url:e.clientUrl}})}),a=await e.transactionBlock.build({client:n}),r=Ic.Transaction.from(a);return this.helper.deserialize({...e,suiClient:t,transaction:r})}async build(e){let t=new Rr.SuiClient({transport:new dt({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<1e8)throw new Error("Insufficient gas fee");let a=await this.helper.build({...e,suiClient:t});a.setSender(e.account.address);let r=await a.build({client:t});return Sc.TransactionBlock.from(r)}},_r=class{constructor(e){this.helper=e}async deserialize(e){let t=new ua.SuiClient({transport:new dt({url:e.clientUrl,rpc:{url:e.clientUrl}})});return this.helper.deserialize({...e,transactionBlock:e.transactionBlock,suiClient:t})}async build(e){let t=new ua.SuiClient({transport:new dt({url:e.clientUrl,rpc:{url:e.clientUrl}})}),n=await t.getBalance({owner:e.account.address});if(Number(n.totalBalance)<1e8)throw new Error("Insufficient gas fee");return this.helper.build({...e,suiClient:t})}};var Rc=require("@msafe/sui3-utils"),Lr=require("@scallop-io/sui-scallop-sdk");var x=require("@msafe/sui3-utils"),Wr=require("@scallop-io/sui-scallop-sdk");var wc=require("@mysten/sui/utils"),ut=class{constructor(e,t){this.transaction=e;this.scallopClient=t;this.scallopClient=t,this.inputs=e.getData().inputs,this.commands=e.getData().commands,this.movecallsAsSet=new Set(this.commands.filter(this.isMoveCall).map(n=>`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`))}inputs;commands;movecallsAsSet;get address(){return this.scallopClient.address}get utils(){return this.scallopClient.utils}get coreId(){return{protocolPkg:this.address.get("core.packages.protocol.id"),market:this.address.get("core.market"),version:this.address.get("core.version"),coinDecimalsRegistry:this.address.get("core.coinDecimalsRegistry"),xOracle:this.address.get("core.oracles.xOracle"),spoolPkg:this.address.get("spool.id"),borrowIncentivePkg:this.address.get("borrowIncentive.id"),veScaPkgId:this.address.get("vesca.id"),scoin:this.address.get("scoin.id"),referral:this.address.get("referral.id")}}matchMoveCallCommand(e,t){let{address:n,module:a,name:r}=(0,wc.parseStructTag)(t);return e?e.package===n&&e.module===a&&e.function===r:!1}isMoveCall(e){return e.$kind==="MoveCall"&&!!e.MoveCall}filterMoveCallCommands(e,t){return this.isMoveCall(e)&&this.matchMoveCallCommand(e.MoveCall,t)}getMoveCallCommands(e){let t=new Set(e),n=e.reduce((r,i,s)=>(r[i]=s,r),{}),a=[];return this.commands.forEach(r=>{this.isMoveCall(r)&&r.MoveCall&&t.has(r.MoveCall.package)&&(a[n[r.MoveCall.package]]=r.MoveCall)}),a}hasMoveCallCommand(e){return this.movecallsAsSet.has(e)}};var pa=require("@mysten/sui/bcs"),mt=require("@mysten/sui/utils"),Er=class o{constructor(e,t){this.moveCall=e;this.transaction=t;this.cmdIdx=e?.MoveCall?t.getData().commands.findIndex(n=>{if(n.$kind==="MoveCall"){let a=`${n.MoveCall.package}::${n.MoveCall.module}::${n.MoveCall.function}`,r=`${e.MoveCall.package}::${e.MoveCall.module}::${e.MoveCall.function}`;return a===r}return!1}):-1}cmdIdx;get txBlockTransactions(){return this.transaction.blockData.transactions[this.cmdIdx]}decodeSharedObjectId(e){let t=this.getInputParam(e);return o.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return o.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"U64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"U8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"Address");return(0,mt.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"String")}decodeInputBool(e){return this.decodePureArg(e,"Bool")}decodePureArg(e,t){let n=this.getInputParam(e);return o.getPureInputValue(n,t)}getInputParam(e){let t=this.txBlockTransactions.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return t}getNestedInputParam(e){let t=this.txBlockTransactions.arguments[e];if(t.kind!=="NestedResult")throw new Error("not input type");return this.transaction.blockData.transactions[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure,a=pa.bcs[t];return pa.bcs[t].parse(new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,mt.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,mt.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,mt.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,mt.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let t=e.value.Pure;return pa.bcs.U64.parse(new Uint8Array(t))}typeArg(e){return(0,mt.normalizeStructTag)(this.txBlockTransactions.typeArguments[e])}txArg(e){return this.transaction.blockData.inputs[e]}},T=Er;var Mr=class{constructor(e,t){this.splitCoin=e;this.txb=t}getAmountInput(){return this.splitCoin.amounts.map(e=>{if(e.kind==="Input")return Number(T.getPureInputValue(e,"U64"))}).filter(e=>e!==void 0)}},O=Mr;var pt=require("@mysten/sui/utils"),kc=async(o,e)=>{let t=await o.suiKit.client().getObject({id:e,options:{showContent:!0}});if(t?.data?.content?.dataType!=="moveObject")return!1;let a=t.data.content.fields.lock_key?.fields.name;if(!a)return!1;let r=o.address.get("borrowIncentive.object");return a===`${r.slice(2)}::incentive_account::IncentiveProgramLockKey`},Kt={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},N={unstakeObligation:(o,e,t)=>o.moveCall(`${Kt.id}::user::unstake`,[Kt.incentivePools,Kt.incentiveAccounts,o.object(e),o.object(t),pt.SUI_CLOCK_OBJECT_ID],[(0,pt.normalizeStructTag)(pt.SUI_TYPE_ARG)]),redeem_rewards:(o,e,t,n)=>o.moveCall(`${Kt.id}::user::redeem_rewards`,[Kt.incentivePools,Kt.incentiveAccounts,o.object(e),o.object(t),pt.SUI_CLOCK_OBJECT_ID],[(0,pt.normalizeStructTag)(n)])};var fa=class extends ut{decode(){if(this.isSupplyWithStakeSpoolTransaction())return this.decodeSupplyWithStakeSpool();if(this.isUnstakeAndWithdrawTransaction())return this.decodeUnstakeAndWithdraw();if(this.isStakeSpoolTransaction())return this.decodeStakeSpool();if(this.isDepositCollateralTransaction())return this.decodeDepositCollateral();if(this.isWithdrawCollateralTransaction())return this.decodeWithdrawCollateral();if(this.isWithdrawLendingScoinTransaction())return this.decodeWithdrawLendingScoin();if(this.isWithdrawLendingTransaction())return this.decodeWithdrawLending();if(this.isSupplyLendingTransaction())return this.decodeSupplyLending();if(this.isBorrowWithReferralTransaction())return this.decodeBorrowWithReferral();if(this.isBorrowWithBoostTransaction())return this.decodeBorrowWithBoost();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayWithBoostTransaction())return this.decodeRepayWithBoost();if(this.isRepayTransaction())return this.decodeRepay();if(this.isUnstakeSpoolTransaction())return this.decodeUnstakeSpool();if(this.isMigrateAndClaim())return this.decodeMigrateAndClaim();if(this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isOpenObligationTransaction())return this.decodeOpenObligation();if(this.isMigrateScoinTransaction())return this.decodeMigrateScoin()}isMigrateScoinTransaction(){return this.hasMoveCallCommand(`${this.coreId.scoin}::s_coin_converter::mint_s_coin`)}isSupplyLendingTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::mint::mint`)}isSupplyWithStakeSpoolTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::mint::mint`),t=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::stake`);return e&&t}isUnstakeAndWithdrawTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::unstake`),t=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`);return e&&t}isStakeSpoolTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::stake`)}isWithdrawLendingTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`)}isWithdrawLendingScoinTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::redeem::redeem`),t=this.hasMoveCallCommand(`${this.coreId.scoin}::s_coin_converter::burn_s_coin`);return e&&t}isDepositCollateralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`)}isWithdrawCollateralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`)}isBorrowTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow`)}isBorrowWithBoostTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`);return e&&t}isBorrowWithReferralTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::borrow::borrow_with_referral`)}isRepayTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::repay::repay`)}isRepayWithBoostTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.protocolPkg}::repay::repay`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`);return e&&t}isUnstakeSpoolTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::unstake`)}isCreateStakeAccountTransaction(){return this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::new_spool_account`)}isClaimRewardTransaction(){let e=this.hasMoveCallCommand(`${this.coreId.spoolPkg}::user::redeem_rewards`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`);return e||t}isOpenObligationTransaction(){return this.hasMoveCallCommand(`${this.coreId.protocolPkg}::open_obligation::open_obligation`)}isMigrateAndClaim(){let e=this.hasMoveCallCommand(`${Wr.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::redeem_rewards`),t=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`),n=this.hasMoveCallCommand(`${this.coreId.borrowIncentivePkg}::user::stake`);return e&&(t||n)}get helperClaimLendingReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::redeem_rewards`)).map(t=>new T(t,this.transaction))}get helperClaimBorrowV2Reward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`)).map(t=>new T(t,this.transaction))}get helperStakeObligationWithVeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`));return new T(e,this.transaction)}get helperClaimBorrowReward(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${Wr.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::redeem_rewards`)).map(t=>new T(t,this.transaction))}get helperMint(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::mint::mint`));return new T(e,this.transaction)}get helperUnstakes(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::unstake`)).map(t=>new T(t,this.transaction))}get helperRedeems(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::redeem::redeem`)).map(t=>new T(t,this.transaction))}get helperRedeem(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::redeem::redeem`));return new T(e,this.transaction)}get helperBurnScoin(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.scoin}::s_coin_converter::burn_s_coin`));return new T(e,this.transaction)}get helperStake(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::stake`));return new T(e,this.transaction)}get helperUnstake(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.spoolPkg}::user::unstake`));return new T(e,this.transaction)}get helperDepositCollateral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`));return new T(e,this.transaction)}get helperWithdrawCollateral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`));return new T(e,this.transaction)}get helperBorrow(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::borrow::borrow`));return new T(e,this.transaction)}get helperBorrowWithReferral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::borrow::borrow_with_referral`));return new T(e,this.transaction)}get helperRepay(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.protocolPkg}::repay::repay`));return new T(e,this.transaction)}decodeMigrateScoin(){return{txType:x.TransactionType.Other,type:"MigrateScoin",intentionData:{}}}decodeMigrateAndClaim(){let e;this.helperStakeObligationWithVeSca.moveCall&&(e=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9));let t=this.helperClaimBorrowReward[0].decodeOwnedObjectId(2),n=this.helperClaimBorrowReward[0].decodeSharedObjectId(3),a=this.utils.parseCoinNameFromType(this.helperClaimBorrowReward[0].typeArg(0));return{txType:x.TransactionType.Other,type:"MigrateAndClaim",intentionData:{obligationKey:t,obligationId:n,rewardCoinName:a,veScaKey:e}}}decodeOpenObligation(){return{txType:x.TransactionType.Other,type:"OpenObligation",intentionData:{}}}decodeSupplyLending(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new O(t,this.transaction).getAmountInput().reduce((a,r)=>a+r,0);return{txType:x.TransactionType.Other,type:"SupplyLending",intentionData:{amount:n,coinName:e}}}decodeWithdrawLending(){let e=this.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0)),t=this.helperRedeem.getNestedInputParam(2),n=new O(t,this.transaction).getAmountInput().reduce((a,r)=>a+r,0);return{txType:x.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:n,coinName:e}}}decodeWithdrawLendingScoin(){let e=this.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0));console.log({coinName:e});let t=this.helperBurnScoin.getNestedInputParam(1),n=new O(t,this.transaction).getAmountInput().reduce((a,r)=>a+r,0);return{txType:x.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:n,coinName:e}}}decodeDepositCollateral(){let e=this.utils.parseCoinNameFromType(this.helperDepositCollateral.typeArg(0)),t=this.helperDepositCollateral.getNestedInputParam(3),n=new O(t,this.transaction).getAmountInput().reduce((r,i)=>r+i,0),a=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:x.TransactionType.Other,type:"DepositCollateral",intentionData:{amount:n,obligationId:a,collateralCoinName:e}}}decodeWithdrawCollateral(){let e=this.utils.parseCoinNameFromType(this.helperWithdrawCollateral.typeArg(0)),t=this.helperWithdrawCollateral.decodeInputU64(5),n=this.helperWithdrawCollateral.decodeSharedObjectId(1),a=this.helperWithdrawCollateral.decodeOwnedObjectId(2);return{txType:x.TransactionType.Other,type:"WithdrawCollateral",intentionData:{amount:t,collateralCoinName:e,obligationKey:a,obligationId:n}}}decodeBorrow(){let e=this.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperBorrow.decodeInputU64(5),n=this.helperBorrow.decodeSharedObjectId(1),a=this.helperBorrow.decodeOwnedObjectId(2);return{txType:x.TransactionType.Other,type:"Borrow",intentionData:{amount:t,coinName:e,obligationKey:a,obligationId:n}}}decodeBorrowWithBoost(){let e=this.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),n=this.helperBorrow.decodeInputU64(5),a=this.helperBorrow.decodeSharedObjectId(1),r=this.helperBorrow.decodeOwnedObjectId(2);return{txType:x.TransactionType.Other,type:"BorrowWithBoost",intentionData:{amount:n,coinName:e,obligationKey:r,obligationId:a,veScaKey:t}}}decodeBorrowWithReferral(){let e=this.utils.parseCoinNameFromType(this.helperBorrowWithReferral.typeArg(0)),t;this.helperStakeObligationWithVeSca.moveCall&&(t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9));let n=this.helperBorrowWithReferral.decodeInputU64(6),a=this.helperBorrowWithReferral.decodeSharedObjectId(1),r=this.helperBorrowWithReferral.decodeOwnedObjectId(2);return{txType:x.TransactionType.Other,type:"BorrowWithReferral",intentionData:{amount:n,coinName:e,obligationKey:r,obligationId:a,veScaKey:t}}}decodeRepay(){let e=this.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperRepay.getNestedInputParam(3),n=new O(t,this.transaction).getAmountInput().reduce((r,i)=>r+i,0),a=this.helperRepay.decodeSharedObjectId(1);return{txType:x.TransactionType.Other,type:"Repay",intentionData:{amount:n,obligationId:a,coinName:e}}}decodeRepayWithBoost(){let e=this.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),n=this.helperRepay.getNestedInputParam(3),a=new O(n,this.transaction).getAmountInput().reduce((i,s)=>i+s,0),r=this.helperRepay.decodeSharedObjectId(1);return{txType:x.TransactionType.Other,type:"RepayWithBoost",intentionData:{amount:a,obligationId:r,coinName:e,veScaKey:t}}}decodeStakeSpool(){let e;this.isCreateStakeAccountTransaction()||(e=this.helperStake.decodeOwnedObjectId(1));let t=0;if(this.helperBurnScoin.moveCall){let r=this.helperBurnScoin.getNestedInputParam(1);t=new O(r,this.transaction).getAmountInput().reduce((i,s)=>i+s,0)}if(this.helperStake.moveCall&&t===0){let r=this.helperStake.getNestedInputParam(2);t=new O(r,this.transaction).getAmountInput().reduce((i,s)=>i+s,0)}let n=this.helperStake.typeArg(0),a=this.utils.parseCoinNameFromType(n);return{txType:x.TransactionType.Other,type:"StakeSpool",intentionData:{amount:t,marketCoinName:a,stakeAccountId:e}}}decodeUnstakeSpool(){let e=this.helperUnstake.decodeOwnedObjectId(1),t=this.helperUnstake.decodeInputU64(2),n=this.helperUnstake.typeArg(0),a=this.utils.parseCoinNameFromType(n);return{txType:x.TransactionType.Other,type:"UnstakeSpool",intentionData:{amount:t,marketCoinName:a,stakeAccountId:e}}}decodeSupplyWithStakeSpool(){let e=this.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),n=new O(t,this.transaction).getAmountInput().reduce((r,i)=>r+i,0),a;return this.isCreateStakeAccountTransaction()||(a=this.helperStake.decodeOwnedObjectId(1)),{txType:x.TransactionType.Other,type:"SupplyAndStakeLending",intentionData:{amount:n,coinName:e,stakeAccountId:a}}}decodeUnstakeAndWithdraw(){let e=[];this.helperUnstakes.forEach(a=>{let r=a.decodeOwnedObjectId(1),i=a.decodeInputU64(2);e.push({id:r,coin:i})});let t=this.utils.parseCoinNameFromType(this.helperRedeems[0].typeArg(0)),n=0;if(this.helperBurnScoin.moveCall){let a=this.helperBurnScoin.getNestedInputParam(1);n=new O(a,this.transaction).getAmountInput().reduce((r,i)=>r+i,0)}return{txType:x.TransactionType.Other,type:"WithdrawAndUnstakeLending",intentionData:{amount:n,coinName:t,stakeAccountId:e}}}decodeClaimReward(){let e=[],t=[],n=[];return this.helperClaimLendingReward.forEach(a=>{let r=a.decodeOwnedObjectId(2),i=a.typeArg(0),s=this.utils.parseCoinNameFromType(i);e.push({stakeMarketCoinName:s,stakeAccountId:r})}),this.helperClaimBorrowV2Reward.forEach(a=>{let r=a.decodeSharedObjectId(3),i=a.decodeOwnedObjectId(4),s=this.utils.parseCoinNameFromType(a.typeArg(0));t.push({obligationId:i,obligationKey:r,rewardCoinName:s})}),this.helperClaimBorrowReward.forEach(a=>{let r=a.decodeSharedObjectId(2),i=a.decodeOwnedObjectId(3),s=this.utils.parseCoinNameFromType(a.typeArg(0));n.push({obligationId:i,obligationKey:r,rewardCoinName:s})}),{txType:x.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:n}}}};var ba=require("@msafe/sui3-utils");var ha=class extends ut{decode(){if(this.isCreateReferralLink())return this.decodeCreateReferralLink();if(this.isClaimRevenueReferral())return this.decodeClaimRevenueReferral();if(this.isBindReferral())return this.decodeBindReferral()}isClaimRevenueReferral(){return this.hasMoveCallCommand(`${this.coreId.referral}::referral_revenue_pool::claim_revenue_with_ve_sca_key`)}isCreateReferralLink(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_placeholder_key`)}isBindReferral(){return this.hasMoveCallCommand(`${this.coreId.referral}::referral_bindings::bind_ve_sca_referrer`)}get helperClaimRevenueReferral(){return this.commands.filter(t=>this.filterMoveCallCommands(t,`${this.coreId.referral}::referral_revenue_pool::claim_revenue_with_ve_sca_key`)).map(t=>new T(t,this.transaction))}get helperBindReferral(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.referral}::referral_bindings::bind_ve_sca_referrer`));return new T(e,this.transaction)}decodeCreateReferralLink(){return{txType:ba.TransactionType.Other,type:"CreateReferralLink",intentionData:{}}}decodeClaimRevenueReferral(){let e=this.helperClaimRevenueReferral[0].decodeOwnedObjectId(2),t=this.helperClaimRevenueReferral.map(n=>n.typeArg(0));return{txType:ba.TransactionType.Other,type:"ClaimRevenueReferral",intentionData:{veScaKey:e,coins:t}}}decodeBindReferral(){let e=this.helperBindReferral.decodePureArg(1,"Address");return{txType:ba.TransactionType.Other,type:"BindReferral",intentionData:{veScaKey:e}}}};var $t=require("@msafe/sui3-utils"),xc=require("@scallop-io/sui-scallop-sdk");var ga=class extends ut{decode(){if(this.isExtendPeriodAndStakeMoreSca())return this.decodePeriodAndStakeMoreSca();if(this.isStakeScaFirsTime()||this.isStakeMoreSca())return this.decodeStakeSca();if(this.isRenewExpiredVeSca())return this.decodeRenewExpiredVeSca();if(this.isExtendPeriod())return this.decodeExtendStakePeriod();if(this.isRedeemSca())return this.decodeRedeemSca()}isStakeScaFirsTime(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`)}isExtendPeriodAndStakeMoreSca(){let e=this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`),t=this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`);return!!e&&!!t}isRedeemSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::redeem`)}isStakeMoreSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`)}isExtendPeriod(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`)}isRenewExpiredVeSca(){return this.hasMoveCallCommand(`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`)}get helperStakeMoreSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`));return new T(e,this.transaction)}get helperStakeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`));return new T(e,this.transaction)}get helperExtendStakePeriod(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`));return new T(e,this.transaction)}get helperRedeemSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::redeem`));return new T(e,this.transaction)}get helperRenewExpired(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`));return new T(e,this.transaction)}get helperOldUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${xc.OLD_BORROW_INCENTIVE_PROTOCOL_ID}::user::unstake`));return new T(e,this.transaction)}get helperUnstakeObligation(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::unstake`));return new T(e,this.transaction)}get helperStakeObligationWithVeSca(){let e=this.commands.find(t=>this.filterMoveCallCommands(t,`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`));return new T(e,this.transaction)}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:$t.TransactionType.Other,type:"RedeemSca",intentionData:{veScaKey:e}}}decodeRenewExpiredVeSca(){let e=this.helperRenewExpired.getNestedInputParam(4),t=this.helperRenewExpired.decodeInputU64(5),n=new O(e,this.transaction).getAmountInput().reduce((b,y)=>b+y,0),a=this.helperRenewExpired.decodeOwnedObjectId(1),r=!!this.helperRedeemSca.moveCall,i=[],s=[],c=[];this.helperOldUnstakeObligation.moveCall&&(i=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(s=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(c=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let l=!1,d=!1,m,p,f=[{condition:i,isOld:!0},{condition:s,isOld:!1},{condition:c,isOld:!1}];for(let b=0;b<f.length;b++)f[b].condition.length>1&&([p,m]=f[b].condition,l=!0,d=f[b].isOld);return{txType:$t.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:n,unlockTime:t,obligationId:m,obligationKey:p,veScaKey:a,isHaveRedeem:r,isObligationLocked:l,isOldBorrowIncentive:d}}}decodeExtendStakePeriod(){let e=this.helperExtendStakePeriod.decodeInputU64(4),t=this.helperExtendStakePeriod.decodeOwnedObjectId(1),n=[],a=[],r=[];this.helperOldUnstakeObligation.moveCall&&(n=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(a=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(r=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let i=!1,s=!1,c,l,d=[{condition:n,isOld:!0},{condition:a,isOld:!1},{condition:r,isOld:!1}];for(let m=0;m<d.length;m++)d[m].condition.length>1&&([l,c]=d[m].condition,i=!0,s=d[m].isOld);return{txType:$t.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{unlockTime:e,obligationId:c,obligationKey:l,veScaKey:t,isObligationLocked:i,isOldBorrowIncentive:s}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),n=new O(e,this.transaction).getAmountInput().reduce((f,b)=>f+b,0),a=[],r=[],i,s=[];this.helperOldUnstakeObligation.moveCall&&(a=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(r=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(i=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(s=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,l=!1,d,m,p=[{condition:a,isOld:!0},{condition:r,isOld:!1},{condition:s,isOld:!1}];for(let f=0;f<p.length;f++)p[f].condition.length>1&&([m,d]=p[f].condition,c=!0,l=p[f].isOld);return{txType:$t.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:n,veScaKey:i,unlockTime:t,obligationId:d,obligationKey:m,isOldBorrowIncentive:l,isObligationLocked:c}}}decodeStakeSca(){let e,t;this.helperStakeSca.moveCall&&this.helperStakeMoreSca.moveCall===void 0?(e=this.helperStakeSca.getNestedInputParam(3),t=this.helperStakeSca.decodeInputU64(4)):e=this.helperStakeMoreSca.getNestedInputParam(4);let n=new O(e,this.transaction).getAmountInput().reduce((f,b)=>f+b,0),a=[],r=[],i,s=[];this.helperOldUnstakeObligation.moveCall&&(a=[this.helperOldUnstakeObligation.decodeOwnedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(r=[this.helperUnstakeObligation.decodeOwnedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(i=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(s=[this.helperStakeObligationWithVeSca.decodeOwnedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,l=!1,d,m,p=[{condition:a,isOld:!0},{condition:r,isOld:!1},{condition:s,isOld:!1}];for(let f=0;f<p.length;f++)p[f].condition.length>1&&([m,d]=p[f].condition,c=!0,l=p[f].isOld);return{txType:$t.TransactionType.Other,type:"StakeSca",intentionData:{amount:n,unlockTime:t,obligationId:d,obligationKey:m,veScaKey:i,isObligationLocked:c,isOldBorrowIncentive:l}}}};var Dc=q(require("sort-keys-recursive")),g=class{constructor(e){this.data=e}get application(){return"msafe-core"}serialize(){return JSON.stringify((0,Dc.default)(this.data))}isObligationLocked=async(e,t)=>{let n=await e.getObject({id:typeof t=="string"?t:t.objectId,options:{showContent:!0}}),a=!1;return n&&n?.data.content?.dataType==="moveObject"&&"lock_key"in n.data.content.fields&&(a=!!n.data.content.fields.lock_key),a};async buildTxWithRefreshObligation(e,t,n){let a=e.builder.createTxBlock();a.setSender(t.walletAddress);let{obligationId:r,obligationKey:i}=t;return await this.isObligationLocked(e.suiKit.client(),r)?(await a.unstakeObligationQuick(r,i),await n(e,a,t),await a.stakeObligationWithVeScaQuick(r,i,t.veScaKey)):await n(e,a,t),a}};var ya=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async borrow({account:t,scallopClient:n}){let{coinName:a,amount:r,obligationId:i,obligationKey:s}=this.data,c=t.address;return(await this.buildTxWithRefreshObligation(n,{walletAddress:c,obligationId:i,obligationKey:s},async(d,m)=>{let p=await m.borrowQuick(+r,a,i,s);m.transferObjects([p],c)})).txBlock}async build(t){return this.borrow(t)}static fromData(t){return new o(t)}};var Ta=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithBoost(t,n,a){let{obligationId:r,obligationKey:i,veScaKey:s,amount:c,coinName:l}=this.data;return(await this.buildTxWithRefreshObligation(t,{walletAddress:a,obligationId:r,obligationKey:i,veScaKey:s},async(m,p)=>{let f=await p.borrowQuick(+c,l,r,i);p.transferObjects([f],a)})).txBlock}async build(t){return this.borrowWithBoost(t.scallopClient,this.data,t.account.address)}static fromData(t){return new o(t)}};var Ca=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async borrowWithReferral({account:t,scallopClient:n}){let a=t.address,{obligationId:r,obligationKey:i,veScaKey:s,coinName:c,amount:l}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:a,obligationId:r,obligationKey:i,veScaKey:s},async(m,p)=>{let f=p.claimReferralTicket(c),b=await p.borrowWithReferralQuick(+l,c,f,r,i);p.burnReferralTicket(f,c),p.transferObjects([b],a)})).txBlock}async build(t){return this.borrowWithReferral(t)}static fromData(t){return new o(t)}};var vc=require("@mysten/sui/utils");var Ia=class o extends g{txType;txSubType;constructor(e={}){super(e)}async claimIncentiveRewards(e,t){let n=e.builder.createTxBlock();n.setSender(t);let a=await e.query.getAllStakeAccounts(t),r=await e.query.getLendings(void 0,t),i=await e.query.getObligations(t),s=Object.values(await e.query.getObligationAccounts(t)??[]),c=(()=>{let p=[...e.constants.whitelist.spool].map(f=>e.utils.parseCoinName(f));return Object.values(r??[]).filter(f=>!!f&&p.includes(f.coinName)).reduce((f,b)=>{let y=e.utils.parseMarketCoinName(b.coinName);return f[y]||(f[y]=0),f[y]+=b.availableClaimCoin,f},{})})(),l={};Object.entries(a).forEach(([p,f])=>{for(let b=0;b<f.length;b++){let y=f[b];if(!c[p])continue;let A=n.claim(y.id,p);l.sui?l.sui.push(A):l.sui=[A]}});let d=(()=>{let p={};return p.sui=Object.values(c).reduce((f,b)=>f+b,0),s.forEach(f=>{Object.values(f.borrowIncentives).forEach(b=>{b&&b.rewards.forEach(y=>{p[y.coinName]||(p[y.coinName]=0),p[y.coinName]?p[y.coinName]+=y.availableClaimCoin:p[y.coinName]=y.availableClaimCoin})})}),p})();if(i.length>0&&s.length>0)for(let p=0;p<s.length;p++){let f=s[p],b=!1,y=i.find(B=>B.id===f.obligationId)?.keyId,A={};if(y){if(Object.values(f.borrowIncentives).forEach(B=>{if(B){let Yt=B.rewards.filter(X=>{let Ae=X.coinName;return X.availableClaimCoin>0&&!A[Ae]});b=Yt.length>0,Yt.forEach(X=>{let Ae=n.claimBorrowIncentive(f.obligationId,y,X.coinName);A[X.coinName]=!0,l[X.coinName]?l[X.coinName].push(Ae):l[X.coinName]=[Ae]})}}),d.sui>0){let B=N.redeem_rewards(n,y,f.obligationId,vc.SUI_TYPE_ARG);l.sui?l.sui.push(B):l.sui=[B]}if(b&&await kc(e.query,f.obligationId)){n.unstakeObligation(f.obligationId,y);let Yt=await e.query.getBindedVeScaKey(f.obligationId);Yt?n.stakeObligationWithVesca(f.obligationId,y,Yt):n.stakeObligation(f.obligationId,y)}}}let m=(await Promise.all(Object.entries(l).map(async([p,f])=>{let b=f[0];if(f.length>1&&n.mergeCoins(b,f.slice(1)),p==="sui"){n.mergeCoins(n.gas,[b]);return}return await e.builder.utils.mergeSimilarCoins(n,b,e.utils.parseCoinType(p),t),b}))).filter(p=>!!p);return m.length>0&&n.transferObjects(m,t),n.txBlock}async build(e){return this.claimIncentiveRewards(e.scallopClient,e.account.address)}static fromData(e={}){return new o(e)}};var Sa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.depositCollateral(this.data.collateralCoinName,+this.data.amount,!1,this.data.obligationId)}static fromData(t){return new o(t)}};var wa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async migrateAndClaim({account:t,scallopClient:n}){let a=t.address,{obligationKey:r,obligationId:i,rewardCoinName:s,veScaKey:c}=this.data,l=n.builder.createTxBlock();l.setSender(a);let d=N.redeem_rewards(l,r,i,n.utils.parseCoinType(s));return l.transferObjects([d],a),await l.unstakeObligationQuick(i,r),c?await l.stakeObligationWithVeScaQuick(i,r,c):await l.stakeObligationQuick(i,r),l.txBlock}async build(t){return this.migrateAndClaim(t)}static fromData(t){return new o(t)}};var ka=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.migrateAllMarketCoin(!1,!1)}static fromData(t){return new o(t)}};var xa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.openObligation(!1)}static fromData(t){return new o(t)}};var Da=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async repay({account:t,scallopClient:n}){let a=t.address,{coinName:r,amount:i,obligationId:s,obligationKey:c}=this.data;return(await this.buildTxWithRefreshObligation(n,{walletAddress:a,obligationId:s,obligationKey:c},async(d,m)=>{await m.repayQuick(+i,r,s)})).txBlock}async build(t){return this.repay(t)}static fromData(t){return new o(t)}};var va=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async repayWithBoost({account:t,scallopClient:n}){let a=t.address,{coinName:r,amount:i,obligationId:s,veScaKey:c}=this.data,l=n.builder.createTxBlock();l.setSender(a);let d=n.constants.whitelist.borrowing.has(r);return d&&await l.unstakeObligationQuick(s,void 0),await l.repayQuick(+i,r,s),d&&await l.stakeObligationWithVeScaQuick(s,void 0,c),l.txBlock}async build(t){return this.repayWithBoost(t)}static fromData(t){return new o(t)}};var Aa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.deposit(this.data.coinName,+this.data.amount,!1,t.account.address)}static fromData(t){return new o(t)}};var Oa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.unstake(this.data.marketCoinName,+this.data.amount,!1)}static fromData(t){return new o(t)}};var Pa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async unstakeAndWithdraw(t,n,a){let r=t.builder.createTxBlock();r.setSender(a);let{stakeAccountId:i,amount:s,coinName:c}=this.data,l=[];for(let d=0;d<i.length;d++){let{id:m,coin:p}=i[d],f=t.utils.parseMarketCoinName(c),[b]=await r.unstakeQuick(p,f,m);if(b){let y=r.withdraw(b,c);l.push(y)}}if(s>0){let d=await r.withdrawQuick(s,c);l.push(d)}return l.length>1&&r.mergeCoins(l[0],l.slice(1)),r.transferObjects(l,a),r.txBlock}async build(t){return this.unstakeAndWithdraw(t.scallopClient,this.data,t.account.address)}static fromData(t){return new o(t)}};var Ra=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.withdrawCollateral(this.data.collateralCoinName,Number(this.data.amount),!1,this.data.obligationId,this.data.obligationKey,t.account.address)}static fromData(t){return new o(t)}};var Ba=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){return t.scallopClient.withdraw(this.data.coinName,Number(this.data.amount),!1,t.account.address)}static fromData(t){return new o(t)}};var _a=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async bindReferral({account:t,scallopClient:n}){let a=t.address,r=n.builder.createTxBlock();return r.setSender(a),r.bindToReferral(this.data.veScaKey),r.txBlock}async build(t){return this.bindReferral(t)}static fromData(t){return new o(t)}};var Ea=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async claimRevenueReferral({account:t,scallopClient:n}){let{veScaKey:a,coins:r}=this.data,i=t.address,s=n.builder.createTxBlock();s.setSender(i);let c=r.map(l=>n.utils.parseCoinNameFromType(l));return await s.claimReferralRevenueQuick(a,c),s.txBlock}async build(t){return this.claimRevenueReferral(t)}static fromData(t){return new o(t)}};var Ma=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async createReferralLink({account:t,scallopClient:n}){let a=t.address,r=n.builder.createTxBlock();r.setSender(a);let i=r.mintEmptyVeSca();return r.transferObjects([i],a),r.txBlock}async build(t){return this.createReferralLink(t)}static fromData(t){return new o(t)}};var Ac=require("@scallop-io/sui-scallop-sdk");var Wa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async extendPeriodAndStakeMoreSca({account:t,scallopClient:n}){let{amount:a,veScaKey:r,unlockTime:i,obligationId:s,obligationKey:c,isOldBorrowIncentive:l,isObligationLocked:d}=this.data,m=t.address,p=n.builder.createTxBlock();p.setSender(m);let f=await n.utils.selectCoins(a,Ac.SCA_COIN_TYPE,m),[b,y]=p.takeAmountFromCoins(f,a);return p.extendLockPeriod(r,i),p.extendLockAmount(r,b),p.transferObjects([y],m),!s||!c||(d&&(l?N.unstakeObligation(p,s,c):p.unstakeObligation(s,c)),p.stakeObligationWithVesca(s,c,r)),p.txBlock}async build(t){return this.extendPeriodAndStakeMoreSca(t)}static fromData(t){return new o(t)}};var Na=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async extendStakeScaLockPeriod({account:t,scallopClient:n}){let a=t.address,{veScaKey:r,unlockTime:i,obligationId:s,obligationKey:c,isObligationLocked:l,isOldBorrowIncentive:d}=this.data,m=n.builder.createTxBlock();return m.setSender(a),m.extendLockPeriod(r,i),s&&c&&(l&&(d?N.unstakeObligation(m,c,s):m.unstakeObligation(s,c)),m.stakeObligationWithVesca(s,c,r)),m.txBlock}async build(t){return this.extendStakeScaLockPeriod(t)}static fromData(t){return new o(t)}};var La=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async redeemSca({account:t,scallopClient:n}){let{veScaKey:a}=this.data,r=t.address,i=n.builder.createTxBlock();return i.setSender(r),await i.redeemScaQuick(a),i.txBlock}async build(t){return this.redeemSca(t)}static fromData(t){return new o(t)}};var Oc=require("@scallop-io/sui-scallop-sdk");var ja=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async renewExpiredStakeSca({account:t,scallopClient:n}){let a=t.address,{amount:r,unlockTime:i,vescaKey:s,isHaveRedeem:c,obligation:l,obligationKey:d,isObligationLocked:m,isOldBorrowIncentive:p}=this.data,f=n.builder.createTxBlock();if(f.setSender(a),c){let B=f.redeemSca(s);f.transferObjects([B],a)}let b=await n.builder.utils.selectCoins(r,Oc.SCA_COIN_TYPE,a),[y,A]=f.takeAmountFromCoins(b,r);return f.transferObjects([A],a),f.renewExpiredVeSca(s,y,i),!l||!d||(m&&(p?N.unstakeObligation(f,d,l):f.unstakeObligation(l,d)),f.stakeObligationWithVesca(l,d,s)),f.txBlock}async build(t){return this.renewExpiredStakeSca(t)}static fromData(t){return new o(t)}};var Pc=require("@scallop-io/sui-scallop-sdk");var Ua=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async stakeSca({account:t,scallopClient:n}){let a=t.address,{amount:r,isObligationLocked:i,isOldBorrowIncentive:s,obligationId:c,obligationKey:l,unlockTime:d,veScaKey:m}=this.data,p=n.builder.createTxBlock();p.setSender(a);let f=await n.utils.selectCoins(r,Pc.SCA_COIN_TYPE,a),[b,y]=p.takeAmountFromCoins(f,r),A;return m?p.extendLockAmount(m,b):A=p.lockSca(b,d),c&&l&&(i&&(s?N.unstakeObligation(p,l,c):p.unstakeObligation(c,l)),p.stakeObligationWithVesca(c,l,m||A)),m||p.transferObjects([A,y],a),p.txBlock}async build(t){return this.stakeSca(t)}static fromData(t){return new o(t)}};var Fa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async supplyAndStake({account:t,scallopClient:n}){let a=t.address,{amount:r,coinName:i,stakeAccountId:s}=this.data,c=n.builder.createTxBlock();c.setSender(a);let l=await c.depositQuick(+r,i),d=n.utils.parseMarketCoinName(i);if(n.constants.whitelist.spool.has(d))return c.txBlock;let m=await n.query.getStakeAccounts(d,a),p=s||(m.length>0?m[0].id:void 0);if(p)await c.stakeQuick(l,d,p);else{let f=c.createStakeAccount(d);await c.stakeQuick(l,d,f),c.transferObjects([f],a)}return c.txBlock}async build(t){return this.supplyAndStake(t)}static fromData(t){return new o(t)}};var qa=class o extends g{constructor(t){super(t);this.data=t}txType;txSubType;async withdrawUnlockedSca({account:t,scallopClient:n}){let{vescaKey:a}=this.data,r=t.address,i=n.builder.createTxBlock();return i.setSender(r),await i.redeemScaQuick(a),i.txBlock}async build(t){return this.withdrawUnlockedSca(t)}static fromData(t){return new o(t)}};var Ka=class{application="scallop";supportSDK="@mysten/sui";scallopClient;async deserialize(e){if(!this.scallopClient){let s=new Lr.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e.account.address,suiClients:[e.suiClient]});this.scallopClient=await s.createScallopClient()}let{transaction:t}=e;console.log("transaction",t);let n=new fa(t,this.scallopClient),a=new ha(t,this.scallopClient),r=new ga(t,this.scallopClient),i=n.decode()||a.decode()||r.decode();if(!i)throw new Error("Unknown transaction type");return{txType:Rc.TransactionType.Other,txSubType:i.type,intentionData:i.intentionData}}async build(e){let{suiClient:t,account:n,network:a,txSubType:r,intentionData:i}=e;if(!this.scallopClient){let c=new Lr.Scallop({addressId:"67c44a103fe1b8c454eb9699",walletAddress:e.account.address,suiClients:[e.suiClient]});this.scallopClient=await c.createScallopClient()}let s;switch(r){case"SupplyLending":s=Aa.fromData(i);break;case"WithdrawLending":s=Ba.fromData(i);break;case"Borrow":s=ya.fromData(i);break;case"Repay":s=Da.fromData(i);break;case"DepositCollateral":s=Sa.fromData(i);break;case"WithdrawCollateral":s=Ra.fromData(i);break;case"OpenObligation":s=xa.fromData(i);break;case"UnstakeSpool":s=Oa.fromData(i);break;case"ClaimIncentiveReward":s=Ia.fromData(i);break;case"BorrowWithBoost":s=Ta.fromData(i);break;case"StakeSca":s=Ua.fromData(i);break;case"ExtendStakePeriod":s=Na.fromData(i);break;case"ExtendPeriodAndStakeMore":s=Wa.fromData(i);break;case"RenewExpStakePeriod":s=ja.fromData(i);break;case"WithdrawStakedSca":s=qa.fromData(i);break;case"SupplyAndStakeLending":s=Fa.fromData(i);break;case"WithdrawAndUnstakeLending":s=Pa.fromData(i);break;case"RedeemSca":s=La.fromData(i);break;case"MigrateAndClaim":s=wa.fromData(i);break;case"BorrowWithReferral":s=Ca.fromData(i);break;case"CreateReferralLink":s=Ma.fromData(i);break;case"ClaimRevenueReferral":s=Ea.fromData(i);break;case"BindReferral":s=_a.fromData(i);break;case"MigrateScoin":s=ka.fromData(i);break;case"RepayWithBoost":s=va.fromData(i);break;default:throw new Error("not implemented")}return s.build({suiClient:t,account:n,network:a,scallopClient:this.scallopClient})}};var Zc=require("@msafe/sui3-utils");var Qt=require("@msafe/sui3-utils"),bt=require("@mysten/sui/utils");var Bc="https://suilend-assets.s3.us-east-2.amazonaws.com/springsui";var Kc=require("@msafe/sui3-utils"),ft=require("@suilend/sdk");var Dt=require("@msafe/sui3-utils"),Ht=require("@mysten/bcs"),Vt=require("@mysten/sui/utils"),vt=require("@suilend/frontend-sui"),jr=q(require("bignumber.js"));var $a=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isDepositTransaction())return this.decodeDeposit();if(this.isWithdrawTransaction())return this.decodeWithdraw();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayTransaction())return this.decodeRepay();if(this.isClaimTransaction())return this.decodeClaim();if(this.isClaimAndDepositTransaction())return this.decodeClaimAndDeposit();throw new Error("Unknown transaction type")}get inputs(){return console.log("this.transaction.getData().inputs",this.transaction.getData().inputs),this.transaction.getData().inputs}get commands(){return console.log("this.transaction.getData().commands",this.transaction.getData().commands),this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}hasDepositTransactionMoveCallCommands(){return!!this.getMoveCallCommand("deposit_liquidity_and_mint_ctokens")&&!!this.getMoveCallCommand("deposit_ctokens_into_obligation")}hasClaimTransactionMoveCallCommands(){return!!this.getMoveCallCommand("claim_rewards")}isDepositTransaction(){return!this.hasClaimTransactionMoveCallCommands()&&this.hasDepositTransactionMoveCallCommands()}isWithdrawTransaction(){return!!this.getMoveCallCommand("withdraw_ctokens")&&!!this.getMoveCallCommand("redeem_ctokens_and_withdraw_liquidity_request")}isBorrowTransaction(){return!!this.getMoveCallCommand("borrow_request")}isRepayTransaction(){return!!this.getMoveCallCommand("repay")}isClaimTransaction(){return this.hasClaimTransactionMoveCallCommands()&&!this.hasDepositTransactionMoveCallCommands()}isClaimAndDepositTransaction(){return this.hasClaimTransactionMoveCallCommands()&&this.hasDepositTransactionMoveCallCommands()}decodeDeposit(){let e={MintEvent:this.simResult.events.find(a=>a.type.includes("lending_market::MintEvent"))},t=(0,Vt.normalizeStructTag)(e.MintEvent.parsedJson.coin_type.name),n=e.MintEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeDeposit",t,n),{txType:Dt.TransactionType.Other,type:"deposit",intentionData:{coinType:t,value:n}}}decodeWithdraw(){let e={withdraw_ctokens:this.getMoveCallCommand("withdraw_ctokens")},t={RedeemEvent:this.simResult.events.find(c=>c.type.includes("lending_market::RedeemEvent"))},n=(0,Vt.normalizeStructTag)(t.RedeemEvent.parsedJson.coin_type.name),a=t.RedeemEvent.parsedJson.liquidity_amount;console.log("Decoder.decodeWithdraw",n,a);let r=e.withdraw_ctokens.MoveCall.arguments[4].Input,i=new jr.default((0,Ht.toHex)((0,Ht.fromBase64)(this.inputs[r].Pure.bytes)),16).toString(),s=i===vt.MAX_U64.toString();return console.log("decodeWithdraw - isMax:",s,"inputIndex:",r,"inputValue:",i,"MAX_U64.toString():",vt.MAX_U64.toString()),s&&(a=vt.MAX_U64.toString()),{txType:Dt.TransactionType.Other,type:"withdraw",intentionData:{coinType:n,value:a}}}decodeBorrow(){let e={borrow_request:this.getMoveCallCommand("borrow_request")},t={BorrowEvent:this.simResult.events.find(c=>c.type.includes("lending_market::BorrowEvent"))},n=(0,Vt.normalizeStructTag)(t.BorrowEvent.parsedJson.coin_type.name),a=`${+t.BorrowEvent.parsedJson.liquidity_amount-+t.BorrowEvent.parsedJson.origination_fee_amount}`;console.log("Decoder.decodeBorrow",n,a);let r=e.borrow_request.MoveCall.arguments[4].Input,i=new jr.default((0,Ht.toHex)((0,Ht.fromBase64)(this.inputs[r].Pure.bytes)),16).toString(),s=i===vt.MAX_U64.toString();return console.log("decodeBorrow - isMax:",s,"inputIndex:",r,"inputValue:",i,"MAX_U64.toString():",vt.MAX_U64.toString()),s&&(a=vt.MAX_U64.toString()),{txType:Dt.TransactionType.Other,type:"borrow",intentionData:{coinType:n,value:a}}}decodeRepay(){let e={RepayEvent:this.simResult.events.find(a=>a.type.includes("lending_market::RepayEvent"))},t=(0,Vt.normalizeStructTag)(e.RepayEvent.parsedJson.coin_type.name),n=e.RepayEvent.parsedJson.liquidity_amount;return console.log("Decoder.decodeRepay",t,n),{txType:Dt.TransactionType.Other,type:"repay",intentionData:{coinType:t,value:n}}}decodeClaim(){let e={ClaimReward:this.simResult.events.filter(n=>n.type.includes("lending_market::ClaimReward"))},t={};for(let n=0;n<e.ClaimReward.length;n++){let a=e.ClaimReward[n],r=(0,Vt.normalizeStructTag)(a.parsedJson.coin_type.name),i=a.parsedJson.liquidity_amount;t[r]=`${+(t[r]??"0")+ +i}`}return console.log("Decoder.decodeClaimRewards",t),{txType:Dt.TransactionType.Other,type:"claim",intentionData:{value:t}}}decodeClaimAndDeposit(){return{txType:Dt.TransactionType.Other,type:"claimAndDeposit",intentionData:this.decodeClaim().intentionData}}};var Ec=require("@mysten/sui/transactions");var _c=q(require("sort-keys-recursive")),R=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,_c.default)(this.data))}};var Va=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;if(console.log("BorrowIntention.build",n,a,r,i,s),!i||!s)throw new Error("Obligation not found");let c=new Ec.Transaction;return await r.borrowAndSendToUser(a.address,i.id,s.id,this.data.coinType,this.data.value,c),c}static fromData(t){return console.log("BorrowIntention.fromData",t),new o(t)}};var Lc=require("@mysten/sui/transactions");var Mc=require("@mysten/sui/utils"),Wc=require("@suilend/frontend-sui"),Gt=require("@suilend/sdk"),Nc=q(require("bignumber.js")),Xd=(o,e)=>{let t={[Gt.Side.DEPOSIT]:[],[Gt.Side.BORROW]:[]};return o.lendingMarket.reserves.forEach(n=>{[Gt.Side.DEPOSIT,Gt.Side.BORROW].forEach(a=>{let r=a===Gt.Side.DEPOSIT?n.depositsPoolRewardManager:n.borrowsPoolRewardManager,i=e.userRewardManagers.find(s=>s.poolRewardManagerId===r.id);i&&(t[a]=r.poolRewards.map((s,c)=>({reserveArrayIndex:n.arrayIndex,rewardIndex:BigInt(c),rewardCoinType:(0,Mc.normalizeStructTag)(s.coinType.name),side:a})).filter(s=>!(0,Wc.isSendPoints)(s.rewardCoinType)&&!!i.rewards[Number(s.rewardIndex)]&&new Nc.default(i.rewards[Number(s.rewardIndex)].earnedRewards.value.toString()).gt(0)))})}),Object.values(t).flat()},Ha=Xd;var Ga=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;if(console.log("ClaimIntention.build",n,a,r,i,s),!i||!s)throw new Error("Obligation not found");let c=new Lc.Transaction;return r.claimRewardsAndSendToUser(a.address,i.id,Ha(r,s),c),c}static fromData(t){return console.log("ClaimIntention.fromData",t),new o(t)}};var jc=require("@mysten/sui/transactions");var Qa=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;if(console.log("ClaimAndDepositIntention.build",n,a,r,i,s),!i||!s)throw new Error("Obligation not found");let c=new jc.Transaction;return r.claimRewardsAndDeposit(a.address,i.id,Ha(r,s),c),c}static fromData(t){return console.log("ClaimAndDepositIntention.fromData",t),new o(t)}};var Uc=require("@mysten/sui/transactions");var za=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;console.log("DepositIntention.build",n,a,r,i,s);let c=new Uc.Transaction;return await r.depositIntoObligation(a.address,this.data.coinType,this.data.value,c,i?.id),c}static fromData(t){return console.log("DepositIntention.fromData",t),new o(t)}};var Fc=require("@mysten/sui/transactions");var Ja=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;if(console.log("RepayIntention.build",n,a,r,i,s),!i||!s)throw new Error("Obligation not found");let c=new Fc.Transaction;return await r.repayIntoObligation(a.address,s.id,this.data.coinType,this.data.value,c),c}static fromData(t){return console.log("RepayIntention.fromData",t),new o(t)}};var qc=require("@mysten/sui/transactions");var Ya=class o extends R{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,obligationOwnerCap:i,obligation:s}=t;if(console.log("WithdrawIntention.build",n,a,r,i,s),!i||!s)throw new Error("Obligation not found");let c=new qc.Transaction;return await r.withdrawAndSendToUser(a.address,i.id,s.id,this.data.coinType,this.data.value,c),c}static fromData(t){return console.log("WithdrawIntention.fromData",t),new o(t)}};var Xa=async(o,e)=>{let t=await ft.SuilendClient.initialize(ft.LENDING_MARKET_ID,ft.LENDING_MARKET_TYPE,o),n=await ft.SuilendClient.getObligationOwnerCaps(e.address,t.lendingMarket.$typeArgs,o),a=await Promise.all(n.map(r=>ft.SuilendClient.getObligation(r.obligationId,t.lendingMarket.$typeArgs,o)));return console.log("XXX getUtils - suilendClient:",t,"obligations:",a,"obligationOwnerCaps:",n),{suilendClient:t,obligationOwnerCaps:n,obligations:a}},Za=class{application="Suilend";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:a}=e;this.utils||(this.utils=await Xa(n,a));let r=await n.devInspectTransactionBlock({sender:a.address,transactionBlock:t});console.log("SuilendAppHelper.deserialize - simResult:",r,"utils:",this.utils,"suiClient:",n);let s=new $a(t,r).decode();return{txType:Kc.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:a,suiClient:r,account:i}=e;this.utils||(this.utils=await Xa(r,i));let s;switch(n){case"deposit":s=za.fromData(a);break;case"withdraw":s=Ya.fromData(a);break;case"borrow":s=Va.fromData(a);break;case"repay":s=Ja.fromData(a);break;case"claim":s=Ga.fromData(a);break;case"claimAndDeposit":s=Qa.fromData(a);break;default:throw new Error("not implemented")}let c=window.localStorage.getItem("obligationId"),l=this.utils.obligations?.find(m=>m.id===c)??this.utils.obligations?.[0],d=this.utils.obligationOwnerCaps?.find(m=>m.obligationId===l?.id);return s.build({network:t,suiClient:r,account:i,suilendClient:this.utils.suilendClient,obligationOwnerCap:d,obligation:l})}};var Ur=async(o,e)=>{let t=await Xa(o,e),n=await(await fetch(`${Bc}/liquid-staking-info-map.json`)).json();return{...t,LIQUID_STAKING_INFO_MAP:n}};var to=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isStakeTransaction())return this.decodeStake();if(this.isStakeAndDepositTransaction())return this.decodeStakeAndDeposit();if(this.isConvertTransaction())return this.decodeConvert();if(this.isConvertAndDepositTransaction())return this.decodeConvertAndDeposit();if(this.isUnstakeTransaction())return this.decodeUnstake();throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}hasSuilendDepositTransactionMoveCallCommands(){return!!this.getMoveCallCommand("deposit_liquidity_and_mint_ctokens")&&!!this.getMoveCallCommand("deposit_ctokens_into_obligation")}hasMintMoveCallCommands(){return!!this.getMoveCallCommand("mint")}hasRedeemMoveCallCommands(){return!!this.getMoveCallCommand("redeem")}isStakeTransaction(){return this.hasMintMoveCallCommands()&&!this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}isStakeAndDepositTransaction(){return this.hasMintMoveCallCommands()&&!this.hasRedeemMoveCallCommands()&&this.hasSuilendDepositTransactionMoveCallCommands()}isConvertTransaction(){return this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}isConvertAndDepositTransaction(){return this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&this.hasSuilendDepositTransactionMoveCallCommands()}isUnstakeTransaction(){return!this.hasMintMoveCallCommands()&&this.hasRedeemMoveCallCommands()&&!this.hasSuilendDepositTransactionMoveCallCommands()}decodeStake(){let e={MintEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::MintEvent"))},t=(0,bt.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStake",n),{txType:Qt.TransactionType.Other,type:"stake",intentionData:{amount:n,outCoinType:t}}}decodeStakeAndDeposit(){let e={MintEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::MintEvent"))},t=(0,bt.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),n=e.MintEvent.parsedJson.event.sui_amount_in;return console.log("Decoder.decodeStakeAndDeposit",n),{txType:Qt.TransactionType.Other,type:"stakeAndDeposit",intentionData:{amount:n,outCoinType:t}}}decodeConvert(){let e={RedeemEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::MintEvent"))},t=(0,bt.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,bt.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),a=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvert",a),{txType:Qt.TransactionType.Other,type:"convert",intentionData:{amount:a,inCoinType:t,outCoinType:n}}}decodeConvertAndDeposit(){let e={RedeemEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::RedeemEvent")),MintEvent:this.simResult.events.find(r=>r.type.includes("liquid_staking::MintEvent"))},t=(0,bt.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=(0,bt.normalizeStructTag)(e.MintEvent.parsedJson.event.typename.name),a=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeConvertAndDeposit",a),{txType:Qt.TransactionType.Other,type:"convertAndDeposit",intentionData:{amount:a,inCoinType:t,outCoinType:n}}}decodeUnstake(){let e={RedeemEvent:this.simResult.events.find(a=>a.type.includes("liquid_staking::RedeemEvent"))},t=(0,bt.normalizeStructTag)(e.RedeemEvent.parsedJson.event.typename.name),n=e.RedeemEvent.parsedJson.event.lst_amount_in;return console.log("Decoder.decodeUnstake",n),{txType:Qt.TransactionType.Other,type:"unstake",intentionData:{amount:n,inCoinType:t}}}};var Vc=require("@mysten/sui/transactions"),xe=require("@suilend/springsui-sdk");var $c=q(require("sort-keys-recursive")),L=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,$c.default)(this.data))}};var eo=class o extends L{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,LIQUID_STAKING_INFO_MAP:i,obligationOwnerCap:s,obligation:c}=t;console.log("ConvertIntention.build",n,a,r,i,s,c);let l=await xe.LstClient.initialize(n,Object.values(i).find(p=>p.type===this.data.inCoinType)),d=await xe.LstClient.initialize(n,Object.values(i).find(p=>p.type===this.data.outCoinType)),m=new Vc.Transaction;return(0,xe.convertLstsAndSendToUser)(l,d,m,a.address,this.data.amount),m}static fromData(t){return console.log("ConvertIntention.fromData",t),new o(t)}};var Hc=require("@mysten/sui/transactions"),ao=require("@suilend/sdk"),De=require("@suilend/springsui-sdk");var no=class o extends L{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,LIQUID_STAKING_INFO_MAP:i,obligationOwnerCap:s,obligation:c}=t;console.log("ConvertAndDepositIntention.build",n,a,r,i,s,c);let l=await De.LstClient.initialize(n,Object.values(i).find(y=>y.type===this.data.inCoinType)),d=await De.LstClient.initialize(n,Object.values(i).find(y=>y.type===this.data.outCoinType)),m=new Hc.Transaction,{obligationOwnerCapId:p,didCreate:f}=(0,ao.createObligationIfNoneExists)(r,m,s),b=(0,De.convertLsts)(l,d,m,a.address,this.data.amount);return r.deposit(b,this.data.outCoinType,p,m),f&&(0,ao.sendObligationToUser)(p,a.address,m),m}static fromData(t){return console.log("ConvertAndDepositIntention.fromData",t),new o(t)}};var Gc=require("@mysten/sui/transactions"),Qc=require("@suilend/springsui-sdk");var oo=class o extends L{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,LIQUID_STAKING_INFO_MAP:i,obligationOwnerCap:s,obligation:c}=t;console.log("StakeIntention.build",n,a,r,i,s,c);let l=await Qc.LstClient.initialize(n,Object.values(i).find(m=>m.type===this.data.outCoinType)),d=new Gc.Transaction;return l.mintAmountAndRebalanceAndSendToUser(d,a.address,this.data.amount),d}static fromData(t){return console.log("StakeIntention.fromData",t),new o(t)}};var zc=require("@mysten/sui/transactions"),io=require("@suilend/sdk"),Jc=require("@suilend/springsui-sdk");var ro=class o extends L{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,LIQUID_STAKING_INFO_MAP:i,obligationOwnerCap:s,obligation:c}=t;console.log("StakeAndDepositIntention.build",n,a,r,i,s,c);let l=await Jc.LstClient.initialize(n,Object.values(i).find(b=>b.type===this.data.outCoinType)),d=new zc.Transaction,{obligationOwnerCapId:m,didCreate:p}=(0,io.createObligationIfNoneExists)(r,d,s),f=l.mintAmountAndRebalance(d,a.address,this.data.amount);return r.deposit(f,this.data.outCoinType,m,d),p&&(0,io.sendObligationToUser)(m,a.address,d),d}static fromData(t){return console.log("StakeAndDepositIntention.fromData",t),new o(t)}};var Yc=require("@mysten/sui/transactions"),Xc=require("@suilend/springsui-sdk");var so=class o extends L{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:n,account:a,suilendClient:r,LIQUID_STAKING_INFO_MAP:i,obligationOwnerCap:s,obligation:c}=t;console.log("UnstakeIntention.build",n,a,r,i,s,c);let l=await Xc.LstClient.initialize(n,Object.values(i).find(m=>m.type===this.data.inCoinType)),d=new Yc.Transaction;return l.redeemAmountAndSendToUser(d,a.address,this.data.amount),d}static fromData(t){return console.log("UnstakeIntention.fromData",t),new o(t)}};var co=class{application="SpringSui";supportSDK="@mysten/sui";utils;async deserialize(e){let{transaction:t,suiClient:n,account:a}=e;this.utils||(this.utils=await Ur(n,a));let r=await n.devInspectTransactionBlock({sender:a.address,transactionBlock:t});console.log("SpringSuiAppHelper.deserialize",r);let s=new to(t,r).decode();return{txType:Zc.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{network:t,txSubType:n,intentionData:a,suiClient:r,account:i}=e;this.utils||(this.utils=await Ur(r,i));let s;switch(n){case"stake":s=oo.fromData(a);break;case"stakeAndDeposit":s=ro.fromData(a);break;case"convert":s=eo.fromData(a);break;case"convertAndDeposit":s=no.fromData(a);break;case"unstake":s=so.fromData(a);break;default:throw new Error("not implemented")}return s.build({network:t,suiClient:r,account:i,suilendClient:this.utils.suilendClient,LIQUID_STAKING_INFO_MAP:this.utils.LIQUID_STAKING_INFO_MAP,obligationOwnerCap:this.utils.obligationOwnerCaps?.[0],obligation:this.utils.obligations?.[0]})}};var nl=require("@msafe/sui3-utils");var Fr=require("@msafe/sui3-utils");var lo=class{constructor(e,t){this.transaction=e;this.simResult=t}decode(){if(this.isMintTransaction()){let e=this.getLiquidityChangeEvent("MintEvent");if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson;return console.log("Decoder event data - ",t),this.decodeMint(t)}if(this.isRedeemTransaction()){let e=this.getLiquidityChangeEvent("RedeemEvent");if(!e)throw new Error("No liquidity change event found. Unable to decode transaction.");let t=e.parsedJson;return console.log("Decoder event data - ",t),this.decodeRedeem(t)}throw new Error("Unknown transaction type")}get commands(){return this.transaction.getData().commands}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getLiquidityChangeEvent(e){return this.simResult.events.find(t=>this.isLiquidityChangeEventType(t.type,e))}isLiquidityChangeEventType(e,t){return e.includes(t)}isMintTransaction(){return!!this.getMoveCallCommand("mint")}isRedeemTransaction(){return!!this.getMoveCallCommand("redeem")}decodeMint(e){let{event:{sui_amount_in:t}}=e;return console.log("Decoder.decodeMint",t),{txType:Fr.TransactionType.Other,type:"mint",intentionData:{amount:t}}}decodeRedeem(e){let{event:{lst_amount_in:t}}=e;return console.log("Decoder.decodeRedeem",t),{txType:Fr.TransactionType.Other,type:"redeem",intentionData:{amount:t}}}};var tl=require("@alphafi/stsui-sdk");var uo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:a}=this.data,r={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},s=await new tl.LST(r).mint(a,n.address);return s.setGasBudget(1e8),s}static fromData(t){return console.log("MintIntention.fromData",t),new o(t)}};var el=require("@alphafi/stsui-sdk");var mo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:n}=t,{amount:a}=this.data,r={lstInfo:"0x1adb343ab351458e151bc392fbf1558b3332467f23bda45ae67cd355a57fd5f5",lstCointype:"0xd1b72982e40348d069bb1ff701e634c117bb5f741f44dff91e472d3b01461e55::stsui::STSUI"},s=await new el.LST(r).redeem(a,n.address);return s.setGasBudget(1e8),s}static fromData(t){return console.log("RedeemIntention.fromData",t),new o(t)}};var po=class{application="stsui";supportSDK="@mysten/sui";async deserialize(e){let{transaction:t,suiClient:n}=e,a=await n.devInspectTransactionBlock({sender:t.getData().sender,transactionBlock:t});console.log("StSuiHelper Sim result - ",a);let i=new lo(t,a).decode();return{txType:nl.TransactionType.Other,txSubType:i.type,intentionData:i.intentionData}}async build(e){let{account:t}=e;console.log("StSui build transaction type",e.txSubType);let n;switch(e.txSubType){case"mint":n=uo.fromData(e.intentionData);break;case"redeem":n=mo.fromData(e.intentionData);break;default:throw new Error("build not implemented")}return n.build({account:t})}};var kl=require("@msafe/sui3-utils"),xl=require("turbos-clmm-sdk");var _=require("@msafe/sui3-utils"),qr=require("@mysten/sui.js/bcs"),gt=require("@mysten/sui.js/utils"),al=require("turbos-clmm-sdk");var U={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},F={PackageId:"0xdee9"};var nu=(o,e,t,n)=>{if(o===1)switch(n.findIndex(i=>i===e)){case 0:return[!0,!0];case 1:return[!0,!1];case 2:return[!1,!0];case 3:return[!1,!1];default:throw new Error(`not target: ${e}`)}switch(t.findIndex(r=>r===e)){case 0:return[!0];case 1:return[!1];default:throw new Error(`not target: ${e}`)}},fo=class{constructor(e,t,n){this.txb=e;this.turbosSdk=t;this.config=n}get transactions(){return this.txb.blockData.transactions}get swap1Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b`,`${this.config.PackageId}::swap_router::swap_b_a`]}get swap2Layer(){return[`${this.config.PackageId}::swap_router::swap_a_b_b_c`,`${this.config.PackageId}::swap_router::swap_a_b_c_b`,`${this.config.PackageId}::swap_router::swap_b_a_b_c`,`${this.config.PackageId}::swap_router::swap_b_a_c_b`]}async decode(e){if(this.isSwapTransaction())return this.decodeSwap();if(this.isAddLiquidityTransaction())return this.decodeAddLiquidity();if(this.isIncreaseLiquidityTransaction())return this.decodeIncreaseLiquidity(e);if(this.isRemoveLiquidityTransaction())return this.decodeRemoveLiquidity(e);if(this.isDecreaseLiquidityTransaction())return this.decodeDecreaseLiquidity(e);if(this.isCollectFeeTransaction())return this.decodeCollectFee();if(this.isCollectRewardTransaction())return this.decodeCollectReward();if(this.isBurnTransaction())return this.decodeBurn();if(this.isPrixClaimTransaction())return this.decodePrixClaim();if(this.isPrixJoinTransaction())return this.decodePrixJoin();if(this.isSwapExactBaseForQuoteTransaction())return this.decodeSwapExactBaseForQuote();if(this.isSwapExactQuoteForBaseTransaction())return this.decodeSwapExactQuoteForBase();throw new Error("Unknown transaction type")}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}getMoveCallsTransaction(e){return e.every(t=>this.transactions.find(n=>n.kind==="MoveCall"&&n.target===t))}getSwapMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&e.includes(t.target))}isSwapTransaction(){return!!this.getSwapMoveCallTransaction([...this.swap1Layer,...this.swap2Layer])}isAddLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::mint`)}isIncreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::increase_liquidity`)}isDecreaseLiquidityTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::decrease_liquidity`)}isCollectFeeTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect`)}isCollectRewardTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::collect_reward`)}isBurnTransaction(){return!!this.getMoveCallTransaction(`${this.config.PackageId}::position_manager::burn`)}isPrixJoinTransaction(){return!!this.getMoveCallTransaction(`${U.PackageId}::claim::join`)}isPrixClaimTransaction(){return!!this.getMoveCallTransaction(`${U.PackageId}::claim::claim`)}isRemoveLiquidityTransaction(){return!!this.getMoveCallsTransaction([`${this.config.PackageId}::position_manager::decrease_liquidity`,`${this.config.PackageId}::position_manager::burn`])}isSwapExactBaseForQuoteTransaction(){return!!this.getMoveCallTransaction(`${F.PackageId}::clob_v2::swap_exact_base_for_quote`)}isSwapExactQuoteForBaseTransaction(){return!!this.getMoveCallTransaction(`${F.PackageId}::clob_v2::swap_exact_quote_for_base`)}async decodeSwap(){let e=this.transactions.find(f=>f.kind==="MoveCall"),t=0;this.swap2Layer.includes(e.target)&&(t=1);let n=nu(t,e.target,this.swap1Layer,this.swap2Layer),a=n.map((f,b)=>{let y=this.helper.decodeSharedObjectId(b),A=this.helper.decodeInputU128(4+b+t),B=this.turbosSdk.math.sqrtPriceX64ToTickIndex(new al.BN(A.toString()));return{pool:y,a2b:f,nextTickIndex:B}}),r=n[0]||t===1?e.typeArguments[0]:e.typeArguments[1],i=t===1?e.typeArguments[4]:n[0]?e.typeArguments[1]:e.typeArguments[0],s=this.helper.decodeInputAddress(6+2*t),c=this.helper.decodeInputU64(7+2*t),l=this.helper.decodeInputBool(5+2*t),d=this.helper.decodeInputU64(2+t),m=this.helper.decodeInputU64(3+t),p=await this.turbosSdk.trade.computeSwapResultV2({pools:[{pool:a[0].pool,a2b:a[0].a2b,amountSpecified:d}],address:s,amountSpecifiedIsInput:l});return{txType:_.TransactionType.Other,type:"Swap",intentionData:{routes:a,coinTypeA:r,coinTypeB:i,address:s,amountA:l?d:m,amountB:l?m:d,amountSpecifiedIsInput:l,slippage:"0.1",deadline:c}}}decodeAddLiquidity(){console.log(this.helper,"decodeAddLiquidity this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeInputAddress(12),n=this.helper.decodeInputU64(8),a=this.helper.decodeInputU64(9),r=this.helper.decodeInputU32(4),i=this.helper.decodeInputBool(5),s=this.helper.decodeInputU32(6),c=this.helper.decodeInputBool(7),l=this.helper.decodeInputU64(13);return{txType:_.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:10,address:t,amountA:n,amountB:a,tickLower:i?-r:r,tickUpper:c?-s:s,deadline:l}}}decodeIncreaseLiquidity(e){console.log(this.helper,"decodeIncreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(0),n=this.helper.decodeSharedObjectId(4),a=this.helper.decodeInputU64(5),r=this.helper.decodeInputU64(6),i=this.helper.decodeInputU64(9);return{txType:_.TransactionType.Other,type:"IncreaseLiquidity",intentionData:{pool:t,slippage:10,address:e,amountA:a,amountB:r,nft:n,deadline:i}}}decodeDecreaseLiquidity(e){console.log(this.helper,"decodeDecreaseLiquidity this.helper");let t=this.helper.decodeSharedObjectId(0),n=this.helper.decodeSharedObjectId(2),a=this.helper.decodeInputU64(3),r=this.helper.decodeInputU64(4),i=this.helper.decodeInputU64(5),s=this.helper.decodeInputU64(6);return{txType:_.TransactionType.Other,type:"DecreaseLiquidity",intentionData:{pool:t,decreaseLiquidity:a,nft:n,amountA:r,amountB:i,slippage:10,address:e,deadline:s}}}decodeCollectFee(){console.log(this.helper,"decodeCollectFee this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2),n=this.helper.decodeInputAddress(5),a=this.helper.decodeInputU64(3),r=this.helper.decodeInputU64(4),i=this.helper.decodeInputU64(6);return{txType:_.TransactionType.Other,type:"CollectFee",intentionData:{pool:e,address:n,collectAmountA:a,collectAmountB:r,nft:t,deadline:i}}}decodeCollectReward(){console.log(this.helper,"decodeCollectReward this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2),n=this.helper.decodeInputAddress(6),a=this.collectRewardHelper.map(i=>i.decodeInputU64(5)),r=this.helper.decodeInputU64(7);return{txType:_.TransactionType.Other,type:"CollectReward",intentionData:{pool:e,address:n,rewardAmounts:a,nft:t,deadline:r}}}decodeBurn(){console.log(this.helper,"decodeBurn this.helper");let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2);return{txType:_.TransactionType.Other,type:"Burn",intentionData:{pool:e,nft:t}}}decodeRemoveLiquidity(e){console.log(this.helper,"decodeRemoveLiquidity this.helper");let t=this.decreaseLiquidityHelper.decodeSharedObjectId(0),n=this.decreaseLiquidityHelper.decodeSharedObjectId(2),a=this.decreaseLiquidityHelper.decodeInputU64(3),r=this.decreaseLiquidityHelper.decodeInputU64(4),i=this.decreaseLiquidityHelper.decodeInputU64(5),s=this.decreaseLiquidityHelper.decodeInputU64(6),c=this.collectRewardHelper.map(m=>m.decodeInputU64(5)),l=this.collectFeeHelper.decodeInputU64(3)||0,d=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:_.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:t,decreaseLiquidity:a,nft:n,amountA:r,amountB:i,slippage:10,address:e,collectAmountA:l,collectAmountB:d,rewardAmounts:c,deadline:s}}}decodePrixClaim(){return{txType:_.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:_.TransactionType.Other,type:"PrixJoin",intentionData:{}}}decodeSwapExactBaseForQuote(){let e=this.swapExactBaseForQuoteHelper.decodeSharedObjectId(0),t=this.swapExactBaseForQuoteHelper.decodeInputU64(3),n=this.swapExactBaseForQuoteHelper.shortTypeArg(0),a=this.swapExactBaseForQuoteHelper.shortTypeArg(1);return{txType:_.TransactionType.Other,type:"SwapExactBaseForQuote",intentionData:{poolId:e,amountIn:t,token1:n,token2:a}}}decodeSwapExactQuoteForBase(){let e=this.swapExactQuoteForBaseHelper.decodeSharedObjectId(0),t=this.swapExactQuoteForBaseHelper.decodeInputU64(3),n=this.swapExactQuoteForBaseHelper.shortTypeArg(0),a=this.swapExactQuoteForBaseHelper.shortTypeArg(1);return{txType:_.TransactionType.Other,type:"SwapExactQuoteForBase",intentionData:{poolId:e,amountIn:t,token1:n,token2:a}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target!=="0x2::coin::zero"&&t.target!=="0x0000000000000000000000000000000000000000000000000000000000000002::coin::zero");return new ht(e,this.txb)}get collectRewardHelper(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::collect_reward`).map(t=>new ht(t,this.txb))}get collectFeeHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::collect`);return new ht(e,this.txb)}get decreaseLiquidityHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::decrease_liquidity`);return new ht(e,this.txb)}get swapExactBaseForQuoteHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${F.PackageId}::clob_v2::swap_exact_base_for_quote`);return new ht(e,this.txb)}get swapExactQuoteForBaseHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${F.PackageId}::clob_v2::swap_exact_quote_for_base`);return new ht(e,this.txb)}},ht=class o{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return o.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return o.getOwnedObjectId(t)}decodeInputU128(e){let t=this.decodePureArg(e,"u128");return Number(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU32(e){let t=this.decodePureArg(e,"u32");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,gt.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return o.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return qr.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,gt.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,gt.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,gt.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,gt.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return qr.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,gt.normalizeStructTag)(this.moveCall.typeArguments[e])}shortTypeArg(e){return this.moveCall.typeArguments[e]}txArg(e){return this.moveCall.arguments[e]}};var ol=require("turbos-clmm-sdk");var bo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ol.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,address:r,amountA:i,amountB:s,slippage:c,tickLower:l,tickUpper:d,deadline:m,txb:p}=this.data;return n.pool.addLiquidity({pool:a,slippage:c,address:r,amountA:i,amountB:s,tickLower:l,tickUpper:d,deadline:m,txb:p})}static fromData(t){return new o(t)}};var rl=require("turbos-clmm-sdk");var ho=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new rl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,nft:r,txb:i}=this.data;return n.nft.burn({pool:a,nft:r,txb:i})}static fromData(t){return new o(t)}};var il=require("turbos-clmm-sdk");var go=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new il.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,address:r,nft:i,collectAmountA:s,collectAmountB:c,deadline:l,txb:d}=this.data;return n.pool.collectFee({pool:a,address:r,collectAmountA:s,collectAmountB:c,nft:i,deadline:l,txb:d})}static fromData(t){return new o(t)}};var sl=require("turbos-clmm-sdk");var yo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new sl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,address:r,nft:i,rewardAmounts:s,deadline:c,txb:l}=this.data;return n.pool.collectReward({pool:a,address:r,rewardAmounts:s,nft:i,deadline:c,txb:l})}static fromData(t){return new o(t)}};var cl=require("turbos-clmm-sdk");var To=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new cl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:a,address:r,tickLower:i,tickUpper:s,sqrtPrice:c,slippage:l,coinTypeA:d,coinTypeB:m,amountA:p,amountB:f,deadline:b,txb:y}=this.data;return n.pool.createPool({fee:a,amountA:p,amountB:f,address:r,tickLower:i,tickUpper:s,sqrtPrice:c,slippage:l,coinTypeA:d,coinTypeB:m,deadline:b,txb:y})}static fromData(t){return new o(t)}};var ll=require("turbos-clmm-sdk");var Co=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ll.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,address:r,amountA:i,amountB:s,slippage:c,nft:l,decreaseLiquidity:d,deadline:m,txb:p}=this.data;return n.pool.decreaseLiquidity({pool:a,slippage:c,address:r,amountA:i,amountB:s,nft:l,decreaseLiquidity:d,deadline:m,txb:p})}static fromData(t){return new o(t)}};var dl=require("turbos-clmm-sdk");var Io=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new dl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:a,address:r,amountA:i,amountB:s,slippage:c,nft:l,deadline:d,txb:m}=this.data;return n.pool.increaseLiquidity({pool:a,slippage:c,address:r,amountA:i,amountB:s,nft:l,deadline:d,txb:m})}static fromData(t){return new o(t)}};var ul=require("@mysten/sui.js/transactions"),ml=require("@mysten/sui.js/utils");var So=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new ul.TransactionBlock;return n.moveCall({target:`${U.PackageId}::claim::claim`,typeArguments:[U.turbosCoinType],arguments:[n.object(U.Claim),n.object(ml.SUI_CLOCK_OBJECT_ID)]}),n}static fromData(t){return new o(t)}};var pl=require("@mysten/sui.js/transactions");var wo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new pl.TransactionBlock;return n.moveCall({target:`${U.PackageId}::claim::join`,typeArguments:[U.turbosCoinType],arguments:[n.object(U.Claim)]}),n}static fromData(t){return new o(t)}};var fl=require("@mysten/sui.js/transactions"),bl=require("turbos-clmm-sdk");var ko=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new bl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),a=new fl.TransactionBlock;return a=await n.pool.collectFee({txb:a,...this.data}),a=await n.pool.collectReward({txb:a,...this.data}),a=await n.pool.decreaseLiquidity({txb:a,...this.data}),a=await n.nft.burn({txb:a,nft:this.data.nft,pool:this.data.pool}),a}static fromData(t){return new o(t)}};var hl=require("turbos-clmm-sdk");var xo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(this.data,"this.data");let n=new hl.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:a,coinTypeA:r,coinTypeB:i,address:s,amountA:c,amountB:l,slippage:d,amountSpecifiedIsInput:m,deadline:p,txb:f}=this.data;return n.trade.swap({routes:a,coinTypeA:r,coinTypeB:i,address:s,amountA:c,amountB:l,amountSpecifiedIsInput:m,slippage:d,deadline:p,txb:f})}static fromData(t){return new o(t)}};var Sl=require("turbos-clmm-sdk");var Kr=require("@mysten/sui.js/transactions"),$r=require("@mysten/sui.js/utils");var gl=require("turbos-clmm-sdk");var ve=class{constructor(e){this.turbosSdk=e}async getCoinsData(e,t,n){let a=[],r;do r=await this.turbosSdk.provider.getCoins({owner:e,coinType:t,cursor:r?.nextCursor}),a.push(...r.data);while(r.hasNextPage);let i=[],s=0;return a.sort((c,l)=>Number(l.balance)-Number(c.balance)).some(c=>s>=n?!0:(s+=Number(c.balance),i.push(c),!1)),i}splitAndMergeCoin(e,t,n){if(!e||e.length<1)return[void 0,void 0];if(this.isSuiCoinAddress(e[0].coinType)){let[i]=n.splitCoins(n.gas,[n.pure(t)]);return[i,void 0]}let a=n.object(e[0].coinObjectId);e.length>1&&n.mergeCoins(a,e.slice(1).map(i=>n.object(i.coinObjectId)));let[r]=n.splitCoins(a,[n.pure(t)]);return[r,a]}isSuiCoinAddress(e){return e.toLocaleLowerCase()==="0x2::sui::sui"}async IsAccountCap(e){let t=await this.turbosSdk.provider.getOwnedObjects({owner:e,options:{showContent:!0,showType:!0,showOwner:!0},filter:{StructType:`${F.PackageId}::custodian_v2::AccountCap`}});return t.data[0]?.data?(0,gl.unstable_getObjectId)(t.data[0].data):void 0}createAccount(e){let[t]=e.moveCall({typeArguments:[],target:`${F.PackageId}::clob_v2::create_account`,arguments:[]});return t}zero(e,t){return t.moveCall({typeArguments:[e],target:"0x2::coin::zero",arguments:[]})}};var yl=89,Tl=1e6,Cl=async o=>{let{token1:e,token2:t,poolId:n,amountIn:a,currentAddress:r,turbosSdk:i}=o,s=new Kr.TransactionBlock,c=new ve(i),l=await c.getCoinsData(r,t,a),[d,m]=c.splitAndMergeCoin(l,a,s);if(!d)throw new Error(`Not enough balance: ${t}`);let p=await c.IsAccountCap(r),f=p?s.object(p):c.createAccount(s),[b,y,A]=s.moveCall({typeArguments:[e,t],target:`${F.PackageId}::clob_v2::swap_exact_quote_for_base`,arguments:[s.object(String(n)),s.pure(yl),f,s.pure(a),s.object((0,$r.normalizeSuiObjectId)("0x6")),d]});return m&&s.transferObjects([m],s.pure(r)),s.transferObjects([b],s.pure(r)),s.transferObjects([y],s.pure(r)),p||s.transferObjects([f],s.pure(r)),s.setSenderIfNotSet(r),s.setGasBudget(Tl),s},Il=async o=>{let{token1:e,token2:t,poolId:n,amountIn:a,currentAddress:r,turbosSdk:i}=o,s=new Kr.TransactionBlock,c=new ve(i),l=await c.getCoinsData(r,e,a),[d,m]=c.splitAndMergeCoin(l,a,s);if(!d)throw new Error(`Not enough balance: ${e}`);let p=await c.IsAccountCap(r),f=p?s.object(p):c.createAccount(s),b=c.zero(t,s),[y,A,B]=s.moveCall({typeArguments:[e,t],target:`${F.PackageId}::clob_v2::swap_exact_base_for_quote`,arguments:[s.object(String(n)),s.pure(yl),f,s.pure(a),d,b,s.object((0,$r.normalizeSuiObjectId)("0x6"))]});return m&&s.transferObjects([m],s.pure(r)),s.transferObjects([y],s.pure(r)),s.transferObjects([A],s.pure(r)),p||s.transferObjects([f],s.pure(r)),s.setSenderIfNotSet(r),s.setGasBudget(Tl),s};var Do=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new Sl.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Il({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new o(t)}};var wl=require("turbos-clmm-sdk");var vo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let n=new wl.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Cl({...this.data,turbosSdk:n,currentAddress:t.account.address})}static fromData(t){return new o(t)}};var Ao=class{application="turbos";supportSDK="@mysten/sui.js";async deserialize(e){let t=new xl.TurbosSdk(e.network.replace("sui:",""),e.suiClient),n=await t.contract.getConfig(),{transactionBlock:a,account:r}=e;console.log(e,"input");let s=await new fo(a,t,n).decode(r.address);return{txType:kl.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{suiClient:t,account:n,network:a}=e,r;switch(console.log(e.intentionData,"intentionData"),e.txSubType){case"CreatePool":r=To.fromData(e.intentionData);break;case"AddLiquidity":r=bo.fromData(e.intentionData);break;case"IncreaseLiquidity":r=Io.fromData(e.intentionData);break;case"DecreaseLiquidity":r=Co.fromData(e.intentionData);break;case"RemoveLiquidity":r=ko.fromData(e.intentionData);break;case"CollectFee":r=go.fromData(e.intentionData);break;case"CollectReward":r=yo.fromData(e.intentionData);break;case"Burn":r=ho.fromData(e.intentionData);break;case"Swap":r=xo.fromData(e.intentionData);break;case"PrixJoin":r=wo.fromData(e.intentionData);break;case"PrixClaim":r=So.fromData(e.intentionData);break;case"SwapExactBaseForQuote":r=Do.fromData(e.intentionData);break;case"SwapExactQuoteForBase":r=vo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:a})}};var Ol=require("@msafe/sui3-utils");var Oo=require("@msafe/sui3-utils"),Vr=require("@mysten/sui.js/bcs"),yt=require("@mysten/sui.js/utils");var au={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},w=au;var Po=class{constructor(e){this.txb=e}decode(){if(console.log("txb",this.txb),this.isStakeTransaction())return this.decodeStake();if(this.isUnStakeTransaction())return this.decodeUnStake();if(this.isClaimTicketTransaction())return this.decodeClaimTicket();throw new Error("Unknown transaction type")}get transactions(){return this.txb.blockData.transactions}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isStakeTransaction(){return!!this.getMoveCallTransaction(`${w.packageId}::native_pool::stake`)}isUnStakeTransaction(){return!!this.getMoveCallTransaction(`${w.packageId}::native_pool::unstake`)}isClaimTicketTransaction(){return!!this.getMoveCallTransaction(`${w.packageId}::native_pool::burn_ticket`)}decodeStake(){let e=this.transactions[0].amounts[0].value.toNumber();return{txType:Oo.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(n=>n.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:Oo.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:Oo.TransactionType.Other,type:"ClaimTicket",intentionData:{ticketId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(w.packageId));return new Hr(e,this.txb)}},Hr=class o{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return o.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return o.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return Number(t)}decodeInputU8(e){let t=this.decodePureArg(e,"u8");return Number(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,yt.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let n=this.getInputParam(e);return o.getPureInputValue(n,t)}getInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="Input")throw new Error("not input type");return this.txb.blockData.inputs[t.index]}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let n=e.value.Pure;return Vr.bcs.de(t,new Uint8Array(n))}return e.value}static getOwnedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value=="object"){if(!("Object"in e.value)||!("ImmOrOwned"in e.value.Object))throw new Error("not ImmOrOwned");return(0,yt.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,yt.normalizeSuiAddress)(e.value)}static getSharedObjectId(e){if(e.type!=="object")throw new Error(`not object argument: ${JSON.stringify(e)}`);if(typeof e.value!="object")return(0,yt.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,yt.normalizeSuiAddress)(e.value.Object.Shared.objectId)}static getPureInput(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value!="object")return e.value;if(!("Pure"in e.value))throw new Error("Pure not in value");let n=e.value.Pure;return Vr.bcs.de(t,new Uint8Array(n))}typeArg(e){return(0,yt.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Dl=require("@mysten/sui.js/transactions");var Ro=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Dl.TransactionBlock,{ticketId:a}=this.data;return n.moveCall({target:`${w.packageId}::native_pool::burn_ticket`,arguments:[n.object(w.poolObjectId),n.object(w.systemStateObjectId),n.object(a)]}),n}static fromData(t){return new o(t)}};var vl=require("@mysten/sui.js/transactions");var Bo=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new vl.TransactionBlock,{amount:a}=this.data,[r]=n.splitCoins(n.gas,[n.pure(a)]);return n.moveCall({target:`${w.packageId}::native_pool::stake`,arguments:[n.object(w.poolObjectId),n.object(w.metadataObjectId),n.object(w.systemStateObjectId),r]}),n}static fromData(t){return new o(t)}};var Al=require("@mysten/sui.js/transactions");var _o=class o extends h{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let n=new Al.TransactionBlock,{amount:a}=this.data,r=(await t.suiClient.getAllCoins({owner:t.account.address,limit:100})).data,[i,...s]=r.filter(d=>d.coinType.split("::")[0]===w.certType.split("::")[0]),c=n.object(i.coinObjectId);s.length&&n.mergeCoins(c,s.map(d=>n.object(d.coinObjectId)));let l=n.splitCoins(n.object(i.coinObjectId),[n.pure(a)]);return n.moveCall({target:`${w.packageId}::native_pool::unstake`,arguments:[n.object(w.poolObjectId),n.object(w.metadataObjectId),n.object(w.systemStateObjectId),l]}),n}static fromData(t){return new o(t)}};var Eo=class{application="volo";supportSDK="@mysten/sui.js";async deserialize(e){let{transactionBlock:t}=e,a=new Po(t).decode();return{txType:Ol.TransactionType.Other,txSubType:a.type,intentionData:a.intentionData}}async build(e){let{suiClient:t,account:n}=e,a;switch(e.txSubType){case"Stake":a=Bo.fromData(e.intentionData);break;case"UnStake":a=_o.fromData(e.intentionData);break;case"ClaimTicket":a=Ro.fromData(e.intentionData);break;default:throw new Error("not implemented")}return a.build({suiClient:t,account:n})}};var Ul=require("@msafe/sui3-utils");var Gr=require("@cetusprotocol/cetus-sui-clmm-sdk"),Tt=require("@msafe/sui3-utils"),zt=require("@mysten/bcs"),Jt=require("@mysten/sui/bcs");var Mo=class{constructor(e){this.transaction=e}decode(){if(this.isOpenPositionTx())return this.decodeOpenPositionTx();if(this.isClosePositionTx())return this.decodeClosePositionTx();if(this.isProvideLiquidityTx())return this.decodeProvideLiquidityTx();if(this.isRemoveLiquidityTx())return this.decodeRemoveLiquidityTx();if(this.isCollectRewardsAndFeeTx())return this.decodeCollectRewardsAndFeeTx();if(this.isCollectRewardsTx())return this.decodeCollectRewardsTx();if(this.isCollectFeeTx())return this.decodeCollectFeeTx();throw new Error("Unknown transaction type")}decodeOpenPositionTx(){let e=this.getMoveCallCommand("open_position"),t=this.getMoveCallCommand("provide_liquidity_with_fixed_amount");return{txType:Tt.TransactionType.Other,type:"OpenPosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,1)),lowerTick:Number((0,Gr.asIntN)(BigInt(this.getU32(this.getInputIndex(e,2)))).toString()),upperTick:Number((0,Gr.asIntN)(BigInt(this.getU32(this.getInputIndex(e,3)))).toString()),tokenAmount:this.getU64(this.getInputIndex(t,6)),maxAmountTokenA:this.getU64(this.getInputIndex(t,7)),maxAmountTokenB:this.getU64(this.getInputIndex(t,8)),isTokenAFixed:this.getBoolean(this.getInputIndex(t,9))}}}decodeClosePositionTx(){let e=this.getMoveCallCommand("close_position"),t=this.getCollectRewardCallData();return{txType:Tt.TransactionType.Other,type:"ClosePosition",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),transferTokensTo:this.getAddress(this.getInputIndex(e,4)),collectRewardTokens:t.map(n=>n.rewardCoinType),collectFeeTokens:this.getTypeArguments(e)}}}decodeProvideLiquidityTx(){let e=this.getMoveCallCommand("provide_liquidity_with_fixed_amount");return{txType:Tt.TransactionType.Other,type:"ProvideLiquidity",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),tokenAmount:this.getU64(this.getInputIndex(e,6)),maxAmountTokenA:this.getU64(this.getInputIndex(e,7)),maxAmountTokenB:this.getU64(this.getInputIndex(e,8)),isTokenAFixed:this.getBoolean(this.getInputIndex(e,9))}}}decodeRemoveLiquidityTx(){let e=this.getMoveCallCommand("remove_liquidity");return{txType:Tt.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),liquidity:this.getU128(this.getInputIndex(e,4)),maxAmountTokenA:this.getU64(this.getInputIndex(e,5)),maxAmountTokenB:this.getU64(this.getInputIndex(e,6)),transferTokensTo:this.getAddress(this.getInputIndex(e,7)),...this.collectTokens()}}}decodeCollectRewardsTx(){let e=this.getCollectRewardCallData();return{txType:Tt.TransactionType.Other,type:"CollectRewards",intentionData:{pool:e[0].pool,position:e[0].position,collectRewardTokens:e.map(t=>t.rewardCoinType)}}}decodeCollectFeeTx(){return{txType:Tt.TransactionType.Other,type:"CollectFee",intentionData:this.getFeeCallData()}}decodeCollectRewardsAndFeeTx(){let e=this.getFeeCallData();return{txType:Tt.TransactionType.Other,type:"CollectRewardsAndFee",intentionData:{pool:e.pool,position:e.position,...this.collectTokens()}}}getFeeCallData(){let e=this.getMoveCallCommand("collect_fee");return{pool:this.getSharedObjectID(this.getInputIndex(e,2)),position:this.getOwnedObjectID(this.getInputIndex(e,3)),collectFeeTokens:this.getTypeArguments(e)}}getCollectRewardCallData(){let e=[];return this.commands.forEach(t=>{t.$kind==="MoveCall"&&t.MoveCall.function==="collect_reward"&&e.push({pool:this.getSharedObjectID(this.getInputIndex(t,2)),position:this.getOwnedObjectID(this.getInputIndex(t,3)),rewardCoinType:this.getTypeArguments(t)[2]})}),e}collectTokens(){let e=this.getFeeCallData(),t=this.getCollectRewardCallData();return{collectFeeTokens:e.collectFeeTokens,collectRewardTokens:t.map(n=>n.rewardCoinType)}}get commands(){return this.transaction.getData().commands}get inputs(){return this.transaction.getData().inputs}isOpenPositionTx(){return!!this.getMoveCallCommand("open_position")}isProvideLiquidityTx(){return!!this.getMoveCallCommand("provide_liquidity_with_fixed_amount")}isRemoveLiquidityTx(){return!!this.getMoveCallCommand("remove_liquidity")}isCollectRewardsTx(){return!!this.getMoveCallCommand("collect_reward")}isCollectFeeTx(){return!!this.getMoveCallCommand("collect_fee")}isCollectRewardsAndFeeTx(){return this.isCollectRewardsTx()&&this.isCollectFeeTx()}isClosePositionTx(){return!!this.getMoveCallCommand("close_position")}getMoveCallCommand(e){return this.commands.find(t=>t.$kind==="MoveCall"&&t.MoveCall.function===e)}getSharedObjectID(e){return this.inputs[e].Object.SharedObject.objectId}getOwnedObjectID(e){return this.inputs[e].Object.ImmOrOwnedObject.objectId}getU32(e){return String(Jt.bcs.u32().parse(Uint8Array.from((0,zt.fromBase64)(this.inputs[e].Pure.bytes))))}getU64(e){return Jt.bcs.u64().parse(Uint8Array.from((0,zt.fromBase64)(this.inputs[e].Pure.bytes)))}getU128(e){return Jt.bcs.u128().parse(Uint8Array.from((0,zt.fromBase64)(this.inputs[e].Pure.bytes)))}getBoolean(e){return Jt.bcs.bool().parse(Uint8Array.from((0,zt.fromBase64)(this.inputs[e].Pure.bytes)))}getAddress(e){return Jt.bcs.Address.parse(Uint8Array.from((0,zt.fromBase64)(this.inputs[e].Pure.bytes)))}getTypeArguments(e){return e.MoveCall.typeArguments||[]}getInputIndex(e,t){return e.MoveCall.arguments[t].Input}};var _l=require("@msafe/sui3-utils");var Q=require("@firefly-exchange/library-sui");var Rl=require("@firefly-exchange/library-sui"),Bl=require("@firefly-exchange/library-sui/dist/src/spot"),Pl={rpc:"https://fullnode.mainnet.sui.io/",objects:{GlobalConfig:"0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",BasePackage:"0x3492c874c1e3b3e2984e8c41b589e642d4d0a5d6459e5a9cfc2d52fd7c89c267",CurrentPackage:"0x6c796c3ab3421a68158e0df18e4657b2827b1f8fed5ed4b82dba9c935988711b"}},It=(o,e)=>{if(o!=="sui:mainnet")throw new Error("Bluefin spot protocol is only available on sui::mainnet");let t=new Rl.SuiClient({url:Pl.rpc});return new Bl.OnChainCalls(t,Pl.objects,{address:e.address,isUIWallet:!1})};var v=class{static async OpenPosition(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool),i=this.prototype.buildLiqInput(r,{...e,slippage:0});return await a.openPositionWithFixedAmount(r,e.lowerTick,e.upperTick,i,{returnTx:!0,sender:t.address})}static async provideLiquidity(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool),i=this.prototype.buildLiqInput(r,e);return await a.provideLiquidityWithFixedAmount(r,e.position,i,{returnTx:!0,sender:t.address})}static async removeLiquidity(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool);return await a.removeLiquidity(r,e.position,{liquidityAmount:new Q.BN(e.liquidity),tokenMaxA:new Q.BN(e.maxAmountTokenA),tokenMaxB:new Q.BN(e.maxAmountTokenB)},{returnTx:!0,sender:t.address})}static async closePosition(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool);return await a.closePosition(r,e.position,{returnTx:!0,sender:t.address})}static async collectRewards(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool);return await a.collectRewards(r,e.position,{rewardCoinsType:e.collectRewardTokens,returnTx:!0,sender:t.address})}static async collectFee(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool);return await a.collectFee(r,e.position,{returnTx:!0,sender:t.address})}static async collectRewardsAndFee(e,t,n){let a=It(n,t),r=await a.queryChain.getPool(e.pool);return console.log(e.position),await a.collectFeeAndRewards(r,e.position,{returnTx:!0,sender:t.address})}buildLiqInput(e,t){return{...Q.ClmmPoolUtil.estLiquidityAndCoinAmountFromOneAmounts(t.lowerTick,t.upperTick,new Q.BN(t.tokenAmount),t.isTokenAFixed,!0,0,new Q.BN(e.current_sqrt_price)),tokenMaxA:new Q.BN(t.maxAmountTokenA),tokenMaxB:new Q.BN(t.maxAmountTokenB)}}};var Wo=class o extends u{constructor(t){super(t);this.data=t}txType=_l.TransactionType.Other;txSubType="ClosePosition";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.closePosition(this.data,n,a)}static fromData(t){return new o(t)}};var El=require("@msafe/sui3-utils");var No=class o extends u{constructor(t){super(t);this.data=t}txType=El.TransactionType.Other;txSubType="CollectFee";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.collectFee(this.data,n,a)}static fromData(t){return new o(t)}};var Ml=require("@msafe/sui3-utils");var Lo=class o extends u{constructor(t){super(t);this.data=t}txType=Ml.TransactionType.Other;txSubType="CollectRewards";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.collectRewards(this.data,n,a)}static fromData(t){return new o(t)}};var Wl=require("@msafe/sui3-utils");var jo=class o extends u{constructor(t){super(t);this.data=t}txType=Wl.TransactionType.Other;txSubType="CollectRewardsAndFee";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.collectRewardsAndFee(this.data,n,a)}static fromData(t){return new o(t)}};var Nl=require("@msafe/sui3-utils");var Uo=class o extends u{constructor(t){super(t);this.data=t}txType=Nl.TransactionType.Other;txSubType="OpenPosition";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.OpenPosition(this.data,n,a)}static fromData(t){return new o(t)}};var Ll=require("@msafe/sui3-utils");var Fo=class o extends u{constructor(t){super(t);this.data=t}txType=Ll.TransactionType.Other;txSubType="ProvideLiquidity";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.provideLiquidity(this.data,n,a)}static fromData(t){return new o(t)}};var jl=require("@msafe/sui3-utils");var qo=class o extends u{constructor(t){super(t);this.data=t}txType=jl.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:n,network:a}=t;return console.log(this.data),v.removeLiquidity(this.data,n,a)}static fromData(t){return new o(t)}};var Ko=class{application="bluefin";supportSDK="@mysten/sui";async deserialize(e){console.log("Bluefin helper deserialize input: ",e);let{transaction:t}=e,a=new Mo(t).decode();return{txType:Ul.TransactionType.Other,txSubType:a.type,intentionData:a.intentionData}}async build(e){let{suiClient:t,account:n,network:a}=e;console.log(e.txSubType);let r;switch(e.txSubType){case"OpenPosition":r=Uo.fromData(e.intentionData);break;case"ProvideLiquidity":r=Fo.fromData(e.intentionData);break;case"RemoveLiquidity":r=qo.fromData(e.intentionData);break;case"ClosePosition":r=Wo.fromData(e.intentionData);break;case"CollectFee":r=No.fromData(e.intentionData);break;case"CollectRewards":r=Lo.fromData(e.intentionData);break;case"CollectRewardsAndFee":r=jo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:n,network:a})}};var Jl=require("@msafe/sui3-utils");var Fl=require("kriya-dev-sdk");var $o=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Fl.KriyaSDK,{params:n}=this.data;return t.Amm.getTxbAddLiquidity(n)}static fromData(t){return new o(t)}};var ql=require("kriya-dev-sdk");var Vo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new ql.KriyaSDK,{params:n}=this.data;return t.Amm.getTxbAddLiquiditySingleSided(n)}static fromData(t){return new o(t)}};var Kl=require("kriya-dev-sdk");var Ho=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Kl.KriyaSDK,{params:n}=this.data;return t.Amm.getTxbClaimRewards(n)}static fromData(t){return new o(t)}};var $l=require("kriya-dev-sdk");var Go=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new $l.KriyaSDK,{params:n}=this.data;return t.Amm.getTxbRemoveLiquidity(n)}static fromData(t){return new o(t)}};var Vl=require("kriya-dev-sdk");var Qo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Vl.KriyaSDK,{params:n}=this.data;return t.Clmm.getTxbAddLiquiditySingleSided(n)}static fromData(t){return new o(t)}};var Hl=require("kriya-dev-sdk");var zo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Hl.KriyaSDK,{params:n}=this.data;return t.Clmm.getTxbAddLiquidity(n)}static fromData(t){return new o(t)}};var Gl=require("kriya-dev-sdk");var Jo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Gl.KriyaSDK,{params:n}=this.data;return t.Clmm.getTxbClaimMayaRewards(n)}static fromData(t){return new o(t)}};var Ql=require("kriya-dev-sdk");var Yo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new Ql.KriyaSDK,{params:n}=this.data;return t.Clmm.getTxbClaimRewards(n)}static fromData(t){return new o(t)}};var zl=require("kriya-dev-sdk");var Xo=class o extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let t=new zl.KriyaSDK,{params:n}=this.data;return t.Clmm.getTxbRemoveLiquidity(n)}static fromData(t){return new o(t)}};var Zo=class{application="kriya";supportSDK="@mysten/sui";async deserialize(e){let{appContext:t}=e;return{txType:Jl.TransactionType.Other,txSubType:t.action,intentionData:t}}async build(e){let t;switch(e.txSubType){case"AddLiquidity":t=$o.fromData(e.intentionData);break;case"AddLiquiditySingleSided":t=Vo.fromData(e.intentionData);break;case"RemoveLiquidity":t=Go.fromData(e.intentionData);break;case"ClaimRewards":t=Ho.fromData(e.intentionData);break;case"ClaimRewardsV3":t=Yo.fromData(e.intentionData);break;case"ClaimV3MayaRewards":t=Jo.fromData(e.intentionData);break;case"AddLiquidityV3":t=zo.fromData(e.intentionData);break;case"AddLiquiditySingleSideV3":t=Qo.fromData(e.intentionData);break;case"RemoveLiquidityV3":t=Xo.fromData(e.intentionData);break;default:throw new Error("not implemented")}return t.build()}};var ru=ma.fromHelpers([new Yn,new sa,new Qn,new ca,new Dn,new Ao,new Zo,new Ka,new Eo,new en,new Za,new co,new We,new Ko,new po]);
|
|
2
2
|
//# sourceMappingURL=index.js.map
|