@msafe/sui-app-store 0.0.116 → 0.0.118
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 +1 -2
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Ki=Object.create;var bt=Object.defineProperty;var Hi=Object.getOwnPropertyDescriptor;var zi=Object.getOwnPropertyNames;var Ji=Object.getPrototypeOf,Xi=Object.prototype.hasOwnProperty;var Cn=(n,e)=>{for(var t in e)bt(n,t,{get:e[t],enumerable:!0})},uo=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of zi(e))!Xi.call(n,o)&&o!==t&&bt(n,o,{get:()=>e[o],enumerable:!(a=Hi(e,o))||a.enumerable});return n};var q=(n,e,t)=>(t=n!=null?Ki(Ji(n)):{},uo(e||!n||!n.__esModule?bt(t,"default",{value:n,enumerable:!0}):t,n)),Yi=n=>uo(bt({},"__esModule",{value:!0}),n);var fc={};Cn(fc,{appHelpers:()=>bc});module.exports=Yi(fc);var Zo=require("@msafe/sui3-utils");var wo=require("@msafe/sui3-utils");var po=q(require("sort-keys-recursive")),u=class{constructor(e){this.data=e}get application(){return"msafe-core"}serialize(){return JSON.stringify((0,po.default)(this.data))}};var mo=require("@cetusprotocol/cetus-periphery-sdk"),bo=require("@cetusprotocol/cetus-sui-clmm-sdk"),Zi={fullRpcUrl:"https://fullnode.mainnet.sui.io/",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:"0xc33c3e937e5aa2009cc0c3fdb3f345a0c3193d4ee663ffc601fe8b894fbc4ba6",version:4,config:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:"0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"}},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0xd43348b8879c1457f882b02555ba862f2bc87bcc31b16294ca14a82f608875d2",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"},es={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:"0xcec352932edc6663a118e8d64ed54da6b8107e8719603bf728f80717592cd9e8",version:3,config:{dividend_manager_id:"0x721c990bfc031d074341c6059a113a59c1febfbd2faeb62d49dcead8408fa6b5",dividend_admin_id:"",dividend_settle_id:""}},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:"0xd3453d9be7e35efe222f78a810bb3af1859fd1600926afced8b4936d825c9a05",version:1,config:{admin_cap_id:"0x78a42978709c4032fab7b33b782b5bcef64c1c6603250bf23644650b72144375",vaults_manager_id:"0x25b82dd2f5ee486ed1c8af144b89a8931cd9c29dee3a86a1bfe194fdea9d04a6",vaults_pool_handle:"0x9036bcc5aa7fd2cceec1659a6a1082871f45bc400c743f50063363457d1738bd"}},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:"0x11ea791d82b5742cc8cab0bf7946035c97d9001d7c3803a93f119753da66f526",version:1,config:{global_config_id:"0x21215f2f6de04b57dd87d9be7bb4e15499aec935e36078e2488f36436d64996e",rewarder_manager_id:"0xe0e155a88c77025056da08db5b1701a91b79edb6167462f768e387c3ed6614d5",rewarder_manager_handle:"0xb32e312cbb3367d6f3d2b4e57c9225e903d29b7b9f612dae2ddf75bdeb26a5aa",admin_cap_id:"0xf10fbf1fea5b7aeaa524b87769461a28c5c977613046360093673991f26d886c"}},haedal:{package_id:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",published_at:"0x1d56b8ec33c3fae897eb7bb1acb79914e8152faed614868928e684c25c8b198d",version:1,config:{support_stakings:[{staking_id:"0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",from_coin_type:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",to_coin_type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"}]}}},ts={fullRpcUrl:"https://fullnode.testnet.sui.io/",simulationAccount:{address:"0xcd0247d0b67e53dde69b285e7a748e3dc390e8a5244eb9dd9c5c53d95e4cf0aa"},cetus_config:{package_id:"0xf5ff7d5ba73b581bca6b4b9fa0049cd320360abd154b809f8700a8fd3cfaf7ca",published_at:"0xf5ff7d5ba73b581bca6b4b9fa0049cd320360abd154b809f8700a8fd3cfaf7ca",config:{coin_list_id:"0x257eb2ba592a5480bba0a97d05338fab17cc3283f8df6998a0e12e4ab9b84478",launchpad_pools_id:"0xdc3a7bd66a6dcff73c77c866e87d73826e446e9171f34e1c1b656377314f94da",clmm_pools_id:"0x26c85500f5dd2983bf35123918a144de24e18936d0b234ef2b49fbb2d3d6307d",admin_cap_id:"0x1a496f6c67668eb2c27c99e07e1d61754715c1acf86dac45020c886ac601edb8",global_config_id:"0xe1f3db327e75f7ec30585fa52241edf66f7e359ef550b533f89aa1528dd1be52",coin_list_handle:"0x3204350fc603609c91675e07b8f9ac0999b9607d83845086321fca7f469de235",launchpad_pools_handle:"0xae67ff87c34aceea4d28107f9c6c62e297a111e9f8e70b9abbc2f4c9f5ec20fd",clmm_pools_handle:"0xd28736923703342b4752f5ed8c2f2a5c0cb2336c30e1fed42b387234ce8408ec"}},clmm_pool:{package_id:"0x0868b71c0cba55bf0faf6c40df8c179c67a4d0ba0e79965b68b3d72d7dfbf666",published_at:"0x1c29d658882c40eeb39a8bb8fe58f71a216a918acb3e3eb3b47d24efd07257f2",config:{pools_id:"0xc090b101978bd6370def2666b7a31d7d07704f84e833e108a969eda86150e8cf",global_config_id:"0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a",global_vault_id:"0xf3114a74d54cbe56b3e68f9306661c043ede8c6615f0351b0c3a93ce895e1699",admin_cap_id:""}},integrate:{package_id:"0x8627c5cdcd8b63bc3daa09a6ab7ed81a829a90cafce6003ae13372d611fbb1a9",published_at:"0xf1a5d0c5b0593e41d13f9684ca91365bdfe54a98836c1d33c90e361a031fac74",version:6},deepbook:{package_id:"0x000000000000000000000000000000000000000000000000000000000000dee9",published_at:"0x000000000000000000000000000000000000000000000000000000000000dee9"},deepbook_endpoint_v2:{package_id:"0xa34ffca2c6540e1ca9e53963ab43e7b1eed7b82e37696c743bb7c6179c15dfa6",published_at:"0xa34ffca2c6540e1ca9e53963ab43e7b1eed7b82e37696c743bb7c6179c15dfa6"},aggregatorUrl:"https://api-sui.devcetus.com/router",swapCountUrl:"https://api-sui.devcetus.com/v2/sui/swap/count"},as={launchpad:{package_id:"0x3beee8416089a5cbff9cfd5c0a2ce2937b0452dc7e2a3ab4dc431c7be05c2335",published_at:"0x3beee8416089a5cbff9cfd5c0a2ce2937b0452dc7e2a3ab4dc431c7be05c2335",config:{pools_id:"0xccc10403ab3da4ae943847908e0e674fe1fdab81c6383e4c6dcd0eea0edade3d",admin_cap_id:"0x8a72713049dbcfc40902ff209dc5e6066fe455d152baa235957c84d7a3b875ed",config_cap_id:"0x16492b4252b01debb60f8a825334020d7fdb9d895b52f8139c98618de30817fc"}},ido:{package_id:"0x1352bf18ef20458f7cc773852d4a90b240015a6a54479dda3a1debfc500bf044",published_at:"0xbd09a0889ea9970b821512428bab3e2fd01e16809a90a325cd3b3d3573eab6a4",config:{pools_id:"0x346bee25ab4d15bcfa9484ef5ebd4d7c94eb665ebaa745ff4094936a7f59a8b1",admin_cap_id:"0xc1bb19a24d3bb65dfd4f3835637b63347c223c67cde4b0888f1a857974f33cbb",package_version_id:"0x3ccf1b38e3259e638b980d4e6b49eac8c5aa94d3cb2ace5e75f0a551c8e67e5e"}},xcetus:{package_id:"0xdebaab6b851fd3414c0a62dbdf8eb752d6b0d31f5cfce5e38541bc6c6daa8966",published_at:"0xdebaab6b851fd3414c0a62dbdf8eb752d6b0d31f5cfce5e38541bc6c6daa8966",config:{xcetus_manager_id:"0x3be34cbad122c8b100ed7157d762b9610e68b3c65734e08bc3c3baf857da807d",lock_manager_id:"0x7c67e805182e3fecd098bd68a6b06c317f28f8c6249bd771e07904a10b424e60",lock_handle_id:"0xc5f3bbfefe9a45c13da7a34bc72cac122ee45d633690476a8ac56bd2c4e78c86"}},xcetus_dividends:{package_id:"0x20d948d640edd0c749f533d41efc5f843f212d441220324ad7959c6e1d281828",published_at:"0x20d948d640edd0c749f533d41efc5f843f212d441220324ad7959c6e1d281828",config:{dividend_manager_id:"0x13b7facb704fae1d199ff0038b8acabc253415a77d142b39189dee97d457e442",dividend_admin_id:"0x5eb78463007422d4130b21f61c180bcd190819b7792f56e00a61df3b8fb928ef",dividend_settle_id:"0x495095e13a170ff494d242ae44ac2c7453011ca6c33cff27498010105e10e4b4"}},cetus_faucet:{package_id:"0x1a69aee6be709054750949959a67aedbb4200583b39586d5e3eabe57f40012c7",published_at:"0x1a69aee6be709054750949959a67aedbb4200583b39586d5e3eabe57f40012c7"},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:"0x25cff94bdb454bae6a5565d09047bfe2b230025ef3bd2199622ec48d854b86b9",published_at:"0x25cff94bdb454bae6a5565d09047bfe2b230025ef3bd2199622ec48d854b86b9",config:{admin_cap_id:"0x9b2d6f5be2650d16d27cd630c4539a76d7793970343ed3cbb023e13f1637c07c",vaults_manager_id:"0xc0a1a937df08880e395d85014ff40c74f13abe7a53abdbffea36f51adaaaf79e",vaults_pool_handle:"0x3ab02203de753de9c8198cc0ce7594dc960878f2c34c5c5a4b7742082241860a"}},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:"0xfa0d98e99c1dbdbea1b0fe089fa93ebab40a7719ae4160c42cc78ebfe029fda0",published_at:"0xfa0d98e99c1dbdbea1b0fe089fa93ebab40a7719ae4160c42cc78ebfe029fda0",config:{global_config_id:"0x5082c7a5ee9a758025d7b0a5e8aa08b56625c7cd535b8909d2b7993991e229cc",rewarder_manager_id:"0xe789e092dbd9dceadbe89350c4761a6f2e11647aab97f09746a01b151926cc0e",rewarder_manager_handle:"0x7e7dd42392b5d82564dc9ad5093a111c5f0598cc9f806cff257d7dacb71f7837",admin_cap_id:"0x4ec248bca2d1fc05f39fd7491ab490464a46d128624caa4d3c2a66d957ef40b0"}},haedal:{package_id:"0xac2afb455cbcdc2ff1a2e9bbb8aa4ccb4506a544b08c740886892a5cdf92f472",published_at:"0x9dac9c5770e5f930d2223ff68782958701acfaee9337e8d8363978ce7670dffb",config:{support_stakings:[{staking_id:"0x6e384d2da5b040b27f973155e25bbe4beb0ad5ca8ee0a36e20dff356094c9fc0",from_coin_type:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",to_coin_type:"0xac2afb455cbcdc2ff1a2e9bbb8aa4ccb4506a544b08c740886892a5cdf92f472::hasui::HASUI"}]}}},fe=(n,e)=>{let t=n==="sui:mainnet"?Zi:ts,a=new bo.CetusClmmSDK(t);return a.senderAddress=e.address,a},P=(n,e)=>{let t=fe(n,e),a=n==="sui:mainnet"?es:as;return new mo.CetusPeripherySDK(a,t)};var fo=async(n,e,t)=>await fe(t,e).Position.createAddLiquidityFixTokenPayload(n?.parameter,n?.gasEstimateArg),go=async(n,e,t)=>await fe(t,e).Position.createAddLiquidityFixTokenPayload(n?.parameter,n?.gasEstimateArg),ho=async(n,e,t)=>await fe(t,e).Position.closePositionTransactionPayload(n),yo=async(n,e,t)=>await fe(t,e).Position.removeLiquidityTransactionPayload(n),So=async(n,e,t)=>await fe(t,e).Rewarder.collectRewarderTransactionPayload(n);var ft=class n extends u{constructor(t){super(t);this.data=t}txType=wo.TransactionType.Other;txSubType="OpenAndAddLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await fo(r,a,o)}static fromData(t){return new n(t)}};var Co=require("@msafe/sui3-utils");var gt=class n extends u{constructor(t){super(t);this.data=t}txType=Co.TransactionType.Other;txSubType="ClaimFeeAndMining";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await So(r,a,o)}static fromData(t){return new n(t)}};var Io=require("@msafe/sui3-utils");var ht=class n extends u{constructor(t){super(t);this.data=t}txType=Io.TransactionType.Other;txSubType="DecreaseLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await yo(r,a,o)}static fromData(t){return new n(t)}};var jo=require("@msafe/sui3-utils");var To=async(n,e,t)=>await P(t,e).Farms.openPositionAddLiquidityStakePaylod(n),ko=async(n,e,t)=>await P(t,e).Farms.addLiquidityFixCoinPayload(n),xo=async(n,e,t)=>await P(t,e).Farms.removeLiquidityPayload(n),vo=async(n,e,t)=>await P(t,e).Farms.removeLiquidityPayload(n),Ao=async(n,e,t)=>await P(t,e).Farms.claimFeeAndClmmReward(n),Oo=async(n,e,t)=>{let a=P(t,e);return console.log("getFarmingHarvest txbParams: ",n),await a.Farms.harvestPayload(n)},Po=async(n,e,t)=>{let a=P(t,e),o=Object.values(n);return console.log("getFarmingBatchHarvest params: ",o),await a.Farms.batchHarvestPayload(o)},Do=async(n,e,t)=>await P(t,e).Farms.depositPayload(n),_o=async(n,e,t)=>await P(t,e).Farms.withdrawPayload(n);var yt=class n extends u{constructor(t){super(t);this.data=t}txType=jo.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await To(r,a,o)}static fromData(t){return new n(t)}};var Bo=require("@msafe/sui3-utils");var St=class n extends u{constructor(t){super(t);this.data=t}txType=Bo.TransactionType.Other;txSubType="FarmingBatchHarvest";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Po(r,a,o)}static fromData(t){return new n(t)}};var Ro=require("@msafe/sui3-utils");var wt=class n extends u{constructor(t){super(t);this.data=t}txType=Ro.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Ao(r,a,o)}static fromData(t){return new n(t)}};var No=require("@msafe/sui3-utils");var Ct=class n extends u{constructor(t){super(t);this.data=t}txType=No.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await xo(r,a,o)}static fromData(t){return new n(t)}};var Eo=require("@msafe/sui3-utils");var It=class n extends u{constructor(t){super(t);this.data=t}txType=Eo.TransactionType.Other;txSubType="FarmingHarvest";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Oo(r,a,o)}static fromData(t){return new n(t)}};var Mo=require("@msafe/sui3-utils");var Tt=class n extends u{constructor(t){super(t);this.data=t}txType=Mo.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await ko(r,a,o)}static fromData(t){return new n(t)}};var Lo=require("@msafe/sui3-utils");var kt=class n extends u{constructor(t){super(t);this.data=t}txType=Lo.TransactionType.Other;txSubType="FarmingRemoveLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await vo(r,a,o)}static fromData(t){return new n(t)}};var Wo=require("@msafe/sui3-utils");var xt=class n extends u{constructor(t){super(t);this.data=t}txType=Wo.TransactionType.Other;txSubType="FarmingStake";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Do(r,a,o)}static fromData(t){return new n(t)}};var Fo=require("@msafe/sui3-utils");var vt=class n extends u{constructor(t){super(t);this.data=t}txType=Fo.TransactionType.Other;txSubType="FarmingUnstake";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await _o(r,a,o)}static fromData(t){return new n(t)}};var Uo=require("@msafe/sui3-utils");var At=class n extends u{constructor(t){super(t);this.data=t}txType=Uo.TransactionType.Other;txSubType="IncreaseLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await go(r,a,o)}static fromData(t){return new n(t)}};var qo=require("@msafe/sui3-utils");var Ot=class n extends u{constructor(t){super(t);this.data=t}txType=qo.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await ho(r,a,o)}static fromData(t){return new n(t)}};var Ho=require("@msafe/sui3-utils");var $o=async(n,e,t)=>await P(t,e).XCetusModule.convertPayload(n),Qo=async(n,e,t)=>await P(t,e).XCetusModule.redeemLockPayload(n),Vo=async(n,e,t)=>await P(t,e).XCetusModule.redeemDividendV2Payload(n.venft_id,n.bonus_types,n.xTokenType),Go=async(n,e,t)=>await P(t,e).XCetusModule.cancelRedeemPayload(n),Ko=async(n,e,t)=>await P(t,e).XCetusModule.redeemPayload(n);var Pt=class n extends u{constructor(t){super(t);this.data=t}txType=Ho.TransactionType.Other;txSubType="xCETUSCancelRedeem";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Go(r,a,o)}static fromData(t){return new n(t)}};var zo=require("@msafe/sui3-utils");var Dt=class n extends u{constructor(t){super(t);this.data=t}txType=zo.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Vo(r,a,o)}static fromData(t){return new n(t)}};var Jo=require("@msafe/sui3-utils");var _t=class n extends u{constructor(t){super(t);this.data=t}txType=Jo.TransactionType.Other;txSubType="xCETUSConvert";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await $o(r,a,o)}static fromData(t){return new n(t)}};var Xo=require("@msafe/sui3-utils");var jt=class n extends u{constructor(t){super(t);this.data=t}txType=Xo.TransactionType.Other;txSubType="xCETUSRedeem";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Ko(r,a,o)}static fromData(t){return new n(t)}};var Yo=require("@msafe/sui3-utils");var Bt=class n extends u{constructor(t){super(t);this.data=t}txType=Yo.TransactionType.Other;txSubType="xCETUSRedeemLock";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Qo(r,a,o)}static fromData(t){return new n(t)}};var Rt=class{application="cetus";async deserialize(e){console.log("Cetus helper deserialize input: ",e);let{txbParams:t,action:a}=e;return{txType:Zo.TransactionType.Other,txSubType:a,intentionData:{txbParams:{...t},action:a}}}async build(e){let{suiClient:t,account:a,network:o}=e;console.log("helper build input: ",e),console.log("helper build input.intentionData: ",e.intentionData),console.log("helper build input.intentionData JSON: ",JSON.stringify(e.intentionData));let r;switch(e.txSubType){case"OpenAndAddLiquidity":r=ft.fromData(e.intentionData);break;case"IncreaseLiquidity":r=At.fromData(e.intentionData);break;case"DecreaseLiquidity":r=ht.fromData(e.intentionData);break;case"RemoveLiquidity":r=Ot.fromData(e.intentionData);break;case"ClaimFeeAndMining":r=gt.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":r=yt.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":r=Tt.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":r=Ct.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":r=kt.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":r=wt.fromData(e.intentionData);break;case"FarmingHarvest":r=It.fromData(e.intentionData);break;case"FarmingBatchHarvest":r=St.fromData(e.intentionData);break;case"FarmingStake":r=xt.fromData(e.intentionData);break;case"FarmingUnstake":r=vt.fromData(e.intentionData);break;case"xCETUSConvert":r=_t.fromData(e.intentionData);break;case"xCETUSRedeemLock":r=Bt.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":r=Dt.fromData(e.intentionData);break;case"xCETUSCancelRedeem":r=Pt.fromData(e.intentionData);break;case"xCETUSRedeem":r=jt.fromData(e.intentionData);break;default:throw new Error("not implemented")}return console.log("helper build intention: ",r),console.log("helper build account: ",a),console.log("helper build network: ",o),r.build({suiClient:t,account:a,network:o})}};var Ir=require("@msafe/sui3-utils");var In={};Cn(In,{contractId:()=>rs,default:()=>ls,feeObjId:()=>cs,roleObjId:()=>is,status:()=>os,transaction:()=>ns,upgradeCapObjId:()=>ds,vaultObjId:()=>ss});var ns="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",os="success",rs="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",is="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",ss="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",cs="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",ds="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",ls={transaction:ns,status:os,contractId:rs,roleObjId:is,vaultObjId:ss,feeObjId:cs,upgradeCapObjId:ds};var Tn={};Cn(Tn,{contractId:()=>ms,default:()=>ys,feeObjId:()=>gs,roleObjId:()=>bs,status:()=>ps,transaction:()=>us,upgradeCapObjId:()=>hs,vaultObjId:()=>fs});var us="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",ps="success",ms="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",bs="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",fs="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",gs="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",hs="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",ys={transaction:us,status:ps,contractId:ms,roleObjId:bs,vaultObjId:fs,feeObjId:gs,upgradeCapObjId:hs};var Ss="https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD",ws="https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD",Cs="https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7",Is="https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7",Ts="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",ks="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",xs="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",vs="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",er=In,tr=Tn,As=new Map([["dev",{env:"dev",rpc:{url:Ss},backend:{url:Ts},contract:er}],["stg",{env:"stg",rpc:{url:ws},backend:{url:ks},contract:er}],["prev",{env:"prev",rpc:{url:Cs},backend:{url:xs},contract:tr}],["prod",{env:"prod",rpc:{url:Is},backend:{url:vs},contract:tr}]]);function ar(n,e){let t=As.get(n);if(!t)throw new Error(`Env not supported: ${n}`);return e&&e.rpc&&(t.rpc=e.rpc),e&&e.backend&&(t.backend=e.backend),e&&e.contract&&(t.contract=e.contract),t}var nr=require("@mysten/sui.js/client");var S=class extends Error{mpayErrorCode;context;constructor(e,t,a={}){let{cause:o,context:r}=a;o?super(`[MPay] ${t}: ${o}`):super(`[MPay] ${t}`),this.mpayErrorCode=e,this.context=r}};var Nt=class extends S{constructor(){super(11,"Backend is not specified")}};var Et=class extends S{constructor(){super(1,"Wallet not connected")}};var G=q(require("axios"));var Te=class extends S{constructor(e,t){super(10,e,{context:t})}};var Mt=class n{constructor(e){this.apiURL=e}static parseResponseData(e){if(e instanceof G.AxiosError)throw new Te(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new Te(e.data.code)}throw new Te(e.status.toString())}async getIncomingStreams(e,t){let a=await G.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return n.parseResponseData(a)}async getOutgoingStreams(e,t){let a=await G.default.post(`${this.apiURL}/stream`,{sender:e,...t});return n.parseResponseData(a)}async getStreamHistory(e){let t=await G.default.post(`${this.apiURL}/stream-events`,e),a=n.parseResponseData(t);return a.data.forEach(o=>{let r=o;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}),a}async getAllCoinTypes(e){let t=await G.default.post(`${this.apiURL}/stream-info`,{address:e});return n.parseResponseData(t)}async getAllRecipients(e,t){let a=await G.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return n.parseResponseData(a)}async getAllSenders(e,t){let a=await G.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return n.parseResponseData(a)}};var ke=class n{signer;suiClient;envConfig;_backend;constructor(e){this.envConfig=e,this.suiClient=new nr.SuiClient({url:e.rpc.url}),e.backend&&(this._backend=new Mt(e.backend.url))}static new(e,t){let a=ar(e,t);return new n(a)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new Nt;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 Et;return this.signer}async walletAddress(){return this.wallet.address()}};var he=require("@mysten/sui.js/utils");var Ge=require("@mysten/sui.js/transactions");var On=require("@mysten/sui.js/transactions"),Ve=require("@mysten/sui.js/utils");var kn=50n,Lt=10000n,or=25n,xn=100000000n;var $=class{constructor(e){this.object=e}moveArg(e){return e.object(this.object)}},Ue=class{constructor(e){this.objects=e}moveArgs(e){return e.makeMoveVec({objects:this.objects.map(t=>e.object(t))})}},te=class n{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,a){if(a in t)return Reflect.get(t,a);let o=i=>new n(t.result[i]);if(a===Symbol.iterator)return function*(){let i=0;for(;;)yield o(i),i++};if(typeof a=="symbol")return;let r=parseInt(a,10);if(!(Number.isNaN(r)||r<0))return o(r)}})}moveArg(){return this.result}};var vn=require("buffer"),rr=require("@mysten/sui.js/utils");var qe=class extends S{constructor(e,t){super(3,e,{context:t})}};var Wt=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 a=this.callResult(e);return this.returnValue(a,t)}getAddress(e=0,t=0){let[a,o]=this.getValue(e,t);if(o!=="address")throw new qe("Invalid contract return type.",{ctx:{expectType:"address",gotType:o}});return(0,rr.normalizeSuiAddress)(vn.Buffer.from(a).toString("hex"))}getU64(e=0,t=0){let[a,o]=this.getValue(e,t);if(o!=="u64")throw new qe("Invalid contract return type.",{ctx:{expectType:"u64",gotType:o}});return vn.Buffer.from(a).readBigInt64LE()}};var An=require("@mysten/sui.js/bcs");var x=class extends S{constructor(e,t,a){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:a}})}};var sr={groupId:"string",name:"string"},Os=64;function cr(n){return dr(n),An.bcs.ser(sr,n).toString("base64")}function $e(n){let e=An.bcs.de(sr,n,"base64");return dr(e),e}function dr(n){if(!ir(n.name))throw new x("Invalid metadata: Name contains unknown character");if(!ir(n.groupId))throw new x("Invalid metadata: Group ID contains unknown character");if(n.name.length>Os)throw new x("Invalid metadata: Name exceed max length 64")}function ir(n){return/^[\x00-\x7F]+$/.test(n)}var Qe=require("@mysten/sui.js/utils");function Ft(n,e){return(0,Qe.normalizeStructTag)(n)===(0,Qe.normalizeStructTag)(e)}function ae(n,e){return(0,Qe.normalizeStructTag)(n)===(0,Qe.normalizeStructTag)(e)}var Ut="txn.gas";var lr=require("nanoid");function ur(){return(0,lr.nanoid)()}var ge=class n{constructor(e,t,a){this.globals=e;this.feeContract=t;this.streamContract=a}static convertCreateStreamInfoToInternal(e){return{metadata:cr({name:e.name,groupId:ur()}),coinType:(0,Ve.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 On.TransactionBlock,a=this.calculateFeesInternal(e),o=this.getCreateStreamCoinRequests(e,a),r=await this.wallet.requestCoins(o),i=await this.addMergeCoins(t,r[0]),s;o.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),p=this.getStreamFeeLocal(d),[m]=t.splitCoins(i,[t.pure(d+p,"u64")]),[b]=t.splitCoins(s,[t.pure(this.flatSuiFee,"u64")]);this.streamContract.createStream(t,{paymentCoin:new te(m),flatFeeCoin:new te(b),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=n.convertCreateStreamInfoToInternal(e);return this.calculateFeesInternal(t)}feeParams(){return{createFeePercent:{numerator:kn,denominator:Lt},claimFeePercent:{numerator:or,denominator:Lt},flatFeePerStream:xn}}async addMergeCoins(e,t){let a;return t.mergedCoins&&t.mergedCoins.length?(e.mergeCoins(e.object(t.primaryCoin),t.mergedCoins.map(o=>e.object(o))),a=e.object(t.primaryCoin)):t.primaryCoin===Ut?a=e.gas:a=e.object(t.primaryCoin),a}getCreateStreamCoinRequests(e,t){let a=e.coinType;return Ft(a,Ve.SUI_TYPE_ARG)?[{coinType:a,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:a,amount:t.totalAmount+t.streamFeeAmount},{coinType:Ve.SUI_TYPE_ARG,amount:t.flatFeeAmount}]}calculateFeesInternal(e){let t=e.recipients.reduce((o,r)=>{let i=this.amountForRecipient(r,e.numberEpoch),s=this.getStreamFeeLocal(i);return{totalAmount:o.totalAmount+i,streamFeeAmount:o.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 xn}getStreamFeeLocal(e){return e*kn/Lt}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new On.TransactionBlock,e),a=await this.globals.suiClient.devInspectTransactionBlock({sender:await this.globals.walletAddress(),transactionBlock:t});return new Wt(a).getU64()}get wallet(){return this.globals.wallet}};var Pn=require("@mysten/sui.js/transactions");var pr="0x0000000000000000000000000000000000000000000000000000000000000006";var xe=class{constructor(e,t,a){this.moduleName=e;this.config=t;this.globals=a}addContractCall(e,t){let a=`${this.config.contractId}::${this.moduleName}::${t.method}`;return e.add(Pn.Transactions.MoveCall({target:a,arguments:t.arguments.map(o=>o instanceof Ue?o.moveArgs(e):o instanceof $?o.moveArg(e):o instanceof te?o.moveArg():e.pure(o)),typeArguments:t.typeArgs})),e}addTransactionBlock(e,t,a=[],o=[]){e.add(Pn.Transactions.MoveCall({target:t,arguments:a.map(r=>r instanceof Ue?r.moveArgs(e):r instanceof $?r.moveArg(e):r instanceof te?r.moveArg():e.pure(r)),typeArguments:o}))}makeObject(e){return typeof e=="string"?new $(e):e}vaultObject(){return new $(this.config.vaultObjId)}roleObject(){return new $(this.config.roleObjId)}feeObject(){return new $(this.config.feeObjId)}clockObject(){return new $(pr)}};var ve=class n extends xe{constructor(t,a){super(n.ModuleName,t,a);this.config=t;this.globals=a}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,a){let o=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:n.MethodName.set_streaming_fee,arguments:[o,r,a],typeArgs:[]})}setStreamingFlatFee(t,a){let o=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:n.MethodName.set_streaming_flat_fee,arguments:[o,r,a],typeArgs:[]})}setClaimFee(t,a){let o=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:n.MethodName.set_claim_fee,arguments:[o,r,a],typeArgs:[]})}streamingFee(t,a){let o=this.feeObject();return this.addContractCall(t,{method:n.MethodName.streaming_fee,arguments:[o,a],typeArgs:[]})}claimFee(t,a){return this.addContractCall(t,{method:n.MethodName.claim_fee,arguments:[this.feeObject(),a],typeArgs:[]})}feeDenominator(t){return this.addContractCall(t,{method:n.MethodName.fee_denominator,arguments:[this.feeObject()],typeArgs:[]})}};var Q=class n extends xe{constructor(t,a){super(n.ModuleName,t,a);this.config=t;this.globals=a}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,a){let o=this.feeObject(),r=this.vaultObject(),i=this.makeObject(a.paymentCoin),s=this.makeObject(a.flatFeeCoin),c=this.clockObject();return this.addContractCall(t,{method:n.MethodName.create_stream,arguments:[o,r,i,s,a.metadata,a.recipient,a.timeStart,a.cliff,a.epochInterval,a.numEpoch,a.amountPerEpoch,a.cancelable,c],typeArgs:[a.coinType]})}setAutoClaim(t,a){let o=this.makeObject(a.streamId);return this.addContractCall(t,{method:n.MethodName.set_auto_claim,arguments:[o,a.enabled],typeArgs:[a.coinType]})}cancelStream(t,a){let o=this.makeObject(a.streamId),r=this.clockObject();return this.addContractCall(t,{method:n.MethodName.cancel_stream,arguments:[o,r],typeArgs:[a.coinType]})}claimStream(t,a){let o=this.makeObject(a.streamId),r=this.clockObject();return this.addContractCall(t,{method:n.MethodName.claim_stream,arguments:[o,r],typeArgs:[a.coinType]})}claimStreamByProxy(t,a){let o=this.makeObject(a.streamId),r=this.vaultObject(),i=this.feeObject(),s=this.clockObject();return this.addContractCall(t,{method:n.MethodName.claim_stream_by_proxy,arguments:[o,r,i,s],typeArgs:[a.coinType]})}get createStreamTarget(){return`${this.config.contractId}::${n.ModuleName}::${n.MethodName.create_stream}`}get setAutoClaimTarget(){return`${this.config.contractId}::${n.ModuleName}::${n.MethodName.set_auto_claim}`}get cancelStreamTarget(){return`${this.config.contractId}::${n.ModuleName}::${n.MethodName.cancel_stream}`}get claimStreamTarget(){return`${this.config.contractId}::${n.ModuleName}::${n.MethodName.claim_stream}`}get claimStreamByProxyTarget(){return`${this.config.contractId}::${n.ModuleName}::${n.MethodName.claim_stream_by_proxy}`}};var Ae=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new ve(t,e),this.streamContract=new Q(t,e)}feeContract;streamContract;async createStreams(e){let t=ge.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new ge(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,a){let o=new Ge.TransactionBlock;return this.streamContract.setAutoClaim(o,{streamId:e,enabled:t,coinType:a})}claimStream(e,t){let a=new Ge.TransactionBlock;return this.streamContract.claimStream(a,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let a=new Ge.TransactionBlock;return this.streamContract.claimStreamByProxy(a,{streamId:e,coinType:t})}cancelStream(e,t){let a=new Ge.TransactionBlock;return this.streamContract.cancelStream(a,{streamId:e,coinType:t}),a}};var O=class extends S{constructor(e,t={}){super(0,e,t)}};async function _n(n){let e=[];for(;await n.hasNext();){let t=await n.next();e.push(t)}return e&&Array.isArray(e[0])?e.flat(1):e}var Dn=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)}},Oe=class{constructor(e){this.requester=e;this.pager=new Dn(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 qt=class extends S{constructor(t,a,o){super(4,`Not enough balance: ${t}`,{context:{coinType:t,requestAmount:a,gotAmount:o}});this.coinType=t;this.requestAmount=a;this.gotAmount=o}};var Ps=25;async function mr(n,e,t,a="0x2::sui::SUI",o=Ps){let r=new jn(n,e,a,o),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 qt(a,t,i);return s}var jn=class extends Oe{constructor(t,a,o,r){super(new Bn(t,a,o,r));this.suiClient=t;this.owner=a;this.coinType=o;this.reqPageSize=r}},Bn=class{constructor(e,t,a,o){this.suiClient=e;this.owner=t;this.coinType=a;this.reqPageSize=o;if(o<=0)throw new O("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 ze=require("@mysten/sui.js/transactions"),Je=require("@mysten/sui.js/utils"),fr=require("luxon");var $t=class extends S{constructor(){super(7,"Connected wallet is not creator")}};var Ke=class extends S{constructor(){super(8,"Connected wallet is not recipient")}};var He=class extends S{constructor(e,t){super(6,e,{context:t})}};var Qt=class extends S{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var Gt=require("luxon"),br=(1n<<64n)-1n,Vt=1e3;function Rn(n){let e;typeof n=="number"?e=n:typeof n=="bigint"?e=Number(n):e=n.toMillis();let t=Math.round(e/Vt);return Gt.DateTime.fromMillis(t*Vt)}function Nn(n){let e;typeof n=="number"?e=n:typeof n=="bigint"?e=Number(n):e=n.toMillis();let t=Math.round(e/Vt);return Gt.Duration.fromMillis(t*Vt)}var ne=class n{constructor(e,t,a){this.globals=e;this.streamId=t;this.rawData=a;this.streamContract=new Q(e.envConfig.contract,e)}streamContract;type="Stream";static async new(e,t){let a=await n.fetchStreamData(e,t);return new n(e,t,a)}static fromObjectData(e,t,a){let o=n.parseRawStreamData(t,a);return new n(e,t,o)}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 n.fetchStreamData(this.globals,this.streamId)}refreshWithData(e){if(e.data?.objectId!==this.streamId)throw new O("Object Id does not align");this.rawData=n.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 $t;let e=new ze.TransactionBlock;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new Ke;let e=new ze.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 Ke;let t=new ze.TransactionBlock;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new ze.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,Je.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 Nn(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return $e(e).groupId}get name(){let{metadata:e}=this.rawData.config;return $e(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return Rn(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return Nn(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:Rn((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===br?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=fr.DateTime.now().toMillis(),t=this.timeStart.toMillis();if(e<t)return-1n;let a=Math.floor((e-t)/Number(this.rawData.config.epochInterval));return BigInt(a)>Number(this.rawData.config.totalEpoch)?this.rawData.config.totalEpoch:BigInt(a)}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 a=await e.suiClient.getObject({id:t,options:{showContent:!0,showType:!0}});return n.parseRawStreamData(t,a)}static parseRawStreamData(e,t){if(t.error)throw t.error.code==="notExists"?new Qt(e):new He(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let a=t.data.content;if(a.dataType!=="moveObject")throw new He("Unexpected object type",{gotType:a.dataType});let{typeParams:o}=(0,Je.parseStructTag)(a.type),r=(0,Je.normalizeStructTag)(o[0]),i=a.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 Pe=require("@mysten/sui.js/utils"),En=require("luxon");var Kt=class extends S{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var Ds=1e3,Ht=class{constructor(e){this.globals=e;this.coinMetaHelper=new Mn(e.suiClient),this.createStreamHelper=new Ae(e).createStreamHelper()}coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new Kt(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 x("Invalid stream steps: 0");let t=e.cliff?e.cliff:{numerator:0n,denominator:100n},a=e.totalAmount*t.numerator/t.denominator,o=(e.totalAmount-a)/e.steps,i={realTotalAmount:o*e.steps+a,cliffAmount:a,amountPerStep:o};return this.validateStreamAmount(i,e.totalAmount),i}calculateTimelineByInterval(e){if(e.steps===0n)throw new x("Invalid stream steps: 0");let t=e.timeStart.plus(e.interval.toMillis()*Number(e.steps)),a={timeStart:e.timeStart,timeEnd:t,interval:e.interval,steps:e.steps};return this.validateTimeline(a),a}calculateTimelineByTotalDuration(e){if(e.steps===0n)throw new x("Invalid stream steps: 0");let t=BigInt(e.total.toMillis())/e.steps,a=e.timeStart.plus(En.Duration.fromMillis(Number(t*e.steps))),o={timeStart:e.timeStart,timeEnd:a,interval:En.Duration.fromMillis(Number(t)),steps:e.steps};return this.validateTimeline(o),o}async getBalance(e,t){let a=await this.globals.suiClient.getBalance({owner:e,coinType:t}),o=await this.getCoinMeta(t);return{...a,coinType:(0,Pe.normalizeStructTag)(a.coinType),coinMeta:o}}async getAllBalance(e){let t=await this.globals.suiClient.getAllBalances({owner:e}),a=await Promise.all(t.map(o=>this.getCoinMeta(o.coinType)));return t.map((o,r)=>({...o,coinType:(0,Pe.normalizeStructTag)(o.coinType),coinMeta:a[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 x("Stream amount too small","totalAmount",t);if(e.cliffAmount>e.realTotalAmount)throw new x("Invalid cliff settings")}validateTimeline(e){if(e.interval.toMillis()<Ds)throw new x("Interval shall be at least 1 second","interval",e.interval)}},Mn=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}coinMetaReg;async getCoinMeta(e){let t=(0,Pe.normalizeStructTag)(e||Pe.SUI_TYPE_ARG);if(this.coinMetaReg.has(t))return this.coinMetaReg.get(t);let a=await this.queryCoinMeta(t);return a&&this.coinMetaReg.set(t,a),a}async queryCoinMeta(e){return await this.suiClient.getCoinMetadata({coinType:e})||void 0}};var oe=require("@mysten/sui.js/utils"),Fn=require("luxon");var De=class extends S{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};var _s=25;async function Wn(n,e,t){let a=new Xe(e),o=new Ye(n,a,t);return await _n(o)}var Xe=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]}},Ye=class extends Oe{constructor(t,a,o){super(new Ln(t,a,o));this.suiClient=t;this.idIter=a;this.options=o}},Ln=class{constructor(e,t,a){this.suiClient=e;this.stringIter=t;this.options=a;this.filter=a?.filter,this.pageSize=a?.pageSize||_s,this.objectOptions=a?.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}),a;if(this.filter){let{filter:o}=this;a=t.filter(r=>o?.(r))}else a=t;return{data:a,hasNext:await this.stringIter.hasNext()}}};var zt=class n{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new De("stream size 0");let a=t.map(r=>r.groupId);if(new Set(a).size!==1)throw new x("Stream does not have same group ID")}type="StreamGroup";static async new(e,t){let a=await Wn(e.suiClient,t);return a.forEach(o=>{if(!o)throw new O("stream group object data undefined")}),n.newFromObjectResponse(e,t,a)}static async newFromObjectResponse(e,t,a){let o=await n.parseGroupStreams(e,t,a);return new n(e,o)}static checkStreamGroup(e){let t=e.map(r=>r.groupCommonInfo),a=t[0],o=!0;return t.forEach(r=>{js(a,r)||(o=!1)}),o}async refresh(){let e=await Wn(this.globals.suiClient,this.streams.map(t=>t.streamId));this.streams.forEach((t,a)=>{t.refreshWithData(e[a])})}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,a){let o=a.map((r,i)=>ne.fromObjectData(e,t[i],r)).filter(r=>!!r);if(new Set(o.map(r=>r.groupId)).size!==1)throw new De("Not same group ID");if(!this.checkStreamGroup(o))throw new De("Not same stream settings");return o}};function js(n,e){return n.name===e.name&&n.groupId===e.groupId&&n.creator===e.creator&&n.start.toMillis()===e.start.toMillis()&&n.interval.toMillis()===e.interval.toMillis()&&n.steps===e.steps&&n.cancelable===e.cancelable}var Ze=class n{constructor(e,t){this.it=e;this.pageSize=t}static async newIncoming(e){let t=await Jt.newIncoming(e);return new n(t,e.pageSize)}static async newOutgoing(e){let t=await Jt.newOutgoing(e);return new n(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}},Jt=class n{constructor(e){this.requester=e}cachedNext;static async newIncoming(e){let t=await Xt.newIncomingQuery(e);return new n(t)}static async newOutgoing(e){let t=await Xt.newOutgoingQuery(e);return new n(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 O("No more results");return t}let e=this.cachedNext;if(this.cachedNext=void 0,e===null)throw new O("No more results");return e}},Xt=class n{constructor(e,t,a,o){this.globals=e;this.recipient=t;this.groupRefs=a;this.query=o;this.current=0;let r=new Xe(a.flat().map(i=>i.streamId));this.objectIter=new Ye(e.suiClient,r)}current=0;objectIter;static async newIncomingQuery(e){let t=Ms(e.query),a=await e.globals.walletAddress(),r=(await e.globals.backend.getIncomingStreams(a,t)).filter(s=>(0,oe.normalizeSuiAddress)(s.recipient)===(0,oe.normalizeSuiAddress)(a)),i=gr(r);return new n(e.globals,a,i,e.query)}static async newOutgoingQuery(e){let t=Ls(e.query),a=await e.globals.walletAddress(),o=await e.globals.backend.getOutgoingStreams(a,t),r=gr(o);return new n(e.globals,a,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 Ns(this.globals,e[0].streamId,this.objectIter);return this.current++,hr(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await Es(this.globals,e.map(a=>a.streamId),this.objectIter);return this.current++,Rs(t,this.query)?t:this.doNextRequest()}throw new O("Stream group with no stream")}};function gr(n){let e=new Map;return n.forEach(t=>{let a=e.get(t.groupId);a?(a.push(t),e.set(t.groupId,a)):e.set(t.groupId,[t])}),Array.from(e.values()).sort((t,a)=>Fn.DateTime.fromISO(a[0].createDate).toMillis()-Fn.DateTime.fromISO(t[0].createDate).toMillis())}function hr(n,e){if(e===void 0)return!0;let t=Bs(n,e.status);if(e&&"claimable"in e&&e.claimable!==void 0){let a=e.claimable?n.progress.claimable!==0n:n.progress.claimable===0n;return t&&a}return t}function Bs(n,e){return e===void 0?!0:Array.isArray(e)?e.includes(n.progress.status):n.progress.status===e}function Rs(n,e){if(!e)return!0;let t=!1;return n.streams.forEach(a=>{hr(a,e)&&(t=!0)}),t}async function Ns(n,e,t){let a=await yr(t,e);return ne.fromObjectData(n,e,a)}async function Es(n,e,t){let a=[];for(;a.length<e.length;){let o=await yr(t,e[a.length]);a.push(o)}return zt.newFromObjectResponse(n,e,a)}async function yr(n,e){if(!await n.hasNext())throw new O("object iterator has been consumed");let t=await n.next();if(!t||t.error||t.data===void 0||t.data===null)throw new O("object iterator undefined response",{cause:t?.error});if(t?.data?.objectId!==e)throw new O("stream id not aligned");return t}function Ms(n){return{status:Un(n?.status),coinType:Sr(n?.coinType),sender:wr(n?.sender)}}function Ls(n){return{status:Un(n?.status),coinType:Sr(n?.coinType),recipient:wr(n?.recipient)}}function Un(n){return n===void 0||n.length===0?"all":Array.isArray(n)?n.reduce((e,t)=>{let a=Un(t);return!e||e===a?a:"all"},void 0):Ws(n)}function Ws(n){switch(n){case"STREAMING":case"STREAMED":case"CANCELED":return"active";case"COMPLETED":case"SETTLED":return"inactive";default:throw new x("Unknown stream filtered status")}}function Sr(n){if(n)return Array.isArray(n)?n.length!==0?n.map(e=>(0,oe.normalizeStructTag)(e)):void 0:(0,oe.normalizeStructTag)(n)}function wr(n){if(n)return Array.isArray(n)?n.length!==0?n.map(e=>(0,oe.normalizeSuiAddress)(e)):void 0:(0,oe.normalizeSuiAddress)(n)}var qn=class{constructor(e){this.msafe=e}get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},Yt=class{constructor(e){this.account=e}async address(){return this.account.address}},$n=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(Ft(e.coinType,he.SUI_TYPE_ARG))return{primaryCoin:Ut};if(e.amount<=0)throw new x("Invalid coin request","coinAmount",e.amount);let t=await mr(this.suiClient,await this.address(),e.amount,e.coinType);if(t.length===0)throw new O("no coins available");return{primaryCoin:t[0].coinObjectId,mergedCoins:t.slice(1).map(a=>a.coinObjectId)}}},Zt=class{globals;helper;constructor(e,t){this.globals=ke.new(e,t),this.helper=new Ht(this.globals)}connectSingleWallet(e){let t=new $n(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new qn(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return ne.new(this.globals,e)}async getIncomingStreams(e,t=10){return Ze.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return Ze.newOutgoing({globals:this.globals,query:e,pageSize:t})}async getCoinTypesForStreamFilter(){let e=await this.wallet.address();return(await this.globals.backend.getAllCoinTypes(e)).map(a=>(0,he.normalizeStructTag)(a))}async getRecipientsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllRecipients(t,e)).map(o=>(0,he.normalizeSuiAddress)(o))}async getCreatorsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllSenders(t,e)).map(o=>(0,he.normalizeSuiAddress)(o))}get wallet(){return this.globals.wallet}builder(){return new Ae(this.globals)}};var Cr=q(require("sort-keys-recursive")),ea=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Cr.default)(this.data))}};var N=class extends ea{application="mpay";getClient(e,t){let a=new Zt(e==="sui:mainnet"?"prod":"dev");return a.connectSingleWallet(new Yt(t)),a}};var et=class extends N{constructor(t){super(t);this.data=t}txType=Ir.TransactionType.Stream;txSubType="Cancel";async build(t){let{network:a,account:o}=t;return(await this.getClient(a,o).getStream(this.data.streamId)).cancel()}};var Tr=require("@msafe/sui3-utils");var tt=class extends N{constructor(t){super(t);this.data=t}txType=Tr.TransactionType.Stream;txSubType="ClaimByProxy";async build(t){let{network:a,account:o}=t;return(await this.getClient(a,o).getStream(this.data.streamId)).claimByProxy()}};var kr=require("@msafe/sui3-utils");var at=class extends N{constructor(t){super(t);this.data=t}txType=kr.TransactionType.Stream;txSubType="Claim";async build(t){let{network:a,account:o}=t;return(await this.getClient(a,o).getStream(this.data.streamId)).claim()}};var xr=require("@msafe/sui3-utils");var nt=class extends N{constructor(t){super(t);this.data=t}txType=xr.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:a,account:o}=t;return this.getClient(a,o).createStream(this.data)}};var Qn=require("@mysten/sui.js/bcs"),re=require("@mysten/sui.js/utils"),_e=class n{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return n.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return n.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return BigInt(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,re.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let a=this.getInputParam(e);return n.getPureInputValue(a,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 a=e.value.Pure;return Qn.bcs.de(t,new Uint8Array(a))}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,re.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,re.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,re.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,re.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 a=e.value.Pure;return Qn.bcs.de(t,new Uint8Array(a))}typeArg(e){return(0,re.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var ta=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(a=>this.getCreationInfoFromMoveCall(a));return this.aggregateGroupStreamInfo(t)}createStreamTransactions(){let e=this.transactions.filter(t=>t.kind==="MoveCall"&&ae(t.target,this.contract.createStreamTarget));if(e.length===0)throw new O("No create stream transactions");return e.map(t=>new _e(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:a,groupId:o}=$e(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),p=e.decodeInputBool(11),m=e.typeArg(0);return{name:a,groupId:o,recipient:r,timeStart:i,cliff:s,epochInterval:c,totalEpoch:l,amountPerEpoch:d,cancelable:p,coinType:m}}aggregateGroupStreamInfo(e){if(new Set(e.map(o=>JSON.stringify({name:o.name,groupId:o.groupId,timeStart:String(o.timeStart),epochInterval:String(o.epochInterval),totalEpoch:String(o.totalEpoch),cancelable:o.cancelable,coinType:o.coinType}))).size!==1)throw new x("Stream group not have common info");let a=e.map(o=>({address:o.recipient,amountPerStep:o.amountPerEpoch,cliffAmount:o.cliff}));return{name:e[0].name,coinType:e[0].coinType,recipients:a,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 Q(this.globals.envConfig.contract,this.globals)}get feeContract(){return new ve(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new ge(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 aa=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new Q(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"&&ae(t.target,this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ae(this.transactions[0].target,this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ae(this.transactions[0].target,this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ae(this.transactions[0].target,this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ae(this.transactions[0].target,this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new ta(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 _e(e,this.txb)}};var vr=require("@msafe/sui3-utils");var ot=class extends N{constructor(t){super(t);this.data=t}txType=vr.TransactionType.Stream;txSubType="SetAutoClaim";async build(t){let{network:a,account:o}=t;return(await this.getClient(a,o).getStream(this.data.streamId)).setAutoClaim(this.data.enabled)}};var na=class{application="mpay";async deserialize(e){let{network:t,transactionBlock:a}=e,o=ke.new(t==="sui:mainnet"?"prod":"dev"),i=new aa(o,a).decode(),s;switch(i.type){case"CreateStream":s=new nt(i.info);break;case"SetAutoClaim":s=new ot({streamId:i.streamId,enabled:i.enabled});break;case"Claim":s=new at({streamId:i.streamId});break;case"ClaimByProxy":s=new tt({streamId:i.streamId});break;case"Cancel":s=new et({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,a;switch(e.txSubType){case"CreateStream":a=new nt(t);break;case"Claim":a=new at(t);break;case"ClaimByProxy":a=new tt(t);break;case"SetAutoClaim":a=new ot(t);break;case"Cancel":a=new et(t);break;default:throw new Error("not implemented")}return a.build({...e})}};var je=require("@msafe/sui3-utils");var Ar=require("@msafe/sui3-utils");var oa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:a,account:o}=t;return(0,Ar.buildCoinTransferTxb)(a,this.data,o.address)}static fromData(t){return new n(t)}};var Or=require("@msafe/sui3-utils");var ra=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:a,account:o}=t;return(0,Or.buildObjectTransferTxb)(a,this.data,o.address)}static fromData(t){return new n(t)}};var Pr=require("@msafe/sui3-utils"),Dr=require("@mysten/sui.js/transactions");var ia=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:a}=t,o=Dr.TransactionBlock.from(this.data.content);if(!(0,Pr.isSameAddress)(o.blockData.sender,a.address))throw new Error("Invalid sender address");return o}static fromData(t){return new n(t)}};var sa=class{application;constructor(){this.application=je.TransactionDefaultApplication}deserialize(){throw new Error("MSafe core transaction intention should be build from API")}async build(e){let{suiClient:t,account:a}=e,o;switch(e.txSubType){case je.TransactionSubTypes.assets.coin.send:o=oa.fromData(e.intentionData);break;case je.TransactionSubTypes.assets.object.send:o=ra.fromData(e.intentionData);break;case je.TransactionSubTypes.others.plain:o=ia.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:a})}};var Ur=require("@msafe/sui3-utils");var _r=!1,jr={ProtocolPackage:"0xc6374c7da60746002bfee93014aeb607e023b2d6b25c9e55a152b826dbc8c1ce",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"},usdc:{name:"USDC",assetId:1,coinType:"usdc",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"}}};async function Vn(){if(!_r)try{let n=await fetch("https://open-api.naviprotocol.io/api/package").then(t=>t.json()),{packageId:e}=n;jr.ProtocolPackage=e,_r=!0}catch(n){console.error(n.message)}}var g=jr;var Be=require("@msafe/sui3-utils"),Gn=require("@mysten/sui.js/bcs"),ie=require("@mysten/sui.js/utils");var ca=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.isEntryDepositTransaction())return this.decodeEntryDeposit();if(this.isEntryRepayTransaction())return this.decodeEntryRepay();if(this.isEntryWithdrawTransaction())return this.decodeEntryWithdraw();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.getMoveCallTransaction(`${g.ProtocolPackage}::incentive_v2::claim_reward`)}isEntryBorrowTransaction(){return!!this.getMoveCallTransaction(`${g.ProtocolPackage}::incentive_v2::entry_borrow`)}isEntryDepositTransaction(){return!!this.getMoveCallTransaction(`${g.ProtocolPackage}::incentive_v2::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallTransaction(`${g.ProtocolPackage}::incentive_v2::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallTransaction(`${g.ProtocolPackage}::incentive_v2::entry_withdraw`)}findPoolByAssetId(e){let t=Object.values(g.pool).find(a=>a.assetId===e);if(!t)throw new Error("Pool not found");return t}decodeClaimReward(){let e=[];return this.transactions.forEach(t=>{if(t.kind==="MoveCall"&&t.target===`${g.ProtocolPackage}::incentive_v2::claim_reward`){let a=new da(t,this.txb),o=a.decodeInputU8(4),r=a.decodeInputU8(5),i=a.decodeSharedObjectId(2),s=this.findPoolByAssetId(o),c=[...t.typeArguments];e.push({coinType:s.coinType,option:r,typeArguments:c,assetId:o,poolId:i})}}),console.log("decode claims",e),{txType:Be.TransactionType.Other,type:"ClaimReward",intentionData:{claims:e}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5),a=this.findPoolByAssetId(e);return{txType:Be.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,coinType:a.coinType}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5),a=this.findPoolByAssetId(e);return{txType:Be.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,coinType:a.coinType}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6),a=this.findPoolByAssetId(e);return{txType:Be.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,coinType:a.coinType}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5),a=this.findPoolByAssetId(e);return{txType:Be.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,coinType:a.coinType}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(g.ProtocolPackage));return new da(e,this.txb)}},da=class n{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return n.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return n.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,ie.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let a=this.getInputParam(e);return n.getPureInputValue(a,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 a=e.value.Pure;return Gn.bcs.de(t,new Uint8Array(a))}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,ie.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,ie.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,ie.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,ie.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 a=e.value.Pure;return Gn.bcs.de(t,new Uint8Array(a))}typeArg(e){return(0,ie.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Er=require("@mysten/sui.js/transactions");function Kn(n,e,t,a){return n.moveCall({target:`${g.ProtocolPackage}::incentive_v2::entry_deposit`,arguments:[n.object("0x06"),n.object(g.StorageId),n.object(e.poolId),n.pure(e.assetId),t,n.pure(a),n.object(g.Incentive),n.object(g.IncentiveV2)],typeArguments:[e.type]}),n}function Br(n,e,t){return n.moveCall({target:`${g.ProtocolPackage}::incentive_v2::entry_withdraw`,arguments:[n.object("0x06"),n.object(g.PriceOracle),n.object(g.StorageId),n.object(e.poolId),n.pure(e.assetId),n.pure(t),n.object(g.Incentive),n.object(g.IncentiveV2)],typeArguments:[e.type]}),n}function Rr(n,e,t){return n.moveCall({target:`${g.ProtocolPackage}::incentive_v2::entry_borrow`,arguments:[n.object("0x06"),n.object(g.PriceOracle),n.object(g.StorageId),n.object(e.poolId),n.pure(e.assetId),n.pure(t),n.object(g.IncentiveV2)],typeArguments:[e.type]}),n}function Hn(n,e,t,a){return n.moveCall({target:`${g.ProtocolPackage}::incentive_v2::entry_repay`,arguments:[n.object("0x06"),n.object(g.PriceOracle),n.object(g.StorageId),n.object(e.poolId),n.pure(e.assetId),t,n.pure(a),n.object(g.IncentiveV2)],typeArguments:[e.type]}),n}function Nr(n,e,t,a,o){return n.moveCall({target:`${g.ProtocolPackage}::incentive_v2::claim_reward`,arguments:[n.object("0x06"),n.object(g.IncentiveV2),n.object(t),n.object(g.StorageId),n.pure(e),n.pure(a)],typeArguments:o}),n}var la=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let{claims:t}=this.data,a=new Er.TransactionBlock;return t.forEach(o=>{let{assetId:r,poolId:i,option:s,typeArguments:c}=o;Nr(a,r,i,s,c)}),a.setGasBudget(g.gasBudget),a}static fromData(t){return new n(t)}};var Mr=require("@mysten/sui.js/transactions");var ua=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let{coinType:t,amount:a}=this.data,o=new Mr.TransactionBlock;o.setGasBudget(g.gasBudget),console.log("build",this.data);let r=g.pool[t];if(!r)throw new Error(`${t} not support, please use ${Object.keys(g.pool).join(", ")}.`);return Rr(o,r,a)}static fromData(t){return new n(t)}};var Lr=require("@mysten/sui.js/transactions");async function pa(n,e,t){let a=await n.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,a),a}var ma=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:a,account:o}=t,{coinType:r,amount:i}=this.data,s=new Lr.TransactionBlock;if(s.setGasBudget(g.gasBudget),console.log("build",this.data),r==="sui"){let[p]=s.splitCoins(s.gas,[i]);return Kn(s,g.pool.sui,p,i)}let c=g.pool[r];if(!c)throw new Error(`${r} not support, please use ${Object.keys(g.pool).join(", ")}.`);let l=await pa(a,o.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 Kn(s,c,s.object(d),i)}static fromData(t){return new n(t)}};var Wr=require("@mysten/sui.js/transactions");var ba=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:a,account:o}=t,{coinType:r,amount:i}=this.data,s=new Wr.TransactionBlock;if(s.setGasBudget(g.gasBudget),console.log("build",this.data),r==="sui"){let[p]=s.splitCoins(s.gas,[i]);return Hn(s,g.pool.sui,p,i)}let c=g.pool[r];if(!c)throw new Error(`${r} not support, please use ${Object.keys(g.pool).join(", ")}.`);let l=await pa(a,o.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 Hn(s,c,s.object(d),i)}static fromData(t){return new n(t)}};var Fr=require("@mysten/sui.js/transactions");var fa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let{coinType:t,amount:a}=this.data,o=new Fr.TransactionBlock;console.log("build",this.data),o.setGasBudget(g.gasBudget);let r=g.pool[t];if(!r)throw new Error(`${t} not support, please use ${Object.keys(g.pool).join(", ")}.`);return Br(o,r,a)}static fromData(t){return new n(t)}};var ga=class{application="navi";async deserialize(e){await Vn();let{transactionBlock:t}=e,o=new ca(t).decode();return{txType:Ur.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:a}=e,o;switch(await Vn(),e.txSubType){case"EntryDeposit":o=ma.fromData(e.intentionData);break;case"EntryBorrow":o=ua.fromData(e.intentionData);break;case"EntryRepay":o=ba.fromData(e.intentionData);break;case"EntryWithdraw":o=fa.fromData(e.intentionData);break;case"ClaimReward":o=la.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:a})}};var ya=require("@msafe/sui3-utils"),qr=require("@mysten/sui.js/transactions"),Sa=require("@mysten/sui.js/utils"),qs=q(require("sort-keys-recursive")),$s="msafe-plain-tx",Qs=ya.TransactionSubTypes.others.plain;var ha=class{application;constructor(){this.application=$s}async deserialize(e){let{transactionBlock:t,suiClient:a}=e,o=await t.build({client:a});return{txType:ya.TransactionType.Other,txSubType:Qs,intentionData:{content:(0,Sa.toHEX)(o)}}}async build(e){let{suiClient:t,account:a}=e,o=qr.TransactionBlock.from((0,Sa.fromHEX)(e.intentionData.content)),r=await t.devInspectTransactionBlock({transactionBlock:o,sender:a.address});if(!(r.effects.status.status==="success"))throw new Error(r.effects.status.error);return o}};var wa=class{apps;constructor(e){this.apps=new Map(e.map(t=>[t.application,t]))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}};var Si=require("@msafe/sui3-utils");var v=require("@msafe/sui3-utils"),ka=require("@mysten/sui.js/bcs"),de=require("@mysten/sui.js/utils");var se="6601955b8b0024600a917079",Ca="0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";var Re="0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",ce="0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA",Se=["eth","btc","usdc","usdt","sui","apt","sol","cetus","afsui","hasui","vsui","sca"],Ia=["eth","btc","usdc","usdt","sui","apt","sol","cetus","afsui","hasui","vsui","sca"],rt=["seth","ssui","susdc","susdt","scetus","safsui","shasui","svsui"],$r=["sui"],Ne=["sui","usdc","usdt"];var Qr={eth:8,btc:8,usdc:6,usdt:6,sui:9,apt:8,sol:8,sca:9,cetus:9,afsui:9,hasui:9,vsui:9,seth:8,sbtc:8,susdc:6,susdt:6,ssui:9,sapt:8,ssol:8,scetus:9,safsui:9,shasui:9,svsui:9,ssca:9};var Ta={seth:"sui",ssui:"sui",susdc:"sui",susdt:"sui",scetus:"sui",safsui:"sui",shasui:"sui",svsui:"sui"},Vr={sui:["sui","sca"],usdc:["sui","sca"],usdt:["sui","sca"]},Gr={sui:"0x0000000000000000000000000000000000000000000000000000000000000002",eth:"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",btc:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",usdc:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",usdt:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",apt:"0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",sol:"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",cetus:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",afsui:"0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",hasui:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",vsui:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",sca:"0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6"},j={eth:"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",btc:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",usdc:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",usdt:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",apt:"0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",sol:"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8"},zn={vsui:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"};var xa=class{constructor(e,t){this.txb=e;this._builder=t}_builder;decode(){if(this.isExtendPeriodAndStakeMoreSca())return this.decodePeriodAndStakeMoreSca();if(this.isStakeScaFirsTime()||this.isStakeMoreSca())return this.decodeStakeSca();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.isWithdrawLendingTransaction())return this.decodeWithdrawLending();if(this.isSupplyLendingTransaction())return this.decodeSupplyLending();if(this.isBorrowWithBoostTransaction())return this.decodeBorrowWithBoost();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayTransaction())return this.decodeRepay();if(this.isUnstakeSpoolTransaction())return this.decodeUnstakeSpool();if(this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isRenewExpiredVeSca())return this.decodeRenewExpiredVeSca();if(this.isExtendPeriod())return this.decodeExtendStakePeriod();if(this.isOpenObligationTransaction())return this.decodeOpenObligation();if(this.isRedeemSca())return this.decodeRedeemSca();if(this.isMigrateAndClaim())return this.decodeMigrateAndClaim();throw new Error("Unknown transaction type")}get coreId(){return{protocolPkg:this._builder.address.get("core.packages.protocol.id"),market:this._builder.address.get("core.market"),version:this._builder.address.get("core.version"),coinDecimalsRegistry:this._builder.address.get("core.coinDecimalsRegistry"),xOracle:this._builder.address.get("core.oracles.xOracle"),spoolPkg:this._builder.address.get("spool.id"),borrowIncentivePkg:this._builder.address.get("borrowIncentive.id"),veScaPkgId:this._builder.address.get("vesca.id")}}get transactions(){return this.txb.blockData.transactions}get inputTransaction(){return this.txb.blockData.inputs}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isSupplyLendingTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::mint::mint`)}isSupplyWithStakeSpoolTransaction(){let e=this.getMoveCallTransaction(`${this.coreId.protocolPkg}::mint::mint`),t=this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::stake`);return!!e&&!!t}isUnstakeAndWithdrawTransaction(){let e=this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::unstake`),t=this.getMoveCallTransaction(`${this.coreId.protocolPkg}::redeem::redeem`);return!!e&&!!t}isStakeSpoolTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::stake`)}isWithdrawLendingTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::redeem::redeem`)}isDepositCollateralTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`)}isWithdrawCollateralTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`)}isBorrowTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::borrow::borrow`)}isBorrowWithBoostTransaction(){let e=this.getMoveCallTransaction(`${this.coreId.protocolPkg}::borrow::borrow`),t=this.getMoveCallTransaction(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`);return!!e&&!!t}isRepayTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::repay::repay`)}isUnstakeSpoolTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::unstake`)}isCreateStakeAccountTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::new_spool_account`)}isClaimRewardTransaction(){let e=this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::redeem_rewards`),t=this.getMoveCallTransaction(`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`);return!!e||!!t}isStakeScaFirsTime(){return!!this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`)}isExtendPeriodAndStakeMoreSca(){let e=this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`),t=this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`);return!!e&&!!t}isRedeemSca(){return!!this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::redeem`)}isStakeMoreSca(){return!!this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`)}isExtendPeriod(){return!!this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`)}isRenewExpiredVeSca(){return!!this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`)}isOpenObligationTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::open_obligation::open_obligation_entry`)}isMigrateAndClaim(){let e=this.getMoveCallTransaction(`${Re}::user::redeem_rewards`),t=this.getMoveCallTransaction(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`);return!!e&&!!t}decodeMigrateAndClaim(){let e=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),t=this.helperClaimBorrowReward[0].decodeSharedObjectId(2),a=this.helperClaimBorrowReward[0].decodeOwnedObjectId(3),o=this._builder.utils.parseCoinNameFromType(this.helperClaimBorrowReward[0].typeArg(0));return{txType:v.TransactionType.Other,type:"MigrateAndClaim",intentionData:{veScaKey:e,obligationKey:t,obligationId:a,rewardCoinName:o}}}decodeOpenObligation(){return{txType:v.TransactionType.Other,type:"OpenObligation",intentionData:{}}}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:v.TransactionType.Other,type:"RedeemSca",intentionData:{veScaKey:e}}}decodeRenewExpiredVeSca(){let e=this.helperRenewExpired.getNestedInputParam(4),t=this.helperRenewExpired.decodeInputU64(5),a=new E(e,this.txb).getAmountInput().reduce((f,y)=>f+y,0),o=this.helperRenewExpired.decodeOwnedObjectId(1),r=!!this.helperRedeemSca.moveCall,i=[],s=[],c=[];this.helperOldUnstakeObligation.moveCall&&(i=[this.helperOldUnstakeObligation.decodeSharedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(s=[this.helperUnstakeObligation.decodeSharedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(c=[this.helperStakeObligationWithVeSca.decodeSharedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let l=!1,d=!1,p,m,b=[{condition:i,isOld:!0},{condition:s,isOld:!1},{condition:c,isOld:!1}];for(let f=0;f<b.length;f++)b[f].condition.length>1&&([m,p]=b[f].condition,l=!0,d=b[f].isOld);return{txType:v.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:a,lockPeriodInDays:t,obligationId:p,obligationKey:m,veScaKey:o,isHaveRedeem:r,isObligationLocked:l,isOldBorrowIncentive:d}}}decodeExtendStakePeriod(){let e=this.helperExtendStakePeriod.decodeInputU64(4),t=this.helperExtendStakePeriod.decodeOwnedObjectId(1),a=[],o=[],r=[];this.helperOldUnstakeObligation.moveCall&&(a=[this.helperOldUnstakeObligation.decodeSharedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(o=[this.helperUnstakeObligation.decodeSharedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(r=[this.helperStakeObligationWithVeSca.decodeSharedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let i=!1,s=!1,c,l,d=[{condition:a,isOld:!0},{condition:o,isOld:!1},{condition:r,isOld:!1}];for(let p=0;p<d.length;p++)d[p].condition.length>1&&([l,c]=d[p].condition,i=!0,s=d[p].isOld);return{txType:v.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{lockPeriodInDays:e,obligationId:c,obligationKey:l,veScaKey:t,isObligationLocked:i,isOldBorrowIncentive:s}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),a=new E(e,this.txb).getAmountInput().reduce((b,f)=>b+f,0),o=[],r=[],i,s=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeSharedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(r=[this.helperUnstakeObligation.decodeSharedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(i=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(s=[this.helperStakeObligationWithVeSca.decodeSharedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,l=!1,d,p,m=[{condition:o,isOld:!0},{condition:r,isOld:!1},{condition:s,isOld:!1}];for(let b=0;b<m.length;b++)m[b].condition.length>1&&([p,d]=m[b].condition,c=!0,l=m[b].isOld);return{txType:v.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:a,veScaKey:i,lockPeriodInDays:t,obligationId:d,obligationKey:p,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),console.log(e));let a=new E(e,this.txb).getAmountInput().reduce((b,f)=>b+f,0),o=[],r=[],i,s=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeSharedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(r=[this.helperUnstakeObligation.decodeSharedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(i=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(s=[this.helperStakeObligationWithVeSca.decodeSharedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,l=!1,d,p,m=[{condition:o,isOld:!0},{condition:r,isOld:!1},{condition:s,isOld:!1}];for(let b=0;b<m.length;b++)m[b].condition.length>1&&([p,d]=m[b].condition,c=!0,l=m[b].isOld);return{txType:v.TransactionType.Other,type:"StakeSca",intentionData:{amount:a,lockPeriodInDays:t,obligationId:d,obligationKey:p,veScaKey:i,isObligationLocked:c,isOldBorrowIncentive:l}}}decodeSupplyLending(){let e=this._builder.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),a=new E(t,this.txb).getAmountInput().reduce((o,r)=>o+r,0);return{txType:v.TransactionType.Other,type:"SupplyLending",intentionData:{amount:a,coinName:e}}}decodeWithdrawLending(){let e=this._builder.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0)),t=this.helperRedeem.getNestedInputParam(2),a=new E(t,this.txb).getAmountInput().reduce((o,r)=>o+r,0);return{txType:v.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:a,coinName:e}}}decodeDepositCollateral(){let e=this._builder.utils.parseCoinNameFromType(this.helperDepositCollateral.typeArg(0)),t=this.helperDepositCollateral.getNestedInputParam(3),a=new E(t,this.txb).getAmountInput().reduce((r,i)=>r+i,0),o=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:v.TransactionType.Other,type:"DepositCollateral",intentionData:{amount:a,obligationId:o,collateralCoinName:e}}}decodeWithdrawCollateral(){let e=this._builder.utils.parseCoinNameFromType(this.helperWithdrawCollateral.typeArg(0)),t=this.helperWithdrawCollateral.decodeInputU64(5),a=this.helperWithdrawCollateral.decodeSharedObjectId(1),o=this.helperWithdrawCollateral.decodeOwnedObjectId(2);return{txType:v.TransactionType.Other,type:"WithdrawCollateral",intentionData:{amount:t,collateralCoinName:e,obligationKey:o,obligationId:a}}}decodeBorrow(){let e=this._builder.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperBorrow.decodeInputU64(5),a=this.helperBorrow.decodeSharedObjectId(1),o=this.helperBorrow.decodeOwnedObjectId(2);return{txType:v.TransactionType.Other,type:"Borrow",intentionData:{amount:t,coinName:e,obligationKey:o,obligationId:a}}}decodeBorrowWithBoost(){let e=this._builder.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),a=this.helperBorrow.decodeInputU64(5),o=this.helperBorrow.decodeSharedObjectId(1),r=this.helperBorrow.decodeOwnedObjectId(2);return{txType:v.TransactionType.Other,type:"BorrowWithBoost",intentionData:{amount:a,coinName:e,obligationKey:r,obligationId:o,veScaKey:t}}}decodeRepay(){let e=this._builder.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperRepay.getNestedInputParam(3),a=new E(t,this.txb).getAmountInput().reduce((r,i)=>r+i,0),o=this.helperRepay.decodeSharedObjectId(1);return{txType:v.TransactionType.Other,type:"Repay",intentionData:{amount:a,obligationId:o,coinName:e}}}decodeStakeSpool(){let e;this.isCreateStakeAccountTransaction()||(e=this.helperStake.decodeOwnedObjectId(1));let t=this.helperStake.getNestedInputParam(2),a=new E(t,this.txb).getAmountInput().reduce((i,s)=>i+s,0),o=this.helperStake.typeArg(0),r=this._builder.utils.parseCoinNameFromType(o);return{txType:v.TransactionType.Other,type:"StakeSpool",intentionData:{amount:a,marketCoinName:r,stakeAccountId:e}}}decodeUnstakeSpool(){let e=this.helperUnstake.decodeOwnedObjectId(1),t=this.helperUnstake.decodeInputU64(2),a=this.helperUnstake.typeArg(0),o=this._builder.utils.parseCoinNameFromType(a);return{txType:v.TransactionType.Other,type:"UnstakeSpool",intentionData:{amount:t,marketCoinName:o,stakeAccountId:e}}}decodeSupplyWithStakeSpool(){let e=this._builder.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),a=new E(t,this.txb).getAmountInput().reduce((r,i)=>r+i,0),o;return this.isCreateStakeAccountTransaction()||(o=this.helperStake.decodeOwnedObjectId(1)),{txType:v.TransactionType.Other,type:"SupplyAndStakeLending",intentionData:{amount:a,coinName:e,stakeAccountId:o}}}decodeUnstakeAndWithdraw(){let e=[];this.helperUnstakes.forEach(r=>{let i=r.decodeOwnedObjectId(1),s=r.decodeInputU64(2);e.push({id:i,coin:s})});let t=this._builder.utils.parseCoinNameFromType(this.helperRedeems[0].typeArg(0)),a=this.helperRedeems.find(r=>r.isHaveNestedInput(2)),o;return a&&(o=new E(a.getNestedInputParam(2),this.txb).getAmountInput().reduce((r,i)=>r+i,0)),{txType:v.TransactionType.Other,type:"WithdrawAndUnstakeLending",intentionData:{amount:o,coinName:t,stakeAccountId:e}}}decodeClaimReward(){let e=[],t=[],a=[];return this.helperClaimLendingReward.forEach(o=>{let r=o.decodeOwnedObjectId(2),i=o.typeArg(0),s=this._builder.utils.parseCoinNameFromType(i);e.push({stakeMarketCoinName:s,stakeAccountId:r})}),this.helperClaimBorrowV2Reward.forEach(o=>{let r=o.decodeSharedObjectId(3),i=o.decodeOwnedObjectId(4),s=this._builder.utils.parseCoinNameFromType(o.typeArg(0));t.push({obligationId:i,obligationKey:r,rewardCoinName:s})}),this.helperClaimBorrowReward.forEach(o=>{let r=o.decodeSharedObjectId(2),i=o.decodeOwnedObjectId(3),s=this._builder.utils.parseCoinNameFromType(o.typeArg(0));a.push({obligationId:i,obligationKey:r,rewardCoinName:s})}),{txType:v.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:a}}}get helperClaimLendingReward(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.spoolPkg}::user::redeem_rewards`)).map(t=>new I(t,this.txb))}get helperClaimBorrowV2Reward(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`)).map(t=>new I(t,this.txb))}get helperStakeMoreSca(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`));return new I(e,this.txb)}get helperStakeSca(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`));return new I(e,this.txb)}get helperExtendStakePeriod(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`));return new I(e,this.txb)}get helperRedeemSca(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.veScaPkgId}::ve_sca::redeem`));return new I(e,this.txb)}get helperRenewExpired(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`));return new I(e,this.txb)}get helperOldUnstakeObligation(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${Re}::user::unstake`));return new I(e,this.txb)}get helperUnstakeObligation(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.borrowIncentivePkg}::user::unstake`));return new I(e,this.txb)}get helperStakeObligationWithVeSca(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`));return new I(e,this.txb)}get helperClaimBorrowReward(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target.startsWith(`${Re}::user::redeem_rewards`)).map(t=>new I(t,this.txb))}get helperMint(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::mint::mint`));return new I(e,this.txb)}get helperUnstakes(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.spoolPkg}::user::unstake`)).map(t=>new I(t,this.txb))}get helperRedeems(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::redeem::redeem`)).map(t=>new I(t,this.txb))}get helperRedeem(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::redeem::redeem`));return new I(e,this.txb)}get helperStake(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.spoolPkg}::user::stake`));return new I(e,this.txb)}get helperUnstake(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.spoolPkg}::user::unstake`));return new I(e,this.txb)}get helperDepositCollateral(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`));return new I(e,this.txb)}get helperWithdrawCollateral(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`));return new I(e,this.txb)}get helperBorrow(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::borrow::borrow`));return new I(e,this.txb)}get helperRepay(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::repay::repay`));return new I(e,this.txb)}},E=class{constructor(e,t){this.splitCoin=e;this.txb=t}getAmountInput(){return this.splitCoin.amounts.map(e=>{if(e.kind==="Input")return Number(I.getPureInputValue(e,"u64"))}).filter(e=>e!==void 0)}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let a=e.value.Pure;return ka.bcs.de(t,new Uint8Array(a))}return e.value}},I=class n{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return n.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return n.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,de.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let a=this.getInputParam(e);return n.getPureInputValue(a,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]}getNestedInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="NestedResult")throw new Error("not input type");return this.txb.blockData.transactions[t.index]}isHaveNestedInput(e){return this.moveCall.arguments[e].kind==="NestedResult"}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let a=e.value.Pure;return ka.bcs.de(t,new Uint8Array(a))}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,de.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,de.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,de.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,de.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 a=e.value.Pure;return ka.bcs.de(t,new Uint8Array(a))}typeArg(e){return(0,de.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var T=require("@mysten/sui.js/transactions"),yi=require("@mysten/sui.js/utils"),oo=q(require("bignumber.js"));var Kr={mainnet:{core:{version:"0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7",versionCap:"0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",object:"0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf",market:"0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9",adminCap:"0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",coinDecimalsRegistry:"0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",obligationAccessStore:"0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9",coins:{cetus:{id:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",metaData:"0x4c0dce55eff2db5419bbd2d239d1aa22b4a400c01bbb648b058a9883989025da",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",feedObject:"0x24c0247fb22457a719efac7f670cdc79be321b521460bd6bd2ccfa9f80713b14"}}},apt:{id:"0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",metaData:"0xc969c5251f372c0f34c32759f1d315cf1ea0ee5e4454b52aea08778eacfdd0a8",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",feedObject:"0x7c5b7837c44a69b469325463ac0673ac1aa8435ff44ddb4191c9ae380463647f"}}},sol:{id:"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",metaData:"0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",feedObject:"0x9d0d275efbd37d8a8855f6f2c761fa5983293dd8ce202ee5196626de8fcd4469"}}},btc:{id:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",metaData:"0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",feedObject:"0x9a62b4863bdeaabdc9500fce769cf7e72d5585eeb28a6d26e4cafadc13f76ab2"}}},eth:{id:"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",metaData:"0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",feedObject:"0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"}}},usdc:{id:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",metaData:"0x4fbf84f3029bd0c0b77164b587963be957f853eccf834a67bb9ecba6ec80f189",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",feedObject:"0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"}}},usdt:{id:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",metaData:"0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",feedObject:"0x985e3db9f93f76ee8bace7c3dd5cc676a096accd5d9e09e9ae0fb6e492b14572"}}},sui:{id:"0x0000000000000000000000000000000000000000000000000000000000000002",metaData:"0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",treasury:"",oracle:{supra:"",switchboard:"0xbca474133638352ba83ccf7b5c931d50f764b09550e16612c9f70f1e21f3f594",pyth:{feed:"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",feedObject:"0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"}}},afsui:{id:"0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",metaData:"0x2f9217f533e51334873a39b8026a4aa6919497b47f49d0986a4f1aec66f8a34d",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",feedObject:"0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"}}},hasui:{id:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",metaData:"0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",feedObject:"0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"}}},vsui:{id:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",metaData:"0xabd84a23467b33854ab25cf862006fd97479f8f6f53e50fe732c43a274d939bd",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",feedObject:"0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"}}},sca:{id:"0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6",metaData:"0x5d26a1e9a55c88147ac870bfa31b729d7f49f8804b8b3adfdf3582d301cca844",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc",feedObject:"0xf6de1d3279a269a597d813cbaca59aa906543ab9a8c64e84a4722f1a20863985"}}}},oracles:{xOracle:"0x93d5bf0936b71eb27255941e532fac33b5a5c7759e377b4923af0a1359ad494f",xOracleCap:"0x1edeae568fde99e090dbdec4bcdbd33a15f53a1ce1f87aeef1a560dedf4b4a90",supra:{registry:"",registryCap:"",holder:""},switchboard:{registry:"",registryCap:""},pyth:{registry:"0xedc293f9413a5a7a5d53bdba1fd889d0a4030894469228f0acdae4aa3c55a213",registryCap:"0xbcb07141eb1f7e01fbda4130ecf5f5adaeabb77f5d9c32158b7532bcd2197acd",state:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",wormhole:"0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a",wormholeState:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"}},packages:{coinDecimalsRegistry:{id:"0xca5a5a62f01c79a104bf4d31669e29daa387f325c241de4edbe30986a9bc8b0d",upgradeCap:"0x34e76a945d29f195bc53ca704fa70877d1cf3a5d7bbfdda1b13e633fff13c0f6"},math:{id:"0xad013d5fde39e15eabda32b3dbdafd67dac32b798ce63237c27a8f73339b9b6f",upgradeCap:"0x3a329598231de02e6135c62284b66005b41cad1d9ab7ca2dc79c08293aba2ec6"},whitelist:{id:"0x1318fdc90319ec9c24df1456d960a447521b0a658316155895014a6e39b5482f",upgradeCap:"0xf5a22aea23db664f7b69855b6a546747f17c1ec4230319cfc17225e462b05761"},x:{id:"0x779b5c547976899f5474f3a5bc0db36ddf4697ad7e5a901db0415c2281d28162",upgradeCap:"0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"},protocol:{id:"0x38fe42a5a69f7eb3635404389e8003be9457b1a5c873f133184648c7e9bd47b7",upgradeCap:"0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"},protocolWhitelist:{id:"0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",upgradeCap:"0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"},query:{id:"0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f",upgradeCap:"0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"},supra:{id:"",upgradeCap:""},pyth:{id:"0x910f30cbc7f601f75a5141a01265cd47c62d468707c5e1aecb32a18f448cb25a",upgradeCap:"0xdf0ffbae1ea5bb25fbca5efba433dcf00c7cced65679af2f04728901275c6157"},switchboard:{id:"",upgradeCap:""},xOracle:{id:"0x1478a432123e4b3d61878b629f2c692969fdb375644f1251cd278a4b1e7d7cd6",upgradeCap:"0x0f928a6b2e26b73330fecaf9b44acfc9800a4a9794d6415c2a3153bc70e3c1f0"},testCoin:{id:"",upgradeCap:""}}},spool:{id:"0xec1ac7f4d01c5bf178ff4e62e523e7df7721453d81d4904a42a0ffc2686c843d",adminCap:"0xdd8a047cbbf802bfcde5288b8ef1910965d789cc614da11d39af05fca0bd020a",object:"0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a",pools:{seth:{id:"0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",rewardPoolId:"0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077"},ssui:{id:"0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4",rewardPoolId:"0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9"},susdc:{id:"0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0",rewardPoolId:"0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8"},susdt:{id:"0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f",rewardPoolId:"0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080"},scetus:{id:"0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",rewardPoolId:"0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f"},safsui:{id:"0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800",rewardPoolId:"0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e"},shasui:{id:"0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa",rewardPoolId:"0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66"},svsui:{id:"0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670",rewardPoolId:"0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a"}},version:"",versionCap:""},borrowIncentive:{id:"0x874f1d43d81e2256e120bab2485938fe07ba0cc21d87129a99a1db11cacb382d",adminCap:"0xc486afa253646f4d381e81d7f1df8aa4723b845a6bb356f69bad635ffefffe2c",object:"0x002875153e09f8145ab63527bc85c00f2bd102e12f9573c47f8cdf1a1cb62934",query:"0x529edc54a3dce2207703ceebbccb0ac14133f7825c1f528775ba0d85a4063489",incentivePools:"0x6547e143d406b5ccd5f46aae482497de279cc1a68c406f701df70a05f9212ab4",incentiveAccounts:"0xc4701fdbc1c92f9a636d334d66012b3027659e9fb8aff27279a82edfb6b77d02",config:"0xdf5d04b4691cc67e82fd4db8394d89ff44823a9de29716c924f74bb4f11cc1f7",version:"",versionCap:""},vesca:{id:"0xcfe2d87aa5712b67cad2732edb6a2201bfdf592377e5c0968b7cb02099bd8e21",adminCap:"0x4d105b16467acca81d18c132cdd1a3cee159920a86c1ef4bdbf2e8d7878500c5",tableId:"0x0a0b7f749baeb61e3dfee2b42245e32d0e6b484063f0a536b33e771d573d7246",table:"0xd3a4632b1080f7d96e1c2487d4dabf2c1196916937c505a69954ac9f393be8d0",treasury:"0xafa4b6231e49c15a22d641ce33fda761baaf650fa21899dfa2eb1716146e7306",config:"0x7cbcb0a342179577a117dfdff974cf1ab765d3b571067bf22ddf5f9e3a667922"}}};var V=class{_auth;_id;_network;_currentAddresses;_addressesMap;constructor(e){let{id:t,auth:a,network:o}=e;a&&(this._auth=a),this._id=t,this._network=o||"mainnet",this._addressesMap=new Map}getId(){return this._id||void 0}get(e){if(this._currentAddresses)return e.split(".").reduce((a,o)=>typeof a=="object"?a[o]:a,this._currentAddresses)||void 0}set(e,t){if(this._currentAddresses){let a=e.split(".");a.reduce((o,r,i)=>{if(i===a.length-1){let s=o;s[r]=t}return o[r]},this._currentAddresses)}return this._currentAddresses}switchCurrentAddresses(e){return this._addressesMap.has(e)&&(this._currentAddresses=this._addressesMap.get(e),this._network=e),this._currentAddresses}getAddresses(e){return e?this._addressesMap.get(e):this._currentAddresses??this._addressesMap.get(this._network)}setAddresses(e,t){let a=t||this._network;a===this._network&&(this._currentAddresses=e),this._addressesMap.set(a,e)}getAllAddresses(){return Object.fromEntries(this._addressesMap)}read(){return Object.entries(Kr).forEach(([e,t])=>{["localnet","devnet","testnet","mainnet"].includes(e)&&(e===this._network&&(this._currentAddresses=t),this._addressesMap.set(e,t))}),this.getAllAddresses()}};var mi=require("@mysten/sui.js/transactions"),bi=require("@mysten/sui.js/utils");var st=require("@mysten/sui.js/utils");var D=n=>{let{sender:e}=n.blockData;if(!e)throw new Error("Sender is required");return e},Jr=(n,e,t,a)=>{let o=!a,r=!o&&a*1e3<=new Date().getTime();if(o||r)if(n!==void 0&&e!==void 0){if(e<=0)throw new Error("Lock period must be greater than 0");if(typeof n=="number"&&n<1e10)throw new Error(`Minimum lock amount for ${r?"renewing expired veSca":"initial lock"} is 10 SCA`);if(e*86400>126144e3)throw new Error(`Maximum lock period is ~4 years (${1460} days)`)}else throw new Error(`SCA amount and lock period is required for ${r?"renewing expired veSca":"initial lock"}`);else{if(Ee(a),typeof n=="number"&&n<1e9)throw new Error("Minimum top up amount is 1 SCA");if(t&&a&&t-a>126057600)throw new Error(`Maximum lock period is ~4 years (${1459} days)`)}},Xr=(n,e,t)=>{if(Ee(t),n<=0)throw new Error("Lock period must be greater than 0");if(!!t&&t*1e3<=new Date().getTime())throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");if(t&&e-(t??0)>126057600)throw new Error(`Maximum lock period is ~4 years (${1459} days)`)},Yr=(n,e)=>{if(Ee(e),n<1e9)throw new Error("Minimum top up amount is 1 SCA");if(!!e&&e*1e3<=new Date().getTime())throw new Error("veSca is expired, use renewExpiredVeScaQuick instead")},Zr=(n,e,t)=>{if(Ee(t),n<1e10)throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");if(e*86400>=126057600)throw new Error(`Maximum lock period is ~4 years (${1459} days)`)},Ee=n=>{if(n===void 0)throw new Error("veSca not found")};var it=require("@mysten/sui.js/utils"),Gs=q(require("bignumber.js"));var Ks=n=>({pointType:(0,it.normalizeStructTag)(n.point_type.name),weightedAmount:Number(n.weighted_amount),points:Number(n.points),totalPoints:Number(n.total_points),index:Number(n.index)}),ei=n=>({poolType:(0,it.normalizeStructTag)(n.pool_type.name),debtAmount:Number(n.debt_amount),pointList:n.points_list.reduce((e,t)=>{let a=Ks(t),o=(0,it.parseStructTag)(a.pointType).name.toLowerCase();return e[o]=a,e},{})});var Jn=n=>{let e=n.slice(1).toLowerCase();return n.charAt(0).toLowerCase()==="s"&&[...new Set([...Se,...Ia,...$r])].includes(e)},Xn=n=>{switch(n){case"afsui":return"afSUI";case"hasui":return"haSUI";case"vsui":return"vSUI";default:return n.toUpperCase()}};var ti=n=>{let e=new Date(n*1e3),t=new Date(n*1e3);t.setUTCHours(0,0,0,0),e.getUTCHours()>=0&&t.setUTCDate(t.getUTCDate()+1);let a=new Date().getTime();return t.getTime()-a>126144e3*1e3&&t.setUTCDate(t.getUTCDate()-1),Math.floor(t.getTime()/1e3)};var ue=class{params;isTestnet;_address;client;constructor(e,t){this.params=e,this._address=t?.address??new V({id:e?.addressesId||se,network:e?.networkType}),this.isTestnet=e.networkType?e.networkType==="testnet":!1,this.client=e.client}init(e=!1,t){e||!this._address.getAddresses()||!t?.getAddresses()?this._address.read():this._address=t}parseSymbol(e){if(Jn(e)){let t=e.slice(1).toLowerCase();return e.slice(0,1).toLowerCase()+Xn(t)}return Xn(e)}parseCoinType(e){let t=Jn(e)?this.parseCoinName(e):e,a=this._address.get(`core.coins.${t}.id`)||Gr[e]||void 0;if(!a)throw Error(`Coin ${e} is not supported`);if(e==="sui")return(0,st.normalizeStructTag)(`${a}::sui::SUI`);let o=[this._address.get("core.coins.usdc.id")??j.usdc,this._address.get("core.coins.usdt.id")??j.usdt,this._address.get("core.coins.eth.id")??j.eth,this._address.get("core.coins.btc.id")??j.btc,this._address.get("core.coins.sol.id")??j.sol,this._address.get("core.coins.apt.id")??j.apt],r=[this._address.get("core.coins.vsui.id")??zn.vsui];return o.includes(a)?`${a}::coin::COIN`:r.includes(a)?`${a}::cert::CERT`:`${a}::${t}::${t.toUpperCase()}`}parseMarketCoinType(e){let t=this._address.get("core.object")||Ca,a=this.parseCoinType(e);return`${t}::reserve::MarketCoin<${a}>`}parseCoinNameFromType(e){let t=(0,st.normalizeStructTag)(e),a=/((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)/,o=e.match(a),r=e.includes("reserve::MarketCoin");t=o?.[1]||e;let i={[`${this._address.get("core.coins.usdc.id")??j.usdc}::coin::COIN`]:"usdc",[`${this._address.get("core.coins.usdt.id")??j.usdt}::coin::COIN`]:"usdt",[`${this._address.get("core.coins.eth.id")??j.eth}::coin::COIN`]:"eth",[`${this._address.get("core.coins.btc.id")??j.btc}::coin::COIN`]:"btc",[`${this._address.get("core.coins.sol.id")??j.sol}::coin::COIN`]:"sol",[`${this._address.get("core.coins.apt.id")??j.apt}::coin::COIN`]:"apt"},s={[`${this._address.get("core.coins.vsui.id")??zn.vsui}::cert::CERT`]:"vsui"},c=i[t]||s[t]||t.split("::")[2].toLowerCase();return r?this.parseMarketCoinName(c):c}parseCoinName(e){return e.slice(1)}parseMarketCoinName(e){return`s${e}`}getSpoolRewardCoinName=e=>Ta[e];getBorrowIncentiveRewardCoinName=e=>Vr[e];getCoinDecimal(e){return Qr[e]}getCoinWrappedType(e){return e==="usdc"||e==="usdt"||e==="eth"||e==="btc"||e==="apt"||e==="sol"?{from:"Wormhole",type:"Portal from Ethereum"}:void 0}async selectCoinIds(e,t=st.SUI_TYPE_ARG,a){let o=a,r=[],i=0,s=!0,c=null;for(;s&&i<e;){let l=await this.client.getCoins({owner:o,coinType:t,cursor:c});l.data.sort((d,p)=>parseInt(p.balance,10)-parseInt(d.balance,10));for(let d=0;d<l.data.length&&(r.push({objectId:l.data[d].coinObjectId,digest:l.data[d].digest,version:l.data[d].version}),i+=parseInt(l.data[d].balance,10),!(i>=e));d++);c=l.nextCursor,s=l.hasNextPage}if(!r.length)throw new Error("No valid coins found for the transaction.");return r.map(l=>l.objectId)}parseAprToApy(e,t=365){return(1+e/t)**t-1}parseApyToApr(e,t=365){return((1+e)**(1/t)-1)*t}takeAmountFromCoins(e,t,a){let o=t.map(s=>e.object(s)),r=o[0];o.length>1&&e.mergeCoins(r,o.slice(1));let[i]=e.splitCoins(r,[e.pure(a)]);return[i,r]}getUnlockAt(e,t){let a=Math.floor(new Date().getTime()/1e3),o=t?Math.max(t-a,0):0,r=0;if(o===0){let i=(e??1)*86400;r=Math.min(a+i,a+126144e3)}else{let i=Math.min(e?e*86400+o:o,126144e3);r=a+i}return ti(r)}};var ai=require("@mysten/sui.js/transactions"),ct=q(require("bignumber.js"));var Me=async(n,e)=>{let t=e,a=n.address.get("core.object")||Ca,o=[],r=!1,i=null;do{let d=await n.client.getOwnedObjects({owner:t,filter:{StructType:`${a}::obligation::ObligationKey`},cursor:i});o.push(...d.data),d.hasNextPage&&d.nextCursor?(r=!0,i=d.nextCursor):r=!1}while(r);let s=o.map(d=>d?.data?.objectId).filter(d=>d!==void 0),c=await n.client.multiGetObjects({ids:s,options:{showContent:!0,showType:!0}}),l=[];for(let d=0;d<c.length;d++){let p=c[d].data.objectId,{content:m}=c[d].data;if(m&&"fields"in m){let b=m.fields,f=String(b.ownership.fields.of),y=await Yn(n,f);l.push({id:f,keyId:p,locked:y})}}return l},Yn=async(n,e)=>{let t=await n.client.getObject({id:e,options:{showContent:!0}}),a=!1;return t.data&&t?.data?.content?.dataType==="moveObject"&&"lock_key"in t.data.content.fields&&(a=!!t.data.content.fields.lock_key),a},ni=async(n,e,t)=>{let a=t||[...Se],o=e,r=[],i=!1,s=null;do{let d=await n.client.getOwnedObjects({owner:o,filter:{MatchAny:a.map(p=>({StructType:`0x2::coin::Coin<${n.utils.parseCoinType(p)}>`}))},options:{showType:!0,showContent:!0},cursor:s});r.push(...d.data),d.hasNextPage&&d.nextCursor?(i=!0,s=d.nextCursor):i=!1}while(i);let c={};return r.map(d=>d.data).filter(d=>d!=null).forEach(d=>{let p=d.type;if(d.content&&"fields"in d.content){let m=d.content.fields,b=n.utils.parseCoinNameFromType(p);b&&(c[b]=(0,ct.default)(c[b]??0).plus(m.balance).toNumber())}}),c},oi=async(n,e,t)=>{let a=t,o=n.utils.parseCoinType(e),r=[],i=!1,s=null;do{let d=await n.client.getOwnedObjects({owner:a,filter:{StructType:`0x2::coin::Coin<${o}>`},options:{showContent:!0},cursor:s});r.push(...d.data),d.hasNextPage&&d.nextCursor?(i=!0,s=d.nextCursor):i=!1}while(i);let c=0;return r.map(d=>d.data).filter(d=>d!=null).forEach(d=>{if(d.content&&"fields"in d.content){let p=d.content.fields;c=(0,ct.default)(c).plus(p.balance).toNumber()}}),c},ri=async(n,e,t)=>{let a=t||[...Se].map(d=>n.utils.parseMarketCoinName(d)),o=e,r=[],i=!1,s=null;do{let d=await n.client.getOwnedObjects({owner:o,filter:{MatchAny:a.map(p=>({StructType:`0x2::coin::Coin<${n.utils.parseMarketCoinType(p)}>`}))},options:{showType:!0,showContent:!0},cursor:s});r.push(...d.data),d.hasNextPage&&d.nextCursor?(i=!0,s=d.nextCursor):i=!1}while(i);let c={};return r.map(d=>d.data).filter(d=>d!=null).forEach(d=>{let p=d.type;if(d.content&&"fields"in d.content){let m=d.content.fields,b=n.utils.parseCoinNameFromType(p);b&&(c[b]=(0,ct.default)(c[b]??0).plus(m.balance).toNumber())}}),c},ii=async(n,e,t)=>{let a=t,o=n.utils.parseMarketCoinType(e),r=[],i=!1,s=null;do{let d=await n.client.getOwnedObjects({owner:a,filter:{StructType:`0x2::coin::Coin<${o}>`},options:{showContent:!0},cursor:s});r.push(...d.data),d.hasNextPage&&d.nextCursor?(i=!0,s=d.nextCursor):i=!1}while(i);let c=0;return r.map(d=>d.data).filter(d=>d!=null).forEach(d=>{if(d.content&&"fields"in d.content){let p=d.content.fields;c=(0,ct.default)(c).plus(p.balance).toNumber()}}),c},si=async(n,e)=>{let a=`${n.address.get("core.packages.query.id")}::obligation_query::obligation_data`,o=new ai.TransactionBlock;return o.moveCall({target:a,arguments:[o.object(e)]}),(await n.client.devInspectTransactionBlock({transactionBlock:o,sender:n.walletAddress})).events[0].parsedJson};var w=require("@mysten/sui.js/utils"),dt=async(n,e)=>{let t=e,a=n.address.get("spool.object"),o=`${a}::spool_account::SpoolAccount`,r=[],i=!1,s=null;do{let m=await n.client.getOwnedObjects({owner:t,filter:{StructType:o},options:{showContent:!0,showType:!0},cursor:s});r.push(...m.data),m.hasNextPage&&m.nextCursor?(i=!0,s=m.nextCursor):i=!1}while(i);let c={seth:[],ssui:[],susdc:[],susdt:[],scetus:[],safsui:[],shasui:[],svsui:[]},l=Object.keys(c).reduce((m,b)=>{let f=n.utils.parseCoinName(b),y=n.utils.parseMarketCoinType(f),C={...m},_=`${a}::spool_account::SpoolAccount<${y}>`;return C[b]=_,C},{}),d=r.map(m=>m?.data?.objectId).filter(m=>m!==void 0);return(await n.client.multiGetObjects({ids:d,options:{showContent:!0,showType:!0}})).forEach(m=>{let b=m.data.objectId,f=m.data.type;if(m.data.content&&"fields"in m.data.content){let y=m.data.content.fields,C=String(y.spool_id),_=String(y.stake_type.fields.name),U=Number(y.stakes),J=Number(y.index),X=Number(y.points),Y=Number(y.total_points);(0,w.normalizeStructTag)(f)===l.seth?c.seth.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:J,points:X,totalPoints:Y}):(0,w.normalizeStructTag)(f)===l.ssui?c.ssui.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:J,points:X,totalPoints:Y}):(0,w.normalizeStructTag)(f)===l.susdc?c.susdc.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:J,points:X,totalPoints:Y}):(0,w.normalizeStructTag)(f)===l.susdt?c.susdt.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:J,points:X,totalPoints:Y}):(0,w.normalizeStructTag)(f)===l.scetus?c.scetus.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:J,points:X,totalPoints:Y}):(0,w.normalizeStructTag)(f)===l.safsui?c.safsui.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:J,points:X,totalPoints:Y}):(0,w.normalizeStructTag)(f)===l.shasui?c.shasui.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:J,points:X,totalPoints:Y}):(0,w.normalizeStructTag)(f)===l.svsui&&c.svsui.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:J,points:X,totalPoints:Y})}}),c},Zn=async(n,e)=>{let t=n.address.get(`spool.pools.${e}.id`),a,o=await n.client.getObject({id:t,options:{showContent:!0,showType:!0}});if(o.data){let r=o.data,i=r.objectId,s=r.type;if(r.content&&"fields"in r.content){let c=r.content.fields,l=Number(c.max_distributed_point),d=Number(c.distributed_point),p=Number(c.distributed_point_per_period),m=Number(c.point_distribution_time),b=Number(c.max_stakes),f=String(c.stake_type.fields.name),y=Number(c.stakes),C=Number(c.index),_=Number(c.created_at),U=Number(c.last_update);a={id:i,type:(0,w.normalizeStructTag)(s),maxPoint:l,distributedPoint:d,pointPerPeriod:p,period:m,maxStake:b,stakeType:(0,w.normalizeStructTag)(f),totalStaked:y,index:C,createdAt:_,lastUpdate:U}}}return a},eo=async(n,e)=>{let t=n.address.get(`spool.pools.${e}.rewardPoolId`),a,o=await n.client.getObject({id:t,options:{showContent:!0,showType:!0}});if(o.data){let r=o.data,i=r.objectId,s=r.type;if(r.content&&"fields"in r.content){let c=r.content.fields,l=String(c.spool_id),d=Number(c.exchange_rate_numerator),p=Number(c.exchange_rate_denominator),m=Number(c.rewards),b=Number(c.claimed_rewards);a={id:i,type:(0,w.normalizeStructTag)(s),stakePoolId:l,ratioNumerator:d,ratioDenominator:p,rewards:m,claimedRewards:b}}}return a};var ci=require("@mysten/sui.js/transactions"),Hs=require("@mysten/sui.js/utils"),zs=q(require("bignumber.js"));var di=async(n,e,t,a)=>{let o=a||[...Ne],r=n.address.get("borrowIncentive.query"),i=n.address.get("borrowIncentive.incentiveAccounts"),s=`${r}::incentive_account_query::incentive_account_data`,c=new ci.TransactionBlock;c.moveCall({target:s,arguments:[c.object(i),c.object(e)]});let d=(await n.client.devInspectTransactionBlock({transactionBlock:c,sender:t})).events[0].parsedJson,p={};return d.pool_records.forEach(m=>{let b=ei(m),{poolType:f}=b,y=n.utils.parseCoinNameFromType(f);o.length>=1&&o.includes(y)&&(p[y]=b)},{}),p};var li=async(n,e)=>{let t=n.address.get(`core.coins.${e}.oracle.pyth.feedObject`),a=await n.client.getObject({id:t,options:{showContent:!0}});if(a.data){let o=a.data;if(o.content&&"fields"in o.content){let r=o.content.fields,i=Number(r.price_info.fields.price_feed.fields.price.fields.expo.fields.magnitude),s=Number(r.price_info.fields.price_feed.fields.price.fields.expo.fields.negative),c=Number(r.price_info.fields.price_feed.fields.price.fields.price.fields.magnitude),l=Number(r.price_info.fields.price_feed.fields.price.fields.price.fields.negative);return c*10**((s?-1:1)*i)*(l?-1:1)}}return 0};var Aa=q(require("bignumber.js")),ui=async(n,e)=>{let t=e,o=`${n.address.get("vesca.id")}::ve_sca::VeScaKey`,r=[],i=!1,s=null;do{let l=await n.client.getOwnedObjects({owner:t,filter:{StructType:o},cursor:s});r.push(...l.data),l.hasNextPage&&l.nextCursor?(i=!0,s=l.nextCursor):i=!1}while(i);return r.map(l=>l.data).filter(l=>!!l)},pi=async(n,e)=>{let a=(await ui(n,e)).map(r=>r.objectId),o=[];for(let r=0;r<a.length;r++){let i=await to(n,a[r]);i&&o.push(i)}return o},to=async(n,e,t)=>{let a=n.address.get("vesca.tableId"),o=e||(await ui(n,t))[0].objectId,r,s=(await n.client.getDynamicFieldObject({parentId:a,name:{type:"0x2::object::ID",value:o}})).data;if(s&&s.content&&s.content.dataType==="moveObject"&&"fields"in s.content){let c=s.content.fields.value.fields;r={id:s.objectId,keyId:o,lockedScaAmount:(0,Aa.default)(c.locked_sca_amount).toNumber(),lockedScaCoin:(0,Aa.default)(c.locked_sca_amount).shiftedBy(-9).toNumber(),unlockAt:(0,Aa.default)(c.unlock_at).toNumber()}}return r};var Le=class{params;address;client;utils;walletAddress;constructor(e,t){this.params=e,this.address=t?.address??new V({id:e?.addressesId||se,network:e?.networkType}),this.client=e.client,this.utils=t?.utils??new ue(this.params,{address:this.address}),this.walletAddress=e.walletAddress}init(e=!1,t){e||!this.address.getAddresses()||!t?.getAddresses()?this.address.read():this.address=t}async getObligations(e){return Me(this,e)}async getCoinAmounts(e,t){return ni(this,e,t)}async getCoinAmount(e,t){return oi(this,e,t)}async getMarketCoinAmounts(e,t){return ri(this,e,t)}async getMarketCoinAmount(e,t){return ii(this,e,t)}async getPriceFromPyth(e){return li(this,e)}async getAllStakeAccounts(e){return dt(this,e)}async getStakeAccounts(e,t){return(await this.getAllStakeAccounts(t))[e]??[]}async getStakePools(e){let t=e??[...rt],a={};for(let o=0;o<t.length;o++){let r=t[o],i=await Zn(this,r);i&&(a[r]=i)}return a}async getStakePool(e){return Zn(this,e)}async getStakeRewardPools(e){let t=e??[...rt],a={};for(let o=0;o<t.length;o++){let r=await eo(this,t[o]);r&&(a[t[o]]=r)}return a}async getStakeRewardPool(e){return eo(this,e)}async getBorrowIncentiveAccounts(e,t,a){return di(this,e,t||this.walletAddress,a)}async getObligationCoinNames(e){let t=await si(this,e),a=t.collaterals.map(s=>`0x${s.type.name}`),o=t.debts.map(s=>`0x${s.type.name}`);return[...new Set([...a,...o])].map(s=>this.utils.parseCoinNameFromType(s))}};var We=class{params;isTestnet;address;query;utils;client;walletAddress;constructor(e,t){this.params=e,this.address=t?.address??new V({id:e?.addressesId||se,network:e?.networkType}),this.query=t?.query??new Le(e,{address:this.address}),this.utils=t?.utils??new ue(this.params,{address:this.address,query:this.query}),this.client=e.client,this.walletAddress=(0,bi.normalizeSuiAddress)(e.walletAddress),this.isTestnet=e.networkType?e.networkType==="testnet":!1}async init(e=!1,t){e||!this.address.getAddresses()||!t?.getAddresses()?this.address.read():this.address=t,this.query.init(e,this.address),this.utils.init(e,this.address)}createTxBlock(e){return new mi.TransactionBlock(e)}async selectCoin(e,t,a,o){let r=this.utils.parseCoinType(t),i=await this.utils.selectCoinIds(a,r,o),[s,c]=this.utils.takeAmountFromCoins(e,i,a);return{takeCoin:s,leftCoin:c}}async selectMarketCoin(e,t,a,o){let r=this.utils.parseMarketCoinType(t),i=await this.utils.selectCoinIds(a,r,o),[s,c]=this.utils.takeAmountFromCoins(e,i,a);return{takeCoin:s,leftCoin:c}}};var H=require("@mysten/sui.js/utils");var we=async(...n)=>{let[e,t,a]=n;if(n.length===3&&a&&typeof a=="string"){let i=await to(e.query,a);return i||void 0}let o=D(t),r=await pi(e.query,o);if(r.length!==0)return r[0]},Js=async(n,e)=>{let t=n.address.get("borrowIncentive.object"),a=n.address.get("borrowIncentive.incentivePools"),o=n.address.get("vesca.id"),{client:r}=n,i=await r.getObject({id:a,options:{showContent:!0}});if(i.data?.content?.dataType!=="moveObject")return!1;let c=i.data.content.fields.ve_sca_bind.fields.id.id,l=`${t}::typed_id::TypedID<${o}::ve_sca::VeScaKey>`,d=await r.getDynamicFieldObject({parentId:c,name:{type:l,value:e}});return d.data?.content?.dataType!=="moveObject"?!1:d.data.content.fields.value.fields.id},ao=async(...n)=>{let[e,t,a,o]=n;if(n.length===4&&a&&o&&typeof a=="string"){let s=await Yn(e.query,a);return{obligationId:a,obligationKey:o,obligationLocked:s}}let r=D(t),i=await Me(e.query,r);if(i.length===0)throw new Error(`No obligation found for sender ${r}`);return{obligationId:i[0].id,obligationKey:i[0].keyId,obligationLocked:i[0].locked}},Xs=({builder:n,txBlock:e})=>{let t={borrowIncentivePkg:n.address.get("borrowIncentive.id"),query:n.address.get("borrowIncentive.query"),incentivePools:n.address.get("borrowIncentive.incentivePools"),incentiveAccounts:n.address.get("borrowIncentive.incentiveAccounts"),obligationAccessStore:n.address.get("core.obligationAccessStore"),config:n.address.get("borrowIncentive.config")},a={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},o={table:n.address.get("vesca.table"),treasury:n.address.get("vesca.treasury"),config:n.address.get("vesca.config")};return{stakeObligation:(r,i)=>{e.moveCall({target:`${t.borrowIncentivePkg}::user::stake`,arguments:[e.object(t.config),e.object(t.incentivePools),e.object(t.incentiveAccounts),e.object(i),e.object(r),e.object(t.obligationAccessStore),e.object(H.SUI_CLOCK_OBJECT_ID)]})},stakeObligationWithVesca:(r,i,s)=>{e.moveCall({target:`${t.borrowIncentivePkg}::user::stake_with_ve_sca`,arguments:[e.object(t.config),e.object(t.incentivePools),e.object(t.incentiveAccounts),e.object(i),e.object(r),e.object(t.obligationAccessStore),e.object(o.config),e.object(o.treasury),e.object(o.table),e.object(s),e.object(H.SUI_CLOCK_OBJECT_ID)]})},unstakeObligation:(r,i)=>{e.moveCall({target:`${t.borrowIncentivePkg}::user::unstake`,arguments:[e.object(t.config),e.object(t.incentivePools),e.object(t.incentiveAccounts),e.object(i),e.object(r),e.object(H.SUI_CLOCK_OBJECT_ID)]})},oldUnstakeObligation:(r,i)=>{e.moveCall({target:`${t.borrowIncentivePkg}::user::unstake`,arguments:[e.object(a.incentivePools),e.object(a.incentiveAccounts),e.object(i),e.object(r),e.object(H.SUI_CLOCK_OBJECT_ID)],typeArguments:[H.SUI_TYPE_ARG]})},claimBorrowIncentive:(r,i,s)=>{let c=n.utils.parseCoinType(s);return e.moveCall({target:`${t.borrowIncentivePkg}::user::redeem_rewards`,arguments:[e.object(t.config),e.object(t.incentivePools),e.object(t.incentiveAccounts),e.object(i),e.object(r),e.object(H.SUI_CLOCK_OBJECT_ID)],typeArguments:[c]})},oldClaimBorrowIncentive(r,i,s){let c=n.utils.parseCoinType(s);return e.moveCall({target:`${a.id}::user::redeem_rewards`,arguments:[e.object(a.incentivePools),e.object(a.incentiveAccounts),e.object(i),e.object(r),e.object(H.SUI_CLOCK_OBJECT_ID)],typeArguments:[c]})}}},M=({builder:n,txBlock:e})=>{let t=Xs({builder:n,txBlock:e});return{normalMethod:t,stakeObligationQuick:async(a,o)=>{let{obligationId:r,obligationKey:i,obligationLocked:s}=await ao(n,e,a,o),c=!!e.blockData.transactions.find(l=>l.kind==="MoveCall"&&l.target===`${n.address.get("borrowIncentive.id")}::user::unstake`);(!s||c)&&t.stakeObligation(r,i)},unstakeObligationQuick:async(a,o)=>{let{obligationId:r,obligationKey:i,obligationLocked:s}=await ao(n,e,a,o);s&&t.unstakeObligation(r,i)},stakeObligationWithVeScaQuick:async(a,o,r)=>{let{obligationId:i,obligationKey:s,obligationLocked:c}=await ao(n,e,a,o),l=!!e.blockData.transactions.find(d=>d.kind==="MoveCall"&&(d.target===`${Re}::user::unstake`||d.target===`${n.address.get("borrowIncentive.id")}::user::unstake`));if(!c||l){let d=await we(n,e,r);if(d){let p=await Js(n,d.keyId);!p||p===i?t.stakeObligationWithVesca(i,s,d.keyId):t.stakeObligation(i,s)}else t.stakeObligation(i,s)}},claimBorrowIncentiveQuick:(a,o,r)=>t.claimBorrowIncentive(o,r,a)}};var z=require("@mysten/sui.js/utils");var ut=require("@mysten/sui.js/utils"),gi=q(require("axios"));var fi={testnet:["https://hermes-beta.pyth.network"],mainnet:["https://hermes.pyth.network","https://scallop.rpc.p2p.world"]};var Oa=require("@mysten/sui.js/bcs"),lt=require("@mysten/sui.js/utils"),no=16*1024,Pa=class{provider;pythStateId;wormholeStateId;pythPackageId;wormholePackageId;priceTableInfo;priceFeedObjectIdCache=new Map;baseUpdateFee;constructor(e,t,a){this.provider=e,this.pythStateId=t,this.wormholeStateId=a,this.pythPackageId=void 0,this.wormholePackageId=void 0}async getBaseUpdateFee(){if(this.baseUpdateFee===void 0){let e=await this.provider.getObject({id:this.pythStateId,options:{showContent:!0}});if(!e.data||!e.data.content||e.data.content.dataType!=="moveObject")throw new Error("Unable to fetch pyth state object");this.baseUpdateFee=e.data.content.fields.base_update_fee}return this.baseUpdateFee}async getPackageId(e){let t=await this.provider.getObject({id:e,options:{showContent:!0}}).then(a=>{if(a.data?.content?.dataType==="moveObject")return a.data.content.fields;throw console.log(a.data?.content),new Error(`Cannot fetch package id for object ${e}`)});if("upgrade_cap"in t)return t.upgrade_cap.fields.package;throw new Error("upgrade_cap not found")}async verifyVaas(e,t){let a=await this.getWormholePackageId(),o=[];return e.forEach(r=>{let[i]=t.moveCall({target:`${a}::vaa::parse_and_verify`,arguments:[t.object(this.wormholeStateId),t.pure(Oa.bcs.ser("vector<u8>",Array.from(r),{maxSize:no}).toBytes()),t.object(lt.SUI_CLOCK_OBJECT_ID)]});o.push(i)}),o}async updatePriceFeeds(e,t,a){let o=await this.getPythPackageId(),r;if(t.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");let i=this.extractVaaBytesFromAccumulatorMessage(t[0]),s=await this.verifyVaas([i],e);[r]=e.moveCall({target:`${o}::pyth::create_authenticated_price_infos_using_accumulator`,arguments:[e.object(this.pythStateId),e.pure(Oa.bcs.ser("vector<u8>",Array.from(t[0]),{maxSize:no}).toBytes()),s[0],e.object(lt.SUI_CLOCK_OBJECT_ID)]});let c=[],l=await this.getBaseUpdateFee(),d=e.splitCoins(e.gas,a.map(()=>e.pure(l))),p=0;for(let m=0;m<a.length;m++){let b=await this.getPriceFeedObjectId(a[m]);if(!b)throw new Error(`Price feed ${a[0]} not found, please create it first`);c.push(b),[r]=e.moveCall({target:`${o}::pyth::update_single_price_feed`,arguments:[e.object(this.pythStateId),r,e.object(b),d[p],e.object(lt.SUI_CLOCK_OBJECT_ID)]}),p++}return e.moveCall({target:`${o}::hot_potato_vector::destroy`,arguments:[r],typeArguments:[`${o}::price_info::PriceInfo`]}),c}async createPriceFeed(e,t){let a=await this.getPythPackageId();if(t.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");let o=this.extractVaaBytesFromAccumulatorMessage(t[0]),r=await this.verifyVaas([o],e);e.moveCall({target:`${a}::pyth::create_price_feeds_using_accumulator`,arguments:[e.object(this.pythStateId),e.pure(Oa.bcs.ser("vector<u8>",Array.from(t[0]),{maxSize:no}).toBytes()),r[0],e.object(lt.SUI_CLOCK_OBJECT_ID)]})}async getWormholePackageId(){return this.wormholePackageId||(this.wormholePackageId=await this.getPackageId(this.wormholeStateId)),this.wormholePackageId}async getPythPackageId(){return this.pythPackageId||(this.pythPackageId=await this.getPackageId(this.pythStateId)),this.pythPackageId}async getPriceFeedObjectId(e){let t=e.replace("0x","");if(!this.priceFeedObjectIdCache.has(t)){let{id:a,fieldType:o}=await this.getPriceTableInfo(),r=await this.provider.getDynamicFieldObject({parentId:a,name:{type:`${o}::price_identifier::PriceIdentifier`,value:{bytes:Array.from(Buffer.from(t,"hex"))}}});if(!r.data||!r.data.content)return;if(r.data.content.dataType!=="moveObject")throw new Error("Price feed type mismatch");this.priceFeedObjectIdCache.set(t,r.data.content.fields.value)}return this.priceFeedObjectIdCache.get(t)}async getPriceTableInfo(){if(this.priceTableInfo===void 0){let e=await this.provider.getDynamicFieldObject({parentId:this.pythStateId,name:{type:"vector<u8>",value:"price_info"}});if(!e.data||!e.data.type)throw new Error("Price Table not found, contract may not be initialized");let t=e.data.type.replace("0x2::table::Table<","");t=t.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>",""),this.priceTableInfo={id:e.data.objectId,fieldType:t}}return this.priceTableInfo}extractVaaBytesFromAccumulatorMessage(e){let a=7+e.readUint8(6)+1,o=e.readUint16BE(a),r=a+2;return e.subarray(r,r+o)}};var Ys=async(n,e)=>(await gi.default.get(`${n}/api/latest_vaas`,{params:{ids:e}})).data.map(o=>Buffer.from(o,"base64")),Da=async(n,e,t)=>{let a=t??[...new Set([...Se,...Ia])],o=n.isTestnet?["pyth"]:["pyth"];if(o.includes("pyth")){let i=new Pa(n.client,n.address.get("core.oracles.pyth.state"),n.address.get("core.oracles.pyth.wormholeState")),s=a.map(l=>n.address.get(`core.coins.${l}.oracle.pyth.feed`)),c=n.params.pythEndpoints??fi[n.isTestnet?"testnet":"mainnet"];try{let l=await Ys(c[0],s);await i.updatePriceFeeds(e,l,s)}catch(l){console.warn(`Failed to update price feeds with endpoint ${c[0]}: ${l}`)}}let r=[...new Set(a)];for(let i=0;i<r.length;i++)await Zs(n,e,r[i],o)},Zs=async(n,e,t,a)=>{let o=n.utils.parseCoinType(t);ec(e,a,n.address.get("core.packages.xOracle.id"),n.address.get("core.oracles.xOracle"),n.address.get("core.packages.pyth.id"),n.address.get("core.oracles.pyth.registry"),n.address.get("core.oracles.pyth.state"),n.address.get(`core.coins.${t}.oracle.pyth.feedObject`),n.address.get("core.packages.switchboard.id"),n.address.get("core.oracles.switchboard.registry"),n.address.get(`core.coins.${t}.oracle.switchboard`),n.address.get("core.packages.supra.id"),n.address.get("core.oracles.supra.registry"),n.address.get("core.oracles.supra.holder"),o)},ec=(n,e,t,a,o,r,i,s,c,l,d,p,m,b,f)=>{let y=tc(n,t,a,f);return e.includes("pyth")&&rc(n,o,y,i,s,r,f),e.includes("switchboard")&&oc(n,c,y,d,l,f),e.includes("supra")&&nc(n,p,y,b,m,f),ac(n,t,a,y,f),n},tc=(n,e,t,a)=>{let o=typeof t=="string"?n.object(t):t,r=`${e}::x_oracle::price_update_request`,i=[a];return n.moveCall({target:r,arguments:[o],typeArguments:i})},ac=(n,e,t,a,o)=>{let r=`${e}::x_oracle::confirm_price_update_request`,i=[o],s=typeof t=="string"?n.object(t):t;return n.moveCall({target:r,arguments:[s,a,n.object(ut.SUI_CLOCK_OBJECT_ID)],typeArguments:i}),n},nc=(n,e,t,a,o,r)=>{let i=typeof a=="string"?n.object(a):a,s=typeof o=="string"?n.object(o):o;n.moveCall({target:`${e}::rule::set_price`,arguments:[t,i,s,n.object(ut.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},oc=(n,e,t,a,o,r)=>{let i=typeof a=="string"?n.object(a):a,s=typeof o=="string"?n.object(o):o;n.moveCall({target:`${e}::rule::set_price`,arguments:[t,i,s,n.object(ut.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},rc=(n,e,t,a,o,r,i)=>{let s=typeof t=="string"?n.object(t):t,c=typeof a=="string"?n.object(a):a,l=typeof o=="string"?n.object(o):o,d=typeof r=="string"?n.object(r):r;n.moveCall({target:`${e}::rule::set_price`,arguments:[s,c,l,d,n.object(ut.SUI_CLOCK_OBJECT_ID)],typeArguments:[i]})};var _a=async(...n)=>{let[e,t,a,o]=n;if(n.length===3&&a)return{obligationId:a};if(n.length===4&&a&&o)return{obligationId:a,obligationKey:o};let r=D(e),i=await Me(t.query,r);if(i.length===0)throw new Error(`No obligation found for sender ${r}`);return{obligationId:i[0].id,obligationKey:i[0].keyId}},ic=({builder:n,txBlock:e})=>{let t={protocolPkg:n.address.get("core.packages.protocol.id"),market:n.address.get("core.market"),version:n.address.get("core.version"),coinDecimalsRegistry:n.address.get("core.coinDecimalsRegistry"),xOracle:n.address.get("core.oracles.xOracle")};return{openObligation:()=>e.moveCall({target:`${t.protocolPkg}::open_obligation::open_obligation`,arguments:[e.pure(t.version)]}),returnObligation:(a,o)=>e.moveCall({target:`${t.protocolPkg}::open_obligation::return_obligation`,arguments:[e.object(t.version),e.object(a),e.object(o)]}),openObligationEntry:()=>e.moveCall({target:`${t.protocolPkg}::open_obligation::open_obligation_entry`,arguments:[e.object(t.version)]}),addCollateral:(a,o,r)=>{let i=n.utils.parseCoinType(r);return e.moveCall({target:`${t.protocolPkg}::deposit_collateral::deposit_collateral`,arguments:[e.object(t.version),e.object(a),e.object(t.market),typeof o!="string"?o:e.pure(o)],typeArguments:[i]})},takeCollateral:(a,o,r,i)=>{let s=n.utils.parseCoinType(i);return e.moveCall({target:`${t.protocolPkg}::withdraw_collateral::withdraw_collateral`,arguments:[e.object(t.version),e.object(a),e.object(o),e.object(t.market),e.object(t.coinDecimalsRegistry),e.pure(r),e.object(t.xOracle),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[s]})},deposit:(a,o)=>{let r=n.utils.parseCoinType(o);return e.moveCall({target:`${t.protocolPkg}::mint::mint`,arguments:[e.object(t.version),e.object(t.market),typeof a!="string"?a:e.pure(a),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},depositEntry:(a,o)=>{let r=n.utils.parseCoinType(o);return e.moveCall({target:`${t.protocolPkg}::mint::mint_entry`,arguments:[e.object(t.version),e.object(t.market),typeof a!="string"?a:e.pure(a),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},withdraw:(a,o)=>{let r=n.utils.parseCoinType(o);return e.moveCall({target:`${t.protocolPkg}::redeem::redeem`,arguments:[e.object(t.version),e.object(t.market),typeof a!="string"?a:e.pure(a),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},withdrawEntry:(a,o)=>{let r=n.utils.parseCoinType(o);return e.moveCall({target:`${t.protocolPkg}::redeem::redeem_entry`,arguments:[e.object(t.version),e.object(t.market),typeof a!="string"?a:e.pure(a),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},borrow:(a,o,r,i)=>{let s=n.utils.parseCoinType(i);return e.moveCall({target:`${t.protocolPkg}::borrow::borrow`,arguments:[e.object(t.version),e.object(a),e.object(o),e.object(t.market),e.object(t.coinDecimalsRegistry),e.pure(r),e.object(t.xOracle),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[s]})},borrowEntry:(a,o,r,i)=>{let s=n.utils.parseCoinType(i);return e.moveCall({target:`${t.protocolPkg}::borrow::borrow_entry`,arguments:[e.object(t.version),e.object(a),e.object(o),e.object(t.market),e.object(t.coinDecimalsRegistry),e.pure(r),e.object(t.xOracle),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[s]})},repay:(a,o,r)=>{let i=n.utils.parseCoinType(r);return e.moveCall({target:`${t.protocolPkg}::repay::repay`,arguments:[e.object(t.version),e.object(a),e.object(t.market),typeof o!="string"?o:e.pure(o),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[i]})},borrowFlashLoan:(a,o)=>{let r=n.utils.parseCoinType(o);return e.moveCall({target:`${t.protocolPkg}::flash_loan::borrow_flash_loan`,arguments:[e.object(t.version),e.object(t.market),e.pure(a)],typeArguments:[r]})},repayFlashLoan:(a,o,r)=>{let i=n.utils.parseCoinType(r);return e.moveCall({target:`${t.protocolPkg}::flash_loan::repay_flash_loan`,arguments:[e.object(t.version),e.object(t.market),e.pure(a),e.object(o)],typeArguments:[i]})}}},L=({builder:n,txBlock:e})=>{let t=ic({builder:n,txBlock:e});return{normalMethod:t,addCollateralQuick:async(a,o,r)=>{let i=D(e),{obligationId:s}=await _a(e,n,r);if(o==="sui"){let[c]=e.splitCoins(e.gas,[a]);t.addCollateral(s,c,o)}else{let{leftCoin:c,takeCoin:l}=await n.selectCoin(e,o,a,i);t.addCollateral(s,l,o),e.transferObjects([c],i)}},takeCollateralQuick:async(a,o,r,i)=>{let s=await _a(e,n,r,i),c=await n.query.getObligationCoinNames(s.obligationId);return await Da(n,e,c),t.takeCollateral(s.obligationId,s.obligationKey,a,o)},depositQuick:async(a,o,r)=>{if(o==="sui"){let[c]=e.splitCoins(e.gas,[a]);return t.deposit(c,o)}let{leftCoin:i,takeCoin:s}=await n.selectCoin(e,o,a,r);return e.transferObjects([i],r),t.deposit(s,o)},withdrawQuick:async(a,o)=>{let r=D(e),i=n.utils.parseMarketCoinName(o),{leftCoin:s,takeCoin:c}=await n.selectMarketCoin(e,i,a,r);return e.transferObjects([s],r),t.withdraw(c,o)},borrowQuick:async(a,o,r,i)=>{let s=await _a(e,n,r,i),l=[...await n.query.getObligationCoinNames(s.obligationId),o];return await Da(n,e,l),t.borrow(s.obligationId,s.obligationKey,a,o)},repayQuick:async(a,o,r,i)=>{let s=await _a(e,n,r);if(o==="sui"){let[d]=e.splitCoins(e.gas,[a]);return t.repay(s.obligationId,d,o)}let{leftCoin:c,takeCoin:l}=await n.selectCoin(e,o,a,i);return e.transferObjects([c],i),t.repay(s.obligationId,l,o)},updateAssetPricesQuick:async a=>Da(n,e,a)}};var pt=require("@mysten/sui.js/utils");var hi=async(...n)=>{let[e,t,a,o]=n;if(n.length===4&&o)return[o];let r=D(t),i=await dt(e.query,r);if(i[a].length===0)throw new Error(`No stake account id found for sender ${r}`);return i[a].map(s=>s.id)},sc=async(...n)=>{let[e,t,a,o]=n,r=D(t),i=await dt(e.query,r);if(i[a].length===0)throw new Error(`No stake account found for sender ${r}`);return o?i[a].filter(c=>c.id===o):i[a]},cc=({builder:n,txBlock:e})=>{let t={spoolPkg:n.address.get("spool.id")};return{createStakeAccount:a=>{let o=n.utils.parseMarketCoinType(a),r=n.address.get(`spool.pools.${a}.id`);return e.moveCall({target:`${t.spoolPkg}::user::new_spool_account`,arguments:[e.object(r),e.object(pt.SUI_CLOCK_OBJECT_ID)],typeArguments:[o]})},stake:(a,o,r)=>{let i=n.utils.parseMarketCoinType(r),s=n.address.get(`spool.pools.${r}.id`);e.moveCall({target:`${t.spoolPkg}::user::stake`,arguments:[e.object(s),e.object(a),typeof o=="string"?e.pure(o):o,e.object(pt.SUI_CLOCK_OBJECT_ID)],typeArguments:[i]})},unstake:(a,o,r)=>{let i=n.utils.parseMarketCoinType(r),s=n.address.get(`spool.pools.${r}.id`);return e.moveCall({target:`${t.spoolPkg}::user::unstake`,arguments:[e.object(s),e.object(a),e.pure(o),e.object(pt.SUI_CLOCK_OBJECT_ID)],typeArguments:[i]})},claim:(a,o)=>{let r=n.address.get(`spool.pools.${o}.id`),i=n.address.get(`spool.pools.${o}.rewardPoolId`),s=n.utils.parseMarketCoinType(o),c=Ta[o],l=n.utils.parseCoinType(c);return e.moveCall({target:`${t.spoolPkg}::user::redeem_rewards`,arguments:[e.object(r),e.object(i),e.object(a),e.object(pt.SUI_CLOCK_OBJECT_ID)],typeArguments:[s,l]})}}},Ce=({builder:n,txBlock:e})=>{let t=cc({builder:n,txBlock:e});return{normalMethod:t,stakeQuick:async(a,o,r)=>{let i=D(e),s=await hi(n,e,o,r),c=n.utils.parseMarketCoinType(o);if(typeof a=="number"){let l=await n.utils.selectCoinIds(a,c,i),[d,p]=n.utils.takeAmountFromCoins(e,l,a);t.stake(s[0],d,o),e.transferObjects([p],i)}else t.stake(s[0],a,o)},unstakeQuick:async(a,o,r)=>{let i=a,s=await sc(n,e,o,r),c=[];for(let l=0;l<s.length;l++){if(s[l].staked===0)continue;let d=Math.min(i,s[l].staked),p=t.unstake(s[l].id,d,o);if(c.push(p),i-=d,i===0)break}return c},claimQuick:async(a,o)=>{let r=await hi(n,e,a,o),i=[];return r.forEach(s=>{let c=t.claim(s,a);i.push(c)}),i}}};var Fe=require("@mysten/sui.js/utils");var dc=({builder:n,txBlock:e})=>{let t={pkgId:n.address.get("vesca.id"),table:n.address.get("vesca.table"),treasury:n.address.get("vesca.treasury"),config:n.address.get("vesca.config")};return{lockSca:(a,o)=>e.moveCall({target:`${t.pkgId}::ve_sca::mint_ve_sca_key`,arguments:[e.object(t.config),e.object(t.table),e.object(t.treasury),typeof a=="string"?e.pure(a):a,e.pure(o),e.object(Fe.SUI_CLOCK_OBJECT_ID)]}),extendLockPeriod:(a,o)=>{e.moveCall({target:`${t.pkgId}::ve_sca::extend_lock_period`,arguments:[e.object(t.config),e.object(a),e.object(t.table),e.object(t.treasury),e.pure(o),e.object(Fe.SUI_CLOCK_OBJECT_ID)]})},extendLockAmount:(a,o)=>{e.moveCall({target:`${t.pkgId}::ve_sca::lock_more_sca`,arguments:[e.object(t.config),e.object(a),e.object(t.table),e.object(t.treasury),typeof o=="string"?e.pure(o):o,e.object(Fe.SUI_CLOCK_OBJECT_ID)]})},renewExpiredVeSca:(a,o,r)=>{e.moveCall({target:`${t.pkgId}::ve_sca::renew_expired_ve_sca`,arguments:[e.object(t.config),e.object(a),e.object(t.table),e.object(t.treasury),typeof o=="string"?e.pure(o):o,e.pure(r),e.object(Fe.SUI_CLOCK_OBJECT_ID)]})},redeemSca:a=>e.moveCall({target:`${t.pkgId}::ve_sca::redeem`,arguments:[e.object(t.config),e.object(a),e.object(t.table),e.object(t.treasury),e.object(Fe.SUI_CLOCK_OBJECT_ID)]})}},Ie=({builder:n,txBlock:e})=>{let t=dc({builder:n,txBlock:e});return{normalMethod:t,lockScaQuick:async(a,o,r=!0)=>{let i=D(e),s=await we(n,e),c,l=[];if(a!==void 0&&typeof a=="number"){let b=await n.utils.selectCoinIds(a,ce,i),[f,y]=n.utils.takeAmountFromCoins(e,b,a);c=f,l.push(y)}else c=a;let d=n.utils.getUnlockAt(o,s?.unlockAt);r&&Jr(a,o,d,s?.unlockAt),console.log(new Date(d*1e3).toLocaleString("en-CA",{hour12:!0}));let p=!s?.unlockAt,m=!p&&s.unlockAt*1e3<=new Date().getTime();if(p||m){if(c)if(p){let b=t.lockSca(c,d);l.push(b)}else{if(s.lockedScaAmount!==0){let b=t.redeemSca(s.keyId);l.push(b)}t.renewExpiredVeSca(s.keyId,c,d)}}else c&&o?(t.extendLockPeriod(s.keyId,d),t.extendLockAmount(s.keyId,c)):o?t.extendLockPeriod(s.keyId,d):c&&t.extendLockAmount(s.keyId,c);l.length>0&&e.transferObjects(l,i)},extendLockPeriodQuick:async(a,o,r=!0)=>{let i=await we(n,e,o),s=n.utils.getUnlockAt(a);r&&Xr(a,s,i?.unlockAt),i&&t.extendLockPeriod(i.keyId,s)},extendLockAmountQuick:async(a,o,r=!0)=>{let i=D(e),s=await we(n,e,o);if(r&&Yr(a,s?.unlockAt),s){let c=await n.utils.selectCoinIds(a,ce,i),[l,d]=n.utils.takeAmountFromCoins(e,c,a);t.extendLockAmount(s.keyId,l),e.transferObjects([d],i)}},renewExpiredVeScaQuick:async(a,o,r,i=!0)=>{let s=D(e),c=await we(n,e,r),l=n.utils.getUnlockAt(o,c?.unlockAt);if(i&&Zr(a,o,c?.unlockAt),c){let d=[];if(c.lockedScaAmount!==0){let f=t.redeemSca(c.keyId);d.push(f)}let p=await n.utils.selectCoinIds(a,ce,s),[m,b]=n.utils.takeAmountFromCoins(e,p,a);d.push(b),t.renewExpiredVeSca(c.keyId,m,l),e.transferObjects(d,s)}},redeemScaQuick:async a=>{let o=D(e),r=await we(n,e,a);if(Ee(r?.unlockAt),r){let i=t.redeemSca(r.keyId);e.transferObjects([i],o)}}}};var h=class{params;client;address;builder;query;utils;walletAddress;constructor(e,t){this.params=e,this.client=e.client,this.address=t?.address??new V({id:e?.addressesId||se,network:e?.networkType}),this.query=t?.query??new Le(e,{address:this.address}),this.utils=t?.utils??new ue(e,{address:this.address,query:this.query}),this.builder=t?.builder??new We(e,{address:this.address,query:this.query,utils:this.utils}),this.walletAddress=(0,yi.normalizeSuiAddress)(e.walletAddress)}init(e=!1){(e||!this.address.getAddresses())&&this.address.read(),this.builder.init(e,this.address),this.query.init(e,this.address),this.utils.init(e,this.address)}async getObligations(e){let t=e||this.walletAddress;return this.query.getObligations(t)}async getAllStakeAccounts(e){let t=e||this.walletAddress;return this.query.getAllStakeAccounts(t)}async getStakeAccounts(e,t){let a=t||this.walletAddress;return this.query.getStakeAccounts(e,a)}async getStakePool(e){return this.query.getStakePool(e)}async getStakeRewardPool(e){return this.query.getStakeRewardPool(e)}async openObligation(e){let t=new T.TransactionBlock,a=L({builder:this.builder,txBlock:t}),o=e||this.walletAddress;return t.setSender(o),a.normalMethod.openObligationEntry(),t}async depositCollateral(e,t,a,o){let r=new T.TransactionBlock,i=o||this.walletAddress;r.setSender(i);let s=L({builder:this.builder,txBlock:r}),c=await this.query.getObligations(i),l=a||c?.[0]?.id;if(l)await s.addCollateralQuick(t,e,l);else{let[d,p,m]=s.normalMethod.openObligation();await s.addCollateralQuick(t,e,d),s.normalMethod.returnObligation(d,m),r.transferObjects([p],i)}return r}async withdrawCollateral(e,t,a,o,r){let i=new T.TransactionBlock,s=L({builder:this.builder,txBlock:i}),c=r||this.walletAddress;i.setSender(c);let l=await s.takeCollateralQuick(t,e,a,o);return i.transferObjects([l],c),i}async deposit(e,t,a){let o=new T.TransactionBlock,r=L({builder:this.builder,txBlock:o}),i=a||this.walletAddress;o.setSender(i);let s=await r.depositQuick(t,e,a);return o.transferObjects([s],i),o}async withdraw(e,t,a){let o=new T.TransactionBlock,r=a||this.walletAddress,i=L({builder:this.builder,txBlock:o});o.setSender(r);let s=await i.withdrawQuick(t,e);return o.transferObjects([s],r),o}async borrow(e,t,a,o,r){let i=new T.TransactionBlock,s=L({builder:this.builder,txBlock:i}),c=M({builder:this.builder,txBlock:i}),l=r||this.walletAddress;i.setSender(l);let d=Ne.includes(e);d&&await c.unstakeObligationQuick(a,o);let p=await s.borrowQuick(t,e,a,o);return i.transferObjects([p],l),d&&await c.stakeObligationQuick(a,o),i}async borrowWithBoost(e,t,a,o,r,i){let s=new T.TransactionBlock,c=L({builder:this.builder,txBlock:s}),l=M({builder:this.builder,txBlock:s}),d=i||this.walletAddress;s.setSender(d);let p=Ne.includes(e);p&&await l.unstakeObligationQuick(a,o);let m=await c.borrowQuick(t,e,a,o);return s.transferObjects([m],d),p&&await l.stakeObligationWithVeScaQuick(a,o,r),s}async repay(e,t,a,o,r){let i=new T.TransactionBlock,s=L({builder:this.builder,txBlock:i}),c=M({builder:this.builder,txBlock:i}),l=r||this.walletAddress;i.setSender(l);let d=Ne.includes(e);return d&&await c.unstakeObligationQuick(a,o),await s.repayQuick(t,e,a,l),d&&await c.stakeObligationQuick(a,o),i}async createStakeAccount(e,t){let a=new T.TransactionBlock,o=Ce({builder:this.builder,txBlock:a}),r=t||this.walletAddress;a.setSender(r);let i=o.normalMethod.createStakeAccount(e);return a.transferObjects([i],r),a}async supplyAndStake(e,t,a,o){let r=new T.TransactionBlock,i=L({builder:this.builder,txBlock:r}),s=Ce({builder:this.builder,txBlock:r}),c=o||this.walletAddress;r.setSender(c);let l=await i.depositQuick(t,e,o),d=this.utils.parseMarketCoinName(e);if(!rt.find(b=>b===d))return r;let p=await this.query.getStakeAccounts(d,c),m=a||(p.length>0?p[0].id:void 0);if(m)await s.stakeQuick(l,d,m);else{let b=s.normalMethod.createStakeAccount(d);await s.stakeQuick(l,d,b),r.transferObjects([b],c)}return r}async unstakeAndWithdraw(e,t,a){let o=new T.TransactionBlock,r=L({builder:this.builder,txBlock:o}),i=Ce({builder:this.builder,txBlock:o}),s=this.walletAddress,c=[];o.setSender(s);let l=this.utils.parseMarketCoinName(e);for(let d=0;d<a.length;d++){let p=a[d],[m]=await i.unstakeQuick(p.coin,l,p.id);if(m){let b=r.normalMethod.withdraw(m,e);c.push(b)}}if(t>0){let d=await r.withdrawQuick(t,e);c.push(d)}return o.transferObjects(c,s),o}async stake(e,t,a,o){let r=new T.TransactionBlock,i=Ce({builder:this.builder,txBlock:r}),s=o||this.walletAddress;r.setSender(s);let c=await this.query.getStakeAccounts(e,s),l=a||(c.length>0?c[0].id:void 0);if(l)await i.stakeQuick(t,e,l);else{let d=i.normalMethod.createStakeAccount(e);await i.stakeQuick(t,e,d),r.transferObjects([d],s)}return r}async unstake(e,t,a,o){let r=new T.TransactionBlock,i=Ce({builder:this.builder,txBlock:r}),s=o||this.walletAddress;r.setSender(s);let c=await i.unstakeQuick(t,e,a);return r.transferObjects(c,s),r}async claim(e,t,a,o){let r=new T.TransactionBlock,i=Ce({builder:this.builder,txBlock:r}),s=M({builder:this.builder,txBlock:r}),c=o||this.walletAddress;r.setSender(c);let l={sui:[],sca:[]};for(let d=0;d<e.length;d++){let{stakeMarketCoinName:p,stakeAccountId:m}=e[d],b=i.normalMethod.claim(m,p);l.sui.push(b)}for(let d=0;d<t.length;d++){let{obligationId:p,obligationKey:m,rewardCoinName:b}=t[d],f=s.normalMethod.claimBorrowIncentive(p,m,b);l[b].push(f)}for(let d=0;d<a.length;d++){let{obligationId:p,obligationKey:m,rewardCoinName:b}=a[d],f=s.normalMethod.oldClaimBorrowIncentive(p,m,b);l[b].push(f)}return l.sui.length>0&&(l.sui.length>1&&r.mergeCoins(l.sui[0],l.sui.slice(1)),r.transferObjects([l.sui[0]],r.pure(c))),l.sca.length>0&&(l.sca.length>1&&r.mergeCoins(l.sca[0],l.sca.slice(1)),r.transferObjects([l.sca[0]],r.pure(c))),r}async stakeObligation(e,t,a){let o=this.builder.createTxBlock(),r=M({builder:this.builder,txBlock:o}),i=a||this.walletAddress;return o.setSender(i),await r.stakeObligationQuick(e,t),o}async unstakeObligation(e,t,a){let o=this.builder.createTxBlock(),r=M({builder:this.builder,txBlock:o}),i=a||this.walletAddress;return o.setSender(i),await r.unstakeObligationQuick(e,t),o}async stakeSca(e,t=!1,a=!1,o,r,i,s,c){let l=new T.TransactionBlock,d=Ie({builder:this.builder,txBlock:l}),p=M({builder:this.builder,txBlock:l}),m=c||this.walletAddress;l.setSender(m);let b=await this.builder.utils.selectCoinIds(e,ce,m),[f,y]=this.builder.utils.takeAmountFromCoins(l,b,e),C;return s?d.normalMethod.extendLockAmount(s,f):C=d.normalMethod.lockSca(f,i),o&&r&&(t&&(a?p.normalMethod.oldUnstakeObligation(o,r):p.normalMethod.unstakeObligation(o,r)),p.normalMethod.stakeObligationWithVesca(o,r,s||C)),s||l.transferObjects([C,y],m),l}async stakeMoreSca(e,t,a){let o=new T.TransactionBlock,r=a||this.walletAddress;return o.setSender(r),o}async extendStakeScaLockPeriod(e,t,a,o,r=!1,i=!1,s){let c=new T.TransactionBlock,l=Ie({builder:this.builder,txBlock:c}),d=M({builder:this.builder,txBlock:c}),p=s||this.walletAddress;return c.setSender(p),l.normalMethod.extendLockPeriod(t,e),a&&o&&(r&&(i?d.normalMethod.oldUnstakeObligation(a,o):d.normalMethod.unstakeObligation(a,o)),d.normalMethod.stakeObligationWithVesca(a,o,t)),c}async extendPeriodAndStakeMoreSca(e,t,a,o,r,i=!1,s=!1,c){let l=new T.TransactionBlock,d=Ie({builder:this.builder,txBlock:l}),p=M({builder:this.builder,txBlock:l}),m=c||this.walletAddress;l.setSender(m);let b=await this.builder.utils.selectCoinIds(e,ce,m),[f,y]=this.builder.utils.takeAmountFromCoins(l,b,e);return d.normalMethod.extendLockPeriod(t,a),d.normalMethod.extendLockAmount(t,f),l.transferObjects([y],m),!o||!r||(i&&(s?p.normalMethod.oldUnstakeObligation(o,r):p.normalMethod.unstakeObligation(o,r)),p.normalMethod.stakeObligationWithVesca(o,r,t)),l}async renewExpiredStakeSca(e,t,a,o=!1,r,i,s=!1,c=!1,l){let d=new T.TransactionBlock,p=Ie({builder:this.builder,txBlock:d}),m=M({builder:this.builder,txBlock:d}),b=l||this.walletAddress;if(d.setSender(b),o){let _=p.normalMethod.redeemSca(a);d.transferObjects([_],b)}let f=await this.builder.utils.selectCoinIds(e,ce,b),[y,C]=this.builder.utils.takeAmountFromCoins(d,f,e);return d.transferObjects([C],b),p.normalMethod.renewExpiredVeSca(a,y,t),!r||!i||(s&&(c?m.normalMethod.oldUnstakeObligation(r,i):m.normalMethod.unstakeObligation(r,i)),m.normalMethod.stakeObligationWithVesca(r,i,a)),d}async redeemSca(e){let t=new T.TransactionBlock,a=Ie({builder:this.builder,txBlock:t}),o=this.walletAddress;return t.setSender(o),await a.redeemScaQuick(e),t}async migrateAndClaim(e,t,a,o){let r=new T.TransactionBlock,i=M({builder:this.builder,txBlock:r}),s=this.walletAddress;r.setSender(s);let c=i.normalMethod.oldClaimBorrowIncentive(a,t,o);return r.transferObjects([c],s),i.stakeObligationWithVeScaQuick(a,t,e),r}async withdrawUnlockedSca(e,t){let a=new T.TransactionBlock,o=Ie({builder:this.builder,txBlock:a}),r=t||this.walletAddress;return a.setSender(r),await o.redeemScaQuick(e),a}calculateAvailableClaimCoin(e,t){let a=new oo.default(e.weightedAmount),r=t.currentPointIndex?(0,oo.default)(t.currentPointIndex-e.index).dividedBy(1e9):1;return a.multipliedBy(r).plus(e.points).shiftedBy(-1*t.coinDecimal)}};var ja=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.borrow(this.data.coinName,Number(this.data.amount),this.data.obligationId,this.data.obligationKey,t.account.address)}static fromData(t){return new n(t)}};var Ba=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return await a.init(),a.borrowWithBoost(this.data.coinName,Number(this.data.amount),this.data.obligationId,this.data.obligationKey,this.data.veScaKey,t.account.address)}static fromData(t){return new n(t)}};var Ra=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.claim(this.data.lendingIncentive,this.data.borrowIncentiveV2,this.data.borrowIncentive,t.account.address)}static fromData(t){return new n(t)}};var Na=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.depositCollateral(this.data.collateralCoinName,Number(this.data.amount),this.data.obligationId,t.account.address)}static fromData(t){return new n(t)}};var Ea=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.extendPeriodAndStakeMoreSca(this.data.amount,this.data.veScaKey,this.data.lockPeriodInDays,this.data.obligationId,this.data.obligationKey,this.data.isObligationLocked,this.data.isOldBorrowIncentive,t.account.address)}static fromData(t){return new n(t)}};var Ma=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.extendStakeScaLockPeriod(this.data.lockPeriodInDays,this.data.veScaKey,this.data.obligationId,this.data.obligationKey,this.data.isObligationLocked,this.data.isOldBorrowIncentive,t.account.address)}static fromData(t){return new n(t)}};var La=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return await a.init(),a.migrateAndClaim(this.data.veScaKey,this.data.obligationKey,this.data.obligationId,this.data.rewardCoinName)}static fromData(t){return new n(t)}};var Wa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.openObligation()}static fromData(t){return new n(t)}};var Fa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.redeemSca(this.data.veScaKey)}static fromData(t){return new n(t)}};var Ua=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.renewExpiredStakeSca(this.data.amount,this.data.lockPeriodInDays,this.data.vescaKey,this.data.isHaveRedeem,this.data.obligation,this.data.obligationKey,this.data.isObligationLocked,this.data.isOldBorrowIncentive,t.account.address)}static fromData(t){return new n(t)}};var qa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.repay(this.data.coinName,Number(this.data.amount),this.data.obligationId,this.data.obligationKey,t.account.address)}static fromData(t){return new n(t)}};var $a=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.stakeSca(this.data.amount,this.data.isObligationLocked,this.data.isOldBorrowIncentive,this.data.obligationId,this.data.obligationKey,this.data.lockPeriodInDays,this.data.veScaKey,t.account.address)}static fromData(t){return new n(t)}};var Qa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.stake(this.data.marketCoinName,Number(this.data.amount),void 0,t.account.address)}static fromData(t){return new n(t)}};var Va=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.supplyAndStake(this.data.coinName,Number(this.data.amount),this.data.stakeAccountId,t.account.address)}static fromData(t){return new n(t)}};var Ga=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.deposit(this.data.coinName,Number(this.data.amount),t.account.address)}static fromData(t){return new n(t)}};var Ka=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.unstake(this.data.marketCoinName,Number(this.data.amount),void 0,t.account.address)}static fromData(t){return new n(t)}};var Ha=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.unstakeAndWithdraw(this.data.coinName,Number(this.data.amount),this.data.stakeAccountId)}static fromData(t){return new n(t)}};var za=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.withdrawCollateral(this.data.collateralCoinName,Number(this.data.amount),this.data.obligationId,this.data.obligationKey,t.account.address)}static fromData(t){return new n(t)}};var Ja=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.withdraw(this.data.coinName,Number(this.data.amount),t.account.address)}static fromData(t){return new n(t)}};var Xa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.withdrawUnlockedSca(this.data.vescaKey,t.account.address)}static fromData(t){return new n(t)}};var Ya=class{application="scallop";async deserialize(e){let t=new We({client:e.suiClient,walletAddress:e.account.address,networkType:e.network.split(":")[1]});await t.init();let{transactionBlock:a}=e,r=new xa(a,t).decode();return{txType:Si.TransactionType.Other,txSubType:r.type,intentionData:r.intentionData}}async build(e){let{suiClient:t,account:a,network:o}=e,r;switch(e.txSubType){case"SupplyLending":r=Ga.fromData(e.intentionData);break;case"WithdrawLending":r=Ja.fromData(e.intentionData);break;case"Borrow":r=ja.fromData(e.intentionData);break;case"Repay":r=qa.fromData(e.intentionData);break;case"DepositCollateral":r=Na.fromData(e.intentionData);break;case"WithdrawCollateral":r=za.fromData(e.intentionData);break;case"OpenObligation":r=Wa.fromData(e.intentionData);break;case"StakeSpool":r=Qa.fromData(e.intentionData);break;case"UnstakeSpool":r=Ka.fromData(e.intentionData);break;case"ClaimIncentiveReward":r=Ra.fromData(e.intentionData);break;case"BorrowWithBoost":r=Ba.fromData(e.intentionData);break;case"StakeSca":r=$a.fromData(e.intentionData);break;case"ExtendStakePeriod":r=Ma.fromData(e.intentionData);break;case"ExtendPeriodAndStakeMore":r=Ea.fromData(e.intentionData);break;case"RenewExpStakePeriod":r=Ua.fromData(e.intentionData);break;case"WithdrawStakedSca":r=Xa.fromData(e.intentionData);break;case"SupplyAndStakeLending":r=Va.fromData(e.intentionData);break;case"WithdrawAndUnstakeLending":r=Ha.fromData(e.intentionData);break;case"RedeemSca":r=Fa.fromData(e.intentionData);break;case"MigrateAndClaim":r=La.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:a,network:o})}};var Ui=require("@msafe/sui3-utils"),qi=require("turbos-clmm-sdk");var B=require("@msafe/sui3-utils"),ro=require("@mysten/sui.js/bcs"),me=require("@mysten/sui.js/utils"),wi=require("turbos-clmm-sdk");var W={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},F={PackageId:"0xdee9"};var uc=(n,e,t,a)=>{if(n===1)switch(a.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}`)}},Za=class{constructor(e,t,a){this.txb=e;this.turbosSdk=t;this.config=a}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`]}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(a=>a.kind==="MoveCall"&&a.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(`${W.PackageId}::claim::join`)}isPrixClaimTransaction(){return!!this.getMoveCallTransaction(`${W.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`)}decodeSwap(){let e=this.transactions.find(m=>m.kind==="MoveCall"),t=0;this.swap2Layer.includes(e.target)&&(t=1);let a=uc(t,e.target,this.swap1Layer,this.swap2Layer),o=a.map((m,b)=>{let f=this.helper.decodeSharedObjectId(b),y=this.helper.decodeInputU128(4+b+t),C=this.turbosSdk.math.sqrtPriceX64ToTickIndex(new wi.BN(y.toString()));return{pool:f,a2b:m,nextTickIndex:C}}),r=a[0]||t===1?e.typeArguments[0]:e.typeArguments[1],i=t===1?e.typeArguments[4]:a[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),p=this.helper.decodeInputU64(3+t);return{txType:B.TransactionType.Other,type:"Swap",intentionData:{routes:o,coinTypeA:r,coinTypeB:i,address:s,amountA:l?d:p,amountB:l?p:d,amountSpecifiedIsInput:l,slippage:"0.1",deadline:c}}}decodeAddLiquidity(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeInputAddress(12),a=this.helper.decodeInputU64(8),o=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:B.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:10,address:t,amountA:a,amountB:o,tickLower:i?-r:r,tickUpper:c?-s:s,deadline:l}}}decodeIncreaseLiquidity(e){let t=this.helper.decodeSharedObjectId(0),a=this.helper.decodeSharedObjectId(4),o=this.helper.decodeInputU64(5),r=this.helper.decodeInputU64(6),i=this.helper.decodeInputU64(9);return{txType:B.TransactionType.Other,type:"IncreaseLiquidity",intentionData:{pool:t,slippage:10,address:e,amountA:o,amountB:r,nft:a,deadline:i}}}decodeDecreaseLiquidity(e){let t=this.helper.decodeSharedObjectId(0),a=this.helper.decodeSharedObjectId(2),o=this.helper.decodeInputU64(3),r=this.helper.decodeInputU64(4),i=this.helper.decodeInputU64(5),s=this.helper.decodeInputU64(6);return{txType:B.TransactionType.Other,type:"DecreaseLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:a,amountA:r,amountB:i,slippage:10,address:e,deadline:s}}}decodeCollectFee(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2),a=this.helper.decodeInputAddress(5),o=this.helper.decodeInputU64(3),r=this.helper.decodeInputU64(4),i=this.helper.decodeInputU64(6);return{txType:B.TransactionType.Other,type:"CollectFee",intentionData:{pool:e,address:a,collectAmountA:o,collectAmountB:r,nft:t,deadline:i}}}decodeCollectReward(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2),a=this.helper.decodeInputAddress(6),o=this.collectRewardHelper.map(i=>i.decodeInputU64(5)),r=this.helper.decodeInputU64(7);return{txType:B.TransactionType.Other,type:"CollectReward",intentionData:{pool:e,address:a,rewardAmounts:o,nft:t,deadline:r}}}decodeBurn(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2);return{txType:B.TransactionType.Other,type:"Burn",intentionData:{pool:e,nft:t}}}decodeRemoveLiquidity(e){let t=this.decreaseLiquidityHelper.decodeSharedObjectId(0),a=this.decreaseLiquidityHelper.decodeSharedObjectId(2),o=this.decreaseLiquidityHelper.decodeInputU64(3),r=this.decreaseLiquidityHelper.decodeInputU64(4),i=this.decreaseLiquidityHelper.decodeInputU64(5),s=this.decreaseLiquidityHelper.decodeInputU64(6),c=this.collectRewardHelper.map(p=>p.decodeInputU64(5)),l=this.collectFeeHelper.decodeInputU64(3)||0,d=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:B.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:a,amountA:r,amountB:i,slippage:10,address:e,collectAmountA:l,collectAmountB:d,rewardAmounts:c,deadline:s}}}decodePrixClaim(){return{txType:B.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:B.TransactionType.Other,type:"PrixJoin",intentionData:{}}}decodeSwapExactBaseForQuote(){let e=this.swapExactBaseForQuoteHelper.decodeSharedObjectId(0),t=this.swapExactBaseForQuoteHelper.decodeInputU64(3),a=this.swapExactBaseForQuoteHelper.shortTypeArg(0),o=this.swapExactBaseForQuoteHelper.shortTypeArg(1);return{txType:B.TransactionType.Other,type:"SwapExactBaseForQuote",intentionData:{poolId:e,amountIn:t,token1:a,token2:o}}}decodeSwapExactQuoteForBase(){let e=this.swapExactQuoteForBaseHelper.decodeSharedObjectId(0),t=this.swapExactQuoteForBaseHelper.decodeInputU64(3),a=this.swapExactQuoteForBaseHelper.shortTypeArg(0),o=this.swapExactQuoteForBaseHelper.shortTypeArg(1);return{txType:B.TransactionType.Other,type:"SwapExactQuoteForBase",intentionData:{poolId:e,amountIn:t,token1:a,token2:o}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target!=="0x2::coin::zero");return new pe(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 pe(t,this.txb))}get collectFeeHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::collect`);return new pe(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 pe(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 pe(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 pe(e,this.txb)}},pe=class n{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return n.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return n.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,me.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let a=this.getInputParam(e);return n.getPureInputValue(a,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 a=e.value.Pure;return ro.bcs.de(t,new Uint8Array(a))}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,me.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,me.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,me.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,me.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 a=e.value.Pure;return ro.bcs.de(t,new Uint8Array(a))}typeArg(e){return(0,me.normalizeStructTag)(this.moveCall.typeArguments[e])}shortTypeArg(e){return this.moveCall.typeArguments[e]}txArg(e){return this.moveCall.arguments[e]}};var Ci=require("turbos-clmm-sdk"),en=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Ci.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,amountA:i,amountB:s,slippage:c,tickLower:l,tickUpper:d,deadline:p,txb:m}=this.data;return a.pool.addLiquidity({pool:o,slippage:c,address:r,amountA:i,amountB:s,tickLower:l,tickUpper:d,deadline:p,txb:m})}static fromData(t){return new n(t)}};var Ii=require("turbos-clmm-sdk");var tn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Ii.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,nft:r,txb:i}=this.data;return a.nft.burn({pool:o,nft:r,txb:i})}static fromData(t){return new n(t)}};var Ti=require("turbos-clmm-sdk");var an=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Ti.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,nft:i,collectAmountA:s,collectAmountB:c,deadline:l,txb:d}=this.data;return a.pool.collectFee({pool:o,address:r,collectAmountA:s,collectAmountB:c,nft:i,deadline:l,txb:d})}static fromData(t){return new n(t)}};var ki=require("turbos-clmm-sdk");var nn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new ki.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,nft:i,rewardAmounts:s,deadline:c,txb:l}=this.data;return a.pool.collectReward({pool:o,address:r,rewardAmounts:s,nft:i,deadline:c,txb:l})}static fromData(t){return new n(t)}};var xi=require("turbos-clmm-sdk");var on=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new xi.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:o,address:r,tickLower:i,tickUpper:s,sqrtPrice:c,slippage:l,coinTypeA:d,coinTypeB:p,amountA:m,amountB:b,deadline:f,txb:y}=this.data;return a.pool.createPool({fee:o,amountA:m,amountB:b,address:r,tickLower:i,tickUpper:s,sqrtPrice:c,slippage:l,coinTypeA:d,coinTypeB:p,deadline:f,txb:y})}static fromData(t){return new n(t)}};var vi=require("turbos-clmm-sdk");var rn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new vi.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,amountA:i,amountB:s,slippage:c,nft:l,decreaseLiquidity:d,deadline:p,txb:m}=this.data;return a.pool.decreaseLiquidity({pool:o,slippage:c,address:r,amountA:i,amountB:s,nft:l,decreaseLiquidity:d,deadline:p,txb:m})}static fromData(t){return new n(t)}};var Ai=require("turbos-clmm-sdk");var sn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Ai.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,amountA:i,amountB:s,slippage:c,nft:l,deadline:d,txb:p}=this.data;return a.pool.increaseLiquidity({pool:o,slippage:c,address:r,amountA:i,amountB:s,nft:l,deadline:d,txb:p})}static fromData(t){return new n(t)}};var Oi=require("@mysten/sui.js/transactions");var Pi=require("@mysten/sui.js/utils"),cn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Oi.TransactionBlock;return a.moveCall({target:`${W.PackageId}::claim::claim`,typeArguments:[W.turbosCoinType],arguments:[a.object(W.Claim),a.object(Pi.SUI_CLOCK_OBJECT_ID)]}),a}static fromData(t){return new n(t)}};var Di=require("@mysten/sui.js/transactions");var dn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Di.TransactionBlock;return a.moveCall({target:`${W.PackageId}::claim::join`,typeArguments:[W.turbosCoinType],arguments:[a.object(W.Claim)]}),a}static fromData(t){return new n(t)}};var _i=require("@mysten/sui.js/transactions"),ji=require("turbos-clmm-sdk");var ln=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new ji.TurbosSdk(t.network.replace("sui:",""),t.suiClient),o=new _i.TransactionBlock;return o=await a.pool.collectFee({txb:o,...this.data}),o=await a.pool.collectReward({txb:o,...this.data}),o=await a.pool.decreaseLiquidity({txb:o,...this.data}),o=await a.nft.burn({txb:o,nft:this.data.nft,pool:this.data.pool}),o}static fromData(t){return new n(t)}};var Bi=require("turbos-clmm-sdk"),un=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(this.data,"this.data");let a=new Bi.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:o,coinTypeA:r,coinTypeB:i,address:s,amountA:c,amountB:l,slippage:d,amountSpecifiedIsInput:p,deadline:m,txb:b}=this.data;return a.trade.swap({routes:o,coinTypeA:r,coinTypeB:i,address:s,amountA:c,amountB:l,amountSpecifiedIsInput:p,slippage:d,deadline:m,txb:b})}static fromData(t){return new n(t)}};var Wi=require("turbos-clmm-sdk");var io=require("@mysten/sui.js/utils"),so=require("@mysten/sui.js/transactions");var Ri=require("turbos-clmm-sdk");var mt=class{constructor(e){this.turbosSdk=e}async getCoinsData(e,t,a){let o=[],r;do r=await this.turbosSdk.provider.getCoins({owner:e,coinType:t,cursor:r?.nextCursor}),o.push(...r.data);while(r.hasNextPage);let i=[],s=0;return o.sort((c,l)=>Number(l.balance)-Number(c.balance)).some(c=>s>=a?!0:(s+=Number(c.balance),i.push(c),!1)),i}splitAndMergeCoin(e,t,a){if(!e||e.length<1)return[void 0,void 0];if(this.isSuiCoinAddress(e[0].coinType)){let[i]=a.splitCoins(a.gas,[a.pure(t)]);return[i,void 0]}let o=a.object(e[0].coinObjectId);e.length>1&&a.mergeCoins(o,e.slice(1).map(i=>a.object(i.coinObjectId)));let[r]=a.splitCoins(o,[a.pure(t)]);return[r,o]}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,Ri.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 Ni=89,Ei=1e6,Mi=async n=>{let{token1:e,token2:t,poolId:a,amountIn:o,currentAddress:r,turbosSdk:i}=n,s=new so.TransactionBlock,c=new mt(i),l=await c.getCoinsData(r,t,o),[d,p]=c.splitAndMergeCoin(l,o,s);if(!d)throw new Error(`Not enough balance: ${t}`);let m=await c.IsAccountCap(r),b=m?s.object(m):c.createAccount(s),[f,y,C]=s.moveCall({typeArguments:[e,t],target:`${F.PackageId}::clob_v2::swap_exact_quote_for_base`,arguments:[s.object(String(a)),s.pure(Ni),b,s.pure(o),s.object((0,io.normalizeSuiObjectId)("0x6")),d]});return p&&s.transferObjects([p],s.pure(r)),s.transferObjects([f],s.pure(r)),s.transferObjects([y],s.pure(r)),m||s.transferObjects([b],s.pure(r)),s.setSenderIfNotSet(r),s.setGasBudget(Ei),s},Li=async n=>{let{token1:e,token2:t,poolId:a,amountIn:o,currentAddress:r,turbosSdk:i}=n,s=new so.TransactionBlock,c=new mt(i),l=await c.getCoinsData(r,e,o),[d,p]=c.splitAndMergeCoin(l,o,s);if(!d)throw new Error(`Not enough balance: ${e}`);let m=await c.IsAccountCap(r),b=m?s.object(m):c.createAccount(s),f=c.zero(t,s),[y,C,_]=s.moveCall({typeArguments:[e,t],target:`${F.PackageId}::clob_v2::swap_exact_base_for_quote`,arguments:[s.object(String(a)),s.pure(Ni),b,s.pure(o),d,f,s.object((0,io.normalizeSuiObjectId)("0x6"))]});return p&&s.transferObjects([p],s.pure(r)),s.transferObjects([y],s.pure(r)),s.transferObjects([C],s.pure(r)),m||s.transferObjects([b],s.pure(r)),s.setSenderIfNotSet(r),s.setGasBudget(Ei),s};var pn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Wi.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Li({...this.data,turbosSdk:a,currentAddress:t.account.address})}static fromData(t){return new n(t)}};var Fi=require("turbos-clmm-sdk");var mn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Fi.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Mi({...this.data,turbosSdk:a,currentAddress:t.account.address})}static fromData(t){return new n(t)}};var bn=class{application="turbos";async deserialize(e){let t=new qi.TurbosSdk(e.network.replace("sui:",""),e.suiClient),a=await t.contract.getConfig(),{transactionBlock:o,account:r}=e;console.log(e,"input");let s=new Za(o,t,a).decode(r.address);return{txType:Ui.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{suiClient:t,account:a,network:o}=e,r;switch(console.log(e.intentionData,"intentionData"),e.txSubType){case"CreatePool":r=on.fromData(e.intentionData);break;case"AddLiquidity":r=en.fromData(e.intentionData);break;case"IncreaseLiquidity":r=sn.fromData(e.intentionData);break;case"DecreaseLiquidity":r=rn.fromData(e.intentionData);break;case"RemoveLiquidity":r=ln.fromData(e.intentionData);break;case"CollectFee":r=an.fromData(e.intentionData);break;case"CollectReward":r=nn.fromData(e.intentionData);break;case"Burn":r=tn.fromData(e.intentionData);break;case"Swap":r=un.fromData(e.intentionData);break;case"PrixJoin":r=dn.fromData(e.intentionData);break;case"PrixClaim":r=cn.fromData(e.intentionData);break;case"SwapExactBaseForQuote":r=pn.fromData(e.intentionData);break;case"SwapExactQuoteForBase":r=mn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:a,network:o})}};var Gi=require("@msafe/sui3-utils");var fn=require("@msafe/sui3-utils"),co=require("@mysten/sui.js/bcs"),be=require("@mysten/sui.js/utils");var pc={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},k=pc;var gn=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(`${k.packageId}::native_pool::stake`)}isUnStakeTransaction(){return!!this.getMoveCallTransaction(`${k.packageId}::native_pool::unstake`)}isClaimTicketTransaction(){return!!this.getMoveCallTransaction(`${k.packageId}::native_pool::burn_ticket`)}decodeStake(){let e=this.transactions[0].amounts[0].value.toNumber();return{txType:fn.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(a=>a.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:fn.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:fn.TransactionType.Other,type:"ClaimTicket",intentionData:{ticketId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(k.packageId));return new lo(e,this.txb)}},lo=class n{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return n.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return n.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,be.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let a=this.getInputParam(e);return n.getPureInputValue(a,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 a=e.value.Pure;return co.bcs.de(t,new Uint8Array(a))}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,be.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,be.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,be.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,be.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 a=e.value.Pure;return co.bcs.de(t,new Uint8Array(a))}typeArg(e){return(0,be.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var $i=require("@mysten/sui.js/transactions");var hn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let a=new $i.TransactionBlock,{ticketId:o}=this.data;return a.moveCall({target:`${k.packageId}::native_pool::burn_ticket`,arguments:[a.object(k.poolObjectId),a.object(k.systemStateObjectId),a.object(o)]}),a.setGasBudget(k.gasBudget),a}static fromData(t){return new n(t)}};var Qi=require("@mysten/sui.js/transactions");var yn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let a=new Qi.TransactionBlock,{amount:o}=this.data,[r]=a.splitCoins(a.gas,[a.pure(o)]);return a.moveCall({target:`${k.packageId}::native_pool::stake`,arguments:[a.object(k.poolObjectId),a.object(k.metadataObjectId),a.object(k.systemStateObjectId),r]}),a.setGasBudget(k.gasBudget),a}static fromData(t){return new n(t)}};var Vi=require("@mysten/sui.js/transactions");var Sn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let a=new Vi.TransactionBlock,{amount:o}=this.data,r=(await t.suiClient.getAllCoins({owner:t.account.address,limit:100})).data,[i,...s]=r.filter(d=>d.coinType.split("::")[0]===k.certType.split("::")[0]),c=a.object(i.coinObjectId);s.length&&a.mergeCoins(c,s.map(d=>a.object(d.coinObjectId)));let l=a.splitCoins(a.object(i.coinObjectId),[a.pure(o)]);return a.moveCall({target:`${k.packageId}::native_pool::unstake`,arguments:[a.object(k.poolObjectId),a.object(k.metadataObjectId),a.object(k.systemStateObjectId),l]}),a.setGasBudget(k.gasBudget),a}static fromData(t){return new n(t)}};var wn=class{application="volo";async deserialize(e){let{transactionBlock:t}=e,o=new gn(t).decode();return{txType:Gi.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:a}=e,o;switch(e.txSubType){case"Stake":o=yn.fromData(e.intentionData);break;case"UnStake":o=Sn.fromData(e.intentionData);break;case"ClaimTicket":o=hn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:a})}};var bc=new wa([new sa,new ga,new na,new ha,new Rt,new bn,new Ya,new wn]);
|
|
1
|
+
"use strict";var as=Object.create;var bt=Object.defineProperty;var ns=Object.getOwnPropertyDescriptor;var os=Object.getOwnPropertyNames;var rs=Object.getPrototypeOf,is=Object.prototype.hasOwnProperty;var In=(n,e)=>{for(var t in e)bt(n,t,{get:e[t],enumerable:!0})},mo=(n,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of os(e))!is.call(n,o)&&o!==t&&bt(n,o,{get:()=>e[o],enumerable:!(a=ns(e,o))||a.enumerable});return n};var q=(n,e,t)=>(t=n!=null?as(rs(n)):{},mo(e||!n||!n.__esModule?bt(t,"default",{value:n,enumerable:!0}):t,n)),ss=n=>mo(bt({},"__esModule",{value:!0}),n);var kc={};In(kc,{appHelpers:()=>Ic});module.exports=ss(kc);var cr=require("@msafe/sui3-utils");var To=require("@msafe/sui3-utils");var bo=q(require("sort-keys-recursive")),u=class{constructor(e){this.data=e}get application(){return"msafe-core"}serialize(){return JSON.stringify((0,bo.default)(this.data))}};var fo=require("@cetusprotocol/cetus-periphery-sdk"),go=require("@cetusprotocol/cetus-sui-clmm-sdk"),cs={fullRpcUrl:"https://fullnode.mainnet.sui.io/",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:"0xc33c3e937e5aa2009cc0c3fdb3f345a0c3193d4ee663ffc601fe8b894fbc4ba6",version:4,config:{pools_id:"0xf699e7f2276f5c9a75944b37a0c5b5d9ddfd2471bf6242483b03ab2887d198d0",global_config_id:"0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",global_vault_id:"0xce7bceef26d3ad1f6d9b6f13a953f053e6ed3ca77907516481ce99ae8e588f2b",admin_cap_id:"0x89c1a321291d15ddae5a086c9abc533dff697fde3d89e0ca836c41af73e36a75"}},integrate:{package_id:"0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",published_at:"0xd43348b8879c1457f882b02555ba862f2bc87bcc31b16294ca14a82f608875d2",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"},ds={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:"0xcec352932edc6663a118e8d64ed54da6b8107e8719603bf728f80717592cd9e8",version:3,config:{dividend_manager_id:"0x721c990bfc031d074341c6059a113a59c1febfbd2faeb62d49dcead8408fa6b5",dividend_admin_id:"",dividend_settle_id:""}},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:"0xd3453d9be7e35efe222f78a810bb3af1859fd1600926afced8b4936d825c9a05",version:1,config:{admin_cap_id:"0x78a42978709c4032fab7b33b782b5bcef64c1c6603250bf23644650b72144375",vaults_manager_id:"0x25b82dd2f5ee486ed1c8af144b89a8931cd9c29dee3a86a1bfe194fdea9d04a6",vaults_pool_handle:"0x9036bcc5aa7fd2cceec1659a6a1082871f45bc400c743f50063363457d1738bd"}},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:"0x11ea791d82b5742cc8cab0bf7946035c97d9001d7c3803a93f119753da66f526",version:1,config:{global_config_id:"0x21215f2f6de04b57dd87d9be7bb4e15499aec935e36078e2488f36436d64996e",rewarder_manager_id:"0xe0e155a88c77025056da08db5b1701a91b79edb6167462f768e387c3ed6614d5",rewarder_manager_handle:"0xb32e312cbb3367d6f3d2b4e57c9225e903d29b7b9f612dae2ddf75bdeb26a5aa",admin_cap_id:"0xf10fbf1fea5b7aeaa524b87769461a28c5c977613046360093673991f26d886c"}},haedal:{package_id:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",published_at:"0x1d56b8ec33c3fae897eb7bb1acb79914e8152faed614868928e684c25c8b198d",version:1,config:{support_stakings:[{staking_id:"0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca",from_coin_type:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",to_coin_type:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI"}]}}},ls={fullRpcUrl:"https://fullnode.testnet.sui.io/",simulationAccount:{address:"0xcd0247d0b67e53dde69b285e7a748e3dc390e8a5244eb9dd9c5c53d95e4cf0aa"},cetus_config:{package_id:"0xf5ff7d5ba73b581bca6b4b9fa0049cd320360abd154b809f8700a8fd3cfaf7ca",published_at:"0xf5ff7d5ba73b581bca6b4b9fa0049cd320360abd154b809f8700a8fd3cfaf7ca",config:{coin_list_id:"0x257eb2ba592a5480bba0a97d05338fab17cc3283f8df6998a0e12e4ab9b84478",launchpad_pools_id:"0xdc3a7bd66a6dcff73c77c866e87d73826e446e9171f34e1c1b656377314f94da",clmm_pools_id:"0x26c85500f5dd2983bf35123918a144de24e18936d0b234ef2b49fbb2d3d6307d",admin_cap_id:"0x1a496f6c67668eb2c27c99e07e1d61754715c1acf86dac45020c886ac601edb8",global_config_id:"0xe1f3db327e75f7ec30585fa52241edf66f7e359ef550b533f89aa1528dd1be52",coin_list_handle:"0x3204350fc603609c91675e07b8f9ac0999b9607d83845086321fca7f469de235",launchpad_pools_handle:"0xae67ff87c34aceea4d28107f9c6c62e297a111e9f8e70b9abbc2f4c9f5ec20fd",clmm_pools_handle:"0xd28736923703342b4752f5ed8c2f2a5c0cb2336c30e1fed42b387234ce8408ec"}},clmm_pool:{package_id:"0x0868b71c0cba55bf0faf6c40df8c179c67a4d0ba0e79965b68b3d72d7dfbf666",published_at:"0x1c29d658882c40eeb39a8bb8fe58f71a216a918acb3e3eb3b47d24efd07257f2",config:{pools_id:"0xc090b101978bd6370def2666b7a31d7d07704f84e833e108a969eda86150e8cf",global_config_id:"0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a",global_vault_id:"0xf3114a74d54cbe56b3e68f9306661c043ede8c6615f0351b0c3a93ce895e1699",admin_cap_id:""}},integrate:{package_id:"0x8627c5cdcd8b63bc3daa09a6ab7ed81a829a90cafce6003ae13372d611fbb1a9",published_at:"0xf1a5d0c5b0593e41d13f9684ca91365bdfe54a98836c1d33c90e361a031fac74",version:6},deepbook:{package_id:"0x000000000000000000000000000000000000000000000000000000000000dee9",published_at:"0x000000000000000000000000000000000000000000000000000000000000dee9"},deepbook_endpoint_v2:{package_id:"0xa34ffca2c6540e1ca9e53963ab43e7b1eed7b82e37696c743bb7c6179c15dfa6",published_at:"0xa34ffca2c6540e1ca9e53963ab43e7b1eed7b82e37696c743bb7c6179c15dfa6"},aggregatorUrl:"https://api-sui.devcetus.com/router",swapCountUrl:"https://api-sui.devcetus.com/v2/sui/swap/count"},us={launchpad:{package_id:"0x3beee8416089a5cbff9cfd5c0a2ce2937b0452dc7e2a3ab4dc431c7be05c2335",published_at:"0x3beee8416089a5cbff9cfd5c0a2ce2937b0452dc7e2a3ab4dc431c7be05c2335",config:{pools_id:"0xccc10403ab3da4ae943847908e0e674fe1fdab81c6383e4c6dcd0eea0edade3d",admin_cap_id:"0x8a72713049dbcfc40902ff209dc5e6066fe455d152baa235957c84d7a3b875ed",config_cap_id:"0x16492b4252b01debb60f8a825334020d7fdb9d895b52f8139c98618de30817fc"}},ido:{package_id:"0x1352bf18ef20458f7cc773852d4a90b240015a6a54479dda3a1debfc500bf044",published_at:"0xbd09a0889ea9970b821512428bab3e2fd01e16809a90a325cd3b3d3573eab6a4",config:{pools_id:"0x346bee25ab4d15bcfa9484ef5ebd4d7c94eb665ebaa745ff4094936a7f59a8b1",admin_cap_id:"0xc1bb19a24d3bb65dfd4f3835637b63347c223c67cde4b0888f1a857974f33cbb",package_version_id:"0x3ccf1b38e3259e638b980d4e6b49eac8c5aa94d3cb2ace5e75f0a551c8e67e5e"}},xcetus:{package_id:"0xdebaab6b851fd3414c0a62dbdf8eb752d6b0d31f5cfce5e38541bc6c6daa8966",published_at:"0xdebaab6b851fd3414c0a62dbdf8eb752d6b0d31f5cfce5e38541bc6c6daa8966",config:{xcetus_manager_id:"0x3be34cbad122c8b100ed7157d762b9610e68b3c65734e08bc3c3baf857da807d",lock_manager_id:"0x7c67e805182e3fecd098bd68a6b06c317f28f8c6249bd771e07904a10b424e60",lock_handle_id:"0xc5f3bbfefe9a45c13da7a34bc72cac122ee45d633690476a8ac56bd2c4e78c86"}},xcetus_dividends:{package_id:"0x20d948d640edd0c749f533d41efc5f843f212d441220324ad7959c6e1d281828",published_at:"0x20d948d640edd0c749f533d41efc5f843f212d441220324ad7959c6e1d281828",config:{dividend_manager_id:"0x13b7facb704fae1d199ff0038b8acabc253415a77d142b39189dee97d457e442",dividend_admin_id:"0x5eb78463007422d4130b21f61c180bcd190819b7792f56e00a61df3b8fb928ef",dividend_settle_id:"0x495095e13a170ff494d242ae44ac2c7453011ca6c33cff27498010105e10e4b4"}},cetus_faucet:{package_id:"0x1a69aee6be709054750949959a67aedbb4200583b39586d5e3eabe57f40012c7",published_at:"0x1a69aee6be709054750949959a67aedbb4200583b39586d5e3eabe57f40012c7"},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:"0x25cff94bdb454bae6a5565d09047bfe2b230025ef3bd2199622ec48d854b86b9",published_at:"0x25cff94bdb454bae6a5565d09047bfe2b230025ef3bd2199622ec48d854b86b9",config:{admin_cap_id:"0x9b2d6f5be2650d16d27cd630c4539a76d7793970343ed3cbb023e13f1637c07c",vaults_manager_id:"0xc0a1a937df08880e395d85014ff40c74f13abe7a53abdbffea36f51adaaaf79e",vaults_pool_handle:"0x3ab02203de753de9c8198cc0ce7594dc960878f2c34c5c5a4b7742082241860a"}},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:"0xfa0d98e99c1dbdbea1b0fe089fa93ebab40a7719ae4160c42cc78ebfe029fda0",published_at:"0xfa0d98e99c1dbdbea1b0fe089fa93ebab40a7719ae4160c42cc78ebfe029fda0",config:{global_config_id:"0x5082c7a5ee9a758025d7b0a5e8aa08b56625c7cd535b8909d2b7993991e229cc",rewarder_manager_id:"0xe789e092dbd9dceadbe89350c4761a6f2e11647aab97f09746a01b151926cc0e",rewarder_manager_handle:"0x7e7dd42392b5d82564dc9ad5093a111c5f0598cc9f806cff257d7dacb71f7837",admin_cap_id:"0x4ec248bca2d1fc05f39fd7491ab490464a46d128624caa4d3c2a66d957ef40b0"}},haedal:{package_id:"0xac2afb455cbcdc2ff1a2e9bbb8aa4ccb4506a544b08c740886892a5cdf92f472",published_at:"0x9dac9c5770e5f930d2223ff68782958701acfaee9337e8d8363978ce7670dffb",config:{support_stakings:[{staking_id:"0x6e384d2da5b040b27f973155e25bbe4beb0ad5ca8ee0a36e20dff356094c9fc0",from_coin_type:"0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",to_coin_type:"0xac2afb455cbcdc2ff1a2e9bbb8aa4ccb4506a544b08c740886892a5cdf92f472::hasui::HASUI"}]}}},G=(n,e)=>{let t=n==="sui:mainnet"?cs:ls,a=new go.CetusClmmSDK(t);return a.senderAddress=e.address,a},P=(n,e)=>{let t=G(n,e),a=n==="sui:mainnet"?ds:us;return new fo.CetusPeripherySDK(a,t)};var ho=async(n,e,t)=>await G(t,e).Position.createAddLiquidityFixTokenPayload(n?.parameter,n?.gasEstimateArg),yo=async(n,e,t)=>await G(t,e).Position.createAddLiquidityFixTokenPayload(n?.parameter,n?.gasEstimateArg),So=async(n,e,t)=>await G(t,e).Position.closePositionTransactionPayload(n),wo=async(n,e,t)=>await G(t,e).Position.removeLiquidityTransactionPayload(n),Co=async(n,e,t)=>await G(t,e).Rewarder.collectRewarderTransactionPayload(n);var ft=class n extends u{constructor(t){super(t);this.data=t}txType=To.TransactionType.Other;txSubType="OpenAndAddLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await ho(r,a,o)}static fromData(t){return new n(t)}};var Io=require("@msafe/sui3-utils");var gt=class n extends u{constructor(t){super(t);this.data=t}txType=Io.TransactionType.Other;txSubType="ClaimFeeAndMining";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Co(r,a,o)}static fromData(t){return new n(t)}};var ko=require("@msafe/sui3-utils");var ht=class n extends u{constructor(t){super(t);this.data=t}txType=ko.TransactionType.Other;txSubType="DecreaseLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await wo(r,a,o)}static fromData(t){return new n(t)}};var Ro=require("@msafe/sui3-utils");var xo=async(n,e,t)=>await P(t,e).Farms.openPositionAddLiquidityStakePaylod(n),vo=async(n,e,t)=>await P(t,e).Farms.addLiquidityFixCoinPayload(n),Ao=async(n,e,t)=>await P(t,e).Farms.removeLiquidityPayload(n),Oo=async(n,e,t)=>await P(t,e).Farms.removeLiquidityPayload(n),Po=async(n,e,t)=>await P(t,e).Farms.claimFeeAndClmmReward(n),Do=async(n,e,t)=>{let a=P(t,e);return console.log("getFarmingHarvest txbParams: ",n),await a.Farms.harvestPayload(n)},_o=async(n,e,t)=>{let a=P(t,e),o=Object.values(n);return console.log("getFarmingBatchHarvest params: ",o),await a.Farms.batchHarvestPayload(o)},Bo=async(n,e,t)=>await P(t,e).Farms.depositPayload(n),jo=async(n,e,t)=>await P(t,e).Farms.withdrawPayload(n);var yt=class n extends u{constructor(t){super(t);this.data=t}txType=Ro.TransactionType.Other;txSubType="FarmingOpenAndAddLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await xo(r,a,o)}static fromData(t){return new n(t)}};var No=require("@msafe/sui3-utils");var St=class n extends u{constructor(t){super(t);this.data=t}txType=No.TransactionType.Other;txSubType="FarmingBatchHarvest";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await _o(r,a,o)}static fromData(t){return new n(t)}};var Eo=require("@msafe/sui3-utils");var wt=class n extends u{constructor(t){super(t);this.data=t}txType=Eo.TransactionType.Other;txSubType="FarmingClaimFeeAndReward";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Po(r,a,o)}static fromData(t){return new n(t)}};var Mo=require("@msafe/sui3-utils");var Ct=class n extends u{constructor(t){super(t);this.data=t}txType=Mo.TransactionType.Other;txSubType="FarmingDecreaseLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Ao(r,a,o)}static fromData(t){return new n(t)}};var Lo=require("@msafe/sui3-utils");var Tt=class n extends u{constructor(t){super(t);this.data=t}txType=Lo.TransactionType.Other;txSubType="FarmingHarvest";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Do(r,a,o)}static fromData(t){return new n(t)}};var Wo=require("@msafe/sui3-utils");var It=class n extends u{constructor(t){super(t);this.data=t}txType=Wo.TransactionType.Other;txSubType="FarmingIncreaseLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await vo(r,a,o)}static fromData(t){return new n(t)}};var Fo=require("@msafe/sui3-utils");var kt=class n extends u{constructor(t){super(t);this.data=t}txType=Fo.TransactionType.Other;txSubType="FarmingRemoveLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Oo(r,a,o)}static fromData(t){return new n(t)}};var Uo=require("@msafe/sui3-utils");var xt=class n extends u{constructor(t){super(t);this.data=t}txType=Uo.TransactionType.Other;txSubType="FarmingStake";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Bo(r,a,o)}static fromData(t){return new n(t)}};var qo=require("@msafe/sui3-utils");var vt=class n extends u{constructor(t){super(t);this.data=t}txType=qo.TransactionType.Other;txSubType="FarmingUnstake";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await jo(r,a,o)}static fromData(t){return new n(t)}};var $o=require("@msafe/sui3-utils");var At=class n extends u{constructor(t){super(t);this.data=t}txType=$o.TransactionType.Other;txSubType="IncreaseLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await yo(r,a,o)}static fromData(t){return new n(t)}};var Qo=require("@msafe/sui3-utils");var Ot=class n extends u{constructor(t){super(t);this.data=t}txType=Qo.TransactionType.Other;txSubType="RemoveLiquidity";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await So(r,a,o)}static fromData(t){return new n(t)}};var Ko=require("@msafe/sui3-utils");var Vo=require("@cetusprotocol/cetus-sui-clmm-sdk");var Go=async(n,e,t,a)=>{let o=G(a,t),r=await o.getOwnerCoinAssets(t.address);return await Vo.TransactionUtil.buildAggregatorSwapTransaction(o,n,r,"",e)};var Pt=class n extends u{constructor(t){super(t);this.data=t}txType=Ko.TransactionType.Other;txSubType="Swap";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Go(r?.createTxParams,r?.slippage,a,o)}static fromData(t){return new n(t)}};var Xo=require("@msafe/sui3-utils");var zo=require("@mysten/sui.js/transactions"),Ho={package_id:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",published_at:"0x355714a1eeb7ab1d80902da6c92001170cda1212edf524c32aa308a3ac177c31",cetus_coin_type:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS"},Jo=async(n,e,t)=>{console.log("getVestingRedeemTxb txbParams: ",n),console.log("getVestingRedeemTxb account: ",e),console.log("getVestingRedeemTxb network: ",t);let{pool:a,nftId:o,periods:r,CLOCK_ADDRESS:i}=n,s=new zo.TransactionBlock;return r.forEach(c=>{s.moveCall({target:`${Ho.published_at}::router::redeem`,typeArguments:[Ho.cetus_coin_type],arguments:[s.object(a),s.object(o),s.pure(c),s.object(i)]})}),s};var Dt=class n extends u{constructor(t){super(t);this.data=t}txType=Xo.TransactionType.Other;txSubType="VestingRedeem";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Jo(r,a,o)}static fromData(t){return new n(t)}};var nr=require("@msafe/sui3-utils");var Yo=async(n,e,t)=>await P(t,e).XCetusModule.convertPayload(n),Zo=async(n,e,t)=>await P(t,e).XCetusModule.redeemLockPayload(n),er=async(n,e,t)=>await P(t,e).XCetusModule.redeemDividendV2Payload(n.venft_id,n.bonus_types,n.xTokenType),tr=async(n,e,t)=>await P(t,e).XCetusModule.cancelRedeemPayload(n),ar=async(n,e,t)=>await P(t,e).XCetusModule.redeemPayload(n);var _t=class n extends u{constructor(t){super(t);this.data=t}txType=nr.TransactionType.Other;txSubType="xCETUSCancelRedeem";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await tr(r,a,o)}static fromData(t){return new n(t)}};var or=require("@msafe/sui3-utils");var Bt=class n extends u{constructor(t){super(t);this.data=t}txType=or.TransactionType.Other;txSubType="xCETUSClaimStakingRwewards";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await er(r,a,o)}static fromData(t){return new n(t)}};var rr=require("@msafe/sui3-utils");var jt=class n extends u{constructor(t){super(t);this.data=t}txType=rr.TransactionType.Other;txSubType="xCETUSConvert";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Yo(r,a,o)}static fromData(t){return new n(t)}};var ir=require("@msafe/sui3-utils");var Rt=class n extends u{constructor(t){super(t);this.data=t}txType=ir.TransactionType.Other;txSubType="xCETUSRedeem";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await ar(r,a,o)}static fromData(t){return new n(t)}};var sr=require("@msafe/sui3-utils");var Nt=class n extends u{constructor(t){super(t);this.data=t}txType=sr.TransactionType.Other;txSubType="xCETUSRedeemLock";async build(t){let{account:a,network:o}=t,{txbParams:r}=this.data;return await Zo(r,a,o)}static fromData(t){return new n(t)}};var Et=class{application="cetus";async deserialize(e){console.log("Cetus helper deserialize input: ",e);let{txbParams:t,action:a}=e;return{txType:cr.TransactionType.Other,txSubType:a,intentionData:{txbParams:{...t},action:a}}}async build(e){let{suiClient:t,account:a,network:o}=e;console.log("helper build input: ",e),console.log("helper build input.intentionData: ",e.intentionData),console.log("helper build input.intentionData JSON: ",JSON.stringify(e.intentionData));let r;switch(e.txSubType){case"OpenAndAddLiquidity":r=ft.fromData(e.intentionData);break;case"IncreaseLiquidity":r=At.fromData(e.intentionData);break;case"DecreaseLiquidity":r=ht.fromData(e.intentionData);break;case"RemoveLiquidity":r=Ot.fromData(e.intentionData);break;case"ClaimFeeAndMining":r=gt.fromData(e.intentionData);break;case"FarmingOpenAndAddLiquidity":r=yt.fromData(e.intentionData);break;case"FarmingIncreaseLiquidity":r=It.fromData(e.intentionData);break;case"FarmingDecreaseLiquidity":r=Ct.fromData(e.intentionData);break;case"FarmingRemoveLiquidity":r=kt.fromData(e.intentionData);break;case"FarmingClaimFeeAndReward":r=wt.fromData(e.intentionData);break;case"FarmingHarvest":r=Tt.fromData(e.intentionData);break;case"FarmingBatchHarvest":r=St.fromData(e.intentionData);break;case"FarmingStake":r=xt.fromData(e.intentionData);break;case"FarmingUnstake":r=vt.fromData(e.intentionData);break;case"xCETUSConvert":r=jt.fromData(e.intentionData);break;case"xCETUSRedeemLock":r=Nt.fromData(e.intentionData);break;case"xCETUSClaimStakingRwewards":r=Bt.fromData(e.intentionData);break;case"xCETUSCancelRedeem":r=_t.fromData(e.intentionData);break;case"xCETUSRedeem":r=Rt.fromData(e.intentionData);break;case"VestingRedeem":r=Dt.fromData(e.intentionData);break;case"Swap":r=Pt.fromData(e.intentionData);break;default:throw new Error("not implemented")}return console.log("helper build intention: ",r),console.log("helper build account: ",a),console.log("helper build network: ",o),r.build({suiClient:t,account:a,network:o})}};var _r=require("@msafe/sui3-utils");var kn={};In(kn,{contractId:()=>bs,default:()=>Ss,feeObjId:()=>hs,roleObjId:()=>fs,status:()=>ms,transaction:()=>ps,upgradeCapObjId:()=>ys,vaultObjId:()=>gs});var ps="DiBZq4UmVVYiRL6ZJmFKYoHcxtxqrhsCXSkFyT7wUr3j",ms="success",bs="0x81c960dc653975fbd0072deca8afb92d322898c911622898ba1b2e3ad0c4bd8d",fs="0xc6ec0bdee0bb59a72077e9acd2f42457043cf47080b3d3fad4d39abf28bba63a",gs="0xbc4021387fbac149119fd24e92be9e58f745774292f3a2a12e2ac6daf5363e1d",hs="0x4178f63970fe2daeb256dc5730ad172e82b3e8eb45f31b33e0daae72cd35e1e1",ys="0xe1e9aa7d222d151bfe6dd83358b0d7fdcb11260f710800cfaf7ccc1b1e245115",Ss={transaction:ps,status:ms,contractId:bs,roleObjId:fs,vaultObjId:gs,feeObjId:hs,upgradeCapObjId:ys};var xn={};In(xn,{contractId:()=>Ts,default:()=>As,feeObjId:()=>xs,roleObjId:()=>Is,status:()=>Cs,transaction:()=>ws,upgradeCapObjId:()=>vs,vaultObjId:()=>ks});var ws="855FNDV8o8Z3fWULPnQo9qdhLJpsg7wZrkCpNyfw9KfB",Cs="success",Ts="0xc357c3985e8fb875d6b37141497af660779aa1bab0ec489b2213efd74067d1fa",Is="0x5ab49bdf9fd1413e328ef242b3f8d83dde791b38a0b627bfc87fb25c010d34f1",ks="0xb483558770d8eb26007f193b75db40f0a45f2e36863a687625885d4de6993378",xs="0x48453fc4d7cde3fe35aad89e5dfb496608a6a55ea529a1c0274681a808627f94",vs="0x34279779a0d0d36bd5044b04830d607fa1b0ecf316548c8ac3a44151e4f1a42a",As={transaction:ws,status:Cs,contractId:Ts,roleObjId:Is,vaultObjId:ks,feeObjId:xs,upgradeCapObjId:vs};var Os="https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD",Ps="https://sui-testnet.blockvision.org/v1/2Sgk89ivT64MnKdcGzjmyjY2ndD",Ds="https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7",_s="https://sui-mainnet.blockvision.org/v1/2Sgk7NPvqkd7mESYkxF01yX15l7",Bs="https://bc3p6l5unl.execute-api.us-west-1.amazonaws.com/prod",js="https://rolsbkota7.execute-api.us-west-1.amazonaws.com/prod",Rs="https://6p6mkx33ne.execute-api.us-west-1.amazonaws.com/prod",Ns="https://xrae3mrjv5.execute-api.us-west-1.amazonaws.com/prod",dr=kn,lr=xn,Es=new Map([["dev",{env:"dev",rpc:{url:Os},backend:{url:Bs},contract:dr}],["stg",{env:"stg",rpc:{url:Ps},backend:{url:js},contract:dr}],["prev",{env:"prev",rpc:{url:Ds},backend:{url:Rs},contract:lr}],["prod",{env:"prod",rpc:{url:_s},backend:{url:Ns},contract:lr}]]);function ur(n,e){let t=Es.get(n);if(!t)throw new Error(`Env not supported: ${n}`);return e&&e.rpc&&(t.rpc=e.rpc),e&&e.backend&&(t.backend=e.backend),e&&e.contract&&(t.contract=e.contract),t}var pr=require("@mysten/sui.js/client");var S=class extends Error{mpayErrorCode;context;constructor(e,t,a={}){let{cause:o,context:r}=a;o?super(`[MPay] ${t}: ${o}`):super(`[MPay] ${t}`),this.mpayErrorCode=e,this.context=r}};var Mt=class extends S{constructor(){super(11,"Backend is not specified")}};var Lt=class extends S{constructor(){super(1,"Wallet not connected")}};var K=q(require("axios"));var Ie=class extends S{constructor(e,t){super(10,e,{context:t})}};var Wt=class n{constructor(e){this.apiURL=e}static parseResponseData(e){if(e instanceof K.AxiosError)throw new Ie(e.response?.statusText);if(e.status===200){if(e.data.success)return e.data.data;throw new Ie(e.data.code)}throw new Ie(e.status.toString())}async getIncomingStreams(e,t){let a=await K.default.post(`${this.apiURL}/stream`,{recipient:e,...t});return n.parseResponseData(a)}async getOutgoingStreams(e,t){let a=await K.default.post(`${this.apiURL}/stream`,{sender:e,...t});return n.parseResponseData(a)}async getStreamHistory(e){let t=await K.default.post(`${this.apiURL}/stream-events`,e),a=n.parseResponseData(t);return a.data.forEach(o=>{let r=o;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}),a}async getAllCoinTypes(e){let t=await K.default.post(`${this.apiURL}/stream-info`,{address:e});return n.parseResponseData(t)}async getAllRecipients(e,t){let a=await K.default.post(`${this.apiURL}/stream-info`,{sender:e,status:t});return n.parseResponseData(a)}async getAllSenders(e,t){let a=await K.default.post(`${this.apiURL}/stream-info`,{recipient:e,status:t});return n.parseResponseData(a)}};var ke=class n{signer;suiClient;envConfig;_backend;constructor(e){this.envConfig=e,this.suiClient=new pr.SuiClient({url:e.rpc.url}),e.backend&&(this._backend=new Wt(e.backend.url))}static new(e,t){let a=ur(e,t);return new n(a)}get walletType(){return this.wallet?this.wallet.type:"disconnected"}get backend(){if(!this._backend)throw new Mt;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 Lt;return this.signer}async walletAddress(){return this.wallet.address()}};var he=require("@mysten/sui.js/utils");var Ge=require("@mysten/sui.js/transactions");var Dn=require("@mysten/sui.js/transactions"),Ve=require("@mysten/sui.js/utils");var vn=50n,Ft=10000n,mr=25n,An=100000000n;var $=class{constructor(e){this.object=e}moveArg(e){return e.object(this.object)}},Ue=class{constructor(e){this.objects=e}moveArgs(e){return e.makeMoveVec({objects:this.objects.map(t=>e.object(t))})}},ae=class n{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,a){if(a in t)return Reflect.get(t,a);let o=i=>new n(t.result[i]);if(a===Symbol.iterator)return function*(){let i=0;for(;;)yield o(i),i++};if(typeof a=="symbol")return;let r=parseInt(a,10);if(!(Number.isNaN(r)||r<0))return o(r)}})}moveArg(){return this.result}};var On=require("buffer"),br=require("@mysten/sui.js/utils");var qe=class extends S{constructor(e,t){super(3,e,{context:t})}};var Ut=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 a=this.callResult(e);return this.returnValue(a,t)}getAddress(e=0,t=0){let[a,o]=this.getValue(e,t);if(o!=="address")throw new qe("Invalid contract return type.",{ctx:{expectType:"address",gotType:o}});return(0,br.normalizeSuiAddress)(On.Buffer.from(a).toString("hex"))}getU64(e=0,t=0){let[a,o]=this.getValue(e,t);if(o!=="u64")throw new qe("Invalid contract return type.",{ctx:{expectType:"u64",gotType:o}});return On.Buffer.from(a).readBigInt64LE()}};var Pn=require("@mysten/sui.js/bcs");var v=class extends S{constructor(e,t,a){super(2,`Invalid input: ${e}`,{context:{fieldKey:t,fieldValue:a}})}};var gr={groupId:"string",name:"string"},Ms=64;function hr(n){return yr(n),Pn.bcs.ser(gr,n).toString("base64")}function $e(n){let e=Pn.bcs.de(gr,n,"base64");return yr(e),e}function yr(n){if(!fr(n.name))throw new v("Invalid metadata: Name contains unknown character");if(!fr(n.groupId))throw new v("Invalid metadata: Group ID contains unknown character");if(n.name.length>Ms)throw new v("Invalid metadata: Name exceed max length 64")}function fr(n){return/^[\x00-\x7F]+$/.test(n)}var Qe=require("@mysten/sui.js/utils");function qt(n,e){return(0,Qe.normalizeStructTag)(n)===(0,Qe.normalizeStructTag)(e)}function ne(n,e){return(0,Qe.normalizeStructTag)(n)===(0,Qe.normalizeStructTag)(e)}var $t="txn.gas";var Sr=require("nanoid");function wr(){return(0,Sr.nanoid)()}var ge=class n{constructor(e,t,a){this.globals=e;this.feeContract=t;this.streamContract=a}static convertCreateStreamInfoToInternal(e){return{metadata:hr({name:e.name,groupId:wr()}),coinType:(0,Ve.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 Dn.TransactionBlock,a=this.calculateFeesInternal(e),o=this.getCreateStreamCoinRequests(e,a),r=await this.wallet.requestCoins(o),i=await this.addMergeCoins(t,r[0]),s;o.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),p=this.getStreamFeeLocal(d),[m]=t.splitCoins(i,[t.pure(d+p,"u64")]),[b]=t.splitCoins(s,[t.pure(this.flatSuiFee,"u64")]);this.streamContract.createStream(t,{paymentCoin:new ae(m),flatFeeCoin:new ae(b),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=n.convertCreateStreamInfoToInternal(e);return this.calculateFeesInternal(t)}feeParams(){return{createFeePercent:{numerator:vn,denominator:Ft},claimFeePercent:{numerator:mr,denominator:Ft},flatFeePerStream:An}}async addMergeCoins(e,t){let a;return t.mergedCoins&&t.mergedCoins.length?(e.mergeCoins(e.object(t.primaryCoin),t.mergedCoins.map(o=>e.object(o))),a=e.object(t.primaryCoin)):t.primaryCoin===$t?a=e.gas:a=e.object(t.primaryCoin),a}getCreateStreamCoinRequests(e,t){let a=e.coinType;return qt(a,Ve.SUI_TYPE_ARG)?[{coinType:a,amount:t.totalAmount+t.streamFeeAmount+t.flatFeeAmount}]:[{coinType:a,amount:t.totalAmount+t.streamFeeAmount},{coinType:Ve.SUI_TYPE_ARG,amount:t.flatFeeAmount}]}calculateFeesInternal(e){let t=e.recipients.reduce((o,r)=>{let i=this.amountForRecipient(r,e.numberEpoch),s=this.getStreamFeeLocal(i);return{totalAmount:o.totalAmount+i,streamFeeAmount:o.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 An}getStreamFeeLocal(e){return e*vn/Ft}async getStreamFeeRemote(e){let t=this.feeContract.streamingFee(new Dn.TransactionBlock,e),a=await this.globals.suiClient.devInspectTransactionBlock({sender:await this.globals.walletAddress(),transactionBlock:t});return new Ut(a).getU64()}get wallet(){return this.globals.wallet}};var _n=require("@mysten/sui.js/transactions");var Cr="0x0000000000000000000000000000000000000000000000000000000000000006";var xe=class{constructor(e,t,a){this.moduleName=e;this.config=t;this.globals=a}addContractCall(e,t){let a=`${this.config.contractId}::${this.moduleName}::${t.method}`;return e.add(_n.Transactions.MoveCall({target:a,arguments:t.arguments.map(o=>o instanceof Ue?o.moveArgs(e):o instanceof $?o.moveArg(e):o instanceof ae?o.moveArg():e.pure(o)),typeArguments:t.typeArgs})),e}addTransactionBlock(e,t,a=[],o=[]){e.add(_n.Transactions.MoveCall({target:t,arguments:a.map(r=>r instanceof Ue?r.moveArgs(e):r instanceof $?r.moveArg(e):r instanceof ae?r.moveArg():e.pure(r)),typeArguments:o}))}makeObject(e){return typeof e=="string"?new $(e):e}vaultObject(){return new $(this.config.vaultObjId)}roleObject(){return new $(this.config.roleObjId)}feeObject(){return new $(this.config.feeObjId)}clockObject(){return new $(Cr)}};var ve=class n extends xe{constructor(t,a){super(n.ModuleName,t,a);this.config=t;this.globals=a}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,a){let o=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:n.MethodName.set_streaming_fee,arguments:[o,r,a],typeArgs:[]})}setStreamingFlatFee(t,a){let o=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:n.MethodName.set_streaming_flat_fee,arguments:[o,r,a],typeArgs:[]})}setClaimFee(t,a){let o=this.roleObject(),r=this.feeObject();return this.addContractCall(t,{method:n.MethodName.set_claim_fee,arguments:[o,r,a],typeArgs:[]})}streamingFee(t,a){let o=this.feeObject();return this.addContractCall(t,{method:n.MethodName.streaming_fee,arguments:[o,a],typeArgs:[]})}claimFee(t,a){return this.addContractCall(t,{method:n.MethodName.claim_fee,arguments:[this.feeObject(),a],typeArgs:[]})}feeDenominator(t){return this.addContractCall(t,{method:n.MethodName.fee_denominator,arguments:[this.feeObject()],typeArgs:[]})}};var Q=class n extends xe{constructor(t,a){super(n.ModuleName,t,a);this.config=t;this.globals=a}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,a){let o=this.feeObject(),r=this.vaultObject(),i=this.makeObject(a.paymentCoin),s=this.makeObject(a.flatFeeCoin),c=this.clockObject();return this.addContractCall(t,{method:n.MethodName.create_stream,arguments:[o,r,i,s,a.metadata,a.recipient,a.timeStart,a.cliff,a.epochInterval,a.numEpoch,a.amountPerEpoch,a.cancelable,c],typeArgs:[a.coinType]})}setAutoClaim(t,a){let o=this.makeObject(a.streamId);return this.addContractCall(t,{method:n.MethodName.set_auto_claim,arguments:[o,a.enabled],typeArgs:[a.coinType]})}cancelStream(t,a){let o=this.makeObject(a.streamId),r=this.clockObject();return this.addContractCall(t,{method:n.MethodName.cancel_stream,arguments:[o,r],typeArgs:[a.coinType]})}claimStream(t,a){let o=this.makeObject(a.streamId),r=this.clockObject();return this.addContractCall(t,{method:n.MethodName.claim_stream,arguments:[o,r],typeArgs:[a.coinType]})}claimStreamByProxy(t,a){let o=this.makeObject(a.streamId),r=this.vaultObject(),i=this.feeObject(),s=this.clockObject();return this.addContractCall(t,{method:n.MethodName.claim_stream_by_proxy,arguments:[o,r,i,s],typeArgs:[a.coinType]})}get createStreamTarget(){return`${this.config.contractId}::${n.ModuleName}::${n.MethodName.create_stream}`}get setAutoClaimTarget(){return`${this.config.contractId}::${n.ModuleName}::${n.MethodName.set_auto_claim}`}get cancelStreamTarget(){return`${this.config.contractId}::${n.ModuleName}::${n.MethodName.cancel_stream}`}get claimStreamTarget(){return`${this.config.contractId}::${n.ModuleName}::${n.MethodName.claim_stream}`}get claimStreamByProxyTarget(){return`${this.config.contractId}::${n.ModuleName}::${n.MethodName.claim_stream_by_proxy}`}};var Ae=class{constructor(e){this.globals=e;let t=e.envConfig.contract;this.feeContract=new ve(t,e),this.streamContract=new Q(t,e)}feeContract;streamContract;async createStreams(e){let t=ge.convertCreateStreamInfoToInternal(e);return this.createStreamHelper().buildCreateStreamTransactionBlock(t)}createStreamHelper(){return new ge(this.globals,this.feeContract,this.streamContract)}setAutoClaim(e,t,a){let o=new Ge.TransactionBlock;return this.streamContract.setAutoClaim(o,{streamId:e,enabled:t,coinType:a})}claimStream(e,t){let a=new Ge.TransactionBlock;return this.streamContract.claimStream(a,{streamId:e,coinType:t})}claimStreamByProxy(e,t){let a=new Ge.TransactionBlock;return this.streamContract.claimStreamByProxy(a,{streamId:e,coinType:t})}cancelStream(e,t){let a=new Ge.TransactionBlock;return this.streamContract.cancelStream(a,{streamId:e,coinType:t}),a}};var O=class extends S{constructor(e,t={}){super(0,e,t)}};async function jn(n){let e=[];for(;await n.hasNext();){let t=await n.next();e.push(t)}return e&&Array.isArray(e[0])?e.flat(1):e}var Bn=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)}},Oe=class{constructor(e){this.requester=e;this.pager=new Bn(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 Qt=class extends S{constructor(t,a,o){super(4,`Not enough balance: ${t}`,{context:{coinType:t,requestAmount:a,gotAmount:o}});this.coinType=t;this.requestAmount=a;this.gotAmount=o}};var Ls=25;async function Tr(n,e,t,a="0x2::sui::SUI",o=Ls){let r=new Rn(n,e,a,o),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 Qt(a,t,i);return s}var Rn=class extends Oe{constructor(t,a,o,r){super(new Nn(t,a,o,r));this.suiClient=t;this.owner=a;this.coinType=o;this.reqPageSize=r}},Nn=class{constructor(e,t,a,o){this.suiClient=e;this.owner=t;this.coinType=a;this.reqPageSize=o;if(o<=0)throw new O("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 ze=require("@mysten/sui.js/transactions"),Je=require("@mysten/sui.js/utils"),kr=require("luxon");var Vt=class extends S{constructor(){super(7,"Connected wallet is not creator")}};var Ke=class extends S{constructor(){super(8,"Connected wallet is not recipient")}};var He=class extends S{constructor(e,t){super(6,e,{context:t})}};var Gt=class extends S{constructor(e){super(5,"Stream not found",{context:{streamId:e}})}};var Ht=require("luxon"),Ir=(1n<<64n)-1n,Kt=1e3;function En(n){let e;typeof n=="number"?e=n:typeof n=="bigint"?e=Number(n):e=n.toMillis();let t=Math.round(e/Kt);return Ht.DateTime.fromMillis(t*Kt)}function Mn(n){let e;typeof n=="number"?e=n:typeof n=="bigint"?e=Number(n):e=n.toMillis();let t=Math.round(e/Kt);return Ht.Duration.fromMillis(t*Kt)}var oe=class n{constructor(e,t,a){this.globals=e;this.streamId=t;this.rawData=a;this.streamContract=new Q(e.envConfig.contract,e)}streamContract;type="Stream";static async new(e,t){let a=await n.fetchStreamData(e,t);return new n(e,t,a)}static fromObjectData(e,t,a){let o=n.parseRawStreamData(t,a);return new n(e,t,o)}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 n.fetchStreamData(this.globals,this.streamId)}refreshWithData(e){if(e.data?.objectId!==this.streamId)throw new O("Object Id does not align");this.rawData=n.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 Vt;let e=new ze.TransactionBlock;return this.streamContract.cancelStream(e,{streamId:this.streamId,coinType:this.coinType}),e}async claim(){if(await this.globals.walletAddress()!==this.recipient)throw new Ke;let e=new ze.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 Ke;let t=new ze.TransactionBlock;return this.streamContract.setAutoClaim(t,{streamId:this.streamId,coinType:this.coinType,enabled:e}),t}async claimByProxy(){let e=new ze.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,Je.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 Mn(this.rawData.config.epochInterval)}get groupId(){let{metadata:e}=this.rawData.config;return $e(e).groupId}get name(){let{metadata:e}=this.rawData.config;return $e(e).name}get recipient(){return this.rawData.config.recipient}get timeStart(){return En(this.rawData.config.timeStart)}get duration(){let e=this.rawData.config,t=e.epochInterval*e.totalEpoch;return Mn(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:En((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===Ir?0n:this.rawData.status.epochClaimed*this.amountPerEpoch+this.cliff}get currentEpoch(){let e=kr.DateTime.now().toMillis(),t=this.timeStart.toMillis();if(e<t)return-1n;let a=Math.floor((e-t)/Number(this.rawData.config.epochInterval));return BigInt(a)>Number(this.rawData.config.totalEpoch)?this.rawData.config.totalEpoch:BigInt(a)}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 a=await e.suiClient.getObject({id:t,options:{showContent:!0,showType:!0}});return n.parseRawStreamData(t,a)}static parseRawStreamData(e,t){if(t.error)throw t.error.code==="notExists"?new Gt(e):new He(`get stream data: ${t.error.code}`,{streamId:e,...t.error});let a=t.data.content;if(a.dataType!=="moveObject")throw new He("Unexpected object type",{gotType:a.dataType});let{typeParams:o}=(0,Je.parseStructTag)(a.type),r=(0,Je.normalizeStructTag)(o[0]),i=a.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 Pe=require("@mysten/sui.js/utils"),Ln=require("luxon");var zt=class extends S{constructor(e,t){super(12,`Transaction failed: ${t}`,{context:{status:e,msg:t}})}};var Ws=1e3,Jt=class{constructor(e){this.globals=e;this.coinMetaHelper=new Wn(e.suiClient),this.createStreamHelper=new Ae(e).createStreamHelper()}coinMetaHelper;createStreamHelper;getStreamIdsFromCreateStreamResponse(e){if(e.effects?.status.status!=="success")throw new zt(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 v("Invalid stream steps: 0");let t=e.cliff?e.cliff:{numerator:0n,denominator:100n},a=e.totalAmount*t.numerator/t.denominator,o=(e.totalAmount-a)/e.steps,i={realTotalAmount:o*e.steps+a,cliffAmount:a,amountPerStep:o};return this.validateStreamAmount(i,e.totalAmount),i}calculateTimelineByInterval(e){if(e.steps===0n)throw new v("Invalid stream steps: 0");let t=e.timeStart.plus(e.interval.toMillis()*Number(e.steps)),a={timeStart:e.timeStart,timeEnd:t,interval:e.interval,steps:e.steps};return this.validateTimeline(a),a}calculateTimelineByTotalDuration(e){if(e.steps===0n)throw new v("Invalid stream steps: 0");let t=BigInt(e.total.toMillis())/e.steps,a=e.timeStart.plus(Ln.Duration.fromMillis(Number(t*e.steps))),o={timeStart:e.timeStart,timeEnd:a,interval:Ln.Duration.fromMillis(Number(t)),steps:e.steps};return this.validateTimeline(o),o}async getBalance(e,t){let a=await this.globals.suiClient.getBalance({owner:e,coinType:t}),o=await this.getCoinMeta(t);return{...a,coinType:(0,Pe.normalizeStructTag)(a.coinType),coinMeta:o}}async getAllBalance(e){let t=await this.globals.suiClient.getAllBalances({owner:e}),a=await Promise.all(t.map(o=>this.getCoinMeta(o.coinType)));return t.map((o,r)=>({...o,coinType:(0,Pe.normalizeStructTag)(o.coinType),coinMeta:a[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 v("Stream amount too small","totalAmount",t);if(e.cliffAmount>e.realTotalAmount)throw new v("Invalid cliff settings")}validateTimeline(e){if(e.interval.toMillis()<Ws)throw new v("Interval shall be at least 1 second","interval",e.interval)}},Wn=class{constructor(e){this.suiClient=e;this.coinMetaReg=new Map}coinMetaReg;async getCoinMeta(e){let t=(0,Pe.normalizeStructTag)(e||Pe.SUI_TYPE_ARG);if(this.coinMetaReg.has(t))return this.coinMetaReg.get(t);let a=await this.queryCoinMeta(t);return a&&this.coinMetaReg.set(t,a),a}async queryCoinMeta(e){return await this.suiClient.getCoinMetadata({coinType:e})||void 0}};var re=require("@mysten/sui.js/utils"),qn=require("luxon");var De=class extends S{constructor(e,t){super(9,`Invalid stream group: ${e}`,{context:t})}};var Fs=25;async function Un(n,e,t){let a=new Xe(e),o=new Ye(n,a,t);return await jn(o)}var Xe=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]}},Ye=class extends Oe{constructor(t,a,o){super(new Fn(t,a,o));this.suiClient=t;this.idIter=a;this.options=o}},Fn=class{constructor(e,t,a){this.suiClient=e;this.stringIter=t;this.options=a;this.filter=a?.filter,this.pageSize=a?.pageSize||Fs,this.objectOptions=a?.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}),a;if(this.filter){let{filter:o}=this;a=t.filter(r=>o?.(r))}else a=t;return{data:a,hasNext:await this.stringIter.hasNext()}}};var Xt=class n{constructor(e,t){this.globals=e;this.streams=t;if(t.length===0)throw new De("stream size 0");let a=t.map(r=>r.groupId);if(new Set(a).size!==1)throw new v("Stream does not have same group ID")}type="StreamGroup";static async new(e,t){let a=await Un(e.suiClient,t);return a.forEach(o=>{if(!o)throw new O("stream group object data undefined")}),n.newFromObjectResponse(e,t,a)}static async newFromObjectResponse(e,t,a){let o=await n.parseGroupStreams(e,t,a);return new n(e,o)}static checkStreamGroup(e){let t=e.map(r=>r.groupCommonInfo),a=t[0],o=!0;return t.forEach(r=>{Us(a,r)||(o=!1)}),o}async refresh(){let e=await Un(this.globals.suiClient,this.streams.map(t=>t.streamId));this.streams.forEach((t,a)=>{t.refreshWithData(e[a])})}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,a){let o=a.map((r,i)=>oe.fromObjectData(e,t[i],r)).filter(r=>!!r);if(new Set(o.map(r=>r.groupId)).size!==1)throw new De("Not same group ID");if(!this.checkStreamGroup(o))throw new De("Not same stream settings");return o}};function Us(n,e){return n.name===e.name&&n.groupId===e.groupId&&n.creator===e.creator&&n.start.toMillis()===e.start.toMillis()&&n.interval.toMillis()===e.interval.toMillis()&&n.steps===e.steps&&n.cancelable===e.cancelable}var Ze=class n{constructor(e,t){this.it=e;this.pageSize=t}static async newIncoming(e){let t=await Yt.newIncoming(e);return new n(t,e.pageSize)}static async newOutgoing(e){let t=await Yt.newOutgoing(e);return new n(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}},Yt=class n{constructor(e){this.requester=e}cachedNext;static async newIncoming(e){let t=await Zt.newIncomingQuery(e);return new n(t)}static async newOutgoing(e){let t=await Zt.newOutgoingQuery(e);return new n(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 O("No more results");return t}let e=this.cachedNext;if(this.cachedNext=void 0,e===null)throw new O("No more results");return e}},Zt=class n{constructor(e,t,a,o){this.globals=e;this.recipient=t;this.groupRefs=a;this.query=o;this.current=0;let r=new Xe(a.flat().map(i=>i.streamId));this.objectIter=new Ye(e.suiClient,r)}current=0;objectIter;static async newIncomingQuery(e){let t=Gs(e.query),a=await e.globals.walletAddress(),r=(await e.globals.backend.getIncomingStreams(a,t)).filter(s=>(0,re.normalizeSuiAddress)(s.recipient)===(0,re.normalizeSuiAddress)(a)),i=xr(r);return new n(e.globals,a,i,e.query)}static async newOutgoingQuery(e){let t=Ks(e.query),a=await e.globals.walletAddress(),o=await e.globals.backend.getOutgoingStreams(a,t),r=xr(o);return new n(e.globals,a,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 Qs(this.globals,e[0].streamId,this.objectIter);return this.current++,vr(t,this.query)?t:this.doNextRequest()}if(e.length>1){let t=await Vs(this.globals,e.map(a=>a.streamId),this.objectIter);return this.current++,$s(t,this.query)?t:this.doNextRequest()}throw new O("Stream group with no stream")}};function xr(n){let e=new Map;return n.forEach(t=>{let a=e.get(t.groupId);a?(a.push(t),e.set(t.groupId,a)):e.set(t.groupId,[t])}),Array.from(e.values()).sort((t,a)=>qn.DateTime.fromISO(a[0].createDate).toMillis()-qn.DateTime.fromISO(t[0].createDate).toMillis())}function vr(n,e){if(e===void 0)return!0;let t=qs(n,e.status);if(e&&"claimable"in e&&e.claimable!==void 0){let a=e.claimable?n.progress.claimable!==0n:n.progress.claimable===0n;return t&&a}return t}function qs(n,e){return e===void 0?!0:Array.isArray(e)?e.includes(n.progress.status):n.progress.status===e}function $s(n,e){if(!e)return!0;let t=!1;return n.streams.forEach(a=>{vr(a,e)&&(t=!0)}),t}async function Qs(n,e,t){let a=await Ar(t,e);return oe.fromObjectData(n,e,a)}async function Vs(n,e,t){let a=[];for(;a.length<e.length;){let o=await Ar(t,e[a.length]);a.push(o)}return Xt.newFromObjectResponse(n,e,a)}async function Ar(n,e){if(!await n.hasNext())throw new O("object iterator has been consumed");let t=await n.next();if(!t||t.error||t.data===void 0||t.data===null)throw new O("object iterator undefined response",{cause:t?.error});if(t?.data?.objectId!==e)throw new O("stream id not aligned");return t}function Gs(n){return{status:$n(n?.status),coinType:Or(n?.coinType),sender:Pr(n?.sender)}}function Ks(n){return{status:$n(n?.status),coinType:Or(n?.coinType),recipient:Pr(n?.recipient)}}function $n(n){return n===void 0||n.length===0?"all":Array.isArray(n)?n.reduce((e,t)=>{let a=$n(t);return!e||e===a?a:"all"},void 0):Hs(n)}function Hs(n){switch(n){case"STREAMING":case"STREAMED":case"CANCELED":return"active";case"COMPLETED":case"SETTLED":return"inactive";default:throw new v("Unknown stream filtered status")}}function Or(n){if(n)return Array.isArray(n)?n.length!==0?n.map(e=>(0,re.normalizeStructTag)(e)):void 0:(0,re.normalizeStructTag)(n)}function Pr(n){if(n)return Array.isArray(n)?n.length!==0?n.map(e=>(0,re.normalizeSuiAddress)(e)):void 0:(0,re.normalizeSuiAddress)(n)}var Qn=class{constructor(e){this.msafe=e}get type(){return"msafe"}async address(){return this.msafe.address()}async requestCoins(e){return this.msafe.requestCoins(e)}},ea=class{constructor(e){this.account=e}async address(){return this.account.address}},Vn=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(qt(e.coinType,he.SUI_TYPE_ARG))return{primaryCoin:$t};if(e.amount<=0)throw new v("Invalid coin request","coinAmount",e.amount);let t=await Tr(this.suiClient,await this.address(),e.amount,e.coinType);if(t.length===0)throw new O("no coins available");return{primaryCoin:t[0].coinObjectId,mergedCoins:t.slice(1).map(a=>a.coinObjectId)}}},ta=class{globals;helper;constructor(e,t){this.globals=ke.new(e,t),this.helper=new Jt(this.globals)}connectSingleWallet(e){let t=new Vn(e,this.globals.suiClient);this.globals.connectWallet(t)}connectMSafeAccount(e){let t=new Qn(e);this.globals.connectWallet(t)}async createStream(e){return this.builder().createStreams(e)}async getStream(e){return oe.new(this.globals,e)}async getIncomingStreams(e,t=10){return Ze.newIncoming({globals:this.globals,query:e,pageSize:t})}async getOutgoingStreams(e,t=10){return Ze.newOutgoing({globals:this.globals,query:e,pageSize:t})}async getCoinTypesForStreamFilter(){let e=await this.wallet.address();return(await this.globals.backend.getAllCoinTypes(e)).map(a=>(0,he.normalizeStructTag)(a))}async getRecipientsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllRecipients(t,e)).map(o=>(0,he.normalizeSuiAddress)(o))}async getCreatorsForStreamFilter(e){let t=await this.wallet.address();return(await this.globals.backend.getAllSenders(t,e)).map(o=>(0,he.normalizeSuiAddress)(o))}get wallet(){return this.globals.wallet}builder(){return new Ae(this.globals)}};var Dr=q(require("sort-keys-recursive")),aa=class{constructor(e){this.data=e}serialize(){return JSON.stringify((0,Dr.default)(this.data))}};var N=class extends aa{application="mpay";getClient(e,t){let a=new ta(e==="sui:mainnet"?"prod":"dev");return a.connectSingleWallet(new ea(t)),a}};var et=class extends N{constructor(t){super(t);this.data=t}txType=_r.TransactionType.Stream;txSubType="Cancel";async build(t){let{network:a,account:o}=t;return(await this.getClient(a,o).getStream(this.data.streamId)).cancel()}};var Br=require("@msafe/sui3-utils");var tt=class extends N{constructor(t){super(t);this.data=t}txType=Br.TransactionType.Stream;txSubType="ClaimByProxy";async build(t){let{network:a,account:o}=t;return(await this.getClient(a,o).getStream(this.data.streamId)).claimByProxy()}};var jr=require("@msafe/sui3-utils");var at=class extends N{constructor(t){super(t);this.data=t}txType=jr.TransactionType.Stream;txSubType="Claim";async build(t){let{network:a,account:o}=t;return(await this.getClient(a,o).getStream(this.data.streamId)).claim()}};var Rr=require("@msafe/sui3-utils");var nt=class extends N{constructor(t){super(t);this.data=t}txType=Rr.TransactionType.Stream;txSubType="CreateStream";async build(t){let{network:a,account:o}=t;return this.getClient(a,o).createStream(this.data)}};var Gn=require("@mysten/sui.js/bcs"),ie=require("@mysten/sui.js/utils"),_e=class n{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return n.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return n.getOwnedObjectId(t)}decodeInputU64(e){let t=this.decodePureArg(e,"u64");return BigInt(t)}decodeInputAddress(e){let t=this.decodePureArg(e,"address");return(0,ie.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let a=this.getInputParam(e);return n.getPureInputValue(a,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 a=e.value.Pure;return Gn.bcs.de(t,new Uint8Array(a))}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,ie.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,ie.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,ie.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,ie.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 a=e.value.Pure;return Gn.bcs.de(t,new Uint8Array(a))}typeArg(e){return(0,ie.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var na=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(a=>this.getCreationInfoFromMoveCall(a));return this.aggregateGroupStreamInfo(t)}createStreamTransactions(){let e=this.transactions.filter(t=>t.kind==="MoveCall"&&ne(t.target,this.contract.createStreamTarget));if(e.length===0)throw new O("No create stream transactions");return e.map(t=>new _e(t,this.txb))}getCreationInfoFromMoveCall(e){let t=e.decodeInputString(4),{name:a,groupId:o}=$e(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),p=e.decodeInputBool(11),m=e.typeArg(0);return{name:a,groupId:o,recipient:r,timeStart:i,cliff:s,epochInterval:c,totalEpoch:l,amountPerEpoch:d,cancelable:p,coinType:m}}aggregateGroupStreamInfo(e){if(new Set(e.map(o=>JSON.stringify({name:o.name,groupId:o.groupId,timeStart:String(o.timeStart),epochInterval:String(o.epochInterval),totalEpoch:String(o.totalEpoch),cancelable:o.cancelable,coinType:o.coinType}))).size!==1)throw new v("Stream group not have common info");let a=e.map(o=>({address:o.recipient,amountPerStep:o.amountPerEpoch,cliffAmount:o.cliff}));return{name:e[0].name,coinType:e[0].coinType,recipients:a,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 Q(this.globals.envConfig.contract,this.globals)}get feeContract(){return new ve(this.globals.envConfig.contract,this.globals)}createStreamHelper(){return new ge(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 oa=class{constructor(e,t){this.globals=e;this.txb=t;this.contract=new Q(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"&&ne(t.target,this.contract.createStreamTarget))!==-1}isSetAutoClaimTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ne(this.transactions[0].target,this.contract.setAutoClaimTarget)}isCancelStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ne(this.transactions[0].target,this.contract.cancelStreamTarget)}isClaimStreamTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ne(this.transactions[0].target,this.contract.claimStreamTarget)}isClaimByProxyTransaction(){return this.transactions.length===1&&this.transactions[0].kind==="MoveCall"&&ne(this.transactions[0].target,this.contract.claimStreamByProxyTarget)}decodeCreateStreamTransaction(){return new na(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 _e(e,this.txb)}};var Nr=require("@msafe/sui3-utils");var ot=class extends N{constructor(t){super(t);this.data=t}txType=Nr.TransactionType.Stream;txSubType="SetAutoClaim";async build(t){let{network:a,account:o}=t;return(await this.getClient(a,o).getStream(this.data.streamId)).setAutoClaim(this.data.enabled)}};var ra=class{application="mpay";async deserialize(e){let{network:t,transactionBlock:a}=e,o=ke.new(t==="sui:mainnet"?"prod":"dev"),i=new oa(o,a).decode(),s;switch(i.type){case"CreateStream":s=new nt(i.info);break;case"SetAutoClaim":s=new ot({streamId:i.streamId,enabled:i.enabled});break;case"Claim":s=new at({streamId:i.streamId});break;case"ClaimByProxy":s=new tt({streamId:i.streamId});break;case"Cancel":s=new et({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,a;switch(e.txSubType){case"CreateStream":a=new nt(t);break;case"Claim":a=new at(t);break;case"ClaimByProxy":a=new tt(t);break;case"SetAutoClaim":a=new ot(t);break;case"Cancel":a=new et(t);break;default:throw new Error("not implemented")}return a.build({...e})}};var Be=require("@msafe/sui3-utils");var Er=require("@msafe/sui3-utils");var ia=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:a,account:o}=t;return(0,Er.buildCoinTransferTxb)(a,this.data,o.address)}static fromData(t){return new n(t)}};var Mr=require("@msafe/sui3-utils");var sa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:a,account:o}=t;return(0,Mr.buildObjectTransferTxb)(a,this.data,o.address)}static fromData(t){return new n(t)}};var Lr=require("@msafe/sui3-utils"),Wr=require("@mysten/sui.js/transactions");var ca=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{account:a}=t,o=Wr.TransactionBlock.from(this.data.content);if(!(0,Lr.isSameAddress)(o.blockData.sender,a.address))throw new Error("Invalid sender address");return o}static fromData(t){return new n(t)}};var da=class{application;constructor(){this.application=Be.TransactionDefaultApplication}deserialize(){throw new Error("MSafe core transaction intention should be build from API")}async build(e){let{suiClient:t,account:a}=e,o;switch(e.txSubType){case Be.TransactionSubTypes.assets.coin.send:o=ia.fromData(e.intentionData);break;case Be.TransactionSubTypes.assets.object.send:o=sa.fromData(e.intentionData);break;case Be.TransactionSubTypes.others.plain:o=ca.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:a})}};var Jr=require("@msafe/sui3-utils");var Fr=!1,Ur={ProtocolPackage:"0xc6374c7da60746002bfee93014aeb607e023b2d6b25c9e55a152b826dbc8c1ce",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"},usdc:{name:"USDC",assetId:1,coinType:"usdc",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"}}};async function Kn(){if(!Fr)try{let n=await fetch("https://open-api.naviprotocol.io/api/package").then(t=>t.json()),{packageId:e}=n;Ur.ProtocolPackage=e,Fr=!0}catch(n){console.error(n.message)}}var g=Ur;var je=require("@msafe/sui3-utils"),Hn=require("@mysten/sui.js/bcs"),se=require("@mysten/sui.js/utils");var la=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.isEntryDepositTransaction())return this.decodeEntryDeposit();if(this.isEntryRepayTransaction())return this.decodeEntryRepay();if(this.isEntryWithdrawTransaction())return this.decodeEntryWithdraw();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.getMoveCallTransaction(`${g.ProtocolPackage}::incentive_v2::claim_reward`)}isEntryBorrowTransaction(){return!!this.getMoveCallTransaction(`${g.ProtocolPackage}::incentive_v2::entry_borrow`)}isEntryDepositTransaction(){return!!this.getMoveCallTransaction(`${g.ProtocolPackage}::incentive_v2::entry_deposit`)}isEntryRepayTransaction(){return!!this.getMoveCallTransaction(`${g.ProtocolPackage}::incentive_v2::entry_repay`)}isEntryWithdrawTransaction(){return!!this.getMoveCallTransaction(`${g.ProtocolPackage}::incentive_v2::entry_withdraw`)}findPoolByAssetId(e){let t=Object.values(g.pool).find(a=>a.assetId===e);if(!t)throw new Error("Pool not found");return t}decodeClaimReward(){let e=[];return this.transactions.forEach(t=>{if(t.kind==="MoveCall"&&t.target===`${g.ProtocolPackage}::incentive_v2::claim_reward`){let a=new ua(t,this.txb),o=a.decodeInputU8(4),r=a.decodeInputU8(5),i=a.decodeSharedObjectId(2),s=this.findPoolByAssetId(o),c=[...t.typeArguments];e.push({coinType:s.coinType,option:r,typeArguments:c,assetId:o,poolId:i})}}),console.log("decode claims",e),{txType:je.TransactionType.Other,type:"ClaimReward",intentionData:{claims:e}}}decodeEntryBorrow(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5),a=this.findPoolByAssetId(e);return{txType:je.TransactionType.Other,type:"EntryBorrow",intentionData:{amount:t,coinType:a.coinType}}}decodeEntryDeposit(){let e=this.helper.decodeInputU8(3),t=this.helper.decodeInputU64(5),a=this.findPoolByAssetId(e);return{txType:je.TransactionType.Other,type:"EntryDeposit",intentionData:{amount:t,coinType:a.coinType}}}decodeEntryRepay(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(6),a=this.findPoolByAssetId(e);return{txType:je.TransactionType.Other,type:"EntryRepay",intentionData:{amount:t,coinType:a.coinType}}}decodeEntryWithdraw(){let e=this.helper.decodeInputU8(4),t=this.helper.decodeInputU64(5),a=this.findPoolByAssetId(e);return{txType:je.TransactionType.Other,type:"EntryWithdraw",intentionData:{amount:t,coinType:a.coinType}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(g.ProtocolPackage));return new ua(e,this.txb)}},ua=class n{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return n.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return n.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,se.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let a=this.getInputParam(e);return n.getPureInputValue(a,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 a=e.value.Pure;return Hn.bcs.de(t,new Uint8Array(a))}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,se.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,se.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,se.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,se.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 a=e.value.Pure;return Hn.bcs.de(t,new Uint8Array(a))}typeArg(e){return(0,se.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Vr=require("@mysten/sui.js/transactions");function zn(n,e,t,a){return n.moveCall({target:`${g.ProtocolPackage}::incentive_v2::entry_deposit`,arguments:[n.object("0x06"),n.object(g.StorageId),n.object(e.poolId),n.pure(e.assetId),t,n.pure(a),n.object(g.Incentive),n.object(g.IncentiveV2)],typeArguments:[e.type]}),n}function qr(n,e,t){return n.moveCall({target:`${g.ProtocolPackage}::incentive_v2::entry_withdraw`,arguments:[n.object("0x06"),n.object(g.PriceOracle),n.object(g.StorageId),n.object(e.poolId),n.pure(e.assetId),n.pure(t),n.object(g.Incentive),n.object(g.IncentiveV2)],typeArguments:[e.type]}),n}function $r(n,e,t){return n.moveCall({target:`${g.ProtocolPackage}::incentive_v2::entry_borrow`,arguments:[n.object("0x06"),n.object(g.PriceOracle),n.object(g.StorageId),n.object(e.poolId),n.pure(e.assetId),n.pure(t),n.object(g.IncentiveV2)],typeArguments:[e.type]}),n}function Jn(n,e,t,a){return n.moveCall({target:`${g.ProtocolPackage}::incentive_v2::entry_repay`,arguments:[n.object("0x06"),n.object(g.PriceOracle),n.object(g.StorageId),n.object(e.poolId),n.pure(e.assetId),t,n.pure(a),n.object(g.IncentiveV2)],typeArguments:[e.type]}),n}function Qr(n,e,t,a,o){return n.moveCall({target:`${g.ProtocolPackage}::incentive_v2::claim_reward`,arguments:[n.object("0x06"),n.object(g.IncentiveV2),n.object(t),n.object(g.StorageId),n.pure(e),n.pure(a)],typeArguments:o}),n}var pa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let{claims:t}=this.data,a=new Vr.TransactionBlock;return t.forEach(o=>{let{assetId:r,poolId:i,option:s,typeArguments:c}=o;Qr(a,r,i,s,c)}),a.setGasBudget(g.gasBudget),a}static fromData(t){return new n(t)}};var Gr=require("@mysten/sui.js/transactions");var ma=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let{coinType:t,amount:a}=this.data,o=new Gr.TransactionBlock;o.setGasBudget(g.gasBudget),console.log("build",this.data);let r=g.pool[t];if(!r)throw new Error(`${t} not support, please use ${Object.keys(g.pool).join(", ")}.`);return $r(o,r,a)}static fromData(t){return new n(t)}};var Kr=require("@mysten/sui.js/transactions");async function ba(n,e,t){let a=await n.getCoins({owner:e,coinType:t});return console.log("getTokenObjs",e,a),a}var fa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:a,account:o}=t,{coinType:r,amount:i}=this.data,s=new Kr.TransactionBlock;if(s.setGasBudget(g.gasBudget),console.log("build",this.data),r==="sui"){let[p]=s.splitCoins(s.gas,[i]);return zn(s,g.pool.sui,p,i)}let c=g.pool[r];if(!c)throw new Error(`${r} not support, please use ${Object.keys(g.pool).join(", ")}.`);let l=await ba(a,o.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 zn(s,c,s.object(d),i)}static fromData(t){return new n(t)}};var Hr=require("@mysten/sui.js/transactions");var ga=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let{suiClient:a,account:o}=t,{coinType:r,amount:i}=this.data,s=new Hr.TransactionBlock;if(s.setGasBudget(g.gasBudget),console.log("build",this.data),r==="sui"){let[p]=s.splitCoins(s.gas,[i]);return Jn(s,g.pool.sui,p,i)}let c=g.pool[r];if(!c)throw new Error(`${r} not support, please use ${Object.keys(g.pool).join(", ")}.`);let l=await ba(a,o.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 Jn(s,c,s.object(d),i)}static fromData(t){return new n(t)}};var zr=require("@mysten/sui.js/transactions");var ha=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(){let{coinType:t,amount:a}=this.data,o=new zr.TransactionBlock;console.log("build",this.data),o.setGasBudget(g.gasBudget);let r=g.pool[t];if(!r)throw new Error(`${t} not support, please use ${Object.keys(g.pool).join(", ")}.`);return qr(o,r,a)}static fromData(t){return new n(t)}};var ya=class{application="navi";async deserialize(e){await Kn();let{transactionBlock:t}=e,o=new la(t).decode();return{txType:Jr.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:a}=e,o;switch(await Kn(),e.txSubType){case"EntryDeposit":o=fa.fromData(e.intentionData);break;case"EntryBorrow":o=ma.fromData(e.intentionData);break;case"EntryRepay":o=ga.fromData(e.intentionData);break;case"EntryWithdraw":o=ha.fromData(e.intentionData);break;case"ClaimReward":o=pa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:a})}};var wa=require("@msafe/sui3-utils"),Xr=require("@mysten/sui.js/transactions"),Ca=require("@mysten/sui.js/utils"),Xs=q(require("sort-keys-recursive")),Ys="msafe-plain-tx",Zs=wa.TransactionSubTypes.others.plain;var Sa=class{application;constructor(){this.application=Ys}async deserialize(e){let{transactionBlock:t,suiClient:a}=e,o=await t.build({client:a});return{txType:wa.TransactionType.Other,txSubType:Zs,intentionData:{content:(0,Ca.toHEX)(o)}}}async build(e){let{suiClient:t,account:a}=e,o=Xr.TransactionBlock.from((0,Ca.fromHEX)(e.intentionData.content)),r=await t.devInspectTransactionBlock({transactionBlock:o,sender:a.address});if(!(r.effects.status.status==="success"))throw new Error(r.effects.status.error);return o}};var Ta=class{apps;constructor(e){this.apps=new Map(e.map(t=>[t.application,t]))}getAppHelper(e){let t=this.apps.get(e);if(!t)throw new Error(`${e} not registered`);return t}};var Oi=require("@msafe/sui3-utils");var A=require("@msafe/sui3-utils"),va=require("@mysten/sui.js/bcs"),le=require("@mysten/sui.js/utils");var ce="6601955b8b0024600a917079",Ia="0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";var Re="0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",de="0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6::sca::SCA",Se=["eth","btc","usdc","usdt","sui","apt","sol","cetus","afsui","hasui","vsui","sca"],ka=["eth","btc","usdc","usdt","sui","apt","sol","cetus","afsui","hasui","vsui","sca"],rt=["seth","ssui","susdc","susdt","scetus","safsui","shasui","svsui"],Yr=["sui"],Ne=["sui","usdc","usdt"];var Zr={eth:8,btc:8,usdc:6,usdt:6,sui:9,apt:8,sol:8,sca:9,cetus:9,afsui:9,hasui:9,vsui:9,seth:8,sbtc:8,susdc:6,susdt:6,ssui:9,sapt:8,ssol:8,scetus:9,safsui:9,shasui:9,svsui:9,ssca:9};var xa={seth:"sui",ssui:"sui",susdc:"sui",susdt:"sui",scetus:"sui",safsui:"sui",shasui:"sui",svsui:"sui"},ei={sui:["sui","sca"],usdc:["sui","sca"],usdt:["sui","sca"]},ti={sui:"0x0000000000000000000000000000000000000000000000000000000000000002",eth:"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",btc:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",usdc:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",usdt:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",apt:"0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",sol:"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",cetus:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",afsui:"0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",hasui:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",vsui:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",sca:"0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6"},B={eth:"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",btc:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",usdc:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",usdt:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",apt:"0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",sol:"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8"},Xn={vsui:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55"};var Aa=class{constructor(e,t){this.txb=e;this._builder=t}_builder;decode(){if(this.isExtendPeriodAndStakeMoreSca())return this.decodePeriodAndStakeMoreSca();if(this.isStakeScaFirsTime()||this.isStakeMoreSca())return this.decodeStakeSca();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.isWithdrawLendingTransaction())return this.decodeWithdrawLending();if(this.isSupplyLendingTransaction())return this.decodeSupplyLending();if(this.isBorrowWithBoostTransaction())return this.decodeBorrowWithBoost();if(this.isBorrowTransaction())return this.decodeBorrow();if(this.isRepayTransaction())return this.decodeRepay();if(this.isUnstakeSpoolTransaction())return this.decodeUnstakeSpool();if(this.isClaimRewardTransaction())return this.decodeClaimReward();if(this.isRenewExpiredVeSca())return this.decodeRenewExpiredVeSca();if(this.isExtendPeriod())return this.decodeExtendStakePeriod();if(this.isOpenObligationTransaction())return this.decodeOpenObligation();if(this.isRedeemSca())return this.decodeRedeemSca();if(this.isMigrateAndClaim())return this.decodeMigrateAndClaim();throw new Error("Unknown transaction type")}get coreId(){return{protocolPkg:this._builder.address.get("core.packages.protocol.id"),market:this._builder.address.get("core.market"),version:this._builder.address.get("core.version"),coinDecimalsRegistry:this._builder.address.get("core.coinDecimalsRegistry"),xOracle:this._builder.address.get("core.oracles.xOracle"),spoolPkg:this._builder.address.get("spool.id"),borrowIncentivePkg:this._builder.address.get("borrowIncentive.id"),veScaPkgId:this._builder.address.get("vesca.id")}}get transactions(){return this.txb.blockData.transactions}get inputTransaction(){return this.txb.blockData.inputs}getMoveCallTransaction(e){return this.transactions.find(t=>t.kind==="MoveCall"&&t.target===e)}isSupplyLendingTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::mint::mint`)}isSupplyWithStakeSpoolTransaction(){let e=this.getMoveCallTransaction(`${this.coreId.protocolPkg}::mint::mint`),t=this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::stake`);return!!e&&!!t}isUnstakeAndWithdrawTransaction(){let e=this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::unstake`),t=this.getMoveCallTransaction(`${this.coreId.protocolPkg}::redeem::redeem`);return!!e&&!!t}isStakeSpoolTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::stake`)}isWithdrawLendingTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::redeem::redeem`)}isDepositCollateralTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`)}isWithdrawCollateralTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`)}isBorrowTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::borrow::borrow`)}isBorrowWithBoostTransaction(){let e=this.getMoveCallTransaction(`${this.coreId.protocolPkg}::borrow::borrow`),t=this.getMoveCallTransaction(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`);return!!e&&!!t}isRepayTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::repay::repay`)}isUnstakeSpoolTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::unstake`)}isCreateStakeAccountTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::new_spool_account`)}isClaimRewardTransaction(){let e=this.getMoveCallTransaction(`${this.coreId.spoolPkg}::user::redeem_rewards`),t=this.getMoveCallTransaction(`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`);return!!e||!!t}isStakeScaFirsTime(){return!!this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`)}isExtendPeriodAndStakeMoreSca(){let e=this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`),t=this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`);return!!e&&!!t}isRedeemSca(){return!!this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::redeem`)}isStakeMoreSca(){return!!this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`)}isExtendPeriod(){return!!this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`)}isRenewExpiredVeSca(){return!!this.getMoveCallTransaction(`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`)}isOpenObligationTransaction(){return!!this.getMoveCallTransaction(`${this.coreId.protocolPkg}::open_obligation::open_obligation_entry`)}isMigrateAndClaim(){let e=this.getMoveCallTransaction(`${Re}::user::redeem_rewards`),t=this.getMoveCallTransaction(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`);return!!e&&!!t}decodeMigrateAndClaim(){let e=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),t=this.helperClaimBorrowReward[0].decodeSharedObjectId(2),a=this.helperClaimBorrowReward[0].decodeOwnedObjectId(3),o=this._builder.utils.parseCoinNameFromType(this.helperClaimBorrowReward[0].typeArg(0));return{txType:A.TransactionType.Other,type:"MigrateAndClaim",intentionData:{veScaKey:e,obligationKey:t,obligationId:a,rewardCoinName:o}}}decodeOpenObligation(){return{txType:A.TransactionType.Other,type:"OpenObligation",intentionData:{}}}decodeRedeemSca(){let e=this.helperRedeemSca.decodeOwnedObjectId(1);return{txType:A.TransactionType.Other,type:"RedeemSca",intentionData:{veScaKey:e}}}decodeRenewExpiredVeSca(){let e=this.helperRenewExpired.getNestedInputParam(4),t=this.helperRenewExpired.decodeInputU64(5),a=new E(e,this.txb).getAmountInput().reduce((f,y)=>f+y,0),o=this.helperRenewExpired.decodeOwnedObjectId(1),r=!!this.helperRedeemSca.moveCall,i=[],s=[],c=[];this.helperOldUnstakeObligation.moveCall&&(i=[this.helperOldUnstakeObligation.decodeSharedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(s=[this.helperUnstakeObligation.decodeSharedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(c=[this.helperStakeObligationWithVeSca.decodeSharedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let l=!1,d=!1,p,m,b=[{condition:i,isOld:!0},{condition:s,isOld:!1},{condition:c,isOld:!1}];for(let f=0;f<b.length;f++)b[f].condition.length>1&&([m,p]=b[f].condition,l=!0,d=b[f].isOld);return{txType:A.TransactionType.Other,type:"RenewExpStakePeriod",intentionData:{amount:a,lockPeriodInDays:t,obligationId:p,obligationKey:m,veScaKey:o,isHaveRedeem:r,isObligationLocked:l,isOldBorrowIncentive:d}}}decodeExtendStakePeriod(){let e=this.helperExtendStakePeriod.decodeInputU64(4),t=this.helperExtendStakePeriod.decodeOwnedObjectId(1),a=[],o=[],r=[];this.helperOldUnstakeObligation.moveCall&&(a=[this.helperOldUnstakeObligation.decodeSharedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(o=[this.helperUnstakeObligation.decodeSharedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeObligationWithVeSca.moveCall&&(r=[this.helperStakeObligationWithVeSca.decodeSharedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let i=!1,s=!1,c,l,d=[{condition:a,isOld:!0},{condition:o,isOld:!1},{condition:r,isOld:!1}];for(let p=0;p<d.length;p++)d[p].condition.length>1&&([l,c]=d[p].condition,i=!0,s=d[p].isOld);return{txType:A.TransactionType.Other,type:"ExtendStakePeriod",intentionData:{lockPeriodInDays:e,obligationId:c,obligationKey:l,veScaKey:t,isObligationLocked:i,isOldBorrowIncentive:s}}}decodePeriodAndStakeMoreSca(){let e=this.helperStakeMoreSca.getNestedInputParam(4),t=this.helperExtendStakePeriod.decodeInputU64(4),a=new E(e,this.txb).getAmountInput().reduce((b,f)=>b+f,0),o=[],r=[],i,s=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeSharedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(r=[this.helperUnstakeObligation.decodeSharedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(i=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(s=[this.helperStakeObligationWithVeSca.decodeSharedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,l=!1,d,p,m=[{condition:o,isOld:!0},{condition:r,isOld:!1},{condition:s,isOld:!1}];for(let b=0;b<m.length;b++)m[b].condition.length>1&&([p,d]=m[b].condition,c=!0,l=m[b].isOld);return{txType:A.TransactionType.Other,type:"ExtendPeriodAndStakeMore",intentionData:{amount:a,veScaKey:i,lockPeriodInDays:t,obligationId:d,obligationKey:p,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),console.log(e));let a=new E(e,this.txb).getAmountInput().reduce((b,f)=>b+f,0),o=[],r=[],i,s=[];this.helperOldUnstakeObligation.moveCall&&(o=[this.helperOldUnstakeObligation.decodeSharedObjectId(2),this.helperOldUnstakeObligation.decodeSharedObjectId(3)]),this.helperUnstakeObligation.moveCall&&(r=[this.helperUnstakeObligation.decodeSharedObjectId(3),this.helperUnstakeObligation.decodeSharedObjectId(4)]),this.helperStakeMoreSca.moveCall&&(i=this.helperStakeMoreSca.decodeOwnedObjectId(1)),this.helperStakeObligationWithVeSca.moveCall&&(s=[this.helperStakeObligationWithVeSca.decodeSharedObjectId(3),this.helperStakeObligationWithVeSca.decodeSharedObjectId(4)]);let c=!1,l=!1,d,p,m=[{condition:o,isOld:!0},{condition:r,isOld:!1},{condition:s,isOld:!1}];for(let b=0;b<m.length;b++)m[b].condition.length>1&&([p,d]=m[b].condition,c=!0,l=m[b].isOld);return{txType:A.TransactionType.Other,type:"StakeSca",intentionData:{amount:a,lockPeriodInDays:t,obligationId:d,obligationKey:p,veScaKey:i,isObligationLocked:c,isOldBorrowIncentive:l}}}decodeSupplyLending(){let e=this._builder.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),a=new E(t,this.txb).getAmountInput().reduce((o,r)=>o+r,0);return{txType:A.TransactionType.Other,type:"SupplyLending",intentionData:{amount:a,coinName:e}}}decodeWithdrawLending(){let e=this._builder.utils.parseCoinNameFromType(this.helperRedeem.typeArg(0)),t=this.helperRedeem.getNestedInputParam(2),a=new E(t,this.txb).getAmountInput().reduce((o,r)=>o+r,0);return{txType:A.TransactionType.Other,type:"WithdrawLending",intentionData:{amount:a,coinName:e}}}decodeDepositCollateral(){let e=this._builder.utils.parseCoinNameFromType(this.helperDepositCollateral.typeArg(0)),t=this.helperDepositCollateral.getNestedInputParam(3),a=new E(t,this.txb).getAmountInput().reduce((r,i)=>r+i,0),o=this.helperDepositCollateral.decodeSharedObjectId(1);return{txType:A.TransactionType.Other,type:"DepositCollateral",intentionData:{amount:a,obligationId:o,collateralCoinName:e}}}decodeWithdrawCollateral(){let e=this._builder.utils.parseCoinNameFromType(this.helperWithdrawCollateral.typeArg(0)),t=this.helperWithdrawCollateral.decodeInputU64(5),a=this.helperWithdrawCollateral.decodeSharedObjectId(1),o=this.helperWithdrawCollateral.decodeOwnedObjectId(2);return{txType:A.TransactionType.Other,type:"WithdrawCollateral",intentionData:{amount:t,collateralCoinName:e,obligationKey:o,obligationId:a}}}decodeBorrow(){let e=this._builder.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperBorrow.decodeInputU64(5),a=this.helperBorrow.decodeSharedObjectId(1),o=this.helperBorrow.decodeOwnedObjectId(2);return{txType:A.TransactionType.Other,type:"Borrow",intentionData:{amount:t,coinName:e,obligationKey:o,obligationId:a}}}decodeBorrowWithBoost(){let e=this._builder.utils.parseCoinNameFromType(this.helperBorrow.typeArg(0)),t=this.helperStakeObligationWithVeSca.decodeOwnedObjectId(9),a=this.helperBorrow.decodeInputU64(5),o=this.helperBorrow.decodeSharedObjectId(1),r=this.helperBorrow.decodeOwnedObjectId(2);return{txType:A.TransactionType.Other,type:"BorrowWithBoost",intentionData:{amount:a,coinName:e,obligationKey:r,obligationId:o,veScaKey:t}}}decodeRepay(){let e=this._builder.utils.parseCoinNameFromType(this.helperRepay.typeArg(0)),t=this.helperRepay.getNestedInputParam(3),a=new E(t,this.txb).getAmountInput().reduce((r,i)=>r+i,0),o=this.helperRepay.decodeSharedObjectId(1);return{txType:A.TransactionType.Other,type:"Repay",intentionData:{amount:a,obligationId:o,coinName:e}}}decodeStakeSpool(){let e;this.isCreateStakeAccountTransaction()||(e=this.helperStake.decodeOwnedObjectId(1));let t=this.helperStake.getNestedInputParam(2),a=new E(t,this.txb).getAmountInput().reduce((i,s)=>i+s,0),o=this.helperStake.typeArg(0),r=this._builder.utils.parseCoinNameFromType(o);return{txType:A.TransactionType.Other,type:"StakeSpool",intentionData:{amount:a,marketCoinName:r,stakeAccountId:e}}}decodeUnstakeSpool(){let e=this.helperUnstake.decodeOwnedObjectId(1),t=this.helperUnstake.decodeInputU64(2),a=this.helperUnstake.typeArg(0),o=this._builder.utils.parseCoinNameFromType(a);return{txType:A.TransactionType.Other,type:"UnstakeSpool",intentionData:{amount:t,marketCoinName:o,stakeAccountId:e}}}decodeSupplyWithStakeSpool(){let e=this._builder.utils.parseCoinNameFromType(this.helperMint.typeArg(0)),t=this.helperMint.getNestedInputParam(2),a=new E(t,this.txb).getAmountInput().reduce((r,i)=>r+i,0),o;return this.isCreateStakeAccountTransaction()||(o=this.helperStake.decodeOwnedObjectId(1)),{txType:A.TransactionType.Other,type:"SupplyAndStakeLending",intentionData:{amount:a,coinName:e,stakeAccountId:o}}}decodeUnstakeAndWithdraw(){let e=[];this.helperUnstakes.forEach(r=>{let i=r.decodeOwnedObjectId(1),s=r.decodeInputU64(2);e.push({id:i,coin:s})});let t=this._builder.utils.parseCoinNameFromType(this.helperRedeems[0].typeArg(0)),a=this.helperRedeems.find(r=>r.isHaveNestedInput(2)),o;return a&&(o=new E(a.getNestedInputParam(2),this.txb).getAmountInput().reduce((r,i)=>r+i,0)),{txType:A.TransactionType.Other,type:"WithdrawAndUnstakeLending",intentionData:{amount:o,coinName:t,stakeAccountId:e}}}decodeClaimReward(){let e=[],t=[],a=[];return this.helperClaimLendingReward.forEach(o=>{let r=o.decodeOwnedObjectId(2),i=o.typeArg(0),s=this._builder.utils.parseCoinNameFromType(i);e.push({stakeMarketCoinName:s,stakeAccountId:r})}),this.helperClaimBorrowV2Reward.forEach(o=>{let r=o.decodeSharedObjectId(3),i=o.decodeOwnedObjectId(4),s=this._builder.utils.parseCoinNameFromType(o.typeArg(0));t.push({obligationId:i,obligationKey:r,rewardCoinName:s})}),this.helperClaimBorrowReward.forEach(o=>{let r=o.decodeSharedObjectId(2),i=o.decodeOwnedObjectId(3),s=this._builder.utils.parseCoinNameFromType(o.typeArg(0));a.push({obligationId:i,obligationKey:r,rewardCoinName:s})}),{txType:A.TransactionType.Other,type:"ClaimIncentiveReward",intentionData:{lendingIncentive:e,borrowIncentiveV2:t,borrowIncentive:a}}}get helperClaimLendingReward(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.spoolPkg}::user::redeem_rewards`)).map(t=>new T(t,this.txb))}get helperClaimBorrowV2Reward(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.borrowIncentivePkg}::user::redeem_rewards`)).map(t=>new T(t,this.txb))}get helperStakeMoreSca(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.veScaPkgId}::ve_sca::lock_more_sca`));return new T(e,this.txb)}get helperStakeSca(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.veScaPkgId}::ve_sca::mint_ve_sca_key`));return new T(e,this.txb)}get helperExtendStakePeriod(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.veScaPkgId}::ve_sca::extend_lock_period`));return new T(e,this.txb)}get helperRedeemSca(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.veScaPkgId}::ve_sca::redeem`));return new T(e,this.txb)}get helperRenewExpired(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.veScaPkgId}::ve_sca::renew_expired_ve_sca`));return new T(e,this.txb)}get helperOldUnstakeObligation(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${Re}::user::unstake`));return new T(e,this.txb)}get helperUnstakeObligation(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.borrowIncentivePkg}::user::unstake`));return new T(e,this.txb)}get helperStakeObligationWithVeSca(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.borrowIncentivePkg}::user::stake_with_ve_sca`));return new T(e,this.txb)}get helperClaimBorrowReward(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target.startsWith(`${Re}::user::redeem_rewards`)).map(t=>new T(t,this.txb))}get helperMint(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::mint::mint`));return new T(e,this.txb)}get helperUnstakes(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.spoolPkg}::user::unstake`)).map(t=>new T(t,this.txb))}get helperRedeems(){return this.transactions.filter(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::redeem::redeem`)).map(t=>new T(t,this.txb))}get helperRedeem(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::redeem::redeem`));return new T(e,this.txb)}get helperStake(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.spoolPkg}::user::stake`));return new T(e,this.txb)}get helperUnstake(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.spoolPkg}::user::unstake`));return new T(e,this.txb)}get helperDepositCollateral(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::deposit_collateral::deposit_collateral`));return new T(e,this.txb)}get helperWithdrawCollateral(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::withdraw_collateral::withdraw_collateral`));return new T(e,this.txb)}get helperBorrow(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::borrow::borrow`));return new T(e,this.txb)}get helperRepay(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(`${this.coreId.protocolPkg}::repay::repay`));return new T(e,this.txb)}},E=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)}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let a=e.value.Pure;return va.bcs.de(t,new Uint8Array(a))}return e.value}},T=class n{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return n.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return n.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,le.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let a=this.getInputParam(e);return n.getPureInputValue(a,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]}getNestedInputParam(e){let t=this.moveCall.arguments[e];if(t.kind!=="NestedResult")throw new Error("not input type");return this.txb.blockData.transactions[t.index]}isHaveNestedInput(e){return this.moveCall.arguments[e].kind==="NestedResult"}static getPureInputValue(e,t){if(e.type!=="pure")throw new Error("not pure argument");if(typeof e.value=="object"&&"Pure"in e.value){let a=e.value.Pure;return va.bcs.de(t,new Uint8Array(a))}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,le.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,le.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,le.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,le.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 a=e.value.Pure;return va.bcs.de(t,new Uint8Array(a))}typeArg(e){return(0,le.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var I=require("@mysten/sui.js/transactions"),Ai=require("@mysten/sui.js/utils"),io=q(require("bignumber.js"));var ai={mainnet:{core:{version:"0x07871c4b3c847a0f674510d4978d5cf6f960452795e8ff6f189fd2088a3f6ac7",versionCap:"0x590a4011cb649b3878f3ea14b3a78674642a9548d79b7e091ef679574b158a07",object:"0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf",market:"0xa757975255146dc9686aa823b7838b507f315d704f428cbadad2f4ea061939d9",adminCap:"0x09689d018e71c337d9db6d67cbca06b74ed92196103624028ccc3ecea411777c",coinDecimalsRegistry:"0x200abe9bf19751cc566ae35aa58e2b7e4ff688fc1130f8d8909ea09bc137d668",obligationAccessStore:"0x733e30b7c94d619d78cb8f5bc4bfbb759ced9a531239028caabb2474e5be59c9",coins:{cetus:{id:"0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b",metaData:"0x4c0dce55eff2db5419bbd2d239d1aa22b4a400c01bbb648b058a9883989025da",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"e5b274b2611143df055d6e7cd8d93fe1961716bcd4dca1cad87a83bc1e78c1ef",feedObject:"0x24c0247fb22457a719efac7f670cdc79be321b521460bd6bd2ccfa9f80713b14"}}},apt:{id:"0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37",metaData:"0xc969c5251f372c0f34c32759f1d315cf1ea0ee5e4454b52aea08778eacfdd0a8",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5",feedObject:"0x7c5b7837c44a69b469325463ac0673ac1aa8435ff44ddb4191c9ae380463647f"}}},sol:{id:"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",metaData:"0x4d2c39082b4477e3e79dc4562d939147ab90c42fc5f3e4acf03b94383cd69b6e",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"ef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d",feedObject:"0x9d0d275efbd37d8a8855f6f2c761fa5983293dd8ce202ee5196626de8fcd4469"}}},btc:{id:"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",metaData:"0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43",feedObject:"0x9a62b4863bdeaabdc9500fce769cf7e72d5585eeb28a6d26e4cafadc13f76ab2"}}},eth:{id:"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",metaData:"0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",feedObject:"0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab"}}},usdc:{id:"0x5d4b302506645c37ff133b98c4b50a5ae14841659738d6d733d59d0d217a93bf",metaData:"0x4fbf84f3029bd0c0b77164b587963be957f853eccf834a67bb9ecba6ec80f189",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a",feedObject:"0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab"}}},usdt:{id:"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",metaData:"0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b",feedObject:"0x985e3db9f93f76ee8bace7c3dd5cc676a096accd5d9e09e9ae0fb6e492b14572"}}},sui:{id:"0x0000000000000000000000000000000000000000000000000000000000000002",metaData:"0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3",treasury:"",oracle:{supra:"",switchboard:"0xbca474133638352ba83ccf7b5c931d50f764b09550e16612c9f70f1e21f3f594",pyth:{feed:"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",feedObject:"0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"}}},afsui:{id:"0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc",metaData:"0x2f9217f533e51334873a39b8026a4aa6919497b47f49d0986a4f1aec66f8a34d",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",feedObject:"0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"}}},hasui:{id:"0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d",metaData:"0x2c5f33af93f6511df699aaaa5822d823aac6ed99d4a0de2a4a50b3afa0172e24",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",feedObject:"0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"}}},vsui:{id:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",metaData:"0xabd84a23467b33854ab25cf862006fd97479f8f6f53e50fe732c43a274d939bd",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744",feedObject:"0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37"}}},sca:{id:"0x7016aae72cfc67f2fadf55769c0a7dd54291a583b63051a5ed71081cce836ac6",metaData:"0x5d26a1e9a55c88147ac870bfa31b729d7f49f8804b8b3adfdf3582d301cca844",treasury:"",oracle:{supra:"",switchboard:"",pyth:{feed:"7e17f0ac105abe9214deb9944c30264f5986bf292869c6bd8e8da3ccd92d79bc",feedObject:"0xf6de1d3279a269a597d813cbaca59aa906543ab9a8c64e84a4722f1a20863985"}}}},oracles:{xOracle:"0x93d5bf0936b71eb27255941e532fac33b5a5c7759e377b4923af0a1359ad494f",xOracleCap:"0x1edeae568fde99e090dbdec4bcdbd33a15f53a1ce1f87aeef1a560dedf4b4a90",supra:{registry:"",registryCap:"",holder:""},switchboard:{registry:"",registryCap:""},pyth:{registry:"0xedc293f9413a5a7a5d53bdba1fd889d0a4030894469228f0acdae4aa3c55a213",registryCap:"0xbcb07141eb1f7e01fbda4130ecf5f5adaeabb77f5d9c32158b7532bcd2197acd",state:"0x1f9310238ee9298fb703c3419030b35b22bb1cc37113e3bb5007c99aec79e5b8",wormhole:"0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a",wormholeState:"0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"}},packages:{coinDecimalsRegistry:{id:"0xca5a5a62f01c79a104bf4d31669e29daa387f325c241de4edbe30986a9bc8b0d",upgradeCap:"0x34e76a945d29f195bc53ca704fa70877d1cf3a5d7bbfdda1b13e633fff13c0f6"},math:{id:"0xad013d5fde39e15eabda32b3dbdafd67dac32b798ce63237c27a8f73339b9b6f",upgradeCap:"0x3a329598231de02e6135c62284b66005b41cad1d9ab7ca2dc79c08293aba2ec6"},whitelist:{id:"0x1318fdc90319ec9c24df1456d960a447521b0a658316155895014a6e39b5482f",upgradeCap:"0xf5a22aea23db664f7b69855b6a546747f17c1ec4230319cfc17225e462b05761"},x:{id:"0x779b5c547976899f5474f3a5bc0db36ddf4697ad7e5a901db0415c2281d28162",upgradeCap:"0x3f203f6fff6a69d151e4f1cd931f22b68c489ef2759765662fc7baf673943c9e"},protocol:{id:"0x38fe42a5a69f7eb3635404389e8003be9457b1a5c873f133184648c7e9bd47b7",upgradeCap:"0x38527d154618d1fd5a644b90717fe07cf0e9f26b46b63e9568e611a3f86d5c1a"},protocolWhitelist:{id:"0x4c262d9343dac53ecb28f482a2a3f62c73d0ebac5b5f03d57383d56ff219acdf",upgradeCap:"0x4a5e88a75039b00988f633f811f58117f31b8627a46bf822aa114d9010049449"},query:{id:"0xb8d603a39114a5efef3dd0bf84df0bed1be1fbd39b78b7dd6e8a61ccc5e6006f",upgradeCap:"0x0d535c35f608b9b01b7ccce11acf43b1dd80c1b72bf8b541744a6e28e8d2745f"},supra:{id:"",upgradeCap:""},pyth:{id:"0x910f30cbc7f601f75a5141a01265cd47c62d468707c5e1aecb32a18f448cb25a",upgradeCap:"0xdf0ffbae1ea5bb25fbca5efba433dcf00c7cced65679af2f04728901275c6157"},switchboard:{id:"",upgradeCap:""},xOracle:{id:"0x1478a432123e4b3d61878b629f2c692969fdb375644f1251cd278a4b1e7d7cd6",upgradeCap:"0x0f928a6b2e26b73330fecaf9b44acfc9800a4a9794d6415c2a3153bc70e3c1f0"},testCoin:{id:"",upgradeCap:""}}},spool:{id:"0xec1ac7f4d01c5bf178ff4e62e523e7df7721453d81d4904a42a0ffc2686c843d",adminCap:"0xdd8a047cbbf802bfcde5288b8ef1910965d789cc614da11d39af05fca0bd020a",object:"0xe87f1b2d498106a2c61421cec75b7b5c5e348512b0dc263949a0e7a3c256571a",pools:{seth:{id:"0xeec40beccb07c575bebd842eeaabb835f77cd3dab73add433477e57f583a6787",rewardPoolId:"0x957de68a18d87817de8309b30c1ec269a4d87ae513abbeed86b5619cb9ce1077"},ssui:{id:"0x4f0ba970d3c11db05c8f40c64a15b6a33322db3702d634ced6536960ab6f3ee4",rewardPoolId:"0x162250ef72393a4ad3d46294c4e1bdfcb03f04c869d390e7efbfc995353a7ee9"},susdc:{id:"0x4ace6648ddc64e646ba47a957c562c32c9599b3bba8f5ac1aadb2ae23a2f8ca0",rewardPoolId:"0xf4268cc9b9413b9bfe09e8966b8de650494c9e5784bf0930759cfef4904daff8"},susdt:{id:"0xcb328f7ffa7f9342ed85af3fdb2f22919e1a06dfb2f713c04c73543870d7548f",rewardPoolId:"0x2c9f934d67a5baa586ceec2cc24163a2f049a6af3d5ba36b84d8ac40f25c4080"},scetus:{id:"0xac1bb13bf4472a637c18c2415fb0e3c1227ea2bcf35242e50563c98215bd298e",rewardPoolId:"0x6835c1224126a45086fc6406adc249e3f30df18d779ca4f4e570e38716a17f3f"},safsui:{id:"0xeedf438abcaa6ce4d9625ffca110920592d5867e4c5637d84ad9f466c4feb800",rewardPoolId:"0x89255a2f86ed7fbfef35ab8b7be48cc7667015975be2685dd9a55a9a64baf76e"},shasui:{id:"0xa6148bc1b623e936d39a952ceb5bea79e8b37228a8f595067bf1852efd3c34aa",rewardPoolId:"0x6f3563644d3e2ef13176dbf9d865bd93479df60ccbe07b7e66db57f6309f5a66"},svsui:{id:"0x69ce8e537e750a95381e6040794afa5ab1758353a1a2e1de7760391b01f91670",rewardPoolId:"0xbca914adce058ad0902c7f3cfcd698392a475f00dcfdc3f76001d0370b98777a"}},version:"",versionCap:""},borrowIncentive:{id:"0x874f1d43d81e2256e120bab2485938fe07ba0cc21d87129a99a1db11cacb382d",adminCap:"0xc486afa253646f4d381e81d7f1df8aa4723b845a6bb356f69bad635ffefffe2c",object:"0x002875153e09f8145ab63527bc85c00f2bd102e12f9573c47f8cdf1a1cb62934",query:"0x529edc54a3dce2207703ceebbccb0ac14133f7825c1f528775ba0d85a4063489",incentivePools:"0x6547e143d406b5ccd5f46aae482497de279cc1a68c406f701df70a05f9212ab4",incentiveAccounts:"0xc4701fdbc1c92f9a636d334d66012b3027659e9fb8aff27279a82edfb6b77d02",config:"0xdf5d04b4691cc67e82fd4db8394d89ff44823a9de29716c924f74bb4f11cc1f7",version:"",versionCap:""},vesca:{id:"0xcfe2d87aa5712b67cad2732edb6a2201bfdf592377e5c0968b7cb02099bd8e21",adminCap:"0x4d105b16467acca81d18c132cdd1a3cee159920a86c1ef4bdbf2e8d7878500c5",tableId:"0x0a0b7f749baeb61e3dfee2b42245e32d0e6b484063f0a536b33e771d573d7246",table:"0xd3a4632b1080f7d96e1c2487d4dabf2c1196916937c505a69954ac9f393be8d0",treasury:"0xafa4b6231e49c15a22d641ce33fda761baaf650fa21899dfa2eb1716146e7306",config:"0x7cbcb0a342179577a117dfdff974cf1ab765d3b571067bf22ddf5f9e3a667922"}}};var V=class{_auth;_id;_network;_currentAddresses;_addressesMap;constructor(e){let{id:t,auth:a,network:o}=e;a&&(this._auth=a),this._id=t,this._network=o||"mainnet",this._addressesMap=new Map}getId(){return this._id||void 0}get(e){if(this._currentAddresses)return e.split(".").reduce((a,o)=>typeof a=="object"?a[o]:a,this._currentAddresses)||void 0}set(e,t){if(this._currentAddresses){let a=e.split(".");a.reduce((o,r,i)=>{if(i===a.length-1){let s=o;s[r]=t}return o[r]},this._currentAddresses)}return this._currentAddresses}switchCurrentAddresses(e){return this._addressesMap.has(e)&&(this._currentAddresses=this._addressesMap.get(e),this._network=e),this._currentAddresses}getAddresses(e){return e?this._addressesMap.get(e):this._currentAddresses??this._addressesMap.get(this._network)}setAddresses(e,t){let a=t||this._network;a===this._network&&(this._currentAddresses=e),this._addressesMap.set(a,e)}getAllAddresses(){return Object.fromEntries(this._addressesMap)}read(){return Object.entries(ai).forEach(([e,t])=>{["localnet","devnet","testnet","mainnet"].includes(e)&&(e===this._network&&(this._currentAddresses=t),this._addressesMap.set(e,t))}),this.getAllAddresses()}};var Ti=require("@mysten/sui.js/transactions"),Ii=require("@mysten/sui.js/utils");var st=require("@mysten/sui.js/utils");var D=n=>{let{sender:e}=n.blockData;if(!e)throw new Error("Sender is required");return e},ri=(n,e,t,a)=>{let o=!a,r=!o&&a*1e3<=new Date().getTime();if(o||r)if(n!==void 0&&e!==void 0){if(e<=0)throw new Error("Lock period must be greater than 0");if(typeof n=="number"&&n<1e10)throw new Error(`Minimum lock amount for ${r?"renewing expired veSca":"initial lock"} is 10 SCA`);if(e*86400>126144e3)throw new Error(`Maximum lock period is ~4 years (${1460} days)`)}else throw new Error(`SCA amount and lock period is required for ${r?"renewing expired veSca":"initial lock"}`);else{if(Ee(a),typeof n=="number"&&n<1e9)throw new Error("Minimum top up amount is 1 SCA");if(t&&a&&t-a>126057600)throw new Error(`Maximum lock period is ~4 years (${1459} days)`)}},ii=(n,e,t)=>{if(Ee(t),n<=0)throw new Error("Lock period must be greater than 0");if(!!t&&t*1e3<=new Date().getTime())throw new Error("veSca is expired, use renewExpiredVeScaQuick instead");if(t&&e-(t??0)>126057600)throw new Error(`Maximum lock period is ~4 years (${1459} days)`)},si=(n,e)=>{if(Ee(e),n<1e9)throw new Error("Minimum top up amount is 1 SCA");if(!!e&&e*1e3<=new Date().getTime())throw new Error("veSca is expired, use renewExpiredVeScaQuick instead")},ci=(n,e,t)=>{if(Ee(t),n<1e10)throw new Error("Minimum lock amount for renewing expired vesca 10 SCA");if(e*86400>=126057600)throw new Error(`Maximum lock period is ~4 years (${1459} days)`)},Ee=n=>{if(n===void 0)throw new Error("veSca not found")};var it=require("@mysten/sui.js/utils"),tc=q(require("bignumber.js"));var ac=n=>({pointType:(0,it.normalizeStructTag)(n.point_type.name),weightedAmount:Number(n.weighted_amount),points:Number(n.points),totalPoints:Number(n.total_points),index:Number(n.index)}),di=n=>({poolType:(0,it.normalizeStructTag)(n.pool_type.name),debtAmount:Number(n.debt_amount),pointList:n.points_list.reduce((e,t)=>{let a=ac(t),o=(0,it.parseStructTag)(a.pointType).name.toLowerCase();return e[o]=a,e},{})});var Yn=n=>{let e=n.slice(1).toLowerCase();return n.charAt(0).toLowerCase()==="s"&&[...new Set([...Se,...ka,...Yr])].includes(e)},Zn=n=>{switch(n){case"afsui":return"afSUI";case"hasui":return"haSUI";case"vsui":return"vSUI";default:return n.toUpperCase()}};var li=n=>{let e=new Date(n*1e3),t=new Date(n*1e3);t.setUTCHours(0,0,0,0),e.getUTCHours()>=0&&t.setUTCDate(t.getUTCDate()+1);let a=new Date().getTime();return t.getTime()-a>126144e3*1e3&&t.setUTCDate(t.getUTCDate()-1),Math.floor(t.getTime()/1e3)};var pe=class{params;isTestnet;_address;client;constructor(e,t){this.params=e,this._address=t?.address??new V({id:e?.addressesId||ce,network:e?.networkType}),this.isTestnet=e.networkType?e.networkType==="testnet":!1,this.client=e.client}init(e=!1,t){e||!this._address.getAddresses()||!t?.getAddresses()?this._address.read():this._address=t}parseSymbol(e){if(Yn(e)){let t=e.slice(1).toLowerCase();return e.slice(0,1).toLowerCase()+Zn(t)}return Zn(e)}parseCoinType(e){let t=Yn(e)?this.parseCoinName(e):e,a=this._address.get(`core.coins.${t}.id`)||ti[e]||void 0;if(!a)throw Error(`Coin ${e} is not supported`);if(e==="sui")return(0,st.normalizeStructTag)(`${a}::sui::SUI`);let o=[this._address.get("core.coins.usdc.id")??B.usdc,this._address.get("core.coins.usdt.id")??B.usdt,this._address.get("core.coins.eth.id")??B.eth,this._address.get("core.coins.btc.id")??B.btc,this._address.get("core.coins.sol.id")??B.sol,this._address.get("core.coins.apt.id")??B.apt],r=[this._address.get("core.coins.vsui.id")??Xn.vsui];return o.includes(a)?`${a}::coin::COIN`:r.includes(a)?`${a}::cert::CERT`:`${a}::${t}::${t.toUpperCase()}`}parseMarketCoinType(e){let t=this._address.get("core.object")||Ia,a=this.parseCoinType(e);return`${t}::reserve::MarketCoin<${a}>`}parseCoinNameFromType(e){let t=(0,st.normalizeStructTag)(e),a=/((0x[^:]+::[^:]+::[^<>]+))(?![^<>]*<)/,o=e.match(a),r=e.includes("reserve::MarketCoin");t=o?.[1]||e;let i={[`${this._address.get("core.coins.usdc.id")??B.usdc}::coin::COIN`]:"usdc",[`${this._address.get("core.coins.usdt.id")??B.usdt}::coin::COIN`]:"usdt",[`${this._address.get("core.coins.eth.id")??B.eth}::coin::COIN`]:"eth",[`${this._address.get("core.coins.btc.id")??B.btc}::coin::COIN`]:"btc",[`${this._address.get("core.coins.sol.id")??B.sol}::coin::COIN`]:"sol",[`${this._address.get("core.coins.apt.id")??B.apt}::coin::COIN`]:"apt"},s={[`${this._address.get("core.coins.vsui.id")??Xn.vsui}::cert::CERT`]:"vsui"},c=i[t]||s[t]||t.split("::")[2].toLowerCase();return r?this.parseMarketCoinName(c):c}parseCoinName(e){return e.slice(1)}parseMarketCoinName(e){return`s${e}`}getSpoolRewardCoinName=e=>xa[e];getBorrowIncentiveRewardCoinName=e=>ei[e];getCoinDecimal(e){return Zr[e]}getCoinWrappedType(e){return e==="usdc"||e==="usdt"||e==="eth"||e==="btc"||e==="apt"||e==="sol"?{from:"Wormhole",type:"Portal from Ethereum"}:void 0}async selectCoinIds(e,t=st.SUI_TYPE_ARG,a){let o=a,r=[],i=0,s=!0,c=null;for(;s&&i<e;){let l=await this.client.getCoins({owner:o,coinType:t,cursor:c});l.data.sort((d,p)=>parseInt(p.balance,10)-parseInt(d.balance,10));for(let d=0;d<l.data.length&&(r.push({objectId:l.data[d].coinObjectId,digest:l.data[d].digest,version:l.data[d].version}),i+=parseInt(l.data[d].balance,10),!(i>=e));d++);c=l.nextCursor,s=l.hasNextPage}if(!r.length)throw new Error("No valid coins found for the transaction.");return r.map(l=>l.objectId)}parseAprToApy(e,t=365){return(1+e/t)**t-1}parseApyToApr(e,t=365){return((1+e)**(1/t)-1)*t}takeAmountFromCoins(e,t,a){let o=t.map(s=>e.object(s)),r=o[0];o.length>1&&e.mergeCoins(r,o.slice(1));let[i]=e.splitCoins(r,[e.pure(a)]);return[i,r]}getUnlockAt(e,t){let a=Math.floor(new Date().getTime()/1e3),o=t?Math.max(t-a,0):0,r=0;if(o===0){let i=(e??1)*86400;r=Math.min(a+i,a+126144e3)}else{let i=Math.min(e?e*86400+o:o,126144e3);r=a+i}return li(r)}};var ui=require("@mysten/sui.js/transactions"),ct=q(require("bignumber.js"));var Me=async(n,e)=>{let t=e,a=n.address.get("core.object")||Ia,o=[],r=!1,i=null;do{let d=await n.client.getOwnedObjects({owner:t,filter:{StructType:`${a}::obligation::ObligationKey`},cursor:i});o.push(...d.data),d.hasNextPage&&d.nextCursor?(r=!0,i=d.nextCursor):r=!1}while(r);let s=o.map(d=>d?.data?.objectId).filter(d=>d!==void 0),c=await n.client.multiGetObjects({ids:s,options:{showContent:!0,showType:!0}}),l=[];for(let d=0;d<c.length;d++){let p=c[d].data.objectId,{content:m}=c[d].data;if(m&&"fields"in m){let b=m.fields,f=String(b.ownership.fields.of),y=await eo(n,f);l.push({id:f,keyId:p,locked:y})}}return l},eo=async(n,e)=>{let t=await n.client.getObject({id:e,options:{showContent:!0}}),a=!1;return t.data&&t?.data?.content?.dataType==="moveObject"&&"lock_key"in t.data.content.fields&&(a=!!t.data.content.fields.lock_key),a},pi=async(n,e,t)=>{let a=t||[...Se],o=e,r=[],i=!1,s=null;do{let d=await n.client.getOwnedObjects({owner:o,filter:{MatchAny:a.map(p=>({StructType:`0x2::coin::Coin<${n.utils.parseCoinType(p)}>`}))},options:{showType:!0,showContent:!0},cursor:s});r.push(...d.data),d.hasNextPage&&d.nextCursor?(i=!0,s=d.nextCursor):i=!1}while(i);let c={};return r.map(d=>d.data).filter(d=>d!=null).forEach(d=>{let p=d.type;if(d.content&&"fields"in d.content){let m=d.content.fields,b=n.utils.parseCoinNameFromType(p);b&&(c[b]=(0,ct.default)(c[b]??0).plus(m.balance).toNumber())}}),c},mi=async(n,e,t)=>{let a=t,o=n.utils.parseCoinType(e),r=[],i=!1,s=null;do{let d=await n.client.getOwnedObjects({owner:a,filter:{StructType:`0x2::coin::Coin<${o}>`},options:{showContent:!0},cursor:s});r.push(...d.data),d.hasNextPage&&d.nextCursor?(i=!0,s=d.nextCursor):i=!1}while(i);let c=0;return r.map(d=>d.data).filter(d=>d!=null).forEach(d=>{if(d.content&&"fields"in d.content){let p=d.content.fields;c=(0,ct.default)(c).plus(p.balance).toNumber()}}),c},bi=async(n,e,t)=>{let a=t||[...Se].map(d=>n.utils.parseMarketCoinName(d)),o=e,r=[],i=!1,s=null;do{let d=await n.client.getOwnedObjects({owner:o,filter:{MatchAny:a.map(p=>({StructType:`0x2::coin::Coin<${n.utils.parseMarketCoinType(p)}>`}))},options:{showType:!0,showContent:!0},cursor:s});r.push(...d.data),d.hasNextPage&&d.nextCursor?(i=!0,s=d.nextCursor):i=!1}while(i);let c={};return r.map(d=>d.data).filter(d=>d!=null).forEach(d=>{let p=d.type;if(d.content&&"fields"in d.content){let m=d.content.fields,b=n.utils.parseCoinNameFromType(p);b&&(c[b]=(0,ct.default)(c[b]??0).plus(m.balance).toNumber())}}),c},fi=async(n,e,t)=>{let a=t,o=n.utils.parseMarketCoinType(e),r=[],i=!1,s=null;do{let d=await n.client.getOwnedObjects({owner:a,filter:{StructType:`0x2::coin::Coin<${o}>`},options:{showContent:!0},cursor:s});r.push(...d.data),d.hasNextPage&&d.nextCursor?(i=!0,s=d.nextCursor):i=!1}while(i);let c=0;return r.map(d=>d.data).filter(d=>d!=null).forEach(d=>{if(d.content&&"fields"in d.content){let p=d.content.fields;c=(0,ct.default)(c).plus(p.balance).toNumber()}}),c},gi=async(n,e)=>{let a=`${n.address.get("core.packages.query.id")}::obligation_query::obligation_data`,o=new ui.TransactionBlock;return o.moveCall({target:a,arguments:[o.object(e)]}),(await n.client.devInspectTransactionBlock({transactionBlock:o,sender:n.walletAddress})).events[0].parsedJson};var w=require("@mysten/sui.js/utils"),dt=async(n,e)=>{let t=e,a=n.address.get("spool.object"),o=`${a}::spool_account::SpoolAccount`,r=[],i=!1,s=null;do{let m=await n.client.getOwnedObjects({owner:t,filter:{StructType:o},options:{showContent:!0,showType:!0},cursor:s});r.push(...m.data),m.hasNextPage&&m.nextCursor?(i=!0,s=m.nextCursor):i=!1}while(i);let c={seth:[],ssui:[],susdc:[],susdt:[],scetus:[],safsui:[],shasui:[],svsui:[]},l=Object.keys(c).reduce((m,b)=>{let f=n.utils.parseCoinName(b),y=n.utils.parseMarketCoinType(f),C={...m},_=`${a}::spool_account::SpoolAccount<${y}>`;return C[b]=_,C},{}),d=r.map(m=>m?.data?.objectId).filter(m=>m!==void 0);return(await n.client.multiGetObjects({ids:d,options:{showContent:!0,showType:!0}})).forEach(m=>{let b=m.data.objectId,f=m.data.type;if(m.data.content&&"fields"in m.data.content){let y=m.data.content.fields,C=String(y.spool_id),_=String(y.stake_type.fields.name),U=Number(y.stakes),X=Number(y.index),Y=Number(y.points),Z=Number(y.total_points);(0,w.normalizeStructTag)(f)===l.seth?c.seth.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:X,points:Y,totalPoints:Z}):(0,w.normalizeStructTag)(f)===l.ssui?c.ssui.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:X,points:Y,totalPoints:Z}):(0,w.normalizeStructTag)(f)===l.susdc?c.susdc.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:X,points:Y,totalPoints:Z}):(0,w.normalizeStructTag)(f)===l.susdt?c.susdt.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:X,points:Y,totalPoints:Z}):(0,w.normalizeStructTag)(f)===l.scetus?c.scetus.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:X,points:Y,totalPoints:Z}):(0,w.normalizeStructTag)(f)===l.safsui?c.safsui.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:X,points:Y,totalPoints:Z}):(0,w.normalizeStructTag)(f)===l.shasui?c.shasui.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:X,points:Y,totalPoints:Z}):(0,w.normalizeStructTag)(f)===l.svsui&&c.svsui.push({id:b,type:(0,w.normalizeStructTag)(f),stakePoolId:C,stakeType:(0,w.normalizeStructTag)(_),staked:U,index:X,points:Y,totalPoints:Z})}}),c},to=async(n,e)=>{let t=n.address.get(`spool.pools.${e}.id`),a,o=await n.client.getObject({id:t,options:{showContent:!0,showType:!0}});if(o.data){let r=o.data,i=r.objectId,s=r.type;if(r.content&&"fields"in r.content){let c=r.content.fields,l=Number(c.max_distributed_point),d=Number(c.distributed_point),p=Number(c.distributed_point_per_period),m=Number(c.point_distribution_time),b=Number(c.max_stakes),f=String(c.stake_type.fields.name),y=Number(c.stakes),C=Number(c.index),_=Number(c.created_at),U=Number(c.last_update);a={id:i,type:(0,w.normalizeStructTag)(s),maxPoint:l,distributedPoint:d,pointPerPeriod:p,period:m,maxStake:b,stakeType:(0,w.normalizeStructTag)(f),totalStaked:y,index:C,createdAt:_,lastUpdate:U}}}return a},ao=async(n,e)=>{let t=n.address.get(`spool.pools.${e}.rewardPoolId`),a,o=await n.client.getObject({id:t,options:{showContent:!0,showType:!0}});if(o.data){let r=o.data,i=r.objectId,s=r.type;if(r.content&&"fields"in r.content){let c=r.content.fields,l=String(c.spool_id),d=Number(c.exchange_rate_numerator),p=Number(c.exchange_rate_denominator),m=Number(c.rewards),b=Number(c.claimed_rewards);a={id:i,type:(0,w.normalizeStructTag)(s),stakePoolId:l,ratioNumerator:d,ratioDenominator:p,rewards:m,claimedRewards:b}}}return a};var hi=require("@mysten/sui.js/transactions"),nc=require("@mysten/sui.js/utils"),oc=q(require("bignumber.js"));var yi=async(n,e,t,a)=>{let o=a||[...Ne],r=n.address.get("borrowIncentive.query"),i=n.address.get("borrowIncentive.incentiveAccounts"),s=`${r}::incentive_account_query::incentive_account_data`,c=new hi.TransactionBlock;c.moveCall({target:s,arguments:[c.object(i),c.object(e)]});let d=(await n.client.devInspectTransactionBlock({transactionBlock:c,sender:t})).events[0].parsedJson,p={};return d.pool_records.forEach(m=>{let b=di(m),{poolType:f}=b,y=n.utils.parseCoinNameFromType(f);o.length>=1&&o.includes(y)&&(p[y]=b)},{}),p};var Si=async(n,e)=>{let t=n.address.get(`core.coins.${e}.oracle.pyth.feedObject`),a=await n.client.getObject({id:t,options:{showContent:!0}});if(a.data){let o=a.data;if(o.content&&"fields"in o.content){let r=o.content.fields,i=Number(r.price_info.fields.price_feed.fields.price.fields.expo.fields.magnitude),s=Number(r.price_info.fields.price_feed.fields.price.fields.expo.fields.negative),c=Number(r.price_info.fields.price_feed.fields.price.fields.price.fields.magnitude),l=Number(r.price_info.fields.price_feed.fields.price.fields.price.fields.negative);return c*10**((s?-1:1)*i)*(l?-1:1)}}return 0};var Pa=q(require("bignumber.js")),wi=async(n,e)=>{let t=e,o=`${n.address.get("vesca.id")}::ve_sca::VeScaKey`,r=[],i=!1,s=null;do{let l=await n.client.getOwnedObjects({owner:t,filter:{StructType:o},cursor:s});r.push(...l.data),l.hasNextPage&&l.nextCursor?(i=!0,s=l.nextCursor):i=!1}while(i);return r.map(l=>l.data).filter(l=>!!l)},Ci=async(n,e)=>{let a=(await wi(n,e)).map(r=>r.objectId),o=[];for(let r=0;r<a.length;r++){let i=await no(n,a[r]);i&&o.push(i)}return o},no=async(n,e,t)=>{let a=n.address.get("vesca.tableId"),o=e||(await wi(n,t))[0].objectId,r,s=(await n.client.getDynamicFieldObject({parentId:a,name:{type:"0x2::object::ID",value:o}})).data;if(s&&s.content&&s.content.dataType==="moveObject"&&"fields"in s.content){let c=s.content.fields.value.fields;r={id:s.objectId,keyId:o,lockedScaAmount:(0,Pa.default)(c.locked_sca_amount).toNumber(),lockedScaCoin:(0,Pa.default)(c.locked_sca_amount).shiftedBy(-9).toNumber(),unlockAt:(0,Pa.default)(c.unlock_at).toNumber()}}return r};var Le=class{params;address;client;utils;walletAddress;constructor(e,t){this.params=e,this.address=t?.address??new V({id:e?.addressesId||ce,network:e?.networkType}),this.client=e.client,this.utils=t?.utils??new pe(this.params,{address:this.address}),this.walletAddress=e.walletAddress}init(e=!1,t){e||!this.address.getAddresses()||!t?.getAddresses()?this.address.read():this.address=t}async getObligations(e){return Me(this,e)}async getCoinAmounts(e,t){return pi(this,e,t)}async getCoinAmount(e,t){return mi(this,e,t)}async getMarketCoinAmounts(e,t){return bi(this,e,t)}async getMarketCoinAmount(e,t){return fi(this,e,t)}async getPriceFromPyth(e){return Si(this,e)}async getAllStakeAccounts(e){return dt(this,e)}async getStakeAccounts(e,t){return(await this.getAllStakeAccounts(t))[e]??[]}async getStakePools(e){let t=e??[...rt],a={};for(let o=0;o<t.length;o++){let r=t[o],i=await to(this,r);i&&(a[r]=i)}return a}async getStakePool(e){return to(this,e)}async getStakeRewardPools(e){let t=e??[...rt],a={};for(let o=0;o<t.length;o++){let r=await ao(this,t[o]);r&&(a[t[o]]=r)}return a}async getStakeRewardPool(e){return ao(this,e)}async getBorrowIncentiveAccounts(e,t,a){return yi(this,e,t||this.walletAddress,a)}async getObligationCoinNames(e){let t=await gi(this,e),a=t.collaterals.map(s=>`0x${s.type.name}`),o=t.debts.map(s=>`0x${s.type.name}`);return[...new Set([...a,...o])].map(s=>this.utils.parseCoinNameFromType(s))}};var We=class{params;isTestnet;address;query;utils;client;walletAddress;constructor(e,t){this.params=e,this.address=t?.address??new V({id:e?.addressesId||ce,network:e?.networkType}),this.query=t?.query??new Le(e,{address:this.address}),this.utils=t?.utils??new pe(this.params,{address:this.address,query:this.query}),this.client=e.client,this.walletAddress=(0,Ii.normalizeSuiAddress)(e.walletAddress),this.isTestnet=e.networkType?e.networkType==="testnet":!1}async init(e=!1,t){e||!this.address.getAddresses()||!t?.getAddresses()?this.address.read():this.address=t,this.query.init(e,this.address),this.utils.init(e,this.address)}createTxBlock(e){return new Ti.TransactionBlock(e)}async selectCoin(e,t,a,o){let r=this.utils.parseCoinType(t),i=await this.utils.selectCoinIds(a,r,o),[s,c]=this.utils.takeAmountFromCoins(e,i,a);return{takeCoin:s,leftCoin:c}}async selectMarketCoin(e,t,a,o){let r=this.utils.parseMarketCoinType(t),i=await this.utils.selectCoinIds(a,r,o),[s,c]=this.utils.takeAmountFromCoins(e,i,a);return{takeCoin:s,leftCoin:c}}};var z=require("@mysten/sui.js/utils");var we=async(...n)=>{let[e,t,a]=n;if(n.length===3&&a&&typeof a=="string"){let i=await no(e.query,a);return i||void 0}let o=D(t),r=await Ci(e.query,o);if(r.length!==0)return r[0]},rc=async(n,e)=>{let t=n.address.get("borrowIncentive.object"),a=n.address.get("borrowIncentive.incentivePools"),o=n.address.get("vesca.id"),{client:r}=n,i=await r.getObject({id:a,options:{showContent:!0}});if(i.data?.content?.dataType!=="moveObject")return!1;let c=i.data.content.fields.ve_sca_bind.fields.id.id,l=`${t}::typed_id::TypedID<${o}::ve_sca::VeScaKey>`,d=await r.getDynamicFieldObject({parentId:c,name:{type:l,value:e}});return d.data?.content?.dataType!=="moveObject"?!1:d.data.content.fields.value.fields.id},oo=async(...n)=>{let[e,t,a,o]=n;if(n.length===4&&a&&o&&typeof a=="string"){let s=await eo(e.query,a);return{obligationId:a,obligationKey:o,obligationLocked:s}}let r=D(t),i=await Me(e.query,r);if(i.length===0)throw new Error(`No obligation found for sender ${r}`);return{obligationId:i[0].id,obligationKey:i[0].keyId,obligationLocked:i[0].locked}},ic=({builder:n,txBlock:e})=>{let t={borrowIncentivePkg:n.address.get("borrowIncentive.id"),query:n.address.get("borrowIncentive.query"),incentivePools:n.address.get("borrowIncentive.incentivePools"),incentiveAccounts:n.address.get("borrowIncentive.incentiveAccounts"),obligationAccessStore:n.address.get("core.obligationAccessStore"),config:n.address.get("borrowIncentive.config")},a={id:"0xc63072e7f5f4983a2efaf5bdba1480d5e7d74d57948e1c7cc436f8e22cbeb410",incentivePools:"0x64972b713ccec45ec3964809e477cea6f97350c0c50ca3aec85bb631639266ec",incentiveAccounts:"0x3c0b707068bdcea8bb859d751ad3e2149a9f83c13fcf4054ef91372a00bccdd3"},o={table:n.address.get("vesca.table"),treasury:n.address.get("vesca.treasury"),config:n.address.get("vesca.config")};return{stakeObligation:(r,i)=>{e.moveCall({target:`${t.borrowIncentivePkg}::user::stake`,arguments:[e.object(t.config),e.object(t.incentivePools),e.object(t.incentiveAccounts),e.object(i),e.object(r),e.object(t.obligationAccessStore),e.object(z.SUI_CLOCK_OBJECT_ID)]})},stakeObligationWithVesca:(r,i,s)=>{e.moveCall({target:`${t.borrowIncentivePkg}::user::stake_with_ve_sca`,arguments:[e.object(t.config),e.object(t.incentivePools),e.object(t.incentiveAccounts),e.object(i),e.object(r),e.object(t.obligationAccessStore),e.object(o.config),e.object(o.treasury),e.object(o.table),e.object(s),e.object(z.SUI_CLOCK_OBJECT_ID)]})},unstakeObligation:(r,i)=>{e.moveCall({target:`${t.borrowIncentivePkg}::user::unstake`,arguments:[e.object(t.config),e.object(t.incentivePools),e.object(t.incentiveAccounts),e.object(i),e.object(r),e.object(z.SUI_CLOCK_OBJECT_ID)]})},oldUnstakeObligation:(r,i)=>{e.moveCall({target:`${t.borrowIncentivePkg}::user::unstake`,arguments:[e.object(a.incentivePools),e.object(a.incentiveAccounts),e.object(i),e.object(r),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[z.SUI_TYPE_ARG]})},claimBorrowIncentive:(r,i,s)=>{let c=n.utils.parseCoinType(s);return e.moveCall({target:`${t.borrowIncentivePkg}::user::redeem_rewards`,arguments:[e.object(t.config),e.object(t.incentivePools),e.object(t.incentiveAccounts),e.object(i),e.object(r),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[c]})},oldClaimBorrowIncentive(r,i,s){let c=n.utils.parseCoinType(s);return e.moveCall({target:`${a.id}::user::redeem_rewards`,arguments:[e.object(a.incentivePools),e.object(a.incentiveAccounts),e.object(i),e.object(r),e.object(z.SUI_CLOCK_OBJECT_ID)],typeArguments:[c]})}}},M=({builder:n,txBlock:e})=>{let t=ic({builder:n,txBlock:e});return{normalMethod:t,stakeObligationQuick:async(a,o)=>{let{obligationId:r,obligationKey:i,obligationLocked:s}=await oo(n,e,a,o),c=!!e.blockData.transactions.find(l=>l.kind==="MoveCall"&&l.target===`${n.address.get("borrowIncentive.id")}::user::unstake`);(!s||c)&&t.stakeObligation(r,i)},unstakeObligationQuick:async(a,o)=>{let{obligationId:r,obligationKey:i,obligationLocked:s}=await oo(n,e,a,o);s&&t.unstakeObligation(r,i)},stakeObligationWithVeScaQuick:async(a,o,r)=>{let{obligationId:i,obligationKey:s,obligationLocked:c}=await oo(n,e,a,o),l=!!e.blockData.transactions.find(d=>d.kind==="MoveCall"&&(d.target===`${Re}::user::unstake`||d.target===`${n.address.get("borrowIncentive.id")}::user::unstake`));if(!c||l){let d=await we(n,e,r);if(d){let p=await rc(n,d.keyId);!p||p===i?t.stakeObligationWithVesca(i,s,d.keyId):t.stakeObligation(i,s)}else t.stakeObligation(i,s)}},claimBorrowIncentiveQuick:(a,o,r)=>t.claimBorrowIncentive(o,r,a)}};var J=require("@mysten/sui.js/utils");var ut=require("@mysten/sui.js/utils"),xi=q(require("axios"));var ki={testnet:["https://hermes-beta.pyth.network"],mainnet:["https://hermes.pyth.network","https://scallop.rpc.p2p.world"]};var Da=require("@mysten/sui.js/bcs"),lt=require("@mysten/sui.js/utils"),ro=16*1024,_a=class{provider;pythStateId;wormholeStateId;pythPackageId;wormholePackageId;priceTableInfo;priceFeedObjectIdCache=new Map;baseUpdateFee;constructor(e,t,a){this.provider=e,this.pythStateId=t,this.wormholeStateId=a,this.pythPackageId=void 0,this.wormholePackageId=void 0}async getBaseUpdateFee(){if(this.baseUpdateFee===void 0){let e=await this.provider.getObject({id:this.pythStateId,options:{showContent:!0}});if(!e.data||!e.data.content||e.data.content.dataType!=="moveObject")throw new Error("Unable to fetch pyth state object");this.baseUpdateFee=e.data.content.fields.base_update_fee}return this.baseUpdateFee}async getPackageId(e){let t=await this.provider.getObject({id:e,options:{showContent:!0}}).then(a=>{if(a.data?.content?.dataType==="moveObject")return a.data.content.fields;throw console.log(a.data?.content),new Error(`Cannot fetch package id for object ${e}`)});if("upgrade_cap"in t)return t.upgrade_cap.fields.package;throw new Error("upgrade_cap not found")}async verifyVaas(e,t){let a=await this.getWormholePackageId(),o=[];return e.forEach(r=>{let[i]=t.moveCall({target:`${a}::vaa::parse_and_verify`,arguments:[t.object(this.wormholeStateId),t.pure(Da.bcs.ser("vector<u8>",Array.from(r),{maxSize:ro}).toBytes()),t.object(lt.SUI_CLOCK_OBJECT_ID)]});o.push(i)}),o}async updatePriceFeeds(e,t,a){let o=await this.getPythPackageId(),r;if(t.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");let i=this.extractVaaBytesFromAccumulatorMessage(t[0]),s=await this.verifyVaas([i],e);[r]=e.moveCall({target:`${o}::pyth::create_authenticated_price_infos_using_accumulator`,arguments:[e.object(this.pythStateId),e.pure(Da.bcs.ser("vector<u8>",Array.from(t[0]),{maxSize:ro}).toBytes()),s[0],e.object(lt.SUI_CLOCK_OBJECT_ID)]});let c=[],l=await this.getBaseUpdateFee(),d=e.splitCoins(e.gas,a.map(()=>e.pure(l))),p=0;for(let m=0;m<a.length;m++){let b=await this.getPriceFeedObjectId(a[m]);if(!b)throw new Error(`Price feed ${a[0]} not found, please create it first`);c.push(b),[r]=e.moveCall({target:`${o}::pyth::update_single_price_feed`,arguments:[e.object(this.pythStateId),r,e.object(b),d[p],e.object(lt.SUI_CLOCK_OBJECT_ID)]}),p++}return e.moveCall({target:`${o}::hot_potato_vector::destroy`,arguments:[r],typeArguments:[`${o}::price_info::PriceInfo`]}),c}async createPriceFeed(e,t){let a=await this.getPythPackageId();if(t.length>1)throw new Error("SDK does not support sending multiple accumulator messages in a single transaction");let o=this.extractVaaBytesFromAccumulatorMessage(t[0]),r=await this.verifyVaas([o],e);e.moveCall({target:`${a}::pyth::create_price_feeds_using_accumulator`,arguments:[e.object(this.pythStateId),e.pure(Da.bcs.ser("vector<u8>",Array.from(t[0]),{maxSize:ro}).toBytes()),r[0],e.object(lt.SUI_CLOCK_OBJECT_ID)]})}async getWormholePackageId(){return this.wormholePackageId||(this.wormholePackageId=await this.getPackageId(this.wormholeStateId)),this.wormholePackageId}async getPythPackageId(){return this.pythPackageId||(this.pythPackageId=await this.getPackageId(this.pythStateId)),this.pythPackageId}async getPriceFeedObjectId(e){let t=e.replace("0x","");if(!this.priceFeedObjectIdCache.has(t)){let{id:a,fieldType:o}=await this.getPriceTableInfo(),r=await this.provider.getDynamicFieldObject({parentId:a,name:{type:`${o}::price_identifier::PriceIdentifier`,value:{bytes:Array.from(Buffer.from(t,"hex"))}}});if(!r.data||!r.data.content)return;if(r.data.content.dataType!=="moveObject")throw new Error("Price feed type mismatch");this.priceFeedObjectIdCache.set(t,r.data.content.fields.value)}return this.priceFeedObjectIdCache.get(t)}async getPriceTableInfo(){if(this.priceTableInfo===void 0){let e=await this.provider.getDynamicFieldObject({parentId:this.pythStateId,name:{type:"vector<u8>",value:"price_info"}});if(!e.data||!e.data.type)throw new Error("Price Table not found, contract may not be initialized");let t=e.data.type.replace("0x2::table::Table<","");t=t.replace("::price_identifier::PriceIdentifier, 0x2::object::ID>",""),this.priceTableInfo={id:e.data.objectId,fieldType:t}}return this.priceTableInfo}extractVaaBytesFromAccumulatorMessage(e){let a=7+e.readUint8(6)+1,o=e.readUint16BE(a),r=a+2;return e.subarray(r,r+o)}};var sc=async(n,e)=>(await xi.default.get(`${n}/api/latest_vaas`,{params:{ids:e}})).data.map(o=>Buffer.from(o,"base64")),Ba=async(n,e,t)=>{let a=t??[...new Set([...Se,...ka])],o=n.isTestnet?["pyth"]:["pyth"];if(o.includes("pyth")){let i=new _a(n.client,n.address.get("core.oracles.pyth.state"),n.address.get("core.oracles.pyth.wormholeState")),s=a.map(l=>n.address.get(`core.coins.${l}.oracle.pyth.feed`)),c=n.params.pythEndpoints??ki[n.isTestnet?"testnet":"mainnet"];try{let l=await sc(c[0],s);await i.updatePriceFeeds(e,l,s)}catch(l){console.warn(`Failed to update price feeds with endpoint ${c[0]}: ${l}`)}}let r=[...new Set(a)];for(let i=0;i<r.length;i++)await cc(n,e,r[i],o)},cc=async(n,e,t,a)=>{let o=n.utils.parseCoinType(t);dc(e,a,n.address.get("core.packages.xOracle.id"),n.address.get("core.oracles.xOracle"),n.address.get("core.packages.pyth.id"),n.address.get("core.oracles.pyth.registry"),n.address.get("core.oracles.pyth.state"),n.address.get(`core.coins.${t}.oracle.pyth.feedObject`),n.address.get("core.packages.switchboard.id"),n.address.get("core.oracles.switchboard.registry"),n.address.get(`core.coins.${t}.oracle.switchboard`),n.address.get("core.packages.supra.id"),n.address.get("core.oracles.supra.registry"),n.address.get("core.oracles.supra.holder"),o)},dc=(n,e,t,a,o,r,i,s,c,l,d,p,m,b,f)=>{let y=lc(n,t,a,f);return e.includes("pyth")&&bc(n,o,y,i,s,r,f),e.includes("switchboard")&&mc(n,c,y,d,l,f),e.includes("supra")&&pc(n,p,y,b,m,f),uc(n,t,a,y,f),n},lc=(n,e,t,a)=>{let o=typeof t=="string"?n.object(t):t,r=`${e}::x_oracle::price_update_request`,i=[a];return n.moveCall({target:r,arguments:[o],typeArguments:i})},uc=(n,e,t,a,o)=>{let r=`${e}::x_oracle::confirm_price_update_request`,i=[o],s=typeof t=="string"?n.object(t):t;return n.moveCall({target:r,arguments:[s,a,n.object(ut.SUI_CLOCK_OBJECT_ID)],typeArguments:i}),n},pc=(n,e,t,a,o,r)=>{let i=typeof a=="string"?n.object(a):a,s=typeof o=="string"?n.object(o):o;n.moveCall({target:`${e}::rule::set_price`,arguments:[t,i,s,n.object(ut.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},mc=(n,e,t,a,o,r)=>{let i=typeof a=="string"?n.object(a):a,s=typeof o=="string"?n.object(o):o;n.moveCall({target:`${e}::rule::set_price`,arguments:[t,i,s,n.object(ut.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},bc=(n,e,t,a,o,r,i)=>{let s=typeof t=="string"?n.object(t):t,c=typeof a=="string"?n.object(a):a,l=typeof o=="string"?n.object(o):o,d=typeof r=="string"?n.object(r):r;n.moveCall({target:`${e}::rule::set_price`,arguments:[s,c,l,d,n.object(ut.SUI_CLOCK_OBJECT_ID)],typeArguments:[i]})};var ja=async(...n)=>{let[e,t,a,o]=n;if(n.length===3&&a)return{obligationId:a};if(n.length===4&&a&&o)return{obligationId:a,obligationKey:o};let r=D(e),i=await Me(t.query,r);if(i.length===0)throw new Error(`No obligation found for sender ${r}`);return{obligationId:i[0].id,obligationKey:i[0].keyId}},fc=({builder:n,txBlock:e})=>{let t={protocolPkg:n.address.get("core.packages.protocol.id"),market:n.address.get("core.market"),version:n.address.get("core.version"),coinDecimalsRegistry:n.address.get("core.coinDecimalsRegistry"),xOracle:n.address.get("core.oracles.xOracle")};return{openObligation:()=>e.moveCall({target:`${t.protocolPkg}::open_obligation::open_obligation`,arguments:[e.pure(t.version)]}),returnObligation:(a,o)=>e.moveCall({target:`${t.protocolPkg}::open_obligation::return_obligation`,arguments:[e.object(t.version),e.object(a),e.object(o)]}),openObligationEntry:()=>e.moveCall({target:`${t.protocolPkg}::open_obligation::open_obligation_entry`,arguments:[e.object(t.version)]}),addCollateral:(a,o,r)=>{let i=n.utils.parseCoinType(r);return e.moveCall({target:`${t.protocolPkg}::deposit_collateral::deposit_collateral`,arguments:[e.object(t.version),e.object(a),e.object(t.market),typeof o!="string"?o:e.pure(o)],typeArguments:[i]})},takeCollateral:(a,o,r,i)=>{let s=n.utils.parseCoinType(i);return e.moveCall({target:`${t.protocolPkg}::withdraw_collateral::withdraw_collateral`,arguments:[e.object(t.version),e.object(a),e.object(o),e.object(t.market),e.object(t.coinDecimalsRegistry),e.pure(r),e.object(t.xOracle),e.object(J.SUI_CLOCK_OBJECT_ID)],typeArguments:[s]})},deposit:(a,o)=>{let r=n.utils.parseCoinType(o);return e.moveCall({target:`${t.protocolPkg}::mint::mint`,arguments:[e.object(t.version),e.object(t.market),typeof a!="string"?a:e.pure(a),e.object(J.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},depositEntry:(a,o)=>{let r=n.utils.parseCoinType(o);return e.moveCall({target:`${t.protocolPkg}::mint::mint_entry`,arguments:[e.object(t.version),e.object(t.market),typeof a!="string"?a:e.pure(a),e.object(J.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},withdraw:(a,o)=>{let r=n.utils.parseCoinType(o);return e.moveCall({target:`${t.protocolPkg}::redeem::redeem`,arguments:[e.object(t.version),e.object(t.market),typeof a!="string"?a:e.pure(a),e.object(J.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},withdrawEntry:(a,o)=>{let r=n.utils.parseCoinType(o);return e.moveCall({target:`${t.protocolPkg}::redeem::redeem_entry`,arguments:[e.object(t.version),e.object(t.market),typeof a!="string"?a:e.pure(a),e.object(J.SUI_CLOCK_OBJECT_ID)],typeArguments:[r]})},borrow:(a,o,r,i)=>{let s=n.utils.parseCoinType(i);return e.moveCall({target:`${t.protocolPkg}::borrow::borrow`,arguments:[e.object(t.version),e.object(a),e.object(o),e.object(t.market),e.object(t.coinDecimalsRegistry),e.pure(r),e.object(t.xOracle),e.object(J.SUI_CLOCK_OBJECT_ID)],typeArguments:[s]})},borrowEntry:(a,o,r,i)=>{let s=n.utils.parseCoinType(i);return e.moveCall({target:`${t.protocolPkg}::borrow::borrow_entry`,arguments:[e.object(t.version),e.object(a),e.object(o),e.object(t.market),e.object(t.coinDecimalsRegistry),e.pure(r),e.object(t.xOracle),e.object(J.SUI_CLOCK_OBJECT_ID)],typeArguments:[s]})},repay:(a,o,r)=>{let i=n.utils.parseCoinType(r);return e.moveCall({target:`${t.protocolPkg}::repay::repay`,arguments:[e.object(t.version),e.object(a),e.object(t.market),typeof o!="string"?o:e.pure(o),e.object(J.SUI_CLOCK_OBJECT_ID)],typeArguments:[i]})},borrowFlashLoan:(a,o)=>{let r=n.utils.parseCoinType(o);return e.moveCall({target:`${t.protocolPkg}::flash_loan::borrow_flash_loan`,arguments:[e.object(t.version),e.object(t.market),e.pure(a)],typeArguments:[r]})},repayFlashLoan:(a,o,r)=>{let i=n.utils.parseCoinType(r);return e.moveCall({target:`${t.protocolPkg}::flash_loan::repay_flash_loan`,arguments:[e.object(t.version),e.object(t.market),e.pure(a),e.object(o)],typeArguments:[i]})}}},L=({builder:n,txBlock:e})=>{let t=fc({builder:n,txBlock:e});return{normalMethod:t,addCollateralQuick:async(a,o,r)=>{let i=D(e),{obligationId:s}=await ja(e,n,r);if(o==="sui"){let[c]=e.splitCoins(e.gas,[a]);t.addCollateral(s,c,o)}else{let{leftCoin:c,takeCoin:l}=await n.selectCoin(e,o,a,i);t.addCollateral(s,l,o),e.transferObjects([c],i)}},takeCollateralQuick:async(a,o,r,i)=>{let s=await ja(e,n,r,i),c=await n.query.getObligationCoinNames(s.obligationId);return await Ba(n,e,c),t.takeCollateral(s.obligationId,s.obligationKey,a,o)},depositQuick:async(a,o,r)=>{if(o==="sui"){let[c]=e.splitCoins(e.gas,[a]);return t.deposit(c,o)}let{leftCoin:i,takeCoin:s}=await n.selectCoin(e,o,a,r);return e.transferObjects([i],r),t.deposit(s,o)},withdrawQuick:async(a,o)=>{let r=D(e),i=n.utils.parseMarketCoinName(o),{leftCoin:s,takeCoin:c}=await n.selectMarketCoin(e,i,a,r);return e.transferObjects([s],r),t.withdraw(c,o)},borrowQuick:async(a,o,r,i)=>{let s=await ja(e,n,r,i),l=[...await n.query.getObligationCoinNames(s.obligationId),o];return await Ba(n,e,l),t.borrow(s.obligationId,s.obligationKey,a,o)},repayQuick:async(a,o,r,i)=>{let s=await ja(e,n,r);if(o==="sui"){let[d]=e.splitCoins(e.gas,[a]);return t.repay(s.obligationId,d,o)}let{leftCoin:c,takeCoin:l}=await n.selectCoin(e,o,a,i);return e.transferObjects([c],i),t.repay(s.obligationId,l,o)},updateAssetPricesQuick:async a=>Ba(n,e,a)}};var pt=require("@mysten/sui.js/utils");var vi=async(...n)=>{let[e,t,a,o]=n;if(n.length===4&&o)return[o];let r=D(t),i=await dt(e.query,r);if(i[a].length===0)throw new Error(`No stake account id found for sender ${r}`);return i[a].map(s=>s.id)},gc=async(...n)=>{let[e,t,a,o]=n,r=D(t),i=await dt(e.query,r);if(i[a].length===0)throw new Error(`No stake account found for sender ${r}`);return o?i[a].filter(c=>c.id===o):i[a]},hc=({builder:n,txBlock:e})=>{let t={spoolPkg:n.address.get("spool.id")};return{createStakeAccount:a=>{let o=n.utils.parseMarketCoinType(a),r=n.address.get(`spool.pools.${a}.id`);return e.moveCall({target:`${t.spoolPkg}::user::new_spool_account`,arguments:[e.object(r),e.object(pt.SUI_CLOCK_OBJECT_ID)],typeArguments:[o]})},stake:(a,o,r)=>{let i=n.utils.parseMarketCoinType(r),s=n.address.get(`spool.pools.${r}.id`);e.moveCall({target:`${t.spoolPkg}::user::stake`,arguments:[e.object(s),e.object(a),typeof o=="string"?e.pure(o):o,e.object(pt.SUI_CLOCK_OBJECT_ID)],typeArguments:[i]})},unstake:(a,o,r)=>{let i=n.utils.parseMarketCoinType(r),s=n.address.get(`spool.pools.${r}.id`);return e.moveCall({target:`${t.spoolPkg}::user::unstake`,arguments:[e.object(s),e.object(a),e.pure(o),e.object(pt.SUI_CLOCK_OBJECT_ID)],typeArguments:[i]})},claim:(a,o)=>{let r=n.address.get(`spool.pools.${o}.id`),i=n.address.get(`spool.pools.${o}.rewardPoolId`),s=n.utils.parseMarketCoinType(o),c=xa[o],l=n.utils.parseCoinType(c);return e.moveCall({target:`${t.spoolPkg}::user::redeem_rewards`,arguments:[e.object(r),e.object(i),e.object(a),e.object(pt.SUI_CLOCK_OBJECT_ID)],typeArguments:[s,l]})}}},Ce=({builder:n,txBlock:e})=>{let t=hc({builder:n,txBlock:e});return{normalMethod:t,stakeQuick:async(a,o,r)=>{let i=D(e),s=await vi(n,e,o,r),c=n.utils.parseMarketCoinType(o);if(typeof a=="number"){let l=await n.utils.selectCoinIds(a,c,i),[d,p]=n.utils.takeAmountFromCoins(e,l,a);t.stake(s[0],d,o),e.transferObjects([p],i)}else t.stake(s[0],a,o)},unstakeQuick:async(a,o,r)=>{let i=a,s=await gc(n,e,o,r),c=[];for(let l=0;l<s.length;l++){if(s[l].staked===0)continue;let d=Math.min(i,s[l].staked),p=t.unstake(s[l].id,d,o);if(c.push(p),i-=d,i===0)break}return c},claimQuick:async(a,o)=>{let r=await vi(n,e,a,o),i=[];return r.forEach(s=>{let c=t.claim(s,a);i.push(c)}),i}}};var Fe=require("@mysten/sui.js/utils");var yc=({builder:n,txBlock:e})=>{let t={pkgId:n.address.get("vesca.id"),table:n.address.get("vesca.table"),treasury:n.address.get("vesca.treasury"),config:n.address.get("vesca.config")};return{lockSca:(a,o)=>e.moveCall({target:`${t.pkgId}::ve_sca::mint_ve_sca_key`,arguments:[e.object(t.config),e.object(t.table),e.object(t.treasury),typeof a=="string"?e.pure(a):a,e.pure(o),e.object(Fe.SUI_CLOCK_OBJECT_ID)]}),extendLockPeriod:(a,o)=>{e.moveCall({target:`${t.pkgId}::ve_sca::extend_lock_period`,arguments:[e.object(t.config),e.object(a),e.object(t.table),e.object(t.treasury),e.pure(o),e.object(Fe.SUI_CLOCK_OBJECT_ID)]})},extendLockAmount:(a,o)=>{e.moveCall({target:`${t.pkgId}::ve_sca::lock_more_sca`,arguments:[e.object(t.config),e.object(a),e.object(t.table),e.object(t.treasury),typeof o=="string"?e.pure(o):o,e.object(Fe.SUI_CLOCK_OBJECT_ID)]})},renewExpiredVeSca:(a,o,r)=>{e.moveCall({target:`${t.pkgId}::ve_sca::renew_expired_ve_sca`,arguments:[e.object(t.config),e.object(a),e.object(t.table),e.object(t.treasury),typeof o=="string"?e.pure(o):o,e.pure(r),e.object(Fe.SUI_CLOCK_OBJECT_ID)]})},redeemSca:a=>e.moveCall({target:`${t.pkgId}::ve_sca::redeem`,arguments:[e.object(t.config),e.object(a),e.object(t.table),e.object(t.treasury),e.object(Fe.SUI_CLOCK_OBJECT_ID)]})}},Te=({builder:n,txBlock:e})=>{let t=yc({builder:n,txBlock:e});return{normalMethod:t,lockScaQuick:async(a,o,r=!0)=>{let i=D(e),s=await we(n,e),c,l=[];if(a!==void 0&&typeof a=="number"){let b=await n.utils.selectCoinIds(a,de,i),[f,y]=n.utils.takeAmountFromCoins(e,b,a);c=f,l.push(y)}else c=a;let d=n.utils.getUnlockAt(o,s?.unlockAt);r&&ri(a,o,d,s?.unlockAt),console.log(new Date(d*1e3).toLocaleString("en-CA",{hour12:!0}));let p=!s?.unlockAt,m=!p&&s.unlockAt*1e3<=new Date().getTime();if(p||m){if(c)if(p){let b=t.lockSca(c,d);l.push(b)}else{if(s.lockedScaAmount!==0){let b=t.redeemSca(s.keyId);l.push(b)}t.renewExpiredVeSca(s.keyId,c,d)}}else c&&o?(t.extendLockPeriod(s.keyId,d),t.extendLockAmount(s.keyId,c)):o?t.extendLockPeriod(s.keyId,d):c&&t.extendLockAmount(s.keyId,c);l.length>0&&e.transferObjects(l,i)},extendLockPeriodQuick:async(a,o,r=!0)=>{let i=await we(n,e,o),s=n.utils.getUnlockAt(a);r&&ii(a,s,i?.unlockAt),i&&t.extendLockPeriod(i.keyId,s)},extendLockAmountQuick:async(a,o,r=!0)=>{let i=D(e),s=await we(n,e,o);if(r&&si(a,s?.unlockAt),s){let c=await n.utils.selectCoinIds(a,de,i),[l,d]=n.utils.takeAmountFromCoins(e,c,a);t.extendLockAmount(s.keyId,l),e.transferObjects([d],i)}},renewExpiredVeScaQuick:async(a,o,r,i=!0)=>{let s=D(e),c=await we(n,e,r),l=n.utils.getUnlockAt(o,c?.unlockAt);if(i&&ci(a,o,c?.unlockAt),c){let d=[];if(c.lockedScaAmount!==0){let f=t.redeemSca(c.keyId);d.push(f)}let p=await n.utils.selectCoinIds(a,de,s),[m,b]=n.utils.takeAmountFromCoins(e,p,a);d.push(b),t.renewExpiredVeSca(c.keyId,m,l),e.transferObjects(d,s)}},redeemScaQuick:async a=>{let o=D(e),r=await we(n,e,a);if(Ee(r?.unlockAt),r){let i=t.redeemSca(r.keyId);e.transferObjects([i],o)}}}};var h=class{params;client;address;builder;query;utils;walletAddress;constructor(e,t){this.params=e,this.client=e.client,this.address=t?.address??new V({id:e?.addressesId||ce,network:e?.networkType}),this.query=t?.query??new Le(e,{address:this.address}),this.utils=t?.utils??new pe(e,{address:this.address,query:this.query}),this.builder=t?.builder??new We(e,{address:this.address,query:this.query,utils:this.utils}),this.walletAddress=(0,Ai.normalizeSuiAddress)(e.walletAddress)}init(e=!1){(e||!this.address.getAddresses())&&this.address.read(),this.builder.init(e,this.address),this.query.init(e,this.address),this.utils.init(e,this.address)}async getObligations(e){let t=e||this.walletAddress;return this.query.getObligations(t)}async getAllStakeAccounts(e){let t=e||this.walletAddress;return this.query.getAllStakeAccounts(t)}async getStakeAccounts(e,t){let a=t||this.walletAddress;return this.query.getStakeAccounts(e,a)}async getStakePool(e){return this.query.getStakePool(e)}async getStakeRewardPool(e){return this.query.getStakeRewardPool(e)}async openObligation(e){let t=new I.TransactionBlock,a=L({builder:this.builder,txBlock:t}),o=e||this.walletAddress;return t.setSender(o),a.normalMethod.openObligationEntry(),t}async depositCollateral(e,t,a,o){let r=new I.TransactionBlock,i=o||this.walletAddress;r.setSender(i);let s=L({builder:this.builder,txBlock:r}),c=await this.query.getObligations(i),l=a||c?.[0]?.id;if(l)await s.addCollateralQuick(t,e,l);else{let[d,p,m]=s.normalMethod.openObligation();await s.addCollateralQuick(t,e,d),s.normalMethod.returnObligation(d,m),r.transferObjects([p],i)}return r}async withdrawCollateral(e,t,a,o,r){let i=new I.TransactionBlock,s=L({builder:this.builder,txBlock:i}),c=r||this.walletAddress;i.setSender(c);let l=await s.takeCollateralQuick(t,e,a,o);return i.transferObjects([l],c),i}async deposit(e,t,a){let o=new I.TransactionBlock,r=L({builder:this.builder,txBlock:o}),i=a||this.walletAddress;o.setSender(i);let s=await r.depositQuick(t,e,a);return o.transferObjects([s],i),o}async withdraw(e,t,a){let o=new I.TransactionBlock,r=a||this.walletAddress,i=L({builder:this.builder,txBlock:o});o.setSender(r);let s=await i.withdrawQuick(t,e);return o.transferObjects([s],r),o}async borrow(e,t,a,o,r){let i=new I.TransactionBlock,s=L({builder:this.builder,txBlock:i}),c=M({builder:this.builder,txBlock:i}),l=r||this.walletAddress;i.setSender(l);let d=Ne.includes(e);d&&await c.unstakeObligationQuick(a,o);let p=await s.borrowQuick(t,e,a,o);return i.transferObjects([p],l),d&&await c.stakeObligationQuick(a,o),i}async borrowWithBoost(e,t,a,o,r,i){let s=new I.TransactionBlock,c=L({builder:this.builder,txBlock:s}),l=M({builder:this.builder,txBlock:s}),d=i||this.walletAddress;s.setSender(d);let p=Ne.includes(e);p&&await l.unstakeObligationQuick(a,o);let m=await c.borrowQuick(t,e,a,o);return s.transferObjects([m],d),p&&await l.stakeObligationWithVeScaQuick(a,o,r),s}async repay(e,t,a,o,r){let i=new I.TransactionBlock,s=L({builder:this.builder,txBlock:i}),c=M({builder:this.builder,txBlock:i}),l=r||this.walletAddress;i.setSender(l);let d=Ne.includes(e);return d&&await c.unstakeObligationQuick(a,o),await s.repayQuick(t,e,a,l),d&&await c.stakeObligationQuick(a,o),i}async createStakeAccount(e,t){let a=new I.TransactionBlock,o=Ce({builder:this.builder,txBlock:a}),r=t||this.walletAddress;a.setSender(r);let i=o.normalMethod.createStakeAccount(e);return a.transferObjects([i],r),a}async supplyAndStake(e,t,a,o){let r=new I.TransactionBlock,i=L({builder:this.builder,txBlock:r}),s=Ce({builder:this.builder,txBlock:r}),c=o||this.walletAddress;r.setSender(c);let l=await i.depositQuick(t,e,o),d=this.utils.parseMarketCoinName(e);if(!rt.find(b=>b===d))return r;let p=await this.query.getStakeAccounts(d,c),m=a||(p.length>0?p[0].id:void 0);if(m)await s.stakeQuick(l,d,m);else{let b=s.normalMethod.createStakeAccount(d);await s.stakeQuick(l,d,b),r.transferObjects([b],c)}return r}async unstakeAndWithdraw(e,t,a){let o=new I.TransactionBlock,r=L({builder:this.builder,txBlock:o}),i=Ce({builder:this.builder,txBlock:o}),s=this.walletAddress,c=[];o.setSender(s);let l=this.utils.parseMarketCoinName(e);for(let d=0;d<a.length;d++){let p=a[d],[m]=await i.unstakeQuick(p.coin,l,p.id);if(m){let b=r.normalMethod.withdraw(m,e);c.push(b)}}if(t>0){let d=await r.withdrawQuick(t,e);c.push(d)}return o.transferObjects(c,s),o}async stake(e,t,a,o){let r=new I.TransactionBlock,i=Ce({builder:this.builder,txBlock:r}),s=o||this.walletAddress;r.setSender(s);let c=await this.query.getStakeAccounts(e,s),l=a||(c.length>0?c[0].id:void 0);if(l)await i.stakeQuick(t,e,l);else{let d=i.normalMethod.createStakeAccount(e);await i.stakeQuick(t,e,d),r.transferObjects([d],s)}return r}async unstake(e,t,a,o){let r=new I.TransactionBlock,i=Ce({builder:this.builder,txBlock:r}),s=o||this.walletAddress;r.setSender(s);let c=await i.unstakeQuick(t,e,a);return r.transferObjects(c,s),r}async claim(e,t,a,o){let r=new I.TransactionBlock,i=Ce({builder:this.builder,txBlock:r}),s=M({builder:this.builder,txBlock:r}),c=o||this.walletAddress;r.setSender(c);let l={sui:[],sca:[]};for(let d=0;d<e.length;d++){let{stakeMarketCoinName:p,stakeAccountId:m}=e[d],b=i.normalMethod.claim(m,p);l.sui.push(b)}for(let d=0;d<t.length;d++){let{obligationId:p,obligationKey:m,rewardCoinName:b}=t[d],f=s.normalMethod.claimBorrowIncentive(p,m,b);l[b].push(f)}for(let d=0;d<a.length;d++){let{obligationId:p,obligationKey:m,rewardCoinName:b}=a[d],f=s.normalMethod.oldClaimBorrowIncentive(p,m,b);l[b].push(f)}return l.sui.length>0&&(l.sui.length>1&&r.mergeCoins(l.sui[0],l.sui.slice(1)),r.transferObjects([l.sui[0]],r.pure(c))),l.sca.length>0&&(l.sca.length>1&&r.mergeCoins(l.sca[0],l.sca.slice(1)),r.transferObjects([l.sca[0]],r.pure(c))),r}async stakeObligation(e,t,a){let o=this.builder.createTxBlock(),r=M({builder:this.builder,txBlock:o}),i=a||this.walletAddress;return o.setSender(i),await r.stakeObligationQuick(e,t),o}async unstakeObligation(e,t,a){let o=this.builder.createTxBlock(),r=M({builder:this.builder,txBlock:o}),i=a||this.walletAddress;return o.setSender(i),await r.unstakeObligationQuick(e,t),o}async stakeSca(e,t=!1,a=!1,o,r,i,s,c){let l=new I.TransactionBlock,d=Te({builder:this.builder,txBlock:l}),p=M({builder:this.builder,txBlock:l}),m=c||this.walletAddress;l.setSender(m);let b=await this.builder.utils.selectCoinIds(e,de,m),[f,y]=this.builder.utils.takeAmountFromCoins(l,b,e),C;return s?d.normalMethod.extendLockAmount(s,f):C=d.normalMethod.lockSca(f,i),o&&r&&(t&&(a?p.normalMethod.oldUnstakeObligation(o,r):p.normalMethod.unstakeObligation(o,r)),p.normalMethod.stakeObligationWithVesca(o,r,s||C)),s||l.transferObjects([C,y],m),l}async stakeMoreSca(e,t,a){let o=new I.TransactionBlock,r=a||this.walletAddress;return o.setSender(r),o}async extendStakeScaLockPeriod(e,t,a,o,r=!1,i=!1,s){let c=new I.TransactionBlock,l=Te({builder:this.builder,txBlock:c}),d=M({builder:this.builder,txBlock:c}),p=s||this.walletAddress;return c.setSender(p),l.normalMethod.extendLockPeriod(t,e),a&&o&&(r&&(i?d.normalMethod.oldUnstakeObligation(a,o):d.normalMethod.unstakeObligation(a,o)),d.normalMethod.stakeObligationWithVesca(a,o,t)),c}async extendPeriodAndStakeMoreSca(e,t,a,o,r,i=!1,s=!1,c){let l=new I.TransactionBlock,d=Te({builder:this.builder,txBlock:l}),p=M({builder:this.builder,txBlock:l}),m=c||this.walletAddress;l.setSender(m);let b=await this.builder.utils.selectCoinIds(e,de,m),[f,y]=this.builder.utils.takeAmountFromCoins(l,b,e);return d.normalMethod.extendLockPeriod(t,a),d.normalMethod.extendLockAmount(t,f),l.transferObjects([y],m),!o||!r||(i&&(s?p.normalMethod.oldUnstakeObligation(o,r):p.normalMethod.unstakeObligation(o,r)),p.normalMethod.stakeObligationWithVesca(o,r,t)),l}async renewExpiredStakeSca(e,t,a,o=!1,r,i,s=!1,c=!1,l){let d=new I.TransactionBlock,p=Te({builder:this.builder,txBlock:d}),m=M({builder:this.builder,txBlock:d}),b=l||this.walletAddress;if(d.setSender(b),o){let _=p.normalMethod.redeemSca(a);d.transferObjects([_],b)}let f=await this.builder.utils.selectCoinIds(e,de,b),[y,C]=this.builder.utils.takeAmountFromCoins(d,f,e);return d.transferObjects([C],b),p.normalMethod.renewExpiredVeSca(a,y,t),!r||!i||(s&&(c?m.normalMethod.oldUnstakeObligation(r,i):m.normalMethod.unstakeObligation(r,i)),m.normalMethod.stakeObligationWithVesca(r,i,a)),d}async redeemSca(e){let t=new I.TransactionBlock,a=Te({builder:this.builder,txBlock:t}),o=this.walletAddress;return t.setSender(o),await a.redeemScaQuick(e),t}async migrateAndClaim(e,t,a,o){let r=new I.TransactionBlock,i=M({builder:this.builder,txBlock:r}),s=this.walletAddress;r.setSender(s);let c=i.normalMethod.oldClaimBorrowIncentive(a,t,o);return r.transferObjects([c],s),i.stakeObligationWithVeScaQuick(a,t,e),r}async withdrawUnlockedSca(e,t){let a=new I.TransactionBlock,o=Te({builder:this.builder,txBlock:a}),r=t||this.walletAddress;return a.setSender(r),await o.redeemScaQuick(e),a}calculateAvailableClaimCoin(e,t){let a=new io.default(e.weightedAmount),r=t.currentPointIndex?(0,io.default)(t.currentPointIndex-e.index).dividedBy(1e9):1;return a.multipliedBy(r).plus(e.points).shiftedBy(-1*t.coinDecimal)}};var Ra=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.borrow(this.data.coinName,Number(this.data.amount),this.data.obligationId,this.data.obligationKey,t.account.address)}static fromData(t){return new n(t)}};var Na=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return await a.init(),a.borrowWithBoost(this.data.coinName,Number(this.data.amount),this.data.obligationId,this.data.obligationKey,this.data.veScaKey,t.account.address)}static fromData(t){return new n(t)}};var Ea=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.claim(this.data.lendingIncentive,this.data.borrowIncentiveV2,this.data.borrowIncentive,t.account.address)}static fromData(t){return new n(t)}};var Ma=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.depositCollateral(this.data.collateralCoinName,Number(this.data.amount),this.data.obligationId,t.account.address)}static fromData(t){return new n(t)}};var La=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.extendPeriodAndStakeMoreSca(this.data.amount,this.data.veScaKey,this.data.lockPeriodInDays,this.data.obligationId,this.data.obligationKey,this.data.isObligationLocked,this.data.isOldBorrowIncentive,t.account.address)}static fromData(t){return new n(t)}};var Wa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.extendStakeScaLockPeriod(this.data.lockPeriodInDays,this.data.veScaKey,this.data.obligationId,this.data.obligationKey,this.data.isObligationLocked,this.data.isOldBorrowIncentive,t.account.address)}static fromData(t){return new n(t)}};var Fa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return await a.init(),a.migrateAndClaim(this.data.veScaKey,this.data.obligationKey,this.data.obligationId,this.data.rewardCoinName)}static fromData(t){return new n(t)}};var Ua=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.openObligation()}static fromData(t){return new n(t)}};var qa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.redeemSca(this.data.veScaKey)}static fromData(t){return new n(t)}};var $a=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.renewExpiredStakeSca(this.data.amount,this.data.lockPeriodInDays,this.data.vescaKey,this.data.isHaveRedeem,this.data.obligation,this.data.obligationKey,this.data.isObligationLocked,this.data.isOldBorrowIncentive,t.account.address)}static fromData(t){return new n(t)}};var Qa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.repay(this.data.coinName,Number(this.data.amount),this.data.obligationId,this.data.obligationKey,t.account.address)}static fromData(t){return new n(t)}};var Va=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.stakeSca(this.data.amount,this.data.isObligationLocked,this.data.isOldBorrowIncentive,this.data.obligationId,this.data.obligationKey,this.data.lockPeriodInDays,this.data.veScaKey,t.account.address)}static fromData(t){return new n(t)}};var Ga=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.stake(this.data.marketCoinName,Number(this.data.amount),void 0,t.account.address)}static fromData(t){return new n(t)}};var Ka=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.supplyAndStake(this.data.coinName,Number(this.data.amount),this.data.stakeAccountId,t.account.address)}static fromData(t){return new n(t)}};var Ha=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.deposit(this.data.coinName,Number(this.data.amount),t.account.address)}static fromData(t){return new n(t)}};var za=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.unstake(this.data.marketCoinName,Number(this.data.amount),void 0,t.account.address)}static fromData(t){return new n(t)}};var Ja=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.unstakeAndWithdraw(this.data.coinName,Number(this.data.amount),this.data.stakeAccountId)}static fromData(t){return new n(t)}};var Xa=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.withdrawCollateral(this.data.collateralCoinName,Number(this.data.amount),this.data.obligationId,this.data.obligationKey,t.account.address)}static fromData(t){return new n(t)}};var Ya=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=t.network.split(":")[1],o=new h({client:t.suiClient,walletAddress:t.account.address,networkType:a});return o.init(),o.withdraw(this.data.coinName,Number(this.data.amount),t.account.address)}static fromData(t){return new n(t)}};var Za=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new h({client:t.suiClient,walletAddress:t.account.address,networkType:t.network.split(":")[1]});return a.init(),a.withdrawUnlockedSca(this.data.vescaKey,t.account.address)}static fromData(t){return new n(t)}};var en=class{application="scallop";async deserialize(e){let t=new We({client:e.suiClient,walletAddress:e.account.address,networkType:e.network.split(":")[1]});await t.init();let{transactionBlock:a}=e,r=new Aa(a,t).decode();return{txType:Oi.TransactionType.Other,txSubType:r.type,intentionData:r.intentionData}}async build(e){let{suiClient:t,account:a,network:o}=e,r;switch(e.txSubType){case"SupplyLending":r=Ha.fromData(e.intentionData);break;case"WithdrawLending":r=Ya.fromData(e.intentionData);break;case"Borrow":r=Ra.fromData(e.intentionData);break;case"Repay":r=Qa.fromData(e.intentionData);break;case"DepositCollateral":r=Ma.fromData(e.intentionData);break;case"WithdrawCollateral":r=Xa.fromData(e.intentionData);break;case"OpenObligation":r=Ua.fromData(e.intentionData);break;case"StakeSpool":r=Ga.fromData(e.intentionData);break;case"UnstakeSpool":r=za.fromData(e.intentionData);break;case"ClaimIncentiveReward":r=Ea.fromData(e.intentionData);break;case"BorrowWithBoost":r=Na.fromData(e.intentionData);break;case"StakeSca":r=Va.fromData(e.intentionData);break;case"ExtendStakePeriod":r=Wa.fromData(e.intentionData);break;case"ExtendPeriodAndStakeMore":r=La.fromData(e.intentionData);break;case"RenewExpStakePeriod":r=$a.fromData(e.intentionData);break;case"WithdrawStakedSca":r=Za.fromData(e.intentionData);break;case"SupplyAndStakeLending":r=Ka.fromData(e.intentionData);break;case"WithdrawAndUnstakeLending":r=Ja.fromData(e.intentionData);break;case"RedeemSca":r=qa.fromData(e.intentionData);break;case"MigrateAndClaim":r=Fa.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:a,network:o})}};var Ji=require("@msafe/sui3-utils"),Xi=require("turbos-clmm-sdk");var j=require("@msafe/sui3-utils"),so=require("@mysten/sui.js/bcs"),be=require("@mysten/sui.js/utils"),Pi=require("turbos-clmm-sdk");var W={PackageId:"0x02fe4933f4521250e55a15441096d1d4a38a7311195b0bca126fc0138c1f5a97",Claim:"0x0c822cec42f7ca703696b4232f1c47b348330c23580172a29aab465bc071d894",turbosCoinType:"0x5d1f47ea69bb0de31c313d7acf89b890dbb8991ea8e03c6c355171f84bb1ba4a::turbos::TURBOS"},F={PackageId:"0xdee9"};var wc=(n,e,t,a)=>{if(n===1)switch(a.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}`)}},tn=class{constructor(e,t,a){this.txb=e;this.turbosSdk=t;this.config=a}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`]}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(a=>a.kind==="MoveCall"&&a.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(`${W.PackageId}::claim::join`)}isPrixClaimTransaction(){return!!this.getMoveCallTransaction(`${W.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`)}decodeSwap(){let e=this.transactions.find(m=>m.kind==="MoveCall"),t=0;this.swap2Layer.includes(e.target)&&(t=1);let a=wc(t,e.target,this.swap1Layer,this.swap2Layer),o=a.map((m,b)=>{let f=this.helper.decodeSharedObjectId(b),y=this.helper.decodeInputU128(4+b+t),C=this.turbosSdk.math.sqrtPriceX64ToTickIndex(new Pi.BN(y.toString()));return{pool:f,a2b:m,nextTickIndex:C}}),r=a[0]||t===1?e.typeArguments[0]:e.typeArguments[1],i=t===1?e.typeArguments[4]:a[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),p=this.helper.decodeInputU64(3+t);return{txType:j.TransactionType.Other,type:"Swap",intentionData:{routes:o,coinTypeA:r,coinTypeB:i,address:s,amountA:l?d:p,amountB:l?p:d,amountSpecifiedIsInput:l,slippage:"0.1",deadline:c}}}decodeAddLiquidity(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeInputAddress(12),a=this.helper.decodeInputU64(8),o=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:j.TransactionType.Other,type:"AddLiquidity",intentionData:{pool:e,slippage:10,address:t,amountA:a,amountB:o,tickLower:i?-r:r,tickUpper:c?-s:s,deadline:l}}}decodeIncreaseLiquidity(e){let t=this.helper.decodeSharedObjectId(0),a=this.helper.decodeSharedObjectId(4),o=this.helper.decodeInputU64(5),r=this.helper.decodeInputU64(6),i=this.helper.decodeInputU64(9);return{txType:j.TransactionType.Other,type:"IncreaseLiquidity",intentionData:{pool:t,slippage:10,address:e,amountA:o,amountB:r,nft:a,deadline:i}}}decodeDecreaseLiquidity(e){let t=this.helper.decodeSharedObjectId(0),a=this.helper.decodeSharedObjectId(2),o=this.helper.decodeInputU64(3),r=this.helper.decodeInputU64(4),i=this.helper.decodeInputU64(5),s=this.helper.decodeInputU64(6);return{txType:j.TransactionType.Other,type:"DecreaseLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:a,amountA:r,amountB:i,slippage:10,address:e,deadline:s}}}decodeCollectFee(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2),a=this.helper.decodeInputAddress(5),o=this.helper.decodeInputU64(3),r=this.helper.decodeInputU64(4),i=this.helper.decodeInputU64(6);return{txType:j.TransactionType.Other,type:"CollectFee",intentionData:{pool:e,address:a,collectAmountA:o,collectAmountB:r,nft:t,deadline:i}}}decodeCollectReward(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2),a=this.helper.decodeInputAddress(6),o=this.collectRewardHelper.map(i=>i.decodeInputU64(5)),r=this.helper.decodeInputU64(7);return{txType:j.TransactionType.Other,type:"CollectReward",intentionData:{pool:e,address:a,rewardAmounts:o,nft:t,deadline:r}}}decodeBurn(){let e=this.helper.decodeSharedObjectId(0),t=this.helper.decodeSharedObjectId(2);return{txType:j.TransactionType.Other,type:"Burn",intentionData:{pool:e,nft:t}}}decodeRemoveLiquidity(e){let t=this.decreaseLiquidityHelper.decodeSharedObjectId(0),a=this.decreaseLiquidityHelper.decodeSharedObjectId(2),o=this.decreaseLiquidityHelper.decodeInputU64(3),r=this.decreaseLiquidityHelper.decodeInputU64(4),i=this.decreaseLiquidityHelper.decodeInputU64(5),s=this.decreaseLiquidityHelper.decodeInputU64(6),c=this.collectRewardHelper.map(p=>p.decodeInputU64(5)),l=this.collectFeeHelper.decodeInputU64(3)||0,d=this.collectFeeHelper.decodeInputU64(4)||0;return{txType:j.TransactionType.Other,type:"RemoveLiquidity",intentionData:{pool:t,decreaseLiquidity:o,nft:a,amountA:r,amountB:i,slippage:10,address:e,collectAmountA:l,collectAmountB:d,rewardAmounts:c,deadline:s}}}decodePrixClaim(){return{txType:j.TransactionType.Other,type:"PrixClaim",intentionData:{}}}decodePrixJoin(){return{txType:j.TransactionType.Other,type:"PrixJoin",intentionData:{}}}decodeSwapExactBaseForQuote(){let e=this.swapExactBaseForQuoteHelper.decodeSharedObjectId(0),t=this.swapExactBaseForQuoteHelper.decodeInputU64(3),a=this.swapExactBaseForQuoteHelper.shortTypeArg(0),o=this.swapExactBaseForQuoteHelper.shortTypeArg(1);return{txType:j.TransactionType.Other,type:"SwapExactBaseForQuote",intentionData:{poolId:e,amountIn:t,token1:a,token2:o}}}decodeSwapExactQuoteForBase(){let e=this.swapExactQuoteForBaseHelper.decodeSharedObjectId(0),t=this.swapExactQuoteForBaseHelper.decodeInputU64(3),a=this.swapExactQuoteForBaseHelper.shortTypeArg(0),o=this.swapExactQuoteForBaseHelper.shortTypeArg(1);return{txType:j.TransactionType.Other,type:"SwapExactQuoteForBase",intentionData:{poolId:e,amountIn:t,token1:a,token2:o}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target!=="0x2::coin::zero");return new me(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 me(t,this.txb))}get collectFeeHelper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target===`${this.config.PackageId}::position_manager::collect`);return new me(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 me(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 me(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 me(e,this.txb)}},me=class n{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return n.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return n.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,be.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let a=this.getInputParam(e);return n.getPureInputValue(a,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 a=e.value.Pure;return so.bcs.de(t,new Uint8Array(a))}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,be.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,be.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,be.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,be.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 a=e.value.Pure;return so.bcs.de(t,new Uint8Array(a))}typeArg(e){return(0,be.normalizeStructTag)(this.moveCall.typeArguments[e])}shortTypeArg(e){return this.moveCall.typeArguments[e]}txArg(e){return this.moveCall.arguments[e]}};var Di=require("turbos-clmm-sdk"),an=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Di.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,amountA:i,amountB:s,slippage:c,tickLower:l,tickUpper:d,deadline:p,txb:m}=this.data;return a.pool.addLiquidity({pool:o,slippage:c,address:r,amountA:i,amountB:s,tickLower:l,tickUpper:d,deadline:p,txb:m})}static fromData(t){return new n(t)}};var _i=require("turbos-clmm-sdk");var nn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new _i.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,nft:r,txb:i}=this.data;return a.nft.burn({pool:o,nft:r,txb:i})}static fromData(t){return new n(t)}};var Bi=require("turbos-clmm-sdk");var on=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Bi.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,nft:i,collectAmountA:s,collectAmountB:c,deadline:l,txb:d}=this.data;return a.pool.collectFee({pool:o,address:r,collectAmountA:s,collectAmountB:c,nft:i,deadline:l,txb:d})}static fromData(t){return new n(t)}};var ji=require("turbos-clmm-sdk");var rn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new ji.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,nft:i,rewardAmounts:s,deadline:c,txb:l}=this.data;return a.pool.collectReward({pool:o,address:r,rewardAmounts:s,nft:i,deadline:c,txb:l})}static fromData(t){return new n(t)}};var Ri=require("turbos-clmm-sdk");var sn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Ri.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{fee:o,address:r,tickLower:i,tickUpper:s,sqrtPrice:c,slippage:l,coinTypeA:d,coinTypeB:p,amountA:m,amountB:b,deadline:f,txb:y}=this.data;return a.pool.createPool({fee:o,amountA:m,amountB:b,address:r,tickLower:i,tickUpper:s,sqrtPrice:c,slippage:l,coinTypeA:d,coinTypeB:p,deadline:f,txb:y})}static fromData(t){return new n(t)}};var Ni=require("turbos-clmm-sdk");var cn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Ni.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,amountA:i,amountB:s,slippage:c,nft:l,decreaseLiquidity:d,deadline:p,txb:m}=this.data;return a.pool.decreaseLiquidity({pool:o,slippage:c,address:r,amountA:i,amountB:s,nft:l,decreaseLiquidity:d,deadline:p,txb:m})}static fromData(t){return new n(t)}};var Ei=require("turbos-clmm-sdk");var dn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Ei.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{pool:o,address:r,amountA:i,amountB:s,slippage:c,nft:l,deadline:d,txb:p}=this.data;return a.pool.increaseLiquidity({pool:o,slippage:c,address:r,amountA:i,amountB:s,nft:l,deadline:d,txb:p})}static fromData(t){return new n(t)}};var Mi=require("@mysten/sui.js/transactions");var Li=require("@mysten/sui.js/utils"),ln=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Mi.TransactionBlock;return a.moveCall({target:`${W.PackageId}::claim::claim`,typeArguments:[W.turbosCoinType],arguments:[a.object(W.Claim),a.object(Li.SUI_CLOCK_OBJECT_ID)]}),a}static fromData(t){return new n(t)}};var Wi=require("@mysten/sui.js/transactions");var un=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Wi.TransactionBlock;return a.moveCall({target:`${W.PackageId}::claim::join`,typeArguments:[W.turbosCoinType],arguments:[a.object(W.Claim)]}),a}static fromData(t){return new n(t)}};var Fi=require("@mysten/sui.js/transactions"),Ui=require("turbos-clmm-sdk");var pn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Ui.TurbosSdk(t.network.replace("sui:",""),t.suiClient),o=new Fi.TransactionBlock;return o=await a.pool.collectFee({txb:o,...this.data}),o=await a.pool.collectReward({txb:o,...this.data}),o=await a.pool.decreaseLiquidity({txb:o,...this.data}),o=await a.nft.burn({txb:o,nft:this.data.nft,pool:this.data.pool}),o}static fromData(t){return new n(t)}};var qi=require("turbos-clmm-sdk"),mn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(this.data,"this.data");let a=new qi.TurbosSdk(t.network.replace("sui:",""),t.suiClient),{routes:o,coinTypeA:r,coinTypeB:i,address:s,amountA:c,amountB:l,slippage:d,amountSpecifiedIsInput:p,deadline:m,txb:b}=this.data;return a.trade.swap({routes:o,coinTypeA:r,coinTypeB:i,address:s,amountA:c,amountB:l,amountSpecifiedIsInput:p,slippage:d,deadline:m,txb:b})}static fromData(t){return new n(t)}};var Hi=require("turbos-clmm-sdk");var co=require("@mysten/sui.js/utils"),lo=require("@mysten/sui.js/transactions");var $i=require("turbos-clmm-sdk");var mt=class{constructor(e){this.turbosSdk=e}async getCoinsData(e,t,a){let o=[],r;do r=await this.turbosSdk.provider.getCoins({owner:e,coinType:t,cursor:r?.nextCursor}),o.push(...r.data);while(r.hasNextPage);let i=[],s=0;return o.sort((c,l)=>Number(l.balance)-Number(c.balance)).some(c=>s>=a?!0:(s+=Number(c.balance),i.push(c),!1)),i}splitAndMergeCoin(e,t,a){if(!e||e.length<1)return[void 0,void 0];if(this.isSuiCoinAddress(e[0].coinType)){let[i]=a.splitCoins(a.gas,[a.pure(t)]);return[i,void 0]}let o=a.object(e[0].coinObjectId);e.length>1&&a.mergeCoins(o,e.slice(1).map(i=>a.object(i.coinObjectId)));let[r]=a.splitCoins(o,[a.pure(t)]);return[r,o]}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,$i.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 Qi=89,Vi=1e6,Gi=async n=>{let{token1:e,token2:t,poolId:a,amountIn:o,currentAddress:r,turbosSdk:i}=n,s=new lo.TransactionBlock,c=new mt(i),l=await c.getCoinsData(r,t,o),[d,p]=c.splitAndMergeCoin(l,o,s);if(!d)throw new Error(`Not enough balance: ${t}`);let m=await c.IsAccountCap(r),b=m?s.object(m):c.createAccount(s),[f,y,C]=s.moveCall({typeArguments:[e,t],target:`${F.PackageId}::clob_v2::swap_exact_quote_for_base`,arguments:[s.object(String(a)),s.pure(Qi),b,s.pure(o),s.object((0,co.normalizeSuiObjectId)("0x6")),d]});return p&&s.transferObjects([p],s.pure(r)),s.transferObjects([f],s.pure(r)),s.transferObjects([y],s.pure(r)),m||s.transferObjects([b],s.pure(r)),s.setSenderIfNotSet(r),s.setGasBudget(Vi),s},Ki=async n=>{let{token1:e,token2:t,poolId:a,amountIn:o,currentAddress:r,turbosSdk:i}=n,s=new lo.TransactionBlock,c=new mt(i),l=await c.getCoinsData(r,e,o),[d,p]=c.splitAndMergeCoin(l,o,s);if(!d)throw new Error(`Not enough balance: ${e}`);let m=await c.IsAccountCap(r),b=m?s.object(m):c.createAccount(s),f=c.zero(t,s),[y,C,_]=s.moveCall({typeArguments:[e,t],target:`${F.PackageId}::clob_v2::swap_exact_base_for_quote`,arguments:[s.object(String(a)),s.pure(Qi),b,s.pure(o),d,f,s.object((0,co.normalizeSuiObjectId)("0x6"))]});return p&&s.transferObjects([p],s.pure(r)),s.transferObjects([y],s.pure(r)),s.transferObjects([C],s.pure(r)),m||s.transferObjects([b],s.pure(r)),s.setSenderIfNotSet(r),s.setGasBudget(Vi),s};var bn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new Hi.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Ki({...this.data,turbosSdk:a,currentAddress:t.account.address})}static fromData(t){return new n(t)}};var zi=require("turbos-clmm-sdk");var fn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){let a=new zi.TurbosSdk(t.network.replace("sui:",""),t.suiClient);return await Gi({...this.data,turbosSdk:a,currentAddress:t.account.address})}static fromData(t){return new n(t)}};var gn=class{application="turbos";async deserialize(e){let t=new Xi.TurbosSdk(e.network.replace("sui:",""),e.suiClient),a=await t.contract.getConfig(),{transactionBlock:o,account:r}=e;console.log(e,"input");let s=new tn(o,t,a).decode(r.address);return{txType:Ji.TransactionType.Other,txSubType:s.type,intentionData:s.intentionData}}async build(e){let{suiClient:t,account:a,network:o}=e,r;switch(console.log(e.intentionData,"intentionData"),e.txSubType){case"CreatePool":r=sn.fromData(e.intentionData);break;case"AddLiquidity":r=an.fromData(e.intentionData);break;case"IncreaseLiquidity":r=dn.fromData(e.intentionData);break;case"DecreaseLiquidity":r=cn.fromData(e.intentionData);break;case"RemoveLiquidity":r=pn.fromData(e.intentionData);break;case"CollectFee":r=on.fromData(e.intentionData);break;case"CollectReward":r=rn.fromData(e.intentionData);break;case"Burn":r=nn.fromData(e.intentionData);break;case"Swap":r=mn.fromData(e.intentionData);break;case"PrixJoin":r=un.fromData(e.intentionData);break;case"PrixClaim":r=ln.fromData(e.intentionData);break;case"SwapExactBaseForQuote":r=bn.fromData(e.intentionData);break;case"SwapExactQuoteForBase":r=fn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return r.build({suiClient:t,account:a,network:o})}};var ts=require("@msafe/sui3-utils");var hn=require("@msafe/sui3-utils"),uo=require("@mysten/sui.js/bcs"),fe=require("@mysten/sui.js/utils");var Cc={packageId:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55",poolObjectId:"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf",metadataObjectId:"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60",systemStateObjectId:"0x0000000000000000000000000000000000000000000000000000000000000005",certType:"0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT",gasBudget:5e7},k=Cc;var yn=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(`${k.packageId}::native_pool::stake`)}isUnStakeTransaction(){return!!this.getMoveCallTransaction(`${k.packageId}::native_pool::unstake`)}isClaimTicketTransaction(){return!!this.getMoveCallTransaction(`${k.packageId}::native_pool::burn_ticket`)}decodeStake(){let e=this.transactions[0].amounts[0].value.toNumber();return{txType:hn.TransactionType.Other,type:"Stake",intentionData:{amount:e}}}decodeUnStake(){let t=this.transactions.find(a=>a.kind==="SplitCoins").amounts[0].value.toNumber();return{txType:hn.TransactionType.Other,type:"UnStake",intentionData:{amount:t}}}decodeClaimTicket(){let e=this.helper.decodeOwnedObjectId(2);return console.log(e),{txType:hn.TransactionType.Other,type:"ClaimTicket",intentionData:{ticketId:e}}}get helper(){let e=this.transactions.find(t=>t.kind==="MoveCall"&&t.target.startsWith(k.packageId));return new po(e,this.txb)}},po=class n{constructor(e,t){this.moveCall=e;this.txb=t}decodeSharedObjectId(e){let t=this.getInputParam(e);return n.getSharedObjectId(t)}decodeOwnedObjectId(e){let t=this.getInputParam(e);return n.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,fe.normalizeSuiAddress)(t)}decodeInputString(e){return this.decodePureArg(e,"string")}decodeInputBool(e){return this.decodePureArg(e,"bool")}decodePureArg(e,t){let a=this.getInputParam(e);return n.getPureInputValue(a,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 a=e.value.Pure;return uo.bcs.de(t,new Uint8Array(a))}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,fe.normalizeSuiAddress)(e.value.Object.ImmOrOwned.objectId)}return(0,fe.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,fe.normalizeSuiAddress)(e.value);if(!("Object"in e.value)||!("Shared"in e.value.Object))throw new Error("not Shared");return(0,fe.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 a=e.value.Pure;return uo.bcs.de(t,new Uint8Array(a))}typeArg(e){return(0,fe.normalizeStructTag)(this.moveCall.typeArguments[e])}txArg(e){return this.moveCall.arguments[e]}};var Yi=require("@mysten/sui.js/transactions");var Sn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let a=new Yi.TransactionBlock,{ticketId:o}=this.data;return a.moveCall({target:`${k.packageId}::native_pool::burn_ticket`,arguments:[a.object(k.poolObjectId),a.object(k.systemStateObjectId),a.object(o)]}),a.setGasBudget(k.gasBudget),a}static fromData(t){return new n(t)}};var Zi=require("@mysten/sui.js/transactions");var wn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let a=new Zi.TransactionBlock,{amount:o}=this.data,[r]=a.splitCoins(a.gas,[a.pure(o)]);return a.moveCall({target:`${k.packageId}::native_pool::stake`,arguments:[a.object(k.poolObjectId),a.object(k.metadataObjectId),a.object(k.systemStateObjectId),r]}),a.setGasBudget(k.gasBudget),a}static fromData(t){return new n(t)}};var es=require("@mysten/sui.js/transactions");var Cn=class n extends u{constructor(t){super(t);this.data=t}txType;txSubType;async build(t){console.log(t);let a=new es.TransactionBlock,{amount:o}=this.data,r=(await t.suiClient.getAllCoins({owner:t.account.address,limit:100})).data,[i,...s]=r.filter(d=>d.coinType.split("::")[0]===k.certType.split("::")[0]),c=a.object(i.coinObjectId);s.length&&a.mergeCoins(c,s.map(d=>a.object(d.coinObjectId)));let l=a.splitCoins(a.object(i.coinObjectId),[a.pure(o)]);return a.moveCall({target:`${k.packageId}::native_pool::unstake`,arguments:[a.object(k.poolObjectId),a.object(k.metadataObjectId),a.object(k.systemStateObjectId),l]}),a.setGasBudget(k.gasBudget),a}static fromData(t){return new n(t)}};var Tn=class{application="volo";async deserialize(e){let{transactionBlock:t}=e,o=new yn(t).decode();return{txType:ts.TransactionType.Other,txSubType:o.type,intentionData:o.intentionData}}async build(e){let{suiClient:t,account:a}=e,o;switch(e.txSubType){case"Stake":o=wn.fromData(e.intentionData);break;case"UnStake":o=Cn.fromData(e.intentionData);break;case"ClaimTicket":o=Sn.fromData(e.intentionData);break;default:throw new Error("not implemented")}return o.build({suiClient:t,account:a})}};var Ic=new Ta([new da,new ya,new ra,new Sa,new Et,new gn,new en,new Tn]);
|
|
2
2
|
//# sourceMappingURL=index.js.map
|