Skip to content

Commit

Permalink
Stub out/correct broken GP parameters (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkent600 authored Nov 27, 2018
1 parent 1964851 commit 1fce079
Show file tree
Hide file tree
Showing 22 changed files with 262 additions and 108 deletions.
13 changes: 10 additions & 3 deletions docs/Daos.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ const newDao = await DAO.new({
tokenName: "My new Token",
tokenSymbol: "MNT",
schemes: [
{ name: "Auction4Reputation", address: theContractAddress },
{
name: "Auction4Reputation",
address: theContractAddress
},
]
});
```
Expand All @@ -139,15 +142,19 @@ You can register non-Arc schemes to a new DAO. To do this you should:
2. supply the address of the scheme
3. if it is a universal scheme, supply the hash of the scheme parameters

For example, for a universal non-Arc scheme:
For example, for a universal non-Arc scheme that requires CanCallDelegateCall permissions when interacting with the DAO's controller:

```javascript
const newDao = await DAO.new({
name: "My New DAO",
tokenName: "My new Token",
tokenSymbol: "MNT",
schemes: [
{ address: theContractAddress, parametersHash: paramsHash },
{
address: theContractAddress,
parametersHash: paramsHash,
permissions: SchemePermissions.CanCallDelegateCall
},
]
});
```
Expand Down
10 changes: 9 additions & 1 deletion docs/DeveloperDocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ This will install the Truffle artifact files from Arc and the migration.json fil


## Arc Contract Wrappers
Every Arc contract wrapper class has as its root base the [ContractWrapperBase class](https://github.com/daostack/arc.js/blob/master/lib/contractWrapperBase.ts).
Every Arc contract wrapper class has as its root base the [ContractWrapperBase](https://github.com/daostack/arc.js/blob/master/lib/contractWrapperBase.ts) class.

Several classes inherit from `ContractWrapperBase`, including:

* [IntVoteInterfaceWrapper](https://github.com/daostack/arc.js/blob/master/lib/intVoteInterfaceWrapper.ts)
* [SchemeWrapperBase](https://github.com/daostack/arc.js/blob/master/lib/schemeWrapperBase.ts)
* [USchemeWrapperBase](https://github.com/daostack/arc.js/blob/master/lib/uSchemeWrapperBase.ts)
* [ProposalGeneratorBase](https://github.com/daostack/arc.js/blob/master/lib/proposalGeneratorBase.ts)


Each wrapper can be instantiated and hydrated using the [ContractWrapperFactory class](https://github.com/daostack/arc.js/blob/master/lib/contractWrapperFactory.ts). The word “hydrated” means to initialize a wrapper instance with information from the chain using `.new`, `.at` or `.deployed`.

Expand Down
28 changes: 1 addition & 27 deletions lib/contractWrapperBase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigNumber } from "bignumber.js";
import { promisify } from "es6-promisify";
import { Address, DefaultSchemePermissions, Hash, SchemePermissions } from "./commonTypes";
import { Address, Hash } from "./commonTypes";
import { ConfigService } from "./configService";
import { ControllerService } from "./controllerService";
import {
Expand Down Expand Up @@ -175,20 +175,6 @@ export abstract class ContractWrapperBase implements IContractWrapper {
return Math.max(Math.min((await func.estimateGas(...params)), maxGasLimit), 21000);
}

/**
* TODO: getDefaultPermissions should be moved to a new subclass `SchemeWrapper`
* which itself would be a base class for a new class `UniversalScheme`
*/

/**
* Any scheme that needs greater permissions should override this
* @hidden - for internal use only.
* This method will eventually be moved (see comment above)
*/
public getDefaultPermissions(): SchemePermissions {
return DefaultSchemePermissions.MinimumPermissions as number;
}

/**
* invoked to let base classes know that the `contract` is available.
*/
Expand All @@ -211,18 +197,6 @@ export abstract class ContractWrapperBase implements IContractWrapper {
return new ArcTransactionDataResult<Hash>(txResult.tx, this.contract, parametersHash);
}

/**
* Returns this scheme's permissions.
* @param avatarAddress
*/
protected async _getSchemePermissions(avatarAddress: Address): Promise<SchemePermissions> {
const controllerService = new ControllerService(avatarAddress);
const controller = await controllerService.getController();
const permissions = await controller.getSchemePermissions(this.address, avatarAddress) as string;

return SchemePermissions.fromString(permissions);
}

protected async _getSchemeParameters(avatarAddress: Address): Promise<any> {
const paramsHash = await this.getSchemeParametersHash(avatarAddress);
return this.getParameters(paramsHash);
Expand Down
2 changes: 2 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export * from "./wrappers/voteInOrganizationScheme";
export * from "./iContractWrapperBase";
export * from "./dao";
export * from "./contractWrapperBase";
export * from "./schemeWrapperBase";
export * from "./uSchemeWrapperBase";
export * from "./contractWrapperFactory";
export * from "./pubSubEventService";
export * from "./web3EventService";
Expand Down
11 changes: 9 additions & 2 deletions lib/proposalGeneratorBase.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Address } from "./commonTypes";
import { ContractWrapperBase } from "./contractWrapperBase";
import { ContractWrapperFactory } from "./contractWrapperFactory";
import { ProposalService } from "./proposalService";
import { USchemeWrapperBase } from "./uSchemeWrapperBase";
import { Web3EventService } from "./web3EventService";
import { IntVoteInterfaceFactory, IntVoteInterfaceWrapper } from "./wrappers/intVoteInterface";

export abstract class ProposalGeneratorBase extends ContractWrapperBase {
/**
* Methods for Arc universal schemes that can create proposals. Note that a contract that
* creates proposals doesn't necessary have to be a universal scheme, nor even a plain-old scheme.
* But all of the Arc proposal-generating schemes currently are currently universal schemes, so
* for the purposes of simplicity of organizating Arc.js and implementing these methods in one
* place, we define this as a `USchemeWrapperBase`.
*/
export abstract class ProposalGeneratorBase extends USchemeWrapperBase {
protected proposalService: ProposalService;
protected votingMachineFactory: ContractWrapperFactory<IntVoteInterfaceWrapper>;

Expand Down
37 changes: 37 additions & 0 deletions lib/schemeWrapperBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Address, DefaultSchemePermissions, SchemePermissions } from "./commonTypes";
import { ContractWrapperBase } from "./contractWrapperBase";
import { ControllerService } from "./controllerService";
import { ISchemeWrapper } from "./iContractWrapperBase";

/**
* Abstract base class for all Arc scheme contract wrapper classes. A scheme is defined as an Arc
* contract that can be registered with and can thus interact with a DAO controller.
*/
export abstract class SchemeWrapperBase extends ContractWrapperBase implements ISchemeWrapper {
/**
* Minimum permissions required by the scheme
*/
public getDefaultPermissions(): SchemePermissions {
return DefaultSchemePermissions.MinimumPermissions as number;
}

/**
* Returns the scheme permissions.
* @param avatarAddress
*/
public getSchemePermissions(avatarAddress: Address): Promise<SchemePermissions> {
return Promise.resolve(this.getDefaultPermissions());
}

/**
* Returns this scheme's permissions.
* @param avatarAddress
*/
protected async _getSchemePermissions(avatarAddress: Address): Promise<SchemePermissions> {
const controllerService = new ControllerService(avatarAddress);
const controller = await controllerService.getController();
const permissions = await controller.getSchemePermissions(this.address, avatarAddress) as string;

return SchemePermissions.fromString(permissions);
}
}
81 changes: 81 additions & 0 deletions lib/uSchemeWrapperBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { Address, Hash } from "./commonTypes";
import { ControllerService } from "./controllerService";
import {
ArcTransactionDataResult,
IUniversalSchemeWrapper,
StandardSchemeParams,
} from "./iContractWrapperBase";
import { SchemeWrapperBase } from "./schemeWrapperBase";
import { TxEventContext } from "./transactionService";

/**
* Abstract base class for all Arc universal scheme contract wrapper classes. A universal scheme
* is defined as an Arc scheme (see `SchemeWrapperBase`) that follows the pattern of registering
* operating parameters with the DAO's controller, thus enabling the contract to be reused across DAOs.
*/
export abstract class USchemeWrapperBase extends SchemeWrapperBase {

/**
* Given a hash, returns the associated parameters as an object.
* @param paramsHash
*/
public abstract getParameters(paramsHash: Hash): Promise<any>;

public abstract getParametersHash(params: any): Promise<Hash>;

public abstract setParameters(params: any): Promise<ArcTransactionDataResult<Hash>>;

public abstract getSchemeParameters(avatarAddress: Address): Promise<any>;

/**
* Given an avatar address, returns the schemes parameters hash
* @param avatarAddress
*/
public async getSchemeParametersHash(avatarAddress: Address): Promise<Hash> {
const controllerService = new ControllerService(avatarAddress);
const controller = await controllerService.getController();
return controller.getSchemeParameters(this.address, avatarAddress);
}

/**
* Given a hash, returns the associated parameters as an array, ordered by the order
* in which the parameters appear in the contract's Parameters struct.
* @param paramsHash
*/
public getParametersArray(paramsHash: Hash): Promise<Array<any>> {
return this.contract.parameters(paramsHash);
}
protected async _setParameters(
functionName: string,
txEventContext: TxEventContext,
...params: Array<any>): Promise<ArcTransactionDataResult<Hash>> {

const parametersHash: Hash = await this.contract.getParametersHash(...params);

const txResult = await this.wrapTransactionInvocation(functionName,
// typically this is supposed to be an object, but here it is an array
Object.assign(params, { txEventContext }),
this.contract.setParameters,
params);

return new ArcTransactionDataResult<Hash>(txResult.tx, this.contract, parametersHash);
}

protected async _getSchemeParameters(avatarAddress: Address): Promise<any> {
const paramsHash = await this.getSchemeParametersHash(avatarAddress);
return this.getParameters(paramsHash);
}

protected _getParametersHash(...params: Array<any>): Promise<Hash> {
return this.contract.getParametersHash(...params);
}

protected validateStandardSchemeParams(params: StandardSchemeParams): void {
if (!params.voteParametersHash) {
throw new Error(`voteParametersHash is not defined`);
}
if (!params.votingMachineAddress) {
throw new Error(`votingMachineAddress is not defined`);
}
}
}
4 changes: 2 additions & 2 deletions lib/wrappers/auction4Reputation.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"use strict";
import BigNumber from "bignumber.js";
import { Address, Hash } from "../commonTypes";
import { ContractWrapperBase } from "../contractWrapperBase";
import { ContractWrapperFactory } from "../contractWrapperFactory";
import { ArcTransactionResult, IContractWrapperFactory } from "../iContractWrapperBase";
import { SchemeWrapperBase } from "../schemeWrapperBase";
import { TxGeneratingFunctionOptions } from "../transactionService";
import { UtilsInternal } from "../utilsInternal";
import { EventFetcherFactory, Web3EventService } from "../web3EventService";
import { WrapperService } from "../wrapperService";
import { StandardTokenWrapper } from "./standardToken";

export class Auction4ReputationWrapper extends ContractWrapperBase {
export class Auction4ReputationWrapper extends SchemeWrapperBase {
public name: string = "Auction4Reputation";
public friendlyName: string = "Auction For Reputation";
public factory: IContractWrapperFactory<Auction4ReputationWrapper> = Auction4ReputationFactory;
Expand Down
2 changes: 1 addition & 1 deletion lib/wrappers/contributionReward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
SchemeProposalExecutedEventResult
} from "./commonEventInterfaces";

export class ContributionRewardWrapper extends ProposalGeneratorBase implements IUniversalSchemeWrapper {
export class ContributionRewardWrapper extends ProposalGeneratorBase {

public name: string = "ContributionReward";
public friendlyName: string = "Contribution Reward";
Expand Down
4 changes: 2 additions & 2 deletions lib/wrappers/fixedReputationAllocation.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"use strict";
import BigNumber from "bignumber.js";
import { Address } from "../commonTypes";
import { ContractWrapperBase } from "../contractWrapperBase";
import { ContractWrapperFactory } from "../contractWrapperFactory";
import { ArcTransactionResult, IContractWrapperFactory } from "../iContractWrapperBase";
import { SchemeWrapperBase } from "../schemeWrapperBase";
import { TxGeneratingFunctionOptions } from "../transactionService";
import { UtilsInternal } from "../utilsInternal";
import { EventFetcherFactory, Web3EventService } from "../web3EventService";

export class FixedReputationAllocationWrapper extends ContractWrapperBase {
export class FixedReputationAllocationWrapper extends SchemeWrapperBase {
public name: string = "FixedReputationAllocation";
public friendlyName: string = "Fixed Reputation Allocation";
public factory: IContractWrapperFactory<FixedReputationAllocationWrapper> = FixedReputationAllocationFactory;
Expand Down
32 changes: 16 additions & 16 deletions lib/wrappers/genesisProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -893,21 +893,21 @@ export class GenesisProtocolWrapper extends IntVoteInterfaceWrapper
public async getParameters(paramsHash: Hash): Promise<GetGenesisProtocolParamsResult> {
const params = await this.getParametersArray(paramsHash);
return {
boostedVotePeriodLimit: params[0][2].toNumber(),
daoBountyConst: params[0][12].toNumber(),
daoBountyLimit: params[0][13],
minimumStakingFee: params[0][5].toNumber(),
preBoostedVotePeriodLimit: params[0][1].toNumber(),
preBoostedVoteRequiredPercentage: params[0][0].toNumber(),
proposingRepRewardConstA: params[0][7].toNumber(),
proposingRepRewardConstB: params[0][8].toNumber(),
quietEndingPeriod: params[0][6].toNumber(),
stakerFeeRatioForVoters: params[0][9].toNumber(),
thresholdConstA: params[0][3],
thresholdConstB: params[0][4].toNumber(),
voteOnBehalf: params[1],
votersGainRepRatioFromLostRep: params[0][11].toNumber(),
votersReputationLossRatio: params[0][10].toNumber(),
boostedVotePeriodLimit: params[2].toNumber(),
daoBountyConst: 0, // params[12].toNumber(),
daoBountyLimit: new BigNumber(0), // params[13],
minimumStakingFee: params[5],
preBoostedVotePeriodLimit: params[1].toNumber(),
preBoostedVoteRequiredPercentage: params[0].toNumber(),
proposingRepRewardConstA: params[7].toNumber(),
proposingRepRewardConstB: params[8].toNumber(),
quietEndingPeriod: params[6].toNumber(),
stakerFeeRatioForVoters: params[9].toNumber(),
thresholdConstA: params[3],
thresholdConstB: params[4].toNumber(),
voteOnBehalf: "", // params[14],
votersGainRepRatioFromLostRep: params[11].toNumber(),
votersReputationLossRatio: params[10].toNumber(),
};
}

Expand Down Expand Up @@ -1204,7 +1204,7 @@ export interface GetGenesisProtocolParamsResult {
proposingRepRewardConstB: number;
quietEndingPeriod: number;
stakerFeeRatioForVoters: number;
thresholdConstA: BigNumber | string;
thresholdConstA: BigNumber;
thresholdConstB: number;
voteOnBehalf: Address;
votersGainRepRatioFromLostRep: number;
Expand Down
2 changes: 1 addition & 1 deletion lib/wrappers/globalConstraintRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SchemeProposalExecutedEventResult
} from "./commonEventInterfaces";

export class GlobalConstraintRegistrarWrapper extends ProposalGeneratorBase implements IUniversalSchemeWrapper {
export class GlobalConstraintRegistrarWrapper extends ProposalGeneratorBase {

public name: string = "GlobalConstraintRegistrar";
public friendlyName: string = "Global Constraint Registrar";
Expand Down
5 changes: 2 additions & 3 deletions lib/wrappers/locking4Reputation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"use strict";
import BigNumber from "bignumber.js";
import { Address, Hash } from "../commonTypes";
import { ContractWrapperBase } from "../contractWrapperBase";
import { ContractWrapperFactory } from "../contractWrapperFactory";
import { ArcTransactionResult, DecodedLogEntryEvent, IContractWrapperFactory } from "../iContractWrapperBase";
import { SchemeWrapperBase } from "../schemeWrapperBase";
import { TxGeneratingFunctionOptions } from "../transactionService";
import { UtilsInternal } from "../utilsInternal";
import {
Expand All @@ -13,7 +12,7 @@ import {
Web3EventService
} from "../web3EventService";

export abstract class Locking4ReputationWrapper extends ContractWrapperBase {
export abstract class Locking4ReputationWrapper extends SchemeWrapperBase {
public name: string = "Locking4Reputation";
public friendlyName: string = "Locking For Reputation";
public factory: IContractWrapperFactory<Locking4ReputationWrapper> = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/wrappers/schemeRegistrar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
SchemeProposalExecutedEventResult
} from "./commonEventInterfaces";

export class SchemeRegistrarWrapper extends ProposalGeneratorBase implements IUniversalSchemeWrapper {
export class SchemeRegistrarWrapper extends ProposalGeneratorBase {

public name: string = "SchemeRegistrar";
public friendlyName: string = "Scheme Registrar";
Expand Down
2 changes: 1 addition & 1 deletion lib/wrappers/upgradeScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
SchemeProposalExecutedEventResult
} from "./commonEventInterfaces";

export class UpgradeSchemeWrapper extends ProposalGeneratorBase implements IUniversalSchemeWrapper {
export class UpgradeSchemeWrapper extends ProposalGeneratorBase {

public name: string = "UpgradeScheme";
public friendlyName: string = "Upgrade Scheme";
Expand Down
2 changes: 1 addition & 1 deletion lib/wrappers/vestingScheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { EntityFetcherFactory, EventFetcherFactory, Web3EventService } from "../
import { SchemeProposalExecuted, SchemeProposalExecutedEventResult } from "./commonEventInterfaces";
import { StandardTokenFactory } from "./standardToken";

export class VestingSchemeWrapper extends ProposalGeneratorBase implements IUniversalSchemeWrapper {
export class VestingSchemeWrapper extends ProposalGeneratorBase {

public name: string = "VestingScheme";
public friendlyName: string = "Vesting Scheme";
Expand Down
Loading

0 comments on commit 1fce079

Please sign in to comment.