Skip to content

Commit

Permalink
feat: remove config into json logic + add impersonation in page.tsx +
Browse files Browse the repository at this point in the history
add new solidity lib
  • Loading branch information
yum0e committed Jul 18, 2023
1 parent eadc246 commit 44f6704
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 74 deletions.
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/sismo-connect-packages"]
path = lib/sismo-connect-packages
url = https://github.com/sismo-core/sismo-connect-packages
[submodule "lib/sismo-connect-solidity"]
path = lib/sismo-connect-solidity
url = https://github.com/sismo-core/sismo-connect-solidity
3 changes: 1 addition & 2 deletions front/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "NODE_OPTIONS='--max-http-header-size=24576' next dev -p 3000 & nodemon --watch ./src/app/sismo-connect-config.ts --watch ../src/Airdrop.sol --exec 'npm run config-to-json && npm run deploy-airdrop && sleep 3 && ./script/log.sh'",
"dev": "NODE_OPTIONS='--max-http-header-size=24576' next dev -p 3000 & nodemon --watch ../src/Airdrop.sol --exec 'npm run deploy-airdrop && sleep 3 && ./script/log.sh'",
"build": "next build",
"start": "NODE_OPTIONS='--max-http-header-size=24576' next start",
"lint": "next lint",
"config-to-json": "npx tsx ./script/sismo-config-to-json.ts > ../sismo-connect-config.json",
"deploy-airdrop": "forge script DeployAirdrop --rpc-url http://localhost:8545 -vv --mnemonics 'test test test test test test test test test test test junk' --sender '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' --broadcast && ./script/generate-abi-from-front.sh"
},
"browser": {
Expand Down
19 changes: 0 additions & 19 deletions front/script/sismo-config-to-json.ts

This file was deleted.

58 changes: 49 additions & 9 deletions front/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,68 @@ import { useEffect, useState } from "react";
import Header from "./components/Header";
import { useAccount, useNetwork } from "wagmi";
import { useConnectModal } from "@rainbow-me/rainbowkit";
import { formatEther } from "viem";
import {
formatError,
getAuthRequestsAndClaimRequestsFromSismoConnectRequest,
getProofDataForAuth,
getProofDataForClaim,
getUserIdFromHex,
signMessage,
} from "@/utils/misc";
import { mumbaiFork } from "@/utils/wagmi";
fundMyAccountOnLocalFork,
useContract,
// chains
mumbaiFork,
mainnet,
goerli,
sepolia,
optimism,
optimismGoerli,
arbitrum,
arbitrumGoerli,
scrollTestnet,
gnosis,
polygon,
polygonMumbai,
} from "@/utils";
import {
AuthRequest,
ClaimRequest,
RequestBuilder,
SismoConnectButton,
VaultConfig,
VerifiedAuth,
VerifiedClaim, // the Sismo Connect React button displayed below
AuthType,
ClaimType,
SismoConnectConfig,
} from "@sismo-core/sismo-connect-react";
import { fundMyAccountOnLocalFork } from "@/utils/fundMyAccountOnLocalFork";
import { CONFIG, AuthType, ClaimType } from "@/app/sismo-connect-config";
import useContract from "@/utils/useContract";
import { decodeAbiParameters, formatEther } from "viem";
import { get } from "http";

/* ********************** Sismo Connect Config *************************** */
// For development purposes insert the Data Sources that you want to impersonate
// Never use this in production
// the appId is not referenced here as it is set directly in the contract
export const CONFIG: Omit<SismoConnectConfig, "appId"> = {
vault: {
// For development purposes insert the Data Sources that you want to impersonate
// Never use this in production
impersonate: [
// EVM Data Sources
"dhadrien.sismo.eth",
"0xA4C94A6091545e40fc9c3E0982AEc8942E282F38",
"0x1b9424ed517f7700e7368e34a9743295a225d889",
"0x82fbed074f62386ed43bb816f748e8817bf46ff7",
"0xc281bd4db5bf94f02a8525dca954db3895685700",
// Github Data Source
"github:dhadrien",
// Twitter Data Source
"twitter:dhadrien_",
// Telegram Data Source
"telegram:dhadrien",
],
},
// displayRawResponse: true, // this enables you to get access directly to the
// Sismo Connect Response in the vault instead of redirecting back to the app
};

/* ******************** Defines the chain to use *************************** */
const CHAIN = mumbaiFork;
Expand Down Expand Up @@ -61,12 +100,13 @@ export default function Home() {
});
const { chain } = useNetwork();
const { openConnectModal, connectModalOpen } = useConnectModal();

const { airdropContract, switchNetworkAsync, waitingForTransaction, error } = useContract({
responseBytes,
chain: CHAIN,
});

// Get the SismoConnectConfig and Sismo Connect Request from the contract
// Set react state accordingly to display the Sismo Connect Button
useEffect(() => {
if (!isConnected) return;
async function getRequests() {
Expand Down
33 changes: 0 additions & 33 deletions front/src/app/sismo-connect-config.ts

This file was deleted.

7 changes: 7 additions & 0 deletions front/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import useContract from "@/utils/useContract";

export * from "./errorsABI";
export * from "./fundMyAccountOnLocalFork";
export * from "./misc";
export { useContract };
export * from "./wagmi";
9 changes: 7 additions & 2 deletions front/src/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { decodeAbiParameters, encodeAbiParameters } from "viem";
import { abi as AirdropABI } from "../../../abi/Airdrop.json";
import { errorsABI } from "./errorsABI";
import { AuthType, VerifiedAuth, VerifiedClaim } from "@/app/sismo-connect-config";
import { AuthRequest, ClaimRequest } from "@sismo-core/sismo-connect-react";
import {
AuthRequest,
AuthType,
ClaimRequest,
VerifiedAuth,
VerifiedClaim,
} from "@sismo-core/sismo-connect-react";

declare global {
interface Window {
Expand Down
14 changes: 14 additions & 0 deletions front/src/utils/wagmi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ import { WagmiConfig } from "wagmi";
import { publicProvider } from "wagmi/providers/public";
import { getDefaultWallets, RainbowKitProvider } from "@rainbow-me/rainbowkit";

export {
mainnet,
goerli,
sepolia,
optimism,
optimismGoerli,
arbitrum,
arbitrumGoerli,
scrollTestnet,
gnosis,
polygon,
polygonMumbai,
};

export const mumbaiFork = {
id: 5151111,
name: "Local Fork Mumbai",
Expand Down
1 change: 0 additions & 1 deletion lib/sismo-connect-packages
Submodule sismo-connect-packages deleted from d1de04
1 change: 1 addition & 0 deletions lib/sismo-connect-solidity
Submodule sismo-connect-solidity added at 52441a
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
forge-std/=lib/forge-std/src/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
sismo-connect-solidity/=lib/sismo-connect-packages/packages/sismo-connect-solidity/src/
sismo-connect-solidity/=lib/sismo-connect-solidity/src/
2 changes: 1 addition & 1 deletion script/Airdrop.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import "forge-std/Script.sol";
import "sismo-connect-solidity/SismoLib.sol";
import "sismo-connect-solidity/SismoConnectLib.sol";
import {Airdrop} from "src/Airdrop.sol";

contract DeployAirdrop is Script {
Expand Down
2 changes: 1 addition & 1 deletion src/Airdrop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.20;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "forge-std/console2.sol";
import "sismo-connect-solidity/SismoLib.sol";
import "sismo-connect-solidity/SismoConnectLib.sol";

/*
* @title Airdrop
Expand Down
2 changes: 1 addition & 1 deletion tests/Airdrop.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.20;

import "tests/base/BaseTest.t.sol";
import "sismo-connect-solidity/SismoLib.sol";
import "sismo-connect-solidity/SismoConnectLib.sol";
import {Airdrop} from "src/Airdrop.sol";

contract Airdroptest is BaseTest {
Expand Down
2 changes: 1 addition & 1 deletion tests/base/BaseTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.17;

import "forge-std/Test.sol";
import "forge-std/console.sol";
import {IAddressesProvider} from "sismo-connect-solidity/SismoLib.sol";
import {IAddressesProvider} from "sismo-connect-solidity/SismoConnectLib.sol";

interface IAvailableRootsRegistry {
event RegisteredRoot(uint256 root);
Expand Down

0 comments on commit 44f6704

Please sign in to comment.