Skip to content

Commit b3fe3d4

Browse files
feat(staking): add reassign/opt out publisher rewards (#1916)
* go * feat: add opt out * go * go
1 parent faf2a1b commit b3fe3d4

File tree

9 files changed

+133
-29
lines changed

9 files changed

+133
-29
lines changed

apps/staking/src/api.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -430,20 +430,24 @@ export const unstakeIntegrityStaking = async (
430430
};
431431

432432
export const reassignPublisherAccount = async (
433-
_client: PythStakingClient,
434-
_stakeAccount: PublicKey,
435-
_targetAccount: PublicKey,
433+
client: PythStakingClient,
434+
stakeAccount: PublicKey,
435+
targetAccount: PublicKey,
436+
publisherKey: PublicKey,
436437
): Promise<void> => {
437-
await new Promise((resolve) => setTimeout(resolve, MOCK_DELAY));
438-
throw new NotImplementedError();
438+
return client.reassignPublisherStakeAccount(
439+
publisherKey,
440+
stakeAccount,
441+
targetAccount,
442+
);
439443
};
440444

441445
export const optPublisherOut = async (
442-
_client: PythStakingClient,
443-
_stakeAccount: PublicKey,
446+
client: PythStakingClient,
447+
stakeAccount: PublicKey,
448+
publisherKey: PublicKey,
444449
): Promise<void> => {
445-
await new Promise((resolve) => setTimeout(resolve, MOCK_DELAY));
446-
throw new NotImplementedError();
450+
await client.removePublisherStakeAccount(stakeAccount, publisherKey);
447451
};
448452

449453
const MOCK_DELAY = 500;
@@ -486,10 +490,3 @@ const mkMockHistory = (): AccountHistory => [
486490
locked: 0n,
487491
},
488492
];
489-
490-
class NotImplementedError extends Error {
491-
constructor() {
492-
super("Not yet implemented!");
493-
this.name = "NotImplementedError";
494-
}
495-
}

apps/staking/src/components/OracleIntegrityStaking/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ const ReassignStakeAccountButton = ({
211211
{({ close }) => (
212212
<ReassignStakeAccountForm
213213
api={api}
214+
publisherPubkey={self.publicKey}
214215
close={close}
215216
setCloseDisabled={setCloseDisabled}
216217
/>
@@ -223,12 +224,14 @@ const ReassignStakeAccountButton = ({
223224

224225
type ReassignStakeAccountFormProps = {
225226
api: States[ApiStateType.Loaded];
227+
publisherPubkey: PublicKey;
226228
close: () => void;
227229
setCloseDisabled: (value: boolean) => void;
228230
};
229231

230232
const ReassignStakeAccountForm = ({
231233
api,
234+
publisherPubkey,
232235
close,
233236
setCloseDisabled,
234237
}: ReassignStakeAccountFormProps) => {
@@ -246,8 +249,8 @@ const ReassignStakeAccountForm = ({
246249
() =>
247250
key === undefined
248251
? Promise.reject(new InvalidKeyError())
249-
: api.reassignPublisherAccount(key),
250-
[api, key],
252+
: api.reassignPublisherAccount(key, publisherPubkey),
253+
[api, key, publisherPubkey],
251254
);
252255

253256
const { state, execute } = useAsync(doReassign);
@@ -332,7 +335,9 @@ type OptOutButtonProps = {
332335
};
333336

334337
const OptOutButton = ({ api, self }: OptOutButtonProps) => {
335-
const { state, execute } = useAsync(api.optPublisherOut);
338+
const { state, execute } = useAsync(() =>
339+
api.optPublisherOut(self.publicKey),
340+
);
336341

337342
const doOptOut = useCallback(() => {
338343
execute().catch(() => {

governance/pyth_staking_sdk/idl/integrity-pool.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@
206206
"address": "11111111111111111111111111111111"
207207
}
208208
],
209-
"args": []
209+
"args": [],
210+
"returns": "u64"
210211
},
211212
{
212213
"name": "create_slash_event",
@@ -223,7 +224,8 @@
223224
"relations": ["pool_config"]
224225
},
225226
{
226-
"name": "slash_custody"
227+
"name": "slash_custody",
228+
"relations": ["pool_config"]
227229
},
228230
{
229231
"name": "pool_data",
@@ -448,6 +450,9 @@
448450
]
449451
}
450452
},
453+
{
454+
"name": "slash_custody"
455+
},
451456
{
452457
"name": "system_program",
453458
"address": "11111111111111111111111111111111"
@@ -608,7 +613,8 @@
608613
}
609614
},
610615
{
611-
"name": "new_stake_account_positions"
616+
"name": "new_stake_account_positions_option",
617+
"optional": true
612618
},
613619
{
614620
"name": "current_stake_account_positions_option",
@@ -1083,7 +1089,7 @@
10831089
},
10841090
{
10851091
"code": 6001,
1086-
"name": "PublisherNeedsToSign"
1092+
"name": "PublisherOrRewardAuthorityNeedsToSign"
10871093
},
10881094
{
10891095
"code": 6002,
@@ -1178,6 +1184,10 @@
11781184
"code": 6023,
11791185
"name": "InvalidY",
11801186
"msg": "Y should not be greater than 1%"
1187+
},
1188+
{
1189+
"code": 6024,
1190+
"name": "InvalidSlashCustodyAccount"
11811191
}
11821192
],
11831193
"types": [
@@ -1343,6 +1353,10 @@
13431353
{
13441354
"name": "y",
13451355
"type": "u64"
1356+
},
1357+
{
1358+
"name": "slash_custody",
1359+
"type": "pubkey"
13461360
}
13471361
]
13481362
}

governance/pyth_staking_sdk/idl/publisher-caps.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@
77
"description": "Created with Anchor"
88
},
99
"instructions": [
10+
{
11+
"name": "close_publisher_caps",
12+
"discriminator": [36, 234, 184, 214, 76, 203, 153, 144],
13+
"accounts": [
14+
{
15+
"name": "write_authority",
16+
"signer": true,
17+
"relations": ["publisher_caps"]
18+
},
19+
{
20+
"name": "publisher_caps",
21+
"writable": true
22+
}
23+
],
24+
"args": []
25+
},
1026
{
1127
"name": "init_publisher_caps",
1228
"discriminator": [193, 208, 32, 97, 144, 247, 246, 168],

governance/pyth_staking_sdk/idl/staking.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"address": "pytS9TjG1qyAZypk7n8rw8gfW9sUaqqYyMhJQ4E7JCQ",
33
"metadata": {
44
"name": "staking",
5-
"version": "1.2.0",
5+
"version": "2.0.0",
66
"spec": "0.1.0",
77
"description": "Created with Anchor"
88
},
@@ -1975,7 +1975,7 @@
19751975
"type": "u8"
19761976
},
19771977
{
1978-
"name": "transfer_epoch",
1978+
"name": "_deprecated",
19791979
"type": {
19801980
"option": "u64"
19811981
}

governance/pyth_staking_sdk/src/pyth-staking-client.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export class PythStakingClient {
183183
.initializePool(rewardProgramAuthority, yAnchor)
184184
.accounts({
185185
poolData,
186+
slashCustody: getStakeAccountCustodyAddress(poolData),
186187
})
187188
.instruction();
188189

@@ -642,4 +643,45 @@ export class PythStakingClient {
642643
lowestEpoch === undefined ? undefined : epochToDate(lowestEpoch + 52n),
643644
};
644645
}
646+
647+
async setPublisherStakeAccount(
648+
publisher: PublicKey,
649+
stakeAccountPositions: PublicKey,
650+
newStakeAccountPositions: PublicKey | undefined,
651+
) {
652+
const instruction = await this.integrityPoolProgram.methods
653+
.setPublisherStakeAccount()
654+
.accounts({
655+
currentStakeAccountPositionsOption: stakeAccountPositions,
656+
newStakeAccountPositionsOption: newStakeAccountPositions ?? null,
657+
publisher,
658+
})
659+
.instruction();
660+
661+
await sendTransaction([instruction], this.connection, this.wallet);
662+
return;
663+
}
664+
665+
public async reassignPublisherStakeAccount(
666+
publisher: PublicKey,
667+
stakeAccountPositions: PublicKey,
668+
newStakeAccountPositions: PublicKey,
669+
) {
670+
return this.setPublisherStakeAccount(
671+
publisher,
672+
stakeAccountPositions,
673+
newStakeAccountPositions,
674+
);
675+
}
676+
677+
public async removePublisherStakeAccount(
678+
publisher: PublicKey,
679+
stakeAccountPositions: PublicKey,
680+
) {
681+
return this.setPublisherStakeAccount(
682+
publisher,
683+
stakeAccountPositions,
684+
undefined,
685+
);
686+
}
645687
}

governance/pyth_staking_sdk/types/integrity-pool.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ export type IntegrityPool = {
344344
},
345345
];
346346
args: [];
347+
returns: "u64";
347348
},
348349
{
349350
name: "createSlashEvent";
@@ -361,6 +362,7 @@ export type IntegrityPool = {
361362
},
362363
{
363364
name: "slashCustody";
365+
relations: ["poolConfig"];
364366
},
365367
{
366368
name: "poolData";
@@ -620,6 +622,9 @@ export type IntegrityPool = {
620622
];
621623
};
622624
},
625+
{
626+
name: "slashCustody";
627+
},
623628
{
624629
name: "systemProgram";
625630
address: "11111111111111111111111111111111";
@@ -803,7 +808,8 @@ export type IntegrityPool = {
803808
};
804809
},
805810
{
806-
name: "newStakeAccountPositions";
811+
name: "newStakeAccountPositionsOption";
812+
optional: true;
807813
},
808814
{
809815
name: "currentStakeAccountPositionsOption";
@@ -1363,7 +1369,7 @@ export type IntegrityPool = {
13631369
},
13641370
{
13651371
code: 6001;
1366-
name: "publisherNeedsToSign";
1372+
name: "publisherOrRewardAuthorityNeedsToSign";
13671373
},
13681374
{
13691375
code: 6002;
@@ -1459,6 +1465,10 @@ export type IntegrityPool = {
14591465
name: "invalidY";
14601466
msg: "Y should not be greater than 1%";
14611467
},
1468+
{
1469+
code: 6024;
1470+
name: "invalidSlashCustodyAccount";
1471+
},
14621472
];
14631473
types: [
14641474
{
@@ -1624,6 +1634,10 @@ export type IntegrityPool = {
16241634
name: "y";
16251635
type: "u64";
16261636
},
1637+
{
1638+
name: "slashCustody";
1639+
type: "pubkey";
1640+
},
16271641
];
16281642
};
16291643
},

governance/pyth_staking_sdk/types/publisher-caps.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ export type PublisherCaps = {
1313
description: "Created with Anchor";
1414
};
1515
instructions: [
16+
{
17+
name: "closePublisherCaps";
18+
discriminator: [36, 234, 184, 214, 76, 203, 153, 144];
19+
accounts: [
20+
{
21+
name: "writeAuthority";
22+
signer: true;
23+
relations: ["publisherCaps"];
24+
},
25+
{
26+
name: "publisherCaps";
27+
writable: true;
28+
},
29+
];
30+
args: [];
31+
},
1632
{
1733
name: "initPublisherCaps";
1834
discriminator: [193, 208, 32, 97, 144, 247, 246, 168];

governance/pyth_staking_sdk/types/staking.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type Staking = {
88
address: "pytS9TjG1qyAZypk7n8rw8gfW9sUaqqYyMhJQ4E7JCQ";
99
metadata: {
1010
name: "staking";
11-
version: "1.2.0";
11+
version: "2.0.0";
1212
spec: "0.1.0";
1313
description: "Created with Anchor";
1414
};
@@ -2184,7 +2184,7 @@ export type Staking = {
21842184
type: "u8";
21852185
},
21862186
{
2187-
name: "transferEpoch";
2187+
name: "deprecated";
21882188
type: {
21892189
option: "u64";
21902190
};

0 commit comments

Comments
 (0)