import { MongoClient } from 'mongodb' import * as dotenv from 'dotenv' let fs = require('fs') import { ethers } from 'ethers' import mongoose from 'mongoose' const envFile = process.env.NODE_ENV && process.env.NODE_ENV === 'production' ? `.env.production` : '.env.development' dotenv.config({ path: envFile }) console.log(process.env.DB_MAIN) import { CECRecord } from './models/CECRecord' import { CECRecordTotal } from './models/CECRecordTotal' const dbMain = mongoose.createConnection(process.env.DB_MAIN) const importCecEvent = async () => { const clientEvent = await MongoClient.connect("mongodb://10.0.0.194/") const dbEvent = clientEvent.db('web-chain-development') let records = await dbEvent.collection('event_score').find({}).toArray() for (let record of records) { if (!record.address) { continue } console.log('1', record.address, record.score, ethers.utils.parseUnits(record.score,"ether").toString()) let cecRecord = new CECRecordTotal({ address: record.address.toLowerCase(), num: Number(record.score), earnTime: 'before 2024', desc: 'old game event' }) cecRecord.amount = ethers.utils.parseUnits(record.score,"ether").toString() await cecRecord.save() } } const importUAW = async () => { let records = await CECRecord.find({}) for (let record of records) { let cecRecord = new CECRecordTotal({ address: record.address.toLowerCase(), amount: record.amount.toString(), num: Number(ethers.utils.formatEther( record.amount )), earnTime: record.earnTime, desc: record.desc }) await cecRecord.save() } } const importGachaEvent = async () => { const clientEvent = await MongoClient.connect("mongodb://10.0.0.194/") const dbEvent = clientEvent.db('web-chain-development') let records = await dbEvent.collection('claim_score_list').find({}).toArray() for (let record of records) { let val = BigInt(record.cecBasicReal) + BigInt(record.cecRankReal) let cecRecord = new CECRecordTotal({ address: record.address.toLowerCase(), amount: val.toString(), num: Number(ethers.utils.formatEther( val )), earnTime: 'Nov 2023', desc: 'Rase of Gacha ' }) await cecRecord.save() } } const loadGameSeason = async () => { console.time('load game test') let datas = fs.readFileSync('initdatas/cec_season_rank.txt', 'utf-8').split('\n') console.timeEnd('load game test') console.time('insert game test') let actionsUaw = [] const descUaw = 'game season rank' const timeUaw = 'Jul 2023 - Jan 2024' for (let data of datas) { if (!data) { continue } let [address, amount] = data.split(' ') address = address.toLowerCase() let amountBig = ethers.utils.parseEther(amount).toString() actionsUaw.push({ insertOne: { document: { address, amount: amountBig, num: Number(amount), desc: descUaw, earnTime: timeUaw, status: 1, firstRate: 50, createdAt: new Date(), updatedAt: new Date(), __v: 0.0, }, }, }) } await dbMain.collection('cec_record_total').bulkWrite(actionsUaw) console.timeEnd('insert game test') } const loadStake = async () => { console.time('load game test') let datas = fs.readFileSync('initdatas/cec_stake.txt', 'utf-8').split('\n') console.timeEnd('load game test') console.time('insert game test') let actionsUaw = [] const descUaw = 'Badge staking rewards' const timeUaw = 'Aug 2023' for (let data of datas) { if (!data) { continue } let [address, amount] = data.split(' ') address = address.toLowerCase() let amountBig = ethers.utils.parseEther(amount).toString() actionsUaw.push({ insertOne: { document: { address, amount: amountBig, num: Number(amount), desc: descUaw, earnTime: timeUaw, status: 1, firstRate: 50, createdAt: new Date(), updatedAt: new Date(), __v: 0.0, }, }, }) } await dbMain.collection('cec_record_total').bulkWrite(actionsUaw) console.timeEnd('insert game test') } const loadHashRate = async () => { console.time('load game test') let datas = fs.readFileSync('initdatas/cec_hashrate.txt', 'utf-8').split('\n') console.timeEnd('load game test') console.time('insert game test') let actionsUaw = [] const descUaw = 'hash rate rewards' const timeUaw = 'Jul 2023 - Jan 2024' for (let data of datas) { if (!data) { continue } let [address, amount] = data.split(' ') address = address.toLowerCase() let amountBig = ethers.utils.parseEther(amount).toString() actionsUaw.push({ insertOne: { document: { address, amount: amountBig, num: Number(amount), desc: descUaw, earnTime: timeUaw, status: 1, firstRate: 50, createdAt: new Date(), updatedAt: new Date(), __v: 0.0, }, }, }) } await dbMain.collection('cec_record_total').bulkWrite(actionsUaw) console.timeEnd('insert game test') } const loadGacha = async () => { console.time('load game test') let datas = fs.readFileSync('initdatas/cec_gacha.txt', 'utf-8').split('\n') console.timeEnd('load game test') console.time('insert game test') let actionsUaw = [] const descUaw = 'Gacha Journey' const timeUaw = 'Nov 2023' for (let data of datas) { if (!data) { continue } let [address, amount] = data.split(' ') address = address.toLowerCase() let amountBig = ethers.utils.parseEther(amount).toString() actionsUaw.push({ insertOne: { document: { address, amount: amountBig, num: Number(amount), desc: descUaw, earnTime: timeUaw, status: 1, firstRate: 50, createdAt: new Date(), updatedAt: new Date(), __v: 0.0, }, }, }) } await dbMain.collection('cec_record_total').bulkWrite(actionsUaw) console.timeEnd('insert game test') } const exportRecords = async () => { let records = await CECRecord.find({}) let results100 = [] let results500 = [] let map = new Map() for (let record of records) { let address = record.address.toLowerCase() if (!map.has(address)) { map.set(address, 0) } map.set(address, map.get(address) + parseFloat(ethers.utils.formatEther( record.amount ))) } for (let [address, amount] of map) { if (amount >=100) { results100.push({ address, amount }) } if (amount >= 500) { results500.push({ address, amount }) } } console.log(results100.length) console.log(results500.length) // write results to file // fs.writeFileSync('outdatas/results100.txt', JSON.stringify(results100)) // fs.writeFileSync('outdatas/results500.txt', JSON.stringify(results500)) } ;(async () => { try { // await importCecEvent(); // await importUAW() // await loadGameSeason() // await loadHashRate() // await importGachaEvent() await loadStake() // await loadGacha() // await exportRecords() } catch (e) { console.log(e) } process.exit(0) })()