Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing smart wallet (PDA wallet) support #1922

Merged
merged 8 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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