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

use archive nodes only for timeseries #121

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
12 changes: 6 additions & 6 deletions scripts/gas-refund-program/staking/2.0/BPTStateTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ export default class BPTStateTracker extends AbstractStateTracker {
this.bVaultContract = new Contract(
BalancerVaultAddress, // same address for all chains
BVaultABI,
Provider.getJsonRpcProvider(this.chainId),
Provider.getArchiveJsonRpcProvider(this.chainId),
) as BVaultContract;

const poolId = Balancer_80PSP_20WETH_address[this.chainId];

this.bptAsERC20 = new Contract(
poolId,
ERC20ABI,
Provider.getJsonRpcProvider(this.chainId),
Provider.getArchiveJsonRpcProvider(this.chainId),
) as MinERC20;
}

Expand Down Expand Up @@ -161,7 +161,7 @@ export default class BPTStateTracker extends AbstractStateTracker {
),
this.startBlock,
this.endBlock,
{ batchSize: QUERY_EVENT_BATCH_SIZE_BY_CHAIN[this.chainId]}
{ batchSize: QUERY_EVENT_BATCH_SIZE_BY_CHAIN[this.chainId] },
)) as PoolBalanceChanged[];

const blockNumToTimestamp = await fetchBlockTimestampForEvents(
Expand Down Expand Up @@ -214,7 +214,7 @@ export default class BPTStateTracker extends AbstractStateTracker {
),
this.startBlock,
this.endBlock,
{ batchSize: QUERY_EVENT_BATCH_SIZE_BY_CHAIN[this.chainId]}
{ batchSize: QUERY_EVENT_BATCH_SIZE_BY_CHAIN[this.chainId] },
)) as Swap[];

const blockNumToTimestamp = await fetchBlockTimestampForEvents(
Expand Down Expand Up @@ -268,14 +268,14 @@ export default class BPTStateTracker extends AbstractStateTracker {
this.bptAsERC20.filters.Transfer(NULL_ADDRESS),
this.startBlock,
this.endBlock,
{ batchSize: QUERY_EVENT_BATCH_SIZE_BY_CHAIN[this.chainId]}
{ batchSize: QUERY_EVENT_BATCH_SIZE_BY_CHAIN[this.chainId] },
),
queryFilterBatched(
this.bptAsERC20,
this.bptAsERC20.filters.Transfer(null, NULL_ADDRESS),
this.startBlock,
this.endBlock,
{ batchSize: QUERY_EVENT_BATCH_SIZE_BY_CHAIN[this.chainId]}
{ batchSize: QUERY_EVENT_BATCH_SIZE_BY_CHAIN[this.chainId] },
),
])
).flat() as Transfer[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class ClaimableSePSP1StateTracker extends AbstractStateTracker {
this.contract = new Contract(
MerkleRedeemAddressSePSP1[this.network],
MerkleRedeemAbi,
Provider.getJsonRpcProvider(this.network),
Provider.getArchiveJsonRpcProvider(this.network),
);
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/gas-refund-program/staking/2.0/ERC20StateTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default class ERC20StateTracker extends AbstractStateTracker {
this.contract = new Contract(
contractAddress,
ERC20ABI,
Provider.getJsonRpcProvider(chainId),
Provider.getArchiveJsonRpcProvider(chainId),
);
}

Expand Down Expand Up @@ -107,7 +107,7 @@ export default class ERC20StateTracker extends AbstractStateTracker {
this.contract.filters.Transfer(),
this.startBlock,
this.endBlock,
{ batchSize: QUERY_EVENT_BATCH_SIZE_BY_CHAIN[this.chainId]}
{ batchSize: QUERY_EVENT_BATCH_SIZE_BY_CHAIN[this.chainId] },
)) as Transfer[];

logger.info(
Expand Down
18 changes: 13 additions & 5 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export const Web3Provider: { [network: number]: string } = {
[CHAIN_ID_AVALANCHE]: process.env.HTTP_PROVIDER_43114 || '',
};

export const Web3ProviderArchive: { [network: number]: string } = {
[CHAIN_ID_MAINNET]: process.env.HTTP_ARCHIVE_PROVIDER || '',
[CHAIN_ID_OPTIMISM]: process.env.HTTP_ARCHIVE_PROVIDER_10 || '',
};

// TODO: in future we can fetch it from the api directly
export const AugustusV5Address: { [network: number]: string } = {
[CHAIN_ID_MAINNET]: '0xdef171fe48cf0115b1d80b88dc8eab59176fee57',
Expand Down Expand Up @@ -95,15 +100,18 @@ export const SAFETY_MODULE_ADDRESS =

//All these must be lower-cased!
export const AUGUSTUS_V5_ADDRESS = '0xdef171fe48cf0115b1d80b88dc8eab59176fee57';
export const AUGUSTUS_V6_0_ADDRESS = '0x00000000fdac7708d0d360bddc1bc7d097f47439';
export const AUGUSTUS_V6_1_ADDRESS = '0x000db803a70511e09da650d4c0506d0000100000';
export const AUGUSTUS_V6_2_ADDRESS = '0x6a000f20005980200259b80c5102003040001068';
export const AUGUSTUS_V6_0_ADDRESS =
'0x00000000fdac7708d0d360bddc1bc7d097f47439';
export const AUGUSTUS_V6_1_ADDRESS =
'0x000db803a70511e09da650d4c0506d0000100000';
export const AUGUSTUS_V6_2_ADDRESS =
'0x6a000f20005980200259b80c5102003040001068';

export const AUGUSTUS_SWAPPERS_V6_OMNICHAIN = new Set([
AUGUSTUS_V6_0_ADDRESS,
AUGUSTUS_V6_1_ADDRESS,
AUGUSTUS_V6_2_ADDRESS
])
AUGUSTUS_V6_2_ADDRESS,
]);

export const BalancerVaultAddress =
'0xba12222222228d8ba445958a75a0704d566bf2c8';
Expand Down
44 changes: 43 additions & 1 deletion src/lib/provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonRpcProvider } from '@ethersproject/providers';
import { Web3Provider } from './constants';
import { Web3Provider, Web3ProviderArchive } from './constants';
import { retryDecorator } from 'ts-retry-promise';

// these params worked best during indexing
Expand All @@ -9,6 +9,7 @@ const RETRY_ATTEMPTS = 5;
const logger = global.LOGGER('provider');
export class Provider {
static jsonRpcProviders: { [network: number]: JsonRpcProvider } = {};
static archiveJsonRpcProviders: { [network: number]: JsonRpcProvider } = {};
static getJsonRpcProvider(network: number): JsonRpcProvider {
if (!this.jsonRpcProviders[network]) {
if (!Web3Provider[network])
Expand Down Expand Up @@ -48,4 +49,45 @@ export class Provider {

return this.jsonRpcProviders[network];
}

// COPY PASTING FROM UP
static getArchiveJsonRpcProvider(network: number): JsonRpcProvider {
if (!this.archiveJsonRpcProviders[network]) {
if (!Web3Provider[network])
throw new Error(`Provider not defined for network ${network}`);
this.archiveJsonRpcProviders[network] = new JsonRpcProvider({
url: Web3ProviderArchive[network],
timeout: TIMEOUT_MS,
});
this.archiveJsonRpcProviders[network] = new Proxy(
this.archiveJsonRpcProviders[network],
{
get: (target, prop) => {
if (prop === 'send') {
const fn = Reflect.get(target, prop).bind(target);
return async function send(
...args: Parameters<JsonRpcProvider['send']>
) {
return retryDecorator(fn, {
retries: RETRY_ATTEMPTS,
delay: DELAY_MS,
timeout: TIMEOUT_MS,
logger: msg => {
logger.warn(msg.substring(0, 200), { network });
},
})(...args);
};
}
return Reflect.get(target, prop);
},
},
);

// this.jsonRpcProviders[network].on('debug', (info: any) => {
// // logger.debug(info);
// });
}

return this.archiveJsonRpcProviders[network];
}
}