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

Lombard PoR address #3623

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions .changeset/bright-shirts-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@chainlink/por-address-list-adapter': minor
---

Add Lombard PoR
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
[
{ "inputs": [], "name": "AccessControlBadConfirmation", "type": "error" },
{
"inputs": [
{ "internalType": "address", "name": "account", "type": "address" },
{ "internalType": "bytes32", "name": "neededRole", "type": "bytes32" }
],
"name": "AccessControlUnauthorizedAccount",
"type": "error"
},
{
"inputs": [{ "internalType": "string", "name": "addressStr", "type": "string" }],
"name": "AddressAlreadyExists",
"type": "error"
},
{
"inputs": [{ "internalType": "string", "name": "addressStr", "type": "string" }],
"name": "AddressDoesNotExist",
"type": "error"
},
{ "inputs": [], "name": "ArrayLengthMismatch", "type": "error" },
{ "inputs": [], "name": "InvalidInitialization", "type": "error" },
{
"inputs": [
{ "internalType": "string", "name": "addressStr", "type": "string" },
{ "internalType": "string", "name": "messageOrPath", "type": "string" },
{ "internalType": "bytes", "name": "signature", "type": "bytes" }
],
"name": "InvalidMessageSignature",
"type": "error"
},
{ "inputs": [], "name": "InvalidRootPubkey", "type": "error" },
{
"inputs": [{ "internalType": "bytes32", "name": "id", "type": "bytes32" }],
"name": "InvalidRootPubkeyId",
"type": "error"
},
{ "inputs": [], "name": "NotInitializing", "type": "error" },
{
"inputs": [{ "internalType": "bytes", "name": "pubkey", "type": "bytes" }],
"name": "RootPubkeyAlreadyExists",
"type": "error"
},
{ "inputs": [], "name": "RootPubkeyCannotBeDeleted", "type": "error" },
{
"inputs": [{ "internalType": "bytes", "name": "pubkey", "type": "bytes" }],
"name": "RootPubkeyDoesNotExist",
"type": "error"
},
{
"anonymous": false,
"inputs": [{ "indexed": false, "internalType": "uint64", "name": "version", "type": "uint64" }],
"name": "Initialized",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "bytes32", "name": "role", "type": "bytes32" },
{
"indexed": true,
"internalType": "bytes32",
"name": "previousAdminRole",
"type": "bytes32"
},
{ "indexed": true, "internalType": "bytes32", "name": "newAdminRole", "type": "bytes32" }
],
"name": "RoleAdminChanged",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "indexed": true, "internalType": "address", "name": "account", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" }
],
"name": "RoleGranted",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "indexed": true, "internalType": "address", "name": "account", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "sender", "type": "address" }
],
"name": "RoleRevoked",
"type": "event"
},
{
"inputs": [],
"name": "DEFAULT_ADMIN_ROLE",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "OPERATOR_ROLE",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "string[]", "name": "_addresses", "type": "string[]" },
{ "internalType": "bytes32[]", "name": "_rootPkIds", "type": "bytes32[]" },
{ "internalType": "string[]", "name": "_messagesOrDerivationData", "type": "string[]" },
{ "internalType": "bytes[]", "name": "_signatures", "type": "bytes[]" }
],
"name": "addAddresses",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes", "name": "_pubkey", "type": "bytes" }],
"name": "addRootPubkey",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "string[]", "name": "_addresses", "type": "string[]" }],
"name": "deleteAddresses",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes", "name": "_pubkey", "type": "bytes" }],
"name": "deleteRootPubkey",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "getPoRAddressListLength",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "uint256", "name": "_start", "type": "uint256" },
{ "internalType": "uint256", "name": "_end", "type": "uint256" }
],
"name": "getPoRAddressSignatureMessages",
"outputs": [
{ "internalType": "string[]", "name": "", "type": "string[]" },
{ "internalType": "bytes32[]", "name": "", "type": "bytes32[]" },
{ "internalType": "string[]", "name": "", "type": "string[]" },
{ "internalType": "bytes[]", "name": "", "type": "bytes[]" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "string[]", "name": "_addresses", "type": "string[]" }],
"name": "getPoRSignatureMessages",
"outputs": [
{ "internalType": "bytes32[]", "name": "", "type": "bytes32[]" },
{ "internalType": "string[]", "name": "", "type": "string[]" },
{ "internalType": "bytes[]", "name": "", "type": "bytes[]" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes32", "name": "role", "type": "bytes32" }],
"name": "getRoleAdmin",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes32", "name": "_id", "type": "bytes32" }],
"name": "getRootPubkey",
"outputs": [{ "internalType": "bytes", "name": "", "type": "bytes" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"name": "grantRole",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"name": "hasRole",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [{ "internalType": "address", "name": "_owner", "type": "address" }],
"name": "initialize",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "internalType": "address", "name": "callerConfirmation", "type": "address" }
],
"name": "renounceRole",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{ "internalType": "bytes32", "name": "role", "type": "bytes32" },
{ "internalType": "address", "name": "account", "type": "address" }
],
"name": "revokeRole",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes4", "name": "interfaceId", "type": "bytes4" }],
"name": "supportsInterface",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{ "internalType": "string[]", "name": "_addresses", "type": "string[]" },
{ "internalType": "string[]", "name": "_messages", "type": "string[]" },
{ "internalType": "bytes[]", "name": "_signatures", "type": "bytes[]" }
],
"name": "updateMessageSignature",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
7 changes: 7 additions & 0 deletions packages/sources/por-address-list/src/endpoint/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ export const inputParameters = new InputParameters(
type: 'boolean',
description: 'Flag to pass on to the balance adapter to search for limbo validators',
},
abiName: {
type: 'string',
options: ['Lombard', 'Default'],
description: 'The name of ABI used for contractAddress',
default: 'Default',
},
},
[
{
Expand All @@ -53,6 +59,7 @@ export const inputParameters = new InputParameters(
batchSize: 10,
network: 'ethereum',
chainId: '1',
abiName: 'Default',
},
],
)
Expand Down
34 changes: 22 additions & 12 deletions packages/sources/por-address-list/src/transport/address.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { SubscriptionTransport } from '@chainlink/external-adapter-framework/transports/abstract/subscription'
import { EndpointContext } from '@chainlink/external-adapter-framework/adapter'
import { PoRAddress } from '@chainlink/external-adapter-framework/adapter/por'
import { TransportDependencies } from '@chainlink/external-adapter-framework/transports'
import { AdapterResponse, sleep } from '@chainlink/external-adapter-framework/util'
import { POR_ADDRESS_LIST_ABI } from '../config/abi'
import { POR_ADDRESS_LIST_ABI } from '../config/PorAddressList'
import LOMBARD_POR_ADDRESS_LIST_ABI from '../config/LombardPorAddressList.json'
import { BaseEndpointTypes, inputParameters } from '../endpoint/address'
import { ethers } from 'ethers'
import { fetchAddressList, addProvider, getProvider } from './utils'
import { addProvider, getProvider } from './providerUtils'
import { DefaultAddressManager, LombardAddressManager, AddressManager } from './addressManager'

export type AddressTransportTypes = BaseEndpointTypes

Expand Down Expand Up @@ -61,6 +62,8 @@ export class AddressTransport extends SubscriptionTransport<AddressTransportType
async _handleRequest(
param: RequestParams,
): Promise<AdapterResponse<AddressTransportTypes['Response']>> {
const providerDataRequestedUnixMs = Date.now()

const {
confirmations,
contractAddress,
Expand All @@ -69,27 +72,34 @@ export class AddressTransport extends SubscriptionTransport<AddressTransportType
network,
chainId,
searchLimboValidators,
abiName,
} = param

this.providersMap = addProvider(contractAddressNetwork, this.providersMap)
const provider = getProvider(contractAddressNetwork, this.providersMap, this.provider)

const addressManager = new ethers.Contract(contractAddress, POR_ADDRESS_LIST_ABI, provider)
let addressManager: AddressManager<string[] | string[][]>

if (abiName == 'Lombard') {
addressManager = new LombardAddressManager(
contractAddress,
LOMBARD_POR_ADDRESS_LIST_ABI,
provider,
)
} else {
addressManager = new DefaultAddressManager(contractAddress, POR_ADDRESS_LIST_ABI, provider)
}

const latestBlockNum = await provider.getBlockNumber()

const providerDataRequestedUnixMs = Date.now()
const addressList = await fetchAddressList<string>(
addressManager,
const addressList = await addressManager.fetchAddressList(
latestBlockNum,
confirmations,
batchSize,
this.settings.GROUP_SIZE,
)
const addresses: PoRAddress[] = addressList.map((address) => ({
address,
network,
chainId,
}))

const addresses = addressManager.processPoRAddressList(addressList, network, chainId)

return {
data: {
Expand Down
Loading
Loading