Skip to content

Commit d28480a

Browse files
authored
Merge pull request #54 from macalinao/igm/stake-pool
Adds SPL stake pool client
2 parents eeaaf67 + 4cd9f9a commit d28480a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+19080
-16
lines changed

.changeset/brave-flies-hope.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@macalinao/clients-orca-whirlpools": patch
3+
"@macalinao/clients-kamino-lending": patch
4+
"@macalinao/clients-spl-governance": patch
5+
"@macalinao/clients-spl-stake-pool": patch
6+
"@macalinao/clients-token-metadata": patch
7+
"@macalinao/clients-quarry": patch
8+
"@macalinao/coda": patch
9+
---
10+
11+
Update docs

bun.lock

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
"@changesets/cli": "^2.29.7",
99
"@macalinao/biome-config": "^0.1.2",
1010
"husky": "^9.1.7",
11-
"lint-staged": "^16.2.3",
11+
"lint-staged": "^16.2.4",
1212
"turbo": "^2.5.8",
13-
"typedoc": "^0.28.13",
13+
"typedoc": "^0.28.14",
14+
"typescript": "catalog:",
1415
},
1516
},
1617
"apps/docs": {
@@ -99,6 +100,21 @@
99100
"@solana/kit": "*",
100101
},
101102
},
103+
"clients/spl-stake-pool": {
104+
"name": "@macalinao/clients-spl-stake-pool",
105+
"version": "0.1.0",
106+
"devDependencies": {
107+
"@macalinao/coda": "workspace:^",
108+
"@macalinao/eslint-config": "catalog:",
109+
"@macalinao/tsconfig": "catalog:",
110+
"@solana/kit": "catalog:",
111+
"eslint": "catalog:",
112+
"typescript": "catalog:",
113+
},
114+
"peerDependencies": {
115+
"@solana/kit": "*",
116+
},
117+
},
102118
"clients/token-metadata": {
103119
"name": "@macalinao/clients-token-metadata",
104120
"version": "0.4.2",
@@ -533,6 +549,8 @@
533549

534550
"@macalinao/clients-spl-governance": ["@macalinao/clients-spl-governance@workspace:clients/spl-governance"],
535551

552+
"@macalinao/clients-spl-stake-pool": ["@macalinao/clients-spl-stake-pool@workspace:clients/spl-stake-pool"],
553+
536554
"@macalinao/clients-token-metadata": ["@macalinao/clients-token-metadata@workspace:clients/token-metadata"],
537555

538556
"@macalinao/clients-voter-stake-registry": ["@macalinao/clients-voter-stake-registry@workspace:clients/voter-stake-registry"],

clients/kamino-lending/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ npm install @macalinao/clients-kamino-lending
2626

2727
```typescript
2828
import {
29-
createInitializeInstruction,
29+
getInitLendingMarketInstruction,
3030
fetchLendingMarket,
3131
// ... other exports
3232
} from "@macalinao/clients-kamino-lending";
@@ -39,7 +39,7 @@ const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
3939
const lendingMarket = await fetchLendingMarket(rpc, marketAddress);
4040

4141
// Create instructions
42-
const instruction = createInitializeInstruction({
42+
const instruction = getInitLendingMarketInstruction({
4343
// ... instruction parameters
4444
});
4545
```

clients/orca-whirlpools/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@ The `coda.config.mjs` file can be customized to add PDAs and other Codama visito
3333
## Usage
3434

3535
```typescript
36-
import {} from /* generated exports */ "@macalinao/clients-orca-whirlpools";
37-
38-
// Use the generated client functions
36+
import {
37+
getSwapInstruction,
38+
fetchWhirlpool,
39+
} from "@macalinao/clients-orca-whirlpools";
40+
41+
// Fetch whirlpool account
42+
const whirlpool = await fetchWhirlpool(rpc, whirlpoolAddress);
43+
44+
// Create swap instruction
45+
const instruction = getSwapInstruction({
46+
// ... instruction parameters
47+
});
3948
```
4049

4150
## License

clients/quarry/README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,18 @@ The `coda.config.mjs` file is configured to load all Quarry protocol IDLs and ge
4040
## Usage
4141

4242
```typescript
43-
import {} from /* generated exports */ "@macalinao/clients-quarry";
44-
45-
// Use the generated client functions for any Quarry program
43+
import {
44+
getCreateMinerInstruction,
45+
fetchMiner,
46+
} from "@macalinao/clients-quarry";
47+
48+
// Fetch miner account
49+
const miner = await fetchMiner(rpc, minerAddress);
50+
51+
// Create miner instruction
52+
const instruction = getCreateMinerInstruction({
53+
// ... instruction parameters
54+
});
4655
```
4756

4857
## License

clients/spl-governance/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ The `coda.config.mjs` file defines custom PDAs for the SPL Governance program, i
4040
## Usage
4141

4242
```typescript
43-
import { createRealm, getRealmPda } from "@macalinao/clients-spl-governance";
43+
import { getCreateRealmInstruction, findRealmPda } from "@macalinao/clients-spl-governance";
4444

4545
// Create a new realm
46-
const realmPda = getRealmPda({ name: "my-dao" });
46+
const realmPda = await findRealmPda({ name: "my-dao" });
4747

4848
// Use the generated client functions
4949
```

clients/spl-stake-pool/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# @macalinao/clients-spl-stake-pool
2+
3+
[![npm version](https://img.shields.io/npm/v/@macalinao/clients-spl-stake-pool.svg)](https://www.npmjs.com/package/@macalinao/clients-spl-stake-pool)
4+
5+
TypeScript client for the SPL Stake Pool program, generated using Coda with full ESM support.
6+
7+
## Installation
8+
9+
```bash
10+
bun add @macalinao/clients-spl-stake-pool
11+
```
12+
13+
## Development
14+
15+
This client is generated from the SPL Stake Pool IDL using Coda CLI:
16+
17+
```bash
18+
# Generate the client from idls/spl_stake_pool.json
19+
bun run codegen
20+
21+
# Build the TypeScript
22+
bun run build
23+
```
24+
25+
### Configuration
26+
27+
The `coda.config.mjs` file defines custom PDAs for the SPL Stake Pool program, including:
28+
29+
- Withdraw authority for the stake pool
30+
- Stake accounts for validators
31+
- Stake accounts with custom seeds
32+
- Transient stake accounts for delegation operations
33+
- Ephemeral stake accounts for temporary operations
34+
35+
## Usage
36+
37+
```typescript
38+
import {
39+
findWithdrawAuthorityPda,
40+
findStakePda
41+
} from "@macalinao/clients-spl-stake-pool";
42+
43+
// Get withdraw authority PDA
44+
const withdrawAuthorityPda = await findWithdrawAuthorityPda({
45+
stakePool: stakePoolPublicKey
46+
});
47+
48+
// Get stake account PDA
49+
const stakePda = await findStakePda({
50+
voteAccount: validatorVoteAccount,
51+
stakePool: stakePoolPublicKey
52+
});
53+
54+
// Use the generated client functions
55+
```
56+
57+
## License
58+
59+
Copyright © 2025 Ian Macalinao
60+
61+
Licensed under the Apache License, Version 2.0
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import {
2+
accountValueNode,
3+
addPdasVisitor,
4+
argumentValueNode,
5+
constantPdaSeedNodeFromString,
6+
defineConfig,
7+
definedTypeLinkNode,
8+
enumValueNode,
9+
numberTypeNode,
10+
pdaLinkNode,
11+
pdaSeedValueNode,
12+
pdaValueNode,
13+
publicKeyTypeNode,
14+
publicKeyValueNode,
15+
remainderOptionTypeNode,
16+
setAccountDiscriminatorFromFieldVisitor,
17+
setInstructionAccountDefaultValuesVisitor,
18+
variablePdaSeedNode,
19+
} from "@macalinao/coda";
20+
21+
/** @type {import("@macalinao/coda").CodaConfig} */
22+
export default defineConfig({
23+
// Use glob pattern to match both IDL files
24+
outputDir: "./src/generated",
25+
docs: {
26+
npmPackageName: "@macalinao/clients-spl-stake-pool",
27+
},
28+
visitors: [
29+
setAccountDiscriminatorFromFieldVisitor({
30+
// Realm accounts
31+
stakePool: {
32+
field: "accountType",
33+
value: enumValueNode(definedTypeLinkNode("accountType"), "StakePool"),
34+
},
35+
validatorList: {
36+
field: "accountType",
37+
value: enumValueNode(
38+
definedTypeLinkNode("accountType"),
39+
"ValidatorList",
40+
),
41+
},
42+
}),
43+
addPdasVisitor({
44+
splStakePool: [
45+
{
46+
name: "withdrawAuthority",
47+
seeds: [
48+
variablePdaSeedNode("stakePoolAddress", publicKeyTypeNode()),
49+
constantPdaSeedNodeFromString("utf8", "withdraw"),
50+
],
51+
},
52+
{
53+
name: "stake",
54+
seeds: [
55+
variablePdaSeedNode("voteAccountAddress", publicKeyTypeNode()),
56+
variablePdaSeedNode("stakePoolAddress", publicKeyTypeNode()),
57+
variablePdaSeedNode(
58+
"seed",
59+
remainderOptionTypeNode(numberTypeNode("u32", "le")),
60+
),
61+
],
62+
},
63+
{
64+
name: "transientStake",
65+
seeds: [
66+
constantPdaSeedNodeFromString("utf8", "transient"),
67+
variablePdaSeedNode("voteAccountAddress", publicKeyTypeNode()),
68+
variablePdaSeedNode("stakePoolAddress", publicKeyTypeNode()),
69+
variablePdaSeedNode("seed", numberTypeNode("u64", "le")),
70+
],
71+
},
72+
{
73+
name: "ephemeralStake",
74+
seeds: [
75+
constantPdaSeedNodeFromString("utf8", "ephemeral"),
76+
variablePdaSeedNode("stakePoolAddress", publicKeyTypeNode()),
77+
variablePdaSeedNode("seed", numberTypeNode("u64", "le")),
78+
],
79+
},
80+
],
81+
}),
82+
setInstructionAccountDefaultValuesVisitor([
83+
{
84+
account: "stakeProgram",
85+
defaultValue: publicKeyValueNode(
86+
"Stake11111111111111111111111111111111111111",
87+
),
88+
},
89+
{
90+
account: "withdrawAuthority",
91+
defaultValue: pdaValueNode(pdaLinkNode("withdrawAuthority"), [
92+
pdaSeedValueNode("stakePoolAddress", accountValueNode("stakePool")),
93+
]),
94+
},
95+
{
96+
account: "transientStakeAccount",
97+
defaultValue: pdaValueNode(pdaLinkNode("transientStake"), [
98+
pdaSeedValueNode(
99+
"voteAccountAddress",
100+
accountValueNode("validatorVoteAccount"),
101+
),
102+
pdaSeedValueNode("stakePoolAddress", accountValueNode("stakePool")),
103+
pdaSeedValueNode("seed", argumentValueNode("transientStakeSeed")),
104+
]),
105+
},
106+
]),
107+
],
108+
});
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { configs } from "@macalinao/eslint-config";
2+
3+
export default [
4+
...configs.fast,
5+
{
6+
languageOptions: {
7+
parserOptions: {
8+
tsconfigRootDir: import.meta.dirname,
9+
},
10+
},
11+
},
12+
{
13+
files: ["src/generated/**/*.ts"],
14+
rules: {
15+
"@typescript-eslint/no-non-null-assertion": "off",
16+
"@typescript-eslint/prefer-nullish-coalescing": "off",
17+
},
18+
},
19+
{
20+
files: [
21+
"src/generated/instructions/*.ts",
22+
"src/generated/types/*.ts",
23+
"src/generated/errors/*.ts",
24+
],
25+
rules: {
26+
"@typescript-eslint/no-unnecessary-condition": "off",
27+
"no-constant-condition": "off",
28+
"@typescript-eslint/no-empty-object-type": "off",
29+
},
30+
},
31+
];

0 commit comments

Comments
 (0)