-
Notifications
You must be signed in to change notification settings - Fork 123
Reward Manager Init in typescript + script #13229
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
Draft
dharit-tan
wants to merge
1
commit into
main
Choose a base branch
from
rt-reward-init
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,179 @@ | ||
| # Quick Start: Initialize Reward Manager | ||
|
|
||
| This guide will help you initialize a Reward Manager program on Solana. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| 1. **Node.js & npm** installed | ||
| 2. **Solana CLI** installed (for generating keypairs and airdrops) | ||
| 3. **Funded wallet** with SOL | ||
|
|
||
| ## Step-by-Step Guide | ||
|
|
||
| ### 1. Install Dependencies | ||
|
|
||
| ```bash | ||
| cd packages/spl | ||
| npm install | ||
| ``` | ||
|
|
||
| ### 2. Generate Keypairs | ||
|
|
||
| You'll need two keypairs: | ||
|
|
||
| - **Payer**: Pays for transactions and account creation | ||
| - **Manager**: Admin account that can manage senders | ||
|
|
||
| ```bash | ||
| # Generate payer keypair (or use existing ~/.config/solana/id.json) | ||
| solana-keygen new --outfile ./payer.json --no-bip39-passphrase | ||
|
|
||
| # Generate manager keypair | ||
| solana-keygen new --outfile ./manager.json --no-bip39-passphrase | ||
| ``` | ||
|
|
||
| ### 3. Fund Your Payer (Devnet) | ||
|
|
||
| ```bash | ||
| # Get your payer address | ||
| solana-keygen pubkey ./payer.json | ||
|
|
||
| # Airdrop SOL | ||
| solana airdrop 2 <PAYER_ADDRESS> --url devnet | ||
|
|
||
| # Check balance | ||
| solana balance <PAYER_ADDRESS> --url devnet | ||
| ``` | ||
|
|
||
| ### 4. Run the Init Script | ||
|
|
||
| ```bash | ||
| npm run init-reward-manager -- \ | ||
| --payer ./payer.json \ | ||
| --manager ./manager.json \ | ||
| --mint 9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM \ | ||
| --min-votes 3 \ | ||
| --cluster devnet | ||
| ``` | ||
|
|
||
| ### 5. Save the Output | ||
|
|
||
| The script will output important addresses. **Save these!** | ||
|
|
||
| ``` | ||
| Reward Manager: ABC123... ← Save this! | ||
| Token Account: DEF456... ← Save this! | ||
| Authority PDA: GHI789... ← Save this! | ||
| ``` | ||
|
|
||
| The script also automatically saves generated keypairs to files: | ||
|
|
||
| - `reward-manager-<timestamp>.json` | ||
| - `token-account-<timestamp>.json` | ||
|
|
||
| ## Common Use Cases | ||
|
|
||
| ### Devnet Testing | ||
|
|
||
| ```bash | ||
| npm run init-reward-manager -- \ | ||
| --payer ~/.config/solana/id.json \ | ||
| --manager ./manager.json \ | ||
| --mint 9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM \ | ||
| --cluster devnet | ||
| ``` | ||
|
|
||
| ### Mainnet Deployment | ||
|
|
||
| ```bash | ||
| npm run init-reward-manager -- \ | ||
| --payer ./mainnet-payer.json \ | ||
| --manager ./mainnet-manager.json \ | ||
| --mint 9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM \ | ||
| --min-votes 5 \ | ||
| --cluster mainnet-beta | ||
| ``` | ||
|
|
||
| ### With Pre-Generated Accounts | ||
|
|
||
| ```bash | ||
| npm run init-reward-manager -- \ | ||
| --payer ./payer.json \ | ||
| --manager ./manager.json \ | ||
| --mint 9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM \ | ||
| --reward-manager-keypair ./reward-manager.json \ | ||
| --token-account-keypair ./token-account.json \ | ||
| --cluster devnet | ||
| ``` | ||
|
|
||
| ## What Gets Created? | ||
|
|
||
| 1. **Reward Manager Account** - Stores program state: | ||
|
|
||
| - Token account reference | ||
| - Manager authority | ||
| - Minimum votes required | ||
|
|
||
| 2. **Token Account** - SPL token account that holds reward tokens | ||
|
|
||
| 3. **Authority PDA** - Program-derived address that: | ||
| - Owns sender accounts | ||
| - Signs token transfers | ||
| - Cannot be controlled by any private key | ||
|
|
||
| ## Next Steps | ||
|
|
||
| After initialization, you can: | ||
|
|
||
| 1. **Fund the Token Account** - Transfer reward tokens to the token account | ||
| 2. **Create Senders** - Add discovery nodes as authorized attestors | ||
| 3. **Submit Attestations** - Have senders attest to reward eligibility | ||
| 4. **Disburse Rewards** - Evaluate attestations and transfer tokens | ||
|
|
||
| See the main [README](./README.md) for more information on these operations. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Error: "Payer has no balance" | ||
|
|
||
| ```bash | ||
| # Check balance | ||
| solana balance ./payer.json --url devnet | ||
|
|
||
| # Request airdrop | ||
| solana airdrop 2 $(solana-keygen pubkey ./payer.json) --url devnet | ||
| ``` | ||
|
|
||
| ### Error: "Keypair file not found" | ||
|
|
||
| Make sure you're running from the correct directory and the file paths are correct. | ||
|
|
||
| ```bash | ||
| # Use absolute paths if needed | ||
| npm run init-reward-manager -- \ | ||
| --payer /Users/yourname/payer.json \ | ||
| --manager /Users/yourname/manager.json \ | ||
| --mint 9LzCMqDgTKYz9Drzqnpgee3SGa89up3a247ypMj2xrqM | ||
| ``` | ||
|
|
||
| ### Error: "Account already exists" | ||
|
|
||
| The reward manager or token account keypair is already initialized. Use different keypairs or generate new ones. | ||
|
|
||
| ### View Transaction Details | ||
|
|
||
| Check the Solana Explorer link printed at the end: | ||
|
|
||
| ``` | ||
| 🔗 View transaction: https://explorer.solana.com/tx/<SIGNATURE>?cluster=devnet | ||
| ``` | ||
|
|
||
| ## Help | ||
|
|
||
| For more options: | ||
|
|
||
| ```bash | ||
| npm run init-reward-manager -- --help | ||
| ``` | ||
|
|
||
| For detailed documentation, see [scripts/README.md](./scripts/README.md). |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -9,7 +9,8 @@ | |
| "start": "tsc --build --verbose --watch tsconfig.all.json", | ||
| "build": "tsc --build --verbose tsconfig.all.json", | ||
| "test": "vitest run", | ||
| "test:watch": "vitest" | ||
| "test:watch": "vitest", | ||
| "init-reward-manager": "ts-node --project scripts/tsconfig.json scripts/initRewardManager.ts" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this belongs here |
||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
|
|
@@ -33,6 +34,9 @@ | |
| "@solana/web3.js": "^1.95.8" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^20.0.0", | ||
| "ts-node": "^10.9.0", | ||
| "typescript": "^5.0.0", | ||
| "vitest": "2.1.1" | ||
| } | ||
| } | ||
This file contains hidden or 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,7 @@ | ||
| # Ignore generated keypair files | ||
| reward-manager-*.json | ||
| token-account-*.json | ||
|
|
||
| # But keep the example | ||
| !example-keypair.json | ||
|
|
Oops, something went wrong.
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.
Remove this file imo