93 lines
2.5 KiB
TypeScript
93 lines
2.5 KiB
TypeScript
import { PrismaClient } from '@prisma/client';
|
|
import Decimal from 'decimal.js';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('Seeding mining-wallet-service database...');
|
|
|
|
// 1. 初始化核心系统账户(总部、运营、手续费)
|
|
const systemAccounts = [
|
|
{ accountType: 'HEADQUARTERS', name: '总部账户', code: 'HQ' },
|
|
{ accountType: 'OPERATION', name: '运营账户', code: 'OP' },
|
|
{ accountType: 'FEE', name: '手续费账户', code: 'FEE' },
|
|
];
|
|
|
|
for (const account of systemAccounts) {
|
|
const existing = await prisma.systemAccount.findFirst({
|
|
where: { code: account.code },
|
|
});
|
|
|
|
if (!existing) {
|
|
await prisma.systemAccount.create({
|
|
data: {
|
|
accountType: account.accountType as any,
|
|
name: account.name,
|
|
code: account.code,
|
|
isActive: true,
|
|
},
|
|
});
|
|
console.log(`Created system account: ${account.code}`);
|
|
} else {
|
|
console.log(`System account already exists: ${account.code}`);
|
|
}
|
|
}
|
|
|
|
// 2. 初始化池账户(积分股池、黑洞池、流通池)
|
|
const poolAccounts = [
|
|
{
|
|
poolType: 'SHARE_POOL',
|
|
name: '积分股池',
|
|
balance: new Decimal('100000000'), // 1亿初始发行量
|
|
description: '挖矿奖励的来源池,总发行量',
|
|
},
|
|
{
|
|
poolType: 'BLACK_HOLE_POOL',
|
|
name: '黑洞池',
|
|
balance: new Decimal('0'),
|
|
targetBurn: new Decimal('50000000'), // 目标销毁5000万
|
|
description: '销毁的积分股,用于减少流通量',
|
|
},
|
|
{
|
|
poolType: 'CIRCULATION_POOL',
|
|
name: '流通池',
|
|
balance: new Decimal('0'),
|
|
description: '市场流通的积分股',
|
|
},
|
|
];
|
|
|
|
for (const pool of poolAccounts) {
|
|
const existing = await prisma.poolAccount.findFirst({
|
|
where: { poolType: pool.poolType as any },
|
|
});
|
|
|
|
if (!existing) {
|
|
await prisma.poolAccount.create({
|
|
data: {
|
|
poolType: pool.poolType as any,
|
|
name: pool.name,
|
|
balance: pool.balance,
|
|
targetBurn: pool.targetBurn,
|
|
remainingBurn: pool.targetBurn,
|
|
description: pool.description,
|
|
isActive: true,
|
|
},
|
|
});
|
|
console.log(`Created pool account: ${pool.poolType}`);
|
|
} else {
|
|
console.log(`Pool account already exists: ${pool.poolType}`);
|
|
}
|
|
}
|
|
|
|
console.log('Seeding completed!');
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error('Seeding failed:', e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|