@aave/client 4.0.0-next.1 → 4.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/AaveClient-CgHY2iS9.d.ts +82 -0
  2. package/dist/AaveClient-L3v8kWvn.d.cts +82 -0
  3. package/dist/actions/index.cjs +2 -0
  4. package/dist/actions/index.cjs.map +1 -0
  5. package/dist/actions/index.d.cts +1033 -0
  6. package/dist/actions/index.d.ts +1033 -0
  7. package/dist/actions/index.js +2 -0
  8. package/dist/actions/index.js.map +1 -0
  9. package/dist/chunk-2TNQ52OQ.js +3 -0
  10. package/dist/chunk-2TNQ52OQ.js.map +1 -0
  11. package/dist/chunk-BQFM5RT3.js +2 -0
  12. package/dist/chunk-BQFM5RT3.js.map +1 -0
  13. package/dist/chunk-BQNVAUS6.js +3 -0
  14. package/dist/chunk-BQNVAUS6.js.map +1 -0
  15. package/dist/ethers.cjs +2 -0
  16. package/dist/ethers.cjs.map +1 -0
  17. package/dist/ethers.d.cts +38 -0
  18. package/dist/ethers.d.ts +38 -0
  19. package/dist/ethers.js +2 -0
  20. package/dist/ethers.js.map +1 -0
  21. package/dist/index.cjs +3 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.cts +23 -0
  24. package/dist/index.d.ts +23 -0
  25. package/dist/index.js +2 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/options-vB2peXdE.d.cts +35 -0
  28. package/dist/options-vB2peXdE.d.ts +35 -0
  29. package/dist/privy.cjs +3 -0
  30. package/dist/privy.cjs.map +1 -0
  31. package/dist/privy.d.cts +30 -0
  32. package/dist/privy.d.ts +30 -0
  33. package/dist/privy.js +2 -0
  34. package/dist/privy.js.map +1 -0
  35. package/dist/test-utils.cjs +3 -0
  36. package/dist/test-utils.cjs.map +1 -0
  37. package/dist/test-utils.d.cts +49 -0
  38. package/dist/test-utils.d.ts +49 -0
  39. package/dist/test-utils.js +3 -0
  40. package/dist/test-utils.js.map +1 -0
  41. package/dist/thirdweb.cjs +3 -0
  42. package/dist/thirdweb.cjs.map +1 -0
  43. package/dist/thirdweb.d.cts +30 -0
  44. package/dist/thirdweb.d.ts +30 -0
  45. package/dist/thirdweb.js +3 -0
  46. package/dist/thirdweb.js.map +1 -0
  47. package/dist/types-Bu63z0x6.d.cts +21 -0
  48. package/dist/types-Bu63z0x6.d.ts +21 -0
  49. package/dist/utils/index.cjs +2 -0
  50. package/dist/utils/index.cjs.map +1 -0
  51. package/dist/utils/index.d.cts +18 -0
  52. package/dist/utils/index.d.ts +18 -0
  53. package/dist/utils/index.js +2 -0
  54. package/dist/utils/index.js.map +1 -0
  55. package/dist/viem.cjs +3 -0
  56. package/dist/viem.cjs.map +1 -0
  57. package/dist/viem.d.cts +50 -0
  58. package/dist/viem.d.ts +50 -0
  59. package/dist/viem.js +2 -0
  60. package/dist/viem.js.map +1 -0
  61. package/package.json +4 -4
@@ -0,0 +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","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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CACjC,MAAA,CAAAD,CAAAA,CACA,MAAOiB,oBAAAA,CAAY,CAAE,GAAIL,CAAAA,CAAO,MAAA,CAAO,OAAQ,CAAC,CAAA,CAChD,QAASW,CAAAA,CAAQ,IACnB,CAAC,CAAA,CAE8B,aAAA,CAAc,CAE3C,KAAA,CAAOX,CAAAA,CAAO,KAAA,CACd,MAAA,CAAQA,CAAAA,CAAO,MAAA,CACf,YAAaA,CAAAA,CAAO,WAAA,CACpB,QAAAW,CACF,CAAC,EAED,OAAOL,mBAAAA,CAAcF,CAAS,CAChC,CAAA,CAEA,OAAOd,iBAAAA,CAAY,WAAA,CAAYsB,GAAqB,CAAIrB,CAAAA,EACtDC,kBAAa,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.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"]}
@@ -0,0 +1,30 @@
1
+ import { ExecutionPlan, SwapByIntentTypedData, CancelSwapTypedData } from '@aave/graphql';
2
+ import { ThirdwebClient } from 'thirdweb';
3
+ import { E as ExecutionPlanHandler, a as ERC20PermitHandler, S as SwapSignatureHandler } from './types-Bu63z0x6.cjs';
4
+ import '@aave/core';
5
+ import '@aave/types';
6
+
7
+ /**
8
+ * Creates an execution plan handler that sends transactions using the provided Thirdweb client and account.
9
+ */
10
+ declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(client: ThirdwebClient): ExecutionPlanHandler<T>;
11
+ /**
12
+ * Sends execution plan transactions using the provided Thirdweb client.
13
+ */
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>;
29
+
30
+ export { sendWith, signERC20PermitWith, signSwapTypedDataWith };
@@ -0,0 +1,30 @@
1
+ import { ExecutionPlan, SwapByIntentTypedData, CancelSwapTypedData } from '@aave/graphql';
2
+ import { ThirdwebClient } from 'thirdweb';
3
+ import { E as ExecutionPlanHandler, a as ERC20PermitHandler, S as SwapSignatureHandler } from './types-Bu63z0x6.js';
4
+ import '@aave/core';
5
+ import '@aave/types';
6
+
7
+ /**
8
+ * Creates an execution plan handler that sends transactions using the provided Thirdweb client and account.
9
+ */
10
+ declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(client: ThirdwebClient): ExecutionPlanHandler<T>;
11
+ /**
12
+ * Sends execution plan transactions using the provided Thirdweb client.
13
+ */
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>;
29
+
30
+ export { sendWith, signERC20PermitWith, signSwapTypedDataWith };
@@ -0,0 +1,3 @@
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
+ //# sourceMappingURL=thirdweb.js.map
@@ -0,0 +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","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,E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AY,CAAAA,CACkC,CAClC,IAAMW,CAAAA,CAAU,KAAK,KAAA,CAAMX,CAAAA,CAAO,OAAO,CAAA,CAEnCY,CAAAA,CAAuB,SAAgC,CAO3D,IAAMR,CAAAA,CAAY,MANHf,MAAAA,CAAO,YAAA,CAAa,CACjC,MAAA,CAAAD,CAAAA,CACA,MAAOiB,WAAAA,CAAY,CAAE,GAAIL,CAAAA,CAAO,MAAA,CAAO,OAAQ,CAAC,CAAA,CAChD,QAASW,CAAAA,CAAQ,IACnB,CAAC,CAAA,CAE8B,aAAA,CAAc,CAE3C,KAAA,CAAOX,CAAAA,CAAO,KAAA,CACd,MAAA,CAAQA,CAAAA,CAAO,MAAA,CACf,YAAaA,CAAAA,CAAO,WAAA,CACpB,QAAAW,CACF,CAAC,EAED,OAAOL,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 ADDED
@@ -0,0 +1,3 @@
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
+ //# sourceMappingURL=viem.cjs.map
@@ -0,0 +1 @@
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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AS,CACd,QAAA,CAAUL,EAAO,OAAA,CAAQ,QAAA,CACzB,MAAOM,mBAAAA,CAAcD,CAAG,CAC1B,CAAA,CAAE,CACJ,CAKO,SAASE,EACdzC,CAAAA,CACoB,CACpB,OAAOqC,CAAAA,CAAgB,IAAA,CAAK,IAAA,CAAMrC,CAAY,CAChD,CAEA,SAAS0C,EACP1C,CAAAA,CACAkC,CAAAA,CACkC,CAClC,OAAAhB,eAAAA,CAAUlB,CAAAA,CAAa,OAAA,CAAS,4BAA4B,CAAA,CAErDE,iBAAAA,CAAY,YACjBoC,qBAAAA,CAActC,CAAAA,CAAc,CAC1B,OAAA,CAASA,CAAAA,CAAa,QACtB,MAAA,CAAQkC,CAAAA,CAAO,OACf,KAAA,CAAOA,CAAAA,CAAO,MACd,WAAA,CAAaA,CAAAA,CAAO,YACpB,OAAA,CAAS,IAAA,CAAK,KAAA,CAAMA,CAAAA,CAAO,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"]}
@@ -0,0 +1,50 @@
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
+
7
+ /**
8
+ * @internal
9
+ */
10
+ declare const devnetChain: Chain;
11
+ /**
12
+ * @internal
13
+ */
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>;
19
+ /**
20
+ * @internal
21
+ */
22
+ declare function transactionError(chain: Chain | undefined, txHash: TxHash, request: TransactionRequest): TransactionError;
23
+ /**
24
+ * @internal
25
+ */
26
+ declare function waitForTransactionResult(walletClient: WalletClient, request: TransactionRequest, initialTxHash: TxHash): ResultAsync<TransactionResult, CancelError | TransactionError | UnexpectedError>;
27
+ /**
28
+ * Creates an execution plan handler that sends transactions using the provided wallet client.
29
+ */
30
+ declare function sendWith(walletClient: WalletClient): ExecutionPlanHandler;
31
+ /**
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.
47
+ */
48
+ declare function signSwapTypedDataWith(walletClient: WalletClient, result: SwapByIntentTypedData | CancelSwapTypedData): ReturnType<SwapSignatureHandler>;
49
+
50
+ export { devnetChain, sendTransaction, sendWith, signERC20PermitWith, signSwapTypedDataWith, supportedChains, transactionError, waitForTransactionResult };
package/dist/viem.d.ts ADDED
@@ -0,0 +1,50 @@
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
+
7
+ /**
8
+ * @internal
9
+ */
10
+ declare const devnetChain: Chain;
11
+ /**
12
+ * @internal
13
+ */
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>;
19
+ /**
20
+ * @internal
21
+ */
22
+ declare function transactionError(chain: Chain | undefined, txHash: TxHash, request: TransactionRequest): TransactionError;
23
+ /**
24
+ * @internal
25
+ */
26
+ declare function waitForTransactionResult(walletClient: WalletClient, request: TransactionRequest, initialTxHash: TxHash): ResultAsync<TransactionResult, CancelError | TransactionError | UnexpectedError>;
27
+ /**
28
+ * Creates an execution plan handler that sends transactions using the provided wallet client.
29
+ */
30
+ declare function sendWith(walletClient: WalletClient): ExecutionPlanHandler;
31
+ /**
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.
47
+ */
48
+ declare function signSwapTypedDataWith(walletClient: WalletClient, result: SwapByIntentTypedData | CancelSwapTypedData): ReturnType<SwapSignatureHandler>;
49
+
50
+ export { devnetChain, sendTransaction, sendWith, signERC20PermitWith, signSwapTypedDataWith, supportedChains, transactionError, waitForTransactionResult };
package/dist/viem.js ADDED
@@ -0,0 +1,2 @@
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
+ //# sourceMappingURL=viem.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"viem.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aave/client",
3
- "version": "4.0.0-next.1",
3
+ "version": "4.0.0-next.2",
4
4
  "description": "The official TypeScript client for the AaveKit API",
5
5
  "keywords": [
6
6
  "aave",
@@ -88,9 +88,9 @@
88
88
  "@urql/core": "^6.0.1",
89
89
  "@urql/exchange-graphcache": "^8.1.0",
90
90
  "graphql": "^16.11.0",
91
- "@aave/core": "1.0.0-next.0",
92
- "@aave/graphql": "1.0.0-next.1",
93
- "@aave/types": "1.0.0-next.0"
91
+ "@aave/types": "1.0.0-next.1",
92
+ "@aave/graphql": "1.0.0-next.2",
93
+ "@aave/core": "1.0.0-next.1"
94
94
  },
95
95
  "devDependencies": {
96
96
  "@bgd-labs/aave-address-book": "^4.25.3",