@zama-fhe/sdk 3.8.0-beta.12 → 3.8.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/telemetry.cjs +1 -1
- package/dist/esm/{base-signer-CfjlL6bq.js → base-signer-6YPpqhw9.js} +2 -2
- package/dist/esm/{base-signer-CfjlL6bq.js.map → base-signer-6YPpqhw9.js.map} +1 -1
- package/dist/esm/cleartext/index.js +1 -1
- package/dist/esm/{cleartext-BHi17H00.js → cleartext-RqXnz7I6.js} +2 -2
- package/dist/esm/{cleartext-BHi17H00.js.map → cleartext-RqXnz7I6.js.map} +1 -1
- package/dist/esm/ethers/index.js +1 -1
- package/dist/esm/{fhevm-relayer-FiD6EMmL.js → fhevm-relayer-DF4uuzDF.js} +2 -2
- package/dist/esm/{fhevm-relayer-FiD6EMmL.js.map → fhevm-relayer-DF4uuzDF.js.map} +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/internal/index.js +1 -1
- package/dist/esm/node/index.js +1 -1
- package/dist/esm/{telemetry-BsoDvF-G.js → telemetry-D9Mf59ts.js} +2 -2
- package/dist/esm/{telemetry-BsoDvF-G.js.map → telemetry-D9Mf59ts.js.map} +1 -1
- package/dist/esm/vaults/index.js +1 -1
- package/dist/esm/viem/index.js +1 -1
- package/dist/esm/web/index.js +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{S as e,_ as t,a as n,b as r,c as i,d as a,g as o,h as s,i as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,v as ee}from"./relayer-ov8b_HOu.js";import{a as g,c as te,d as ne,i as _,l as v,n as re,o as y,s as ie,t as b,u as ae}from"./signing-CneT-WIV.js";import{n as oe,r as x,t as S}from"./encryption-ieCO6J5r.js";import{A as se,C as ce,D as le,F as ue,G as de,H as C,I as fe,J as w,K as pe,L as T,M as E,N as me,O as he,P as ge,R as D,S as _e,T as ve,V as ye,W as be,Y as xe,_ as Se,a as Ce,b as we,c as Te,d as Ee,f as De,g as O,h as Oe,i as ke,j as Ae,k as je,l as Me,m as Ne,n as Pe,o as Fe,q as Ie,r as Le,s as Re,t as ze,u as Be,v as Ve,x as He,z as Ue}from"./wrappers-registry-DnYVQ02R.js";import{n as We,r as k}from"./fatal-batch-CI1pes1q.js";import{a as A,c as Ge,d as Ke,f as qe,h as Je,l as Ye,m as Xe,n as Ze,o as Qe,p as $e,r as j,s as et,t as tt,u as nt}from"./token-DlsiZmg5.js";import{C as rt,D as it,E as at,O as ot,T as st,_ as ct,a as lt,c as ut,d as dt,f as ft,g as pt,h as mt,i as ht,l as gt,m as _t,n as vt,o as yt,p as bt,r as xt,s as St,t as Ct,u as wt,v as Tt,w as Et,y as Dt}from"./wrapped-token-C8eKid8W.js";import{r as M}from"./telemetry-BsoDvF-G.js";import{t as Ot}from"./cleartext-BHi17H00.js";import{a as kt,c as At,d as jt,f as Mt,i as Nt,l as Pt,m as Ft,n as It,o as N,p as Lt,r as Rt,s as zt,t as Bt,u as Vt}from"./base-signer-CfjlL6bq.js";import{n as P,r as Ht,s as Ut,t as Wt}from"./primitives-Cym-3HKa.js";import{t as F}from"./validation-ChQwNxaY.js";import{a as Gt,c as Kt,i as qt,l as Jt,n as Yt,o as Xt,r as Zt,s as Qt,t as $t,u as en}from"./chains-CF-Hzs9R.js";import{getAddress as I,size as tn}from"viem";import{z as L}from"zod/mini";function nn(e,t){if(e instanceof p){let n=t[e.code];if(n)return n(e)}return t._?.(e)}var R=class extends p{encryptedValue;contractAddress;account;constructor(e,t){super(c.NotEntitled,`Account ${e.account} is not entitled to decrypt encrypted value ${e.encryptedValue} on contract ${e.contractAddress}. This is not a transient failure — the account needs an on-chain ACL grant before it can decrypt this encrypted value.`,t),this.name=`NotEntitledError`,this.encryptedValue=e.encryptedValue,this.contractAddress=e.contractAddress,this.account=e.account}},z=class extends p{constructor(e,t){super(c.DelegationSelfNotAllowed,e,t),this.name=`DelegationSelfNotAllowedError`}},rn=class extends p{constructor(e,t){super(c.DelegationCooldown,e,t),this.name=`DelegationCooldownError`}},B=class extends p{constructor(e,t){super(c.DelegationNotFound,e,t),this.name=`DelegationNotFoundError`}},V=class extends p{constructor(e,t){super(c.DelegationExpired,e,t),this.name=`DelegationExpiredError`}},H=class extends p{constructor(e,t){super(c.DelegationExpiryUnchanged,e,t),this.name=`DelegationExpiryUnchangedError`}},U=class extends p{constructor(e,t){super(c.DelegationDelegateEqualsContract,e,t),this.name=`DelegationDelegateEqualsContractError`}},W=class extends p{constructor(e,t){super(c.DelegationDelegateCannotBeWildcard,e,t),this.name=`DelegationDelegateCannotBeWildcardError`}},an=class extends p{constructor(e,t){super(c.DelegationContractIsSelf,e,t),this.name=`DelegationContractIsSelfError`}},on=class extends p{constructor(e,t){super(c.AclPaused,e,t),this.name=`AclPausedError`}},G=class extends p{constructor(e,t){super(c.DelegationExpirationTooSoon,e,t),this.name=`DelegationExpirationTooSoonError`}},K=class extends p{constructor(e,t){super(c.DelegationNotPropagated,e,t),this.name=`DelegationNotPropagatedError`}};const sn=[S,y,u,K,re,b,R,k,_,v];function q(e,n,c={}){if(sn.some(t=>e instanceof t))return e;let d=e instanceof Error?e.message:n;if(e instanceof Error&&f(e.message))return new _(e.message,{cause:e});if(t(e))return new v(`The permit's KMS context has been revoked on-chain, so the permit is no longer usable. The SDK evicts the permit and re-grants automatically; if this error surfaced, the retry failed the same way. The on-chain validity check is cached for up to 15 minutes, so a just-revoked context can keep failing across that window. Retry after the window; the SDK re-runs the recovery on the next decrypt, no manual cleanup is needed.`,{cause:e});if(e instanceof Error&&l(e.message))return c.isDelegated?new K(`Delegated decryption was denied by the on-chain ACL check. This is most commonly caused by the delegation not having propagated yet, or by the RPC node serving a stale block. Propagation usually completes within ~10 blocks (a few seconds) and the SDK retries across that window; seeing this means it did not sync in time. Retry shortly (and prefer a fresh, low-lag RPC endpoint). If it persists, the delegator may genuinely lack the on-chain ACL grant.`,{cause:e}):new R({encryptedValue:r(e.message)??``,contractAddress:c.contractAddress??``,account:c.account??``},{cause:e});if(a(e))return new k(d,{cause:e,retryAfter:i(e)});let p=m(e);return p===void 0&&ee(e)?new k(d,{cause:e,retryAfter:i(e)}):p===400?new y(e instanceof Error?e.message:`No ciphertext for this account`,{cause:e}):c.isDelegated&&p===500?new K(`Delegated decryption failed with a server error. This is most commonly caused by the delegation not having propagated to the gateway yet. Cross-chain sync usually completes within ~10 blocks (a few seconds) and the SDK retries across that window; seeing this means it did not sync in time — retry shortly. If the error persists, the gateway or relayer may be experiencing an unrelated issue.`,{cause:e}):s(e)||p!==void 0?new u(d,p,{cause:e,retryAfter:i(e),retryable:o(e)||void 0}):new S(n,{cause:e})}function cn(e,t){if(e instanceof p)return e;let n=m(e),r=o(e);return n!==void 0||s(e)?new u(e instanceof Error?e.message:t,n,{cause:e,retryAfter:i(e),retryable:r||void 0}):new x(t,{cause:e})}const J=[{type:`function`,name:`allow`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`allowForDecryption`,inputs:[{name:`handlesList`,type:`bytes32[]`,internalType:`bytes32[]`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`allowTransient`,inputs:[{name:`ciphertext`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`cleanTransientStorage`,inputs:[],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`delegateForUserDecryption`,inputs:[{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`},{name:`expirationDate`,type:`uint64`,internalType:`uint64`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`getUserDecryptionDelegationExpirationDate`,inputs:[{name:`delegator`,type:`address`,internalType:`address`},{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint64`,internalType:`uint64`}],stateMutability:`view`},{type:`function`,name:`isAccountDenied`,inputs:[{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isAllowed`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isAllowedForDecryption`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isHandleDelegatedForUserDecryption`,inputs:[{name:`delegator`,type:`address`,internalType:`address`},{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`},{name:`handle`,type:`bytes32`,internalType:`bytes32`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`multicall`,inputs:[{name:`data`,type:`bytes[]`,internalType:`bytes[]`}],outputs:[{name:`results`,type:`bytes[]`,internalType:`bytes[]`}],stateMutability:`payable`},{type:`function`,name:`persistAllowed`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`revokeDelegationForUserDecryption`,inputs:[{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`}];function Y(e,t,n,r){return{address:e,abi:J,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function X(e,t,n){return{address:e,abi:J,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function ln(e,t,n,r){return{address:e,abi:J,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function un(e,t,n,r,i){return{address:e,abi:J,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const Z=2n**64n-1n,Q=`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`;function dn(e){return Nt(e.signer,e.provider,e)}var fn=class{#e;#t;#n;#r;#i;#a;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#a=e.emitEvent}#o(e){return w(this.#r,e)}#s(e,t){throw this.#a({type:C.PermitError,operation:e,error:t instanceof Error?t:Error(String(t))}),t}async grantPermit(e){if(e.length===0)return;let t;try{t=this.#o(`grantPermit`),await Qe(`grantPermit`,this.#e,this.#t)}catch(e){this.#s(`grantPermit`,e)}await t.grantPermit(e)}async grantDelegationPermit(e,t){if(t.length===0)return;let n;try{n=this.#o(`grantDelegationPermit`),await Qe(`grantDelegationPermit`,this.#e,this.#t)}catch(e){this.#s(`grantDelegationPermit`,e)}await n.grantPermit(t,e)}async hasPermit(e){return this.#r?this.#r.hasPermit(e):!1}async hasDelegationPermit(e,t){return this.#r?this.#r.hasPermit(t,e):!1}async warmTransportKeyPair(){let e=this.#r;if(!e)return;let t=this.#e?.walletAccount.getSnapshot();t&&await e.warmTransportKeyPair(t.address)}registerPermit(e,t){return this.batchRegisterPermits([{prepared:e,signature:t}])}async batchRegisterPermits(e){let t;try{t=this.#o(`registerPermit`)}catch(e){this.#s(`registerPermit`,e)}await t.batchRegisterPermits(e),await Promise.all([...new Set(e.map(e=>e.prepared.signerAddress))].map(e=>this.#c(e)))}async revokePermits(e){let t=this.#o(`revokePermits`),n=I((await A(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#c(n)}}async clear(){let e=this.#o(`clear`),t=I((await A(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#c(t)}}async#c(e){await D(`clear decrypt cache`,()=>this.#n.clearForRequester(e),this.#i)}async revokeTransportKeyPair(e){await this.#o(`revokeTransportKeyPair`).revokeTransportKeyPair(e)}async warmTransportKeyPairScope(e){await this.#o(`warmTransportKeyPairScope`).warmTransportKeyPairScope(e)}},pn=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return w(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let r=this.#r(`delegateDecryption`),i=await A(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(r,{contractAddress:e,delegateAddress:t,delegatorAddress:i.address,expirationDate:n})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let n=this.#r(`revokeDelegation`),r=await A(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(n,{contractAddress:e,delegateAddress:t,delegatorAddress:r.address})}async isActive(e){return this.#n.isDelegated(e)}async getExpiry(e){return this.#n.getDelegationExpiry(e)}async getStatus(e){return this.#n.getStatus(e)}},mn=class{#e;#t;#n;#r;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.router,this.#r=e.decryptionService}#i(e){return w(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),r=await A(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,r.address,M(t,`decrypt-values`))}async delegatedDecryptValues(e,t,n=t,r){let i=this.#i(`delegatedDecryptValues`),a=await A(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedDecryptValues(e,t,a.address,n,M(r,`delegated-decrypt-values`))}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};let n=M(t,`decrypt-public-values`);try{let t=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:n}),r={};return t.checkSignaturesArgs.handlesList.forEach((e,n)=>{ye(t.clearValues[n],`result.clearValues[${n}]`),r[e]=t.clearValues[n].value}),{clearValues:r,abiEncodedClearValues:t.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:t.checkSignaturesArgs.decryptionProof}}catch(e){throw q(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:r,waitForPropagation:i,operation:a}){let o=this.#i(`delegatedBatchDecryptValues`),s=await A(`delegatedBatchDecryptValues`,this.#e,this.#t);return o.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:s.address,accountAddress:n,maxConcurrency:r,waitForPropagation:i,operation:a??`delegated-batch-decrypt-values`})}},hn=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}prepare(e,t){return this.#e.prepare(e,t)}preparePermit(e){return this.#t.preparePermit(e)}batchPreparePermits(e){return this.#t.batchPreparePermits(e)}},gn=class{async get(e){return(await chrome.storage.session.get(e))[e]??null}async set(e,t){await chrome.storage.session.set({[e]:t})}async delete(e){await chrome.storage.session.remove(e)}};const _n=new gn,vn=L.union([L.bigint(),L.boolean(),P]),yn=L.array(L.string());var bn=class{#e;#t;#n=`zama:decrypt`;#r=`${this.#n}:keys`;#i=Promise.resolve();constructor(e,t){this.#e=e,this.#t=t}async get(e,t,n){try{let r=this.#c(e,t,n),i=await this.#e.get(r);if(i===null)return null;let a=vn.safeParse(i);return a.success?a.data:(await this.delete(e,t,n),null)}catch(e){return this.#t.warn(`CachingService.get failed`,{error:e}),null}}async set(e,t,n,r){try{let i=this.#c(e,t,n);await this.#e.set(i,r),this.#i=this.#i.then(()=>this.#u(i).catch(e=>{this.#t.warn(`CachingService index write failed`,{error:e})})),await this.#i}catch(e){this.#t.warn(`CachingService.set failed`,{error:e})}}async delete(e,t,n){let r=this.#c(e,t,n);this.#i=this.#i.then(()=>this.#a(r).catch(e=>{this.#t.warn(`CachingService.delete failed`,{error:e})})),await this.#i}async clearForRequester(e){this.#i=this.#i.then(()=>this.#o(e).catch(e=>{this.#t.warn(`CachingService.clearForRequester failed`,{error:e})})),await this.#i}async clearAll(){this.#i=this.#i.then(()=>this.#s().catch(e=>{this.#t.warn(`CachingService.clearAll failed`,{error:e})})),await this.#i}async#a(e){await this.#e.delete(e).catch(()=>{});let t=await this.#l(),n=t.filter(t=>t!==e);n.length!==t.length&&await this.#e.set(this.#r,n)}async#o(e){let t=I(e),n=`${this.#n}:${t}:`,r=await this.#l(),i=[],a=[];for(let e of r)e.startsWith(n)?i.push(e):a.push(e);await Promise.all(i.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.set(this.#r,a)}async#s(){let e=await this.#l();await Promise.all(e.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.delete(this.#r)}#c(e,t,n){return`${this.#n}:${I(e)}:${I(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=yn.safeParse(e);return t.success?t.data:(await this.#e.delete(this.#r).catch(()=>{}),[])}async#u(e){let t=await this.#l();t.includes(e)||(t.push(e),await this.#e.set(this.#r,t))}};function xn(e,t){let n=Sn(e,t);if(!n)throw new S(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:n.serializedPermit}}function Sn(e,t){let n=Wt(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const Cn=e=>new Promise(t=>setTimeout(t,e));var wn=class{#e;#t;#n;#r;#i;constructor({cache:e,credentialService:t,delegationService:n,router:r,emitEvent:i}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async decryptValues(e,t,n){let r=I(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=I(t),o=I(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:I(r),delegator:a,validate:e=>this.#m(e,{delegatorAddress:a,delegateAddress:o}),errorMessage:`Failed to decrypt delegated encrypted values`},{operation:i?.operation},s))}async#a(e,t){let n;for(let r=0;r<16;r++)try{return await t()}catch(t){if(n=t,!(r<15&&e&&t instanceof K))throw t;await Cn(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:r,maxConcurrency:i=5,waitForPropagation:a=!0,operation:o}){let s=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:I(e.contractAddress)}));if(s.length===0)return{items:s};let c=I(r);try{let e=await this.delegatedDecryptValues(s.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,c,{waitForPropagation:a,operation:o});for(let t of s)this.#d(t,e);return{items:s}}catch(e){if(We(e))throw e;if(s.length===1){let[n=this.#p()]=s;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:I(t)}),{items:s}}}let l=!1,u;if(await j(s.map(e=>async()=>{if(!l)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,c,{waitForPropagation:!1,operation:o});this.#d(e,r)}catch(n){if(We(n)){l=!0,u??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:I(t)})}}),i),u!==void 0)throw u;return{items:s}}async#o(e,t,n,r){let i=xn(e,t),a;try{a=await this.#r.relayer.parseTransportKeyPair({publicKey:i.publicKey,privateKey:i.privateKey,tkmsVersion:e.keypair.tkmsVersion})}catch(e){throw e instanceof Error&&f(e.message)&&await this.#t.evictTransportKeyPair(),e}let o=await this.#r.relayer.parseSignedDecryptionPermit({transportKeyPair:a,serializedPermit:i.serializedPermit});return this.#r.relayer.decryptValues({transportKeyPair:a,signedPermit:o,encryptedValues:n,contractAddress:t,options:r})}async#s(t,n,r,i={spent:!1}){if(t.length===0)return{};let a=t.map(e=>({encryptedValue:e.encryptedValue,contractAddress:I(e.contractAddress)})),o={},s=[];for(let e of a)Ye(e.encryptedValue)?o[e.encryptedValue]=0n:s.push(e);if(s.length===0)return o;let c=Array.from(new Set(a.map(e=>e.contractAddress))),l=Array.from(new Set(s.map(e=>e.contractAddress)));if(n.validate)try{await n.validate(l)}catch(e){throw ee(e)?this.#u(e,`the delegation pre-check`):e}let u=[];for(let e of s){let t=await this.#e.get(n.requesterAddress,e.contractAddress,e.encryptedValue);t===null?u.push(e):o[e.encryptedValue]=t}if(u.length===0)return o;let d=await this.#t.grantPermit(c,n.delegator),f=new Map;for(let e of u){let t=f.get(e.contractAddress);t?t.push(e.encryptedValue):f.set(e.contractAddress,[e.encryptedValue])}let m=[];for(let[e,t]of f)for(let n of Ge(t))m.push({contractAddress:e,encryptedValues:n});let h=Date.now(),g=u.map(e=>e.encryptedValue);try{this.#i({type:C.DecryptStart,encryptedValues:g});try{await this.#c(n,d,m,o,r)}catch(e){if(!(e instanceof v)||i.spent)throw e;let t=d.permissions.map(e=>e.serializedPermit.signature);i.spent=!0;try{d=await this.#t.recoverPermits(c,n.delegator,t)}catch(e){throw e instanceof b?new v(`The permit's KMS context has been revoked on-chain and the automatic re-grant failed, so the decrypt cannot proceed. Establish a new permit for this scope and retry.`,{cause:e}):e}await this.#c(n,d,m.filter(({encryptedValues:e})=>e.some(e=>o[e]===void 0)),o,r)}let e={};for(let t of g){let n=o[t];n!==void 0&&(e[t]=n)}return this.#i({type:C.DecryptEnd,durationMs:Date.now()-h,encryptedValues:g,result:e}),o}catch(t){let r=t instanceof p&&t.cause instanceof Error?t.cause:t;throw this.#i({type:C.DecryptError,error:e(r),durationMs:Date.now()-h,encryptedValues:g}),q(t,n.errorMessage,{isDelegated:n.delegator!==void 0})}}async#c(e,t,n,r,i){let a=(await j(n.map(({contractAddress:n,encryptedValues:a})=>async()=>{try{await this.#l(e,t,n,a,r,i);return}catch(e){return e}}),5)).filter(e=>e!==void 0);if(a.length>0)throw a.find(e=>e instanceof v)??a[0]}async#l(e,t,n,r,i,a){let o;try{o=await this.#o(t,n,r,a)}catch(t){throw q(t,e.errorMessage,{isDelegated:e.delegator!==void 0,contractAddress:n,account:e.delegator??e.requesterAddress})}for(let t=0;t<r.length;t++){let a=r[t],s=o[t]?.value;a!==void 0&&s!==void 0&&(i[a]=s,await this.#e.set(e.requesterAddress,n,a,s))}let s=r.filter(e=>i[e]===void 0);if(s.length>0)throw new S(`${e.errorMessage}: relayer returned no clear value for ${s.length} of ${r.length} handle(s) on ${n}`,{cause:AggregateError(s.map(e=>new S(`No clear value for handle ${e} on ${n}`)),`${s.length} handle(s) missing a clear value on ${n}`)})}#u(e,t){return new k(`RPC provider rate-limited ${t}; retry with backoff.`,{cause:e,retryAfter:i(e)})}#d(e,t){let n=t[e.encryptedValue];if(n===void 0){e.error=new S(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=n}#f(e,t,n){return e instanceof p?e:q(e,t,n)}#p(){throw new S(`Batch delegated decryption invariant failed: missing item`)}async#m(e,{delegatorAddress:t,delegateAddress:n}){let r=await this.#n.findInactiveDelegations(e,t,n);if(r.size!==0)for(let e of r.values())throw e}};const $={AlreadyDelegatedOrRevokedInSameBlock:e=>new rn(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new an(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new on(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new z(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new U(`Delegate address cannot be the same as the contract address.`,{cause:e}),DelegateCannotBeWildcard:e=>new W(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new G(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new H(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new B(`Cannot revoke: no active delegation exists.`,{cause:e})};function Tn(e){return Object.hasOwn($,e)}function En(e,t){let n=ot(e);if(n&&Tn(n))return $[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries($))if(r.includes(e))return n(t);return null}var Dn=class{#e;#t;#n;#r;constructor({provider:e,router:t,emitEvent:n=()=>{},logger:r}){this.#t=e,this.#e=t,this.#r=r,this.#n=n}async delegateDecryption(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r,expirationDate:i}){if(i&&i.getTime()<Date.now()+36e5)throw new G(`Expiration date must be at least 1 hour in the future`);let a=I(t),o=I(n),s=I(r);if(o===s)throw new z(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===I(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`))throw new W(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`);if(o===a)throw new U(`Delegate address cannot be the same as the contract address (${a}).`);let c=this.#e.relayer.chain.aclContractAddress,l=i?BigInt(Math.floor(i.getTime()/1e3)):Z,u;try{u=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:s,delegateAddress:o})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),u=-1n}if(u===l)throw new H(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return a!==I(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`)&&await this.#i({contractAddress:a,delegatorAddress:s,delegateAddress:o}),this.#s({operation:`delegateDecryption`,signer:e,contractAddress:a,config:Y(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=I(t),a=I(n),o=I(r),s=this.#e.relayer.chain.aclContractAddress,c;try{c=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:o,delegateAddress:a})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),c=1n}if(c===0n)throw new B(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#s({operation:`revokeDelegation`,signer:e,contractAddress:i,config:X(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=I(e.contractAddress)===Q,[n,r]=await Promise.all([this.getDelegationExpiry(e),t?Promise.resolve(0n):this.getDelegationExpiry({...e,contractAddress:Q})]),i=this.#a(n)||this.#a(r)?await this.#t.getBlockTimestamp():void 0,a=this.#o(n,i);if(a.isActive)return a;let o=this.#o(r,i);return o.isActive?o:n>=r?a:o}async#i(e){try{let{isActive:t}=await this.getStatus({...e,contractAddress:Q});t&&this.#r.warn(`delegateDecryption: ${e.delegateAddress} already holds an active wildcard delegation from ${e.delegatorAddress}; this grant for ${e.contractAddress} is redundant.`)}catch(e){this.#r.warn(`delegateDecryption: wildcard redundancy check failed`,{error:e})}}#a(e){return e!==0n&&e!==Z}#o(e,t){return e===0n?{isActive:!1,expiryTimestamp:e}:e===Z?{isActive:!0,expiryTimestamp:e}:{isActive:t!==void 0&&e>t,expiryTimestamp:e}}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let r=this.#e.relayer.chain.aclContractAddress;return this.#t.readContract(ln(r,I(t),I(n),I(e)))}async#s({operation:e,signer:t,contractAddress:n,config:r}){try{return await Ze({operation:e,signer:t,provider:this.#t,config:r,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#c(e),e}}#c(e){if(!(e instanceof xe))return;let t=En(e.cause??e,e);if(t)throw t}async findInactiveDelegations(e,t,n){let r=new Map;return await Promise.all(e.map(async e=>{try{await this.assertDelegationActive(e,t,n)}catch(t){if(t instanceof B||t instanceof V){let n=I(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=I(e),i=I(t),a=I(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new B(`No active delegation from ${i} to ${a} for ${r}`):new V(`Delegation from ${i} to ${a} for ${r} has expired`)}},On=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(t,n){let r=Date.now(),i=I(t.contractAddress);try{this.#t({type:C.EncryptStart},i);let e=await this.#e.relayer.encryptValues({...t,options:n});return this.#t({type:C.EncryptEnd,durationMs:Date.now()-r},i),e}catch(t){throw this.#t({type:C.EncryptError,error:e(t),durationMs:Date.now()-r},i),cn(t,`Encryption failed`)}}},kn=class{#e;#t;#n;#r;#i;#a;#o=new Set;#s;constructor(e){this.#e=e.signer,this.#t=e.router,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.clearCredentialsOnWalletChange,this.#a=e.logger,this.#e&&(this.#s=this.#e.walletAccount.subscribe(e=>{this.#c(e).catch(e=>{this.#a.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#o.add(e),()=>{this.#o.delete(e)}}dispose(){this.#s?.(),this.#s=void 0,this.#o.clear()}async#c(e){let t=e.previous,n=e.next,r=n?.chainId;r!==void 0&&await D(`switch relayer chain`,()=>this.#t.switchChain(r),this.#a),this.#i&&await this.#l(t,n),await Promise.all(Array.from(this.#o,t=>D(`wallet account listener`,()=>t(e),this.#a)))}async#l(e,t){let n=this.#r;n&&await D(`credential wallet account change`,()=>n.handleWalletAccountChange(e,t),this.#a),e&&await D(`clear decrypt cache`,()=>this.#n.clearForRequester(e.address),this.#a)}};const An=L.object({kind:L.literal(`ConfidentialTransfer`),from:P,token:P,to:P,amount:L.bigint()}),jn=L.object({kind:L.literal(`ConfidentialTransferFrom`),from:P,token:P,owner:P,to:P,amount:L.bigint()}),Mn=L.object({kind:L.literal(`SetOperator`),from:P,token:P,operator:P,until:Ut}),Nn=L.object({kind:L.literal(`Unwrap`),from:P,token:P,to:P,amount:L.bigint()}),Pn=L.object({kind:L.literal(`UnwrapAll`),from:P,token:P,to:P}),Fn=L.object({kind:L.literal(`FinalizeUnwrap`),from:P,wrapper:P,unwrapRequestIdOrAmount:Ht}),In=L.object({kind:L.literal(`ApproveUnderlying`),from:P,underlying:P,spender:P,amount:L.bigint()}),Ln=L.object({kind:L.literal(`Wrap`),from:P,wrapper:P,to:P,amount:L.bigint()}),Rn=Ht.check(L.refine(e=>e===`0x`||tn(e)===20,`TransferAndCall.recipientData must be "0x" (self-shield to the sender) or a raw 20-byte address, not a 32-byte ABI-encoded value the wrapper would truncate to a garbage address`)),zn=L.object({kind:L.literal(`TransferAndCall`),from:P,underlying:P,wrapper:P,amount:L.bigint(),recipientData:L.optional(Rn)}),Bn=L.object({kind:L.literal(`DelegateDecryption`),from:P,contractAddress:P,delegateAddress:P,expirationDate:L.optional(L.date())}),Vn=L.object({kind:L.literal(`RevokeDelegation`),from:P,contractAddress:P,delegateAddress:P});L.discriminatedUnion(`kind`,[An,jn,Mn,Nn,Pn,Fn,In,Ln,zn,Bn,Vn]);const Hn=L.strictObject({maxFeePerGas:L.bigint(),maxPriorityFeePerGas:L.bigint()}),Un=L.object({nonce:L.optional(L.int().check(L.nonnegative())),gasLimit:L.optional(L.bigint()),fees:L.optional(Hn)}),Wn=L.object({address:P,abi:L.array(L.unknown()),functionName:L.string(),args:L.array(L.unknown()),value:L.optional(L.bigint()),gas:L.optional(L.bigint())}),Gn=L.extend(Un,{from:P,calldata:Wn});var Kn=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(e,t){t&&=F(Un,t);let n=await this.#e.getChainId(),r=this.#t.chain.id;if(n!==r)throw new h(`Offline.prepare: provider is on chain ${n} but the SDK is configured for chain ${r}. The prepared transaction's contract addresses and encrypted inputs are bound to chain ${r} — point the provider at the same chain.`);let i=F(Gn,{calldata:await this.#r(e),from:e.from,nonce:t?.nonce,gasLimit:t?.gasLimit,fees:t?.fees}),a=await this.#e.prepareTransaction(i);return{kind:e.kind,unsignedTx:a,from:i.from}}async#r(e){switch(e.kind){case`ConfidentialTransfer`:return this.#i(e);case`ConfidentialTransferFrom`:return this.#a(e);case`SetOperator`:return this.#o(e);case`Unwrap`:return this.#s(e);case`UnwrapAll`:return this.#c(e);case`FinalizeUnwrap`:return this.#l(e);case`ApproveUnderlying`:return this.#u(e);case`Wrap`:return this.#d(e);case`TransferAndCall`:return this.#f(e);case`DelegateDecryption`:return this.#p(e);case`RevokeDelegation`:return this.#m(e);default:throw new h(`OfflineService.prepare: unsupported transaction kind '${e.kind}'.`)}}async#i(e){e=F(An,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer`}),r=t[0];if(!r)throw new x(`Encryption returned no handles for ConfidentialTransfer`);return ve(e.token,e.to,r,n)}async#a(e){e=F(jn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer-from`}),r=t[0];if(!r)throw new x(`Encryption returned no handles for ConfidentialTransferFrom`);return le(e.token,e.owner,e.to,r,n)}#o(e){return e=F(Mn,e),E(e.token,e.operator,e.until)}async#s(e){e=F(Nn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-unwrap`}),r=t[0];if(!r)throw new x(`Encryption returned no handles for Unwrap`);return ge(e.token,e.from,e.to,r,n)}async#c(e){e=F(Pn,e);let t=await this.#e.readContract(_e(e.token,e.from));return ue(e.token,e.from,e.to,t)}async#l(e){e=F(Fn,e);let t=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount],options:{operation:`offline-finalize-unwrap`}}).catch(e=>{throw q(e,`Public decryption failed during FinalizeUnwrap`)}),n=t.clearValues[0]?.value;return Ue(n,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),he(e.wrapper,e.unwrapRequestIdOrAmount,n,t.checkSignaturesArgs.decryptionProof)}#u(e){return e=F(In,e),O(e.underlying,e.spender,e.amount)}#d(e){return e=F(Ln,e),T(e.wrapper,e.to,e.amount)}#f(e){return e=F(zn,e),rt(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=F(Bn,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new G(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new z(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new U(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):Z;return Y(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=F(Vn,e),X(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function qn(e){if(!(!Object.hasOwn(e,`transportKeyPairDerivationSecret`)||e.transportKeyPairDerivationSecret!==void 0))throw new h(`transportKeyPairDerivationSecret was passed as undefined, which usually means the environment variable it reads is unset (e.g. process.env.ZAMA_DERIVATION_SECRET). Supply the secret, or omit the option entirely to persist transport key pairs in cleartext on purpose.`)}function Jn(e){if(e===void 0)return;let{importScripts:t}=globalThis;if(!(typeof window>`u`&&typeof document>`u`&&typeof t!=`function`))throw new h(`transportKeyPairDerivationSecret is supported in headless environments only (CLI tools, servers, agents). Remove the option: an environment with a platform keystore, or one that ships a bundle, must delegate at-rest security of the transport key pair to the storage backend.`)}function Yn(e){if(e===void 0)return;let t=F(Pt,e);return new Vt(typeof t==`string`?t:new Uint8Array(t))}var Xn=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){qn(t),Jn(t.transportKeyPairDerivationSecret);let n=Yn(t.transportKeyPairDerivationSecret);this.#e=e.router,this.provider=e.provider,this.signer=e.signer,this.storage=e.storage,this.#r=e.onEvent??function(){},this.#i=e.logger,this.#a=new bn(e.storage,this.#i),this.#u=new Dn({provider:this.provider,router:e.router,emitEvent:this.emitEvent.bind(this),logger:this.#i});let r={};for(let t of e.chains)t.registryAddress&&(r[t.id]=t.registryAddress);this.registry=new N({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new zt({router:e.router,signer:e.signer,transportKeyPairTTL:e.transportKeyPairTTL,permitTTL:e.permitTTL,scope:e.transportKeyPairScope,derivationSecret:n,storage:this.storage,permitStorage:e.permitStorage,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),e.signer&&(this.#c=new wn({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new On({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new kn({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,clearCredentialsOnWalletChange:e.clearCredentialsOnWalletChange,logger:this.#i}),this.#d=new Kn({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new fn({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new pn({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new mn({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new hn(this.#d,this.#l)}onWalletAccountChange(e){return this.#o.onWalletAccountChange(e)}get logger(){return this.#i}get relayer(){return this.#e.relayer}emitEvent(e,t){try{this.#r({...e,tokenAddress:t,timestamp:Date.now()})}catch(t){this.#i.warn(`${e.type} event listener silently failed`,{error:t})}}createWrappersRegistry(e){return new N({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,M(t,`encrypt`))}createToken(e){return new tt(this,e)}createWrappedToken(e){return new Ct(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};export{vt as ACL_TOPICS,on as AclPausedError,xt as AclTopics,nt as BalanceCheckUnavailableError,Bt as BaseSigner,Je as ChainMismatchError,gn as ChromeSessionStorage,h as ConfigurationError,mn as Decryption,S as DecryptionFailedError,kt as DefaultRegistryAddresses,an as DelegationContractIsSelfError,rn as DelegationCooldownError,W as DelegationDelegateCannotBeWildcardError,U as DelegationDelegateEqualsContractError,G as DelegationExpirationTooSoonError,V as DelegationExpiredError,H as DelegationExpiryUnchangedError,B as DelegationNotFoundError,K as DelegationNotPropagatedError,z as DelegationSelfNotAllowedError,pn as Delegations,Te as ERC1363_INTERFACE_ID,Ke as ERC20ReadFailedError,Me as ERC7984_INTERFACE_ID,Be as ERC7984_WRAPPER_INTERFACE_ID,oe as EncryptOffloadUnavailableError,x as EncryptionFailedError,Lt as IndexedDBStorage,qe as InsufficientAllowanceError,$e as InsufficientConfidentialBalanceError,Xe as InsufficientERC20BalanceError,_ as InvalidTransportKeyPairError,g as KeyWrappingError,Z as MAX_UINT64,jt as MemoryStorage,It as MutableWalletAccountStore,y as NoCiphertextError,R as NotEntitledError,hn as Offline,fn as Permits,ie as PreparedPermitChainMismatchError,te as PreparedPermitExpiredError,u as RelayerRequestFailedError,v as RevokedKmsContextError,k as RpcRateLimitError,be as SignerNotConfiguredError,de as SignerRequiredError,b as SigningFailedError,re as SigningRejectedError,ht as TOKEN_TOPICS,tt as Token,lt as Topics,xe as TransactionRevertedError,ae as TransportKeyPairChangedError,ne as TransportKeyPairExpiredError,Et as UnlistedConfidentialTokenError,it as UnshieldAlreadyFinalizedError,st as VaultBatcherPausedError,at as VaultGroupJoinUnconfirmedError,Q as WILDCARD_CONTRACT,pe as WalletAccountNotReadyError,Ie as WalletNotConnectedError,Ct as WrappedToken,N as WrappersRegistry,et as ZERO_ENCRYPTED_VALUE,p as ZamaError,c as ZamaErrorCode,Xn as ZamaSDK,C as ZamaSDKEvents,Oe as allowanceContract,$t as anvil,O as approveContract,Se as balanceOfContract,Yt as bscTestnet,Zt as chains,_n as chromeSessionStorage,Ot as cleartext,_e as confidentialBalanceOfContract,ce as confidentialTotalSupplyContract,ve as confidentialTransferContract,le as confidentialTransferFromContract,dn as createConfig,Rt as createWalletAccountStore,Ve as decimalsContract,yt as decodeAclEvent,St as decodeAclEvents,ut as decodeConfidentialTransfer,gt as decodeDelegatedForUserDecryption,wt as decodeOnChainEvent,dt as decodeOnChainEvents,ft as decodeRevokedDelegationForUserDecryption,bt as decodeUnwrapFinalized,_t as decodeUnwrapRequested,mt as decodeWrap,Y as delegateForUserDecryptionContract,he as finalizeUnwrapContract,pt as findDelegatedForUserDecryption,ct as findRevokedDelegationForUserDecryption,Tt as findUnwrapRequested,Dt as findWrap,ze as getConfidentialTokenAddressContract,ln as getDelegationExpiryContract,Pe as getTokenAddressContract,Le as getTokenPairContract,ke as getTokenPairsContract,Ce as getTokenPairsLengthContract,Fe as getTokenPairsSliceContract,qt as hardhat,Gt as hoodi,Ft as indexedDBStorage,je as inferredTotalSupplyContract,Ee as isConfidentialTokenContract,Re as isConfidentialTokenValidContract,De as isConfidentialWrapperContract,Ye as isEncryptedValueZero,un as isHandleDelegatedContract,se as isOperatorContract,n as isRetryable,Xt as mainnet,nn as matchZamaError,Mt as memoryStorage,we as nameContract,At as parsePreparedPermit,Qt as polygon,Kt as polygonAmoy,Ae as rateContract,d as retryAfterSeconds,X as revokeDelegationContract,Jt as sepolia,E as setOperatorContract,Ne as supportsInterfaceContract,He as symbolContract,rt as transferAndCallContract,me as underlyingContract,ge as unwrapContract,ue as unwrapFromBalanceContract,fe as unwrapRequesterContract,T as wrapContract,en as zenithTrexTestnet};
|
|
1
|
+
import{S as e,_ as t,a as n,b as r,c as i,d as a,g as o,h as s,i as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,v as ee}from"./relayer-ov8b_HOu.js";import{a as g,c as te,d as ne,i as _,l as v,n as re,o as y,s as ie,t as b,u as ae}from"./signing-CneT-WIV.js";import{n as oe,r as x,t as S}from"./encryption-ieCO6J5r.js";import{A as se,C as ce,D as le,F as ue,G as de,H as C,I as fe,J as w,K as pe,L as T,M as E,N as me,O as he,P as ge,R as D,S as _e,T as ve,V as ye,W as be,Y as xe,_ as Se,a as Ce,b as we,c as Te,d as Ee,f as De,g as O,h as Oe,i as ke,j as Ae,k as je,l as Me,m as Ne,n as Pe,o as Fe,q as Ie,r as Le,s as Re,t as ze,u as Be,v as Ve,x as He,z as Ue}from"./wrappers-registry-DnYVQ02R.js";import{n as We,r as k}from"./fatal-batch-CI1pes1q.js";import{a as A,c as Ge,d as Ke,f as qe,h as Je,l as Ye,m as Xe,n as Ze,o as Qe,p as $e,r as j,s as et,t as tt,u as nt}from"./token-DlsiZmg5.js";import{C as rt,D as it,E as at,O as ot,T as st,_ as ct,a as lt,c as ut,d as dt,f as ft,g as pt,h as mt,i as ht,l as gt,m as _t,n as vt,o as yt,p as bt,r as xt,s as St,t as Ct,u as wt,v as Tt,w as Et,y as Dt}from"./wrapped-token-C8eKid8W.js";import{r as M}from"./telemetry-D9Mf59ts.js";import{t as Ot}from"./cleartext-RqXnz7I6.js";import{a as kt,c as At,d as jt,f as Mt,i as Nt,l as Pt,m as Ft,n as It,o as N,p as Lt,r as Rt,s as zt,t as Bt,u as Vt}from"./base-signer-6YPpqhw9.js";import{n as P,r as Ht,s as Ut,t as Wt}from"./primitives-Cym-3HKa.js";import{t as F}from"./validation-ChQwNxaY.js";import{a as Gt,c as Kt,i as qt,l as Jt,n as Yt,o as Xt,r as Zt,s as Qt,t as $t,u as en}from"./chains-CF-Hzs9R.js";import{getAddress as I,size as tn}from"viem";import{z as L}from"zod/mini";function nn(e,t){if(e instanceof p){let n=t[e.code];if(n)return n(e)}return t._?.(e)}var R=class extends p{encryptedValue;contractAddress;account;constructor(e,t){super(c.NotEntitled,`Account ${e.account} is not entitled to decrypt encrypted value ${e.encryptedValue} on contract ${e.contractAddress}. This is not a transient failure — the account needs an on-chain ACL grant before it can decrypt this encrypted value.`,t),this.name=`NotEntitledError`,this.encryptedValue=e.encryptedValue,this.contractAddress=e.contractAddress,this.account=e.account}},z=class extends p{constructor(e,t){super(c.DelegationSelfNotAllowed,e,t),this.name=`DelegationSelfNotAllowedError`}},rn=class extends p{constructor(e,t){super(c.DelegationCooldown,e,t),this.name=`DelegationCooldownError`}},B=class extends p{constructor(e,t){super(c.DelegationNotFound,e,t),this.name=`DelegationNotFoundError`}},V=class extends p{constructor(e,t){super(c.DelegationExpired,e,t),this.name=`DelegationExpiredError`}},H=class extends p{constructor(e,t){super(c.DelegationExpiryUnchanged,e,t),this.name=`DelegationExpiryUnchangedError`}},U=class extends p{constructor(e,t){super(c.DelegationDelegateEqualsContract,e,t),this.name=`DelegationDelegateEqualsContractError`}},W=class extends p{constructor(e,t){super(c.DelegationDelegateCannotBeWildcard,e,t),this.name=`DelegationDelegateCannotBeWildcardError`}},an=class extends p{constructor(e,t){super(c.DelegationContractIsSelf,e,t),this.name=`DelegationContractIsSelfError`}},on=class extends p{constructor(e,t){super(c.AclPaused,e,t),this.name=`AclPausedError`}},G=class extends p{constructor(e,t){super(c.DelegationExpirationTooSoon,e,t),this.name=`DelegationExpirationTooSoonError`}},K=class extends p{constructor(e,t){super(c.DelegationNotPropagated,e,t),this.name=`DelegationNotPropagatedError`}};const sn=[S,y,u,K,re,b,R,k,_,v];function q(e,n,c={}){if(sn.some(t=>e instanceof t))return e;let d=e instanceof Error?e.message:n;if(e instanceof Error&&f(e.message))return new _(e.message,{cause:e});if(t(e))return new v(`The permit's KMS context has been revoked on-chain, so the permit is no longer usable. The SDK evicts the permit and re-grants automatically; if this error surfaced, the retry failed the same way. The on-chain validity check is cached for up to 15 minutes, so a just-revoked context can keep failing across that window. Retry after the window; the SDK re-runs the recovery on the next decrypt, no manual cleanup is needed.`,{cause:e});if(e instanceof Error&&l(e.message))return c.isDelegated?new K(`Delegated decryption was denied by the on-chain ACL check. This is most commonly caused by the delegation not having propagated yet, or by the RPC node serving a stale block. Propagation usually completes within ~10 blocks (a few seconds) and the SDK retries across that window; seeing this means it did not sync in time. Retry shortly (and prefer a fresh, low-lag RPC endpoint). If it persists, the delegator may genuinely lack the on-chain ACL grant.`,{cause:e}):new R({encryptedValue:r(e.message)??``,contractAddress:c.contractAddress??``,account:c.account??``},{cause:e});if(a(e))return new k(d,{cause:e,retryAfter:i(e)});let p=m(e);return p===void 0&&ee(e)?new k(d,{cause:e,retryAfter:i(e)}):p===400?new y(e instanceof Error?e.message:`No ciphertext for this account`,{cause:e}):c.isDelegated&&p===500?new K(`Delegated decryption failed with a server error. This is most commonly caused by the delegation not having propagated to the gateway yet. Cross-chain sync usually completes within ~10 blocks (a few seconds) and the SDK retries across that window; seeing this means it did not sync in time — retry shortly. If the error persists, the gateway or relayer may be experiencing an unrelated issue.`,{cause:e}):s(e)||p!==void 0?new u(d,p,{cause:e,retryAfter:i(e),retryable:o(e)||void 0}):new S(n,{cause:e})}function cn(e,t){if(e instanceof p)return e;let n=m(e),r=o(e);return n!==void 0||s(e)?new u(e instanceof Error?e.message:t,n,{cause:e,retryAfter:i(e),retryable:r||void 0}):new x(t,{cause:e})}const J=[{type:`function`,name:`allow`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`allowForDecryption`,inputs:[{name:`handlesList`,type:`bytes32[]`,internalType:`bytes32[]`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`allowTransient`,inputs:[{name:`ciphertext`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`cleanTransientStorage`,inputs:[],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`delegateForUserDecryption`,inputs:[{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`},{name:`expirationDate`,type:`uint64`,internalType:`uint64`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`getUserDecryptionDelegationExpirationDate`,inputs:[{name:`delegator`,type:`address`,internalType:`address`},{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint64`,internalType:`uint64`}],stateMutability:`view`},{type:`function`,name:`isAccountDenied`,inputs:[{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isAllowed`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isAllowedForDecryption`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isHandleDelegatedForUserDecryption`,inputs:[{name:`delegator`,type:`address`,internalType:`address`},{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`},{name:`handle`,type:`bytes32`,internalType:`bytes32`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`multicall`,inputs:[{name:`data`,type:`bytes[]`,internalType:`bytes[]`}],outputs:[{name:`results`,type:`bytes[]`,internalType:`bytes[]`}],stateMutability:`payable`},{type:`function`,name:`persistAllowed`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`revokeDelegationForUserDecryption`,inputs:[{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`}];function Y(e,t,n,r){return{address:e,abi:J,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function X(e,t,n){return{address:e,abi:J,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function ln(e,t,n,r){return{address:e,abi:J,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function un(e,t,n,r,i){return{address:e,abi:J,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const Z=2n**64n-1n,Q=`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`;function dn(e){return Nt(e.signer,e.provider,e)}var fn=class{#e;#t;#n;#r;#i;#a;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#a=e.emitEvent}#o(e){return w(this.#r,e)}#s(e,t){throw this.#a({type:C.PermitError,operation:e,error:t instanceof Error?t:Error(String(t))}),t}async grantPermit(e){if(e.length===0)return;let t;try{t=this.#o(`grantPermit`),await Qe(`grantPermit`,this.#e,this.#t)}catch(e){this.#s(`grantPermit`,e)}await t.grantPermit(e)}async grantDelegationPermit(e,t){if(t.length===0)return;let n;try{n=this.#o(`grantDelegationPermit`),await Qe(`grantDelegationPermit`,this.#e,this.#t)}catch(e){this.#s(`grantDelegationPermit`,e)}await n.grantPermit(t,e)}async hasPermit(e){return this.#r?this.#r.hasPermit(e):!1}async hasDelegationPermit(e,t){return this.#r?this.#r.hasPermit(t,e):!1}async warmTransportKeyPair(){let e=this.#r;if(!e)return;let t=this.#e?.walletAccount.getSnapshot();t&&await e.warmTransportKeyPair(t.address)}registerPermit(e,t){return this.batchRegisterPermits([{prepared:e,signature:t}])}async batchRegisterPermits(e){let t;try{t=this.#o(`registerPermit`)}catch(e){this.#s(`registerPermit`,e)}await t.batchRegisterPermits(e),await Promise.all([...new Set(e.map(e=>e.prepared.signerAddress))].map(e=>this.#c(e)))}async revokePermits(e){let t=this.#o(`revokePermits`),n=I((await A(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#c(n)}}async clear(){let e=this.#o(`clear`),t=I((await A(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#c(t)}}async#c(e){await D(`clear decrypt cache`,()=>this.#n.clearForRequester(e),this.#i)}async revokeTransportKeyPair(e){await this.#o(`revokeTransportKeyPair`).revokeTransportKeyPair(e)}async warmTransportKeyPairScope(e){await this.#o(`warmTransportKeyPairScope`).warmTransportKeyPairScope(e)}},pn=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return w(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let r=this.#r(`delegateDecryption`),i=await A(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(r,{contractAddress:e,delegateAddress:t,delegatorAddress:i.address,expirationDate:n})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let n=this.#r(`revokeDelegation`),r=await A(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(n,{contractAddress:e,delegateAddress:t,delegatorAddress:r.address})}async isActive(e){return this.#n.isDelegated(e)}async getExpiry(e){return this.#n.getDelegationExpiry(e)}async getStatus(e){return this.#n.getStatus(e)}},mn=class{#e;#t;#n;#r;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.router,this.#r=e.decryptionService}#i(e){return w(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),r=await A(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,r.address,M(t,`decrypt-values`))}async delegatedDecryptValues(e,t,n=t,r){let i=this.#i(`delegatedDecryptValues`),a=await A(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedDecryptValues(e,t,a.address,n,M(r,`delegated-decrypt-values`))}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};let n=M(t,`decrypt-public-values`);try{let t=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:n}),r={};return t.checkSignaturesArgs.handlesList.forEach((e,n)=>{ye(t.clearValues[n],`result.clearValues[${n}]`),r[e]=t.clearValues[n].value}),{clearValues:r,abiEncodedClearValues:t.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:t.checkSignaturesArgs.decryptionProof}}catch(e){throw q(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:r,waitForPropagation:i,operation:a}){let o=this.#i(`delegatedBatchDecryptValues`),s=await A(`delegatedBatchDecryptValues`,this.#e,this.#t);return o.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:s.address,accountAddress:n,maxConcurrency:r,waitForPropagation:i,operation:a??`delegated-batch-decrypt-values`})}},hn=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}prepare(e,t){return this.#e.prepare(e,t)}preparePermit(e){return this.#t.preparePermit(e)}batchPreparePermits(e){return this.#t.batchPreparePermits(e)}},gn=class{async get(e){return(await chrome.storage.session.get(e))[e]??null}async set(e,t){await chrome.storage.session.set({[e]:t})}async delete(e){await chrome.storage.session.remove(e)}};const _n=new gn,vn=L.union([L.bigint(),L.boolean(),P]),yn=L.array(L.string());var bn=class{#e;#t;#n=`zama:decrypt`;#r=`${this.#n}:keys`;#i=Promise.resolve();constructor(e,t){this.#e=e,this.#t=t}async get(e,t,n){try{let r=this.#c(e,t,n),i=await this.#e.get(r);if(i===null)return null;let a=vn.safeParse(i);return a.success?a.data:(await this.delete(e,t,n),null)}catch(e){return this.#t.warn(`CachingService.get failed`,{error:e}),null}}async set(e,t,n,r){try{let i=this.#c(e,t,n);await this.#e.set(i,r),this.#i=this.#i.then(()=>this.#u(i).catch(e=>{this.#t.warn(`CachingService index write failed`,{error:e})})),await this.#i}catch(e){this.#t.warn(`CachingService.set failed`,{error:e})}}async delete(e,t,n){let r=this.#c(e,t,n);this.#i=this.#i.then(()=>this.#a(r).catch(e=>{this.#t.warn(`CachingService.delete failed`,{error:e})})),await this.#i}async clearForRequester(e){this.#i=this.#i.then(()=>this.#o(e).catch(e=>{this.#t.warn(`CachingService.clearForRequester failed`,{error:e})})),await this.#i}async clearAll(){this.#i=this.#i.then(()=>this.#s().catch(e=>{this.#t.warn(`CachingService.clearAll failed`,{error:e})})),await this.#i}async#a(e){await this.#e.delete(e).catch(()=>{});let t=await this.#l(),n=t.filter(t=>t!==e);n.length!==t.length&&await this.#e.set(this.#r,n)}async#o(e){let t=I(e),n=`${this.#n}:${t}:`,r=await this.#l(),i=[],a=[];for(let e of r)e.startsWith(n)?i.push(e):a.push(e);await Promise.all(i.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.set(this.#r,a)}async#s(){let e=await this.#l();await Promise.all(e.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.delete(this.#r)}#c(e,t,n){return`${this.#n}:${I(e)}:${I(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=yn.safeParse(e);return t.success?t.data:(await this.#e.delete(this.#r).catch(()=>{}),[])}async#u(e){let t=await this.#l();t.includes(e)||(t.push(e),await this.#e.set(this.#r,t))}};function xn(e,t){let n=Sn(e,t);if(!n)throw new S(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:n.serializedPermit}}function Sn(e,t){let n=Wt(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const Cn=e=>new Promise(t=>setTimeout(t,e));var wn=class{#e;#t;#n;#r;#i;constructor({cache:e,credentialService:t,delegationService:n,router:r,emitEvent:i}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async decryptValues(e,t,n){let r=I(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=I(t),o=I(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:I(r),delegator:a,validate:e=>this.#m(e,{delegatorAddress:a,delegateAddress:o}),errorMessage:`Failed to decrypt delegated encrypted values`},{operation:i?.operation},s))}async#a(e,t){let n;for(let r=0;r<16;r++)try{return await t()}catch(t){if(n=t,!(r<15&&e&&t instanceof K))throw t;await Cn(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:r,maxConcurrency:i=5,waitForPropagation:a=!0,operation:o}){let s=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:I(e.contractAddress)}));if(s.length===0)return{items:s};let c=I(r);try{let e=await this.delegatedDecryptValues(s.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,c,{waitForPropagation:a,operation:o});for(let t of s)this.#d(t,e);return{items:s}}catch(e){if(We(e))throw e;if(s.length===1){let[n=this.#p()]=s;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:I(t)}),{items:s}}}let l=!1,u;if(await j(s.map(e=>async()=>{if(!l)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,c,{waitForPropagation:!1,operation:o});this.#d(e,r)}catch(n){if(We(n)){l=!0,u??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:I(t)})}}),i),u!==void 0)throw u;return{items:s}}async#o(e,t,n,r){let i=xn(e,t),a;try{a=await this.#r.relayer.parseTransportKeyPair({publicKey:i.publicKey,privateKey:i.privateKey,tkmsVersion:e.keypair.tkmsVersion})}catch(e){throw e instanceof Error&&f(e.message)&&await this.#t.evictTransportKeyPair(),e}let o=await this.#r.relayer.parseSignedDecryptionPermit({transportKeyPair:a,serializedPermit:i.serializedPermit});return this.#r.relayer.decryptValues({transportKeyPair:a,signedPermit:o,encryptedValues:n,contractAddress:t,options:r})}async#s(t,n,r,i={spent:!1}){if(t.length===0)return{};let a=t.map(e=>({encryptedValue:e.encryptedValue,contractAddress:I(e.contractAddress)})),o={},s=[];for(let e of a)Ye(e.encryptedValue)?o[e.encryptedValue]=0n:s.push(e);if(s.length===0)return o;let c=Array.from(new Set(a.map(e=>e.contractAddress))),l=Array.from(new Set(s.map(e=>e.contractAddress)));if(n.validate)try{await n.validate(l)}catch(e){throw ee(e)?this.#u(e,`the delegation pre-check`):e}let u=[];for(let e of s){let t=await this.#e.get(n.requesterAddress,e.contractAddress,e.encryptedValue);t===null?u.push(e):o[e.encryptedValue]=t}if(u.length===0)return o;let d=await this.#t.grantPermit(c,n.delegator),f=new Map;for(let e of u){let t=f.get(e.contractAddress);t?t.push(e.encryptedValue):f.set(e.contractAddress,[e.encryptedValue])}let m=[];for(let[e,t]of f)for(let n of Ge(t))m.push({contractAddress:e,encryptedValues:n});let h=Date.now(),g=u.map(e=>e.encryptedValue);try{this.#i({type:C.DecryptStart,encryptedValues:g});try{await this.#c(n,d,m,o,r)}catch(e){if(!(e instanceof v)||i.spent)throw e;let t=d.permissions.map(e=>e.serializedPermit.signature);i.spent=!0;try{d=await this.#t.recoverPermits(c,n.delegator,t)}catch(e){throw e instanceof b?new v(`The permit's KMS context has been revoked on-chain and the automatic re-grant failed, so the decrypt cannot proceed. Establish a new permit for this scope and retry.`,{cause:e}):e}await this.#c(n,d,m.filter(({encryptedValues:e})=>e.some(e=>o[e]===void 0)),o,r)}let e={};for(let t of g){let n=o[t];n!==void 0&&(e[t]=n)}return this.#i({type:C.DecryptEnd,durationMs:Date.now()-h,encryptedValues:g,result:e}),o}catch(t){let r=t instanceof p&&t.cause instanceof Error?t.cause:t;throw this.#i({type:C.DecryptError,error:e(r),durationMs:Date.now()-h,encryptedValues:g}),q(t,n.errorMessage,{isDelegated:n.delegator!==void 0})}}async#c(e,t,n,r,i){let a=(await j(n.map(({contractAddress:n,encryptedValues:a})=>async()=>{try{await this.#l(e,t,n,a,r,i);return}catch(e){return e}}),5)).filter(e=>e!==void 0);if(a.length>0)throw a.find(e=>e instanceof v)??a[0]}async#l(e,t,n,r,i,a){let o;try{o=await this.#o(t,n,r,a)}catch(t){throw q(t,e.errorMessage,{isDelegated:e.delegator!==void 0,contractAddress:n,account:e.delegator??e.requesterAddress})}for(let t=0;t<r.length;t++){let a=r[t],s=o[t]?.value;a!==void 0&&s!==void 0&&(i[a]=s,await this.#e.set(e.requesterAddress,n,a,s))}let s=r.filter(e=>i[e]===void 0);if(s.length>0)throw new S(`${e.errorMessage}: relayer returned no clear value for ${s.length} of ${r.length} handle(s) on ${n}`,{cause:AggregateError(s.map(e=>new S(`No clear value for handle ${e} on ${n}`)),`${s.length} handle(s) missing a clear value on ${n}`)})}#u(e,t){return new k(`RPC provider rate-limited ${t}; retry with backoff.`,{cause:e,retryAfter:i(e)})}#d(e,t){let n=t[e.encryptedValue];if(n===void 0){e.error=new S(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=n}#f(e,t,n){return e instanceof p?e:q(e,t,n)}#p(){throw new S(`Batch delegated decryption invariant failed: missing item`)}async#m(e,{delegatorAddress:t,delegateAddress:n}){let r=await this.#n.findInactiveDelegations(e,t,n);if(r.size!==0)for(let e of r.values())throw e}};const $={AlreadyDelegatedOrRevokedInSameBlock:e=>new rn(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new an(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new on(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new z(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new U(`Delegate address cannot be the same as the contract address.`,{cause:e}),DelegateCannotBeWildcard:e=>new W(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new G(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new H(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new B(`Cannot revoke: no active delegation exists.`,{cause:e})};function Tn(e){return Object.hasOwn($,e)}function En(e,t){let n=ot(e);if(n&&Tn(n))return $[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries($))if(r.includes(e))return n(t);return null}var Dn=class{#e;#t;#n;#r;constructor({provider:e,router:t,emitEvent:n=()=>{},logger:r}){this.#t=e,this.#e=t,this.#r=r,this.#n=n}async delegateDecryption(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r,expirationDate:i}){if(i&&i.getTime()<Date.now()+36e5)throw new G(`Expiration date must be at least 1 hour in the future`);let a=I(t),o=I(n),s=I(r);if(o===s)throw new z(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===I(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`))throw new W(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`);if(o===a)throw new U(`Delegate address cannot be the same as the contract address (${a}).`);let c=this.#e.relayer.chain.aclContractAddress,l=i?BigInt(Math.floor(i.getTime()/1e3)):Z,u;try{u=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:s,delegateAddress:o})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),u=-1n}if(u===l)throw new H(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return a!==I(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`)&&await this.#i({contractAddress:a,delegatorAddress:s,delegateAddress:o}),this.#s({operation:`delegateDecryption`,signer:e,contractAddress:a,config:Y(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=I(t),a=I(n),o=I(r),s=this.#e.relayer.chain.aclContractAddress,c;try{c=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:o,delegateAddress:a})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),c=1n}if(c===0n)throw new B(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#s({operation:`revokeDelegation`,signer:e,contractAddress:i,config:X(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=I(e.contractAddress)===Q,[n,r]=await Promise.all([this.getDelegationExpiry(e),t?Promise.resolve(0n):this.getDelegationExpiry({...e,contractAddress:Q})]),i=this.#a(n)||this.#a(r)?await this.#t.getBlockTimestamp():void 0,a=this.#o(n,i);if(a.isActive)return a;let o=this.#o(r,i);return o.isActive?o:n>=r?a:o}async#i(e){try{let{isActive:t}=await this.getStatus({...e,contractAddress:Q});t&&this.#r.warn(`delegateDecryption: ${e.delegateAddress} already holds an active wildcard delegation from ${e.delegatorAddress}; this grant for ${e.contractAddress} is redundant.`)}catch(e){this.#r.warn(`delegateDecryption: wildcard redundancy check failed`,{error:e})}}#a(e){return e!==0n&&e!==Z}#o(e,t){return e===0n?{isActive:!1,expiryTimestamp:e}:e===Z?{isActive:!0,expiryTimestamp:e}:{isActive:t!==void 0&&e>t,expiryTimestamp:e}}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let r=this.#e.relayer.chain.aclContractAddress;return this.#t.readContract(ln(r,I(t),I(n),I(e)))}async#s({operation:e,signer:t,contractAddress:n,config:r}){try{return await Ze({operation:e,signer:t,provider:this.#t,config:r,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#c(e),e}}#c(e){if(!(e instanceof xe))return;let t=En(e.cause??e,e);if(t)throw t}async findInactiveDelegations(e,t,n){let r=new Map;return await Promise.all(e.map(async e=>{try{await this.assertDelegationActive(e,t,n)}catch(t){if(t instanceof B||t instanceof V){let n=I(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=I(e),i=I(t),a=I(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new B(`No active delegation from ${i} to ${a} for ${r}`):new V(`Delegation from ${i} to ${a} for ${r} has expired`)}},On=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(t,n){let r=Date.now(),i=I(t.contractAddress);try{this.#t({type:C.EncryptStart},i);let e=await this.#e.relayer.encryptValues({...t,options:n});return this.#t({type:C.EncryptEnd,durationMs:Date.now()-r},i),e}catch(t){throw this.#t({type:C.EncryptError,error:e(t),durationMs:Date.now()-r},i),cn(t,`Encryption failed`)}}},kn=class{#e;#t;#n;#r;#i;#a;#o=new Set;#s;constructor(e){this.#e=e.signer,this.#t=e.router,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.clearCredentialsOnWalletChange,this.#a=e.logger,this.#e&&(this.#s=this.#e.walletAccount.subscribe(e=>{this.#c(e).catch(e=>{this.#a.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#o.add(e),()=>{this.#o.delete(e)}}dispose(){this.#s?.(),this.#s=void 0,this.#o.clear()}async#c(e){let t=e.previous,n=e.next,r=n?.chainId;r!==void 0&&await D(`switch relayer chain`,()=>this.#t.switchChain(r),this.#a),this.#i&&await this.#l(t,n),await Promise.all(Array.from(this.#o,t=>D(`wallet account listener`,()=>t(e),this.#a)))}async#l(e,t){let n=this.#r;n&&await D(`credential wallet account change`,()=>n.handleWalletAccountChange(e,t),this.#a),e&&await D(`clear decrypt cache`,()=>this.#n.clearForRequester(e.address),this.#a)}};const An=L.object({kind:L.literal(`ConfidentialTransfer`),from:P,token:P,to:P,amount:L.bigint()}),jn=L.object({kind:L.literal(`ConfidentialTransferFrom`),from:P,token:P,owner:P,to:P,amount:L.bigint()}),Mn=L.object({kind:L.literal(`SetOperator`),from:P,token:P,operator:P,until:Ut}),Nn=L.object({kind:L.literal(`Unwrap`),from:P,token:P,to:P,amount:L.bigint()}),Pn=L.object({kind:L.literal(`UnwrapAll`),from:P,token:P,to:P}),Fn=L.object({kind:L.literal(`FinalizeUnwrap`),from:P,wrapper:P,unwrapRequestIdOrAmount:Ht}),In=L.object({kind:L.literal(`ApproveUnderlying`),from:P,underlying:P,spender:P,amount:L.bigint()}),Ln=L.object({kind:L.literal(`Wrap`),from:P,wrapper:P,to:P,amount:L.bigint()}),Rn=Ht.check(L.refine(e=>e===`0x`||tn(e)===20,`TransferAndCall.recipientData must be "0x" (self-shield to the sender) or a raw 20-byte address, not a 32-byte ABI-encoded value the wrapper would truncate to a garbage address`)),zn=L.object({kind:L.literal(`TransferAndCall`),from:P,underlying:P,wrapper:P,amount:L.bigint(),recipientData:L.optional(Rn)}),Bn=L.object({kind:L.literal(`DelegateDecryption`),from:P,contractAddress:P,delegateAddress:P,expirationDate:L.optional(L.date())}),Vn=L.object({kind:L.literal(`RevokeDelegation`),from:P,contractAddress:P,delegateAddress:P});L.discriminatedUnion(`kind`,[An,jn,Mn,Nn,Pn,Fn,In,Ln,zn,Bn,Vn]);const Hn=L.strictObject({maxFeePerGas:L.bigint(),maxPriorityFeePerGas:L.bigint()}),Un=L.object({nonce:L.optional(L.int().check(L.nonnegative())),gasLimit:L.optional(L.bigint()),fees:L.optional(Hn)}),Wn=L.object({address:P,abi:L.array(L.unknown()),functionName:L.string(),args:L.array(L.unknown()),value:L.optional(L.bigint()),gas:L.optional(L.bigint())}),Gn=L.extend(Un,{from:P,calldata:Wn});var Kn=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(e,t){t&&=F(Un,t);let n=await this.#e.getChainId(),r=this.#t.chain.id;if(n!==r)throw new h(`Offline.prepare: provider is on chain ${n} but the SDK is configured for chain ${r}. The prepared transaction's contract addresses and encrypted inputs are bound to chain ${r} — point the provider at the same chain.`);let i=F(Gn,{calldata:await this.#r(e),from:e.from,nonce:t?.nonce,gasLimit:t?.gasLimit,fees:t?.fees}),a=await this.#e.prepareTransaction(i);return{kind:e.kind,unsignedTx:a,from:i.from}}async#r(e){switch(e.kind){case`ConfidentialTransfer`:return this.#i(e);case`ConfidentialTransferFrom`:return this.#a(e);case`SetOperator`:return this.#o(e);case`Unwrap`:return this.#s(e);case`UnwrapAll`:return this.#c(e);case`FinalizeUnwrap`:return this.#l(e);case`ApproveUnderlying`:return this.#u(e);case`Wrap`:return this.#d(e);case`TransferAndCall`:return this.#f(e);case`DelegateDecryption`:return this.#p(e);case`RevokeDelegation`:return this.#m(e);default:throw new h(`OfflineService.prepare: unsupported transaction kind '${e.kind}'.`)}}async#i(e){e=F(An,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer`}),r=t[0];if(!r)throw new x(`Encryption returned no handles for ConfidentialTransfer`);return ve(e.token,e.to,r,n)}async#a(e){e=F(jn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer-from`}),r=t[0];if(!r)throw new x(`Encryption returned no handles for ConfidentialTransferFrom`);return le(e.token,e.owner,e.to,r,n)}#o(e){return e=F(Mn,e),E(e.token,e.operator,e.until)}async#s(e){e=F(Nn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-unwrap`}),r=t[0];if(!r)throw new x(`Encryption returned no handles for Unwrap`);return ge(e.token,e.from,e.to,r,n)}async#c(e){e=F(Pn,e);let t=await this.#e.readContract(_e(e.token,e.from));return ue(e.token,e.from,e.to,t)}async#l(e){e=F(Fn,e);let t=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount],options:{operation:`offline-finalize-unwrap`}}).catch(e=>{throw q(e,`Public decryption failed during FinalizeUnwrap`)}),n=t.clearValues[0]?.value;return Ue(n,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),he(e.wrapper,e.unwrapRequestIdOrAmount,n,t.checkSignaturesArgs.decryptionProof)}#u(e){return e=F(In,e),O(e.underlying,e.spender,e.amount)}#d(e){return e=F(Ln,e),T(e.wrapper,e.to,e.amount)}#f(e){return e=F(zn,e),rt(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=F(Bn,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new G(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new z(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new U(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):Z;return Y(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=F(Vn,e),X(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function qn(e){if(!(!Object.hasOwn(e,`transportKeyPairDerivationSecret`)||e.transportKeyPairDerivationSecret!==void 0))throw new h(`transportKeyPairDerivationSecret was passed as undefined, which usually means the environment variable it reads is unset (e.g. process.env.ZAMA_DERIVATION_SECRET). Supply the secret, or omit the option entirely to persist transport key pairs in cleartext on purpose.`)}function Jn(e){if(e===void 0)return;let{importScripts:t}=globalThis;if(!(typeof window>`u`&&typeof document>`u`&&typeof t!=`function`))throw new h(`transportKeyPairDerivationSecret is supported in headless environments only (CLI tools, servers, agents). Remove the option: an environment with a platform keystore, or one that ships a bundle, must delegate at-rest security of the transport key pair to the storage backend.`)}function Yn(e){if(e===void 0)return;let t=F(Pt,e);return new Vt(typeof t==`string`?t:new Uint8Array(t))}var Xn=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){qn(t),Jn(t.transportKeyPairDerivationSecret);let n=Yn(t.transportKeyPairDerivationSecret);this.#e=e.router,this.provider=e.provider,this.signer=e.signer,this.storage=e.storage,this.#r=e.onEvent??function(){},this.#i=e.logger,this.#a=new bn(e.storage,this.#i),this.#u=new Dn({provider:this.provider,router:e.router,emitEvent:this.emitEvent.bind(this),logger:this.#i});let r={};for(let t of e.chains)t.registryAddress&&(r[t.id]=t.registryAddress);this.registry=new N({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new zt({router:e.router,signer:e.signer,transportKeyPairTTL:e.transportKeyPairTTL,permitTTL:e.permitTTL,scope:e.transportKeyPairScope,derivationSecret:n,storage:this.storage,permitStorage:e.permitStorage,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),e.signer&&(this.#c=new wn({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new On({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new kn({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,clearCredentialsOnWalletChange:e.clearCredentialsOnWalletChange,logger:this.#i}),this.#d=new Kn({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new fn({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new pn({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new mn({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new hn(this.#d,this.#l)}onWalletAccountChange(e){return this.#o.onWalletAccountChange(e)}get logger(){return this.#i}get relayer(){return this.#e.relayer}emitEvent(e,t){try{this.#r({...e,tokenAddress:t,timestamp:Date.now()})}catch(t){this.#i.warn(`${e.type} event listener silently failed`,{error:t})}}createWrappersRegistry(e){return new N({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,M(t,`encrypt`))}createToken(e){return new tt(this,e)}createWrappedToken(e){return new Ct(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};export{vt as ACL_TOPICS,on as AclPausedError,xt as AclTopics,nt as BalanceCheckUnavailableError,Bt as BaseSigner,Je as ChainMismatchError,gn as ChromeSessionStorage,h as ConfigurationError,mn as Decryption,S as DecryptionFailedError,kt as DefaultRegistryAddresses,an as DelegationContractIsSelfError,rn as DelegationCooldownError,W as DelegationDelegateCannotBeWildcardError,U as DelegationDelegateEqualsContractError,G as DelegationExpirationTooSoonError,V as DelegationExpiredError,H as DelegationExpiryUnchangedError,B as DelegationNotFoundError,K as DelegationNotPropagatedError,z as DelegationSelfNotAllowedError,pn as Delegations,Te as ERC1363_INTERFACE_ID,Ke as ERC20ReadFailedError,Me as ERC7984_INTERFACE_ID,Be as ERC7984_WRAPPER_INTERFACE_ID,oe as EncryptOffloadUnavailableError,x as EncryptionFailedError,Lt as IndexedDBStorage,qe as InsufficientAllowanceError,$e as InsufficientConfidentialBalanceError,Xe as InsufficientERC20BalanceError,_ as InvalidTransportKeyPairError,g as KeyWrappingError,Z as MAX_UINT64,jt as MemoryStorage,It as MutableWalletAccountStore,y as NoCiphertextError,R as NotEntitledError,hn as Offline,fn as Permits,ie as PreparedPermitChainMismatchError,te as PreparedPermitExpiredError,u as RelayerRequestFailedError,v as RevokedKmsContextError,k as RpcRateLimitError,be as SignerNotConfiguredError,de as SignerRequiredError,b as SigningFailedError,re as SigningRejectedError,ht as TOKEN_TOPICS,tt as Token,lt as Topics,xe as TransactionRevertedError,ae as TransportKeyPairChangedError,ne as TransportKeyPairExpiredError,Et as UnlistedConfidentialTokenError,it as UnshieldAlreadyFinalizedError,st as VaultBatcherPausedError,at as VaultGroupJoinUnconfirmedError,Q as WILDCARD_CONTRACT,pe as WalletAccountNotReadyError,Ie as WalletNotConnectedError,Ct as WrappedToken,N as WrappersRegistry,et as ZERO_ENCRYPTED_VALUE,p as ZamaError,c as ZamaErrorCode,Xn as ZamaSDK,C as ZamaSDKEvents,Oe as allowanceContract,$t as anvil,O as approveContract,Se as balanceOfContract,Yt as bscTestnet,Zt as chains,_n as chromeSessionStorage,Ot as cleartext,_e as confidentialBalanceOfContract,ce as confidentialTotalSupplyContract,ve as confidentialTransferContract,le as confidentialTransferFromContract,dn as createConfig,Rt as createWalletAccountStore,Ve as decimalsContract,yt as decodeAclEvent,St as decodeAclEvents,ut as decodeConfidentialTransfer,gt as decodeDelegatedForUserDecryption,wt as decodeOnChainEvent,dt as decodeOnChainEvents,ft as decodeRevokedDelegationForUserDecryption,bt as decodeUnwrapFinalized,_t as decodeUnwrapRequested,mt as decodeWrap,Y as delegateForUserDecryptionContract,he as finalizeUnwrapContract,pt as findDelegatedForUserDecryption,ct as findRevokedDelegationForUserDecryption,Tt as findUnwrapRequested,Dt as findWrap,ze as getConfidentialTokenAddressContract,ln as getDelegationExpiryContract,Pe as getTokenAddressContract,Le as getTokenPairContract,ke as getTokenPairsContract,Ce as getTokenPairsLengthContract,Fe as getTokenPairsSliceContract,qt as hardhat,Gt as hoodi,Ft as indexedDBStorage,je as inferredTotalSupplyContract,Ee as isConfidentialTokenContract,Re as isConfidentialTokenValidContract,De as isConfidentialWrapperContract,Ye as isEncryptedValueZero,un as isHandleDelegatedContract,se as isOperatorContract,n as isRetryable,Xt as mainnet,nn as matchZamaError,Mt as memoryStorage,we as nameContract,At as parsePreparedPermit,Qt as polygon,Kt as polygonAmoy,Ae as rateContract,d as retryAfterSeconds,X as revokeDelegationContract,Jt as sepolia,E as setOperatorContract,Ne as supportsInterfaceContract,He as symbolContract,rt as transferAndCallContract,me as underlyingContract,ge as unwrapContract,ue as unwrapFromBalanceContract,fe as unwrapRequesterContract,T as wrapContract,en as zenithTrexTestnet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as e,r as t,y as n}from"../relayer-ov8b_HOu.js";import{t as r}from"../fatal-batch-CI1pes1q.js";import{n as i}from"../fhevm-relayer-
|
|
1
|
+
import{i as e,r as t,y as n}from"../relayer-ov8b_HOu.js";import{t as r}from"../fatal-batch-CI1pes1q.js";import{n as i}from"../fhevm-relayer-DF4uuzDF.js";import{t as a}from"../typed-data-eAgGr9V-.js";const o=r;function s(r,i,a){let s=o[r],c=s?new s(i):new t(r,i,r===e.RelayerRequestFailed?{retryable:a.retryable}:void 0);return c.retryable&&n(a.retryAfter)?Object.assign(c,{retryAfter:a.retryAfter}):c}function c(e,t){return e.onWalletAccountChange(t)}export{s as reviveZamaError,c as subscribeWalletAccountChanges,i as toFhevmAuth,a as toViemTypedData};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/node/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"../fhevm-relayer-
|
|
1
|
+
import{t as e}from"../fhevm-relayer-DF4uuzDF.js";import{t}from"../telemetry-D9Mf59ts.js";import{t as n}from"../cleartext-RqXnz7I6.js";import{a as r,c as i,i as a,l as o,n as s,o as c,r as l,s as u,t as d,u as f}from"../chains-CF-Hzs9R.js";import{AsyncLocalStorage as p}from"node:async_hooks";function m(n){return{type:`node`,createRelayer:(r,i,a)=>{let o=t(globalThis.process?.env?.ZAMA_SDK_TELEMETRY)??a?.mode;return new e({chain:r,options:n,logger:i,telemetry:a&&o!==void 0&&o!==`off`?{state:a,runtime:`node`,mode:o}:void 0})}}}var h=class{#e=new p;run(e){return this.#e.run(new Map,e)}async get(e){return this.#e.getStore()?.get(e)??null}async set(e,t){this.#e.getStore()?.set(e,t)}async delete(e){this.#e.getStore()?.delete(e)}};const g=new h;export{h as AsyncLocalMapStorage,d as anvil,g as asyncLocalStorage,s as bscTestnet,l as chains,n as cleartext,a as hardhat,r as hoodi,c as mainnet,m as node,u as polygon,i as polygonAmoy,o as sepolia,f as zenithTrexTestnet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e,t){let n=Object.entries({version:`3.8.0-beta.
|
|
2
|
-
//# sourceMappingURL=telemetry-
|
|
1
|
+
function e(e,t){let n=Object.entries({version:`3.8.0-beta.13`,layer:e.state.layer,runtime:e.runtime,...t!==void 0&&{operation:t}}),r=e=>Object.fromEntries(n.map(([t,n])=>[`${e}${t}`,n]));return e.mode===`query`?{query:r(`zama_sdk_`)}:{headers:r(`x-zama-sdk-`)}}function t(e,t){return Object.assign({},e,{operation:e?.operation??t})}function n(e){if(typeof e==`boolean`)return e?`header`:`off`;let t=typeof e==`string`?e.trim().toLowerCase():void 0;return t===`0`||t===`false`?`off`:t===`header`||t===`query`||t===`off`?t:void 0}export{e as n,t as r,n as t};
|
|
2
|
+
//# sourceMappingURL=telemetry-D9Mf59ts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"telemetry-
|
|
1
|
+
{"version":3,"file":"telemetry-D9Mf59ts.js","names":["packageJson.version"],"sources":["../../package.json","../../src/version.ts","../../src/telemetry.ts"],"sourcesContent":["","import packageJson from \"../package.json\" with { type: \"json\" };\n\nexport const SDK_VERSION: string = packageJson.version;\n","import { SDK_VERSION } from \"./version\";\n\n// No telemetry field may carry a wallet address, encrypted value, amount or identifier.\n\nexport type TelemetryLayer = \"core\" | \"react\";\n\nexport type TelemetryRuntime = \"web\" | \"node\";\n\nexport type TelemetryMode = \"header\" | \"query\" | \"off\";\n\n/** Values are frozen once shipped, so that dashboards keyed on them survive method renames. */\nexport type TelemetryOperation =\n | \"balance-of\"\n | \"decrypt-balance-as\"\n | \"batch-balances-of\"\n | \"batch-decrypt-balances-as\"\n | \"confidential-transfer\"\n | \"confidential-transfer-from\"\n | \"confidential-transfer-and-call\"\n | \"confidential-transfer-from-and-call\"\n | \"unshield\"\n | \"unshield-all\"\n | \"resume-unshield\"\n | \"unwrap\"\n | \"finalize-unwrap\"\n | \"vault-deposit\"\n | \"vault-redeem\"\n | \"vault-join\"\n | \"vault-group-deposit\"\n | \"vault-group-redeem\"\n | \"vault-deposit-of\"\n | \"encrypt\"\n | \"decrypt-values\"\n | \"delegated-decrypt-values\"\n | \"delegated-batch-decrypt-values\"\n | \"decrypt-public-values\"\n | \"offline-confidential-transfer\"\n | \"offline-confidential-transfer-from\"\n | \"offline-unwrap\"\n | \"offline-finalize-unwrap\";\n\n/**\n * Shared by every relayer of a config. `layer` flips to `react` once\n * `ZamaProvider` marks the config, after the relayers exist.\n *\n * @internal\n */\nexport interface TelemetryState {\n layer: TelemetryLayer;\n readonly mode: Exclude<TelemetryMode, \"off\">;\n}\n\nexport interface RelayerTelemetry {\n readonly state: TelemetryState;\n readonly runtime: TelemetryRuntime;\n /** The config's `mode`, unless `ZAMA_SDK_TELEMETRY` overrode it on Node. */\n readonly mode: Exclude<TelemetryMode, \"off\">;\n}\n\nexport function telemetryRequestOptions(\n telemetry: RelayerTelemetry,\n operation: TelemetryOperation | undefined,\n): { headers?: Record<string, string>; query?: Record<string, string> } {\n const fields = Object.entries({\n version: SDK_VERSION,\n layer: telemetry.state.layer,\n runtime: telemetry.runtime,\n ...(operation !== undefined && { operation }),\n });\n const prefixed = (prefix: string) =>\n Object.fromEntries(fields.map(([name, value]) => [`${prefix}${name}`, value]));\n return telemetry.mode === \"query\"\n ? { query: prefixed(\"zama_sdk_\") }\n : { headers: prefixed(\"x-zama-sdk-\") };\n}\n\n/** `options` labelled with `operation`, unless the caller already labelled it. */\nexport function withOperation<T extends { readonly operation?: TelemetryOperation }>(\n options: T | undefined,\n operation: TelemetryOperation,\n): Partial<T> & { readonly operation: TelemetryOperation } {\n return Object.assign({}, options, { operation: options?.operation ?? operation });\n}\n\nexport function parseTelemetryMode(value: string | boolean | undefined): TelemetryMode | undefined {\n if (typeof value === \"boolean\") {\n return value ? \"header\" : \"off\";\n }\n // JavaScript callers can pass anything; only a string can name a mode.\n const mode = typeof value === \"string\" ? value.trim().toLowerCase() : undefined;\n // `0` and `false` predate the named modes and still mean off.\n if (mode === \"0\" || mode === \"false\") {\n return \"off\";\n }\n return mode === \"header\" || mode === \"query\" || mode === \"off\" ? mode : undefined;\n}\n"],"mappings":"AE2DA,SAAgB,EACd,EACA,EACsE,CACtE,IAAM,EAAS,OAAO,QAAQ,CAC5B,QAAS,gBACT,MAAO,EAAU,MAAM,MACvB,QAAS,EAAU,QACnB,GAAI,IAAc,IAAA,IAAa,CAAE,WAAU,CAC7C,CAAC,EACK,EAAY,GAChB,OAAO,YAAY,EAAO,KAAK,CAAC,EAAM,KAAW,CAAC,GAAG,IAAS,IAAQ,CAAK,CAAC,CAAC,EAC/E,OAAO,EAAU,OAAS,QACtB,CAAE,MAAO,EAAS,WAAW,CAAE,EAC/B,CAAE,QAAS,EAAS,aAAa,CAAE,CACzC,CAGA,SAAgB,EACd,EACA,EACyD,CACzD,OAAO,OAAO,OAAO,CAAC,EAAG,EAAS,CAAE,UAAW,GAAS,WAAa,CAAU,CAAC,CAClF,CAEA,SAAgB,EAAmB,EAAgE,CACjG,GAAI,OAAO,GAAU,UACnB,OAAO,EAAQ,SAAW,MAG5B,IAAM,EAAO,OAAO,GAAU,SAAW,EAAM,KAAK,CAAC,CAAC,YAAY,EAAI,IAAA,GAKtE,OAHI,IAAS,KAAO,IAAS,QACpB,MAEF,IAAS,UAAY,IAAS,SAAW,IAAS,MAAQ,EAAO,IAAA,EAC1E"}
|
package/dist/esm/vaults/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"../relayer-ov8b_HOu.js";import{r as t,t as n}from"../encryption-ieCO6J5r.js";import{V as r,W as i,Y as a,s as o,w as s,z as c}from"../wrappers-registry-DnYVQ02R.js";import{a as l,i as u,l as d,n as f,o as p,t as ee,u as te}from"../token-DlsiZmg5.js";import{E as ne,S as re,T as ie,b as ae,t as m,w as oe,x as se}from"../wrapped-token-C8eKid8W.js";import{r as h}from"../telemetry-BsoDvF-G.js";import{l as g,p as _}from"../invalidation-CzspPBR7.js";import{encodeAbiParameters as ce,getAbiItem as le,getAddress as v}from"viem";function y(e){let t,n=null;return()=>t===void 0?(n||=e().then(e=>(t=e,n=null,e)).catch(e=>{throw n=null,e}),n):Promise.resolve(t)}const b=[{type:`function`,name:`batchCallbackDeadline`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`batchCreatedAt`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`batchDispatchedAt`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`batchMaxSlippageBps`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint16`,internalType:`uint16`}],stateMutability:`view`},{type:`function`,name:`batchMinBatchAge`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`batchState`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint8`,internalType:`enum BatcherConfidential.BatchState`}],stateMutability:`view`},{type:`function`,name:`callbackDeadline`,inputs:[],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`claim`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bytes32`,internalType:`euint64`}],stateMutability:`nonpayable`},{type:`function`,name:`currentBatchId`,inputs:[],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`deposits`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bytes32`,internalType:`euint64`}],stateMutability:`view`},{type:`function`,name:`dispatchBatch`,inputs:[],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`exchangeRate`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint64`,internalType:`uint64`}],stateMutability:`view`},{type:`function`,name:`exchangeRateDecimals`,inputs:[],outputs:[{name:``,type:`uint8`,internalType:`uint8`}],stateMutability:`pure`},{type:`function`,name:`fromToken`,inputs:[],outputs:[{name:``,type:`address`,internalType:`contract IERC7984ERC20Wrapper`}],stateMutability:`view`},{type:`function`,name:`join`,inputs:[{name:`beneficiary`,type:`address`,internalType:`address`},{name:`encryptedAmount`,type:`bytes32`,internalType:`externalEuint64`},{name:`inputProof`,type:`bytes`,internalType:`bytes`}],outputs:[{name:`joined`,type:`bytes32`,internalType:`euint64`}],stateMutability:`nonpayable`},{type:`function`,name:`maxSlippageBps`,inputs:[],outputs:[{name:``,type:`uint16`,internalType:`uint16`}],stateMutability:`view`},{type:`function`,name:`minBatchAge`,inputs:[],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`paused`,inputs:[],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`quit`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bytes32`,internalType:`euint64`}],stateMutability:`nonpayable`},{type:`function`,name:`recover`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:`refunded`,type:`bytes32`,internalType:`euint64`}],stateMutability:`nonpayable`},{type:`function`,name:`toToken`,inputs:[],outputs:[{name:``,type:`address`,internalType:`contract IERC7984ERC20Wrapper`}],stateMutability:`view`},{type:`function`,name:`totalDeposits`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bytes32`,internalType:`euint64`}],stateMutability:`view`},{type:`function`,name:`unwrapRequestId`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bytes32`,internalType:`bytes32`}],stateMutability:`view`},{type:`function`,name:`vault`,inputs:[],outputs:[{name:``,type:`address`,internalType:`contract IERC4626`}],stateMutability:`view`},{type:`event`,name:`BatchCanceled`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`}],anonymous:!1},{type:`event`,name:`BatchDispatched`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`}],anonymous:!1},{type:`event`,name:`BatchFinalized`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`},{name:`exchangeRate`,type:`uint64`,indexed:!1,internalType:`uint64`}],anonymous:!1},{type:`event`,name:`Claimed`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`},{name:`account`,type:`address`,indexed:!0,internalType:`address`},{name:`amount`,type:`bytes32`,indexed:!1,internalType:`euint64`}],anonymous:!1},{type:`event`,name:`Joined`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`},{name:`account`,type:`address`,indexed:!0,internalType:`address`},{name:`amount`,type:`bytes32`,indexed:!1,internalType:`euint64`}],anonymous:!1},{type:`event`,name:`Quit`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`},{name:`account`,type:`address`,indexed:!0,internalType:`address`},{name:`amount`,type:`bytes32`,indexed:!1,internalType:`euint64`}],anonymous:!1},{type:`error`,name:`BatchNonexistent`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}]},{type:`error`,name:`BatchTooYoung`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`elapsed`,type:`uint256`,internalType:`uint256`},{name:`required`,type:`uint256`,internalType:`uint256`}]},{type:`error`,name:`BatchUnexpectedState`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`current`,type:`uint8`,internalType:`enum BatcherConfidential.BatchState`},{name:`expectedStates`,type:`bytes32`,internalType:`bytes32`}]},{type:`error`,name:`DuplicateUnderlyingTokens`,inputs:[]},{type:`error`,name:`EnforcedPause`,inputs:[]},{type:`error`,name:`ExpectedPause`,inputs:[]},{type:`error`,name:`IntermediateStepToTokenBalanceChanged`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}]},{type:`error`,name:`InvalidBeneficiary`,inputs:[]},{type:`error`,name:`InvalidCallbackDeadline`,inputs:[]},{type:`error`,name:`InvalidExchangeRate`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`totalDeposits`,type:`uint256`,internalType:`uint256`},{name:`exchangeRate`,type:`uint64`,internalType:`uint64`}]},{type:`error`,name:`InvalidKMSSignatures`,inputs:[]},{type:`error`,name:`InvalidMaxSlippageBps`,inputs:[]},{type:`error`,name:`InvalidMinBatchAge`,inputs:[]},{type:`error`,name:`InvalidTokenRate`,inputs:[]},{type:`error`,name:`InvalidWrapperToken`,inputs:[{name:`token`,type:`address`,internalType:`address`}]},{type:`error`,name:`OwnableInvalidOwner`,inputs:[{name:`owner`,type:`address`,internalType:`address`}]},{type:`error`,name:`OwnableUnauthorizedAccount`,inputs:[{name:`account`,type:`address`,internalType:`address`}]},{type:`error`,name:`ReentrancyGuardReentrantCall`,inputs:[]},{type:`error`,name:`RouteAssetMismatch`,inputs:[{name:`actualAsset`,type:`address`,internalType:`address`},{name:`expectedAsset`,type:`address`,internalType:`address`}]},{type:`error`,name:`RouteShareMismatch`,inputs:[{name:`actualShare`,type:`address`,internalType:`address`},{name:`expectedShare`,type:`address`,internalType:`address`}]},{type:`error`,name:`SafeCastOverflowedUintDowncast`,inputs:[{name:`bits`,type:`uint8`,internalType:`uint8`},{name:`value`,type:`uint256`,internalType:`uint256`}]},{type:`error`,name:`SafeERC20FailedOperation`,inputs:[{name:`token`,type:`address`,internalType:`address`}]},{type:`error`,name:`SenderNotAllowedToUseHandle`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`sender`,type:`address`,internalType:`address`}]},{type:`error`,name:`SlippageExceeded`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`actual`,type:`uint256`,internalType:`uint256`},{name:`minimum`,type:`uint256`,internalType:`uint256`}]},{type:`error`,name:`Unauthorized`,inputs:[]},{type:`error`,name:`ZamaProtocolUnsupported`,inputs:[]},{type:`error`,name:`ZeroDeposits`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`account`,type:`address`,internalType:`address`}]}];function x(e,t,n,r){return{address:e,abi:b,functionName:`join`,args:[t,n,r]}}function S(e,t,n){return{address:e,abi:b,functionName:`claim`,args:[t,n]}}function C(e,t){return{address:e,abi:b,functionName:`quit`,args:[t]}}function w(e,t,n){return{address:e,abi:b,functionName:`recover`,args:[t,n]}}function T(e){return{address:e,abi:b,functionName:`dispatchBatch`,args:[]}}function E(e){return{address:e,abi:b,functionName:`currentBatchId`,args:[]}}function D(e,t){return{address:e,abi:b,functionName:`batchState`,args:[t]}}function O(e,t){return{address:e,abi:b,functionName:`totalDeposits`,args:[t]}}function k(e,t,n){return{address:e,abi:b,functionName:`deposits`,args:[t,n]}}function A(e){return{address:e,abi:b,functionName:`vault`,args:[]}}function j(e){return{address:e,abi:b,functionName:`fromToken`,args:[]}}function M(e){return{address:e,abi:b,functionName:`toToken`,args:[]}}function N(e){return{address:e,abi:b,functionName:`minBatchAge`,args:[]}}function P(e,t){return{address:e,abi:b,functionName:`batchMinBatchAge`,args:[t]}}function F(e){return{address:e,abi:b,functionName:`callbackDeadline`,args:[]}}function I(e,t){return{address:e,abi:b,functionName:`batchCallbackDeadline`,args:[t]}}function L(e,t){return{address:e,abi:b,functionName:`batchCreatedAt`,args:[t]}}function R(e,t){return{address:e,abi:b,functionName:`batchDispatchedAt`,args:[t]}}function z(e,t){return{address:e,abi:b,functionName:`exchangeRate`,args:[t]}}function B(e){return{address:e,abi:b,functionName:`exchangeRateDecimals`,args:[]}}function V(e){return{address:e,abi:b,functionName:`paused`,args:[]}}const H=[{type:`function`,name:`join`,inputs:[{name:`legs`,type:`tuple[]`,internalType:`struct IVaultBatcherConfidentialRouter.Allocation[]`,components:[{name:`batcher`,type:`address`,internalType:`address`},{name:`token`,type:`address`,internalType:`address`},{name:`amount`,type:`bytes32`,internalType:`externalEuint64`}]},{name:`inputProof`,type:`bytes`,internalType:`bytes`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`tokenWrapperRegistry`,inputs:[],outputs:[{name:``,type:`address`,internalType:`contract ITokenWrapperRegistry`}],stateMutability:`view`},{type:`error`,name:`InvalidTokenWrapperRegistry`,inputs:[]},{type:`error`,name:`MissingInputProof`,inputs:[]},{type:`error`,name:`ReentrancyGuardReentrantCall`,inputs:[]},{type:`error`,name:`ZamaProtocolUnsupported`,inputs:[]},{type:`error`,name:`UnlistedConfidentialToken`,inputs:[{name:`token`,type:`address`,internalType:`address`}]}];function ue(e,t,n){return{address:e,abi:H,functionName:`join`,args:[t,n]}}const de=le({abi:H,name:`join`}).inputs;function fe(e,t){return ce(de,[e.map(e=>({...e})),t])}function pe(e){return{address:e,abi:H,functionName:`tokenWrapperRegistry`,args:[]}}const U={Joined:ae(`Joined(uint256,address,bytes32)`)};function W(e){let[t,n,r]=e.topics;return t!==U.Joined||n===void 0||r===void 0?null:{batchId:BigInt(n),account:se(r),confidentialAmount:re(e.data,0)}}function me(e,t,n){if(e.address!==void 0&&v(e.address)!==t)return null;let r=W(e);return!r||n!==void 0&&r.account!==n?null:r}function G(e,t,n){return K([...e],t,n)}function K(e,t,n){let r=n?v(n):void 0;for(let[n,i]of e.entries()){let a=me(i,t,r);if(a)return e.splice(n,1),a}return null}const q={Pending:0,Dispatched:1,Finalized:2,Canceled:3};var J=class{sdk;address;#e;#t;#n;#r=null;constructor(e,t){this.sdk=e,this.address=v(t),this.#e=y(()=>e.provider.readContract(A(this.address))),this.#t=y(()=>e.provider.readContract(j(this.address))),this.#n=y(()=>e.provider.readContract(M(this.address)))}async vault(){return this.#e()}async fromToken(){return this.#t()}async toToken(){return this.#n()}async currentBatchId(){return this.sdk.provider.readContract(E(this.address))}async batchState(e){return await this.sdk.provider.readContract(D(this.address,e))}async paused(){return this.sdk.provider.readContract(V(this.address))}async minBatchAge(){return this.sdk.provider.readContract(N(this.address))}async batchMinBatchAge(e){return this.sdk.provider.readContract(P(this.address,e))}async callbackDeadline(){return this.sdk.provider.readContract(F(this.address))}async batchCallbackDeadline(e){return this.sdk.provider.readContract(I(this.address,e))}async batchCreatedAt(e){return this.sdk.provider.readContract(L(this.address,e))}async batchDispatchedAt(e){return this.sdk.provider.readContract(R(this.address,e))}async exchangeRate(e){return this.sdk.provider.readContract(z(this.address,e))}async exchangeRateDecimals(){return this.sdk.provider.readContract(B(this.address))}async timeUntilDispatchable(e){let[t,n,r,i]=await Promise.all([this.batchState(e),this.batchCreatedAt(e),this.batchMinBatchAge(e),this.sdk.provider.getBlockTimestamp()]);if(t!==q.Pending)return null;let a=n+r;return a>i?a-i:0n}async confidentialTotalDeposits(e){return this.sdk.provider.readContract(O(this.address,e))}async confidentialDepositOf(e,t){return this.sdk.provider.readContract(k(this.address,e,v(t)))}async depositOf(e,t){let r=v(t),i=await this.confidentialDepositOf(e,r);if(d(i))return 0n;let a=(await this.sdk.decryption.decryptValues([{encryptedValue:i,contractAddress:this.address}],{operation:`vault-deposit-of`}))[i];if(a===void 0)throw new n(`Decryption returned no value for ${i}`);return c(a,`depositOf: result[encryptedValue]`),a}async join(e,n,r){let{operation:i}=h(r,`vault-join`);this.#i(`join`);let o=v((await l(`join`,this.sdk.signer,this.sdk.provider)).address),s=n?v(n):o;r?.skipBalanceCheck||await this.#o(e,i);let{encryptedValues:c,inputProof:u}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:o},{operation:i}),d=c[0];if(!d)throw new t(`Encryption returned no encrypted values`);let f=await this.#c(`vault:join`,x(this.address,s,d,u)),p=G(f.receipt.logs,this.address,s);if(!p)throw new a(`No Joined event for ${s} from batcher ${this.address} found in the join receipt`);return{...f,batchId:p.batchId,beneficiary:p.account,confidentialJoinedAmount:p.confidentialAmount}}async quit(e){return this.#i(`quit`),await p(`quit`,this.sdk.signer,this.sdk.provider),this.#c(`vault:quit`,C(this.address,e))}async recover(e,t){let n=await this.#s(`recover`,t);return this.#c(`vault:recover`,w(this.address,e,n))}async claim(e,t){let n=await this.#s(`claim`,t);return this.#c(`vault:claim`,S(this.address,e,n))}async dispatchBatch(){return this.#i(`dispatchBatch`),await p(`dispatchBatch`,this.sdk.signer,this.sdk.provider),this.#c(`vault:dispatchBatch`,T(this.address))}#i(e){if(!this.sdk.signer)throw new i(e);return this.sdk.signer}async#a(){return this.#r??=this.fromToken().then(e=>new ee(this.sdk,e)).catch(e=>{throw this.#r=null,e}),this.#r}async#o(e,t){let n=await this.#a();return u({operation:`join`,tokenAddress:n.address,amount:e,signer:this.sdk.signer,provider:this.sdk.provider,readBalance:e=>n.decryptBalance(e,t)})}async#s(e,t){return this.#i(e),t?(await p(e,this.sdk.signer,this.sdk.provider),v(t)):v((await l(e,this.sdk.signer,this.sdk.provider)).address)}async#c(e,t){return f({operation:e,signer:this.#i(e),provider:this.sdk.provider,config:t,emit:e=>this.sdk.emitEvent(e,this.address),logger:this.sdk.logger})}};function he(e,t){return new J(e,t)}var Y=class{sdk;depositBatcher;redeemBatcher;#e=null;#t=null;#n=null;#r;constructor(e,t){this.sdk=e,this.#r=t.vault?v(t.vault):void 0,this.depositBatcher=new J(e,t.depositBatcher),this.redeemBatcher=new J(e,t.redeemBatcher)}async vaultAddress(){return this.#e??=this.#i().catch(e=>{throw this.#e=null,e}),this.#e}async cAsset(){return this.#t??=this.depositBatcher.fromToken().then(e=>new m(this.sdk,e)).catch(e=>{throw this.#t=null,e}),this.#t}async cShare(){return this.#n??=this.redeemBatcher.fromToken().then(e=>new m(this.sdk,e)).catch(e=>{throw this.#n=null,e}),this.#n}async deposit(e,t){let[,n]=await Promise.all([this.vaultAddress(),this.cAsset()]);return await this.#a(`deposit`,n,this.depositBatcher.address,t?.operatorUntil),this.depositBatcher.join(e,t?.beneficiary,{skipBalanceCheck:t?.skipBalanceCheck,operation:`vault-deposit`})}async redeem(e,t){let[,n]=await Promise.all([this.vaultAddress(),this.cShare()]);return await this.#a(`redeem`,n,this.redeemBatcher.address,t?.operatorUntil),this.redeemBatcher.join(e,t?.beneficiary,{skipBalanceCheck:t?.skipBalanceCheck,operation:`vault-redeem`})}async#i(){let[t,n]=await Promise.all([this.depositBatcher.vault(),this.redeemBatcher.vault()]);if(v(t)!==v(n))throw new e(`Vault batchers point at different ERC-4626 vaults: deposit batcher ${this.depositBatcher.address} reports ${t}, redeem batcher ${this.redeemBatcher.address} reports ${n}`);let r=v(t);if(this.#r!==void 0&&this.#r!==r)throw new e(`Configured vault address ${this.#r} does not match the ${r} both batchers report`);return r}async#a(e,t,n,r){if(!this.sdk.signer)throw new i(e);let a=this.sdk.signer.requireWalletAccount(e);await t.isOperator(a.address,n)||await t.setOperator(n,r)}};function ge(e,t){return new Y(e,t)}const _e=10,ve={deposit:{batcher:e=>e.depositBatcher,token:e=>e.cAsset(),asset:e=>e.depositBatcher.fromToken()},redeem:{batcher:e=>e.redeemBatcher,token:e=>e.cShare(),asset:e=>e.redeemBatcher.toToken()}};function ye(e){return[...new Map(e.map(e=>[e.token.address,e.token])).values()]}function X(e){let t=new Set;for(let n of e){if(t.has(n))return n;t.add(n)}}var Z=class{sdk;id;cAsset;router;members;#e;constructor(t,n){if(n.vaults.length<2)throw new e(`Vault group "${n.id}" names ${n.vaults.length} vault(s); a group needs at least two, and a single vault is a Vault`);if(n.vaults.length>10)throw new e(`Vault group "${n.id}" names ${n.vaults.length} vaults, above the 10 a submission can carry`);let r=n.vaults.map(e=>({id:e.id,vault:new Y(t,e)})),i=X(r.map(e=>e.id));if(i!==void 0)throw new e(`Vault group "${n.id}" names "${i}" twice`);let a=X(n.vaults.flatMap(e=>e.vault?[v(e.vault)]:[]));if(a!==void 0)throw new e(`Vault group "${n.id}" gives ${a} as the vault of more than one member`);let o=X(r.flatMap(({vault:e})=>[e.depositBatcher.address,e.redeemBatcher.address]));if(o!==void 0)throw new e(`Vault group "${n.id}" names batcher ${o} more than once`);this.sdk=t,this.id=n.id,this.cAsset=v(n.cAsset),this.router=v(n.router),this.members=r,this.#e=y(async()=>v(await t.provider.readContract(pe(this.router))))}async isAssetListed(){return this.sdk.provider.readContract(o(await this.#e(),this.cAsset))}member(t){let n=this.members.find(e=>e.id===t);if(!n)throw new e(`Vault group "${this.id}" has no vault "${t}"`);return n}async deposit(e,n,r){let{operation:i}=h(r,`vault-group-deposit`),{member:a,signer:o,holder:c}=await this.#t(`deposit`,e),[l]=await Promise.all([this.#n(`deposit`,a,n),this.#o()]);await this.#i(`deposit`,a,n,l,o,r);let[u,d]=await Promise.all([this.sdk.encrypt({values:[{value:n,type:`euint64`}],contractAddress:this.cAsset,userAddress:c},{operation:i}),this.#a(c,l,i)]),[f]=u.encryptedValues;if(!f)throw new t(`Encryption returned no encrypted values`);let p=await this.#s(o,s(this.cAsset,this.router,f,u.inputProof,fe(d.legs,d.inputProof)));return this.#c(e,c,l,p)}async redeem(e,t,n){let{operation:r}=h(n,`vault-group-redeem`),{member:i,signer:a,holder:o}=await this.#t(`redeem`,e),[s]=await Promise.all([this.#n(`redeem`,i,t),this.#e()]);await this.#i(`redeem`,i,t,s,a,n);let c=await this.#a(o,s,r),l=await Promise.all(ye(s).map(async e=>({token:e,granted:await e.isOperator(o,this.router)})));for(let{token:e}of l.filter(e=>!e.granted))await e.setOperator(this.router,n?.operatorUntil);let u=await this.#s(a,ue(this.router,c.legs,c.inputProof));return this.#c(e,o,s,u)}async#t(e,t){let n=this.member(t),r=this.sdk.signer;if(!r)throw new i(e);return{member:n,signer:r,holder:v((await l(e,r,this.sdk.provider)).address)}}async#n(t,n,r){let i=await Promise.all(this.members.map(e=>this.#r(t,e,e===n?r:0n))),a=X(i.map(e=>e.vault));if(a!==void 0)throw new e(`Vault group "${this.id}" has two members whose batchers report the same vault ${a}`);return i}async#r(t,n,r){let i=ve[t],a=i.batcher(n.vault),[o,s,c,l]=await Promise.all([n.vault.vaultAddress(),i.token(n.vault),i.asset(n.vault),a.paused()]);if(v(c)!==this.cAsset)throw new e(`Batcher ${a.address} of vault "${n.id}" is paired with ${c}, but group "${this.id}" is configured with ${this.cAsset}`);if(l)throw new ie(`Batcher ${a.address} of vault "${n.id}" in group "${this.id}" is paused, so no member can be joined until it resumes`,{batcher:a.address,vaultId:n.id});return{member:n,batcher:a,token:s,vault:o,amount:r}}async#i(e,t,n,r,i,a){if(a?.skipBalanceCheck)return;let o=await ve[e].token(t.vault),s=ye(r);await u({operation:e,tokenAddress:o.address,amount:n,signer:i,provider:this.sdk.provider,readBalance:async e=>{let{results:t,errors:n}=await ee.batchBalancesOf(s,e),r=t.get(o.address);if(r===void 0)throw n.get(o.address)??new te(`Balance validation failed (token: ${o.address})`);return r}})}async#a(e,n,r){let{encryptedValues:i,inputProof:a}=await this.sdk.encrypt({values:n.map(e=>({value:e.amount,type:`euint64`})),contractAddress:this.router,userAddress:e},{operation:r});if(i.length!==n.length)throw new t(`Encryption returned ${i.length} values for ${n.length} legs`);return{legs:n.map((e,t)=>({batcher:e.batcher.address,token:e.token.address,amount:i[t]})),inputProof:a}}async#o(){if(!await this.isAssetListed())throw new oe(`The vault router's registry does not list ${this.cAsset}, so it would reject a transfer of it`,{token:this.cAsset,registry:await this.#e()})}#s(e,t){return f({operation:`vault:routerJoin`,signer:e,provider:this.sdk.provider,config:t,emit:e=>this.sdk.emitEvent(e,this.router),logger:this.sdk.logger})}#c(e,t,n,r){let i=[...r.receipt.logs],a=[],o=[];for(let e of n){let n=K(i,e.batcher.address,t);if(!n){o.push(e.member.id);continue}a.push({vaultId:e.member.id,batcher:e.batcher.address,token:e.token.address,batchId:n.batchId,confidentialJoinedAmount:n.confidentialAmount})}if(o.length>0)throw new ne(`Transaction ${r.txHash} was mined, but its receipt has no Joined event for ${t} from the batcher of vault(s) ${o.map(e=>`"${e}"`).join(`, `)} in group "${this.id}"`,{txHash:r.txHash,receipt:r.receipt,joins:a,unconfirmed:o});return{...r,vaultId:e,joins:a}}};function be(e,t){return new Z(e,t)}const Q={currentBatchId:{batcher:e=>[`zama.vault.currentBatchId`,{batcherAddress:v(e)}]},batchState:{batcher:e=>[`zama.vault.batchState`,{batcherAddress:v(e)}],batch:(e,t)=>[`zama.vault.batchState`,{batcherAddress:v(e),batchId:t}]},timeUntilDispatchable:{batcher:e=>[`zama.vault.timeUntilDispatchable`,{batcherAddress:v(e)}],batch:(e,t)=>[`zama.vault.timeUntilDispatchable`,{batcherAddress:v(e),batchId:t}]}};function $(e,t){e.invalidateQueries({queryKey:Q.currentBatchId.batcher(t)}),e.invalidateQueries({queryKey:Q.batchState.batcher(t)}),e.invalidateQueries({queryKey:Q.timeUntilDispatchable.batcher(t)})}function xe(e,t){g(e,t.fromToken),$(e,t.batcherAddress)}function Se(e,t){g(e,t.fromToken),$(e,t.batcherAddress)}function Ce(e,t){g(e,t.toToken)}function we(e,t){$(e,t)}function Te(e){return{mutationKey:[`zama.vaultGroup.deposit`,{cAsset:e.cAsset,batchers:e.members.map(({vault:e})=>e.depositBatcher.address)}],mutationFn:async({vaultId:t,amount:n,...r})=>e.deposit(t,n,r)}}function Ee(e){return{mutationKey:[`zama.vaultGroup.redeem`,{cAsset:e.cAsset,batchers:e.members.map(({vault:e})=>e.redeemBatcher.address)}],mutationFn:async({vaultId:t,amount:n,...r})=>e.redeem(t,n,r)}}function De(e,t={}){let n=t.query??{};return{..._(n),queryKey:Q.currentBatchId.batcher(e.address),queryFn:async()=>e.currentBatchId(),enabled:n.enabled!==!1}}function Oe(e,t={}){let n=t.query??{};return{..._(n),queryKey:Q.batchState.batch(e.address,t.batchId),queryFn:async t=>{let[,{batchId:n}]=t.queryKey;return r(n,`batchStateQueryOptions: batchId`),e.batchState(n)},enabled:t.batchId!==void 0&&n.enabled!==!1}}function ke(e,t={}){let n=t.query??{};return{..._(n),queryKey:Q.timeUntilDispatchable.batch(e.address,t.batchId),queryFn:async t=>{let[,{batchId:n}]=t.queryKey;return r(n,`timeUntilDispatchableQueryOptions: batchId`),e.timeUntilDispatchable(n)},enabled:t.batchId!==void 0&&n.enabled!==!1}}function Ae(e){return{mutationKey:[`zama.vault.deposit`,e.depositBatcher.address],mutationFn:async({amount:t,...n})=>e.deposit(t,n)}}function je(e){return{mutationKey:[`zama.vault.redeem`,e.redeemBatcher.address],mutationFn:async({amount:t,...n})=>e.redeem(t,n)}}function Me(e){return{mutationKey:[`zama.vault.join`,e.address],mutationFn:async({amount:t,beneficiary:n,...r})=>e.join(t,n,r)}}function Ne(e){return{mutationKey:[`zama.vault.claim`,e.address],mutationFn:async({batchId:t,account:n})=>e.claim(t,n)}}function Pe(e){return{mutationKey:[`zama.vault.quit`,e.address],mutationFn:async({batchId:t})=>e.quit(t)}}function Fe(e){return{mutationKey:[`zama.vault.recover`,e.address],mutationFn:async({batchId:t,account:n})=>e.recover(t,n)}}function Ie(e){return{mutationKey:[`zama.vault.dispatchBatch`,e.address],mutationFn:async()=>e.dispatchBatch()}}export{q as BatchState,_e as MAX_GROUP_VAULTS,Y as Vault,J as VaultBatcher,Z as VaultGroup,U as VaultTopics,I as batchCallbackDeadlineContract,L as batchCreatedAtContract,R as batchDispatchedAtContract,P as batchMinBatchAgeContract,D as batchStateContract,Oe as batchStateQueryOptions,F as callbackDeadlineContract,S as claimContract,Ne as claimMutationOptions,ge as createVault,he as createVaultBatcher,be as createVaultGroup,E as currentBatchIdContract,De as currentBatchIdQueryOptions,W as decodeJoined,Ae as depositMutationOptions,k as depositsContract,T as dispatchBatchContract,Ie as dispatchBatchMutationOptions,z as exchangeRateContract,B as exchangeRateDecimalsContract,G as findJoined,j as fromTokenContract,Te as groupDepositMutationOptions,Ee as groupRedeemMutationOptions,Ce as invalidateAfterClaim,we as invalidateAfterDispatchBatch,xe as invalidateAfterJoin,Se as invalidateAfterQuit,$ as invalidateBatchQueries,x as joinContract,Me as joinMutationOptions,N as minBatchAgeContract,V as pausedContract,C as quitContract,Pe as quitMutationOptions,w as recoverContract,Fe as recoverMutationOptions,je as redeemMutationOptions,ke as timeUntilDispatchableQueryOptions,M as toTokenContract,O as totalDepositsContract,A as vaultContract,Q as vaultQueryKeys};
|
|
1
|
+
import{t as e}from"../relayer-ov8b_HOu.js";import{r as t,t as n}from"../encryption-ieCO6J5r.js";import{V as r,W as i,Y as a,s as o,w as s,z as c}from"../wrappers-registry-DnYVQ02R.js";import{a as l,i as u,l as d,n as f,o as p,t as ee,u as te}from"../token-DlsiZmg5.js";import{E as ne,S as re,T as ie,b as ae,t as m,w as oe,x as se}from"../wrapped-token-C8eKid8W.js";import{r as h}from"../telemetry-D9Mf59ts.js";import{l as g,p as _}from"../invalidation-CzspPBR7.js";import{encodeAbiParameters as ce,getAbiItem as le,getAddress as v}from"viem";function y(e){let t,n=null;return()=>t===void 0?(n||=e().then(e=>(t=e,n=null,e)).catch(e=>{throw n=null,e}),n):Promise.resolve(t)}const b=[{type:`function`,name:`batchCallbackDeadline`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`batchCreatedAt`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`batchDispatchedAt`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`batchMaxSlippageBps`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint16`,internalType:`uint16`}],stateMutability:`view`},{type:`function`,name:`batchMinBatchAge`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`batchState`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint8`,internalType:`enum BatcherConfidential.BatchState`}],stateMutability:`view`},{type:`function`,name:`callbackDeadline`,inputs:[],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`claim`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bytes32`,internalType:`euint64`}],stateMutability:`nonpayable`},{type:`function`,name:`currentBatchId`,inputs:[],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`deposits`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bytes32`,internalType:`euint64`}],stateMutability:`view`},{type:`function`,name:`dispatchBatch`,inputs:[],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`exchangeRate`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`uint64`,internalType:`uint64`}],stateMutability:`view`},{type:`function`,name:`exchangeRateDecimals`,inputs:[],outputs:[{name:``,type:`uint8`,internalType:`uint8`}],stateMutability:`pure`},{type:`function`,name:`fromToken`,inputs:[],outputs:[{name:``,type:`address`,internalType:`contract IERC7984ERC20Wrapper`}],stateMutability:`view`},{type:`function`,name:`join`,inputs:[{name:`beneficiary`,type:`address`,internalType:`address`},{name:`encryptedAmount`,type:`bytes32`,internalType:`externalEuint64`},{name:`inputProof`,type:`bytes`,internalType:`bytes`}],outputs:[{name:`joined`,type:`bytes32`,internalType:`euint64`}],stateMutability:`nonpayable`},{type:`function`,name:`maxSlippageBps`,inputs:[],outputs:[{name:``,type:`uint16`,internalType:`uint16`}],stateMutability:`view`},{type:`function`,name:`minBatchAge`,inputs:[],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`paused`,inputs:[],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`quit`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bytes32`,internalType:`euint64`}],stateMutability:`nonpayable`},{type:`function`,name:`recover`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:`refunded`,type:`bytes32`,internalType:`euint64`}],stateMutability:`nonpayable`},{type:`function`,name:`toToken`,inputs:[],outputs:[{name:``,type:`address`,internalType:`contract IERC7984ERC20Wrapper`}],stateMutability:`view`},{type:`function`,name:`totalDeposits`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bytes32`,internalType:`euint64`}],stateMutability:`view`},{type:`function`,name:`unwrapRequestId`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bytes32`,internalType:`bytes32`}],stateMutability:`view`},{type:`function`,name:`vault`,inputs:[],outputs:[{name:``,type:`address`,internalType:`contract IERC4626`}],stateMutability:`view`},{type:`event`,name:`BatchCanceled`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`}],anonymous:!1},{type:`event`,name:`BatchDispatched`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`}],anonymous:!1},{type:`event`,name:`BatchFinalized`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`},{name:`exchangeRate`,type:`uint64`,indexed:!1,internalType:`uint64`}],anonymous:!1},{type:`event`,name:`Claimed`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`},{name:`account`,type:`address`,indexed:!0,internalType:`address`},{name:`amount`,type:`bytes32`,indexed:!1,internalType:`euint64`}],anonymous:!1},{type:`event`,name:`Joined`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`},{name:`account`,type:`address`,indexed:!0,internalType:`address`},{name:`amount`,type:`bytes32`,indexed:!1,internalType:`euint64`}],anonymous:!1},{type:`event`,name:`Quit`,inputs:[{name:`batchId`,type:`uint256`,indexed:!0,internalType:`uint256`},{name:`account`,type:`address`,indexed:!0,internalType:`address`},{name:`amount`,type:`bytes32`,indexed:!1,internalType:`euint64`}],anonymous:!1},{type:`error`,name:`BatchNonexistent`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}]},{type:`error`,name:`BatchTooYoung`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`elapsed`,type:`uint256`,internalType:`uint256`},{name:`required`,type:`uint256`,internalType:`uint256`}]},{type:`error`,name:`BatchUnexpectedState`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`current`,type:`uint8`,internalType:`enum BatcherConfidential.BatchState`},{name:`expectedStates`,type:`bytes32`,internalType:`bytes32`}]},{type:`error`,name:`DuplicateUnderlyingTokens`,inputs:[]},{type:`error`,name:`EnforcedPause`,inputs:[]},{type:`error`,name:`ExpectedPause`,inputs:[]},{type:`error`,name:`IntermediateStepToTokenBalanceChanged`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`}]},{type:`error`,name:`InvalidBeneficiary`,inputs:[]},{type:`error`,name:`InvalidCallbackDeadline`,inputs:[]},{type:`error`,name:`InvalidExchangeRate`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`totalDeposits`,type:`uint256`,internalType:`uint256`},{name:`exchangeRate`,type:`uint64`,internalType:`uint64`}]},{type:`error`,name:`InvalidKMSSignatures`,inputs:[]},{type:`error`,name:`InvalidMaxSlippageBps`,inputs:[]},{type:`error`,name:`InvalidMinBatchAge`,inputs:[]},{type:`error`,name:`InvalidTokenRate`,inputs:[]},{type:`error`,name:`InvalidWrapperToken`,inputs:[{name:`token`,type:`address`,internalType:`address`}]},{type:`error`,name:`OwnableInvalidOwner`,inputs:[{name:`owner`,type:`address`,internalType:`address`}]},{type:`error`,name:`OwnableUnauthorizedAccount`,inputs:[{name:`account`,type:`address`,internalType:`address`}]},{type:`error`,name:`ReentrancyGuardReentrantCall`,inputs:[]},{type:`error`,name:`RouteAssetMismatch`,inputs:[{name:`actualAsset`,type:`address`,internalType:`address`},{name:`expectedAsset`,type:`address`,internalType:`address`}]},{type:`error`,name:`RouteShareMismatch`,inputs:[{name:`actualShare`,type:`address`,internalType:`address`},{name:`expectedShare`,type:`address`,internalType:`address`}]},{type:`error`,name:`SafeCastOverflowedUintDowncast`,inputs:[{name:`bits`,type:`uint8`,internalType:`uint8`},{name:`value`,type:`uint256`,internalType:`uint256`}]},{type:`error`,name:`SafeERC20FailedOperation`,inputs:[{name:`token`,type:`address`,internalType:`address`}]},{type:`error`,name:`SenderNotAllowedToUseHandle`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`sender`,type:`address`,internalType:`address`}]},{type:`error`,name:`SlippageExceeded`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`actual`,type:`uint256`,internalType:`uint256`},{name:`minimum`,type:`uint256`,internalType:`uint256`}]},{type:`error`,name:`Unauthorized`,inputs:[]},{type:`error`,name:`ZamaProtocolUnsupported`,inputs:[]},{type:`error`,name:`ZeroDeposits`,inputs:[{name:`batchId`,type:`uint256`,internalType:`uint256`},{name:`account`,type:`address`,internalType:`address`}]}];function x(e,t,n,r){return{address:e,abi:b,functionName:`join`,args:[t,n,r]}}function S(e,t,n){return{address:e,abi:b,functionName:`claim`,args:[t,n]}}function C(e,t){return{address:e,abi:b,functionName:`quit`,args:[t]}}function w(e,t,n){return{address:e,abi:b,functionName:`recover`,args:[t,n]}}function T(e){return{address:e,abi:b,functionName:`dispatchBatch`,args:[]}}function E(e){return{address:e,abi:b,functionName:`currentBatchId`,args:[]}}function D(e,t){return{address:e,abi:b,functionName:`batchState`,args:[t]}}function O(e,t){return{address:e,abi:b,functionName:`totalDeposits`,args:[t]}}function k(e,t,n){return{address:e,abi:b,functionName:`deposits`,args:[t,n]}}function A(e){return{address:e,abi:b,functionName:`vault`,args:[]}}function j(e){return{address:e,abi:b,functionName:`fromToken`,args:[]}}function M(e){return{address:e,abi:b,functionName:`toToken`,args:[]}}function N(e){return{address:e,abi:b,functionName:`minBatchAge`,args:[]}}function P(e,t){return{address:e,abi:b,functionName:`batchMinBatchAge`,args:[t]}}function F(e){return{address:e,abi:b,functionName:`callbackDeadline`,args:[]}}function I(e,t){return{address:e,abi:b,functionName:`batchCallbackDeadline`,args:[t]}}function L(e,t){return{address:e,abi:b,functionName:`batchCreatedAt`,args:[t]}}function R(e,t){return{address:e,abi:b,functionName:`batchDispatchedAt`,args:[t]}}function z(e,t){return{address:e,abi:b,functionName:`exchangeRate`,args:[t]}}function B(e){return{address:e,abi:b,functionName:`exchangeRateDecimals`,args:[]}}function V(e){return{address:e,abi:b,functionName:`paused`,args:[]}}const H=[{type:`function`,name:`join`,inputs:[{name:`legs`,type:`tuple[]`,internalType:`struct IVaultBatcherConfidentialRouter.Allocation[]`,components:[{name:`batcher`,type:`address`,internalType:`address`},{name:`token`,type:`address`,internalType:`address`},{name:`amount`,type:`bytes32`,internalType:`externalEuint64`}]},{name:`inputProof`,type:`bytes`,internalType:`bytes`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`tokenWrapperRegistry`,inputs:[],outputs:[{name:``,type:`address`,internalType:`contract ITokenWrapperRegistry`}],stateMutability:`view`},{type:`error`,name:`InvalidTokenWrapperRegistry`,inputs:[]},{type:`error`,name:`MissingInputProof`,inputs:[]},{type:`error`,name:`ReentrancyGuardReentrantCall`,inputs:[]},{type:`error`,name:`ZamaProtocolUnsupported`,inputs:[]},{type:`error`,name:`UnlistedConfidentialToken`,inputs:[{name:`token`,type:`address`,internalType:`address`}]}];function ue(e,t,n){return{address:e,abi:H,functionName:`join`,args:[t,n]}}const de=le({abi:H,name:`join`}).inputs;function fe(e,t){return ce(de,[e.map(e=>({...e})),t])}function pe(e){return{address:e,abi:H,functionName:`tokenWrapperRegistry`,args:[]}}const U={Joined:ae(`Joined(uint256,address,bytes32)`)};function W(e){let[t,n,r]=e.topics;return t!==U.Joined||n===void 0||r===void 0?null:{batchId:BigInt(n),account:se(r),confidentialAmount:re(e.data,0)}}function me(e,t,n){if(e.address!==void 0&&v(e.address)!==t)return null;let r=W(e);return!r||n!==void 0&&r.account!==n?null:r}function G(e,t,n){return K([...e],t,n)}function K(e,t,n){let r=n?v(n):void 0;for(let[n,i]of e.entries()){let a=me(i,t,r);if(a)return e.splice(n,1),a}return null}const q={Pending:0,Dispatched:1,Finalized:2,Canceled:3};var J=class{sdk;address;#e;#t;#n;#r=null;constructor(e,t){this.sdk=e,this.address=v(t),this.#e=y(()=>e.provider.readContract(A(this.address))),this.#t=y(()=>e.provider.readContract(j(this.address))),this.#n=y(()=>e.provider.readContract(M(this.address)))}async vault(){return this.#e()}async fromToken(){return this.#t()}async toToken(){return this.#n()}async currentBatchId(){return this.sdk.provider.readContract(E(this.address))}async batchState(e){return await this.sdk.provider.readContract(D(this.address,e))}async paused(){return this.sdk.provider.readContract(V(this.address))}async minBatchAge(){return this.sdk.provider.readContract(N(this.address))}async batchMinBatchAge(e){return this.sdk.provider.readContract(P(this.address,e))}async callbackDeadline(){return this.sdk.provider.readContract(F(this.address))}async batchCallbackDeadline(e){return this.sdk.provider.readContract(I(this.address,e))}async batchCreatedAt(e){return this.sdk.provider.readContract(L(this.address,e))}async batchDispatchedAt(e){return this.sdk.provider.readContract(R(this.address,e))}async exchangeRate(e){return this.sdk.provider.readContract(z(this.address,e))}async exchangeRateDecimals(){return this.sdk.provider.readContract(B(this.address))}async timeUntilDispatchable(e){let[t,n,r,i]=await Promise.all([this.batchState(e),this.batchCreatedAt(e),this.batchMinBatchAge(e),this.sdk.provider.getBlockTimestamp()]);if(t!==q.Pending)return null;let a=n+r;return a>i?a-i:0n}async confidentialTotalDeposits(e){return this.sdk.provider.readContract(O(this.address,e))}async confidentialDepositOf(e,t){return this.sdk.provider.readContract(k(this.address,e,v(t)))}async depositOf(e,t){let r=v(t),i=await this.confidentialDepositOf(e,r);if(d(i))return 0n;let a=(await this.sdk.decryption.decryptValues([{encryptedValue:i,contractAddress:this.address}],{operation:`vault-deposit-of`}))[i];if(a===void 0)throw new n(`Decryption returned no value for ${i}`);return c(a,`depositOf: result[encryptedValue]`),a}async join(e,n,r){let{operation:i}=h(r,`vault-join`);this.#i(`join`);let o=v((await l(`join`,this.sdk.signer,this.sdk.provider)).address),s=n?v(n):o;r?.skipBalanceCheck||await this.#o(e,i);let{encryptedValues:c,inputProof:u}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:o},{operation:i}),d=c[0];if(!d)throw new t(`Encryption returned no encrypted values`);let f=await this.#c(`vault:join`,x(this.address,s,d,u)),p=G(f.receipt.logs,this.address,s);if(!p)throw new a(`No Joined event for ${s} from batcher ${this.address} found in the join receipt`);return{...f,batchId:p.batchId,beneficiary:p.account,confidentialJoinedAmount:p.confidentialAmount}}async quit(e){return this.#i(`quit`),await p(`quit`,this.sdk.signer,this.sdk.provider),this.#c(`vault:quit`,C(this.address,e))}async recover(e,t){let n=await this.#s(`recover`,t);return this.#c(`vault:recover`,w(this.address,e,n))}async claim(e,t){let n=await this.#s(`claim`,t);return this.#c(`vault:claim`,S(this.address,e,n))}async dispatchBatch(){return this.#i(`dispatchBatch`),await p(`dispatchBatch`,this.sdk.signer,this.sdk.provider),this.#c(`vault:dispatchBatch`,T(this.address))}#i(e){if(!this.sdk.signer)throw new i(e);return this.sdk.signer}async#a(){return this.#r??=this.fromToken().then(e=>new ee(this.sdk,e)).catch(e=>{throw this.#r=null,e}),this.#r}async#o(e,t){let n=await this.#a();return u({operation:`join`,tokenAddress:n.address,amount:e,signer:this.sdk.signer,provider:this.sdk.provider,readBalance:e=>n.decryptBalance(e,t)})}async#s(e,t){return this.#i(e),t?(await p(e,this.sdk.signer,this.sdk.provider),v(t)):v((await l(e,this.sdk.signer,this.sdk.provider)).address)}async#c(e,t){return f({operation:e,signer:this.#i(e),provider:this.sdk.provider,config:t,emit:e=>this.sdk.emitEvent(e,this.address),logger:this.sdk.logger})}};function he(e,t){return new J(e,t)}var Y=class{sdk;depositBatcher;redeemBatcher;#e=null;#t=null;#n=null;#r;constructor(e,t){this.sdk=e,this.#r=t.vault?v(t.vault):void 0,this.depositBatcher=new J(e,t.depositBatcher),this.redeemBatcher=new J(e,t.redeemBatcher)}async vaultAddress(){return this.#e??=this.#i().catch(e=>{throw this.#e=null,e}),this.#e}async cAsset(){return this.#t??=this.depositBatcher.fromToken().then(e=>new m(this.sdk,e)).catch(e=>{throw this.#t=null,e}),this.#t}async cShare(){return this.#n??=this.redeemBatcher.fromToken().then(e=>new m(this.sdk,e)).catch(e=>{throw this.#n=null,e}),this.#n}async deposit(e,t){let[,n]=await Promise.all([this.vaultAddress(),this.cAsset()]);return await this.#a(`deposit`,n,this.depositBatcher.address,t?.operatorUntil),this.depositBatcher.join(e,t?.beneficiary,{skipBalanceCheck:t?.skipBalanceCheck,operation:`vault-deposit`})}async redeem(e,t){let[,n]=await Promise.all([this.vaultAddress(),this.cShare()]);return await this.#a(`redeem`,n,this.redeemBatcher.address,t?.operatorUntil),this.redeemBatcher.join(e,t?.beneficiary,{skipBalanceCheck:t?.skipBalanceCheck,operation:`vault-redeem`})}async#i(){let[t,n]=await Promise.all([this.depositBatcher.vault(),this.redeemBatcher.vault()]);if(v(t)!==v(n))throw new e(`Vault batchers point at different ERC-4626 vaults: deposit batcher ${this.depositBatcher.address} reports ${t}, redeem batcher ${this.redeemBatcher.address} reports ${n}`);let r=v(t);if(this.#r!==void 0&&this.#r!==r)throw new e(`Configured vault address ${this.#r} does not match the ${r} both batchers report`);return r}async#a(e,t,n,r){if(!this.sdk.signer)throw new i(e);let a=this.sdk.signer.requireWalletAccount(e);await t.isOperator(a.address,n)||await t.setOperator(n,r)}};function ge(e,t){return new Y(e,t)}const _e=10,ve={deposit:{batcher:e=>e.depositBatcher,token:e=>e.cAsset(),asset:e=>e.depositBatcher.fromToken()},redeem:{batcher:e=>e.redeemBatcher,token:e=>e.cShare(),asset:e=>e.redeemBatcher.toToken()}};function ye(e){return[...new Map(e.map(e=>[e.token.address,e.token])).values()]}function X(e){let t=new Set;for(let n of e){if(t.has(n))return n;t.add(n)}}var Z=class{sdk;id;cAsset;router;members;#e;constructor(t,n){if(n.vaults.length<2)throw new e(`Vault group "${n.id}" names ${n.vaults.length} vault(s); a group needs at least two, and a single vault is a Vault`);if(n.vaults.length>10)throw new e(`Vault group "${n.id}" names ${n.vaults.length} vaults, above the 10 a submission can carry`);let r=n.vaults.map(e=>({id:e.id,vault:new Y(t,e)})),i=X(r.map(e=>e.id));if(i!==void 0)throw new e(`Vault group "${n.id}" names "${i}" twice`);let a=X(n.vaults.flatMap(e=>e.vault?[v(e.vault)]:[]));if(a!==void 0)throw new e(`Vault group "${n.id}" gives ${a} as the vault of more than one member`);let o=X(r.flatMap(({vault:e})=>[e.depositBatcher.address,e.redeemBatcher.address]));if(o!==void 0)throw new e(`Vault group "${n.id}" names batcher ${o} more than once`);this.sdk=t,this.id=n.id,this.cAsset=v(n.cAsset),this.router=v(n.router),this.members=r,this.#e=y(async()=>v(await t.provider.readContract(pe(this.router))))}async isAssetListed(){return this.sdk.provider.readContract(o(await this.#e(),this.cAsset))}member(t){let n=this.members.find(e=>e.id===t);if(!n)throw new e(`Vault group "${this.id}" has no vault "${t}"`);return n}async deposit(e,n,r){let{operation:i}=h(r,`vault-group-deposit`),{member:a,signer:o,holder:c}=await this.#t(`deposit`,e),[l]=await Promise.all([this.#n(`deposit`,a,n),this.#o()]);await this.#i(`deposit`,a,n,l,o,r);let[u,d]=await Promise.all([this.sdk.encrypt({values:[{value:n,type:`euint64`}],contractAddress:this.cAsset,userAddress:c},{operation:i}),this.#a(c,l,i)]),[f]=u.encryptedValues;if(!f)throw new t(`Encryption returned no encrypted values`);let p=await this.#s(o,s(this.cAsset,this.router,f,u.inputProof,fe(d.legs,d.inputProof)));return this.#c(e,c,l,p)}async redeem(e,t,n){let{operation:r}=h(n,`vault-group-redeem`),{member:i,signer:a,holder:o}=await this.#t(`redeem`,e),[s]=await Promise.all([this.#n(`redeem`,i,t),this.#e()]);await this.#i(`redeem`,i,t,s,a,n);let c=await this.#a(o,s,r),l=await Promise.all(ye(s).map(async e=>({token:e,granted:await e.isOperator(o,this.router)})));for(let{token:e}of l.filter(e=>!e.granted))await e.setOperator(this.router,n?.operatorUntil);let u=await this.#s(a,ue(this.router,c.legs,c.inputProof));return this.#c(e,o,s,u)}async#t(e,t){let n=this.member(t),r=this.sdk.signer;if(!r)throw new i(e);return{member:n,signer:r,holder:v((await l(e,r,this.sdk.provider)).address)}}async#n(t,n,r){let i=await Promise.all(this.members.map(e=>this.#r(t,e,e===n?r:0n))),a=X(i.map(e=>e.vault));if(a!==void 0)throw new e(`Vault group "${this.id}" has two members whose batchers report the same vault ${a}`);return i}async#r(t,n,r){let i=ve[t],a=i.batcher(n.vault),[o,s,c,l]=await Promise.all([n.vault.vaultAddress(),i.token(n.vault),i.asset(n.vault),a.paused()]);if(v(c)!==this.cAsset)throw new e(`Batcher ${a.address} of vault "${n.id}" is paired with ${c}, but group "${this.id}" is configured with ${this.cAsset}`);if(l)throw new ie(`Batcher ${a.address} of vault "${n.id}" in group "${this.id}" is paused, so no member can be joined until it resumes`,{batcher:a.address,vaultId:n.id});return{member:n,batcher:a,token:s,vault:o,amount:r}}async#i(e,t,n,r,i,a){if(a?.skipBalanceCheck)return;let o=await ve[e].token(t.vault),s=ye(r);await u({operation:e,tokenAddress:o.address,amount:n,signer:i,provider:this.sdk.provider,readBalance:async e=>{let{results:t,errors:n}=await ee.batchBalancesOf(s,e),r=t.get(o.address);if(r===void 0)throw n.get(o.address)??new te(`Balance validation failed (token: ${o.address})`);return r}})}async#a(e,n,r){let{encryptedValues:i,inputProof:a}=await this.sdk.encrypt({values:n.map(e=>({value:e.amount,type:`euint64`})),contractAddress:this.router,userAddress:e},{operation:r});if(i.length!==n.length)throw new t(`Encryption returned ${i.length} values for ${n.length} legs`);return{legs:n.map((e,t)=>({batcher:e.batcher.address,token:e.token.address,amount:i[t]})),inputProof:a}}async#o(){if(!await this.isAssetListed())throw new oe(`The vault router's registry does not list ${this.cAsset}, so it would reject a transfer of it`,{token:this.cAsset,registry:await this.#e()})}#s(e,t){return f({operation:`vault:routerJoin`,signer:e,provider:this.sdk.provider,config:t,emit:e=>this.sdk.emitEvent(e,this.router),logger:this.sdk.logger})}#c(e,t,n,r){let i=[...r.receipt.logs],a=[],o=[];for(let e of n){let n=K(i,e.batcher.address,t);if(!n){o.push(e.member.id);continue}a.push({vaultId:e.member.id,batcher:e.batcher.address,token:e.token.address,batchId:n.batchId,confidentialJoinedAmount:n.confidentialAmount})}if(o.length>0)throw new ne(`Transaction ${r.txHash} was mined, but its receipt has no Joined event for ${t} from the batcher of vault(s) ${o.map(e=>`"${e}"`).join(`, `)} in group "${this.id}"`,{txHash:r.txHash,receipt:r.receipt,joins:a,unconfirmed:o});return{...r,vaultId:e,joins:a}}};function be(e,t){return new Z(e,t)}const Q={currentBatchId:{batcher:e=>[`zama.vault.currentBatchId`,{batcherAddress:v(e)}]},batchState:{batcher:e=>[`zama.vault.batchState`,{batcherAddress:v(e)}],batch:(e,t)=>[`zama.vault.batchState`,{batcherAddress:v(e),batchId:t}]},timeUntilDispatchable:{batcher:e=>[`zama.vault.timeUntilDispatchable`,{batcherAddress:v(e)}],batch:(e,t)=>[`zama.vault.timeUntilDispatchable`,{batcherAddress:v(e),batchId:t}]}};function $(e,t){e.invalidateQueries({queryKey:Q.currentBatchId.batcher(t)}),e.invalidateQueries({queryKey:Q.batchState.batcher(t)}),e.invalidateQueries({queryKey:Q.timeUntilDispatchable.batcher(t)})}function xe(e,t){g(e,t.fromToken),$(e,t.batcherAddress)}function Se(e,t){g(e,t.fromToken),$(e,t.batcherAddress)}function Ce(e,t){g(e,t.toToken)}function we(e,t){$(e,t)}function Te(e){return{mutationKey:[`zama.vaultGroup.deposit`,{cAsset:e.cAsset,batchers:e.members.map(({vault:e})=>e.depositBatcher.address)}],mutationFn:async({vaultId:t,amount:n,...r})=>e.deposit(t,n,r)}}function Ee(e){return{mutationKey:[`zama.vaultGroup.redeem`,{cAsset:e.cAsset,batchers:e.members.map(({vault:e})=>e.redeemBatcher.address)}],mutationFn:async({vaultId:t,amount:n,...r})=>e.redeem(t,n,r)}}function De(e,t={}){let n=t.query??{};return{..._(n),queryKey:Q.currentBatchId.batcher(e.address),queryFn:async()=>e.currentBatchId(),enabled:n.enabled!==!1}}function Oe(e,t={}){let n=t.query??{};return{..._(n),queryKey:Q.batchState.batch(e.address,t.batchId),queryFn:async t=>{let[,{batchId:n}]=t.queryKey;return r(n,`batchStateQueryOptions: batchId`),e.batchState(n)},enabled:t.batchId!==void 0&&n.enabled!==!1}}function ke(e,t={}){let n=t.query??{};return{..._(n),queryKey:Q.timeUntilDispatchable.batch(e.address,t.batchId),queryFn:async t=>{let[,{batchId:n}]=t.queryKey;return r(n,`timeUntilDispatchableQueryOptions: batchId`),e.timeUntilDispatchable(n)},enabled:t.batchId!==void 0&&n.enabled!==!1}}function Ae(e){return{mutationKey:[`zama.vault.deposit`,e.depositBatcher.address],mutationFn:async({amount:t,...n})=>e.deposit(t,n)}}function je(e){return{mutationKey:[`zama.vault.redeem`,e.redeemBatcher.address],mutationFn:async({amount:t,...n})=>e.redeem(t,n)}}function Me(e){return{mutationKey:[`zama.vault.join`,e.address],mutationFn:async({amount:t,beneficiary:n,...r})=>e.join(t,n,r)}}function Ne(e){return{mutationKey:[`zama.vault.claim`,e.address],mutationFn:async({batchId:t,account:n})=>e.claim(t,n)}}function Pe(e){return{mutationKey:[`zama.vault.quit`,e.address],mutationFn:async({batchId:t})=>e.quit(t)}}function Fe(e){return{mutationKey:[`zama.vault.recover`,e.address],mutationFn:async({batchId:t,account:n})=>e.recover(t,n)}}function Ie(e){return{mutationKey:[`zama.vault.dispatchBatch`,e.address],mutationFn:async()=>e.dispatchBatch()}}export{q as BatchState,_e as MAX_GROUP_VAULTS,Y as Vault,J as VaultBatcher,Z as VaultGroup,U as VaultTopics,I as batchCallbackDeadlineContract,L as batchCreatedAtContract,R as batchDispatchedAtContract,P as batchMinBatchAgeContract,D as batchStateContract,Oe as batchStateQueryOptions,F as callbackDeadlineContract,S as claimContract,Ne as claimMutationOptions,ge as createVault,he as createVaultBatcher,be as createVaultGroup,E as currentBatchIdContract,De as currentBatchIdQueryOptions,W as decodeJoined,Ae as depositMutationOptions,k as depositsContract,T as dispatchBatchContract,Ie as dispatchBatchMutationOptions,z as exchangeRateContract,B as exchangeRateDecimalsContract,G as findJoined,j as fromTokenContract,Te as groupDepositMutationOptions,Ee as groupRedeemMutationOptions,Ce as invalidateAfterClaim,we as invalidateAfterDispatchBatch,xe as invalidateAfterJoin,Se as invalidateAfterQuit,$ as invalidateBatchQueries,x as joinContract,Me as joinMutationOptions,N as minBatchAgeContract,V as pausedContract,C as quitContract,Pe as quitMutationOptions,w as recoverContract,Fe as recoverMutationOptions,je as redeemMutationOptions,ke as timeUntilDispatchableQueryOptions,M as toTokenContract,O as totalDepositsContract,A as vaultContract,Q as vaultQueryKeys};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/viem/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{F as e,H as t,L as n,M as r,N as i,O as a,P as o,S as s,T as c,Y as l,a as u,i as d,m as f,n as p,o as m,q as h,r as g,s as _,t as v}from"../wrappers-registry-DnYVQ02R.js";import{i as y,t as b}from"../base-signer-
|
|
1
|
+
import{F as e,H as t,L as n,M as r,N as i,O as a,P as o,S as s,T as c,Y as l,a as u,i as d,m as f,n as p,o as m,q as h,r as g,s as _,t as v}from"../wrappers-registry-DnYVQ02R.js";import{i as y,t as b}from"../base-signer-6YPpqhw9.js";import{t as x}from"../typed-data-eAgGr9V-.js";import{t as S}from"../eip1193-subscribe-CNxVHW6y.js";import{encodeFunctionData as C,getAddress as w,serializeTransaction as T}from"viem";var E=class{#e;constructor(e){this.#e=e.publicClient}async getChainId(){return this.#e.getChainId()}async readContract(e){return this.#e.readContract(e)}async waitForTransactionReceipt(e){return this.#e.waitForTransactionReceipt({hash:e})}async getBlockTimestamp(){return(await this.#e.getBlock()).timestamp}async prepareTransaction(e){let{from:t,calldata:n}=e,r=C({abi:n.abi,functionName:n.functionName,args:n.args}),i=this.#e.getChainId(),a=e.nonce===void 0?this.#e.getTransactionCount({address:t,blockTag:`pending`}):Promise.resolve(e.nonce),o=e.gasLimit===void 0?n.gas??this.#e.estimateGas({account:t,to:n.address,data:r,value:n.value??0n}).catch(e=>{throw new l(`ViemProvider.prepareTransaction: gas estimation reverted for ${n.functionName} on ${n.address}`,{cause:e})}):Promise.resolve(e.gasLimit),s=e.fees??this.#e.estimateFeesPerGas(),[c,u,d,f]=await Promise.all([i,a,o,s]);return T({type:`eip1559`,chainId:c,nonce:u,to:n.address,data:r,value:n.value??0n,gas:d,maxFeePerGas:f.maxFeePerGas,maxPriorityFeePerGas:f.maxPriorityFeePerGas})}};function D(e){if(!(!e.account||!e.chain))return{address:w(e.account.address),chainId:e.chain.id}}var O=class extends b{#e;#t;#n;constructor(e){super(D(e.walletClient)),this.#e=e.walletClient,this.#t=e.ethereum,this.#n=this.#i()}#r(e){if(!this.#e.account)throw new h(e);return{walletClient:this.#e,account:this.#e.account}}async signTypedData(e){let{walletClient:t,account:n}=this.#r(`signTypedData`);return t.signTypedData({account:n,...x(e)})}async writeContract(e){let{walletClient:t,account:n}=this.#r(`writeContract`);return t.writeContract({chain:t.chain,account:n,...e})}#i(){return this.#t?S({provider:this.#t,getInitialWalletAccount:()=>D(this.#e),onWalletAccountChange:({next:e})=>{this.walletAccount.setSnapshot(e)}}):()=>{}}onDispose(){this.#n()}};function k(e){return y(new O({walletClient:e.walletClient,ethereum:e.ethereum}),new E({publicClient:e.publicClient}),e)}function A(e){if(!e.account)throw TypeError(`WalletClient has no account`);return e.account}function j(e,t,n){return e.readContract(s(t,n))}function M(e,t){return e.readContract(i(t))}function N(e,t,n){return e.readContract(f(t,n))}function P(e,t,n,r,i){return e.writeContract({chain:e.chain,account:A(e),...c(t,n,r,i)})}function F(e,t,n,r,i,a){return e.writeContract({chain:e.chain,account:A(e),...o(t,n,r,i,a)})}function I(t,n,r,i,a){return t.writeContract({chain:t.chain,account:A(t),...e(n,r,i,a)})}function L(e,t,n,r,i){return e.writeContract({chain:e.chain,account:A(e),...a(t,n,r,i)})}function R(e,t,n,i){return e.writeContract({chain:e.chain,account:A(e),...r(t,n,i)})}function z(e,t,r,i){return e.writeContract({chain:e.chain,account:A(e),...n(t,r,i)})}function B(e,t){return e.readContract(d(t))}function V(e,t){return e.readContract(u(t))}function H(e,t,n,r){return e.readContract(m(t,n,r))}function U(e,t,n){return e.readContract(g(t,n))}function W(e,t,n){return e.readContract(v(t,n))}function G(e,t,n){return e.readContract(p(t,n))}function K(e,t,n){return e.readContract(_(t,n))}export{b as BaseSigner,E as ViemProvider,O as ViemSigner,t as ZamaSDKEvents,k as createConfig,j as readConfidentialBalanceOfContract,W as readConfidentialTokenAddressContract,K as readIsConfidentialTokenValidContract,N as readSupportsInterfaceContract,G as readTokenAddressContract,U as readTokenPairContract,B as readTokenPairsContract,V as readTokenPairsLengthContract,H as readTokenPairsSliceContract,M as readUnderlyingTokenContract,P as writeConfidentialTransferContract,L as writeFinalizeUnwrapContract,R as writeSetOperatorContract,F as writeUnwrapContract,I as writeUnwrapFromBalanceContract,z as writeWrapContract};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/web/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{r as e,t}from"../fhevm-relayer-
|
|
1
|
+
import{r as e,t}from"../fhevm-relayer-DF4uuzDF.js";import{t as n}from"../validation-ChQwNxaY.js";import{z as r}from"zod/mini";const i=e=>r._default(r.number().check(r.positive()),e),a=r.custom(e=>typeof e==`function`),o=r.object({offloadEncrypt:r._default(r.union([r.literal(`auto`),r.boolean()]),`auto`),offloadTimeouts:r.optional(r.object({spawn:i(e.spawn),init:i(e.init)})),offloadWorker:r.optional(r.union([r.string().check(r.minLength(1)),r.instanceof(URL),a]))});function s(e){let{offloadEncrypt:r,offloadTimeouts:i,offloadWorker:a,...s}=e??{},c=n(o,{offloadEncrypt:r,offloadTimeouts:i,offloadWorker:a});return{type:`web`,createRelayer:(e,n,r)=>new t({chain:e,options:s,telemetry:r&&{state:r,runtime:`web`,mode:r.mode},offloadEncrypt:c.offloadEncrypt,offloadTimeouts:c.offloadTimeouts,offloadWorker:c.offloadWorker,logger:n})}}export{s as web};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|