PageSourceSearch

https://app.hotstuff.trade/_next/static/chunks/17v59cf_tj6cg.js?dpl=dpl_2UkkgYJtZRL8qYawe9FfkxiApWHv

js hotstuff.trade collected 2026-10-07 04:33:20 UTC 34,019 bytes, 5 lines download raw bytes

1;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="35580611-61ce-7cc1-2552-0b5a21ec4bff")}catch(e){}}();
2(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,914289,e=>{"use strict";var t=e.i(271645),r=e.i(957195),a=e.i(268407);e.s(["useOrderHistory",0,function({vaultAddress:e,refetch:s=!1,polling:n=!1,enabled:u=!0}={}){let{setOrderHistory:i,successTable:l}=(0,a.useUserTradingDataStore)(),{setVaultOrderHistory:o}=(0,a.useVaultsStore)();(0,a.useVaultsStore)(e=>e.vaults);let c=(0,a.useVaultsStore)(e=>e.subVaults);(0,a.useVaultsStore)(e=>e.loadingTable);let d=(0,a.useVaultsStore)(e=>e.successTable),[f,g]=(0,t.useState)(!1),[h,m]=(0,t.useState)(null),{infoClient:p}=(0,r.useInfoClient)(),{address:y,status:S}=(0,a.useAuthStore)(),b=(0,t.useCallback)(async(e,t,r)=>{try{let a=await p.orderHistory({user:t,limit:10});r.push(...a.data),o(e,[...r])}catch(e){console.error("Error fetching order history for sub-vault:",t,e)}},[p,o]),_=(0,t.useCallback)(async()=>{try{if(n||(g(!0),m(null)),!u||!y||"disconnected"===S)return;if(e){let t=c[e]?.map(e=>e.sub_vault_address)||[],r=[];await Promise.all(t.map(t=>b(e,t,r)))}else{let e=await p.orderHistory({user:y,limit:20});i(e.data,e.total_count)}}catch(e){console.error("Error fetching order history:",e),n||m("Failed to fetch order history")}finally{n||g(!1)}},[y,e,c,b,p,i,n]),E=e?d[e]?.orderHistory:l.orderHistory;return(0,t.useEffect)(()=>{(!E||s)&&_()},[u,y,S,_,s,e,E]),{isLoading:f,error:h,fetchOrderHistory:_}}])},678844,681621,534979,17596,e=>{"use strict";var t=e.i(271645),r=e.i(957195),a=e.i(268407),s=e.i(960343),n=e.i(346944),u=e.i(780632);e.s(["useOpenOrders",0,function({vaultAddress:e,enabled:i=!0}={}){let{infoClient:l}=(0,r.useInfoClient)(),{setOpenOrders:o,batchUpdateOpenOrders:c}=(0,a.useUserTradingDataStore)(),{setVaultOpenOrders:d,batchUpdateVaultOpenOrders:f}=(0,a.useVaultsStore)(),g=(0,a.useVaultsStore)((0,n.useShallow)(t=>e?t.subVaults[e]??[]:[])),h=(0,t.useMemo)(()=>g.map(e=>e.sub_vault_address).filter(e=>!!e),[g]),{subscriptionClient:m}=(0,s.useSubscriptionClient)(),{address:p,status:y}=(0,a.useAuthStore)(),[S,b]=(0,t.useState)(!1),[_,E]=(0,t.useState)(null),T=(0,t.useRef)([]),v=(0,t.useRef)((0,u.createThrottledBatch)(u.THROTTLE_MS.openOrders,e=>{c(e)})),w=(0,t.useRef)(new Map),C=(0,t.useCallback)(e=>(w.current.has(e)||w.current.set(e,(0,u.createThrottledBatch)(u.THROTTLE_MS.openOrders,t=>{f(e,t)})),w.current.get(e)),[f]),k=(0,t.useCallback)(async(e,t,r,a)=>{try{let s=await l.openOrders({user:t});r.push(...s.data),d(e,[...r]);let n=C(e),u=await m.accountOrderUpdates({address:t},e=>{n.add(e.detail)});a.push(u)}catch(e){console.error("Error with sub-vault open orders:",t,e)}},[l,m,d,C]),A=(0,t.useCallback)(async()=>{let t=[];if(e&&0===h.length)return t;try{if(b(!0),E(null),e){let r=[];await Promise.all(h.map(a=>k(e,a,r,t)))}else{let e=await l.openOrders({user:p});o(e.data);let r=await m.accountOrderUpdates({address:p},e=>{v.current.add(e.detail)});t.push(r)}}catch(e){console.error("[OPEN_ORDERS] Error initializing open orders:",e),E("Failed to fetch open orders")}finally{b(!1)}return t},[p,e,h,k,l,m,o]);return(0,t.useEffect)(()=>{if(i&&p&&"disconnected"!==y)return T.current.forEach(e=>e.unsubscribe()),T.current=[],A().then(e=>{T.current=e}).catch(e=>{console.error("Error initializing open orders:",e)}),()=>{T.current.forEach(e=>e.unsubscribe()),T.current=[],v.current.cancel(),w.current.forEach(e=>e.cancel()),w.current.clear()}},[i,p,y,A]),{isLoading:S,error:_}}],678844),e.s(["useTwapOrders",0,function({enabled:e=!0}={}){let{infoClient:n}=(0,r.useInfoClient)(),{subscriptionClient:i}
2=(0,s.useSubscriptionClient)(),{address:l,status:o}=(0,a.useAuthStore)(),{setTwapOrders:c,batchUpdateTwapOrders:d}=(0,a.useUserTradingDataStore)(),[f,g]=(0,t.useState)(!1),[h,m]=(0,t.useState)(null),p=(0,t.useRef)(null),y=(0,t.useRef)((0,u.createThrottledBatch)(u.THROTTLE_MS.openOrders,e=>{d(e)})),S=(0,t.useCallback)(async()=>{if(!e||!l||"disconnected"===o)return null;try{g(!0),m(null);let e=await n.twapOrders({user:l,limit:100});return c(e.data??[]),i.twapOrderUpdates({address:l},e=>{y.current.add(e.detail)})}catch(e){return console.error("[TWAP_ORDERS] Error initializing TWAP orders:",e),m("Failed to fetch TWAP orders"),null}finally{g(!1)}},[l,e,n,c,o,i]);return(0,t.useEffect)(()=>{if(e&&l&&"disconnected"!==o)return p.current?.unsubscribe(),p.current=null,S().then(e=>{p.current=e}).catch(e=>{console.error("Error initializing TWAP orders:",e)}),()=>{p.current?.unsubscribe(),p.current=null,y.current.cancel()}},[l,e,S,o]),{isLoading:f,error:h}}],681621),e.s(["useTwapOrderHistory",0,function({refetch:e=!1,polling:s=!1,enabled:n=!0}={}){let{setTwapOrderHistory:u,successTable:i}=(0,a.useUserTradingDataStore)(),{infoClient:l}=(0,r.useInfoClient)(),{address:o,status:c}=(0,a.useAuthStore)(),[d,f]=(0,t.useState)(!1),[g,h]=(0,t.useState)(null),m=(0,t.useCallback)(async()=>{try{if(s||(f(!0),h(null)),!n||!o||"disconnected"===c)return;let e=await l.twapOrderHistory({user:o,limit:20});u(e.data??[],e.total_count)}catch(e){console.error("Error fetching TWAP order history:",e),s||h("Failed to fetch TWAP order history")}finally{s||f(!1)}},[o,n,l,s,u,c]);return(0,t.useEffect)(()=>{(!i.twapOrderHistory||e)&&m()},[o,n,m,e,c,i.twapOrderHistory]),{isLoading:d,error:g,fetchTwapOrderHistory:m}}],534979);var i=e.i(143813);let l=e=>e?.legs.map(t=>({entry_price:t.entry_price.toString(),instrument:e.instrument,instrument_id:e.instrument_id,leverage:t.leverage.value.toString(),margin_mode:t.leverage.type,position_side:t.side,position_value:t.position_value.toString(),size:t.size.toString(),updated_at:e.block_timestamp,user:e.account}));e.s(["usePositions",0,function({vaultAddress:e,enabled:o=!0}={}){let{updatePositions:c,deletePosition:d,setError:f,setLoadingTable:g,setSuccessTable:h}=(0,a.useUserTradingDataStore)(),{setVaultPositions:m,updateVaultPositions:p,deleteVaultPosition:y,setLoadingTable:S,setSuccessTable:b}=(0,a.useVaultsStore)(),_=(0,a.useVaultsStore)((0,n.useShallow)(t=>e?t.subVaults[e]??[]:[])),E=(0,t.useMemo)(()=>(0,i.getSubVaultAdresses)(_.map(e=>e.sub_vault_address).filter(e=>!!e)),[_]),{subscriptionClient:T}=(0,s.useSubscriptionClient)(),{infoClient:v}=(0,r.useInfoClient)(),{address:w,status:C}=(0,a.useAuthStore)(),k=(0,t.useRef)([]),A=(0,t.useRef)((0,u.createThrottledBatch)(u.THROTTLE_MS.positions,e=>{e.forEach(e=>c(e))})),O=(0,t.useRef)(new Map),R=(0,t.useCallback)(e=>(O.current.has(e)||O.current.set(e,(0,u.createThrottledBatch)(u.THROTTLE_MS.positions,t=>{t.forEach(t=>p(e,t))})),O.current.get(e)),[p]),D=(0,t.useCallback)(async(e,t,r)=>{try{let a=R(e),s=await T.positions({address:t},t=>{let r=t.detail;if(r?.legs?.length>0){let e=l(r);a.add(e)}else y(e,String(r.instrument_id),r.position_side_updated)});r.push(s)}catch(e){console.error("Error subscribing to sub-vault positions:",t,e),f("Failed to subscribe to positions")}},[T,R,y,f]),F=(0,t.useCallback)(async()=>{let t=[];if(e&&0===E.length)return t;try{if(e)f(null),await Promise.all(E.map(r=>D(e,r,t)));else{f(null);let e=await T.positions({address:w},e=>{let t=e.detail;if(t?.legs&&t?.legs?.length>0){let e=l(t);A.current.add(e)}else d(String(t.instrument_id),t.position_side_updated)});t.push(e)}}catch(t){console.error("Error fetching/subscribing to positions:",t),e?b(e,!1,"positions"):f("Failed to fetch positions")}finally{e&&S(e,!1,"positions")}return t},[w,e,E,D,T,c,d,f]);return(0,t.useEffect)(()=>{if(o&&(e||w&&"disconnected"!==C))return k.current.forEach(e=>e.unsubscribe()),k.current=[],F().then(e=>{k.current=e}).catch(e=>{console.error("Error subscribing to positions:",e)}),()=>{k.current.forEach(e=>e.unsubscribe()),k.current=[],A.current.cancel(),O.current.forEach(e=>e.cancel()),O.current.clear()}},[o,w,C,e,F]),{}}],17596)},717931,e=>{"use strict";var t=e.i(271645),r=e.i(957195),a=e.i(268407),s=e.i(960343),n=e.i(143813);e.s(["useTradeHistory",0,function({vaultAddress:e,refetch:u=!1,polling:i=!1,enabled:l=!0,page:o=0,limit:c=10}={}){let{setNotification:d}=(0,a.useNotificationStore)(),{subscriptionClient:f}
2=(0,s.useSubscriptionClient)(),{setTradeHistory:g,successTable:h,updateTradeHistory:m}=(0,a.useUserTradingDataStore)(),{setVaultTradeHistory:p,updateVaultTradeHistory:y}=(0,a.useVaultsStore)();(0,a.useVaultsStore)(e=>e.vaults);let S=(0,a.useVaultsStore)(e=>e.subVaults),b=(0,a.useVaultsStore)(e=>e.successTable),{infoClient:_}=(0,r.useInfoClient)(),{address:E,status:T}=(0,a.useAuthStore)(),[v,w]=(0,t.useState)(!1),[C,k]=(0,t.useState)(null),A=(0,t.useRef)(!1),O=(0,t.useRef)(null),R=(0,a.useGlobalStore)(e=>e.enableFillNotifications),D=(0,t.useCallback)(async(e,t,r)=>{try{let a=await _.tradeHistory({user:t,limit:10});r.push(...a.data),p(e,[...r])}catch(e){console.error("Error fetching trade history for sub-vault:",t,e)}},[_]),F=(0,t.useCallback)(async()=>{if(!A.current){A.current=!0;try{if(i||(w(!0),k(null)),!l||!E||"disconnected"===T){A.current=!1;return}if(e){let t=(0,n.getSubVaultAdresses)(S[e]?.map(e=>e.sub_vault_address)||[]),r=[];await Promise.all(t.map(t=>D(e,t,r)))}else{let e=await _.tradeHistory({user:E,limit:20,page:o});g(e.data.reverse(),e.total_count)}}catch(e){console.error("Error fetching trade history:",e),i||k("Failed to fetch trade history")}finally{A.current=!1,i||w(!1)}}},[E,e,S,D,_,i,l,T,o,c,g]),I=t=>{let r=t.detail,s=a.useUserTradingDataStore.getState().pendingStatusOrders;!R||e||s.includes(r.cloid)||d({id:r.trade_id.toString(),title:"Fill",message:`Fill ${r.instrument} ${r.size} at ${r.price}`,type:"success"}),e||m(r)};e?b[e]?.tradeHistory:h.tradeHistory;let M=async e=>{await F(),await U(e)},U=async t=>{try{O.current&&O.current.unsubscribe(),O.current=await f.fills({address:e||t},I)}catch(e){console.error("Error subscribing to fills:",e)}};return(0,t.useEffect)(()=>(E&&"0x0000000000000000000000000000000000000000"!==E&&M(E),()=>{O.current&&(O.current.unsubscribe(),O.current=null)}),[E]),{isLoading:v,error:C,fetchTradeHistory:F,enableFillNotifications:R}}])},953694,e=>{"use strict";var t=e.i(500932),r=e.i(271645),a=e.i(957195),s=e.i(960343),n=e.i(268407),u=e.i(618566),i=e.i(780632);e.i(164485);var l=e.i(279582);function o(e){return e.selectedInstrument}function c(e){return e.trades}e.s(["useThrottledTrades",0,function(e){let a,s,u,i,l,d,f,g=(0,t.c)(13),h=void 0===e?100:e,m=(0,n.useTradingDataStore)(c),p=(0,n.useTradingDataStore)(o),[y,S]=(0,r.useState)(void 0),b=(0,r.useRef)(0),_=(0,r.useRef)(null),E=(0,r.useRef)(!1),T=(0,r.useRef)(void 0);g[0]!==m||g[1]!==h?(a=()=>{let e=Date.now(),t=e-b.current;if(m!==T.current){if(t>=h)S(m),T.current=m,b.current=e,E.current=!1;else if(!E.current){E.current=!0;let e=h-t;_.current&&clearTimeout(_.current),_.current=setTimeout(()=>{S(m),T.current=m,b.current=Date.now(),E.current=!1},e)}}},g[0]=m,g[1]=h,g[2]=a):a=g[2];let v=a;return g[3]!==m||g[4]!==p?(s=()=>{p&&(S(m),T.current=m,b.current=Date.now())},u=[p,m],g[3]=m,g[4]=p,g[5]=s,g[6]=u):(s=g[5],u=g[6]),(0,r.useEffect)(s,u),g[7]!==v?(i=()=>{v()},g[7]=v,g[8]=i):i=g[8],g[9]!==m?(l=[m],g[9]=m,g[10]=l):l=g[10],(0,r.useEffect)(i,l),g[11]===Symbol.for("react.memo_cache_sentinel")?(d=()=>()=>{_.current&&clearTimeout(_.current)},f=[],g[11]=d,g[12]=f):(d=g[11],f=g[12]),(0,r.useEffect)(d,f),y},"useTradingData",0,function({featureFlags:e}){let{updateInstruments:t,updateTicker:o,selectedInstrument:c,setTrades:d,updateTrades:f,clearTrades:g,setSupportedCollateral:h}=(0,n.useTradingDataStore)(),{infoClient:m}=(0,a.useInfoClient)(),{subscriptionClient:p}=(0,s.useSubscriptionClient)(),y=(0,u.useParams)(),S=(0,r.useRef)(y),[b,_]=(0,r.useState)(!1),[E,T]=(0,r.useState)(null),v=(0,r.useRef)(null),w=(0,r.useRef)(null),{activeSource:C}=(0,l.useAuthController)(),k=(0,r.useRef)((0,i.createThrottledBatch)(i.THROTTLE_MS.ticker,t=>{let r=new Map;t.forEach(e=>{r.set(e.instrument_name,e)}),r.forEach((t,r)=>{o(r,t,e.invest)})})),A=(0,r.useRef)((0,i.createThrottledBatch)(i.THROTTLE_MS.trades,e=>{e.forEach(e=>f(e))}));(0,r.useEffect)(()=>{S.current=y},[y]);let O=(0,r.useCallback)(async()=>{try{_(!0),T(null);let r=m.getInstruments({type:"all"});m.getTicker({symbol:"all"}).then(t=>{for(let r of t)o(r.symbol,r,e.invest)}).catch(e=>{console.error("Failed to get ticker for all instruments",e)});let a=await r;if(a&&"object"==typeof a){t(a,e.invest);try{w.current=await p.ticker({symbol:"all"},e=>{k.current.add(e.detail)})}catch(e){console.error("Failed to subscribe to ticker for all instruments",e)}}return a}catch(e){console.error("Error fetching instruments:",e),T(e instanceof Error?e:Error("Failed to fetch instruments"))}finally{_(!1)}},[m,p,t,o,e.invest]),R=(0,r.useCallback)(async e=>{try{v.current&&(v.current.unsubscribe(),v.current=null),g();
2let t=await m.getTrades({symbol:e,limit:20});d(t);try{v.current=await p.trade({instrumentId:e},e=>{A.current.add(e.detail)})}catch(e){console.error("Failed to subscribe to trade updates:",e)}}catch(e){console.error("Error fetching trades:",e),T(e instanceof Error?e:Error("Failed to fetch trades"))}finally{_(!1)}},[m,d,f,p,g]);return(0,r.useEffect)(()=>{O()},[O]),(0,r.useEffect)(()=>{c&&R(c)},[c,R]),(0,r.useEffect)(()=>()=>{v.current&&(v.current.unsubscribe(),v.current=null),w.current&&(w.current.unsubscribe(),w.current=null),k.current.cancel(),A.current.cancel()},[]),(0,r.useEffect)(()=>{(async()=>{try{let t=await m.getSupportedCollateral({symbol:"all"});h(t,e.invest,!1)}catch(e){console.error("Error fetching supported collaterals:",e),T(e instanceof Error?e:Error("Failed to fetch supported collaterals"))}})()},[m,h,e.invest]),{getInstruments:O,isLoading:b,error:E}}])},706967,e=>{"use strict";e.i(500932),e.i(271645),e.i(960343),e.i(268407),e.s([])},562483,e=>{"use strict";var t=e.i(500932),r=e.i(268407),a=e.i(271645),s=e.i(960343),n=e.i(780632);function u(e){return parseFloat(e.price)}function i(e){return parseFloat(e.price)}function l(e){return e.selectedInstrument}e.s(["useOrderbook",0,function(e){let a,s,n=(0,t.c)(13),o=(0,r.useTradingDataStore)(l),c=e??o;n[0]!==c?(a=e=>c?e.orderbooks[c]:void 0,n[0]=c,n[1]=a):a=n[1];let d=(0,r.useOrderbookDataStore)(a);if(!d||!d.instrument_name||0===d.bids.length&&0===d.asks.length)return;let f=0,g=0;if(d.asks.length>0){let e;n[2]!==d.asks?(e=Math.min(...d.asks.map(i)),n[2]=d.asks,n[3]=e):e=n[3],f=e}if(d.bids.length>0){let e;n[4]!==d.bids?(e=Math.max(...d.bids.map(u)),n[4]=d.bids,n[5]=e):e=n[5],g=e}let h=f&&g?f-g:0,m=f&&g?(f+g)/2:0,p=m>0?h/m*100:0;return n[6]!==f||n[7]!==g||n[8]!==m||n[9]!==d||n[10]!==h||n[11]!==p?(s={...d,bestAsk:f,bestBid:g,spread:h,mid:m,spreadPercentage:p},n[6]=f,n[7]=g,n[8]=m,n[9]=d,n[10]=h,n[11]=p,n[12]=s):s=n[12],s},"useOrderbookData",0,function(e,t=!0){let{updateOrderbook:u,setOrderbook:i,clearOrderbook:l}=(0,r.useOrderbookDataStore)(),{subscriptionClient:o}=(0,s.useSubscriptionClient)(),{selectedInstrument:c}=(0,r.useTradingDataStore)(),d=e??c,[f,g]=(0,a.useState)(!1),[h,m]=(0,a.useState)(null),p=(0,a.useRef)(null),y=(0,a.useRef)(null),S=(0,a.useRef)(null),b=(0,a.useCallback)(()=>{if(S.current&&(S.current.cancel(),S.current=null),p.current){try{p.current.unsubscribe()}catch(e){}p.current=null}},[]),_=(0,a.useCallback)(async()=>{if(d)try{g(!0),m(null),b(),S.current=(0,n.createThrottledBatch)(n.THROTTLE_MS.orderbook,e=>{y.current===d&&e.forEach(e=>u(d,e))});try{let e=S.current;p.current=await o.orderbook({instrumentId:d},t=>{if(y.current===d){if("snapshot"===t.detail.update_type){let e=t.detail.books;i(d,e)}"delta"===t.detail.update_type&&e.add(t.detail.books)}})}catch(e){console.error("Failed to subscribe to orderbook updates:",e)}}catch(e){throw console.error("Error fetching orderbook:",e),m(e instanceof Error?e:Error("Failed to fetch orderbook")),e}finally{g(!1)}},[d,i,o,u,b]);return(0,a.useEffect)(()=>{if(t&&d)y.current=d,b(),l(d),_();else{let e=y.current;b(),e&&l(e),y.current=null}},[t,d,_,l,b]),(0,a.useEffect)(()=>()=>{b()},[b]),{isLoading:f,error:h}}])},967219,844890,366609,37770,e=>{"use strict";var t=e.i(271645),r=e.i(957195),a=e.i(960343),s=e.i(268407);e.i(732839);var n=e.i(149691),u=e.i(215772),i=e.i(858532);e.i(842917);var l=e.i(68043);function o(){let{setAgentWallets:e}=(0,s.useUserTradingDataStore)(),{infoClient:o}=(0,r.useInfoClient)(),{subscriptionClient:c}=(0,a.useSubscriptionClient)(),{address:d,status:f,pendingAgents:g,clearPendingAgent:h,setAgent:m,clearAgent:p,setStatus:y}=(0,s.useAuthStore)(),[S,b]=(0,t.useState)(!1),[_,E]=(0,t.useState)(null),T=(0,t.useRef)(null),v=(0,t.useCallback)(e=>{let t=s.useAuthStore.getState().agents[d];if(!t||"qr-code"===t.name)return;let r=e.find(e=>"default"===e.agent_name);if(!r){console.warn("No default agent found. Clearing auth agent."),p(d),y("connected"),i.showToast.warning({message:"Trading disabled. Please enable trading."});return}if(r.agent_address.toLowerCase()!==t.address.toLowerCase()){console.warn("Default agent address does not match auth agent address. Clearing auth agent."),p(d),y("connected"),i.showToast.warning({message:"Agent wallet mismatch detected. Trading has been disabled."});return}if(e.length>3&&e.filter(e=>"default"!==e.agent_name).every(e=>r.created_at_block_timestamp<e.created_at_block_timestamp)){console.warn("More than 3 agents detected and default agent is older than all others. Clearing auth agent."),p(d),y("connected"),i.showToast.warning({message:"Unauthorized agent detected. Trading has been disabled."});return}},[d,p,y]),w=(0,t.useCallback)(async()=>{try{b(!0);let t=await o.getAgents({user:d});d?(e(t),v(t)):e(t)}catch(e){console.error("Error fetching agent wallets:",e),E("Failed to fetch agent wallets")}finally{b(!1)}},[d,o,e,v]),C=(0,t.useCallback)(async()=>{try{b(!0);let e=new n.HttpTransport({env:(0,l.getSdkEnv)(),...u.default.http}),t=g[d];if(!t)return{success:!1,error:"No pending agent found"};let r=await e.request("exchange",{action:{data:t?.params,type:"1201"},signature:t?.signature,nonce:t?.params.nonce});return h(d),m(d,{name:t?.params.agentName,address:t?.params.agent,privateKey:t?.privateKey}),{success:!0,data:r}}catch(t){let e=t instanceof Error?t.message:String(t);return i.showToast.error({message:e}),{success:!1,error:e}}},[d,g,h,m]),k=(0,t.useCallback)(async()=>{try{T.current=await c.agents({user:d},t=>{let r=t.detail,a={user:r.main_account,agent_address:r.agent_address,agent_name:r.agent_name,valid_until_timestamp:r.valid_until,created_at_block_timestamp:r.block_t
2imestamp},n=s.useUserTradingDataStore.getState().agentWallets.filter(e=>e.user.toLowerCase()!==a.user.toLowerCase()||e.agent_name!==a.agent_name);n.push(a),e(n),v(n)})}catch(e){console.error("Failed to subscribe to agent updates:",e)}},[d,c,e,v]);return(0,t.useEffect)(()=>{if(d&&"disconnected"!==f)return w(),k(),()=>{if(T.current)try{T.current.unsubscribe()}catch(e){console.error("Failed to unsubscribe from agent updates on cleanup:",e)}finally{T.current=null}}},[d,f,w,k]),{isLoading:S,error:_,fetchAgentWallets:w,resendEnableTradingRequest:C}}e.s(["useAgentWallets",0,o],844890);var c=e.i(344873),d=e.i(780632);e.s(["useAccountSummary",0,function(){let{infoClient:e}=(0,r.useInfoClient)(),{address:n,master:u}=(0,s.useAuthStore)(),{subscriptionClient:i}=(0,a.useSubscriptionClient)(),{resendEnableTradingRequest:l}=o(),f=(0,t.useRef)(null),g=(0,t.useRef)(null),h=(0,t.useCallback)(e=>{let t=[];return Object.entries(e.perp_positions||{}).forEach(([r,a])=>{a.legs.forEach(s=>{t.push({margin:a.im.toString(),entry_price:s.entry_price.toString(),instrument:s.instrument_name||r,instrument_id:s.instrument_id,leverage:s.leverage.value.toString(),liquidation_price:a.liquidation_price.toString(),margin_mode:s.leverage.type,position_side:s.side,position_value:s.position_value.toString(),size:s.size.toString(),updated_at:Date.now(),user:e.address})})}),t},[]),m=(0,t.useCallback)(async e=>{let{updateAccountSummary:t,setPositions:r}=s.useUserTradingDataStore.getState(),{updateStatusFromAccountSummary:a}=s.useAuthStore.getState();t(e),r(h(e));let n=Object.keys(e.collateral).length>0||Object.keys(e.spot_collateral).length>0;"user-not-found"===s.useAuthStore.getState().status&&n&&(await l(),a(n))},[l,h]),p=(0,t.useCallback)(e=>{g.current?g.current.add(e.detail):m(e.detail)},[m]),y=(0,t.useCallback)(async t=>{let r=(0,c.normalizeAddress)(t),{setLoadingTable:a,setAccountSummary:n,setPositions:u,setSuccessTable:o,setError:y,setLoading:S}=s.useUserTradingDataStore.getState(),{updateStatusFromAccountSummary:b}=s.useAuthStore.getState();try{a(!0,"positions");let t=await e.accountSummary({user:r});n(t);let s=h(t);u(s),o(!0,"positions"),y(null);let c=Object.keys(t?.collateral).length>0||Object.keys(t?.spot_collateral).length>0;c&&await l(),b(c);try{f.current&&f.current.unsubscribe(),g.current&&g.current.cancel(),g.current=(0,d.createThrottledBatch)(d.THROTTLE_MS.accountSummary,e=>{e.length>0&&m(e[e.length-1])}),f.current=await i.accountSummary({user:r},p)}catch(e){console.error("Failed to subscribe to account summary updates:",e)}}catch(e){console.error("Error fetching account summary:",e),y("Failed to fetch account summary"),o(!1,"positions")}finally{S(!1),a(!1,"positions")}},[e,i,p,l,h]),S=(0,t.useCallback)(async t=>{let{setVaults:r,setSubVaults:a}=s.useUserTradingDataStore.getState();try{let s=await e.getVaults({user:t});for(let t of(r(s.vaults),s.vaults)){let r=await e.getSubVaults({vaultAddress:t.vault_address});a(r)}}catch(e){console.error("Error fetching vaults:",e)}},[e]);return(0,t.useEffect)(()=>(n&&"0x0000000000000000000000000000000000000000"!==n&&"disconnected"!==s.useAuthStore.getState().status&&y(n),()=>{f.current&&(f.current.unsubscribe(),f.current=null),g.current&&(g.current.cancel(),g.current=null)}),[n,y]),(0,t.useEffect)(()=>{u&&"0x0000000000000000000000000000000000000000"!==u&&S(u)},[u,S]),{}}],967219);var f=e.i(500932);e.s(["useAccountHistory",0,function(){let e,a,n=(0,f.c)(6),{infoClient:u}=(0,r.useInfoClient)(),{address:i,status:l}=(0,s.useAuthStore)(),{setAccountHistory:o}=(0,s.useAccountHistoryStore)();n[0]!==i||n[1]!==u||n[2]!==o||n[3]!==l?(e=()=>{let e=async e=>{let t=(0,c.normalizeAddress)(e);try{let e=await u.accountHistory({user:t});Array.isArray(e)&&o(t,e)}catch(e){console.error("accountHistory fetch failed",e)}};i&&"disconnected"!==l&&e(i)},a=[i,l,u,o],n[0]=i,n[1]=u,n[2]=o,n[3]=l,n[4]=e,n[5]=a):(e=n[4],a=n[5]),(0,t.useEffect)(e,a)}],366609),e.s(["useUserFees",0,function(){let{isLoading:e,setLoading:a,setUserFees:n}=(0,s.useUserTradingDataStore)(),[u,i]=(0,t.useState)(null),{infoCl
2ient:l}=(0,r.useInfoClient)(),{address:o,status:d}=(0,s.useAuthStore)(),f=async e=>{let t=(0,c.normalizeAddress)(e);try{a(!0),i(null);let e=await l.userFeeInfo({user:t});n(e)}catch(e){console.error("Error fetching user fees:",e),i(e instanceof Error?e:Error("Failed to fetch user fees"))}finally{a(!1)}};return(0,t.useEffect)(()=>{o&&"disconnected"!==d&&f(o)},[o,d]),{isLoading:e,error:u}}],37770)},39900,e=>{"use strict";var t=e.i(271645),r=e.i(957195),a=e.i(268407);e.s(["useInstrumentLeverage",0,function(){let{setLeverage:e}=(0,a.useUserTradingDataStore)(),{infoClient:s}=(0,r.useInfoClient)(),{address:n,status:u}=(0,a.useAuthStore)(),[i,l]=(0,t.useState)(!1),[o,c]=(0,t.useState)(null),d=Object.values((0,a.useTradingDataStore)(e=>e.instruments)).filter(e=>"perps"===e.kind).length,f=(0,t.useCallback)(async t=>{if(n&&"disconnected"!==u)try{if(l(!0),c(null),t){if(!t.includes("PERP"))return;let r=await s.getInstrumentLeverage({user:n,symbol:t});e(t,{leverage:r?.leverage??r?.Leverage??1,margin_mode:r?.margin_type??r?.MarginType??"cross"});return}let r=Object.values(a.useTradingDataStore.getState().instruments).filter(e=>"perps"===e.kind).map(e=>e.name);if(0===r.length)return;(await Promise.allSettled(r.map(e=>s.getInstrumentLeverage({user:n,symbol:e})))).forEach((t,a)=>{if("fulfilled"===t.status&&r[a]){let s=t.value;e(r[a],{leverage:s?.leverage??s?.Leverage??1,margin_mode:s?.margin_type??s?.MarginType??"cross"})}})}catch(e){console.error("Error fetching instrument leverage:",e),c("Failed to fetch instrument leverage")}finally{l(!1)}},[n,u,s,e]);return(0,t.useEffect)(()=>{n&&"disconnected"!==u&&d>0&&f()},[n,u,d,f]),{isLoading:i,error:o,fetchInstrumentLeverage:f}}])},929009,806378,44867,58016,201034,487251,118925,73111,868873,444714,839577,e=>{"use strict";e.i(914289),e.i(678844),e.i(681621),e.i(534979),e.i(17596),e.i(717931),e.i(953694),e.i(706967),e.i(960343);var t=e.i(957195);e.i(562483),e.i(967219),e.i(366609),e.i(37770),e.i(844890),e.i(39900);var r=e.i(271645),a=e.i(268407);e.s(["useFundingPayments",0,function({refetch:e=!1,polling:s=!1,enabled:n=!0}={}){let{setFundingPayments:u,successTable:i}=(0,a.useUserTradingDataStore)(),{infoClient:l}=(0,t.useInfoClient)(),{address:o,status:c}=(0,a.useAuthStore)(),[d,f]=(0,r.useState)(!1),[g,h]=(0,r.useState)(null),m=(0,r.useCallback)(async()=>{try{if(s||f(!0),!n||!o||"disconnected"===c)return;let e=await l.fundingHistory({user:o,limit:20});u(e.data,e.total_count)}catch(e){console.error("Error fetching funding payments:",e),s||h("Failed to fetch funding payments")}finally{s||f(!1)}},[o,l,u,s,n,c]),p=i.fundingPayments;return(0,r.useEffect)(()=>{(!p||e)&&m()},[n,o,c,m,e,p]),{isLoading:d,error:g,fetchFundingPayments:m}}],806378),e.s(["useUserMetadata",0,function(){let{setUserMetadata:e,setStatus:r,setIsUserMetadataLoading:s}=(0,a.useAuthStore)(),{setAccountInfo:n}=(0,a.useUserTradingDataStore)(),{infoClient:u}=(0,t.useInfoClient)();return{fetchUserMetadata:async t=>{try{let r=await u.getUserMetadata({user:t});e(t,r)}catch(e){console.error("Error fetching user metadata:",e)}finally{s(!1)}},fetchAccountInfo:async e=>{try{let t=await u.accountInfo({user:e});if("error"in t&&"account not found"===t.error)return void n(e,null);n(e,t)}catch(e){console.error("Error fetching user metadata:",e)}}}}],44867);var s=e.i(111635),n=e.i(818279),u=e.i(858532),i=e.i(942290);e.s(["useExpedition",0,()=>{let{infoClient:e}=(0,t.useInfoClient)(),{activeTier:r,completedMilestones:l,setActiveTier:o,setCompletedMilestones:c,setLoading:d}=(0,a.useExpeditionDataStore)();return{activeTier:r,completedMilestones:l,checkExpeditionProgress:async()=>{let{address:e,setUserMetadata:t}=a.useAuthStore.getState();if(e&&"0x0000000000000000000000000000000000000000"!==e){d(!0);try{let r=await (0,n.checkExpeditionProgress)(e);r&&t(e,r);let a=r?.metadata?.active_tier??0,u=r?.metadata?.completed_milestones||[];c(new Set(u));let i=s.EXPEDITION_TIERS.find(e=>e.id===a)||s.EXPEDITION_TIERS[0],l={...i,milestones:i.milestones.map(e=>({...e,completed:u.includes(e.id)}
2))};o(l)}catch(e){console.error("Error checking expedition progress:",e),o(s.EXPEDITION_TIERS[0])}finally{d(!1)}}},claimGM:async()=>{let{address:t,setUserMetadata:r}=a.useAuthStore.getState();try{let a=await e.claimGM({user:t}),s=a?.error;if(s){let e=(0,i.getErrorOverride)(s);u.showToast.error({message:"Error Claiming GM",...e?{description:e}:{}})}else u.showToast.success({message:"GM claimed successfully",description:"You have received 1 GM"}),r(t,a)}catch(r){let e=(0,i.getErrorMessage)(r),t=(0,i.getErrorOverride)(e);u.showToast.error({message:"Error Claiming GM",...t?{description:t}:{}})}}}}],58016),e.s(["useCollateralTransactions",0,function({refetch:e=!1,polling:s=!1,enabled:n=!0}={}){let{setCollateralTransactions:u}=(0,a.useUserTradingDataStore)(),{infoClient:i}=(0,t.useInfoClient)(),{address:l,status:o}=(0,a.useAuthStore)(),[c,d]=(0,r.useState)(!1),[f,g]=(0,r.useState)(null),h=(0,r.useCallback)(async()=>{try{if(s||(d(!0),g(null)),!n||!l||"disconnected"===o){s||d(!1);return}let e=await i.getTransferHistory({user:l});u(e)}catch(e){s||g("Failed to fetch collateral transactions")}finally{s||d(!1)}},[l,i,u,s,n,o]);return(0,r.useEffect)(()=>{n&&h()},[h,n]),(0,r.useEffect)(()=>{e&&n&&h()},[e,n,h]),{isLoading:c,error:f,fetchCollateralTransactions:h}}],201034),e.i(849387);var l=e.i(727726),o=e.i(344873);e.s(["useReferralSummary",0,function(){let{infoClient:e}=(0,t.useInfoClient)(),{address:s,status:n}=(0,a.useAuthStore)(),u=(0,a.useUserTradingDataStore)(e=>e.setReferralSummary),i=(0,a.useUserTradingDataStore)(e=>e.referralSummary[s]),{setReferrer:c}=(0,l.useAccountActions)(),[d,f]=(0,r.useState)(!1),g=(0,r.useRef)(!1),h=(0,r.useRef)(!1),m=(0,r.useCallback)(async t=>{if(h.current)return;let r=(0,o.normalizeAddress)(t);try{h.current=!0,f(!0);let t=await e.referralSummary({user:r});u(t)}catch(e){console.error("referralSummary fetch failed",e)}finally{f(!1),h.current=!1}},[e,u]);return(0,r.useEffect)(()=>{s&&"disconnected"!==n&&!i&&m(s)},[s,n,i,m]),(0,r.useEffect)(()=>{if(s&&"trading-enabled"===n&&!g.current){let e=i?.referrer_code;if(!e||""===e)try{let e=JSON.parse(localStorage.getItem("pendingReferralCodes")||"{}"),t=e[s];t&&""!==t&&(g.current=!0,c(t).then(()=>{delete e[s],localStorage.setItem("pendingReferralCodes",JSON.stringify(e)),m(s)}).catch(t=>{console.error("Failed to set referrer code:",t),delete e[s],localStorage.setItem("pendingReferralCodes",JSON.stringify(e)),g.current=!1}))}catch(e){console.error("Error reading pending referral codes:",e)}}},[s,n,i,c,m]),{fetchReferralSummary:m,isLoading:d}}],487251);var c=e.i(500932);e.s(["useLegalTerms",0,function(){let e,t,r=(0,c.c)(4),{setLegalTermsSigned:s}=(0,a.useAuthStore)();r[0]!==s?(e=async e=>{try{let t=await (0,n.getLegalTermsStatus)(e);return s(e,t.signed),t.signed}catch(t){return console.error("Error fetching legal terms status:",t),s(e,!1),!1}},r[0]=s,r[1]=e):e=r[1];let u=e;return r[2]!==u?(t={fetchLegalTermsStatus:u},r[2]=u,r[3]=t):t=r[3],t}],118925),e.i(842917);var d=e.i(68043);e.s(["useVaultApr",0,function({vaultAddress:e,totalEquity:s}){let{infoClient:n}=(0,t.useInfoClient)(),u=(0,a.useVaultsStore)(t=>e?t.vaultStatsByAddress[e]?.trailing_7d_apr:void 0),i=(0,a.useVaultsStore)(t=>e?t.vaultStatsByAddress[e]?.trailing_30d_apr:void 0),[l,o]=(0,r.useState)([]),[c,f]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let t=async()=>{if(e){f(!0);try{let t=await n.getTransferHistory({user:e});Array.isArray(t)&&o(t)}catch(e){console.error("Error fetching vault transactions:",e)}finally{f(!1)}}};e&&t()},[e,n]);let g=(0,r.useMemo)(()=>c||!e?null:l.length>0&&s>0?Math.max(function(e,t){if(!e||0===e.length)return 0;let r=0,a=0,s=0;e.forEach(e=>{let t="string"==typeof e.amount?parseFloat(e.amount):e.amount;"vault_deposit"===e.type?r+=t:"vault_withdraw"===e.type?a+=t:"derivative_balance_transfer"===e.type&&(s+=t)});let n=r-a;if(n<=0)return 0;let u=t+s,i=e.map(e=>{try{let t=e.timestamp.replace("Z","+00:00");return new Date(t).getTime()}catch{return 0}}).filter(e=>e>0);if(i.length<2)return 0;let l=Math.min(...i),o=(Math.max(...i)-l)/864e5;return o<=0?0:Math.pow(u/n,365.25/o)-1}(l,s),.3764):.3764,[l,s,c,e]),h=(0,r.useMemo)(()=>{let e=Number(u);return Number.isFinite(e)?e:null},[u]),m=(0,r.useMemo)(()=>{let e=Number(i);return Number.isFinite(e)?e:null},[i]),p=(0,r.useMemo)(()=>
2{if(l.length>0&&s>0){if(!l||0===l.length)return 0;let e=0,t=0,r=0;return l.forEach(a=>{let s="string"==typeof a.amount?parseFloat(a.amount):a.amount;"vault_deposit"===a.type?e+=s:"vault_withdraw"===a.type?t+=s:"derivative_balance_transfer"===a.type&&(r+=s)}),s+r-(e-t)}return 0},[l,s]);return{apr7d:d.isTestnet?.9125:h??g,apr:d.isTestnet?.8725:m??g,vaultEarned:p,transactions:l,isLoading:c}}],73111),e.s(["usePointsHistory",0,function(){let{setPointsHistory:e,setIsPointsHistoryLoading:t}=(0,a.useAuthStore)();return{fetchPointsHistory:async r=>{t(!0);try{let t=await (0,n.getPointsHistory)(r);e(r,t)}catch(e){console.error("Error fetching points history:",e)}finally{t(!1)}}}}],868873),e.s(["useBrokers",0,function({page:e=1,limit:s=100,enabled:n=!0}={}){let{setBrokers:u}=(0,a.useUserTradingDataStore)(),{infoClient:i}=(0,t.useInfoClient)(),{address:l,status:o}=(0,a.useAuthStore)(),[c,d]=(0,r.useState)(!1),[f,g]=(0,r.useState)(null),[h,m]=(0,r.useState)({page:1,limit:100,total_count:0,total_pages:1,has_next:!1,has_prev:!1}),p=(0,r.useCallback)(async(t,r)=>{try{d(!0);let a=t??e,n=r??s,o=await i.brokersCheck({user:l,page:a,limit:n});l&&u(l,o.data),m({page:o.page,limit:o.limit,total_count:o.total_count,total_pages:o.total_pages,has_next:o.has_next,has_prev:o.has_prev})}catch(e){console.error("Error fetching builders:",e),g("Failed to fetch builders")}finally{d(!1)}},[l,i,u]);return(0,r.useEffect)(()=>{l&&"disconnected"!==o&&n&&p(e,s)},[l,o,n,e,s,p]),{isLoading:c,error:f,fetchBrokers:p,pagination_meta:h}}],444714);let f=(e,t)=>e instanceof Error?e:Error(t);e.s(["useUserProfile",0,function(){let e=(0,a.useAuthStore)(e=>e.address),t=(0,a.useAuthStore)(t=>t.userProfile[e]),s=(0,a.useAuthStore)(e=>e.setUserProfile),[u,i]=(0,r.useState)(null),[l,c]=(0,r.useState)(!1),[d,g]=(0,r.useState)(!1),[h,m]=(0,r.useState)(!1),p=(0,r.useCallback)(async e=>{try{c(!0),i(null);let t=await (0,n.getUserProfile)(e),r=t.username?{user_address:(0,o.normalizeAddress)(t.user_address),username:t.username,avatar:"string"==typeof t.avatar?t.avatar:void 0,updated_at:"number"==typeof t.updated_at?t.updated_at:Date.now()}:null;return r&&s(r.user_address,r),t}catch(t){let e=f(t,"Failed to fetch user profile");throw i(e),e}finally{c(!1)}},[s]),y=(0,r.useCallback)(async e=>p({user_address:(0,o.normalizeAddress)(e)}),[p]),S=(0,r.useCallback)(async e=>p({username:e.replace(/^@+/,"")}),[p]);return{userProfile:t,fetchUserProfile:p,fetchUserProfileByAddress:y,fetchUserProfileByUsername:S,checkUsernameAvailable:(0,r.useCallback)(async e=>{try{return g(!0),i(null),await (0,n.usernameAvailable)(e)}catch(t){let e=f(t,"Failed to check username availability");throw i(e),e}finally{g(!1)}},[]),updateUsername:(0,r.useCallback)(async e=>{try{m(!0),i(null);let t=await (0,n.setUsername)(e),r=(0,o.normalizeAddress)(t.user_address);return s(r,{user_address:r,username:t.username,updated_at:Date.now()}),t}catch(t){let e=f(t,"Failed to set username");throw i(e),e}finally{m(!1)}},[s]),error:u,isFetchingProfile:l,isCheckingUsername:d,isSettingUsername:h,isLoading:l||d||h}}],839577),e.s([],929009)}]);
3
4//# debugId=35580611-61ce-7cc1-2552-0b5a21ec4bff
5//# sourceMappingURL=04da~.dwfk5ur.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.