Skip to content
Open
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
87 changes: 36 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions packages/common/src/hooks/useCoinflowAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ export const useCoinflowWithdrawalAdapter = () => {
sendTransaction: async (
transaction: Transaction | VersionedTransaction
) => {
if (transaction instanceof VersionedTransaction) {
throw new Error(
'VersionedTransaction not supported in withdrawal adapter'
)
}
if (!currentUser) {
throw new Error('Missing current user')
}
Expand Down
38 changes: 28 additions & 10 deletions packages/common/src/services/audius-backend/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
Keypair,
PublicKey,
Transaction,
TransactionInstruction
TransactionInstruction,
VersionedTransaction
} from '@solana/web3.js'

import { CommonStoreContext } from '~/store/storeContext'
Expand Down Expand Up @@ -261,7 +262,7 @@ export const decorateCoinflowWithdrawalTransaction = async (
ethAddress,
wallet
}: {
transaction: Transaction
transaction: Transaction | VersionedTransaction
ethAddress: string
wallet: Keypair
}
Expand All @@ -278,7 +279,9 @@ export const decorateCoinflowWithdrawalTransaction = async (

// Filter any compute budget instructions since the budget will
// definitely change
const instructions = transaction.instructions.filter(
const originalInstructions =
await sdk.services.solanaClient.getInstructions(transaction)
const instructions = originalInstructions.filter(
(instruction) =>
!instruction.programId.equals(ComputeBudgetProgram.programId)
)
Expand Down Expand Up @@ -447,6 +450,8 @@ type TransferFromUserBankParams = {
analyticsFields: any
/** If included, will attach a signed memo indicating a recovery transaction. */
signer?: Keypair
/** If included, this keypair pays tx/ATA fees instead of relay. */
feePayerSigner?: Keypair
}

export const transferFromUserBank = async ({
Expand All @@ -459,11 +464,15 @@ export const transferFromUserBank = async ({
track,
make,
analyticsFields,
signer
signer,
feePayerSigner
}: TransferFromUserBankParams) => {
let isCreatingTokenAccount = false
try {
const instructions: TransactionInstruction[] = []
const feePayer = feePayerSigner?.publicKey
? feePayerSigner.publicKey
: await sdk.services.solanaRelay.getFeePayer()

// Check if destinationWallet is already an associated token account
let destination = destinationWallet
Expand Down Expand Up @@ -520,10 +529,9 @@ export const transferFromUserBank = async ({
...analyticsFields
})
)
const payerKey = await sdk.services.solanaRelay.getFeePayer()
const createAtaInstruction =
createAssociatedTokenAccountIdempotentInstruction(
payerKey,
feePayer,
destination,
destinationWallet,
mint
Expand All @@ -546,7 +554,8 @@ export const transferFromUserBank = async ({
await sdk.services.claimableTokensClient.createTransferInstruction({
ethWallet,
mint,
destination
destination,
feePayer
})
instructions.push(transferInstruction)

Expand All @@ -566,11 +575,20 @@ export const transferFromUserBank = async ({
}

const transaction = await sdk.services.solanaClient.buildTransaction({
instructions
instructions,
feePayer: feePayerSigner?.publicKey
})

if (signer) {
transaction.sign([signer])
const signers = [signer, feePayerSigner].filter(
(keypair): keypair is Keypair => !!keypair
)
if (signers.length) {
const uniqueSigners = signers.filter(
(keypair, index) =>
signers.findIndex((s) => s.publicKey.equals(keypair.publicKey)) ===
index
)
transaction.sign(uniqueSigners)
}

const signature =
Expand Down
11 changes: 9 additions & 2 deletions packages/common/src/store/ui/withdraw-usdc/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ function* doWithdrawUSDCCoinflow({
track,
make,
analyticsFields,
signer: rootSolanaAccount
signer: rootSolanaAccount,
feePayerSigner: rootSolanaAccount
})

console.debug(
Expand Down Expand Up @@ -209,6 +210,7 @@ function* doWithdrawUSDCManualTransfer({
const withdrawalAmountDollars = amount / 100
const queryClient = yield* getContext('queryClient')
const sdk = yield* getSDK()
const solanaWalletService = yield* getContext('solanaWalletService')
const connection = sdk.services.solanaClient.connection
const env = yield* getContext('env')
const mint = new PublicKey(env.USDC_MINT_ADDRESS)
Expand All @@ -234,6 +236,10 @@ function* doWithdrawUSDCManualTransfer({
}
const ethWallet = user.wallet
const destinationWallet = new PublicKey(destinationAddress)
const rootSolanaAccount = yield* call([solanaWalletService, 'getKeypair'])
if (!rootSolanaAccount) {
throw new Error('Missing solana root wallet')
}

const signature = yield* call(transferFromUserBank, {
connection,
Expand All @@ -244,7 +250,8 @@ function* doWithdrawUSDCManualTransfer({
destinationWallet,
track,
make,
analyticsFields
analyticsFields,
feePayerSigner: rootSolanaAccount
})

console.debug('Withdraw USDC - successfully transferred USDC.', {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@audius/harmony": "*",
"@audius/sdk": "*",
"@cloudflare/kv-asset-handler": "0.2.0",
"@coinflowlabs/react": "5.5.1",
"@coinflowlabs/react": "^5.8.1",
"@emotion/css": "11.13.5",
"@emotion/react": "11.14.0",
"@emotion/server": "11.11.0",
Expand Down