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

Refactor validatePools: add more CLM validation #2467

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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@
"pause": "ts-node ./scripts/pausePlatform.ts",
"setVaultUrls": "ts-node -r dotenv/config ./scripts/setVaultUrls.ts && prettier --write ./src/config/vault/*.json",
"setVaultStatus": "ts-node -r dotenv/config ./scripts/setVaultStatus.ts",
"addClmRewardPools": "ts-node -r dotenv/config ./scripts/addClmRewardPools.ts",
"updateRewardPoolRewards": "ts-node -r dotenv/config ./scripts/updateRewardPoolRewards.ts",
"addCurveZap": "ts-node -r dotenv/config ./scripts/addCurveZap.ts",
"addBalancerZap": "ts-node -r dotenv/config ./scripts/addBalancerZap.ts",
"checkVaultTokenDecimals": "ts-node -r dotenv/config ./scripts/checkVaultTokenDecimals.ts && prettier --write ./src/config/vault/*.json",
Expand Down Expand Up @@ -115,6 +113,7 @@
"@types/react-dom": "^18.3.0",
"@types/react-router-dom": "^5.3.3",
"@vitejs/plugin-react": "^3.1.0",
"chalk": "^4.1.2",
"cross-env": "^7.0.3",
"csv-parser": "^3.0.0",
"dotenv": "^16.3.1",
Expand Down
57 changes: 57 additions & 0 deletions scripts/common/abi/BeefyOracleAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Abi } from 'viem';

export const BeefyOracleAbi = [
{
inputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
name: 'subOracle',
outputs: [
{
internalType: 'address',
name: 'oracle',
type: 'address',
},
{
internalType: 'bytes',
name: 'data',
type: 'bytes',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
{
internalType: 'address',
name: '',
type: 'address',
},
],
name: 'subOracle',
outputs: [
{
internalType: 'address',
name: 'oracle',
type: 'address',
},
{
internalType: 'bytes',
name: 'data',
type: 'bytes',
},
],
stateMutability: 'view',
type: 'function',
},
] as const satisfies Abi;
8 changes: 4 additions & 4 deletions scripts/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type ChainConfig = (typeof chainConfigs)[keyof typeof chainConfigs];
* Use `yarn makeExcludeConfig chain` to generate the hash
* Key must be the addressbook/api chain id, not app chain id (i.e. use one over harmony)
* */
export const excludeChains: Record<string, { count: number; hash: string }> = {
export const excludeChains: Partial<Record<AddressBookChainId, { count: number; hash: string }>> = {
heco: {
count: 35,
hash: 'ccab3fea9945e6474f803946d72001a04245fb2556f340ebee7a65af61be4773',
Expand Down Expand Up @@ -57,9 +57,9 @@ export const excludeChains: Record<string, { count: number; hash: string }> = {
},
};

export const excludedChainIds = Object.keys(excludeChains);
export const allChainIds: string[] = Object.keys(chainConfigs);
export const chainIds: string[] = allChainIds.filter(chainId => !(chainId in excludeChains));
export const excludedChainIds = Object.keys(excludeChains) as AddressBookChainId[];
export const allChainIds = Object.keys(chainConfigs) as AddressBookChainId[];
export const chainIds = allChainIds.filter(chainId => !(chainId in excludeChains));
export const chainRpcs: Record<string, string> = Object.fromEntries(
allChainIds.map(chainId => [
chainId,
Expand Down
26 changes: 26 additions & 0 deletions scripts/common/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
type FactoryFn<P, R> = (...props: P[]) => R;

export function createFactory<P, R>(factoryFn: FactoryFn<P, R>): FactoryFn<P, R> {
let cache: R | undefined;
return (...args: P[]): R => {
if (cache === undefined) {
cache = factoryFn(...args);
}
return cache;
};
}

export function createCachedFactory<FN extends (...args: any[]) => any>(
factoryFn: FN,
keyFn: (...args: Parameters<FN>) => string = (...args) => JSON.stringify(args)
) {
const cache: { [index: string]: ReturnType<FN> } = {};
return (...args: Parameters<FN>) => {
const index = keyFn(...args);
let value = cache[index];
if (value === undefined) {
value = cache[index] = factoryFn(...args);
}
return value;
};
}
78 changes: 78 additions & 0 deletions scripts/common/pconsole.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import chalk from 'chalk';
import { formatWithOptions, InspectOptions } from 'node:util';

class PrettyConsole {
private successTag: string = '[SUCCESS]';
private infoTag: string = '[INFO]';
private warnTag: string = '[WARN]';
private errorTag: string = '[ERROR]';
private formatOptions: InspectOptions = { colors: false };
private supportsColor: boolean = false;

constructor(color: boolean = true) {
if (color) {
this.enableColor();
}
}

enableColor() {
if (chalk.supportsColor) {
this.supportsColor = true;
this.successTag = chalk.green('success');
this.infoTag = chalk.blue('info');
this.warnTag = chalk.yellow('warn');
this.errorTag = chalk.red('error');
this.formatOptions = { colors: true };
}
}

disableColor() {
if (this.supportsColor) {
this.supportsColor = false;
this.successTag = '[SUCCESS]';
this.infoTag = '[INFO]';
this.warnTag = '[WARN]';
this.errorTag = '[ERROR]';
this.formatOptions = { colors: false };
}
}

private get columns() {
return process.stdout.columns || 80;
}

success(...args: any[]) {
console.log(this.successTag, ...args);
}

info(...args: any[]) {
console.info(this.infoTag, ...args);
}

warn(...args: any[]) {
console.warn(this.warnTag, ...args);
}

error(...args: any[]) {
console.error(this.errorTag, ...args);
}

log(...args: any[]) {
console.log(...args);
}

dim(...args: any[]) {
if (this.supportsColor) {
console.log(chalk.dim(this.format(...args)));
} else {
console.log(...args);
}
}

private format(...args: any[]) {
// should be very similar to how console.log formats to string
return formatWithOptions(this.formatOptions, ...args);
}
}

export const pconsole = new PrettyConsole();
33 changes: 33 additions & 0 deletions scripts/common/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Address, getAddress } from 'viem';

export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
const trimReg = /(^\s*)|(\s*$)/g;

export function isValidChecksumAddress(address: unknown): address is Address {
Expand Down Expand Up @@ -115,3 +116,35 @@ export async function mapValuesAsync<T, U>(
}
return result;
}

export type RetryOptions = {
retries: number;
delay: number;
onRetry?: (error: Error, attempt: number) => void;
};

const defaultRetryOptions: RetryOptions = {
retries: 5,
delay: 1000,
};

export async function withRetries<T>(
fn: () => Promise<T>,
options: RetryOptions = defaultRetryOptions
): Promise<T> {
for (let i = 0; i < options.retries; i++) {
try {
return await fn();
} catch (e) {
if (options.onRetry) {
options.onRetry(e, i);
}
await sleep(options.delay);
}
}
return fn();
}

export function isDefined<T>(value: T | undefined | null): value is Exclude<T, undefined | null> {
return value !== undefined && value !== null;
}
3 changes: 2 additions & 1 deletion scripts/pausePlatform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import { saveJson } from './common/files';
const vaultsDir = './src/config/vault/';

async function pause() {
const timestamp = Math.floor(Date.now() / 1000);
const timestamp = Math.trunc(Date.now() / 1000);
const platformId = process.argv[2];
for (const chain of chains) {
const vaultsFile = vaultsDir + chain + '.json';
const vaults = JSON.parse(await fs.readFile(vaultsFile, 'utf8'));
vaults.forEach(v => {
if (v.platformId === platformId && v.status === 'active') {
v.status = 'paused';
v.pausedAt = timestamp;
}
});
await saveJson(vaultsFile, vaults, 'prettier');
Expand Down
Loading