Skip to content

Commit

Permalink
feat: optional sponsor api key for callWithSyncFee(ERC2771)
Browse files Browse the repository at this point in the history
  • Loading branch information
opatavi committed Apr 4, 2023
1 parent ceef383 commit ab88477
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,37 @@ 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<RelayResponse>} Response object with taskId parameter
*
*/
callWithSyncFee = (
request: CallWithSyncFeeRequest,
sponsorApiKey?: string,
options?: RelayRequestOptions
): Promise<RelayResponse> =>
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<RelayResponse>} Response object with taskId parameter
*
*/
callWithSyncFeeERC2771 = (
request: CallWithSyncFeeERC2771Request,
walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet,
sponsorApiKey?: string,
options?: RelayRequestOptions
): Promise<RelayResponse> =>
library.relayWithCallWithSyncFeeERC2771(
{
request,
walletOrProvider,
sponsorApiKey,
options,
},
this.#config
Expand Down
10 changes: 8 additions & 2 deletions src/lib/callWithSyncFee/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { getHttpErrorMessage, post } from "../../utils";
import { isNetworkSupported } from "../network";
import {
ApiKey,
Config,
Optional,
RelayCall,
RelayRequestOptions,
RelayResponse,
Expand All @@ -12,12 +14,13 @@ import { CallWithSyncFeeRequest } from "./types";
export const relayWithSyncFee = async (
payload: {
request: CallWithSyncFeeRequest;
sponsorApiKey?: string;
options?: RelayRequestOptions;
},
config: Config
): Promise<RelayResponse> => {
try {
const { request, options } = payload;
const { request, options, sponsorApiKey } = payload;
const isSupported = await isNetworkSupported(
{ chainId: Number(request.chainId) },
config
Expand All @@ -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<ApiKey, "sponsorApiKey">,
RelayResponse
>(
{
Expand All @@ -35,6 +40,7 @@ export const relayWithSyncFee = async (
...request,
isRelayContext: request.isRelayContext ?? true,
...options,
sponsorApiKey,
},
},
config
Expand Down
9 changes: 7 additions & 2 deletions src/lib/erc2771/callWithSyncFeeERC2771/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
} from "../../../utils";
import { isNetworkSupported } from "../../network";
import {
ApiKey,
BaseCallWithSyncFeeParams,
Config,
Optional,
RelayCall,
RelayRequestOptions,
RelayResponse,
Expand All @@ -28,12 +30,13 @@ export const relayWithCallWithSyncFeeERC2771 = async (
payload: {
request: CallWithSyncFeeERC2771Request;
walletOrProvider: ethers.providers.Web3Provider | ethers.Wallet;
sponsorApiKey?: string;
options?: RelayRequestOptions;
},
config: Config
): Promise<RelayResponse> => {
try {
const { request, walletOrProvider, options } = payload;
const { request, walletOrProvider, options, sponsorApiKey } = payload;
if (!walletOrProvider.provider) {
throw new Error(`Missing provider`);
}
Expand Down Expand Up @@ -70,7 +73,8 @@ export const relayWithCallWithSyncFeeERC2771 = async (
CallWithERC2771Struct &
BaseCallWithSyncFeeParams &
RelayRequestOptions &
UserAuthSignature,
UserAuthSignature &
Optional<ApiKey, "sponsorApiKey">,
RelayResponse
>(
{
Expand All @@ -81,6 +85,7 @@ export const relayWithCallWithSyncFeeERC2771 = async (
feeToken,
isRelayContext: isRelayContext ?? true,
userSignature: signature,
sponsorApiKey,
},
},
config
Expand Down

0 comments on commit ab88477

Please sign in to comment.