Skip to content

Commit

Permalink
fix: Use SafeERC20 in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
codynhat committed Aug 26, 2022
1 parent 9e551e3 commit f54bd15
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 17 deletions.
5 changes: 3 additions & 2 deletions contracts/pco-license/facets/CFAPenaltyBidFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import "hardhat-deploy/solc_0.8/diamond/libraries/LibDiamond.sol";
import {IConstantFlowAgreementV1} from "@superfluid-finance/ethereum-contracts/contracts/apps/CFAv1Library.sol";
import {CFAv1Library} from "@superfluid-finance/ethereum-contracts/contracts/apps/CFAv1Library.sol";
import {ISuperToken} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/superfluid/ISuperToken.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/// @notice Handles bidding using CFAs and penalities
contract CFAPenaltyBidFacet is ICFABiddable, CFABasePCOFacetModifiers {
using CFAv1Library for CFAv1Library.InitData;
using SafeERC20 for ISuperToken;

/// @notice Emitted when a bid is accepted
event BidAccepted(
Expand Down Expand Up @@ -214,12 +216,11 @@ contract CFAPenaltyBidFacet is ICFABiddable, CFABasePCOFacetModifiers {
newContributionRate
);
uint256 requiredCollateral = requiredBuffer + newForSalePrice;
bool success = paymentToken.transferFrom(
paymentToken.safeTransferFrom(
msg.sender,
address(this),
requiredCollateral
);
require(success, "CFAPenaltyBidFacet: Bid deposit failed");

// Save pending bid
_pendingBid.timestamp = block.timestamp;
Expand Down
5 changes: 3 additions & 2 deletions contracts/pco-license/libraries/LibCFABasePCO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ pragma solidity ^0.8.14;
import "../../registry/interfaces/IPCOLicenseParamsStore.sol";
import {CFAv1Library} from "@superfluid-finance/ethereum-contracts/contracts/apps/CFAv1Library.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

library LibCFABasePCO {
using CFAv1Library for CFAv1Library.InitData;
using SafeERC20 for ISuperToken;

bytes32 constant STORAGE_POSITION =
keccak256("diamond.standard.diamond.storage.LibBasePCO");
Expand Down Expand Up @@ -140,12 +142,11 @@ library LibCFABasePCO {
paymentToken,
newContributionRate
);
bool success1 = paymentToken.transferFrom(
paymentToken.safeTransferFrom(
msg.sender,
address(this),
requiredBuffer - deposit
);
require(success1, "LibCFABasePCO: Required buffer payment failed");
}

(, int96 flowRate, , ) = cs.cfaV1.cfa.getFlow(
Expand Down
14 changes: 4 additions & 10 deletions contracts/registry/facets/PCOLicenseClaimerFacet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import "hardhat-deploy/solc_0.8/diamond/libraries/LibDiamond.sol";
import "../../beacon-diamond/BeaconDiamond.sol";
import {IDiamondLoupe} from "hardhat-deploy/solc_0.8/diamond/interfaces/IDiamondLoupe.sol";
import {IConstantFlowAgreementV1} from "@superfluid-finance/ethereum-contracts/contracts/interfaces/agreements/IConstantFlowAgreementV1.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

contract PCOLicenseClaimerFacet {
using CFAv1Library for CFAv1Library.InitData;
using SafeERC20 for ISuperToken;

/// @notice Emitted when a parcel is claimed
event ParcelClaimed(uint256 indexed _licenseId, address indexed _payer);
Expand Down Expand Up @@ -224,15 +226,11 @@ contract PCOLicenseClaimerFacet {

if (block.timestamp <= ds.auctionEnd) {
// Transfer initial payment
bool success = ls.paymentToken.transferFrom(
ls.paymentToken.safeTransferFrom(
msg.sender,
ls.beneficiary,
initialForSalePrice
);
require(
success,
"PCOLicenseClaimerFacet: Initial claim payment failed"
);
}

uint256 licenseId = LibPCOLicenseClaimer._buildAndMint(
Expand Down Expand Up @@ -268,15 +266,11 @@ contract PCOLicenseClaimerFacet {
ls.paymentToken,
initialContributionRate
);
bool success1 = ls.paymentToken.transferFrom(
ls.paymentToken.safeTransferFrom(
msg.sender,
address(proxy),
requiredBuffer
);
require(
success1,
"PCOLicenseClaimerFacet: Required buffer payment failed"
);
}

// Initialize beacon
Expand Down
Loading

0 comments on commit f54bd15

Please sign in to comment.