diff --git a/package.json b/package.json index 9854270..f69d30e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gelatonetwork/relay-sdk", - "version": "5.2.0", + "version": "5.3.0", "description": "SDK to integrate with Gelato Relay", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/index.ts b/src/index.ts index d057025..badac14 100644 --- a/src/index.ts +++ b/src/index.ts @@ -95,19 +95,22 @@ export class GelatoRelay { /** * @param {CallWithSyncFeeRequest} request - CallWithSyncFee request to be relayed by Gelato Executors * @param {RelayRequestOptions} [options] - Optional Relay configuration + * @param {string} [sponsorApiKey] Optional Sponsor API key to be used for the call * @returns {Promise} Response object with taskId parameter * */ callWithSyncFee = ( request: CallWithSyncFeeRequest, - options?: RelayRequestOptions + options?: RelayRequestOptions, + sponsorApiKey?: string ): Promise => - library.relayWithSyncFee({ request, options }, this.#config); + library.relayWithSyncFee({ request, sponsorApiKey, options }, this.#config); /** * @param {CallWithSyncFeeERC2771Request | CallWithSyncFeeConcurrentERC2771Request} request - Call with sync fee: Sequential ERC2771 or Concurrent ERC2771 request to be relayed by Gelato Executors * @param {ethers.BrowserProvider | ethers.Wallet} walletOrProvider - BrowserProvider [front-end] or Wallet [back-end] to sign the payload * @param {RelayRequestOptions} [options] - Optional Relay configuration + * @param {string} [sponsorApiKey] Optional Sponsor API key to be used for the call * @returns {Promise} Response object with taskId parameter * */ @@ -116,12 +119,14 @@ export class GelatoRelay { | CallWithSyncFeeERC2771Request | CallWithSyncFeeConcurrentERC2771Request, walletOrProvider: ethers.BrowserProvider | ethers.Wallet, - options?: RelayRequestOptions + options?: RelayRequestOptions, + sponsorApiKey?: string ): Promise => library.relayWithCallWithSyncFeeERC2771( { request, walletOrProvider, + sponsorApiKey, options, }, this.#config @@ -231,6 +236,7 @@ export class GelatoRelay { * @param {BaseCallWithSyncFeeParams} syncFeeParams - Call with Sync Fee parameters * @param {SignatureData["signature"]} signature - Signature that can be obtained from getSignatureDataERC2771 * @param {RelayRequestOptions} [options] - Optional Relay configuration + * @param {string} [sponsorApiKey] Optional Sponsor API key to be used for the call * @returns {Promise} Response object with taskId parameter * */ @@ -238,7 +244,8 @@ export class GelatoRelay { struct: SignatureData["struct"], syncFeeParams: BaseCallWithSyncFeeParams, signature: SignatureData["signature"], - options?: RelayRequestOptions + options?: RelayRequestOptions, + sponsorApiKey?: string ): Promise => library.callWithSyncFeeERC2771WithSignature( { @@ -246,6 +253,7 @@ export class GelatoRelay { syncFeeParams, signature, options, + sponsorApiKey, }, this.#config ); diff --git a/src/lib/callWithSyncFee/index.ts b/src/lib/callWithSyncFee/index.ts index 969b91b..c951457 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: 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 >( { @@ -34,8 +39,10 @@ export const relayWithSyncFee = async ( request: { ...request, isRelayContext: request.isRelayContext ?? true, - ...options, + sponsorApiKey, chainId: request.chainId.toString(), + gasLimit: options?.gasLimit ? options.gasLimit.toString() : undefined, + retries: options?.retries, }, }, config diff --git a/src/lib/erc2771/callWithSyncFeeERC2771/index.ts b/src/lib/erc2771/callWithSyncFeeERC2771/index.ts index 873a928..49f46c2 100644 --- a/src/lib/erc2771/callWithSyncFeeERC2771/index.ts +++ b/src/lib/erc2771/callWithSyncFeeERC2771/index.ts @@ -2,9 +2,11 @@ import { ethers } from "ethers"; import { post } from "../../../utils"; import { + ApiKey, BaseCallWithSyncFeeParams, ConcurrencyOptions, Config, + Optional, RelayCall, RelayRequestOptions, RelayResponse, @@ -26,12 +28,13 @@ export const relayWithCallWithSyncFeeERC2771 = async ( | CallWithSyncFeeERC2771Request | CallWithSyncFeeConcurrentERC2771Request; walletOrProvider: ethers.BrowserProvider | 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`); } @@ -51,6 +54,7 @@ export const relayWithCallWithSyncFeeERC2771 = async ( BaseCallWithSyncFeeParams & RelayRequestOptions & UserAuthSignature & + Optional & ConcurrencyOptions, RelayResponse >( @@ -58,11 +62,15 @@ export const relayWithCallWithSyncFeeERC2771 = async ( relayCall: RelayCall.CallWithSyncFeeERC2771, request: { ...safeTransformStruct(struct), - ...options, feeToken, isRelayContext: isRelayContext ?? true, userSignature: signature, isConcurrent, + sponsorApiKey, + gasLimit: options?.gasLimit + ? options.gasLimit.toString() + : undefined, + retries: options?.retries, }, }, config @@ -82,6 +90,7 @@ export const relayWithCallWithSyncFeeERC2771 = async ( BaseCallWithSyncFeeParams & RelayRequestOptions & UserAuthSignature & + Optional & ConcurrencyOptions, RelayResponse >( @@ -89,11 +98,15 @@ export const relayWithCallWithSyncFeeERC2771 = async ( relayCall: RelayCall.CallWithSyncFeeERC2771, request: { ...safeTransformStruct(struct), - ...options, feeToken, isRelayContext: isRelayContext ?? true, userSignature: signature, isConcurrent, + sponsorApiKey, + gasLimit: options?.gasLimit + ? options.gasLimit.toString() + : undefined, + retries: options?.retries, }, }, config diff --git a/src/lib/erc2771/callWithSyncFeeERC2771WithSignature/index.ts b/src/lib/erc2771/callWithSyncFeeERC2771WithSignature/index.ts index cfe39a8..c21989e 100644 --- a/src/lib/erc2771/callWithSyncFeeERC2771WithSignature/index.ts +++ b/src/lib/erc2771/callWithSyncFeeERC2771WithSignature/index.ts @@ -1,9 +1,11 @@ import { isConcurrentStruct, post } from "../../../utils"; import { isNetworkSupported } from "../../network"; import { + ApiKey, BaseCallWithSyncFeeParams, ConcurrencyOptions, Config, + Optional, RelayCall, RelayRequestOptions, RelayResponse, @@ -21,11 +23,13 @@ export const callWithSyncFeeERC2771WithSignature = async ( syncFeeParams: BaseCallWithSyncFeeParams; signature: string; options?: RelayRequestOptions; + sponsorApiKey?: string; }, config: Config ): Promise => { try { - const { signature, struct, syncFeeParams, options } = payload; + const { signature, struct, syncFeeParams, options, sponsorApiKey } = + payload; const isSupported = await isNetworkSupported( { chainId: struct.chainId }, @@ -42,6 +46,7 @@ export const callWithSyncFeeERC2771WithSignature = async ( BaseCallWithSyncFeeParams & RelayRequestOptions & UserAuthSignature & + Optional & ConcurrencyOptions, RelayResponse >( @@ -50,10 +55,14 @@ export const callWithSyncFeeERC2771WithSignature = async ( request: { ...safeTransformStruct(struct), ...syncFeeParams, - ...options, isRelayContext: syncFeeParams.isRelayContext ?? true, userSignature: signature, isConcurrent, + sponsorApiKey, + gasLimit: options?.gasLimit + ? options.gasLimit.toString() + : undefined, + retries: options?.retries, }, }, config @@ -65,6 +74,7 @@ export const callWithSyncFeeERC2771WithSignature = async ( BaseCallWithSyncFeeParams & RelayRequestOptions & UserAuthSignature & + Optional & ConcurrencyOptions, RelayResponse >( @@ -73,10 +83,14 @@ export const callWithSyncFeeERC2771WithSignature = async ( request: { ...safeTransformStruct(struct), ...syncFeeParams, - ...options, isRelayContext: syncFeeParams.isRelayContext ?? true, userSignature: signature, isConcurrent, + sponsorApiKey, + gasLimit: options?.gasLimit + ? options.gasLimit.toString() + : undefined, + retries: options?.retries, }, }, config diff --git a/src/lib/erc2771/sponsoredCallERC2771/index.ts b/src/lib/erc2771/sponsoredCallERC2771/index.ts index 3902ca0..6fff669 100644 --- a/src/lib/erc2771/sponsoredCallERC2771/index.ts +++ b/src/lib/erc2771/sponsoredCallERC2771/index.ts @@ -72,10 +72,13 @@ const sponsoredCallERC2771 = async ( relayCall: RelayCall.SponsoredCallERC2771, request: { ...safeTransformStruct(struct), - ...options, userSignature: signature, sponsorApiKey, isConcurrent, + gasLimit: options?.gasLimit + ? options.gasLimit.toString() + : undefined, + retries: options?.retries, }, }, config @@ -105,10 +108,13 @@ const sponsoredCallERC2771 = async ( relayCall: RelayCall.SponsoredCallERC2771, request: { ...safeTransformStruct(struct), - ...options, userSignature: signature, sponsorApiKey, isConcurrent, + gasLimit: options?.gasLimit + ? options.gasLimit.toString() + : undefined, + retries: options?.retries, }, }, config diff --git a/src/lib/erc2771/sponsoredCallERC2771WithSignature/index.ts b/src/lib/erc2771/sponsoredCallERC2771WithSignature/index.ts index 874b572..35b4fb1 100644 --- a/src/lib/erc2771/sponsoredCallERC2771WithSignature/index.ts +++ b/src/lib/erc2771/sponsoredCallERC2771WithSignature/index.ts @@ -49,10 +49,13 @@ export const sponsoredCallERC2771WithSignature = async ( relayCall: RelayCall.SponsoredCallERC2771, request: { ...safeTransformStruct(struct), - ...options, userSignature: signature, sponsorApiKey, isConcurrent, + gasLimit: options?.gasLimit + ? options.gasLimit.toString() + : undefined, + retries: options?.retries, }, }, config @@ -71,10 +74,13 @@ export const sponsoredCallERC2771WithSignature = async ( relayCall: RelayCall.SponsoredCallERC2771, request: { ...safeTransformStruct(struct), - ...options, userSignature: signature, sponsorApiKey, isConcurrent, + gasLimit: options?.gasLimit + ? options.gasLimit.toString() + : undefined, + retries: options?.retries, }, }, config diff --git a/src/lib/sponsoredCall/index.ts b/src/lib/sponsoredCall/index.ts index a447f5e..9299ccf 100644 --- a/src/lib/sponsoredCall/index.ts +++ b/src/lib/sponsoredCall/index.ts @@ -61,8 +61,9 @@ const sponsoredCall = async ( relayCall: RelayCall.SponsoredCall, request: { ...struct, - ...options, sponsorApiKey, + gasLimit: options?.gasLimit ? options.gasLimit.toString() : undefined, + retries: options?.retries, }, }, config diff --git a/src/lib/types/index.ts b/src/lib/types/index.ts index 57c7f13..268aa08 100644 --- a/src/lib/types/index.ts +++ b/src/lib/types/index.ts @@ -68,5 +68,11 @@ export type Config = { }; export type SafeRequestPayload = { - [K in keyof T]: T[K] extends bigint ? string : T[K]; + [K in keyof T]: T[K] extends bigint + ? string + : T[K] extends bigint | undefined + ? string | undefined + : T[K] extends object + ? SafeRequestPayload + : T[K]; };