anchor-sdk 0.1.44-beta.1 → 0.1.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{createPublicClient as ne,createWalletClient as te,http as Ie,custom as L,encodeFunctionData as K,isAddress as f,keccak256 as h,stringToHex as W,concat as E,parseEther as ye}from"viem";import{encodeFunctionData as M}from"viem";import{abstract as pe,abstractTestnet as o,base as ie,baseSepolia as D,berachain as le,berachainBepolia as k,ronin as ue,saigon as g}from"viem/chains";var re;((y)=>{y.DEV="dev";y.BETA="beta";y.PROD="prod"})(re||={});var U=[{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"account",type:"address"}],name:"balanceOf",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{name:"recipient",type:"address"},{name:"amount",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"sender",type:"address"},{name:"recipient",type:"address"},{name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],Y={dev:{apiBaseUrl:"https://anchordev.dipbit.xyz",contracts:{[g.id]:{anchorPay:"0x8551891728967D2D7b6B502eF5339EEb2281143a",anchorERC1155:"0x23Da7778F6152D7B91C20808bEF7163c5EC2C470"},[D.id]:{anchorPay:"0x2C69537d9b82d2C863BCfF3442D1c4E7633ead7c",anchorERC1155:"0x1CE9506cdDdD304AA753c0E8f1F898ab97Ec2870"},[k.id]:{anchorPay:"0x80635645c4B4dA367F2eE6D8F38BED1c2CF8C484",anchorERC1155:"0x20a6e4aa138cF4635c0abFC79272FBeB8a116F36"},[o.id]:{anchorPay:"0xc5c1606fDe120018E74751253F572796EDbaBC09",anchorERC1155:"0x0E03d8fA4A37287eabfb2e5BBdc7AcD7C1D3e869"},["1962"]:{anchorERC1155:"0xa670ca0270c46876e5a78c9a7c596bfef91185a8"}}},beta:{apiBaseUrl:"https://anchorbeta.dipbit.xyz",contracts:{[g.id]:{anchorPay:"0xcbA8A3FE5fa94A807143bC2467A012010b02Cd94",anchorERC1155:"0x4a4D5888A284fED88fbE998c2C59957CE87923D2"},[D.id]:{anchorPay:"0x2EB31dAbb95F3697eC6bBfE0c41b55D9C321571e",anchorERC1155:"0xE78F00BBD1be39Db6C404142Cf4a3A2471A915e7"},[k.id]:{anchorPay:"0x382F7946378e8A7A848d04166083711c90D76061",anchorERC1155:"0x99eed4522a3Da62CaEE3e87BfFd3779d7d5EF853"},[o.id]:{anchorPay:"0x7dc99a343555711aB92fc844d0Df657161df7D67",anchorERC1155:"0xa34F267d3Ab2Ce21CBD1F04F593300f6CB609a29"},["1962"]:{anchorERC1155:"0xa51B53Dc3aA7f4ef5fE9bb429521a73f411ad867"}}},prod:{apiBaseUrl:"https://api-anchor.deek.network",contracts:{[pe.id]:{anchorPay:"0xf87C02027f36067a87E4eaeeD61b7Ce2ffE0813A",anchorERC1155:"0xd6895dc1740e057D564C795923542122f1513142"},[ie.id]:{anchorPay:"0x56f0fAF3a0336F57289e61Be6F32380B38C171E1"},[ue.id]:{anchorPay:"0x56f0fAF3a0336F57289e61Be6F32380B38C171E1",anchorERC1155:"0xA412f7D0B39c7451E9A8a34a66f0D69CB5A378dA"},[le.id]:{anchorPay:"0x4567890123456789012345678901234567890123",anchorERC1155:"0xdefabcdefabcdefabcdefabcdefabcdefabcdefab"}}}},Se={TOKEN_RECEIVED:"0x8b2cb2c7b7e2282e2e4b29a6a8c2b2db4218c6a5f8e8fcb3d5598f3e1e6c59d9"},I="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",j="0xcA11bde05977b3631167028862bE2a173976CA11",$=[{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall3.Call[]",name:"calls",type:"tuple[]"}],name:"aggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes[]",name:"returnData",type:"bytes[]"}],stateMutability:"payable",type:"function"},{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bool",name:"allowFailure",type:"bool"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall3.Call3[]",name:"calls",type:"tuple[]"}],name:"aggregate3",outputs:[{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall3.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"payable",type:"function"},{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bool",name:"allowFailure",type:"bool"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall3.Call3Value[]",name:"calls",type:"tuple[]"}],name:"aggregate3Value",outputs:[{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall3.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"payable",type:"function"}];var w=[{type:"constructor",inputs:[],stateMutability:"nonpayable"},{type:"function",name:"UPGRADE_INTERFACE_VERSION",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"acceptOwnership",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"balanceOf",inputs:[{name:"account",type:"address",internalType:"address"},{name:"token",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"depositFor",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"token",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"getInterfaceImplementer",inputs:[{name:"account",type:"address",internalType:"address"},{name:"_interfaceHash",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"initialize",inputs:[{name:"_defaultAdmin",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"pause",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"pendingOwner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"proxiableUUID",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"renounceOwnership",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"send",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"token",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"payable"},{type:"function",name:"setInterfaceImplementer",inputs:[{name:"account",type:"address",internalType:"address"},{name:"_interfaceHash",type:"bytes32",internalType:"bytes32"},{name:"implementer",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"transferOwnership",inputs:[{name:"newOwner",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"unpause",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"upgradeToAndCall",inputs:[{name:"newImplementation",type:"address",internalType:"address"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"payable"},{type:"function",name:"withdraw",inputs:[{name:"token",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"event",name:"Deposited",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"token",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Initialized",inputs:[{name:"version",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"InterfaceImplementerSet",inputs:[{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"interfaceHash",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"implementer",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"OwnershipTransferStarted",inputs:[{name:"previousOwner",type:"address",indexed:!0,internalType:"address"},{name:"newOwner",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"OwnershipTransferred",inputs:[{name:"previousOwner",type:"address",indexed:!0,internalType:"address"},{name:"newOwner",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"Paid",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"data",type:"bytes",indexed:!1,internalType:"bytes"}],anonymous:!1},{type:"event",name:"Upgraded",inputs:[{name:"implementation",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"Withdrawn",inputs:[{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"token",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"error",name:"AddressEmptyCode",inputs:[{name:"target",type:"address",internalType:"address"}]},{type:"error",name:"AddressNotSet",inputs:[]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{name:"implementation",type:"address",internalType:"address"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InsufficientBalance",inputs:[]},{type:"error",name:"InsufficientPayment",inputs:[]},{type:"error",name:"InvalidAddress",inputs:[]},{type:"error",name:"InvalidAmount",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidMsgValue",inputs:[]},{type:"error",name:"InvalidState",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"OwnableInvalidOwner",inputs:[{name:"owner",type:"address",internalType:"address"}]},{type:"error",name:"OwnableUnauthorizedAccount",inputs:[{name:"account",type:"address",internalType:"address"}]},{type:"error",name:"PaymentTransferFailed",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{name:"token",type:"address",internalType:"address"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{name:"slot",type:"bytes32",internalType:"bytes32"}]}];class Z{publicClient;walletClient;account;network;contracts;constructor(e,n,t,y,a){this.publicClient=e,this.network=n,this.walletClient=t,this.account=y,this.contracts=a||{}}async sendETH(e,n,t="0x",y){if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=M({abi:w,functionName:"send",args:[e,I,n,t]});if(y?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:a,value:n};let{maxFeePerGas:u,maxPriorityFeePerGas:l}=await this.publicClient.estimateFeesPerGas(),i=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:a,value:n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let p=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:a,value:n,maxFeePerGas:y?.maxFeePerGas||u,maxPriorityFeePerGas:y?.maxPriorityFeePerGas||l,gas:y?.gas||i,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:p})}async sendERC20(e,n,t,y="0x",a){if(a?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");if(a?.autoApprove!==!1&&this.walletClient&&this.account)try{console.log(`Checking ERC20 token approval status: ${n}`);let r=await this.publicClient.readContract({address:n,abi:U,functionName:"allowance",args:[this.account.address,this.contracts?.anchorPay]});if(console.log(`Current allowance: ${r}, Required amount: ${t}, AnchorPay contract address: ${this.contracts?.anchorPay}`),r<t){console.log(`Approving ${t} tokens to AnchorPay contract...`);let b=2n**256n-1n,{maxFeePerGas:z,maxPriorityFeePerGas:O}=await this.publicClient.estimateFeesPerGas(),x=M({abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b]}),d=await this.publicClient.estimateGas({to:n,data:x,value:0n,account:this.account}),v=await this.walletClient.writeContract({account:this.account,address:n,abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b],chain:this.publicClient.chain,maxFeePerGas:z,maxPriorityFeePerGas:O,gas:d});console.log(`Approval transaction sent, hash: ${v}`),await this.publicClient.waitForTransactionReceipt({hash:v}),console.log("Approval transaction confirmed")}else console.log("Sufficient allowance already exists, no need for additional approval")}catch(r){throw console.error("Approval failed:",r),Error(`ERC20 approval failed: ${r instanceof Error?r.message:String(r)}`)}let u=M({abi:w,functionName:"send",args:[e,n,t,y]});if(a?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:u,value:0n};let{maxFeePerGas:l,maxPriorityFeePerGas:i}=await this.publicClient.estimateFeesPerGas(),p=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:u,value:0n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let m=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:u,maxFeePerGas:a?.maxFeePerGas||l,maxPriorityFeePerGas:a?.maxPriorityFeePerGas||i,gas:a?.gas||p,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:m})}async getInterfaceImplementer(e,n){return await this.publicClient.readContract({address:this.contracts?.anchorPay||"",abi:w,functionName:"getInterfaceImplementer",args:[e,n]})}async setInterfaceImplementer(e,n,t){if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let{maxFeePerGas:y,maxPriorityFeePerGas:a}=await this.publicClient.estimateFeesPerGas(),u=M({abi:w,functionName:"setInterfaceImplementer",args:[e,n,t]}),l=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:u,value:0n,account:this.account}),i=await this.walletClient.writeContract({account:this.account,address:this.contracts?.anchorPay||"",abi:w,functionName:"setInterfaceImplementer",args:[e,n,t],chain:this.publicClient.chain,maxFeePerGas:y,maxPriorityFeePerGas:a,gas:l});return await this.publicClient.waitForTransactionReceipt({hash:i})}getERC20ApprovalData(e,n,t){let y=t||this.contracts?.anchorPay||"",a=M({abi:U,functionName:"approve",args:[y,n]});return{to:e,data:a,value:0n}}async balanceOf(e,n){return await this.publicClient.readContract({address:this.contracts?.anchorPay||"",abi:w,functionName:"balanceOf",args:[e,n]})}async depositETH(e,n,t){if(t?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let y=M({abi:w,functionName:"depositFor",args:[e,I,n]});if(t?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:y,value:n};let{maxFeePerGas:a,maxPriorityFeePerGas:u}=await this.publicClient.estimateFeesPerGas(),l=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:y,value:n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let i=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:y,value:n,maxFeePerGas:t?.maxFeePerGas||a,maxPriorityFeePerGas:t?.maxPriorityFeePerGas||u,gas:t?.gas||l,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:i})}async depositERC20(e,n,t,y){if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");if(y?.autoApprove!==!1&&this.walletClient&&this.account)try{console.log(`Checking ERC20 token approval status: ${n}`);let T=await this.publicClient.readContract({address:n,abi:U,functionName:"allowance",args:[this.account.address,this.contracts?.anchorPay]});if(console.log(`Current allowance: ${T}, Required amount: ${t}, AnchorPay contract address: ${this.contracts?.anchorPay}`),T<t){console.log(`Approving ${t} tokens to AnchorPay contract...`);let r=2n**256n-1n,{maxFeePerGas:b,maxPriorityFeePerGas:z}=await this.publicClient.estimateFeesPerGas(),O=M({abi:U,functionName:"approve",args:[this.contracts?.anchorPay,r]}),x=await this.publicClient.estimateGas({to:n,data:O,value:0n,account:this.account}),d=await this.walletClient.writeContract({account:this.account,address:n,abi:U,functionName:"approve",args:[this.contracts?.anchorPay,r],chain:this.publicClient.chain,maxFeePerGas:b,maxPriorityFeePerGas:z,gas:x});console.log(`Approval transaction sent, hash: ${d}`),await this.publicClient.waitForTransactionReceipt({hash:d}),console.log("Approval transaction confirmed")}else console.log("Sufficient allowance already exists, no need for additional approval")}catch(T){throw console.error("Approval failed:",T),Error(`ERC20 approval failed: ${T instanceof Error?T.message:String(T)}`)}let a=M({abi:w,functionName:"depositFor",args:[e,n,t]});if(y?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:a,value:0n};let{maxFeePerGas:u,maxPriorityFeePerGas:l}=await this.publicClient.estimateFeesPerGas(),i=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:a,value:0n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let p=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:a,maxFeePerGas:y?.maxFeePerGas||u,maxPriorityFeePerGas:y?.maxPriorityFeePerGas||l,gas:y?.gas||i,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:p})}async withdraw(e,n,t){if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let{maxFeePerGas:y,maxPriorityFeePerGas:a}=await this.publicClient.estimateFeesPerGas(),u=M({abi:w,functionName:"withdraw",args:[e,n]}),l=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:u,value:0n,account:this.account}),i=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:u,maxFeePerGas:t?.maxFeePerGas||y,maxPriorityFeePerGas:t?.maxPriorityFeePerGas||a,gas:t?.gas||l,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:i})}async batchDepositETH(e,n){if(e.length===0)throw Error("No deposits provided");if(n?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let t=e.map((T)=>{let r=M({abi:w,functionName:"depositFor",args:[T.recipient,I,T.amount]});return{target:this.contracts?.anchorPay||"",allowFailure:!1,value:T.amount,callData:r}}),y=e.reduce((T,r)=>T+r.amount,0n),a=M({abi:$,functionName:"aggregate3Value",args:[t]});if(n?.sendTransaction===!1)return{to:j,data:a,value:y};let{maxFeePerGas:u,maxPriorityFeePerGas:l}=await this.publicClient.estimateFeesPerGas(),i=await this.publicClient.estimateGas({to:j,data:a,value:y,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let p=await this.walletClient.sendTransaction({account:this.account,to:j,data:a,value:y,maxFeePerGas:n?.maxFeePerGas||u,maxPriorityFeePerGas:n?.maxPriorityFeePerGas||l,gas:n?.gas||i,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:p})}async batchDepositERC20(e,n,t){if(n.length===0)throw Error("No deposits provided");if(t?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let y=n.reduce((r,b)=>r+b.amount,0n);if(t?.autoApprove!==!1&&this.walletClient&&this.account)try{console.log(`Checking ERC20 token approval status: ${e}`);let r=await this.publicClient.readContract({address:e,abi:U,functionName:"allowance",args:[this.account.address,this.contracts?.anchorPay]});if(console.log(`Current allowance: ${r}, Required amount: ${y}, AnchorPay contract address: ${this.contracts?.anchorPay}`),r<y){console.log(`Approving ${y} tokens to AnchorPay contract...`);let b=2n**256n-1n,{maxFeePerGas:z,maxPriorityFeePerGas:O}=await this.publicClient.estimateFeesPerGas(),x=M({abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b]}),d=await this.publicClient.estimateGas({to:e,data:x,value:0n,account:this.account}),v=await this.walletClient.writeContract({account:this.account,address:e,abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b],chain:this.publicClient.chain,maxFeePerGas:z,maxPriorityFeePerGas:O,gas:d});console.log(`Approval transaction sent, hash: ${v}`),await this.publicClient.waitForTransactionReceipt({hash:v}),console.log("Approval transaction confirmed")}else console.log("Sufficient allowance already exists, no need for additional approval")}catch(r){throw console.error("Approval failed:",r),Error(`ERC20 approval failed: ${r instanceof Error?r.message:String(r)}`)}let a=n.map((r)=>{let b=M({abi:w,functionName:"depositFor",args:[r.recipient,e,r.amount]});return{target:this.contracts?.anchorPay||"",allowFailure:!1,value:0n,callData:b}}),u=M({abi:$,functionName:"aggregate3Value",args:[a]});if(t?.sendTransaction===!1)return{to:j,data:u,value:0n};let{maxFeePerGas:l,maxPriorityFeePerGas:i}=await this.publicClient.estimateFeesPerGas(),p=await this.publicClient.estimateGas({to:j,data:u,value:0n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let m=await this.walletClient.sendTransaction({account:this.account,to:j,data:u,maxFeePerGas:t?.maxFeePerGas||l,maxPriorityFeePerGas:t?.maxPriorityFeePerGas||i,gas:t?.gas||p,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:m})}async batchSendETH(e,n){if(e.length===0)throw Error("No transfers provided");if(n?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let t=e.map((T)=>{let r=M({abi:w,functionName:"send",args:[T.recipient,I,T.amount,T.data||"0x"]});return{target:this.contracts?.anchorPay||"",allowFailure:!1,value:T.amount,callData:r}}),y=e.reduce((T,r)=>T+r.amount,0n),a=M({abi:$,functionName:"aggregate3Value",args:[t]});if(n?.sendTransaction===!1)return{to:j,data:a,value:y};let{maxFeePerGas:u,maxPriorityFeePerGas:l}=await this.publicClient.estimateFeesPerGas(),i=await this.publicClient.estimateGas({to:j,data:a,value:y,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let p=await this.walletClient.sendTransaction({account:this.account,to:j,data:a,value:y,maxFeePerGas:n?.maxFeePerGas||u,maxPriorityFeePerGas:n?.maxPriorityFeePerGas||l,gas:n?.gas||i,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:p})}async batchSendERC20(e,n,t){if(n.length===0)throw Error("No transfers provided");if(t?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let y=n.reduce((r,b)=>r+b.amount,0n);if(t?.autoApprove!==!1&&this.walletClient&&this.account)try{console.log(`Checking ERC20 token approval status: ${e}`);let r=await this.publicClient.readContract({address:e,abi:U,functionName:"allowance",args:[this.account.address,this.contracts?.anchorPay]});if(console.log(`Current allowance: ${r}, Required amount: ${y}, AnchorPay contract address: ${this.contracts?.anchorPay}`),r<y){console.log(`Approving ${y} tokens to AnchorPay contract...`);let b=2n**256n-1n,{maxFeePerGas:z,maxPriorityFeePerGas:O}=await this.publicClient.estimateFeesPerGas(),x=M({abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b]}),d=await this.publicClient.estimateGas({to:e,data:x,value:0n,account:this.account}),v=await this.walletClient.writeContract({account:this.account,address:e,abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b],chain:this.publicClient.chain,maxFeePerGas:z,maxPriorityFeePerGas:O,gas:d});console.log(`Approval transaction sent, hash: ${v}`),await this.publicClient.waitForTransactionReceipt({hash:v}),console.log("Approval transaction confirmed")}else console.log("Sufficient allowance already exists, no need for additional approval")}catch(r){throw console.error("Approval failed:",r),Error(`ERC20 approval failed: ${r instanceof Error?r.message:String(r)}`)}let a=n.map((r)=>{let b=M({abi:w,functionName:"send",args:[r.recipient,e,r.amount,r.data||"0x"]});return{target:this.contracts?.anchorPay||"",allowFailure:!1,value:0n,callData:b}}),u=M({abi:$,functionName:"aggregate3Value",args:[a]});if(t?.sendTransaction===!1)return{to:j,data:u,value:0n};let{maxFeePerGas:l,maxPriorityFeePerGas:i}=await this.publicClient.estimateFeesPerGas(),p=await this.publicClient.estimateGas({to:j,data:u,value:0n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let m=await this.walletClient.sendTransaction({account:this.account,to:j,data:u,maxFeePerGas:t?.maxFeePerGas||l,maxPriorityFeePerGas:t?.maxPriorityFeePerGas||i,gas:t?.gas||p,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:m})}}import{concat as c,encodeAbiParameters as A,encodeFunctionData as ve,keccak256 as P,stringToHex as C}from"viem";var _=[{type:"constructor",inputs:[],stateMutability:"nonpayable"},{type:"function",name:"DEFAULT_ADMIN_ROLE",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"UPGRADE_INTERFACE_VERSION",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"badgeToProject",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"balanceOf",inputs:[{name:"account",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"balanceOfBatch",inputs:[{name:"accounts",type:"address[]",internalType:"address[]"},{name:"ids",type:"uint256[]",internalType:"uint256[]"}],outputs:[{name:"",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"view"},{type:"function",name:"burnBatch",inputs:[{name:"from",type:"address",internalType:"address"},{name:"ids",type:"uint256[]",internalType:"uint256[]"},{name:"values",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"calculateProjectTokenId",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"projectTokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"pure"},{type:"function",name:"createBatch",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"_to",type:"address",internalType:"address"},{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"},{name:"_maxSupplies",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"createBatch",inputs:[{name:"_to",type:"address",internalType:"address"},{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"},{name:"_maxSupplies",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"eip712Domain",inputs:[],outputs:[{name:"fields",type:"bytes1",internalType:"bytes1"},{name:"name",type:"string",internalType:"string"},{name:"version",type:"string",internalType:"string"},{name:"chainId",type:"uint256",internalType:"uint256"},{name:"verifyingContract",type:"address",internalType:"address"},{name:"salt",type:"bytes32",internalType:"bytes32"},{name:"extensions",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"view"},{type:"function",name:"exists",inputs:[{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"getRoleAdmin",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"grantAdminRole",inputs:[{name:"admin",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"grantProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"grantRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"hasRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"initialize",inputs:[{name:"_defaultAdmin",type:"address",internalType:"address"},{name:"_name",type:"string",internalType:"string"},{name:"_symbol",type:"string",internalType:"string"},{name:"_version",type:"string",internalType:"string"},{name:"_baseURI",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"isApprovedForAll",inputs:[{name:"account",type:"address",internalType:"address"},{name:"operator",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"mintWithSignature",inputs:[{name:"_req",type:"tuple",internalType:"struct AnchorDataTypes.MintRequest",components:[{name:"to",type:"address",internalType:"address"},{name:"tokenId",type:"uint256",internalType:"uint256"},{name:"quantity",type:"uint256",internalType:"uint256"},{name:"price",type:"uint256",internalType:"uint256"},{name:"currency",type:"address",internalType:"address"},{name:"validityStartTimestamp",type:"uint128",internalType:"uint128"},{name:"validityEndTimestamp",type:"uint128",internalType:"uint128"},{name:"uid",type:"bytes32",internalType:"bytes32"},{name:"chainId",type:"uint256",internalType:"uint256"},{name:"projectHandle",type:"bytes32",internalType:"bytes32"}]},{name:"_signature",type:"bytes",internalType:"bytes"}],outputs:[{name:"signer",type:"address",internalType:"address"}],stateMutability:"payable"},{type:"function",name:"multicall",inputs:[{name:"data",type:"bytes[]",internalType:"bytes[]"}],outputs:[{name:"results",type:"bytes[]",internalType:"bytes[]"}],stateMutability:"nonpayable"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"nextTokenIdToMint",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"projectTotalSupply",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"proxiableUUID",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"renounceRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"callerConfirmation",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"revokeProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"revokeRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"safeBatchTransferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"ids",type:"uint256[]",internalType:"uint256[]"},{name:"values",type:"uint256[]",internalType:"uint256[]"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"safeTransferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"},{name:"value",type:"uint256",internalType:"uint256"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setApprovalForAll",inputs:[{name:"operator",type:"address",internalType:"address"},{name:"approved",type:"bool",internalType:"bool"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setMaxSupply",inputs:[{name:"_tokenId",type:"uint256",internalType:"uint256"},{name:"_maxSupply",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRegistry",inputs:[{name:"registry",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setURIs",inputs:[{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setup",inputs:[{name:"_name",type:"string",internalType:"string"},{name:"_symbol",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"supportsInterface",inputs:[{name:"interfaceId",type:"bytes4",internalType:"bytes4"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"pure"},{type:"function",name:"symbol",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"tokenReceived",inputs:[{name:"token",type:"address",internalType:"address"},{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"},{name:"userData",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"totalSupply",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"totalSupply",inputs:[{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"upgradeTo",inputs:[{name:"newImplementation",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"upgradeToAndCall",inputs:[{name:"newImplementation",type:"address",internalType:"address"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"payable"},{type:"function",name:"uri",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"version",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"event",name:"AnchorInitialized",inputs:[{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ApprovalForAll",inputs:[{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"approved",type:"bool",indexed:!1,internalType:"bool"}],anonymous:!1},{type:"event",name:"BatchBurned",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"BatchCreated",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"projectTokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"tokenURIs",type:"string[]",indexed:!1,internalType:"string[]"},{name:"maxSupply",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"BatchURI",inputs:[{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"tokenURIs",type:"string[]",indexed:!1,internalType:"string[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"EIP712DomainChanged",inputs:[],anonymous:!1},{type:"event",name:"Initialized",inputs:[{name:"version",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"MaxSupplyUpdated",inputs:[{name:"tokenId",type:"uint256",indexed:!1,internalType:"uint256"},{name:"maxSupply",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Minted",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"tokenId",type:"uint256",indexed:!0,internalType:"uint256"},{name:"quantity",type:"uint256",indexed:!1,internalType:"uint256"},{name:"price",type:"uint256",indexed:!1,internalType:"uint256"},{name:"currency",type:"address",indexed:!1,internalType:"address"},{name:"uid",type:"bytes32",indexed:!1,internalType:"bytes32"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ProjectOperatorGranted",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ProjectOperatorRevoked",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"RoleAdminChanged",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"previousAdminRole",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"newAdminRole",type:"bytes32",indexed:!0,internalType:"bytes32"}],anonymous:!1},{type:"event",name:"RoleGranted",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"RoleRevoked",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"TransferBatch",inputs:[{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"ids",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"}],anonymous:!1},{type:"event",name:"TransferSingle",inputs:[{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"uint256",indexed:!1,internalType:"uint256"},{name:"value",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"URI",inputs:[{name:"value",type:"string",indexed:!1,internalType:"string"},{name:"id",type:"uint256",indexed:!0,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Upgraded",inputs:[{name:"implementation",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"error",name:"AccessControlBadConfirmation",inputs:[]},{type:"error",name:"AccessControlUnauthorizedAccount",inputs:[{name:"account",type:"address",internalType:"address"},{name:"neededRole",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"AddressEmptyCode",inputs:[{name:"target",type:"address",internalType:"address"}]},{type:"error",name:"AddressNotSet",inputs:[]},{type:"error",name:"ArrayLengthMismatch",inputs:[]},{type:"error",name:"ECDSAInvalidSignature",inputs:[]},{type:"error",name:"ECDSAInvalidSignatureLength",inputs:[{name:"length",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ECDSAInvalidSignatureS",inputs:[{name:"s",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"ERC1155InsufficientBalance",inputs:[{name:"sender",type:"address",internalType:"address"},{name:"balance",type:"uint256",internalType:"uint256"},{name:"needed",type:"uint256",internalType:"uint256"},{name:"tokenId",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ERC1155InvalidApprover",inputs:[{name:"approver",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidArrayLength",inputs:[{name:"idsLength",type:"uint256",internalType:"uint256"},{name:"valuesLength",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ERC1155InvalidOperator",inputs:[{name:"operator",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidReceiver",inputs:[{name:"receiver",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidSender",inputs:[{name:"sender",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155MissingApprovalForAll",inputs:[{name:"operator",type:"address",internalType:"address"},{name:"owner",type:"address",internalType:"address"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{name:"implementation",type:"address",internalType:"address"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"EmptyArray",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidChainId",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"InvalidPayment",inputs:[]},{type:"error",name:"InvalidReceiver",inputs:[]},{type:"error",name:"InvalidRegistry",inputs:[]},{type:"error",name:"InvalidSignature",inputs:[]},{type:"error",name:"InvalidTokenId",inputs:[]},{type:"error",name:"MaxSupplyExceeded",inputs:[]},{type:"error",name:"NonTransferableToken",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProjectOperator",inputs:[]},{type:"error",name:"PaymentRequired",inputs:[]},{type:"error",name:"ProjectHandleZero",inputs:[]},{type:"error",name:"RecipientUndefined",inputs:[]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SignatureExpired",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{name:"slot",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"Unauthorized",inputs:[]},{type:"error",name:"ZeroQuantity",inputs:[]}];import{Contract as Te,Interface as be}from"ethers";var H=[{type:"constructor",inputs:[],stateMutability:"nonpayable"},{type:"function",name:"DEFAULT_ADMIN_ROLE",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"UPGRADE_INTERFACE_VERSION",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"badgeToProject",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"balanceOf",inputs:[{name:"account",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"balanceOfBatch",inputs:[{name:"accounts",type:"address[]",internalType:"address[]"},{name:"ids",type:"uint256[]",internalType:"uint256[]"}],outputs:[{name:"",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"view"},{type:"function",name:"burnBatch",inputs:[{name:"from",type:"address",internalType:"address"},{name:"ids",type:"uint256[]",internalType:"uint256[]"},{name:"values",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"calculateProjectTokenId",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"projectTokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"pure"},{type:"function",name:"createBatch",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"_to",type:"address",internalType:"address"},{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"},{name:"_maxSupplies",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"createBatch",inputs:[{name:"_to",type:"address",internalType:"address"},{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"},{name:"_maxSupplies",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"eip712Domain",inputs:[],outputs:[{name:"fields",type:"bytes1",internalType:"bytes1"},{name:"name",type:"string",internalType:"string"},{name:"version",type:"string",internalType:"string"},{name:"chainId",type:"uint256",internalType:"uint256"},{name:"verifyingContract",type:"address",internalType:"address"},{name:"salt",type:"bytes32",internalType:"bytes32"},{name:"extensions",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"view"},{type:"function",name:"exists",inputs:[{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"getRoleAdmin",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"grantAdminRole",inputs:[{name:"admin",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"grantProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"grantRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"hasRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"initialize",inputs:[{name:"_defaultAdmin",type:"address",internalType:"address"},{name:"_name",type:"string",internalType:"string"},{name:"_symbol",type:"string",internalType:"string"},{name:"_version",type:"string",internalType:"string"},{name:"_baseURI",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"isApprovedForAll",inputs:[{name:"account",type:"address",internalType:"address"},{name:"operator",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"mintWithSignature",inputs:[{name:"_req",type:"tuple",internalType:"struct AnchorDataTypes.MintRequest",components:[{name:"to",type:"address",internalType:"address"},{name:"tokenId",type:"uint256",internalType:"uint256"},{name:"quantity",type:"uint256",internalType:"uint256"},{name:"price",type:"uint256",internalType:"uint256"},{name:"currency",type:"address",internalType:"address"},{name:"validityStartTimestamp",type:"uint128",internalType:"uint128"},{name:"validityEndTimestamp",type:"uint128",internalType:"uint128"},{name:"uid",type:"bytes32",internalType:"bytes32"},{name:"chainId",type:"uint256",internalType:"uint256"},{name:"projectHandle",type:"bytes32",internalType:"bytes32"}]},{name:"_signature",type:"bytes",internalType:"bytes"}],outputs:[{name:"signer",type:"address",internalType:"address"}],stateMutability:"payable"},{type:"function",name:"multicall",inputs:[{name:"data",type:"bytes[]",internalType:"bytes[]"}],outputs:[{name:"results",type:"bytes[]",internalType:"bytes[]"}],stateMutability:"nonpayable"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"nextTokenIdToMint",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"projectTotalSupply",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"proxiableUUID",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"renounceRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"callerConfirmation",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"revokeProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"revokeRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"safeBatchTransferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"ids",type:"uint256[]",internalType:"uint256[]"},{name:"values",type:"uint256[]",internalType:"uint256[]"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"safeTransferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"},{name:"value",type:"uint256",internalType:"uint256"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setApprovalForAll",inputs:[{name:"operator",type:"address",internalType:"address"},{name:"approved",type:"bool",internalType:"bool"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setMaxSupply",inputs:[{name:"_tokenId",type:"uint256",internalType:"uint256"},{name:"_maxSupply",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRegistry",inputs:[{name:"registry",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setURIs",inputs:[{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setup",inputs:[{name:"_name",type:"string",internalType:"string"},{name:"_symbol",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"supportsInterface",inputs:[{name:"interfaceId",type:"bytes4",internalType:"bytes4"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"pure"},{type:"function",name:"symbol",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"tokenReceived",inputs:[{name:"token",type:"address",internalType:"address"},{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"},{name:"userData",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"totalSupply",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"totalSupply",inputs:[{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"upgradeTo",inputs:[{name:"newImplementation",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"upgradeToAndCall",inputs:[{name:"newImplementation",type:"address",internalType:"address"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"payable"},{type:"function",name:"uri",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"version",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"event",name:"AnchorInitialized",inputs:[{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ApprovalForAll",inputs:[{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"approved",type:"bool",indexed:!1,internalType:"bool"}],anonymous:!1},{type:"event",name:"BatchBurned",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"BatchCreated",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"projectTokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"tokenURIs",type:"string[]",indexed:!1,internalType:"string[]"},{name:"maxSupply",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"BatchURI",inputs:[{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"tokenURIs",type:"string[]",indexed:!1,internalType:"string[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"EIP712DomainChanged",inputs:[],anonymous:!1},{type:"event",name:"Initialized",inputs:[{name:"version",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"MaxSupplyUpdated",inputs:[{name:"tokenId",type:"uint256",indexed:!1,internalType:"uint256"},{name:"maxSupply",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Minted",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"tokenId",type:"uint256",indexed:!0,internalType:"uint256"},{name:"quantity",type:"uint256",indexed:!1,internalType:"uint256"},{name:"price",type:"uint256",indexed:!1,internalType:"uint256"},{name:"currency",type:"address",indexed:!1,internalType:"address"},{name:"uid",type:"bytes32",indexed:!1,internalType:"bytes32"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ProjectOperatorGranted",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ProjectOperatorRevoked",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"RoleAdminChanged",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"previousAdminRole",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"newAdminRole",type:"bytes32",indexed:!0,internalType:"bytes32"}],anonymous:!1},{type:"event",name:"RoleGranted",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"RoleRevoked",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"TransferBatch",inputs:[{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"ids",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"}],anonymous:!1},{type:"event",name:"TransferSingle",inputs:[{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"uint256",indexed:!1,internalType:"uint256"},{name:"value",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"URI",inputs:[{name:"value",type:"string",indexed:!1,internalType:"string"},{name:"id",type:"uint256",indexed:!0,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Upgraded",inputs:[{name:"implementation",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"error",name:"AccessControlBadConfirmation",inputs:[]},{type:"error",name:"AccessControlUnauthorizedAccount",inputs:[{name:"account",type:"address",internalType:"address"},{name:"neededRole",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"AddressEmptyCode",inputs:[{name:"target",type:"address",internalType:"address"}]},{type:"error",name:"AddressNotSet",inputs:[]},{type:"error",name:"ArrayLengthMismatch",inputs:[]},{type:"error",name:"ECDSAInvalidSignature",inputs:[]},{type:"error",name:"ECDSAInvalidSignatureLength",inputs:[{name:"length",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ECDSAInvalidSignatureS",inputs:[{name:"s",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"ERC1155InsufficientBalance",inputs:[{name:"sender",type:"address",internalType:"address"},{name:"balance",type:"uint256",internalType:"uint256"},{name:"needed",type:"uint256",internalType:"uint256"},{name:"tokenId",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ERC1155InvalidApprover",inputs:[{name:"approver",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidArrayLength",inputs:[{name:"idsLength",type:"uint256",internalType:"uint256"},{name:"valuesLength",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ERC1155InvalidOperator",inputs:[{name:"operator",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidReceiver",inputs:[{name:"receiver",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidSender",inputs:[{name:"sender",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155MissingApprovalForAll",inputs:[{name:"operator",type:"address",internalType:"address"},{name:"owner",type:"address",internalType:"address"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{name:"implementation",type:"address",internalType:"address"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"EmptyArray",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidChainId",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"InvalidPayment",inputs:[]},{type:"error",name:"InvalidReceiver",inputs:[]},{type:"error",name:"InvalidRegistry",inputs:[]},{type:"error",name:"InvalidSignature",inputs:[]},{type:"error",name:"InvalidTokenId",inputs:[]},{type:"error",name:"MaxSupplyExceeded",inputs:[]},{type:"error",name:"NonTransferableToken",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProjectOperator",inputs:[]},{type:"error",name:"PaymentRequired",inputs:[]},{type:"error",name:"ProjectHandleZero",inputs:[]},{type:"error",name:"RecipientUndefined",inputs:[]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SignatureExpired",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{name:"slot",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"Unauthorized",inputs:[]},{type:"error",name:"ZeroQuantity",inputs:[]}];class J{static abi=H;static createInterface(){return new be(H)}static connect(e,n){return new Te(e,H,n)}}import{Contract as Fe,Interface as Le}from"ethers";class X{publicClient;walletClient;account;network;contracts;constructor(e,n,t,y,a){this.publicClient=e,this.network=n,this.walletClient=t,this.account=y,this.contracts=a||{}}async getTokenURI(e){if(!this.contracts?.anchorERC1155)throw Error("AnchorERC1155 contract address not set, please check network configuration");return await this.publicClient.readContract({address:this.contracts.anchorERC1155,abi:_,functionName:"uri",args:[e]})}async getName(){if(!this.contracts?.anchorERC1155)throw Error("AnchorERC1155 contract address not set, please check network configuration");return await this.publicClient.readContract({address:this.contracts.anchorERC1155,abi:_,functionName:"name"})}async getSymbol(){if(!this.contracts?.anchorERC1155)throw Error("AnchorERC1155 contract address not set, please check network configuration");return await this.publicClient.readContract({address:this.contracts.anchorERC1155,abi:_,functionName:"symbol"})}async mintWithSignature(e,n,t){if(BigInt(e.request.price)!==0n)throw Error("mintWithSignature method can only be used to mint free tokens");let y=n||this.contracts?.anchorERC1155,a=J.createInterface().encodeFunctionData("mintWithSignature",[this.formatMintRequest(e.request),e.signature]);if(console.log(a,"data"),t?.sendTransaction===!1)return{to:y,data:a,value:0n};if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let{maxFeePerGas:u,maxPriorityFeePerGas:l}=await this.publicClient.estimateFeesPerGas(),i=await this.publicClient.estimateGas({to:y,data:a,value:0n,account:this.account}),p=await this.walletClient.writeContract({account:this.account,address:y,abi:J.abi,functionName:"mintWithSignature",args:[this.formatMintRequest(e.request),e.signature],chain:this.publicClient.chain,maxFeePerGas:u,maxPriorityFeePerGas:l,gas:i});return await this.publicClient.waitForTransactionReceipt({hash:p})}encodeTokenReceivedData(e){let n=P(C("AnchorERC1155")),t=e.signature.startsWith("0x")?e.signature:`0x${e.signature}`,y=this.formatMintRequest(e.request);console.log("Formatted request data:",JSON.stringify(y,(u,l)=>typeof l==="bigint"?l.toString():l)),console.log("Signature:",t);let a=A([{components:[{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"quantity",type:"uint256"},{name:"price",type:"uint256"},{name:"currency",type:"address"},{name:"validityStartTimestamp",type:"uint128"},{name:"validityEndTimestamp",type:"uint128"},{name:"uid",type:"bytes32"},{name:"chainId",type:"uint256"},{name:"projectHandle",type:"bytes32"}],name:"req",type:"tuple"},{name:"signature",type:"bytes"}],[y,t]);return console.log("Encoded userData:",a),c([n,a])}encodeTokenReceivedDataWithEmptyInterface(e){let n=P(C("")),t=e.signature.startsWith("0x")?e.signature:`0x${e.signature}`,y=this.formatMintRequest(e.request);console.log("Formatted request data (empty interface):",JSON.stringify(y,(u,l)=>typeof l==="bigint"?l.toString():l)),console.log("Signature:",t);let a=A([{components:[{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"quantity",type:"uint256"},{name:"price",type:"uint256"},{name:"currency",type:"address"},{name:"validityStartTimestamp",type:"uint128"},{name:"validityEndTimestamp",type:"uint128"},{name:"uid",type:"bytes32"},{name:"chainId",type:"uint256"},{name:"projectHandle",type:"bytes32"}],name:"req",type:"tuple"},{name:"signature",type:"bytes"}],[y,t]);return console.log("Encoded userData (empty interface):",a),c([n,a])}async multicall(e,n){if(!this.contracts?.anchorERC1155)throw Error("AnchorERC1155 contract address not set, please check network configuration");let t=this.contracts.anchorERC1155,y=ve({abi:_,functionName:"multicall",args:[e]});if(n?.sendTransaction===!1)return{to:t,data:y,value:0n};if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let{maxFeePerGas:a,maxPriorityFeePerGas:u}=await this.publicClient.estimateFeesPerGas(),l=await this.publicClient.estimateGas({to:t,data:y,value:0n,account:this.account}),i=await this.walletClient.writeContract({account:this.account,address:t,abi:_,functionName:"multicall",args:[e],chain:this.publicClient.chain,maxFeePerGas:a,maxPriorityFeePerGas:u,gas:l});return await this.publicClient.waitForTransactionReceipt({hash:i})}formatMintRequest(e){let n;if(typeof e.uid==="string")if(e.uid.startsWith("0x"))n=e.uid;else n=P(C(e.uid));else n=e.uid;let t=BigInt(Math.floor(Date.now()/1000));return{to:e.to,tokenId:BigInt(e.tokenId),quantity:BigInt(e.quantity),price:BigInt(e.price),currency:e.currency,validityStartTimestamp:e.validityStartTimestamp?BigInt(e.validityStartTimestamp):t,validityEndTimestamp:e.validityEndTimestamp?BigInt(e.validityEndTimestamp):e.validUntil?BigInt(e.validUntil):t+3600n,uid:n,chainId:BigInt(e.chainId||this.network.id),projectHandle:e.projectHandle}}}var xe;((u)=>{u.Json="application/json";u.JsonApi="application/vnd.api+json";u.FormData="multipart/form-data";u.UrlEncoded="application/x-www-form-urlencoded";u.Text="text/plain"})(xe||={});class R{baseUrl="https://anchordev.dipbit.xyz/";securityData=null;securityWorker;abortControllers=new Map;customFetch=(...e)=>fetch(...e);baseApiParams={credentials:"same-origin",headers:{},redirect:"follow",referrerPolicy:"no-referrer"};constructor(e={}){Object.assign(this,e)}setSecurityData=(e)=>{this.securityData=e};encodeQueryParam(e,n){return`${encodeURIComponent(e)}=${encodeURIComponent(typeof n==="number"?n:`${n}`)}`}addQueryParam(e,n){return this.encodeQueryParam(n,e[n])}addArrayQueryParam(e,n){return e[n].map((y)=>this.encodeQueryParam(n,y)).join("&")}toQueryString(e){let n=e||{};return Object.keys(n).filter((y)=>typeof n[y]<"u").map((y)=>Array.isArray(n[y])?this.addArrayQueryParam(n,y):this.addQueryParam(n,y)).join("&")}addQueryParams(e){let n=this.toQueryString(e);return n?`?${n}`:""}contentFormatters={["application/json"]:(e)=>e!==null&&(typeof e==="object"||typeof e==="string")?JSON.stringify(e):e,["application/vnd.api+json"]:(e)=>e!==null&&(typeof e==="object"||typeof e==="string")?JSON.stringify(e):e,["text/plain"]:(e)=>e!==null&&typeof e!=="string"?JSON.stringify(e):e,["multipart/form-data"]:(e)=>{if(e instanceof FormData)return e;return Object.keys(e||{}).reduce((n,t)=>{let y=e[t];return n.append(t,y instanceof Blob?y:typeof y==="object"&&y!==null?JSON.stringify(y):`${y}`),n},new FormData)},["application/x-www-form-urlencoded"]:(e)=>this.toQueryString(e)};mergeRequestParams(e,n){return{...this.baseApiParams,...e,...n||{},headers:{...this.baseApiParams.headers||{},...e.headers||{},...n&&n.headers||{}}}}createAbortSignal=(e)=>{if(this.abortControllers.has(e)){let t=this.abortControllers.get(e);if(t)return t.signal;return}let n=new AbortController;return this.abortControllers.set(e,n),n.signal};abortRequest=(e)=>{let n=this.abortControllers.get(e);if(n)n.abort(),this.abortControllers.delete(e)};request=async({body:e,secure:n,path:t,type:y,query:a,format:u,baseUrl:l,cancelToken:i,...p})=>{let m=(typeof n==="boolean"?n:this.baseApiParams.secure)&&this.securityWorker&&await this.securityWorker(this.securityData)||{},T=this.mergeRequestParams(p,m),r=a&&this.toQueryString(a),b=this.contentFormatters[y||"application/json"],z=u||T.format;return this.customFetch(`${l||this.baseUrl||""}${t}${r?`?${r}`:""}`,{...T,headers:{...T.headers||{},...y&&y!=="multipart/form-data"?{"Content-Type":y}:{}},signal:(i?this.createAbortSignal(i):T.signal)||null,body:typeof e>"u"||e===null?null:b(e)}).then(async(O)=>{let x=O;x.data=null,x.error=null;let d=!z?x:await O[z]().then((v)=>{if(x.ok)x.data=v;else x.error=v;return x}).catch((v)=>{return x.error=v,x});if(i)this.abortControllers.delete(i);if(!O.ok)throw d;return d})}}class G extends R{s1={queryAssets:(e,n,t={})=>this.request({path:`/s1/assets/${e}`,method:"POST",body:n,type:"application/json",format:"json",...t}),grantBadge:(e,n={})=>this.request({path:"/s1/badges",method:"POST",body:e,type:"application/json",format:"json",...n}),badgesCheck:(e,n={})=>this.request({path:"/s1/badges/check",method:"POST",body:e,type:"application/json",format:"json",...n}),queryBadgesHolders:(e,n={})=>this.request({path:"/s1/badges/holders",method:"GET",query:e,format:"json",...n}),checkByEvent:(e,n={})=>this.request({path:"/s1/check/event",method:"POST",body:e,type:"application/json",format:"json",...n}),intervalReset:(e,n={})=>this.request({path:"/s1/interval/reset",method:"POST",body:e,type:"application/json",format:"json",...n}),getUserNftHoldingByDuration:(e,n={})=>this.request({path:"/s1/nft/holding-by-duration",method:"POST",body:e,type:"application/json",format:"json",...n}),purchaseMint:(e,n,t={})=>this.request({path:`/s1/purchase/${e}`,method:"POST",body:n,type:"application/json",format:"json",...t}),getNftSeriesDetail:(e,n,t,y={})=>this.request({path:`/s1/series/${e}/${n}`,method:"GET",query:t,format:"json",...y}),createTeam:(e,n={})=>this.request({path:"/s1/teams",method:"POST",body:e,type:"application/json",format:"json",...n}),teamDetail:(e,n={})=>this.request({path:`/s1/teams/detail/${e}`,method:"GET",format:"json",...n}),joinTeam:(e,n={})=>this.request({path:"/s1/teams/join",method:"POST",body:e,type:"application/json",format:"json",...n}),leaveTeam:(e,n={})=>this.request({path:`/s1/teams/leave/${e}`,method:"DELETE",format:"json",...n}),removeTeamMember:(e,n,t={})=>this.request({path:`/s1/teams/remove/${e}/${n}`,method:"DELETE",format:"json",...t}),updateTeamType:(e,n,t={})=>this.request({path:`/s1/teams/update/type/${e}`,method:"POST",query:n,format:"json",...t}),getTokenBalances:(e,n={})=>this.request({path:"/s1/token/balances",method:"POST",body:e,type:"application/json",format:"json",...n})};v1={badgeAssets:(e,n={})=>this.request({path:"/v1/badges",method:"GET",query:e,format:"json",...n}),getCheckResult:(e,n={})=>this.request({path:`/v1/check/${e}`,method:"GET",format:"json",...n}),check:(e,n={})=>this.request({path:`/v1/check/${e}`,method:"POST",format:"json",...n}),getNotifications:(e,n={})=>this.request({path:"/v1/notifications",method:"GET",query:e,format:"json",...n}),markNotificationRead:(e,n={})=>this.request({path:`/v1/notifications/${e}/read`,method:"POST",format:"json",...n}),listSeasonConfig:(e={})=>this.request({path:"/v1/seasons",method:"GET",format:"json",...e}),nftSeries:(e,n={})=>this.request({path:`/v1/series/${e}`,method:"GET",format:"json",...n}),getNftSeriesById:(e,n,t,y={})=>this.request({path:`/v1/series/${e}/${n}`,method:"GET",query:t,format:"json",...y}),getTeamBadges:(e,n={})=>this.request({path:"/v1/teams/badges",method:"GET",query:e,format:"json",...n}),getBadgeContributors:(e,n={})=>this.request({path:`/v1/teams/badges/${e}/contributors`,method:"GET",format:"json",...n}),getTeamLeaderboard:(e,n={})=>this.request({path:"/v1/teams/leaderboard",method:"GET",query:e,format:"json",...n}),getMyTeamProfile:(e={})=>this.request({path:"/v1/teams/members/me",method:"GET",format:"json",...e}),getTeamDetail:(e,n={})=>this.request({path:`/v1/teams/${e}/detail`,method:"GET",format:"json",...n}),getTeamMemberRanking:(e,n,t={})=>this.request({path:`/v1/teams/${e}/members/ranking`,method:"GET",query:n,format:"json",...t}),userOpHashProcess:(e,n={})=>this.request({path:"/v1/transaction/process/userOpHash",method:"POST",body:e,type:"application/json",format:"json",...n}),transactionHashProcess:(e,n={})=>this.request({path:`/v1/transaction/process/${e}`,method:"POST",format:"json",...n})};v2={queryBadges:(e,n={})=>this.request({path:"/v2/badges",method:"GET",query:e,format:"json",...n}),checkUserClaimableBadges:(e,n={})=>this.request({path:"/v2/badges",method:"POST",body:e,type:"application/json",format:"json",...n}),getUserBadgeAssets:(e,n={})=>this.request({path:"/v2/badges/assets",method:"GET",query:e,format:"json",...n}),categoriesList:(e,n={})=>this.request({path:"/v2/badges/categories",method:"GET",query:e,format:"json",...n}),categoriesDetail:(e,n,t={})=>this.request({path:`/v2/badges/categories/${e}`,method:"GET",query:n,format:"json",...t}),getUserClaimableBadges:(e,n={})=>this.request({path:"/v2/badges/claimable",method:"GET",query:e,format:"json",...n}),getBadgeSeries:(e,n={})=>this.request({path:"/v2/badges/series",method:"GET",query:e,format:"json",...n}),getBadgeSeriesDetail:(e,n,t={})=>this.request({path:`/v2/badges/series/${e}`,method:"GET",query:n,format:"json",...t}),getBadgeClaimSignatures:(e,n={})=>this.request({path:"/v2/badges/signatures",method:"POST",body:e,type:"application/json",format:"json",...n}),getBadgeVerifiers:(e,n={})=>this.request({path:"/v2/badges/verifiers",method:"GET",query:e,format:"json",...n}),getBadgeDetail:(e,n={})=>this.request({path:`/v2/badges/${e}`,method:"GET",format:"json",...n}),checkSingleBadgeClaimable:(e,n,t={})=>this.request({path:`/v2/badges/${e}`,method:"POST",body:n,type:"application/json",format:"json",...t}),batchMint:(e,n,t={})=>this.request({path:`/v2/batch/mint/${e}`,method:"POST",body:n,type:"application/json",format:"json",...t}),mint:(e,n,t={})=>this.request({path:`/v2/mint/${e}`,method:"POST",body:n,type:"application/json",format:"json",...t})}}class Q{generatedApi;network;authToken;projectId;chainId;onTokenExpired;constructor(e){this.network=e.network,this.authToken=e.authToken,this.projectId=e.projectId,this.chainId=e.network.id.toString(),this.onTokenExpired=e.onTokenExpired,this.generatedApi=new G({baseUrl:e.apiBaseUrl.endsWith("/")?e.apiBaseUrl.slice(0,-1):e.apiBaseUrl})}setAuthToken(e){this.authToken=e}setTokenExpiredCallback(e){this.onTokenExpired=e}setProjectId(e){this.projectId=e}setChainId(e){this.chainId=e}createHeaders(){let e={"Content-Type":"application/json"};if(this.authToken)e.Authorization=`Bearer ${this.authToken}`,e.jwt_token=`${this.authToken}`;if(this.projectId)e["X-Project-Id"]=this.projectId,e.saas_id=this.projectId;if(this.chainId)e["X-Chain-Id"]=this.chainId,e.chain_id=this.chainId;return e}getRequestParams(){return{headers:this.createHeaders()}}async handleApiCall(e){try{let n=await e();if(this.isTokenExpiredResponse(n)){console.log("Token expired: JWT token is invalid or expired");let t=Error("Token expired: JWT token is invalid or expired");if(this.onTokenExpired)this.onTokenExpired(t);throw t}return n}catch(n){if(n?.status===401){if(this.onTokenExpired)this.onTokenExpired(n)}throw n}}isTokenExpiredResponse(e){if(e?.success===!1&&e?.code==="9101")return!0;if(e?.success===!1&&e?.msgKey==="params.jwt.check.invalid")return!0;return!1}async getBadgeVerifiers(e,n){return this.handleApiCall(async()=>{let t={platform:e,type:n};return(await this.generatedApi.v2.getBadgeVerifiers(t,this.getRequestParams())).data})}async getUserClaimableBadges(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getUserClaimableBadges(e,this.getRequestParams())).data})}async getUserBadgeAssets(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getUserBadgeAssets(e,this.getRequestParams())).data})}async getBadgeSeriesDetail(e,n){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getBadgeSeriesDetail(e,n,this.getRequestParams())).data})}async getBadgeDetail(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getBadgeDetail(e,this.getRequestParams())).data})}async checkSingleBadgeClaimable(e,n){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.checkSingleBadgeClaimable(e,n,this.getRequestParams())).data})}async checkUserClaimableBadges(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.checkUserClaimableBadges(e,this.getRequestParams())).data})}async queryBadges(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.queryBadges(e,this.getRequestParams())).data})}async categoriesDetail(e,n){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.categoriesDetail(e,n,this.getRequestParams())).data})}async categoriesList(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.categoriesList(e,this.getRequestParams())).data})}async getBadgeClaimSignatures(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getBadgeClaimSignatures(e,this.getRequestParams())).data})}async getBadgeSeries(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getBadgeSeries(e,this.getRequestParams())).data})}async mint(e,n){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.mint(e,n,this.getRequestParams())).data})}async batchMint(e,n){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.batchMint(e,n,this.getRequestParams())).data})}async transactionHashProcess(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v1.transactionHashProcess(e,this.getRequestParams())).data})}async userOpHashProcess(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v1.userOpHashProcess(e,this.getRequestParams())).data})}}import Me,{createContext as we,useContext as Ue,useEffect as je,useState as N}from"react";var q=we(void 0);function Oe({children:e,config:n}){let[t,y]=N(null),[a,u]=N(!0),[l,i]=N(null),[p,m]=N(!1);je(()=>{try{let d=new F(n);y(d),m(!0),i(null)}catch(d){i(d instanceof Error?d:Error("初始化 Anchor SDK 失败"))}finally{u(!1)}},[n.publicClient,n.walletClient,n.network.id,n.apiBaseUrl,n.authToken,n.projectId,n.env,n.anchorERC1155Address,n.anchorPayAddress]);let x={sdk:t,loading:a,error:l,initialized:p,setWalletClient:(d)=>{if(!t)throw Error("Anchor SDK not initialized");t.setWalletClient(d),y(t)},buyBadgeWithETH:async(d,v,S,V=1,B,s)=>{if(!t)throw Error("Anchor SDK not initialized");return await t.buyBadgeWithETH(d,v,S,V,B,s)},buyBadgeWithERC20:async(d,v,S,V=1,B,s,ae)=>{if(!t)throw Error("Anchor SDK not initialized");return await t.buyBadgeWithERC20(d,v,S,V,B,s,ae)},buyBadgeWithETHWithSignedRequest:async(d,v,S)=>{if(!t)throw Error("Anchor SDK not initialized");return await t.buyBadgeWithETHWithSignedRequest(d,v,S)},buyBadgeWithERC20WithSignedRequest:async(d,v,S)=>{if(!t)throw Error("Anchor SDK not initialized");return await t.buyBadgeWithERC20WithSignedRequest(d,v,S)}};return Me.createElement(q.Provider,{value:x},e)}var ee=()=>{let e=Ue(q);if(e===void 0)throw Error("useAnchorSDK must be used inside AnchorReactProvider");return e},ze=()=>{let{sdk:e,loading:n,error:t,initialized:y}=ee();return{loading:n,error:t,initialized:y,getClaimableBadges:async()=>{if(!e?.anchorApi)throw Error("Anchor API client not initialized");return await e.anchorApi.getUserBadgeAssets({includeClaimable:!0,strategy:"BADGE_ALL"})},getClaimedBadges:async()=>{if(!e?.anchorApi)throw Error("Anchor API client not initialized");return await e.anchorApi.getUserBadgeAssets({includeClaimable:!1,strategy:"BADGE_ALL"})},getNftSeries:async()=>{if(!e?.anchorApi)throw Error("Anchor API client not initialized");return await e.anchorApi.getBadgeSeries({includeBadges:!0,limit:100})},getNftSeriesById:async(p)=>{if(!e?.anchorApi)throw Error("Anchor API client not initialized");return await e.anchorApi.getBadgeSeriesDetail(p,{status:"active"})}}};class F{publicClient;walletClient;account;network;config;contracts;anchorPay;anchorERC1155;anchorApi;constructor(e){if(this.config=e,this.contracts={},"publicClient"in e&&e.publicClient)this.publicClient=e.publicClient,this.walletClient=e.walletClient,this.account=this.walletClient?.account,this.network=this.createChainFromNetwork(e.network);else{this.network=this.createChainFromNetwork(e.network),this.publicClient=this.initializePublicClient(e.provider);let t=e.signer||e.provider;this.walletClient=t?this.initializeWalletClient(t):void 0,this.account=this.walletClient?.account||this.getAccountFromSigner(t)}if(e.anchorPayAddress)this.contracts.anchorPay=e.anchorPayAddress;if(e.anchorERC1155Address)this.contracts.anchorERC1155=e.anchorERC1155Address;this.anchorPay=new Z(this.publicClient,this.network,this.walletClient,this.account,this.contracts),this.anchorERC1155=new X(this.publicClient,this.network,this.walletClient,this.account,this.contracts);let n=e.apiBaseUrl;if(e.env&&Y[e.env]){if(!n)n=Y[e.env].apiBaseUrl;if(this.network.id&&Y[e.env].contracts[this.network.id]){let t=Y[e.env].contracts[this.network.id];if(!t)throw Error("no contracts");if(t.anchorPay&&!this.contracts.anchorPay)this.contracts.anchorPay=t.anchorPay;if(t.anchorERC1155&&!this.contracts.anchorERC1155)this.contracts.anchorERC1155=t.anchorERC1155;this.anchorPay=new Z(this.publicClient,this.network,this.walletClient,this.account,this.contracts),this.anchorERC1155=new X(this.publicClient,this.network,this.walletClient,this.account,this.contracts)}}if(n)this.anchorApi=new Q({apiBaseUrl:n,authToken:e.authToken,projectId:e.projectId,network:this.network,onTokenExpired:e.onTokenExpired})}setTokenExpiredCallback(e){if(this.anchorApi)this.anchorApi.setTokenExpiredCallback(e)}setWalletClient(e){if(e&&"account"in e)this.walletClient=e,this.account=e.account;else{let n=e||this.config.provider;this.walletClient=this.initializeWalletClient(n),this.account=this.walletClient?.account||this.getAccountFromSigner(n)}return this.anchorPay=new Z(this.publicClient,this.network,this.walletClient,this.account,this.contracts),this.anchorERC1155=new X(this.publicClient,this.network,this.walletClient,this.account,this.contracts),console.log("SDK wallet client updated:",this.account),this}initializePublicClient(e){if(typeof e==="string")return ne({chain:this.network,transport:Ie(e)});if(e&&typeof e==="object")return ne({chain:this.network,transport:L(e)});throw Error("Invalid provider. Please provide a valid RPC URL or Web3 Provider.")}initializeWalletClient(e){if(!e)return;if(e&&typeof e==="object"){if(e.selectedAddress)return te({chain:this.network,transport:L(e),account:e.selectedAddress});if(e.address)return te({chain:this.network,transport:L(e.provider||e),account:e.address})}return}getAccountFromSigner(e){if(!e)return;if(e.selectedAddress)return{address:e.selectedAddress,type:"json-rpc"};if(e.address)return{address:e.address,type:"json-rpc"};return}createChainFromNetwork(e){return{...e,nativeCurrency:e.nativeCurrency||{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:[typeof this.config.provider==="string"?this.config.provider:""]},public:{http:[typeof this.config.provider==="string"?this.config.provider:""]}}}}async buyBadgeWithETHWithSignedRequest(e,n,t){if(!e||!e.request||!e.signature)throw Error("signedRequest is required and must contain request and signature");if(!n||!f(n))throw Error("receiptAddress is required and must be a valid Ethereum address");if(t?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");if(this.validateMintRequest(e.request),e.request.currency!==I)throw Error("Currency must be ETH");let y=BigInt(e.request.price)*BigInt(e.request.quantity),a=this.anchorERC1155.encodeTokenReceivedData(e),u=await this.anchorPay.sendETH(n,y,a,t);if(t?.sendTransaction!==!1&&u&&typeof u==="object"&&"transactionHash"in u)try{await this.processTransactionHash(u.transactionHash)}catch(l){console.warn(`Failed to process transaction hash: ${l instanceof Error?l.message:String(l)}`)}return u}async buyBadgeWithERC20WithSignedRequest(e,n,t){if(!e||!e.request||!e.signature)throw Error("signedRequest is required and must contain request and signature");if(!n||!f(n))throw Error("receiptAddress is required and must be a valid Ethereum address");if(t?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");if(this.validateMintRequest(e.request),e.request.currency===I)throw Error("Currency cannot be native token");let y=BigInt(e.request.price)*BigInt(e.request.quantity),a=this.anchorERC1155.encodeTokenReceivedData(e),u=await this.anchorPay.sendERC20(n,e.request.currency,y,a,t);if(t?.sendTransaction!==!1&&u&&typeof u==="object"&&"transactionHash"in u)try{await this.processTransactionHash(u.transactionHash)}catch(l){console.warn(`Failed to process transaction hash: ${l instanceof Error?l.message:String(l)}`)}return u}async buyBadgeWithETH(e,n,t,y=1,a,u){if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!a||!f(a))throw Error("receiptAddress is required and must be a valid Ethereum address");if(t===void 0||t==="")throw Error("tokenId is required");if(BigInt(y.toString())<=0n)throw Error("quantity must be greater than 0");if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(u?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let i=[`${t.toString()}`],p=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:i});if(p.code!=="0000"||!p.obj||!p.obj.signatures||p.obj.signatures.length===0)throw Error(p.code||"Failed to get mint request from backend");let m=p.obj.signatures[0];if(!m)throw Error("Mint request missing required fields");let T={request:{to:e,tokenId:BigInt(m.badgeId||t),quantity:BigInt(m.quantity||y),price:BigInt(m.price||0),currency:m.currency,validityStartTimestamp:BigInt(m.validityStartTimestamp||Math.floor(Date.now()/1000)),validityEndTimestamp:BigInt(m.validityEndTimestamp||Math.floor(Date.now()/1000)+3600),uid:m.uid,chainId:BigInt(m.chainId||this.network.id),projectHandle:m.projectHandle},signature:m.signature};return await this.buyBadgeWithETHWithSignedRequest(T,a,u)}async buyBadgeWithETHWithCustomSignature(e,n,t){if(!e)throw Error("signedRequest is required");if(!e.to||!f(e.to))throw Error("signedRequest.to is required and must be a valid Ethereum address");if(e.tokenId===void 0||e.tokenId==="")throw Error("signedRequest.tokenId is required");if(e.quantity===void 0||BigInt(e.quantity.toString())<=0n)throw Error("signedRequest.quantity is required and must be greater than 0");if(e.price===void 0)throw Error("signedRequest.price is required");if(!e.uid)throw Error("signedRequest.uid is required");if(!e.signature)throw Error("signedRequest.signature is required");if(!e.chainId)throw Error("signedRequest.chainId is required");if(!n||!f(n))throw Error("receiptAddress is required and must be a valid Ethereum address");let y={request:{to:e.to,tokenId:BigInt(e.tokenId),quantity:BigInt(e.quantity),price:BigInt(e.price),currency:e.currency,validityStartTimestamp:BigInt(e.validityStartTimestamp||Math.floor(Date.now()/1000)+3600),validityEndTimestamp:BigInt(e.validityEndTimestamp||Math.floor(Date.now()/1000)+3600),uid:e.uid,chainId:BigInt(e.chainId||this.network.id),projectHandle:e.projectHandle},signature:e.signature.startsWith("0x")?e.signature:`0x${e.signature}`};return await this.buyBadgeWithETHWithSignedRequest(y,n,t)}async buyBadgeWithERC20(e,n,t,y=1,a,u,l){if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(l?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!u||!f(u))throw Error("receiptAddress is required and must be a valid Ethereum address");if(!a||!f(a))throw Error("currency is required and must be a valid ERC20 token address");if(t===void 0||t==="")throw Error("tokenId is required");if(BigInt(y.toString())<=0n)throw Error("quantity must be greater than 0");let p=[`${t.toString()}`],m=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:p});if(m.code!=="0000"||!m.obj||!m.obj.signatures||m.obj.signatures.length===0)throw Error(m.code||"Failed to get mint request from backend");let T=m.obj.signatures[0];if(!T)throw Error("Mint request missing required fields");if(!T.badgeId||!T.signature||!T.validityStartTimestamp||!T.validityEndTimestamp)throw Error("Mint request missing required fields");let r={request:{to:e,tokenId:BigInt(T.badgeId||t),quantity:BigInt(T.quantity||y),price:BigInt(T.price||0),currency:T.currency,validityStartTimestamp:BigInt(T.validityStartTimestamp||Math.floor(Date.now()/1000)),validityEndTimestamp:BigInt(T.validityEndTimestamp||Math.floor(Date.now()/1000)+3600),uid:T.uid,chainId:BigInt(T.chainId||this.network.id),projectHandle:T.projectHandle},signature:T.signature};return await this.buyBadgeWithERC20WithSignedRequest(r,u,l)}async buyBadgeWithERC20WithCustomSignature(e,n,t){if(!e)throw Error("signedRequest is required");if(!e.to||!f(e.to))throw Error("signedRequest.to is required and must be a valid Ethereum address");if(e.tokenId===void 0||e.tokenId==="")throw Error("signedRequest.tokenId is required");if(e.quantity===void 0||BigInt(e.quantity.toString())<=0n)throw Error("signedRequest.quantity is required and must be greater than 0");if(e.price===void 0)throw Error("signedRequest.price is required");if(!e.uid)throw Error("signedRequest.uid is required");if(!e.signature)throw Error("signedRequest.signature is required");if(!e.chainId)throw Error("signedRequest.chainId is required");if(!n||!f(n))throw Error("receiptAddress is required and must be a valid Ethereum address");let y={request:{to:e.to,tokenId:BigInt(e.tokenId),quantity:BigInt(e.quantity),price:BigInt(e.price),currency:e.currency,validityStartTimestamp:BigInt(e.validityStartTimestamp||Math.floor(Date.now()/1000)+3600),validityEndTimestamp:BigInt(e.validityEndTimestamp||Math.floor(Date.now()/1000)+3600),uid:e.uid,chainId:BigInt(e.chainId||this.network.id),projectHandle:e.projectHandle},signature:e.signature.startsWith("0x")?e.signature:`0x${e.signature}`};return await this.buyBadgeWithERC20WithSignedRequest(y,n,t)}async pay(e,n,t,y){if(!e||e.trim()==="")throw Error("orderId is required and cannot be empty");if(!t||!f(t))throw Error("receiptAddress is required and must be a valid Ethereum address");if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=typeof n==="string"||typeof n==="number"?ye(n.toString()):n,u=this.encodeUserData(e),l=K({abi:w,functionName:"send",args:[t,I,a,u]});if(y?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:l,value:a};let i=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:l,value:a}),p=await this.publicClient.waitForTransactionReceipt({hash:i});if(p&&typeof p==="object"&&"transactionHash"in p)try{await this.processTransactionHash(p.transactionHash)}catch(m){console.warn(`Failed to process transaction hash: ${m instanceof Error?m.message:String(m)}`)}return p}async sendPaymentWithNativeToken(e){let{callData:n,amount:t,receiptAddress:y,contractName:a,options:u}=e;if(!n||n.trim()==="")throw Error("callData is required and cannot be empty");if(!y||!f(y))throw Error("receiptAddress is required and must be a valid Ethereum address");if(u?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let l=typeof t==="string"||typeof t==="number"?ye(t.toString()):t,i=h(W(a||"")),p=E([i,n]),m=K({abi:w,functionName:"send",args:[y,I,l,p]});if(u?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:m,value:l};let T=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:m,value:l}),r=await this.publicClient.waitForTransactionReceipt({hash:T});if(r&&typeof r==="object"&&"transactionHash"in r)try{await this.processTransactionHash(r.transactionHash)}catch(b){console.warn(`Failed to process transaction hash: ${b instanceof Error?b.message:String(b)}`)}return r}async sendPaymentWithERC20(e){let{callData:n,amount:t,receiptAddress:y,tokenAddress:a,contractName:u,options:l}=e;if(!n||n.trim()==="")throw Error("callData is required and cannot be empty");if(!y||!f(y))throw Error("receiptAddress is required and must be a valid Ethereum address");if(!a||!f(a))throw Error("tokenAddress is required and must be a valid Ethereum address");let i=await this.publicClient.readContract({address:a,abi:U,functionName:"decimals"}),p=typeof t==="bigint"?t:BigInt(Math.floor(Number(t)*10**i)),m=h(W(u||""));console.log(`Interface hash: ${m}`);let T=E([m,n]);console.log(`callData: ${n}`),console.log(`Data: ${T}`);let r=await this.anchorPay.sendERC20(y,a,p,T,l);if(r&&typeof r==="object"&&"transactionHash"in r)try{await this.processTransactionHash(r.transactionHash)}catch(b){console.warn(`Failed to process transaction hash ${r.transactionHash} with Anchor API: ${b}`)}return r}encodeUserData(e){let n=h(W(""));console.log(n,"interfaceHash");let t=W(e);return console.log(E([n,t]),"concat"),E([n,t])}async mintFreeBadge(e,n,t,y){if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!t||!Array.isArray(t)||t.length===0)throw Error("tokenIds is required and must be a non-empty array");for(let l of t)if(!l||typeof l!=="string")throw Error("Each tokenId must be a non-empty string");if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:t});if(console.log(JSON.stringify(a)),a.code!=="0000"||!a.obj||!a.obj.signatures||a.obj.signatures.length===0)throw Error(a.code||"Failed to get mint request from backend");if(y?.sendTransaction===!1){let l=a.obj.signatures;return await Promise.all(l.map(async(p)=>{if(!p.badgeId||!p.signature||!p.validityStartTimestamp||!p.validityEndTimestamp)throw Error("Mint request missing required fields");let m={request:{to:e,tokenId:BigInt(p.badgeId),quantity:BigInt(p.quantity||1),price:BigInt(p.price||0),currency:p.currency,validityStartTimestamp:BigInt(p.validityStartTimestamp),validityEndTimestamp:BigInt(p.validityEndTimestamp),uid:p.uid,chainId:BigInt(p.chainId||this.network.id),projectHandle:p.projectHandle},signature:p.signature};if(this.validateMintRequest(m.request),BigInt(m.request.price)!==0n)throw Error("Free Badge price must be 0");return await this.anchorERC1155.mintWithSignature(m,n,{sendTransaction:!1})}))}let u=null;for(let l of a.obj.signatures){if(!l.badgeId||!l.signature||!l.validityStartTimestamp||!l.validityEndTimestamp){console.warn("铸造请求缺失必要字段",l);continue}let i={request:{to:e,tokenId:BigInt(l.badgeId),quantity:BigInt(l.quantity||1),price:BigInt(l.price||0),currency:l.currency,validityStartTimestamp:BigInt(l.validityStartTimestamp),validityEndTimestamp:BigInt(l.validityEndTimestamp),uid:l.uid,chainId:BigInt(l.chainId||this.network.id),projectHandle:l.projectHandle},signature:l.signature};if(this.validateMintRequest(i.request),BigInt(i.request.price)!==0n)throw Error("Free Badge price must be 0");console.log(i,"signedRequest");let p=await this.anchorERC1155.mintWithSignature(i,n,{sendTransaction:!0});if("transactionHash"in p){u=p;try{await this.processTransactionHash(p.transactionHash)}catch(m){console.warn(`Failed to process transaction hash: ${m instanceof Error?m.message:String(m)}`)}}else throw Error("Expected transaction receipt, but received transaction data")}if(!u)throw Error("No successful mint transaction");return u}async mintFreeBadgeWithSignedRequest(e,n){if(this.validateMintRequest(e.request),BigInt(e.request.price)!==0n)throw Error("Free Badge price must be 0");let t=await this.anchorERC1155.mintWithSignature(e,e?.request?.contractAddress,n);if(n?.sendTransaction!==!1&&t&&typeof t==="object"&&"transactionHash"in t)try{await this.processTransactionHash(t.transactionHash)}catch(y){console.warn(`Failed to process transaction hash: ${y instanceof Error?y.message:String(y)}`)}return t}getERC20ApprovalData(e,n,t){return this.anchorPay.getERC20ApprovalData(e,n,t)}validateMintRequest(e){if(!f(e.to))throw Error("Invalid recipient address");let n=Math.floor(Date.now()/1000),t=e.validityEndTimestamp;if(t&&BigInt(t)<BigInt(n))throw Error("Mint request expired");if(BigInt(e.quantity)<=0n)throw Error("Quantity must be greater than 0")}async processTransactionHash(e){try{if(this.anchorApi){let n=await this.anchorApi.transactionHashProcess(e);return console.log(`Transaction processing accelerated: ${e}`),n}}catch(n){console.warn(`Failed to accelerate transaction processing: ${n instanceof Error?n.message:String(n)}`)}return}async batchMintBadge(e,n,t,y){if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!Array.isArray(t)||t.length===0)throw Error("tokenIds is required and must be a non-empty array");for(let i of t)if(!i||typeof i!=="string")throw Error("Each tokenId must be a non-empty string");if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:t});if(a.code!=="0000"||!a.obj||!a.obj.signatures||a.obj.signatures.length===0)throw Error(a.code||"Failed to get batch mint request from backend");let u=a.obj.signatures;if(y?.sendTransaction===!1)return await Promise.all(u.map(async(p)=>{if(!p.badgeId||!p.signature||!p.validityStartTimestamp||!p.validityEndTimestamp)throw Error("Mint request missing required fields");let m={request:{to:e,tokenId:BigInt(p.badgeId),quantity:BigInt(p.quantity||1),price:BigInt(p.price||0),currency:p.currency,validityStartTimestamp:BigInt(p.validityStartTimestamp),validityEndTimestamp:BigInt(p.validityEndTimestamp),uid:p.uid,chainId:BigInt(p.chainId||this.network.id),projectHandle:p.projectHandle},signature:p.signature};return this.validateMintRequest(m.request),await this.anchorERC1155.mintWithSignature(m,n,{sendTransaction:!1})}));let l=null;for(let i of u){if(!i.badgeId||!i.signature||!i.validityStartTimestamp||!i.validityEndTimestamp){console.warn("铸造请求缺失必要字段",i);continue}let p={request:{to:e,tokenId:BigInt(i.badgeId),quantity:BigInt(i.quantity||1),price:BigInt(i.price||0),currency:i.currency,validityStartTimestamp:BigInt(i.validityStartTimestamp),validityEndTimestamp:BigInt(i.validityEndTimestamp),uid:i.uid,chainId:BigInt(i.chainId||this.network.id),projectHandle:i.projectHandle},signature:i.signature};this.validateMintRequest(p.request);let m=await this.anchorERC1155.mintWithSignature(p,n,{sendTransaction:!0});if("transactionHash"in m){l=m;try{await this.processTransactionHash(m.transactionHash)}catch(T){console.warn(`Failed to process transaction hash: ${T instanceof Error?T.message:String(T)}`)}}else throw Error("Expected transaction receipt, but received transaction data")}if(!l)throw Error("No successful mint transaction");return l}async batchMintBadgeWithMulticall(e,n,t,y){if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!Array.isArray(t)||t.length===0)throw Error("tokenIds is required and must be a non-empty array");if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:t});if(a.code!=="0000"||!a.obj||!a.obj.signatures||a.obj.signatures.length===0)throw Error(a.code||"Failed to get batch mint request from backend");let l=a.obj.signatures.map((p)=>{if(!p.badgeId||!p.signature||!p.validityStartTimestamp||!p.validityEndTimestamp)throw Error("Mint request missing required fields");let m={request:{to:e,tokenId:BigInt(p.badgeId),quantity:BigInt(p.quantity||1),price:BigInt(p.price||0),currency:p.currency,validityStartTimestamp:BigInt(p.validityStartTimestamp),validityEndTimestamp:BigInt(p.validityEndTimestamp),uid:p.uid,chainId:BigInt(p.chainId||this.network.id),projectHandle:p.projectHandle},signature:p.signature};return this.validateMintRequest(m.request),K({abi:_,functionName:"mintWithSignature",args:[this.anchorERC1155.formatMintRequest(m.request),m.signature]})}),i=await this.anchorERC1155.multicall(l,y);if(y?.sendTransaction!==!1&&i&&typeof i==="object"&&"transactionHash"in i)try{await this.processTransactionHash(i.transactionHash)}catch(p){console.warn(`Failed to process transaction hash: ${p instanceof Error?p.message:String(p)}`)}return i}async mintFreeBadgeWithMulticall(e,n,t,y){if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!Array.isArray(t)||t.length===0)throw Error("tokenIds is required and must be a non-empty array");for(let i of t)if(!i||typeof i!=="string")throw Error("Each tokenId must be a non-empty string");if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:t});if(a.code!=="0000"||!a.obj||!a.obj.signatures||a.obj.signatures.length===0)throw Error(a.code||"Failed to get mint request from backend");let u=a.obj.signatures.map((i)=>{if(!i.badgeId||!i.signature||!i.validityStartTimestamp||!i.validityEndTimestamp)throw Error("Mint request missing required fields");let p={request:{to:e,tokenId:BigInt(i.badgeId),quantity:BigInt(i.quantity||1),price:BigInt(i.price||0),currency:i.currency,validityStartTimestamp:BigInt(i.validityStartTimestamp),validityEndTimestamp:BigInt(i.validityEndTimestamp),uid:i.uid,chainId:BigInt(i.chainId||this.network.id),projectHandle:i.projectHandle},signature:i.signature};if(this.validateMintRequest(p.request),BigInt(p.request.price)!==0n)throw Error("Free Badge price must be 0");return K({abi:_,functionName:"mintWithSignature",args:[this.anchorERC1155.formatMintRequest(p.request),p.signature]})}),l=await this.anchorERC1155.multicall(u,y);if(y?.sendTransaction!==!1&&l&&typeof l==="object"&&"transactionHash"in l)try{await this.processTransactionHash(l.transactionHash)}catch(i){console.warn(`Failed to process transaction hash: ${i instanceof Error?i.message:String(i)}`)}return l}}export{ee as useAnchorSDK,ze as useAnchorBadge,I as NATIVE_TOKEN_ADDRESS,j as MULTICALL3_ADDRESS,$ as MULTICALL3_ABI,Se as INTERFACE_HASHES,R as HttpClient,re as Environment,U as ERC20_ABI,Y as ENVIRONMENTS,xe as ContentType,G as Api,F as AnchorSDK,Oe as AnchorReactProvider,Z as AnchorPayClient,X as AnchorERC1155Client,Q as AnchorApiClientV2};
1
+ import{createPublicClient as ne,createWalletClient as te,http as _e,custom as F,encodeFunctionData as N,isAddress as f,keccak256 as h,stringToHex as K,concat as W,parseEther as ye}from"viem";import{encodeFunctionData as M}from"viem";import{abstract as pe,abstractTestnet as L,base as ie,baseSepolia as D,berachain as le,berachainBepolia as k,ronin as ue,saigon as g}from"viem/chains";var re;((y)=>{y.DEV="dev";y.BETA="beta";y.PROD="prod"})(re||={});var U=[{constant:!0,inputs:[],name:"decimals",outputs:[{name:"",type:"uint8"}],payable:!1,stateMutability:"view",type:"function"},{inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],name:"allowance",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],name:"approve",outputs:[{name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"account",type:"address"}],name:"balanceOf",outputs:[{name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{name:"recipient",type:"address"},{name:"amount",type:"uint256"}],name:"transfer",outputs:[{name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{name:"sender",type:"address"},{name:"recipient",type:"address"},{name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],X={dev:{apiBaseUrl:"https://anchordev.dipbit.xyz",contracts:{[g.id]:{anchorPay:"0x8551891728967D2D7b6B502eF5339EEb2281143a",anchorERC1155:"0x23Da7778F6152D7B91C20808bEF7163c5EC2C470"},[D.id]:{anchorPay:"0x2C69537d9b82d2C863BCfF3442D1c4E7633ead7c",anchorERC1155:"0x1CE9506cdDdD304AA753c0E8f1F898ab97Ec2870"},[k.id]:{anchorPay:"0x80635645c4B4dA367F2eE6D8F38BED1c2CF8C484",anchorERC1155:"0x20a6e4aa138cF4635c0abFC79272FBeB8a116F36"},[L.id]:{anchorPay:"0xc5c1606fDe120018E74751253F572796EDbaBC09",anchorERC1155:"0x0E03d8fA4A37287eabfb2e5BBdc7AcD7C1D3e869"},["1962"]:{anchorERC1155:"0xa670ca0270c46876e5a78c9a7c596bfef91185a8"}}},beta:{apiBaseUrl:"https://anchorbeta.dipbit.xyz",contracts:{[g.id]:{anchorPay:"0xcbA8A3FE5fa94A807143bC2467A012010b02Cd94",anchorERC1155:"0x4a4D5888A284fED88fbE998c2C59957CE87923D2"},[D.id]:{anchorPay:"0x2EB31dAbb95F3697eC6bBfE0c41b55D9C321571e",anchorERC1155:"0xE78F00BBD1be39Db6C404142Cf4a3A2471A915e7"},[k.id]:{anchorPay:"0x382F7946378e8A7A848d04166083711c90D76061",anchorERC1155:"0x99eed4522a3Da62CaEE3e87BfFd3779d7d5EF853"},[L.id]:{anchorPay:"0x7dc99a343555711aB92fc844d0Df657161df7D67",anchorERC1155:"0xa34F267d3Ab2Ce21CBD1F04F593300f6CB609a29"},["1962"]:{anchorERC1155:"0xa51B53Dc3aA7f4ef5fE9bb429521a73f411ad867"}}},prod:{apiBaseUrl:"https://api-anchor.deek.network",contracts:{[pe.id]:{anchorPay:"0xf87C02027f36067a87E4eaeeD61b7Ce2ffE0813A",anchorERC1155:"0xd6895dc1740e057D564C795923542122f1513142"},[ie.id]:{anchorPay:"0x56f0fAF3a0336F57289e61Be6F32380B38C171E1"},[ue.id]:{anchorPay:"0x56f0fAF3a0336F57289e61Be6F32380B38C171E1",anchorERC1155:"0xA412f7D0B39c7451E9A8a34a66f0D69CB5A378dA"},[le.id]:{anchorPay:"0x4567890123456789012345678901234567890123",anchorERC1155:"0xdefabcdefabcdefabcdefabcdefabcdefabcdefab"}}}},Ie={TOKEN_RECEIVED:"0x8b2cb2c7b7e2282e2e4b29a6a8c2b2db4218c6a5f8e8fcb3d5598f3e1e6c59d9"},_="0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",j="0xcA11bde05977b3631167028862bE2a173976CA11",Y=[{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall3.Call[]",name:"calls",type:"tuple[]"}],name:"aggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes[]",name:"returnData",type:"bytes[]"}],stateMutability:"payable",type:"function"},{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bool",name:"allowFailure",type:"bool"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall3.Call3[]",name:"calls",type:"tuple[]"}],name:"aggregate3",outputs:[{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall3.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"payable",type:"function"},{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bool",name:"allowFailure",type:"bool"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall3.Call3Value[]",name:"calls",type:"tuple[]"}],name:"aggregate3Value",outputs:[{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall3.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"payable",type:"function"}];var w=[{type:"constructor",inputs:[],stateMutability:"nonpayable"},{type:"function",name:"UPGRADE_INTERFACE_VERSION",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"acceptOwnership",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"balanceOf",inputs:[{name:"account",type:"address",internalType:"address"},{name:"token",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"depositFor",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"token",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"getInterfaceImplementer",inputs:[{name:"account",type:"address",internalType:"address"},{name:"_interfaceHash",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"initialize",inputs:[{name:"_defaultAdmin",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"pause",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"pendingOwner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"proxiableUUID",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"renounceOwnership",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"send",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"token",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"payable"},{type:"function",name:"setInterfaceImplementer",inputs:[{name:"account",type:"address",internalType:"address"},{name:"_interfaceHash",type:"bytes32",internalType:"bytes32"},{name:"implementer",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"transferOwnership",inputs:[{name:"newOwner",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"unpause",inputs:[],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"upgradeToAndCall",inputs:[{name:"newImplementation",type:"address",internalType:"address"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"payable"},{type:"function",name:"withdraw",inputs:[{name:"token",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"event",name:"Deposited",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"token",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Initialized",inputs:[{name:"version",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"InterfaceImplementerSet",inputs:[{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"interfaceHash",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"implementer",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"OwnershipTransferStarted",inputs:[{name:"previousOwner",type:"address",indexed:!0,internalType:"address"},{name:"newOwner",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"OwnershipTransferred",inputs:[{name:"previousOwner",type:"address",indexed:!0,internalType:"address"},{name:"newOwner",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"Paid",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"data",type:"bytes",indexed:!1,internalType:"bytes"}],anonymous:!1},{type:"event",name:"Upgraded",inputs:[{name:"implementation",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"Withdrawn",inputs:[{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"token",type:"address",indexed:!0,internalType:"address"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"error",name:"AddressEmptyCode",inputs:[{name:"target",type:"address",internalType:"address"}]},{type:"error",name:"AddressNotSet",inputs:[]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{name:"implementation",type:"address",internalType:"address"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InsufficientBalance",inputs:[]},{type:"error",name:"InsufficientPayment",inputs:[]},{type:"error",name:"InvalidAddress",inputs:[]},{type:"error",name:"InvalidAmount",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidMsgValue",inputs:[]},{type:"error",name:"InvalidState",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"OwnableInvalidOwner",inputs:[{name:"owner",type:"address",internalType:"address"}]},{type:"error",name:"OwnableUnauthorizedAccount",inputs:[{name:"account",type:"address",internalType:"address"}]},{type:"error",name:"PaymentTransferFailed",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{name:"token",type:"address",internalType:"address"}]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{name:"slot",type:"bytes32",internalType:"bytes32"}]}];class S{publicClient;walletClient;account;network;contracts;constructor(e,n,t,y,a){this.publicClient=e,this.network=n,this.walletClient=t,this.account=y,this.contracts=a||{}}async sendETH(e,n,t="0x",y){if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=M({abi:w,functionName:"send",args:[e,_,n,t]});if(y?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:a,value:n};let{maxFeePerGas:u,maxPriorityFeePerGas:l}=await this.publicClient.estimateFeesPerGas(),i=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:a,value:n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let p=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:a,value:n,maxFeePerGas:y?.maxFeePerGas||u,maxPriorityFeePerGas:y?.maxPriorityFeePerGas||l,gas:y?.gas||i,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:p})}async sendERC20(e,n,t,y="0x",a){if(a?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");if(a?.autoApprove!==!1&&this.walletClient&&this.account)try{console.log(`Checking ERC20 token approval status: ${n}`);let r=await this.publicClient.readContract({address:n,abi:U,functionName:"allowance",args:[this.account.address,this.contracts?.anchorPay]});if(console.log(`Current allowance: ${r}, Required amount: ${t}, AnchorPay contract address: ${this.contracts?.anchorPay}`),r<t){console.log(`Approving ${t} tokens to AnchorPay contract...`);let b=2n**256n-1n,{maxFeePerGas:z,maxPriorityFeePerGas:O}=await this.publicClient.estimateFeesPerGas(),x=M({abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b]}),d=await this.publicClient.estimateGas({to:n,data:x,value:0n,account:this.account}),v=await this.walletClient.writeContract({account:this.account,address:n,abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b],chain:this.publicClient.chain,maxFeePerGas:z,maxPriorityFeePerGas:O,gas:d});console.log(`Approval transaction sent, hash: ${v}`),await this.publicClient.waitForTransactionReceipt({hash:v}),console.log("Approval transaction confirmed")}else console.log("Sufficient allowance already exists, no need for additional approval")}catch(r){throw console.error("Approval failed:",r),Error(`ERC20 approval failed: ${r instanceof Error?r.message:String(r)}`)}let u=M({abi:w,functionName:"send",args:[e,n,t,y]});if(a?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:u,value:0n};let{maxFeePerGas:l,maxPriorityFeePerGas:i}=await this.publicClient.estimateFeesPerGas(),p=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:u,value:0n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let T=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:u,maxFeePerGas:a?.maxFeePerGas||l,maxPriorityFeePerGas:a?.maxPriorityFeePerGas||i,gas:a?.gas||p,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:T})}async getInterfaceImplementer(e,n){return await this.publicClient.readContract({address:this.contracts?.anchorPay||"",abi:w,functionName:"getInterfaceImplementer",args:[e,n]})}async setInterfaceImplementer(e,n,t){if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let{maxFeePerGas:y,maxPriorityFeePerGas:a}=await this.publicClient.estimateFeesPerGas(),u=M({abi:w,functionName:"setInterfaceImplementer",args:[e,n,t]}),l=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:u,value:0n,account:this.account}),i=await this.walletClient.writeContract({account:this.account,address:this.contracts?.anchorPay||"",abi:w,functionName:"setInterfaceImplementer",args:[e,n,t],chain:this.publicClient.chain,maxFeePerGas:y,maxPriorityFeePerGas:a,gas:l});return await this.publicClient.waitForTransactionReceipt({hash:i})}getERC20ApprovalData(e,n,t){let y=t||this.contracts?.anchorPay||"",a=M({abi:U,functionName:"approve",args:[y,n]});return{to:e,data:a,value:0n}}async balanceOf(e,n){return await this.publicClient.readContract({address:this.contracts?.anchorPay||"",abi:w,functionName:"balanceOf",args:[e,n]})}async depositETH(e,n,t){if(t?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let y=M({abi:w,functionName:"depositFor",args:[e,_,n]});if(t?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:y,value:n};let{maxFeePerGas:a,maxPriorityFeePerGas:u}=await this.publicClient.estimateFeesPerGas(),l=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:y,value:n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let i=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:y,value:n,maxFeePerGas:t?.maxFeePerGas||a,maxPriorityFeePerGas:t?.maxPriorityFeePerGas||u,gas:t?.gas||l,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:i})}async depositERC20(e,n,t,y){if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");if(y?.autoApprove!==!1&&this.walletClient&&this.account)try{console.log(`Checking ERC20 token approval status: ${n}`);let m=await this.publicClient.readContract({address:n,abi:U,functionName:"allowance",args:[this.account.address,this.contracts?.anchorPay]});if(console.log(`Current allowance: ${m}, Required amount: ${t}, AnchorPay contract address: ${this.contracts?.anchorPay}`),m<t){console.log(`Approving ${t} tokens to AnchorPay contract...`);let r=2n**256n-1n,{maxFeePerGas:b,maxPriorityFeePerGas:z}=await this.publicClient.estimateFeesPerGas(),O=M({abi:U,functionName:"approve",args:[this.contracts?.anchorPay,r]}),x=await this.publicClient.estimateGas({to:n,data:O,value:0n,account:this.account}),d=await this.walletClient.writeContract({account:this.account,address:n,abi:U,functionName:"approve",args:[this.contracts?.anchorPay,r],chain:this.publicClient.chain,maxFeePerGas:b,maxPriorityFeePerGas:z,gas:x});console.log(`Approval transaction sent, hash: ${d}`),await this.publicClient.waitForTransactionReceipt({hash:d}),console.log("Approval transaction confirmed")}else console.log("Sufficient allowance already exists, no need for additional approval")}catch(m){throw console.error("Approval failed:",m),Error(`ERC20 approval failed: ${m instanceof Error?m.message:String(m)}`)}let a=M({abi:w,functionName:"depositFor",args:[e,n,t]});if(y?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:a,value:0n};let{maxFeePerGas:u,maxPriorityFeePerGas:l}=await this.publicClient.estimateFeesPerGas(),i=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:a,value:0n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let p=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:a,maxFeePerGas:y?.maxFeePerGas||u,maxPriorityFeePerGas:y?.maxPriorityFeePerGas||l,gas:y?.gas||i,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:p})}async withdraw(e,n,t){if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let{maxFeePerGas:y,maxPriorityFeePerGas:a}=await this.publicClient.estimateFeesPerGas(),u=M({abi:w,functionName:"withdraw",args:[e,n]}),l=await this.publicClient.estimateGas({to:this.contracts?.anchorPay||"",data:u,value:0n,account:this.account}),i=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:u,maxFeePerGas:t?.maxFeePerGas||y,maxPriorityFeePerGas:t?.maxPriorityFeePerGas||a,gas:t?.gas||l,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:i})}async batchDepositETH(e,n){if(e.length===0)throw Error("No deposits provided");if(n?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let t=e.map((m)=>{let r=M({abi:w,functionName:"depositFor",args:[m.recipient,_,m.amount]});return{target:this.contracts?.anchorPay||"",allowFailure:!1,value:m.amount,callData:r}}),y=e.reduce((m,r)=>m+r.amount,0n),a=M({abi:Y,functionName:"aggregate3Value",args:[t]});if(n?.sendTransaction===!1)return{to:j,data:a,value:y};let{maxFeePerGas:u,maxPriorityFeePerGas:l}=await this.publicClient.estimateFeesPerGas(),i=await this.publicClient.estimateGas({to:j,data:a,value:y,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let p=await this.walletClient.sendTransaction({account:this.account,to:j,data:a,value:y,maxFeePerGas:n?.maxFeePerGas||u,maxPriorityFeePerGas:n?.maxPriorityFeePerGas||l,gas:n?.gas||i,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:p})}async batchDepositERC20(e,n,t){if(n.length===0)throw Error("No deposits provided");if(t?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let y=n.reduce((r,b)=>r+b.amount,0n);if(t?.autoApprove!==!1&&this.walletClient&&this.account)try{console.log(`Checking ERC20 token approval status: ${e}`);let r=await this.publicClient.readContract({address:e,abi:U,functionName:"allowance",args:[this.account.address,this.contracts?.anchorPay]});if(console.log(`Current allowance: ${r}, Required amount: ${y}, AnchorPay contract address: ${this.contracts?.anchorPay}`),r<y){console.log(`Approving ${y} tokens to AnchorPay contract...`);let b=2n**256n-1n,{maxFeePerGas:z,maxPriorityFeePerGas:O}=await this.publicClient.estimateFeesPerGas(),x=M({abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b]}),d=await this.publicClient.estimateGas({to:e,data:x,value:0n,account:this.account}),v=await this.walletClient.writeContract({account:this.account,address:e,abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b],chain:this.publicClient.chain,maxFeePerGas:z,maxPriorityFeePerGas:O,gas:d});console.log(`Approval transaction sent, hash: ${v}`),await this.publicClient.waitForTransactionReceipt({hash:v}),console.log("Approval transaction confirmed")}else console.log("Sufficient allowance already exists, no need for additional approval")}catch(r){throw console.error("Approval failed:",r),Error(`ERC20 approval failed: ${r instanceof Error?r.message:String(r)}`)}let a=n.map((r)=>{let b=M({abi:w,functionName:"depositFor",args:[r.recipient,e,r.amount]});return{target:this.contracts?.anchorPay||"",allowFailure:!1,value:0n,callData:b}}),u=M({abi:Y,functionName:"aggregate3Value",args:[a]});if(t?.sendTransaction===!1)return{to:j,data:u,value:0n};let{maxFeePerGas:l,maxPriorityFeePerGas:i}=await this.publicClient.estimateFeesPerGas(),p=await this.publicClient.estimateGas({to:j,data:u,value:0n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let T=await this.walletClient.sendTransaction({account:this.account,to:j,data:u,maxFeePerGas:t?.maxFeePerGas||l,maxPriorityFeePerGas:t?.maxPriorityFeePerGas||i,gas:t?.gas||p,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:T})}async batchSendETH(e,n){if(e.length===0)throw Error("No transfers provided");if(n?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let t=e.map((m)=>{let r=M({abi:w,functionName:"send",args:[m.recipient,_,m.amount,m.data||"0x"]});return{target:this.contracts?.anchorPay||"",allowFailure:!1,value:m.amount,callData:r}}),y=e.reduce((m,r)=>m+r.amount,0n),a=M({abi:Y,functionName:"aggregate3Value",args:[t]});if(n?.sendTransaction===!1)return{to:j,data:a,value:y};let{maxFeePerGas:u,maxPriorityFeePerGas:l}=await this.publicClient.estimateFeesPerGas(),i=await this.publicClient.estimateGas({to:j,data:a,value:y,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let p=await this.walletClient.sendTransaction({account:this.account,to:j,data:a,value:y,maxFeePerGas:n?.maxFeePerGas||u,maxPriorityFeePerGas:n?.maxPriorityFeePerGas||l,gas:n?.gas||i,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:p})}async batchSendERC20(e,n,t){if(n.length===0)throw Error("No transfers provided");if(t?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let y=n.reduce((r,b)=>r+b.amount,0n);if(t?.autoApprove!==!1&&this.walletClient&&this.account)try{console.log(`Checking ERC20 token approval status: ${e}`);let r=await this.publicClient.readContract({address:e,abi:U,functionName:"allowance",args:[this.account.address,this.contracts?.anchorPay]});if(console.log(`Current allowance: ${r}, Required amount: ${y}, AnchorPay contract address: ${this.contracts?.anchorPay}`),r<y){console.log(`Approving ${y} tokens to AnchorPay contract...`);let b=2n**256n-1n,{maxFeePerGas:z,maxPriorityFeePerGas:O}=await this.publicClient.estimateFeesPerGas(),x=M({abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b]}),d=await this.publicClient.estimateGas({to:e,data:x,value:0n,account:this.account}),v=await this.walletClient.writeContract({account:this.account,address:e,abi:U,functionName:"approve",args:[this.contracts?.anchorPay,b],chain:this.publicClient.chain,maxFeePerGas:z,maxPriorityFeePerGas:O,gas:d});console.log(`Approval transaction sent, hash: ${v}`),await this.publicClient.waitForTransactionReceipt({hash:v}),console.log("Approval transaction confirmed")}else console.log("Sufficient allowance already exists, no need for additional approval")}catch(r){throw console.error("Approval failed:",r),Error(`ERC20 approval failed: ${r instanceof Error?r.message:String(r)}`)}let a=n.map((r)=>{let b=M({abi:w,functionName:"send",args:[r.recipient,e,r.amount,r.data||"0x"]});return{target:this.contracts?.anchorPay||"",allowFailure:!1,value:0n,callData:b}}),u=M({abi:Y,functionName:"aggregate3Value",args:[a]});if(t?.sendTransaction===!1)return{to:j,data:u,value:0n};let{maxFeePerGas:l,maxPriorityFeePerGas:i}=await this.publicClient.estimateFeesPerGas(),p=await this.publicClient.estimateGas({to:j,data:u,value:0n,account:this.account});if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let T=await this.walletClient.sendTransaction({account:this.account,to:j,data:u,maxFeePerGas:t?.maxFeePerGas||l,maxPriorityFeePerGas:t?.maxPriorityFeePerGas||i,gas:t?.gas||p,chain:this.publicClient.chain});return await this.publicClient.waitForTransactionReceipt({hash:T})}}import{concat as c,encodeAbiParameters as A,encodeFunctionData as ve,keccak256 as H,stringToHex as P}from"viem";var s=[{type:"constructor",inputs:[],stateMutability:"nonpayable"},{type:"function",name:"DEFAULT_ADMIN_ROLE",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"UPGRADE_INTERFACE_VERSION",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"badgeToProject",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"balanceOf",inputs:[{name:"account",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"balanceOfBatch",inputs:[{name:"accounts",type:"address[]",internalType:"address[]"},{name:"ids",type:"uint256[]",internalType:"uint256[]"}],outputs:[{name:"",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"view"},{type:"function",name:"burnBatch",inputs:[{name:"from",type:"address",internalType:"address"},{name:"ids",type:"uint256[]",internalType:"uint256[]"},{name:"values",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"calculateProjectTokenId",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"projectTokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"pure"},{type:"function",name:"createBatch",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"_to",type:"address",internalType:"address"},{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"},{name:"_maxSupplies",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"createBatch",inputs:[{name:"_to",type:"address",internalType:"address"},{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"},{name:"_maxSupplies",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"eip712Domain",inputs:[],outputs:[{name:"fields",type:"bytes1",internalType:"bytes1"},{name:"name",type:"string",internalType:"string"},{name:"version",type:"string",internalType:"string"},{name:"chainId",type:"uint256",internalType:"uint256"},{name:"verifyingContract",type:"address",internalType:"address"},{name:"salt",type:"bytes32",internalType:"bytes32"},{name:"extensions",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"view"},{type:"function",name:"exists",inputs:[{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"getRoleAdmin",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"grantAdminRole",inputs:[{name:"admin",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"grantProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"grantRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"hasRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"initialize",inputs:[{name:"_defaultAdmin",type:"address",internalType:"address"},{name:"_name",type:"string",internalType:"string"},{name:"_symbol",type:"string",internalType:"string"},{name:"_version",type:"string",internalType:"string"},{name:"_baseURI",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"isApprovedForAll",inputs:[{name:"account",type:"address",internalType:"address"},{name:"operator",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"mintWithSignature",inputs:[{name:"_req",type:"tuple",internalType:"struct AnchorDataTypes.MintRequest",components:[{name:"to",type:"address",internalType:"address"},{name:"tokenId",type:"uint256",internalType:"uint256"},{name:"quantity",type:"uint256",internalType:"uint256"},{name:"price",type:"uint256",internalType:"uint256"},{name:"currency",type:"address",internalType:"address"},{name:"validityStartTimestamp",type:"uint128",internalType:"uint128"},{name:"validityEndTimestamp",type:"uint128",internalType:"uint128"},{name:"uid",type:"bytes32",internalType:"bytes32"},{name:"chainId",type:"uint256",internalType:"uint256"},{name:"projectHandle",type:"bytes32",internalType:"bytes32"}]},{name:"_signature",type:"bytes",internalType:"bytes"}],outputs:[{name:"signer",type:"address",internalType:"address"}],stateMutability:"payable"},{type:"function",name:"multicall",inputs:[{name:"data",type:"bytes[]",internalType:"bytes[]"}],outputs:[{name:"results",type:"bytes[]",internalType:"bytes[]"}],stateMutability:"nonpayable"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"nextTokenIdToMint",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"projectTotalSupply",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"proxiableUUID",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"renounceRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"callerConfirmation",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"revokeProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"revokeRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"safeBatchTransferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"ids",type:"uint256[]",internalType:"uint256[]"},{name:"values",type:"uint256[]",internalType:"uint256[]"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"safeTransferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"},{name:"value",type:"uint256",internalType:"uint256"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setApprovalForAll",inputs:[{name:"operator",type:"address",internalType:"address"},{name:"approved",type:"bool",internalType:"bool"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setMaxSupply",inputs:[{name:"_tokenId",type:"uint256",internalType:"uint256"},{name:"_maxSupply",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRegistry",inputs:[{name:"registry",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setURIs",inputs:[{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setup",inputs:[{name:"_name",type:"string",internalType:"string"},{name:"_symbol",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"supportsInterface",inputs:[{name:"interfaceId",type:"bytes4",internalType:"bytes4"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"pure"},{type:"function",name:"symbol",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"tokenReceived",inputs:[{name:"token",type:"address",internalType:"address"},{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"},{name:"userData",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"totalSupply",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"totalSupply",inputs:[{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"upgradeTo",inputs:[{name:"newImplementation",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"upgradeToAndCall",inputs:[{name:"newImplementation",type:"address",internalType:"address"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"payable"},{type:"function",name:"uri",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"version",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"event",name:"AnchorInitialized",inputs:[{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ApprovalForAll",inputs:[{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"approved",type:"bool",indexed:!1,internalType:"bool"}],anonymous:!1},{type:"event",name:"BatchBurned",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"BatchCreated",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"projectTokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"tokenURIs",type:"string[]",indexed:!1,internalType:"string[]"},{name:"maxSupply",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"BatchURI",inputs:[{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"tokenURIs",type:"string[]",indexed:!1,internalType:"string[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"EIP712DomainChanged",inputs:[],anonymous:!1},{type:"event",name:"Initialized",inputs:[{name:"version",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"MaxSupplyUpdated",inputs:[{name:"tokenId",type:"uint256",indexed:!1,internalType:"uint256"},{name:"maxSupply",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Minted",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"tokenId",type:"uint256",indexed:!0,internalType:"uint256"},{name:"quantity",type:"uint256",indexed:!1,internalType:"uint256"},{name:"price",type:"uint256",indexed:!1,internalType:"uint256"},{name:"currency",type:"address",indexed:!1,internalType:"address"},{name:"uid",type:"bytes32",indexed:!1,internalType:"bytes32"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ProjectOperatorGranted",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ProjectOperatorRevoked",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"RoleAdminChanged",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"previousAdminRole",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"newAdminRole",type:"bytes32",indexed:!0,internalType:"bytes32"}],anonymous:!1},{type:"event",name:"RoleGranted",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"RoleRevoked",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"TransferBatch",inputs:[{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"ids",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"}],anonymous:!1},{type:"event",name:"TransferSingle",inputs:[{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"uint256",indexed:!1,internalType:"uint256"},{name:"value",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"URI",inputs:[{name:"value",type:"string",indexed:!1,internalType:"string"},{name:"id",type:"uint256",indexed:!0,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Upgraded",inputs:[{name:"implementation",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"error",name:"AccessControlBadConfirmation",inputs:[]},{type:"error",name:"AccessControlUnauthorizedAccount",inputs:[{name:"account",type:"address",internalType:"address"},{name:"neededRole",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"AddressEmptyCode",inputs:[{name:"target",type:"address",internalType:"address"}]},{type:"error",name:"AddressNotSet",inputs:[]},{type:"error",name:"ArrayLengthMismatch",inputs:[]},{type:"error",name:"ECDSAInvalidSignature",inputs:[]},{type:"error",name:"ECDSAInvalidSignatureLength",inputs:[{name:"length",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ECDSAInvalidSignatureS",inputs:[{name:"s",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"ERC1155InsufficientBalance",inputs:[{name:"sender",type:"address",internalType:"address"},{name:"balance",type:"uint256",internalType:"uint256"},{name:"needed",type:"uint256",internalType:"uint256"},{name:"tokenId",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ERC1155InvalidApprover",inputs:[{name:"approver",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidArrayLength",inputs:[{name:"idsLength",type:"uint256",internalType:"uint256"},{name:"valuesLength",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ERC1155InvalidOperator",inputs:[{name:"operator",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidReceiver",inputs:[{name:"receiver",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidSender",inputs:[{name:"sender",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155MissingApprovalForAll",inputs:[{name:"operator",type:"address",internalType:"address"},{name:"owner",type:"address",internalType:"address"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{name:"implementation",type:"address",internalType:"address"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"EmptyArray",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidChainId",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"InvalidPayment",inputs:[]},{type:"error",name:"InvalidReceiver",inputs:[]},{type:"error",name:"InvalidRegistry",inputs:[]},{type:"error",name:"InvalidSignature",inputs:[]},{type:"error",name:"InvalidTokenId",inputs:[]},{type:"error",name:"MaxSupplyExceeded",inputs:[]},{type:"error",name:"NonTransferableToken",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProjectOperator",inputs:[]},{type:"error",name:"PaymentRequired",inputs:[]},{type:"error",name:"ProjectHandleZero",inputs:[]},{type:"error",name:"RecipientUndefined",inputs:[]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SignatureExpired",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{name:"slot",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"Unauthorized",inputs:[]},{type:"error",name:"ZeroQuantity",inputs:[]}];import{Contract as me,Interface as be}from"ethers";var o=[{type:"constructor",inputs:[],stateMutability:"nonpayable"},{type:"function",name:"DEFAULT_ADMIN_ROLE",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"UPGRADE_INTERFACE_VERSION",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"badgeToProject",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"balanceOf",inputs:[{name:"account",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"balanceOfBatch",inputs:[{name:"accounts",type:"address[]",internalType:"address[]"},{name:"ids",type:"uint256[]",internalType:"uint256[]"}],outputs:[{name:"",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"view"},{type:"function",name:"burnBatch",inputs:[{name:"from",type:"address",internalType:"address"},{name:"ids",type:"uint256[]",internalType:"uint256[]"},{name:"values",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"calculateProjectTokenId",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"projectTokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"pure"},{type:"function",name:"createBatch",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"_to",type:"address",internalType:"address"},{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"},{name:"_maxSupplies",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"createBatch",inputs:[{name:"_to",type:"address",internalType:"address"},{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"},{name:"_maxSupplies",type:"uint256[]",internalType:"uint256[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"eip712Domain",inputs:[],outputs:[{name:"fields",type:"bytes1",internalType:"bytes1"},{name:"name",type:"string",internalType:"string"},{name:"version",type:"string",internalType:"string"},{name:"chainId",type:"uint256",internalType:"uint256"},{name:"verifyingContract",type:"address",internalType:"address"},{name:"salt",type:"bytes32",internalType:"bytes32"},{name:"extensions",type:"uint256[]",internalType:"uint256[]"}],stateMutability:"view"},{type:"function",name:"exists",inputs:[{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"getRoleAdmin",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"grantAdminRole",inputs:[{name:"admin",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"grantProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"grantRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"hasRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"initialize",inputs:[{name:"_defaultAdmin",type:"address",internalType:"address"},{name:"_name",type:"string",internalType:"string"},{name:"_symbol",type:"string",internalType:"string"},{name:"_version",type:"string",internalType:"string"},{name:"_baseURI",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"isApprovedForAll",inputs:[{name:"account",type:"address",internalType:"address"},{name:"operator",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"isProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"mintWithSignature",inputs:[{name:"_req",type:"tuple",internalType:"struct AnchorDataTypes.MintRequest",components:[{name:"to",type:"address",internalType:"address"},{name:"tokenId",type:"uint256",internalType:"uint256"},{name:"quantity",type:"uint256",internalType:"uint256"},{name:"price",type:"uint256",internalType:"uint256"},{name:"currency",type:"address",internalType:"address"},{name:"validityStartTimestamp",type:"uint128",internalType:"uint128"},{name:"validityEndTimestamp",type:"uint128",internalType:"uint128"},{name:"uid",type:"bytes32",internalType:"bytes32"},{name:"chainId",type:"uint256",internalType:"uint256"},{name:"projectHandle",type:"bytes32",internalType:"bytes32"}]},{name:"_signature",type:"bytes",internalType:"bytes"}],outputs:[{name:"signer",type:"address",internalType:"address"}],stateMutability:"payable"},{type:"function",name:"multicall",inputs:[{name:"data",type:"bytes[]",internalType:"bytes[]"}],outputs:[{name:"results",type:"bytes[]",internalType:"bytes[]"}],stateMutability:"nonpayable"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"nextTokenIdToMint",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"owner",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"projectTotalSupply",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"proxiableUUID",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"renounceRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"callerConfirmation",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"revokeProjectOperator",inputs:[{name:"projectHandle",type:"bytes32",internalType:"bytes32"},{name:"operator",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"revokeRole",inputs:[{name:"role",type:"bytes32",internalType:"bytes32"},{name:"account",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"safeBatchTransferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"ids",type:"uint256[]",internalType:"uint256[]"},{name:"values",type:"uint256[]",internalType:"uint256[]"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"safeTransferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"},{name:"value",type:"uint256",internalType:"uint256"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setApprovalForAll",inputs:[{name:"operator",type:"address",internalType:"address"},{name:"approved",type:"bool",internalType:"bool"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setMaxSupply",inputs:[{name:"_tokenId",type:"uint256",internalType:"uint256"},{name:"_maxSupply",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setRegistry",inputs:[{name:"registry",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setURIs",inputs:[{name:"_tokenIds",type:"uint256[]",internalType:"uint256[]"},{name:"_tokenURIs",type:"string[]",internalType:"string[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setup",inputs:[{name:"_name",type:"string",internalType:"string"},{name:"_symbol",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"supportsInterface",inputs:[{name:"interfaceId",type:"bytes4",internalType:"bytes4"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"pure"},{type:"function",name:"symbol",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"tokenReceived",inputs:[{name:"token",type:"address",internalType:"address"},{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"},{name:"userData",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"totalSupply",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"totalSupply",inputs:[{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"upgradeTo",inputs:[{name:"newImplementation",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"upgradeToAndCall",inputs:[{name:"newImplementation",type:"address",internalType:"address"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"payable"},{type:"function",name:"uri",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"version",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"event",name:"AnchorInitialized",inputs:[{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ApprovalForAll",inputs:[{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"approved",type:"bool",indexed:!1,internalType:"bool"}],anonymous:!1},{type:"event",name:"BatchBurned",inputs:[{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"BatchCreated",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"projectTokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"tokenURIs",type:"string[]",indexed:!1,internalType:"string[]"},{name:"maxSupply",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"BatchURI",inputs:[{name:"tokenIds",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"tokenURIs",type:"string[]",indexed:!1,internalType:"string[]"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"EIP712DomainChanged",inputs:[],anonymous:!1},{type:"event",name:"Initialized",inputs:[{name:"version",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"MaxSupplyUpdated",inputs:[{name:"tokenId",type:"uint256",indexed:!1,internalType:"uint256"},{name:"maxSupply",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Minted",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"tokenId",type:"uint256",indexed:!0,internalType:"uint256"},{name:"quantity",type:"uint256",indexed:!1,internalType:"uint256"},{name:"price",type:"uint256",indexed:!1,internalType:"uint256"},{name:"currency",type:"address",indexed:!1,internalType:"address"},{name:"uid",type:"bytes32",indexed:!1,internalType:"bytes32"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ProjectOperatorGranted",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"ProjectOperatorRevoked",inputs:[{name:"projectHandle",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"timestamp",type:"uint64",indexed:!1,internalType:"uint64"}],anonymous:!1},{type:"event",name:"RoleAdminChanged",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"previousAdminRole",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"newAdminRole",type:"bytes32",indexed:!0,internalType:"bytes32"}],anonymous:!1},{type:"event",name:"RoleGranted",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"RoleRevoked",inputs:[{name:"role",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"account",type:"address",indexed:!0,internalType:"address"},{name:"sender",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"event",name:"TransferBatch",inputs:[{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"ids",type:"uint256[]",indexed:!1,internalType:"uint256[]"},{name:"values",type:"uint256[]",indexed:!1,internalType:"uint256[]"}],anonymous:!1},{type:"event",name:"TransferSingle",inputs:[{name:"operator",type:"address",indexed:!0,internalType:"address"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"uint256",indexed:!1,internalType:"uint256"},{name:"value",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"URI",inputs:[{name:"value",type:"string",indexed:!1,internalType:"string"},{name:"id",type:"uint256",indexed:!0,internalType:"uint256"}],anonymous:!1},{type:"event",name:"Upgraded",inputs:[{name:"implementation",type:"address",indexed:!0,internalType:"address"}],anonymous:!1},{type:"error",name:"AccessControlBadConfirmation",inputs:[]},{type:"error",name:"AccessControlUnauthorizedAccount",inputs:[{name:"account",type:"address",internalType:"address"},{name:"neededRole",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"AddressEmptyCode",inputs:[{name:"target",type:"address",internalType:"address"}]},{type:"error",name:"AddressNotSet",inputs:[]},{type:"error",name:"ArrayLengthMismatch",inputs:[]},{type:"error",name:"ECDSAInvalidSignature",inputs:[]},{type:"error",name:"ECDSAInvalidSignatureLength",inputs:[{name:"length",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ECDSAInvalidSignatureS",inputs:[{name:"s",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"ERC1155InsufficientBalance",inputs:[{name:"sender",type:"address",internalType:"address"},{name:"balance",type:"uint256",internalType:"uint256"},{name:"needed",type:"uint256",internalType:"uint256"},{name:"tokenId",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ERC1155InvalidApprover",inputs:[{name:"approver",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidArrayLength",inputs:[{name:"idsLength",type:"uint256",internalType:"uint256"},{name:"valuesLength",type:"uint256",internalType:"uint256"}]},{type:"error",name:"ERC1155InvalidOperator",inputs:[{name:"operator",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidReceiver",inputs:[{name:"receiver",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155InvalidSender",inputs:[{name:"sender",type:"address",internalType:"address"}]},{type:"error",name:"ERC1155MissingApprovalForAll",inputs:[{name:"operator",type:"address",internalType:"address"},{name:"owner",type:"address",internalType:"address"}]},{type:"error",name:"ERC1967InvalidImplementation",inputs:[{name:"implementation",type:"address",internalType:"address"}]},{type:"error",name:"ERC1967NonPayable",inputs:[]},{type:"error",name:"EmptyArray",inputs:[]},{type:"error",name:"FailedCall",inputs:[]},{type:"error",name:"InvalidChainId",inputs:[]},{type:"error",name:"InvalidInitialization",inputs:[]},{type:"error",name:"InvalidParameter",inputs:[]},{type:"error",name:"InvalidPayment",inputs:[]},{type:"error",name:"InvalidReceiver",inputs:[]},{type:"error",name:"InvalidRegistry",inputs:[]},{type:"error",name:"InvalidSignature",inputs:[]},{type:"error",name:"InvalidTokenId",inputs:[]},{type:"error",name:"MaxSupplyExceeded",inputs:[]},{type:"error",name:"NonTransferableToken",inputs:[]},{type:"error",name:"NotInitializing",inputs:[]},{type:"error",name:"NotProjectOperator",inputs:[]},{type:"error",name:"PaymentRequired",inputs:[]},{type:"error",name:"ProjectHandleZero",inputs:[]},{type:"error",name:"RecipientUndefined",inputs:[]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SignatureExpired",inputs:[]},{type:"error",name:"UUPSUnauthorizedCallContext",inputs:[]},{type:"error",name:"UUPSUnsupportedProxiableUUID",inputs:[{name:"slot",type:"bytes32",internalType:"bytes32"}]},{type:"error",name:"Unauthorized",inputs:[]},{type:"error",name:"ZeroQuantity",inputs:[]}];class Z{static abi=o;static createInterface(){return new be(o)}static connect(e,n){return new me(e,o,n)}}import{Contract as Ge,Interface as Fe}from"ethers";class J{publicClient;walletClient;account;network;contracts;constructor(e,n,t,y,a){this.publicClient=e,this.network=n,this.walletClient=t,this.account=y,this.contracts=a||{}}async getTokenURI(e){if(!this.contracts?.anchorERC1155)throw Error("AnchorERC1155 contract address not set, please check network configuration");return await this.publicClient.readContract({address:this.contracts.anchorERC1155,abi:s,functionName:"uri",args:[e]})}async getName(){if(!this.contracts?.anchorERC1155)throw Error("AnchorERC1155 contract address not set, please check network configuration");return await this.publicClient.readContract({address:this.contracts.anchorERC1155,abi:s,functionName:"name"})}async getSymbol(){if(!this.contracts?.anchorERC1155)throw Error("AnchorERC1155 contract address not set, please check network configuration");return await this.publicClient.readContract({address:this.contracts.anchorERC1155,abi:s,functionName:"symbol"})}async mintWithSignature(e,n,t){if(BigInt(e.request.price)!==0n)throw Error("mintWithSignature method can only be used to mint free tokens");let y=n||this.contracts?.anchorERC1155,a=Z.createInterface().encodeFunctionData("mintWithSignature",[this.formatMintRequest(e.request),e.signature]);if(console.log(a,"data"),t?.sendTransaction===!1)return{to:y,data:a,value:0n};if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let{maxFeePerGas:u,maxPriorityFeePerGas:l}=await this.publicClient.estimateFeesPerGas(),i=await this.publicClient.estimateGas({to:y,data:a,value:0n,account:this.account}),p=await this.walletClient.writeContract({account:this.account,address:y,abi:Z.abi,functionName:"mintWithSignature",args:[this.formatMintRequest(e.request),e.signature],chain:this.publicClient.chain,maxFeePerGas:u,maxPriorityFeePerGas:l,gas:i});return await this.publicClient.waitForTransactionReceipt({hash:p})}encodeTokenReceivedData(e){let n=H(P("AnchorERC1155")),t=e.signature.startsWith("0x")?e.signature:`0x${e.signature}`,y=this.formatMintRequest(e.request);console.log("Formatted request data:",JSON.stringify(y,(u,l)=>typeof l==="bigint"?l.toString():l)),console.log("Signature:",t);let a=A([{components:[{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"quantity",type:"uint256"},{name:"price",type:"uint256"},{name:"currency",type:"address"},{name:"validityStartTimestamp",type:"uint128"},{name:"validityEndTimestamp",type:"uint128"},{name:"uid",type:"bytes32"},{name:"chainId",type:"uint256"},{name:"projectHandle",type:"bytes32"}],name:"req",type:"tuple"},{name:"signature",type:"bytes"}],[y,t]);return console.log("Encoded userData:",a),c([n,a])}encodeTokenReceivedDataWithEmptyInterface(e){let n=H(P("")),t=e.signature.startsWith("0x")?e.signature:`0x${e.signature}`,y=this.formatMintRequest(e.request);console.log("Formatted request data (empty interface):",JSON.stringify(y,(u,l)=>typeof l==="bigint"?l.toString():l)),console.log("Signature:",t);let a=A([{components:[{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"quantity",type:"uint256"},{name:"price",type:"uint256"},{name:"currency",type:"address"},{name:"validityStartTimestamp",type:"uint128"},{name:"validityEndTimestamp",type:"uint128"},{name:"uid",type:"bytes32"},{name:"chainId",type:"uint256"},{name:"projectHandle",type:"bytes32"}],name:"req",type:"tuple"},{name:"signature",type:"bytes"}],[y,t]);return console.log("Encoded userData (empty interface):",a),c([n,a])}async multicall(e,n){if(!this.contracts?.anchorERC1155)throw Error("AnchorERC1155 contract address not set, please check network configuration");let t=this.contracts.anchorERC1155,y=ve({abi:s,functionName:"multicall",args:[e]});if(n?.sendTransaction===!1)return{to:t,data:y,value:0n};if(!this.walletClient||!this.account)throw Error("Wallet client and account are required to send transactions");let{maxFeePerGas:a,maxPriorityFeePerGas:u}=await this.publicClient.estimateFeesPerGas(),l=await this.publicClient.estimateGas({to:t,data:y,value:0n,account:this.account}),i=await this.walletClient.writeContract({account:this.account,address:t,abi:s,functionName:"multicall",args:[e],chain:this.publicClient.chain,maxFeePerGas:a,maxPriorityFeePerGas:u,gas:l});return await this.publicClient.waitForTransactionReceipt({hash:i})}formatMintRequest(e){let n;if(typeof e.uid==="string")if(e.uid.startsWith("0x"))n=e.uid;else n=H(P(e.uid));else n=e.uid;let t=BigInt(Math.floor(Date.now()/1000));return{to:e.to,tokenId:BigInt(e.tokenId),quantity:BigInt(e.quantity),price:BigInt(e.price),currency:e.currency,validityStartTimestamp:e.validityStartTimestamp?BigInt(e.validityStartTimestamp):t,validityEndTimestamp:e.validityEndTimestamp?BigInt(e.validityEndTimestamp):e.validUntil?BigInt(e.validUntil):t+3600n,uid:n,chainId:BigInt(e.chainId||this.network.id),projectHandle:e.projectHandle}}}var xe;((u)=>{u.Json="application/json";u.JsonApi="application/vnd.api+json";u.FormData="multipart/form-data";u.UrlEncoded="application/x-www-form-urlencoded";u.Text="text/plain"})(xe||={});class R{baseUrl="https://anchordev.dipbit.xyz/";securityData=null;securityWorker;abortControllers=new Map;customFetch=(...e)=>fetch(...e);baseApiParams={credentials:"same-origin",headers:{},redirect:"follow",referrerPolicy:"no-referrer"};constructor(e={}){Object.assign(this,e)}setSecurityData=(e)=>{this.securityData=e};encodeQueryParam(e,n){return`${encodeURIComponent(e)}=${encodeURIComponent(typeof n==="number"?n:`${n}`)}`}addQueryParam(e,n){return this.encodeQueryParam(n,e[n])}addArrayQueryParam(e,n){return e[n].map((y)=>this.encodeQueryParam(n,y)).join("&")}toQueryString(e){let n=e||{};return Object.keys(n).filter((y)=>typeof n[y]<"u").map((y)=>Array.isArray(n[y])?this.addArrayQueryParam(n,y):this.addQueryParam(n,y)).join("&")}addQueryParams(e){let n=this.toQueryString(e);return n?`?${n}`:""}contentFormatters={["application/json"]:(e)=>e!==null&&(typeof e==="object"||typeof e==="string")?JSON.stringify(e):e,["application/vnd.api+json"]:(e)=>e!==null&&(typeof e==="object"||typeof e==="string")?JSON.stringify(e):e,["text/plain"]:(e)=>e!==null&&typeof e!=="string"?JSON.stringify(e):e,["multipart/form-data"]:(e)=>{if(e instanceof FormData)return e;return Object.keys(e||{}).reduce((n,t)=>{let y=e[t];return n.append(t,y instanceof Blob?y:typeof y==="object"&&y!==null?JSON.stringify(y):`${y}`),n},new FormData)},["application/x-www-form-urlencoded"]:(e)=>this.toQueryString(e)};mergeRequestParams(e,n){return{...this.baseApiParams,...e,...n||{},headers:{...this.baseApiParams.headers||{},...e.headers||{},...n&&n.headers||{}}}}createAbortSignal=(e)=>{if(this.abortControllers.has(e)){let t=this.abortControllers.get(e);if(t)return t.signal;return}let n=new AbortController;return this.abortControllers.set(e,n),n.signal};abortRequest=(e)=>{let n=this.abortControllers.get(e);if(n)n.abort(),this.abortControllers.delete(e)};request=async({body:e,secure:n,path:t,type:y,query:a,format:u,baseUrl:l,cancelToken:i,...p})=>{let T=(typeof n==="boolean"?n:this.baseApiParams.secure)&&this.securityWorker&&await this.securityWorker(this.securityData)||{},m=this.mergeRequestParams(p,T),r=a&&this.toQueryString(a),b=this.contentFormatters[y||"application/json"],z=u||m.format;return this.customFetch(`${l||this.baseUrl||""}${t}${r?`?${r}`:""}`,{...m,headers:{...m.headers||{},...y&&y!=="multipart/form-data"?{"Content-Type":y}:{}},signal:(i?this.createAbortSignal(i):m.signal)||null,body:typeof e>"u"||e===null?null:b(e)}).then(async(O)=>{let x=O;x.data=null,x.error=null;let d=!z?x:await O[z]().then((v)=>{if(x.ok)x.data=v;else x.error=v;return x}).catch((v)=>{return x.error=v,x});if(i)this.abortControllers.delete(i);if(!O.ok)throw d;return d})}}class C extends R{s1={queryAssets:(e,n,t={})=>this.request({path:`/s1/assets/${e}`,method:"POST",body:n,type:"application/json",format:"json",...t}),grantBadge:(e,n={})=>this.request({path:"/s1/badges",method:"POST",body:e,type:"application/json",format:"json",...n}),badgesCheck:(e,n={})=>this.request({path:"/s1/badges/check",method:"POST",body:e,type:"application/json",format:"json",...n}),queryBadgesHolders:(e,n={})=>this.request({path:"/s1/badges/holders",method:"GET",query:e,format:"json",...n}),checkByEvent:(e,n={})=>this.request({path:"/s1/check/event",method:"POST",body:e,type:"application/json",format:"json",...n}),intervalReset:(e,n={})=>this.request({path:"/s1/interval/reset",method:"POST",body:e,type:"application/json",format:"json",...n}),getUserNftHoldingByDuration:(e,n={})=>this.request({path:"/s1/nft/holding-by-duration",method:"POST",body:e,type:"application/json",format:"json",...n}),getUserNftHoldingDurationSummary:(e,n={})=>this.request({path:"/s1/nft/holding-duration-summary",method:"POST",body:e,type:"application/json",format:"json",...n}),purchaseMint:(e,n,t={})=>this.request({path:`/s1/purchase/${e}`,method:"POST",body:n,type:"application/json",format:"json",...t}),getNftSeriesDetail:(e,n,t,y={})=>this.request({path:`/s1/series/${e}/${n}`,method:"GET",query:t,format:"json",...y}),createTeam:(e,n={})=>this.request({path:"/s1/teams",method:"POST",body:e,type:"application/json",format:"json",...n}),teamDetail:(e,n={})=>this.request({path:`/s1/teams/detail/${e}`,method:"GET",format:"json",...n}),joinTeam:(e,n={})=>this.request({path:"/s1/teams/join",method:"POST",body:e,type:"application/json",format:"json",...n}),leaveTeam:(e,n={})=>this.request({path:`/s1/teams/leave/${e}`,method:"DELETE",format:"json",...n}),removeTeamMember:(e,n,t={})=>this.request({path:`/s1/teams/remove/${e}/${n}`,method:"DELETE",format:"json",...t}),updateTeam:(e,n={})=>this.request({path:"/s1/teams/update",method:"PUT",body:e,type:"application/json",format:"json",...n}),updateSocialPrivacy:(e,n={})=>this.request({path:"/s1/teams/update/social-privacy",method:"PUT",body:e,type:"application/json",format:"json",...n}),updateTeamType:(e,n,t={})=>this.request({path:`/s1/teams/update/type/${e}`,method:"POST",query:n,format:"json",...t}),getTokenBalances:(e,n={})=>this.request({path:"/s1/token/balances",method:"POST",body:e,type:"application/json",format:"json",...n}),getWalletDexPairStates:(e,n={})=>this.request({path:"/s1/token/dex-pair-states",method:"POST",body:e,type:"application/json",format:"json",...n})};v1={getUserApplications:(e,n={})=>this.request({path:"/v1/applications/me",method:"GET",query:e,format:"json",...n}),acknowledgeApplication:(e,n={})=>this.request({path:`/v1/applications/${e}/acknowledge`,method:"POST",format:"json",...n}),approveApplication:(e,n={})=>this.request({path:`/v1/applications/${e}/approve`,method:"POST",format:"json",...n}),cancelApplication:(e,n={})=>this.request({path:`/v1/applications/${e}/cancel`,method:"POST",format:"json",...n}),denyApplication:(e,n,t={})=>this.request({path:`/v1/applications/${e}/deny`,method:"POST",body:n,type:"application/json",format:"json",...t}),badgeAssets:(e,n={})=>this.request({path:"/v1/badges",method:"GET",query:e,format:"json",...n}),getCheckResult:(e,n={})=>this.request({path:`/v1/check/${e}`,method:"GET",format:"json",...n}),check:(e,n={})=>this.request({path:`/v1/check/${e}`,method:"POST",format:"json",...n}),getNotifications:(e,n={})=>this.request({path:"/v1/notifications",method:"GET",query:e,format:"json",...n}),markNotificationRead:(e,n={})=>this.request({path:`/v1/notifications/${e}/read`,method:"POST",format:"json",...n}),searchMultiple:(e,n={})=>this.request({path:"/v1/search/multiple",method:"GET",query:e,format:"json",...n}),listSeasonConfig:(e={})=>this.request({path:"/v1/seasons",method:"GET",format:"json",...e}),nftSeries:(e,n={})=>this.request({path:`/v1/series/${e}`,method:"GET",format:"json",...n}),getNftSeriesById:(e,n,t,y={})=>this.request({path:`/v1/series/${e}/${n}`,method:"GET",query:t,format:"json",...y}),getTeamBadges:(e,n={})=>this.request({path:"/v1/teams/badges",method:"GET",query:e,format:"json",...n}),getBadgeContributors:(e,n={})=>this.request({path:`/v1/teams/badges/${e}/contributors`,method:"GET",format:"json",...n}),getTeamLeaderboard:(e,n={})=>this.request({path:"/v1/teams/leaderboard",method:"GET",query:e,format:"json",...n}),getMyTeamProfile:(e={})=>this.request({path:"/v1/teams/members/me",method:"GET",format:"json",...e}),getTeamApplications:(e,n,t={})=>this.request({path:`/v1/teams/${e}/applications`,method:"GET",query:n,format:"json",...t}),getTeamDetail:(e,n={})=>this.request({path:`/v1/teams/${e}/detail`,method:"GET",format:"json",...n}),getTeamMemberRanking:(e,n,t={})=>this.request({path:`/v1/teams/${e}/members/ranking`,method:"GET",query:n,format:"json",...t}),userOpHashProcess:(e,n={})=>this.request({path:"/v1/transaction/process/userOpHash",method:"POST",body:e,type:"application/json",format:"json",...n}),transactionHashProcess:(e,n={})=>this.request({path:`/v1/transaction/process/${e}`,method:"POST",format:"json",...n})};v2={queryBadges:(e,n={})=>this.request({path:"/v2/badges",method:"GET",query:e,format:"json",...n}),checkUserClaimableBadges:(e,n={})=>this.request({path:"/v2/badges",method:"POST",body:e,type:"application/json",format:"json",...n}),getUserBadgeAssets:(e,n={})=>this.request({path:"/v2/badges/assets",method:"GET",query:e,format:"json",...n}),categoriesList:(e,n={})=>this.request({path:"/v2/badges/categories",method:"GET",query:e,format:"json",...n}),categoriesDetail:(e,n,t={})=>this.request({path:`/v2/badges/categories/${e}`,method:"GET",query:n,format:"json",...t}),getUserClaimableBadges:(e,n={})=>this.request({path:"/v2/badges/claimable",method:"GET",query:e,format:"json",...n}),getBadgeSeries:(e,n={})=>this.request({path:"/v2/badges/series",method:"GET",query:e,format:"json",...n}),getBadgeSeriesDetail:(e,n,t={})=>this.request({path:`/v2/badges/series/${e}`,method:"GET",query:n,format:"json",...t}),getBadgeClaimSignatures:(e,n={})=>this.request({path:"/v2/badges/signatures",method:"POST",body:e,type:"application/json",format:"json",...n}),getBadgeVerifiers:(e,n={})=>this.request({path:"/v2/badges/verifiers",method:"GET",query:e,format:"json",...n}),getBadgeDetail:(e,n={})=>this.request({path:`/v2/badges/${e}`,method:"GET",format:"json",...n}),checkSingleBadgeClaimable:(e,n,t={})=>this.request({path:`/v2/badges/${e}`,method:"POST",body:n,type:"application/json",format:"json",...t}),batchMint:(e,n,t={})=>this.request({path:`/v2/batch/mint/${e}`,method:"POST",body:n,type:"application/json",format:"json",...t}),mint:(e,n,t={})=>this.request({path:`/v2/mint/${e}`,method:"POST",body:n,type:"application/json",format:"json",...t})}}class ${generatedApi;network;authToken;projectId;chainId;onTokenExpired;constructor(e){this.network=e.network,this.authToken=e.authToken,this.projectId=e.projectId,this.chainId=e.network.id.toString(),this.onTokenExpired=e.onTokenExpired,this.generatedApi=new C({baseUrl:e.apiBaseUrl.endsWith("/")?e.apiBaseUrl.slice(0,-1):e.apiBaseUrl})}setAuthToken(e){this.authToken=e}setTokenExpiredCallback(e){this.onTokenExpired=e}setProjectId(e){this.projectId=e}setChainId(e){this.chainId=e}createHeaders(){let e={"Content-Type":"application/json"};if(this.authToken)e.Authorization=`Bearer ${this.authToken}`,e.jwt_token=`${this.authToken}`;if(this.projectId)e["X-Project-Id"]=this.projectId,e.saas_id=this.projectId;if(this.chainId)e["X-Chain-Id"]=this.chainId,e.chain_id=this.chainId;return e}getRequestParams(){return{headers:this.createHeaders()}}async handleApiCall(e){try{let n=await e();if(this.isTokenExpiredResponse(n)){console.log("Token expired: JWT token is invalid or expired");let t=Error("Token expired: JWT token is invalid or expired");if(this.onTokenExpired)this.onTokenExpired(t);throw t}return n}catch(n){if(n?.status===401){if(this.onTokenExpired)this.onTokenExpired(n)}throw n}}isTokenExpiredResponse(e){if(e?.success===!1&&e?.code==="9101")return!0;if(e?.success===!1&&e?.msgKey==="params.jwt.check.invalid")return!0;return!1}async getBadgeVerifiers(e,n){return this.handleApiCall(async()=>{let t={platform:e,type:n};return(await this.generatedApi.v2.getBadgeVerifiers(t,this.getRequestParams())).data})}async getUserClaimableBadges(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getUserClaimableBadges(e,this.getRequestParams())).data})}async getUserBadgeAssets(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getUserBadgeAssets(e,this.getRequestParams())).data})}async getBadgeSeriesDetail(e,n){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getBadgeSeriesDetail(e,n,this.getRequestParams())).data})}async getBadgeDetail(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getBadgeDetail(e,this.getRequestParams())).data})}async checkSingleBadgeClaimable(e,n){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.checkSingleBadgeClaimable(e,n,this.getRequestParams())).data})}async checkUserClaimableBadges(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.checkUserClaimableBadges(e,this.getRequestParams())).data})}async queryBadges(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.queryBadges(e,this.getRequestParams())).data})}async categoriesDetail(e,n){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.categoriesDetail(e,n,this.getRequestParams())).data})}async categoriesList(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.categoriesList(e,this.getRequestParams())).data})}async getBadgeClaimSignatures(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getBadgeClaimSignatures(e,this.getRequestParams())).data})}async getBadgeSeries(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.getBadgeSeries(e,this.getRequestParams())).data})}async mint(e,n){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.mint(e,n,this.getRequestParams())).data})}async batchMint(e,n){return this.handleApiCall(async()=>{return(await this.generatedApi.v2.batchMint(e,n,this.getRequestParams())).data})}async transactionHashProcess(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v1.transactionHashProcess(e,this.getRequestParams())).data})}async userOpHashProcess(e){return this.handleApiCall(async()=>{return(await this.generatedApi.v1.userOpHashProcess(e,this.getRequestParams())).data})}}import Me,{createContext as we,useContext as Ue,useEffect as je,useState as Q}from"react";var q=we(void 0);function Oe({children:e,config:n}){let[t,y]=Q(null),[a,u]=Q(!0),[l,i]=Q(null),[p,T]=Q(!1);je(()=>{try{let d=new G(n);y(d),T(!0),i(null)}catch(d){i(d instanceof Error?d:Error("初始化 Anchor SDK 失败"))}finally{u(!1)}},[n.publicClient,n.walletClient,n.network.id,n.apiBaseUrl,n.authToken,n.projectId,n.env,n.anchorERC1155Address,n.anchorPayAddress]);let x={sdk:t,loading:a,error:l,initialized:p,setWalletClient:(d)=>{if(!t)throw Error("Anchor SDK not initialized");t.setWalletClient(d),y(t)},buyBadgeWithETH:async(d,v,I,E=1,V,B)=>{if(!t)throw Error("Anchor SDK not initialized");return await t.buyBadgeWithETH(d,v,I,E,V,B)},buyBadgeWithERC20:async(d,v,I,E=1,V,B,ae)=>{if(!t)throw Error("Anchor SDK not initialized");return await t.buyBadgeWithERC20(d,v,I,E,V,B,ae)},buyBadgeWithETHWithSignedRequest:async(d,v,I)=>{if(!t)throw Error("Anchor SDK not initialized");return await t.buyBadgeWithETHWithSignedRequest(d,v,I)},buyBadgeWithERC20WithSignedRequest:async(d,v,I)=>{if(!t)throw Error("Anchor SDK not initialized");return await t.buyBadgeWithERC20WithSignedRequest(d,v,I)}};return Me.createElement(q.Provider,{value:x},e)}var ee=()=>{let e=Ue(q);if(e===void 0)throw Error("useAnchorSDK must be used inside AnchorReactProvider");return e},ze=()=>{let{sdk:e,loading:n,error:t,initialized:y}=ee();return{loading:n,error:t,initialized:y,getClaimableBadges:async()=>{if(!e?.anchorApi)throw Error("Anchor API client not initialized");return await e.anchorApi.getUserBadgeAssets({includeClaimable:!0,strategy:"BADGE_ALL"})},getClaimedBadges:async()=>{if(!e?.anchorApi)throw Error("Anchor API client not initialized");return await e.anchorApi.getUserBadgeAssets({includeClaimable:!1,strategy:"BADGE_ALL"})},getNftSeries:async()=>{if(!e?.anchorApi)throw Error("Anchor API client not initialized");return await e.anchorApi.getBadgeSeries({includeBadges:!0,limit:100})},getNftSeriesById:async(p)=>{if(!e?.anchorApi)throw Error("Anchor API client not initialized");return await e.anchorApi.getBadgeSeriesDetail(p,{status:"active"})}}};class G{publicClient;walletClient;account;network;config;contracts;anchorPay;anchorERC1155;anchorApi;constructor(e){if(this.config=e,this.contracts={},"publicClient"in e&&e.publicClient)this.publicClient=e.publicClient,this.walletClient=e.walletClient,this.account=this.walletClient?.account,this.network=this.createChainFromNetwork(e.network);else{this.network=this.createChainFromNetwork(e.network),this.publicClient=this.initializePublicClient(e.provider);let t=e.signer||e.provider;this.walletClient=t?this.initializeWalletClient(t):void 0,this.account=this.walletClient?.account||this.getAccountFromSigner(t)}if(e.anchorPayAddress)this.contracts.anchorPay=e.anchorPayAddress;if(e.anchorERC1155Address)this.contracts.anchorERC1155=e.anchorERC1155Address;this.anchorPay=new S(this.publicClient,this.network,this.walletClient,this.account,this.contracts),this.anchorERC1155=new J(this.publicClient,this.network,this.walletClient,this.account,this.contracts);let n=e.apiBaseUrl;if(e.env&&X[e.env]){if(!n)n=X[e.env].apiBaseUrl;if(this.network.id&&X[e.env].contracts[this.network.id]){let t=X[e.env].contracts[this.network.id];if(!t)throw Error("no contracts");if(t.anchorPay&&!this.contracts.anchorPay)this.contracts.anchorPay=t.anchorPay;if(t.anchorERC1155&&!this.contracts.anchorERC1155)this.contracts.anchorERC1155=t.anchorERC1155;this.anchorPay=new S(this.publicClient,this.network,this.walletClient,this.account,this.contracts),this.anchorERC1155=new J(this.publicClient,this.network,this.walletClient,this.account,this.contracts)}}if(n)this.anchorApi=new $({apiBaseUrl:n,authToken:e.authToken,projectId:e.projectId,network:this.network,onTokenExpired:e.onTokenExpired})}setTokenExpiredCallback(e){if(this.anchorApi)this.anchorApi.setTokenExpiredCallback(e)}setWalletClient(e){if(e&&"account"in e)this.walletClient=e,this.account=e.account;else{let n=e||this.config.provider;this.walletClient=this.initializeWalletClient(n),this.account=this.walletClient?.account||this.getAccountFromSigner(n)}return this.anchorPay=new S(this.publicClient,this.network,this.walletClient,this.account,this.contracts),this.anchorERC1155=new J(this.publicClient,this.network,this.walletClient,this.account,this.contracts),console.log("SDK wallet client updated:",this.account),this}initializePublicClient(e){if(typeof e==="string")return ne({chain:this.network,transport:_e(e)});if(e&&typeof e==="object")return ne({chain:this.network,transport:F(e)});throw Error("Invalid provider. Please provide a valid RPC URL or Web3 Provider.")}initializeWalletClient(e){if(!e)return;if(e&&typeof e==="object"){if(e.selectedAddress)return te({chain:this.network,transport:F(e),account:e.selectedAddress});if(e.address)return te({chain:this.network,transport:F(e.provider||e),account:e.address})}return}getAccountFromSigner(e){if(!e)return;if(e.selectedAddress)return{address:e.selectedAddress,type:"json-rpc"};if(e.address)return{address:e.address,type:"json-rpc"};return}createChainFromNetwork(e){return{...e,nativeCurrency:e.nativeCurrency||{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:[typeof this.config.provider==="string"?this.config.provider:""]},public:{http:[typeof this.config.provider==="string"?this.config.provider:""]}}}}async buyBadgeWithETHWithSignedRequest(e,n,t){if(!e||!e.request||!e.signature)throw Error("signedRequest is required and must contain request and signature");if(!n||!f(n))throw Error("receiptAddress is required and must be a valid Ethereum address");if(t?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");if(this.validateMintRequest(e.request),e.request.currency!==_)throw Error("Currency must be ETH");let y=BigInt(e.request.price)*BigInt(e.request.quantity),a=this.anchorERC1155.encodeTokenReceivedData(e),u=await this.anchorPay.sendETH(n,y,a,t);if(t?.sendTransaction!==!1&&u&&typeof u==="object"&&"transactionHash"in u)try{await this.processTransactionHash(u.transactionHash)}catch(l){console.warn(`Failed to process transaction hash: ${l instanceof Error?l.message:String(l)}`)}return u}async buyBadgeWithERC20WithSignedRequest(e,n,t){if(!e||!e.request||!e.signature)throw Error("signedRequest is required and must contain request and signature");if(!n||!f(n))throw Error("receiptAddress is required and must be a valid Ethereum address");if(t?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");if(this.validateMintRequest(e.request),e.request.currency===_)throw Error("Currency cannot be native token");let y=BigInt(e.request.price)*BigInt(e.request.quantity),a=this.anchorERC1155.encodeTokenReceivedData(e),u=await this.anchorPay.sendERC20(n,e.request.currency,y,a,t);if(t?.sendTransaction!==!1&&u&&typeof u==="object"&&"transactionHash"in u)try{await this.processTransactionHash(u.transactionHash)}catch(l){console.warn(`Failed to process transaction hash: ${l instanceof Error?l.message:String(l)}`)}return u}async buyBadgeWithETH(e,n,t,y=1,a,u){if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!a||!f(a))throw Error("receiptAddress is required and must be a valid Ethereum address");if(t===void 0||t==="")throw Error("tokenId is required");if(BigInt(y.toString())<=0n)throw Error("quantity must be greater than 0");if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(u?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let i=[`${t.toString()}`],p=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:i});if(p.code!=="0000"||!p.obj||!p.obj.signatures||p.obj.signatures.length===0)throw Error(p.code||"Failed to get mint request from backend");let T=p.obj.signatures[0];if(!T)throw Error("Mint request missing required fields");let m={request:{to:e,tokenId:BigInt(T.badgeId||t),quantity:BigInt(T.quantity||y),price:BigInt(T.price||0),currency:T.currency,validityStartTimestamp:BigInt(T.validityStartTimestamp||Math.floor(Date.now()/1000)),validityEndTimestamp:BigInt(T.validityEndTimestamp||Math.floor(Date.now()/1000)+3600),uid:T.uid,chainId:BigInt(T.chainId||this.network.id),projectHandle:T.projectHandle},signature:T.signature};return await this.buyBadgeWithETHWithSignedRequest(m,a,u)}async buyBadgeWithETHWithCustomSignature(e,n,t){if(!e)throw Error("signedRequest is required");if(!e.to||!f(e.to))throw Error("signedRequest.to is required and must be a valid Ethereum address");if(e.tokenId===void 0||e.tokenId==="")throw Error("signedRequest.tokenId is required");if(e.quantity===void 0||BigInt(e.quantity.toString())<=0n)throw Error("signedRequest.quantity is required and must be greater than 0");if(e.price===void 0)throw Error("signedRequest.price is required");if(!e.uid)throw Error("signedRequest.uid is required");if(!e.signature)throw Error("signedRequest.signature is required");if(!e.chainId)throw Error("signedRequest.chainId is required");if(!n||!f(n))throw Error("receiptAddress is required and must be a valid Ethereum address");let y={request:{to:e.to,tokenId:BigInt(e.tokenId),quantity:BigInt(e.quantity),price:BigInt(e.price),currency:e.currency,validityStartTimestamp:BigInt(e.validityStartTimestamp||Math.floor(Date.now()/1000)+3600),validityEndTimestamp:BigInt(e.validityEndTimestamp||Math.floor(Date.now()/1000)+3600),uid:e.uid,chainId:BigInt(e.chainId||this.network.id),projectHandle:e.projectHandle},signature:e.signature.startsWith("0x")?e.signature:`0x${e.signature}`};return await this.buyBadgeWithETHWithSignedRequest(y,n,t)}async buyBadgeWithERC20(e,n,t,y=1,a,u,l){if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(l?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!u||!f(u))throw Error("receiptAddress is required and must be a valid Ethereum address");if(!a||!f(a))throw Error("currency is required and must be a valid ERC20 token address");if(t===void 0||t==="")throw Error("tokenId is required");if(BigInt(y.toString())<=0n)throw Error("quantity must be greater than 0");let p=[`${t.toString()}`],T=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:p});if(T.code!=="0000"||!T.obj||!T.obj.signatures||T.obj.signatures.length===0)throw Error(T.code||"Failed to get mint request from backend");let m=T.obj.signatures[0];if(!m)throw Error("Mint request missing required fields");if(!m.badgeId||!m.signature||!m.validityStartTimestamp||!m.validityEndTimestamp)throw Error("Mint request missing required fields");let r={request:{to:e,tokenId:BigInt(m.badgeId||t),quantity:BigInt(m.quantity||y),price:BigInt(m.price||0),currency:m.currency,validityStartTimestamp:BigInt(m.validityStartTimestamp||Math.floor(Date.now()/1000)),validityEndTimestamp:BigInt(m.validityEndTimestamp||Math.floor(Date.now()/1000)+3600),uid:m.uid,chainId:BigInt(m.chainId||this.network.id),projectHandle:m.projectHandle},signature:m.signature};return await this.buyBadgeWithERC20WithSignedRequest(r,u,l)}async buyBadgeWithERC20WithCustomSignature(e,n,t){if(!e)throw Error("signedRequest is required");if(!e.to||!f(e.to))throw Error("signedRequest.to is required and must be a valid Ethereum address");if(e.tokenId===void 0||e.tokenId==="")throw Error("signedRequest.tokenId is required");if(e.quantity===void 0||BigInt(e.quantity.toString())<=0n)throw Error("signedRequest.quantity is required and must be greater than 0");if(e.price===void 0)throw Error("signedRequest.price is required");if(!e.uid)throw Error("signedRequest.uid is required");if(!e.signature)throw Error("signedRequest.signature is required");if(!e.chainId)throw Error("signedRequest.chainId is required");if(!n||!f(n))throw Error("receiptAddress is required and must be a valid Ethereum address");let y={request:{to:e.to,tokenId:BigInt(e.tokenId),quantity:BigInt(e.quantity),price:BigInt(e.price),currency:e.currency,validityStartTimestamp:BigInt(e.validityStartTimestamp||Math.floor(Date.now()/1000)+3600),validityEndTimestamp:BigInt(e.validityEndTimestamp||Math.floor(Date.now()/1000)+3600),uid:e.uid,chainId:BigInt(e.chainId||this.network.id),projectHandle:e.projectHandle},signature:e.signature.startsWith("0x")?e.signature:`0x${e.signature}`};return await this.buyBadgeWithERC20WithSignedRequest(y,n,t)}async pay(e,n,t,y){if(!e||e.trim()==="")throw Error("orderId is required and cannot be empty");if(!t||!f(t))throw Error("receiptAddress is required and must be a valid Ethereum address");if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=typeof n==="string"||typeof n==="number"?ye(n.toString()):n,u=this.encodeUserData(e),l=N({abi:w,functionName:"send",args:[t,_,a,u]});if(y?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:l,value:a};let i=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:l,value:a}),p=await this.publicClient.waitForTransactionReceipt({hash:i});if(p&&typeof p==="object"&&"transactionHash"in p)try{await this.processTransactionHash(p.transactionHash)}catch(T){console.warn(`Failed to process transaction hash: ${T instanceof Error?T.message:String(T)}`)}return p}async sendPaymentWithNativeToken(e){let{callData:n,amount:t,receiptAddress:y,contractName:a,options:u}=e;if(!n||n.trim()==="")throw Error("callData is required and cannot be empty");if(!y||!f(y))throw Error("receiptAddress is required and must be a valid Ethereum address");if(u?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let l=typeof t==="string"||typeof t==="number"?ye(t.toString()):t,i=h(K(a||"")),p=W([i,n]),T=N({abi:w,functionName:"send",args:[y,_,l,p]});if(u?.sendTransaction===!1)return{to:this.contracts?.anchorPay||"",data:T,value:l};let m=await this.walletClient.sendTransaction({account:this.account,to:this.contracts?.anchorPay||"",data:T,value:l}),r=await this.publicClient.waitForTransactionReceipt({hash:m});if(r&&typeof r==="object"&&"transactionHash"in r)try{await this.processTransactionHash(r.transactionHash)}catch(b){console.warn(`Failed to process transaction hash: ${b instanceof Error?b.message:String(b)}`)}return r}async sendPaymentWithERC20(e){let{callData:n,amount:t,receiptAddress:y,tokenAddress:a,contractName:u,options:l}=e;if(!n||n.trim()==="")throw Error("callData is required and cannot be empty");if(!y||!f(y))throw Error("receiptAddress is required and must be a valid Ethereum address");if(!a||!f(a))throw Error("tokenAddress is required and must be a valid Ethereum address");let i=await this.publicClient.readContract({address:a,abi:U,functionName:"decimals"}),p=typeof t==="bigint"?t:BigInt(Math.floor(Number(t)*10**i)),T=h(K(u||""));console.log(`Interface hash: ${T}`);let m=W([T,n]);console.log(`callData: ${n}`),console.log(`Data: ${m}`);let r=await this.anchorPay.sendERC20(y,a,p,m,l);if(r&&typeof r==="object"&&"transactionHash"in r)try{await this.processTransactionHash(r.transactionHash)}catch(b){console.warn(`Failed to process transaction hash ${r.transactionHash} with Anchor API: ${b}`)}return r}encodeUserData(e){let n=h(K(""));console.log(n,"interfaceHash");let t=K(e);return console.log(W([n,t]),"concat"),W([n,t])}async mintFreeBadge(e,n,t,y){if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!t||!Array.isArray(t)||t.length===0)throw Error("tokenIds is required and must be a non-empty array");for(let l of t)if(!l||typeof l!=="string")throw Error("Each tokenId must be a non-empty string");if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:t});if(console.log(JSON.stringify(a)),a.code!=="0000"||!a.obj||!a.obj.signatures||a.obj.signatures.length===0)throw Error(a.code||"Failed to get mint request from backend");if(y?.sendTransaction===!1){let l=a.obj.signatures;return await Promise.all(l.map(async(p)=>{if(!p.badgeId||!p.signature||!p.validityStartTimestamp||!p.validityEndTimestamp)throw Error("Mint request missing required fields");let T={request:{to:e,tokenId:BigInt(p.badgeId),quantity:BigInt(p.quantity||1),price:BigInt(p.price||0),currency:p.currency,validityStartTimestamp:BigInt(p.validityStartTimestamp),validityEndTimestamp:BigInt(p.validityEndTimestamp),uid:p.uid,chainId:BigInt(p.chainId||this.network.id),projectHandle:p.projectHandle},signature:p.signature};if(this.validateMintRequest(T.request),BigInt(T.request.price)!==0n)throw Error("Free Badge price must be 0");return await this.anchorERC1155.mintWithSignature(T,n,{sendTransaction:!1})}))}let u=null;for(let l of a.obj.signatures){if(!l.badgeId||!l.signature||!l.validityStartTimestamp||!l.validityEndTimestamp){console.warn("铸造请求缺失必要字段",l);continue}let i={request:{to:e,tokenId:BigInt(l.badgeId),quantity:BigInt(l.quantity||1),price:BigInt(l.price||0),currency:l.currency,validityStartTimestamp:BigInt(l.validityStartTimestamp),validityEndTimestamp:BigInt(l.validityEndTimestamp),uid:l.uid,chainId:BigInt(l.chainId||this.network.id),projectHandle:l.projectHandle},signature:l.signature};if(this.validateMintRequest(i.request),BigInt(i.request.price)!==0n)throw Error("Free Badge price must be 0");console.log(i,"signedRequest");let p=await this.anchorERC1155.mintWithSignature(i,n,{sendTransaction:!0});if("transactionHash"in p){u=p;try{await this.processTransactionHash(p.transactionHash)}catch(T){console.warn(`Failed to process transaction hash: ${T instanceof Error?T.message:String(T)}`)}}else throw Error("Expected transaction receipt, but received transaction data")}if(!u)throw Error("No successful mint transaction");return u}async mintFreeBadgeWithSignedRequest(e,n){if(this.validateMintRequest(e.request),BigInt(e.request.price)!==0n)throw Error("Free Badge price must be 0");let t=await this.anchorERC1155.mintWithSignature(e,e?.request?.contractAddress,n);if(n?.sendTransaction!==!1&&t&&typeof t==="object"&&"transactionHash"in t)try{await this.processTransactionHash(t.transactionHash)}catch(y){console.warn(`Failed to process transaction hash: ${y instanceof Error?y.message:String(y)}`)}return t}getERC20ApprovalData(e,n,t){return this.anchorPay.getERC20ApprovalData(e,n,t)}validateMintRequest(e){if(!f(e.to))throw Error("Invalid recipient address");let n=Math.floor(Date.now()/1000),t=e.validityEndTimestamp;if(t&&BigInt(t)<BigInt(n))throw Error("Mint request expired");if(BigInt(e.quantity)<=0n)throw Error("Quantity must be greater than 0")}async processTransactionHash(e){try{if(this.anchorApi){let n=await this.anchorApi.transactionHashProcess(e);return console.log(`Transaction processing accelerated: ${e}`),n}}catch(n){console.warn(`Failed to accelerate transaction processing: ${n instanceof Error?n.message:String(n)}`)}return}async batchMintBadge(e,n,t,y){if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!Array.isArray(t)||t.length===0)throw Error("tokenIds is required and must be a non-empty array");for(let i of t)if(!i||typeof i!=="string")throw Error("Each tokenId must be a non-empty string");if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:t});if(a.code!=="0000"||!a.obj||!a.obj.signatures||a.obj.signatures.length===0)throw Error(a.code||"Failed to get batch mint request from backend");let u=a.obj.signatures;if(y?.sendTransaction===!1)return await Promise.all(u.map(async(p)=>{if(!p.badgeId||!p.signature||!p.validityStartTimestamp||!p.validityEndTimestamp)throw Error("Mint request missing required fields");let T={request:{to:e,tokenId:BigInt(p.badgeId),quantity:BigInt(p.quantity||1),price:BigInt(p.price||0),currency:p.currency,validityStartTimestamp:BigInt(p.validityStartTimestamp),validityEndTimestamp:BigInt(p.validityEndTimestamp),uid:p.uid,chainId:BigInt(p.chainId||this.network.id),projectHandle:p.projectHandle},signature:p.signature};return this.validateMintRequest(T.request),await this.anchorERC1155.mintWithSignature(T,n,{sendTransaction:!1})}));let l=null;for(let i of u){if(!i.badgeId||!i.signature||!i.validityStartTimestamp||!i.validityEndTimestamp){console.warn("铸造请求缺失必要字段",i);continue}let p={request:{to:e,tokenId:BigInt(i.badgeId),quantity:BigInt(i.quantity||1),price:BigInt(i.price||0),currency:i.currency,validityStartTimestamp:BigInt(i.validityStartTimestamp),validityEndTimestamp:BigInt(i.validityEndTimestamp),uid:i.uid,chainId:BigInt(i.chainId||this.network.id),projectHandle:i.projectHandle},signature:i.signature};this.validateMintRequest(p.request);let T=await this.anchorERC1155.mintWithSignature(p,n,{sendTransaction:!0});if("transactionHash"in T){l=T;try{await this.processTransactionHash(T.transactionHash)}catch(m){console.warn(`Failed to process transaction hash: ${m instanceof Error?m.message:String(m)}`)}}else throw Error("Expected transaction receipt, but received transaction data")}if(!l)throw Error("No successful mint transaction");return l}async batchMintBadgeWithMulticall(e,n,t,y){if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!Array.isArray(t)||t.length===0)throw Error("tokenIds is required and must be a non-empty array");if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:t});if(a.code!=="0000"||!a.obj||!a.obj.signatures||a.obj.signatures.length===0)throw Error(a.code||"Failed to get batch mint request from backend");let l=a.obj.signatures.map((p)=>{if(!p.badgeId||!p.signature||!p.validityStartTimestamp||!p.validityEndTimestamp)throw Error("Mint request missing required fields");let T={request:{to:e,tokenId:BigInt(p.badgeId),quantity:BigInt(p.quantity||1),price:BigInt(p.price||0),currency:p.currency,validityStartTimestamp:BigInt(p.validityStartTimestamp),validityEndTimestamp:BigInt(p.validityEndTimestamp),uid:p.uid,chainId:BigInt(p.chainId||this.network.id),projectHandle:p.projectHandle},signature:p.signature};return this.validateMintRequest(T.request),N({abi:s,functionName:"mintWithSignature",args:[this.anchorERC1155.formatMintRequest(T.request),T.signature]})}),i=await this.anchorERC1155.multicall(l,y);if(y?.sendTransaction!==!1&&i&&typeof i==="object"&&"transactionHash"in i)try{await this.processTransactionHash(i.transactionHash)}catch(p){console.warn(`Failed to process transaction hash: ${p instanceof Error?p.message:String(p)}`)}return i}async mintFreeBadgeWithMulticall(e,n,t,y){if(!this.anchorApi)throw Error("Anchor API client not initialized, please check apiBaseUrl configuration");if(!e||!f(e))throw Error("customerAddress is required and must be a valid Ethereum address");if(!n||!f(n))throw Error("contractAddress is required and must be a valid Ethereum address");if(!Array.isArray(t)||t.length===0)throw Error("tokenIds is required and must be a non-empty array");for(let i of t)if(!i||typeof i!=="string")throw Error("Each tokenId must be a non-empty string");if(y?.sendTransaction!==!1&&(!this.walletClient||!this.account))throw Error("Wallet client and account are required to send transactions");let a=await this.anchorApi.getBadgeClaimSignatures({customerAddress:e,badgeIds:t});if(a.code!=="0000"||!a.obj||!a.obj.signatures||a.obj.signatures.length===0)throw Error(a.code||"Failed to get mint request from backend");let u=a.obj.signatures.map((i)=>{if(!i.badgeId||!i.signature||!i.validityStartTimestamp||!i.validityEndTimestamp)throw Error("Mint request missing required fields");let p={request:{to:e,tokenId:BigInt(i.badgeId),quantity:BigInt(i.quantity||1),price:BigInt(i.price||0),currency:i.currency,validityStartTimestamp:BigInt(i.validityStartTimestamp),validityEndTimestamp:BigInt(i.validityEndTimestamp),uid:i.uid,chainId:BigInt(i.chainId||this.network.id),projectHandle:i.projectHandle},signature:i.signature};if(this.validateMintRequest(p.request),BigInt(p.request.price)!==0n)throw Error("Free Badge price must be 0");return N({abi:s,functionName:"mintWithSignature",args:[this.anchorERC1155.formatMintRequest(p.request),p.signature]})}),l=await this.anchorERC1155.multicall(u,y);if(y?.sendTransaction!==!1&&l&&typeof l==="object"&&"transactionHash"in l)try{await this.processTransactionHash(l.transactionHash)}catch(i){console.warn(`Failed to process transaction hash: ${i instanceof Error?i.message:String(i)}`)}return l}}export{ee as useAnchorSDK,ze as useAnchorBadge,_ as NATIVE_TOKEN_ADDRESS,j as MULTICALL3_ADDRESS,Y as MULTICALL3_ABI,Ie as INTERFACE_HASHES,R as HttpClient,re as Environment,U as ERC20_ABI,X as ENVIRONMENTS,xe as ContentType,C as Api,G as AnchorSDK,Oe as AnchorReactProvider,S as AnchorPayClient,J as AnchorERC1155Client,$ as AnchorApiClientV2};
2
2
 
3
- //# debugId=6F72C53764B95F2764756E2164756E21
3
+ //# debugId=7387F6DCF745049064756E2164756E21