Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Magic number #433

Merged
merged 13 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions apps/web/components/Forms/PoolEditForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { DisputeOutcome, PoolTypes } from "@/types";
import { abiWithErrors } from "@/utils/abiWithErrors";
import {
calculateDecay,
calculateMaxRatioNum,
CV_SCALE_PRECISION,
ETH_DECIMALS,
MAX_RATIO_CONSTANT,
} from "@/utils/numbers";
import { capitalize } from "@/utils/text";

Expand Down Expand Up @@ -157,9 +157,9 @@ export default function PoolEditForm({
spendingLimit = spendingLimit / 100;
minimumConviction = minimumConviction / 100;

const maxRatioNum = spendingLimit / MAX_RATIO_CONSTANT;
const weightNum = minimumConviction * maxRatioNum ** 2;
const maxRatioNum = calculateMaxRatioNum(spendingLimit, minimumConviction);

const weightNum = minimumConviction * maxRatioNum ** 2;
const blockTime = chainConfigMap[chainId].blockTime;

// pool settings
Expand Down Expand Up @@ -297,12 +297,12 @@ export default function PoolEditForm({
}}
registerOptions={{
max: {
value: 100,
message: "Max amount cannot exceed 100%",
value: 99.9,
message: "Minimum conviction should be under 100%",
},
min: {
value: 1 / CV_SCALE_PRECISION,
message: "Amount must be greater than 0",
message: "Minimum conviction must be greater than 0",
},
}}
>
Expand Down
12 changes: 6 additions & 6 deletions apps/web/components/Forms/PoolForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import { getEventFromReceipt } from "@/utils/contracts";
import { ipfsJsonUpload } from "@/utils/ipfsUtils";
import {
calculateDecay,
calculateMaxRatioNum,
CV_PERCENTAGE_SCALE,
CV_SCALE_PRECISION,
ETH_DECIMALS,
MAX_RATIO_CONSTANT,
} from "@/utils/numbers";
import { capitalize, ethAddressRegEx } from "@/utils/text";

Expand Down Expand Up @@ -287,13 +287,13 @@ export function PoolForm({ token, communityAddr }: Props) {
spendingLimit = spendingLimit / 100;
minimumConviction = minimumConviction / 100;

const maxRatioNum = spendingLimit / MAX_RATIO_CONSTANT;
const maxRatioNum = calculateMaxRatioNum(spendingLimit, minimumConviction);

const weightNum = minimumConviction * maxRatioNum ** 2;

const blockTime = chain.blockTime;
// pool settings

// pool settings
const maxRatio = BigInt(Math.round(maxRatioNum * CV_SCALE_PRECISION));
const weight = BigInt(Math.round(weightNum * CV_SCALE_PRECISION));
const decay = BigInt(calculateDecay(blockTime, convictionGrowth));
Expand Down Expand Up @@ -824,12 +824,12 @@ export function PoolForm({ token, communityAddr }: Props) {
}}
registerOptions={{
max: {
value: 100,
message: "Max amount cannot exceed 100%",
value: 99.9,
message: "Minimum conviction should be under 100%",
},
min: {
value: 1 / CV_SCALE_PRECISION,
message: "Amount must be greater than 0",
message: "Minimum conviction must be greater than 0",
},
}}
>
Expand Down
9 changes: 7 additions & 2 deletions apps/web/components/PoolHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ export default function PoolHeader({
strategy.config.minThresholdPoints,
+token.decimals,
);
const spendingLimit = spendingLimitPct * MAX_RATIO_CONSTANT;

const spendingLimit =
(strategy.config.maxRatio / CV_SCALE_PRECISION) *
(1 - Math.sqrt(minimumConviction / 100)) *
100;

const communityAddr = strategy.registryCommunity.id as Address;
const defaultResolution = arbitrableConfig.defaultRuling;
const proposalCollateral = arbitrableConfig.submitterCollateralAmount;
Expand Down Expand Up @@ -297,7 +302,7 @@ export default function PoolHeader({
proposalOnDispute={proposalOnDispute}
initValues={{
minimumConviction: minimumConviction.toFixed(2),
convictionGrowth: convictionGrowthSec.toFixed(2),
convictionGrowth: convictionGrowthSec.toFixed(4),
minThresholdPoints: minThresholdPoints,
spendingLimit: spendingLimit.toFixed(2),
defaultResolution: defaultResolution,
Expand Down
2 changes: 1 addition & 1 deletion apps/web/configs/chains.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const chainConfigMap: {
name: arbitrumSepolia.name,
icon: Arbitrum,
explorer: "https://arbitrum-sepolia.blockscout.com/",
blockTime: 0.23,
blockTime: 14,
confirmations: 7,
rpcUrl: process.env.NEXT_PUBLIC_RPC_URL_ARB_TESTNET!,
subgraphUrl: `${process.env.NEXT_PUBLIC_SUBGRAPH_URL_ARB_SEP?.replace("/version/latest", "")}/${SUBGRAPH_TESTNET_VERSION}`,
Expand Down
8 changes: 8 additions & 0 deletions apps/web/utils/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ function calculateDecay(blockTime: number, convictionGrowth: number) {
return Math.floor(result);
}

function calculateMaxRatioNum(
spendingLimit: number,
minimumConviction: number,
Mati0x marked this conversation as resolved.
Show resolved Hide resolved
) {
return spendingLimit / (1 - Math.sqrt(minimumConviction));
}

export {
calculateFees,
formatTokenAmount,
Expand All @@ -204,4 +211,5 @@ export {
calculatePercentageBigInt,
calculatePercentage,
calculateDecay,
calculateMaxRatioNum,
};
Loading
Loading