@aave/client 4.0.0-next.9 → 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 +454 -178
- package/dist/actions/index.d.ts +454 -178
- 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-OKIVO6WG.js +0 -2
- package/dist/chunk-OKIVO6WG.js.map +0 -1
- package/dist/chunk-QV7WXM6U.js +0 -3
- package/dist/chunk-QV7WXM6U.js.map +0 -1
- package/dist/types-Bu63z0x6.d.cts +0 -21
- package/dist/types-Bu63z0x6.d.ts +0 -21
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/cache.ts","../src/environments.ts","../src/config.ts","../src/types.ts","../src/AaveClient.ts"],"names":["transformToBigInt","parent","_args","_cache","info","transformToBigDecimal","BigDecimal","transformToNullableBigDecimal","value","transformToDate","transformToNullableDate","exchange","cacheExchange","introspectedSchema","_","request","isHubInputVariant","encodeHubId","_parent","args","cache","isTxHashInputVariant","txHash","chainId","matches","f","set","pageRef","itemRefs","ref","spokeRef","chainRef","itemChainId","data","production","staging","local","configureContext","environment","headers","debug","fragments","isHasProcessedKnownTransactionRequest","result","AaveClient","_AaveClient","GqlClient","options","invariant","ResultAsync","err","TimeoutError","UnexpectedError","document","predicate","op","startedAt","hasProcessedKnownTransaction","ok","delay"],"mappings":"6dAqCA,IAAMA,CAAAA,CAA8B,CAACC,CAAAA,CAAQC,CAAAA,CAAOC,CAAAA,CAAQC,CAAAA,GACnD,MAAA,CAAOH,CAAAA,CAAOG,CAAAA,CAAK,SAAS,CAAW,CAAA,CAG1CC,CAAAA,CAAkC,CAACJ,CAAAA,CAAQC,CAAAA,CAAOC,CAAAA,CAAQC,CAAAA,GACvDE,UAAAA,CAAW,GAAA,CAAIL,EAAOG,CAAAA,CAAK,SAAS,CAAW,CAAA,CAGlDG,CAAAA,CAA0C,CAC9CN,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,GACG,CACH,IAAMI,CAAAA,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,CACR,KAAA,CAGFW,CAAAA,CAAUC,CAAAA,CAAG,SAAA,CAAyBZ,CAAAA,CAAO,KAAe,CACrE,CACA,OAAO,MACT,CAAC,EACH,CAEA,MAAgB,qBAAA,CACd5B,CAAAA,CACiB,CACjB,IAAMyC,CAAAA,CAAY,IAAA,CAAK,GAAA,EAAI,CAE3B,KAAO,IAAA,CAAK,GAAA,EAAI,CAAIA,CAAAA,CAAY,IAAA,CAAK,OAAA,CAAQ,WAAA,CAAY,eAAA,EAAiB,CAQxE,GAPkB,MAAMC,GAAAA,CAA6B,IAAA,CAAM1C,CAAO,CAAA,CAAE,KAAA,CACjE2C,CAAAA,EAAOA,CAAAA,CACPR,CAAAA,EAAQ,CACP,MAAMA,CACR,CACF,CAAA,CAGE,OAAOnC,EAAQ,MAAA,CAGjB,MAAM4C,KAAAA,CAAM,IAAA,CAAK,OAAA,CAAQ,WAAA,CAAY,eAAe,EACtD,CACA,MAAMR,YAAAA,CAAa,IAAA,CACjB,CAAA,gCAAA,EAAmCpC,CAAAA,CAAQ,MAAM,CAAA,iBAAA,CACnD,CACF,CACF","file":"index.js","sourcesContent":["import {\n type ActivitiesQuery,\n type BorrowActivity,\n type Chain,\n type Erc20Token,\n encodeHubId,\n type Hub,\n type HubAsset,\n type HubQuery,\n isHubInputVariant,\n isTxHashInputVariant,\n type LiquidatedActivity,\n type NativeToken,\n type RepayActivity,\n type Reserve,\n type ReserveInfo,\n type Spoke,\n type SupplyActivity,\n type SwapByIntent,\n type SwapByIntentWithApprovalRequired,\n type SwapByTransaction,\n type TokenInfo,\n type UpdatedDynamicConfigActivity,\n type UpdatedRiskPremiumActivity,\n type UserPosition,\n type UsingAsCollateralActivity,\n type VariablesOf,\n type WithdrawActivity,\n} from '@aave/graphql';\nimport introspectedSchema from '@aave/graphql/schema';\nimport { BigDecimal, type TxHash } from '@aave/types';\nimport {\n cacheExchange,\n type Resolver,\n type Scalar,\n} from '@urql/exchange-graphcache';\n\nconst transformToBigInt: Resolver = (parent, _args, _cache, info) => {\n return BigInt(parent[info.fieldName] as string) as unknown as Scalar;\n};\n\nconst transformToBigDecimal: Resolver = (parent, _args, _cache, info) => {\n return BigDecimal.new(parent[info.fieldName] as string);\n};\n\nconst transformToNullableBigDecimal: Resolver = (\n parent,\n _args,\n _cache,\n info,\n) => {\n const value = parent[info.fieldName];\n if (value === null || value === undefined) {\n return null;\n }\n return transformToBigDecimal(parent, _args, _cache, info);\n};\n\nconst transformToDate: Resolver = (parent, _args, _cache, info) => {\n return new Date(parent[info.fieldName] as string);\n};\n\nconst transformToNullableDate: Resolver = (parent, _args, _cache, info) => {\n const value = parent[info.fieldName];\n if (value === null || value === undefined) {\n return null;\n }\n return transformToDate(parent, _args, _cache, info);\n};\n\nexport const exchange = cacheExchange({\n schema: introspectedSchema,\n resolvers: {\n PercentNumber: {\n onChainValue: transformToBigInt,\n value: transformToBigDecimal,\n normalized: transformToBigDecimal,\n },\n DecimalNumber: {\n onChainValue: transformToBigInt,\n value: transformToBigDecimal,\n },\n ExchangeAmount: {\n value: transformToBigDecimal,\n },\n AssetPriceSample: {\n price: transformToBigDecimal,\n date: transformToDate,\n },\n Reserve: {\n borrowCap: transformToBigDecimal,\n supplyCap: transformToBigDecimal,\n },\n HealthFactorError: {\n current: transformToNullableBigDecimal,\n after: transformToNullableBigDecimal,\n },\n HealthFactorVariation: {\n current: transformToNullableBigDecimal,\n after: transformToNullableBigDecimal,\n },\n HealthFactorWithChange: {\n current: transformToNullableBigDecimal,\n },\n UserSummary: {\n lowestHealthFactor: transformToNullableBigDecimal,\n },\n UserSummaryHistoryItem: {\n healthFactor: transformToNullableBigDecimal,\n date: transformToDate,\n },\n TransactionRequest: {\n value: transformToBigInt,\n },\n ApySample: {\n date: transformToDate,\n },\n AssetBorrowSample: {\n date: transformToDate,\n },\n AssetCategoryBorrowSample: {\n date: transformToDate,\n },\n AssetCategorySupplySample: {\n date: transformToDate,\n },\n AssetSupplySample: {\n date: transformToDate,\n },\n HubSummarySample: {\n date: transformToDate,\n },\n ProtocolHistorySample: {\n date: transformToDate,\n },\n BorrowActivity: {\n timestamp: transformToDate,\n },\n LiquidatedActivity: {\n timestamp: transformToDate,\n },\n RepayActivity: {\n timestamp: transformToDate,\n },\n SupplyActivity: {\n timestamp: transformToDate,\n },\n WithdrawActivity: {\n timestamp: transformToDate,\n },\n UsingAsCollateralActivity: {\n timestamp: transformToDate,\n },\n UpdatedDynamicConfigActivity: {\n timestamp: transformToDate,\n },\n UpdatedRiskPremiumActivity: {\n timestamp: transformToDate,\n },\n SpokeUserPositionManager: {\n approvedOn: transformToDate,\n },\n SwapCancelled: {\n createdAt: transformToDate,\n cancelledAt: transformToNullableDate,\n },\n SwapExpired: {\n createdAt: transformToDate,\n expiredAt: transformToDate,\n },\n SwapFulfilled: {\n createdAt: transformToDate,\n fulfilledAt: transformToDate,\n },\n SwapOpen: {\n createdAt: transformToDate,\n deadline: transformToDate,\n },\n SwapPendingSignature: {\n createdAt: transformToDate,\n deadline: transformToDate,\n },\n SwapReceipt: {\n createdAt: transformToDate,\n },\n // Intentionally omitted to keep it as BigIntString\n // PermitMessageData: {\n // value: transformToBigInt,\n // nonce: transformToBigInt,\n // },\n\n Query: {\n hub: (_, { request }: VariablesOf<typeof HubQuery>) => {\n if (isHubInputVariant(request.query)) {\n return {\n __typename: 'Hub',\n id: encodeHubId(request.query.hubInput),\n };\n }\n return {\n __typename: 'Hub',\n id: request.query.hubId,\n };\n },\n\n activities: (\n _parent,\n args: VariablesOf<typeof ActivitiesQuery>,\n cache,\n ) => {\n // Bail out if not a txHash filter lookup\n if (!isTxHashInputVariant(args.request.query)) {\n return cache.resolve('Query', 'activities', args);\n }\n\n const { txHash, chainId } = args.request.query.txHash;\n\n // Collect all cached activities matching txHash\n const matches = cache\n .inspectFields('Query')\n .filter((f) => f.fieldName === 'activities')\n .reduce((set, f) => {\n const pageRef = cache.resolve('Query', f.fieldKey) as string | null;\n if (!pageRef) return set;\n\n const itemRefs = cache.resolve(pageRef, 'items') as string[] | null;\n if (!itemRefs) return set;\n\n for (const ref of itemRefs) {\n set.add(ref);\n }\n return set;\n }, new Set<string>())\n .values()\n .toArray()\n .filter((ref) => {\n const itemTxHash = cache.resolve(ref, 'txHash') as TxHash;\n if (itemTxHash !== txHash) return false;\n\n // Verify chainId via spoke.chain.chainId if present\n const spokeRef = cache.resolve(ref, 'spoke') as string | null;\n if (spokeRef) {\n const chainRef = cache.resolve(spokeRef, 'chain') as\n | string\n | null;\n const itemChainId = chainRef\n ? (cache.resolve(chainRef, 'chainId') as number | undefined)\n : undefined;\n if (typeof itemChainId === 'number') {\n return itemChainId === chainId;\n }\n }\n return true;\n });\n\n if (matches.length === 0) return undefined;\n\n return {\n __typename: 'PaginatedActivitiesResult',\n items: matches,\n pageInfo: {\n __typename: 'PaginatedResultInfo',\n prev: null,\n next: null,\n },\n };\n },\n },\n },\n keys: {\n // Entitied with composite key\n Hub: (data: Hub) => data.id,\n HubAsset: (data: HubAsset) => data.id,\n Reserve: (data: Reserve) => data.id,\n ReserveInfo: (data: ReserveInfo) => data.id,\n Spoke: (data: Spoke) => data.id,\n\n // Entities with id field as key\n BorrowActivity: (data: BorrowActivity) => data.id,\n LiquidatedActivity: (data: LiquidatedActivity) => data.id,\n SupplyActivity: (data: SupplyActivity) => data.id,\n SwapByIntent: (data: SwapByIntent) => data.quote.quoteId,\n SwapByIntentWithApprovalRequired: (\n data: SwapByIntentWithApprovalRequired,\n ) => data.quote.quoteId,\n SwapByTransaction: (data: SwapByTransaction) => data.quote.quoteId,\n UserPosition: (data: UserPosition) => data.id,\n UpdatedDynamicConfigActivity: (data: UpdatedDynamicConfigActivity) =>\n data.id,\n UpdatedRiskPremiumActivity: (data: UpdatedRiskPremiumActivity) => data.id,\n UsingAsCollateralActivity: (data: UsingAsCollateralActivity) => data.id,\n WithdrawActivity: (data: WithdrawActivity) => data.id,\n RepayActivity: (data: RepayActivity) => data.id,\n TokenInfo: (data: TokenInfo) => data.id,\n\n // Entities with address field as key\n Erc20Token: (data: Erc20Token) => data.address,\n\n // Entities with other fields as key\n Chain: (data: Chain) => data.chainId.toString(),\n NativeToken: (data: NativeToken) => data.chain.chainId.toString(),\n\n // Entities without keys will be embedded directly on the parent entity\n PaginatedActivitiesResult: () => null,\n PaginatedResultInfo: () => null,\n PaginatedSpokePositionManagerResult: () => null,\n PaginatedSpokeUserPositionManagerResult: () => null,\n PaginatedUserSwapsResult: () => null,\n SpokePositionManger: () => null,\n SpokeUserPositionManager: () => null,\n SwapReceipt: () => null,\n SwapTransactionRequest: () => null,\n\n // Value objects and result types\n ApySample: () => null,\n Asset: () => null,\n AssetBorrowSample: () => null,\n AssetCategoryBorrowSample: () => null,\n AssetCategorySupplySample: () => null,\n AssetPriceSample: () => null,\n AssetSummary: () => null,\n AssetSupplySample: () => null,\n CancelSwapTypedData: () => null,\n CancelSwapTypeDefinition: () => null,\n DecimalNumber: () => null,\n DecimalNumberWithChange: () => null,\n DomainData: () => null,\n Erc20Amount: () => null,\n Erc20ApprovalRequired: () => null,\n ExchangeAmount: () => null,\n ExchangeAmountVariation: () => null,\n ExchangeAmountWithChange: () => null,\n ForkTopUpResponse: () => null,\n HealthFactorError: () => null,\n HealthFactorVariation: () => null,\n HealthFactorWithChange: () => null,\n HubAssetSettings: () => null,\n HubAssetSummary: () => null,\n HubAssetUserState: () => null,\n HubSummary: () => null,\n HubSummarySample: () => null,\n InsufficientBalanceError: () => null,\n NativeAmount: () => null,\n PercentNumber: () => null,\n PercentNumberVariation: () => null,\n PercentNumberWithChange: () => null,\n PermitMessageData: () => null,\n PermitTypedDataResponse: () => null,\n PreContractActionRequired: () => null,\n PrepareSwapCancelResult: () => null,\n PreviewUserPosition: () => null,\n ProtocolHistorySample: () => null,\n ReserveSettings: () => null,\n ReserveStatus: () => null,\n ReserveSummary: () => null,\n ReserveUserState: () => null,\n SwapApprovalRequired: () => null,\n SwapByIntentTypedData: () => null,\n SwapByIntentTypeDefinition: () => null,\n SwapCancelled: () => null,\n SwapExpired: () => null,\n SwapFulfilled: () => null,\n SwapOpen: () => null,\n SwapPendingSignature: () => null,\n SwapQuote: () => null,\n SwapQuoteCosts: () => null,\n TransactionRequest: () => null,\n TypeDefinition: () => null,\n TypeField: () => null,\n UserBalance: () => null,\n UserBorrowItem: () => null,\n UserRiskPremiumBreakdownItem: () => null,\n UserSummary: () => null,\n UserSummaryHistoryItem: () => null,\n UserSupplyItem: () => null,\n },\n});\n","import type { EnvironmentConfig } from '@aave/core';\n\n/**\n * The production environment configuration.\n */\nexport const production: EnvironmentConfig = {\n name: 'production',\n backend: 'https://api.v4.aave.com/graphql',\n indexingTimeout: 60_000,\n pollingInterval: 100,\n exchangeRateInterval: 10000,\n};\n\n/**\n * @internal\n */\nexport const staging: EnvironmentConfig = {\n name: 'staging',\n backend: 'https://api.v4.staging.aave.com/graphql',\n indexingTimeout: 60_000,\n pollingInterval: 500,\n exchangeRateInterval: 10000,\n};\n\n/**\n * @internal\n */\nexport const local: EnvironmentConfig = {\n name: 'local',\n backend: 'http://localhost:3007/graphql',\n indexingTimeout: 60_000,\n pollingInterval: 1000,\n exchangeRateInterval: 10000,\n};\n","import type { Context } from '@aave/core';\nimport type { TypedDocumentNode } from '@urql/core';\nimport type { EnvironmentConfig } from '../../core/src/types';\nimport { exchange } from './cache';\nimport { production } from './environments';\n\n/**\n * The client configuration.\n */\nexport type ClientConfig = {\n /**\n * @internal\n * @defaultValue `production`\n */\n environment?: EnvironmentConfig;\n /**\n * @internal\n */\n headers?: Record<string, string>;\n /**\n * Whether to enable caching.\n *\n * @defaultValue `true`\n */\n cache?: boolean;\n /**\n * Whether to enable debug mode.\n *\n * @defaultValue `false`\n */\n debug?: boolean;\n /**\n * The custom fragments to use.\n *\n * @experimental This is an experimental API and may be subject to breaking changes.\n */\n fragments?: TypedDocumentNode[];\n};\n\n/**\n * @internal\n */\nexport function configureContext({\n environment = production,\n headers,\n cache = true,\n debug = false,\n fragments = [],\n}: ClientConfig): Context {\n return {\n displayName: 'AaveClient',\n environment,\n headers,\n cache: cache ? exchange : null,\n debug,\n fragments,\n };\n}\n","import type {\n CancelError,\n SigningError,\n TransactionError,\n UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n CancelSwapTypedData,\n ERC20PermitSignature,\n ExecutionPlan,\n HasProcessedKnownTransactionRequest,\n InsufficientBalanceError,\n OperationType,\n PermitTypedDataResponse,\n SwapByIntentTypedData,\n} from '@aave/graphql';\nimport type { ResultAsync, TxHash } from '@aave/types';\n\n/**\n * @internal\n */\nexport type TransactionResult = {\n txHash: TxHash;\n operations: OperationType[] | null;\n};\n\n/**\n * @internal\n */\nexport function isHasProcessedKnownTransactionRequest(\n result: TransactionResult,\n): result is HasProcessedKnownTransactionRequest {\n return result.operations !== null && result.operations.length > 0;\n}\n\nexport type SendWithError =\n | CancelError\n | SigningError\n | TransactionError\n | ValidationError<InsufficientBalanceError>\n | UnexpectedError;\n\nexport type ExecutionPlanHandler<T extends ExecutionPlan = ExecutionPlan> = (\n result: T,\n) => ResultAsync<TransactionResult, SendWithError>;\n\nexport type ERC20PermitHandler = (\n result: PermitTypedDataResponse,\n) => ResultAsync<ERC20PermitSignature, SigningError>;\n\nexport type SwapSignatureHandler = (\n result: CancelSwapTypedData | SwapByIntentTypedData,\n) => ResultAsync<ERC20PermitSignature, SigningError>;\n","import {\n delay,\n GqlClient,\n type StandardData,\n TimeoutError,\n UnexpectedError,\n} from '@aave/core';\nimport type { HasProcessedKnownTransactionRequest } from '@aave/graphql';\nimport {\n type AnyVariables,\n invariant,\n ResultAsync,\n type TxHash,\n} from '@aave/types';\nimport type { TypedDocumentNode } from '@urql/core';\nimport { hasProcessedKnownTransaction } from './actions';\nimport { type ClientConfig, configureContext } from './config';\nimport {\n isHasProcessedKnownTransactionRequest,\n type TransactionResult,\n} from './types';\n\nexport class AaveClient extends GqlClient {\n /**\n * Create a new instance of the {@link AaveClient}.\n *\n * ```ts\n * const client = AaveClient.create({\n * environment: production,\n * });\n * ```\n *\n * @param options - The options to configure the client.\n * @returns The new instance of the client.\n */\n static create(options?: ClientConfig): AaveClient {\n return new AaveClient(configureContext(options ?? {}));\n }\n\n /**\n * Given the transaction hash of an Aave protocol transaction, wait for the transaction to be\n * processed by the Aave v4 API.\n *\n * Returns a {@link TimeoutError} if the transaction is not processed within the expected timeout period.\n *\n * @param result - The transaction execution result to wait for.\n * @returns The transaction hash or a TimeoutError\n */\n readonly waitForTransaction = (\n result: TransactionResult,\n ): ResultAsync<TxHash, TimeoutError | UnexpectedError> => {\n invariant(\n isHasProcessedKnownTransactionRequest(result),\n `Received a transaction result for an untracked operation. Make sure you're following the instructions in the docs.`,\n );\n\n return ResultAsync.fromPromise(\n this.pollTransactionStatus(result),\n (err) => {\n if (err instanceof TimeoutError || err instanceof UnexpectedError) {\n return err;\n }\n return UnexpectedError.from(err);\n },\n );\n };\n\n /**\n * @internal\n */\n async refreshQueryWhere<TValue, TVariables extends AnyVariables>(\n document: TypedDocumentNode<StandardData<TValue>, TVariables>,\n predicate: (\n variables: TVariables,\n data: TValue,\n ) => boolean | Promise<boolean>,\n ): Promise<void> {\n await this.refreshWhere(async (op) => {\n if (op.query === document) {\n const result = await this.query(document, op.variables as TVariables, {\n requestPolicy: 'cache-only',\n });\n\n if (result.isErr()) {\n return false;\n }\n\n return predicate(op.variables as TVariables, result.value as TValue);\n }\n return false;\n });\n }\n\n protected async pollTransactionStatus(\n request: HasProcessedKnownTransactionRequest,\n ): Promise<TxHash> {\n const startedAt = Date.now();\n\n while (Date.now() - startedAt < this.context.environment.indexingTimeout) {\n const processed = await hasProcessedKnownTransaction(this, request).match(\n (ok) => ok,\n (err) => {\n throw err;\n },\n );\n\n if (processed) {\n return request.txHash;\n }\n\n await delay(this.context.environment.pollingInterval);\n }\n throw TimeoutError.from(\n `Timeout waiting for transaction ${request.txHash} to be processed.`,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/cache.ts","../src/environments.ts","../src/config.ts","../src/types.ts","../src/AaveClient.ts"],"names":["transformToBigInt","parent","_args","_cache","info","transformToBigDecimal","BigDecimal","transformToNullableBigDecimal","value","transformToDate","transformToNullableDate","exchange","cacheExchange","introspectedSchema","_","request","isHubInputVariant","encodeHubId","isReserveInputVariant","encodeReserveId","chainId","address","decodeSpokeId","encodeUserPositionId","_parent","args","cache","isTxHashInputVariant","txHash","matches","f","set","pageRef","itemRefs","ref","spokeRef","chainRef","itemChainId","data","production","staging","local","configureContext","environment","headers","batch","debug","isHasProcessedKnownTransactionRequest","result","transactionReceipt","AaveClient","_AaveClient","GqlClient","options","invariant","ResultAsync","err","TimeoutError","UnexpectedError","startedAt","hasProcessedKnownTransaction","ok","delay"],"mappings":"olBA0DA,IAAMA,CAAAA,CAA8B,CAACC,CAAAA,CAAQC,CAAAA,CAAOC,CAAAA,CAAQC,CAAAA,GACnD,OAAOH,CAAAA,CAAOG,CAAAA,CAAK,SAAS,CAAW,CAAA,CAG1CC,EAAkC,CAACJ,CAAAA,CAAQC,CAAAA,CAAOC,CAAAA,CAAQC,IACvDE,UAAAA,CAAW,GAAA,CAAIL,EAAOG,CAAAA,CAAK,SAAS,CAAW,CAAA,CAGlDG,CAAAA,CAA0C,CAC9CN,CAAAA,CACAC,CAAAA,CACAC,EACAC,CAAAA,GACG,CACH,IAAMI,CAAAA,CAAQP,CAAAA,CAAOG,EAAK,SAAS,CAAA,CACnC,OAAII,CAAAA,EAAU,KACL,IAAA,CAEFH,CAAAA,CAAsBJ,EAAQC,CAAAA,CAAOC,CAAAA,CAAQC,CAAI,CAC1D,CAAA,CAEMK,CAAAA,CAA4B,CAACR,EAAQC,CAAAA,CAAOC,CAAAA,CAAQC,IACjD,IAAI,IAAA,CAAKH,EAAOG,CAAAA,CAAK,SAAS,CAAW,CAAA,CAG5CM,EAAoC,CAACT,CAAAA,CAAQC,EAAOC,CAAAA,CAAQC,CAAAA,GAAS,CACzE,IAAMI,CAAAA,CAAQP,EAAOG,CAAAA,CAAK,SAAS,EACnC,OAAII,CAAAA,EAAU,KAC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Q,WAAA,CAAY,iBAAiB,CAQxE,GAPkB,MAAMC,CAAAA,CAA6B,IAAA,CAAM7C,CAAO,CAAA,CAAE,MACjE8C,CAAAA,EAAOA,CAAAA,CACPL,GAAQ,CACP,MAAMA,CACR,CACF,CAAA,CAGE,OAAOP,CAAAA,CAAmBlC,EAAQ,MAAM,CAAA,CAG1C,MAAM+C,KAAAA,CAAM,IAAA,CAAK,QAAQ,WAAA,CAAY,eAAe,EACtD,CACA,MAAML,aAAa,IAAA,CACjB,CAAA,gCAAA,EAAmC1C,EAAQ,MAAM,CAAA,iBAAA,CACnD,CACF,CACF","file":"index.js","sourcesContent":["import {\n type ActivitiesQuery,\n type Asset,\n type BoostedRateId,\n type BorrowActivity,\n type BorrowPoints,\n type BorrowSwapActivity,\n type Chain,\n decodeSpokeId,\n type Erc20Token,\n encodeHubId,\n encodeReserveId,\n encodeUserPositionId,\n type Hub,\n type HubAsset,\n type HubQuery,\n isHubInputVariant,\n isReserveInputVariant,\n isTxHashInputVariant,\n type LiquidatedActivity,\n type MerklBorrowReward,\n type MerklGenericCriteria,\n type MerklSupplyReward,\n type NativeToken,\n type PointsGenericCriteria,\n type PointsProgram,\n type RepayActivity,\n type RepayWithSupplyActivity,\n type Reserve,\n type ReserveInfo,\n type ReserveQuery,\n type Spoke,\n type StableVault,\n type StableVaultUserPosition,\n type SupplyActivity,\n type SupplyPoints,\n type SupplySwapActivity,\n type TokenInfo,\n type TokenMovementRecord,\n type TokenSwapActivity,\n type UpdatedDynamicConfigActivity,\n type UpdatedRiskPremiumActivity,\n type UserMerklClaimableReward,\n type UserPosition,\n type UserPositionQuery,\n type UsingAsCollateralActivity,\n type VariablesOf,\n type WithdrawActivity,\n type WithdrawSwapActivity,\n} from '@aave/graphql';\nimport introspectedSchema from '@aave/graphql/schema';\nimport { BigDecimal, type TxHash } from '@aave/types';\nimport {\n cacheExchange,\n type Resolver,\n type Scalar,\n} from '@urql/exchange-graphcache';\n\nconst transformToBigInt: Resolver = (parent, _args, _cache, info) => {\n return BigInt(parent[info.fieldName] as string) as unknown as Scalar;\n};\n\nconst transformToBigDecimal: Resolver = (parent, _args, _cache, info) => {\n return BigDecimal.new(parent[info.fieldName] as string);\n};\n\nconst transformToNullableBigDecimal: Resolver = (\n parent,\n _args,\n _cache,\n info,\n) => {\n const value = parent[info.fieldName];\n if (value === null || value === undefined) {\n return null;\n }\n return transformToBigDecimal(parent, _args, _cache, info);\n};\n\nconst transformToDate: Resolver = (parent, _args, _cache, info) => {\n return new Date(parent[info.fieldName] as string);\n};\n\nconst transformToNullableDate: Resolver = (parent, _args, _cache, info) => {\n const value = parent[info.fieldName];\n if (value === null || value === undefined) {\n return null;\n }\n return transformToDate(parent, _args, _cache, info);\n};\n\nexport const exchange = cacheExchange({\n schema: introspectedSchema,\n resolvers: {\n PercentNumber: {\n onChainValue: transformToBigInt,\n value: transformToBigDecimal,\n normalized: transformToBigDecimal,\n },\n DecimalNumber: {\n onChainValue: transformToBigInt,\n value: transformToBigDecimal,\n },\n ExchangeAmount: {\n value: transformToBigDecimal,\n },\n AssetPriceSample: {\n price: transformToBigDecimal,\n date: transformToDate,\n },\n PermitTypedData: {\n signedAmount: transformToBigDecimal,\n },\n HealthFactorError: {\n current: transformToNullableBigDecimal,\n after: transformToNullableBigDecimal,\n },\n HealthFactorVariation: {\n current: transformToNullableBigDecimal,\n after: transformToNullableBigDecimal,\n },\n HealthFactorWithChange: {\n current: transformToNullableBigDecimal,\n },\n UserSummary: {\n lowestHealthFactor: transformToNullableBigDecimal,\n },\n UserSummaryHistoryItem: {\n healthFactor: transformToNullableBigDecimal,\n date: transformToDate,\n },\n TransactionRequest: {\n value: transformToBigInt,\n },\n ApySample: {\n date: transformToDate,\n },\n AssetBorrowSample: {\n date: transformToDate,\n },\n AssetSupplySample: {\n date: transformToDate,\n },\n HubSummarySample: {\n date: transformToDate,\n },\n BorrowPointsReward: {\n startDate: transformToDate,\n endDate: transformToNullableDate,\n },\n PreviewBorrowPointsReward: {\n startDate: transformToDate,\n endDate: transformToNullableDate,\n },\n PreviewMerklBorrowReward: {\n startDate: transformToDate,\n endDate: transformToDate,\n },\n PreviewMerklSupplyReward: {\n startDate: transformToDate,\n endDate: transformToDate,\n },\n PreviewSupplyPointsReward: {\n startDate: transformToDate,\n endDate: transformToNullableDate,\n },\n SupplyPointsReward: {\n startDate: transformToDate,\n endDate: transformToNullableDate,\n },\n ProtocolHistorySample: {\n date: transformToDate,\n },\n BorrowActivity: {\n timestamp: transformToDate,\n },\n LiquidatedActivity: {\n timestamp: transformToDate,\n },\n MerklBorrowReward: {\n startDate: transformToDate,\n endDate: transformToDate,\n },\n MerklSupplyReward: {\n startDate: transformToDate,\n endDate: transformToDate,\n },\n RepayActivity: {\n timestamp: transformToDate,\n },\n SupplyActivity: {\n timestamp: transformToDate,\n },\n WithdrawActivity: {\n timestamp: transformToDate,\n },\n UsingAsCollateralActivity: {\n timestamp: transformToDate,\n },\n UpdatedDynamicConfigActivity: {\n timestamp: transformToDate,\n },\n UpdatedRiskPremiumActivity: {\n timestamp: transformToDate,\n },\n TokenSwapActivity: {\n timestamp: transformToDate,\n },\n SupplySwapActivity: {\n timestamp: transformToDate,\n },\n BorrowSwapActivity: {\n timestamp: transformToDate,\n },\n RepayWithSupplyActivity: {\n timestamp: transformToDate,\n },\n WithdrawSwapActivity: {\n timestamp: transformToDate,\n },\n UserMerklClaimableReward: {\n startDate: transformToDate,\n endDate: transformToDate,\n claimUntil: transformToDate,\n },\n UserPosition: {\n createdAt: transformToDate,\n },\n UserBorrowItem: {\n createdAt: transformToNullableDate,\n },\n UserSupplyItem: {\n createdAt: transformToNullableDate,\n },\n SpokeUserPositionManager: {\n approvedOn: transformToDate,\n },\n SwapCancelled: {\n createdAt: transformToDate,\n cancelledAt: transformToNullableDate,\n },\n SwapCancelledResult: {\n createdAt: transformToDate,\n cancelledAt: transformToNullableDate,\n },\n SwapExpired: {\n createdAt: transformToDate,\n expiredAt: transformToDate,\n },\n SwapFulfilled: {\n createdAt: transformToDate,\n fulfilledAt: transformToDate,\n },\n SwapOpen: {\n createdAt: transformToDate,\n deadline: transformToDate,\n },\n SwapPendingSignature: {\n createdAt: transformToDate,\n deadline: transformToDate,\n },\n SwapReceipt: {\n createdAt: transformToDate,\n },\n StableVaultSummary: {\n shares: transformToBigInt,\n totalDeposits: transformToBigDecimal,\n userCount: transformToBigInt,\n },\n StableVaultWithdrawClaim: {\n executableAfter: transformToDate,\n },\n TokenMovementRecord: {\n timestamp: transformToDate,\n },\n StableVaultPendingAvailability: {\n executableAfter: transformToDate,\n },\n Query: {\n hub: (_, { request }: VariablesOf<typeof HubQuery>) => {\n if (isHubInputVariant(request.query)) {\n return {\n __typename: 'Hub',\n id: encodeHubId(request.query.hubInput),\n };\n }\n return {\n __typename: 'Hub',\n id: request.query.hubId,\n };\n },\n\n reserve: (_, { request }: VariablesOf<typeof ReserveQuery>) => {\n if (isReserveInputVariant(request.query)) {\n return {\n __typename: 'Reserve',\n id: encodeReserveId(request.query.reserveInput),\n };\n }\n return {\n __typename: 'Reserve',\n id: request.query.reserveId,\n };\n },\n\n userPosition: (_, { request }: VariablesOf<typeof UserPositionQuery>) => {\n if ('userSpoke' in request && request.userSpoke) {\n const { chainId, address } = decodeSpokeId(request.userSpoke.spoke);\n return {\n __typename: 'UserPosition',\n id: encodeUserPositionId({\n chainId,\n spoke: address,\n user: request.userSpoke.user,\n }),\n };\n }\n if ('id' in request && request.id) {\n return {\n __typename: 'UserPosition',\n id: request.id,\n };\n }\n return undefined;\n },\n\n activities: (\n _parent,\n args: VariablesOf<typeof ActivitiesQuery>,\n cache,\n ) => {\n // Bail out if not a txHash filter lookup\n if (!isTxHashInputVariant(args.request.query)) {\n return cache.resolve('Query', 'activities', args);\n }\n\n const { txHash, chainId } = args.request.query.txHash;\n\n // Collect all cached activities matching txHash\n const matches = cache\n .inspectFields('Query')\n .filter((f) => f.fieldName === 'activities')\n .reduce((set, f) => {\n const pageRef = cache.resolve('Query', f.fieldKey) as string | null;\n if (!pageRef) return set;\n\n const itemRefs = cache.resolve(pageRef, 'items') as string[] | null;\n if (!itemRefs) return set;\n\n for (const ref of itemRefs) {\n set.add(ref);\n }\n return set;\n }, new Set<string>())\n .values()\n .toArray()\n .filter((ref) => {\n const itemTxHash = cache.resolve(ref, 'txHash') as TxHash;\n if (itemTxHash !== txHash) return false;\n\n // Verify chainId via spoke.chain.chainId if present\n const spokeRef = cache.resolve(ref, 'spoke') as string | null;\n if (spokeRef) {\n const chainRef = cache.resolve(spokeRef, 'chain') as\n | string\n | null;\n const itemChainId = chainRef\n ? (cache.resolve(chainRef, 'chainId') as number | undefined)\n : undefined;\n if (typeof itemChainId === 'number') {\n return itemChainId === chainId;\n }\n }\n return true;\n });\n\n if (matches.length === 0) return undefined;\n\n return {\n __typename: 'PaginatedActivitiesResult',\n items: matches,\n pageInfo: {\n __typename: 'PaginatedResultInfo',\n prev: null,\n next: null,\n },\n };\n },\n },\n },\n keys: {\n // Entities with id field as key\n Asset: (data: Asset) => data.id,\n BorrowActivity: (data: BorrowActivity) => data.id,\n BorrowPointsReward: (data: BorrowPoints) => data.id,\n BorrowSwapActivity: (data: BorrowSwapActivity) => data.id,\n // URQL SystemFields & DataFields doesn't play ball with the bigint scalar (BoostedRate.userCounts field),\n // hence the type assertion to BoostedRateId which is a string alias of the id\n BoostedRate: (data) => data.id as BoostedRateId,\n Hub: (data: Hub) => data.id,\n HubAsset: (data: HubAsset) => data.id,\n LiquidatedActivity: (data: LiquidatedActivity) => data.id,\n MerklBorrowReward: (data: MerklBorrowReward) => data.id,\n MerklGenericCriteria: (data: MerklGenericCriteria) => data.id,\n MerklSupplyReward: (data: MerklSupplyReward) => data.id,\n PointsGenericCriteria: (data: PointsGenericCriteria) => data.id,\n PointsProgram: (data: PointsProgram) => data.id,\n RepayActivity: (data: RepayActivity) => data.id,\n RepayWithSupplyActivity: (data: RepayWithSupplyActivity) => data.id,\n Reserve: (data: Reserve) => data.id,\n ReserveInfo: (data: ReserveInfo) => data.id,\n Spoke: (data: Spoke) => data.id,\n StableVault: (data: StableVault) => data.id,\n StableVaultUserPosition: (data: StableVaultUserPosition) => data.id,\n SupplyActivity: (data: SupplyActivity) => data.id,\n SupplyPointsReward: (data: SupplyPoints) => data.id,\n SupplySwapActivity: (data: SupplySwapActivity) => data.id,\n TokenInfo: (data: TokenInfo) => data.id,\n TokenMovementRecord: (data: TokenMovementRecord) => data.id,\n TokenSwapActivity: (data: TokenSwapActivity) => data.id,\n UpdatedDynamicConfigActivity: (data: UpdatedDynamicConfigActivity) =>\n data.id,\n UpdatedRiskPremiumActivity: (data: UpdatedRiskPremiumActivity) => data.id,\n UserMerklClaimableReward: (data: UserMerklClaimableReward) => data.id,\n UserPosition: (data: UserPosition) => data.id,\n UsingAsCollateralActivity: (data: UsingAsCollateralActivity) => data.id,\n WithdrawActivity: (data: WithdrawActivity) => data.id,\n WithdrawSwapActivity: (data: WithdrawSwapActivity) => data.id,\n\n // Entities with address field as key\n Erc20Token: (data: Erc20Token) => data.address,\n\n // Entities with other fields as key\n Chain: (data: Chain) => data.chainId.toString(),\n NativeToken: (data: NativeToken) => data.chain.chainId.toString(),\n\n // Value objects and result types\n ApySample: () => null,\n AssetAmountWithChange: () => null,\n AssetBorrowSample: () => null,\n AssetPriceSample: () => null,\n AssetSampleBreakdown: () => null,\n AssetSummary: () => null,\n AssetSupplySample: () => null,\n BorrowSwap: () => null,\n BorrowSwapQuoteResult: () => null,\n CollateralFactorVariation: () => null,\n DecimalNumber: () => null,\n DecimalNumberWithChange: () => null,\n DomainData: () => null,\n Erc20Amount: () => null,\n Erc20Approval: () => null,\n Erc20ApprovalRequired: () => null,\n ExchangeAmount: () => null,\n ExchangeAmountVariation: () => null,\n ExchangeAmountWithChange: () => null,\n ForkTopUpResponse: () => null,\n HealthFactorError: () => null,\n HealthFactorVariation: () => null,\n HealthFactorWithChange: () => null,\n HubAssetInterestRateModelPoint: () => null,\n HubAssetInterestRateModelResult: () => null,\n HubAssetSettings: () => null,\n HubAssetSummary: () => null,\n HubAssetUserState: () => null,\n HubSummary: () => null,\n HubSummarySample: () => null,\n InsufficientBalanceError: () => null,\n InsufficientLiquidityError: () => null,\n LiquidationFeeVariation: () => null,\n MaxLiquidationBonusVariation: () => null,\n NativeAmount: () => null,\n PaginatedActivitiesResult: () => null,\n PaginatedResultInfo: () => null,\n PaginatedSpokePositionManagerResult: () => null,\n PaginatedSpokeUserPositionManagerResult: () => null,\n PaginatedStableVaultMovementsResult: () => null,\n PaginatedStableVaultRateUsersResult: () => null,\n PaginatedUserSwapsResult: () => null,\n PercentNumber: () => null,\n PercentNumberChangeSnapshot: () => null,\n PercentNumberVariation: () => null,\n PercentNumberWithChange: () => null,\n PermitTypedData: () => null,\n PositionAmount: () => null,\n PositionSwapAdapterContractApproval: () => null,\n PositionSwapByIntentApprovalsRequired: () => null,\n PositionSwapPositionManagerApproval: () => null,\n PreContractActionRequired: () => null,\n PrepareSwapCancelResult: () => null,\n PrepareSwapOrder: () => null,\n PreviewBorrowPointsReward: () => null,\n PreviewMerklBorrowReward: () => null,\n PreviewMerklSupplyReward: () => null,\n PreviewReserveRates: () => null,\n PreviewRewardOutcome: () => null,\n PreviewSupplyPointsReward: () => null,\n PreviewUserPosition: () => null,\n ProtocolHistorySample: () => null,\n RepayWithSupply: () => null,\n RepayWithSupplyQuoteResult: () => null,\n ReserveSettings: () => null,\n ReserveStatus: () => null,\n ReserveSummary: () => null,\n ReserveUserState: () => null,\n SpokePositionManager: () => null,\n SpokeUserPositionManager: () => null,\n StableVaultPendingAvailability: () => null,\n StableVaultRates: () => null,\n StableVaultSummary: () => null,\n StableVaultWithdrawClaim: () => null,\n SupplySwap: () => null,\n SupplySwapQuoteResult: () => null,\n SwapByIntent: () => null,\n SwapByIntentWithApprovalRequired: () => null,\n SwapByTransaction: () => null,\n SwapCancelled: () => null,\n SwapCancelledResult: () => null,\n SwapExpired: () => null,\n SwapFulfilled: () => null,\n SwapOpen: () => null,\n SwapPendingSignature: () => null,\n SwapQuote: () => null,\n SwapQuoteCosts: () => null,\n SwapReceipt: () => null,\n SwapTransactionRequest: () => null,\n SwapTypedData: () => null,\n TokenMovementAllocate: () => null,\n TokenMovementBridgeIn: () => null,\n TokenMovementBridgeOut: () => null,\n TokenMovementDeallocate: () => null,\n TokenMovementRebalance: () => null,\n TokenMovementSwap: () => null,\n TokenSwap: () => null,\n TokenSwapQuoteResult: () => null,\n TransactionRequest: () => null,\n UserBalance: () => null,\n UserBorrowItem: () => null,\n UserPositionRiskPremium: () => null,\n UserRiskPremiumBreakdownItem: () => null,\n UserSummary: () => null,\n UserSummaryHistoryItem: () => null,\n UserSupplyItem: () => null,\n WithdrawSwap: () => null,\n WithdrawSwapQuoteResult: () => null,\n },\n});\n","import type { EnvironmentConfig } from '@aave/core';\n\n/**\n * The production environment configuration.\n */\nexport const production: EnvironmentConfig = {\n name: 'production',\n backend: 'https://api.aave.com/graphql',\n indexingTimeout: 60_000,\n pollingInterval: 100,\n exchangeRateInterval: 10_000,\n swapQuoteInterval: 30_000,\n swapStatusInterval: 5_000,\n};\n\n/**\n * @internal\n */\nexport const staging: EnvironmentConfig = {\n name: 'staging',\n backend: 'https://api.staging.aave.com/graphql',\n indexingTimeout: 60_000,\n pollingInterval: 500,\n exchangeRateInterval: 10_000,\n swapQuoteInterval: 30_000,\n swapStatusInterval: 5_000,\n};\n\n/**\n * @internal\n */\nexport const local: EnvironmentConfig = {\n name: 'local',\n backend: 'http://localhost:3007/graphql',\n indexingTimeout: 60_000,\n pollingInterval: 1000,\n exchangeRateInterval: 10_000,\n swapQuoteInterval: 30_000,\n swapStatusInterval: 5_000,\n};\n","import type { Context } from '@aave/core';\nimport type { EnvironmentConfig } from '../../core/src/types';\nimport { exchange } from './cache';\nimport { production } from './environments';\n\n/**\n * The client configuration.\n */\nexport type ClientConfig = {\n /**\n * @internal\n * @defaultValue `production`\n */\n environment?: EnvironmentConfig;\n /**\n * @internal\n */\n headers?: Record<string, string>;\n /**\n * Whether to enable caching.\n *\n * @defaultValue `true`\n */\n cache?: boolean;\n /**\n * Whether to enable query batching.\n *\n * @defaultValue `true`\n */\n batch?: boolean;\n /**\n * Whether to enable debug mode.\n *\n * @defaultValue `false`\n */\n debug?: boolean;\n};\n\n/**\n * @internal\n */\nexport function configureContext({\n environment = production,\n headers,\n cache = true,\n batch = true,\n debug = false,\n}: ClientConfig): Context {\n return {\n displayName: 'AaveClient',\n environment,\n headers,\n cache: cache ? exchange : null,\n batch,\n debug,\n };\n}\n","import type {\n CancelError,\n SigningError,\n TransactionError,\n UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n ExecutionPlan,\n HasProcessedKnownTransactionRequest,\n InsufficientBalanceError,\n OperationType,\n PermitTypedData,\n SwapTypedData,\n} from '@aave/graphql';\nimport type { ResultAsync, Signature, TxHash } from '@aave/types';\n\n/**\n * @internal\n */\nexport type TransactionResult = {\n txHash: TxHash;\n operations: OperationType[] | null;\n};\n\n/**\n * @internal\n */\nexport function isHasProcessedKnownTransactionRequest(\n result: TransactionResult,\n): result is HasProcessedKnownTransactionRequest {\n return result.operations !== null && result.operations.length > 0;\n}\n\nexport type TransactionReceipt = {\n __typename: 'TransactionReceipt';\n txHash: TxHash;\n};\n\n/**\n * @internal\n */\nexport function transactionReceipt(txHash: TxHash): TransactionReceipt {\n return { __typename: 'TransactionReceipt', txHash };\n}\n\nexport type SendWithError =\n | CancelError\n | SigningError\n | TransactionError\n | ValidationError<InsufficientBalanceError>\n | UnexpectedError;\n\nexport type ExecutionPlanHandler<T extends ExecutionPlan = ExecutionPlan> = (\n result: T,\n) => ResultAsync<TransactionResult, SendWithError>;\n\nexport type SignTypedDataError = CancelError | SigningError;\n\n/**\n * Union type for all EIP-712 typed data structures used in the SDK.\n */\nexport type TypedData = PermitTypedData | SwapTypedData;\n\nexport type TypedDataHandler = (\n data: TypedData,\n) => ResultAsync<Signature, SignTypedDataError>;\n","import { delay, GqlClient, TimeoutError, UnexpectedError } from '@aave/core';\nimport type { HasProcessedKnownTransactionRequest } from '@aave/graphql';\nimport { invariant, ResultAsync } from '@aave/types';\nimport { hasProcessedKnownTransaction } from './actions';\nimport { type ClientConfig, configureContext } from './config';\nimport {\n isHasProcessedKnownTransactionRequest,\n type TransactionReceipt,\n type TransactionResult,\n transactionReceipt,\n} from './types';\n\nexport class AaveClient extends GqlClient {\n /**\n * Create a new instance of the {@link AaveClient}.\n *\n * ```ts\n * const client = AaveClient.create({\n * environment: production,\n * });\n * ```\n *\n * @param options - The options to configure the client.\n * @returns The new instance of the client.\n */\n static create(options?: ClientConfig): AaveClient {\n return new AaveClient(configureContext(options ?? {}));\n }\n\n /**\n * Given the transaction hash of an Aave protocol transaction, wait for the transaction to be\n * processed by the Aave v4 API.\n *\n * Returns a {@link TimeoutError} if the transaction is not processed within the expected timeout period.\n *\n * @param result - The transaction execution result to wait for.\n * @returns The {@link TransactionReceipt} or a error\n */\n readonly waitForTransaction = (\n result: TransactionResult,\n ): ResultAsync<TransactionReceipt, TimeoutError | UnexpectedError> => {\n invariant(\n isHasProcessedKnownTransactionRequest(result),\n 'AaveClient.waitForTransaction called with an non-tracked operation. See the documentation for correct tracking setup.',\n );\n\n return ResultAsync.fromPromise(\n this.pollTransactionStatus(result),\n (err) => {\n if (err instanceof TimeoutError || err instanceof UnexpectedError) {\n return err;\n }\n return UnexpectedError.from(err);\n },\n );\n };\n\n protected async pollTransactionStatus(\n request: HasProcessedKnownTransactionRequest,\n ): Promise<TransactionReceipt> {\n const startedAt = Date.now();\n\n while (Date.now() - startedAt < this.context.environment.indexingTimeout) {\n const processed = await hasProcessedKnownTransaction(this, request).match(\n (ok) => ok,\n (err) => {\n throw err;\n },\n );\n\n if (processed) {\n return transactionReceipt(request.txHash);\n }\n\n await delay(this.context.environment.pollingInterval);\n }\n throw TimeoutError.from(\n `Timeout waiting for transaction ${request.txHash} to be processed.`,\n );\n }\n}\n"]}
|
package/dist/privy.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')
|
|
2
|
-
exports.sendWith=rn;exports.signERC20PermitWith=on;exports.signSwapTypedDataWith=sn;//# sourceMappingURL=privy.cjs.map
|
|
1
|
+
'use strict';var core=require('@aave/core'),types=require('@aave/types'),viem=require('viem'),actions=require('viem/actions'),D=require('viem/chains');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var D__namespace=/*#__PURE__*/_interopNamespace(D);function g(n){return typeof n=="object"&&n!==null&&"approvals"in n&&Array.isArray(n.approvals)}function u(n){return g(n)&&types.isOneEntryArray(n.approvals)&&!!n.approvals[0].bySignature}function l(n,r,e){let t=n?.blockExplorers?.default?.url,i=t&&new URL(`/tx/${r}`,t).toString();return core.TransactionError.new({txHash:r,request:e,link:i})}var H=Object.values(D__namespace);async function S(n,r,e){let{hash:t}=await n.walletApi.ethereum.sendTransaction({walletId:e,caip2:`eip155:${r.chainId}`,transaction:{from:r.from,to:r.to,value:`0x${BigInt(r.value).toString(16)}`,chainId:r.chainId,data:r.data}});return types.txHash(t)}function o(n,r,e){let t=viem.extractChain({chains:H,id:r.chainId}),i=viem.createPublicClient({chain:t,transport:viem.http()});return types.ResultAsync.fromPromise(S(n,r,e),a=>core.SigningError.from(a)).andThen(a=>types.ResultAsync.fromPromise(actions.waitForTransactionReceipt(i,{hash:a,pollingInterval:100,retryCount:20,retryDelay:50}),s=>core.UnexpectedError.from(s))).andThen(a=>{let s=types.txHash(a.transactionHash);return a.status==="reverted"?types.errAsync(l(t,s,r)):types.okAsync({txHash:s,operations:r.operations})})}function m(n,r,e){switch(e.__typename){case "TransactionRequest":return o(n,e,r);case "Erc20ApprovalRequired":return e.approvals.reduce((t,i)=>t.andThen(()=>o(n,i.byTransaction,r)),types.okAsync(void 0)).andThen(()=>o(n,e.originalTransaction,r));case "PreContractActionRequired":return o(n,e.transaction,r).andThen(()=>o(n,e.originalTransaction,r));case "InsufficientBalanceError":return types.errAsync(core.ValidationError.fromGqlNode(e))}}function mn(n,r,e){return e?m(n,r,e):m.bind(null,n,r)}function Tn(n,r,e){return e().andThen(t=>{if(u(t)){let i=t.approvals[0].bySignature;return b(n,r,i).map(a=>({deadline:i.message.deadline,value:a})).andThen(a=>e(a))}return types.okAsync(t)})}function T(n,r,e){return types.ResultAsync.fromPromise(n.walletApi.ethereum.signTypedData({walletId:r,typedData:{domain:e.domain,types:e.types,message:e.message,primaryType:e.primaryType}}),t=>core.SigningError.from(t)).map(t=>t.signature)}function b(n,r,e){return e===void 0?t=>T(n,r,t).map(types.signatureFrom):T(n,r,e).map(types.signatureFrom)}exports.permitWith=Tn;exports.sendWith=mn;exports.signTypedDataWith=b;//# sourceMappingURL=privy.cjs.map
|
|
3
2
|
//# sourceMappingURL=privy.cjs.map
|
package/dist/privy.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/viem.ts","../src/privy.ts"],"names":["devnetChain","defineChain","supportedChains","chainId","transactionError","chain","txHash","request","baseUrl","link","TransactionError","sendTransaction","privy","walletId","hash","sendTransactionAndWait","publicClient","createPublicClient","http","ResultAsync","err","SigningError","waitForTransactionReceipt","receipt","errAsync","okAsync","executePlan","result","ValidationError","sendWith","signERC20Permit","response","signatureFrom","signERC20PermitWith","signSwapTypedData","message","signSwapTypedDataWith"],"mappings":"qJAwEA,IAAMA,CAAAA,CAAyBC,gBAAAA,CAAY,CACzC,EAAA,CAAI,MAAA,CAAO,QAAA,CAAS,WAAA,CAA2C,EAAE,CAAA,CACjE,IAAA,CAAM,SACN,OAAA,CAAS,eAAA,CACT,cAAA,CAAgB,CAAE,IAAA,CAAM,OAAA,CAAS,MAAA,CAAQ,KAAA,CAAO,QAAA,CAAU,EAAG,CAAA,CAC7D,OAAA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AClC,IAAMQ,CAAAA,CAAU,IAAA,CAAK,MAAMR,CAAAA,CAAO,OAAO,CAAA,CACzC,OAAOR,iBAAAA,CAAY,WAAA,CACjBP,CAAAA,CAAM,SAAA,CAAU,QAAA,CAAS,aAAA,CAAc,CACrC,QAAA,CAAAC,CAAAA,CACA,SAAA,CAAW,CACT,MAAA,CAAQc,CAAAA,CAAO,MAAA,CACf,KAAA,CAAOA,CAAAA,CAAO,KAAA,CACd,OAAA,CAAAQ,CAAAA,CACA,WAAA,CAAaR,CAAAA,CAAO,WACtB,CACF,CAAC,CAAA,CACAP,CAAAA,EAAQC,iBAAAA,CAAa,IAAA,CAAKD,CAAG,CAChC,CAAA,CAAE,GAAA,CAAKW,CAAAA,GAAc,CACnB,QAAA,CAAUI,CAAAA,CAAQ,QAAA,CAClB,KAAA,CAAOH,mBAAAA,CAAcD,CAAAA,CAAS,SAAS,CACzC,CAAA,CAAE,CACJ,CAmBO,SAASK,EAAAA,CACdxB,CAAAA,CACAC,CAAAA,CACAc,CAAAA,CACyD,CACzD,OAAOA,CAAAA,CACHO,CAAAA,CAAkBtB,CAAAA,CAAOC,CAAAA,CAAUc,CAAM,CAAA,CACzCO,CAAAA,CAAkB,IAAA,CAAK,IAAA,CAAMtB,CAAAA,CAAOC,CAAQ,CAClD","file":"privy.cjs","sourcesContent":["import {\n CancelError,\n SigningError,\n TransactionError,\n 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 isObject,\n okAsync,\n ResultAsync,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport {\n type Account,\n defineChain,\n type ProviderRpcError,\n type RpcError,\n SwitchChainError,\n TransactionExecutionError,\n type Transport,\n type TypedData,\n type TypedDataDomain,\n UserRejectedRequestError,\n type Chain as ViemChain,\n type WalletClient,\n} from 'viem';\nimport {\n estimateGas as estimateGasWithViem,\n sendTransaction as sendTransactionWithViem,\n signTypedData,\n waitForTransactionReceipt,\n} from 'viem/actions';\nimport { mainnet, sepolia } from 'viem/chains';\nimport type { AaveClient } from './AaveClient';\nimport { chain as fetchChain } from './actions';\nimport type {\n ERC20PermitHandler,\n ExecutionPlanHandler,\n SwapSignatureHandler,\n TransactionResult,\n} from './types';\n\nfunction isRpcError(err: unknown): err is RpcError {\n return isObject(err) && 'code' in err && 'message' in err;\n}\n\nfunction isProviderRpcError(\n err: unknown,\n): err is ProviderRpcError<{ originalError?: { code: number } }> {\n return isObject(err) &&\n 'name' in err &&\n 'message' in err &&\n 'originalError' in err\n ? isRpcError(err.originalError) && 'code' in err.originalError\n : true;\n}\n\nconst devnetChain: ViemChain = defineChain({\n id: Number.parseInt(import.meta.env.ETHEREUM_TENDERLY_FORK_ID, 10),\n name: 'Devnet',\n network: 'ethereum-fork',\n nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },\n rpcUrls: {\n default: { http: [import.meta.env.ETHEREUM_TENDERLY_PUBLIC_RPC] },\n },\n blockExplorers: {\n default: {\n name: 'Devnet Explorer',\n url: import.meta.env.ETHEREUM_TENDERLY_BLOCKEXPLORER,\n },\n },\n});\n\n/**\n * @internal\n * @deprecated\n */\nexport const supportedChains: Record<ChainId, ViemChain> = {\n [chainId(devnetChain.id)]: devnetChain,\n};\n\n/**\n * @internal\n */\nexport function toViemChain(chain: Chain): ViemChain {\n // known chains\n switch (chain.chainId) {\n case chainId(mainnet.id):\n return mainnet;\n\n case chainId(sepolia.id):\n return sepolia;\n }\n\n // most likely a tenderly fork\n return defineChain({\n id: chain.chainId,\n name: chain.name,\n nativeCurrency: {\n name: chain.nativeInfo.name,\n symbol: chain.nativeInfo.symbol,\n decimals: chain.nativeInfo.decimals,\n },\n rpcUrls: { default: { http: [chain.rpcUrl] } },\n blockExplorers: {\n default: {\n name: `${chain.name} Explorer`,\n url: chain.explorerUrl,\n },\n },\n });\n}\n\n/**\n * @internal\n */\nexport function viemChainsFrom(chains: Chain[]): ViemChain[] {\n return chains.map(toViemChain);\n}\n\n/**\n * @internal\n */\nexport function ensureChain(\n aaveClient: AaveClient,\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<void, CancelError | SigningError | UnexpectedError> {\n return ResultAsync.fromPromise(walletClient.getChainId(), (err) =>\n SigningError.from(err),\n ).andThen((chainId) => {\n if (chainId === request.chainId) {\n return okAsync();\n }\n\n return fetchChain(\n aaveClient,\n { chainId: request.chainId },\n { batch: false },\n ).andThen((chain) => {\n invariant(chain, `Chain ${request.chainId} is not supported`);\n\n return ResultAsync.fromPromise(\n walletClient.switchChain({ id: request.chainId }),\n (err) => SigningError.from(err),\n ).orElse((err) => {\n const code = isRpcError(err.cause)\n ? err.cause.code\n : // Unwrapping for MetaMask Mobile\n // https://github.com/MetaMask/metamask-mobile/issues/2944#issuecomment-976988719\n isProviderRpcError(err.cause)\n ? err.cause.data?.originalError?.code\n : undefined;\n\n if (code === SwitchChainError.code) {\n return ResultAsync.fromPromise(\n walletClient.addChain({ chain: toViemChain(chain) }),\n (err) => {\n if (\n isRpcError(err) &&\n err.code === UserRejectedRequestError.code\n ) {\n return CancelError.from(err);\n }\n return SigningError.from(err);\n },\n );\n }\n\n return err.asResultAsync();\n });\n });\n });\n}\n\nfunction estimateGas(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<bigint, SigningError> {\n return ResultAsync.fromPromise(\n estimateGasWithViem(walletClient, {\n account: walletClient.account,\n data: request.data,\n to: request.to,\n value: BigInt(request.value),\n }),\n (err) => SigningError.from(err),\n ).map((gas) => (gas * 115n) / 100n); // 15% buffer\n}\n\nfunction sendEip1559Transaction(\n walletClient: WalletClient<Transport, ViemChain, Account>,\n request: TransactionRequest,\n): ResultAsync<TxHash, CancelError | SigningError> {\n return estimateGas(walletClient, request)\n .andThen((gas) =>\n ResultAsync.fromPromise(\n sendTransactionWithViem(walletClient, {\n account: walletClient.account,\n data: request.data,\n to: request.to,\n value: BigInt(request.value),\n chain: walletClient.chain,\n gas,\n }),\n (err) => {\n if (err instanceof TransactionExecutionError) {\n const rejected = err.walk(\n (err) => err instanceof UserRejectedRequestError,\n );\n\n if (rejected) {\n return CancelError.from(rejected);\n }\n }\n return SigningError.from(err);\n },\n ),\n )\n .map(txHash);\n}\n\nfunction isWalletClientWithAccount(\n walletClient: WalletClient,\n): walletClient is WalletClient<Transport, ViemChain, Account> {\n return walletClient.account !== undefined;\n}\n\n/**\n * @internal\n */\nexport function sendTransaction(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<TxHash, CancelError | SigningError> {\n invariant(\n isWalletClientWithAccount(walletClient),\n 'Wallet client with account is required',\n );\n\n return sendEip1559Transaction(walletClient, request);\n}\n\n/**\n * @internal\n */\nexport function transactionError(\n chain: ViemChain | undefined,\n txHash: TxHash,\n request: TransactionRequest,\n): TransactionError {\n const baseUrl = chain?.blockExplorers?.default?.url;\n const link = baseUrl && new URL(`/tx/${txHash}`, baseUrl).toString();\n\n return TransactionError.new({ txHash, request, link });\n}\n\n/**\n * @internal\n */\nexport function waitForTransactionResult(\n walletClient: WalletClient,\n request: TransactionRequest,\n initialTxHash: TxHash,\n): ResultAsync<\n TransactionResult,\n CancelError | TransactionError | UnexpectedError\n> {\n return ResultAsync.fromPromise(\n waitForTransactionReceipt(walletClient, {\n hash: initialTxHash,\n pollingInterval: 100,\n retryCount: 20,\n retryDelay: 50,\n }),\n (err) => UnexpectedError.from(err),\n ).andThen((receipt) => {\n const hash = txHash(receipt.transactionHash);\n\n switch (receipt.status) {\n case 'reverted':\n if (initialTxHash !== hash) {\n return errAsync(CancelError.from(`Transaction replaced by ${hash}`));\n }\n return errAsync(transactionError(walletClient.chain, hash, request));\n case 'success':\n return okAsync({\n // viem's waitForTransactionReceipt supports transaction replacement\n // so it's important to use the transaction hash from the receipt\n txHash: hash,\n operations: request.operations,\n });\n }\n });\n}\n\nfunction sendTransactionAndWait(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<\n TransactionResult,\n CancelError | SigningError | TransactionError | UnexpectedError\n> {\n return sendTransaction(walletClient, request).andThen((hash) =>\n waitForTransactionResult(walletClient, request, hash),\n );\n}\n\nfunction executePlan(\n walletClient: WalletClient,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(walletClient, result);\n\n case 'Erc20ApprovalRequired':\n case 'PreContractActionRequired':\n return sendTransactionAndWait(walletClient, result.transaction).andThen(\n () => sendTransactionAndWait(walletClient, result.originalTransaction),\n );\n\n case 'InsufficientBalanceError':\n return errAsync(ValidationError.fromGqlNode(result));\n }\n}\n\n/**\n * Creates an execution plan handler that sends transactions using the provided wallet client.\n */\nexport function sendWith(walletClient: WalletClient): ExecutionPlanHandler;\n/**\n * Sends execution plan transactions using the provided wallet client.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n walletClient: WalletClient,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n walletClient: WalletClient,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(walletClient, result)\n : executePlan.bind(null, walletClient);\n}\n\nfunction signERC20Permit(\n walletClient: WalletClient,\n result: PermitTypedDataResponse,\n): ReturnType<ERC20PermitHandler> {\n invariant(walletClient.account, 'Wallet account is required');\n\n return ResultAsync.fromPromise(\n signTypedData(walletClient, {\n account: walletClient.account,\n domain: result.domain as TypedDataDomain,\n types: result.types as TypedData,\n primaryType: result.primaryType as keyof typeof result.types,\n message: result.message,\n }),\n (err) => SigningError.from(err),\n ).map((hex) => ({\n deadline: result.message.deadline,\n value: signatureFrom(hex),\n }));\n}\n\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the provided wallet client.\n */\nexport function signERC20PermitWith(\n walletClient: WalletClient,\n): ERC20PermitHandler {\n return signERC20Permit.bind(null, walletClient);\n}\n\nfunction signSwapTypedData(\n walletClient: WalletClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n invariant(walletClient.account, 'Wallet account is required');\n\n return ResultAsync.fromPromise(\n signTypedData(walletClient, {\n account: walletClient.account,\n domain: result.domain as TypedDataDomain,\n types: result.types as TypedData,\n primaryType: result.primaryType,\n message: JSON.parse(result.message),\n }),\n (err) => SigningError.from(err),\n ).map((hex) => ({\n deadline: JSON.parse(result.message).deadline,\n value: signatureFrom(hex),\n }));\n}\n\n/**\n * @internal\n * Creates a swap signature handler that signs swap typed data using the provided wallet client.\n */\nexport function signSwapTypedDataWith(\n walletClient: WalletClient,\n): SwapSignatureHandler;\n/**\n * @internal\n * Signs swap typed data using the provided wallet client.\n */\nexport function signSwapTypedDataWith(\n walletClient: WalletClient,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n walletClient: WalletClient,\n result?: SwapByIntentTypedData | CancelSwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(walletClient, result)\n : signSwapTypedData.bind(null, walletClient);\n}\n","import {\n SigningError,\n type TransactionError,\n ValidationError,\n} from '@aave/core';\nimport type {\n CancelSwapTypedData,\n ExecutionPlan,\n PermitTypedDataResponse,\n SwapByIntentTypedData,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n errAsync,\n okAsync,\n ResultAsync,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport type { PrivyClient } from '@privy-io/server-auth';\nimport { createPublicClient, http } from 'viem';\nimport { waitForTransactionReceipt } from 'viem/actions';\nimport type {\n ERC20PermitHandler,\n ExecutionPlanHandler,\n SwapSignatureHandler,\n TransactionResult,\n} from './types';\nimport { supportedChains, transactionError } from './viem';\n\nasync function sendTransaction(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): Promise<TxHash> {\n const { hash } = await privy.walletApi.ethereum.sendTransaction({\n walletId,\n caip2: `eip155:${request.chainId}`,\n transaction: {\n from: request.from,\n to: request.to,\n value: `0x${BigInt(request.value).toString(16)}`,\n chainId: request.chainId,\n data: request.data,\n },\n });\n return txHash(hash);\n}\n\nfunction sendTransactionAndWait(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): ResultAsync<TransactionResult, SigningError | TransactionError> {\n // TODO: verify it's on the correct chain, ask to switch if possible\n // TODO: verify if wallet account is correct, switch if possible\n const publicClient = createPublicClient({\n chain: supportedChains[request.chainId],\n transport: http(),\n });\n\n return ResultAsync.fromPromise(\n sendTransaction(privy, request, walletId),\n (err) => SigningError.from(err),\n )\n .map(async (hash) =>\n waitForTransactionReceipt(publicClient, {\n hash,\n pollingInterval: 100,\n retryCount: 20,\n retryDelay: 50,\n }),\n )\n .andThen((receipt) => {\n const hash = txHash(receipt.transactionHash);\n\n if (receipt.status === 'reverted') {\n return errAsync(\n transactionError(supportedChains[request.chainId], hash, request),\n );\n }\n return okAsync({\n txHash: hash,\n operations: request.operations,\n });\n });\n}\n\nfunction executePlan(\n privy: PrivyClient,\n walletId: string,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(privy, result, walletId);\n\n case 'Erc20ApprovalRequired':\n case 'PreContractActionRequired':\n return sendTransactionAndWait(\n privy,\n result.transaction,\n walletId,\n ).andThen(() =>\n sendTransactionAndWait(privy, result.originalTransaction, walletId),\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 specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(privy, walletId, result)\n : executePlan.bind(null, privy, walletId);\n}\n\nfunction signERC20Permit(\n privy: PrivyClient,\n walletId: string,\n result: PermitTypedDataResponse,\n): ReturnType<ERC20PermitHandler> {\n return ResultAsync.fromPromise(\n privy.walletApi.ethereum.signTypedData({\n walletId,\n typedData: {\n domain: result.domain,\n types: result.types,\n message: result.message,\n primaryType: result.primaryType,\n },\n }),\n (err) => SigningError.from(err),\n ).map((response) => ({\n deadline: result.message.deadline,\n value: signatureFrom(response.signature),\n }));\n}\n\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the specified Privy wallet.\n */\nexport function signERC20PermitWith(\n privy: PrivyClient,\n walletId: string,\n): ERC20PermitHandler {\n return signERC20Permit.bind(null, privy, walletId);\n}\n\nfunction signSwapTypedData(\n privy: PrivyClient,\n walletId: string,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n const message = JSON.parse(result.message);\n return ResultAsync.fromPromise(\n privy.walletApi.ethereum.signTypedData({\n walletId,\n typedData: {\n domain: result.domain,\n types: result.types,\n message,\n primaryType: result.primaryType,\n },\n }),\n (err) => SigningError.from(err),\n ).map((response) => ({\n deadline: message.deadline,\n value: signatureFrom(response.signature),\n }));\n}\n\n/**\n * @internal\n * Creates a swap signature handler that signs swap typed data using the specified Privy wallet.\n */\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n): SwapSignatureHandler;\n/**\n * @internal\n * Signs swap typed data using the specified Privy wallet.\n */\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n result?: SwapByIntentTypedData | CancelSwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(privy, walletId, result)\n : signSwapTypedData.bind(null, privy, walletId);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/adapters.ts","../src/viem.ts","../src/privy.ts"],"names":["hasApprovals","plan","supportsPermit","isOneEntryArray","transactionError","chain","txHash","request","baseUrl","link","TransactionError","allChains","viemChains","sendTransaction","privy","walletId","hash","sendTransactionAndWait","extractChain","publicClient","createPublicClient","http","ResultAsync","err","SigningError","waitForTransactionReceipt","UnexpectedError","receipt","errAsync","okAsync","executePlan","result","approval","ValidationError","sendWith","permitWith","action","permitTypedData","signTypedDataWith","signature","permitSig","signTypedData","data","response","typedData","signatureFrom"],"mappings":"6fAKA,SAASA,CAAAA,CAAaC,CAAAA,CAAsC,CAC1D,OACE,OAAOA,CAAAA,EAAS,QAAA,EAChBA,IAAS,IAAA,EACT,WAAA,GAAeA,CAAAA,EACf,KAAA,CAAM,OAAA,CAAQA,CAAAA,CAAK,SAAS,CAEhC,CASO,SAASC,CAAAA,CAAkBD,CAAAA,CAG9B,CACF,OACED,CAAAA,CAAaC,CAAI,CAAA,EACjBE,sBAAgBF,CAAAA,CAAK,SAAS,CAAA,EAC9B,CAAC,CAACA,CAAAA,CAAK,SAAA,CAAU,CAAC,CAAA,CAAE,WAExB,CCuOO,SAASG,CAAAA,CACdC,CAAAA,CACAC,EACAC,CAAAA,CACkB,CAClB,IAAMC,CAAAA,CAAUH,CAAAA,EAAO,cAAA,EAAgB,OAAA,EAAS,GAAA,CAC1CI,CAAAA,CAAOD,CAAAA,EAAW,IAAI,GAAA,CAAI,CAAA,IAAA,EAAOF,CAAM,CAAA,CAAA,CAAIE,CAAO,EAAE,QAAA,EAAS,CAEnE,OAAOE,qBAAAA,CAAiB,GAAA,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K,OAAA,CACd,WAAA,CAAaA,CAAAA,CAAK,WACpB,CACF,CAAC,CAAA,CACAnB,CAAAA,EAAQC,kBAAa,IAAA,CAAKD,CAAG,CAChC,CAAA,CAAE,GAAA,CAAKoB,CAAAA,EAAaA,CAAAA,CAAS,SAAS,CACxC,CAqCO,SAASL,CAAAA,CACdxB,CAAAA,CACAC,CAAAA,CACA2B,CAAAA,CACiD,CACjD,OAAIA,CAAAA,GAAS,MAAA,CACHE,CAAAA,EACNH,CAAAA,CAAc3B,CAAAA,CAAOC,CAAAA,CAAU6B,CAAS,CAAA,CAAE,IAAIC,mBAAa,CAAA,CAExDJ,CAAAA,CAAc3B,CAAAA,CAAOC,CAAAA,CAAU2B,CAAI,CAAA,CAAE,GAAA,CAAIG,mBAAa,CAC/D","file":"privy.cjs","sourcesContent":["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 CancelError,\n SigningError,\n TransactionError,\n UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n Chain,\n ERC20PermitSignature,\n ExecutionPlan,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n chainId,\n errAsync,\n invariant,\n isObject,\n okAsync,\n ResultAsync,\n type Signature,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport {\n type Account,\n defineChain,\n type ProviderRpcError,\n type RpcError,\n SwitchChainError,\n TransactionExecutionError,\n type Transport,\n UserRejectedRequestError,\n type Chain as ViemChain,\n type WalletClient,\n} from 'viem';\nimport {\n estimateGas as estimateGasWithViem,\n sendTransaction as sendTransactionWithViem,\n waitForTransactionReceipt,\n} from 'viem/actions';\nimport { mainnet, sepolia } from 'viem/chains';\nimport type { AaveClient } from './AaveClient';\nimport { chain as fetchChain } from './actions';\nimport { supportsPermit } from './adapters';\nimport type {\n ExecutionPlanHandler,\n SignTypedDataError,\n TransactionResult,\n TypedData,\n TypedDataHandler,\n} from './types';\n\nfunction isRpcError(err: unknown): err is RpcError {\n return isObject(err) && 'code' in err && 'message' in err;\n}\n\nfunction isProviderRpcError(\n err: unknown,\n): err is ProviderRpcError<{ originalError?: { code: number } }> {\n return isObject(err) &&\n 'name' in err &&\n 'message' in err &&\n 'originalError' in err\n ? isRpcError(err.originalError) && 'code' in err.originalError\n : true;\n}\n\nfunction signTypedData(\n walletClient: WalletClient,\n data: TypedData,\n): ResultAsync<Signature, SignTypedDataError> {\n invariant(\n walletClient.account,\n 'Wallet account is required to sign typed data',\n );\n\n return ResultAsync.fromPromise(\n walletClient.signTypedData({\n account: walletClient.account,\n domain: data.domain,\n types: data.types,\n primaryType: data.primaryType,\n message: data.message,\n }),\n (err) => {\n if (err instanceof UserRejectedRequestError) {\n return CancelError.from(err);\n }\n return SigningError.from(err);\n },\n ).map(signatureFrom);\n}\n\n/**\n * @internal\n */\nexport function toViemChain(chain: Chain): ViemChain {\n // known chains\n switch (chain.chainId) {\n case chainId(mainnet.id):\n return mainnet;\n\n case chainId(sepolia.id):\n return sepolia;\n }\n\n // most likely a tenderly fork\n return defineChain({\n id: chain.chainId,\n name: chain.name,\n nativeCurrency: {\n name: chain.nativeInfo.name,\n symbol: chain.nativeInfo.symbol,\n decimals: chain.nativeInfo.decimals,\n },\n rpcUrls: { default: { http: [chain.rpcUrl] } },\n blockExplorers: {\n default: {\n name: `${chain.name} Explorer`,\n url: chain.explorerUrl,\n },\n },\n });\n}\n\n/**\n * @internal\n */\nexport function viemChainsFrom(chains: Chain[]): ViemChain[] {\n return chains.map(toViemChain);\n}\n\n/**\n * @internal\n */\nexport function ensureChain(\n aaveClient: AaveClient,\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<void, CancelError | SigningError | UnexpectedError> {\n return ResultAsync.fromPromise(walletClient.getChainId(), (err) =>\n SigningError.from(err),\n ).andThen((chainId) => {\n if (chainId === request.chainId) {\n return okAsync();\n }\n\n return fetchChain(\n aaveClient,\n { chainId: request.chainId },\n { batch: false },\n ).andThen((chain) => {\n invariant(chain, `Chain ${request.chainId} is not supported`);\n\n return ResultAsync.fromPromise(\n walletClient.switchChain({ id: request.chainId }),\n (err) => SigningError.from(err),\n ).orElse((err) => {\n const code = isRpcError(err.cause)\n ? err.cause.code\n : // Unwrapping for MetaMask Mobile\n // https://github.com/MetaMask/metamask-mobile/issues/2944#issuecomment-976988719\n isProviderRpcError(err.cause)\n ? err.cause.data?.originalError?.code\n : undefined;\n\n if (code === SwitchChainError.code) {\n return ResultAsync.fromPromise(\n walletClient.addChain({ chain: toViemChain(chain) }),\n (err) => {\n if (\n isRpcError(err) &&\n err.code === UserRejectedRequestError.code\n ) {\n return CancelError.from(err);\n }\n return SigningError.from(err);\n },\n );\n }\n\n return err.asResultAsync();\n });\n });\n });\n}\n\nfunction estimateGas(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<bigint, SigningError> {\n return ResultAsync.fromPromise(\n estimateGasWithViem(walletClient, {\n account: walletClient.account,\n data: request.data,\n to: request.to,\n value: BigInt(request.value),\n prepare: false,\n }),\n (err) => SigningError.from(err),\n ).map((gas) => (gas * 115n) / 100n); // 15% buffer\n}\n\nfunction sendEip1559Transaction(\n walletClient: WalletClient<Transport, ViemChain, Account>,\n request: TransactionRequest,\n): ResultAsync<TxHash, CancelError | SigningError> {\n return estimateGas(walletClient, request)\n .andThen((gas) =>\n ResultAsync.fromPromise(\n sendTransactionWithViem(walletClient, {\n account: walletClient.account,\n data: request.data,\n to: request.to,\n value: BigInt(request.value),\n chain: walletClient.chain,\n gas,\n }),\n (err) => {\n if (err instanceof TransactionExecutionError) {\n const rejected = err.walk(\n (err) => err instanceof UserRejectedRequestError,\n );\n\n if (rejected) {\n return CancelError.from(rejected);\n }\n }\n return SigningError.from(err);\n },\n ),\n )\n .map(txHash);\n}\n\nfunction isWalletClientWithAccount(\n walletClient: WalletClient,\n): walletClient is WalletClient<Transport, ViemChain, Account> {\n return walletClient.account !== undefined;\n}\n\n/**\n * @internal\n */\nexport function sendTransaction(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<TxHash, CancelError | SigningError> {\n invariant(\n isWalletClientWithAccount(walletClient),\n 'Wallet client with account is required',\n );\n\n return sendEip1559Transaction(walletClient, request);\n}\n\n/**\n * @internal\n */\nexport function transactionError(\n chain: ViemChain | undefined,\n txHash: TxHash,\n request: TransactionRequest,\n): TransactionError {\n const baseUrl = chain?.blockExplorers?.default?.url;\n const link = baseUrl && new URL(`/tx/${txHash}`, baseUrl).toString();\n\n return TransactionError.new({ txHash, request, link });\n}\n\n/**\n * @internal\n */\nexport function waitForTransactionResult(\n walletClient: WalletClient,\n request: TransactionRequest,\n initialTxHash: TxHash,\n): ResultAsync<\n TransactionResult,\n CancelError | TransactionError | UnexpectedError\n> {\n return ResultAsync.fromPromise(\n waitForTransactionReceipt(walletClient, {\n hash: initialTxHash,\n pollingInterval: 100,\n retryCount: 20,\n retryDelay: 50,\n }),\n (err) => UnexpectedError.from(err),\n ).andThen((receipt) => {\n const hash = txHash(receipt.transactionHash);\n\n switch (receipt.status) {\n case 'reverted':\n if (initialTxHash !== hash) {\n return errAsync(CancelError.from(`Transaction replaced by ${hash}`));\n }\n return errAsync(transactionError(walletClient.chain, hash, request));\n case 'success':\n return okAsync({\n // viem's waitForTransactionReceipt supports transaction replacement\n // so it's important to use the transaction hash from the receipt\n txHash: hash,\n operations: request.operations,\n });\n }\n });\n}\n\nfunction sendTransactionAndWait(\n walletClient: WalletClient,\n request: TransactionRequest,\n): ResultAsync<\n TransactionResult,\n CancelError | SigningError | TransactionError | UnexpectedError\n> {\n return sendTransaction(walletClient, request).andThen((hash) =>\n waitForTransactionResult(walletClient, request, hash),\n );\n}\n\nfunction executePlan(\n walletClient: WalletClient,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(walletClient, result);\n\n case 'Erc20ApprovalRequired':\n return result.approvals\n .reduce<ReturnType<typeof sendTransactionAndWait>>(\n (chain, approval) =>\n chain.andThen(() =>\n sendTransactionAndWait(walletClient, approval.byTransaction),\n ),\n okAsync(undefined as never),\n )\n .andThen(() =>\n sendTransactionAndWait(walletClient, result.originalTransaction),\n );\n\n case 'PreContractActionRequired':\n return sendTransactionAndWait(walletClient, result.transaction).andThen(\n () => sendTransactionAndWait(walletClient, result.originalTransaction),\n );\n\n case 'InsufficientBalanceError':\n return errAsync(ValidationError.fromGqlNode(result));\n }\n}\n\n/**\n * Creates an execution plan handler that sends transactions using the provided wallet client.\n */\nexport function sendWith(walletClient: WalletClient): ExecutionPlanHandler;\n/**\n * Sends execution plan transactions using the provided wallet client.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n walletClient: WalletClient,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n walletClient: WalletClient,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(walletClient, result)\n : executePlan.bind(null, walletClient);\n}\n\n/**\n * Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided wallet client.\n *\n * @param walletClient - The wallet client 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(walletClient: WalletClient): TypedDataHandler;\n\n/**\n * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the provided wallet client.\n *\n * @param walletClient - The wallet client to use for signing.\n * @param data - The typed data to sign.\n * @returns A ResultAsync containing the raw signature.\n *\n * ```ts\n * const result = await signTypedDataWith(wallet, typedData);\n * ```\n */\nexport function signTypedDataWith(\n walletClient: WalletClient,\n data: TypedData,\n): ReturnType<TypedDataHandler>;\n\nexport function signTypedDataWith(\n walletClient: WalletClient,\n data?: TypedData,\n): TypedDataHandler | ReturnType<TypedDataHandler> {\n if (data === undefined) {\n return signTypedData.bind(null, walletClient);\n }\n return signTypedData(walletClient, data);\n}\n\n/**\n * Handles ERC20 permit signing for actions that require token approval.\n *\n * Calls the action to get an initial execution plan. If the plan requires ERC20 approval\n * and the token supports permit signatures, signs the permit and re-calls the action\n * with the signature to get a new plan that can be sent directly.\n *\n * ```ts\n * const result = await permitWith(walletClient, (permitSig) =>\n * supply(client, {\n * reserve: reserve.id,\n * amount: { erc20: { value: amount, permitSig } },\n * sender: evmAddress(walletClient.account.address),\n * })\n * )\n * .andThen(sendWith(walletClient))\n * .andThen(client.waitForTransaction);\n * ```\n *\n * @param walletClient - The wallet client to use for signing permits.\n * @param action - A function that returns an execution plan, accepting an optional permit signature.\n * @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.\n */\nexport function permitWith<E>(\n walletClient: WalletClient,\n action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>,\n): ResultAsync<ExecutionPlan, E | SignTypedDataError> {\n return action().andThen((result) => {\n if (supportsPermit(result)) {\n const permitTypedData = result.approvals[0].bySignature;\n // Sign and wrap with deadline\n return signTypedDataWith(walletClient, 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","import {\n SigningError,\n type TransactionError,\n UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n ERC20PermitSignature,\n ExecutionPlan,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n errAsync,\n okAsync,\n ResultAsync,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport type { PrivyClient } from '@privy-io/server-auth';\nimport { createPublicClient, extractChain, http } from 'viem';\nimport { waitForTransactionReceipt } from 'viem/actions';\nimport * as viemChains from 'viem/chains';\nimport { supportsPermit } from './adapters';\nimport type {\n ExecutionPlanHandler,\n SignTypedDataError,\n TransactionResult,\n TypedData,\n TypedDataHandler,\n} from './types';\nimport { transactionError } from './viem';\n\nconst allChains = Object.values(viemChains);\n\nasync function sendTransaction(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): Promise<TxHash> {\n const { hash } = await privy.walletApi.ethereum.sendTransaction({\n walletId,\n caip2: `eip155:${request.chainId}`,\n transaction: {\n from: request.from,\n to: request.to,\n value: `0x${BigInt(request.value).toString(16)}`,\n chainId: request.chainId,\n data: request.data,\n },\n });\n return txHash(hash);\n}\n\nfunction sendTransactionAndWait(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): ResultAsync<\n TransactionResult,\n SigningError | TransactionError | UnexpectedError\n> {\n const chain = extractChain({\n chains: allChains,\n id: request.chainId as (typeof allChains)[number]['id'],\n });\n\n const publicClient = createPublicClient({\n chain,\n transport: http(),\n });\n\n return ResultAsync.fromPromise(\n sendTransaction(privy, request, walletId),\n (err) => SigningError.from(err),\n )\n .andThen((hash) =>\n ResultAsync.fromPromise(\n waitForTransactionReceipt(publicClient, {\n hash,\n pollingInterval: 100,\n retryCount: 20,\n retryDelay: 50,\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(transactionError(chain, hash, request));\n }\n return okAsync({\n txHash: hash,\n operations: request.operations,\n });\n });\n}\n\nfunction executePlan(\n privy: PrivyClient,\n walletId: string,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(privy, result, walletId);\n\n case 'Erc20ApprovalRequired':\n return result.approvals\n .reduce<ReturnType<typeof sendTransactionAndWait>>(\n (chain, approval) =>\n chain.andThen(() =>\n sendTransactionAndWait(privy, approval.byTransaction, walletId),\n ),\n okAsync(undefined as never),\n )\n .andThen(() =>\n sendTransactionAndWait(privy, result.originalTransaction, walletId),\n );\n\n case 'PreContractActionRequired':\n return sendTransactionAndWait(\n privy,\n result.transaction,\n walletId,\n ).andThen(() =>\n sendTransactionAndWait(privy, result.originalTransaction, walletId),\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 specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(privy, walletId, result)\n : executePlan.bind(null, privy, walletId);\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(privy, walletId, (permitSig) =>\n * supply(client, {\n * reserve: reserve.id,\n * amount: { erc20: { value: amount, permitSig } },\n * sender: evmAddress(walletAddress),\n * })\n * )\n * .andThen(sendWith(privy, walletId))\n * .andThen(client.waitForTransaction);\n * ```\n *\n * @param privy - The Privy client for signing permits.\n * @param walletId - The ID of the Privy wallet to use.\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 privy: PrivyClient,\n walletId: string,\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(privy, walletId, 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 privy: PrivyClient,\n walletId: string,\n data: TypedData,\n): ResultAsync<string, SigningError> {\n return ResultAsync.fromPromise(\n privy.walletApi.ethereum.signTypedData({\n walletId,\n typedData: {\n domain: data.domain,\n types: data.types,\n message: data.message,\n primaryType: data.primaryType,\n },\n }),\n (err) => SigningError.from(err),\n ).map((response) => response.signature);\n}\n\n/**\n * Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.\n *\n * @param privy - The Privy client instance.\n * @param walletId - The wallet ID 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(privy, walletId));\n * ```\n */\nexport function signTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n): TypedDataHandler;\n\n/**\n * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.\n *\n * @param privy - The Privy client instance.\n * @param walletId - The wallet ID 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(privy, walletId, typedData);\n * ```\n */\nexport function signTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n data: TypedData,\n): ReturnType<TypedDataHandler>;\n\nexport function signTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n data?: TypedData,\n): TypedDataHandler | ReturnType<TypedDataHandler> {\n if (data === undefined) {\n return (typedData: TypedData) =>\n signTypedData(privy, walletId, typedData).map(signatureFrom);\n }\n return signTypedData(privy, walletId, data).map(signatureFrom);\n}\n"]}
|
package/dist/privy.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ERC20PermitSignature, ExecutionPlan } from '@aave/graphql';
|
|
2
|
+
import { ResultAsync } from '@aave/types';
|
|
2
3
|
import { PrivyClient } from '@privy-io/server-auth';
|
|
3
|
-
import { E as ExecutionPlanHandler,
|
|
4
|
+
import { S as SignTypedDataError, E as ExecutionPlanHandler, T as TypedDataHandler, a as TypedData } from './types-XProSTZ7.cjs';
|
|
4
5
|
import '@aave/core';
|
|
5
|
-
import '@aave/types';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates an execution plan handler that sends transactions using the specified Privy wallet.
|
|
@@ -13,18 +13,55 @@ declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(privy: PrivyC
|
|
|
13
13
|
*/
|
|
14
14
|
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(privy: PrivyClient, walletId: string, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Handles ERC20 permit signing for actions that require token approval.
|
|
17
|
+
*
|
|
18
|
+
* Calls the action to get an initial execution plan. If the plan requires ERC20 approval
|
|
19
|
+
* and the token supports permit signatures, signs the permit and re-calls the action
|
|
20
|
+
* with the signature to get a new plan that can be sent directly.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* const result = await permitWith(privy, walletId, (permitSig) =>
|
|
24
|
+
* supply(client, {
|
|
25
|
+
* reserve: reserve.id,
|
|
26
|
+
* amount: { erc20: { value: amount, permitSig } },
|
|
27
|
+
* sender: evmAddress(walletAddress),
|
|
28
|
+
* })
|
|
29
|
+
* )
|
|
30
|
+
* .andThen(sendWith(privy, walletId))
|
|
31
|
+
* .andThen(client.waitForTransaction);
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param privy - The Privy client for signing permits.
|
|
35
|
+
* @param walletId - The ID of the Privy wallet to use.
|
|
36
|
+
* @param action - A function that returns an execution plan, accepting an optional permit signature.
|
|
37
|
+
* @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.
|
|
17
38
|
*/
|
|
18
|
-
declare function
|
|
39
|
+
declare function permitWith<E>(privy: PrivyClient, walletId: string, action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>): ResultAsync<ExecutionPlan, E | SignTypedDataError>;
|
|
19
40
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
41
|
+
* Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.
|
|
42
|
+
*
|
|
43
|
+
* @param privy - The Privy client instance.
|
|
44
|
+
* @param walletId - The wallet ID to use for signing.
|
|
45
|
+
* @returns A function that takes typed data and returns a ResultAsync containing the raw signature.
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* const result = await prepareSwapCancel(client, request)
|
|
49
|
+
* .andThen(signTypedDataWith(privy, walletId));
|
|
50
|
+
* ```
|
|
22
51
|
*/
|
|
23
|
-
declare function
|
|
52
|
+
declare function signTypedDataWith(privy: PrivyClient, walletId: string): TypedDataHandler;
|
|
24
53
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
54
|
+
* Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.
|
|
55
|
+
*
|
|
56
|
+
* @param privy - The Privy client instance.
|
|
57
|
+
* @param walletId - The wallet ID to use for signing.
|
|
58
|
+
* @param data - The typed data to sign.
|
|
59
|
+
* @returns A ResultAsync containing the raw signature.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* const result = await signTypedDataWith(privy, walletId, typedData);
|
|
63
|
+
* ```
|
|
27
64
|
*/
|
|
28
|
-
declare function
|
|
65
|
+
declare function signTypedDataWith(privy: PrivyClient, walletId: string, data: TypedData): ReturnType<TypedDataHandler>;
|
|
29
66
|
|
|
30
|
-
export {
|
|
67
|
+
export { permitWith, sendWith, signTypedDataWith };
|
package/dist/privy.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ERC20PermitSignature, ExecutionPlan } from '@aave/graphql';
|
|
2
|
+
import { ResultAsync } from '@aave/types';
|
|
2
3
|
import { PrivyClient } from '@privy-io/server-auth';
|
|
3
|
-
import { E as ExecutionPlanHandler,
|
|
4
|
+
import { S as SignTypedDataError, E as ExecutionPlanHandler, T as TypedDataHandler, a as TypedData } from './types-XProSTZ7.js';
|
|
4
5
|
import '@aave/core';
|
|
5
|
-
import '@aave/types';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Creates an execution plan handler that sends transactions using the specified Privy wallet.
|
|
@@ -13,18 +13,55 @@ declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(privy: PrivyC
|
|
|
13
13
|
*/
|
|
14
14
|
declare function sendWith<T extends ExecutionPlan = ExecutionPlan>(privy: PrivyClient, walletId: string, result: T): ReturnType<ExecutionPlanHandler<T>>;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Handles ERC20 permit signing for actions that require token approval.
|
|
17
|
+
*
|
|
18
|
+
* Calls the action to get an initial execution plan. If the plan requires ERC20 approval
|
|
19
|
+
* and the token supports permit signatures, signs the permit and re-calls the action
|
|
20
|
+
* with the signature to get a new plan that can be sent directly.
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* const result = await permitWith(privy, walletId, (permitSig) =>
|
|
24
|
+
* supply(client, {
|
|
25
|
+
* reserve: reserve.id,
|
|
26
|
+
* amount: { erc20: { value: amount, permitSig } },
|
|
27
|
+
* sender: evmAddress(walletAddress),
|
|
28
|
+
* })
|
|
29
|
+
* )
|
|
30
|
+
* .andThen(sendWith(privy, walletId))
|
|
31
|
+
* .andThen(client.waitForTransaction);
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param privy - The Privy client for signing permits.
|
|
35
|
+
* @param walletId - The ID of the Privy wallet to use.
|
|
36
|
+
* @param action - A function that returns an execution plan, accepting an optional permit signature.
|
|
37
|
+
* @returns A ResultAsync containing the resolved ExecutionPlan ready to be sent with `sendWith`.
|
|
17
38
|
*/
|
|
18
|
-
declare function
|
|
39
|
+
declare function permitWith<E>(privy: PrivyClient, walletId: string, action: (permitSig?: ERC20PermitSignature) => ResultAsync<ExecutionPlan, E>): ResultAsync<ExecutionPlan, E | SignTypedDataError>;
|
|
19
40
|
/**
|
|
20
|
-
*
|
|
21
|
-
*
|
|
41
|
+
* Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.
|
|
42
|
+
*
|
|
43
|
+
* @param privy - The Privy client instance.
|
|
44
|
+
* @param walletId - The wallet ID to use for signing.
|
|
45
|
+
* @returns A function that takes typed data and returns a ResultAsync containing the raw signature.
|
|
46
|
+
*
|
|
47
|
+
* ```ts
|
|
48
|
+
* const result = await prepareSwapCancel(client, request)
|
|
49
|
+
* .andThen(signTypedDataWith(privy, walletId));
|
|
50
|
+
* ```
|
|
22
51
|
*/
|
|
23
|
-
declare function
|
|
52
|
+
declare function signTypedDataWith(privy: PrivyClient, walletId: string): TypedDataHandler;
|
|
24
53
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
54
|
+
* Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.
|
|
55
|
+
*
|
|
56
|
+
* @param privy - The Privy client instance.
|
|
57
|
+
* @param walletId - The wallet ID to use for signing.
|
|
58
|
+
* @param data - The typed data to sign.
|
|
59
|
+
* @returns A ResultAsync containing the raw signature.
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* const result = await signTypedDataWith(privy, walletId, typedData);
|
|
63
|
+
* ```
|
|
27
64
|
*/
|
|
28
|
-
declare function
|
|
65
|
+
declare function signTypedDataWith(privy: PrivyClient, walletId: string, data: TypedData): ReturnType<TypedDataHandler>;
|
|
29
66
|
|
|
30
|
-
export {
|
|
67
|
+
export { permitWith, sendWith, signTypedDataWith };
|
package/dist/privy.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {a
|
|
1
|
+
import {e}from'./chunk-SXZ2BGUZ.js';import {a}from'./chunk-N4LXBTGY.js';import'./chunk-HH6OAH2K.js';import {ValidationError,SigningError,UnexpectedError}from'@aave/core';import {okAsync,signatureFrom,errAsync,ResultAsync,txHash}from'@aave/types';import {extractChain,createPublicClient,http}from'viem';import {waitForTransactionReceipt}from'viem/actions';import*as R from'viem/chains';var D=Object.values(R);async function H(e,n,t){let{hash:r}=await e.walletApi.ethereum.sendTransaction({walletId:t,caip2:`eip155:${n.chainId}`,transaction:{from:n.from,to:n.to,value:`0x${BigInt(n.value).toString(16)}`,chainId:n.chainId,data:n.data}});return txHash(r)}function o(e$1,n,t){let r=extractChain({chains:D,id:n.chainId}),i=createPublicClient({chain:r,transport:http()});return ResultAsync.fromPromise(H(e$1,n,t),a=>SigningError.from(a)).andThen(a=>ResultAsync.fromPromise(waitForTransactionReceipt(i,{hash:a,pollingInterval:100,retryCount:20,retryDelay:50}),s=>UnexpectedError.from(s))).andThen(a=>{let s=txHash(a.transactionHash);return a.status==="reverted"?errAsync(e(r,s,n)):okAsync({txHash:s,operations:n.operations})})}function y(e,n,t){switch(t.__typename){case "TransactionRequest":return o(e,t,n);case "Erc20ApprovalRequired":return t.approvals.reduce((r,i)=>r.andThen(()=>o(e,i.byTransaction,n)),okAsync(void 0)).andThen(()=>o(e,t.originalTransaction,n));case "PreContractActionRequired":return o(e,t.transaction,n).andThen(()=>o(e,t.originalTransaction,n));case "InsufficientBalanceError":return errAsync(ValidationError.fromGqlNode(t))}}function F(e,n,t){return t?y(e,n,t):y.bind(null,e,n)}function U(e,n,t){return t().andThen(r=>{if(a(r)){let i=r.approvals[0].bySignature;return A(e,n,i).map(a=>({deadline:i.message.deadline,value:a})).andThen(a=>t(a))}return okAsync(r)})}function T(e,n,t){return ResultAsync.fromPromise(e.walletApi.ethereum.signTypedData({walletId:n,typedData:{domain:t.domain,types:t.types,message:t.message,primaryType:t.primaryType}}),r=>SigningError.from(r)).map(r=>r.signature)}function A(e,n,t){return t===void 0?r=>T(e,n,r).map(signatureFrom):T(e,n,t).map(signatureFrom)}export{U as permitWith,F as sendWith,A as signTypedDataWith};//# sourceMappingURL=privy.js.map
|
|
2
2
|
//# sourceMappingURL=privy.js.map
|
package/dist/privy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/privy.ts"],"names":["sendTransaction","privy","request","walletId","hash","txHash","sendTransactionAndWait","publicClient","createPublicClient","supportedChains","http","ResultAsync","err","SigningError","waitForTransactionReceipt","receipt","errAsync","transactionError","okAsync","executePlan","result","ValidationError","sendWith","signERC20Permit","response","signatureFrom","signERC20PermitWith","signSwapTypedData","message","signSwapTypedDataWith"],"mappings":"oSA+BA,eAAeA,EACbC,CAAAA,CACAC,CAAAA,CACAC,EACiB,CACjB,GAAM,CAAE,IAAA,CAAAC,CAAK,EAAI,MAAMH,CAAAA,CAAM,UAAU,QAAA,CAAS,eAAA,CAAgB,CAC9D,QAAA,CAAAE,CAAAA,CACA,MAAO,CAAA,OAAA,EAAUD,CAAAA,CAAQ,OAAO,CAAA,CAAA,CAChC,WAAA,CAAa,CACX,IAAA,CAAMA,CAAAA,CAAQ,KACd,EAAA,CAAIA,CAAAA,CAAQ,GACZ,KAAA,CAAO,CAAA,EAAA,EAAK,OAAOA,CAAAA,CAAQ,KAAK,EAAE,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA,CAC9C,OAAA,CAASA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AAAA,CAAO,OACf,KAAA,CAAOA,CAAAA,CAAO,MACd,OAAA,CAAAQ,CAAAA,CACA,YAAaR,CAAAA,CAAO,WACtB,CACF,CAAC,CAAA,CACAR,GAAQC,YAAAA,CAAa,IAAA,CAAKD,CAAG,CAChC,CAAA,CAAE,IAAKY,CAAAA,GAAc,CACnB,SAAUI,CAAAA,CAAQ,QAAA,CAClB,MAAOH,aAAAA,CAAcD,CAAAA,CAAS,SAAS,CACzC,CAAA,CAAE,CACJ,CAmBO,SAASK,EACd5B,CAAAA,CACAE,CAAAA,CACAiB,EACyD,CACzD,OAAOA,EACHO,CAAAA,CAAkB1B,CAAAA,CAAOE,EAAUiB,CAAM,CAAA,CACzCO,EAAkB,IAAA,CAAK,IAAA,CAAM1B,CAAAA,CAAOE,CAAQ,CAClD","file":"privy.js","sourcesContent":["import {\n SigningError,\n type TransactionError,\n ValidationError,\n} from '@aave/core';\nimport type {\n CancelSwapTypedData,\n ExecutionPlan,\n PermitTypedDataResponse,\n SwapByIntentTypedData,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n errAsync,\n okAsync,\n ResultAsync,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport type { PrivyClient } from '@privy-io/server-auth';\nimport { createPublicClient, http } from 'viem';\nimport { waitForTransactionReceipt } from 'viem/actions';\nimport type {\n ERC20PermitHandler,\n ExecutionPlanHandler,\n SwapSignatureHandler,\n TransactionResult,\n} from './types';\nimport { supportedChains, transactionError } from './viem';\n\nasync function sendTransaction(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): Promise<TxHash> {\n const { hash } = await privy.walletApi.ethereum.sendTransaction({\n walletId,\n caip2: `eip155:${request.chainId}`,\n transaction: {\n from: request.from,\n to: request.to,\n value: `0x${BigInt(request.value).toString(16)}`,\n chainId: request.chainId,\n data: request.data,\n },\n });\n return txHash(hash);\n}\n\nfunction sendTransactionAndWait(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): ResultAsync<TransactionResult, SigningError | TransactionError> {\n // TODO: verify it's on the correct chain, ask to switch if possible\n // TODO: verify if wallet account is correct, switch if possible\n const publicClient = createPublicClient({\n chain: supportedChains[request.chainId],\n transport: http(),\n });\n\n return ResultAsync.fromPromise(\n sendTransaction(privy, request, walletId),\n (err) => SigningError.from(err),\n )\n .map(async (hash) =>\n waitForTransactionReceipt(publicClient, {\n hash,\n pollingInterval: 100,\n retryCount: 20,\n retryDelay: 50,\n }),\n )\n .andThen((receipt) => {\n const hash = txHash(receipt.transactionHash);\n\n if (receipt.status === 'reverted') {\n return errAsync(\n transactionError(supportedChains[request.chainId], hash, request),\n );\n }\n return okAsync({\n txHash: hash,\n operations: request.operations,\n });\n });\n}\n\nfunction executePlan(\n privy: PrivyClient,\n walletId: string,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(privy, result, walletId);\n\n case 'Erc20ApprovalRequired':\n case 'PreContractActionRequired':\n return sendTransactionAndWait(\n privy,\n result.transaction,\n walletId,\n ).andThen(() =>\n sendTransactionAndWait(privy, result.originalTransaction, walletId),\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 specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(privy, walletId, result)\n : executePlan.bind(null, privy, walletId);\n}\n\nfunction signERC20Permit(\n privy: PrivyClient,\n walletId: string,\n result: PermitTypedDataResponse,\n): ReturnType<ERC20PermitHandler> {\n return ResultAsync.fromPromise(\n privy.walletApi.ethereum.signTypedData({\n walletId,\n typedData: {\n domain: result.domain,\n types: result.types,\n message: result.message,\n primaryType: result.primaryType,\n },\n }),\n (err) => SigningError.from(err),\n ).map((response) => ({\n deadline: result.message.deadline,\n value: signatureFrom(response.signature),\n }));\n}\n\n/**\n * Creates an ERC20 permit handler that signs ERC20 permits using the specified Privy wallet.\n */\nexport function signERC20PermitWith(\n privy: PrivyClient,\n walletId: string,\n): ERC20PermitHandler {\n return signERC20Permit.bind(null, privy, walletId);\n}\n\nfunction signSwapTypedData(\n privy: PrivyClient,\n walletId: string,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler> {\n const message = JSON.parse(result.message);\n return ResultAsync.fromPromise(\n privy.walletApi.ethereum.signTypedData({\n walletId,\n typedData: {\n domain: result.domain,\n types: result.types,\n message,\n primaryType: result.primaryType,\n },\n }),\n (err) => SigningError.from(err),\n ).map((response) => ({\n deadline: message.deadline,\n value: signatureFrom(response.signature),\n }));\n}\n\n/**\n * @internal\n * Creates a swap signature handler that signs swap typed data using the specified Privy wallet.\n */\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n): SwapSignatureHandler;\n/**\n * @internal\n * Signs swap typed data using the specified Privy wallet.\n */\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n result: SwapByIntentTypedData | CancelSwapTypedData,\n): ReturnType<SwapSignatureHandler>;\nexport function signSwapTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n result?: SwapByIntentTypedData | CancelSwapTypedData,\n): SwapSignatureHandler | ReturnType<SwapSignatureHandler> {\n return result\n ? signSwapTypedData(privy, walletId, result)\n : signSwapTypedData.bind(null, privy, walletId);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/privy.ts"],"names":["allChains","viemChains","sendTransaction","privy","request","walletId","hash","txHash","sendTransactionAndWait","chain","extractChain","publicClient","createPublicClient","http","ResultAsync","err","SigningError","waitForTransactionReceipt","UnexpectedError","receipt","errAsync","transactionError","okAsync","executePlan","result","approval","ValidationError","sendWith","permitWith","action","supportsPermit","permitTypedData","signTypedDataWith","signature","permitSig","signTypedData","data","response","typedData","signatureFrom"],"mappings":"iYAiCA,IAAMA,CAAAA,CAAY,MAAA,CAAO,OAAOC,CAAU,CAAA,CAE1C,eAAeC,CAAAA,CACbC,CAAAA,CACAC,EACAC,CAAAA,CACiB,CACjB,GAAM,CAAE,IAAA,CAAAC,CAAK,EAAI,MAAMH,CAAAA,CAAM,UAAU,QAAA,CAAS,eAAA,CAAgB,CAC9D,QAAA,CAAAE,CAAAA,CACA,KAAA,CAAO,CAAA,OAAA,EAAUD,CAAAA,CAAQ,OAAO,GAChC,WAAA,CAAa,CACX,KAAMA,CAAAA,CAAQ,IAAA,CACd,GAAIA,CAAAA,CAAQ,EAAA,CACZ,KAAA,CAAO,CAAA,EAAA,EAAK,MAAA,CAAOA,CAAAA,CAAQ,KAAK,CAAA,CAAE,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA,CAC9C,QAASA,CAAAA,CAAQ,OAAA,CACjB,IAAA,CAAMA,CAAAA,CAAQ,IAChB,CACF,CAAC,CAAA,CACD,OAAOG,MAAAA,CAAOD,CAAI,CACpB,CAEA,SAASE,CAAAA,CACPL,GAAAA,CACAC,CAAAA,CACAC,CAAAA,CAIA,CACA,IAAMI,EAAQC,YAAAA,CAAa,CACzB,OAAQV,CAAAA,CACR,EAAA,CAAII,EAAQ,OACd,CAAC,CAAA,CAEKO,CAAAA,CAAeC,kBAAAA,CAAmB,CACtC,MAAAH,CAAAA,CACA,SAAA,CAAWI,MACb,CAAC,EAED,OAAOC,WAAAA,CAAY,WAAA,CACjBZ,CAAAA,CAAgBC,GAAAA,CAAOC,CAAAA,CAASC,CAAQ,CAAA,CACvCU,CAAAA,EAAQC,aAAa,IAAA,CAA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AG,CAChC,EAAE,GAAA,CAAKsB,CAAAA,EAAaA,CAAAA,CAAS,SAAS,CACxC,CAqCO,SAASL,CAAAA,CACd7B,CAAAA,CACAE,EACA+B,CAAAA,CACiD,CACjD,OAAIA,CAAAA,GAAS,MAAA,CACHE,CAAAA,EACNH,CAAAA,CAAchC,CAAAA,CAAOE,CAAAA,CAAUiC,CAAS,CAAA,CAAE,GAAA,CAAIC,aAAa,CAAA,CAExDJ,CAAAA,CAAchC,CAAAA,CAAOE,EAAU+B,CAAI,CAAA,CAAE,GAAA,CAAIG,aAAa,CAC/D","file":"privy.js","sourcesContent":["import {\n SigningError,\n type TransactionError,\n UnexpectedError,\n ValidationError,\n} from '@aave/core';\nimport type {\n ERC20PermitSignature,\n ExecutionPlan,\n TransactionRequest,\n} from '@aave/graphql';\nimport {\n errAsync,\n okAsync,\n ResultAsync,\n signatureFrom,\n type TxHash,\n txHash,\n} from '@aave/types';\nimport type { PrivyClient } from '@privy-io/server-auth';\nimport { createPublicClient, extractChain, http } from 'viem';\nimport { waitForTransactionReceipt } from 'viem/actions';\nimport * as viemChains from 'viem/chains';\nimport { supportsPermit } from './adapters';\nimport type {\n ExecutionPlanHandler,\n SignTypedDataError,\n TransactionResult,\n TypedData,\n TypedDataHandler,\n} from './types';\nimport { transactionError } from './viem';\n\nconst allChains = Object.values(viemChains);\n\nasync function sendTransaction(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): Promise<TxHash> {\n const { hash } = await privy.walletApi.ethereum.sendTransaction({\n walletId,\n caip2: `eip155:${request.chainId}`,\n transaction: {\n from: request.from,\n to: request.to,\n value: `0x${BigInt(request.value).toString(16)}`,\n chainId: request.chainId,\n data: request.data,\n },\n });\n return txHash(hash);\n}\n\nfunction sendTransactionAndWait(\n privy: PrivyClient,\n request: TransactionRequest,\n walletId: string,\n): ResultAsync<\n TransactionResult,\n SigningError | TransactionError | UnexpectedError\n> {\n const chain = extractChain({\n chains: allChains,\n id: request.chainId as (typeof allChains)[number]['id'],\n });\n\n const publicClient = createPublicClient({\n chain,\n transport: http(),\n });\n\n return ResultAsync.fromPromise(\n sendTransaction(privy, request, walletId),\n (err) => SigningError.from(err),\n )\n .andThen((hash) =>\n ResultAsync.fromPromise(\n waitForTransactionReceipt(publicClient, {\n hash,\n pollingInterval: 100,\n retryCount: 20,\n retryDelay: 50,\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(transactionError(chain, hash, request));\n }\n return okAsync({\n txHash: hash,\n operations: request.operations,\n });\n });\n}\n\nfunction executePlan(\n privy: PrivyClient,\n walletId: string,\n result: ExecutionPlan,\n): ReturnType<ExecutionPlanHandler> {\n switch (result.__typename) {\n case 'TransactionRequest':\n return sendTransactionAndWait(privy, result, walletId);\n\n case 'Erc20ApprovalRequired':\n return result.approvals\n .reduce<ReturnType<typeof sendTransactionAndWait>>(\n (chain, approval) =>\n chain.andThen(() =>\n sendTransactionAndWait(privy, approval.byTransaction, walletId),\n ),\n okAsync(undefined as never),\n )\n .andThen(() =>\n sendTransactionAndWait(privy, result.originalTransaction, walletId),\n );\n\n case 'PreContractActionRequired':\n return sendTransactionAndWait(\n privy,\n result.transaction,\n walletId,\n ).andThen(() =>\n sendTransactionAndWait(privy, result.originalTransaction, walletId),\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 specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n): ExecutionPlanHandler<T>;\n/**\n * Sends execution plan transactions using the specified Privy wallet.\n */\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result: T,\n): ReturnType<ExecutionPlanHandler<T>>;\nexport function sendWith<T extends ExecutionPlan = ExecutionPlan>(\n privy: PrivyClient,\n walletId: string,\n result?: T,\n): ExecutionPlanHandler<T> | ReturnType<ExecutionPlanHandler<T>> {\n return result\n ? executePlan(privy, walletId, result)\n : executePlan.bind(null, privy, walletId);\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(privy, walletId, (permitSig) =>\n * supply(client, {\n * reserve: reserve.id,\n * amount: { erc20: { value: amount, permitSig } },\n * sender: evmAddress(walletAddress),\n * })\n * )\n * .andThen(sendWith(privy, walletId))\n * .andThen(client.waitForTransaction);\n * ```\n *\n * @param privy - The Privy client for signing permits.\n * @param walletId - The ID of the Privy wallet to use.\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 privy: PrivyClient,\n walletId: string,\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(privy, walletId, 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 privy: PrivyClient,\n walletId: string,\n data: TypedData,\n): ResultAsync<string, SigningError> {\n return ResultAsync.fromPromise(\n privy.walletApi.ethereum.signTypedData({\n walletId,\n typedData: {\n domain: data.domain,\n types: data.types,\n message: data.message,\n primaryType: data.primaryType,\n },\n }),\n (err) => SigningError.from(err),\n ).map((response) => response.signature);\n}\n\n/**\n * Creates a function that signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.\n *\n * @param privy - The Privy client instance.\n * @param walletId - The wallet ID 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(privy, walletId));\n * ```\n */\nexport function signTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n): TypedDataHandler;\n\n/**\n * Signs EIP-712 typed data (ERC-20 permits, swap intents, etc.) using the specified Privy wallet.\n *\n * @param privy - The Privy client instance.\n * @param walletId - The wallet ID 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(privy, walletId, typedData);\n * ```\n */\nexport function signTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n data: TypedData,\n): ReturnType<TypedDataHandler>;\n\nexport function signTypedDataWith(\n privy: PrivyClient,\n walletId: string,\n data?: TypedData,\n): TypedDataHandler | ReturnType<TypedDataHandler> {\n if (data === undefined) {\n return (typedData: TypedData) =>\n signTypedData(privy, walletId, typedData).map(signatureFrom);\n }\n return signTypedData(privy, walletId, data).map(signatureFrom);\n}\n"]}
|