Skip to content

Commit

Permalink
Integrate with ETHEREUM_CL_INDEXER (#3686)
Browse files Browse the repository at this point in the history
* Integrate with ETHEREUM_CL_INDEXER

* optional
  • Loading branch information
mxiao-cll authored Feb 18, 2025
1 parent 2d7b5a8 commit 6ac4280
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 38 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-suits-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/proof-of-reserves-adapter': minor
---

Integrate with ETHEREUM_CL_INDEXER
65 changes: 33 additions & 32 deletions packages/composites/proof-of-reserves/README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/composites/proof-of-reserves/schemas/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
},
{
"required": ["CEFFU_ADAPTER_URL"]
},
{
"required": ["ETHEREUM_CL_INDEXER_ADAPTER_URL"]
}
]
}
Expand Down
8 changes: 7 additions & 1 deletion packages/composites/proof-of-reserves/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Requester, util } from '@chainlink/ea-bootstrap'
import { DefaultConfig } from '@chainlink/ea-bootstrap'
import { adaptersV2 as BalanceAdaptersV2, adaptersV3 as BalanceAdaptersV3 } from '../utils/balance'
import {
adaptersV2 as BalanceAdaptersV2,
adaptersV3 as BalanceAdaptersV3,
ETHEREUM_CL_INDEXER,
} from '../utils/balance'
import {
adaptersV2 as ProtocolAdaptersV2,
adaptersV3 as ProtocolAdaptersV3,
Expand Down Expand Up @@ -60,5 +64,7 @@ export const makeOptions = (): Options => {
}
options.protocol.push(LIST_ADAPTER)
options.protocol.push(LIST_ADAPTER.toLowerCase())
options.indexer.push(ETHEREUM_CL_INDEXER)
options.indexer.push(ETHEREUM_CL_INDEXER.toLowerCase())
return options
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
adaptersV2 as indexerAdaptersV2,
adaptersV3 as indexerAdaptersV3,
runBalanceAdapter,
ETHEREUM_CL_INDEXER,
} from '../utils/balance'
import {
adaptersV2 as protocolAdaptersV2,
Expand Down Expand Up @@ -58,6 +59,7 @@ const inputParameters: InputParameters<TInputParameters> = {
...indexerAdaptersV2.map(({ NAME }) => NAME.toUpperCase()),
...indexerAdaptersV3.map(({ name }) => name.toLowerCase()),
...indexerAdaptersV3.map(({ name }) => name.toUpperCase()),
ETHEREUM_CL_INDEXER,
],
},
indexerEndpoint: {
Expand Down Expand Up @@ -118,7 +120,9 @@ export const execute: ExecuteWithConfig<Config> = async (input, context, config)
config,
validator.validated.data.protocolEndpoint,
)

const validatedAddresses = getValidAddresses(protocolOutput, validator)

const balanceOutput = await runBalanceAdapter(
indexer,
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const validateAddresses = (
for (const addressObj of addresses) {
const { address, network, chainId, contractAddress, wallets } = addressObj
let validatedAddress: string | undefined = undefined
let validationNetwork = network || indexerToNetwork[indexer]
let validationNetwork = network || indexerToNetwork[indexer] || ''
// If the indexer is eth_beacon, override the validationNetwork as it might contain a different value (goerli, ethereum, mainnet...)
validationNetwork = indexer === 'eth_beacon' ? 'beacon' : validationNetwork

Expand Down
5 changes: 4 additions & 1 deletion packages/composites/proof-of-reserves/src/utils/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { adapter as porIndexer } from '@chainlink/por-indexer-adapter'
import { adapter as tokenBalance } from '@chainlink/token-balance-adapter'
import { adapter as ceffu } from '@chainlink/ceffu-adapter'

export const ETHEREUM_CL_INDEXER = 'ETHEREUM_CL_INDEXER'

// TODO: type
export const adaptersV2: v2AdapterImplementation[] = [
amberdata as unknown as v2AdapterImplementation,
Expand Down Expand Up @@ -63,7 +65,8 @@ export const runBalanceAdapter = async (
indexerEndpoint?: string,
indexerParams?: Record<string, string>,
): Promise<AdapterResponse> => {
const execute = makeRequestFactory(config, indexer)
const postfix = indexer == ETHEREUM_CL_INDEXER ? '/' + indexerEndpoint : ''
const execute = makeRequestFactory(config, indexer, postfix)
let next
switch (indexer) {
case bitcoinJsonRpc.NAME:
Expand Down
4 changes: 2 additions & 2 deletions packages/composites/proof-of-reserves/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import {
} from '@chainlink/ea-bootstrap'

export const makeRequestFactory =
(config: Config, prefix: string): Execute =>
(config: Config, prefix: string, postfix = ''): Execute =>
async (input: AdapterRequest) =>
(
await Requester.request({
...config.api,
method: 'post',
url: util.getURL(prefix, true),
url: (util.getURL(prefix, true) || '') + postfix,
data: input,
})
).data as AdapterResponse
Expand Down
20 changes: 19 additions & 1 deletion packages/composites/proof-of-reserves/src/utils/reduce.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as reduce from '@chainlink/reduce-adapter'
import { AdapterContext, AdapterResponse } from '@chainlink/ea-bootstrap'
import { AdapterContext, AdapterError, AdapterResponse } from '@chainlink/ea-bootstrap'
import { callAdapter } from '.'
import * as bitcoinJsonRpc from '@chainlink/bitcoin-json-rpc-adapter'
import { adapter as bitcoinPorIndexer } from '@chainlink/por-indexer-adapter'
Expand All @@ -8,6 +8,7 @@ import { adapter as lotus } from '@chainlink/lotus-adapter'
import { adapter as tokenBalance } from '@chainlink/token-balance-adapter'
import { adapter as ceffu } from '@chainlink/ceffu-adapter'
import { ethers } from 'ethers'
import { ETHEREUM_CL_INDEXER } from './balance'

const returnParsedUnits = (
jobRunID: string,
Expand Down Expand Up @@ -56,6 +57,23 @@ export const runReduceAdapter = async (
case adaBalance.NAME:
// TODO: type makeExecute response
return returnParsedUnits(input.jobRunID, input.data.result as string, 0)
case ETHEREUM_CL_INDEXER:
if (input.data.isValid) {
return {
jobRunID: input.jobRunID,
result: input.data.totalBalance as string,
statusCode: 200,
data: {
result: input.data.totalBalance as string,
statusCode: 200,
},
}
} else {
throw new AdapterError({
statusCode: 400,
message: `ETHEREUM_CL_INDEXER ripcord is true: ${JSON.stringify(input.data)}`,
})
}
}

const next = {
Expand Down

0 comments on commit 6ac4280

Please sign in to comment.