fix: reputation curve fixed

This commit is contained in:
PedroCailleret
2022-12-04 01:51:20 -03:00
parent fc478dc12f
commit eb4cca9c12
22 changed files with 136 additions and 183 deletions

View File

@@ -13,13 +13,18 @@ import {
// exported interfaces
export interface P2pixFixture {
p2pix: P2PIX;
reputation: Reputation;
erc20: MockToken;
// proof: string[];
// wrongProof: string[];
// merkleRoot: string;
}
export interface RepFixture {
reputation: Reputation;
}
type P2PixAndReputation = P2pixFixture & RepFixture;
// exported constants
export const getSignerAddrs = (
amount: number,
@@ -32,6 +37,7 @@ export const getSignerAddrs = (
}
return signers;
};
export const randomSigners = (amount: number): Signer[] => {
const signers: Signer[] = [];
for (let i = 0; i < amount; i++) {
@@ -39,10 +45,12 @@ export const randomSigners = (amount: number): Signer[] => {
}
return signers;
};
export const getError = (Error: string) =>
ethers.utils
.keccak256(ethers.utils.toUtf8Bytes(Error))
.slice(0, 10);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const padBuffer = (addr: any) => {
return Buffer.from(
@@ -51,8 +59,24 @@ export const padBuffer = (addr: any) => {
);
};
export const curve = (x: number): number => {
return Math.round(
1 + (10 ** 6 * x) / Math.sqrt(2.5 * 10 ** 11 + x * x),
);
};
// exported async functions
export async function p2pixFixture(): Promise<P2pixFixture> {
export async function repFixture(): Promise<RepFixture> {
const Reputation = await ethers.getContractFactory(
"Reputation",
);
const reputation =
(await Reputation.deploy()) as Reputation;
return { reputation };
}
export async function p2pixFixture(): Promise<P2PixAndReputation> {
const validSigners = getSignerAddrs(
2,
await ethers.getSigners(),