@nexus-cross/pop 1.4.1-beta.6 → 1.4.1-beta.7

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/AGENTS.md CHANGED
@@ -158,7 +158,7 @@ await safeDrop.refund({ claimAddress, sponsor: address });
158
158
 
159
159
  ```ts
160
160
  const { txHashes, recipient } = await safeDrop.batchClaim({
161
- id: myHandle, // normalized internally
161
+ id: myHandle, // API/result preserve it; contract calls normalize it
162
162
  oauth, // X OAuth proof (handle ownership)
163
163
  sponsor: sender,
164
164
  claimAddress,
@@ -224,8 +224,7 @@ The SDK does not wrap it — use `EventSource` directly. Delivery is best-effort
224
224
  `maxBatchGas`; calibrate these values below the chain block gas limit.
225
225
  6. **`message` ≤ 140 runes** (code points) and `envelopeId` must come from `listEnvelopes()`;
226
226
  otherwise the backend rejects with `INVALID_PARAM` / `ENVELOPE_NOT_FOUND`.
227
- 7. **Handles are normalized** by the SDK (`normalizeHandle`); pass the same handle to deposit and
228
- to the API — do not hand-roll a second normalization.
227
+ 7. **Handle API values are preserved; contract calls are normalized** by `normalizeHandle`.
229
228
  8. **Drops are keyed by bytes32.** Resolve `activeDropOf(claimAddress)` before `drops(dropKey)`.
230
229
 
231
230
  ## 7. API surface
@@ -81,7 +81,7 @@ interface RefundResult {
81
81
  readonly txHash: Hex;
82
82
  }
83
83
  interface BatchClaimParams {
84
- /** 소셜 식별자(내 핸들). 내부에서 normalizeHandle을 거친다. */
84
+ /** 소셜 식별자(내 X 핸들). 입력한 값을 그대로 사용한다. */
85
85
  id: Id;
86
86
  /** 핸들 소유 증명용 X OAuth 토큰. 서명 발급의 전제. */
87
87
  oauth: OAuthProof;
@@ -1,8 +1,8 @@
1
- import { C as CryptoPort, b as ClaimSignerPort, a as SafeDropChainPort, O as OnePopDrop, D as DropState, S as SafeDrop } from '../createSafeDrop-BGoIQ4nK.js';
2
- import { S as Secret, a as SecretHash, H as Hex, A as Address, I as Id, m as SafeDropApiPort } from '../SafeDropApiPort-B7NfQOsb.js';
1
+ import { C as CryptoPort, b as ClaimSignerPort, a as SafeDropChainPort, O as OnePopDrop, D as DropState, S as SafeDrop } from '../createSafeDrop-BFooPsSR.js';
2
+ import { S as Secret, a as SecretHash, H as Hex, A as Address, I as Id, m as SafeDropApiPort } from '../SafeDropApiPort-BwcuQkf0.js';
3
3
  import { PublicClient, WalletClient, Chain, Transport, Abi } from 'viem';
4
- import { H as HttpSafeDropApiAdapterOptions } from '../index-DVeDD7Dp.js';
5
- export { C as CrossAuthClient, a as CrossAuthClientOptions, D as DEFAULT_POP_API_PATHS, b as HttpSafeDropApiAdapter, c as HttpXAuthAdapter, d as HttpXAuthAdapterOptions, O as ONE_POP_BPS_DENOMINATOR, e as ONE_POP_DEPLOYMENTS, f as ONE_POP_FEE_BPS, P as Pkce, g as PopApiPaths, h as PopContracts, i as PopDeployment, j as PopEnvironment, S as SessionStore, X as XAuthClient, k as XAuthClientOptions, l as generatePkce, m as generateState, n as getCrossAuthBaseUrl, o as getOnePopApiBaseUrl, p as getOnePopContracts, q as getOnePopDeployment, r as getPopEnvironment } from '../index-DVeDD7Dp.js';
4
+ import { H as HttpSafeDropApiAdapterOptions } from '../index-Dljcnddn.js';
5
+ export { C as CrossAuthClient, a as CrossAuthClientOptions, D as DEFAULT_POP_API_PATHS, b as HttpSafeDropApiAdapter, c as HttpXAuthAdapter, d as HttpXAuthAdapterOptions, O as ONE_POP_BPS_DENOMINATOR, e as ONE_POP_DEPLOYMENTS, f as ONE_POP_FEE_BPS, P as Pkce, g as PopApiPaths, h as PopContracts, i as PopDeployment, j as PopEnvironment, S as SessionStore, X as XAuthClient, k as XAuthClientOptions, l as generatePkce, m as generateState, n as getCrossAuthBaseUrl, o as getOnePopApiBaseUrl, p as getOnePopContracts, q as getOnePopDeployment, r as getPopEnvironment } from '../index-Dljcnddn.js';
6
6
  import '../XAuthPort-BNJePosj.js';
7
7
 
8
8
  /**
@@ -1 +1 @@
1
- import{j as N}from"../chunk-M7FFQCP2.js";import{a as Z,b as q,c as $,d as X,e as j,g as Y,h as D,i as z,j as J,k as P,l as Q,m as ee,n as te,o as ne,p as ie}from"../chunk-ENB6CCH7.js";import{a as d}from"../chunk-5DT3H2VX.js";import{bytesToHex as ae,keccak256 as se,recoverAddress as re,toBytes as pe}from"viem";var l=class{keccak256(e){return se(pe(e))}randomSecret(){let e=new Uint8Array(32);return de().getRandomValues(e),ae(e).slice(2)}recoverAddress(e){return re({hash:e.digest,signature:e.signature})}};function de(){let r=globalThis.crypto;if(!r||typeof r.getRandomValues!="function")throw new Error("Secure crypto RNG (globalThis.crypto.getRandomValues) is unavailable");return r}import{serializeSignature as oe,sign as ye}from"viem/accounts";var h=class{async signDigest(e){try{let t=await ye({hash:e.digest,privateKey:e.claimKey});return oe(t)}catch(t){throw new d("SIGN_FAILED","Failed to sign claim digest with temp key",{cause:t instanceof Error?t.message:String(t)})}}};import{BaseError as G,ContractFunctionRevertedError as K,createWalletClient as ce,http as me,keccak256 as I,parseEventLogs as le,parseSignature as B,toBytes as f,toHex as V}from"viem";import{privateKeyToAccount as he,serializeSignature as _,sign as F}from"viem/accounts";var E=[{name:"sponsor",type:"address"},{name:"amount",type:"uint96"},{name:"claimAddr",type:"address"},{name:"recipient",type:"address"},{name:"secretHash",type:"bytes32"},{name:"id",type:"string"}],S=[{name:"dropKeys",type:"bytes32[]"},{name:"records",type:"tuple[]",components:E}],ue=["AlreadyMapped","AmountOverflow","BelowMinDeposit","ChangeAlreadyRequested","ChangeInProgress","CountExceedsPending","DropAlreadyExists","DropNotFound","ECDSAInvalidSignature","EmptyId","IdMismatch","IdNotMapped","InvalidClaimSignature","InvalidExecutor","InvalidShortString","InvalidValidatorNonce","InvalidValidatorSignature","NoPendingChange","NotRecipient","NotSponsor","PendingLimitExceeded","RecipientNotEmpty","ReentrancyGuardReentrantCall","SameRecipient","SecretMismatch","TokenNotEighteenDecimals","ValidatorSigExpired","ZeroAmount","ZeroClaimAddress","ZeroCount","ZeroFeeRecipient","ZeroRecipient","ZeroSbt","ZeroSecretHash","ZeroToken","ZeroValidator"],R=[...ue.map(r=>({type:"error",name:r,inputs:[]})),{type:"error",name:"ECDSAInvalidSignatureLength",inputs:[{name:"length",type:"uint256"}]},{type:"error",name:"ECDSAInvalidSignatureS",inputs:[{name:"s",type:"bytes32"}]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{name:"token",type:"address"}]},{type:"error",name:"StringTooLong",inputs:[{name:"str",type:"string"}]}],s=[{type:"event",name:"Deposited",inputs:[{name:"addr",type:"address",indexed:!0},{name:"sponsor",type:"address",indexed:!0},{name:"dropKey",type:"bytes32",indexed:!0},{name:"amount",type:"uint256",indexed:!1},{name:"id",type:"string",indexed:!1},{name:"secretHash",type:"bytes32",indexed:!1},{name:"token",type:"address",indexed:!1}],anonymous:!1},{type:"function",name:"activeDropOf",stateMutability:"view",inputs:[{name:"sponsor",type:"address"},{name:"claimAddr",type:"address"}],outputs:[{type:"bytes32"}]},{type:"function",name:"drops",stateMutability:"view",inputs:[{name:"dropKey",type:"bytes32"}],outputs:E},{type:"function",name:"token",stateMutability:"view",inputs:[],outputs:[{type:"address"}]},{type:"function",name:"claimDigest",stateMutability:"view",inputs:[{name:"recipient",type:"address"},{name:"id",type:"string"},{name:"dropKey",type:"bytes32"}],outputs:[{type:"bytes32"}]},{type:"function",name:"anchorClaimDigest",stateMutability:"view",inputs:[{name:"recipient",type:"address"},{name:"id",type:"string"},{name:"dropKey",type:"bytes32"}],outputs:[{type:"bytes32"}]},{type:"function",name:"claimedRecipientOf",stateMutability:"view",inputs:[{name:"id",type:"string"}],outputs:[{type:"address"}]},{type:"function",name:"pendingDropsByXid",stateMutability:"view",inputs:[{name:"id",type:"string"}],outputs:S},{type:"function",name:"pendingDropsByRecipient",stateMutability:"view",inputs:[{name:"recipient",type:"address"}],outputs:S},{type:"function",name:"pendingDropsOf",stateMutability:"view",inputs:[{name:"sponsor",type:"address"}],outputs:S},{type:"function",name:"depositMapped",stateMutability:"nonpayable",inputs:[{name:"amount",type:"uint256"},{name:"id",type:"string"},{name:"permitDeadline",type:"uint256"},{name:"v",type:"uint8"},{name:"r",type:"bytes32"},{name:"s",type:"bytes32"}],outputs:[]},{type:"function",name:"withdrawUnmapped",stateMutability:"nonpayable",inputs:[{name:"recipient",type:"address"},{name:"id",type:"string"},{name:"dropKey",type:"bytes32"},{name:"signature",type:"bytes"},{name:"secret",type:"bytes"}],outputs:[]},{type:"function",name:"withdrawUnmappedBatchByKeys",stateMutability:"nonpayable",inputs:[{name:"recipient",type:"address"},{name:"id",type:"string"},{name:"anchorDropKey",type:"bytes32"},{name:"signature",type:"bytes"},{name:"secret",type:"bytes"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"},{name:"executor",type:"address"},{name:"dropKeys",type:"bytes32[]"},{name:"validatorSignature",type:"bytes"}],outputs:[]},{type:"function",name:"withdrawMapped",stateMutability:"nonpayable",inputs:[{name:"dropKey",type:"bytes32"}],outputs:[]},{type:"function",name:"batchWithdrawMapped",stateMutability:"nonpayable",inputs:[{name:"count",type:"uint256"}],outputs:[]},{type:"function",name:"batchWithdrawMapped",stateMutability:"nonpayable",inputs:[{name:"dropKeys",type:"bytes32[]"}],outputs:[]},{type:"function",name:"refund",stateMutability:"nonpayable",inputs:[{name:"dropKey",type:"bytes32"}],outputs:[]},{type:"function",name:"changeNonceById",stateMutability:"view",inputs:[{name:"idKey",type:"bytes32"}],outputs:[{type:"uint256"}]},{type:"function",name:"pendingRecipientChange",stateMutability:"view",inputs:[{name:"idKey",type:"bytes32"}],outputs:[{name:"newRecipient",type:"address"}]},{type:"function",name:"requestRecipientChange",stateMutability:"nonpayable",inputs:[{name:"id",type:"string"},{name:"newRecipient",type:"address"}],outputs:[]},{type:"function",name:"completeRecipientChange",stateMutability:"nonpayable",inputs:[{name:"id",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"},{name:"validatorSignature",type:"bytes"}],outputs:[]},{type:"function",name:"cancelRecipientChange",stateMutability:"nonpayable",inputs:[{name:"id",type:"string"}],outputs:[]},{type:"function",name:"resetRecipient",stateMutability:"nonpayable",inputs:[{name:"id",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"},{name:"validatorSignature",type:"bytes"}],outputs:[]},...R];var T=[{type:"function",name:"deposit",stateMutability:"nonpayable",inputs:[{name:"claimAddr",type:"address"},{name:"amount",type:"uint256"},{name:"id",type:"string"},{name:"secretHash",type:"bytes32"},{name:"deadline",type:"uint256"},{name:"v",type:"uint8"},{name:"r",type:"bytes32"},{name:"s",type:"bytes32"}],outputs:[]},{type:"function",name:"token",stateMutability:"view",inputs:[],outputs:[{type:"address"}]},...R],b=[{type:"function",name:"name",stateMutability:"view",inputs:[],outputs:[{type:"string"}]},{type:"function",name:"nonces",stateMutability:"view",inputs:[{name:"owner",type:"address"}],outputs:[{type:"uint256"}]},{type:"function",name:"eip712Domain",stateMutability:"view",inputs:[],outputs:[{name:"fields",type:"bytes1"},{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"},{name:"salt",type:"bytes32"},{name:"extensions",type:"uint256[]"}]}],H={Permit:[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]};var g=[{type:"function",name:"validator",stateMutability:"view",inputs:[],outputs:[{type:"address"}]},{type:"function",name:"validatorClaimDigest",stateMutability:"view",inputs:[{name:"executor",type:"address"},{name:"recipient",type:"address"},{name:"id",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}],outputs:[{type:"bytes32"}]},{type:"function",name:"validatorNonceById",stateMutability:"view",inputs:[{name:"idHash",type:"bytes32"}],outputs:[{type:"uint256"}]},{type:"function",name:"claimedRecipientOf",stateMutability:"view",inputs:[{name:"id",type:"string"}],outputs:[{type:"address"}]},{type:"error",name:"ValidatorSigExpired",inputs:[]},{type:"error",name:"InvalidValidatorNonce",inputs:[]}];var be="0x0000000000000000000000000000000000000000",ge=`0x${"00".repeat(32)}`,fe={gas:BigInt(1e6),batchBaseGas:BigInt(1e6),batchGasPerDrop:BigInt(75e4),maxBatchGas:BigInt(3e7),maxFeePerGas:BigInt(4e9),maxPriorityFeePerGas:BigInt(1e9)},k=BigInt(1800),w=class{constructor(e){if(this.address=e.address,this.publicClient=e.publicClient,this.walletClient=e.walletClient,this.chain=e.chain,this.transport=e.transport??me(),this.transactionFees={...fe,...e.withdrawFees,...e.transactionFees},this.transactionFees.gas<=BigInt(0)||this.transactionFees.batchBaseGas<=BigInt(0)||this.transactionFees.batchGasPerDrop<=BigInt(0)||this.transactionFees.maxBatchGas<=BigInt(0)||this.transactionFees.maxFeePerGas<=BigInt(0)||this.transactionFees.maxPriorityFeePerGas<=BigInt(0)||this.transactionFees.maxPriorityFeePerGas>this.transactionFees.maxFeePerGas)throw new d("INVALID_PARAM","invalid EIP-1559 gas configuration");this.depositWithPermit=t=>this.permitDeposit(t)}async getDropByKey(e){try{let[t,n,i,a,o,y]=await this.publicClient.readContract({address:this.address,abi:s,functionName:"drops",args:[e]});return t.toLowerCase()===be?null:{dropKey:e,sponsor:t,amount:n,claimAddress:i,recipient:a,secretHash:o,id:y}}catch(t){throw p("drops",t)}}async getDropKeyByClaimAddress(e,t){try{let n=await this.publicClient.readContract({address:this.address,abi:s,functionName:"activeDropOf",args:[t,e]});return n===ge?null:n}catch(n){throw p("activeDropOf",n)}}async getPendingDropsById(e){try{let[t,n]=await this.publicClient.readContract({address:this.address,abi:s,functionName:"pendingDropsByXid",args:[e.id]});return n.map((i,a)=>M(t[a],i))}catch(t){throw p("pendingDropsByXid",t)}}async getPendingDropsByRecipient(e){try{let[t,n]=await this.publicClient.readContract({address:this.address,abi:s,functionName:"pendingDropsByRecipient",args:[e.recipient]});return n.map((i,a)=>M(t[a],i))}catch(t){throw p("pendingDropsByRecipient",t)}}async getPendingDropsBySponsor(e){try{let[t,n]=await this.publicClient.readContract({address:this.address,abi:s,functionName:"pendingDropsOf",args:[e.sponsor]});return n.map((i,a)=>M(t[a],i))}catch(t){throw p("pendingDropsOf",t)}}async getDrop(e,t){let n=await this.getDropKeyByClaimAddress(e,t);if(!n)return null;let[i,a]=await Promise.all([this.getDropByKey(n),this.escrowToken()]);return i&&a?{...i,token:a}:null}async escrowToken(){try{return await this.publicClient.readContract({address:this.address,abi:T,functionName:"token"})}catch{throw new d("CHAIN_ERROR","token() failed")}}async getClaimDigest(e){try{return await this.publicClient.readContract({address:this.address,abi:s,functionName:"claimDigest",args:[e.recipient,e.id,e.dropKey]})}catch(t){throw p("claimDigest",t)}}async permitDeposit(e){try{let t=this.requireAccount(),n=e.token,[i,a,o]=await Promise.all([this.publicClient.readContract({address:this.address,abi:T,functionName:"token"}),this.publicClient.readContract({address:n,abi:b,functionName:"nonces",args:[t.address]}),this.permitDomain(n)]);if(i.toLowerCase()!==n.toLowerCase())throw new d("INVALID_TOKEN","token does not match the escrow token",{expected:i,received:e.token});let y=BigInt(Math.floor(Date.now()/1e3))+k,u=await this.walletClient.signTypedData({account:t,domain:{...o,chainId:this.chain.id,verifyingContract:n},types:H,primaryType:"Permit",message:{owner:t.address,spender:this.address,value:e.amount,nonce:a,deadline:y}}),{r:C,s:x,v:A,yParity:v}=B(u),c=await this.walletClient.writeContract({address:this.address,abi:T,functionName:"deposit",args:[e.claimAddress,e.amount,e.id,e.secretHash,y,Number(A??BigInt(v+27)),C,x],account:t,chain:this.chain,...this.transactionOverrides()});await e.onSubmitted?.(c);let m=await this.confirm("depositWithPermit",c);return{txHash:c,dropKey:this.depositedDropKey(m.logs,t.address,e.amount,e.id,c)}}catch(t){throw p("depositWithPermit",t)}}async depositMapped(e){try{let t=this.requireAccount(),n=e.token,[i,a,o]=await Promise.all([this.publicClient.readContract({address:this.address,abi:s,functionName:"token"}),this.publicClient.readContract({address:n,abi:b,functionName:"nonces",args:[t.address]}),this.permitDomain(n)]);if(i.toLowerCase()!==n.toLowerCase())throw new d("INVALID_TOKEN","token does not match the escrow token",{expected:i,received:e.token});let y=BigInt(Math.floor(Date.now()/1e3))+k,u=await this.walletClient.signTypedData({account:t,domain:{...o,chainId:this.chain.id,verifyingContract:n},types:H,primaryType:"Permit",message:{owner:t.address,spender:this.address,value:e.amount,nonce:a,deadline:y}}),{r:C,s:x,v:A,yParity:v}=B(u),c=[e.amount,e.id,y,Number(A??BigInt(v+27)),C,x];await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"depositMapped",args:c,account:t});let m=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"depositMapped",args:c,account:t,chain:this.chain,...this.transactionOverrides()});await e.onSubmitted?.(m);let U=await this.confirm("depositMapped",m);return{txHash:m,dropKey:this.depositedDropKey(U.logs,t.address,e.amount,e.id,m)}}catch(t){throw p("depositMapped",t)}}async permitDomain(e){try{let t=await this.publicClient.readContract({address:e,abi:b,functionName:"eip712Domain"});return{name:t[1],version:t[2]}}catch{return{name:await this.publicClient.readContract({address:e,abi:b,functionName:"name"}),version:"1"}}}async withdrawUnmapped(e){try{let t=he(e.claimKey),n=await this.publicClient.readContract({address:this.address,abi:s,functionName:"claimDigest",args:[e.recipient,e.id,e.dropKey]}),i=e.signature??_(await F({hash:n,privateKey:e.claimKey})),o=await ce({account:t,chain:this.chain,transport:this.transport}).writeContract({address:this.address,abi:s,functionName:"withdrawUnmapped",args:[e.recipient,e.id,e.dropKey,i,V(f(e.secret))],...this.transactionOverrides()});return await e.onSubmitted?.(o),await this.confirm("withdrawUnmapped",o),o}catch(t){throw L("withdrawUnmapped",t)}}async withdrawMapped(e){let t=this.requireAccount();try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"withdrawMapped",args:[e.dropKey],account:t});let n=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"withdrawMapped",args:[e.dropKey],account:t,chain:this.chain,...this.transactionOverrides()});return await e.onSubmitted?.(n),await this.confirm("withdrawMapped",n),n}catch(n){throw p("withdrawMapped",n)}}async batchWithdrawMapped(e){if(!Number.isSafeInteger(e.count)||e.count<=0)throw new d("INVALID_PARAM","count must be a positive safe integer");let t=this.batchTransactionOverrides(e.count),n=this.requireAccount();try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"batchWithdrawMapped",args:[BigInt(e.count)],account:n});let i=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"batchWithdrawMapped",args:[BigInt(e.count)],account:n,chain:this.chain,...t});return await this.confirm("batchWithdrawMapped",i),i}catch(i){throw p("batchWithdrawMapped",i)}}async batchWithdrawMappedByKeys(e){if(!e.dropKeys.length)throw new d("INVALID_PARAM","dropKeys must not be empty");let t=this.batchTransactionOverrides(e.dropKeys.length),n=this.requireAccount(),i=[e.dropKeys];try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"batchWithdrawMapped",args:i,account:n});let a=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"batchWithdrawMapped",args:i,account:n,chain:this.chain,...t});return await this.confirm("batchWithdrawMapped",a),a}catch(a){throw p("batchWithdrawMapped",a)}}async withdrawUnmappedBatchByKeys(e){let t=e.dropKeys.filter(a=>a.toLowerCase()!==e.anchorDropKey.toLowerCase()),n=this.batchTransactionOverrides(t.length+1),i=this.requireAccount();try{let a=await this.publicClient.readContract({address:this.address,abi:s,functionName:"anchorClaimDigest",args:[e.recipient,e.id,e.anchorDropKey]}),o=_(await F({hash:a,privateKey:e.claimKey})),y=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"withdrawUnmappedBatchByKeys",args:[e.recipient,e.id,e.anchorDropKey,o,V(f(e.secret)),e.nonce,e.deadline,e.executor,t,e.validatorSignature],account:i,chain:this.chain,...n});return await this.confirm("withdrawUnmappedBatchByKeys",y),y}catch(a){throw L("withdrawUnmappedBatchByKeys",a)}}async getValidatorNonce(e){try{return await this.publicClient.readContract({address:this.address,abi:g,functionName:"validatorNonceById",args:[I(f(e.id))]})}catch(t){throw p("validatorNonceById",t)}}async getValidatorClaimDigest(e){try{return await this.publicClient.readContract({address:this.address,abi:g,functionName:"validatorClaimDigest",args:[e.executor,e.recipient,e.id,e.nonce,e.deadline]})}catch(t){throw p("validatorClaimDigest",t)}}async getValidator(){try{return await this.publicClient.readContract({address:this.address,abi:g,functionName:"validator"})}catch(e){throw p("validator",e)}}async getClaimedRecipient(e){try{return await this.publicClient.readContract({address:this.address,abi:s,functionName:"claimedRecipientOf",args:[e.id]})}catch(t){throw p("claimedRecipientOf",t)}}async refundByKey(e){let t=this.requireAccount();try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"refund",args:[e.dropKey],account:t});let n=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"refund",args:[e.dropKey],account:t,chain:this.chain,...this.transactionOverrides()});return await this.confirm("refund",n),n}catch(n){throw p("refund",n)}}async getChangeNonce(e){try{return await this.publicClient.readContract({address:this.address,abi:s,functionName:"changeNonceById",args:[I(f(e.id))]})}catch(t){throw p("changeNonceById",t)}}async getPendingRecipientChange(e){try{return await this.publicClient.readContract({address:this.address,abi:s,functionName:"pendingRecipientChange",args:[I(f(e.id))]})}catch(t){throw p("pendingRecipientChange",t)}}async requestRecipientChange(e){return this.currentContractWrite("requestRecipientChange",[e.id,e.newRecipient])}async completeRecipientChange(e){return this.currentContractWrite("completeRecipientChange",[e.id,e.nonce,e.deadline,e.signature])}async cancelRecipientChange(e){return this.currentContractWrite("cancelRecipientChange",[e.id])}async resetRecipient(e){let t=this.requireAccount();try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"resetRecipient",args:[e.id,e.nonce,e.deadline,e.signature],account:t});let n=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"resetRecipient",args:[e.id,e.nonce,e.deadline,e.signature],account:t,chain:this.chain,...this.transactionOverrides()});return await this.confirm("resetRecipient",n),n}catch(n){throw p("resetRecipient",n)}}async currentContractWrite(e,t){let n=this.requireAccount();try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:e,args:t,account:n});let i=await this.walletClient.writeContract({address:this.address,abi:s,functionName:e,args:t,account:n,chain:this.chain,...this.transactionOverrides()});return await this.confirm(e,i),i}catch(i){throw p(e,i)}}transactionOverrides(e=this.transactionFees.gas){return{type:"eip1559",gas:e,maxFeePerGas:this.transactionFees.maxFeePerGas,maxPriorityFeePerGas:this.transactionFees.maxPriorityFeePerGas}}batchTransactionOverrides(e){if(!Number.isSafeInteger(e)||e<=0)throw new d("INVALID_PARAM","batch count must be a positive safe integer");let t=this.transactionFees.batchBaseGas+this.transactionFees.batchGasPerDrop*BigInt(e);if(t>this.transactionFees.maxBatchGas)throw new d("INVALID_PARAM","batch gas exceeds maxBatchGas",{count:e,gas:t.toString(),maxBatchGas:this.transactionFees.maxBatchGas.toString()});return this.transactionOverrides(t)}async sponsorWrite(e,t){try{let n=await t();return await this.confirm(e,n),n}catch(n){throw p(e,n)}}depositedDropKey(e,t,n,i,a){let o=le({abi:s,eventName:"Deposited",logs:[...e]}).find(({address:y,args:u})=>y.toLowerCase()===this.address.toLowerCase()&&u.sponsor.toLowerCase()===t.toLowerCase()&&u.amount===n&&u.id===i);if(!o)throw new d("CHAIN_ERROR","deposit receipt omitted the Deposited event",{txHash:a});return o.args.dropKey}async confirm(e,t){let n=await this.publicClient.waitForTransactionReceipt({hash:t});if(n.status!=="success"){let i=await this.recoverRevertName(t,n.blockNumber),a=i?`SafeDrop.${e} reverted: ${i}`:`transaction reverted: ${t}`;throw new d("CHAIN_ERROR",a,{revertName:i,txHash:t})}return n}async recoverRevertName(e,t){try{let n=await this.publicClient.getTransaction({hash:e});await this.publicClient.call({account:n.from,to:n.to??void 0,data:n.input,value:n.value,blockNumber:t});return}catch(n){return O(n)}}requireAccount(){let e=this.walletClient.account;if(!e)throw new d("CHAIN_ERROR","walletClient has no account (connect a wallet first)");return e}};function M(r,e){return{dropKey:r,sponsor:e.sponsor,amount:e.amount,claimAddress:e.claimAddr,recipient:e.recipient,secretHash:e.secretHash,id:e.id}}function p(r,e){if(e instanceof d)return e;let t=O(e),n=e instanceof Error?e.message:String(e),i=t?`SafeDrop.${r} reverted: ${t}`:`SafeDrop.${r} failed`;return new d("CHAIN_ERROR",i,{cause:n,revertName:t})}function L(r,e){if(e instanceof d)return e;let t=O(e),n=e instanceof G?e.walk(o=>{let y=o;return typeof y.code=="number"||y.data!==void 0}):void 0,i={revertName:t};typeof n?.code=="number"&&(i.rpcCode=n.code),typeof n?.details=="string"&&(i.rpcMessage=n.details),typeof n?.data=="string"&&(i.rpcData=n.data);let a=t?`SafeDrop.${r} reverted: ${t}`:`SafeDrop.${r} failed`;return new d("CHAIN_ERROR",a,i)}function O(r){if(!(r instanceof G))return;let e=r.walk(t=>t instanceof K);if(e instanceof K)return e.data?.errorName??e.reason??void 0}var W=[{type:"constructor",inputs:[{name:"token_",type:"address",internalType:"contract IERC20"},{name:"validator_",type:"address",internalType:"address"},{name:"sbt_",type:"address",internalType:"contract ISoulboundToken"},{name:"feeRecipient_",type:"address",internalType:"address"},{name:"minDeposit_",type:"uint256",internalType:"uint256"}],stateMutability:"nonpayable"},{type:"function",name:"FEE_BPS",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"MAX_PENDING_PER_SPONSOR_ID",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"activeDropOf",inputs:[{name:"sponsor",type:"address",internalType:"address"},{name:"claimAddr",type:"address",internalType:"address"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"anchorClaimDigest",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"dropKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"batchWithdrawMapped",inputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"batchWithdrawMapped",inputs:[{name:"count",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"cancelRecipientChange",inputs:[{name:"id",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"changeNonceById",inputs:[{name:"idKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"changeRecipientDigest",inputs:[{name:"id",type:"string",internalType:"string"},{name:"newRecipient",type:"address",internalType:"address"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"claimDigest",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"dropKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"claimedRecipientOf",inputs:[{name:"id",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"completeRecipientChange",inputs:[{name:"id",type:"string",internalType:"string"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"},{name:"validatorSignature",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"deposit",inputs:[{name:"claimAddr",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"},{name:"id",type:"string",internalType:"string"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"permitDeadline",type:"uint256",internalType:"uint256"},{name:"v",type:"uint8",internalType:"uint8"},{name:"r",type:"bytes32",internalType:"bytes32"},{name:"s",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"depositMapped",inputs:[{name:"amount",type:"uint256",internalType:"uint256"},{name:"id",type:"string",internalType:"string"},{name:"permitDeadline",type:"uint256",internalType:"uint256"},{name:"v",type:"uint8",internalType:"uint8"},{name:"r",type:"bytes32",internalType:"bytes32"},{name:"s",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"drops",inputs:[{name:"dropKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}],stateMutability:"view"},{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:"feeRecipient",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"minDeposit",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingCountOf",inputs:[{name:"sponsor",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingCountOf",inputs:[{name:"sponsor",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingDropsByRecipient",inputs:[{name:"recipient",type:"address",internalType:"address"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]}],stateMutability:"view"},{type:"function",name:"pendingDropsByRecipient",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"offset",type:"uint256",internalType:"uint256"},{name:"limit",type:"uint256",internalType:"uint256"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]},{name:"total",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingDropsByXid",inputs:[{name:"id",type:"string",internalType:"string"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]}],stateMutability:"view"},{type:"function",name:"pendingDropsByXid",inputs:[{name:"id",type:"string",internalType:"string"},{name:"offset",type:"uint256",internalType:"uint256"},{name:"limit",type:"uint256",internalType:"uint256"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]},{name:"total",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingDropsOf",inputs:[{name:"sponsor",type:"address",internalType:"address"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]}],stateMutability:"view"},{type:"function",name:"pendingDropsOf",inputs:[{name:"sponsor",type:"address",internalType:"address"},{name:"offset",type:"uint256",internalType:"uint256"},{name:"limit",type:"uint256",internalType:"uint256"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]},{name:"total",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingRecipientChange",inputs:[{name:"idKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"newRecipient",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"refund",inputs:[{name:"dropKey",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"requestRecipientChange",inputs:[{name:"id",type:"string",internalType:"string"},{name:"newRecipient",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"resetRecipient",inputs:[{name:"id",type:"string",internalType:"string"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"},{name:"validatorSignature",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"resetRecipientDigest",inputs:[{name:"id",type:"string",internalType:"string"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"sbt",inputs:[],outputs:[{name:"",type:"address",internalType:"contract ISoulboundToken"}],stateMutability:"view"},{type:"function",name:"settledCountOf",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"token",inputs:[],outputs:[{name:"",type:"address",internalType:"contract IERC20"}],stateMutability:"view"},{type:"function",name:"validator",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"validatorClaimDigest",inputs:[{name:"executor",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"validatorNonceById",inputs:[{name:"idKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"withdrawMapped",inputs:[{name:"dropKey",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"withdrawUnmapped",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"dropKey",type:"bytes32",internalType:"bytes32"},{name:"signature",type:"bytes",internalType:"bytes"},{name:"secret",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"withdrawUnmappedBatch",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"anchorDropKey",type:"bytes32",internalType:"bytes32"},{name:"signature",type:"bytes",internalType:"bytes"},{name:"secret",type:"bytes",internalType:"bytes"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"},{name:"executor",type:"address",internalType:"address"},{name:"payCount",type:"uint256",internalType:"uint256"},{name:"moveCount",type:"uint256",internalType:"uint256"},{name:"validatorSignature",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"withdrawUnmappedBatchByKeys",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"anchorDropKey",type:"bytes32",internalType:"bytes32"},{name:"signature",type:"bytes",internalType:"bytes"},{name:"secret",type:"bytes",internalType:"bytes"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"},{name:"executor",type:"address",internalType:"address"},{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"validatorSignature",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"event",name:"Deposited",inputs:[{name:"addr",type:"address",indexed:!0,internalType:"address"},{name:"sponsor",type:"address",indexed:!0,internalType:"address"},{name:"dropKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"id",type:"string",indexed:!1,internalType:"string"},{name:"secretHash",type:"bytes32",indexed:!1,internalType:"bytes32"},{name:"token",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"EIP712DomainChanged",inputs:[],anonymous:!1},{type:"event",name:"FeeCharged",inputs:[{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"gross",type:"uint256",indexed:!1,internalType:"uint256"},{name:"fee",type:"uint256",indexed:!1,internalType:"uint256"},{name:"token",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"Moved",inputs:[{name:"claimAddr",type:"address",indexed:!0,internalType:"address"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"dropKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"sponsor",type:"address",indexed:!1,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"RecipientChangeCancelled",inputs:[{name:"idKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RecipientChangeRequested",inputs:[{name:"idKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RecipientChanged",inputs:[{name:"idKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RecipientMapped",inputs:[{name:"idKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RecipientReset",inputs:[{name:"idKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"Refunded",inputs:[{name:"claimAddr",type:"address",indexed:!0,internalType:"address"},{name:"sponsor",type:"address",indexed:!0,internalType:"address"},{name:"dropKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"id",type:"string",indexed:!1,internalType:"string"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"token",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"Withdrawn",inputs:[{name:"claimAddr",type:"address",indexed:!0,internalType:"address"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"sponsor",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"token",type:"address",indexed:!1,internalType:"address"},{name:"sbtTokenId",type:"uint256",indexed:!1,internalType:"uint256"},{name:"dropKey",type:"bytes32",indexed:!1,internalType:"bytes32"}],anonymous:!1},{type:"error",name:"AlreadyMapped",inputs:[]},{type:"error",name:"AmountOverflow",inputs:[]},{type:"error",name:"BelowMinDeposit",inputs:[]},{type:"error",name:"ChangeAlreadyRequested",inputs:[]},{type:"error",name:"ChangeInProgress",inputs:[]},{type:"error",name:"CountExceedsPending",inputs:[]},{type:"error",name:"DropAlreadyExists",inputs:[]},{type:"error",name:"DropNotFound",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:"EmptyId",inputs:[]},{type:"error",name:"IdMismatch",inputs:[]},{type:"error",name:"IdNotMapped",inputs:[]},{type:"error",name:"InvalidClaimSignature",inputs:[]},{type:"error",name:"InvalidExecutor",inputs:[]},{type:"error",name:"InvalidShortString",inputs:[]},{type:"error",name:"InvalidValidatorNonce",inputs:[]},{type:"error",name:"InvalidValidatorSignature",inputs:[]},{type:"error",name:"NoPendingChange",inputs:[]},{type:"error",name:"NotRecipient",inputs:[]},{type:"error",name:"NotSponsor",inputs:[]},{type:"error",name:"PendingLimitExceeded",inputs:[]},{type:"error",name:"RecipientNotEmpty",inputs:[]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{name:"token",type:"address",internalType:"address"}]},{type:"error",name:"SameRecipient",inputs:[]},{type:"error",name:"SecretMismatch",inputs:[]},{type:"error",name:"StringTooLong",inputs:[{name:"str",type:"string",internalType:"string"}]},{type:"error",name:"TokenNotEighteenDecimals",inputs:[]},{type:"error",name:"ValidatorSigExpired",inputs:[]},{type:"error",name:"ZeroAmount",inputs:[]},{type:"error",name:"ZeroClaimAddress",inputs:[]},{type:"error",name:"ZeroCount",inputs:[]},{type:"error",name:"ZeroFeeRecipient",inputs:[]},{type:"error",name:"ZeroRecipient",inputs:[]},{type:"error",name:"ZeroSbt",inputs:[]},{type:"error",name:"ZeroSecretHash",inputs:[]},{type:"error",name:"ZeroToken",inputs:[]},{type:"error",name:"ZeroValidator",inputs:[]}];var Te=W;function Ce(r){let e=r.apiPort??new P(r.api),t=new w({address:r.contractAddress??D().onePop,publicClient:r.publicClient,walletClient:r.walletClient,chain:r.chain,transport:r.transport,withdrawFees:r.withdrawFees,transactionFees:r.transactionFees});return N({claimBaseUrl:r.claimBaseUrl},{api:e,chain:t,signer:new h,crypto:new l})}export{Q as CrossAuthClient,X as DEFAULT_POP_API_PATHS,P as HttpSafeDropApiAdapter,ne as HttpXAuthAdapter,s as ONEPOP_ABI,q as ONE_POP_BPS_DENOMINATOR,$ as ONE_POP_DEPLOYMENTS,Z as ONE_POP_FEE_BPS,Te as SAFEDROP_ABI,g as SAFEDROP_VALIDATOR_ABI,h as ViemClaimSignerAdapter,l as ViemCryptoAdapter,w as ViemSafeDropChainAdapter,ie as XAuthClient,Ce as createSafeDropClient,ee as generatePkce,te as generateState,J as getCrossAuthBaseUrl,z as getOnePopApiBaseUrl,D as getOnePopContracts,Y as getOnePopDeployment,j as getPopEnvironment};
1
+ import{f as c,j as K}from"../chunk-OXKMFZVC.js";import{a as $,b as X,c as j,d as Y,e as z,g as J,h as S,i as Q,j as ee,k as R,l as te,m as ne,n as ie,o as ae,p as se}from"../chunk-ENB6CCH7.js";import{a as d}from"../chunk-5DT3H2VX.js";import{bytesToHex as re,keccak256 as pe,recoverAddress as de,toBytes as oe}from"viem";var h=class{keccak256(e){return pe(oe(e))}randomSecret(){let e=new Uint8Array(32);return ye().getRandomValues(e),re(e).slice(2)}recoverAddress(e){return de({hash:e.digest,signature:e.signature})}};function ye(){let r=globalThis.crypto;if(!r||typeof r.getRandomValues!="function")throw new Error("Secure crypto RNG (globalThis.crypto.getRandomValues) is unavailable");return r}import{serializeSignature as ce,sign as ue}from"viem/accounts";var b=class{async signDigest(e){try{let t=await ue({hash:e.digest,privateKey:e.claimKey});return ce(t)}catch(t){throw new d("SIGN_FAILED","Failed to sign claim digest with temp key",{cause:t instanceof Error?t.message:String(t)})}}};import{BaseError as U,ContractFunctionRevertedError as V,createWalletClient as le,http as he,keccak256 as O,parseEventLogs as be,parseSignature as _,toBytes as w,toHex as F}from"viem";import{privateKeyToAccount as ge,serializeSignature as k,sign as L}from"viem/accounts";var B=[{name:"sponsor",type:"address"},{name:"amount",type:"uint96"},{name:"claimAddr",type:"address"},{name:"recipient",type:"address"},{name:"secretHash",type:"bytes32"},{name:"id",type:"string"}],H=[{name:"dropKeys",type:"bytes32[]"},{name:"records",type:"tuple[]",components:B}],me=["AlreadyMapped","AmountOverflow","BelowMinDeposit","ChangeAlreadyRequested","ChangeInProgress","CountExceedsPending","DropAlreadyExists","DropNotFound","ECDSAInvalidSignature","EmptyId","IdMismatch","IdNotMapped","InvalidClaimSignature","InvalidExecutor","InvalidShortString","InvalidValidatorNonce","InvalidValidatorSignature","NoPendingChange","NotRecipient","NotSponsor","PendingLimitExceeded","RecipientNotEmpty","ReentrancyGuardReentrantCall","SameRecipient","SecretMismatch","TokenNotEighteenDecimals","ValidatorSigExpired","ZeroAmount","ZeroClaimAddress","ZeroCount","ZeroFeeRecipient","ZeroRecipient","ZeroSbt","ZeroSecretHash","ZeroToken","ZeroValidator"],I=[...me.map(r=>({type:"error",name:r,inputs:[]})),{type:"error",name:"ECDSAInvalidSignatureLength",inputs:[{name:"length",type:"uint256"}]},{type:"error",name:"ECDSAInvalidSignatureS",inputs:[{name:"s",type:"bytes32"}]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{name:"token",type:"address"}]},{type:"error",name:"StringTooLong",inputs:[{name:"str",type:"string"}]}],s=[{type:"event",name:"Deposited",inputs:[{name:"addr",type:"address",indexed:!0},{name:"sponsor",type:"address",indexed:!0},{name:"dropKey",type:"bytes32",indexed:!0},{name:"amount",type:"uint256",indexed:!1},{name:"id",type:"string",indexed:!1},{name:"secretHash",type:"bytes32",indexed:!1},{name:"token",type:"address",indexed:!1}],anonymous:!1},{type:"function",name:"activeDropOf",stateMutability:"view",inputs:[{name:"sponsor",type:"address"},{name:"claimAddr",type:"address"}],outputs:[{type:"bytes32"}]},{type:"function",name:"drops",stateMutability:"view",inputs:[{name:"dropKey",type:"bytes32"}],outputs:B},{type:"function",name:"token",stateMutability:"view",inputs:[],outputs:[{type:"address"}]},{type:"function",name:"claimDigest",stateMutability:"view",inputs:[{name:"recipient",type:"address"},{name:"id",type:"string"},{name:"dropKey",type:"bytes32"}],outputs:[{type:"bytes32"}]},{type:"function",name:"anchorClaimDigest",stateMutability:"view",inputs:[{name:"recipient",type:"address"},{name:"id",type:"string"},{name:"dropKey",type:"bytes32"}],outputs:[{type:"bytes32"}]},{type:"function",name:"claimedRecipientOf",stateMutability:"view",inputs:[{name:"id",type:"string"}],outputs:[{type:"address"}]},{type:"function",name:"pendingDropsByXid",stateMutability:"view",inputs:[{name:"id",type:"string"}],outputs:H},{type:"function",name:"pendingDropsByRecipient",stateMutability:"view",inputs:[{name:"recipient",type:"address"}],outputs:H},{type:"function",name:"pendingDropsOf",stateMutability:"view",inputs:[{name:"sponsor",type:"address"}],outputs:H},{type:"function",name:"depositMapped",stateMutability:"nonpayable",inputs:[{name:"amount",type:"uint256"},{name:"id",type:"string"},{name:"permitDeadline",type:"uint256"},{name:"v",type:"uint8"},{name:"r",type:"bytes32"},{name:"s",type:"bytes32"}],outputs:[]},{type:"function",name:"withdrawUnmapped",stateMutability:"nonpayable",inputs:[{name:"recipient",type:"address"},{name:"id",type:"string"},{name:"dropKey",type:"bytes32"},{name:"signature",type:"bytes"},{name:"secret",type:"bytes"}],outputs:[]},{type:"function",name:"withdrawUnmappedBatchByKeys",stateMutability:"nonpayable",inputs:[{name:"recipient",type:"address"},{name:"id",type:"string"},{name:"anchorDropKey",type:"bytes32"},{name:"signature",type:"bytes"},{name:"secret",type:"bytes"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"},{name:"executor",type:"address"},{name:"dropKeys",type:"bytes32[]"},{name:"validatorSignature",type:"bytes"}],outputs:[]},{type:"function",name:"withdrawMapped",stateMutability:"nonpayable",inputs:[{name:"dropKey",type:"bytes32"}],outputs:[]},{type:"function",name:"batchWithdrawMapped",stateMutability:"nonpayable",inputs:[{name:"count",type:"uint256"}],outputs:[]},{type:"function",name:"batchWithdrawMapped",stateMutability:"nonpayable",inputs:[{name:"dropKeys",type:"bytes32[]"}],outputs:[]},{type:"function",name:"refund",stateMutability:"nonpayable",inputs:[{name:"dropKey",type:"bytes32"}],outputs:[]},{type:"function",name:"changeNonceById",stateMutability:"view",inputs:[{name:"idKey",type:"bytes32"}],outputs:[{type:"uint256"}]},{type:"function",name:"pendingRecipientChange",stateMutability:"view",inputs:[{name:"idKey",type:"bytes32"}],outputs:[{name:"newRecipient",type:"address"}]},{type:"function",name:"requestRecipientChange",stateMutability:"nonpayable",inputs:[{name:"id",type:"string"},{name:"newRecipient",type:"address"}],outputs:[]},{type:"function",name:"completeRecipientChange",stateMutability:"nonpayable",inputs:[{name:"id",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"},{name:"validatorSignature",type:"bytes"}],outputs:[]},{type:"function",name:"cancelRecipientChange",stateMutability:"nonpayable",inputs:[{name:"id",type:"string"}],outputs:[]},{type:"function",name:"resetRecipient",stateMutability:"nonpayable",inputs:[{name:"id",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"},{name:"validatorSignature",type:"bytes"}],outputs:[]},...I];var C=[{type:"function",name:"deposit",stateMutability:"nonpayable",inputs:[{name:"claimAddr",type:"address"},{name:"amount",type:"uint256"},{name:"id",type:"string"},{name:"secretHash",type:"bytes32"},{name:"deadline",type:"uint256"},{name:"v",type:"uint8"},{name:"r",type:"bytes32"},{name:"s",type:"bytes32"}],outputs:[]},{type:"function",name:"token",stateMutability:"view",inputs:[],outputs:[{type:"address"}]},...I],g=[{type:"function",name:"name",stateMutability:"view",inputs:[],outputs:[{type:"string"}]},{type:"function",name:"nonces",stateMutability:"view",inputs:[{name:"owner",type:"address"}],outputs:[{type:"uint256"}]},{type:"function",name:"eip712Domain",stateMutability:"view",inputs:[],outputs:[{name:"fields",type:"bytes1"},{name:"name",type:"string"},{name:"version",type:"string"},{name:"chainId",type:"uint256"},{name:"verifyingContract",type:"address"},{name:"salt",type:"bytes32"},{name:"extensions",type:"uint256[]"}]}],M={Permit:[{name:"owner",type:"address"},{name:"spender",type:"address"},{name:"value",type:"uint256"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}]};var f=[{type:"function",name:"validator",stateMutability:"view",inputs:[],outputs:[{type:"address"}]},{type:"function",name:"validatorClaimDigest",stateMutability:"view",inputs:[{name:"executor",type:"address"},{name:"recipient",type:"address"},{name:"id",type:"string"},{name:"nonce",type:"uint256"},{name:"deadline",type:"uint256"}],outputs:[{type:"bytes32"}]},{type:"function",name:"validatorNonceById",stateMutability:"view",inputs:[{name:"idHash",type:"bytes32"}],outputs:[{type:"uint256"}]},{type:"function",name:"claimedRecipientOf",stateMutability:"view",inputs:[{name:"id",type:"string"}],outputs:[{type:"address"}]},{type:"error",name:"ValidatorSigExpired",inputs:[]},{type:"error",name:"InvalidValidatorNonce",inputs:[]}];var fe="0x0000000000000000000000000000000000000000",we=`0x${"00".repeat(32)}`,Te={gas:BigInt(1e6),batchBaseGas:BigInt(1e6),batchGasPerDrop:BigInt(75e4),maxBatchGas:BigInt(3e7),maxFeePerGas:BigInt(4e9),maxPriorityFeePerGas:BigInt(1e9)},G=BigInt(1800),T=class{constructor(e){if(this.address=e.address,this.publicClient=e.publicClient,this.walletClient=e.walletClient,this.chain=e.chain,this.transport=e.transport??he(),this.transactionFees={...Te,...e.withdrawFees,...e.transactionFees},this.transactionFees.gas<=BigInt(0)||this.transactionFees.batchBaseGas<=BigInt(0)||this.transactionFees.batchGasPerDrop<=BigInt(0)||this.transactionFees.maxBatchGas<=BigInt(0)||this.transactionFees.maxFeePerGas<=BigInt(0)||this.transactionFees.maxPriorityFeePerGas<=BigInt(0)||this.transactionFees.maxPriorityFeePerGas>this.transactionFees.maxFeePerGas)throw new d("INVALID_PARAM","invalid EIP-1559 gas configuration");this.depositWithPermit=t=>this.permitDeposit(t)}async getDropByKey(e){try{let[t,n,i,a,o,y]=await this.publicClient.readContract({address:this.address,abi:s,functionName:"drops",args:[e]});return t.toLowerCase()===fe?null:{dropKey:e,sponsor:t,amount:n,claimAddress:i,recipient:a,secretHash:o,id:y}}catch(t){throw p("drops",t)}}async getDropKeyByClaimAddress(e,t){try{let n=await this.publicClient.readContract({address:this.address,abi:s,functionName:"activeDropOf",args:[t,e]});return n===we?null:n}catch(n){throw p("activeDropOf",n)}}async getPendingDropsById(e){try{let[t,n]=await this.publicClient.readContract({address:this.address,abi:s,functionName:"pendingDropsByXid",args:[c(e.id)]});return n.map((i,a)=>N(t[a],i))}catch(t){throw p("pendingDropsByXid",t)}}async getPendingDropsByRecipient(e){try{let[t,n]=await this.publicClient.readContract({address:this.address,abi:s,functionName:"pendingDropsByRecipient",args:[e.recipient]});return n.map((i,a)=>N(t[a],i))}catch(t){throw p("pendingDropsByRecipient",t)}}async getPendingDropsBySponsor(e){try{let[t,n]=await this.publicClient.readContract({address:this.address,abi:s,functionName:"pendingDropsOf",args:[e.sponsor]});return n.map((i,a)=>N(t[a],i))}catch(t){throw p("pendingDropsOf",t)}}async getDrop(e,t){let n=await this.getDropKeyByClaimAddress(e,t);if(!n)return null;let[i,a]=await Promise.all([this.getDropByKey(n),this.escrowToken()]);return i&&a?{...i,token:a}:null}async escrowToken(){try{return await this.publicClient.readContract({address:this.address,abi:C,functionName:"token"})}catch{throw new d("CHAIN_ERROR","token() failed")}}async getClaimDigest(e){try{return await this.publicClient.readContract({address:this.address,abi:s,functionName:"claimDigest",args:[e.recipient,c(e.id),e.dropKey]})}catch(t){throw p("claimDigest",t)}}async permitDeposit(e){let t=c(e.id);try{let n=this.requireAccount(),i=e.token,[a,o,y]=await Promise.all([this.publicClient.readContract({address:this.address,abi:C,functionName:"token"}),this.publicClient.readContract({address:i,abi:g,functionName:"nonces",args:[n.address]}),this.permitDomain(i)]);if(a.toLowerCase()!==i.toLowerCase())throw new d("INVALID_TOKEN","token does not match the escrow token",{expected:a,received:e.token});let u=BigInt(Math.floor(Date.now()/1e3))+G,x=await this.walletClient.signTypedData({account:n,domain:{...y,chainId:this.chain.id,verifyingContract:i},types:M,primaryType:"Permit",message:{owner:n.address,spender:this.address,value:e.amount,nonce:o,deadline:u}}),{r:A,s:v,v:D,yParity:P}=_(x),m=await this.walletClient.writeContract({address:this.address,abi:C,functionName:"deposit",args:[e.claimAddress,e.amount,t,e.secretHash,u,Number(D??BigInt(P+27)),A,v],account:n,chain:this.chain,...this.transactionOverrides()});await e.onSubmitted?.(m);let l=await this.confirm("depositWithPermit",m);return{txHash:m,dropKey:this.depositedDropKey(l.logs,n.address,e.amount,t,m)}}catch(n){throw p("depositWithPermit",n)}}async depositMapped(e){let t=c(e.id);try{let n=this.requireAccount(),i=e.token,[a,o,y]=await Promise.all([this.publicClient.readContract({address:this.address,abi:s,functionName:"token"}),this.publicClient.readContract({address:i,abi:g,functionName:"nonces",args:[n.address]}),this.permitDomain(i)]);if(a.toLowerCase()!==i.toLowerCase())throw new d("INVALID_TOKEN","token does not match the escrow token",{expected:a,received:e.token});let u=BigInt(Math.floor(Date.now()/1e3))+G,x=await this.walletClient.signTypedData({account:n,domain:{...y,chainId:this.chain.id,verifyingContract:i},types:M,primaryType:"Permit",message:{owner:n.address,spender:this.address,value:e.amount,nonce:o,deadline:u}}),{r:A,s:v,v:D,yParity:P}=_(x),m=[e.amount,t,u,Number(D??BigInt(P+27)),A,v];await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"depositMapped",args:m,account:n});let l=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"depositMapped",args:m,account:n,chain:this.chain,...this.transactionOverrides()});await e.onSubmitted?.(l);let q=await this.confirm("depositMapped",l);return{txHash:l,dropKey:this.depositedDropKey(q.logs,n.address,e.amount,t,l)}}catch(n){throw p("depositMapped",n)}}async permitDomain(e){try{let t=await this.publicClient.readContract({address:e,abi:g,functionName:"eip712Domain"});return{name:t[1],version:t[2]}}catch{return{name:await this.publicClient.readContract({address:e,abi:g,functionName:"name"}),version:"1"}}}async withdrawUnmapped(e){let t=c(e.id);try{let n=ge(e.claimKey),i=await this.publicClient.readContract({address:this.address,abi:s,functionName:"claimDigest",args:[e.recipient,t,e.dropKey]}),a=e.signature??k(await L({hash:i,privateKey:e.claimKey})),y=await le({account:n,chain:this.chain,transport:this.transport}).writeContract({address:this.address,abi:s,functionName:"withdrawUnmapped",args:[e.recipient,t,e.dropKey,a,F(w(e.secret))],...this.transactionOverrides()});return await e.onSubmitted?.(y),await this.confirm("withdrawUnmapped",y),y}catch(n){throw W("withdrawUnmapped",n)}}async withdrawMapped(e){let t=this.requireAccount();try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"withdrawMapped",args:[e.dropKey],account:t});let n=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"withdrawMapped",args:[e.dropKey],account:t,chain:this.chain,...this.transactionOverrides()});return await e.onSubmitted?.(n),await this.confirm("withdrawMapped",n),n}catch(n){throw p("withdrawMapped",n)}}async batchWithdrawMapped(e){if(!Number.isSafeInteger(e.count)||e.count<=0)throw new d("INVALID_PARAM","count must be a positive safe integer");let t=this.batchTransactionOverrides(e.count),n=this.requireAccount();try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"batchWithdrawMapped",args:[BigInt(e.count)],account:n});let i=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"batchWithdrawMapped",args:[BigInt(e.count)],account:n,chain:this.chain,...t});return await this.confirm("batchWithdrawMapped",i),i}catch(i){throw p("batchWithdrawMapped",i)}}async batchWithdrawMappedByKeys(e){if(!e.dropKeys.length)throw new d("INVALID_PARAM","dropKeys must not be empty");let t=this.batchTransactionOverrides(e.dropKeys.length),n=this.requireAccount(),i=[e.dropKeys];try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"batchWithdrawMapped",args:i,account:n});let a=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"batchWithdrawMapped",args:i,account:n,chain:this.chain,...t});return await this.confirm("batchWithdrawMapped",a),a}catch(a){throw p("batchWithdrawMapped",a)}}async withdrawUnmappedBatchByKeys(e){let t=c(e.id),n=e.dropKeys.filter(o=>o.toLowerCase()!==e.anchorDropKey.toLowerCase()),i=this.batchTransactionOverrides(n.length+1),a=this.requireAccount();try{let o=await this.publicClient.readContract({address:this.address,abi:s,functionName:"anchorClaimDigest",args:[e.recipient,t,e.anchorDropKey]}),y=k(await L({hash:o,privateKey:e.claimKey})),u=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"withdrawUnmappedBatchByKeys",args:[e.recipient,t,e.anchorDropKey,y,F(w(e.secret)),e.nonce,e.deadline,e.executor,n,e.validatorSignature],account:a,chain:this.chain,...i});return await this.confirm("withdrawUnmappedBatchByKeys",u),u}catch(o){throw W("withdrawUnmappedBatchByKeys",o)}}async getValidatorNonce(e){try{return await this.publicClient.readContract({address:this.address,abi:f,functionName:"validatorNonceById",args:[O(w(c(e.id)))]})}catch(t){throw p("validatorNonceById",t)}}async getValidatorClaimDigest(e){try{return await this.publicClient.readContract({address:this.address,abi:f,functionName:"validatorClaimDigest",args:[e.executor,e.recipient,c(e.id),e.nonce,e.deadline]})}catch(t){throw p("validatorClaimDigest",t)}}async getValidator(){try{return await this.publicClient.readContract({address:this.address,abi:f,functionName:"validator"})}catch(e){throw p("validator",e)}}async getClaimedRecipient(e){try{return await this.publicClient.readContract({address:this.address,abi:s,functionName:"claimedRecipientOf",args:[c(e.id)]})}catch(t){throw p("claimedRecipientOf",t)}}async refundByKey(e){let t=this.requireAccount();try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"refund",args:[e.dropKey],account:t});let n=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"refund",args:[e.dropKey],account:t,chain:this.chain,...this.transactionOverrides()});return await this.confirm("refund",n),n}catch(n){throw p("refund",n)}}async getChangeNonce(e){try{return await this.publicClient.readContract({address:this.address,abi:s,functionName:"changeNonceById",args:[O(w(c(e.id)))]})}catch(t){throw p("changeNonceById",t)}}async getPendingRecipientChange(e){try{return await this.publicClient.readContract({address:this.address,abi:s,functionName:"pendingRecipientChange",args:[O(w(c(e.id)))]})}catch(t){throw p("pendingRecipientChange",t)}}async requestRecipientChange(e){return this.currentContractWrite("requestRecipientChange",[c(e.id),e.newRecipient])}async completeRecipientChange(e){return this.currentContractWrite("completeRecipientChange",[c(e.id),e.nonce,e.deadline,e.signature])}async cancelRecipientChange(e){return this.currentContractWrite("cancelRecipientChange",[c(e.id)])}async resetRecipient(e){let t=c(e.id),n=this.requireAccount();try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:"resetRecipient",args:[t,e.nonce,e.deadline,e.signature],account:n});let i=await this.walletClient.writeContract({address:this.address,abi:s,functionName:"resetRecipient",args:[t,e.nonce,e.deadline,e.signature],account:n,chain:this.chain,...this.transactionOverrides()});return await this.confirm("resetRecipient",i),i}catch(i){throw p("resetRecipient",i)}}async currentContractWrite(e,t){let n=this.requireAccount();try{await this.publicClient.simulateContract({address:this.address,abi:s,functionName:e,args:t,account:n});let i=await this.walletClient.writeContract({address:this.address,abi:s,functionName:e,args:t,account:n,chain:this.chain,...this.transactionOverrides()});return await this.confirm(e,i),i}catch(i){throw p(e,i)}}transactionOverrides(e=this.transactionFees.gas){return{type:"eip1559",gas:e,maxFeePerGas:this.transactionFees.maxFeePerGas,maxPriorityFeePerGas:this.transactionFees.maxPriorityFeePerGas}}batchTransactionOverrides(e){if(!Number.isSafeInteger(e)||e<=0)throw new d("INVALID_PARAM","batch count must be a positive safe integer");let t=this.transactionFees.batchBaseGas+this.transactionFees.batchGasPerDrop*BigInt(e);if(t>this.transactionFees.maxBatchGas)throw new d("INVALID_PARAM","batch gas exceeds maxBatchGas",{count:e,gas:t.toString(),maxBatchGas:this.transactionFees.maxBatchGas.toString()});return this.transactionOverrides(t)}async sponsorWrite(e,t){try{let n=await t();return await this.confirm(e,n),n}catch(n){throw p(e,n)}}depositedDropKey(e,t,n,i,a){let o=be({abi:s,eventName:"Deposited",logs:[...e]}).find(({address:y,args:u})=>y.toLowerCase()===this.address.toLowerCase()&&u.sponsor.toLowerCase()===t.toLowerCase()&&u.amount===n&&u.id===i);if(!o)throw new d("CHAIN_ERROR","deposit receipt omitted the Deposited event",{txHash:a});return o.args.dropKey}async confirm(e,t){let n=await this.publicClient.waitForTransactionReceipt({hash:t});if(n.status!=="success"){let i=await this.recoverRevertName(t,n.blockNumber),a=i?`SafeDrop.${e} reverted: ${i}`:`transaction reverted: ${t}`;throw new d("CHAIN_ERROR",a,{revertName:i,txHash:t})}return n}async recoverRevertName(e,t){try{let n=await this.publicClient.getTransaction({hash:e});await this.publicClient.call({account:n.from,to:n.to??void 0,data:n.input,value:n.value,blockNumber:t});return}catch(n){return E(n)}}requireAccount(){let e=this.walletClient.account;if(!e)throw new d("CHAIN_ERROR","walletClient has no account (connect a wallet first)");return e}};function N(r,e){return{dropKey:r,sponsor:e.sponsor,amount:e.amount,claimAddress:e.claimAddr,recipient:e.recipient,secretHash:e.secretHash,id:e.id}}function p(r,e){if(e instanceof d)return e;let t=E(e),n=e instanceof Error?e.message:String(e),i=t?`SafeDrop.${r} reverted: ${t}`:`SafeDrop.${r} failed`;return new d("CHAIN_ERROR",i,{cause:n,revertName:t})}function W(r,e){if(e instanceof d)return e;let t=E(e),n=e instanceof U?e.walk(o=>{let y=o;return typeof y.code=="number"||y.data!==void 0}):void 0,i={revertName:t};typeof n?.code=="number"&&(i.rpcCode=n.code),typeof n?.details=="string"&&(i.rpcMessage=n.details),typeof n?.data=="string"&&(i.rpcData=n.data);let a=t?`SafeDrop.${r} reverted: ${t}`:`SafeDrop.${r} failed`;return new d("CHAIN_ERROR",a,i)}function E(r){if(!(r instanceof U))return;let e=r.walk(t=>t instanceof V);if(e instanceof V)return e.data?.errorName??e.reason??void 0}var Z=[{type:"constructor",inputs:[{name:"token_",type:"address",internalType:"contract IERC20"},{name:"validator_",type:"address",internalType:"address"},{name:"sbt_",type:"address",internalType:"contract ISoulboundToken"},{name:"feeRecipient_",type:"address",internalType:"address"},{name:"minDeposit_",type:"uint256",internalType:"uint256"}],stateMutability:"nonpayable"},{type:"function",name:"FEE_BPS",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"MAX_PENDING_PER_SPONSOR_ID",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"activeDropOf",inputs:[{name:"sponsor",type:"address",internalType:"address"},{name:"claimAddr",type:"address",internalType:"address"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"anchorClaimDigest",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"dropKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"batchWithdrawMapped",inputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"batchWithdrawMapped",inputs:[{name:"count",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"cancelRecipientChange",inputs:[{name:"id",type:"string",internalType:"string"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"changeNonceById",inputs:[{name:"idKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"changeRecipientDigest",inputs:[{name:"id",type:"string",internalType:"string"},{name:"newRecipient",type:"address",internalType:"address"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"claimDigest",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"dropKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"claimedRecipientOf",inputs:[{name:"id",type:"string",internalType:"string"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"completeRecipientChange",inputs:[{name:"id",type:"string",internalType:"string"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"},{name:"validatorSignature",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"deposit",inputs:[{name:"claimAddr",type:"address",internalType:"address"},{name:"amount",type:"uint256",internalType:"uint256"},{name:"id",type:"string",internalType:"string"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"permitDeadline",type:"uint256",internalType:"uint256"},{name:"v",type:"uint8",internalType:"uint8"},{name:"r",type:"bytes32",internalType:"bytes32"},{name:"s",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"depositMapped",inputs:[{name:"amount",type:"uint256",internalType:"uint256"},{name:"id",type:"string",internalType:"string"},{name:"permitDeadline",type:"uint256",internalType:"uint256"},{name:"v",type:"uint8",internalType:"uint8"},{name:"r",type:"bytes32",internalType:"bytes32"},{name:"s",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"drops",inputs:[{name:"dropKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}],stateMutability:"view"},{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:"feeRecipient",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"minDeposit",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingCountOf",inputs:[{name:"sponsor",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingCountOf",inputs:[{name:"sponsor",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingDropsByRecipient",inputs:[{name:"recipient",type:"address",internalType:"address"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]}],stateMutability:"view"},{type:"function",name:"pendingDropsByRecipient",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"offset",type:"uint256",internalType:"uint256"},{name:"limit",type:"uint256",internalType:"uint256"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]},{name:"total",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingDropsByXid",inputs:[{name:"id",type:"string",internalType:"string"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]}],stateMutability:"view"},{type:"function",name:"pendingDropsByXid",inputs:[{name:"id",type:"string",internalType:"string"},{name:"offset",type:"uint256",internalType:"uint256"},{name:"limit",type:"uint256",internalType:"uint256"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]},{name:"total",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingDropsOf",inputs:[{name:"sponsor",type:"address",internalType:"address"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]}],stateMutability:"view"},{type:"function",name:"pendingDropsOf",inputs:[{name:"sponsor",type:"address",internalType:"address"},{name:"offset",type:"uint256",internalType:"uint256"},{name:"limit",type:"uint256",internalType:"uint256"}],outputs:[{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"records",type:"tuple[]",internalType:"struct ONEpop.Drop[]",components:[{name:"sponsor",type:"address",internalType:"address"},{name:"amount",type:"uint96",internalType:"uint96"},{name:"claimAddr",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"secretHash",type:"bytes32",internalType:"bytes32"},{name:"id",type:"string",internalType:"string"}]},{name:"total",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"pendingRecipientChange",inputs:[{name:"idKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"newRecipient",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"refund",inputs:[{name:"dropKey",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"requestRecipientChange",inputs:[{name:"id",type:"string",internalType:"string"},{name:"newRecipient",type:"address",internalType:"address"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"resetRecipient",inputs:[{name:"id",type:"string",internalType:"string"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"},{name:"validatorSignature",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"resetRecipientDigest",inputs:[{name:"id",type:"string",internalType:"string"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"sbt",inputs:[],outputs:[{name:"",type:"address",internalType:"contract ISoulboundToken"}],stateMutability:"view"},{type:"function",name:"settledCountOf",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"token",inputs:[],outputs:[{name:"",type:"address",internalType:"contract IERC20"}],stateMutability:"view"},{type:"function",name:"validator",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"validatorClaimDigest",inputs:[{name:"executor",type:"address",internalType:"address"},{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"validatorNonceById",inputs:[{name:"idKey",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"withdrawMapped",inputs:[{name:"dropKey",type:"bytes32",internalType:"bytes32"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"withdrawUnmapped",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"dropKey",type:"bytes32",internalType:"bytes32"},{name:"signature",type:"bytes",internalType:"bytes"},{name:"secret",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"withdrawUnmappedBatch",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"anchorDropKey",type:"bytes32",internalType:"bytes32"},{name:"signature",type:"bytes",internalType:"bytes"},{name:"secret",type:"bytes",internalType:"bytes"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"},{name:"executor",type:"address",internalType:"address"},{name:"payCount",type:"uint256",internalType:"uint256"},{name:"moveCount",type:"uint256",internalType:"uint256"},{name:"validatorSignature",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"withdrawUnmappedBatchByKeys",inputs:[{name:"recipient",type:"address",internalType:"address"},{name:"id",type:"string",internalType:"string"},{name:"anchorDropKey",type:"bytes32",internalType:"bytes32"},{name:"signature",type:"bytes",internalType:"bytes"},{name:"secret",type:"bytes",internalType:"bytes"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"},{name:"executor",type:"address",internalType:"address"},{name:"dropKeys",type:"bytes32[]",internalType:"bytes32[]"},{name:"validatorSignature",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"event",name:"Deposited",inputs:[{name:"addr",type:"address",indexed:!0,internalType:"address"},{name:"sponsor",type:"address",indexed:!0,internalType:"address"},{name:"dropKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"id",type:"string",indexed:!1,internalType:"string"},{name:"secretHash",type:"bytes32",indexed:!1,internalType:"bytes32"},{name:"token",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"EIP712DomainChanged",inputs:[],anonymous:!1},{type:"event",name:"FeeCharged",inputs:[{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"gross",type:"uint256",indexed:!1,internalType:"uint256"},{name:"fee",type:"uint256",indexed:!1,internalType:"uint256"},{name:"token",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"Moved",inputs:[{name:"claimAddr",type:"address",indexed:!0,internalType:"address"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"dropKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"sponsor",type:"address",indexed:!1,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"}],anonymous:!1},{type:"event",name:"RecipientChangeCancelled",inputs:[{name:"idKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RecipientChangeRequested",inputs:[{name:"idKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RecipientChanged",inputs:[{name:"idKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"to",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RecipientMapped",inputs:[{name:"idKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"RecipientReset",inputs:[{name:"idKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"from",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"}],anonymous:!1},{type:"event",name:"Refunded",inputs:[{name:"claimAddr",type:"address",indexed:!0,internalType:"address"},{name:"sponsor",type:"address",indexed:!0,internalType:"address"},{name:"dropKey",type:"bytes32",indexed:!0,internalType:"bytes32"},{name:"id",type:"string",indexed:!1,internalType:"string"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"token",type:"address",indexed:!1,internalType:"address"}],anonymous:!1},{type:"event",name:"Withdrawn",inputs:[{name:"claimAddr",type:"address",indexed:!0,internalType:"address"},{name:"recipient",type:"address",indexed:!0,internalType:"address"},{name:"sponsor",type:"address",indexed:!0,internalType:"address"},{name:"id",type:"string",indexed:!1,internalType:"string"},{name:"amount",type:"uint256",indexed:!1,internalType:"uint256"},{name:"token",type:"address",indexed:!1,internalType:"address"},{name:"sbtTokenId",type:"uint256",indexed:!1,internalType:"uint256"},{name:"dropKey",type:"bytes32",indexed:!1,internalType:"bytes32"}],anonymous:!1},{type:"error",name:"AlreadyMapped",inputs:[]},{type:"error",name:"AmountOverflow",inputs:[]},{type:"error",name:"BelowMinDeposit",inputs:[]},{type:"error",name:"ChangeAlreadyRequested",inputs:[]},{type:"error",name:"ChangeInProgress",inputs:[]},{type:"error",name:"CountExceedsPending",inputs:[]},{type:"error",name:"DropAlreadyExists",inputs:[]},{type:"error",name:"DropNotFound",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:"EmptyId",inputs:[]},{type:"error",name:"IdMismatch",inputs:[]},{type:"error",name:"IdNotMapped",inputs:[]},{type:"error",name:"InvalidClaimSignature",inputs:[]},{type:"error",name:"InvalidExecutor",inputs:[]},{type:"error",name:"InvalidShortString",inputs:[]},{type:"error",name:"InvalidValidatorNonce",inputs:[]},{type:"error",name:"InvalidValidatorSignature",inputs:[]},{type:"error",name:"NoPendingChange",inputs:[]},{type:"error",name:"NotRecipient",inputs:[]},{type:"error",name:"NotSponsor",inputs:[]},{type:"error",name:"PendingLimitExceeded",inputs:[]},{type:"error",name:"RecipientNotEmpty",inputs:[]},{type:"error",name:"ReentrancyGuardReentrantCall",inputs:[]},{type:"error",name:"SafeERC20FailedOperation",inputs:[{name:"token",type:"address",internalType:"address"}]},{type:"error",name:"SameRecipient",inputs:[]},{type:"error",name:"SecretMismatch",inputs:[]},{type:"error",name:"StringTooLong",inputs:[{name:"str",type:"string",internalType:"string"}]},{type:"error",name:"TokenNotEighteenDecimals",inputs:[]},{type:"error",name:"ValidatorSigExpired",inputs:[]},{type:"error",name:"ZeroAmount",inputs:[]},{type:"error",name:"ZeroClaimAddress",inputs:[]},{type:"error",name:"ZeroCount",inputs:[]},{type:"error",name:"ZeroFeeRecipient",inputs:[]},{type:"error",name:"ZeroRecipient",inputs:[]},{type:"error",name:"ZeroSbt",inputs:[]},{type:"error",name:"ZeroSecretHash",inputs:[]},{type:"error",name:"ZeroToken",inputs:[]},{type:"error",name:"ZeroValidator",inputs:[]}];var xe=Z;function Ae(r){let e=r.apiPort??new R(r.api),t=new T({address:r.contractAddress??S().onePop,publicClient:r.publicClient,walletClient:r.walletClient,chain:r.chain,transport:r.transport,withdrawFees:r.withdrawFees,transactionFees:r.transactionFees});return K({claimBaseUrl:r.claimBaseUrl},{api:e,chain:t,signer:new b,crypto:new h})}export{te as CrossAuthClient,Y as DEFAULT_POP_API_PATHS,R as HttpSafeDropApiAdapter,ae as HttpXAuthAdapter,s as ONEPOP_ABI,X as ONE_POP_BPS_DENOMINATOR,j as ONE_POP_DEPLOYMENTS,$ as ONE_POP_FEE_BPS,xe as SAFEDROP_ABI,f as SAFEDROP_VALIDATOR_ABI,b as ViemClaimSignerAdapter,h as ViemCryptoAdapter,T as ViemSafeDropChainAdapter,se as XAuthClient,Ae as createSafeDropClient,ne as generatePkce,ie as generateState,ee as getCrossAuthBaseUrl,Q as getOnePopApiBaseUrl,S as getOnePopContracts,J as getOnePopDeployment,z as getPopEnvironment};
@@ -1,3 +1,3 @@
1
- export { C as CrossAuthClient, a as CrossAuthClientOptions, D as DEFAULT_POP_API_PATHS, b as HttpSafeDropApiAdapter, H as HttpSafeDropApiAdapterOptions, c as HttpXAuthAdapter, d as HttpXAuthAdapterOptions, e as ONE_POP_DEPLOYMENTS, P as Pkce, g as PopApiPaths, h as PopContracts, i as PopDeployment, j as PopEnvironment, S as SessionStore, X as XAuthClient, k as XAuthClientOptions, l as generatePkce, m as generateState, n as getCrossAuthBaseUrl, o as getOnePopApiBaseUrl, s as resolvePopEnvironment } from '../index-DVeDD7Dp.js';
2
- import '../SafeDropApiPort-B7NfQOsb.js';
1
+ export { C as CrossAuthClient, a as CrossAuthClientOptions, D as DEFAULT_POP_API_PATHS, b as HttpSafeDropApiAdapter, H as HttpSafeDropApiAdapterOptions, c as HttpXAuthAdapter, d as HttpXAuthAdapterOptions, e as ONE_POP_DEPLOYMENTS, P as Pkce, g as PopApiPaths, h as PopContracts, i as PopDeployment, j as PopEnvironment, S as SessionStore, X as XAuthClient, k as XAuthClientOptions, l as generatePkce, m as generateState, n as getCrossAuthBaseUrl, o as getOnePopApiBaseUrl, s as resolvePopEnvironment } from '../index-Dljcnddn.js';
2
+ import '../SafeDropApiPort-BwcuQkf0.js';
3
3
  import '../XAuthPort-BNJePosj.js';
@@ -0,0 +1 @@
1
+ import{a as o}from"./chunk-5DT3H2VX.js";function D(a){let e=a.baseUrl.replace(/\/$/,""),r=e.includes("?")?"&":"?",n=a.claimAddress?`&claim=${encodeURIComponent(a.claimAddress)}`:"",s=`${e}${r}sender=${encodeURIComponent(a.sender)}${n}`;return a.secret?`${s}#${encodeURIComponent(a.secret)}`:s}function E(a){let e=a.indexOf("#"),r=e===-1?a:a.slice(0,e),n=e===-1?"":a.slice(e+1),s=r.indexOf("?"),p=s===-1?"":r.slice(s+1);return{sender:b(p,"sender"),secret:n?decodeURIComponent(n):null}}function B(a){return`\u{1F381} You've received a one-pop drop! Claim your tokens here: ${a}`}function M(a,e){let r=[`text=${encodeURIComponent(a)}`];return e&&r.push(`recipient_id=${encodeURIComponent(e)}`),`https://x.com/messages/compose?${r.join("&")}`}function b(a,e){if(!a)return null;for(let r of a.split("&")){if(!r)continue;let n=r.indexOf("=");if(decodeURIComponent(n===-1?r:r.slice(0,n))===e)return decodeURIComponent(n===-1?"":r.slice(n+1))}return null}var g=class{constructor(e,r,n,s){this.chain=e;this.api=r;this.crypto=n;this.claimBaseUrl=s}async execute(e){if(!e.sender)throw new o("MISSING_SENDER","sender address is required");if(!e.recipient?.handle)throw new o("MISSING_RECIPIENT","recipient social handle is required");if(!e.token)throw new o("INVALID_TOKEN","token address is required (ERC20 only)");if(e.amount<=0n)throw new o("INVALID_AMOUNT","amount must be a positive BigInt");if(e.message&&[...e.message].length>140)throw new o("INVALID_PARAM","message must be <= 140 runes");let r=await this.api.createClaimWallet({sender:e.sender,recipient:e.recipient}),n=r.id,s=async c=>{if(this.api.recordDropMetadata)try{await this.api.recordDropMetadata({txHash:c,message:e.message,envelopeId:e.envelopeId})}catch(m){if(m instanceof o&&m.details?.codeName==="ENVELOPE_NOT_FOUND"&&e.envelopeId)try{await this.api.recordDropMetadata({txHash:c,message:e.message})}catch{}}};if(r.isMapped){let{txHash:c,dropKey:m}=await this.chain.depositMapped({token:e.token,amount:e.amount,id:n,onSubmitted:s});return{isMapped:!0,dropKey:m,depositTxHash:c}}let p=e.secret??this.crypto.randomSecret();if(!p)throw new o("MISSING_SECRET","secret is empty");let i=this.crypto.keccak256(p),t={claimAddress:r.claimAddress,token:e.token,amount:e.amount,id:n,secretHash:i,onSubmitted:s},{txHash:l,dropKey:u}=await this.chain.depositWithPermit(t);return{isMapped:!1,dropKey:u,claimAddress:r.claimAddress,secretHash:i,withdrawLink:D({baseUrl:this.claimBaseUrl,sender:e.sender,claimAddress:r.claimAddress,secret:p}),depositTxHash:l}}};function S(a){return a.trim().replace(/^@/,"").toLowerCase()}var N=BigInt(1800),x=30,y=class{constructor(e,r,n,s=()=>Date.now()){this.chain=e;this.api=r;this.crypto=n;this.now=s}async execute(e){let r=e.id;if(!r)throw new o("MISSING_RECIPIENT","batchClaim requires an id");let n=S(r);if(!n)throw new o("MISSING_RECIPIENT","batchClaim requires an id");if(!e.claimAddress)throw new o("MISSING_CLAIM_ADDRESS","claim address is required");if(!e.sponsor)throw new o("MISSING_SENDER","sponsor address is required");if(!e.claimKey)throw new o("MISSING_CLAIM_KEY","claim key is required");if(!e.secret)throw new o("MISSING_SECRET","secret is required");if(!this.api.requestBatchClaimSignature)throw new o("API_ERROR","requestBatchClaimSignature is not implemented");if(!this.chain.getValidatorNonce||!this.chain.getValidatorClaimDigest||!this.chain.getValidator)throw new o("CHAIN_ERROR","validator reads are not implemented");let s=await this.chain.getDropKeyByClaimAddress(e.claimAddress,e.sponsor);if(!s)throw new o("DROP_NOT_FOUND","anchor drop not found");let p=await this.chain.getDropByKey(s);if(!p||p.id!==n)throw new o("DROP_NOT_FOUND","anchor drop id does not match");let i=await this.chain.getPendingDropsById({id:n});if(!i.length)throw new o("DROP_NOT_FOUND",`No pending drops for ${r}`);let t=e.maxCount??x;if(!Number.isSafeInteger(t)||t<=0)throw new o("INVALID_PARAM","maxCount must be a positive safe integer");let l=e.deadline??BigInt(Math.floor(this.now()/1e3))+(e.deadlineTtlSeconds??N),u=[],c="",m=BigInt(0);for(;i.length;){let R=await this.chain.getValidatorNonce({id:n}),h=await this.api.requestBatchClaimSignature({id:r,oauth:e.oauth,nonce:R,deadline:l});if(e.recipient&&e.recipient.toLowerCase()!==h.recipient.toLowerCase())throw new o("SIGN_FAILED","validator signature is bound to a different recipient");if(c&&c.toLowerCase()!==h.recipient.toLowerCase())throw new o("SIGN_FAILED","validator recipient changed between batches");c=h.recipient,u.length||(m=h.nonce);let I=await this.chain.getValidatorClaimDigest({executor:c,recipient:c,id:n,nonce:h.nonce,deadline:h.deadline});await this.assertSignedByValidator(I,h.signature);let A=i.length,C=await this.chain.withdrawUnmappedBatchByKeys({claimKey:e.claimKey,recipient:c,id:n,anchorDropKey:s,secret:e.secret,nonce:h.nonce,deadline:h.deadline,executor:c,dropKeys:i.slice(0,t).map(w=>w.dropKey).filter(w=>w.toLowerCase()!==s.toLowerCase()),validatorSignature:h.signature});if(u.push(C),i=await this.chain.getPendingDropsById({id:n}),i.length>=A)throw new o("CHAIN_ERROR","batch claim made no progress",{id:r,txHash:C})}return{txHashes:u,recipient:c,id:r,nonce:m,deadline:l}}async assertSignedByValidator(e,r){if(!this.crypto.recoverAddress||!this.chain.getValidator)return;let[n,s]=await Promise.all([this.crypto.recoverAddress({digest:e,signature:r}),this.chain.getValidator()]);if(n.toLowerCase()!==s.toLowerCase())throw new o("SIGN_FAILED","batch-claim signature does not recover to validator")}};var f=class{constructor(e,r){this.chain=e;this.signer=r}async execute(e){if(!e.recipient)throw new o("MISSING_RECIPIENT","recipient address is required");if(!e.claimAddress)throw new o("MISSING_CLAIM_ADDRESS","claim address is required");if(!e.secret)throw new o("MISSING_SECRET","secret is required");if(!e.claimKey)throw new o("MISSING_CLAIM_KEY","claim key is required");if(!e.sponsor)throw new o("MISSING_SENDER","sponsor address is required");let r=await this.chain.getDropKeyByClaimAddress(e.claimAddress,e.sponsor);if(!r)throw new o("DROP_NOT_FOUND",`No drop for claim address ${e.claimAddress}`);let n=await this.chain.getDropByKey(r);if(!n)throw new o("DROP_NOT_FOUND",`No drop for key ${r}`);let s=await this.chain.getClaimDigest({recipient:e.recipient,id:n.id,dropKey:r}),p=await this.signer.signDigest({claimKey:e.claimKey,digest:s});return{txHash:await this.chain.withdrawUnmapped({claimKey:e.claimKey,recipient:e.recipient,id:n.id,dropKey:r,signature:p,secret:e.secret})}}};var P=class{constructor(e){this.chain=e}async execute(e){if(!e.claimAddress)throw new o("MISSING_CLAIM_ADDRESS","claim address is required");if(!e.sponsor)throw new o("MISSING_SENDER","sponsor address is required");let r=await this.chain.getDropKeyByClaimAddress(e.claimAddress,e.sponsor);if(!r)throw new o("DROP_NOT_FOUND",`No drop for claim address ${e.claimAddress}`);return{txHash:await this.chain.refundByKey({dropKey:r})}}};function d(a,e){if(!a)throw new o("API_ERROR",`SafeDropApiPort.${e} is not implemented by the injected api adapter`);return a}function Y(a,e){let r=new g(e.chain,e.api,e.crypto,a.claimBaseUrl),n=new f(e.chain,e.signer),s=new P(e.chain),p=new y(e.chain,e.api,e.crypto),{api:i}=e;return{config:a,deposit:t=>r.execute(t),retrieveClaimKey:t=>i.retrieveClaimKey(t),withdraw:t=>n.execute(t),refund:t=>s.execute(t),getDrop:(t,l)=>e.chain.getDrop(t,l),getDropByKey:t=>e.chain.getDropByKey(t),getDropKeyByClaimAddress:(t,l)=>e.chain.getDropKeyByClaimAddress(t,l),getClaimedRecipient:t=>e.chain.getClaimedRecipient({id:t}),getPendingDropsById:t=>e.chain.getPendingDropsById({id:t}),getPendingDropsByRecipient:t=>e.chain.getPendingDropsByRecipient({recipient:t}),getPendingDropsBySponsor:t=>e.chain.getPendingDropsBySponsor({sponsor:t}),withdrawUnmapped:t=>e.chain.withdrawUnmapped(t),withdrawMapped:t=>e.chain.withdrawMapped(t),batchWithdrawMapped:t=>e.chain.batchWithdrawMapped({count:t}),batchWithdrawMappedByKeys:t=>e.chain.batchWithdrawMappedByKeys({dropKeys:t}),refundByKey:t=>e.chain.refundByKey({dropKey:t}),getChangeNonce:t=>e.chain.getChangeNonce({id:t}),getPendingRecipientChange:t=>e.chain.getPendingRecipientChange({id:t}),requestRecipientChange:(t,l)=>e.chain.requestRecipientChange({id:t,newRecipient:l}),completeRecipientChange:t=>e.chain.completeRecipientChange(t),cancelRecipientChange:t=>e.chain.cancelRecipientChange({id:t}),resetRecipient:t=>e.chain.resetRecipient(t),listDrops:t=>d(i.listDrops,"listDrops").call(i,t),rejectDrops:t=>d(i.rejectDrops,"rejectDrops").call(i,{dropIds:t}),listEnvelopes:t=>d(i.listEnvelopes,"listEnvelopes").call(i,t),getLeaderboard:t=>d(i.getLeaderboard,"getLeaderboard").call(i,t),getMyLeaderboardEntry:t=>d(i.getMyLeaderboardEntry,"getMyLeaderboardEntry").call(i,t),listHistories:t=>d(i.listHistories,"listHistories").call(i,t),getXConnection:()=>d(i.getXConnection,"getXConnection").call(i),connectX:t=>d(i.connectX,"connectX").call(i,t),disconnectX:()=>d(i.disconnectX,"disconnectX").call(i),submitFeedback:t=>d(i.submitFeedback,"submitFeedback").call(i,t),setRevealYou:t=>d(i.setRevealYou,"setRevealYou").call(i,{revealYou:t}),requestRecipientChangeSignature:t=>d(i.requestRecipientChangeSignature,"requestRecipientChangeSignature").call(i,t),requestRecipientResetSignature:t=>d(i.requestRecipientResetSignature,"requestRecipientResetSignature").call(i,t),batchClaim:t=>p.execute(t),requestBatchClaimSignature:t=>d(i.requestBatchClaimSignature,"requestBatchClaimSignature").call(i,t)}}export{D as a,E as b,B as c,M as d,g as e,S as f,y as g,f as h,P as i,Y as j};
@@ -1,4 +1,4 @@
1
- import { S as Secret, a as SecretHash, H as Hex, A as Address, I as Id, D as DepositParams, b as DepositResult, O as OAuthProof, W as WithdrawParams, c as WithdrawResult, R as RefundParams, d as RefundResult, e as DropInbox, E as Envelope, L as LeaderboardPage, M as MyLeaderboardEntry, f as HistoryType, g as HistoryStatus, h as HistoryPage, X as XConnection, i as RecipientChangeSignature, j as RecipientSignature, B as BatchClaimParams, k as BatchClaimResult, l as BatchClaimSignature, m as SafeDropApiPort } from './SafeDropApiPort-B7NfQOsb.js';
1
+ import { S as Secret, a as SecretHash, H as Hex, A as Address, I as Id, D as DepositParams, b as DepositResult, O as OAuthProof, W as WithdrawParams, c as WithdrawResult, R as RefundParams, d as RefundResult, e as DropInbox, E as Envelope, L as LeaderboardPage, M as MyLeaderboardEntry, f as HistoryType, g as HistoryStatus, h as HistoryPage, X as XConnection, i as RecipientChangeSignature, j as RecipientSignature, B as BatchClaimParams, k as BatchClaimResult, l as BatchClaimSignature, m as SafeDropApiPort } from './SafeDropApiPort-BwcuQkf0.js';
2
2
 
3
3
  /**
4
4
  * 순수 계산이 아니라 외부 구현(해시 라이브러리/CSPRNG)이 필요한 암호 연산.
@@ -1,4 +1,4 @@
1
- import { m as SafeDropApiPort, A as Address, w as SocialIdentifier, I as Id, H as Hex, O as OAuthProof, e as DropInbox, E as Envelope, L as LeaderboardPage, M as MyLeaderboardEntry, f as HistoryType, g as HistoryStatus, h as HistoryPage, X as XConnection, i as RecipientChangeSignature, j as RecipientSignature, l as BatchClaimSignature } from './SafeDropApiPort-B7NfQOsb.js';
1
+ import { m as SafeDropApiPort, A as Address, w as SocialIdentifier, I as Id, H as Hex, O as OAuthProof, e as DropInbox, E as Envelope, L as LeaderboardPage, M as MyLeaderboardEntry, f as HistoryType, g as HistoryStatus, h as HistoryPage, X as XConnection, i as RecipientChangeSignature, j as RecipientSignature, l as BatchClaimSignature } from './SafeDropApiPort-BwcuQkf0.js';
2
2
  import { X as XAuthPort, a as XTokenResult } from './XAuthPort-BNJePosj.js';
3
3
 
4
4
  /**
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { m as SafeDropApiPort, D as DepositParams, b as DepositResult, B as BatchClaimParams, k as BatchClaimResult, W as WithdrawParams, c as WithdrawResult, R as RefundParams, d as RefundResult, A as Address, S as Secret } from './SafeDropApiPort-B7NfQOsb.js';
2
- export { l as BatchClaimSignature, e as DropInbox, n as DropSender, E as Envelope, o as EnvelopeLayout, H as Hex, p as HistoryEntry, h as HistoryPage, q as HistoryParty, r as HistoryReceiverParty, g as HistoryStatus, f as HistoryType, I as Id, s as LeaderboardEntry, L as LeaderboardPage, t as MappedDepositResult, M as MyLeaderboardEntry, O as OAuthProof, P as PendingDrop, i as RecipientChangeSignature, j as RecipientSignature, u as SafeDropError, v as SafeDropErrorCode, a as SecretHash, w as SocialIdentifier, x as SocialProvider, U as UnmappedDepositResult, X as XConnection } from './SafeDropApiPort-B7NfQOsb.js';
3
- import { a as SafeDropChainPort, C as CryptoPort, b as ClaimSignerPort } from './createSafeDrop-BGoIQ4nK.js';
4
- export { D as DropState, O as OnePopDrop, S as SafeDrop, c as SafeDropConfig, d as SafeDropDeps, e as createSafeDrop } from './createSafeDrop-BGoIQ4nK.js';
1
+ import { m as SafeDropApiPort, D as DepositParams, b as DepositResult, B as BatchClaimParams, k as BatchClaimResult, W as WithdrawParams, c as WithdrawResult, R as RefundParams, d as RefundResult, A as Address, S as Secret } from './SafeDropApiPort-BwcuQkf0.js';
2
+ export { l as BatchClaimSignature, e as DropInbox, n as DropSender, E as Envelope, o as EnvelopeLayout, H as Hex, p as HistoryEntry, h as HistoryPage, q as HistoryParty, r as HistoryReceiverParty, g as HistoryStatus, f as HistoryType, I as Id, s as LeaderboardEntry, L as LeaderboardPage, t as MappedDepositResult, M as MyLeaderboardEntry, O as OAuthProof, P as PendingDrop, i as RecipientChangeSignature, j as RecipientSignature, u as SafeDropError, v as SafeDropErrorCode, a as SecretHash, w as SocialIdentifier, x as SocialProvider, U as UnmappedDepositResult, X as XConnection } from './SafeDropApiPort-BwcuQkf0.js';
3
+ import { a as SafeDropChainPort, C as CryptoPort, b as ClaimSignerPort } from './createSafeDrop-BFooPsSR.js';
4
+ export { D as DropState, O as OnePopDrop, S as SafeDrop, c as SafeDropConfig, d as SafeDropDeps, e as createSafeDrop } from './createSafeDrop-BFooPsSR.js';
5
5
  export { X as XAuthPort, a as XTokenResult } from './XAuthPort-BNJePosj.js';
6
6
 
7
7
  /**
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{a as e,b as o,c as t,d as p,e as a,f as s,g as i,h as f,i as n,j as m}from"./chunk-M7FFQCP2.js";import{a as r}from"./chunk-5DT3H2VX.js";export{i as BatchClaimUseCase,s as DepositUseCase,n as RefundUseCase,r as SafeDropError,f as WithdrawUseCase,a as buildComposeUrl,p as buildDmText,o as buildWithdrawLink,m as createSafeDrop,e as normalizeHandle,t as parseWithdrawLink};
1
+ import{a as e,b as o,c as t,d as p,e as a,f as s,g as i,h as f,i as n,j as m}from"./chunk-OXKMFZVC.js";import{a as r}from"./chunk-5DT3H2VX.js";export{i as BatchClaimUseCase,a as DepositUseCase,n as RefundUseCase,r as SafeDropError,f as WithdrawUseCase,p as buildComposeUrl,t as buildDmText,e as buildWithdrawLink,m as createSafeDrop,s as normalizeHandle,o as parseWithdrawLink};
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { S as SafeDrop } from '../createSafeDrop-BGoIQ4nK.js';
4
- import '../SafeDropApiPort-B7NfQOsb.js';
3
+ import { S as SafeDrop } from '../createSafeDrop-BFooPsSR.js';
4
+ import '../SafeDropApiPort-BwcuQkf0.js';
5
5
 
6
6
  interface SafeDropProviderProps {
7
7
  client: SafeDrop;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexus-cross/pop",
3
- "version": "1.4.1-beta.6",
3
+ "version": "1.4.1-beta.7",
4
4
  "description": "pop — framework-agnostic core + React adapter.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1 +0,0 @@
1
- import{a as i}from"./chunk-5DT3H2VX.js";function g(a){return a.trim().replace(/^@/,"").toLowerCase()}function S(a){let e=a.baseUrl.replace(/\/$/,""),r=e.includes("?")?"&":"?",n=a.claimAddress?`&claim=${encodeURIComponent(a.claimAddress)}`:"",s=`${e}${r}sender=${encodeURIComponent(a.sender)}${n}`;return a.secret?`${s}#${encodeURIComponent(a.secret)}`:s}function E(a){let e=a.indexOf("#"),r=e===-1?a:a.slice(0,e),n=e===-1?"":a.slice(e+1),s=r.indexOf("?"),d=s===-1?"":r.slice(s+1);return{sender:A(d,"sender"),secret:n?decodeURIComponent(n):null}}function B(a){return`\u{1F381} You've received a one-pop drop! Claim your tokens here: ${a}`}function M(a,e){let r=[`text=${encodeURIComponent(a)}`];return e&&r.push(`recipient_id=${encodeURIComponent(e)}`),`https://x.com/messages/compose?${r.join("&")}`}function A(a,e){if(!a)return null;for(let r of a.split("&")){if(!r)continue;let n=r.indexOf("=");if(decodeURIComponent(n===-1?r:r.slice(0,n))===e)return decodeURIComponent(n===-1?"":r.slice(n+1))}return null}var y=class{constructor(e,r,n,s){this.chain=e;this.api=r;this.crypto=n;this.claimBaseUrl=s}async execute(e){if(!e.sender)throw new i("MISSING_SENDER","sender address is required");if(!e.recipient?.handle)throw new i("MISSING_RECIPIENT","recipient social handle is required");if(!e.token)throw new i("INVALID_TOKEN","token address is required (ERC20 only)");if(e.amount<=0n)throw new i("INVALID_AMOUNT","amount must be a positive BigInt");if(e.message&&[...e.message].length>140)throw new i("INVALID_PARAM","message must be <= 140 runes");let r=g(e.recipient.handle);if(!r)throw new i("MISSING_RECIPIENT","recipient handle normalizes to empty");let n=await this.api.createClaimWallet({sender:e.sender,recipient:{...e.recipient,handle:r}}),s=n.id,d=async m=>{if(this.api.recordDropMetadata)try{await this.api.recordDropMetadata({txHash:m,message:e.message,envelopeId:e.envelopeId})}catch(c){if(c instanceof i&&c.details?.codeName==="ENVELOPE_NOT_FOUND"&&e.envelopeId)try{await this.api.recordDropMetadata({txHash:m,message:e.message})}catch{}}};if(n.isMapped){let{txHash:m,dropKey:c}=await this.chain.depositMapped({token:e.token,amount:e.amount,id:s,onSubmitted:d});return{isMapped:!0,dropKey:c,depositTxHash:m}}let o=e.secret??this.crypto.randomSecret();if(!o)throw new i("MISSING_SECRET","secret is empty");let t=this.crypto.keccak256(o),l={claimAddress:n.claimAddress,token:e.token,amount:e.amount,id:s,secretHash:t,onSubmitted:d},{txHash:h,dropKey:u}=await this.chain.depositWithPermit(l);return{isMapped:!1,dropKey:u,claimAddress:n.claimAddress,secretHash:t,withdrawLink:S({baseUrl:this.claimBaseUrl,sender:e.sender,claimAddress:n.claimAddress,secret:o}),depositTxHash:h}}};var b=BigInt(1800),N=30,f=class{constructor(e,r,n,s=()=>Date.now()){this.chain=e;this.api=r;this.crypto=n;this.now=s}async execute(e){let r=g(e.id);if(!r)throw new i("MISSING_RECIPIENT","batchClaim requires an id");if(!e.claimAddress)throw new i("MISSING_CLAIM_ADDRESS","claim address is required");if(!e.sponsor)throw new i("MISSING_SENDER","sponsor address is required");if(!e.claimKey)throw new i("MISSING_CLAIM_KEY","claim key is required");if(!e.secret)throw new i("MISSING_SECRET","secret is required");if(!this.api.requestBatchClaimSignature)throw new i("API_ERROR","requestBatchClaimSignature is not implemented");if(!this.chain.getValidatorNonce||!this.chain.getValidatorClaimDigest||!this.chain.getValidator)throw new i("CHAIN_ERROR","validator reads are not implemented");let n=await this.chain.getDropKeyByClaimAddress(e.claimAddress,e.sponsor);if(!n)throw new i("DROP_NOT_FOUND","anchor drop not found");let s=await this.chain.getDropByKey(n);if(!s||s.id!==r)throw new i("DROP_NOT_FOUND","anchor drop id does not match");let d=await this.chain.getPendingDropsById({id:r});if(!d.length)throw new i("DROP_NOT_FOUND",`No pending drops for ${r}`);let o=e.maxCount??N;if(!Number.isSafeInteger(o)||o<=0)throw new i("INVALID_PARAM","maxCount must be a positive safe integer");let t=e.deadline??BigInt(Math.floor(this.now()/1e3))+(e.deadlineTtlSeconds??b),l=[],h="",u=BigInt(0);for(;d.length;){let m=await this.chain.getValidatorNonce({id:r}),c=await this.api.requestBatchClaimSignature({id:r,oauth:e.oauth,nonce:m,deadline:t});if(e.recipient&&e.recipient.toLowerCase()!==c.recipient.toLowerCase())throw new i("SIGN_FAILED","validator signature is bound to a different recipient");if(h&&h.toLowerCase()!==c.recipient.toLowerCase())throw new i("SIGN_FAILED","validator recipient changed between batches");h=c.recipient,l.length||(u=c.nonce);let R=await this.chain.getValidatorClaimDigest({executor:h,recipient:h,id:r,nonce:c.nonce,deadline:c.deadline});await this.assertSignedByValidator(R,c.signature);let I=d.length,D=await this.chain.withdrawUnmappedBatchByKeys({claimKey:e.claimKey,recipient:h,id:r,anchorDropKey:n,secret:e.secret,nonce:c.nonce,deadline:c.deadline,executor:h,dropKeys:d.slice(0,o).map(C=>C.dropKey).filter(C=>C.toLowerCase()!==n.toLowerCase()),validatorSignature:c.signature});if(l.push(D),d=await this.chain.getPendingDropsById({id:r}),d.length>=I)throw new i("CHAIN_ERROR","batch claim made no progress",{id:r,txHash:D})}return{txHashes:l,recipient:h,id:r,nonce:u,deadline:t}}async assertSignedByValidator(e,r){if(!this.crypto.recoverAddress||!this.chain.getValidator)return;let[n,s]=await Promise.all([this.crypto.recoverAddress({digest:e,signature:r}),this.chain.getValidator()]);if(n.toLowerCase()!==s.toLowerCase())throw new i("SIGN_FAILED","batch-claim signature does not recover to validator")}};var P=class{constructor(e,r){this.chain=e;this.signer=r}async execute(e){if(!e.recipient)throw new i("MISSING_RECIPIENT","recipient address is required");if(!e.claimAddress)throw new i("MISSING_CLAIM_ADDRESS","claim address is required");if(!e.secret)throw new i("MISSING_SECRET","secret is required");if(!e.claimKey)throw new i("MISSING_CLAIM_KEY","claim key is required");if(!e.sponsor)throw new i("MISSING_SENDER","sponsor address is required");let r=await this.chain.getDropKeyByClaimAddress(e.claimAddress,e.sponsor);if(!r)throw new i("DROP_NOT_FOUND",`No drop for claim address ${e.claimAddress}`);let n=await this.chain.getDropByKey(r);if(!n)throw new i("DROP_NOT_FOUND",`No drop for key ${r}`);let s=await this.chain.getClaimDigest({recipient:e.recipient,id:n.id,dropKey:r}),d=await this.signer.signDigest({claimKey:e.claimKey,digest:s});return{txHash:await this.chain.withdrawUnmapped({claimKey:e.claimKey,recipient:e.recipient,id:n.id,dropKey:r,signature:d,secret:e.secret})}}};var w=class{constructor(e){this.chain=e}async execute(e){if(!e.claimAddress)throw new i("MISSING_CLAIM_ADDRESS","claim address is required");if(!e.sponsor)throw new i("MISSING_SENDER","sponsor address is required");let r=await this.chain.getDropKeyByClaimAddress(e.claimAddress,e.sponsor);if(!r)throw new i("DROP_NOT_FOUND",`No drop for claim address ${e.claimAddress}`);return{txHash:await this.chain.refundByKey({dropKey:r})}}};function p(a,e){if(!a)throw new i("API_ERROR",`SafeDropApiPort.${e} is not implemented by the injected api adapter`);return a}function Y(a,e){let r=new y(e.chain,e.api,e.crypto,a.claimBaseUrl),n=new P(e.chain,e.signer),s=new w(e.chain),d=new f(e.chain,e.api,e.crypto),{api:o}=e;return{config:a,deposit:t=>r.execute(t),retrieveClaimKey:t=>o.retrieveClaimKey(t),withdraw:t=>n.execute(t),refund:t=>s.execute(t),getDrop:(t,l)=>e.chain.getDrop(t,l),getDropByKey:t=>e.chain.getDropByKey(t),getDropKeyByClaimAddress:(t,l)=>e.chain.getDropKeyByClaimAddress(t,l),getClaimedRecipient:t=>e.chain.getClaimedRecipient({id:t}),getPendingDropsById:t=>e.chain.getPendingDropsById({id:t}),getPendingDropsByRecipient:t=>e.chain.getPendingDropsByRecipient({recipient:t}),getPendingDropsBySponsor:t=>e.chain.getPendingDropsBySponsor({sponsor:t}),withdrawUnmapped:t=>e.chain.withdrawUnmapped(t),withdrawMapped:t=>e.chain.withdrawMapped(t),batchWithdrawMapped:t=>e.chain.batchWithdrawMapped({count:t}),batchWithdrawMappedByKeys:t=>e.chain.batchWithdrawMappedByKeys({dropKeys:t}),refundByKey:t=>e.chain.refundByKey({dropKey:t}),getChangeNonce:t=>e.chain.getChangeNonce({id:t}),getPendingRecipientChange:t=>e.chain.getPendingRecipientChange({id:t}),requestRecipientChange:(t,l)=>e.chain.requestRecipientChange({id:t,newRecipient:l}),completeRecipientChange:t=>e.chain.completeRecipientChange(t),cancelRecipientChange:t=>e.chain.cancelRecipientChange({id:t}),resetRecipient:t=>e.chain.resetRecipient(t),listDrops:t=>p(o.listDrops,"listDrops").call(o,t),rejectDrops:t=>p(o.rejectDrops,"rejectDrops").call(o,{dropIds:t}),listEnvelopes:t=>p(o.listEnvelopes,"listEnvelopes").call(o,t),getLeaderboard:t=>p(o.getLeaderboard,"getLeaderboard").call(o,t),getMyLeaderboardEntry:t=>p(o.getMyLeaderboardEntry,"getMyLeaderboardEntry").call(o,t),listHistories:t=>p(o.listHistories,"listHistories").call(o,t),getXConnection:()=>p(o.getXConnection,"getXConnection").call(o),connectX:t=>p(o.connectX,"connectX").call(o,t),disconnectX:()=>p(o.disconnectX,"disconnectX").call(o),submitFeedback:t=>p(o.submitFeedback,"submitFeedback").call(o,t),setRevealYou:t=>p(o.setRevealYou,"setRevealYou").call(o,{revealYou:t}),requestRecipientChangeSignature:t=>p(o.requestRecipientChangeSignature,"requestRecipientChangeSignature").call(o,t),requestRecipientResetSignature:t=>p(o.requestRecipientResetSignature,"requestRecipientResetSignature").call(o,t),batchClaim:t=>d.execute(t),requestBatchClaimSignature:t=>p(o.requestBatchClaimSignature,"requestBatchClaimSignature").call(o,t)}}export{g as a,S as b,E as c,B as d,M as e,y as f,f as g,P as h,w as i,Y as j};