Skip to content

Commit

Permalink
updated to backward compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
leekt committed Oct 18, 2020
1 parent da4fb94 commit a34e80c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 74 deletions.
20 changes: 0 additions & 20 deletions contracts/ContinuousOffering.sol
Original file line number Diff line number Diff line change
Expand Up @@ -197,30 +197,10 @@ contract ContinuousOffering
{
if(address(whitelist) != address(0))
{
//automatically activate wallet _from
//does not activate if,
//1. _from is zero address,
//2. it is burn
if(!whitelist.walletActivated(_from) && _from != address(0) && !(_to == address(0) && !_isSell)){
whitelist.activateWallet(_from);
}
//automatically activate wallet _to
//does not activate if,
//1. _to is zero address,
if(!whitelist.walletActivated(_to) && _to != address(0)){
whitelist.activateWallet(_to);
}
// This is not set for the minting of initialReserve
whitelist.authorizeTransfer(_from, _to, _value, _isSell);
}
_;
if(address(whitelist) != address(0)){
//automatically deactivates _from if _from's balance is zero
if(balanceOf(_from) == 0 && _from != address(0) && !(_to==address(0) && !_isSell)){
//deactivate wallets without balance
whitelist.deactivateWallet(_from);
}
}
}

/**
Expand Down
21 changes: 11 additions & 10 deletions contracts/Whitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -700,15 +700,8 @@ contract Whitelist is IWhitelist, Ownable, OperatorRole {
/**
* @notice activate wallet enlist user when user is not enlisted
* @dev This function can be called even user does not have balance
* only owner or callingContract can call this function
* only owner can call this function
*/
function activateWallet(
address _wallet
) external {
require(msg.sender == address(callingContract) || isOperator(msg.sender), "CALL_VIA_CONTRACT_OR_OPERATOR_ONLY");
_activateWallet(_wallet);
}

function activateWallets(
address[] calldata _wallets
) external onlyOperator {
Expand Down Expand Up @@ -839,8 +832,16 @@ contract Whitelist is IWhitelist, Ownable, OperatorRole {
);
address toUserId = authorizedWalletToUserId[_to];
require(toUserId != address(0) || _to == address(0), "TO_USER_UNKNOWN");
require(walletActivated[_from] || _from == address(0),"FROM_DEACTIVATED_WALLET");
require(walletActivated[_to] || _to == address(0),"TO_DEACTIVATED_WALLET");
if(!walletActivated[_from] && _from != address(0)){
_activateWallet(_from);
}
if(!walletActivated[_to] && _to != address(0)){
_activateWallet(_to);
}
if(callingContract.balanceOf(_from) == _value && _from != address(0)){
//deactivate wallets without balance
_deactivateWallet(_from);
}

// A single user can move funds between wallets they control without restriction
if (fromUserId != toUserId) {
Expand Down
8 changes: 0 additions & 8 deletions contracts/interfaces/IWhitelist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ interface IWhitelist {
bool _isSell
) external;

function activateWallet(
address _wallet
) external;

function deactivateWallet(
address _wallet
) external;

function walletActivated(
address _wallet
) external returns(bool);
Expand Down
6 changes: 3 additions & 3 deletions test/whitelist/activateWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ contract("whitelist / activateWallet", (accounts) => {

it("shouldFail when msg.sender is not callingContract nor owner", async () => {
await expectRevert(
contracts.whitelist.activateWallet(accounts[4], { from: accounts[4] }),
"CALL_VIA_CONTRACT_OR_OPERATOR_ONLY"
contracts.whitelist.activateWallets([accounts[4]], { from: accounts[4] }),
"OperatorRole: caller does not have the Operator role"
);
});

Expand All @@ -48,7 +48,7 @@ contract("whitelist / activateWallet", (accounts) => {
from: operatorAccount,
});
await expectRevert(
contracts.whitelist.activateWallet(accounts[4], {
contracts.whitelist.activateWallets([accounts[4]], {
from: operatorAccount,
}),
"ALREADY_ACTIVATED_WALLET"
Expand Down
34 changes: 1 addition & 33 deletions test/whitelist/authorizeTransfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ contract("whitelist / authorizeTransfer", (accounts) => {
await whitelist.updateJurisdictionFlows([1, 4, 4], [4, 1, 4], [1, 1, 1], {
from: accounts[0],
});

await whitelist.addOperator(operatorAccount,{from:accounts[0]});
await whitelist.approveNewUsers([accounts[4], accounts[7]], [4, 4], {
from: accounts[0],
});
Expand Down Expand Up @@ -117,38 +117,6 @@ contract("whitelist / authorizeTransfer", (accounts) => {
"TO_USER_UNKNOWN"
);
});

it("should fail if _from is not activated", async () => {
await whitelist.addApprovedUserWallets([accounts[4]], [accounts[5]], {
from: accounts[0],
});
await whitelist.addApprovedUserWallets([accounts[7]], [accounts[6]], {
from: accounts[0],
});
await whitelist.activateWallet(accounts[6], { from: accounts[1] });
await expectRevert(
whitelist.authorizeTransfer(accounts[5], accounts[6], 100, false, {
from: accounts[1],
}),
"FROM_DEACTIVATED_WALLET"
);
});

it("should fail if _to is not activated", async () => {
await whitelist.addApprovedUserWallets([accounts[4]], [accounts[5]], {
from: accounts[0],
});
await whitelist.addApprovedUserWallets([accounts[7]], [accounts[6]], {
from: accounts[0],
});
await whitelist.activateWallet(accounts[5], { from: accounts[1] });
await expectRevert(
whitelist.authorizeTransfer(accounts[5], accounts[6], 100, false, {
from: accounts[1],
}),
"TO_DEACTIVATED_WALLET"
);
});
});

describe("when blocked by jurisdiction flow", () => {
Expand Down

0 comments on commit a34e80c

Please sign in to comment.