Skip to content

Commit

Permalink
Feature/patch token decimals into voucher hub (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Le-Caignec authored Jan 3, 2025
2 parents 145178d + c9ee780 commit 224fe6c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
18 changes: 11 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# Changelog

## vNEXT

- Remove references to blockscout v5. (#49)
- Override the decimals function of ERC-20 to set the token's decimal precision to 9, aligning with RLC standards. (#50)
- Verify VoucherProxy contracts. (#51)

## v1.0.0

### What's new?

- Allow users to access resources of the iExec network via a sponsorship voucher.

### More details

- Upgrade Solidity Compiler to `v0.8.27`. (#45)
- Bump dependencies: (#44)
- `@openzeppelin/hardhat-upgrades`, `hardhat`, `ethers`, `prettier`, and others [minor version bump]
- `prettier-plugin-organize-imports@4`
- `@openzeppelin/hardhat-upgrades`, `hardhat`, `ethers`, `prettier`, and others [minor version bump]
- `prettier-plugin-organize-imports@4`
- Add `getVoucherProxyCodeHash(..)` & `isRefundedTask(..)` view functions. (#43)
- Add `predictVoucher(..)` & `isVoucher(..)` functions. (#42)
- Generate UML class diagram for contracts. (#41)
Expand Down Expand Up @@ -44,12 +48,12 @@
- Match orders through voucher. (#12)
- Add external-hardhat network configuration. (#11)
- Add voucher credit and SRLC manipulation. (#10)
- SRLC and iExec poco is mocked.
- set voucher credit as VoucherHub is ERC20.
- SRLC and iExec poco is mocked.
- set voucher credit as VoucherHub is ERC20.
- Upgrade configuration: (#9)
- Upgrade dependencies: hardhat, husky, iExec Poco.
- Ignore mocks in coverage.
- Add solidity optimizer and use Bellecour network config.
- Upgrade dependencies: hardhat, husky, iExec Poco.
- Ignore mocks in coverage.
- Add solidity optimizer and use Bellecour network config.
- Add role-based access control to VoucherHub. (#8)
- Create voucher from VoucherHub with : type, expiration, authorize list. (#6)
- Create vouchers with create2. (#5)
Expand Down
14 changes: 14 additions & 0 deletions contracts/NonTransferableERC20Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/
* @notice This contracts follows the standard ERC-20 Upgradeable model, but it cannot be transferred.
*/
contract NonTransferableERC20Upgradeable is ERC20Upgradeable {
/**
* @dev By default, the standard ERC-20 `decimals` value is `18`. However, this value
* is overridden here to `9` to align with the number of decimal places used by
* the RLC token. This ensures consistency in how input values are handled
* when a voucher is minted.
*
* See https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC20/ERC20.sol#L78
*
* @return The number of decimal places (9) used for token representation.
*/
function decimals() public pure override returns (uint8) {
return 9;
}

/**
* @notice NonTransferableERC20Upgradeable is not transferable.
*/
Expand Down
6 changes: 6 additions & 0 deletions contracts/VoucherHub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ contract VoucherHub is
emit VoucherTypeCreated($._voucherTypes.length - 1, description, duration);
}

/**
* This function only updates the duration for newly minted vouchers and not the existing ones to provide
* guarantees regarding the expiration of vouchers. When a voucher is delivered, its credits should not expire
* before the original expiration date.
* As mentioned in Halborn audit report (HAL-01), this is not a bug, but rather, an intended feature.
*/
function updateVoucherTypeDescription(
uint256 id,
string memory description
Expand Down
5 changes: 5 additions & 0 deletions docs/VoucherHub.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ function createVoucherType(string description, uint256 duration) external
function updateVoucherTypeDescription(uint256 id, string description) external
```

This function only updates the duration for newly minted vouchers and not the existing ones to provide
guarantees regarding the expiration of vouchers. When a voucher is delivered, its credits should not expire
before the original expiration date.
As mentioned in Halborn audit report (HAL-01), this is not a bug, but rather, an intended feature.

### updateVoucherTypeDuration

```solidity
Expand Down
7 changes: 7 additions & 0 deletions test/VoucherHub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,13 @@ describe('VoucherHub', function () {
'NonTransferableERC20Upgradeable: Unsupported transferFrom',
);
});

it('Should return 9 as the number of decimals', async function () {
const { voucherHub } = await loadFixture(deployFixture);

// Call the decimals function and check the returned value
expect(await voucherHub.decimals()).to.equal(9);
});
});
});

Expand Down

0 comments on commit 224fe6c

Please sign in to comment.