diff --git a/src/adapters/supabase/helpers/client.ts b/src/adapters/supabase/helpers/client.ts index b8a3b23da..cca34de5a 100644 --- a/src/adapters/supabase/helpers/client.ts +++ b/src/adapters/supabase/helpers/client.ts @@ -469,37 +469,30 @@ 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, }; }; 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, + 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, nonce: data.nonce, deadline: data.deadline, + bountyHunterAddress: data.beneficiary, + walletOwnerAddress: data.owner, signature: data.signature, - walletOwnerAddress: data.wallet_owner_address, } as Permit; }; @@ -509,8 +502,8 @@ export const savePermit = async (permit: InsertPermit): Promise => { .from("permits") .insert({ ...getDbDataFromPermit(permit), - created_at: new Date().toISOString(), - id: undefined, // id is auto-generated + created: new Date().toISOString(), + updated: new Date().toISOString(), }) .select(); if (error) { diff --git a/src/handlers/payout/action.ts b/src/handlers/payout/action.ts index 25bf01562..c8075230b 100644 --- a/src/handlers/payout/action.ts +++ b/src/handlers/payout/action.ts @@ -505,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)}`); 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; diff --git a/src/helpers/permit.ts b/src/helpers/permit.ts index deddcffe0..2ed9f3ab1 100644 --- a/src/helpers/permit.ts +++ b/src/helpers/permit.ts @@ -10,12 +10,9 @@ const PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; // same on export type Permit = { id: number; - createdAt: Date; - organizationId: number | null; - repositoryId: number; - issueId: number; + created: Date; + updated: 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, diff --git a/supabase/migrations/20230923153903_new_permit.sql b/supabase/migrations/20230923153903_new_permit.sql new file mode 100644 index 000000000..9d79126ba --- /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 timestamptz not null, + updated timestamptz not null, + network smallserial not null, + token text check (char_length(token) = 42) not null, + amount numeric not null, + nonce numeric not null, + deadline numeric 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 + new_permits ( + id, + created, + updated, + 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..8d8417069 --- /dev/null +++ b/supabase/migrations/20230923182214_fix_debit.sql @@ -0,0 +1,8 @@ +ALTER TABLE Debits +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