Skip to content

Commit

Permalink
Merge pull request #624 from celo-org/rossy/production-update-v1.4.1
Browse files Browse the repository at this point in the history
Update production branch with Wallet v.1.4.1 changes
  • Loading branch information
timmoreton authored Aug 19, 2019
2 parents 40c611d + c422cab commit 7a5f54a
Show file tree
Hide file tree
Showing 130 changed files with 2,221 additions and 450 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ packages/blockchain-api/dist

packages/cli/lib

packages/contractkit/lib/

packages/walletkit/lib/
packages/walletkit/.artifacts/
packages/walletkit/contracts/
Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,20 @@
]
},
"devDependencies": {
"@types/jest": "^24.0.17",
"husky": "^3.0.0",
"lerna": "^3.16.0",
"patch-package": "^5.1.1",
"prettier": "1.13.5",
"pretty-quick": "^1.11.1",
"solc": "0.5.8",
"tslint": "^5.12.1",
"typescript-tslint-plugin": "^0.5.0"
"typescript": "^3.3.3",
"jest": "^24.8.0",
"ts-jest": "^24.0.2",
"typescript-tslint-plugin": "^0.5.4",
"tsconfig-paths": "^3.8.0",
"ts-node": "^8.3.0"
},
"dependencies": {
"codecov": "^3.1.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain-api/app.alfajores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ env_variables:
# Pull addresses from the build artifacts of the network in protocol/build
CELO_GOLD_ADDRESS: '0x11CD75C45638Ec9f41C0e8Df78fc756201E48ff2'
CELO_DOLLAR_ADDRESS: '0xd4b4fcaCAc9e23225680e89308E0a4C41Dd9C6B4'
FAUCET_ADDRESS: '0x456f41406B32c45D59E539e4BBA3D7898c3584dA'
FAUCET_ADDRESS: '0xCEa3eF8e187490A9d85A1849D98412E5D27D1Bb3'
VERIFICATION_REWARDS_ADDRESS: '0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5'
ABE_ADDRESS: '0x714f2879A4aa985508537f851FeBCfB26D7aF40D'
2 changes: 1 addition & 1 deletion packages/blockchain-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@google-cloud/nodejs-repo-tools": "^2.3.3",
"@types/dotenv": "^4.0.3",
"@types/express": "^4.16.1",
"@types/jest": "^24.0.13",
"@types/jest": "^24.0.17",
"@types/utf8": "^2.1.6",
"@types/web3": "^1.0.18",
"jest": "^24.8.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ a few useful commands to make running a node really easy.
- Clone [Celo Blockchain repo](https://github.com/celo-org/celo-blockchain)
- Build `celotooljs geth build --geth-dir <directory-where-you-cloned-geth-repo> -c`
- Init `celotooljs geth init --geth-dir <directory-where-you-cloned-geth-repo> --data-dir <geth-data-dir> -e <env-name>`
- Run `celotooljs geth run --geth-dir <directory-where-you-cloned-geth-repo> --data-dir <geth-data-dir> --sync-mode <full | fast | light | celolatest>`
- Run `celotooljs geth run --geth-dir <directory-where-you-cloned-geth-repo> --data-dir <geth-data-dir> --sync-mode <full | fast | light | ultralight>`
8 changes: 3 additions & 5 deletions packages/celotool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"author": "Celo",
"license": "Apache-2.0",
"dependencies": {
"@celo/walletkit": "^0.0.4",
"@celo/walletkit": "^0.0.14",
"@google-cloud/monitoring": "0.7.1",
"@google-cloud/pubsub": "^0.28.1",
"@google-cloud/storage": "^2.4.3",
Expand All @@ -25,21 +25,19 @@
"node-fetch": "^2.2.0",
"prompts": "1.2.0",
"sleep-promise": "^8.0.1",
"tsconfig-paths": "3.6.0",
"web3": "1.0.0-beta.37",
"web3-eth-admin": "1.0.0-beta.55",
"yargs": "12.0.2"
},
"devDependencies": {
"@types/dotenv": "^4.0.3",
"@types/jest": "^24.0.13",
"@types/jest": "^24.0.17",
"@types/node-fetch": "^2.1.2",
"@types/prompts": "^1.1.1",
"@types/web3": "^1.0.18",
"@types/yargs": "^12.0.1",
"jest": "^24.8.0",
"ts-jest": "^24.0.0",
"ts-node": "^7.0.1"
"ts-jest": "^24.0.0"
},
"scripts": {
"cli": "TS_NODE_FILES=true ts-node -r tsconfig-paths/register src/cli.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/cmds/geth/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const builder = (argv: yargs.Argv) => {
default: '1101',
})
.option('sync-mode', {
choices: ['full', 'fast', 'light', 'celolatest', 'ultralight'],
choices: ['full', 'fast', 'light', 'ultralight'],
demandOption: true,
})
.option('mining', {
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@celo/celocli",
"description": "CLI Tool for transacting with the Celo protocol",
"version": "0.0.6",
"version": "0.0.17",
"author": "Celo",
"license": "Apache-2.0",
"repository": "celo-org/celo-monorepo",
Expand All @@ -24,10 +24,11 @@
"build": "rm -rf lib && tsc -b",
"docs": "yarn oclif-dev readme --multi --dir=../docs/command-line-interface && yarn prettier ../docs/command-line-interface/*.md --write",
"lint": "tslint -c tslint.json --project tsconfig.json",
"prepublishOnly": "yarn --cwd=../walletkit build && yarn run build && oclif-dev manifest && oclif-dev readme",
"test": "export TZ=UTC && jest --ci --silent"
},
"dependencies": {
"@celo/walletkit": "^0.0.4",
"@celo/walletkit": "^0.0.14",
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/plugin-help": "^2",
Expand Down Expand Up @@ -60,7 +61,6 @@
"@types/node": "^10",
"@types/web3": "^1.0.18",
"globby": "^8",
"ts-node": "^8",
"tslint": "^5",
"typescript": "^3.3.3"
},
Expand All @@ -71,7 +71,7 @@
"/oclif.manifest.json"
],
"oclif": {
"commands": "./lib/commands",
"commands": "./lib/src/commands",
"topics": {
"account": {
"description": "Manage your account, send and receive Celo Gold and Celo Dollars"
Expand Down
3 changes: 3 additions & 0 deletions packages/contractkit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/generated
tsconfig.tsbuildinfo
lib/
7 changes: 7 additions & 0 deletions packages/contractkit/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules
/coverage
/tslint.json
/tsconfig.json
/test
/src
/jest.config.json
7 changes: 7 additions & 0 deletions packages/contractkit/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
moduleNameMapper: {
'^src/(.*)$': '<rootDir>/src/$1',
},
}
39 changes: 39 additions & 0 deletions packages/contractkit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@celo/contractkit",
"version": "0.0.5-beta3",
"description": "Celo's ContractKit to interact with Celo network",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"author": "Celo",
"license": "Apache-2.0",
"homepage": "https://github.com/celo-org/celo-monorepo/tree/master/packages/contractkit",
"repository": "https://github.com/celo-org/celo-monorepo/tree/master/packages/contractkit",
"keywords": ["celo", "blockchain", "contractkit", "defi"],
"scripts": {
"build": "tsc -b .",
"clean": "tsc -b . --clean && rm -rf src/generated",
"build:gen": "yarn --cwd ../protocol build",
"prepublishOnly": "yarn build:gen && yarn build",
"lint": "tslint -c tslint.json --project . && tslint -c tslint.json --project test"
},
"dependencies": {
"@celo/utils": "^0.0.6-beta5",
"@types/debug": "^4.1.5",
"bignumber.js": "^7.2.0",
"debug": "^4.1.1",
"web3": "1.0.0-beta.37",
"web3-utils": "1.0.0-beta.37"
},
"devDependencies": {
"@celo/protocol": "1.0.0",
"@types/debug": "^4.1.5",
"@types/jest": "^24.0.17",
"@types/web3": "^1.0.18"
},
"engines": {
"node": ">=8.13.0"
},
"files": [
"lib/**/*"
]
}
37 changes: 37 additions & 0 deletions packages/contractkit/src/address-registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Address, AllContracts, CeloContract, NULL_ADDRESS } from './base'
import { newRegistry } from './generated/Registry'
import { Registry } from './generated/types/Registry'
import { ContractKit } from './kit'

// Registry contract is always predeployed to this address
const REGISTRY_CONTRACT_ADDRESS = '0x000000000000000000000000000000000000ce10'

export class AddressRegistry {
private readonly registry: Registry
private readonly cache: Map<CeloContract, Address> = new Map()

constructor(kit: ContractKit) {
this.cache.set(CeloContract.Registry, REGISTRY_CONTRACT_ADDRESS)
this.registry = newRegistry(kit.web3, REGISTRY_CONTRACT_ADDRESS)
}

async addressFor(contract: CeloContract): Promise<Address> {
if (!this.cache.has(contract)) {
const address = await this.registry.methods.getAddressFor(contract).call()

if (!address || address === NULL_ADDRESS) {
throw new Error(`Failed to get address for ${contract} from the Registry`)
}
this.cache.set(contract, address)
}
return this.cache.get(contract)!
}

async allAddresses(): Promise<Record<CeloContract, Address>> {
const res: Partial<Record<CeloContract, Address>> = {}
for (const contract of AllContracts) {
res[contract] = await this.addressFor(contract)
}
return res as Record<CeloContract, Address>
}
}
27 changes: 27 additions & 0 deletions packages/contractkit/src/base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export type Address = string

export enum CeloContract {
Attestations = 'Attestations',
BondedDeposits = 'BondedDeposits',
Escrow = 'Escrow',
Exchange = 'Exchange',
GasCurrencyWhitelist = 'GasCurrencyWhitelist',
GasPriceMinimum = 'GasPriceMinimum',
GoldToken = 'GoldToken',
Governance = 'Governance',
MultiSig = 'MultiSig',
Random = 'Random',
Registry = 'Registry',
Reserve = 'Reserve',
SortedOracles = 'SortedOracles',
StableToken = 'StableToken',
Validators = 'Validators',
}

export type CeloToken = CeloContract.GoldToken | CeloContract.StableToken

export const AllContracts = Object.keys(CeloContract).map(
(k) => CeloContract[k as any]
) as CeloContract[]

export const NULL_ADDRESS = '0x0000000000000000000000000000000000000000' as Address
104 changes: 104 additions & 0 deletions packages/contractkit/src/contract-cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { CeloContract } from './base'
import { ContractKit } from './kit'
import { BondedDepositsWrapper } from './wrappers/BondedDeposits'
import { ExchangeWrapper } from './wrappers/Exchange'
import { GoldTokenWrapper } from './wrappers/GoldTokenWrapper'
import { StableTokenWrapper } from './wrappers/StableTokenWrapper'
import { ValidatorsWrapper } from './wrappers/Validators'

const WrapperFactories = {
// [CeloContract.Attestations]: AttestationsWrapper,
[CeloContract.BondedDeposits]: BondedDepositsWrapper,
// [CeloContract.Escrow]: EscrowWrapper,
[CeloContract.Exchange]: ExchangeWrapper,
// [CeloContract.GasCurrencyWhitelist]: GasCurrencyWhitelistWrapper,
// [CeloContract.GasPriceMinimum]: GasPriceMinimumWrapper,
[CeloContract.GoldToken]: GoldTokenWrapper,
// [CeloContract.Governance]: GovernanceWrapper,
// [CeloContract.MultiSig]: MultiSigWrapper,
// [CeloContract.Random]: RandomWrapper,
// [CeloContract.Registry]: RegistryWrapper,
// [CeloContract.Reserve]: ReserveWrapper,
// [CeloContract.SortedOracles]: SortedOraclesWrapper,
[CeloContract.StableToken]: StableTokenWrapper,
[CeloContract.Validators]: ValidatorsWrapper,
}

type CFType = typeof WrapperFactories

interface WrapperCacheMap {
// [CeloContract.Attestations]?: AttestationsWrapper,
[CeloContract.BondedDeposits]?: BondedDepositsWrapper
// [CeloContract.Escrow]?: EscrowWrapper,
[CeloContract.Exchange]?: ExchangeWrapper
// [CeloContract.GasCurrencyWhitelist]?: GasCurrencyWhitelistWrapper,
// [CeloContract.GasPriceMinimum]?: GasPriceMinimumWrapper,
[CeloContract.GoldToken]?: GoldTokenWrapper
// [CeloContract.Governance]?: GovernanceWrapper,
// [CeloContract.MultiSig]?: MultiSigWrapper,
// [CeloContract.Random]?: RandomWrapper,
// [CeloContract.Registry]?: RegistryWrapper,
// [CeloContract.Reserve]?: ReserveWrapper,
// [CeloContract.SortedOracles]?: SortedOraclesWrapper,
[CeloContract.StableToken]?: StableTokenWrapper
[CeloContract.Validators]?: ValidatorsWrapper
}

export class WrapperCache {
// private wrapperCache: Map<CeloContract, any> = new Map()
private wrapperCache: WrapperCacheMap = {}

constructor(readonly kit: ContractKit) {}

// getAttestations() {
// return this.getWrapper(CeloContract.Attestations, newAttestations)
// }
getBondedDeposits() {
return this.getContract(CeloContract.BondedDeposits)
}
// getEscrow() {
// return this.getWrapper(CeloContract.Escrow, newEscrow)
// }
getExchange() {
return this.getContract(CeloContract.Exchange)
}
// getGasCurrencyWhitelist() {
// return this.getWrapper(CeloContract.GasCurrencyWhitelist, newGasCurrencyWhitelist)
// }
// getGasPriceMinimum() {
// return this.getWrapper(CeloContract.GasPriceMinimum, newGasPriceMinimum)
// }
getGoldToken() {
return this.getContract(CeloContract.GoldToken)
}
// getGovernance() {
// return this.getWrapper(CeloContract.Governance, newGovernance)
// }
// getMultiSig() {
// return this.getWrapper(CeloContract.MultiSig, newMultiSig)
// }
// getRegistry() {
// return this.getWrapper(CeloContract.Registry, newRegistry)
// }
// getReserve() {
// return this.getWrapper(CeloContract.Reserve, newReserve)
// }
// getSortedOracles() {
// return this.getWrapper(CeloContract.SortedOracles, newSortedOracles)
// }
getStableToken() {
return this.getContract(CeloContract.StableToken)
}
getValidators() {
return this.getContract(CeloContract.Validators)
}

public async getContract<C extends keyof CFType>(contract: C) {
if (this.wrapperCache[contract] == null) {
const instance = await this.kit._web3Contracts.getContract(contract)
const Klass: CFType[C] = WrapperFactories[contract]
this.wrapperCache[contract] = new Klass(this.kit, instance as any) as any
}
return this.wrapperCache[contract]!
}
}
8 changes: 8 additions & 0 deletions packages/contractkit/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Web3 from 'web3'

export { Address, CeloContract, CeloToken, NULL_ADDRESS } from './base'
export * from './kit'

export function newWeb3(url: string) {
return new Web3(url)
}
Loading

0 comments on commit 7a5f54a

Please sign in to comment.