merge develop
This commit is contained in:
@@ -8,11 +8,15 @@ use url::Url;
|
||||
pub mod eth_contract;
|
||||
#[cfg(network = "milhon")]
|
||||
pub mod milhon;
|
||||
#[cfg(network = "qa")]
|
||||
pub mod qa;
|
||||
#[cfg(network = "sandbox")]
|
||||
pub mod sandbox;
|
||||
|
||||
#[cfg(network = "milhon")]
|
||||
pub use milhon::*;
|
||||
#[cfg(network = "qa")]
|
||||
pub use qa::*;
|
||||
#[cfg(network = "sandbox")]
|
||||
pub use sandbox::*;
|
||||
|
||||
@@ -58,6 +62,14 @@ pub fn default_validators() -> Vec<ValidatorDetails> {
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(network = "qa")]
|
||||
pub fn default_validators() -> Vec<ValidatorDetails> {
|
||||
vec![ValidatorDetails::new(
|
||||
"https://qa-validator.nymtech.net",
|
||||
Some("https://qa-validator.nymtech.net/api"),
|
||||
)]
|
||||
}
|
||||
|
||||
#[cfg(network = "sandbox")]
|
||||
pub fn default_validators() -> Vec<ValidatorDetails> {
|
||||
vec![ValidatorDetails::new(
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// Copyright 2021 - Nym Technologies SA <contact@nymtech.net>
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
pub const BECH32_PREFIX: &str = "nymt";
|
||||
pub const DENOM: &str = "unymt";
|
||||
|
||||
pub const DEFAULT_MIXNET_CONTRACT_ADDRESS: &str = "nymt14hj2tavq8fpesdwxxcu44rty3hh90vhuysqrsr";
|
||||
pub const DEFAULT_VESTING_CONTRACT_ADDRESS: &str = "nymt17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9f8xzkv";
|
||||
pub const BANDWIDTH_CLAIM_CONTRACT_ADDRESS: &str = "nymt17p9rzwnnfxcjp32un9ug7yhhzgtkhvl9f8xzkv";
|
||||
pub const REWARDING_VALIDATOR_ADDRESS: &str = "nymt1dn52nx8wv9wkqmrvj6tcmdzh4es6jt8tr7f6j9";
|
||||
pub const ETH_CONTRACT_ADDRESS: [u8; 20] =
|
||||
hex_literal::hex!("9fEE3e28c17dbB87310A51F13C4fbf4331A6f102");
|
||||
|
||||
// Name of the event triggered by the eth contract. If the event name is changed,
|
||||
// this would also need to be changed; It is currently tested against the json abi
|
||||
pub const ETH_EVENT_NAME: &str = "Burned";
|
||||
pub const ETH_BURN_FUNCTION_NAME: &str = "burnTokenForAccessCode";
|
||||
@@ -291,61 +291,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<QueryResponse, Cont
|
||||
Ok(query_res?)
|
||||
}
|
||||
#[entry_point]
|
||||
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone)]
|
||||
pub struct StoredMixnodeBondOld {
|
||||
pub pledge_amount: mixnet_contract_common::Coin,
|
||||
pub owner: Addr,
|
||||
pub layer: mixnet_contract_common::Layer,
|
||||
pub block_height: u64,
|
||||
pub mix_node: mixnet_contract_common::MixNode,
|
||||
pub profit_margin_percent: Option<u8>,
|
||||
pub proxy: Option<Addr>,
|
||||
}
|
||||
pub struct MixnodeBondIndexOld<'a> {
|
||||
pub owner: cw_storage_plus::UniqueIndex<'a, Addr, StoredMixnodeBondOld>,
|
||||
}
|
||||
impl<'a> cw_storage_plus::IndexList<StoredMixnodeBondOld> for MixnodeBondIndexOld<'a> {
|
||||
fn get_indexes(
|
||||
&'_ self,
|
||||
) -> Box<dyn Iterator<Item = &'_ dyn cw_storage_plus::Index<StoredMixnodeBondOld>> + '_>
|
||||
{
|
||||
let v: Vec<&dyn cw_storage_plus::Index<StoredMixnodeBondOld>> = vec![&self.owner];
|
||||
Box::new(v.into_iter())
|
||||
}
|
||||
}
|
||||
pub(crate) fn mixnodes_old<'a>() -> cw_storage_plus::IndexedMap<
|
||||
'a,
|
||||
mixnet_contract_common::IdentityKeyRef<'a>,
|
||||
StoredMixnodeBondOld,
|
||||
MixnodeBondIndexOld<'a>,
|
||||
> {
|
||||
let indexes = MixnodeBondIndexOld {
|
||||
owner: cw_storage_plus::UniqueIndex::new(|d| d.owner.clone(), "mno"),
|
||||
};
|
||||
cw_storage_plus::IndexedMap::new("mno", indexes)
|
||||
}
|
||||
|
||||
let stored_mixnode_bonds: Vec<_> = mixnodes_old()
|
||||
.range(deps.storage, None, None, cosmwasm_std::Order::Ascending)
|
||||
.flatten()
|
||||
.map(|record| crate::mixnodes::storage::StoredMixnodeBond {
|
||||
pledge_amount: record.1.pledge_amount,
|
||||
owner: record.1.owner,
|
||||
layer: record.1.layer,
|
||||
block_height: record.1.block_height,
|
||||
mix_node: record.1.mix_node,
|
||||
proxy: record.1.proxy,
|
||||
})
|
||||
.collect();
|
||||
for stored_mixnode_bond in stored_mixnode_bonds {
|
||||
crate::mixnodes::storage::mixnodes().save(
|
||||
deps.storage,
|
||||
stored_mixnode_bond.identity(),
|
||||
&stored_mixnode_bond,
|
||||
)?;
|
||||
}
|
||||
|
||||
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Response, ContractError> {
|
||||
Ok(Default::default())
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ export const Settings = () => {
|
||||
setMixnodeDetails(details)
|
||||
}
|
||||
if (showSettings) getBondDetails()
|
||||
}, [showSettings])
|
||||
}, [showSettings, selectedTab])
|
||||
|
||||
const handleTabChange = (_: React.SyntheticEvent, newTab: number) => setSelectedTab(newTab)
|
||||
|
||||
@@ -48,9 +48,7 @@ export const Settings = () => {
|
||||
</Alert>
|
||||
)}
|
||||
{selectedTab === 0 && mixnodeDetails && <Profile />}
|
||||
{selectedTab === 1 && mixnodeDetails && (
|
||||
<SystemVariables mixnodeDetails={mixnodeDetails.mix_node} pledge={mixnodeDetails.pledge_amount} />
|
||||
)}
|
||||
{selectedTab === 1 && mixnodeDetails && <SystemVariables mixnodeDetails={mixnodeDetails.mix_node} />}
|
||||
{selectedTab === 2 && mixnodeDetails && <NodeStats mixnodeId={mixnodeDetails.mix_node.identity_key} />}
|
||||
</>
|
||||
</NymCard>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useContext, useState } from 'react'
|
||||
import React, { useContext, useEffect, useState } from 'react'
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -15,24 +15,18 @@ import { AccessTimeOutlined, PercentOutlined } from '@mui/icons-material'
|
||||
import { yupResolver } from '@hookform/resolvers/yup'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { InfoTooltip } from '../../components/InfoToolTip'
|
||||
import { EnumNodeType, TMixnodeBondDetails } from '../../types'
|
||||
import { TMixnodeBondDetails } from '../../types'
|
||||
import { validationSchema } from './validationSchema'
|
||||
import { bond, unbond } from '../../requests'
|
||||
import { ClientContext } from '../../context/main'
|
||||
import { getGasFee, updateMixnode } from '../../requests'
|
||||
import { ClientContext, MAJOR_CURRENCY } from '../../context/main'
|
||||
|
||||
type TFormData = {
|
||||
profitMarginPercent: number
|
||||
signature: string
|
||||
}
|
||||
|
||||
export const SystemVariables = ({
|
||||
mixnodeDetails,
|
||||
pledge,
|
||||
}: {
|
||||
mixnodeDetails: TMixnodeBondDetails['mix_node']
|
||||
pledge: TMixnodeBondDetails['pledge_amount']
|
||||
}) => {
|
||||
export const SystemVariables = ({ mixnodeDetails }: { mixnodeDetails: TMixnodeBondDetails['mix_node'] }) => {
|
||||
const [nodeUpdateResponse, setNodeUpdateResponse] = useState<'success' | 'failed'>()
|
||||
const [configFee, setConfigFee] = useState<string>()
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -40,28 +34,28 @@ export const SystemVariables = ({
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm({
|
||||
resolver: yupResolver(validationSchema),
|
||||
defaultValues: { profitMarginPercent: mixnodeDetails.profit_margin_percent.toString(), signature: '' },
|
||||
defaultValues: { profitMarginPercent: mixnodeDetails.profit_margin_percent.toString() },
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
;(async () => {
|
||||
const fee = await getGasFee('UpdateMixnodeConfig')
|
||||
setConfigFee(fee.amount)
|
||||
})()
|
||||
}, [])
|
||||
|
||||
const { userBalance } = useContext(ClientContext)
|
||||
|
||||
const onSubmit = async (data: TFormData) => {
|
||||
await unbond(EnumNodeType.mixnode)
|
||||
await bond({
|
||||
type: EnumNodeType.mixnode,
|
||||
data: { ...mixnodeDetails, profit_margin_percent: data.profitMarginPercent },
|
||||
pledge: { denom: 'Minor', amount: pledge.amount },
|
||||
//hardcoded for the moment as required in bonding but not necessary
|
||||
ownerSignature: data.signature,
|
||||
})
|
||||
.then(() => {
|
||||
try {
|
||||
await updateMixnode({ profitMarginPercent: data.profitMarginPercent }).then(() => {
|
||||
userBalance.fetchBalance()
|
||||
setNodeUpdateResponse('success')
|
||||
})
|
||||
.catch((e) => {
|
||||
setNodeUpdateResponse('failed')
|
||||
console.log(e)
|
||||
})
|
||||
} catch (e) {
|
||||
setNodeUpdateResponse('failed')
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -81,6 +75,7 @@ export const SystemVariables = ({
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
|
||||
<Divider />
|
||||
<DataField
|
||||
title="Estimated reward"
|
||||
info="Estimated reward per epoch for this profit margin if your node is selected in the active set."
|
||||
@@ -119,7 +114,9 @@ export const SystemVariables = ({
|
||||
) : nodeUpdateResponse === 'failed' ? (
|
||||
<Typography sx={{ color: 'error.main', fontWeight: 600 }}>Node updated failed</Typography>
|
||||
) : (
|
||||
<Box />
|
||||
<Typography sx={{ color: 'nym.fee' }}>
|
||||
Fee for this transaction: {`${configFee} ${MAJOR_CURRENCY}`}{' '}
|
||||
</Typography>
|
||||
)}
|
||||
<Button
|
||||
variant="contained"
|
||||
|
||||
@@ -2,5 +2,4 @@ import * as Yup from 'yup'
|
||||
|
||||
export const validationSchema = Yup.object({
|
||||
profitMarginPercent: Yup.number().typeError('profit margin percent must be a number').min(0).max(100).required(),
|
||||
signature: Yup.string().required(),
|
||||
})
|
||||
|
||||
@@ -10,7 +10,6 @@ import {
|
||||
TauriContractStateParams,
|
||||
TauriTxResult,
|
||||
TCreateAccount,
|
||||
TDelegation,
|
||||
TMixnodeBondDetails,
|
||||
TPagedDelegations,
|
||||
TSignInWithMnemonic,
|
||||
@@ -50,6 +49,7 @@ export const undelegate = async ({
|
||||
|
||||
export const send = async (args: { amount: Coin; address: string; memo: string }): Promise<TauriTxResult> =>
|
||||
await invoke('send', args)
|
||||
|
||||
export const checkMixnodeOwnership = async (): Promise<boolean> => await invoke('owns_mixnode')
|
||||
|
||||
export const checkGatewayOwnership = async (): Promise<boolean> => await invoke('owns_gateway')
|
||||
@@ -83,3 +83,6 @@ export const getReverseGatewayDelegations = async (): Promise<TPagedDelegations>
|
||||
|
||||
export const getMixnodeBondDetails = async (): Promise<TMixnodeBondDetails | null> =>
|
||||
await invoke('mixnode_bond_details')
|
||||
|
||||
export const updateMixnode = async ({ profitMarginPercent }: { profitMarginPercent: number }) =>
|
||||
await invoke('update_mixnode', { profitMarginPercent })
|
||||
|
||||
Reference in New Issue
Block a user