From bfc9787351ffeb0e92f98362eb56e4a6a73c0b16 Mon Sep 17 00:00:00 2001 From: Seprintour Date: Sat, 23 Sep 2023 19:23:45 +0100 Subject: [PATCH 1/7] chore: create permit table and move data --- .../migrations/20230923153903_new_permit.sql | 48 +++++++++++++++++++ .../migrations/20230923182214_fix_debit.sql | 2 + 2 files changed, 50 insertions(+) create mode 100644 supabase/migrations/20230923153903_new_permit.sql create mode 100644 supabase/migrations/20230923182214_fix_debit.sql diff --git a/supabase/migrations/20230923153903_new_permit.sql b/supabase/migrations/20230923153903_new_permit.sql new file mode 100644 index 000000000..7f321169e --- /dev/null +++ b/supabase/migrations/20230923153903_new_permit.sql @@ -0,0 +1,48 @@ +CREATE TABLE IF NOT EXISTS + new_permits ( + id serial primary key, + created_at timestamptz not null, + updated_at timestamptz not null, + network smallserial not null, + token char(42) not null, + amount numeric not null, + nonce numeric not null, + deadline numeric not null, + beneficiary char(42) not null, + owner char(42) not null, + signature char(132) not null + ); + +INSERT INTO + new_permits ( + id, + created_at, + updated_at, + network, + token, + amount, + nonce, + deadline, + beneficiary, + owner, + signature + ) +SELECT + id, + created_at, + created_at, + network_id, + token_address, + CAST(payout_amount AS numeric), + CAST(nonce AS numeric), + CAST(deadline AS numeric), + bounty_hunter_address, + wallet_owner_address, + signature +FROM + permits; + +DROP TABLE permits; + +ALTER TABLE new_permits +RENAME TO permits; \ No newline at end of file diff --git a/supabase/migrations/20230923182214_fix_debit.sql b/supabase/migrations/20230923182214_fix_debit.sql new file mode 100644 index 000000000..f2a5086b6 --- /dev/null +++ b/supabase/migrations/20230923182214_fix_debit.sql @@ -0,0 +1,2 @@ +ALTER TABLE Debits +ALTER COLUMN amount TYPE NUMERIC; \ No newline at end of file From e26a67320c0c1cb1fc38d4617b7f63081606ef37 Mon Sep 17 00:00:00 2001 From: Seprintour Date: Sun, 24 Sep 2023 15:23:12 +0100 Subject: [PATCH 2/7] chore: save permit to db --- src/adapters/supabase/helpers/client.ts | 31 +++++++------------ .../migrations/20230923153903_new_permit.sql | 8 ++--- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/src/adapters/supabase/helpers/client.ts b/src/adapters/supabase/helpers/client.ts index 480ecd0f9..9321bbe34 100644 --- a/src/adapters/supabase/helpers/client.ts +++ b/src/adapters/supabase/helpers/client.ts @@ -469,18 +469,14 @@ export const removePenalty = async (username: string, repoName: string, tokenAdd const getDbDataFromPermit = (permit: InsertPermit): Record => { return { - organization_id: permit.organizationId, - repository_id: permit.repositoryId, - issue_id: permit.issueId, - network_id: permit.networkId, - bounty_hunter_id: permit.bountyHunterId, - token_address: permit.tokenAddress, - payout_amount: permit.payoutAmount, - bounty_hunter_address: permit.bountyHunterAddress, + network: permit.networkId, + token: permit.tokenAddress, + amount: permit.payoutAmount, nonce: permit.nonce, deadline: permit.deadline, + beneficiary: permit.bountyHunterAddress, + owner: permit.walletOwnerAddress, signature: permit.signature, - wallet_owner_address: permit.walletOwnerAddress, }; }; @@ -488,18 +484,15 @@ const getPermitFromDbData = (data: Record): Permit => { return { id: data.id, createdAt: new Date(Date.parse(data.created_at as string)), - organizationId: data.organization_id, - repositoryId: data.repository_i, - issueId: data.issue_id, - networkId: data.network_id, - bountyHunterId: data.bounty_hunter_id, - tokenAddress: data.token_address, - payoutAmount: data.payout_amount, - bountyHunterAddress: data.bounty_hunter_address, + updatedAt: new Date(Date.parse(data.updated_at as string)), + network: data.network, + token: data.token, + amount: data.amount, nonce: data.nonce, deadline: data.deadline, + beneficiary: data.beneficiary, + owner: data.owner, signature: data.signature, - walletOwnerAddress: data.wallet_owner_address, } as Permit; }; @@ -510,7 +503,7 @@ export const savePermit = async (permit: InsertPermit): Promise => { .insert({ ...getDbDataFromPermit(permit), created_at: new Date().toISOString(), - id: undefined, // id is auto-generated + updated_at: new Date().toISOString(), }) .select(); if (error) { diff --git a/supabase/migrations/20230923153903_new_permit.sql b/supabase/migrations/20230923153903_new_permit.sql index 7f321169e..df59ffb08 100644 --- a/supabase/migrations/20230923153903_new_permit.sql +++ b/supabase/migrations/20230923153903_new_permit.sql @@ -4,13 +4,13 @@ CREATE TABLE IF NOT EXISTS created_at timestamptz not null, updated_at timestamptz not null, network smallserial not null, - token char(42) not null, + token varchar(42) not null, amount numeric not null, nonce numeric not null, deadline numeric not null, - beneficiary char(42) not null, - owner char(42) not null, - signature char(132) not null + beneficiary varchar(42) not null, + owner varchar(42) not null, + signature varchar(132) not null ); INSERT INTO From 23977fe95c734dfe362c31ab7986dde00f2c2d0f Mon Sep 17 00:00:00 2001 From: Seprintour Date: Sun, 24 Sep 2023 15:27:41 +0100 Subject: [PATCH 3/7] chore: permit fully setup --- src/adapters/supabase/helpers/client.ts | 10 +++++----- src/handlers/payout/action.ts | 2 +- src/helpers/permit.ts | 15 ++++----------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/adapters/supabase/helpers/client.ts b/src/adapters/supabase/helpers/client.ts index 9321bbe34..f93311862 100644 --- a/src/adapters/supabase/helpers/client.ts +++ b/src/adapters/supabase/helpers/client.ts @@ -485,13 +485,13 @@ const getPermitFromDbData = (data: Record): Permit => { id: data.id, createdAt: new Date(Date.parse(data.created_at as string)), updatedAt: new Date(Date.parse(data.updated_at as string)), - network: data.network, - token: data.token, - amount: data.amount, + networkId: data.network, + tokenAddress: data.token, + payoutAmount: data.amount, nonce: data.nonce, deadline: data.deadline, - beneficiary: data.beneficiary, - owner: data.owner, + bountyHunterAddress: data.beneficiary, + walletOwnerAddress: data.owner, signature: data.signature, } as Permit; }; diff --git a/src/handlers/payout/action.ts b/src/handlers/payout/action.ts index 0afe9c424..21ae2e4b3 100644 --- a/src/handlers/payout/action.ts +++ b/src/handlers/payout/action.ts @@ -442,7 +442,7 @@ export const handleIssueClosed = async ( ); } - await savePermitToDB(incentivesCalculation.assignee.id, txData); + await savePermitToDB(txData); } // MERGE ALL REWARDS diff --git a/src/helpers/permit.ts b/src/helpers/permit.ts index 064b8918c..fe561348b 100644 --- a/src/helpers/permit.ts +++ b/src/helpers/permit.ts @@ -11,11 +11,8 @@ const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; // same on export type Permit = { id: number; createdAt: Date; - organizationId: number | null; - repositoryId: number; - issueId: number; + updatedAt: Date; networkId: number; - bountyHunterId: number; bountyHunterAddress: string; tokenAddress: string; payoutAmount: string; @@ -25,7 +22,7 @@ export type Permit = { walletOwnerAddress: string; }; -export type InsertPermit = Omit; +export type InsertPermit = Omit; type TxData = { permit: { @@ -106,14 +103,14 @@ export const generatePermit2Signature = async ( return { txData, payoutUrl }; }; -export const savePermitToDB = async (bountyHunterId: number, txData: TxData): Promise => { +export const savePermitToDB = async (txData: TxData): Promise => { const logger = getLogger(); const context = getBotContext(); const payload = context.payload as Payload; const issue = payload.issue; const repository = payload.repository; - const organization = payload.organization; + //const organization = payload.organization; if (!issue || !repository) { logger.error("Cannot save permit to DB, missing issue, repository or organization"); throw new Error("Cannot save permit to DB, missing issue, repository or organization"); @@ -123,11 +120,7 @@ export const savePermitToDB = async (bountyHunterId: number, txData: TxData): Pr const { networkId } = payout; const permit: InsertPermit = { - organizationId: organization?.id ?? null, - repositoryId: repository?.id, - issueId: issue?.id, networkId: networkId, - bountyHunterId: bountyHunterId, tokenAddress: txData.permit.permitted.token, payoutAmount: txData.permit.permitted.amount, bountyHunterAddress: txData.transferDetails.to, From 07ad3457382b5935679e6dfeea06d0f1d8e112d5 Mon Sep 17 00:00:00 2001 From: Seprintour Date: Mon, 25 Sep 2023 19:59:08 +0100 Subject: [PATCH 4/7] chore: remove all _at suffix --- src/adapters/supabase/helpers/client.ts | 8 ++++---- src/helpers/permit.ts | 6 +++--- supabase/migrations/20230923153903_new_permit.sql | 8 ++++---- supabase/migrations/20230923182214_fix_debit.sql | 8 +++++++- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/adapters/supabase/helpers/client.ts b/src/adapters/supabase/helpers/client.ts index f93311862..a3055e11c 100644 --- a/src/adapters/supabase/helpers/client.ts +++ b/src/adapters/supabase/helpers/client.ts @@ -483,8 +483,8 @@ const getDbDataFromPermit = (permit: InsertPermit): Record => { const getPermitFromDbData = (data: Record): Permit => { return { id: data.id, - createdAt: new Date(Date.parse(data.created_at as string)), - updatedAt: new Date(Date.parse(data.updated_at as string)), + created: new Date(Date.parse(data.created as string)), + updated: new Date(Date.parse(data.updated as string)), networkId: data.network, tokenAddress: data.token, payoutAmount: data.amount, @@ -502,8 +502,8 @@ export const savePermit = async (permit: InsertPermit): Promise => { .from("permits") .insert({ ...getDbDataFromPermit(permit), - created_at: new Date().toISOString(), - updated_at: new Date().toISOString(), + created: new Date().toISOString(), + updated: new Date().toISOString(), }) .select(); if (error) { diff --git a/src/helpers/permit.ts b/src/helpers/permit.ts index fe561348b..99685f95b 100644 --- a/src/helpers/permit.ts +++ b/src/helpers/permit.ts @@ -10,8 +10,8 @@ const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; // same on export type Permit = { id: number; - createdAt: Date; - updatedAt: Date; + created: Date; + updated: Date; networkId: number; bountyHunterAddress: string; tokenAddress: string; @@ -22,7 +22,7 @@ export type Permit = { walletOwnerAddress: string; }; -export type InsertPermit = Omit; +export type InsertPermit = Omit; type TxData = { permit: { diff --git a/supabase/migrations/20230923153903_new_permit.sql b/supabase/migrations/20230923153903_new_permit.sql index df59ffb08..706fc6603 100644 --- a/supabase/migrations/20230923153903_new_permit.sql +++ b/supabase/migrations/20230923153903_new_permit.sql @@ -1,8 +1,8 @@ CREATE TABLE IF NOT EXISTS new_permits ( id serial primary key, - created_at timestamptz not null, - updated_at timestamptz not null, + created timestamptz not null, + updated timestamptz not null, network smallserial not null, token varchar(42) not null, amount numeric not null, @@ -16,8 +16,8 @@ CREATE TABLE IF NOT EXISTS INSERT INTO new_permits ( id, - created_at, - updated_at, + created, + updated, network, token, amount, diff --git a/supabase/migrations/20230923182214_fix_debit.sql b/supabase/migrations/20230923182214_fix_debit.sql index f2a5086b6..8d8417069 100644 --- a/supabase/migrations/20230923182214_fix_debit.sql +++ b/supabase/migrations/20230923182214_fix_debit.sql @@ -1,2 +1,8 @@ ALTER TABLE Debits -ALTER COLUMN amount TYPE NUMERIC; \ No newline at end of file +ALTER COLUMN amount TYPE NUMERIC; + +ALTER TABLE Debits +RENAME COLUMN created_at TO created; + +ALTER TABLE Debits +RENAME COLUMN updated_at TO updated; \ No newline at end of file From f20f77e48eed6809a68418f81962f71079b98a3c Mon Sep 17 00:00:00 2001 From: Seprintour Date: Sat, 30 Sep 2023 10:06:08 +0100 Subject: [PATCH 5/7] chore: fix new changes error --- src/handlers/payout/action.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/handlers/payout/action.ts b/src/handlers/payout/action.ts index 833400a76..c8075230b 100644 --- a/src/handlers/payout/action.ts +++ b/src/handlers/payout/action.ts @@ -446,8 +446,6 @@ export const handleIssueClosed = async ( assigneeReward.reward[0].penaltyAmount ); } - - await savePermitToDB(txData); } // MERGE ALL REWARDS @@ -507,7 +505,7 @@ export const handleIssueClosed = async ( const comment = createDetailsTable(price, payoutUrl, reward.user, detailsValue, reward.debug); - await savePermitToDB(Number(reward.userId), txData); + await savePermitToDB(txData); permitComment += comment; logger.info(`Skipping to generate a permit url for missing accounts. fallback: ${JSON.stringify(conversationRewards.fallbackReward)}`); From 3d15f7ba88c8cec5ca3b49186b0cc463cb4b77a3 Mon Sep 17 00:00:00 2001 From: 0xcodercrane <108444211+0xcodercrane@users.noreply.github.com> Date: Wed, 4 Oct 2023 10:12:08 +0800 Subject: [PATCH 6/7] chore: fix warning --- src/helpers/comment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/comment.ts b/src/helpers/comment.ts index 7be39376c..1338aea44 100644 --- a/src/helpers/comment.ts +++ b/src/helpers/comment.ts @@ -99,7 +99,7 @@ export const createDetailsTable = ( if (!isEmpty(debug)) { const data = Object.entries(debug) - .filter(([_, value]) => value.count > 0) + .filter(([, value]) => value.count > 0) .map(([key, value]) => { const element = key === "#text" ? "words" : key; const units = value.count; From ca1edbc9e7e79ac5cedbae6564ecbaf0d4d2512e Mon Sep 17 00:00:00 2001 From: Seprintour Date: Mon, 9 Oct 2023 12:29:04 +0100 Subject: [PATCH 7/7] chore: text with checks --- supabase/migrations/20230923153903_new_permit.sql | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/supabase/migrations/20230923153903_new_permit.sql b/supabase/migrations/20230923153903_new_permit.sql index 706fc6603..9d79126ba 100644 --- a/supabase/migrations/20230923153903_new_permit.sql +++ b/supabase/migrations/20230923153903_new_permit.sql @@ -4,13 +4,13 @@ CREATE TABLE IF NOT EXISTS created timestamptz not null, updated timestamptz not null, network smallserial not null, - token varchar(42) not null, + token text check (char_length(token) = 42) not null, amount numeric not null, nonce numeric not null, deadline numeric not null, - beneficiary varchar(42) not null, - owner varchar(42) not null, - signature varchar(132) not null + beneficiary text check (char_length(beneficiary) = 42) not null, + owner text check (char_length(owner) = 42) not null, + signature text check (char_length(signature) = 132) not null ); INSERT INTO