-
Notifications
You must be signed in to change notification settings - Fork 376
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #624 from celo-org/rossy/production-update-v1.4.1
Update production branch with Wallet v.1.4.1 changes
- Loading branch information
Showing
130 changed files
with
2,221 additions
and
450 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
src/generated | ||
tsconfig.tsbuildinfo | ||
lib/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]! | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.