Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RunOnFluxBot committed Nov 26, 2024
1 parent 961fcd0 commit 705d60f
Showing 1 changed file with 34 additions and 18 deletions.
52 changes: 34 additions & 18 deletions services/appsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4207,7 +4207,7 @@ async function softRegisterAppLocally(appSpecs, componentSpecs, res) {
* @param {number} height Block height.
* @returns {number} App price.
*/
async function appPricePerMonth(dataForAppRegistration, height, suppliedPrices) {
async function appPricePerMonth(dataForAppRegistration, height, suppliedPrices, callByFiatAndFluxPriceFunction) {
if (!dataForAppRegistration) {
return new Error('Application specification not provided');
}
Expand Down Expand Up @@ -4253,6 +4253,12 @@ async function appPricePerMonth(dataForAppRegistration, height, suppliedPrices)
const additionalPrice = (appPrice * instancesAdditional) / 3;
appPrice = (Math.ceil(additionalPrice * 100) + Math.ceil(appPrice * 100)) / 100;
}
if (callByFiatAndFluxPriceFunction) {
const gSyncthingApp = dataForAppRegistration.containerData.includes('g:');
if (gSyncthingApp) {
appPrice *= 0.8;
}
}
if (appPrice < priceSpecifications.minPrice) {
appPrice = priceSpecifications.minPrice;
}
Expand Down Expand Up @@ -4280,6 +4286,17 @@ async function appPricePerMonth(dataForAppRegistration, height, suppliedPrices)
const additionalPrice = (appPrice * instancesAdditional) / 3;
appPrice = (Math.ceil(additionalPrice * 100) + Math.ceil(appPrice * 100)) / 100;
}
if (callByFiatAndFluxPriceFunction) {
if (cpuTotal <= 3 && ramTotal <= 6000 && hddTotal <= 150) {
appPrice *= 0.8;
} else if (cpuTotal <= 7 && ramTotal <= 29000 && hddTotal <= 370) {
appPrice *= 0.9;
}
const gSyncthingApp = dataForAppRegistration.containerData.includes('g:');
if (gSyncthingApp) {
appPrice *= 0.8;
}
}
if (appPrice < priceSpecifications.minPrice) {
appPrice = priceSpecifications.minPrice;
}
Expand Down Expand Up @@ -4325,20 +4342,19 @@ async function appPricePerMonth(dataForAppRegistration, height, suppliedPrices)
const additionalPrice = (appPrice * instancesAdditional) / 3;
appPrice = (Math.ceil(additionalPrice * 100) + Math.ceil(appPrice * 100)) / 100;
}
if (cpuTotalCount <= 3 && ramTotalCount <= 6000 && hddTotalCount <= 150) {
appPrice *= 0.8;
} else if (cpuTotalCount <= 7 && ramTotalCount <= 29000 && hddTotalCount <= 370) {
appPrice *= 0.9;
}
let gSyncthingApp = false;
if (dataForAppRegistration.version <= 3) {
gSyncthingApp = dataForAppRegistration.containerData.includes('g:');
} else {
gSyncthingApp = dataForAppRegistration.compose.find((comp) => comp.containerData.includes('g:'));
}
if (gSyncthingApp) {
appPrice *= 0.8;

if (callByFiatAndFluxPriceFunction) {
if (cpuTotalCount <= 3 && ramTotalCount <= 6000 && hddTotalCount <= 150) {
appPrice *= 0.8;
} else if (cpuTotalCount <= 7 && ramTotalCount <= 29000 && hddTotalCount <= 370) {
appPrice *= 0.9;
}
const gSyncthingApp = dataForAppRegistration.compose.find((comp) => comp.containerData.includes('g:'));
if (gSyncthingApp) {
appPrice *= 0.8;
}
}

if (appPrice < priceSpecifications.minPrice) {
appPrice = priceSpecifications.minPrice;
}
Expand Down Expand Up @@ -10230,14 +10246,14 @@ async function getAppFluxOnChainPrice(appSpecification) {
const priceSpecifications = intervals[intervals.length - 1]; // filter does not change order
const appInfo = await dbHelper.findOneInDatabase(database, globalAppsInformation, query, projection);
const defaultExpire = config.fluxapps.blocksLasting; // if expire is not set in specs, use this default value
let actualPriceToPay = await appPricePerMonth(appSpecFormatted, daemonHeight, appPrices);
let actualPriceToPay = await appPricePerMonth(appSpecFormatted, daemonHeight, appPrices, true);
const expireIn = appSpecFormatted.expire || defaultExpire;
// app prices are ceiled to highest 0.01
const multiplier = expireIn / defaultExpire;
actualPriceToPay *= multiplier;
actualPriceToPay = Math.ceil(actualPriceToPay * 100) / 100;
if (appInfo) {
let previousSpecsPrice = await appPricePerMonth(appInfo, daemonHeight, appPrices); // calculate previous based on CURRENT height, with current interval of prices!
let previousSpecsPrice = await appPricePerMonth(appInfo, daemonHeight, appPrices, true); // calculate previous based on CURRENT height, with current interval of prices!
let previousExpireIn = previousSpecsPrice.expire || defaultExpire; // bad typo bug line. Leave it like it is, this bug is a feature now.
if (daemonHeight > 1315000) {
previousExpireIn = appInfo.expire || defaultExpire;
Expand Down Expand Up @@ -10389,15 +10405,15 @@ async function getAppFiatAndFluxPrice(req, res) {
}
let actualPriceToPay = 0;
const defaultExpire = config.fluxapps.blocksLasting; // if expire is not set in specs, use this default value
actualPriceToPay = await appPricePerMonth(appSpecFormatted, daemonHeight, appPrices);
actualPriceToPay = await appPricePerMonth(appSpecFormatted, daemonHeight, appPrices, true);
const expireIn = appSpecFormatted.expire || defaultExpire;
// app prices are ceiled to highest 0.01
const multiplier = expireIn / defaultExpire;
actualPriceToPay *= multiplier;
actualPriceToPay = Number(actualPriceToPay).toFixed(2);
const appInfo = await dbHelper.findOneInDatabase(database, globalAppsInformation, query, projection);
if (appInfo) {
let previousSpecsPrice = await appPricePerMonth(appInfo, daemonHeight, appPrices); // calculate previous based on CURRENT height, with current interval of prices!
let previousSpecsPrice = await appPricePerMonth(appInfo, daemonHeight, appPrices, true); // calculate previous based on CURRENT height, with current interval of prices!
let previousExpireIn = previousSpecsPrice.expire || defaultExpire; // bad typo bug line. Leave it like it is, this bug is a feature now.
if (daemonHeight > 1315000) {
previousExpireIn = appInfo.expire || defaultExpire;
Expand Down

0 comments on commit 705d60f

Please sign in to comment.