Skip to content

Commit 5a62ac7

Browse files
authored
Merge pull request #39 from TomAFrench/typescript
migration to TypeScript
2 parents 412123b + 43f136b commit 5a62ac7

Some content is hidden

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

90 files changed

+2307
-2031
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,6 @@ yarn-error.log*
2323
# subgraph
2424
/packages/subgraph/build/
2525
/packages/subgraph/src/types/
26+
27+
# now
28+
.now

babel.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module.exports = {
22
presets: [
3-
[
4-
'@babel/preset-env',
3+
'@babel/preset-typescript',
4+
['@babel/preset-env',
55
{
66
targets: {
77
node: 'current',
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module.exports = {
2+
"env": {
3+
"es6": true,
4+
"browser": true
5+
},
6+
"extends": [
7+
'eslint:recommended',
8+
"plugin:@typescript-eslint/recommended",
9+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
10+
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
11+
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
12+
],
13+
// "ignorePatterns": [],
14+
"parser": "@typescript-eslint/parser",
15+
"parserOptions": {
16+
"project": "./tsconfig.json",
17+
"tsconfigRootDir": __dirname,
18+
"sourceType": "module"
19+
},
20+
"plugins": [
21+
"@typescript-eslint",
22+
],
23+
"rules": {
24+
"import/extensions": [
25+
"error",
26+
"ignorePackages",
27+
{
28+
"js": "never",
29+
"ts": "never"
30+
}
31+
]
32+
},
33+
"settings": {
34+
'import/resolver': {
35+
node: {
36+
extensions: ['.js', '.ts']
37+
},
38+
},
39+
}
40+
};
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib

packages/contract-artifacts/abis/AztecStreamer.json renamed to packages/contract-artifacts/abis/NoteStream.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
},
229229
{
230230
"internalType": "bytes32",
231-
"name": "currentBalance",
231+
"name": "noteHash",
232232
"type": "bytes32"
233233
},
234234
{
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"ACE": "0x065178E11D516D115eA9437336f8d1bF4178f48c",
3-
"AztecStreamer": "0x15b1E0446b3f96C2C49Aa2d4E280f4613082449E"
3+
"NoteStream": "0xCcb98Efa4eA6a3814ece095f73264c43D7D50071"
44
}

packages/contract-artifacts/lib/index.js

-47
This file was deleted.

packages/contract-artifacts/package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
"bugs": {
77
"url": "https://github.com/TomAFrench/NoteStream/issues"
88
},
9-
"dependencies": {
10-
"lodash": "^4.17.11"
11-
},
9+
"dependencies": {},
1210
"devDependencies": {
1311
"@babel/cli": "^7.4.3",
1412
"@babel/core": "^7.4.0",
1513
"@babel/plugin-proposal-object-rest-spread": "^7.4.0",
16-
"@babel/preset-env": "^7.4.2",
14+
"@babel/preset-env": "^7.9.0",
15+
"@babel/preset-typescript": "^7.9.0",
1716
"eslint": "^5.15.3",
1817
"eslint-config-airbnb-base": "^13.1.0",
1918
"eslint-config-prettier": "^6.0.0",
@@ -44,11 +43,12 @@
4443
"url": "git+https://github.com/TomAFrench/NoteStream.git"
4544
},
4645
"scripts": {
47-
"build:dev": "yarn clean && babel --copy-files --out-dir ./lib --root-mode upward ./src",
48-
"build": "yarn clean && babel --copy-files --out-dir ./lib --root-mode upward ./src",
49-
"build:prod": "yarn build",
46+
"prepare": "yarn clean && yarn lint --fix",
47+
"build": "yarn prepare && yarn build:types && yarn build:js",
48+
"build:js": " babel src --out-dir lib --extensions '.ts,.tsx' --root-mode upward ./src",
49+
"build:types": "tsc --emitDeclarationOnly",
5050
"clean": "shx rm -rf ./lib",
51-
"lint": "eslint --ignore-path ../../.eslintignore .",
52-
"watch": "yarn build:dev --watch"
51+
"lint": "eslint --config .eslintrc.js --ext .js,.ts . ",
52+
"watch": "yarn build --watch"
5353
}
5454
}

packages/contract-artifacts/src/index.js

-33
This file was deleted.
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import NoteStreamABI from "../abis/NoteStream.json";
2+
// import mainnetAddresses from "./addresses/mainnet";
3+
import rinkebyAddresses from "../addresses/rinkeby.json";
4+
5+
export type Address = string;
6+
7+
export interface Deployment {
8+
ACE: Address;
9+
NoteStream: Address;
10+
}
11+
12+
export const abis: object = {
13+
NoteStream: NoteStreamABI,
14+
};
15+
16+
/**
17+
* Used to get addresses of contracts that have been deployed to either the
18+
* Ethereum mainnet or a supported testnet. Throws if there are no known
19+
* contracts deployed on the corresponding network.
20+
* @param networkId The desired networkId.
21+
* @returns The set of addresses for contracts which have been deployed on the
22+
* given networkId.
23+
*/
24+
export const getContractAddressesForNetwork = (
25+
networkId: number
26+
): Deployment => {
27+
switch (networkId) {
28+
// case 1:
29+
// return mainnetAddresses;
30+
case 4:
31+
return rinkebyAddresses;
32+
default:
33+
throw new Error(
34+
`Unknown network id (${networkId}). No known NoteStream contracts have been deployed on this network.`
35+
);
36+
}
37+
};
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"compilerOptions": {
3+
/* Basic Options */
4+
"lib": [
5+
"ES2015",
6+
"DOM"
7+
],
8+
"module": "ES2015",
9+
"outDir": "lib",
10+
"sourceMap": true,
11+
"target": "ES2015",
12+
"declaration": true,
13+
/* Strict Type-Checking Options */
14+
"noImplicitAny": true,
15+
"strict": true,
16+
/* Module Resolution Options */
17+
"esModuleInterop": true,
18+
"moduleResolution": "node",
19+
"resolveJsonModule": true,
20+
"skipLibCheck": false,
21+
/* Advanced Options */
22+
"forceConsistentCasingInFileNames": true,
23+
},
24+
"include": [
25+
"./src/**/*",
26+
"./lib/**/*"
27+
]
28+
}

packages/contracts/.eslintrc.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = {
2+
"env": {
3+
"es6": true,
4+
},
5+
"extends": [
6+
'eslint:recommended',
7+
"plugin:prettier/recommended" // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
8+
],
9+
"rules": {
10+
"import/extensions": [
11+
"error",
12+
"ignorePackages",
13+
{
14+
"js": "never",
15+
"ts": "never"
16+
}
17+
],
18+
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.js"]}]
19+
},
20+
}

packages/contracts/contracts/AztecStreamer.sol renamed to packages/contracts/contracts/NoteStream.sol

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import "./Types.sol";
1111
* @title NoteStream's Money Streaming
1212
* @author NoteStream
1313
*/
14-
contract AztecStreamer is ReentrancyGuard {
14+
contract NoteStream is ReentrancyGuard {
1515
using SafeMath for uint256;
1616

1717
/*** Storage Properties ***/
@@ -114,7 +114,7 @@ contract AztecStreamer is ReentrancyGuard {
114114
returns (
115115
address sender,
116116
address recipient,
117-
bytes32 currentBalance,
117+
bytes32 noteHash,
118118
address tokenAddress,
119119
uint256 startTime,
120120
uint256 lastWithdrawTime,
@@ -123,7 +123,7 @@ contract AztecStreamer is ReentrancyGuard {
123123
{
124124
sender = streams[streamId].sender;
125125
recipient = streams[streamId].recipient;
126-
currentBalance = streams[streamId].currentBalance;
126+
noteHash = streams[streamId].noteHash;
127127
tokenAddress = address(streams[streamId].tokenAddress);
128128
startTime = streams[streamId].startTime;
129129
lastWithdrawTime = streams[streamId].lastWithdrawTime;
@@ -168,7 +168,7 @@ contract AztecStreamer is ReentrancyGuard {
168168
/* Create and store the stream object. */
169169
uint256 streamId = nextStreamId;
170170
streams[streamId] = Types.AztecStream({
171-
currentBalance: noteHash,
171+
noteHash: noteHash,
172172
sender: msg.sender,
173173
recipient: recipient,
174174
startTime: startTime,
@@ -220,15 +220,15 @@ contract AztecStreamer is ReentrancyGuard {
220220

221221
// Check that withdrawal transaction is valid and perform transfer
222222
// i.e. change note remains on contract, sender and recipient have view access, etc.
223-
bytes32 newCurrentBalanceNoteHash = StreamUtilities._processWithdrawal(
223+
bytes32 newNoteHash = StreamUtilities._processWithdrawal(
224224
aceContractAddress,
225225
_proof2,
226226
_proof1OutputNotes,
227227
stream
228228
);
229229

230230
// Update stream information
231-
stream.currentBalance = newCurrentBalanceNoteHash;
231+
stream.noteHash = newNoteHash;
232232
stream.lastWithdrawTime = stream.lastWithdrawTime.add(
233233
_streamDurationToWithdraw
234234
);
@@ -237,7 +237,7 @@ contract AztecStreamer is ReentrancyGuard {
237237
streamId,
238238
stream.sender,
239239
stream.recipient,
240-
newCurrentBalanceNoteHash,
240+
newNoteHash,
241241
_streamDurationToWithdraw
242242
);
243243
}

0 commit comments

Comments
 (0)