Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/DF-20745 proof of reserves token balance #3573

Merged
merged 8 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions .changeset/swift-forks-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/proof-of-reserves-adapter': minor
---

Added token-balance indexer
1 change: 1 addition & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/composites/proof-of-reserves/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ At least one of each of the following categories must be set as an environment v
| | `POR_INDEXER_ADAPTER_URL` | The location of a Proof-of-Reserves Indexer external adapter | | |
| | `SOCHAIN_ADAPTER_URL` | The location of a SoChain external adapter | | |
| | `STADER_BALANCE_ADAPTER_URL` | The location of a Stader Balance external adapter | | |
| | `TOKEN_BALANCE_ADAPTER_URL` | The location of a Token Balance external adapter | | |

## Running

Expand All @@ -58,7 +59,7 @@ See the [Composite Adapter README](../README.md) for more information on how to
| :-------: | :--------------------------------: | :--------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :---------: |
| ✅ | `protocol` | The protocol external adapter to use | `celsius_address_list`, `chain_reserve_wallet`, `coinbase_prime`, `coinbase_prime_eth` `gemini`,`moonbeam_address_list`, `multi_address_list`, `ignition_address_list`, `list`, `por_address_list`, `renvm`, `stader_address_list`, `swell_address_list`, `wbtc`, `wrapped` | |
| | `protocolEndpoint` | Optional endpoint for the protocol external adapter to use | | |
| ✅ | `indexer` | The indexer external adapter to use | `ada_balance`, `amberdata`, `avalanche_platform`, `bitcoin_json_rpc`, `blockchain_com`. `blockchair`, `blockcypher`, `btc_com`, `cryptoapis`, `eth_balance`, `eth_beacon`, `lotus`, `polkadot_balance`, `por_indexer`, `sochain`, `stader_balance` | |
| ✅ | `indexer` | The indexer external adapter to use | `ada_balance`, `amberdata`, `avalanche_platform`, `bitcoin_json_rpc`, `blockchain_com`. `blockchair`, `blockcypher`, `btc_com`, `cryptoapis`, `eth_balance`, `eth_beacon`, `lotus`, `polkadot_balance`, `por_indexer`, `sochain`, `stader_balance`, `token_balance` | |
| | `confirmations` | The number of confirmations required for a transaction to be counted when getting an address balance | | 6 |
| | `addresses` | An array of addresses to get the balance from, when "protocol" is set to `list` | | |
| | `disableAddressValidation` | if this parameter is set to `true` address validation will be turned off | `true`, `false` | `false` |
Expand Down
1 change: 1 addition & 0 deletions packages/composites/proof-of-reserves/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@chainlink/stader-address-list-adapter": "workspace:*",
"@chainlink/stader-balance-adapter": "workspace:*",
"@chainlink/swell-address-list-adapter": "workspace:*",
"@chainlink/token-balance-adapter": "workspace:*",
"@chainlink/wbtc-address-set-adapter": "workspace:*",
"@chainlink/wrapped-adapter": "workspace:*",
"decimal.js": "^10.3.1",
Expand Down
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 @@ -95,6 +95,9 @@
},
{
"required": ["POR_INDEXER_ADAPTER_URL"]
},
{
"required": ["TOKEN_BALANCE_ADAPTER_URL"]
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type AddressObject = {
address: string
network?: string
chainId?: string
wallets?: string[]
}

const indexerToNetwork: Record<string, string> = {
Expand All @@ -16,6 +17,7 @@ const indexerToNetwork: Record<string, string> = {
avalanche_platform: 'avalanche',
bitcoin_json_rpc: 'bitcoin',
lotus: 'filecoin',
token_balance: 'multi-evm',
}

export const getValidAddresses = (
Expand Down Expand Up @@ -46,7 +48,7 @@ export const validateAddresses = (
): AddressObject[] => {
const validatedAddresses: AddressObject[] = []
for (const addressObj of addresses) {
const { address, network, chainId } = addressObj
const { address, network, chainId, wallets } = addressObj
let validatedAddress: string | undefined = undefined
let validationNetwork = network || indexerToNetwork[indexer]
// If the indexer is eth_beacon, override the validationNetwork as it might contain a different value (goerli, ethereum, mainnet...)
Expand Down Expand Up @@ -75,6 +77,15 @@ export const validateAddresses = (
case 'avalanche-fuji':
validatedAddress = getValidAvalancheAddress(id, address)
break
case 'multi-evm':
mmcallister-cll marked this conversation as resolved.
Show resolved Hide resolved
if (wallets && wallets.length) {
const validWallets = wallets
.map((wallet) => getValidEvmAddress(id, wallet))
.filter(Boolean) as string[]
addressObj.wallets = validWallets
validatedAddresses.push(addressObj)
}
break
default:
Logger.debug(
`JobId ${id}: There is no address validation procedure defined for the "${network}" network.`,
Expand Down
16 changes: 16 additions & 0 deletions packages/composites/proof-of-reserves/src/utils/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import { adapter as ethBeacon } from '@chainlink/eth-beacon-adapter'
import { adapter as lotus } from '@chainlink/lotus-adapter'
import { adapter as porIndexer } from '@chainlink/por-indexer-adapter'
import { adapter as tokenBalance } from '@chainlink/token-balance-adapter'

Check failure on line 28 in packages/composites/proof-of-reserves/src/utils/balance.ts

View workflow job for this annotation

GitHub Actions / Run Soak Tests Against Changed Adapters

Cannot find module '@chainlink/token-balance-adapter' or its corresponding type declarations.

Check failure on line 28 in packages/composites/proof-of-reserves/src/utils/balance.ts

View workflow job for this annotation

GitHub Actions / Install and verify dependencies

Cannot find module '@chainlink/token-balance-adapter' or its corresponding type declarations.

// TODO: type
export const adaptersV2: v2AdapterImplementation[] = [
Expand All @@ -47,6 +48,7 @@
avalanchePlatform,
lotus,
porIndexer,
tokenBalance,
]

// Get balances for address set
Expand All @@ -66,6 +68,9 @@
case porIndexer.name:
next = buildPorIndexerRequest(input, confirmations)
break
case tokenBalance.name:
next = buildTokenBalanceRequest(input, confirmations)
break
case ethBeacon.name:
next = {
id: input.jobRunID,
Expand Down Expand Up @@ -135,3 +140,14 @@
},
}
}

function buildTokenBalanceRequest(input: AdapterResponse, minConfirmations: number) {
return {
id: input.jobRunID,
data: {
endpoint: 'evm',
addresses: input.data.result,
minConfirmations,
},
}
}
2 changes: 2 additions & 0 deletions packages/composites/proof-of-reserves/src/utils/reduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { adapter as bitcoinPorIndexer } from '@chainlink/por-indexer-adapter'
import * as adaBalance from '@chainlink/ada-balance-adapter'
import { adapter as lotus } from '@chainlink/lotus-adapter'
import { adapter as tokenBalance } from '@chainlink/token-balance-adapter'

Check failure on line 8 in packages/composites/proof-of-reserves/src/utils/reduce.ts

View workflow job for this annotation

GitHub Actions / Run Soak Tests Against Changed Adapters

Cannot find module '@chainlink/token-balance-adapter' or its corresponding type declarations.

Check failure on line 8 in packages/composites/proof-of-reserves/src/utils/reduce.ts

View workflow job for this annotation

GitHub Actions / Install and verify dependencies

Cannot find module '@chainlink/token-balance-adapter' or its corresponding type declarations.
import { ethers } from 'ethers'

const returnParsedUnits = (jobRunID: string, result: string, units: number) => {
Expand Down Expand Up @@ -35,6 +36,7 @@
return returnParsedUnits(input.jobRunID, input.data.result as string, 8)
case lotus.name:
case adaBalance.NAME:
case tokenBalance.name:
mmcallister-cll marked this conversation as resolved.
Show resolved Hide resolved
// TODO: type makeExecute response
return returnParsedUnits(input.jobRunID, input.data.result as string, 0)
}
Expand Down
1 change: 1 addition & 0 deletions packages/composites/proof-of-reserves/test-payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const indexerEnvironmentVariables = [
{ envKey: 'BTC_COM_ADAPTER_URL', value: 'btc_com' },
{ envKey: 'CRYPTOAPIS_ADAPTER_URL', value: 'cryptoapis' },
{ envKey: 'POR_INDEXER_ADAPTER_URL', value: 'por_indexer' },
{ envKey: 'TOKEN_BALANCE_ADAPTER_URL', value: 'token_balance' },
{ envKey: 'SOCHAIN_ADAPTER_URL', value: 'sochain' },
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('execute', () => {
CACHE_ENABLED: 'false',
ETH_BALANCE_ADAPTER_URL: 'https://eth-balance-adapter.com',
POR_INDEXER_ADAPTER_URL: 'https://por-indexer-adapter.com',
TOKEN_BALANCE_ADAPTER_URL: 'https://token-balance-adapter.com',
GEMINI_ADAPTER_URL: 'https://gemini-adapter.com',
LOTUS_ADAPTER_URL: 'https://lotus-adapter.com',
}
Expand Down
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5133,6 +5133,7 @@ __metadata:
"@chainlink/stader-address-list-adapter": "workspace:*"
"@chainlink/stader-balance-adapter": "workspace:*"
"@chainlink/swell-address-list-adapter": "workspace:*"
"@chainlink/token-balance-adapter": "workspace:*"
"@chainlink/wbtc-address-set-adapter": "workspace:*"
"@chainlink/wrapped-adapter": "workspace:*"
"@types/jest": "npm:27.5.2"
Expand Down Expand Up @@ -5704,7 +5705,7 @@ __metadata:
languageName: unknown
linkType: soft

"@chainlink/token-balance-adapter@workspace:packages/sources/token-balance":
"@chainlink/token-balance-adapter@workspace:*, @chainlink/token-balance-adapter@workspace:packages/sources/token-balance":
version: 0.0.0-use.local
resolution: "@chainlink/token-balance-adapter@workspace:packages/sources/token-balance"
dependencies:
Expand Down
Loading