diff --git a/.changeset/plenty-garlics-sort.md b/.changeset/plenty-garlics-sort.md new file mode 100644 index 0000000000..2f59ee1bcd --- /dev/null +++ b/.changeset/plenty-garlics-sort.md @@ -0,0 +1,5 @@ +--- +'@chainlink/proof-of-reserves-adapter': minor +--- + +Add support for decimals value being returned by view-function-multi-chain diff --git a/packages/composites/proof-of-reserves/src/utils/reduce.ts b/packages/composites/proof-of-reserves/src/utils/reduce.ts index 727186ee14..08c379660d 100644 --- a/packages/composites/proof-of-reserves/src/utils/reduce.ts +++ b/packages/composites/proof-of-reserves/src/utils/reduce.ts @@ -113,19 +113,28 @@ export const runReduceAdapter = async ( }) } break - case viewFunctionMultiChain.name: - if (!viewFunctionIndexerResultDecimals) { + case viewFunctionMultiChain.name: { + let decimalsOffset: number + + const decimalsHex = input.data.decimals + if (decimalsHex != null) { + decimalsOffset = 18 - Number(decimalsHex) + } else if (viewFunctionIndexerResultDecimals != null) { + decimalsOffset = 18 - Number(viewFunctionIndexerResultDecimals) + } else { throw new Error( - 'viewFunctionIndexerResultDecimals is a required parameter when using the view-function-multi-chain indexer', + `Missing decimals: neither input.data.decimals nor viewFunctionIndexerResultDecimals provided`, ) } + return returnParsedUnits( input.jobRunID, parseHexToBigInt(input.data.result).toString(), - 18 - (viewFunctionIndexerResultDecimals as number), + decimalsOffset, false, 18, ) + } } const next = { diff --git a/packages/composites/proof-of-reserves/test/integration/__snapshots__/adapter.test.ts.snap b/packages/composites/proof-of-reserves/test/integration/__snapshots__/adapter.test.ts.snap index 8c69196fa5..c7c91bf788 100644 --- a/packages/composites/proof-of-reserves/test/integration/__snapshots__/adapter.test.ts.snap +++ b/packages/composites/proof-of-reserves/test/integration/__snapshots__/adapter.test.ts.snap @@ -67,11 +67,11 @@ exports[`execute multiReserves endpoint should return success 1`] = ` } `; -exports[`execute multiReserves endpoint view-function-multi-chain fails 1`] = ` +exports[`execute multiReserves endpoint view-function-multi-chain should fail 1`] = ` { "error": { "feedID": "054baf47a9ff27c8384416a3ce83c17c", - "message": "viewFunctionIndexerResultDecimals is a required parameter when using the view-function-multi-chain indexer", + "message": "Missing decimals: neither input.data.decimals nor viewFunctionIndexerResultDecimals provided", "name": "Error", }, "jobRunID": "1", @@ -80,6 +80,19 @@ exports[`execute multiReserves endpoint view-function-multi-chain fails 1`] = ` } `; +exports[`execute multiReserves endpoint view-function-multi-chain should return success - decimals value 1`] = ` +{ + "data": { + "decimals": 18, + "result": "184467440737095516150000000000", + "statusCode": 200, + }, + "jobRunID": "1", + "result": "184467440737095516150000000000", + "statusCode": 200, +} +`; + exports[`execute multiReserves endpoint view-function-multi-chain should return success 1`] = ` { "data": { diff --git a/packages/composites/proof-of-reserves/test/integration/adapter.test.ts b/packages/composites/proof-of-reserves/test/integration/adapter.test.ts index 87707ac572..4c696e512f 100644 --- a/packages/composites/proof-of-reserves/test/integration/adapter.test.ts +++ b/packages/composites/proof-of-reserves/test/integration/adapter.test.ts @@ -9,6 +9,7 @@ import { mockLotusSuccess, mockPoRindexerSuccess, mockViewFunctionMultiChainSuccess, + mockViewFunctionMultiChainSuccess2, } from './fixtures' describe('execute', () => { @@ -223,7 +224,41 @@ describe('execute', () => { expect(response.body).toMatchSnapshot() }) - it('view-function-multi-chain fails', async () => { + it('view-function-multi-chain should return success - decimals value', async () => { + const data: AdapterRequest = { + id: '1', + data: { + endpoint: 'reserves', + protocol: 'list', + addresses: [''], + indexer: 'view_function_multi_chain', + indexerEndpoint: 'function', + indexerParams: { + signature: 'function getPending() public view returns (uint256)', + address: '0xa69b964a597435A2F938cc55FaAbe34F2A9AF278', + network: 'BASE', + data: { + decimals: { + signature: 'function decimals() view returns (uint8)', + }, + }, + }, + disableDuplicateAddressFiltering: true, + }, + } + mockViewFunctionMultiChainSuccess2() + + const response = await (context.req as SuperTest) + .post('/') + .send(data) + .set('Accept', '*/*') + .set('Content-Type', 'application/json') + .expect('Content-Type', /json/) + .expect(200) + expect(response.body).toMatchSnapshot() + }) + + it('view-function-multi-chain should fail', async () => { const data: AdapterRequest = { id: '1', data: { @@ -249,7 +284,6 @@ describe('execute', () => { .set('Content-Type', 'application/json') .expect('Content-Type', /json/) .expect(500) - expect(response.body).toMatchSnapshot() }) }) diff --git a/packages/composites/proof-of-reserves/test/integration/fixtures.ts b/packages/composites/proof-of-reserves/test/integration/fixtures.ts index 6b06643bbe..0d0a92adf8 100644 --- a/packages/composites/proof-of-reserves/test/integration/fixtures.ts +++ b/packages/composites/proof-of-reserves/test/integration/fixtures.ts @@ -17,6 +17,24 @@ export const mockViewFunctionMultiChainSuccess = (): nock.Scope => { }) } +export const mockViewFunctionMultiChainSuccess2 = (): nock.Scope => { + return nock('https://view-function-multi-chain-adapter.com') + .post('/') + .reply(200, { + jobRunID: '1', + result: '0x000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFF', + statusCode: 200, + data: { + result: '0x000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFF', + decimals: '0x0000000000000000000000000000000000000000000000000000000000000008', + }, + metricsMeta: { + feedId: + '{"signature":"function getpending() public view returns (uint256)","address":"0xa69b964a597435a2f938cc55faabe34f2a9af278","inputParams":[],"network":"base"}', + }, + }) +} + export const mockPoRindexerSuccess = (): nock.Scope => { return nock('https://por-indexer-adapter.com') .post('/')