@aave/client 4.0.0-next.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{AaveClient-CgHY2iS9.d.ts → AaveClient-C7hQU3qX.d.ts} +14 -17
- package/dist/{AaveClient-L3v8kWvn.d.cts → AaveClient-wwfQOLJS.d.cts} +14 -17
- package/dist/actions/index.cjs +1 -1
- package/dist/actions/index.cjs.map +1 -1
- package/dist/actions/index.d.cts +485 -144
- package/dist/actions/index.d.ts +485 -144
- package/dist/actions/index.js +1 -1
- package/dist/chunk-HH6OAH2K.js +2 -0
- package/dist/chunk-HH6OAH2K.js.map +1 -0
- package/dist/chunk-N4LXBTGY.js +2 -0
- package/dist/chunk-N4LXBTGY.js.map +1 -0
- package/dist/chunk-SXZ2BGUZ.js +2 -0
- package/dist/chunk-SXZ2BGUZ.js.map +1 -0
- package/dist/ethers.cjs +1 -1
- package/dist/ethers.cjs.map +1 -1
- package/dist/ethers.d.cts +45 -11
- package/dist/ethers.d.ts +45 -11
- 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 +20 -3
- package/dist/index.d.ts +20 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/privy.cjs +1 -2
- package/dist/privy.cjs.map +1 -1
- package/dist/privy.d.cts +49 -12
- package/dist/privy.d.ts +49 -12
- package/dist/privy.js +1 -1
- package/dist/privy.js.map +1 -1
- package/dist/testing.d.ts +3675 -29
- package/dist/testing.js +52 -289
- package/dist/testing.js.map +1 -1
- package/dist/thirdweb.cjs +1 -2
- package/dist/thirdweb.cjs.map +1 -1
- package/dist/thirdweb.d.cts +49 -20
- package/dist/thirdweb.d.ts +49 -20
- package/dist/thirdweb.js +1 -2
- package/dist/thirdweb.js.map +1 -1
- package/dist/types-XProSTZ7.d.cts +33 -0
- package/dist/types-XProSTZ7.d.ts +33 -0
- package/dist/viem.cjs +1 -2
- package/dist/viem.cjs.map +1 -1
- package/dist/viem.d.cts +51 -23
- package/dist/viem.d.ts +51 -23
- package/dist/viem.js +1 -1
- package/package.json +7 -6
- package/dist/chunk-3VL3Y3IZ.js +0 -2
- package/dist/chunk-3VL3Y3IZ.js.map +0 -1
- package/dist/chunk-X2C2UEY7.js +0 -3
- package/dist/chunk-X2C2UEY7.js.map +0 -1
- package/dist/types-Bu63z0x6.d.cts +0 -21
- package/dist/types-Bu63z0x6.d.ts +0 -21
package/dist/thirdweb.cjs
CHANGED
|
@@ -1,3 +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
|
|
2
|
-
exports.sendWith=V;exports.signERC20PermitWith=X;exports.signSwapTypedDataWith=j;exports.supportedChains=P;exports.toThirdwebChain=q;//# sourceMappingURL=thirdweb.cjs.map
|
|
1
|
+
'use strict';var core=require('@aave/core'),types=require('@aave/types'),thirdweb=require('thirdweb'),chains=require('thirdweb/chains'),graphql=require('@aave/graphql');var p={currency:graphql.Currency.Usd,timeWindow:graphql.TimeWindow.LastDay,requestPolicy:"cache-and-network",batch:true};function d(e,t,{batch:n=p.batch,requestPolicy:a=p.requestPolicy}=p){return e.query(graphql.ChainQuery,{request:t},{batch:n,requestPolicy:a})}function C(e){return typeof e=="object"&&e!==null&&"approvals"in e&&Array.isArray(e.approvals)}function T(e){return C(e)&&types.isOneEntryArray(e.approvals)&&!!e.approvals[0].bySignature}function U(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 I(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(U(n))))}async function O(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 o(e,t,n){return I(e,n.chainId).andThen(a=>types.ResultAsync.fromPromise(O(t,a,n),r=>core.SigningError.from(r)).andThen(r=>types.ResultAsync.fromPromise(thirdweb.waitForReceipt({client:t,chain:a,transactionHash:r}),s=>core.UnexpectedError.from(s))).andThen(r=>{let s=types.txHash(r.transactionHash);return r.status==="reverted"?types.errAsync(core.TransactionError.new({txHash:s,request:n})):types.okAsync({txHash:s,operations:n.operations})}))}function m(e,t,n){switch(n.__typename){case "TransactionRequest":return o(e,t,n);case "Erc20ApprovalRequired":return n.approvals.reduce((a,r)=>a.andThen(()=>o(e,t,r.byTransaction)),types.okAsync(void 0)).andThen(()=>o(e,t,n.originalTransaction));case "PreContractActionRequired":return o(e,t,n.transaction).andThen(()=>o(e,t,n.originalTransaction));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(n))}}function Z(e,t,n){return n?m(e,t,n):m.bind(null,e,t)}function ee(e,t){return t().andThen(n=>{if(T(n)){let a=n.approvals[0].bySignature;return Q(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 Q(e,t){return t===void 0?n=>h(e,n):h(e,t)}exports.permitWith=ee;exports.sendWith=Z;exports.signTypedDataWith=Q;exports.toThirdwebChain=U;//# sourceMappingURL=thirdweb.cjs.map
|
|
3
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","devnetChain","defineChain","supportedChains","chainId","toThirdwebChain","mainnet","sepolia","fetchThirdwebChain","id","okAsync","invariant","sendTransaction","thirdwebClient","txResponse","Engine","txHash","sendTransactionAndWait","aaveClient","ResultAsync","err","SigningError","hash","waitForReceipt","receipt","errAsync","TransactionError","executePlan","result","ValidationError","sendWith","signTypedData","signature","signatureFrom","signERC20Permit","value","signERC20PermitWith","signSwapTypedData","message","signTypedDataPromise","signSwapTypedDataWith"],"mappings":"yKA+CO,IAAMA,CAAAA,CAAwB,CACnC,QAAA,CAAUC,gBAAAA,CAAS,GAAA,CACnB,UAAA,CAAYC,mBAAW,OAAA,CACvB,aAAA,CAAe,mBAAA,CACf,KAAA,CAAO,IACT,CAAA,CCTO,SAASC,CAAAA,CACdC,CAAAA,CACAC,EACA,CAAE,KAAA,CAAAC,CAAM,CAAA,CAAkBN,CAAAA,CACkB,CAC5C,OAAOI,CAAAA,CAAO,KAAA,CAAMG,kBAAAA,CAAY,CAAE,OAAA,CAAAF,CAAQ,CAAA,CAAG,CAAE,MAAAC,CAAM,CAAC,CACxD,KCNME,CAAAA,CAA6BC,oBAAAA,CAAY,CAC7C,EAAA,CAAI,OAAO,QAAA,CAAS,WAAA,CAA2C,EAAE,CAAA,CACjE,KAAM,QAAA,CACN,cAAA,CAAgB,CAAE,IAAA,CAAM,QAAS,MAAA,CAAQ,KAAA,CAAO,QAAA,CAAU,EAAG,EAC7D,OAAA,CAAS,CACP,OAAA,CAAS,CAAE,KAAM,CAAC,2FAA4C,CAAE,CAClE,EACA,cAAA,CAAgB,CACd,OAAA,CAAS,CACP,KAAM,iBAAA,CACN,GAAA,CAAK,mFACP,CACF,CACF,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,EAAQ+B,CAAM,CAAA,CAChCS,EAAkB,IAAA,CAAK,IAAA,CAAMxC,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 CancelSwapTypedData,\n Chain,\n ExecutionPlan,\n PermitTypedDataResponse,\n SwapByIntentTypedData,\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\nconst devnetChain: ThirdwebChain = defineChain({\n id: Number.parseInt(import.meta.env.ETHEREUM_TENDERLY_FORK_ID, 10),\n name: 'Devnet',\n nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },\n rpcUrls: {\n default: { http: [import.meta.env.ETHEREUM_TENDERLY_PUBLIC_RPC] },\n },\n blockExplorers: {\n default: {\n name: 'Devnet Explorer',\n url: import.meta.env.ETHEREUM_TENDERLY_BLOCKEXPLORER,\n },\n },\n});\n\n/**\n * @internal\n */\nexport const supportedChains: Record<ChainId, ThirdwebChain> = {\n // TODO add them back when deployed on these chains\n // [chainId(mainnet.id)]: mainnet,\n // [chainId(sepolia.id)]: sepolia,\n [chainId(devnetChain.id)]: devnetChain,\n};\n\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 client: ThirdwebClient,\n result: PermitTypedDataResponse,\n): Promise<Signature> {\n const wallet = Engine.serverWallet({\n client,\n chain: supportedChains[result.domain.chainId],\n address: result.message.owner,\n });\n\n const signature = await wallet.signTypedData({\n // silence the rest of the type inference\n types: result.types as Record<string, unknown>,\n domain: result.domain,\n primaryType: result.primaryType,\n message: result.message,\n });\n\n return signatureFrom(signature);\n}\n\nfunction signERC20Permit(\n client: ThirdwebClient,\n result: PermitTypedDataResponse,\n): ReturnType<ERC20PermitHandler> {\n return ResultAsync.fromPromise(signTypedData(client, result), (err) =>\n SigningError.from(err),\n ).map((value) => ({\n deadline: result.message.deadline,\n value,\n }));\n}\n\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the provided Thirdweb client and account.\n */\nexport function signERC20PermitWith(\n client: ThirdwebClient,\n): ERC20PermitHandler {\n return signERC20Permit.bind(null, client);\n}\n\nfunction signSwapTypedData(\n client: ThirdwebClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n const message = JSON.parse(result.message);\n\n const signTypedDataPromise = async (): Promise<Signature> => {\n const wallet = Engine.serverWallet({\n client,\n chain: supportedChains[result.domain.chainId],\n address: message.user,\n });\n\n const signature = await wallet.signTypedData({\n // silence the rest of the type inference\n types: result.types as Record<string, unknown>,\n domain: result.domain,\n primaryType: result.primaryType,\n message,\n });\n\n return signatureFrom(signature);\n };\n\n return ResultAsync.fromPromise(signTypedDataPromise(), (err) =>\n SigningError.from(err),\n ).map((value) => ({\n deadline: message.deadline,\n value,\n }));\n}\n\n/**\n * @internal\n * Creates a swap signature handler that signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n): SwapSignatureHandler;\n/**\n * @internal\n * Signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n result?: SwapByIntentTypedData | CancelSwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(client, result)\n : signSwapTypedData.bind(null, client);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/options.ts","../src/actions/misc.ts","../src/adapters.ts","../src/thirdweb.ts"],"names":["DEFAULT_QUERY_OPTIONS","Currency","TimeWindow","chain","client","request","batch","requestPolicy","ChainQuery","hasApprovals","plan","supportsPermit","isOneEntryArray","toThirdwebChain","chainId","mainnet","sepolia","defineChain","fetchThirdwebChain","id","okAsync","invariant","sendTransaction","thirdwebClient","txResponse","Engine","txHash","sendTransactionAndWait","aaveClient","ResultAsync","err","SigningError","hash","waitForReceipt","UnexpectedError","receipt","errAsync","TransactionError","executePlan","result","approval","ValidationError","sendWith","permitWith","wallet","action","permit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,GAAcJ,CAAAA,CAAOI,CAAS,CAAC,CAC7C,CACA,OAAO7B,aAAAA,CAAQmB,CAAM,CACvB,CAAC,CACH,CAEA,SAASW,EACPN,CAAAA,CACAO,CAAAA,CACsC,CACtC,OAAOtB,kBAAY,WAAA,CACjBe,CAAAA,CAAO,aAAA,CAAc,CACnB,MAAOO,CAAAA,CAAK,KAAA,CACZ,MAAA,CAAQA,CAAAA,CAAK,MAAA,CACb,WAAA,CAAaA,CAAAA,CAAK,WAAA,CAClB,QAASA,CAAAA,CAAK,OAChB,CAAC,CAAA,CACArB,GAAQC,iBAAAA,CAAa,IAAA,CAAKD,CAAG,CAChC,EAAE,GAAA,CAAIsB,mBAAa,CACrB,CAiCO,SAASL,CAAAA,CACdH,CAAAA,CACAO,CAAAA,CACiD,CACjD,OAAIA,CAAAA,GAAS,MAAA,CACHE,CAAAA,EAAyBH,CAAAA,CAAcN,EAAQS,CAAS,CAAA,CAE3DH,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 {\n type BatchOptions,\n DEFAULT_QUERY_OPTIONS,\n type RequestPolicyOptions,\n} 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 * @param options - The query options.\n * @returns The chain data, or null if not found.\n */\nexport function chain(\n client: AaveClient,\n request: ChainRequest,\n {\n batch = DEFAULT_QUERY_OPTIONS.batch,\n requestPolicy = DEFAULT_QUERY_OPTIONS.requestPolicy,\n }: BatchOptions & RequestPolicyOptions = DEFAULT_QUERY_OPTIONS,\n): ResultAsync<Chain | null, UnexpectedError> {\n return client.query(ChainQuery, { request }, { batch, requestPolicy });\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 * @param options - The query options.\n * @returns The exchange rate information as a fiat amount.\n */\nexport function exchangeRate(\n client: AaveClient,\n request: ExchangeRateRequest,\n {\n requestPolicy = DEFAULT_QUERY_OPTIONS.requestPolicy,\n }: RequestPolicyOptions = DEFAULT_QUERY_OPTIONS,\n): ResultAsync<ExchangeAmount, UnexpectedError> {\n return client.query(ExchangeRateQuery, { request }, { requestPolicy });\n}\n","import type { Erc20Approval, PermitTypedData } from '@aave/graphql';\nimport { isOneEntryArray } from '@aave/types';\n\ntype WithApprovals = { approvals: Erc20Approval[] };\n\nfunction hasApprovals(plan: unknown): plan is WithApprovals {\n return (\n typeof plan === 'object' &&\n plan !== null &&\n 'approvals' in plan &&\n Array.isArray(plan.approvals)\n );\n}\n\n/**\n * Checks if a plan supports permit (single approval with bySignature).\n * Works with union types - picks any member that has an `approvals` array\n * with a single entry containing `bySignature`.\n *\n * @internal\n */\nexport function supportsPermit<T>(plan: T): plan is T &\n Extract<T, WithApprovals> & {\n approvals: [Erc20Approval & { bySignature: PermitTypedData }];\n } {\n return (\n hasApprovals(plan) &&\n isOneEntryArray(plan.approvals) &&\n !!plan.approvals[0].bySignature\n );\n}\n","import {\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 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 { supportsPermit } from './adapters';\nimport type {\n ExecutionPlanHandler,\n SignTypedDataError,\n TransactionResult,\n TypedData,\n TypedDataHandler,\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 .andThen((hash) =>\n ResultAsync.fromPromise(\n waitForReceipt({\n client: thirdwebClient,\n chain,\n transactionHash: hash,\n }),\n (err) => UnexpectedError.from(err),\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 result.approvals\n .reduce<ReturnType<typeof sendTransactionAndWait>>(\n (chain, approval) =>\n chain.andThen(() =>\n sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n approval.byTransaction,\n ),\n ),\n okAsync(undefined as never),\n )\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 (supportsPermit(result)) {\n const permitTypedData = result.approvals[0].bySignature;\n return signTypedDataWith(wallet, permitTypedData)\n .map((signature) => ({\n deadline: permitTypedData.message.deadline as number,\n value: signature,\n }))\n .andThen((permitSig) => action(permitSig));\n }\n return okAsync(result);\n });\n}\n\nfunction signTypedData(\n 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 * Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.\n *\n * @param wallet - The Thirdweb server wallet to use for signing.\n * @returns A function that takes typed data and returns a ResultAsync containing the raw signature.\n *\n * ```ts\n * const result = await prepareSwapCancel(client, request)\n * .andThen(signTypedDataWith(wallet));\n * ```\n */\nexport function signTypedDataWith(\n wallet: Engine.ServerWallet,\n): TypedDataHandler;\n\n/**\n * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.\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 *\n * ```ts\n * const result = await signTypedDataWith(wallet, typedData);\n * ```\n */\nexport function signTypedDataWith(\n wallet: Engine.ServerWallet,\n data: TypedData,\n): ReturnType<TypedDataHandler>;\n\nexport function signTypedDataWith(\n wallet: Engine.ServerWallet,\n data?: TypedData,\n): TypedDataHandler | ReturnType<TypedDataHandler> {\n if (data === undefined) {\n return (typedData: TypedData) => signTypedData(wallet, typedData);\n }\n return signTypedData(wallet, data);\n}\n"]}
|
package/dist/thirdweb.d.cts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { A as AaveClient } from './AaveClient-
|
|
5
|
-
import { E as ExecutionPlanHandler,
|
|
1
|
+
import { ERC20PermitSignature, ExecutionPlan, Chain } from '@aave/graphql';
|
|
2
|
+
import { ResultAsync } from '@aave/types';
|
|
3
|
+
import { Engine, ThirdwebClient, Chain as Chain$1 } from 'thirdweb';
|
|
4
|
+
import { A as AaveClient } from './AaveClient-wwfQOLJS.cjs';
|
|
5
|
+
import { S as SignTypedDataError, E as ExecutionPlanHandler, T as TypedDataHandler, a as TypedData } from './types-XProSTZ7.cjs';
|
|
6
6
|
import '@aave/core';
|
|
7
|
-
import '@urql/core';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @internal
|
|
11
10
|
*/
|
|
12
|
-
declare
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
declare function toThirdwebChain(chain: Chain$1): Chain;
|
|
11
|
+
declare function toThirdwebChain(chain: Chain): Chain$1;
|
|
17
12
|
/**
|
|
18
13
|
* Creates an execution plan handler that sends transactions using the provided Thirdweb client and account.
|
|
19
14
|
*/
|
|
@@ -23,18 +18,52 @@ declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(aaveClient: A
|
|
|
23
18
|
*/
|
|
24
19
|
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(aaveClient: AaveClient, thirdwebClient: ThirdwebClient, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
25
20
|
/**
|
|
26
|
-
*
|
|
21
|
+
* Handles ERC20 permit signing for actions that require token approval.
|
|
22
|
+
*
|
|
23
|
+
* Calls the action to get an initial execution plan. If the plan requires ERC20 approval
|
|
24
|
+
* and the token supports permit signatures, signs the permit and re-calls the action
|
|
25
|
+
* with the signature to get a new plan that can be sent directly.
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const result = await permitWith(wallet, (permitSig) =>
|
|
29
|
+
* supply(client, {
|
|
30
|
+
* reserve: reserve.id,
|
|
31
|
+
* amount: { erc20: { value: amount, permitSig } },
|
|
32
|
+
* sender: evmAddress(wallet.address),
|
|
33
|
+
* })
|
|
34
|
+
* )
|
|
35
|
+
* .andThen(sendWith(wallet))
|
|
36
|
+
* .andThen(client.waitForTransaction);
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @param wallet - The Thirdweb server wallet for signing permits.
|
|
40
|
+
* @param action - A function that returns an execution plan, accepting an optional permit signature.
|
|
41
|
+
* @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.
|
|
27
42
|
*/
|
|
28
|
-
declare function
|
|
43
|
+
declare function permitWith<E>(wallet: Engine.ServerWallet, action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>): ResultAsync<ExecutionPlan, E | SignTypedDataError>;
|
|
29
44
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
45
|
+
* Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.
|
|
46
|
+
*
|
|
47
|
+
* @param wallet - The Thirdweb server wallet to use for signing.
|
|
48
|
+
* @returns A function that takes typed data and returns a ResultAsync containing the raw signature.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* const result = await prepareSwapCancel(client, request)
|
|
52
|
+
* .andThen(signTypedDataWith(wallet));
|
|
53
|
+
* ```
|
|
32
54
|
*/
|
|
33
|
-
declare function
|
|
55
|
+
declare function signTypedDataWith(wallet: Engine.ServerWallet): TypedDataHandler;
|
|
34
56
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
57
|
+
* Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.
|
|
58
|
+
*
|
|
59
|
+
* @param wallet - The Thirdweb server wallet to use for signing.
|
|
60
|
+
* @param data - The typed data to sign.
|
|
61
|
+
* @returns A ResultAsync containing the raw signature.
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const result = await signTypedDataWith(wallet, typedData);
|
|
65
|
+
* ```
|
|
37
66
|
*/
|
|
38
|
-
declare function
|
|
67
|
+
declare function signTypedDataWith(wallet: Engine.ServerWallet, data: TypedData): ReturnType<TypedDataHandler>;
|
|
39
68
|
|
|
40
|
-
export {
|
|
69
|
+
export { permitWith, sendWith, signTypedDataWith, toThirdwebChain };
|
package/dist/thirdweb.d.ts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { A as AaveClient } from './AaveClient-
|
|
5
|
-
import { E as ExecutionPlanHandler,
|
|
1
|
+
import { ERC20PermitSignature, ExecutionPlan, Chain } from '@aave/graphql';
|
|
2
|
+
import { ResultAsync } from '@aave/types';
|
|
3
|
+
import { Engine, ThirdwebClient, Chain as Chain$1 } from 'thirdweb';
|
|
4
|
+
import { A as AaveClient } from './AaveClient-C7hQU3qX.js';
|
|
5
|
+
import { S as SignTypedDataError, E as ExecutionPlanHandler, T as TypedDataHandler, a as TypedData } from './types-XProSTZ7.js';
|
|
6
6
|
import '@aave/core';
|
|
7
|
-
import '@urql/core';
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* @internal
|
|
11
10
|
*/
|
|
12
|
-
declare
|
|
13
|
-
/**
|
|
14
|
-
* @internal
|
|
15
|
-
*/
|
|
16
|
-
declare function toThirdwebChain(chain: Chain$1): Chain;
|
|
11
|
+
declare function toThirdwebChain(chain: Chain): Chain$1;
|
|
17
12
|
/**
|
|
18
13
|
* Creates an execution plan handler that sends transactions using the provided Thirdweb client and account.
|
|
19
14
|
*/
|
|
@@ -23,18 +18,52 @@ declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(aaveClient: A
|
|
|
23
18
|
*/
|
|
24
19
|
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(aaveClient: AaveClient, thirdwebClient: ThirdwebClient, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
25
20
|
/**
|
|
26
|
-
*
|
|
21
|
+
* Handles ERC20 permit signing for actions that require token approval.
|
|
22
|
+
*
|
|
23
|
+
* Calls the action to get an initial execution plan. If the plan requires ERC20 approval
|
|
24
|
+
* and the token supports permit signatures, signs the permit and re-calls the action
|
|
25
|
+
* with the signature to get a new plan that can be sent directly.
|
|
26
|
+
*
|
|
27
|
+
* ```ts
|
|
28
|
+
* const result = await permitWith(wallet, (permitSig) =>
|
|
29
|
+
* supply(client, {
|
|
30
|
+
* reserve: reserve.id,
|
|
31
|
+
* amount: { erc20: { value: amount, permitSig } },
|
|
32
|
+
* sender: evmAddress(wallet.address),
|
|
33
|
+
* })
|
|
34
|
+
* )
|
|
35
|
+
* .andThen(sendWith(wallet))
|
|
36
|
+
* .andThen(client.waitForTransaction);
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @param wallet - The Thirdweb server wallet for signing permits.
|
|
40
|
+
* @param action - A function that returns an execution plan, accepting an optional permit signature.
|
|
41
|
+
* @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.
|
|
27
42
|
*/
|
|
28
|
-
declare function
|
|
43
|
+
declare function permitWith<E>(wallet: Engine.ServerWallet, action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>): ResultAsync<ExecutionPlan, E | SignTypedDataError>;
|
|
29
44
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
45
|
+
* Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.
|
|
46
|
+
*
|
|
47
|
+
* @param wallet - The Thirdweb server wallet to use for signing.
|
|
48
|
+
* @returns A function that takes typed data and returns a ResultAsync containing the raw signature.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* const result = await prepareSwapCancel(client, request)
|
|
52
|
+
* .andThen(signTypedDataWith(wallet));
|
|
53
|
+
* ```
|
|
32
54
|
*/
|
|
33
|
-
declare function
|
|
55
|
+
declare function signTypedDataWith(wallet: Engine.ServerWallet): TypedDataHandler;
|
|
34
56
|
/**
|
|
35
|
-
*
|
|
36
|
-
*
|
|
57
|
+
* Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.
|
|
58
|
+
*
|
|
59
|
+
* @param wallet - The Thirdweb server wallet to use for signing.
|
|
60
|
+
* @param data - The typed data to sign.
|
|
61
|
+
* @returns A ResultAsync containing the raw signature.
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* const result = await signTypedDataWith(wallet, typedData);
|
|
65
|
+
* ```
|
|
37
66
|
*/
|
|
38
|
-
declare function
|
|
67
|
+
declare function signTypedDataWith(wallet: Engine.ServerWallet, data: TypedData): ReturnType<TypedDataHandler>;
|
|
39
68
|
|
|
40
|
-
export {
|
|
69
|
+
export { permitWith, sendWith, signTypedDataWith, toThirdwebChain };
|
package/dist/thirdweb.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export{N as sendWith,k as signERC20PermitWith,O as signSwapTypedDataWith,R as supportedChains,v as toThirdwebChain};//# sourceMappingURL=thirdweb.js.map
|
|
1
|
+
import {a}from'./chunk-N4LXBTGY.js';import {g}from'./chunk-HH6OAH2K.js';import {ValidationError,SigningError,UnexpectedError,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 w(e){switch(e.chainId){case chainId(mainnet.id):return mainnet;case chainId(sepolia.id):return sepolia}return 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 D(e,r){switch(r){case chainId(mainnet.id):return okAsync(mainnet);case chainId(sepolia.id):return okAsync(sepolia)}return g(e,{chainId:r},{batch:false}).andThen(n=>(invariant(n,`Chain ${r} is not supported`),okAsync(w(n))))}async function b(e,r,n){let a=await Engine.serverWallet({client:e,chain:r,address:n.from}).sendTransaction({type:"eip1559",chainId:r.id,to:n.to,value:BigInt(n.value),data:n.data});return txHash(a.transactionHash)}function o(e,r,n){return D(e,n.chainId).andThen(t=>ResultAsync.fromPromise(b(r,t,n),a=>SigningError.from(a)).andThen(a=>ResultAsync.fromPromise(waitForReceipt({client:r,chain:t,transactionHash:a}),s=>UnexpectedError.from(s))).andThen(a=>{let s=txHash(a.transactionHash);return a.status==="reverted"?errAsync(TransactionError.new({txHash:s,request:n})):okAsync({txHash:s,operations:n.operations})}))}function m(e,r,n){switch(n.__typename){case "TransactionRequest":return o(e,r,n);case "Erc20ApprovalRequired":return n.approvals.reduce((t,a)=>t.andThen(()=>o(e,r,a.byTransaction)),okAsync(void 0)).andThen(()=>o(e,r,n.originalTransaction));case "PreContractActionRequired":return o(e,r,n.transaction).andThen(()=>o(e,r,n.originalTransaction));case "InsufficientBalanceError":return errAsync(ValidationError.fromGqlNode(n))}}function F(e,r,n){return n?m(e,r,n):m.bind(null,e,r)}function _(e,r){return r().andThen(n=>{if(a(n)){let t=n.approvals[0].bySignature;return S(e,t).map(a=>({deadline:t.message.deadline,value:a})).andThen(a=>r(a))}return okAsync(n)})}function y(e,r){return ResultAsync.fromPromise(e.signTypedData({types:r.types,domain:r.domain,primaryType:r.primaryType,message:r.message}),n=>SigningError.from(n)).map(signatureFrom)}function S(e,r){return r===void 0?n=>y(e,n):y(e,r)}export{_ as permitWith,F as sendWith,S as signTypedDataWith,w as toThirdwebChain};//# sourceMappingURL=thirdweb.js.map
|
|
3
2
|
//# sourceMappingURL=thirdweb.js.map
|
package/dist/thirdweb.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/thirdweb.ts"],"names":["devnetChain","defineChain","supportedChains","chainId","toThirdwebChain","chain","mainnet","sepolia","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","signature","signatureFrom","signERC20Permit","value","signERC20PermitWith","signSwapTypedData","message","signTypedDataPromise","signSwapTypedDataWith"],"mappings":"gTA2CA,IAAMA,CAAAA,CAA6BC,WAAAA,CAAY,CAC7C,GAAI,MAAA,CAAO,QAAA,CAAS,WAAA,CAA2C,EAAE,CAAA,CACjE,IAAA,CAAM,QAAA,CACN,cAAA,CAAgB,CAAE,IAAA,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pB,OAAA,CAAAU,CACF,CAAC,CAAA,CAED,OAAOL,aAAAA,CAAcD,CAAS,CAChC,CAAA,CAEA,OAAOb,WAAAA,CAAY,WAAA,CAAYoB,CAAAA,EAAqB,CAAInB,CAAAA,EACtDC,YAAAA,CAAa,KAAKD,CAAG,CACvB,CAAA,CAAE,GAAA,CAAKe,IAAW,CAChB,QAAA,CAAUG,CAAAA,CAAQ,QAAA,CAClB,MAAAH,CACF,CAAA,CAAE,CACJ,CAiBO,SAASK,CAAAA,CACdjC,CAAAA,CACAqB,CAAAA,CACyD,CACzD,OAAOA,CAAAA,CACHS,CAAAA,CAAkB9B,CAAAA,CAAQqB,CAAM,CAAA,CAChCS,CAAAA,CAAkB,IAAA,CAAK,IAAA,CAAM9B,CAAM,CACzC","file":"thirdweb.js","sourcesContent":["import {\n SigningError,\n TransactionError,\n type UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n CancelSwapTypedData,\n Chain,\n ExecutionPlan,\n PermitTypedDataResponse,\n SwapByIntentTypedData,\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\nconst devnetChain: ThirdwebChain = defineChain({\n id: Number.parseInt(import.meta.env.ETHEREUM_TENDERLY_FORK_ID, 10),\n name: 'Devnet',\n nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },\n rpcUrls: {\n default: { http: [import.meta.env.ETHEREUM_TENDERLY_PUBLIC_RPC] },\n },\n blockExplorers: {\n default: {\n name: 'Devnet Explorer',\n url: import.meta.env.ETHEREUM_TENDERLY_BLOCKEXPLORER,\n },\n },\n});\n\n/**\n * @internal\n */\nexport const supportedChains: Record<ChainId, ThirdwebChain> = {\n // TODO add them back when deployed on these chains\n // [chainId(mainnet.id)]: mainnet,\n // [chainId(sepolia.id)]: sepolia,\n [chainId(devnetChain.id)]: devnetChain,\n};\n\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 client: ThirdwebClient,\n result: PermitTypedDataResponse,\n): Promise<Signature> {\n const wallet = Engine.serverWallet({\n client,\n chain: supportedChains[result.domain.chainId],\n address: result.message.owner,\n });\n\n const signature = await wallet.signTypedData({\n // silence the rest of the type inference\n types: result.types as Record<string, unknown>,\n domain: result.domain,\n primaryType: result.primaryType,\n message: result.message,\n });\n\n return signatureFrom(signature);\n}\n\nfunction signERC20Permit(\n client: ThirdwebClient,\n result: PermitTypedDataResponse,\n): ReturnType<ERC20PermitHandler> {\n return ResultAsync.fromPromise(signTypedData(client, result), (err) =>\n SigningError.from(err),\n ).map((value) => ({\n deadline: result.message.deadline,\n value,\n }));\n}\n\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the provided Thirdweb client and account.\n */\nexport function signERC20PermitWith(\n client: ThirdwebClient,\n): ERC20PermitHandler {\n return signERC20Permit.bind(null, client);\n}\n\nfunction signSwapTypedData(\n client: ThirdwebClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n const message = JSON.parse(result.message);\n\n const signTypedDataPromise = async (): Promise<Signature> => {\n const wallet = Engine.serverWallet({\n client,\n chain: supportedChains[result.domain.chainId],\n address: message.user,\n });\n\n const signature = await wallet.signTypedData({\n // silence the rest of the type inference\n types: result.types as Record<string, unknown>,\n domain: result.domain,\n primaryType: result.primaryType,\n message,\n });\n\n return signatureFrom(signature);\n };\n\n return ResultAsync.fromPromise(signTypedDataPromise(), (err) =>\n SigningError.from(err),\n ).map((value) => ({\n deadline: message.deadline,\n value,\n }));\n}\n\n/**\n * @internal\n * Creates a swap signature handler that signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n): SwapSignatureHandler;\n/**\n * @internal\n * Signs swap typed data using the provided Thirdweb client.\n */\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n client: ThirdwebClient,\n result?: SwapByIntentTypedData | CancelSwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(client, result)\n : signSwapTypedData.bind(null, client);\n}\n"]}
|
|
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","UnexpectedError","receipt","errAsync","TransactionError","executePlan","result","approval","ValidationError","sendWith","permitWith","wallet","action","supportsPermit","permitTypedData","signTypedDataWith","signature","permitSig","signTypedData","data","signatureFrom","typedData"],"mappings":"oWA8CO,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,IAAA,CACZ,cAAA,CAAgB,CACd,IAAA,CAAMA,CAAAA,CAAM,UAAA,CAAW,IAAA,CACvB,MAAA,CAAQA,CAAAA,CAAM,UAAA,CAAW,MAAA,CACzB,QAAA,CAAUA,CAAAA,CAAM,UAAA,CAAW,QAC7B,CAAA,CACA,OAAA,CAAS,CAAE,OAAA,CAAS,CAAE,IAAA,CAAM,CAACA,CAAAA,CAAM,MAAM,CAAE,CAAE,CAAA,CAC7C,cAAA,CAAgB,CACd,OAAA,CAAS,CACP,IAAA,CAAM,CAAA,EAAGA,CAAAA,CAAM,IAAI,CAAA,SAAA,CAA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,WAAAA,CAAY,WAAA,CACjBe,CAAAA,CAAO,aAAA,CAAc,CACnB,KAAA,CAAOQ,CAAAA,CAAK,KAAA,CACZ,MAAA,CAAQA,CAAAA,CAAK,MAAA,CACb,WAAA,CAAaA,CAAAA,CAAK,WAAA,CAClB,OAAA,CAASA,CAAAA,CAAK,OAChB,CAAC,CAAA,CACAtB,CAAAA,EAAQC,YAAAA,CAAa,IAAA,CAAKD,CAAG,CAChC,CAAA,CAAE,GAAA,CAAIuB,aAAa,CACrB,CAiCO,SAASL,CAAAA,CACdJ,CAAAA,CACAQ,CAAAA,CACiD,CACjD,OAAIA,CAAAA,GAAS,MAAA,CACHE,CAAAA,EAAyBH,CAAAA,CAAcP,CAAAA,CAAQU,CAAS,CAAA,CAE3DH,CAAAA,CAAcP,CAAAA,CAAQQ,CAAI,CACnC","file":"thirdweb.js","sourcesContent":["import {\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 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 { supportsPermit } from './adapters';\nimport type {\n ExecutionPlanHandler,\n SignTypedDataError,\n TransactionResult,\n TypedData,\n TypedDataHandler,\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 .andThen((hash) =>\n ResultAsync.fromPromise(\n waitForReceipt({\n client: thirdwebClient,\n chain,\n transactionHash: hash,\n }),\n (err) => UnexpectedError.from(err),\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 result.approvals\n .reduce<ReturnType<typeof sendTransactionAndWait>>(\n (chain, approval) =>\n chain.andThen(() =>\n sendTransactionAndWait(\n aaveClient,\n thirdwebClient,\n approval.byTransaction,\n ),\n ),\n okAsync(undefined as never),\n )\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 (supportsPermit(result)) {\n const permitTypedData = result.approvals[0].bySignature;\n return signTypedDataWith(wallet, permitTypedData)\n .map((signature) => ({\n deadline: permitTypedData.message.deadline as number,\n value: signature,\n }))\n .andThen((permitSig) => action(permitSig));\n }\n return okAsync(result);\n });\n}\n\nfunction signTypedData(\n 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 * Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.\n *\n * @param wallet - The Thirdweb server wallet to use for signing.\n * @returns A function that takes typed data and returns a ResultAsync containing the raw signature.\n *\n * ```ts\n * const result = await prepareSwapCancel(client, request)\n * .andThen(signTypedDataWith(wallet));\n * ```\n */\nexport function signTypedDataWith(\n wallet: Engine.ServerWallet,\n): TypedDataHandler;\n\n/**\n * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided Thirdweb wallet.\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 *\n * ```ts\n * const result = await signTypedDataWith(wallet, typedData);\n * ```\n */\nexport function signTypedDataWith(\n wallet: Engine.ServerWallet,\n data: TypedData,\n): ReturnType<TypedDataHandler>;\n\nexport function signTypedDataWith(\n wallet: Engine.ServerWallet,\n data?: TypedData,\n): TypedDataHandler | ReturnType<TypedDataHandler> {\n if (data === undefined) {\n return (typedData: TypedData) => signTypedData(wallet, typedData);\n }\n return signTypedData(wallet, data);\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CancelError, SigningError, TransactionError, ValidationError, UnexpectedError } from '@aave/core';
|
|
2
|
+
import { ExecutionPlan, OperationType, InsufficientBalanceError, PermitTypedData, SwapTypedData, HasProcessedKnownTransactionRequest } from '@aave/graphql';
|
|
3
|
+
import { ResultAsync, TxHash, Signature } from '@aave/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
type TransactionResult = {
|
|
9
|
+
txHash: TxHash;
|
|
10
|
+
operations: OperationType[] | null;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
declare function isHasProcessedKnownTransactionRequest(result: TransactionResult): result is HasProcessedKnownTransactionRequest;
|
|
16
|
+
type TransactionReceipt = {
|
|
17
|
+
__typename: 'TransactionReceipt';
|
|
18
|
+
txHash: TxHash;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
declare function transactionReceipt(txHash: TxHash): TransactionReceipt;
|
|
24
|
+
type SendWithError = CancelError | SigningError | TransactionError | ValidationError<InsufficientBalanceError> | UnexpectedError;
|
|
25
|
+
type ExecutionPlanHandler<T extends ExecutionPlan = ExecutionPlan> = (result: T) => ResultAsync<TransactionResult, SendWithError>;
|
|
26
|
+
type SignTypedDataError = CancelError | SigningError;
|
|
27
|
+
/**
|
|
28
|
+
* Union type for all EIP-712 typed data structures used in the SDK.
|
|
29
|
+
*/
|
|
30
|
+
type TypedData = PermitTypedData | SwapTypedData;
|
|
31
|
+
type TypedDataHandler = (data: TypedData) => ResultAsync<Signature, SignTypedDataError>;
|
|
32
|
+
|
|
33
|
+
export { type ExecutionPlanHandler as E, type SignTypedDataError as S, type TypedDataHandler as T, type TypedData as a, type TransactionResult as b, type SendWithError as c, type TransactionReceipt as d, isHasProcessedKnownTransactionRequest as i, transactionReceipt as t };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { CancelError, SigningError, TransactionError, ValidationError, UnexpectedError } from '@aave/core';
|
|
2
|
+
import { ExecutionPlan, OperationType, InsufficientBalanceError, PermitTypedData, SwapTypedData, HasProcessedKnownTransactionRequest } from '@aave/graphql';
|
|
3
|
+
import { ResultAsync, TxHash, Signature } from '@aave/types';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
type TransactionResult = {
|
|
9
|
+
txHash: TxHash;
|
|
10
|
+
operations: OperationType[] | null;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
declare function isHasProcessedKnownTransactionRequest(result: TransactionResult): result is HasProcessedKnownTransactionRequest;
|
|
16
|
+
type TransactionReceipt = {
|
|
17
|
+
__typename: 'TransactionReceipt';
|
|
18
|
+
txHash: TxHash;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
declare function transactionReceipt(txHash: TxHash): TransactionReceipt;
|
|
24
|
+
type SendWithError = CancelError | SigningError | TransactionError | ValidationError<InsufficientBalanceError> | UnexpectedError;
|
|
25
|
+
type ExecutionPlanHandler<T extends ExecutionPlan = ExecutionPlan> = (result: T) => ResultAsync<TransactionResult, SendWithError>;
|
|
26
|
+
type SignTypedDataError = CancelError | SigningError;
|
|
27
|
+
/**
|
|
28
|
+
* Union type for all EIP-712 typed data structures used in the SDK.
|
|
29
|
+
*/
|
|
30
|
+
type TypedData = PermitTypedData | SwapTypedData;
|
|
31
|
+
type TypedDataHandler = (data: TypedData) => ResultAsync<Signature, SignTypedDataError>;
|
|
32
|
+
|
|
33
|
+
export { type ExecutionPlanHandler as E, type SignTypedDataError as S, type TypedDataHandler as T, type TypedData as a, type TransactionResult as b, type SendWithError as c, type TransactionReceipt as d, isHasProcessedKnownTransactionRequest as i, transactionReceipt as t };
|
package/dist/viem.cjs
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
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=de;exports.sendTransaction=Y;exports.sendWith=me;exports.signERC20PermitWith=ye;exports.signSwapTypedDataWith=he;exports.supportedChains=pe;exports.toViemChain=w;exports.transactionError=G;exports.viemChainsFrom=le;exports.waitForTransactionResult=$;//# sourceMappingURL=viem.cjs.map
|
|
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 p={currency:graphql.Currency.Usd,timeWindow:graphql.TimeWindow.LastDay,requestPolicy:"cache-and-network",batch:true};function h(e,n,{batch:r=p.batch,requestPolicy:t=p.requestPolicy}=p){return e.query(graphql.ChainQuery,{request:n},{batch:r,requestPolicy:t})}function H(e){return typeof e=="object"&&e!==null&&"approvals"in e&&Array.isArray(e.approvals)}function E(e){return H(e)&&types.isOneEntryArray(e.approvals)&&!!e.approvals[0].bySignature}function m(e){return types.isObject(e)&&"code"in e&&"message"in e}function j(e){return types.isObject(e)&&"name"in e&&"message"in e&&"originalError"in e?m(e.originalError)&&"code"in e.originalError:true}function g(e,n){return types.invariant(e.account,"Wallet account is required to sign typed data"),types.ResultAsync.fromPromise(e.signTypedData({account:e.account,domain:n.domain,types:n.types,primaryType:n.primaryType,message:n.message}),r=>r instanceof viem.UserRejectedRequestError?core.CancelError.from(r):core.SigningError.from(r)).map(types.signatureFrom)}function W(e){switch(e.chainId){case types.chainId(chains.mainnet.id):return chains.mainnet;case types.chainId(chains.sepolia.id):return chains.sepolia}return viem.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 me(e){return e.map(W)}function fe(e,n,r){return types.ResultAsync.fromPromise(n.getChainId(),t=>core.SigningError.from(t)).andThen(t=>t===r.chainId?types.okAsync():h(e,{chainId:r.chainId},{batch:false}).andThen(a=>(types.invariant(a,`Chain ${r.chainId} is not supported`),types.ResultAsync.fromPromise(n.switchChain({id:r.chainId}),o=>core.SigningError.from(o)).orElse(o=>(m(o.cause)?o.cause.code:j(o.cause)?o.cause.data?.originalError?.code:void 0)===viem.SwitchChainError.code?types.ResultAsync.fromPromise(n.addChain({chain:W(a)}),u=>m(u)&&u.code===viem.UserRejectedRequestError.code?core.CancelError.from(u):core.SigningError.from(u)):o.asResultAsync()))))}function G(e,n){return types.ResultAsync.fromPromise(actions.estimateGas(e,{account:e.account,data:n.data,to:n.to,value:BigInt(n.value),prepare:false}),r=>core.SigningError.from(r)).map(r=>r*115n/100n)}function K(e,n){return G(e,n).andThen(r=>types.ResultAsync.fromPromise(actions.sendTransaction(e,{account:e.account,data:n.data,to:n.to,value:BigInt(n.value),chain:e.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 L(e){return e.account!==void 0}function $(e,n){return types.invariant(L(e),"Wallet client with account is required"),K(e,n)}function N(e,n,r){let t=e?.blockExplorers?.default?.url,a=t&&new URL(`/tx/${n}`,t).toString();return core.TransactionError.new({txHash:n,request:r,link:a})}function Y(e,n,r){return types.ResultAsync.fromPromise(actions.waitForTransactionReceipt(e,{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(N(e.chain,a,n));case "success":return types.okAsync({txHash:a,operations:n.operations})}})}function c(e,n){return $(e,n).andThen(r=>Y(e,n,r))}function A(e,n){switch(n.__typename){case "TransactionRequest":return c(e,n);case "Erc20ApprovalRequired":return n.approvals.reduce((r,t)=>r.andThen(()=>c(e,t.byTransaction)),types.okAsync(void 0)).andThen(()=>c(e,n.originalTransaction));case "PreContractActionRequired":return c(e,n.transaction).andThen(()=>c(e,n.originalTransaction));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(n))}}function Te(e,n){return n?A(e,n):A.bind(null,e)}function z(e,n){return n===void 0?g.bind(null,e):g(e,n)}function he(e,n){return n().andThen(r=>{if(E(r)){let t=r.approvals[0].bySignature;return z(e,t).map(a=>({deadline:t.message.deadline,value:a})).andThen(a=>n(a))}return types.okAsync(r)})}exports.ensureChain=fe;exports.permitWith=he;exports.sendTransaction=$;exports.sendWith=Te;exports.signTypedDataWith=z;exports.toViemChain=W;exports.transactionError=N;exports.viemChainsFrom=me;exports.waitForTransactionResult=Y;//# sourceMappingURL=viem.cjs.map
|
|
3
2
|
//# sourceMappingURL=viem.cjs.map
|