@aave/client 4.0.0-next.21 → 4.0.0-next.22

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.
Files changed (49) hide show
  1. package/dist/{AaveClient-C36zcfbL.d.ts → AaveClient-BjSHF3YP.d.ts} +1 -1
  2. package/dist/{AaveClient-BIfAdE-4.d.cts → AaveClient-xmYaeYSl.d.cts} +1 -1
  3. package/dist/actions/index.cjs +1 -1
  4. package/dist/actions/index.cjs.map +1 -1
  5. package/dist/actions/index.d.cts +4 -26
  6. package/dist/actions/index.d.ts +4 -26
  7. package/dist/actions/index.js +1 -1
  8. package/dist/chunk-IDO2PFSI.js +2 -0
  9. package/dist/chunk-IDO2PFSI.js.map +1 -0
  10. package/dist/chunk-Y6WK5HED.js +3 -0
  11. package/dist/chunk-Y6WK5HED.js.map +1 -0
  12. package/dist/ethers.cjs +1 -1
  13. package/dist/ethers.cjs.map +1 -1
  14. package/dist/ethers.d.cts +33 -12
  15. package/dist/ethers.d.ts +33 -12
  16. package/dist/ethers.js +1 -1
  17. package/dist/ethers.js.map +1 -1
  18. package/dist/index.cjs +2 -2
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +2 -2
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +2 -2
  23. package/dist/index.js.map +1 -1
  24. package/dist/privy.cjs +2 -2
  25. package/dist/privy.cjs.map +1 -1
  26. package/dist/privy.d.cts +35 -12
  27. package/dist/privy.d.ts +35 -12
  28. package/dist/privy.js +1 -1
  29. package/dist/privy.js.map +1 -1
  30. package/dist/testing.js +13 -13
  31. package/dist/testing.js.map +1 -1
  32. package/dist/thirdweb.cjs +1 -1
  33. package/dist/thirdweb.cjs.map +1 -1
  34. package/dist/thirdweb.d.cts +34 -13
  35. package/dist/thirdweb.d.ts +34 -13
  36. package/dist/thirdweb.js +1 -1
  37. package/dist/thirdweb.js.map +1 -1
  38. package/dist/{types-CQvue0x0.d.cts → types-fGKXqIpf.d.cts} +8 -5
  39. package/dist/{types-CQvue0x0.d.ts → types-fGKXqIpf.d.ts} +8 -5
  40. package/dist/viem.cjs +2 -2
  41. package/dist/viem.cjs.map +1 -1
  42. package/dist/viem.d.cts +34 -17
  43. package/dist/viem.d.ts +34 -17
  44. package/dist/viem.js +1 -1
  45. package/package.json +2 -2
  46. package/dist/chunk-3HZQC3YV.js +0 -3
  47. package/dist/chunk-3HZQC3YV.js.map +0 -1
  48. package/dist/chunk-MKZBFAXA.js +0 -2
  49. package/dist/chunk-MKZBFAXA.js.map +0 -1
package/dist/privy.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { ExecutionPlan, SwapTypedData } from '@aave/graphql';
1
+ import { ExecutionPlan, ERC20PermitSignature } from '@aave/graphql';
2
+ import { ResultAsync, Signature } from '@aave/types';
2
3
  import { PrivyClient } from '@privy-io/server-auth';
3
- import { E as ExecutionPlanHandler, a as ERC20PermitHandler, S as SwapSignatureHandler } from './types-CQvue0x0.js';
4
+ import { E as ExecutionPlanHandler, S as SignTypedDataError, a as TypedData } from './types-fGKXqIpf.js';
4
5
  import '@aave/core';
5
- import '@aave/types';
6
6
 
7
7
  /**
8
8
  * Creates an execution plan handler that sends transactions using the specified Privy wallet.
@@ -13,16 +13,39 @@ declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(privy: PrivyC
13
13
  */
14
14
  declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(privy: PrivyClient, walletId: string, result: T): ReturnType<ExecutionPlanHandler<T>>;
15
15
  /**
16
- * Creates an ERC20 permit handler that signs ERC20 permits using the specified Privy wallet.
16
+ * Handles ERC20 permit signing for actions that require token approval.
17
+ *
18
+ * Calls the action to get an initial execution plan. If the plan requires ERC20 approval
19
+ * and the token supports permit signatures, signs the permit and re-calls the action
20
+ * with the signature to get a new plan that can be sent directly.
21
+ *
22
+ * ```ts
23
+ * const result = await permitWith(privy, walletId, (permitSig) =>
24
+ * supply(client, {
25
+ * reserve: reserve.id,
26
+ * amount: { erc20: { value: amount, permitSig } },
27
+ * sender: evmAddress(walletAddress),
28
+ * })
29
+ * )
30
+ * .andThen(sendWith(privy, walletId))
31
+ * .andThen(client.waitForTransaction);
32
+ * ```
33
+ *
34
+ * @param privy - The Privy client for signing permits.
35
+ * @param walletId - The ID of the Privy wallet to use.
36
+ * @param action - A function that returns an execution plan, accepting an optional permit signature.
37
+ * @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.
17
38
  */
18
- declare function signERC20PermitWith(privy: PrivyClient, walletId: string): ERC20PermitHandler;
39
+ declare function permitWith<E>(privy: PrivyClient, walletId: string, action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>): ResultAsync<ExecutionPlan, E | SignTypedDataError>;
19
40
  /**
20
- * Creates a swap signature handler that signs swap typed data using the specified Privy wallet.
41
+ * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.
42
+ * Returns the raw signature without any wrapping. Deadline encapsulation is handled by consumer code.
43
+ *
44
+ * @param privy - The Privy client instance.
45
+ * @param walletId - The wallet ID to use for signing.
46
+ * @param data - The typed data to sign.
47
+ * @returns A ResultAsync containing the raw signature.
21
48
  */
22
- declare function signSwapTypedDataWith(privy: PrivyClient, walletId: string): SwapSignatureHandler;
23
- /**
24
- * Signs swap typed data using the specified Privy wallet.
25
- */
26
- declare function signSwapTypedDataWith(privy: PrivyClient, walletId: string, result: SwapTypedData): ReturnType<SwapSignatureHandler>;
49
+ declare function signTypedDataWith(privy: PrivyClient, walletId: string, data: TypedData): ResultAsync<Signature, SignTypedDataError>;
27
50
 
28
- export { sendWith, signERC20PermitWith, signSwapTypedDataWith };
51
+ export { permitWith, sendWith, signTypedDataWith };
package/dist/privy.js CHANGED
@@ -1,2 +1,2 @@
1
- import {a,f}from'./chunk-3HZQC3YV.js';import'./chunk-MKZBFAXA.js';import {ValidationError,SigningError}from'@aave/core';import {errAsync,ResultAsync,signatureFrom,txHash,okAsync}from'@aave/types';import {createPublicClient,http}from'viem';import {waitForTransactionReceipt}from'viem/actions';async function E(a,n,t){let{hash:e}=await a.walletApi.ethereum.sendTransaction({walletId:t,caip2:`eip155:${n.chainId}`,transaction:{from:n.from,to:n.to,value:`0x${BigInt(n.value).toString(16)}`,chainId:n.chainId,data:n.data}});return txHash(e)}function o(a$1,n,t){let e=createPublicClient({chain:a[n.chainId],transport:http()});return ResultAsync.fromPromise(E(a$1,n,t),r=>SigningError.from(r)).map(async r=>waitForTransactionReceipt(e,{hash:r,pollingInterval:100,retryCount:20,retryDelay:50})).andThen(r=>{let c=txHash(r.transactionHash);return r.status==="reverted"?errAsync(f(a[n.chainId],c,n)):okAsync({txHash:c,operations:n.operations})})}function d(a,n,t){switch(t.__typename){case "TransactionRequest":return o(a,t,n);case "Erc20ApprovalRequired":case "PreContractActionRequired":return o(a,t.transaction,n).andThen(()=>o(a,t.originalTransaction,n));case "InsufficientBalanceError":return errAsync(ValidationError.fromGqlNode(t))}}function D(a,n,t){return t?d(a,n,t):d.bind(null,a,n)}function R(a,n,t){return ResultAsync.fromPromise(a.walletApi.ethereum.signTypedData({walletId:n,typedData:{domain:t.domain,types:t.types,message:t.message,primaryType:t.primaryType}}),e=>SigningError.from(e)).map(e=>({deadline:t.message.deadline,value:signatureFrom(e.signature)}))}function A(a,n){return R.bind(null,a,n)}function y(a,n,t){return ResultAsync.fromPromise(a.walletApi.ethereum.signTypedData({walletId:n,typedData:{domain:t.domain,types:t.types,message:t.message,primaryType:t.primaryType}}),e=>SigningError.from(e)).map(({signature:e})=>signatureFrom(e))}function I(a,n,t){return t?y(a,n,t):y.bind(null,a,n)}export{D as sendWith,A as signERC20PermitWith,I as signSwapTypedDataWith};//# sourceMappingURL=privy.js.map
1
+ import {a,f as f$1}from'./chunk-Y6WK5HED.js';import'./chunk-IDO2PFSI.js';import {ValidationError,SigningError}from'@aave/core';import {okAsync,signatureFrom,errAsync,ResultAsync,txHash}from'@aave/types';import {createPublicClient,http}from'viem';import {waitForTransactionReceipt}from'viem/actions';async function x(r,n,t){let{hash:a}=await r.walletApi.ethereum.sendTransaction({walletId:t,caip2:`eip155:${n.chainId}`,transaction:{from:n.from,to:n.to,value:`0x${BigInt(n.value).toString(16)}`,chainId:n.chainId,data:n.data}});return txHash(a)}function o(r,n,t){let a$1=createPublicClient({chain:a[n.chainId],transport:http()});return ResultAsync.fromPromise(x(r,n,t),e=>SigningError.from(e)).map(async e=>waitForTransactionReceipt(a$1,{hash:e,pollingInterval:100,retryCount:20,retryDelay:50})).andThen(e=>{let i=txHash(e.transactionHash);return e.status==="reverted"?errAsync(f$1(a[n.chainId],i,n)):okAsync({txHash:i,operations:n.operations})})}function p(r,n,t){switch(t.__typename){case "TransactionRequest":return o(r,t,n);case "Erc20ApprovalRequired":return o(r,t.approval.byTransaction,n).andThen(()=>o(r,t.originalTransaction,n));case "PreContractActionRequired":return o(r,t.transaction,n).andThen(()=>o(r,t.originalTransaction,n));case "InsufficientBalanceError":return errAsync(ValidationError.fromGqlNode(t))}}function H(r,n,t){return t?p(r,n,t):p.bind(null,r,n)}function b(r,n,t){return t().andThen(a=>{if(a.__typename==="Erc20ApprovalRequired"&&a.approval.bySignature){let e=a.approval.bySignature;return R(r,n,e).map(i=>({deadline:e.message.deadline,value:i})).andThen(i=>t(i))}return okAsync(a)})}function f(r,n,t){return ResultAsync.fromPromise(r.walletApi.ethereum.signTypedData({walletId:n,typedData:{domain:t.domain,types:t.types,message:t.message,primaryType:t.primaryType}}),a=>SigningError.from(a)).map(a=>a.signature)}function R(r,n,t){return f(r,n,t).map(signatureFrom)}export{b as permitWith,H as sendWith,R as signTypedDataWith};//# sourceMappingURL=privy.js.map
2
2
  //# sourceMappingURL=privy.js.map
package/dist/privy.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/privy.ts"],"names":["sendTransaction","privy","request","walletId","hash","txHash","sendTransactionAndWait","publicClient","createPublicClient","supportedChains","http","ResultAsync","err","SigningError","waitForTransactionReceipt","receipt","errAsync","transactionError","okAsync","executePlan","result","ValidationError","sendWith","signERC20Permit","response","signatureFrom","signERC20PermitWith","signSwapTypedData","signature","signSwapTypedDataWith"],"mappings":"oSA8BA,eAAeA,CAAAA,CACbC,CAAAA,CACAC,EACAC,CAAAA,CACiB,CACjB,GAAM,CAAE,IAAA,CAAAC,CAAK,CAAA,CAAI,MAAMH,EAAM,SAAA,CAAU,QAAA,CAAS,gBAAgB,CAC9D,QAAA,CAAAE,CAAAA,CACA,KAAA,CAAO,UAAUD,CAAAA,CAAQ,OAAO,GAChC,WAAA,CAAa,CACX,KAAMA,CAAAA,CAAQ,IAAA,CACd,GAAIA,CAAAA,CAAQ,EAAA,CACZ,MAAO,CAAA,EAAA,EAAK,MAAA,CAAOA,EAAQ,KAAK,CAAA,CAAE,SAAS,EAAE,CAAC,GAC9C,OAAA,CAASA,CAAAA,CAAQ,QACjB,IAAA,CAAMA,CAAAA,CAAQ,IAChB,CACF,CAAC,EACD,OAAOG,MAAAA,CAAOD,CAAI,CACpB,CAEA,SAASE,CAAAA,CACPL,GAAAA,CACAC,EACAC,CAAAA,CACiE,CAGjE,IAAMI,CAAAA,CAAeC,kBAAAA,CAAmB,CACtC,KAAA,CAAOC,EAAgBP,CAAAA,CAAQ,OAAO,EACtC,SAAA,CAAWQ,IAAAA,EACb,CAAC,CAAA,CAED,OAAOC,WAAAA,CAAY,WAAA,CACjBX,EAAgBC,GAAAA,CAAOC,CAAAA,CAASC,CAAQ,CAAA,CACvCS,CAAAA,EAAQC,aAAa,IAAA,CAAKD,CAAG,CAChC,CAAA,CACG,GAAA,CAAI,MAAOR,CAAAA,EACVU,yBAAAA,CAA0BP,EAAc,CACtC,IAAA,CAAAH,EACA,eAAA,CAAiB,GAAA,CACjB,WAAY,EAAA,CACZ,UAAA,CAAY,EACd,CAAC,CACH,EACC,OAAA,CAASW,CAAAA,EAAY,CACpB,IAAMX,CAAAA,CAAOC,MAAAA,CAAOU,CAAAA,CAAQ,eAAe,CAAA,CAE3C,OAAIA,EA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E,IAAKY,CAAAA,GAAc,CACnB,QAAA,CAAUJ,CAAAA,CAAO,QAAQ,QAAA,CACzB,KAAA,CAAOK,cAAcD,CAAAA,CAAS,SAAS,CACzC,CAAA,CAAE,CACJ,CAKO,SAASE,CAAAA,CACdzB,EACAE,CAAAA,CACoB,CACpB,OAAOoB,CAAAA,CAAgB,IAAA,CAAK,KAAMtB,CAAAA,CAAOE,CAAQ,CACnD,CAEA,SAASwB,EACP1B,CAAAA,CACAE,CAAAA,CACAiB,EACkC,CAClC,OAAOT,YAAY,WAAA,CACjBV,CAAAA,CAAM,UAAU,QAAA,CAAS,aAAA,CAAc,CACrC,QAAA,CAAAE,CAAAA,CACA,UAAW,CACT,MAAA,CAAQiB,EAAO,MAAA,CACf,KAAA,CAAOA,EAAO,KAAA,CACd,OAAA,CAASA,EAAO,OAAA,CAChB,WAAA,CAAaA,EAAO,WACtB,CACF,CAAC,CAAA,CACAR,CAAAA,EAAQC,aAAa,IAAA,CAAKD,CAAG,CAChC,CAAA,CAAE,GAAA,CAAI,CAAC,CAAE,SAAA,CAAAgB,CAAU,CAAA,GAAMH,aAAAA,CAAcG,CAAS,CAAC,CACnD,CAiBO,SAASC,CAAAA,CACd5B,EACAE,CAAAA,CACAiB,CAAAA,CACyD,CACzD,OAAOA,CAAAA,CACHO,EAAkB1B,CAAAA,CAAOE,CAAAA,CAAUiB,CAAM,CAAA,CACzCO,CAAAA,CAAkB,KAAK,IAAA,CAAM1B,CAAAA,CAAOE,CAAQ,CAClD","file":"privy.js","sourcesContent":["import {\n SigningError,\n type TransactionError,\n ValidationError,\n} from '@aave/core';\nimport type {\n ExecutionPlan,\n PermitTypedDataResponse,\n SwapTypedData,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n errAsync,\n okAsync,\n ResultAsync,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport type { PrivyClient } from '@privy-io/server-auth';\nimport { createPublicClient, http } from 'viem';\nimport { waitForTransactionReceipt } from 'viem/actions';\nimport type {\n ERC20PermitHandler,\n ExecutionPlanHandler,\n SwapSignatureHandler,\n TransactionResult,\n} from './types';\nimport { supportedChains, transactionError } from './viem';\n\nasync function sendTransaction(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): Promise<TxHash> {\n const { hash } = await privy.walletApi.ethereum.sendTransaction({\n walletId,\n caip2: `eip155:${request.chainId}`,\n transaction: {\n from: request.from,\n to: request.to,\n value: `0x${BigInt(request.value).toString(16)}`,\n chainId: request.chainId,\n data: request.data,\n },\n });\n return txHash(hash);\n}\n\nfunction sendTransactionAndWait(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): ResultAsync<TransactionResult, SigningError | TransactionError> {\n // TODO: verify it's on the correct chain, ask to switch if possible\n // TODO: verify if wallet account is correct, switch if possible\n const publicClient = createPublicClient({\n chain: supportedChains[request.chainId],\n transport: http(),\n });\n\n return ResultAsync.fromPromise(\n sendTransaction(privy, request, walletId),\n (err) => SigningError.from(err),\n )\n .map(async (hash) =>\n waitForTransactionReceipt(publicClient, {\n hash,\n pollingInterval: 100,\n retryCount: 20,\n retryDelay: 50,\n }),\n )\n .andThen((receipt) => {\n const hash = txHash(receipt.transactionHash);\n\n if (receipt.status === 'reverted') {\n return errAsync(\n transactionError(supportedChains[request.chainId], hash, request),\n );\n }\n return okAsync({\n txHash: hash,\n operations: request.operations,\n });\n });\n}\n\nfunction executePlan(\n privy: PrivyClient,\n walletId: string,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(privy, result, walletId);\n\n case 'Erc20ApprovalRequired':\n case 'PreContractActionRequired':\n return sendTransactionAndWait(\n privy,\n result.transaction,\n walletId,\n ).andThen(() =>\n sendTransactionAndWait(privy, result.originalTransaction, walletId),\n );\n\n case 'InsufficientBalanceError':\n return errAsync(ValidationError.fromGqlNode(result));\n }\n}\n\n/**\n * Creates an execution plan handler that sends transactions using the specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(privy, walletId, result)\n : executePlan.bind(null, privy, walletId);\n}\n\nfunction signERC20Permit(\n privy: PrivyClient,\n walletId: string,\n result: PermitTypedDataResponse,\n): ReturnType<ERC20PermitHandler> {\n return ResultAsync.fromPromise(\n privy.walletApi.ethereum.signTypedData({\n walletId,\n typedData: {\n domain: result.domain,\n types: result.types,\n message: result.message,\n primaryType: result.primaryType,\n },\n }),\n (err) => SigningError.from(err),\n ).map((response) => ({\n deadline: result.message.deadline,\n value: signatureFrom(response.signature),\n }));\n}\n\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the specified Privy wallet.\n */\nexport function signERC20PermitWith(\n privy: PrivyClient,\n walletId: string,\n): ERC20PermitHandler {\n return signERC20Permit.bind(null, privy, walletId);\n}\n\nfunction signSwapTypedData(\n privy: PrivyClient,\n walletId: string,\n result: SwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n return ResultAsync.fromPromise(\n privy.walletApi.ethereum.signTypedData({\n walletId,\n typedData: {\n domain: result.domain,\n types: result.types,\n message: result.message,\n primaryType: result.primaryType,\n },\n }),\n (err) => SigningError.from(err),\n ).map(({ signature }) => signatureFrom(signature));\n}\n\n/**\n * Creates a swap signature handler that signs swap typed data using the specified Privy wallet.\n */\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n): SwapSignatureHandler;\n/**\n * Signs swap typed data using the specified Privy wallet.\n */\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n result: SwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n result?: SwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(privy, walletId, result)\n : signSwapTypedData.bind(null, privy, walletId);\n}\n"]}
1
+ {"version":3,"sources":["../src/privy.ts"],"names":["sendTransaction","privy","request","walletId","hash","txHash","sendTransactionAndWait","publicClient","createPublicClient","supportedChains","http","ResultAsync","err","SigningError","waitForTransactionReceipt","receipt","errAsync","transactionError","okAsync","executePlan","result","ValidationError","sendWith","permitWith","action","permitTypedData","signTypedDataWith","signature","permitSig","signTypedData","data","response","signatureFrom"],"mappings":"2SA8BA,eAAeA,CAAAA,CACbC,EACAC,CAAAA,CACAC,CAAAA,CACiB,CACjB,GAAM,CAAE,KAAAC,CAAK,CAAA,CAAI,MAAMH,CAAAA,CAAM,SAAA,CAAU,SAAS,eAAA,CAAgB,CAC9D,QAAA,CAAAE,CAAAA,CACA,MAAO,CAAA,OAAA,EAAUD,CAAAA,CAAQ,OAAO,CAAA,CAAA,CAChC,WAAA,CAAa,CACX,IAAA,CAAMA,CAAAA,CAAQ,KACd,EAAA,CAAIA,CAAAA,CAAQ,GACZ,KAAA,CAAO,CAAA,EAAA,EAAK,OAAOA,CAAAA,CAAQ,KAAK,EAAE,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA,CAC9C,OAAA,CAASA,EAAQ,OAAA,CACjB,IAAA,CAAMA,EAAQ,IAChB,CACF,CAAC,CAAA,CACD,OAAOG,OAAOD,CAAI,CACpB,CAEA,SAASE,CAAAA,CACPL,EACAC,CAAAA,CACAC,CAAAA,CACiE,CAGjE,IAAMI,GAAAA,CAAeC,kBAAAA,CAAmB,CACtC,MAAOC,CAAAA,CAAgBP,CAAAA,CAAQ,OAAO,CAAA,CACtC,SAAA,CAAWQ,MACb,CAAC,EAED,OAAOC,WA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U2B,CAAI,CAAA,CAAE,GAAA,CAAIE,aAAa,CAC/D","file":"privy.js","sourcesContent":["import {\n SigningError,\n type TransactionError,\n ValidationError,\n} from '@aave/core';\nimport type {\n ERC20PermitSignature,\n ExecutionPlan,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n errAsync,\n okAsync,\n ResultAsync,\n type Signature,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport type { PrivyClient } from '@privy-io/server-auth';\nimport { createPublicClient, http } from 'viem';\nimport { waitForTransactionReceipt } from 'viem/actions';\nimport type {\n ExecutionPlanHandler,\n SignTypedDataError,\n TransactionResult,\n TypedData,\n} from './types';\nimport { supportedChains, transactionError } from './viem';\n\nasync function sendTransaction(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): Promise<TxHash> {\n const { hash } = await privy.walletApi.ethereum.sendTransaction({\n walletId,\n caip2: `eip155:${request.chainId}`,\n transaction: {\n from: request.from,\n to: request.to,\n value: `0x${BigInt(request.value).toString(16)}`,\n chainId: request.chainId,\n data: request.data,\n },\n });\n return txHash(hash);\n}\n\nfunction sendTransactionAndWait(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): ResultAsync<TransactionResult, SigningError | TransactionError> {\n // TODO: verify it's on the correct chain, ask to switch if possible\n // TODO: verify if wallet account is correct, switch if possible\n const publicClient = createPublicClient({\n chain: supportedChains[request.chainId],\n transport: http(),\n });\n\n return ResultAsync.fromPromise(\n sendTransaction(privy, request, walletId),\n (err) => SigningError.from(err),\n )\n .map(async (hash) =>\n waitForTransactionReceipt(publicClient, {\n hash,\n pollingInterval: 100,\n retryCount: 20,\n retryDelay: 50,\n }),\n )\n .andThen((receipt) => {\n const hash = txHash(receipt.transactionHash);\n\n if (receipt.status === 'reverted') {\n return errAsync(\n transactionError(supportedChains[request.chainId], hash, request),\n );\n }\n return okAsync({\n txHash: hash,\n operations: request.operations,\n });\n });\n}\n\nfunction executePlan(\n privy: PrivyClient,\n walletId: string,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(privy, result, walletId);\n\n case 'Erc20ApprovalRequired':\n return sendTransactionAndWait(\n privy,\n result.approval.byTransaction,\n walletId,\n ).andThen(() =>\n sendTransactionAndWait(privy, result.originalTransaction, walletId),\n );\n\n case 'PreContractActionRequired':\n return sendTransactionAndWait(\n privy,\n result.transaction,\n walletId,\n ).andThen(() =>\n sendTransactionAndWait(privy, result.originalTransaction, walletId),\n );\n\n case 'InsufficientBalanceError':\n return errAsync(ValidationError.fromGqlNode(result));\n }\n}\n\n/**\n * Creates an execution plan handler that sends transactions using the specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(privy, walletId, result)\n : executePlan.bind(null, privy, walletId);\n}\n\n/**\n * Handles ERC20 permit signing for actions that require token approval.\n *\n * Calls the action to get an initial execution plan. If the plan requires ERC20 approval\n * and the token supports permit signatures, signs the permit and re-calls the action\n * with the signature to get a new plan that can be sent directly.\n *\n * ```ts\n * const result = await permitWith(privy, walletId, (permitSig) =>\n * supply(client, {\n * reserve: reserve.id,\n * amount: { erc20: { value: amount, permitSig } },\n * sender: evmAddress(walletAddress),\n * })\n * )\n * .andThen(sendWith(privy, walletId))\n * .andThen(client.waitForTransaction);\n * ```\n *\n * @param privy - The Privy client for signing permits.\n * @param walletId - The ID of the Privy wallet to use.\n * @param action - A function that returns an execution plan, accepting an optional permit signature.\n * @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.\n */\nexport function permitWith<E>(\n privy: PrivyClient,\n walletId: string,\n action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>,\n): ResultAsync<ExecutionPlan, E | SignTypedDataError> {\n return action().andThen((result) => {\n if (\n result.__typename === 'Erc20ApprovalRequired' &&\n result.approval.bySignature\n ) {\n const permitTypedData = result.approval.bySignature;\n return signTypedDataWith(privy, walletId, permitTypedData)\n .map((signature) => ({\n deadline: permitTypedData.message.deadline,\n value: signature,\n }))\n .andThen((permitSig) => action(permitSig));\n }\n return okAsync(result);\n });\n}\n\nfunction signTypedData(\n privy: PrivyClient,\n walletId: string,\n data: TypedData,\n): ResultAsync<string, SigningError> {\n return ResultAsync.fromPromise(\n privy.walletApi.ethereum.signTypedData({\n walletId,\n typedData: {\n domain: data.domain,\n types: data.types,\n message: data.message,\n primaryType: data.primaryType,\n },\n }),\n (err) => SigningError.from(err),\n ).map((response) => response.signature);\n}\n\n/**\n * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.\n * Returns the raw signature without any wrapping. Deadline encapsulation is handled by consumer code.\n *\n * @param privy - The Privy client instance.\n * @param walletId - The wallet ID to use for signing.\n * @param data - The typed data to sign.\n * @returns A ResultAsync containing the raw signature.\n */\nexport function signTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n data: TypedData,\n): ResultAsync<Signature, SignTypedDataError> {\n return signTypedData(privy, walletId, data).map(signatureFrom);\n}\n"]}