Skip to content

Commit

Permalink
Merge pull request #1 from gelatodigital/feat/GN-4796-Relay-SDK-Viem-…
Browse files Browse the repository at this point in the history
…Support

Feat/gn 4796 relay sdk viem support
  • Loading branch information
opatavi authored Apr 14, 2024
2 parents 398d2e0 + acd22b1 commit 85e14d6
Show file tree
Hide file tree
Showing 30 changed files with 5,884 additions and 2,520 deletions.
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "public",
"baseBranch": "master",
"updateInternalDependencies": "patch",
"ignore": []
}
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ test/contracts/types
src/logs/

# yarn
yarn-error.log
yarn-error.log

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
893 changes: 893 additions & 0 deletions .yarn/releases/yarn-4.1.1.cjs

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.1.1.cjs
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# @gelatonetwork/relay-sdk-viem

## 1.0.1

### Patch Changes

- Viem Support
- Viem support
- Viem Support
- Viem Support

## 1.0.1-next.2

### Patch Changes

- Viem Support

## 1.0.1-next.1

### Patch Changes

- Viem Support

## 1.0.1-next.0

### Patch Changes

- Viem support
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gelatonetwork/relay-sdk",
"version": "5.5.5",
"description": "SDK to integrate with Gelato Relay",
"name": "@gelatonetwork/relay-sdk-viem",
"version": "1.0.1",
"description": "SDK to integrate with Gelato Relay with viem",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -38,13 +38,15 @@
"typescript": "5.0.4"
},
"dependencies": {
"@changesets/cli": "^2.27.1",
"axios": "0.27.2",
"ethers": "6.7.0",
"isomorphic-ws": "^5.0.0",
"viem": "2.9.15",
"ws": "^8.5.0"
},
"lint-staged": {
"*.{js,json,md,ts}": "yarn format",
"*.{ts,js}": "yarn lint"
}
},
"packageManager": "[email protected]"
}
34 changes: 14 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
Config,
RelayRequestOptions,
RelayResponse,
SignerOrProvider,
PublicOrWalletClient,
} from "./lib/types";
import {
GELATO_RELAY_1BALANCE_ERC2771_ADDRESS,
Expand Down Expand Up @@ -46,7 +46,7 @@ export {
CallWithSyncFeeConcurrentERC2771Request,
CallWithConcurrentERC2771Request,
Config,
SignerOrProvider,
PublicOrWalletClient,
TaskState,
};

Expand Down Expand Up @@ -125,7 +125,7 @@ export class GelatoRelay {

/**
* @param {CallWithSyncFeeERC2771Request | CallWithSyncFeeConcurrentERC2771Request} request - Call with sync fee: Sequential ERC2771 or Concurrent ERC2771 request to be relayed by Gelato Executors
* @param {SignerOrProvider} signerOrProvider - BrowserProvider [front-end] or Signer [back-end] to sign the payload
* @param {PublicOrWalletClient} client - Public or Wallet Client
* @param {RelayRequestOptions} [options] - Optional Relay configuration
* @param {string} [sponsorApiKey] Optional Sponsor API key to be used for the call
* @returns {Promise<RelayResponse>} Response object with taskId parameter
Expand All @@ -135,14 +135,14 @@ export class GelatoRelay {
request:
| CallWithSyncFeeERC2771Request
| CallWithSyncFeeConcurrentERC2771Request,
signerOrProvider: SignerOrProvider,
client: PublicOrWalletClient,
options?: RelayRequestOptions,
sponsorApiKey?: string
): Promise<RelayResponse> => {
const response = await library.relayWithCallWithSyncFeeERC2771(
{
request,
signerOrProvider,
client,
sponsorApiKey,
options,
},
Expand Down Expand Up @@ -182,22 +182,22 @@ export class GelatoRelay {

/**
* @param {CallWithERC2771Request | CallWithConcurrentERC2771Request} request - Sponsored: Sequential ERC2771 or Concurrent ERC2771 request to be relayed by Gelato Executors
* @param {SignerOrProvider} signerOrProvider - BrowserProvider [front-end] or Signer [back-end] to sign the payload
* @param {PublicOrWalletClient} client - Public or Wallet Client
* @param {string} sponsorApiKey - Sponsor API key
* @param {RelayRequestOptions} [options] - Optional Relay configuration
* @returns {Promise<RelayResponse>} Response object with taskId parameter
*
*/
sponsoredCallERC2771 = async (
request: CallWithERC2771Request | CallWithConcurrentERC2771Request,
signerOrProvider: SignerOrProvider,
client: PublicOrWalletClient,
sponsorApiKey: string,
options?: RelayRequestOptions
): Promise<RelayResponse> => {
const response = await library.relayWithSponsoredCallERC2771(
{
request,
signerOrProvider,
client,
sponsorApiKey,
options,
},
Expand All @@ -213,37 +213,31 @@ export class GelatoRelay {

/**
* @param {CallWithERC2771Request | CallWithConcurrentERC2771Request} request - Sequential ERC2771 or Concurrent ERC2771 request to be relayed by Gelato Executors
* @param {SignerOrProvider} signerOrProvider - BrowserProvider [front-end] or Signer [back-end] to sign the payload
* @param {PublicOrWalletClient} client - Public or Wallet Client
* @param {ERC2771Type} type - ERC2771Type.CallWithSyncFee or ERC2771Type.SponsoredCall
* @returns {Promise<SignatureData>} Response object with struct and signature
*
*/
getSignatureDataERC2771 = (
request: CallWithERC2771Request | CallWithConcurrentERC2771Request,
signerOrProvider: SignerOrProvider,
client: PublicOrWalletClient,
type: ERC2771Type
): Promise<SignatureData> =>
library.getSignatureDataERC2771(
{ request, signerOrProvider, type },
this.#config
);
library.getSignatureDataERC2771({ request, client, type }, this.#config);

/**
* @param {CallWithERC2771Request | CallWithConcurrentERC2771Request} request - Sequential ERC2771 or Concurrent ERC2771 request to be relayed by Gelato Executors
* @param {SignerOrProvider} [signerOrProvider] - Optional BrowserProvider [front-end] or Signer [back-end] to sign the payload
* @param {PublicOrWalletClient} [client] - Optional Public or Wallet Client
* @param {ERC2771Type} type - ERC2771Type.CallWithSyncFee or ERC2771Type.SponsoredCall
* @returns {Promise<PayloadToSign>} Response object with struct and typed data
*
*/
getDataToSignERC2771 = (
request: CallWithERC2771Request | CallWithConcurrentERC2771Request,
type: ERC2771Type,
signerOrProvider?: SignerOrProvider
client?: PublicOrWalletClient
): Promise<PayloadToSign> =>
library.getDataToSignERC2771(
{ request, signerOrProvider, type },
this.#config
);
library.getDataToSignERC2771({ request, client, type }, this.#config);

/**
* @param {SignatureData["struct"]} struct - Struct that can be obtained from getSignatureDataERC2771
Expand Down
10 changes: 5 additions & 5 deletions src/lib/erc2771/callWithSyncFeeERC2771/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
RelayCall,
RelayRequestOptions,
RelayResponse,
SignerOrProvider,
PublicOrWalletClient,
} from "../../types";
import {
CallWithConcurrentERC2771Struct,
Expand All @@ -26,22 +26,22 @@ export const relayWithCallWithSyncFeeERC2771 = async (
request:
| CallWithSyncFeeERC2771Request
| CallWithSyncFeeConcurrentERC2771Request;
signerOrProvider: SignerOrProvider;
client: PublicOrWalletClient;
sponsorApiKey?: string;
options?: RelayRequestOptions;
},
config: Config
): Promise<RelayResponse> => {
try {
const { request, signerOrProvider, options, sponsorApiKey } = payload;
const { request, client, options, sponsorApiKey } = payload;

if (request.isConcurrent) {
const isConcurrent = true;
const { isRelayContext, feeToken } = request;
const type = ERC2771Type.ConcurrentCallWithSyncFee;

const { struct, signature } = await getSignatureDataERC2771(
{ request, signerOrProvider, type },
{ request, client, type },
config
);

Expand Down Expand Up @@ -77,7 +77,7 @@ export const relayWithCallWithSyncFeeERC2771 = async (
const type = ERC2771Type.CallWithSyncFee;

const { struct, signature } = await getSignatureDataERC2771(
{ request, signerOrProvider, type },
{ request, client, type },
config
);

Expand Down
16 changes: 8 additions & 8 deletions src/lib/erc2771/getDataToSignERC2771/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isConcurrentRequest } from "../../../utils";
import { isNetworkSupported } from "../../network";
import { Config, SignerOrProvider } from "../../types";
import { Config, PublicOrWalletClient } from "../../types";
import {
CallWithERC2771Request,
ERC2771Type,
Expand All @@ -15,7 +15,7 @@ export async function getDataToSignERC2771(
payload: {
request: CallWithERC2771Request;
type: ERC2771Type.CallWithSyncFee | ERC2771Type.SponsoredCall;
signerOrProvider?: SignerOrProvider;
client?: PublicOrWalletClient;
},
config: Config
): Promise<SequentialPayloadToSign>;
Expand All @@ -26,7 +26,7 @@ export async function getDataToSignERC2771(
type:
| ERC2771Type.ConcurrentCallWithSyncFee
| ERC2771Type.ConcurrentSponsoredCall;
signerOrProvider?: SignerOrProvider;
client?: PublicOrWalletClient;
},
config: Config
): Promise<ConcurrentPayloadToSign>;
Expand All @@ -35,7 +35,7 @@ export async function getDataToSignERC2771(
payload: {
request: CallWithERC2771Request | CallWithConcurrentERC2771Request;
type: ERC2771Type;
signerOrProvider?: SignerOrProvider;
client?: PublicOrWalletClient;
},
config: Config
): Promise<PayloadToSign>;
Expand All @@ -44,12 +44,12 @@ export async function getDataToSignERC2771(
payload: {
request: CallWithERC2771Request | CallWithConcurrentERC2771Request;
type: ERC2771Type;
signerOrProvider?: SignerOrProvider;
client?: PublicOrWalletClient;
},
config: Config
): Promise<PayloadToSign> {
try {
const { request, signerOrProvider } = payload;
const { request, client } = payload;

const { chainId } = request;
const isSupported = await isNetworkSupported({ chainId }, config);
Expand All @@ -66,7 +66,7 @@ export async function getDataToSignERC2771(
{
request,
type,
signerOrProvider,
client,
},
config
);
Expand All @@ -81,7 +81,7 @@ export async function getDataToSignERC2771(
| ERC2771Type.SponsoredCall;

const { struct, typedData } = await populatePayloadToSign(
{ request, type, signerOrProvider },
{ request, type, client },
config
);

Expand Down
Loading

0 comments on commit 85e14d6

Please sign in to comment.