@oakagentkit/core 0.1.0 → 0.1.2
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/build/dist/api/addresses.d.ts +1 -1
- package/build/dist/api/addresses.js +1 -1
- package/build/dist/api/amounts.js +1 -1
- package/build/dist/api/args.d.ts +19 -0
- package/build/dist/api/args.js +1 -0
- package/build/dist/api/canonical.js +1 -1
- package/build/dist/api/chain.js +1 -1
- package/build/dist/api/errors.d.ts +1 -0
- package/build/dist/api/errors.js +1 -1
- package/build/dist/api/gas.d.ts +5 -0
- package/build/dist/api/gas.js +1 -0
- package/build/dist/api/grandfather.js +1 -1
- package/build/dist/api/history.js +1 -1
- package/build/dist/api/http.js +1 -1
- package/build/dist/api/identity-link.js +1 -1
- package/build/dist/api/merkle.js +1 -1
- package/build/dist/api/metadata.js +1 -1
- package/build/dist/api/module.js +1 -1
- package/build/dist/api/modules/beefy/index.js +1 -1
- package/build/dist/api/modules/clanker/index.js +1 -1
- package/build/dist/api/modules/erc8004/index.d.ts +11 -0
- package/build/dist/api/modules/erc8004/index.js +1 -1
- package/build/dist/api/modules/grove/index.js +1 -1
- package/build/dist/api/modules/heyresearch/index.js +1 -1
- package/build/dist/api/modules/hoodag/index.js +1 -1
- package/build/dist/api/modules/hoodlock/airdrop.js +1 -1
- package/build/dist/api/modules/hoodlock/index.js +1 -1
- package/build/dist/api/modules/hoodlock/locks-burn.js +1 -1
- package/build/dist/api/modules/hookr/create-cancel.d.ts +2 -2
- package/build/dist/api/modules/hookr/create-cancel.js +1 -1
- package/build/dist/api/modules/hookr/fill-bounty.js +1 -1
- package/build/dist/api/modules/hookr/index.js +1 -1
- package/build/dist/api/modules/kyberswap/index.js +1 -1
- package/build/dist/api/modules/lighter/index.js +1 -1
- package/build/dist/api/modules/longbow/index.d.ts +4 -2
- package/build/dist/api/modules/longbow/index.js +1 -1
- package/build/dist/api/modules/meridian/index.js +1 -1
- package/build/dist/api/modules/meridian/markets.js +1 -1
- package/build/dist/api/modules/meridian/rfq.js +1 -1
- package/build/dist/api/modules/merkl/index.js +1 -1
- package/build/dist/api/modules/morpho/index.d.ts +1 -1
- package/build/dist/api/modules/morpho/index.js +2 -2
- package/build/dist/api/modules/netnet/index.js +1 -1
- package/build/dist/api/modules/orbio/index.js +1 -1
- package/build/dist/api/modules/pons/claim.js +1 -1
- package/build/dist/api/modules/pons/index.js +1 -1
- package/build/dist/api/modules/pons/launch-status.js +1 -1
- package/build/dist/api/modules/pons/prices.js +1 -1
- package/build/dist/api/modules/pons/trade.d.ts +3 -1
- package/build/dist/api/modules/pons/trade.js +1 -1
- package/build/dist/api/modules/poolstrade/index.js +1 -1
- package/build/dist/api/modules/priors/index.js +1 -1
- package/build/dist/api/modules/relay/inbound.d.ts +2 -0
- package/build/dist/api/modules/relay/inbound.js +1 -1
- package/build/dist/api/modules/relay/index.js +1 -1
- package/build/dist/api/modules/relay/outbound-status.js +1 -1
- package/build/dist/api/modules/spark/index.js +1 -1
- package/build/dist/api/modules/steakhouse/index.js +1 -1
- package/build/dist/api/modules/tickerspring/index.js +1 -1
- package/build/dist/api/modules/uniswap/index.js +1 -1
- package/build/dist/api/modules/uniswap/v3.js +1 -1
- package/build/dist/api/modules/uniswap/v4.js +1 -1
- package/build/dist/api/modules/velora/index.js +1 -1
- package/build/dist/api/positions.js +1 -1
- package/build/dist/api/pricenote.js +1 -1
- package/build/dist/api/prices.js +1 -1
- package/build/dist/api/pricing.d.ts +5 -1
- package/build/dist/api/pricing.js +1 -1
- package/build/dist/api/routes.js +1 -1
- package/build/dist/api/secret-fields.js +1 -1
- package/build/dist/api/send.d.ts +45 -0
- package/build/dist/api/send.js +1 -0
- package/build/dist/api/simulate.js +1 -1
- package/build/dist/api/swap.d.ts +6 -1
- package/build/dist/api/swap.js +1 -1
- package/build/dist/api/tokens.js +1 -1
- package/build/dist/api/tool-policy.d.ts +1 -0
- package/build/dist/api/tool-policy.js +1 -1
- package/build/dist/api/tx.js +1 -1
- package/build/dist/api/types.d.ts +13 -0
- package/build/dist/api/untrusted.js +1 -1
- package/build/dist/api/vendor-limits.js +1 -1
- package/build/dist/chunks/2IRORNOH.js +1 -0
- package/build/dist/chunks/{YTHDLCHL.js → 3PA2XT75.js} +1 -1
- package/build/dist/chunks/52TGAWSI.js +1 -0
- package/build/dist/chunks/{OOSNTGDJ.js → 66DWJWDA.js} +1 -1
- package/build/dist/chunks/{ZKOMJGNH.js → 6SYTB6FB.js} +1 -1
- package/build/dist/chunks/73EABRFC.js +1 -0
- package/build/dist/chunks/{VZWOWR6G.js → A5ITAEUQ.js} +1 -1
- package/build/dist/chunks/A5KSG6LW.js +1 -0
- package/build/dist/chunks/{JMPOXXNJ.js → B4FOHEBE.js} +1 -1
- package/build/dist/chunks/B4MLWDPM.js +1 -0
- package/build/dist/chunks/{D45AODDL.js → BHR46XNW.js} +1 -1
- package/build/dist/chunks/{YEE3KKTA.js → BOFA26WU.js} +1 -1
- package/build/dist/chunks/CQNZWL7F.js +1 -0
- package/build/dist/chunks/GDP4JSAX.js +1 -0
- package/build/dist/chunks/{P7Q6MJZH.js → GIBF3YJO.js} +1 -1
- package/build/dist/chunks/GN4QZ4JA.js +1 -0
- package/build/dist/chunks/{B5RZYFQC.js → I5CQ64EU.js} +1 -1
- package/build/dist/chunks/ICCJ3TOO.js +1 -0
- package/build/dist/chunks/{XN4WDN3O.js → JXOEJPJ4.js} +1 -1
- package/build/dist/chunks/{47PKSOXA.js → KL5YE7JA.js} +1 -1
- package/build/dist/chunks/KVVTKM6E.js +1 -0
- package/build/dist/chunks/{UL2L7NHO.js → M6JGTQRY.js} +1 -1
- package/build/dist/chunks/{ZUAXW2ZD.js → MK6L6TGI.js} +1 -1
- package/build/dist/chunks/{KFMNCJXJ.js → MOVRI5IV.js} +1 -1
- package/build/dist/chunks/NA7HV7BR.js +1 -0
- package/build/dist/chunks/NGAI6GTU.js +1 -0
- package/build/dist/chunks/{UZH4FQEL.js → OBX7IZG5.js} +1 -1
- package/build/dist/chunks/{KP7VSXIQ.js → OSQ4AAM2.js} +1 -1
- package/build/dist/chunks/{75D6Q7L3.js → OWEUVFB6.js} +1 -1
- package/build/dist/chunks/{LZK6C5LT.js → P4G3EKF7.js} +1 -1
- package/build/dist/chunks/{IABIXUNX.js → QGDHMVPE.js} +1 -1
- package/build/dist/chunks/{VZPFBWVH.js → SJ7HDRI4.js} +1 -1
- package/build/dist/chunks/SPAKOCR7.js +1 -0
- package/build/dist/chunks/T6O2L6HF.js +1 -0
- package/build/dist/chunks/TEVKPJV5.js +1 -0
- package/build/dist/chunks/UCMNB2UP.js +1 -0
- package/build/dist/chunks/{64EN6Y7E.js → Y3P6SUNL.js} +1 -1
- package/build/dist/chunks/YX4NVVSX.js +1 -0
- package/build/dist/chunks/ZUC6ILK2.js +1 -0
- package/package.json +9 -13
- package/build/dist/chunks/24JYIH53.js +0 -1
- package/build/dist/chunks/25EOXUBI.js +0 -1
- package/build/dist/chunks/4P6XI564.js +0 -1
- package/build/dist/chunks/6YU3JLQQ.js +0 -1
- package/build/dist/chunks/AE6YEEZP.js +0 -1
- package/build/dist/chunks/BH3CI6WO.js +0 -1
- package/build/dist/chunks/CUBRTOMA.js +0 -1
- package/build/dist/chunks/FSSCJNAQ.js +0 -1
- package/build/dist/chunks/MGEJPRXP.js +0 -1
- package/build/dist/chunks/S3YSJ7XH.js +0 -1
- package/build/dist/chunks/SGDWO7XI.js +0 -1
- package/build/dist/chunks/T5E4OJEU.js +0 -1
- package/build/dist/chunks/VBV366XQ.js +0 -1
- package/build/dist/chunks/XUL6NKAK.js +0 -1
- package/build/dist/chunks/ZERWRK6X.js +0 -1
package/build/dist/api/swap.d.ts
CHANGED
|
@@ -69,10 +69,12 @@ export interface SwapQuote extends Quote {
|
|
|
69
69
|
oakFee?: DecimalString;
|
|
70
70
|
feeDisclosure?: string;
|
|
71
71
|
ponsCurveToken?: Address;
|
|
72
|
+
ponsPoolToken?: Address;
|
|
72
73
|
blockNumber?: DecimalString;
|
|
73
74
|
calldataMinAmountOut?: DecimalString;
|
|
74
75
|
expectedSpend?: DecimalString;
|
|
75
76
|
expectedRefund?: DecimalString;
|
|
77
|
+
priceImpact?: 'available' | 'unavailable';
|
|
76
78
|
priceImpactBps?: string | null;
|
|
77
79
|
priceImpactWarning?: string;
|
|
78
80
|
}
|
|
@@ -107,7 +109,10 @@ export declare function assertQuoteBinding(quote: SwapQuote, accepted: SwapQuote
|
|
|
107
109
|
export declare function resolveNowSeconds(now?: () => number): number;
|
|
108
110
|
export declare function isNativeToken(token: Address): boolean;
|
|
109
111
|
export declare function computeMinAmountOut(amountOut: DecimalString, slippageBps?: number): DecimalString;
|
|
110
|
-
export declare
|
|
112
|
+
export declare const MAX_VELORA_FEE_BPS = 200;
|
|
113
|
+
export declare function veloraVenueFeeBps(percent: unknown): number;
|
|
114
|
+
export declare function veloraCalldataMinimum(net: DecimalString, feeBps?: number): bigint;
|
|
115
|
+
export declare function assertVeloraPartnerAndFee(word: bigint, feeBps: number): void;
|
|
111
116
|
export declare function formatVenueFeeDisclosure(params: {
|
|
112
117
|
provider?: string;
|
|
113
118
|
venueFee: DecimalString;
|
package/build/dist/api/swap.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y}from"../chunks/
|
|
1
|
+
import{A,B,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"../chunks/2IRORNOH.js";import"../chunks/GDP4JSAX.js";import"../chunks/LIUXNOLP.js";import"../chunks/Y3P6SUNL.js";import"../chunks/GIBF3YJO.js";import"../chunks/A5ITAEUQ.js";import"../chunks/I5CQ64EU.js";import"../chunks/5HCXZWUH.js";import"../chunks/M6JGTQRY.js";import"../chunks/ZUC6ILK2.js";import"../chunks/B4MLWDPM.js";import"../chunks/NGAI6GTU.js";import"../chunks/JXOEJPJ4.js";export{b as DEFAULT_SLIPPAGE_BPS,h as ExpiredQuoteError,i as MAX_RECENT_QUOTES,p as MAX_VELORA_FEE_BPS,e as NATIVE_ETH_ADDRESS,g as NoRouteError,c as PRICE_IMPACT_WARNING_BPS,a as QUOTE_TTL_SECONDS,f as ZERO_ADDRESS,x as assertCalldataMinAmountOut,l as assertQuoteBinding,y as assertSwapTransaction,s as assertVeloraPartnerAndFee,B as buildSwapFromQuote,o as computeMinAmountOut,j as copyQuote,w as decodeSwapMinAmountOut,u as encodeKyberSwapData,v as encodeVeloraSwapData,t as formatVenueFeeDisclosure,A as getQuote,n as isNativeToken,z as normalizeQuote,d as ponsCurveSwapAbi,m as resolveNowSeconds,k as snapshotQuote,r as veloraCalldataMinimum,q as veloraVenueFeeBps};
|
package/build/dist/api/tokens.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"../chunks/
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k,l,m}from"../chunks/MOVRI5IV.js";import"../chunks/YX4NVVSX.js";import"../chunks/BHR46XNW.js";import"../chunks/73EABRFC.js";import"../chunks/2IRORNOH.js";import"../chunks/GDP4JSAX.js";import"../chunks/LIUXNOLP.js";import"../chunks/MK6L6TGI.js";import"../chunks/Y3P6SUNL.js";import"../chunks/GIBF3YJO.js";import"../chunks/UCMNB2UP.js";import"../chunks/Z25UKUJF.js";import"../chunks/A5ITAEUQ.js";import"../chunks/I5CQ64EU.js";import"../chunks/NA7HV7BR.js";import"../chunks/5HCXZWUH.js";import"../chunks/M6JGTQRY.js";import"../chunks/ZUC6ILK2.js";import"../chunks/B4MLWDPM.js";import"../chunks/NGAI6GTU.js";import"../chunks/JXOEJPJ4.js";export{j as MULTICALL3_ABI,b as NATIVE_ETH_TOKEN,a as STOCK_ASSETS_URL,e as USDE_TOKEN,c as USDG_TOKEN,d as WETH_TOKEN,h as assertOfficialStockIdentity,i as fetchOfficialStockTokens,l as findToken,k as getBalances,f as parseOfficialStockAssets,m as resolveQuoteToken,g as verifyOfficialStockToken};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{a,b}from"../chunks/ICCJ3TOO.js";export{b as COMING_SOON,a as isReadDiscovery};
|
package/build/dist/api/tx.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e}from"../chunks/
|
|
1
|
+
import{a,b,c,d,e}from"../chunks/A5ITAEUQ.js";import"../chunks/I5CQ64EU.js";import"../chunks/NGAI6GTU.js";import"../chunks/JXOEJPJ4.js";export{c as approval,a as assertAddress,d as deposit,e as redeemAll,b as unsignedTx};
|
|
@@ -41,14 +41,27 @@ export type ProjectStep = {
|
|
|
41
41
|
export type ActionResult = {
|
|
42
42
|
txs: UnsignedTx[];
|
|
43
43
|
summary: string;
|
|
44
|
+
hashes?: string[];
|
|
45
|
+
status?: 'mined';
|
|
44
46
|
} | {
|
|
45
47
|
steps: ProjectStep[];
|
|
46
48
|
continuation?: Record<string, unknown>;
|
|
47
49
|
summary: string;
|
|
48
50
|
};
|
|
51
|
+
export interface SenderTransaction {
|
|
52
|
+
hash: string;
|
|
53
|
+
chainId: number;
|
|
54
|
+
to: Address;
|
|
55
|
+
role: 'approval' | 'permit2_approval' | 'revoke' | 'wrap' | 'action';
|
|
56
|
+
token?: Address;
|
|
57
|
+
spender?: Address;
|
|
58
|
+
amount?: DecimalString;
|
|
59
|
+
}
|
|
49
60
|
export interface SenderResult {
|
|
50
61
|
hashes: string[];
|
|
62
|
+
transactions?: SenderTransaction[];
|
|
51
63
|
summary: string;
|
|
64
|
+
status?: 'submitted' | 'mined' | 'final' | 'not_submitted';
|
|
52
65
|
}
|
|
53
66
|
export type ToolResponse<T = unknown> = {
|
|
54
67
|
ok: true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c}from"../chunks/
|
|
1
|
+
import{a,b,c}from"../chunks/JXOEJPJ4.js";export{c as confusableSkeleton,b as hasUnsafeText,a as untrustedText};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c}from"../chunks/
|
|
1
|
+
import{a,b,c}from"../chunks/Y3P6SUNL.js";import"../chunks/NGAI6GTU.js";import"../chunks/JXOEJPJ4.js";export{a as VendorBusyError,b as vendorBudget,c as vendorBusy};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as F}from"./GDP4JSAX.js";import{c as j}from"./Y3P6SUNL.js";import{a as w,b as X,c as ae}from"./A5ITAEUQ.js";import{a as r,d as re}from"./I5CQ64EU.js";import{A as R,B as ne,C as oe,a as h,i as D,z as G}from"./ZUC6ILK2.js";import{a as o}from"./NGAI6GTU.js";import{decodeAbiParameters as B,decodeFunctionData as y,encodeAbiParameters as Q,encodeFunctionData as L,parseAbi as z,parseAbiParameters as J}from"viem";var ve=60,q=50,_e=200,ce=z(["function buy(uint256 quoteIn,uint256 minTokensOut,address recipient) payable returns (uint256)","function sell(uint256 tokensIn,uint256 minQuoteOut,address recipient) returns (uint256)"]),Se="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",N="0x0000000000000000000000000000000000000000",M=D[4663].routes.kyberswap.address,V=D[4663].routes.velora.address,ee=G[4663].kyberswap.toLowerCase(),le=G[4663].velora.toLowerCase(),be="0x0000000000000000000000000000000000000000000000000000000000000000",H=z(["function swap((address callTarget, address approveTarget, bytes targetData, (address srcToken, address dstToken, address[] srcReceivers, uint256[] srcAmounts, address[] feeReceivers, uint256[] feeAmounts, address dstReceiver, uint256 amount, uint256 minReturnAmount, uint256 flags, bytes permit) desc, bytes clientData) execution) payable returns (uint256 returnAmount, uint256 gasUsed)"]),K=z(["function swapExactAmountIn(address executor, (address srcToken, address destToken, uint256 fromAmount, uint256 toAmount, uint256 quotedAmount, bytes32 metadata, address beneficiary) swapData, uint256 partnerAndFee, bytes permit, bytes executorData) payable returns (uint256 receivedAmount, uint256 submittedAmount, uint256 augustusFeeAmount)"]),C=class extends o{name="NoRouteError";constructor(t="No swap route is available for this token pair and amount."){super(t)}},P=class extends o{name="ExpiredQuoteError";constructor(t="Quote has expired. Request a fresh quote."){super(t)}},Oe=1e3,S=new Map;function me(e){for(let[t,n]of S)BigInt(e)>=r(n.expiresAt)&&S.delete(t)}function Y(e){return{...e,...e.txs?{txs:e.txs.map(t=>({...t}))}:{}}}function se(e){let t=Y(e);return t.txs&&(t.txs.forEach(Object.freeze),Object.freeze(t.txs)),Object.freeze(t)}var xe=["router","from","to","wallet","amountIn","amountOut","minAmountOut","expiresAt","chainId","spender","value","ponsCurveToken","ponsPoolToken","blockNumber","calldataMinAmountOut","expectedSpend","expectedRefund"];function $(e,t,n=!1){for(let i of xe)if(!(i==="expiresAt"&&n&&r(e.expiresAt)<=r(t.expiresAt))&&e[i]!==void 0&&String(e[i]).toLowerCase()!==String(t[i]).toLowerCase())throw new o(`Quote ${i} does not match the accepted quote.`)}function U(e=Date.now){let t=e();if(!Number.isFinite(t)||t<0)throw new o("Clock must return a non-negative timestamp.");return t>1e11?Math.floor(t/1e3):Math.floor(t)}function O(e){let t=e.toLowerCase();return t===Se.toLowerCase()||t===N.toLowerCase()}function Ie(e,t=q){if(!Number.isInteger(t)||t<0||t>=1e4)throw new o("Slippage must be an integer from 0 to 9999 bps.");return re(e,String(1e4-t),"10000","floor")}var ye=200;function Me(e){if(typeof e!="number"||!Number.isFinite(e)||!/^\d+(?:\.\d{1,2})?$/.test(String(e)))throw new o("Velora returned an unsupported venue fee. Request a fresh quote.");let[t,n=""]=String(e).split("."),i=Number(t)*100+Number(n.padEnd(2,"0"));return te(i),i}function te(e){if(!Number.isInteger(e)||e<0||e>ye)throw new o("Velora returned an unsupported venue fee. Request a fresh quote.")}function pe(e,t=1){return te(t),r(e)*10000n/BigInt(1e4-t)+1n}function ke(e,t){te(t);let n=e>>96n,i=ne>>96n,a=0x3fffn,c=1n<<92n,u=e&(1n<<96n)-1n;if(n!==i&&!(n===0n&&t===0)||(u&a)!==BigInt(t)||(u&~(c|a))!==0n)throw new o("Velora partnerAndFee must match the accepted venue fee and recipient.")}function fe(e){if(e.oakFee!==void 0&&r(e.oakFee)!==0n)throw new o("Oak charges 0 swap fee; venue fees must never be counted as Oak income.");let t=e.provider??"venue";return`Venue fee: ${e.venueFee} base units (${e.venueFeeBps} bps) retained by ${t}; Oak swap fee: 0 (venue fee is never Oak income).`}function De(e){w(e.from),w(e.to),w(e.wallet);let t=e.callTarget??R[h].kyberswap.address,n=e.approveTarget??N;w(t),w(n);let i=r(e.amountIn),a=r(e.minAmountOut);return L({abi:H,functionName:"swap",args:[{callTarget:t,approveTarget:n,targetData:e.targetData??"0x",desc:{srcToken:e.from,dstToken:e.to,srcReceivers:O(e.from)?[]:[t],srcAmounts:O(e.from)?[]:[i],feeReceivers:[],feeAmounts:[],dstReceiver:e.wallet,amount:i,minReturnAmount:a,flags:0n,permit:"0x"},clientData:e.clientData??"0x"}]})}function Ce(e){w(e.from),w(e.to),w(e.wallet);let t=e.executor??R[h].velora.address;return w(t),L({abi:K,functionName:"swapExactAmountIn",args:[t,{srcToken:e.from,destToken:e.to,fromAmount:r(e.amountIn),toAmount:r(e.minAmountOut),quotedAmount:r(e.amountOut),metadata:e.metadata??be,beneficiary:e.wallet},e.partnerAndFee??0n,"0x",e.executorData??"0x"]})}var ie=z(["function execute(bytes commands,bytes[] inputs,uint256 deadline) payable"]),ue=J("((address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks) poolKey,bool zeroForOne,uint128 amountIn,uint128 amountOutMinimum,uint256 minHopPriceX36,bytes hookData)"),de=J("bytes,bytes[]"),_=J("address,uint256");function Z(e){let t=y({abi:ie,data:e}),[n,i,a]=t.args;if(n!=="0x10"||i.length!==1||L({abi:ie,...t}).toLowerCase()!==e.toLowerCase())throw new o("Pons router must contain one canonical v4 swap command.");let[c,u]=B(de,i[0]);if(c!=="0x060c0f"||u.length!==3||Q(de,[c,u]).toLowerCase()!==i[0].toLowerCase())throw new o("Pons router actions must swap, settle the exact input and take all output to the sender.");let m=B(ue,u[0])[0],A=B(_,u[1]),d=B(_,u[2]);if(Q(ue,[m]).toLowerCase()!==u[0].toLowerCase()||Q(_,A).toLowerCase()!==u[1].toLowerCase()||Q(_,d).toLowerCase()!==u[2].toLowerCase()||m.hookData!=="0x"||m.minHopPriceX36!==0n||A[0].toLowerCase()!==(m.zeroForOne?m.poolKey.currency0:m.poolKey.currency1).toLowerCase()||A[1]!==m.amountIn||d[0].toLowerCase()!==(m.zeroForOne?m.poolKey.currency1:m.poolKey.currency0).toLowerCase()||d[1]!==m.amountOutMinimum)throw new o("Pons router settlement and receipt must match the single swap.");return{swap:m,deadline:a}}function Te(e){if(typeof e!="string"||!/^0x([0-9a-fA-F]{2})+$/.test(e)||e.length<10)throw new o("Swap calldata must contain a 4-byte function selector.");let t=e.slice(0,10).toLowerCase();if(t===ee)return y({abi:H,data:e}).args[0].desc.minReturnAmount;if(t===le)return y({abi:K,data:e}).args[1].toAmount;if(t==="0x3593564c")return Z(e).swap.amountOutMinimum;let n=y({abi:ce,data:e});if(n.functionName==="buy"||n.functionName==="sell")return n.args[1];throw new o(`Unsupported swap router selector ${t}.`)}function we(e,t,n=!1){let i=r(t),a=Te(e);if(a<=0n||i<=0n||a!==i&&!(n&&(a>i||e.slice(0,10).toLowerCase()===ee&&a+1n===i)))throw new o(`Built swap calldata minimum output (${a}) does not match the accepted quote minimum (${i}).`);return a}function Ae(e,t){let{from:n,to:i,wallet:a,amountIn:c}=t;if(!n||!i||!a||c===void 0)throw new o("Accepted quote must include input, output, amount and wallet.");for(let s of[n,i,a,t.router,e.to])w(s);let u=(s,l,g)=>{if(s.toLowerCase()!==l.toLowerCase())throw new o(`Built swap ${g} does not match the accepted quote.`)};if(u(e.to,t.router,"router"),e.chainId!==(t.chainId??h))throw new o("Built swap chain does not match the accepted quote.");let m=O(n)?r(c):0n;if(r(e.value)!==m||t.value!==void 0&&r(t.value)!==m)throw new o("Built swap value does not match the accepted quote input.");let A=e.data.slice(0,10).toLowerCase(),d=t.router.toLowerCase(),f;if(d===M.toLowerCase()&&A===ee){u(t.spender??t.router,M,"spender");let s=y({abi:H,data:e.data});if(L({abi:H,...s}).toLowerCase()!==e.data.toLowerCase())throw new o("KyberSwap calldata must be canonically decodable.");let{callTarget:l,approveTarget:g,desc:p}=s.args[0];u(l,R[h].kyberswap.address,"executor"),u(g,N,"executor approval target");let v=O(n);if(p.srcReceivers.length!==(v?0:1)||p.srcAmounts.length!==(v?0:1)||!v&&(p.srcReceivers[0].toLowerCase()!==l.toLowerCase()||p.srcAmounts[0]!==r(c)))throw new o("KyberSwap source transfers must send the exact input to the pinned executor.");if(p.feeReceivers.length||p.feeAmounts.length||p.flags!==0n&&p.flags!==512n||p.permit!=="0x")throw new o("KyberSwap fee recipients, fee amounts, flags and permit must match the pinned zero-fee policy.");f={from:p.srcToken,to:p.dstToken,wallet:p.dstReceiver,amount:p.amount}}else if(d===V.toLowerCase()&&A===le){u(t.spender??t.router,V,"spender");let s=y({abi:K,data:e.data});if(L({abi:K,...s}).toLowerCase()!==e.data.toLowerCase())throw new o("Velora calldata must be canonically decodable.");let[l,g,p,v]=s.args;if(!oe.some(T=>T.toLowerCase()===l.toLowerCase()))throw new o("Built swap executor does not match the accepted quote.");if(v!=="0x")throw new o("Velora permit must match the pinned empty-permit policy.");if((t.calldataMinAmountOut!==void 0||p!==0n)&&ke(p,t.venueFeeBps??0),t.calldataMinAmountOut!==void 0&&r(t.calldataMinAmountOut)!==pe(t.minAmountOut,t.venueFeeBps??1))throw new o("Velora calldata minimum must cover the accepted net output, venue fee and router dust.");if(t.calldataMinAmountOut!==void 0&&(g.quotedAmount!==r(t.grossAmountOut??"0")||g.quotedAmount<r(t.calldataMinAmountOut)))throw new o("Velora quoted gross output must match the accepted quote and cover its calldata minimum.");if(p!==0n&&t.calldataMinAmountOut===void 0)throw new o("Velora venue fee requires a fee-adjusted calldata minimum.");f={from:g.srcToken,to:g.destToken,wallet:g.beneficiary,amount:g.fromAmount}}else if(t.provider==="pons"&&t.ponsPoolToken){if(u(t.router,D[h].ponsTrade.universal_router.address,"Pons router"),u(t.spender??t.router,D[h].ponsTrade.permit2.address,"Pons spender"),!t.data)throw new o("Pons pool quote must include locally reconstructed calldata.");let{swap:s,deadline:l}=Z(e.data),g=Z(t.data),p=O(n);if(u(s.poolKey.currency0,N,"pool native currency"),u(s.poolKey.currency1,t.ponsPoolToken,"pool token"),u(s.poolKey.hooks,D[h].pons.memeHook.address,"pool hook"),s.zeroForOne!==p||!O(p?n:i)||s.poolKey.fee!==g.swap.poolKey.fee||s.poolKey.tickSpacing!==g.swap.poolKey.tickSpacing||l!==g.deadline)throw new o("Pons pool direction, parameters or deadline differ from the accepted quote.");u(p?i:n,t.ponsPoolToken,"pool token"),f={from:n,to:i,wallet:a,amount:s.amountIn}}else if(t.provider==="pons"&&t.ponsCurveToken){let s=y({abi:ce,data:e.data}),l=O(n);if(s.functionName!==(l?"buy":"sell")||!O(l?n:i))throw new o("Pons curve direction does not match the accepted quote.");u(l?i:n,t.ponsCurveToken,"curve token"),u(t.spender??t.router,t.router,"curve spender"),f={from:n,to:i,wallet:s.args[2],amount:s.args[0]}}else throw new o("Built swap selector does not match the accepted router.");if(u(f.from,n,"input token"),u(f.to,i,"output token"),u(f.wallet,a,"recipient"),f.amount!==r(c))throw new o("Built swap input amount does not match the accepted quote.");we(e.data,t.calldataMinAmountOut??t.minAmountOut,d===M.toLowerCase())}function W(e,t={}){if(!e||typeof e.quoteId!="string"||!e.quoteId.trim())throw new o("Quote must include a non-empty quoteId.");if(w(e.router),e.oakFee!==void 0&&r(e.oakFee)!==0n)throw new o("Oak charges 0 swap fee; venue fees must never be counted as Oak income.");let n=r(e.amountOut),i=e.destAmountAfterFee??e.netAmountOut,a,c,u;if(i!==void 0){if(c=r(i),a=e.grossAmountOut!==void 0?r(e.grossAmountOut):n>=c?n:c,a<c)throw new o("Gross output cannot be less than net output.");u=e.venueFee!==void 0?r(e.venueFee):a-c}else if(e.grossAmountOut!==void 0){if(a=r(e.grossAmountOut),c=n,a<c)throw new o("Gross output cannot be less than net output.");u=e.venueFee!==void 0?r(e.venueFee):a-c}else e.venueFee!==void 0?(u=r(e.venueFee),c=n,a=c+u):(c=n,a=n,u=0n);if(c<=0n)throw new C("Quote output amount must be positive.");let m=t.slippageBps??e.slippageBps??q,A=e.minAmountOut!==void 0?r(e.minAmountOut):r(Ie(c.toString(),m));if(A<=0n||A>a)throw new o("Quote minAmountOut must be positive and not exceed gross output.");if((t.provider??e.provider)==="velora"&&e.calldataMinAmountOut!==void 0){if(r(e.calldataMinAmountOut)!==pe(A.toString(),e.venueFeeBps??1)||r(e.calldataMinAmountOut)>a)throw new o("Velora calldata minimum must cover the accepted net output, venue fee and router dust.")}else if(e.calldataMinAmountOut!==void 0||e.ponsCurveToken!==void 0){if((t.provider??e.provider)!=="pons"||!e.ponsCurveToken)throw new o("Curve minimum requires a Pons curve quote.");w(e.ponsCurveToken);let b=r(t.amountIn??e.amountIn??"0"),I=r(e.expectedSpend??"0"),ge=r(e.expectedRefund??"0"),he=r(e.calldataMinAmountOut??"0");if(b<=0n||I<=0n||I+ge!==b||he*I/b!==A)throw new o("Pons actual minimum and refund do not match the encoded minimum.")}let d=U(t.now),f=BigInt(d+ve),s=e.expiresAt!==void 0?r(e.expiresAt):f,l=(s>f?f:s).toString(),g=u.toString(),p=e.venueFeeBps??(a>0n&&u>0n?Number((u*10000n+a/2n)/a):0),v=t.provider??e.provider??(e.router.toLowerCase()===V.toLowerCase()?"velora":"kyberswap"),T=v==="pons"&&e.feeDisclosure?e.feeDisclosure:fe({provider:v,venueFee:g,venueFeeBps:p,oakFee:"0"}),x={...e,quoteId:e.quoteId,amountOut:c.toString(),minAmountOut:A.toString(),router:e.router,expiresAt:l,provider:v,grossAmountOut:a.toString(),destAmountAfterFee:c.toString(),netAmountOut:c.toString(),venueFee:g,venueFeeBps:p,oakFee:"0",feeDisclosure:T,...t.from??e.from?{from:F(t.from??e.from)}:{},...t.to??e.to?{to:F(t.to??e.to)}:{},...t.amountIn??e.amountIn?{amountIn:t.amountIn??e.amountIn}:{},...t.wallet??e.wallet?{wallet:t.wallet??e.wallet}:{},slippageBps:m,chainId:t.chainId??e.chainId??h,spender:e.spender??e.router,...t.allowance??e.allowance?{allowance:t.allowance??e.allowance}:{}};if(BigInt(d)>=r(l))throw new P;if(t.cache===!1)return x;if(me(d),BigInt(d)>=r(l))throw new P;let E=S.get(x.quoteId);if(E){$(x,E,!0);let b=se({...E,expiresAt:x.expiresAt});return S.set(b.quoteId,b),Y(b)}for(;S.size>=Oe;)S.delete(S.keys().next().value);let k=se(x);return S.set(k.quoteId,k),Y(k)}async function Ne(e,t,n={}){e={...e},w(e.from),w(e.to),w(e.wallet),e.from=F(e.from),e.to=F(e.to);let i=r(e.amountIn);if(i<=0n)throw new o("Swap amountIn must be greater than zero.");let a=e.slippageBps??q;if(!Number.isInteger(a)||a<0||a>=1e4)throw new o("Slippage must be an integer from 0 to 9999 bps.");if(!Array.isArray(t)||t.length===0)throw new C;let c={from:e.from,to:e.to,amountIn:i.toString(),slippageBps:a},u=await Promise.allSettled(t.map(async d=>{let f=await(d.quotePrices??d.quote).call(d,{...c},e.wallet);return{quote:W(f,{provider:d.name,from:e.from,to:e.to,amountIn:i.toString(),wallet:e.wallet,slippageBps:a,chainId:e.chainId??h,allowance:e.allowance,now:e.now,cache:!1}),provider:d}})),m,A=[];for(let d of u)d.status==="rejected"&&(m??=j(d.reason)),d.status==="fulfilled"&&r(d.value.quote.expiresAt)>BigInt(U(e.now))&&A.push(d.value);if(A.length===0)throw m??new C;A.sort((d,f)=>{let l=r(f.quote.amountOut)-r(d.quote.amountOut)||r(f.quote.minAmountOut)-r(d.quote.minAmountOut);return l>0n?1:l<0n?-1:0});for(let{quote:d,provider:f}of A)try{if(BigInt(U(e.now))>=r(d.expiresAt))continue;if(n.deferBuild||!f.prepareQuote)return W(d,{now:e.now});let s=await f.prepareQuote(d.quoteId,e.wallet);if(s.quoteId!==d.quoteId)throw new o("Prepared quote ID does not match the selected route.");if($(s,d,!0),!s.data)throw new o("Selected route did not return swap calldata.");let l={...d,expiresAt:s.expiresAt,data:s.data,value:s.value,allowance:s.allowance??d.allowance};return Ae(X({to:l.router,data:s.data,value:s.value??"0",chainId:l.chainId??h,description:"Selected swap route"}),l),W(l,{now:e.now})}catch(s){m??=j(s);continue}throw m??new C}function Ve(e,t={}){if(!e||typeof e.quoteId!="string"||!e.quoteId.trim())throw new o("Provide a valid quote to build a swap.");w(e.router);let n=S.get(e.quoteId),i=U(t.now);if(me(i),!n||BigInt(i)>=r(n.expiresAt))throw S.delete(e.quoteId),new P;if(e.oakFee!==void 0&&r(e.oakFee)!==0n)throw new o("Oak charges 0 swap fee; venue fees must never be counted as Oak income.");$(e,n),$({...n,...t},n);let a=n.from,c=n.to,u=n.amountIn,m=n.wallet;if(!a||!c||!m||u===void 0)throw new o("Accepted quote must include input, output, amount and wallet.");let A=n.chainId??h,d=n.spender??n.router,f=t.allowance??e.allowance??n?.allowance??"0";w(a),w(c),w(m),w(d);let s=r(u);if(s<=0n)throw new o("Swap amountIn must be greater than zero.");let l=r(n.minAmountOut);if(l<=0n)throw new o("Swap minAmountOut must be greater than zero.");let g=e.router.toLowerCase()===V.toLowerCase(),p=t.data??e.data??n?.data??(g?Ce({from:a,to:c,amountIn:s.toString(),amountOut:n.amountOut,minAmountOut:l.toString(),wallet:m}):De({from:a,to:c,amountIn:s.toString(),minAmountOut:l.toString(),wallet:m}));we(p,n.calldataMinAmountOut??l.toString(),n.router.toLowerCase()===M.toLowerCase());let v=n.venueFee??"0",T=n.venueFeeBps??0,x=n.provider??(g?"velora":"kyberswap"),E=n.feeDisclosure??fe({provider:x,venueFee:v,venueFeeBps:T,oakFee:"0"}),k=O(a),b=t.value??e.value??n?.value??(k?s.toString():"0"),I=X({to:e.router,data:p,value:b,chainId:A,description:`Swap ${s} base units of ${a} for at least ${l} base units of ${c} via ${x} (${e.router}). ${E}`});return Ae(I,n),k||r(f)>=s?[I]:[ae(a,d,s.toString(),A),I]}export{ve as a,q as b,_e as c,ce as d,Se as e,N as f,C as g,P as h,Oe as i,Y as j,se as k,$ as l,U as m,O as n,Ie as o,ye as p,Me as q,pe as r,ke as s,fe as t,De as u,Ce as v,Te as w,we as x,Ae as y,W as z,Ne as A,Ve as B};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as i,i as d}from"./
|
|
1
|
+
import{a as i,i as d}from"./ZUC6ILK2.js";import{a as n}from"./NGAI6GTU.js";import{encodeAbiParameters as y,keccak256 as g,parseAbi as p,zeroAddress as w}from"viem";var u=d[i].pons,m=p(["function getLaunchedToken(address) view returns ((address token,address curve,address deployer,address creatorFeeRecipient,address pairToken,uint256 graduationThreshold,uint24 poolFee,int24 tickSpacing,uint16 creatorTaxBps,bool buybackEnabled,uint8 phase,uint256 sweptQuote,uint256 sweptTokens,uint256 sweptAt,bool exists))","function memeHook() view returns (address)"]),h=p(["function factory() view returns (address)","function getReserves() view returns (uint256 quoteReserve,uint256 tokenReserve)"]),l=p(["function getSlot0(bytes32) view returns (uint160,int24,uint24,uint24)","function getLiquidity(bytes32) view returns (uint128)"]);async function P(t,r,s){if(t.chainId!==i||!Number.isInteger(t.decimals)||t.decimals<0||t.decimals>255)throw new n("No supported Pons reference price on this chain or for these token decimals.");let e=await r.readContract({address:u.factory.address,abi:m,functionName:"getLaunchedToken",args:[t.address],blockNumber:s});if(!e.exists||e.token.toLowerCase()!==t.address.toLowerCase()||e.pairToken.toLowerCase()!==w)throw new n("No supported native-ETH Pons launch reference price.");let f=10n**BigInt(t.decimals);if(e.phase===0){let[c,[a,o]]=await Promise.all([r.readContract({address:e.curve,abi:h,functionName:"factory",blockNumber:s}),r.readContract({address:e.curve,abi:h,functionName:"getReserves",blockNumber:s})]);if(c.toLowerCase()!==u.factory.address.toLowerCase()||a<=0n||o<=0n)throw new n("The Pons curve reference price is unavailable.");return{numerator:a*f,denominator:o*10n**18n}}if(e.phase===2){let c=await r.readContract({address:u.factory.address,abi:m,functionName:"memeHook",blockNumber:s}),a=g(y([{type:"address"},{type:"address"},{type:"uint24"},{type:"int24"},{type:"address"}],[w,t.address,e.poolFee,e.tickSpacing,c])),[o,v]=await Promise.all([r.readContract({address:d[i].ponsTrade.state_view.address,abi:l,functionName:"getSlot0",args:[a],blockNumber:s}),r.readContract({address:d[i].ponsTrade.state_view.address,abi:l,functionName:"getLiquidity",args:[a],blockNumber:s})]);if(o[0]<=0n||v<=0n)throw new n("The graduated Pons pool reference price is unavailable.");return{numerator:(1n<<192n)*f,denominator:o[0]**2n*10n**18n}}throw new n("The Pons launch has no active reference price in this phase.")}export{P as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as y}from"./I5CQ64EU.js";import{c as E}from"./ZUC6ILK2.js";import{a as r}from"./NGAI6GTU.js";import{decodeAbiParameters as F,parseAbiParameters as X}from"viem";var G="12333333",J="9000000",Z="20000000000000000000",tt="300000000000000000000",nt=["100000000000000000000000","500000000000000000000000","1000000000000000000000000","10000000000000000000000000"],k=1800,U=9000n,A=9607n,L=150n,q=(1n<<256n)-1n,f=10000n,m=10n**18n,H=10n**30n,R=1n<<192n,_=20n*m,P=75n*m,O=100n*m,B=300n*m,x=100000n*m,w=500000n*m,p=1000000n*m,N=10000000n*m;function e(t){let n=typeof t=="bigint"?t:y(t);if(n<0n||n>q)throw new r("Amount must be within the uint256 range.");return n}function h(t){if(typeof t=="bigint")return t;if(typeof t=="number"){if(!Number.isSafeInteger(t))throw new r("Integer parameter must be a safe integer.");return BigInt(t)}if(typeof t!="string"||!/^-?\d+$/.test(t))throw new r("Value must be a signed integer decimal string.");return BigInt(t)}function v(t,n=77){let i=typeof t=="number"?t:typeof t=="string"&&/^\d+$/.test(t)?Number(t):NaN;if(!Number.isInteger(i)||i<0||i>n)throw new r(`Token decimals must be an integer from 0 to ${n}.`);return i}function T(t){return 10n**BigInt(t)}function I(t,n="Result"){if(t<0n||t>q)throw new r(`${n} exceeds uint256 bounds.`);return t}function b(t,n,i="Factor"){return I(t*n,i)}function g(t,n,i,o="floor"){if(i<=0n)throw new r("The denominator must be positive.");let c=t*n;if(c===0n)return 0n;let s=o==="ceil"?c/i+(c%i===0n?0n:1n):c/i;return I(s,"Math.mulDiv result")}function it(t){let n=e(t);return n<x?_.toString():n<w?(_+g(n-x,P-_,w-x)).toString():n<p?(P+g(n-w,O-P,p-w)).toString():n<N?(O+g(n-p,B-O,N-p)).toString():B.toString()}function et(t){let n=e(t);return I(9000000n+n/1000000000000n/6n,"noHoldPriceBase").toString()}function rt(t){let n=e(t),i=n/4n,o=n-i;return{burn:i.toString(),treasury:o.toString()}}function V(t){let n=e(t);return g(n,5n,100n,"ceil").toString()}function ot(t){let n=e(t);return(n-BigInt(V(n))).toString()}function ct(t,n){let i=e(t),o=e(n);if(o<=0n)throw new r("OAK-per-ETH price must be positive.");return g(i,m,o,"floor").toString()}function st(t,n,i=E){let o=e(t),c=e(n);if(c<=0n)throw new r("OAK USD price must be positive.");let s=T(v(i));return g(o,s,c,"ceil").toString()}function at(t,n,i=E){let o=e(t),c=e(n),s=T(v(i));return g(o,c,s,"floor").toString()}function ut(t,n){let i=e(t),o=e(n);if(i>f||o>f)throw new r("FeePolicyOutOfBounds: hook fee or creator tax exceeds 10000 bps.");let c=i+o+L;if(c>f-U)throw new r("FeePolicyOutOfBounds: fees and impact allowance exceed 1000 bps.");let s=f-c;return(s>A?A:s).toString()}function gt(t,n,i,o,c){let s=v(o,83);if(s<6)throw new r("OAK decimals must be at least 6 for burner conversion.");let a=e(c);if(a<U||a>A)throw new r("InvalidBurnerFloor: floor must be from 9000 to 9607 bps.");let u=e(t),d=e(n),l=e(i);if(l<=0n)throw new r("ETH USD price must be positive.");let D=T(s-6),S=b(u,D,"burnerMinOut usdgIn * decimalScale"),W=b(d,a,"burnerMinOut oakPerEthE18 * floorBps"),M=b(l,f,"burnerMinOut ethUsdE18 * 10000");return g(S,W,M,"floor").toString()}function mt(t,n,i=k){let o=h(t),c=h(n),s=h(i);if(s<=0n)throw new r("Observation window seconds must be positive.");let a=c-o,d=a/s-(a<0n&&a%s!==0n?1n:0n);return Number(d)}function lt(t,n){if(!t||typeof n!="string"||!/^0x[0-9a-fA-F]*$/.test(n))throw new r("Oracle observe call failed or returned invalid hex.");if(n==="0x"||n.length<258)throw new r("Oracle observe return data is empty or too short.");try{let[i]=F(X("int56[] tickCumulatives, uint160[] secondsPerLiquidityCumulativeX128s"),n);if(!Array.isArray(i)||i.length<2)throw new r("Oracle observe did not return two tick cumulatives.");return[i[0].toString(),i[1].toString()]}catch(i){throw i instanceof r?i:new r("Oracle observe return data could not be decoded.")}}function dt(t){let n=e(t);if(n<=0n)throw new r("sqrtRatioX96 must be positive.");let i=b(n,n,"sqrtRatioX96 squared");return g(i,H,R,"floor").toString()}function K(t){let n=e(t);if(n<=0n)throw new r("sqrtPriceX96 must be positive.");let i=b(n,n,"sqrtPriceX96 squared");return g(i,m,R,"floor").toString()}function C(t){let n="ethAmountWei"in t&&t.ethAmountWei!==void 0?t.ethAmountWei:"ethVolumeWei"in t?t.ethVolumeWei:void 0;if(n===void 0)throw new r("SwapTrade must provide ethAmountWei.");let i=h(n),o=i<0n?-i:i;if(o<=0n)throw new r("SwapTrade ETH volume must be positive.");let c;t.sqrtPriceX96!==void 0&&t.sqrtPriceX96!==""&&t.sqrtPriceX96!=="0"&&(c=BigInt(K(t.sqrtPriceX96)));let s;if(t.oakPerEthE18!==void 0&&t.oakPerEthE18!==""&&(s=e(t.oakPerEthE18)),c!==void 0&&s!==void 0&&c!==s)throw new r("SwapTrade oakPerEthE18 does not match post-swap sqrtPriceX96.");let a=c??s;if(a===void 0||a<=0n)throw new r("SwapTrade must provide a positive post-swap price.");let u=t.timestamp!==void 0&&t.timestamp!==""?e(t.timestamp):void 0;return{volumeWei:o,oakPerEth:a,timestamp:u}}function Y(t,n){if(!Array.isArray(t)||t.length===0)throw new r("At least one SwapTrade is required to compute the 30-minute average.");let i=n?.windowEnd!==void 0?e(BigInt(n.windowEnd)):n?.now!==void 0?e(BigInt(n.now)):void 0,o=n?.windowStart!==void 0?e(BigInt(n.windowStart)):i!==void 0?i-BigInt(k):void 0,c=0n,s=0n;for(let a of t){let{volumeWei:u,oakPerEth:d,timestamp:l}=C(a);o!==void 0&&i!==void 0&&l!==void 0&&(l<o||l>=i)||(c+=u*d,s+=u)}if(s<=0n)throw new r("No trades with positive ETH volume fell inside the 30-minute window.");return(c/s).toString()}function St(t,n,i=k){let o=e(BigInt(n)),c=e(BigInt(i));if(c<=0n||o<c)throw new r("Invalid 30-minute observation window bounds.");let s=o-c,a=[],u=0n;for(let l of t){let{volumeWei:D,timestamp:S}=C(l);S!==void 0&&(S<s||S>=o)||(a.push(l),u+=D)}return{oakPerEthE18:Y(a),tradeCount:a.length,ethVolumeWei:u.toString(),windowStart:s.toString(),windowEnd:o.toString()}}function ft(t,n){return e(t)<=e(n)}function bt(t,n){return e(t)<=e(n)}export{G as a,J as b,Z as c,tt as d,nt as e,k as f,U as g,A as h,L as i,it as j,et as k,rt as l,V as m,ot as n,ct as o,st as p,at as q,ut as r,gt as s,mt as t,lt as u,dt as v,K as w,Y as x,St as y,ft as z,bt as A};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{b as k,c as D,d as x}from"./KFMNCJXJ.js";import{a as V}from"./S3YSJ7XH.js";import{a as T}from"./VZWOWR6G.js";import{a as c,d as j,i as O}from"./25EOXUBI.js";import{a as X,b as W}from"./B5RZYFQC.js";import{a as s}from"./T5E4OJEU.js";import{encodeFunctionData as J,erc20Abi as G,getAddress as a,isAddress as ft,parseAbi as pt}from"viem";var kt="hookr",y=a(O[4663].hookr.HookrLimitOrders.address),gt=a(O[4663].hookr.HookrRoot.address),At=a(O[4663].hookr.HookrRouter.address),wt=a(O[4663].hookr.HookrForwarder.address),Ot=a(O[4663].hookr.PoolManager.address),Bt=a(O[4663].hookr.HOOKR_Token.address),L="0x0000000000000000000000000000000000000000",ht="0x000000000000000000000000000000000000dEaD",Q=(1n<<128n)-1n,It=new Set([L.toLowerCase(),ht.toLowerCase(),y.toLowerCase(),At.toLowerCase(),wt.toLowerCase(),Ot.toLowerCase(),gt.toLowerCase()]),B=pt(["function getOrder(uint256 orderId) view returns (((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, address owner, uint40 createdAt, uint40 expiry, bool zeroForOne, uint8 status, address recipient, uint128 amountIn, uint128 minAmountOut, uint128 bounty, uint160 sqrtPriceLimitX96))","function quoteFill(uint256 orderId) view returns (bool fillable, uint256 amountOut)","function bountyBounds((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, bool zeroForOne, uint128 amountIn, uint128 minAmountOut) view returns (uint128 minBounty, uint128 defaultBounty, uint128 maxBounty)","function fill(uint256 orderId) returns (uint256 amountOut)","function claimBounty(address to) returns (uint256 amount)","function bountyOf(address keeper) view returns (uint256)","function lastOrderId() view returns (uint256)","function liabilities(address currency) view returns (uint256)"]);function St(t){let n=t.toLowerCase();return n===L.toLowerCase()||n===V.toLowerCase()}function Tt(t,n,i){let o=n.trim();if(o.startsWith("-")){let u=o.slice(1),r=t(u,i);return r==="0"?"0":`-${r}`}return t(o,i)}function Kt(t,n,i){return W(t,n,i)}function Y(t,n){return!t.changes||t.changes.length===0?"no net ERC-20/native transfer delta on caller":t.changes.map(i=>`${Tt(n,i.amount,i.token.decimals)} ${i.token.symbol} (${i.token.address})`).join(", ")}function $t(t){if(typeof t=="bigint"){if(t<=0n)throw new s("Hookr orderId must be a positive integer.");return t}if(typeof t=="number"){if(!Number.isSafeInteger(t)||t<=0)throw new s("Hookr orderId must be a positive integer.");return BigInt(t)}if(typeof t=="string"&&/^\d+$/.test(t.trim())){let n=BigInt(t.trim());if(n<=0n)throw new s("Hookr orderId must be a positive integer.");return n}throw new s("Provide a positive integer Hookr orderId.")}function tt(t){if(t==null)return c;if(typeof t!="number"||!Number.isSafeInteger(t)||t!==c)throw new s(`Hookr limit orders are only supported on chain ${c}.`);return c}function Ht(t){switch(t){case 0:return"None";case 1:return"Open";case 2:return"Filled";case 3:return"Cancelled";default:return"Unknown"}}function xt(t){if(Array.isArray(t)){let[n,i,o,u,r,d,g,m,b,e,l]=t;return{key:Array.isArray(n)?{currency0:n[0],currency1:n[1],fee:Number(n[2]),tickSpacing:Number(n[3]),hooks:n[4]}:n,owner:i,createdAt:o,expiry:u,zeroForOne:!!r,status:d,recipient:g,amountIn:BigInt(m),minAmountOut:BigInt(b),bounty:BigInt(e),sqrtPriceLimitX96:BigInt(l)}}if(t&&typeof t=="object"){let n=t;if(n.key&&typeof n.key=="object")return{key:{currency0:n.key.currency0,currency1:n.key.currency1,fee:Number(n.key.fee),tickSpacing:Number(n.key.tickSpacing),hooks:n.key.hooks},owner:n.owner,createdAt:n.createdAt,expiry:n.expiry,zeroForOne:!!n.zeroForOne,status:n.status,recipient:n.recipient,amountIn:BigInt(n.amountIn),minAmountOut:BigInt(n.minAmountOut),bounty:BigInt(n.bounty),sqrtPriceLimitX96:BigInt(n.sqrtPriceLimitX96)}}throw new s("HookrLimitOrders returned a malformed order tuple.")}function Rt(t){if(Array.isArray(t)&&t.length>=2)return{fillable:!!t[0],amountOut:BigInt(t[1])};if(t&&typeof t=="object"&&"fillable"in t&&"amountOut"in t){let n=t;return{fillable:!!n.fillable,amountOut:BigInt(n.amountOut)}}throw new s("HookrLimitOrders returned a malformed quoteFill response.")}function Ct(t){if(Array.isArray(t)&&t.length>=3)return{minBounty:BigInt(t[0]),defaultBounty:BigInt(t[1]),maxBounty:BigInt(t[2])};if(t&&typeof t=="object"&&"minBounty"in t&&"defaultBounty"in t&&"maxBounty"in t){let n=t;return{minBounty:BigInt(n.minBounty),defaultBounty:BigInt(n.defaultBounty),maxBounty:BigInt(n.maxBounty)}}throw new s("HookrLimitOrders returned a malformed bountyBounds response.")}async function Z(t,n,i=c){if(i!==c)throw new s(`Unsupported token chain ${i}; Hookr requires chain ${c}.`);if(St(n))return{...k,chainId:i};T(n);let o=a(n),u=o.toLowerCase();if(u===D.address.toLowerCase())return{address:o,symbol:D.symbol,decimals:j,chainId:i};if(u===x.address.toLowerCase())return{address:o,symbol:x.symbol,decimals:x.decimals,chainId:i};if(u===Bt.toLowerCase())return{address:o,symbol:"HOOKR",decimals:18,chainId:i};let[r,d]=await Promise.all([t.readContract({address:o,abi:G,functionName:"symbol"}),t.readContract({address:o,abi:G,functionName:"decimals"})]),g=typeof r=="string"&&r.trim()?r.trim():o,m=Number(d);if(!Number.isInteger(m)||m<0||m>255)throw new s(`Invalid token decimals for ${o} on chain ${i}.`);return{address:o,symbol:g,decimals:m,chainId:i}}async function Dt(t){if(typeof t.getBlock!="function")throw new s("Cannot read the latest block timestamp for Hookr order expiry.");let n=await t.getBlock().catch(()=>{throw new s("Cannot read the latest block timestamp for Hookr order expiry.")});if(!n||typeof n.timestamp!="bigint"||n.timestamp<=0n)throw new s("Hookr requires a usable latest block timestamp to check order expiry.");return n.timestamp}function P(t,n=[]){if(typeof t!="string"||!ft(t,{strict:!1}))throw new s("Provide a valid recipient wallet address.");let i=a(t),o=i.toLowerCase();if(It.has(o)||n.some(u=>u.toLowerCase()===o))throw new s(`Recipient ${i} is a reserved protocol or zero address (invalid recipient).`);return i}function nt(t){if(t.minBountyEth!==void 0||t.minAmountOutDecimal!==void 0||t.rounding!==void 0)throw new s("Use minBounty and minAmountOut as base-unit integer strings.")}function E(t,n){if(t!==void 0){if(typeof t!="string"||!/^\d+$/.test(t))throw new s(`Provide ${n} as a base-unit integer string.`);return X(t)}}function Pt(t){return{name:"hookr_fill",inputSchema:{type:"object",properties:{orderId:{type:"string",description:"HookrLimitOrders orderId as a positive integer string."},minBounty:{type:"string",description:"Optional minimum keeper bounty in wei (decimal base-unit string)."},minAmountOut:{type:"string",description:"Optional quote pre-check only, in token base-unit integer strings. Not enforced on chain: fill(uint256) enforces only the order minAmountOut."},chainId:{type:"number",description:"Target chain ID (must be 4663)."}},required:["orderId"],additionalProperties:!1},async execute(n,i){try{nt(n),T(i);let o=a(i),u=tt(n.chainId),r=$t(n.orderId),d=t.clientFor(u),[g,m,b]=await Promise.all([d.readContract({address:y,abi:B,functionName:"getOrder",args:[r]}),d.readContract({address:y,abi:B,functionName:"quoteFill",args:[r]}),Dt(d)]),e=xt(g),l=Number(e.status),h=Ht(l);if(l===0||e.owner.toLowerCase()===L.toLowerCase())throw new s(`Hookr order #${r} does not exist.`);if(l!==1)throw new s(`Hookr order #${r} is not open (current status: ${h}).`);let A=BigInt(e.expiry);if(A<b)throw new s(`Hookr order #${r} is expired (expiry ${A} < current timestamp ${b}).`);let f=Number(e.key.tickSpacing),$=Number(e.key.fee);if(!Number.isInteger(f)||f<=0)throw new s(`Hookr order #${r} has an invalid pool tickSpacing (${f}).`);if(e.amountIn<=0n||e.amountIn>Q)throw new s(`Hookr order #${r} has an invalid amountIn (${e.amountIn}).`);if(e.minAmountOut<=0n||e.minAmountOut>Q)throw new s(`Hookr order #${r} has an invalid minAmountOut (${e.minAmountOut}).`);let R=a(e.key.hooks);P(e.recipient,[R]);let et=await d.readContract({address:y,abi:B,functionName:"bountyBounds",args:[{currency0:a(e.key.currency0),currency1:a(e.key.currency1),fee:$,tickSpacing:f,hooks:R},e.zeroForOne,e.amountIn,e.minAmountOut]}),w=Ct(et),C=E(n.minBounty,"minBounty"),_=C!==void 0&&C>w.minBounty?C:w.minBounty;if(e.bounty<_)throw new s(`Hookr order #${r} is underbounty: order bounty (${e.bounty} wei) is below the required keeper bounty (${_} wei).`);if(e.bounty>w.maxBounty)throw new s(`Hookr order #${r} bounty (${e.bounty} wei) exceeds maximum bounty bound (${w.maxBounty} wei).`);let I=Rt(m),ot=e.zeroForOne?e.key.currency0:e.key.currency1,rt=e.zeroForOne?e.key.currency1:e.key.currency0,[H,p]=await Promise.all([Z(d,ot,u),Z(d,rt,u)]),S=E(n.minAmountOut,"minAmountOut"),F=S!==void 0&&S>e.minAmountOut?S:e.minAmountOut;if(!I.fillable||I.amountOut<=0n||I.amountOut<F)throw new s(`Hookr order #${r} is not executable: quoted output (${I.amountOut} base units of ${p.address}) does not meet minimum output (${F} base units).`);let it=J({abi:B,functionName:"fill",args:[r]}),st=t.formatAmount(e.amountIn.toString(),H.decimals),ut=t.formatAmount(I.amountOut.toString(),p.decimals),at=t.formatAmount(e.minAmountOut.toString(),p.decimals),mt=t.formatAmount(e.bounty.toString(),18),dt=S===void 0?"":` Caller minAmountOut ${S} base units is a quote pre-check only, not enforced on chain; fill(uint256) enforces the order minimum of ${e.minAmountOut} base units.`,v=`Fill Hookr order #${r}: maker's escrow pays ${st} ${H.symbol} (${e.amountIn} base units of ${H.address}); net output goes to ${a(e.recipient)} (quoted ${ut} ${p.symbol}, order minimum ${at} ${p.symbol}, ${e.minAmountOut} base units of ${p.address}). The filler sends no tokens or ETH (value 0), pays gas, and accrues ${mt} ETH (${e.bounty} wei) bounty to ${o}, payable only via claimBounty. Pool tickSpacing ${f}; expiry ${A} inclusive.${dt}`,q=t.unsignedTx({to:y,data:it,value:"0",chainId:u,description:v}),M=await t.preview([q],o),ct=Y(M,t.formatAmount),z={token:H,amount:e.amountIn.toString()},K={token:p,amount:e.minAmountOut.toString()},lt={token:p,amount:I.amountOut.toString()},U={token:{...k,chainId:u},amount:e.bounty.toString()},yt={orderId:r.toString(),key:{currency0:a(e.key.currency0),currency1:a(e.key.currency1),fee:$,tickSpacing:f,hooks:R},owner:a(e.owner),recipient:a(e.recipient),createdAt:BigInt(e.createdAt).toString(),expiry:A.toString(),zeroForOne:e.zeroForOne,status:l,statusLabel:h,amountIn:z,minAmountOut:K,bounty:U,sqrtPriceLimitX96:e.sqrtPriceLimitX96.toString()},bt={minBounty:{token:{...k,chainId:u},amount:w.minBounty.toString()},defaultBounty:{token:{...k,chainId:u},amount:w.defaultBounty.toString()},maxBounty:{token:{...k,chainId:u},amount:w.maxBounty.toString()}};return{txs:[q],summary:`${v} Preview deltas: ${ct}.`,preview:M,orderId:r.toString(),fillable:!0,amountIn:z,minAmountOut:K,quotedAmountOut:lt,bounty:U,bountyBounds:bt,order:yt}}catch(o){throw new s(t.plainError(o))}}}}function Et(t){return{name:"hookr_claim_bounty",inputSchema:{type:"object",properties:{to:{type:"string",description:"Optional recipient address for the claimed native ETH bounty (must be the signing wallet)."},minBounty:{type:"string",description:"Optional minimum claimable bounty in wei (decimal base-unit string)."},chainId:{type:"number",description:"Target chain ID (must be 4663)."}},additionalProperties:!1},async execute(n,i){try{nt(n),T(i);let o=a(i),u=tt(n.chainId),r=n.to!==void 0&&n.to!==null?P(String(n.to)):P(o);if(r!==o)throw new s("Hookr bounty recipient must be the signing wallet.");let g=await t.clientFor(u).readContract({address:y,abi:B,functionName:"bountyOf",args:[o]}),m=BigInt(g);if(m<=0n)throw new s(`No claimable Hookr keeper bounty for ${o}.`);let b=E(n.minBounty,"minBounty");if(b!==void 0&&m<b)throw new s(`Claimable Hookr bounty (${m} wei) is below the requested minimum (${b} wei).`);let e=J({abi:B,functionName:"claimBounty",args:[r]}),l=t.formatAmount(m.toString(),18),h=t.unsignedTx({to:y,data:e,value:"0",chainId:u,description:`Claim ${l} ETH (${m} wei) of accrued Hookr keeper bounty from ${y} to ${r}.`}),A=await t.preview([h],o),f=Y(A,t.formatAmount),$={token:{...k,chainId:u},amount:m.toString()};return{txs:[h],summary:`Claim ${l} ETH (${m} wei) Hookr keeper bounty to ${r}. Preview deltas: ${f}.`,preview:A,recipient:r,claimableBounty:$}}catch(o){throw new s(t.plainError(o))}}}}async function Lt(t,n){T(n);let i=a(n),o=t.clientFor(c);try{let u=await o.readContract({address:y,abi:B,functionName:"bountyOf",args:[i]}),r=BigInt(u);if(r<=0n)return[];let d=t.formatAmount(r.toString(),18);return[{module:kt,id:`hookr:bounty:${i.toLowerCase()}`,chainId:c,assets:[{token:{...k,chainId:c},amount:r.toString()}],description:`Hookr claimable keeper bounty (${d} ETH)`}]}catch(u){throw new s(t.plainError(u))}}var N=t=>({tools:[Pt(t),Et(t)],positions:n=>Lt(t,n)}),Ut=N,jt=N,Xt=N;export{kt as a,y as b,gt as c,At as d,wt as e,Ot as f,Bt as g,B as h,Tt as i,Kt as j,Pt as k,Et as l,Lt as m,N as n,Ut as o,jt as p,Xt as q};
|
|
1
|
+
import{b as k,c as D,d as x}from"./MOVRI5IV.js";import{a as V}from"./GDP4JSAX.js";import{a as T}from"./A5ITAEUQ.js";import{a as X,b as W}from"./I5CQ64EU.js";import{a as c,d as j,i as O}from"./ZUC6ILK2.js";import{a as s}from"./NGAI6GTU.js";import{encodeFunctionData as J,erc20Abi as G,getAddress as a,isAddress as ft,parseAbi as pt}from"viem";var kt="hookr",y=a(O[4663].hookr.HookrLimitOrders.address),gt=a(O[4663].hookr.HookrRoot.address),At=a(O[4663].hookr.HookrRouter.address),wt=a(O[4663].hookr.HookrForwarder.address),Ot=a(O[4663].hookr.PoolManager.address),Bt=a(O[4663].hookr.HOOKR_Token.address),L="0x0000000000000000000000000000000000000000",ht="0x000000000000000000000000000000000000dEaD",Q=(1n<<128n)-1n,It=new Set([L.toLowerCase(),ht.toLowerCase(),y.toLowerCase(),At.toLowerCase(),wt.toLowerCase(),Ot.toLowerCase(),gt.toLowerCase()]),B=pt(["function getOrder(uint256 orderId) view returns (((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, address owner, uint40 createdAt, uint40 expiry, bool zeroForOne, uint8 status, address recipient, uint128 amountIn, uint128 minAmountOut, uint128 bounty, uint160 sqrtPriceLimitX96))","function quoteFill(uint256 orderId) view returns (bool fillable, uint256 amountOut)","function bountyBounds((address currency0, address currency1, uint24 fee, int24 tickSpacing, address hooks) key, bool zeroForOne, uint128 amountIn, uint128 minAmountOut) view returns (uint128 minBounty, uint128 defaultBounty, uint128 maxBounty)","function fill(uint256 orderId) returns (uint256 amountOut)","function claimBounty(address to) returns (uint256 amount)","function bountyOf(address keeper) view returns (uint256)","function lastOrderId() view returns (uint256)","function liabilities(address currency) view returns (uint256)"]);function St(t){let n=t.toLowerCase();return n===L.toLowerCase()||n===V.toLowerCase()}function Tt(t,n,i){let o=n.trim();if(o.startsWith("-")){let u=o.slice(1),r=t(u,i);return r==="0"?"0":`-${r}`}return t(o,i)}function Kt(t,n,i){return W(t,n,i)}function Y(t,n){return!t.changes||t.changes.length===0?"no net ERC-20/native transfer delta on caller":t.changes.map(i=>`${Tt(n,i.amount,i.token.decimals)} ${i.token.symbol} (${i.token.address})`).join(", ")}function $t(t){if(typeof t=="bigint"){if(t<=0n)throw new s("Hookr orderId must be a positive integer.");return t}if(typeof t=="number"){if(!Number.isSafeInteger(t)||t<=0)throw new s("Hookr orderId must be a positive integer.");return BigInt(t)}if(typeof t=="string"&&/^\d+$/.test(t.trim())){let n=BigInt(t.trim());if(n<=0n)throw new s("Hookr orderId must be a positive integer.");return n}throw new s("Provide a positive integer Hookr orderId.")}function tt(t){if(t==null)return c;if(typeof t!="number"||!Number.isSafeInteger(t)||t!==c)throw new s(`Hookr limit orders are only supported on chain ${c}.`);return c}function Ht(t){switch(t){case 0:return"None";case 1:return"Open";case 2:return"Filled";case 3:return"Cancelled";default:return"Unknown"}}function xt(t){if(Array.isArray(t)){let[n,i,o,u,r,d,g,m,b,e,l]=t;return{key:Array.isArray(n)?{currency0:n[0],currency1:n[1],fee:Number(n[2]),tickSpacing:Number(n[3]),hooks:n[4]}:n,owner:i,createdAt:o,expiry:u,zeroForOne:!!r,status:d,recipient:g,amountIn:BigInt(m),minAmountOut:BigInt(b),bounty:BigInt(e),sqrtPriceLimitX96:BigInt(l)}}if(t&&typeof t=="object"){let n=t;if(n.key&&typeof n.key=="object")return{key:{currency0:n.key.currency0,currency1:n.key.currency1,fee:Number(n.key.fee),tickSpacing:Number(n.key.tickSpacing),hooks:n.key.hooks},owner:n.owner,createdAt:n.createdAt,expiry:n.expiry,zeroForOne:!!n.zeroForOne,status:n.status,recipient:n.recipient,amountIn:BigInt(n.amountIn),minAmountOut:BigInt(n.minAmountOut),bounty:BigInt(n.bounty),sqrtPriceLimitX96:BigInt(n.sqrtPriceLimitX96)}}throw new s("HookrLimitOrders returned a malformed order tuple.")}function Rt(t){if(Array.isArray(t)&&t.length>=2)return{fillable:!!t[0],amountOut:BigInt(t[1])};if(t&&typeof t=="object"&&"fillable"in t&&"amountOut"in t){let n=t;return{fillable:!!n.fillable,amountOut:BigInt(n.amountOut)}}throw new s("HookrLimitOrders returned a malformed quoteFill response.")}function Ct(t){if(Array.isArray(t)&&t.length>=3)return{minBounty:BigInt(t[0]),defaultBounty:BigInt(t[1]),maxBounty:BigInt(t[2])};if(t&&typeof t=="object"&&"minBounty"in t&&"defaultBounty"in t&&"maxBounty"in t){let n=t;return{minBounty:BigInt(n.minBounty),defaultBounty:BigInt(n.defaultBounty),maxBounty:BigInt(n.maxBounty)}}throw new s("HookrLimitOrders returned a malformed bountyBounds response.")}async function Z(t,n,i=c){if(i!==c)throw new s(`Unsupported token chain ${i}; Hookr requires chain ${c}.`);if(St(n))return{...k,chainId:i};T(n);let o=a(n),u=o.toLowerCase();if(u===D.address.toLowerCase())return{address:o,symbol:D.symbol,decimals:j,chainId:i};if(u===x.address.toLowerCase())return{address:o,symbol:x.symbol,decimals:x.decimals,chainId:i};if(u===Bt.toLowerCase())return{address:o,symbol:"HOOKR",decimals:18,chainId:i};let[r,d]=await Promise.all([t.readContract({address:o,abi:G,functionName:"symbol"}),t.readContract({address:o,abi:G,functionName:"decimals"})]),g=typeof r=="string"&&r.trim()?r.trim():o,m=Number(d);if(!Number.isInteger(m)||m<0||m>255)throw new s(`Invalid token decimals for ${o} on chain ${i}.`);return{address:o,symbol:g,decimals:m,chainId:i}}async function Dt(t){if(typeof t.getBlock!="function")throw new s("Cannot read the latest block timestamp for Hookr order expiry.");let n=await t.getBlock().catch(()=>{throw new s("Cannot read the latest block timestamp for Hookr order expiry.")});if(!n||typeof n.timestamp!="bigint"||n.timestamp<=0n)throw new s("Hookr requires a usable latest block timestamp to check order expiry.");return n.timestamp}function P(t,n=[]){if(typeof t!="string"||!ft(t,{strict:!1}))throw new s("Provide a valid recipient wallet address.");let i=a(t),o=i.toLowerCase();if(It.has(o)||n.some(u=>u.toLowerCase()===o))throw new s(`Recipient ${i} is a reserved protocol or zero address (invalid recipient).`);return i}function nt(t){if(t.minBountyEth!==void 0||t.minAmountOutDecimal!==void 0||t.rounding!==void 0)throw new s("Use minBounty and minAmountOut as base-unit integer strings.")}function E(t,n){if(t!==void 0){if(typeof t!="string"||!/^\d+$/.test(t))throw new s(`Provide ${n} as a base-unit integer string.`);return X(t)}}function Pt(t){return{name:"hookr_fill",inputSchema:{type:"object",properties:{orderId:{type:"string",description:"HookrLimitOrders orderId as a positive integer string."},minBounty:{type:"string",description:"Optional minimum keeper bounty in wei (decimal base-unit string)."},minAmountOut:{type:"string",description:"Optional quote pre-check only, in token base-unit integer strings. Not enforced on chain: fill(uint256) enforces only the order minAmountOut."},chainId:{type:"number",description:"Target chain ID (must be 4663)."}},required:["orderId"],additionalProperties:!1},async execute(n,i){try{nt(n),T(i);let o=a(i),u=tt(n.chainId),r=$t(n.orderId),d=t.clientFor(u),[g,m,b]=await Promise.all([d.readContract({address:y,abi:B,functionName:"getOrder",args:[r]}),d.readContract({address:y,abi:B,functionName:"quoteFill",args:[r]}),Dt(d)]),e=xt(g),l=Number(e.status),h=Ht(l);if(l===0||e.owner.toLowerCase()===L.toLowerCase())throw new s(`Hookr order #${r} does not exist.`);if(l!==1)throw new s(`Hookr order #${r} is not open (current status: ${h}).`);let A=BigInt(e.expiry);if(A<b)throw new s(`Hookr order #${r} is expired (expiry ${A} < current timestamp ${b}).`);let f=Number(e.key.tickSpacing),$=Number(e.key.fee);if(!Number.isInteger(f)||f<=0)throw new s(`Hookr order #${r} has an invalid pool tickSpacing (${f}).`);if(e.amountIn<=0n||e.amountIn>Q)throw new s(`Hookr order #${r} has an invalid amountIn (${e.amountIn}).`);if(e.minAmountOut<=0n||e.minAmountOut>Q)throw new s(`Hookr order #${r} has an invalid minAmountOut (${e.minAmountOut}).`);let R=a(e.key.hooks);P(e.recipient,[R]);let et=await d.readContract({address:y,abi:B,functionName:"bountyBounds",args:[{currency0:a(e.key.currency0),currency1:a(e.key.currency1),fee:$,tickSpacing:f,hooks:R},e.zeroForOne,e.amountIn,e.minAmountOut]}),w=Ct(et),C=E(n.minBounty,"minBounty"),_=C!==void 0&&C>w.minBounty?C:w.minBounty;if(e.bounty<_)throw new s(`Hookr order #${r} is underbounty: order bounty (${e.bounty} wei) is below the required keeper bounty (${_} wei).`);if(e.bounty>w.maxBounty)throw new s(`Hookr order #${r} bounty (${e.bounty} wei) exceeds maximum bounty bound (${w.maxBounty} wei).`);let I=Rt(m),ot=e.zeroForOne?e.key.currency0:e.key.currency1,rt=e.zeroForOne?e.key.currency1:e.key.currency0,[H,p]=await Promise.all([Z(d,ot,u),Z(d,rt,u)]),S=E(n.minAmountOut,"minAmountOut"),F=S!==void 0&&S>e.minAmountOut?S:e.minAmountOut;if(!I.fillable||I.amountOut<=0n||I.amountOut<F)throw new s(`Hookr order #${r} is not executable: quoted output (${I.amountOut} base units of ${p.address}) does not meet minimum output (${F} base units).`);let it=J({abi:B,functionName:"fill",args:[r]}),st=t.formatAmount(e.amountIn.toString(),H.decimals),ut=t.formatAmount(I.amountOut.toString(),p.decimals),at=t.formatAmount(e.minAmountOut.toString(),p.decimals),mt=t.formatAmount(e.bounty.toString(),18),dt=S===void 0?"":` Caller minAmountOut ${S} base units is a quote pre-check only, not enforced on chain; fill(uint256) enforces the order minimum of ${e.minAmountOut} base units.`,v=`Fill Hookr order #${r}: maker's escrow pays ${st} ${H.symbol} (${e.amountIn} base units of ${H.address}); net output goes to ${a(e.recipient)} (quoted ${ut} ${p.symbol}, order minimum ${at} ${p.symbol}, ${e.minAmountOut} base units of ${p.address}). The filler sends no tokens or ETH (value 0), pays gas, and accrues ${mt} ETH (${e.bounty} wei) bounty to ${o}, payable only via claimBounty. Pool tickSpacing ${f}; expiry ${A} inclusive.${dt}`,q=t.unsignedTx({to:y,data:it,value:"0",chainId:u,description:v}),M=await t.preview([q],o),ct=Y(M,t.formatAmount),z={token:H,amount:e.amountIn.toString()},K={token:p,amount:e.minAmountOut.toString()},lt={token:p,amount:I.amountOut.toString()},U={token:{...k,chainId:u},amount:e.bounty.toString()},yt={orderId:r.toString(),key:{currency0:a(e.key.currency0),currency1:a(e.key.currency1),fee:$,tickSpacing:f,hooks:R},owner:a(e.owner),recipient:a(e.recipient),createdAt:BigInt(e.createdAt).toString(),expiry:A.toString(),zeroForOne:e.zeroForOne,status:l,statusLabel:h,amountIn:z,minAmountOut:K,bounty:U,sqrtPriceLimitX96:e.sqrtPriceLimitX96.toString()},bt={minBounty:{token:{...k,chainId:u},amount:w.minBounty.toString()},defaultBounty:{token:{...k,chainId:u},amount:w.defaultBounty.toString()},maxBounty:{token:{...k,chainId:u},amount:w.maxBounty.toString()}};return{txs:[q],summary:`${v} Preview deltas: ${ct}.`,preview:M,orderId:r.toString(),fillable:!0,amountIn:z,minAmountOut:K,quotedAmountOut:lt,bounty:U,bountyBounds:bt,order:yt}}catch(o){throw new s(t.plainError(o))}}}}function Et(t){return{name:"hookr_claim_bounty",inputSchema:{type:"object",properties:{to:{type:"string",description:"Optional recipient address for the claimed native ETH bounty (must be the signing wallet)."},minBounty:{type:"string",description:"Optional minimum claimable bounty in wei (decimal base-unit string)."},chainId:{type:"number",description:"Target chain ID (must be 4663)."}},additionalProperties:!1},async execute(n,i){try{nt(n),T(i);let o=a(i),u=tt(n.chainId),r=n.to!==void 0&&n.to!==null?P(String(n.to)):P(o);if(r!==o)throw new s("Hookr bounty recipient must be the signing wallet.");let g=await t.clientFor(u).readContract({address:y,abi:B,functionName:"bountyOf",args:[o]}),m=BigInt(g);if(m<=0n)throw new s(`No claimable Hookr keeper bounty for ${o}.`);let b=E(n.minBounty,"minBounty");if(b!==void 0&&m<b)throw new s(`Claimable Hookr bounty (${m} wei) is below the requested minimum (${b} wei).`);let e=J({abi:B,functionName:"claimBounty",args:[r]}),l=t.formatAmount(m.toString(),18),h=t.unsignedTx({to:y,data:e,value:"0",chainId:u,description:`Claim ${l} ETH (${m} wei) of accrued Hookr keeper bounty from ${y} to ${r}.`}),A=await t.preview([h],o),f=Y(A,t.formatAmount),$={token:{...k,chainId:u},amount:m.toString()};return{txs:[h],summary:`Claim ${l} ETH (${m} wei) Hookr keeper bounty to ${r}. Preview deltas: ${f}.`,preview:A,recipient:r,claimableBounty:$}}catch(o){throw new s(t.plainError(o))}}}}async function Lt(t,n){T(n);let i=a(n),o=t.clientFor(c);try{let u=await o.readContract({address:y,abi:B,functionName:"bountyOf",args:[i]}),r=BigInt(u);if(r<=0n)return[];let d=t.formatAmount(r.toString(),18);return[{module:kt,id:`hookr:bounty:${i.toLowerCase()}`,chainId:c,assets:[{token:{...k,chainId:c},amount:r.toString()}],description:`Hookr claimable keeper bounty (${d} ETH)`}]}catch(u){throw new s(t.plainError(u))}}var N=t=>({tools:[Pt(t),Et(t)],positions:n=>Lt(t,n)}),Ut=N,jt=N,Xt=N;export{kt as a,y as b,gt as c,At as d,wt as e,Ot as f,Bt as g,B as h,Tt as i,Kt as j,Pt as k,Et as l,Lt as m,N as n,Ut as o,jt as p,Xt as q};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as v}from"./I5CQ64EU.js";import{a as d}from"./ZUC6ILK2.js";import{a as c}from"./NGAI6GTU.js";import{concat as B,encodeAbiParameters as D,getAddress as k,isAddress as F,keccak256 as g,parseAbiParameters as O,recoverAddress as q,toHex as N}from"viem";import{privateKeyToAccount as U}from"viem/accounts";var T="OakPriceNote",l="1",w=300,E="0x0000000000000000000000000000000000000000",W=g(N("PriceNote(address wallet,uint256 oakPerEthE18,uint64 timestamp,bytes32 nonce)")),L=g(N("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")),M=(1n<<64n)-1n,P=(1n<<256n)-1n,z=0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141n,G=0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0n;function X(e){if(typeof e!="string"||!/^0x[0-9a-fA-F]{130}$/.test(e))return!1;let n=BigInt(`0x${e.slice(2,66)}`),t=BigInt(`0x${e.slice(66,130)}`),i=Number.parseInt(e.slice(130,132),16);return!(i!==27&&i!==28||n<=0n||n>=z||t<=0n||t>G)}function m(e,n){if(typeof e!="string"||!F(e,{strict:!1}))throw new c(`Invalid ${n} address.`);return k(e)}function p(e,n){let t;if(typeof e=="bigint")t=e;else if(typeof e=="number"){if(!Number.isSafeInteger(e)||e<0)throw new c(`Invalid ${n}.`);t=BigInt(e)}else t=v(e);if(t<0n||t>P)throw new c(`${n} exceeds uint256 bounds.`);return t}function h(e,n){let t=p(e,n);if(t>M)throw new c(`${n} exceeds uint64 bounds.`);return t}function Y(e,n){if(typeof e!="string"||!/^0x[0-9a-fA-F]{64}$/.test(e))throw new c(`${n} must be a 32-byte hex string.`);return e}function j(e){if(typeof e=="bigint"){if(e<=0n||e>P)throw new c("Private key must be a positive scalar.");return`0x${e.toString(16).padStart(64,"0")}`}if(typeof e=="string"&&/^0x[0-9a-fA-F]{1,64}$/.test(e))return`0x${e.slice(2).padStart(64,"0")}`;throw new c("Invalid private key format.")}function K(e){let n=p(e.chainId,"chainId"),t=m(e.verifyingContract,"verifyingContract");return g(D(O("bytes32, bytes32, bytes32, uint256, address"),[L,g(N(e.name)),g(N(e.version)),n,t]))}function ce(e,n=d,t=l){return{name:T,version:t,chainId:Number(p(n,"chainId")),verifyingContract:m(e,"consumer")}}function J(e,n=d,t=l){return K({name:T,version:t,chainId:n,verifyingContract:e})}function Q(e){let n=m(e.wallet,"wallet"),t=p(e.oakPerEthE18,"oakPerEthE18"),i=h(e.timestamp,"timestamp"),r=Y(e.nonce,"nonce");return g(D(O("bytes32, address, uint256, uint64, bytes32"),[W,n,t,i,r]))}function C(e,n,t=d,i=l){let r=J(n,t,i),o=Q(e);return g(B(["0x1901",r,o]))}async function fe(e,n,t,i=d,r=l){let o=C(e,n,i,r);return typeof t=="object"&&t!==null&&"sign"in t?t.sign({hash:o}):U(j(t)).sign({hash:o})}async function Z(e,n,t,i=d,r=l){if(!X(n))return E;try{let o=C(e,t,i,r),x=await q({hash:o,signature:n});return k(x)}catch{return E}}function ee(e,n){let t=p(e,"oakPerEthE18"),i=p(n,"spotOakPerEthE18");if(i<=0n||t<=0n)return!1;if(t>P/2n||i>P/3n)throw new c("Guard arithmetic overflow.");let r=t*2n;return r>=i&&r<=i*3n}function te(e,n,t,i){if("signature"in e&&"consumer"in e&&"note"in e&&!("average"in e))return e;if("note"in e&&"signature"in e&&"consumer"in e){let a=e,f=n??{};return{...f,note:a.note,signature:a.signature,consumer:f.consumer??a.consumer,expiresAt:f.expiresAt??a.expiresAt}}return{...i??{},note:e,signature:n,consumer:t}}async function ne(e,n,t,i){let r=te(e,n,t,i),{note:o,signature:x,consumer:y}=r,a=h(o.timestamp,"timestamp"),f=p(o.oakPerEthE18,"oakPerEthE18"),S=(a+BigInt(w)).toString(),s=(b,V,H)=>({valid:!1,ok:!1,...H?{signer:H}:{},oakPerEthE18:f.toString(),expiresAt:S,reason:b,error:V}),I=r.wallet??r.boundWallet;if(I===void 0)return s("wrong_wallet","Bound wallet context is required to verify a price note.");if(m(o.wallet,"wallet")!==m(I,"boundWallet"))return s("wrong_wallet","Price note wallet does not match the bound wallet.");if(r.now===void 0)return s("expired","Current time (now) is required to verify price note expiry.");let A=h(r.now,"now");if(a>A)return s("not_yet_valid","Price note timestamp is in the future.");if(A-a>BigInt(w))return s("expired","Price note has expired.");if(r.expiresAt!==void 0){let b=h(r.expiresAt,"expiresAt");if(b!==a+BigInt(w)||A>b)return s("expired","Price note has expired.")}let R=r.chainId??d,$=r.version??l,u=await Z(o,x,y,R,$);if(u===E)return s("bad_signature","Price note signature could not be recovered.");if(r.signer===void 0)return s("bad_signature","Expected oracle signer is required to verify a price note.",u);let _=m(r.signer,"signer");return _===E||u!==_?s("bad_signature","Price note signer does not match the oracle signer.",u):r.spotOakPerEthE18===void 0?s("outside_guard","Spot OAK/ETH price is required to verify the price note guard band.",u):ee(f,r.spotOakPerEthE18)?{valid:!0,ok:!0,signer:u,oakPerEthE18:f.toString(),expiresAt:S}:s("outside_guard","Price note is outside the 50% spot guard band.",u)}var ue=ne;export{T as a,l as b,w as c,E as d,W as e,K as f,ce as g,J as h,Q as i,C as j,fe as k,Z as l,ee as m,ne as n,ue as o};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as E,o as O}from"./2IRORNOH.js";import{c as Q}from"./MK6L6TGI.js";import{b as K}from"./UCMNB2UP.js";import{a as J}from"./I5CQ64EU.js";import{a as p,i as G}from"./ZUC6ILK2.js";import{a as _}from"./B4MLWDPM.js";import{a as r}from"./NGAI6GTU.js";import{decodeFunctionResult as ie,encodeAbiParameters as P,encodeFunctionData as v,erc20Abi as H,isAddress as te,parseAbi as oe,parseAbiParameters as L,toHex as F,zeroAddress as $}from"viem";var h=G[p].clanker,U=oe(["function deployToken(((address tokenAdmin,string name,string symbol,bytes32 salt,string image,string metadata,string context,uint256 originatingChainId) tokenConfig,(address hook,address pairedToken,int24 tickIfToken0IsClanker,int24 tickSpacing,bytes poolData) poolConfig,(address locker,address[] rewardAdmins,address[] rewardRecipients,uint16[] rewardBps,int24[] tickLower,int24[] tickUpper,uint16[] positionBps,bytes lockerData) lockerConfig,(address mevModule,bytes mevModuleData) mevModuleConfig,(address extension,uint256 msgValue,uint16 extensionBps,bytes extensionData)[] extensionConfigs) config) payable returns (address)","function tokenDeploymentInfo(address) view returns ((address,address,address,address[]))"]),k=oe(["function availableFees(address,address) view returns (uint256)","function claim(address,address)","function collectRewards(address)","function mevModuleEnabled(bytes32) view returns (bool)","function mevModuleOperational(bytes32) returns (bool)"]),C={address:h.paired_weth.address,symbol:"WETH",decimals:18,chainId:p},ae="https://www.clanker.world/api/tokens",X={type:"string",pattern:"^\\d+$"},Y={type:"string",pattern:"^0x[0-9a-fA-F]{40}$"},Z={type:"string",pattern:"^0x[0-9a-fA-F]{64}$"};function S(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function b(e){if(typeof e!="string"||!te(e,{strict:!1})||e.toLowerCase()===$)throw new r("Provide a valid nonzero address.");return e}function ee(e,t){if(typeof e!="string"||!/^0x[0-9a-fA-F]{64}$/.test(e))throw new r(`Provide an explicit bytes32 ${t}.`);return e}function A(e,t,i=!1){if(e===void 0&&!i)return"";if(typeof e!="string"||i&&!e.trim())throw new r(`Provide ${t} as text.`);return e}function R(e,t=256){let i=J(e);if(i>=1n<<BigInt(t))throw new r(`Amount exceeds the uint${t} range.`);return i}function q(e){if(typeof e!="bigint"||e<0n||e>=1n<<256n)throw new r("The contract returned an invalid amount.");return e.toString()}function V(e,t){let i=Object.keys(e).find(m=>!t.includes(m));if(i)throw new r(`Unsupported Clanker input: ${i}.`)}function ne(e,t){return t.changes.map(({token:i,amount:m})=>{let w=m.startsWith("-");return`${w?"-":"+"}${e.formatAmount(w?m.slice(1):m,i.decimals)} ${i.symbol} (${i.address}, chain ${i.chainId})`}).join("; ")}function de(e){return S(e)&&Array.isArray(e.data)&&Number.isSafeInteger(e.total)&&Number(e.total)>=0&&Number.isSafeInteger(e.tokensDeployed)&&Number(e.tokensDeployed)>=0&&(e.cursor===null||typeof e.cursor=="string"||e.cursor===void 0&&e.data.length===0&&e.total===0&&e.tokensDeployed===0)&&e.data.every(t=>S(t)&&typeof t.name=="string"&&typeof t.symbol=="string"&&Number.isSafeInteger(t.chain_id)&&["contract_address","admin","msg_sender","factory_address"].every(i=>typeof t[i]=="string"&&te(t[i],{strict:!1})))}async function ce(e,t={}){V(t,["q","limit","cursor","deployer"]);let i=t.limit??10;if(typeof i!="number"||!Number.isInteger(i)||i<1||i>20)throw new r("Choose an indexer limit from 1 to 20.");let m=new URL(ae);m.searchParams.set("chainId",String(p)),m.searchParams.set("limit",String(i)),t.q!==void 0&&m.searchParams.set("q",A(t.q,"search")),t.cursor!==void 0&&m.searchParams.set("cursor",A(t.cursor,"cursor",!0)),t.deployer!==void 0&&m.searchParams.set("msgSender",b(t.deployer));let w=await Q(e.http,m.toString(),{headers:{"User-Agent":"Oak-Clanker/1.0"}},de);return{tokens:w.data.filter(x=>x.chain_id===p&&x.factory_address.toLowerCase()===h.factory.address.toLowerCase()),total:w.total,cursor:w.cursor||null,tokensDeployed:w.tokensDeployed}}var ue=e=>{let t=()=>e.clientFor(p),i=async n=>{try{return await n()}catch(s){throw new r(e.plainError(s))}},m=(n,s,l,d="0")=>e.unsignedTx({to:n,data:s,value:d,chainId:p,description:l}),w=async(n,s)=>q(await t().readContract({address:h.fee_locker.address,abi:k,functionName:"availableFees",args:[n,s]})),x=async n=>{if(n.toLowerCase()===C.address.toLowerCase())return C;let[s,l]=await Promise.all([t().readContract({address:n,abi:H,functionName:"symbol"}),t().readContract({address:n,abi:H,functionName:"decimals"})]);if(typeof s!="string"||!s.trim()||!Number.isInteger(l)||l<0||l>255)throw new r("The contract returned invalid token metadata.");return{address:n,chainId:p,symbol:s,decimals:l}},j=n=>ce(e,n),se=async(n,s)=>{if(V(n,["name","symbol","salt","image","metadata","context","vanity","initialBuy","minAmountOut","slippageBps"]),n.vanity!==void 0&&n.vanity!==!1)throw new r("Clanker launches use vanity false and an explicit salt.");let l=A(n.name,"token name",!0),d=A(n.symbol,"token symbol",!0),g=ee(n.salt,"salt"),f=R(n.initialBuy??"0"),c=n.slippageBps??E;if(typeof c!="number")throw new r("Slippage must be an integer from 0 to 9999 bps.");O("0",c);let o=n.minAmountOut===void 0?void 0:R(n.minAmountOut,128);if(o!==void 0&&o<=1n)throw new r("Initial-buy minimum must exceed one base unit.");if(!f&&o!==void 0)throw new r("A minimum requires a positive initial buy.");let u={tokenConfig:{tokenAdmin:s,name:l,symbol:d,salt:g,image:A(n.image,"image"),metadata:A(n.metadata,"metadata"),context:n.context===void 0?JSON.stringify({interface:"Oak",platform:"robinhood"}):A(n.context,"context"),originatingChainId:BigInt(p)},poolConfig:{hook:h.fee_static_hook_v2.address,pairedToken:C.address,tickIfToken0IsClanker:-230400,tickSpacing:200,poolData:P(L("(address,bytes,bytes)"),[[$,"0x",P(L("uint24,uint24"),[1e4,1e4])]])},lockerConfig:{locker:h.locker.address,rewardAdmins:[s],rewardRecipients:[s],rewardBps:[1e4],tickLower:[-230400],tickUpper:[-12e4],positionBps:[1e4],lockerData:P(L("(uint8[])"),[[[0]]])},mevModuleConfig:{mevModule:h.mev_module.address,mevModuleData:P(L("(uint24,uint24,uint256)"),[[666777,41673,15n]])},extensionConfigs:[]},y=await t().simulateContract({address:h.factory.address,abi:U,functionName:"deployToken",args:[u],account:s,value:0n,gas:_}),a=b(y.result),D=W=>{let M=f?[{extension:h.devbuy.address,msgValue:f,extensionBps:0,extensionData:P(L("(address,address,uint24,int24,address),uint128,address"),[[$,$,0,0,$],W,s])}]:[];return m(h.factory.address,v({abi:U,functionName:"deployToken",args:[{...u,extensionConfigs:M}]}),`Launch ${l} (${d}); initial buy ${f} native ETH base units.`,f.toString())};if(f&&o===void 0){let M=(await e.preview([D(0n)],s)).changes.filter(T=>T.token.chainId===p&&T.token.address.toLowerCase()===a.toLowerCase()&&T.token.decimals===18).reduce((T,z)=>T+(/^-?\d+$/.test(z.amount)?BigInt(z.amount):(()=>{throw new r("Invalid initial-buy simulation amount.")})()),0n);if(M<=0n)throw new r("Initial-buy simulation returned no token output.");if(o=R(O(M.toString(),c),128),o<=1n)throw new r("Initial-buy output is too small for a protected minimum.")}let I=[D(o??0n)],B=await e.preview(I,s);return{txs:I,preview:B,predictedToken:a,token:{address:a,chainId:p,symbol:d,decimals:18},...o!==void 0?{minAmountOut:o.toString()}:{},summary:`Launch ${d} at ${a} (CREATE2 address predicted from simulation); vanity false; salt ${g}. Supply 100000000000000000000000000000 base units (18 decimals). Static LP fee 1%; protocol adds 20% of LP fees. Reward allocation: ${s} 10000 bps, both assets. Position 10000 bps, ticks -230400 to -120000, spacing 200. Sniper fees 666777 to 41673 over 15 seconds. ${B.summary} ${ne(e,B)}`}},re=async(n,s)=>{if(V(n,["token","poolId"]),n.poolId!==void 0&&n.token===void 0)throw new r("A pool ID requires its Clanker token.");let l=[C],d=[];if(n.token!==void 0){let o=b(n.token);if(o.toLowerCase()===C.address.toLowerCase())throw new r("Provide the launched Clanker token, not WETH.");if(n.poolId!==void 0){let u=ee(n.poolId,"pool ID for fee collection"),y=await t().readContract({address:h.factory.address,abi:U,functionName:"tokenDeploymentInfo",args:[o]});if(!Array.isArray(y)||y.length!==4||typeof y[0]!="string"||y[0].toLowerCase()!==o.toLowerCase())throw new r("The factory did not identify this Clanker token.");let a=b(y[1]),D=b(y[2]),I=await t().readContract({address:a,abi:k,functionName:"mevModuleEnabled",args:[u]});if(typeof I!="boolean")throw new r("The hook returned an invalid MEV guard state.");I&&d.push(m(a,v({abi:k,functionName:"mevModuleOperational",args:[u]}),"Update the Clanker pool MEV guard before collection.")),d.push(m(D,v({abi:k,functionName:"collectRewards",args:[o]}),"Collect pending LP fees into the fee locker."))}l.push(await x(o))}let g;if(d.length){if(await t().getChainId()!==p)throw new r("Fee simulation endpoint is on the wrong chain.");let o=[...d.map(a=>({from:s,gas:F(_),to:a.to,data:a.data,value:F(BigInt(a.value))})),...l.map(a=>({from:s,gas:F(_),to:h.fee_locker.address,data:v({abi:k,functionName:"availableFees",args:[s,a.address]}),value:"0x0"}))],u=await t().request({method:"eth_simulateV1",params:[{blockStateCalls:[{calls:o}],validation:!1,traceTransfers:!1},"latest"]},{retryCount:0});if(!Array.isArray(u)||u.length!==1||!S(u[0])||!Array.isArray(u[0].calls)||u[0].calls.length!==o.length)throw new r("The endpoint returned an unexpected fee simulation response.");let y=u[0].calls;if(!y.every(a=>S(a)&&a.status==="0x1"&&!a.error))throw new r("Clanker fee collection simulation failed.");g=y.slice(d.length).map(a=>{if(!S(a)||typeof a.returnData!="string"||!/^0x[0-9a-fA-F]{64}$/.test(a.returnData))throw new r("The endpoint returned an invalid fee balance.");return q(ie({abi:k,functionName:"availableFees",data:a.returnData}))})}else g=await Promise.all(l.map(o=>w(s,o.address)));let f=l.flatMap((o,u)=>BigInt(g[u])>0n?[{token:o,amount:g[u]}]:[]);if(!f.length)throw new r("No claimable fees for this wallet; pending LP fees may require the MEV window to end.");for(let{token:o}of f)d.push(m(h.fee_locker.address,v({abi:k,functionName:"claim",args:[s,o.address]}),`Claim ${o.symbol} fees to ${s}.`));let c=await e.preview(d,s);return{txs:d,preview:c,fees:f,summary:`Claim fees to ${s}. WETH fees aggregate across all Clanker launches for this recipient. ${c.summary} ${ne(e,c)}`}},N=(n,s,l,d)=>({name:`clanker_${n}`,inputSchema:{type:"object",properties:s,required:l,additionalProperties:!1},execute:(g,f)=>i(async()=>d(g,b(f)))});return{tools:[N("launch",{name:{type:"string"},symbol:{type:"string"},salt:Z,image:{type:"string"},metadata:{type:"string"},context:{type:"string"},vanity:{const:!1},initialBuy:{...X,description:"Native ETH base units, 18 decimals."},minAmountOut:{...X,description:"Minimum new token base units, 18 decimals; derived from simulation when omitted."},slippageBps:{type:"integer",minimum:0,maximum:9999,default:E}},["name","symbol","salt"],se),N("claim",{token:{...Y,description:"Optional launched token to claim already-collected token fees or collect LP fees."},poolId:{...Z,description:"Optional pool ID used with token to sync the MEV guard and collect pending LP fees before claiming."}},[],re),N("browse",{q:{type:"string"},limit:{type:"integer",minimum:1,maximum:20},cursor:{type:"string"},deployer:Y},[],j)],positions:n=>i(async()=>{b(n);let s=new Map,l=new Set,d;do{let c=await j({deployer:n,limit:20,...d?{cursor:d}:{}});for(let o of c.tokens)o.msg_sender.toLowerCase()===n.toLowerCase()&&s.set(o.contract_address.toLowerCase(),o);if(c.cursor&&l.has(c.cursor))throw new r("The Clanker indexer repeated a pagination cursor.");c.cursor&&l.add(c.cursor),d=c.cursor??void 0}while(d);let g=[],f=[C];for(let[c,o]of s){let u=await x(o.contract_address),y=q(await t().readContract({address:u.address,abi:H,functionName:"balanceOf",args:[n]}));g.push({module:"clanker",id:`launch:${c}`,chainId:p,assets:[{token:u,amount:y}],description:`Indexed launch ${o.name}; wallet token balance, not locked LP principal.`}),f.some(a=>a.address.toLowerCase()===u.address.toLowerCase())||f.push(u)}for(let c of f){let o=await w(n,c.address);BigInt(o)>0n&&g.push({module:"clanker",id:`fees:${c.address.toLowerCase()}`,chainId:p,assets:[{token:c,amount:o}],description:"Collected fees across launches for this recipient. Pending LP fees excluded; token-side discovery covers indexed launches by this wallet."})}return g})}},ke=e=>K("clanker",[ue(e)]);export{ce as a,ue as b,ke as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as m}from"./
|
|
1
|
+
import{a as m}from"./I5CQ64EU.js";import{a as i}from"./NGAI6GTU.js";import{encodeFunctionData as d,erc20Abi as f,isAddress as g,parseAbi as h}from"viem";var p=h(["function deposit(uint256 assets,address receiver) returns (uint256 shares)","function redeem(uint256 shares,address receiver,address owner) returns (uint256 assets)"]),l=(1n<<256n)-1n;function a(e){if(typeof e!="string"||!g(e,{strict:!1}))throw new i("Provide a valid contract or wallet address.")}function o(e){let t=m(e);if(t>l)throw new i("Amount exceeds the uint256 range.");return t}function u(e){a(e.to);let t=e.chainId??4663;if(!Number.isSafeInteger(t)||t<=0)throw new i("Provide a positive integer chain ID.");if(typeof e.data!="string"||!/^0x([0-9a-fA-F]{2})*$/.test(e.data))throw new i("Transaction data must be hex-encoded bytes.");if(typeof e.description!="string"||!e.description.trim())throw new i("Provide a transaction description.");return{to:e.to,data:e.data,value:o(e.value).toString(),chainId:t,description:e.description}}function A(e,t,s,r=4663){a(t);let n=o(s);return u({to:e,data:d({abi:f,functionName:"approve",args:[t,n]}),value:"0",chainId:r,description:`Approve ${n} token base units for ${t}.`})}function w(e,t,s,r,n=4663){a(r);let c=o(s);return{txs:[A(t,e,s,n),u({to:e,data:d({abi:p,functionName:"deposit",args:[c,r]}),value:"0",chainId:n,description:`Deposit ${c} asset base units into ${e}.`})],summary:"Approve the exact asset amount, then deposit into the vault."}}function y(e,t,s,r=4663){a(s);let n=o(t);return{txs:[u({to:e,data:d({abi:p,functionName:"redeem",args:[n,s,s]}),value:"0",chainId:r,description:`Redeem the full ${n} share base units from ${e}.`})],summary:"Redeem the supplied full share balance to the wallet."}}export{a,u as b,A as c,w as d,y as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as he,b as Z,g as ee,h as te,i as we,m as F,n as ne,y as oe,z as ke}from"./2IRORNOH.js";import{a as be,b as $}from"./GDP4JSAX.js";import{a as L}from"./A5ITAEUQ.js";import{a as le}from"./I5CQ64EU.js";import{a as w,i as Y}from"./ZUC6ILK2.js";import{a as fe}from"./B4MLWDPM.js";import{a as i}from"./NGAI6GTU.js";import{a as me}from"./JXOEJPJ4.js";import{randomUUID as Se}from"node:crypto";import{encodeAbiParameters as H,encodeFunctionData as se,erc20Abi as ge,getAddress as Pe,parseAbi as R,parseAbiParameters as K,zeroAddress as U}from"viem";var ve=Y[w].pons,N=Y[w].ponsTrade,Ie=R(["function getLaunchedToken(address) view returns ((address token,address curve,address deployer,address creatorFeeRecipient,address pairToken,uint256 graduationThreshold,uint24 poolFee,int24 tickSpacing,uint16 creatorTaxBps,bool buybackEnabled,uint8 phase,uint256 sweptQuote,uint256 sweptTokens,uint256 sweptAt,bool exists))"]),z=R(["function getReserves() view returns (uint256 quoteReserve,uint256 tokenReserve)","function feeBps() view returns (uint256)","function creatorTaxBps() view returns (uint256)","function currentSnipeTaxBps(address) view returns (uint256)","function sellableTokens() view returns (uint256)","function buy(uint256 quoteIn,uint256 minTokensOut,address recipient) payable returns (uint256)","function sell(uint256 tokensIn,uint256 minQuoteOut,address recipient) returns (uint256)"]),Be=R(["function quoteExactInputSingle(((address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks) poolKey,bool zeroForOne,uint128 exactAmount,bytes hookData) params) returns (uint256 amountOut,uint256 gasEstimate)"]),qe=R(["function execute(bytes commands,bytes[] inputs,uint256 deadline) payable"]),Ee=R(["function approve(address token,address spender,uint160 amount,uint48 expiration)"]),Ne=K("((address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks) poolKey,bool zeroForOne,uint128 amountIn,uint128 amountOutMinimum,uint256 minHopPriceX36,bytes hookData)"),M={address:be,chainId:w,decimals:18,symbol:"ETH"},ye="There is no on-chain expiry. The signed transaction is protected by its minimum output.",Oe=`Quote expiry is enforced by Oak before signing only. ${ye}`,x=10000n,re=(1n<<256n)-1n,Te=(1n<<128n)-1n,y=(a,u)=>({token:a,amount:u.toString()}),xe=(a,u)=>(a+u-1n)/u,Ce={type:"object",additionalProperties:!1,required:["token","amountIn"],properties:{token:{type:"string",pattern:"^0x[0-9a-fA-F]{40}$",description:"Pons launch token address on chain 4663."},amountIn:{type:"string",pattern:"^[0-9]+$",description:"Positive base units: native ETH for buy, launch token for sell."},slippageBps:{type:"integer",minimum:0,maximum:9999,default:Z}}};async function Ae(a,u,k,o,A=!1,s=!1,f){if(L(k),Object.keys(u).some(l=>!["token","amountIn","slippageBps"].includes(l)))throw new i("Provide only token, amountIn and optional slippageBps.");if(typeof u.token!="string")throw new i("Provide a launch token address.");L(u.token);let e=Pe(u.token),t=le(u.amountIn);if(t===0n||t>re)throw new i("Trade amount must be positive and within the uint256 range.");let d=u.slippageBps??Z;if(typeof d!="number"||!Number.isInteger(d)||d<0||d>=1e4)throw new i("Slippage must be an integer from 0 to 9999 basis points.");let g=l=>l*(x-BigInt(d))/x,n=a.clientFor(w),c=f===void 0?await n.getBlock():await n.getBlock({blockNumber:f});if(f!==void 0&&c.number!==f)throw new i("Pons quote snapshot is unavailable.");let r=await n.readContract({address:ve.factory.address,abi:Ie,functionName:"getLaunchedToken",args:[e],blockNumber:c.number});if(!r.exists||r.token.toLowerCase()!==e.toLowerCase())throw new i("This address is not a Pons launch token.");if(s&&r.phase!==0)throw new ee("Pons curve quotes are only available before graduation.");if(r.phase===1)throw new i("Pons graduation is pending; the curve is closed and the pool is not ready.");if(r.phase===3)throw new i("This Pons launch was rescued and has no active trade route.");if(r.phase!==0&&r.phase!==2)throw new i("This Pons launch has an unknown trade phase.");if(r.pairToken.toLowerCase()!==U)throw new i("This trade route supports native ETH pairs only.");let[E,X]=await Promise.all([n.readContract({address:e,abi:ge,functionName:"symbol",blockNumber:c.number}),n.readContract({address:e,abi:ge,functionName:"decimals",blockNumber:c.number})]),v={address:e,chainId:w,symbol:me(E),decimals:X},S=o?M:v,O=o?v:M,P=[],j=(l,B,b,T)=>a.unsignedTx({to:l,data:B,value:b.toString(),chainId:w,description:T}),m,p,D,I=t,ie=null,G;if(r.phase===0){let l=h=>n.readContract({address:r.curve,abi:z,functionName:h,blockNumber:c.number}),[[B,b],T,q,ue,_]=await Promise.all([n.readContract({address:r.curve,abi:z,functionName:"getReserves",blockNumber:c.number}),l("feeBps"),l("creatorTaxBps"),o?n.readContract({address:r.curve,abi:z,functionName:"currentSnipeTaxBps",args:[k],blockNumber:c.number}):Promise.resolve(0n),o?l("sellableTokens"):Promise.resolve(0n)]);if(B<=0n||b<=0n||T+q>x-100n)throw new i("Pons curve reserves or fee settings are unavailable.");let ce=x-T-q-100n,J=ue<ce?ue:ce,de=h=>({base:h*T/x,creator:h*q/x,snipe:h*J/x}),pe=h=>{let C=de(h);return h-C.base-C.creator-C.snipe},Q;if(o){if(_<=0n||_>=b)throw new i("The curve has no available sellable tokens.");let h=pe(t);if(m=h*b/(B+h),m>=_){m=_;let C=m*B/(b-m)+1n;I=xe(C*x,x-T-q-J),I>t&&(I=t)}Q=I,p=g(m),D=xe(p*t,I)}else Q=t*B/(b+t),m=pe(Q),p=g(m),P.push(a.approval(e,r.curve,t.toString(),w));let W=de(Q);ie={base:y(M,W.base),creator:y(M,W.creator),snipe:y(M,W.snipe)},G=`Curve fees included: ${T} base, ${q} creator and ${J} opening-tax basis points, each rounded separately.`,P.push(j(r.curve,se({abi:z,functionName:o?"buy":"sell",args:[t,D??p,k]}),o?t:0n,o?"Buy Pons curve tokens with native ETH.":"Sell Pons curve tokens for native ETH."))}else{if(t>Te)throw new i("Trade amount exceeds the router uint128 range.");let l={currency0:U,currency1:e,fee:r.poolFee,tickSpacing:r.tickSpacing,hooks:ve.memeHook.address};if(m=(await n.simulateContract({address:N.quoter.address,abi:Be,functionName:"quoteExactInputSingle",args:[{poolKey:l,zeroForOne:o,exactAmount:t,hookData:"0x"}],account:k,gas:fe,blockNumber:c.number})).result[0],p=g(m),p>Te)throw new i("Minimum output exceeds the router uint128 range.");let b=c.timestamp+300n;if(b>=1n<<48n)throw new i("Permit2 expiry exceeds its timestamp range.");o||(P.push(a.approval(e,N.permit2.address,t.toString(),w)),P.push(j(N.permit2.address,se({abi:Ee,functionName:"approve",args:[e,N.universal_router.address,t,Number(b)]}),0n,"Approve the exact token amount to the Pons router through Permit2 for five minutes.")));let T=[H(Ne,[{poolKey:l,zeroForOne:o,amountIn:t,amountOutMinimum:p,minHopPriceX36:0n,hookData:"0x"}]),H(K("address,uint256"),[o?U:e,t]),H(K("address,uint256"),[o?e:U,p])],q=H(K("bytes,bytes[]"),["0x060c0f",T]);P.push(j(N.universal_router.address,se({abi:qe,functionName:"execute",args:["0x10",[q],b]}),o?t:0n,"Trade through Pons Universal Router v2.1.2.")),G="Quoter output is net of Pons hook fees; no additional fee is subtracted."}if(m<=0n||p<=0n||p>re||(D??p)>re)throw new i("Trade output or minimum is outside the supported positive range.");let ae=A?{changes:[],summary:"Quote only; preview is required before sending."}:await a.preview(P,k),V=t-I;return{txs:P,changes:ae.changes,summary:`${o?"Buy":"Sell"} ${v.symbol} (${v.address}) on chain ${w}. ${G} ${r.phase===0?`${ye} `:""}${V>0n?`Expected native refund: ${a.formatAmount(V.toString(),18)} ETH; minimum output uses the expected spend after refund. `:""}${ae.summary}`,quote:{phase:r.phase,amountIn:y(S,t),amountOut:y(O,m),minAmountOut:y(O,p),minimumKind:"absolute",calldataMinAmountOut:y(O,D??p),expectedSpend:y(S,I),expectedRefund:y(S,V),fees:ie,blockNumber:c.number.toString(),blockTimestamp:c.timestamp.toString()}}}function Xe(a){return $e(a,!0)}function $e(a,u=!1,k){let o=new Map,A=s=>{if(BigInt(F())>=BigInt(s.expiresAt))throw new te};return{name:"pons",async quote(s,f){s={...s,from:$(s.from),to:$(s.to)};let e=ne(s.from);if(e===ne(s.to))throw new ee("Pons curve quotes require native ETH and a launch token.");let t=F(),d=await Ae(a,{token:e?s.to:s.from,amountIn:s.amountIn,slippageBps:s.slippageBps},f,e,!0,u,k),g=d.txs.at(-1),n=d.quote,c=String(BigInt(k===void 0?t:n.blockTimestamp)+BigInt(he)),r=n.minAmountOut.amount,E=n.fees,X=E?`Pons curve fees included in net output: ${E.base.amount} base, ${E.creator.amount} creator and ${E.snipe.amount} opening tax, in native ETH base units (18 decimals). Oak swap fee: 0 (venue fee is never Oak income). ${Oe}`:"Quoter output is net of Pons hook fees; no additional fee is subtracted. Oak swap fee: 0.",v=ke({...s,quoteId:`pons:${Se()}`,provider:"pons",wallet:f,chainId:w,router:g.to,spender:n.phase===0?g.to:N.permit2.address,expiresAt:c,data:g.data,value:g.value,amountOut:n.amountOut.amount,minAmountOut:r,blockNumber:n.blockNumber,...n.phase===0?{ponsCurveToken:e?s.to:s.from,calldataMinAmountOut:n.calldataMinAmountOut.amount}:{ponsPoolToken:e?s.to:s.from},expectedSpend:n.expectedSpend.amount,expectedRefund:n.expectedRefund.amount,feeDisclosure:X,oakFee:"0"});oe(g,v),A(v);for(let[S,O]of o)BigInt(F())>=BigInt(O.quote.expiresAt)&&o.delete(S);for(;o.size>=we;)o.delete(o.keys().next().value);return o.set(v.quoteId,{quote:{...v},txs:d.txs.map(S=>({...S})),summary:d.summary}),v},async build(s,f){let e=o.get(s);if(!e)throw new te;if(A(e.quote),L(f),f.toLowerCase()!==e.quote.wallet.toLowerCase())throw new i("Quote was issued for a different wallet.");let t=e.txs.map(n=>({...n}));oe(t.at(-1),e.quote);let d=await a.preview(t,f);if(A(e.quote),d.changes.filter(n=>$(n.token.address).toLowerCase()===$(e.quote.to).toLowerCase()).reduce((n,c)=>n+BigInt(c.amount),0n)<BigInt(e.quote.minAmountOut))throw new i("Preview retained output is below the accepted minimum.");return{txs:t,summary:`${e.summary} ${d.summary} ${e.quote.feeDisclosure}`}}}}var Me=a=>({tools:[!0,!1].map(u=>({name:u?"pons_buy":"pons_sell",inputSchema:Ce,async execute(k,o){try{return await Ae(a,k,o,u)}catch(A){throw new i(a.plainError(A))}}}))}),je=Me;export{Xe as a,$e as b,Me as c,je as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as s}from"./
|
|
1
|
+
import{c as s}from"./MK6L6TGI.js";import{a as n}from"./5HCXZWUH.js";var i=new WeakMap;async function h(a,r,p){let e=new URL(r);if(!(e.origin==="https://aggregator-api.kyberswap.com"&&e.pathname==="/robinhood/api/v1/routes")&&!(e.origin==="https://api.velora.xyz"&&e.pathname==="/prices"))throw new Error("Only supported public price routes may be shared.");let t=i.get(a);t||(t=new n(3e3),i.set(a,t));let o=await t.read(r,()=>s(a,r,{method:"GET"},p));return{value:o.value,expiresAt:Math.floor(o.started/1e3)+60}}export{h as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as f}from"./NGAI6GTU.js";var s=10000000n;function p(n,i){let t=s;return typeof n=="bigint"&&n>0n&&n<t&&(t=n),typeof i=="bigint"&&i>0n&&i*2n<t&&(t=i*2n),t}function u(n,i,t,r){return`needs ETH for network fees: need at least ${t} wei including transaction value; held ${r} wei. Send ETH to ${n} on chain ${i}.`}function m(n,i,t,r,g,d){let o=t+21000n*r;if(i<o)throw new f(u(g,d,o,i));let e=r>0n?(i-t)/r:n;return e<n?e:n}export{s as a,p as b,u as c,m as d};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{b as ge,o as be}from"./
|
|
1
|
+
import{b as ge,o as be}from"./2IRORNOH.js";import{a as fe}from"./GDP4JSAX.js";import{c as he}from"./MK6L6TGI.js";import{a as pe}from"./A5ITAEUQ.js";import{a as me}from"./I5CQ64EU.js";import{a as l,i as re,l as u}from"./ZUC6ILK2.js";import{a}from"./NGAI6GTU.js";import{a as I}from"./JXOEJPJ4.js";import{decodeEventLog as Re,encodeAbiParameters as Ee,encodeFunctionData as j,erc20Abi as V,getAddress as Ae,keccak256 as _e,parseAbi as Q,parseAbiItem as Le,toHex as Oe,zeroAddress as N}from"viem";var ce=re[l].pons.launchAndBuyRouter.address,ye=re[l].ponsTrade.state_view.address,X={address:N,chainId:l,symbol:"ETH",decimals:18},f=Q(["function getLaunchedToken(address) view returns ((address token,address curve,address deployer,address creatorFeeRecipient,address pairToken,uint256 graduationThreshold,uint24 poolFee,int24 tickSpacing,uint16 creatorTaxBps,bool buybackEnabled,uint8 phase,uint256 sweptQuote,uint256 sweptTokens,uint256 sweptAt,bool exists))","function previewLaunchEconomics(uint256,address) view returns (bytes32)","function launchFee() view returns (uint256)","function canLaunch(address) view returns (bool)","function launchConfigCount() view returns (uint256)","function approvedPairTokens(address) view returns (bool)","function pairTokenEconomics(address) view returns (uint256 phantomQuote,uint256 graduationThreshold,uint8 decimals)","function transferCreatorFeeRecipient(address token,address newRecipient)","function setBuybackEnabled(address token,bool enabled)","function getLaunchConfig(uint256) view returns ((uint256 supply,uint256 curveFeeBps,uint256 phantomQuote,uint256 graduationThreshold,uint24 poolFee,int24 tickSpacing,bool enabled))","function maxCreatorTaxBps() view returns (uint256)","function getLaunchFeePolicy(address) view returns ((address,uint16,uint16,uint16,uint16))","function memeHook() view returns (address)","function createGraduatedPool(address)"]),z=Q(["function factory() view returns (address)","function feeEscrow() view returns (address)","function getReserves() view returns (uint256,uint256)","function realQuoteReserve() view returns (uint256)","function feeBps() view returns (uint256)"]),Ue=Q(["function launchFactory() view returns (address)"]),qe=Q(["function currentFeePolicy() view returns ((address,uint16,uint16,uint16,uint16))"]),we=Q(["function getSlot0(bytes32) view returns (uint160,int24,uint24,uint24)","function getLiquidity(bytes32) view returns (uint128)"]),ae=Q(["function launchToken((string,string,string,string,(string,string,string,string,string),address,uint16,bool,bytes32,bytes32),uint256,address) payable","function launchToken((string,string,string,string,(string,string,string,string,string),address,uint16,bool,bytes32,bytes32),uint256,address,address[]) payable","function launchAndBuy((string,string,string,string,(string,string,string,string,string),address,uint16,bool,bytes32,bytes32),uint256,address,uint256,uint256,address,address[]) payable"]),xe=Le("event TokenLaunched(address indexed token,address indexed curve,address indexed deployer,address pairToken,uint256 launchConfigId,uint256 graduationThreshold)"),He=["curve","pending pool creation","graduated","rescued"],Me=10000n,ke=2000n,M={type:"string",pattern:"^[0-9]+$"},_={type:"string",pattern:"^0x[0-9a-fA-F]{40}$"};function F(n){if(typeof n!="string")throw new a("Provide a token or wallet address.");return pe(n),Ae(n)}function p(n,e){return n.toLowerCase()===e.toLowerCase()}function D(n){if(typeof n!="string")throw new a("Amounts must be integer strings in base units.");let e=me(n);if(e>=1n<<256n)throw new a("Amount exceeds the uint256 range.");return e}function Te(n,e){if(typeof n!="string"||!n.trim())throw new a(`Provide ${e}.`);return n}function L(n,e){return{token:n,amount:e.toString()}}function Be(n,e,t,i,o){let r=n*BigInt(t)/10000n,s=i?(n-r)*BigInt(o)/10000n:0n;return{baseBps:n.toString(),creatorTaxBps:e.toString(),totalBps:(n+BigInt(e)).toString(),protocolBps:r.toString(),creatorBps:(n-r-s+BigInt(e)).toString(),buybackBps:s.toString(),buybackEnabled:i}}async function J(n,e,t){if(p(e,N))return X;let i=n.clientFor(l),[o,r]=await Promise.all([i.readContract({address:e,abi:V,functionName:"symbol",blockNumber:t}),i.readContract({address:e,abi:V,functionName:"decimals",blockNumber:t})]);return{address:Ae(e),chainId:l,symbol:I(o),decimals:r}}async function Z(n,e,t){let i=n.clientFor(l),[o,r]=await Promise.all([i.readContract({address:e,abi:Ue,functionName:"launchFactory",blockNumber:t}),i.readContract({address:u,abi:f,functionName:"getLaunchedToken",args:[e],blockNumber:t})]);if(!p(o,u)||!r.exists||!p(r.token,e))throw new a("This token is not a launch from the supported Pons factory.");if(r.phase>3)throw new a("Pons returned an unknown launch phase.");return r}async function Fe(n,e,t){let i=n.clientFor(l),o=await Z(n,e,t),[r,s,c,d,h,T,b]=await Promise.all([J(n,e,t),J(n,o.pairToken,t),i.readContract({address:e,abi:V,functionName:"totalSupply",blockNumber:t}),i.readContract({address:o.curve,abi:z,functionName:"factory",blockNumber:t}),i.readContract({address:o.curve,abi:z,functionName:"feeEscrow",blockNumber:t}),i.readContract({address:u,abi:f,functionName:"memeHook",blockNumber:t}),i.readContract({address:u,abi:f,functionName:"getLaunchFeePolicy",args:[e],blockNumber:t})]);if(!p(d,u))throw new a("The Pons curve does not belong to the supported factory.");let m=BigInt(b[3]),C=o.sweptQuote,g=null,S=null,v=null;if(o.phase===0){let[$,w,A]=await Promise.all([i.readContract({address:o.curve,abi:z,functionName:"getReserves",blockNumber:t}),i.readContract({address:o.curve,abi:z,functionName:"realQuoteReserve",blockNumber:t}),i.readContract({address:o.curve,abi:z,functionName:"feeBps",blockNumber:t})]);if(C=w,m=A,o.graduationThreshold<=0n||$[1]<=0n)throw new a("Pons returned unavailable curve reserves or threshold.");g=w*1000000n/o.graduationThreshold,g>1000000n&&(g=1000000n),S=L(s,$[0]*10n**BigInt(r.decimals)/$[1])}else if(o.phase===2){let $=[e,o.pairToken].sort((H,x)=>BigInt(H)<BigInt(x)?-1:1),w=_e(Ee([{type:"address"},{type:"address"},{type:"uint24"},{type:"int24"},{type:"address"}],[$[0],$[1],o.poolFee,o.tickSpacing,T])),[A,R]=await Promise.all([i.readContract({address:ye,abi:we,functionName:"getSlot0",args:[w],blockNumber:t}),i.readContract({address:ye,abi:we,functionName:"getLiquidity",args:[w],blockNumber:t})]);if(A[0]===0n)throw new a("The graduated Pons pool price is unavailable.");let E=A[0]**2n,q=10n**BigInt(r.decimals);S=L(s,p($[0],e)?E*q/(1n<<192n):(1n<<192n)*q/E),v={id:w,sqrtPriceX96:A[0].toString(),tick:A[1],protocolFee:A[2],lpFee:A[3],liquidity:R.toString()},g=1000000n}else o.phase===1&&(g=1000000n);return{token:r,pairToken:s,blockNumber:t.toString(),factory:u,curve:o.curve,hook:T,escrow:h,creator:o.deployer,creatorFeeRecipient:o.creatorFeeRecipient,phase:o.phase,phaseName:He[o.phase],tradable:o.phase===0||o.phase===2,graduationThreshold:L(s,o.graduationThreshold),raised:L(s,C),sweptTokens:L(r,o.sweptTokens),sweptAt:o.sweptAt.toString(),progressPpm:g?.toString()??null,totalSupply:L(r,c),fees:Be(m,o.creatorTaxBps,b[1],o.buybackEnabled,b[2]),pool:v,spot:S,priceKind:"Marginal spot per whole token; not an execution quote or time average."}}async function je(n,e){try{return await Fe(n,F(e),await n.clientFor(l).getBlockNumber({cacheTime:0}))}catch(t){throw new a(n.plainError(t))}}async function ve(n,e={}){try{let t=n.clientFor(l),i=await t.getBlockNumber({cacheTime:0}),o=e.toBlock===void 0?i:D(e.toBlock),r=e.fromBlock===void 0?o>=ke?o-ke+1n:0n:D(e.fromBlock),s=e.limit??20;if(typeof s!="number"||!Number.isInteger(s)||s<1||s>100)throw new a("Choose a launch limit from 1 to 100.");if(r>o||o>i||o-r+1n>Me)throw new a("Choose an ordered range of at most 10000 mined blocks.");let c=await t.getLogs({address:u,event:xe,fromBlock:r,toBlock:o,strict:!0}),d=new Map;for(let b of c.filter(m=>p(m.address,u)&&!m.removed&&m.blockNumber!==null&&m.blockNumber>=r&&m.blockNumber<=o).sort((m,C)=>m.blockNumber===C.blockNumber?(C.logIndex??0)-(m.logIndex??0):m.blockNumber>C.blockNumber?-1:1)){let m=F(b.args.token);d.set(m.toLowerCase(),m)}let h=[...d.values()];return{items:await Promise.all(h.slice(0,s).map(b=>Fe(n,b,i))),fromBlock:r.toString(),toBlock:o.toString(),statusBlock:i.toString(),truncated:h.length>s,coverage:"Only launches in the requested block range; this is not a complete launch history."}}catch(t){throw new a(n.plainError(t))}}async function Y(n,e,t,i){let o=(Array.isArray(e)?e:[e]).map(n.unsignedTx),r=await n.preview(o,t),s=r.changes.map(c=>{let d=c.amount.startsWith("-");return`${d?"-":""}${n.formatAmount(d?c.amount.slice(1):c.amount,c.token.decimals)} ${c.token.symbol} (${c.token.chainId}:${c.token.address})`});return{txs:o,preview:r,summary:`${i} ${r.summary}${s.length?` Changes: ${s.join(", ")}.`:""}`}}var K=["twitter","telegram","discord","website","farcaster"],Pe=5242880,Ce="https://ponsfamily.com/api/ipfs/image";function se(n,e){if(n==="")return"";if(typeof n!="string"||n.length>2048)throw new a(`Provide a public HTTPS or IPFS ${e}.`);try{let t=new URL(n);if(!["https:","ipfs:"].includes(t.protocol)||!t.hostname||t.username||t.password)throw new Error}catch{throw new a(`Provide a public HTTPS or IPFS ${e}.`)}return n}function De(n){if(n===void 0)return;if(!n||typeof n!="object"||Array.isArray(n))throw new a("Provide image mimeType and base64.");let e=n,t={"image/png":"png","image/jpeg":"jpg","image/webp":"webp"};if(Object.keys(e).some(s=>!["mimeType","base64"].includes(s))||typeof e.mimeType!="string"||!t[e.mimeType])throw new a("Use a PNG, JPEG, or WebP image.");if(typeof e.base64!="string"||!e.base64.length||e.base64.length>4*Math.ceil(Pe/3)||e.base64.length%4!==0||!/^[A-Za-z0-9+/]*={0,2}$/.test(e.base64))throw new a("Provide a base64 image of 1 to 5242880 bytes.");let i=atob(e.base64);if(!i.length||i.length>Pe||btoa(i)!==e.base64)throw new a("Provide a base64 image of 1 to 5242880 bytes.");let o=Uint8Array.from(i,s=>s.charCodeAt(0));if(!(e.mimeType==="image/png"?i.startsWith(`\x89PNG\r
|
|
2
2
|
|
|
3
3
|
`):e.mimeType==="image/jpeg"?o[0]===255&&o[1]===216&&o[2]===255:i.startsWith("RIFF")&&i.slice(8,12)==="WEBP"))throw new a("Image bytes do not match the declared PNG, JPEG, or WebP type.");return{bytes:o,mimeType:e.mimeType,extension:t[e.mimeType]}}async function Qe(n,e,t){if(typeof e!="string"||!/^0x[0-9a-fA-F]{64}$/.test(e))throw new a("Provide a mined Pons launch transaction hash.");let o=await n.clientFor(l).getTransactionReceipt({hash:e});if(o.status!=="success"||!p(o.from,t))throw new a("The Pons launch must be a successful transaction from this wallet.");let r=o.logs.flatMap(d=>{if(!p(d.address,u))return[];try{return[Re({abi:[xe],data:d.data,topics:d.topics,strict:!0}).args]}catch{return[]}}).filter(d=>p(d.deployer,t));if(r.length!==1)throw new a("The receipt does not contain exactly one Pons launch for this wallet.");let s=r[0].token,c=await Z(n,s,o.blockNumber);return{transactionHash:e,token:await J(n,s,o.blockNumber),curve:c.curve,creator:c.deployer,creatorFeeRecipient:c.creatorFeeRecipient,chainId:l,summary:`Pons launch mined: ${s}. Creator fee recipient ${c.creatorFeeRecipient}.`}}async function We(n,e,t){let i=Te(e.name,"a coin name"),o=Te(e.symbol,"a coin symbol");if(e.creatorFeeRecipient===void 0)throw new a("Provide an explicit nonzero creatorFeeRecipient; it is never defaulted to the agent wallet.");let r=F(e.creatorFeeRecipient);if(p(r,N))throw new a("Provide a nonzero creator fee recipient.");let s=p(r,t)?"":`Warning: creator fees go to ${r}, not the signing wallet ${t}; this wallet cannot claim those fees.`,c=F(e.pairToken??N),d=D(e.launchConfigId??"0"),h=D(e.initialBuy??"0"),T=F(e.buyRecipient??t);if(p(T,N))throw new a("Provide a nonzero initial buy recipient.");if(h===0n&&e.buyRecipient!==void 0)throw new a("A buy recipient requires an initial buy.");let b=D(e.minTokensOut??"0");if(h>0n&&e.minTokensOut!==void 0&&b<=1n)throw new a("Initial buy minimum must exceed one token base unit.");if(h>0n&&!p(T,t)&&e.minTokensOut===void 0)throw new a("Provide minTokensOut for an initial buy sent to another wallet.");if(h===0n&&b!==0n)throw new a("A launch without an initial buy must have a zero token minimum.");let m=e.creatorTaxBps??100;if(typeof m!="number"||!Number.isInteger(m)||m<0||m>65535)throw new a("Creator tax must be an integer number of basis points.");let C=e.buybackEnabled??!1;if(typeof C!="boolean")throw new a("Buyback enabled must be true or false.");let g=e.metadata??["",""],S=e.links??["","","","",""];if(!Array.isArray(g)||g.length!==2||!g.every(y=>typeof y=="string")||!Array.isArray(S)||S.length!==5||!S.every(y=>typeof y=="string"))throw new a("Provide two metadata strings and five link strings in ABI order.");if(e.metadata!==void 0&&(e.logo!==void 0||e.description!==void 0||e.image!==void 0))throw new a("Use named logo, description and image inputs or legacy metadata, not both.");if(e.links!==void 0&&e.socials!==void 0)throw new a("Use named socials or legacy links, not both.");let v=se(e.logo??g[0],"coin image URI"),$=e.description??g[1];if(typeof $!="string")throw new a("Provide a coin description string.");let w=e.socials;if(w!==void 0&&(!w||typeof w!="object"||Array.isArray(w)||Object.keys(w).some(y=>!K.includes(y))))throw new a("Provide twitter, telegram, discord, website and farcaster social links.");let A=K.map((y,k)=>se(w===void 0?S[k]:w[y]??"",`${y} link`)),R=De(e.image);if(R&&v)throw new a("Provide an image upload or an existing logo URI, not both.");let E=e.snipeTaxExemptions??[];if(!Array.isArray(E)||E.length>32)throw new a("Provide at most 32 snipe tax exemption addresses.");let q=E.map(F),H=e.salt??Oe(crypto.getRandomValues(new Uint8Array(32)));if(typeof H!="string"||!/^0x[0-9a-fA-F]{64}$/.test(H))throw new a("Salt must be 32 hex-encoded bytes.");let x=n.clientFor(l),B=await x.getBlockNumber({cacheTime:0}),[ue,Ie]=await Promise.all([x.readContract({address:u,abi:f,functionName:"canLaunch",args:[t],blockNumber:B}),x.readContract({address:u,abi:f,functionName:"launchConfigCount",blockNumber:B})]);if(!ue)throw new a("This wallet cannot launch on Pons. Ask Pons for launch access and retry when canLaunch is true.");if(d>=Ie)throw new a("Choose an existing Pons launchConfigId using pons_launch_options.");let[ee,W,Ne,Se]=await Promise.all([x.readContract({address:u,abi:f,functionName:"launchFee",blockNumber:B}),x.readContract({address:u,abi:f,functionName:"getLaunchConfig",args:[d],blockNumber:B}),x.readContract({address:u,abi:f,functionName:"maxCreatorTaxBps",blockNumber:B}),x.readContract({address:u,abi:f,functionName:"memeHook",blockNumber:B})]);if(!W.enabled)throw new a("This Pons launch configuration is disabled. Choose an enabled launchConfigId.");let O=X,de=W.phantomQuote,le=W.graduationThreshold;if(!p(c,N)){let[y,k]=await Promise.all([x.readContract({address:u,abi:f,functionName:"approvedPairTokens",args:[c],blockNumber:B}),x.readContract({address:u,abi:f,functionName:"pairTokenEconomics",args:[c],blockNumber:B})]);if(!y||k[0]<=0n||k[1]<=0n)throw new a("This pair token is not approved with usable Pons economics. Choose a supported pair.");if(O=await J(n,c,B),k[2]!==O.decimals)throw new a("Pair token decimals disagree with Pons. Ask Pons to refresh pair economics.");[de,le]=k}if(BigInt(m)>Ne)throw new a("Creator tax exceeds the current Pons maximum.");let[ne,te]=await Promise.all([x.readContract({address:u,abi:f,functionName:"previewLaunchEconomics",args:[d,c],blockNumber:B}),x.readContract({address:Se,abi:qe,functionName:"currentFeePolicy",blockNumber:B})]);if(e.expectedEconomics!==void 0&&e.expectedEconomics!==ne)throw new a("Pons launch economics changed. Refresh the launch preview.");let G=Be(W.curveFeeBps,m,te[1],C,te[2]),oe="";if(R){let y=new FormData;y.append("image",new Blob([R.bytes],{type:R.mimeType}),`coin.${R.extension}`);let k=await he(n.http,Ce,{method:"POST",body:y,redirect:"error"},P=>!!P&&typeof P=="object"&&typeof P.uri=="string");if(v=se(k.uri,"uploaded coin image URI"),!v)throw new a("Pons returned an empty image URI. Retry with a public image URI.");oe=`Image (${R.bytes.length} bytes, ${R.mimeType}) uploaded via multipart POST to ${Ce}; URI ${I(v)}. This off-chain upload persists even if launch is cancelled or fails; Pons retention/deletion is unknown.`}let ie=y=>{let k=[i,o,v,$,A,r,m,C,ne,H],P={to:h===0n?u:ce,chainId:l,value:(ee+(p(c,N)?h:0n)).toString(),data:h===0n?q.length?j({abi:ae,functionName:"launchToken",args:[k,d,c,q]}):j({abi:ae,functionName:"launchToken",args:[k,d,c]}):j({abi:ae,functionName:"launchAndBuy",args:[k,d,c,h,y,T,q]}),description:`Launch ${I(i)} through the Pons ${h===0n?"factory":"router"} from ${t}; creator fees to ${r}. ${s} ${oe}`.trim()};return h>0n&&!p(c,N)?[n.approval(c,ce,h.toString(),l),P]:[P]};if(h>0n&&e.minTokensOut===void 0){let k=(await n.preview(ie(0n).map(n.unsignedTx),t)).changes.filter(P=>P.token.chainId===l&&!p(P.token.address,N)&&!p(P.token.address,fe)&&!p(P.token.address,c)&&P.token.decimals===18&&/^\d+$/.test(P.amount)&&BigInt(P.amount)>0n);if(k.length!==1)throw new a("Pons launch preview did not identify a unique initial buy token output.");if(b=BigInt(be(k[0].amount,ge)),b<=1n)throw new a("Initial buy minimum must exceed one token base unit.")}let U=await Y(n,ie(b),t,`Unsigned Pons launch from ${t}: ${I(i)} (${I(o)}), image ${v?I(v):"none"}, description ${I($)}, links ${JSON.stringify(Object.fromEntries(K.map((y,k)=>[y,I(A[k])])))}. canLaunch=true at block ${B}; config ${d}, supply ${W.supply}, phantom quote ${de}, graduation threshold ${le} pair base units. Pair ${O.symbol} (${l}:${O.address}, ${O.decimals} decimals). Initial buy ${n.formatAmount(h.toString(),O.decimals)} ${O.symbol} to ${T}; minimum ${b} token base units (18 decimals). Launch fee ${n.formatAmount(ee.toString(),18)} ETH plus gas; exact transaction value ${ie(b).at(-1).value} wei. Curve fees ${G.totalBps} bps total, ${G.protocolBps} bps protocol, ${G.creatorBps} bps creator, ${G.buybackBps} bps buyback; creator tax ${m} bps, buybacks ${C?"on":"off"}, graduated hook fee ${te[3]} bps plus creator tax. Creator fee recipient ${r}. Extra opening-tax exemptions ${JSON.stringify(q)}. Name, metadata, pair, tax and launch economics are fixed after launch. ${oe}`);return s&&(U.preview.summary.includes(s)||(U.preview={...U.preview,summary:`${s} ${U.preview.summary}`}),U.summary.includes(s)||(U.summary=`${s} ${U.summary}`)),{...U,creatorFeeWarning:s||void 0,preview:{...U.preview,warnings:s?[s]:[]},canLaunch:ue,blockNumber:B.toString(),launchConfigId:d.toString(),pairToken:O,salt:H,logo:v&&I(v),economics:ne,launchFee:L(X,ee),initialBuy:L(O,h),minimum:{amount:b.toString(),decimals:18,token:{chainId:l,address:null,name:I(i),symbol:I(o)},addressStatus:"Read the mined token address with pons_launch transactionHash; the local bridge does this automatically."},fees:G}}async function Ge(n,e,t){let i=n.clientFor(l),o=await i.getBlockNumber({cacheTime:0}),r=F(e.pairToken??N),[s,c,d,h]=await Promise.all([i.readContract({address:u,abi:f,functionName:"canLaunch",args:[t],blockNumber:o}),i.readContract({address:u,abi:f,functionName:"launchConfigCount",blockNumber:o}),i.readContract({address:u,abi:f,functionName:"launchFee",blockNumber:o}),i.readContract({address:u,abi:f,functionName:"maxCreatorTaxBps",blockNumber:o})]),T=D(e.offset??"0"),b=await Promise.all(Array.from({length:Number(c>T?c-T>100n?100n:c-T:0n)},async(v,$)=>{let w=T+BigInt($),A=await i.readContract({address:u,abi:f,functionName:"getLaunchConfig",args:[w],blockNumber:o});return{id:w.toString(),...Object.fromEntries(Object.entries(A).map(([R,E])=>[R,typeof E=="bigint"?E.toString():E]))}})),m=p(r,N),[C,g,S]=await Promise.all([m?!0:i.readContract({address:u,abi:f,functionName:"approvedPairTokens",args:[r],blockNumber:o}),m?void 0:i.readContract({address:u,abi:f,functionName:"pairTokenEconomics",args:[r],blockNumber:o}),J(n,r,o)]);return{chainId:l,factory:u,router:ce,blockNumber:o.toString(),canLaunch:s,launchFee:L(X,d),maxCreatorTaxBps:h.toString(),configs:b,configCount:c.toString(),nextOffset:T+BigInt(b.length)<c?(T+BigInt(b.length)).toString():null,pairToken:S,pairApproved:C&&(!g||g[0]>0n&&g[1]>0n&&g[2]===S.decimals),pairEconomics:g?{phantomQuote:g[0].toString(),graduationThreshold:g[1].toString(),decimals:g[2]}:null,pairDiscovery:"Native ETH or any approved ERC-20 address with usable pairTokenEconomics; query each candidate address. The factory has no pair enumeration read."}}async function $e(n,e,t,i){let o=F(e.token),r=await Z(n,o,await n.clientFor(l).getBlockNumber({cacheTime:0}));if(!p(r.creatorFeeRecipient,t))throw new a(`Only the current creator fee recipient ${r.creatorFeeRecipient} can change this setting. Use that wallet.`);if(i){let s=F(e.creatorFeeRecipient);if(p(s,N))throw new a("Provide a nonzero creator fee recipient.");return Y(n,{to:u,chainId:l,value:"0",data:j({abi:f,functionName:"transferCreatorFeeRecipient",args:[o,s]}),description:`Transfer future creator fees and the buyback vest beneficiary for ${o} to ${s}.`},t,`Unsigned Pons fee recipient transfer to ${s}; previously credited fees stay with ${t}. This wallet loses future fee controls. Cost: gas only.`)}if(typeof e.enabled!="boolean")throw new a("Buyback enabled must be true or false.");return Y(n,{to:u,chainId:l,value:"0",data:j({abi:f,functionName:"setBuybackEnabled",args:[o,e.enabled]}),description:`Turn Pons buybacks ${e.enabled?"on":"off"} for ${o}.`},t,`Unsigned Pons buyback change: ${e.enabled?"on; funded from the creator fee share, tokens vest over five years":"off; existing vest stays locked on its schedule"}. Cost: gas only.`)}var ze=n=>{function e(t,i,o,r){return{name:t,inputSchema:{type:"object",properties:i,required:o,additionalProperties:!1,...t==="pons_launch"?{anyOf:[{required:["transactionHash"]},{required:["name","symbol","creatorFeeRecipient"]}]}:{}},execute:async(s,c)=>{try{F(c);for(let d of Object.keys(s))if(!(d in i))throw new a(`Unknown ${t} input: ${d}.`);return await r(s,c)}catch(d){throw new a(n.plainError(d))}}}}return{tools:[e("pons_browse",{fromBlock:M,toBlock:M,limit:{type:"integer",minimum:1,maximum:100}},[],t=>ve(n,t)),e("pons_status",{token:_},["token"],t=>je(n,F(t.token))),e("pons_launch_options",{pairToken:_,offset:M},[],(t,i)=>Ge(n,t,i)),e("pons_transfer_creator_fee_recipient",{token:_,creatorFeeRecipient:_},["token","creatorFeeRecipient"],(t,i)=>$e(n,t,i,!0)),e("pons_set_buyback",{token:_,enabled:{type:"boolean"}},["token","enabled"],(t,i)=>$e(n,t,i,!1)),e("pons_launch",{name:{type:"string",minLength:1},symbol:{type:"string",minLength:1},creatorFeeRecipient:_,pairToken:_,launchConfigId:M,buyRecipient:_,logo:{type:"string"},description:{type:"string"},socials:{type:"object",properties:Object.fromEntries(K.map(t=>[t,{type:"string"}])),additionalProperties:!1},image:{type:"object",properties:{mimeType:{type:"string",enum:["image/png","image/jpeg","image/webp"]},base64:{type:"string",minLength:1,maxLength:6990508}},required:["mimeType","base64"],additionalProperties:!1},snipeTaxExemptions:{type:"array",items:_,maxItems:32},transactionHash:{type:"string",pattern:"^0x[0-9a-fA-F]{64}$"},initialBuy:M,minTokensOut:M,creatorTaxBps:{type:"integer",minimum:0,maximum:65535},buybackEnabled:{type:"boolean"},expectedEconomics:{type:"string",pattern:"^0x[0-9a-fA-F]{64}$"},salt:{type:"string",pattern:"^0x[0-9a-fA-F]{64}$"},metadata:{type:"array",items:{type:"string"},minItems:2,maxItems:2},links:{type:"array",items:{type:"string"},minItems:5,maxItems:5}},[],(t,i)=>t.transactionHash===void 0?We(n,t,i):Qe(n,t.transactionHash,i)),e("pons_graduate",{token:_},["token"],async(t,i)=>{let o=F(t.token);if((await Z(n,o,await n.clientFor(l).getBlockNumber({cacheTime:0}))).phase!==1)throw new a("Graduation requires a launch pending pool creation (phase 1).");return Y(n,{to:u,chainId:l,value:"0",data:j({abi:f,functionName:"createGraduatedPool",args:[o]}),description:`Create the graduated Pons pool for ${o}.`},i,"Unsigned permissionless graduation retry; recheck status after the transaction is mined.")})],positions:async t=>{try{F(t);let i=await ve(n,{limit:100}),o=i.items.filter(r=>p(r.creator,t)||p(r.creatorFeeRecipient,t));return await Promise.all(o.map(async r=>{let s=await n.clientFor(l).readContract({address:r.token.address,abi:V,functionName:"balanceOf",args:[t],blockNumber:BigInt(r.blockNumber)});return{module:"pons",id:`${l}:${r.token.address}`,chainId:l,assets:[L(r.token,s)],description:`Pons ${r.phaseName}; creator fee recipient ${r.creatorFeeRecipient}. Discovery covers recent launches only (${i.fromBlock}-${i.toBlock}${i.truncated?", truncated":""}).`}}))}catch(i){throw new a(n.plainError(i))}}}},on=ze;export{je as a,ve as b,ze as c,on as d};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as A}from"./I5CQ64EU.js";import{a as g}from"./OSQ4AAM2.js";import{a as d}from"./NGAI6GTU.js";import{concat as b,encodeAbiParameters as L,getAddress as G,isAddress as C,keccak256 as h,parseAbiParameters as I,toHex as v}from"viem";var B=h(v("OakGrandfather/v1")),w="oak-grandfather/v1",D=(1n<<256n)-1n,H="0x0000000000000000000000000000000000000000000000000000000000000000";function p(e,n){if(typeof e!="string"||!C(e,{strict:!1}))throw new d(`Invalid ${n} address.`);return G(e)}function x(e,n){if(typeof e!="string"||!/^0x[0-9a-fA-F]{64}$/.test(e))throw new d(`${n} must be a 32-byte hex string.`);return e.toLowerCase()}function E(e){let n=typeof e=="bigint"?e:A(e);if(n<0n||n>D)throw new d("Count exceeds uint256 bounds.");return n}function j(e,n,o){let i=typeof e=="object"?e.wallet:e,t=typeof e=="object"?e.count:n,c=typeof e=="object"?e.source:o;if(t===void 0||c===void 0)throw new d("Grandfather leaf requires wallet, count and source.");let u=h(L(I("bytes32, address, uint256, address"),[B,p(i,"wallet"),E(t),p(c,"source")]));return h(u)}function R(e,n){let o=x(e,"first node"),i=x(n,"second node");return BigInt(o)<=BigInt(i)?h(b([o,i])):h(b([i,o]))}function _(e,n,o){if(!Array.isArray(o))throw new d("Grandfather proof must be an array.");let i=x(e,"root"),t=x(n,"leaf");for(let c=0;c<o.length;c++){if(!Object.prototype.hasOwnProperty.call(o,c))throw new d("Grandfather proof must not be a sparse array.");t=R(t,o[c])}return t===i}function S(e){if(!Array.isArray(e))throw new d("Grandfather entries must be an array.");let n=new Set,o=[];for(let r=0;r<e.length;r++){if(!Object.prototype.hasOwnProperty.call(e,r)||!e[r])throw new d(`Grandfather entries must not be sparse (missing index ${r}).`);let s=e[r],a=p(s.wallet,"wallet").toLowerCase(),f=p(s.source,"source").toLowerCase(),l=E(s.count).toString();if(n.has(a))throw new d(`Duplicate wallet in grandfather entries: ${a}`);n.add(a),o.push({wallet:a,count:l,source:f})}if(o.sort((r,s)=>BigInt(r.wallet)<BigInt(s.wallet)?-1:BigInt(r.wallet)>BigInt(s.wallet)?1:0),o.length===0){let r=g({entries:[],root:H,schema:w});return{schema:w,root:H,entries:[],proofs:{},canonicalJson:r}}let i=o.map(r=>j(r)),t=[i];for(;t[t.length-1].length>1;){let r=t[t.length-1],s=[];for(let a=0;a<r.length;a+=2){let f=r[a],l=r[a+1];s.push(l!==void 0?R(f,l):f)}t.push(s)}let c=t[t.length-1][0],u={},P=o.map((r,s)=>{let a=[],f=s;for(let l=0;l<t.length-1;l++){let y=t[l],m=f^1;m<y.length&&a.push(y[m]),f=Math.floor(f/2)}return u[r.wallet]=a,u[G(r.wallet)]=a,{...r,leaf:i[s],proof:a}}),T=g({entries:o.map(({count:r,source:s,wallet:a})=>({count:r,source:s,wallet:a})),root:c,schema:w});return{schema:w,root:c,entries:P,proofs:u,canonicalJson:T}}var M=S;function N(e,n){let o=p(n,"wallet").toLowerCase(),i=Array.isArray(e)?S(e):e,t=i.entries.find(u=>u.wallet.toLowerCase()===o);if(!t)throw new d(`Wallet ${n} is not in the grandfather list.`);let c=[...t.proof];return Object.defineProperties(c,{proof:{value:[...t.proof],enumerable:!1},leaf:{value:t.leaf,enumerable:!1},root:{value:i.root,enumerable:!1},entry:{value:{wallet:t.wallet,count:t.count,source:t.source},enumerable:!1},count:{value:t.count,enumerable:!1},source:{value:t.source,enumerable:!1}}),c}export{B as a,w as b,j as c,R as d,_ as e,S as f,M as g,N as h};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as $}from"./UCMNB2UP.js";import{a as y}from"./A5ITAEUQ.js";import{t as C}from"./ZUC6ILK2.js";import{a as d}from"./NGAI6GTU.js";import{a as S}from"./JXOEJPJ4.js";import{Buffer as H}from"node:buffer";import{decodeEventLog as B,encodeFunctionData as U,parseAbi as V,parseAbiItem as W,toEventSelector as D}from"viem";var m=V(["function register(string agentURI) returns (uint256 agentId)","function setMetadata(uint256 agentId,string metadataKey,bytes metadataValue)","event MetadataSet(uint256 indexed agentId,string indexed indexedMetadataKey,string metadataKey,bytes metadataValue)","function setAgentURI(uint256 agentId,string newURI)","function balanceOf(address owner) view returns (uint256)","function ownerOf(uint256 agentId) view returns (address)","function tokenURI(uint256 agentId) view returns (string)","function getApproved(uint256 agentId) view returns (address)","function isApprovedForAll(address owner,address operator) view returns (bool)","function getAgentWallet(uint256 agentId) view returns (address)","function getMetadata(uint256 agentId,string metadataKey) view returns (bytes)","event Registered(uint256 indexed agentId,string agentURI,address indexed owner)","event URIUpdated(uint256 indexed agentId,string newURI,address indexed updatedBy)"]),oe={register:"erc8004_register"};function h(e){let{chainId:t,identityRegistry:n}=C[e.network??"mainnet"];return{chainId:t,registry:n,registryId:`eip155:${t}:${n}`}}var j="https://eips.ethereum.org/EIPS/eip-8004#registration-v1",v="oak.registrar",M="0x6f616b",_="Profile contents and oak.registrar are mutable, self-asserted metadata, not registry-validated claims or proof of provenance.",N={type:"string",pattern:"^[0-9]+$",description:"Agent ID as a decimal uint256 integer string."},J={type:"object",required:["type","name","description","image","services","x402Support","active","registrations"],properties:{type:{const:j},name:{type:"string",minLength:1},description:{type:"string"},image:{type:"string"},services:{type:"array",items:{type:"object",required:["name","endpoint"]}},x402Support:{type:"boolean"},active:{type:"boolean"},registrations:{type:"array"},tags:{type:"array",items:{type:"string"}},supportedTrust:{type:"array",items:{type:"string"}}}};function R(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function l(e,t){return e.toLowerCase()===t.toLowerCase()}function I(e){if(typeof e!="string"||!/^[0-9]+$/.test(e)||e.length>78||BigInt(e)>=2n**256n)throw new d("Provide an agent ID as a decimal uint256 integer string.");return BigInt(e)}function b(e,t,n=!1){if(typeof e!="string"||!n&&!e.trim())throw new d(`Provide a valid profile ${t}.`)}function E(e,t){b(e,t);try{let n=new URL(e);if(!["https:","ipfs:"].includes(n.protocol)||!n.hostname||n.username||n.password)throw new Error}catch{throw new d(`Profile ${t} must be an HTTPS or IPFS URI without credentials.`)}}function z(e,t,n,r){let{registryId:s}=h(e);if(!R(t))throw new d("Provide a registration-v1 profile object.");if(n!==void 0&&typeof n!="boolean")throw new d("The tag option must be a boolean.");if(t.type!==j)throw new d("Use the ERC-8004 registration-v1 profile type.");if(b(t.name,"name"),b(t.description,"description",!0),E(t.image,"image"),typeof t.active!="boolean"||typeof t.x402Support!="boolean")throw new d("Profile active and x402Support must be booleans.");if(!Array.isArray(t.services)||!Array.isArray(t.registrations))throw new d("Profile services and registrations must be arrays.");for(let o of t.services){if(!R(o))throw new d("Provide valid profile services.");b(o.name,"service name"),E(o.endpoint,"service endpoint"),o.version!==void 0&&b(o.version,"service version")}for(let o of["tags","supportedTrust"])if(t[o]!==void 0&&(!Array.isArray(t[o])||!t[o].every(p=>typeof p=="string"&&p.trim())))throw new d(`Profile ${o} must be an array of nonempty strings.`);let c=t.registrations.map(o=>{if(!R(o)||typeof o.agentRegistry!="string"||!/^eip155:[1-9][0-9]*:0x[0-9a-fA-F]{40}$/.test(o.agentRegistry))throw new d("Provide a valid agentRegistry for every registration.");let p=typeof o.agentId=="number"&&Number.isSafeInteger(o.agentId)?String(o.agentId):o.agentId,u=I(p);if(l(o.agentRegistry,s)){if(r===void 0)throw new d("Do not predict a registration ID; obtain it from the mined Registered receipt.");if(u!==r)throw new d("Profile registration ID does not match the agent being updated.")}return{...o}});r!==void 0&&!c.some(o=>l(o.agentRegistry,s))&&c.push({agentId:r.toString(),agentRegistry:s});let i=[...new Set((t.tags??[]).filter(o=>o!==v))];n!==!1&&i.push(v);let g={...t,registrations:c,...i.length?{tags:i}:{}};i.length||delete g.tags;let a;try{if(a=JSON.stringify(g),H.byteLength(a)>65536)throw new Error;JSON.parse(a)}catch{throw new d("Profile must be JSON data no larger than 64 KiB.")}return`data:application/json;base64,${H.from(a,"utf8").toString("base64")}`}async function A(e,t){try{let{chainId:n,registry:r}=h(e),s=I(t),c=e.clientFor(n),i=await c.readContract({address:r,abi:m,functionName:"ownerOf",args:[s]});y(i);let[g,a,o]=await Promise.all([c.readContract({address:r,abi:m,functionName:"tokenURI",args:[s]}),c.readContract({address:r,abi:m,functionName:"getAgentWallet",args:[s]}),c.readContract({address:r,abi:m,functionName:"getMetadata",args:[s,v]})]);if(y(a),typeof g!="string"||typeof o!="string"||!/^0x([0-9a-fA-F]{2})*$/.test(o))throw new d("The registry returned invalid identity data.");return{agentId:s.toString(),chainId:n,registry:r,owner:i,uri:g,agentWallet:a,registrarMetadata:o,registryValidated:!1,summary:_}}catch(n){throw new d(e.plainError(n))}}async function se(e,t){let n=await A(e,t);return{...n,uri:S(n.uri)}}async function F(e,t,n){let{chainId:r,registry:s}=h(e),c=e.clientFor(r),i=await c.readContract({address:s,abi:m,functionName:"ownerOf",args:[t]});if(y(i),l(i,n))return;let[g,a]=await Promise.all([c.readContract({address:s,abi:m,functionName:"getApproved",args:[t]}),c.readContract({address:s,abi:m,functionName:"isApprovedForAll",args:[i,n]})]);if(y(g),typeof a!="boolean")throw new d("The registry returned invalid operator approval data.");if(!l(g,n)&&!a)throw new d("Only the agent owner or an approved operator can update this profile.")}async function L(e,t,n,r){let{chainId:s,registry:c}=h(e);if(typeof t!="string"||!/^0x[0-9a-fA-F]{64}$/.test(t))throw new d("Provide the mined transaction hash.");let i=e.clientFor(s),g=await i.getTransactionReceipt({hash:t});if(!g)throw new d("The transaction is not mined yet. Try again after confirmation.");if(g.status!=="success"||!g.to||!l(g.to,c)||!l(g.from,n)||!l(g.transactionHash,t))throw new d("The receipt is not a successful matching registry transaction.");let a=await i.getTransaction({hash:t});if(a.chainId!==s||a.value!==0n||!a.to||!l(a.to,c)||!l(a.from,n))throw new d("The transaction does not match this chain, registry and wallet.");if(typeof a.input!="string"||!l(a.input,r))throw new d("The mined transaction calldata does not match the exact operation Oak built.");return g}async function G(e,t,n,r,s,c){let{registry:i}=h(e),g=await L(e,t,n,s),a=c===void 0?"Registered":"URIUpdated",o=D(c===void 0?"Registered(uint256,string,address)":"URIUpdated(uint256,string,address)"),p=g.logs.filter(x=>l(x.address,i)&&x.topics[0]===o&&!x.removed);if(p.length!==1)throw new d(`The receipt must contain one matching ${a} event.`);let u=p[0],f=B({abi:m,eventName:a,topics:u.topics,data:u.data,strict:!0}),w=f.args.agentId,q=f.eventName==="Registered"?f.args.agentURI:f.args.newURI,K=f.eventName==="Registered"?f.args.owner:f.args.updatedBy;if(c!==void 0&&w!==c||q!==r||!l(K,n))throw new d("The registry event does not match the expected agent, URI and wallet.");let k=await A(e,w.toString());if(k.uri!==r||c===void 0&&!l(k.owner,n))throw new d("The current agent owner or URI does not match the confirmed operation.");return k}function T(e,t){let{chainId:n,registry:r}=h(e);return e.unsignedTx({to:r,chainId:n,value:"0",data:U({abi:m,functionName:"setMetadata",args:[t,v,M]}),description:`Set mutable oak.registrar metadata to oak for agent ${t}.`})}async function Q(e,t,n,r){let{registry:s}=h(e),c=I(r.agentId),i=await L(e,t,n,T(e,c).data),g=D("MetadataSet(uint256,string,string,bytes)"),a=i.logs.filter(f=>l(f.address,s)&&f.topics[0]===g&&!f.removed);if(a.length!==1)throw new d("The receipt must contain one matching MetadataSet event.");let o=a[0],{args:p}=B({abi:m,eventName:"MetadataSet",topics:o.topics,data:o.data,strict:!0});if(p.agentId!==c||p.metadataKey!==v||p.metadataValue!==M)throw new d("The metadata event does not match this agent and registrar marker.");let u=await A(e,r.agentId);if(u.registrarMetadata!==M||u.uri!==r.uri||!l(u.owner,r.owner))throw new d("The current agent metadata, owner or URI does not match the confirmed operation.");return u}async function P(e,t,n,r){let s=await e.preview(t,n),c=s.changes.map(({amount:i,token:g})=>{let a=i.startsWith("-");return`${a?"-":""}${e.formatAmount(a?i.slice(1):i,g.decimals)} ${g.symbol} (${g.address}, chain ${g.chainId})`});return{txs:t,summary:`${s.summary} ${c.join("; ")} ${_} ${r}`}}async function X(e,t){let{chainId:n,registry:r}=h(e),s=e.clientFor(n),c=await s.readContract({address:r,abi:m,functionName:"balanceOf",args:[t]});if(c===0n)return;if(typeof c!="bigint"||c<0n)throw new d("Registry balance is unavailable; registration was not built.");let i=await s.getBlockNumber({cacheTime:0}),g=new Set;for(;;){let a=i>9999999n?i-9999999n:0n,o=await s.getLogs({address:r,event:W("event Transfer(address indexed from,address indexed to,uint256 indexed tokenId)"),args:{to:t},fromBlock:a,toBlock:i,strict:!0});for(let p of o){let u=p.args.tokenId.toString();if(p.removed||g.has(u))continue;g.add(u);let f=await A(e,u);if(l(f.owner,t))return f}if(a===0n)throw new d("Owned identity could not be located; registration was not built. Run oak setup link <agentId>.");i=a-1n}}async function O(e,t,n,r){let{chainId:s,registry:c}=h(e);if(y(r),n.chainId!==void 0&&n.chainId!==s)throw new d(`ERC-8004 actions are supported only on chain ${s}.`);let i=t?I(n.agentId):void 0,g=z(e,n.profile,n.tag,i),a=n.tag!==!1;if(n.metadataTransactionHash!==void 0&&(!a||n.transactionHash===void 0))throw new d("A metadata transaction hash requires tagging and the profile transaction hash.");let o=i===void 0?U({abi:m,functionName:"register",args:[g]}):U({abi:m,functionName:"setAgentURI",args:[i,g]});if(n.transactionHash!==void 0){let u=await G(e,n.transactionHash,r,g,o,i);if(!a)return u;if(n.metadataTransactionHash!==void 0)return Q(e,n.metadataTransactionHash,r,u);let f=I(u.agentId);await F(e,f,r);let w=await P(e,[T(e,f)],r,`Profile transaction confirmed for agent ${f}; onchain registrar metadata is pending. Submit this metadata transaction locally if not already submitted, then repeat the original arguments with transactionHash and metadataTransactionHash to verify both calls.`);return{...u,...w}}if(!t){let u=await X(e,r);if(u){let f={...u,registrationResumed:!0};if(!a||u.registrarMetadata===M)return f;let w=await P(e,[T(e,I(u.agentId))],r,`Resume registrar metadata for owned agent ${u.agentId}; no new identity will be minted.`);return{...f,...w}}}i!==void 0&&await F(e,i,r);let p=[e.unsignedTx({to:c,data:o,value:"0",chainId:s,description:i===void 0?"Register an ERC-8004 agent profile.":`Update ERC-8004 agent ${i} profile.`})];return i!==void 0&&a&&p.push(T(e,i)),P(e,p,r,`Submit locally, then repeat the original arguments with transactionHash to verify the profile receipt and URI.${a?i===void 0?" The mined Registered event supplies the actual agent ID; confirmation then builds a separate setMetadata transaction for oak.registrar. Both transactions require network gas.":" Submit the profile and metadata transactions in order, then supply metadataTransactionHash as well to verify the onchain oak.registrar marker. Both transactions require network gas.":" No registrar metadata transaction is built; --no-tag does not clear existing onchain metadata."}${i===void 0?" Update the profile registrations with the mined ID afterward.":""}`)}var Y=e=>{let t=(r,s,c)=>({name:r,inputSchema:s,execute:async(i,g)=>{try{let a=await c(i,g);return R(a)&&typeof a.uri=="string"?{...a,uri:S(a.uri)}:a}catch(a){throw new d(e.plainError(a))}}}),n=r=>({type:"object",additionalProperties:!1,required:r?["agentId","profile"]:["profile"],properties:{profile:J,tag:{type:"boolean",default:!0,description:"Set false for --no-tag; removes the profile tag and skips setMetadata, leaving existing onchain metadata unchanged."},transactionHash:{type:"string",pattern:"^0x[0-9a-fA-F]{64}$",description:"After local submission, verify exact calldata, event and URI; if tagged, build the metadata follow-up unless metadataTransactionHash is supplied."},metadataTransactionHash:{type:"string",pattern:"^0x[0-9a-fA-F]{64}$",description:"Hash of the separate setMetadata transaction; supplied with transactionHash to complete tagged confirmation."},...r?{agentId:N}:{}}});return{tools:[t("erc8004_register",n(!1),(r,s)=>O(e,!1,r,s)),t("erc8004_update",n(!0),(r,s)=>O(e,!0,r,s)),t("erc8004_identity",{type:"object",additionalProperties:!1,required:["agentId"],properties:{agentId:N}},r=>A(e,r.agentId))]}},de=e=>$("erc8004",[Y(e)]);export{m as a,oe as b,se as c,Y as d,de as e};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as H,b as z}from"./LIUXNOLP.js";import{a as _}from"./GIBF3YJO.js";import{a as O,b as B}from"./A5ITAEUQ.js";import{a as $,b as M,i as R,t as S}from"./ZUC6ILK2.js";import{b as D,c as E,d as U}from"./B4MLWDPM.js";import{a as u,b as N,c as I,d as F}from"./NGAI6GTU.js";import{decodeFunctionResult as J,encodeFunctionData as Q,erc20Abi as q,getAddress as G,isAddress as X,toEventSelector as Y,toHex as v,zeroAddress as Z}from"viem";var C="0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";function ee(e){let r=e.toLowerCase();return r===Z||r===C?C:e}var te=Y("Transfer(address,address,uint256)"),K="Preview note: simulation transfer-based token changes exclude gas and do not prove external settlement.";function A(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function P(){throw new u("The endpoint returned an unexpected simulation response.")}async function L(e,r,d,a){let s=await e.getChainId();if(s!==r)throw new u(`Preview is on chain ${r}, but the endpoint reports chain ${s}.`);let i=await H(e),t=await z(e,i);if(i.number===null||typeof i.baseFeePerGas!="bigint"||i.baseFeePerGas<0n||typeof t!="bigint"||t<0n)throw new u("Current block base fee and gas price are unavailable or inconsistent. Retry the preview.");let n=t<i.baseFeePerGas?i.baseFeePerGas:t,y=D(i.gasLimit),b=d.map(f=>({from:a,to:f.to,data:f.data,value:v(BigInt(f.value)),gasPrice:v(n),gas:v(y)})),w=()=>e.request({method:"eth_simulateV1",params:[{blockStateCalls:[{blockOverrides:{baseFeePerGas:v(i.baseFeePerGas)},calls:b}],validation:!1,traceTransfers:!0},v(i.number)]},{retryCount:0});try{return await w()}catch(f){if(!I(f))throw f;let o=await e.getBalance({address:a,blockNumber:i.number}),c=await Promise.all(d.map(m=>e.estimateGas({account:a,to:m.to,data:m.data,value:BigInt(m.value),gas:y,blockNumber:i.number}).catch(()=>{}))),p=o;for(let[m,l]of b.entries()){let g=BigInt(l.value),x=U(D(i.gasLimit,c[m]),p,g,n,a,r),T=c[m];if(T!==void 0&&T>x)throw new u(E(a,r,o-p+g+T*n,o));l.gas=v(x),p-=g}let h=await w();if(Array.isArray(h)&&A(h[0])&&Array.isArray(h[0].calls))for(let[m,l]of h[0].calls.entries()){let g=b[m];if(g&&A(l)&&l.status==="0x0"&&typeof l.gasUsed=="string"&&/^0x[0-9a-f]+$/i.test(l.gasUsed)&&BigInt(l.gasUsed)>=BigInt(g.gas))throw new u(E(a,r,BigInt(g.value)+(BigInt(g.gas)+1n)*n,o))}return h}}function V(e,r,d,a){(!Array.isArray(e)||e.length!==1||!A(e[0])||!Array.isArray(e[0].calls)||e[0].calls.length!==r)&&P();let s=new Map;for(let[i,t]of e[0].calls.entries()){if(A(t)||P(),t.status==="0x0")throw new u(`Preview call ${i+1} on chain ${a} reverted. ${F(t.error)}`);(t.status!=="0x1"||t.error||!Array.isArray(t.logs))&&P();for(let n of t.logs){if((!A(n)||!Array.isArray(n.topics))&&P(),typeof n.topics[0]!="string"||n.topics[0].toLowerCase()!==te||n.topics.length===4)continue;(n.topics.length!==3||typeof n.address!="string"||!X(n.address,{strict:!1})||typeof n.data!="string"||!/^0x[0-9a-fA-F]{64}$/.test(n.data)||!n.topics.slice(1).every(c=>typeof c=="string"&&/^0x0{24}[0-9a-fA-F]{40}$/.test(c)))&&P();let y=n.topics[1].slice(-40).toLowerCase(),b=n.topics[2].slice(-40).toLowerCase(),w=d.slice(2).toLowerCase(),f=BigInt(n.data),o=(b===w?f:0n)-(y===w?f:0n);if(o!==0n){let c=ee(n.address.toLowerCase());s.set(c,(s.get(c)??0n)+o)}}}return s}async function W(e,r,d,a){let s=r===$?S.mainnet:r===M?S.testnet:void 0,i=s&&[{address:s.usdg,symbol:"USDG",decimals:6},{address:s.weth,symbol:"WETH",decimals:18},...r===$?[{address:R[4663].meridian.CollateralToken_USDe.address,symbol:"USDe",decimals:18}]:[]].find(n=>n.address.toLowerCase()===e);if(i)return{...i,address:G(e),chainId:r};let t;if(e===C){let n=d.chain?.nativeCurrency??(r===4663?{symbol:"ETH",decimals:18}:void 0);if(!n)throw new u(`Native token metadata is unavailable for chain ${r}.`);t={address:e,chainId:r,symbol:n.symbol,decimals:n.decimals}}else if(a)t=await a(e,r,d);else{let n=await _(d,r,e,"decimals");t={address:e,chainId:r,symbol:e,decimals:n}}if(!t||typeof t.address!="string"||t.address.toLowerCase()!==e||t.chainId!==r||typeof t.symbol!="string"||!t.symbol.trim()||!Number.isInteger(t.decimals)||t.decimals<0||t.decimals>255)throw new u(`Invalid token metadata for ${e} on chain ${r}.`);return{address:e===C?e:G(e),chainId:r,symbol:e===C?t.symbol:G(e),decimals:t.decimals}}function le(e){return async(r,d)=>{O(d);let a=r.map(B),s=a[0]?.chainId;if(s===void 0)return{txs:a,changes:[],summary:K};let i=a.find(t=>t.chainId!==s);if(i)throw new u(`Preview cannot combine chain ${s} with chain ${i.chainId}. Preview each chain separately.`);try{let t=e.clientFor(s),n;try{n=await L(t,s,a,d)}catch(o){if(!N(o,-32601,-32004)||!e.anvilFor)throw o;t=await e.anvilFor(s),n=await L(t,s,a,d)}let y=V(n,a.length,d,s),b=new Map,w=[];for(let[o,c]of y)if(c!==0n)try{b.set(o,await W(o,s,t,e.tokenFor))}catch(p){if(o===C||e.tokenFor||(await t.getCode({address:o})??"0x")!=="0x")throw p;w.push(o)}if(w.length){let o=w.flatMap(m=>["symbol","decimals"].map(l=>B({to:m,data:Q({abi:q,functionName:l}),value:"0",chainId:s,description:`Read simulated token ${l}.`}))),c=await L(t,s,[...a,...o],d);(!Array.isArray(c)||c.length!==1||!A(c[0])||!Array.isArray(c[0].calls)||c[0].calls.length!==a.length+o.length)&&P();let p=c[0].calls,h=V([{calls:p.slice(0,a.length)}],a.length,d,s);if(y.size!==h.size||[...y].some(([m,l])=>h.get(m)!==l))throw new u("Simulation changed while reading new-token metadata. Refresh the preview.");for(let[m,l]of w.entries()){let g=(T,j)=>{let k=p[a.length+m*2+j];if(!A(k)||k.status!=="0x1"||k.error||typeof k.returnData!="string"||!/^0x[0-9a-fA-F]+$/.test(k.returnData))throw new u(`Invalid simulated token metadata for ${l} on chain ${s}.`);return J({abi:q,functionName:T,data:k.returnData})},x={address:l,chainId:s,symbol:g("symbol",0),decimals:g("decimals",1)};b.set(l,await W(l,s,t,async()=>x))}}let f=[...y].filter(([,o])=>o!==0n).map(([o,c])=>({token:b.get(o),amount:c.toString()}));return{txs:a,changes:f,summary:K}}catch(t){throw new u(`Preview on chain ${s} failed: ${F(t)}`)}}}export{C as a,ee as b,le as c};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as A}from"./5HCXZWUH.js";import{g as y}from"./
|
|
1
|
+
import{c as A}from"./5HCXZWUH.js";import{g as y}from"./M6JGTQRY.js";import{a as b}from"./NGAI6GTU.js";import{erc20Abi as F,getAddress as $}from"viem";var P=new WeakMap,E=3e3,k=new WeakMap;async function q(C,h,u,m,c){u=$(u);let n=A(C),e=P.get(n);e||(e=new Map,P.set(n,e));let i=`${h}:${u.toLowerCase()}:${m}:${c??"latest"}`,t=e.get(i);if(t&&(e.delete(i),e.set(i,t)),!t){for(t=new Promise((s,T)=>{let a=k.get(n);a||(a=new Map,k.set(n,a));let f=`${h}:${c??"latest"}`,l=a.get(f);if(!l){l=[],a.set(f,l);let d=l;queueMicrotask(async()=>{a.delete(f);let w=d.map(r=>({address:r.address,abi:F,functionName:r.field}));try{if(d.length>1&&n.chain?.contracts?.multicall3&&typeof n.multicall=="function"){let r=await y(()=>n.multicall({contracts:w,blockNumber:c,allowFailure:!0}));d.forEach((o,p)=>{let g=r[p];g?.status==="success"?o.resolve(g.result):o.reject(g?.error??new b("Token metadata could not be read."))})}else await Promise.all(d.map(async(r,o)=>{try{r.resolve(await y(()=>n.readContract({...w[o],blockNumber:c})))}catch(p){r.reject(p)}}))}catch(r){d.forEach(o=>o.reject(r))}})}l.push({address:u,field:m,resolve:s,reject:T})}).then(s=>{if(m==="decimals"?!Number.isInteger(s)||Number(s)<0||Number(s)>255:typeof s!="string"||!s.trim())throw new b("The contract returned invalid token metadata.");return s});e.size>=E;)e.delete(e.keys().next().value);e.set(i,t);let M=t;t.catch(()=>{e.get(i)===M&&e.delete(i)})}try{return await t}finally{c!==void 0&&e.get(i)===t&&e.delete(i)}}export{q as a};
|