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:
Jordan Prince 2021-04-11 16:38:37 -05:00
parent 68fb3d85de
commit 7aba9b761c
5 changed files with 15 additions and 17 deletions

View File

@ -58,10 +58,11 @@ export function approve(
// if delegate is not passed ephemeral transfer authority is used
delegate?: PublicKey,
existingTransferAuthority?: Account,
): Account {
const tokenProgram = TOKEN_PROGRAM_ID;
const transferAuthority = new Account();
const transferAuthority = existingTransferAuthority || new Account();
const delegateKey = delegate ?? transferAuthority.publicKey;
const instruction = Token.createApproveInstruction(

View File

@ -69,7 +69,7 @@ export const PROGRAM_IDS = [
{
name: 'testnet',
timelock: () => ({
programId: new PublicKey('8DevpkpN6CsdczP6rQ64CHraApXFrq96oGm4VjSNCs4q'),
programId: new PublicKey('DCVPuhaGNMLh73FRWFroH4o3ERUhBKMRWfBgJV94VqRk'),
}),
wormhole: () => ({
pubkey: new PublicKey('5gQf5AUhAgWYgUCt9ouShm9H7dzzXUsLdssYwe5krKhg'),

View File

@ -93,20 +93,26 @@ export const withdrawVotingTokens = async (
votingTokenAmount,
);
const yesTransferAuthority = approve(
approve(
instructions,
[],
existingYesVoteAccount,
wallet.publicKey,
votingTokenAmount,
undefined,
undefined,
transferAuthority,
);
const noTransferAuthority = approve(
approve(
instructions,
[],
existingNoVoteAccount,
wallet.publicKey,
votingTokenAmount,
undefined,
undefined,
transferAuthority,
);
const [governanceVotingRecord] = await PublicKey.findProgramAddress(
@ -119,8 +125,6 @@ export const withdrawVotingTokens = async (
);
signers.push(transferAuthority);
signers.push(yesTransferAuthority);
signers.push(noTransferAuthority);
instructions.push(
withdrawVotingTokensInstruction(
@ -138,8 +142,6 @@ export const withdrawVotingTokens = async (
state.pubkey,
proposal.pubkey,
transferAuthority.publicKey,
yesTransferAuthority.publicKey,
noTransferAuthority.publicKey,
mintAuthority,
votingTokenAmount,
),

View File

@ -43,6 +43,7 @@ export function WithdrawVote({
votingTokens > 0 &&
(state.info.status === TimelockStateStatus.Voting ||
state.info.status === TimelockStateStatus.Completed ||
state.info.status === TimelockStateStatus.Executing ||
state.info.status === TimelockStateStatus.Defeated);
const [btnLabel, title, msg, action] =

View File

@ -20,10 +20,8 @@ import BN from 'bn.js';
/// 11. `[]` Timelock state account.
/// 12. `[]` Timelock set account.
/// 13. `[]` Transfer authority
/// 14. `[]` Yes Transfer authority
/// 15. `[]` No Transfer authority
/// 16. `[]` Timelock program mint authority
/// 17. `[]` Token program account.
/// 14. `[]` Timelock program mint authority
/// 15. `[]` Token program account.
export const withdrawVotingTokensInstruction = (
governanceVotingRecord: PublicKey,
votingAccount: PublicKey,
@ -39,8 +37,6 @@ export const withdrawVotingTokensInstruction = (
timelockStateAccount: PublicKey,
timelockSetAccount: PublicKey,
transferAuthority: PublicKey,
yesTransferAuthority: PublicKey,
noTransferAuthority: PublicKey,
mintAuthority: PublicKey,
votingTokenAmount: number,
): TransactionInstruction => {
@ -75,9 +71,7 @@ export const withdrawVotingTokensInstruction = (
{ pubkey: noVotingMint, isSigner: false, isWritable: true },
{ pubkey: timelockStateAccount, isSigner: false, isWritable: false },
{ pubkey: timelockSetAccount, isSigner: false, isWritable: false },
{ pubkey: transferAuthority, isSigner: false, isWritable: false },
{ pubkey: yesTransferAuthority, isSigner: false, isWritable: false },
{ pubkey: noTransferAuthority, isSigner: false, isWritable: false },
{ pubkey: transferAuthority, isSigner: true, isWritable: false },
{ pubkey: mintAuthority, isSigner: false, isWritable: false },
{ pubkey: PROGRAM_IDS.token, isSigner: false, isWritable: false },
];