Skip to content

Commit

Permalink
Ensure balances and allowances are sufficient
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnial committed Feb 26, 2018
1 parent b4c98a8 commit 7a89e6d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions contracts/examples/Collateralized.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,26 @@ contract Collateralized is TermsContract {
*/
require(collateralForAgreementID[agreementID].lockupPeriod == 0);

// the collateral must be successfully received by this contract.
require(ERC20(token).transferFrom(
msg.sender,
address(this),
ERC20 erc20token = ERC20(token);
address collateralizer = msg.sender;
address custodian = address(this);

/*
The collateralizer must have sufficient balance equal to or greater
than the amount being put up for collateral.
*/
require(erc20token.balanceOf(collateralizer) >= amount);

/*
The custodian must have an allowance granted by the collateralizer equal
to or greater than the amount being put up for collateral.
*/
require(erc20token.allowance(collateralizer, custodian) >= amount);

// the collateral must be successfully transferred to this contract.
require(erc20token.transferFrom(
collateralizer,
custodian,
amount
));

Expand Down

0 comments on commit 7a89e6d

Please sign in to comment.