@aave/client 4.0.0-next.3 → 4.0.0-next.30
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/README.md +6 -3
- package/dist/{AaveClient-L3v8kWvn.d.cts → AaveClient-1SYnTlsS.d.cts} +3 -1
- package/dist/{AaveClient-CgHY2iS9.d.ts → AaveClient-DGbooMqK.d.ts} +3 -1
- package/dist/actions/index.cjs +1 -1
- package/dist/actions/index.cjs.map +1 -1
- package/dist/actions/index.d.cts +245 -171
- package/dist/actions/index.d.ts +245 -171
- package/dist/actions/index.js +1 -1
- package/dist/chunk-35WSRP27.js +2 -0
- package/dist/chunk-35WSRP27.js.map +1 -0
- package/dist/chunk-BU2KVGJB.js +2 -0
- package/dist/chunk-BU2KVGJB.js.map +1 -0
- package/dist/ethers.cjs +1 -1
- package/dist/ethers.cjs.map +1 -1
- package/dist/ethers.d.cts +47 -13
- package/dist/ethers.d.ts +47 -13
- package/dist/ethers.js +1 -1
- package/dist/ethers.js.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/{options-vB2peXdE.d.cts → options-BX6n3sbh.d.cts} +17 -1
- package/dist/{options-vB2peXdE.d.ts → options-BX6n3sbh.d.ts} +17 -1
- package/dist/privy.cjs +1 -2
- package/dist/privy.cjs.map +1 -1
- package/dist/privy.d.cts +49 -12
- package/dist/privy.d.ts +49 -12
- package/dist/privy.js +1 -1
- package/dist/privy.js.map +1 -1
- package/dist/testing.d.ts +3842 -0
- package/dist/testing.js +546 -0
- package/dist/testing.js.map +1 -0
- package/dist/thirdweb.cjs +1 -2
- package/dist/thirdweb.cjs.map +1 -1
- package/dist/thirdweb.d.cts +55 -15
- package/dist/thirdweb.d.ts +55 -15
- package/dist/thirdweb.js +1 -2
- package/dist/thirdweb.js.map +1 -1
- package/dist/{types-Bu63z0x6.d.cts → types-4gDcMKeo.d.cts} +9 -5
- package/dist/{types-Bu63z0x6.d.ts → types-4gDcMKeo.d.ts} +9 -5
- package/dist/viem.cjs +1 -2
- package/dist/viem.cjs.map +1 -1
- package/dist/viem.d.cts +57 -17
- package/dist/viem.d.ts +57 -17
- package/dist/viem.js +1 -1
- package/package.json +10 -11
- package/dist/chunk-2URLJFKP.js +0 -3
- package/dist/chunk-2URLJFKP.js.map +0 -1
- package/dist/chunk-BQFM5RT3.js +0 -2
- package/dist/chunk-BQFM5RT3.js.map +0 -1
- package/dist/chunk-BQNVAUS6.js +0 -3
- package/dist/chunk-BQNVAUS6.js.map +0 -1
- package/dist/test-utils.cjs +0 -3
- package/dist/test-utils.cjs.map +0 -1
- package/dist/test-utils.d.cts +0 -49
- package/dist/test-utils.d.ts +0 -49
- package/dist/test-utils.js +0 -3
- package/dist/test-utils.js.map +0 -1
package/dist/privy.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ExecutionPlan,
|
|
1
|
+
import { ExecutionPlan, ERC20PermitSignature } from '@aave/graphql';
|
|
2
|
+
import { ResultAsync } from '@aave/types';
|
|
2
3
|
import { PrivyClient } from '@privy-io/server-auth';
|
|
3
|
-
import { E as ExecutionPlanHandler, a as
|
|
4
|
+
import { E as ExecutionPlanHandler, S as SignTypedDataError, a as TypedDataHandler, b as TypedData } from './types-4gDcMKeo.cjs';
|
|
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,18 +13,55 @@ 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
|
-
*
|
|
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
|
|
39
|
+
declare function permitWith<E>(privy: PrivyClient, walletId: string, action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>): ResultAsync<ExecutionPlan, E | SignTypedDataError>;
|
|
19
40
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
41
|
+
* Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.
|
|
42
|
+
*
|
|
43
|
+
* @param privy - The Privy client instance.
|
|
44
|
+
* @param walletId - The wallet ID to use for signing.
|
|
45
|
+
* @returns A function that takes typed data and returns a ResultAsync containing the raw signature.
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* const result = await prepareSwapCancel(client, request)
|
|
49
|
+
* .andThen(signTypedDataWith(privy, walletId));
|
|
50
|
+
* ```
|
|
22
51
|
*/
|
|
23
|
-
declare function
|
|
52
|
+
declare function signTypedDataWith(privy: PrivyClient, walletId: string): TypedDataHandler;
|
|
24
53
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
54
|
+
* Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.
|
|
55
|
+
*
|
|
56
|
+
* @param privy - The Privy client instance.
|
|
57
|
+
* @param walletId - The wallet ID to use for signing.
|
|
58
|
+
* @param data - The typed data to sign.
|
|
59
|
+
* @returns A ResultAsync containing the raw signature.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* const result = await signTypedDataWith(privy, walletId, typedData);
|
|
63
|
+
* ```
|
|
27
64
|
*/
|
|
28
|
-
declare function
|
|
65
|
+
declare function signTypedDataWith(privy: PrivyClient, walletId: string, data: TypedData): ReturnType<TypedDataHandler>;
|
|
29
66
|
|
|
30
|
-
export {
|
|
67
|
+
export { permitWith, sendWith, signTypedDataWith };
|
package/dist/privy.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ExecutionPlan,
|
|
1
|
+
import { ExecutionPlan, ERC20PermitSignature } from '@aave/graphql';
|
|
2
|
+
import { ResultAsync } from '@aave/types';
|
|
2
3
|
import { PrivyClient } from '@privy-io/server-auth';
|
|
3
|
-
import { E as ExecutionPlanHandler, a as
|
|
4
|
+
import { E as ExecutionPlanHandler, S as SignTypedDataError, a as TypedDataHandler, b as TypedData } from './types-4gDcMKeo.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,18 +13,55 @@ 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
|
-
*
|
|
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
|
|
39
|
+
declare function permitWith<E>(privy: PrivyClient, walletId: string, action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>): ResultAsync<ExecutionPlan, E | SignTypedDataError>;
|
|
19
40
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
41
|
+
* Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.
|
|
42
|
+
*
|
|
43
|
+
* @param privy - The Privy client instance.
|
|
44
|
+
* @param walletId - The wallet ID to use for signing.
|
|
45
|
+
* @returns A function that takes typed data and returns a ResultAsync containing the raw signature.
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* const result = await prepareSwapCancel(client, request)
|
|
49
|
+
* .andThen(signTypedDataWith(privy, walletId));
|
|
50
|
+
* ```
|
|
22
51
|
*/
|
|
23
|
-
declare function
|
|
52
|
+
declare function signTypedDataWith(privy: PrivyClient, walletId: string): TypedDataHandler;
|
|
24
53
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
54
|
+
* Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.
|
|
55
|
+
*
|
|
56
|
+
* @param privy - The Privy client instance.
|
|
57
|
+
* @param walletId - The wallet ID to use for signing.
|
|
58
|
+
* @param data - The typed data to sign.
|
|
59
|
+
* @returns A ResultAsync containing the raw signature.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* const result = await signTypedDataWith(privy, walletId, typedData);
|
|
63
|
+
* ```
|
|
27
64
|
*/
|
|
28
|
-
declare function
|
|
65
|
+
declare function signTypedDataWith(privy: PrivyClient, walletId: string, data: TypedData): ReturnType<TypedDataHandler>;
|
|
29
66
|
|
|
30
|
-
export {
|
|
67
|
+
export { permitWith, sendWith, signTypedDataWith };
|
package/dist/privy.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {e}from'./chunk-BU2KVGJB.js';import'./chunk-35WSRP27.js';import {ValidationError,SigningError}from'@aave/core';import {okAsync,signatureFrom,errAsync,ResultAsync,txHash}from'@aave/types';import {extractChain,createPublicClient,http}from'viem';import {waitForTransactionReceipt}from'viem/actions';import*as v from'viem/chains';var C=Object.values(v);async function R(a,n,t){let{hash:r}=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(r)}function i(a,n,t){let r=extractChain({chains:C,id:n.chainId}),o=createPublicClient({chain:r,transport:http()});return ResultAsync.fromPromise(R(a,n,t),e=>SigningError.from(e)).map(async e=>waitForTransactionReceipt(o,{hash:e,pollingInterval:100,retryCount:20,retryDelay:50})).andThen(e$1=>{let s=txHash(e$1.transactionHash);return e$1.status==="reverted"?errAsync(e(r,s,n)):okAsync({txHash:s,operations:n.operations})})}function l(a,n,t){switch(t.__typename){case "TransactionRequest":return i(a,t,n);case "Erc20ApprovalRequired":return i(a,t.approval.byTransaction,n).andThen(()=>i(a,t.originalTransaction,n));case "PreContractActionRequired":return i(a,t.transaction,n).andThen(()=>i(a,t.originalTransaction,n));case "InsufficientBalanceError":return errAsync(ValidationError.fromGqlNode(t))}}function I(a,n,t){return t?l(a,n,t):l.bind(null,a,n)}function _(a,n,t){return t().andThen(r=>{if(r.__typename==="Erc20ApprovalRequired"&&r.approval.bySignature){let o=r.approval.bySignature;return D(a,n,o).map(e=>({deadline:o.message.deadline,value:e})).andThen(e=>t(e))}return okAsync(r)})}function u(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}}),r=>SigningError.from(r)).map(r=>r.signature)}function D(a,n,t){return t===void 0?r=>u(a,n,r).map(signatureFrom):u(a,n,t).map(signatureFrom)}export{_ as permitWith,I as sendWith,D 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","message","signSwapTypedDataWith"],"mappings":"+QA+BA,eAAeA,EACbC,CAAAA,CACAC,CAAAA,CACAC,EACiB,CACjB,GAAM,CAAE,IAAA,CAAAC,CAAK,EAAI,MAAMH,CAAAA,CAAM,UAAU,QAAA,CAAS,eAAA,CAAgB,CAC9D,QAAA,CAAAE,CAAAA,CACA,MAAO,CAAA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ASwB,CAAAA,CACP1B,CAAAA,CACAE,EACAiB,CAAAA,CACkC,CAClC,IAAMQ,CAAAA,CAAU,IAAA,CAAK,MAAMR,CAAAA,CAAO,OAAO,EACzC,OAAOT,WAAAA,CAAY,YACjBV,CAAAA,CAAM,SAAA,CAAU,SAAS,aAAA,CAAc,CACrC,SAAAE,CAAAA,CACA,SAAA,CAAW,CACT,MAAA,CAAQiB,CAAAA,CAAO,OACf,KAAA,CAAOA,CAAAA,CAAO,MACd,OAAA,CAAAQ,CAAAA,CACA,YAAaR,CAAAA,CAAO,WACtB,CACF,CAAC,CAAA,CACAR,GAAQC,YAAAA,CAAa,IAAA,CAAKD,CAAG,CAChC,CAAA,CAAE,IAAKY,CAAAA,GAAc,CACnB,SAAUI,CAAAA,CAAQ,QAAA,CAClB,MAAOH,aAAAA,CAAcD,CAAAA,CAAS,SAAS,CACzC,CAAA,CAAE,CACJ,CAmBO,SAASK,EACd5B,CAAAA,CACAE,CAAAA,CACAiB,EACyD,CACzD,OAAOA,EACHO,CAAAA,CAAkB1B,CAAAA,CAAOE,EAAUiB,CAAM,CAAA,CACzCO,EAAkB,IAAA,CAAK,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 CancelSwapTypedData,\n ExecutionPlan,\n PermitTypedDataResponse,\n SwapByIntentTypedData,\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: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n const message = JSON.parse(result.message);\n return ResultAsync.fromPromise(\n privy.walletApi.ethereum.signTypedData({\n walletId,\n typedData: {\n domain: result.domain,\n types: result.types,\n message,\n primaryType: result.primaryType,\n },\n }),\n (err) => SigningError.from(err),\n ).map((response) => ({\n deadline: message.deadline,\n value: signatureFrom(response.signature),\n }));\n}\n\n/**\n * @internal\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 * @internal\n * Signs swap typed data using the specified Privy wallet.\n */\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n result?: SwapByIntentTypedData | CancelSwapTypedData,\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":["allChains","viemChains","sendTransaction","privy","request","walletId","hash","txHash","sendTransactionAndWait","chain","extractChain","publicClient","createPublicClient","http","ResultAsync","err","SigningError","waitForTransactionReceipt","receipt","errAsync","transactionError","okAsync","executePlan","result","ValidationError","sendWith","permitWith","action","permitTypedData","signTypedDataWith","signature","permitSig","signTypedData","data","response","typedData","signatureFrom"],"mappings":"6UA+BA,IAAMA,CAAAA,CAAY,MAAA,CAAO,OAAOC,CAAU,CAAA,CAE1C,eAAeC,CAAAA,CACbC,CAAAA,CACAC,EACAC,CAAAA,CACiB,CACjB,GAAM,CAAE,IAAA,CAAAC,CAAK,EAAI,MAAMH,CAAAA,CAAM,UAAU,QAAA,CAAS,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,EAAA,CACZ,KAAA,CAAO,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,CAAAA,CACAC,CAAAA,CACAC,EACiE,CACjE,IAAMI,EAAQC,YAAAA,CAAa,CACzB,OAAQV,CAAAA,CACR,EAAA,CAAII,EAAQ,OACd,CAAC,EAEKO,CAAAA,CAAe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AAA,CACd1B,EACAE,CAAAA,CACA4B,CAAAA,CACiD,CACjD,OAAIA,CAAAA,GAAS,OACHE,CAAAA,EACNH,CAAAA,CAAc7B,EAAOE,CAAAA,CAAU8B,CAAS,EAAE,GAAA,CAAIC,aAAa,EAExDJ,CAAAA,CAAc7B,CAAAA,CAAOE,EAAU4B,CAAI,CAAA,CAAE,GAAA,CAAIG,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 signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport type { PrivyClient } from '@privy-io/server-auth';\nimport { createPublicClient, extractChain, http } from 'viem';\nimport { waitForTransactionReceipt } from 'viem/actions';\nimport * as viemChains from 'viem/chains';\nimport type {\n ExecutionPlanHandler,\n SignTypedDataError,\n TransactionResult,\n TypedData,\n TypedDataHandler,\n} from './types';\nimport { transactionError } from './viem';\n\nconst allChains = Object.values(viemChains);\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 const chain = extractChain({\n chains: allChains,\n id: request.chainId as (typeof allChains)[number]['id'],\n });\n\n const publicClient = createPublicClient({\n chain,\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(transactionError(chain, hash, request));\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 as number,\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 * Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.\n *\n * @param privy - The Privy client instance.\n * @param walletId - The wallet ID to use for signing.\n * @returns A function that takes typed data and returns a ResultAsync containing the raw signature.\n *\n * ```ts\n * const result = await prepareSwapCancel(client, request)\n * .andThen(signTypedDataWith(privy, walletId));\n * ```\n */\nexport function signTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n): TypedDataHandler;\n\n/**\n * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.\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 *\n * ```ts\n * const result = await signTypedDataWith(privy, walletId, typedData);\n * ```\n */\nexport function signTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n data: TypedData,\n): ReturnType<TypedDataHandler>;\n\nexport function signTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n data?: TypedData,\n): TypedDataHandler | ReturnType<TypedDataHandler> {\n if (data === undefined) {\n return (typedData: TypedData) =>\n signTypedData(privy, walletId, typedData).map(signatureFrom);\n }\n return signTypedData(privy, walletId, data).map(signatureFrom);\n}\n"]}
|