Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
298 changes: 298 additions & 0 deletions migration/1779802432879-AddForeignKeyIndexes.js

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions src/integration/tatum/services/tatum-webhook.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@nestjs/common';
import { Network as TatumNetwork, TatumSDK, Solana as TatumSolana, Tron as TatumTron } from '@tatumio/tatum';
import { Observable, Subject } from 'rxjs';
import { Config, Environment } from 'src/config/config';
import { Blockchain } from 'src/integration/blockchain/shared/enums/blockchain.enum';
import { Util } from 'src/shared/utils/util';
import { CreateTatumWebhookDto, TatumWebhookDto } from '../dto/tatum.dto';
import { TatumNetworkMapper } from '../tatum-network-mapper';
Expand Down Expand Up @@ -56,6 +57,16 @@ export class TatumWebhookService {
).then((s) => s.map((s) => s.data.id));
}

async hasAddressSubscription(blockchain: Blockchain, address: string): Promise<boolean> {
const network = TatumNetworkMapper.toTatumNetworkByBlockchain(blockchain);
if (!network) return false;

const tatumSdk = await this.getTatumSdk(network);
const result = await tatumSdk.notification.getAll({ pageSize: 50, address });

return result.data?.length > 0;
}

getAddressWebhookObservable(): Observable<TatumWebhookDto> {
return this.addressWebhookSubject.asObservable();
}
Expand Down
3 changes: 2 additions & 1 deletion src/shared/models/fiat/fiat.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AmlRule } from 'src/subdomains/core/aml/enums/aml-rule.enum';
import { PriceRule } from 'src/subdomains/supporting/pricing/domain/entities/price-rule.entity';
import { Column, Entity, ManyToOne } from 'typeorm';
import { Column, Entity, Index, ManyToOne } from 'typeorm';
import { IEntity } from '../entity';

export interface IbanCountryConfig {
Expand Down Expand Up @@ -34,6 +34,7 @@ export class Fiat extends IEntity {
@Column({ default: true })
refundEnabled: boolean;

@Index()
@ManyToOne(() => PriceRule)
priceRule: PriceRule;

Expand Down
4 changes: 3 additions & 1 deletion src/shared/models/ip-log/ip-log.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IEntity } from 'src/shared/models/entity';
import { UserData } from 'src/subdomains/generic/user/models/user-data/user-data.entity';
import { User } from 'src/subdomains/generic/user/models/user/user.entity';
import { WalletType } from 'src/subdomains/generic/user/models/user/user.enum';
import { Column, Entity, ManyToOne } from 'typeorm';
import { Column, Entity, Index, ManyToOne } from 'typeorm';

@Entity()
export class IpLog extends IEntity {
Expand All @@ -24,9 +24,11 @@ export class IpLog extends IEntity {
@Column({ length: 256, nullable: true })
walletType?: WalletType;

@Index()
@ManyToOne(() => User, { nullable: true })
user?: User;

@Index()
@ManyToOne(() => UserData, { nullable: true })
userData?: UserData;
}
3 changes: 2 additions & 1 deletion src/shared/models/reward.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IEntity } from 'src/shared/models/entity';
import { Column, ManyToOne } from 'typeorm';
import { Column, Index, ManyToOne } from 'typeorm';
import { Asset } from './asset/asset.entity';

export class Reward extends IEntity {
Expand All @@ -24,6 +24,7 @@ export class Reward extends IEntity {
@Column({ type: 'float', nullable: true })
outputAmount?: number;

@Index()
@ManyToOne(() => Asset, { eager: true, nullable: true })
outputAsset?: Asset;

Expand Down
4 changes: 2 additions & 2 deletions src/shared/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { XMLParser, XMLValidator } from 'fast-xml-parser';
import { readFile } from 'fs';
import { isEqual } from 'lodash';
import sanitizeHtml from 'sanitize-html';
import { FindOperator, Like } from 'typeorm';
import { FindOperator, ILike } from 'typeorm';
import { IEntity, UpdateResult } from '../models/entity';

export type KeyType<T, U> = {
Expand Down Expand Up @@ -501,7 +501,7 @@ export class Util {
// --- DB --- //

static contains(search: string): FindOperator<string> {
return Like(`%${search}%`);
return ILike(`%${search}%`);
}

// --- MISC --- //
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Asset } from 'src/shared/models/asset/asset.entity';
import { IEntity, UpdateResult } from 'src/shared/models/entity';
import { Util } from 'src/shared/utils/util';
import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from 'typeorm';
import { Column, Entity, Index, JoinColumn, ManyToOne, OneToOne } from 'typeorm';
import { BuyCrypto } from './buy-crypto.entity';

@Entity()
Expand All @@ -10,6 +10,7 @@ export class BuyCryptoFee extends IEntity {
@JoinColumn()
buyCrypto: BuyCrypto;

@Index()
@ManyToOne(() => Asset, { eager: true, nullable: false })
feeReferenceAsset: Asset;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { SpecialExternalAccount } from 'src/subdomains/supporting/payment/entiti
import { Transaction } from 'src/subdomains/supporting/payment/entities/transaction.entity';
import { Price, PriceStep } from 'src/subdomains/supporting/pricing/domain/entities/price';
import { PriceCurrency } from 'src/subdomains/supporting/pricing/services/pricing.service';
import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from 'typeorm';
import { Column, Entity, Index, JoinColumn, ManyToOne, OneToOne } from 'typeorm';
import { AmlReason } from '../../../aml/enums/aml-reason.enum';
import { CheckStatus } from '../../../aml/enums/check-status.enum';
import { Buy } from '../../routes/buy/buy.entity';
Expand Down Expand Up @@ -78,16 +78,19 @@ export class BuyCrypto extends IEntity {
@JoinColumn()
checkoutTx?: CheckoutTx;

@Index()
@ManyToOne(() => Buy, (buy) => buy.buyCryptos, { nullable: true })
buy?: Buy;

@OneToOne(() => CryptoInput, { nullable: true })
@JoinColumn()
cryptoInput?: CryptoInput;

@Index()
@ManyToOne(() => Swap, (cryptoRoute) => cryptoRoute.buyCryptos, { nullable: true })
cryptoRoute?: Swap;

@Index()
@ManyToOne(() => BuyCryptoBatch, (batch) => batch.transactions, { eager: true, nullable: true })
batch?: BuyCryptoBatch;

Expand Down
3 changes: 3 additions & 0 deletions src/subdomains/core/buy-crypto/routes/buy/buy.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ export class Buy extends IEntity {
@Column({ default: true })
active: boolean;

@Index()
@ManyToOne(() => User, (user) => user.buys)
user: User;

@Index()
@ManyToOne(() => Asset, { eager: true, nullable: true })
asset?: Asset;

@Index()
@ManyToOne(() => Deposit, { eager: true, nullable: true })
deposit?: Deposit;

Expand Down
4 changes: 3 additions & 1 deletion src/subdomains/core/buy-crypto/routes/swap/swap.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { PaymentLink } from 'src/subdomains/core/payment-link/entities/payment-l
import { Route } from 'src/subdomains/core/route/route.entity';
import { User } from 'src/subdomains/generic/user/models/user/user.entity';
import { CryptoInput } from 'src/subdomains/supporting/payin/entities/crypto-input.entity';
import { ChildEntity, Column, JoinColumn, ManyToOne, OneToMany, OneToOne } from 'typeorm';
import { ChildEntity, Column, Index, JoinColumn, ManyToOne, OneToMany, OneToOne } from 'typeorm';
import { Deposit } from '../../../../supporting/address-pool/deposit/deposit.entity';
import { DepositRoute, RouteType } from '../../../../supporting/address-pool/route/deposit-route.entity';

Expand All @@ -22,9 +22,11 @@ export class Swap extends DepositRoute {
@ManyToOne(() => User, (user) => user.swaps, { nullable: false })
declare user: User;

@Index()
@ManyToOne(() => Asset, { eager: true, nullable: true })
asset?: Asset;

@Index()
@ManyToOne(() => Deposit, { eager: true, nullable: true })
targetDeposit?: Deposit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { CustodyAccount } from './custody-account.entity';
@Entity()
@Index((a: CustodyAccountAccess) => [a.account, a.userData], { unique: true })
export class CustodyAccountAccess extends IEntity {
@Index()
@ManyToOne(() => CustodyAccount, (custodyAccount) => custodyAccount.accessGrants, { nullable: false })
account: CustodyAccount;

@Index()
@ManyToOne(() => UserData, { nullable: false })
userData: UserData;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IEntity } from 'src/shared/models/entity';
import { UserData } from 'src/subdomains/generic/user/models/user-data/user-data.entity';
import { Column, Entity, ManyToOne, OneToMany } from 'typeorm';
import { Column, Entity, Index, ManyToOne, OneToMany } from 'typeorm';
import { CustodyAccountStatus } from '../enums/custody';
import { CustodyAccountAccess } from './custody-account-access.entity';

Expand All @@ -12,6 +12,7 @@ export class CustodyAccount extends IEntity {
@Column({ type: 'text', nullable: true })
description?: string;

@Index()
@ManyToOne(() => UserData, { nullable: false })
owner: UserData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ export class CustodyBalance extends IEntity {
@Column({ type: 'float', default: 0 })
balance: number;

@Index()
@ManyToOne(() => User, (user) => user.custodyBalances, { nullable: false, eager: true })
user: User;

@Index()
@ManyToOne(() => Asset, { nullable: false, eager: true })
asset: Asset;

@Index()
@ManyToOne(() => CustodyAccount, { nullable: true })
account?: CustodyAccount;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { IEntity, UpdateResult } from 'src/shared/models/entity';
import { Util } from 'src/shared/utils/util';
import { Column, Entity, ManyToOne } from 'typeorm';
import { Column, Entity, Index, ManyToOne } from 'typeorm';
import { CustodyOrderStepCommand, CustodyOrderStepContext, CustodyOrderStepStatus } from '../enums/custody';
import { CustodyOrder } from './custody-order.entity';

@Entity()
export class CustodyOrderStep extends IEntity {
@Index()
@ManyToOne(() => CustodyOrder, (order) => order.steps, { nullable: false, eager: true })
order: CustodyOrder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { UserData } from 'src/subdomains/generic/user/models/user-data/user-data
import { User } from 'src/subdomains/generic/user/models/user/user.entity';
import { TransactionRequest } from 'src/subdomains/supporting/payment/entities/transaction-request.entity';
import { Transaction } from 'src/subdomains/supporting/payment/entities/transaction.entity';
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, OneToOne } from 'typeorm';
import { Column, Entity, Index, JoinColumn, ManyToOne, OneToMany, OneToOne } from 'typeorm';
import { Buy } from '../../buy-crypto/routes/buy/buy.entity';
import { Swap } from '../../buy-crypto/routes/swap/swap.entity';
import { Sell } from '../../sell-crypto/route/sell.entity';
Expand Down Expand Up @@ -42,6 +42,7 @@ export class CustodyOrder extends IEntity {
@ManyToOne(() => CustodyAccount, { nullable: true })
account?: CustodyAccount;

@Index()
@ManyToOne(() => UserData, { nullable: true })
initiatedBy?: UserData;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Asset } from 'src/shared/models/asset/asset.entity';
import { IEntity, UpdateResult } from 'src/shared/models/entity';
import { UserData } from 'src/subdomains/generic/user/models/user-data/user-data.entity';
import { User } from 'src/subdomains/generic/user/models/user/user.entity';
import { Column, Entity, ManyToOne } from 'typeorm';
import { Column, Entity, Index, ManyToOne } from 'typeorm';
import { FaucetRequestStatus } from '../enums/faucet-request';

@Entity()
Expand All @@ -13,12 +13,15 @@ export class FaucetRequest extends IEntity {
@Column({ type: 'float' })
amount: number;

@Index()
@ManyToOne(() => Asset, { eager: true, nullable: false })
asset: Asset;

@Index()
@ManyToOne(() => UserData, (userData) => userData.faucetRequests, { nullable: false })
userData: UserData;

@Index()
@ManyToOne(() => User, { nullable: false })
user: User;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IEntity } from 'src/shared/models/entity';
import { Column, Entity, JoinColumn, ManyToOne } from 'typeorm';
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { LiquidityManagementSystem } from '../enums';

@Entity()
Expand All @@ -16,10 +16,12 @@ export class LiquidityManagementAction extends IEntity {
@Column({ type: 'text', nullable: true })
params?: string;

@Index()
@ManyToOne(() => LiquidityManagementAction, { nullable: true })
@JoinColumn()
onSuccess?: LiquidityManagementAction | null;

@Index()
@ManyToOne(() => LiquidityManagementAction, { nullable: true })
@JoinColumn()
onFail?: LiquidityManagementAction | null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Active } from 'src/shared/models/active';
import { IEntity } from 'src/shared/models/entity';
import { Price, PriceStep } from 'src/subdomains/supporting/pricing/domain/entities/price';
import { Column, Entity, JoinTable, ManyToOne } from 'typeorm';
import { Column, Entity, Index, JoinTable, ManyToOne } from 'typeorm';
import { LiquidityManagementOrderStatus } from '../enums';
import { OrderFailedException } from '../exceptions/order-failed.exception';
import { OrderNotProcessableException } from '../exceptions/order-not-processable.exception';
Expand Down Expand Up @@ -31,13 +31,15 @@ export class LiquidityManagementOrder extends IEntity {
@Column({ length: 256, nullable: true })
outputAsset?: string;

@Index()
@ManyToOne(() => LiquidityManagementPipeline, (liquidityPipeline) => liquidityPipeline.buyCryptos, {
eager: true,
nullable: false,
})
@JoinTable()
pipeline: LiquidityManagementPipeline;

@Index()
@ManyToOne(() => LiquidityManagementAction, { eager: true, nullable: false })
@JoinTable()
action: LiquidityManagementAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ export class LiquidityManagementPipeline extends IEntity {
@Column({ type: 'float', nullable: true })
maxAmount?: number;

@Index()
@ManyToOne(() => LiquidityManagementAction, { eager: true, nullable: true })
@JoinTable()
currentAction?: LiquidityManagementAction;

@Index()
@ManyToOne(() => LiquidityManagementAction, { eager: true, nullable: true })
@JoinTable()
previousAction?: LiquidityManagementAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class LiquidityManagementRule extends IEntity {
@JoinColumn()
targetAsset?: Asset;

@Index()
@ManyToOne(() => Fiat, { eager: true, nullable: true })
targetFiat?: Fiat;

Expand All @@ -38,9 +39,11 @@ export class LiquidityManagementRule extends IEntity {
@Column({ type: 'float', nullable: true })
limit?: number;

@Index()
@ManyToOne(() => LiquidityManagementAction, { eager: true, nullable: true })
deficitStartAction?: LiquidityManagementAction;

@Index()
@ManyToOne(() => LiquidityManagementAction, { eager: true, nullable: true })
redundancyStartAction?: LiquidityManagementAction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class PaymentActivation extends IEntity {
@Column()
method: TransferMethod;

@Index()
@ManyToOne(() => Asset, { nullable: false, eager: true })
asset: Asset;

Expand All @@ -36,9 +37,11 @@ export class PaymentActivation extends IEntity {
@Column({ length: 256 })
standard: PaymentStandard;

@Index()
@ManyToOne(() => PaymentLinkPayment, (p) => p.activations, { nullable: false })
payment: PaymentLinkPayment;

@Index()
@ManyToOne(() => PaymentQuote, (q) => q.activations, { nullable: true })
quote?: PaymentQuote;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export class PaymentLinkPayment extends IEntity {
@Column({ type: 'float' })
amount: number;

@Index()
@ManyToOne(() => Fiat, { nullable: false, eager: true })
currency: Fiat;

Expand Down
Loading
Loading