From 44f670485421c22b37a9116c2faddd2c46c8a49b Mon Sep 17 00:00:00 2001 From: bigq Date: Tue, 18 Jul 2023 17:43:26 +0200 Subject: [PATCH] feat: remove config into json logic + add impersonation in page.tsx + add new solidity lib --- .gitmodules | 6 +-- front/package.json | 3 +- front/script/sismo-config-to-json.ts | 19 --------- front/src/app/page.tsx | 58 ++++++++++++++++++++++----- front/src/app/sismo-connect-config.ts | 33 --------------- front/src/utils/index.ts | 7 ++++ front/src/utils/misc.ts | 9 ++++- front/src/utils/wagmi.tsx | 14 +++++++ lib/sismo-connect-packages | 1 - lib/sismo-connect-solidity | 1 + remappings.txt | 2 +- script/Airdrop.s.sol | 2 +- src/Airdrop.sol | 2 +- tests/Airdrop.t.sol | 2 +- tests/base/BaseTest.t.sol | 2 +- 15 files changed, 87 insertions(+), 74 deletions(-) delete mode 100644 front/script/sismo-config-to-json.ts delete mode 100644 front/src/app/sismo-connect-config.ts create mode 100644 front/src/utils/index.ts delete mode 160000 lib/sismo-connect-packages create mode 160000 lib/sismo-connect-solidity diff --git a/.gitmodules b/.gitmodules index 96de28d..d08fd58 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/front/package.json b/front/package.json index 227edbe..21e9e0c 100644 --- a/front/package.json +++ b/front/package.json @@ -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": { diff --git a/front/script/sismo-config-to-json.ts b/front/script/sismo-config-to-json.ts deleted file mode 100644 index 5e171be..0000000 --- a/front/script/sismo-config-to-json.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { CONFIG, AUTHS, CLAIMS } from "../src/app/sismo-connect-config"; - -const printSismoConfigJson = (): void => { - const impersonate = CONFIG?.vault?.impersonate; - console.log( - JSON.stringify( - { - appId: CONFIG.appId, - isImpersonationMode: impersonate ? impersonate.length > 0 : false, - authRequests: AUTHS, - claimRequests: CLAIMS, - // signatureRequest: SIGNATURE_REQUEST, - }, - null, - 2 - ) - ); -}; -printSismoConfigJson(); diff --git a/front/src/app/page.tsx b/front/src/app/page.tsx index 33b37ca..aab3d88 100644 --- a/front/src/app/page.tsx +++ b/front/src/app/page.tsx @@ -4,6 +4,7 @@ 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, @@ -11,22 +12,60 @@ import { 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 = { + 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; @@ -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() { diff --git a/front/src/app/sismo-connect-config.ts b/front/src/app/sismo-connect-config.ts deleted file mode 100644 index dcc93fd..0000000 --- a/front/src/app/sismo-connect-config.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { - ClaimType, - AuthType, - SismoConnectConfig, - VerifiedAuth, - VerifiedClaim, -} from "@sismo-core/sismo-connect-client"; - -export { ClaimType, AuthType }; -export type { VerifiedAuth, VerifiedClaim }; -export const CONFIG: SismoConnectConfig = { - appId: "0x32403ced4b65f2079eda77c84e7d2be6", - 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 -}; diff --git a/front/src/utils/index.ts b/front/src/utils/index.ts new file mode 100644 index 0000000..00a8987 --- /dev/null +++ b/front/src/utils/index.ts @@ -0,0 +1,7 @@ +import useContract from "@/utils/useContract"; + +export * from "./errorsABI"; +export * from "./fundMyAccountOnLocalFork"; +export * from "./misc"; +export { useContract }; +export * from "./wagmi"; diff --git a/front/src/utils/misc.ts b/front/src/utils/misc.ts index f67a600..0411ebb 100644 --- a/front/src/utils/misc.ts +++ b/front/src/utils/misc.ts @@ -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 { diff --git a/front/src/utils/wagmi.tsx b/front/src/utils/wagmi.tsx index 0dc8a12..6435385 100644 --- a/front/src/utils/wagmi.tsx +++ b/front/src/utils/wagmi.tsx @@ -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", diff --git a/lib/sismo-connect-packages b/lib/sismo-connect-packages deleted file mode 160000 index d1de041..0000000 --- a/lib/sismo-connect-packages +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d1de04182f20e9e1a2526aaab8659252982e8500 diff --git a/lib/sismo-connect-solidity b/lib/sismo-connect-solidity new file mode 160000 index 0000000..52441ae --- /dev/null +++ b/lib/sismo-connect-solidity @@ -0,0 +1 @@ +Subproject commit 52441ae8f880071944db8ecba6d1dc1202016182 diff --git a/remappings.txt b/remappings.txt index fbe0825..8062183 100644 --- a/remappings.txt +++ b/remappings.txt @@ -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/ \ No newline at end of file +sismo-connect-solidity/=lib/sismo-connect-solidity/src/ \ No newline at end of file diff --git a/script/Airdrop.s.sol b/script/Airdrop.s.sol index cc45522..0d8b7e3 100644 --- a/script/Airdrop.s.sol +++ b/script/Airdrop.s.sol @@ -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 { diff --git a/src/Airdrop.sol b/src/Airdrop.sol index fde1885..567942f 100644 --- a/src/Airdrop.sol +++ b/src/Airdrop.sol @@ -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 diff --git a/tests/Airdrop.t.sol b/tests/Airdrop.t.sol index abccc39..581dfdc 100644 --- a/tests/Airdrop.t.sol +++ b/tests/Airdrop.t.sol @@ -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 { diff --git a/tests/base/BaseTest.t.sol b/tests/base/BaseTest.t.sol index e591d25..12829da 100644 --- a/tests/base/BaseTest.t.sol +++ b/tests/base/BaseTest.t.sol @@ -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);