-
Notifications
You must be signed in to change notification settings - Fork 216
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
(Feature) Enable proxy for both strategies #1024
Changes from 11 commits
629abfc
bffb104
0ce061c
ccafb9a
ea7af7d
4599ab0
45bc31a
4d8070d
a650a8d
b88b5bb
26b286e
8e1894f
eb5302f
4ec3c88
32b69a2
6772136
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
pragma solidity ^0.4.24; | ||
|
||
/** | ||
* @title Ownable | ||
* @dev The Ownable contract has an owner address, and provides basic authorization control | ||
* functions, this simplifies the implementation of "user permissions". | ||
*/ | ||
contract Ownable { | ||
address public owner; | ||
|
||
|
||
event OwnershipRenounced(address indexed previousOwner); | ||
event OwnershipTransferred( | ||
address indexed previousOwner, | ||
address indexed newOwner | ||
); | ||
|
||
|
||
/** | ||
* @dev The Ownable constructor sets the original `owner` of the contract to the sender | ||
* account. | ||
*/ | ||
constructor() public { | ||
owner = msg.sender; | ||
} | ||
|
||
/** | ||
* @dev Throws if called by any account other than the owner. | ||
*/ | ||
modifier onlyOwner() { | ||
require(msg.sender == owner); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Allows the current owner to relinquish control of the contract. | ||
* @notice Renouncing to ownership will leave the contract without an owner. | ||
* It will not be possible to call the functions with the `onlyOwner` | ||
* modifier anymore. | ||
*/ | ||
function renounceOwnership() public onlyOwner { | ||
emit OwnershipRenounced(owner); | ||
owner = address(0); | ||
} | ||
|
||
/** | ||
* @dev Allows the current owner to transfer control of the contract to a newOwner. | ||
* @param _newOwner The address to transfer ownership to. | ||
*/ | ||
function transferOwnership(address _newOwner) public onlyOwner { | ||
_transferOwnership(_newOwner); | ||
} | ||
|
||
/** | ||
* @dev Transfers control of the contract to a newOwner. | ||
* @param _newOwner The address to transfer ownership to. | ||
*/ | ||
function _transferOwnership(address _newOwner) internal { | ||
require(_newOwner != address(0)); | ||
emit OwnershipTransferred(owner, _newOwner); | ||
owner = _newOwner; | ||
} | ||
} | ||
|
||
contract AbstractProxy { | ||
bytes32 public app_exec_id; | ||
function getAdmin() external view returns (address); | ||
} | ||
|
||
contract MintedCappedIdx { | ||
function getAdmin(address, bytes32) external view returns (address); | ||
} | ||
|
||
contract DutchIdx { | ||
function getAdmin(address, bytes32) external view returns (address); | ||
} | ||
|
||
/** | ||
* Registry of contracts deployed from Token Wizard 2.0. | ||
*/ | ||
contract TokenWizardProxiesRegistry is Ownable { | ||
address public abstractStorageAddr; | ||
address public mintedCappedIdxAddr; | ||
address public dutchIdxAddr; | ||
mapping (address => Crowdsale[]) private deployedCrowdsalesByUser; | ||
event Added(address indexed sender, address indexed proxyAddress, bytes32 appExecID); | ||
struct Crowdsale { | ||
address proxyAddress; | ||
bytes32 execID; | ||
} | ||
|
||
constructor ( | ||
address _abstractStorage, | ||
address _mintedCappedIdx, | ||
address _dutchIdx | ||
) public { | ||
require(_abstractStorage != address(0)); | ||
require(_mintedCappedIdx != address(0)); | ||
require(_dutchIdx != address(0)); | ||
require(_abstractStorage != _mintedCappedIdx && _abstractStorage != _dutchIdx && _mintedCappedIdx != _dutchIdx); | ||
abstractStorageAddr = _abstractStorage; | ||
mintedCappedIdxAddr = _mintedCappedIdx; | ||
dutchIdxAddr = _dutchIdx; | ||
} | ||
|
||
function changeAbstractStorage(address newAbstractStorageAddr) public onlyOwner { | ||
abstractStorageAddr = newAbstractStorageAddr; | ||
} | ||
|
||
function changeMintedCappedIdx(address newMintedCappedIdxAddr) public onlyOwner { | ||
mintedCappedIdxAddr = newMintedCappedIdxAddr; | ||
} | ||
|
||
function changeDutchIdxAddr(address newDutchIdxAddr) public onlyOwner { | ||
dutchIdxAddr = newDutchIdxAddr; | ||
} | ||
|
||
function trackCrowdsale(address proxyAddress) public { | ||
AbstractProxy proxy = AbstractProxy(proxyAddress); | ||
require(proxyAddress != address(0)); | ||
require(msg.sender == proxy.getAdmin()); | ||
bytes32 appExecID = proxy.app_exec_id(); | ||
require(mintedCappedIdx.getAdmin(abstractStorageAddr, appExecID) != address(0) || dutchIdx.getAdmin(abstractStorageAddr, appExecID) != address(0)); | ||
MintedCappedIdx mintedCappedIdx = MintedCappedIdx(mintedCappedIdxAddr); | ||
DutchIdx dutchIdx = DutchIdx(dutchIdxAddr); | ||
for (uint i = 0; i < deployedCrowdsalesByUser[msg.sender].length; i++) { | ||
require(deployedCrowdsalesByUser[msg.sender][i].proxyAddress != proxyAddress); | ||
require(deployedCrowdsalesByUser[msg.sender][i].execID != appExecID); | ||
} | ||
deployedCrowdsalesByUser[msg.sender].push(Crowdsale({proxyAddress: proxyAddress, execID: appExecID})); | ||
emit Added(msg.sender, proxyAddress, appExecID); | ||
} | ||
|
||
function countCrowdsalesForUser(address deployer) public view returns (uint) { | ||
return deployedCrowdsalesByUser[deployer].length; | ||
} | ||
|
||
function getCrowdsalesForUser(address deployer) public view returns (address[]) { | ||
address[] storage proxies; | ||
for (uint k = 0; k < deployedCrowdsalesByUser[deployer].length; k++) { | ||
proxies.push(deployedCrowdsalesByUser[deployer][k].proxyAddress); | ||
} | ||
return proxies; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -100,17 +100,26 @@ export let getCrowdsaleData = async (initCrowdsaleContract, execID) => { | |||
if (crowdsaleInfo && !crowdsaleInfo.hasOwnProperty('team_wallet')) { | ||||
crowdsaleInfo.team_wallet = crowdsaleInfo[1] | ||||
} | ||||
if (crowdsaleInfo && !crowdsaleInfo.hasOwnProperty('is_initialized')) { | ||||
crowdsaleInfo.is_initialized = crowdsaleInfo[2] | ||||
} | ||||
if (crowdsaleInfo && !crowdsaleInfo.hasOwnProperty('is_finalized')) { | ||||
crowdsaleInfo.is_finalized = crowdsaleInfo[3] | ||||
if (crowdsaleStore.isMintedCappedCrowdsale) { | ||||
if (crowdsaleInfo && !crowdsaleInfo.hasOwnProperty('is_initialized')) { | ||||
crowdsaleInfo.is_initialized = crowdsaleInfo[2] | ||||
} | ||||
if (crowdsaleInfo && !crowdsaleInfo.hasOwnProperty('is_finalized')) { | ||||
crowdsaleInfo.is_finalized = crowdsaleInfo[3] | ||||
} | ||||
} else if (crowdsaleStore.isDutchAuction) { | ||||
if (crowdsaleInfo && !crowdsaleInfo.hasOwnProperty('is_initialized')) { | ||||
crowdsaleInfo.is_initialized = crowdsaleInfo[3] | ||||
} | ||||
if (crowdsaleInfo && !crowdsaleInfo.hasOwnProperty('is_finalized')) { | ||||
crowdsaleInfo.is_finalized = crowdsaleInfo[4] | ||||
} | ||||
} | ||||
const wei_raised = crowdsaleInfo.wei_raised ? crowdsaleInfo.wei_raised : crowdsaleInfo[0] | ||||
const wei_raised = crowdsaleInfo.wei_raised | ||||
let tokensSold = await getTokensSold(...params).call() | ||||
console.log('tokensSold:', tokensSold) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||||
const contributors = await getCrowdsaleUniqueBuyers(...params).call() | ||||
const { fromWei } = web3Store.web3.utils | ||||
|
||||
crowdsalePageStore.setProperty('weiRaised', wei_raised) | ||||
crowdsalePageStore.setProperty('ethRaised', fromWei(wei_raised, 'ether')) | ||||
crowdsalePageStore.setProperty('tokensSold', tokensSold) | ||||
|
@@ -130,13 +139,19 @@ export let getCrowdsaleData = async (initCrowdsaleContract, execID) => { | |||
|
||||
if (crowdsaleStore.isDutchAuction) { | ||||
const crowdsaleStatus = await getCrowdsaleStatus(...params).call() | ||||
const { max_sellable } = await isCrowdsaleFull(...params).call() | ||||
crowdsaleStatus.start_rate = crowdsaleStatus.start_rate || crowdsaleStatus[0] | ||||
crowdsaleStatus.end_rate = crowdsaleStatus.end_rate || crowdsaleStatus[1] | ||||
crowdsaleStatus.current_rate = crowdsaleStatus.current_rate || crowdsaleStatus[2] | ||||
crowdsaleStatus.time_remaining = crowdsaleStatus.time_remaining || crowdsaleStatus[4] | ||||
const tokens_remaining = crowdsaleStatus.tokens_remaining || crowdsaleStatus[5] | ||||
const _isCrowdsaleFull = await isCrowdsaleFull(...params).call() | ||||
const max_sellable = _isCrowdsaleFull.max_sellable || _isCrowdsaleFull[1] | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious, why in some cases you use the array lookup for the value as an alternative, and in other cases just go with the object key lookup like in?: https://github.com/poanetwork/token-wizard/pull/1024/files#diff-5c25cfce1eba8feb7668398c93446a0bR118
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use the array lookup because Proxy getters return only arrays. In the line, that you provided, array lookup wasn't made because it was made earlier in this line:
|
||||
const current_rate = chooseRateForDutchAuction(crowdsaleStatus) | ||||
|
||||
crowdsalePageStore.setProperty('rate', current_rate) //should be one token in wei | ||||
crowdsalePageStore.setProperty('maximumSellableTokens', max_sellable) | ||||
|
||||
const tokenRemainingBN = toBigNumber(crowdsaleStatus.tokens_remaining) | ||||
const tokenRemainingBN = toBigNumber(tokens_remaining) | ||||
const curRateBN = toBigNumber(current_rate) //one token in wei | ||||
const remainingWEI = curRateBN.gt(0) | ||||
? tokenRemainingBN | ||||
|
@@ -219,6 +234,8 @@ export let getCrowdsaleTargetDates = (initCrowdsaleContract, execID) => { | |||
.getCrowdsaleStartAndEndTimes(...params) | ||||
.call() | ||||
.then(crowdsaleStartAndEndTimes => { | ||||
crowdsaleStartAndEndTimes.start_time = crowdsaleStartAndEndTimes.start_time || crowdsaleStartAndEndTimes[0] | ||||
crowdsaleStartAndEndTimes.end_time = crowdsaleStartAndEndTimes.end_time || crowdsaleStartAndEndTimes[1] | ||||
const tierDates = setTierDates(crowdsaleStartAndEndTimes.start_time, crowdsaleStartAndEndTimes.end_time) | ||||
|
||||
fillCrowdsalePageStoreDates(tierDates.startsAtMilliseconds, tierDates.endsAtMilliseconds) | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.error
insteadThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed