forked from sismo-core/app-store
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add zkDrop template app (sismo-core#187)
Co-authored-by: leo21.sismo.eth <[email protected]>
- Loading branch information
1 parent
6d4b3d9
commit c15eee0
Showing
37 changed files
with
7,901 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
name: Upload zkDrop Metadata | ||
|
||
on: | ||
issue_comment: | ||
types: [created] | ||
|
||
jobs: | ||
create-app: | ||
runs-on: ubuntu-latest | ||
if: contains(github.event.comment.body, '/upload-metadata') | ||
steps: | ||
- name: Check if sismo-core organisation member | ||
id: is_organization_member | ||
uses: jamessingleton/[email protected] | ||
with: | ||
organization: "sismo-core" | ||
username: ${{ github.actor }} | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- if: steps.is_organization_member.outputs.result != 'true' | ||
run: exit 1 | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # fetch all branches and tags | ||
token: ${{secrets.SISMOBOT_TOKEN}} | ||
|
||
- name: Checkout Pull Request | ||
run: hub pr checkout ${{ github.event.issue.number }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.SISMOBOT_TOKEN }} | ||
|
||
- name: Install dependencies | ||
run: yarn install --frozen-lockfile | ||
|
||
- id: changed-files | ||
uses: ahmadnassri/action-changed-files@v1 | ||
|
||
- name: content | ||
run: | | ||
echo 'Changed files:' | ||
echo "${{ steps.changed-files.outputs.files }}" | ||
- name: Get modified spaces and apps | ||
id: updated-spaces | ||
run: | | ||
echo 'Changed files:' | ||
DEMO_UPDATED_SPACES=$(echo ${{steps.changed-files.outputs.files}} | awk 'BEGIN {OFS=FS=" "} {for(i=1; i<=NF; i++) {if ($i ~ /demo/){split($i,a,"/"); n=split(a[length(a)],b,"."); print b[1]}}}' | xargs) | ||
echo "::set-output name=demo_updated_spaces::'$(echo "$DEMO_UPDATED_SPACES")'" | ||
MAIN_UPDATED_SPACES=$(echo ${{steps.changed-files.outputs.files}} | awk 'BEGIN {OFS=FS=" "} {for(i=1; i<=NF; i++) {if ($i ~ /main/){split($i,a,"/"); n=split(a[length(a)],b,"."); print b[1]}}}' | xargs) | ||
echo "::set-output name=main_updated_spaces::'$(echo "$MAIN_UPDATED_SPACES")'" | ||
- name: Display changes | ||
run: | | ||
echo "[DEMO] Modified spaces and apps in commit:" | ||
echo "${{ steps.updated-spaces.outputs.demo_updated_spaces }}" | ||
echo "[MAIN] Modified spaces and apps in commit:" | ||
echo "${{ steps.updated-spaces.outputs.main_updated_spaces }}" | ||
- name: Run Upload metadata script [demo] | ||
env: | ||
NEXT_PUBLIC_NODE_ENV: demo | ||
PINATA_JWT_TOKEN: ${{ secrets.PINATA_JWT_TOKEN }} | ||
run: | | ||
yarn upload-zk-drop-metadata ${{ steps.updated-spaces.outputs.demo_updated_spaces }} | ||
- name: Run Upload metadata script [main] | ||
env: | ||
NEXT_PUBLIC_NODE_ENV: main | ||
PINATA_JWT_TOKEN: ${{ secrets.PINATA_JWT_TOKEN }} | ||
run: | | ||
yarn upload-zk-drop-metadata ${{ steps.updated-spaces.outputs.main_updated_spaces }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -466,6 +466,6 @@ export default { | |
options: { | ||
isFeatured: true, | ||
}, | ||
}, | ||
} | ||
], | ||
} as SpaceConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -152,6 +152,7 @@ export default { | |
}, | ||
}, | ||
}, | ||
|
||
}, | ||
], | ||
} as SpaceConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,6 @@ export default { | |
options: { | ||
endDate: new Date("2023-07-07T18:00"), | ||
}, | ||
}, | ||
} | ||
], | ||
} as SpaceConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
import ServiceFactory from "@/src/services/service-factory/service-factory"; | ||
import { POST } from "./route"; | ||
import { spaceMock1, spaceMock2 } from "@/src/services/spaces-service/tests/spaces-mock"; | ||
import { Network } from "@/src/libs/contracts/networks"; | ||
|
||
|
||
const mockMint = jest.fn().mockImplementation(() => Promise.resolve({ hash: 'mockTxHash' })); | ||
|
||
jest.mock("../../../../libs/contracts/signers", () => { | ||
return { | ||
getDefenderRelayerSigner: jest.fn().mockReturnValue({}), | ||
}; | ||
}); | ||
|
||
jest.mock('../../../../libs/contracts/zk-drop', () => { | ||
const originalModule = jest.requireActual("../../../../libs/contracts/zk-drop"); | ||
return { | ||
__esModule: true, | ||
...originalModule, | ||
ZkDropContract: jest.fn().mockImplementation(() => { | ||
return { | ||
mint: mockMint, | ||
}; | ||
}), | ||
}; | ||
}); | ||
|
||
describe('POST /api/zk-drop/relay-tx', () => { | ||
beforeEach(() => { | ||
let spacesService = ServiceFactory.getSpacesService(); | ||
const configs = [ | ||
spaceMock1, | ||
spaceMock2 | ||
] | ||
spacesService.updateConfigs(configs); | ||
}) | ||
|
||
afterEach(() => { | ||
let configs = ServiceFactory.getSpaceConfigs(); | ||
let spacesService = ServiceFactory.getSpacesService(); | ||
spacesService.updateConfigs(configs); | ||
jest.clearAllMocks(); | ||
}) | ||
|
||
it('Should throw with an incorrect app slug', async () => { | ||
const req: any = { | ||
json: jest.fn().mockResolvedValue({ | ||
responseBytes: 'mockResponseBytes', | ||
destination: 'mockDestination', | ||
spaceSlug: spaceMock1.metadata.slug, | ||
appSlug: "zk-drop-slug-invalid", | ||
chain: Network.Sepolia | ||
}) | ||
}; | ||
|
||
const response = await POST(req); | ||
const data = await response.json(); | ||
expect(data.code).toEqual(`No app found for ${spaceMock1.metadata.slug}/zk-drop-slug-invalid`); | ||
}); | ||
|
||
it('Should throw with an incorrect chain', async () => { | ||
const req: any = { | ||
json: jest.fn().mockResolvedValue({ | ||
responseBytes: 'mockResponseBytes', | ||
destination: 'mockDestination', | ||
spaceSlug: spaceMock1.metadata.slug, | ||
appSlug: "zk-drop-slug", | ||
chain: Network.Mumbai | ||
}) | ||
}; | ||
|
||
const response = await POST(req); | ||
const data = await response.json(); | ||
expect(data.code).toEqual(`Chain mumbai not supported for the app ${spaceMock1.metadata.slug}/zk-drop-slug`); | ||
}); | ||
|
||
it('Should call mint with the correct arguments', async () => { | ||
const req: any = { | ||
json: jest.fn().mockResolvedValue({ | ||
responseBytes: 'mockResponseBytes', | ||
destination: 'mockDestination', | ||
spaceSlug: spaceMock1.metadata.slug, | ||
appSlug: "zk-drop-slug", | ||
chain: Network.Sepolia | ||
}) | ||
}; | ||
await POST(req); | ||
console.log("Mock mint calls: ", mockMint.mock.calls); | ||
expect(mockMint).toHaveBeenCalledWith({ | ||
responseBytes: 'mockResponseBytes', | ||
address: 'mockDestination' | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import env from "@/src/environments"; | ||
import { getDefenderRelayerSigner } from "@/src/libs/contracts/signers"; | ||
import { ZkDropContract } from "@/src/libs/contracts/zk-drop"; | ||
import ServiceFactory from "@/src/services/service-factory/service-factory"; | ||
import { ZkDropAppType } from "@/src/services/spaces-service"; | ||
import { NextResponse } from "next/server"; | ||
|
||
export async function POST(req: Request) { | ||
const { responseBytes, destination, chain, spaceSlug, appSlug } = await req.json(); | ||
|
||
const spacesService = ServiceFactory.getSpacesService(); | ||
const apps = await spacesService.getApps({ where: { spaceSlug, appSlug }}); | ||
if (!apps || apps.length !== 1) { | ||
return NextResponse.json({ | ||
code: `No app found for ${spaceSlug}/${appSlug}` | ||
}) | ||
} | ||
const app = apps[0] as ZkDropAppType; | ||
|
||
const signer = getDefenderRelayerSigner(chain, env.defenderAPIKeys.zkDrop); | ||
const chainConfig = app.chains.find(_chain => _chain.name === chain) | ||
|
||
if (!chainConfig) { | ||
return NextResponse.json({ | ||
code: `Chain ${chain} not supported for the app ${spaceSlug}/${appSlug}` | ||
}) | ||
} | ||
const zkDropContract = new ZkDropContract({ signer, contractAddress: chainConfig.contractAddress }); | ||
|
||
try { | ||
console.log({ | ||
responseBytes, | ||
address: destination, | ||
chain, | ||
contractAddress: chainConfig.contractAddress | ||
}); | ||
const tx = await zkDropContract.mint({ | ||
responseBytes, | ||
address: destination | ||
}); | ||
|
||
return NextResponse.json({ | ||
success: true, | ||
txHash: tx.hash | ||
}); | ||
} catch (e) { | ||
console.error(e); | ||
return NextResponse.json({ | ||
code: "minting-error" | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.