This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 400,000 packages pre-installed, including checks-utils
with all npm
packages installed. Try it out:
require()
any package directly from npmawait
any promise instead of using callbacks (example)This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
Simple Tools to work with checks, discount rate, expiration term, commissions.
$ npm i checks-utils
const check-util = require("checks-utils")
{*float} nominalValue: Nominal value of the check.
{*float} commision: Comissions percibed, value between 0 and 1.
{*uint} expiration: Expiration term in days.
{*float} discountTax: Discount tax, value between 0 and 1.
const newCheck = new check-util.check(1000, 0.05, 90, 0.3)
Calculate net value after discount commision.
const newCheck = new check-util.check(100000, 0.05, 90, 0.3)
const netValue = newCheck.netValue() // => 97000
Calculate the minimal value accepted after aply commission and discount tax.
const newCheck = new check-util.check(100000, 0.05, 90, 0.3)
const netValue = newCheck.minValue() // => 89725
const netValue = newCheck.minValue() // => 89725
Assuming decimals are 18, we name a new unit called minToken, which is:
1 token = 10^18 minToken
then we have the rate and cap defined as (included in ERC20 standard):
rate = 1 / minTokenPrice[WEI], or: rate = 10^18 / tokenPrice[ETH]
and:
minValueOfCheck[WEI] = convert(newCheck.minValue(), exchangeRateTo[WEI])
cap = minValueOfCheck[WEI]
The formula to calculate the amount of token created is:
tokenAmount = cap / tokenPrice[WEI]
then:
tokenPrice[WEI] = cap / tokenAmount
If we define:
cap = minValueOfCheck[WEI]
then:
tokenPrice = 10^18 WEI = 1 ETH
and:
minTokenPrice = 1 WEI
rate = 1 / minTokenPrice[WEI] = 1
Simple solution to tokenization problem.