Skip to content

Commit

Permalink
fix(app): updating zksync 1.0 to lite (passportxyz#1382)
Browse files Browse the repository at this point in the history
* fix(app): updating zksync 1.0 to lite

* fix(app): changed provider name back

* fix(app): changed provider type back to zksync
  • Loading branch information
michaelgreen06 authored Jun 23, 2023
1 parent 06ca116 commit 4e008e8
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 43 deletions.
2 changes: 1 addition & 1 deletion platforms/src/ZkSync/App-Bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProviderPayload> {
Expand Down
8 changes: 4 additions & 4 deletions platforms/src/ZkSync/Providers-config.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand All @@ -13,13 +13,13 @@ 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",
providers: [{ title: "Transacted on zkSync Era", name: "ZkSyncEra" }],
},
];

export const providers: Provider[] = [new ZkSyncProvider(), new ZkSyncEraProvider()];
export const providers: Provider[] = [new ZkSyncLiteProvider(), new ZkSyncEraProvider()];
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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";

Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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}'.`];
Expand Down
52 changes: 26 additions & 26 deletions platforms/src/ZkSync/__tests__/zkSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -122,22 +122,22 @@ 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,
direction: "older",
},
});

expect(zkSyncPayload).toEqual({
expect(zkSyncLitePayload).toEqual({
valid: true,
record: {
address: MOCK_ADDRESS_LOWER,
Expand All @@ -158,22 +158,22 @@ 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,
direction: "older",
},
});

expect(zkSyncPayload).toEqual({
expect(zkSyncLitePayload).toEqual({
valid: false,
error: ["Unable to find a finalized transaction from the given address"],
});
Expand All @@ -190,22 +190,22 @@ 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,
direction: "older",
},
});

expect(zkSyncPayload).toEqual({
expect(zkSyncLitePayload).toEqual({
valid: false,
error: ["Unable to find a finalized transaction from the given address"],
});
Expand All @@ -223,24 +223,24 @@ 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,
direction: "older",
},
});

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'."],
});
});

Expand All @@ -256,22 +256,22 @@ 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,
direction: "older",
},
});

expect(zkSyncPayload).toEqual({
expect(zkSyncLitePayload).toEqual({
valid: false,
error: ["HTTP Error '400'. Details: 'Bad Request'."],
});
Expand All @@ -282,22 +282,22 @@ 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,
direction: "older",
},
});

expect(zkSyncPayload).toEqual({
expect(zkSyncLitePayload).toEqual({
valid: false,
error: ["Error getting transaction list for address"],
});
Expand Down
2 changes: 1 addition & 1 deletion platforms/src/ZkSync/index.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down

0 comments on commit 4e008e8

Please sign in to comment.