-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
190 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,17 +12,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) { | |
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getNonCirculatingSupplyAddressConfigurations = exports.getNetworkConfigurations = exports.nonCirculatingSupplyAddressesConfigInput = void 0; | ||
exports.getNonCirculatingSupplyAddressConfigurations = exports.getNetworkConfigurations = exports.getNonCirculatingSupplyAddressesConfigInput = void 0; | ||
// src/config.ts | ||
const node_fetch_1 = __importDefault(require("node-fetch")); | ||
const fs_1 = __importDefault(require("fs")); | ||
const path_1 = __importDefault(require("path")); | ||
const mongodb_1 = require("mongodb"); | ||
const dotenv_1 = require("dotenv"); | ||
(0, dotenv_1.config)(); | ||
const API_URL = process.env.API_URL; | ||
// const MONGODB_URI = "mongodb+srv://tokenSupply_app_dev_qa_uat:[email protected]/?retryWrites=true&w=majority"; | ||
const DATABASE_NAME = "ferrum-network-dev"; | ||
const DATABASE_NAME = process.env.DATABASE_NAME; | ||
const DB_COLLECTION_NAME_NON_CIRCULATING_SUPPLY_ADDRESS = process.env.DB_COLLECTION_NAME_NON_CIRCULATING_SUPPLY_ADDRESS; | ||
const DB_COLLECTION_NAME_CHAIN_NETWORK_MAP = process.env.DB_COLLECTION_NAME_CHAIN_NETWORK_MAP; | ||
function getChainIdToNetworkMap() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const MONGODB_URI = process.env.MONGODB_URI; | ||
|
@@ -32,11 +31,11 @@ function getChainIdToNetworkMap() { | |
const client = new mongodb_1.MongoClient(MONGODB_URI); | ||
yield client.connect(); | ||
const database = client.db(DATABASE_NAME); | ||
const chainIdToNetworkMapCollection = database.collection("chainIdToNetworkMap"); | ||
const chainIdToNetworkMapCollection = database.collection(DB_COLLECTION_NAME_CHAIN_NETWORK_MAP); | ||
const result = yield chainIdToNetworkMapCollection.findOne({ appName: "tokenSupply" }); | ||
yield client.close(); | ||
if (!result) { | ||
throw new Error("chainIdToNetworkMap not found in the database."); | ||
throw new Error(`${DB_COLLECTION_NAME_CHAIN_NETWORK_MAP} not found in the database.`); | ||
} | ||
const chainIdToNetworkMap = {}; | ||
for (const item of result.chainIdToNetworkMap) { | ||
|
@@ -65,19 +64,40 @@ function getNetworkConfigurations(tokenContractAddress, chainId) { | |
}; | ||
} | ||
} | ||
return networks; | ||
// Get the currencyId from the response data | ||
const currencyId = data.body.currencyAddressesByNetworks[0].currency._id; | ||
return { networks, currencyId }; | ||
}); | ||
} | ||
exports.getNetworkConfigurations = getNetworkConfigurations; | ||
exports.nonCirculatingSupplyAddressesConfigInput = JSON.parse(fs_1.default.readFileSync(path_1.default.join(__dirname, "../config/", "nonCirculatingSupplyAddressesConfig.json"), "utf-8")); | ||
function getNonCirculatingSupplyAddressConfigurations(tokenContractAddress, chainId) { | ||
function getNonCirculatingSupplyAddressesConfigInput(currencyId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const MONGODB_URI = process.env.MONGODB_URI; | ||
if (!MONGODB_URI) { | ||
throw new Error('MONGODB_URI is not defined in the environment variables'); | ||
} | ||
const client = new mongodb_1.MongoClient(MONGODB_URI); | ||
yield client.connect(); | ||
const database = client.db(DATABASE_NAME); | ||
const collection = database.collection(DB_COLLECTION_NAME_NON_CIRCULATING_SUPPLY_ADDRESS); | ||
const result = yield collection.findOne({ currency: new mongodb_1.ObjectId(currencyId) }); | ||
yield client.close(); | ||
if (!result) { | ||
throw new Error(`No non-circulating supply addresses configuration found for currency with ID: ${currencyId}`); | ||
} | ||
return result.nonCirculatingSupplyAddresses; | ||
}); | ||
} | ||
exports.getNonCirculatingSupplyAddressesConfigInput = getNonCirculatingSupplyAddressesConfigInput; | ||
function getNonCirculatingSupplyAddressConfigurations(tokenContractAddress, chainId, currencyId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const url = `${API_URL}?tokenContractAddress=${tokenContractAddress}&chainId=${chainId}&offset=0`; | ||
const response = yield (0, node_fetch_1.default)(url); | ||
const data = yield response.json(); | ||
const nonCirculatingSupplyAddresses = []; | ||
const chainIdToNetworkMap = yield getChainIdToNetworkMap(); | ||
for (const item of exports.nonCirculatingSupplyAddressesConfigInput) { | ||
const nonCirculatingSupplyAddressesConfigInput = yield getNonCirculatingSupplyAddressesConfigInput(currencyId); | ||
for (const item of nonCirculatingSupplyAddressesConfigInput) { | ||
const network = chainIdToNetworkMap[item.chainId]; | ||
let networkItemFromGatewayConfig = data.body.currencyAddressesByNetworks.find(i => i.network.chainId === item.chainId); | ||
nonCirculatingSupplyAddresses.push({ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.