Giter Club home page Giter Club logo

Comments (1)

tomkha avatar tomkha commented on August 27, 2024

Here is a simplified demo:

const Nimiq = require('@nimiq/core');

const balance = Nimiq.Policy.coinsToLunas(1500);
const start = 1000;
const stepBlocks = 100;
const stepAmount = Nimiq.Policy.coinsToLunas(100);
const totalAmount = Nimiq.Policy.coinsToLunas(1000);

const contract = new Nimiq.VestingContract(balance, Nimiq.Address.NULL, start, stepBlocks, stepAmount, totalAmount);


for (let block = 0; block <= 2000; block += 100) {
    const minCap = contract.getMinCap(block);
    const available = Math.max(0, balance - minCap);
    console.log(`#${block}: min cap: ${Nimiq.Policy.lunasToCoins(minCap)}, available: ${Nimiq.Policy.lunasToCoins(available)}`);
}

and the result:

#0: min cap: 2000, available: 0
#100: min cap: 1900, available: 0
#200: min cap: 1800, available: 0
#300: min cap: 1700, available: 0
#400: min cap: 1600, available: 0
#500: min cap: 1500, available: 0
#600: min cap: 1400, available: 100
#700: min cap: 1300, available: 200
#800: min cap: 1200, available: 300
#900: min cap: 1100, available: 400
#1000: min cap: 1000, available: 500
#1100: min cap: 900, available: 600
#1200: min cap: 800, available: 700
#1300: min cap: 700, available: 800
#1400: min cap: 600, available: 900
#1500: min cap: 500, available: 1000
#1600: min cap: 400, available: 1100
#1700: min cap: 300, available: 1200
#1800: min cap: 200, available: 1300
#1900: min cap: 100, available: 1400
#2000: min cap: 0, available: 1500

in other words, getMinCap counts negative steps too.

Here is the contract from the testnet:
https://test.nimiq.watch/#NQ50+NE4C+8X7C+HFA5+7F58+DVPC+VC6C+UVEH+GE47

nimiq-watch

from core-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.