Comparing version 0.2.91 to 0.2.92
@@ -95,4 +95,2 @@ import { Converter, nRelay, ChoppedRelay } from "./interfaces"; | ||
export declare function fund(smartTokens: Asset, reserveBalance: Asset, smartSupply: Asset): Asset; | ||
export declare function calculateFundReturnSmall(reserveTokens: Asset, reserveBalance: Asset, smartSupply: Asset): Asset; | ||
export declare function calculateFundReturnBig(reserveTokens: Asset, reserveBalance: Asset, smartSupply: Asset): Asset; | ||
export declare function calculateFundReturn(reserveTokens: Asset, reserveBalance: Asset, smartSupply: Asset): Asset; |
@@ -13,2 +13,3 @@ "use strict"; | ||
const underscore_1 = __importDefault(require("underscore")); | ||
decimal_js_1.default.set({ precision: 15, rounding: decimal_js_1.default.ROUND_DOWN }); | ||
/** | ||
@@ -287,9 +288,12 @@ * Bancor Formula | ||
exports.calculateLiquidateCost = calculateLiquidateCost; | ||
const bigNumber = decimal_js_1.default.pow(10, 10); | ||
// Returns what user can expect to be charged in order to buy X amount of smart tokens | ||
function fund(smartTokens, reserveBalance, smartSupply) { | ||
const reserveTokensN = smartTokens.toDecimal(); | ||
const reserveBalanceN = reserveBalance.toDecimal(); | ||
const smartSupplyN = smartSupply.toDecimal(); | ||
decimal_js_1.default.set({ precision: 15, rounding: decimal_js_1.default.ROUND_DOWN }); | ||
const smartTokensN = smartTokens.toDecimal().times(bigNumber); | ||
const reserveBalanceN = reserveBalance.toDecimal().times(bigNumber); | ||
const smartSupplyN = smartSupply.toDecimal().times(bigNumber); | ||
const one = new decimal_js_1.default(1); | ||
// (smart_amount * balance - 1) / current_smart_supply + 1; | ||
const reward = reserveTokensN | ||
const cost = smartTokensN | ||
.times(reserveBalanceN) | ||
@@ -299,4 +303,5 @@ .minus(one) | ||
.plus(one); | ||
return new eos_common_1.Asset(reward | ||
return new eos_common_1.Asset(cost | ||
.times(Math.pow(10, reserveBalance.symbol.precision)) | ||
.div(bigNumber) | ||
.toDecimalPlaces(0, decimal_js_1.default.ROUND_DOWN) | ||
@@ -306,30 +311,11 @@ .toNumber(), reserveBalance.symbol); | ||
exports.fund = fund; | ||
function calculateFundReturnSmall(reserveTokens, reserveBalance, smartSupply) { | ||
const wholeGuarantee = new decimal_js_1.default(Math.pow(10, 10)); | ||
const reserveTokensN = reserveTokens.toDecimal().times(wholeGuarantee); | ||
const reserveBalanceN = reserveBalance.toDecimal().times(wholeGuarantee); | ||
const smartSupplyN = smartSupply.toDecimal().times(wholeGuarantee); | ||
const one = new decimal_js_1.default(1); | ||
function calculateFundReturn(reserveTokens, reserveBalance, smartSupply) { | ||
decimal_js_1.default.set({ precision: 15, rounding: decimal_js_1.default.ROUND_DOWN }); | ||
const reward = reserveTokensN | ||
.times(smartSupplyN) | ||
.minus(smartSupplyN) | ||
.plus(one) | ||
.div(reserveBalanceN); | ||
return new eos_common_1.Asset(reward | ||
.div(wholeGuarantee) | ||
.times(Math.pow(10, smartSupply.symbol.precision)) | ||
.toDecimalPlaces(0, decimal_js_1.default.ROUND_DOWN) | ||
.toNumber(), smartSupply.symbol); | ||
} | ||
exports.calculateFundReturnSmall = calculateFundReturnSmall; | ||
function calculateFundReturnBig(reserveTokens, reserveBalance, smartSupply) { | ||
const reserveTokensN = reserveTokens.toDecimal(); | ||
const reserveBalanceN = reserveBalance.toDecimal(); | ||
const smartSupplyN = smartSupply.toDecimal(); | ||
const reserveTokensN = reserveTokens.toDecimal().times(bigNumber); | ||
const reserveBalanceN = reserveBalance.toDecimal().times(bigNumber); | ||
const smartSupplyN = smartSupply.toDecimal().times(bigNumber); | ||
const one = new decimal_js_1.default(1); | ||
decimal_js_1.default.set({ precision: 15, rounding: decimal_js_1.default.ROUND_DOWN }); | ||
// y(s+1) + 1 / r | ||
const reward = reserveTokensN | ||
.times(smartSupplyN) | ||
.minus(smartSupplyN) | ||
.times(smartSupplyN.plus(one)) | ||
.plus(one) | ||
@@ -339,12 +325,7 @@ .div(reserveBalanceN); | ||
.times(Math.pow(10, smartSupply.symbol.precision)) | ||
.div(bigNumber) | ||
.toDecimalPlaces(0, decimal_js_1.default.ROUND_DOWN) | ||
.toNumber(), smartSupply.symbol); | ||
} | ||
exports.calculateFundReturnBig = calculateFundReturnBig; | ||
function calculateFundReturn(reserveTokens, reserveBalance, smartSupply) { | ||
return reserveTokens.toDecimal().greaterThanOrEqualTo(1) | ||
? calculateFundReturnBig(reserveTokens, reserveBalance, smartSupply) | ||
: calculateFundReturnSmall(reserveTokens, reserveBalance, smartSupply); | ||
} | ||
exports.calculateFundReturn = calculateFundReturn; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "bancorx", | ||
"version": "0.2.91", | ||
"version": "0.2.92", | ||
"description": "BancorX Utility", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55674
788