Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/lucky-vans-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@chainlink/proof-of-reserves-adapter': major
'@chainlink/view-function-multi-chain-adapter': minor
---

USDO PoR EA Update - Remove viewFunctionIndexerResultDecimals input param
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For major need to add more details on what the NOP should do

16 changes: 1 addition & 15 deletions packages/composites/proof-of-reserves/src/endpoint/reserves.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export type TInputParameters = {
description?: string
startUTC?: string
endUTC?: string
viewFunctionIndexerResultDecimals?: number
}

const inputParameters: InputParameters<TInputParameters> = {
Expand Down Expand Up @@ -115,13 +114,6 @@ const inputParameters: InputParameters<TInputParameters> = {
type: 'string',
description: 'end time for scheduleWindow in UTC [Format HHMM]',
},
// TODO: https://smartcontract-it.atlassian.net/browse/OPDATA-3775
viewFunctionIndexerResultDecimals: {
required: false,
type: 'number',
description:
'The decimal precision of the value returned by the view-function-multi-chain indexer for the contract answer.',
},
}
export const execute: ExecuteWithConfig<Config> = async (input, context, config) => {
const validator = new Validator(input, inputParameters, config.options)
Expand Down Expand Up @@ -168,13 +160,7 @@ export const execute: ExecuteWithConfig<Config> = async (input, context, config)
validator.validated.data.indexerParams,
)

const reduceOutput = await runReduceAdapter(
indexer,
context,
balanceOutput,
indexerEndpoint,
validator.validated.data.viewFunctionIndexerResultDecimals,
)
const reduceOutput = await runReduceAdapter(indexer, context, balanceOutput, indexerEndpoint)
reduceOutput.data.description = validator.validated.data.description
return reduceOutput
}
8 changes: 1 addition & 7 deletions packages/composites/proof-of-reserves/src/utils/reduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export const runReduceAdapter = async (
context: AdapterContext,
input: AdapterResponse,
indexerEndpoint?: string,
viewFunctionIndexerResultDecimals?: number,
): Promise<AdapterResponse> => {
// Some adapters' balances come already reduced
// but needs to be converted from their base unit
Expand Down Expand Up @@ -114,15 +113,10 @@ export const runReduceAdapter = async (
}
break
case viewFunctionMultiChain.name:
if (!viewFunctionIndexerResultDecimals) {
throw new Error(
'viewFunctionIndexerResultDecimals is a required parameter when using the view-function-multi-chain indexer',
)
}
return returnParsedUnits(
input.jobRunID,
parseHexToBigInt(input.data.result).toString(),
18 - (viewFunctionIndexerResultDecimals as number),
18 - (input.data.decimals as number),
false,
18,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,6 @@ exports[`execute multiReserves endpoint should return success 1`] = `
}
`;

exports[`execute multiReserves endpoint view-function-multi-chain fails 1`] = `
{
"error": {
"feedID": "054baf47a9ff27c8384416a3ce83c17c",
"message": "viewFunctionIndexerResultDecimals is a required parameter when using the view-function-multi-chain indexer",
"name": "Error",
},
"jobRunID": "1",
"status": "errored",
"statusCode": 500,
}
`;

exports[`execute multiReserves endpoint view-function-multi-chain should return success 1`] = `
{
"data": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ describe('execute', () => {
network: 'BASE',
},
disableDuplicateAddressFiltering: true,
viewFunctionIndexerResultDecimals: 6,
},
}
mockViewFunctionMultiChainSuccess()
Expand All @@ -222,36 +221,6 @@ describe('execute', () => {
.expect(200)
expect(response.body).toMatchSnapshot()
})

it('view-function-multi-chain fails', 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',
},
disableDuplicateAddressFiltering: true,
},
}
mockViewFunctionMultiChainSuccess()

const response = await (context.req as SuperTest<Test>)
.post('/')
.send(data)
.set('Accept', '*/*')
.set('Content-Type', 'application/json')
.expect('Content-Type', /json/)
.expect(500)

expect(response.body).toMatchSnapshot()
})
})

describe('multiReserves endpoint with scaling', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const mockViewFunctionMultiChainSuccess = (): nock.Scope => {
statusCode: 200,
data: {
result: '0x000000000000000000000000000000000000000000000000FFFFFFFFFFFFFFFF',
decimals: 6,
},
metricsMeta: {
feedId:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type BaseEndpointTypes = {
Response: {
Data: {
result: string
decimals: number
}
Result: string
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@
data: encoded,
})

let decimals = await this._get_decimals(networkName, address)

Check failure on line 113 in packages/sources/view-function-multi-chain/src/transport/function-common.ts

View workflow job for this annotation

GitHub Actions / Run linters and formatters

'decimals' is never reassigned. Use 'const' instead

const timestamps = {
providerDataRequestedUnixMs,
providerDataReceivedUnixMs: Date.now(),
Expand All @@ -120,14 +122,34 @@

return {
data: {
result,
result: result,
decimals: decimals,
},
statusCode: 200,
result,
timestamps,
}
}

async _get_decimals(networkName: string, address: string): Promise<number> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do this instead? Simpler

const abi = [
  "function decimals() view returns (uint8)"
];

const token = new ethers.Contract(tokenAddress, abi, provider);
const decimals = await token.decimals();

let decimals: number = 0

Check failure on line 135 in packages/sources/view-function-multi-chain/src/transport/function-common.ts

View workflow job for this annotation

GitHub Actions / Run linters and formatters

Type number trivially inferred from a number literal, remove type annotation

try {
const decimalsIface = new ethers.Interface(['function decimals() view returns (uint8)'])
const decimalsData = decimalsIface.encodeFunctionData('decimals')
const decimalsEncoded = await this.providers[networkName].call({
to: address,
data: decimalsData,
})
const [decodedDecimals] = decimalsIface.decodeFunctionResult('decimals', decimalsEncoded)
decimals = Number(decodedDecimals)
} catch (err) {
logger.warn(`Error fetching decimals, defaulting to 0: ${err}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think defaulting to 0 is the right thing to do, we should prob throw an exception

}

return decimals
}

getSubscriptionTtlFromConfig(adapterSettings: T['Settings']): number {
return (adapterSettings as { WARMUP_SUBSCRIPTION_TTL: number }).WARMUP_SUBSCRIPTION_TTL
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports[`execute aptos-df-reader endpoint should return success 1`] = `
exports[`execute function endpoint should return success 1`] = `
{
"data": {
"decimals": 8,
"result": "0x000000000000000000000000000000000000000000000000000000005ad789f8",
},
"result": "0x000000000000000000000000000000000000000000000000000000005ad789f8",
Expand All @@ -45,6 +46,7 @@ exports[`execute function endpoint should return success 1`] = `
exports[`execute function endpoint should return success for different network 1`] = `
{
"data": {
"decimals": 24,
"result": "0x000000000000000000000000000000000000000000000000eead809f678d30f0",
},
"result": "0x000000000000000000000000000000000000000000000000eead809f678d30f0",
Expand All @@ -59,6 +61,7 @@ exports[`execute function endpoint should return success for different network 1
exports[`execute function endpoint should return success with parameters 1`] = `
{
"data": {
"decimals": 8,
"result": "0x000000000000000000000000000000000000000000000000000000005cf7ff3b",
},
"result": "0x000000000000000000000000000000000000000000000000000000005cf7ff3b",
Expand All @@ -84,6 +87,7 @@ exports[`execute function-response-selector endpoint should fail with non-exista
exports[`execute function-response-selector endpoint should return success with resultField 1`] = `
{
"data": {
"decimals": 0,
"result": "123456789",
},
"result": "123456789",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,29 @@
id: request.id,
result: '0x000000000000000000000000000000000000000000000000000000005ad789f8',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x2c1d072e956affc0d435cb7ac38ef18d24d9127c' &&
request.params[0].data === '0x313ce567' // decimals()
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x0000000000000000000000000000000000000000000000000000000000000008',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x2c1d072e956affc0d435cb7ac38ef18d24d9127c' &&
request.params[0].data ===
'0xb5ab58dc0000000000000000000000000000000000000000000000060000000000001df4'
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x000000000000000000000000000000000000000000000000000000005cf7ff3b',
}
} else if (
request.method === 'eth_call' &&

Check failure on line 62 in packages/sources/view-function-multi-chain/test/integration/fixtures.ts

View workflow job for this annotation

GitHub Actions / Run linters and formatters

This branch can never execute. Its condition is a duplicate or covered by previous conditions in the if-else-if chain
request.params[0].to === '0x2c1d072e956affc0d435cb7ac38ef18d24d9127c' &&
request.params[0].data ===
'0xb5ab58dc0000000000000000000000000000000000000000000000060000000000001df4'
Expand Down Expand Up @@ -110,6 +131,16 @@
id: request.id,
result: '0x000000000000000000000000000000000000000000000000eead809f678d30f0',
}
} else if (
request.method === 'eth_call' &&
request.params[0].to === '0x779877a7b0d9e8603169ddbd7836e478b4624789' &&
request.params[0].data === '0x313ce567' // decimals()
) {
return {
jsonrpc: '2.0',
id: request.id,
result: '0x0000000000000000000000000000000000000000000000000000000000000018',
}
} else {
// Default response for unsupported calls
return {
Expand Down
Loading