games_app/backend/dist-test-faq/scripts/seedHotWallets.js

104 lines
4.3 KiB
JavaScript

"use strict";
/**
* Seed hot wallets for USDT TRC20 (TRON) and USDT BEP20 (BSC) withdrawals.
*
* Usage (from backend/):
* npm run seed-hot-wallets
*
* VPS:
* sudo docker compose run --rm --no-deps --build backend node dist/scripts/seedHotWallets.js
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
require("./loadEnv");
const connection_1 = require("../db/connection");
const hdWallet_1 = require("../services/hdWallet");
const hotWalletRepository = __importStar(require("../repositories/hotWalletRepository"));
const walletRepository = __importStar(require("../repositories/walletRepository"));
const walletCapabilities_1 = require("../services/walletCapabilities");
const HOT_DERIVATION_INDEX_TRON = 1000000;
const HOT_DERIVATION_INDEX_BSC = 1000001;
async function seedOne(opts) {
const wt = await walletRepository.getWalletTypeByCode(opts.code);
if (!wt)
throw new Error(`${opts.code} wallet type not found — run migrations first.`);
const existing = await (0, connection_1.query)('SELECT wallet_type_id FROM hot_wallets WHERE is_active = TRUE AND wallet_type_id = $1', [wt.id]);
if (existing.length > 0) {
console.log(`Hot wallet already exists for ${opts.code}. Skipping.`);
console.log(' ', opts.address);
}
else {
await hotWalletRepository.create({
walletTypeId: wt.id,
address: opts.address,
encryptedPrivateKey: opts.encryptedPrivateKey,
derivationIndex: opts.derivationIndex,
});
console.log(`Created hot wallet for ${opts.code}:`, opts.address);
}
console.log(` Fund with: ${opts.fundHint}`);
}
async function main() {
const mnemonic = (process.env.PLATFORM_MNEMONIC || '').trim();
if (!mnemonic || mnemonic.split(/\s+/).length < 12) {
throw new Error('PLATFORM_MNEMONIC must be set in .env (12 or 24 words).');
}
if (!process.env.ENCRYPTION_KEY || process.env.ENCRYPTION_KEY.length !== 64) {
throw new Error('ENCRYPTION_KEY must be 32-byte hex (64 chars) in .env.');
}
const tron = (0, hdWallet_1.deriveTronFromMnemonic)(mnemonic, HOT_DERIVATION_INDEX_TRON);
await seedOne({
code: walletCapabilities_1.USDT_TRC20_CODE,
address: tron.address,
encryptedPrivateKey: (0, hdWallet_1.encryptPrivateKey)(tron.privateKey),
derivationIndex: HOT_DERIVATION_INDEX_TRON,
fundHint: 'TRX (gas) + USDT TRC20 on TRON mainnet',
});
const bsc = (0, hdWallet_1.deriveEvmFromMnemonic)(mnemonic, HOT_DERIVATION_INDEX_BSC);
await seedOne({
code: walletCapabilities_1.USDT_BEP20_CODE,
address: bsc.address,
encryptedPrivateKey: (0, hdWallet_1.encryptPrivateKey)(bsc.privateKey),
derivationIndex: HOT_DERIVATION_INDEX_BSC,
fundHint: 'BNB (gas) + USDT BEP20 on BSC mainnet',
});
}
main()
.then(() => process.exit(0))
.catch((e) => {
console.error(e);
process.exit(1);
});
//# sourceMappingURL=seedHotWallets.js.map