Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VestingContract doesn't make funds above vestingTotalAmount immediately available. #539

Open
2 tasks
tomkha opened this issue Feb 2, 2020 · 1 comment
Open
2 tasks

Comments

@tomkha
Copy link
Contributor

tomkha commented Feb 2, 2020

New issue checklist

General information

  • Library version(s): 1.5.4
  • Browser version(s):
  • Devices/Simulators/Machine affected:
  • Reproducible in the testnet? (Yes/No): Yes
  • Related issues:

Bug report

VestingContract.getMinCap must not return a value greater than vestingTotalAmount

Expected behavior

Funds above vestingTotalAmount must be immediately available after creation.

Actual behavior

Extra funds are unlocked in steps preceding vestingStart block.

Steps to reproduce

Create a vesting contract with the vesting start block somewhere in the future, define vesting step block, vesting step amount, total vesting amount. The transaction must have a value greater than total vesting amount. If you try to withdraw those extra funds before the vesting start block you'll get "balance error".

@tomkha
Copy link
Contributor Author

tomkha commented Feb 2, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant