diff --git a/packages/api/src/abi/ConfluxEthUsd.json b/packages/api/src/abi/ConfluxEthUsd.json new file mode 100644 index 00000000..121f8ca4 --- /dev/null +++ b/packages/api/src/abi/ConfluxEthUsd.json @@ -0,0 +1,116 @@ +[ + { + "inputs": [ + { "internalType": "address", "name": "_wrb", "type": "address" } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint64", + "name": "", + "type": "uint64" + } + ], + "name": "PriceUpdated", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "string", + "name": "", + "type": "string" + } + ], + "name": "ResultError", + "type": "event" + }, + { + "inputs": [], + "name": "ETHUSD3ID", + "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [], + "name": "lastPrice", + "outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [], + "name": "lastRequestId", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [], + "name": "pending", + "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [], + "name": "request", + "outputs": [ + { + "internalType": "contract WitnetRequest", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [], + "name": "timestamp", + "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], + "stateMutability": "view", + "type": "function", + "constant": true + }, + { + "inputs": [], + "name": "requestUpdate", + "outputs": [], + "stateMutability": "payable", + "type": "function", + "payable": true + }, + { + "inputs": [], + "name": "completeUpdate", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [{ "internalType": "bytes32", "name": "_id", "type": "bytes32" }], + "name": "valueFor", + "outputs": [ + { "internalType": "int256", "name": "", "type": "int256" }, + { "internalType": "uint256", "name": "", "type": "uint256" }, + { "internalType": "uint256", "name": "", "type": "uint256" } + ], + "stateMutability": "view", + "type": "function", + "constant": true + } +] diff --git a/packages/api/src/dataFeeds.json b/packages/api/src/dataFeeds.json index 1b2159cd..e4a4cf61 100644 --- a/packages/api/src/dataFeeds.json +++ b/packages/api/src/dataFeeds.json @@ -70,5 +70,29 @@ "address": "0x0C4be6AA667df48de54BA174bE7948875fdf152B", "abi": "./src/abi/WitnetRequestBoardProxy.json" } + }, + { + "abi": "./src/abi/ConfluxBtcUsd.json", + "address": "0x8934bfeFb0d5d7d4f1fbEf558562f6487787b6cC", + "witnetRequestBoard": { + "address": "0x84f3342E460265D1A271Fc1Bd678A361a9208e72", + "abi": "./src/abi/ConfluxWitnetRequestBoardProxy.json" + }, + "network": "conflux", + "name": "btc/usd", + "label": "$", + "pollingPeriod": 900000 + }, + { + "abi": "./src/abi/ConfluxEthUsd.json", + "address": "0x8E5C614bA4DA97E823D4C3f0DCB02c872C84E6C3", + "witnetRequestBoard": { + "address": "0x84f3342E460265D1A271Fc1Bd678A361a9208e72", + "abi": "./src/abi/ConfluxWitnetRequestBoardProxy.json" + }, + "network": "conflux", + "name": "eth/usd", + "label": "$", + "pollingPeriod": 900000 } ] diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 3f1bee3f..03572729 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -38,24 +38,25 @@ async function main () { function readDataFeeds (): Array { console.log('DIRNAME', __dirname) console.log('DATA_FEED_CONFIG_PATH:>', process.env.DATA_FEED_CONFIG_PATH) - console.log('resolve path: ', path.resolve(process.env.DATA_FEED_CONFIG_PATH || './dataFeeds.json')) + console.log( + 'resolve path: ', + path.resolve(process.env.DATA_FEED_CONFIG_PATH || './dataFeeds.json') + ) const dataFeeds: Array = JSON.parse( - fs.readFileSync(path.resolve(process.env.DATA_FEED_CONFIG_PATH || './dataFeeds.json'), 'utf-8') + fs.readFileSync( + path.resolve(process.env.DATA_FEED_CONFIG_PATH || './dataFeeds.json'), + 'utf-8' + ) ) return dataFeeds.map(dataFeed => ({ ...dataFeed, - abi: JSON.parse( - fs.readFileSync(path.resolve(dataFeed.abi), 'utf-8') - ), + abi: JSON.parse(fs.readFileSync(path.resolve(dataFeed.abi), 'utf-8')), witnetRequestBoard: { ...dataFeed.witnetRequestBoard, abi: JSON.parse( - fs.readFileSync( - path.resolve(dataFeed.witnetRequestBoard.abi), - 'utf-8' - ) + fs.readFileSync(path.resolve(dataFeed.witnetRequestBoard.abi), 'utf-8') ) } })) diff --git a/packages/api/src/repository/Feed.ts b/packages/api/src/repository/Feed.ts index 02b23794..4646e156 100644 --- a/packages/api/src/repository/Feed.ts +++ b/packages/api/src/repository/Feed.ts @@ -26,7 +26,9 @@ export class FeedRepository { ).map(this.normalizeId) } - async insert (feed: Omit): Promise { + async insert ( + feed: Omit + ): Promise { if (this.isValidFeed(feed)) { const response = await this.collection.insertOne(feed) @@ -38,7 +40,10 @@ export class FeedRepository { } } - async addResultRequest (feedId: ObjectId, resultRequestId: ObjectId): Promise { + async addResultRequest ( + feedId: ObjectId, + resultRequestId: ObjectId + ): Promise { const response = await this.collection.findOneAndUpdate( { _id: feedId }, { $push: { requests: resultRequestId } }, @@ -54,7 +59,10 @@ export class FeedRepository { ) } - async getFeeds (page: number, size: number): Promise> { + async getFeeds ( + page: number, + size: number + ): Promise> { return ( await this.collection .find({ address: { $in: this.dataFeedsAddresses } }) @@ -82,6 +90,6 @@ export class FeedRepository { } private isValidFeed (feed: Omit): boolean { - return !containFalsyValues(feed) + return !containFalsyValues(feed) } } diff --git a/packages/api/src/repository/ResultRequest.ts b/packages/api/src/repository/ResultRequest.ts index 7ea4c175..6387c800 100644 --- a/packages/api/src/repository/ResultRequest.ts +++ b/packages/api/src/repository/ResultRequest.ts @@ -18,7 +18,9 @@ export class ResultRequestRepository { this.dataFeedsAddresses = dataFeeds.map(dataFeed => dataFeed.address) } - async getFeedRequests (feedId: ObjectId): Promise> { + async getFeedRequests ( + feedId: ObjectId + ): Promise> { return ( await this.collection .find({ @@ -29,7 +31,11 @@ export class ResultRequestRepository { ).map(this.normalizeId) } - async getFeedRequestsPage (feedId: ObjectId, page: number, size: number): Promise> { + async getFeedRequestsPage ( + feedId: ObjectId, + page: number, + size: number + ): Promise> { return ( await this.collection .find({ @@ -42,7 +48,9 @@ export class ResultRequestRepository { ).map(this.normalizeId) } - async getLastResult (feedId: ObjectId): Promise { + async getLastResult ( + feedId: ObjectId + ): Promise { const lastResultRequest = await this.collection.findOne( { feedId: feedId.toString() @@ -61,7 +69,9 @@ export class ResultRequestRepository { return this.normalizeId(lastResultRequest) } - async insert (resultRequest: Omit): Promise { + async insert ( + resultRequest: Omit + ): Promise { if (this.isValidResultRequest(resultRequest)) { const response = await this.collection.insertOne(resultRequest) diff --git a/packages/api/src/repository/containFalsyValues.ts b/packages/api/src/repository/containFalsyValues.ts index 7e01ea3f..17d65f2b 100644 --- a/packages/api/src/repository/containFalsyValues.ts +++ b/packages/api/src/repository/containFalsyValues.ts @@ -1,3 +1,3 @@ -export function containFalsyValues(obj: Object): boolean { +export function containFalsyValues (obj: Object): boolean { return !Object.values(obj).reduce((prev, val) => prev && val) -} \ No newline at end of file +} diff --git a/packages/api/src/web3Middleware/dataFeeds.ts b/packages/api/src/web3Middleware/dataFeeds.ts deleted file mode 100644 index fb629020..00000000 --- a/packages/api/src/web3Middleware/dataFeeds.ts +++ /dev/null @@ -1,68 +0,0 @@ -// import { FeedInfo, Network, AbiItem } from '../types' -// import BtcUsdAbi from './abi/BtcUsd.json' -// import ConfluxBtcUsdAbi from './abi/ConfluxBtcUsd.json' -// import ConfluxWitnetRequestBoardProxy from './abi/ConfluxWitnetRequestBoardProxy.json' -// import WitnetRequestBoardProxy from './abi/WitnetRequestBoardProxy.json' - -// export const dataFeeds: Array = [ -// { -// abi: BtcUsdAbi as Array, -// address: '0xa3AFD68122a21c7D21Ddd95E5c077f958dA46662', -// network: Network.Goerli, -// name: 'btc/usd', -// label: '$', -// pollingPeriod: 10000, -// witnetRequestBoard: { -// address: '0x0C4be6AA667df48de54BA174bE7948875fdf152B', -// abi: WitnetRequestBoardProxy as Array -// } -// }, -// { -// abi: BtcUsdAbi as Array, -// address: '0x56834Ff8D4b27db647Da97CA3bd8540f7fA0e89D', -// network: Network.Kovan, -// name: 'btc/usd', -// label: '$', -// pollingPeriod: 15000, -// witnetRequestBoard: { -// address: '0xD9a6d1Ea0d0f4795985725C7Bd40C31a667c033d', -// abi: WitnetRequestBoardProxy as Array -// } -// }, -// { -// abi: BtcUsdAbi as Array, -// address: '0x49C0BCce51a8B28f92d008394F06d5B259657F33', -// witnetRequestBoard: { -// address: '0x9b42b0D80C428B17A5828dF5C2c96454ca54bD04', -// abi: WitnetRequestBoardProxy as Array -// }, -// network: Network.Rinkeby, -// name: 'btc/usd', -// label: '$', -// pollingPeriod: 10000 -// }, -// { -// abi: ConfluxBtcUsdAbi as Array, -// address: '0x83803e703fb38d8682b53C698B7330dfd262E949', -// witnetRequestBoard: { -// address: '0x80786fD4878c98EC22559942e533223CaA8B003F', -// abi: ConfluxWitnetRequestBoardProxy as Array -// }, -// network: Network.Conflux, -// name: 'btc/usd', -// label: '$', -// pollingPeriod: 10000 -// }, -// { -// abi: ConfluxBtcUsdAbi as Array, -// address: '0x8aE319e40dE6Cbb2226d4C449375d429d6782739', -// witnetRequestBoard: { -// address: '0x80786fD4878c98EC22559942e533223CaA8B003F', -// abi: ConfluxWitnetRequestBoardProxy as Array -// }, -// network: Network.Conflux, -// name: 'eth/usd', -// label: '$', -// pollingPeriod: 10000 -// } -// ] diff --git a/packages/api/src/web3Middleware/index.ts b/packages/api/src/web3Middleware/index.ts index f6b8ec78..2d028fdd 100644 --- a/packages/api/src/web3Middleware/index.ts +++ b/packages/api/src/web3Middleware/index.ts @@ -54,11 +54,7 @@ export class Web3Middleware { return feed }) - try { - return await Promise.all(promises) - } catch (err) { - console.error('[ERROR]', err.message) - } + return await Promise.all(promises) } async listen () { diff --git a/packages/api/test/containFalsyValues.spec.ts b/packages/api/test/containFalsyValues.spec.ts index ce0cb12c..4b02003f 100644 --- a/packages/api/test/containFalsyValues.spec.ts +++ b/packages/api/test/containFalsyValues.spec.ts @@ -4,7 +4,7 @@ describe('containFalsyValues', () => { it('should return FALSE when no falsy value is found on the object', () => { const obj = { a: 'a', - b: 'b', + b: 'b' } expect(containFalsyValues(obj)).toBe(false) @@ -13,9 +13,9 @@ describe('containFalsyValues', () => { it('should return TRUE when falsy value is found on the object', () => { const obj = { a: 'a', - b: null, + b: null } expect(containFalsyValues(obj)).toBe(true) }) -}) \ No newline at end of file +}) diff --git a/packages/api/tsconfig.json b/packages/api/tsconfig.json index b21f40b0..3a5a9f94 100644 --- a/packages/api/tsconfig.json +++ b/packages/api/tsconfig.json @@ -10,7 +10,7 @@ "noUnusedLocals": true, "noUnusedParameters": true, "resolveJsonModule": true, - "noImplicitReturns": true, + "noImplicitReturns": true }, "include": ["src/"], "exclude": ["node_modules", "test"]