Skip to content
11 changes: 9 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { AppController } from './app.controller';
import { SharedModule } from './shared/shared.module';
import { GetConfig } from './config/config';
import { IntegrationModule } from './integration/integration.module';
import { LoggerModule } from './logger/logger.module';
import { SharedModule } from './shared/shared.module';
import { SubdomainsModule } from './subdomains/subdomains.module';

@Module({
imports: [TypeOrmModule.forRoot(GetConfig().database), SharedModule, IntegrationModule, SubdomainsModule],
imports: [
TypeOrmModule.forRoot(GetConfig().database),
SharedModule,
IntegrationModule,
SubdomainsModule,
LoggerModule,
],
controllers: [AppController],
providers: [],
exports: [],
Expand Down
10 changes: 7 additions & 3 deletions src/integration/alchemy/controllers/alchemy.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {
import { AuthGuard } from '@nestjs/passport';
import { ApiBearerAuth, ApiExcludeEndpoint, ApiTags } from '@nestjs/swagger';
import { Request } from 'express';
import { DfxLogger } from 'src/logger/dfx-logger.service';
import { LoggerFactory } from 'src/logger/logger.factory';
import { RoleGuard } from 'src/shared/auth/role.guard';
import { UserActiveGuard } from 'src/shared/auth/user-active.guard';
import { UserRole } from 'src/shared/auth/user-role.enum';
import { DfxLogger } from 'src/shared/services/dfx-logger';
import { AlchemySyncTransactionsDto } from '../dto/alchemy-sync-transactions.dto';
import { AlchemyWebhookDto } from '../dto/alchemy-webhook.dto';
import { AlchemyWebhookService } from '../services/alchemy-webhook.service';
Expand All @@ -25,12 +26,15 @@ import { AlchemyService } from '../services/alchemy.service';
@ApiTags('Alchemy')
@Controller('alchemy')
export class AlchemyController {
private readonly logger = new DfxLogger(AlchemyController);
private readonly logger: DfxLogger;

constructor(
readonly loggerFactory: LoggerFactory,
private readonly alchemyWebhookService: AlchemyWebhookService,
private readonly alchemyService: AlchemyService,
) {}
) {
this.logger = loggerFactory.create(AlchemyController);
}

@Post('addressWebhook')
@ApiExcludeEndpoint()
Expand Down
9 changes: 5 additions & 4 deletions src/integration/alchemy/services/alchemy-webhook.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,24 @@ import {
} from 'alchemy-sdk';
import { Observable, Subject, filter } from 'rxjs';
import { Config, GetConfig } from 'src/config/config';
import { DfxLogger } from 'src/shared/services/dfx-logger';
import { DfxLogger } from 'src/logger/dfx-logger.service';
import { LoggerFactory } from 'src/logger/logger.factory';
import { Util } from 'src/shared/utils/util';
import { AlchemyNetworkMapper } from '../alchemy-network-mapper';
import { CreateWebhookDto } from '../dto/alchemy-create-webhook.dto';
import { AlchemyWebhookDto } from '../dto/alchemy-webhook.dto';

@Injectable()
export class AlchemyWebhookService implements OnModuleInit {
private readonly logger = new DfxLogger(AlchemyWebhookService);

private readonly logger: DfxLogger;
private readonly alchemy: Alchemy;
private readonly webhookCache: Map<string, string>;

private readonly addressWebhookSubject: Subject<AlchemyWebhookDto>;

constructor() {
constructor(readonly loggerFactory: LoggerFactory) {
const config = GetConfig();
this.logger = loggerFactory.create(AlchemyWebhookService);

const settings = {
apiKey: config.alchemy.apiKey,
Expand Down
10 changes: 6 additions & 4 deletions src/integration/bank/services/olkypay.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Injectable } from '@nestjs/common';
import { Method } from 'axios';
import { stringify } from 'qs';
import { Config } from 'src/config/config';
import { DfxLogger } from 'src/shared/services/dfx-logger';
import { DfxLogger } from 'src/logger/dfx-logger.service';
import { LoggerFactory } from 'src/logger/logger.factory';
import { HttpService } from 'src/shared/services/http.service';
import { Util } from 'src/shared/utils/util';
import { BankTx, BankTxIndicator, BankTxType } from 'src/subdomains/supporting/bank-tx/bank-tx/entities/bank-tx.entity';
Expand Down Expand Up @@ -43,14 +44,15 @@ enum TransactionType {

@Injectable()
export class OlkypayService {
private readonly logger = new DfxLogger(OlkypayService);

private readonly logger: DfxLogger;
private readonly baseUrl = 'https://ws.olkypay.com/reporting';
private readonly loginUrl = 'https://stp.olkypay.com/auth/realms/b2b/protocol/openid-connect/token';

private accessToken = 'access-token-will-be-updated';

constructor(private readonly http: HttpService) {}
constructor(private readonly http: HttpService, readonly loggerFactory: LoggerFactory) {
this.logger = loggerFactory.create(OlkypayService);
}

async getOlkyTransactions(lastModificationTime: string, accountIban: string): Promise<Partial<BankTx>[]> {
if (!Config.bank.olkypay.credentials.clientId) return [];
Expand Down
10 changes: 6 additions & 4 deletions src/integration/bank/services/revolut.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Injectable } from '@nestjs/common';
import { Method } from 'axios';
import { stringify } from 'qs';
import { Config } from 'src/config/config';
import { DfxLogger } from 'src/shared/services/dfx-logger';
import { DfxLogger } from 'src/logger/dfx-logger.service';
import { LoggerFactory } from 'src/logger/logger.factory';
import { HttpService } from 'src/shared/services/http.service';
import { Util } from 'src/shared/utils/util';
import { BankTx, BankTxIndicator } from 'src/subdomains/supporting/bank-tx/bank-tx/entities/bank-tx.entity';
Expand Down Expand Up @@ -96,14 +97,15 @@ enum TransactionType {

@Injectable()
export class RevolutService {
private readonly logger = new DfxLogger(RevolutService);

private readonly logger: DfxLogger;
private readonly baseUrl = 'https://b2b.revolut.com/api/1.0';
private readonly loginUrl = 'https://b2b.revolut.com/api/1.0/auth/token';

private accessToken = 'access-token-will-be-updated';

constructor(private readonly http: HttpService) {}
constructor(private readonly http: HttpService, readonly loggerFactory: LoggerFactory) {
this.logger = loggerFactory.create(RevolutService);
}

async getRevolutTransactions(lastModificationTime: string, accountIban: string): Promise<Partial<BankTx>[]> {
if (!Config.bank.revolut.clientAssertion || !Config.bank.revolut.refreshToken) return [];
Expand Down
6 changes: 2 additions & 4 deletions src/integration/binance-pay/services/binance-pay.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BadRequestException, Injectable, ServiceUnavailableException } from '@nestjs/common';
import * as crypto from 'crypto';
import { Config } from 'src/config/config';
import { DfxLogger } from 'src/shared/services/dfx-logger';
import { LoggerFactory } from 'src/logger/logger.factory';
import { HttpService } from 'src/shared/services/http.service';
import { Util } from 'src/shared/utils/util';
import { TransferInfo } from 'src/subdomains/core/payment-link/dto/payment-link.dto';
Expand Down Expand Up @@ -35,8 +35,6 @@ import {

@Injectable()
export class BinancePayService implements C2BPaymentLinkProvider<BinancePayWebhookDto> {
private readonly logger = new DfxLogger(BinancePayService);

private readonly baseUrl = 'https://bpay.binanceapi.com';
private readonly apiKey: string;
private readonly secretKey: string;
Expand All @@ -49,7 +47,7 @@ export class BinancePayService implements C2BPaymentLinkProvider<BinancePayWebho
BinanceBizType.MERCHANT_QR_CODE,
];

constructor(private readonly http: HttpService) {
constructor(private readonly http: HttpService, readonly loggerFactory: LoggerFactory) {
this.apiKey = Config.payment.binancePayPublic;
this.secretKey = Config.payment.binancePaySecret;
this.certificatedExpiry = 0;
Expand Down
6 changes: 4 additions & 2 deletions src/integration/blockchain/arbitrum/arbitrum-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import {
} from '@arbitrum/sdk/dist/lib/message/L1Transaction';
import { Contract, ethers } from 'ethers';
import { GetConfig } from 'src/config/config';
import { DfxLogger } from 'src/logger/dfx-logger.service';
import { Asset, AssetType } from 'src/shared/models/asset/asset.entity';
import { DfxLogger } from 'src/shared/services/dfx-logger';
import { Util } from 'src/shared/utils/util';
import ERC20_ABI from '../shared/evm/abi/erc20.abi.json';
import { EvmClient, EvmClientParams } from '../shared/evm/evm-client';
import { EvmUtil } from '../shared/evm/evm.util';
import { L2BridgeEvmClient } from '../shared/evm/interfaces';

export class ArbitrumClient extends EvmClient implements L2BridgeEvmClient {
private readonly logger = new DfxLogger(ArbitrumClient);
private logger: DfxLogger;

private readonly l1Provider: ethers.providers.JsonRpcProvider;
private readonly l1Wallet: ethers.Wallet;
Expand All @@ -31,6 +31,8 @@ export class ArbitrumClient extends EvmClient implements L2BridgeEvmClient {
constructor(params: EvmClientParams) {
super(params);

this.logger = params.loggerFactory.create(ArbitrumClient);

const { ethGatewayUrl, ethApiKey, ethWalletPrivateKey } = GetConfig().blockchain.ethereum;
const ethereumGateway = `${ethGatewayUrl}/${ethApiKey ?? ''}`;

Expand Down
4 changes: 3 additions & 1 deletion src/integration/blockchain/arbitrum/arbitrum.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Injectable } from '@nestjs/common';
import { GetConfig } from 'src/config/config';
import { AlchemyService } from 'src/integration/alchemy/services/alchemy.service';
import { LoggerFactory } from 'src/logger/logger.factory';
import { HttpService } from 'src/shared/services/http.service';
import { EvmService } from '../shared/evm/evm.service';
import { ArbitrumClient } from './arbitrum-client';

@Injectable()
export class ArbitrumService extends EvmService {
constructor(http: HttpService, alchemyService: AlchemyService) {
constructor(http: HttpService, alchemyService: AlchemyService, loggerFactory: LoggerFactory) {
const {
arbitrumGatewayUrl,
arbitrumApiKey,
Expand All @@ -24,6 +25,7 @@ export class ArbitrumService extends EvmService {
apiKey: arbitrumApiKey,
walletPrivateKey: arbitrumWalletPrivateKey,
chainId: arbitrumChainId,
loggerFactory,
swapContractAddress,
quoteContractAddress,
});
Expand Down
6 changes: 4 additions & 2 deletions src/integration/blockchain/base/base-client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CrossChainMessenger, L2Provider, MessageStatus, asL2Provider, estimateTotalGasCost } from '@eth-optimism/sdk';
import { BigNumber, ethers } from 'ethers';
import { GetConfig } from 'src/config/config';
import { DfxLogger } from 'src/logger/dfx-logger.service';
import { Asset } from 'src/shared/models/asset/asset.entity';
import { DfxLogger } from 'src/shared/services/dfx-logger';
import { Util } from 'src/shared/utils/util';
import { EvmClient, EvmClientParams } from '../shared/evm/evm-client';
import { EvmUtil } from '../shared/evm/evm.util';
Expand All @@ -16,7 +16,7 @@ interface BaseTransactionReceipt extends ethers.providers.TransactionReceipt {
}

export class BaseClient extends EvmClient implements L2BridgeEvmClient {
private readonly logger = new DfxLogger(BaseClient);
private readonly logger: DfxLogger;

private readonly l1Provider: ethers.providers.JsonRpcProvider;
private readonly l1Wallet: ethers.Wallet;
Expand All @@ -26,6 +26,8 @@ export class BaseClient extends EvmClient implements L2BridgeEvmClient {
constructor(params: EvmClientParams) {
super(params);

this.logger = params.loggerFactory.create(BaseClient);

const { ethGatewayUrl, ethApiKey, ethWalletPrivateKey, ethChainId } = GetConfig().blockchain.ethereum;
const { baseChainId } = GetConfig().blockchain.base;
const ethereumGateway = `${ethGatewayUrl}/${ethApiKey ?? ''}`;
Expand Down
4 changes: 3 additions & 1 deletion src/integration/blockchain/base/base.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Injectable } from '@nestjs/common';
import { GetConfig } from 'src/config/config';
import { AlchemyService } from 'src/integration/alchemy/services/alchemy.service';
import { LoggerFactory } from 'src/logger/logger.factory';
import { HttpService } from 'src/shared/services/http.service';
import { EvmService } from '../shared/evm/evm.service';
import { BaseClient } from './base-client';

@Injectable()
export class BaseService extends EvmService {
constructor(http: HttpService, alchemyService: AlchemyService) {
constructor(http: HttpService, alchemyService: AlchemyService, loggerFactory: LoggerFactory) {
const {
baseGatewayUrl,
baseApiKey,
Expand All @@ -25,6 +26,7 @@ export class BaseService extends EvmService {
apiKey: baseApiKey,
walletPrivateKey: baseWalletPrivateKey,
chainId: baseChainId,
loggerFactory,
swapContractAddress,
swapFactoryAddress,
quoteContractAddress,
Expand Down
3 changes: 2 additions & 1 deletion src/integration/blockchain/bitcoin/bitcoin.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Module } from '@nestjs/common';
import { LoggerModule } from 'src/logger/logger.module';
import { SharedModule } from 'src/shared/shared.module';
import { BitcoinService } from './node/bitcoin.service';
import { NodeController } from './node/node.controller';
import { BitcoinFeeService } from './services/bitcoin-fee.service';

@Module({
imports: [SharedModule],
imports: [SharedModule, LoggerModule],
providers: [BitcoinService, BitcoinFeeService],
exports: [BitcoinService, BitcoinFeeService],
controllers: [NodeController],
Expand Down
11 changes: 11 additions & 0 deletions src/integration/blockchain/bitcoin/node/bitcoin-client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Currency } from '@uniswap/sdk-core';
import { Config } from 'src/config/config';
import { DfxLogger } from 'src/logger/dfx-logger.service';
import { LoggerFactory } from 'src/logger/logger.factory';
import { Asset } from 'src/shared/models/asset/asset.entity';
import { HttpService } from 'src/shared/services/http.service';
import { BlockchainTokenBalance } from '../../shared/dto/blockchain-token-balance.dto';
import { BitcoinSignedTransactionResponse } from '../../shared/dto/signed-transaction-reponse.dto';
import { NodeClient, NodeCommand } from './node-client';
Expand Down Expand Up @@ -29,6 +32,14 @@ type AddressInfoInnerArray = AddressInfoArray[];
type AddressInfoArray = [string, number, string];

export class BitcoinClient extends NodeClient {
protected readonly logger: DfxLogger;

constructor(readonly loggerFactory: LoggerFactory, http: HttpService, url: string) {
super(http, url);

this.logger = this.loggerFactory.create(BitcoinClient);
}

async send(
addressTo: string,
txId: string,
Expand Down
11 changes: 6 additions & 5 deletions src/integration/blockchain/bitcoin/node/bitcoin.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BlockchainInfo } from '@defichain/jellyfish-api-core/dist/category/blockchain';
import { BadRequestException, Injectable } from '@nestjs/common';
import { Config } from 'src/config/config';
import { DfxLogger } from 'src/shared/services/dfx-logger';
import { LoggerFactory } from 'src/logger/logger.factory';
import { HttpService } from 'src/shared/services/http.service';
import { Util } from 'src/shared/utils/util';
import { BlockchainService } from '../../shared/util/blockchain.service';
Expand All @@ -24,13 +24,14 @@ interface BitcoinCheckResult {

@Injectable()
export class BitcoinService extends BlockchainService {
private readonly logger = new DfxLogger(BitcoinService);

private readonly allNodes: Map<BitcoinNodeType, BitcoinClient> = new Map();
private readonly loggerFactory: LoggerFactory;

constructor(private readonly http: HttpService) {
constructor(private readonly http: HttpService, readonly loggerFactory2: LoggerFactory) {
super();

this.loggerFactory = loggerFactory2;

this.initAllNodes();
}

Expand Down Expand Up @@ -75,7 +76,7 @@ export class BitcoinService extends BlockchainService {
}

private createNodeClient(url: string | undefined): BitcoinClient | null {
return url ? new BitcoinClient(this.http, url) : null;
return url ? new BitcoinClient(this.loggerFactory, this.http, url) : null;
}

// --- HELPER METHODS --- //
Expand Down
5 changes: 2 additions & 3 deletions src/integration/blockchain/bitcoin/node/node-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AddressType, InWalletTransaction, UTXO } from '@defichain/jellyfish-api
import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc';
import { ServiceUnavailableException } from '@nestjs/common';
import { Config } from 'src/config/config';
import { DfxLogger } from 'src/shared/services/dfx-logger';
import { DfxLogger } from 'src/logger/dfx-logger.service';
import { HttpService } from 'src/shared/services/http.service';
import { QueueHandler } from 'src/shared/utils/queue-handler';
import { Util } from 'src/shared/utils/util';
Expand All @@ -20,8 +20,7 @@ export enum NodeCommand {
}

export abstract class NodeClient extends BlockchainClient {
private readonly logger = new DfxLogger(NodeClient);

protected abstract readonly logger: DfxLogger;
protected chain = Config.network;
private readonly client: ApiClient;
private readonly queue: QueueHandler;
Expand Down
4 changes: 3 additions & 1 deletion src/integration/blockchain/bsc/bsc.service.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Injectable } from '@nestjs/common';
import { GetConfig } from 'src/config/config';
import { AlchemyService } from 'src/integration/alchemy/services/alchemy.service';
import { LoggerFactory } from 'src/logger/logger.factory';
import { HttpService } from 'src/shared/services/http.service';
import { EvmService } from '../shared/evm/evm.service';
import { BscClient } from './bsc-client';

@Injectable()
export class BscService extends EvmService {
constructor(http: HttpService, alchemyService: AlchemyService) {
constructor(http: HttpService, alchemyService: AlchemyService, loggerFactory: LoggerFactory) {
const { bscGatewayUrl, bscApiKey, bscWalletPrivateKey, bscChainId, swapContractAddress, quoteContractAddress } =
GetConfig().blockchain.bsc;

Expand All @@ -18,6 +19,7 @@ export class BscService extends EvmService {
apiKey: bscApiKey,
walletPrivateKey: bscWalletPrivateKey,
chainId: bscChainId,
loggerFactory,
swapContractAddress,
quoteContractAddress,
});
Expand Down
Loading
Loading