reverse-mirage
Advanced tools
Comparing version 1.0.0 to 1.0.1
1594
dist/index.js
@@ -1,2 +0,2 @@ | ||
import b from 'tiny-invariant'; | ||
import invariant3 from 'tiny-invariant'; | ||
import { parseUnits, getAddress } from 'viem/utils'; | ||
@@ -6,6 +6,1594 @@ import { getAddress as getAddress$1 } from 'viem'; | ||
var c=(t,e)=>t.decimals?e*10n**BigInt(t.decimals):e,At=(t,e)=>t.decimals?e/10n**BigInt(t.decimals):e,y=t=>typeof t=="object",Q=(t,e)=>({type:`${t.type}Amount`,token:t,amount:t.decimals?parseUnits(e,t.decimals):BigInt(e)}),U=(t,e)=>({type:`${t.type}Amount`,token:t,amount:c(t,e.numerator)/e.denominator}),T=(t,e)=>({type:`${t.type}Amount`,token:t,amount:e}),ke=(t,e)=>(y(e)&&b(t.token===e.token),y(e)?{...t,amount:t.amount+e.amount}:{...t,amount:t.amount+c(t.token,BigInt(e))}),we=(t,e)=>(y(e)&&b(t.token===e.token),y(e)?{...t,amount:t.amount-e.amount}:{...t,amount:t.amount-c(t.token,BigInt(e))}),Fe=(t,e)=>(y(e)&&b(t.token===e.token),y(e)?{...t,amount:At(t.token,t.amount*e.amount)}:{...t,amount:t.amount*BigInt(e)}),Ne=(t,e)=>(y(e)&&b(t.token===e.token),y(e)?{...t,amount:c(t.token,t.amount)/e.amount}:{...t,amount:t.amount/BigInt(e)}),Ge=(t,e)=>(y(e)&&b(t.token===e.token),y(e)?t.amount<e.amount:t.amount<c(t.token,BigInt(e))),De=(t,e)=>(y(e)&&b(t.token===e.token),y(e)?t.amount===e.amount:t.amount===c(t.token,BigInt(e))),Me=(t,e)=>(y(e)&&b(t.token===e.token),y(e)?t.amount>e.amount:t.amount>c(t.token,BigInt(e))),je=t=>Number(t.amount)/10**(t.token.decimals??0);var o=(t,e,n,a)=>({type:"nativeCurrency",name:t,symbol:e,decimals:n,chainID:a});var m=(t,e,n,a,r,i=0n)=>({type:"weth",address:getAddress(t),name:e,symbol:n,decimals:a,chainID:r,blockCreated:i});var He={native:o("Ether","ETH",18,42161),weth:m("0x82aF49447D8a07e3bd95BD0d56f35241523fBab1","Wrapped Ether","WETH",18,42161,55n)};var We={native:o("Ether","ETH",18,421613),weth:m("0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3","Wrapped Ether","WETH",18,421613,16n)};var Qe={native:o("Ether","ETH",18,8453),weth:m("0x4200000000000000000000000000000000000006","Wrapped Ether","WETH",18,8453)};var Ue={native:o("Ether","ETH",18,84531),weth:m("0x4200000000000000000000000000000000000006","Wrapped Ether","WETH",18,84531)};var _e={native:o("Celo Native Asset","CELO",18,42220),weth:m("0x471EcE3750Da237f93B8E339c536989b8978a438","Celo Native Asset","CELO",18,42220,2919n)};var qe={native:o("Celo Native Asset","CELO",18,44787),weth:m("0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9","Celo Native Asset","CELO",18,44787)};var Le={native:o("Ether","ETH",18,31337)};var $e={native:o("Ether","ETH",18,5),weth:m("0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6","Wrapped Ether","WETH",18,5,1036651n)};var Xe={native:o("Ether","ETH",18,1),weth:m("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2","Wrapped Ether","WETH",18,1,4719568n)};var ze={native:o("Ether","ETH",18,10),weth:m("0x4200000000000000000000000000000000000006","Wrapped Ether","WETH",18,10)};var Je={native:o("Ether","ETH",18,420),weth:m("0x4200000000000000000000000000000000000006","Wrapped Ether","WETH",18,420)};var Ke={native:o("Ether","ETH",18,11155111),weth:m("0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14","Wrapped Ether","WETH",18,11155111,3518216n)};var _=(t,e,n,a,r,i=0n)=>({type:"erc20",address:getAddress(t),name:e,symbol:n,decimals:a,chainID:r,blockCreated:i}),q=(t,e,n,a,r,i,d=0n)=>({type:"erc20Permit",address:getAddress(t),name:e,symbol:n,decimals:a,version:r,chainID:i,blockCreated:d}),Ye=(t,e,n)=>({...Q(t,e),type:`${t.type}Data`,nonce:n}),Ze=(t,e,n)=>({...U(t,e),type:`${t.type}Data`,nonce:n}),L=(t,e,n)=>({...T(t,e),type:`${t.type}Data`,nonce:n}),$={Permit:[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]};var v=[{constant:!0,payable:!1,stateMutability:"view",type:"function",inputs:[],name:"name",outputs:[{name:"",type:"string"}]},{constant:!1,payable:!1,stateMutability:"nonpayable",type:"function",inputs:[{name:"guy",type:"address"},{name:"wad",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}]},{constant:!0,payable:!1,stateMutability:"view",type:"function",inputs:[],name:"totalSupply",outputs:[{name:"",type:"uint256"}]},{constant:!1,payable:!1,stateMutability:"nonpayable",type:"function",inputs:[{name:"src",type:"address"},{name:"dst",type:"address"},{name:"wad",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}]},{constant:!1,payable:!1,stateMutability:"nonpayable",type:"function",inputs:[{name:"wad",type:"uint256"}],name:"withdraw",outputs:[]},{constant:!0,payable:!1,stateMutability:"view",type:"function",inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}]},{constant:!0,payable:!1,stateMutability:"view",type:"function",inputs:[{name:"",type:"address"}],name:"balanceOf",outputs:[{name:"",type:"uint256"}]},{constant:!0,payable:!1,stateMutability:"view",type:"function",inputs:[],name:"symbol",outputs:[{name:"",type:"string"}]},{constant:!1,payable:!1,stateMutability:"nonpayable",type:"function",inputs:[{name:"dst",type:"address"},{name:"wad",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}]},{constant:!1,payable:!0,stateMutability:"payable",type:"function",inputs:[],name:"deposit",outputs:[]},{constant:!0,payable:!1,stateMutability:"view",type:"function",inputs:[{name:"",type:"address"},{name:"",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}]},{payable:!0,stateMutability:"payable",type:"fallback"},{type:"event",anonymous:!1,inputs:[{name:"src",type:"address",indexed:!0},{name:"guy",type:"address",indexed:!0},{name:"wad",type:"uint256",indexed:!1}],name:"Approval"},{type:"event",anonymous:!1,inputs:[{name:"src",type:"address",indexed:!0},{name:"dst",type:"address",indexed:!0},{name:"wad",type:"uint256",indexed:!1}],name:"Transfer"},{type:"event",anonymous:!1,inputs:[{name:"dst",type:"address",indexed:!0},{name:"wad",type:"uint256",indexed:!1}],name:"Deposit"},{type:"event",anonymous:!1,inputs:[{name:"src",type:"address",indexed:!0},{name:"wad",type:"uint256",indexed:!1}],name:"Withdrawal"}],l=[{type:"event",anonymous:!1,inputs:[{name:"owner",internalType:"address",type:"address",indexed:!0},{name:"operator",internalType:"address",type:"address",indexed:!0},{name:"approved",internalType:"bool",type:"bool",indexed:!1}],name:"ApprovalForAll"},{type:"event",anonymous:!1,inputs:[{name:"operator",internalType:"address",type:"address",indexed:!0},{name:"from",internalType:"address",type:"address",indexed:!0},{name:"to",internalType:"address",type:"address",indexed:!0},{name:"ids",internalType:"uint256[]",type:"uint256[]",indexed:!1},{name:"amounts",internalType:"uint256[]",type:"uint256[]",indexed:!1}],name:"TransferBatch"},{type:"event",anonymous:!1,inputs:[{name:"operator",internalType:"address",type:"address",indexed:!0},{name:"from",internalType:"address",type:"address",indexed:!0},{name:"to",internalType:"address",type:"address",indexed:!0},{name:"id",internalType:"uint256",type:"uint256",indexed:!1},{name:"amount",internalType:"uint256",type:"uint256",indexed:!1}],name:"TransferSingle"},{type:"event",anonymous:!1,inputs:[{name:"value",internalType:"string",type:"string",indexed:!1},{name:"id",internalType:"uint256",type:"uint256",indexed:!0}],name:"URI"},{stateMutability:"view",type:"function",inputs:[{name:"",internalType:"address",type:"address"},{name:"",internalType:"uint256",type:"uint256"}],name:"balanceOf",outputs:[{name:"",internalType:"uint256",type:"uint256"}]},{stateMutability:"view",type:"function",inputs:[{name:"owners",internalType:"address[]",type:"address[]"},{name:"ids",internalType:"uint256[]",type:"uint256[]"}],name:"balanceOfBatch",outputs:[{name:"balances",internalType:"uint256[]",type:"uint256[]"}]},{stateMutability:"view",type:"function",inputs:[{name:"",internalType:"address",type:"address"},{name:"",internalType:"address",type:"address"}],name:"isApprovedForAll",outputs:[{name:"",internalType:"bool",type:"bool"}]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"from",internalType:"address",type:"address"},{name:"to",internalType:"address",type:"address"},{name:"ids",internalType:"uint256[]",type:"uint256[]"},{name:"amounts",internalType:"uint256[]",type:"uint256[]"},{name:"data",internalType:"bytes",type:"bytes"}],name:"safeBatchTransferFrom",outputs:[]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"from",internalType:"address",type:"address"},{name:"to",internalType:"address",type:"address"},{name:"id",internalType:"uint256",type:"uint256"},{name:"amount",internalType:"uint256",type:"uint256"},{name:"data",internalType:"bytes",type:"bytes"}],name:"safeTransferFrom",outputs:[]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"operator",internalType:"address",type:"address"},{name:"approved",internalType:"bool",type:"bool"}],name:"setApprovalForAll",outputs:[]},{stateMutability:"view",type:"function",inputs:[{name:"interfaceId",internalType:"bytes4",type:"bytes4"}],name:"supportsInterface",outputs:[{name:"",internalType:"bool",type:"bool"}]},{stateMutability:"view",type:"function",inputs:[{name:"id",internalType:"uint256",type:"uint256"}],name:"uri",outputs:[{name:"",internalType:"string",type:"string"}]}],s=[{type:"event",anonymous:!1,inputs:[{name:"owner",internalType:"address",type:"address",indexed:!0},{name:"spender",internalType:"address",type:"address",indexed:!0},{name:"amount",internalType:"uint256",type:"uint256",indexed:!1}],name:"Approval"},{type:"event",anonymous:!1,inputs:[{name:"from",internalType:"address",type:"address",indexed:!0},{name:"to",internalType:"address",type:"address",indexed:!0},{name:"amount",internalType:"uint256",type:"uint256",indexed:!1}],name:"Transfer"},{stateMutability:"view",type:"function",inputs:[],name:"DOMAIN_SEPARATOR",outputs:[{name:"",internalType:"bytes32",type:"bytes32"}]},{stateMutability:"view",type:"function",inputs:[{name:"",internalType:"address",type:"address"},{name:"",internalType:"address",type:"address"}],name:"allowance",outputs:[{name:"",internalType:"uint256",type:"uint256"}]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"spender",internalType:"address",type:"address"},{name:"amount",internalType:"uint256",type:"uint256"}],name:"approve",outputs:[{name:"",internalType:"bool",type:"bool"}]},{stateMutability:"view",type:"function",inputs:[{name:"",internalType:"address",type:"address"}],name:"balanceOf",outputs:[{name:"",internalType:"uint256",type:"uint256"}]},{stateMutability:"view",type:"function",inputs:[],name:"decimals",outputs:[{name:"",internalType:"uint8",type:"uint8"}]},{stateMutability:"view",type:"function",inputs:[],name:"name",outputs:[{name:"",internalType:"string",type:"string"}]},{stateMutability:"view",type:"function",inputs:[{name:"",internalType:"address",type:"address"}],name:"nonces",outputs:[{name:"",internalType:"uint256",type:"uint256"}]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"owner",internalType:"address",type:"address"},{name:"spender",internalType:"address",type:"address"},{name:"value",internalType:"uint256",type:"uint256"},{name:"deadline",internalType:"uint256",type:"uint256"},{name:"v",internalType:"uint8",type:"uint8"},{name:"r",internalType:"bytes32",type:"bytes32"},{name:"s",internalType:"bytes32",type:"bytes32"}],name:"permit",outputs:[]},{stateMutability:"view",type:"function",inputs:[],name:"symbol",outputs:[{name:"",internalType:"string",type:"string"}]},{stateMutability:"view",type:"function",inputs:[],name:"totalSupply",outputs:[{name:"",internalType:"uint256",type:"uint256"}]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"to",internalType:"address",type:"address"},{name:"amount",internalType:"uint256",type:"uint256"}],name:"transfer",outputs:[{name:"",internalType:"bool",type:"bool"}]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"from",internalType:"address",type:"address"},{name:"to",internalType:"address",type:"address"},{name:"amount",internalType:"uint256",type:"uint256"}],name:"transferFrom",outputs:[{name:"",internalType:"bool",type:"bool"}]}],p=[{type:"event",anonymous:!1,inputs:[{name:"owner",internalType:"address",type:"address",indexed:!0},{name:"spender",internalType:"address",type:"address",indexed:!0},{name:"id",internalType:"uint256",type:"uint256",indexed:!0}],name:"Approval"},{type:"event",anonymous:!1,inputs:[{name:"owner",internalType:"address",type:"address",indexed:!0},{name:"operator",internalType:"address",type:"address",indexed:!0},{name:"approved",internalType:"bool",type:"bool",indexed:!1}],name:"ApprovalForAll"},{type:"event",anonymous:!1,inputs:[{name:"from",internalType:"address",type:"address",indexed:!0},{name:"to",internalType:"address",type:"address",indexed:!0},{name:"id",internalType:"uint256",type:"uint256",indexed:!0}],name:"Transfer"},{stateMutability:"nonpayable",type:"function",inputs:[{name:"spender",internalType:"address",type:"address"},{name:"id",internalType:"uint256",type:"uint256"}],name:"approve",outputs:[]},{stateMutability:"view",type:"function",inputs:[{name:"owner",internalType:"address",type:"address"}],name:"balanceOf",outputs:[{name:"",internalType:"uint256",type:"uint256"}]},{stateMutability:"view",type:"function",inputs:[{name:"",internalType:"uint256",type:"uint256"}],name:"getApproved",outputs:[{name:"",internalType:"address",type:"address"}]},{stateMutability:"view",type:"function",inputs:[{name:"",internalType:"address",type:"address"},{name:"",internalType:"address",type:"address"}],name:"isApprovedForAll",outputs:[{name:"",internalType:"bool",type:"bool"}]},{stateMutability:"view",type:"function",inputs:[],name:"name",outputs:[{name:"",internalType:"string",type:"string"}]},{stateMutability:"view",type:"function",inputs:[{name:"id",internalType:"uint256",type:"uint256"}],name:"ownerOf",outputs:[{name:"owner",internalType:"address",type:"address"}]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"from",internalType:"address",type:"address"},{name:"to",internalType:"address",type:"address"},{name:"id",internalType:"uint256",type:"uint256"}],name:"safeTransferFrom",outputs:[]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"from",internalType:"address",type:"address"},{name:"to",internalType:"address",type:"address"},{name:"id",internalType:"uint256",type:"uint256"},{name:"data",internalType:"bytes",type:"bytes"}],name:"safeTransferFrom",outputs:[]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"operator",internalType:"address",type:"address"},{name:"approved",internalType:"bool",type:"bool"}],name:"setApprovalForAll",outputs:[]},{stateMutability:"view",type:"function",inputs:[{name:"interfaceId",internalType:"bytes4",type:"bytes4"}],name:"supportsInterface",outputs:[{name:"",internalType:"bool",type:"bool"}]},{stateMutability:"view",type:"function",inputs:[],name:"symbol",outputs:[{name:"",internalType:"string",type:"string"}]},{stateMutability:"view",type:"function",inputs:[{name:"id",internalType:"uint256",type:"uint256"}],name:"tokenURI",outputs:[{name:"",internalType:"string",type:"string"}]},{stateMutability:"nonpayable",type:"function",inputs:[{name:"from",internalType:"address",type:"address"},{name:"to",internalType:"address",type:"address"},{name:"id",internalType:"uint256",type:"uint256"}],name:"transferFrom",outputs:[]}];var A=(t,{erc20:e,...n})=>readContract(t,{abi:s,address:e.address,functionName:"decimals",...n});var h=(t,{erc20:e,...n})=>readContract(t,{abi:s,address:e.address,functionName:"name",...n});var x=(t,{erc20:e,...n})=>readContract(t,{abi:s,address:e.address,functionName:"symbol",...n});var g=(t,{erc20:e,...n})=>Promise.all([h(t,{erc20:e,...n}),x(t,{erc20:e,...n}),A(t,{erc20:e,...n})]).then(([a,r,i])=>_(e.address,a,r,i,e.chainID,e.blockCreated));var X=(t,{erc20:e,owner:n,spender:a,...r})=>readContract(t,{abi:s,address:e.address,functionName:"allowance",args:[n,a],...r}).then(i=>T(e,i));var z=(t,{erc20:e,address:n,...a})=>readContract(t,{abi:s,address:e.address,functionName:"balanceOf",args:[n],...a}).then(r=>T(e,r));var B=(t,{erc20:e,...n})=>readContract(t,{abi:s,address:e.address,functionName:"DOMAIN_SEPARATOR",...n});var I=(t,{erc20:e,...n})=>Promise.all([h(t,{erc20:e,...n}),x(t,{erc20:e,...n}),A(t,{erc20:e,...n})]).then(([a,r,i])=>q(e.address,a,r,i,e.version??"1",e.chainID,e.blockCreated));var J=(t,{erc20:e,address:n,...a})=>Promise.all([readContract(t,{abi:s,address:e.address,functionName:"balanceOf",args:[n],...a}),readContract(t,{abi:s,address:e.address,functionName:"nonces",args:[n],...a})]).then(([r,i])=>L(e,r,i));var K=(t,{erc20:e,address:n,...a})=>readContract(t,{abi:s,address:e.address,functionName:"nonces",args:[n],...a});var V=(t,{erc20:e,...n})=>readContract(t,{abi:s,address:e.address,functionName:"totalSupply",...n}).then(a=>T(e,a));var Y=(t,{erc20:e,...n})=>Promise.all([I(t,{erc20:e,...n}),B(t,{erc20:e,...n})]).then(([a])=>a).catch(()=>g(t,{erc20:e,...n}));var Z=(t,{permitData:e,spender:n,deadline:a,account:r=t.account,...i})=>{let d={name:e.token.name,version:e.token.version,chainId:e.token.chainID,verifyingContract:getAddress(e.token.address)},f=t.account?.address??(typeof r=="object"?r.address:r);return signTypedData(t,{domain:d,types:$,primaryType:"Permit",message:{owner:f,spender:n,value:e.amount,deadline:a,nonce:e.nonce},account:r,...i})};var ee=(t,{args:{amount:e,spender:n},...a})=>simulateContract(t,{address:e.token.address,abi:s,functionName:"approve",args:[n,e.amount],...a});var te=(t,{args:{owner:e,spender:n,signature:a,permitData:r,deadline:i},...d})=>{let f=`0x${a.substring(2,66)}`,W=`0x${a.substring(2+64,2+64+64)}`,Rt=+`0x${a.substring(2+64+64)}`;return simulateContract(t,{address:r.token.address,abi:s,functionName:"permit",args:[e,n,r.amount,i,Rt,f,W],...d})};var ne=(t,{args:{amount:e,to:n},...a})=>simulateContract(t,{address:e.token.address,abi:s,functionName:"transfer",args:[n,e.amount],...a});var ae=(t,{args:{amount:e,from:n,to:a},...r})=>simulateContract(t,{address:e.token.address,abi:s,functionName:"transferFrom",args:[n,a,e.amount],...r});var re=(t,e,n,a,r=0n)=>({type:"erc721",address:getAddress(t),name:e,symbol:n,chainID:a,blockCreated:r}),ie=(t,e,n)=>({type:`${t.type}Data`,token:t,balance:e,ids:n});var S=(t,{erc721:e,...n})=>readContract(t,{abi:p,address:e.address,functionName:"name",...n});var O=(t,{erc721:e,...n})=>readContract(t,{abi:p,address:e.address,functionName:"symbol",...n});var se=(t,{erc721:e,...n})=>Promise.all([S(t,{erc721:e,...n}),O(t,{erc721:e,...n})]).then(([a,r])=>re(e.address,a,r,e.chainID,e.blockCreated));var oe=(t,{erc721:e,id:n,...a})=>readContract(t,{abi:p,address:e.address,functionName:"getApproved",args:[n],...a});var k=(t,{erc721:e,address:n,...a})=>readContract(t,{abi:p,address:e.address,functionName:"balanceOf",args:[n],...a});var pe=(t,{erc721:e,address:n,...a})=>k(t,{erc721:e,address:n,...a}).then(r=>{if(r>Number.MAX_SAFE_INTEGER)throw Error("balance exceeds maximum representable number");return ie(e,Number(r))});var me=(t,{erc721:e,owner:n,spender:a,...r})=>readContract(t,{abi:p,address:e.address,functionName:"isApprovedForAll",args:[n,a],...r});var de=(t,{erc721:e,id:n,...a})=>readContract(t,{abi:p,address:e.address,functionName:"ownerOf",args:[n],...a});var ue=(t,{erc721:e,interfaceID:n,...a})=>readContract(t,{abi:p,address:e.address,functionName:"supportsInterface",args:[n],...a});var ye=(t,{erc721:e,id:n,...a})=>readContract(t,{abi:p,address:e.address,functionName:"tokenURI",args:[n],...a});var le=(t,{args:{erc721:e,from:n,to:a,data:r,id:i},...d})=>r===void 0?simulateContract(t,{address:e.address,abi:p,functionName:"transferFrom",args:[n??t.account?.address??(typeof d.account=="object"?d.account.address:d.account),a,i],...d}):r==="safe"?simulateContract(t,{address:e.address,abi:p,functionName:"safeTransferFrom",args:[n??t.account?.address??(typeof d.account=="object"?d.account.address:d.account),a,i],...d}):simulateContract(t,{address:e.address,abi:p,functionName:"safeTransferFrom",args:[n??t.account?.address??(typeof d.account=="object"?d.account.address:d.account),a,i,r],...d});var Ce=(t,{args:{erc721:e,spender:n,id:a},...r})=>simulateContract(t,{address:e.address,abi:p,functionName:"approve",args:[n,a],...r});var Te=(t,{args:{erc721:e,spender:n,approved:a},...r})=>simulateContract(t,{address:e.address,abi:p,functionName:"setApprovalForAll",args:[n,a],...r});var ce=(t,e,n,a,r=0n)=>({type:"erc1155",address:getAddress$1(t),id:e,uri:n,chainID:a,blockCreated:r}),fe=(t,e)=>({type:`${t.type}Data`,token:t,amount:e});var Re=(t,{erc1155:e,...n})=>readContract(t,{abi:l,address:e.address,functionName:"uri",args:[e.id],...n}).then(a=>ce(e.address,e.id,a,e.chainID,e.blockCreated));var Ee=(t,{erc1155:e,address:n,...a})=>readContract(t,{abi:l,address:e.address,functionName:"balanceOf",args:[n,e.id],...a}).then(r=>fe(e,r));var Ae=(t,{erc1155:e,owner:n,spender:a,...r})=>readContract(t,{abi:l,address:e.address,functionName:"isApprovedForAll",args:[n,a],...r});var he=(t,{erc1155:e,...n})=>readContract(t,{abi:l,address:e.address,functionName:"uri",args:[e.id],...n});var xe=(t,{args:{erc1155Data:e,to:n,from:a,data:r},...i})=>simulateContract(t,{address:e.token.address,abi:l,functionName:"safeTransferFrom",args:[a??t.account?.address??(typeof i.account=="object"?i.account.address:i.account),n,e.token.id,e.amount,r??"0x"],...i});var be=(t,{args:{erc1155Data:e,to:n,from:a,data:r},...i})=>{let d=e.reduce((f,W)=>{if(f===void 0)return getAddress$1(W.token.address);if(f!==getAddress$1(W.token.address))throw Error("Tokens refering to different addresses");return f},void 0);if(d===void 0)throw Error("No tokens passed to transfer");return simulateContract(t,{address:d,abi:l,functionName:"safeBatchTransferFrom",args:[a??t.account?.address??(typeof i.account=="object"?i.account.address:i.account),n,e.map(f=>f.token.id),e.map(f=>f.amount),r??"0x"],...i})};var Pe=(t,{args:{erc1155:e,spender:n,approved:a},...r})=>simulateContract(t,{address:e.address,abi:l,functionName:"setApprovalForAll",args:[n,a],...r});var E=t=>typeof t=="object",at=(t,e=1)=>{let n=BigInt(e);return b(n!==0n,"Fraction: denominator equal to 0"),{type:"fraction",numerator:BigInt(t),denominator:n}},rt=t=>t.numerator/t.denominator,it=t=>t.numerator%t.denominator,ve=t=>(b(t.numerator!==0n,"Fraction: denominator equal to 0"),{type:"fraction",numerator:t.denominator,denominator:t.numerator}),G=(t,e)=>E(e)?{type:"fraction",numerator:t.numerator*e.denominator+e.numerator*t.denominator,denominator:t.denominator*e.denominator}:{type:"fraction",numerator:t.numerator+t.denominator*BigInt(e),denominator:t.denominator},D=(t,e)=>E(e)?{type:"fraction",numerator:t.numerator*e.denominator-e.numerator*t.denominator,denominator:t.denominator*e.denominator}:{type:"fraction",numerator:t.numerator-t.denominator*BigInt(e),denominator:t.denominator},w=(t,e)=>E(e)?{type:"fraction",numerator:t.numerator*e.numerator,denominator:t.denominator*e.denominator}:{type:"fraction",numerator:t.numerator*BigInt(e),denominator:t.denominator},F=(t,e)=>E(e)?{type:"fraction",numerator:t.numerator*e.denominator,denominator:t.denominator*e.numerator}:{type:"fraction",numerator:t.numerator,denominator:t.denominator*BigInt(e)},M=(t,e)=>E(e)?t.numerator*e.denominator<t.denominator*e.numerator:t.numerator<t.denominator*BigInt(e),j=(t,e)=>E(e)?t.numerator*e.denominator>t.denominator*e.numerator:t.numerator>t.denominator*BigInt(e),H=(t,e)=>E(e)?t.numerator*e.denominator===t.denominator*e.numerator:t.numerator===t.denominator*BigInt(e),ge=t=>Number(t.numerator)/Number(t.denominator);var Be=(t,{address:e,nativeCurrency:n,...a})=>getBalance(t,{address:e,...a}).then(r=>T(n,r));var C=t=>typeof t=="object",N=(t,e,n)=>({type:"price",quote:t,base:e,numerator:t.decimals?n.numerator*10n**BigInt(t.decimals):n.numerator,denominator:e.decimals?n.denominator*10n**BigInt(e.decimals):n.denominator}),st=(t,e)=>({type:"price",quote:t.token,base:e.token,numerator:e.amount,denominator:t.amount}),ot=(t,e,n,a=1)=>({type:"price",quote:t,base:e,numerator:t.decimals?BigInt(n)*10n**BigInt(t.decimals):BigInt(n),denominator:e.decimals?BigInt(a)*10n**BigInt(e.decimals):BigInt(a)}),pt=t=>({...ve(u(t)),type:"price",quote:t.base,base:t.quote}),mt=(t,e)=>(C(e)&&b(t.base===e.base&&t.quote===e.quote),C(e)?{...G(u(t),u(e)),type:"price",quote:t.quote,base:t.base}:N(t.quote,t.base,G(R(t),e))),dt=(t,e)=>(C(e)&&b(t.base===e.base&&t.quote===e.quote),C(e)?{...D(u(t),u(e)),type:"price",quote:t.quote,base:t.base}:N(t.quote,t.base,D(R(t),e))),ut=(t,e)=>(C(e)&&b(t.base===e.base&&t.quote===e.quote),C(e)?{type:"price",quote:t.quote,base:t.base,numerator:c(t.base,w(u(t),u(e)).numerator),denominator:c(t.quote,w(u(t),u(e)).denominator)}:N(t.quote,t.base,w(R(t),e))),yt=(t,e)=>(C(e)&&b(t.base===e.base&&t.quote===e.quote),C(e)?{type:"price",quote:t.quote,base:t.base,numerator:c(t.quote,F(u(t),u(e)).numerator),denominator:c(t.base,F(u(t),u(e)).denominator)}:N(t.quote,t.base,F(R(t),e))),lt=(t,e)=>(C(e)&&b(t.base===e.base&&t.quote===e.quote),C(e)?M(u(t),u(e)):M(R(t),e)),Ct=(t,e)=>(C(e)&&b(t.base===e.base&&t.quote===e.quote),C(e)?H(u(t),u(e)):H(R(t),e)),Tt=(t,e)=>(C(e)&&b(t.base===e.base&&t.quote===e.quote),C(e)?j(u(t),u(e)):j(R(t),e)),ct=(t,e)=>(b(t.base===e.token),T(t.quote,t.numerator*e.amount/t.denominator)),u=t=>({type:"fraction",numerator:t.numerator,denominator:t.denominator}),R=t=>({type:"fraction",numerator:t.base.decimals?t.numerator*10n**BigInt(t.base.decimals):t.numerator,denominator:t.quote.decimals?t.denominator*10n**BigInt(t.quote.decimals):t.denominator}),ft=t=>ge(R(t));var Ie=(t,{args:{amount:e},...n})=>simulateContract(t,{address:e.token.address,abi:v,functionName:"deposit",value:e.amount,...n});var Se=(t,{args:{amount:e},...n})=>simulateContract(t,{address:e.token.address,abi:v,functionName:"withdraw",args:[e.amount],...n});var rn=t=>({getNativeBalance:e=>Be(t,e),getERC20:e=>g(t,e),getERC20Allowance:e=>X(t,e),getERC20BalanceOf:e=>z(t,e),getERC20TotalSupply:e=>V(t,e),getERC20Name:e=>h(t,e),getERC20Symbol:e=>x(t,e),getERC20Decimals:e=>A(t,e),getERC20DomainSeparator:e=>B(t,e),getERC20Permit:e=>I(t,e),getERC20PermitNonce:e=>K(t,e),getERC20PermitData:e=>J(t,e),getIsERC20Permit:e=>Y(t,e),getERC721:e=>se(t,e),getERC721Approved:e=>oe(t,e),getERC721BalanceOf:e=>k(t,e),getERC721OwnerOf:e=>de(t,e),getERC721Data:e=>pe(t,e),getERC721Name:e=>S(t,e),getERC721Symbol:e=>O(t,e),getERC721TokenURI:e=>ye(t,e),getERC721IsApprovedForAll:e=>me(t,e),getERC721SupportsInterface:e=>ue(t,e),getERC1155:e=>Re(t,e),getERC1155BalanceOf:e=>Ee(t,e),getERC1155IsApprovedForAll:e=>Ae(t,e),getERC1155URI:e=>he(t,e),simulateWETHDeposit:e=>Ie(t,e),simulateWETHWithdraw:e=>Se(t,e),simulateERC20Approve:e=>ee(t,e),simulateERC20Permit:e=>te(t,e),simulateERC20Transfer:e=>ne(t,e),simulateERC20TransferFrom:e=>ae(t,e),simulateERC721Approve:e=>Ce(t,e),simulateERC721SetApprovalForAll:e=>Te(t,e),simulateERC721Transfer:e=>le(t,e),simulateERC1155SetApprovalForAll:e=>Pe(t,e),simulateERC1155Transfer:e=>xe(t,e),simulateERC1155TransferBatch:e=>be(t,e)});var sn=t=>({signERC20Permit:e=>Z(t,e)}); | ||
// src/amount/utils.ts | ||
var scaleUp = (token, amount) => token.decimals ? amount * 10n ** BigInt(token.decimals) : amount; | ||
var scaleDown = (token, amount) => token.decimals ? amount / 10n ** BigInt(token.decimals) : amount; | ||
var isAmount = (x) => typeof x === "object"; | ||
var createAmountFromString = (token, amount) => ({ | ||
type: `${token.type}Amount`, | ||
token, | ||
amount: token.decimals ? parseUnits(amount, token.decimals) : BigInt(amount) | ||
}); | ||
var createAmountFromFraction = (token, amount) => ({ | ||
type: `${token.type}Amount`, | ||
token, | ||
amount: scaleUp(token, amount.numerator) / amount.denominator | ||
}); | ||
var createAmountFromRaw = (token, amount) => ({ | ||
type: `${token.type}Amount`, | ||
token, | ||
amount | ||
}); | ||
var amountAdd = (a, b) => { | ||
if (isAmount(b)) { | ||
invariant3(a.token === b.token); | ||
} | ||
return isAmount(b) ? { ...a, amount: a.amount + b.amount } : { ...a, amount: a.amount + scaleUp(a.token, BigInt(b)) }; | ||
}; | ||
var amountSubtract = (a, b) => { | ||
if (isAmount(b)) { | ||
invariant3(a.token === b.token); | ||
} | ||
return isAmount(b) ? { ...a, amount: a.amount - b.amount } : { ...a, amount: a.amount - scaleUp(a.token, BigInt(b)) }; | ||
}; | ||
var amountMultiply = (a, b) => { | ||
if (isAmount(b)) { | ||
invariant3(a.token === b.token); | ||
} | ||
return isAmount(b) ? { ...a, amount: scaleDown(a.token, a.amount * b.amount) } : { ...a, amount: a.amount * BigInt(b) }; | ||
}; | ||
var amountDivide = (a, b) => { | ||
if (isAmount(b)) { | ||
invariant3(a.token === b.token); | ||
} | ||
return isAmount(b) ? { ...a, amount: scaleUp(a.token, a.amount) / b.amount } : { ...a, amount: a.amount / BigInt(b) }; | ||
}; | ||
var amountLessThan = (a, b) => { | ||
if (isAmount(b)) { | ||
invariant3(a.token === b.token); | ||
} | ||
return isAmount(b) ? a.amount < b.amount : a.amount < scaleUp(a.token, BigInt(b)); | ||
}; | ||
var amountEqualTo = (a, b) => { | ||
if (isAmount(b)) { | ||
invariant3(a.token === b.token); | ||
} | ||
return isAmount(b) ? a.amount === b.amount : a.amount === scaleUp(a.token, BigInt(b)); | ||
}; | ||
var amountGreaterThan = (a, b) => { | ||
if (isAmount(b)) { | ||
invariant3(a.token === b.token); | ||
} | ||
return isAmount(b) ? a.amount > b.amount : a.amount > scaleUp(a.token, BigInt(b)); | ||
}; | ||
var amountToNumber = (amount) => Number(amount.amount) / 10 ** (amount.token.decimals ?? 0); | ||
export { $ as PermitType, R as adjustedPrice, ke as amountAdd, Ne as amountDivide, De as amountEqualTo, Me as amountGreaterThan, Ge as amountLessThan, Fe as amountMultiply, we as amountSubtract, je as amountToNumber, We as arbitrumGoerliTokens, He as arbitrumTokens, Ue as baseGoerliTokens, Qe as baseTokens, qe as celoAlfajoresTokens, _e as celoTokens, U as createAmountFromFraction, T as createAmountFromRaw, Q as createAmountFromString, ce as createERC1155, fe as createERC1155Data, _ as createERC20, q as createERC20Permit, Ze as createERC20PermitDataFromFraction, L as createERC20PermitDataFromRaw, Ye as createERC20PermitDataFromString, re as createERC721, ie as createERC721Data, at as createFraction, o as createNativeCurrency, ot as createPrice, st as createPriceFromAmounts, N as createPriceFromFraction, m as createWETH, l as erc1155ABI, s as erc20ABI, p as erc721ABI, Le as foundryTokens, G as fractionAdd, F as fractionDivide, H as fractionEqualTo, j as fractionGreaterThan, ve as fractionInvert, M as fractionLessThan, w as fractionMultiply, rt as fractionQuotient, it as fractionRemainder, D as fractionSubtract, ge as fractionToNumber, Re as getERC1155, Ee as getERC1155BalanceOf, Ae as getERC1155IsApprovedForAll, he as getERC1155URI, g as getERC20, X as getERC20Allowance, z as getERC20BalanceOf, A as getERC20Decimals, B as getERC20DomainSeparator, h as getERC20Name, I as getERC20Permit, J as getERC20PermitData, K as getERC20PermitNonce, x as getERC20Symbol, V as getERC20TotalSupply, se as getERC721, oe as getERC721Approved, k as getERC721BalanceOf, pe as getERC721Data, me as getERC721IsApprovedForAll, S as getERC721Name, de as getERC721OwnerOf, ue as getERC721SupportsInterface, O as getERC721Symbol, ye as getERC721TokenURI, Y as getIsERC20Permit, Be as getNativeBalance, $e as goerliTokens, y as isAmount, E as isFraction, C as isPrice, Xe as mainnetTokens, Je as optimismGoerliTokens, ze as optimismTokens, mt as priceAdd, yt as priceDivide, Ct as priceEqualTo, Tt as priceGreaterThan, pt as priceInvert, lt as priceLessThan, ut as priceMultiply, ct as priceQuote, dt as priceSubtract, ft as priceToNumber, rn as publicActionReverseMirage, u as rawPrice, Ke as sepoliaTokens, Z as signERC20Permit, Pe as simulateERC1155SetApprovalForAll, xe as simulateERC1155Transfer, be as simulateERC1155TransferBatch, ee as simulateERC20Approve, te as simulateERC20Permit, ne as simulateERC20Transfer, ae as simulateERC20TransferFrom, Ce as simulateERC721Approve, Te as simulateERC721SetApprovalForAll, le as simulateERC721Transfer, Ie as simulateWETHDeposit, Se as simulateWETHWithdraw, sn as walletActionReverseMirage, v as weth9ABI }; | ||
// src/native/utils.ts | ||
var createNativeCurrency = (name, symbol, decimals, chainID) => ({ | ||
type: "nativeCurrency", | ||
name, | ||
symbol, | ||
decimals, | ||
chainID | ||
}); | ||
var createWETH = (address, name, symbol, decimals, chainID, blockCreated = 0n) => ({ | ||
type: "weth", | ||
address: getAddress(address), | ||
name, | ||
symbol, | ||
decimals, | ||
chainID, | ||
blockCreated | ||
}); | ||
// src/chains/arbitrum.ts | ||
var arbitrumTokens = { | ||
native: createNativeCurrency("Ether", "ETH", 18, 42161), | ||
weth: createWETH( | ||
"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1", | ||
"Wrapped Ether", | ||
"WETH", | ||
18, | ||
42161, | ||
55n | ||
) | ||
}; | ||
// src/chains/arbitrumGoerli.ts | ||
var arbitrumGoerliTokens = { | ||
native: createNativeCurrency("Ether", "ETH", 18, 421613), | ||
weth: createWETH( | ||
"0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3", | ||
"Wrapped Ether", | ||
"WETH", | ||
18, | ||
421613, | ||
16n | ||
) | ||
}; | ||
// src/chains/base.ts | ||
var baseTokens = { | ||
native: createNativeCurrency("Ether", "ETH", 18, 8453), | ||
weth: createWETH( | ||
"0x4200000000000000000000000000000000000006", | ||
"Wrapped Ether", | ||
"WETH", | ||
18, | ||
8453 | ||
) | ||
}; | ||
// src/chains/baseGoerli.ts | ||
var baseGoerliTokens = { | ||
native: createNativeCurrency("Ether", "ETH", 18, 84531), | ||
weth: createWETH( | ||
"0x4200000000000000000000000000000000000006", | ||
"Wrapped Ether", | ||
"WETH", | ||
18, | ||
84531 | ||
) | ||
}; | ||
// src/chains/celo.ts | ||
var celoTokens = { | ||
native: createNativeCurrency("Celo Native Asset", "CELO", 18, 42220), | ||
weth: createWETH( | ||
"0x471EcE3750Da237f93B8E339c536989b8978a438", | ||
"Celo Native Asset", | ||
"CELO", | ||
18, | ||
42220, | ||
2919n | ||
) | ||
}; | ||
// src/chains/celoAlfajores.ts | ||
var celoAlfajoresTokens = { | ||
native: createNativeCurrency("Celo Native Asset", "CELO", 18, 44787), | ||
weth: createWETH( | ||
"0xF194afDf50B03e69Bd7D057c1Aa9e10c9954E4C9", | ||
"Celo Native Asset", | ||
"CELO", | ||
18, | ||
44787 | ||
) | ||
}; | ||
// src/chains/foundry.ts | ||
var foundryTokens = { | ||
native: createNativeCurrency("Ether", "ETH", 18, 31337) | ||
}; | ||
// src/chains/goerli.ts | ||
var goerliTokens = { | ||
native: createNativeCurrency("Ether", "ETH", 18, 5), | ||
weth: createWETH( | ||
"0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6", | ||
"Wrapped Ether", | ||
"WETH", | ||
18, | ||
5, | ||
1036651n | ||
) | ||
}; | ||
// src/chains/mainnet.ts | ||
var mainnetTokens = { | ||
native: createNativeCurrency("Ether", "ETH", 18, 1), | ||
weth: createWETH( | ||
"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", | ||
"Wrapped Ether", | ||
"WETH", | ||
18, | ||
1, | ||
4719568n | ||
) | ||
}; | ||
// src/chains/optimism.ts | ||
var optimismTokens = { | ||
native: createNativeCurrency("Ether", "ETH", 18, 10), | ||
weth: createWETH( | ||
"0x4200000000000000000000000000000000000006", | ||
"Wrapped Ether", | ||
"WETH", | ||
18, | ||
10 | ||
) | ||
}; | ||
// src/chains/optimismGoerli.ts | ||
var optimismGoerliTokens = { | ||
native: createNativeCurrency("Ether", "ETH", 18, 420), | ||
weth: createWETH( | ||
"0x4200000000000000000000000000000000000006", | ||
"Wrapped Ether", | ||
"WETH", | ||
18, | ||
420 | ||
) | ||
}; | ||
// src/chains/sepolia.ts | ||
var sepoliaTokens = { | ||
native: createNativeCurrency("Ether", "ETH", 18, 11155111), | ||
weth: createWETH( | ||
"0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14", | ||
"Wrapped Ether", | ||
"WETH", | ||
18, | ||
11155111, | ||
3518216n | ||
) | ||
}; | ||
var createERC20 = (address, name, symbol, decimals, chainID, blockCreated = 0n) => ({ | ||
type: "erc20", | ||
address: getAddress(address), | ||
name, | ||
symbol, | ||
decimals, | ||
chainID, | ||
blockCreated | ||
}); | ||
var createERC20Permit = (address, name, symbol, decimals, version, chainID, blockCreated = 0n) => ({ | ||
type: "erc20Permit", | ||
address: getAddress(address), | ||
name, | ||
symbol, | ||
decimals, | ||
version, | ||
chainID, | ||
blockCreated | ||
}); | ||
var createERC20PermitDataFromString = (erc20Permit, amount, nonce) => ({ | ||
...createAmountFromString(erc20Permit, amount), | ||
type: `${erc20Permit.type}Data`, | ||
nonce | ||
}); | ||
var createERC20PermitDataFromFraction = (erc20Permit, amount, nonce) => ({ | ||
...createAmountFromFraction(erc20Permit, amount), | ||
type: `${erc20Permit.type}Data`, | ||
nonce | ||
}); | ||
var createERC20PermitDataFromRaw = (erc20Permit, amount, nonce) => ({ | ||
...createAmountFromRaw(erc20Permit, amount), | ||
type: `${erc20Permit.type}Data`, | ||
nonce | ||
}); | ||
var PermitType = { | ||
Permit: [ | ||
{ | ||
name: "owner", | ||
type: "address" | ||
}, | ||
{ name: "spender", type: "address" }, | ||
{ name: "value", type: "uint256" }, | ||
{ name: "nonce", type: "uint256" }, | ||
{ name: "deadline", type: "uint256" } | ||
] | ||
}; | ||
// src/generated.ts | ||
var weth9ABI = [ | ||
{ | ||
constant: true, | ||
payable: false, | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "name", | ||
outputs: [{ name: "", type: "string" }] | ||
}, | ||
{ | ||
constant: false, | ||
payable: false, | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "guy", type: "address" }, | ||
{ name: "wad", type: "uint256" } | ||
], | ||
name: "approve", | ||
outputs: [{ name: "", type: "bool" }] | ||
}, | ||
{ | ||
constant: true, | ||
payable: false, | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "totalSupply", | ||
outputs: [{ name: "", type: "uint256" }] | ||
}, | ||
{ | ||
constant: false, | ||
payable: false, | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "src", type: "address" }, | ||
{ name: "dst", type: "address" }, | ||
{ name: "wad", type: "uint256" } | ||
], | ||
name: "transferFrom", | ||
outputs: [{ name: "", type: "bool" }] | ||
}, | ||
{ | ||
constant: false, | ||
payable: false, | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [{ name: "wad", type: "uint256" }], | ||
name: "withdraw", | ||
outputs: [] | ||
}, | ||
{ | ||
constant: true, | ||
payable: false, | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "decimals", | ||
outputs: [{ name: "", type: "uint8" }] | ||
}, | ||
{ | ||
constant: true, | ||
payable: false, | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "", type: "address" }], | ||
name: "balanceOf", | ||
outputs: [{ name: "", type: "uint256" }] | ||
}, | ||
{ | ||
constant: true, | ||
payable: false, | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "symbol", | ||
outputs: [{ name: "", type: "string" }] | ||
}, | ||
{ | ||
constant: false, | ||
payable: false, | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "dst", type: "address" }, | ||
{ name: "wad", type: "uint256" } | ||
], | ||
name: "transfer", | ||
outputs: [{ name: "", type: "bool" }] | ||
}, | ||
{ | ||
constant: false, | ||
payable: true, | ||
stateMutability: "payable", | ||
type: "function", | ||
inputs: [], | ||
name: "deposit", | ||
outputs: [] | ||
}, | ||
{ | ||
constant: true, | ||
payable: false, | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [ | ||
{ name: "", type: "address" }, | ||
{ name: "", type: "address" } | ||
], | ||
name: "allowance", | ||
outputs: [{ name: "", type: "uint256" }] | ||
}, | ||
{ payable: true, stateMutability: "payable", type: "fallback" }, | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ name: "src", type: "address", indexed: true }, | ||
{ name: "guy", type: "address", indexed: true }, | ||
{ name: "wad", type: "uint256", indexed: false } | ||
], | ||
name: "Approval" | ||
}, | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ name: "src", type: "address", indexed: true }, | ||
{ name: "dst", type: "address", indexed: true }, | ||
{ name: "wad", type: "uint256", indexed: false } | ||
], | ||
name: "Transfer" | ||
}, | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ name: "dst", type: "address", indexed: true }, | ||
{ name: "wad", type: "uint256", indexed: false } | ||
], | ||
name: "Deposit" | ||
}, | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ name: "src", type: "address", indexed: true }, | ||
{ name: "wad", type: "uint256", indexed: false } | ||
], | ||
name: "Withdrawal" | ||
} | ||
]; | ||
var solmateErc1155ABI = [ | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
name: "owner", | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ | ||
name: "operator", | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ name: "approved", internalType: "bool", type: "bool", indexed: false } | ||
], | ||
name: "ApprovalForAll" | ||
}, | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
name: "operator", | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ name: "from", internalType: "address", type: "address", indexed: true }, | ||
{ name: "to", internalType: "address", type: "address", indexed: true }, | ||
{ | ||
name: "ids", | ||
internalType: "uint256[]", | ||
type: "uint256[]", | ||
indexed: false | ||
}, | ||
{ | ||
name: "amounts", | ||
internalType: "uint256[]", | ||
type: "uint256[]", | ||
indexed: false | ||
} | ||
], | ||
name: "TransferBatch" | ||
}, | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
name: "operator", | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ name: "from", internalType: "address", type: "address", indexed: true }, | ||
{ name: "to", internalType: "address", type: "address", indexed: true }, | ||
{ name: "id", internalType: "uint256", type: "uint256", indexed: false }, | ||
{ | ||
name: "amount", | ||
internalType: "uint256", | ||
type: "uint256", | ||
indexed: false | ||
} | ||
], | ||
name: "TransferSingle" | ||
}, | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ name: "value", internalType: "string", type: "string", indexed: false }, | ||
{ name: "id", internalType: "uint256", type: "uint256", indexed: true } | ||
], | ||
name: "URI" | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [ | ||
{ name: "", internalType: "address", type: "address" }, | ||
{ name: "", internalType: "uint256", type: "uint256" } | ||
], | ||
name: "balanceOf", | ||
outputs: [{ name: "", internalType: "uint256", type: "uint256" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [ | ||
{ name: "owners", internalType: "address[]", type: "address[]" }, | ||
{ name: "ids", internalType: "uint256[]", type: "uint256[]" } | ||
], | ||
name: "balanceOfBatch", | ||
outputs: [ | ||
{ name: "balances", internalType: "uint256[]", type: "uint256[]" } | ||
] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [ | ||
{ name: "", internalType: "address", type: "address" }, | ||
{ name: "", internalType: "address", type: "address" } | ||
], | ||
name: "isApprovedForAll", | ||
outputs: [{ name: "", internalType: "bool", type: "bool" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "from", internalType: "address", type: "address" }, | ||
{ name: "to", internalType: "address", type: "address" }, | ||
{ name: "ids", internalType: "uint256[]", type: "uint256[]" }, | ||
{ name: "amounts", internalType: "uint256[]", type: "uint256[]" }, | ||
{ name: "data", internalType: "bytes", type: "bytes" } | ||
], | ||
name: "safeBatchTransferFrom", | ||
outputs: [] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "from", internalType: "address", type: "address" }, | ||
{ name: "to", internalType: "address", type: "address" }, | ||
{ name: "id", internalType: "uint256", type: "uint256" }, | ||
{ name: "amount", internalType: "uint256", type: "uint256" }, | ||
{ name: "data", internalType: "bytes", type: "bytes" } | ||
], | ||
name: "safeTransferFrom", | ||
outputs: [] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "operator", internalType: "address", type: "address" }, | ||
{ name: "approved", internalType: "bool", type: "bool" } | ||
], | ||
name: "setApprovalForAll", | ||
outputs: [] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "interfaceId", internalType: "bytes4", type: "bytes4" }], | ||
name: "supportsInterface", | ||
outputs: [{ name: "", internalType: "bool", type: "bool" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "id", internalType: "uint256", type: "uint256" }], | ||
name: "uri", | ||
outputs: [{ name: "", internalType: "string", type: "string" }] | ||
} | ||
]; | ||
var solmateErc20ABI = [ | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
name: "owner", | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ | ||
name: "spender", | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ | ||
name: "amount", | ||
internalType: "uint256", | ||
type: "uint256", | ||
indexed: false | ||
} | ||
], | ||
name: "Approval" | ||
}, | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ name: "from", internalType: "address", type: "address", indexed: true }, | ||
{ name: "to", internalType: "address", type: "address", indexed: true }, | ||
{ | ||
name: "amount", | ||
internalType: "uint256", | ||
type: "uint256", | ||
indexed: false | ||
} | ||
], | ||
name: "Transfer" | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "DOMAIN_SEPARATOR", | ||
outputs: [{ name: "", internalType: "bytes32", type: "bytes32" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [ | ||
{ name: "", internalType: "address", type: "address" }, | ||
{ name: "", internalType: "address", type: "address" } | ||
], | ||
name: "allowance", | ||
outputs: [{ name: "", internalType: "uint256", type: "uint256" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "spender", internalType: "address", type: "address" }, | ||
{ name: "amount", internalType: "uint256", type: "uint256" } | ||
], | ||
name: "approve", | ||
outputs: [{ name: "", internalType: "bool", type: "bool" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "", internalType: "address", type: "address" }], | ||
name: "balanceOf", | ||
outputs: [{ name: "", internalType: "uint256", type: "uint256" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "decimals", | ||
outputs: [{ name: "", internalType: "uint8", type: "uint8" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "name", | ||
outputs: [{ name: "", internalType: "string", type: "string" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "", internalType: "address", type: "address" }], | ||
name: "nonces", | ||
outputs: [{ name: "", internalType: "uint256", type: "uint256" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "owner", internalType: "address", type: "address" }, | ||
{ name: "spender", internalType: "address", type: "address" }, | ||
{ name: "value", internalType: "uint256", type: "uint256" }, | ||
{ name: "deadline", internalType: "uint256", type: "uint256" }, | ||
{ name: "v", internalType: "uint8", type: "uint8" }, | ||
{ name: "r", internalType: "bytes32", type: "bytes32" }, | ||
{ name: "s", internalType: "bytes32", type: "bytes32" } | ||
], | ||
name: "permit", | ||
outputs: [] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "symbol", | ||
outputs: [{ name: "", internalType: "string", type: "string" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "totalSupply", | ||
outputs: [{ name: "", internalType: "uint256", type: "uint256" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "to", internalType: "address", type: "address" }, | ||
{ name: "amount", internalType: "uint256", type: "uint256" } | ||
], | ||
name: "transfer", | ||
outputs: [{ name: "", internalType: "bool", type: "bool" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "from", internalType: "address", type: "address" }, | ||
{ name: "to", internalType: "address", type: "address" }, | ||
{ name: "amount", internalType: "uint256", type: "uint256" } | ||
], | ||
name: "transferFrom", | ||
outputs: [{ name: "", internalType: "bool", type: "bool" }] | ||
} | ||
]; | ||
var solmateErc721ABI = [ | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
name: "owner", | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ | ||
name: "spender", | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ name: "id", internalType: "uint256", type: "uint256", indexed: true } | ||
], | ||
name: "Approval" | ||
}, | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ | ||
name: "owner", | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ | ||
name: "operator", | ||
internalType: "address", | ||
type: "address", | ||
indexed: true | ||
}, | ||
{ name: "approved", internalType: "bool", type: "bool", indexed: false } | ||
], | ||
name: "ApprovalForAll" | ||
}, | ||
{ | ||
type: "event", | ||
anonymous: false, | ||
inputs: [ | ||
{ name: "from", internalType: "address", type: "address", indexed: true }, | ||
{ name: "to", internalType: "address", type: "address", indexed: true }, | ||
{ name: "id", internalType: "uint256", type: "uint256", indexed: true } | ||
], | ||
name: "Transfer" | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "spender", internalType: "address", type: "address" }, | ||
{ name: "id", internalType: "uint256", type: "uint256" } | ||
], | ||
name: "approve", | ||
outputs: [] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "owner", internalType: "address", type: "address" }], | ||
name: "balanceOf", | ||
outputs: [{ name: "", internalType: "uint256", type: "uint256" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "", internalType: "uint256", type: "uint256" }], | ||
name: "getApproved", | ||
outputs: [{ name: "", internalType: "address", type: "address" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [ | ||
{ name: "", internalType: "address", type: "address" }, | ||
{ name: "", internalType: "address", type: "address" } | ||
], | ||
name: "isApprovedForAll", | ||
outputs: [{ name: "", internalType: "bool", type: "bool" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "name", | ||
outputs: [{ name: "", internalType: "string", type: "string" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "id", internalType: "uint256", type: "uint256" }], | ||
name: "ownerOf", | ||
outputs: [{ name: "owner", internalType: "address", type: "address" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "from", internalType: "address", type: "address" }, | ||
{ name: "to", internalType: "address", type: "address" }, | ||
{ name: "id", internalType: "uint256", type: "uint256" } | ||
], | ||
name: "safeTransferFrom", | ||
outputs: [] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "from", internalType: "address", type: "address" }, | ||
{ name: "to", internalType: "address", type: "address" }, | ||
{ name: "id", internalType: "uint256", type: "uint256" }, | ||
{ name: "data", internalType: "bytes", type: "bytes" } | ||
], | ||
name: "safeTransferFrom", | ||
outputs: [] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "operator", internalType: "address", type: "address" }, | ||
{ name: "approved", internalType: "bool", type: "bool" } | ||
], | ||
name: "setApprovalForAll", | ||
outputs: [] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "interfaceId", internalType: "bytes4", type: "bytes4" }], | ||
name: "supportsInterface", | ||
outputs: [{ name: "", internalType: "bool", type: "bool" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [], | ||
name: "symbol", | ||
outputs: [{ name: "", internalType: "string", type: "string" }] | ||
}, | ||
{ | ||
stateMutability: "view", | ||
type: "function", | ||
inputs: [{ name: "id", internalType: "uint256", type: "uint256" }], | ||
name: "tokenURI", | ||
outputs: [{ name: "", internalType: "string", type: "string" }] | ||
}, | ||
{ | ||
stateMutability: "nonpayable", | ||
type: "function", | ||
inputs: [ | ||
{ name: "from", internalType: "address", type: "address" }, | ||
{ name: "to", internalType: "address", type: "address" }, | ||
{ name: "id", internalType: "uint256", type: "uint256" } | ||
], | ||
name: "transferFrom", | ||
outputs: [] | ||
} | ||
]; | ||
var getERC20Decimals = (client, { erc20, ...request }) => readContract(client, { | ||
abi: solmateErc20ABI, | ||
address: erc20.address, | ||
functionName: "decimals", | ||
...request | ||
}); | ||
var getERC20Name = (client, { erc20, ...request }) => readContract(client, { | ||
abi: solmateErc20ABI, | ||
address: erc20.address, | ||
functionName: "name", | ||
...request | ||
}); | ||
var getERC20Symbol = (client, { erc20, ...request }) => readContract(client, { | ||
abi: solmateErc20ABI, | ||
address: erc20.address, | ||
functionName: "symbol", | ||
...request | ||
}); | ||
// src/erc20/publicActions/getERC20.ts | ||
var getERC20 = (client, { erc20, ...request }) => Promise.all([ | ||
getERC20Name(client, { erc20, ...request }), | ||
getERC20Symbol(client, { erc20, ...request }), | ||
getERC20Decimals(client, { erc20, ...request }) | ||
]).then( | ||
([name, symbol, decimals]) => createERC20( | ||
erc20.address, | ||
name, | ||
symbol, | ||
decimals, | ||
erc20.chainID, | ||
erc20.blockCreated | ||
) | ||
); | ||
var getERC20Allowance = (client, { erc20, owner, spender, ...request }) => readContract(client, { | ||
abi: solmateErc20ABI, | ||
address: erc20.address, | ||
functionName: "allowance", | ||
args: [owner, spender], | ||
...request | ||
}).then((data) => createAmountFromRaw(erc20, data)); | ||
var getERC20BalanceOf = (client, { erc20, address, ...request }) => readContract(client, { | ||
abi: solmateErc20ABI, | ||
address: erc20.address, | ||
functionName: "balanceOf", | ||
args: [address], | ||
...request | ||
}).then((data) => createAmountFromRaw(erc20, data)); | ||
var getERC20DomainSeparator = (client, { erc20, ...request }) => readContract(client, { | ||
abi: solmateErc20ABI, | ||
address: erc20.address, | ||
functionName: "DOMAIN_SEPARATOR", | ||
...request | ||
}); | ||
// src/erc20/publicActions/getERC20Permit.ts | ||
var getERC20Permit = (client, { erc20, ...request }) => Promise.all([ | ||
getERC20Name(client, { erc20, ...request }), | ||
getERC20Symbol(client, { erc20, ...request }), | ||
getERC20Decimals(client, { erc20, ...request }) | ||
]).then( | ||
([name, symbol, decimals]) => createERC20Permit( | ||
erc20.address, | ||
name, | ||
symbol, | ||
decimals, | ||
erc20.version ?? "1", | ||
erc20.chainID, | ||
erc20.blockCreated | ||
) | ||
); | ||
var getERC20PermitData = (client, { erc20, address, ...request }) => Promise.all([ | ||
readContract(client, { | ||
abi: solmateErc20ABI, | ||
address: erc20.address, | ||
functionName: "balanceOf", | ||
args: [address], | ||
...request | ||
}), | ||
readContract(client, { | ||
abi: solmateErc20ABI, | ||
address: erc20.address, | ||
functionName: "nonces", | ||
args: [address], | ||
...request | ||
}) | ||
]).then( | ||
([balance, nonce]) => createERC20PermitDataFromRaw(erc20, balance, nonce) | ||
); | ||
var getERC20PermitNonce = (client, { erc20, address, ...request }) => readContract(client, { | ||
abi: solmateErc20ABI, | ||
address: erc20.address, | ||
functionName: "nonces", | ||
args: [address], | ||
...request | ||
}); | ||
var getERC20TotalSupply = (client, { erc20, ...request }) => readContract(client, { | ||
abi: solmateErc20ABI, | ||
address: erc20.address, | ||
functionName: "totalSupply", | ||
...request | ||
}).then((data) => createAmountFromRaw(erc20, data)); | ||
// src/erc20/publicActions/getIsERC20Permit.ts | ||
var getIsERC20Permit = (client, { erc20, ...request }) => Promise.all([ | ||
getERC20Permit(client, { erc20, ...request }), | ||
getERC20DomainSeparator(client, { erc20, ...request }) | ||
]).then(([erc202]) => erc202).catch(() => getERC20(client, { erc20, ...request })); | ||
var signERC20Permit = (client, { | ||
permitData, | ||
spender, | ||
deadline, | ||
account = client.account, | ||
...request | ||
}) => { | ||
const domain = { | ||
name: permitData.token.name, | ||
version: permitData.token.version, | ||
chainId: permitData.token.chainID, | ||
verifyingContract: getAddress(permitData.token.address) | ||
}; | ||
const owner = client.account?.address ?? (typeof account === "object" ? account.address : account); | ||
return signTypedData(client, { | ||
domain, | ||
types: PermitType, | ||
primaryType: "Permit", | ||
message: { | ||
owner, | ||
spender, | ||
value: permitData.amount, | ||
deadline, | ||
nonce: permitData.nonce | ||
}, | ||
account, | ||
...request | ||
}); | ||
}; | ||
var simulateERC20Approve = (client, { | ||
args: { amount, spender }, | ||
...request | ||
}) => simulateContract(client, { | ||
address: amount.token.address, | ||
abi: solmateErc20ABI, | ||
functionName: "approve", | ||
args: [spender, amount.amount], | ||
...request | ||
}); | ||
var simulateERC20Permit = (client, { | ||
args: { owner, spender, signature, permitData, deadline }, | ||
...request | ||
}) => { | ||
const r = `0x${signature.substring(2, 2 + 64)}`; | ||
const s = `0x${signature.substring(2 + 64, 2 + 64 + 64)}`; | ||
const v = Number(`0x${signature.substring(2 + 64 + 64)}`); | ||
return simulateContract(client, { | ||
address: permitData.token.address, | ||
abi: solmateErc20ABI, | ||
functionName: "permit", | ||
args: [owner, spender, permitData.amount, deadline, v, r, s], | ||
...request | ||
}); | ||
}; | ||
var simulateERC20Transfer = (client, { | ||
args: { amount, to }, | ||
...request | ||
}) => simulateContract(client, { | ||
address: amount.token.address, | ||
abi: solmateErc20ABI, | ||
functionName: "transfer", | ||
args: [to, amount.amount], | ||
...request | ||
}); | ||
var simulateERC20TransferFrom = (client, { | ||
args: { amount, from, to }, | ||
...request | ||
}) => simulateContract(client, { | ||
address: amount.token.address, | ||
abi: solmateErc20ABI, | ||
functionName: "transferFrom", | ||
args: [from, to, amount.amount], | ||
...request | ||
}); | ||
var createERC721 = (address, name, symbol, chainID, blockCreated = 0n) => ({ | ||
type: "erc721", | ||
address: getAddress(address), | ||
name, | ||
symbol, | ||
chainID, | ||
blockCreated | ||
}); | ||
var createERC721Data = (erc721, balance, ids) => ({ | ||
type: `${erc721.type}Data`, | ||
token: erc721, | ||
balance, | ||
ids | ||
}); | ||
var getERC721Name = (client, { erc721, ...request }) => readContract(client, { | ||
abi: solmateErc721ABI, | ||
address: erc721.address, | ||
functionName: "name", | ||
...request | ||
}); | ||
var getERC721Symbol = (client, { erc721, ...request }) => readContract(client, { | ||
abi: solmateErc721ABI, | ||
address: erc721.address, | ||
functionName: "symbol", | ||
...request | ||
}); | ||
// src/erc721/publicActions/getERC721.ts | ||
var getERC721 = (client, { erc721, ...request }) => Promise.all([ | ||
getERC721Name(client, { erc721, ...request }), | ||
getERC721Symbol(client, { erc721, ...request }) | ||
]).then( | ||
([name, symbol]) => createERC721( | ||
erc721.address, | ||
name, | ||
symbol, | ||
erc721.chainID, | ||
erc721.blockCreated | ||
) | ||
); | ||
var getERC721Approved = (client, { erc721, id, ...request }) => readContract(client, { | ||
abi: solmateErc721ABI, | ||
address: erc721.address, | ||
functionName: "getApproved", | ||
args: [id], | ||
...request | ||
}); | ||
var getERC721BalanceOf = (client, { erc721, address, ...request }) => readContract(client, { | ||
abi: solmateErc721ABI, | ||
address: erc721.address, | ||
functionName: "balanceOf", | ||
args: [address], | ||
...request | ||
}); | ||
// src/erc721/publicActions/getERC721Data.ts | ||
var getERC721Data = (client, { erc721, address, ...request }) => getERC721BalanceOf(client, { erc721, address, ...request }).then((data) => { | ||
if (data > Number.MAX_SAFE_INTEGER) | ||
throw Error("balance exceeds maximum representable number"); | ||
return createERC721Data(erc721, Number(data)); | ||
}); | ||
var getERC721IsApprovedForAll = (client, { erc721, owner, spender, ...request }) => readContract(client, { | ||
abi: solmateErc721ABI, | ||
address: erc721.address, | ||
functionName: "isApprovedForAll", | ||
args: [owner, spender], | ||
...request | ||
}); | ||
var getERC721OwnerOf = (client, { erc721, id, ...request }) => readContract(client, { | ||
abi: solmateErc721ABI, | ||
address: erc721.address, | ||
functionName: "ownerOf", | ||
args: [id], | ||
...request | ||
}); | ||
var getERC721SupportsInterface = (client, { erc721, interfaceID, ...request }) => readContract(client, { | ||
abi: solmateErc721ABI, | ||
address: erc721.address, | ||
functionName: "supportsInterface", | ||
args: [interfaceID], | ||
...request | ||
}); | ||
var getERC721TokenURI = (client, { erc721, id, ...request }) => readContract(client, { | ||
abi: solmateErc721ABI, | ||
address: erc721.address, | ||
functionName: "tokenURI", | ||
args: [id], | ||
...request | ||
}); | ||
var simulateERC721Transfer = (client, { | ||
args: { erc721, from, to, data, id }, | ||
...request | ||
}) => data === void 0 ? simulateContract(client, { | ||
address: erc721.address, | ||
abi: solmateErc721ABI, | ||
functionName: "transferFrom", | ||
args: [ | ||
from ?? client.account?.address ?? (typeof request.account === "object" ? request.account.address : request.account), | ||
to, | ||
id | ||
], | ||
...request | ||
}) : data === "safe" ? simulateContract(client, { | ||
address: erc721.address, | ||
abi: solmateErc721ABI, | ||
functionName: "safeTransferFrom", | ||
args: [ | ||
from ?? client.account?.address ?? (typeof request.account === "object" ? request.account.address : request.account), | ||
to, | ||
id | ||
], | ||
...request | ||
}) : simulateContract(client, { | ||
address: erc721.address, | ||
abi: solmateErc721ABI, | ||
functionName: "safeTransferFrom", | ||
args: [ | ||
from ?? client.account?.address ?? (typeof request.account === "object" ? request.account.address : request.account), | ||
to, | ||
id, | ||
data | ||
], | ||
...request | ||
}); | ||
var simulateERC721Approve = (client, { | ||
args: { erc721, spender, id }, | ||
...request | ||
}) => simulateContract(client, { | ||
address: erc721.address, | ||
abi: solmateErc721ABI, | ||
functionName: "approve", | ||
args: [spender, id], | ||
...request | ||
}); | ||
var simulateERC721SetApprovalForAll = (client, { | ||
args: { erc721, spender, approved }, | ||
...request | ||
}) => simulateContract(client, { | ||
address: erc721.address, | ||
abi: solmateErc721ABI, | ||
functionName: "setApprovalForAll", | ||
args: [spender, approved], | ||
...request | ||
}); | ||
var createERC1155 = (address, id, uri, chainID, blockCreated = 0n) => ({ | ||
type: "erc1155", | ||
address: getAddress$1(address), | ||
id, | ||
uri, | ||
chainID, | ||
blockCreated | ||
}); | ||
var createERC1155Data = (erc1155, amount) => ({ | ||
type: `${erc1155.type}Data`, | ||
token: erc1155, | ||
amount | ||
}); | ||
var getERC1155 = (client, { erc1155, ...request }) => readContract(client, { | ||
abi: solmateErc1155ABI, | ||
address: erc1155.address, | ||
functionName: "uri", | ||
args: [erc1155.id], | ||
...request | ||
}).then( | ||
(data) => createERC1155( | ||
erc1155.address, | ||
erc1155.id, | ||
data, | ||
erc1155.chainID, | ||
erc1155.blockCreated | ||
) | ||
); | ||
var getERC1155BalanceOf = (client, { erc1155, address, ...request }) => readContract(client, { | ||
abi: solmateErc1155ABI, | ||
address: erc1155.address, | ||
functionName: "balanceOf", | ||
args: [address, erc1155.id], | ||
...request | ||
}).then((data) => createERC1155Data(erc1155, data)); | ||
var getERC1155IsApprovedForAll = (client, { erc1155, owner, spender, ...request }) => readContract(client, { | ||
abi: solmateErc1155ABI, | ||
address: erc1155.address, | ||
functionName: "isApprovedForAll", | ||
args: [owner, spender], | ||
...request | ||
}); | ||
var getERC1155URI = (client, { erc1155, ...request }) => readContract(client, { | ||
abi: solmateErc1155ABI, | ||
address: erc1155.address, | ||
functionName: "uri", | ||
args: [erc1155.id], | ||
...request | ||
}); | ||
var simulateERC1155Transfer = (client, { | ||
args: { erc1155Data, to, from, data }, | ||
...request | ||
}) => simulateContract(client, { | ||
address: erc1155Data.token.address, | ||
abi: solmateErc1155ABI, | ||
functionName: "safeTransferFrom", | ||
args: [ | ||
from ?? client.account?.address ?? (typeof request.account === "object" ? request.account.address : request.account), | ||
to, | ||
erc1155Data.token.id, | ||
erc1155Data.amount, | ||
data ?? "0x" | ||
], | ||
...request | ||
}); | ||
var simulateERC1155TransferBatch = (client, { | ||
args: { erc1155Data, to, from, data }, | ||
...request | ||
}) => { | ||
const address = erc1155Data.reduce((addr, cur) => { | ||
if (addr === void 0) | ||
return getAddress$1(cur.token.address); | ||
else if (addr !== getAddress$1(cur.token.address)) | ||
throw Error("Tokens refering to different addresses"); | ||
else | ||
return addr; | ||
}, void 0); | ||
if (address === void 0) | ||
throw Error("No tokens passed to transfer"); | ||
return simulateContract(client, { | ||
address, | ||
abi: solmateErc1155ABI, | ||
functionName: "safeBatchTransferFrom", | ||
args: [ | ||
from ?? client.account?.address ?? (typeof request.account === "object" ? request.account.address : request.account), | ||
to, | ||
erc1155Data.map((t) => t.token.id), | ||
erc1155Data.map((t) => t.amount), | ||
data ?? "0x" | ||
], | ||
...request | ||
}); | ||
}; | ||
var simulateERC1155SetApprovalForAll = (client, { | ||
args: { erc1155, spender, approved }, | ||
...request | ||
}) => simulateContract(client, { | ||
address: erc1155.address, | ||
abi: solmateErc1155ABI, | ||
functionName: "setApprovalForAll", | ||
args: [spender, approved], | ||
...request | ||
}); | ||
var isFraction = (x) => typeof x === "object"; | ||
var createFraction = (numerator, denominator = 1) => { | ||
const d = BigInt(denominator); | ||
invariant3(d !== 0n, "Fraction: denominator equal to 0"); | ||
return { type: "fraction", numerator: BigInt(numerator), denominator: d }; | ||
}; | ||
var fractionQuotient = (fraction) => fraction.numerator / fraction.denominator; | ||
var fractionRemainder = (fraction) => fraction.numerator % fraction.denominator; | ||
var fractionInvert = (fraction) => { | ||
invariant3(fraction.numerator !== 0n, "Fraction: denominator equal to 0"); | ||
return { | ||
type: "fraction", | ||
numerator: fraction.denominator, | ||
denominator: fraction.numerator | ||
}; | ||
}; | ||
var fractionAdd = (a, b) => isFraction(b) ? { | ||
type: "fraction", | ||
numerator: a.numerator * b.denominator + b.numerator * a.denominator, | ||
denominator: a.denominator * b.denominator | ||
} : { | ||
type: "fraction", | ||
numerator: a.numerator + a.denominator * BigInt(b), | ||
denominator: a.denominator | ||
}; | ||
var fractionSubtract = (a, b) => isFraction(b) ? { | ||
type: "fraction", | ||
numerator: a.numerator * b.denominator - b.numerator * a.denominator, | ||
denominator: a.denominator * b.denominator | ||
} : { | ||
type: "fraction", | ||
numerator: a.numerator - a.denominator * BigInt(b), | ||
denominator: a.denominator | ||
}; | ||
var fractionMultiply = (a, b) => isFraction(b) ? { | ||
type: "fraction", | ||
numerator: a.numerator * b.numerator, | ||
denominator: a.denominator * b.denominator | ||
} : { | ||
type: "fraction", | ||
numerator: a.numerator * BigInt(b), | ||
denominator: a.denominator | ||
}; | ||
var fractionDivide = (a, b) => isFraction(b) ? { | ||
type: "fraction", | ||
numerator: a.numerator * b.denominator, | ||
denominator: a.denominator * b.numerator | ||
} : { | ||
type: "fraction", | ||
numerator: a.numerator, | ||
denominator: a.denominator * BigInt(b) | ||
}; | ||
var fractionLessThan = (a, b) => isFraction(b) ? a.numerator * b.denominator < a.denominator * b.numerator : a.numerator < a.denominator * BigInt(b); | ||
var fractionGreaterThan = (a, b) => isFraction(b) ? a.numerator * b.denominator > a.denominator * b.numerator : a.numerator > a.denominator * BigInt(b); | ||
var fractionEqualTo = (a, b) => isFraction(b) ? a.numerator * b.denominator === a.denominator * b.numerator : a.numerator === a.denominator * BigInt(b); | ||
var fractionToNumber = (fraction) => Number(fraction.numerator) / Number(fraction.denominator); | ||
var getNativeBalance = (client, { | ||
address, | ||
nativeCurrency, | ||
...request | ||
}) => getBalance(client, { address, ...request }).then( | ||
(data) => createAmountFromRaw(nativeCurrency, data) | ||
); | ||
var isPrice = (x) => typeof x === "object"; | ||
var createPriceFromFraction = (quote, base, price) => ({ | ||
type: "price", | ||
quote, | ||
base, | ||
numerator: quote.decimals ? price.numerator * 10n ** BigInt(quote.decimals) : price.numerator, | ||
denominator: base.decimals ? price.denominator * 10n ** BigInt(base.decimals) : price.denominator | ||
}); | ||
var createPriceFromAmounts = (quote, base) => ({ | ||
type: "price", | ||
quote: quote.token, | ||
base: base.token, | ||
numerator: base.amount, | ||
denominator: quote.amount | ||
}); | ||
var createPrice = (quote, base, numerator, denominator = 1) => ({ | ||
type: "price", | ||
quote, | ||
base, | ||
numerator: quote.decimals ? BigInt(numerator) * 10n ** BigInt(quote.decimals) : BigInt(numerator), | ||
denominator: base.decimals ? BigInt(denominator) * 10n ** BigInt(base.decimals) : BigInt(denominator) | ||
}); | ||
var priceInvert = (price) => ({ | ||
...fractionInvert(rawPrice(price)), | ||
type: "price", | ||
quote: price.base, | ||
base: price.quote | ||
}); | ||
var priceAdd = (a, b) => { | ||
if (isPrice(b)) | ||
invariant3(a.base === b.base && a.quote === b.quote); | ||
return isPrice(b) ? { | ||
...fractionAdd(rawPrice(a), rawPrice(b)), | ||
type: "price", | ||
quote: a.quote, | ||
base: a.base | ||
} : createPriceFromFraction( | ||
a.quote, | ||
a.base, | ||
fractionAdd(adjustedPrice(a), b) | ||
); | ||
}; | ||
var priceSubtract = (a, b) => { | ||
if (isPrice(b)) | ||
invariant3(a.base === b.base && a.quote === b.quote); | ||
return isPrice(b) ? { | ||
...fractionSubtract(rawPrice(a), rawPrice(b)), | ||
type: "price", | ||
quote: a.quote, | ||
base: a.base | ||
} : createPriceFromFraction( | ||
a.quote, | ||
a.base, | ||
fractionSubtract(adjustedPrice(a), b) | ||
); | ||
}; | ||
var priceMultiply = (a, b) => { | ||
if (isPrice(b)) | ||
invariant3(a.base === b.base && a.quote === b.quote); | ||
return isPrice(b) ? { | ||
type: "price", | ||
quote: a.quote, | ||
base: a.base, | ||
numerator: scaleUp( | ||
a.base, | ||
fractionMultiply(rawPrice(a), rawPrice(b)).numerator | ||
), | ||
denominator: scaleUp( | ||
a.quote, | ||
fractionMultiply(rawPrice(a), rawPrice(b)).denominator | ||
) | ||
} : createPriceFromFraction( | ||
a.quote, | ||
a.base, | ||
fractionMultiply(adjustedPrice(a), b) | ||
); | ||
}; | ||
var priceDivide = (a, b) => { | ||
if (isPrice(b)) | ||
invariant3(a.base === b.base && a.quote === b.quote); | ||
return isPrice(b) ? { | ||
type: "price", | ||
quote: a.quote, | ||
base: a.base, | ||
numerator: scaleUp( | ||
a.quote, | ||
fractionDivide(rawPrice(a), rawPrice(b)).numerator | ||
), | ||
denominator: scaleUp( | ||
a.base, | ||
fractionDivide(rawPrice(a), rawPrice(b)).denominator | ||
) | ||
} : createPriceFromFraction( | ||
a.quote, | ||
a.base, | ||
fractionDivide(adjustedPrice(a), b) | ||
); | ||
}; | ||
var priceLessThan = (a, b) => { | ||
if (isPrice(b)) | ||
invariant3(a.base === b.base && a.quote === b.quote); | ||
return isPrice(b) ? fractionLessThan(rawPrice(a), rawPrice(b)) : fractionLessThan(adjustedPrice(a), b); | ||
}; | ||
var priceEqualTo = (a, b) => { | ||
if (isPrice(b)) | ||
invariant3(a.base === b.base && a.quote === b.quote); | ||
return isPrice(b) ? fractionEqualTo(rawPrice(a), rawPrice(b)) : fractionEqualTo(adjustedPrice(a), b); | ||
}; | ||
var priceGreaterThan = (a, b) => { | ||
if (isPrice(b)) | ||
invariant3(a.base === b.base && a.quote === b.quote); | ||
return isPrice(b) ? fractionGreaterThan(rawPrice(a), rawPrice(b)) : fractionGreaterThan(adjustedPrice(a), b); | ||
}; | ||
var priceQuote = (price, amount) => { | ||
invariant3(price.base === amount.token); | ||
return createAmountFromRaw( | ||
price.quote, | ||
price.numerator * amount.amount / price.denominator | ||
); | ||
}; | ||
var rawPrice = (price) => ({ | ||
type: "fraction", | ||
numerator: price.numerator, | ||
denominator: price.denominator | ||
}); | ||
var adjustedPrice = (price) => ({ | ||
type: "fraction", | ||
numerator: price.base.decimals ? price.numerator * 10n ** BigInt(price.base.decimals) : price.numerator, | ||
denominator: price.quote.decimals ? price.denominator * 10n ** BigInt(price.quote.decimals) : price.denominator | ||
}); | ||
var priceToNumber = (price) => fractionToNumber(adjustedPrice(price)); | ||
var simulateWETHDeposit = (client, { | ||
args: { amount }, | ||
...request | ||
}) => simulateContract(client, { | ||
address: amount.token.address, | ||
abi: weth9ABI, | ||
functionName: "deposit", | ||
value: amount.amount, | ||
...request | ||
}); | ||
var simulateWETHWithdraw = (client, { | ||
args: { amount }, | ||
...request | ||
}) => simulateContract(client, { | ||
address: amount.token.address, | ||
abi: weth9ABI, | ||
functionName: "withdraw", | ||
args: [amount.amount], | ||
...request | ||
}); | ||
// src/decorator/publicActions.ts | ||
var publicActionReverseMirage = (client) => ({ | ||
getNativeBalance: (args) => getNativeBalance(client, args), | ||
getERC20: (args) => getERC20(client, args), | ||
getERC20Allowance: (args) => getERC20Allowance(client, args), | ||
getERC20BalanceOf: (args) => getERC20BalanceOf(client, args), | ||
getERC20TotalSupply: (args) => getERC20TotalSupply(client, args), | ||
getERC20Name: (args) => getERC20Name(client, args), | ||
getERC20Symbol: (args) => getERC20Symbol(client, args), | ||
getERC20Decimals: (args) => getERC20Decimals(client, args), | ||
getERC20DomainSeparator: (args) => getERC20DomainSeparator(client, args), | ||
getERC20Permit: (args) => getERC20Permit(client, args), | ||
getERC20PermitNonce: (args) => getERC20PermitNonce(client, args), | ||
getERC20PermitData: (args) => getERC20PermitData(client, args), | ||
getIsERC20Permit: (args) => getIsERC20Permit(client, args), | ||
getERC721: (args) => getERC721(client, args), | ||
getERC721Approved: (args) => getERC721Approved(client, args), | ||
getERC721BalanceOf: (args) => getERC721BalanceOf(client, args), | ||
getERC721OwnerOf: (args) => getERC721OwnerOf(client, args), | ||
getERC721Data: (args) => getERC721Data(client, args), | ||
getERC721Name: (args) => getERC721Name(client, args), | ||
getERC721Symbol: (args) => getERC721Symbol(client, args), | ||
getERC721TokenURI: (args) => getERC721TokenURI(client, args), | ||
getERC721IsApprovedForAll: (args) => getERC721IsApprovedForAll(client, args), | ||
getERC721SupportsInterface: (args) => getERC721SupportsInterface(client, args), | ||
getERC1155: (args) => getERC1155(client, args), | ||
getERC1155BalanceOf: (args) => getERC1155BalanceOf(client, args), | ||
getERC1155IsApprovedForAll: (args) => getERC1155IsApprovedForAll(client, args), | ||
getERC1155URI: (args) => getERC1155URI(client, args), | ||
simulateWETHDeposit: (args) => simulateWETHDeposit(client, args), | ||
simulateWETHWithdraw: (args) => simulateWETHWithdraw(client, args), | ||
simulateERC20Approve: (args) => simulateERC20Approve(client, args), | ||
simulateERC20Permit: (args) => simulateERC20Permit(client, args), | ||
simulateERC20Transfer: (args) => simulateERC20Transfer(client, args), | ||
simulateERC20TransferFrom: (args) => simulateERC20TransferFrom(client, args), | ||
simulateERC721Approve: (args) => simulateERC721Approve(client, args), | ||
simulateERC721SetApprovalForAll: (args) => simulateERC721SetApprovalForAll(client, args), | ||
simulateERC721Transfer: (args) => simulateERC721Transfer(client, args), | ||
simulateERC1155SetApprovalForAll: (args) => simulateERC1155SetApprovalForAll(client, args), | ||
simulateERC1155Transfer: (args) => simulateERC1155Transfer(client, args), | ||
simulateERC1155TransferBatch: (args) => simulateERC1155TransferBatch(client, args) | ||
}); | ||
// src/decorator/walletActions.ts | ||
var walletActionReverseMirage = (client) => ({ | ||
signERC20Permit: (args) => signERC20Permit(client, args) | ||
}); | ||
export { PermitType, adjustedPrice, amountAdd, amountDivide, amountEqualTo, amountGreaterThan, amountLessThan, amountMultiply, amountSubtract, amountToNumber, arbitrumGoerliTokens, arbitrumTokens, baseGoerliTokens, baseTokens, celoAlfajoresTokens, celoTokens, createAmountFromFraction, createAmountFromRaw, createAmountFromString, createERC1155, createERC1155Data, createERC20, createERC20Permit, createERC20PermitDataFromFraction, createERC20PermitDataFromRaw, createERC20PermitDataFromString, createERC721, createERC721Data, createFraction, createNativeCurrency, createPrice, createPriceFromAmounts, createPriceFromFraction, createWETH, solmateErc1155ABI as erc1155ABI, solmateErc20ABI as erc20ABI, solmateErc721ABI as erc721ABI, foundryTokens, fractionAdd, fractionDivide, fractionEqualTo, fractionGreaterThan, fractionInvert, fractionLessThan, fractionMultiply, fractionQuotient, fractionRemainder, fractionSubtract, fractionToNumber, getERC1155, getERC1155BalanceOf, getERC1155IsApprovedForAll, getERC1155URI, getERC20, getERC20Allowance, getERC20BalanceOf, getERC20Decimals, getERC20DomainSeparator, getERC20Name, getERC20Permit, getERC20PermitData, getERC20PermitNonce, getERC20Symbol, getERC20TotalSupply, getERC721, getERC721Approved, getERC721BalanceOf, getERC721Data, getERC721IsApprovedForAll, getERC721Name, getERC721OwnerOf, getERC721SupportsInterface, getERC721Symbol, getERC721TokenURI, getIsERC20Permit, getNativeBalance, goerliTokens, isAmount, isFraction, isPrice, mainnetTokens, optimismGoerliTokens, optimismTokens, priceAdd, priceDivide, priceEqualTo, priceGreaterThan, priceInvert, priceLessThan, priceMultiply, priceQuote, priceSubtract, priceToNumber, publicActionReverseMirage, rawPrice, sepoliaTokens, signERC20Permit, simulateERC1155SetApprovalForAll, simulateERC1155Transfer, simulateERC1155TransferBatch, simulateERC20Approve, simulateERC20Permit, simulateERC20Transfer, simulateERC20TransferFrom, simulateERC721Approve, simulateERC721SetApprovalForAll, simulateERC721Transfer, simulateWETHDeposit, simulateWETHWithdraw, walletActionReverseMirage, weth9ABI }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "reverse-mirage", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Application level typescript utilities for Ethereum", | ||
@@ -59,3 +59,3 @@ "type": "module", | ||
"@viem/anvil": "^0.0.6", | ||
"@vitest/coverage-v8": "^0.34.5", | ||
"@vitest/coverage-v8": "^0.34.6", | ||
"bun": "^1.0.3", | ||
@@ -66,4 +66,4 @@ "mitata": "^0.1.6", | ||
"typescript": "^5.2.2", | ||
"viem": "^1.12.2", | ||
"vitest": "^0.34.5" | ||
"viem": "^1.14.0", | ||
"vitest": "^0.34.6" | ||
}, | ||
@@ -70,0 +70,0 @@ "packageManager": "pnpm@8.6.10", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
900566
12696
1