Untitled

 avatar
unknown
typescript
a year ago
1.9 kB
112
Indexable
const ata = getAssociatedTokenAddressSync(poolKeysInit.baseMint,wallet.publicKey)
    console.log("ATA:",ata);
    const destinationAccount : TransactionInstruction = await createAssociatedTokenAccountInstruction(
        wallet.publicKey,
        ata,
        wallet.publicKey,
        poolKeysInit.baseMint
      );

    /*const token = await getMint(connection, poolKeysInit.baseMint);
    const amount = 0.1*10**token.decimals*/
    const innerTransaction = Liquidity.makeSwapFixedInInstruction(
      {
        poolKeys: poolKeysInit,
        userKeys: {
          tokenAccountIn: PUB_KEY_SOL,
          tokenAccountOut: ata,
          owner: wallet.publicKey,
        },
        amountIn: 100000000,
        minAmountOut: 0,
      }, 4
    );
    
    const messageV0 = new TransactionMessage({
      payerKey: wallet.publicKey,
      recentBlockhash: (await connection.getLatestBlockhash({ commitment: 'confirmed' })).blockhash,
      instructions: [
        ComputeBudgetProgram.setComputeUnitLimit({ units: 25000 }),
        ComputeBudgetProgram.setComputeUnitPrice({ microLamports: 60000 }),
        destinationAccount,
        innerTransaction.innerTransaction.instructions[0],
      ],
    }).compileToV0Message();

    const transaction = new VersionedTransaction(messageV0);
    
    transaction.sign([wallet]);
    const txid = await connection.sendTransaction(transaction);

    //const rawTransaction = transaction.serialize();
    //const txid = await connection.sendRawTransaction(rawTransaction, {skipPreflight: true, maxRetries:3});

    console.log(
      "txid: ",txid, ' Buy');
      //console.log("POOL: ", poolKeysInit);
    const status = await connection.getTransaction(txid,{maxSupportedTransactionVersion:4});
    console.log("status: ", status);
    
    if (seenTransactions.includes(signature)) {
        return;
    }

    seenTransactions.push(signature);
  }
Editor is loading...
Leave a Comment