generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
08e7028
commit 50b396b
Showing
12 changed files
with
1,028 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {}; |
Oops, something went wrong.