@aave/client 4.0.0-next.21 → 4.0.0-next.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AaveClient-C36zcfbL.d.ts → AaveClient-BjSHF3YP.d.ts} +1 -1
- package/dist/{AaveClient-BIfAdE-4.d.cts → AaveClient-xmYaeYSl.d.cts} +1 -1
- package/dist/actions/index.cjs +1 -1
- package/dist/actions/index.cjs.map +1 -1
- package/dist/actions/index.d.cts +4 -26
- package/dist/actions/index.d.ts +4 -26
- package/dist/actions/index.js +1 -1
- package/dist/chunk-IDO2PFSI.js +2 -0
- package/dist/chunk-IDO2PFSI.js.map +1 -0
- package/dist/chunk-Y6WK5HED.js +3 -0
- package/dist/chunk-Y6WK5HED.js.map +1 -0
- package/dist/ethers.cjs +1 -1
- package/dist/ethers.cjs.map +1 -1
- package/dist/ethers.d.cts +33 -12
- package/dist/ethers.d.ts +33 -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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/privy.cjs +2 -2
- package/dist/privy.cjs.map +1 -1
- package/dist/privy.d.cts +35 -12
- package/dist/privy.d.ts +35 -12
- package/dist/privy.js +1 -1
- package/dist/privy.js.map +1 -1
- package/dist/testing.js +13 -13
- package/dist/testing.js.map +1 -1
- package/dist/thirdweb.cjs +1 -1
- package/dist/thirdweb.cjs.map +1 -1
- package/dist/thirdweb.d.cts +34 -13
- package/dist/thirdweb.d.ts +34 -13
- package/dist/thirdweb.js +1 -1
- package/dist/thirdweb.js.map +1 -1
- package/dist/{types-CQvue0x0.d.cts → types-fGKXqIpf.d.cts} +8 -5
- package/dist/{types-CQvue0x0.d.ts → types-fGKXqIpf.d.ts} +8 -5
- package/dist/viem.cjs +2 -2
- package/dist/viem.cjs.map +1 -1
- package/dist/viem.d.cts +34 -17
- package/dist/viem.d.ts +34 -17
- package/dist/viem.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-3HZQC3YV.js +0 -3
- package/dist/chunk-3HZQC3YV.js.map +0 -1
- package/dist/chunk-MKZBFAXA.js +0 -2
- package/dist/chunk-MKZBFAXA.js.map +0 -1
package/dist/thirdweb.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var core=require('@aave/core'),types=require('@aave/types'),thirdweb=require('thirdweb'),chains=require('thirdweb/chains'),graphql=require('@aave/graphql');var
|
|
1
|
+
'use strict';var core=require('@aave/core'),types=require('@aave/types'),thirdweb=require('thirdweb'),chains=require('thirdweb/chains'),graphql=require('@aave/graphql');var l={currency:graphql.Currency.Usd,timeWindow:graphql.TimeWindow.LastDay,requestPolicy:"cache-and-network",batch:true};function d(e,t,{batch:n}=l){return e.query(graphql.ChainQuery,{request:t},{batch:n})}function b(e){switch(e.chainId){case types.chainId(chains.mainnet.id):return chains.mainnet;case types.chainId(chains.sepolia.id):return chains.sepolia}return thirdweb.defineChain({id:e.chainId,name:e.name,nativeCurrency:{name:e.nativeInfo.name,symbol:e.nativeInfo.symbol,decimals:e.nativeInfo.decimals},rpcUrls:{default:{http:[e.rpcUrl]}},blockExplorers:{default:{name:`${e.name} Explorer`,url:e.explorerUrl}}})}function S(e,t){switch(t){case types.chainId(chains.mainnet.id):return types.okAsync(chains.mainnet);case types.chainId(chains.sepolia.id):return types.okAsync(chains.sepolia)}return d(e,{chainId:t},{batch:false}).andThen(n=>(types.invariant(n,`Chain ${t} is not supported`),types.okAsync(b(n))))}async function U(e,t,n){let r=await thirdweb.Engine.serverWallet({client:e,chain:t,address:n.from}).sendTransaction({type:"eip1559",chainId:t.id,to:n.to,value:BigInt(n.value),data:n.data});return types.txHash(r.transactionHash)}function i(e,t,n){return S(e,n.chainId).andThen(a=>types.ResultAsync.fromPromise(U(t,a,n),r=>core.SigningError.from(r)).map(async r=>thirdweb.waitForReceipt({client:t,chain:a,transactionHash:r})).andThen(r=>{let p=types.txHash(r.transactionHash);return r.status==="reverted"?types.errAsync(core.TransactionError.new({txHash:p,request:n})):types.okAsync({txHash:p,operations:n.operations})}))}function y(e,t,n){switch(n.__typename){case "TransactionRequest":return i(e,t,n);case "Erc20ApprovalRequired":return i(e,t,n.approval.byTransaction).andThen(()=>i(e,t,n.originalTransaction));case "PreContractActionRequired":return i(e,t,n.transaction).andThen(()=>i(e,t,n.originalTransaction));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(n))}}function G(e,t,n){return n?y(e,t,n):y.bind(null,e,t)}function V(e,t){return t().andThen(n=>{if(n.__typename==="Erc20ApprovalRequired"&&n.approval.bySignature){let a=n.approval.bySignature;return I(e,a).map(r=>({deadline:a.message.deadline,value:r})).andThen(r=>t(r))}return types.okAsync(n)})}function H(e,t){return types.ResultAsync.fromPromise(e.signTypedData({types:t.types,domain:t.domain,primaryType:t.primaryType,message:t.message}),n=>core.SigningError.from(n)).map(types.signatureFrom)}function I(e,t){return H(e,t)}exports.permitWith=V;exports.sendWith=G;exports.signTypedDataWith=I;exports.toThirdwebChain=b;//# sourceMappingURL=thirdweb.cjs.map
|
|
2
2
|
//# sourceMappingURL=thirdweb.cjs.map
|
package/dist/thirdweb.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/options.ts","../src/actions/misc.ts","../src/thirdweb.ts"],"names":["DEFAULT_QUERY_OPTIONS","Currency","TimeWindow","chain","client","request","batch","ChainQuery","toThirdwebChain","chainId","mainnet","sepolia","defineChain","fetchThirdwebChain","id","okAsync","invariant","sendTransaction","thirdwebClient","txResponse","Engine","txHash","sendTransactionAndWait","aaveClient","ResultAsync","err","SigningError","hash","waitForReceipt","receipt","errAsync","TransactionError","executePlan","result","ValidationError","sendWith","signTypedData","wallet","signature","signatureFrom","signERC20PermitWith","value","signSwapTypedData","signTypedDataPromise","signSwapTypedDataWith"],"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,CAAAA,CAAQJ,CAAM,CAAA,CAChCS,CAAAA,CAAkB,IAAA,CAAK,IAAA,CAAML,CAAM,CACzC","file":"thirdweb.cjs","sourcesContent":["import { Currency, TimeWindow } from '@aave/graphql';\nimport type { RequestPolicy } from '@urql/core';\n\nexport type CurrencyQueryOptions = {\n /**\n * The currency for fiat amounts.\n *\n * @defaultValue {@link Currency.Usd}\n */\n currency?: Currency;\n};\n\nexport type TimeWindowQueryOptions = {\n /**\n * The time window for historical data changes.\n *\n * @defaultValue {@link TimeWindow.LastDay}\n */\n timeWindow?: TimeWindow;\n};\n\n/**\n * @internal\n */\nexport type RequestPolicyOptions = {\n /**\n * The request policy to use.\n *\n * @internal This is used for testing purposes and could be changed without notice.\n * @defaultValue `cache-and-network`\n */\n requestPolicy?: RequestPolicy;\n};\n\n/**\n * @internal\n */\nexport type BatchOptions = {\n /**\n * Whether to batch the query or not.\n *\n * @internal This is used to turn off batching for a single query.\n * @defaultValue `true`\n */\n batch?: boolean;\n};\n\nexport const DEFAULT_QUERY_OPTIONS = {\n currency: Currency.Usd,\n timeWindow: TimeWindow.LastDay,\n requestPolicy: 'cache-and-network',\n batch: true,\n} as const;\n","import type { UnexpectedError } from '@aave/core';\nimport {\n type Chain,\n ChainQuery,\n type ChainRequest,\n ChainsQuery,\n type ChainsRequest,\n type ExchangeAmount,\n ExchangeRateQuery,\n type ExchangeRateRequest,\n HasProcessedKnownTransactionQuery,\n type HasProcessedKnownTransactionRequest,\n} from '@aave/graphql';\nimport type { ResultAsync } from '@aave/types';\nimport type { AaveClient } from '../AaveClient';\nimport { type BatchOptions, DEFAULT_QUERY_OPTIONS } from '../options';\n\n/**\n * Fetches a specific chain by chain ID.\n *\n * ```ts\n * const result = await chain(client, {\n * chainId: chainId(1),\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The chain request parameters.\n * @returns The chain data, or null if not found.\n */\n\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n): ResultAsync<Chain | null, UnexpectedError>;\n/**\n * @internal\n */\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n options: BatchOptions,\n): ResultAsync<Chain | null, UnexpectedError>;\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n { batch }: BatchOptions = DEFAULT_QUERY_OPTIONS,\n): ResultAsync<Chain | null, UnexpectedError> {\n return client.query(ChainQuery, { request }, { batch });\n}\n\n/**\n * Fetches the list of supported chains.\n *\n * ```ts\n * const chains = await chains(client, {\n * query: { filter: ChainsFilter.ALL }\n * });\n * ```\n *\n * ```ts\n * const chains = await chains(client, {\n * query: { chainIds: [chainId(1), chainId(137)] }\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The chains request parameters.\n * @returns Array of supported chains.\n */\nexport function chains(\n client: AaveClient,\n request: ChainsRequest,\n): ResultAsync<Chain[], UnexpectedError> {\n return client.query(ChainsQuery, { request });\n}\n\n/**\n * Check if a transaction has been processed by the Aave API.\n *\n * @param client - Aave client.\n * @param request - The request containing transaction hash and operations to check.\n * @returns True if the transaction has been processed, false otherwise.\n */\nexport function hasProcessedKnownTransaction(\n client: AaveClient,\n request: HasProcessedKnownTransactionRequest,\n): ResultAsync<boolean, UnexpectedError> {\n return client.query(\n HasProcessedKnownTransactionQuery,\n { request },\n {\n requestPolicy: 'network-only', // alwats hit the network\n batch: false, // never batch, always run ASAP\n },\n );\n}\n\n/**\n * Fetches the exchange rate between tokens and fiat currencies.\n *\n * ```ts\n * const result = await exchangeRate(client, {\n * from: { erc20: { chainId: chainId(1), address: evmAddress('0xA0b86a33E6...') } },\n * to: Currency.Usd,\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The exchange rate request parameters.\n * @returns The exchange rate information as a fiat amount.\n */\nexport function exchangeRate(\n client: AaveClient,\n request: ExchangeRateRequest,\n): ResultAsync<ExchangeAmount, UnexpectedError> {\n return client.query(ExchangeRateQuery, { request });\n}\n","import {\n SigningError,\n TransactionError,\n type UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n Chain,\n ExecutionPlan,\n PermitTypedDataResponse,\n SwapTypedData,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n type ChainId,\n chainId,\n errAsync,\n invariant,\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 Chain as ThirdwebChain,\n type ThirdwebClient,\n waitForReceipt,\n} from 'thirdweb';\nimport { mainnet, sepolia } from 'thirdweb/chains';\nimport type { AaveClient } from './AaveClient';\nimport { chain as fetchChain } from './actions';\nimport type {\n ERC20PermitHandler,\n ExecutionPlanHandler,\n SwapSignatureHandler,\n TransactionResult,\n} from './types';\n\n/**\n * @internal\n */\nexport function toThirdwebChain(chain: Chain): ThirdwebChain {\n // known chains\n switch (chain.chainId) {\n case chainId(mainnet.id):\n return mainnet;\n\n case chainId(sepolia.id):\n return sepolia;\n }\n\n // most likely a tenderly fork\n return defineChain({\n id: chain.chainId,\n name: chain.name,\n nativeCurrency: {\n name: chain.nativeInfo.name,\n symbol: chain.nativeInfo.symbol,\n decimals: chain.nativeInfo.decimals,\n },\n rpcUrls: { default: { http: [chain.rpcUrl] } },\n blockExplorers: {\n default: {\n name: `${chain.name} Explorer`,\n url: chain.explorerUrl,\n },\n },\n });\n}\n\nfunction fetchThirdwebChain(\n client: AaveClient,\n id: ChainId,\n): ResultAsync<ThirdwebChain, UnexpectedError> {\n switch (id) {\n case chainId(mainnet.id):\n return okAsync(mainnet);\n case chainId(sepolia.id):\n return okAsync(sepolia);\n }\n\n return fetchChain(client, { chainId: id }, { batch: false }).andThen(\n (chain) => {\n invariant(chain, `Chain ${id} is not supported`);\n return okAsync(toThirdwebChain(chain));\n },\n );\n}\n\nasync function sendTransaction(\n thirdwebClient: ThirdwebClient,\n chain: ThirdwebChain,\n request: TransactionRequest,\n): Promise<TxHash> {\n const wallet = Engine.serverWallet({\n client: thirdwebClient,\n chain,\n address: request.from,\n });\n\n const txResponse = await wallet.sendTransaction({\n type: 'eip1559',\n chainId: chain.id,\n to: request.to,\n value: BigInt(request.value),\n data: request.data,\n });\n return txHash(txResponse.transactionHash);\n}\n\nfunction sendTransactionAndWait(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n request: TransactionRequest,\n): ResultAsync<\n TransactionResult,\n SigningError | TransactionError | UnexpectedError\n> {\n return fetchThirdwebChain(aaveClient, request.chainId).andThen((chain) => {\n return ResultAsync.fromPromise(\n sendTransaction(thirdwebClient, chain, request),\n (err) => SigningError.from(err),\n )\n .map(async (hash) =>\n waitForReceipt({\n client: thirdwebClient,\n chain,\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}\n\nfunction executePlan(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(aaveClient, thirdwebClient, result);\n\n case 'Erc20ApprovalRequired':\n case 'PreContractActionRequired':\n return sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.transaction,\n ).andThen(() =>\n sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.originalTransaction,\n ),\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 aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the provided Thirdweb client.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(aaveClient, thirdwebClient, result)\n : executePlan.bind(null, aaveClient, thirdwebClient);\n}\n\nasync function signTypedData(\n wallet: Engine.ServerWallet,\n result: PermitTypedDataResponse,\n): Promise<Signature> {\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\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the provided Thirdweb client and account.\n */\nexport function signERC20PermitWith(\n wallet: Engine.ServerWallet,\n): ERC20PermitHandler {\n return function signERC20Permit(\n result: PermitTypedDataResponse,\n ): ReturnType<ERC20PermitHandler> {\n return ResultAsync.fromPromise(signTypedData(wallet, result), (err) =>\n SigningError.from(err),\n ).map((value) => ({\n deadline: result.message.deadline,\n value,\n }));\n };\n}\n\nfunction signSwapTypedData(\n wallet: Engine.ServerWallet,\n result: SwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n const signTypedDataPromise = async (): Promise<Signature> => {\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\n return ResultAsync.fromPromise(signTypedDataPromise(), (err) =>\n SigningError.from(err),\n ).map(signatureFrom);\n}\n\n/**\n * Creates a swap signature handler that signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n wallet: Engine.ServerWallet,\n): SwapSignatureHandler;\n/**\n * Signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n wallet: Engine.ServerWallet,\n result: SwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n wallet: Engine.ServerWallet,\n result?: SwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(wallet, result)\n : signSwapTypedData.bind(null, wallet);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/options.ts","../src/actions/misc.ts","../src/thirdweb.ts"],"names":["DEFAULT_QUERY_OPTIONS","Currency","TimeWindow","chain","client","request","batch","ChainQuery","toThirdwebChain","chainId","mainnet","sepolia","defineChain","fetchThirdwebChain","id","okAsync","invariant","sendTransaction","thirdwebClient","txResponse","Engine","txHash","sendTransactionAndWait","aaveClient","ResultAsync","err","SigningError","hash","waitForReceipt","receipt","errAsync","TransactionError","executePlan","result","ValidationError","sendWith","permitWith","wallet","action","permitTypedData","signTypedDataWith","signature","permitSig","signTypedData","data","signatureFrom"],"mappings":"yKA+CO,IAAMA,CAAAA,CAAwB,CACnC,QAAA,CAAUC,gBAAAA,CAAS,GAAA,CACnB,UAAA,CAAYC,kBAAAA,CAAW,OAAA,CACvB,aAAA,CAAe,mBAAA,CACf,KAAA,CAAO,IACT,CAAA,CCTO,SAASC,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACA,CAAE,KAAA,CAAAC,CAAM,CAAA,CAAkBN,CAAAA,CACkB,CAC5C,OAAOI,CAAAA,CAAO,KAAA,CAAMG,kBAAAA,CAAY,CAAE,OAAA,CAAAF,CAAQ,CAAA,CAAG,CAAE,KAAA,CAAAC,CAAM,CAAC,CACxD,CCLO,SAASE,CAAAA,CAAgBL,CAAAA,CAA6B,CAE3D,OAAQA,CAAAA,CAAM,OAAA,EACZ,KAAKM,aAAAA,CAAQC,cAAAA,CAAQ,EAAE,CAAA,CACrB,OAAOA,cAAAA,CAET,KAAKD,aAAAA,CAAQE,cAAAA,CAAQ,EAAE,CAAA,CACrB,OAAOA,cACX,CAGA,OAAOC,oBAAAA,CAAY,CACjB,EAAA,CAAIT,CAAAA,CAAM,OAAA,CACV,IAAA,CAAMA,CAAAA,CAAM,IAAA,CACZ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A,CAAQkB,CAAM,CACvB,CAAC,CACH,CAEA,SAASU,CAAAA,CACPN,CAAAA,CACAO,CAAAA,CACsC,CACtC,OAAOpB,iBAAAA,CAAY,WAAA,CACjBa,CAAAA,CAAO,cAAc,CACnB,KAAA,CAAOO,CAAAA,CAAK,KAAA,CACZ,MAAA,CAAQA,CAAAA,CAAK,MAAA,CACb,WAAA,CAAaA,CAAAA,CAAK,WAAA,CAClB,OAAA,CAASA,CAAAA,CAAK,OAChB,CAAC,CAAA,CACAnB,CAAAA,EAAQC,kBAAa,IAAA,CAAKD,CAAG,CAChC,CAAA,CAAE,GAAA,CAAIoB,mBAAa,CACrB,CAUO,SAASL,CAAAA,CACdH,CAAAA,CACAO,CAAAA,CAC4C,CAC5C,OAAOD,CAAAA,CAAcN,CAAAA,CAAQO,CAAI,CACnC","file":"thirdweb.cjs","sourcesContent":["import { Currency, TimeWindow } from '@aave/graphql';\nimport type { RequestPolicy } from '@urql/core';\n\nexport type CurrencyQueryOptions = {\n /**\n * The currency for fiat amounts.\n *\n * @defaultValue {@link Currency.Usd}\n */\n currency?: Currency;\n};\n\nexport type TimeWindowQueryOptions = {\n /**\n * The time window for historical data changes.\n *\n * @defaultValue {@link TimeWindow.LastDay}\n */\n timeWindow?: TimeWindow;\n};\n\n/**\n * @internal\n */\nexport type RequestPolicyOptions = {\n /**\n * The request policy to use.\n *\n * @internal This is used for testing purposes and could be changed without notice.\n * @defaultValue `cache-and-network`\n */\n requestPolicy?: RequestPolicy;\n};\n\n/**\n * @internal\n */\nexport type BatchOptions = {\n /**\n * Whether to batch the query or not.\n *\n * @internal This is used to turn off batching for a single query.\n * @defaultValue `true`\n */\n batch?: boolean;\n};\n\nexport const DEFAULT_QUERY_OPTIONS = {\n currency: Currency.Usd,\n timeWindow: TimeWindow.LastDay,\n requestPolicy: 'cache-and-network',\n batch: true,\n} as const;\n","import type { UnexpectedError } from '@aave/core';\nimport {\n type Chain,\n ChainQuery,\n type ChainRequest,\n ChainsQuery,\n type ChainsRequest,\n type ExchangeAmount,\n ExchangeRateQuery,\n type ExchangeRateRequest,\n HasProcessedKnownTransactionQuery,\n type HasProcessedKnownTransactionRequest,\n} from '@aave/graphql';\nimport type { ResultAsync } from '@aave/types';\nimport type { AaveClient } from '../AaveClient';\nimport { type BatchOptions, DEFAULT_QUERY_OPTIONS } from '../options';\n\n/**\n * Fetches a specific chain by chain ID.\n *\n * ```ts\n * const result = await chain(client, {\n * chainId: chainId(1),\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The chain request parameters.\n * @returns The chain data, or null if not found.\n */\n\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n): ResultAsync<Chain | null, UnexpectedError>;\n/**\n * @internal\n */\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n options: BatchOptions,\n): ResultAsync<Chain | null, UnexpectedError>;\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n { batch }: BatchOptions = DEFAULT_QUERY_OPTIONS,\n): ResultAsync<Chain | null, UnexpectedError> {\n return client.query(ChainQuery, { request }, { batch });\n}\n\n/**\n * Fetches the list of supported chains.\n *\n * ```ts\n * const chains = await chains(client, {\n * query: { filter: ChainsFilter.ALL }\n * });\n * ```\n *\n * ```ts\n * const chains = await chains(client, {\n * query: { chainIds: [chainId(1), chainId(137)] }\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The chains request parameters.\n * @returns Array of supported chains.\n */\nexport function chains(\n client: AaveClient,\n request: ChainsRequest,\n): ResultAsync<Chain[], UnexpectedError> {\n return client.query(ChainsQuery, { request });\n}\n\n/**\n * Check if a transaction has been processed by the Aave API.\n *\n * @param client - Aave client.\n * @param request - The request containing transaction hash and operations to check.\n * @returns True if the transaction has been processed, false otherwise.\n */\nexport function hasProcessedKnownTransaction(\n client: AaveClient,\n request: HasProcessedKnownTransactionRequest,\n): ResultAsync<boolean, UnexpectedError> {\n return client.query(\n HasProcessedKnownTransactionQuery,\n { request },\n {\n requestPolicy: 'network-only', // alwats hit the network\n batch: false, // never batch, always run ASAP\n },\n );\n}\n\n/**\n * Fetches the exchange rate between tokens and fiat currencies.\n *\n * ```ts\n * const result = await exchangeRate(client, {\n * from: { erc20: { chainId: chainId(1), address: evmAddress('0xA0b86a33E6...') } },\n * to: Currency.Usd,\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The exchange rate request parameters.\n * @returns The exchange rate information as a fiat amount.\n */\nexport function exchangeRate(\n client: AaveClient,\n request: ExchangeRateRequest,\n): ResultAsync<ExchangeAmount, UnexpectedError> {\n return client.query(ExchangeRateQuery, { request });\n}\n","import {\n SigningError,\n TransactionError,\n type UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n Chain,\n ERC20PermitSignature,\n ExecutionPlan,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n type ChainId,\n chainId,\n errAsync,\n invariant,\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 Chain as ThirdwebChain,\n type ThirdwebClient,\n waitForReceipt,\n} from 'thirdweb';\nimport { mainnet, sepolia } from 'thirdweb/chains';\nimport type { AaveClient } from './AaveClient';\nimport { chain as fetchChain } from './actions';\nimport type {\n ExecutionPlanHandler,\n SignTypedDataError,\n TransactionResult,\n TypedData,\n} from './types';\n\n/**\n * @internal\n */\nexport function toThirdwebChain(chain: Chain): ThirdwebChain {\n // known chains\n switch (chain.chainId) {\n case chainId(mainnet.id):\n return mainnet;\n\n case chainId(sepolia.id):\n return sepolia;\n }\n\n // most likely a tenderly fork\n return defineChain({\n id: chain.chainId,\n name: chain.name,\n nativeCurrency: {\n name: chain.nativeInfo.name,\n symbol: chain.nativeInfo.symbol,\n decimals: chain.nativeInfo.decimals,\n },\n rpcUrls: { default: { http: [chain.rpcUrl] } },\n blockExplorers: {\n default: {\n name: `${chain.name} Explorer`,\n url: chain.explorerUrl,\n },\n },\n });\n}\n\nfunction fetchThirdwebChain(\n client: AaveClient,\n id: ChainId,\n): ResultAsync<ThirdwebChain, UnexpectedError> {\n switch (id) {\n case chainId(mainnet.id):\n return okAsync(mainnet);\n case chainId(sepolia.id):\n return okAsync(sepolia);\n }\n\n return fetchChain(client, { chainId: id }, { batch: false }).andThen(\n (chain) => {\n invariant(chain, `Chain ${id} is not supported`);\n return okAsync(toThirdwebChain(chain));\n },\n );\n}\n\nasync function sendTransaction(\n thirdwebClient: ThirdwebClient,\n chain: ThirdwebChain,\n request: TransactionRequest,\n): Promise<TxHash> {\n const wallet = Engine.serverWallet({\n client: thirdwebClient,\n chain,\n address: request.from,\n });\n\n const txResponse = await wallet.sendTransaction({\n type: 'eip1559',\n chainId: chain.id,\n to: request.to,\n value: BigInt(request.value),\n data: request.data,\n });\n return txHash(txResponse.transactionHash);\n}\n\nfunction sendTransactionAndWait(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n request: TransactionRequest,\n): ResultAsync<\n TransactionResult,\n SigningError | TransactionError | UnexpectedError\n> {\n return fetchThirdwebChain(aaveClient, request.chainId).andThen((chain) => {\n return ResultAsync.fromPromise(\n sendTransaction(thirdwebClient, chain, request),\n (err) => SigningError.from(err),\n )\n .map(async (hash) =>\n waitForReceipt({\n client: thirdwebClient,\n chain,\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}\n\nfunction executePlan(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(aaveClient, thirdwebClient, result);\n\n case 'Erc20ApprovalRequired':\n return sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.approval.byTransaction,\n ).andThen(() =>\n sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.originalTransaction,\n ),\n );\n\n case 'PreContractActionRequired':\n return sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.transaction,\n ).andThen(() =>\n sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.originalTransaction,\n ),\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 aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the provided Thirdweb client.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(aaveClient, thirdwebClient, result)\n : executePlan.bind(null, aaveClient, thirdwebClient);\n}\n\n/**\n * Handles ERC20 permit signing for actions that require token approval.\n *\n * Calls the action to get an initial execution plan. If the plan requires ERC20 approval\n * and the token supports permit signatures, signs the permit and re-calls the action\n * with the signature to get a new plan that can be sent directly.\n *\n * ```ts\n * const result = await permitWith(wallet, (permitSig) =>\n * supply(client, {\n * reserve: reserve.id,\n * amount: { erc20: { value: amount, permitSig } },\n * sender: evmAddress(wallet.address),\n * })\n * )\n * .andThen(sendWith(wallet))\n * .andThen(client.waitForTransaction);\n * ```\n *\n * @param wallet - The Thirdweb server wallet for signing permits.\n * @param action - A function that returns an execution plan, accepting an optional permit signature.\n * @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.\n */\nexport function permitWith<E>(\n wallet: Engine.ServerWallet,\n action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>,\n): ResultAsync<ExecutionPlan, E | SignTypedDataError> {\n return action().andThen((result) => {\n if (\n result.__typename === 'Erc20ApprovalRequired' &&\n result.approval.bySignature\n ) {\n const permitTypedData = result.approval.bySignature;\n return signTypedDataWith(wallet, permitTypedData)\n .map((signature) => ({\n deadline: permitTypedData.message.deadline,\n value: signature,\n }))\n .andThen((permitSig) => action(permitSig));\n }\n return okAsync(result);\n });\n}\n\nfunction signTypedData(\n wallet: Engine.ServerWallet,\n data: TypedData,\n): ResultAsync<Signature, SigningError> {\n return ResultAsync.fromPromise(\n wallet.signTypedData({\n types: data.types,\n domain: data.domain,\n primaryType: data.primaryType,\n message: data.message,\n }),\n (err) => SigningError.from(err),\n ).map(signatureFrom);\n}\n\n/**\n * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.\n * Returns the raw signature without any wrapping. Deadline encapsulation is handled by consumer code.\n *\n * @param wallet - The Thirdweb server wallet to use for signing.\n * @param data - The typed data to sign.\n * @returns A ResultAsync containing the raw signature.\n */\nexport function signTypedDataWith(\n wallet: Engine.ServerWallet,\n data: TypedData,\n): ResultAsync<Signature, SignTypedDataError> {\n return signTypedData(wallet, data);\n}\n"]}
|
package/dist/thirdweb.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Chain, ExecutionPlan,
|
|
1
|
+
import { Chain, ExecutionPlan, ERC20PermitSignature } from '@aave/graphql';
|
|
2
|
+
import { ResultAsync, Signature } from '@aave/types';
|
|
2
3
|
import { Chain as Chain$1, ThirdwebClient, Engine } from 'thirdweb';
|
|
3
|
-
import { A as AaveClient } from './AaveClient-
|
|
4
|
-
import { E as ExecutionPlanHandler,
|
|
4
|
+
import { A as AaveClient } from './AaveClient-xmYaeYSl.cjs';
|
|
5
|
+
import { E as ExecutionPlanHandler, S as SignTypedDataError, a as TypedData } from './types-fGKXqIpf.cjs';
|
|
5
6
|
import '@aave/core';
|
|
6
|
-
import '@aave/types';
|
|
7
7
|
import '@urql/core';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -19,16 +19,37 @@ declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(aaveClient: A
|
|
|
19
19
|
*/
|
|
20
20
|
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(aaveClient: AaveClient, thirdwebClient: ThirdwebClient, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Handles ERC20 permit signing for actions that require token approval.
|
|
23
|
+
*
|
|
24
|
+
* Calls the action to get an initial execution plan. If the plan requires ERC20 approval
|
|
25
|
+
* and the token supports permit signatures, signs the permit and re-calls the action
|
|
26
|
+
* with the signature to get a new plan that can be sent directly.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* const result = await permitWith(wallet, (permitSig) =>
|
|
30
|
+
* supply(client, {
|
|
31
|
+
* reserve: reserve.id,
|
|
32
|
+
* amount: { erc20: { value: amount, permitSig } },
|
|
33
|
+
* sender: evmAddress(wallet.address),
|
|
34
|
+
* })
|
|
35
|
+
* )
|
|
36
|
+
* .andThen(sendWith(wallet))
|
|
37
|
+
* .andThen(client.waitForTransaction);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param wallet - The Thirdweb server wallet for signing permits.
|
|
41
|
+
* @param action - A function that returns an execution plan, accepting an optional permit signature.
|
|
42
|
+
* @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.
|
|
23
43
|
*/
|
|
24
|
-
declare function
|
|
44
|
+
declare function permitWith<E>(wallet: Engine.ServerWallet, action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>): ResultAsync<ExecutionPlan, E | SignTypedDataError>;
|
|
25
45
|
/**
|
|
26
|
-
*
|
|
46
|
+
* Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.
|
|
47
|
+
* Returns the raw signature without any wrapping. Deadline encapsulation is handled by consumer code.
|
|
48
|
+
*
|
|
49
|
+
* @param wallet - The Thirdweb server wallet to use for signing.
|
|
50
|
+
* @param data - The typed data to sign.
|
|
51
|
+
* @returns A ResultAsync containing the raw signature.
|
|
27
52
|
*/
|
|
28
|
-
declare function
|
|
29
|
-
/**
|
|
30
|
-
* Signs swap typed data using the provided Thirdweb client.
|
|
31
|
-
*/
|
|
32
|
-
declare function signSwapTypedDataWith(wallet: Engine.ServerWallet, result: SwapTypedData): ReturnType<SwapSignatureHandler>;
|
|
53
|
+
declare function signTypedDataWith(wallet: Engine.ServerWallet, data: TypedData): ResultAsync<Signature, SignTypedDataError>;
|
|
33
54
|
|
|
34
|
-
export {
|
|
55
|
+
export { permitWith, sendWith, signTypedDataWith, toThirdwebChain };
|
package/dist/thirdweb.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Chain, ExecutionPlan,
|
|
1
|
+
import { Chain, ExecutionPlan, ERC20PermitSignature } from '@aave/graphql';
|
|
2
|
+
import { ResultAsync, Signature } from '@aave/types';
|
|
2
3
|
import { Chain as Chain$1, ThirdwebClient, Engine } from 'thirdweb';
|
|
3
|
-
import { A as AaveClient } from './AaveClient-
|
|
4
|
-
import { E as ExecutionPlanHandler,
|
|
4
|
+
import { A as AaveClient } from './AaveClient-BjSHF3YP.js';
|
|
5
|
+
import { E as ExecutionPlanHandler, S as SignTypedDataError, a as TypedData } from './types-fGKXqIpf.js';
|
|
5
6
|
import '@aave/core';
|
|
6
|
-
import '@aave/types';
|
|
7
7
|
import '@urql/core';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -19,16 +19,37 @@ declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(aaveClient: A
|
|
|
19
19
|
*/
|
|
20
20
|
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(aaveClient: AaveClient, thirdwebClient: ThirdwebClient, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* Handles ERC20 permit signing for actions that require token approval.
|
|
23
|
+
*
|
|
24
|
+
* Calls the action to get an initial execution plan. If the plan requires ERC20 approval
|
|
25
|
+
* and the token supports permit signatures, signs the permit and re-calls the action
|
|
26
|
+
* with the signature to get a new plan that can be sent directly.
|
|
27
|
+
*
|
|
28
|
+
* ```ts
|
|
29
|
+
* const result = await permitWith(wallet, (permitSig) =>
|
|
30
|
+
* supply(client, {
|
|
31
|
+
* reserve: reserve.id,
|
|
32
|
+
* amount: { erc20: { value: amount, permitSig } },
|
|
33
|
+
* sender: evmAddress(wallet.address),
|
|
34
|
+
* })
|
|
35
|
+
* )
|
|
36
|
+
* .andThen(sendWith(wallet))
|
|
37
|
+
* .andThen(client.waitForTransaction);
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param wallet - The Thirdweb server wallet for signing permits.
|
|
41
|
+
* @param action - A function that returns an execution plan, accepting an optional permit signature.
|
|
42
|
+
* @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.
|
|
23
43
|
*/
|
|
24
|
-
declare function
|
|
44
|
+
declare function permitWith<E>(wallet: Engine.ServerWallet, action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>): ResultAsync<ExecutionPlan, E | SignTypedDataError>;
|
|
25
45
|
/**
|
|
26
|
-
*
|
|
46
|
+
* Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.
|
|
47
|
+
* Returns the raw signature without any wrapping. Deadline encapsulation is handled by consumer code.
|
|
48
|
+
*
|
|
49
|
+
* @param wallet - The Thirdweb server wallet to use for signing.
|
|
50
|
+
* @param data - The typed data to sign.
|
|
51
|
+
* @returns A ResultAsync containing the raw signature.
|
|
27
52
|
*/
|
|
28
|
-
declare function
|
|
29
|
-
/**
|
|
30
|
-
* Signs swap typed data using the provided Thirdweb client.
|
|
31
|
-
*/
|
|
32
|
-
declare function signSwapTypedDataWith(wallet: Engine.ServerWallet, result: SwapTypedData): ReturnType<SwapSignatureHandler>;
|
|
53
|
+
declare function signTypedDataWith(wallet: Engine.ServerWallet, data: TypedData): ResultAsync<Signature, SignTypedDataError>;
|
|
33
54
|
|
|
34
|
-
export {
|
|
55
|
+
export { permitWith, sendWith, signTypedDataWith, toThirdwebChain };
|
package/dist/thirdweb.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {f}from'./chunk-
|
|
1
|
+
import {f}from'./chunk-IDO2PFSI.js';import {ValidationError,SigningError,TransactionError}from'@aave/core';import {chainId,okAsync,errAsync,ResultAsync,signatureFrom,txHash,invariant}from'@aave/types';import {defineChain,waitForReceipt,Engine}from'thirdweb';import {sepolia,mainnet}from'thirdweb/chains';function R(n){switch(n.chainId){case chainId(mainnet.id):return mainnet;case chainId(sepolia.id):return sepolia}return defineChain({id:n.chainId,name:n.name,nativeCurrency:{name:n.nativeInfo.name,symbol:n.nativeInfo.symbol,decimals:n.nativeInfo.decimals},rpcUrls:{default:{http:[n.rpcUrl]}},blockExplorers:{default:{name:`${n.name} Explorer`,url:n.explorerUrl}}})}function A(n,r){switch(r){case chainId(mainnet.id):return okAsync(mainnet);case chainId(sepolia.id):return okAsync(sepolia)}return f(n,{chainId:r},{batch:false}).andThen(e=>(invariant(e,`Chain ${r} is not supported`),okAsync(R(e))))}async function b(n,r,e){let a=await Engine.serverWallet({client:n,chain:r,address:e.from}).sendTransaction({type:"eip1559",chainId:r.id,to:e.to,value:BigInt(e.value),data:e.data});return txHash(a.transactionHash)}function i(n,r,e){return A(n,e.chainId).andThen(t=>ResultAsync.fromPromise(b(r,t,e),a=>SigningError.from(a)).map(async a=>waitForReceipt({client:r,chain:t,transactionHash:a})).andThen(a=>{let p=txHash(a.transactionHash);return a.status==="reverted"?errAsync(TransactionError.new({txHash:p,request:e})):okAsync({txHash:p,operations:e.operations})}))}function u(n,r,e){switch(e.__typename){case "TransactionRequest":return i(n,r,e);case "Erc20ApprovalRequired":return i(n,r,e.approval.byTransaction).andThen(()=>i(n,r,e.originalTransaction));case "PreContractActionRequired":return i(n,r,e.transaction).andThen(()=>i(n,r,e.originalTransaction));case "InsufficientBalanceError":return errAsync(ValidationError.fromGqlNode(e))}}function _(n,r,e){return e?u(n,r,e):u.bind(null,n,r)}function q(n,r){return r().andThen(e=>{if(e.__typename==="Erc20ApprovalRequired"&&e.approval.bySignature){let t=e.approval.bySignature;return S(n,t).map(a=>({deadline:t.message.deadline,value:a})).andThen(a=>r(a))}return okAsync(e)})}function w(n,r){return ResultAsync.fromPromise(n.signTypedData({types:r.types,domain:r.domain,primaryType:r.primaryType,message:r.message}),e=>SigningError.from(e)).map(signatureFrom)}function S(n,r){return w(n,r)}export{q as permitWith,_ as sendWith,S as signTypedDataWith,R as toThirdwebChain};//# sourceMappingURL=thirdweb.js.map
|
|
2
2
|
//# sourceMappingURL=thirdweb.js.map
|
package/dist/thirdweb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/thirdweb.ts"],"names":["toThirdwebChain","chain","chainId","mainnet","sepolia","defineChain","fetchThirdwebChain","client","id","okAsync","invariant","sendTransaction","thirdwebClient","request","txResponse","Engine","txHash","sendTransactionAndWait","aaveClient","ResultAsync","err","SigningError","hash","waitForReceipt","receipt","errAsync","TransactionError","executePlan","result","ValidationError","sendWith","signTypedData","wallet","signature","signatureFrom","signERC20PermitWith","value","signSwapTypedData","signTypedDataPromise","signSwapTypedDataWith"],"mappings":"gTA6CO,SAASA,CAAAA,CAAgBC,CAAAA,CAA6B,CAE3D,OAAQA,CAAAA,CAAM,OAAA,EACZ,KAAKC,OAAAA,CAAQC,OAAAA,CAAQ,EAAE,CAAA,CACrB,OAAOA,OAAAA,CAET,KAAKD,OAAAA,CAAQE,OAAAA,CAAQ,EAAE,CAAA,CACrB,OAAOA,OACX,CAGA,OAAOC,WAAAA,CAAY,CACjB,EAAA,CAAIJ,CAAAA,CAAM,OAAA,CACV,IAAA,CAAMA,CAAAA,CAAM,IA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CAEA,SAASC,CAAAA,CACPL,CAAAA,CACAJ,CAAAA,CACkC,CAClC,IAAMU,CAAAA,CAAuB,SAAgC,CAC3D,IAAML,CAAAA,CAAY,MAAMD,CAAAA,CAAO,aAAA,CAAc,CAE3C,KAAA,CAAOJ,CAAAA,CAAO,KAAA,CACd,MAAA,CAAQA,CAAAA,CAAO,MAAA,CACf,WAAA,CAAaA,CAAAA,CAAO,WAAA,CACpB,OAAA,CAASA,CAAAA,CAAO,OAClB,CAAC,CAAA,CAED,OAAOM,aAAAA,CAAcD,CAAS,CAChC,CAAA,CAEA,OAAOd,YAAY,WAAA,CAAYmB,CAAAA,EAAqB,CAAIlB,CAAAA,EACtDC,YAAAA,CAAa,IAAA,CAAKD,CAAG,CACvB,CAAA,CAAE,GAAA,CAAIc,aAAa,CACrB,CAeO,SAASK,CAAAA,CACdP,CAAAA,CACAJ,CAAAA,CACyD,CACzD,OAAOA,CAAAA,CACHS,CAAAA,CAAkBL,CAAAA,CAAQJ,CAAM,CAAA,CAChCS,CAAAA,CAAkB,IAAA,CAAK,IAAA,CAAML,CAAM,CACzC","file":"thirdweb.js","sourcesContent":["import {\n SigningError,\n TransactionError,\n type UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n Chain,\n ExecutionPlan,\n PermitTypedDataResponse,\n SwapTypedData,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n type ChainId,\n chainId,\n errAsync,\n invariant,\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 Chain as ThirdwebChain,\n type ThirdwebClient,\n waitForReceipt,\n} from 'thirdweb';\nimport { mainnet, sepolia } from 'thirdweb/chains';\nimport type { AaveClient } from './AaveClient';\nimport { chain as fetchChain } from './actions';\nimport type {\n ERC20PermitHandler,\n ExecutionPlanHandler,\n SwapSignatureHandler,\n TransactionResult,\n} from './types';\n\n/**\n * @internal\n */\nexport function toThirdwebChain(chain: Chain): ThirdwebChain {\n // known chains\n switch (chain.chainId) {\n case chainId(mainnet.id):\n return mainnet;\n\n case chainId(sepolia.id):\n return sepolia;\n }\n\n // most likely a tenderly fork\n return defineChain({\n id: chain.chainId,\n name: chain.name,\n nativeCurrency: {\n name: chain.nativeInfo.name,\n symbol: chain.nativeInfo.symbol,\n decimals: chain.nativeInfo.decimals,\n },\n rpcUrls: { default: { http: [chain.rpcUrl] } },\n blockExplorers: {\n default: {\n name: `${chain.name} Explorer`,\n url: chain.explorerUrl,\n },\n },\n });\n}\n\nfunction fetchThirdwebChain(\n client: AaveClient,\n id: ChainId,\n): ResultAsync<ThirdwebChain, UnexpectedError> {\n switch (id) {\n case chainId(mainnet.id):\n return okAsync(mainnet);\n case chainId(sepolia.id):\n return okAsync(sepolia);\n }\n\n return fetchChain(client, { chainId: id }, { batch: false }).andThen(\n (chain) => {\n invariant(chain, `Chain ${id} is not supported`);\n return okAsync(toThirdwebChain(chain));\n },\n );\n}\n\nasync function sendTransaction(\n thirdwebClient: ThirdwebClient,\n chain: ThirdwebChain,\n request: TransactionRequest,\n): Promise<TxHash> {\n const wallet = Engine.serverWallet({\n client: thirdwebClient,\n chain,\n address: request.from,\n });\n\n const txResponse = await wallet.sendTransaction({\n type: 'eip1559',\n chainId: chain.id,\n to: request.to,\n value: BigInt(request.value),\n data: request.data,\n });\n return txHash(txResponse.transactionHash);\n}\n\nfunction sendTransactionAndWait(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n request: TransactionRequest,\n): ResultAsync<\n TransactionResult,\n SigningError | TransactionError | UnexpectedError\n> {\n return fetchThirdwebChain(aaveClient, request.chainId).andThen((chain) => {\n return ResultAsync.fromPromise(\n sendTransaction(thirdwebClient, chain, request),\n (err) => SigningError.from(err),\n )\n .map(async (hash) =>\n waitForReceipt({\n client: thirdwebClient,\n chain,\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}\n\nfunction executePlan(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(aaveClient, thirdwebClient, result);\n\n case 'Erc20ApprovalRequired':\n case 'PreContractActionRequired':\n return sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.transaction,\n ).andThen(() =>\n sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.originalTransaction,\n ),\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 aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the provided Thirdweb client.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(aaveClient, thirdwebClient, result)\n : executePlan.bind(null, aaveClient, thirdwebClient);\n}\n\nasync function signTypedData(\n wallet: Engine.ServerWallet,\n result: PermitTypedDataResponse,\n): Promise<Signature> {\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\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the provided Thirdweb client and account.\n */\nexport function signERC20PermitWith(\n wallet: Engine.ServerWallet,\n): ERC20PermitHandler {\n return function signERC20Permit(\n result: PermitTypedDataResponse,\n ): ReturnType<ERC20PermitHandler> {\n return ResultAsync.fromPromise(signTypedData(wallet, result), (err) =>\n SigningError.from(err),\n ).map((value) => ({\n deadline: result.message.deadline,\n value,\n }));\n };\n}\n\nfunction signSwapTypedData(\n wallet: Engine.ServerWallet,\n result: SwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n const signTypedDataPromise = async (): Promise<Signature> => {\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\n return ResultAsync.fromPromise(signTypedDataPromise(), (err) =>\n SigningError.from(err),\n ).map(signatureFrom);\n}\n\n/**\n * Creates a swap signature handler that signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n wallet: Engine.ServerWallet,\n): SwapSignatureHandler;\n/**\n * Signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n wallet: Engine.ServerWallet,\n result: SwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n wallet: Engine.ServerWallet,\n result?: SwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(wallet, result)\n : signSwapTypedData.bind(null, wallet);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/thirdweb.ts"],"names":["toThirdwebChain","chain","chainId","mainnet","sepolia","defineChain","fetchThirdwebChain","client","id","okAsync","invariant","sendTransaction","thirdwebClient","request","txResponse","Engine","txHash","sendTransactionAndWait","aaveClient","ResultAsync","err","SigningError","hash","waitForReceipt","receipt","errAsync","TransactionError","executePlan","result","ValidationError","sendWith","permitWith","wallet","action","permitTypedData","signTypedDataWith","signature","permitSig","signTypedData","data","signatureFrom"],"mappings":"gTA4CO,SAASA,CAAA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,CAAAA,CAAkBN,CAAAA,CAAO,QAAA,CAAS,WAAA,CACxC,OAAOO,EAAkBH,CAAAA,CAAQE,CAAe,CAAA,CAC7C,GAAA,CAAKE,CAAAA,GAAe,CACnB,QAAA,CAAUF,CAAAA,CAAgB,OAAA,CAAQ,QAAA,CAClC,KAAA,CAAOE,CACT,CAAA,CAAE,CAAA,CACD,QAASC,CAAAA,EAAcJ,CAAAA,CAAOI,CAAS,CAAC,CAC7C,CACA,OAAO5B,OAAAA,CAAQmB,CAAM,CACvB,CAAC,CACH,CAEA,SAASU,EACPN,CAAAA,CACAO,CAAAA,CACsC,CACtC,OAAOpB,WAAAA,CAAY,WAAA,CACjBa,CAAAA,CAAO,aAAA,CAAc,CACnB,KAAA,CAAOO,CAAAA,CAAK,KAAA,CACZ,MAAA,CAAQA,CAAAA,CAAK,OACb,WAAA,CAAaA,CAAAA,CAAK,WAAA,CAClB,OAAA,CAASA,CAAAA,CAAK,OAChB,CAAC,CAAA,CACAnB,CAAAA,EAAQC,YAAAA,CAAa,IAAA,CAAKD,CAAG,CAChC,CAAA,CAAE,IAAIoB,aAAa,CACrB,CAUO,SAASL,CAAAA,CACdH,CAAAA,CACAO,CAAAA,CAC4C,CAC5C,OAAOD,CAAAA,CAAcN,CAAAA,CAAQO,CAAI,CACnC","file":"thirdweb.js","sourcesContent":["import {\n SigningError,\n TransactionError,\n type UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n Chain,\n ERC20PermitSignature,\n ExecutionPlan,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n type ChainId,\n chainId,\n errAsync,\n invariant,\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 Chain as ThirdwebChain,\n type ThirdwebClient,\n waitForReceipt,\n} from 'thirdweb';\nimport { mainnet, sepolia } from 'thirdweb/chains';\nimport type { AaveClient } from './AaveClient';\nimport { chain as fetchChain } from './actions';\nimport type {\n ExecutionPlanHandler,\n SignTypedDataError,\n TransactionResult,\n TypedData,\n} from './types';\n\n/**\n * @internal\n */\nexport function toThirdwebChain(chain: Chain): ThirdwebChain {\n // known chains\n switch (chain.chainId) {\n case chainId(mainnet.id):\n return mainnet;\n\n case chainId(sepolia.id):\n return sepolia;\n }\n\n // most likely a tenderly fork\n return defineChain({\n id: chain.chainId,\n name: chain.name,\n nativeCurrency: {\n name: chain.nativeInfo.name,\n symbol: chain.nativeInfo.symbol,\n decimals: chain.nativeInfo.decimals,\n },\n rpcUrls: { default: { http: [chain.rpcUrl] } },\n blockExplorers: {\n default: {\n name: `${chain.name} Explorer`,\n url: chain.explorerUrl,\n },\n },\n });\n}\n\nfunction fetchThirdwebChain(\n client: AaveClient,\n id: ChainId,\n): ResultAsync<ThirdwebChain, UnexpectedError> {\n switch (id) {\n case chainId(mainnet.id):\n return okAsync(mainnet);\n case chainId(sepolia.id):\n return okAsync(sepolia);\n }\n\n return fetchChain(client, { chainId: id }, { batch: false }).andThen(\n (chain) => {\n invariant(chain, `Chain ${id} is not supported`);\n return okAsync(toThirdwebChain(chain));\n },\n );\n}\n\nasync function sendTransaction(\n thirdwebClient: ThirdwebClient,\n chain: ThirdwebChain,\n request: TransactionRequest,\n): Promise<TxHash> {\n const wallet = Engine.serverWallet({\n client: thirdwebClient,\n chain,\n address: request.from,\n });\n\n const txResponse = await wallet.sendTransaction({\n type: 'eip1559',\n chainId: chain.id,\n to: request.to,\n value: BigInt(request.value),\n data: request.data,\n });\n return txHash(txResponse.transactionHash);\n}\n\nfunction sendTransactionAndWait(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n request: TransactionRequest,\n): ResultAsync<\n TransactionResult,\n SigningError | TransactionError | UnexpectedError\n> {\n return fetchThirdwebChain(aaveClient, request.chainId).andThen((chain) => {\n return ResultAsync.fromPromise(\n sendTransaction(thirdwebClient, chain, request),\n (err) => SigningError.from(err),\n )\n .map(async (hash) =>\n waitForReceipt({\n client: thirdwebClient,\n chain,\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}\n\nfunction executePlan(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(aaveClient, thirdwebClient, result);\n\n case 'Erc20ApprovalRequired':\n return sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.approval.byTransaction,\n ).andThen(() =>\n sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.originalTransaction,\n ),\n );\n\n case 'PreContractActionRequired':\n return sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.transaction,\n ).andThen(() =>\n sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n result.originalTransaction,\n ),\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 aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the provided Thirdweb client.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n aaveClient: AaveClient,\n thirdwebClient: ThirdwebClient,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(aaveClient, thirdwebClient, result)\n : executePlan.bind(null, aaveClient, thirdwebClient);\n}\n\n/**\n * Handles ERC20 permit signing for actions that require token approval.\n *\n * Calls the action to get an initial execution plan. If the plan requires ERC20 approval\n * and the token supports permit signatures, signs the permit and re-calls the action\n * with the signature to get a new plan that can be sent directly.\n *\n * ```ts\n * const result = await permitWith(wallet, (permitSig) =>\n * supply(client, {\n * reserve: reserve.id,\n * amount: { erc20: { value: amount, permitSig } },\n * sender: evmAddress(wallet.address),\n * })\n * )\n * .andThen(sendWith(wallet))\n * .andThen(client.waitForTransaction);\n * ```\n *\n * @param wallet - The Thirdweb server wallet for signing permits.\n * @param action - A function that returns an execution plan, accepting an optional permit signature.\n * @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.\n */\nexport function permitWith<E>(\n wallet: Engine.ServerWallet,\n action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>,\n): ResultAsync<ExecutionPlan, E | SignTypedDataError> {\n return action().andThen((result) => {\n if (\n result.__typename === 'Erc20ApprovalRequired' &&\n result.approval.bySignature\n ) {\n const permitTypedData = result.approval.bySignature;\n return signTypedDataWith(wallet, permitTypedData)\n .map((signature) => ({\n deadline: permitTypedData.message.deadline,\n value: signature,\n }))\n .andThen((permitSig) => action(permitSig));\n }\n return okAsync(result);\n });\n}\n\nfunction signTypedData(\n wallet: Engine.ServerWallet,\n data: TypedData,\n): ResultAsync<Signature, SigningError> {\n return ResultAsync.fromPromise(\n wallet.signTypedData({\n types: data.types,\n domain: data.domain,\n primaryType: data.primaryType,\n message: data.message,\n }),\n (err) => SigningError.from(err),\n ).map(signatureFrom);\n}\n\n/**\n * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.\n * Returns the raw signature without any wrapping. Deadline encapsulation is handled by consumer code.\n *\n * @param wallet - The Thirdweb server wallet to use for signing.\n * @param data - The typed data to sign.\n * @returns A ResultAsync containing the raw signature.\n */\nexport function signTypedDataWith(\n wallet: Engine.ServerWallet,\n data: TypedData,\n): ResultAsync<Signature, SignTypedDataError> {\n return signTypedData(wallet, data);\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CancelError, SigningError, TransactionError, ValidationError, UnexpectedError } from '@aave/core';
|
|
2
|
-
import { OperationType, ExecutionPlan, InsufficientBalanceError,
|
|
3
|
-
import { TxHash, ResultAsync
|
|
2
|
+
import { OperationType, ExecutionPlan, InsufficientBalanceError, PermitTypedData, SwapTypedData, HasProcessedKnownTransactionRequest } from '@aave/graphql';
|
|
3
|
+
import { TxHash, ResultAsync } from '@aave/types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
@@ -15,7 +15,10 @@ type TransactionResult = {
|
|
|
15
15
|
declare function isHasProcessedKnownTransactionRequest(result: TransactionResult): result is HasProcessedKnownTransactionRequest;
|
|
16
16
|
type SendWithError = CancelError | SigningError | TransactionError | ValidationError<InsufficientBalanceError> | UnexpectedError;
|
|
17
17
|
type ExecutionPlanHandler<T extends ExecutionPlan = ExecutionPlan> = (result: T) => ResultAsync<TransactionResult, SendWithError>;
|
|
18
|
-
type
|
|
19
|
-
|
|
18
|
+
type SignTypedDataError = CancelError | SigningError;
|
|
19
|
+
/**
|
|
20
|
+
* Union type for all EIP-712 typed data structures used in the SDK.
|
|
21
|
+
*/
|
|
22
|
+
type TypedData = PermitTypedData | SwapTypedData;
|
|
20
23
|
|
|
21
|
-
export { type ExecutionPlanHandler as E, type
|
|
24
|
+
export { type ExecutionPlanHandler as E, type SignTypedDataError as S, type TransactionResult as T, type TypedData as a, type SendWithError as b, isHasProcessedKnownTransactionRequest as i };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CancelError, SigningError, TransactionError, ValidationError, UnexpectedError } from '@aave/core';
|
|
2
|
-
import { OperationType, ExecutionPlan, InsufficientBalanceError,
|
|
3
|
-
import { TxHash, ResultAsync
|
|
2
|
+
import { OperationType, ExecutionPlan, InsufficientBalanceError, PermitTypedData, SwapTypedData, HasProcessedKnownTransactionRequest } from '@aave/graphql';
|
|
3
|
+
import { TxHash, ResultAsync } from '@aave/types';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @internal
|
|
@@ -15,7 +15,10 @@ type TransactionResult = {
|
|
|
15
15
|
declare function isHasProcessedKnownTransactionRequest(result: TransactionResult): result is HasProcessedKnownTransactionRequest;
|
|
16
16
|
type SendWithError = CancelError | SigningError | TransactionError | ValidationError<InsufficientBalanceError> | UnexpectedError;
|
|
17
17
|
type ExecutionPlanHandler<T extends ExecutionPlan = ExecutionPlan> = (result: T) => ResultAsync<TransactionResult, SendWithError>;
|
|
18
|
-
type
|
|
19
|
-
|
|
18
|
+
type SignTypedDataError = CancelError | SigningError;
|
|
19
|
+
/**
|
|
20
|
+
* Union type for all EIP-712 typed data structures used in the SDK.
|
|
21
|
+
*/
|
|
22
|
+
type TypedData = PermitTypedData | SwapTypedData;
|
|
20
23
|
|
|
21
|
-
export { type ExecutionPlanHandler as E, type
|
|
24
|
+
export { type ExecutionPlanHandler as E, type SignTypedDataError as S, type TransactionResult as T, type TypedData as a, type SendWithError as b, isHasProcessedKnownTransactionRequest as i };
|
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'),chains=require('viem/chains'),graphql=require('@aave/graphql');var
|
|
2
|
-
exports.ensureChain=
|
|
1
|
+
'use strict';var core=require('@aave/core'),types=require('@aave/types'),viem=require('viem'),actions=require('viem/actions'),chains=require('viem/chains'),graphql=require('@aave/graphql');var f={currency:graphql.Currency.Usd,timeWindow:graphql.TimeWindow.LastDay,requestPolicy:"cache-and-network",batch:true};function T(n,e,{batch:r}=f){return n.query(graphql.ChainQuery,{request:e},{batch:r})}function m(n){return types.isObject(n)&&"code"in n&&"message"in n}function L(n){return types.isObject(n)&&"name"in n&&"message"in n&&"originalError"in n?m(n.originalError)&&"code"in n.originalError:true}function B(n,e){return types.invariant(n.account,"Wallet account is required to sign typed data"),types.ResultAsync.fromPromise(n.signTypedData({account:n.account,domain:e.domain,types:e.types,primaryType:e.primaryType,message:e.message}),r=>r instanceof viem.UserRejectedRequestError?core.CancelError.from(r):core.SigningError.from(r)).map(types.signatureFrom)}var x=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/"}}}),pn={[types.chainId(x.id)]:x};function W(n){switch(n.chainId){case types.chainId(chains.mainnet.id):return chains.mainnet;case types.chainId(chains.sepolia.id):return chains.sepolia}return viem.defineChain({id:n.chainId,name:n.name,nativeCurrency:{name:n.nativeInfo.name,symbol:n.nativeInfo.symbol,decimals:n.nativeInfo.decimals},rpcUrls:{default:{http:[n.rpcUrl]}},blockExplorers:{default:{name:`${n.name} Explorer`,url:n.explorerUrl}}})}function ln(n){return n.map(W)}function dn(n,e,r){return types.ResultAsync.fromPromise(e.getChainId(),t=>core.SigningError.from(t)).andThen(t=>t===r.chainId?types.okAsync():T(n,{chainId:r.chainId},{batch:false}).andThen(a=>(types.invariant(a,`Chain ${r.chainId} is not supported`),types.ResultAsync.fromPromise(e.switchChain({id:r.chainId}),o=>core.SigningError.from(o)).orElse(o=>(m(o.cause)?o.cause.code:L(o.cause)?o.cause.data?.originalError?.code:void 0)===viem.SwitchChainError.code?types.ResultAsync.fromPromise(e.addChain({chain:W(a)}),u=>m(u)&&u.code===viem.UserRejectedRequestError.code?core.CancelError.from(u):core.SigningError.from(u)):o.asResultAsync()))))}function Q(n,e){return types.ResultAsync.fromPromise(actions.estimateGas(n,{account:n.account,data:e.data,to:e.to,value:BigInt(e.value)}),r=>core.SigningError.from(r)).map(r=>r*115n/100n)}function F(n,e){return Q(n,e).andThen(r=>types.ResultAsync.fromPromise(actions.sendTransaction(n,{account:n.account,data:e.data,to:e.to,value:BigInt(e.value),chain:n.chain,gas:r}),t=>{if(t instanceof viem.TransactionExecutionError){let a=t.walk(o=>o instanceof viem.UserRejectedRequestError);if(a)return core.CancelError.from(a)}return core.SigningError.from(t)})).map(types.txHash)}function N(n){return n.account!==void 0}function K(n,e){return types.invariant(N(n),"Wallet client with account is required"),F(n,e)}function Y(n,e,r){let t=n?.blockExplorers?.default?.url,a=t&&new URL(`/tx/${e}`,t).toString();return core.TransactionError.new({txHash:e,request:r,link:a})}function G(n,e,r){return types.ResultAsync.fromPromise(actions.waitForTransactionReceipt(n,{hash:r,pollingInterval:100,retryCount:20,retryDelay:50}),t=>core.UnexpectedError.from(t)).andThen(t=>{let a=types.txHash(t.transactionHash);switch(t.status){case "reverted":return r!==a?types.errAsync(core.CancelError.from(`Transaction replaced by ${a}`)):types.errAsync(Y(n.chain,a,e));case "success":return types.okAsync({txHash:a,operations:e.operations})}})}function s(n,e){return K(n,e).andThen(r=>G(n,e,r))}function g(n,e){switch(e.__typename){case "TransactionRequest":return s(n,e);case "Erc20ApprovalRequired":return s(n,e.approval.byTransaction).andThen(()=>s(n,e.originalTransaction));case "PreContractActionRequired":return s(n,e.transaction).andThen(()=>s(n,e.originalTransaction));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(e))}}function mn(n,e){return e?g(n,e):g.bind(null,n)}function $(n,e){return B(n,e)}function yn(n,e){return e().andThen(r=>{if(r.__typename==="Erc20ApprovalRequired"&&r.approval.bySignature){let t=r.approval.bySignature;return $(n,t).map(a=>({deadline:t.message.deadline,value:a})).andThen(a=>e(a))}return types.okAsync(r)})}
|
|
2
|
+
exports.ensureChain=dn;exports.permitWith=yn;exports.sendTransaction=K;exports.sendWith=mn;exports.signTypedDataWith=$;exports.supportedChains=pn;exports.toViemChain=W;exports.transactionError=Y;exports.viemChainsFrom=ln;exports.waitForTransactionResult=G;//# sourceMappingURL=viem.cjs.map
|
|
3
3
|
//# sourceMappingURL=viem.cjs.map
|
package/dist/viem.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/options.ts","../src/actions/misc.ts","../src/viem.ts"],"names":["DEFAULT_QUERY_OPTIONS","Currency","TimeWindow","chain","client","request","batch","ChainQuery","isRpcError","err","isObject","isProviderRpcError","devnetChain","defineChain","supportedChains","chainId","toViemChain","mainnet","sepolia","viemChainsFrom","chains","ensureChain","aaveClient","walletClient","ResultAsync","SigningError","okAsync","invariant","SwitchChainError","UserRejectedRequestError","CancelError","estimateGas","estimateGasWithViem","gas","sendEip1559Transaction","sendTransactionWithViem","TransactionExecutionError","rejected","txHash","isWalletClientWithAccount","sendTransaction","transactionError","baseUrl","link","TransactionError","waitForTransactionResult","initialTxHash","waitForTransactionReceipt","UnexpectedError","receipt","hash","errAsync","sendTransactionAndWait","executePlan","result","ValidationError","sendWith","signERC20Permit","data","signTypedData","hex","signatureFrom","signERC20PermitWith","signSwapTypedData","signSwapTypedDataWith"],"mappings":"6LA+CO,IAAMA,CAAAA,CAAwB,CACnC,QAAA,CAAUC,iBAAS,GAAA,CACnB,UAAA,CAAYC,kBAAAA,CAAW,OAAA,CACvB,aAAA,CAAe,mBAAA,CACf,MAAO,IACT,CAAA,CCTO,SAASC,CAAAA,CACdC,CAAAA,CACAC,CAAAA,CACA,CAAE,KAAA,CAAAC,CAAM,EAAkBN,CAAAA,CACkB,CAC5C,OAAOI,CAAAA,CAAO,KAAA,CAAMG,kBAAAA,CAAY,CAAE,OAAA,CAAAF,CAAQ,CAAA,CAAG,CAAE,KAAA,CAAAC,CAAM,CAAC,CACxD,CCOA,SAASE,CAAAA,CAAWC,CAAAA,CAA+B,CACjD,OAAOC,cAAAA,CAASD,CAAG,CAAA,EAAK,MAAA,GAAUA,CAAAA,EAAO,YAAaA,CACxD,CAEA,SAASE,CAAAA,CACPF,CAAAA,CAC+D,CAC/D,OAAOC,cAAAA,CAAS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AAIoD,mBAAa,CACrB,CAeO,SAASG,EAAAA,CACdzC,CAAAA,CACA+B,EACyD,CACzD,OAAOA,CAAAA,CACHS,CAAAA,CAAkBxC,CAAAA,CAAc+B,CAAM,EACtCS,CAAAA,CAAkB,IAAA,CAAK,IAAA,CAAMxC,CAAY,CAC/C","file":"viem.cjs","sourcesContent":["import { Currency, TimeWindow } from '@aave/graphql';\nimport type { RequestPolicy } from '@urql/core';\n\nexport type CurrencyQueryOptions = {\n /**\n * The currency for fiat amounts.\n *\n * @defaultValue {@link Currency.Usd}\n */\n currency?: Currency;\n};\n\nexport type TimeWindowQueryOptions = {\n /**\n * The time window for historical data changes.\n *\n * @defaultValue {@link TimeWindow.LastDay}\n */\n timeWindow?: TimeWindow;\n};\n\n/**\n * @internal\n */\nexport type RequestPolicyOptions = {\n /**\n * The request policy to use.\n *\n * @internal This is used for testing purposes and could be changed without notice.\n * @defaultValue `cache-and-network`\n */\n requestPolicy?: RequestPolicy;\n};\n\n/**\n * @internal\n */\nexport type BatchOptions = {\n /**\n * Whether to batch the query or not.\n *\n * @internal This is used to turn off batching for a single query.\n * @defaultValue `true`\n */\n batch?: boolean;\n};\n\nexport const DEFAULT_QUERY_OPTIONS = {\n currency: Currency.Usd,\n timeWindow: TimeWindow.LastDay,\n requestPolicy: 'cache-and-network',\n batch: true,\n} as const;\n","import type { UnexpectedError } from '@aave/core';\nimport {\n type Chain,\n ChainQuery,\n type ChainRequest,\n ChainsQuery,\n type ChainsRequest,\n type ExchangeAmount,\n ExchangeRateQuery,\n type ExchangeRateRequest,\n HasProcessedKnownTransactionQuery,\n type HasProcessedKnownTransactionRequest,\n} from '@aave/graphql';\nimport type { ResultAsync } from '@aave/types';\nimport type { AaveClient } from '../AaveClient';\nimport { type BatchOptions, DEFAULT_QUERY_OPTIONS } from '../options';\n\n/**\n * Fetches a specific chain by chain ID.\n *\n * ```ts\n * const result = await chain(client, {\n * chainId: chainId(1),\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The chain request parameters.\n * @returns The chain data, or null if not found.\n */\n\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n): ResultAsync<Chain | null, UnexpectedError>;\n/**\n * @internal\n */\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n options: BatchOptions,\n): ResultAsync<Chain | null, UnexpectedError>;\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n { batch }: BatchOptions = DEFAULT_QUERY_OPTIONS,\n): ResultAsync<Chain | null, UnexpectedError> {\n return client.query(ChainQuery, { request }, { batch });\n}\n\n/**\n * Fetches the list of supported chains.\n *\n * ```ts\n * const chains = await chains(client, {\n * query: { filter: ChainsFilter.ALL }\n * });\n * ```\n *\n * ```ts\n * const chains = await chains(client, {\n * query: { chainIds: [chainId(1), chainId(137)] }\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The chains request parameters.\n * @returns Array of supported chains.\n */\nexport function chains(\n client: AaveClient,\n request: ChainsRequest,\n): ResultAsync<Chain[], UnexpectedError> {\n return client.query(ChainsQuery, { request });\n}\n\n/**\n * Check if a transaction has been processed by the Aave API.\n *\n * @param client - Aave client.\n * @param request - The request containing transaction hash and operations to check.\n * @returns True if the transaction has been processed, false otherwise.\n */\nexport function hasProcessedKnownTransaction(\n client: AaveClient,\n request: HasProcessedKnownTransactionRequest,\n): ResultAsync<boolean, UnexpectedError> {\n return client.query(\n HasProcessedKnownTransactionQuery,\n { request },\n {\n requestPolicy: 'network-only', // alwats hit the network\n batch: false, // never batch, always run ASAP\n },\n );\n}\n\n/**\n * Fetches the exchange rate between tokens and fiat currencies.\n *\n * ```ts\n * const result = await exchangeRate(client, {\n * from: { erc20: { chainId: chainId(1), address: evmAddress('0xA0b86a33E6...') } },\n * to: Currency.Usd,\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The exchange rate request parameters.\n * @returns The exchange rate information as a fiat amount.\n */\nexport function exchangeRate(\n client: AaveClient,\n request: ExchangeRateRequest,\n): ResultAsync<ExchangeAmount, UnexpectedError> {\n return client.query(ExchangeRateQuery, { request });\n}\n","import {\n CancelError,\n SigningError,\n TransactionError,\n UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n Chain,\n ExecutionPlan,\n PermitTypedDataResponse,\n SwapTypedData,\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 defineChain,\n type ProviderRpcError,\n type RpcError,\n SwitchChainError,\n TransactionExecutionError,\n type Transport,\n type TypedData,\n type TypedDataDomain,\n UserRejectedRequestError,\n type Chain as ViemChain,\n type WalletClient,\n} from 'viem';\nimport {\n estimateGas as estimateGasWithViem,\n sendTransaction as sendTransactionWithViem,\n signTypedData,\n waitForTransactionReceipt,\n} from 'viem/actions';\nimport { mainnet, sepolia } from 'viem/chains';\nimport type { AaveClient } from './AaveClient';\nimport { chain as fetchChain } from './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\nconst devnetChain: ViemChain = 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 * @deprecated\n */\nexport const supportedChains: Record<ChainId, ViemChain> = {\n [chainId(devnetChain.id)]: devnetChain,\n};\n\n/**\n * @internal\n */\nexport function toViemChain(chain: Chain): ViemChain {\n // known chains\n switch (chain.chainId) {\n case chainId(mainnet.id):\n return mainnet;\n\n case chainId(sepolia.id):\n return sepolia;\n }\n\n // most likely a tenderly fork\n return defineChain({\n id: chain.chainId,\n name: chain.name,\n nativeCurrency: {\n name: chain.nativeInfo.name,\n symbol: chain.nativeInfo.symbol,\n decimals: chain.nativeInfo.decimals,\n },\n rpcUrls: { default: { http: [chain.rpcUrl] } },\n blockExplorers: {\n default: {\n name: `${chain.name} Explorer`,\n url: chain.explorerUrl,\n },\n },\n });\n}\n\n/**\n * @internal\n */\nexport function viemChainsFrom(chains: Chain[]): ViemChain[] {\n return chains.map(toViemChain);\n}\n\n/**\n * @internal\n */\nexport function ensureChain(\n aaveClient: AaveClient,\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<void, CancelError | SigningError | UnexpectedError> {\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 fetchChain(\n aaveClient,\n { chainId: request.chainId },\n { batch: false },\n ).andThen((chain) => {\n invariant(chain, `Chain ${request.chainId} is not supported`);\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 (code === SwitchChainError.code) {\n return ResultAsync.fromPromise(\n walletClient.addChain({ chain: toViemChain(chain) }),\n (err) => {\n if (\n isRpcError(err) &&\n err.code === UserRejectedRequestError.code\n ) {\n return CancelError.from(err);\n }\n return SigningError.from(err);\n },\n );\n }\n\n return err.asResultAsync();\n });\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, ViemChain, 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, ViemChain, 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 sendEip1559Transaction(walletClient, request);\n}\n\n/**\n * @internal\n */\nexport function transactionError(\n chain: ViemChain | 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 data: 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: data.domain as TypedDataDomain,\n types: data.types as TypedData,\n primaryType: data.primaryType as keyof typeof data.types,\n message: data.message,\n }),\n (err) => SigningError.from(err),\n ).map((hex) => ({\n deadline: data.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/**\n * Signs ERC20 permits using the provided wallet client.\n */\nexport function signERC20PermitWith(\n walletClient: WalletClient,\n data: PermitTypedDataResponse,\n): ReturnType<ERC20PermitHandler>;\nexport function signERC20PermitWith(\n walletClient: WalletClient,\n data?: PermitTypedDataResponse,\n): ERC20PermitHandler | ReturnType<ERC20PermitHandler> {\n return typeof data === 'undefined'\n ? signERC20Permit.bind(null, walletClient)\n : signERC20Permit(walletClient, data);\n}\n\nfunction signSwapTypedData(\n walletClient: WalletClient,\n result: SwapTypedData,\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: result.message,\n }),\n (err) => SigningError.from(err),\n ).map(signatureFrom);\n}\n\n/**\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 * Signs swap typed data using the provided wallet client.\n */\nexport function signSwapTypedDataWith(\n walletClient: WalletClient,\n result: SwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n walletClient: WalletClient,\n result?: SwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(walletClient, result)\n : signSwapTypedData.bind(null, walletClient);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/options.ts","../src/actions/misc.ts","../src/viem.ts"],"names":["DEFAULT_QUERY_OPTIONS","Currency","TimeWindow","chain","client","request","batch","ChainQuery","isRpcError","err","isObject","isProviderRpcError","signTypedData","walletClient","data","invariant","ResultAsync","UserRejectedRequestError","CancelError","SigningError","signatureFrom","devnetChain","defineChain","supportedChains","chainId","toViemChain","mainnet","sepolia","viemChainsFrom","chains","ensureChain","aaveClient","okAsync","SwitchChainError","estimateGas","estimateGasWithViem","gas","sendEip1559Transaction","sendTransactionWithViem","TransactionExecutionError","rejected","txHash","isWalletClientWithAccount","sendTransaction","transactionError","baseUrl","link","TransactionError","waitForTransactionResult","initialTxHash","waitForTransactionReceipt","UnexpectedError","receipt","hash","errAsync","sendTransactionAndWait","executePlan","result","ValidationError","sendWith","signTypedDataWith","permitWith","action","permitTypedData","signature","permitSig"],"mappings":"6LA+CO,IAAMA,CAAAA,CAAwB,CACnC,QAAA,CAAUC,gBAAAA,CAAS,GAAA,CACnB,WAAYC,kBAAAA,CAAW,OAAA,CACvB,aAAA,CAAe,mBAAA,CACf,KAAA,CAAO,IACT,ECTO,SAASC,CAAAA,CACdC,EACAC,CAAAA,CACA,CAAE,KAAA,CAAAC,CAAM,CAAA,CAAkBN,CAAAA,CACkB,CAC5C,OAAOI,CAAAA,CAAO,KAAA,CAAMG,kBAAAA,CAAY,CAAE,OAAA,CAAAF,CAAQ,CAAA,CAAG,CAAE,KAAA,CAAAC,CAAM,CAAC,CACxD,CCKA,SAASE,CAAAA,CAAWC,EAA+B,CACjD,OAAOC,eAASD,CAAG,CAAA,EAAK,MAAA,GAAUA,CAAAA,EAAO,SAAA,GAAaA,CACxD,CAEA,SAASE,CAAAA,CACPF,CAAAA,CAC+D,CAC/D,OAAOC,cAAAA,CA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H","file":"viem.cjs","sourcesContent":["import { Currency, TimeWindow } from '@aave/graphql';\nimport type { RequestPolicy } from '@urql/core';\n\nexport type CurrencyQueryOptions = {\n /**\n * The currency for fiat amounts.\n *\n * @defaultValue {@link Currency.Usd}\n */\n currency?: Currency;\n};\n\nexport type TimeWindowQueryOptions = {\n /**\n * The time window for historical data changes.\n *\n * @defaultValue {@link TimeWindow.LastDay}\n */\n timeWindow?: TimeWindow;\n};\n\n/**\n * @internal\n */\nexport type RequestPolicyOptions = {\n /**\n * The request policy to use.\n *\n * @internal This is used for testing purposes and could be changed without notice.\n * @defaultValue `cache-and-network`\n */\n requestPolicy?: RequestPolicy;\n};\n\n/**\n * @internal\n */\nexport type BatchOptions = {\n /**\n * Whether to batch the query or not.\n *\n * @internal This is used to turn off batching for a single query.\n * @defaultValue `true`\n */\n batch?: boolean;\n};\n\nexport const DEFAULT_QUERY_OPTIONS = {\n currency: Currency.Usd,\n timeWindow: TimeWindow.LastDay,\n requestPolicy: 'cache-and-network',\n batch: true,\n} as const;\n","import type { UnexpectedError } from '@aave/core';\nimport {\n type Chain,\n ChainQuery,\n type ChainRequest,\n ChainsQuery,\n type ChainsRequest,\n type ExchangeAmount,\n ExchangeRateQuery,\n type ExchangeRateRequest,\n HasProcessedKnownTransactionQuery,\n type HasProcessedKnownTransactionRequest,\n} from '@aave/graphql';\nimport type { ResultAsync } from '@aave/types';\nimport type { AaveClient } from '../AaveClient';\nimport { type BatchOptions, DEFAULT_QUERY_OPTIONS } from '../options';\n\n/**\n * Fetches a specific chain by chain ID.\n *\n * ```ts\n * const result = await chain(client, {\n * chainId: chainId(1),\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The chain request parameters.\n * @returns The chain data, or null if not found.\n */\n\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n): ResultAsync<Chain | null, UnexpectedError>;\n/**\n * @internal\n */\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n options: BatchOptions,\n): ResultAsync<Chain | null, UnexpectedError>;\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n { batch }: BatchOptions = DEFAULT_QUERY_OPTIONS,\n): ResultAsync<Chain | null, UnexpectedError> {\n return client.query(ChainQuery, { request }, { batch });\n}\n\n/**\n * Fetches the list of supported chains.\n *\n * ```ts\n * const chains = await chains(client, {\n * query: { filter: ChainsFilter.ALL }\n * });\n * ```\n *\n * ```ts\n * const chains = await chains(client, {\n * query: { chainIds: [chainId(1), chainId(137)] }\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The chains request parameters.\n * @returns Array of supported chains.\n */\nexport function chains(\n client: AaveClient,\n request: ChainsRequest,\n): ResultAsync<Chain[], UnexpectedError> {\n return client.query(ChainsQuery, { request });\n}\n\n/**\n * Check if a transaction has been processed by the Aave API.\n *\n * @param client - Aave client.\n * @param request - The request containing transaction hash and operations to check.\n * @returns True if the transaction has been processed, false otherwise.\n */\nexport function hasProcessedKnownTransaction(\n client: AaveClient,\n request: HasProcessedKnownTransactionRequest,\n): ResultAsync<boolean, UnexpectedError> {\n return client.query(\n HasProcessedKnownTransactionQuery,\n { request },\n {\n requestPolicy: 'network-only', // alwats hit the network\n batch: false, // never batch, always run ASAP\n },\n );\n}\n\n/**\n * Fetches the exchange rate between tokens and fiat currencies.\n *\n * ```ts\n * const result = await exchangeRate(client, {\n * from: { erc20: { chainId: chainId(1), address: evmAddress('0xA0b86a33E6...') } },\n * to: Currency.Usd,\n * });\n * ```\n *\n * @param client - Aave client.\n * @param request - The exchange rate request parameters.\n * @returns The exchange rate information as a fiat amount.\n */\nexport function exchangeRate(\n client: AaveClient,\n request: ExchangeRateRequest,\n): ResultAsync<ExchangeAmount, UnexpectedError> {\n return client.query(ExchangeRateQuery, { request });\n}\n","import {\n CancelError,\n SigningError,\n TransactionError,\n UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n Chain,\n ERC20PermitSignature,\n ExecutionPlan,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n type ChainId,\n chainId,\n errAsync,\n invariant,\n isObject,\n okAsync,\n ResultAsync,\n type Signature,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport {\n type Account,\n defineChain,\n type ProviderRpcError,\n type RpcError,\n SwitchChainError,\n TransactionExecutionError,\n type Transport,\n type TypedDataDefinition,\n UserRejectedRequestError,\n type Chain as ViemChain,\n type WalletClient,\n} from 'viem';\nimport {\n estimateGas as estimateGasWithViem,\n sendTransaction as sendTransactionWithViem,\n waitForTransactionReceipt,\n} from 'viem/actions';\nimport { mainnet, sepolia } from 'viem/chains';\nimport type { AaveClient } from './AaveClient';\nimport { chain as fetchChain } from './actions';\nimport type {\n ExecutionPlanHandler,\n SignTypedDataError,\n TransactionResult,\n TypedData,\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\nfunction signTypedData(\n walletClient: WalletClient,\n data: TypedDataDefinition<Record<string, unknown>>,\n): ResultAsync<Signature, CancelError | SigningError> {\n invariant(\n walletClient.account,\n 'Wallet account is required to sign typed data',\n );\n\n return ResultAsync.fromPromise(\n walletClient.signTypedData({\n account: walletClient.account,\n domain: data.domain,\n types: data.types,\n primaryType: data.primaryType,\n message: data.message,\n }),\n (err) => {\n if (err instanceof UserRejectedRequestError) {\n return CancelError.from(err);\n }\n return SigningError.from(err);\n },\n ).map(signatureFrom);\n}\n\nconst devnetChain: ViemChain = 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 * @deprecated\n */\nexport const supportedChains: Record<ChainId, ViemChain> = {\n [chainId(devnetChain.id)]: devnetChain,\n};\n\n/**\n * @internal\n */\nexport function toViemChain(chain: Chain): ViemChain {\n // known chains\n switch (chain.chainId) {\n case chainId(mainnet.id):\n return mainnet;\n\n case chainId(sepolia.id):\n return sepolia;\n }\n\n // most likely a tenderly fork\n return defineChain({\n id: chain.chainId,\n name: chain.name,\n nativeCurrency: {\n name: chain.nativeInfo.name,\n symbol: chain.nativeInfo.symbol,\n decimals: chain.nativeInfo.decimals,\n },\n rpcUrls: { default: { http: [chain.rpcUrl] } },\n blockExplorers: {\n default: {\n name: `${chain.name} Explorer`,\n url: chain.explorerUrl,\n },\n },\n });\n}\n\n/**\n * @internal\n */\nexport function viemChainsFrom(chains: Chain[]): ViemChain[] {\n return chains.map(toViemChain);\n}\n\n/**\n * @internal\n */\nexport function ensureChain(\n aaveClient: AaveClient,\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<void, CancelError | SigningError | UnexpectedError> {\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 fetchChain(\n aaveClient,\n { chainId: request.chainId },\n { batch: false },\n ).andThen((chain) => {\n invariant(chain, `Chain ${request.chainId} is not supported`);\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 (code === SwitchChainError.code) {\n return ResultAsync.fromPromise(\n walletClient.addChain({ chain: toViemChain(chain) }),\n (err) => {\n if (\n isRpcError(err) &&\n err.code === UserRejectedRequestError.code\n ) {\n return CancelError.from(err);\n }\n return SigningError.from(err);\n },\n );\n }\n\n return err.asResultAsync();\n });\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, ViemChain, 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, ViemChain, 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 sendEip1559Transaction(walletClient, request);\n}\n\n/**\n * @internal\n */\nexport function transactionError(\n chain: ViemChain | 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 return sendTransactionAndWait(\n walletClient,\n result.approval.byTransaction,\n ).andThen(() =>\n sendTransactionAndWait(walletClient, result.originalTransaction),\n );\n\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\n/**\n * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided wallet client.\n * Returns the raw signature without any wrapping. Deadline encapsulation is handled by consumer code.\n *\n * @param walletClient - The wallet client to use for signing.\n * @param data - The typed data to sign.\n * @returns A ResultAsync containing the raw signature.\n */\nexport function signTypedDataWith(\n walletClient: WalletClient,\n data: TypedData,\n): ResultAsync<Signature, SignTypedDataError> {\n return signTypedData(walletClient, data);\n}\n\n/**\n * Handles ERC20 permit signing for actions that require token approval.\n *\n * Calls the action to get an initial execution plan. If the plan requires ERC20 approval\n * and the token supports permit signatures, signs the permit and re-calls the action\n * with the signature to get a new plan that can be sent directly.\n *\n * ```ts\n * const result = await permitWith(walletClient, (permitSig) =>\n * supply(client, {\n * reserve: reserve.id,\n * amount: { erc20: { value: amount, permitSig } },\n * sender: evmAddress(walletClient.account.address),\n * })\n * )\n * .andThen(sendWith(walletClient))\n * .andThen(client.waitForTransaction);\n * ```\n *\n * @param walletClient - The wallet client to use for signing permits.\n * @param action - A function that returns an execution plan, accepting an optional permit signature.\n * @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.\n */\nexport function permitWith<E>(\n walletClient: WalletClient,\n action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>,\n): ResultAsync<ExecutionPlan, E | SignTypedDataError> {\n return action().andThen((result) => {\n if (\n result.__typename === 'Erc20ApprovalRequired' &&\n result.approval.bySignature\n ) {\n const permitTypedData = result.approval.bySignature;\n // Sign and wrap with deadline\n return signTypedDataWith(walletClient, permitTypedData)\n .map((signature) => ({\n deadline: permitTypedData.message.deadline,\n value: signature,\n }))\n .andThen((permitSig) => action(permitSig));\n }\n return okAsync(result);\n });\n}\n"]}
|
package/dist/viem.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CancelError, SigningError, UnexpectedError, TransactionError } from '@aave/core';
|
|
2
|
-
import { Chain as Chain$1, TransactionRequest, ExecutionPlan,
|
|
3
|
-
import { ChainId, ResultAsync, TxHash } from '@aave/types';
|
|
2
|
+
import { Chain as Chain$1, TransactionRequest, ExecutionPlan, ERC20PermitSignature } from '@aave/graphql';
|
|
3
|
+
import { ChainId, ResultAsync, TxHash, Signature } from '@aave/types';
|
|
4
4
|
import { Chain, WalletClient } from 'viem';
|
|
5
|
-
import { A as AaveClient } from './AaveClient-
|
|
6
|
-
import { T as TransactionResult, E as ExecutionPlanHandler, a as
|
|
5
|
+
import { A as AaveClient } from './AaveClient-xmYaeYSl.cjs';
|
|
6
|
+
import { T as TransactionResult, E as ExecutionPlanHandler, a as TypedData, S as SignTypedDataError } from './types-fGKXqIpf.cjs';
|
|
7
7
|
import '@urql/core';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -44,20 +44,37 @@ declare function sendWith(walletClient: WalletClient): ExecutionPlanHandler;
|
|
|
44
44
|
*/
|
|
45
45
|
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(walletClient: WalletClient, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
46
46
|
/**
|
|
47
|
-
*
|
|
47
|
+
* Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided wallet client.
|
|
48
|
+
* Returns the raw signature without any wrapping. Deadline encapsulation is handled by consumer code.
|
|
49
|
+
*
|
|
50
|
+
* @param walletClient - The wallet client to use for signing.
|
|
51
|
+
* @param data - The typed data to sign.
|
|
52
|
+
* @returns A ResultAsync containing the raw signature.
|
|
48
53
|
*/
|
|
49
|
-
declare function
|
|
54
|
+
declare function signTypedDataWith(walletClient: WalletClient, data: TypedData): ResultAsync<Signature, SignTypedDataError>;
|
|
50
55
|
/**
|
|
51
|
-
*
|
|
56
|
+
* Handles ERC20 permit signing for actions that require token approval.
|
|
57
|
+
*
|
|
58
|
+
* Calls the action to get an initial execution plan. If the plan requires ERC20 approval
|
|
59
|
+
* and the token supports permit signatures, signs the permit and re-calls the action
|
|
60
|
+
* with the signature to get a new plan that can be sent directly.
|
|
61
|
+
*
|
|
62
|
+
* ```ts
|
|
63
|
+
* const result = await permitWith(walletClient, (permitSig) =>
|
|
64
|
+
* supply(client, {
|
|
65
|
+
* reserve: reserve.id,
|
|
66
|
+
* amount: { erc20: { value: amount, permitSig } },
|
|
67
|
+
* sender: evmAddress(walletClient.account.address),
|
|
68
|
+
* })
|
|
69
|
+
* )
|
|
70
|
+
* .andThen(sendWith(walletClient))
|
|
71
|
+
* .andThen(client.waitForTransaction);
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @param walletClient - The wallet client to use for signing permits.
|
|
75
|
+
* @param action - A function that returns an execution plan, accepting an optional permit signature.
|
|
76
|
+
* @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.
|
|
52
77
|
*/
|
|
53
|
-
declare function
|
|
54
|
-
/**
|
|
55
|
-
* Creates a swap signature handler that signs swap typed data using the provided wallet client.
|
|
56
|
-
*/
|
|
57
|
-
declare function signSwapTypedDataWith(walletClient: WalletClient): SwapSignatureHandler;
|
|
58
|
-
/**
|
|
59
|
-
* Signs swap typed data using the provided wallet client.
|
|
60
|
-
*/
|
|
61
|
-
declare function signSwapTypedDataWith(walletClient: WalletClient, result: SwapTypedData): ReturnType<SwapSignatureHandler>;
|
|
78
|
+
declare function permitWith<E>(walletClient: WalletClient, action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>): ResultAsync<ExecutionPlan, E | SignTypedDataError>;
|
|
62
79
|
|
|
63
|
-
export { ensureChain, sendTransaction, sendWith,
|
|
80
|
+
export { ensureChain, permitWith, sendTransaction, sendWith, signTypedDataWith, supportedChains, toViemChain, transactionError, viemChainsFrom, waitForTransactionResult };
|