generated from ubiquity/ts-template
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add the permit-generator github action #69
Closed
Closed
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
25932b2
feat: add the permit-generator github action
hhio618 f0b5b9d
feat: add permit-generator script [WIP]
hhio618 36e3245
feat: add the permit-generator script
hhio618 b2038b0
feat: post permits to github issues
hhio618 c3b3c8d
fix: few adjustments
hhio618 798aa5c
fix: add missing envs
hhio618 e397fe0
refactor: downgrade to ethers@v5
cohow 787979f
fix: add yarnrc file back
cohow 2e61614
chore: change yarn version
cohow ba0d046
chore: remove packageManager
cohow a225135
fix: remove the env decoder
hhio618 f926e74
fix: type/typo fix
hhio618 1620035
chore: add logs
hhio618 0ac5357
fix: extend context env type
hhio618 917ae26
refactor: switch over action core lib
hhio618 f828cb3
chore: add log
hhio618 8540751
refactor: add USERS_AMOUNTS env
hhio618 133090e
chore: add more logs
hhio618 f4fb78c
Merge branch 'ubiquity-os:development' into development
hhio618 a7c05c9
fix: supabase wallets query
hhio618 7191ee8
feat: use workflow_dispatch runId as issueNodeId
hhio618 011e368
chore: cleanup
hhio618 81884f6
fix: add missing env X25519_PRIVATE_KEY
hhio618 04ecb36
test: hard-code fastest provider
hhio618 f31251d
fix: pipeline data flow
hhio618 203433f
fix: report request
hhio618 153dfe4
fix: report request
hhio618 55423fb
refactor: runId type
hhio618 52cb2c3
Merge branch 'ubiquity-os:development' into development
hhio618 d5f79bc
fix: unit-tests
hhio618 479ce93
chore: cleanup
hhio618 b945bdc
feat: use precompiled script
hhio618 41f85f5
refactor: revert script execution command
hhio618 b147da4
chore: remove unused ncc dep
hhio618 d19d962
refactor: rename USERS_AMOUNTS to PAYMENT_REQUESTS
hhio618 6aaa1ce
feat: add step to log permits data
hhio618 5e858dd
refactor: remove the contributionType
hhio618 99d2feb
feat: use uuid for nonce
hhio618 8e5cd8f
chore: fix knip
hhio618 4aadfc4
chore: add @types/uuid
hhio618 2db0505
chore: cleanup
hhio618 ff0d9d9
chore: fix format:cspell
hhio618 5b20c35
refactor: remove runId
hhio618 c22e4c2
refactor: simplify the env vars
hhio618 c78613a
refactor: rem return to kernel
hhio618 9fe5fda
Merge branch 'ubiquity-os:development' into development
hhio618 fe3e60a
chore: cleanup
hhio618 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: Permit Generator | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
PAYMENT_REQUESTS: | ||
description: "A JSON array containing usernames and associated amounts" | ||
required: true | ||
# example: '[{"user1": 100}, {"user2": 150}]' | ||
|
||
jobs: | ||
run: | ||
runs-on: ubuntu-latest | ||
permissions: write-all | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20.10.0" | ||
|
||
- name: Install dependencies | ||
run: yarn install --immutable --immutable-cache --check-cache | ||
|
||
- name: Process permit requests | ||
id: parse | ||
run: | | ||
echo "Received input: ${{ github.event.inputs.PAYMENT_REQUESTS }}" | ||
npx tsx scripts/github-action-permit-generator.ts permits.txt | ||
shell: bash | ||
env: | ||
X25519_PRIVATE_KEY: ${{ secrets.X25519_PRIVATE_KEY }} | ||
EVM_NETWORK_ID: ${{ secrets.EVM_NETWORK_ID }} | ||
EVM_PRIVATE_KEY: ${{ secrets.EVM_PRIVATE_KEY }} | ||
EVM_TOKEN_ADDRESS: ${{ secrets.EVM_TOKEN_ADDRESS }} | ||
SUPABASE_URL: ${{ secrets.SUPABASE_URL}} | ||
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PAYMENT_REQUESTS: ${{ github.event.inputs.PAYMENT_REQUESTS }} | ||
|
||
- name: Log permits data | ||
run: | | ||
export PERMITS=$(cat permits.txt) | ||
echo $PERMITS |
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,94 @@ | ||
import { Octokit } from "@octokit/rest"; | ||
import { createClient } from "@supabase/supabase-js"; | ||
import { createAdapters } from "../src/adapters"; | ||
import { Database } from "../src/adapters/supabase/types/database"; | ||
import { generatePayoutPermit } from "../src/handlers"; | ||
import { Context } from "../src/types/context"; | ||
import { PermitGenerationSettings, PermitRequest } from "../src/types/plugin-input"; | ||
import * as fs from "fs"; | ||
|
||
function getEnvVar(key: string) { | ||
return ( | ||
process.env[key] || | ||
(() => { | ||
throw new Error(`Environment variable ${key} is required`); | ||
})() | ||
); | ||
} | ||
/** | ||
* Generates all the permits based on the current github workflow dispatch. | ||
*/ | ||
export async function generatePermitsFromGithubWorkflowDispatch() { | ||
const EVM_NETWORK_ID = getEnvVar("EVM_NETWORK_ID"); | ||
const EVM_PRIVATE_KEY = getEnvVar("EVM_PRIVATE_KEY"); | ||
const EVM_TOKEN_ADDRESS = getEnvVar("EVM_TOKEN_ADDRESS"); | ||
const PAYMENT_REQUESTS = getEnvVar("PAYMENT_REQUESTS"); | ||
const GITHUB_TOKEN = getEnvVar("GITHUB_TOKEN"); | ||
const SUPABASE_URL = getEnvVar("SUPABASE_URL"); | ||
const SUPABASE_KEY = getEnvVar("SUPABASE_KEY"); | ||
|
||
console.log(`Received: ${PAYMENT_REQUESTS}`); | ||
const userAmounts = JSON.parse(PAYMENT_REQUESTS); | ||
|
||
// Populate the permitRequests from the user_amounts payload | ||
|
||
const permitRequests: PermitRequest[] = userAmounts.flatMap((userObj: { [key: string]: number }) => | ||
Object.entries(userObj).map(([user, amount]) => ({ | ||
type: "ERC20", | ||
username: user, | ||
amount: amount, | ||
tokenAddress: EVM_TOKEN_ADDRESS, | ||
})) | ||
); | ||
|
||
const config: PermitGenerationSettings = { | ||
evmNetworkId: Number(EVM_NETWORK_ID), | ||
evmPrivateEncrypted: EVM_PRIVATE_KEY, | ||
permitRequests: permitRequests, | ||
}; | ||
|
||
const octokit = new Octokit({ auth: GITHUB_TOKEN }); | ||
const supabaseClient = createClient<Database>(SUPABASE_URL, SUPABASE_KEY); | ||
|
||
const context: Context = { | ||
eventName: "workflow_dispatch", | ||
config: config, | ||
octokit, | ||
payload: userAmounts, | ||
env: undefined, | ||
logger: { | ||
debug(message: unknown, ...optionalParams: unknown[]) { | ||
console.debug(message, ...optionalParams); | ||
}, | ||
info(message: unknown, ...optionalParams: unknown[]) { | ||
console.log(message, ...optionalParams); | ||
}, | ||
warn(message: unknown, ...optionalParams: unknown[]) { | ||
console.warn(message, ...optionalParams); | ||
}, | ||
error(message: unknown, ...optionalParams: unknown[]) { | ||
console.error(message, ...optionalParams); | ||
}, | ||
fatal(message: unknown, ...optionalParams: unknown[]) { | ||
console.error(message, ...optionalParams); | ||
}, | ||
}, | ||
adapters: {} as ReturnType<typeof createAdapters>, | ||
}; | ||
|
||
context.adapters = createAdapters(supabaseClient, context); | ||
|
||
const permits = await generatePayoutPermit(context, config.permitRequests); | ||
const out = Buffer.from(JSON.stringify(permits)).toString("base64"); | ||
fs.writeFile(process.argv[2], out, (err) => { | ||
if (err) { | ||
throw err; | ||
} | ||
}); | ||
} | ||
|
||
generatePermitsFromGithubWorkflowDispatch() | ||
.then((result) => console.log(`result: ${result}`)) | ||
.catch((error) => { | ||
console.error(error); | ||
}); |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should only be a single wallet associated per user. Why did you check for arrays
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I keep getting an array here. Even though the docs say
wallets
should be anobject
, it’s probably showing up as anarray
becauseSupabase
treats it like aone-to-many
relationship, even if the user only has a single wallet.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@whilefoo @rndquu can you concur this is correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you use
single()
to retrieve only one? The type should be properly deduced.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still, keep getting an array.
Here's the code:
Results after run:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes it's correct for that to be an array because it's querying an user with wallets as a relation. if you wanted to get just one record you would need to query the wallet table directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@whilefoo The code is already in the base branch but isn't working without the changes in this PR. Should I move the hotfix to a separate PR?