From 53f22fc03c1f19e7d74f29448e3a85e3c3f09c54 Mon Sep 17 00:00:00 2001 From: Yannick1712 Date: Thu, 6 Oct 2022 01:40:41 +0200 Subject: [PATCH 1/4] [DEV-801] & [DEV-802]: min Deposit --- src/config/config.ts | 5 +++++ .../models/crypto-route/crypto-route.controller.ts | 2 +- src/payment/models/sell/sell.controller.ts | 10 ++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/config/config.ts b/src/config/config.ts index 189b2dec37..330f24ee99 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -210,6 +210,11 @@ export class Configuration { USD: 1, }, }, + minTransactionVolume: { + // min volume in output asset + USD: 1000, + EUR: 1, + }, }, ethereum: { ethWalletAddress: process.env.ETH_WALLET_ADDRESS, diff --git a/src/payment/models/crypto-route/crypto-route.controller.ts b/src/payment/models/crypto-route/crypto-route.controller.ts index d61a8ddf10..3f9bca0996 100644 --- a/src/payment/models/crypto-route/crypto-route.controller.ts +++ b/src/payment/models/crypto-route/crypto-route.controller.ts @@ -138,7 +138,7 @@ export class CryptoRouteController { case Blockchain.BITCOIN: return Util.transformToMinDeposit(Config.blockchain.default.minDeposit.Bitcoin); case Blockchain.DEFICHAIN: - return Util.transformToMinDeposit(Config.blockchain.default.minDeposit.DeFiChain); + return Util.transformToMinDeposit(Config.blockchain.default.minDeposit.DeFiChain, 'USD'); } } diff --git a/src/payment/models/sell/sell.controller.ts b/src/payment/models/sell/sell.controller.ts index 98500d80ff..8476367edf 100644 --- a/src/payment/models/sell/sell.controller.ts +++ b/src/payment/models/sell/sell.controller.ts @@ -84,7 +84,10 @@ export class SellController { ...sell, fee, isInUse: sellDepositsInUse.includes(sell.deposit.id), - minDeposits: Util.transformToMinDeposit(Config.blockchain.default.minDeposit.DeFiChain), + minDeposits: + sell.fiat.name === 'USD' + ? Util.transformToMinDeposit(Config.blockchain.default.minTransactionVolume, 'USD') + : Util.transformToMinDeposit(Config.blockchain.default.minDeposit.DeFiChain, 'USD'), }; } @@ -92,7 +95,10 @@ export class SellController { return { fee: await this.getFee(userId), depositAddress: sell.deposit.address, - minDeposits: Util.transformToMinDeposit(Config.blockchain.default.minDeposit.DeFiChain), + minDeposits: + sell.fiat.name === 'USD' + ? Util.transformToMinDeposit(Config.blockchain.default.minTransactionVolume, 'USD') + : Util.transformToMinDeposit(Config.blockchain.default.minDeposit.DeFiChain, 'USD'), }; } From 9379772b3d2812b0e86df874c76364bd4f533512 Mon Sep 17 00:00:00 2001 From: Yannick1712 Date: Fri, 7 Oct 2022 15:39:35 +0200 Subject: [PATCH 2/4] [DEV-801]&[DEV-802] change config --- src/config/config.ts | 10 +++++++--- src/payment/models/sell/sell.controller.ts | 10 ++-------- src/shared/util.ts | 12 ++++++++++++ 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/config/config.ts b/src/config/config.ts index 330f24ee99..050cef6819 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -211,9 +211,13 @@ export class Configuration { }, }, minTransactionVolume: { - // min volume in output asset - USD: 1000, - EUR: 1, + // outputAsset: { minTransactionAsset: minTransactionVolume } + USD: { + USD: 1000, + }, + default: { + USD: 1, + }, }, }, ethereum: { diff --git a/src/payment/models/sell/sell.controller.ts b/src/payment/models/sell/sell.controller.ts index 8476367edf..8e0fd83194 100644 --- a/src/payment/models/sell/sell.controller.ts +++ b/src/payment/models/sell/sell.controller.ts @@ -84,10 +84,7 @@ export class SellController { ...sell, fee, isInUse: sellDepositsInUse.includes(sell.deposit.id), - minDeposits: - sell.fiat.name === 'USD' - ? Util.transformToMinDeposit(Config.blockchain.default.minTransactionVolume, 'USD') - : Util.transformToMinDeposit(Config.blockchain.default.minDeposit.DeFiChain, 'USD'), + minDeposits: Util.getMinDeposit(sell.fiat.name), }; } @@ -95,10 +92,7 @@ export class SellController { return { fee: await this.getFee(userId), depositAddress: sell.deposit.address, - minDeposits: - sell.fiat.name === 'USD' - ? Util.transformToMinDeposit(Config.blockchain.default.minTransactionVolume, 'USD') - : Util.transformToMinDeposit(Config.blockchain.default.minDeposit.DeFiChain, 'USD'), + minDeposits: Util.getMinDeposit(sell.fiat.name), }; } diff --git a/src/shared/util.ts b/src/shared/util.ts index 0ecca0b1fc..698ab73ee2 100644 --- a/src/shared/util.ts +++ b/src/shared/util.ts @@ -1,6 +1,8 @@ import { BinaryLike, createHash, createSign, KeyLike } from 'crypto'; import { XMLValidator, XMLParser } from 'fast-xml-parser'; import { readFile } from 'fs'; +import { values } from 'lodash'; +import { Config } from 'src/config/config'; import { MinDeposit } from 'src/payment/models/deposit/dto/min-deposit.dto'; type KeyType = { @@ -171,6 +173,16 @@ export class Util { return '***' + iban.slice(iban.length - 4); } + static getMinDeposit(outputAsset: string): MinDeposit[] { + const index = Object.entries(Config.blockchain.default.minTransactionVolume) + .filter(([key, _]) => key === outputAsset) + .map(([_, value]) => value); + + return this.transformToMinDeposit( + index.length != 0 ? index[0] : Config.blockchain.default.minTransactionVolume.default, + ); + } + static transformToMinDeposit(deposit: { [asset: string]: number }, filter?: string[] | string): MinDeposit[] { return Object.entries(deposit) .filter(([key, _]) => filter?.includes(key) ?? true) From 944523e3856b336f09d01bcc0694448a04fadd67 Mon Sep 17 00:00:00 2001 From: Yannick1712 Date: Sat, 8 Oct 2022 11:31:55 +0200 Subject: [PATCH 3/4] [DEV-801] Refactoring --- src/shared/util.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/shared/util.ts b/src/shared/util.ts index 698ab73ee2..f6070923ae 100644 --- a/src/shared/util.ts +++ b/src/shared/util.ts @@ -174,13 +174,11 @@ export class Util { } static getMinDeposit(outputAsset: string): MinDeposit[] { - const index = Object.entries(Config.blockchain.default.minTransactionVolume) + const minVolume = Object.entries(Config.blockchain.default.minTransactionVolume) .filter(([key, _]) => key === outputAsset) .map(([_, value]) => value); - return this.transformToMinDeposit( - index.length != 0 ? index[0] : Config.blockchain.default.minTransactionVolume.default, - ); + return this.transformToMinDeposit(minVolume[0] ?? Config.blockchain.default.minTransactionVolume.default); } static transformToMinDeposit(deposit: { [asset: string]: number }, filter?: string[] | string): MinDeposit[] { From cebe782069026399674a996107cb82e1b817fb56 Mon Sep 17 00:00:00 2001 From: Yannick1712 Date: Sat, 8 Oct 2022 14:13:40 +0200 Subject: [PATCH 4/4] [DEV-801] move getMinDeposit --- src/payment/models/sell/sell.controller.ts | 13 +++++++++++-- src/shared/util.ts | 10 ---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/payment/models/sell/sell.controller.ts b/src/payment/models/sell/sell.controller.ts index 8e0fd83194..a03bc720b6 100644 --- a/src/payment/models/sell/sell.controller.ts +++ b/src/payment/models/sell/sell.controller.ts @@ -17,6 +17,7 @@ import { Config } from 'src/config/config'; import { Util } from 'src/shared/util'; import { GetSellPaymentInfoDto } from './dto/get-sell-payment-info.dto'; import { SellPaymentInfoDto } from './dto/sell-payment-info.dto'; +import { MinDeposit } from '../deposit/dto/min-deposit.dto'; @ApiTags('sell') @Controller('sell') @@ -84,7 +85,7 @@ export class SellController { ...sell, fee, isInUse: sellDepositsInUse.includes(sell.deposit.id), - minDeposits: Util.getMinDeposit(sell.fiat.name), + minDeposits: this.getMinDeposit(sell.fiat.name), }; } @@ -92,7 +93,7 @@ export class SellController { return { fee: await this.getFee(userId), depositAddress: sell.deposit.address, - minDeposits: Util.getMinDeposit(sell.fiat.name), + minDeposits: this.getMinDeposit(sell.fiat.name), }; } @@ -100,4 +101,12 @@ export class SellController { async getFee(userId: number): Promise { return this.userService.getUserSellFee(userId); } + + private getMinDeposit(outputAsset: string): MinDeposit[] { + const minVolume = Object.entries(Config.blockchain.default.minTransactionVolume) + .filter(([key, _]) => key === outputAsset) + .map(([_, value]) => value); + + return Util.transformToMinDeposit(minVolume[0] ?? Config.blockchain.default.minTransactionVolume.default); + } } diff --git a/src/shared/util.ts b/src/shared/util.ts index f6070923ae..0ecca0b1fc 100644 --- a/src/shared/util.ts +++ b/src/shared/util.ts @@ -1,8 +1,6 @@ import { BinaryLike, createHash, createSign, KeyLike } from 'crypto'; import { XMLValidator, XMLParser } from 'fast-xml-parser'; import { readFile } from 'fs'; -import { values } from 'lodash'; -import { Config } from 'src/config/config'; import { MinDeposit } from 'src/payment/models/deposit/dto/min-deposit.dto'; type KeyType = { @@ -173,14 +171,6 @@ export class Util { return '***' + iban.slice(iban.length - 4); } - static getMinDeposit(outputAsset: string): MinDeposit[] { - const minVolume = Object.entries(Config.blockchain.default.minTransactionVolume) - .filter(([key, _]) => key === outputAsset) - .map(([_, value]) => value); - - return this.transformToMinDeposit(minVolume[0] ?? Config.blockchain.default.minTransactionVolume.default); - } - static transformToMinDeposit(deposit: { [asset: string]: number }, filter?: string[] | string): MinDeposit[] { return Object.entries(deposit) .filter(([key, _]) => filter?.includes(key) ?? true)