Skip to content

Commit

Permalink
Typescript Refactor (#22)
Browse files Browse the repository at this point in the history
* feat: setup typescript

* feat: update errors to .ts

* feat: update gm test to .ts

* feat: update prettierrc to typescript

* feat: include eslintrc

* feat: start gm.ts

* feat: add and test gm constructor

* style: lint

* feat: add webpack bundling and lint on precommit

* feat: use ganache core for websocket server

* feat: set accounts and tx sender

* feat: use colon in npm script commands

* feat: unlock account

* feat: add contract library installer binary

* fix: pass array into contract installer

* docs: add instructions for installer

* docs: update test command

* feat: remove and ignore build dir

* feat: implement execute

* feat: test execute and unlock account without password

* feat: update test script and use refactored ganache

* feat: update build scripts

* fix: replace contracts with contract-library

* feat: add gm ping

* feat: add maker protocol

* feat: use caip networks and update errors

* refactor: move execute method and set default from

* feat: add mint dai convenience method

* fix: set default from

* fix: get address by contract name

* fix: return status from mintDai

* fix: throw if contract for method is not installed

* refactor: install protocols instead of individual contracts

* feat: add protocols to gm

* fix: add preset protocols to gm instances

* fix: use call for constant functions

* fix: import from utils instead of contracts

* feat: update license to 2021

* feat: update package json

* feat: throw if websocket is not open

* fix: update mintCErc20

* feat: remove truffle config

* test: update tests

* feat: add byte length util

* fmt: clean comments

* feat: clean up package scripts and ganache dep

* fmt: use 2 spaces for package.json

and ignore from prettier

* fix: update package lock

* feat: log websocket in debug mode and update test

* feat: clean up types

* feat: update release it

and delete whitespace

* feat: update types and lint

* fix: update godmode-ganache-core without branch

* feat: update package lock
  • Loading branch information
v-stickykeys authored Feb 14, 2021
1 parent 3e86239 commit 2f85134
Show file tree
Hide file tree
Showing 76 changed files with 16,768 additions and 3,285,310 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'prettier/@typescript-eslint',
'plugin:prettier/recommended', // Display prettier errors as ESLint errors. Must be last in the extends array.
],
};
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules
.env
dist
build
.vscode
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build
contracts
node_modules
dist
package*.json
16 changes: 8 additions & 8 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"trailingComma": "es5",
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
"trailingComma": "es5",
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": true,
"bracketSpacing": true,
"arrowParens": "always",
"endOfLine": "lf"
}
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 XGM
Copyright (c) 2021 XGM Studio

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
69 changes: 49 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ You will also need to [install truffle](https://www.npmjs.com/package/truffle) s

When using this library, you need to run GodMode ganache as well.

- [GODMODE Ganache-cli](https://github.com/xGodMode/godmode-ganache-cli)
- [GODMODE Ganache-core](https://github.com/xGodMode/godmode-ganache-core)
- [GODMODE Ganache-cli](https://github.com/xGodMode/godmode-ganache-cli)
- [GODMODE Ganache-core](https://github.com/xGodMode/godmode-ganache-core)

To see a sample project that uses this library, see this repo:

- [GODMODE Sample Project](https://github.com/xGodMode/godmode-sample-project)
- [GODMODE Sample Project](https://github.com/xGodMode/godmode-sample-project)

### Setting it up in the test environment

Expand All @@ -45,44 +45,73 @@ let GODMODE = new GM('development', 'ws://localhost:8545');

```javascript
await GODMODE.executeAs(
targetContract,
replacementContractArtifact,
'function_In_RC',
/* some arguments for the function */
{ from: Bob } // Transaction meta info
targetContract,
replacementContractArtifact,
'function_In_RC',
/* some arguments for the function */
{ from: Bob } // Transaction meta info
);
```

Variable explanation:

- `targetContract` is the deployed contract, for example:
- the `hasOwnerShipContract` in `hasOwnerShipContract = await HasOwnerShip.new({ from: Alice });`.
- `replacementContractArtifact` is the contract artifact produced by truffle, for example:
- the `HasOwnerShipInstrumented` in `const HasOwnerShipInstrumented = artifacts.require("HasOwnerShipInstrumented");`
- `function_In_RC` is the function that was defined in the replacementContractArtifact.
- `targetContract` is the deployed contract, for example:
- the `hasOwnerShipContract` in `hasOwnerShipContract = await HasOwnerShip.new({ from: Alice });`.
- `replacementContractArtifact` is the contract artifact produced by truffle, for example:
- the `HasOwnerShipInstrumented` in `const HasOwnerShipInstrumented = artifacts.require("HasOwnerShipInstrumented");`
- `function_In_RC` is the function that was defined in the replacementContractArtifact.

### With pre-compiled contracts
### Install pre-compiled protocol contracts

**IMPORTANT: this only works on mainnet fork**

When you install a protocol, all of the contracts for that protocol will be stored in your `build/protocols` directory.

- Install all GM protocols

```sh
npx godmode install --all
```

- Install protocols from command line

```
npx godmode install --protocols Maker Compound
```

- Install protocols from package.json

```json
"godmode": {
"protocols": [
"Maker",
"Compound"
]
}
```

```
npx godmode install
```

#### MakerDao

- Mint DAI to an address: `await GODMODE.mintDai(Bob, 10000);`
- Mint DAI to an address: `await GODMODE.mintDai(Bob, 10000);`

#### Uniswap

- Enable Fee collection in UniswapV2: `await GODMODE.uniswapV2Factory_setFeeTo(Bob);`
- Enable Fee collection in UniswapV2: `await GODMODE.uniswapV2Factory_setFeeTo(Bob);`

#### Compound

- Give the address cTokens: `await GODMODE.CToken_giveAddrTokens("0x6c8c6b02e7b2be14d4fa6022dfd6d75921d90e4e", Bob, 100); `
- Give the address cTokens: `await GODMODE.CToken_giveAddrTokens("0x6c8c6b02e7b2be14d4fa6022dfd6d75921d90e4e", Bob, 100); `

## Testing

Tests are written in [mocha](https://mochajs.org/).

Test the core GM class with `npm run test-core`.
Test GM contract interactions with `npm run test-contracts`.
Test the core GM class with `npm run test:core`.
Test GM contract interactions with `npm run test:contracts`.

## Contributing

Expand All @@ -93,6 +122,6 @@ Fork this repo and create a descriptive PR.
GodMode is in **alpha** so releases may be frequent.
Core devs should create releases after merging in new features by running

`npm run release`
`npm run dist && npm run release`

This will ask you for the release version, then automatically create a release and publish it to npm.
3 changes: 3 additions & 0 deletions bin/godmode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node

require('../dist/bin/godmode.js');
145,773 changes: 0 additions & 145,773 deletions build/contracts/CDelegateInterface.json

This file was deleted.

145,735 changes: 0 additions & 145,735 deletions build/contracts/CDelegationStorage.json

This file was deleted.

145,791 changes: 0 additions & 145,791 deletions build/contracts/CDelegatorInterface.json

This file was deleted.

Loading

0 comments on commit 2f85134

Please sign in to comment.