Skip to content

Commit

Permalink
Merge pull request #84 from martillansky/testnets
Browse files Browse the repository at this point in the history
Testnets
  • Loading branch information
martillansky authored Sep 28, 2024
2 parents 4ca6bc7 + 8f0af6c commit 18752f6
Show file tree
Hide file tree
Showing 9 changed files with 1,992 additions and 49 deletions.
8 changes: 6 additions & 2 deletions schemas/request.gql
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ query Request($id: ID!) {
id
}
nbRounds
rounds(orderBy: creationTime) {
rounds(orderBy: index) {
creationTime
index
requesterFund {
amount
}
Expand All @@ -81,6 +82,9 @@ query Request($id: ID!) {
arbitratorHistory {
updateTime
registrationMeta
id
arbitrator
extraData
}
}
}
}
12 changes: 5 additions & 7 deletions src/app/[pohid]/[chain]/[request]/ActionBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ interface ActionBarProps extends JSX.IntrinsicAttributes {
onChainVouches: Address[];
offChainVouches: { voucher: Address; expiration: number; signature: Hash }[];
expired: boolean;
arbitrationHistory: { __typename?: "ArbitratorHistory" | undefined; updateTime: any; registrationMeta: string; id: string; arbitrator: any; extraData: any; }
}

export default withClientConnected<ActionBarProps>(function ActionBar({
Expand All @@ -70,6 +71,7 @@ export default withClientConnected<ActionBarProps>(function ActionBar({
offChainVouches,
// advanceRequestsOnChainVouches,
expired,
arbitrationHistory,
}) {
const chain = useChainParam()!;
const { address } = useAccount();
Expand Down Expand Up @@ -432,16 +434,12 @@ export default withClientConnected<ActionBarProps>(function ActionBar({
pohId={pohId}
requestIndex={index}
disputeId={currentChallenge.disputeId}
/* Subgraph does not update correctly arbitration data changes
arbitrator={contractData.arbitrationInfo.arbitrator}
extraData={contractData.arbitrationInfo.extraData} */
arbitrator={arbitrationHistory.arbitrator}
extraData={arbitrationHistory.extraData}
contributor={address!}
claimer={requester}
challenger={currentChallenge.challenger?.id}
// Appelate instance funds makes sense when current round is bigger than zero which is the initial round
/* Subgraph needs redesign to have created a fresh round right after appelate is created
challengerFunds={currentChallenge.rounds.length>1 && currentChallenge.rounds.at(0)?.challengerFund?.amount}
claimerFunds={currentChallenge.rounds.length>1 && currentChallenge.rounds.at(0)?.requesterFund.amount} */
currentChallenge={currentChallenge}
chainId={chain.id}
/>

Expand Down
47 changes: 21 additions & 26 deletions src/app/[pohid]/[chain]/[request]/Appeal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { toast } from "react-toastify";
import { useEffectOnce } from "@legendapp/state/react";
import TimeAgo from "components/TimeAgo";
import { useLoading } from "hooks/useLoading";
import { APIPoH, ArbitratorFromRequest, CurrentRoundSideFunds, StakeMultipliers } from "contracts/apis/APIPoH";
import { APIPoH, StakeMultipliers } from "contracts/apis/APIPoH";
import { APIArbitrator, ArbitratorsData, DisputeStatusEnum, SideEnum } from "contracts/apis/APIArbitrator";
import { RequestQuery } from "generated/graphql";


interface SideFundingProps {
Expand Down Expand Up @@ -109,29 +110,29 @@ const SideFunding: React.FC<SideFundingProps> = ({
interface AppealProps {
pohId: Address;
requestIndex: number;
/* arbitrator: Address;
extraData: any, */
arbitrator: Address;
extraData: any,
contributor: Address;
claimer: Address;
challenger: Address;
disputeId: bigint;
/* challengerFunds: bigint;
claimerFunds: bigint; */
chainId: SupportedChainId;
currentChallenge: ArrayElement<
NonNullable<NonNullable<RequestQuery>["request"]>["challenges"]
>;
}

const Appeal: React.FC<AppealProps> = ({
pohId,
requestIndex,
disputeId,
/* arbitrator,
extraData, */
arbitrator,
extraData,
contributor,
chainId,
claimer,
challenger,
/* claimerFunds,
challengerFunds, */
currentChallenge
}) => {
const [totalClaimerCost, setTotalClaimerCost] = useState(0n);
const [totalChallengerCost, setTotalChallengerCost] = useState(0n);
Expand All @@ -142,7 +143,6 @@ const Appeal: React.FC<AppealProps> = ({
const [error, setError] = useState(false);
const errorRef = useRef(false);
const [loading, setLoading] = useState(true);
const [arbitrator, setArbitrator] = useState(null);
const [claimerFunds, setClaimerFunds] = useState(0n);
const [challengerFunds, setChallengerFunds] = useState(0n);

Expand Down Expand Up @@ -179,33 +179,28 @@ const Appeal: React.FC<AppealProps> = ({

const getAppealData = async () => {
try{
const arbitratorFromRequest: ArbitratorFromRequest = await APIPoH.getArbitratorFromRequest(chainId, pohId, requestIndex);
const arbitrator = arbitratorFromRequest.arbitrator!;
const extraData = arbitratorFromRequest.extraData!;
setArbitrator(arbitrator as any);

const currentRoundSideFunds: CurrentRoundSideFunds = await APIPoH.getCurrentRoundSideFunds(chainId, pohId, requestIndex, arbitrator, disputeId);
setClaimerFunds(currentRoundSideFunds.claimerFunds!);
setChallengerFunds(currentRoundSideFunds.challengerFunds!);
const isPartiallyFunded = Number(currentChallenge.nbRounds)+1 === currentChallenge.rounds.length;
const claimerFunds = isPartiallyFunded? currentChallenge.rounds.at(-1)?.requesterFund.amount: 0n;
const challengerFunds = isPartiallyFunded? (currentChallenge.rounds.at(-1)?.challengerFund? currentChallenge.rounds.at(-1)?.challengerFund?.amount: 0n): 0n;
setClaimerFunds(claimerFunds);
setChallengerFunds(challengerFunds);

const stakeMultipliers: StakeMultipliers = await APIPoH.getStakeMultipliers(chainId);
const winnerMult = stakeMultipliers.winnerStakeMultiplier;
const loserMult = stakeMultipliers.looserStakeMultiplier;
const loserMult = stakeMultipliers.loserStakeMultiplier;
const sharedMult = stakeMultipliers.sharedStakeMultiplier;

const arbitratorsData: ArbitratorsData = await APIArbitrator.getArbitratorsData(chainId, arbitrator, disputeId, extraData);
const status = arbitratorsData.status;
const cost = arbitratorsData.cost;
const period = arbitratorsData.period;
const currentRuling = arbitratorsData.currentRuling;


setPeriod(period as any);
setPeriod(period!);
setDisputeStatus(Number(status) as DisputeStatusEnum);
//setDisputeStatus(1 as DisputeStatusEnum); // -------------------------------- JUST FOR TESTING
formatCurrentRuling(Number(currentRuling) as SideEnum);
calculateTotalCost(cost as any, Number(currentRuling) as SideEnum, Number(winnerMult), Number(loserMult), Number(sharedMult));
calculateTotalCost(cost!, Number(currentRuling) as SideEnum, Number(winnerMult), Number(loserMult), Number(sharedMult));

setLoading(false);
} catch (e) {
!errorRef.current && toast.info("Unexpected error while reading appelate round info. Come back later");
Expand All @@ -222,7 +217,7 @@ const Appeal: React.FC<AppealProps> = ({
<Modal
header={`Appeal case #${disputeId}`}
trigger={
<button className="btn-sec mb-2">
<button className="btn-sec px-[24px] h-[48px] rounded">
Fund Appeal (ends&nbsp;<TimeAgo time={parseInt(String(period[1]))}/>)
</button>}
>
Expand Down Expand Up @@ -263,4 +258,4 @@ const Appeal: React.FC<AppealProps> = ({
);
};

export default Appeal;
export default Appeal;
1 change: 1 addition & 0 deletions src/app/[pohid]/[chain]/[request]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export default async function Request({ params }: PageProps) {
}
onChainVouches={onChainVouches}
offChainVouches={offChainVouches}
arbitrationHistory={request.arbitratorHistory}
/>

<div className="mb-6 border border-stroke shadow bg-whiteBackground rounded">
Expand Down
31 changes: 22 additions & 9 deletions src/contracts/abis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,31 @@ import multicall3 from "./multicall3";
import klerosLiquid from "./kleros-liquid";
import gnosisAMBHelper from "./gnosis-amb-helper";
import ethereumAMBBridge from "./ethereum-amb-bridge";
import { ChainSet, configSetSelection } from "contracts";
import { ChainSet, configSetSelection, configSets } from "contracts";
import abisMainnets from "./mainnets";
import abisTestnets from "./testnets";

const abis = (configSetSelection.chainSet === ChainSet.MAINNETS)? {
ProofOfHumanity: abisMainnets.ProofOfHumanity,
KlerosLiquid: klerosLiquid,
CrossChainProofOfHumanity: abisMainnets.CrossChainProofOfHumanity,
GnosisAMBHelper: gnosisAMBHelper,
EthereumAMBBridge: ethereumAMBBridge,
Multicall3: multicall3,
} : {
// There are different versions of each deployment,
// slight differences but we need to correct abis to each case
// for wagmi to predict txs correctly

const abis = (configSetSelection.chainSet === ChainSet.MAINNETS)?
(configSetSelection === configSets.mainOld)? {
ProofOfHumanity: abisMainnets.ProofOfHumanityOLD,
KlerosLiquid: klerosLiquid,
CrossChainProofOfHumanity: abisMainnets.CrossChainProofOfHumanity,
GnosisAMBHelper: gnosisAMBHelper,
EthereumAMBBridge: ethereumAMBBridge,
Multicall3: multicall3,
} : {//(configSetSelection === configSets.main)?
ProofOfHumanity: abisMainnets.ProofOfHumanity,
KlerosLiquid: klerosLiquid,
CrossChainProofOfHumanity: abisMainnets.CrossChainProofOfHumanity,
GnosisAMBHelper: gnosisAMBHelper,
EthereumAMBBridge: ethereumAMBBridge,
Multicall3: multicall3,
}
: {
ProofOfHumanity: abisTestnets.ProofOfHumanity,
KlerosLiquid: klerosLiquid,
CrossChainProofOfHumanity: abisTestnets.CrossChainProofOfHumanity,
Expand Down
2 changes: 2 additions & 0 deletions src/contracts/abis/mainnets/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import crossChainProofOfHumanity from "./cross-chain-proof-of-humanity";
import proofOfHumanity from "./proof-of-humanity";
import proofOfHumanityOLD from "./proof-of-humanity.OLD";

const abisMainnets = {
ProofOfHumanity: proofOfHumanity,
ProofOfHumanityOLD: proofOfHumanityOLD,
CrossChainProofOfHumanity: crossChainProofOfHumanity,
} as const;

Expand Down
Loading

0 comments on commit 18752f6

Please sign in to comment.