77 createInitializeMintInstruction ,
88 getMint ,
99 NATIVE_MINT ,
10- createSyncNativeInstruction
10+ createSyncNativeInstruction ,
11+ createApproveInstruction
1112} from '@bbachain/spl-token'
1213import {
1314 CurveType ,
@@ -735,12 +736,19 @@ export const useCreatePool = () => {
735736 console . log ( '💰 BBA/Token pool (BBA as base)' )
736737
737738 // Check BBA balance (native daltons)
738- const userBBABalance = await connection . getBalance ( ownerAddress )
739- const requiredBBA = bbaTodaltons ( liquidityBaseAmount )
739+ const userWBBATokenAccount = await getAssociatedTokenAddress ( NATIVE_MINT , ownerAddress )
740+ console . log ( 'ini lewat bang' )
741+ const userWBBAInfo = await connection . getAccountInfo ( userWBBATokenAccount )
742+ if ( ! userWBBAInfo ) {
743+ throw new Error (
744+ 'WBBA token account not found. Please ensure you have the required tokens.'
745+ )
746+ }
740747
741- if ( userBBABalance < requiredBBA ) {
748+ const userWBBABalance = new BN ( userWBBAInfo . data . slice ( 64 , 72 ) , 'le' )
749+ if ( userWBBABalance . lt ( new BN ( baseAmountDaltons ) ) ) {
742750 throw new Error (
743- `Insufficient BBA balance. Required: ${ liquidityBaseAmount } BBA , Available: ${ daltonsToBBA ( userBBABalance ) } BBA `
751+ `Insufficient ${ payload . baseToken . symbol } balance. Required: ${ liquidityBaseAmount } , Available: ${ userWBBABalance . div ( new BN ( 1000000 ) ) . toString ( ) } `
744752 )
745753 }
746754
@@ -761,28 +769,34 @@ export const useCreatePool = () => {
761769 )
762770 }
763771
764- // Transfer BBA to pool (using special BBA handling)
765- console . log ( '🔄 Transferring BBA to pool account...' )
766- const transferBBAIx = SystemProgram . transfer ( {
767- fromPubkey : ownerAddress ,
768- toPubkey : swapTokenAAccount ,
769- daltons : requiredBBA
770- } )
771-
772- const { createSyncNativeInstruction } = await import ( '@bbachain/spl-token' )
773- const syncBBAIx = createSyncNativeInstruction ( swapTokenAAccount )
774-
775772 // Transfer quote token (standard SPL transfer)
776773 const { createTransferInstruction } = await import ( '@bbachain/spl-token' )
774+
775+ const transferBBAIx = createTransferInstruction (
776+ userWBBATokenAccount ,
777+ swapTokenAAccount ,
778+ ownerAddress ,
779+ baseAmountDaltons
780+ )
781+
777782 const transferQuoteIx = createTransferInstruction (
778783 userQuoteTokenAccount ,
779784 swapTokenBAccount ,
780785 ownerAddress ,
781786 quoteAmountDaltons
782787 )
783788
789+ console . log ( 're-check' , {
790+ swapTokenA : swapTokenAAccount . toBase58 ( ) ,
791+ wbbaTokenAccount : userWBBATokenAccount . toBase58 ( ) ,
792+ wbbaDaltons : baseAmountDaltons ,
793+ wbbaAmount : baseAmount
794+ } )
795+
784796 // Combine all transfers
785- const liquidityTx = new Transaction ( ) . add ( transferBBAIx , syncBBAIx , transferQuoteIx )
797+ const liquidityTx = new Transaction ( ) . add ( transferBBAIx , transferQuoteIx )
798+
799+ console . log ( 'this causes error' )
786800 const liquiditySig = await sendTransactionWithRetry (
787801 liquidityTx ,
788802 connection ,
0 commit comments