diff --git a/.changeset/slick-numbers-jam.md b/.changeset/slick-numbers-jam.md new file mode 100644 index 00000000..129b88a8 --- /dev/null +++ b/.changeset/slick-numbers-jam.md @@ -0,0 +1,6 @@ +--- +"@macalinao/clients-orca-whirlpools": patch +"@macalinao/clients-tribeca": patch +--- + +update package.json diff --git a/bun.lock b/bun.lock index 7a570366..da1cd631 100644 --- a/bun.lock +++ b/bun.lock @@ -131,6 +131,21 @@ "@solana/kit": "*", }, }, + "clients/tribeca": { + "name": "@macalinao/clients-tribeca", + "version": "0.1.0", + "devDependencies": { + "@macalinao/coda": "workspace:^", + "@macalinao/eslint-config": "catalog:", + "@macalinao/tsconfig": "catalog:", + "@solana/kit": "catalog:", + "eslint": "catalog:", + "typescript": "catalog:", + }, + "peerDependencies": { + "@solana/kit": "*", + }, + }, "clients/voter-stake-registry": { "name": "@macalinao/clients-voter-stake-registry", "version": "0.2.2", @@ -587,6 +602,8 @@ "@macalinao/clients-token-metadata": ["@macalinao/clients-token-metadata@workspace:clients/token-metadata"], + "@macalinao/clients-tribeca": ["@macalinao/clients-tribeca@workspace:clients/tribeca"], + "@macalinao/clients-voter-stake-registry": ["@macalinao/clients-voter-stake-registry@workspace:clients/voter-stake-registry"], "@macalinao/coda": ["@macalinao/coda@workspace:packages/coda"], diff --git a/clients/orca-whirlpools/package.json b/clients/orca-whirlpools/package.json index 3b90827d..d224544f 100644 --- a/clients/orca-whirlpools/package.json +++ b/clients/orca-whirlpools/package.json @@ -4,6 +4,8 @@ "description": "TypeScript client for Orca Whirlpools program", "type": "module", "sideEffects": false, + "author": "Ian Macalinao ", + "homepage": "https://coda.ianm.com", "license": "Apache-2.0", "keywords": [ "coda", diff --git a/clients/tribeca/.gitignore b/clients/tribeca/.gitignore new file mode 100644 index 00000000..24943919 --- /dev/null +++ b/clients/tribeca/.gitignore @@ -0,0 +1,31 @@ +# Dependencies +node_modules/ +.pnp +.pnp.js + +# Build output +dist/ +*.tsbuildinfo + +# Debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.pnpm-debug.log* +bun.lockb + +# Environment +.env +.env.local +.env.*.local + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +.DS_Store + +# Cache +.turbo/ +.eslintcache \ No newline at end of file diff --git a/clients/tribeca/README.md b/clients/tribeca/README.md new file mode 100644 index 00000000..7ba8776c --- /dev/null +++ b/clients/tribeca/README.md @@ -0,0 +1,89 @@ +# @macalinao/clients-tribeca + +[![npm version](https://img.shields.io/npm/v/@macalinao/clients-tribeca.svg)](https://www.npmjs.com/package/@macalinao/clients-tribeca) + +TypeScript client for Tribeca governance programs (Govern and Locked Voter), generated using Coda CLI with full ESM support. + +## Installation + +```bash +bun add @macalinao/clients-tribeca +``` + +## About Tribeca + +Tribeca is a governance protocol on Solana that provides decentralized autonomous organization (DAO) functionality through two main programs: + +- **Govern**: Core governance program for creating governors, proposals, and voting +- **Locked Voter**: Vote escrow system for token-weighted governance with time-locked voting power + +## Programs Included + +### Govern Program + +- **Governor**: Manages proposals and voting parameters +- **Proposal**: Individual governance proposals with metadata +- **Vote**: Records individual voter decisions on proposals +- **ProposalMeta**: Additional metadata for proposals + +### Locked Voter Program + +- **Locker**: Manages vote escrows for a governance token +- **Escrow**: Individual user's locked tokens and voting power +- **Whitelist**: Programs authorized to interact with the locker + +## Development + +This client is generated from the Tribeca IDLs using Coda CLI: + +```bash +# Generate the client from idls/ +bun run codegen + +# Build the TypeScript +bun run build +``` + +### Configuration + +The `coda.config.mjs` file includes custom PDAs for both programs and links accounts to their corresponding PDA helpers. + +## Usage + +```typescript +import { + getCastVoteInstruction, + fetchGovernor, + fetchProposal, + getCreateEscrowInstruction, + fetchLocker, +} from "@macalinao/clients-tribeca"; + +// Governance example +const governor = await fetchGovernor(rpc, governorAddress); +const proposal = await fetchProposal(rpc, proposalAddress); + +const voteInstruction = getCastVoteInstruction({ + governor: governorAddress, + proposal: proposalAddress, + vote: voteAddress, // PDA automatically calculated + voter: voterPublicKey, + // ... other parameters +}); + +// Locked voter example +const locker = await fetchLocker(rpc, lockerAddress); + +const escrowInstruction = getCreateEscrowInstruction({ + locker: lockerAddress, + escrow: escrowAddress, // PDA automatically calculated + authority: authorityPublicKey, + // ... other parameters +}); +``` + +## License + +Copyright © 2025 Ian Macalinao + +Licensed under the Apache License, Version 2.0 diff --git a/clients/tribeca/coda.config.mjs b/clients/tribeca/coda.config.mjs new file mode 100644 index 00000000..594d7355 --- /dev/null +++ b/clients/tribeca/coda.config.mjs @@ -0,0 +1,126 @@ +import { + addPdasVisitor, + constantPdaSeedNodeFromString, + constantValueNode, + defineConfig, + numberTypeNode, + pdaLinkNode, + publicKeyTypeNode, + SYSTEM_PROGRAM_VALUE_NODE, + updateAccountsVisitor, + variablePdaSeedNode, + zeroableOptionTypeNode, +} from "@macalinao/coda"; + +export default defineConfig({ + outputDir: "./src/generated", + + // Add custom PDAs for Tribeca programs + visitors: [ + addPdasVisitor({ + lockedVoter: [ + { + name: "locker", + docs: [ + "Locker account that manages vote escrows for a specific base", + ], + seeds: [ + constantPdaSeedNodeFromString("utf8", "Locker"), + variablePdaSeedNode("base", publicKeyTypeNode()), + ], + }, + { + name: "escrow", + docs: ["Escrow account that holds locked tokens for a user"], + seeds: [ + constantPdaSeedNodeFromString("utf8", "Escrow"), + variablePdaSeedNode("locker", publicKeyTypeNode()), + variablePdaSeedNode("authority", publicKeyTypeNode()), + ], + }, + { + name: "whitelist", + docs: [ + "Whitelist entry for a program that can interact with the locker", + ], + seeds: [ + constantPdaSeedNodeFromString("utf8", "LockerWhitelistEntry"), + variablePdaSeedNode("locker", publicKeyTypeNode()), + variablePdaSeedNode("programId", publicKeyTypeNode()), + variablePdaSeedNode( + "owner", + zeroableOptionTypeNode( + publicKeyTypeNode(), + constantValueNode( + publicKeyTypeNode(), + SYSTEM_PROGRAM_VALUE_NODE, + ), + ), + ), + ], + }, + ], + govern: [ + { + name: "governor", + docs: ["Governor account that manages proposals and voting"], + seeds: [ + constantPdaSeedNodeFromString("utf8", "TribecaGovernor"), + variablePdaSeedNode("base", publicKeyTypeNode()), + ], + }, + { + name: "proposal", + docs: ["Proposal account for governance actions"], + seeds: [ + constantPdaSeedNodeFromString("utf8", "TribecaProposal"), + variablePdaSeedNode("governor", publicKeyTypeNode()), + variablePdaSeedNode("index", numberTypeNode("u64")), + ], + }, + { + name: "vote", + docs: ["Vote account representing a voter's decision on a proposal"], + seeds: [ + constantPdaSeedNodeFromString("utf8", "TribecaVote"), + variablePdaSeedNode("proposal", publicKeyTypeNode()), + variablePdaSeedNode("voter", publicKeyTypeNode()), + ], + }, + { + name: "proposalMeta", + docs: ["Proposal metadata account with additional information"], + seeds: [ + constantPdaSeedNodeFromString("utf8", "TribecaProposalMeta"), + variablePdaSeedNode("proposal", publicKeyTypeNode()), + ], + }, + ], + }), + updateAccountsVisitor({ + // lockedVoter accounts + locker: { + pda: pdaLinkNode("locker"), + }, + escrow: { + pda: pdaLinkNode("escrow"), + }, + lockerWhitelistEntry: { + pda: pdaLinkNode("whitelist"), + }, + // govern accounts + governor: { + pda: pdaLinkNode("governor"), + }, + proposal: { + pda: pdaLinkNode("proposal"), + }, + vote: { + pda: pdaLinkNode("vote"), + }, + proposalMeta: { + pda: pdaLinkNode("proposalMeta"), + }, + }), + ], +}); diff --git a/clients/tribeca/eslint.config.js b/clients/tribeca/eslint.config.js new file mode 100644 index 00000000..f157753e --- /dev/null +++ b/clients/tribeca/eslint.config.js @@ -0,0 +1,31 @@ +import { configs } from "@macalinao/eslint-config"; + +export default [ + ...configs.fast, + { + languageOptions: { + parserOptions: { + tsconfigRootDir: import.meta.dirname, + }, + }, + }, + { + files: ["src/generated/**/*.ts"], + rules: { + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/prefer-nullish-coalescing": "off", + }, + }, + { + files: [ + "src/generated/instructions/*.ts", + "src/generated/types/*.ts", + "src/generated/errors/*.ts", + ], + rules: { + "@typescript-eslint/no-unnecessary-condition": "off", + "no-constant-condition": "off", + "@typescript-eslint/no-empty-object-type": "off", + }, + }, +]; diff --git a/clients/tribeca/idls/govern.json b/clients/tribeca/idls/govern.json new file mode 100644 index 00000000..ffe76091 --- /dev/null +++ b/clients/tribeca/idls/govern.json @@ -0,0 +1,861 @@ +{ + "metadata": { + "address": "Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw" + }, + "version": "0.5.6", + "name": "govern", + "instructions": [ + { + "name": "createGovernor", + "accounts": [ + { + "name": "base", + "isMut": false, + "isSigner": true + }, + { + "name": "governor", + "isMut": true, + "isSigner": false + }, + { + "name": "smartWallet", + "isMut": false, + "isSigner": false + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "bump", + "type": "u8" + }, + { + "name": "electorate", + "type": "publicKey" + }, + { + "name": "params", + "type": { + "defined": "GovernanceParameters" + } + } + ] + }, + { + "name": "createProposal", + "accounts": [ + { + "name": "governor", + "isMut": true, + "isSigner": false + }, + { + "name": "proposal", + "isMut": true, + "isSigner": false + }, + { + "name": "proposer", + "isMut": false, + "isSigner": true + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "bump", + "type": "u8" + }, + { + "name": "instructions", + "type": { + "vec": { + "defined": "ProposalInstruction" + } + } + } + ] + }, + { + "name": "activateProposal", + "accounts": [ + { + "name": "governor", + "isMut": false, + "isSigner": false + }, + { + "name": "proposal", + "isMut": true, + "isSigner": false + }, + { + "name": "electorate", + "isMut": false, + "isSigner": true + } + ], + "args": [] + }, + { + "name": "cancelProposal", + "accounts": [ + { + "name": "governor", + "isMut": false, + "isSigner": false + }, + { + "name": "proposal", + "isMut": true, + "isSigner": false + }, + { + "name": "proposer", + "isMut": false, + "isSigner": true + } + ], + "args": [] + }, + { + "name": "queueProposal", + "accounts": [ + { + "name": "governor", + "isMut": false, + "isSigner": false + }, + { + "name": "proposal", + "isMut": true, + "isSigner": false + }, + { + "name": "transaction", + "isMut": true, + "isSigner": false + }, + { + "name": "smartWallet", + "isMut": true, + "isSigner": false + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "smartWalletProgram", + "isMut": false, + "isSigner": false + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "txBump", + "type": "u8" + } + ] + }, + { + "name": "newVote", + "accounts": [ + { + "name": "proposal", + "isMut": false, + "isSigner": false + }, + { + "name": "vote", + "isMut": true, + "isSigner": false + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "bump", + "type": "u8" + }, + { + "name": "voter", + "type": "publicKey" + } + ] + }, + { + "name": "setVote", + "accounts": [ + { + "name": "governor", + "isMut": false, + "isSigner": false + }, + { + "name": "proposal", + "isMut": true, + "isSigner": false + }, + { + "name": "vote", + "isMut": true, + "isSigner": false + }, + { + "name": "electorate", + "isMut": false, + "isSigner": true + } + ], + "args": [ + { + "name": "side", + "type": "u8" + }, + { + "name": "weight", + "type": "u64" + } + ] + }, + { + "name": "setGovernanceParams", + "accounts": [ + { + "name": "governor", + "isMut": true, + "isSigner": false + }, + { + "name": "smartWallet", + "isMut": false, + "isSigner": true + } + ], + "args": [ + { + "name": "params", + "type": { + "defined": "GovernanceParameters" + } + } + ] + }, + { + "name": "setElectorate", + "accounts": [ + { + "name": "governor", + "isMut": true, + "isSigner": false + }, + { + "name": "smartWallet", + "isMut": false, + "isSigner": true + } + ], + "args": [ + { + "name": "newElectorate", + "type": "publicKey" + } + ] + }, + { + "name": "createProposalMeta", + "accounts": [ + { + "name": "proposal", + "isMut": false, + "isSigner": false + }, + { + "name": "proposer", + "isMut": false, + "isSigner": true + }, + { + "name": "proposalMeta", + "isMut": true, + "isSigner": false + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "bump", + "type": "u8" + }, + { + "name": "title", + "type": "string" + }, + { + "name": "descriptionLink", + "type": "string" + } + ] + } + ], + "accounts": [ + { + "name": "Governor", + "type": { + "kind": "struct", + "fields": [ + { + "name": "base", + "type": "publicKey" + }, + { + "name": "bump", + "type": "u8" + }, + { + "name": "proposalCount", + "type": "u64" + }, + { + "name": "electorate", + "type": "publicKey" + }, + { + "name": "smartWallet", + "type": "publicKey" + }, + { + "name": "params", + "type": { + "defined": "GovernanceParameters" + } + } + ] + } + }, + { + "name": "Proposal", + "type": { + "kind": "struct", + "fields": [ + { + "name": "governor", + "type": "publicKey" + }, + { + "name": "index", + "type": "u64" + }, + { + "name": "bump", + "type": "u8" + }, + { + "name": "proposer", + "type": "publicKey" + }, + { + "name": "quorumVotes", + "type": "u64" + }, + { + "name": "forVotes", + "type": "u64" + }, + { + "name": "againstVotes", + "type": "u64" + }, + { + "name": "abstainVotes", + "type": "u64" + }, + { + "name": "canceledAt", + "type": "i64" + }, + { + "name": "createdAt", + "type": "i64" + }, + { + "name": "activatedAt", + "type": "i64" + }, + { + "name": "votingEndsAt", + "type": "i64" + }, + { + "name": "queuedAt", + "type": "i64" + }, + { + "name": "queuedTransaction", + "type": "publicKey" + }, + { + "name": "instructions", + "type": { + "vec": { + "defined": "ProposalInstruction" + } + } + } + ] + } + }, + { + "name": "ProposalMeta", + "type": { + "kind": "struct", + "fields": [ + { + "name": "proposal", + "type": "publicKey" + }, + { + "name": "title", + "type": "string" + }, + { + "name": "descriptionLink", + "type": "string" + } + ] + } + }, + { + "name": "Vote", + "type": { + "kind": "struct", + "fields": [ + { + "name": "proposal", + "type": "publicKey" + }, + { + "name": "voter", + "type": "publicKey" + }, + { + "name": "bump", + "type": "u8" + }, + { + "name": "side", + "type": "u8" + }, + { + "name": "weight", + "type": "u64" + } + ] + } + } + ], + "types": [ + { + "name": "GovernanceParameters", + "type": { + "kind": "struct", + "fields": [ + { + "name": "votingDelay", + "type": "u64" + }, + { + "name": "votingPeriod", + "type": "u64" + }, + { + "name": "quorumVotes", + "type": "u64" + }, + { + "name": "timelockDelaySeconds", + "type": "i64" + } + ] + } + }, + { + "name": "ProposalInstruction", + "type": { + "kind": "struct", + "fields": [ + { + "name": "programId", + "type": "publicKey" + }, + { + "name": "keys", + "type": { + "vec": { + "defined": "ProposalAccountMeta" + } + } + }, + { + "name": "data", + "type": "bytes" + } + ] + } + }, + { + "name": "ProposalAccountMeta", + "type": { + "kind": "struct", + "fields": [ + { + "name": "pubkey", + "type": "publicKey" + }, + { + "name": "isSigner", + "type": "bool" + }, + { + "name": "isWritable", + "type": "bool" + } + ] + } + }, + { + "name": "ProposalState", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Draft" + }, + { + "name": "Active" + }, + { + "name": "Canceled" + }, + { + "name": "Defeated" + }, + { + "name": "Succeeded" + }, + { + "name": "Queued" + } + ] + } + }, + { + "name": "VoteSide", + "type": { + "kind": "enum", + "variants": [ + { + "name": "Pending" + }, + { + "name": "Against" + }, + { + "name": "For" + }, + { + "name": "Abstain" + } + ] + } + } + ], + "events": [ + { + "name": "GovernorCreateEvent", + "fields": [ + { + "name": "governor", + "type": "publicKey", + "index": false + }, + { + "name": "electorate", + "type": "publicKey", + "index": false + }, + { + "name": "smartWallet", + "type": "publicKey", + "index": false + }, + { + "name": "parameters", + "type": { + "defined": "GovernanceParameters" + }, + "index": false + } + ] + }, + { + "name": "ProposalCreateEvent", + "fields": [ + { + "name": "governor", + "type": "publicKey", + "index": false + }, + { + "name": "proposal", + "type": "publicKey", + "index": false + }, + { + "name": "index", + "type": "u64", + "index": false + }, + { + "name": "instructions", + "type": { + "vec": { + "defined": "ProposalInstruction" + } + }, + "index": false + } + ] + }, + { + "name": "ProposalActivateEvent", + "fields": [ + { + "name": "governor", + "type": "publicKey", + "index": false + }, + { + "name": "proposal", + "type": "publicKey", + "index": false + }, + { + "name": "votingEndsAt", + "type": "i64", + "index": false + } + ] + }, + { + "name": "ProposalCancelEvent", + "fields": [ + { + "name": "governor", + "type": "publicKey", + "index": false + }, + { + "name": "proposal", + "type": "publicKey", + "index": false + } + ] + }, + { + "name": "ProposalQueueEvent", + "fields": [ + { + "name": "governor", + "type": "publicKey", + "index": false + }, + { + "name": "proposal", + "type": "publicKey", + "index": false + }, + { + "name": "transaction", + "type": "publicKey", + "index": false + } + ] + }, + { + "name": "VoteSetEvent", + "fields": [ + { + "name": "governor", + "type": "publicKey", + "index": false + }, + { + "name": "proposal", + "type": "publicKey", + "index": false + }, + { + "name": "voter", + "type": "publicKey", + "index": false + }, + { + "name": "vote", + "type": "publicKey", + "index": false + }, + { + "name": "side", + "type": "u8", + "index": false + }, + { + "name": "weight", + "type": "u64", + "index": false + } + ] + }, + { + "name": "ProposalMetaCreateEvent", + "fields": [ + { + "name": "governor", + "type": "publicKey", + "index": false + }, + { + "name": "proposal", + "type": "publicKey", + "index": false + }, + { + "name": "title", + "type": "string", + "index": false + }, + { + "name": "descriptionLink", + "type": "string", + "index": false + } + ] + }, + { + "name": "GovernorSetParamsEvent", + "fields": [ + { + "name": "governor", + "type": "publicKey", + "index": false + }, + { + "name": "prevParams", + "type": { + "defined": "GovernanceParameters" + }, + "index": false + }, + { + "name": "params", + "type": { + "defined": "GovernanceParameters" + }, + "index": false + } + ] + }, + { + "name": "GovernorSetElectorateEvent", + "fields": [ + { + "name": "governor", + "type": "publicKey", + "index": false + }, + { + "name": "prevElectorate", + "type": "publicKey", + "index": false + }, + { + "name": "newElectorate", + "type": "publicKey", + "index": false + } + ] + } + ], + "errors": [ + { + "code": 6000, + "name": "InvalidVoteSide", + "msg": "Invalid vote side." + }, + { + "code": 6001, + "name": "GovernorNotFound", + "msg": "The owner of the smart wallet doesn't match with current." + }, + { + "code": 6002, + "name": "VotingDelayNotMet", + "msg": "The proposal cannot be activated since it has not yet passed the voting delay." + }, + { + "code": 6003, + "name": "ProposalNotDraft", + "msg": "Only drafts can be canceled." + }, + { + "code": 6004, + "name": "ProposalNotActive", + "msg": "The proposal must be active." + } + ] +} diff --git a/clients/tribeca/idls/locked_voter.json b/clients/tribeca/idls/locked_voter.json new file mode 100644 index 00000000..5ab6b10d --- /dev/null +++ b/clients/tribeca/idls/locked_voter.json @@ -0,0 +1,951 @@ +{ + "metadata": { + "address": "LocktDzaV1W2Bm9DeZeiyz4J9zs4fRqNiYqQyracRXw" + }, + "version": "0.5.6", + "name": "locked_voter", + "instructions": [ + { + "name": "newLocker", + "accounts": [ + { + "name": "base", + "isMut": false, + "isSigner": true + }, + { + "name": "locker", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenMint", + "isMut": false, + "isSigner": false + }, + { + "name": "governor", + "isMut": false, + "isSigner": false + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "bump", + "type": "u8" + }, + { + "name": "params", + "type": { + "defined": "LockerParams" + } + } + ] + }, + { + "name": "newEscrow", + "accounts": [ + { + "name": "locker", + "isMut": false, + "isSigner": false + }, + { + "name": "escrow", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowOwner", + "isMut": false, + "isSigner": false + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "bump", + "type": "u8" + } + ] + }, + { + "name": "lock", + "accounts": [ + { + "name": "locker", + "isMut": true, + "isSigner": false + }, + { + "name": "escrow", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowTokens", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowOwner", + "isMut": false, + "isSigner": true + }, + { + "name": "sourceTokens", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + }, + { + "name": "duration", + "type": "i64" + } + ] + }, + { + "name": "lockWithWhitelist", + "accounts": [ + { + "name": "lock", + "accounts": [ + { + "name": "locker", + "isMut": true, + "isSigner": false + }, + { + "name": "escrow", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowTokens", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowOwner", + "isMut": false, + "isSigner": true + }, + { + "name": "sourceTokens", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + } + ] + }, + { + "name": "instructionsSysvar", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + }, + { + "name": "duration", + "type": "i64" + } + ] + }, + { + "name": "lockWithWhitelistEntry", + "accounts": [ + { + "name": "lock", + "accounts": [ + { + "name": "locker", + "isMut": true, + "isSigner": false + }, + { + "name": "escrow", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowTokens", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowOwner", + "isMut": false, + "isSigner": true + }, + { + "name": "sourceTokens", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + } + ] + }, + { + "name": "instructionsSysvar", + "isMut": false, + "isSigner": false + }, + { + "name": "whitelistEntry", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + }, + { + "name": "duration", + "type": "i64" + } + ] + }, + { + "name": "lockPermissionless", + "accounts": [ + { + "name": "locker", + "isMut": true, + "isSigner": false + }, + { + "name": "escrow", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowTokens", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowOwner", + "isMut": false, + "isSigner": true + }, + { + "name": "sourceTokens", + "isMut": true, + "isSigner": false + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "amount", + "type": "u64" + }, + { + "name": "duration", + "type": "i64" + } + ] + }, + { + "name": "exit", + "accounts": [ + { + "name": "locker", + "isMut": true, + "isSigner": false + }, + { + "name": "escrow", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowOwner", + "isMut": false, + "isSigner": true + }, + { + "name": "escrowTokens", + "isMut": true, + "isSigner": false + }, + { + "name": "destinationTokens", + "isMut": true, + "isSigner": false + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "tokenProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "activateProposal", + "accounts": [ + { + "name": "locker", + "isMut": false, + "isSigner": false + }, + { + "name": "governor", + "isMut": false, + "isSigner": false + }, + { + "name": "proposal", + "isMut": true, + "isSigner": false + }, + { + "name": "escrow", + "isMut": false, + "isSigner": false + }, + { + "name": "escrowOwner", + "isMut": false, + "isSigner": true + }, + { + "name": "governProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [] + }, + { + "name": "castVote", + "accounts": [ + { + "name": "locker", + "isMut": false, + "isSigner": false + }, + { + "name": "escrow", + "isMut": false, + "isSigner": false + }, + { + "name": "voteDelegate", + "isMut": false, + "isSigner": true + }, + { + "name": "proposal", + "isMut": true, + "isSigner": false + }, + { + "name": "vote", + "isMut": true, + "isSigner": false + }, + { + "name": "governor", + "isMut": false, + "isSigner": false + }, + { + "name": "governProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "side", + "type": "u8" + } + ] + }, + { + "name": "setVoteDelegate", + "accounts": [ + { + "name": "escrow", + "isMut": true, + "isSigner": false + }, + { + "name": "escrowOwner", + "isMut": false, + "isSigner": true + } + ], + "args": [ + { + "name": "newDelegate", + "type": "publicKey" + } + ] + }, + { + "name": "setLockerParams", + "accounts": [ + { + "name": "locker", + "isMut": true, + "isSigner": false + }, + { + "name": "governor", + "isMut": false, + "isSigner": false + }, + { + "name": "smartWallet", + "isMut": false, + "isSigner": true + } + ], + "args": [ + { + "name": "params", + "type": { + "defined": "LockerParams" + } + } + ] + }, + { + "name": "approveProgramLockPrivilege", + "accounts": [ + { + "name": "locker", + "isMut": false, + "isSigner": false + }, + { + "name": "whitelistEntry", + "isMut": true, + "isSigner": false + }, + { + "name": "governor", + "isMut": false, + "isSigner": false + }, + { + "name": "smartWallet", + "isMut": false, + "isSigner": true + }, + { + "name": "executableId", + "isMut": false, + "isSigner": false + }, + { + "name": "whitelistedOwner", + "isMut": false, + "isSigner": false + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + }, + { + "name": "systemProgram", + "isMut": false, + "isSigner": false + } + ], + "args": [ + { + "name": "bump", + "type": "u8" + } + ] + }, + { + "name": "revokeProgramLockPrivilege", + "accounts": [ + { + "name": "locker", + "isMut": false, + "isSigner": false + }, + { + "name": "whitelistEntry", + "isMut": true, + "isSigner": false + }, + { + "name": "governor", + "isMut": false, + "isSigner": false + }, + { + "name": "smartWallet", + "isMut": false, + "isSigner": true + }, + { + "name": "payer", + "isMut": true, + "isSigner": true + } + ], + "args": [] + } + ], + "accounts": [ + { + "name": "Locker", + "type": { + "kind": "struct", + "fields": [ + { + "name": "base", + "type": "publicKey" + }, + { + "name": "bump", + "type": "u8" + }, + { + "name": "tokenMint", + "type": "publicKey" + }, + { + "name": "lockedSupply", + "type": "u64" + }, + { + "name": "governor", + "type": "publicKey" + }, + { + "name": "params", + "type": { + "defined": "LockerParams" + } + } + ] + } + }, + { + "name": "LockerWhitelistEntry", + "type": { + "kind": "struct", + "fields": [ + { + "name": "bump", + "type": "u8" + }, + { + "name": "locker", + "type": "publicKey" + }, + { + "name": "programId", + "type": "publicKey" + }, + { + "name": "owner", + "type": "publicKey" + } + ] + } + }, + { + "name": "Escrow", + "type": { + "kind": "struct", + "fields": [ + { + "name": "locker", + "type": "publicKey" + }, + { + "name": "owner", + "type": "publicKey" + }, + { + "name": "bump", + "type": "u8" + }, + { + "name": "tokens", + "type": "publicKey" + }, + { + "name": "amount", + "type": "u64" + }, + { + "name": "escrowStartedAt", + "type": "i64" + }, + { + "name": "escrowEndsAt", + "type": "i64" + }, + { + "name": "voteDelegate", + "type": "publicKey" + } + ] + } + } + ], + "types": [ + { + "name": "LockerParams", + "type": { + "kind": "struct", + "fields": [ + { + "name": "whitelistEnabled", + "type": "bool" + }, + { + "name": "maxStakeVoteMultiplier", + "type": "u8" + }, + { + "name": "minStakeDuration", + "type": "u64" + }, + { + "name": "maxStakeDuration", + "type": "u64" + }, + { + "name": "proposalActivationMinVotes", + "type": "u64" + } + ] + } + } + ], + "events": [ + { + "name": "ApproveLockPrivilegeEvent", + "fields": [ + { + "name": "locker", + "type": "publicKey", + "index": false + }, + { + "name": "programId", + "type": "publicKey", + "index": false + }, + { + "name": "owner", + "type": "publicKey", + "index": false + }, + { + "name": "timestamp", + "type": "i64", + "index": false + } + ] + }, + { + "name": "ExitEscrowEvent", + "fields": [ + { + "name": "escrowOwner", + "type": "publicKey", + "index": false + }, + { + "name": "locker", + "type": "publicKey", + "index": false + }, + { + "name": "timestamp", + "type": "i64", + "index": false + }, + { + "name": "lockerSupply", + "type": "u64", + "index": false + }, + { + "name": "releasedAmount", + "type": "u64", + "index": false + } + ] + }, + { + "name": "LockEvent", + "fields": [ + { + "name": "locker", + "type": "publicKey", + "index": false + }, + { + "name": "escrowOwner", + "type": "publicKey", + "index": false + }, + { + "name": "tokenMint", + "type": "publicKey", + "index": false + }, + { + "name": "amount", + "type": "u64", + "index": false + }, + { + "name": "lockerSupply", + "type": "u64", + "index": false + }, + { + "name": "duration", + "type": "i64", + "index": false + }, + { + "name": "prevEscrowEndsAt", + "type": "i64", + "index": false + }, + { + "name": "nextEscrowEndsAt", + "type": "i64", + "index": false + }, + { + "name": "nextEscrowStartedAt", + "type": "i64", + "index": false + } + ] + }, + { + "name": "NewEscrowEvent", + "fields": [ + { + "name": "escrow", + "type": "publicKey", + "index": false + }, + { + "name": "escrowOwner", + "type": "publicKey", + "index": false + }, + { + "name": "locker", + "type": "publicKey", + "index": false + }, + { + "name": "timestamp", + "type": "i64", + "index": false + } + ] + }, + { + "name": "NewLockerEvent", + "fields": [ + { + "name": "governor", + "type": "publicKey", + "index": false + }, + { + "name": "locker", + "type": "publicKey", + "index": false + }, + { + "name": "tokenMint", + "type": "publicKey", + "index": false + }, + { + "name": "params", + "type": { + "defined": "LockerParams" + }, + "index": false + } + ] + }, + { + "name": "RevokeLockPrivilegeEvent", + "fields": [ + { + "name": "locker", + "type": "publicKey", + "index": false + }, + { + "name": "programId", + "type": "publicKey", + "index": false + }, + { + "name": "timestamp", + "type": "i64", + "index": false + } + ] + }, + { + "name": "LockerSetParamsEvent", + "fields": [ + { + "name": "locker", + "type": "publicKey", + "index": false + }, + { + "name": "prevParams", + "type": { + "defined": "LockerParams" + }, + "index": false + }, + { + "name": "params", + "type": { + "defined": "LockerParams" + }, + "index": false + } + ] + }, + { + "name": "SetVoteDelegateEvent", + "fields": [ + { + "name": "escrowOwner", + "type": "publicKey", + "index": false + }, + { + "name": "oldDelegate", + "type": "publicKey", + "index": false + }, + { + "name": "newDelegate", + "type": "publicKey", + "index": false + } + ] + } + ], + "errors": [ + { + "code": 6000, + "name": "ProgramNotWhitelisted", + "msg": "CPI caller not whitelisted to invoke lock instruction." + }, + { + "code": 6001, + "name": "LockupDurationTooShort", + "msg": "Lockup duration must at least be the min stake duration." + }, + { + "code": 6002, + "name": "LockupDurationTooLong", + "msg": "Lockup duration must at most be the max stake duration." + }, + { + "code": 6003, + "name": "RefreshCannotShorten", + "msg": "A voting escrow refresh cannot shorten the escrow time remaining." + }, + { + "code": 6004, + "name": "EscrowNotEnded", + "msg": "Escrow has not ended." + }, + { + "code": 6005, + "name": "MustProvideWhitelist", + "msg": "Program whitelist enabled; please provide whitelist entry and instructions sysvar or use the 'lock_with_whitelist' instruction." + }, + { + "code": 6006, + "name": "EscrowOwnerNotWhitelisted", + "msg": "CPI caller not whitelisted for escrow owner to invoke lock instruction." + }, + { + "code": 6007, + "name": "MustCallLockWithWhitelistEntry", + "msg": "Must call `lock_with_whitelist_entry` to lock via CPI." + }, + { + "code": 6008, + "name": "MustCallLockPermissionless", + "msg": "Must call `lock_permissionless` since this DAO does not have a CPI whitelist." + } + ] +} diff --git a/clients/tribeca/package.json b/clients/tribeca/package.json new file mode 100644 index 00000000..a3f96b79 --- /dev/null +++ b/clients/tribeca/package.json @@ -0,0 +1,57 @@ +{ + "name": "@macalinao/clients-tribeca", + "version": "0.1.0", + "description": "TypeScript client for Tribeca governance programs (Govern and Locked Voter)", + "type": "module", + "sideEffects": false, + "author": "Ian Macalinao ", + "homepage": "https://coda.ianm.com", + "license": "Apache-2.0", + "keywords": [ + "coda", + "solana", + "tribeca", + "governance", + "voting", + "dao", + "client", + "typescript" + ], + "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "import": "./dist/index.js", + "types": "./dist/index.d.ts" + } + }, + "files": [ + "dist/", + "src/" + ], + "scripts": { + "build": "tsc", + "clean": "rm -fr dist/ tsconfig.tsbuildinfo", + "codegen": "rm -fr src/generated/ && coda generate", + "lint": "eslint . --cache" + }, + "peerDependencies": { + "@solana/kit": "*" + }, + "devDependencies": { + "@macalinao/coda": "workspace:^", + "@macalinao/eslint-config": "catalog:", + "@macalinao/tsconfig": "catalog:", + "@solana/kit": "catalog:", + "eslint": "catalog:", + "typescript": "catalog:" + }, + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/macalinao/coda.git", + "directory": "clients/tribeca" + } +} diff --git a/clients/tribeca/src/generated/accounts/escrow.ts b/clients/tribeca/src/generated/accounts/escrow.ts new file mode 100644 index 00000000..fc199e49 --- /dev/null +++ b/clients/tribeca/src/generated/accounts/escrow.ts @@ -0,0 +1,185 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import type { EscrowSeeds } from "../pdas/index.js"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findEscrowPda } from "../pdas/index.js"; + +export const ESCROW_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 31, 213, 123, 187, 186, 22, 218, 155, +]); + +export function getEscrowDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(ESCROW_DISCRIMINATOR); +} + +export interface Escrow { + discriminator: ReadonlyUint8Array; + locker: Address; + owner: Address; + bump: number; + tokens: Address; + amount: bigint; + escrowStartedAt: bigint; + escrowEndsAt: bigint; + voteDelegate: Address; +} + +export interface EscrowArgs { + locker: Address; + owner: Address; + bump: number; + tokens: Address; + amount: number | bigint; + escrowStartedAt: number | bigint; + escrowEndsAt: number | bigint; + voteDelegate: Address; +} + +export function getEscrowEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["locker", getAddressEncoder()], + ["owner", getAddressEncoder()], + ["bump", getU8Encoder()], + ["tokens", getAddressEncoder()], + ["amount", getU64Encoder()], + ["escrowStartedAt", getI64Encoder()], + ["escrowEndsAt", getI64Encoder()], + ["voteDelegate", getAddressEncoder()], + ]), + (value) => ({ ...value, discriminator: ESCROW_DISCRIMINATOR }), + ); +} + +export function getEscrowDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["locker", getAddressDecoder()], + ["owner", getAddressDecoder()], + ["bump", getU8Decoder()], + ["tokens", getAddressDecoder()], + ["amount", getU64Decoder()], + ["escrowStartedAt", getI64Decoder()], + ["escrowEndsAt", getI64Decoder()], + ["voteDelegate", getAddressDecoder()], + ]); +} + +export function getEscrowCodec(): FixedSizeCodec { + return combineCodec(getEscrowEncoder(), getEscrowDecoder()); +} + +export function decodeEscrow( + encodedAccount: EncodedAccount, +): Account; +export function decodeEscrow( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeEscrow( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getEscrowDecoder(), + ); +} + +export async function fetchEscrow( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeEscrow(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeEscrow( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeEscrow(maybeAccount); +} + +export async function fetchAllEscrow( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeEscrow(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeEscrow( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeEscrow(maybeAccount)); +} + +export async function fetchEscrowFromSeeds( + rpc: Parameters[0], + seeds: EscrowSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeEscrowFromSeeds(rpc, seeds, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeEscrowFromSeeds( + rpc: Parameters[0], + seeds: EscrowSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findEscrowPda(seeds, { programAddress }); + return await fetchMaybeEscrow(rpc, address, fetchConfig); +} diff --git a/clients/tribeca/src/generated/accounts/governor.ts b/clients/tribeca/src/generated/accounts/governor.ts new file mode 100644 index 00000000..d1bc93c3 --- /dev/null +++ b/clients/tribeca/src/generated/accounts/governor.ts @@ -0,0 +1,183 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import type { GovernorSeeds } from "../pdas/index.js"; +import type { + GovernanceParameters, + GovernanceParametersArgs, +} from "../types/index.js"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findGovernorPda } from "../pdas/index.js"; +import { + getGovernanceParametersDecoder, + getGovernanceParametersEncoder, +} from "../types/index.js"; + +export const GOVERNOR_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 37, 136, 44, 80, 68, 85, 213, 178, +]); + +export function getGovernorDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(GOVERNOR_DISCRIMINATOR); +} + +export interface Governor { + discriminator: ReadonlyUint8Array; + base: Address; + bump: number; + proposalCount: bigint; + electorate: Address; + smartWallet: Address; + params: GovernanceParameters; +} + +export interface GovernorArgs { + base: Address; + bump: number; + proposalCount: number | bigint; + electorate: Address; + smartWallet: Address; + params: GovernanceParametersArgs; +} + +export function getGovernorEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["base", getAddressEncoder()], + ["bump", getU8Encoder()], + ["proposalCount", getU64Encoder()], + ["electorate", getAddressEncoder()], + ["smartWallet", getAddressEncoder()], + ["params", getGovernanceParametersEncoder()], + ]), + (value) => ({ ...value, discriminator: GOVERNOR_DISCRIMINATOR }), + ); +} + +export function getGovernorDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["base", getAddressDecoder()], + ["bump", getU8Decoder()], + ["proposalCount", getU64Decoder()], + ["electorate", getAddressDecoder()], + ["smartWallet", getAddressDecoder()], + ["params", getGovernanceParametersDecoder()], + ]); +} + +export function getGovernorCodec(): FixedSizeCodec { + return combineCodec(getGovernorEncoder(), getGovernorDecoder()); +} + +export function decodeGovernor( + encodedAccount: EncodedAccount, +): Account; +export function decodeGovernor( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeGovernor( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getGovernorDecoder(), + ); +} + +export async function fetchGovernor( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeGovernor(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeGovernor( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeGovernor(maybeAccount); +} + +export async function fetchAllGovernor( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeGovernor(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeGovernor( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeGovernor(maybeAccount)); +} + +export async function fetchGovernorFromSeeds( + rpc: Parameters[0], + seeds: GovernorSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeGovernorFromSeeds(rpc, seeds, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeGovernorFromSeeds( + rpc: Parameters[0], + seeds: GovernorSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findGovernorPda(seeds, { programAddress }); + return await fetchMaybeGovernor(rpc, address, fetchConfig); +} diff --git a/clients/tribeca/src/generated/accounts/index.ts b/clients/tribeca/src/generated/accounts/index.ts new file mode 100644 index 00000000..e6057cef --- /dev/null +++ b/clients/tribeca/src/generated/accounts/index.ts @@ -0,0 +1,15 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./escrow.js"; +export * from "./governor.js"; +export * from "./locker.js"; +export * from "./lockerWhitelistEntry.js"; +export * from "./proposal.js"; +export * from "./proposalMeta.js"; +export * from "./vote.js"; diff --git a/clients/tribeca/src/generated/accounts/locker.ts b/clients/tribeca/src/generated/accounts/locker.ts new file mode 100644 index 00000000..abfbedb4 --- /dev/null +++ b/clients/tribeca/src/generated/accounts/locker.ts @@ -0,0 +1,180 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import type { LockerSeeds } from "../pdas/index.js"; +import type { LockerParams, LockerParamsArgs } from "../types/index.js"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findLockerPda } from "../pdas/index.js"; +import { + getLockerParamsDecoder, + getLockerParamsEncoder, +} from "../types/index.js"; + +export const LOCKER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 74, 246, 6, 113, 249, 228, 75, 169, +]); + +export function getLockerDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(LOCKER_DISCRIMINATOR); +} + +export interface Locker { + discriminator: ReadonlyUint8Array; + base: Address; + bump: number; + tokenMint: Address; + lockedSupply: bigint; + governor: Address; + params: LockerParams; +} + +export interface LockerArgs { + base: Address; + bump: number; + tokenMint: Address; + lockedSupply: number | bigint; + governor: Address; + params: LockerParamsArgs; +} + +export function getLockerEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["base", getAddressEncoder()], + ["bump", getU8Encoder()], + ["tokenMint", getAddressEncoder()], + ["lockedSupply", getU64Encoder()], + ["governor", getAddressEncoder()], + ["params", getLockerParamsEncoder()], + ]), + (value) => ({ ...value, discriminator: LOCKER_DISCRIMINATOR }), + ); +} + +export function getLockerDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["base", getAddressDecoder()], + ["bump", getU8Decoder()], + ["tokenMint", getAddressDecoder()], + ["lockedSupply", getU64Decoder()], + ["governor", getAddressDecoder()], + ["params", getLockerParamsDecoder()], + ]); +} + +export function getLockerCodec(): FixedSizeCodec { + return combineCodec(getLockerEncoder(), getLockerDecoder()); +} + +export function decodeLocker( + encodedAccount: EncodedAccount, +): Account; +export function decodeLocker( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeLocker( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getLockerDecoder(), + ); +} + +export async function fetchLocker( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeLocker(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeLocker( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeLocker(maybeAccount); +} + +export async function fetchAllLocker( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeLocker(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeLocker( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeLocker(maybeAccount)); +} + +export async function fetchLockerFromSeeds( + rpc: Parameters[0], + seeds: LockerSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeLockerFromSeeds(rpc, seeds, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeLockerFromSeeds( + rpc: Parameters[0], + seeds: LockerSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findLockerPda(seeds, { programAddress }); + return await fetchMaybeLocker(rpc, address, fetchConfig); +} diff --git a/clients/tribeca/src/generated/accounts/lockerWhitelistEntry.ts b/clients/tribeca/src/generated/accounts/lockerWhitelistEntry.ts new file mode 100644 index 00000000..4fbb013a --- /dev/null +++ b/clients/tribeca/src/generated/accounts/lockerWhitelistEntry.ts @@ -0,0 +1,195 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import type { WhitelistSeeds } from "../pdas/index.js"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { findWhitelistPda } from "../pdas/index.js"; + +export const LOCKER_WHITELIST_ENTRY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([128, 245, 238, 138, 226, 48, 216, 63]); + +export function getLockerWhitelistEntryDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + LOCKER_WHITELIST_ENTRY_DISCRIMINATOR, + ); +} + +export interface LockerWhitelistEntry { + discriminator: ReadonlyUint8Array; + bump: number; + locker: Address; + programId: Address; + owner: Address; +} + +export interface LockerWhitelistEntryArgs { + bump: number; + locker: Address; + programId: Address; + owner: Address; +} + +export function getLockerWhitelistEntryEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bump", getU8Encoder()], + ["locker", getAddressEncoder()], + ["programId", getAddressEncoder()], + ["owner", getAddressEncoder()], + ]), + (value) => ({ + ...value, + discriminator: LOCKER_WHITELIST_ENTRY_DISCRIMINATOR, + }), + ); +} + +export function getLockerWhitelistEntryDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bump", getU8Decoder()], + ["locker", getAddressDecoder()], + ["programId", getAddressDecoder()], + ["owner", getAddressDecoder()], + ]); +} + +export function getLockerWhitelistEntryCodec(): FixedSizeCodec< + LockerWhitelistEntryArgs, + LockerWhitelistEntry +> { + return combineCodec( + getLockerWhitelistEntryEncoder(), + getLockerWhitelistEntryDecoder(), + ); +} + +export function decodeLockerWhitelistEntry( + encodedAccount: EncodedAccount, +): Account; +export function decodeLockerWhitelistEntry( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeLockerWhitelistEntry( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): + | Account + | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getLockerWhitelistEntryDecoder(), + ); +} + +export async function fetchLockerWhitelistEntry< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeLockerWhitelistEntry( + rpc, + address, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeLockerWhitelistEntry< + TAddress extends string = string, +>( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeLockerWhitelistEntry(maybeAccount); +} + +export async function fetchAllLockerWhitelistEntry( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeLockerWhitelistEntry( + rpc, + addresses, + config, + ); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeLockerWhitelistEntry( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => + decodeLockerWhitelistEntry(maybeAccount), + ); +} + +export async function fetchLockerWhitelistEntryFromSeeds( + rpc: Parameters[0], + seeds: WhitelistSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeLockerWhitelistEntryFromSeeds( + rpc, + seeds, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeLockerWhitelistEntryFromSeeds( + rpc: Parameters[0], + seeds: WhitelistSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findWhitelistPda(seeds, { programAddress }); + return await fetchMaybeLockerWhitelistEntry(rpc, address, fetchConfig); +} diff --git a/clients/tribeca/src/generated/accounts/proposal.ts b/clients/tribeca/src/generated/accounts/proposal.ts new file mode 100644 index 00000000..1c6a09da --- /dev/null +++ b/clients/tribeca/src/generated/accounts/proposal.ts @@ -0,0 +1,223 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + Codec, + Decoder, + EncodedAccount, + Encoder, + FetchAccountConfig, + FetchAccountsConfig, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import type { ProposalSeeds } from "../pdas/index.js"; +import type { + ProposalInstruction, + ProposalInstructionArgs, +} from "../types/index.js"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findProposalPda } from "../pdas/index.js"; +import { + getProposalInstructionDecoder, + getProposalInstructionEncoder, +} from "../types/index.js"; + +export const PROPOSAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 26, 94, 189, 187, 116, 136, 53, 33, +]); + +export function getProposalDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(PROPOSAL_DISCRIMINATOR); +} + +export interface Proposal { + discriminator: ReadonlyUint8Array; + governor: Address; + index: bigint; + bump: number; + proposer: Address; + quorumVotes: bigint; + forVotes: bigint; + againstVotes: bigint; + abstainVotes: bigint; + canceledAt: bigint; + createdAt: bigint; + activatedAt: bigint; + votingEndsAt: bigint; + queuedAt: bigint; + queuedTransaction: Address; + instructions: ProposalInstruction[]; +} + +export interface ProposalArgs { + governor: Address; + index: number | bigint; + bump: number; + proposer: Address; + quorumVotes: number | bigint; + forVotes: number | bigint; + againstVotes: number | bigint; + abstainVotes: number | bigint; + canceledAt: number | bigint; + createdAt: number | bigint; + activatedAt: number | bigint; + votingEndsAt: number | bigint; + queuedAt: number | bigint; + queuedTransaction: Address; + instructions: ProposalInstructionArgs[]; +} + +export function getProposalEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["governor", getAddressEncoder()], + ["index", getU64Encoder()], + ["bump", getU8Encoder()], + ["proposer", getAddressEncoder()], + ["quorumVotes", getU64Encoder()], + ["forVotes", getU64Encoder()], + ["againstVotes", getU64Encoder()], + ["abstainVotes", getU64Encoder()], + ["canceledAt", getI64Encoder()], + ["createdAt", getI64Encoder()], + ["activatedAt", getI64Encoder()], + ["votingEndsAt", getI64Encoder()], + ["queuedAt", getI64Encoder()], + ["queuedTransaction", getAddressEncoder()], + ["instructions", getArrayEncoder(getProposalInstructionEncoder())], + ]), + (value) => ({ ...value, discriminator: PROPOSAL_DISCRIMINATOR }), + ); +} + +export function getProposalDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["governor", getAddressDecoder()], + ["index", getU64Decoder()], + ["bump", getU8Decoder()], + ["proposer", getAddressDecoder()], + ["quorumVotes", getU64Decoder()], + ["forVotes", getU64Decoder()], + ["againstVotes", getU64Decoder()], + ["abstainVotes", getU64Decoder()], + ["canceledAt", getI64Decoder()], + ["createdAt", getI64Decoder()], + ["activatedAt", getI64Decoder()], + ["votingEndsAt", getI64Decoder()], + ["queuedAt", getI64Decoder()], + ["queuedTransaction", getAddressDecoder()], + ["instructions", getArrayDecoder(getProposalInstructionDecoder())], + ]); +} + +export function getProposalCodec(): Codec { + return combineCodec(getProposalEncoder(), getProposalDecoder()); +} + +export function decodeProposal( + encodedAccount: EncodedAccount, +): Account; +export function decodeProposal( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeProposal( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getProposalDecoder(), + ); +} + +export async function fetchProposal( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeProposal(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeProposal( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeProposal(maybeAccount); +} + +export async function fetchAllProposal( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeProposal(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeProposal( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeProposal(maybeAccount)); +} + +export async function fetchProposalFromSeeds( + rpc: Parameters[0], + seeds: ProposalSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeProposalFromSeeds(rpc, seeds, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeProposalFromSeeds( + rpc: Parameters[0], + seeds: ProposalSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findProposalPda(seeds, { programAddress }); + return await fetchMaybeProposal(rpc, address, fetchConfig); +} diff --git a/clients/tribeca/src/generated/accounts/proposalMeta.ts b/clients/tribeca/src/generated/accounts/proposalMeta.ts new file mode 100644 index 00000000..efa5f387 --- /dev/null +++ b/clients/tribeca/src/generated/accounts/proposalMeta.ts @@ -0,0 +1,177 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + Codec, + Decoder, + EncodedAccount, + Encoder, + FetchAccountConfig, + FetchAccountsConfig, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import type { ProposalMetaSeeds } from "../pdas/index.js"; +import { + addDecoderSizePrefix, + addEncoderSizePrefix, + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, + getUtf8Decoder, + getUtf8Encoder, + transformEncoder, +} from "@solana/kit"; +import { findProposalMetaPda } from "../pdas/index.js"; + +export const PROPOSAL_META_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 50, 100, 46, 24, 151, 174, 216, 78, +]); + +export function getProposalMetaDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + PROPOSAL_META_DISCRIMINATOR, + ); +} + +export interface ProposalMeta { + discriminator: ReadonlyUint8Array; + proposal: Address; + title: string; + descriptionLink: string; +} + +export interface ProposalMetaArgs { + proposal: Address; + title: string; + descriptionLink: string; +} + +export function getProposalMetaEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["proposal", getAddressEncoder()], + ["title", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + [ + "descriptionLink", + addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()), + ], + ]), + (value) => ({ ...value, discriminator: PROPOSAL_META_DISCRIMINATOR }), + ); +} + +export function getProposalMetaDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["proposal", getAddressDecoder()], + ["title", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + [ + "descriptionLink", + addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder()), + ], + ]); +} + +export function getProposalMetaCodec(): Codec { + return combineCodec(getProposalMetaEncoder(), getProposalMetaDecoder()); +} + +export function decodeProposalMeta( + encodedAccount: EncodedAccount, +): Account; +export function decodeProposalMeta( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeProposalMeta( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getProposalMetaDecoder(), + ); +} + +export async function fetchProposalMeta( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeProposalMeta(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeProposalMeta( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeProposalMeta(maybeAccount); +} + +export async function fetchAllProposalMeta( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeProposalMeta(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeProposalMeta( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeProposalMeta(maybeAccount)); +} + +export async function fetchProposalMetaFromSeeds( + rpc: Parameters[0], + seeds: ProposalMetaSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeProposalMetaFromSeeds( + rpc, + seeds, + config, + ); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeProposalMetaFromSeeds( + rpc: Parameters[0], + seeds: ProposalMetaSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findProposalMetaPda(seeds, { programAddress }); + return await fetchMaybeProposalMeta(rpc, address, fetchConfig); +} diff --git a/clients/tribeca/src/generated/accounts/vote.ts b/clients/tribeca/src/generated/accounts/vote.ts new file mode 100644 index 00000000..5b0b0d30 --- /dev/null +++ b/clients/tribeca/src/generated/accounts/vote.ts @@ -0,0 +1,171 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Account, + Address, + EncodedAccount, + FetchAccountConfig, + FetchAccountsConfig, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + MaybeAccount, + MaybeEncodedAccount, + ReadonlyUint8Array, +} from "@solana/kit"; +import type { VoteSeeds } from "../pdas/index.js"; +import { + assertAccountExists, + assertAccountsExist, + combineCodec, + decodeAccount, + fetchEncodedAccount, + fetchEncodedAccounts, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { findVotePda } from "../pdas/index.js"; + +export const VOTE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 96, 91, 104, 57, 145, 35, 172, 155, +]); + +export function getVoteDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(VOTE_DISCRIMINATOR); +} + +export interface Vote { + discriminator: ReadonlyUint8Array; + proposal: Address; + voter: Address; + bump: number; + side: number; + weight: bigint; +} + +export interface VoteArgs { + proposal: Address; + voter: Address; + bump: number; + side: number; + weight: number | bigint; +} + +export function getVoteEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["proposal", getAddressEncoder()], + ["voter", getAddressEncoder()], + ["bump", getU8Encoder()], + ["side", getU8Encoder()], + ["weight", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: VOTE_DISCRIMINATOR }), + ); +} + +export function getVoteDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["proposal", getAddressDecoder()], + ["voter", getAddressDecoder()], + ["bump", getU8Decoder()], + ["side", getU8Decoder()], + ["weight", getU64Decoder()], + ]); +} + +export function getVoteCodec(): FixedSizeCodec { + return combineCodec(getVoteEncoder(), getVoteDecoder()); +} + +export function decodeVote( + encodedAccount: EncodedAccount, +): Account; +export function decodeVote( + encodedAccount: MaybeEncodedAccount, +): MaybeAccount; +export function decodeVote( + encodedAccount: EncodedAccount | MaybeEncodedAccount, +): Account | MaybeAccount { + return decodeAccount( + encodedAccount as MaybeEncodedAccount, + getVoteDecoder(), + ); +} + +export async function fetchVote( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchMaybeVote(rpc, address, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeVote( + rpc: Parameters[0], + address: Address, + config?: FetchAccountConfig, +): Promise> { + const maybeAccount = await fetchEncodedAccount(rpc, address, config); + return decodeVote(maybeAccount); +} + +export async function fetchAllVote( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchAllMaybeVote(rpc, addresses, config); + assertAccountsExist(maybeAccounts); + return maybeAccounts; +} + +export async function fetchAllMaybeVote( + rpc: Parameters[0], + addresses: Address[], + config?: FetchAccountsConfig, +): Promise[]> { + const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config); + return maybeAccounts.map((maybeAccount) => decodeVote(maybeAccount)); +} + +export async function fetchVoteFromSeeds( + rpc: Parameters[0], + seeds: VoteSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const maybeAccount = await fetchMaybeVoteFromSeeds(rpc, seeds, config); + assertAccountExists(maybeAccount); + return maybeAccount; +} + +export async function fetchMaybeVoteFromSeeds( + rpc: Parameters[0], + seeds: VoteSeeds, + config: FetchAccountConfig & { programAddress?: Address } = {}, +): Promise> { + const { programAddress, ...fetchConfig } = config; + const [address] = await findVotePda(seeds, { programAddress }); + return await fetchMaybeVote(rpc, address, fetchConfig); +} diff --git a/clients/tribeca/src/generated/errors/govern.ts b/clients/tribeca/src/generated/errors/govern.ts new file mode 100644 index 00000000..7ae4665a --- /dev/null +++ b/clients/tribeca/src/generated/errors/govern.ts @@ -0,0 +1,69 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, + SolanaError, +} from "@solana/kit"; +import { isProgramError } from "@solana/kit"; +import { GOVERN_PROGRAM_ADDRESS } from "../programs/index.js"; + +/** InvalidVoteSide: Invalid vote side. */ +export const GOVERN_ERROR__INVALID_VOTE_SIDE = 0x1770; // 6000 +/** GovernorNotFound: The owner of the smart wallet doesn't match with current. */ +export const GOVERN_ERROR__GOVERNOR_NOT_FOUND = 0x1771; // 6001 +/** VotingDelayNotMet: The proposal cannot be activated since it has not yet passed the voting delay. */ +export const GOVERN_ERROR__VOTING_DELAY_NOT_MET = 0x1772; // 6002 +/** ProposalNotDraft: Only drafts can be canceled. */ +export const GOVERN_ERROR__PROPOSAL_NOT_DRAFT = 0x1773; // 6003 +/** ProposalNotActive: The proposal must be active. */ +export const GOVERN_ERROR__PROPOSAL_NOT_ACTIVE = 0x1774; // 6004 + +export type GovernError = + | typeof GOVERN_ERROR__GOVERNOR_NOT_FOUND + | typeof GOVERN_ERROR__INVALID_VOTE_SIDE + | typeof GOVERN_ERROR__PROPOSAL_NOT_ACTIVE + | typeof GOVERN_ERROR__PROPOSAL_NOT_DRAFT + | typeof GOVERN_ERROR__VOTING_DELAY_NOT_MET; + +let governErrorMessages: Record | undefined; +if (true) { + governErrorMessages = { + [GOVERN_ERROR__GOVERNOR_NOT_FOUND]: `The owner of the smart wallet doesn't match with current.`, + [GOVERN_ERROR__INVALID_VOTE_SIDE]: "Invalid vote side.", + [GOVERN_ERROR__PROPOSAL_NOT_ACTIVE]: "The proposal must be active.", + [GOVERN_ERROR__PROPOSAL_NOT_DRAFT]: "Only drafts can be canceled.", + [GOVERN_ERROR__VOTING_DELAY_NOT_MET]: + "The proposal cannot be activated since it has not yet passed the voting delay.", + }; +} + +export function getGovernErrorMessage(code: GovernError): string { + if (true) { + return governErrorMessages![code]; + } + + return "Error message not available in production bundles."; +} + +export function isGovernError( + error: unknown, + transactionMessage: { + instructions: Record; + }, + code?: TProgramErrorCode, +): error is SolanaError & + Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { + return isProgramError( + error, + transactionMessage, + GOVERN_PROGRAM_ADDRESS, + code, + ); +} diff --git a/clients/tribeca/src/generated/errors/index.ts b/clients/tribeca/src/generated/errors/index.ts new file mode 100644 index 00000000..c900e269 --- /dev/null +++ b/clients/tribeca/src/generated/errors/index.ts @@ -0,0 +1,10 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./govern.js"; +export * from "./lockedVoter.js"; diff --git a/clients/tribeca/src/generated/errors/lockedVoter.ts b/clients/tribeca/src/generated/errors/lockedVoter.ts new file mode 100644 index 00000000..c075cb86 --- /dev/null +++ b/clients/tribeca/src/generated/errors/lockedVoter.ts @@ -0,0 +1,91 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, + SolanaError, +} from "@solana/kit"; +import { isProgramError } from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; + +/** ProgramNotWhitelisted: CPI caller not whitelisted to invoke lock instruction. */ +export const LOCKED_VOTER_ERROR__PROGRAM_NOT_WHITELISTED = 0x1770; // 6000 +/** LockupDurationTooShort: Lockup duration must at least be the min stake duration. */ +export const LOCKED_VOTER_ERROR__LOCKUP_DURATION_TOO_SHORT = 0x1771; // 6001 +/** LockupDurationTooLong: Lockup duration must at most be the max stake duration. */ +export const LOCKED_VOTER_ERROR__LOCKUP_DURATION_TOO_LONG = 0x1772; // 6002 +/** RefreshCannotShorten: A voting escrow refresh cannot shorten the escrow time remaining. */ +export const LOCKED_VOTER_ERROR__REFRESH_CANNOT_SHORTEN = 0x1773; // 6003 +/** EscrowNotEnded: Escrow has not ended. */ +export const LOCKED_VOTER_ERROR__ESCROW_NOT_ENDED = 0x1774; // 6004 +/** MustProvideWhitelist: Program whitelist enabled; please provide whitelist entry and instructions sysvar or use the 'lock_with_whitelist' instruction. */ +export const LOCKED_VOTER_ERROR__MUST_PROVIDE_WHITELIST = 0x1775; // 6005 +/** EscrowOwnerNotWhitelisted: CPI caller not whitelisted for escrow owner to invoke lock instruction. */ +export const LOCKED_VOTER_ERROR__ESCROW_OWNER_NOT_WHITELISTED = 0x1776; // 6006 +/** MustCallLockWithWhitelistEntry: Must call `lock_with_whitelist_entry` to lock via CPI. */ +export const LOCKED_VOTER_ERROR__MUST_CALL_LOCK_WITH_WHITELIST_ENTRY = 0x1777; // 6007 +/** MustCallLockPermissionless: Must call `lock_permissionless` since this DAO does not have a CPI whitelist. */ +export const LOCKED_VOTER_ERROR__MUST_CALL_LOCK_PERMISSIONLESS = 0x1778; // 6008 + +export type LockedVoterError = + | typeof LOCKED_VOTER_ERROR__ESCROW_NOT_ENDED + | typeof LOCKED_VOTER_ERROR__ESCROW_OWNER_NOT_WHITELISTED + | typeof LOCKED_VOTER_ERROR__LOCKUP_DURATION_TOO_LONG + | typeof LOCKED_VOTER_ERROR__LOCKUP_DURATION_TOO_SHORT + | typeof LOCKED_VOTER_ERROR__MUST_CALL_LOCK_PERMISSIONLESS + | typeof LOCKED_VOTER_ERROR__MUST_CALL_LOCK_WITH_WHITELIST_ENTRY + | typeof LOCKED_VOTER_ERROR__MUST_PROVIDE_WHITELIST + | typeof LOCKED_VOTER_ERROR__PROGRAM_NOT_WHITELISTED + | typeof LOCKED_VOTER_ERROR__REFRESH_CANNOT_SHORTEN; + +let lockedVoterErrorMessages: Record | undefined; +if (true) { + lockedVoterErrorMessages = { + [LOCKED_VOTER_ERROR__ESCROW_NOT_ENDED]: "Escrow has not ended.", + [LOCKED_VOTER_ERROR__ESCROW_OWNER_NOT_WHITELISTED]: + "CPI caller not whitelisted for escrow owner to invoke lock instruction.", + [LOCKED_VOTER_ERROR__LOCKUP_DURATION_TOO_LONG]: + "Lockup duration must at most be the max stake duration.", + [LOCKED_VOTER_ERROR__LOCKUP_DURATION_TOO_SHORT]: + "Lockup duration must at least be the min stake duration.", + [LOCKED_VOTER_ERROR__MUST_CALL_LOCK_PERMISSIONLESS]: + "Must call `lock_permissionless` since this DAO does not have a CPI whitelist.", + [LOCKED_VOTER_ERROR__MUST_CALL_LOCK_WITH_WHITELIST_ENTRY]: + "Must call `lock_with_whitelist_entry` to lock via CPI.", + [LOCKED_VOTER_ERROR__MUST_PROVIDE_WHITELIST]: `Program whitelist enabled; please provide whitelist entry and instructions sysvar or use the 'lock_with_whitelist' instruction.`, + [LOCKED_VOTER_ERROR__PROGRAM_NOT_WHITELISTED]: + "CPI caller not whitelisted to invoke lock instruction.", + [LOCKED_VOTER_ERROR__REFRESH_CANNOT_SHORTEN]: + "A voting escrow refresh cannot shorten the escrow time remaining.", + }; +} + +export function getLockedVoterErrorMessage(code: LockedVoterError): string { + if (true) { + return lockedVoterErrorMessages![code]; + } + + return "Error message not available in production bundles."; +} + +export function isLockedVoterError( + error: unknown, + transactionMessage: { + instructions: Record; + }, + code?: TProgramErrorCode, +): error is SolanaError & + Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> { + return isProgramError( + error, + transactionMessage, + LOCKED_VOTER_PROGRAM_ADDRESS, + code, + ); +} diff --git a/clients/tribeca/src/generated/index.ts b/clients/tribeca/src/generated/index.ts new file mode 100644 index 00000000..975e985c --- /dev/null +++ b/clients/tribeca/src/generated/index.ts @@ -0,0 +1,14 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./accounts/index.js"; +export * from "./errors/index.js"; +export * from "./instructions/index.js"; +export * from "./pdas/index.js"; +export * from "./programs/index.js"; +export * from "./types/index.js"; diff --git a/clients/tribeca/src/generated/instructions/activateProposal.ts b/clients/tribeca/src/generated/instructions/activateProposal.ts new file mode 100644 index 00000000..c801ff39 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/activateProposal.ts @@ -0,0 +1,242 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const ACTIVATE_PROPOSAL_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([90, 186, 203, 234, 70, 185, 191, 21]); + +export function getActivateProposalDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + ACTIVATE_PROPOSAL_DISCRIMINATOR, + ); +} + +export type ActivateProposalInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountGovernor extends string | AccountMeta = string, + TAccountProposal extends string | AccountMeta = string, + TAccountEscrow extends string | AccountMeta = string, + TAccountEscrowOwner extends string | AccountMeta = string, + TAccountGovernProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? ReadonlyAccount + : TAccountLocker, + TAccountGovernor extends string + ? ReadonlyAccount + : TAccountGovernor, + TAccountProposal extends string + ? WritableAccount + : TAccountProposal, + TAccountEscrow extends string + ? ReadonlyAccount + : TAccountEscrow, + TAccountEscrowOwner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountEscrowOwner, + TAccountGovernProgram extends string + ? ReadonlyAccount + : TAccountGovernProgram, + ...TRemainingAccounts, + ] + >; + +export interface ActivateProposalInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface ActivateProposalInstructionDataArgs {} + +export function getActivateProposalInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: ACTIVATE_PROPOSAL_DISCRIMINATOR }), + ); +} + +export function getActivateProposalInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getActivateProposalInstructionDataCodec(): FixedSizeCodec< + ActivateProposalInstructionDataArgs, + ActivateProposalInstructionData +> { + return combineCodec( + getActivateProposalInstructionDataEncoder(), + getActivateProposalInstructionDataDecoder(), + ); +} + +export interface ActivateProposalInput< + TAccountLocker extends string = string, + TAccountGovernor extends string = string, + TAccountProposal extends string = string, + TAccountEscrow extends string = string, + TAccountEscrowOwner extends string = string, + TAccountGovernProgram extends string = string, +> { + locker: Address; + governor: Address; + proposal: Address; + escrow: Address; + escrowOwner: TransactionSigner; + governProgram: Address; +} + +export function getActivateProposalInstruction< + TAccountLocker extends string, + TAccountGovernor extends string, + TAccountProposal extends string, + TAccountEscrow extends string, + TAccountEscrowOwner extends string, + TAccountGovernProgram extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: ActivateProposalInput< + TAccountLocker, + TAccountGovernor, + TAccountProposal, + TAccountEscrow, + TAccountEscrowOwner, + TAccountGovernProgram + >, + config?: { programAddress?: TProgramAddress }, +): ActivateProposalInstruction< + TProgramAddress, + TAccountLocker, + TAccountGovernor, + TAccountProposal, + TAccountEscrow, + TAccountEscrowOwner, + TAccountGovernProgram +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: false }, + governor: { value: input.governor ?? null, isWritable: false }, + proposal: { value: input.proposal ?? null, isWritable: true }, + escrow: { value: input.escrow ?? null, isWritable: false }, + escrowOwner: { value: input.escrowOwner ?? null, isWritable: false }, + governProgram: { value: input.governProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.governor), + getAccountMeta(accounts.proposal), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.escrowOwner), + getAccountMeta(accounts.governProgram), + ], + data: getActivateProposalInstructionDataEncoder().encode({}), + programAddress, + } as ActivateProposalInstruction< + TProgramAddress, + TAccountLocker, + TAccountGovernor, + TAccountProposal, + TAccountEscrow, + TAccountEscrowOwner, + TAccountGovernProgram + >); +} + +export interface ParsedActivateProposalInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + governor: TAccountMetas[1]; + proposal: TAccountMetas[2]; + escrow: TAccountMetas[3]; + escrowOwner: TAccountMetas[4]; + governProgram: TAccountMetas[5]; + }; + data: ActivateProposalInstructionData; +} + +export function parseActivateProposalInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedActivateProposalInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + governor: getNextAccount(), + proposal: getNextAccount(), + escrow: getNextAccount(), + escrowOwner: getNextAccount(), + governProgram: getNextAccount(), + }, + data: getActivateProposalInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/approveProgramLockPrivilege.ts b/clients/tribeca/src/generated/instructions/approveProgramLockPrivilege.ts new file mode 100644 index 00000000..de2a75f5 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/approveProgramLockPrivilege.ts @@ -0,0 +1,303 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const APPROVE_PROGRAM_LOCK_PRIVILEGE_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([75, 202, 1, 4, 122, 110, 102, 148]); + +export function getApproveProgramLockPrivilegeDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + APPROVE_PROGRAM_LOCK_PRIVILEGE_DISCRIMINATOR, + ); +} + +export type ApproveProgramLockPrivilegeInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountWhitelistEntry extends string | AccountMeta = string, + TAccountGovernor extends string | AccountMeta = string, + TAccountSmartWallet extends string | AccountMeta = string, + TAccountExecutableId extends string | AccountMeta = string, + TAccountWhitelistedOwner extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? ReadonlyAccount + : TAccountLocker, + TAccountWhitelistEntry extends string + ? WritableAccount + : TAccountWhitelistEntry, + TAccountGovernor extends string + ? ReadonlyAccount + : TAccountGovernor, + TAccountSmartWallet extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSmartWallet, + TAccountExecutableId extends string + ? ReadonlyAccount + : TAccountExecutableId, + TAccountWhitelistedOwner extends string + ? ReadonlyAccount + : TAccountWhitelistedOwner, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface ApproveProgramLockPrivilegeInstructionData { + discriminator: ReadonlyUint8Array; + bump: number; +} + +export interface ApproveProgramLockPrivilegeInstructionDataArgs { + bump: number; +} + +export function getApproveProgramLockPrivilegeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bump", getU8Encoder()], + ]), + (value) => ({ + ...value, + discriminator: APPROVE_PROGRAM_LOCK_PRIVILEGE_DISCRIMINATOR, + }), + ); +} + +export function getApproveProgramLockPrivilegeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bump", getU8Decoder()], + ]); +} + +export function getApproveProgramLockPrivilegeInstructionDataCodec(): FixedSizeCodec< + ApproveProgramLockPrivilegeInstructionDataArgs, + ApproveProgramLockPrivilegeInstructionData +> { + return combineCodec( + getApproveProgramLockPrivilegeInstructionDataEncoder(), + getApproveProgramLockPrivilegeInstructionDataDecoder(), + ); +} + +export interface ApproveProgramLockPrivilegeInput< + TAccountLocker extends string = string, + TAccountWhitelistEntry extends string = string, + TAccountGovernor extends string = string, + TAccountSmartWallet extends string = string, + TAccountExecutableId extends string = string, + TAccountWhitelistedOwner extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, +> { + locker: Address; + whitelistEntry: Address; + governor: Address; + smartWallet: TransactionSigner; + executableId: Address; + whitelistedOwner: Address; + payer: TransactionSigner; + systemProgram?: Address; + bump: ApproveProgramLockPrivilegeInstructionDataArgs["bump"]; +} + +export function getApproveProgramLockPrivilegeInstruction< + TAccountLocker extends string, + TAccountWhitelistEntry extends string, + TAccountGovernor extends string, + TAccountSmartWallet extends string, + TAccountExecutableId extends string, + TAccountWhitelistedOwner extends string, + TAccountPayer extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: ApproveProgramLockPrivilegeInput< + TAccountLocker, + TAccountWhitelistEntry, + TAccountGovernor, + TAccountSmartWallet, + TAccountExecutableId, + TAccountWhitelistedOwner, + TAccountPayer, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): ApproveProgramLockPrivilegeInstruction< + TProgramAddress, + TAccountLocker, + TAccountWhitelistEntry, + TAccountGovernor, + TAccountSmartWallet, + TAccountExecutableId, + TAccountWhitelistedOwner, + TAccountPayer, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: false }, + whitelistEntry: { value: input.whitelistEntry ?? null, isWritable: true }, + governor: { value: input.governor ?? null, isWritable: false }, + smartWallet: { value: input.smartWallet ?? null, isWritable: false }, + executableId: { value: input.executableId ?? null, isWritable: false }, + whitelistedOwner: { + value: input.whitelistedOwner ?? null, + isWritable: false, + }, + payer: { value: input.payer ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.whitelistEntry), + getAccountMeta(accounts.governor), + getAccountMeta(accounts.smartWallet), + getAccountMeta(accounts.executableId), + getAccountMeta(accounts.whitelistedOwner), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + ], + data: getApproveProgramLockPrivilegeInstructionDataEncoder().encode( + args as ApproveProgramLockPrivilegeInstructionDataArgs, + ), + programAddress, + } as ApproveProgramLockPrivilegeInstruction< + TProgramAddress, + TAccountLocker, + TAccountWhitelistEntry, + TAccountGovernor, + TAccountSmartWallet, + TAccountExecutableId, + TAccountWhitelistedOwner, + TAccountPayer, + TAccountSystemProgram + >); +} + +export interface ParsedApproveProgramLockPrivilegeInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + whitelistEntry: TAccountMetas[1]; + governor: TAccountMetas[2]; + smartWallet: TAccountMetas[3]; + executableId: TAccountMetas[4]; + whitelistedOwner: TAccountMetas[5]; + payer: TAccountMetas[6]; + systemProgram: TAccountMetas[7]; + }; + data: ApproveProgramLockPrivilegeInstructionData; +} + +export function parseApproveProgramLockPrivilegeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedApproveProgramLockPrivilegeInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + whitelistEntry: getNextAccount(), + governor: getNextAccount(), + smartWallet: getNextAccount(), + executableId: getNextAccount(), + whitelistedOwner: getNextAccount(), + payer: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getApproveProgramLockPrivilegeInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/tribeca/src/generated/instructions/cancelProposal.ts b/clients/tribeca/src/generated/instructions/cancelProposal.ts new file mode 100644 index 00000000..6b3fb4a4 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/cancelProposal.ts @@ -0,0 +1,201 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { GOVERN_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const CANCEL_PROPOSAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( + [106, 74, 128, 146, 19, 65, 39, 23], +); + +export function getCancelProposalDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CANCEL_PROPOSAL_DISCRIMINATOR, + ); +} + +export type CancelProposalInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountGovernor extends string | AccountMeta = string, + TAccountProposal extends string | AccountMeta = string, + TAccountProposer extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountGovernor extends string + ? ReadonlyAccount + : TAccountGovernor, + TAccountProposal extends string + ? WritableAccount + : TAccountProposal, + TAccountProposer extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountProposer, + ...TRemainingAccounts, + ] + >; + +export interface CancelProposalInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface CancelProposalInstructionDataArgs {} + +export function getCancelProposalInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: CANCEL_PROPOSAL_DISCRIMINATOR }), + ); +} + +export function getCancelProposalInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getCancelProposalInstructionDataCodec(): FixedSizeCodec< + CancelProposalInstructionDataArgs, + CancelProposalInstructionData +> { + return combineCodec( + getCancelProposalInstructionDataEncoder(), + getCancelProposalInstructionDataDecoder(), + ); +} + +export interface CancelProposalInput< + TAccountGovernor extends string = string, + TAccountProposal extends string = string, + TAccountProposer extends string = string, +> { + governor: Address; + proposal: Address; + proposer: TransactionSigner; +} + +export function getCancelProposalInstruction< + TAccountGovernor extends string, + TAccountProposal extends string, + TAccountProposer extends string, + TProgramAddress extends Address = typeof GOVERN_PROGRAM_ADDRESS, +>( + input: CancelProposalInput< + TAccountGovernor, + TAccountProposal, + TAccountProposer + >, + config?: { programAddress?: TProgramAddress }, +): CancelProposalInstruction< + TProgramAddress, + TAccountGovernor, + TAccountProposal, + TAccountProposer +> { + // Program address. + const programAddress = config?.programAddress ?? GOVERN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + governor: { value: input.governor ?? null, isWritable: false }, + proposal: { value: input.proposal ?? null, isWritable: true }, + proposer: { value: input.proposer ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.governor), + getAccountMeta(accounts.proposal), + getAccountMeta(accounts.proposer), + ], + data: getCancelProposalInstructionDataEncoder().encode({}), + programAddress, + } as CancelProposalInstruction< + TProgramAddress, + TAccountGovernor, + TAccountProposal, + TAccountProposer + >); +} + +export interface ParsedCancelProposalInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + governor: TAccountMetas[0]; + proposal: TAccountMetas[1]; + proposer: TAccountMetas[2]; + }; + data: CancelProposalInstructionData; +} + +export function parseCancelProposalInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCancelProposalInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + governor: getNextAccount(), + proposal: getNextAccount(), + proposer: getNextAccount(), + }, + data: getCancelProposalInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/castVote.ts b/clients/tribeca/src/generated/instructions/castVote.ts new file mode 100644 index 00000000..a3266c6c --- /dev/null +++ b/clients/tribeca/src/generated/instructions/castVote.ts @@ -0,0 +1,270 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const CAST_VOTE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 20, 212, 15, 189, 69, 180, 69, 151, +]); + +export function getCastVoteDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(CAST_VOTE_DISCRIMINATOR); +} + +export type CastVoteInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountEscrow extends string | AccountMeta = string, + TAccountVoteDelegate extends string | AccountMeta = string, + TAccountProposal extends string | AccountMeta = string, + TAccountVote extends string | AccountMeta = string, + TAccountGovernor extends string | AccountMeta = string, + TAccountGovernProgram extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? ReadonlyAccount + : TAccountLocker, + TAccountEscrow extends string + ? ReadonlyAccount + : TAccountEscrow, + TAccountVoteDelegate extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountVoteDelegate, + TAccountProposal extends string + ? WritableAccount + : TAccountProposal, + TAccountVote extends string + ? WritableAccount + : TAccountVote, + TAccountGovernor extends string + ? ReadonlyAccount + : TAccountGovernor, + TAccountGovernProgram extends string + ? ReadonlyAccount + : TAccountGovernProgram, + ...TRemainingAccounts, + ] + >; + +export interface CastVoteInstructionData { + discriminator: ReadonlyUint8Array; + side: number; +} + +export interface CastVoteInstructionDataArgs { + side: number; +} + +export function getCastVoteInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["side", getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: CAST_VOTE_DISCRIMINATOR }), + ); +} + +export function getCastVoteInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["side", getU8Decoder()], + ]); +} + +export function getCastVoteInstructionDataCodec(): FixedSizeCodec< + CastVoteInstructionDataArgs, + CastVoteInstructionData +> { + return combineCodec( + getCastVoteInstructionDataEncoder(), + getCastVoteInstructionDataDecoder(), + ); +} + +export interface CastVoteInput< + TAccountLocker extends string = string, + TAccountEscrow extends string = string, + TAccountVoteDelegate extends string = string, + TAccountProposal extends string = string, + TAccountVote extends string = string, + TAccountGovernor extends string = string, + TAccountGovernProgram extends string = string, +> { + locker: Address; + escrow: Address; + voteDelegate: TransactionSigner; + proposal: Address; + vote: Address; + governor: Address; + governProgram: Address; + side: CastVoteInstructionDataArgs["side"]; +} + +export function getCastVoteInstruction< + TAccountLocker extends string, + TAccountEscrow extends string, + TAccountVoteDelegate extends string, + TAccountProposal extends string, + TAccountVote extends string, + TAccountGovernor extends string, + TAccountGovernProgram extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: CastVoteInput< + TAccountLocker, + TAccountEscrow, + TAccountVoteDelegate, + TAccountProposal, + TAccountVote, + TAccountGovernor, + TAccountGovernProgram + >, + config?: { programAddress?: TProgramAddress }, +): CastVoteInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountVoteDelegate, + TAccountProposal, + TAccountVote, + TAccountGovernor, + TAccountGovernProgram +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: false }, + escrow: { value: input.escrow ?? null, isWritable: false }, + voteDelegate: { value: input.voteDelegate ?? null, isWritable: false }, + proposal: { value: input.proposal ?? null, isWritable: true }, + vote: { value: input.vote ?? null, isWritable: true }, + governor: { value: input.governor ?? null, isWritable: false }, + governProgram: { value: input.governProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.voteDelegate), + getAccountMeta(accounts.proposal), + getAccountMeta(accounts.vote), + getAccountMeta(accounts.governor), + getAccountMeta(accounts.governProgram), + ], + data: getCastVoteInstructionDataEncoder().encode( + args as CastVoteInstructionDataArgs, + ), + programAddress, + } as CastVoteInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountVoteDelegate, + TAccountProposal, + TAccountVote, + TAccountGovernor, + TAccountGovernProgram + >); +} + +export interface ParsedCastVoteInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + escrow: TAccountMetas[1]; + voteDelegate: TAccountMetas[2]; + proposal: TAccountMetas[3]; + vote: TAccountMetas[4]; + governor: TAccountMetas[5]; + governProgram: TAccountMetas[6]; + }; + data: CastVoteInstructionData; +} + +export function parseCastVoteInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCastVoteInstruction { + if (instruction.accounts.length < 7) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + escrow: getNextAccount(), + voteDelegate: getNextAccount(), + proposal: getNextAccount(), + vote: getNextAccount(), + governor: getNextAccount(), + governProgram: getNextAccount(), + }, + data: getCastVoteInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/createGovernor.ts b/clients/tribeca/src/generated/instructions/createGovernor.ts new file mode 100644 index 00000000..bb1e26ac --- /dev/null +++ b/clients/tribeca/src/generated/instructions/createGovernor.ts @@ -0,0 +1,273 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import type { + GovernanceParameters, + GovernanceParametersArgs, +} from "../types/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { GOVERN_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import { + getGovernanceParametersDecoder, + getGovernanceParametersEncoder, +} from "../types/index.js"; + +export const CREATE_GOVERNOR_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( + [103, 30, 78, 252, 28, 128, 40, 3], +); + +export function getCreateGovernorDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CREATE_GOVERNOR_DISCRIMINATOR, + ); +} + +export type CreateGovernorInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountBase extends string | AccountMeta = string, + TAccountGovernor extends string | AccountMeta = string, + TAccountSmartWallet extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountBase extends string + ? ReadonlySignerAccount & AccountSignerMeta + : TAccountBase, + TAccountGovernor extends string + ? WritableAccount + : TAccountGovernor, + TAccountSmartWallet extends string + ? ReadonlyAccount + : TAccountSmartWallet, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface CreateGovernorInstructionData { + discriminator: ReadonlyUint8Array; + bump: number; + electorate: Address; + params: GovernanceParameters; +} + +export interface CreateGovernorInstructionDataArgs { + bump: number; + electorate: Address; + params: GovernanceParametersArgs; +} + +export function getCreateGovernorInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bump", getU8Encoder()], + ["electorate", getAddressEncoder()], + ["params", getGovernanceParametersEncoder()], + ]), + (value) => ({ ...value, discriminator: CREATE_GOVERNOR_DISCRIMINATOR }), + ); +} + +export function getCreateGovernorInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bump", getU8Decoder()], + ["electorate", getAddressDecoder()], + ["params", getGovernanceParametersDecoder()], + ]); +} + +export function getCreateGovernorInstructionDataCodec(): FixedSizeCodec< + CreateGovernorInstructionDataArgs, + CreateGovernorInstructionData +> { + return combineCodec( + getCreateGovernorInstructionDataEncoder(), + getCreateGovernorInstructionDataDecoder(), + ); +} + +export interface CreateGovernorInput< + TAccountBase extends string = string, + TAccountGovernor extends string = string, + TAccountSmartWallet extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, +> { + base: TransactionSigner; + governor: Address; + smartWallet: Address; + payer: TransactionSigner; + systemProgram?: Address; + bump: CreateGovernorInstructionDataArgs["bump"]; + electorate: CreateGovernorInstructionDataArgs["electorate"]; + params: CreateGovernorInstructionDataArgs["params"]; +} + +export function getCreateGovernorInstruction< + TAccountBase extends string, + TAccountGovernor extends string, + TAccountSmartWallet extends string, + TAccountPayer extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof GOVERN_PROGRAM_ADDRESS, +>( + input: CreateGovernorInput< + TAccountBase, + TAccountGovernor, + TAccountSmartWallet, + TAccountPayer, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): CreateGovernorInstruction< + TProgramAddress, + TAccountBase, + TAccountGovernor, + TAccountSmartWallet, + TAccountPayer, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? GOVERN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + base: { value: input.base ?? null, isWritable: false }, + governor: { value: input.governor ?? null, isWritable: true }, + smartWallet: { value: input.smartWallet ?? null, isWritable: false }, + payer: { value: input.payer ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.base), + getAccountMeta(accounts.governor), + getAccountMeta(accounts.smartWallet), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + ], + data: getCreateGovernorInstructionDataEncoder().encode( + args as CreateGovernorInstructionDataArgs, + ), + programAddress, + } as CreateGovernorInstruction< + TProgramAddress, + TAccountBase, + TAccountGovernor, + TAccountSmartWallet, + TAccountPayer, + TAccountSystemProgram + >); +} + +export interface ParsedCreateGovernorInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + base: TAccountMetas[0]; + governor: TAccountMetas[1]; + smartWallet: TAccountMetas[2]; + payer: TAccountMetas[3]; + systemProgram: TAccountMetas[4]; + }; + data: CreateGovernorInstructionData; +} + +export function parseCreateGovernorInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCreateGovernorInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + base: getNextAccount(), + governor: getNextAccount(), + smartWallet: getNextAccount(), + payer: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getCreateGovernorInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/createProposal.ts b/clients/tribeca/src/generated/instructions/createProposal.ts new file mode 100644 index 00000000..8e1a91a7 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/createProposal.ts @@ -0,0 +1,269 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import type { + ProposalInstruction, + ProposalInstructionArgs, +} from "../types/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { GOVERN_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import { + getProposalInstructionDecoder, + getProposalInstructionEncoder, +} from "../types/index.js"; + +export const CREATE_PROPOSAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array( + [132, 116, 68, 174, 216, 160, 198, 22], +); + +export function getCreateProposalDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CREATE_PROPOSAL_DISCRIMINATOR, + ); +} + +export type CreateProposalInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountGovernor extends string | AccountMeta = string, + TAccountProposal extends string | AccountMeta = string, + TAccountProposer extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountGovernor extends string + ? WritableAccount + : TAccountGovernor, + TAccountProposal extends string + ? WritableAccount + : TAccountProposal, + TAccountProposer extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountProposer, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface CreateProposalInstructionData { + discriminator: ReadonlyUint8Array; + bump: number; + instructions: ProposalInstruction[]; +} + +export interface CreateProposalInstructionDataArgs { + bump: number; + instructions: ProposalInstructionArgs[]; +} + +export function getCreateProposalInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bump", getU8Encoder()], + ["instructions", getArrayEncoder(getProposalInstructionEncoder())], + ]), + (value) => ({ ...value, discriminator: CREATE_PROPOSAL_DISCRIMINATOR }), + ); +} + +export function getCreateProposalInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bump", getU8Decoder()], + ["instructions", getArrayDecoder(getProposalInstructionDecoder())], + ]); +} + +export function getCreateProposalInstructionDataCodec(): Codec< + CreateProposalInstructionDataArgs, + CreateProposalInstructionData +> { + return combineCodec( + getCreateProposalInstructionDataEncoder(), + getCreateProposalInstructionDataDecoder(), + ); +} + +export interface CreateProposalInput< + TAccountGovernor extends string = string, + TAccountProposal extends string = string, + TAccountProposer extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, +> { + governor: Address; + proposal: Address; + proposer: TransactionSigner; + payer: TransactionSigner; + systemProgram?: Address; + bump: CreateProposalInstructionDataArgs["bump"]; + instructions: CreateProposalInstructionDataArgs["instructions"]; +} + +export function getCreateProposalInstruction< + TAccountGovernor extends string, + TAccountProposal extends string, + TAccountProposer extends string, + TAccountPayer extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof GOVERN_PROGRAM_ADDRESS, +>( + input: CreateProposalInput< + TAccountGovernor, + TAccountProposal, + TAccountProposer, + TAccountPayer, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): CreateProposalInstruction< + TProgramAddress, + TAccountGovernor, + TAccountProposal, + TAccountProposer, + TAccountPayer, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? GOVERN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + governor: { value: input.governor ?? null, isWritable: true }, + proposal: { value: input.proposal ?? null, isWritable: true }, + proposer: { value: input.proposer ?? null, isWritable: false }, + payer: { value: input.payer ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.governor), + getAccountMeta(accounts.proposal), + getAccountMeta(accounts.proposer), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + ], + data: getCreateProposalInstructionDataEncoder().encode( + args as CreateProposalInstructionDataArgs, + ), + programAddress, + } as CreateProposalInstruction< + TProgramAddress, + TAccountGovernor, + TAccountProposal, + TAccountProposer, + TAccountPayer, + TAccountSystemProgram + >); +} + +export interface ParsedCreateProposalInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + governor: TAccountMetas[0]; + proposal: TAccountMetas[1]; + proposer: TAccountMetas[2]; + payer: TAccountMetas[3]; + systemProgram: TAccountMetas[4]; + }; + data: CreateProposalInstructionData; +} + +export function parseCreateProposalInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCreateProposalInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + governor: getNextAccount(), + proposal: getNextAccount(), + proposer: getNextAccount(), + payer: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getCreateProposalInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/createProposalMeta.ts b/clients/tribeca/src/generated/instructions/createProposalMeta.ts new file mode 100644 index 00000000..11dc99bf --- /dev/null +++ b/clients/tribeca/src/generated/instructions/createProposalMeta.ts @@ -0,0 +1,280 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + Codec, + Decoder, + Encoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + addDecoderSizePrefix, + addEncoderSizePrefix, + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU32Decoder, + getU32Encoder, + getUtf8Decoder, + getUtf8Encoder, + transformEncoder, +} from "@solana/kit"; +import { GOVERN_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const CREATE_PROPOSAL_META_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([238, 138, 212, 160, 46, 53, 51, 88]); + +export function getCreateProposalMetaDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + CREATE_PROPOSAL_META_DISCRIMINATOR, + ); +} + +export type CreateProposalMetaInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountProposal extends string | AccountMeta = string, + TAccountProposer extends string | AccountMeta = string, + TAccountProposalMeta extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountProposal extends string + ? ReadonlyAccount + : TAccountProposal, + TAccountProposer extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountProposer, + TAccountProposalMeta extends string + ? WritableAccount + : TAccountProposalMeta, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface CreateProposalMetaInstructionData { + discriminator: ReadonlyUint8Array; + bump: number; + title: string; + descriptionLink: string; +} + +export interface CreateProposalMetaInstructionDataArgs { + bump: number; + title: string; + descriptionLink: string; +} + +export function getCreateProposalMetaInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bump", getU8Encoder()], + ["title", addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())], + [ + "descriptionLink", + addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder()), + ], + ]), + (value) => ({ + ...value, + discriminator: CREATE_PROPOSAL_META_DISCRIMINATOR, + }), + ); +} + +export function getCreateProposalMetaInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bump", getU8Decoder()], + ["title", addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())], + [ + "descriptionLink", + addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder()), + ], + ]); +} + +export function getCreateProposalMetaInstructionDataCodec(): Codec< + CreateProposalMetaInstructionDataArgs, + CreateProposalMetaInstructionData +> { + return combineCodec( + getCreateProposalMetaInstructionDataEncoder(), + getCreateProposalMetaInstructionDataDecoder(), + ); +} + +export interface CreateProposalMetaInput< + TAccountProposal extends string = string, + TAccountProposer extends string = string, + TAccountProposalMeta extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, +> { + proposal: Address; + proposer: TransactionSigner; + proposalMeta: Address; + payer: TransactionSigner; + systemProgram?: Address; + bump: CreateProposalMetaInstructionDataArgs["bump"]; + title: CreateProposalMetaInstructionDataArgs["title"]; + descriptionLink: CreateProposalMetaInstructionDataArgs["descriptionLink"]; +} + +export function getCreateProposalMetaInstruction< + TAccountProposal extends string, + TAccountProposer extends string, + TAccountProposalMeta extends string, + TAccountPayer extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof GOVERN_PROGRAM_ADDRESS, +>( + input: CreateProposalMetaInput< + TAccountProposal, + TAccountProposer, + TAccountProposalMeta, + TAccountPayer, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): CreateProposalMetaInstruction< + TProgramAddress, + TAccountProposal, + TAccountProposer, + TAccountProposalMeta, + TAccountPayer, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? GOVERN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + proposal: { value: input.proposal ?? null, isWritable: false }, + proposer: { value: input.proposer ?? null, isWritable: false }, + proposalMeta: { value: input.proposalMeta ?? null, isWritable: true }, + payer: { value: input.payer ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.proposal), + getAccountMeta(accounts.proposer), + getAccountMeta(accounts.proposalMeta), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + ], + data: getCreateProposalMetaInstructionDataEncoder().encode( + args as CreateProposalMetaInstructionDataArgs, + ), + programAddress, + } as CreateProposalMetaInstruction< + TProgramAddress, + TAccountProposal, + TAccountProposer, + TAccountProposalMeta, + TAccountPayer, + TAccountSystemProgram + >); +} + +export interface ParsedCreateProposalMetaInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + proposal: TAccountMetas[0]; + proposer: TAccountMetas[1]; + proposalMeta: TAccountMetas[2]; + payer: TAccountMetas[3]; + systemProgram: TAccountMetas[4]; + }; + data: CreateProposalMetaInstructionData; +} + +export function parseCreateProposalMetaInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedCreateProposalMetaInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + proposal: getNextAccount(), + proposer: getNextAccount(), + proposalMeta: getNextAccount(), + payer: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getCreateProposalMetaInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/tribeca/src/generated/instructions/exit.ts b/clients/tribeca/src/generated/instructions/exit.ts new file mode 100644 index 00000000..0fd2114b --- /dev/null +++ b/clients/tribeca/src/generated/instructions/exit.ts @@ -0,0 +1,268 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const EXIT_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 234, 32, 12, 71, 126, 5, 219, 160, +]); + +export function getExitDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(EXIT_DISCRIMINATOR); +} + +export type ExitInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountEscrow extends string | AccountMeta = string, + TAccountEscrowOwner extends string | AccountMeta = string, + TAccountEscrowTokens extends string | AccountMeta = string, + TAccountDestinationTokens extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? WritableAccount + : TAccountLocker, + TAccountEscrow extends string + ? WritableAccount + : TAccountEscrow, + TAccountEscrowOwner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountEscrowOwner, + TAccountEscrowTokens extends string + ? WritableAccount + : TAccountEscrowTokens, + TAccountDestinationTokens extends string + ? WritableAccount + : TAccountDestinationTokens, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface ExitInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface ExitInstructionDataArgs {} + +export function getExitInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ ...value, discriminator: EXIT_DISCRIMINATOR }), + ); +} + +export function getExitInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getExitInstructionDataCodec(): FixedSizeCodec< + ExitInstructionDataArgs, + ExitInstructionData +> { + return combineCodec( + getExitInstructionDataEncoder(), + getExitInstructionDataDecoder(), + ); +} + +export interface ExitInput< + TAccountLocker extends string = string, + TAccountEscrow extends string = string, + TAccountEscrowOwner extends string = string, + TAccountEscrowTokens extends string = string, + TAccountDestinationTokens extends string = string, + TAccountPayer extends string = string, + TAccountTokenProgram extends string = string, +> { + locker: Address; + escrow: Address; + escrowOwner: TransactionSigner; + escrowTokens: Address; + destinationTokens: Address; + payer: TransactionSigner; + tokenProgram?: Address; +} + +export function getExitInstruction< + TAccountLocker extends string, + TAccountEscrow extends string, + TAccountEscrowOwner extends string, + TAccountEscrowTokens extends string, + TAccountDestinationTokens extends string, + TAccountPayer extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: ExitInput< + TAccountLocker, + TAccountEscrow, + TAccountEscrowOwner, + TAccountEscrowTokens, + TAccountDestinationTokens, + TAccountPayer, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): ExitInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowOwner, + TAccountEscrowTokens, + TAccountDestinationTokens, + TAccountPayer, + TAccountTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: true }, + escrow: { value: input.escrow ?? null, isWritable: true }, + escrowOwner: { value: input.escrowOwner ?? null, isWritable: false }, + escrowTokens: { value: input.escrowTokens ?? null, isWritable: true }, + destinationTokens: { + value: input.destinationTokens ?? null, + isWritable: true, + }, + payer: { value: input.payer ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.escrowOwner), + getAccountMeta(accounts.escrowTokens), + getAccountMeta(accounts.destinationTokens), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.tokenProgram), + ], + data: getExitInstructionDataEncoder().encode({}), + programAddress, + } as ExitInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowOwner, + TAccountEscrowTokens, + TAccountDestinationTokens, + TAccountPayer, + TAccountTokenProgram + >); +} + +export interface ParsedExitInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + escrow: TAccountMetas[1]; + escrowOwner: TAccountMetas[2]; + escrowTokens: TAccountMetas[3]; + destinationTokens: TAccountMetas[4]; + payer: TAccountMetas[5]; + tokenProgram: TAccountMetas[6]; + }; + data: ExitInstructionData; +} + +export function parseExitInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedExitInstruction { + if (instruction.accounts.length < 7) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + escrow: getNextAccount(), + escrowOwner: getNextAccount(), + escrowTokens: getNextAccount(), + destinationTokens: getNextAccount(), + payer: getNextAccount(), + tokenProgram: getNextAccount(), + }, + data: getExitInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/index.ts b/clients/tribeca/src/generated/instructions/index.ts new file mode 100644 index 00000000..37efead2 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/index.ts @@ -0,0 +1,31 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./activateProposal.js"; +export * from "./activateProposal.js"; +export * from "./approveProgramLockPrivilege.js"; +export * from "./cancelProposal.js"; +export * from "./castVote.js"; +export * from "./createGovernor.js"; +export * from "./createProposal.js"; +export * from "./createProposalMeta.js"; +export * from "./exit.js"; +export * from "./lock.js"; +export * from "./lockPermissionless.js"; +export * from "./lockWithWhitelist.js"; +export * from "./lockWithWhitelistEntry.js"; +export * from "./newEscrow.js"; +export * from "./newLocker.js"; +export * from "./newVote.js"; +export * from "./queueProposal.js"; +export * from "./revokeProgramLockPrivilege.js"; +export * from "./setElectorate.js"; +export * from "./setGovernanceParams.js"; +export * from "./setLockerParams.js"; +export * from "./setVote.js"; +export * from "./setVoteDelegate.js"; diff --git a/clients/tribeca/src/generated/instructions/lock.ts b/clients/tribeca/src/generated/instructions/lock.ts new file mode 100644 index 00000000..b08546cb --- /dev/null +++ b/clients/tribeca/src/generated/instructions/lock.ts @@ -0,0 +1,271 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const LOCK_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 21, 19, 208, 43, 237, 62, 255, 87, +]); + +export function getLockDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(LOCK_DISCRIMINATOR); +} + +export type LockInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountEscrow extends string | AccountMeta = string, + TAccountEscrowTokens extends string | AccountMeta = string, + TAccountEscrowOwner extends string | AccountMeta = string, + TAccountSourceTokens extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? WritableAccount + : TAccountLocker, + TAccountEscrow extends string + ? WritableAccount + : TAccountEscrow, + TAccountEscrowTokens extends string + ? WritableAccount + : TAccountEscrowTokens, + TAccountEscrowOwner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountEscrowOwner, + TAccountSourceTokens extends string + ? WritableAccount + : TAccountSourceTokens, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface LockInstructionData { + discriminator: ReadonlyUint8Array; + amount: bigint; + duration: bigint; +} + +export interface LockInstructionDataArgs { + amount: number | bigint; + duration: number | bigint; +} + +export function getLockInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["amount", getU64Encoder()], + ["duration", getI64Encoder()], + ]), + (value) => ({ ...value, discriminator: LOCK_DISCRIMINATOR }), + ); +} + +export function getLockInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["amount", getU64Decoder()], + ["duration", getI64Decoder()], + ]); +} + +export function getLockInstructionDataCodec(): FixedSizeCodec< + LockInstructionDataArgs, + LockInstructionData +> { + return combineCodec( + getLockInstructionDataEncoder(), + getLockInstructionDataDecoder(), + ); +} + +export interface LockInput< + TAccountLocker extends string = string, + TAccountEscrow extends string = string, + TAccountEscrowTokens extends string = string, + TAccountEscrowOwner extends string = string, + TAccountSourceTokens extends string = string, + TAccountTokenProgram extends string = string, +> { + locker: Address; + escrow: Address; + escrowTokens: Address; + escrowOwner: TransactionSigner; + sourceTokens: Address; + tokenProgram?: Address; + amount: LockInstructionDataArgs["amount"]; + duration: LockInstructionDataArgs["duration"]; +} + +export function getLockInstruction< + TAccountLocker extends string, + TAccountEscrow extends string, + TAccountEscrowTokens extends string, + TAccountEscrowOwner extends string, + TAccountSourceTokens extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: LockInput< + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): LockInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: true }, + escrow: { value: input.escrow ?? null, isWritable: true }, + escrowTokens: { value: input.escrowTokens ?? null, isWritable: true }, + escrowOwner: { value: input.escrowOwner ?? null, isWritable: false }, + sourceTokens: { value: input.sourceTokens ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.escrowTokens), + getAccountMeta(accounts.escrowOwner), + getAccountMeta(accounts.sourceTokens), + getAccountMeta(accounts.tokenProgram), + ], + data: getLockInstructionDataEncoder().encode( + args as LockInstructionDataArgs, + ), + programAddress, + } as LockInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram + >); +} + +export interface ParsedLockInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + escrow: TAccountMetas[1]; + escrowTokens: TAccountMetas[2]; + escrowOwner: TAccountMetas[3]; + sourceTokens: TAccountMetas[4]; + tokenProgram: TAccountMetas[5]; + }; + data: LockInstructionData; +} + +export function parseLockInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedLockInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + escrow: getNextAccount(), + escrowTokens: getNextAccount(), + escrowOwner: getNextAccount(), + sourceTokens: getNextAccount(), + tokenProgram: getNextAccount(), + }, + data: getLockInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/lockPermissionless.ts b/clients/tribeca/src/generated/instructions/lockPermissionless.ts new file mode 100644 index 00000000..2d0d3ee3 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/lockPermissionless.ts @@ -0,0 +1,274 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const LOCK_PERMISSIONLESS_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([146, 106, 208, 36, 187, 241, 122, 2]); + +export function getLockPermissionlessDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + LOCK_PERMISSIONLESS_DISCRIMINATOR, + ); +} + +export type LockPermissionlessInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountEscrow extends string | AccountMeta = string, + TAccountEscrowTokens extends string | AccountMeta = string, + TAccountEscrowOwner extends string | AccountMeta = string, + TAccountSourceTokens extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? WritableAccount + : TAccountLocker, + TAccountEscrow extends string + ? WritableAccount + : TAccountEscrow, + TAccountEscrowTokens extends string + ? WritableAccount + : TAccountEscrowTokens, + TAccountEscrowOwner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountEscrowOwner, + TAccountSourceTokens extends string + ? WritableAccount + : TAccountSourceTokens, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + ...TRemainingAccounts, + ] + >; + +export interface LockPermissionlessInstructionData { + discriminator: ReadonlyUint8Array; + amount: bigint; + duration: bigint; +} + +export interface LockPermissionlessInstructionDataArgs { + amount: number | bigint; + duration: number | bigint; +} + +export function getLockPermissionlessInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["amount", getU64Encoder()], + ["duration", getI64Encoder()], + ]), + (value) => ({ ...value, discriminator: LOCK_PERMISSIONLESS_DISCRIMINATOR }), + ); +} + +export function getLockPermissionlessInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["amount", getU64Decoder()], + ["duration", getI64Decoder()], + ]); +} + +export function getLockPermissionlessInstructionDataCodec(): FixedSizeCodec< + LockPermissionlessInstructionDataArgs, + LockPermissionlessInstructionData +> { + return combineCodec( + getLockPermissionlessInstructionDataEncoder(), + getLockPermissionlessInstructionDataDecoder(), + ); +} + +export interface LockPermissionlessInput< + TAccountLocker extends string = string, + TAccountEscrow extends string = string, + TAccountEscrowTokens extends string = string, + TAccountEscrowOwner extends string = string, + TAccountSourceTokens extends string = string, + TAccountTokenProgram extends string = string, +> { + locker: Address; + escrow: Address; + escrowTokens: Address; + escrowOwner: TransactionSigner; + sourceTokens: Address; + tokenProgram?: Address; + amount: LockPermissionlessInstructionDataArgs["amount"]; + duration: LockPermissionlessInstructionDataArgs["duration"]; +} + +export function getLockPermissionlessInstruction< + TAccountLocker extends string, + TAccountEscrow extends string, + TAccountEscrowTokens extends string, + TAccountEscrowOwner extends string, + TAccountSourceTokens extends string, + TAccountTokenProgram extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: LockPermissionlessInput< + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram + >, + config?: { programAddress?: TProgramAddress }, +): LockPermissionlessInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: true }, + escrow: { value: input.escrow ?? null, isWritable: true }, + escrowTokens: { value: input.escrowTokens ?? null, isWritable: true }, + escrowOwner: { value: input.escrowOwner ?? null, isWritable: false }, + sourceTokens: { value: input.sourceTokens ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.escrowTokens), + getAccountMeta(accounts.escrowOwner), + getAccountMeta(accounts.sourceTokens), + getAccountMeta(accounts.tokenProgram), + ], + data: getLockPermissionlessInstructionDataEncoder().encode( + args as LockPermissionlessInstructionDataArgs, + ), + programAddress, + } as LockPermissionlessInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram + >); +} + +export interface ParsedLockPermissionlessInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + escrow: TAccountMetas[1]; + escrowTokens: TAccountMetas[2]; + escrowOwner: TAccountMetas[3]; + sourceTokens: TAccountMetas[4]; + tokenProgram: TAccountMetas[5]; + }; + data: LockPermissionlessInstructionData; +} + +export function parseLockPermissionlessInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedLockPermissionlessInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + escrow: getNextAccount(), + escrowTokens: getNextAccount(), + escrowOwner: getNextAccount(), + sourceTokens: getNextAccount(), + tokenProgram: getNextAccount(), + }, + data: getLockPermissionlessInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/tribeca/src/generated/instructions/lockWithWhitelist.ts b/clients/tribeca/src/generated/instructions/lockWithWhitelist.ts new file mode 100644 index 00000000..28941ed8 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/lockWithWhitelist.ts @@ -0,0 +1,295 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const LOCK_WITH_WHITELIST_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([138, 141, 28, 193, 7, 211, 181, 69]); + +export function getLockWithWhitelistDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + LOCK_WITH_WHITELIST_DISCRIMINATOR, + ); +} + +export type LockWithWhitelistInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountEscrow extends string | AccountMeta = string, + TAccountEscrowTokens extends string | AccountMeta = string, + TAccountEscrowOwner extends string | AccountMeta = string, + TAccountSourceTokens extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountInstructionsSysvar extends + | string + | AccountMeta = "Sysvar1nstructions1111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? WritableAccount + : TAccountLocker, + TAccountEscrow extends string + ? WritableAccount + : TAccountEscrow, + TAccountEscrowTokens extends string + ? WritableAccount + : TAccountEscrowTokens, + TAccountEscrowOwner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountEscrowOwner, + TAccountSourceTokens extends string + ? WritableAccount + : TAccountSourceTokens, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountInstructionsSysvar extends string + ? ReadonlyAccount + : TAccountInstructionsSysvar, + ...TRemainingAccounts, + ] + >; + +export interface LockWithWhitelistInstructionData { + discriminator: ReadonlyUint8Array; + amount: bigint; + duration: bigint; +} + +export interface LockWithWhitelistInstructionDataArgs { + amount: number | bigint; + duration: number | bigint; +} + +export function getLockWithWhitelistInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["amount", getU64Encoder()], + ["duration", getI64Encoder()], + ]), + (value) => ({ ...value, discriminator: LOCK_WITH_WHITELIST_DISCRIMINATOR }), + ); +} + +export function getLockWithWhitelistInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["amount", getU64Decoder()], + ["duration", getI64Decoder()], + ]); +} + +export function getLockWithWhitelistInstructionDataCodec(): FixedSizeCodec< + LockWithWhitelistInstructionDataArgs, + LockWithWhitelistInstructionData +> { + return combineCodec( + getLockWithWhitelistInstructionDataEncoder(), + getLockWithWhitelistInstructionDataDecoder(), + ); +} + +export interface LockWithWhitelistInput< + TAccountLocker extends string = string, + TAccountEscrow extends string = string, + TAccountEscrowTokens extends string = string, + TAccountEscrowOwner extends string = string, + TAccountSourceTokens extends string = string, + TAccountTokenProgram extends string = string, + TAccountInstructionsSysvar extends string = string, +> { + locker: Address; + escrow: Address; + escrowTokens: Address; + escrowOwner: TransactionSigner; + sourceTokens: Address; + tokenProgram?: Address; + instructionsSysvar?: Address; + amount: LockWithWhitelistInstructionDataArgs["amount"]; + duration: LockWithWhitelistInstructionDataArgs["duration"]; +} + +export function getLockWithWhitelistInstruction< + TAccountLocker extends string, + TAccountEscrow extends string, + TAccountEscrowTokens extends string, + TAccountEscrowOwner extends string, + TAccountSourceTokens extends string, + TAccountTokenProgram extends string, + TAccountInstructionsSysvar extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: LockWithWhitelistInput< + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram, + TAccountInstructionsSysvar + >, + config?: { programAddress?: TProgramAddress }, +): LockWithWhitelistInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram, + TAccountInstructionsSysvar +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: true }, + escrow: { value: input.escrow ?? null, isWritable: true }, + escrowTokens: { value: input.escrowTokens ?? null, isWritable: true }, + escrowOwner: { value: input.escrowOwner ?? null, isWritable: false }, + sourceTokens: { value: input.sourceTokens ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + instructionsSysvar: { + value: input.instructionsSysvar ?? null, + isWritable: false, + }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionsSysvar.value) { + accounts.instructionsSysvar.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.escrowTokens), + getAccountMeta(accounts.escrowOwner), + getAccountMeta(accounts.sourceTokens), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.instructionsSysvar), + ], + data: getLockWithWhitelistInstructionDataEncoder().encode( + args as LockWithWhitelistInstructionDataArgs, + ), + programAddress, + } as LockWithWhitelistInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram, + TAccountInstructionsSysvar + >); +} + +export interface ParsedLockWithWhitelistInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + escrow: TAccountMetas[1]; + escrowTokens: TAccountMetas[2]; + escrowOwner: TAccountMetas[3]; + sourceTokens: TAccountMetas[4]; + tokenProgram: TAccountMetas[5]; + instructionsSysvar: TAccountMetas[6]; + }; + data: LockWithWhitelistInstructionData; +} + +export function parseLockWithWhitelistInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedLockWithWhitelistInstruction { + if (instruction.accounts.length < 7) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + escrow: getNextAccount(), + escrowTokens: getNextAccount(), + escrowOwner: getNextAccount(), + sourceTokens: getNextAccount(), + tokenProgram: getNextAccount(), + instructionsSysvar: getNextAccount(), + }, + data: getLockWithWhitelistInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/lockWithWhitelistEntry.ts b/clients/tribeca/src/generated/instructions/lockWithWhitelistEntry.ts new file mode 100644 index 00000000..d93c7997 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/lockWithWhitelistEntry.ts @@ -0,0 +1,314 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const LOCK_WITH_WHITELIST_ENTRY_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([138, 248, 185, 79, 3, 115, 115, 57]); + +export function getLockWithWhitelistEntryDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + LOCK_WITH_WHITELIST_ENTRY_DISCRIMINATOR, + ); +} + +export type LockWithWhitelistEntryInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountEscrow extends string | AccountMeta = string, + TAccountEscrowTokens extends string | AccountMeta = string, + TAccountEscrowOwner extends string | AccountMeta = string, + TAccountSourceTokens extends string | AccountMeta = string, + TAccountTokenProgram extends + | string + | AccountMeta = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA", + TAccountInstructionsSysvar extends + | string + | AccountMeta = "Sysvar1nstructions1111111111111111111111111", + TAccountWhitelistEntry extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? WritableAccount + : TAccountLocker, + TAccountEscrow extends string + ? WritableAccount + : TAccountEscrow, + TAccountEscrowTokens extends string + ? WritableAccount + : TAccountEscrowTokens, + TAccountEscrowOwner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountEscrowOwner, + TAccountSourceTokens extends string + ? WritableAccount + : TAccountSourceTokens, + TAccountTokenProgram extends string + ? ReadonlyAccount + : TAccountTokenProgram, + TAccountInstructionsSysvar extends string + ? ReadonlyAccount + : TAccountInstructionsSysvar, + TAccountWhitelistEntry extends string + ? ReadonlyAccount + : TAccountWhitelistEntry, + ...TRemainingAccounts, + ] + >; + +export interface LockWithWhitelistEntryInstructionData { + discriminator: ReadonlyUint8Array; + amount: bigint; + duration: bigint; +} + +export interface LockWithWhitelistEntryInstructionDataArgs { + amount: number | bigint; + duration: number | bigint; +} + +export function getLockWithWhitelistEntryInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["amount", getU64Encoder()], + ["duration", getI64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: LOCK_WITH_WHITELIST_ENTRY_DISCRIMINATOR, + }), + ); +} + +export function getLockWithWhitelistEntryInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["amount", getU64Decoder()], + ["duration", getI64Decoder()], + ]); +} + +export function getLockWithWhitelistEntryInstructionDataCodec(): FixedSizeCodec< + LockWithWhitelistEntryInstructionDataArgs, + LockWithWhitelistEntryInstructionData +> { + return combineCodec( + getLockWithWhitelistEntryInstructionDataEncoder(), + getLockWithWhitelistEntryInstructionDataDecoder(), + ); +} + +export interface LockWithWhitelistEntryInput< + TAccountLocker extends string = string, + TAccountEscrow extends string = string, + TAccountEscrowTokens extends string = string, + TAccountEscrowOwner extends string = string, + TAccountSourceTokens extends string = string, + TAccountTokenProgram extends string = string, + TAccountInstructionsSysvar extends string = string, + TAccountWhitelistEntry extends string = string, +> { + locker: Address; + escrow: Address; + escrowTokens: Address; + escrowOwner: TransactionSigner; + sourceTokens: Address; + tokenProgram?: Address; + instructionsSysvar?: Address; + whitelistEntry: Address; + amount: LockWithWhitelistEntryInstructionDataArgs["amount"]; + duration: LockWithWhitelistEntryInstructionDataArgs["duration"]; +} + +export function getLockWithWhitelistEntryInstruction< + TAccountLocker extends string, + TAccountEscrow extends string, + TAccountEscrowTokens extends string, + TAccountEscrowOwner extends string, + TAccountSourceTokens extends string, + TAccountTokenProgram extends string, + TAccountInstructionsSysvar extends string, + TAccountWhitelistEntry extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: LockWithWhitelistEntryInput< + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram, + TAccountInstructionsSysvar, + TAccountWhitelistEntry + >, + config?: { programAddress?: TProgramAddress }, +): LockWithWhitelistEntryInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram, + TAccountInstructionsSysvar, + TAccountWhitelistEntry +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: true }, + escrow: { value: input.escrow ?? null, isWritable: true }, + escrowTokens: { value: input.escrowTokens ?? null, isWritable: true }, + escrowOwner: { value: input.escrowOwner ?? null, isWritable: false }, + sourceTokens: { value: input.sourceTokens ?? null, isWritable: true }, + tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, + instructionsSysvar: { + value: input.instructionsSysvar ?? null, + isWritable: false, + }, + whitelistEntry: { value: input.whitelistEntry ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.tokenProgram.value) { + accounts.tokenProgram.value = + "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" as Address<"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA">; + } + if (!accounts.instructionsSysvar.value) { + accounts.instructionsSysvar.value = + "Sysvar1nstructions1111111111111111111111111" as Address<"Sysvar1nstructions1111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.escrowTokens), + getAccountMeta(accounts.escrowOwner), + getAccountMeta(accounts.sourceTokens), + getAccountMeta(accounts.tokenProgram), + getAccountMeta(accounts.instructionsSysvar), + getAccountMeta(accounts.whitelistEntry), + ], + data: getLockWithWhitelistEntryInstructionDataEncoder().encode( + args as LockWithWhitelistEntryInstructionDataArgs, + ), + programAddress, + } as LockWithWhitelistEntryInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowTokens, + TAccountEscrowOwner, + TAccountSourceTokens, + TAccountTokenProgram, + TAccountInstructionsSysvar, + TAccountWhitelistEntry + >); +} + +export interface ParsedLockWithWhitelistEntryInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + escrow: TAccountMetas[1]; + escrowTokens: TAccountMetas[2]; + escrowOwner: TAccountMetas[3]; + sourceTokens: TAccountMetas[4]; + tokenProgram: TAccountMetas[5]; + instructionsSysvar: TAccountMetas[6]; + whitelistEntry: TAccountMetas[7]; + }; + data: LockWithWhitelistEntryInstructionData; +} + +export function parseLockWithWhitelistEntryInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedLockWithWhitelistEntryInstruction { + if (instruction.accounts.length < 8) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + escrow: getNextAccount(), + escrowTokens: getNextAccount(), + escrowOwner: getNextAccount(), + sourceTokens: getNextAccount(), + tokenProgram: getNextAccount(), + instructionsSysvar: getNextAccount(), + whitelistEntry: getNextAccount(), + }, + data: getLockWithWhitelistEntryInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/tribeca/src/generated/instructions/newEscrow.ts b/clients/tribeca/src/generated/instructions/newEscrow.ts new file mode 100644 index 00000000..597550d6 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/newEscrow.ts @@ -0,0 +1,250 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const NEW_ESCROW_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 216, 182, 143, 11, 220, 38, 86, 185, +]); + +export function getNewEscrowDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(NEW_ESCROW_DISCRIMINATOR); +} + +export type NewEscrowInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountEscrow extends string | AccountMeta = string, + TAccountEscrowOwner extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? ReadonlyAccount + : TAccountLocker, + TAccountEscrow extends string + ? WritableAccount + : TAccountEscrow, + TAccountEscrowOwner extends string + ? ReadonlyAccount + : TAccountEscrowOwner, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface NewEscrowInstructionData { + discriminator: ReadonlyUint8Array; + bump: number; +} + +export interface NewEscrowInstructionDataArgs { + bump: number; +} + +export function getNewEscrowInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bump", getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: NEW_ESCROW_DISCRIMINATOR }), + ); +} + +export function getNewEscrowInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bump", getU8Decoder()], + ]); +} + +export function getNewEscrowInstructionDataCodec(): FixedSizeCodec< + NewEscrowInstructionDataArgs, + NewEscrowInstructionData +> { + return combineCodec( + getNewEscrowInstructionDataEncoder(), + getNewEscrowInstructionDataDecoder(), + ); +} + +export interface NewEscrowInput< + TAccountLocker extends string = string, + TAccountEscrow extends string = string, + TAccountEscrowOwner extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, +> { + locker: Address; + escrow: Address; + escrowOwner: Address; + payer: TransactionSigner; + systemProgram?: Address; + bump: NewEscrowInstructionDataArgs["bump"]; +} + +export function getNewEscrowInstruction< + TAccountLocker extends string, + TAccountEscrow extends string, + TAccountEscrowOwner extends string, + TAccountPayer extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: NewEscrowInput< + TAccountLocker, + TAccountEscrow, + TAccountEscrowOwner, + TAccountPayer, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): NewEscrowInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowOwner, + TAccountPayer, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: false }, + escrow: { value: input.escrow ?? null, isWritable: true }, + escrowOwner: { value: input.escrowOwner ?? null, isWritable: false }, + payer: { value: input.payer ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.escrowOwner), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + ], + data: getNewEscrowInstructionDataEncoder().encode( + args as NewEscrowInstructionDataArgs, + ), + programAddress, + } as NewEscrowInstruction< + TProgramAddress, + TAccountLocker, + TAccountEscrow, + TAccountEscrowOwner, + TAccountPayer, + TAccountSystemProgram + >); +} + +export interface ParsedNewEscrowInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + escrow: TAccountMetas[1]; + escrowOwner: TAccountMetas[2]; + payer: TAccountMetas[3]; + systemProgram: TAccountMetas[4]; + }; + data: NewEscrowInstructionData; +} + +export function parseNewEscrowInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedNewEscrowInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + escrow: getNextAccount(), + escrowOwner: getNextAccount(), + payer: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getNewEscrowInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/newLocker.ts b/clients/tribeca/src/generated/instructions/newLocker.ts new file mode 100644 index 00000000..0a6ac6dd --- /dev/null +++ b/clients/tribeca/src/generated/instructions/newLocker.ts @@ -0,0 +1,275 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import type { LockerParams, LockerParamsArgs } from "../types/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import { + getLockerParamsDecoder, + getLockerParamsEncoder, +} from "../types/index.js"; + +export const NEW_LOCKER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 177, 133, 32, 90, 229, 216, 131, 47, +]); + +export function getNewLockerDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(NEW_LOCKER_DISCRIMINATOR); +} + +export type NewLockerInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountBase extends string | AccountMeta = string, + TAccountLocker extends string | AccountMeta = string, + TAccountTokenMint extends string | AccountMeta = string, + TAccountGovernor extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountBase extends string + ? ReadonlySignerAccount & AccountSignerMeta + : TAccountBase, + TAccountLocker extends string + ? WritableAccount + : TAccountLocker, + TAccountTokenMint extends string + ? ReadonlyAccount + : TAccountTokenMint, + TAccountGovernor extends string + ? ReadonlyAccount + : TAccountGovernor, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface NewLockerInstructionData { + discriminator: ReadonlyUint8Array; + bump: number; + params: LockerParams; +} + +export interface NewLockerInstructionDataArgs { + bump: number; + params: LockerParamsArgs; +} + +export function getNewLockerInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bump", getU8Encoder()], + ["params", getLockerParamsEncoder()], + ]), + (value) => ({ ...value, discriminator: NEW_LOCKER_DISCRIMINATOR }), + ); +} + +export function getNewLockerInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bump", getU8Decoder()], + ["params", getLockerParamsDecoder()], + ]); +} + +export function getNewLockerInstructionDataCodec(): FixedSizeCodec< + NewLockerInstructionDataArgs, + NewLockerInstructionData +> { + return combineCodec( + getNewLockerInstructionDataEncoder(), + getNewLockerInstructionDataDecoder(), + ); +} + +export interface NewLockerInput< + TAccountBase extends string = string, + TAccountLocker extends string = string, + TAccountTokenMint extends string = string, + TAccountGovernor extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, +> { + base: TransactionSigner; + locker: Address; + tokenMint: Address; + governor: Address; + payer: TransactionSigner; + systemProgram?: Address; + bump: NewLockerInstructionDataArgs["bump"]; + params: NewLockerInstructionDataArgs["params"]; +} + +export function getNewLockerInstruction< + TAccountBase extends string, + TAccountLocker extends string, + TAccountTokenMint extends string, + TAccountGovernor extends string, + TAccountPayer extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: NewLockerInput< + TAccountBase, + TAccountLocker, + TAccountTokenMint, + TAccountGovernor, + TAccountPayer, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): NewLockerInstruction< + TProgramAddress, + TAccountBase, + TAccountLocker, + TAccountTokenMint, + TAccountGovernor, + TAccountPayer, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + base: { value: input.base ?? null, isWritable: false }, + locker: { value: input.locker ?? null, isWritable: true }, + tokenMint: { value: input.tokenMint ?? null, isWritable: false }, + governor: { value: input.governor ?? null, isWritable: false }, + payer: { value: input.payer ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.base), + getAccountMeta(accounts.locker), + getAccountMeta(accounts.tokenMint), + getAccountMeta(accounts.governor), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + ], + data: getNewLockerInstructionDataEncoder().encode( + args as NewLockerInstructionDataArgs, + ), + programAddress, + } as NewLockerInstruction< + TProgramAddress, + TAccountBase, + TAccountLocker, + TAccountTokenMint, + TAccountGovernor, + TAccountPayer, + TAccountSystemProgram + >); +} + +export interface ParsedNewLockerInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + base: TAccountMetas[0]; + locker: TAccountMetas[1]; + tokenMint: TAccountMetas[2]; + governor: TAccountMetas[3]; + payer: TAccountMetas[4]; + systemProgram: TAccountMetas[5]; + }; + data: NewLockerInstructionData; +} + +export function parseNewLockerInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedNewLockerInstruction { + if (instruction.accounts.length < 6) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + base: getNextAccount(), + locker: getNextAccount(), + tokenMint: getNextAccount(), + governor: getNextAccount(), + payer: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getNewLockerInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/newVote.ts b/clients/tribeca/src/generated/instructions/newVote.ts new file mode 100644 index 00000000..c23d70cc --- /dev/null +++ b/clients/tribeca/src/generated/instructions/newVote.ts @@ -0,0 +1,243 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { GOVERN_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const NEW_VOTE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 163, 108, 157, 189, 140, 80, 13, 143, +]); + +export function getNewVoteDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(NEW_VOTE_DISCRIMINATOR); +} + +export type NewVoteInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountProposal extends string | AccountMeta = string, + TAccountVote extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountProposal extends string + ? ReadonlyAccount + : TAccountProposal, + TAccountVote extends string + ? WritableAccount + : TAccountVote, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface NewVoteInstructionData { + discriminator: ReadonlyUint8Array; + bump: number; + voter: Address; +} + +export interface NewVoteInstructionDataArgs { + bump: number; + voter: Address; +} + +export function getNewVoteInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["bump", getU8Encoder()], + ["voter", getAddressEncoder()], + ]), + (value) => ({ ...value, discriminator: NEW_VOTE_DISCRIMINATOR }), + ); +} + +export function getNewVoteInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["bump", getU8Decoder()], + ["voter", getAddressDecoder()], + ]); +} + +export function getNewVoteInstructionDataCodec(): FixedSizeCodec< + NewVoteInstructionDataArgs, + NewVoteInstructionData +> { + return combineCodec( + getNewVoteInstructionDataEncoder(), + getNewVoteInstructionDataDecoder(), + ); +} + +export interface NewVoteInput< + TAccountProposal extends string = string, + TAccountVote extends string = string, + TAccountPayer extends string = string, + TAccountSystemProgram extends string = string, +> { + proposal: Address; + vote: Address; + payer: TransactionSigner; + systemProgram?: Address; + bump: NewVoteInstructionDataArgs["bump"]; + voter: NewVoteInstructionDataArgs["voter"]; +} + +export function getNewVoteInstruction< + TAccountProposal extends string, + TAccountVote extends string, + TAccountPayer extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof GOVERN_PROGRAM_ADDRESS, +>( + input: NewVoteInput< + TAccountProposal, + TAccountVote, + TAccountPayer, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): NewVoteInstruction< + TProgramAddress, + TAccountProposal, + TAccountVote, + TAccountPayer, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? GOVERN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + proposal: { value: input.proposal ?? null, isWritable: false }, + vote: { value: input.vote ?? null, isWritable: true }, + payer: { value: input.payer ?? null, isWritable: true }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.proposal), + getAccountMeta(accounts.vote), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.systemProgram), + ], + data: getNewVoteInstructionDataEncoder().encode( + args as NewVoteInstructionDataArgs, + ), + programAddress, + } as NewVoteInstruction< + TProgramAddress, + TAccountProposal, + TAccountVote, + TAccountPayer, + TAccountSystemProgram + >); +} + +export interface ParsedNewVoteInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + proposal: TAccountMetas[0]; + vote: TAccountMetas[1]; + payer: TAccountMetas[2]; + systemProgram: TAccountMetas[3]; + }; + data: NewVoteInstructionData; +} + +export function parseNewVoteInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedNewVoteInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + proposal: getNextAccount(), + vote: getNextAccount(), + payer: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getNewVoteInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/queueProposal.ts b/clients/tribeca/src/generated/instructions/queueProposal.ts new file mode 100644 index 00000000..f411569f --- /dev/null +++ b/clients/tribeca/src/generated/instructions/queueProposal.ts @@ -0,0 +1,283 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, +} from "@solana/kit"; +import { GOVERN_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const QUEUE_PROPOSAL_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 168, 219, 139, 211, 205, 152, 125, 110, +]); + +export function getQueueProposalDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + QUEUE_PROPOSAL_DISCRIMINATOR, + ); +} + +export type QueueProposalInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountGovernor extends string | AccountMeta = string, + TAccountProposal extends string | AccountMeta = string, + TAccountTransaction extends string | AccountMeta = string, + TAccountSmartWallet extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TAccountSmartWalletProgram extends string | AccountMeta = string, + TAccountSystemProgram extends + | string + | AccountMeta = "11111111111111111111111111111111", + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountGovernor extends string + ? ReadonlyAccount + : TAccountGovernor, + TAccountProposal extends string + ? WritableAccount + : TAccountProposal, + TAccountTransaction extends string + ? WritableAccount + : TAccountTransaction, + TAccountSmartWallet extends string + ? WritableAccount + : TAccountSmartWallet, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + TAccountSmartWalletProgram extends string + ? ReadonlyAccount + : TAccountSmartWalletProgram, + TAccountSystemProgram extends string + ? ReadonlyAccount + : TAccountSystemProgram, + ...TRemainingAccounts, + ] + >; + +export interface QueueProposalInstructionData { + discriminator: ReadonlyUint8Array; + txBump: number; +} + +export interface QueueProposalInstructionDataArgs { + txBump: number; +} + +export function getQueueProposalInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["txBump", getU8Encoder()], + ]), + (value) => ({ ...value, discriminator: QUEUE_PROPOSAL_DISCRIMINATOR }), + ); +} + +export function getQueueProposalInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["txBump", getU8Decoder()], + ]); +} + +export function getQueueProposalInstructionDataCodec(): FixedSizeCodec< + QueueProposalInstructionDataArgs, + QueueProposalInstructionData +> { + return combineCodec( + getQueueProposalInstructionDataEncoder(), + getQueueProposalInstructionDataDecoder(), + ); +} + +export interface QueueProposalInput< + TAccountGovernor extends string = string, + TAccountProposal extends string = string, + TAccountTransaction extends string = string, + TAccountSmartWallet extends string = string, + TAccountPayer extends string = string, + TAccountSmartWalletProgram extends string = string, + TAccountSystemProgram extends string = string, +> { + governor: Address; + proposal: Address; + transaction: Address; + smartWallet: Address; + payer: TransactionSigner; + smartWalletProgram: Address; + systemProgram?: Address; + txBump: QueueProposalInstructionDataArgs["txBump"]; +} + +export function getQueueProposalInstruction< + TAccountGovernor extends string, + TAccountProposal extends string, + TAccountTransaction extends string, + TAccountSmartWallet extends string, + TAccountPayer extends string, + TAccountSmartWalletProgram extends string, + TAccountSystemProgram extends string, + TProgramAddress extends Address = typeof GOVERN_PROGRAM_ADDRESS, +>( + input: QueueProposalInput< + TAccountGovernor, + TAccountProposal, + TAccountTransaction, + TAccountSmartWallet, + TAccountPayer, + TAccountSmartWalletProgram, + TAccountSystemProgram + >, + config?: { programAddress?: TProgramAddress }, +): QueueProposalInstruction< + TProgramAddress, + TAccountGovernor, + TAccountProposal, + TAccountTransaction, + TAccountSmartWallet, + TAccountPayer, + TAccountSmartWalletProgram, + TAccountSystemProgram +> { + // Program address. + const programAddress = config?.programAddress ?? GOVERN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + governor: { value: input.governor ?? null, isWritable: false }, + proposal: { value: input.proposal ?? null, isWritable: true }, + transaction: { value: input.transaction ?? null, isWritable: true }, + smartWallet: { value: input.smartWallet ?? null, isWritable: true }, + payer: { value: input.payer ?? null, isWritable: true }, + smartWalletProgram: { + value: input.smartWalletProgram ?? null, + isWritable: false, + }, + systemProgram: { value: input.systemProgram ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Resolve default values. + if (!accounts.systemProgram.value) { + accounts.systemProgram.value = + "11111111111111111111111111111111" as Address<"11111111111111111111111111111111">; + } + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.governor), + getAccountMeta(accounts.proposal), + getAccountMeta(accounts.transaction), + getAccountMeta(accounts.smartWallet), + getAccountMeta(accounts.payer), + getAccountMeta(accounts.smartWalletProgram), + getAccountMeta(accounts.systemProgram), + ], + data: getQueueProposalInstructionDataEncoder().encode( + args as QueueProposalInstructionDataArgs, + ), + programAddress, + } as QueueProposalInstruction< + TProgramAddress, + TAccountGovernor, + TAccountProposal, + TAccountTransaction, + TAccountSmartWallet, + TAccountPayer, + TAccountSmartWalletProgram, + TAccountSystemProgram + >); +} + +export interface ParsedQueueProposalInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + governor: TAccountMetas[0]; + proposal: TAccountMetas[1]; + transaction: TAccountMetas[2]; + smartWallet: TAccountMetas[3]; + payer: TAccountMetas[4]; + smartWalletProgram: TAccountMetas[5]; + systemProgram: TAccountMetas[6]; + }; + data: QueueProposalInstructionData; +} + +export function parseQueueProposalInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedQueueProposalInstruction { + if (instruction.accounts.length < 7) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + governor: getNextAccount(), + proposal: getNextAccount(), + transaction: getNextAccount(), + smartWallet: getNextAccount(), + payer: getNextAccount(), + smartWalletProgram: getNextAccount(), + systemProgram: getNextAccount(), + }, + data: getQueueProposalInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/revokeProgramLockPrivilege.ts b/clients/tribeca/src/generated/instructions/revokeProgramLockPrivilege.ts new file mode 100644 index 00000000..e8d8c2ec --- /dev/null +++ b/clients/tribeca/src/generated/instructions/revokeProgramLockPrivilege.ts @@ -0,0 +1,235 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, + WritableSignerAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const REVOKE_PROGRAM_LOCK_PRIVILEGE_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([170, 151, 7, 88, 194, 86, 245, 112]); + +export function getRevokeProgramLockPrivilegeDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + REVOKE_PROGRAM_LOCK_PRIVILEGE_DISCRIMINATOR, + ); +} + +export type RevokeProgramLockPrivilegeInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountWhitelistEntry extends string | AccountMeta = string, + TAccountGovernor extends string | AccountMeta = string, + TAccountSmartWallet extends string | AccountMeta = string, + TAccountPayer extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? ReadonlyAccount + : TAccountLocker, + TAccountWhitelistEntry extends string + ? WritableAccount + : TAccountWhitelistEntry, + TAccountGovernor extends string + ? ReadonlyAccount + : TAccountGovernor, + TAccountSmartWallet extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSmartWallet, + TAccountPayer extends string + ? WritableSignerAccount & + AccountSignerMeta + : TAccountPayer, + ...TRemainingAccounts, + ] + >; + +export interface RevokeProgramLockPrivilegeInstructionData { + discriminator: ReadonlyUint8Array; +} + +export interface RevokeProgramLockPrivilegeInstructionDataArgs {} + +export function getRevokeProgramLockPrivilegeInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([["discriminator", fixEncoderSize(getBytesEncoder(), 8)]]), + (value) => ({ + ...value, + discriminator: REVOKE_PROGRAM_LOCK_PRIVILEGE_DISCRIMINATOR, + }), + ); +} + +export function getRevokeProgramLockPrivilegeInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ]); +} + +export function getRevokeProgramLockPrivilegeInstructionDataCodec(): FixedSizeCodec< + RevokeProgramLockPrivilegeInstructionDataArgs, + RevokeProgramLockPrivilegeInstructionData +> { + return combineCodec( + getRevokeProgramLockPrivilegeInstructionDataEncoder(), + getRevokeProgramLockPrivilegeInstructionDataDecoder(), + ); +} + +export interface RevokeProgramLockPrivilegeInput< + TAccountLocker extends string = string, + TAccountWhitelistEntry extends string = string, + TAccountGovernor extends string = string, + TAccountSmartWallet extends string = string, + TAccountPayer extends string = string, +> { + locker: Address; + whitelistEntry: Address; + governor: Address; + smartWallet: TransactionSigner; + payer: TransactionSigner; +} + +export function getRevokeProgramLockPrivilegeInstruction< + TAccountLocker extends string, + TAccountWhitelistEntry extends string, + TAccountGovernor extends string, + TAccountSmartWallet extends string, + TAccountPayer extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: RevokeProgramLockPrivilegeInput< + TAccountLocker, + TAccountWhitelistEntry, + TAccountGovernor, + TAccountSmartWallet, + TAccountPayer + >, + config?: { programAddress?: TProgramAddress }, +): RevokeProgramLockPrivilegeInstruction< + TProgramAddress, + TAccountLocker, + TAccountWhitelistEntry, + TAccountGovernor, + TAccountSmartWallet, + TAccountPayer +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: false }, + whitelistEntry: { value: input.whitelistEntry ?? null, isWritable: true }, + governor: { value: input.governor ?? null, isWritable: false }, + smartWallet: { value: input.smartWallet ?? null, isWritable: false }, + payer: { value: input.payer ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.whitelistEntry), + getAccountMeta(accounts.governor), + getAccountMeta(accounts.smartWallet), + getAccountMeta(accounts.payer), + ], + data: getRevokeProgramLockPrivilegeInstructionDataEncoder().encode({}), + programAddress, + } as RevokeProgramLockPrivilegeInstruction< + TProgramAddress, + TAccountLocker, + TAccountWhitelistEntry, + TAccountGovernor, + TAccountSmartWallet, + TAccountPayer + >); +} + +export interface ParsedRevokeProgramLockPrivilegeInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + whitelistEntry: TAccountMetas[1]; + governor: TAccountMetas[2]; + smartWallet: TAccountMetas[3]; + payer: TAccountMetas[4]; + }; + data: RevokeProgramLockPrivilegeInstructionData; +} + +export function parseRevokeProgramLockPrivilegeInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedRevokeProgramLockPrivilegeInstruction { + if (instruction.accounts.length < 5) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + whitelistEntry: getNextAccount(), + governor: getNextAccount(), + smartWallet: getNextAccount(), + payer: getNextAccount(), + }, + data: getRevokeProgramLockPrivilegeInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/tribeca/src/generated/instructions/setElectorate.ts b/clients/tribeca/src/generated/instructions/setElectorate.ts new file mode 100644 index 00000000..3b039dc8 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/setElectorate.ts @@ -0,0 +1,195 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { GOVERN_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_ELECTORATE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 145, 135, 92, 16, 77, 195, 145, 91, +]); + +export function getSetElectorateDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_ELECTORATE_DISCRIMINATOR, + ); +} + +export type SetElectorateInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountGovernor extends string | AccountMeta = string, + TAccountSmartWallet extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountGovernor extends string + ? WritableAccount + : TAccountGovernor, + TAccountSmartWallet extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSmartWallet, + ...TRemainingAccounts, + ] + >; + +export interface SetElectorateInstructionData { + discriminator: ReadonlyUint8Array; + newElectorate: Address; +} + +export interface SetElectorateInstructionDataArgs { + newElectorate: Address; +} + +export function getSetElectorateInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["newElectorate", getAddressEncoder()], + ]), + (value) => ({ ...value, discriminator: SET_ELECTORATE_DISCRIMINATOR }), + ); +} + +export function getSetElectorateInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["newElectorate", getAddressDecoder()], + ]); +} + +export function getSetElectorateInstructionDataCodec(): FixedSizeCodec< + SetElectorateInstructionDataArgs, + SetElectorateInstructionData +> { + return combineCodec( + getSetElectorateInstructionDataEncoder(), + getSetElectorateInstructionDataDecoder(), + ); +} + +export interface SetElectorateInput< + TAccountGovernor extends string = string, + TAccountSmartWallet extends string = string, +> { + governor: Address; + smartWallet: TransactionSigner; + newElectorate: SetElectorateInstructionDataArgs["newElectorate"]; +} + +export function getSetElectorateInstruction< + TAccountGovernor extends string, + TAccountSmartWallet extends string, + TProgramAddress extends Address = typeof GOVERN_PROGRAM_ADDRESS, +>( + input: SetElectorateInput, + config?: { programAddress?: TProgramAddress }, +): SetElectorateInstruction< + TProgramAddress, + TAccountGovernor, + TAccountSmartWallet +> { + // Program address. + const programAddress = config?.programAddress ?? GOVERN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + governor: { value: input.governor ?? null, isWritable: true }, + smartWallet: { value: input.smartWallet ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.governor), + getAccountMeta(accounts.smartWallet), + ], + data: getSetElectorateInstructionDataEncoder().encode( + args as SetElectorateInstructionDataArgs, + ), + programAddress, + } as SetElectorateInstruction< + TProgramAddress, + TAccountGovernor, + TAccountSmartWallet + >); +} + +export interface ParsedSetElectorateInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + governor: TAccountMetas[0]; + smartWallet: TAccountMetas[1]; + }; + data: SetElectorateInstructionData; +} + +export function parseSetElectorateInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetElectorateInstruction { + if (instruction.accounts.length < 2) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { governor: getNextAccount(), smartWallet: getNextAccount() }, + data: getSetElectorateInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/setGovernanceParams.ts b/clients/tribeca/src/generated/instructions/setGovernanceParams.ts new file mode 100644 index 00000000..c295ff81 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/setGovernanceParams.ts @@ -0,0 +1,205 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import type { + GovernanceParameters, + GovernanceParametersArgs, +} from "../types/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { GOVERN_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import { + getGovernanceParametersDecoder, + getGovernanceParametersEncoder, +} from "../types/index.js"; + +export const SET_GOVERNANCE_PARAMS_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([175, 187, 3, 73, 8, 251, 67, 178]); + +export function getSetGovernanceParamsDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_GOVERNANCE_PARAMS_DISCRIMINATOR, + ); +} + +export type SetGovernanceParamsInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountGovernor extends string | AccountMeta = string, + TAccountSmartWallet extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountGovernor extends string + ? WritableAccount + : TAccountGovernor, + TAccountSmartWallet extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSmartWallet, + ...TRemainingAccounts, + ] + >; + +export interface SetGovernanceParamsInstructionData { + discriminator: ReadonlyUint8Array; + params: GovernanceParameters; +} + +export interface SetGovernanceParamsInstructionDataArgs { + params: GovernanceParametersArgs; +} + +export function getSetGovernanceParamsInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["params", getGovernanceParametersEncoder()], + ]), + (value) => ({ + ...value, + discriminator: SET_GOVERNANCE_PARAMS_DISCRIMINATOR, + }), + ); +} + +export function getSetGovernanceParamsInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["params", getGovernanceParametersDecoder()], + ]); +} + +export function getSetGovernanceParamsInstructionDataCodec(): FixedSizeCodec< + SetGovernanceParamsInstructionDataArgs, + SetGovernanceParamsInstructionData +> { + return combineCodec( + getSetGovernanceParamsInstructionDataEncoder(), + getSetGovernanceParamsInstructionDataDecoder(), + ); +} + +export interface SetGovernanceParamsInput< + TAccountGovernor extends string = string, + TAccountSmartWallet extends string = string, +> { + governor: Address; + smartWallet: TransactionSigner; + params: SetGovernanceParamsInstructionDataArgs["params"]; +} + +export function getSetGovernanceParamsInstruction< + TAccountGovernor extends string, + TAccountSmartWallet extends string, + TProgramAddress extends Address = typeof GOVERN_PROGRAM_ADDRESS, +>( + input: SetGovernanceParamsInput, + config?: { programAddress?: TProgramAddress }, +): SetGovernanceParamsInstruction< + TProgramAddress, + TAccountGovernor, + TAccountSmartWallet +> { + // Program address. + const programAddress = config?.programAddress ?? GOVERN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + governor: { value: input.governor ?? null, isWritable: true }, + smartWallet: { value: input.smartWallet ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.governor), + getAccountMeta(accounts.smartWallet), + ], + data: getSetGovernanceParamsInstructionDataEncoder().encode( + args as SetGovernanceParamsInstructionDataArgs, + ), + programAddress, + } as SetGovernanceParamsInstruction< + TProgramAddress, + TAccountGovernor, + TAccountSmartWallet + >); +} + +export interface ParsedSetGovernanceParamsInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + governor: TAccountMetas[0]; + smartWallet: TAccountMetas[1]; + }; + data: SetGovernanceParamsInstructionData; +} + +export function parseSetGovernanceParamsInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetGovernanceParamsInstruction { + if (instruction.accounts.length < 2) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { governor: getNextAccount(), smartWallet: getNextAccount() }, + data: getSetGovernanceParamsInstructionDataDecoder().decode( + instruction.data, + ), + }; +} diff --git a/clients/tribeca/src/generated/instructions/setLockerParams.ts b/clients/tribeca/src/generated/instructions/setLockerParams.ts new file mode 100644 index 00000000..d72c2198 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/setLockerParams.ts @@ -0,0 +1,218 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import type { LockerParams, LockerParamsArgs } from "../types/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; +import { + getLockerParamsDecoder, + getLockerParamsEncoder, +} from "../types/index.js"; + +export const SET_LOCKER_PARAMS_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([106, 39, 132, 84, 254, 77, 161, 169]); + +export function getSetLockerParamsDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_LOCKER_PARAMS_DISCRIMINATOR, + ); +} + +export type SetLockerParamsInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountLocker extends string | AccountMeta = string, + TAccountGovernor extends string | AccountMeta = string, + TAccountSmartWallet extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountLocker extends string + ? WritableAccount + : TAccountLocker, + TAccountGovernor extends string + ? ReadonlyAccount + : TAccountGovernor, + TAccountSmartWallet extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountSmartWallet, + ...TRemainingAccounts, + ] + >; + +export interface SetLockerParamsInstructionData { + discriminator: ReadonlyUint8Array; + params: LockerParams; +} + +export interface SetLockerParamsInstructionDataArgs { + params: LockerParamsArgs; +} + +export function getSetLockerParamsInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["params", getLockerParamsEncoder()], + ]), + (value) => ({ ...value, discriminator: SET_LOCKER_PARAMS_DISCRIMINATOR }), + ); +} + +export function getSetLockerParamsInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["params", getLockerParamsDecoder()], + ]); +} + +export function getSetLockerParamsInstructionDataCodec(): FixedSizeCodec< + SetLockerParamsInstructionDataArgs, + SetLockerParamsInstructionData +> { + return combineCodec( + getSetLockerParamsInstructionDataEncoder(), + getSetLockerParamsInstructionDataDecoder(), + ); +} + +export interface SetLockerParamsInput< + TAccountLocker extends string = string, + TAccountGovernor extends string = string, + TAccountSmartWallet extends string = string, +> { + locker: Address; + governor: Address; + smartWallet: TransactionSigner; + params: SetLockerParamsInstructionDataArgs["params"]; +} + +export function getSetLockerParamsInstruction< + TAccountLocker extends string, + TAccountGovernor extends string, + TAccountSmartWallet extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: SetLockerParamsInput< + TAccountLocker, + TAccountGovernor, + TAccountSmartWallet + >, + config?: { programAddress?: TProgramAddress }, +): SetLockerParamsInstruction< + TProgramAddress, + TAccountLocker, + TAccountGovernor, + TAccountSmartWallet +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + locker: { value: input.locker ?? null, isWritable: true }, + governor: { value: input.governor ?? null, isWritable: false }, + smartWallet: { value: input.smartWallet ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.locker), + getAccountMeta(accounts.governor), + getAccountMeta(accounts.smartWallet), + ], + data: getSetLockerParamsInstructionDataEncoder().encode( + args as SetLockerParamsInstructionDataArgs, + ), + programAddress, + } as SetLockerParamsInstruction< + TProgramAddress, + TAccountLocker, + TAccountGovernor, + TAccountSmartWallet + >); +} + +export interface ParsedSetLockerParamsInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + locker: TAccountMetas[0]; + governor: TAccountMetas[1]; + smartWallet: TAccountMetas[2]; + }; + data: SetLockerParamsInstructionData; +} + +export function parseSetLockerParamsInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetLockerParamsInstruction { + if (instruction.accounts.length < 3) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + locker: getNextAccount(), + governor: getNextAccount(), + smartWallet: getNextAccount(), + }, + data: getSetLockerParamsInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/setVote.ts b/clients/tribeca/src/generated/instructions/setVote.ts new file mode 100644 index 00000000..11725626 --- /dev/null +++ b/clients/tribeca/src/generated/instructions/setVote.ts @@ -0,0 +1,235 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlyAccount, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, + transformEncoder, +} from "@solana/kit"; +import { GOVERN_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_VOTE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([ + 171, 33, 83, 172, 148, 215, 239, 97, +]); + +export function getSetVoteDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode(SET_VOTE_DISCRIMINATOR); +} + +export type SetVoteInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountGovernor extends string | AccountMeta = string, + TAccountProposal extends string | AccountMeta = string, + TAccountVote extends string | AccountMeta = string, + TAccountElectorate extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountGovernor extends string + ? ReadonlyAccount + : TAccountGovernor, + TAccountProposal extends string + ? WritableAccount + : TAccountProposal, + TAccountVote extends string + ? WritableAccount + : TAccountVote, + TAccountElectorate extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountElectorate, + ...TRemainingAccounts, + ] + >; + +export interface SetVoteInstructionData { + discriminator: ReadonlyUint8Array; + side: number; + weight: bigint; +} + +export interface SetVoteInstructionDataArgs { + side: number; + weight: number | bigint; +} + +export function getSetVoteInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["side", getU8Encoder()], + ["weight", getU64Encoder()], + ]), + (value) => ({ ...value, discriminator: SET_VOTE_DISCRIMINATOR }), + ); +} + +export function getSetVoteInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["side", getU8Decoder()], + ["weight", getU64Decoder()], + ]); +} + +export function getSetVoteInstructionDataCodec(): FixedSizeCodec< + SetVoteInstructionDataArgs, + SetVoteInstructionData +> { + return combineCodec( + getSetVoteInstructionDataEncoder(), + getSetVoteInstructionDataDecoder(), + ); +} + +export interface SetVoteInput< + TAccountGovernor extends string = string, + TAccountProposal extends string = string, + TAccountVote extends string = string, + TAccountElectorate extends string = string, +> { + governor: Address; + proposal: Address; + vote: Address; + electorate: TransactionSigner; + side: SetVoteInstructionDataArgs["side"]; + weight: SetVoteInstructionDataArgs["weight"]; +} + +export function getSetVoteInstruction< + TAccountGovernor extends string, + TAccountProposal extends string, + TAccountVote extends string, + TAccountElectorate extends string, + TProgramAddress extends Address = typeof GOVERN_PROGRAM_ADDRESS, +>( + input: SetVoteInput< + TAccountGovernor, + TAccountProposal, + TAccountVote, + TAccountElectorate + >, + config?: { programAddress?: TProgramAddress }, +): SetVoteInstruction< + TProgramAddress, + TAccountGovernor, + TAccountProposal, + TAccountVote, + TAccountElectorate +> { + // Program address. + const programAddress = config?.programAddress ?? GOVERN_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + governor: { value: input.governor ?? null, isWritable: false }, + proposal: { value: input.proposal ?? null, isWritable: true }, + vote: { value: input.vote ?? null, isWritable: true }, + electorate: { value: input.electorate ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.governor), + getAccountMeta(accounts.proposal), + getAccountMeta(accounts.vote), + getAccountMeta(accounts.electorate), + ], + data: getSetVoteInstructionDataEncoder().encode( + args as SetVoteInstructionDataArgs, + ), + programAddress, + } as SetVoteInstruction< + TProgramAddress, + TAccountGovernor, + TAccountProposal, + TAccountVote, + TAccountElectorate + >); +} + +export interface ParsedSetVoteInstruction< + TProgram extends string = typeof GOVERN_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + governor: TAccountMetas[0]; + proposal: TAccountMetas[1]; + vote: TAccountMetas[2]; + electorate: TAccountMetas[3]; + }; + data: SetVoteInstructionData; +} + +export function parseSetVoteInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetVoteInstruction { + if (instruction.accounts.length < 4) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + governor: getNextAccount(), + proposal: getNextAccount(), + vote: getNextAccount(), + electorate: getNextAccount(), + }, + data: getSetVoteInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/instructions/setVoteDelegate.ts b/clients/tribeca/src/generated/instructions/setVoteDelegate.ts new file mode 100644 index 00000000..59672c6c --- /dev/null +++ b/clients/tribeca/src/generated/instructions/setVoteDelegate.ts @@ -0,0 +1,194 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, + Instruction, + InstructionWithAccounts, + InstructionWithData, + ReadonlySignerAccount, + ReadonlyUint8Array, + TransactionSigner, + WritableAccount, +} from "@solana/kit"; +import type { ResolvedAccount } from "../shared/index.js"; +import { + combineCodec, + fixDecoderSize, + fixEncoderSize, + getAddressDecoder, + getAddressEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + transformEncoder, +} from "@solana/kit"; +import { LOCKED_VOTER_PROGRAM_ADDRESS } from "../programs/index.js"; +import { getAccountMetaFactory } from "../shared/index.js"; + +export const SET_VOTE_DELEGATE_DISCRIMINATOR: ReadonlyUint8Array = + new Uint8Array([46, 236, 241, 243, 251, 108, 156, 12]); + +export function getSetVoteDelegateDiscriminatorBytes(): ReadonlyUint8Array { + return fixEncoderSize(getBytesEncoder(), 8).encode( + SET_VOTE_DELEGATE_DISCRIMINATOR, + ); +} + +export type SetVoteDelegateInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountEscrow extends string | AccountMeta = string, + TAccountEscrowOwner extends string | AccountMeta = string, + TRemainingAccounts extends readonly AccountMeta[] = [], +> = Instruction & + InstructionWithData & + InstructionWithAccounts< + [ + TAccountEscrow extends string + ? WritableAccount + : TAccountEscrow, + TAccountEscrowOwner extends string + ? ReadonlySignerAccount & + AccountSignerMeta + : TAccountEscrowOwner, + ...TRemainingAccounts, + ] + >; + +export interface SetVoteDelegateInstructionData { + discriminator: ReadonlyUint8Array; + newDelegate: Address; +} + +export interface SetVoteDelegateInstructionDataArgs { + newDelegate: Address; +} + +export function getSetVoteDelegateInstructionDataEncoder(): FixedSizeEncoder { + return transformEncoder( + getStructEncoder([ + ["discriminator", fixEncoderSize(getBytesEncoder(), 8)], + ["newDelegate", getAddressEncoder()], + ]), + (value) => ({ ...value, discriminator: SET_VOTE_DELEGATE_DISCRIMINATOR }), + ); +} + +export function getSetVoteDelegateInstructionDataDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["discriminator", fixDecoderSize(getBytesDecoder(), 8)], + ["newDelegate", getAddressDecoder()], + ]); +} + +export function getSetVoteDelegateInstructionDataCodec(): FixedSizeCodec< + SetVoteDelegateInstructionDataArgs, + SetVoteDelegateInstructionData +> { + return combineCodec( + getSetVoteDelegateInstructionDataEncoder(), + getSetVoteDelegateInstructionDataDecoder(), + ); +} + +export interface SetVoteDelegateInput< + TAccountEscrow extends string = string, + TAccountEscrowOwner extends string = string, +> { + escrow: Address; + escrowOwner: TransactionSigner; + newDelegate: SetVoteDelegateInstructionDataArgs["newDelegate"]; +} + +export function getSetVoteDelegateInstruction< + TAccountEscrow extends string, + TAccountEscrowOwner extends string, + TProgramAddress extends Address = typeof LOCKED_VOTER_PROGRAM_ADDRESS, +>( + input: SetVoteDelegateInput, + config?: { programAddress?: TProgramAddress }, +): SetVoteDelegateInstruction< + TProgramAddress, + TAccountEscrow, + TAccountEscrowOwner +> { + // Program address. + const programAddress = config?.programAddress ?? LOCKED_VOTER_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + escrow: { value: input.escrow ?? null, isWritable: true }, + escrowOwner: { value: input.escrowOwner ?? null, isWritable: false }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, "programId"); + return Object.freeze({ + accounts: [ + getAccountMeta(accounts.escrow), + getAccountMeta(accounts.escrowOwner), + ], + data: getSetVoteDelegateInstructionDataEncoder().encode( + args as SetVoteDelegateInstructionDataArgs, + ), + programAddress, + } as SetVoteDelegateInstruction< + TProgramAddress, + TAccountEscrow, + TAccountEscrowOwner + >); +} + +export interface ParsedSetVoteDelegateInstruction< + TProgram extends string = typeof LOCKED_VOTER_PROGRAM_ADDRESS, + TAccountMetas extends readonly AccountMeta[] = readonly AccountMeta[], +> { + programAddress: Address; + accounts: { + escrow: TAccountMetas[0]; + escrowOwner: TAccountMetas[1]; + }; + data: SetVoteDelegateInstructionData; +} + +export function parseSetVoteDelegateInstruction< + TProgram extends string, + TAccountMetas extends readonly AccountMeta[], +>( + instruction: Instruction & + InstructionWithAccounts & + InstructionWithData, +): ParsedSetVoteDelegateInstruction { + if (instruction.accounts.length < 2) { + // TODO: Coded error. + throw new Error("Not enough accounts"); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = (instruction.accounts as TAccountMetas)[accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { escrow: getNextAccount(), escrowOwner: getNextAccount() }, + data: getSetVoteDelegateInstructionDataDecoder().decode(instruction.data), + }; +} diff --git a/clients/tribeca/src/generated/pdas/escrow.ts b/clients/tribeca/src/generated/pdas/escrow.ts new file mode 100644 index 00000000..b25a32d0 --- /dev/null +++ b/clients/tribeca/src/generated/pdas/escrow.ts @@ -0,0 +1,37 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface EscrowSeeds { + locker: Address; + authority: Address; +} + +/** Escrow account that holds locked tokens for a user */ +export async function findEscrowPda( + seeds: EscrowSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "LocktDzaV1W2Bm9DeZeiyz4J9zs4fRqNiYqQyracRXw" as Address<"LocktDzaV1W2Bm9DeZeiyz4J9zs4fRqNiYqQyracRXw">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("Escrow"), + getAddressEncoder().encode(seeds.locker), + getAddressEncoder().encode(seeds.authority), + ], + }); +} diff --git a/clients/tribeca/src/generated/pdas/governor.ts b/clients/tribeca/src/generated/pdas/governor.ts new file mode 100644 index 00000000..579ccff5 --- /dev/null +++ b/clients/tribeca/src/generated/pdas/governor.ts @@ -0,0 +1,35 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface GovernorSeeds { + base: Address; +} + +/** Governor account that manages proposals and voting */ +export async function findGovernorPda( + seeds: GovernorSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw" as Address<"Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("TribecaGovernor"), + getAddressEncoder().encode(seeds.base), + ], + }); +} diff --git a/clients/tribeca/src/generated/pdas/index.ts b/clients/tribeca/src/generated/pdas/index.ts new file mode 100644 index 00000000..c3bb5aa3 --- /dev/null +++ b/clients/tribeca/src/generated/pdas/index.ts @@ -0,0 +1,15 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./escrow.js"; +export * from "./governor.js"; +export * from "./locker.js"; +export * from "./proposal.js"; +export * from "./proposalMeta.js"; +export * from "./vote.js"; +export * from "./whitelist.js"; diff --git a/clients/tribeca/src/generated/pdas/locker.ts b/clients/tribeca/src/generated/pdas/locker.ts new file mode 100644 index 00000000..78a98503 --- /dev/null +++ b/clients/tribeca/src/generated/pdas/locker.ts @@ -0,0 +1,35 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface LockerSeeds { + base: Address; +} + +/** Locker account that manages vote escrows for a specific base */ +export async function findLockerPda( + seeds: LockerSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "LocktDzaV1W2Bm9DeZeiyz4J9zs4fRqNiYqQyracRXw" as Address<"LocktDzaV1W2Bm9DeZeiyz4J9zs4fRqNiYqQyracRXw">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("Locker"), + getAddressEncoder().encode(seeds.base), + ], + }); +} diff --git a/clients/tribeca/src/generated/pdas/proposal.ts b/clients/tribeca/src/generated/pdas/proposal.ts new file mode 100644 index 00000000..04032ef5 --- /dev/null +++ b/clients/tribeca/src/generated/pdas/proposal.ts @@ -0,0 +1,38 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getU64Encoder, + getUtf8Encoder, +} from "@solana/kit"; + +export interface ProposalSeeds { + governor: Address; + index: number | bigint; +} + +/** Proposal account for governance actions */ +export async function findProposalPda( + seeds: ProposalSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw" as Address<"Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("TribecaProposal"), + getAddressEncoder().encode(seeds.governor), + getU64Encoder().encode(seeds.index), + ], + }); +} diff --git a/clients/tribeca/src/generated/pdas/proposalMeta.ts b/clients/tribeca/src/generated/pdas/proposalMeta.ts new file mode 100644 index 00000000..691cd490 --- /dev/null +++ b/clients/tribeca/src/generated/pdas/proposalMeta.ts @@ -0,0 +1,35 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface ProposalMetaSeeds { + proposal: Address; +} + +/** Proposal metadata account with additional information */ +export async function findProposalMetaPda( + seeds: ProposalMetaSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw" as Address<"Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("TribecaProposalMeta"), + getAddressEncoder().encode(seeds.proposal), + ], + }); +} diff --git a/clients/tribeca/src/generated/pdas/vote.ts b/clients/tribeca/src/generated/pdas/vote.ts new file mode 100644 index 00000000..31a2a4d4 --- /dev/null +++ b/clients/tribeca/src/generated/pdas/vote.ts @@ -0,0 +1,37 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ProgramDerivedAddress } from "@solana/kit"; +import { + getAddressEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface VoteSeeds { + proposal: Address; + voter: Address; +} + +/** Vote account representing a voter's decision on a proposal */ +export async function findVotePda( + seeds: VoteSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw" as Address<"Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("TribecaVote"), + getAddressEncoder().encode(seeds.proposal), + getAddressEncoder().encode(seeds.voter), + ], + }); +} diff --git a/clients/tribeca/src/generated/pdas/whitelist.ts b/clients/tribeca/src/generated/pdas/whitelist.ts new file mode 100644 index 00000000..ca0afd1d --- /dev/null +++ b/clients/tribeca/src/generated/pdas/whitelist.ts @@ -0,0 +1,50 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + OptionOrNullable, + ProgramDerivedAddress, +} from "@solana/kit"; +import { + address, + getAddressEncoder, + getOptionEncoder, + getProgramDerivedAddress, + getUtf8Encoder, +} from "@solana/kit"; + +export interface WhitelistSeeds { + locker: Address; + programId: Address; + owner: OptionOrNullable
; +} + +/** Whitelist entry for a program that can interact with the locker */ +export async function findWhitelistPda( + seeds: WhitelistSeeds, + config: { programAddress?: Address | undefined } = {}, +): Promise { + const { + programAddress = "LocktDzaV1W2Bm9DeZeiyz4J9zs4fRqNiYqQyracRXw" as Address<"LocktDzaV1W2Bm9DeZeiyz4J9zs4fRqNiYqQyracRXw">, + } = config; + return await getProgramDerivedAddress({ + programAddress, + seeds: [ + getUtf8Encoder().encode("LockerWhitelistEntry"), + getAddressEncoder().encode(seeds.locker), + getAddressEncoder().encode(seeds.programId), + getOptionEncoder(getAddressEncoder(), { + prefix: null, + noneValue: getAddressEncoder().encode( + address("11111111111111111111111111111111"), + ), + }).encode(seeds.owner), + ], + }); +} diff --git a/clients/tribeca/src/generated/programs/govern.ts b/clients/tribeca/src/generated/programs/govern.ts new file mode 100644 index 00000000..96946c54 --- /dev/null +++ b/clients/tribeca/src/generated/programs/govern.ts @@ -0,0 +1,251 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ReadonlyUint8Array } from "@solana/kit"; +import type { + ParsedActivateProposalInstruction, + ParsedCancelProposalInstruction, + ParsedCreateGovernorInstruction, + ParsedCreateProposalInstruction, + ParsedCreateProposalMetaInstruction, + ParsedNewVoteInstruction, + ParsedQueueProposalInstruction, + ParsedSetElectorateInstruction, + ParsedSetGovernanceParamsInstruction, + ParsedSetVoteInstruction, +} from "../instructions/index.js"; +import { containsBytes, fixEncoderSize, getBytesEncoder } from "@solana/kit"; + +export const GOVERN_PROGRAM_ADDRESS = + "Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw" as Address<"Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw">; + +export enum GovernAccount { + Governor = 0, + Proposal = 1, + ProposalMeta = 2, + Vote = 3, +} + +export function identifyGovernAccount( + account: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): GovernAccount { + const data = "data" in account ? account.data : account; + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([37, 136, 44, 80, 68, 85, 213, 178]), + ), + 0, + ) + ) { + return GovernAccount.Governor; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([26, 94, 189, 187, 116, 136, 53, 33]), + ), + 0, + ) + ) { + return GovernAccount.Proposal; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([50, 100, 46, 24, 151, 174, 216, 78]), + ), + 0, + ) + ) { + return GovernAccount.ProposalMeta; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([96, 91, 104, 57, 145, 35, 172, 155]), + ), + 0, + ) + ) { + return GovernAccount.Vote; + } + throw new Error( + "The provided account could not be identified as a govern account.", + ); +} + +export enum GovernInstruction { + CreateGovernor = 0, + CreateProposal = 1, + ActivateProposal = 2, + CancelProposal = 3, + QueueProposal = 4, + NewVote = 5, + SetVote = 6, + SetGovernanceParams = 7, + SetElectorate = 8, + CreateProposalMeta = 9, +} + +export function identifyGovernInstruction( + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): GovernInstruction { + const data = "data" in instruction ? instruction.data : instruction; + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([103, 30, 78, 252, 28, 128, 40, 3]), + ), + 0, + ) + ) { + return GovernInstruction.CreateGovernor; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([132, 116, 68, 174, 216, 160, 198, 22]), + ), + 0, + ) + ) { + return GovernInstruction.CreateProposal; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([90, 186, 203, 234, 70, 185, 191, 21]), + ), + 0, + ) + ) { + return GovernInstruction.ActivateProposal; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([106, 74, 128, 146, 19, 65, 39, 23]), + ), + 0, + ) + ) { + return GovernInstruction.CancelProposal; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([168, 219, 139, 211, 205, 152, 125, 110]), + ), + 0, + ) + ) { + return GovernInstruction.QueueProposal; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([163, 108, 157, 189, 140, 80, 13, 143]), + ), + 0, + ) + ) { + return GovernInstruction.NewVote; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([171, 33, 83, 172, 148, 215, 239, 97]), + ), + 0, + ) + ) { + return GovernInstruction.SetVote; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([175, 187, 3, 73, 8, 251, 67, 178]), + ), + 0, + ) + ) { + return GovernInstruction.SetGovernanceParams; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([145, 135, 92, 16, 77, 195, 145, 91]), + ), + 0, + ) + ) { + return GovernInstruction.SetElectorate; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([238, 138, 212, 160, 46, 53, 51, 88]), + ), + 0, + ) + ) { + return GovernInstruction.CreateProposalMeta; + } + throw new Error( + "The provided instruction could not be identified as a govern instruction.", + ); +} + +export type ParsedGovernInstruction< + TProgram extends string = "Govz1VyoyLD5BL6CSCxUJLVLsQHRwjfFj1prNsdNg5Jw", +> = + | ({ + instructionType: GovernInstruction.CreateGovernor; + } & ParsedCreateGovernorInstruction) + | ({ + instructionType: GovernInstruction.CreateProposal; + } & ParsedCreateProposalInstruction) + | ({ + instructionType: GovernInstruction.ActivateProposal; + } & ParsedActivateProposalInstruction) + | ({ + instructionType: GovernInstruction.CancelProposal; + } & ParsedCancelProposalInstruction) + | ({ + instructionType: GovernInstruction.QueueProposal; + } & ParsedQueueProposalInstruction) + | ({ + instructionType: GovernInstruction.NewVote; + } & ParsedNewVoteInstruction) + | ({ + instructionType: GovernInstruction.SetVote; + } & ParsedSetVoteInstruction) + | ({ + instructionType: GovernInstruction.SetGovernanceParams; + } & ParsedSetGovernanceParamsInstruction) + | ({ + instructionType: GovernInstruction.SetElectorate; + } & ParsedSetElectorateInstruction) + | ({ + instructionType: GovernInstruction.CreateProposalMeta; + } & ParsedCreateProposalMetaInstruction); diff --git a/clients/tribeca/src/generated/programs/index.ts b/clients/tribeca/src/generated/programs/index.ts new file mode 100644 index 00000000..c900e269 --- /dev/null +++ b/clients/tribeca/src/generated/programs/index.ts @@ -0,0 +1,10 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./govern.js"; +export * from "./lockedVoter.js"; diff --git a/clients/tribeca/src/generated/programs/lockedVoter.ts b/clients/tribeca/src/generated/programs/lockedVoter.ts new file mode 100644 index 00000000..ccb151b5 --- /dev/null +++ b/clients/tribeca/src/generated/programs/lockedVoter.ts @@ -0,0 +1,287 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { Address, ReadonlyUint8Array } from "@solana/kit"; +import type { + ParsedActivateProposalInstruction, + ParsedApproveProgramLockPrivilegeInstruction, + ParsedCastVoteInstruction, + ParsedExitInstruction, + ParsedLockInstruction, + ParsedLockPermissionlessInstruction, + ParsedLockWithWhitelistEntryInstruction, + ParsedLockWithWhitelistInstruction, + ParsedNewEscrowInstruction, + ParsedNewLockerInstruction, + ParsedRevokeProgramLockPrivilegeInstruction, + ParsedSetLockerParamsInstruction, + ParsedSetVoteDelegateInstruction, +} from "../instructions/index.js"; +import { containsBytes, fixEncoderSize, getBytesEncoder } from "@solana/kit"; + +export const LOCKED_VOTER_PROGRAM_ADDRESS = + "LocktDzaV1W2Bm9DeZeiyz4J9zs4fRqNiYqQyracRXw" as Address<"LocktDzaV1W2Bm9DeZeiyz4J9zs4fRqNiYqQyracRXw">; + +export enum LockedVoterAccount { + Locker = 0, + LockerWhitelistEntry = 1, + Escrow = 2, +} + +export function identifyLockedVoterAccount( + account: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): LockedVoterAccount { + const data = "data" in account ? account.data : account; + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([74, 246, 6, 113, 249, 228, 75, 169]), + ), + 0, + ) + ) { + return LockedVoterAccount.Locker; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([128, 245, 238, 138, 226, 48, 216, 63]), + ), + 0, + ) + ) { + return LockedVoterAccount.LockerWhitelistEntry; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([31, 213, 123, 187, 186, 22, 218, 155]), + ), + 0, + ) + ) { + return LockedVoterAccount.Escrow; + } + throw new Error( + "The provided account could not be identified as a lockedVoter account.", + ); +} + +export enum LockedVoterInstruction { + NewLocker = 0, + NewEscrow = 1, + Lock = 2, + LockWithWhitelist = 3, + LockWithWhitelistEntry = 4, + LockPermissionless = 5, + Exit = 6, + ActivateProposal = 7, + CastVote = 8, + SetVoteDelegate = 9, + SetLockerParams = 10, + ApproveProgramLockPrivilege = 11, + RevokeProgramLockPrivilege = 12, +} + +export function identifyLockedVoterInstruction( + instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array, +): LockedVoterInstruction { + const data = "data" in instruction ? instruction.data : instruction; + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([177, 133, 32, 90, 229, 216, 131, 47]), + ), + 0, + ) + ) { + return LockedVoterInstruction.NewLocker; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([216, 182, 143, 11, 220, 38, 86, 185]), + ), + 0, + ) + ) { + return LockedVoterInstruction.NewEscrow; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([21, 19, 208, 43, 237, 62, 255, 87]), + ), + 0, + ) + ) { + return LockedVoterInstruction.Lock; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([138, 141, 28, 193, 7, 211, 181, 69]), + ), + 0, + ) + ) { + return LockedVoterInstruction.LockWithWhitelist; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([138, 248, 185, 79, 3, 115, 115, 57]), + ), + 0, + ) + ) { + return LockedVoterInstruction.LockWithWhitelistEntry; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([146, 106, 208, 36, 187, 241, 122, 2]), + ), + 0, + ) + ) { + return LockedVoterInstruction.LockPermissionless; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([234, 32, 12, 71, 126, 5, 219, 160]), + ), + 0, + ) + ) { + return LockedVoterInstruction.Exit; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([90, 186, 203, 234, 70, 185, 191, 21]), + ), + 0, + ) + ) { + return LockedVoterInstruction.ActivateProposal; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([20, 212, 15, 189, 69, 180, 69, 151]), + ), + 0, + ) + ) { + return LockedVoterInstruction.CastVote; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([46, 236, 241, 243, 251, 108, 156, 12]), + ), + 0, + ) + ) { + return LockedVoterInstruction.SetVoteDelegate; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([106, 39, 132, 84, 254, 77, 161, 169]), + ), + 0, + ) + ) { + return LockedVoterInstruction.SetLockerParams; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([75, 202, 1, 4, 122, 110, 102, 148]), + ), + 0, + ) + ) { + return LockedVoterInstruction.ApproveProgramLockPrivilege; + } + if ( + containsBytes( + data, + fixEncoderSize(getBytesEncoder(), 8).encode( + new Uint8Array([170, 151, 7, 88, 194, 86, 245, 112]), + ), + 0, + ) + ) { + return LockedVoterInstruction.RevokeProgramLockPrivilege; + } + throw new Error( + "The provided instruction could not be identified as a lockedVoter instruction.", + ); +} + +export type ParsedLockedVoterInstruction< + TProgram extends string = "LocktDzaV1W2Bm9DeZeiyz4J9zs4fRqNiYqQyracRXw", +> = + | ({ + instructionType: LockedVoterInstruction.NewLocker; + } & ParsedNewLockerInstruction) + | ({ + instructionType: LockedVoterInstruction.NewEscrow; + } & ParsedNewEscrowInstruction) + | ({ + instructionType: LockedVoterInstruction.Lock; + } & ParsedLockInstruction) + | ({ + instructionType: LockedVoterInstruction.LockWithWhitelist; + } & ParsedLockWithWhitelistInstruction) + | ({ + instructionType: LockedVoterInstruction.LockWithWhitelistEntry; + } & ParsedLockWithWhitelistEntryInstruction) + | ({ + instructionType: LockedVoterInstruction.LockPermissionless; + } & ParsedLockPermissionlessInstruction) + | ({ + instructionType: LockedVoterInstruction.Exit; + } & ParsedExitInstruction) + | ({ + instructionType: LockedVoterInstruction.ActivateProposal; + } & ParsedActivateProposalInstruction) + | ({ + instructionType: LockedVoterInstruction.CastVote; + } & ParsedCastVoteInstruction) + | ({ + instructionType: LockedVoterInstruction.SetVoteDelegate; + } & ParsedSetVoteDelegateInstruction) + | ({ + instructionType: LockedVoterInstruction.SetLockerParams; + } & ParsedSetLockerParamsInstruction) + | ({ + instructionType: LockedVoterInstruction.ApproveProgramLockPrivilege; + } & ParsedApproveProgramLockPrivilegeInstruction) + | ({ + instructionType: LockedVoterInstruction.RevokeProgramLockPrivilege; + } & ParsedRevokeProgramLockPrivilegeInstruction); diff --git a/clients/tribeca/src/generated/shared/index.ts b/clients/tribeca/src/generated/shared/index.ts new file mode 100644 index 00000000..b79b9c6b --- /dev/null +++ b/clients/tribeca/src/generated/shared/index.ts @@ -0,0 +1,168 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + AccountMeta, + AccountSignerMeta, + Address, + ProgramDerivedAddress, + TransactionSigner, +} from "@solana/kit"; +import { + AccountRole, + isProgramDerivedAddress, + isTransactionSigner as kitIsTransactionSigner, + upgradeRoleToSigner, +} from "@solana/kit"; + +/** + * Asserts that the given value is not null or undefined. + * @internal + */ +export function expectSome(value: T | null | undefined): T { + if (value === null || value === undefined) { + throw new Error("Expected a value but received null or undefined."); + } + return value; +} + +/** + * Asserts that the given value is a PublicKey. + * @internal + */ +export function expectAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined, +): Address { + if (!value) { + throw new Error("Expected a Address."); + } + if (typeof value === "object" && "address" in value) { + return value.address; + } + if (Array.isArray(value)) { + return value[0] as Address; + } + return value as Address; +} + +/** + * Asserts that the given value is a PDA. + * @internal + */ +export function expectProgramDerivedAddress( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined, +): ProgramDerivedAddress { + if (!(value && Array.isArray(value) && isProgramDerivedAddress(value))) { + throw new Error("Expected a ProgramDerivedAddress."); + } + return value; +} + +/** + * Asserts that the given value is a TransactionSigner. + * @internal + */ +export function expectTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner + | null + | undefined, +): TransactionSigner { + if (!(value && isTransactionSigner(value))) { + throw new Error("Expected a TransactionSigner."); + } + return value; +} + +/** + * Defines an instruction account to resolve. + * @internal + */ +export interface ResolvedAccount< + T extends string = string, + U extends + | Address + | ProgramDerivedAddress + | TransactionSigner + | null = + | Address + | ProgramDerivedAddress + | TransactionSigner + | null, +> { + isWritable: boolean; + value: U; +} + +/** + * Defines an instruction that stores additional bytes on-chain. + * @internal + */ +export interface InstructionWithByteDelta { + byteDelta: number; +} + +/** + * Get account metas and signers from resolved accounts. + * @internal + */ +export function getAccountMetaFactory( + programAddress: Address, + optionalAccountStrategy: "omitted" | "programId", +) { + return ( + account: ResolvedAccount, + ): AccountMeta | AccountSignerMeta | undefined => { + if (!account.value) { + if (optionalAccountStrategy === "omitted") { + return; + } + return Object.freeze({ + address: programAddress, + role: AccountRole.READONLY, + }); + } + + const writableRole = account.isWritable + ? AccountRole.WRITABLE + : AccountRole.READONLY; + return Object.freeze({ + address: expectAddress(account.value), + role: isTransactionSigner(account.value) + ? upgradeRoleToSigner(writableRole) + : writableRole, + ...(isTransactionSigner(account.value) ? { signer: account.value } : {}), + }); + }; +} + +export function isTransactionSigner( + value: + | Address + | ProgramDerivedAddress + | TransactionSigner, +): value is TransactionSigner { + return ( + !!value && + typeof value === "object" && + "address" in value && + kitIsTransactionSigner(value) + ); +} diff --git a/clients/tribeca/src/generated/types/governanceParameters.ts b/clients/tribeca/src/generated/types/governanceParameters.ts new file mode 100644 index 00000000..a6409303 --- /dev/null +++ b/clients/tribeca/src/generated/types/governanceParameters.ts @@ -0,0 +1,64 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU64Decoder, + getU64Encoder, +} from "@solana/kit"; + +export interface GovernanceParameters { + votingDelay: bigint; + votingPeriod: bigint; + quorumVotes: bigint; + timelockDelaySeconds: bigint; +} + +export interface GovernanceParametersArgs { + votingDelay: number | bigint; + votingPeriod: number | bigint; + quorumVotes: number | bigint; + timelockDelaySeconds: number | bigint; +} + +export function getGovernanceParametersEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["votingDelay", getU64Encoder()], + ["votingPeriod", getU64Encoder()], + ["quorumVotes", getU64Encoder()], + ["timelockDelaySeconds", getI64Encoder()], + ]); +} + +export function getGovernanceParametersDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["votingDelay", getU64Decoder()], + ["votingPeriod", getU64Decoder()], + ["quorumVotes", getU64Decoder()], + ["timelockDelaySeconds", getI64Decoder()], + ]); +} + +export function getGovernanceParametersCodec(): FixedSizeCodec< + GovernanceParametersArgs, + GovernanceParameters +> { + return combineCodec( + getGovernanceParametersEncoder(), + getGovernanceParametersDecoder(), + ); +} diff --git a/clients/tribeca/src/generated/types/index.ts b/clients/tribeca/src/generated/types/index.ts new file mode 100644 index 00000000..4b87bd80 --- /dev/null +++ b/clients/tribeca/src/generated/types/index.ts @@ -0,0 +1,14 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +export * from "./governanceParameters.js"; +export * from "./lockerParams.js"; +export * from "./proposalAccountMeta.js"; +export * from "./proposalInstruction.js"; +export * from "./proposalState.js"; +export * from "./voteSide.js"; diff --git a/clients/tribeca/src/generated/types/lockerParams.ts b/clients/tribeca/src/generated/types/lockerParams.ts new file mode 100644 index 00000000..10157972 --- /dev/null +++ b/clients/tribeca/src/generated/types/lockerParams.ts @@ -0,0 +1,67 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getBooleanDecoder, + getBooleanEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + getU64Decoder, + getU64Encoder, +} from "@solana/kit"; + +export interface LockerParams { + whitelistEnabled: boolean; + maxStakeVoteMultiplier: number; + minStakeDuration: bigint; + maxStakeDuration: bigint; + proposalActivationMinVotes: bigint; +} + +export interface LockerParamsArgs { + whitelistEnabled: boolean; + maxStakeVoteMultiplier: number; + minStakeDuration: number | bigint; + maxStakeDuration: number | bigint; + proposalActivationMinVotes: number | bigint; +} + +export function getLockerParamsEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["whitelistEnabled", getBooleanEncoder()], + ["maxStakeVoteMultiplier", getU8Encoder()], + ["minStakeDuration", getU64Encoder()], + ["maxStakeDuration", getU64Encoder()], + ["proposalActivationMinVotes", getU64Encoder()], + ]); +} + +export function getLockerParamsDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["whitelistEnabled", getBooleanDecoder()], + ["maxStakeVoteMultiplier", getU8Decoder()], + ["minStakeDuration", getU64Decoder()], + ["maxStakeDuration", getU64Decoder()], + ["proposalActivationMinVotes", getU64Decoder()], + ]); +} + +export function getLockerParamsCodec(): FixedSizeCodec< + LockerParamsArgs, + LockerParams +> { + return combineCodec(getLockerParamsEncoder(), getLockerParamsDecoder()); +} diff --git a/clients/tribeca/src/generated/types/proposalAccountMeta.ts b/clients/tribeca/src/generated/types/proposalAccountMeta.ts new file mode 100644 index 00000000..82c800e1 --- /dev/null +++ b/clients/tribeca/src/generated/types/proposalAccountMeta.ts @@ -0,0 +1,57 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getBooleanDecoder, + getBooleanEncoder, + getStructDecoder, + getStructEncoder, +} from "@solana/kit"; + +export interface ProposalAccountMeta { + pubkey: Address; + isSigner: boolean; + isWritable: boolean; +} + +export type ProposalAccountMetaArgs = ProposalAccountMeta; + +export function getProposalAccountMetaEncoder(): FixedSizeEncoder { + return getStructEncoder([ + ["pubkey", getAddressEncoder()], + ["isSigner", getBooleanEncoder()], + ["isWritable", getBooleanEncoder()], + ]); +} + +export function getProposalAccountMetaDecoder(): FixedSizeDecoder { + return getStructDecoder([ + ["pubkey", getAddressDecoder()], + ["isSigner", getBooleanDecoder()], + ["isWritable", getBooleanDecoder()], + ]); +} + +export function getProposalAccountMetaCodec(): FixedSizeCodec< + ProposalAccountMetaArgs, + ProposalAccountMeta +> { + return combineCodec( + getProposalAccountMetaEncoder(), + getProposalAccountMetaDecoder(), + ); +} diff --git a/clients/tribeca/src/generated/types/proposalInstruction.ts b/clients/tribeca/src/generated/types/proposalInstruction.ts new file mode 100644 index 00000000..5ae468fe --- /dev/null +++ b/clients/tribeca/src/generated/types/proposalInstruction.ts @@ -0,0 +1,73 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + Address, + Codec, + Decoder, + Encoder, + ReadonlyUint8Array, +} from "@solana/kit"; +import type { ProposalAccountMeta, ProposalAccountMetaArgs } from "./index.js"; +import { + addDecoderSizePrefix, + addEncoderSizePrefix, + combineCodec, + getAddressDecoder, + getAddressEncoder, + getArrayDecoder, + getArrayEncoder, + getBytesDecoder, + getBytesEncoder, + getStructDecoder, + getStructEncoder, + getU32Decoder, + getU32Encoder, +} from "@solana/kit"; +import { + getProposalAccountMetaDecoder, + getProposalAccountMetaEncoder, +} from "./index.js"; + +export interface ProposalInstruction { + programId: Address; + keys: ProposalAccountMeta[]; + data: ReadonlyUint8Array; +} + +export interface ProposalInstructionArgs { + programId: Address; + keys: ProposalAccountMetaArgs[]; + data: ReadonlyUint8Array; +} + +export function getProposalInstructionEncoder(): Encoder { + return getStructEncoder([ + ["programId", getAddressEncoder()], + ["keys", getArrayEncoder(getProposalAccountMetaEncoder())], + ["data", addEncoderSizePrefix(getBytesEncoder(), getU32Encoder())], + ]); +} + +export function getProposalInstructionDecoder(): Decoder { + return getStructDecoder([ + ["programId", getAddressDecoder()], + ["keys", getArrayDecoder(getProposalAccountMetaDecoder())], + ["data", addDecoderSizePrefix(getBytesDecoder(), getU32Decoder())], + ]); +} + +export function getProposalInstructionCodec(): Codec< + ProposalInstructionArgs, + ProposalInstruction +> { + return combineCodec( + getProposalInstructionEncoder(), + getProposalInstructionDecoder(), + ); +} diff --git a/clients/tribeca/src/generated/types/proposalState.ts b/clients/tribeca/src/generated/types/proposalState.ts new file mode 100644 index 00000000..87060fff --- /dev/null +++ b/clients/tribeca/src/generated/types/proposalState.ts @@ -0,0 +1,40 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; + +export enum ProposalState { + Draft = 0, + Active = 1, + Canceled = 2, + Defeated = 3, + Succeeded = 4, + Queued = 5, +} + +export type ProposalStateArgs = ProposalState; + +export function getProposalStateEncoder(): FixedSizeEncoder { + return getEnumEncoder(ProposalState); +} + +export function getProposalStateDecoder(): FixedSizeDecoder { + return getEnumDecoder(ProposalState); +} + +export function getProposalStateCodec(): FixedSizeCodec< + ProposalStateArgs, + ProposalState +> { + return combineCodec(getProposalStateEncoder(), getProposalStateDecoder()); +} diff --git a/clients/tribeca/src/generated/types/voteSide.ts b/clients/tribeca/src/generated/types/voteSide.ts new file mode 100644 index 00000000..c6bc89e2 --- /dev/null +++ b/clients/tribeca/src/generated/types/voteSide.ts @@ -0,0 +1,35 @@ +/** + * This code was AUTOGENERATED using the Codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun Codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import type { + FixedSizeCodec, + FixedSizeDecoder, + FixedSizeEncoder, +} from "@solana/kit"; +import { combineCodec, getEnumDecoder, getEnumEncoder } from "@solana/kit"; + +export enum VoteSide { + Pending = 0, + Against = 1, + For = 2, + Abstain = 3, +} + +export type VoteSideArgs = VoteSide; + +export function getVoteSideEncoder(): FixedSizeEncoder { + return getEnumEncoder(VoteSide); +} + +export function getVoteSideDecoder(): FixedSizeDecoder { + return getEnumDecoder(VoteSide); +} + +export function getVoteSideCodec(): FixedSizeCodec { + return combineCodec(getVoteSideEncoder(), getVoteSideDecoder()); +} diff --git a/clients/tribeca/src/index.ts b/clients/tribeca/src/index.ts new file mode 100644 index 00000000..ab03489a --- /dev/null +++ b/clients/tribeca/src/index.ts @@ -0,0 +1,2 @@ +// Re-export all generated code +export * from "./generated/index.js"; diff --git a/clients/tribeca/tsconfig.json b/clients/tribeca/tsconfig.json new file mode 100644 index 00000000..e528d933 --- /dev/null +++ b/clients/tribeca/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@macalinao/tsconfig/tsconfig.base.json" +}