SmartCoin Contract Changes

Creado El diff nunca expira
198 eliminaciones
466 líneas
59 adiciones
316 líneas
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: Apache-2.0


pragma solidity 0.8.22;

/**
/**
* This is an official institutional stablecoin issued by Societe Generale–FORGE
* This is an official institutional stablecoin issued by Societe Generale–FORGE
*
*
* CoinVertible are exclusively intended for persons who are not U.S. Persons, as defined in Regulation S of the U.S. Securities Act of 1933, as amended and who are not physically present in the U.S..
* CoinVertible are exclusively intended for persons who are not U.S. Persons, as defined in Regulation S of the U.S. Securities Act of 1933, as amended and who are not physically present in the U.S..
*
*
* Offering, or inviting to purchase, CoinVertible in the U.S. is not authorized. Potential users shall observe any such restrictions in accordance with the relevant CoinVertible whitepaper available on SG Forge website.
* Offering, or inviting to purchase, CoinVertible in the U.S. is not authorized. Potential users shall observe any such restrictions in accordance with the relevant CoinVertible whitepaper available on SG Forge website.
*/
*/


pragma solidity 0.8.17;

import "./ISmartCoin.sol";
import "./ISmartCoin.sol";
import "../libraries/EncodingUtils.sol";


import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import { ERC20Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { UUPSUpgradeable } from "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";


import "./AccessControlUpgradeable.sol";
import "./AccessControlUpgradeable.sol";
import "./SmartCoinDataLayout.sol";
import "./SmartCoinDataLayout.sol";


/**
* @dev Used when trying to validate an unknown transfer request
*/
error TransferRequestNotFound();
/**
* @dev Used when trying to validate an already validated transfer request
*/
error InvalidTransferRequestStatus();
error SpenderLockedForApproval();
/**
/**
* @dev Used when "available" balance is insufficient
* @dev Used when "available" balance is insufficient
*/
*/
error InsufficientBalance(uint256 current, uint256 required);
error InsufficientBalance(uint256 current, uint256 required);


/**

* @dev Used when generated hash already exists
*/
error HashCollision();
/**
/**
* @dev The `SmartCoin` contract is basically an ERC20 with a few specifics
* @dev The `SmartCoin` contract is basically an ERC20 with a few specifics
* It uses the UUPS upgrade mechanism
* It uses the UUPS upgrade mechanism
* It has a set of operators with specific rights :
* It has a set of operators with specific rights :
* - the registrar operator :
* - the registrar operator :
* - manages the blacklisting of users
* - manages the blacklisting of users
* - reviews(and either validates or rejects) transfers of tokens back to the registrar or the operations address
* - names the operators for next implementation contract upgrade (AccessControlUpgradeable.nameNewOperators)
* - names the operators for next implementation contract upgrade (AccessControlUpgradeable.nameNewOperators)
* - authorises upgrade to next implementation contract (AccessControlUpgradeable.authorizeImplementation)
* - authorises upgrade to next implementation contract (AccessControlUpgradeable.authorizeImplementation)
* - the operations operator is a special address used when token owners want to 'cash out' of the SmartCoin
- manages redemption addresses
* (i.e. sell their tokens to the issuer in exchange for cash) :
* - it is not possible to use the operations operator's address as spender or destination of a transferFrom
* - transfers to the operations address have to be reviewed by the registrar operator before being performed.
* - the technical operator :
* - the technical operator :
* - only the technical operator can launch a (previously authorised) upgrade of the implementation contract (upgradeTo/upgradeToAndCall)
* - only the technical operator can launch a (previously authorised) upgrade of the implementation contract (upgradeTo/upgradeToAndCall)
* Redemption Addresses are special addresses used when token owners want to 'cash out' of the SmartCoin (i.e. sell their tokens to the issuer in exchange for cash)
*/
*/
contract SmartCoin is
contract SmartCoin is
SmartCoinDataLayout,
SmartCoinDataLayout,
AccessControlUpgradeable,
AccessControlUpgradeable,
ERC20Upgradeable,
ERC20Upgradeable,
UUPSUpgradeable,
UUPSUpgradeable,
ISmartCoin
ISmartCoin
{
{
/**
* @dev Performs balance checks based on the "available" balance instead of total balance
* The "available" balance excludes tokens currently engaged in a transfer request,
* which is a two-step transfer back to the registrar operator or the operations operator
* (initiated with the transfer() method)
*/
modifier onlyWhenBalanceAvailable(address _from, uint256 _value) {
uint256 availableBalance = _availableBalance(_from);
if (_value > availableBalance)
revert InsufficientBalance({
current: availableBalance,
required: _value
});
_;
}


/// @custom:oz-upgrades-unsafe-allow constructor
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(
constructor(
address _registrar,
address _registrar,
address _operations,
address _operations,
address _technical
address _technical
)
)
onlyNotZeroAddress(_registrar)
onlyNotZeroAddress(_registrar)
onlyNotZeroAddress(_operations)
onlyNotZeroAddress(_operations)
onlyNotZeroAddress(_technical)
onlyNotZeroAddress(_technical)
OnlyWhenOperatorsHaveDifferentAddress(
OnlyWhenOperatorsHaveDifferentAddress(
_registrar,
_registrar,
_operations,
_operations,
_technical
_technical
)
)
AccessControlUpgradeable(_registrar, _operations, _technical)
AccessControlUpgradeable(
_registrar,
_operations,
_technical
)
{
{
// https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#potentially-unsafe-operations
// https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#potentially-unsafe-operations
// https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#initializing_the_implementation_contract
// https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#initializing_the_implementation_contract
_disableInitializers();
_disableInitializers();
}
}


Text moved with changes from lines 240-249 (94.1% similarity)
/**
* @dev UUPS initializer that initializes the token's name and symbol
*/
function initialize(
string memory _name,
string memory _symbol
) public initializer {
__AccessControl_init();
__ERC20_init(_name, _symbol);
__UUPSUpgradeable_init();
}

/**
/**
* @dev Burns the balance of `_addr` address
* @dev Burns the balance of `_addr` address
*
*
* NB: This method is reserved to the registrar operator.
* NB: This method is reserved to the registrar operator.
*/
*/
function wipeFrozenAddress(
function wipeFrozenAddress(
address _addr
address _addr
) external override onlyRegistrar onlyFrozen(_addr) returns (bool) {
) external override onlyRegistrar onlyFrozen(_addr) returns (bool) {
super._burn(_addr, balanceOf(_addr));
super._burn(_addr, balanceOf(_addr));
return true;
return true;
}
}


/**
/**
* @dev Burns a `amount` amount of tokens from the caller.
* @dev Burns a `amount` amount of tokens from the caller.
* NB: only the registrar operator is allowed to burn their tokens
* NB: only the registrar operator is allowed to burn their tokens
*/
*/
function burn(
function burn(
uint256 _amount
uint256 _amount
)
)
external
external
override
override
onlyWhenNotPaused
onlyRegistrar
onlyRegistrar
onlyWhenBalanceAvailable(registrar, _amount)
returns (bool)
returns (bool)
{
{
super._burn(registrar, _amount);
super._burn(registrar, _amount);
return true;
return true;