Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notifications #284

Merged
merged 1 commit into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ HTTP_RPC_NODE=
## If you want notifications delivered through other channels, consider creating a notifier implementation for that channel -
## see `src/services/slackNotifier.js` for a blueprint. PRs welcome!

## If notifications are enabled, setting this enables alerts when the sentinel account balance goes below the specified threshold.
## Note that the value is in wei. Thus in order to set a threshold of 1 native token (e.g. ETH), the value should be 1000000000000000000.
#SENTINEL_BALANCE_THRESHOLD=0


## --- TECHNICAL PARAMETERS ---

Expand Down
7 changes: 4 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,10 @@ class App {
}
// create all web3 infrastructure needed
await this.client.init();
const balanceMsg = `RPC connected with chainId ${await this.client.getChainId()}`
+ this.config.OBSERVER ? "" :
`account ${this.client.accountManager.getAccountAddress(0)} has balance ${wad4human(await this.client.accountManager.getAccountBalance(0))}`;
const balanceMsg = `RPC connected with chainId ${await this.client.getChainId()}` + (
this.config.OBSERVER ? "" :
` - account ${this.client.accountManager.getAccountAddress(0)} has balance ${wad4human(await this.client.accountManager.getAccountBalance(0))}`
);
this.notifier.sendNotification(balanceMsg);

//check conditions to decide if getting snapshot data
Expand Down
2 changes: 1 addition & 1 deletion src/config/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class Config {
this.NO_REMOTE_MANIFEST = this._parseToBool(process.env.NO_REMOTE_MANIFEST, false);
this.RPC_STUCK_THRESHOLD = process.env.RPC_STUCK_THRESHOLD || (this.POLLING_INTERVAL * 4) / 1000;
this.INSTANCE_NAME = process.env.INSTANCE_NAME || "Sentinel";
this.SENTINEL_BALANCE_THRESHOLD = process.env.SENTINEL_BALANCE_THRESHOLD || 0;
this.SENTINEL_BALANCE_THRESHOLD = process.env.SENTINEL_BALANCE_THRESHOLD || "0";
}

_parseToBool(value, defaultValue = false) {
Expand Down
7 changes: 3 additions & 4 deletions src/web3client/accountManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ class AccountManager {
}

async isAccountBalanceBelowMinimum(index = 0, threshold) {
console.log("isAccountBalanceBelowMinimum index: ", index, " threshold: ", threshold);
if (!this.accounts[index]) {
throw new Error("AccountManager: account does not exist");
}
if (!BN.isBN(threshold)) {
throw new Error("AccountManager: invalid threshold");
}
const thresholdBN = new BN(threshold);

const balance = new BN(await this.getAccountBalance(index));
return {
isBelow: balance.lt(threshold),
isBelow: balance.lt(thresholdBN),
balance: balance
};
}
Expand Down
Loading