From e46dd96463bb9d0c55435c4a082be5476e05fb9c Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Wed, 11 May 2022 12:36:50 +0430 Subject: [PATCH 01/44] Add preferences module to utility --- utility/pom.xml | 1 + utility/preferences/pom.xml | 15 +++++++++++++++ .../co/nilin/opex/utility/preferences/Chain.kt | 5 +++++ .../opex/utility/preferences/ChainSyncSchedule.kt | 3 +++ .../co/nilin/opex/utility/preferences/Currency.kt | 12 ++++++++++++ .../nilin/opex/utility/preferences/FeeConfig.kt | 7 +++++++ .../utility/preferences/ProjectPreferences.kt | 5 +++++ .../nilin/opex/utility/preferences/UserLevel.kt | 12 ++++++++++++ .../co/nilin/opex/utility/preferences/Wallet.kt | 12 ++++++++++++ 9 files changed, 72 insertions(+) create mode 100644 utility/preferences/pom.xml create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Chain.kt create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt diff --git a/utility/pom.xml b/utility/pom.xml index b55db498f..6216eec86 100644 --- a/utility/pom.xml +++ b/utility/pom.xml @@ -20,6 +20,7 @@ error-handler logging-handler interceptors + preferences diff --git a/utility/preferences/pom.xml b/utility/preferences/pom.xml new file mode 100644 index 000000000..2d2e9e0ff --- /dev/null +++ b/utility/preferences/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + utility + co.nilin.opex.utility + 1.0-SNAPSHOT + + + co.nilin.opex.utility.preferences + preferences + + \ No newline at end of file diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Chain.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Chain.kt new file mode 100644 index 000000000..de9113308 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Chain.kt @@ -0,0 +1,5 @@ +package co.nilin.opex.utility.preferences + +data class Chain( + var name: String, var addressType: String, val endpointUrl: String, var schedule: ChainSyncSchedule +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt new file mode 100644 index 000000000..03fef72b1 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt @@ -0,0 +1,3 @@ +package co.nilin.opex.utility.preferences + +data class ChainSyncSchedule(var chain: String, var retryTime: Long, var delay: Long, var errorDelay: Long) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt new file mode 100644 index 000000000..ea2f85aba --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt @@ -0,0 +1,12 @@ +package co.nilin.opex.utility.preferences + +import java.math.BigDecimal + +data class Currency( + var symbol: String, + var name: String, + var leftSideFraction: BigDecimal, + var rightSideFraction: BigDecimal, + var feeConfig: FeeConfig, + var precision: BigDecimal +) \ No newline at end of file diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt new file mode 100644 index 000000000..8341928a8 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt @@ -0,0 +1,7 @@ +package co.nilin.opex.utility.preferences + +import java.math.BigDecimal + +data class FeeConfig( + var direction: String, var makerFee: BigDecimal, var takerFee: BigDecimal, var userLevel: BigDecimal +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt new file mode 100644 index 000000000..75d429429 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt @@ -0,0 +1,5 @@ +package co.nilin.opex.utility.preferences + +data class ProjectPreferences( + var chains: List, var currencies: List, var wallets: List, var userLevels: List +) \ No newline at end of file diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt new file mode 100644 index 000000000..d15d57d62 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt @@ -0,0 +1,12 @@ +package co.nilin.opex.utility.preferences + +import java.math.BigDecimal + +data class UserLevel( + var level: String, + var withdrawFee: BigDecimal, + var dailyTotal: BigDecimal, + var dailyCount: Int, + var monthlyTotal: BigDecimal, + var monthlyCount: Int +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt new file mode 100644 index 000000000..6a7164092 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt @@ -0,0 +1,12 @@ +package co.nilin.opex.utility.preferences + +import java.math.BigDecimal + +data class Wallet( + var currency: String, + var mainBalance: BigDecimal, + var dailyTotal: BigDecimal, + var dailyCount: Int, + var monthlyTotal: BigDecimal, + var monthlyCount: Int +) From b212e1cc59120bc7b968780a265fefee0110f732 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Wed, 11 May 2022 13:25:56 +0430 Subject: [PATCH 02/44] Add implementations field to currency --- .../co/nilin/opex/utility/preferences/Currency.kt | 3 ++- .../utility/preferences/CurrencyImplementation.kt | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt index ea2f85aba..7f0602c3c 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt @@ -8,5 +8,6 @@ data class Currency( var leftSideFraction: BigDecimal, var rightSideFraction: BigDecimal, var feeConfig: FeeConfig, - var precision: BigDecimal + var precision: BigDecimal, + var implementations: List ) \ No newline at end of file diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt new file mode 100644 index 000000000..25a41d343 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt @@ -0,0 +1,14 @@ +package co.nilin.opex.utility.preferences + +import java.math.BigDecimal + +data class CurrencyImplementation( + var chain: String, + var token: Boolean, + var tokenAddress: String?, + var tokenName: String?, + var withdrawEnabled: Boolean, + var withdrawFee: BigDecimal, + var withdrawMin: BigDecimal, + var decimal: BigDecimal +) \ No newline at end of file From 457706caece8b15965c18f75eaa99d7226ad6a15 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Wed, 11 May 2022 13:29:21 +0430 Subject: [PATCH 03/44] Add preferences-schema.yml config file --- preferences-schema.yml | 47 +++++++++++++++++++ preferences.yml | 0 .../opex/utility/preferences/Currency.kt | 1 - .../nilin/opex/utility/preferences/Market.kt | 12 +++++ .../utility/preferences/ProjectPreferences.kt | 6 ++- .../opex/utility/preferences/UserLevel.kt | 3 ++ 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 preferences-schema.yml create mode 100644 preferences.yml create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt diff --git a/preferences-schema.yml b/preferences-schema.yml new file mode 100644 index 000000000..3c3a59a93 --- /dev/null +++ b/preferences-schema.yml @@ -0,0 +1,47 @@ +addressTypes: + - addressType: + addressRegex: +chains: + - name: + addressType: + endpointUrl: + schedule: +currencies: + - symbol: + name: + marketFraction: + precision: + implementations: + - chain: + token: + tokenAddress: + tokenName: + withdrawEnabled: + withdrawFee: + withdrawMin: + decimal: +markets: + - pair: + leftSide: + rightSide: + leftSideFraction: + rightSideFraction: + feeConfigs: + - direction: + makerFee: + takerFee: + userLevel: +wallets: + - currency: + mainBalance: + dailyTotal: + dailyCount: + monthlyTotal: + monthlyCount: +userLimits: + - level: + withdrawFee: + dailyTotal: + dailyCount: + monthlyTotal: + monthlyCount: \ No newline at end of file diff --git a/preferences.yml b/preferences.yml new file mode 100644 index 000000000..e69de29bb diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt index 7f0602c3c..bbcdd9518 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt @@ -7,7 +7,6 @@ data class Currency( var name: String, var leftSideFraction: BigDecimal, var rightSideFraction: BigDecimal, - var feeConfig: FeeConfig, var precision: BigDecimal, var implementations: List ) \ No newline at end of file diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt new file mode 100644 index 000000000..9ce127dc9 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt @@ -0,0 +1,12 @@ +package co.nilin.opex.utility.preferences + +import java.math.BigDecimal + +data class Market( + var pair: String, + var leftSide: String, + var rightSide: String, + var leftSideFraction: BigDecimal?, + var rightSideFraction: BigDecimal?, + var feeConfigs: List +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt index 75d429429..bce2bfb3c 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt @@ -1,5 +1,9 @@ package co.nilin.opex.utility.preferences data class ProjectPreferences( - var chains: List, var currencies: List, var wallets: List, var userLevels: List + var chains: List, + var currencies: List, + var markets: List, + var wallets: List, + var userLevels: List ) \ No newline at end of file diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt index d15d57d62..143398e0e 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt @@ -4,6 +4,9 @@ import java.math.BigDecimal data class UserLevel( var level: String, + var owner: String, + var action: String, + var walletType: String, var withdrawFee: BigDecimal, var dailyTotal: BigDecimal, var dailyCount: Int, From f981a8829d0e4b64fe94fb2a63a4ac25d5e8858e Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Wed, 11 May 2022 16:23:35 +0430 Subject: [PATCH 04/44] Update preferences-schema --- preferences-schema.yml | 17 +++++++++-------- .../opex/utility/preferences/AddressType.kt | 3 +++ .../utility/preferences/ProjectPreferences.kt | 1 + 3 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/AddressType.kt diff --git a/preferences-schema.yml b/preferences-schema.yml index 3c3a59a93..719e9c997 100644 --- a/preferences-schema.yml +++ b/preferences-schema.yml @@ -6,11 +6,19 @@ chains: addressType: endpointUrl: schedule: + - retryTime: + delay: + errorDelay: currencies: - symbol: name: marketFraction: precision: + mainBalance: + dailyTotal: + dailyCount: + monthlyTotal: + monthlyCount: implementations: - chain: token: @@ -28,16 +36,9 @@ markets: rightSideFraction: feeConfigs: - direction: + userLevel: makerFee: takerFee: - userLevel: -wallets: - - currency: - mainBalance: - dailyTotal: - dailyCount: - monthlyTotal: - monthlyCount: userLimits: - level: withdrawFee: diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/AddressType.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/AddressType.kt new file mode 100644 index 000000000..788766a47 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/AddressType.kt @@ -0,0 +1,3 @@ +package co.nilin.opex.utility.preferences + +data class AddressType(var addressType: String, var addressRegex: String) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt index bce2bfb3c..b3035e4d1 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt @@ -1,6 +1,7 @@ package co.nilin.opex.utility.preferences data class ProjectPreferences( + var addressTypes: List, var chains: List, var currencies: List, var markets: List, From 3641923f516711edfb3d166390208d32e15a42a4 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Wed, 11 May 2022 16:24:14 +0430 Subject: [PATCH 05/44] Add preferences.yml --- preferences.yml | 275 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 275 insertions(+) diff --git a/preferences.yml b/preferences.yml index e69de29bb..fe706ce61 100644 --- a/preferences.yml +++ b/preferences.yml @@ -0,0 +1,275 @@ +addressTypes: + - addressType: bitcoin + addressRegex: * + - addressType: ethereum + addressRegex: * + - addressType: test-bitcoin + addressRegex: * +chains: + - name: bitcoin + addressType: bitcoin + endpointUrl: lb://chain-scan-gateway/bitcoin/transfers + schedule: + - retryTime: CURRENT_DATE + delay: 600 + errorDelay: 60 + - name: ethereum + addressType: ethereum + endpointUrl: lb://chain-scan-gateway/eth/transfers + schedule: + - retryTime: CURRENT_DATE + delay: 90 + errorDelay: 60 + - name: bsc + addressType: ethereum + endpointUrl: lb://chain-scan-gateway/bsc/transfers + schedule: + - retryTime: CURRENT_DATE + delay: 90 + errorDelay: 60 + - name: test-bitcoin + addressType: test-bitcoin + endpointUrl: lb://chain-scan-gateway/test-bitcoin/transfers + schedule: + - retryTime: CURRENT_DATE + delay: 600 + errorDelay: 60 + - name: test-ethereum + addressType: ethereum + endpointUrl: lb://chain-scan-gateway/test-eth/transfers + schedule: + - retryTime: CURRENT_DATE + delay: 90 + errorDelay: 60 +currencies: + - symbol: BTC + name: Bitcoin + precision: 0.000001 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: bitcoin + withdrawFee: 0.0001 + withdrawMin: 0.0001 + decimal: 0 + - symbol: ETH + name: Ethereum + precision: 0.000001 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: ethereum + withdrawFee: 0.00001 + withdrawMin: 0.000001 + decimal: 18 + - symbol: USDT + name: Tether + precision: 0.01 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: ethereum + token: true + tokenAddress: 0xdac17f958d2ee523a2206206994597c13d831ec7 + tokenName: Tether USD + withdrawFee: 0.01 + withdrawMin: 0.01 + decimal: 6 + - symbol: BNB + name: Binance + precision: 0.0001 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: bsc + withdrawFee: 0.00001 + withdrawMin: 0.000001 + decimal: 18 + - symbol: BUSD + name: Binance USD + precision: 0.01 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: bsc + token: + tokenAddress: + tokenName: BUSD Token + withdrawFee: 0.01 + withdrawMin: 0.01 + decimal: 18 + - symbol: IRT + name: Toman + precision: 0.1 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + - symbol: TBTC + name: Bitcoin (Test) + precision: 0.000001 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: test-bitcoin + withdrawFee: 0.0001 + withdrawMin: 0.0001 + decimal: 0 + - symbol: TETH + name: Ethereum (Test) + precision: 0.000001 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: test-ethereum + withdrawFee: 0.00001 + withdrawMin: 0.000001 + decimal: 18 + - symbol: TUSDT + name: Tether (Test) + precision: 0.01 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: ethereum + token: true + tokenAddress: 0x110a13fc3efe6a245b50102d2d79b3e76125ae83 + tokenName: Tether USD + withdrawFee: 0.01 + withdrawMin: 0.01 + decimal: 6 +markets: + - leftSide: BTC + rightSide: USDT + feeConfigs: + - direction: ASK + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - leftSide: ETH + rightSide: USDT + feeConfigs: + - direction: ASK + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - leftSide: BNB + rightSide: USDT + feeConfigs: + - direction: ASK + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - leftSide: BTC + rightSide: IRT + feeConfigs: + - direction: ASK + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - leftSide: ETH + rightSide: IRT + feeConfigs: + - direction: ASK + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - leftSide: BNB + rightSide: IRT + feeConfigs: + - direction: ASK + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - leftSide: BUSD + rightSide: IRT + feeConfigs: + - direction: ASK + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - leftSide: TBTC + rightSide: TUSDT + feeConfigs: + - direction: ASK + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - leftSide: TETH + rightSide: TUSDT + feeConfigs: + - direction: ASK + userLevel: * + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: * + makerFee: 0.01 + takerFee: 0.01 +userLimits: + - level: zero + owner: 1 + action: withdraw + walletType: main + withdrawFee: 0.0001 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 \ No newline at end of file From 18412e1328ba36f47394766b367fc997620019ea Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Wed, 11 May 2022 16:45:13 +0430 Subject: [PATCH 06/44] Remove redundant `data.sql`s --- .../src/main/resources/data.sql | 62 ---------- .../src/main/resources/data.sql | 21 ---- .../src/main/resources/data.sql | 109 ------------------ preferences-schema.yml | 3 + preferences.yml | 27 +++++ .../nilin/opex/utility/preferences/Market.kt | 1 + .../src/main/resources/data.sql | 82 ------------- 7 files changed, 31 insertions(+), 274 deletions(-) delete mode 100644 accountant/accountant-ports/accountant-persister-postgres/src/main/resources/data.sql delete mode 100644 api/api-ports/api-persister-postgres/src/main/resources/data.sql diff --git a/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/data.sql b/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/data.sql deleted file mode 100644 index 0b209872f..000000000 --- a/accountant/accountant-ports/accountant-persister-postgres/src/main/resources/data.sql +++ /dev/null @@ -1,62 +0,0 @@ -INSERT INTO pair_config -VALUES ('btc_usdt', 'btc', 'usdt', 0.000001, 0.01, 55000), - ('eth_usdt', 'eth', 'usdt', 0.00001, 0.01, 3800), - ('btc_irt', 'btc', 'irt', 0.000001, 0.01, 55000), - ('eth_irt', 'eth', 'irt', 0.00001, 0.01, 3800), - ('bnb_irt', 'bnb', 'irt', 0.00001, 0.01, 3800), - ('bnb_usdt', 'bnb', 'usdt', 0.00001, 0.01, 3800), - ('busd_irt', 'busd', 'irt', 0.00001, 0.01, 3800), - ('nln_usdt', 'nln', 'usdt', 1.0, 0.01, 0.01), - ('nln_btc', 'nln', 'btc', 1.0, 0.000001, 1 / 5500000), - ('nln_eth', 'nln', 'eth', 1.0, 0.000001, 1 / 550000) -ON CONFLICT DO NOTHING; - --- Test pairs -INSERT INTO pair_config -VALUES ('tbtc_tusdt', 'tbtc', 'tusdt', 0.000001, 0.01, 55000), - ('teth_tusdt', 'teth', 'tusdt', 0.00001, 0.01, 3800), - ('nln_tusdt', 'nln', 'tusdt', 1.0, 0.01, 0.01), - ('nln_tbtc', 'nln', 'tbtc', 1.0, 0.000001, 1 / 5500000), - ('nln_teth', 'nln', 'teth', 1.0, 0.000001, 1 / 550000) -ON CONFLICT DO NOTHING; - -INSERT INTO pair_fee_config -VALUES (1, 'btc_usdt', 'ASK', '*', 0.01, 0.01), - (2, 'btc_usdt', 'BID', '*', 0.01, 0.01), - (3, 'nln_usdt', 'ASK', '*', 0.01, 0.01), - (4, 'nln_usdt', 'BID', '*', 0.01, 0.01), - (5, 'nln_btc', 'ASK', '*', 0.01, 0.01), - (6, 'nln_btc', 'BID', '*', 0.01, 0.01), - (7, 'eth_usdt', 'ASK', '*', 0.01, 0.01), - (8, 'eth_usdt', 'BID', '*', 0.01, 0.01), - (9, 'nln_eth', 'ASK', '*', 0.01, 0.01), - (10, 'nln_eth', 'BID', '*', 0.01, 0.01), - (11, 'btc_irt', 'ASK', '*', 0.01, 0.01), - (12, 'btc_irt', 'BID', '*', 0.01, 0.01), - (13, 'eth_irt', 'ASK', '*', 0.01, 0.01), - (14, 'eth_irt', 'BID', '*', 0.01, 0.01), - (15, 'bnb_irt', 'ASK', '*', 0.01, 0.01), - (16, 'bnb_irt', 'BID', '*', 0.01, 0.01), - (17, 'bnb_usdt', 'ASK', '*', 0.01, 0.01), - (18, 'bnb_usdt', 'BID', '*', 0.01, 0.01), - (19, 'busd_irt', 'ASK', '*', 0.01, 0.01), - (20, 'busd_irt', 'BID', '*', 0.01, 0.01) -ON CONFLICT DO NOTHING; - --- Test pair configs -INSERT INTO pair_fee_config -VALUES (21, 'tbtc_tusdt', 'ASK', '*', 0.01, 0.01), - (22, 'tbtc_tusdt', 'BID', '*', 0.01, 0.01), - (23, 'nln_tusdt', 'ASK', '*', 0.01, 0.01), - (24, 'nln_tusdt', 'BID', '*', 0.01, 0.01), - (25, 'nln_tbtc', 'ASK', '*', 0.01, 0.01), - (26, 'nln_tbtc', 'BID', '*', 0.01, 0.01), - (27, 'teth_tusdt', 'ASK', '*', 0.01, 0.01), - (28, 'teth_tusdt', 'BID', '*', 0.01, 0.01), - (29, 'nln_teth', 'ASK', '*', 0.01, 0.01), - (30, 'nln_teth', 'BID', '*', 0.01, 0.01) -ON CONFLICT DO NOTHING; - -SELECT setval(pg_get_serial_sequence('pair_fee_config', 'id'), (SELECT MAX(id) FROM pair_fee_config)); - -COMMIT; diff --git a/api/api-ports/api-persister-postgres/src/main/resources/data.sql b/api/api-ports/api-persister-postgres/src/main/resources/data.sql deleted file mode 100644 index 803ee830b..000000000 --- a/api/api-ports/api-persister-postgres/src/main/resources/data.sql +++ /dev/null @@ -1,21 +0,0 @@ -INSERT INTO symbol_maps(symbol, value) -VALUES ('btc_usdt', 'BTCUSDT'), - ('eth_usdt', 'ETHUSDT'), - ('bnb_usdt', 'BNBUSDT'), - ('eth_btc', 'ETHBTC'), - ('nln_usdt', 'NLNUSDT'), - ('nln_btc', 'NLNBTC'), - ('btc_irt', 'BTCIRT'), - ('eth_irt', 'ETHIRT'), - ('bnb_irt', 'BNBIRT'), - ('busd_irt', 'BUSDIRT') -ON CONFLICT DO NOTHING; - --- Test symbol mapper -INSERT INTO symbol_maps(symbol, value) -VALUES ('tbtc_tusdt', 'TBTCTUSDT'), - ('teth_tusdt', 'TETHTUSDT'), - ('teth_tbtc', 'TETHTBTC'), - ('nln_tusdt', 'NLNTUSDT'), - ('nln_tbtc', 'NLNTBTC') -ON CONFLICT DO NOTHING; diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql index acad3fe8b..039080767 100644 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql @@ -1,112 +1,3 @@ -INSERT INTO currency -VALUES ('BTC', 'Bitcoin'), - ('ETH', 'Ethereum'), - ('USDT', 'Tether'), - ('IRT', 'Toman'), - ('BNB', 'Binance'), - ('BUSD', 'Binance USD') -ON CONFLICT DO NOTHING; - --- Test currency -INSERT INTO currency -VALUES ('TBTC', 'Bitcoin (Test)'), - ('TETH', 'Ethereum (Test)'), - ('TUSDT', 'Tether (Test)') -ON CONFLICT DO NOTHING; - -INSERT INTO chains -VALUES ('bitcoin'), - ('ethereum'), - ('bsc') -ON CONFLICT DO NOTHING; - --- Test chains -INSERT INTO chains -VALUES ('test-bitcoin'), - ('test-ethereum') -ON CONFLICT DO NOTHING; - -INSERT INTO address_types(id, address_type, address_regex) -VALUES (1, 'bitcoin', '.*'), - (2, 'ethereum', '.*'), - (3, 'test-bitcoin', '.*') -ON CONFLICT DO NOTHING; - -SELECT setval(pg_get_serial_sequence('address_types', 'id'), (SELECT MAX(id) FROM address_types)); - -INSERT INTO chain_address_types(chain_name, addr_type_id) -VALUES ('bitcoin', 1), - ('ethereum', 2), - ('bsc', 2) -ON CONFLICT DO NOTHING; - --- Test chain address types -INSERT INTO chain_address_types(chain_name, addr_type_id) -VALUES ('test-bitcoin', 3), - ('test-ethereum', 2) -ON CONFLICT DO NOTHING; - -INSERT INTO currency_implementations(id, - symbol, - chain, - token, - token_address, - token_name, - withdraw_enabled, - withdraw_fee, - withdraw_min, - decimal) -VALUES (1, 'BTC', 'bitcoin', false, null, null, true, 0.0001, 0.0001, 0), - (2, 'ETH', 'ethereum', false, null, null, true, 0.00001, 0.000001, 18), - (3, 'USDT', 'ethereum', true, '0xdac17f958d2ee523a2206206994597c13d831ec7', 'USDT', true, 0.01, 0.01, 6), - (4, 'BNB', 'bsc', false, null, null, true, 0.0001, 0.0001, 0), - (5, 'BUSD', 'bsc', true, '0xe9e7cea3dedca5984780bafc599bd69add087d56', 'BUSD', true, 0.01, 0.01, 6) -ON CONFLICT DO NOTHING; - --- Test currency implementation -INSERT INTO currency_implementations(id, - symbol, - chain, - token, - token_address, - token_name, - withdraw_enabled, - withdraw_fee, - withdraw_min, - decimal) -VALUES (6, 'TBTC', 'test-bitcoin', false, null, null, true, 0.0001, 0.0001, 0), - (7, 'TETH', 'test-ethereum', false, null, null, true, 0.00001, 0.000001, 18), - (8, 'TUSDT', 'test-ethereum', true, '0x110a13fc3efe6a245b50102d2d79b3e76125ae83', 'TUSDT', true, 0.01, 0.01, 6) -ON CONFLICT DO NOTHING; - -SELECT setval(pg_get_serial_sequence('currency_implementations', 'id'), (SELECT MAX(id) FROM currency_implementations)); - -INSERT INTO chain_endpoints(id, chain_name, endpoint_url) -VALUES (1, 'bitcoin', 'lb://chain-scan-gateway/bitcoin/transfers'), - (2, 'ethereum', 'lb://chain-scan-gateway/eth/transfers'), - (3, 'bsc', 'lb://chain-scan-gateway/bsc/transfers') -ON CONFLICT DO NOTHING; - --- Test chain endpoints -INSERT INTO chain_endpoints(id, chain_name, endpoint_url) -VALUES (4, 'test-bitcoin', 'lb://chain-scan-gateway/test-bitcoin/transfers'), - (5, 'test-ethereum', 'lb://chain-scan-gateway/test-eth/transfers') -ON CONFLICT DO NOTHING; - -SELECT setval(pg_get_serial_sequence('chain_endpoints', 'id'), (SELECT MAX(id) FROM chain_endpoints)); - -INSERT INTO chain_sync_schedules -VALUES ('bitcoin', CURRENT_DATE, 600, 60), - ('ethereum', CURRENT_DATE, 90, 60), - ('bsc', CURRENT_DATE, 90, 60) -ON CONFLICT DO NOTHING; - --- Test chain scan schedules -INSERT INTO chain_sync_schedules -VALUES ('test-bitcoin', CURRENT_DATE, 600, 60), - ('test-ethereum', CURRENT_DATE, 90, 60) -ON CONFLICT DO NOTHING; - INSERT INTO wallet_sync_schedules VALUES (1, CURRENT_DATE, 10, 10000) ON CONFLICT DO NOTHING; diff --git a/preferences-schema.yml b/preferences-schema.yml index 719e9c997..8b8b89316 100644 --- a/preferences-schema.yml +++ b/preferences-schema.yml @@ -34,6 +34,9 @@ markets: rightSide: leftSideFraction: rightSideFraction: + aliases: + - key: + value: feeConfigs: - direction: userLevel: diff --git a/preferences.yml b/preferences.yml index fe706ce61..0a7c86d10 100644 --- a/preferences.yml +++ b/preferences.yml @@ -166,6 +166,9 @@ currencies: markets: - leftSide: BTC rightSide: USDT + aliases: + - key: binance + value: BTCUSDT feeConfigs: - direction: ASK userLevel: * @@ -177,6 +180,9 @@ markets: takerFee: 0.01 - leftSide: ETH rightSide: USDT + aliases: + - key: binance + value: ETHUSDT feeConfigs: - direction: ASK userLevel: * @@ -188,6 +194,9 @@ markets: takerFee: 0.01 - leftSide: BNB rightSide: USDT + aliases: + - key: binance + value: BNBUSDT feeConfigs: - direction: ASK userLevel: * @@ -199,6 +208,9 @@ markets: takerFee: 0.01 - leftSide: BTC rightSide: IRT + aliases: + - key: binance + value: BTCIRT feeConfigs: - direction: ASK userLevel: * @@ -210,6 +222,9 @@ markets: takerFee: 0.01 - leftSide: ETH rightSide: IRT + aliases: + - key: binance + value: ETHIRT feeConfigs: - direction: ASK userLevel: * @@ -221,6 +236,9 @@ markets: takerFee: 0.01 - leftSide: BNB rightSide: IRT + aliases: + - key: binance + value: BNBIRT feeConfigs: - direction: ASK userLevel: * @@ -232,6 +250,9 @@ markets: takerFee: 0.01 - leftSide: BUSD rightSide: IRT + aliases: + - key: binance + value: BUSDIRT feeConfigs: - direction: ASK userLevel: * @@ -243,6 +264,9 @@ markets: takerFee: 0.01 - leftSide: TBTC rightSide: TUSDT + aliases: + - key: binance + value: TBTCTUSDT feeConfigs: - direction: ASK userLevel: * @@ -254,6 +278,9 @@ markets: takerFee: 0.01 - leftSide: TETH rightSide: TUSDT + aliases: + - key: binance + value: TETHTUSDT feeConfigs: - direction: ASK userLevel: * diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt index 9ce127dc9..fd048b314 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt @@ -4,6 +4,7 @@ import java.math.BigDecimal data class Market( var pair: String, + var aliases: List, var leftSide: String, var rightSide: String, var leftSideFraction: BigDecimal?, diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql index edc167ca4..2ac30c132 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql @@ -3,85 +3,3 @@ VALUES (1, '1', 'system', 'basic') ON CONFLICT DO NOTHING; SELECT setval(pg_get_serial_sequence('wallet_owner', 'id'), (SELECT MAX(id) FROM wallet_owner)); - -INSERT INTO currency(name, symbol, precision) -VALUES ('btc', 'btc', 0.000001), - ('eth', 'eth', 0.00001), - ('usdt', 'usdt', 0.01), - ('bnb', 'bnb', 0.01), - ('busd', 'busd', 0.01), - ('nln', 'nln', 1), - ('irt', 'irt', 1) -ON CONFLICT DO NOTHING; - --- Test currency -INSERT INTO currency(name, symbol, precision) -VALUES ('tbtc', 'tbtc', 0.000001), - ('teth', 'teth', 0.00001), - ('tusdt', 'tusdt', 0.01) -ON CONFLICT DO NOTHING; - -INSERT INTO currency_rate(id, source_currency, dest_currency, rate) -VALUES (1, 'btc', 'nln', 5500000), - (2, 'usdt', 'nln', 100), - (3, 'btc', 'usdt', 55000), - (4, 'eth', 'usdt', 3800), - (5, 'btc', 'irt', 3800), - (6, 'eth', 'irt', 3800), - (7, 'bnb', 'irt', 3800), - (8, 'bnb', 'usdt', 3800), - (9, 'busd', 'usdt', 3800) -ON CONFLICT DO NOTHING; - --- Test currency rate -INSERT INTO currency_rate(id, source_currency, dest_currency, rate) -VALUES (10, 'tbtc', 'nln', 5500000), - (11, 'tusdt', 'nln', 100), - (12, 'tbtc', 'tusdt', 55000), - (13, 'teth', 'tusdt', 3800) -ON CONFLICT DO NOTHING; - -SELECT setval(pg_get_serial_sequence('currency_rate', 'id'), (SELECT MAX(id) FROM currency_rate)); - -INSERT INTO wallet(id, owner, wallet_type, currency, balance) -VALUES (1, 1, 'main', 'btc', 10), - (2, 1, 'exchange', 'btc', 0), - (3, 1, 'main', 'usdt', 550000), - (4, 1, 'exchange', 'usdt', 0), - (5, 1, 'main', 'nln', 100000000), - (6, 1, 'exchange', 'nln', 0), - (7, 1, 'main', 'eth', 10000), - (8, 1, 'exchange', 'eth', 0), - (9, 1, 'main', 'irt', 100000000), - (10, 1, 'exchange', 'irt', 0), - (11, 1, 'main', 'bnb', 100000000), - (12, 1, 'exchange', 'bnb', 0), - (13, 1, 'main', 'busd', 100000000), - (14, 1, 'exchange', 'busd', 0) -ON CONFLICT DO NOTHING; - --- Test wallet -INSERT INTO wallet(id, owner, wallet_type, currency, balance) -VALUES (15, 1, 'main', 'tbtc', 10), - (16, 1, 'exchange', 'tbtc', 0), - (17, 1, 'main', 'tusdt', 550000), - (18, 1, 'exchange', 'tusdt', 0), - (19, 1, 'main', 'teth', 10000), - (20, 1, 'exchange', 'teth', 0) -ON CONFLICT DO NOTHING; - -SELECT setval(pg_get_serial_sequence('wallet', 'id'), (SELECT MAX(id) FROM wallet)); - -INSERT INTO user_limits(id, - level, - owner, - action, - wallet_type, - daily_total, - daily_count, - monthly_total, - monthly_count) -VALUES (1, null, 1, 'withdraw', 'main', 1000, 100, 10000, 1000) -ON CONFLICT DO NOTHING; - -SELECT setval(pg_get_serial_sequence('user_limits', 'id'), (SELECT MAX(id) FROM user_limits)); From 193b19d545b924724b61fe87dd4e8a14d311964e Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Wed, 11 May 2022 16:52:21 +0430 Subject: [PATCH 07/44] Add system wallet to preferences --- .../src/main/resources/data.sql | 3 --- preferences-schema.yml | 10 +++++++++- preferences.yml | 10 +++++++++- .../opex/utility/preferences/ChainSyncSchedule.kt | 2 +- .../opex/utility/preferences/ProjectPreferences.kt | 3 ++- .../co/nilin/opex/utility/preferences/SystemWallet.kt | 5 +++++ .../opex/utility/preferences/WalletSyncSchedule.kt | 3 +++ .../src/main/resources/data.sql | 5 ----- 8 files changed, 29 insertions(+), 12 deletions(-) delete mode 100644 bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt delete mode 100644 wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql deleted file mode 100644 index 039080767..000000000 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/data.sql +++ /dev/null @@ -1,3 +0,0 @@ -INSERT INTO wallet_sync_schedules -VALUES (1, CURRENT_DATE, 10, 10000) -ON CONFLICT DO NOTHING; diff --git a/preferences-schema.yml b/preferences-schema.yml index 8b8b89316..9b1d597f2 100644 --- a/preferences-schema.yml +++ b/preferences-schema.yml @@ -48,4 +48,12 @@ userLimits: dailyTotal: dailyCount: monthlyTotal: - monthlyCount: \ No newline at end of file + monthlyCount: +systemWallet: + uuid: + title: + level: + schedule: + - retryTime: + delay: + batchSize: \ No newline at end of file diff --git a/preferences.yml b/preferences.yml index 0a7c86d10..895c56813 100644 --- a/preferences.yml +++ b/preferences.yml @@ -299,4 +299,12 @@ userLimits: dailyTotal: 1000 dailyCount: 100 monthlyTotal: 30000 - monthlyCount: 3000 \ No newline at end of file + monthlyCount: 3000 +systemWallet: + uuid: 1 + title: system + level: basic + schedule: + - retryTime: CURRENT_DATE + delay: 10 + batchSize: 10000 \ No newline at end of file diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt index 03fef72b1..6dc531ee1 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt @@ -1,3 +1,3 @@ package co.nilin.opex.utility.preferences -data class ChainSyncSchedule(var chain: String, var retryTime: Long, var delay: Long, var errorDelay: Long) +data class ChainSyncSchedule(var retryTime: Long, var delay: Long, var errorDelay: Long) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt index b3035e4d1..30409798f 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt @@ -6,5 +6,6 @@ data class ProjectPreferences( var currencies: List, var markets: List, var wallets: List, - var userLevels: List + var userLevels: List, + var systemWallet: SystemWallet ) \ No newline at end of file diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt new file mode 100644 index 000000000..583be1240 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt @@ -0,0 +1,5 @@ +package co.nilin.opex.utility.preferences + +import java.util.UUID + +data class SystemWallet(var uuid: UUID, var title: String, var level: String, var schedule: WalletSyncSchedule) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt new file mode 100644 index 000000000..43557f2a6 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt @@ -0,0 +1,3 @@ +package co.nilin.opex.utility.preferences + +class WalletSyncSchedule(var retryTime: Long, var delay: Long, var batchSize: Long) diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql deleted file mode 100644 index 2ac30c132..000000000 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/data.sql +++ /dev/null @@ -1,5 +0,0 @@ -INSERT INTO wallet_owner(id, uuid, title, level) -VALUES (1, '1', 'system', 'basic') -ON CONFLICT DO NOTHING; - -SELECT setval(pg_get_serial_sequence('wallet_owner', 'id'), (SELECT MAX(id) FROM wallet_owner)); From f4e4a8a50a5d39af0524e818e584c381f4fc6510 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Thu, 12 May 2022 16:27:53 +0430 Subject: [PATCH 08/44] preferences: Improve schema --- preferences-schema.yml | 12 ++++++------ preferences.yml | 2 +- .../opex/utility/preferences/AddressType.kt | 2 +- .../nilin/opex/utility/preferences/Alias.kt | 3 +++ .../nilin/opex/utility/preferences/Chain.kt | 5 ++++- .../utility/preferences/ChainSyncSchedule.kt | 6 +++++- .../opex/utility/preferences/Currency.kt | 19 ++++++++++++------- .../preferences/CurrencyImplementation.kt | 18 +++++++++--------- .../opex/utility/preferences/FeeConfig.kt | 5 ++++- .../nilin/opex/utility/preferences/Market.kt | 14 +++++++------- .../utility/preferences/ProjectPreferences.kt | 15 +++++++-------- .../opex/utility/preferences/SystemWallet.kt | 9 +++++++-- .../opex/utility/preferences/UserLevel.kt | 15 --------------- .../opex/utility/preferences/UserLimit.kt | 15 +++++++++++++++ .../nilin/opex/utility/preferences/Wallet.kt | 12 ------------ .../utility/preferences/WalletSyncSchedule.kt | 2 +- 16 files changed, 82 insertions(+), 72 deletions(-) create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt delete mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt delete mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt diff --git a/preferences-schema.yml b/preferences-schema.yml index 9b1d597f2..881d3bb8d 100644 --- a/preferences-schema.yml +++ b/preferences-schema.yml @@ -6,9 +6,9 @@ chains: addressType: endpointUrl: schedule: - - retryTime: - delay: - errorDelay: + retryTime: + delay: + errorDelay: currencies: - symbol: name: @@ -54,6 +54,6 @@ systemWallet: title: level: schedule: - - retryTime: - delay: - batchSize: \ No newline at end of file + retryTime: + delay: + batchSize: diff --git a/preferences.yml b/preferences.yml index 895c56813..52089d68d 100644 --- a/preferences.yml +++ b/preferences.yml @@ -307,4 +307,4 @@ systemWallet: schedule: - retryTime: CURRENT_DATE delay: 10 - batchSize: 10000 \ No newline at end of file + batchSize: 10000 diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/AddressType.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/AddressType.kt index 788766a47..7ef22eba0 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/AddressType.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/AddressType.kt @@ -1,3 +1,3 @@ package co.nilin.opex.utility.preferences -data class AddressType(var addressType: String, var addressRegex: String) +data class AddressType(var addressType: String = "", var addressRegex: String = "*") diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt new file mode 100644 index 000000000..2b04fc665 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt @@ -0,0 +1,3 @@ +package co.nilin.opex.utility.preferences + +data class Alias(var key: String = "", var value: String = "") diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Chain.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Chain.kt index de9113308..8cc4abecc 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Chain.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Chain.kt @@ -1,5 +1,8 @@ package co.nilin.opex.utility.preferences data class Chain( - var name: String, var addressType: String, val endpointUrl: String, var schedule: ChainSyncSchedule + var name: String = "", + var addressType: String = "", + val endpointUrl: String = "", + var schedule: ChainSyncSchedule = ChainSyncSchedule() ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt index 6dc531ee1..8da2cc67b 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt @@ -1,3 +1,7 @@ package co.nilin.opex.utility.preferences -data class ChainSyncSchedule(var retryTime: Long, var delay: Long, var errorDelay: Long) +data class ChainSyncSchedule( + var retryTime: String = "CURRENT_DATE", + var delay: Long = 0, + var errorDelay: Long = 0 +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt index bbcdd9518..297e59918 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt @@ -3,10 +3,15 @@ package co.nilin.opex.utility.preferences import java.math.BigDecimal data class Currency( - var symbol: String, - var name: String, - var leftSideFraction: BigDecimal, - var rightSideFraction: BigDecimal, - var precision: BigDecimal, - var implementations: List -) \ No newline at end of file + var symbol: String = "", + var name: String = "", + var precision: BigDecimal = BigDecimal.ZERO, + var leftSideFraction: BigDecimal = precision, + var rightSideFraction: BigDecimal = precision, + var mainBalance: BigDecimal = BigDecimal.ZERO, + var dailyTotal: BigDecimal = BigDecimal.ZERO, + var dailyCount: Int = 0, + var monthlyTotal: BigDecimal = BigDecimal.ZERO, + var monthlyCount: Int = 0, + var implementations: List = emptyList() +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt index 25a41d343..6f015e7a2 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt @@ -3,12 +3,12 @@ package co.nilin.opex.utility.preferences import java.math.BigDecimal data class CurrencyImplementation( - var chain: String, - var token: Boolean, - var tokenAddress: String?, - var tokenName: String?, - var withdrawEnabled: Boolean, - var withdrawFee: BigDecimal, - var withdrawMin: BigDecimal, - var decimal: BigDecimal -) \ No newline at end of file + var chain: String = "", + var withdrawEnabled: Boolean = true, + var token: Boolean = false, + var tokenAddress: String? = null, + var tokenName: String? = null, + var withdrawFee: BigDecimal? = null, + var withdrawMin: BigDecimal? = null, + var decimal: Int? = null +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt index 8341928a8..677649594 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt @@ -3,5 +3,8 @@ package co.nilin.opex.utility.preferences import java.math.BigDecimal data class FeeConfig( - var direction: String, var makerFee: BigDecimal, var takerFee: BigDecimal, var userLevel: BigDecimal + var userLevel: String = "", + var direction: String? = "", + var makerFee: BigDecimal = BigDecimal.valueOf(0.01), + var takerFee: BigDecimal = BigDecimal.valueOf(0.01) ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt index fd048b314..6c6bb55e4 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt @@ -3,11 +3,11 @@ package co.nilin.opex.utility.preferences import java.math.BigDecimal data class Market( - var pair: String, - var aliases: List, - var leftSide: String, - var rightSide: String, - var leftSideFraction: BigDecimal?, - var rightSideFraction: BigDecimal?, - var feeConfigs: List + var leftSide: String = "", + var rightSide: String = "", + var pair: String? = "${leftSide}_$rightSide", + var feeConfigs: List = emptyList(), + var aliases: List = emptyList(), + var leftSideFraction: BigDecimal? = null, + var rightSideFraction: BigDecimal? = null ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt index 30409798f..e20aaa52a 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt @@ -1,11 +1,10 @@ package co.nilin.opex.utility.preferences data class ProjectPreferences( - var addressTypes: List, - var chains: List, - var currencies: List, - var markets: List, - var wallets: List, - var userLevels: List, - var systemWallet: SystemWallet -) \ No newline at end of file + var addressTypes: List = emptyList(), + var chains: List = emptyList(), + var currencies: List = emptyList(), + var markets: List = emptyList(), + var userLimits: List = emptyList(), + var systemWallet: SystemWallet = SystemWallet() +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt index 583be1240..ff21ba38d 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt @@ -1,5 +1,10 @@ package co.nilin.opex.utility.preferences -import java.util.UUID +import java.util.* -data class SystemWallet(var uuid: UUID, var title: String, var level: String, var schedule: WalletSyncSchedule) +data class SystemWallet( + var uuid: String = UUID.randomUUID().toString(), + var title: String = "", + var level: String = "", + var schedule: WalletSyncSchedule = WalletSyncSchedule() +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt deleted file mode 100644 index 143398e0e..000000000 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLevel.kt +++ /dev/null @@ -1,15 +0,0 @@ -package co.nilin.opex.utility.preferences - -import java.math.BigDecimal - -data class UserLevel( - var level: String, - var owner: String, - var action: String, - var walletType: String, - var withdrawFee: BigDecimal, - var dailyTotal: BigDecimal, - var dailyCount: Int, - var monthlyTotal: BigDecimal, - var monthlyCount: Int -) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt new file mode 100644 index 000000000..6a6f41ca7 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt @@ -0,0 +1,15 @@ +package co.nilin.opex.utility.preferences + +import java.math.BigDecimal + +data class UserLimit( + var level: String = "", + var owner: String = "", + var action: String = "", + var walletType: String = "", + var withdrawFee: BigDecimal = BigDecimal.ZERO, + var dailyTotal: BigDecimal = BigDecimal.ZERO, + var dailyCount: Int = 0, + var monthlyTotal: BigDecimal = BigDecimal.ZERO, + var monthlyCount: Int = 0 +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt deleted file mode 100644 index 6a7164092..000000000 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt +++ /dev/null @@ -1,12 +0,0 @@ -package co.nilin.opex.utility.preferences - -import java.math.BigDecimal - -data class Wallet( - var currency: String, - var mainBalance: BigDecimal, - var dailyTotal: BigDecimal, - var dailyCount: Int, - var monthlyTotal: BigDecimal, - var monthlyCount: Int -) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt index 43557f2a6..6fcf05473 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt @@ -1,3 +1,3 @@ package co.nilin.opex.utility.preferences -class WalletSyncSchedule(var retryTime: Long, var delay: Long, var batchSize: Long) +class WalletSyncSchedule(var retryTime: String = "CURRENT_DATE", var delay: Long = 0, var batchSize: Long = 0) From 45b45e8ba95527d87cba299e09fb25f7042ff7f5 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Thu, 12 May 2022 16:41:51 +0430 Subject: [PATCH 09/44] preferences: Fix default values --- .../co/nilin/opex/utility/preferences/Currency.kt | 14 +++++++++++--- .../co/nilin/opex/utility/preferences/Market.kt | 8 ++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt index 297e59918..4a23a7950 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt @@ -6,12 +6,20 @@ data class Currency( var symbol: String = "", var name: String = "", var precision: BigDecimal = BigDecimal.ZERO, - var leftSideFraction: BigDecimal = precision, - var rightSideFraction: BigDecimal = precision, var mainBalance: BigDecimal = BigDecimal.ZERO, var dailyTotal: BigDecimal = BigDecimal.ZERO, var dailyCount: Int = 0, var monthlyTotal: BigDecimal = BigDecimal.ZERO, var monthlyCount: Int = 0, var implementations: List = emptyList() -) +) { + var leftSideFraction: BigDecimal? = null + get() { + return field ?: precision + } + + var rightSideFraction: BigDecimal? = null + get() { + return field ?: precision + } +} diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt index 6c6bb55e4..1d3eb6533 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt @@ -5,9 +5,13 @@ import java.math.BigDecimal data class Market( var leftSide: String = "", var rightSide: String = "", - var pair: String? = "${leftSide}_$rightSide", var feeConfigs: List = emptyList(), var aliases: List = emptyList(), var leftSideFraction: BigDecimal? = null, var rightSideFraction: BigDecimal? = null -) +) { + var pair: String? = null + get() { + return field ?: "${leftSide}_$rightSide" + } +} From 2f5e24a07f909f1bc839d52ac623af41e3290bfb Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Thu, 12 May 2022 19:47:25 +0430 Subject: [PATCH 10/44] preferences: Make preferences a dummy object --- .../co/nilin/opex/utility/preferences/Currency.kt | 14 +++----------- .../co/nilin/opex/utility/preferences/Market.kt | 8 ++------ 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt index 4a23a7950..fa3ee5456 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt @@ -6,20 +6,12 @@ data class Currency( var symbol: String = "", var name: String = "", var precision: BigDecimal = BigDecimal.ZERO, + var leftSideFraction: BigDecimal = BigDecimal.ZERO, + var rightSideFraction: BigDecimal = BigDecimal.ZERO, var mainBalance: BigDecimal = BigDecimal.ZERO, var dailyTotal: BigDecimal = BigDecimal.ZERO, var dailyCount: Int = 0, var monthlyTotal: BigDecimal = BigDecimal.ZERO, var monthlyCount: Int = 0, var implementations: List = emptyList() -) { - var leftSideFraction: BigDecimal? = null - get() { - return field ?: precision - } - - var rightSideFraction: BigDecimal? = null - get() { - return field ?: precision - } -} +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt index 1d3eb6533..04c738c88 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt @@ -5,13 +5,9 @@ import java.math.BigDecimal data class Market( var leftSide: String = "", var rightSide: String = "", + var pair: String? = null, var feeConfigs: List = emptyList(), var aliases: List = emptyList(), var leftSideFraction: BigDecimal? = null, var rightSideFraction: BigDecimal? = null -) { - var pair: String? = null - get() { - return field ?: "${leftSide}_$rightSide" - } -} +) From e34dc3827719323ea40d79248a688c3a7ab51d66 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Thu, 12 May 2022 19:48:15 +0430 Subject: [PATCH 11/44] preferences: Scape reserved * character in config file --- preferences.yml | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/preferences.yml b/preferences.yml index 52089d68d..8dfef1270 100644 --- a/preferences.yml +++ b/preferences.yml @@ -1,10 +1,10 @@ addressTypes: - addressType: bitcoin - addressRegex: * + addressRegex: "*" - addressType: ethereum - addressRegex: * + addressRegex: "*" - addressType: test-bitcoin - addressRegex: * + addressRegex: "*" chains: - name: bitcoin addressType: bitcoin @@ -171,11 +171,11 @@ markets: value: BTCUSDT feeConfigs: - direction: ASK - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - direction: BID - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - leftSide: ETH @@ -185,11 +185,11 @@ markets: value: ETHUSDT feeConfigs: - direction: ASK - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - direction: BID - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - leftSide: BNB @@ -199,11 +199,11 @@ markets: value: BNBUSDT feeConfigs: - direction: ASK - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - direction: BID - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - leftSide: BTC @@ -213,11 +213,11 @@ markets: value: BTCIRT feeConfigs: - direction: ASK - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - direction: BID - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - leftSide: ETH @@ -227,11 +227,11 @@ markets: value: ETHIRT feeConfigs: - direction: ASK - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - direction: BID - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - leftSide: BNB @@ -241,11 +241,11 @@ markets: value: BNBIRT feeConfigs: - direction: ASK - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - direction: BID - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - leftSide: BUSD @@ -255,11 +255,11 @@ markets: value: BUSDIRT feeConfigs: - direction: ASK - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - direction: BID - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - leftSide: TBTC @@ -269,11 +269,11 @@ markets: value: TBTCTUSDT feeConfigs: - direction: ASK - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - direction: BID - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - leftSide: TETH @@ -283,11 +283,11 @@ markets: value: TETHTUSDT feeConfigs: - direction: ASK - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 - direction: BID - userLevel: * + userLevel: "*" makerFee: 0.01 takerFee: 0.01 userLimits: From 7dfc063d46ea42ed87a103ede3816551b7ab59bf Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Thu, 12 May 2022 20:34:07 +0430 Subject: [PATCH 12/44] preferences: Add initialize logic to bc-gateway --- bc-gateway/bc-gateway-app/pom.xml | 9 +++ .../bcgateway/app/config/SetupPreferences.kt | 78 +++++++++++++++++++ bc-gateway/pom.xml | 5 ++ .../preferences/CurrencyImplementation.kt | 6 +- 4 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt diff --git a/bc-gateway/bc-gateway-app/pom.xml b/bc-gateway/bc-gateway-app/pom.xml index c8a5fa93b..2b2851b28 100644 --- a/bc-gateway/bc-gateway-app/pom.xml +++ b/bc-gateway/bc-gateway-app/pom.xml @@ -81,6 +81,10 @@ co.nilin.opex.bcgateway.ports.kafka.listener bc-gateway-eventlistener-kafka + + co.nilin.opex.utility.preferences + preferences + io.springfox springfox-boot-starter @@ -90,6 +94,11 @@ org.springframework.cloud spring-cloud-starter-vault-config + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + 2.13.0 + diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt new file mode 100644 index 000000000..b999cce72 --- /dev/null +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt @@ -0,0 +1,78 @@ +package co.nilin.opex.bcgateway.app.config + +import co.nilin.opex.bcgateway.ports.postgres.dao.* +import co.nilin.opex.bcgateway.ports.postgres.model.* +import co.nilin.opex.utility.preferences.ProjectPreferences +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory +import kotlinx.coroutines.reactive.awaitFirst +import kotlinx.coroutines.reactor.awaitSingle +import kotlinx.coroutines.runBlocking +import org.springframework.beans.factory.annotation.Value +import org.springframework.stereotype.Component +import java.io.File +import java.time.LocalDateTime + +@Component +class SetupPreferences( + @Value("preferences.yml") file: File, + addressTypeRepository: AddressTypeRepository, + chainRepository: ChainRepository, + chainAddressTypeRepository: ChainAddressTypeRepository, + chainEndpointRepository: ChainEndpointRepository, + currencyRepository: CurrencyRepository, + currencyImplementationRepository: CurrencyImplementationRepository, + chainSyncScheduleRepository: ChainSyncScheduleRepository, + walletSyncScheduleRepository: WalletSyncScheduleRepository +) { + init { + val mapper = ObjectMapper(YAMLFactory()) + val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) + runBlocking { + // Add address types + addressTypeRepository.saveAll(p.addressTypes.mapIndexed { i, it -> + AddressTypeModel(i + 1L, it.addressType, it.addressRegex, null) + }).awaitFirst() + + // Add chains with endpoints + chainRepository.saveAll(p.chains.mapIndexed { i, it -> + ChainModel(it.name) + }).awaitFirst() + chainAddressTypeRepository.saveAll(p.chains.mapIndexed { i, it -> + val addressTypeId = addressTypeRepository.findByType(it.addressType).awaitSingle().id!! + ChainAddressTypeModel(i + 1L, it.name, addressTypeId) + }).awaitFirst() + chainEndpointRepository.saveAll(p.chains.mapIndexed { i, it -> + ChainEndpointModel(i + 1L, it.name, it.endpointUrl, null, null) + }).awaitFirst() + + // Add currencies with implementations + currencyRepository.saveAll(p.currencies.mapIndexed { i, it -> + CurrencyModel(it.symbol, it.name) + }).awaitFirst() + currencyImplementationRepository.saveAll(p.currencies.flatMap { listOf(it).zip(it.implementations) } + .mapIndexed { i, (currency, impl) -> + CurrencyImplementationModel( + i + 1L, + currency.symbol, + impl.chain, + impl.token, + impl.tokenAddress, + impl.tokenName, + impl.withdrawEnabled, + impl.withdrawFee, + impl.withdrawMin, + impl.decimal + ) + }).awaitFirst() + + // Add sync schedules. Wallet and Chain + chainSyncScheduleRepository.saveAll(p.chains.mapIndexed { i, it -> + ChainSyncScheduleModel(it.name, LocalDateTime.now(), it.schedule.delay, it.schedule.errorDelay) + }) + walletSyncScheduleRepository.save(p.systemWallet.let { + WalletSyncScheduleModel(1, LocalDateTime.now(), it.schedule.delay, it.schedule.batchSize) + }) + } + } +} diff --git a/bc-gateway/pom.xml b/bc-gateway/pom.xml index 3c408f018..6fc01550a 100644 --- a/bc-gateway/pom.xml +++ b/bc-gateway/pom.xml @@ -72,6 +72,11 @@ interceptors ${project.version} + + co.nilin.opex.utility.preferences + preferences + ${project.version} + diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt index 6f015e7a2..1cfe3c066 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt @@ -8,7 +8,7 @@ data class CurrencyImplementation( var token: Boolean = false, var tokenAddress: String? = null, var tokenName: String? = null, - var withdrawFee: BigDecimal? = null, - var withdrawMin: BigDecimal? = null, - var decimal: Int? = null + var withdrawFee: BigDecimal = BigDecimal.ZERO, + var withdrawMin: BigDecimal = BigDecimal.ZERO, + var decimal: Int = 0 ) From e1d55088c5a4bef6fd681d6ca70b524dfc8ae770 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Thu, 12 May 2022 22:01:38 +0430 Subject: [PATCH 13/44] preferences: Remove retryTime --- preferences-schema.yml | 2 -- preferences.yml | 18 ++++++------------ .../utility/preferences/ChainSyncSchedule.kt | 1 - .../utility/preferences/WalletSyncSchedule.kt | 2 +- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/preferences-schema.yml b/preferences-schema.yml index 881d3bb8d..5cd5fb4b9 100644 --- a/preferences-schema.yml +++ b/preferences-schema.yml @@ -6,7 +6,6 @@ chains: addressType: endpointUrl: schedule: - retryTime: delay: errorDelay: currencies: @@ -54,6 +53,5 @@ systemWallet: title: level: schedule: - retryTime: delay: batchSize: diff --git a/preferences.yml b/preferences.yml index 8dfef1270..ac0b317ba 100644 --- a/preferences.yml +++ b/preferences.yml @@ -10,36 +10,31 @@ chains: addressType: bitcoin endpointUrl: lb://chain-scan-gateway/bitcoin/transfers schedule: - - retryTime: CURRENT_DATE - delay: 600 + - delay: 600 errorDelay: 60 - name: ethereum addressType: ethereum endpointUrl: lb://chain-scan-gateway/eth/transfers schedule: - - retryTime: CURRENT_DATE - delay: 90 + - delay: 90 errorDelay: 60 - name: bsc addressType: ethereum endpointUrl: lb://chain-scan-gateway/bsc/transfers schedule: - - retryTime: CURRENT_DATE - delay: 90 + - delay: 90 errorDelay: 60 - name: test-bitcoin addressType: test-bitcoin endpointUrl: lb://chain-scan-gateway/test-bitcoin/transfers schedule: - - retryTime: CURRENT_DATE - delay: 600 + - delay: 600 errorDelay: 60 - name: test-ethereum addressType: ethereum endpointUrl: lb://chain-scan-gateway/test-eth/transfers schedule: - - retryTime: CURRENT_DATE - delay: 90 + - delay: 90 errorDelay: 60 currencies: - symbol: BTC @@ -305,6 +300,5 @@ systemWallet: title: system level: basic schedule: - - retryTime: CURRENT_DATE - delay: 10 + - delay: 10 batchSize: 10000 diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt index 8da2cc67b..f745e1379 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt @@ -1,7 +1,6 @@ package co.nilin.opex.utility.preferences data class ChainSyncSchedule( - var retryTime: String = "CURRENT_DATE", var delay: Long = 0, var errorDelay: Long = 0 ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt index 6fcf05473..9108b5a59 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt @@ -1,3 +1,3 @@ package co.nilin.opex.utility.preferences -class WalletSyncSchedule(var retryTime: String = "CURRENT_DATE", var delay: Long = 0, var batchSize: Long = 0) +class WalletSyncSchedule(var delay: Long = 0, var batchSize: Long = 0) From f4dea9c74b737bcd9c82ec6be2d2cae9b8fa726e Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Thu, 12 May 2022 22:09:40 +0430 Subject: [PATCH 14/44] preferences: Fix schedule declaration --- preferences.yml | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/preferences.yml b/preferences.yml index ac0b317ba..36530ca88 100644 --- a/preferences.yml +++ b/preferences.yml @@ -10,32 +10,32 @@ chains: addressType: bitcoin endpointUrl: lb://chain-scan-gateway/bitcoin/transfers schedule: - - delay: 600 - errorDelay: 60 + delay: 600 + errorDelay: 60 - name: ethereum addressType: ethereum endpointUrl: lb://chain-scan-gateway/eth/transfers schedule: - - delay: 90 - errorDelay: 60 + delay: 90 + errorDelay: 60 - name: bsc addressType: ethereum endpointUrl: lb://chain-scan-gateway/bsc/transfers schedule: - - delay: 90 - errorDelay: 60 + delay: 90 + errorDelay: 60 - name: test-bitcoin addressType: test-bitcoin endpointUrl: lb://chain-scan-gateway/test-bitcoin/transfers schedule: - - delay: 600 - errorDelay: 60 + delay: 600 + errorDelay: 60 - name: test-ethereum addressType: ethereum endpointUrl: lb://chain-scan-gateway/test-eth/transfers schedule: - - delay: 90 - errorDelay: 60 + delay: 90 + errorDelay: 60 currencies: - symbol: BTC name: Bitcoin @@ -300,5 +300,5 @@ systemWallet: title: system level: basic schedule: - - delay: 10 - batchSize: 10000 + delay: 10 + batchSize: 10000 From 4fd9266a676fdb22b2830f9df9d41904d7b3100e Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 01:15:03 +0430 Subject: [PATCH 15/44] preferences: Fix BUSD declaration --- preferences.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/preferences.yml b/preferences.yml index 36530ca88..211a2d969 100644 --- a/preferences.yml +++ b/preferences.yml @@ -102,8 +102,8 @@ currencies: monthlyCount: 3000 implementations: - chain: bsc - token: - tokenAddress: + token: true + tokenAddress: 0xe9e7cea3dedca5984780bafc599bd69add087d56 tokenName: BUSD Token withdrawFee: 0.01 withdrawMin: 0.01 @@ -300,5 +300,5 @@ systemWallet: title: system level: basic schedule: - delay: 10 - batchSize: 10000 + delay: 10 + batchSize: 10000 From f6210a18fd03ae6adce23bfb539d15c47a99df0e Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 01:16:14 +0430 Subject: [PATCH 16/44] bc-gateway: Fix and refactor db init method --- .../bcgateway/app/config/SetupPreferences.kt | 144 ++++++++++++------ .../ports/postgres/config/PostgresConfig.kt | 8 +- 2 files changed, 96 insertions(+), 56 deletions(-) diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt index b999cce72..e2b22d094 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt @@ -2,77 +2,121 @@ package co.nilin.opex.bcgateway.app.config import co.nilin.opex.bcgateway.ports.postgres.dao.* import co.nilin.opex.bcgateway.ports.postgres.model.* +import co.nilin.opex.utility.preferences.AddressType +import co.nilin.opex.utility.preferences.Chain +import co.nilin.opex.utility.preferences.Currency import co.nilin.opex.utility.preferences.ProjectPreferences import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.yaml.YAMLFactory -import kotlinx.coroutines.reactive.awaitFirst +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch import kotlinx.coroutines.reactor.awaitSingle +import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.DependsOn import org.springframework.stereotype.Component import java.io.File import java.time.LocalDateTime @Component +@DependsOn("postgresConfig") class SetupPreferences( @Value("preferences.yml") file: File, - addressTypeRepository: AddressTypeRepository, - chainRepository: ChainRepository, - chainAddressTypeRepository: ChainAddressTypeRepository, - chainEndpointRepository: ChainEndpointRepository, - currencyRepository: CurrencyRepository, - currencyImplementationRepository: CurrencyImplementationRepository, - chainSyncScheduleRepository: ChainSyncScheduleRepository, - walletSyncScheduleRepository: WalletSyncScheduleRepository + private val addressTypeRepository: AddressTypeRepository, + private val chainRepository: ChainRepository, + private val chainAddressTypeRepository: ChainAddressTypeRepository, + private val chainEndpointRepository: ChainEndpointRepository, + private val currencyRepository: CurrencyRepository, + private val currencyImplementationRepository: CurrencyImplementationRepository, + private val chainSyncScheduleRepository: ChainSyncScheduleRepository, + private val walletSyncScheduleRepository: WalletSyncScheduleRepository ) { + private val mapper = ObjectMapper(YAMLFactory()) + init { - val mapper = ObjectMapper(YAMLFactory()) val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) runBlocking { - // Add address types - addressTypeRepository.saveAll(p.addressTypes.mapIndexed { i, it -> - AddressTypeModel(i + 1L, it.addressType, it.addressRegex, null) - }).awaitFirst() + addAddressTypes(p.addressTypes) + addChains(p.chains) + addCurrencies(p.currencies) + addSchedules(p) + } + } + + private suspend fun addAddressTypes(data: List) = coroutineScope { + val items = data.mapIndexed { i, it -> + if (addressTypeRepository.existsById(i + 1L).awaitSingle()) + null + else AddressTypeModel(null, it.addressType, it.addressRegex, null) + }.filterNotNull() + addressTypeRepository.saveAll(items).collectList().awaitSingleOrNull() + } - // Add chains with endpoints - chainRepository.saveAll(p.chains.mapIndexed { i, it -> - ChainModel(it.name) - }).awaitFirst() - chainAddressTypeRepository.saveAll(p.chains.mapIndexed { i, it -> + private suspend fun addChains(data: List) = coroutineScope { + data.map { chainRepository.insert(it.name).awaitSingleOrNull() } + val items1 = data.mapIndexed { i, it -> + if (chainAddressTypeRepository.existsById(i + 1L).awaitSingle()) { + null + } else { val addressTypeId = addressTypeRepository.findByType(it.addressType).awaitSingle().id!! - ChainAddressTypeModel(i + 1L, it.name, addressTypeId) - }).awaitFirst() - chainEndpointRepository.saveAll(p.chains.mapIndexed { i, it -> - ChainEndpointModel(i + 1L, it.name, it.endpointUrl, null, null) - }).awaitFirst() + ChainAddressTypeModel(null, it.name, addressTypeId) + } + }.filterNotNull() + chainAddressTypeRepository.saveAll(items1).collectList().awaitSingleOrNull() + val items2 = data.mapIndexed { i, it -> + if (chainEndpointRepository.existsById(i + 1L).awaitSingle()) null + else ChainEndpointModel(null, it.name, it.endpointUrl, null, null) + }.filterNotNull() + chainEndpointRepository.saveAll(items2).collectList().awaitSingleOrNull() + } - // Add currencies with implementations - currencyRepository.saveAll(p.currencies.mapIndexed { i, it -> - CurrencyModel(it.symbol, it.name) - }).awaitFirst() - currencyImplementationRepository.saveAll(p.currencies.flatMap { listOf(it).zip(it.implementations) } - .mapIndexed { i, (currency, impl) -> - CurrencyImplementationModel( - i + 1L, - currency.symbol, - impl.chain, - impl.token, - impl.tokenAddress, - impl.tokenName, - impl.withdrawEnabled, - impl.withdrawFee, - impl.withdrawMin, - impl.decimal - ) - }).awaitFirst() + private suspend fun addCurrencies(data: List) = coroutineScope { + coroutineScope { + data.forEach { + launch { + currencyRepository.insert(it.name, it.symbol).awaitSingleOrNull() + } + } + } + val items = + data.flatMap { it.implementations.map { impl -> it to impl } }.mapIndexed { i, (currency, impl) -> + if (currencyImplementationRepository.existsById(i + 1L).awaitSingle()) null + else CurrencyImplementationModel( + null, + currency.symbol, + impl.chain, + impl.token, + impl.tokenAddress, + impl.tokenName, + impl.withdrawEnabled, + impl.withdrawFee, + impl.withdrawMin, + impl.decimal + ) + }.filterNotNull() + currencyImplementationRepository.saveAll(items).collectList().awaitSingleOrNull() + } - // Add sync schedules. Wallet and Chain - chainSyncScheduleRepository.saveAll(p.chains.mapIndexed { i, it -> - ChainSyncScheduleModel(it.name, LocalDateTime.now(), it.schedule.delay, it.schedule.errorDelay) - }) - walletSyncScheduleRepository.save(p.systemWallet.let { - WalletSyncScheduleModel(1, LocalDateTime.now(), it.schedule.delay, it.schedule.batchSize) - }) + private suspend fun addSchedules(data: ProjectPreferences) = coroutineScope { + data.chains.map { + launch { + chainSyncScheduleRepository.insert( + it.name, + it.schedule.delay.toInt(), + it.schedule.errorDelay.toInt() + ).awaitSingleOrNull() + } + } + if (walletSyncScheduleRepository.existsById(1).awaitSingle()) null + else { + val item = WalletSyncScheduleModel( + null, + LocalDateTime.now(), + data.systemWallet.schedule.delay, + data.systemWallet.schedule.batchSize + ) + walletSyncScheduleRepository.save(item).awaitSingleOrNull() } } } diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/config/PostgresConfig.kt b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/config/PostgresConfig.kt index 0b6367666..c1dae05d6 100644 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/config/PostgresConfig.kt +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/kotlin/co/nilin/opex/bcgateway/ports/postgres/config/PostgresConfig.kt @@ -10,17 +10,13 @@ import org.springframework.r2dbc.core.DatabaseClient @EnableR2dbcRepositories(basePackages = ["co.nilin.opex"]) class PostgresConfig( db: DatabaseClient, - @Value("classpath:schema.sql") private val schemaResource: Resource, - @Value("classpath:data.sql") private val dataResource: Resource? + @Value("classpath:schema.sql") private val schemaResource: Resource ) { init { val schemaReader = schemaResource.inputStream.reader() val schema = schemaReader.readText().trim() schemaReader.close() - val dataReader = dataResource?.inputStream?.reader() - val data = dataReader?.readText()?.trim() ?: "" - dataReader?.close() - val initDb = db.sql { schema.plus(data) } + val initDb = db.sql { schema } initDb // initialize the database .then() .subscribe() // execute From c0f2a805373429f05c1ce3a2f24ef52810773764 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 01:50:39 +0430 Subject: [PATCH 17/44] accountant: Add preferences to accountant --- accountant/accountant-app/pom.xml | 9 +++ .../accountant/app/config/SetupPreferences.kt | 62 +++++++++++++++++++ .../ports/postgres/config/PostgresConfig.kt | 8 +-- .../postgres/dao/PairConfigRepository.kt | 14 ++++- accountant/pom.xml | 5 ++ api/api-app/pom.xml | 9 +++ .../opex/api/app/config/SetupPreferences.kt | 36 +++++++++++ .../ports/postgres/dao/SymbolMapRepository.kt | 5 +- api/pom.xml | 5 ++ preferences-schema.yml | 3 +- preferences.yml | 27 +++----- .../nilin/opex/utility/preferences/Alias.kt | 3 - .../opex/utility/preferences/Currency.kt | 2 - .../opex/utility/preferences/FeeConfig.kt | 2 +- .../nilin/opex/utility/preferences/Market.kt | 2 +- 15 files changed, 157 insertions(+), 35 deletions(-) create mode 100644 accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt create mode 100644 api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt delete mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt diff --git a/accountant/accountant-app/pom.xml b/accountant/accountant-app/pom.xml index aa8f7f94d..4e2c00b49 100644 --- a/accountant/accountant-app/pom.xml +++ b/accountant/accountant-app/pom.xml @@ -63,6 +63,15 @@ org.springframework.boot spring-boot-starter-actuator + + co.nilin.opex.utility.preferences + preferences + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + 2.13.0 + diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt new file mode 100644 index 000000000..07fbe7190 --- /dev/null +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt @@ -0,0 +1,62 @@ +package co.nilin.opex.accountant.app.config + +import co.nilin.opex.accountant.ports.postgres.dao.PairConfigRepository +import co.nilin.opex.accountant.ports.postgres.dao.PairFeeConfigRepository +import co.nilin.opex.accountant.ports.postgres.model.PairFeeConfigModel +import co.nilin.opex.utility.preferences.ProjectPreferences +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory +import kotlinx.coroutines.launch +import kotlinx.coroutines.reactor.awaitSingleOrNull +import kotlinx.coroutines.runBlocking +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.DependsOn +import org.springframework.stereotype.Component +import java.io.File + +@Component +@DependsOn("postgresConfig") +class SetupPreferences( + @Value("preferences.yml") file: File, + pairConfigRepository: PairConfigRepository, + pairFeeConfigRepository: PairFeeConfigRepository +) { + private val mapper = ObjectMapper(YAMLFactory()) + + init { + val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) + runBlocking { + p.markets.map { + launch { + val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" + val leftSideCurrency = p.currencies.first { c -> it.leftSide == c.symbol } + val rightSideCurrency = p.currencies.first { c -> it.rightSide == c.symbol } + val leftSideFraction = (it.leftSideFraction ?: leftSideCurrency.precision).toDouble() + val rightSideFraction = (it.rightSideFraction ?: rightSideCurrency.precision).toDouble() + pairConfigRepository.insert( + pair, + it.leftSide, + it.rightSide, + leftSideFraction, + rightSideFraction, + 0.0 + ).awaitSingleOrNull() + it.feeConfigs.forEach { f -> + launch { + pairFeeConfigRepository.save( + PairFeeConfigModel( + null, + pair, + f.direction, + f.userLevel, + f.makerFee.toDouble(), + f.takerFee.toDouble() + ) + ).awaitSingleOrNull() + } + } + } + } + } + } +} diff --git a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/config/PostgresConfig.kt b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/config/PostgresConfig.kt index 10fe331da..dd0fbf78e 100644 --- a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/config/PostgresConfig.kt +++ b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/config/PostgresConfig.kt @@ -11,17 +11,13 @@ import org.springframework.r2dbc.core.DatabaseClient @EnableR2dbcRepositories(basePackages = ["co.nilin.opex"]) class PostgresConfig( db: DatabaseClient, - @Value("classpath:schema.sql") private val schemaResource: Resource, - @Value("classpath:data.sql") private val dataResource: Resource? + @Value("classpath:schema.sql") private val schemaResource: Resource ) { init { val schemaReader = schemaResource.inputStream.reader() val schema = schemaReader.readText().trim() schemaReader.close() - val dataReader = dataResource?.inputStream?.reader() - val data = dataReader?.readText()?.trim() ?: "" - dataReader?.close() - val initDb = db.sql { schema.plus(data) } + val initDb = db.sql { schema } initDb // initialize the database .then() .subscribe() // execute diff --git a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairConfigRepository.kt b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairConfigRepository.kt index 9f76a937b..f455eff05 100644 --- a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairConfigRepository.kt +++ b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairConfigRepository.kt @@ -1,8 +1,20 @@ package co.nilin.opex.accountant.ports.postgres.dao import co.nilin.opex.accountant.ports.postgres.model.PairConfigModel +import org.springframework.data.r2dbc.repository.Query import org.springframework.data.repository.reactive.ReactiveCrudRepository import org.springframework.stereotype.Repository +import reactor.core.publisher.Mono @Repository -interface PairConfigRepository : ReactiveCrudRepository +interface PairConfigRepository : ReactiveCrudRepository { + @Query("insert into pair_config values (:pair, :leftSide, :rightSide, :leftSideFraction, :rightSideFraction, :rate)") + fun insert( + pair: String, + leftSide: String, + rightSide: String, + leftSideFraction: Double, + rightSideFraction: Double, + rate: Double + ): Mono +} diff --git a/accountant/pom.xml b/accountant/pom.xml index 1a20c1ff2..01387a319 100644 --- a/accountant/pom.xml +++ b/accountant/pom.xml @@ -73,6 +73,11 @@ logging-handler ${project.version} + + co.nilin.opex.utility.preferences + preferences + ${project.version} + org.springframework.cloud spring-cloud-dependencies diff --git a/api/api-app/pom.xml b/api/api-app/pom.xml index 00529ca01..38276d23c 100644 --- a/api/api-app/pom.xml +++ b/api/api-app/pom.xml @@ -68,6 +68,15 @@ org.springframework.cloud spring-cloud-starter-vault-config + + co.nilin.opex.utility.preferences + preferences + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + 2.13.0 + diff --git a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt new file mode 100644 index 000000000..78ce83740 --- /dev/null +++ b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt @@ -0,0 +1,36 @@ +package co.nilin.opex.api.app.config + +import co.nilin.opex.api.ports.postgres.dao.SymbolMapRepository +import co.nilin.opex.utility.preferences.ProjectPreferences +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory +import kotlinx.coroutines.launch +import kotlinx.coroutines.reactor.awaitSingle +import kotlinx.coroutines.reactor.awaitSingleOrNull +import kotlinx.coroutines.runBlocking +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.DependsOn +import org.springframework.stereotype.Component +import java.io.File + +@Component +@DependsOn("postgresConfig") +class SetupPreferences( + @Value("preferences.yml") file: File, + symbolMapRepository: SymbolMapRepository +) { + private val mapper = ObjectMapper(YAMLFactory()) + + init { + val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) + runBlocking { + p.markets.map { + launch { + val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" + if (!symbolMapRepository.existsById(pair).awaitSingle()) + symbolMapRepository.insert(pair, it.aliases.first()).awaitSingleOrNull() + } + } + } + } +} diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt index 4bc30a34a..a56b06a69 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt @@ -15,4 +15,7 @@ interface SymbolMapRepository : ReactiveCrudRepository { @Query("select * from symbol_maps where value = :value") fun findByValue(@Param("value") value: String): Mono -} \ No newline at end of file + + @Query("insert into symbol_maps values (:symbol, :value)") + fun insert(symbol: String, value: String): Mono +} diff --git a/api/pom.xml b/api/pom.xml index 701612a51..ec4485c61 100644 --- a/api/pom.xml +++ b/api/pom.xml @@ -77,6 +77,11 @@ interceptors ${project.version} + + co.nilin.opex.utility.preferences + preferences + ${project.version} + org.springframework.cloud spring-cloud-dependencies diff --git a/preferences-schema.yml b/preferences-schema.yml index 5cd5fb4b9..d47a67306 100644 --- a/preferences-schema.yml +++ b/preferences-schema.yml @@ -34,8 +34,7 @@ markets: leftSideFraction: rightSideFraction: aliases: - - key: - value: + - arrItem feeConfigs: - direction: userLevel: diff --git a/preferences.yml b/preferences.yml index 211a2d969..1d03bd3c4 100644 --- a/preferences.yml +++ b/preferences.yml @@ -162,8 +162,7 @@ markets: - leftSide: BTC rightSide: USDT aliases: - - key: binance - value: BTCUSDT + - BTCUSDT feeConfigs: - direction: ASK userLevel: "*" @@ -176,8 +175,7 @@ markets: - leftSide: ETH rightSide: USDT aliases: - - key: binance - value: ETHUSDT + - ETHUSDT feeConfigs: - direction: ASK userLevel: "*" @@ -190,8 +188,7 @@ markets: - leftSide: BNB rightSide: USDT aliases: - - key: binance - value: BNBUSDT + - BNBUSDT feeConfigs: - direction: ASK userLevel: "*" @@ -204,8 +201,7 @@ markets: - leftSide: BTC rightSide: IRT aliases: - - key: binance - value: BTCIRT + - BTCIRT feeConfigs: - direction: ASK userLevel: "*" @@ -218,8 +214,7 @@ markets: - leftSide: ETH rightSide: IRT aliases: - - key: binance - value: ETHIRT + - ETHIRT feeConfigs: - direction: ASK userLevel: "*" @@ -232,8 +227,7 @@ markets: - leftSide: BNB rightSide: IRT aliases: - - key: binance - value: BNBIRT + - BNBIRT feeConfigs: - direction: ASK userLevel: "*" @@ -246,8 +240,7 @@ markets: - leftSide: BUSD rightSide: IRT aliases: - - key: binance - value: BUSDIRT + - BUSDIRT feeConfigs: - direction: ASK userLevel: "*" @@ -260,8 +253,7 @@ markets: - leftSide: TBTC rightSide: TUSDT aliases: - - key: binance - value: TBTCTUSDT + - TBTCTUSDT feeConfigs: - direction: ASK userLevel: "*" @@ -274,8 +266,7 @@ markets: - leftSide: TETH rightSide: TUSDT aliases: - - key: binance - value: TETHTUSDT + - TETHTUSDT feeConfigs: - direction: ASK userLevel: "*" diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt deleted file mode 100644 index 2b04fc665..000000000 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt +++ /dev/null @@ -1,3 +0,0 @@ -package co.nilin.opex.utility.preferences - -data class Alias(var key: String = "", var value: String = "") diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt index fa3ee5456..2bd20b33f 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt @@ -6,8 +6,6 @@ data class Currency( var symbol: String = "", var name: String = "", var precision: BigDecimal = BigDecimal.ZERO, - var leftSideFraction: BigDecimal = BigDecimal.ZERO, - var rightSideFraction: BigDecimal = BigDecimal.ZERO, var mainBalance: BigDecimal = BigDecimal.ZERO, var dailyTotal: BigDecimal = BigDecimal.ZERO, var dailyCount: Int = 0, diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt index 677649594..44e10c193 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/FeeConfig.kt @@ -4,7 +4,7 @@ import java.math.BigDecimal data class FeeConfig( var userLevel: String = "", - var direction: String? = "", + var direction: String = "", var makerFee: BigDecimal = BigDecimal.valueOf(0.01), var takerFee: BigDecimal = BigDecimal.valueOf(0.01) ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt index 04c738c88..c011906b7 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt @@ -7,7 +7,7 @@ data class Market( var rightSide: String = "", var pair: String? = null, var feeConfigs: List = emptyList(), - var aliases: List = emptyList(), + var aliases: List = emptyList(), var leftSideFraction: BigDecimal? = null, var rightSideFraction: BigDecimal? = null ) From 1e751c07070a03567893caf363a3b6b8f918a9d4 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 12:27:02 +0430 Subject: [PATCH 18/44] wallet: Add preferences --- .../opex/utility/preferences/UserLimit.kt | 2 +- wallet/pom.xml | 5 + wallet/wallet-app/pom.xml | 9 ++ .../wallet/app/config/SetupPreferences.kt | 107 ++++++++++++++++++ 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt index 6a6f41ca7..9ecffe7e6 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt @@ -4,7 +4,7 @@ import java.math.BigDecimal data class UserLimit( var level: String = "", - var owner: String = "", + var owner: Long = 0, var action: String = "", var walletType: String = "", var withdrawFee: BigDecimal = BigDecimal.ZERO, diff --git a/wallet/pom.xml b/wallet/pom.xml index 8b7b0dd83..79ffc0cc5 100644 --- a/wallet/pom.xml +++ b/wallet/pom.xml @@ -61,6 +61,11 @@ interceptors ${project.version} + + co.nilin.opex.utility.preferences + preferences + ${project.version} + diff --git a/wallet/wallet-app/pom.xml b/wallet/wallet-app/pom.xml index f38284053..5ffdb319e 100644 --- a/wallet/wallet-app/pom.xml +++ b/wallet/wallet-app/pom.xml @@ -107,6 +107,15 @@ org.springframework.cloud spring-cloud-starter-vault-config + + co.nilin.opex.utility.preferences + preferences + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + 2.13.0 + diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt new file mode 100644 index 000000000..673922591 --- /dev/null +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt @@ -0,0 +1,107 @@ +package co.nilin.opex.wallet.app.config + +import co.nilin.opex.utility.preferences.ProjectPreferences +import co.nilin.opex.wallet.ports.postgres.dao.CurrencyRepository +import co.nilin.opex.wallet.ports.postgres.dao.UserLimitsRepository +import co.nilin.opex.wallet.ports.postgres.dao.WalletOwnerRepository +import co.nilin.opex.wallet.ports.postgres.dao.WalletRepository +import co.nilin.opex.wallet.ports.postgres.model.UserLimitsModel +import co.nilin.opex.wallet.ports.postgres.model.WalletModel +import co.nilin.opex.wallet.ports.postgres.model.WalletOwnerModel +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch +import kotlinx.coroutines.reactor.awaitSingle +import kotlinx.coroutines.reactor.awaitSingleOrNull +import kotlinx.coroutines.runBlocking +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.DependsOn +import org.springframework.stereotype.Component +import java.io.File +import java.math.BigDecimal + +@Component +@DependsOn("postgresConfig") +class SetupPreferences( + @Value("preferences.yml") file: File, + private val currencyRepository: CurrencyRepository, + private val walletOwnerRepository: WalletOwnerRepository, + private val walletRepository: WalletRepository, + private val userLimitsRepository: UserLimitsRepository +) { + private val mapper = ObjectMapper(YAMLFactory()) + + init { + val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) + runBlocking { + addCurrencies(p) + addSystemWallet(p) + addUserLimits(p) + } + } + + private suspend fun addUserLimits(p: ProjectPreferences) = coroutineScope { + p.userLimits.forEachIndexed { i, it -> + launch { + if (!userLimitsRepository.existsById(i + 1L).awaitSingle()) { + userLimitsRepository.save( + UserLimitsModel( + null, + it.level, + it.owner, + it.action, + it.walletType, + it.dailyTotal, + it.dailyCount, + it.monthlyTotal, + it.monthlyCount + ) + ).awaitSingleOrNull() + } + } + } + } + + private suspend fun addSystemWallet(p: ProjectPreferences) = coroutineScope { + if (!walletOwnerRepository.existsById(1).awaitSingle()) { + walletOwnerRepository.save( + WalletOwnerModel( + null, + p.systemWallet.uuid, + p.systemWallet.title, + p.systemWallet.level + ) + ).awaitSingleOrNull() + } + launch { + val items1 = p.currencies.map { + WalletModel( + null, + 1, + "main", + it.symbol, + it.mainBalance + ) + } + val items2 = p.currencies.map { + WalletModel( + null, + 1, + "exchange", + it.symbol, + BigDecimal.ZERO + ) + } + walletRepository.saveAll(items1.zip(items2).flatMap { it.toList() }).collectList().awaitSingleOrNull() + } + } + + private suspend fun addCurrencies(p: ProjectPreferences) = coroutineScope { + p.currencies.forEach { + launch { + currencyRepository.insert(it.name, it.symbol, it.precision.toDouble()).awaitSingleOrNull() + } + } + } +} From 6a3290d92770572489270b1a0b4534045a25b701 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 12:36:53 +0430 Subject: [PATCH 19/44] postgres: Remove data.sql load script --- .../opex/api/ports/postgres/config/PostgresConfig.kt | 8 ++------ .../opex/wallet/ports/postgres/config/PostgresConfig.kt | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/config/PostgresConfig.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/config/PostgresConfig.kt index a2924ed23..47e7038ae 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/config/PostgresConfig.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/config/PostgresConfig.kt @@ -10,17 +10,13 @@ import org.springframework.r2dbc.core.DatabaseClient @EnableR2dbcRepositories(basePackages = ["co.nilin.opex"]) class PostgresConfig( db: DatabaseClient, - @Value("classpath:schema.sql") private val schemaResource: Resource, - @Value("classpath:data.sql") private val dataResource: Resource? + @Value("classpath:schema.sql") private val schemaResource: Resource ) { init { val schemaReader = schemaResource.inputStream.reader() val schema = schemaReader.readText().trim() schemaReader.close() - val dataReader = dataResource?.inputStream?.reader() - val data = dataReader?.readText()?.trim() ?: "" - dataReader?.close() - val initDb = db.sql { schema.plus(data) } + val initDb = db.sql { schema } initDb // initialize the database .then() .subscribe() // execute diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/config/PostgresConfig.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/config/PostgresConfig.kt index 793b4a09a..d06b8686d 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/config/PostgresConfig.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/config/PostgresConfig.kt @@ -10,17 +10,13 @@ import org.springframework.r2dbc.core.DatabaseClient @EnableR2dbcRepositories(basePackages = ["co.nilin.opex"]) class PostgresConfig( db: DatabaseClient, - @Value("classpath:schema.sql") private val schemaResource: Resource, - @Value("classpath:data.sql") private val dataResource: Resource? + @Value("classpath:schema.sql") private val schemaResource: Resource ) { init { val schemaReader = schemaResource.inputStream.reader() val schema = schemaReader.readText().trim() schemaReader.close() - val dataReader = dataResource?.inputStream?.reader() - val data = dataReader?.readText()?.trim() ?: "" - dataReader?.close() - val initDb = db.sql { schema.plus(data) } + val initDb = db.sql { schema } initDb // initialize the database .then() .subscribe() // execute From 7d0ca9df94f7405ce7197c3b522bbc898cae5d2d Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 12:40:49 +0430 Subject: [PATCH 20/44] preferences: Decouple dev and demo environments --- preferences.yml => preferences-demo.yml | 69 --------------- preferences-dev.yml | 113 ++++++++++++++++++++++++ preferences-schema.yml | 56 ------------ 3 files changed, 113 insertions(+), 125 deletions(-) rename preferences.yml => preferences-demo.yml (74%) create mode 100644 preferences-dev.yml delete mode 100644 preferences-schema.yml diff --git a/preferences.yml b/preferences-demo.yml similarity index 74% rename from preferences.yml rename to preferences-demo.yml index 1d03bd3c4..c8f2996a3 100644 --- a/preferences.yml +++ b/preferences-demo.yml @@ -3,8 +3,6 @@ addressTypes: addressRegex: "*" - addressType: ethereum addressRegex: "*" - - addressType: test-bitcoin - addressRegex: "*" chains: - name: bitcoin addressType: bitcoin @@ -24,18 +22,6 @@ chains: schedule: delay: 90 errorDelay: 60 - - name: test-bitcoin - addressType: test-bitcoin - endpointUrl: lb://chain-scan-gateway/test-bitcoin/transfers - schedule: - delay: 600 - errorDelay: 60 - - name: test-ethereum - addressType: ethereum - endpointUrl: lb://chain-scan-gateway/test-eth/transfers - schedule: - delay: 90 - errorDelay: 60 currencies: - symbol: BTC name: Bitcoin @@ -129,35 +115,6 @@ currencies: withdrawFee: 0.0001 withdrawMin: 0.0001 decimal: 0 - - symbol: TETH - name: Ethereum (Test) - precision: 0.000001 - mainBalance: 10000 - dailyTotal: 1000 - dailyCount: 100 - monthlyTotal: 30000 - monthlyCount: 3000 - implementations: - - chain: test-ethereum - withdrawFee: 0.00001 - withdrawMin: 0.000001 - decimal: 18 - - symbol: TUSDT - name: Tether (Test) - precision: 0.01 - mainBalance: 10000 - dailyTotal: 1000 - dailyCount: 100 - monthlyTotal: 30000 - monthlyCount: 3000 - implementations: - - chain: ethereum - token: true - tokenAddress: 0x110a13fc3efe6a245b50102d2d79b3e76125ae83 - tokenName: Tether USD - withdrawFee: 0.01 - withdrawMin: 0.01 - decimal: 6 markets: - leftSide: BTC rightSide: USDT @@ -250,32 +207,6 @@ markets: userLevel: "*" makerFee: 0.01 takerFee: 0.01 - - leftSide: TBTC - rightSide: TUSDT - aliases: - - TBTCTUSDT - feeConfigs: - - direction: ASK - userLevel: "*" - makerFee: 0.01 - takerFee: 0.01 - - direction: BID - userLevel: "*" - makerFee: 0.01 - takerFee: 0.01 - - leftSide: TETH - rightSide: TUSDT - aliases: - - TETHTUSDT - feeConfigs: - - direction: ASK - userLevel: "*" - makerFee: 0.01 - takerFee: 0.01 - - direction: BID - userLevel: "*" - makerFee: 0.01 - takerFee: 0.01 userLimits: - level: zero owner: 1 diff --git a/preferences-dev.yml b/preferences-dev.yml new file mode 100644 index 000000000..b79a19ca8 --- /dev/null +++ b/preferences-dev.yml @@ -0,0 +1,113 @@ +addressTypes: + - addressType: ethereum + addressRegex: "*" + - addressType: test-bitcoin + addressRegex: "*" +chains: + - name: test-bitcoin + addressType: test-bitcoin + endpointUrl: lb://chain-scan-gateway/test-bitcoin/transfers + schedule: + delay: 600 + errorDelay: 60 + - name: test-ethereum + addressType: ethereum + endpointUrl: lb://chain-scan-gateway/test-eth/transfers + schedule: + delay: 90 + errorDelay: 60 +currencies: + - symbol: IRT + name: Toman + precision: 0.1 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + - symbol: TBTC + name: Bitcoin (Test) + precision: 0.000001 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: test-bitcoin + withdrawFee: 0.0001 + withdrawMin: 0.0001 + decimal: 0 + - symbol: TETH + name: Ethereum (Test) + precision: 0.000001 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: test-ethereum + withdrawFee: 0.00001 + withdrawMin: 0.000001 + decimal: 18 + - symbol: TUSDT + name: Tether (Test) + precision: 0.01 + mainBalance: 10000 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 + implementations: + - chain: ethereum + token: true + tokenAddress: 0x110a13fc3efe6a245b50102d2d79b3e76125ae83 + tokenName: Tether USD + withdrawFee: 0.01 + withdrawMin: 0.01 + decimal: 6 +markets: + - leftSide: TBTC + rightSide: TUSDT + aliases: + - TBTCTUSDT + feeConfigs: + - direction: ASK + userLevel: "*" + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: "*" + makerFee: 0.01 + takerFee: 0.01 + - leftSide: TETH + rightSide: TUSDT + aliases: + - TETHTUSDT + feeConfigs: + - direction: ASK + userLevel: "*" + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: "*" + makerFee: 0.01 + takerFee: 0.01 +userLimits: + - level: zero + owner: 1 + action: withdraw + walletType: main + withdrawFee: 0.0001 + dailyTotal: 1000 + dailyCount: 100 + monthlyTotal: 30000 + monthlyCount: 3000 +systemWallet: + uuid: 1 + title: system + level: basic + schedule: + delay: 10 + batchSize: 10000 diff --git a/preferences-schema.yml b/preferences-schema.yml deleted file mode 100644 index d47a67306..000000000 --- a/preferences-schema.yml +++ /dev/null @@ -1,56 +0,0 @@ -addressTypes: - - addressType: - addressRegex: -chains: - - name: - addressType: - endpointUrl: - schedule: - delay: - errorDelay: -currencies: - - symbol: - name: - marketFraction: - precision: - mainBalance: - dailyTotal: - dailyCount: - monthlyTotal: - monthlyCount: - implementations: - - chain: - token: - tokenAddress: - tokenName: - withdrawEnabled: - withdrawFee: - withdrawMin: - decimal: -markets: - - pair: - leftSide: - rightSide: - leftSideFraction: - rightSideFraction: - aliases: - - arrItem - feeConfigs: - - direction: - userLevel: - makerFee: - takerFee: -userLimits: - - level: - withdrawFee: - dailyTotal: - dailyCount: - monthlyTotal: - monthlyCount: -systemWallet: - uuid: - title: - level: - schedule: - delay: - batchSize: From bdb7c358cefb94ef08b99c5d49f2f8dea0ffbef8 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 13:00:32 +0430 Subject: [PATCH 21/44] accountant: Change platform coin to IRT --- accountant/accountant-app/src/main/resources/application.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accountant/accountant-app/src/main/resources/application.yml b/accountant/accountant-app/src/main/resources/application.yml index 6e5e58484..9bf8bbb6a 100644 --- a/accountant/accountant-app/src/main/resources/application.yml +++ b/accountant/accountant-app/src/main/resources/application.yml @@ -45,7 +45,7 @@ spring: config: import: vault://secret/${spring.application.name} app: - coin: nln + coin: IRT address: 1 wallet: url: lb://opex-wallet/ From 7a7860a2d4b350c67ac57b5b0c437883bdcee35d Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 13:05:47 +0430 Subject: [PATCH 22/44] preferences: Read config file location from application.yml --- .../co/nilin/opex/accountant/app/config/SetupPreferences.kt | 2 +- accountant/accountant-app/src/main/resources/application.yml | 1 + .../kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt | 2 +- api/api-app/src/main/resources/application.yml | 1 + .../co/nilin/opex/bcgateway/app/config/SetupPreferences.kt | 2 +- bc-gateway/bc-gateway-app/src/main/resources/application.yml | 1 + .../co/nilin/opex/wallet/app/config/SetupPreferences.kt | 2 +- wallet/wallet-app/src/main/resources/application.yml | 5 +++-- 8 files changed, 10 insertions(+), 6 deletions(-) diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt index 07fbe7190..d950d86ee 100644 --- a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt @@ -17,7 +17,7 @@ import java.io.File @Component @DependsOn("postgresConfig") class SetupPreferences( - @Value("preferences.yml") file: File, + @Value("\${app.preferences}") file: File, pairConfigRepository: PairConfigRepository, pairFeeConfigRepository: PairFeeConfigRepository ) { diff --git a/accountant/accountant-app/src/main/resources/application.yml b/accountant/accountant-app/src/main/resources/application.yml index 9bf8bbb6a..cc04045eb 100644 --- a/accountant/accountant-app/src/main/resources/application.yml +++ b/accountant/accountant-app/src/main/resources/application.yml @@ -49,3 +49,4 @@ app: address: 1 wallet: url: lb://opex-wallet/ + preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt index 78ce83740..127dc172c 100644 --- a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt +++ b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt @@ -16,7 +16,7 @@ import java.io.File @Component @DependsOn("postgresConfig") class SetupPreferences( - @Value("preferences.yml") file: File, + @Value("\${app.preferences}") file: File, symbolMapRepository: SymbolMapRepository ) { private val mapper = ObjectMapper(YAMLFactory()) diff --git a/api/api-app/src/main/resources/application.yml b/api/api-app/src/main/resources/application.yml index 9eb9ec2d8..5ff7f0657 100644 --- a/api/api-app/src/main/resources/application.yml +++ b/api/api-app/src/main/resources/application.yml @@ -55,4 +55,5 @@ app: url: lb://opex-bc-gateway auth: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs + preferences: ${PREFERENCES:classpath:preferences.yml} swagger.authUrl: ${SWAGGER_AUTH_URL:https://api.opex.dev/auth}/realms/opex/protocol/openid-connect/token diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt index e2b22d094..6ed1cfaac 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt @@ -22,7 +22,7 @@ import java.time.LocalDateTime @Component @DependsOn("postgresConfig") class SetupPreferences( - @Value("preferences.yml") file: File, + @Value("\${app.preferences}") file: File, private val addressTypeRepository: AddressTypeRepository, private val chainRepository: ChainRepository, private val chainAddressTypeRepository: ChainAddressTypeRepository, diff --git a/bc-gateway/bc-gateway-app/src/main/resources/application.yml b/bc-gateway/bc-gateway-app/src/main/resources/application.yml index 024ae0aef..49f5e1719 100644 --- a/bc-gateway/bc-gateway-app/src/main/resources/application.yml +++ b/bc-gateway/bc-gateway-app/src/main/resources/application.yml @@ -50,3 +50,4 @@ app: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs wallet: url: lb://opex-wallet + preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt index 673922591..e78164a28 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt @@ -24,7 +24,7 @@ import java.math.BigDecimal @Component @DependsOn("postgresConfig") class SetupPreferences( - @Value("preferences.yml") file: File, + @Value("\${app.preferences}") file: File, private val currencyRepository: CurrencyRepository, private val walletOwnerRepository: WalletOwnerRepository, private val walletRepository: WalletRepository, diff --git a/wallet/wallet-app/src/main/resources/application.yml b/wallet/wallet-app/src/main/resources/application.yml index 6874669f9..5e650b538 100644 --- a/wallet/wallet-app/src/main/resources/application.yml +++ b/wallet/wallet-app/src/main/resources/application.yml @@ -45,12 +45,13 @@ spring: import: vault://secret/${spring.application.name} app: gift: - symbol: tusdt - amount: 1000 + symbol: TUSDT + amount: 100000 auth: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs system: uuid: 1 + preferences: ${PREFERENCES:classpath:preferences.yml} logging: level: org.apache.kafka: ERROR From 5b56d915e4703f7e61cd2237beed371542a4925e Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 13:15:21 +0430 Subject: [PATCH 23/44] preferences: Update docker-compose --- docker-compose.configs.yml | 17 +++++++++++++++++ docker-compose.yml | 5 +++++ 2 files changed, 22 insertions(+) create mode 100644 docker-compose.configs.yml diff --git a/docker-compose.configs.yml b/docker-compose.configs.yml new file mode 100644 index 000000000..d6216ad3c --- /dev/null +++ b/docker-compose.configs.yml @@ -0,0 +1,17 @@ +version: '3.8' +services: + accountant: + volumes: + - "/preferences-dev.yml:/preferences.yml" + matching-engine: + volumes: + - "/preferences-dev.yml:/preferences.yml" + wallet: + volumes: + - "/preferences-dev.yml:/preferences.yml" + api: + volumes: + - "/preferences-dev.yml:/preferences.yml" + bc-gateway: + volumes: + - "/preferences-dev.yml:/preferences.yml" diff --git a/docker-compose.yml b/docker-compose.yml index 1a50b6fb9..23226d405 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -256,6 +256,7 @@ services: - BACKEND_USER=${BACKEND_USER} - VAULT_HOST=vault - SWAGGER_AUTH_URL=$KEYCLOAK_FRONTEND_URL + - PREFERENCES=$PREFERENCES networks: - default depends_on: @@ -292,6 +293,7 @@ services: - JAVA_OPTS=-Xmx256m -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 - KAFKA_IP_PORT=kafka-1:29092,kafka-2:29092,kafka-3:29092 - REDIS_HOST=redis + - PREFERENCES=$PREFERENCES networks: - default depends_on: @@ -352,6 +354,7 @@ services: - BACKEND_USER=${BACKEND_USER} - VAULT_HOST=vault - SWAGGER_AUTH_URL=$KEYCLOAK_FRONTEND_URL + - PREFERENCES=$PREFERENCES depends_on: - kafka-1 - kafka-2 @@ -376,6 +379,7 @@ services: - BACKEND_USER=${BACKEND_USER} - VAULT_HOST=vault - SWAGGER_AUTH_URL=$KEYCLOAK_FRONTEND_URL + - PREFERENCES=$PREFERENCES depends_on: - kafka-1 - kafka-2 @@ -429,6 +433,7 @@ services: - BACKEND_USER=${BACKEND_USER} - VAULT_HOST=vault - SWAGGER_AUTH_URL=$KEYCLOAK_FRONTEND_URL + - PREFERENCES=$PREFERENCES depends_on: - kafka-1 - kafka-2 From d96da2f29638d1c80751555f7aea04538db8c094 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 13:21:25 +0430 Subject: [PATCH 24/44] preferences: Refactor matching-engine to read symbols from preferences --- matching-engine/matching-engine-app/pom.xml | 9 +++++ .../matching/engine/app/config/AppConfig.kt | 39 ++++++++++--------- .../src/main/resources/application.yml | 2 +- matching-engine/pom.xml | 5 +++ 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/matching-engine/matching-engine-app/pom.xml b/matching-engine/matching-engine-app/pom.xml index f35dadf9c..0a8b07676 100644 --- a/matching-engine/matching-engine-app/pom.xml +++ b/matching-engine/matching-engine-app/pom.xml @@ -47,6 +47,15 @@ org.springframework.boot spring-boot-starter-actuator + + co.nilin.opex.utility.preferences + preferences + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + 2.13.0 + diff --git a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt index ef535cba3..b3e3cd721 100644 --- a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt +++ b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt @@ -8,6 +8,9 @@ import co.nilin.opex.matching.engine.core.model.PersistentOrderBook import co.nilin.opex.matching.engine.core.spi.OrderBookPersister import co.nilin.opex.matching.engine.ports.kafka.listener.consumer.EventKafkaListener import co.nilin.opex.matching.engine.ports.kafka.listener.consumer.OrderKafkaListener +import co.nilin.opex.utility.preferences.ProjectPreferences +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -16,13 +19,10 @@ import org.springframework.beans.factory.annotation.Value import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import java.io.File @Configuration class AppConfig { - - @Value("\${spring.app.symbols}") - private val symbols: String? = null - @Bean @ConditionalOnMissingBean(value = [OrderBookPersister::class]) fun orderBookPersister(): OrderBookPersister { @@ -37,23 +37,24 @@ class AppConfig { } @Autowired - fun configureOrderBooks(orderBookPersister: OrderBookPersister) { - symbols!!.split(",") - .forEach { symbol -> - CoroutineScope(AppSchedulers.generalExecutor).launch { - val lastOrderBook = orderBookPersister.loadLastState(symbol) - //todo: load db orders from last order in order book and put in order book - //todo: add missing orders to lastOrderBook or create one - if (lastOrderBook != null) { - withContext(coroutineContext) { - OrderBooks.reloadOrderBook(lastOrderBook) - } - } else { - OrderBooks.createOrderBook(symbol) + fun configureOrderBooks(orderBookPersister: OrderBookPersister, @Value("\${app.preferences}") file: File) { + val mapper = ObjectMapper(YAMLFactory()) + val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) + p.markets.map { it.pair ?: "${it.leftSide}_${it.rightSide}" }.forEach { symbol -> + CoroutineScope(AppSchedulers.generalExecutor).launch { + val lastOrderBook = orderBookPersister.loadLastState(symbol) + //todo: load db orders from last order in order book and put in order book + //todo: add missing orders to lastOrderBook or create one + if (lastOrderBook != null) { + withContext(coroutineContext) { + OrderBooks.reloadOrderBook(lastOrderBook) } - + } else { + OrderBooks.createOrderBook(symbol) } + } + } } @Bean @@ -81,4 +82,4 @@ class AppConfig { exchangeEventHandler.register() } -} \ No newline at end of file +} diff --git a/matching-engine/matching-engine-app/src/main/resources/application.yml b/matching-engine/matching-engine-app/src/main/resources/application.yml index 74dec34ed..134b00fa1 100644 --- a/matching-engine/matching-engine-app/src/main/resources/application.yml +++ b/matching-engine/matching-engine-app/src/main/resources/application.yml @@ -11,4 +11,4 @@ spring: host: ${REDIS_HOST:localhost} port: 6379 app: - symbols: btc_usdt,eth_usdt,eth_btc,tbtc_tusdt,teth_tusdt,teth_tbtc,btc_irt,eth_irt,bnb_irt,bnb_usdt,busd_irt + preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/matching-engine/pom.xml b/matching-engine/pom.xml index da7a0072b..c53a2590f 100644 --- a/matching-engine/pom.xml +++ b/matching-engine/pom.xml @@ -67,6 +67,11 @@ interceptors ${project.version} + + co.nilin.opex.utility.preferences + preferences + ${project.version} + From 5bfafff17744c4f8daab14e67d8d6b4e74308b4a Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 13:49:47 +0430 Subject: [PATCH 25/44] wallet: Move gift to preferences --- preferences-dev.yml | 3 ++ .../opex/utility/preferences/Currency.kt | 3 +- .../app/service/UserRegistrationService.kt | 36 +++++++------------ .../src/main/resources/application.yml | 3 -- 4 files changed, 18 insertions(+), 27 deletions(-) diff --git a/preferences-dev.yml b/preferences-dev.yml index b79a19ca8..40ecda473 100644 --- a/preferences-dev.yml +++ b/preferences-dev.yml @@ -38,6 +38,7 @@ currencies: withdrawFee: 0.0001 withdrawMin: 0.0001 decimal: 0 + gift: 21000000 - symbol: TETH name: Ethereum (Test) precision: 0.000001 @@ -51,6 +52,7 @@ currencies: withdrawFee: 0.00001 withdrawMin: 0.000001 decimal: 18 + gift: 2000 - symbol: TUSDT name: Tether (Test) precision: 0.01 @@ -67,6 +69,7 @@ currencies: withdrawFee: 0.01 withdrawMin: 0.01 decimal: 6 + gift: 1000000 markets: - leftSide: TBTC rightSide: TUSDT diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt index 2bd20b33f..a8457e7a9 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt @@ -11,5 +11,6 @@ data class Currency( var dailyCount: Int = 0, var monthlyTotal: BigDecimal = BigDecimal.ZERO, var monthlyCount: Int = 0, - var implementations: List = emptyList() + var implementations: List = emptyList(), + var gift: BigDecimal = BigDecimal.ZERO ) diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt index 4ee4c420e..521f07f89 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt @@ -2,15 +2,18 @@ package co.nilin.opex.wallet.app.service import co.nilin.opex.utility.error.data.OpexError import co.nilin.opex.utility.error.data.OpexException +import co.nilin.opex.utility.preferences.ProjectPreferences import co.nilin.opex.wallet.core.model.Amount -import co.nilin.opex.wallet.core.model.Wallet import co.nilin.opex.wallet.core.spi.CurrencyService import co.nilin.opex.wallet.core.spi.WalletManager import co.nilin.opex.wallet.core.spi.WalletOwnerManager import co.nilin.opex.wallet.ports.kafka.listener.model.UserCreatedEvent +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Component import org.springframework.transaction.annotation.Transactional +import java.io.File import java.math.BigDecimal @Component @@ -18,31 +21,18 @@ class UserRegistrationService( val walletOwnerManager: WalletOwnerManager, val walletManager: WalletManager, val currencyService: CurrencyService, - @Value("\${app.gift.symbol}") - val symbol: String, - @Value("\${app.gift.amount}") - val amount: BigDecimal + @Value("\${app.preferences}") val file: File ) { @Transactional - suspend fun registerNewUser(event: UserCreatedEvent): Wallet { - val owner = - walletOwnerManager.createWalletOwner(event.uuid, "${event.firstName} ${event.lastName}", "1") + suspend fun registerNewUser(event: UserCreatedEvent) { + val mapper = ObjectMapper(YAMLFactory()) + val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) - val btcSymbol = currencyService.getCurrency("tbtc") ?: throw OpexException(OpexError.CurrencyNotFound) - //TODO REMOVE LATER - walletManager.createWallet( - owner, - Amount(btcSymbol, BigDecimal.ONE), - btcSymbol, - "main" - ) + val owner = walletOwnerManager.createWalletOwner(event.uuid, "${event.firstName} ${event.lastName}", "1") - val giftSymbol = currencyService.getCurrency(symbol) ?: throw OpexException(OpexError.CurrencyNotFound) - return walletManager.createWallet( - owner, - Amount(giftSymbol, amount), - giftSymbol, - "main" - ) + p.currencies.filter { it.gift > BigDecimal.ZERO }.forEach { + val currency = currencyService.getCurrency(it.symbol) ?: throw OpexException(OpexError.CurrencyNotFound) + walletManager.createWallet(owner, Amount(currency, it.gift), currency, "main") + } } } diff --git a/wallet/wallet-app/src/main/resources/application.yml b/wallet/wallet-app/src/main/resources/application.yml index 5e650b538..5a2f15c93 100644 --- a/wallet/wallet-app/src/main/resources/application.yml +++ b/wallet/wallet-app/src/main/resources/application.yml @@ -44,9 +44,6 @@ spring: config: import: vault://secret/${spring.application.name} app: - gift: - symbol: TUSDT - amount: 100000 auth: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs system: From 38b18cf376960109dbb78053ba93864f58221d78 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 14:55:02 +0430 Subject: [PATCH 26/44] wallet: Fix setup preferences --- docker-compose.configs.yml | 10 ++++----- .../wallet/app/config/SetupPreferences.kt | 22 +++++-------------- .../ports/postgres/dao/CurrencyRepository.kt | 4 ++-- .../ports/postgres/model/UserLimitsModel.kt | 4 ++-- .../src/main/resources/schema.sql | 3 ++- 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/docker-compose.configs.yml b/docker-compose.configs.yml index d6216ad3c..28b0d98e6 100644 --- a/docker-compose.configs.yml +++ b/docker-compose.configs.yml @@ -2,16 +2,16 @@ version: '3.8' services: accountant: volumes: - - "/preferences-dev.yml:/preferences.yml" + - "./preferences-dev.yml:/preferences.yml" matching-engine: volumes: - - "/preferences-dev.yml:/preferences.yml" + - "./preferences-dev.yml:/preferences.yml" wallet: volumes: - - "/preferences-dev.yml:/preferences.yml" + - "./preferences-dev.yml:/preferences.yml" api: volumes: - - "/preferences-dev.yml:/preferences.yml" + - "./preferences-dev.yml:/preferences.yml" bc-gateway: volumes: - - "/preferences-dev.yml:/preferences.yml" + - "./preferences-dev.yml:/preferences.yml" diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt index e78164a28..6886abba9 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt @@ -75,25 +75,13 @@ class SetupPreferences( ).awaitSingleOrNull() } launch { - val items1 = p.currencies.map { - WalletModel( - null, - 1, - "main", - it.symbol, - it.mainBalance - ) - } - val items2 = p.currencies.map { - WalletModel( - null, - 1, - "exchange", - it.symbol, - BigDecimal.ZERO + val items = p.currencies.flatMapIndexed { i, it -> + listOf( + WalletModel(null, 1, "main", it.symbol, it.mainBalance), + WalletModel(null, 1, "exchange", it.symbol, BigDecimal.ZERO) ) } - walletRepository.saveAll(items1.zip(items2).flatMap { it.toList() }).collectList().awaitSingleOrNull() + walletRepository.saveAll(items).collectList().awaitSingleOrNull() } } diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/CurrencyRepository.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/CurrencyRepository.kt index dcc8981a2..53700ce0b 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/CurrencyRepository.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/dao/CurrencyRepository.kt @@ -12,10 +12,10 @@ interface CurrencyRepository : ReactiveCrudRepository { @Query("select * from currency where symbol = :symbol") fun findBySymbol(symbol: String): Mono - @Query("insert into currency values (:name, :symbol, :precision) on conflict do nothing") + @Query("insert into currency values (:symbol, :name, :precision) on conflict do nothing") fun insert(name: String, symbol: String, precision: Double): Mono @Query("delete from currency where name = :name") fun deleteByName(name: String): Mono -} \ No newline at end of file +} diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/UserLimitsModel.kt b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/UserLimitsModel.kt index edc298c78..cb70e3379 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/UserLimitsModel.kt +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/kotlin/co/nilin/opex/wallet/ports/postgres/model/UserLimitsModel.kt @@ -7,7 +7,7 @@ import java.math.BigDecimal @Table("user_limits") class UserLimitsModel( - @Id val id: Long?, + @Id var id: Long?, val level: String?, val owner: Long?, val action: String, //withdraw or deposit @@ -16,4 +16,4 @@ class UserLimitsModel( @Column("daily_count") val dailyCount: Int?, @Column("monthly_total") val monthlyTotal: BigDecimal?, @Column("monthly_count") val monthlyCount: Int? -) \ No newline at end of file +) diff --git a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql index fd9462799..e37ea43c1 100644 --- a/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql +++ b/wallet/wallet-ports/wallet-persister-postgres/src/main/resources/schema.sql @@ -31,7 +31,8 @@ CREATE TABLE IF NOT EXISTS wallet owner INTEGER NOT NULL REFERENCES wallet_owner (id), wallet_type VARCHAR(10) NOT NULL, currency VARCHAR(25) NOT NULL REFERENCES currency (symbol), - balance DECIMAL NOT NULL + balance DECIMAL NOT NULL, + UNIQUE (owner, wallet_type, currency) ); CREATE TABLE IF NOT EXISTS transaction From 5f588b4c4ab32090c0075d886e7cbd0cade2db2e Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 15:41:38 +0430 Subject: [PATCH 27/44] preferences: Improve sql scripts --- .../accountant/app/config/SetupPreferences.kt | 22 ++++++----- .../postgres/dao/PairConfigRepository.kt | 2 +- .../opex/api/app/config/SetupPreferences.kt | 4 +- .../ports/postgres/dao/SymbolMapRepository.kt | 2 +- .../bcgateway/app/config/SetupPreferences.kt | 38 ++++++++----------- .../src/main/resources/schema.sql | 4 +- .../wallet/app/config/SetupPreferences.kt | 36 +++++++++--------- 7 files changed, 50 insertions(+), 58 deletions(-) diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt index d950d86ee..ec664d8ba 100644 --- a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt @@ -43,16 +43,18 @@ class SetupPreferences( ).awaitSingleOrNull() it.feeConfigs.forEach { f -> launch { - pairFeeConfigRepository.save( - PairFeeConfigModel( - null, - pair, - f.direction, - f.userLevel, - f.makerFee.toDouble(), - f.takerFee.toDouble() - ) - ).awaitSingleOrNull() + runCatching { + pairFeeConfigRepository.save( + PairFeeConfigModel( + null, + pair, + f.direction, + f.userLevel, + f.makerFee.toDouble(), + f.takerFee.toDouble() + ) + ).awaitSingleOrNull() + } } } } diff --git a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairConfigRepository.kt b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairConfigRepository.kt index f455eff05..c3d9ca417 100644 --- a/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairConfigRepository.kt +++ b/accountant/accountant-ports/accountant-persister-postgres/src/main/kotlin/co/nilin/opex/accountant/ports/postgres/dao/PairConfigRepository.kt @@ -8,7 +8,7 @@ import reactor.core.publisher.Mono @Repository interface PairConfigRepository : ReactiveCrudRepository { - @Query("insert into pair_config values (:pair, :leftSide, :rightSide, :leftSideFraction, :rightSideFraction, :rate)") + @Query("insert into pair_config values (:pair, :leftSide, :rightSide, :leftSideFraction, :rightSideFraction, :rate) on conflict do nothing") fun insert( pair: String, leftSide: String, diff --git a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt index 127dc172c..31c07b5fa 100644 --- a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt +++ b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt @@ -5,7 +5,6 @@ import co.nilin.opex.utility.preferences.ProjectPreferences import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import kotlinx.coroutines.launch -import kotlinx.coroutines.reactor.awaitSingle import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking import org.springframework.beans.factory.annotation.Value @@ -27,8 +26,7 @@ class SetupPreferences( p.markets.map { launch { val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" - if (!symbolMapRepository.existsById(pair).awaitSingle()) - symbolMapRepository.insert(pair, it.aliases.first()).awaitSingleOrNull() + symbolMapRepository.insert(pair, it.aliases.first()).awaitSingleOrNull() } } } diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt index a56b06a69..4ee30a33a 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt @@ -16,6 +16,6 @@ interface SymbolMapRepository : ReactiveCrudRepository { @Query("select * from symbol_maps where value = :value") fun findByValue(@Param("value") value: String): Mono - @Query("insert into symbol_maps values (:symbol, :value)") + @Query("insert into symbol_maps values (:symbol, :value) on conflict do nothing") fun insert(symbol: String, value: String): Mono } diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt index 6ed1cfaac..1e748802b 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt @@ -50,39 +50,31 @@ class SetupPreferences( null else AddressTypeModel(null, it.addressType, it.addressRegex, null) }.filterNotNull() - addressTypeRepository.saveAll(items).collectList().awaitSingleOrNull() + runCatching { addressTypeRepository.saveAll(items).collectList().awaitSingleOrNull() } } private suspend fun addChains(data: List) = coroutineScope { data.map { chainRepository.insert(it.name).awaitSingleOrNull() } - val items1 = data.mapIndexed { i, it -> - if (chainAddressTypeRepository.existsById(i + 1L).awaitSingle()) { - null - } else { - val addressTypeId = addressTypeRepository.findByType(it.addressType).awaitSingle().id!! - ChainAddressTypeModel(null, it.name, addressTypeId) - } - }.filterNotNull() - chainAddressTypeRepository.saveAll(items1).collectList().awaitSingleOrNull() - val items2 = data.mapIndexed { i, it -> - if (chainEndpointRepository.existsById(i + 1L).awaitSingle()) null - else ChainEndpointModel(null, it.name, it.endpointUrl, null, null) - }.filterNotNull() - chainEndpointRepository.saveAll(items2).collectList().awaitSingleOrNull() + val items1 = data.map { + val addressTypeId = addressTypeRepository.findByType(it.addressType).awaitSingle().id!! + ChainAddressTypeModel(null, it.name, addressTypeId) + } + runCatching { chainAddressTypeRepository.saveAll(items1).collectList().awaitSingleOrNull() } + val items2 = data.map { + ChainEndpointModel(null, it.name, it.endpointUrl, null, null) + } + runCatching { chainEndpointRepository.saveAll(items2).collectList().awaitSingleOrNull() } } private suspend fun addCurrencies(data: List) = coroutineScope { coroutineScope { data.forEach { - launch { - currencyRepository.insert(it.name, it.symbol).awaitSingleOrNull() - } + launch { currencyRepository.insert(it.name, it.symbol).awaitSingleOrNull() } } } val items = data.flatMap { it.implementations.map { impl -> it to impl } }.mapIndexed { i, (currency, impl) -> - if (currencyImplementationRepository.existsById(i + 1L).awaitSingle()) null - else CurrencyImplementationModel( + CurrencyImplementationModel( null, currency.symbol, impl.chain, @@ -94,8 +86,8 @@ class SetupPreferences( impl.withdrawMin, impl.decimal ) - }.filterNotNull() - currencyImplementationRepository.saveAll(items).collectList().awaitSingleOrNull() + } + runCatching { currencyImplementationRepository.saveAll(items).collectList().awaitSingleOrNull() } } private suspend fun addSchedules(data: ProjectPreferences) = coroutineScope { @@ -116,7 +108,7 @@ class SetupPreferences( data.systemWallet.schedule.delay, data.systemWallet.schedule.batchSize ) - walletSyncScheduleRepository.save(item).awaitSingleOrNull() + runCatching { walletSyncScheduleRepository.save(item).awaitSingleOrNull() } } } } diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql index 9ee61fab8..2f8fce24a 100644 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql @@ -40,8 +40,8 @@ CREATE TABLE IF NOT EXISTS assigned_address_chains CREATE TABLE IF NOT EXISTS chain_address_types ( id SERIAL PRIMARY KEY, - chain_name VARCHAR(72) NOT NULL REFERENCES chains (name), - addr_type_id INTEGER NOT NULL REFERENCES address_types (id) + chain_name VARCHAR(72) UNIQUE NOT NULL REFERENCES chains (name), + addr_type_id INTEGER NOT NULL REFERENCES address_types (id), ); CREATE TABLE IF NOT EXISTS chain_endpoints diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt index 6886abba9..63962c231 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt @@ -45,19 +45,21 @@ class SetupPreferences( p.userLimits.forEachIndexed { i, it -> launch { if (!userLimitsRepository.existsById(i + 1L).awaitSingle()) { - userLimitsRepository.save( - UserLimitsModel( - null, - it.level, - it.owner, - it.action, - it.walletType, - it.dailyTotal, - it.dailyCount, - it.monthlyTotal, - it.monthlyCount - ) - ).awaitSingleOrNull() + runCatching { + userLimitsRepository.save( + UserLimitsModel( + null, + it.level, + it.owner, + it.action, + it.walletType, + it.dailyTotal, + it.dailyCount, + it.monthlyTotal, + it.monthlyCount + ) + ).awaitSingleOrNull() + } } } } @@ -75,21 +77,19 @@ class SetupPreferences( ).awaitSingleOrNull() } launch { - val items = p.currencies.flatMapIndexed { i, it -> + val items = p.currencies.flatMap { listOf( WalletModel(null, 1, "main", it.symbol, it.mainBalance), WalletModel(null, 1, "exchange", it.symbol, BigDecimal.ZERO) ) } - walletRepository.saveAll(items).collectList().awaitSingleOrNull() + runCatching { walletRepository.saveAll(items).collectList().awaitSingleOrNull() } } } private suspend fun addCurrencies(p: ProjectPreferences) = coroutineScope { p.currencies.forEach { - launch { - currencyRepository.insert(it.name, it.symbol, it.precision.toDouble()).awaitSingleOrNull() - } + launch { currencyRepository.insert(it.name, it.symbol, it.precision.toDouble()).awaitSingleOrNull() } } } } From 563ba7d18d52dd13fe0e2009172ecf798d766783 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 15:46:29 +0430 Subject: [PATCH 28/44] preferences: Remove wallet uuid from configs --- preferences-demo.yml | 1 - preferences-dev.yml | 1 - .../kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt | 3 --- .../kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt | 3 ++- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/preferences-demo.yml b/preferences-demo.yml index c8f2996a3..1fb6f8012 100644 --- a/preferences-demo.yml +++ b/preferences-demo.yml @@ -218,7 +218,6 @@ userLimits: monthlyTotal: 30000 monthlyCount: 3000 systemWallet: - uuid: 1 title: system level: basic schedule: diff --git a/preferences-dev.yml b/preferences-dev.yml index 40ecda473..c9cda0716 100644 --- a/preferences-dev.yml +++ b/preferences-dev.yml @@ -108,7 +108,6 @@ userLimits: monthlyTotal: 30000 monthlyCount: 3000 systemWallet: - uuid: 1 title: system level: basic schedule: diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt index ff21ba38d..a137ea0e0 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt @@ -1,9 +1,6 @@ package co.nilin.opex.utility.preferences -import java.util.* - data class SystemWallet( - var uuid: String = UUID.randomUUID().toString(), var title: String = "", var level: String = "", var schedule: WalletSyncSchedule = WalletSyncSchedule() diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt index 63962c231..cc6ff3834 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt @@ -25,6 +25,7 @@ import java.math.BigDecimal @DependsOn("postgresConfig") class SetupPreferences( @Value("\${app.preferences}") file: File, + @Value("\${app.system.uuid}") val systemUuid: String, private val currencyRepository: CurrencyRepository, private val walletOwnerRepository: WalletOwnerRepository, private val walletRepository: WalletRepository, @@ -70,7 +71,7 @@ class SetupPreferences( walletOwnerRepository.save( WalletOwnerModel( null, - p.systemWallet.uuid, + systemUuid, p.systemWallet.title, p.systemWallet.level ) From a68d15954effc59e5937b499976b12bf3eb6bf5c Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 16:00:16 +0430 Subject: [PATCH 29/44] wallet: Fix preferences: Improve schema.sql --- .../bc-gateway-persister-postgres/src/main/resources/schema.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql index 2f8fce24a..6733d6103 100644 --- a/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql +++ b/bc-gateway/bc-gateway-ports/bc-gateway-persister-postgres/src/main/resources/schema.sql @@ -41,7 +41,7 @@ CREATE TABLE IF NOT EXISTS chain_address_types ( id SERIAL PRIMARY KEY, chain_name VARCHAR(72) UNIQUE NOT NULL REFERENCES chains (name), - addr_type_id INTEGER NOT NULL REFERENCES address_types (id), + addr_type_id INTEGER NOT NULL REFERENCES address_types (id) ); CREATE TABLE IF NOT EXISTS chain_endpoints From bdf60b565b1023bd24095d818c1a6f242a1d0313 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 16:49:55 +0430 Subject: [PATCH 30/44] matching-engine: Fix symbols config --- .../matching/engine/app/config/AppConfig.kt | 15 +++++---------- .../engine/app/config/SetupPreferences.kt | 19 +++++++++++++++++++ .../src/main/resources/application.yml | 4 ++-- .../kafka/listener/config/OrderKafkaConfig.kt | 8 ++++---- .../submitter/config/KafkaTopicConfig.kt | 16 ++++++---------- 5 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt diff --git a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt index b3e3cd721..246c936ee 100644 --- a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt +++ b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/AppConfig.kt @@ -8,21 +8,19 @@ import co.nilin.opex.matching.engine.core.model.PersistentOrderBook import co.nilin.opex.matching.engine.core.spi.OrderBookPersister import co.nilin.opex.matching.engine.ports.kafka.listener.consumer.EventKafkaListener import co.nilin.opex.matching.engine.ports.kafka.listener.consumer.OrderKafkaListener -import co.nilin.opex.utility.preferences.ProjectPreferences -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Value import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration -import java.io.File @Configuration class AppConfig { + @Autowired + private lateinit var symbols: List + @Bean @ConditionalOnMissingBean(value = [OrderBookPersister::class]) fun orderBookPersister(): OrderBookPersister { @@ -37,10 +35,8 @@ class AppConfig { } @Autowired - fun configureOrderBooks(orderBookPersister: OrderBookPersister, @Value("\${app.preferences}") file: File) { - val mapper = ObjectMapper(YAMLFactory()) - val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) - p.markets.map { it.pair ?: "${it.leftSide}_${it.rightSide}" }.forEach { symbol -> + fun configureOrderBooks(orderBookPersister: OrderBookPersister) { + symbols.forEach { symbol -> CoroutineScope(AppSchedulers.generalExecutor).launch { val lastOrderBook = orderBookPersister.loadLastState(symbol) //todo: load db orders from last order in order book and put in order book @@ -81,5 +77,4 @@ class AppConfig { fun configureMatchingEngineListener(exchangeEventHandler: ExchangeEventHandler) { exchangeEventHandler.register() } - } diff --git a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt new file mode 100644 index 000000000..ef7d2208f --- /dev/null +++ b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt @@ -0,0 +1,19 @@ +package co.nilin.opex.matching.engine.app.config + +import co.nilin.opex.utility.preferences.ProjectPreferences +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import java.io.File + +@Configuration +class SetupPreferences(@Value("\${app.preferences}") private val file: File) { + @Bean("symbols") + fun getSymbols(): List { + val mapper = ObjectMapper(YAMLFactory()) + val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) + return p.markets.map { it.pair ?: "${it.leftSide}_${it.rightSide}" }.map { it.lowercase() } + } +} diff --git a/matching-engine/matching-engine-app/src/main/resources/application.yml b/matching-engine/matching-engine-app/src/main/resources/application.yml index 134b00fa1..8fdc2b47f 100644 --- a/matching-engine/matching-engine-app/src/main/resources/application.yml +++ b/matching-engine/matching-engine-app/src/main/resources/application.yml @@ -10,5 +10,5 @@ spring: redis: host: ${REDIS_HOST:localhost} port: 6379 - app: - preferences: ${PREFERENCES:classpath:preferences.yml} +app: + preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/listener/config/OrderKafkaConfig.kt b/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/listener/config/OrderKafkaConfig.kt index 8f2edb314..2817f2c00 100644 --- a/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/listener/config/OrderKafkaConfig.kt +++ b/matching-engine/matching-engine-ports/matching-engine-eventlistener-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/listener/config/OrderKafkaConfig.kt @@ -29,8 +29,8 @@ class OrderKafkaConfig { @Value("\${spring.kafka.consumer.group-id}") private lateinit var groupId: String - @Value("\${spring.app.symbols}") - private lateinit var symbols: String + @Autowired + private lateinit var symbols: List @Bean("consumerConfigs") fun consumerConfigs(): Map { @@ -60,7 +60,7 @@ class OrderKafkaConfig { @Qualifier("orderKafkaTemplate") template: KafkaTemplate, @Qualifier("orderConsumerFactory") consumerFactory: ConsumerFactory ) { - val topics = symbols.split(",").map { s -> "orders_$s" }.toTypedArray() + val topics = symbols.map { s -> "orders_$s" }.toTypedArray() val containerProps = ContainerProperties(*topics) containerProps.messageListener = orderKafkaListener val container = KafkaMessageListenerContainer(consumerFactory, containerProps) @@ -91,4 +91,4 @@ class OrderKafkaConfig { return DefaultErrorHandler(recoverer, FixedBackOff(5_000, 20)) } -} \ No newline at end of file +} diff --git a/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/submitter/config/KafkaTopicConfig.kt b/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/submitter/config/KafkaTopicConfig.kt index 5cbc89854..ee8446e29 100644 --- a/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/submitter/config/KafkaTopicConfig.kt +++ b/matching-engine/matching-engine-ports/matching-engine-submitter-kafka/src/main/kotlin/co/nilin/opex/matching/engine/ports/kafka/submitter/config/KafkaTopicConfig.kt @@ -3,7 +3,6 @@ package co.nilin.opex.matching.engine.ports.kafka.submitter.config import org.apache.kafka.clients.admin.NewTopic import org.apache.kafka.common.config.TopicConfig import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.Configuration import org.springframework.context.support.GenericApplicationContext import org.springframework.kafka.config.TopicBuilder @@ -12,13 +11,12 @@ import java.util.function.Supplier @Configuration class KafkaTopicConfig { - @Value("\${spring.app.symbols}") - private lateinit var symbols: String + @Autowired + private lateinit var symbols: List @Autowired fun createTopics(applicationContext: GenericApplicationContext) { - symbols.split(",") - .map { s -> "orders_$s" } + symbols.map { s -> "orders_$s" } .forEach { topic -> applicationContext.registerBean("topic_${topic}", NewTopic::class.java, Supplier { TopicBuilder.name(topic) @@ -29,8 +27,7 @@ class KafkaTopicConfig { }) } - symbols.split(",") - .map { s -> "events_$s" } + symbols.map { s -> "events_$s" } .forEach { topic -> applicationContext.registerBean("topic_${topic}", NewTopic::class.java, Supplier { TopicBuilder.name(topic) @@ -41,8 +38,7 @@ class KafkaTopicConfig { }) } - symbols.split(",") - .map { s -> "trades_$s" } + symbols.map { s -> "trades_$s" } .forEach { topic -> applicationContext.registerBean("topic_${topic}", NewTopic::class.java, Supplier { TopicBuilder.name(topic) @@ -54,4 +50,4 @@ class KafkaTopicConfig { } } -} \ No newline at end of file +} From 2a62d5dd6f705af8a3a9ae11e31a3e2207e22d7a Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 16:53:09 +0430 Subject: [PATCH 31/44] preferences: Add IRT pairs --- preferences-dev.yml | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/preferences-dev.yml b/preferences-dev.yml index c9cda0716..84dd967e1 100644 --- a/preferences-dev.yml +++ b/preferences-dev.yml @@ -97,6 +97,45 @@ markets: userLevel: "*" makerFee: 0.01 takerFee: 0.01 + - leftSide: TBTC + rightSide: IRT + aliases: + - TBTCIRT + feeConfigs: + - direction: ASK + userLevel: "*" + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: "*" + makerFee: 0.01 + takerFee: 0.01 + - leftSide: TETH + rightSide: IRT + aliases: + - TETHIRT + feeConfigs: + - direction: ASK + userLevel: "*" + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: "*" + makerFee: 0.01 + takerFee: 0.01 + - leftSide: TUSDT + rightSide: IRT + aliases: + - TUSDTIRT + feeConfigs: + - direction: ASK + userLevel: "*" + makerFee: 0.01 + takerFee: 0.01 + - direction: BID + userLevel: "*" + makerFee: 0.01 + takerFee: 0.01 userLimits: - level: zero owner: 1 From a0e6d4fad6b2f6b8613573617984e01b48af0653 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 17:25:07 +0430 Subject: [PATCH 32/44] preferences: Fix and improve alias section --- .../accountant/app/config/SetupPreferences.kt | 55 ++++++++--------- .../opex/api/app/config/SetupPreferences.kt | 9 ++- .../nilin/opex/api/core/spi/SymbolMapper.kt | 6 +- .../binance/controller/FiltersController.kt | 3 +- .../binance/controller/MarketController.kt | 8 +-- .../ports/postgres/dao/SymbolMapRepository.kt | 12 ++-- .../ports/postgres/impl/SymbolMapperImpl.kt | 15 ++--- .../ports/postgres/model/SymbolMapModel.kt | 9 +-- .../src/main/resources/schema.sql | 6 +- .../bcgateway/app/config/SetupPreferences.kt | 18 ++---- preferences-demo.yml | 21 ++++--- preferences-dev.yml | 15 +++-- .../nilin/opex/utility/preferences/Alias.kt | 3 + .../nilin/opex/utility/preferences/Market.kt | 2 +- .../wallet/app/config/SetupPreferences.kt | 59 ++++++++----------- 15 files changed, 115 insertions(+), 126 deletions(-) create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt index ec664d8ba..c66d1e2a5 100644 --- a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt @@ -6,7 +6,6 @@ import co.nilin.opex.accountant.ports.postgres.model.PairFeeConfigModel import co.nilin.opex.utility.preferences.ProjectPreferences import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.yaml.YAMLFactory -import kotlinx.coroutines.launch import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking import org.springframework.beans.factory.annotation.Value @@ -27,35 +26,31 @@ class SetupPreferences( val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) runBlocking { p.markets.map { - launch { - val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" - val leftSideCurrency = p.currencies.first { c -> it.leftSide == c.symbol } - val rightSideCurrency = p.currencies.first { c -> it.rightSide == c.symbol } - val leftSideFraction = (it.leftSideFraction ?: leftSideCurrency.precision).toDouble() - val rightSideFraction = (it.rightSideFraction ?: rightSideCurrency.precision).toDouble() - pairConfigRepository.insert( - pair, - it.leftSide, - it.rightSide, - leftSideFraction, - rightSideFraction, - 0.0 - ).awaitSingleOrNull() - it.feeConfigs.forEach { f -> - launch { - runCatching { - pairFeeConfigRepository.save( - PairFeeConfigModel( - null, - pair, - f.direction, - f.userLevel, - f.makerFee.toDouble(), - f.takerFee.toDouble() - ) - ).awaitSingleOrNull() - } - } + val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" + val leftSideCurrency = p.currencies.first { c -> it.leftSide == c.symbol } + val rightSideCurrency = p.currencies.first { c -> it.rightSide == c.symbol } + val leftSideFraction = (it.leftSideFraction ?: leftSideCurrency.precision).toDouble() + val rightSideFraction = (it.rightSideFraction ?: rightSideCurrency.precision).toDouble() + pairConfigRepository.insert( + pair, + it.leftSide, + it.rightSide, + leftSideFraction, + rightSideFraction, + 0.0 + ).awaitSingleOrNull() + it.feeConfigs.forEach { f -> + runCatching { + pairFeeConfigRepository.save( + PairFeeConfigModel( + null, + pair, + f.direction, + f.userLevel, + f.makerFee.toDouble(), + f.takerFee.toDouble() + ) + ).awaitSingleOrNull() } } } diff --git a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt index 31c07b5fa..4ba5e83e6 100644 --- a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt +++ b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt @@ -1,10 +1,10 @@ package co.nilin.opex.api.app.config import co.nilin.opex.api.ports.postgres.dao.SymbolMapRepository +import co.nilin.opex.api.ports.postgres.model.SymbolMapModel import co.nilin.opex.utility.preferences.ProjectPreferences import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.yaml.YAMLFactory -import kotlinx.coroutines.launch import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking import org.springframework.beans.factory.annotation.Value @@ -24,10 +24,9 @@ class SetupPreferences( val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) runBlocking { p.markets.map { - launch { - val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" - symbolMapRepository.insert(pair, it.aliases.first()).awaitSingleOrNull() - } + val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" + val items = it.aliases.map { a -> SymbolMapModel(null, pair, a.key, a.alias) } + runCatching { symbolMapRepository.saveAll(items).collectList().awaitSingleOrNull() } } } } diff --git a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/SymbolMapper.kt b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/SymbolMapper.kt index 6e36e717c..893080836 100644 --- a/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/SymbolMapper.kt +++ b/api/api-core/src/main/kotlin/co/nilin/opex/api/core/spi/SymbolMapper.kt @@ -4,7 +4,7 @@ interface SymbolMapper { suspend fun map(symbol: String?): String? - suspend fun unmap(value: String?): String? + suspend fun unmap(alias: String?): String? - suspend fun getKeyValues(): Map -} \ No newline at end of file + suspend fun getAll(): Map +} diff --git a/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/FiltersController.kt b/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/FiltersController.kt index 46db1b010..a8bf2d9ca 100644 --- a/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/FiltersController.kt +++ b/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/FiltersController.kt @@ -3,5 +3,4 @@ package co.nilin.opex.api.ports.binance.controller import org.springframework.web.bind.annotation.RestController @RestController -class FiltersController { -} \ No newline at end of file +class FiltersController diff --git a/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/MarketController.kt b/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/MarketController.kt index 92899a607..75f7177a0 100644 --- a/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/MarketController.kt +++ b/api/api-ports/api-binance-rest/src/main/kotlin/co/nilin/opex/api/ports/binance/controller/MarketController.kt @@ -141,15 +141,15 @@ class MarketController( @RequestParam("symbols", required = false) symbols: String? ): ExchangeInfoResponse { - val symbolsMap = symbolMapper.getKeyValues() + val symbolsMap = symbolMapper.getAll() val pairConfigs = accountantProxy.getPairConfigs() .map { ExchangeInfoSymbol( symbolsMap[it.pair] ?: it.pair, "TRADING", - it.leftSideWalletSymbol.toUpperCase(), + it.leftSideWalletSymbol.uppercase(), BigDecimal.valueOf(it.leftSideFraction).scale(), - it.rightSideWalletSymbol.toUpperCase(), + it.rightSideWalletSymbol.uppercase(), BigDecimal.valueOf(it.rightSideFraction).scale() ) } @@ -200,4 +200,4 @@ class MarketController( return list } -} \ No newline at end of file +} diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt index 4ee30a33a..0c1824218 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/dao/SymbolMapRepository.kt @@ -9,13 +9,9 @@ import reactor.core.publisher.Mono @Repository interface SymbolMapRepository : ReactiveCrudRepository { + @Query("select * from symbol_maps where symbol = :symbol and aliasKey = :aliasKey") + fun findByAliasKeyAndSymbol(aliasKey: String, @Param("symbol") symbol: String): Mono - @Query("select * from symbol_maps where symbol = :symbol") - fun findBySymbol(@Param("symbol") symbol: String): Mono - - @Query("select * from symbol_maps where value = :value") - fun findByValue(@Param("value") value: String): Mono - - @Query("insert into symbol_maps values (:symbol, :value) on conflict do nothing") - fun insert(symbol: String, value: String): Mono + @Query("select * from symbol_maps where aliasKey = :aliasKey and alias = :alias") + fun findByAliasKeyAndAlias(aliasKey: String, @Param("alias") alias: String): Mono } diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/SymbolMapperImpl.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/SymbolMapperImpl.kt index d8f462be7..fd7194925 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/SymbolMapperImpl.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/impl/SymbolMapperImpl.kt @@ -11,20 +11,21 @@ class SymbolMapperImpl(val symbolMapRepository: SymbolMapRepository) : SymbolMap override suspend fun map(symbol: String?): String? { if (symbol == null) return null - return symbolMapRepository.findBySymbol(symbol).awaitFirstOrNull()?.value + return symbolMapRepository.findByAliasKeyAndSymbol("binance", symbol).awaitFirstOrNull()?.alias } - override suspend fun unmap(value: String?): String? { - if (value == null) return null - return symbolMapRepository.findByValue(value).awaitFirstOrNull()?.symbol + override suspend fun unmap(alias: String?): String? { + if (alias == null) return null + return symbolMapRepository.findByAliasKeyAndAlias("binance", alias).awaitFirstOrNull()?.symbol } - override suspend fun getKeyValues(): Map { + override suspend fun getAll(): Map { val map = HashMap() symbolMapRepository.findAll() .collectList() .awaitFirstOrElse { emptyList() } - .forEach { map[it.symbol] = it.value } + .filter { it.aliasKey == "binance" } + .associate { it.symbol to it.alias } return map } -} \ No newline at end of file +} diff --git a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/SymbolMapModel.kt b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/SymbolMapModel.kt index 5897724ee..e72ed124a 100644 --- a/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/SymbolMapModel.kt +++ b/api/api-ports/api-persister-postgres/src/main/kotlin/co/nilin/opex/api/ports/postgres/model/SymbolMapModel.kt @@ -2,11 +2,12 @@ package co.nilin.opex.api.ports.postgres.model import org.springframework.data.annotation.Id -import org.springframework.data.relational.core.mapping.Column import org.springframework.data.relational.core.mapping.Table @Table("symbol_maps") class SymbolMapModel( - @Id val symbol: String, - @Column("value") val value: String, -) \ No newline at end of file + @Id var id: Long?, + val symbol: String, + val aliasKey: String, + val alias: String, +) diff --git a/api/api-ports/api-persister-postgres/src/main/resources/schema.sql b/api/api-ports/api-persister-postgres/src/main/resources/schema.sql index 497ccb398..7c4f87865 100644 --- a/api/api-ports/api-persister-postgres/src/main/resources/schema.sql +++ b/api/api-ports/api-persister-postgres/src/main/resources/schema.sql @@ -56,8 +56,10 @@ CREATE TABLE IF NOT EXISTS trades CREATE TABLE IF NOT EXISTS symbol_maps ( - symbol VARCHAR(72) PRIMARY KEY, - value VARCHAR(72) UNIQUE NOT NULL + id SERIAL PRIMARY KEY, + symbol VARCHAR(72) NOT NULL, + aliasKey VARCHAR(72) NOT NULL, + alias VARCHAR(72) UNIQUE NOT NULL ); CREATE OR REPLACE FUNCTION interval_generator( diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt index 1e748802b..e1a59d727 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt @@ -9,7 +9,6 @@ import co.nilin.opex.utility.preferences.ProjectPreferences import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.launch import kotlinx.coroutines.reactor.awaitSingle import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking @@ -60,20 +59,18 @@ class SetupPreferences( ChainAddressTypeModel(null, it.name, addressTypeId) } runCatching { chainAddressTypeRepository.saveAll(items1).collectList().awaitSingleOrNull() } - val items2 = data.map { - ChainEndpointModel(null, it.name, it.endpointUrl, null, null) - } + val items2 = data.map { ChainEndpointModel(null, it.name, it.endpointUrl, null, null) } runCatching { chainEndpointRepository.saveAll(items2).collectList().awaitSingleOrNull() } } private suspend fun addCurrencies(data: List) = coroutineScope { coroutineScope { data.forEach { - launch { currencyRepository.insert(it.name, it.symbol).awaitSingleOrNull() } + currencyRepository.insert(it.name, it.symbol).awaitSingleOrNull() } } val items = - data.flatMap { it.implementations.map { impl -> it to impl } }.mapIndexed { i, (currency, impl) -> + data.flatMap { it.implementations.map { impl -> it to impl } }.map { (currency, impl) -> CurrencyImplementationModel( null, currency.symbol, @@ -92,13 +89,8 @@ class SetupPreferences( private suspend fun addSchedules(data: ProjectPreferences) = coroutineScope { data.chains.map { - launch { - chainSyncScheduleRepository.insert( - it.name, - it.schedule.delay.toInt(), - it.schedule.errorDelay.toInt() - ).awaitSingleOrNull() - } + chainSyncScheduleRepository.insert(it.name, it.schedule.delay.toInt(), it.schedule.errorDelay.toInt()) + .awaitSingleOrNull() } if (walletSyncScheduleRepository.existsById(1).awaitSingle()) null else { diff --git a/preferences-demo.yml b/preferences-demo.yml index 1fb6f8012..9c3f11844 100644 --- a/preferences-demo.yml +++ b/preferences-demo.yml @@ -119,7 +119,8 @@ markets: - leftSide: BTC rightSide: USDT aliases: - - BTCUSDT + - key: binance + alias: BTCUSDT feeConfigs: - direction: ASK userLevel: "*" @@ -132,7 +133,8 @@ markets: - leftSide: ETH rightSide: USDT aliases: - - ETHUSDT + - key: binance + alias: ETHUSDT feeConfigs: - direction: ASK userLevel: "*" @@ -145,7 +147,8 @@ markets: - leftSide: BNB rightSide: USDT aliases: - - BNBUSDT + - key: binance + alias: BNBUSDT feeConfigs: - direction: ASK userLevel: "*" @@ -158,7 +161,8 @@ markets: - leftSide: BTC rightSide: IRT aliases: - - BTCIRT + - key: binance + alias: BTCIRT feeConfigs: - direction: ASK userLevel: "*" @@ -171,7 +175,8 @@ markets: - leftSide: ETH rightSide: IRT aliases: - - ETHIRT + - key: binance + alias: ETHIRT feeConfigs: - direction: ASK userLevel: "*" @@ -184,7 +189,8 @@ markets: - leftSide: BNB rightSide: IRT aliases: - - BNBIRT + - key: binance + alias: BNBIRT feeConfigs: - direction: ASK userLevel: "*" @@ -197,7 +203,8 @@ markets: - leftSide: BUSD rightSide: IRT aliases: - - BUSDIRT + - key: binance + alias: BUSDIRT feeConfigs: - direction: ASK userLevel: "*" diff --git a/preferences-dev.yml b/preferences-dev.yml index 84dd967e1..53b929025 100644 --- a/preferences-dev.yml +++ b/preferences-dev.yml @@ -74,7 +74,8 @@ markets: - leftSide: TBTC rightSide: TUSDT aliases: - - TBTCTUSDT + - key: binance + alias: TBTCTUSDT feeConfigs: - direction: ASK userLevel: "*" @@ -87,7 +88,8 @@ markets: - leftSide: TETH rightSide: TUSDT aliases: - - TETHTUSDT + - key: binance + alias: TETHTUSDT feeConfigs: - direction: ASK userLevel: "*" @@ -100,7 +102,8 @@ markets: - leftSide: TBTC rightSide: IRT aliases: - - TBTCIRT + - key: binance + alias: TBTCIRT feeConfigs: - direction: ASK userLevel: "*" @@ -113,7 +116,8 @@ markets: - leftSide: TETH rightSide: IRT aliases: - - TETHIRT + - key: binance + alias: TETHIRT feeConfigs: - direction: ASK userLevel: "*" @@ -126,7 +130,8 @@ markets: - leftSide: TUSDT rightSide: IRT aliases: - - TUSDTIRT + - key: binance + alias: TUSDTIRT feeConfigs: - direction: ASK userLevel: "*" diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt new file mode 100644 index 000000000..4fbd6b4a8 --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Alias.kt @@ -0,0 +1,3 @@ +package co.nilin.opex.utility.preferences + +data class Alias(var key: String = "", var alias: String = "") diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt index c011906b7..04c738c88 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Market.kt @@ -7,7 +7,7 @@ data class Market( var rightSide: String = "", var pair: String? = null, var feeConfigs: List = emptyList(), - var aliases: List = emptyList(), + var aliases: List = emptyList(), var leftSideFraction: BigDecimal? = null, var rightSideFraction: BigDecimal? = null ) diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt index cc6ff3834..3b39d6a47 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt @@ -11,7 +11,6 @@ import co.nilin.opex.wallet.ports.postgres.model.WalletOwnerModel import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import kotlinx.coroutines.coroutineScope -import kotlinx.coroutines.launch import kotlinx.coroutines.reactor.awaitSingle import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking @@ -44,23 +43,21 @@ class SetupPreferences( private suspend fun addUserLimits(p: ProjectPreferences) = coroutineScope { p.userLimits.forEachIndexed { i, it -> - launch { - if (!userLimitsRepository.existsById(i + 1L).awaitSingle()) { - runCatching { - userLimitsRepository.save( - UserLimitsModel( - null, - it.level, - it.owner, - it.action, - it.walletType, - it.dailyTotal, - it.dailyCount, - it.monthlyTotal, - it.monthlyCount - ) - ).awaitSingleOrNull() - } + if (!userLimitsRepository.existsById(i + 1L).awaitSingle()) { + runCatching { + userLimitsRepository.save( + UserLimitsModel( + null, + it.level, + it.owner, + it.action, + it.walletType, + it.dailyTotal, + it.dailyCount, + it.monthlyTotal, + it.monthlyCount + ) + ).awaitSingleOrNull() } } } @@ -68,29 +65,21 @@ class SetupPreferences( private suspend fun addSystemWallet(p: ProjectPreferences) = coroutineScope { if (!walletOwnerRepository.existsById(1).awaitSingle()) { - walletOwnerRepository.save( - WalletOwnerModel( - null, - systemUuid, - p.systemWallet.title, - p.systemWallet.level - ) - ).awaitSingleOrNull() + walletOwnerRepository.save(WalletOwnerModel(null, systemUuid, p.systemWallet.title, p.systemWallet.level)) + .awaitSingleOrNull() } - launch { - val items = p.currencies.flatMap { - listOf( - WalletModel(null, 1, "main", it.symbol, it.mainBalance), - WalletModel(null, 1, "exchange", it.symbol, BigDecimal.ZERO) - ) - } - runCatching { walletRepository.saveAll(items).collectList().awaitSingleOrNull() } + val items = p.currencies.flatMap { + listOf( + WalletModel(null, 1, "main", it.symbol, it.mainBalance), + WalletModel(null, 1, "exchange", it.symbol, BigDecimal.ZERO) + ) } + runCatching { walletRepository.saveAll(items).collectList().awaitSingleOrNull() } } private suspend fun addCurrencies(p: ProjectPreferences) = coroutineScope { p.currencies.forEach { - launch { currencyRepository.insert(it.name, it.symbol, it.precision.toDouble()).awaitSingleOrNull() } + currencyRepository.insert(it.name, it.symbol, it.precision.toDouble()).awaitSingleOrNull() } } } From 0600724a03ecea3ea694e34f48b3acbb66d25f98 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 17:59:03 +0430 Subject: [PATCH 33/44] api: Add symbol_maps constraints --- .../api-persister-postgres/src/main/resources/schema.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/api-ports/api-persister-postgres/src/main/resources/schema.sql b/api/api-ports/api-persister-postgres/src/main/resources/schema.sql index 7c4f87865..5dc3005bb 100644 --- a/api/api-ports/api-persister-postgres/src/main/resources/schema.sql +++ b/api/api-ports/api-persister-postgres/src/main/resources/schema.sql @@ -59,7 +59,8 @@ CREATE TABLE IF NOT EXISTS symbol_maps id SERIAL PRIMARY KEY, symbol VARCHAR(72) NOT NULL, aliasKey VARCHAR(72) NOT NULL, - alias VARCHAR(72) UNIQUE NOT NULL + alias VARCHAR(72) NOT NULL, + UNIQUE (symbol, aliasKey, alias) ); CREATE OR REPLACE FUNCTION interval_generator( From 4ad4ea9279bfc72623c4a7970f02cb5b1a81543b Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 17:59:49 +0430 Subject: [PATCH 34/44] api: Fix symbol_maps schema --- .../api-persister-postgres/src/main/resources/schema.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/api-ports/api-persister-postgres/src/main/resources/schema.sql b/api/api-ports/api-persister-postgres/src/main/resources/schema.sql index 5dc3005bb..4c59f00ce 100644 --- a/api/api-ports/api-persister-postgres/src/main/resources/schema.sql +++ b/api/api-ports/api-persister-postgres/src/main/resources/schema.sql @@ -58,9 +58,9 @@ CREATE TABLE IF NOT EXISTS symbol_maps ( id SERIAL PRIMARY KEY, symbol VARCHAR(72) NOT NULL, - aliasKey VARCHAR(72) NOT NULL, + alias_key VARCHAR(72) NOT NULL, alias VARCHAR(72) NOT NULL, - UNIQUE (symbol, aliasKey, alias) + UNIQUE (symbol, alias_key, alias) ); CREATE OR REPLACE FUNCTION interval_generator( From 2c0090999c2980843ba734a9a8310d6dc1503974 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 22:42:49 +0430 Subject: [PATCH 35/44] preferences: Move read file logic to preferences --- accountant/accountant-app/pom.xml | 5 ---- .../accountant/app/config/SetupPreferences.kt | 23 ++++++++----------- .../src/main/resources/application.yml | 1 - api/api-app/pom.xml | 5 ---- .../opex/api/app/config/SetupPreferences.kt | 19 ++++++--------- .../src/main/resources/application.yml | 1 - bc-gateway/bc-gateway-app/pom.xml | 5 ---- .../bcgateway/app/config/SetupPreferences.kt | 21 ++++++++--------- .../src/main/resources/application.yml | 1 - matching-engine/matching-engine-app/pom.xml | 5 ---- .../engine/app/config/SetupPreferences.kt | 14 +++++------ .../src/main/resources/application.yml | 2 -- utility/preferences/pom.xml | 13 ++++++++++- .../preferences/reader/ReadPreferences.kt | 23 +++++++++++++++++++ wallet/wallet-app/pom.xml | 5 ---- .../wallet/app/config/SetupPreferences.kt | 18 +++++++-------- .../src/main/resources/application.yml | 1 - 17 files changed, 75 insertions(+), 87 deletions(-) create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt diff --git a/accountant/accountant-app/pom.xml b/accountant/accountant-app/pom.xml index 4e2c00b49..835465fa0 100644 --- a/accountant/accountant-app/pom.xml +++ b/accountant/accountant-app/pom.xml @@ -67,11 +67,6 @@ co.nilin.opex.utility.preferences preferences - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - 2.13.0 - diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt index c66d1e2a5..2d505ea41 100644 --- a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt @@ -4,31 +4,28 @@ import co.nilin.opex.accountant.ports.postgres.dao.PairConfigRepository import co.nilin.opex.accountant.ports.postgres.dao.PairFeeConfigRepository import co.nilin.opex.accountant.ports.postgres.model.PairFeeConfigModel import co.nilin.opex.utility.preferences.ProjectPreferences -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking -import org.springframework.beans.factory.annotation.Value +import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.annotation.DependsOn import org.springframework.stereotype.Component -import java.io.File @Component @DependsOn("postgresConfig") class SetupPreferences( - @Value("\${app.preferences}") file: File, - pairConfigRepository: PairConfigRepository, - pairFeeConfigRepository: PairFeeConfigRepository + private val pairConfigRepository: PairConfigRepository, + private val pairFeeConfigRepository: PairFeeConfigRepository ) { - private val mapper = ObjectMapper(YAMLFactory()) + @Autowired + private lateinit var preferences: ProjectPreferences - init { - val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) + @Autowired + fun init() { runBlocking { - p.markets.map { + preferences.markets.map { val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" - val leftSideCurrency = p.currencies.first { c -> it.leftSide == c.symbol } - val rightSideCurrency = p.currencies.first { c -> it.rightSide == c.symbol } + val leftSideCurrency = preferences.currencies.first { c -> it.leftSide == c.symbol } + val rightSideCurrency = preferences.currencies.first { c -> it.rightSide == c.symbol } val leftSideFraction = (it.leftSideFraction ?: leftSideCurrency.precision).toDouble() val rightSideFraction = (it.rightSideFraction ?: rightSideCurrency.precision).toDouble() pairConfigRepository.insert( diff --git a/accountant/accountant-app/src/main/resources/application.yml b/accountant/accountant-app/src/main/resources/application.yml index cc04045eb..9bf8bbb6a 100644 --- a/accountant/accountant-app/src/main/resources/application.yml +++ b/accountant/accountant-app/src/main/resources/application.yml @@ -49,4 +49,3 @@ app: address: 1 wallet: url: lb://opex-wallet/ - preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/api/api-app/pom.xml b/api/api-app/pom.xml index 38276d23c..f7324038b 100644 --- a/api/api-app/pom.xml +++ b/api/api-app/pom.xml @@ -72,11 +72,6 @@ co.nilin.opex.utility.preferences preferences - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - 2.13.0 - diff --git a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt index 4ba5e83e6..c88f6cd48 100644 --- a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt +++ b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt @@ -3,27 +3,22 @@ package co.nilin.opex.api.app.config import co.nilin.opex.api.ports.postgres.dao.SymbolMapRepository import co.nilin.opex.api.ports.postgres.model.SymbolMapModel import co.nilin.opex.utility.preferences.ProjectPreferences -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking -import org.springframework.beans.factory.annotation.Value +import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.annotation.DependsOn import org.springframework.stereotype.Component -import java.io.File @Component @DependsOn("postgresConfig") -class SetupPreferences( - @Value("\${app.preferences}") file: File, - symbolMapRepository: SymbolMapRepository -) { - private val mapper = ObjectMapper(YAMLFactory()) +class SetupPreferences(private val symbolMapRepository: SymbolMapRepository) { + @Autowired + private lateinit var preferences: ProjectPreferences - init { - val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) + @Autowired + fun init() { runBlocking { - p.markets.map { + preferences.markets.map { val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" val items = it.aliases.map { a -> SymbolMapModel(null, pair, a.key, a.alias) } runCatching { symbolMapRepository.saveAll(items).collectList().awaitSingleOrNull() } diff --git a/api/api-app/src/main/resources/application.yml b/api/api-app/src/main/resources/application.yml index 5ff7f0657..9eb9ec2d8 100644 --- a/api/api-app/src/main/resources/application.yml +++ b/api/api-app/src/main/resources/application.yml @@ -55,5 +55,4 @@ app: url: lb://opex-bc-gateway auth: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs - preferences: ${PREFERENCES:classpath:preferences.yml} swagger.authUrl: ${SWAGGER_AUTH_URL:https://api.opex.dev/auth}/realms/opex/protocol/openid-connect/token diff --git a/bc-gateway/bc-gateway-app/pom.xml b/bc-gateway/bc-gateway-app/pom.xml index 2b2851b28..7c66de544 100644 --- a/bc-gateway/bc-gateway-app/pom.xml +++ b/bc-gateway/bc-gateway-app/pom.xml @@ -94,11 +94,6 @@ org.springframework.cloud spring-cloud-starter-vault-config - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - 2.13.0 - diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt index e1a59d727..d8a8a5c72 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt @@ -6,22 +6,18 @@ import co.nilin.opex.utility.preferences.AddressType import co.nilin.opex.utility.preferences.Chain import co.nilin.opex.utility.preferences.Currency import co.nilin.opex.utility.preferences.ProjectPreferences -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.reactor.awaitSingle import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking -import org.springframework.beans.factory.annotation.Value +import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.annotation.DependsOn import org.springframework.stereotype.Component -import java.io.File import java.time.LocalDateTime @Component @DependsOn("postgresConfig") class SetupPreferences( - @Value("\${app.preferences}") file: File, private val addressTypeRepository: AddressTypeRepository, private val chainRepository: ChainRepository, private val chainAddressTypeRepository: ChainAddressTypeRepository, @@ -31,15 +27,16 @@ class SetupPreferences( private val chainSyncScheduleRepository: ChainSyncScheduleRepository, private val walletSyncScheduleRepository: WalletSyncScheduleRepository ) { - private val mapper = ObjectMapper(YAMLFactory()) + @Autowired + private lateinit var preferences: ProjectPreferences - init { - val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) + @Autowired + fun init() { runBlocking { - addAddressTypes(p.addressTypes) - addChains(p.chains) - addCurrencies(p.currencies) - addSchedules(p) + addAddressTypes(preferences.addressTypes) + addChains(preferences.chains) + addCurrencies(preferences.currencies) + addSchedules(preferences) } } diff --git a/bc-gateway/bc-gateway-app/src/main/resources/application.yml b/bc-gateway/bc-gateway-app/src/main/resources/application.yml index 49f5e1719..024ae0aef 100644 --- a/bc-gateway/bc-gateway-app/src/main/resources/application.yml +++ b/bc-gateway/bc-gateway-app/src/main/resources/application.yml @@ -50,4 +50,3 @@ app: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs wallet: url: lb://opex-wallet - preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/matching-engine/matching-engine-app/pom.xml b/matching-engine/matching-engine-app/pom.xml index 0a8b07676..c27f3b7b4 100644 --- a/matching-engine/matching-engine-app/pom.xml +++ b/matching-engine/matching-engine-app/pom.xml @@ -51,11 +51,6 @@ co.nilin.opex.utility.preferences preferences - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - 2.13.0 - diff --git a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt index ef7d2208f..1edc241df 100644 --- a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt +++ b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt @@ -1,19 +1,17 @@ package co.nilin.opex.matching.engine.app.config import co.nilin.opex.utility.preferences.ProjectPreferences -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory -import org.springframework.beans.factory.annotation.Value +import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration -import java.io.File @Configuration -class SetupPreferences(@Value("\${app.preferences}") private val file: File) { +class SetupPreferences() { + @Autowired + private lateinit var preferences: ProjectPreferences + @Bean("symbols") fun getSymbols(): List { - val mapper = ObjectMapper(YAMLFactory()) - val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) - return p.markets.map { it.pair ?: "${it.leftSide}_${it.rightSide}" }.map { it.lowercase() } + return preferences.markets.map { it.pair ?: "${it.leftSide}_${it.rightSide}" }.map { it.lowercase() } } } diff --git a/matching-engine/matching-engine-app/src/main/resources/application.yml b/matching-engine/matching-engine-app/src/main/resources/application.yml index 8fdc2b47f..694e6c8a0 100644 --- a/matching-engine/matching-engine-app/src/main/resources/application.yml +++ b/matching-engine/matching-engine-app/src/main/resources/application.yml @@ -10,5 +10,3 @@ spring: redis: host: ${REDIS_HOST:localhost} port: 6379 -app: - preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/utility/preferences/pom.xml b/utility/preferences/pom.xml index 2d2e9e0ff..62ead6424 100644 --- a/utility/preferences/pom.xml +++ b/utility/preferences/pom.xml @@ -12,4 +12,15 @@ co.nilin.opex.utility.preferences preferences - \ No newline at end of file + + + org.springframework.boot + spring-boot-starter-data-r2dbc + + + com.fasterxml.jackson.dataformat + jackson-dataformat-yaml + 2.13.0 + + + diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt new file mode 100644 index 000000000..24808e8da --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt @@ -0,0 +1,23 @@ +package co.nilin.opex.utility.preferences.reader + +import co.nilin.opex.utility.preferences.ProjectPreferences +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import java.io.File + +@Configuration +class ReadPreferences() { + private val mapper = ObjectMapper(YAMLFactory()) + + @Value("\${app.preferences}") + private lateinit var preferencesYmlPath: String + + @Bean + fun preferences(): ProjectPreferences { + val preferencesYml = File(preferencesYmlPath) + return mapper.readValue(preferencesYml, ProjectPreferences::class.java) + } +} diff --git a/wallet/wallet-app/pom.xml b/wallet/wallet-app/pom.xml index 5ffdb319e..f3fa59979 100644 --- a/wallet/wallet-app/pom.xml +++ b/wallet/wallet-app/pom.xml @@ -111,11 +111,6 @@ co.nilin.opex.utility.preferences preferences - - com.fasterxml.jackson.dataformat - jackson-dataformat-yaml - 2.13.0 - diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt index 3b39d6a47..6c4d83f52 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt @@ -8,36 +8,34 @@ import co.nilin.opex.wallet.ports.postgres.dao.WalletRepository import co.nilin.opex.wallet.ports.postgres.model.UserLimitsModel import co.nilin.opex.wallet.ports.postgres.model.WalletModel import co.nilin.opex.wallet.ports.postgres.model.WalletOwnerModel -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.reactor.awaitSingle import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking +import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value import org.springframework.context.annotation.DependsOn import org.springframework.stereotype.Component -import java.io.File import java.math.BigDecimal @Component @DependsOn("postgresConfig") class SetupPreferences( - @Value("\${app.preferences}") file: File, @Value("\${app.system.uuid}") val systemUuid: String, private val currencyRepository: CurrencyRepository, private val walletOwnerRepository: WalletOwnerRepository, private val walletRepository: WalletRepository, private val userLimitsRepository: UserLimitsRepository ) { - private val mapper = ObjectMapper(YAMLFactory()) + @Autowired + private lateinit var preferences: ProjectPreferences - init { - val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) + @Autowired + fun init() { runBlocking { - addCurrencies(p) - addSystemWallet(p) - addUserLimits(p) + addCurrencies(preferences) + addSystemWallet(preferences) + addUserLimits(preferences) } } diff --git a/wallet/wallet-app/src/main/resources/application.yml b/wallet/wallet-app/src/main/resources/application.yml index 5a2f15c93..2f3f0f75e 100644 --- a/wallet/wallet-app/src/main/resources/application.yml +++ b/wallet/wallet-app/src/main/resources/application.yml @@ -48,7 +48,6 @@ app: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs system: uuid: 1 - preferences: ${PREFERENCES:classpath:preferences.yml} logging: level: org.apache.kafka: ERROR From 7bbeaec5430246ecf9cdf40cc6405d198692d504 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 22:47:07 +0430 Subject: [PATCH 36/44] preferences: Add app.preferences to application.yml of all modules --- accountant/accountant-app/src/main/resources/application.yml | 1 + api/api-app/src/main/resources/application.yml | 1 + bc-gateway/bc-gateway-app/src/main/resources/application.yml | 1 + .../matching-engine-app/src/main/resources/application.yml | 1 + wallet/wallet-app/src/main/resources/application.yml | 1 + 5 files changed, 5 insertions(+) diff --git a/accountant/accountant-app/src/main/resources/application.yml b/accountant/accountant-app/src/main/resources/application.yml index 9bf8bbb6a..cc04045eb 100644 --- a/accountant/accountant-app/src/main/resources/application.yml +++ b/accountant/accountant-app/src/main/resources/application.yml @@ -49,3 +49,4 @@ app: address: 1 wallet: url: lb://opex-wallet/ + preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/api/api-app/src/main/resources/application.yml b/api/api-app/src/main/resources/application.yml index 9eb9ec2d8..5ff7f0657 100644 --- a/api/api-app/src/main/resources/application.yml +++ b/api/api-app/src/main/resources/application.yml @@ -55,4 +55,5 @@ app: url: lb://opex-bc-gateway auth: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs + preferences: ${PREFERENCES:classpath:preferences.yml} swagger.authUrl: ${SWAGGER_AUTH_URL:https://api.opex.dev/auth}/realms/opex/protocol/openid-connect/token diff --git a/bc-gateway/bc-gateway-app/src/main/resources/application.yml b/bc-gateway/bc-gateway-app/src/main/resources/application.yml index 024ae0aef..49f5e1719 100644 --- a/bc-gateway/bc-gateway-app/src/main/resources/application.yml +++ b/bc-gateway/bc-gateway-app/src/main/resources/application.yml @@ -50,3 +50,4 @@ app: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs wallet: url: lb://opex-wallet + preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/matching-engine/matching-engine-app/src/main/resources/application.yml b/matching-engine/matching-engine-app/src/main/resources/application.yml index 694e6c8a0..84d99b169 100644 --- a/matching-engine/matching-engine-app/src/main/resources/application.yml +++ b/matching-engine/matching-engine-app/src/main/resources/application.yml @@ -10,3 +10,4 @@ spring: redis: host: ${REDIS_HOST:localhost} port: 6379 + preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/wallet/wallet-app/src/main/resources/application.yml b/wallet/wallet-app/src/main/resources/application.yml index 2f3f0f75e..5a2f15c93 100644 --- a/wallet/wallet-app/src/main/resources/application.yml +++ b/wallet/wallet-app/src/main/resources/application.yml @@ -48,6 +48,7 @@ app: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs system: uuid: 1 + preferences: ${PREFERENCES:classpath:preferences.yml} logging: level: org.apache.kafka: ERROR From e6bc7c516dccdfd0a3507c566d63f4909ecb5655 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 22:57:00 +0430 Subject: [PATCH 37/44] preferences: Handle missing file --- .../opex/utility/preferences/reader/ReadPreferences.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt index 24808e8da..9838083b9 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt @@ -16,8 +16,8 @@ class ReadPreferences() { private lateinit var preferencesYmlPath: String @Bean - fun preferences(): ProjectPreferences { + fun preferences(): ProjectPreferences = runCatching { val preferencesYml = File(preferencesYmlPath) - return mapper.readValue(preferencesYml, ProjectPreferences::class.java) - } + mapper.readValue(preferencesYml, ProjectPreferences::class.java) + }.getOrElse { ProjectPreferences() } } From 0447abc784f647c341afc2159b087263c692f098 Mon Sep 17 00:00:00 2001 From: ebrahimmfadae Date: Fri, 13 May 2022 23:08:47 +0430 Subject: [PATCH 38/44] preferences: Rename SetupPreferences to InitializeService --- .../app/config/InitializeService.kt | 54 ++++++++++++++++++ .../accountant/app/config/SetupPreferences.kt | 56 ------------------- ...tupPreferences.kt => InitializeService.kt} | 14 ++--- ...tupPreferences.kt => InitializeService.kt} | 14 ++--- ...tupPreferences.kt => InitializeService.kt} | 2 +- ...tupPreferences.kt => InitializeService.kt} | 22 ++++---- 6 files changed, 78 insertions(+), 84 deletions(-) create mode 100644 accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/InitializeService.kt delete mode 100644 accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt rename api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/{SetupPreferences.kt => InitializeService.kt} (58%) rename bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/{SetupPreferences.kt => InitializeService.kt} (94%) rename matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/{SetupPreferences.kt => InitializeService.kt} (95%) rename wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/{SetupPreferences.kt => InitializeService.kt} (85%) diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/InitializeService.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/InitializeService.kt new file mode 100644 index 000000000..9c7e16646 --- /dev/null +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/InitializeService.kt @@ -0,0 +1,54 @@ +package co.nilin.opex.accountant.app.config + +import co.nilin.opex.accountant.ports.postgres.dao.PairConfigRepository +import co.nilin.opex.accountant.ports.postgres.dao.PairFeeConfigRepository +import co.nilin.opex.accountant.ports.postgres.model.PairFeeConfigModel +import co.nilin.opex.utility.preferences.ProjectPreferences +import kotlinx.coroutines.reactor.awaitSingleOrNull +import kotlinx.coroutines.runBlocking +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.annotation.DependsOn +import org.springframework.stereotype.Component + +@Component +@DependsOn("postgresConfig") +class InitializeService( + private val pairConfigRepository: PairConfigRepository, + private val pairFeeConfigRepository: PairFeeConfigRepository +) { + @Autowired + private lateinit var preferences: ProjectPreferences + + @Autowired + fun init() = runBlocking { + preferences.markets.map { + val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" + val leftSideCurrency = preferences.currencies.first { c -> it.leftSide == c.symbol } + val rightSideCurrency = preferences.currencies.first { c -> it.rightSide == c.symbol } + val leftSideFraction = (it.leftSideFraction ?: leftSideCurrency.precision).toDouble() + val rightSideFraction = (it.rightSideFraction ?: rightSideCurrency.precision).toDouble() + pairConfigRepository.insert( + pair, + it.leftSide, + it.rightSide, + leftSideFraction, + rightSideFraction, + 0.0 + ).awaitSingleOrNull() + it.feeConfigs.forEach { f -> + runCatching { + pairFeeConfigRepository.save( + PairFeeConfigModel( + null, + pair, + f.direction, + f.userLevel, + f.makerFee.toDouble(), + f.takerFee.toDouble() + ) + ).awaitSingleOrNull() + } + } + } + } +} diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt deleted file mode 100644 index 2d505ea41..000000000 --- a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/SetupPreferences.kt +++ /dev/null @@ -1,56 +0,0 @@ -package co.nilin.opex.accountant.app.config - -import co.nilin.opex.accountant.ports.postgres.dao.PairConfigRepository -import co.nilin.opex.accountant.ports.postgres.dao.PairFeeConfigRepository -import co.nilin.opex.accountant.ports.postgres.model.PairFeeConfigModel -import co.nilin.opex.utility.preferences.ProjectPreferences -import kotlinx.coroutines.reactor.awaitSingleOrNull -import kotlinx.coroutines.runBlocking -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.context.annotation.DependsOn -import org.springframework.stereotype.Component - -@Component -@DependsOn("postgresConfig") -class SetupPreferences( - private val pairConfigRepository: PairConfigRepository, - private val pairFeeConfigRepository: PairFeeConfigRepository -) { - @Autowired - private lateinit var preferences: ProjectPreferences - - @Autowired - fun init() { - runBlocking { - preferences.markets.map { - val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" - val leftSideCurrency = preferences.currencies.first { c -> it.leftSide == c.symbol } - val rightSideCurrency = preferences.currencies.first { c -> it.rightSide == c.symbol } - val leftSideFraction = (it.leftSideFraction ?: leftSideCurrency.precision).toDouble() - val rightSideFraction = (it.rightSideFraction ?: rightSideCurrency.precision).toDouble() - pairConfigRepository.insert( - pair, - it.leftSide, - it.rightSide, - leftSideFraction, - rightSideFraction, - 0.0 - ).awaitSingleOrNull() - it.feeConfigs.forEach { f -> - runCatching { - pairFeeConfigRepository.save( - PairFeeConfigModel( - null, - pair, - f.direction, - f.userLevel, - f.makerFee.toDouble(), - f.takerFee.toDouble() - ) - ).awaitSingleOrNull() - } - } - } - } - } -} diff --git a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/InitializeService.kt similarity index 58% rename from api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt rename to api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/InitializeService.kt index c88f6cd48..f36ea8ba6 100644 --- a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/SetupPreferences.kt +++ b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/InitializeService.kt @@ -11,18 +11,16 @@ import org.springframework.stereotype.Component @Component @DependsOn("postgresConfig") -class SetupPreferences(private val symbolMapRepository: SymbolMapRepository) { +class InitializeService(private val symbolMapRepository: SymbolMapRepository) { @Autowired private lateinit var preferences: ProjectPreferences @Autowired - fun init() { - runBlocking { - preferences.markets.map { - val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" - val items = it.aliases.map { a -> SymbolMapModel(null, pair, a.key, a.alias) } - runCatching { symbolMapRepository.saveAll(items).collectList().awaitSingleOrNull() } - } + fun init() = runBlocking { + preferences.markets.map { + val pair = it.pair ?: "${it.leftSide}_${it.rightSide}" + val items = it.aliases.map { a -> SymbolMapModel(null, pair, a.key, a.alias) } + runCatching { symbolMapRepository.saveAll(items).collectList().awaitSingleOrNull() } } } } diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/InitializeService.kt similarity index 94% rename from bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt rename to bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/InitializeService.kt index d8a8a5c72..e9eabc4ff 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/SetupPreferences.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/InitializeService.kt @@ -17,7 +17,7 @@ import java.time.LocalDateTime @Component @DependsOn("postgresConfig") -class SetupPreferences( +class InitializeService( private val addressTypeRepository: AddressTypeRepository, private val chainRepository: ChainRepository, private val chainAddressTypeRepository: ChainAddressTypeRepository, @@ -31,13 +31,11 @@ class SetupPreferences( private lateinit var preferences: ProjectPreferences @Autowired - fun init() { - runBlocking { - addAddressTypes(preferences.addressTypes) - addChains(preferences.chains) - addCurrencies(preferences.currencies) - addSchedules(preferences) - } + fun init() = runBlocking { + addAddressTypes(preferences.addressTypes) + addChains(preferences.chains) + addCurrencies(preferences.currencies) + addSchedules(preferences) } private suspend fun addAddressTypes(data: List) = coroutineScope { diff --git a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/InitializeService.kt similarity index 95% rename from matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt rename to matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/InitializeService.kt index 1edc241df..283d1b39c 100644 --- a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/SetupPreferences.kt +++ b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/InitializeService.kt @@ -6,7 +6,7 @@ import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @Configuration -class SetupPreferences() { +class InitializeService() { @Autowired private lateinit var preferences: ProjectPreferences diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/InitializeService.kt similarity index 85% rename from wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt rename to wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/InitializeService.kt index 6c4d83f52..373ac96be 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/SetupPreferences.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/InitializeService.kt @@ -1,6 +1,8 @@ package co.nilin.opex.wallet.app.config +import co.nilin.opex.utility.preferences.Currency import co.nilin.opex.utility.preferences.ProjectPreferences +import co.nilin.opex.utility.preferences.UserLimit import co.nilin.opex.wallet.ports.postgres.dao.CurrencyRepository import co.nilin.opex.wallet.ports.postgres.dao.UserLimitsRepository import co.nilin.opex.wallet.ports.postgres.dao.WalletOwnerRepository @@ -20,7 +22,7 @@ import java.math.BigDecimal @Component @DependsOn("postgresConfig") -class SetupPreferences( +class InitializeService( @Value("\${app.system.uuid}") val systemUuid: String, private val currencyRepository: CurrencyRepository, private val walletOwnerRepository: WalletOwnerRepository, @@ -31,16 +33,14 @@ class SetupPreferences( private lateinit var preferences: ProjectPreferences @Autowired - fun init() { - runBlocking { - addCurrencies(preferences) - addSystemWallet(preferences) - addUserLimits(preferences) - } + fun init() = runBlocking { + addCurrencies(preferences.currencies) + addSystemWallet(preferences) + addUserLimits(preferences.userLimits) } - private suspend fun addUserLimits(p: ProjectPreferences) = coroutineScope { - p.userLimits.forEachIndexed { i, it -> + private suspend fun addUserLimits(data: List) = coroutineScope { + data.forEachIndexed { i, it -> if (!userLimitsRepository.existsById(i + 1L).awaitSingle()) { runCatching { userLimitsRepository.save( @@ -75,8 +75,8 @@ class SetupPreferences( runCatching { walletRepository.saveAll(items).collectList().awaitSingleOrNull() } } - private suspend fun addCurrencies(p: ProjectPreferences) = coroutineScope { - p.currencies.forEach { + private suspend fun addCurrencies(data: List) = coroutineScope { + data.forEach { currencyRepository.insert(it.name, it.symbol, it.precision.toDouble()).awaitSingleOrNull() } } From 0edd857919598aa08a47c844bb749295f9942440 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Sat, 14 May 2022 11:16:28 +0430 Subject: [PATCH 39/44] preferences: Move config file address from application.yml to envs --- .../src/main/resources/application.yml | 1 - api/api-app/src/main/resources/application.yml | 1 - .../src/main/resources/application.yml | 1 - docker-compose.configs.yml | 17 ----------------- docker-compose.override.yml | 17 +++++++++++++++++ .../src/main/resources/application.yml | 1 - .../preferences/reader/ReadPreferences.kt | 2 +- .../src/main/resources/application.yml | 1 - 8 files changed, 18 insertions(+), 23 deletions(-) delete mode 100644 docker-compose.configs.yml create mode 100644 docker-compose.override.yml diff --git a/accountant/accountant-app/src/main/resources/application.yml b/accountant/accountant-app/src/main/resources/application.yml index cc04045eb..9bf8bbb6a 100644 --- a/accountant/accountant-app/src/main/resources/application.yml +++ b/accountant/accountant-app/src/main/resources/application.yml @@ -49,4 +49,3 @@ app: address: 1 wallet: url: lb://opex-wallet/ - preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/api/api-app/src/main/resources/application.yml b/api/api-app/src/main/resources/application.yml index 5ff7f0657..9eb9ec2d8 100644 --- a/api/api-app/src/main/resources/application.yml +++ b/api/api-app/src/main/resources/application.yml @@ -55,5 +55,4 @@ app: url: lb://opex-bc-gateway auth: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs - preferences: ${PREFERENCES:classpath:preferences.yml} swagger.authUrl: ${SWAGGER_AUTH_URL:https://api.opex.dev/auth}/realms/opex/protocol/openid-connect/token diff --git a/bc-gateway/bc-gateway-app/src/main/resources/application.yml b/bc-gateway/bc-gateway-app/src/main/resources/application.yml index 49f5e1719..024ae0aef 100644 --- a/bc-gateway/bc-gateway-app/src/main/resources/application.yml +++ b/bc-gateway/bc-gateway-app/src/main/resources/application.yml @@ -50,4 +50,3 @@ app: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs wallet: url: lb://opex-wallet - preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/docker-compose.configs.yml b/docker-compose.configs.yml deleted file mode 100644 index 28b0d98e6..000000000 --- a/docker-compose.configs.yml +++ /dev/null @@ -1,17 +0,0 @@ -version: '3.8' -services: - accountant: - volumes: - - "./preferences-dev.yml:/preferences.yml" - matching-engine: - volumes: - - "./preferences-dev.yml:/preferences.yml" - wallet: - volumes: - - "./preferences-dev.yml:/preferences.yml" - api: - volumes: - - "./preferences-dev.yml:/preferences.yml" - bc-gateway: - volumes: - - "./preferences-dev.yml:/preferences.yml" diff --git a/docker-compose.override.yml b/docker-compose.override.yml new file mode 100644 index 000000000..647bb9cbc --- /dev/null +++ b/docker-compose.override.yml @@ -0,0 +1,17 @@ +version: '3.8' +services: + accountant: + volumes: + - "./preferences-$PREFERENCES_IDENTIFIER.yml:/preferences.yml" + matching-engine: + volumes: + - "./preferences-$PREFERENCES_IDENTIFIER.yml:/preferences.yml" + wallet: + volumes: + - "./preferences-$PREFERENCES_IDENTIFIER.yml:/preferences.yml" + api: + volumes: + - "./preferences-$PREFERENCES_IDENTIFIER.yml:/preferences.yml" + bc-gateway: + volumes: + - "./preferences-$PREFERENCES_IDENTIFIER.yml:/preferences.yml" diff --git a/matching-engine/matching-engine-app/src/main/resources/application.yml b/matching-engine/matching-engine-app/src/main/resources/application.yml index 84d99b169..694e6c8a0 100644 --- a/matching-engine/matching-engine-app/src/main/resources/application.yml +++ b/matching-engine/matching-engine-app/src/main/resources/application.yml @@ -10,4 +10,3 @@ spring: redis: host: ${REDIS_HOST:localhost} port: 6379 - preferences: ${PREFERENCES:classpath:preferences.yml} diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt index 9838083b9..69a8e38cd 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt @@ -12,7 +12,7 @@ import java.io.File class ReadPreferences() { private val mapper = ObjectMapper(YAMLFactory()) - @Value("\${app.preferences}") + @Value("\${PREFERENCES:classpath:preferences.yml}") private lateinit var preferencesYmlPath: String @Bean diff --git a/wallet/wallet-app/src/main/resources/application.yml b/wallet/wallet-app/src/main/resources/application.yml index 5a2f15c93..2f3f0f75e 100644 --- a/wallet/wallet-app/src/main/resources/application.yml +++ b/wallet/wallet-app/src/main/resources/application.yml @@ -48,7 +48,6 @@ app: cert-url: lb://opex-auth/auth/realms/opex/protocol/openid-connect/certs system: uuid: 1 - preferences: ${PREFERENCES:classpath:preferences.yml} logging: level: org.apache.kafka: ERROR From 558af9ed7b6087dd15f8359c37bdd7e5ed2b2209 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Sat, 14 May 2022 11:20:43 +0430 Subject: [PATCH 40/44] GitHub: Update GitHub actions --- .github/workflows/dev.yml | 10 ++++++++-- .github/workflows/main.yml | 10 ++++++++-- .github/workflows/pr.yml | 5 ++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index 17152d073..46282070c 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -25,7 +25,10 @@ jobs: - name: Build run: mvn -B -T 1C clean install - name: Build Docker images - run: TAG=dev docker-compose -f docker-compose.build.yml build + env: + TAG: dev + PREFERENCES_IDENTIFIER: dev + run: docker-compose -f docker-compose.build.yml build - name: Login to GitHub Container Registry uses: docker/login-action@v1 with: @@ -33,4 +36,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Push images to GitHub Container Registry - run: TAG=dev docker-compose -f docker-compose.build.yml push + env: + TAG: dev + PREFERENCES_IDENTIFIER: dev + run: docker-compose -f docker-compose.build.yml push diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 69b0c85c5..7ffad3312 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,10 @@ jobs: - name: Build run: mvn -B -T 1C clean install - name: Build Docker images - run: TAG=latest docker-compose -f docker-compose.build.yml build + env: + TAG: latest + PREFERENCES_IDENTIFIER: dev + run: docker-compose -f docker-compose.build.yml build - name: Login to GitHub Container Registry uses: docker/login-action@v1 with: @@ -33,4 +36,7 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - name: Push images to GitHub Container Registry - run: TAG=latest docker-compose -f docker-compose.build.yml push + env: + TAG: dev + PREFERENCES_IDENTIFIER: demo + run: docker-compose -f docker-compose.build.yml push diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 3911048fd..206221671 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -24,4 +24,7 @@ jobs: - name: Build run: mvn -B -T 1C clean install - name: Build Docker images - run: TAG=latest docker-compose -f docker-compose.build.yml build + env: + TAG: dev + PREFERENCES_IDENTIFIER: dev + run: docker-compose -f docker-compose.build.yml build From f370fd2dd6d5d4c4b2d74a6bde6bfcdbcc960076 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Sat, 14 May 2022 11:31:44 +0430 Subject: [PATCH 41/44] wallet: Fix crash in user registration service --- utility/preferences/pom.xml | 4 ++-- .../app/service/UserRegistrationService.kt | 18 ++++++------------ 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/utility/preferences/pom.xml b/utility/preferences/pom.xml index 62ead6424..6dfc536ef 100644 --- a/utility/preferences/pom.xml +++ b/utility/preferences/pom.xml @@ -14,8 +14,8 @@ - org.springframework.boot - spring-boot-starter-data-r2dbc + org.springframework + spring-context com.fasterxml.jackson.dataformat diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt index 521f07f89..492f0a6e0 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt @@ -8,29 +8,23 @@ import co.nilin.opex.wallet.core.spi.CurrencyService import co.nilin.opex.wallet.core.spi.WalletManager import co.nilin.opex.wallet.core.spi.WalletOwnerManager import co.nilin.opex.wallet.ports.kafka.listener.model.UserCreatedEvent -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory -import org.springframework.beans.factory.annotation.Value +import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component import org.springframework.transaction.annotation.Transactional -import java.io.File import java.math.BigDecimal @Component class UserRegistrationService( - val walletOwnerManager: WalletOwnerManager, - val walletManager: WalletManager, - val currencyService: CurrencyService, - @Value("\${app.preferences}") val file: File + val walletOwnerManager: WalletOwnerManager, val walletManager: WalletManager, val currencyService: CurrencyService ) { + @Autowired + private lateinit var preferences: ProjectPreferences + @Transactional suspend fun registerNewUser(event: UserCreatedEvent) { - val mapper = ObjectMapper(YAMLFactory()) - val p: ProjectPreferences = mapper.readValue(file, ProjectPreferences::class.java) - val owner = walletOwnerManager.createWalletOwner(event.uuid, "${event.firstName} ${event.lastName}", "1") - p.currencies.filter { it.gift > BigDecimal.ZERO }.forEach { + preferences.currencies.filter { it.gift > BigDecimal.ZERO }.forEach { val currency = currencyService.getCurrency(it.symbol) ?: throw OpexException(OpexError.CurrencyNotFound) walletManager.createWallet(owner, Amount(currency, it.gift), currency, "main") } From 004fb0995ac872e63208ed51a12e7da702b45aaf Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Sat, 14 May 2022 12:59:39 +0430 Subject: [PATCH 42/44] preferences: Replace USDT with BUSD --- preferences-demo.yml | 41 ++++++----------------------------------- 1 file changed, 6 insertions(+), 35 deletions(-) diff --git a/preferences-demo.yml b/preferences-demo.yml index 9c3f11844..f2b32b8ee 100644 --- a/preferences-demo.yml +++ b/preferences-demo.yml @@ -49,22 +49,6 @@ currencies: withdrawFee: 0.00001 withdrawMin: 0.000001 decimal: 18 - - symbol: USDT - name: Tether - precision: 0.01 - mainBalance: 10000 - dailyTotal: 1000 - dailyCount: 100 - monthlyTotal: 30000 - monthlyCount: 3000 - implementations: - - chain: ethereum - token: true - tokenAddress: 0xdac17f958d2ee523a2206206994597c13d831ec7 - tokenName: Tether USD - withdrawFee: 0.01 - withdrawMin: 0.01 - decimal: 6 - symbol: BNB name: Binance precision: 0.0001 @@ -102,25 +86,12 @@ currencies: dailyCount: 100 monthlyTotal: 30000 monthlyCount: 3000 - - symbol: TBTC - name: Bitcoin (Test) - precision: 0.000001 - mainBalance: 10000 - dailyTotal: 1000 - dailyCount: 100 - monthlyTotal: 30000 - monthlyCount: 3000 - implementations: - - chain: test-bitcoin - withdrawFee: 0.0001 - withdrawMin: 0.0001 - decimal: 0 markets: - leftSide: BTC - rightSide: USDT + rightSide: BUSD aliases: - key: binance - alias: BTCUSDT + alias: BTCBUSD feeConfigs: - direction: ASK userLevel: "*" @@ -131,10 +102,10 @@ markets: makerFee: 0.01 takerFee: 0.01 - leftSide: ETH - rightSide: USDT + rightSide: BUSD aliases: - key: binance - alias: ETHUSDT + alias: ETHBUSD feeConfigs: - direction: ASK userLevel: "*" @@ -145,10 +116,10 @@ markets: makerFee: 0.01 takerFee: 0.01 - leftSide: BNB - rightSide: USDT + rightSide: BUSD aliases: - key: binance - alias: BNBUSDT + alias: BNBBUSD feeConfigs: - direction: ASK userLevel: "*" From 37eac9806e275ceeb44f881686075e30048c28b0 Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Sat, 14 May 2022 13:14:16 +0430 Subject: [PATCH 43/44] preferences: Improve defaults --- .../utility/preferences/ChainSyncSchedule.kt | 3 +-- .../nilin/opex/utility/preferences/Currency.kt | 10 +++++----- .../preferences/CurrencyImplementation.kt | 4 ++-- .../opex/utility/preferences/SystemWallet.kt | 4 ++-- .../nilin/opex/utility/preferences/UserLimit.kt | 16 ++++++++-------- .../utility/preferences/WalletSyncSchedule.kt | 2 +- 6 files changed, 19 insertions(+), 20 deletions(-) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt index f745e1379..19b8f824a 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ChainSyncSchedule.kt @@ -1,6 +1,5 @@ package co.nilin.opex.utility.preferences data class ChainSyncSchedule( - var delay: Long = 0, - var errorDelay: Long = 0 + var delay: Long = 600, var errorDelay: Long = 60 ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt index a8457e7a9..1537c7583 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Currency.kt @@ -5,12 +5,12 @@ import java.math.BigDecimal data class Currency( var symbol: String = "", var name: String = "", - var precision: BigDecimal = BigDecimal.ZERO, + var precision: BigDecimal = BigDecimal.ONE, var mainBalance: BigDecimal = BigDecimal.ZERO, - var dailyTotal: BigDecimal = BigDecimal.ZERO, - var dailyCount: Int = 0, - var monthlyTotal: BigDecimal = BigDecimal.ZERO, - var monthlyCount: Int = 0, + var dailyTotal: BigDecimal = BigDecimal.valueOf(1000), + var dailyCount: Int = 100, + var monthlyTotal: BigDecimal = BigDecimal.valueOf(30000), + var monthlyCount: Int = 3000, var implementations: List = emptyList(), var gift: BigDecimal = BigDecimal.ZERO ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt index 1cfe3c066..97d778095 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/CurrencyImplementation.kt @@ -8,7 +8,7 @@ data class CurrencyImplementation( var token: Boolean = false, var tokenAddress: String? = null, var tokenName: String? = null, - var withdrawFee: BigDecimal = BigDecimal.ZERO, - var withdrawMin: BigDecimal = BigDecimal.ZERO, + var withdrawFee: BigDecimal = BigDecimal.valueOf(0.01), + var withdrawMin: BigDecimal = BigDecimal.valueOf(0.01), var decimal: Int = 0 ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt index a137ea0e0..a1a0251e0 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt @@ -1,7 +1,7 @@ package co.nilin.opex.utility.preferences data class SystemWallet( - var title: String = "", - var level: String = "", + var title: String = "system", + var level: String = "basic", var schedule: WalletSyncSchedule = WalletSyncSchedule() ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt index 9ecffe7e6..7dd1e19ce 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt @@ -4,12 +4,12 @@ import java.math.BigDecimal data class UserLimit( var level: String = "", - var owner: Long = 0, - var action: String = "", - var walletType: String = "", - var withdrawFee: BigDecimal = BigDecimal.ZERO, - var dailyTotal: BigDecimal = BigDecimal.ZERO, - var dailyCount: Int = 0, - var monthlyTotal: BigDecimal = BigDecimal.ZERO, - var monthlyCount: Int = 0 + var owner: Long = 1, + var action: String = "withdraw", + var walletType: String = "main", + var withdrawFee: BigDecimal = BigDecimal.valueOf(0.0001), + var dailyTotal: BigDecimal = BigDecimal.valueOf(1000), + var dailyCount: Int = 100, + var monthlyTotal: BigDecimal = BigDecimal.valueOf(30000), + var monthlyCount: Int = 3000 ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt index 9108b5a59..d001817e2 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/WalletSyncSchedule.kt @@ -1,3 +1,3 @@ package co.nilin.opex.utility.preferences -class WalletSyncSchedule(var delay: Long = 0, var batchSize: Long = 0) +class WalletSyncSchedule(var delay: Long = 10, var batchSize: Long = 10000) From 7fd1598a5dfa2f03889b982f33221420c2e8d52f Mon Sep 17 00:00:00 2001 From: metalicn20 Date: Sat, 14 May 2022 14:10:08 +0430 Subject: [PATCH 44/44] preferences: Refactor config schema --- .../app/config/InitializeService.kt | 4 +- .../opex/api/app/config/InitializeService.kt | 4 +- .../bcgateway/app/config/InitializeService.kt | 43 ++++++++----------- .../engine/app/config/InitializeService.kt | 4 +- preferences-demo.yml | 16 +++---- preferences-dev.yml | 16 +++---- .../{ProjectPreferences.kt => Preferences.kt} | 5 ++- .../nilin/opex/utility/preferences/System.kt | 5 +++ .../opex/utility/preferences/UserLimit.kt | 2 +- .../{SystemWallet.kt => Wallet.kt} | 4 +- .../preferences/reader/ReadPreferences.kt | 8 ++-- .../wallet/app/config/InitializeService.kt | 8 ++-- .../app/service/UserRegistrationService.kt | 4 +- 13 files changed, 61 insertions(+), 62 deletions(-) rename utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/{ProjectPreferences.kt => Preferences.kt} (75%) create mode 100644 utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/System.kt rename utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/{SystemWallet.kt => Wallet.kt} (53%) diff --git a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/InitializeService.kt b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/InitializeService.kt index 9c7e16646..71c857eb0 100644 --- a/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/InitializeService.kt +++ b/accountant/accountant-app/src/main/kotlin/co/nilin/opex/accountant/app/config/InitializeService.kt @@ -3,7 +3,7 @@ package co.nilin.opex.accountant.app.config import co.nilin.opex.accountant.ports.postgres.dao.PairConfigRepository import co.nilin.opex.accountant.ports.postgres.dao.PairFeeConfigRepository import co.nilin.opex.accountant.ports.postgres.model.PairFeeConfigModel -import co.nilin.opex.utility.preferences.ProjectPreferences +import co.nilin.opex.utility.preferences.Preferences import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking import org.springframework.beans.factory.annotation.Autowired @@ -17,7 +17,7 @@ class InitializeService( private val pairFeeConfigRepository: PairFeeConfigRepository ) { @Autowired - private lateinit var preferences: ProjectPreferences + private lateinit var preferences: Preferences @Autowired fun init() = runBlocking { diff --git a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/InitializeService.kt b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/InitializeService.kt index f36ea8ba6..63a9291b3 100644 --- a/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/InitializeService.kt +++ b/api/api-app/src/main/kotlin/co/nilin/opex/api/app/config/InitializeService.kt @@ -2,7 +2,7 @@ package co.nilin.opex.api.app.config import co.nilin.opex.api.ports.postgres.dao.SymbolMapRepository import co.nilin.opex.api.ports.postgres.model.SymbolMapModel -import co.nilin.opex.utility.preferences.ProjectPreferences +import co.nilin.opex.utility.preferences.Preferences import kotlinx.coroutines.reactor.awaitSingleOrNull import kotlinx.coroutines.runBlocking import org.springframework.beans.factory.annotation.Autowired @@ -13,7 +13,7 @@ import org.springframework.stereotype.Component @DependsOn("postgresConfig") class InitializeService(private val symbolMapRepository: SymbolMapRepository) { @Autowired - private lateinit var preferences: ProjectPreferences + private lateinit var preferences: Preferences @Autowired fun init() = runBlocking { diff --git a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/InitializeService.kt b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/InitializeService.kt index e9eabc4ff..9e4a1e6ff 100644 --- a/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/InitializeService.kt +++ b/bc-gateway/bc-gateway-app/src/main/kotlin/co/nilin/opex/bcgateway/app/config/InitializeService.kt @@ -5,7 +5,7 @@ import co.nilin.opex.bcgateway.ports.postgres.model.* import co.nilin.opex.utility.preferences.AddressType import co.nilin.opex.utility.preferences.Chain import co.nilin.opex.utility.preferences.Currency -import co.nilin.opex.utility.preferences.ProjectPreferences +import co.nilin.opex.utility.preferences.Preferences import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.reactor.awaitSingle import kotlinx.coroutines.reactor.awaitSingleOrNull @@ -28,7 +28,7 @@ class InitializeService( private val walletSyncScheduleRepository: WalletSyncScheduleRepository ) { @Autowired - private lateinit var preferences: ProjectPreferences + private lateinit var preferences: Preferences @Autowired fun init() = runBlocking { @@ -40,8 +40,7 @@ class InitializeService( private suspend fun addAddressTypes(data: List) = coroutineScope { val items = data.mapIndexed { i, it -> - if (addressTypeRepository.existsById(i + 1L).awaitSingle()) - null + if (addressTypeRepository.existsById(i + 1L).awaitSingle()) null else AddressTypeModel(null, it.addressType, it.addressRegex, null) }.filterNotNull() runCatching { addressTypeRepository.saveAll(items).collectList().awaitSingleOrNull() } @@ -64,25 +63,24 @@ class InitializeService( currencyRepository.insert(it.name, it.symbol).awaitSingleOrNull() } } - val items = - data.flatMap { it.implementations.map { impl -> it to impl } }.map { (currency, impl) -> - CurrencyImplementationModel( - null, - currency.symbol, - impl.chain, - impl.token, - impl.tokenAddress, - impl.tokenName, - impl.withdrawEnabled, - impl.withdrawFee, - impl.withdrawMin, - impl.decimal - ) - } + val items = data.flatMap { it.implementations.map { impl -> it to impl } }.map { (currency, impl) -> + CurrencyImplementationModel( + null, + currency.symbol, + impl.chain, + impl.token, + impl.tokenAddress, + impl.tokenName, + impl.withdrawEnabled, + impl.withdrawFee, + impl.withdrawMin, + impl.decimal + ) + } runCatching { currencyImplementationRepository.saveAll(items).collectList().awaitSingleOrNull() } } - private suspend fun addSchedules(data: ProjectPreferences) = coroutineScope { + private suspend fun addSchedules(data: Preferences) = coroutineScope { data.chains.map { chainSyncScheduleRepository.insert(it.name, it.schedule.delay.toInt(), it.schedule.errorDelay.toInt()) .awaitSingleOrNull() @@ -90,10 +88,7 @@ class InitializeService( if (walletSyncScheduleRepository.existsById(1).awaitSingle()) null else { val item = WalletSyncScheduleModel( - null, - LocalDateTime.now(), - data.systemWallet.schedule.delay, - data.systemWallet.schedule.batchSize + null, LocalDateTime.now(), data.wallet.schedule.delay, data.wallet.schedule.batchSize ) runCatching { walletSyncScheduleRepository.save(item).awaitSingleOrNull() } } diff --git a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/InitializeService.kt b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/InitializeService.kt index 283d1b39c..ede9e53a1 100644 --- a/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/InitializeService.kt +++ b/matching-engine/matching-engine-app/src/main/kotlin/co/nilin/opex/matching/engine/app/config/InitializeService.kt @@ -1,6 +1,6 @@ package co.nilin.opex.matching.engine.app.config -import co.nilin.opex.utility.preferences.ProjectPreferences +import co.nilin.opex.utility.preferences.Preferences import org.springframework.beans.factory.annotation.Autowired import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration @Configuration class InitializeService() { @Autowired - private lateinit var preferences: ProjectPreferences + private lateinit var preferences: Preferences @Bean("symbols") fun getSymbols(): List { diff --git a/preferences-demo.yml b/preferences-demo.yml index f2b32b8ee..3cbd08b42 100644 --- a/preferences-demo.yml +++ b/preferences-demo.yml @@ -185,9 +185,12 @@ markets: userLevel: "*" makerFee: 0.01 takerFee: 0.01 +wallet: + schedule: + delay: 10 + batchSize: 10000 userLimits: - - level: zero - owner: 1 + - owner: 1 action: withdraw walletType: main withdrawFee: 0.0001 @@ -195,9 +198,6 @@ userLimits: dailyCount: 100 monthlyTotal: 30000 monthlyCount: 3000 -systemWallet: - title: system - level: basic - schedule: - delay: 10 - batchSize: 10000 +system: + walletTitle: system + walletLevel: basic diff --git a/preferences-dev.yml b/preferences-dev.yml index 53b929025..1e97292ea 100644 --- a/preferences-dev.yml +++ b/preferences-dev.yml @@ -141,9 +141,12 @@ markets: userLevel: "*" makerFee: 0.01 takerFee: 0.01 +wallet: + schedule: + delay: 10 + batchSize: 10000 userLimits: - - level: zero - owner: 1 + - owner: 1 action: withdraw walletType: main withdrawFee: 0.0001 @@ -151,9 +154,6 @@ userLimits: dailyCount: 100 monthlyTotal: 30000 monthlyCount: 3000 -systemWallet: - title: system - level: basic - schedule: - delay: 10 - batchSize: 10000 +system: + walletTitle: system + walletLevel: basic diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Preferences.kt similarity index 75% rename from utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt rename to utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Preferences.kt index e20aaa52a..5649f35d2 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/ProjectPreferences.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Preferences.kt @@ -1,10 +1,11 @@ package co.nilin.opex.utility.preferences -data class ProjectPreferences( +data class Preferences( var addressTypes: List = emptyList(), var chains: List = emptyList(), var currencies: List = emptyList(), var markets: List = emptyList(), var userLimits: List = emptyList(), - var systemWallet: SystemWallet = SystemWallet() + var wallet: Wallet = Wallet(), + var system: System = System() ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/System.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/System.kt new file mode 100644 index 000000000..7820c402d --- /dev/null +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/System.kt @@ -0,0 +1,5 @@ +package co.nilin.opex.utility.preferences + +data class System( + var walletTitle: String = "system", var walletLevel: String = "basic" +) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt index 7dd1e19ce..958374899 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/UserLimit.kt @@ -3,7 +3,7 @@ package co.nilin.opex.utility.preferences import java.math.BigDecimal data class UserLimit( - var level: String = "", + var level: String? = null, var owner: Long = 1, var action: String = "withdraw", var walletType: String = "main", diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt similarity index 53% rename from utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt rename to utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt index a1a0251e0..487130f88 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/SystemWallet.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/Wallet.kt @@ -1,7 +1,5 @@ package co.nilin.opex.utility.preferences -data class SystemWallet( - var title: String = "system", - var level: String = "basic", +data class Wallet( var schedule: WalletSyncSchedule = WalletSyncSchedule() ) diff --git a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt index 69a8e38cd..cce06f5cd 100644 --- a/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt +++ b/utility/preferences/src/main/kotlin/co/nilin/opex/utility/preferences/reader/ReadPreferences.kt @@ -1,6 +1,6 @@ package co.nilin.opex.utility.preferences.reader -import co.nilin.opex.utility.preferences.ProjectPreferences +import co.nilin.opex.utility.preferences.Preferences import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.dataformat.yaml.YAMLFactory import org.springframework.beans.factory.annotation.Value @@ -16,8 +16,8 @@ class ReadPreferences() { private lateinit var preferencesYmlPath: String @Bean - fun preferences(): ProjectPreferences = runCatching { + fun preferences(): Preferences = runCatching { val preferencesYml = File(preferencesYmlPath) - mapper.readValue(preferencesYml, ProjectPreferences::class.java) - }.getOrElse { ProjectPreferences() } + mapper.readValue(preferencesYml, Preferences::class.java) + }.getOrElse { Preferences() } } diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/InitializeService.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/InitializeService.kt index 373ac96be..f98c87207 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/InitializeService.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/config/InitializeService.kt @@ -1,7 +1,7 @@ package co.nilin.opex.wallet.app.config import co.nilin.opex.utility.preferences.Currency -import co.nilin.opex.utility.preferences.ProjectPreferences +import co.nilin.opex.utility.preferences.Preferences import co.nilin.opex.utility.preferences.UserLimit import co.nilin.opex.wallet.ports.postgres.dao.CurrencyRepository import co.nilin.opex.wallet.ports.postgres.dao.UserLimitsRepository @@ -30,7 +30,7 @@ class InitializeService( private val userLimitsRepository: UserLimitsRepository ) { @Autowired - private lateinit var preferences: ProjectPreferences + private lateinit var preferences: Preferences @Autowired fun init() = runBlocking { @@ -61,9 +61,9 @@ class InitializeService( } } - private suspend fun addSystemWallet(p: ProjectPreferences) = coroutineScope { + private suspend fun addSystemWallet(p: Preferences) = coroutineScope { if (!walletOwnerRepository.existsById(1).awaitSingle()) { - walletOwnerRepository.save(WalletOwnerModel(null, systemUuid, p.systemWallet.title, p.systemWallet.level)) + walletOwnerRepository.save(WalletOwnerModel(null, systemUuid, p.system.walletTitle, p.system.walletLevel)) .awaitSingleOrNull() } val items = p.currencies.flatMap { diff --git a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt index 492f0a6e0..f2c679c81 100644 --- a/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt +++ b/wallet/wallet-app/src/main/kotlin/co/nilin/opex/wallet/app/service/UserRegistrationService.kt @@ -2,7 +2,7 @@ package co.nilin.opex.wallet.app.service import co.nilin.opex.utility.error.data.OpexError import co.nilin.opex.utility.error.data.OpexException -import co.nilin.opex.utility.preferences.ProjectPreferences +import co.nilin.opex.utility.preferences.Preferences import co.nilin.opex.wallet.core.model.Amount import co.nilin.opex.wallet.core.spi.CurrencyService import co.nilin.opex.wallet.core.spi.WalletManager @@ -18,7 +18,7 @@ class UserRegistrationService( val walletOwnerManager: WalletOwnerManager, val walletManager: WalletManager, val currencyService: CurrencyService ) { @Autowired - private lateinit var preferences: ProjectPreferences + private lateinit var preferences: Preferences @Transactional suspend fun registerNewUser(event: UserCreatedEvent) {