@aave/react 4.0.0-next.7 → 4.0.0-next.8
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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +67 -12
- package/dist/index.d.ts +67 -12
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/thirdweb.cjs +1 -1
- package/dist/thirdweb.cjs.map +1 -1
- package/dist/thirdweb.js +1 -1
- package/dist/thirdweb.js.map +1 -1
- package/dist/viem/index.cjs +1 -1
- package/dist/viem/index.cjs.map +1 -1
- package/dist/viem/index.js +1 -1
- package/dist/viem/index.js.map +1 -1
- package/package.json +4 -4
package/dist/viem/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/viem/adapters.ts","../../src/viem/useNetworkFee.ts"],"names":["useSendTransaction","walletClient","client","useAaveClient","useAsyncTask","request","invariant","ensureChain","sendTransaction","hash","PendingTransaction","waitForTransactionResult","useERC20Permit","permitTypedData","usePermitTypedDataAction","signERC20PermitWith","useSignSwapTypedDataWith","typedData","signSwapTypedDataWith","estimatedApprovalGas","gasEstimates","inferGasEstimate","action","key","never","extractReserveId","extractChainId","reserveId","decodeReserveId","inferChainId","query","inferTimestampForExchangeRateLookup","resolveChain","okAsync","fetchChain","nonNullable","useExecutionDetails","chain","publicClient","createPublicClient","toViemChain","http","ResultAsync","error","UnexpectedError","receipt","maxFeePerGas","createNetworkFeeAmount","details","rate","gasCostInWei","gasCost","bigDecimal","amount","RoundingMode","useNetworkFee","currency","Currency","pause","suspense","fetchDetails","useExchangeRate","useEffect","ReadResult"],"mappings":"6kBAsCO,SAASA,CAAAA,CACdC,IAC0B,CAC1B,IAAMC,CAAAA,CAASC,CAAAA,GAEf,OAAOC,CAAAA,CACJC,CAAAA,GACCC,SAAAA,CACEL,IACA,yDACF,CAAA,CAEOM,YAAYL,CAAAA,CAAQD,GAAA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A,CAAIzB,CAAAA,CAAoCD,CAAK,EAC7C,KAAA,CAAA4B,CAAAA,CACA,GAAIC,CAAAA,CAAW,CAAE,SAAAA,CAAS,CAAA,CAAI,EAChC,CAAC,CAAA,CASD,OANAG,SAAAA,CAAU,IAAM,CACVJ,CAAAA,EAASV,CAAAA,CAAQ,MAAA,EAAU,CAAClB,GAEhC8B,CAAAA,CAAa9B,CAAK,EACpB,CAAA,CAAG,CAAC8B,EAAcF,CAAAA,CAAOV,CAAAA,CAAQ,MAAM,CAAC,EAEpCC,CAAAA,CAAK,MAAA,CACAc,IAAW,MAAA,CAChBf,CAAAA,CAAQ,MAAQC,CAAAA,CAAK,IAAA,CACjBF,CAAAA,CAAuBC,CAAAA,CAAQ,KAAMC,CAAAA,CAAK,IAAI,EAC9C,MAAA,CACJA,CAAAA,CAAK,MAAQA,CAAAA,CAAK,KAAA,CAAQ,MAC5B,CAAA,CAGE,CAACD,CAAAA,CAAQ,MAAA,EAAUA,CAAAA,CAAQ,OAAA,EAAWC,EAAK,OAAA,CACtCc,GAAAA,CAAW,OAAA,EAAQ,CAGxBf,EAAQ,KAAA,EAASC,CAAAA,CAAK,MACjBc,GAAAA,CAAW,OAAA,CAChBf,EAAQ,KAAA,EAASC,CAAAA,CAAK,KAAA,EAASzB,KAAAA,CAAM,eAAe,CACtD,CAAA,EAGFlB,UACE0C,CAAAA,CAAQ,IAAA,EAAQC,EAAK,IAAA,CACrB,wCACF,CAAA,CAEOc,GAAAA,CAAW,QAAQhB,CAAAA,CAAuBC,CAAAA,CAAQ,KAAMC,CAAAA,CAAK,IAAI,CAAC,CAAA,CAC3E,CAAA","file":"index.js","sourcesContent":["import type { SigningError, UnexpectedError } from '@aave/client';\nimport {\n ensureChain,\n sendTransaction,\n signERC20PermitWith,\n signSwapTypedDataWith,\n waitForTransactionResult,\n} from '@aave/client/viem';\nimport type {\n ERC20PermitSignature,\n PermitRequest,\n SwapByIntentTypedData,\n TransactionRequest,\n} from '@aave/graphql';\nimport { invariant } from '@aave/types';\nimport type { WalletClient } from 'viem';\nimport { useAaveClient } from '../context';\nimport {\n PendingTransaction,\n type UseAsyncTask,\n type UseSendTransactionResult,\n useAsyncTask,\n} from '../helpers';\nimport { usePermitTypedDataAction } from '../permits';\n\n/**\n * A hook that provides a way to send Aave transactions using a viem WalletClient instance.\n *\n * Use the `useWalletClient` wagmi hook to get the `WalletClient` instance, then pass it to this hook to create a function that can be used to send transactions.\n *\n * ```ts\n * const { data: wallet } = useWalletClient(); // wagmi hook\n *\n * const [sendTransaction] = useSendTransaction(wallet);\n * ```\n *\n * @param walletClient - The wallet client to use for sending transactions.\n */\nexport function useSendTransaction(\n walletClient: WalletClient | undefined,\n): UseSendTransactionResult {\n const client = useAaveClient();\n\n return useAsyncTask(\n (request: TransactionRequest) => {\n invariant(\n walletClient,\n 'Expected a WalletClient to handle the operation result.',\n );\n\n return ensureChain(client, walletClient, request)\n .andThen(() => sendTransaction(walletClient, request))\n .map(\n (hash) =>\n new PendingTransaction(() =>\n waitForTransactionResult(walletClient, request, hash),\n ),\n );\n },\n [client, walletClient],\n );\n}\n\nexport type SignERC20PermitError = SigningError | UnexpectedError;\n\n/**\n * A hook that provides a way to sign ERC20 permits using a viem WalletClient instance.\n *\n * ```ts\n * const { data: wallet } = useWalletClient(); // wagmi hook\n * const [signERC20Permit, { loading, error, data }] = useERC20Permit(wallet);\n *\n * const run = async () => {\n * const result = await signERC20Permit({\n * supply: {\n * sender: evmAddress(wallet.account.address), // User's address\n * reserve: {\n * reserveId: reserve.id,\n * chainId: reserve.chain.chainId,\n * spoke: reserve.spoke.address,\n * },\n * amount: {\n * value: bigDecimal(42), // 42 USDC\n * },\n * },\n * });\n *\n * if (result.isErr()) {\n * console.error(result.error);\n * return;\n * }\n *\n * console.log('ERC20 Permit signature:', result.value);\n * };\n * ```\n */\nexport function useERC20Permit(\n walletClient: WalletClient | undefined,\n): UseAsyncTask<PermitRequest, ERC20PermitSignature, SignERC20PermitError> {\n const [permitTypedData] = usePermitTypedDataAction();\n\n return useAsyncTask(\n (request: PermitRequest) => {\n invariant(walletClient, 'Expected a WalletClient to sign ERC20 permits');\n\n return permitTypedData(request).andThen(\n signERC20PermitWith(walletClient),\n );\n },\n [permitTypedData, walletClient],\n );\n}\n\nexport type SignSwapTypedDataError = SigningError | UnexpectedError;\n\n/**\n * @internal\n * A hook that provides a way to sign swap typed data using a viem WalletClient instance.\n *\n * ```ts\n * const { data: wallet } = useWalletClient(); // wagmi hook\n * const [signSwapTypedData, { loading, error, data }] = useSignSwapTypedDataWith(wallet);\n *\n * const run = async () => {\n * const result = await signSwapTypedData(swapTypedData);\n *\n * if (result.isErr()) {\n * console.error(result.error);\n * return;\n * }\n *\n * console.log('Swap typed data signed:', result.value);\n * };\n * ```\n */\nexport function useSignSwapTypedDataWith(\n walletClient: WalletClient | undefined,\n): UseAsyncTask<\n SwapByIntentTypedData,\n ERC20PermitSignature,\n SignSwapTypedDataError\n> {\n return useAsyncTask(\n (typedData: SwapByIntentTypedData) => {\n invariant(\n walletClient,\n 'Expected a WalletClient to sign swap typed data',\n );\n\n return signSwapTypedDataWith(walletClient)(typedData);\n },\n [walletClient],\n );\n}\n","import { type AaveClient, UnexpectedError } from '@aave/client';\nimport { chain as fetchChain } from '@aave/client/actions';\nimport { toViemChain } from '@aave/client/viem';\nimport {\n type Chain,\n Currency,\n type DecimalNumber,\n decodeReserveId,\n type ExchangeAmount,\n type NativeAmount,\n type PreviewAction,\n type ReserveId,\n} from '@aave/graphql';\nimport {\n bigDecimal,\n type ChainId,\n invariant,\n never,\n nonNullable,\n okAsync,\n ResultAsync,\n RoundingMode,\n} from '@aave/types';\nimport { useEffect } from 'react';\nimport { createPublicClient, http } from 'viem';\nimport { useAaveClient } from '../context';\nimport {\n ReadResult,\n type SuspendableResult,\n type UseAsyncTask,\n useAsyncTask,\n} from '../helpers';\nimport {\n type UseNetworkFee,\n type UseNetworkFeeRequestQuery,\n useExchangeRate,\n} from '../misc';\n\nconst estimatedApprovalGas = 55_558n;\n\nconst gasEstimates: Record<keyof PreviewAction, bigint> = {\n supply: 132_136n + estimatedApprovalGas,\n borrow: 250_551n,\n withdraw: 195_049n,\n repay: 217_889n + estimatedApprovalGas,\n setUserSuppliesAsCollateral: 240_284n,\n};\n\nfunction inferGasEstimate(action: PreviewAction): bigint {\n const key = Object.keys(action)[0] as keyof PreviewAction;\n return gasEstimates[key] ?? never(`Expected gas estimate for action ${key}`);\n}\n\nfunction extractReserveId(action: PreviewAction): ReserveId {\n if ('supply' in action) {\n return action.supply.reserve;\n }\n\n if ('borrow' in action) {\n return action.borrow.reserve;\n }\n\n if ('withdraw' in action) {\n return action.withdraw.reserve;\n }\n\n if ('repay' in action) {\n return action.repay.reserve;\n }\n\n if ('setUserSuppliesAsCollateral' in action) {\n // assumes they are all on the same chain\n return action.setUserSuppliesAsCollateral.changes[0]!.reserve;\n }\n\n return never('Expected reserve id');\n}\n\nfunction extractChainId(action: PreviewAction): ChainId {\n const reserveId = extractReserveId(action);\n return decodeReserveId(reserveId).chainId;\n}\n\nfunction inferChainId(query: UseNetworkFeeRequestQuery): ChainId | undefined {\n if ('activity' in query && query.activity) {\n return query.activity.chain.chainId;\n }\n\n if ('estimate' in query && query.estimate) {\n return extractChainId(query.estimate);\n }\n\n return undefined;\n}\n\nfunction inferTimestampForExchangeRateLookup(\n query: UseNetworkFeeRequestQuery,\n): Date | undefined {\n if ('activity' in query && query.activity) {\n return query.activity.timestamp;\n }\n return undefined; // i.e., now\n}\n\nfunction resolveChain(\n client: AaveClient,\n query: UseNetworkFeeRequestQuery,\n): ResultAsync<Chain, UnexpectedError> {\n if ('activity' in query && query.activity) {\n return okAsync(query.activity.chain);\n }\n\n if ('estimate' in query && query.estimate) {\n return fetchChain(client, {\n chainId: extractChainId(query.estimate),\n }).map(nonNullable);\n }\n\n return never('Expected chain');\n}\n\ntype ExecutionDetails = {\n chain: Chain;\n gasPrice: bigint;\n gasUnits: bigint;\n};\n\nfunction useExecutionDetails(): UseAsyncTask<\n UseNetworkFeeRequestQuery,\n ExecutionDetails,\n UnexpectedError\n> {\n const client = useAaveClient();\n\n return useAsyncTask(\n (query) =>\n resolveChain(client, query).andThen((chain) => {\n const publicClient = createPublicClient({\n chain: toViemChain(chain),\n transport: http(),\n });\n\n if ('activity' in query) {\n return ResultAsync.fromPromise(\n publicClient.getTransactionReceipt({ hash: query.activity.txHash }),\n (error) => UnexpectedError.from(error),\n ).map((receipt) => {\n return {\n chain: query.activity.chain,\n gasPrice: receipt.effectiveGasPrice,\n gasUnits: receipt.gasUsed,\n };\n });\n }\n\n if ('estimate' in query && query.estimate) {\n return ResultAsync.fromPromise(\n publicClient.estimateFeesPerGas(),\n (error) => UnexpectedError.from(error),\n ).map(({ maxFeePerGas }) => {\n return {\n chain,\n gasPrice: maxFeePerGas,\n gasUnits: inferGasEstimate(query.estimate),\n };\n });\n }\n\n return okAsync({\n chain: never('Expected chain'),\n gasPrice: 0n,\n gasUnits: 0n,\n });\n }),\n [client],\n );\n}\n\nfunction createNetworkFeeAmount(\n details: ExecutionDetails,\n rate: ExchangeAmount,\n): NativeAmount {\n const gasCostInWei = details.gasPrice * details.gasUnits;\n const gasCost = bigDecimal(gasCostInWei).rescale(\n -details.chain.nativeInfo.decimals,\n );\n\n const amount: DecimalNumber = {\n __typename: 'DecimalNumber',\n decimals: details.chain.nativeInfo.decimals,\n onChainValue: gasCostInWei,\n value: gasCost,\n };\n\n return {\n __typename: 'NativeAmount',\n token: {\n __typename: 'NativeToken',\n info: details.chain.nativeInfo,\n chain: details.chain,\n },\n amount,\n exchange: {\n __typename: 'ExchangeAmount',\n value: gasCost.mul(rate.value),\n name: rate.name,\n symbol: rate.symbol,\n icon: rate.icon,\n decimals: rate.decimals,\n },\n exchangeRate: {\n __typename: 'DecimalNumber',\n decimals: 2,\n onChainValue: BigInt(rate.value.rescale(2).toFixed(0, RoundingMode.Down)),\n value: rate.value,\n },\n };\n}\n\n/**\n * Fetch the network fee for an ActivityItem or estimates networkf feed for a preview action.\n *\n * @experimental This hook is experimental and may be subject to breaking changes.\n */\nexport const useNetworkFee: UseNetworkFee = (({\n query,\n currency = Currency.Usd,\n pause = false,\n suspense = false,\n}: {\n query: UseNetworkFeeRequestQuery;\n currency?: Currency;\n pause?: boolean;\n suspense?: boolean;\n}): SuspendableResult<NativeAmount, UnexpectedError> => {\n const [fetchDetails, details] = useExecutionDetails();\n\n const rate = useExchangeRate({\n from: {\n native: inferChainId(query),\n },\n to: currency,\n at: inferTimestampForExchangeRateLookup(query),\n pause,\n ...(suspense ? { suspense } : {}),\n });\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: query omitted since it's usually a literal object that changes at every render\n useEffect(() => {\n if (pause || details.called || !query) return;\n\n fetchDetails(query);\n }, [fetchDetails, pause, details.called]);\n\n if (rate.paused) {\n return ReadResult.Paused(\n details.data && rate.data\n ? createNetworkFeeAmount(details.data, rate.data)\n : undefined,\n rate.error ? rate.error : undefined,\n );\n }\n\n if (!details.called || details.loading || rate.loading) {\n return ReadResult.Loading();\n }\n\n if (details.error || rate.error) {\n return ReadResult.Failure(\n details.error ?? rate.error ?? never('Unknown error'),\n );\n }\n\n invariant(\n details.data && rate.data,\n 'Expected receipt, chain, and rate data',\n );\n\n return ReadResult.Success(createNetworkFeeAmount(details.data, rate.data));\n}) as UseNetworkFee;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/viem/adapters.ts","../../src/viem/useNetworkFee.ts"],"names":["useSendTransaction","walletClient","client","useAaveClient","useAsyncTask","request","invariant","ensureChain","sendTransaction","hash","PendingTransaction","waitForTransactionResult","useERC20Permit","permitTypedData","usePermitTypedDataAction","signERC20PermitWith","useSignSwapTypedDataWith","typedData","signSwapTypedDataWith","estimatedApprovalGas","gasEstimates","inferGasEstimate","action","key","never","extractChainId","decodeReserveId","reserve","prev","current","inferChainId","query","inferTimestampForExchangeRateLookup","resolveChain","okAsync","fetchChain","nonNullable","useExecutionDetails","chain","publicClient","createPublicClient","toViemChain","http","ResultAsync","error","UnexpectedError","receipt","maxFeePerGas","createNetworkFeeAmount","details","rate","gasCostInWei","gasCost","bigDecimal","amount","RoundingMode","useNetworkFee","currency","Currency","pause","suspense","fetchDetails","useExchangeRate","useEffect","ReadResult"],"mappings":"6kBAsCO,SAASA,CAAAA,CACdC,GAAAA,CAC0B,CAC1B,IAAMC,CAAAA,CAASC,GAAc,CAE7B,OAAOC,EACJC,CAAAA,GACCC,SAAAA,CACEL,GAAAA,CACA,yDACF,EAEOM,WAAAA,CAAYL,CAAAA,CAAQD,IAAcI,CAAO,CAAA,CAC7C,QAAQ,IAAMG,eAAAA,CAAgBP,GAAAA,CAAcI,CAAO,CAAC,CAAA,CACpD,GAAA,CACEI,GACC,IAAIC,CAAAA,CAAmB,IACrBC,wBAAAA,CAAyBV,GAAAA,CAAcI,CAAAA,CAASI,CAAI,CACtD,CACJ,CAAA,CAAA,CAEJ,CAACP,CAAAA,CAAQD,GAAY,CACvB,CACF,CAmCO,SAASW,CAAAA,CACdX,EACyE,CACzE,GAAM,CAACY,CAAe,CAAA,CAAIC,GAAyB,CAEnD,OAAOV,EACJC,CAAAA,GACCC,SAAAA,CAAUL,EAAc,+CAA+C,CAAA,CAEhEY,EAAgBR,CAAO,CAAA,CAAE,QAC9BU,mBAAAA,CAAoBd,CAAY,CAClC,CAAA,CAAA,CAEF,CAACY,CAAAA,CAAiBZ,CAAY,CAChC,CACF,CAwBO,SAASe,CAAAA,CACdf,CAAAA,CAKA,CACA,OAAOG,EACJa,CAAAA,GACCX,SAAAA,CACEL,EACA,iDACF,CAAA,CAEOiB,sBAAsBjB,CAAY,CAAA,CAAEgB,CAAS,CAAA,CAAA,CAEtD,CAAChB,CAAY,CACf,CACF,CCpHA,IAAMkB,EAAuB,MAAA,CAEvBC,CAAAA,CAAoD,CACxD,MAAA,CAAQ,OAAA,CAAWD,EACnB,MAAA,CAAQ,OAAA,CACR,SAAU,OAAA,CACV,KAAA,CAAO,QAAWA,CAAAA,CAClB,2BAAA,CAA6B,OA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,OAAA,GAGhBf,CAAAA,CAAQ,KAAA,EAASC,EAAK,KAAA,CACjBc,GAAAA,CAAW,QAChBf,CAAAA,CAAQ,KAAA,EAASC,CAAAA,CAAK,KAAA,EAAS1B,MAAM,eAAe,CACtD,GAGFlB,SAAAA,CACE2C,CAAAA,CAAQ,MAAQC,CAAAA,CAAK,IAAA,CACrB,wCACF,CAAA,CAEOc,GAAAA,CAAW,QAAQhB,CAAAA,CAAuBC,CAAAA,CAAQ,KAAMC,CAAAA,CAAK,IAAI,CAAC,CAAA,CAC3E,CAAA","file":"index.js","sourcesContent":["import type { SigningError, UnexpectedError } from '@aave/client';\nimport {\n ensureChain,\n sendTransaction,\n signERC20PermitWith,\n signSwapTypedDataWith,\n waitForTransactionResult,\n} from '@aave/client/viem';\nimport type {\n ERC20PermitSignature,\n PermitRequest,\n SwapByIntentTypedData,\n TransactionRequest,\n} from '@aave/graphql';\nimport { invariant } from '@aave/types';\nimport type { WalletClient } from 'viem';\nimport { useAaveClient } from '../context';\nimport {\n PendingTransaction,\n type UseAsyncTask,\n type UseSendTransactionResult,\n useAsyncTask,\n} from '../helpers';\nimport { usePermitTypedDataAction } from '../permits';\n\n/**\n * A hook that provides a way to send Aave transactions using a viem WalletClient instance.\n *\n * Use the `useWalletClient` wagmi hook to get the `WalletClient` instance, then pass it to this hook to create a function that can be used to send transactions.\n *\n * ```ts\n * const { data: wallet } = useWalletClient(); // wagmi hook\n *\n * const [sendTransaction] = useSendTransaction(wallet);\n * ```\n *\n * @param walletClient - The wallet client to use for sending transactions.\n */\nexport function useSendTransaction(\n walletClient: WalletClient | undefined,\n): UseSendTransactionResult {\n const client = useAaveClient();\n\n return useAsyncTask(\n (request: TransactionRequest) => {\n invariant(\n walletClient,\n 'Expected a WalletClient to handle the operation result.',\n );\n\n return ensureChain(client, walletClient, request)\n .andThen(() => sendTransaction(walletClient, request))\n .map(\n (hash) =>\n new PendingTransaction(() =>\n waitForTransactionResult(walletClient, request, hash),\n ),\n );\n },\n [client, walletClient],\n );\n}\n\nexport type SignERC20PermitError = SigningError | UnexpectedError;\n\n/**\n * A hook that provides a way to sign ERC20 permits using a viem WalletClient instance.\n *\n * ```ts\n * const { data: wallet } = useWalletClient(); // wagmi hook\n * const [signERC20Permit, { loading, error, data }] = useERC20Permit(wallet);\n *\n * const run = async () => {\n * const result = await signERC20Permit({\n * supply: {\n * sender: evmAddress(wallet.account.address), // User's address\n * reserve: {\n * reserveId: reserve.id,\n * chainId: reserve.chain.chainId,\n * spoke: reserve.spoke.address,\n * },\n * amount: {\n * value: bigDecimal(42), // 42 USDC\n * },\n * },\n * });\n *\n * if (result.isErr()) {\n * console.error(result.error);\n * return;\n * }\n *\n * console.log('ERC20 Permit signature:', result.value);\n * };\n * ```\n */\nexport function useERC20Permit(\n walletClient: WalletClient | undefined,\n): UseAsyncTask<PermitRequest, ERC20PermitSignature, SignERC20PermitError> {\n const [permitTypedData] = usePermitTypedDataAction();\n\n return useAsyncTask(\n (request: PermitRequest) => {\n invariant(walletClient, 'Expected a WalletClient to sign ERC20 permits');\n\n return permitTypedData(request).andThen(\n signERC20PermitWith(walletClient),\n );\n },\n [permitTypedData, walletClient],\n );\n}\n\nexport type SignSwapTypedDataError = SigningError | UnexpectedError;\n\n/**\n * @internal\n * A hook that provides a way to sign swap typed data using a viem WalletClient instance.\n *\n * ```ts\n * const { data: wallet } = useWalletClient(); // wagmi hook\n * const [signSwapTypedData, { loading, error, data }] = useSignSwapTypedDataWith(wallet);\n *\n * const run = async () => {\n * const result = await signSwapTypedData(swapTypedData);\n *\n * if (result.isErr()) {\n * console.error(result.error);\n * return;\n * }\n *\n * console.log('Swap typed data signed:', result.value);\n * };\n * ```\n */\nexport function useSignSwapTypedDataWith(\n walletClient: WalletClient | undefined,\n): UseAsyncTask<\n SwapByIntentTypedData,\n ERC20PermitSignature,\n SignSwapTypedDataError\n> {\n return useAsyncTask(\n (typedData: SwapByIntentTypedData) => {\n invariant(\n walletClient,\n 'Expected a WalletClient to sign swap typed data',\n );\n\n return signSwapTypedDataWith(walletClient)(typedData);\n },\n [walletClient],\n );\n}\n","import { type AaveClient, UnexpectedError } from '@aave/client';\nimport { chain as fetchChain } from '@aave/client/actions';\nimport { toViemChain } from '@aave/client/viem';\nimport {\n type Chain,\n Currency,\n type DecimalNumber,\n decodeReserveId,\n type ExchangeAmount,\n type NativeAmount,\n type PreviewAction,\n} from '@aave/graphql';\nimport {\n bigDecimal,\n type ChainId,\n invariant,\n never,\n nonNullable,\n okAsync,\n ResultAsync,\n RoundingMode,\n} from '@aave/types';\nimport { useEffect } from 'react';\nimport { createPublicClient, http } from 'viem';\nimport { useAaveClient } from '../context';\nimport {\n ReadResult,\n type SuspendableResult,\n type UseAsyncTask,\n useAsyncTask,\n} from '../helpers';\nimport {\n type UseNetworkFee,\n type UseNetworkFeeRequestQuery,\n useExchangeRate,\n} from '../misc';\n\nconst estimatedApprovalGas = 55_558n;\n\nconst gasEstimates: Record<keyof PreviewAction, bigint> = {\n supply: 132_136n + estimatedApprovalGas,\n borrow: 250_551n,\n withdraw: 195_049n,\n repay: 217_889n + estimatedApprovalGas,\n setUserSuppliesAsCollateral: 240_284n,\n};\n\nfunction inferGasEstimate(action: PreviewAction): bigint {\n const key = Object.keys(action)[0] as keyof PreviewAction;\n return gasEstimates[key] ?? never(`Expected gas estimate for action ${key}`);\n}\n\nfunction extractChainId(action: PreviewAction): ChainId {\n if ('supply' in action) {\n return decodeReserveId(action.supply.reserve).chainId;\n }\n\n if ('borrow' in action) {\n return decodeReserveId(action.borrow.reserve).chainId;\n }\n\n if ('withdraw' in action) {\n return decodeReserveId(action.withdraw.reserve).chainId;\n }\n\n if ('repay' in action) {\n return decodeReserveId(action.repay.reserve).chainId;\n }\n\n if ('setUserSuppliesAsCollateral' in action) {\n return action.setUserSuppliesAsCollateral.changes\n .map(({ reserve }) => decodeReserveId(reserve))\n .reduce((prev, current) => {\n invariant(\n prev.chainId === current.chainId && prev.spoke === current.spoke,\n 'All reserves MUST on the same spoke',\n );\n return prev;\n }).chainId;\n }\n\n never('Expected reserve id');\n}\n\nfunction inferChainId(query: UseNetworkFeeRequestQuery): ChainId | undefined {\n if ('activity' in query && query.activity) {\n return query.activity.chain.chainId;\n }\n\n if ('estimate' in query && query.estimate) {\n return extractChainId(query.estimate);\n }\n\n return undefined;\n}\n\nfunction inferTimestampForExchangeRateLookup(\n query: UseNetworkFeeRequestQuery,\n): Date | undefined {\n if ('activity' in query && query.activity) {\n return query.activity.timestamp;\n }\n return undefined; // i.e., now\n}\n\nfunction resolveChain(\n client: AaveClient,\n query: UseNetworkFeeRequestQuery,\n): ResultAsync<Chain, UnexpectedError> {\n if ('activity' in query && query.activity) {\n return okAsync(query.activity.chain);\n }\n\n if ('estimate' in query && query.estimate) {\n return fetchChain(client, {\n chainId: extractChainId(query.estimate),\n }).map(nonNullable);\n }\n\n return never('Expected chain');\n}\n\ntype ExecutionDetails = {\n chain: Chain;\n gasPrice: bigint;\n gasUnits: bigint;\n};\n\nfunction useExecutionDetails(): UseAsyncTask<\n UseNetworkFeeRequestQuery,\n ExecutionDetails,\n UnexpectedError\n> {\n const client = useAaveClient();\n\n return useAsyncTask(\n (query) =>\n resolveChain(client, query).andThen((chain) => {\n const publicClient = createPublicClient({\n chain: toViemChain(chain),\n transport: http(),\n });\n\n if ('activity' in query) {\n return ResultAsync.fromPromise(\n publicClient.getTransactionReceipt({ hash: query.activity.txHash }),\n (error) => UnexpectedError.from(error),\n ).map((receipt) => {\n return {\n chain: query.activity.chain,\n gasPrice: receipt.effectiveGasPrice,\n gasUnits: receipt.gasUsed,\n };\n });\n }\n\n if ('estimate' in query && query.estimate) {\n return ResultAsync.fromPromise(\n publicClient.estimateFeesPerGas(),\n (error) => UnexpectedError.from(error),\n ).map(({ maxFeePerGas }) => {\n return {\n chain,\n gasPrice: maxFeePerGas,\n gasUnits: inferGasEstimate(query.estimate),\n };\n });\n }\n\n return okAsync({\n chain: never('Expected chain'),\n gasPrice: 0n,\n gasUnits: 0n,\n });\n }),\n [client],\n );\n}\n\nfunction createNetworkFeeAmount(\n details: ExecutionDetails,\n rate: ExchangeAmount,\n): NativeAmount {\n const gasCostInWei = details.gasPrice * details.gasUnits;\n const gasCost = bigDecimal(gasCostInWei).rescale(\n -details.chain.nativeInfo.decimals,\n );\n\n const amount: DecimalNumber = {\n __typename: 'DecimalNumber',\n decimals: details.chain.nativeInfo.decimals,\n onChainValue: gasCostInWei,\n value: gasCost,\n };\n\n return {\n __typename: 'NativeAmount',\n token: {\n __typename: 'NativeToken',\n info: details.chain.nativeInfo,\n chain: details.chain,\n },\n amount,\n exchange: {\n __typename: 'ExchangeAmount',\n value: gasCost.mul(rate.value),\n name: rate.name,\n symbol: rate.symbol,\n icon: rate.icon,\n decimals: rate.decimals,\n },\n exchangeRate: {\n __typename: 'DecimalNumber',\n decimals: 2,\n onChainValue: BigInt(rate.value.rescale(2).toFixed(0, RoundingMode.Down)),\n value: rate.value,\n },\n };\n}\n\n/**\n * Fetch the network fee for an ActivityItem or estimates networkf feed for a preview action.\n *\n * @experimental This hook is experimental and may be subject to breaking changes.\n */\nexport const useNetworkFee: UseNetworkFee = (({\n query,\n currency = Currency.Usd,\n pause = false,\n suspense = false,\n}: {\n query: UseNetworkFeeRequestQuery;\n currency?: Currency;\n pause?: boolean;\n suspense?: boolean;\n}): SuspendableResult<NativeAmount, UnexpectedError> => {\n const [fetchDetails, details] = useExecutionDetails();\n\n const rate = useExchangeRate({\n from: {\n native: inferChainId(query),\n },\n to: currency,\n at: inferTimestampForExchangeRateLookup(query),\n pause,\n ...(suspense ? { suspense } : {}),\n });\n\n // biome-ignore lint/correctness/useExhaustiveDependencies: query omitted since it's usually a literal object that changes at every render\n useEffect(() => {\n if (pause || details.called || !query) return;\n\n fetchDetails(query);\n }, [fetchDetails, pause, details.called]);\n\n if (rate.paused) {\n return ReadResult.Paused(\n details.data && rate.data\n ? createNetworkFeeAmount(details.data, rate.data)\n : undefined,\n rate.error ? rate.error : undefined,\n );\n }\n\n if (!details.called || details.loading || rate.loading) {\n return ReadResult.Loading();\n }\n\n if (details.error || rate.error) {\n return ReadResult.Failure(\n details.error ?? rate.error ?? never('Unknown error'),\n );\n }\n\n invariant(\n details.data && rate.data,\n 'Expected receipt, chain, and rate data',\n );\n\n return ReadResult.Success(createNetworkFeeAmount(details.data, rate.data));\n}) as UseNetworkFee;\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aave/react",
|
|
3
|
-
"version": "4.0.0-next.
|
|
3
|
+
"version": "4.0.0-next.8",
|
|
4
4
|
"description": "The official React bindings for the Aave Protocol",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aave",
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
"sideEffects": false,
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"urql": "^5.0.1",
|
|
75
|
+
"@aave/client": "4.0.0-next.8",
|
|
76
|
+
"@aave/types": "1.0.0-next.4",
|
|
75
77
|
"@aave/core": "1.0.0-next.5",
|
|
76
|
-
"@aave/
|
|
77
|
-
"@aave/graphql": "1.0.0-next.6",
|
|
78
|
-
"@aave/types": "1.0.0-next.4"
|
|
78
|
+
"@aave/graphql": "1.0.0-next.7"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
81
|
"@privy-io/react-auth": "^2.20.0",
|