From 2b7c7c8068d6f18313b8657333df70c602b8ef68 Mon Sep 17 00:00:00 2001 From: keyvan Date: Fri, 13 Sep 2024 10:05:30 -0700 Subject: [PATCH 1/4] go --- apps/staking/src/api.ts | 14 +++++++++----- .../components/OracleIntegrityStaking/index.tsx | 7 +++++-- .../pyth_staking_sdk/src/pyth-staking-client.ts | 17 +++++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/apps/staking/src/api.ts b/apps/staking/src/api.ts index 7cb320071..384ef3d57 100644 --- a/apps/staking/src/api.ts +++ b/apps/staking/src/api.ts @@ -435,12 +435,16 @@ export const unstakeIntegrityStaking = async ( }; export const reassignPublisherAccount = async ( - _client: PythStakingClient, - _stakeAccount: PublicKey, - _targetAccount: PublicKey, + client: PythStakingClient, + stakeAccount: PublicKey, + targetAccount: PublicKey, + publisherKey: PublicKey, ): Promise => { - await new Promise((resolve) => setTimeout(resolve, MOCK_DELAY)); - throw new NotImplementedError(); + return client.setPublisherStakeAccount( + publisherKey, + stakeAccount, + targetAccount, + ); }; export const optPublisherOut = async ( diff --git a/apps/staking/src/components/OracleIntegrityStaking/index.tsx b/apps/staking/src/components/OracleIntegrityStaking/index.tsx index 9386848d9..0b882bd61 100644 --- a/apps/staking/src/components/OracleIntegrityStaking/index.tsx +++ b/apps/staking/src/components/OracleIntegrityStaking/index.tsx @@ -211,6 +211,7 @@ const ReassignStakeAccountButton = ({ {({ close }) => ( @@ -223,12 +224,14 @@ const ReassignStakeAccountButton = ({ type ReassignStakeAccountFormProps = { api: States[ApiStateType.Loaded]; + publisherPubkey: PublicKey; close: () => void; setCloseDisabled: (value: boolean) => void; }; const ReassignStakeAccountForm = ({ api, + publisherPubkey, close, setCloseDisabled, }: ReassignStakeAccountFormProps) => { @@ -246,8 +249,8 @@ const ReassignStakeAccountForm = ({ () => key === undefined ? Promise.reject(new InvalidKeyError()) - : api.reassignPublisherAccount(key), - [api, key], + : api.reassignPublisherAccount(key, publisherPubkey), + [api, key, publisherPubkey], ); const { state, execute } = useAsync(doReassign); diff --git a/governance/pyth_staking_sdk/src/pyth-staking-client.ts b/governance/pyth_staking_sdk/src/pyth-staking-client.ts index c353892bc..74482e716 100644 --- a/governance/pyth_staking_sdk/src/pyth-staking-client.ts +++ b/governance/pyth_staking_sdk/src/pyth-staking-client.ts @@ -611,4 +611,21 @@ export class PythStakingClient { } return totalRewards; } + + public async setPublisherStakeAccount( + publisher: PublicKey, + stakeAccountPositions: PublicKey, + newStakeAccountPositions: PublicKey, + ) { + const instruction = await this.integrityPoolProgram.methods + .setPublisherStakeAccount() + .accounts({ + currentStakeAccountPositionsOption: stakeAccountPositions, + newStakeAccountPositions, + publisher, + }).instruction(); + + await sendTransaction([instruction], this.connection, this.wallet); + return; + } } From 00fe6972f64169c21113f8fc3981fb5c135143da Mon Sep 17 00:00:00 2001 From: keyvan Date: Fri, 13 Sep 2024 10:35:39 -0700 Subject: [PATCH 2/4] feat: add opt out --- apps/staking/src/api.ts | 8 +++---- .../OracleIntegrityStaking/index.tsx | 4 +++- .../pyth_staking_sdk/idl/integrity-pool.json | 22 +++++++++++++++---- .../pyth_staking_sdk/idl/publisher-caps.json | 16 ++++++++++++++ governance/pyth_staking_sdk/idl/staking.json | 4 ++-- .../src/pyth-staking-client.ts | 8 ++++--- .../pyth_staking_sdk/types/integrity-pool.ts | 18 +++++++++++++-- .../pyth_staking_sdk/types/publisher-caps.ts | 16 ++++++++++++++ governance/pyth_staking_sdk/types/staking.ts | 4 ++-- 9 files changed, 82 insertions(+), 18 deletions(-) diff --git a/apps/staking/src/api.ts b/apps/staking/src/api.ts index 384ef3d57..f27cad3b4 100644 --- a/apps/staking/src/api.ts +++ b/apps/staking/src/api.ts @@ -448,11 +448,11 @@ export const reassignPublisherAccount = async ( }; export const optPublisherOut = async ( - _client: PythStakingClient, - _stakeAccount: PublicKey, + client: PythStakingClient, + stakeAccount: PublicKey, + publisherKey: PublicKey, ): Promise => { - await new Promise((resolve) => setTimeout(resolve, MOCK_DELAY)); - throw new NotImplementedError(); + await client.setPublisherStakeAccount(publisherKey, stakeAccount, undefined); }; const MOCK_DELAY = 500; diff --git a/apps/staking/src/components/OracleIntegrityStaking/index.tsx b/apps/staking/src/components/OracleIntegrityStaking/index.tsx index 0b882bd61..e995654d4 100644 --- a/apps/staking/src/components/OracleIntegrityStaking/index.tsx +++ b/apps/staking/src/components/OracleIntegrityStaking/index.tsx @@ -335,7 +335,9 @@ type OptOutButtonProps = { }; const OptOutButton = ({ api, self }: OptOutButtonProps) => { - const { state, execute } = useAsync(api.optPublisherOut); + const { state, execute } = useAsync(() => + api.optPublisherOut(self.publicKey), + ); const doOptOut = useCallback(() => { execute().catch(() => { diff --git a/governance/pyth_staking_sdk/idl/integrity-pool.json b/governance/pyth_staking_sdk/idl/integrity-pool.json index c568341b3..a2351f572 100644 --- a/governance/pyth_staking_sdk/idl/integrity-pool.json +++ b/governance/pyth_staking_sdk/idl/integrity-pool.json @@ -206,7 +206,8 @@ "address": "11111111111111111111111111111111" } ], - "args": [] + "args": [], + "returns": "u64" }, { "name": "create_slash_event", @@ -223,7 +224,8 @@ "relations": ["pool_config"] }, { - "name": "slash_custody" + "name": "slash_custody", + "relations": ["pool_config"] }, { "name": "pool_data", @@ -448,6 +450,9 @@ ] } }, + { + "name": "slash_custody" + }, { "name": "system_program", "address": "11111111111111111111111111111111" @@ -608,7 +613,8 @@ } }, { - "name": "new_stake_account_positions" + "name": "new_stake_account_positions_option", + "optional": true }, { "name": "current_stake_account_positions_option", @@ -1083,7 +1089,7 @@ }, { "code": 6001, - "name": "PublisherNeedsToSign" + "name": "PublisherOrRewardAuthorityNeedsToSign" }, { "code": 6002, @@ -1178,6 +1184,10 @@ "code": 6023, "name": "InvalidY", "msg": "Y should not be greater than 1%" + }, + { + "code": 6024, + "name": "InvalidSlashCustodyAccount" } ], "types": [ @@ -1343,6 +1353,10 @@ { "name": "y", "type": "u64" + }, + { + "name": "slash_custody", + "type": "pubkey" } ] } diff --git a/governance/pyth_staking_sdk/idl/publisher-caps.json b/governance/pyth_staking_sdk/idl/publisher-caps.json index da48bf558..65b541fe7 100644 --- a/governance/pyth_staking_sdk/idl/publisher-caps.json +++ b/governance/pyth_staking_sdk/idl/publisher-caps.json @@ -7,6 +7,22 @@ "description": "Created with Anchor" }, "instructions": [ + { + "name": "close_publisher_caps", + "discriminator": [36, 234, 184, 214, 76, 203, 153, 144], + "accounts": [ + { + "name": "write_authority", + "signer": true, + "relations": ["publisher_caps"] + }, + { + "name": "publisher_caps", + "writable": true + } + ], + "args": [] + }, { "name": "init_publisher_caps", "discriminator": [193, 208, 32, 97, 144, 247, 246, 168], diff --git a/governance/pyth_staking_sdk/idl/staking.json b/governance/pyth_staking_sdk/idl/staking.json index 1c0ea84e4..3e3cd6764 100644 --- a/governance/pyth_staking_sdk/idl/staking.json +++ b/governance/pyth_staking_sdk/idl/staking.json @@ -2,7 +2,7 @@ "address": "pytS9TjG1qyAZypk7n8rw8gfW9sUaqqYyMhJQ4E7JCQ", "metadata": { "name": "staking", - "version": "1.2.0", + "version": "2.0.0", "spec": "0.1.0", "description": "Created with Anchor" }, @@ -1975,7 +1975,7 @@ "type": "u8" }, { - "name": "transfer_epoch", + "name": "_deprecated", "type": { "option": "u64" } diff --git a/governance/pyth_staking_sdk/src/pyth-staking-client.ts b/governance/pyth_staking_sdk/src/pyth-staking-client.ts index 74482e716..c587cda36 100644 --- a/governance/pyth_staking_sdk/src/pyth-staking-client.ts +++ b/governance/pyth_staking_sdk/src/pyth-staking-client.ts @@ -171,6 +171,7 @@ export class PythStakingClient { .initializePool(rewardProgramAuthority, yAnchor) .accounts({ poolData, + slashCustody: getStakeAccountCustodyAddress(poolData), }) .instruction(); @@ -615,15 +616,16 @@ export class PythStakingClient { public async setPublisherStakeAccount( publisher: PublicKey, stakeAccountPositions: PublicKey, - newStakeAccountPositions: PublicKey, + newStakeAccountPositions: PublicKey | undefined, ) { const instruction = await this.integrityPoolProgram.methods .setPublisherStakeAccount() .accounts({ currentStakeAccountPositionsOption: stakeAccountPositions, - newStakeAccountPositions, + newStakeAccountPositionsOption: newStakeAccountPositions ?? null, publisher, - }).instruction(); + }) + .instruction(); await sendTransaction([instruction], this.connection, this.wallet); return; diff --git a/governance/pyth_staking_sdk/types/integrity-pool.ts b/governance/pyth_staking_sdk/types/integrity-pool.ts index 8d3a96e9c..6b5644609 100644 --- a/governance/pyth_staking_sdk/types/integrity-pool.ts +++ b/governance/pyth_staking_sdk/types/integrity-pool.ts @@ -344,6 +344,7 @@ export type IntegrityPool = { }, ]; args: []; + returns: "u64"; }, { name: "createSlashEvent"; @@ -361,6 +362,7 @@ export type IntegrityPool = { }, { name: "slashCustody"; + relations: ["poolConfig"]; }, { name: "poolData"; @@ -620,6 +622,9 @@ export type IntegrityPool = { ]; }; }, + { + name: "slashCustody"; + }, { name: "systemProgram"; address: "11111111111111111111111111111111"; @@ -803,7 +808,8 @@ export type IntegrityPool = { }; }, { - name: "newStakeAccountPositions"; + name: "newStakeAccountPositionsOption"; + optional: true; }, { name: "currentStakeAccountPositionsOption"; @@ -1363,7 +1369,7 @@ export type IntegrityPool = { }, { code: 6001; - name: "publisherNeedsToSign"; + name: "publisherOrRewardAuthorityNeedsToSign"; }, { code: 6002; @@ -1459,6 +1465,10 @@ export type IntegrityPool = { name: "invalidY"; msg: "Y should not be greater than 1%"; }, + { + code: 6024; + name: "invalidSlashCustodyAccount"; + }, ]; types: [ { @@ -1624,6 +1634,10 @@ export type IntegrityPool = { name: "y"; type: "u64"; }, + { + name: "slashCustody"; + type: "pubkey"; + }, ]; }; }, diff --git a/governance/pyth_staking_sdk/types/publisher-caps.ts b/governance/pyth_staking_sdk/types/publisher-caps.ts index 49fcd98ba..8e64c8349 100644 --- a/governance/pyth_staking_sdk/types/publisher-caps.ts +++ b/governance/pyth_staking_sdk/types/publisher-caps.ts @@ -13,6 +13,22 @@ export type PublisherCaps = { description: "Created with Anchor"; }; instructions: [ + { + name: "closePublisherCaps"; + discriminator: [36, 234, 184, 214, 76, 203, 153, 144]; + accounts: [ + { + name: "writeAuthority"; + signer: true; + relations: ["publisherCaps"]; + }, + { + name: "publisherCaps"; + writable: true; + }, + ]; + args: []; + }, { name: "initPublisherCaps"; discriminator: [193, 208, 32, 97, 144, 247, 246, 168]; diff --git a/governance/pyth_staking_sdk/types/staking.ts b/governance/pyth_staking_sdk/types/staking.ts index 6370355f0..d1493cc46 100644 --- a/governance/pyth_staking_sdk/types/staking.ts +++ b/governance/pyth_staking_sdk/types/staking.ts @@ -8,7 +8,7 @@ export type Staking = { address: "pytS9TjG1qyAZypk7n8rw8gfW9sUaqqYyMhJQ4E7JCQ"; metadata: { name: "staking"; - version: "1.2.0"; + version: "2.0.0"; spec: "0.1.0"; description: "Created with Anchor"; }; @@ -2184,7 +2184,7 @@ export type Staking = { type: "u8"; }, { - name: "transferEpoch"; + name: "deprecated"; type: { option: "u64"; }; From e93943a8a7a2c3b6048f70d4f031bcf15cde971f Mon Sep 17 00:00:00 2001 From: keyvan Date: Fri, 13 Sep 2024 10:36:50 -0700 Subject: [PATCH 3/4] go --- apps/staking/src/api.ts | 7 ------- 1 file changed, 7 deletions(-) diff --git a/apps/staking/src/api.ts b/apps/staking/src/api.ts index 38266ccd5..2ae748775 100644 --- a/apps/staking/src/api.ts +++ b/apps/staking/src/api.ts @@ -490,10 +490,3 @@ const mkMockHistory = (): AccountHistory => [ locked: 0n, }, ]; - -class NotImplementedError extends Error { - constructor() { - super("Not yet implemented!"); - this.name = "NotImplementedError"; - } -} From 69ea428ded627155b7b707d8e47be39d51d5827d Mon Sep 17 00:00:00 2001 From: keyvan Date: Fri, 13 Sep 2024 10:52:09 -0700 Subject: [PATCH 4/4] go --- apps/staking/src/api.ts | 4 +-- .../src/pyth-staking-client.ts | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/apps/staking/src/api.ts b/apps/staking/src/api.ts index 2ae748775..07cd48075 100644 --- a/apps/staking/src/api.ts +++ b/apps/staking/src/api.ts @@ -435,7 +435,7 @@ export const reassignPublisherAccount = async ( targetAccount: PublicKey, publisherKey: PublicKey, ): Promise => { - return client.setPublisherStakeAccount( + return client.reassignPublisherStakeAccount( publisherKey, stakeAccount, targetAccount, @@ -447,7 +447,7 @@ export const optPublisherOut = async ( stakeAccount: PublicKey, publisherKey: PublicKey, ): Promise => { - await client.setPublisherStakeAccount(publisherKey, stakeAccount, undefined); + await client.removePublisherStakeAccount(stakeAccount, publisherKey); }; const MOCK_DELAY = 500; diff --git a/governance/pyth_staking_sdk/src/pyth-staking-client.ts b/governance/pyth_staking_sdk/src/pyth-staking-client.ts index 17a1b8dc4..022beec38 100644 --- a/governance/pyth_staking_sdk/src/pyth-staking-client.ts +++ b/governance/pyth_staking_sdk/src/pyth-staking-client.ts @@ -644,7 +644,7 @@ export class PythStakingClient { }; } - public async setPublisherStakeAccount( + async setPublisherStakeAccount( publisher: PublicKey, stakeAccountPositions: PublicKey, newStakeAccountPositions: PublicKey | undefined, @@ -661,4 +661,27 @@ export class PythStakingClient { await sendTransaction([instruction], this.connection, this.wallet); return; } + + public async reassignPublisherStakeAccount( + publisher: PublicKey, + stakeAccountPositions: PublicKey, + newStakeAccountPositions: PublicKey, + ) { + return this.setPublisherStakeAccount( + publisher, + stakeAccountPositions, + newStakeAccountPositions, + ); + } + + public async removePublisherStakeAccount( + publisher: PublicKey, + stakeAccountPositions: PublicKey, + ) { + return this.setPublisherStakeAccount( + publisher, + stakeAccountPositions, + undefined, + ); + } }