diff --git a/.gitmodules b/.gitmodules index c93a2e2..9b3aa47 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,7 +1,3 @@ -[submodule "lib/ubiquibot"] - path = lib/ubiquibot - url = https://github.com/ubiquity/ubiquibot - branch = development [submodule "lib/chainlist"] path = lib/chainlist url = https://github.com/DefiLlama/chainlist.git diff --git a/lib/ubiquibot b/lib/ubiquibot deleted file mode 160000 index cb08490..0000000 --- a/lib/ubiquibot +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cb084909ab332f67bba271b5a17b907d21716bd1 diff --git a/package.json b/package.json index d0e016b..2aa9cb6 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "@octokit/plugin-create-or-update-text-file": "^4.0.1", "@octokit/rest": "^20.0.2", "@types/libsodium-wrappers": "^0.7.13", + "@ubiquibot/configuration": "1.1.0", "@uniswap/permit2-sdk": "^1.2.0", "dotenv": "^16.4.4", "ethers": "^5.7.2", diff --git a/static/scripts/onboarding/onboarding.ts b/static/scripts/onboarding/onboarding.ts index 4f263bb..d067538 100644 --- a/static/scripts/onboarding/onboarding.ts +++ b/static/scripts/onboarding/onboarding.ts @@ -1,12 +1,12 @@ import { JsonRpcSigner } from "@ethersproject/providers"; import { createOrUpdateTextFile } from "@octokit/plugin-create-or-update-text-file"; import { Octokit } from "@octokit/rest"; +import { BotConfig, generateConfiguration } from "@ubiquibot/configuration"; import { PERMIT2_ADDRESS } from "@uniswap/permit2-sdk"; import { ethers } from "ethers"; import { parseUnits } from "ethers/lib/utils"; import _sodium from "libsodium-wrappers"; import YAML from "yaml"; -import { BotConfig } from "../../../lib/ubiquibot/src/types/configuration-types"; import { erc20Abi } from "../rewards/abis/erc20Abi"; import { getNetworkName, NetworkIds, Tokens } from "../rewards/constants"; @@ -34,7 +34,7 @@ const STATUS_LOG = ".status-log"; let encryptedValue = ""; -const defaultConf = {} as BotConfig; +const defaultConf = generateConfiguration(); export async function parseYAML(data: string | undefined) { if (!data) return undefined; @@ -63,23 +63,6 @@ export function stringifyYAML(value: BotConfig): string { return YAML.stringify(value, { defaultKeyType: "PLAIN", defaultStringType: "QUOTE_DOUBLE", lineWidth: 0 }); } -export async function getConf(): Promise { - try { - const octokit = new Octokit({ auth: githubPAT.value }); - const { data } = await octokit.rest.repos.getContent({ - owner: orgName.value, - repo: REPO_NAME, - path: KEY_PATH, - mediaType: { - format: "raw", - }, - }); - return data as unknown as string; - } catch (error: unknown) { - return undefined; - } -} - function getTextBox(text: string) { const strLen = text.split("\n").length * 22; return `${strLen > 140 ? strLen : 140}px`; @@ -216,17 +199,14 @@ async function handleInstall( }); } - const conf = await getConf(); - const updatedConf = defaultConf; - const parsedConf = await parseYAML(conf); updatedConf.keys[PRIVATE_ENCRYPTED_KEY_NAME] = encryptedValue; updatedConf.payments[EVM_NETWORK_KEY_NAME] = Number(chainIdSelect.value); // combine configs (default + remote org wide) - const combinedConf = Object.assign(updatedConf, parsedConf); + const combinedConf = Object.assign(updatedConf, defaultConf); - const stringified = stringifyYAML(combinedConf); + const stringified = btoa(stringifyYAML(combinedConf)); outKey.value = stringified; const { status } = await octokit.repos.createOrUpdateFileContents({ owner: orgName.value, diff --git a/static/types/window.d.ts b/static/types/window.d.ts new file mode 100644 index 0000000..438620a --- /dev/null +++ b/static/types/window.d.ts @@ -0,0 +1,7 @@ +import { ExternalProvider } from "@ethersproject/providers"; + +declare global { + interface Window { + ethereum: ExternalProvider & { on: (event: string, callback) => void }; + } +} diff --git a/yarn.lock b/yarn.lock index ef244dc..9f82467 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1500,6 +1500,11 @@ "@pnpm/resolve-workspace-range" "5.0.1" ramda "npm:@pnpm/ramda@0.28.1" +"@sinclair/typebox@0.32.14": + version "0.32.14" + resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.32.14.tgz#ef0a4ed981515fd430cadfb65cb6c2719a0b5539" + integrity sha512-EC77Mw8huT2z9YlYbWfpIQgN6shZE1tH4NP4/Trig8UBel9FZNMZRJ42ubJI8PLor2uIU+waLml1dce5ReCOPg== + "@snyk/github-codeowners@1.1.0": version "1.1.0" resolved "https://registry.yarnpkg.com/@snyk/github-codeowners/-/github-codeowners-1.1.0.tgz#45b99732c3c38b5f5b47e43d2b0c9db67a6d2bcc" @@ -1632,6 +1637,18 @@ "@typescript-eslint/types" "7.0.1" eslint-visitor-keys "^3.4.1" +"@ubiquibot/configuration@1.1.0": + version "1.1.0" + resolved "https://registry.yarnpkg.com/@ubiquibot/configuration/-/configuration-1.1.0.tgz#f6846fecd8b95ab115eb6e82cb788a86afb977b6" + integrity sha512-Qny3W7YbbJ46YNiU8gxT81eS6rBcmjibpzGo8qbt3n8o7e8ZuAMJOeIL8MmBya2tO/v2nn3Txnv3ZNmb6QMjpg== + dependencies: + "@sinclair/typebox" "0.32.14" + ajv "8.12.0" + ajv-formats "2.1.1" + dotenv "16.4.4" + lodash "4.17.21" + ms "2.1.3" + "@ungap/structured-clone@^1.2.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@ungap/structured-clone/-/structured-clone-1.2.0.tgz#756641adb587851b5ccb3e095daf27ae581c8406" @@ -1688,17 +1705,14 @@ aggregate-error@^3.0.0: clean-stack "^2.0.0" indent-string "^4.0.0" -ajv@^6.12.4: - version "6.12.6" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" - integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== +ajv-formats@2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/ajv-formats/-/ajv-formats-2.1.1.tgz#6e669400659eb74973bbf2e33327180a0996b520" + integrity sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA== dependencies: - fast-deep-equal "^3.1.1" - fast-json-stable-stringify "^2.0.0" - json-schema-traverse "^0.4.1" - uri-js "^4.2.2" + ajv "^8.0.0" -ajv@^8.11.0: +ajv@8.12.0, ajv@^8.0.0, ajv@^8.11.0: version "8.12.0" resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.12.0.tgz#d1a0527323e22f53562c567c00991577dfbe19d1" integrity sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA== @@ -1708,6 +1722,16 @@ ajv@^8.11.0: require-from-string "^2.0.2" uri-js "^4.2.2" +ajv@^6.12.4: + version "6.12.6" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4" + integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g== + dependencies: + fast-deep-equal "^3.1.1" + fast-json-stable-stringify "^2.0.0" + json-schema-traverse "^0.4.1" + uri-js "^4.2.2" + ansi-escapes@^6.2.0: version "6.2.0" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-6.2.0.tgz#8a13ce75286f417f1963487d86ba9f90dccf9947" @@ -2353,7 +2377,7 @@ dot-prop@^6.0.1: dependencies: is-obj "^2.0.0" -dotenv@^16.4.4: +dotenv@16.4.4, dotenv@^16.4.4: version "16.4.4" resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.4.tgz#a26e7bb95ebd36272ebb56edb80b826aecf224c1" integrity sha512-XvPXc8XAQThSjAbY6cQ/9PcBXmFoWuw1sQ3b8HqUCR6ziGXjkTi//kB9SWa2UwqlgdAIuRqAa/9hVljzPehbYg== @@ -3755,7 +3779,7 @@ lodash.upperfirst@^4.3.1: resolved "https://registry.yarnpkg.com/lodash.upperfirst/-/lodash.upperfirst-4.3.1.tgz#1365edf431480481ef0d1c68957a5ed99d49f7ce" integrity sha512-sReKOYJIJf74dhJONhU4e0/shzi1trVbSWDOhKYE5XV2O+H7Sb2Dihwuc7xWxVl+DgFPyTqIN3zMfT9cq5iWDg== -lodash@^4.17.15: +lodash@4.17.21, lodash@^4.17.15: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== @@ -3941,6 +3965,11 @@ ms@2.1.2: resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009" integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== +ms@2.1.3: + version "2.1.3" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.3.tgz#574c8138ce1d2b5861f0b44579dbadd60c6615b2" + integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7"