@aave/client 0.7.0 → 4.0.0-next.0
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 +35 -27
- package/dist/{AaveClient-C-OkXfVz.d.ts → AaveClient-CgHY2iS9.d.ts} +12 -15
- package/dist/{AaveClient-PHUEzt7l.d.cts → AaveClient-L3v8kWvn.d.cts} +12 -15
- package/dist/actions/index.cjs +1 -1
- package/dist/actions/index.cjs.map +1 -1
- package/dist/actions/index.d.cts +626 -710
- package/dist/actions/index.d.ts +626 -710
- package/dist/actions/index.js +1 -1
- package/dist/chunk-2TNQ52OQ.js +3 -0
- package/dist/chunk-2TNQ52OQ.js.map +1 -0
- package/dist/chunk-BQFM5RT3.js +2 -0
- package/dist/chunk-BQFM5RT3.js.map +1 -0
- package/dist/chunk-BQNVAUS6.js +3 -0
- package/dist/chunk-BQNVAUS6.js.map +1 -0
- package/dist/ethers.cjs +1 -1
- package/dist/ethers.cjs.map +1 -1
- package/dist/ethers.d.cts +28 -12
- package/dist/ethers.d.ts +28 -12
- 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 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/options-vB2peXdE.d.cts +35 -0
- package/dist/options-vB2peXdE.d.ts +35 -0
- package/dist/privy.cjs +2 -2
- package/dist/privy.cjs.map +1 -1
- package/dist/privy.d.cts +21 -9
- package/dist/privy.d.ts +21 -9
- package/dist/privy.js +1 -1
- package/dist/privy.js.map +1 -1
- package/dist/test-utils.cjs +2 -449
- package/dist/test-utils.cjs.map +1 -1
- package/dist/test-utils.d.cts +28 -20
- package/dist/test-utils.d.ts +28 -20
- package/dist/test-utils.js +2 -437
- package/dist/test-utils.js.map +1 -1
- package/dist/thirdweb.cjs +2 -2
- package/dist/thirdweb.cjs.map +1 -1
- package/dist/thirdweb.d.cts +21 -9
- package/dist/thirdweb.d.ts +21 -9
- package/dist/thirdweb.js +2 -2
- package/dist/thirdweb.js.map +1 -1
- package/dist/types-Bu63z0x6.d.cts +21 -0
- package/dist/types-Bu63z0x6.d.ts +21 -0
- package/dist/utils/index.cjs +2 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +18 -0
- package/dist/utils/index.d.ts +18 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/viem.cjs +2 -2
- package/dist/viem.cjs.map +1 -1
- package/dist/viem.d.cts +32 -12
- package/dist/viem.d.ts +32 -12
- package/dist/viem.js +1 -1
- package/package.json +32 -8
- package/dist/chunk-BLZHGYNH.js +0 -2
- package/dist/chunk-BLZHGYNH.js.map +0 -1
- package/dist/chunk-FW4363Y4.js +0 -2
- package/dist/chunk-FW4363Y4.js.map +0 -1
- package/dist/chunk-QQSK6HIZ.js +0 -3
- package/dist/chunk-QQSK6HIZ.js.map +0 -1
- package/dist/chunk-V4DWF6LT.js +0 -3
- package/dist/chunk-V4DWF6LT.js.map +0 -1
- package/dist/magic-string.es-PTUXR566.js +0 -14
- package/dist/magic-string.es-PTUXR566.js.map +0 -1
- package/dist/types-ieyj0UmJ.d.cts +0 -16
- package/dist/types-ieyj0UmJ.d.ts +0 -16
package/dist/thirdweb.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var core=require('@aave/core'),types=require('@aave/types'),thirdweb=require('thirdweb');async function
|
|
2
|
-
exports.sendWith=
|
|
1
|
+
'use strict';var core=require('@aave/core'),types=require('@aave/types'),thirdweb=require('thirdweb');async function P(e,n){let a=await e.sendTransaction({type:"eip1559",chainId:n.chainId,to:n.to,value:BigInt(n.value),data:n.data});return types.txHash(a.transactionHash)}function r(e,n){let a=thirdweb.Engine.serverWallet({client:e,address:n.from});return types.ResultAsync.fromPromise(P(a,n),t=>core.SigningError.from(t)).map(async t=>thirdweb.waitForReceipt({client:e,chain:{id:n.chainId,rpc:`https://${n.chainId}.rpc.thirdweb.com/${e.clientId}`},transactionHash:t})).andThen(t=>{let i=types.txHash(t.transactionHash);return t.status==="reverted"?types.errAsync(core.TransactionError.new({txHash:i,request:n})):types.okAsync({txHash:i,operations:n.operations})})}function p(e,n){switch(n.__typename){case "TransactionRequest":return r(e,n);case "Erc20ApprovalRequired":case "PreContractActionRequired":return r(e,n.transaction).andThen(()=>r(e,n.originalTransaction));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(n))}}function H(e,n){return n?p(e,n):p.bind(null,e)}async function S(e,n){let t=await thirdweb.Engine.serverWallet({client:e,chain:thirdweb.defineChain({id:n.domain.chainId}),address:n.message.owner}).signTypedData({types:n.types,domain:n.domain,primaryType:n.primaryType,message:n.message});return types.signatureFrom(t)}function f(e,n){return types.ResultAsync.fromPromise(S(e,n),a=>core.SigningError.from(a)).map(a=>({deadline:n.message.deadline,value:a}))}function D(e){return f.bind(null,e)}function c(e,n){let a=JSON.parse(n.message),t=async()=>{let m=await thirdweb.Engine.serverWallet({client:e,chain:thirdweb.defineChain({id:n.domain.chainId}),address:a.user}).signTypedData({types:n.types,domain:n.domain,primaryType:n.primaryType,message:a});return types.signatureFrom(m)};return types.ResultAsync.fromPromise(t(),i=>core.SigningError.from(i)).map(i=>({deadline:a.deadline,value:i}))}function b(e,n){return n?c(e,n):c.bind(null,e)}
|
|
2
|
+
exports.sendWith=H;exports.signERC20PermitWith=D;exports.signSwapTypedDataWith=b;//# sourceMappingURL=thirdweb.cjs.map
|
|
3
3
|
//# sourceMappingURL=thirdweb.cjs.map
|
package/dist/thirdweb.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/thirdweb.ts"],"names":["sendTransaction","wallet","request","txResponse","txHash","sendTransactionAndWait","client","Engine","ResultAsync","err","SigningError","hash","waitForReceipt","receipt","errAsync","TransactionError","okAsync","
|
|
1
|
+
{"version":3,"sources":["../src/thirdweb.ts"],"names":["sendTransaction","wallet","request","txResponse","txHash","sendTransactionAndWait","client","Engine","ResultAsync","err","SigningError","hash","waitForReceipt","receipt","errAsync","TransactionError","okAsync","executePlan","result","ValidationError","sendWith","signTypedData","signature","defineChain","signatureFrom","signERC20Permit","value","signERC20PermitWith","signSwapTypedData","message","signTypedDataPromise","signSwapTypedDataWith"],"mappings":"sGA8BA,eAAeA,CAAAA,CACbC,EACAC,CAAAA,CACiB,CACjB,IAAMC,CAAAA,CAAa,MAAMF,EAAO,eAAA,CAAgB,CAC9C,KAAM,SAAA,CACN,OAAA,CAASC,EAAQ,OAAA,CACjB,EAAA,CAAIA,CAAAA,CAAQ,EAAA,CACZ,KAAA,CAAO,MAAA,CAAOA,EAAQ,KAAK,CAAA,CAC3B,KAAMA,CAAAA,CAAQ,IAChB,CAAC,CAAA,CACD,OAAOE,aAAOD,CAAAA,CAAW,eAAe,CAC1C,CAEA,SAASE,EACPC,CAAAA,CACAJ,CAAAA,CACiE,CACjE,IAAMD,CAAAA,CAASM,eAAAA,CAAO,YAAA,CAAa,CACjC,MAAA,CAAAD,EACA,OAAA,CAASJ,CAAAA,CAAQ,IACnB,CAAC,CAAA,CAED,OAAOM,iBAAAA,CAAY,WAAA,CAAYR,CAAAA,CAAgBC,CAAAA,CAAQC,CAAO,CAAA,CAAIO,GAChEC,iBAAAA,CAAa,IAAA,CAAKD,CAAG,CACvB,CAAA,CACG,IAAI,MAAOE,CAAAA,EACVC,uBAAAA,CAAe,CACb,MAAA,CAAAN,CAAAA,CACA,MAAO,CACL,EAAA,CAAIJ,EAAQ,OAAA,CACZ,GAAA,CAAK,WAAWA,CAAAA,CAAQ,OAAO,qBAAqBI,CAAAA,CAAO,QAAQ,EACrE,CAAA,CACA,eAAA,CAAiBK,CACnB,CAAC,CACH,EACC,OAAA,CAASE,CAAAA,EAAY,CACpB,IAAMF,CAAAA,CAAOP,YAAAA,CAAOS,EAAQ,eAAe,CAAA,CAE3C,OAAIA,CAAAA,CAAQ,MAAA,GA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AAA,CACHU,EAAkBtB,CAAAA,CAAQY,CAAM,EAChCU,CAAAA,CAAkB,IAAA,CAAK,IAAA,CAAMtB,CAAM,CACzC","file":"thirdweb.cjs","sourcesContent":["import { SigningError, TransactionError, ValidationError } 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 type Signature,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport {\n defineChain,\n Engine,\n type ThirdwebClient,\n waitForReceipt,\n} from 'thirdweb';\nimport type {\n ERC20PermitHandler,\n ExecutionPlanHandler,\n SwapSignatureHandler,\n TransactionResult,\n} from './types';\n\nasync function sendTransaction(\n wallet: Engine.ServerWallet,\n request: TransactionRequest,\n): Promise<TxHash> {\n const txResponse = await wallet.sendTransaction({\n type: 'eip1559',\n chainId: request.chainId,\n to: request.to,\n value: BigInt(request.value),\n data: request.data,\n });\n return txHash(txResponse.transactionHash);\n}\n\nfunction sendTransactionAndWait(\n client: ThirdwebClient,\n request: TransactionRequest,\n): ResultAsync<TransactionResult, SigningError | TransactionError> {\n const wallet = Engine.serverWallet({\n client,\n address: request.from,\n });\n\n return ResultAsync.fromPromise(sendTransaction(wallet, request), (err) =>\n SigningError.from(err),\n )\n .map(async (hash) =>\n waitForReceipt({\n client,\n chain: {\n id: request.chainId,\n rpc: `https://${request.chainId}.rpc.thirdweb.com/${client.clientId}`,\n },\n transactionHash: hash,\n }),\n )\n .andThen((receipt) => {\n const hash = txHash(receipt.transactionHash);\n\n if (receipt.status === 'reverted') {\n return errAsync(\n TransactionError.new({\n txHash: hash,\n request,\n }),\n );\n }\n return okAsync({\n txHash: hash,\n operations: request.operations,\n });\n });\n}\n\nfunction executePlan(\n client: ThirdwebClient,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(client, result);\n\n case 'Erc20ApprovalRequired':\n case 'PreContractActionRequired':\n return sendTransactionAndWait(client, result.transaction).andThen(() =>\n sendTransactionAndWait(client, result.originalTransaction),\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 provided Thirdweb client and account.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n client: ThirdwebClient,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the provided Thirdweb client.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n client: ThirdwebClient,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n client: ThirdwebClient,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result ? executePlan(client, result) : executePlan.bind(null, client);\n}\n\nasync function signTypedData(\n client: ThirdwebClient,\n result: PermitTypedDataResponse,\n): Promise<Signature> {\n const wallet = Engine.serverWallet({\n client,\n chain: defineChain({ id: result.domain.chainId }),\n address: result.message.owner,\n });\n\n const signature = await wallet.signTypedData({\n // silence the rest of the type inference\n types: result.types as Record<string, unknown>,\n domain: result.domain,\n primaryType: result.primaryType,\n message: result.message,\n });\n\n return signatureFrom(signature);\n}\n\nfunction signERC20Permit(\n client: ThirdwebClient,\n result: PermitTypedDataResponse,\n): ReturnType<ERC20PermitHandler> {\n return ResultAsync.fromPromise(signTypedData(client, result), (err) =>\n SigningError.from(err),\n ).map((value) => ({\n deadline: result.message.deadline,\n value,\n }));\n}\n\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the provided Thirdweb client and account.\n */\nexport function signERC20PermitWith(\n client: ThirdwebClient,\n): ERC20PermitHandler {\n return signERC20Permit.bind(null, client);\n}\n\nfunction signSwapTypedData(\n client: ThirdwebClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n const message = JSON.parse(result.message);\n\n const signTypedDataPromise = async (): Promise<Signature> => {\n const wallet = Engine.serverWallet({\n client,\n chain: defineChain({ id: result.domain.chainId }),\n address: message.user,\n });\n\n const signature = await wallet.signTypedData({\n // silence the rest of the type inference\n types: result.types as Record<string, unknown>,\n domain: result.domain,\n primaryType: result.primaryType,\n message,\n });\n\n return signatureFrom(signature);\n };\n\n return ResultAsync.fromPromise(signTypedDataPromise(), (err) =>\n SigningError.from(err),\n ).map((value) => ({\n deadline: message.deadline,\n value,\n }));\n}\n\n/**\n * @internal\n * Creates a swap signature handler that signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n): SwapSignatureHandler;\n/**\n * @internal\n * Signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n result?: SwapByIntentTypedData | CancelSwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(client, result)\n : signSwapTypedData.bind(null, client);\n}\n"]}
|
package/dist/thirdweb.d.cts
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
+
import { ExecutionPlan, SwapByIntentTypedData, CancelSwapTypedData } from '@aave/graphql';
|
|
1
2
|
import { ThirdwebClient } from 'thirdweb';
|
|
2
|
-
import { E as ExecutionPlanHandler,
|
|
3
|
+
import { E as ExecutionPlanHandler, a as ERC20PermitHandler, S as SwapSignatureHandler } from './types-Bu63z0x6.cjs';
|
|
3
4
|
import '@aave/core';
|
|
4
|
-
import '@aave/graphql';
|
|
5
5
|
import '@aave/types';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* Handles {@link TransactionRequest} by signing and sending, {@link ApprovalRequired} by sending both approval and original transactions, and returns validation errors for {@link InsufficientBalanceError}.
|
|
8
|
+
* Creates an execution plan handler that sends transactions using the provided Thirdweb client and account.
|
|
11
9
|
*/
|
|
12
|
-
declare function sendWith(client: ThirdwebClient): ExecutionPlanHandler
|
|
10
|
+
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(client: ThirdwebClient): ExecutionPlanHandler<T>;
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* Sends execution plan transactions using the provided Thirdweb client.
|
|
15
13
|
*/
|
|
16
|
-
declare function
|
|
14
|
+
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(client: ThirdwebClient, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an ERC20 permit handler that signs ERC20 permits using the provided Thirdweb client and account.
|
|
17
|
+
*/
|
|
18
|
+
declare function signERC20PermitWith(client: ThirdwebClient): ERC20PermitHandler;
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
* Creates a swap signature handler that signs swap typed data using the provided Thirdweb client.
|
|
22
|
+
*/
|
|
23
|
+
declare function signSwapTypedDataWith(client: ThirdwebClient): SwapSignatureHandler;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
* Signs swap typed data using the provided Thirdweb client.
|
|
27
|
+
*/
|
|
28
|
+
declare function signSwapTypedDataWith(client: ThirdwebClient, result: SwapByIntentTypedData | CancelSwapTypedData): ReturnType<SwapSignatureHandler>;
|
|
17
29
|
|
|
18
|
-
export { sendWith, signERC20PermitWith };
|
|
30
|
+
export { sendWith, signERC20PermitWith, signSwapTypedDataWith };
|
package/dist/thirdweb.d.ts
CHANGED
|
@@ -1,18 +1,30 @@
|
|
|
1
|
+
import { ExecutionPlan, SwapByIntentTypedData, CancelSwapTypedData } from '@aave/graphql';
|
|
1
2
|
import { ThirdwebClient } from 'thirdweb';
|
|
2
|
-
import { E as ExecutionPlanHandler,
|
|
3
|
+
import { E as ExecutionPlanHandler, a as ERC20PermitHandler, S as SwapSignatureHandler } from './types-Bu63z0x6.js';
|
|
3
4
|
import '@aave/core';
|
|
4
|
-
import '@aave/graphql';
|
|
5
5
|
import '@aave/types';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* Handles {@link TransactionRequest} by signing and sending, {@link ApprovalRequired} by sending both approval and original transactions, and returns validation errors for {@link InsufficientBalanceError}.
|
|
8
|
+
* Creates an execution plan handler that sends transactions using the provided Thirdweb client and account.
|
|
11
9
|
*/
|
|
12
|
-
declare function sendWith(client: ThirdwebClient): ExecutionPlanHandler
|
|
10
|
+
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(client: ThirdwebClient): ExecutionPlanHandler<T>;
|
|
13
11
|
/**
|
|
14
|
-
*
|
|
12
|
+
* Sends execution plan transactions using the provided Thirdweb client.
|
|
15
13
|
*/
|
|
16
|
-
declare function
|
|
14
|
+
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(client: ThirdwebClient, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates an ERC20 permit handler that signs ERC20 permits using the provided Thirdweb client and account.
|
|
17
|
+
*/
|
|
18
|
+
declare function signERC20PermitWith(client: ThirdwebClient): ERC20PermitHandler;
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
* Creates a swap signature handler that signs swap typed data using the provided Thirdweb client.
|
|
22
|
+
*/
|
|
23
|
+
declare function signSwapTypedDataWith(client: ThirdwebClient): SwapSignatureHandler;
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
* Signs swap typed data using the provided Thirdweb client.
|
|
27
|
+
*/
|
|
28
|
+
declare function signSwapTypedDataWith(client: ThirdwebClient, result: SwapByIntentTypedData | CancelSwapTypedData): ReturnType<SwapSignatureHandler>;
|
|
17
29
|
|
|
18
|
-
export { sendWith, signERC20PermitWith };
|
|
30
|
+
export { sendWith, signERC20PermitWith, signSwapTypedDataWith };
|
package/dist/thirdweb.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
export{
|
|
1
|
+
import {ValidationError,SigningError,TransactionError}from'@aave/core';import {errAsync,ResultAsync,txHash,okAsync,signatureFrom}from'@aave/types';import {Engine,waitForReceipt,defineChain}from'thirdweb';async function P(e,n){let a=await e.sendTransaction({type:"eip1559",chainId:n.chainId,to:n.to,value:BigInt(n.value),data:n.data});return txHash(a.transactionHash)}function r(e,n){let a=Engine.serverWallet({client:e,address:n.from});return ResultAsync.fromPromise(P(a,n),t=>SigningError.from(t)).map(async t=>waitForReceipt({client:e,chain:{id:n.chainId,rpc:`https://${n.chainId}.rpc.thirdweb.com/${e.clientId}`},transactionHash:t})).andThen(t=>{let i=txHash(t.transactionHash);return t.status==="reverted"?errAsync(TransactionError.new({txHash:i,request:n})):okAsync({txHash:i,operations:n.operations})})}function p(e,n){switch(n.__typename){case "TransactionRequest":return r(e,n);case "Erc20ApprovalRequired":case "PreContractActionRequired":return r(e,n.transaction).andThen(()=>r(e,n.originalTransaction));case "InsufficientBalanceError":return errAsync(ValidationError.fromGqlNode(n))}}function H(e,n){return n?p(e,n):p.bind(null,e)}async function S(e,n){let t=await Engine.serverWallet({client:e,chain:defineChain({id:n.domain.chainId}),address:n.message.owner}).signTypedData({types:n.types,domain:n.domain,primaryType:n.primaryType,message:n.message});return signatureFrom(t)}function f(e,n){return ResultAsync.fromPromise(S(e,n),a=>SigningError.from(a)).map(a=>({deadline:n.message.deadline,value:a}))}function D(e){return f.bind(null,e)}function c(e,n){let a=JSON.parse(n.message),t=async()=>{let m=await Engine.serverWallet({client:e,chain:defineChain({id:n.domain.chainId}),address:a.user}).signTypedData({types:n.types,domain:n.domain,primaryType:n.primaryType,message:a});return signatureFrom(m)};return ResultAsync.fromPromise(t(),i=>SigningError.from(i)).map(i=>({deadline:a.deadline,value:i}))}function b(e,n){return n?c(e,n):c.bind(null,e)}
|
|
2
|
+
export{H as sendWith,D as signERC20PermitWith,b as signSwapTypedDataWith};//# sourceMappingURL=thirdweb.js.map
|
|
3
3
|
//# sourceMappingURL=thirdweb.js.map
|
package/dist/thirdweb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/thirdweb.ts"],"names":["sendTransaction","wallet","request","txResponse","txHash","sendTransactionAndWait","client","Engine","ResultAsync","err","SigningError","hash","waitForReceipt","receipt","errAsync","TransactionError","okAsync","
|
|
1
|
+
{"version":3,"sources":["../src/thirdweb.ts"],"names":["sendTransaction","wallet","request","txResponse","txHash","sendTransactionAndWait","client","Engine","ResultAsync","err","SigningError","hash","waitForReceipt","receipt","errAsync","TransactionError","okAsync","executePlan","result","ValidationError","sendWith","signTypedData","signature","defineChain","signatureFrom","signERC20Permit","value","signERC20PermitWith","signSwapTypedData","message","signTypedDataPromise","signSwapTypedDataWith"],"mappings":"4MA8BA,eAAeA,CAAAA,CACbC,EACAC,CAAAA,CACiB,CACjB,IAAMC,CAAAA,CAAa,MAAMF,EAAO,eAAA,CAAgB,CAC9C,KAAM,SAAA,CACN,OAAA,CAASC,EAAQ,OAAA,CACjB,EAAA,CAAIA,CAAAA,CAAQ,EAAA,CACZ,KAAA,CAAO,MAAA,CAAOA,EAAQ,KAAK,CAAA,CAC3B,KAAMA,CAAAA,CAAQ,IAChB,CAAC,CAAA,CACD,OAAOE,OAAOD,CAAAA,CAAW,eAAe,CAC1C,CAEA,SAASE,EACPC,CAAAA,CACAJ,CAAAA,CACiE,CACjE,IAAMD,CAAAA,CAASM,MAAAA,CAAO,YAAA,CAAa,CACjC,MAAA,CAAAD,EACA,OAAA,CAASJ,CAAAA,CAAQ,IACnB,CAAC,CAAA,CAED,OAAOM,WAAAA,CAAY,WAAA,CAAYR,CAAAA,CAAgBC,CAAAA,CAAQC,CAAO,CAAA,CAAIO,GAChEC,YAAAA,CAAa,IAAA,CAAKD,CAAG,CACvB,CAAA,CACG,IAAI,MAAOE,CAAAA,EACVC,cAAAA,CA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aAAAA,CAAcF,CAAS,CAChC,CAAA,CAEA,OAAOd,WAAAA,CAAY,WAAA,CAAYsB,GAAqB,CAAIrB,CAAAA,EACtDC,aAAa,IAAA,CAAKD,CAAG,CACvB,CAAA,CAAE,GAAA,CAAKiB,CAAAA,GAAW,CAChB,QAAA,CAAUG,CAAAA,CAAQ,SAClB,KAAA,CAAAH,CACF,EAAE,CACJ,CAiBO,SAASK,CAAAA,CACdzB,CAAAA,CACAY,CAAAA,CACyD,CACzD,OAAOA,CAAAA,CACHU,EAAkBtB,CAAAA,CAAQY,CAAM,EAChCU,CAAAA,CAAkB,IAAA,CAAK,IAAA,CAAMtB,CAAM,CACzC","file":"thirdweb.js","sourcesContent":["import { SigningError, TransactionError, ValidationError } 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 type Signature,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport {\n defineChain,\n Engine,\n type ThirdwebClient,\n waitForReceipt,\n} from 'thirdweb';\nimport type {\n ERC20PermitHandler,\n ExecutionPlanHandler,\n SwapSignatureHandler,\n TransactionResult,\n} from './types';\n\nasync function sendTransaction(\n wallet: Engine.ServerWallet,\n request: TransactionRequest,\n): Promise<TxHash> {\n const txResponse = await wallet.sendTransaction({\n type: 'eip1559',\n chainId: request.chainId,\n to: request.to,\n value: BigInt(request.value),\n data: request.data,\n });\n return txHash(txResponse.transactionHash);\n}\n\nfunction sendTransactionAndWait(\n client: ThirdwebClient,\n request: TransactionRequest,\n): ResultAsync<TransactionResult, SigningError | TransactionError> {\n const wallet = Engine.serverWallet({\n client,\n address: request.from,\n });\n\n return ResultAsync.fromPromise(sendTransaction(wallet, request), (err) =>\n SigningError.from(err),\n )\n .map(async (hash) =>\n waitForReceipt({\n client,\n chain: {\n id: request.chainId,\n rpc: `https://${request.chainId}.rpc.thirdweb.com/${client.clientId}`,\n },\n transactionHash: hash,\n }),\n )\n .andThen((receipt) => {\n const hash = txHash(receipt.transactionHash);\n\n if (receipt.status === 'reverted') {\n return errAsync(\n TransactionError.new({\n txHash: hash,\n request,\n }),\n );\n }\n return okAsync({\n txHash: hash,\n operations: request.operations,\n });\n });\n}\n\nfunction executePlan(\n client: ThirdwebClient,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(client, result);\n\n case 'Erc20ApprovalRequired':\n case 'PreContractActionRequired':\n return sendTransactionAndWait(client, result.transaction).andThen(() =>\n sendTransactionAndWait(client, result.originalTransaction),\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 provided Thirdweb client and account.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n client: ThirdwebClient,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the provided Thirdweb client.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n client: ThirdwebClient,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n client: ThirdwebClient,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result ? executePlan(client, result) : executePlan.bind(null, client);\n}\n\nasync function signTypedData(\n client: ThirdwebClient,\n result: PermitTypedDataResponse,\n): Promise<Signature> {\n const wallet = Engine.serverWallet({\n client,\n chain: defineChain({ id: result.domain.chainId }),\n address: result.message.owner,\n });\n\n const signature = await wallet.signTypedData({\n // silence the rest of the type inference\n types: result.types as Record<string, unknown>,\n domain: result.domain,\n primaryType: result.primaryType,\n message: result.message,\n });\n\n return signatureFrom(signature);\n}\n\nfunction signERC20Permit(\n client: ThirdwebClient,\n result: PermitTypedDataResponse,\n): ReturnType<ERC20PermitHandler> {\n return ResultAsync.fromPromise(signTypedData(client, result), (err) =>\n SigningError.from(err),\n ).map((value) => ({\n deadline: result.message.deadline,\n value,\n }));\n}\n\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the provided Thirdweb client and account.\n */\nexport function signERC20PermitWith(\n client: ThirdwebClient,\n): ERC20PermitHandler {\n return signERC20Permit.bind(null, client);\n}\n\nfunction signSwapTypedData(\n client: ThirdwebClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n const message = JSON.parse(result.message);\n\n const signTypedDataPromise = async (): Promise<Signature> => {\n const wallet = Engine.serverWallet({\n client,\n chain: defineChain({ id: result.domain.chainId }),\n address: message.user,\n });\n\n const signature = await wallet.signTypedData({\n // silence the rest of the type inference\n types: result.types as Record<string, unknown>,\n domain: result.domain,\n primaryType: result.primaryType,\n message,\n });\n\n return signatureFrom(signature);\n };\n\n return ResultAsync.fromPromise(signTypedDataPromise(), (err) =>\n SigningError.from(err),\n ).map((value) => ({\n deadline: message.deadline,\n value,\n }));\n}\n\n/**\n * @internal\n * Creates a swap signature handler that signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n): SwapSignatureHandler;\n/**\n * @internal\n * Signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n result?: SwapByIntentTypedData | CancelSwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(client, result)\n : signSwapTypedData.bind(null, client);\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CancelError, SigningError, TransactionError, ValidationError, UnexpectedError } from '@aave/core';
|
|
2
|
+
import { OperationType, ExecutionPlan, InsufficientBalanceError, PermitTypedDataResponse, ERC20PermitSignature, CancelSwapTypedData, SwapByIntentTypedData, HasProcessedKnownTransactionRequest } from '@aave/graphql';
|
|
3
|
+
import { TxHash, ResultAsync } from '@aave/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
type TransactionResult = {
|
|
9
|
+
txHash: TxHash;
|
|
10
|
+
operations: OperationType[] | null;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
declare function isHasProcessedKnownTransactionRequest(result: TransactionResult): result is HasProcessedKnownTransactionRequest;
|
|
16
|
+
type SendWithError = CancelError | SigningError | TransactionError | ValidationError<InsufficientBalanceError> | UnexpectedError;
|
|
17
|
+
type ExecutionPlanHandler<T extends ExecutionPlan = ExecutionPlan> = (result: T) => ResultAsync<TransactionResult, SendWithError>;
|
|
18
|
+
type ERC20PermitHandler = (result: PermitTypedDataResponse) => ResultAsync<ERC20PermitSignature, SigningError>;
|
|
19
|
+
type SwapSignatureHandler = (result: CancelSwapTypedData | SwapByIntentTypedData) => ResultAsync<ERC20PermitSignature, SigningError>;
|
|
20
|
+
|
|
21
|
+
export { type ExecutionPlanHandler as E, type SwapSignatureHandler as S, type TransactionResult as T, type ERC20PermitHandler as a, type SendWithError as b, isHasProcessedKnownTransactionRequest as i };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CancelError, SigningError, TransactionError, ValidationError, UnexpectedError } from '@aave/core';
|
|
2
|
+
import { OperationType, ExecutionPlan, InsufficientBalanceError, PermitTypedDataResponse, ERC20PermitSignature, CancelSwapTypedData, SwapByIntentTypedData, HasProcessedKnownTransactionRequest } from '@aave/graphql';
|
|
3
|
+
import { TxHash, ResultAsync } from '@aave/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
type TransactionResult = {
|
|
9
|
+
txHash: TxHash;
|
|
10
|
+
operations: OperationType[] | null;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
declare function isHasProcessedKnownTransactionRequest(result: TransactionResult): result is HasProcessedKnownTransactionRequest;
|
|
16
|
+
type SendWithError = CancelError | SigningError | TransactionError | ValidationError<InsufficientBalanceError> | UnexpectedError;
|
|
17
|
+
type ExecutionPlanHandler<T extends ExecutionPlan = ExecutionPlan> = (result: T) => ResultAsync<TransactionResult, SendWithError>;
|
|
18
|
+
type ERC20PermitHandler = (result: PermitTypedDataResponse) => ResultAsync<ERC20PermitSignature, SigningError>;
|
|
19
|
+
type SwapSignatureHandler = (result: CancelSwapTypedData | SwapByIntentTypedData) => ResultAsync<ERC20PermitSignature, SigningError>;
|
|
20
|
+
|
|
21
|
+
export { type ExecutionPlanHandler as E, type SwapSignatureHandler as S, type TransactionResult as T, type ERC20PermitHandler as a, type SendWithError as b, isHasProcessedKnownTransactionRequest as i };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
'use strict';var types=require('@aave/types');function o(r){return types.isNonEmptyArray(r)?r.reduce((u,e)=>e.summary.supplyApy.value.gt(u.summary.supplyApy.value)?e:u,r[0]):null}function l(r){return types.isNonEmptyArray(r)?r.reduce((u,e)=>e.summary.borrowApy.value.lt(u.summary.borrowApy.value)?e:u,r[0]):null}exports.pickHighestSupplyApyReserve=o;exports.pickLowestBorrowApyReserve=l;//# sourceMappingURL=index.cjs.map
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/reserves.ts"],"names":["pickHighestSupplyApyReserve","reserves","isNonEmptyArray","max","reserve","pickLowestBorrowApyReserve","min"],"mappings":"8CASO,SAASA,CAAAA,CACdC,CAAAA,CACgB,CAChB,OAAKC,qBAAAA,CAAgBD,CAAQ,CAAA,CAItBA,CAAAA,CAAS,MAAA,CAAO,CAACE,CAAAA,CAAKC,CAAAA,GACpBA,CAAAA,CAAQ,OAAA,CAAQ,SAAA,CAAU,KAAA,CAAM,EAAA,CAAGD,CAAAA,CAAI,OAAA,CAAQ,SAAA,CAAU,KAAK,CAAA,CACjEC,CAAAA,CACAD,CAAAA,CACHF,EAAS,CAAC,CAAC,CAAA,CAPL,IAQX,CAQO,SAASI,CAAAA,CACdJ,CAAAA,CACgB,CAChB,OAAKC,qBAAAA,CAAgBD,CAAQ,CAAA,CAItBA,CAAAA,CAAS,MAAA,CAAO,CAACK,EAAKF,CAAAA,GACpBA,CAAAA,CAAQ,OAAA,CAAQ,SAAA,CAAU,KAAA,CAAM,EAAA,CAAGE,CAAAA,CAAI,OAAA,CAAQ,SAAA,CAAU,KAAK,CAAA,CACjEF,CAAAA,CACAE,CAAAA,CACHL,CAAAA,CAAS,CAAC,CAAC,EAPL,IAQX","file":"index.cjs","sourcesContent":["import type { Reserve } from '@aave/graphql';\nimport { isNonEmptyArray } from '@aave/types';\n\n/**\n * Picks the highest supply APY reserve from the given reserves.\n *\n * @param reserves - The reserves to pick the highest supply apy reserve from.\n * @returns The highest supply APY reserve or null if not found.\n */\nexport function pickHighestSupplyApyReserve(\n reserves: Reserve[],\n): Reserve | null {\n if (!isNonEmptyArray(reserves)) {\n return null;\n }\n\n return reserves.reduce((max, reserve) => {\n return reserve.summary.supplyApy.value.gt(max.summary.supplyApy.value)\n ? reserve\n : max;\n }, reserves[0]);\n}\n\n/**\n * Picks the lowest borrow APY reserve from the given reserves.\n *\n * @param reserves - The reserves to pick the lowest borrow apy reserve from.\n * @returns The lowest borrow APY reserve or null if not found.\n */\nexport function pickLowestBorrowApyReserve(\n reserves: Reserve[],\n): Reserve | null {\n if (!isNonEmptyArray(reserves)) {\n return null;\n }\n\n return reserves.reduce((min, reserve) => {\n return reserve.summary.borrowApy.value.lt(min.summary.borrowApy.value)\n ? reserve\n : min;\n }, reserves[0]);\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Reserve } from '@aave/graphql';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Picks the highest supply APY reserve from the given reserves.
|
|
5
|
+
*
|
|
6
|
+
* @param reserves - The reserves to pick the highest supply apy reserve from.
|
|
7
|
+
* @returns The highest supply APY reserve or null if not found.
|
|
8
|
+
*/
|
|
9
|
+
declare function pickHighestSupplyApyReserve(reserves: Reserve[]): Reserve | null;
|
|
10
|
+
/**
|
|
11
|
+
* Picks the lowest borrow APY reserve from the given reserves.
|
|
12
|
+
*
|
|
13
|
+
* @param reserves - The reserves to pick the lowest borrow apy reserve from.
|
|
14
|
+
* @returns The lowest borrow APY reserve or null if not found.
|
|
15
|
+
*/
|
|
16
|
+
declare function pickLowestBorrowApyReserve(reserves: Reserve[]): Reserve | null;
|
|
17
|
+
|
|
18
|
+
export { pickHighestSupplyApyReserve, pickLowestBorrowApyReserve };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Reserve } from '@aave/graphql';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Picks the highest supply APY reserve from the given reserves.
|
|
5
|
+
*
|
|
6
|
+
* @param reserves - The reserves to pick the highest supply apy reserve from.
|
|
7
|
+
* @returns The highest supply APY reserve or null if not found.
|
|
8
|
+
*/
|
|
9
|
+
declare function pickHighestSupplyApyReserve(reserves: Reserve[]): Reserve | null;
|
|
10
|
+
/**
|
|
11
|
+
* Picks the lowest borrow APY reserve from the given reserves.
|
|
12
|
+
*
|
|
13
|
+
* @param reserves - The reserves to pick the lowest borrow apy reserve from.
|
|
14
|
+
* @returns The lowest borrow APY reserve or null if not found.
|
|
15
|
+
*/
|
|
16
|
+
declare function pickLowestBorrowApyReserve(reserves: Reserve[]): Reserve | null;
|
|
17
|
+
|
|
18
|
+
export { pickHighestSupplyApyReserve, pickLowestBorrowApyReserve };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {isNonEmptyArray}from'@aave/types';function o(r){return isNonEmptyArray(r)?r.reduce((u,e)=>e.summary.supplyApy.value.gt(u.summary.supplyApy.value)?e:u,r[0]):null}function l(r){return isNonEmptyArray(r)?r.reduce((u,e)=>e.summary.borrowApy.value.lt(u.summary.borrowApy.value)?e:u,r[0]):null}export{o as pickHighestSupplyApyReserve,l as pickLowestBorrowApyReserve};//# sourceMappingURL=index.js.map
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/reserves.ts"],"names":["pickHighestSupplyApyReserve","reserves","isNonEmptyArray","max","reserve","pickLowestBorrowApyReserve","min"],"mappings":"0CASO,SAASA,CAAAA,CACdC,CAAAA,CACgB,CAChB,OAAKC,eAAAA,CAAgBD,CAAQ,CAAA,CAItBA,CAAAA,CAAS,MAAA,CAAO,CAACE,CAAAA,CAAKC,CAAAA,GACpBA,CAAAA,CAAQ,OAAA,CAAQ,SAAA,CAAU,KAAA,CAAM,EAAA,CAAGD,CAAAA,CAAI,OAAA,CAAQ,SAAA,CAAU,KAAK,CAAA,CACjEC,CAAAA,CACAD,CAAAA,CACHF,EAAS,CAAC,CAAC,CAAA,CAPL,IAQX,CAQO,SAASI,CAAAA,CACdJ,CAAAA,CACgB,CAChB,OAAKC,eAAAA,CAAgBD,CAAQ,CAAA,CAItBA,CAAAA,CAAS,MAAA,CAAO,CAACK,EAAKF,CAAAA,GACpBA,CAAAA,CAAQ,OAAA,CAAQ,SAAA,CAAU,KAAA,CAAM,EAAA,CAAGE,CAAAA,CAAI,OAAA,CAAQ,SAAA,CAAU,KAAK,CAAA,CACjEF,CAAAA,CACAE,CAAAA,CACHL,CAAAA,CAAS,CAAC,CAAC,EAPL,IAQX","file":"index.js","sourcesContent":["import type { Reserve } from '@aave/graphql';\nimport { isNonEmptyArray } from '@aave/types';\n\n/**\n * Picks the highest supply APY reserve from the given reserves.\n *\n * @param reserves - The reserves to pick the highest supply apy reserve from.\n * @returns The highest supply APY reserve or null if not found.\n */\nexport function pickHighestSupplyApyReserve(\n reserves: Reserve[],\n): Reserve | null {\n if (!isNonEmptyArray(reserves)) {\n return null;\n }\n\n return reserves.reduce((max, reserve) => {\n return reserve.summary.supplyApy.value.gt(max.summary.supplyApy.value)\n ? reserve\n : max;\n }, reserves[0]);\n}\n\n/**\n * Picks the lowest borrow APY reserve from the given reserves.\n *\n * @param reserves - The reserves to pick the lowest borrow apy reserve from.\n * @returns The lowest borrow APY reserve or null if not found.\n */\nexport function pickLowestBorrowApyReserve(\n reserves: Reserve[],\n): Reserve | null {\n if (!isNonEmptyArray(reserves)) {\n return null;\n }\n\n return reserves.reduce((min, reserve) => {\n return reserve.summary.borrowApy.value.lt(min.summary.borrowApy.value)\n ? reserve\n : min;\n }, reserves[0]);\n}\n"]}
|
package/dist/viem.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';var core=require('@aave/core'),types=require('@aave/types'),viem=require('viem'),actions=require('viem/actions')
|
|
2
|
-
exports.
|
|
1
|
+
'use strict';var core=require('@aave/core'),types=require('@aave/types'),viem=require('viem'),actions=require('viem/actions');function p(n){return types.isObject(n)&&"code"in n&&"message"in n}function U(n){return types.isObject(n)&&"name"in n&&"message"in n&&"originalError"in n?p(n.originalError)&&"code"in n.originalError:true}var m=viem.defineChain({id:Number.parseInt("123456789",10),name:"Devnet",network:"ethereum-fork",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://virtual.mainnet-aave.us-east.rpc.tenderly.co/dbaa58ab-597b-4bcd-ae6a-b8e50f716146"]}},blockExplorers:{default:{name:"Devnet Explorer",url:"https://dashboard.tenderly.co/explorer/vnet/dbaa58ab-597b-4bcd-ae6a-b8e50f716146/"}}}),T={[types.chainId(m.id)]:m};function _(n,e){return types.ResultAsync.fromPromise(n.getChainId(),a=>core.SigningError.from(a)).andThen(a=>a===e.chainId?types.okAsync():types.ResultAsync.fromPromise(n.switchChain({id:e.chainId}),r=>core.SigningError.from(r)).orElse(r=>(p(r.cause)?r.cause.code:U(r.cause)?r.cause.data?.originalError?.code:void 0)===viem.SwitchChainError.code&&e.chainId in T?types.ResultAsync.fromPromise(n.addChain({chain:T[e.chainId]}),c=>p(c)&&c.code===viem.UserRejectedRequestError.code?core.CancelError.from(c):core.SigningError.from(c)):r.asResultAsync()))}function k(n,e){return types.ResultAsync.fromPromise(actions.estimateGas(n,{account:n.account,data:e.data,to:e.to,value:BigInt(e.value)}),a=>core.SigningError.from(a)).map(a=>a*115n/100n)}function B(n,e){return k(n,e).andThen(a=>types.ResultAsync.fromPromise(actions.sendTransaction(n,{account:n.account,data:e.data,to:e.to,value:BigInt(e.value),chain:n.chain,gas:a}),r=>{if(r instanceof viem.TransactionExecutionError){let t=r.walk(c=>c instanceof viem.UserRejectedRequestError);if(t)return core.CancelError.from(t)}return core.SigningError.from(r)})).map(types.txHash)}function L(n){return n.account!==void 0}function N(n,e){return types.invariant(L(n),"Wallet client with account is required"),_(n,e).andThen(a=>B(n,e))}function q(n,e,a){let r=n?.blockExplorers?.default?.url,t=r&&new URL(`/tx/${e}`,r).toString();return core.TransactionError.new({txHash:e,request:a,link:t})}function O(n,e,a){return types.ResultAsync.fromPromise(actions.waitForTransactionReceipt(n,{hash:a,pollingInterval:100,retryCount:20,retryDelay:50}),r=>core.UnexpectedError.from(r)).andThen(r=>{let t=types.txHash(r.transactionHash);switch(r.status){case "reverted":return a!==t?types.errAsync(core.CancelError.from(`Transaction replaced by ${t}`)):types.errAsync(q(n.chain,t,e));case "success":return types.okAsync({txHash:t,operations:e.operations})}})}function s(n,e){return N(n,e).andThen(a=>O(n,e,a))}function y(n,e){switch(e.__typename){case "TransactionRequest":return s(n,e);case "Erc20ApprovalRequired":case "PreContractActionRequired":return s(n,e.transaction).andThen(()=>s(n,e.originalTransaction));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(e))}}function Y(n,e){return e?y(n,e):y.bind(null,n)}function F(n,e){return types.invariant(n.account,"Wallet account is required"),types.ResultAsync.fromPromise(actions.signTypedData(n,{account:n.account,domain:e.domain,types:e.types,primaryType:e.primaryType,message:e.message}),a=>core.SigningError.from(a)).map(a=>({deadline:e.message.deadline,value:types.signatureFrom(a)}))}function J(n){return F.bind(null,n)}function E(n,e){return types.invariant(n.account,"Wallet account is required"),types.ResultAsync.fromPromise(actions.signTypedData(n,{account:n.account,domain:e.domain,types:e.types,primaryType:e.primaryType,message:JSON.parse(e.message)}),a=>core.SigningError.from(a)).map(a=>({deadline:JSON.parse(e.message).deadline,value:types.signatureFrom(a)}))}function K(n,e){return e?E(n,e):E.bind(null,n)}
|
|
2
|
+
exports.devnetChain=m;exports.sendTransaction=N;exports.sendWith=Y;exports.signERC20PermitWith=J;exports.signSwapTypedDataWith=K;exports.supportedChains=T;exports.transactionError=q;exports.waitForTransactionResult=O;//# sourceMappingURL=viem.cjs.map
|
|
3
3
|
//# sourceMappingURL=viem.cjs.map
|
package/dist/viem.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/viem.ts"],"names":["sonic","defineChain","soneium","supportedChains","chainId","mainnet","arbitrum","avalanche","base","baseSepolia","bsc","celo","gnosis","linea","metis","optimism","polygon","scroll","zksync","sendTransaction","walletClient","request","sendEip1559Transaction","transactionError","chain","txHash","baseUrl","link","TransactionError","sendTransactionAndWait","ResultAsync","err","SigningError","hash","waitForTransactionReceipt","receipt","errAsync","okAsync","sendWith","result","ValidationError","signERC20PermitWith","invariant","signTypedData","hex","signatureFrom"],"mappings":"4JAuDA,IAAMA,CAAAA,CAAeC,gBAAAA,CAAY,CAC/B,EAAA,CAAI,GAAA,CACJ,IAAA,CAAM,OAAA,CACN,cAAA,CAAgB,CAAE,IAAA,CAAM,OAAA,CAAS,MAAA,CAAQ,GAAA,CAAK,QAAA,CAAU,EAAG,CAAA,CAC3D,OAAA,CAAS,CACP,OAAA,CAAS,CACP,IAAA,CAAM,CAAC,uBAAuB,CAChC,CACF,CAAA,CACA,cAAA,CAAgB,CACd,OAAA,CAAS,CACP,IAAA,CAAM,WAAA,CACN,GAAA,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B,OAAA,CAASA,CAAAA,CAAO,OAClB,CAAC,CAAA,CACAR,CAAAA,EAAQC,iBAAAA,CAAa,IAAA,CAAKD,CAAG,CAChC,CAAA,CAAE,GAAA,CAAKa,CAAAA,GAAS,CACd,QAAA,CAAUL,CAAAA,CAAO,OAAA,CAAQ,QAAA,CACzB,KAAA,CAAOM,mBAAAA,CAAcD,CAAG,CAC1B,CAAA,CAAE,CAAA,CAEN","file":"viem.cjs","sourcesContent":["import { SigningError, TransactionError, ValidationError } from '@aave/core';\nimport type {\n ExecutionPlan,\n InsufficientBalanceError,\n PermitTypedDataResponse,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n type ChainId,\n chainId,\n errAsync,\n invariant,\n okAsync,\n ResultAsync,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport {\n type Chain,\n defineChain,\n type Hash,\n type TypedData,\n type TypedDataDomain,\n type WalletClient,\n} from 'viem';\nimport {\n sendTransaction as sendEip1559Transaction,\n signTypedData,\n waitForTransactionReceipt,\n} from 'viem/actions';\n// chains.ts\nimport {\n arbitrum,\n avalanche,\n base,\n baseSepolia,\n bsc,\n celo,\n gnosis,\n linea,\n mainnet,\n metis,\n optimism,\n polygon,\n scroll,\n zksync,\n} from 'viem/chains';\nimport type {\n ExecutionPlanHandler,\n PermitHandler,\n TransactionExecutionResult,\n} from './types';\n\n// Other chains\nconst sonic: Chain = defineChain({\n id: 146,\n name: 'Sonic',\n nativeCurrency: { name: 'Sonic', symbol: 'S', decimals: 18 },\n rpcUrls: {\n default: {\n http: ['https://sonicscan.org'], // Replace with actual RPC URL if needed\n },\n },\n blockExplorers: {\n default: {\n name: 'SonicScan',\n url: 'https://sonicscan.org',\n },\n },\n});\n\nconst soneium: Chain = defineChain({\n id: 1868,\n name: 'Soneium',\n nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },\n rpcUrls: {\n default: {\n http: ['https://soneium.blockscout.com'], // Replace with actual RPC URL if needed\n },\n },\n blockExplorers: {\n default: {\n name: 'Blockscout',\n url: 'https://soneium.blockscout.com',\n },\n },\n});\n\n/**\n * @internal\n */\nexport const supportedChains: Record<\n ChainId,\n ReturnType<typeof defineChain>\n> = {\n [chainId(mainnet.id)]: mainnet,\n [chainId(arbitrum.id)]: arbitrum,\n [chainId(avalanche.id)]: avalanche,\n [chainId(base.id)]: base,\n [chainId(baseSepolia.id)]: baseSepolia,\n [chainId(bsc.id)]: bsc,\n [chainId(celo.id)]: celo,\n [chainId(gnosis.id)]: gnosis,\n [chainId(linea.id)]: linea,\n [chainId(metis.id)]: metis,\n [chainId(optimism.id)]: optimism,\n [chainId(polygon.id)]: polygon,\n [chainId(scroll.id)]: scroll,\n [chainId(zksync.id)]: zksync,\n [chainId(sonic.id)]: sonic,\n [chainId(soneium.id)]: soneium,\n};\n\nasync function sendTransaction(\n walletClient: WalletClient,\n request: TransactionRequest,\n): Promise<Hash> {\n return sendEip1559Transaction(walletClient, {\n account: request.from,\n data: request.data,\n to: request.to,\n value: BigInt(request.value),\n chain: walletClient.chain,\n });\n}\n\n/**\n * @internal\n */\nexport function transactionError(\n chain: Chain | undefined,\n txHash: TxHash,\n request: TransactionRequest,\n): TransactionError {\n const baseUrl = chain?.blockExplorers?.default?.url;\n const link = baseUrl && `${baseUrl.replace(/\\/+$/, '')}/tx/${txHash}`;\n\n return TransactionError.new({ txHash, request, link });\n}\n\n/**\n * @internal\n */\nexport function sendTransactionAndWait(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<TransactionExecutionResult, 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\n return ResultAsync.fromPromise(\n sendTransaction(walletClient, request),\n (err) => SigningError.from(err),\n )\n .map(async (hash) =>\n waitForTransactionReceipt(walletClient, {\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(walletClient.chain, hash, request));\n }\n return okAsync({\n txHash: hash,\n operation: request.operation,\n });\n });\n}\n\n/**\n * Sends transactions using the provided wallet client.\n *\n * Handles {@link TransactionRequest} by signing and sending, {@link ApprovalRequired} by sending both approval and original transactions, and returns validation errors for {@link InsufficientBalanceError}.\n */\nexport function sendWith(walletClient: WalletClient): ExecutionPlanHandler {\n return (\n result: ExecutionPlan,\n ): ResultAsync<\n TransactionExecutionResult,\n SigningError | TransactionError | ValidationError<InsufficientBalanceError>\n > => {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(walletClient, result);\n\n case 'ApprovalRequired':\n return sendTransactionAndWait(walletClient, result.approval).andThen(\n () =>\n sendTransactionAndWait(walletClient, result.originalTransaction),\n );\n\n case 'InsufficientBalanceError':\n return errAsync(ValidationError.fromGqlNode(result));\n }\n };\n}\n\n/**\n * Signs an ERC20 permit using the provided wallet client.\n */\nexport function signERC20PermitWith(walletClient: WalletClient): PermitHandler {\n return (result: PermitTypedDataResponse) => {\n invariant(walletClient.account, 'Wallet account is required');\n\n return ResultAsync.fromPromise(\n signTypedData(walletClient, {\n account: walletClient.account,\n domain: result.domain as TypedDataDomain,\n types: result.types as TypedData,\n primaryType: result.primaryType as keyof typeof result.types,\n message: result.message,\n }),\n (err) => SigningError.from(err),\n ).map((hex) => ({\n deadline: result.message.deadline,\n value: signatureFrom(hex),\n }));\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/viem.ts"],"names":["isRpcError","err","isObject","isProviderRpcError","devnetChain","defineChain","supportedChains","chainId","ensureChain","walletClient","request","ResultAsync","SigningError","okAsync","SwitchChainError","UserRejectedRequestError","CancelError","estimateGas","estimateGasWithViem","gas","sendEip1559Transaction","sendTransactionWithViem","TransactionExecutionError","rejected","txHash","isWalletClientWithAccount","sendTransaction","invariant","_","transactionError","chain","baseUrl","link","TransactionError","waitForTransactionResult","initialTxHash","waitForTransactionReceipt","UnexpectedError","receipt","hash","errAsync","sendTransactionAndWait","executePlan","result","ValidationError","sendWith","signERC20Permit","signTypedData","hex","signatureFrom","signERC20PermitWith","signSwapTypedData","signSwapTypedDataWith"],"mappings":"8HAqDA,SAASA,CAAAA,CAAWC,EAA+B,CACjD,OAAOC,cAAAA,CAASD,CAAG,GAAK,MAAA,GAAUA,CAAAA,EAAO,YAAaA,CACxD,CAEA,SAASE,CAAAA,CACPF,CAAAA,CAC+D,CAC/D,OAAOC,eAASD,CAAG,CAAA,EACjB,SAAUA,CAAAA,EACV,SAAA,GAAaA,GACb,eAAA,GAAmBA,CAAAA,CACjBD,EAAWC,CAAAA,CAAI,aAAa,GAAK,MAAA,GAAUA,CAAAA,CAAI,cAC/C,IACN,KAKaG,CAAAA,CAAqBC,gBAAAA,CAAY,CAC5C,EAAA,CAAI,OAAO,QAAA,CAAS,WAAA,CAA2C,EAAE,CAAA,CACjE,IAAA,CAAM,SACN,OAAA,CAAS,eAAA,CACT,cAAA,CAAgB,CAAE,KAAM,OAAA,CAAS,MAAA,CAAQ,MAAO,QAAA,CAAU,EAAG,EAC7D,OAAA,CAAS,CACP,OAAA,CAAS,CAAE,KAAM,CAAC,2FAA4C,CAAE,CAClE,CAAA,CACA,eAAgB,CACd,OAAA,CAAS,CACP,IAAA,CAAM,iBAAA,CACN,IAAK,mFACP,CACF,CACF,CAAC,CAAA,CAKYC,EAGT,CAIF,CAACC,aAAAA,CAAQH,CAAAA,CAAY,EAAE,CAAC,EAAGA,CAC7B,EAEA,SAASI,EACPC,CAAAA,CACAC,CAAAA,CAC+C,CAC/C,OAAOC,kBAAY,WAAA,CAAYF,CAAAA,CAAa,YAAW,CAAIR,CAAAA,EACzDW,kBAAa,IAAA,CAAKX,CAAG,CACvB,CAAA,CAAE,QAASM,CAAAA,EACLA,CAAAA,GAAYG,EAAQ,OAAA,CACfG,aAAAA,GAGFF,iBAAAA,CAAY,WAAA,CACjBF,EAAa,WAAA,CAAY,CAAE,GAAIC,CAAAA,CAAQ,OAAQ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AO,OAAO,CACpC,CAAC,EACA1C,CAAAA,EAAQW,iBAAAA,CAAa,KAAKX,CAAG,CAChC,EAAE,GAAA,CAAK+C,CAAAA,GAAS,CACd,QAAA,CAAU,IAAA,CAAK,MAAML,CAAAA,CAAO,OAAO,EAAE,QAAA,CACrC,KAAA,CAAOM,mBAAAA,CAAcD,CAAG,CAC1B,CAAA,CAAE,CACJ,CAiBO,SAASI,CAAAA,CACd3C,EACAkC,CAAAA,CACyD,CACzD,OAAOA,CAAAA,CACHQ,CAAAA,CAAkB1C,EAAckC,CAAM,CAAA,CACtCQ,EAAkB,IAAA,CAAK,IAAA,CAAM1C,CAAY,CAC/C","file":"viem.cjs","sourcesContent":["import {\n CancelError,\n SigningError,\n TransactionError,\n UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n CancelSwapTypedData,\n ExecutionPlan,\n PermitTypedDataResponse,\n SwapByIntentTypedData,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n type ChainId,\n chainId,\n errAsync,\n invariant,\n isObject,\n okAsync,\n ResultAsync,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport {\n type Account,\n type Chain,\n defineChain,\n type ProviderRpcError,\n type RpcError,\n SwitchChainError,\n TransactionExecutionError,\n type Transport,\n type TypedData,\n type TypedDataDomain,\n UserRejectedRequestError,\n type WalletClient,\n} from 'viem';\nimport {\n estimateGas as estimateGasWithViem,\n sendTransaction as sendTransactionWithViem,\n signTypedData,\n waitForTransactionReceipt,\n} from 'viem/actions';\nimport type {\n ERC20PermitHandler,\n ExecutionPlanHandler,\n SwapSignatureHandler,\n TransactionResult,\n} from './types';\n\nfunction isRpcError(err: unknown): err is RpcError {\n return isObject(err) && 'code' in err && 'message' in err;\n}\n\nfunction isProviderRpcError(\n err: unknown,\n): err is ProviderRpcError<{ originalError?: { code: number } }> {\n return isObject(err) &&\n 'name' in err &&\n 'message' in err &&\n 'originalError' in err\n ? isRpcError(err.originalError) && 'code' in err.originalError\n : true;\n}\n\n/**\n * @internal\n */\nexport const devnetChain: Chain = defineChain({\n id: Number.parseInt(import.meta.env.ETHEREUM_TENDERLY_FORK_ID, 10),\n name: 'Devnet',\n network: 'ethereum-fork',\n nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },\n rpcUrls: {\n default: { http: [import.meta.env.ETHEREUM_TENDERLY_PUBLIC_RPC] },\n },\n blockExplorers: {\n default: {\n name: 'Devnet Explorer',\n url: import.meta.env.ETHEREUM_TENDERLY_BLOCKEXPLORER,\n },\n },\n});\n\n/**\n * @internal\n */\nexport const supportedChains: Record<\n ChainId,\n ReturnType<typeof defineChain>\n> = {\n // TODO add them back when deployed on these chains\n // [chainId(mainnet.id)]: mainnet,\n // [chainId(sepolia.id)]: sepolia,\n [chainId(devnetChain.id)]: devnetChain,\n};\n\nfunction ensureChain(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<void, CancelError | SigningError> {\n return ResultAsync.fromPromise(walletClient.getChainId(), (err) =>\n SigningError.from(err),\n ).andThen((chainId) => {\n if (chainId === request.chainId) {\n return okAsync();\n }\n\n return ResultAsync.fromPromise(\n walletClient.switchChain({ id: request.chainId }),\n (err) => SigningError.from(err),\n ).orElse((err) => {\n const code = isRpcError(err.cause)\n ? err.cause.code\n : // Unwrapping for MetaMask Mobile\n // https://github.com/MetaMask/metamask-mobile/issues/2944#issuecomment-976988719\n isProviderRpcError(err.cause)\n ? err.cause.data?.originalError?.code\n : undefined;\n\n if (\n code === SwitchChainError.code &&\n request.chainId in supportedChains\n ) {\n return ResultAsync.fromPromise(\n walletClient.addChain({ chain: supportedChains[request.chainId] }),\n (err) => {\n if (isRpcError(err) && err.code === UserRejectedRequestError.code) {\n return CancelError.from(err);\n }\n return SigningError.from(err);\n },\n );\n }\n\n return err.asResultAsync();\n });\n });\n}\n\nfunction estimateGas(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<bigint, SigningError> {\n return ResultAsync.fromPromise(\n estimateGasWithViem(walletClient, {\n account: walletClient.account,\n data: request.data,\n to: request.to,\n value: BigInt(request.value),\n }),\n (err) => SigningError.from(err),\n ).map((gas) => (gas * 115n) / 100n); // 15% buffer\n}\n\nfunction sendEip1559Transaction(\n walletClient: WalletClient<Transport, Chain, Account>,\n request: TransactionRequest,\n): ResultAsync<TxHash, CancelError | SigningError> {\n return estimateGas(walletClient, request)\n .andThen((gas) =>\n ResultAsync.fromPromise(\n sendTransactionWithViem(walletClient, {\n account: walletClient.account,\n data: request.data,\n to: request.to,\n value: BigInt(request.value),\n chain: walletClient.chain,\n gas,\n }),\n (err) => {\n if (err instanceof TransactionExecutionError) {\n const rejected = err.walk(\n (err) => err instanceof UserRejectedRequestError,\n );\n\n if (rejected) {\n return CancelError.from(rejected);\n }\n }\n return SigningError.from(err);\n },\n ),\n )\n .map(txHash);\n}\n\nfunction isWalletClientWithAccount(\n walletClient: WalletClient,\n): walletClient is WalletClient<Transport, Chain, Account> {\n return walletClient.account !== undefined;\n}\n\n/**\n * @internal\n */\nexport function sendTransaction(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<TxHash, CancelError | SigningError> {\n invariant(\n isWalletClientWithAccount(walletClient),\n 'Wallet client with account is required',\n );\n\n return ensureChain(walletClient, request).andThen((_) =>\n sendEip1559Transaction(walletClient, request),\n );\n}\n\n/**\n * @internal\n */\nexport function transactionError(\n chain: Chain | undefined,\n txHash: TxHash,\n request: TransactionRequest,\n): TransactionError {\n const baseUrl = chain?.blockExplorers?.default?.url;\n const link = baseUrl && new URL(`/tx/${txHash}`, baseUrl).toString();\n\n return TransactionError.new({ txHash, request, link });\n}\n\n/**\n * @internal\n */\nexport function waitForTransactionResult(\n walletClient: WalletClient,\n request: TransactionRequest,\n initialTxHash: TxHash,\n): ResultAsync<\n TransactionResult,\n CancelError | TransactionError | UnexpectedError\n> {\n return ResultAsync.fromPromise(\n waitForTransactionReceipt(walletClient, {\n hash: initialTxHash,\n pollingInterval: 100,\n retryCount: 20,\n retryDelay: 50,\n }),\n (err) => UnexpectedError.from(err),\n ).andThen((receipt) => {\n const hash = txHash(receipt.transactionHash);\n\n switch (receipt.status) {\n case 'reverted':\n if (initialTxHash !== hash) {\n return errAsync(CancelError.from(`Transaction replaced by ${hash}`));\n }\n return errAsync(transactionError(walletClient.chain, hash, request));\n case 'success':\n return okAsync({\n // viem's waitForTransactionReceipt supports transaction replacement\n // so it's important to use the transaction hash from the receipt\n txHash: hash,\n operations: request.operations,\n });\n }\n });\n}\n\nfunction sendTransactionAndWait(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<\n TransactionResult,\n CancelError | SigningError | TransactionError | UnexpectedError\n> {\n return sendTransaction(walletClient, request).andThen((hash) =>\n waitForTransactionResult(walletClient, request, hash),\n );\n}\n\nfunction executePlan(\n walletClient: WalletClient,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(walletClient, result);\n\n case 'Erc20ApprovalRequired':\n case 'PreContractActionRequired':\n return sendTransactionAndWait(walletClient, result.transaction).andThen(\n () => sendTransactionAndWait(walletClient, result.originalTransaction),\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 provided wallet client.\n */\nexport function sendWith(walletClient: WalletClient): ExecutionPlanHandler;\n/**\n * Sends execution plan transactions using the provided wallet client.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n walletClient: WalletClient,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n walletClient: WalletClient,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(walletClient, result)\n : executePlan.bind(null, walletClient);\n}\n\nfunction signERC20Permit(\n walletClient: WalletClient,\n result: PermitTypedDataResponse,\n): ReturnType<ERC20PermitHandler> {\n invariant(walletClient.account, 'Wallet account is required');\n\n return ResultAsync.fromPromise(\n signTypedData(walletClient, {\n account: walletClient.account,\n domain: result.domain as TypedDataDomain,\n types: result.types as TypedData,\n primaryType: result.primaryType as keyof typeof result.types,\n message: result.message,\n }),\n (err) => SigningError.from(err),\n ).map((hex) => ({\n deadline: result.message.deadline,\n value: signatureFrom(hex),\n }));\n}\n\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the provided wallet client.\n */\nexport function signERC20PermitWith(\n walletClient: WalletClient,\n): ERC20PermitHandler {\n return signERC20Permit.bind(null, walletClient);\n}\n\nfunction signSwapTypedData(\n walletClient: WalletClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n invariant(walletClient.account, 'Wallet account is required');\n\n return ResultAsync.fromPromise(\n signTypedData(walletClient, {\n account: walletClient.account,\n domain: result.domain as TypedDataDomain,\n types: result.types as TypedData,\n primaryType: result.primaryType,\n message: JSON.parse(result.message),\n }),\n (err) => SigningError.from(err),\n ).map((hex) => ({\n deadline: JSON.parse(result.message).deadline,\n value: signatureFrom(hex),\n }));\n}\n\n/**\n * @internal\n * Creates a swap signature handler that signs swap typed data using the provided wallet client.\n */\nexport function signSwapTypedDataWith(\n walletClient: WalletClient,\n): SwapSignatureHandler;\n/**\n * @internal\n * Signs swap typed data using the provided wallet client.\n */\nexport function signSwapTypedDataWith(\n walletClient: WalletClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n walletClient: WalletClient,\n result?: SwapByIntentTypedData | CancelSwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(walletClient, result)\n : signSwapTypedData.bind(null, walletClient);\n}\n"]}
|
package/dist/viem.d.cts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TransactionRequest } from '@aave/graphql';
|
|
3
|
-
import { ChainId,
|
|
4
|
-
import {
|
|
5
|
-
import { T as
|
|
1
|
+
import { CancelError, SigningError, TransactionError, UnexpectedError } from '@aave/core';
|
|
2
|
+
import { TransactionRequest, ExecutionPlan, SwapByIntentTypedData, CancelSwapTypedData } from '@aave/graphql';
|
|
3
|
+
import { ChainId, ResultAsync, TxHash } from '@aave/types';
|
|
4
|
+
import { Chain, defineChain, WalletClient } from 'viem';
|
|
5
|
+
import { T as TransactionResult, E as ExecutionPlanHandler, a as ERC20PermitHandler, S as SwapSignatureHandler } from './types-Bu63z0x6.cjs';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
declare const devnetChain: Chain;
|
|
7
11
|
/**
|
|
8
12
|
* @internal
|
|
9
13
|
*/
|
|
10
14
|
declare const supportedChains: Record<ChainId, ReturnType<typeof defineChain>>;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
declare function sendTransaction(walletClient: WalletClient, request: TransactionRequest): ResultAsync<TxHash, CancelError | SigningError>;
|
|
11
19
|
/**
|
|
12
20
|
* @internal
|
|
13
21
|
*/
|
|
@@ -15,16 +23,28 @@ declare function transactionError(chain: Chain | undefined, txHash: TxHash, requ
|
|
|
15
23
|
/**
|
|
16
24
|
* @internal
|
|
17
25
|
*/
|
|
18
|
-
declare function
|
|
26
|
+
declare function waitForTransactionResult(walletClient: WalletClient, request: TransactionRequest, initialTxHash: TxHash): ResultAsync<TransactionResult, CancelError | TransactionError | UnexpectedError>;
|
|
19
27
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* Handles {@link TransactionRequest} by signing and sending, {@link ApprovalRequired} by sending both approval and original transactions, and returns validation errors for {@link InsufficientBalanceError}.
|
|
28
|
+
* Creates an execution plan handler that sends transactions using the provided wallet client.
|
|
23
29
|
*/
|
|
24
30
|
declare function sendWith(walletClient: WalletClient): ExecutionPlanHandler;
|
|
25
31
|
/**
|
|
26
|
-
*
|
|
32
|
+
* Sends execution plan transactions using the provided wallet client.
|
|
33
|
+
*/
|
|
34
|
+
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(walletClient: WalletClient, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates an ERC20 permit handler that signs ERC20 permits using the provided wallet client.
|
|
37
|
+
*/
|
|
38
|
+
declare function signERC20PermitWith(walletClient: WalletClient): ERC20PermitHandler;
|
|
39
|
+
/**
|
|
40
|
+
* @internal
|
|
41
|
+
* Creates a swap signature handler that signs swap typed data using the provided wallet client.
|
|
42
|
+
*/
|
|
43
|
+
declare function signSwapTypedDataWith(walletClient: WalletClient): SwapSignatureHandler;
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
* Signs swap typed data using the provided wallet client.
|
|
27
47
|
*/
|
|
28
|
-
declare function
|
|
48
|
+
declare function signSwapTypedDataWith(walletClient: WalletClient, result: SwapByIntentTypedData | CancelSwapTypedData): ReturnType<SwapSignatureHandler>;
|
|
29
49
|
|
|
30
|
-
export {
|
|
50
|
+
export { devnetChain, sendTransaction, sendWith, signERC20PermitWith, signSwapTypedDataWith, supportedChains, transactionError, waitForTransactionResult };
|
package/dist/viem.d.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TransactionRequest } from '@aave/graphql';
|
|
3
|
-
import { ChainId,
|
|
4
|
-
import {
|
|
5
|
-
import { T as
|
|
1
|
+
import { CancelError, SigningError, TransactionError, UnexpectedError } from '@aave/core';
|
|
2
|
+
import { TransactionRequest, ExecutionPlan, SwapByIntentTypedData, CancelSwapTypedData } from '@aave/graphql';
|
|
3
|
+
import { ChainId, ResultAsync, TxHash } from '@aave/types';
|
|
4
|
+
import { Chain, defineChain, WalletClient } from 'viem';
|
|
5
|
+
import { T as TransactionResult, E as ExecutionPlanHandler, a as ERC20PermitHandler, S as SwapSignatureHandler } from './types-Bu63z0x6.js';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
declare const devnetChain: Chain;
|
|
7
11
|
/**
|
|
8
12
|
* @internal
|
|
9
13
|
*/
|
|
10
14
|
declare const supportedChains: Record<ChainId, ReturnType<typeof defineChain>>;
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
declare function sendTransaction(walletClient: WalletClient, request: TransactionRequest): ResultAsync<TxHash, CancelError | SigningError>;
|
|
11
19
|
/**
|
|
12
20
|
* @internal
|
|
13
21
|
*/
|
|
@@ -15,16 +23,28 @@ declare function transactionError(chain: Chain | undefined, txHash: TxHash, requ
|
|
|
15
23
|
/**
|
|
16
24
|
* @internal
|
|
17
25
|
*/
|
|
18
|
-
declare function
|
|
26
|
+
declare function waitForTransactionResult(walletClient: WalletClient, request: TransactionRequest, initialTxHash: TxHash): ResultAsync<TransactionResult, CancelError | TransactionError | UnexpectedError>;
|
|
19
27
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* Handles {@link TransactionRequest} by signing and sending, {@link ApprovalRequired} by sending both approval and original transactions, and returns validation errors for {@link InsufficientBalanceError}.
|
|
28
|
+
* Creates an execution plan handler that sends transactions using the provided wallet client.
|
|
23
29
|
*/
|
|
24
30
|
declare function sendWith(walletClient: WalletClient): ExecutionPlanHandler;
|
|
25
31
|
/**
|
|
26
|
-
*
|
|
32
|
+
* Sends execution plan transactions using the provided wallet client.
|
|
33
|
+
*/
|
|
34
|
+
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(walletClient: WalletClient, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
35
|
+
/**
|
|
36
|
+
* Creates an ERC20 permit handler that signs ERC20 permits using the provided wallet client.
|
|
37
|
+
*/
|
|
38
|
+
declare function signERC20PermitWith(walletClient: WalletClient): ERC20PermitHandler;
|
|
39
|
+
/**
|
|
40
|
+
* @internal
|
|
41
|
+
* Creates a swap signature handler that signs swap typed data using the provided wallet client.
|
|
42
|
+
*/
|
|
43
|
+
declare function signSwapTypedDataWith(walletClient: WalletClient): SwapSignatureHandler;
|
|
44
|
+
/**
|
|
45
|
+
* @internal
|
|
46
|
+
* Signs swap typed data using the provided wallet client.
|
|
27
47
|
*/
|
|
28
|
-
declare function
|
|
48
|
+
declare function signSwapTypedDataWith(walletClient: WalletClient, result: SwapByIntentTypedData | CancelSwapTypedData): ReturnType<SwapSignatureHandler>;
|
|
29
49
|
|
|
30
|
-
export {
|
|
50
|
+
export { devnetChain, sendTransaction, sendWith, signERC20PermitWith, signSwapTypedDataWith, supportedChains, transactionError, waitForTransactionResult };
|
package/dist/viem.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{c as
|
|
1
|
+
export{a as devnetChain,c as sendTransaction,f as sendWith,g as signERC20PermitWith,h as signSwapTypedDataWith,b as supportedChains,d as transactionError,e as waitForTransactionResult}from'./chunk-2TNQ52OQ.js';//# sourceMappingURL=viem.js.map
|
|
2
2
|
//# sourceMappingURL=viem.js.map
|