diff --git a/platforms/src/ZkSync/App-Bindings.ts b/platforms/src/ZkSync/App-Bindings.ts index fe3b56c88e..05ff1e2c76 100644 --- a/platforms/src/ZkSync/App-Bindings.ts +++ b/platforms/src/ZkSync/App-Bindings.ts @@ -7,7 +7,7 @@ export class ZkSyncPlatform extends Platform { banner = { heading: - "Only 'TRANSFER' transactions on zkSync 1.0 are recognized. Transactions need to achieve verified status (may take up to 24hrs) across all zkSync networks to count. Other transaction types are not currently included.", + "Only 'TRANSFER' transactions on ZkSync Lite are recognized. Transactions need to achieve verified status (may take up to 24hrs) across all zkSync networks to count. Other transaction types are not currently included.", }; async getProviderPayload(appContext: AppContext): Promise { diff --git a/platforms/src/ZkSync/Providers-config.ts b/platforms/src/ZkSync/Providers-config.ts index 975b86913e..caba5ba571 100644 --- a/platforms/src/ZkSync/Providers-config.ts +++ b/platforms/src/ZkSync/Providers-config.ts @@ -1,5 +1,5 @@ import { PlatformSpec, PlatformGroupSpec, Provider } from "../types"; -import { ZkSyncProvider } from "./Providers/zkSync"; +import { ZkSyncLiteProvider } from "./Providers/zkSyncLite"; import { ZkSyncEraProvider } from "./Providers/zkSyncEra"; export const PlatformDetails: PlatformSpec = { @@ -13,8 +13,8 @@ export const PlatformDetails: PlatformSpec = { export const ProviderConfig: PlatformGroupSpec[] = [ { - platformGroup: "zkSync 1.0", - providers: [{ title: "Transacted on zkSync 1.0", name: "ZkSync" }], + platformGroup: "zkSync Lite", + providers: [{ title: "Transacted on zkSync Lite", name: "ZkSync" }], }, { platformGroup: "zkSync Era", @@ -22,4 +22,4 @@ export const ProviderConfig: PlatformGroupSpec[] = [ }, ]; -export const providers: Provider[] = [new ZkSyncProvider(), new ZkSyncEraProvider()]; +export const providers: Provider[] = [new ZkSyncLiteProvider(), new ZkSyncEraProvider()]; diff --git a/platforms/src/ZkSync/Providers/zkSync.ts b/platforms/src/ZkSync/Providers/zkSyncLite.ts similarity index 75% rename from platforms/src/ZkSync/Providers/zkSync.ts rename to platforms/src/ZkSync/Providers/zkSyncLite.ts index 6fec066435..448cdbc001 100644 --- a/platforms/src/ZkSync/Providers/zkSync.ts +++ b/platforms/src/ZkSync/Providers/zkSyncLite.ts @@ -9,7 +9,7 @@ import axios from "axios"; import { getAddress } from "../../utils/signer"; // https://docs.zksync.io/api/v0.2/ -export const zkSyncApiEndpoint = "https://api.zksync.io/api/v0.2/"; +export const zkSyncLiteApiEndpoint = "https://api.zksync.io/api/v0.2/"; // Pagination structure type Pagination = { @@ -20,21 +20,21 @@ type Pagination = { }; // Defining interfaces for the data structure returned by the subgraph -type ZKSyncTransaction = { +type ZKSyncLiteTransaction = { txHash: string; op: { from: string; to: string }; status: string; }; -type ZkSyncResponse = { +type ZkSyncLiteResponse = { status: string; error: unknown; - result: { list: ZKSyncTransaction[] }; + result: { list: ZKSyncLiteTransaction[] }; pagination: Pagination; }; // Export a Provider to verify ZkSync Transactions -export class ZkSyncProvider implements Provider { +export class ZkSyncLiteProvider implements Provider { // Give the provider a type so that we can select it with a payload type = "ZkSync"; @@ -55,7 +55,7 @@ export class ZkSyncProvider implements Provider { const address = (await getAddress(payload)).toLowerCase(); try { - const requestResponse = await axios.get(`${zkSyncApiEndpoint}accounts/${address}/transactions`, { + const requestResponse = await axios.get(`${zkSyncLiteApiEndpoint}accounts/${address}/transactions`, { params: { from: "latest", limit: 100, @@ -64,13 +64,13 @@ export class ZkSyncProvider implements Provider { }); if (requestResponse.status == 200) { - const zkSyncResponse = requestResponse.data as ZkSyncResponse; + const zkSyncLiteResponse = requestResponse.data as ZkSyncLiteResponse; - if (zkSyncResponse.status === "success") { + if (zkSyncLiteResponse.status === "success") { // We consider the verification valid if this account has at least one finalized // transaction initiated by this account - for (let i = 0; i < zkSyncResponse.result.list.length; i++) { - const t = zkSyncResponse.result.list[i]; + for (let i = 0; i < zkSyncLiteResponse.result.list.length; i++) { + const t = zkSyncLiteResponse.result.list[i]; if (t.status === "finalized" && t.op.from === address) { valid = true; break; @@ -81,7 +81,9 @@ export class ZkSyncProvider implements Provider { error = ["Unable to find a finalized transaction from the given address"]; } } else { - error = [`ZKSync API Error '${zkSyncResponse.status}'. Details: '${zkSyncResponse.error.toString()}'.`]; + error = [ + `ZKSync Lite API Error '${zkSyncLiteResponse.status}'. Details: '${zkSyncLiteResponse.error.toString()}'.`, + ]; } } else { error = [`HTTP Error '${requestResponse.status}'. Details: '${requestResponse.statusText}'.`]; diff --git a/platforms/src/ZkSync/__tests__/zkSync.test.ts b/platforms/src/ZkSync/__tests__/zkSync.test.ts index 4100272ec6..e6d5cc31ff 100644 --- a/platforms/src/ZkSync/__tests__/zkSync.test.ts +++ b/platforms/src/ZkSync/__tests__/zkSync.test.ts @@ -4,7 +4,7 @@ import { RequestPayload } from "@gitcoin/passport-types"; // ----- Libs import axios from "axios"; -import { zkSyncApiEndpoint, ZkSyncProvider } from "../Providers/zkSync"; +import { zkSyncLiteApiEndpoint, ZkSyncLiteProvider } from "../Providers/zkSyncLite"; jest.mock("axios"); @@ -122,14 +122,14 @@ describe("Verification succeeds", function () { }); }); - const zkSyncProvider = new ZkSyncProvider(); - const zkSyncPayload = await zkSyncProvider.verify({ + const zkSyncLiteProvider = new ZkSyncLiteProvider(); + const zkSyncLitePayload = await zkSyncLiteProvider.verify({ address: MOCK_ADDRESS, } as unknown as RequestPayload); // Check the request to get the transactions expect(axios.get).toHaveBeenCalledTimes(1); - expect(mockedAxios.get).toBeCalledWith(`${zkSyncApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { + expect(mockedAxios.get).toBeCalledWith(`${zkSyncLiteApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { params: { from: "latest", limit: 100, @@ -137,7 +137,7 @@ describe("Verification succeeds", function () { }, }); - expect(zkSyncPayload).toEqual({ + expect(zkSyncLitePayload).toEqual({ valid: true, record: { address: MOCK_ADDRESS_LOWER, @@ -158,14 +158,14 @@ describe("Verification fails", function () { }); }); - const zkSyncProvider = new ZkSyncProvider(); - const zkSyncPayload = await zkSyncProvider.verify({ + const zkSyncLiteProvider = new ZkSyncLiteProvider(); + const zkSyncLitePayload = await zkSyncLiteProvider.verify({ address: MOCK_ADDRESS, } as unknown as RequestPayload); // Check the request to get the transactions expect(axios.get).toHaveBeenCalledTimes(1); - expect(mockedAxios.get).toBeCalledWith(`${zkSyncApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { + expect(mockedAxios.get).toBeCalledWith(`${zkSyncLiteApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { params: { from: "latest", limit: 100, @@ -173,7 +173,7 @@ describe("Verification fails", function () { }, }); - expect(zkSyncPayload).toEqual({ + expect(zkSyncLitePayload).toEqual({ valid: false, error: ["Unable to find a finalized transaction from the given address"], }); @@ -190,14 +190,14 @@ describe("Verification fails", function () { }); }); - const zkSyncProvider = new ZkSyncProvider(); - const zkSyncPayload = await zkSyncProvider.verify({ + const zkSyncLiteProvider = new ZkSyncLiteProvider(); + const zkSyncLitePayload = await zkSyncLiteProvider.verify({ address: MOCK_ADDRESS, } as unknown as RequestPayload); // Check the request to get the transactions expect(axios.get).toHaveBeenCalledTimes(1); - expect(mockedAxios.get).toBeCalledWith(`${zkSyncApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { + expect(mockedAxios.get).toBeCalledWith(`${zkSyncLiteApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { params: { from: "latest", limit: 100, @@ -205,7 +205,7 @@ describe("Verification fails", function () { }, }); - expect(zkSyncPayload).toEqual({ + expect(zkSyncLitePayload).toEqual({ valid: false, error: ["Unable to find a finalized transaction from the given address"], }); @@ -223,14 +223,14 @@ describe("Verification fails", function () { }); }); - const zkSyncProvider = new ZkSyncProvider(); - const zkSyncPayload = await zkSyncProvider.verify({ + const zkSyncLiteProvider = new ZkSyncLiteProvider(); + const zkSyncLitePayload = await zkSyncLiteProvider.verify({ address: MOCK_ADDRESS, } as unknown as RequestPayload); // Check the request to get the transactions expect(axios.get).toHaveBeenCalledTimes(1); - expect(mockedAxios.get).toBeCalledWith(`${zkSyncApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { + expect(mockedAxios.get).toBeCalledWith(`${zkSyncLiteApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { params: { from: "latest", limit: 100, @@ -238,9 +238,9 @@ describe("Verification fails", function () { }, }); - expect(zkSyncPayload).toEqual({ + expect(zkSyncLitePayload).toEqual({ valid: false, - error: ["ZKSync API Error 'error'. Details: 'some kind of error'."], + error: ["ZKSync Lite API Error 'error'. Details: 'some kind of error'."], }); }); @@ -256,14 +256,14 @@ describe("Verification fails", function () { }); }); - const zkSyncProvider = new ZkSyncProvider(); - const zkSyncPayload = await zkSyncProvider.verify({ + const zkSyncLiteProvider = new ZkSyncLiteProvider(); + const zkSyncLitePayload = await zkSyncLiteProvider.verify({ address: MOCK_ADDRESS, } as unknown as RequestPayload); // Check the request to get the transactions expect(axios.get).toHaveBeenCalledTimes(1); - expect(mockedAxios.get).toBeCalledWith(`${zkSyncApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { + expect(mockedAxios.get).toBeCalledWith(`${zkSyncLiteApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { params: { from: "latest", limit: 100, @@ -271,7 +271,7 @@ describe("Verification fails", function () { }, }); - expect(zkSyncPayload).toEqual({ + expect(zkSyncLitePayload).toEqual({ valid: false, error: ["HTTP Error '400'. Details: 'Bad Request'."], }); @@ -282,14 +282,14 @@ describe("Verification fails", function () { throw "something bad happened"; }); - const zkSyncProvider = new ZkSyncProvider(); - const zkSyncPayload = await zkSyncProvider.verify({ + const zkSyncLiteProvider = new ZkSyncLiteProvider(); + const zkSyncLitePayload = await zkSyncLiteProvider.verify({ address: MOCK_ADDRESS, } as unknown as RequestPayload); // Check the request to get the transactions expect(axios.get).toHaveBeenCalledTimes(1); - expect(mockedAxios.get).toBeCalledWith(`${zkSyncApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { + expect(mockedAxios.get).toBeCalledWith(`${zkSyncLiteApiEndpoint}accounts/${MOCK_ADDRESS_LOWER}/transactions`, { params: { from: "latest", limit: 100, @@ -297,7 +297,7 @@ describe("Verification fails", function () { }, }); - expect(zkSyncPayload).toEqual({ + expect(zkSyncLitePayload).toEqual({ valid: false, error: ["Error getting transaction list for address"], }); diff --git a/platforms/src/ZkSync/index.ts b/platforms/src/ZkSync/index.ts index 6076afa809..fad5a6ae62 100644 --- a/platforms/src/ZkSync/index.ts +++ b/platforms/src/ZkSync/index.ts @@ -1,4 +1,4 @@ -export { ZkSyncProvider } from "./Providers/zkSync"; +export { ZkSyncLiteProvider } from "./Providers/zkSyncLite"; export { ZkSyncEraProvider } from "./Providers/zkSyncEra"; export { PlatformDetails, ProviderConfig, providers } from "./Providers-config";