Skip to content

Commit 26aaabc

Browse files
authored
Merge pull request #39 from macalinao/igm/quarry-updates
Add more defaults to Quarry
2 parents 5f5fb17 + 39617d1 commit 26aaabc

Some content is hidden

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

51 files changed

+2855
-142
lines changed

.changeset/small-geckos-brake.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@macalinao/coda-visitors": patch
3+
"@macalinao/clients-quarry": patch
4+
---
5+
6+
Add more defaults to Quarry client

clients/quarry/coda.config.mjs

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import {
2+
accountValueNode,
23
addPdasVisitor,
4+
associatedTokenAccountValueNode,
35
constantPdaSeedNodeFromString,
46
defineConfig,
7+
pdaLinkNode,
8+
pdaSeedValueNode,
9+
pdaValueNode,
510
publicKeyTypeNode,
11+
setInstructionAccountDefaultValuesVisitor,
12+
updateAccountsVisitor,
613
variablePdaSeedNode,
714
} from "@macalinao/coda";
815
import { renameVisitor } from "@macalinao/codama-rename-visitor";
@@ -14,17 +21,64 @@ export default defineConfig({
1421
},
1522

1623
visitors: [
24+
updateAccountsVisitor({
25+
// quarryMine accounts
26+
rewarder: {
27+
pda: pdaLinkNode("rewarder"),
28+
},
29+
quarry: {
30+
pda: pdaLinkNode("quarry"),
31+
},
32+
miner: {
33+
pda: pdaLinkNode("miner"),
34+
},
35+
36+
// quarryMergeMine accounts
37+
mergePool: {
38+
pda: pdaLinkNode("mergePool"),
39+
},
40+
mergeMiner: {
41+
pda: pdaLinkNode("mergeMiner"),
42+
},
43+
44+
// quarryMintWrapper accounts
45+
mintWrapper: {
46+
pda: pdaLinkNode("mintWrapper"),
47+
},
48+
minter: {
49+
pda: pdaLinkNode("minter"),
50+
},
51+
52+
// quarryOperator accounts
53+
operator: {
54+
pda: pdaLinkNode("operator"),
55+
},
56+
57+
// quarryRedeemer accounts
58+
redeemer: {
59+
pda: pdaLinkNode("redeemer"),
60+
},
61+
62+
// quarryRegistry accounts
63+
registry: {
64+
pda: pdaLinkNode("registry"),
65+
},
66+
}),
1767
addPdasVisitor({
1868
quarryMine: [
1969
{
2070
name: "rewarder",
71+
docs: [
72+
"Rewarder account that manages reward distribution for quarries",
73+
],
2174
seeds: [
2275
constantPdaSeedNodeFromString("utf8", "Rewarder"),
2376
variablePdaSeedNode("base", publicKeyTypeNode()),
2477
],
2578
},
2679
{
2780
name: "quarry",
81+
docs: ["Individual quarry (staking pool) for a specific token mint"],
2882
seeds: [
2983
constantPdaSeedNodeFromString("utf8", "Quarry"),
3084
variablePdaSeedNode("rewarder", publicKeyTypeNode()),
@@ -33,6 +87,9 @@ export default defineConfig({
3387
},
3488
{
3589
name: "miner",
90+
docs: [
91+
"Miner account representing a user's staking position in a quarry",
92+
],
3693
seeds: [
3794
constantPdaSeedNodeFromString("utf8", "Miner"),
3895
variablePdaSeedNode("quarry", publicKeyTypeNode()),
@@ -43,20 +100,25 @@ export default defineConfig({
43100
quarryMergeMine: [
44101
{
45102
name: "mergePool",
103+
docs: [
104+
"Merge pool that allows staking multiple quarry rewards as one",
105+
],
46106
seeds: [
47107
constantPdaSeedNodeFromString("utf8", "MergePool"),
48108
variablePdaSeedNode("primaryMint", publicKeyTypeNode()),
49109
],
50110
},
51111
{
52112
name: "replicaMint",
113+
docs: ["Replica mint token for the merge pool"],
53114
seeds: [
54115
constantPdaSeedNodeFromString("utf8", "ReplicaMint"),
55116
variablePdaSeedNode("pool", publicKeyTypeNode()),
56117
],
57118
},
58119
{
59120
name: "mergeMiner",
121+
docs: ["Merge miner account for a user in a merge pool"],
60122
seeds: [
61123
constantPdaSeedNodeFromString("utf8", "MergeMiner"),
62124
variablePdaSeedNode("pool", publicKeyTypeNode()),
@@ -67,13 +129,15 @@ export default defineConfig({
67129
quarryMintWrapper: [
68130
{
69131
name: "mintWrapper",
132+
docs: ["Mint wrapper that controls minting of wrapped tokens"],
70133
seeds: [
71134
constantPdaSeedNodeFromString("utf8", "MintWrapper"),
72135
variablePdaSeedNode("base", publicKeyTypeNode()),
73136
],
74137
},
75138
{
76139
name: "minter",
140+
docs: ["Minter authority for a specific mint wrapper"],
77141
seeds: [
78142
constantPdaSeedNodeFromString("utf8", "MintWrapperMinter"),
79143
variablePdaSeedNode("wrapper", publicKeyTypeNode()),
@@ -84,6 +148,9 @@ export default defineConfig({
84148
quarryOperator: [
85149
{
86150
name: "operator",
151+
docs: [
152+
"Operator account with delegated authority to manage quarries",
153+
],
87154
seeds: [
88155
constantPdaSeedNodeFromString("utf8", "Operator"),
89156
variablePdaSeedNode("base", publicKeyTypeNode()),
@@ -93,6 +160,9 @@ export default defineConfig({
93160
quarryRedeemer: [
94161
{
95162
name: "redeemer",
163+
docs: [
164+
"Redeemer account for exchanging IOU tokens for redemption tokens",
165+
],
96166
seeds: [
97167
constantPdaSeedNodeFromString("utf8", "Redeemer"),
98168
variablePdaSeedNode("iouMint", publicKeyTypeNode()),
@@ -103,6 +173,7 @@ export default defineConfig({
103173
quarryRegistry: [
104174
{
105175
name: "registry",
176+
docs: ["Registry tracking all quarries for a rewarder"],
106177
seeds: [
107178
constantPdaSeedNodeFromString("utf8", "QuarryRegistry"),
108179
variablePdaSeedNode("rewarder", publicKeyTypeNode()),
@@ -125,5 +196,178 @@ export default defineConfig({
125196
},
126197
},
127198
}),
199+
setInstructionAccountDefaultValuesVisitor([
200+
// Operator
201+
{
202+
account: "operator",
203+
instruction: "createOperator",
204+
defaultValue: pdaValueNode(pdaLinkNode("operator"), [
205+
pdaSeedValueNode("base", accountValueNode("base")),
206+
]),
207+
},
208+
{
209+
account: "operator",
210+
instruction: "createOperatorV2",
211+
defaultValue: pdaValueNode(pdaLinkNode("operator"), [
212+
pdaSeedValueNode("base", accountValueNode("base")),
213+
]),
214+
},
215+
216+
...[
217+
"delegateCreateQuarry",
218+
"delegateCreateQuarryV2",
219+
"createQuarry",
220+
"createQuarryV2",
221+
].map((instruction) => ({
222+
account: "quarry",
223+
instruction,
224+
defaultValue: pdaValueNode(pdaLinkNode("quarry"), [
225+
pdaSeedValueNode("rewarder", accountValueNode("rewarder")),
226+
pdaSeedValueNode("tokenMint", accountValueNode("tokenMint")),
227+
]),
228+
})),
229+
230+
...[
231+
"createMiner",
232+
"createMinerV2",
233+
"claimRewards",
234+
"claimRewardsV2",
235+
"withdrawTokens",
236+
"stakeTokens",
237+
].map((instruction) => ({
238+
account: "miner",
239+
instruction,
240+
defaultValue: pdaValueNode(pdaLinkNode("miner"), [
241+
pdaSeedValueNode("quarry", accountValueNode("quarry")),
242+
pdaSeedValueNode("authority", accountValueNode("authority")),
243+
]),
244+
})),
245+
246+
...["claimRewardsMM", "claimRewards", "claimRewardsV2"].flatMap(
247+
(instruction) => [
248+
{
249+
account: "minter",
250+
instruction,
251+
defaultValue: pdaValueNode(pdaLinkNode("minter"), [
252+
pdaSeedValueNode("wrapper", accountValueNode("mintWrapper")),
253+
pdaSeedValueNode("authority", accountValueNode("rewarder")),
254+
]),
255+
},
256+
{
257+
account: "claimFeeTokenAccount",
258+
instruction,
259+
defaultValue: associatedTokenAccountValueNode({
260+
owner: accountValueNode("rewarder"),
261+
mint: accountValueNode("rewardsTokenMint"),
262+
}),
263+
},
264+
],
265+
),
266+
267+
...["claimRewardsMM", "stakePrimaryMiner", "stakeReplicaMiner"].map(
268+
(instruction) => ({
269+
account: "miner",
270+
instruction,
271+
defaultValue: pdaValueNode(pdaLinkNode("miner"), [
272+
pdaSeedValueNode("quarry", accountValueNode("quarry")),
273+
pdaSeedValueNode("authority", accountValueNode("mm")),
274+
]),
275+
}),
276+
),
277+
278+
...["newRewarder", "newRewarderV2"].flatMap((instruction) => [
279+
{
280+
account: "rewarder",
281+
instruction,
282+
defaultValue: pdaValueNode(pdaLinkNode("rewarder"), [
283+
pdaSeedValueNode("base", accountValueNode("base")),
284+
]),
285+
},
286+
{
287+
account: "initialAuthority",
288+
instruction,
289+
defaultValue: accountValueNode("payer"),
290+
},
291+
]),
292+
293+
...["stakePrimaryMiner", "stakeReplicaMiner"].flatMap((instruction) => [
294+
{
295+
account: "mm",
296+
instruction,
297+
defaultValue: pdaValueNode(pdaLinkNode("mergeMiner"), [
298+
pdaSeedValueNode("pool", accountValueNode("pool")),
299+
pdaSeedValueNode("owner", accountValueNode("mmOwner")),
300+
]),
301+
},
302+
]),
303+
...["withdrawTokensMM", "initMergeMiner", "initMergeMinerV2"].flatMap(
304+
(instruction) => [
305+
{
306+
account: "mm",
307+
instruction,
308+
defaultValue: pdaValueNode(pdaLinkNode("mergeMiner"), [
309+
pdaSeedValueNode("pool", accountValueNode("pool")),
310+
pdaSeedValueNode("owner", accountValueNode("owner")),
311+
]),
312+
},
313+
],
314+
),
315+
316+
{
317+
account: "iouSource",
318+
defaultValue: associatedTokenAccountValueNode({
319+
owner: accountValueNode("sourceAuthority"),
320+
mint: accountValueNode("iouMint"),
321+
}),
322+
},
323+
{
324+
account: "mmTokenAccount",
325+
defaultValue: associatedTokenAccountValueNode({
326+
owner: accountValueNode("mm"),
327+
mint: accountValueNode("withdrawMint"),
328+
}),
329+
},
330+
{
331+
account: "rewardsTokenAccount",
332+
defaultValue: associatedTokenAccountValueNode({
333+
owner: accountValueNode("mm"),
334+
mint: accountValueNode("rewardsTokenMint"),
335+
}),
336+
},
337+
338+
...["newWrapper", "newWrapperV2"].flatMap((instruction) => [
339+
{
340+
account: "mintWrapper",
341+
instruction,
342+
defaultValue: pdaValueNode(pdaLinkNode("mintWrapper"), [
343+
pdaSeedValueNode("base", accountValueNode("base")),
344+
]),
345+
},
346+
{
347+
account: "admin",
348+
instruction,
349+
defaultValue: accountValueNode("payer"),
350+
},
351+
]),
352+
353+
...["newMinter", "newMinterV2"].flatMap((instruction) => [
354+
{
355+
account: "minter",
356+
instruction,
357+
defaultValue: pdaValueNode(pdaLinkNode("minter"), [
358+
pdaSeedValueNode("wrapper", accountValueNode("mintWrapper")),
359+
pdaSeedValueNode(
360+
"authority",
361+
accountValueNode("newMinterAuthority"),
362+
),
363+
]),
364+
},
365+
{
366+
account: "newMinterAuthority",
367+
instruction,
368+
defaultValue: accountValueNode("payer"),
369+
},
370+
]),
371+
]),
128372
],
129373
});

clients/quarry/src/generated/accounts/mergeMiner.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 { MergeMinerSeeds } from "../pdas/index.js";
2223
import {
2324
assertAccountExists,
2425
assertAccountsExist,
@@ -40,6 +41,7 @@ import {
4041
getU64Encoder,
4142
transformEncoder,
4243
} from "@solana/kit";
44+
import { findMergeMinerPda } from "../pdas/index.js";
4345

4446
export const MERGE_MINER_DISCRIMINATOR: ReadonlyUint8Array = new Uint8Array([
4547
243, 97, 253, 80, 19, 210, 148, 120,
@@ -154,3 +156,23 @@ export async function fetchAllMaybeMergeMiner(
154156
const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
155157
return maybeAccounts.map((maybeAccount) => decodeMergeMiner(maybeAccount));
156158
}
159+
160+
export async function fetchMergeMinerFromSeeds(
161+
rpc: Parameters<typeof fetchEncodedAccount>[0],
162+
seeds: MergeMinerSeeds,
163+
config: FetchAccountConfig & { programAddress?: Address } = {},
164+
): Promise<Account<MergeMiner>> {
165+
const maybeAccount = await fetchMaybeMergeMinerFromSeeds(rpc, seeds, config);
166+
assertAccountExists(maybeAccount);
167+
return maybeAccount;
168+
}
169+
170+
export async function fetchMaybeMergeMinerFromSeeds(
171+
rpc: Parameters<typeof fetchEncodedAccount>[0],
172+
seeds: MergeMinerSeeds,
173+
config: FetchAccountConfig & { programAddress?: Address } = {},
174+
): Promise<MaybeAccount<MergeMiner>> {
175+
const { programAddress, ...fetchConfig } = config;
176+
const [address] = await findMergeMinerPda(seeds, { programAddress });
177+
return await fetchMaybeMergeMiner(rpc, address, fetchConfig);
178+
}

0 commit comments

Comments
 (0)