Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
752affb9ef | ||
|
|
0fef13d9d2 | ||
|
|
aa600d7a9a | ||
|
|
299c8cbae0 | ||
|
|
346ad5d30b | ||
|
|
9f442698a4 |
@@ -10,6 +10,8 @@
|
||||
"governance.proposal.updateMarket.minVoterBalance",
|
||||
"governance.proposal.updateNetParam.minProposerBalance",
|
||||
"governance.proposal.updateNetParam.minVoterBalance",
|
||||
"governance.proposal.updateAsset.minProposerBalance",
|
||||
"governance.proposal.updateAsset.minVoterBalance",
|
||||
"reward.staking.delegation.maxPayoutPerEpoch",
|
||||
"reward.staking.delegation.maxPayoutPerParticipant",
|
||||
"reward.staking.delegation.minimumValidatorStake",
|
||||
@@ -19,9 +21,6 @@
|
||||
"validators.delegation.minAmount"
|
||||
],
|
||||
"fiveDecimal": [
|
||||
"governance.proposal.updateAsset.minProposerBalance",
|
||||
"governance.proposal.updateAsset.minVoterBalance",
|
||||
"governance.proposal.updateAsset.requiredParticipation",
|
||||
"market.fee.factors.infrastructureFee",
|
||||
"market.fee.factors.makerFee",
|
||||
"market.liquidity.bondPenaltyParameter",
|
||||
@@ -77,6 +76,7 @@
|
||||
"governance.proposal.updateNetParam.requiredMajority",
|
||||
"governance.proposal.updateNetParam.requiredParticipation",
|
||||
"governance.proposal.updateMarket.minProposerEquityLikeShare",
|
||||
"governance.proposal.updateAsset.requiredParticipation",
|
||||
"validators.vote.required"
|
||||
],
|
||||
"duration": [
|
||||
|
||||
@@ -21,6 +21,7 @@ import { useDocumentTitle } from '../../hooks/use-document-title';
|
||||
const PERCENTAGE_PARAMS = [
|
||||
'governance.proposal.asset.requiredMajority',
|
||||
'governance.proposal.asset.requiredParticipation',
|
||||
'governance.proposal.updateAsset.requiredParticipation',
|
||||
'governance.proposal.freeform.requiredMajority',
|
||||
'governance.proposal.freeform.requiredParticipation',
|
||||
'governance.proposal.market.requiredMajority',
|
||||
|
||||
@@ -21,10 +21,10 @@ export const useGetUserBalances = (account: string | undefined) => {
|
||||
token.allowance(account, config.staking_bridge_contract.address),
|
||||
]);
|
||||
|
||||
const balance = toBigNum(b, decimals);
|
||||
const walletBalance = toBigNum(w, decimals);
|
||||
const lien = toBigNum(stats.lien, decimals);
|
||||
const allowance = toBigNum(a, decimals);
|
||||
const balance = toBigNum(b.toString(), decimals);
|
||||
const walletBalance = toBigNum(w.toString(), decimals);
|
||||
const lien = toBigNum(stats.lien.toString(), decimals);
|
||||
const allowance = toBigNum(a.toString(), decimals);
|
||||
|
||||
return {
|
||||
balanceFormatted: balance,
|
||||
|
||||
@@ -21,8 +21,14 @@ export function useRefreshAssociatedBalances() {
|
||||
]);
|
||||
|
||||
updateBalances({
|
||||
walletAssociatedBalance: toBigNum(walletAssociatedBalance, decimals),
|
||||
vestingAssociatedBalance: toBigNum(vestingAssociatedBalance, decimals),
|
||||
walletAssociatedBalance: toBigNum(
|
||||
walletAssociatedBalance.toString(),
|
||||
decimals
|
||||
),
|
||||
vestingAssociatedBalance: toBigNum(
|
||||
vestingAssociatedBalance.toString(),
|
||||
decimals
|
||||
),
|
||||
});
|
||||
},
|
||||
[staking, vesting, updateBalances, decimals]
|
||||
|
||||
@@ -31,12 +31,18 @@ export const useRefreshBalances = (address: string) => {
|
||||
pubKey ? vesting.stake_balance(address, pubKey) : null,
|
||||
]);
|
||||
|
||||
const balance = toBigNum(b, decimals);
|
||||
const walletBalance = toBigNum(w, decimals);
|
||||
const lien = toBigNum(stats.lien, decimals);
|
||||
const allowance = toBigNum(a, decimals);
|
||||
const walletAssociatedBalance = toBigNum(walletStakeBalance, decimals);
|
||||
const vestingAssociatedBalance = toBigNum(vestingStakeBalance, decimals);
|
||||
const balance = toBigNum(b.toString(), decimals);
|
||||
const walletBalance = toBigNum(w.toString(), decimals);
|
||||
const lien = toBigNum(stats.lien.toString(), decimals);
|
||||
const allowance = toBigNum(a.toString(), decimals);
|
||||
const walletAssociatedBalance = toBigNum(
|
||||
walletStakeBalance ? walletStakeBalance.toString() : 0,
|
||||
decimals
|
||||
);
|
||||
const vestingAssociatedBalance = toBigNum(
|
||||
vestingStakeBalance ? vestingStakeBalance.toString() : 0,
|
||||
decimals
|
||||
);
|
||||
|
||||
updateBalances({
|
||||
balanceFormatted: balance,
|
||||
|
||||
@@ -34,8 +34,9 @@ export const useUserTrancheBalances = (address: string | undefined) => {
|
||||
vesting.get_vested_for_tranche(address, tId),
|
||||
]);
|
||||
|
||||
const total = toBigNum(t, decimals);
|
||||
const vested = toBigNum(v, decimals);
|
||||
// Convert t and v EthersBigNumbers to regular BigNumbers
|
||||
const total = toBigNum(t.toString(), decimals);
|
||||
const vested = toBigNum(v.toString(), decimals);
|
||||
|
||||
return {
|
||||
id: tId,
|
||||
|
||||
@@ -54,7 +54,7 @@ export const WalletAssociate = ({
|
||||
address,
|
||||
ethereumConfig.staking_bridge_contract.address
|
||||
);
|
||||
const allowance = toBigNum(a, decimals);
|
||||
const allowance = toBigNum(a.toString(), decimals);
|
||||
setAllowance(allowance);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,9 +9,8 @@ declare global {
|
||||
}
|
||||
|
||||
export function addGetNetworkParameters() {
|
||||
// @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command
|
||||
Cypress.Commands.add('get_network_parameters', () => {
|
||||
const mutation = `
|
||||
const query = `
|
||||
{
|
||||
networkParametersConnection {
|
||||
edges {
|
||||
@@ -26,17 +25,17 @@ export function addGetNetworkParameters() {
|
||||
method: 'POST',
|
||||
url: `http://localhost:3008/graphql`,
|
||||
body: {
|
||||
query: mutation,
|
||||
query,
|
||||
},
|
||||
headers: { 'content-type': 'application/json' },
|
||||
})
|
||||
.its('body.data.networkParametersConnection.edges')
|
||||
.then(function (response) {
|
||||
// @ts-ignore - ignoring Cypress type error which gets resolved when Cypress uses the command
|
||||
const object = response.reduce(function (r, e) {
|
||||
const { value, key } = e.node;
|
||||
r[key] = value;
|
||||
return r;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const object = response.reduce(function (obj: any, edge: any) {
|
||||
const { value, key } = edge.node;
|
||||
obj[key] = value;
|
||||
return obj;
|
||||
}, {});
|
||||
return cy.wrap(object);
|
||||
});
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
"@vegaprotocol/data-provider",
|
||||
"graphql",
|
||||
"graphql-tag",
|
||||
"graphql-ws"
|
||||
"graphql-ws",
|
||||
"ethers",
|
||||
"@ethersproject"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ethers } from 'ethers';
|
||||
import abi from '../abis/staking_abi.json';
|
||||
import { calcGasBuffer, prepend0x } from '../utils';
|
||||
import type { BigNumber as EthersBigNum } from 'ethers';
|
||||
|
||||
export class StakingBridge {
|
||||
public contract: ethers.Contract;
|
||||
@@ -51,7 +52,7 @@ export class StakingBridge {
|
||||
staking_token() {
|
||||
return this.contract.staking_token();
|
||||
}
|
||||
stake_balance(target: string, vegaPublicKey: string) {
|
||||
stake_balance(target: string, vegaPublicKey: string): Promise<EthersBigNum> {
|
||||
return this.contract.stake_balance(target, prepend0x(vegaPublicKey));
|
||||
}
|
||||
total_staked() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ethers } from 'ethers';
|
||||
import abi from '../abis/vesting_abi.json';
|
||||
import { calcGasBuffer, prepend0x } from '../utils';
|
||||
import type { BigNumber as EthersBigNum } from 'ethers';
|
||||
|
||||
export class TokenVesting {
|
||||
public contract: ethers.Contract;
|
||||
@@ -29,13 +30,15 @@ export class TokenVesting {
|
||||
gasLimit,
|
||||
});
|
||||
}
|
||||
stake_balance(address: string, vegaPublicKey: string) {
|
||||
stake_balance(address: string, vegaPublicKey: string): Promise<EthersBigNum> {
|
||||
return this.contract.stake_balance(address, prepend0x(vegaPublicKey));
|
||||
}
|
||||
total_staked() {
|
||||
return this.contract.total_staked();
|
||||
}
|
||||
user_stats(address: string) {
|
||||
user_stats(
|
||||
address: string
|
||||
): Promise<{ lien: EthersBigNum; total_in_all_tranches: EthersBigNum }> {
|
||||
return this.contract.user_stats(address);
|
||||
}
|
||||
get_tranche_balance(address: string, trancheId: number) {
|
||||
@@ -44,7 +47,7 @@ export class TokenVesting {
|
||||
get_vested_for_tranche(address: string, trancheId: number) {
|
||||
return this.contract.get_vested_for_tranche(address, trancheId);
|
||||
}
|
||||
user_total_all_tranches(address: string) {
|
||||
user_total_all_tranches(address: string): Promise<EthersBigNum> {
|
||||
return this.contract.user_total_all_tranches(address);
|
||||
}
|
||||
async withdraw_from_tranche(trancheId: number) {
|
||||
|
||||
@@ -11,7 +11,9 @@
|
||||
"@vegaprotocol/data-provider",
|
||||
"graphql",
|
||||
"graphql-tag",
|
||||
"graphql-ws"
|
||||
"graphql-ws",
|
||||
"ethers",
|
||||
"@ethersproject"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { BigNumber } from 'bignumber.js';
|
||||
import { BigNumber as EthersBigNumber } from 'ethers';
|
||||
import isNil from 'lodash/isNil';
|
||||
import memoize from 'lodash/memoize';
|
||||
|
||||
@@ -15,16 +14,14 @@ export function toDecimal(numberOfDecimals: number) {
|
||||
}
|
||||
|
||||
export function toBigNum(
|
||||
rawValue: string | number | EthersBigNumber,
|
||||
rawValue: string | number,
|
||||
decimals: number
|
||||
): BigNumber {
|
||||
return new BigNumber(
|
||||
rawValue instanceof EthersBigNumber ? rawValue.toString() : rawValue || 0
|
||||
).dividedBy(Math.pow(10, decimals));
|
||||
return new BigNumber(rawValue || 0).dividedBy(Math.pow(10, decimals));
|
||||
}
|
||||
|
||||
export function addDecimal(
|
||||
value: string | number | EthersBigNumber,
|
||||
value: string | number,
|
||||
decimals: number,
|
||||
decimalPrecision = decimals
|
||||
): string {
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { ethereumAddress, vegaPublicKey } from './common';
|
||||
|
||||
it('ethereumAddress', () => {
|
||||
const errorMessage = 'Invalid Ethereum address';
|
||||
|
||||
const validAddress = '0x72c22822A19D20DE7e426fB84aa047399Ddd8853';
|
||||
expect(ethereumAddress(validAddress)).toEqual(true);
|
||||
|
||||
const invalidChars = '0xzzc22822A19D20DE7e426fB84aa047399Ddd8853';
|
||||
expect(ethereumAddress(invalidChars)).toEqual(errorMessage);
|
||||
|
||||
const tooManyChars = '0x72c22822A19D20DE7e426fB84aa047399Ddd88531111111';
|
||||
expect(ethereumAddress(tooManyChars)).toEqual(errorMessage);
|
||||
|
||||
const no0x = '1x72c22822A19D20DE7e426fB84aa047399Ddd8853';
|
||||
expect(ethereumAddress(no0x)).toEqual(errorMessage);
|
||||
});
|
||||
|
||||
it('vegaPublicKey', () => {
|
||||
const errorMessage = 'Invalid Vega key';
|
||||
|
||||
const validKey =
|
||||
'70d14a321e02e71992fd115563df765000ccc4775cbe71a0e2f9ff5a3b9dc680';
|
||||
expect(vegaPublicKey(validKey)).toEqual(true);
|
||||
|
||||
const invalidChars =
|
||||
'zzz14a321e02e71992fd115563df765000ccc4775cbe71a0e2f9ff5a3b9dc680';
|
||||
expect(vegaPublicKey(invalidChars)).toEqual(errorMessage);
|
||||
|
||||
const tooManyChars =
|
||||
'70d14a321e02e71992fd115563df765000ccc4775cbe71a0e2f9ff5a3b9dc680111111';
|
||||
expect(vegaPublicKey(tooManyChars)).toEqual(errorMessage);
|
||||
});
|
||||
@@ -1,5 +1,4 @@
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { ethers } from 'ethers';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
|
||||
export const required = (value: string) => {
|
||||
@@ -10,14 +9,14 @@ export const required = (value: string) => {
|
||||
};
|
||||
|
||||
export const ethereumAddress = (value: string) => {
|
||||
if (!ethers.utils.isAddress(value)) {
|
||||
if (!/^0x[0-9a-fA-F]{40}$/i.test(value)) {
|
||||
return t('Invalid Ethereum address');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
export const vegaPublicKey = (value: string) => {
|
||||
if (value.length !== 64 || !/^[A-Fa-f0-9]*$/i.test(value)) {
|
||||
if (!/^[A-Fa-f0-9]{64}$/i.test(value)) {
|
||||
return t('Invalid Vega key');
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user