Skip to content

Commit

Permalink
feat: add space param to offchain voting power strategies (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e authored Mar 7, 2024
1 parent 4d63ef2 commit e456b85
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-cats-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@snapshot-labs/sx": patch
---

add space param to offchain voting power strategies
1 change: 1 addition & 0 deletions apps/ui/src/networks/evm/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,7 @@ export function createActions(
},
send: (envelope: any) => ethSigClient.send(envelope),
getVotingPower: async (
spaceId: string,
strategiesAddresses: string[],
strategiesParams: any[],
strategiesMetadata: StrategyParsedMetadata[],
Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/networks/offchain/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export function createActions(
},
send: (envelope: any) => client.send(envelope),
getVotingPower: async (
spaceId: string,
strategiesNames: string[],
strategiesOrValidationParams: any[],
strategiesMetadata: StrategyParsedMetadata[],
Expand All @@ -162,6 +163,7 @@ export function createActions(
if (!strategy) return [{ address: name, value: 0n, decimals: 0, token: null, symbol: '' }];

const result = await strategy.getVotingPower(
spaceId,
voterAddress,
strategiesOrValidationParams,
snapshotInfo
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/networks/starknet/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ export function createActions(
throw new Error('Not implemented');
},
getVotingPower: async (
spaceId: string,
strategiesAddresses: string[],
strategiesParams: any[],
strategiesMetadata: StrategyParsedMetadata[],
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/networks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export type VotingPowerStatus = 'loading' | 'success' | 'error';

export type ReadOnlyNetworkActions = {
getVotingPower(
spaceId: string,
strategiesAddresses: string[],
strategiesParams: any[],
strategiesMetadata: StrategyParsedMetadata[],
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/views/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ async function getVotingPower() {
const network = getNetwork(space.value.network);
const votingPowers = await network.actions.getVotingPower(
space.value.id,
space.value.voting_power_validation_strategy_strategies,
space.value.voting_power_validation_strategy_strategies_params,
space.value.voting_power_validation_strategies_parsed_metadata,
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/views/Proposal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ async function getVotingPower() {
votingPowerStatus.value = 'loading';
try {
votingPowers.value = await network.value.actions.getVotingPower(
proposal.value.space.id,
proposal.value.strategies,
proposal.value.strategies_params,
proposal.value.space.strategies_parsed_metadata,
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/views/Space/Proposals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async function getVotingPower() {
votingPowerStatus.value = 'loading';
try {
votingPowers.value = await network.value.actions.getVotingPower(
props.space.id,
props.space.strategies,
props.space.strategies_params,
props.space.strategies_parsed_metadata,
Expand Down
7 changes: 6 additions & 1 deletion packages/sx.js/src/clients/offchain/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export type SnapshotInfo = {

export type Strategy = {
type: string;
getVotingPower(voterAddress: string, params: any, snapshotInfo: SnapshotInfo): Promise<bigint[]>;
getVotingPower(
spaceId: string,
voterAddress: string,
params: any,
snapshotInfo: SnapshotInfo
): Promise<bigint[]>;
};

export type EIP712VoteMessage = {
Expand Down
2 changes: 1 addition & 1 deletion packages/sx.js/src/strategies/offchain/only-members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Strategy } from '../../clients/offchain/types';
export default function createOnlyMembersStrategy(): Strategy {
return {
type: 'only-members',
async getVotingPower(voterAddress: string, params: any) {
async getVotingPower(spaceId: string, voterAddress: string, params: any) {
const isValid = params[0].addresses
.map((address: string) => address.toLowerCase())
.includes(voterAddress.toLowerCase());
Expand Down
9 changes: 7 additions & 2 deletions packages/sx.js/src/strategies/offchain/remote-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ import { Strategy, SnapshotInfo } from '../../clients/offchain/types';
export default function createRemoteValidateStrategy(type: string): Strategy {
return {
type,
async getVotingPower(voterAddress: string, params: any, snapshotInfo: SnapshotInfo) {
async getVotingPower(
spaceId: string,
voterAddress: string,
params: any,
snapshotInfo: SnapshotInfo
) {
const isValid = await fetchScoreApi('validate', {
validation: type,
author: voterAddress,
space: '',
space: spaceId,
network: snapshotInfo.chainId,
snapshot: snapshotInfo.at ?? 'latest',
params: params[0]
Expand Down
9 changes: 7 additions & 2 deletions packages/sx.js/src/strategies/offchain/remote-vp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ import { Strategy, SnapshotInfo } from '../../clients/offchain/types';
export default function createRemoteVpStrategy(): Strategy {
return {
type: 'remote-vp',
async getVotingPower(voterAddress: string, params: any, snapshotInfo: SnapshotInfo) {
async getVotingPower(
spaceId: string,
voterAddress: string,
params: any,
snapshotInfo: SnapshotInfo
) {
const result = await fetchScoreApi('get_vp', {
address: voterAddress,
space: '',
space: spaceId,
strategies: params,
network: snapshotInfo.chainId,
snapshot: snapshotInfo.at ?? 'latest'
Expand Down

0 comments on commit e456b85

Please sign in to comment.