Skip to content

Commit db12844

Browse files
committed
Update kamino lending PDAs to include farm pdas
1 parent 9c47857 commit db12844

Some content is hidden

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

53 files changed

+2416
-81
lines changed

biome.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.2.5/schema.json",
2+
"$schema": "https://biomejs.dev/schemas/2.2.6/schema.json",
33
"extends": ["@macalinao/biome-config/base"],
44
"files": {
55
"ignoreUnknown": false,

bun.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"": {
55
"name": "@macalinao/coda-monorepo",
66
"devDependencies": {
7-
"@biomejs/biome": "^2.2.5",
7+
"@biomejs/biome": "^2.2.6",
88
"@changesets/cli": "^2.29.7",
99
"@macalinao/biome-config": "^0.1.2",
1010
"husky": "^9.1.7",
1111
"lint-staged": "^16.2.4",
1212
"turbo": "^2.5.8",
1313
"typedoc": "^0.28.14",
14-
"typescript": "catalog:",
14+
"typescript": "^5.9.3",
1515
},
1616
},
1717
"apps/docs": {

clients/kamino-lending/coda.config.mjs

Lines changed: 157 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import {
2+
accountValueNode,
23
addPdasVisitor,
4+
associatedTokenAccountValueNode,
35
constantPdaSeedNodeFromString,
46
defineConfig,
57
numberTypeNode,
8+
pdaLinkNode,
9+
pdaSeedValueNode,
10+
pdaValueNode,
611
programLinkNode,
712
publicKeyTypeNode,
813
renameVisitor,
914
stringTypeNode,
15+
updateAccountsVisitor,
1016
variablePdaSeedNode,
1117
} from "@macalinao/coda";
1218

@@ -18,6 +24,90 @@ export default defineConfig({
1824
npmPackageName: "@macalinao/clients-kamino-lending",
1925
},
2026
instructionAccountDefaultValues: [
27+
// farms
28+
...["initializeFarm", "stake"].map((instruction) => ({
29+
instruction,
30+
account: "farmVault",
31+
defaultValue: pdaValueNode(pdaLinkNode("farmVault"), [
32+
pdaSeedValueNode("farmState", accountValueNode("farmState")),
33+
pdaSeedValueNode("tokenMint", accountValueNode("tokenMint")),
34+
]),
35+
})),
36+
// note: delegated farms will have a different seed, the "owner" is the delegatee.
37+
...["harvestReward", "stake", "unstake", "withdrawUnstakedDeposits"].map(
38+
(instruction) => ({
39+
instruction,
40+
account: "userState",
41+
defaultValue: pdaValueNode(pdaLinkNode("farmsUserState"), [
42+
pdaSeedValueNode("farmState", accountValueNode("farmState")),
43+
pdaSeedValueNode("owner", accountValueNode("owner")),
44+
]),
45+
}),
46+
),
47+
{
48+
instruction: "initializeUser",
49+
account: "userState",
50+
defaultValue: pdaValueNode(pdaLinkNode("farmsUserState"), [
51+
pdaSeedValueNode("farmState", accountValueNode("farmState")),
52+
pdaSeedValueNode("delegatee", accountValueNode("owner")),
53+
]),
54+
},
55+
{
56+
account: "userRewardAta",
57+
defaultValue: associatedTokenAccountValueNode({
58+
owner: accountValueNode("owner"),
59+
mint: accountValueNode("rewardMint"),
60+
tokenProgram: accountValueNode("tokenProgram"),
61+
}),
62+
},
63+
{
64+
account: "rewardVault",
65+
defaultValue: pdaValueNode(pdaLinkNode("rewardVault"), [
66+
pdaSeedValueNode("farmState", accountValueNode("farmState")),
67+
pdaSeedValueNode("rewardMint", accountValueNode("rewardMint")),
68+
]),
69+
},
70+
{
71+
account: "rewardsVault",
72+
defaultValue: pdaValueNode(pdaLinkNode("rewardVault"), [
73+
pdaSeedValueNode("farmState", accountValueNode("farmState")),
74+
pdaSeedValueNode("rewardMint", accountValueNode("rewardMint")),
75+
]),
76+
},
77+
{
78+
account: "rewardsTreasuryVault",
79+
defaultValue: pdaValueNode(pdaLinkNode("rewardTreasuryVault"), [
80+
pdaSeedValueNode("globalConfig", accountValueNode("globalConfig")),
81+
pdaSeedValueNode("rewardMint", accountValueNode("rewardMint")),
82+
]),
83+
},
84+
{
85+
account: "rewardTreasuryVault",
86+
defaultValue: pdaValueNode(pdaLinkNode("rewardTreasuryVault"), [
87+
pdaSeedValueNode("globalConfig", accountValueNode("globalConfig")),
88+
pdaSeedValueNode("rewardMint", accountValueNode("rewardMint")),
89+
]),
90+
},
91+
{
92+
account: "treasuryVaultAuthority",
93+
defaultValue: pdaValueNode(pdaLinkNode("treasuryVaultsAuthority"), [
94+
pdaSeedValueNode("globalConfig", accountValueNode("globalConfig")),
95+
]),
96+
},
97+
{
98+
account: "treasuryVaultsAuthority",
99+
defaultValue: pdaValueNode(pdaLinkNode("treasuryVaultsAuthority"), [
100+
pdaSeedValueNode("globalConfig", accountValueNode("globalConfig")),
101+
]),
102+
},
103+
{
104+
account: "farmVaultsAuthority",
105+
defaultValue: pdaValueNode(pdaLinkNode("farmVaultsAuthority"), [
106+
pdaSeedValueNode("farmState", accountValueNode("farmState")),
107+
]),
108+
},
109+
110+
// other
21111
{
22112
account: "farmsProgram",
23113
defaultValue: programLinkNode("farms"),
@@ -28,11 +118,53 @@ export default defineConfig({
28118
addPdasVisitor({
29119
farms: [
30120
{
31-
name: "obligationFarmState",
121+
name: "rewardTreasuryVault",
122+
seeds: [
123+
constantPdaSeedNodeFromString("utf8", "tvault"),
124+
variablePdaSeedNode("globalConfig", publicKeyTypeNode()),
125+
variablePdaSeedNode("rewardMint", publicKeyTypeNode()),
126+
],
127+
},
128+
{
129+
name: "treasuryVaultsAuthority",
130+
seeds: [
131+
constantPdaSeedNodeFromString("utf8", "authority"),
132+
variablePdaSeedNode("globalConfig", publicKeyTypeNode()),
133+
],
134+
},
135+
{
136+
name: "farmVaultsAuthority",
137+
seeds: [
138+
constantPdaSeedNodeFromString("utf8", "authority"),
139+
variablePdaSeedNode("farmState", publicKeyTypeNode()),
140+
],
141+
},
142+
{
143+
name: "farmVault",
144+
seeds: [
145+
constantPdaSeedNodeFromString("utf8", "fvault"),
146+
variablePdaSeedNode("farmState", publicKeyTypeNode()),
147+
variablePdaSeedNode("tokenMint", publicKeyTypeNode()),
148+
],
149+
},
150+
{
151+
name: "rewardVault",
152+
seeds: [
153+
constantPdaSeedNodeFromString("utf8", "rvault"),
154+
variablePdaSeedNode("farmState", publicKeyTypeNode()),
155+
variablePdaSeedNode("rewardMint", publicKeyTypeNode()),
156+
],
157+
},
158+
{
159+
name: "farmsUserState",
32160
seeds: [
33161
constantPdaSeedNodeFromString("utf8", "user"),
34-
variablePdaSeedNode("farm", publicKeyTypeNode()),
35-
variablePdaSeedNode("obligation", publicKeyTypeNode()),
162+
variablePdaSeedNode("farmState", publicKeyTypeNode()),
163+
variablePdaSeedNode(
164+
"owner",
165+
publicKeyTypeNode(),
166+
"The user who owns the farm.",
167+
),
36168
],
37169
},
38170
],
@@ -132,5 +264,27 @@ export default defineConfig({
132264
},
133265
},
134266
}),
267+
updateAccountsVisitor({
268+
// farms
269+
farmsUserState: {
270+
pda: pdaLinkNode("farmsUserState"),
271+
},
272+
// lending
273+
obligation: {
274+
pda: pdaLinkNode("obligation"),
275+
},
276+
userMetadata: {
277+
pda: pdaLinkNode("userMetadata"),
278+
},
279+
referrerTokenState: {
280+
pda: pdaLinkNode("referrerTokenState"),
281+
},
282+
referrerState: {
283+
pda: pdaLinkNode("referrerState"),
284+
},
285+
shortUrl: {
286+
pda: pdaLinkNode("shortUrl"),
287+
},
288+
}),
135289
],
136290
});

clients/kamino-lending/src/generated/accounts/farmsUserState.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
MaybeEncodedAccount,
2020
ReadonlyUint8Array,
2121
} from "@solana/kit";
22+
import type { FarmsUserStateSeeds } from "../pdas/index.js";
2223
import {
2324
assertAccountExists,
2425
assertAccountsExist,
@@ -44,6 +45,7 @@ import {
4445
getU128Encoder,
4546
transformEncoder,
4647
} from "@solana/kit";
48+
import { findFarmsUserStatePda } from "../pdas/index.js";
4749

4850
export const FARMS_USER_STATE_DISCRIMINATOR: ReadonlyUint8Array =
4951
new Uint8Array([72, 177, 85, 249, 76, 167, 186, 126]);
@@ -264,3 +266,27 @@ export async function fetchAllMaybeFarmsUserState(
264266
decodeFarmsUserState(maybeAccount),
265267
);
266268
}
269+
270+
export async function fetchFarmsUserStateFromSeeds(
271+
rpc: Parameters<typeof fetchEncodedAccount>[0],
272+
seeds: FarmsUserStateSeeds,
273+
config: FetchAccountConfig & { programAddress?: Address } = {},
274+
): Promise<Account<FarmsUserState>> {
275+
const maybeAccount = await fetchMaybeFarmsUserStateFromSeeds(
276+
rpc,
277+
seeds,
278+
config,
279+
);
280+
assertAccountExists(maybeAccount);
281+
return maybeAccount;
282+
}
283+
284+
export async function fetchMaybeFarmsUserStateFromSeeds(
285+
rpc: Parameters<typeof fetchEncodedAccount>[0],
286+
seeds: FarmsUserStateSeeds,
287+
config: FetchAccountConfig & { programAddress?: Address } = {},
288+
): Promise<MaybeAccount<FarmsUserState>> {
289+
const { programAddress, ...fetchConfig } = config;
290+
const [address] = await findFarmsUserStatePda(seeds, { programAddress });
291+
return await fetchMaybeFarmsUserState(rpc, address, fetchConfig);
292+
}

clients/kamino-lending/src/generated/accounts/obligation.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
MaybeEncodedAccount,
2020
ReadonlyUint8Array,
2121
} from "@solana/kit";
22+
import type { ObligationSeeds } from "../pdas/index.js";
2223
import type {
2324
LastUpdate,
2425
LastUpdateArgs,
@@ -52,6 +53,7 @@ import {
5253
getU128Encoder,
5354
transformEncoder,
5455
} from "@solana/kit";
56+
import { findObligationPda } from "../pdas/index.js";
5557
import {
5658
getLastUpdateDecoder,
5759
getLastUpdateEncoder,
@@ -259,3 +261,23 @@ export async function fetchAllMaybeObligation(
259261
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
260262
return maybeAccounts.map((maybeAccount) => decodeObligation(maybeAccount));
261263
}
264+
265+
export async function fetchObligationFromSeeds(
266+
rpc: Parameters<typeof fetchEncodedAccount>[0],
267+
seeds: ObligationSeeds,
268+
config: FetchAccountConfig & { programAddress?: Address } = {},
269+
): Promise<Account<Obligation>> {
270+
const maybeAccount = await fetchMaybeObligationFromSeeds(rpc, seeds, config);
271+
assertAccountExists(maybeAccount);
272+
return maybeAccount;
273+
}
274+
275+
export async function fetchMaybeObligationFromSeeds(
276+
rpc: Parameters<typeof fetchEncodedAccount>[0],
277+
seeds: ObligationSeeds,
278+
config: FetchAccountConfig & { programAddress?: Address } = {},
279+
): Promise<MaybeAccount<Obligation>> {
280+
const { programAddress, ...fetchConfig } = config;
281+
const [address] = await findObligationPda(seeds, { programAddress });
282+
return await fetchMaybeObligation(rpc, address, fetchConfig);
283+
}

clients/kamino-lending/src/generated/accounts/referrerState.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
MaybeEncodedAccount,
2020
ReadonlyUint8Array,
2121
} from "@solana/kit";
22+
import type { ReferrerStateSeeds } from "../pdas/index.js";
2223
import {
2324
assertAccountExists,
2425
assertAccountsExist,
@@ -36,6 +37,7 @@ import {
3637
getStructEncoder,
3738
transformEncoder,
3839
} from "@solana/kit";
40+
import { findReferrerStatePda } from "../pdas/index.js";
3941

4042
export const REFERRER_STATE_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
4143
194, 81, 217, 103, 12, 19, 12, 66,
@@ -140,3 +142,27 @@ export async function fetchAllMaybeReferrerState(
140142
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
141143
return maybeAccounts.map((maybeAccount) => decodeReferrerState(maybeAccount));
142144
}
145+
146+
export async function fetchReferrerStateFromSeeds(
147+
rpc: Parameters<typeof fetchEncodedAccount>[0],
148+
seeds: ReferrerStateSeeds,
149+
config: FetchAccountConfig & { programAddress?: Address } = {},
150+
): Promise<Account<ReferrerState>> {
151+
const maybeAccount = await fetchMaybeReferrerStateFromSeeds(
152+
rpc,
153+
seeds,
154+
config,
155+
);
156+
assertAccountExists(maybeAccount);
157+
return maybeAccount;
158+
}
159+
160+
export async function fetchMaybeReferrerStateFromSeeds(
161+
rpc: Parameters<typeof fetchEncodedAccount>[0],
162+
seeds: ReferrerStateSeeds,
163+
config: FetchAccountConfig & { programAddress?: Address } = {},
164+
): Promise<MaybeAccount<ReferrerState>> {
165+
const { programAddress, ...fetchConfig } = config;
166+
const [address] = await findReferrerStatePda(seeds, { programAddress });
167+
return await fetchMaybeReferrerState(rpc, address, fetchConfig);
168+
}

clients/kamino-lending/src/generated/accounts/referrerTokenState.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import type {
1919
MaybeEncodedAccount,
2020
ReadonlyUint8Array,
2121
} from "@solana/kit";
22+
import type { ReferrerTokenStateSeeds } from "../pdas/index.js";
2223
import {
2324
assertAccountExists,
2425
assertAccountsExist,
@@ -42,6 +43,7 @@ import {
4243
getU128Encoder,
4344
transformEncoder,
4445
} from "@solana/kit";
46+
import { findReferrerTokenStatePda } from "../pdas/index.js";
4547

4648
export const REFERRER_TOKEN_STATE_DISCRIMINATOR: ReadonlyUint8Array =
4749
new Uint8Array([39, 15, 208, 77, 32, 195, 105, 56]);
@@ -173,3 +175,27 @@ export async function fetchAllMaybeReferrerTokenState(
173175
decodeReferrerTokenState(maybeAccount),
174176
);
175177
}
178+
179+
export async function fetchReferrerTokenStateFromSeeds(
180+
rpc: Parameters<typeof fetchEncodedAccount>[0],
181+
seeds: ReferrerTokenStateSeeds,
182+
config: FetchAccountConfig & { programAddress?: Address } = {},
183+
): Promise<Account<ReferrerTokenState>> {
184+
const maybeAccount = await fetchMaybeReferrerTokenStateFromSeeds(
185+
rpc,
186+
seeds,
187+
config,
188+
);
189+
assertAccountExists(maybeAccount);
190+
return maybeAccount;
191+
}
192+
193+
export async function fetchMaybeReferrerTokenStateFromSeeds(
194+
rpc: Parameters<typeof fetchEncodedAccount>[0],
195+
seeds: ReferrerTokenStateSeeds,
196+
config: FetchAccountConfig & { programAddress?: Address } = {},
197+
): Promise<MaybeAccount<ReferrerTokenState>> {
198+
const { programAddress, ...fetchConfig } = config;
199+
const [address] = await findReferrerTokenStatePda(seeds, { programAddress });
200+
return await fetchMaybeReferrerTokenState(rpc, address, fetchConfig);
201+
}

0 commit comments

Comments
 (0)