@aegis-engine/core 0.13.1 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/account.js CHANGED
@@ -1 +1 @@
1
- import{w as u,o as b,n as A,s as I,l as P,E as g,A as h,r as f,a as x,i as c,b as E,c as S,d as C,e as _,P as T,f as D}from"./transactionHistory-C8KRA_tE.js";import{g as M,h as j,j as J,k as O,m as U,p as G,q as Z,t as Q,u as V,v as W,x as X,y as Y,z as ee,B as ae,C as oe,D as se,F as ne,G as te,H as re}from"./transactionHistory-C8KRA_tE.js";import{keccak256 as k,encodeAbiParameters as y}from"viem";const H=b({version:P(1),snapshotId:I().uuid(),page:A().int().min(1).max(95)}).strict();function v(e){if(!/^[A-Za-z0-9_-]{1,256}$/.test(e))throw new Error("invalid-cursor");return H.parse(JSON.parse(atob(e.replace(/-/g,"+").replace(/_/g,"/"))));}function L(e){return u({...e,chainIds:[e.chainId]},async r=>{let o;try{if(!/^0x[0-9a-fA-F]{64}$/.test(e.poolId)||!["lend_shares","borrow_vault"].includes(e.kind)||(e.kind==="borrow_vault"?!g.safeParse(e.vaultId).success:e.vaultId!==void 0))throw new Error("invalid-query");e.cursor!==void 0&&(o=v(e.cursor));}catch{throw new h("invalid-query",400);}const a=await f(r,"positions/accounting",{chainId:String(e.chainId),poolId:e.poolId.toLowerCase(),kind:e.kind,...(e.kind==="borrow_vault"?{vaultId:e.vaultId}:{}),...(e.cursor?{cursor:e.cursor}:{})},x,{omitChainIds:!0,responseLimit:256*1024});if(Date.parse(a.expiresAt)<=Date.now())throw new h("snapshot-expired",410);const n=a.position,l=n.key;if((n.account!==r.query.account||n.chainId!==e.chainId||n.poolId!==e.poolId.toLowerCase()||n.kind!==e.kind||n.vaultId!==(e.vaultId??null)||n.scope!==(e.kind==="lend_shares"?"account-lending":"vault-lifetime")||a.page.snapshotId!==a.snapshotId||a.page.page!==((o==null?void 0:o.page)??0)||o&&o.snapshotId!==a.snapshotId||a.page.page>=a.pageCount||a.recordCount>0&&a.page.records.length===0||a.page.records.length>a.recordCount||a.pageCount===1&&a.page.records.length!==a.recordCount||Date.parse(a.expiresAt)-Date.parse(a.createdAt)!==6e5||l.currency0>=l.currency1||k(y([{type:"address"},{type:"address"},{type:"uint24"},{type:"int24"},{type:"address"}],[l.currency0,l.currency1,l.fee,l.tickSpacing,l.hooks]))!==n.poolId)&&c(),a.page.page+1<a.pageCount!=(a.nextCursor!==null)&&c(),a.nextCursor!==null)try{const t=v(a.nextCursor);(t.snapshotId!==a.snapshotId||t.page!==a.page.page+1)&&c();}catch{c();}const m=/* @__PURE__ */new Map();let i;for(const t of a.page.records){const s=t.event,p=m.get(s.transactionHash);if((s.blockNumber>a.frame.blockNumber||s.blockTimestamp>a.frame.blockTimestamp||i&&(s.blockNumber<i.blockNumber||s.blockTimestamp<i.blockTimestamp||s.blockNumber===i.blockNumber&&(s.logIndex<=i.logIndex||s.blockTimestamp!==i.blockTimestamp||s.transactionIndex<i.transactionIndex||s.transactionIndex===i.transactionIndex!=(s.transactionHash===i.transactionHash)))||p&&(p.blockNumber!==s.blockNumber||p.blockTimestamp!==s.blockTimestamp||p.transactionIndex!==s.transactionIndex))&&c(),t.type==="ownership")(e.kind!=="borrow_vault"||t.event.vaultId!==e.vaultId||t.event.registry!==n.registry||s.id!==`vault-transfer:${n.chainId}:${n.registry}:${s.transactionHash}:${s.logIndex}`||s.blockNumber===a.frame.blockNumber&&t.event.blockHash!==a.frame.blockHash)&&c();else{const d=t.event,w=["liquidity_modified","share_transfer","protocol_fee_minted"].includes(d.kind);(e.kind==="lend_shares"!==w||d.kind==="liquidity_modified"&&d.details.account!==n.account||d.kind==="protocol_fee_minted"&&d.details.recipient!==n.account||d.kind==="share_transfer"&&d.details.from!==n.account&&d.details.to!==n.account)&&c(),(t.event.id!==`engine-event:${n.chainId}:${n.engine}:${s.transactionHash}:${s.logIndex}`||t.event.sourceId!==`${s.transactionHash}-${s.logIndex}`||e.kind==="lend_shares"&&t.ownershipAtEvent.status!=="not-applicable"||e.kind==="borrow_vault"&&(a.ownership.status!=="complete"?t.ownershipAtEvent.status!=="unavailable":!["known","inactive"].includes(t.ownershipAtEvent.status)))&&c();}m.set(s.transactionHash,s),i=s;}return a;});}const R=_({ttlMs:0,maxEntries:64});async function F(e){var n;(n=e.signal)==null||n.throwIfAborted();const r={...e.source,headers:{...e.source.headers}},o=JSON.stringify([E(r.baseUrl),S(r.headers),r.timeoutMs,e.account,e.chainId,e.poolId,e.vaultId,e.snapshotId]),a=R.read(o,()=>$({...e,source:r,signal:void 0}));return structuredClone(await C(a,e.signal,"Position PnL read aborted."));}function $(e){return u({...e,chainIds:[e.chainId]},async r=>{if(!/^0x[0-9a-fA-F]{64}$/.test(e.poolId)||!g.safeParse(e.vaultId).success||!I().uuid().safeParse(e.snapshotId).success)throw new h("invalid-query",400);const o=await f(r,"positions/pnl",{chainId:String(e.chainId),poolId:e.poolId.toLowerCase(),kind:"borrow_vault",vaultId:e.vaultId,snapshotId:e.snapshotId},T,{omitChainIds:!0,responseLimit:32*1024});if(Date.parse(o.expiresAt)<=Date.now())throw new h("snapshot-expired",410);if((o.account!==r.query.account||o.chainId!==e.chainId||o.poolId!==e.poolId.toLowerCase()||o.vaultId!==e.vaultId||o.snapshotId!==e.snapshotId||Date.parse(o.capturedAt)>Date.now()+6e4||Date.parse(o.expiresAt)-Date.parse(o.capturedAt)>6e5)&&c(),o.status==="token-pnl"){const a=o.key;k(y([{type:"address"},{type:"address"},{type:"uint24"},{type:"int24"},{type:"address"}],[a.currency0,a.currency1,a.fee,a.tickSpacing,a.hooks]))!==o.poolId&&c();}return o;});}function z(e){return u({...e,chainIds:[e.chainId]},async r=>{if(!/^0x[0-9a-fA-F]{64}$/.test(e.poolId)||!g.safeParse(e.vaultId).success||!I().uuid().safeParse(e.snapshotId).success||e.portfolioSnapshotId!==void 0&&!I().uuid().safeParse(e.portfolioSnapshotId).success)throw new h("invalid-query",400);const o=await f(r,"positions/performance",{chainId:String(e.chainId),poolId:e.poolId.toLowerCase(),kind:"borrow_vault",vaultId:e.vaultId,snapshotId:e.snapshotId,...(e.portfolioSnapshotId?{portfolioSnapshotId:e.portfolioSnapshotId}:{})},D,{omitChainIds:!0,responseLimit:32*1024});if(Date.parse(o.expiresAt)<=Date.now())throw new h("snapshot-expired",410);return(o.account!==r.query.account||o.chainId!==e.chainId||o.poolId!==e.poolId.toLowerCase()||o.vaultId!==e.vaultId||o.snapshotId!==e.snapshotId||o.portfolioSnapshotId!==(e.portfolioSnapshotId??null)||Date.parse(o.capturedAt)>Date.now()+6e4||Date.parse(o.expiresAt)-Date.parse(o.capturedAt)>6e5)&&c(),o;});}export{h as AegisEngineAccountReadError,M as createEngineTransactionHistory,j as engineAccountPositionKey,J as engineAccountTransactionKey,O as engineHistoryCatalogResponseSchema,U as enginePortfolioPriceFor,G as enginePositionHistoryResponseSchema,Z as engineTransactionStorageKey,Q as fetchEngineAccountActivity,V as fetchEngineAccountPortfolio,W as fetchEngineHistoryPositions,L as fetchEnginePositionAccounting,X as fetchEnginePositionHistory,z as fetchEnginePositionPerformance,F as fetchEnginePositionPnl,Y as fetchEngineTransactionStatus,ee as formatEngineAccountTokenAmount,ae as groupEngineAccountActivity,oe as groupEnginePortfolioPositions,se as mergeEngineTransactionRecord,ne as parseEngineTransactionRecords,te as resolveEngineAccountPositionTarget,re as serializeEngineTransactionRecords};
1
+ import{w as u,o as b,n as A,s as I,l as P,E as g,A as h,r as f,a as x,i as c,b as E,c as S,d as C,e as _,P as T,f as D}from"./transactionHistory-BGpe2c7k.js";import{g as M,h as j,j as J,k as O,m as U,p as G,q as Z,t as Q,u as V,v as W,x as X,y as Y,z as ee,B as ae,C as oe,D as se,F as ne,G as te,H as re}from"./transactionHistory-BGpe2c7k.js";import{keccak256 as k,encodeAbiParameters as y}from"viem";const H=b({version:P(1),snapshotId:I().uuid(),page:A().int().min(1).max(95)}).strict();function v(e){if(!/^[A-Za-z0-9_-]{1,256}$/.test(e))throw new Error("invalid-cursor");return H.parse(JSON.parse(atob(e.replace(/-/g,"+").replace(/_/g,"/"))));}function L(e){return u({...e,chainIds:[e.chainId]},async r=>{let o;try{if(!/^0x[0-9a-fA-F]{64}$/.test(e.poolId)||!["lend_shares","borrow_vault"].includes(e.kind)||(e.kind==="borrow_vault"?!g.safeParse(e.vaultId).success:e.vaultId!==void 0))throw new Error("invalid-query");e.cursor!==void 0&&(o=v(e.cursor));}catch{throw new h("invalid-query",400);}const a=await f(r,"positions/accounting",{chainId:String(e.chainId),poolId:e.poolId.toLowerCase(),kind:e.kind,...(e.kind==="borrow_vault"?{vaultId:e.vaultId}:{}),...(e.cursor?{cursor:e.cursor}:{})},x,{omitChainIds:!0,responseLimit:256*1024});if(Date.parse(a.expiresAt)<=Date.now())throw new h("snapshot-expired",410);const n=a.position,l=n.key;if((n.account!==r.query.account||n.chainId!==e.chainId||n.poolId!==e.poolId.toLowerCase()||n.kind!==e.kind||n.vaultId!==(e.vaultId??null)||n.scope!==(e.kind==="lend_shares"?"account-lending":"vault-lifetime")||a.page.snapshotId!==a.snapshotId||a.page.page!==((o==null?void 0:o.page)??0)||o&&o.snapshotId!==a.snapshotId||a.page.page>=a.pageCount||a.recordCount>0&&a.page.records.length===0||a.page.records.length>a.recordCount||a.pageCount===1&&a.page.records.length!==a.recordCount||Date.parse(a.expiresAt)-Date.parse(a.createdAt)!==6e5||l.currency0>=l.currency1||k(y([{type:"address"},{type:"address"},{type:"uint24"},{type:"int24"},{type:"address"}],[l.currency0,l.currency1,l.fee,l.tickSpacing,l.hooks]))!==n.poolId)&&c(),a.page.page+1<a.pageCount!=(a.nextCursor!==null)&&c(),a.nextCursor!==null)try{const t=v(a.nextCursor);(t.snapshotId!==a.snapshotId||t.page!==a.page.page+1)&&c();}catch{c();}const m=/* @__PURE__ */new Map();let i;for(const t of a.page.records){const s=t.event,p=m.get(s.transactionHash);if((s.blockNumber>a.frame.blockNumber||s.blockTimestamp>a.frame.blockTimestamp||i&&(s.blockNumber<i.blockNumber||s.blockTimestamp<i.blockTimestamp||s.blockNumber===i.blockNumber&&(s.logIndex<=i.logIndex||s.blockTimestamp!==i.blockTimestamp||s.transactionIndex<i.transactionIndex||s.transactionIndex===i.transactionIndex!=(s.transactionHash===i.transactionHash)))||p&&(p.blockNumber!==s.blockNumber||p.blockTimestamp!==s.blockTimestamp||p.transactionIndex!==s.transactionIndex))&&c(),t.type==="ownership")(e.kind!=="borrow_vault"||t.event.vaultId!==e.vaultId||t.event.registry!==n.registry||s.id!==`vault-transfer:${n.chainId}:${n.registry}:${s.transactionHash}:${s.logIndex}`||s.blockNumber===a.frame.blockNumber&&t.event.blockHash!==a.frame.blockHash)&&c();else{const d=t.event,w=["liquidity_modified","share_transfer","protocol_fee_minted"].includes(d.kind);(e.kind==="lend_shares"!==w||d.kind==="liquidity_modified"&&d.details.account!==n.account||d.kind==="protocol_fee_minted"&&d.details.recipient!==n.account||d.kind==="share_transfer"&&d.details.from!==n.account&&d.details.to!==n.account)&&c(),(t.event.id!==`engine-event:${n.chainId}:${n.engine}:${s.transactionHash}:${s.logIndex}`||t.event.sourceId!==`${s.transactionHash}-${s.logIndex}`||e.kind==="lend_shares"&&t.ownershipAtEvent.status!=="not-applicable"||e.kind==="borrow_vault"&&(a.ownership.status!=="complete"?t.ownershipAtEvent.status!=="unavailable":!["known","inactive"].includes(t.ownershipAtEvent.status)))&&c();}m.set(s.transactionHash,s),i=s;}return a;});}const R=_({ttlMs:0,maxEntries:64});async function F(e){var n;(n=e.signal)==null||n.throwIfAborted();const r={...e.source,headers:{...e.source.headers}},o=JSON.stringify([E(r.baseUrl),S(r.headers),r.timeoutMs,e.account,e.chainId,e.poolId,e.vaultId,e.snapshotId]),a=R.read(o,()=>$({...e,source:r,signal:void 0}));return structuredClone(await C(a,e.signal,"Position PnL read aborted."));}function $(e){return u({...e,chainIds:[e.chainId]},async r=>{if(!/^0x[0-9a-fA-F]{64}$/.test(e.poolId)||!g.safeParse(e.vaultId).success||!I().uuid().safeParse(e.snapshotId).success)throw new h("invalid-query",400);const o=await f(r,"positions/pnl",{chainId:String(e.chainId),poolId:e.poolId.toLowerCase(),kind:"borrow_vault",vaultId:e.vaultId,snapshotId:e.snapshotId},T,{omitChainIds:!0,responseLimit:32*1024});if(Date.parse(o.expiresAt)<=Date.now())throw new h("snapshot-expired",410);if((o.account!==r.query.account||o.chainId!==e.chainId||o.poolId!==e.poolId.toLowerCase()||o.vaultId!==e.vaultId||o.snapshotId!==e.snapshotId||Date.parse(o.capturedAt)>Date.now()+6e4||Date.parse(o.expiresAt)-Date.parse(o.capturedAt)>6e5)&&c(),o.status==="token-pnl"){const a=o.key;k(y([{type:"address"},{type:"address"},{type:"uint24"},{type:"int24"},{type:"address"}],[a.currency0,a.currency1,a.fee,a.tickSpacing,a.hooks]))!==o.poolId&&c();}return o;});}function z(e){return u({...e,chainIds:[e.chainId]},async r=>{if(!/^0x[0-9a-fA-F]{64}$/.test(e.poolId)||!g.safeParse(e.vaultId).success||!I().uuid().safeParse(e.snapshotId).success||e.portfolioSnapshotId!==void 0&&!I().uuid().safeParse(e.portfolioSnapshotId).success)throw new h("invalid-query",400);const o=await f(r,"positions/performance",{chainId:String(e.chainId),poolId:e.poolId.toLowerCase(),kind:"borrow_vault",vaultId:e.vaultId,snapshotId:e.snapshotId,...(e.portfolioSnapshotId?{portfolioSnapshotId:e.portfolioSnapshotId}:{})},D,{omitChainIds:!0,responseLimit:32*1024});if(Date.parse(o.expiresAt)<=Date.now())throw new h("snapshot-expired",410);return(o.account!==r.query.account||o.chainId!==e.chainId||o.poolId!==e.poolId.toLowerCase()||o.vaultId!==e.vaultId||o.snapshotId!==e.snapshotId||o.portfolioSnapshotId!==(e.portfolioSnapshotId??null)||Date.parse(o.capturedAt)>Date.now()+6e4||Date.parse(o.expiresAt)-Date.parse(o.capturedAt)>6e5)&&c(),o;});}export{h as AegisEngineAccountReadError,M as createEngineTransactionHistory,j as engineAccountPositionKey,J as engineAccountTransactionKey,O as engineHistoryCatalogResponseSchema,U as enginePortfolioPriceFor,G as enginePositionHistoryResponseSchema,Z as engineTransactionStorageKey,Q as fetchEngineAccountActivity,V as fetchEngineAccountPortfolio,W as fetchEngineHistoryPositions,L as fetchEnginePositionAccounting,X as fetchEnginePositionHistory,z as fetchEnginePositionPerformance,F as fetchEnginePositionPnl,Y as fetchEngineTransactionStatus,ee as formatEngineAccountTokenAmount,ae as groupEngineAccountActivity,oe as groupEnginePortfolioPositions,se as mergeEngineTransactionRecord,ne as parseEngineTransactionRecords,te as resolveEngineAccountPositionTarget,re as serializeEngineTransactionRecords};