Skip to content

Commit

Permalink
Merge pull request #21 from ubiquibot/development
Browse files Browse the repository at this point in the history
build: development to main
  • Loading branch information
gentlementlegen authored Jun 18, 2024
2 parents a54158a + f86cb3c commit 8f7c3bb
Show file tree
Hide file tree
Showing 31 changed files with 11,926 additions and 7,710 deletions.
3 changes: 2 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"Libsodium",
"ciphertext",
"tweetnacl",
"typeguards"
"typeguards",
"Numberish"
]
}
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
X25519_PRIVATE_KEY=
NFT_MINTER_PRIVATE_KEY=
SUPABASE_URL=
SUPABASE_ANON_KEY=
SUPABASE_KEY=
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"plugins": ["@typescript-eslint", "sonarjs"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:sonarjs/recommended"],
"ignorePatterns": ["**/*.js"],
"ignorePatterns": ["**/*.js", "src/adapters/supabase/types/database.ts"],
"rules": {
"prefer-arrow-callback": ["warn", { "allowNamedFunctions": true }],
"func-style": ["warn", "declaration", { "allowArrowFunctions": false }],
Expand Down
25 changes: 1 addition & 24 deletions .github/workflows/compute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,5 @@ jobs:

- name: Generate Permit
run: npx tsx ./src/index.ts
id: permit
env:
STATE_ID: ${{ github.event.inputs.stateId }}
EVENT_NAME: ${{ github.event.inputs.eventName }}
EVENT_PAYLOAD: ${{ github.event.inputs.eventPayload }}
SETTINGS: ${{ github.event.inputs.settings }}
AUTH_TOKEN: ${{ github.event.inputs.authToken }}
REF: ${{ github.event.inputs.ref }}

- name: Return Permit To The Kernel
uses: actions/github-script@v7
with:
script: |
const permitStr = '${{ steps.permit.outputs.result }}';
const permitObj = JSON.parse(permitStr);
await github.rest.repos.createDispatchEvent({
owner: "${{ github.repository }}".split("/")[0],
repo: "${{ github.repository }}".split("/")[1],
event_type: "return_data_to_ubiquibot_kernel",
client_payload: {
state_id: "${{ inputs.stateId }}",
output: JSON.stringify(permitObj),
},
});
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Binary file modified bun.lockb
Binary file not shown.
34 changes: 27 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ubiquibot/permit-generation",
"version": "1.0.0",
"version": "1.2.2",
"description": "ECR20 / ECR721 permit generation for automated payments.",
"author": "Ubiquity DAO",
"license": "MIT",
Expand Down Expand Up @@ -31,7 +31,7 @@
"@octokit/rest": "^20.0.2",
"@octokit/webhooks": "^13.1.0",
"@sinclair/typebox": "^0.32.5",
"@supabase/supabase-js": "^2.39.7",
"@supabase/supabase-js": "2.42.0",
"@uniswap/permit2-sdk": "^1.2.0",
"dotenv": "^16.4.4",
"ethers": "6.11.1",
Expand Down Expand Up @@ -64,7 +64,8 @@
"lint-staged": "^15.2.2",
"npm-run-all": "^4.1.5",
"prettier": "^3.2.5",
"rollup": "4.14.0",
"rollup": "4.14.3",
"rollup-plugin-delete": "2.0.0",
"rollup-plugin-dts-bundle-generator": "1.4.0",
"rollup-plugin-typescript2": "0.36.0",
"ts-jest": "29.1.2",
Expand All @@ -87,11 +88,30 @@
]
},
"files": [
"dist/*",
"dist/types/*",
"dist/handlers/*",
"dist/core/*",
"README.md",
"package.json"
],
"module": "dist/index.esm.js",
"main": "dist/index.js",
"typings": "dist/index.d.ts"
"module": "core/index.esm.js",
"main": "core/index.js",
"typings": "types/index.d.ts",
"exports": {
"./core": {
"require": "./dist/core/index.js",
"import": "./dist/core/index.js",
"types": "./dist/core/index.d.ts"
},
"./types": {
"require": "./dist/types/index.js",
"import": "./dist/types/index.js",
"types": "./dist/types/index.d.ts"
},
"./handlers": {
"require": "./dist/handlers/index.js",
"import": "./dist/handlers/index.js",
"types": "./dist/handlers/index.d.ts"
}
}
}
61 changes: 54 additions & 7 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,59 @@ import nodeResolve from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import terser from "@rollup/plugin-terser";
import del from "rollup-plugin-delete";

export default {
input: "src/index.ts",
output: {
dir: "dist",
format: "cjs",
/** @type {import("rollup").RollupOptions[]} */
const config = [
{
input: "src/types/index.ts",
output: {
dir: "dist/types",
format: "cjs",
},
plugins: [
del({ targets: ["dist/*"] }),
nodeResolve({ browser: true }),
commonjs(),
typescript(),
yaml(),
json(),
generateDtsBundle(),
terser(),
],
},
plugins: [nodeResolve(), commonjs(), typescript(), yaml(), json(), generateDtsBundle(), terser()],
};
{
input: "src/handlers/index.ts",
output: {
dir: "dist/handlers",
format: "cjs",
},
plugins: [
nodeResolve({ browser: true }),
commonjs(),
typescript(),
yaml(),
json(),
generateDtsBundle(),
terser(),
],
},
{
input: "src/index.ts",
output: {
dir: "dist/core",
format: "cjs",
},
plugins: [
nodeResolve(),
commonjs(),
typescript(),
yaml(),
json(),
generateDtsBundle(),
terser(),
],
},
];

export default config;
27 changes: 8 additions & 19 deletions src/adapters/supabase/helpers/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,30 @@ export class User extends Super {
super(supabase, context);
}

async getUsernameById(userId: number) {
const { data, error } = await this.supabase.from("users").select("username").eq("user_id", userId).single();
async getUserById(userId: number) {
const { data, error } = await this.supabase.from("users").select("*").eq("id", userId).single();
if (error) {
console.error(FAILED_TO_GET_USER, { userId, error });
throw error;
}

console.log(SUCCESSFULLY_FETCHED_USER, { userId, username: data?.username });
return data?.username;
}

async getUserIdByUsername(username: string) {
const { data, error } = await this.supabase.from("users").select("user_id").eq("username", username).single();
if (error) {
console.error(FAILED_TO_GET_USER, { username, error });
throw error;
}

console.log(SUCCESSFULLY_FETCHED_USER, { username, userId: data?.user_id });
return data?.user_id;
console.log(SUCCESSFULLY_FETCHED_USER, { userId, ...data });
return data;
}

async getUserIdByWallet(wallet: string) {
const { data, error } = await this.supabase.from("wallets").select("user_id").eq("address", wallet).single();
const { data, error } = await this.supabase.from("wallets").select("id").eq("address", wallet).single();
if (error) {
console.error(FAILED_TO_GET_USER, { wallet, error });
throw error;
}

console.log(SUCCESSFULLY_FETCHED_USER, { wallet, userId: data?.user_id });
return data?.user_id;
console.log(SUCCESSFULLY_FETCHED_USER, { wallet, userId: data?.id });
return data?.id.toString();
}

async upsertUser(userId: number, username: string) {
const { error } = await this.supabase.from("users").upsert({ user_id: userId, username }).select();
const { error } = await this.supabase.from("users").upsert({ id: userId, username }).select();
if (error) {
console.error("Failed to upsert user", { userId, username, error });
throw error;
Expand Down
40 changes: 11 additions & 29 deletions src/adapters/supabase/helpers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,31 @@ export class Wallet extends Super {
}

async getWalletByUserId(userId: number) {
const { data, error } = await this.supabase.from("wallets").select("address").eq("user_id", userId).single();
const { data, error } = await this.supabase.from("users").select("wallets(*)").eq("id", userId).single();
if (error) {
console.error("Failed to get wallet", { userId, error });
throw error;
}

console.info("Successfully fetched wallet", { userId, address: data.address });
return data.address;
console.info("Successfully fetched wallet", { userId, address: data.wallets?.address });
return data.wallets?.address;
}

async getWalletByUsername(username: string) {
const { data, error } = await this.supabase.from("users").select("id").eq("username", username).single();
if (error) {
console.error("Failed to get user", { username, error });
throw error;
}

const userId = data?.id;

if (!userId) {
console.error("Failed to get user", { username });
throw new Error("User not found");
}

const { data: walletData, error: walletError } = await this.supabase.from("wallets").select("address").eq("user_id", userId).single();
async upsertWallet(userId: number, address: string) {
const { error: walletError, data } = await this.supabase.from("wallets").upsert([{ address }]).select().single();

if (walletError) {
console.error("Failed to get wallet", { userId, error });
console.error("Failed to upsert wallet", { userId, address, walletError });
throw walletError;
}

console.info("Successfully fetched wallet", { userId, address: walletData?.address });

return walletData?.address as `0x${string}` | undefined;
}
const { error: userError } = await this.supabase.from("users").upsert([{ id: userId, wallet_id: data.id }]);

async upsertWallet(userId: number, address: string) {
const { error } = await this.supabase.from("wallets").upsert([{ user_id: userId.toString(), address }]);
if (error) {
console.error("Failed to upsert wallet", { userId, address, error });
throw error;
if (userError) {
console.error("Failed to upsert user with new wallet", { userId, address, userError });
throw userError;
}

console.info("Successfully upserted wallet", { userId, address });
console.info("Successfully upsert wallet", { userId, address });
}
}
Loading

0 comments on commit 8f7c3bb

Please sign in to comment.