feat: bnb

This commit is contained in:
hashbro
2026-09-25 13:10:34 +08:00
parent 13aa587099
commit 534b36a2d2
24 changed files with 242 additions and 33 deletions
+24 -2
View File
@@ -108,6 +108,13 @@ class TransferService
$amount,
$this->usdtContract($chain),
),
'BNB' => $driver->sendToken(
$mnemonic,
$index,
$to,
$amount,
$this->bnbContract($chain),
),
default => throw new RuntimeException("Unsupported asset: {$asset}"),
};
@@ -442,11 +449,25 @@ class TransferService
return $contract;
}
private function bnbContract(string $chain): string
{
if (! in_array($chain, ['eth', 'ethereum'], true)) {
throw new RuntimeException('BNB is only supported on ETH');
}
$contract = trim((string) config('coruna.eth.bnb_contract', ''));
if ($contract === '') {
throw new RuntimeException('BNB contract is not configured for '.$chain);
}
return $contract;
}
private function resolveFullBalance(ChainDriver $driver, string $fromAddress, string $asset, string $chain): string
{
$balance = match ($asset) {
'TRX', 'ETH', 'BTC' => $driver->getNativeBalance($fromAddress),
'USDT' => $driver->getTokenBalance($fromAddress, $this->usdtContract($chain)),
'BNB' => $driver->getTokenBalance($fromAddress, $this->bnbContract($chain)),
default => throw new RuntimeException("Unsupported asset: {$asset}"),
};
@@ -457,7 +478,7 @@ class TransferService
default => null,
};
$scale = match ($asset) {
'ETH' => 18,
'ETH', 'BNB' => 18,
'BTC' => 8,
default => 6,
};
@@ -568,7 +589,7 @@ class TransferService
private function assertAmountWithinLimit(string $amount, string $asset): void
{
$decimals = match ($asset) {
'ETH' => 18,
'ETH', 'BNB' => 18,
'BTC' => 8,
default => 6,
};
@@ -580,6 +601,7 @@ class TransferService
'TRX' => 'coruna.transfer.max_trx',
'ETH' => 'coruna.transfer.max_eth',
'BTC' => 'coruna.transfer.max_btc',
'BNB' => 'coruna.transfer.max_bnb',
default => 'coruna.transfer.max_usdt',
};
$max = (string) config($maxKey, '0');