Skip to content

Commit

Permalink
fix: switch to private sdk (#31)
Browse files Browse the repository at this point in the history
* fix: switch to private sdk

* .npmrc

* feat: add private sdk components to dockerfile

* fix: description too long

* fix

* fix: set env to prod (#32)

* fix: overclaimed known

* feat: add tc and core support (#33)

* fix: tx

* fix: dispute bot (#34)

* fix: distrib fetching (#35)

* feat: add name to dispute bot (#36)

* feat: add name to dispute bot

* update bot names

* fix: fix referee names

---------

Co-authored-by: Baptiste Guerin <[email protected]>

* fix: merkl root computation (#37)

* fix: names

* feat: alerting delay (#38)

---------

Co-authored-by: Baptiste Guerin <[email protected]>
Co-authored-by: Baptiste Guerin <[email protected]>
Co-authored-by: Thibaud <[email protected]>
  • Loading branch information
4 people authored Dec 7, 2023
1 parent a099006 commit 3f72418
Show file tree
Hide file tree
Showing 28 changed files with 245 additions and 1,078 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ src/script/debug.ts
.env
.env.local
.vscode
.npmrc
.DS_Store
secrets*
config
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@angleprotocol:registry=https://npm.pkg.github.com
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Use an official Node.js runtime as the builder image
FROM node:16-alpine
FROM node:20-alpine

ARG GITHUB_TOKEN

ENV GITHUB_TOKEN $GITHUB_TOKEN

# Set the working directory inside the container
WORKDIR /app
Expand All @@ -10,8 +14,12 @@ COPY package.json ./
# Copy the yarn.lock file to the container
COPY yarn.lock ./

COPY .npmrc ./

# Install the app dependencies
RUN yarn install
RUN echo "//npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}" >> .npmrc
RUN yarn install --frozen-lockfile && yarn cache clean
RUN rm -f .npmrc

# Copy the tsconfig.json to be able to compile the typescript
COPY tsconfig.json ./
Expand Down
85 changes: 0 additions & 85 deletions cloudrun.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"publish-image": "chmod +x ./scripts/publish.sh && ./scripts/publish.sh"
},
"dependencies": {
"@angleprotocol/sdk": "^3.0.118",
"@angleprotocol/sdk": "0.7.2",
"@google-cloud/secret-manager": "^4.2.2",
"@octokit/rest": "19.0.13",
"@types/chai": "^4.3.6",
Expand All @@ -41,7 +41,7 @@
"devDependencies": {
"@types/express": "^4.17.13",
"@types/graceful-fs": "^4.1.5",
"@types/node": "^16.9.6",
"@types/node": "^20.9.2",
"@typescript-eslint/eslint-plugin": "^5.2.0",
"@typescript-eslint/parser": "^5.2.0",
"eslint": "^8.1.0",
Expand Down
8 changes: 6 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")
chainValues=(137 1 10 42161 1101 8453)
chainKeys=("polygon" "ethereum" "optimism" "arbitrum" "zkevm" "base" "thundercore" "core")
chainValues=(137 1 10 42161 1101 8453 108 1116)

for ((i=0; i<${#chainKeys[@]}; i++))
do
Expand All @@ -22,6 +22,10 @@ do
export CHAIN_ID=${chainValues[$i]}
yq -i '.spec.template.spec.containers[0].env[0].value= strenv(CHAIN_ID)' ./cloudrun.yaml

[[ $account = 'merkl-dispute-1' ]] && name="Chapron" || name="Pierluigi"
export BOT_NAME=$name
yq -i '.spec.template.spec.containers[0].env[2].value= strenv(BOT_NAME)' ./cloudrun.yaml

export SERVICE_ACCOUNT=merkl-dispute-sa@$account.iam.gserviceaccount.com
yq -i '.spec.template.spec.serviceAccountName= strenv(SERVICE_ACCOUNT)' ./cloudrun.yaml

Expand Down
3 changes: 2 additions & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash
account=$1
version=$2
token=$3

echo "Building docker image"
docker build -t merkl-dispute:latest --platform linux/amd64 .
docker build --build-arg GITHUB_TOKEN=$token -t merkl-dispute:latest --platform linux/amd64 .

docker tag merkl-dispute:latest europe-west1-docker.pkg.dev/$account/registry/merkl-dispute:$version

Expand Down
5 changes: 4 additions & 1 deletion scripts/publishAndDeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ read version
echo "Please enter the account to deploy to: (merkl-dispute-1 or merkl-dispute-2)"
read account

sh scripts/publish.sh $account $version
echo "Please enter Github token to download the SDK"
read token

sh scripts/publish.sh $account $version $token
bash scripts/deploy.sh $account $version
134 changes: 68 additions & 66 deletions scripts/templates/cloudrun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,72 +14,74 @@ spec:
spec:
containerConcurrency: '1'
containers:
- env:
- name: CHAINID
value: CHANGE_ME # spec.template.spec.containers.env[0].value
- name: ENV
value: dev
- name: DISPUTE_BOT_PRIVATE_KEY
valueFrom:
secretKeyRef:
key: latest
name: DISPUTE_BOT_PRIVATE_KEY
- name: PROVIDER_1
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_1
- name: PROVIDER_10
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_10
- name: PROVIDER_137
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_137
- name: PROVIDER_42161
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_42161
- name: PROVIDER_1101
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_1101
- name: PROVIDER_8453
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_8453
- name: DISCORD_TOKEN
valueFrom:
secretKeyRef:
key: latest
name: DISCORD_TOKEN
- name: KEEPER_GITHUB_AUTH_TOKEN
valueFrom:
secretKeyRef:
key: latest
name: KEEPER_GITHUB_AUTH_TOKEN
image: CHANGE_ME # spec.template.spec.containers.image
ports:
- containerPort: '5002'
name: http1
resources:
limits:
cpu: '1'
memory: 1Gi
startupProbe:
failureThreshold: 1
periodSeconds: 240
tcpSocket:
port: '5002'
timeoutSeconds: 240
- env:
- name: CHAINID
value: CHANGE_ME # spec.template.spec.containers.env[0].value
- name: ENV
value: prod
- name: BOT_NAME
value: CHANGE_ME # spec.template.spec.containers.env[2].value
- name: DISPUTE_BOT_PRIVATE_KEY
valueFrom:
secretKeyRef:
key: latest
name: DISPUTE_BOT_PRIVATE_KEY
- name: PROVIDER_1
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_1
- name: PROVIDER_10
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_10
- name: PROVIDER_137
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_137
- name: PROVIDER_42161
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_42161
- name: PROVIDER_1101
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_1101
- name: PROVIDER_8453
valueFrom:
secretKeyRef:
key: latest
name: PROVIDER_8453
- name: DISCORD_TOKEN
valueFrom:
secretKeyRef:
key: latest
name: DISCORD_TOKEN
- name: KEEPER_GITHUB_AUTH_TOKEN
valueFrom:
secretKeyRef:
key: latest
name: KEEPER_GITHUB_AUTH_TOKEN
image: CHANGE_ME # spec.template.spec.containers.image
ports:
- containerPort: '5002'
name: http1
resources:
limits:
cpu: '1'
memory: 1Gi
startupProbe:
failureThreshold: 1
periodSeconds: 240
tcpSocket:
port: '5002'
timeoutSeconds: 240
serviceAccountName: CHANGE_ME # spec.template.spec.serviceAccountName
timeoutSeconds: '600'
traffic:
- latestRevision: true
percent: 100
- latestRevision: true
percent: 100
3 changes: 1 addition & 2 deletions src/bot/dispute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const approveDisputeStake: Step = async ({ onChainProvider, chainId }, re

export const disputeTree: Step = async ({ onChainProvider, chainId }, report) => {
try {
const { disputeToken, disputeAmount } = report?.params;
const { signer } = report?.disputeReport;

const txnOverrides =
Expand All @@ -59,7 +58,7 @@ export const disputeTree: Step = async ({ onChainProvider, chainId }, report) =>
}
: {};

const disputeReceipt = await onChainProvider.sendApproveTxn(signer, disputeToken, disputeAmount, txnOverrides);
const disputeReceipt = await onChainProvider.sendDisputeTxn(signer, 'Dispute detected', txnOverrides);

return Result.Success({ ...report, disputeReport: { ...report.disputeReport, disputeReceipt } });
} catch (err) {
Expand Down
30 changes: 27 additions & 3 deletions src/bot/runner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { HOUR } from '@angleprotocol/sdk';
import { getAddress } from 'ethers/lib/utils';
import moment from 'moment';

import { NULL_ADDRESS } from '../constants';
import { ALLOWED_OVER_CLAIM, NULL_ADDRESS } from '../constants';
import { ALERTING_DELAY } from '../constants/alertingDelay';
import { buildMerklTree } from '../helpers';
import createDiffTable from '../helpers/diffTable';
import { BotError, MerklReport, Resolver, Result, Step, StepResult } from '../types/bot';
Expand Down Expand Up @@ -32,6 +35,7 @@ export const checkOnChainParams: Step = async ({ onChainProvider, logger }, repo

return Result.Success({ ...report, params });
} catch (err) {
console.error(err);
return Result.Error({ code: BotError.OnChainFetch, reason: `Unable to get on-chain params: ${err}`, report });
}
};
Expand All @@ -43,7 +47,17 @@ export const checkDisputeWindow: Step = async (context, report) => {

if (!!disputer && disputer !== NULL_ADDRESS) return Result.Exit({ reason: 'Already disputed', report });
else if (disputeToken === NULL_ADDRESS) return Result.Exit({ reason: 'No dispute token set', report });
else if (endOfDisputePeriod <= startTime) return Result.Exit({ reason: 'Not in dispute period', report });
else if (endOfDisputePeriod <= startTime) {
// Check delay since last dispute period and eventually send an alert
if (endOfDisputePeriod + ALERTING_DELAY[context.chainId] * HOUR <= startTime) {
await context.logger.error(
context,
`Last update was ${((startTime - endOfDisputePeriod) / HOUR)?.toFixed(2)} hours ago`,
BotError.AlertDelay
);
}
return Result.Exit({ reason: 'Not in dispute period', report });
}
return Result.Success(report);
} catch (err) {
return Result.Error({ code: BotError.OnChainFetch, reason: `Unable to check dispute status: ${err}`, report });
Expand Down Expand Up @@ -125,7 +139,17 @@ export const checkOverclaimedRewards: Step = async ({ onChainProvider }, report)
expandedHoldersReport = await validateClaims(onChainProvider, holdersReport);
const overclaims = expandedHoldersReport.overclaimed;

if (overclaims.length > 0) throw overclaims.join('\n');
if (
overclaims?.filter((a) => {
try {
const add = a?.split(':')[0];
return !(ALLOWED_OVER_CLAIM?.includes(add?.toLowerCase()) || ALLOWED_OVER_CLAIM?.includes(getAddress(add)));
} catch {
return true;
}
}).length > 0
)
throw overclaims.join('\n');

return Result.Success({ ...report, holdersReport: expandedHoldersReport });
} catch (reason) {
Expand Down
Loading

0 comments on commit 3f72418

Please sign in to comment.