Skip to content

Commit

Permalink
Validator assign operator in QP miner dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Naiem Yeganeh committed Sep 6, 2024
1 parent fb4f4b4 commit e437cf0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import { QuantumPortalGateway } from '../../../typechain-types/QuantumPortalGate
import { QuantumPortalGateway__factory } from '../../../typechain-types/factories/QuantumPortalGateway__factory';
import { QuantumPortalLedgerMgrImpl } from '../../../typechain-types/QuantumPortalLedgerMgrImpl';
import { QuantumPortalLedgerMgrImpl__factory } from '../../../typechain-types/factories/QuantumPortalLedgerMgrImpl__factory';
import { QuantumPortalStake } from '../../../typechain-types/QuantumPortalStake';
import { QuantumPortalStake__factory } from '../../../typechain-types/factories/QuantumPortalStake__factory';
import { Utils } from 'types';
import { QpContractConfig } from '../../../common/Consts';
import { QuantumPortalMinerMgr } from '../../../typechain-types/QuantumPortalMinerMgr';
import { QuantumPortalMinerMgr__factory } from '../../../typechain-types/factories/QuantumPortalMinerMgr__factory';
import { OperatorRelation } from '../../../typechain-types/OperatorRelation';
import { QuantumPortalStakeWithDelegate } from '../../../typechain-types/QuantumPortalStakeWithDelegate';
import { QuantumPortalStakeWithDelegate__factory } from '../../../typechain-types/factories/QuantumPortalStakeWithDelegate__factory';
import { QuantumPortalLedgerMgr } from '../../../typechain-types';
import { QuantumPortalAuthorityMgr } from '../../../typechain-types/QuantumPortalAuthorityMgr';
import { QuantumPortalAuthorityMgr__factory } from '../../../typechain-types/factories/QuantumPortalAuthorityMgr__factory';
import { ethers } from 'ethers';

export interface QpMinerStakeInfo {
qpGatewayContract: string;
Expand Down Expand Up @@ -142,6 +142,28 @@ export class QpMinerClient implements Injectable {
return await this.api.runPopulatedTransaction(tx);
}

async assignValidatorOperator(operator: string): Promise<string> {
const val = await this.validatorContract()
const con = ethers.ContractFactory.getContract(val.address, [
{
"inputs": [
{
"internalType": "address",
"name": "toOp",
"type": "address"
}
],
"name": "assignOperator",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
]);
const tx = await con.populateTransaction.assignOperator(operator, { from: this.address() });
// const tx = await val.populateTransaction. assignOperator(operator, { from: this.address() });
return await this.api.runPopulatedTransaction(tx);
}

async registerMiner(): Promise<string> {
const gw = this.qpGateway();
const mgrAddr = await gw.quantumPortalLedgerMgr();
Expand Down Expand Up @@ -202,6 +224,22 @@ export class QpMinerClient implements Injectable {
});
}

async validatorContract(): Promise<QuantumPortalAuthorityMgr> {
return this.qpStakeCache.getAsync(this.network() + '_AuthMgr', async () => {
try {
const gw = this.qpGateway();
console.log('Gateway is', gw.address);
const amAddr = await gw.quantumPortalAuthorityMgr();
const mm = QuantumPortalAuthorityMgr__factory.connect(amAddr, this.api.ethersProvider(this.network()));
ValidationUtils.isTrue(!!mm, 'Could not connect to authMgr contract');
return mm;
} catch(e) {
console.error('Error initialinzg the authMgr contract', e as Error);
throw e;
}
});
}

async minerMgrContract(): Promise<QuantumPortalMinerMgr> {
return this.qpStakeCache.getAsync(this.network() + '_MinerMgr', async () => {
try {
Expand All @@ -212,7 +250,7 @@ export class QpMinerClient implements Injectable {
ValidationUtils.isTrue(!!mm, 'Could not connect to minerMgr contract');
return mm;
} catch(e) {
console.error('Error initialinzg the stake contract', e as Error);
console.error('Error initialinzg the minerMgr contract', e as Error);
throw e;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface QpMinerStakeState {
withdrawAmount: string;
delegateAddress: string;
operatorAddress: string;
validatorOperatorAddress: string;

error?: string;
}
Expand Down Expand Up @@ -61,6 +62,11 @@ const reducer = (state: QpMinerStakeState, action: AnyAction) => {
...state,
operatorAddress: action.payload.value,
}
case 'UPDATE_VALIDATOR_OPERATOR':
return {
...state,
validatorOperatorAddress: action.payload.value,
}
case 'UPDATE_WITHDRAW':
return {
...state,
Expand Down Expand Up @@ -126,6 +132,12 @@ async function assignOperator(state: QpMinerStakeState, dispatch: Dispatch<AnyAc
// TODO: Handle tx ID
}

async function assignValidatorOperator(state: QpMinerStakeState, dispatch: Dispatch<AnyAction>) {
const client = inject<QpMinerClient>(QpMinerClient);
const txId = await client.assignValidatorOperator(state.validatorOperatorAddress);
// TODO: Handle tx ID
}

async function registerMiner(state: QpMinerStakeState, dispatch: Dispatch<AnyAction>) {
const client = inject<QpMinerClient>(QpMinerClient);
const txId = await client.registerMiner();
Expand Down Expand Up @@ -237,6 +249,13 @@ export function QpMinerStake(props: {}) {
disabled={Number(state.miner?.totalStakedHuman || '0') === 0}
/>}
/>
<FInputText label={'Validator Operator'}
value={state.validatorOperatorAddress}
onChange={(e: any) => dispatch({type: 'UPDATE_VALIDATOR_OPERATOR', payload: { value: e.target.value }})}
postfix={<FButton
title={'ASSIGN - ONLY VALIDATOR'} onClick={() => assignValidatorOperator(state, dispatch)}
/>}
/>
<FInputText label={'Delegate'}
value={state.delegateAddress}
onChange={(e: any) => dispatch({type: 'UPDATE_DELEGATE', payload: { value: e.target.value }})}
Expand Down

0 comments on commit e437cf0

Please sign in to comment.