Skip to content

Commit

Permalink
feat: add gnosis to dispute bot (#39)
Browse files Browse the repository at this point in the history
* feat: add gnosis to dispute bot

* fix: add provider to cloudrun yaml

* fix: update sdk

* chore: add google provider for rewards files
  • Loading branch information
BaptistG authored Jan 15, 2024
1 parent 0fdbc0d commit e04c0ef
Show file tree
Hide file tree
Showing 8 changed files with 705 additions and 754 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.9.0
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"bot": "node ./build/index.js",
"start": "node ./build/index.js serve",
"dev": "nodemon --watch 'src/**/*.ts' --exec 'ts-node' src/index.ts serve",
"build": "tsc -p .",
"build": "tsc -p . || true",
"lint": "eslint src --fix",
"test": "mocha --require ts-node/register tests/**/*.test.ts",
"update": "chmod +x ./scripts/deploy.sh && ./scripts/deploy.sh",
Expand All @@ -20,7 +20,7 @@
"publish-image": "chmod +x ./scripts/publish.sh && ./scripts/publish.sh"
},
"dependencies": {
"@angleprotocol/sdk": "0.10.0",
"@angleprotocol/sdk": "0.25.0",
"@google-cloud/secret-manager": "^4.2.2",
"@octokit/rest": "19.0.13",
"@types/chai": "^4.3.6",
Expand Down
4 changes: 2 additions & 2 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
account=$1
version=$2

chainKeys=("polygon" "ethereum" "optimism" "arbitrum" "zkevm" "base" "thundercore" "core")
chainValues=(137 1 10 42161 1101 8453 108 1116)
chainKeys=("polygon" "ethereum" "optimism" "arbitrum" "zkevm" "base" "gnosis" "thundercore" "core")
chainValues=(137 1 10 42161 1101 8453 100 108 1116)

for ((i=0; i<${#chainKeys[@]}; i++))
do
Expand Down
5 changes: 5 additions & 0 deletions scripts/templates/cloudrun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ spec:
secretKeyRef:
key: latest
name: PROVIDER_8453
- name: PROVIDER_100
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_100
- name: DISCORD_TOKEN
valueFrom:
secretKeyRef:
Expand Down
3 changes: 2 additions & 1 deletion src/bot/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import GithubRootsProvider from '../providers/merkl-roots/GithubRootsProvider';
import MerkleRootsProvider from '../providers/merkl-roots/MerkleRootsProvider';
import OnChainProvider from '../providers/on-chain/OnChainProvider';
import RpcProvider from '../providers/on-chain/RpcProvider';
import GoogleRootsProvider from '../providers/merkl-roots/GoogleRootsProvider';

export interface DisputeContext {
chainId: ChainId;
Expand Down Expand Up @@ -39,7 +40,7 @@ export const defaultContext = (chainId: number, blockNumber?: number): DisputeCo
chainId,
blockNumber,
onChainProvider,
merkleRootsProvider: new GithubRootsProvider('https://raw.githubusercontent.com/AngleProtocol/merkl-rewards/main/', chainId),
merkleRootsProvider: new GoogleRootsProvider('https://storage.googleapis.com/merkl-production-rewards', chainId),
logger: new Loggers(loggers),
uploadDiffTable: true,
};
Expand Down
8 changes: 6 additions & 2 deletions src/providers/merkl-roots/GithubRootsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default class GithubRootsProvider extends MerkleRootsProvider {
async cacheMerklIndex(): Promise<void> {
const indexUrl = `${this.url}/index.json`;
const res = await axios.get<MerklIndexType>(indexUrl, {
timeout: 25_000,
timeout: 60_000,
maxBodyLength: Infinity,
maxContentLength: Infinity,
});

this.merklIndex = res.data;
Expand All @@ -30,7 +32,9 @@ export default class GithubRootsProvider extends MerkleRootsProvider {

try {
const res = await axios.get<AggregatedRewardsType>(rewardsUrl, {
timeout: 25_000,
timeout: 60_000,
maxBodyLength: Infinity,
maxContentLength: Infinity,
});
return res.data;
} catch (err) {
Expand Down
61 changes: 61 additions & 0 deletions src/providers/merkl-roots/GoogleRootsProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { AggregatedRewardsType } from '@angleprotocol/sdk';
import axios from 'axios';

import { ExponentialFetchParams } from '../ExponentialBackoffProvider';
import MerkleRootsProvider from './MerkleRootsProvider';

export type MerklIndexType = { [merklRoot: string]: number };

export default class GoogleRootsProvider extends MerkleRootsProvider {
url: string;
merklIndex: MerklIndexType;
chainId: number;

constructor(url: string, chainId: number, fetchParams?: ExponentialFetchParams) {
super(fetchParams);
this.url = `${url}/${chainId}`;
}

async cacheMerklIndex(): Promise<void> {
const indexUrl = `${this.url}/index.json`;
const res = await axios.get<MerklIndexType>(indexUrl, {
timeout: 60_000,
maxBodyLength: Infinity,
maxContentLength: Infinity,
});

this.merklIndex = res.data;
}

override tree = async (epoch: number) => {
const rewardsUrl = `${this.url}/backup/rewards_${epoch}.json`;

try {
const res = await axios.get<AggregatedRewardsType>(rewardsUrl, {
timeout: 60_000,
maxBodyLength: Infinity,
maxContentLength: Infinity,
});
return res.data;
} catch (err) {
console.log('??', rewardsUrl, err);
}
};

override epoch = async (root: string) => {
if (!this.merklIndex) await this.cacheMerklIndex();

return this.merklIndex[root];
};

override epochFromTimestamp = async (timestamp: number): Promise<number> => {
if (!this.merklIndex) await this.cacheMerklIndex();

let epoch = Math.floor(timestamp / 3600);

while (!Object.values(this.merklIndex).includes(epoch)) {
epoch -= 1;
}
return epoch;
};
}
Loading

0 comments on commit e04c0ef

Please sign in to comment.