64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { MongoClient } from 'mongodb'
|
|
import * as dotenv from 'dotenv'
|
|
|
|
dotenv.config()
|
|
|
|
const MONGODB_URI = process.env.MONGODB_URI
|
|
|
|
if (!MONGODB_URI) {
|
|
console.error('Please define the MONGODB_URI environment variable in .env')
|
|
process.exit(1)
|
|
}
|
|
|
|
async function giveAllSol() {
|
|
const amountStr = process.argv[2]
|
|
const amount = parseFloat(amountStr)
|
|
|
|
if (!amountStr || isNaN(amount) || amount <= 0) {
|
|
console.error('Please provide a valid positive number as the amount to add')
|
|
console.error('Usage: npx ts-node scripts/give-all-sol.ts <amount>')
|
|
process.exit(1)
|
|
}
|
|
|
|
let client: MongoClient | null = null;
|
|
try {
|
|
client = await MongoClient.connect(MONGODB_URI!)
|
|
const db = client.db('pummmpfun')
|
|
|
|
console.log(`Adding ${amount} SOL to all users...`)
|
|
|
|
// Add to user balances
|
|
const usersResult = await db.collection('users').updateMany(
|
|
{},
|
|
{
|
|
$inc: {
|
|
balance: amount
|
|
}
|
|
}
|
|
)
|
|
|
|
console.log(`Added ${amount} SOL to ${usersResult.modifiedCount} users (matched ${usersResult.matchedCount})`)
|
|
|
|
// Set notice about the bonus
|
|
const bonusDate = new Date().toLocaleDateString()
|
|
const noticeMessage = `As of ${bonusDate}, all users received a ${amount} SOL bonus!`
|
|
|
|
console.log('Setting bonus notice...')
|
|
await db.collection('notices').insertOne({
|
|
message: noticeMessage,
|
|
reason: `Bonus: ${amount} SOL`,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date()
|
|
})
|
|
console.log('Bonus notice set')
|
|
|
|
console.log(`Successfully gave ${amount} SOL to all users!`)
|
|
|
|
} catch (error) {
|
|
console.error('Error during bonus distribution:', error)
|
|
} finally {
|
|
if (client) await client.close()
|
|
}
|
|
}
|
|
|
|
giveAllSol()
|