From bbf9660f624f054d6b3ad34663af7da527e6f3ad Mon Sep 17 00:00:00 2001 From: Fernando Date: Mon, 12 Feb 2024 20:33:31 +0900 Subject: [PATCH 1/9] feat: type pulled from gitmodule bot repository --- .gitmodules | 4 + lib/ubiquibot | 1 + static/scripts/onboarding/onboarding.ts | 131 +++++------------------- 3 files changed, 32 insertions(+), 104 deletions(-) create mode 160000 lib/ubiquibot diff --git a/.gitmodules b/.gitmodules index a3706a83..3d81c6bd 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,3 +5,7 @@ [submodule "lib/permit2"] path = lib/permit2 url = https://github.com/Uniswap/permit2 +[submodule "lib/ubiquibot"] + path = lib/ubiquibot + url = https://github.com/ubiquity/ubiquibot + shallow = true diff --git a/lib/ubiquibot b/lib/ubiquibot new file mode 160000 index 00000000..8afd7cfa --- /dev/null +++ b/lib/ubiquibot @@ -0,0 +1 @@ +Subproject commit 8afd7cfa13e9731fb49b5f5a03f605258458d649 diff --git a/static/scripts/onboarding/onboarding.ts b/static/scripts/onboarding/onboarding.ts index 9526252f..5c74edff 100644 --- a/static/scripts/onboarding/onboarding.ts +++ b/static/scripts/onboarding/onboarding.ts @@ -1,13 +1,15 @@ -import _sodium from "libsodium-wrappers"; -import { Octokit } from "@octokit/rest"; +import { JsonRpcSigner } from "@ethersproject/providers"; import { createOrUpdateTextFile } from "@octokit/plugin-create-or-update-text-file"; -import YAML from "yaml"; -import { ethers } from "ethers"; +import { Octokit } from "@octokit/rest"; import { PERMIT2_ADDRESS } from "@uniswap/permit2-sdk"; -import { JsonRpcSigner, Network } from "@ethersproject/providers"; +import { ethers } from "ethers"; import { parseUnits } from "ethers/lib/utils"; -import { NetworkIds, Tokens, getNetworkName, networkNames } from "../rewards/constants"; +import _sodium from "libsodium-wrappers"; +import YAML from "yaml"; +import { DefaultConfig } from "../../../lib/ubiquibot/src/configs/ubiquibot-config-default"; +import { MergedConfig } from "../../../lib/ubiquibot/src/types"; import { erc20Abi } from "../rewards/abis/erc20Abi"; +import { getNetworkName, NetworkIds, Tokens } from "../rewards/constants"; const classes = ["error", "warn", "success"]; const inputClasses = ["input-warn", "input-error", "input-success"]; @@ -33,96 +35,14 @@ const X25519_KEY = "5ghIlfGjz_ChcYlBDOG7dzmgAgBPuTahpvTMBipSH00"; let encryptedValue = ""; -interface ConfLabel { - name: string; -} - -interface CommandLabel { - name: string; - enabled: boolean; -} - -interface IIncentive { - comment: { - elements: Record; - totals: { - word: number; - }; - }; -} - -interface IControl { - label: boolean; - organization: boolean; -} - -interface IConf { - "private-key-encrypted"?: string; - "safe-address"?: string; - "base-multiplier"?: number; - "auto-pay-mode"?: boolean; - "analytics-mode"?: boolean; - "max-concurrent-bounties"?: number; - "incentive-mode"?: boolean; - "evm-network-id"?: number; - "price-multiplier"?: number; - "issue-creator-multiplier"?: number; - "payment-permit-max-price"?: number; - "max-concurrent-assigns"?: number; - "assistive-pricing"?: boolean; - "disable-analytics"?: boolean; - "comment-incentives"?: boolean; - "register-wallet-with-verification"?: boolean; - "promotion-comment"?: string; - "default-labels"?: string[]; - "time-labels"?: ConfLabel[]; - "priority-labels"?: ConfLabel[]; - "command-settings"?: CommandLabel[]; - incentives?: IIncentive; - "enable-access-control"?: IControl; -} - -let defaultConf: IConf = { - "private-key-encrypted": "", - "safe-address": "", - "base-multiplier": 1, - "auto-pay-mode": false, - "analytics-mode": false, - "max-concurrent-bounties": 1, - "incentive-mode": false, - "evm-network-id": 1, - "price-multiplier": 1, - "issue-creator-multiplier": 1, - "payment-permit-max-price": 1, - "max-concurrent-assigns": 1, - "assistive-pricing": false, - "disable-analytics": false, - "comment-incentives": false, - "register-wallet-with-verification": false, - "promotion-comment": "", - "default-labels": [], - "time-labels": [], - "priority-labels": [], - "command-settings": [], - incentives: { - comment: { - elements: {}, - totals: { - word: 0, - }, - }, - }, - "enable-access-control": { - label: false, - organization: true, - }, -}; +let defaultConf = DefaultConfig -export const parseYAML = async (data: any): Promise => { +export const parseYAML = async (data: string | undefined) => { + if (!data) return undefined try { const parsedData = await YAML.parse(data); if (parsedData !== null) { - return parsedData; + return parsedData as T; } else { return undefined; } @@ -131,10 +51,10 @@ export const parseYAML = async (data: any): Promise => { } }; -export const parseJSON = async (data: any): Promise => { +export const parseJSON = async (data: string) => { try { const parsedData = await JSON.parse(data); - return parsedData; + return parsedData as T; } catch (error) { return undefined; } @@ -227,9 +147,9 @@ const sodiumEncryptedSeal = async (publicKey: string, secret: string) => { const binsec = sodium.from_string(secret); const encBytes = sodium.crypto_box_seal(binsec, binkey); const output = sodium.to_base64(encBytes, sodium.base64_variants.URLSAFE_NO_PADDING); - defaultConf[KEY_NAME] = output; - defaultConf["evm-network-id"] = Number(chainIdSelect.value); - defaultConf["safe-address"] = safeAddressInput.value; + // defaultConf[KEY_NAME] = output; + defaultConf["evmNetworkId"] = Number(chainIdSelect.value); + // defaultConf["safe-address"] = safeAddressInput.value; outKey.value = YAMLStringify(defaultConf); outKey.style.height = getTextBox(outKey.value); encryptedValue = output; @@ -304,10 +224,10 @@ const setConfig = async () => { const conf = await getConf(); const updatedConf = defaultConf; - const parsedConf: IConf | undefined = await parseYAML(conf); - updatedConf[KEY_NAME] = encryptedValue; - updatedConf["evm-network-id"] = Number(chainIdSelect.value); - updatedConf["safe-address"] = safeAddressInput.value; + const parsedConf = await parseYAML(conf); + // updatedConf[KEY_NAME] = encryptedValue; + updatedConf["evmNetworkId"] = Number(chainIdSelect.value); + // updatedConf["safe-address"] = safeAddressInput.value; // combine configs (default + remote org wide) const combinedConf = Object.assign(updatedConf, parsedConf); @@ -555,9 +475,12 @@ const init = async () => { let conf = await getConf(true); if (conf !== undefined) { try { - conf = JSON.parse(conf); - defaultConf = conf as IConf; - defaultConf["private-key-encrypted"] = ""; + const parsedConf = JSON.parse(conf) as MergedConfig; + if (!parsedConf) { + throw new Error("Configuration could not be parsed!") + } + defaultConf = parsedConf; + // defaultConf["private-key-encrypted"] = ""; setInputListeners(); setBtn.addEventListener("click", async () => { From 344c81d2482a7cd85d838afbbc9001730f11ea28 Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 13 Feb 2024 17:02:32 +0900 Subject: [PATCH 2/9] chore: renamed conf keys to match the new bot conf --- static/scripts/onboarding/onboarding.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/static/scripts/onboarding/onboarding.ts b/static/scripts/onboarding/onboarding.ts index 5c74edff..081bb40d 100644 --- a/static/scripts/onboarding/onboarding.ts +++ b/static/scripts/onboarding/onboarding.ts @@ -29,7 +29,8 @@ const REPO_NAME = "ubiquibot-config"; const DEFAULT_REPO = "ubiquibot"; const KEY_PATH = ".github/ubiquibot-config.yml"; const DEFAULT_PATH = "ubiquibot-config-default.json"; -const KEY_NAME = "private-key-encrypted"; +const PRIVATE_ENCRYPTED_KEY_NAME = "privateKeyEncrypted"; +const EVM_NETWORK_KEY_NAME = "evmNetworkId"; const KEY_PREFIX = "HSK_"; const X25519_KEY = "5ghIlfGjz_ChcYlBDOG7dzmgAgBPuTahpvTMBipSH00"; @@ -147,9 +148,8 @@ const sodiumEncryptedSeal = async (publicKey: string, secret: string) => { const binsec = sodium.from_string(secret); const encBytes = sodium.crypto_box_seal(binsec, binkey); const output = sodium.to_base64(encBytes, sodium.base64_variants.URLSAFE_NO_PADDING); - // defaultConf[KEY_NAME] = output; - defaultConf["evmNetworkId"] = Number(chainIdSelect.value); - // defaultConf["safe-address"] = safeAddressInput.value; + defaultConf[PRIVATE_ENCRYPTED_KEY_NAME] = output; + defaultConf[EVM_NETWORK_KEY_NAME] = Number(chainIdSelect.value); outKey.value = YAMLStringify(defaultConf); outKey.style.height = getTextBox(outKey.value); encryptedValue = output; @@ -225,9 +225,8 @@ const setConfig = async () => { const updatedConf = defaultConf; const parsedConf = await parseYAML(conf); - // updatedConf[KEY_NAME] = encryptedValue; - updatedConf["evmNetworkId"] = Number(chainIdSelect.value); - // updatedConf["safe-address"] = safeAddressInput.value; + updatedConf[PRIVATE_ENCRYPTED_KEY_NAME] = encryptedValue; + updatedConf[EVM_NETWORK_KEY_NAME] = Number(chainIdSelect.value); // combine configs (default + remote org wide) const combinedConf = Object.assign(updatedConf, parsedConf); From b556272402f934be15a8f1bb180ea909243b5c9c Mon Sep 17 00:00:00 2001 From: Fernando Date: Tue, 13 Feb 2024 17:04:50 +0900 Subject: [PATCH 3/9] chore: set private key to empty string to init conf --- static/scripts/onboarding/onboarding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/scripts/onboarding/onboarding.ts b/static/scripts/onboarding/onboarding.ts index 081bb40d..7d035fcb 100644 --- a/static/scripts/onboarding/onboarding.ts +++ b/static/scripts/onboarding/onboarding.ts @@ -479,7 +479,7 @@ const init = async () => { throw new Error("Configuration could not be parsed!") } defaultConf = parsedConf; - // defaultConf["private-key-encrypted"] = ""; + defaultConf[PRIVATE_ENCRYPTED_KEY_NAME] = ""; setInputListeners(); setBtn.addEventListener("click", async () => { From baf6f8de317402c52f144ec76873f409736043d7 Mon Sep 17 00:00:00 2001 From: Fernando Date: Thu, 15 Feb 2024 14:05:48 +0900 Subject: [PATCH 4/9] chore: removed default conf fetch as it is already imported in the submodule --- static/scripts/onboarding/onboarding.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/static/scripts/onboarding/onboarding.ts b/static/scripts/onboarding/onboarding.ts index 7d035fcb..7ee0bc17 100644 --- a/static/scripts/onboarding/onboarding.ts +++ b/static/scripts/onboarding/onboarding.ts @@ -471,14 +471,8 @@ const step2Handler = async () => { }; const init = async () => { - let conf = await getConf(true); - if (conf !== undefined) { + if (defaultConf !== undefined) { try { - const parsedConf = JSON.parse(conf) as MergedConfig; - if (!parsedConf) { - throw new Error("Configuration could not be parsed!") - } - defaultConf = parsedConf; defaultConf[PRIVATE_ENCRYPTED_KEY_NAME] = ""; setInputListeners(); From ef0b7b3f3858259a52beb92d6245fe13b1e2d71f Mon Sep 17 00:00:00 2001 From: Fernando Date: Thu, 15 Feb 2024 16:41:45 +0900 Subject: [PATCH 5/9] chore: changed privateKeyEncrypted to be undefined by default --- static/scripts/onboarding/onboarding.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/scripts/onboarding/onboarding.ts b/static/scripts/onboarding/onboarding.ts index 7ee0bc17..c763c707 100644 --- a/static/scripts/onboarding/onboarding.ts +++ b/static/scripts/onboarding/onboarding.ts @@ -473,7 +473,7 @@ const step2Handler = async () => { const init = async () => { if (defaultConf !== undefined) { try { - defaultConf[PRIVATE_ENCRYPTED_KEY_NAME] = ""; + defaultConf[PRIVATE_ENCRYPTED_KEY_NAME] = undefined; setInputListeners(); setBtn.addEventListener("click", async () => { From 24618d6907334108c3c82872f8467b68eec71775 Mon Sep 17 00:00:00 2001 From: Fernando Date: Thu, 15 Feb 2024 17:32:44 +0900 Subject: [PATCH 6/9] chore: added back safe-address --- static/scripts/onboarding/onboarding.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/static/scripts/onboarding/onboarding.ts b/static/scripts/onboarding/onboarding.ts index c763c707..d4c48803 100644 --- a/static/scripts/onboarding/onboarding.ts +++ b/static/scripts/onboarding/onboarding.ts @@ -36,10 +36,10 @@ const X25519_KEY = "5ghIlfGjz_ChcYlBDOG7dzmgAgBPuTahpvTMBipSH00"; let encryptedValue = ""; -let defaultConf = DefaultConfig +let defaultConf = { ...DefaultConfig, "safe-address": "" }; export const parseYAML = async (data: string | undefined) => { - if (!data) return undefined + if (!data) return undefined; try { const parsedData = await YAML.parse(data); if (parsedData !== null) { @@ -150,6 +150,7 @@ const sodiumEncryptedSeal = async (publicKey: string, secret: string) => { const output = sodium.to_base64(encBytes, sodium.base64_variants.URLSAFE_NO_PADDING); defaultConf[PRIVATE_ENCRYPTED_KEY_NAME] = output; defaultConf[EVM_NETWORK_KEY_NAME] = Number(chainIdSelect.value); + defaultConf["safe-address"] = safeAddressInput.value; outKey.value = YAMLStringify(defaultConf); outKey.style.height = getTextBox(outKey.value); encryptedValue = output; @@ -224,9 +225,10 @@ const setConfig = async () => { const conf = await getConf(); const updatedConf = defaultConf; - const parsedConf = await parseYAML(conf); + const parsedConf = await parseYAML(conf); updatedConf[PRIVATE_ENCRYPTED_KEY_NAME] = encryptedValue; updatedConf[EVM_NETWORK_KEY_NAME] = Number(chainIdSelect.value); + defaultConf["safe-address"] = safeAddressInput.value; // combine configs (default + remote org wide) const combinedConf = Object.assign(updatedConf, parsedConf); From 3819fb93ef79228dc226c6603619756bada96e49 Mon Sep 17 00:00:00 2001 From: Fernando Date: Thu, 15 Feb 2024 17:39:58 +0900 Subject: [PATCH 7/9] chore: removed unused constants --- static/scripts/onboarding/onboarding.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/static/scripts/onboarding/onboarding.ts b/static/scripts/onboarding/onboarding.ts index d4c48803..98966069 100644 --- a/static/scripts/onboarding/onboarding.ts +++ b/static/scripts/onboarding/onboarding.ts @@ -24,11 +24,8 @@ const chainIdSelect = document.getElementById("chainId") as HTMLSelectElement; const loader = document.querySelector(".loader-wrap") as HTMLElement; const APP_ID = 236521; -const DEFAULT_ORG = "ubiquity"; const REPO_NAME = "ubiquibot-config"; -const DEFAULT_REPO = "ubiquibot"; const KEY_PATH = ".github/ubiquibot-config.yml"; -const DEFAULT_PATH = "ubiquibot-config-default.json"; const PRIVATE_ENCRYPTED_KEY_NAME = "privateKeyEncrypted"; const EVM_NETWORK_KEY_NAME = "evmNetworkId"; const KEY_PREFIX = "HSK_"; @@ -63,13 +60,13 @@ export const parseJSON = async (data: string) => { export const YAMLStringify = (value: any) => YAML.stringify(value, { defaultKeyType: "PLAIN", defaultStringType: "QUOTE_DOUBLE", lineWidth: 0 }); -export const getConf = async (initial: boolean = false): Promise => { +export const getConf = async (): Promise => { try { const octokit = new Octokit({ auth: githubPAT.value }); const { data } = await octokit.rest.repos.getContent({ - owner: initial ? DEFAULT_ORG : orgName.value, - repo: initial ? DEFAULT_REPO : REPO_NAME, - path: initial ? DEFAULT_PATH : KEY_PATH, + owner: orgName.value, + repo: REPO_NAME, + path: KEY_PATH, mediaType: { format: "raw", }, From 41006a281cefa5d38d1ae329253918129881d847 Mon Sep 17 00:00:00 2001 From: Fernando Date: Fri, 16 Feb 2024 01:21:30 +0900 Subject: [PATCH 8/9] chore: removed unused safe-address --- static/onboarding.html | 5 ----- static/scripts/onboarding/onboarding.ts | 16 +--------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/static/onboarding.html b/static/onboarding.html index 9ab078a9..23953483 100644 --- a/static/onboarding.html +++ b/static/onboarding.html @@ -33,11 +33,6 @@

Onboarding

-
- - - -
diff --git a/static/scripts/onboarding/onboarding.ts b/static/scripts/onboarding/onboarding.ts index 98966069..69e3947e 100644 --- a/static/scripts/onboarding/onboarding.ts +++ b/static/scripts/onboarding/onboarding.ts @@ -33,7 +33,7 @@ const X25519_KEY = "5ghIlfGjz_ChcYlBDOG7dzmgAgBPuTahpvTMBipSH00"; let encryptedValue = ""; -let defaultConf = { ...DefaultConfig, "safe-address": "" }; +let defaultConf = DefaultConfig; export const parseYAML = async (data: string | undefined) => { if (!data) return undefined; @@ -147,7 +147,6 @@ const sodiumEncryptedSeal = async (publicKey: string, secret: string) => { const output = sodium.to_base64(encBytes, sodium.base64_variants.URLSAFE_NO_PADDING); defaultConf[PRIVATE_ENCRYPTED_KEY_NAME] = output; defaultConf[EVM_NETWORK_KEY_NAME] = Number(chainIdSelect.value); - defaultConf["safe-address"] = safeAddressInput.value; outKey.value = YAMLStringify(defaultConf); outKey.style.height = getTextBox(outKey.value); encryptedValue = output; @@ -225,7 +224,6 @@ const setConfig = async () => { const parsedConf = await parseYAML(conf); updatedConf[PRIVATE_ENCRYPTED_KEY_NAME] = encryptedValue; updatedConf[EVM_NETWORK_KEY_NAME] = Number(chainIdSelect.value); - defaultConf["safe-address"] = safeAddressInput.value; // combine configs (default + remote org wide) const combinedConf = Object.assign(updatedConf, parsedConf); @@ -391,18 +389,6 @@ const step1Handler = async () => { singleToggle("warn", `Warn: GitHub PAT is not set.`, githubPAT); return; } - if (!safeAddressInput.value.startsWith("0x")) { - singleToggle("warn", `Warn: Safe Address must start with 0x.`, safeAddressInput); - return; - } - if (!isHex(safeAddressInput.value.substring(2))) { - singleToggle("warn", `Warn: Safe Address is not a valid hex string.`, safeAddressInput); - return; - } - if (safeAddressInput.value.length !== 42) { - singleToggle("warn", `Warn: Safe Address must be 20 bytes long.`, safeAddressInput); - return; - } await sodiumEncryptedSeal(X25519_KEY, `${KEY_PREFIX}${walletPrivateKey.value}`); setConfig(); From 6c9239ab47930e514430650f1c9beed0b5ce1e5a Mon Sep 17 00:00:00 2001 From: Fernando Date: Fri, 16 Feb 2024 01:25:10 +0900 Subject: [PATCH 9/9] chore: submodule checkout --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f889017f..7e8052a6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,6 +17,8 @@ jobs: steps: - name: Checkout repository uses: actions/checkout@v3 + with: + submodules: recursive - name: Setup Node uses: actions/setup-node@v3