Skip to content

Commit 1dda65a

Browse files
committed
Add support for view function CalculateProposalConviction
1 parent 27cb081 commit 1dda65a

File tree

27 files changed

+594
-358
lines changed

27 files changed

+594
-358
lines changed

apps/web/hooks/useConvictionRead.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const useConvictionRead = ({
5151
refetch: triggerConvictionRefetch,
5252
} = useContractRead({
5353
...cvStrategyContract,
54-
functionName: "updateProposalConviction" as any,
54+
functionName: "calculateProposalConviction",
5555
args: [BigInt(proposalData?.proposalNumber ?? 0)],
5656
enabled,
5757
});

broadcast/UpgradeCVMultichainTest.s.sol/421614/run-1731864508.json

Lines changed: 472 additions & 0 deletions
Large diffs are not rendered by default.

broadcast/UpgradeCVMultichainTest.s.sol/421614/run-latest.json

Lines changed: 50 additions & 321 deletions
Large diffs are not rendered by default.

pkg/contracts/out/CVStrategyHelpers.sol/CVStrategyHelpers.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/CVStrategyV0_0.sol/CVStrategyV0_0.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/CVStrategyV0_0.sol/IPointStrategy.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/CollateralVault.sol/CollateralVault.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/FAllo.sol/FAllo.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/IArbitrator.sol/IArbitrator.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/ICollateralVault.sol/ICollateralVault.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/IRegistryFactory.sol/IRegistryFactory.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/ISafe.sol/Enum.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/ISafe.sol/ISafe.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/ISafe.sol/SafeProxyFactory.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/PassportScorer.sol/PassportScorer.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/RegistryCommunityV0_0.sol/RegistryCommunityV0_0.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/RegistryFactoryDiamond.sol/RegistryFactoryDiamond.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/RegistryFactoryFacet.sol/RegistryFactoryFacet.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/RegistryFactoryV0_0.sol/RegistryFactoryV0_0.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/RegistryFactoryV0_1.sol/RegistryFactoryV0_1.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/out/SafeArbitrator.sol/SafeArbitrator.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/contracts/src/CVStrategy/CVStrategyV0_0.sol

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,16 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
973973
return uint256(result);
974974
}
975975

976+
977+
function calculateProposalConviction(uint256 _proposalId) public view virtual returns (uint256) {
978+
Proposal storage proposal = proposals[_proposalId];
979+
return calculateConviction(
980+
block.number - proposal.blockLast,
981+
proposal.convictionLast,
982+
proposal.stakedAmount
983+
);
984+
}
985+
976986
/**
977987
* @dev Conviction formula: a^t * y(0) + x * (1 - a^t) / (1 - a)
978988
* Solidity implementation: y = (2^128 * a^t * y0 + x * D * (2^128 - 2^128 * a^t) / (D - aD) + 2^127) / 2^128
@@ -996,6 +1006,7 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
9961006
>> 128;
9971007
}
9981008

1009+
9991010
/**
10001011
* @dev Formula: ρ * totalStaked / (1 - a) / (β - requestedAmount / total)**2
10011012
* For the Solidity implementation we amplify ρ and β and simplify the formula:
@@ -1112,7 +1123,6 @@ contract CVStrategyV0_0 is BaseStrategyUpgradeable, IArbitrable, IPointStrategy,
11121123
}
11131124
// calculateConviction and store it
11141125
conviction = calculateConviction(
1115-
// TODO: Goss -> we should do this math inside the func so UI does not need to fetch latest block
11161126
blockNumber - _proposal.blockLast, // we assert it doesn't overflow above
11171127
_proposal.convictionLast,
11181128
_oldStaked

pkg/subgraph/src/mappings/cv-strategy.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import {
66
MemberStrategy,
77
Stake,
88
Member,
9-
ProposalDispute,
9+
ProposalDispute
1010
} from "../../generated/schema";
1111
import {
1212
ProposalDisputeMetadata as ProposalDisputeMetadataTemplate,
13-
ProposalMetadata as ProposalMetadataTemplate,
13+
ProposalMetadata as ProposalMetadataTemplate
1414
} from "../../generated/templates";
1515

1616
import {
@@ -692,6 +692,7 @@ function computeInitialize(
692692
cvs.totalEffectiveActivePoints = cvc.totalEffectiveActivePoints();
693693
cvs.isEnabled = false;
694694
cvs.sybilScorer = data.sybilScorer.toHexString();
695+
cvs.archived = false;
695696
config.proposalType = BigInt.fromI32(pType);
696697
config.pointSystem = BigInt.fromI32(pointSystem);
697698
config.maxAmount = maxAmount;

pkg/subgraph/src/mappings/registry-community.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
MemberStrategy
1111
} from "../../generated/schema";
1212

13-
import { BigInt, dataSource, ethereum, log } from "@graphprotocol/graph-ts";
13+
import { BigInt, dataSource, log } from "@graphprotocol/graph-ts";
1414
import {
1515
RegistryInitialized,
1616
RegistryCommunityV0_0 as RegistryCommunityContract,
@@ -32,7 +32,8 @@ import {
3232
CouncilSafeUpdated,
3333
CovenantIpfsHashUpdated,
3434
FeeReceiverChanged,
35-
KickEnabledUpdated
35+
KickEnabledUpdated,
36+
PoolRejected
3637
} from "../../generated/templates/RegistryCommunityV0_0/RegistryCommunityV0_0";
3738

3839
import { RegistryFactoryV0_0 as RegistryFactoryContract } from "../../generated/RegistryFactoryV0_0/RegistryFactoryV0_0";
@@ -265,6 +266,7 @@ export function handleStrategyAdded(event: StrategyAdded): void {
265266
}
266267

267268
cvs.isEnabled = true;
269+
cvs.archived = false;
268270
cvs.save();
269271
}
270272

@@ -633,6 +635,23 @@ export function handleFeeReceiverChanged(event: FeeReceiverChanged): void {
633635
community.save();
634636
}
635637

638+
export function handlePoolRejected(event: PoolRejected): void {
639+
log.debug("RegistryCommunity: handlePoolRejected: strategy:{}", [
640+
event.params._strategy.toHexString()
641+
]);
642+
643+
const strategyAddress = event.params._strategy;
644+
const strategy = CVStrategy.load(strategyAddress.toHexString());
645+
if (strategy == null) {
646+
log.error("RegistryCommunity: Strategy not found: {}", [
647+
strategyAddress.toHexString()
648+
]);
649+
return;
650+
}
651+
strategy.archived = true;
652+
strategy.save();
653+
}
654+
636655
// handler: handleMemberPowerDecreased
637656
// export function handleMemberPowerDecreased(event: MemberPowerDecreased): void {
638657
// log.debug("RegistryCommunity: handleMemberPowerDecreased: member:{} power:{} strategy:{} ", [

pkg/subgraph/src/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type CVStrategy @entity(immutable: false) {
1212
isEnabled: Boolean!
1313
token: String!
1414
sybilScorer: PassportScorer
15+
archived: Boolean!
1516
}
1617

1718
type CVStrategyConfig @entity(immutable: false) {

pkg/subgraph/src/templates/subgraph.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ templates:
7575
- event: CommunityNameUpdated(string)
7676
handler: handleCommunityNameUpdated
7777
- event: FeeReceiverChanged(address)
78-
handler: handleFeeReceiverChanged
78+
handler: handleFeeReceiverChanged
79+
- event: PoolRejected(address)
80+
handler: handlePoolRejected
7981
file: ./src/mappings/registry-community.ts
8082

8183
- kind: ethereum/contract

pkg/subgraph/subgraph.yaml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ schema:
66
dataSources:
77
- kind: ethereum/contract
88
name: RegistryFactoryV0_0
9-
network: arbitrum-sepolia
9+
network: localhost
1010
context:
1111
chainId:
1212
type: Int
13-
data: 421614
13+
data: 1337
1414
source:
15-
address: "0x2689b1e4afcbfb393d9727fba2ab52930035ee85"
15+
address: "0xb7f8bc63bbcad18155201308c8f3540b07f84f5e"
1616
abi: RegistryFactoryV0_0
17-
startBlock: 95965509
17+
startBlock: 0
1818
mapping:
1919
kind: ethereum/events
2020
apiVersion: 0.0.7
@@ -40,15 +40,15 @@ dataSources:
4040

4141
- kind: ethereum/contract
4242
name: PassportScorer
43-
network: arbitrum-sepolia
43+
network: localhost
4444
context:
4545
chainId:
4646
type: Int
47-
data: 421614
47+
data: 1337
4848
source:
49-
address: "0x32Fe66622a4D4607241AC723e23Fef487ACDABb5"
49+
address: "0x0165878a594ca255338adfa4d48449f69242eb8f"
5050
abi: PassportScorer
51-
startBlock: 95965509
51+
startBlock: 0
5252
mapping:
5353
kind: ethereum/events
5454
apiVersion: 0.0.7
@@ -78,7 +78,7 @@ dataSources:
7878
templates:
7979
- kind: ethereum/contract
8080
name: RegistryCommunityV0_0
81-
network: arbitrum-sepolia
81+
network: localhost
8282
source:
8383
abi: RegistryCommunityV0_0
8484
mapping:
@@ -143,12 +143,14 @@ templates:
143143
- event: CommunityNameUpdated(string)
144144
handler: handleCommunityNameUpdated
145145
- event: FeeReceiverChanged(address)
146-
handler: handleFeeReceiverChanged
146+
handler: handleFeeReceiverChanged
147+
- event: PoolRejected(address)
148+
handler: handlePoolRejected
147149
file: ./src/mappings/registry-community.ts
148150

149151
- kind: ethereum/contract
150152
name: CVStrategyV0_0
151-
network: arbitrum-sepolia
153+
network: localhost
152154
source:
153155
abi: CVStrategyV0_0
154156
mapping:
@@ -207,7 +209,7 @@ templates:
207209

208210
- kind: ethereum/contract
209211
name: CollateralVault
210-
network: arbitrum-sepolia
212+
network: localhost
211213
source:
212214
abi: CollateralVault
213215
mapping:

0 commit comments

Comments
 (0)