Skip to content

Commit 16a13ca

Browse files
committed
chore: add collect all launchpad creator fees demo
1 parent 30bb714 commit 16a13ca

File tree

6 files changed

+144
-18
lines changed

6 files changed

+144
-18
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Raydium SDK V2 demo.",
55
"license": "GPL-3.0",
66
"dependencies": {
7-
"@raydium-io/raydium-sdk-v2": "0.2.13-alpha",
7+
"@raydium-io/raydium-sdk-v2": "0.2.16-alpha",
88
"@solana/spl-token": "^0.4.6",
99
"@solana/web3.js": "^1.95.3",
1010
"@triton-one/yellowstone-grpc": "^1.2.0",

src/cpmm/swap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
ApiV3PoolInfoStandardItemCpmm,
33
CpmmKeys,
4-
CpmmRpcData,
4+
CpmmParsedRpcData,
55
CurveCalculator,
66
FeeOn,
77
printSimulate,
@@ -24,7 +24,7 @@ export const swap = async () => {
2424

2525
let poolInfo: ApiV3PoolInfoStandardItemCpmm
2626
let poolKeys: CpmmKeys | undefined
27-
let rpcData: CpmmRpcData
27+
let rpcData: CpmmParsedRpcData
2828

2929
if (raydium.cluster === 'mainnet') {
3030
// note: api doesn't support get devnet pool info, so in devnet else we go rpc method

src/cpmm/swapBaseOut.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
ApiV3PoolInfoStandardItemCpmm,
33
CpmmKeys,
4-
CpmmRpcData,
4+
CpmmParsedRpcData,
55
CurveCalculator,
66
USDCMint,
77
FeeOn,
@@ -27,7 +27,7 @@ export const swapBaseOut = async () => {
2727

2828
let poolInfo: ApiV3PoolInfoStandardItemCpmm
2929
let poolKeys: CpmmKeys | undefined
30-
let rpcData: CpmmRpcData
30+
let rpcData: CpmmParsedRpcData
3131

3232
if (raydium.cluster === 'mainnet') {
3333
// note: api doesn't support get devnet pool info, so in devnet else we go rpc method
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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()

src/launchpad/type.ts

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ApiV3Token } from '@raydium-io/raydium-sdk-v2'
1+
import { ApiV3Token, CpmmCreatorFeeOn } from '@raydium-io/raydium-sdk-v2'
22

33
export interface ConfigInfo {
44
name: string
@@ -21,6 +21,39 @@ export interface ConfigInfo {
2121
mintB: string
2222
}
2323

24+
export interface PlatformCurveAPI {
25+
epoch: number
26+
index: number
27+
configId: string
28+
bondingCurveParam: {
29+
migrateType: number | null
30+
migrateCpmmFeeOn: number | null
31+
supply: string | null
32+
totalSellA: string | null
33+
totalFundRaisingB: string | null
34+
totalLockedAmount: string | null
35+
cliffPeriod: string | null
36+
unlockPeriod: string | null
37+
}
38+
}
39+
40+
export interface PlatformConfig {
41+
pubKey: string
42+
platformClaimFeeWallet: string
43+
platformLockNftWallet: string
44+
transferFeeExtensionAuth: string
45+
cpConfigId: string
46+
platformScale: string
47+
creatorScale: string
48+
burnScale: string
49+
feeRate: string
50+
creatorFeeRate: string
51+
name: string
52+
web: string
53+
img: string
54+
platformCurve: PlatformCurveAPI[]
55+
}
56+
2457
export interface MintInfo {
2558
creator: string
2659
decimals: string
@@ -43,6 +76,10 @@ export interface MintInfo {
4376
initPrice: string
4477
endPrice: string
4578
migrateAmmId?: string
79+
80+
migrateCreatorNftMint?: string
81+
migratePlatformNftMint?: string
82+
4683
priceStageTime1?: number
4784
priceStageTime2?: number
4885
priceFinalTime?: number
@@ -54,21 +91,25 @@ export interface MintInfo {
5491
configId: string
5592
configInfo: ConfigInfo
5693

57-
platformInfo: {
58-
feeRate: string
59-
img: string
60-
name: string
61-
platformClaimFeeWallet: string
62-
pubKey: string
63-
web: string
64-
}
94+
platformInfo: PlatformConfig
6595

6696
cliffPeriod: string
6797
unlockPeriod: string
6898
totalAllocatedShare: number
6999
totalLockedAmount: number
70100

71101
defaultCurve?: boolean
102+
103+
totalSellA: string
104+
totalFundRaisingB: string
105+
106+
migrateType: 'cpmm' | 'amm'
107+
mintProgramA: string
108+
109+
transferFeeBasePoints?: number
110+
maxinumFee?: string
111+
112+
cpmmCreatorFeeOn: CpmmCreatorFeeOn
72113
}
73114

74115
export interface TradeHistory {

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@
278278
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
279279
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==
280280

281-
"@raydium-io/[email protected].13-alpha":
282-
version "0.2.13-alpha"
283-
resolved "https://registry.yarnpkg.com/@raydium-io/raydium-sdk-v2/-/raydium-sdk-v2-0.2.13-alpha.tgz#911f050a9d510c5f7cee59be07cf39c39e9e6083"
284-
integrity sha512-+0WeCX65Beq/ilhkD0KGJzaDsz7HRAXbospRb2labdJN6cbEoStyez+W2WbNY49/O64yq+HRnVf9r0bRoAQ8Uw==
281+
"@raydium-io/[email protected].16-alpha":
282+
version "0.2.16-alpha"
283+
resolved "https://registry.yarnpkg.com/@raydium-io/raydium-sdk-v2/-/raydium-sdk-v2-0.2.16-alpha.tgz#619dc59ee2de3af748897a27faadb49b67660753"
284+
integrity sha512-GJYPhRKiXAq8aZAOFiqLGZj7Imyj+JIUHIjgPk9HNVuNxGiz/mo0rJvUIdJ1FDbgU3ik75J9uTKRmUqSBh+KJg==
285285
dependencies:
286286
"@solana/buffer-layout" "^4.0.1"
287287
"@solana/spl-token" "^0.4.8"

0 commit comments

Comments
 (0)