Skip to content

Commit

Permalink
Merge pull request #39 from TomAFrench/typescript
Browse files Browse the repository at this point in the history
migration to TypeScript
  • Loading branch information
TomAFrench authored Apr 8, 2020
2 parents 412123b + 43f136b commit 5a62ac7
Show file tree
Hide file tree
Showing 90 changed files with 2,307 additions and 2,031 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ yarn-error.log*
# subgraph
/packages/subgraph/build/
/packages/subgraph/src/types/

# now
.now
4 changes: 2 additions & 2 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
presets: [
[
'@babel/preset-env',
'@babel/preset-typescript',
['@babel/preset-env',
{
targets: {
node: 'current',
Expand Down
40 changes: 40 additions & 0 deletions packages/contract-artifacts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module.exports = {
"env": {
"es6": true,
"browser": true
},
"extends": [
'eslint:recommended',
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"prettier/@typescript-eslint", // Uses eslint-config-prettier to disable ESLint rules from @typescript-eslint/eslint-plugin that would conflict with prettier
"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.
],
// "ignorePatterns": [],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json",
"tsconfigRootDir": __dirname,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
],
"rules": {
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"ts": "never"
}
]
},
"settings": {
'import/resolver': {
node: {
extensions: ['.js', '.ts']
},
},
}
};
1 change: 1 addition & 0 deletions packages/contract-artifacts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
},
{
"internalType": "bytes32",
"name": "currentBalance",
"name": "noteHash",
"type": "bytes32"
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/contract-artifacts/addresses/rinkeby.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"ACE": "0x065178E11D516D115eA9437336f8d1bF4178f48c",
"AztecStreamer": "0x15b1E0446b3f96C2C49Aa2d4E280f4613082449E"
"NoteStream": "0xCcb98Efa4eA6a3814ece095f73264c43D7D50071"
}
47 changes: 0 additions & 47 deletions packages/contract-artifacts/lib/index.js

This file was deleted.

18 changes: 9 additions & 9 deletions packages/contract-artifacts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
"bugs": {
"url": "https://github.com/TomAFrench/NoteStream/issues"
},
"dependencies": {
"lodash": "^4.17.11"
},
"dependencies": {},
"devDependencies": {
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.0",
"@babel/plugin-proposal-object-rest-spread": "^7.4.0",
"@babel/preset-env": "^7.4.2",
"@babel/preset-env": "^7.9.0",
"@babel/preset-typescript": "^7.9.0",
"eslint": "^5.15.3",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^6.0.0",
Expand Down Expand Up @@ -44,11 +43,12 @@
"url": "git+https://github.com/TomAFrench/NoteStream.git"
},
"scripts": {
"build:dev": "yarn clean && babel --copy-files --out-dir ./lib --root-mode upward ./src",
"build": "yarn clean && babel --copy-files --out-dir ./lib --root-mode upward ./src",
"build:prod": "yarn build",
"prepare": "yarn clean && yarn lint --fix",
"build": "yarn prepare && yarn build:types && yarn build:js",
"build:js": " babel src --out-dir lib --extensions '.ts,.tsx' --root-mode upward ./src",
"build:types": "tsc --emitDeclarationOnly",
"clean": "shx rm -rf ./lib",
"lint": "eslint --ignore-path ../../.eslintignore .",
"watch": "yarn build:dev --watch"
"lint": "eslint --config .eslintrc.js --ext .js,.ts . ",
"watch": "yarn build --watch"
}
}
33 changes: 0 additions & 33 deletions packages/contract-artifacts/src/index.js

This file was deleted.

37 changes: 37 additions & 0 deletions packages/contract-artifacts/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import NoteStreamABI from "../abis/NoteStream.json";
// import mainnetAddresses from "./addresses/mainnet";
import rinkebyAddresses from "../addresses/rinkeby.json";

export type Address = string;

export interface Deployment {
ACE: Address;
NoteStream: Address;
}

export const abis: object = {
NoteStream: NoteStreamABI,
};

/**
* Used to get addresses of contracts that have been deployed to either the
* Ethereum mainnet or a supported testnet. Throws if there are no known
* contracts deployed on the corresponding network.
* @param networkId The desired networkId.
* @returns The set of addresses for contracts which have been deployed on the
* given networkId.
*/
export const getContractAddressesForNetwork = (
networkId: number
): Deployment => {
switch (networkId) {
// case 1:
// return mainnetAddresses;
case 4:
return rinkebyAddresses;
default:
throw new Error(
`Unknown network id (${networkId}). No known NoteStream contracts have been deployed on this network.`
);
}
};
28 changes: 28 additions & 0 deletions packages/contract-artifacts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"compilerOptions": {
/* Basic Options */
"lib": [
"ES2015",
"DOM"
],
"module": "ES2015",
"outDir": "lib",
"sourceMap": true,
"target": "ES2015",
"declaration": true,
/* Strict Type-Checking Options */
"noImplicitAny": true,
"strict": true,
/* Module Resolution Options */
"esModuleInterop": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"skipLibCheck": false,
/* Advanced Options */
"forceConsistentCasingInFileNames": true,
},
"include": [
"./src/**/*",
"./lib/**/*"
]
}
20 changes: 20 additions & 0 deletions packages/contracts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
"env": {
"es6": true,
},
"extends": [
'eslint:recommended',
"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.
],
"rules": {
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"ts": "never"
}
],
"import/no-extraneous-dependencies": ["error", {"devDependencies": ["**/*.js"]}]
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "./Types.sol";
* @title NoteStream's Money Streaming
* @author NoteStream
*/
contract AztecStreamer is ReentrancyGuard {
contract NoteStream is ReentrancyGuard {
using SafeMath for uint256;

/*** Storage Properties ***/
Expand Down Expand Up @@ -114,7 +114,7 @@ contract AztecStreamer is ReentrancyGuard {
returns (
address sender,
address recipient,
bytes32 currentBalance,
bytes32 noteHash,
address tokenAddress,
uint256 startTime,
uint256 lastWithdrawTime,
Expand All @@ -123,7 +123,7 @@ contract AztecStreamer is ReentrancyGuard {
{
sender = streams[streamId].sender;
recipient = streams[streamId].recipient;
currentBalance = streams[streamId].currentBalance;
noteHash = streams[streamId].noteHash;
tokenAddress = address(streams[streamId].tokenAddress);
startTime = streams[streamId].startTime;
lastWithdrawTime = streams[streamId].lastWithdrawTime;
Expand Down Expand Up @@ -168,7 +168,7 @@ contract AztecStreamer is ReentrancyGuard {
/* Create and store the stream object. */
uint256 streamId = nextStreamId;
streams[streamId] = Types.AztecStream({
currentBalance: noteHash,
noteHash: noteHash,
sender: msg.sender,
recipient: recipient,
startTime: startTime,
Expand Down Expand Up @@ -220,15 +220,15 @@ contract AztecStreamer is ReentrancyGuard {

// Check that withdrawal transaction is valid and perform transfer
// i.e. change note remains on contract, sender and recipient have view access, etc.
bytes32 newCurrentBalanceNoteHash = StreamUtilities._processWithdrawal(
bytes32 newNoteHash = StreamUtilities._processWithdrawal(
aceContractAddress,
_proof2,
_proof1OutputNotes,
stream
);

// Update stream information
stream.currentBalance = newCurrentBalanceNoteHash;
stream.noteHash = newNoteHash;
stream.lastWithdrawTime = stream.lastWithdrawTime.add(
_streamDurationToWithdraw
);
Expand All @@ -237,7 +237,7 @@ contract AztecStreamer is ReentrancyGuard {
streamId,
stream.sender,
stream.recipient,
newCurrentBalanceNoteHash,
newNoteHash,
_streamDurationToWithdraw
);
}
Expand Down
Loading

1 comment on commit 5a62ac7

@vercel
Copy link

@vercel vercel bot commented on 5a62ac7 Apr 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.