Skip to content

Commit dc41baa

Browse files
Michał SieczkowskiMichał Sieczkowski
andauthored
📦 Introduce subpackage for Proof Of Reserve feature development (#1189)
Co-authored-by: Michał Sieczkowski <[email protected]>
1 parent 9215ad2 commit dc41baa

15 files changed

+2360
-37
lines changed

.eslintignore

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

package.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
"name": "trusttoken-smart-contracts",
33
"version": "2.0.0",
44
"description": "TrueFi and True Currency Smart Contracts",
5+
"private": true,
6+
"workspaces": [
7+
"packages/*"
8+
],
59
"scripts": {
610
"postinstall": "patch-package",
711
"flatten": "./flatten.sh",
@@ -42,9 +46,14 @@
4246
"slither": "./slither.sh",
4347
"coverage": "bash ./runCoverage.sh"
4448
},
45-
"author": "",
4649
"license": "SEE LICENSE IN LICENSE.md",
4750
"devDependencies": {
51+
"@ethersproject/abi": "5.0.7",
52+
"@ethersproject/constants": "5.0.5",
53+
"@ethersproject/keccak256": "5.0.4",
54+
"@ethersproject/providers": "5.0.13",
55+
"@ethersproject/strings": "5.0.5",
56+
"@ethersproject/units": "5.0.6",
4857
"@typechain/ethers-v5": "^6.0.5",
4958
"@types/chai": "^4.2.11",
5059
"@types/mocha": "^7.0.2",
@@ -85,8 +94,6 @@
8594
"web3": "1.2.4"
8695
},
8796
"resolutions": {
88-
"ethereum-waffle/**/ganache-core": "^2.13.0",
89-
"@ethereum-waffle/provider/ganache-core": "^2.13.0",
9097
"**/@resolver-engine/core": "^0.3.3"
9198
}
9299
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"version": "0.8.16",
3+
"settings": {
4+
"optimizer": {
5+
"enabled": true,
6+
"runs": 200
7+
}
8+
}
9+
}

packages/contracts-por/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
/build
3+
/cache
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"require": ["ts-node/register/transpile-only", "tsconfig-paths/register"],
3+
"extension": ["ts"],
4+
"target": "esnext",
5+
"timeout": 40000,
6+
"watch-files": ["test"],
7+
"exit": true
8+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const { extendConfig } = require('hardhat/config')
4+
5+
const { HardhatPluginError } = require('hardhat/plugins')
6+
7+
const {
8+
TASK_COMPILE,
9+
} = require('hardhat/builtin-tasks/task-names')
10+
11+
extendConfig(function (config, userConfig) {
12+
config.abiExporter = Object.assign(
13+
{
14+
path: './abi',
15+
clear: false,
16+
flat: false,
17+
only: [],
18+
except: [],
19+
spacing: 2,
20+
},
21+
userConfig.abiExporter,
22+
)
23+
})
24+
25+
task(TASK_COMPILE, async function (args, hre, runSuper) {
26+
const config = hre.config.abiExporter
27+
28+
await runSuper()
29+
30+
const outputDirectory = path.resolve(hre.config.paths.root, config.path)
31+
32+
if (!outputDirectory.startsWith(hre.config.paths.root)) {
33+
throw new HardhatPluginError('resolved path must be inside of project directory')
34+
}
35+
36+
if (outputDirectory === hre.config.paths.root) {
37+
throw new HardhatPluginError('resolved path must not be root directory')
38+
}
39+
40+
if (config.clear) {
41+
if (fs.existsSync(outputDirectory)) {
42+
fs.rmdirSync(outputDirectory, { recursive: true })
43+
}
44+
}
45+
46+
if (!fs.existsSync(outputDirectory)) {
47+
fs.mkdirSync(outputDirectory, { recursive: true })
48+
}
49+
50+
for (const fullName of await hre.artifacts.getAllFullyQualifiedNames()) {
51+
if (config.only.length && !config.only.some(m => fullName.match(m))) continue
52+
if (config.except.length && config.except.some(m => fullName.match(m))) continue
53+
54+
const { abi, sourceName, contractName, bytecode, deployedBytecode } = await hre.artifacts.readArtifact(fullName)
55+
56+
if (!abi.length) continue
57+
58+
const destination = path.resolve(
59+
outputDirectory,
60+
config.flat ? '' : sourceName,
61+
contractName,
62+
) + '.json'
63+
64+
if (!fs.existsSync(path.dirname(destination))) {
65+
fs.mkdirSync(path.dirname(destination), { recursive: true })
66+
}
67+
68+
fs.writeFileSync(destination, `${JSON.stringify({ abi, bytecode, deployedBytecode }, null, config.spacing)}\n`, { flag: 'w' })
69+
}
70+
})
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.16;
3+
4+
contract DummyContract {
5+
uint256 private value = 5;
6+
7+
function getValue() public view returns (uint256) {
8+
return value;
9+
}
10+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import '@typechain/hardhat'
2+
import '@nomiclabs/hardhat-waffle'
3+
import './abi-exporter'
4+
5+
import compiler from './.compiler.json'
6+
7+
module.exports = {
8+
paths: {
9+
sources: './contracts',
10+
artifacts: './build',
11+
cache: './cache',
12+
},
13+
abiExporter: {
14+
path: './build',
15+
flat: true,
16+
spacing: 2,
17+
},
18+
networks: {
19+
hardhat: {
20+
allowUnlimitedContractSize: true,
21+
},
22+
},
23+
typechain: {
24+
outDir: 'build/types',
25+
target: 'ethers-v5',
26+
},
27+
solidity: {
28+
compilers: [compiler],
29+
},
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "@trusttoken-smart-contracts/contracts-por",
3+
"version": "0.0.1",
4+
"description": "Updates to TUSD contracts for Proof of Reserve feature",
5+
"private": true,
6+
"scripts": {
7+
"clean": "rm -rf ./build && hardhat clean",
8+
"build:hardhat": "hardhat compile",
9+
"build:typechain": "typechain --target ethers-v5 --out-dir build/types 'build/*.json'",
10+
"build": "yarn clean && yarn build:hardhat && yarn build:typechain && mars",
11+
"test": "mocha 'test/**/*.test.ts'"
12+
},
13+
"dependencies": {
14+
"ethereum-mars": "0.2.5"
15+
},
16+
"devDependencies": {
17+
"@ethersproject/abi": "^5.7.0",
18+
"@ethersproject/bytes": "^5.7.0",
19+
"@ethersproject/providers": "^5.7.0",
20+
"@nomiclabs/hardhat-waffle": "^2.0.3",
21+
"@typechain/ethers-v5": "^10.0.0",
22+
"@typechain/hardhat": "^6.0.0",
23+
"@types/chai": "^4.3.3",
24+
"@types/mocha": "^9.1.1",
25+
"@types/node": "^17.0.34",
26+
"chai": "^4.3.6",
27+
"ethereum-waffle": "4.0.7",
28+
"ethers": "^5.7.0",
29+
"hardhat": "~2.10.2",
30+
"mocha": "^10.0.0",
31+
"solc": "0.8.16",
32+
"ts-node": "^10.7.0",
33+
"tsconfig-paths": "^4.1.0",
34+
"typechain": "^8.0.0",
35+
"typescript": "4.5.4"
36+
}
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { expect, use } from 'chai'
2+
import { solidity } from 'ethereum-waffle'
3+
import { setupFixtureLoader } from './setup'
4+
import { dummyContractFixture } from 'fixtures/dummyContractFixture'
5+
6+
use(solidity)
7+
8+
describe('DummyContract', () => {
9+
const loadFixture = setupFixtureLoader()
10+
11+
it('should have a constructor', async () => {
12+
const { dummyContract } = await loadFixture(dummyContractFixture)
13+
expect(await dummyContract.getValue()).to.eq(5)
14+
})
15+
})

0 commit comments

Comments
 (0)