Skip to content

Commit

Permalink
⚡ cv chart fixes
Browse files Browse the repository at this point in the history
⚡ covenant ix
⚡ deploy script
  • Loading branch information
kamikazebr committed May 29, 2024
1 parent 85510fb commit c95ccc1
Show file tree
Hide file tree
Showing 17 changed files with 5,889 additions and 937 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {
getProposalDataDocument,
getProposalDataQuery,
} from "#/subgraph/.graphclient";
import {
formatTokenAmount,
calculatePercentageDecimals,
} from "@/utils/numbers";
import { formatTokenAmount, calculatePercentageBigInt } from "@/utils/numbers";
import { getIpfsMetadata } from "@/utils/ipfsUtils";

export const dynamic = "force-dynamic";
Expand Down Expand Up @@ -84,7 +81,7 @@ export default async function Proposal({
const tokenDecimals = getProposalQuery?.tokenGarden?.decimals;
const proposalIdNumber = proposalData.proposalNumber as number;
const convictionLast = proposalData.convictionLast as string;
const threshold = proposalData.threshold;
const threshold = proposalData.threshold as bigint;
const proposalType = proposalData.strategy.config?.proposalType as number;
const requestedAmount = proposalData.requestedAmount as bigint;
const beneficiary = proposalData.beneficiary as Address;
Expand All @@ -93,6 +90,8 @@ export default async function Proposal({
const stakedAmount = proposalData.stakedAmount as bigint;
const metadata = proposalData.metadata;

const isSignalingType = proposalType == 0;

const { title, description } = await getIpfsMetadata(metadata);

const client = createPublicClient({
Expand All @@ -112,16 +111,24 @@ export default async function Proposal({
let thFromContract = 0n;
let stakeAmountFromContract = 0n;

try {
if (!isSignalingType) {
thFromContract = (await client.readContract({
...cvStrategyContract,
functionName: "calculateThreshold",
args: [proposalIdNumber],
})) as bigint;
}
} catch (error) {
console.log(error);
}

try {
totalEffectiveActivePoints = (await client.readContract({
...cvStrategyContract,
functionName: "totalEffectiveActivePoints",
})) as bigint;
thFromContract = (await client.readContract({
...cvStrategyContract,
functionName: "calculateThreshold",
args: [requestedAmount],
})) as bigint;

stakeAmountFromContract = (await client.readContract({
...cvStrategyContract,
functionName: "getProposalStakedAmount",
Expand All @@ -143,13 +150,12 @@ export default async function Proposal({
args: [totalEffectiveActivePoints],
})) as bigint;
} catch (error) {
updateConvictionLast = getProposal[7];
updateConvictionLast = getProposal[7] as bigint;
console.log(
"proposal already executed so threshold can no be read from contracts, or it is siganling proposal",
error,
);
}
const isSignalingType = proposalType == 0;

//logs for debugging in arb sepolia - //TODO: remove before merge
console.log("requesteAmount: %s", requestedAmount);
Expand All @@ -171,16 +177,11 @@ export default async function Proposal({
// console.log(convictionLast);
console.log("convictionLast: %s", convictionLast);

// const thresholdPct = calculatePercentageDecimals(
// threshold,
// maxCVSupply,
// tokenDecimals,
// );

const thresholdPct =
(parseFloat(formatUnits(threshold, tokenDecimals)) /
parseFloat(formatUnits(maxCVSupply, tokenDecimals))) *
100;
const thresholdPct = calculatePercentageBigInt(
threshold,
maxCVSupply,
tokenDecimals,
);

console.log("thresholdPct: %s", thresholdPct);

Expand All @@ -192,10 +193,11 @@ export default async function Proposal({
// tokenDecimals,
// );

const totalSupportPct =
(parseFloat(formatUnits(stakedAmount, tokenDecimals)) /
parseFloat(formatUnits(totalEffectiveActivePoints, tokenDecimals))) *
100;
const totalSupportPct = calculatePercentageBigInt(
stakedAmount,
totalEffectiveActivePoints,
tokenDecimals,
);

console.log("totalSupportPct: %s", totalSupportPct);
// const currentConvictionPct = calculatePercentageDecimals(
Expand All @@ -204,10 +206,11 @@ export default async function Proposal({
// tokenDecimals,
// );

const currentConvictionPct =
(parseFloat(formatUnits(updateConvictionLast, tokenDecimals)) /
parseFloat(formatUnits(maxCVSupply, tokenDecimals))) *
100;
const currentConvictionPct = calculatePercentageBigInt(
updateConvictionLast,
maxCVSupply,
tokenDecimals,
);

console.log("currentConviction: %s", currentConvictionPct);

Expand Down
25 changes: 16 additions & 9 deletions apps/web/components/Charts/ConvictionBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ export const ConvictionBarChart = ({
//1) Conviction < Total Support < Threshold --- working ...
convictionLTSupportLTThreshold: {
condition: () =>
currentConvictionPct < proposalSupportPct && proposalSupportPct < thresholdPct,
currentConvictionPct < proposalSupportPct &&
proposalSupportPct < thresholdPct,
details: [
{
message: `This proposal needs ${supportNeeded} % more support to reach thresholdPct`,
message: `This proposal needs ${supportNeeded} % more support to reach ${thresholdPct}%`,
growing: true,
},
],
Expand All @@ -79,18 +80,20 @@ export const ConvictionBarChart = ({
//3) Total Support < Conviction < Threshold
supportLTConvictionLTThreshold: {
condition: () =>
proposalSupportPct < currentConvictionPct && currentConvictionPct < thresholdPct,
proposalSupportPct < currentConvictionPct &&
currentConvictionPct < thresholdPct,
details: [
{
message: `This proposal needs ${supportNeeded} % more support to reach thresholdPct`,
message: `This proposal needs ${supportNeeded} % more support to reach ${thresholdPct}%`,
growing: false,
},
],
},
//4) Total Support < Threshold < Conviction
supportLTThresholdLTConviction: {
condition: () =>
proposalSupportPct < thresholdPct && thresholdPct < currentConvictionPct,
proposalSupportPct < thresholdPct &&
thresholdPct < currentConvictionPct,
details: [
{
message: "This proposal is Executable until X date",
Expand All @@ -101,7 +104,8 @@ export const ConvictionBarChart = ({
//5) Threshold < Conviction < Total Support
thresholdLTConvictionLTSupport: {
condition: () =>
thresholdPct < currentConvictionPct && currentConvictionPct < proposalSupportPct,
thresholdPct < currentConvictionPct &&
currentConvictionPct < proposalSupportPct,
details: [
{
message: "This proposal is ready to be executed !",
Expand All @@ -112,7 +116,8 @@ export const ConvictionBarChart = ({
//6) Threshold < Total Support < Conviction
thresholdLTSupportLTConviction: {
condition: () =>
thresholdPct < proposalSupportPct && proposalSupportPct < currentConvictionPct,
thresholdPct < proposalSupportPct &&
proposalSupportPct < currentConvictionPct,
details: [
{
message: "This proposal is ready to be executed!",
Expand All @@ -128,7 +133,7 @@ export const ConvictionBarChart = ({
proposalSupportPct < thresholdPct,
details: [
{
message: `This proposal needs ${supportNeeded} % more support to reach thresholdPct`,
message: `This proposal needs ${supportNeeded} % more support to reach ${thresholdPct}%`,
growing: null,
},
],
Expand Down Expand Up @@ -305,7 +310,9 @@ export const ConvictionBarChart = ({
name: !isSignalingType ? "Threshold" : "",
stack: "a",
barWidth: 50,
data: [Number(supportNeeded) < 0 ? 0 : thresholdPct - proposalSupportPct],
data: [
Number(supportNeeded) < 0 ? 0 : thresholdPct - proposalSupportPct,
],
color: "#e9ecef",
z: -10,
markLine: {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/components/CommunityProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const CommunityProfile = ({ ...props }: CommunityProfileProps) => {
<p className="text-justify leading-6">
{covenantData?.covenant
? covenantData?.covenant
: "No covenent was submitted for this community."}
: "No covenant was submitted for this community."}
</p>
</div>
</div>
Expand Down
24 changes: 24 additions & 0 deletions apps/web/utils/numbers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as dn from "dnum";
import { formatUnits } from "viem";

export const PRECISION_SCALE = BigInt(10 ** 4);
export const INPUT_MIN_VALUE = 0.000000000001;
Expand Down Expand Up @@ -46,6 +47,28 @@ function gte(
return dn.greaterThan(v1, v2) || dn.equal(v1, v2);
}

function calculatePercentageBigInt(
value1: bigint,
value2: bigint,
tokenDecimals: number,
): number {
if (!value1 || !value2) {
// console.log("divideWithDecimals: value1 or value2 is undefined");
return 0;
}

if (value1 == 0n || value2 == 0n) {
return 0;
}

return parseFloat(
(
(parseFloat(formatUnits(value1, tokenDecimals)) /
parseFloat(formatUnits(value2, tokenDecimals))) *
100
).toFixed(2),
);
}
function calculatePercentage(value1: number, value2: number): number {
if (!value1 || !value2) {
// console.log("divideWithDecimals: value1 or value2 is undefined");
Expand Down Expand Up @@ -107,5 +130,6 @@ export {
gte,
dn,
calculatePercentageDecimals,
calculatePercentageBigInt,
calculatePercentage,
};
599 changes: 599 additions & 0 deletions broadcast/DeployCVMultiChain.s.sol/11155111/run-1716961391.json

Large diffs are not rendered by default.

599 changes: 599 additions & 0 deletions broadcast/DeployCVMultiChain.s.sol/11155111/run-1716961481.json

Large diffs are not rendered by default.

599 changes: 599 additions & 0 deletions broadcast/DeployCVMultiChain.s.sol/11155111/run-1716961553.json

Large diffs are not rendered by default.

603 changes: 603 additions & 0 deletions broadcast/DeployCVMultiChain.s.sol/11155111/run-1716962277.json

Large diffs are not rendered by default.

603 changes: 603 additions & 0 deletions broadcast/DeployCVMultiChain.s.sol/11155111/run-1716962334.json

Large diffs are not rendered by default.

1,972 changes: 1,972 additions & 0 deletions broadcast/DeployCVMultiChain.s.sol/11155111/run-1716962479.json

Large diffs are not rendered by default.

1,695 changes: 819 additions & 876 deletions broadcast/DeployCVMultiChain.s.sol/11155111/run-latest.json

Large diffs are not rendered by default.

22 changes: 10 additions & 12 deletions pkg/contracts/script/DeployCVMultiChain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ contract DeployCVMultiChain is Native, CVStrategyHelpers, Script, SafeSetup {

metadata = Metadata({protocol: 1, pointer: "QmX5jPva6koRnn88s7ZcPnNXKg1UzmYaZu9h15d8kzH1CN"});
params._metadata = metadata; // convenant ipfs
params.covenantIpfsHash = "QmX5jPva6koRnn88s7ZcPnNXKg1UzmYaZu9h15d8kzH1CN";

// params._communityName = "Alpha Seedling";
params._communityName = "Alpha Centaurians";
Expand Down Expand Up @@ -184,11 +185,11 @@ contract DeployCVMultiChain is Native, CVStrategyHelpers, Script, SafeSetup {
// paramsCV.weight = _etherToFloat(0.001 ether); // RHO = p = weight

paramsCV.decay = _etherToFloat(0.9999903 ether); // alpha = decay
paramsCV.maxRatio = _etherToFloat(0.321978234271363 ether); // beta = maxRatio
paramsCV.weight = _etherToFloat(0.01036699833 ether); // RHO = p = weight
paramsCV.maxRatio = _etherToFloat(0.3219782 ether); // beta = maxRatio
paramsCV.weight = _etherToFloat(0.010367 ether); // RHO = p = weight

(uint256 poolId, address _strategy1) = registryCommunity.createPool(
address(token), paramsCV, Metadata({protocol: 1, pointer: "QmReQ5dwWgVZTMKkJ4EWHSM6MBmKN21PQN45YtRRAUHiLG"})
address(token), paramsCV, Metadata({protocol: 1, pointer: "QmVtM9MpAJLre2TZXqRc2FTeEdseeY1HTkQUe7QuwGcEAN"})
);

CVStrategy strategy1 = CVStrategy(payable(_strategy1));
Expand All @@ -197,9 +198,9 @@ contract DeployCVMultiChain is Native, CVStrategyHelpers, Script, SafeSetup {
// strategy1.setDecay(_etherToFloat(0.8705505 ether)); // alpha = decay
// strategy1.setMaxRatio(_etherToFloat(0.321978234271363 ether)); // beta = maxRatio
// strategy1.setWeight(_etherToFloat(0.01036699833 ether)); // RHO = p = weight
strategy1.setDecay(_etherToFloat(0.9999903 ether)); // alpha = decay
strategy1.setMaxRatio(_etherToFloat(0.321978234271363 ether)); // beta = maxRatio
strategy1.setWeight(_etherToFloat(0.01036699833 ether)); // RHO = p = weight
// strategy1.setDecay(_etherToFloat(0.9999903 ether)); // alpha = decay
// strategy1.setMaxRatio(_etherToFloat(0.3219782 ether)); // beta = maxRatio
// strategy1.setWeight(_etherToFloat(0.010367 ether)); // RHO = p = weight

paramsCV.proposalType = StrategyStruct.ProposalType.Signaling;
paramsCV.pointSystem = StrategyStruct.PointSystem.Unlimited;
Expand All @@ -210,12 +211,9 @@ contract DeployCVMultiChain is Native, CVStrategyHelpers, Script, SafeSetup {

CVStrategy strategy2 = CVStrategy(payable(_strategy2));

// FAST 1 MIN GROWTH
strategy1.setDecay(_etherToFloat(0.9999903 ether)); // alpha = decay
strategy1.setMaxRatio(_etherToFloat(0.321978234271363 ether)); // beta = maxRatio
strategy1.setWeight(_etherToFloat(0.01036699833 ether)); // RHO = p = weight

// vm.sleep(WAIT_TIME);
strategy2.setDecay(_etherToFloat(0.9999903 ether)); // alpha = decay
strategy2.setMaxRatio(_etherToFloat(0.3219782 ether)); // beta = maxRatio
strategy2.setWeight(_etherToFloat(0.010367 ether)); // RHO = p = weight

safeHelper(
Safe(payable(COUNCIL_SAFE)),
Expand Down
2 changes: 1 addition & 1 deletion pkg/subgraph/.graphclient/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,7 @@ export type getTokenGardensQueryVariables = Exact<{
}>;
export type getTokenGardensQuery = {
tokenGardens: Array<(Pick<TokenGarden, 'id' | 'chainId' | 'name' | 'symbol' | 'decimals' | 'totalBalance'> & {
communities?: Maybe<Array<(Pick<RegistryCommunity, 'id' | 'chainId' | 'communityFee'> & {
communities?: Maybe<Array<(Pick<RegistryCommunity, 'id' | 'chainId' | 'covenantIpfsHash' | 'communityFee'> & {
members?: Maybe<Array<Pick<MemberCommunity, 'id'>>>;
})>>;
})>;
Expand Down
1 change: 1 addition & 0 deletions pkg/subgraph/.graphclient/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const getTokenGardensDocument = gql `
communities {
id
chainId
covenantIpfsHash
communityFee
members {
id
Expand Down
4 changes: 2 additions & 2 deletions pkg/subgraph/config/ethsepolia.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"dataSources": [
{
"name": "RegistryFactory",
"startBlock": 5997994,
"address": "0x054e83880b6151513edeae79eb1b6bc6a3872df4",
"startBlock": 5998577,
"address": "0xbff8a6c13d6536d48dce27186fc3fb503539e5f0",
"customTemplate": "registryFactory"
}
]
Expand Down
1 change: 1 addition & 0 deletions pkg/subgraph/src/query/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ query getTokenGardens {
communities {
id
chainId
covenantIpfsHash
communityFee
members {
id
Expand Down
12 changes: 6 additions & 6 deletions pkg/subgraph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ schema:
dataSources:
- kind: ethereum/contract
name: RegistryFactory
network: localhost
network: sepolia
context:
chainId:
type: Int
data: 1337
data: 11155111
source:
address: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707"
address: "0xbff8a6c13d6536d48dce27186fc3fb503539e5f0"
abi: RegistryFactory
startBlock: 0
startBlock: 5998577
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand All @@ -37,7 +37,7 @@ dataSources:
templates:
- kind: ethereum/contract
name: RegistryCommunity
network: localhost
network: sepolia
source:
abi: RegistryCommunity
mapping:
Expand Down Expand Up @@ -99,7 +99,7 @@ templates:

- kind: ethereum/contract
name: CVStrategy
network: localhost
network: sepolia
source:
abi: CVStrategy
mapping:
Expand Down

0 comments on commit c95ccc1

Please sign in to comment.