@show-karma/karma-gap-sdk 0.2.4 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,6 +12,7 @@ export interface AttestationArgs<T = unknown, S extends Schema = Schema> {
12
12
  revoked?: boolean;
13
13
  revocationTime?: Date | number;
14
14
  createdAt?: Date | number;
15
+ chainID?: number;
15
16
  }
16
17
  /**
17
18
  * Represents the EAS Attestation and provides methods to manage attestations.
@@ -54,6 +55,7 @@ export declare class Attestation<T = unknown, S extends Schema = GapSchema> impl
54
55
  readonly revoked?: boolean;
55
56
  readonly revocationTime?: Date;
56
57
  readonly createdAt: Date;
58
+ readonly chainID: number;
57
59
  private _reference?;
58
60
  constructor(args: AttestationArgs<T, S>);
59
61
  /**
@@ -50,6 +50,7 @@ class Attestation {
50
50
  this.revoked = args.revoked;
51
51
  this.revocationTime = (0, get_date_1.getDate)(args.revocationTime);
52
52
  this.createdAt = (0, get_date_1.getDate)(args.createdAt || Date.now() / 1000);
53
+ this.chainID = args.chainID;
53
54
  }
54
55
  /**
55
56
  * Encodes the schema.
@@ -78,6 +78,12 @@ export declare abstract class Fetcher extends AxiosGQL {
78
78
  * @returns
79
79
  */
80
80
  abstract projectBySlug(slug: string): Promise<Project>;
81
+ /**
82
+ * Search projects by name. This method will return a list of projects
83
+ * __Must be implemented by the indexer__
84
+ * @param query
85
+ */
86
+ abstract searchProjects(query: string): Promise<Project[]>;
81
87
  /**
82
88
  * Fetch projects with details and members.
83
89
  * @param name if set, will search by the name.
@@ -204,7 +204,7 @@ export declare class GAP extends Facade {
204
204
  * Get the multicall contract
205
205
  * @param signer
206
206
  */
207
- static getProjectResolver(signer: SignerOrProvider): ethers.Contract;
207
+ static getProjectResolver(signer: SignerOrProvider, chainId?: number): ethers.Contract;
208
208
  get schemas(): GapSchema[];
209
209
  /**
210
210
  * Defined if the transactions will be gasless or not.
package/core/class/GAP.js CHANGED
@@ -14,6 +14,7 @@ const eas_sdk_1 = require("@ethereum-attestation-service/eas-sdk");
14
14
  const consts_1 = require("../consts");
15
15
  const ethers_1 = require("ethers");
16
16
  const package_json_1 = require("../../package.json");
17
+ const get_web3_provider_1 = require("../utils/get-web3-provider");
17
18
  /**
18
19
  * GAP SDK Facade.
19
20
  *
@@ -172,9 +173,10 @@ class GAP extends types_1.Facade {
172
173
  * Get the multicall contract
173
174
  * @param signer
174
175
  */
175
- static getProjectResolver(signer) {
176
+ static getProjectResolver(signer, chainId) {
177
+ const provider = chainId ? (0, get_web3_provider_1.getWeb3Provider)(chainId) : signer;
176
178
  const address = consts_1.Networks[this.client.network].contracts.projectResolver;
177
- return new ethers_1.ethers.Contract(address, ProjectResolver_json_1.default, signer);
179
+ return new ethers_1.ethers.Contract(address, ProjectResolver_json_1.default, provider);
178
180
  }
179
181
  get schemas() {
180
182
  return this._schemas;
@@ -44,6 +44,7 @@ export declare class GapEasClient extends Fetcher {
44
44
  projectById(uid: Hex): Promise<Project>;
45
45
  projectBySlug(slug: string): Promise<Project>;
46
46
  slugExists(slug: string): Promise<boolean>;
47
+ searchProjects(query: string): Promise<Project[]>;
47
48
  projects(name?: string): Promise<Project[]>;
48
49
  projectsOf(grantee: Hex): Promise<Project[]>;
49
50
  grantee(address: Hex): Promise<Grantee>;
@@ -229,6 +229,9 @@ class GapEasClient extends Fetcher_1.Fetcher {
229
229
  const { schema: { attestations }, } = await this.query(query);
230
230
  return attestations.some((a) => a.decodedDataJson.includes(slug));
231
231
  }
232
+ searchProjects(query) {
233
+ throw new Error('Method not implemented.');
234
+ }
232
235
  async projects(name) {
233
236
  const result = await this.attestations('Project', name);
234
237
  if (!result.length)
@@ -65,6 +65,6 @@ export declare class GapContract {
65
65
  * @param projectUID
66
66
  * @returns
67
67
  */
68
- static isProjectOwner(signer: SignerOrProvider, projectUID: Hex): Promise<boolean>;
68
+ static isProjectOwner(signer: SignerOrProvider, projectUID: Hex, projectChainId: number): Promise<boolean>;
69
69
  private static getTransactionLogs;
70
70
  }
@@ -181,8 +181,8 @@ class GapContract {
181
181
  * @param projectUID
182
182
  * @returns
183
183
  */
184
- static async isProjectOwner(signer, projectUID) {
185
- const contract = GAP_1.GAP.getProjectResolver(signer);
184
+ static async isProjectOwner(signer, projectUID, projectChainId) {
185
+ const contract = GAP_1.GAP.getProjectResolver(signer, projectChainId);
186
186
  const address = await this.getSignerAddress(signer);
187
187
  const isOwner = await contract.functions.isAdmin(projectUID, address);
188
188
  return !!isOwner?.[0];
@@ -51,7 +51,7 @@ class Project extends Attestation_1.Attestation {
51
51
  await GapContract_1.GapContract.transferProjectOwnership(signer, this.uid, newOwner);
52
52
  }
53
53
  isOwner(signer) {
54
- return GapContract_1.GapContract.isProjectOwner(signer, this.uid);
54
+ return GapContract_1.GapContract.isProjectOwner(signer, this.uid, this.chainID);
55
55
  }
56
56
  /**
57
57
  * Add new members to the project.
@@ -16,6 +16,7 @@ export declare class GapIndexerClient extends Fetcher {
16
16
  communityById(uid: `0x${string}`): Promise<Community>;
17
17
  projectBySlug(slug: string): Promise<Project>;
18
18
  projectById(uid: `0x${string}`): Promise<Project>;
19
+ searchProjects(query: string): Promise<Project[]>;
19
20
  projects(name?: string): Promise<Project[]>;
20
21
  projectsOf(grantee: `0x${string}`): Promise<Project[]>;
21
22
  grantee(address: `0x${string}`): Promise<Grantee>;
@@ -91,6 +91,14 @@ class GapIndexerClient extends Fetcher_1.Fetcher {
91
91
  projectById(uid) {
92
92
  return this.projectBySlug(uid);
93
93
  }
94
+ async searchProjects(query) {
95
+ const { data } = await this.client.get(Endpoints.project.all(), {
96
+ params: {
97
+ q: query,
98
+ },
99
+ });
100
+ return entities_1.Project.from(data);
101
+ }
94
102
  async projects(name) {
95
103
  const { data } = await this.client.get(Endpoints.project.all(), {
96
104
  params: {
package/core/consts.js CHANGED
@@ -57,6 +57,7 @@ exports.Networks = {
57
57
  optimism: {
58
58
  chainId: 10,
59
59
  url: 'https://optimism.easscan.org/graphql',
60
+ rpcUrl: 'https://opt-mainnet.g.alchemy.com/v2/fx2SlVDrPbXwPMQT4v0lRT1PABA16Myl',
60
61
  contracts: {
61
62
  eas: '0x4200000000000000000000000000000000000021',
62
63
  schema: '0x4200000000000000000000000000000000000020',
@@ -77,6 +78,7 @@ exports.Networks = {
77
78
  'optimism-goerli': {
78
79
  chainId: 420,
79
80
  url: 'https://optimism-goerli-bedrock.easscan.org/graphql',
81
+ rpcUrl: 'https://opt-goerli.g.alchemy.com/v2/94gBUTVw7SbDxxdeB8gi3KQmgQSD7SHi',
80
82
  contracts: {
81
83
  eas: '0x4200000000000000000000000000000000000021',
82
84
  schema: '0x4200000000000000000000000000000000000020',
package/core/types.d.ts CHANGED
@@ -60,6 +60,7 @@ export interface MultiAttestData {
60
60
  export type MultiAttestPayload = [Attestation, RawMultiAttestPayload][];
61
61
  export interface EASNetworkConfig {
62
62
  url: string;
63
+ rpcUrl: string;
63
64
  chainId: number;
64
65
  contracts: {
65
66
  eas: Hex;
@@ -0,0 +1,4 @@
1
+ import { ethers } from 'ethers';
2
+ declare const providers: Record<number, ethers.providers.JsonRpcProvider>;
3
+ export declare const getWeb3Provider: (chainId: number) => ethers.providers.JsonRpcProvider;
4
+ export {};
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getWeb3Provider = void 0;
4
+ const consts_1 = require("../consts");
5
+ const ethers_1 = require("ethers");
6
+ const providers = {};
7
+ const getWeb3Provider = (chainId) => {
8
+ const rpcUrl = Object.values(consts_1.Networks).find((n) => n.chainId === chainId)
9
+ ?.rpcUrl;
10
+ if (!rpcUrl) {
11
+ throw new Error(`No rpcUrl found for chainId ${chainId}`);
12
+ }
13
+ if (!providers[chainId]) {
14
+ providers[chainId] = new ethers_1.ethers.providers.JsonRpcProvider(rpcUrl);
15
+ }
16
+ return providers[chainId];
17
+ };
18
+ exports.getWeb3Provider = getWeb3Provider;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.2.4",
6
+ "version": "0.2.7",
7
7
  "description": "Simple and easy interface between EAS and Karma GAP.",
8
8
  "main": "./index.js",
9
9
  "author": "KarmaHQ",
@@ -15,7 +15,8 @@
15
15
  },
16
16
  "scripts": {
17
17
  "deploy": "npx ts-node ./core/scripts/deploy.ts",
18
- "csv-upload": "npx ts-node ./csv-upload/scripts/run.ts"
18
+ "csv-upload": "npx ts-node ./csv-upload/scripts/run.ts",
19
+ "publish-npm": "npm version patch && tsc && cd .dist && npm publish --scope=@show-karma/karma-gap-sdk --access public"
19
20
  },
20
21
  "dependencies": {
21
22
  "@ethereum-attestation-service/eas-sdk": "^1.1.0-beta.2",