Skip to content

Commit

Permalink
feat: permit generation module
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Apr 11, 2024
1 parent 08e7028 commit 50b396b
Show file tree
Hide file tree
Showing 12 changed files with 1,028 additions and 51 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/local-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
node-version: "20.10.0"

- name: Action Test
uses: gentlementlegen/conversation-rewards@feat/cli-issue-url
uses: gentlementlegen/conversation-rewards@feat/permit-generation
with:
issue_url: "https://github.com/ubiquibot/comment-incentives/issues/22"
issueUrl: "https://github.com/ubiquibot/comment-incentives/issues/22"
14 changes: 12 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ name: Run Local Tests

on:
workflow_dispatch:
inputs:
issueUrl:
description: "The URL the the issue needing to be parsed"
required: true
evmNetworkId:
description: "The EVM network ID to use"
required: true
evmPrivateEncrypted:
description: "The encrypted EVM private key"
required: true

jobs:
test:
Expand All @@ -18,6 +28,6 @@ jobs:
node-version: "20.10.0"

- name: Action Test
uses: gentlementlegen/conversation-rewards@feat/cli-issue-url
uses: gentlementlegen/conversation-rewards@feat/permit-generation
with:
issue_url: "https://github.com/ubiquibot/comment-incentives/issues/22"
issueUrl: ${{ inputs.issueUrl }}
16 changes: 16 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Release Please

on:
workflow_dispatch:
push:
branches:
- main

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v4
with:
release-type: simple
default-branch: main
10 changes: 8 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
name: "Conversation Rewards"
description: "Compute rewards for contributors' discussion on issues that are closed as complete."
inputs:
issue_url:
issueUrl:
description: "The URL the the issue needing to be parsed"
required: true
evmNetworkId:
description: "The EVM network ID to use"
required: true
evmPrivateEncrypted:
description: "The encrypted EVM private key"
required: true
outputs:
result:
description: "The result containing all the rewards of the users"
Expand All @@ -13,7 +19,7 @@ runs:
steps:
- run: |
yarn --cwd ${{ github.action_path }} --production=true
yarn --cwd ${{ github.action_path }} start --issue "${{ inputs.issue_url }}" --file "${{ github.action_path }}/results.json"
yarn --cwd ${{ github.action_path }} start --issue "${{ inputs.issueUrl }}" --file "${{ github.action_path }}/results.json"
output=$(cat ${{ github.action_path }}/results.json | tr -s ' ' | tr -d '\n')
echo "Output of calculations:"
echo "$output"
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
"open-source"
],
"dependencies": {
"@actions/github": "6.0.0",
"@commander-js/extra-typings": "12.0.1",
"@octokit/rest": "20.0.2",
"@octokit/rest": "20.1.0",
"@sinclair/typebox": "0.32.20",
"@supabase/supabase-js": "2.42.0",
"@ubiquibot/permit-generation": "1.0.0",
"commander": "12.0.0",
"decimal.js": "10.4.3",
"dotenv": "16.4.5",
Expand Down
2 changes: 2 additions & 0 deletions rewards-configuration.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ formattingEvaluator:
- type: [REVIEW, CONTRIBUTOR]:
formattingMultiplier: 0.25
wordValue: 0.1
permitGeneration:
enabled: true
9 changes: 9 additions & 0 deletions src/configuration/permit-generation-configuration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Static, Type } from "@sinclair/typebox";

const permitGenerationConfigurationType = Type.Object({
enabled: Type.Boolean(),
});

export type PermitGenerationConfiguration = Static<typeof permitGenerationConfigurationType>;

export default permitGenerationConfigurationType;
114 changes: 114 additions & 0 deletions src/parser/permit-generation-module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { context } from "@actions/github";
import { Value } from "@sinclair/typebox/value";
import { createClient } from "@supabase/supabase-js";
import {
Context,
createAdapters,
Database,
encodePermits,
generatePayoutPermit,
SupportedEvents,
TokenType,
} from "@ubiquibot/permit-generation";
import configuration from "../configuration/config-reader";
import contentEvaluatorConfig from "../configuration/content-evaluator-config";
import { getOctokitInstance } from "../get-authentication-token";
import { IssueActivity } from "../issue-activity";
import { Module, Result } from "./processor";

interface Payload {
evmNetworkId: number;
issueUrl: string;
evmPrivateEncrypted: string;
issue: { id: number };
}

export class PermitGenerationModule implements Module {
readonly _configuration: PermitGenerationModule = configuration.permitGeneration;
readonly _supabase = createClient<Database>(process.env.SUPABASE_URL, process.env.SUPABASE_ANON_KEY);

async transform(data: Readonly<IssueActivity>, result: Result): Promise<Result> {
const payload: Context["payload"] & Payload = context.payload.inputs;
const issueId = Number(payload.issueUrl.match(/[0-9]+$/)?.[1]);
payload.issue = {
id: issueId,
};
const env = process.env;
const eventName = context.eventName as SupportedEvents;
const octokit = getOctokitInstance();
const logger = {
debug(message: unknown, optionalParams: unknown) {
console.log(message, optionalParams);
},
error(message: unknown, optionalParams: unknown) {
console.error(message, optionalParams);
},
fatal(message: unknown, optionalParams: unknown) {
console.error(message, optionalParams);
},
info(message: unknown, optionalParams: unknown) {
console.log(message, optionalParams);
},
warn(message: unknown, optionalParams: unknown) {
console.warn(message, optionalParams);
},
};
const adapters = {} as ReturnType<typeof createAdapters>;

for (const [key, value] of Object.entries(result)) {
try {
const config: Context["config"] = {
evmNetworkId: payload.evmNetworkId,
evmPrivateEncrypted: payload.evmPrivateEncrypted,
permitRequests: [
{
amount: value.total,
userId: value.userId,
contributionType: "",
type: TokenType.ERC20,
},
],
};
const permits = await generatePayoutPermit(
{
env,
eventName,
logger,
payload,
adapters: createAdapters(this._supabase, {
env,
eventName,
octokit,
config,
logger,
payload,
adapters,
}),
octokit,
config,
},
[
{
type: "ERC20",
userId: value.userId,
amount: value.total,
contributionType: "",
},
]
);
result[key].permitUrl = `https://pay.ubq.fi?claim=${encodePermits(permits)}`;
} catch (e) {
console.error(e);
}
}
return Promise.resolve(result);
}

get enabled(): boolean {
if (!Value.Check(contentEvaluatorConfig, this._configuration)) {
console.warn("Invalid configuration detected for PermitGenerationModule, disabling.");
return false;
}
return this._configuration.enabled;
}
}
6 changes: 5 additions & 1 deletion src/parser/processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import program from "./command-line";
import { ContentEvaluatorModule } from "./content-evaluator-module";
import { DataPurgeModule } from "./data-purge-module";
import { FormattingEvaluatorModule } from "./formatting-evaluator-module";
import { PermitGenerationModule } from "./permit-generation-module";
import { UserExtractorModule } from "./user-extractor-module";

export class Processor {
Expand All @@ -17,7 +18,8 @@ export class Processor {
this.add(new UserExtractorModule())
.add(new DataPurgeModule())
.add(new FormattingEvaluatorModule())
.add(new ContentEvaluatorModule());
.add(new ContentEvaluatorModule())
.add(new PermitGenerationModule());
}

add(transformer: Module) {
Expand Down Expand Up @@ -96,6 +98,8 @@ export interface Result {
task?: {
reward: number;
};
permitUrl?: string;
userId: number;
};
}

Expand Down
1 change: 1 addition & 0 deletions src/parser/user-extractor-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class UserExtractorModule implements Module {
...result[comment.user.login],
total: 0,
task,
userId: comment.user.id,
};
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
GITHUB_TOKEN: string;
OPENAI_API_KEY: string;
X25519_PRIVATE_KEY: string;
SUPABASE_ANON_KEY: string;
SUPABASE_URL: string;
NFT_CONTRACT_ADDRESS: string;
NFT_MINTER_PRIVATE_KEY: string;
}
}
}

export {};
Loading

0 comments on commit 50b396b

Please sign in to comment.