diff --git a/scripts/templates/cloudrun.yaml b/scripts/templates/cloudrun.yaml index 2db4924..ac2b059 100644 --- a/scripts/templates/cloudrun.yaml +++ b/scripts/templates/cloudrun.yaml @@ -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: diff --git a/src/constants/index.ts b/src/constants/index.ts index b2957e8..9f63877 100644 --- a/src/constants/index.ts +++ b/src/constants/index.ts @@ -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"; diff --git a/src/diff.ts b/src/diff.ts index 95e5afb..94e9d30 100644 --- a/src/diff.ts +++ b/src/diff.ts @@ -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; @@ -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}×tamp=${fromTimeStamp}`)).data; + const endRootData = (await axios.get(`${MERKL_API_URL}/rootForTimestamp?chainId=${context.chainId}×tamp=${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); } diff --git a/src/utils/merklAPI.ts b/src/utils/merklAPI.ts index 813ae53..37de78f 100644 --- a/src/utils/merklAPI.ts +++ b/src/utils/merklAPI.ts @@ -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 { @@ -16,4 +15,4 @@ export async function fetchCampaigns(chainId: number): Promise<{ [campaignId: st campaigns[campaign.campaignId] = campaign as CampaignParameters; } return campaigns; - } +}