Skip to content

Commit

Permalink
ignore when init failed
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoch05 committed Aug 19, 2024
1 parent abcdb8c commit 8c3eec7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/relayer/relayer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,24 @@ export class RelayerService implements OnModuleInit {
fromToken.address,
fromWallet.wallet
);
fromTokenDecimals = await fromTokenContract.decimals();
try {
fromTokenDecimals = await fromTokenContract.decimals();
} catch (err) {
this.logger.warn(`[${fromChainInfo.chainName}]get token decimals failed, err ${err}`);
fromTokenDecimals = -1;
}
}
if (toToken.address !== zeroAddress) {
toTokenContract = new Erc20Contract(
toToken.address,
toWallet.wallet
);
toTokenDecimals = await toTokenContract.decimals();
try {
toTokenDecimals = await toTokenContract.decimals();
} catch (err) {
this.logger.warn(`[${toChainInfo.chainName}]get token decimals failed, err ${err}`);
toTokenDecimals = -1;
}
}
return {
fromAddress: fromToken.address,
Expand Down Expand Up @@ -418,6 +428,9 @@ export class RelayerService implements OnModuleInit {
if (!lnBridge.minProfit || !lnBridge.maxProfit) return;
if (fromChainInfo.adjustingFee) return;
if (lnProviderInfo.swapRate < 0.01) return;
if (lnProviderInfo.fromTokenDecimals === -1) {
lnProviderInfo.fromTokenDecimals = await lnProviderInfo.fromToken.decimals();
}
let srcDecimals = lnProviderInfo.fromTokenDecimals;
// native fee decimals = 10**18
function nativeFeeToToken(fee: bigint): bigint {
Expand Down Expand Up @@ -779,6 +792,9 @@ export class RelayerService implements OnModuleInit {
let nativeFeeUsed = BigInt(0);
// relay for each token configured
for (const lnProvider of bridge.lnProviders) {
if (lnProvider.fromTokenDecimals === -1) {
lnProvider.fromTokenDecimals = await lnProvider.fromToken.decimals();
}
let srcDecimals = lnProvider.fromTokenDecimals;
if (lnProvider.useDynamicBaseFee && needUpdateDynamicFee) {
if (nativeFeeUsed <= 0) {
Expand Down

0 comments on commit 8c3eec7

Please sign in to comment.