Skip to content

Commit dd8bf5e

Browse files
committed
Publication of the new version
1 parent 134b00d commit dd8bf5e

66 files changed

Lines changed: 161624 additions & 26215 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.env.sample

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
PRIVATE_KEY=
22
INFURA_KEY=
3-
REGISTRAR=
3+
ETHERSCAN_API_KEY=
4+
EXAION_KEY=

.github/pull_request_template.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

.gitignore

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
/node_modules
22
/dist/
3-
/buid/
4-
.env
3+
4+
node_modules
5+
.env
6+
coverage
7+
coverage.json
8+
typechain
9+
typechain-types
10+
11+
# Hardhat files
12+
cache
13+
artifacts
14+
15+
.vscode/
16+
reports/
17+
.openzeppelin

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16.15.0

.solcover.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module.exports = {
2+
skipFiles: ['openzeppelin/utils/Context.sol', 'testContracts/'],
3+
istanbulFolder: 'reports',
4+
istanbulReporter: ['text', 'json-summary', 'cobertura', 'lcov'],
5+
limits: {
6+
statements: 100,
7+
branches: 99.43,
8+
functions: 100,
9+
lines: 100
10+
},
11+
};

.solhint.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"avoid-throw": "off",
66
"avoid-suicide": "error",
77
"avoid-sha3": "warn",
8-
"compiler-version": ["error", "0.8.17"]
8+
"ordering": "error",
9+
"compiler-version": ["error", "0.8.17"],
10+
"func-visibility": ["warn",{"ignoreConstructors":true}]
911
},
1012
"plugins": ["prettier"]
1113
}

README.md

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,69 @@
44

55
# Description
66

7-
Smartcoin is a token that aims to be used by whitelisted entities.
7+
The SmartCoin contract is basically an ERC20 with a few specifics
88

9-
The Registrar is responsible for whitelisting elegible entities.
9+
The Registrar is responsible for managing elegible entities.
1010

11-
The Registrar is also responsible for mint, burn, recall.
12-
13-
A modified version of ERC-20 transfers is used, which requires the approval of the Registrar.
11+
The Registrar is also responsible for freeze addresses, unfreeze addresses, mint, burn and wipe frozen addresses.
12+
13+
## Transfer to the Special Entities
14+
15+
A modified version of ERC-20 transfers is used, transfers to the specials entities (i.e. registrar and operations) are restricted.
16+
Only direct transfer can be made, they cannot be the destination of an approve or a transferFrom.
17+
When the transfer function is called with thoses entities as destination a transfer request is emited.
18+
Tokens will not be transfer until the registrar validate that transfer request.
19+
Until the registrar validate or reject the request, tokens are "engaged".
20+
While engaged, tokens cannot be moved from the holder balance.
21+
22+
## Contract and Operator Upgrades
23+
24+
The implementation upgrade and operator upgrade are tied.
25+
For the operator to be well regulated, token transaction to/from them are restricted.
26+
This mean that for each transaction (transfer/approve/transferFrom) checks are to be performed.
27+
The goal of this is to lower gas cost of those checks, by storing the operator in the bytecode, while keeping a secure way to update the Operators.
28+
29+
The main step to perform an upgrade are :
30+
31+
- Registrar name the next Operators
32+
- Each operator accept the role
33+
- The actual Technical deploy a new contract
34+
- The actual Registrar authorize the update to the new contract
35+
- The actual Technical launch the UpgradeTo fonction
36+
- The upgrade to function check each operator is Ok, then upgrade is performed
37+
38+
### Sequence Diagram
39+
```mermaid
40+
sequenceDiagram
41+
autonumber
42+
actor OldRegistrar
43+
actor NewOperators
44+
actor OldTechnicalOperator
45+
box gray SmartCoin
46+
participant Proxy
47+
participant OldImpl
48+
participant NewImpl
49+
end
50+
OldRegistrar ->> Proxy : NameNewOperator
51+
Proxy ->> OldImpl : Fw:NameNewOperator
52+
NewOperators ->> Proxy : n*AcceptRole
53+
Proxy ->> OldImpl : Fw:n*AcceptRole
54+
OldTechnicalOperator ->> NewImpl : Deploy With New Operators as Immutable field
55+
critical AuthorizeUpgrade
56+
OldRegistrar ->> Proxy : AuthorizeUpgradeTo(newImplAddress)
57+
Proxy ->> OldImpl : Fw:AuthorizeUpgradeTo(newImplAddress)
58+
OldImpl ->> NewImpl : getOperators
59+
OldImpl ->> OldImpl : validateOperatorsMatchAndHaveAccepted
60+
end
61+
critical UpgradeTo Transaction
62+
OldTechnicalOperator ->> Proxy : UpgradeTo
63+
Proxy ->> OldImpl : Fw: UpgradeTo
64+
OldImpl ->> OldImpl: onlyAuthorizedImplementation
65+
OldImpl ->> OldImpl : _authorizeUpgrade
66+
OldImpl ->> OldImpl : SetImpl
67+
OldImpl ->> OldImpl : Reset Upgrade Operators and Authorization (storage)
68+
end
69+
```
1470

1571
# Pre-requisites
1672

@@ -23,7 +79,7 @@ Configure an environment file `.env` using the example seen in `env.sample`
2379
Install the package dependencies via `npm install`
2480
Compile the project via `npm run build`
2581

26-
Deployment is done via truffle by supplying a network to the `deploy` command as follows: `npm run deploy -- --network sepolia`
82+
Deployment is done via hardhat by supplying a network to the `deploy` command as follows: `npm run deploy -- --network sepolia`
2783

2884
Unit tests can be run via `npm run test`, and code linting can be performed via `npm run lint`
2985

__snapshots__/dataLayout.snapshot.js

Lines changed: 148419 additions & 0 deletions
Large diffs are not rendered by default.

check-coverage-limit.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const path = require('path');
2+
const fs = require('fs');
3+
4+
const solcoverConfig = require('./.solcover.js');
5+
6+
const jsonSummaryFilePath = path.join(solcoverConfig.istanbulFolder, 'coverage-summary.json');
7+
const coverage = JSON.parse(fs.readFileSync(jsonSummaryFilePath, 'utf8'));
8+
const globalCoverage = coverage.total;
9+
10+
Object
11+
.entries(solcoverConfig.limits)
12+
.forEach(
13+
([key, limitValue]) => {
14+
const coverageForKey = globalCoverage[key];
15+
16+
if(coverageForKey === undefined){
17+
console.error(`Unknown key [${key}] valid key are [${Object.keys(globalCoverage)}]`);
18+
process.exit(2);
19+
}
20+
21+
const coveragePercentageForKey = coverageForKey.pct;
22+
23+
if(coveragePercentageForKey < limitValue){
24+
console.error(`Target limit for ${key} not reach expected ${limitValue} is ${coveragePercentageForKey}`)
25+
process.exit(1);
26+
}
27+
}
28+
)
29+
30+
console.log('Coverage limit are in set boundary');
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//export NEW_SMARTCOIN_IMPLEMENTATION_JSON_CONFIG='
2+
{
3+
"NewOperatorsAddress":{
4+
"Registrar": "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
5+
"Operation": "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c",
6+
"Technical": "0x1aBaEA1f7C830bD89Acc67eC4af516284b1bC33c"
7+
},
8+
"Contracts":{
9+
"ImplementationArtifactName": "SmartCoin"
10+
},
11+
"OutputFolder": "dist/"
12+
}
13+
//'

0 commit comments

Comments
 (0)