Skip to content

Commit

Permalink
Add missing smart wallet (PDA wallet) support (solana-labs#1922)
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinmadrid authored Nov 15, 2023
1 parent 9447152 commit 3b8b7e6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
26 changes: 16 additions & 10 deletions components/GovernancePower/Vanilla/useDepositCallback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,30 @@ export const useDepositCallback = (
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
mint,
walletPk // owner
walletPk, // owner
true
)

const instructions: TransactionInstruction[] = []
const signers: Keypair[] = []

const transferAuthority = approveTokenTransfer(
instructions,
[],
userAtaPk,
wallet!.publicKey!,
amount
)
// Checks if the connected wallet is the Squads Multisig extension (or any PDA wallet for future reference). If it is the case, it will not use an ephemeral signer.
const transferAuthority = wallet?.name == "SquadsX"
? undefined
: approveTokenTransfer(instructions, [], userAtaPk, wallet!.publicKey!, amount);

signers.push(transferAuthority)
if (transferAuthority) {
signers.push(transferAuthority);
}

const programVersion = await fetchProgramVersion(connection, realm.owner)

const publicKeyToUse = transferAuthority != undefined && wallet?.publicKey != null ? transferAuthority.publicKey : wallet?.publicKey;

if (!publicKeyToUse) {
throw new Error()
}

await withDepositGoverningTokens(
instructions,
realm.owner,
Expand All @@ -64,7 +70,7 @@ export const useDepositCallback = (
userAtaPk,
mint,
walletPk,
transferAuthority.publicKey,
publicKeyToUse,
walletPk,
amount
)
Expand Down
3 changes: 2 additions & 1 deletion hooks/useUserGovTokenAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const useUserGovTokenAccountQuery = (role: 'community' | 'council') => {
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
mint,
walletPk
walletPk,
true
),
[mint, walletPk]
)
Expand Down
6 changes: 4 additions & 2 deletions utils/instructions/PsyFinance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ export const initializeOptionInstruction = async (
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
underlyingMint,
FEE_OWNER_KEY
FEE_OWNER_KEY,
true
)
remainingAccounts.push({
pubkey: mintFeeKey,
Expand All @@ -199,7 +200,8 @@ export const initializeOptionInstruction = async (
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_PROGRAM_ID,
quoteMint,
FEE_OWNER_KEY
FEE_OWNER_KEY,
true
)
remainingAccounts.push({
pubkey: exerciseFeeKey,
Expand Down
4 changes: 2 additions & 2 deletions utils/uiTypes/VotePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export class VotingClient {
)

for (const pos of this.heliumVsrVotingPositions) {
const tokenAccount = await getAssociatedTokenAddress(pos.mint, walletPk)
const tokenAccount = await getAssociatedTokenAddress(pos.mint, walletPk, true)

remainingAccounts.push(
new AccountData(tokenAccount),
Expand Down Expand Up @@ -396,7 +396,7 @@ export class VotingClient {

for (let i = 0; i < unusedPositions.length; i++) {
const pos = unusedPositions[i]
const tokenAccount = await getAssociatedTokenAddress(pos.mint, walletPk)
const tokenAccount = await getAssociatedTokenAddress(pos.mint, walletPk, true)
const [nftVoteRecord] = nftVoteRecordKey(
proposal.pubkey,
pos.mint,
Expand Down

0 comments on commit 3b8b7e6

Please sign in to comment.