@zama-fhe/sdk 3.0.0 → 3.0.1
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/activity.cjs +1 -1
- package/dist/cjs/activity.cjs.map +1 -1
- package/dist/cjs/wrappers-registry.cjs +1 -1
- package/dist/cjs/wrappers-registry.cjs.map +1 -1
- package/dist/esm/activity-BAFx7EMt.js +2 -0
- package/dist/esm/{activity-dMzF5FdR.js.map → activity-BAFx7EMt.js.map} +1 -1
- package/dist/esm/{activity-DBMyE78S.d.ts → activity-CUYnGNME.d.ts} +4180 -5352
- package/dist/esm/ethers/index.js +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/query/index.d.ts +1 -1
- package/dist/esm/query/index.js +1 -1
- package/dist/esm/viem/index.js +1 -1
- package/dist/esm/wrappers-registry-Ckwd2j6g.js +2 -0
- package/dist/esm/wrappers-registry-Ckwd2j6g.js.map +1 -0
- package/package.json +1 -1
- package/dist/esm/activity-dMzF5FdR.js +0 -2
- package/dist/esm/wrappers-registry-DO0729Zi.js +0 -2
- package/dist/esm/wrappers-registry-DO0729Zi.js.map +0 -1
package/dist/cjs/activity.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require(`./relayer.cjs`),t=require(`./wrappers-registry.cjs`);let n=require(`viem`);var r=class extends e.a{constructor(t,n){super(e.o.SigningRejected,t,n),this.name=`SigningRejectedError`}},i=class extends e.a{constructor(t,n){super(e.o.SigningFailed,t,n),this.name=`SigningFailedError`}};function a(e,t){let n=typeof e==`object`&&!!e&&`code`in e&&e.code===4001,a=e instanceof Error?e.message:String(e),o=a.toLowerCase(),s=o.includes(`user rejected`)||o.includes(`user denied`),c=`${t}: ${a}`;throw n||s?new r(c,{cause:e}):new i(c,{cause:e})}var o=class extends e.a{constructor(t,n){super(e.o.KeypairExpired,t,n),this.name=`KeypairExpiredError`}},s=class extends e.a{constructor(t,n){super(e.o.InvalidKeypair,t,n),this.name=`InvalidKeypairError`}},c=class extends e.a{constructor(t,n){super(e.o.NoCiphertext,t,n),this.name=`NoCiphertextError`}},l=class extends e.a{constructor(t,n){super(e.o.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},u=class extends e.a{constructor(t,n){super(e.o.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},d=class extends e.a{constructor(t,n){super(e.o.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},f=class extends e.a{constructor(t,n){super(e.o.DelegationExpired,t,n),this.name=`DelegationExpiredError`}},p=class extends e.a{constructor(t,n){super(e.o.DelegationExpiryUnchanged,t,n),this.name=`DelegationExpiryUnchangedError`}},m=class extends e.a{constructor(t,n){super(e.o.DelegationDelegateEqualsContract,t,n),this.name=`DelegationDelegateEqualsContractError`}},h=class extends e.a{constructor(t,n){super(e.o.DelegationContractIsSelf,t,n),this.name=`DelegationContractIsSelfError`}},g=class extends e.a{constructor(t,n){super(e.o.AclPaused,t,n),this.name=`AclPausedError`}},_=class extends e.a{constructor(t,n){super(e.o.DelegationExpirationTooSoon,t,n),this.name=`DelegationExpirationTooSoonError`}},v=class extends e.a{constructor(t,n){super(e.o.DelegationNotPropagated,t,n),this.name=`DelegationNotPropagatedError`}};function y(t,n,a=!1){if(t instanceof e.r||t instanceof c||t instanceof e.n||t instanceof v||t instanceof r||t instanceof i)return t;let o=typeof t==`object`&&t&&`statusCode`in t&&typeof t.statusCode==`number`?t.statusCode:void 0;return o===400?new c(t instanceof Error?t.message:`No ciphertext for this account`,{cause:t}):a&&o===500?new v(`Delegated decryption failed with a server error. This is most commonly caused by the delegation not having propagated to the gateway yet — after granting delegation, allow 1–2 minutes for cross-chain synchronization before retrying. If the error persists, the gateway or relayer may be experiencing an unrelated issue.`,{cause:t}):o===void 0?new e.r(n,{cause:t}):new e.n(t instanceof Error?t.message:n,o,{cause:t})}function b(t){return t instanceof r||t instanceof i||t instanceof e.t}function ee(e,t){if(e==null)throw TypeError(`${t} must not be null or undefined`)}function te(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`${t} must be an object, got ${typeof e}`)}function x(e,t){if(typeof e!=`string`)throw TypeError(`${t} must be a string, got ${typeof e}`)}function ne(e,t){if(!Array.isArray(e))throw TypeError(`${t} must be an array, got ${typeof e}`)}function re(e,t){if(typeof e!=`function`)throw TypeError(`${t} must be a function, got ${typeof e}`)}function S(e,t){if(typeof e!=`bigint`)throw TypeError(`${t} must be a bigint, got ${typeof e}`)}function ie(e,t,n){x(e[t],n)}function ae(e,t,n){re(e[t],n)}function oe(e,t){if(!e)throw TypeError(t)}function C(e){return e instanceof Error?e:typeof e==`object`&&e&&`message`in e?Error(String(e.message)):Error(String(e))}function se(e){if(!(e instanceof Error))return!1;if(e.name===`ContractFunctionExecutionError`||e.name===`ContractFunctionRevertedError`||`code`in e&&e.code===`CALL_EXCEPTION`)return!0;let t=e.message.toLowerCase();return t.includes(`execution reverted`)||t.includes(`call revert exception`)}function w(e){return e.startsWith(`0x`)?e:`0x${e}`}function T(e){return e===`0x0000000000000000000000000000000000000000000000000000000000000000`||e===`0x`}function E(e){return{address:e,abi:n.erc20Abi,functionName:`name`,args:[]}}function D(e){return{address:e,abi:n.erc20Abi,functionName:`symbol`,args:[]}}function O(e){return{address:e,abi:n.erc20Abi,functionName:`decimals`,args:[]}}function ce(e){return{address:e,abi:n.erc20Abi,functionName:`totalSupply`,args:[]}}function le(e,t){return{address:e,abi:n.erc20Abi,functionName:`balanceOf`,args:[t]}}function k(e,t,r){return{address:e,abi:n.erc20Abi,functionName:`allowance`,args:[t,r]}}function ue(e,t,r){return{address:e,abi:n.erc20Abi,functionName:`approve`,args:[t,r]}}const A=[{inputs:[{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`},{internalType:`uint64`,name:`expirationDate`,type:`uint64`}],name:`delegateForUserDecryption`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`}],name:`revokeDelegationForUserDecryption`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`delegator`,type:`address`},{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`}],name:`getUserDecryptionDelegationExpirationDate`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`delegator`,type:`address`},{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`},{internalType:`bytes32`,name:`handle`,type:`bytes32`}],name:`isHandleDelegatedForUserDecryption`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`}];function de(e,t,n,r){return{address:e,abi:A,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function fe(e,t,n){return{address:e,abi:A,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function j(e,t,n,r){return{address:e,abi:A,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function pe(e,t,n,r,i){return{address:e,abi:A,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const M=2n**64n-1n,N={CredentialsLoading:`credentials:loading`,CredentialsCached:`credentials:cached`,CredentialsExpired:`credentials:expired`,CredentialsCreating:`credentials:creating`,CredentialsCreated:`credentials:created`,CredentialsRevoked:`credentials:revoked`,CredentialsPersistFailed:`credentials:persist_failed`,CredentialsAllowed:`credentials:allowed`,CredentialsCorrupted:`credentials:corrupted`,SessionExpired:`session:expired`,EncryptStart:`encrypt:start`,EncryptEnd:`encrypt:end`,EncryptError:`encrypt:error`,DecryptStart:`decrypt:start`,DecryptEnd:`decrypt:end`,DecryptError:`decrypt:error`,TransactionError:`transaction:error`,ShieldSubmitted:`shield:submitted`,TransferSubmitted:`transfer:submitted`,TransferFromSubmitted:`transferFrom:submitted`,ApproveSubmitted:`approve:submitted`,ApproveUnderlyingSubmitted:`approveUnderlying:submitted`,UnwrapSubmitted:`unwrap:submitted`,FinalizeUnwrapSubmitted:`finalizeUnwrap:submitted`,DelegationSubmitted:`delegation:submitted`,RevokeDelegationSubmitted:`revokeDelegation:submitted`,UnshieldPhase1Submitted:`unshield:phase1_submitted`,UnshieldPhase2Started:`unshield:phase2_started`,UnshieldPhase2Submitted:`unshield:phase2_submitted`};async function P(e,t=1/0){if(Number.isFinite(t)&&t<=0)throw Error(`maxConcurrency must be a positive number`);if(!Number.isFinite(t)||t>=e.length)return Promise.all(e.map(e=>e()));let n=Array.from({length:e.length}),r=0;async function i(){for(;r<e.length;){let t=r++;e[t]&&(n[t]=await e[t]())}}return await Promise.all(Array.from({length:t},i)),n}var me=class r{sdk;address;constructor(e,t){this.sdk=e,this.address=(0,n.getAddress)(t)}async balanceOf(t){let r=t?(0,n.getAddress)(t):await this.sdk.signer.getAddress(),i=await this.readConfidentialBalanceOf(r),a=(await this.sdk.userDecrypt([{handle:i,contractAddress:this.address}]))[i];if(a===void 0)throw new e.r(`Decryption returned no value for handle ${i}`);return S(a,`balanceOf: result[handle]`),a}async confidentialBalanceOf(e){let t=e?(0,n.getAddress)(e):await this.sdk.signer.getAddress();return this.readConfidentialBalanceOf(t)}async isConfidential(){return this.sdk.signer.readContract(t.f(this.address,t.c))}async isWrapper(){return this.sdk.signer.readContract(t.f(this.address,t.l))}static async batchBalancesOf(t,n){let i=new Map,a=new Map;if(t.length===0)return{results:i,errors:a};await r.assertSameSdk(t).allow(t.map(e=>e.address));let o=await P(t.map(e=>async()=>{try{return{status:`fulfilled`,value:await e.balanceOf(n)}}catch(e){return{status:`rejected`,reason:e}}}),5);for(let n=0;n<t.length;n++){let r=t[n].address,s=o[n];if(s.status===`fulfilled`)i.set(r,s.value);else{let t=s.reason;if(b(t))throw t;let n=t instanceof e.a?t:new e.r(C(t).message,{cause:t});a.set(r,n)}}if(a.size===t.length)throw a.values().next().value??new e.r(`All token balance decryptions failed`);return{results:i,errors:a}}static async batchDecryptBalancesAs(t,n){if(t.length===0)return new Map;let{delegatorAddress:i,handles:a,owner:o,onError:s,maxConcurrency:c}=n,l=o??i,u=t[0];r.assertSameSdk(t);let d=a??await Promise.all(t.map(e=>e.readConfidentialBalanceOf(l)));if(t.length!==d.length)throw new e.r(`tokens.length (${t.length}) must equal handles.length (${d.length})`);let f=new Map,p=[],m=await Promise.all(t.map(async(e,t)=>{let n=d[t];return T(n)?0n:u.sdk.cache.get(l,e.address,n)}));for(let e=0;e<t.length;e++){let n=t[e],r=d[e],i=m[e];if(i!=null){S(i,`batchDecryptBalancesAs: cached`),f.set(n.address,i);continue}p.push({token:n,handle:r})}if(p.length===0)return f;await u.#e(i);let h=p.map(e=>e.token.address),g=await u.sdk.delegatedCredentials.allow(i,...h),_=[],v=[];for(let{token:t,handle:n}of p)v.push(()=>u.sdk.relayer.delegatedUserDecrypt({handles:[n],contractAddress:t.address,signedContractAddresses:g.contractAddresses,privateKey:g.privateKey,publicKey:g.publicKey,signature:g.signature,delegatorAddress:g.delegatorAddress,delegateAddress:g.delegateAddress,startTimestamp:g.startTimestamp,durationDays:g.durationDays}).then(async r=>{let i=r[n];if(i===void 0)throw new e.r(`Batch delegated decryption returned no value for handle ${n} on token ${t.address}`);S(i,`batchDecryptBalancesAs: result[handle]`),f.set(t.address,i),u.sdk.cache.set(l,t.address,n,i).catch(e=>{console.warn(`[zama-sdk] Failed to cache decrypted value:`,e)})}).catch(e=>{if(b(e))throw e;let n=C(e);if(s)try{f.set(t.address,s(n,t.address))}catch(e){_.push({address:t.address,error:C(e)})}else _.push({address:t.address,error:n})}));if(await P(v,c),_.length>0){let t=_.map(e=>`${e.address}: ${e.error.message}`).join(`; `);throw new e.r(`Batch delegated decryption failed for ${_.length} token(s): ${t}`,{cause:_[0].error})}return f}async underlyingToken(){return this.sdk.signer.readContract(t.T(this.address))}async allowance(e,r){let i=(0,n.getAddress)(e),a=await this.sdk.signer.readContract(t.T(i)),o=r?(0,n.getAddress)(r):await this.sdk.signer.getAddress();return this.sdk.signer.readContract(k(a,o,i))}async name(){return this.sdk.signer.readContract(E(this.address))}async symbol(){return this.sdk.signer.readContract(D(this.address))}async decimals(){return this.sdk.signer.readContract(O(this.address))}async allow(){await this.sdk.allow([this.address])}async isAllowed(){return this.sdk.credentials.isAllowed([this.address])}async revoke(...e){await this.sdk.credentials.revoke(...e)}static async allow(...e){e.length!==0&&await r.assertSameSdk(e).allow(e.map(e=>e.address))}async getAclAddress(){return this.sdk.relayer.getAclAddress()}async isDelegated(e){let t=await this.getDelegationExpiry(e);return t===0n?!1:t===M?!0:t>await this.sdk.signer.getBlockTimestamp()}async getDelegationExpiry({delegatorAddress:e,delegateAddress:t}){let r=await this.getAclAddress();return this.sdk.signer.readContract(j(r,(0,n.getAddress)(e),(0,n.getAddress)(t),this.address))}async#e(e){let t=await this.sdk.signer.getAddress(),n=await this.getDelegationExpiry({delegatorAddress:e,delegateAddress:t});if(n===0n)throw new d(`No active delegation from ${e} to ${t} for ${this.address}`);if(n!==M&&n<=await this.sdk.signer.getBlockTimestamp())throw new f(`Delegation from ${e} to ${t} for ${this.address} has expired`)}async readConfidentialBalanceOf(e){return await this.sdk.signer.readContract(t.p(this.address,e))}async decryptBalanceAs({delegatorAddress:t,owner:r}){let i=(0,n.getAddress)(t),a=r?(0,n.getAddress)(r):i,o=await this.readConfidentialBalanceOf(a);if(T(o))return 0n;let s=await this.sdk.cache.get(a,this.address,o);if(s!==null)return S(s,`decryptBalanceAs: cached`),s;await this.#e(i);let c=Date.now();try{this.emit({type:N.DecryptStart,handles:[o]});let t=await this.sdk.delegatedCredentials.allow(i,this.address),n=await this.sdk.relayer.delegatedUserDecrypt({handles:[o],contractAddress:this.address,signedContractAddresses:t.contractAddresses,privateKey:t.privateKey,publicKey:t.publicKey,signature:t.signature,delegatorAddress:t.delegatorAddress,delegateAddress:t.delegateAddress,startTimestamp:t.startTimestamp,durationDays:t.durationDays}),r=n[o];if(r===void 0)throw new e.r(`Delegated decryption returned no value for handle ${o}`);return S(r,`decryptBalanceAs: result[handle]`),this.emit({type:N.DecryptEnd,durationMs:Date.now()-c,handles:[o],result:n}),await this.sdk.cache.set(a,this.address,o,r),r}catch(e){throw this.emit({type:N.DecryptError,error:C(e),durationMs:Date.now()-c,handles:[o]}),y(e,`Failed to decrypt delegated balance`,!0)}}emit(e){this.sdk.emitEvent(e,this.address)}static assertSameSdk(t){let n=t[0].sdk;for(let r=1;r<t.length;r++)if(t[r].sdk!==n)throw new e.t(`All tokens in a batch operation must share the same ZamaSDK instance`);return n}};const F={ConfidentialTransfer:`0x67500e8d0ed826d2194f514dd0d8124f35648ab6e3fb5e6ed867134cffe661e9`,Wrapped:`0x4700c1726b4198077cd40320a32c45265a1910521eb0ef713dd1d8412413d7fc`,UnwrapRequested:`0x77d02d353c5629272875d11f1b34ec4c65d7430b075575b78cd2502034c469ee`,UnwrappedFinalized:`0x2d4edf3c2943002120f53dab3f8940043f34799f4a92ab90f2f81f7dd004a49e`,UnwrappedStarted:`0x3838891d4843c6d7f9f494570b6fd8843f4e3c3ddb817c1411760bd31b819806`};function I(e){return(0,n.getAddress)(w(e.slice(-40)))}function L(e){return BigInt(e)}function he(e){return e}function R(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function z(e,t){return(0,n.getAddress)(w(R(e,t).slice(-40)))}function B(e,t){return BigInt(`0x`+R(e,t))}function ge(e,t){return BigInt(`0x`+R(e,t))!==0n}function V(e,t){return w(R(e,t))}function H(e){return e.topics[0]!==F.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:I(e.topics[1]),to:I(e.topics[2]),encryptedAmountHandle:he(e.topics[3])}}function U(e){return e.topics[0]!==F.Wrapped||e.topics.length<2?null:{eventName:`Wrapped`,to:I(e.topics[1]),amountIn:B(e.data,0)}}function W(e){return e.topics[0]!==F.UnwrapRequested||e.topics.length<2?null:{eventName:`UnwrapRequested`,receiver:I(e.topics[1]),encryptedAmount:V(e.data,0)}}function G(e){return e.topics[0]!==F.UnwrappedFinalized||e.topics.length<2?null:{eventName:`UnwrappedFinalized`,receiver:I(e.topics[1]),encryptedAmount:V(e.data,0),cleartextAmount:B(e.data,1)}}function K(e){return e.topics[0]!==F.UnwrappedStarted||e.topics.length<4?null:{eventName:`UnwrappedStarted`,requestId:L(e.topics[1]),txId:L(e.topics[2]),to:I(e.topics[3]),returnVal:ge(e.data,0),refund:z(e.data,1),requestedAmount:V(e.data,2),burnAmount:V(e.data,3)}}function q(e){return H(e)??U(e)??W(e)??G(e)??K(e)}function _e(e){let t=[];for(let n of e){let e=q(n);e&&t.push(e)}return t}function ve(e){for(let t of e){let e=W(t);if(e)return e}return null}function ye(e){for(let t of e){let e=U(t);if(e)return e}return null}const be=[F.ConfidentialTransfer,F.Wrapped,F.UnwrapRequested,F.UnwrappedFinalized,F.UnwrappedStarted],J={DelegatedForUserDecryption:`0x527b025d7ff06689c1ab9d32dfd7881c964cce72ce8ac5b2fe1d3be8cfda5bfc`,RevokedDelegationForUserDecryption:`0x7aca80b6b7928b9038f186e3d9922a0fc5d52c398fbf144725c142c52a5277e4`};function Y(e){return e.topics[0]!==J.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:I(e.topics[1]),delegate:I(e.topics[2]),contractAddress:z(e.data,0),delegationCounter:B(e.data,1),oldExpirationDate:B(e.data,2),newExpirationDate:B(e.data,3)}}function X(e){return e.topics[0]!==J.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:I(e.topics[1]),delegate:I(e.topics[2]),contractAddress:z(e.data,0),delegationCounter:B(e.data,1),oldExpirationDate:B(e.data,2)}}function Z(e){return Y(e)??X(e)}function xe(e){let t=[];for(let n of e){let e=Z(n);e&&t.push(e)}return t}function Se(e){for(let t of e){let e=Y(t);if(e)return e}return null}function Ce(e){for(let t of e){let e=X(t);if(e)return e}return null}const we=[J.DelegatedForUserDecryption,J.RevokedDelegationForUserDecryption];function Q(e,t){return e.toLowerCase()===t.toLowerCase()}function $(e,t,n){let r=t!==void 0&&Q(e,t),i=n!==void 0&&Q(e,n);return r&&i?`self`:r?`outgoing`:`incoming`}function Te(e,t,n){switch(e.eventName){case`ConfidentialTransfer`:return Ee(e,t,n);case`Wrapped`:return De(e,t,n);case`UnwrapRequested`:return Oe(e,t,n);case`UnwrappedStarted`:return ke(e,t,n);case`UnwrappedFinalized`:return Ae(e,t,n);default:throw Error(`Unknown event: ${e.eventName}`)}}function Ee(e,t,n){return{type:`transfer`,direction:$(t,e.from,e.to),amount:{type:`encrypted`,handle:e.encryptedAmountHandle},from:e.from,to:e.to,metadata:n,rawEvent:e}}function De(e,t,n){return{type:`shield`,direction:$(t,void 0,e.to),amount:{type:`clear`,value:e.amountIn},to:e.to,metadata:n,rawEvent:e}}function Oe(e,t,n){return{type:`unshield_requested`,direction:$(t,void 0,e.receiver),amount:{type:`encrypted`,handle:e.encryptedAmount},to:e.receiver,metadata:n,rawEvent:e}}function ke(e,t,n){return{type:`unshield_started`,direction:$(t,void 0,e.to),amount:{type:`encrypted`,handle:e.requestedAmount},to:e.to,success:e.returnVal,metadata:n,rawEvent:e}}function Ae(e,t,n){return{type:`unshield_finalized`,direction:$(t,void 0,e.receiver),amount:{type:`clear`,value:e.cleartextAmount},to:e.receiver,metadata:n,rawEvent:e}}function je(e,t){let n=[];for(let r of e){let e=q(r);if(!e)continue;let i={transactionHash:r.transactionHash,blockNumber:r.blockNumber,logIndex:r.logIndex};n.push(Te(e,t,i))}return n}function Me(e){let t=new Set;for(let n of e)if(n.amount.type===`encrypted`&&n.amount.decryptedValue===void 0){let e=n.amount.handle;T(e)||t.add(e)}return[...t]}function Ne(e,t){return e.map(e=>{if(e.amount.type!==`encrypted`)return e;let n=t[e.amount.handle];return n===void 0?e:(S(n,`applyDecryptedValues: value`),{...e,amount:{type:`encrypted`,handle:e.amount.handle,decryptedValue:n}})})}function Pe(e){return[...e].toSorted((e,t)=>{let n=e.metadata.blockNumber,r=t.metadata.blockNumber;if(n===void 0&&r===void 0)return 0;if(n===void 0)return-1;if(r===void 0)return 1;let i=typeof n==`bigint`?n:BigInt(n),a=typeof r==`bigint`?r:BigInt(r);if(a>i)return 1;if(a<i)return-1;let o=e.metadata.logIndex??0;return(t.metadata.logIndex??0)-o})}Object.defineProperty(exports,`$`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`A`,{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,`B`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,`D`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`E`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`F`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`G`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`H`,{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,`I`,{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,`J`,{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,`K`,{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,`L`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`M`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`N`,{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,`O`,{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,`P`,{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,`Q`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`R`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,`T`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,`U`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`V`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`W`,{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,`X`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`Y`,{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,`Z`,{enumerable:!0,get:function(){return ie}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,`at`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return Se}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`ct`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return H}}),Object.defineProperty(exports,`dt`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`et`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,`ft`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,`it`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`j`,{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,`k`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,`lt`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,`mt`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,`nt`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,`ot`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,`pt`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`q`,{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return je}}),Object.defineProperty(exports,`rt`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,`st`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return Ne}}),Object.defineProperty(exports,`tt`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,`ut`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,`w`,{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,`z`,{enumerable:!0,get:function(){return`0x0000000000000000000000000000000000000000000000000000000000000000`}});
|
|
1
|
+
const e=require(`./relayer.cjs`),t=require(`./wrappers-registry.cjs`);let n=require(`viem`);var r=class extends e.a{constructor(t,n){super(e.o.SigningRejected,t,n),this.name=`SigningRejectedError`}},i=class extends e.a{constructor(t,n){super(e.o.SigningFailed,t,n),this.name=`SigningFailedError`}};function a(e,t){let n=typeof e==`object`&&!!e&&`code`in e&&e.code===4001,a=e instanceof Error?e.message:String(e),o=a.toLowerCase(),s=o.includes(`user rejected`)||o.includes(`user denied`),c=`${t}: ${a}`;throw n||s?new r(c,{cause:e}):new i(c,{cause:e})}var o=class extends e.a{constructor(t,n){super(e.o.KeypairExpired,t,n),this.name=`KeypairExpiredError`}},s=class extends e.a{constructor(t,n){super(e.o.InvalidKeypair,t,n),this.name=`InvalidKeypairError`}},c=class extends e.a{constructor(t,n){super(e.o.NoCiphertext,t,n),this.name=`NoCiphertextError`}},l=class extends e.a{constructor(t,n){super(e.o.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},u=class extends e.a{constructor(t,n){super(e.o.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},d=class extends e.a{constructor(t,n){super(e.o.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},f=class extends e.a{constructor(t,n){super(e.o.DelegationExpired,t,n),this.name=`DelegationExpiredError`}},p=class extends e.a{constructor(t,n){super(e.o.DelegationExpiryUnchanged,t,n),this.name=`DelegationExpiryUnchangedError`}},m=class extends e.a{constructor(t,n){super(e.o.DelegationDelegateEqualsContract,t,n),this.name=`DelegationDelegateEqualsContractError`}},h=class extends e.a{constructor(t,n){super(e.o.DelegationContractIsSelf,t,n),this.name=`DelegationContractIsSelfError`}},g=class extends e.a{constructor(t,n){super(e.o.AclPaused,t,n),this.name=`AclPausedError`}},_=class extends e.a{constructor(t,n){super(e.o.DelegationExpirationTooSoon,t,n),this.name=`DelegationExpirationTooSoonError`}},v=class extends e.a{constructor(t,n){super(e.o.DelegationNotPropagated,t,n),this.name=`DelegationNotPropagatedError`}};function y(t,n,a=!1){if(t instanceof e.r||t instanceof c||t instanceof e.n||t instanceof v||t instanceof r||t instanceof i)return t;let o=typeof t==`object`&&t&&`statusCode`in t&&typeof t.statusCode==`number`?t.statusCode:void 0;return o===400?new c(t instanceof Error?t.message:`No ciphertext for this account`,{cause:t}):a&&o===500?new v(`Delegated decryption failed with a server error. This is most commonly caused by the delegation not having propagated to the gateway yet — after granting delegation, allow 1–2 minutes for cross-chain synchronization before retrying. If the error persists, the gateway or relayer may be experiencing an unrelated issue.`,{cause:t}):o===void 0?new e.r(n,{cause:t}):new e.n(t instanceof Error?t.message:n,o,{cause:t})}function ee(t){return t instanceof r||t instanceof i||t instanceof e.t}function te(e,t){if(e==null)throw TypeError(`${t} must not be null or undefined`)}function ne(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(`${t} must be an object, got ${typeof e}`)}function b(e,t){if(typeof e!=`string`)throw TypeError(`${t} must be a string, got ${typeof e}`)}function re(e,t){if(!Array.isArray(e))throw TypeError(`${t} must be an array, got ${typeof e}`)}function ie(e,t){if(typeof e!=`function`)throw TypeError(`${t} must be a function, got ${typeof e}`)}function x(e,t){if(typeof e!=`bigint`)throw TypeError(`${t} must be a bigint, got ${typeof e}`)}function ae(e,t,n){b(e[t],n)}function oe(e,t,n){ie(e[t],n)}function se(e,t){if(!e)throw TypeError(t)}function S(e){return e instanceof Error?e:typeof e==`object`&&e&&`message`in e?Error(String(e.message)):Error(String(e))}function ce(e){if(!(e instanceof Error))return!1;if(e.name===`ContractFunctionExecutionError`||e.name===`ContractFunctionRevertedError`||`code`in e&&e.code===`CALL_EXCEPTION`)return!0;let t=e.message.toLowerCase();return t.includes(`execution reverted`)||t.includes(`call revert exception`)}function C(e){return e.startsWith(`0x`)?e:`0x${e}`}function w(e){return e===`0x0000000000000000000000000000000000000000000000000000000000000000`||e===`0x`}function T(e){return{address:e,abi:n.erc20Abi,functionName:`name`,args:[]}}function E(e){return{address:e,abi:n.erc20Abi,functionName:`symbol`,args:[]}}function D(e){return{address:e,abi:n.erc20Abi,functionName:`decimals`,args:[]}}function le(e){return{address:e,abi:n.erc20Abi,functionName:`totalSupply`,args:[]}}function ue(e,t){return{address:e,abi:n.erc20Abi,functionName:`balanceOf`,args:[t]}}function O(e,t,r){return{address:e,abi:n.erc20Abi,functionName:`allowance`,args:[t,r]}}function de(e,t,r){return{address:e,abi:n.erc20Abi,functionName:`approve`,args:[t,r]}}const k=[{inputs:[{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`},{internalType:`uint64`,name:`expirationDate`,type:`uint64`}],name:`delegateForUserDecryption`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`}],name:`revokeDelegationForUserDecryption`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`delegator`,type:`address`},{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`}],name:`getUserDecryptionDelegationExpirationDate`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`delegator`,type:`address`},{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`},{internalType:`bytes32`,name:`handle`,type:`bytes32`}],name:`isHandleDelegatedForUserDecryption`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`}];function fe(e,t,n,r){return{address:e,abi:k,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function pe(e,t,n){return{address:e,abi:k,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function A(e,t,n,r){return{address:e,abi:k,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function me(e,t,n,r,i){return{address:e,abi:k,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const j=2n**64n-1n,M={CredentialsLoading:`credentials:loading`,CredentialsCached:`credentials:cached`,CredentialsExpired:`credentials:expired`,CredentialsCreating:`credentials:creating`,CredentialsCreated:`credentials:created`,CredentialsRevoked:`credentials:revoked`,CredentialsPersistFailed:`credentials:persist_failed`,CredentialsAllowed:`credentials:allowed`,CredentialsCorrupted:`credentials:corrupted`,SessionExpired:`session:expired`,EncryptStart:`encrypt:start`,EncryptEnd:`encrypt:end`,EncryptError:`encrypt:error`,DecryptStart:`decrypt:start`,DecryptEnd:`decrypt:end`,DecryptError:`decrypt:error`,TransactionError:`transaction:error`,ShieldSubmitted:`shield:submitted`,TransferSubmitted:`transfer:submitted`,TransferFromSubmitted:`transferFrom:submitted`,ApproveSubmitted:`approve:submitted`,ApproveUnderlyingSubmitted:`approveUnderlying:submitted`,UnwrapSubmitted:`unwrap:submitted`,FinalizeUnwrapSubmitted:`finalizeUnwrap:submitted`,DelegationSubmitted:`delegation:submitted`,RevokeDelegationSubmitted:`revokeDelegation:submitted`,UnshieldPhase1Submitted:`unshield:phase1_submitted`,UnshieldPhase2Started:`unshield:phase2_started`,UnshieldPhase2Submitted:`unshield:phase2_submitted`};async function N(e,t=1/0){if(Number.isFinite(t)&&t<=0)throw Error(`maxConcurrency must be a positive number`);if(!Number.isFinite(t)||t>=e.length)return Promise.all(e.map(e=>e()));let n=Array.from({length:e.length}),r=0;async function i(){for(;r<e.length;){let t=r++;e[t]&&(n[t]=await e[t]())}}return await Promise.all(Array.from({length:t},i)),n}var he=class r{sdk;address;constructor(e,t){this.sdk=e,this.address=(0,n.getAddress)(t)}async balanceOf(t){let r=t?(0,n.getAddress)(t):await this.sdk.signer.getAddress(),i=await this.readConfidentialBalanceOf(r),a=(await this.sdk.userDecrypt([{handle:i,contractAddress:this.address}]))[i];if(a===void 0)throw new e.r(`Decryption returned no value for handle ${i}`);return x(a,`balanceOf: result[handle]`),a}async confidentialBalanceOf(e){let t=e?(0,n.getAddress)(e):await this.sdk.signer.getAddress();return this.readConfidentialBalanceOf(t)}async isConfidential(){return this.sdk.signer.readContract(t.f(this.address,t.c))}async isWrapper(){return this.sdk.signer.readContract(t.f(this.address,t.l))}static async batchBalancesOf(t,n){let i=new Map,a=new Map;if(t.length===0)return{results:i,errors:a};await r.assertSameSdk(t).allow(t.map(e=>e.address));let o=await N(t.map(e=>async()=>{try{return{status:`fulfilled`,value:await e.balanceOf(n)}}catch(e){return{status:`rejected`,reason:e}}}),5);for(let n=0;n<t.length;n++){let r=t[n].address,s=o[n];if(s.status===`fulfilled`)i.set(r,s.value);else{let t=s.reason;if(ee(t))throw t;let n=t instanceof e.a?t:new e.r(S(t).message,{cause:t});a.set(r,n)}}if(a.size===t.length)throw a.values().next().value??new e.r(`All token balance decryptions failed`);return{results:i,errors:a}}static async batchDecryptBalancesAs(t,n){if(t.length===0)return new Map;let{delegatorAddress:i,handles:a,owner:o,onError:s,maxConcurrency:c}=n,l=o??i,u=t[0];r.assertSameSdk(t);let d=a??await Promise.all(t.map(e=>e.readConfidentialBalanceOf(l)));if(t.length!==d.length)throw new e.r(`tokens.length (${t.length}) must equal handles.length (${d.length})`);let f=new Map,p=[],m=await Promise.all(t.map(async(e,t)=>{let n=d[t];return w(n)?0n:u.sdk.cache.get(l,e.address,n)}));for(let e=0;e<t.length;e++){let n=t[e],r=d[e],i=m[e];if(i!=null){x(i,`batchDecryptBalancesAs: cached`),f.set(n.address,i);continue}p.push({token:n,handle:r})}if(p.length===0)return f;await u.#e(i);let h=p.map(e=>e.token.address),g=await u.sdk.delegatedCredentials.allow(i,...h),_=[],v=[];for(let{token:t,handle:n}of p)v.push(()=>u.sdk.relayer.delegatedUserDecrypt({handles:[n],contractAddress:t.address,signedContractAddresses:g.contractAddresses,privateKey:g.privateKey,publicKey:g.publicKey,signature:g.signature,delegatorAddress:g.delegatorAddress,delegateAddress:g.delegateAddress,startTimestamp:g.startTimestamp,durationDays:g.durationDays}).then(async r=>{let i=r[n];if(i===void 0)throw new e.r(`Batch delegated decryption returned no value for handle ${n} on token ${t.address}`);x(i,`batchDecryptBalancesAs: result[handle]`),f.set(t.address,i),u.sdk.cache.set(l,t.address,n,i).catch(e=>{console.warn(`[zama-sdk] Failed to cache decrypted value:`,e)})}).catch(e=>{if(ee(e))throw e;let n=S(e);if(s)try{f.set(t.address,s(n,t.address))}catch(e){_.push({address:t.address,error:S(e)})}else _.push({address:t.address,error:n})}));if(await N(v,c),_.length>0){let t=_.map(e=>`${e.address}: ${e.error.message}`).join(`; `);throw new e.r(`Batch delegated decryption failed for ${_.length} token(s): ${t}`,{cause:_[0].error})}return f}async underlyingToken(){return this.sdk.signer.readContract(t.T(this.address))}async allowance(e,r){let i=(0,n.getAddress)(e),a=await this.sdk.signer.readContract(t.T(i)),o=r?(0,n.getAddress)(r):await this.sdk.signer.getAddress();return this.sdk.signer.readContract(O(a,o,i))}async name(){return this.sdk.signer.readContract(T(this.address))}async symbol(){return this.sdk.signer.readContract(E(this.address))}async decimals(){return this.sdk.signer.readContract(D(this.address))}async allow(){await this.sdk.allow([this.address])}async isAllowed(){return this.sdk.credentials.isAllowed([this.address])}async revoke(...e){await this.sdk.credentials.revoke(...e)}static async allow(...e){e.length!==0&&await r.assertSameSdk(e).allow(e.map(e=>e.address))}async getAclAddress(){return this.sdk.relayer.getAclAddress()}async isDelegated(e){let t=await this.getDelegationExpiry(e);return t===0n?!1:t===j?!0:t>await this.sdk.signer.getBlockTimestamp()}async getDelegationExpiry({delegatorAddress:e,delegateAddress:t}){let r=await this.getAclAddress();return this.sdk.signer.readContract(A(r,(0,n.getAddress)(e),(0,n.getAddress)(t),this.address))}async#e(e){let t=await this.sdk.signer.getAddress(),n=await this.getDelegationExpiry({delegatorAddress:e,delegateAddress:t});if(n===0n)throw new d(`No active delegation from ${e} to ${t} for ${this.address}`);if(n!==j&&n<=await this.sdk.signer.getBlockTimestamp())throw new f(`Delegation from ${e} to ${t} for ${this.address} has expired`)}async readConfidentialBalanceOf(e){return await this.sdk.signer.readContract(t.p(this.address,e))}async decryptBalanceAs({delegatorAddress:t,owner:r}){let i=(0,n.getAddress)(t),a=r?(0,n.getAddress)(r):i,o=await this.readConfidentialBalanceOf(a);if(w(o))return 0n;let s=await this.sdk.cache.get(a,this.address,o);if(s!==null)return x(s,`decryptBalanceAs: cached`),s;await this.#e(i);let c=Date.now();try{this.emit({type:M.DecryptStart,handles:[o]});let t=await this.sdk.delegatedCredentials.allow(i,this.address),n=await this.sdk.relayer.delegatedUserDecrypt({handles:[o],contractAddress:this.address,signedContractAddresses:t.contractAddresses,privateKey:t.privateKey,publicKey:t.publicKey,signature:t.signature,delegatorAddress:t.delegatorAddress,delegateAddress:t.delegateAddress,startTimestamp:t.startTimestamp,durationDays:t.durationDays}),r=n[o];if(r===void 0)throw new e.r(`Delegated decryption returned no value for handle ${o}`);return x(r,`decryptBalanceAs: result[handle]`),this.emit({type:M.DecryptEnd,durationMs:Date.now()-c,handles:[o],result:n}),await this.sdk.cache.set(a,this.address,o,r),r}catch(e){throw this.emit({type:M.DecryptError,error:S(e),durationMs:Date.now()-c,handles:[o]}),y(e,`Failed to decrypt delegated balance`,!0)}}emit(e){this.sdk.emitEvent(e,this.address)}static assertSameSdk(t){let n=t[0].sdk;for(let r=1;r<t.length;r++)if(t[r].sdk!==n)throw new e.t(`All tokens in a batch operation must share the same ZamaSDK instance`);return n}};function P(e){return(0,n.keccak256)((0,n.toBytes)(e))}const F={ConfidentialTransfer:P(`ConfidentialTransfer(address,address,bytes32)`),Wrapped:P(`Wrapped(address,uint256)`),UnwrapRequested:P(`UnwrapRequested(address,bytes32,bytes32)`),UnwrappedFinalized:P(`UnwrapFinalized(address,bytes32,bytes32,uint64)`),UnwrappedStarted:P(`UnwrappedStarted(bool,uint256,uint256,address,address,bytes32,bytes32)`)};function I(e){return(0,n.getAddress)(C(e.slice(-40)))}function L(e){return BigInt(e)}function R(e){return e}function z(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function B(e,t){return(0,n.getAddress)(C(z(e,t).slice(-40)))}function V(e,t){return BigInt(`0x`+z(e,t))}function ge(e,t){return BigInt(`0x`+z(e,t))!==0n}function H(e,t){return C(z(e,t))}function U(e){return e.topics[0]!==F.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:I(e.topics[1]),to:I(e.topics[2]),encryptedAmountHandle:R(e.topics[3])}}function W(e){return e.topics[0]!==F.Wrapped||e.topics.length<2?null:{eventName:`Wrapped`,to:I(e.topics[1]),amountIn:V(e.data,0)}}function G(e){return e.topics[0]!==F.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:I(e.topics[1]),unwrapRequestId:R(e.topics[2]),encryptedAmount:H(e.data,0)}}function K(e){return e.topics[0]!==F.UnwrappedFinalized||e.topics.length<3?null:{eventName:`UnwrappedFinalized`,receiver:I(e.topics[1]),unwrapRequestId:R(e.topics[2]),encryptedAmount:H(e.data,0),cleartextAmount:V(e.data,1)}}function q(e){return e.topics[0]!==F.UnwrappedStarted||e.topics.length<4?null:{eventName:`UnwrappedStarted`,requestId:L(e.topics[1]),txId:L(e.topics[2]),to:I(e.topics[3]),returnVal:ge(e.data,0),refund:B(e.data,1),requestedAmount:H(e.data,2),burnAmount:H(e.data,3)}}function J(e){return U(e)??W(e)??G(e)??K(e)??q(e)}function _e(e){let t=[];for(let n of e){let e=J(n);e&&t.push(e)}return t}function ve(e){for(let t of e){let e=G(t);if(e)return e}return null}function ye(e){for(let t of e){let e=W(t);if(e)return e}return null}const be=[F.ConfidentialTransfer,F.Wrapped,F.UnwrapRequested,F.UnwrappedFinalized,F.UnwrappedStarted],Y={DelegatedForUserDecryption:`0x527b025d7ff06689c1ab9d32dfd7881c964cce72ce8ac5b2fe1d3be8cfda5bfc`,RevokedDelegationForUserDecryption:`0x7aca80b6b7928b9038f186e3d9922a0fc5d52c398fbf144725c142c52a5277e4`};function X(e){return e.topics[0]!==Y.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:I(e.topics[1]),delegate:I(e.topics[2]),contractAddress:B(e.data,0),delegationCounter:V(e.data,1),oldExpirationDate:V(e.data,2),newExpirationDate:V(e.data,3)}}function Z(e){return e.topics[0]!==Y.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:I(e.topics[1]),delegate:I(e.topics[2]),contractAddress:B(e.data,0),delegationCounter:V(e.data,1),oldExpirationDate:V(e.data,2)}}function xe(e){return X(e)??Z(e)}function Se(e){let t=[];for(let n of e){let e=xe(n);e&&t.push(e)}return t}function Ce(e){for(let t of e){let e=X(t);if(e)return e}return null}function we(e){for(let t of e){let e=Z(t);if(e)return e}return null}const Te=[Y.DelegatedForUserDecryption,Y.RevokedDelegationForUserDecryption];function Q(e,t){return e.toLowerCase()===t.toLowerCase()}function $(e,t,n){let r=t!==void 0&&Q(e,t),i=n!==void 0&&Q(e,n);return r&&i?`self`:r?`outgoing`:`incoming`}function Ee(e,t,n){switch(e.eventName){case`ConfidentialTransfer`:return De(e,t,n);case`Wrapped`:return Oe(e,t,n);case`UnwrapRequested`:return ke(e,t,n);case`UnwrappedStarted`:return Ae(e,t,n);case`UnwrappedFinalized`:return je(e,t,n);default:throw Error(`Unknown event: ${e.eventName}`)}}function De(e,t,n){return{type:`transfer`,direction:$(t,e.from,e.to),amount:{type:`encrypted`,handle:e.encryptedAmountHandle},from:e.from,to:e.to,metadata:n,rawEvent:e}}function Oe(e,t,n){return{type:`shield`,direction:$(t,void 0,e.to),amount:{type:`clear`,value:e.amountIn},to:e.to,metadata:n,rawEvent:e}}function ke(e,t,n){return{type:`unshield_requested`,direction:$(t,void 0,e.receiver),amount:{type:`encrypted`,handle:e.encryptedAmount},to:e.receiver,metadata:n,rawEvent:e}}function Ae(e,t,n){return{type:`unshield_started`,direction:$(t,void 0,e.to),amount:{type:`encrypted`,handle:e.requestedAmount},to:e.to,success:e.returnVal,metadata:n,rawEvent:e}}function je(e,t,n){return{type:`unshield_finalized`,direction:$(t,void 0,e.receiver),amount:{type:`clear`,value:e.cleartextAmount},to:e.receiver,metadata:n,rawEvent:e}}function Me(e,t){let n=[];for(let r of e){let e=J(r);if(!e)continue;let i={transactionHash:r.transactionHash,blockNumber:r.blockNumber,logIndex:r.logIndex};n.push(Ee(e,t,i))}return n}function Ne(e){let t=new Set;for(let n of e)if(n.amount.type===`encrypted`&&n.amount.decryptedValue===void 0){let e=n.amount.handle;w(e)||t.add(e)}return[...t]}function Pe(e,t){return e.map(e=>{if(e.amount.type!==`encrypted`)return e;let n=t[e.amount.handle];return n===void 0?e:(x(n,`applyDecryptedValues: value`),{...e,amount:{type:`encrypted`,handle:e.amount.handle,decryptedValue:n}})})}function Fe(e){return[...e].toSorted((e,t)=>{let n=e.metadata.blockNumber,r=t.metadata.blockNumber;if(n===void 0&&r===void 0)return 0;if(n===void 0)return-1;if(r===void 0)return 1;let i=typeof n==`bigint`?n:BigInt(n),a=typeof r==`bigint`?r:BigInt(r);if(a>i)return 1;if(a<i)return-1;let o=e.metadata.logIndex??0;return(t.metadata.logIndex??0)-o})}Object.defineProperty(exports,`$`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`A`,{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,`B`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,`D`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`E`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`F`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`G`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`H`,{enumerable:!0,get:function(){return ce}}),Object.defineProperty(exports,`I`,{enumerable:!0,get:function(){return le}}),Object.defineProperty(exports,`J`,{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,`K`,{enumerable:!0,get:function(){return se}}),Object.defineProperty(exports,`L`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`M`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`N`,{enumerable:!0,get:function(){return de}}),Object.defineProperty(exports,`O`,{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,`P`,{enumerable:!0,get:function(){return ue}}),Object.defineProperty(exports,`Q`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`R`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,`T`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`U`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`V`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`W`,{enumerable:!0,get:function(){return re}}),Object.defineProperty(exports,`X`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`Y`,{enumerable:!0,get:function(){return ne}}),Object.defineProperty(exports,`Z`,{enumerable:!0,get:function(){return ae}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return Te}}),Object.defineProperty(exports,`at`,{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return F}}),Object.defineProperty(exports,`ct`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,`dt`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`et`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,`ft`,{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return G}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return Fe}}),Object.defineProperty(exports,`it`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`j`,{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,`k`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,`lt`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,`mt`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return Ne}}),Object.defineProperty(exports,`nt`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,`ot`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,`pt`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`q`,{enumerable:!0,get:function(){return oe}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,`rt`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,`st`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,`tt`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return Se}}),Object.defineProperty(exports,`ut`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,`w`,{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,`z`,{enumerable:!0,get:function(){return`0x0000000000000000000000000000000000000000000000000000000000000000`}});
|
|
2
2
|
//# sourceMappingURL=activity.cjs.map
|