generated from peersky/bootstrap_solidity
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added paid distributor contract * added changeset * happy linter - happy life * linting fixes & improvements
- Loading branch information
Showing
9 changed files
with
296 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@peeramid-labs/eds": minor | ||
--- | ||
|
||
added paid distributor contract |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
import "./Distributor.sol"; | ||
|
||
abstract contract TokenizedDistributor is Distributor { | ||
event InstantiationCostChanged(bytes32 indexed id, uint256 cost); | ||
IERC20 public paymentToken; | ||
address public _beneficiary; | ||
mapping(bytes32 id => uint256) public instantiationCosts; | ||
uint256 public defaultInstantiationCost; | ||
constructor(IERC20 token, uint256 defaultCost, address beneficiary) Distributor() { | ||
paymentToken = token; | ||
defaultInstantiationCost = defaultCost; | ||
_beneficiary = beneficiary; | ||
} | ||
|
||
/** | ||
* @notice Sets instantiation cost on a specific instantiation id | ||
* @param distributorsId distributors id | ||
* @param cost cost of instantiation | ||
*/ | ||
function _setInstantiationCost(bytes32 distributorsId, uint256 cost) internal { | ||
instantiationCosts[distributorsId] = cost; | ||
emit InstantiationCostChanged(distributorsId, cost); | ||
} | ||
|
||
/** | ||
* @inheritdoc Distributor | ||
*/ | ||
function _addDistribution( | ||
bytes32 id, | ||
address initializerAddress | ||
) internal override returns (bytes32 distributorsId) { | ||
distributorsId = super._addDistribution(id, initializerAddress); | ||
_setInstantiationCost(distributorsId, defaultInstantiationCost); | ||
} | ||
|
||
/** | ||
* @inheritdoc Distributor | ||
*/ | ||
function _instantiate( | ||
bytes32 distributorsId, | ||
bytes memory args | ||
) | ||
internal | ||
virtual | ||
override | ||
returns (address[] memory instances, bytes32 distributionName, uint256 distributionVersion) | ||
{ | ||
paymentToken.transferFrom(msg.sender, _beneficiary, instantiationCosts[distributorsId]); | ||
return super._instantiate(distributorsId, args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
contract MockERC20 is ERC20 { | ||
constructor(string memory name, string memory symbol, uint256 initialSupply) ERC20(name, symbol) { | ||
_mint(msg.sender, initialSupply); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.8.0 <0.9.0; | ||
|
||
import "../abstracts/TokenizedDistributor.sol"; | ||
import "@openzeppelin/contracts/access/extensions/AccessControlDefaultAdminRules.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
|
||
contract MockTokenizedDistributor is TokenizedDistributor, AccessControlDefaultAdminRules { | ||
constructor( | ||
address defaultAdmin, | ||
IERC20 token, | ||
uint256 defaultCost | ||
) TokenizedDistributor(token, defaultCost, defaultAdmin) AccessControlDefaultAdminRules(3 days, defaultAdmin) { | ||
paymentToken = token; | ||
defaultInstantiationCost = defaultCost; | ||
} | ||
|
||
/** | ||
* @notice Adds a new distribution with the given identifier and initializer address. | ||
* @dev This function can only be called by an account with the `DEFAULT_ADMIN_ROLE`. | ||
* @param id The unique identifier for the distribution. | ||
* @param initializer The address that initializes the distribution. | ||
*/ | ||
function addDistribution(bytes32 id, address initializer) external onlyRole(DEFAULT_ADMIN_ROLE) { | ||
super._addDistribution(id, initializer); | ||
instantiationCosts[keccak256(abi.encode(id, initializer))] = defaultInstantiationCost; | ||
} | ||
|
||
/** | ||
* @notice Sets instantiation cost on a specific instantiation id | ||
* @param id distributors id | ||
* @param cost cost of instantiation | ||
*/ | ||
function setInstantiationCost(bytes32 id, uint256 cost) public onlyRole(DEFAULT_ADMIN_ROLE) { | ||
super._setInstantiationCost(id, cost); | ||
} | ||
|
||
/** | ||
* @notice Instantiates a new contract with the given identifier and arguments. | ||
* @param id The unique identifier for the contract to be instantiated. | ||
* @param args The calldata arguments required for the instantiation process. | ||
* @return srcs An array of instantiated infrastructure | ||
* @return name The name of the instantiated distribution. | ||
* @return version The version number of the instantiated distribution. | ||
*/ | ||
function instantiate( | ||
bytes32 id, | ||
bytes calldata args | ||
) external returns (address[] memory srcs, bytes32 name, uint256 version) { | ||
return super._instantiate(id, args); | ||
} | ||
|
||
/** | ||
* @notice Removes a distribution entry identified by the given ID. | ||
* @dev This function can only be called by an account with the `DEFAULT_ADMIN_ROLE`. | ||
* @param id The unique identifier of the distribution entry to be removed. | ||
*/ | ||
function removeDistribution(bytes32 id) public onlyRole(DEFAULT_ADMIN_ROLE) { | ||
_removeDistribution(id); | ||
} | ||
|
||
/** | ||
* | ||
* This function checks if the contract implements the interface defined by ERC165 | ||
* | ||
* @param interfaceId The interface identifier, as specified in ERC-165. | ||
* @return `true` if the contract implements `interfaceId` and | ||
* `interfaceId` is not 0xffffffff, `false` otherwise. | ||
*/ | ||
function supportsInterface( | ||
bytes4 interfaceId | ||
) public view virtual override(AccessControlDefaultAdminRules, Distributor) returns (bool) { | ||
return | ||
AccessControlDefaultAdminRules.supportsInterface(interfaceId) || Distributor.supportsInterface(interfaceId); | ||
} | ||
|
||
function changeVersion( | ||
bytes32 distributionId, | ||
LibSemver.VersionRequirement memory newRequirement | ||
) public override onlyRole(DEFAULT_ADMIN_ROLE) { | ||
super._changeVersion(distributionId, newRequirement); | ||
} | ||
|
||
// @inheritdoc IDistributor | ||
function addDistribution( | ||
IRepository repository, | ||
address initializer, | ||
LibSemver.VersionRequirement memory requirement | ||
) external override onlyRole(DEFAULT_ADMIN_ROLE) { | ||
bytes32 distributorId = keccak256(abi.encode(repository, initializer)); | ||
instantiationCosts[distributorId] = defaultInstantiationCost; | ||
super._addDistribution(address(repository), initializer, requirement); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.