diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f0798b8b09c..85327d216da 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -8,7 +8,7 @@ /packages/cli/ @mcortesi @asaj /packages/helm-charts/ @nambrot @timmoreton /packages/mobile/ @cmcewen @jmrossy -/packages/notification-service/ @jmrossy @cmcewen +/packages/notification-service/ @annakaz @cmcewen /packages/protocol/ @asaj @m-chrzan /packages/react-components/ @cmcewen @jmrossy /packages/walletkit/ @ashishb @yerdua diff --git a/lerna.json b/lerna.json index 7121d13b47c..f9888d62218 100644 --- a/lerna.json +++ b/lerna.json @@ -3,5 +3,5 @@ "packages": ["packages/*"], "npmClient": "yarn", "useWorkspaces": true, - "version": "1.0.0" + "version": "independent" } diff --git a/packages/attestation-service/package.json b/packages/attestation-service/package.json index 5ded1990591..39cfc583511 100644 --- a/packages/attestation-service/package.json +++ b/packages/attestation-service/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "@celo/contractkit": "0.1.1", - "@celo/utils": "^0.0.6-beta5", + "@celo/utils": "^0.1.0", "bignumber.js": "^7.2.0", "body-parser": "1.19.0", "debug": "^4.1.1", diff --git a/packages/attestation-service/tsconfig.json b/packages/attestation-service/tsconfig.json index c36e81f05e4..ec91f3e2ee9 100644 --- a/packages/attestation-service/tsconfig.json +++ b/packages/attestation-service/tsconfig.json @@ -4,5 +4,6 @@ "rootDir": "src", "outDir": "lib" }, - "include": ["src", "types/", "index.d.ts"] + "include": ["src", "types/", "index.d.ts"], + "references": [{ "path": "../utils" }] } diff --git a/packages/celotool/package.json b/packages/celotool/package.json index f8b9a417dbb..5770e31bba6 100644 --- a/packages/celotool/package.json +++ b/packages/celotool/package.json @@ -7,9 +7,9 @@ "license": "Apache-2.0", "dependencies": { "@celo/verification-pool-api": "^1.0.0", - "@celo/utils": "^0.0.6-beta5", + "@celo/utils": "^0.1.0", "@celo/walletkit": "^0.0.14", - "@celo/contractkit": "0.1.1", + "@celo/contractkit": "0.1.5", "@google-cloud/monitoring": "0.7.1", "@google-cloud/pubsub": "^0.28.1", "@google-cloud/storage": "^2.4.3", diff --git a/packages/celotool/tsconfig.json b/packages/celotool/tsconfig.json index ef8424cc086..83264d28d8a 100644 --- a/packages/celotool/tsconfig.json +++ b/packages/celotool/tsconfig.json @@ -14,5 +14,6 @@ } }, "include": ["src/"], - "exclude": ["node_modules/"] + "exclude": ["node_modules/"], + "references": [{ "path": "../utils" }] } diff --git a/packages/cli/package.json b/packages/cli/package.json index 4a69e3fc68d..3c0268046f4 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -29,7 +29,7 @@ "test": "TZ=UTC jest" }, "dependencies": { - "@celo/utils": "^0.0.6-beta5", + "@celo/utils": "^0.1.0", "@celo/contractkit": "^0.1.1", "@oclif/command": "^1", "@oclif/config": "^1", diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 020ae87c3e7..0d4b633aea4 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -5,5 +5,6 @@ "outDir": "lib", "esModuleInterop": true }, - "include": ["src"] + "include": ["src"], + "references": [{ "path": "../utils" }] } diff --git a/packages/contractkit/package.json b/packages/contractkit/package.json index 9582c621491..75dbe7bfb44 100644 --- a/packages/contractkit/package.json +++ b/packages/contractkit/package.json @@ -1,6 +1,6 @@ { "name": "@celo/contractkit", - "version": "0.1.1", + "version": "0.1.6", "description": "Celo's ContractKit to interact with Celo network", "main": "./lib/index.js", "types": "./lib/index.d.ts", @@ -25,7 +25,8 @@ "lint": "tslint -c tslint.json --project ." }, "dependencies": { - "@celo/utils": "^0.0.6-beta5", + "@0x/subproviders": "^5.0.0", + "@celo/utils": "^0.1.0", "@types/debug": "^4.1.5", "bignumber.js": "^7.2.0", "debug": "^4.1.1", diff --git a/packages/contractkit/tsconfig.json b/packages/contractkit/tsconfig.json index c163b866107..67241945d7e 100644 --- a/packages/contractkit/tsconfig.json +++ b/packages/contractkit/tsconfig.json @@ -4,5 +4,6 @@ "rootDir": "src", "outDir": "lib" }, - "include": ["src", "types/"] + "include": ["src", "types/"], + "references": [{ "path": "../utils" }] } diff --git a/packages/dappkit/package.json b/packages/dappkit/package.json index 9a565e724d3..64ecf5686a3 100644 --- a/packages/dappkit/package.json +++ b/packages/dappkit/package.json @@ -5,8 +5,8 @@ "build": "tsc" }, "dependencies": { - "@celo/contractkit": "0.1.1", - "@celo/utils": "0.0.6-beta5", + "@celo/contractkit": "0.1.5", + "@celo/utils": "^0.1.0", "expo": "^34.0.1", "expo-contacts": "6.0.0", "libphonenumber-js": "^1.7.22" diff --git a/packages/dappkit/tsconfig.json b/packages/dappkit/tsconfig.json index c163b866107..67241945d7e 100644 --- a/packages/dappkit/tsconfig.json +++ b/packages/dappkit/tsconfig.json @@ -4,5 +4,6 @@ "rootDir": "src", "outDir": "lib" }, - "include": ["src", "types/"] + "include": ["src", "types/"], + "references": [{ "path": "../utils" }] } diff --git a/packages/mobile/package.json b/packages/mobile/package.json index 2e36fac09ab..a33a0ba7fbd 100644 --- a/packages/mobile/package.json +++ b/packages/mobile/package.json @@ -48,7 +48,7 @@ "dependencies": { "@celo/client": "2d1d8ca", "@celo/react-native-sms-retriever": "git+https://github.com/celo-org/react-native-sms-retriever#d3a2fdb", - "@celo/utils": "^0.0.6-beta5", + "@celo/utils": "^0.1.0", "@celo/walletkit": "^0.0.14", "@react-native-community/netinfo": "^2.0.4", "@segment/analytics-react-native": "^1.1.0-beta.1", diff --git a/packages/mobile/tsconfig.json b/packages/mobile/tsconfig.json index d1d06ad2f7e..3ead19d2555 100644 --- a/packages/mobile/tsconfig.json +++ b/packages/mobile/tsconfig.json @@ -16,5 +16,6 @@ "target": "es2015", "strict": true }, - "exclude": ["node_modules", "vendor", ".bundle"] + "exclude": ["node_modules", "vendor", ".bundle"], + "references": [{ "path": "../utils" }] } diff --git a/packages/notification-service/README.md b/packages/notification-service/README.md index 536a3e6b737..0a9e2b346b1 100644 --- a/packages/notification-service/README.md +++ b/packages/notification-service/README.md @@ -16,6 +16,14 @@ Next, run this task to build, configure, and start the service: yarn start:local +## Updating environments + +To find a web3 provider for an environment, run + + kubectl get svc -n alfajores --context gke_celo-testnet-production_us-west1-a_alfajores + +then look for the external IP for one of the tx nodes, for example `alfajores-service-0`. + ## Deploying to App Engine Deploy your app. The project will be built automatically by Google Cloud Build: diff --git a/packages/notification-service/app.integration.yaml b/packages/notification-service/app.integration.yaml index d3f4a17def1..2e20ffd20f9 100644 --- a/packages/notification-service/app.integration.yaml +++ b/packages/notification-service/app.integration.yaml @@ -1,6 +1,5 @@ -runtime: nodejs -env: flex -service: integration +runtime: nodejs8 +service: integration instance_class: B4 manual_scaling: - instances: 1 \ No newline at end of file + instances: 1 diff --git a/packages/notification-service/config/config.alfajores.env b/packages/notification-service/config/config.alfajores.env index 65141180fa2..69df57b4b03 100644 --- a/packages/notification-service/config/config.alfajores.env +++ b/packages/notification-service/config/config.alfajores.env @@ -3,8 +3,6 @@ PORT=80 FIREBASE_DB=https://celo-org-mobile-alfajores.firebaseio.com BLOCKSCOUT_API=https://alfajores-blockscout.celo-testnet.org/api? NODE_TLS_REJECT_UNAUTHORIZED=0 -STABLE_TOKEN_ADDRESS=0xd4b4fcaCAc9e23225680e89308E0a4C41Dd9C6B4 -GOLD_TOKEN_ADDRESS=0x11CD75C45638Ec9f41C0e8Df78fc756201E48ff2 DEFAULT_LOCALE=en NOTIFICATION_TTL_MS=604800000 POLLING_INTERVAL=1000 diff --git a/packages/notification-service/config/config.alfajoresstaging.env b/packages/notification-service/config/config.alfajoresstaging.env index 1ab2bc5a547..2e4b534ef48 100644 --- a/packages/notification-service/config/config.alfajoresstaging.env +++ b/packages/notification-service/config/config.alfajoresstaging.env @@ -3,8 +3,7 @@ PORT=80 FIREBASE_DB=https://celo-org-mobile-alfajoresstaging.firebaseio.com/ BLOCKSCOUT_API=https://alfajoresstaging-blockscout.celo-testnet.org/api? NODE_TLS_REJECT_UNAUTHORIZED=0 -STABLE_TOKEN_ADDRESS=0x2dF4dD6Bd1b26a8503F763506bdB8e7cf165f69E -GOLD_TOKEN_ADDRESS=0x1313e2f3EBef8f0d869EECEb796D55A066eEA863 DEFAULT_LOCALE=es NOTIFICATION_TTL_MS=604800000 POLLING_INTERVAL=1000 +WEB3_PROVIDER_URL=http://35.233.160.250:8545 \ No newline at end of file diff --git a/packages/notification-service/config/config.integration.env b/packages/notification-service/config/config.integration.env index 1edea5ef0aa..5a3f6062f47 100644 --- a/packages/notification-service/config/config.integration.env +++ b/packages/notification-service/config/config.integration.env @@ -3,10 +3,8 @@ PORT=80 FIREBASE_DB=https://celo-org-mobile-int.firebaseio.com BLOCKSCOUT_API=https://integration-blockscout.celo-testnet.org/api? NODE_TLS_REJECT_UNAUTHORIZED=0 -STABLE_TOKEN_ADDRESS=0x47736AB66b892b0FCCb5c7d69B879C6141F6E80c -GOLD_TOKEN_ADDRESS=0x9102eCD93ac8D66bAc3D397BF52bc57Ee34Bcb87 DEFAULT_LOCALE=en NOTIFICATION_TTL_MS=604800000 POLLING_INTERVAL=1000 EXCHANGE_POLLING_INTERVAL=1800000 -WEB3_PROVIDER_URL=http://34.83.137.48:8545 \ No newline at end of file +WEB3_PROVIDER_URL=http://35.233.200.197:8545 \ No newline at end of file diff --git a/packages/notification-service/config/config.local.env b/packages/notification-service/config/config.local.env index d81d9caa5f1..d32373899c3 100644 --- a/packages/notification-service/config/config.local.env +++ b/packages/notification-service/config/config.local.env @@ -3,11 +3,9 @@ PORT=8080 FIREBASE_DB=https://celo-org-mobile-int.firebaseio.com BLOCKSCOUT_API=https://integration-blockscout.celo-testnet.org/api? NODE_TLS_REJECT_UNAUTHORIZED=0 -STABLE_TOKEN_ADDRESS=0x94a076695b5c4050fbe57ab205e31c18bddb7cb5 -GOLD_TOKEN_ADDRESS=0x140ad3e4625160f48208daf47ca7fdff40527f5f DEFAULT_LOCALE=en GOOGLE_APPLICATION_CREDENTIALS="./config/serviceAccountKey.json" NOTIFICATION_TTL_MS=604800000 POLLING_INTERVAL=5000 EXCHANGE_POLLING_INTERVAL=1800000 -WEB3_PROVIDER_URL=http://34.83.137.48:8545 \ No newline at end of file +WEB3_PROVIDER_URL=http://35.233.200.197:8545 \ No newline at end of file diff --git a/packages/notification-service/config/config.pilot.env b/packages/notification-service/config/config.pilot.env index 404ec263d92..bd8c4c0fa3e 100644 --- a/packages/notification-service/config/config.pilot.env +++ b/packages/notification-service/config/config.pilot.env @@ -3,8 +3,7 @@ PORT=80 FIREBASE_DB=https://celo-org-mobile-pilot.firebaseio.com BLOCKSCOUT_API=https://pilot-blockscout.celo-testnet.org/api? NODE_TLS_REJECT_UNAUTHORIZED=0 -STABLE_TOKEN_ADDRESS=0x996e24D7791A182f237635018c49E30cdA8FBa5e -GOLD_TOKEN_ADDRESS=0xa69c3D18a74B3FD5F8aDA748428d0bfF8c5387Fe DEFAULT_LOCALE=en NOTIFICATION_TTL_MS=604800000 POLLING_INTERVAL=1000 +WEB3_PROVIDER_URL=http://35.203.185.89:8545 \ No newline at end of file diff --git a/packages/notification-service/config/config.pilotstaging.env b/packages/notification-service/config/config.pilotstaging.env deleted file mode 100644 index c8466b931b2..00000000000 --- a/packages/notification-service/config/config.pilotstaging.env +++ /dev/null @@ -1,10 +0,0 @@ -ENVIRONMENT=pilotstaging -PORT=80 -FIREBASE_DB=https://celo-org-mobile-pilotstaging.firebaseio.com -BLOCKSCOUT_API=https://pilotstaging-blockscout.celo-testnet.org/api? -NODE_TLS_REJECT_UNAUTHORIZED=0 -STABLE_TOKEN_ADDRESS=0x21C4A2C97eaE0c0E8c630FB3529F7718Fa37eCC1 -GOLD_TOKEN_ADDRESS=0x2c9829C36c9D0802f04C6a06c423e132a3Ae1767 -DEFAULT_LOCALE=en -NOTIFICATION_TTL_MS=604800000 -POLLING_INTERVAL=1000 diff --git a/packages/notification-service/config/config.production.env b/packages/notification-service/config/config.production.env deleted file mode 100644 index de7c7b14dbf..00000000000 --- a/packages/notification-service/config/config.production.env +++ /dev/null @@ -1,10 +0,0 @@ -ENVIRONMENT=production -PORT=80 -FIREBASE_DB=https://celo-org-mobile.firebaseio.com -BLOCKSCOUT_API=https://argentinaproduction-blockscout.celo-testnet.org/api? -NODE_TLS_REJECT_UNAUTHORIZED=0 -STABLE_TOKEN_ADDRESS=0xcc245456b0c057ad2c8139824f8fe4161f66e47b -GOLD_TOKEN_ADDRESS=0x000000000000000000000000000000000000ce10 -DEFAULT_LOCALE=es -NOTIFICATION_TTL_MS=604800000 -POLLING_INTERVAL=1000 diff --git a/packages/notification-service/config/config.test.env b/packages/notification-service/config/config.test.env new file mode 100644 index 00000000000..d32373899c3 --- /dev/null +++ b/packages/notification-service/config/config.test.env @@ -0,0 +1,11 @@ +ENVIRONMENT=local +PORT=8080 +FIREBASE_DB=https://celo-org-mobile-int.firebaseio.com +BLOCKSCOUT_API=https://integration-blockscout.celo-testnet.org/api? +NODE_TLS_REJECT_UNAUTHORIZED=0 +DEFAULT_LOCALE=en +GOOGLE_APPLICATION_CREDENTIALS="./config/serviceAccountKey.json" +NOTIFICATION_TTL_MS=604800000 +POLLING_INTERVAL=5000 +EXCHANGE_POLLING_INTERVAL=1800000 +WEB3_PROVIDER_URL=http://35.233.200.197:8545 \ No newline at end of file diff --git a/packages/notification-service/jest.setup.ts b/packages/notification-service/jest.setup.ts index 32a5fcf5b87..6617e6b779f 100644 --- a/packages/notification-service/jest.setup.ts +++ b/packages/notification-service/jest.setup.ts @@ -1,7 +1,4 @@ jest.mock('./src/config', () => ({ ...jest.requireActual('./src/config'), - BLOCKSCOUT_API: '', - STABLE_TOKEN_ADDRESS: '', - GOLD_TOKEN_ADDRESS: '', NOTIFICATIONS_DISABLED: true, })) diff --git a/packages/notification-service/package.json b/packages/notification-service/package.json index 00f1e2592e9..f50d48240af 100644 --- a/packages/notification-service/package.json +++ b/packages/notification-service/package.json @@ -11,7 +11,7 @@ "scripts": { "build": "tsc", "gcp-build": "npm run build", - "test": "export TZ=UTC && jest", + "test": "cp config/config.test.env .env; export TZ=UTC && jest", "test:watch": "yarn test --watch", "lint": "tslint -c tslint.json --project tsconfig.json", "start": "node ./dist/index.js", @@ -19,8 +19,8 @@ "deploy": "./deploy.sh" }, "dependencies": { - "@celo/utils": "^0.0.6-beta5", - "@celo/walletkit": "^0.0.14", + "@celo/contractkit": "0.1.5", + "@celo/utils": "^0.1.0", "async-polling": "^0.2.1", "bignumber.js": "^7.2.0", "dotenv": "^6.0.0", diff --git a/packages/notification-service/src/blockscout/transfers.ts b/packages/notification-service/src/blockscout/transfers.ts index ec9e51ea57f..0ad73f2ce2f 100644 --- a/packages/notification-service/src/blockscout/transfers.ts +++ b/packages/notification-service/src/blockscout/transfers.ts @@ -1,8 +1,8 @@ import BigNumber from 'bignumber.js' import fetch from 'node-fetch' -import { BLOCKSCOUT_API, GOLD_TOKEN_ADDRESS, STABLE_TOKEN_ADDRESS } from '../config' +import { BLOCKSCOUT_API } from '../config' import { getLastBlockNotified, sendPaymentNotification, setLastBlockNotified } from '../firebase' -import { removeEmptyValuesFromObject } from '../util/utils' +import { getTokenAddresses, removeEmptyValuesFromObject } from '../util/utils' import { Log, Response, Transfer } from './blockscout' import { decodeLogs } from './decode' @@ -121,15 +121,16 @@ export async function handleTransferNotifications(): Promise { return } + const { goldTokenAddress, stableTokenAddress } = await getTokenAddresses() const { transfers: goldTransfers, latestBlock: goldTransfersLatestBlock, - } = await getLatestTokenTransfers(GOLD_TOKEN_ADDRESS, lastBlockNotified, Currencies.GOLD) + } = await getLatestTokenTransfers(goldTokenAddress, lastBlockNotified, Currencies.GOLD) const { transfers: stableTransfers, latestBlock: stableTransfersLatestBlock, - } = await getLatestTokenTransfers(STABLE_TOKEN_ADDRESS, lastBlockNotified, Currencies.DOLLAR) + } = await getLatestTokenTransfers(stableTokenAddress, lastBlockNotified, Currencies.DOLLAR) const allTransfers = filterAndJoinTransfers(goldTransfers, stableTransfers) diff --git a/packages/notification-service/src/config.ts b/packages/notification-service/src/config.ts index 44c0d565bba..f7effbe7938 100644 --- a/packages/notification-service/src/config.ts +++ b/packages/notification-service/src/config.ts @@ -30,8 +30,6 @@ export const FIREBASE_DB = process.env.FIREBASE_DB const ENFORCE_NOTIFICATIONS = process.env.ENFORCE_LOCAL_NOTIFICATIONS === 'true' export const NOTIFICATIONS_DISABLED = !ENFORCE_NOTIFICATIONS && ENVIRONMENT === 'local' export const BLOCKSCOUT_API = process.env.BLOCKSCOUT_API -export const STABLE_TOKEN_ADDRESS = (process.env.STABLE_TOKEN_ADDRESS || '').toLowerCase() -export const GOLD_TOKEN_ADDRESS = (process.env.GOLD_TOKEN_ADDRESS || '').toLowerCase() export const DEFAULT_LOCALE = process.env.DEFAULT_LOCALE export const POLLING_INTERVAL = Number(process.env.POLLING_INTERVAL) || 1000 export const NOTIFICATIONS_TTL_MS = Number(process.env.NOTIFICATION_TTL_MS) || 3600 * 1000 * 24 * 7 // 1 week in milliseconds diff --git a/packages/notification-service/src/exchange/exchangeQuery.ts b/packages/notification-service/src/exchange/exchangeQuery.ts index 098bfd5f03c..5a33117b37f 100644 --- a/packages/notification-service/src/exchange/exchangeQuery.ts +++ b/packages/notification-service/src/exchange/exchangeQuery.ts @@ -1,9 +1,8 @@ +import { ContractKit } from '@celo/contractkit' import { CURRENCY_ENUM } from '@celo/utils' -import { ContractUtils } from '@celo/walletkit' // To be updated to contractkit when new version is published on npm import BigNumber from 'bignumber.js' -import Web3 from 'web3' -import { WEB3_PROVIDER_URL } from '../config' import { writeExchangeRatePair } from '../firebase' +import { getContractKit } from '../util/utils' // Amounts to estimate the exchange rate, as the rate varies based on transaction size const SELL_AMOUNTS = { @@ -12,34 +11,22 @@ const SELL_AMOUNTS = { } export async function handleExchangeQuery() { - const web3Instance = await getWeb3Instance() + const contractKitInstance = await getContractKit() const fetchTime = Date.now().toString() const [dollarMakerRate, goldMakerRate] = await Promise.all([ - getExchangeRate(CURRENCY_ENUM.DOLLAR, web3Instance), - getExchangeRate(CURRENCY_ENUM.GOLD, web3Instance), + getExchangeRate(CURRENCY_ENUM.DOLLAR, contractKitInstance), + getExchangeRate(CURRENCY_ENUM.GOLD, contractKitInstance), ]) writeExchangeRatePair(CURRENCY_ENUM.DOLLAR, dollarMakerRate.toString(), fetchTime) writeExchangeRatePair(CURRENCY_ENUM.GOLD, goldMakerRate.toString(), fetchTime) } -export async function getExchangeRate(makerToken: CURRENCY_ENUM, web3Instance: Web3) { - const rate = await ContractUtils.getExchangeRate( - web3Instance, - makerToken, - SELL_AMOUNTS[makerToken] +async function getExchangeRate(makerToken: CURRENCY_ENUM, contractKitInstance: ContractKit) { + const exchange = await contractKitInstance.contracts.getExchange() + const rate = await exchange.getExchangeRate( + SELL_AMOUNTS[makerToken], + makerToken === CURRENCY_ENUM.GOLD ) return rate } - -let web3: Web3 -export async function getWeb3Instance(): Promise { - if (web3 && (await web3.eth.net.isListening())) { - // Already connected - return web3 - } else { - const httpProvider = new Web3.providers.HttpProvider(WEB3_PROVIDER_URL) - web3 = new Web3(httpProvider) - return web3 - } -} diff --git a/packages/notification-service/src/index.ts b/packages/notification-service/src/index.ts index 367d09334cf..13b149d7724 100644 --- a/packages/notification-service/src/index.ts +++ b/packages/notification-service/src/index.ts @@ -68,6 +68,7 @@ notificationPolling.run() if (!WEB3_PROVIDER_URL) { console.info('No Web3 provider found. Skipping exchange polling.') + console.info('Note that you will need to manually set contract addresses.') } else { /** * Start polling the Exchange contract diff --git a/packages/notification-service/src/util/utils.ts b/packages/notification-service/src/util/utils.ts index c23c7ea4df3..379fbabedb7 100644 --- a/packages/notification-service/src/util/utils.ts +++ b/packages/notification-service/src/util/utils.ts @@ -1,3 +1,7 @@ +import { CeloContract, ContractKit, newKitFromWeb3 } from '@celo/contractkit' +import Web3 from 'web3' +import { WEB3_PROVIDER_URL } from '../config' + interface ObjectWithStringsAndUndefined { [key: string]: string | undefined } @@ -15,3 +19,29 @@ export function removeEmptyValuesFromObject(obj: ObjectWithStringsAndUndefined) .forEach((k) => (newObj[k] = obj[k])) return newObj } + +let goldTokenAddress: string +let stableTokenAddress: string +export async function getTokenAddresses() { + if (goldTokenAddress && stableTokenAddress) { + return { goldTokenAddress, stableTokenAddress } + } else { + const kit = await getContractKit() + goldTokenAddress = await kit.registry.addressFor(CeloContract.StableToken) + stableTokenAddress = await kit.registry.addressFor(CeloContract.GoldToken) + return { goldTokenAddress, stableTokenAddress } + } +} + +let contractKit: ContractKit +export async function getContractKit(): Promise { + if (contractKit && (await contractKit.isListening())) { + // Already connected + return contractKit + } else { + const httpProvider = new Web3.providers.HttpProvider(WEB3_PROVIDER_URL) + const web3 = new Web3(httpProvider) + contractKit = newKitFromWeb3(web3) + return contractKit + } +} diff --git a/packages/notification-service/tsconfig.json b/packages/notification-service/tsconfig.json index 1cab23893a3..7b7f6c5ae47 100644 --- a/packages/notification-service/tsconfig.json +++ b/packages/notification-service/tsconfig.json @@ -15,5 +15,6 @@ "lib": ["es7", "esnext"] }, "include": ["src/**/*"], - "exclude": ["node_modules", "vendor", ".bundle"] + "exclude": ["node_modules", "vendor", ".bundle"], + "references": [{ "path": "../utils" }] } diff --git a/packages/notification-service/yarn.lock b/packages/notification-service/yarn.lock new file mode 120000 index 00000000000..3f82ebc9cdb --- /dev/null +++ b/packages/notification-service/yarn.lock @@ -0,0 +1 @@ +../../yarn.lock \ No newline at end of file diff --git a/packages/protocol/package.json b/packages/protocol/package.json index 7acd736503a..2a53f18b185 100644 --- a/packages/protocol/package.json +++ b/packages/protocol/package.json @@ -42,7 +42,7 @@ "@0x/sol-profiler": "^3.0.0", "@0x/sol-trace": "^2.0.16", "@0x/subproviders": "^5.0.0", - "@celo/utils": "^0.0.6-beta5", + "@celo/utils": "^0.1.0", "apollo-client": "^2.4.13", "bls12377js": "https://github.com/celo-org/bls12377js#4f596cabb659c4f8969ae4b617f185f2bc74cbbb", "chai-subset": "^1.6.0", @@ -76,7 +76,6 @@ "devDependencies": { "@celo/ganache-cli": "git+https://github.com/celo-org/ganache-cli.git#816a475", "@celo/typescript": "0.0.1", - "@celo/utils": "^0.0.6-beta5", "@types/bignumber.js": "^5.0.0", "@types/bn.js": "^4.11.0", "@types/chai": "^4.1.3", diff --git a/packages/react-components/package.json b/packages/react-components/package.json index 68dc0fc1c59..408f8e65e47 100644 --- a/packages/react-components/package.json +++ b/packages/react-components/package.json @@ -14,7 +14,7 @@ "test:watch": "export TZ=UTC && jest --watch" }, "dependencies": { - "@celo/utils": "^0.0.6-beta5", + "@celo/utils": "^0.1.0", "hoist-non-react-statics": "^3.3.0", "lodash": "^4.17.14", "react-native-autocomplete-input": "^3.6.0", diff --git a/packages/react-components/tsconfig.json b/packages/react-components/tsconfig.json index d284124405c..5106958f1b7 100644 --- a/packages/react-components/tsconfig.json +++ b/packages/react-components/tsconfig.json @@ -17,5 +17,6 @@ "target": "es2015", "resolveJsonModule": true }, - "exclude": ["node_modules"] + "exclude": ["node_modules"], + "references": [{ "path": "../utils" }] } diff --git a/packages/transaction-metrics-exporter/package.json b/packages/transaction-metrics-exporter/package.json index c251c6ac013..df546f94e81 100644 --- a/packages/transaction-metrics-exporter/package.json +++ b/packages/transaction-metrics-exporter/package.json @@ -8,7 +8,7 @@ "private": true, "dependencies": { "@celo/contractkit": "^0.1.1", - "@celo/utils": "0.0.6-beta5", + "@celo/utils": "^0.1.0", "express": "4.16.4", "prom-client": "11.2.0" }, diff --git a/packages/transaction-metrics-exporter/tsconfig.json b/packages/transaction-metrics-exporter/tsconfig.json index 00453cb784a..a149848c92f 100644 --- a/packages/transaction-metrics-exporter/tsconfig.json +++ b/packages/transaction-metrics-exporter/tsconfig.json @@ -4,5 +4,6 @@ "rootDir": "src", "outDir": "lib" }, - "include": ["src"] + "include": ["src"], + "references": [{ "path": "../utils" }] } diff --git a/packages/utils/package.json b/packages/utils/package.json index cb77ed2dca1..0485521e709 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@celo/utils", - "version": "0.0.6-beta5", + "version": "0.1.1", "description": "Celo common utils", "author": "Celo", "license": "Apache-2.0", diff --git a/packages/verifier/package.json b/packages/verifier/package.json index 9e7b9fbd849..5119768b01f 100644 --- a/packages/verifier/package.json +++ b/packages/verifier/package.json @@ -26,7 +26,7 @@ }, "dependencies": { "@celo/react-components": "1.0.0", - "@celo/utils": "^0.0.6-beta5", + "@celo/utils": "^0.1.0", "@react-native-community/netinfo": "^2.0.4", "@segment/analytics-react-native": "^1.1.0-beta.1", "@segment/analytics-react-native-firebase": "^1.1.0-beta.1", diff --git a/packages/verifier/tsconfig.json b/packages/verifier/tsconfig.json index f5be6db9ea4..20b33fc6f9c 100644 --- a/packages/verifier/tsconfig.json +++ b/packages/verifier/tsconfig.json @@ -16,5 +16,6 @@ "baseUrl": ".", "lib": ["es7", "esnext", "dom"] }, - "exclude": ["node_modules", "vendor", ".bundle"] + "exclude": ["node_modules", "vendor", ".bundle"], + "references": [{ "path": "../utils" }] } diff --git a/packages/walletkit/package.json b/packages/walletkit/package.json index 240ffdb1ed3..757c8e38ef9 100644 --- a/packages/walletkit/package.json +++ b/packages/walletkit/package.json @@ -23,7 +23,7 @@ }, "dependencies": { "@0x/subproviders": "^4.1.0", - "@celo/utils": "^0.0.6-beta5", + "@celo/utils": "^0.1.0", "@google-cloud/storage": "^2.3.3", "babel-jest": "^24.8.0", "bignumber.js": "^7.2.0", diff --git a/packages/walletkit/tsconfig.json b/packages/walletkit/tsconfig.json index 2568053e1db..07409136d50 100644 --- a/packages/walletkit/tsconfig.json +++ b/packages/walletkit/tsconfig.json @@ -21,5 +21,6 @@ "esModuleInterop": true }, "include": [".", "src/**/*", "types/**/*", "contracts/**/*"], - "exclude": ["lib", "node_modules"] + "exclude": ["lib", "node_modules"], + "references": [{ "path": "../utils" }] } diff --git a/packages/web/package.json b/packages/web/package.json index f909efaccde..94c0ddc5b73 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -19,7 +19,7 @@ "test-licenses": "yarn licenses list --prod | grep '\\(─ GPL\\|─ (GPL-[1-9]\\.[0-9]\\+ OR GPL-[1-9]\\.[0-9]\\+)\\)' && echo 'Found GPL license(s). Use 'yarn licenses list --prod' to look up the offending package' || echo 'No GPL licenses found'" }, "dependencies": { - "@celo/utils": "^0.0.6-beta5", + "@celo/utils": "^0.1.0", "@segment/in-eu": "^0.2.1", "@sentry/browser": "^5.6.2", "@sentry/node": "^5.6.2", diff --git a/packages/web/tsconfig.json b/packages/web/tsconfig.json index 78661f2e322..e095042f761 100644 --- a/packages/web/tsconfig.json +++ b/packages/web/tsconfig.json @@ -19,5 +19,6 @@ "next-i18next": ["src/next-i18next-aug.d.ts"] } }, - "exclude": ["dist"] + "exclude": ["dist"], + "references": [{ "path": "../utils" }] } diff --git a/yarn.lock b/yarn.lock index 6463b909740..eaef59fd671 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2248,6 +2248,34 @@ resolved "https://registry.yarnpkg.com/@celo/client/-/client-0.0.107.tgz#3cb82455bd66868e126aeb605346514085b0dff0" integrity sha512-s47vj2NYha1u3x5S0u/VhY4YHYb3KySmahKxWFZbWfojMe0vu/bZ3M72nIZf4LM34wEpv40nKe/foGH9Q9LOMw== +"@celo/contractkit@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@celo/contractkit/-/contractkit-0.1.1.tgz#bd85812d883b58fbc8d9897a59e2f7311cc0e2eb" + integrity sha512-GQbLuLUEgKtwy2I8ZVi4P0HBVhh9MlT5S90vIrGznb9eZ2vwGahfOxHapVKcxw2I4tbVBNTTWWpcjzOtJZCY7Q== + 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" + +"@celo/contractkit@0.1.5": + version "0.1.5" + resolved "https://registry.yarnpkg.com/@celo/contractkit/-/contractkit-0.1.5.tgz#097052ac8f672f03480a1226f11f0c398c35c75e" + integrity sha512-vW8/ZluqJXx4SOB64XyFZjR3Z6qzcCUjXk6ec5613NH8DC/7jzxPCnbPsnxL4R+zuEajDWKfjjeH94Y1uLgVGA== + dependencies: + "@0x/subproviders" "^5.0.0" + "@celo/utils" "0.1.0" + "@types/debug" "^4.1.5" + bignumber.js "^7.2.0" + debug "^4.1.1" + eth-lib "^0.2.8" + web3 "1.0.0-beta.37" + web3-core-helpers "1.0.0-beta.37" + web3-eth-abi "1.0.0-beta.37" + web3-utils "1.0.0-beta.37" + "@celo/dev-cli@^2.0.3": version "2.0.3" resolved "https://registry.yarnpkg.com/@celo/dev-cli/-/dev-cli-2.0.3.tgz#67f61dfee373ad8b412925e386cf122aabada5f5" @@ -2286,6 +2314,43 @@ version "1.0.3" resolved "git+https://github.com/celo-org/react-native-sms-retriever#d3a2fdb148e3427c9a8c1c87acb61e79e2afcfee" +"@celo/utils@0.1.0": + version "0.1.0" + resolved "https://registry.yarnpkg.com/@celo/utils/-/utils-0.1.0.tgz#081e0c9a7ea3e7b50cbc88e89b0f7ff8d5578499" + integrity sha512-sSE17+lu0dqG+Zo+H/aZYFXq436+Kd9xhXk5a36RtONXuJY8q6jfaXMFoBJ0Wft19rJM24e9F2aM84HM/IiUTQ== + dependencies: + "@umpirsky/country-list" "git://github.com/umpirsky/country-list#05fda51" + bigi "^1.1.0" + bignumber.js "^7.2.0" + bn.js "4.11.8" + buffer-reverse "^1.0.1" + country-data "^0.0.31" + crypto-js "^3.1.9-1" + elliptic "^6.4.1" + ethereumjs-util "^5.2.0" + futoin-hkdf "^1.0.3" + google-libphonenumber "^3.2.4" + keccak256 "^1.0.0" + lodash "^4.17.14" + web3-utils "1.0.0-beta.37" + +"@celo/utils@^0.0.6-beta5": + version "0.0.6-beta5" + resolved "https://registry.yarnpkg.com/@celo/utils/-/utils-0.0.6-beta5.tgz#a558cfc9dc68d9ec15888798c95cd6e5f1d3fe67" + integrity sha512-TGIDjr1aCcNRVv2Z3DZkjd71K/vNd6C18BPZw8VfKzSFyt0UcxkbN/X+loqvJSrwymtYgu/s6JdIQD3t14xiJA== + dependencies: + "@umpirsky/country-list" "git://github.com/umpirsky/country-list#05fda51" + bignumber.js "^7.2.0" + bn.js "4.11.8" + country-data "^0.0.31" + crypto-js "^3.1.9-1" + elliptic "^6.4.1" + ethereumjs-util "^5.2.0" + futoin-hkdf "^1.0.3" + google-libphonenumber "^3.2.1" + lodash "^4.17.14" + web3-utils "1.0.0-beta.37" + "@cnakazawa/watch@^1.0.3": version "1.0.3" resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.3.tgz#099139eaec7ebf07a27c1786a3ff64f39464d2ef" @@ -15939,6 +16004,11 @@ google-gax@^0.25.0: semver "^5.5.1" walkdir "^0.3.2" +google-libphonenumber@^3.2.1: + version "3.2.5" + resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.5.tgz#2ebe6437fd3dbbffd65f4339ad1ba93b3dc56836" + integrity sha512-Y0r7MFCI11UDLn0KaMPBEInhROyIOkWkQIyvWMFVF2I+h+sHE3vbl5a7FVe39td6u/w+nlKDdUMP9dMOZyv+2Q== + google-libphonenumber@^3.2.4: version "3.2.4" resolved "https://registry.yarnpkg.com/google-libphonenumber/-/google-libphonenumber-3.2.4.tgz#91d3fe62ca531f154165e6580b1c55ff6bd53abf"