Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Arc v58, Rinkeby contract addresses #382

Merged
merged 26 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f6478c4
fix GP params
dkent600 Dec 3, 2018
e68525f
update latest DX contracts, make CR desc hashing optional
dkent600 Dec 3, 2018
873d542
add more support for registering in ExternalLocking
dkent600 Dec 3, 2018
82c03e2
fix lockignToken initialize params
dkent600 Dec 3, 2018
e6f604e
upgrade migration version, clean DAO entries from migraiton json
dkent600 Dec 4, 2018
2a86298
upgrade ganache version to sync with migration package
dkent600 Dec 5, 2018
7075f48
bug fixes, constant ganache addresses, but changed account addresses
dkent600 Dec 6, 2018
15fd775
token test fix
dkent600 Dec 6, 2018
6f70438
activate fix
dkent600 Dec 6, 2018
846f450
add getUserEarnedReputation
dkent600 Dec 8, 2018
7b6c138
add auction.getBidBlocker
dkent600 Dec 8, 2018
6a35f0a
add auction.getUserEarnedReputation
dkent600 Dec 8, 2018
5eca83a
pass options to getUserEarnedReputation
dkent600 Dec 8, 2018
0b06c42
added auction.getBids
dkent600 Dec 8, 2018
3190eb2
cleanup redeeming validation
dkent600 Dec 11, 2018
b2d047c
validate enough GEN to bid
dkent600 Dec 13, 2018
a5d6e87
addded external.hasMgnToActivate
dkent600 Dec 14, 2018
f1cc82f
added locking.getReleasedAmount and getReleases
dkent600 Dec 14, 2018
e2a6497
enable account services when contracts aren't available
dkent600 Dec 15, 2018
db7df38
add getCurrentAuctionId, fix getAuctionTotalBid
dkent600 Dec 19, 2018
9b7e637
tweaked some error messages
dkent600 Dec 21, 2018
df40a87
dynamically get MGM token in hasMgnToActivate
dkent600 Dec 22, 2018
173eb10
make check for isUniversal more robust in DaoCreate.setSchemes
dkent600 Dec 24, 2018
f80dc77
bumpbed package#
dkent600 Dec 24, 2018
3710429
validation message changes
dkent600 Dec 26, 2018
949b54c
Merge branch 'master' into upgradeArc
dkent600 Dec 27, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
"host": "127.0.0.1",
"port": 8546
},
"private": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is private ? what the diff from ganache ?

Copy link
Contributor Author

@dkent600 dkent600 Dec 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private is the name used for networks with an unknown id. ganache is a special case for a network running with a particular network id that arc.js supplies. So, for example, the user might have ganache running with a unknown network id, but arc.js can't know that it is in fact ganache, so will name it "private".

BTW, "private" is the name used by the migrations package and web3.

"host": "127.0.0.1",
"port": 8545
},
"ganache": {
"host": "127.0.0.1",
"port": 8545
Expand Down
1 change: 1 addition & 0 deletions lib/contractWrapperBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export abstract class ContractWrapperBase implements IContractWrapper {

const maxGasLimit = await UtilsInternal.computeMaxGasLimit();

// note that Ganache is identified specifically as the one instantiated by arc.js (by the networkId)
if (currentNetwork === "Ganache") {
return maxGasLimit; // because who cares with ganache and we can't get good estimates from it
}
Expand Down
1 change: 1 addition & 0 deletions lib/contractWrapperFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export class ContractWrapperFactory<TWrapper extends IContractWrapper>

const maxGasLimit = await UtilsInternal.computeMaxGasLimit();

// note that Ganache is identified specifically as the one instantiated by arc.js (by the networkId)
if (currentNetwork === "Ganache") {
return maxGasLimit; // because who cares with ganache and we can't get good estimates from it
}
Expand Down
3 changes: 1 addition & 2 deletions lib/scripts/createGenesisDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ interface FounderSpec {
export class GenesisDaoCreator {

constructor(
private web3: Web3,
private network: string) {
private web3: Web3) {
}

public async run(): Promise<void> {
Expand Down
94 changes: 88 additions & 6 deletions lib/wrappers/auction4Reputation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
import BigNumber from "bignumber.js";
import { DecodedLogEntry } from "web3";
import { Address, Hash } from "../commonTypes";
import { ContractWrapperFactory } from "../contractWrapperFactory";
import { ArcTransactionResult, IContractWrapperFactory } from "../iContractWrapperBase";
Expand Down Expand Up @@ -92,6 +93,7 @@ export class Auction4ReputationWrapper extends SchemeWrapperBase {

public async redeem(options: Auction4ReputationRedeemOptions & TxGeneratingFunctionOptions)
: Promise<ArcTransactionResult> {

if (!options.beneficiaryAddress) {
throw new Error("beneficiaryAddress is not defined");
}
Expand All @@ -104,6 +106,27 @@ export class Auction4ReputationWrapper extends SchemeWrapperBase {
throw new Error("auctionId must be greater than or equal to zero");
}

const errMsg = await this.getRedeemBlocker(options);

if (errMsg) {
throw new Error(errMsg);
}

this.logContractFunctionCall("Auction4Reputation.redeem", options);

return this.wrapTransactionInvocation("Auction4Reputation.redeem",
options,
this.contract.redeem,
[options.beneficiaryAddress, options.auctionId]
);
}

/**
* Returns reason why can't redeem, or else null if can redeem
* @param lockerAddress
*/
public async getRedeemBlocker(options: Auction4ReputationRedeemOptions): Promise<string | null> {

const redeemEnableTime = await this.getRedeemEnableTime();
const now = await UtilsInternal.lastBlockDate();

Expand All @@ -117,13 +140,12 @@ export class Auction4ReputationWrapper extends SchemeWrapperBase {
throw new Error("the auction period has not passed");
}

this.logContractFunctionCall("Auction4Reputation.redeem", options);
const bid = await this.getBid(options.beneficiaryAddress, options.auctionId);
if (bid.lte(0)) {
return "nothing has been bid in this auction";
}

return this.wrapTransactionInvocation("Auction4Reputation.redeem",
options,
this.contract.redeem,
[options.beneficiaryAddress, options.auctionId]
);
return null;
}

/**
Expand Down Expand Up @@ -201,12 +223,67 @@ export class Auction4ReputationWrapper extends SchemeWrapperBase {
throw new Error("bidderAddress is not defined");
}

if (!Number.isInteger(auctionId)) {
throw new Error("auctionId is not an integer");
}

if (auctionId < 0) {
throw new Error("auctionId must be greater than or equal to zero");
}

this.validateAuctionId(auctionId);

this.logContractFunctionCall("Auction4Reputation.getBid", { bidderAddress, auctionId });
return this.contract.getBid(bidderAddress, auctionId);
}

public async getUserEarnedReputation(options: Auction4ReputationRedeemOptions): Promise<BigNumber> {
if (!options.beneficiaryAddress) {
throw new Error("beneficiaryAddress is not defined");
}

if (!Number.isInteger(options.auctionId)) {
throw new Error("auctionId is not an integer");
}

if (options.auctionId < 0) {
throw new Error("auctionId must be greater than or equal to zero");
}

const errMsg = await this.getRedeemBlocker(options);

if (errMsg) {
throw new Error(errMsg);
}

this.logContractFunctionCall("Locking4Reputation.redeem.call", options);

return this.contract.redeem.call(options.beneficiaryAddress, options.auctionId);
}

/**
* get a promise of an array of auction ids and amounts in which the given account has placed a bid,
* or all auctions if beneficiaryAddressis not supplied
* @param beneficiaryAddress optional
*/
public async getBids(beneficiaryAddress?: Address): Promise<Array<GetBidAuctionIdsResult>> {

if (!beneficiaryAddress) {
throw new Error("beneficiaryAddress is not defined");
}

const filter = beneficiaryAddress ? { _bidder: beneficiaryAddress } : {};

const bids = await this.Bid(filter).get();

return bids.map((bid: DecodedLogEntry<Auction4ReputationBidEventResult>): GetBidAuctionIdsResult => {
return {
amount: bid.args._amount,
auctionId: bid.args._auctionId.toNumber(),
};
});
}

/**
* Get a promise of the first date/time when anything can be redeemed
*/
Expand Down Expand Up @@ -399,3 +476,8 @@ export interface Auction4ReputationRedeemEventResult {
*/
_beneficiary: Address;
}

export interface GetBidAuctionIdsResult {
auctionId: number;
amount: BigNumber;
}
28 changes: 16 additions & 12 deletions lib/wrappers/contributionReward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class ContributionRewardWrapper extends ProposalGeneratorBase {
: Promise<ArcTransactionProposalResult> {

const defaults = {
descriptionIsHashed: false,
ethReward: "0",
externalToken: "", // must have a value for solidity
externalTokenReward: "0",
Expand Down Expand Up @@ -154,7 +155,7 @@ export class ContributionRewardWrapper extends ProposalGeneratorBase {
eventContext,
this.contract.proposeContributionReward,
[options.avatar,
Utils.SHA3(options.description),
options.descriptionIsHashed ? options.description : Utils.SHA3(options.description),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes a bit more sense to me to pass in whether you Arc.js to hash or not, so by default it would not be hashed, but this is ok too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tibetsprague I did it this way to avoid creating a breaking change. For what it is worth, it has the most convenient option as the default.

reputationChange,
[nativeTokenReward, ethReward, externalTokenReward, options.periodLength, options.numberOfPeriods],
options.externalToken,
Expand Down Expand Up @@ -539,17 +540,16 @@ export class ContributionRewardWrapper extends ProposalGeneratorBase {

private convertProposalPropsArrayToObject(propsArray: Array<any>, proposalId: Hash): ContributionProposal {
return {
beneficiaryAddress: propsArray[6],
contributionDescriptionHash: propsArray[0],
ethReward: propsArray[3],
executionTime: propsArray[9],
externalToken: propsArray[4],
externalTokenReward: propsArray[5],
nativeTokenReward: propsArray[1],
numberOfPeriods: propsArray[8],
periodLength: propsArray[7],
beneficiaryAddress: propsArray[5],
ethReward: propsArray[2],
executionTime: propsArray[8],
externalToken: propsArray[3],
externalTokenReward: propsArray[4],
nativeTokenReward: propsArray[0],
numberOfPeriods: propsArray[7],
periodLength: propsArray[6],
proposalId,
reputationChange: propsArray[2],
reputationChange: propsArray[1],
};
}
}
Expand Down Expand Up @@ -587,7 +587,6 @@ export interface NewContributionProposalEventResult {
export interface ContributionProposal {
proposalId: Hash;
beneficiaryAddress: Address;
contributionDescriptionHash: Hash;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this get removed?

Copy link
Contributor Author

@dkent600 dkent600 Dec 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tibetsprague I forgot about that. I've added it to the list of breaking changes above. That property was removed from the contract as part of this PR: https://github.com/daostack/arc/pull/561/files

ethReward: BigNumber;
executionTime: number;
externalToken: Address;
Expand Down Expand Up @@ -747,6 +746,11 @@ export interface ProposeContributionRewardParams {
* beneficiary address
*/
beneficiaryAddress: string;
/**
* True if description is a hashed, false if not and in which case Arc.js will hash it.
* The default is false.
*/
descriptionIsHashed?: boolean;
}

export interface ContributionRewardRedeemParams {
Expand Down
73 changes: 56 additions & 17 deletions lib/wrappers/externalLocking4Reputation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Address } from "../commonTypes";
import { ContractWrapperFactory } from "../contractWrapperFactory";
import { ArcTransactionResult, IContractWrapperFactory } from "../iContractWrapperBase";
import { TxGeneratingFunctionOptions } from "../transactionService";
import { Utils } from "../utils";
import { Web3EventService } from "../web3EventService";
import { Locking4ReputationWrapper } from "./locking4Reputation";

Expand Down Expand Up @@ -39,47 +40,85 @@ export class ExternalLocking4ReputationWrapper extends Locking4ReputationWrapper
);
}

public async getLockBlocker(options: ExternalLockingLockOptions): Promise<string | null> {

public async getLockBlocker(options: ExternalLockingClaimOptions): Promise<string | null> {
/**
* stub out amount and period -- they aren't relevant to external locking validation.
* stub out lockerAddress, amount and period -- they aren't relevant to external locking validation.
*/
const msg = await super.getLockBlocker(Object.assign({}, options, { amount: "1", period: 1 }));
const msg = await super.getLockBlocker(Object.assign({},
{ lockerAddress: "0x", amount: "1", period: 1 }
));

if (msg) {
return msg;
}

if (!options.lockerAddress) {
return "lockerAddress is not defined";
}

const alreadyLocked = await this.getAccountHasLocked(options.lockerAddress);
if (alreadyLocked) {
return "this account has already executed a lock";
}
}

public async lock(options: ExternalLockingLockOptions & TxGeneratingFunctionOptions): Promise<ArcTransactionResult> {
/**
* Claim the MGN tokens and lock them. Provide `lockerAddress` to claim on their behalf,
* otherwise claims on behalf of the caller.
* @param options
*/
public async lock(
options: ExternalLockingClaimOptions & TxGeneratingFunctionOptions): Promise<ArcTransactionResult> {

const msg = await this.getLockBlocker(options);
if (msg) {
throw new Error(msg);
}

this.logContractFunctionCall("ExternalLocking4Reputation.lock", options);
const currentAccount = (await Utils.getDefaultAccount()).toLowerCase();
let lockerAddress: Address | number = options.lockerAddress;

return this.wrapTransactionInvocation("ExternalLocking4Reputation.lock",
if (lockerAddress && (lockerAddress.toLowerCase() === currentAccount)) {
lockerAddress = 0;
}

if (lockerAddress && !(await this.isRegistered(lockerAddress as Address))) {
throw new Error(`lockerAddress has not been registered for proxy claiming: ${lockerAddress}`);
}

this.logContractFunctionCall("ExternalLocking4Reputation.claim", options);

return this.wrapTransactionInvocation("ExternalLocking4Reputation.claim",
options,
this.contract.lock,
[],
{ from: options.lockerAddress }
this.contract.claim,
[lockerAddress]
);
}

/**
* The caller is giving permission to the contract to allow someone else to claim
* on their behalf.
*/
public async register(): Promise<ArcTransactionResult> {

this.logContractFunctionCall("ExternalLocking4Reputation.register");

return this.wrapTransactionInvocation("ExternalLocking4Reputation.register",
{},
this.contract.register,
[]
);
}

/**
* Returns promise of a boolean indicating whether the given address has registered
* to have their tokens claimed for them (see `register`).
* @param lockerAddress
*/
public isRegistered(lockerAddress: Address): Promise<boolean> {
this.logContractFunctionCall("ExternalLocking4Reputation.registrar", { lockerAddress });
return this.contract.registrar(lockerAddress);
}

public getExternalLockingContract(): Promise<Address> {
this.logContractFunctionCall("ExternalLocking4Reputation.externalLockingContract");
return this.contract.externalLockingContract();

}

public getGetBalanceFuncSignature(): Promise<string> {
Expand Down Expand Up @@ -126,6 +165,6 @@ export interface ExternalLockingInitializeOptions {
reputationReward: BigNumber | string;
}

export interface ExternalLockingLockOptions {
lockerAddress: Address;
export interface ExternalLockingClaimOptions {
lockerAddress?: Address;
}
Loading