-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89194ff
commit 308cd02
Showing
5 changed files
with
126 additions
and
20 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,26 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.13; | ||
|
||
import "../../libraries/ChargingStorage.sol"; | ||
|
||
import {ADMIN_ROLE} from "../../shared/Roles.sol"; | ||
|
||
import "@solidstate/contracts/access/access_control/AccessControlInternal.sol"; | ||
|
||
/** | ||
* @title Charging | ||
* @notice TODO Documentation | ||
*/ | ||
contract Charging is AccessControlInternal { | ||
event OperationCostSet(bytes32 operation, uint256 cost); | ||
|
||
// TODO Documentation | ||
function setOperationCost( | ||
bytes32 operation, | ||
uint256 cost | ||
) external onlyRole(ADMIN_ROLE) { | ||
ChargingStorage.getStorage().operationCost[operation] = cost; | ||
|
||
emit OperationCostSet(operation, cost); | ||
} | ||
} |
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,22 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.13; | ||
|
||
import "../../libraries/SharedStorage.sol"; | ||
import "../../libraries/ChargingStorage.sol"; | ||
|
||
import "@openzeppelin/contracts/interfaces/IERC20.sol"; | ||
|
||
/** | ||
* @title ChargingInternal | ||
* @notice TODO Documentation | ||
*/ | ||
library ChargingInternal { | ||
// TODO Documentation | ||
function _chargeDcx(address sender, bytes32 operation) internal { | ||
SharedStorage.Storage storage s = SharedStorage.getStorage(); | ||
|
||
uint256 cost = ChargingStorage.getStorage().operationCost[operation]; | ||
|
||
IERC20(s.dimoCredit).transferFrom(sender, s.foundation, cost); | ||
} | ||
} |
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,29 @@ | ||
//SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.13; | ||
|
||
import "../interfaces/IDimo.sol"; | ||
import "../interfaces/ILicense.sol"; | ||
|
||
// TODO Documentation | ||
/** | ||
* @title ChargingStorage | ||
* @notice Storage of the Charging contract | ||
*/ | ||
library ChargingStorage { | ||
bytes32 internal constant CHARGING_STORAGE_SLOT = | ||
keccak256("DIMORegistry.charging.storage"); | ||
|
||
struct Storage { | ||
// TODO Use Enumerable Set ? | ||
mapping(bytes32 => uint256) operationCost; | ||
} | ||
|
||
/* solhint-disable no-inline-assembly */ | ||
function getStorage() internal pure returns (Storage storage s) { | ||
bytes32 slot = CHARGING_STORAGE_SLOT; | ||
assembly { | ||
s.slot := slot | ||
} | ||
} | ||
/* solhint-enable no-inline-assembly */ | ||
} |
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,28 @@ | ||
//SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.13; | ||
|
||
// TODO Documentation | ||
/** | ||
* @title SharedStorage | ||
* @notice Storage of shared variables | ||
*/ | ||
library SharedStorage { | ||
bytes32 internal constant SHARED_STORAGE_SLOT = | ||
keccak256("DIMORegistry.shared.storage"); | ||
|
||
struct Storage { | ||
address foundation; // TODO Maybe a better name | ||
address dimoCredit; | ||
address dimoToken; | ||
address manufacturerLicense; // TODO to deprecate AdLicenseValidator | ||
} | ||
|
||
/* solhint-disable no-inline-assembly */ | ||
function getStorage() internal pure returns (Storage storage s) { | ||
bytes32 slot = SHARED_STORAGE_SLOT; | ||
assembly { | ||
s.slot := slot | ||
} | ||
} | ||
/* solhint-enable no-inline-assembly */ | ||
} |