From ab884773e13ac2cc201fdb47af04be2cdcdb5cd8 Mon Sep 17 00:00:00 2001 From: opatavi Date: Tue, 4 Apr 2023 13:28:44 +0300 Subject: [PATCH] feat: optional sponsor api key for callWithSyncFee(ERC2771) --- src/index.ts | 7 ++++++- src/lib/callWithSyncFee/index.ts | 10 ++++++++-- src/lib/erc2771/callWithSyncFeeERC2771/index.ts | 9 +++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/index.ts b/src/index.ts index eabd418..fd1bb3b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,19 +57,22 @@ export class GelatoRelay { /** * @param {CallWithSyncFeeRequest} request - CallWithSyncFee request to be relayed by Gelato Executors + * @param {string} [sponsorApiKey] Optional Sponsor API key to be used for the call * @param {RelayRequestOptions} [options] - Optional Relay configuration * @returns {Promise} Response object with taskId parameter * */ callWithSyncFee = ( request: CallWithSyncFeeRequest, + sponsorApiKey?: string, options?: RelayRequestOptions ): Promise => - library.relayWithSyncFee({ request, options }, this.#config); + library.relayWithSyncFee({ request, sponsorApiKey, options }, this.#config); /** * @param {CallWithSyncFeeERC2771Request} request - CallWithSyncFeeERC2771 request to be relayed by Gelato Executors * @param {ethers.providers.Web3Provider | ethers.Wallet} walletOrProvider - Web3Provider [front-end] or Wallet [back-end] to sign the payload + * @param {string} [sponsorApiKey] Optional Sponsor API key to be used for the call * @param {RelayRequestOptions} [options] - Optional Relay configuration * @returns {Promise} Response object with taskId parameter * @@ -77,12 +80,14 @@ export class GelatoRelay { callWithSyncFeeERC2771 = ( request: CallWithSyncFeeERC2771Request, walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet, + sponsorApiKey?: string, options?: RelayRequestOptions ): Promise => library.relayWithCallWithSyncFeeERC2771( { request, walletOrProvider, + sponsorApiKey, options, }, this.#config diff --git a/src/lib/callWithSyncFee/index.ts b/src/lib/callWithSyncFee/index.ts index b614ab0..6922504 100644 --- a/src/lib/callWithSyncFee/index.ts +++ b/src/lib/callWithSyncFee/index.ts @@ -1,7 +1,9 @@ import { getHttpErrorMessage, post } from "../../utils"; import { isNetworkSupported } from "../network"; import { + ApiKey, Config, + Optional, RelayCall, RelayRequestOptions, RelayResponse, @@ -12,12 +14,13 @@ import { CallWithSyncFeeRequest } from "./types"; export const relayWithSyncFee = async ( payload: { request: CallWithSyncFeeRequest; + sponsorApiKey?: string; options?: RelayRequestOptions; }, config: Config ): Promise => { try { - const { request, options } = payload; + const { request, options, sponsorApiKey } = payload; const isSupported = await isNetworkSupported( { chainId: Number(request.chainId) }, config @@ -26,7 +29,9 @@ export const relayWithSyncFee = async ( throw new Error(`Chain id [${request.chainId}] is not supported`); } return await post< - CallWithSyncFeeRequest & RelayRequestOptions, + CallWithSyncFeeRequest & + RelayRequestOptions & + Optional, RelayResponse >( { @@ -35,6 +40,7 @@ export const relayWithSyncFee = async ( ...request, isRelayContext: request.isRelayContext ?? true, ...options, + sponsorApiKey, }, }, config diff --git a/src/lib/erc2771/callWithSyncFeeERC2771/index.ts b/src/lib/erc2771/callWithSyncFeeERC2771/index.ts index 271552a..86be489 100644 --- a/src/lib/erc2771/callWithSyncFeeERC2771/index.ts +++ b/src/lib/erc2771/callWithSyncFeeERC2771/index.ts @@ -8,8 +8,10 @@ import { } from "../../../utils"; import { isNetworkSupported } from "../../network"; import { + ApiKey, BaseCallWithSyncFeeParams, Config, + Optional, RelayCall, RelayRequestOptions, RelayResponse, @@ -28,12 +30,13 @@ export const relayWithCallWithSyncFeeERC2771 = async ( payload: { request: CallWithSyncFeeERC2771Request; walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet; + sponsorApiKey?: string; options?: RelayRequestOptions; }, config: Config ): Promise => { try { - const { request, walletOrProvider, options } = payload; + const { request, walletOrProvider, options, sponsorApiKey } = payload; if (!walletOrProvider.provider) { throw new Error(`Missing provider`); } @@ -70,7 +73,8 @@ export const relayWithCallWithSyncFeeERC2771 = async ( CallWithERC2771Struct & BaseCallWithSyncFeeParams & RelayRequestOptions & - UserAuthSignature, + UserAuthSignature & + Optional, RelayResponse >( { @@ -81,6 +85,7 @@ export const relayWithCallWithSyncFeeERC2771 = async ( feeToken, isRelayContext: isRelayContext ?? true, userSignature: signature, + sponsorApiKey, }, }, config