Skip to content

Commit

Permalink
feat: merkl report
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptistG committed Feb 2, 2024
1 parent 1599074 commit a47baf0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 14 deletions.
2 changes: 2 additions & 0 deletions scripts/templates/cloudrun.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ spec:
value: prod
- name: BOT_NAME
value: CHANGE_ME # spec.template.spec.containers.env[2].value
- name: MERKL_API_URL
value: 'https://api.angle.money/v3'
- name: DISPUTE_BOT_PRIVATE_KEY
valueFrom:
secretKeyRef:
Expand Down
2 changes: 2 additions & 0 deletions src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export const ALLOWED_OVER_CLAIM = [
'0x3f9763cE4F230368437f45CE81Be598c253Db338',
'0x2A6Be69cd729288006f831737D5032f15626d52c',
];

export const MERKL_API_URL = process.env.MERKL_API_URL ? process.env.MERKL_API_URL : "https://api-staging.angle.money/v3";
35 changes: 24 additions & 11 deletions src/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { buildMerklTree } from './helpers';
import createDiffTable from './helpers/diffTable';
import ConsoleLogger from './helpers/logger/ConsoleLogger';
import blockFromTimestamp from './providers/blockNumberFromTimestamp';
import axios from 'axios';
import { MERKL_API_URL } from './constants';
import { fetchCampaigns, fetchLeaves } from './utils/merklAPI';
import { BaseTree } from './providers/tree';
import { MerklChainId } from '@angleprotocol/sdk';
import { gtStrings } from './utils/addString';

export default async function (context: DisputeContext, fromTimeStamp: number, toTimeStamp: number) {
const { onChainProvider } = context;
Expand All @@ -21,21 +27,28 @@ export default async function (context: DisputeContext, fromTimeStamp: number, t

onChainProvider.setBlock(endBlock);

// TODO - update this job to use the new logic (need to get the roots from the API)
// const startEpoch = await merkleRootsProvider.epochFromTimestamp(fromTimeStamp);
// const endEpoch = await merkleRootsProvider.epochFromTimestamp(toTimeStamp);
// const startTree = await merkleRootsProvider.fetchTreeFor(startEpoch);
// const endTree = await merkleRootsProvider.fetchTreeFor(endEpoch);

const startRootData = (await axios.get(`${MERKL_API_URL}/rootForTimestamp?chainId=${context.chainId}&timestamp=${fromTimeStamp}`)).data;
const endRootData = (await axios.get(`${MERKL_API_URL}/rootForTimestamp?chainId=${context.chainId}&timestamp=${toTimeStamp}`)).data;

const startLeaves = await fetchLeaves(context.chainId, startRootData.root);
const startTree = new BaseTree(startLeaves, context.chainId as MerklChainId);

const endLeaves = await fetchLeaves(context.chainId, endRootData.root);
const endTree = new BaseTree(endLeaves, context.chainId as MerklChainId);

// logger.trees(startEpoch, startTree, endEpoch, endTree);

// const endRoot = buildMerklTree(endTree.rewards).tree.getHexRoot();
// const startRoot = buildMerklTree(startTree.rewards).tree.getHexRoot();
const endRoot = startTree.merklRoot()
const startRoot = endTree.merklRoot()

// logger.computedRoots(startRoot, endRoot);
logger.computedRoots(startRoot, endRoot);

// const holdersReport = await validateClaims(onChainProvider, await validateHolders(onChainProvider, startTree, endTree));
const campaigns = await fetchCampaigns(context.chainId);

const { diffCampaigns, diffRecipients, negativeDiffs } = BaseTree.computeDiff(startTree, endTree, campaigns);

// const res = await createDiffTable(holdersReport.details, holdersReport.changePerDistrib, !context.uploadDiffTable);
// context.uploadDiffTable && console.log('output:', res);
console.log('diffCampaigns:', diffCampaigns);
console.log('diffRecipients:', diffRecipients);
console.log('negativeDiffs:', negativeDiffs);
}
5 changes: 2 additions & 3 deletions src/utils/merklAPI.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Campaign, CampaignParameters } from "@angleprotocol/sdk";
import axios from "axios";

const MERKL_API_URL = "https://api-staging.angle.money/v3";
import { MERKL_API_URL } from "../constants";

// TODO add retries
export async function fetchLeaves(chainId: number, root: string): Promise<any> {
Expand All @@ -16,4 +15,4 @@ export async function fetchCampaigns(chainId: number): Promise<{ [campaignId: st
campaigns[campaign.campaignId] = campaign as CampaignParameters<Campaign>;
}
return campaigns;
}
}

0 comments on commit a47baf0

Please sign in to comment.