|
| 1 | +import { |
| 2 | + DEVNET_PROGRAM_ID, |
| 3 | + printSimulate, |
| 4 | + LAUNCHPAD_PROGRAM, |
| 5 | + getPdaCreatorVault, |
| 6 | + splAccountLayout, |
| 7 | + ApiV3Token, |
| 8 | +} from '@raydium-io/raydium-sdk-v2' |
| 9 | +import { initSdk, txVersion } from '../config' |
| 10 | +import { PublicKey } from '@solana/web3.js' |
| 11 | +import axios from 'axios' |
| 12 | +import { MintInfo } from './type' |
| 13 | +import Decimal from 'decimal.js' |
| 14 | + |
| 15 | +export const collectAllCreatorFees = async () => { |
| 16 | + const raydium = await initSdk() |
| 17 | + |
| 18 | + const isDevnet = raydium.cluster === 'devnet' |
| 19 | + const host = isDevnet ? 'https://launch-mint-v1-devnet.raydium.io' : 'https://launch-mint-v1.raydium.io' |
| 20 | + |
| 21 | + const ownerCreatedMintRes: { id: string; success: boolean; data: { rows: MintInfo[]; nextPageId?: string } } = ( |
| 22 | + await axios.get(`${host}/get/by/user?wallet=${raydium.ownerPubKey.toBase58()}&size=100`) |
| 23 | + ).data |
| 24 | + |
| 25 | + if (!ownerCreatedMintRes.data || !ownerCreatedMintRes.data.rows.length) { |
| 26 | + console.log('owner did not have any created mints') |
| 27 | + process.exit() |
| 28 | + } |
| 29 | + |
| 30 | + const allMintB: Record<string, ApiV3Token> = {} |
| 31 | + ownerCreatedMintRes.data.rows.forEach((d) => { |
| 32 | + allMintB[d.mintB.address] = d.mintB |
| 33 | + }) |
| 34 | + const allMintBArray = Object.values(allMintB) |
| 35 | + |
| 36 | + // code below is to show how many pending fees, for display only |
| 37 | + |
| 38 | + // const program = isDevnet ? DEVNET_PROGRAM_ID.LAUNCHPAD_PROGRAM : LAUNCHPAD_PROGRAM |
| 39 | + // const allMintBVault = allMintBArray.map( |
| 40 | + // (mint) => getPdaCreatorVault(program, raydium.ownerPubKey, new PublicKey(mint.address)).publicKey |
| 41 | + // ) |
| 42 | + // const vaultRes = await raydium.connection.getMultipleAccountsInfo(allMintBVault) |
| 43 | + // const allPendingFees: Map<string, Decimal> = new Map() |
| 44 | + // res.data.rows.forEach((d) => { |
| 45 | + // allMintB[d.mintB.address] = d.mintB |
| 46 | + // }) |
| 47 | + // vaultRes.forEach((data, idx) => { |
| 48 | + // if (!data) return |
| 49 | + // const mint = allMintBArray[idx] |
| 50 | + // const feeAmount = new Decimal(splAccountLayout.decode(data.data).amount.toString()).div(10 ** mint.decimals) |
| 51 | + // if (allPendingFees.has(mint.address)) |
| 52 | + // allPendingFees.set(mint.address, allPendingFees.get(mint.address)!.add(feeAmount)) |
| 53 | + // else allPendingFees.set(mint.address, feeAmount) |
| 54 | + // }) |
| 55 | + // Array.from(allPendingFees.entries()).forEach((feeData) => { |
| 56 | + // console.log(`== ${allMintB[feeData[0]].symbol} pending fees: ${feeData[1].toString()} ==`) |
| 57 | + // }) |
| 58 | + |
| 59 | + const { transactions, execute } = await raydium.launchpad.claimMultipleCreatorFee({ |
| 60 | + // currently we only have SOL as mintB, so this array should only have 1 item |
| 61 | + mintBList: allMintBArray.map((mint) => ({ |
| 62 | + pubKey: new PublicKey(mint.address), |
| 63 | + programId: new PublicKey(mint.programId), |
| 64 | + })), |
| 65 | + txVersion, |
| 66 | + // computeBudgetConfig: { |
| 67 | + // units: 600000, |
| 68 | + // microLamports: 600000, |
| 69 | + // }, |
| 70 | + }) |
| 71 | + |
| 72 | + printSimulate(transactions) |
| 73 | + |
| 74 | + try { |
| 75 | + const sentInfo = await execute({ sequentially: true }) |
| 76 | + console.log(sentInfo) |
| 77 | + } catch (e: any) { |
| 78 | + console.log(e) |
| 79 | + } |
| 80 | + |
| 81 | + process.exit() // if you don't want to end up node execution, comment this line |
| 82 | +} |
| 83 | + |
| 84 | +/** uncomment code below to execute */ |
| 85 | +// collectAllCreatorFees() |
0 commit comments