Skip to content
39 changes: 9 additions & 30 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,17 @@ import { TransactionModule } from './endpoints/transaction/transaction.module';
import { SpecializationModule } from './endpoints/category/specialization/specialization.module';
import { NotificationEndpointModule } from './endpoints/notification-endpoint/notification-endpoint.module';
import { DnaCollectionModule } from './endpoints/category/dna-collection/dna-collection.module';
import {
GCloudSecretManagerModule,
GCloudSecretManagerService,
} from '@debionetwork/nestjs-gcloud-secret-manager';
import { keyList, SecretKeyList } from './common/secrets';
import { ConversionModule } from './endpoints/conversion/conversion.module';
import { PinataModule } from './endpoints/pinata/pinata.module';
import { MyriadModule } from './endpoints/myriad/myriad.module';
import { SecondOpinionModule } from './endpoints/second-opinion/second-opinion.module';
import { config } from './config';

require('dotenv').config(); // eslint-disable-line

@Module({
imports: [
ScheduleModule.forRoot(),
GCloudSecretManagerModule.withConfig(process.env.PARENT, SecretKeyList),
TypeOrmModule.forRootAsync({
imports: [
ProcessEnvModule.setDefault({
Expand All @@ -52,23 +47,15 @@ require('dotenv').config(); // eslint-disable-line
DB_POSTGRES: 'DB_POSTGRES',
DB_LOCATIONS: 'DB_LOCATIONS',
}),
GCloudSecretManagerModule.withConfig(process.env.PARENT, SecretKeyList),
],
inject: [ProcessEnvProxy, GCloudSecretManagerService],
useFactory: async (
processEnvProxy: ProcessEnvProxy,
gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) => {
inject: [ProcessEnvProxy],
useFactory: async (processEnvProxy: ProcessEnvProxy) => {
return {
type: 'postgres',
host: processEnvProxy.env.HOST_POSTGRES,
port: 5432,
username: gCloudSecretManagerService
.getSecret('POSTGRES_USERNAME')
.toString(),
password: gCloudSecretManagerService
.getSecret('POSTGRES_PASSWORD')
.toString(),
username: config.POSTGRES_USERNAME.toString(),
password: config.POSTGRES_PASSWORD.toString(),
database: processEnvProxy.env.DB_POSTGRES,
entities: [LabRating, TransactionRequest],
autoLoadEntities: true,
Expand All @@ -84,23 +71,15 @@ require('dotenv').config(); // eslint-disable-line
DB_POSTGRES: 'DB_POSTGRES',
DB_LOCATIONS: 'DB_LOCATIONS',
}),
GCloudSecretManagerModule.withConfig(process.env.PARENT, SecretKeyList),
],
inject: [ProcessEnvProxy, GCloudSecretManagerService],
useFactory: async (
processEnvProxy: ProcessEnvProxy,
gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) => {
inject: [ProcessEnvProxy],
useFactory: async (processEnvProxy: ProcessEnvProxy) => {
return {
type: 'postgres',
host: processEnvProxy.env.HOST_POSTGRES,
port: 5432,
username: gCloudSecretManagerService
.getSecret('POSTGRES_USERNAME')
.toString(),
password: gCloudSecretManagerService
.getSecret('POSTGRES_PASSWORD')
.toString(),
username: config.POSTGRES_USERNAME.toString(),
password: config.POSTGRES_PASSWORD.toString(),
database: processEnvProxy.env.DB_LOCATIONS,
entities: [...LocationEntities],
autoLoadEntities: true,
Expand Down
17 changes: 6 additions & 11 deletions src/common/modules/caches/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { CacheModule, Module } from '@nestjs/common';
import { CachesService } from './caches.service';
import * as redisStore from 'cache-manager-redis-store';
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { keyList } from '../../secrets';
import { config } from '../../../config';

@Module({
imports: [
CacheModule.registerAsync({
inject: [GCloudSecretManagerService],
useFactory: async (
gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) => {
inject: [],
useFactory: async () => {
return {
store: redisStore,
host: gCloudSecretManagerService.getSecret('REDIS_HOST').toString(),
port: gCloudSecretManagerService.getSecret('REDIS_PORT').toString(),
auth_pass: gCloudSecretManagerService
.getSecret('REDIS_PASSWORD')
.toString(),
host: config.REDIS_HOST.toString(),
port: config.REDIS_PORT.toString(),
auth_pass: config.REDIS_PASSWORD.toString(),
};
},
}),
Expand Down
17 changes: 6 additions & 11 deletions src/common/modules/debio-conversion/debio-conversion.module.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { DebioConversionService } from './debio-conversion.service';
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { CacheModule, Module } from '@nestjs/common';
import * as redisStore from 'cache-manager-redis-store';
import { keyList } from '../../../common/secrets';
import { config } from '../../../config';

@Module({
imports: [
CacheModule.registerAsync({
inject: [GCloudSecretManagerService],
useFactory: async (
gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) => {
inject: [],
useFactory: async () => {
return {
store: redisStore,
host: gCloudSecretManagerService.getSecret('REDIS_HOST').toString(),
port: gCloudSecretManagerService.getSecret('REDIS_PORT').toString(),
auth_pass: gCloudSecretManagerService
.getSecret('REDIS_PASSWORD')
.toString(),
host: config.REDIS_HOST.toString(),
port: config.REDIS_PORT.toString(),
auth_pass: config.REDIS_PASSWORD.toString(),
ttl: 2 * 60 * 60,
};
},
Expand Down
28 changes: 8 additions & 20 deletions src/common/modules/debio-conversion/debio-conversion.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { keyList } from '../../secrets';
import axios from 'axios';
import { CACHE_MANAGER, Inject, Injectable } from '@nestjs/common';
import { Cache } from 'cache-manager';
Expand All @@ -10,13 +8,11 @@ import {
estimateSwap,
getExpectedOutputFromSwapTodos,
} from '@ref-finance/ref-sdk';
import { config } from '../../../config';

@Injectable()
export class DebioConversionService {
constructor(
private readonly gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
@Inject(CACHE_MANAGER) private readonly cacheManager: Cache,
) {}
constructor(@Inject(CACHE_MANAGER) private readonly cacheManager: Cache) {}

async getCacheExchange() {
return this.cacheManager.get<Exchange>('exchange');
Expand All @@ -27,10 +23,8 @@ export class DebioConversionService {
}

async setCacheExchangeFromTo(from: string, to: string) {
const listApiKey: string[] = this.gCloudSecretManagerService
.getSecret('COINMARKETCAP_API_KEY')
.toString()
.split(',');
const listApiKey: string[] =
config.COINMARKETCAP_API_KEY.toString().split(',');
const indexCurrentApiKey: number = await this.cacheManager.get<number>(
'index_api_key',
);
Expand Down Expand Up @@ -68,10 +62,8 @@ export class DebioConversionService {
async setCacheExchange() {
const sodaki = await this.getSodakiExchange();

const listApiKey: string[] = this.gCloudSecretManagerService
.getSecret('COINMARKETCAP_API_KEY')
.toString()
.split(',');
const listApiKey: string[] =
config.COINMARKETCAP_API_KEY.toString().split(',');
const indexCurrentApiKey: number = await this.cacheManager.get<number>(
'index_api_key',
);
Expand Down Expand Up @@ -149,9 +141,7 @@ export class DebioConversionService {

async convertDaiToUsd(apiKey: string, daiAmount: number): Promise<number> {
const response = await axios.get(
`${this.gCloudSecretManagerService
.getSecret('COINMARKETCAP_HOST')
.toString()}/tools/price-conversion`,
`${config.COINMARKETCAP_HOST.toString()}/tools/price-conversion`,
{
headers: {
'X-CMC_PRO_API_KEY': apiKey,
Expand All @@ -174,9 +164,7 @@ export class DebioConversionService {
to: string,
): Promise<number> {
const response = await axios.get(
`${this.gCloudSecretManagerService
.getSecret('COINMARKETCAP_HOST')
.toString()}/tools/price-conversion`,
`${config.COINMARKETCAP_HOST.toString()}/tools/price-conversion`,
{
headers: {
'X-CMC_PRO_API_KEY': apiKey,
Expand Down
12 changes: 3 additions & 9 deletions src/common/modules/escrow/escrow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { EthereumService, SubstrateService } from '../..';
import { setOrderPaid } from '@debionetwork/polkadot-provider';
import { ethers } from 'ethers';
import AsyncLock from 'async-lock';
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { keyList } from '../../secrets';
import { config } from '../../../config';

const lock = new AsyncLock();
const ESCROW_WALLET_LOCK_KEY = 'escrow-wallet-lock';
Expand All @@ -14,7 +13,6 @@ let nonce = 0;
@Injectable()
export class EscrowService {
constructor(
private readonly gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
private readonly substrateService: SubstrateService,
private readonly ethereumService: EthereumService,
) {}
Expand All @@ -24,9 +22,7 @@ export class EscrowService {
async onModuleInit(): Promise<void> {
this.provider = await this.ethereumService.getEthersProvider();
this.escrowWallet = await new ethers.Wallet(
this.gCloudSecretManagerService
.getSecret('DEBIO_ESCROW_PRIVATE_KEY')
.toString(),
config.DEBIO_ESCROW_PRIVATE_KEY.toString(),
this.provider,
);
}
Expand Down Expand Up @@ -138,9 +134,7 @@ export class EscrowService {
const tokenAmount = ethers.utils.parseUnits(String(amount), 18);
const tokenContract = this.ethereumService.getContract();
const wallet: WalletSigner = await this.ethereumService.createWallet(
this.gCloudSecretManagerService
.getSecret('DEBIO_ESCROW_PRIVATE_KEY')
.toString(),
config.DEBIO_ESCROW_PRIVATE_KEY.toString(),
);
const tokenContractWithSigner = tokenContract.connect(wallet);
const options = {
Expand Down
14 changes: 4 additions & 10 deletions src/common/modules/ethereum/ethereum.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import ABI from './utils/ABI.json';
import escrowContract from './utils/Escrow.json';
import { ethers } from 'ethers';
import { CachesService } from '../caches';
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { keyList } from '../../secrets';
import { config } from '../../../config';

@Injectable()
export class EthereumService {
constructor(
private readonly gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
private readonly ethersContract: EthersContract,
private readonly ethersSigner: EthersSigner,
private readonly cachesService: CachesService,
Expand All @@ -38,17 +36,15 @@ export class EthereumService {

getEthersProvider(): ethers.providers.JsonRpcProvider {
const provider = new ethers.providers.JsonRpcProvider(
this.gCloudSecretManagerService.getSecret('WEB3_RPC_HTTPS').toString(),
config.WEB3_RPC_HTTPS.toString(),
);
return provider;
}

getContract(): SmartContract {
try {
const contract: SmartContract = this.ethersContract.create(
this.gCloudSecretManagerService
.getSecret('ESCROW_CONTRACT_ADDRESS')
.toString(),
config.ESCROW_CONTRACT_ADDRESS.toString(),
ABI,
);

Expand All @@ -62,9 +58,7 @@ export class EthereumService {
try {
const provider = this.getEthersProvider();
const contract = new ethers.Contract(
this.gCloudSecretManagerService
.getSecret('ESCROW_CONTRACT_ADDRESS')
.toString(),
config.ESCROW_CONTRACT_ADDRESS.toString(),
escrowContract.abi,
provider,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
import { GCloudSecretManagerService } from '@debionetwork/nestjs-gcloud-secret-manager';
import { Module } from '@nestjs/common';
import { ElasticsearchModule } from '@nestjs/elasticsearch';
import { TerminusModule } from '@nestjs/terminus';
import { ElasticsearchHealthIndicator } from './elasticsearch.health.indicator';
import { keyList } from '../../../secrets';
import { config } from '../../../../config';

@Module({
imports: [
TerminusModule,
ElasticsearchModule.registerAsync({
inject: [GCloudSecretManagerService],
useFactory: async (
gCloudSecretManagerService: GCloudSecretManagerService<keyList>,
) => {
inject: [],
useFactory: async () => {
return {
node: gCloudSecretManagerService
.getSecret('ELASTICSEARCH_NODE')
.toString(),
node: config.ELASTICSEARCH_NODE.toString(),
auth: {
username: gCloudSecretManagerService
.getSecret('ELASTICSEARCH_USERNAME')
.toString(),
password: gCloudSecretManagerService
.getSecret('ELASTICSEARCH_PASSWORD')
.toString(),
username: config.ELASTICSEARCH_USERNAME.toString(),
password: config.ELASTICSEARCH_PASSWORD.toString(),
},
};
},
Expand Down
Loading