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

Allow changing restake when below threshold #357

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.7.2

### Fixed

- Allow validators to change restaking preference while below minimum threshold

## 1.7.1

### Changed
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "concordium-desktop-wallet",
"productName": "concordium-desktop-wallet",
"description": "concordium-desktop-wallet",
"version": "1.7.1",
"version": "1.7.2",
"main": "./main.prod.js",
"author": {
"name": "Concordium Software",
Expand Down
12 changes: 11 additions & 1 deletion app/utils/transactionHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ReleaseSchedule,
TransactionSummaryType,
TransactionKindString,
isBakerAccount,
} from '@concordium/web-sdk';
import { Validate } from 'react-hook-form';
import {
Expand Down Expand Up @@ -682,7 +683,16 @@ export function validateBakerStake(
return 'Value is not a valid CCD amount';
}
const amount = ccdToMicroCcd(amountToValidate);
if (bakerStakeThreshold && bakerStakeThreshold > amount) {
const currentStake: bigint | undefined =
accountInfo && isBakerAccount(accountInfo)
? accountInfo.accountBaker.stakedAmount
: undefined;

if (
bakerStakeThreshold &&
bakerStakeThreshold > amount &&
(!currentStake || amount !== currentStake)
) {
return `Stake is below the threshold (${displayAsCcd(
bakerStakeThreshold
)}) for validation`;
Expand Down
48 changes: 47 additions & 1 deletion test/utils/transactionHelpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import '../mockWindow';
import { createRegularIntervalSchedule } from '../../app/utils/transactionHelpers';
import { AccountInfo } from '@concordium/web-sdk';
import {
createRegularIntervalSchedule,
validateBakerStake,
} from '../../app/utils/transactionHelpers';

test('createRegularIntervalSchedule release amounts should sum to input amount', () => {
const totalAmount = 100n;
Expand Down Expand Up @@ -44,3 +48,45 @@ test('createRegularIntervalSchedule should increase timestamps by interval', ()
)
).toEqual(true);
});

test('validateBakerStake allows amount below threshold (if equal to currentStake)', () => {
const stakedAmount = 1000000n; // microCCD (1 CCD)
const accountAmount = 1000000000n; // microCCD (1000 CCD)
const accountInfo = {
accountAmount,
accountBaker: { stakedAmount },
} as AccountInfo;
const threshold = 100000000n; // microCCD (100 CCD)
const amount = '1'; // CCD
expect(
validateBakerStake(threshold, amount, accountInfo, 1n)
).toBeUndefined();
});

test('validateBakerStake does not allow amount below threshold (if not equal to currentStake)', () => {
const stakedAmount = 1000000n; // microCCD (1 CCD)
const accountAmount = 1000000000n; // microCCD (1000 CCD)
const accountInfo = {
accountAmount,
accountBaker: { stakedAmount },
} as AccountInfo;
const threshold = 100000000n; // microCCD (100 CCD)
const amount = '5'; // CCD
expect(validateBakerStake(threshold, amount, accountInfo, 1n)).toContain(
'below the threshold'
);
});

test('validateBakerStake allows amount equal threshold', () => {
const stakedAmount = 1000000n; // microCCD (1 CCD)
const accountAmount = 1000000000n; // microCCD (1000 CCD)
const accountInfo = {
accountAmount,
accountBaker: { stakedAmount },
} as AccountInfo;
const threshold = 100000000n; // microCCD (100 CCD)
const amount = '100'; // CCD
expect(
validateBakerStake(threshold, amount, accountInfo, 1n)
).toBeUndefined();
});
Loading