New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@0x/0x-parser

Package Overview
Dependencies
Maintainers
10
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0x/0x-parser - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

dist/parseSwapV2.d.ts

2

dist/index.cjs.js

@@ -1,1 +0,1 @@

"use strict";var N=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var $=Object.prototype.hasOwnProperty;var j=(r,t)=>{for(var s in t)N(r,s,{get:t[s],enumerable:true})};var q=(r,t,s,a)=>{if(t&&typeof t==="object"||typeof t==="function"){for(let n of W(t))if(!$.call(r,n)&&n!==s)N(r,n,{get:()=>t[n],enumerable:!(a=G(t,n))||a.enumerable})}return r};var Z=r=>q(N({},"__esModule",{value:true}),r);var Et={};j(Et,{parseSwap:()=>Tt});module.exports=Z(Et);var C=require("viem");var Y=require("viem/chains");var l=require("viem");var P={LimitOrderFilled:"0xab614d2b738543c0ea21f56347cf696a3a0c42a7cbec3212a5ca22a4dcff2124",LiquidityProviderSwap:"0x40a6ba9513d09e3488135e0e0d10e2d4382b792720155b144cbea89ac9db6d34",OtcOrderFilled:"0xac75f773e3a92f1a02b12134d65e1f47f8a14eabe4eaf1e24624918e6a8b269f",MetaTransactionExecuted:"0x7f4fe3ff8ae440e1570c558da08440b26f89fb1c1f2910cd91ca6452955f121a",Transfer:"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",TransformedERC20:"0x0f6672f78a59ba8e5e5b5d38df3ebc67f3c792e2c9259b8d97d7f00dd78ba1b3"};var M={permitAndCall:{IERC2612:"0x34b4d153",IERC20PermitAllowed:"0x7f9cb4d7",IERC20MetaTransaction:"0x9d50b5e4"}};var B="https://raw.githubusercontent.com/0xProject/protocol/development/packages/contract-artifacts/artifacts/IZeroEx.json";var k="0xDef1C0ded9bec7F1a1670819833240f027b25EfF";var D={1:"0x1291C02D288de3De7dC25353459489073D11E1Ae",137:"0x2Ddd30fE5c12FC4CD497526F14Bf3d1fcd3D5Db4",8453:"0x3CA53031Ad0B86a304845e83644983Be3340895f"};var S={1:k,5:"0xF91bB752490473B8342a3E964E855b9f9a2A668e",10:"0xDEF1ABE32c034e558Cdd535791643C58a13aCC10",56:k,137:k,250:"0xDEF189DeAEF76E379df891899eb5A00a94cBC250",8453:k,42161:k,42220:k,43114:k};var x={weth:"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"};var p={symbol:"ETH",decimals:18,address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"};var R={1:"ETH",5:"ETH",10:"ETH",56:"BNB",137:"MATIC",250:"FTM",8453:"ETH",42161:"ETH",42220:"CELO",43114:"AVAX"};var I=[{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"symbol",stateMutability:"view",inputs:[],outputs:[{name:"",type:"string"}]}];var h=require("viem");function H(r){return`0x${r.slice(-40)}`}function V(r){return[1,5,10,56,137,250,8453,42220,43114,42161].includes(r)}function v(r){return[1,137,8453].includes(r)}async function f({publicClient:r,transactionReceipt:t}){const{logs:s}=t;const a=s.filter(c=>c.topics[0]===P.Transfer).map(c=>({...c,address:(0,h.getAddress)(c.address)}));const n=[...a.map(c=>({abi:I,address:c.address,functionName:"symbol"})),...a.map(c=>({abi:I,address:c.address,functionName:"decimals"}))];const o=await r.multicall({contracts:n});const e=Math.floor(o.length/2);const i=a.map((c,d)=>{const u=o[d].result;const m=o[e+d].result;const b=(0,h.formatUnits)(BigInt(c.data),m);const{address:E,topics:A}=c;const{1:T,2:g}=A;const w=(0,h.getAddress)(H(T));const O=(0,h.getAddress)(H(g));return{to:O,from:w,symbol:u,amount:b,address:E,decimals:m}}).filter(c=>c.amount!=="0");return i}function y(r,t){return{tokenIn:{symbol:r.symbol,amount:r.amount,address:(0,h.getAddress)(r.address)},tokenOut:{symbol:t.symbol,amount:t.amount,address:(0,h.getAddress)(t.address)}}}var L=[{inputs:[{internalType:"contract IERC2612",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20PermitAllowed",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"bool",name:"allowed",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20MetaTransaction",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[],name:"target",outputs:[{internalType:"address payable",name:"",type:"address"}],stateMutability:"view",type:"function"}];async function z({publicClient:r,transactionReceipt:t}){const s=await f({publicClient:r,transactionReceipt:t});const a=(0,l.getAddress)(t.from);const n=s.find(e=>a===e.from);const o=s.find(e=>a===e.to);if(n&&o){return y(n,o)}}async function J({publicClient:r,transactionReceipt:t}){const s=(0,l.getAddress)(t.from);const a=await f({publicClient:r,transactionReceipt:t});const n=a.find(e=>s===e.from);const o=a.find(e=>e.address===x.weth);if(n&&o){o.symbol=p.symbol;o.address=p.address;return y(n,o)}}async function K({publicClient:r,transactionReceipt:t}){const s=(0,l.getAddress)(t.from);const a=await f({publicClient:r,transactionReceipt:t});const n=a.find(e=>e.address===x.weth);const o=a.find(e=>e.to===s);if(n&&o){n.symbol=p.symbol;n.address=p.address;return y(n,o)}}async function Q({callData:r,publicClient:t,exchangeProxyAbi:s,transactionReceipt:a}){const{args:n}=(0,l.decodeFunctionData)({abi:s,data:r});const[o]=n;const e=await f({publicClient:t,transactionReceipt:a});const{maker:i,taker:c}=o;const d=e.find(m=>m.from===c);const u=e.find(m=>m.from===i);if(d&&u){return y(d,u)}}async function tt({publicClient:r,transactionReceipt:t}){const s=await f({publicClient:r,transactionReceipt:t});const a=(0,l.getAddress)(t.from);const n=s.find(e=>e.from===a);const o=s.find(e=>e.to===a);if(n&&o){return y(n,o)}}async function et({publicClient:r,transactionReceipt:t}){const s=await f({publicClient:r,transactionReceipt:t});const a=s.find(o=>o.address!==x.weth);const n=s.find(o=>o.address===x.weth);if(a&&n){n.symbol=p.symbol;n.address=p.address;return y(a,n)}}async function nt({publicClient:r,transactionReceipt:t}){const s=await f({publicClient:r,transactionReceipt:t});const a=(0,l.getAddress)(t.from);const n=s.find(e=>e.from===a);const o=s.find(e=>e.address===x.weth);if(n&&o){o.symbol=p.symbol;o.address=p.address;return y(n,o)}}async function ot({publicClient:r,transactionReceipt:t}){const s=await f({publicClient:r,transactionReceipt:t});const a=(0,l.getAddress)(t.from);const n=s.find(e=>a===e.from);const o=s.find(e=>a===e.to);if(n&&o){return y(n,o)}}async function st({publicClient:r,transactionReceipt:t}){const s=await f({publicClient:r,transactionReceipt:t});const a=(0,l.getAddress)(t.from);const n=s.find(e=>e.address===x.weth);const o=s.find(e=>a===e.to);if(n&&o){n.symbol=p.symbol;n.address=p.address;return y(n,o)}}async function rt({publicClient:r,transactionReceipt:t}){const s=await f({publicClient:r,transactionReceipt:t});const a=s[0];const n=s[s.length-1];return y(a,n)}async function at({chainId:r,publicClient:t,exchangeProxyAbi:s,transactionReceipt:a}){const n=R[r];for(const o of a.logs){const{topics:e,data:i}=o;const[c]=e;if(c===P.TransformedERC20){let d;let u;let m;let b;const E=(0,l.decodeEventLog)({data:i,topics:e,abi:s});const{inputToken:A,outputToken:T,inputTokenAmount:g,outputTokenAmount:w}=E.args;const O={address:A,abi:I};const _={address:T,abi:I};if(A===p.address){d=n;u=18}else{[{result:d},{result:u}]=await t.multicall({contracts:[{...O,functionName:"symbol"},{...O,functionName:"decimals"}]})}if(T===p.address){m=n;b=18}else{[{result:m},{result:b}]=await t.multicall({contracts:[{..._,functionName:"symbol"},{..._,functionName:"decimals"}]})}const U=(0,l.formatUnits)(g,u);const X=(0,l.formatUnits)(w,b);return{tokenIn:{address:A,amount:U,symbol:d},tokenOut:{address:T,amount:X,symbol:m}}}}}async function it({publicClient:r,transactionReceipt:t}){const s=await f({publicClient:r,transactionReceipt:t});const a=(0,l.getAddress)(t.from);const n=s.find(e=>a===e.from);const o=s.find(e=>a===e.to);if(n&&o){return y(n,o)}}async function ct({callData:r,publicClient:t,exchangeProxyAbi:s,transactionReceipt:a}){const n=await f({publicClient:t,transactionReceipt:a});const{args:o}=(0,l.decodeFunctionData)({abi:s,data:r});const[e]=o;return n.reduce((i,c)=>{const{symbol:d,amount:u,address:m}=c;if(m===x.weth){return{...i,tokenOut:{...i.tokenOut,amount:(Number(i.tokenOut.amount)+Number(u)).toString()}}}else if(m===e){return{...i,tokenIn:{...i.tokenIn,symbol:d,address:m,amount:(Number(i.tokenIn.amount)+Number(u)).toString()}}}else{return i}},{tokenIn:{address:"",amount:"",symbol:""},tokenOut:{amount:"",symbol:p.symbol,address:p.address}})}async function dt({callData:r,transaction:t,publicClient:s,exchangeProxyAbi:a,transactionReceipt:n}){const{value:o}=t;const{args:e}=(0,l.decodeFunctionData)({abi:a,data:r});const i=await f({publicClient:s,transactionReceipt:n});const[c]=e;const d=1000000000000000000n;const u=o/d;const m=o%d;const b=Number(u)+Number(m)/Number(d);const E=i.reduce((g,w)=>{return w.address===c?g+Number(w.amount):g},0);const A=i.find(g=>g.address===x.weth);const T=i.find(g=>g.address===c);if(A&&T){return{tokenIn:{symbol:p.symbol,amount:b.toString(),address:p.address},tokenOut:{symbol:T.symbol,amount:E.toString(),address:T.address}}}}async function lt({callData:r,publicClient:t,exchangeProxyAbi:s,transactionReceipt:a}){const n=await f({publicClient:t,transactionReceipt:a});const{args:o}=(0,l.decodeFunctionData)({abi:s,data:r});const[e,i]=o;const c={[e]:{amount:"0",symbol:"",address:""},[i]:{amount:"0",symbol:"",address:""}};n.forEach(({address:d,symbol:u,amount:m})=>{if((0,l.getAddress)(d)in c){c[(0,l.getAddress)(d)].address=(0,l.getAddress)(d);c[(0,l.getAddress)(d)].symbol=u;c[(0,l.getAddress)(d)].amount=(Number(c[(0,l.getAddress)(d)].amount)+Number(m)).toString()}});return{tokenIn:c[e],tokenOut:c[i]}}async function ut({publicClient:r,transactionReceipt:t}){const s=await f({publicClient:r,transactionReceipt:t});const a=(0,l.getAddress)(S[56]);const n=(0,l.getAddress)(t.from);let o=s.find(i=>i.from===n);let e=s.find(i=>i.from!==n);if(o===void 0){o=s.find(i=>i.from===a);e=s.find(i=>i.from!==a)}if(!s.some(i=>i.to===n)){e=s.find(i=>i.to===a)}if(o&&e){return y(o,e)}}async function mt({callData:r,publicClient:t,exchangeProxyAbi:s,transactionReceipt:a}){const{args:n}=(0,l.decodeFunctionData)({abi:s,data:r});const o=await f({publicClient:t,transactionReceipt:a});const[e]=n;const{makerToken:i,takerToken:c}=e;const d=o.find(m=>m.address===c);const u=o.find(m=>m.address===i);if(d&&u){u.symbol=p.symbol;u.address=p.address;return y(d,u)}}async function pt({callData:r,publicClient:t,exchangeProxyAbi:s,transactionReceipt:a}){const{args:n}=(0,l.decodeFunctionData)({abi:s,data:r});const o=await f({publicClient:t,transactionReceipt:a});const[e]=n;const{makerToken:i,takerToken:c}=e;const d=o.find(m=>m.address===c);const u=o.find(m=>m.address===i);if(d&&u){d.symbol=p.symbol;d.address=p.address;return y(d,u)}}async function ft({callData:r,publicClient:t,exchangeProxyAbi:s,transactionReceipt:a}){const{args:n}=(0,l.decodeFunctionData)({abi:s,data:r});const[o]=n;const{maker:e,taker:i}=o;const c=await f({publicClient:t,transactionReceipt:a});if(typeof e==="string"&&typeof i==="string"){const d=c.find(m=>m.from===i);const u=c.find(m=>m.from===e);if(d&&u){return y(d,u)}}}async function yt({callData:r,publicClient:t,exchangeProxyAbi:s,transactionReceipt:a}){const{args:n}=(0,l.decodeFunctionData)({abi:s,data:r});const[o]=n;const{signer:e}=o;const i=await f({publicClient:t,transactionReceipt:a});if(typeof e==="string"){const c=i.find(u=>u.from===e);const d=i.find(u=>u.to===e);if(c&&d){return y(c,d)}}}async function bt({chainId:r,transaction:t,publicClient:s,exchangeProxyAbi:a,transactionReceipt:n,callData:o}){const{args:e}=(0,l.decodeFunctionData)({abi:a,data:o});const[i]=e;const{callData:c}=i;const{functionName:d}=(0,l.decodeFunctionData)({data:c,abi:a});const u=F[d];return u({chainId:r,callData:c,transaction:t,publicClient:s,exchangeProxyAbi:a,transactionReceipt:n})}function gt({chainId:r,transaction:t,publicClient:s,exchangeProxyAbi:a,transactionReceipt:n}){const{args:o}=(0,l.decodeFunctionData)({abi:L,data:t.input});let e;const i=(0,l.encodeFunctionData)({abi:L,functionName:"permitAndCall",args:[...o]});const c=i.slice(0,10);const{IERC2612:d,IERC20PermitAllowed:u,IERC20MetaTransaction:m}=M.permitAndCall;switch(c){case d:e=o[7];break;case u:e=o[8];break;case m:e=o[6];break}if(e){const{functionName:b}=(0,l.decodeFunctionData)({abi:a,data:e});const E=F[b];return E({chainId:r,callData:e,transaction:t,publicClient:s,exchangeProxyAbi:a,transactionReceipt:n})}}var F={fillLimitOrder:ft,fillOtcOrder:tt,fillOtcOrderForEth:mt,fillOtcOrderWithEth:pt,fillTakerSignedOtcOrder:Q,fillTakerSignedOtcOrderForEth:et,executeMetaTransaction:yt,executeMetaTransactionV2:bt,multiplexBatchSellTokenForToken:lt,multiplexBatchSellTokenForEth:ct,multiplexBatchSellEthForToken:dt,multiplexMultiHopSellTokenForToken:it,multiplexMultiHopSellEthForToken:K,multiplexMultiHopSellTokenForEth:J,permitAndCall:gt,sellToUniswap:rt,sellTokenForEthToUniswapV3:nt,sellEthForTokenToUniswapV3:st,sellTokenForTokenToUniswapV3:ot,sellToLiquidityProvider:z,sellToPancakeSwap:ut,transformERC20:at};async function Tt({rpcUrl:r,exchangeProxyAbi:t,transactionHash:s}){if(!r)throw new Error("Missing rpcUrl\u2026");if(!s)throw new Error("Missing transaction hash\u2026");if(!t){throw new Error(`Missing 0x Exchange Proxy ABI: ${B}\u2026`)}const a=(0,C.createPublicClient)({chain:Y.mainnet,transport:(0,C.http)(r)});const{getChainId:n,getTransaction:o,getTransactionReceipt:e}=a;const[i,c,d]=await Promise.all([n(),o({hash:s}),e({hash:s})]);if(d.status==="reverted"){return null}if(!V(i)){throw new Error(`chainId ${i} is unsupported\u2026`)}const u=S[i];const m=v(i)?D[i]:null;const b=(0,C.getAddress)(c.to);const E=b===u;const A=b===m;if(!E&&!A){return null}const{functionName:T}=E?(0,C.decodeFunctionData)({abi:t,data:c.input}):(0,C.decodeFunctionData)({abi:L,data:c.input});const g=F[T];return g({chainId:i,transaction:c,publicClient:a,exchangeProxyAbi:t,transactionReceipt:d,callData:c.input})}0&&(module.exports={parseSwap});
"use strict";var M=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var Z=(o,e)=>{for(var s in e)M(o,s,{get:e[s],enumerable:true})};var z=(o,e,s,a)=>{if(e&&typeof e==="object"||typeof e==="function"){for(let n of q(e))if(!K.call(o,n)&&n!==s)M(o,n,{get:()=>e[n],enumerable:!(a=j(e,n))||a.enumerable})}return o};var J=o=>z(M({},"__esModule",{value:true}),o);var wt={};Z(wt,{parseSwap:()=>It,parseSwapV2:()=>X});module.exports=J(wt);var h=require("viem");var G=require("viem/chains");var l=require("viem");var N={LimitOrderFilled:"0xab614d2b738543c0ea21f56347cf696a3a0c42a7cbec3212a5ca22a4dcff2124",LiquidityProviderSwap:"0x40a6ba9513d09e3488135e0e0d10e2d4382b792720155b144cbea89ac9db6d34",OtcOrderFilled:"0xac75f773e3a92f1a02b12134d65e1f47f8a14eabe4eaf1e24624918e6a8b269f",MetaTransactionExecuted:"0x7f4fe3ff8ae440e1570c558da08440b26f89fb1c1f2910cd91ca6452955f121a",Transfer:"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",TransformedERC20:"0x0f6672f78a59ba8e5e5b5d38df3ebc67f3c792e2c9259b8d97d7f00dd78ba1b3"};var B={permitAndCall:{IERC2612:"0x34b4d153",IERC20PermitAllowed:"0x7f9cb4d7",IERC20MetaTransaction:"0x9d50b5e4"}};var R="https://raw.githubusercontent.com/0xProject/protocol/development/packages/contract-artifacts/artifacts/IZeroEx.json";var w="0xDef1C0ded9bec7F1a1670819833240f027b25EfF";var D={1:"0x1291C02D288de3De7dC25353459489073D11E1Ae",137:"0x2Ddd30fE5c12FC4CD497526F14Bf3d1fcd3D5Db4",8453:"0x3CA53031Ad0B86a304845e83644983Be3340895f"};var F={1:w,5:"0xF91bB752490473B8342a3E964E855b9f9a2A668e",10:"0xDEF1ABE32c034e558Cdd535791643C58a13aCC10",56:w,137:w,250:"0xDEF189DeAEF76E379df891899eb5A00a94cBC250",8453:w,42161:w,42220:w,43114:w};var C={weth:"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"};var p={symbol:"ETH",decimals:18,address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"};var H={1:"ETH",5:"ETH",10:"ETH",56:"BNB",137:"MATIC",250:"FTM",8453:"ETH",42161:"ETH",42220:"CELO",43114:"AVAX"};var S=[{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"symbol",stateMutability:"view",inputs:[],outputs:[{name:"",type:"string"}]}];var I=require("viem");function V(o){return`0x${o.slice(-40)}`}function v(o){return[1,5,10,56,137,250,8453,42220,43114,42161].includes(o)}function Y(o){return[1,137,8453].includes(o)}async function f({publicClient:o,transactionReceipt:e}){const{logs:s}=e;const a=s.filter(i=>i.topics[0]===N.Transfer).map(i=>({...i,address:(0,I.getAddress)(i.address)}));const n=[...a.map(i=>({abi:S,address:i.address,functionName:"symbol"})),...a.map(i=>({abi:S,address:i.address,functionName:"decimals"}))];const r=await o.multicall({contracts:n});const t=Math.floor(r.length/2);const d=a.map((i,c)=>{const u=r[c].result;const m=r[t+c].result;const b=(0,I.formatUnits)(BigInt(i.data),m);const{address:T,topics:A}=i;const{1:E,2:g}=A;const k=(0,I.getAddress)(V(E));const L=(0,I.getAddress)(V(g));return{to:L,from:k,symbol:u,amount:b,address:T,decimals:m}}).filter(i=>i.amount!=="0");return d}function y(o,e){return{tokenIn:{symbol:o.symbol,amount:o.amount,address:(0,I.getAddress)(o.address)},tokenOut:{symbol:e.symbol,amount:e.amount,address:(0,I.getAddress)(e.address)}}}var O=[{inputs:[{internalType:"contract IERC2612",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20PermitAllowed",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"bool",name:"allowed",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20MetaTransaction",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[],name:"target",outputs:[{internalType:"address payable",name:"",type:"address"}],stateMutability:"view",type:"function"}];async function Q({publicClient:o,transactionReceipt:e}){const s=await f({publicClient:o,transactionReceipt:e});const a=(0,l.getAddress)(e.from);const n=s.find(t=>a===t.from);const r=s.find(t=>a===t.to);if(n&&r){return y(n,r)}}async function tt({publicClient:o,transactionReceipt:e}){const s=(0,l.getAddress)(e.from);const a=await f({publicClient:o,transactionReceipt:e});const n=a.find(t=>s===t.from);const r=a.find(t=>t.address===C.weth);if(n&&r){r.symbol=p.symbol;r.address=p.address;return y(n,r)}}async function et({publicClient:o,transactionReceipt:e}){const s=(0,l.getAddress)(e.from);const a=await f({publicClient:o,transactionReceipt:e});const n=a.find(t=>t.address===C.weth);const r=a.find(t=>t.to===s);if(n&&r){n.symbol=p.symbol;n.address=p.address;return y(n,r)}}async function nt({callData:o,publicClient:e,exchangeProxyAbi:s,transactionReceipt:a}){const{args:n}=(0,l.decodeFunctionData)({abi:s,data:o});const[r]=n;const t=await f({publicClient:e,transactionReceipt:a});const{maker:d,taker:i}=r;const c=t.find(m=>m.from===i);const u=t.find(m=>m.from===d);if(c&&u){return y(c,u)}}async function ot({publicClient:o,transactionReceipt:e}){const s=await f({publicClient:o,transactionReceipt:e});const a=(0,l.getAddress)(e.from);const n=s.find(t=>t.from===a);const r=s.find(t=>t.to===a);if(n&&r){return y(n,r)}}async function st({publicClient:o,transactionReceipt:e}){const s=await f({publicClient:o,transactionReceipt:e});const a=s.find(r=>r.address!==C.weth);const n=s.find(r=>r.address===C.weth);if(a&&n){n.symbol=p.symbol;n.address=p.address;return y(a,n)}}async function rt({publicClient:o,transactionReceipt:e}){const s=await f({publicClient:o,transactionReceipt:e});const a=(0,l.getAddress)(e.from);const n=s.find(t=>t.from===a);const r=s.find(t=>t.address===C.weth);if(n&&r){r.symbol=p.symbol;r.address=p.address;return y(n,r)}}async function at({publicClient:o,transactionReceipt:e}){const s=await f({publicClient:o,transactionReceipt:e});const a=(0,l.getAddress)(e.from);const n=s.find(t=>a===t.from);const r=s.find(t=>a===t.to);if(n&&r){return y(n,r)}}async function it({publicClient:o,transactionReceipt:e}){const s=await f({publicClient:o,transactionReceipt:e});const a=(0,l.getAddress)(e.from);const n=s.find(t=>t.address===C.weth);const r=s.find(t=>a===t.to);if(n&&r){n.symbol=p.symbol;n.address=p.address;return y(n,r)}}async function ct({publicClient:o,transactionReceipt:e}){const s=await f({publicClient:o,transactionReceipt:e});const a=s[0];const n=s[s.length-1];return y(a,n)}async function dt({chainId:o,publicClient:e,exchangeProxyAbi:s,transactionReceipt:a}){const n=H[o];for(const r of a.logs){const{topics:t,data:d}=r;const[i]=t;if(i===N.TransformedERC20){let c;let u;let m;let b;const T=(0,l.decodeEventLog)({data:d,topics:t,abi:s});const{inputToken:A,outputToken:E,inputTokenAmount:g,outputTokenAmount:k}=T.args;const L={address:A,abi:S};const P={address:E,abi:S};if(A===p.address){c=n;u=18}else{[{result:c},{result:u}]=await e.multicall({contracts:[{...L,functionName:"symbol"},{...L,functionName:"decimals"}]})}if(E===p.address){m=n;b=18}else{[{result:m},{result:b}]=await e.multicall({contracts:[{...P,functionName:"symbol"},{...P,functionName:"decimals"}]})}const $=(0,l.formatUnits)(g,u);const W=(0,l.formatUnits)(k,b);return{tokenIn:{address:A,amount:$,symbol:c},tokenOut:{address:E,amount:W,symbol:m}}}}}async function ut({publicClient:o,transactionReceipt:e}){const s=await f({publicClient:o,transactionReceipt:e});const a=(0,l.getAddress)(e.from);const n=s.find(t=>a===t.from);const r=s.find(t=>a===t.to);if(n&&r){return y(n,r)}}async function lt({callData:o,publicClient:e,exchangeProxyAbi:s,transactionReceipt:a}){const n=await f({publicClient:e,transactionReceipt:a});const{args:r}=(0,l.decodeFunctionData)({abi:s,data:o});const[t]=r;return n.reduce((d,i)=>{const{symbol:c,amount:u,address:m}=i;if(m===C.weth){return{...d,tokenOut:{...d.tokenOut,amount:(Number(d.tokenOut.amount)+Number(u)).toString()}}}else if(m===t){return{...d,tokenIn:{...d.tokenIn,symbol:c,address:m,amount:(Number(d.tokenIn.amount)+Number(u)).toString()}}}else{return d}},{tokenIn:{address:"",amount:"",symbol:""},tokenOut:{amount:"",symbol:p.symbol,address:p.address}})}async function mt({callData:o,transaction:e,publicClient:s,exchangeProxyAbi:a,transactionReceipt:n}){const{value:r}=e;const{args:t}=(0,l.decodeFunctionData)({abi:a,data:o});const d=await f({publicClient:s,transactionReceipt:n});const[i]=t;const c=1000000000000000000n;const u=r/c;const m=r%c;const b=Number(u)+Number(m)/Number(c);const T=d.reduce((g,k)=>{return k.address===i?g+Number(k.amount):g},0);const A=d.find(g=>g.address===C.weth);const E=d.find(g=>g.address===i);if(A&&E){return{tokenIn:{symbol:p.symbol,amount:b.toString(),address:p.address},tokenOut:{symbol:E.symbol,amount:T.toString(),address:E.address}}}}async function pt({callData:o,publicClient:e,exchangeProxyAbi:s,transactionReceipt:a}){const n=await f({publicClient:e,transactionReceipt:a});const{args:r}=(0,l.decodeFunctionData)({abi:s,data:o});const[t,d]=r;const i={[t]:{amount:"0",symbol:"",address:""},[d]:{amount:"0",symbol:"",address:""}};n.forEach(({address:c,symbol:u,amount:m})=>{if((0,l.getAddress)(c)in i){i[(0,l.getAddress)(c)].address=(0,l.getAddress)(c);i[(0,l.getAddress)(c)].symbol=u;i[(0,l.getAddress)(c)].amount=(Number(i[(0,l.getAddress)(c)].amount)+Number(m)).toString()}});return{tokenIn:i[t],tokenOut:i[d]}}async function ft({publicClient:o,transactionReceipt:e}){const s=await f({publicClient:o,transactionReceipt:e});const a=(0,l.getAddress)(F[56]);const n=(0,l.getAddress)(e.from);let r=s.find(d=>d.from===n);let t=s.find(d=>d.from!==n);if(r===void 0){r=s.find(d=>d.from===a);t=s.find(d=>d.from!==a)}if(!s.some(d=>d.to===n)){t=s.find(d=>d.to===a)}if(r&&t){return y(r,t)}}async function yt({callData:o,publicClient:e,exchangeProxyAbi:s,transactionReceipt:a}){const{args:n}=(0,l.decodeFunctionData)({abi:s,data:o});const r=await f({publicClient:e,transactionReceipt:a});const[t]=n;const{makerToken:d,takerToken:i}=t;const c=r.find(m=>m.address===i);const u=r.find(m=>m.address===d);if(c&&u){u.symbol=p.symbol;u.address=p.address;return y(c,u)}}async function bt({callData:o,publicClient:e,exchangeProxyAbi:s,transactionReceipt:a}){const{args:n}=(0,l.decodeFunctionData)({abi:s,data:o});const r=await f({publicClient:e,transactionReceipt:a});const[t]=n;const{makerToken:d,takerToken:i}=t;const c=r.find(m=>m.address===i);const u=r.find(m=>m.address===d);if(c&&u){c.symbol=p.symbol;c.address=p.address;return y(c,u)}}async function gt({callData:o,publicClient:e,exchangeProxyAbi:s,transactionReceipt:a}){const{args:n}=(0,l.decodeFunctionData)({abi:s,data:o});const[r]=n;const{maker:t,taker:d}=r;const i=await f({publicClient:e,transactionReceipt:a});if(typeof t==="string"&&typeof d==="string"){const c=i.find(m=>m.from===d);const u=i.find(m=>m.from===t);if(c&&u){return y(c,u)}}}async function Et({callData:o,publicClient:e,exchangeProxyAbi:s,transactionReceipt:a}){const{args:n}=(0,l.decodeFunctionData)({abi:s,data:o});const[r]=n;const{signer:t}=r;const d=await f({publicClient:e,transactionReceipt:a});if(typeof t==="string"){const i=d.find(u=>u.from===t);const c=d.find(u=>u.to===t);if(i&&c){return y(i,c)}}}async function Tt({chainId:o,transaction:e,publicClient:s,exchangeProxyAbi:a,transactionReceipt:n,callData:r}){const{args:t}=(0,l.decodeFunctionData)({abi:a,data:r});const[d]=t;const{callData:i}=d;const{functionName:c}=(0,l.decodeFunctionData)({data:i,abi:a});const u=_[c];return u({chainId:o,callData:i,transaction:e,publicClient:s,exchangeProxyAbi:a,transactionReceipt:n})}function At({chainId:o,transaction:e,publicClient:s,exchangeProxyAbi:a,transactionReceipt:n}){const{args:r}=(0,l.decodeFunctionData)({abi:O,data:e.input});let t;const d=(0,l.encodeFunctionData)({abi:O,functionName:"permitAndCall",args:[...r]});const i=d.slice(0,10);const{IERC2612:c,IERC20PermitAllowed:u,IERC20MetaTransaction:m}=B.permitAndCall;switch(i){case c:t=r[7];break;case u:t=r[8];break;case m:t=r[6];break}if(t){const{functionName:b}=(0,l.decodeFunctionData)({abi:a,data:t});const T=_[b];return T({chainId:o,callData:t,transaction:e,publicClient:s,exchangeProxyAbi:a,transactionReceipt:n})}}var _={fillLimitOrder:gt,fillOtcOrder:ot,fillOtcOrderForEth:yt,fillOtcOrderWithEth:bt,fillTakerSignedOtcOrder:nt,fillTakerSignedOtcOrderForEth:st,executeMetaTransaction:Et,executeMetaTransactionV2:Tt,multiplexBatchSellTokenForToken:pt,multiplexBatchSellTokenForEth:lt,multiplexBatchSellEthForToken:mt,multiplexMultiHopSellTokenForToken:ut,multiplexMultiHopSellEthForToken:et,multiplexMultiHopSellTokenForEth:tt,permitAndCall:At,sellToUniswap:ct,sellTokenForEthToUniswapV3:rt,sellEthForTokenToUniswapV3:it,sellTokenForTokenToUniswapV3:at,sellToLiquidityProvider:Q,sellToPancakeSwap:ft,transformERC20:dt};var x=require("viem");var xt="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";var Ct={1:"ETH",10:"ETH",56:"BNB",137:"MATIC",8453:"ETH",42161:"ETH",43114:"AVAX"};function ht(o){return[1,10,56,137,8453,42161,43114].includes(o)}async function kt({publicClient:o,transactionReceipt:e}){const s={Transfer:"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"};const{logs:a}=e;const n=a.filter(c=>c.topics[0]===s.Transfer).map(c=>({...c,address:(0,x.getAddress)(c.address)}));const r=[...n.map(c=>({abi:x.erc20Abi,address:c.address,functionName:"symbol"})),...n.map(c=>({abi:x.erc20Abi,address:c.address,functionName:"decimals"}))];const t=await o.multicall({contracts:r});const d=Math.floor(t.length/2);const i=n.map((c,u)=>{const m=t[u].result;const b=t[d+u].result;const T=c.data==="0x"?"0":(0,x.formatUnits)(BigInt(c.data),b);const{address:A,topics:E}=c;const{1:g,2:k}=E;const L=(0,x.getAddress)(U(g));const P=(0,x.getAddress)(U(k));return{to:P,from:L,symbol:m,amount:T,address:A,decimals:b}}).filter(c=>c.amount!=="0");return i}function U(o){return`0x${o.slice(-40)}`}async function X({publicClient:o,transactionHash:e}){const s=await o.getChainId();if(!ht(s)){throw new Error(`chainId ${s} is unsupported\u2026`)}const a=await o.getTransactionReceipt({hash:e});const{value:n}=await o.getTransaction({hash:e});const r=n>0n;const t=await kt({publicClient:o,transactionReceipt:a});const d=t[0];const i=t[t.length-1];if(r){const c=(0,x.formatUnits)(n,18);return{tokenIn:{symbol:Ct[s],amount:c,address:xt},tokenOut:{symbol:i.symbol,amount:i.amount,address:i.address}}}return{tokenIn:{symbol:d.symbol,amount:d.amount,address:d.address},tokenOut:{symbol:i.symbol,amount:i.amount,address:i.address}}}async function It({rpcUrl:o,exchangeProxyAbi:e,transactionHash:s}){if(!o)throw new Error("Missing rpcUrl\u2026");if(!s)throw new Error("Missing transaction hash\u2026");if(!e){throw new Error(`Missing 0x Exchange Proxy ABI: ${R}\u2026`)}const a=(0,h.createPublicClient)({chain:G.mainnet,transport:(0,h.http)(o)});const{getChainId:n,getTransaction:r,getTransactionReceipt:t}=a;const[d,i,c]=await Promise.all([n(),r({hash:s}),t({hash:s})]);if(c.status==="reverted"){return null}if(!v(d)){throw new Error(`chainId ${d} is unsupported\u2026`)}const u=F[d];const m=Y(d)?D[d]:null;const b=(0,h.getAddress)(i.to);const T=b===u;const A=b===m;if(!T&&!A){return null}const{functionName:E}=T?(0,h.decodeFunctionData)({abi:e,data:i.input}):(0,h.decodeFunctionData)({abi:O,data:i.input});const g=_[E];return g({chainId:d,transaction:i,publicClient:a,exchangeProxyAbi:e,transactionReceipt:c,callData:i.input})}0&&(module.exports={parseSwap,parseSwapV2});
import type { ParseSwapArgs } from "./types";
export * from "./types";
export declare function parseSwap({ rpcUrl, exchangeProxyAbi, transactionHash: hash, }: ParseSwapArgs): Promise<import("./types").TokenTransaction | null>;
/**
* This function is specific to 0x API transactions on Settler.
*/
export { parseSwapV2 } from "./parseSwapV2";

@@ -1,1 +0,1 @@

import{http as yt,getAddress as bt,decodeFunctionData as Y,createPublicClient as gt}from"viem";import{mainnet as Tt}from"viem/chains";import{getAddress as y,formatUnits as v,decodeEventLog as W,decodeFunctionData as T,encodeFunctionData as $}from"viem";var P={LimitOrderFilled:"0xab614d2b738543c0ea21f56347cf696a3a0c42a7cbec3212a5ca22a4dcff2124",LiquidityProviderSwap:"0x40a6ba9513d09e3488135e0e0d10e2d4382b792720155b144cbea89ac9db6d34",OtcOrderFilled:"0xac75f773e3a92f1a02b12134d65e1f47f8a14eabe4eaf1e24624918e6a8b269f",MetaTransactionExecuted:"0x7f4fe3ff8ae440e1570c558da08440b26f89fb1c1f2910cd91ca6452955f121a",Transfer:"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",TransformedERC20:"0x0f6672f78a59ba8e5e5b5d38df3ebc67f3c792e2c9259b8d97d7f00dd78ba1b3"};var _={permitAndCall:{IERC2612:"0x34b4d153",IERC20PermitAllowed:"0x7f9cb4d7",IERC20MetaTransaction:"0x9d50b5e4"}};var M="https://raw.githubusercontent.com/0xProject/protocol/development/packages/contract-artifacts/artifacts/IZeroEx.json";var h="0xDef1C0ded9bec7F1a1670819833240f027b25EfF";var B={1:"0x1291C02D288de3De7dC25353459489073D11E1Ae",137:"0x2Ddd30fE5c12FC4CD497526F14Bf3d1fcd3D5Db4",8453:"0x3CA53031Ad0B86a304845e83644983Be3340895f"};var S={1:h,5:"0xF91bB752490473B8342a3E964E855b9f9a2A668e",10:"0xDEF1ABE32c034e558Cdd535791643C58a13aCC10",56:h,137:h,250:"0xDEF189DeAEF76E379df891899eb5A00a94cBC250",8453:h,42161:h,42220:h,43114:h};var C={weth:"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"};var m={symbol:"ETH",decimals:18,address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"};var D={1:"ETH",5:"ETH",10:"ETH",56:"BNB",137:"MATIC",250:"FTM",8453:"ETH",42161:"ETH",42220:"CELO",43114:"AVAX"};var w=[{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"symbol",stateMutability:"view",inputs:[],outputs:[{name:"",type:"string"}]}];import{getAddress as I,formatUnits as G}from"viem";function R(a){return`0x${a.slice(-40)}`}function H(a){return[1,5,10,56,137,250,8453,42220,43114,42161].includes(a)}function V(a){return[1,137,8453].includes(a)}async function p({publicClient:a,transactionReceipt:o}){const{logs:s}=o;const r=s.filter(c=>c.topics[0]===P.Transfer).map(c=>({...c,address:I(c.address)}));const n=[...r.map(c=>({abi:w,address:c.address,functionName:"symbol"})),...r.map(c=>({abi:w,address:c.address,functionName:"decimals"}))];const e=await a.multicall({contracts:n});const t=Math.floor(e.length/2);const i=r.map((c,d)=>{const l=e[d].result;const u=e[t+d].result;const b=G(BigInt(c.data),u);const{address:A,topics:x}=c;const{1:E,2:g}=x;const k=I(R(E));const O=I(R(g));return{to:O,from:k,symbol:l,amount:b,address:A,decimals:u}}).filter(c=>c.amount!=="0");return i}function f(a,o){return{tokenIn:{symbol:a.symbol,amount:a.amount,address:I(a.address)},tokenOut:{symbol:o.symbol,amount:o.amount,address:I(o.address)}}}var L=[{inputs:[{internalType:"contract IERC2612",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20PermitAllowed",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"bool",name:"allowed",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20MetaTransaction",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[],name:"target",outputs:[{internalType:"address payable",name:"",type:"address"}],stateMutability:"view",type:"function"}];async function j({publicClient:a,transactionReceipt:o}){const s=await p({publicClient:a,transactionReceipt:o});const r=y(o.from);const n=s.find(t=>r===t.from);const e=s.find(t=>r===t.to);if(n&&e){return f(n,e)}}async function q({publicClient:a,transactionReceipt:o}){const s=y(o.from);const r=await p({publicClient:a,transactionReceipt:o});const n=r.find(t=>s===t.from);const e=r.find(t=>t.address===C.weth);if(n&&e){e.symbol=m.symbol;e.address=m.address;return f(n,e)}}async function Z({publicClient:a,transactionReceipt:o}){const s=y(o.from);const r=await p({publicClient:a,transactionReceipt:o});const n=r.find(t=>t.address===C.weth);const e=r.find(t=>t.to===s);if(n&&e){n.symbol=m.symbol;n.address=m.address;return f(n,e)}}async function z({callData:a,publicClient:o,exchangeProxyAbi:s,transactionReceipt:r}){const{args:n}=T({abi:s,data:a});const[e]=n;const t=await p({publicClient:o,transactionReceipt:r});const{maker:i,taker:c}=e;const d=t.find(u=>u.from===c);const l=t.find(u=>u.from===i);if(d&&l){return f(d,l)}}async function J({publicClient:a,transactionReceipt:o}){const s=await p({publicClient:a,transactionReceipt:o});const r=y(o.from);const n=s.find(t=>t.from===r);const e=s.find(t=>t.to===r);if(n&&e){return f(n,e)}}async function K({publicClient:a,transactionReceipt:o}){const s=await p({publicClient:a,transactionReceipt:o});const r=s.find(e=>e.address!==C.weth);const n=s.find(e=>e.address===C.weth);if(r&&n){n.symbol=m.symbol;n.address=m.address;return f(r,n)}}async function Q({publicClient:a,transactionReceipt:o}){const s=await p({publicClient:a,transactionReceipt:o});const r=y(o.from);const n=s.find(t=>t.from===r);const e=s.find(t=>t.address===C.weth);if(n&&e){e.symbol=m.symbol;e.address=m.address;return f(n,e)}}async function tt({publicClient:a,transactionReceipt:o}){const s=await p({publicClient:a,transactionReceipt:o});const r=y(o.from);const n=s.find(t=>r===t.from);const e=s.find(t=>r===t.to);if(n&&e){return f(n,e)}}async function et({publicClient:a,transactionReceipt:o}){const s=await p({publicClient:a,transactionReceipt:o});const r=y(o.from);const n=s.find(t=>t.address===C.weth);const e=s.find(t=>r===t.to);if(n&&e){n.symbol=m.symbol;n.address=m.address;return f(n,e)}}async function nt({publicClient:a,transactionReceipt:o}){const s=await p({publicClient:a,transactionReceipt:o});const r=s[0];const n=s[s.length-1];return f(r,n)}async function ot({chainId:a,publicClient:o,exchangeProxyAbi:s,transactionReceipt:r}){const n=D[a];for(const e of r.logs){const{topics:t,data:i}=e;const[c]=t;if(c===P.TransformedERC20){let d;let l;let u;let b;const A=W({data:i,topics:t,abi:s});const{inputToken:x,outputToken:E,inputTokenAmount:g,outputTokenAmount:k}=A.args;const O={address:x,abi:w};const N={address:E,abi:w};if(x===m.address){d=n;l=18}else{[{result:d},{result:l}]=await o.multicall({contracts:[{...O,functionName:"symbol"},{...O,functionName:"decimals"}]})}if(E===m.address){u=n;b=18}else{[{result:u},{result:b}]=await o.multicall({contracts:[{...N,functionName:"symbol"},{...N,functionName:"decimals"}]})}const U=v(g,l);const X=v(k,b);return{tokenIn:{address:x,amount:U,symbol:d},tokenOut:{address:E,amount:X,symbol:u}}}}}async function st({publicClient:a,transactionReceipt:o}){const s=await p({publicClient:a,transactionReceipt:o});const r=y(o.from);const n=s.find(t=>r===t.from);const e=s.find(t=>r===t.to);if(n&&e){return f(n,e)}}async function rt({callData:a,publicClient:o,exchangeProxyAbi:s,transactionReceipt:r}){const n=await p({publicClient:o,transactionReceipt:r});const{args:e}=T({abi:s,data:a});const[t]=e;return n.reduce((i,c)=>{const{symbol:d,amount:l,address:u}=c;if(u===C.weth){return{...i,tokenOut:{...i.tokenOut,amount:(Number(i.tokenOut.amount)+Number(l)).toString()}}}else if(u===t){return{...i,tokenIn:{...i.tokenIn,symbol:d,address:u,amount:(Number(i.tokenIn.amount)+Number(l)).toString()}}}else{return i}},{tokenIn:{address:"",amount:"",symbol:""},tokenOut:{amount:"",symbol:m.symbol,address:m.address}})}async function at({callData:a,transaction:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:n}){const{value:e}=o;const{args:t}=T({abi:r,data:a});const i=await p({publicClient:s,transactionReceipt:n});const[c]=t;const d=1000000000000000000n;const l=e/d;const u=e%d;const b=Number(l)+Number(u)/Number(d);const A=i.reduce((g,k)=>{return k.address===c?g+Number(k.amount):g},0);const x=i.find(g=>g.address===C.weth);const E=i.find(g=>g.address===c);if(x&&E){return{tokenIn:{symbol:m.symbol,amount:b.toString(),address:m.address},tokenOut:{symbol:E.symbol,amount:A.toString(),address:E.address}}}}async function it({callData:a,publicClient:o,exchangeProxyAbi:s,transactionReceipt:r}){const n=await p({publicClient:o,transactionReceipt:r});const{args:e}=T({abi:s,data:a});const[t,i]=e;const c={[t]:{amount:"0",symbol:"",address:""},[i]:{amount:"0",symbol:"",address:""}};n.forEach(({address:d,symbol:l,amount:u})=>{if(y(d)in c){c[y(d)].address=y(d);c[y(d)].symbol=l;c[y(d)].amount=(Number(c[y(d)].amount)+Number(u)).toString()}});return{tokenIn:c[t],tokenOut:c[i]}}async function ct({publicClient:a,transactionReceipt:o}){const s=await p({publicClient:a,transactionReceipt:o});const r=y(S[56]);const n=y(o.from);let e=s.find(i=>i.from===n);let t=s.find(i=>i.from!==n);if(e===void 0){e=s.find(i=>i.from===r);t=s.find(i=>i.from!==r)}if(!s.some(i=>i.to===n)){t=s.find(i=>i.to===r)}if(e&&t){return f(e,t)}}async function dt({callData:a,publicClient:o,exchangeProxyAbi:s,transactionReceipt:r}){const{args:n}=T({abi:s,data:a});const e=await p({publicClient:o,transactionReceipt:r});const[t]=n;const{makerToken:i,takerToken:c}=t;const d=e.find(u=>u.address===c);const l=e.find(u=>u.address===i);if(d&&l){l.symbol=m.symbol;l.address=m.address;return f(d,l)}}async function lt({callData:a,publicClient:o,exchangeProxyAbi:s,transactionReceipt:r}){const{args:n}=T({abi:s,data:a});const e=await p({publicClient:o,transactionReceipt:r});const[t]=n;const{makerToken:i,takerToken:c}=t;const d=e.find(u=>u.address===c);const l=e.find(u=>u.address===i);if(d&&l){d.symbol=m.symbol;d.address=m.address;return f(d,l)}}async function ut({callData:a,publicClient:o,exchangeProxyAbi:s,transactionReceipt:r}){const{args:n}=T({abi:s,data:a});const[e]=n;const{maker:t,taker:i}=e;const c=await p({publicClient:o,transactionReceipt:r});if(typeof t==="string"&&typeof i==="string"){const d=c.find(u=>u.from===i);const l=c.find(u=>u.from===t);if(d&&l){return f(d,l)}}}async function mt({callData:a,publicClient:o,exchangeProxyAbi:s,transactionReceipt:r}){const{args:n}=T({abi:s,data:a});const[e]=n;const{signer:t}=e;const i=await p({publicClient:o,transactionReceipt:r});if(typeof t==="string"){const c=i.find(l=>l.from===t);const d=i.find(l=>l.to===t);if(c&&d){return f(c,d)}}}async function pt({chainId:a,transaction:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:n,callData:e}){const{args:t}=T({abi:r,data:e});const[i]=t;const{callData:c}=i;const{functionName:d}=T({data:c,abi:r});const l=F[d];return l({chainId:a,callData:c,transaction:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:n})}function ft({chainId:a,transaction:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:n}){const{args:e}=T({abi:L,data:o.input});let t;const i=$({abi:L,functionName:"permitAndCall",args:[...e]});const c=i.slice(0,10);const{IERC2612:d,IERC20PermitAllowed:l,IERC20MetaTransaction:u}=_.permitAndCall;switch(c){case d:t=e[7];break;case l:t=e[8];break;case u:t=e[6];break}if(t){const{functionName:b}=T({abi:r,data:t});const A=F[b];return A({chainId:a,callData:t,transaction:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:n})}}var F={fillLimitOrder:ut,fillOtcOrder:J,fillOtcOrderForEth:dt,fillOtcOrderWithEth:lt,fillTakerSignedOtcOrder:z,fillTakerSignedOtcOrderForEth:K,executeMetaTransaction:mt,executeMetaTransactionV2:pt,multiplexBatchSellTokenForToken:it,multiplexBatchSellTokenForEth:rt,multiplexBatchSellEthForToken:at,multiplexMultiHopSellTokenForToken:st,multiplexMultiHopSellEthForToken:Z,multiplexMultiHopSellTokenForEth:q,permitAndCall:ft,sellToUniswap:nt,sellTokenForEthToUniswapV3:Q,sellEthForTokenToUniswapV3:et,sellTokenForTokenToUniswapV3:tt,sellToLiquidityProvider:j,sellToPancakeSwap:ct,transformERC20:ot};async function Vt({rpcUrl:a,exchangeProxyAbi:o,transactionHash:s}){if(!a)throw new Error("Missing rpcUrl\u2026");if(!s)throw new Error("Missing transaction hash\u2026");if(!o){throw new Error(`Missing 0x Exchange Proxy ABI: ${M}\u2026`)}const r=gt({chain:Tt,transport:yt(a)});const{getChainId:n,getTransaction:e,getTransactionReceipt:t}=r;const[i,c,d]=await Promise.all([n(),e({hash:s}),t({hash:s})]);if(d.status==="reverted"){return null}if(!H(i)){throw new Error(`chainId ${i} is unsupported\u2026`)}const l=S[i];const u=V(i)?B[i]:null;const b=bt(c.to);const A=b===l;const x=b===u;if(!A&&!x){return null}const{functionName:E}=A?Y({abi:o,data:c.input}):Y({abi:L,data:c.input});const g=F[E];return g({chainId:i,transaction:c,publicClient:r,exchangeProxyAbi:o,transactionReceipt:d,callData:c.input})}export{Vt as parseSwap};
import{http as kt,getAddress as It,decodeFunctionData as $,createPublicClient as wt}from"viem";import{mainnet as Lt}from"viem/chains";import{getAddress as y,formatUnits as Y,decodeEventLog as K,decodeFunctionData as A,encodeFunctionData as Z}from"viem";var P={LimitOrderFilled:"0xab614d2b738543c0ea21f56347cf696a3a0c42a7cbec3212a5ca22a4dcff2124",LiquidityProviderSwap:"0x40a6ba9513d09e3488135e0e0d10e2d4382b792720155b144cbea89ac9db6d34",OtcOrderFilled:"0xac75f773e3a92f1a02b12134d65e1f47f8a14eabe4eaf1e24624918e6a8b269f",MetaTransactionExecuted:"0x7f4fe3ff8ae440e1570c558da08440b26f89fb1c1f2910cd91ca6452955f121a",Transfer:"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",TransformedERC20:"0x0f6672f78a59ba8e5e5b5d38df3ebc67f3c792e2c9259b8d97d7f00dd78ba1b3"};var M={permitAndCall:{IERC2612:"0x34b4d153",IERC20PermitAllowed:"0x7f9cb4d7",IERC20MetaTransaction:"0x9d50b5e4"}};var B="https://raw.githubusercontent.com/0xProject/protocol/development/packages/contract-artifacts/artifacts/IZeroEx.json";var k="0xDef1C0ded9bec7F1a1670819833240f027b25EfF";var R={1:"0x1291C02D288de3De7dC25353459489073D11E1Ae",137:"0x2Ddd30fE5c12FC4CD497526F14Bf3d1fcd3D5Db4",8453:"0x3CA53031Ad0B86a304845e83644983Be3340895f"};var N={1:k,5:"0xF91bB752490473B8342a3E964E855b9f9a2A668e",10:"0xDEF1ABE32c034e558Cdd535791643C58a13aCC10",56:k,137:k,250:"0xDEF189DeAEF76E379df891899eb5A00a94cBC250",8453:k,42161:k,42220:k,43114:k};var C={weth:"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"};var m={symbol:"ETH",decimals:18,address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"};var D={1:"ETH",5:"ETH",10:"ETH",56:"BNB",137:"MATIC",250:"FTM",8453:"ETH",42161:"ETH",42220:"CELO",43114:"AVAX"};var w=[{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"symbol",stateMutability:"view",inputs:[],outputs:[{name:"",type:"string"}]}];import{getAddress as L,formatUnits as q}from"viem";function H(o){return`0x${o.slice(-40)}`}function V(o){return[1,5,10,56,137,250,8453,42220,43114,42161].includes(o)}function v(o){return[1,137,8453].includes(o)}async function p({publicClient:o,transactionReceipt:s}){const{logs:r}=s;const a=r.filter(i=>i.topics[0]===P.Transfer).map(i=>({...i,address:L(i.address)}));const n=[...a.map(i=>({abi:w,address:i.address,functionName:"symbol"})),...a.map(i=>({abi:w,address:i.address,functionName:"decimals"}))];const e=await o.multicall({contracts:n});const t=Math.floor(e.length/2);const d=a.map((i,c)=>{const u=e[c].result;const l=e[t+c].result;const b=q(BigInt(i.data),l);const{address:T,topics:x}=i;const{1:E,2:g}=x;const h=L(H(E));const I=L(H(g));return{to:I,from:h,symbol:u,amount:b,address:T,decimals:l}}).filter(i=>i.amount!=="0");return d}function f(o,s){return{tokenIn:{symbol:o.symbol,amount:o.amount,address:L(o.address)},tokenOut:{symbol:s.symbol,amount:s.amount,address:L(s.address)}}}var S=[{inputs:[{internalType:"contract IERC2612",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20PermitAllowed",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"bool",name:"allowed",type:"bool"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[{internalType:"contract IERC20MetaTransaction",name:"token",type:"address"},{internalType:"address",name:"owner",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"},{internalType:"bytes",name:"data",type:"bytes"}],name:"permitAndCall",outputs:[{internalType:"bytes",name:"",type:"bytes"}],stateMutability:"payable",type:"function"},{inputs:[],name:"target",outputs:[{internalType:"address payable",name:"",type:"address"}],stateMutability:"view",type:"function"}];async function z({publicClient:o,transactionReceipt:s}){const r=await p({publicClient:o,transactionReceipt:s});const a=y(s.from);const n=r.find(t=>a===t.from);const e=r.find(t=>a===t.to);if(n&&e){return f(n,e)}}async function J({publicClient:o,transactionReceipt:s}){const r=y(s.from);const a=await p({publicClient:o,transactionReceipt:s});const n=a.find(t=>r===t.from);const e=a.find(t=>t.address===C.weth);if(n&&e){e.symbol=m.symbol;e.address=m.address;return f(n,e)}}async function Q({publicClient:o,transactionReceipt:s}){const r=y(s.from);const a=await p({publicClient:o,transactionReceipt:s});const n=a.find(t=>t.address===C.weth);const e=a.find(t=>t.to===r);if(n&&e){n.symbol=m.symbol;n.address=m.address;return f(n,e)}}async function tt({callData:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:a}){const{args:n}=A({abi:r,data:o});const[e]=n;const t=await p({publicClient:s,transactionReceipt:a});const{maker:d,taker:i}=e;const c=t.find(l=>l.from===i);const u=t.find(l=>l.from===d);if(c&&u){return f(c,u)}}async function et({publicClient:o,transactionReceipt:s}){const r=await p({publicClient:o,transactionReceipt:s});const a=y(s.from);const n=r.find(t=>t.from===a);const e=r.find(t=>t.to===a);if(n&&e){return f(n,e)}}async function nt({publicClient:o,transactionReceipt:s}){const r=await p({publicClient:o,transactionReceipt:s});const a=r.find(e=>e.address!==C.weth);const n=r.find(e=>e.address===C.weth);if(a&&n){n.symbol=m.symbol;n.address=m.address;return f(a,n)}}async function ot({publicClient:o,transactionReceipt:s}){const r=await p({publicClient:o,transactionReceipt:s});const a=y(s.from);const n=r.find(t=>t.from===a);const e=r.find(t=>t.address===C.weth);if(n&&e){e.symbol=m.symbol;e.address=m.address;return f(n,e)}}async function st({publicClient:o,transactionReceipt:s}){const r=await p({publicClient:o,transactionReceipt:s});const a=y(s.from);const n=r.find(t=>a===t.from);const e=r.find(t=>a===t.to);if(n&&e){return f(n,e)}}async function rt({publicClient:o,transactionReceipt:s}){const r=await p({publicClient:o,transactionReceipt:s});const a=y(s.from);const n=r.find(t=>t.address===C.weth);const e=r.find(t=>a===t.to);if(n&&e){n.symbol=m.symbol;n.address=m.address;return f(n,e)}}async function at({publicClient:o,transactionReceipt:s}){const r=await p({publicClient:o,transactionReceipt:s});const a=r[0];const n=r[r.length-1];return f(a,n)}async function it({chainId:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:a}){const n=D[o];for(const e of a.logs){const{topics:t,data:d}=e;const[i]=t;if(i===P.TransformedERC20){let c;let u;let l;let b;const T=K({data:d,topics:t,abi:r});const{inputToken:x,outputToken:E,inputTokenAmount:g,outputTokenAmount:h}=T.args;const I={address:x,abi:w};const O={address:E,abi:w};if(x===m.address){c=n;u=18}else{[{result:c},{result:u}]=await s.multicall({contracts:[{...I,functionName:"symbol"},{...I,functionName:"decimals"}]})}if(E===m.address){l=n;b=18}else{[{result:l},{result:b}]=await s.multicall({contracts:[{...O,functionName:"symbol"},{...O,functionName:"decimals"}]})}const W=Y(g,u);const j=Y(h,b);return{tokenIn:{address:x,amount:W,symbol:c},tokenOut:{address:E,amount:j,symbol:l}}}}}async function ct({publicClient:o,transactionReceipt:s}){const r=await p({publicClient:o,transactionReceipt:s});const a=y(s.from);const n=r.find(t=>a===t.from);const e=r.find(t=>a===t.to);if(n&&e){return f(n,e)}}async function dt({callData:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:a}){const n=await p({publicClient:s,transactionReceipt:a});const{args:e}=A({abi:r,data:o});const[t]=e;return n.reduce((d,i)=>{const{symbol:c,amount:u,address:l}=i;if(l===C.weth){return{...d,tokenOut:{...d.tokenOut,amount:(Number(d.tokenOut.amount)+Number(u)).toString()}}}else if(l===t){return{...d,tokenIn:{...d.tokenIn,symbol:c,address:l,amount:(Number(d.tokenIn.amount)+Number(u)).toString()}}}else{return d}},{tokenIn:{address:"",amount:"",symbol:""},tokenOut:{amount:"",symbol:m.symbol,address:m.address}})}async function ut({callData:o,transaction:s,publicClient:r,exchangeProxyAbi:a,transactionReceipt:n}){const{value:e}=s;const{args:t}=A({abi:a,data:o});const d=await p({publicClient:r,transactionReceipt:n});const[i]=t;const c=1000000000000000000n;const u=e/c;const l=e%c;const b=Number(u)+Number(l)/Number(c);const T=d.reduce((g,h)=>{return h.address===i?g+Number(h.amount):g},0);const x=d.find(g=>g.address===C.weth);const E=d.find(g=>g.address===i);if(x&&E){return{tokenIn:{symbol:m.symbol,amount:b.toString(),address:m.address},tokenOut:{symbol:E.symbol,amount:T.toString(),address:E.address}}}}async function lt({callData:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:a}){const n=await p({publicClient:s,transactionReceipt:a});const{args:e}=A({abi:r,data:o});const[t,d]=e;const i={[t]:{amount:"0",symbol:"",address:""},[d]:{amount:"0",symbol:"",address:""}};n.forEach(({address:c,symbol:u,amount:l})=>{if(y(c)in i){i[y(c)].address=y(c);i[y(c)].symbol=u;i[y(c)].amount=(Number(i[y(c)].amount)+Number(l)).toString()}});return{tokenIn:i[t],tokenOut:i[d]}}async function mt({publicClient:o,transactionReceipt:s}){const r=await p({publicClient:o,transactionReceipt:s});const a=y(N[56]);const n=y(s.from);let e=r.find(d=>d.from===n);let t=r.find(d=>d.from!==n);if(e===void 0){e=r.find(d=>d.from===a);t=r.find(d=>d.from!==a)}if(!r.some(d=>d.to===n)){t=r.find(d=>d.to===a)}if(e&&t){return f(e,t)}}async function pt({callData:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:a}){const{args:n}=A({abi:r,data:o});const e=await p({publicClient:s,transactionReceipt:a});const[t]=n;const{makerToken:d,takerToken:i}=t;const c=e.find(l=>l.address===i);const u=e.find(l=>l.address===d);if(c&&u){u.symbol=m.symbol;u.address=m.address;return f(c,u)}}async function ft({callData:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:a}){const{args:n}=A({abi:r,data:o});const e=await p({publicClient:s,transactionReceipt:a});const[t]=n;const{makerToken:d,takerToken:i}=t;const c=e.find(l=>l.address===i);const u=e.find(l=>l.address===d);if(c&&u){c.symbol=m.symbol;c.address=m.address;return f(c,u)}}async function yt({callData:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:a}){const{args:n}=A({abi:r,data:o});const[e]=n;const{maker:t,taker:d}=e;const i=await p({publicClient:s,transactionReceipt:a});if(typeof t==="string"&&typeof d==="string"){const c=i.find(l=>l.from===d);const u=i.find(l=>l.from===t);if(c&&u){return f(c,u)}}}async function bt({callData:o,publicClient:s,exchangeProxyAbi:r,transactionReceipt:a}){const{args:n}=A({abi:r,data:o});const[e]=n;const{signer:t}=e;const d=await p({publicClient:s,transactionReceipt:a});if(typeof t==="string"){const i=d.find(u=>u.from===t);const c=d.find(u=>u.to===t);if(i&&c){return f(i,c)}}}async function gt({chainId:o,transaction:s,publicClient:r,exchangeProxyAbi:a,transactionReceipt:n,callData:e}){const{args:t}=A({abi:a,data:e});const[d]=t;const{callData:i}=d;const{functionName:c}=A({data:i,abi:a});const u=F[c];return u({chainId:o,callData:i,transaction:s,publicClient:r,exchangeProxyAbi:a,transactionReceipt:n})}function Et({chainId:o,transaction:s,publicClient:r,exchangeProxyAbi:a,transactionReceipt:n}){const{args:e}=A({abi:S,data:s.input});let t;const d=Z({abi:S,functionName:"permitAndCall",args:[...e]});const i=d.slice(0,10);const{IERC2612:c,IERC20PermitAllowed:u,IERC20MetaTransaction:l}=M.permitAndCall;switch(i){case c:t=e[7];break;case u:t=e[8];break;case l:t=e[6];break}if(t){const{functionName:b}=A({abi:a,data:t});const T=F[b];return T({chainId:o,callData:t,transaction:s,publicClient:r,exchangeProxyAbi:a,transactionReceipt:n})}}var F={fillLimitOrder:yt,fillOtcOrder:et,fillOtcOrderForEth:pt,fillOtcOrderWithEth:ft,fillTakerSignedOtcOrder:tt,fillTakerSignedOtcOrderForEth:nt,executeMetaTransaction:bt,executeMetaTransactionV2:gt,multiplexBatchSellTokenForToken:lt,multiplexBatchSellTokenForEth:dt,multiplexBatchSellEthForToken:ut,multiplexMultiHopSellTokenForToken:ct,multiplexMultiHopSellEthForToken:Q,multiplexMultiHopSellTokenForEth:J,permitAndCall:Et,sellToUniswap:at,sellTokenForEthToUniswapV3:ot,sellEthForTokenToUniswapV3:rt,sellTokenForTokenToUniswapV3:st,sellToLiquidityProvider:z,sellToPancakeSwap:mt,transformERC20:it};import{erc20Abi as U,getAddress as _,formatUnits as G}from"viem";var Tt="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";var At={1:"ETH",10:"ETH",56:"BNB",137:"MATIC",8453:"ETH",42161:"ETH",43114:"AVAX"};function xt(o){return[1,10,56,137,8453,42161,43114].includes(o)}async function Ct({publicClient:o,transactionReceipt:s}){const r={Transfer:"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"};const{logs:a}=s;const n=a.filter(c=>c.topics[0]===r.Transfer).map(c=>({...c,address:_(c.address)}));const e=[...n.map(c=>({abi:U,address:c.address,functionName:"symbol"})),...n.map(c=>({abi:U,address:c.address,functionName:"decimals"}))];const t=await o.multicall({contracts:e});const d=Math.floor(t.length/2);const i=n.map((c,u)=>{const l=t[u].result;const b=t[d+u].result;const T=c.data==="0x"?"0":G(BigInt(c.data),b);const{address:x,topics:E}=c;const{1:g,2:h}=E;const I=_(X(g));const O=_(X(h));return{to:O,from:I,symbol:l,amount:T,address:x,decimals:b}}).filter(c=>c.amount!=="0");return i}function X(o){return`0x${o.slice(-40)}`}async function ht({publicClient:o,transactionHash:s}){const r=await o.getChainId();if(!xt(r)){throw new Error(`chainId ${r} is unsupported\u2026`)}const a=await o.getTransactionReceipt({hash:s});const{value:n}=await o.getTransaction({hash:s});const e=n>0n;const t=await Ct({publicClient:o,transactionReceipt:a});const d=t[0];const i=t[t.length-1];if(e){const c=G(n,18);return{tokenIn:{symbol:At[r],amount:c,address:Tt},tokenOut:{symbol:i.symbol,amount:i.amount,address:i.address}}}return{tokenIn:{symbol:d.symbol,amount:d.amount,address:d.address},tokenOut:{symbol:i.symbol,amount:i.amount,address:i.address}}}async function Zt({rpcUrl:o,exchangeProxyAbi:s,transactionHash:r}){if(!o)throw new Error("Missing rpcUrl\u2026");if(!r)throw new Error("Missing transaction hash\u2026");if(!s){throw new Error(`Missing 0x Exchange Proxy ABI: ${B}\u2026`)}const a=wt({chain:Lt,transport:kt(o)});const{getChainId:n,getTransaction:e,getTransactionReceipt:t}=a;const[d,i,c]=await Promise.all([n(),e({hash:r}),t({hash:r})]);if(c.status==="reverted"){return null}if(!V(d)){throw new Error(`chainId ${d} is unsupported\u2026`)}const u=N[d];const l=v(d)?R[d]:null;const b=It(i.to);const T=b===u;const x=b===l;if(!T&&!x){return null}const{functionName:E}=T?$({abi:s,data:i.input}):$({abi:S,data:i.input});const g=F[E];return g({chainId:d,transaction:i,publicClient:a,exchangeProxyAbi:s,transactionReceipt:c,callData:i.input})}export{Zt as parseSwap,ht as parseSwapV2};
{
"name": "@0x/0x-parser",
"version": "1.1.1",
"version": "1.2.0",
"description": "🧾 Designed for 0x integrators: This library parses 0x transactions on EVM blockchains into a format that is both user-friendly and easy to understand.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -90,1 +90,6 @@ import { http, getAddress, decodeFunctionData, createPublicClient } from "viem";

}
/**
* This function is specific to 0x API transactions on Settler.
*/
export { parseSwapV2 } from "./parseSwapV2";
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc