Skip to content

Commit

Permalink
Implements getProposals
Browse files Browse the repository at this point in the history
Signed-off-by: emmdim <[email protected]>
  • Loading branch information
emmdim committed Sep 22, 2023
1 parent 12e34bb commit 1ab335b
Show file tree
Hide file tree
Showing 16 changed files with 638 additions and 441 deletions.
2 changes: 1 addition & 1 deletion packages/contracts-ethers/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vocdoni/offchain-voting-ethers",
"author": "Vocdoni Association",
"version": "0.0.2",
"version": "0.0.3",
"description": "Plugin contract definitions for ethers.js",
"main": "dist/bundle-cjs.js",
"module": "dist/bundle-esm.js",
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"lint:ts": "eslint --ignore-path ./.eslintignore --ext .js,.ts .",
"postinstall": "DOTENV_CONFIG_PATH=../../.env.example yarn typechain",
"test": "hardhat test",
"my": "hardhat run --network goerli deploy/02_setup/11_setup_conclude.ts",
"typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain",
"clean": "rimraf ./artifacts ./cache ./coverage ./types ./coverage.json && yarn typechain"
}
Expand Down
1 change: 0 additions & 1 deletion packages/contracts/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const ERRORS = {

export function getPluginRepoFactoryAddress(networkName: string) {
let pluginRepoFactoryAddr: string;

if (
networkName === 'localhost' ||
networkName === 'hardhat' ||
Expand Down
10 changes: 5 additions & 5 deletions packages/js-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vocdoni/offchain-voting",
"author": "Vocdoni Association",
"version": "0.0.8",
"version": "0.0.19",
"license": "AGPL-3.0-or-later",
"main": "dist/index.js",
"module": "dist/offchain-voting.esm.js",
Expand All @@ -26,9 +26,7 @@
"clean": "rm -Rf .turbo dist",
"examples": "node ./scripts/generate-examples-md.js ./examples ./examples.md"
},
"peerDependencies": {
"@vocdoni/offchain-voting-ethers": ">=0.0.1"
},
"peerDependencies": {},
"husky": {
"hooks": {
"pre-commit": "tsdx lint --fix"
Expand Down Expand Up @@ -74,7 +72,9 @@
"@ethersproject/wallet": "^5.7.0",
"graphql": "^16.6.0",
"graphql-request": "4.3.0",
"@vocdoni/offchain-voting-ethers": "./vocdoni-offchain-voting-ethers-v0.0.2.tgz"
"@vocdoni/offchain-voting-ethers": "./vocdoni-offchain-voting-ethers-v0.0.3.tgz",
"@vocdoni/sdk": "0.3.0",
"axios": "0.27.2"
},
"jest": {
"testEnvironment": "./test-environment.js",
Expand Down
25 changes: 14 additions & 11 deletions packages/js-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import {
IOffchainVotingClientEncoding,
IOffchainVotingClientEstimation,
IOffchainVotingClientMethods,
SimpleStoragClientEstimation,
OffchainVotingClientEstimation,
OffchainVotingClientDecoding,
OffchainVotingClientEncoding,
OffchainVotingClientMethods,
} from './internal';
import { OffchainVotingClientCore } from './internal/core';
import {
PluginInstallItem,
} from '@aragon/sdk-client-common';
import { Networkish } from '@ethersproject/providers';
import { OffchainVotingPluginInstall } from './types';
import { PluginInstallItem } from '@aragon/sdk-client-common';
import { Networkish } from '@ethersproject/providers';
import { EnvOptions } from '@vocdoni/sdk';

export class OffchainVotingClient
extends OffchainVotingClientCore
Expand All @@ -26,12 +25,16 @@ export class OffchainVotingClient
public encoding: IOffchainVotingClientEncoding;
public decoding: IOffchainVotingClientDecoding;

constructor(pluginContext: OffchainVotingContext) {
super(pluginContext);
this.methods = new OffchainVotingClientMethods(pluginContext);
this.estimation = new SimpleStoragClientEstimation(pluginContext);
this.encoding = new OffchainVotingClientEncoding(pluginContext);
this.decoding = new OffchainVotingClientDecoding(pluginContext);
constructor(pluginContext: OffchainVotingContext, vocdoniEnv: EnvOptions) {
if (!vocdoniEnv) throw 'Invalid Vocdoni environment';
super(pluginContext, vocdoniEnv);
this.methods = new OffchainVotingClientMethods(pluginContext, vocdoniEnv);
this.estimation = new OffchainVotingClientEstimation(
pluginContext,
vocdoniEnv
);
this.encoding = new OffchainVotingClientEncoding(pluginContext, vocdoniEnv);
this.decoding = new OffchainVotingClientDecoding(pluginContext, vocdoniEnv);
}

static encoding = {
Expand Down
8 changes: 4 additions & 4 deletions packages/js-client/src/internal/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export const DEFAULT_ADDRESSES: {
repoAddress: '',
},
goerli: {
setupAddress: '',
repoAddress: '',
setupAddress: '0xAe0c94AB8289C6fb0a45CA7733a84f549808F75b',
repoAddress: '0x2a5Cc5974D3ab30d4B0a6e6a605e06956c975171',
},
matic: {
setupAddress: '',
repoAddress: '',
},
maticmum: {
setupAddress: '',
repoAddress: '0xaca70d8c462940b839de386bcdd4cacf745632ca',
setupAddress: '0x5A6E29875cCa6eb7a9c39938720e6096468a8917',
repoAddress: '0x5BD8F8Dc73476d24F37c4d885c4528d5abB8cBe6',
},
};

Expand Down
8 changes: 5 additions & 3 deletions packages/js-client/src/internal/core.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { OffchainVotingContext } from '../context';
import { ClientCore } from '@aragon/sdk-client-common';
import { EnvOptions, VocdoniSDKClient } from '@vocdoni/sdk';

export class OffchainVotingClientCore extends ClientCore {
public offchainVotingContext: string;
public offchainVotingRepoAddress: string;

constructor(pluginContext: OffchainVotingContext) {
protected vocdoniSDK: VocdoniSDKClient;

constructor(pluginContext: OffchainVotingContext, vocdoniEnv: EnvOptions) {
super(pluginContext);
this.vocdoniSDK = new VocdoniSDKClient({ env: vocdoniEnv });
this.offchainVotingContext = pluginContext.offchainVotingBackendUrl;
this.offchainVotingRepoAddress = pluginContext.offchainVotingRepoAddress;
}
}

40 changes: 38 additions & 2 deletions packages/js-client/src/internal/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { PrepareInstallationParams } from '../types';
import {
CreateGasslessProposalParams,
GaslessVotingProposal,
PrepareInstallationParams,
GaslessPluginVotingSettings,
} from '../types';
import { IDAO } from '@aragon/osx-ethers';
import {
VotingSettings,
MintTokenParams,
ProposalCreationStepValue,
Erc20TokenDetails,
Erc721TokenDetails,
Erc20WrapperTokenDetails,
TokenVotingMember,
} from '@aragon/sdk-client';
import {
GasFeeEstimation,
Expand All @@ -24,8 +35,33 @@ export interface IOffchainVotingClientMethods {
// repo if its not specified in the state of the client
prepareInstallation(
params: PrepareInstallationParams
): AsyncGenerator<PrepareInstallationStepValue>
): AsyncGenerator<PrepareInstallationStepValue>;
// Add any methods that you need
createProposal(
params: CreateGasslessProposalParams
): AsyncGenerator<ProposalCreationStepValue>;
//
getProposal(
dao: IDAO,
pluginAddress: string,
proposalId: number
): Promise<GaslessVotingProposal | null>;
//
getProposals(
dao: IDAO,
pluginAddress: string
): Promise<GaslessVotingProposal[]>;
//
getVotingSettings(
pluginAddress: string,
blockNumber?: number
): Promise<GaslessPluginVotingSettings | null>;
getToken(
pluginAddress: string
): Promise<
Erc20TokenDetails | Erc721TokenDetails | Erc20WrapperTokenDetails | null
>;
getMembers(pluginAddress: string): Promise<TokenVotingMember[]>;
}
export interface IOffchainVotingClientEstimation {
prepareInstallation(
Expand Down
14 changes: 10 additions & 4 deletions packages/js-client/src/internal/modules/encoding.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import metadata from '../../../../contracts/src/build-metadata.json';
import { DEFAULT_ADDRESSES } from '../constants';
import { ITokenVotingClientEncoding } from '../interfaces';
import { OffchainVotingPluginInstall } from '../../types';
import { DEFAULT_ADDRESSES } from '../constants';
import { OffchainVotingClientCore } from '../core';
import {
IOffchainVotingClientEncoding,
ITokenVotingClientEncoding,
} from '../interfaces';
import { mintTokenParamsToContract, initParamsToContract } from '../utils';
import { IERC20MintableUpgradeable__factory } from '@aragon/osx-ethers';
import {
Expand Down Expand Up @@ -34,8 +38,8 @@ const prepareInstallationDataTypes = getNamedTypesFromMetadata(
* Encoding module the SDK TokenVoting Client
*/
export class OffchainVotingClientEncoding
extends ClientCore
implements ITokenVotingClientEncoding
extends OffchainVotingClientCore
implements IOffchainVotingClientEncoding
{
/**
* Computes the parameters to be given when creating the DAO,
Expand All @@ -56,6 +60,8 @@ export class OffchainVotingClientEncoding
}
const args = initParamsToContract(params);
const hexBytes = defaultAbiCoder.encode(prepareInstallationDataTypes, args);
console.log(`network ${networkName}`);
console.log(`repoaddress ${DEFAULT_ADDRESSES[networkName].repoAddress}`);
return {
id: DEFAULT_ADDRESSES[networkName].repoAddress,
data: hexToBytes(hexBytes),
Expand Down
26 changes: 14 additions & 12 deletions packages/js-client/src/internal/modules/estimation.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import * as BUILD_METADATA from "../../../../contracts/src/build-metadata.json";
import { PrepareInstallationParams } from "../../types";
import { OffchainVotingClientCore } from "../core";
import { IOffchainVotingClientEstimation } from "../interfaces";
import { PluginRepo__factory } from "@aragon/osx-ethers";
import * as BUILD_METADATA from '../../../../contracts/src/build-metadata.json';
import { PrepareInstallationParams } from '../../types';
import { OffchainVotingClientCore } from '../core';
import { IOffchainVotingClientEstimation } from '../interfaces';
import { PluginRepo__factory } from '@aragon/osx-ethers';
import {
GasFeeEstimation,
prepareGenericInstallationEstimation,
} from "@aragon/sdk-client-common";
} from '@aragon/sdk-client-common';

export class SimpleStoragClientEstimation extends OffchainVotingClientCore
implements IOffchainVotingClientEstimation {
export class OffchainVotingClientEstimation
extends OffchainVotingClientCore
implements IOffchainVotingClientEstimation
{
public async prepareInstallation(
params: PrepareInstallationParams,
params: PrepareInstallationParams
): Promise<GasFeeEstimation> {
let version = params.versionTag;
// if not specified use the lates version
Expand All @@ -21,13 +23,13 @@ export class SimpleStoragClientEstimation extends OffchainVotingClientCore
// connect to the plugin repo
const pluginRepo = PluginRepo__factory.connect(
this.offchainVotingRepoAddress,
signer,
signer
);
// get latest release
const currentRelease = await pluginRepo.latestRelease();
// get latest version
const latestVersion = await pluginRepo["getLatestVersion(uint8)"](
currentRelease,
const latestVersion = await pluginRepo['getLatestVersion(uint8)'](
currentRelease
);
version = latestVersion.tag;
}
Expand Down
Loading

0 comments on commit 1ab335b

Please sign in to comment.