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
26 changes: 26 additions & 0 deletions migration/1770287692177-AddTotalCustodyBalanceChfAuditPeriod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/

/**
* @class
* @implements {MigrationInterface}
*/
module.exports = class AddTotalCustodyBalanceChfAuditPeriod1770287692177 {
name = 'AddTotalCustodyBalanceChfAuditPeriod1770287692177'

/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_data" ADD "totalCustodyBalanceChfAuditPeriod" float`);
}

/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "user_data" DROP COLUMN "totalCustodyBalanceChfAuditPeriod"`);
}
}
53 changes: 53 additions & 0 deletions migration/1770300000000-AddOutputDateToTransaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @typedef {import('typeorm').MigrationInterface} MigrationInterface
* @typedef {import('typeorm').QueryRunner} QueryRunner
*/

/**
* @class
* @implements {MigrationInterface}
*/
module.exports = class AddOutputDateToTransaction1770300000000 {
name = 'AddOutputDateToTransaction1770300000000';

/**
* @param {QueryRunner} queryRunner
*/
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "dbo"."transaction" ADD "outputDate" datetime2`);

// Populate from buy_crypto
await queryRunner.query(`
UPDATE t
SET t."outputDate" = bc."outputDate"
FROM "dbo"."transaction" t
INNER JOIN "dbo"."buy_crypto" bc ON bc."transactionId" = t."id"
WHERE bc."outputDate" IS NOT NULL
`);

// Populate from buy_fiat
await queryRunner.query(`
UPDATE t
SET t."outputDate" = bf."outputDate"
FROM "dbo"."transaction" t
INNER JOIN "dbo"."buy_fiat" bf ON bf."transactionId" = t."id"
WHERE bf."outputDate" IS NOT NULL
`);

// Populate from ref_reward
await queryRunner.query(`
UPDATE t
SET t."outputDate" = rr."outputDate"
FROM "dbo"."transaction" t
INNER JOIN "dbo"."ref_reward" rr ON rr."transactionId" = t."id"
WHERE rr."outputDate" IS NOT NULL
`);
}

/**
* @param {QueryRunner} queryRunner
*/
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "dbo"."transaction" DROP COLUMN "outputDate"`);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CustodyOrderService } from 'src/subdomains/core/custody/services/custod
import { LiquidityOrderContext } from 'src/subdomains/supporting/dex/entities/liquidity-order.entity';
import { DexService } from 'src/subdomains/supporting/dex/services/dex.service';
import { FeeService } from 'src/subdomains/supporting/payment/services/fee.service';
import { TransactionService } from 'src/subdomains/supporting/payment/services/transaction.service';
import { PayoutOrderContext } from 'src/subdomains/supporting/payout/entities/payout-order.entity';
import { PayoutRequest } from 'src/subdomains/supporting/payout/interfaces';
import { PayoutService } from 'src/subdomains/supporting/payout/services/payout.service';
Expand Down Expand Up @@ -39,6 +40,7 @@ export class BuyCryptoOutService {
private readonly fiatService: FiatService,
private readonly custodyOrderService: CustodyOrderService,
private readonly feeService: FeeService,
private readonly transactionService: TransactionService,
) {}

async payoutTransactions(): Promise<void> {
Expand Down Expand Up @@ -201,6 +203,8 @@ export class BuyCryptoOutService {

await this.buyCryptoRepo.save(tx);

if (tx.transaction) await this.transactionService.completeTransaction(tx.transaction.id, tx.outputDate);

const custodyOrder = await this.custodyOrderService.getCustodyOrderByTx(tx);

if (custodyOrder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { LiquidityOrderContext } from 'src/subdomains/supporting/dex/entities/li
import { DexService } from 'src/subdomains/supporting/dex/services/dex.service';
import { PayoutOrderContext } from 'src/subdomains/supporting/payout/entities/payout-order.entity';
import { PayoutRequest } from 'src/subdomains/supporting/payout/interfaces';
import { TransactionService } from 'src/subdomains/supporting/payment/services/transaction.service';
import { PayoutService } from 'src/subdomains/supporting/payout/services/payout.service';
import { RefReward, RewardStatus } from '../ref-reward.entity';
import { RefRewardRepository } from '../ref-reward.repository';
Expand All @@ -19,13 +20,14 @@ export class RefRewardOutService {
private readonly payoutService: PayoutService,
private readonly dexService: DexService,
private readonly refRewardService: RefRewardService,
private readonly transactionService: TransactionService,
) {}

async checkPaidTransaction(): Promise<void> {
try {
const transactionsPaidOut = await this.refRewardRepo.find({
where: { status: RewardStatus.PAYING_OUT },
relations: { user: true },
relations: { user: true, transaction: true },
});

await this.checkCompletion(transactionsPaidOut);
Expand Down Expand Up @@ -94,6 +96,8 @@ export class RefRewardOutService {
if (isComplete) {
await this.refRewardRepo.update(...tx.complete(payoutTxId));

if (tx.transaction) await this.transactionService.completeTransaction(tx.transaction.id, tx.outputDate);

await this.dexService.completeOrders(LiquidityOrderContext.REF_PAYOUT, tx.id.toString());

await this.refRewardService.updatePaidRefCredit([tx.user?.id]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { PayInStatus } from 'src/subdomains/supporting/payin/entities/crypto-inp
import { CryptoPaymentMethod, FiatPaymentMethod } from 'src/subdomains/supporting/payment/dto/payment-method.enum';
import { FeeService } from 'src/subdomains/supporting/payment/services/fee.service';
import { TransactionHelper } from 'src/subdomains/supporting/payment/services/transaction-helper';
import { TransactionService } from 'src/subdomains/supporting/payment/services/transaction.service';
import { Price, PriceStep } from 'src/subdomains/supporting/pricing/domain/entities/price';
import {
PriceCurrency,
Expand Down Expand Up @@ -44,6 +45,7 @@ export class BuyFiatPreparationService {
private readonly countryService: CountryService,
private readonly buyFiatNotificationService: BuyFiatNotificationService,
private readonly fiatOutputService: FiatOutputService,
private readonly transactionService: TransactionService,
) {}

async doAmlCheck(): Promise<void> {
Expand Down Expand Up @@ -365,6 +367,9 @@ export class BuyFiatPreparationService {
...entity.complete(entity.fiatOutput.remittanceInfo, entity.fiatOutput.outputDate, entity.fiatOutput.bankTx),
);

if (entity.transaction)
await this.transactionService.completeTransaction(entity.transaction.id, entity.outputDate);

// send webhook
await this.buyFiatService.triggerWebhook(entity);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export class KycFileListEntry {
pep?: boolean;
complexOrgStructure?: boolean;
totalVolumeChfAuditPeriod?: number;
totalCustodyBalanceChfAuditPeriod?: number;
}

export class KycFileYearlyStats {
Expand Down
1 change: 1 addition & 0 deletions src/subdomains/generic/support/support.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export class SupportService {
pep: userData.pep,
complexOrgStructure: userData.complexOrgStructure,
totalVolumeChfAuditPeriod: userData.totalVolumeChfAuditPeriod,
totalCustodyBalanceChfAuditPeriod: userData.totalCustodyBalanceChfAuditPeriod,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ export class UpdateUserDataDto {
@IsNumber()
totalVolumeChfAuditPeriod?: number;

@IsOptional()
@IsNumber()
totalCustodyBalanceChfAuditPeriod?: number;

@IsOptional()
@IsBoolean()
olkypayAllowed?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export class UserData extends IEntity {
@Column({ type: 'float', nullable: true })
totalVolumeChfAuditPeriod?: number;

@Column({ type: 'float', nullable: true })
totalCustodyBalanceChfAuditPeriod?: number;

// TODO remove
@Column({ length: 256, nullable: true })
allBeneficialOwnersName?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export class UserDataService {
'userData.pep',
'userData.complexOrgStructure',
'userData.totalVolumeChfAuditPeriod',
'userData.totalCustodyBalanceChfAuditPeriod',
'country.name',
])
.where('userData.kycFileId > 0')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export class Transaction extends IEntity {
@Column({ type: 'datetime2', nullable: true })
mailSendDate?: Date;

@Column({ type: 'datetime2', nullable: true })
outputDate?: Date;

// References
@OneToOne(() => BuyCrypto, (buyCrypto) => buyCrypto.transaction, { nullable: true })
buyCrypto?: BuyCrypto;
Expand Down Expand Up @@ -183,6 +186,6 @@ export class Transaction extends IEntity {
}

get completionDate(): Date | undefined {
return this.buyCrypto?.outputDate ?? this.buyFiat?.outputDate ?? this.refReward?.outputDate;
return this.outputDate ?? this.buyCrypto?.outputDate ?? this.buyFiat?.outputDate ?? this.refReward?.outputDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ export class TransactionService {
return this.repo.find({ where: { userData: { id: userDataId } }, relations });
}

async completeTransaction(transactionId: number, outputDate: Date): Promise<void> {
await this.repo.update(transactionId, { outputDate });
}

async getTransactionByKey(key: string, value: any): Promise<Transaction> {
return this.repo
.createQueryBuilder('transaction')
Expand Down
Loading