Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fetch automate from w3f api #99

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { AutomateSDK } from "@gelatonetwork/automate-sdk";
```typescript
import { isAutomateSupported } from "@gelatonetwork/automate-sdk";

if (!isAutomateSupported(chainId)) {
if (!(await isAutomateSupported(chainId))) {
console.log(`Automate network not supported (${chainId})`);
return;
}
Expand All @@ -40,7 +40,7 @@ if (!isAutomateSupported(chainId)) {
3. Instantiate Automate using your signer:

```typescript
const automate = new AutomateSDK(chainId, signer);
const automate = await AutomateSDK.create(chainId, signer);
goums marked this conversation as resolved.
Show resolved Hide resolved
```

4. Create an automation task:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gelatonetwork/automate-sdk",
"version": "3.0.19",
"version": "4.0.0",
"description": "SDK to create Automate tasks",
"url": "https://github.com/gelatodigital/automate-sdk",
"main": "dist/index.js",
Expand Down
209 changes: 3 additions & 206 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { GelatoAddressBook } from "../types";

export const W3F_API_ENDPOINT = "https://api.gelato.digital/w3f/networks";
goums marked this conversation as resolved.
Show resolved Hide resolved
export const W3F_API_ENDPOINT_DEV =
"https://api.dev.gelato.digital/w3f/networks";
export const AUTOMATE_USER_API = "https://api.gelato.digital/automate/users";
export const AUTOMATE_TASKS_API = "https://api.gelato.digital/automate/tasks";
export const AUTOMATE_USER_DEV_API =
Expand All @@ -10,208 +12,3 @@ export const AUTOMATE_TASKS_DEV_API =

export const ETH = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
export const ZERO_ADD = "0x0000000000000000000000000000000000000000";

export const CHAIN_ID = {
MAINNET: 1,
GOERLI: 5,
OPTIMISM: 10,
CRONOS: 25,
OPTIMISTIC_GOERLI: 420,
BSC: 56,
GNOSIS: 100,
POLYGON: 137,
FANTOM: 250,
MOONBEAM: 1284,
MOONRIVER: 1285,
ARBITRUM: 42161,
AVALANCHE: 43114,
MUMBAI: 80001,
ZKSYNC: 324,
LINEA: 59144,
BASE: 8453,
POLYGONZK: 1101,
ZKATANA: 1261120,
SEPOLIA: 11155111,
UNREAL: 18233,
OSEPOLIA: 11155420,
ARBSEPOLIA: 421614,
GELOPCELESTIATESTNET: 123420111,
BASESEPOLIA: 84532,
METIS: 1088,
LISKSEPOLIA: 4202,
BLASTSEPOLIA: 168587773,
MODE: 34443,
ASTARZKEVM: 3776,
ASTARZKYOTO: 6038361,
BLAST: 81457,
GELATOORBITTESTNET: 88153591557,
REYACRONOS: 89346162,
REYA: 1729,
PLAYBLOCK: 1829,
BLACKBERRY: 94_204_209,
AMOY: 80002,
REAL: 111188,
CONNEXTSEPOLIA: 6398,
ANOMALY_ANDROMEDA: 241120,
ALEPHZEROTESTNET: 2039,
LISK: 1135,
COREDAO: 1116,
ROOTSTOCK: 30,
NOVASTROTESTNET: 560098,
OPENCAMPUSCODEX: 656476,
CAMPNETWORKTESTNET: 325000,
RIDOTTOTETROMINO: 4444,
};

export const GELATO_ADDRESSES: GelatoAddressBook = {
[CHAIN_ID.MAINNET]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.GOERLI]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.OPTIMISTIC_GOERLI]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.POLYGON]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.MUMBAI]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
automateDev: "0xC97aBa1B6cf4d8aCa19dFba68e99befaDA9aeFE3",
},
[CHAIN_ID.FANTOM]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.ARBITRUM]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.AVALANCHE]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.BASE]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.BSC]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.GNOSIS]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.OPTIMISM]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.POLYGONZK]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.MOONBEAM]: {
automate: "",
},
[CHAIN_ID.MOONRIVER]: {
automate: "",
},
[CHAIN_ID.CRONOS]: {
automate: "",
},
[CHAIN_ID.ZKSYNC]: {
automate: "0xF27e0dfD58B423b1e1B90a554001d0561917602F",
},
[CHAIN_ID.LINEA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.ZKATANA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.SEPOLIA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.UNREAL]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.OSEPOLIA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.ARBSEPOLIA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.GELOPCELESTIATESTNET]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.BASESEPOLIA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.METIS]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.LISKSEPOLIA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.BLASTSEPOLIA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.MODE]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.ASTARZKEVM]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.ASTARZKYOTO]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.BLAST]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.GELATOORBITTESTNET]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
automateDev: "0xd84ED255d7ee2B032f66AeCfB41b51044d409aDC",
},
[CHAIN_ID.REYACRONOS]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.REYA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.PLAYBLOCK]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.BLACKBERRY]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.AMOY]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
automateDev: "0xd84ED255d7ee2B032f66AeCfB41b51044d409aDC",
},
[CHAIN_ID.REAL]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.CONNEXTSEPOLIA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.ANOMALY_ANDROMEDA]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.ALEPHZEROTESTNET]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.LISK]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.COREDAO]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.ROOTSTOCK]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.NOVASTROTESTNET]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.OPENCAMPUSCODEX]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.CAMPNETWORKTESTNET]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
[CHAIN_ID.RIDOTTOTETROMINO]: {
automate: "0x2A6C106ae13B558BB9E2Ec64Bd2f1f7BEFF3A5E0",
},
};
2 changes: 1 addition & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const main = async () => {
const provider = new ethers.providers.JsonRpcProvider(providerUrl);

const wallet = new ethers.Wallet(pk as string, provider);
const sdk = new AutomateSDK(chainId, wallet);
const sdk = await AutomateSDK.create(chainId, wallet);

const { taskId, tx } = await sdk.createTask({
name: "AutomateSdkTest",
Expand Down
67 changes: 36 additions & 31 deletions src/lib/AutomateSDK.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
AUTOMATE_TASKS_API,
AUTOMATE_TASKS_DEV_API,
ETH,
GELATO_ADDRESSES,
ZERO_ADD,
} from "../constants";
import {
Expand All @@ -37,11 +36,7 @@ import {
TaskTransaction,
} from "../types";
import { Module, ModuleData } from "../types/Module.interface";
import {
errorMessage,
isAutomateDevSupported,
isAutomateSupported,
} from "../utils";
import { errorMessage, w3fApi } from "../utils";
import { AutomateModule } from "./AutomateModule";
import { Signature } from "./Signature";

Expand All @@ -54,50 +49,60 @@ export class AutomateSDK {
private readonly _taskApi: Axios;
private readonly _signature: Signature;

constructor(
private constructor(
chainId: number,
signer: Signer,
automate: Automate,
taskApi: Axios,
signature: Signature,
) {
this._automateModule = new AutomateModule();
this._chainId = chainId;
this._signer = signer;
this._automate = automate;
this._taskApi = taskApi;
this._signature = signature;
}

public static async create(
chainId: number,
signer: Signer,
signatureMessage?: string,
config?: Partial<Config>,
) {
let automateAddress: string;
if (config && config.isDevelopment) {
if (!isAutomateDevSupported(chainId)) {
): Promise<AutomateSDK> {
const network = await w3fApi.getNetwork(chainId, config?.isDevelopment);
if (!network) {
if (config?.isDevelopment) {
throw new Error(`AutomateDev is not available on chainId:${chainId}`);
}

automateAddress = GELATO_ADDRESSES[chainId].automateDev!;
} else {
if (!isAutomateSupported(chainId)) {
} else {
throw new Error(`Automate is not available on chainId:${chainId}`);
}

automateAddress = GELATO_ADDRESSES[chainId].automate;
}

const automateAddress = network.automate;

if (!Signer.isSigner(signer)) {
throw new Error(`Invalid Automate signer`);
}

this._automateModule = new AutomateModule();
this._signature = new Signature(
const automate = Automate__factory.connect(automateAddress, signer);

let taskApiUrl: string = AUTOMATE_TASKS_API;
if (config) {
taskApiUrl =
config.taskApi ??
(config.isDevelopment ? AUTOMATE_TASKS_DEV_API : AUTOMATE_TASKS_API);
}
const taskApi = axios.create({ baseURL: taskApiUrl });

const signature = new Signature(
chainId,
signer,
signatureMessage,
config?.signatureDomain,
);
this._chainId = chainId;
this._signer = signer;
this._automate = Automate__factory.connect(automateAddress, this._signer);

let taskApiUrl: string = AUTOMATE_TASKS_API;
if (config) {
taskApiUrl =
config.taskApi ?? config.isDevelopment
? AUTOMATE_TASKS_DEV_API
: AUTOMATE_TASKS_API;
}
this._taskApi = axios.create({ baseURL: taskApiUrl });
return new AutomateSDK(chainId, signer, automate, taskApi, signature);
}

public async getActiveTasks(creatorAddress?: string): Promise<Task[]> {
Expand Down
4 changes: 4 additions & 0 deletions src/types/W3fNetworks.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface W3fNetwork {
automate: string;
}
export type W3fNetworks = Record<number, W3fNetwork>;
Loading