Skip to content

Commit

Permalink
add custom errors
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcabot committed Dec 14, 2022
1 parent 72dbe6e commit 6741872
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 15 deletions.
9 changes: 4 additions & 5 deletions contracts/SoulLinker.sol
Expand Up @@ -162,8 +162,8 @@ contract SoulLinker is PaymentGateway, EIP712, Pausable {
require(identityOwner == tokenOwner, "IDENTITY_OWNER_NOT_TOKEN_OWNER");
if (identityOwner != _msgSender()) revert CallerNotOwner(_msgSender());
require(expirationDate >= block.timestamp, "VALID_PERIOD_EXPIRED");
require(
_verify(
if (
!_verify(
_hash(
readerIdentityId,
ownerIdentityId,
Expand All @@ -175,9 +175,8 @@ contract SoulLinker is PaymentGateway, EIP712, Pausable {
),
signature,
identityOwner
),
"INVALID_SIGNATURE"
);
)
) revert InvalidSignature();

if (addPermissionPriceMASA > 0) {
// if there is a price in MASA, pay it without conversion rate
Expand Down
2 changes: 1 addition & 1 deletion contracts/SoulboundCreditScore.sol
Expand Up @@ -57,7 +57,7 @@ contract SoulboundCreditScore is MasaSBTSelfSovereign {
) public payable virtual returns (uint256) {
address to = soulboundIdentity.ownerOf(identityId);
if (to != _msgSender()) revert CallerNotOwner(_msgSender());
require(balanceOf(to) < 1, "CREDITSCORE_ALREADY_CREATED");
if (balanceOf(to) > 0) revert CreditScoreAlreadyCreated(to);

_verify(
_hash(identityId, authorityAddress, signatureDate),
Expand Down
4 changes: 2 additions & 2 deletions contracts/SoulboundIdentity.sol
Expand Up @@ -46,7 +46,7 @@ contract SoulboundIdentity is MasaSBTAuthority, ISoulboundIdentity {
/// @param to Address of the admin of the new identity
function mint(address to) public override returns (uint256) {
// Soulbound identity already created!
require(balanceOf(to) < 1, "SB_IDENTITY_ALREADY_CREATED");
if (balanceOf(to) > 0) revert IdentityAlreadyCreated(to);

return _mintWithCounter(to);
}
Expand Down Expand Up @@ -220,7 +220,7 @@ contract SoulboundIdentity is MasaSBTAuthority, ISoulboundIdentity {
/* ========== MODIFIERS ================================================= */

modifier soulNameAlreadySet() {
require(address(soulName) != address(0), "SOULNAME_CONTRACT_NOT_SET");
if (address(soulName) == address(0)) revert SoulNameContractNotSet();
_;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/dex/PaymentGateway.sol
Expand Up @@ -109,7 +109,7 @@ abstract contract PaymentGateway is Ownable {
/// @param _erc20token New ERC20 token to add
function addErc20Token(address _erc20token) external onlyOwner {
if (_erc20token == address(0)) revert ZeroAddress();
require(!erc20token[_erc20token], "ALREADY_ADDED");
if (erc20token[_erc20token]) revert AlreadyAdded();

erc20token[_erc20token] = true;
erc20tokens.push(_erc20token);
Expand Down
6 changes: 6 additions & 0 deletions contracts/libraries/Errors.sol
@@ -1,7 +1,13 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.7;

error AlreadyAdded();
error CallerNotOwner(address caller);
error CreditScoreAlreadyCreated(address to);
error IdentityAlreadyCreated(address to);
error InvalidPaymentMethod(address paymentMethod);
error InvalidSignature();
error NotAuthorized(address signer);
error SameValue();
error SoulNameContractNotSet();
error ZeroAddress();
6 changes: 3 additions & 3 deletions contracts/tokens/MasaSBTSelfSovereign.sol
Expand Up @@ -92,7 +92,7 @@ abstract contract MasaSBTSelfSovereign is PaymentGateway, MasaSBT, EIP712 {
onlyRole(DEFAULT_ADMIN_ROLE)
{
if (_authority == address(0)) revert ZeroAddress();
require(!authorities[_authority], "ALREADY_ADDED");
if (authorities[_authority]) revert AlreadyAdded();

authorities[_authority] = true;
}
Expand Down Expand Up @@ -137,8 +137,8 @@ abstract contract MasaSBTSelfSovereign is PaymentGateway, MasaSBT, EIP712 {
address signer
) internal view {
address _signer = ECDSA.recover(digest, signature);
require(_signer == signer, "INVALID_SIGNATURE");
require(authorities[_signer], "NOT_AUTHORIZED");
if (_signer != signer) revert InvalidSignature();
if (!authorities[_signer]) revert NotAuthorized(_signer);
}

function _mintWithCounter(address to) internal virtual returns (uint256) {
Expand Down
22 changes: 22 additions & 0 deletions docs/SoulLinker.md
Expand Up @@ -836,6 +836,17 @@ event Unpaused(address account)

## Errors

### AlreadyAdded

```solidity
error AlreadyAdded()
```






### CallerNotOwner

```solidity
Expand Down Expand Up @@ -868,6 +879,17 @@ error InvalidPaymentMethod(address paymentMethod)
|---|---|---|
| paymentMethod | address | undefined |

### InvalidSignature

```solidity
error InvalidSignature()
```






### SameValue

```solidity
Expand Down
11 changes: 11 additions & 0 deletions docs/SoulStore.md
Expand Up @@ -649,6 +649,17 @@ event Unpaused(address account)

## Errors

### AlreadyAdded

```solidity
error AlreadyAdded()
```






### InvalidPaymentMethod

```solidity
Expand Down
38 changes: 38 additions & 0 deletions docs/Soulbound2FA.md
Expand Up @@ -959,6 +959,17 @@ event Soulbound2FAMinted(uint256 tokenId, uint256 identityId, address authorityA

## Errors

### AlreadyAdded

```solidity
error AlreadyAdded()
```






### CallerNotOwner

```solidity
Expand Down Expand Up @@ -991,6 +1002,33 @@ error InvalidPaymentMethod(address paymentMethod)
|---|---|---|
| paymentMethod | address | undefined |

### InvalidSignature

```solidity
error InvalidSignature()
```






### NotAuthorized

```solidity
error NotAuthorized(address signer)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| signer | address | undefined |

### SameValue

```solidity
Expand Down
54 changes: 54 additions & 0 deletions docs/SoulboundCreditScore.md
Expand Up @@ -959,6 +959,17 @@ event SoulboundCreditScoreMinted(uint256 tokenId, uint256 identityId, address au

## Errors

### AlreadyAdded

```solidity
error AlreadyAdded()
```






### CallerNotOwner

```solidity
Expand All @@ -975,6 +986,22 @@ error CallerNotOwner(address caller)
|---|---|---|
| caller | address | undefined |

### CreditScoreAlreadyCreated

```solidity
error CreditScoreAlreadyCreated(address to)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| to | address | undefined |

### InvalidPaymentMethod

```solidity
Expand All @@ -991,6 +1018,33 @@ error InvalidPaymentMethod(address paymentMethod)
|---|---|---|
| paymentMethod | address | undefined |

### InvalidSignature

```solidity
error InvalidSignature()
```






### NotAuthorized

```solidity
error NotAuthorized(address signer)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| signer | address | undefined |

### SameValue

```solidity
Expand Down
38 changes: 38 additions & 0 deletions docs/SoulboundIdentity.md
Expand Up @@ -731,6 +731,44 @@ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed

## Errors

### IdentityAlreadyCreated

```solidity
error IdentityAlreadyCreated(address to)
```





#### Parameters

| Name | Type | Description |
|---|---|---|
| to | address | undefined |

### SameValue

```solidity
error SameValue()
```






### SoulNameContractNotSet

```solidity
error SoulNameContractNotSet()
```






### ZeroAddress

```solidity
Expand Down
11 changes: 11 additions & 0 deletions docs/dex/PaymentGateway.md
Expand Up @@ -337,6 +337,17 @@ event OwnershipTransferred(address indexed previousOwner, address indexed newOwn

## Errors

### AlreadyAdded

```solidity
error AlreadyAdded()
```






### SameValue

```solidity
Expand Down
11 changes: 11 additions & 0 deletions docs/tokens/MasaSBTSelfSovereign.md
Expand Up @@ -886,6 +886,17 @@ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed

## Errors

### AlreadyAdded

```solidity
error AlreadyAdded()
```






### InvalidPaymentMethod

```solidity
Expand Down
6 changes: 3 additions & 3 deletions test/SoulboundCreditScore.test.ts
Expand Up @@ -219,7 +219,7 @@ describe("Soulbound Credit Score", () => {
signatureDate,
signature
)
).to.be.revertedWith("CREDITSCORE_ALREADY_CREATED");
).to.be.revertedWith("CreditScoreAlreadyCreated");

expect(await soulboundCreditScore.totalSupply()).to.equal(1);
expect(await soulboundCreditScore.tokenByIndex(0)).to.equal(0);
Expand Down Expand Up @@ -279,7 +279,7 @@ describe("Soulbound Credit Score", () => {
signatureDate,
signatureNonAuthority
)
).to.be.revertedWith("NOT_AUTHORIZED");
).to.be.revertedWith("NotAuthorized");
});

it("should fail to mint with invalid signature", async () => {
Expand All @@ -298,7 +298,7 @@ describe("Soulbound Credit Score", () => {
signatureDate,
signatureNonAuthority
)
).to.be.revertedWith("INVALID_SIGNATURE");
).to.be.revertedWith("InvalidSignature");
});
});

Expand Down

0 comments on commit 6741872

Please sign in to comment.