1import{a as o,u as K,b as G,d as X,f as H,h as te,i as ae,k as q,n as ie,O as ce,o as B,j as e,A as k,t as re,p as W,q as oe,X as de,D as z,s as V,v as A,w as C,L as le,x as ue,y as me,z as xe,B as he,C as M,E as Y,F as fe,G as ve,H as $,I as O,J as D,N as ge,K as J,M as U,P as be,Q as pe,R as je,U as E,V as Ie,W as Ne,Y as ke,Z as Q,$ as ye,a0 as we,a1 as Z,a2 as Se,a3 as Pe,a4 as Te,a5 as F,l as Ae,a6 as Ce}from"./index-hZR_pMzJ.js";import{u as Ee,T as Be,P as Le}from"./TokenSelection-ChU_8IUJ.js";import{P as _e}from"./PoolItem-Y1gLJ2Im.js";import{u as $e}from"./epochs-DbkVI9Ll.js";import{C as ze}from"./Checkbox-BdWiQbp9.js";import"./PoolItemPosition-A3Raq0du.js";const ee=o.createContext(void 0);function Me({children:s,tokens:t,pool:n,refetch:i}){const[a,r]=o.useState(),[d,l]=o.useState(0n),[c,u]=o.useState(!1),[m,x]=o.useState(!1),{address:p}=K(),{data:j}=G(t),{data:g}=X(p,j,t),[h]=H(),y=o.useMemo(()=>{const T=h?.get("pos");if(!g||!n||!T)return;const _=BigInt(T);return g?.find(R=>R.chainId===n.chainId&&R.id===_)},[g,h,n]),[f,N]=o.useMemo(()=>[t.all[`${n.chainId}:${n.token0.toLowerCase()}`],t.all[`${n.chainId}:${n.token1.toLowerCase()}`]],[n,t]),I=te(),S=o.useMemo(()=>I||[],[t,I]),{data:v=[],refetch:b}=$e(n,t,1,0),{data:P}=ae(),L=v[0],{chain:se}=q(n.chainId);o.useEffect(()=>{const T=se.superchainConfig.defaultTokens.find(_=>ie(_));r(t[`${n.chainId}:${T}`])},[n.chainId]);const ne=o.useMemo(()=>ce===a?.address&&a?.chainId===B.id&&n.chainId!==B.id,[a,n]);return e.jsx(ee.Provider,{value:{tokens:t,pool:n,token:a,setToken:r,amount:d,setAmount:l,incentivizing:c,setIncentivizing:u,success:m,setSuccess:x,token0:f,token1:N,extraIncentiveTokens:S,currentEpoch:L,veStats:P,isBridge:ne,position:y,refetch:()=>{i(),b()}},children:a?s:null})}function w(){const s=o.useContext(ee);if(s===void 0)throw new Error("useBribeContext must be used within a BribeContextProvider");return s}function Oe(){const{currentEpoch:s,pool:t}=w();return s?.bribes?.length?e.jsxs("div",{className:"space-y-4 divide-y divide-accent-10 text-xs sm:text-sm",children:[e.jsx("div",{className:"font-semibold",children:"Current pool incentives"}),e.jsx("div",{className:"divide-y divide-accent-10",children:s.bribes.map(n=>e.jsx("div",{className:"py-4",children:e.jsx(k,{tokenAddress:n.token,chainId:t.chainId,amount:n.amount,showSymbol:!0,showValue:!0})},n.token))})]}):null}function De({steps:s,step:t,value:n,onChange:i,className:a}){return e.jsxs("div",{className:re("relative flex flex-col items-center",a),children:[e.jsx("input",{type:"range",value:n,onChange:r=>i(Number(r.target.value)),step:t,min:s[0].value,max:s.at(-1).value,className:"z-10 h-3 w-full cursor-pointer appearance-none rounded-full bg-transparent disabled:cursor-not-allowed"}),e.jsx("div",{className:"absolute left-0 top-1 h-1 w-full rounded-full bg-accent-20",children:e.jsx("div",{className:"pointer-events-none left-0 h-1 rounded-full bg-primary",style:{width:`${n/s.at(-1).value*100}%`}})}),e.jsx("div",{className:"relative h-[1em] w-full pt-1",children:s.map((r,d)=>e.jsx("button",{type:"button",onClick:()=>i(r.value),className:"absolute text-nowrap rounded-lg text-2xs text-accent-50 outline-none hover:text-foreground focus-visible:ring-2",style:{left:`${d/(s.length-1)*100}%`,translate:d===0?"0":d===s.length-1?"-100%":"-50%"},children:r.label},r.label))})]})}function Ue({position:s,percentage:t,setPercentage:n}){const{data:i}=W(),a=s.staked>0n,r=Number(t/100n),d=f=>n(BigInt(f*100));o.useEffect(()=>d(25),[]);const[l,c]=o.useMemo(()=>{if(!i)return[null,null];const f=s.chainId;return a?[i.all[`${f}:${f==z.id?oe:de}`],null]:[i.all[`${f}:${s.token0.address}`],i.all[`${f}:${s.token1.address}`]]},[s,i]),[u,m,x,p,j,g,h,y]=o.useMemo(()=>{if(!i)return[0n,0n,0n,0n,0n,0n,0n,0n];const f=V(a?s.emissions_earned:s.unstaked_earned0,l.decimals,0,r.toString()),N=a?0n:V(s.unstaked_earned1,c.decimals,0,r.toString());return[a?s.emissions_earned:s.unstaked_earned0,A(a?s.emissions_earned:s.unstaked_earned0,l.price??0n,l.decimals),a?0n:s.unstaked_earned1,a?0n:A(s.unstaked_earned1,c.price??0n,c.decimals),f,A(f,l.price??0n,l.decimals),N,A(N,c?.price??0n,c?.decimals)]},[r,s,a]);return!i||!s||!l?null:e.jsxs("div",{className:"flex flex-col pt-2",children:[e.jsxs("div",{className:"mb-8 flex flex-col gap-1 text-sm",children:[e.jsxs("div",{className:"font-semibold",children:["Incentivize with accrued ",a?"emissions":"trading fees"]}),e.jsxs("div",{className:"text-accent-50",children:["Use a share of ",a?"emissions":"trading fees"," that have accrued in your locked position as incentives."]})]}),e.jsx(De,{value:r,onChange:d,step:1,steps:[{label:"0%",value:0},{label:"25%",value:25},{label:"50%",value:50},{label:"75%",value:75},{label:"100%",value:100}]}),e.jsxs("div",{className:"mt-8 grid grid-cols-[auto_min-content_min-content] gap-x-6 gap-y-4 text-sm",children:[e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("div",{className:"font-semibold",children:"Total available"}),e.jsxs("div",{className:"text-accent-50",children:["Claimable ",a?"emissions":"trading fees"]})]}),e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("div",{className:"ml-1 text-end",children:e.jsx(k,{disableTooltip:!0,showLogo:!1,amount:u,tokenAddress:l.address,chainId:s.chainId,showSymbol:!0})}),e.jsx("div",{className:"ml-auto text-accent-50",children:e.jsx(C,{className:"text-sm",value:m})})]}),c?e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("div",{className:"ml-1 text-end",children:e.jsx(k,{disableTooltip:!0,showLogo:!1,amount:x,tokenAddress:c.address,chainId:s.chainId,showSymbol:!0})}),e.jsx("div",{className:"ml-auto text-accent-50",children:e.jsx(C,{className:"text-sm",value:p})})]}):e.jsx("div",{}),e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("div",{className:"font-semibold",children:"Incentive"}),e.jsx("div",{className:"text-accent-50",children:"Incentivize share"})]}),e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("div",{className:"text-end",children:e.jsx(k,{disableTooltip:!0,showLogo:!1,amount:j,tokenAddress:l.address,chainId:s.chainId,showSymbol:!0})}),e.jsx("div",{className:"ml-auto text-accent-50",children:e.jsx(C,{className:"text-sm",value:g})})]}),c?e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("div",{className:"text-end",children:e.jsx(k,{disableTooltip:!0,showLogo:!1,amount:h,tokenAddress:c.address,chainId:s.chainId,showSymbol:!0})}),e.jsx("div",{className:"ml-auto text-accent-50",children:e.jsx(C,{className:"text-sm",value:y})})]}):e.jsx("div",{})]})]})}function Re(){const{currentEpoch:s,pool:t,veStats:n}=w();return e.jsxs("div",{className:"divide-y divide-accent-10 text-xs sm:text-sm",children:[e.jsxs("div",{className:"flex justify-between py-4",children:[e.jsx("div",{className:"font-semibold",children:"Pool votes"}),e.jsx(k,{amount:s?.votes||0n,tokenAddress:t.emissions_token,chainId:t.chainId,showLogo:!1,plain:!0})]}),e.jsxs("div",{className:"flex justify-between py-4",children:[e.jsx("div",{className:"font-semibold",children:"Total new emissions"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(k,{amount:n?.emissions||0n,tokenAddress:n?.token,chainId:z.id,showSymbol:!0,testId:`${le}-emissions`})})]}),e.jsxs("div",{className:"flex justify-between py-4",children:[e.jsx("div",{className:"font-semibold",children:"Voting and incentives deadline"}),e.jsxs("div",{children:["ends in"," ",e.jsx(ue,{ts:Number(s?.ts||n?.epochStartedAt),deltaDays:7})]})]})]})}const Ve=[...$.map(s=>`${s}:eth`),...$.map(s=>`${s}:${be}`),...$.map(s=>`${s}:${Y}`)];function Fe(){const{tokens:s,pool:t,token:n,setToken:i,amount:a,setAmount:r,extraIncentiveTokens:d,token0:l,token1:c,incentivizing:u,setIncentivizing:m,position:x,success:p,isBridge:j}
1=w(),[g,h]=o.useState(!1),{balance:y}=me(n,{fetchInterval:xe}),{bridgeLimit:f,isLoading:N}=he({address:Y,chainId:B.id},t.chainId,M,void 0,!1,{enabled:j}),I=j&&f>=a,S=(y?.value??0n)>=a,v=a>0n&&n.listed&&(!j||I)&&g;return u?e.jsx(fe,{title:"Incentive amount",onEdit:p?void 0:()=>m(!1),children:e.jsx(k,{amount:a,tokenAddress:n.address,chainId:t.chainId,showValue:!0,showSymbol:!0})}):e.jsxs("div",{className:"space-y-5 rounded-2xl bg-gradient-to-b from-accent-0 to-background p-5 sm:space-y-8 sm:p-8",children:[e.jsx(Re,{}),e.jsx(Oe,{}),e.jsx(ze,{testId:"bribe-checkbox",checked:g,onChange:h,children:"I understand that once incentives are added, these are non-refundable and can NOT be withdrawn under any circumstances."}),g&&(x?e.jsx(Ue,{position:x,percentage:a,setPercentage:r}):e.jsxs("div",{className:"space-y-3",children:[e.jsx(ve,{assets:s.sorted||[],asset:n,setAsset:i,amount:a,setAmount:r,chain:t.chainId,testId:"briber-input",include:d,exclude:Ve,children:"Your Incentive"},"briber-input"),j&&!N&&!I&&e.jsxs("div",{className:"text-end text-xs font-semibold text-red",children:["Current bridging limit is"," ",e.jsx(k,{amount:f,showLogo:!1})]})]})),!n.listed&&e.jsx(O,{type:"error",icon:D,children:"The selected token is not whitelisted and can't be used for adding incentives. Change to a different token if you want to continue."}),e.jsxs("div",{className:"flex items-center gap-4 [&>*]:flex-1",children:[e.jsx(ge,{useButton:!0,size:"lg",color:"secondary",href:J(l,c),children:"Change pool"}),e.jsx(U,{size:"lg",disabled:!v||!S,onClick:()=>m(!0),"data-testid":"bribe-button","data-test-enabled":v,children:"Incentivize"})]})]})}function Ke(){return e.jsx("div",{className:"rounded-2xl bg-gradient-to-b from-accent-0 to-background p-5 sm:p-8",children:e.jsxs(O,{type:"error",icon:D,children:["The selected pool is currently not eligible",e.jsx("div",{className:"inline sm:block",children:" to receive any incentives."})]})})}function Ge({pool:s,token:t,amount:n,position:i,setTx:a,isBridge:r,onPendingStateChange:d,onError:l}){const{address:c}=pe(),u=M,{data:m}=je({bridge:r?u:void 0,originChain:t.chainId,destinationChain:s.chainId,recipient:c,amount:n});return i?e.jsx(E,{write:{chainId:i.chainId,address:i.locker,abi:Ie,functionName:"bribe",args:[Number(n)]},onSuccess:a,successMessage:"Incentives added",onPendingStateChange:d,onError:l,autoExecute:!0,children:"Incentivize"}):r?e.jsx(E,{write:{chainId:B.id,address:u,abi:Ne,functionName:"sendToken",args:[s.gauge,n,BigInt(s.chainId)],value:m,query:{enabled:n>0n&&!!m}},onSuccess:a,successMessage:`${t.symbol} incentive added`,onPendingStateChange:d,onError:l,autoExecute:!0,children:"Add Incentive"}):e.jsx(E,{write:{chainId:s.chainId,address:s.bribe,abi:ke(["function notifyRewardAmount(address, uint) external"]),functionName:"notifyRewardAmount",args:[t.address,n]},onSuccess:a,successMessage:`${t.symbol} incentive added`,onPendingStateChange:d,onError:l,autoExecute:!0,children:"Add Incentive"})}function Xe({setBribeTx:s}){const{pool:t,token:n,amount:i,setIncentivizing:a,success:r,isBridge:d,position:l}=w(),[c,u]=o.useState(!1),[m,x]=o.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx(Q,{title:r?"Incentive added":"Add incentive",success:r,loading:c,error:m,chainId:n?.chainId}),e.jsxs("div",{className:"flex items-center gap-4 [&>*]:flex-1",children:[e.jsx(U,{size:"lg",color:"secondary",onClick:()=>a(!1),children:r?"New incentive":"Edit amount"}),!r&&e.jsx(Ge,{pool:t,position:l,token:n,amount:i,setTx:s,isBridge:d,onPendingStateChange:u,onError:x})]})]})}function He(){const{pool:s,refetch:t,setIncentivizing:n}=w(),{chain:i,isCanonical:a}=q(s.chainId),[r,d]=o.useState(),[l,c]=o.useState(!1),[u,m]=o.useState(void 0);return e.jsxs(e.Fragment,{children:[e.jsx(Q,{title:r?"Gauge created":"Create gauge for this pool",success:!!r,loading:l,error:u,chainId:s.chainId}),e.jsxs("div",{className:"flex items-center gap-4 [&>*]:flex-1",children:[e.jsx(U,{size:"lg",color:"secondary",onClick:()=>n(!1),children:"Edit amount"}),a&&e.jsx(E,{write:{chainId:i.id,address:we,abi:ye,functionName:"createGauge",args:[s.factory,s.address],query:{enabled:a}},onSuccess:x=>{d(x),t()},onPendingStateChange:c,onError:m,autoExecute:!0,children:"Create gauge"})]})]})}function qe(){const{token:s,amount:t,pool:n,setIncentivizing:i,setSuccess:a,isBridge:r,position:d}=w(),[l,c]=o.useState(),[u,m]=o.useState(!!d),x=n.gauge!=Z,p=Se(s,r?M:n.bribe,t);return o.useEffect(()=>{a(!!l)},[l]),e.jsx("div",{className:"-m-px rounded-[17px] bg-gradient-to-b from-primary/50 to-background p-px",children:e.jsxs("div",{className:"space-y-4 rounded-2xl bg-gradient-to-b from-accent-0 to-background p-5 sm:p-8",children:[!x&&e.jsx(He,{}),x&&!p.approved&&!u&&e.jsx(Pe,{approval:p,onEdit:()=>i(!1),onSuccess:()=>m(!0)}),x&&(p.approved||u)&&e.jsx(Xe,{setBribeTx:c})]})})}function We(){const{pool:s,token0:t,token1:n,incentivizing:i}=w();return e.jsxs("div",{className:"mx-auto max-w-screen-sm space-y-2",children:[e.jsx(Te,{title:"Incentivize pool",pool:s,changeUrl:J(t,n)}),s.gauge==Z||s.gauge_alive?e.jsx(Fe,{}):e.jsx(Ke,{}),i&&e.jsx(qe,{})]})}function ns(){const{address:s}=K(),{data:t,error:n}=W(),{data:i,error:a,refetch:r}=G(t,{allPools:!1}),[d,l]=o.useState();o.useEffect(()=>{(n||a)&&toast.error(n||a)},[n,a]);const{token0:c,token1:u,setTokens:m}=Ee(),[x,,p]=H(),j=x.get("pool")?.toLowerCase(),g=Number(x.get("chain0")??x.get("chain")??z.id),h=o.useMemo(()=>(i?.[g]||[]).find(v=>v.address.toLowerCase()===j),[i,j,c,u,g]),{data:y=[],isPending:f}=X(s,i,t),N=o.useMemo(()=>
1{if(!c||!u)return[];const v=[c,u].map(b=>(b.wrappedAddress||b.address).toLowerCase());return i?.[g]?.filter(b=>{const P=d==="basic"?F.basic(b.type):F.concentrated(b.type);return v.includes(b.token0.toLowerCase())&&v.includes(b.token1.toLowerCase())&&(!d||P)})},[i,c,u,d,g]);o.useEffect(()=>{if(h&&t&&(!c||!c)){const v=h.token0.toLowerCase(),b=h.token1.toLowerCase(),P=t[`${h.chainId}:${v}`],L=t[`${h.chainId}:${b}`];m({token0:P,token1:L,preserveParams:!0})}},[h,t]);const I=Ae.isEmpty(i)||f,S=!c||!u||!h;return e.jsxs("div",{children:[I&&e.jsx(Ce,{message:"Loading onchain data..."}),!I&&S&&e.jsxs("div",{className:"mx-auto max-w-screen-sm space-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-5 overflow-hidden rounded-2xl bg-gradient-to-b from-accent-0 to-background p-5 sm:gap-8 sm:p-8",children:[e.jsx("h2",{className:"flex items-center gap-2 border-b border-accent-10 pb-3 text-lg font-semibold sm:pb-5 sm:text-xl",children:"Incentivize pool"}),e.jsx(Be,{token0:c,token1:u,token0Label:"Token you want to incentivize",setTokens:m}),c&&u&&e.jsx(Le,{poolType:d,setPoolType:l}),e.jsxs(O,{type:"error",icon:D,children:[e.jsx("strong",{children:"Warning:"})," The incentivize feature is mainly used by protocols. Make sure you know how it works before using it as any transaction is final and cannot be reverted."]})]}),c&&u&&N&&e.jsx("div",{className:"space-y-4",children:N.map(v=>e.jsx(_e,{pool:v,showPositions:!1,positions:y.filter(b=>v.superchainKey===b.pool.superchainKey),targetUrl:`/incentivize?${p({pool:v.address.toLowerCase()},{preserveParams:!0})}`,buttonText:"Add incentive"},v.superchainKey))})]}),!I&&!S&&h&&t&&e.jsx(Me,{tokens:t,pool:h,refetch:r,children:e.jsx(We,{})})]})}export{ns as default};
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.