-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add gnosis to dispute bot (#39)
* 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
Showing
8 changed files
with
705 additions
and
754 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v20.9.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
} |
Oops, something went wrong.