mirror of https://github.com/certusone/oyster.git
Change approve token to allow existing authority and use it to not duplicate keys across the three different voting blcoks
This commit is contained in:
parent
68fb3d85de
commit
7aba9b761c
|
@ -58,10 +58,11 @@ export function approve(
|
||||||
|
|
||||||
// if delegate is not passed ephemeral transfer authority is used
|
// if delegate is not passed ephemeral transfer authority is used
|
||||||
delegate?: PublicKey,
|
delegate?: PublicKey,
|
||||||
|
existingTransferAuthority?: Account,
|
||||||
): Account {
|
): Account {
|
||||||
const tokenProgram = TOKEN_PROGRAM_ID;
|
const tokenProgram = TOKEN_PROGRAM_ID;
|
||||||
|
|
||||||
const transferAuthority = new Account();
|
const transferAuthority = existingTransferAuthority || new Account();
|
||||||
const delegateKey = delegate ?? transferAuthority.publicKey;
|
const delegateKey = delegate ?? transferAuthority.publicKey;
|
||||||
|
|
||||||
const instruction = Token.createApproveInstruction(
|
const instruction = Token.createApproveInstruction(
|
||||||
|
|
|
@ -69,7 +69,7 @@ export const PROGRAM_IDS = [
|
||||||
{
|
{
|
||||||
name: 'testnet',
|
name: 'testnet',
|
||||||
timelock: () => ({
|
timelock: () => ({
|
||||||
programId: new PublicKey('8DevpkpN6CsdczP6rQ64CHraApXFrq96oGm4VjSNCs4q'),
|
programId: new PublicKey('DCVPuhaGNMLh73FRWFroH4o3ERUhBKMRWfBgJV94VqRk'),
|
||||||
}),
|
}),
|
||||||
wormhole: () => ({
|
wormhole: () => ({
|
||||||
pubkey: new PublicKey('5gQf5AUhAgWYgUCt9ouShm9H7dzzXUsLdssYwe5krKhg'),
|
pubkey: new PublicKey('5gQf5AUhAgWYgUCt9ouShm9H7dzzXUsLdssYwe5krKhg'),
|
||||||
|
|
|
@ -93,20 +93,26 @@ export const withdrawVotingTokens = async (
|
||||||
votingTokenAmount,
|
votingTokenAmount,
|
||||||
);
|
);
|
||||||
|
|
||||||
const yesTransferAuthority = approve(
|
approve(
|
||||||
instructions,
|
instructions,
|
||||||
[],
|
[],
|
||||||
existingYesVoteAccount,
|
existingYesVoteAccount,
|
||||||
wallet.publicKey,
|
wallet.publicKey,
|
||||||
votingTokenAmount,
|
votingTokenAmount,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
transferAuthority,
|
||||||
);
|
);
|
||||||
|
|
||||||
const noTransferAuthority = approve(
|
approve(
|
||||||
instructions,
|
instructions,
|
||||||
[],
|
[],
|
||||||
existingNoVoteAccount,
|
existingNoVoteAccount,
|
||||||
wallet.publicKey,
|
wallet.publicKey,
|
||||||
votingTokenAmount,
|
votingTokenAmount,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
transferAuthority,
|
||||||
);
|
);
|
||||||
|
|
||||||
const [governanceVotingRecord] = await PublicKey.findProgramAddress(
|
const [governanceVotingRecord] = await PublicKey.findProgramAddress(
|
||||||
|
@ -119,8 +125,6 @@ export const withdrawVotingTokens = async (
|
||||||
);
|
);
|
||||||
|
|
||||||
signers.push(transferAuthority);
|
signers.push(transferAuthority);
|
||||||
signers.push(yesTransferAuthority);
|
|
||||||
signers.push(noTransferAuthority);
|
|
||||||
|
|
||||||
instructions.push(
|
instructions.push(
|
||||||
withdrawVotingTokensInstruction(
|
withdrawVotingTokensInstruction(
|
||||||
|
@ -138,8 +142,6 @@ export const withdrawVotingTokens = async (
|
||||||
state.pubkey,
|
state.pubkey,
|
||||||
proposal.pubkey,
|
proposal.pubkey,
|
||||||
transferAuthority.publicKey,
|
transferAuthority.publicKey,
|
||||||
yesTransferAuthority.publicKey,
|
|
||||||
noTransferAuthority.publicKey,
|
|
||||||
mintAuthority,
|
mintAuthority,
|
||||||
votingTokenAmount,
|
votingTokenAmount,
|
||||||
),
|
),
|
||||||
|
|
|
@ -43,6 +43,7 @@ export function WithdrawVote({
|
||||||
votingTokens > 0 &&
|
votingTokens > 0 &&
|
||||||
(state.info.status === TimelockStateStatus.Voting ||
|
(state.info.status === TimelockStateStatus.Voting ||
|
||||||
state.info.status === TimelockStateStatus.Completed ||
|
state.info.status === TimelockStateStatus.Completed ||
|
||||||
|
state.info.status === TimelockStateStatus.Executing ||
|
||||||
state.info.status === TimelockStateStatus.Defeated);
|
state.info.status === TimelockStateStatus.Defeated);
|
||||||
|
|
||||||
const [btnLabel, title, msg, action] =
|
const [btnLabel, title, msg, action] =
|
||||||
|
|
|
@ -20,10 +20,8 @@ import BN from 'bn.js';
|
||||||
/// 11. `[]` Timelock state account.
|
/// 11. `[]` Timelock state account.
|
||||||
/// 12. `[]` Timelock set account.
|
/// 12. `[]` Timelock set account.
|
||||||
/// 13. `[]` Transfer authority
|
/// 13. `[]` Transfer authority
|
||||||
/// 14. `[]` Yes Transfer authority
|
/// 14. `[]` Timelock program mint authority
|
||||||
/// 15. `[]` No Transfer authority
|
/// 15. `[]` Token program account.
|
||||||
/// 16. `[]` Timelock program mint authority
|
|
||||||
/// 17. `[]` Token program account.
|
|
||||||
export const withdrawVotingTokensInstruction = (
|
export const withdrawVotingTokensInstruction = (
|
||||||
governanceVotingRecord: PublicKey,
|
governanceVotingRecord: PublicKey,
|
||||||
votingAccount: PublicKey,
|
votingAccount: PublicKey,
|
||||||
|
@ -39,8 +37,6 @@ export const withdrawVotingTokensInstruction = (
|
||||||
timelockStateAccount: PublicKey,
|
timelockStateAccount: PublicKey,
|
||||||
timelockSetAccount: PublicKey,
|
timelockSetAccount: PublicKey,
|
||||||
transferAuthority: PublicKey,
|
transferAuthority: PublicKey,
|
||||||
yesTransferAuthority: PublicKey,
|
|
||||||
noTransferAuthority: PublicKey,
|
|
||||||
mintAuthority: PublicKey,
|
mintAuthority: PublicKey,
|
||||||
votingTokenAmount: number,
|
votingTokenAmount: number,
|
||||||
): TransactionInstruction => {
|
): TransactionInstruction => {
|
||||||
|
@ -75,9 +71,7 @@ export const withdrawVotingTokensInstruction = (
|
||||||
{ pubkey: noVotingMint, isSigner: false, isWritable: true },
|
{ pubkey: noVotingMint, isSigner: false, isWritable: true },
|
||||||
{ pubkey: timelockStateAccount, isSigner: false, isWritable: false },
|
{ pubkey: timelockStateAccount, isSigner: false, isWritable: false },
|
||||||
{ pubkey: timelockSetAccount, isSigner: false, isWritable: false },
|
{ pubkey: timelockSetAccount, isSigner: false, isWritable: false },
|
||||||
{ pubkey: transferAuthority, isSigner: false, isWritable: false },
|
{ pubkey: transferAuthority, isSigner: true, isWritable: false },
|
||||||
{ pubkey: yesTransferAuthority, isSigner: false, isWritable: false },
|
|
||||||
{ pubkey: noTransferAuthority, isSigner: false, isWritable: false },
|
|
||||||
{ pubkey: mintAuthority, isSigner: false, isWritable: false },
|
{ pubkey: mintAuthority, isSigner: false, isWritable: false },
|
||||||
{ pubkey: PROGRAM_IDS.token, isSigner: false, isWritable: false },
|
{ pubkey: PROGRAM_IDS.token, isSigner: false, isWritable: false },
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue