Skip to content

Commit

Permalink
fix: default configuration undefined value (#7)
Browse files Browse the repository at this point in the history
* chore: push everything including commits

* chore: update lib

* chore: update lib

* chore: update

* chore: update

* chore: update

* chore: update

* chore: update deploy

* chore: please knip

* fix: updated ubiquibot package and removed submodule

* fix: the remote config now comes from the package and not a fetch

---------

Co-authored-by: molecula451 <[email protected]>
  • Loading branch information
Fernand and molecula451 authored Mar 4, 2024
1 parent 3510c8f commit 4ffd7d2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 40 deletions.
4 changes: 0 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/ubiquibot
Submodule ubiquibot deleted from cb0849
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
28 changes: 4 additions & 24 deletions static/scripts/onboarding/onboarding.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -34,7 +34,7 @@ const STATUS_LOG = ".status-log";

let encryptedValue = "";

const defaultConf = {} as BotConfig;
const defaultConf = generateConfiguration();

export async function parseYAML<T>(data: string | undefined) {
if (!data) return undefined;
Expand Down Expand Up @@ -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<string | undefined> {
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`;
Expand Down Expand Up @@ -216,17 +199,14 @@ async function handleInstall(
});
}

const conf = await getConf();

const updatedConf = defaultConf;
const parsedConf = await parseYAML<BotConfig>(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,
Expand Down
7 changes: 7 additions & 0 deletions static/types/window.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ExternalProvider } from "@ethersproject/providers";

declare global {
interface Window {
ethereum: ExternalProvider & { on: (event: string, callback) => void };
}
}
51 changes: 40 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,11 @@
"@pnpm/resolve-workspace-range" "5.0.1"
ramda "npm:@pnpm/[email protected]"

"@sinclair/[email protected]":
version "0.32.14"
resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.32.14.tgz#ef0a4ed981515fd430cadfb65cb6c2719a0b5539"
integrity sha512-EC77Mw8huT2z9YlYbWfpIQgN6shZE1tH4NP4/Trig8UBel9FZNMZRJ42ubJI8PLor2uIU+waLml1dce5ReCOPg==

"@snyk/[email protected]":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@snyk/github-codeowners/-/github-codeowners-1.1.0.tgz#45b99732c3c38b5f5b47e43d2b0c9db67a6d2bcc"
Expand Down Expand Up @@ -1632,6 +1637,18 @@
"@typescript-eslint/types" "7.0.1"
eslint-visitor-keys "^3.4.1"

"@ubiquibot/[email protected]":
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"
Expand Down Expand Up @@ -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[email protected]:
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==
Expand All @@ -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"
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -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==
Expand Down Expand Up @@ -3941,6 +3965,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.2.tgz#d09d1f357b443f493382a8eb3ccd183872ae6009"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

[email protected]:
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"
Expand Down

0 comments on commit 4ffd7d2

Please sign in to comment.