-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: multisig-mon * add to dockerfile and ci pipeline, need for bignumber * logger.error * safe nonces
- Loading branch information
Showing
8 changed files
with
207 additions
and
59 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
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './balance-mon/service' | ||
export * from './drippie-mon/service' | ||
export * from './fault-mon/index' | ||
export * from './multisig-mon/service' | ||
export * from './wd-mon/service' | ||
export * from './wallet-mon/service' | ||
export * from './fault-mon/index' |
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,109 @@ | ||
import { | ||
BaseServiceV2, | ||
StandardOptions, | ||
Gauge, | ||
Counter, | ||
validators, | ||
} from '@eth-optimism/common-ts' | ||
import { Provider } from '@ethersproject/abstract-provider' | ||
import { ethers } from 'ethers' | ||
|
||
import Safe from '../abi/IGnosisSafe.0.8.19.json' | ||
import { version } from '../../package.json' | ||
|
||
type MultisigMonOptions = { | ||
rpc: Provider | ||
accounts: string | ||
} | ||
|
||
type MultisigMonMetrics = { | ||
safeNonce: Gauge | ||
unexpectedRpcErrors: Counter | ||
} | ||
|
||
type MultisigMonState = { | ||
accounts: Array<{ address: string; nickname: string }> | ||
} | ||
|
||
export class MultisigMonService extends BaseServiceV2< | ||
MultisigMonOptions, | ||
MultisigMonMetrics, | ||
MultisigMonState | ||
> { | ||
constructor(options?: Partial<MultisigMonOptions & StandardOptions>) { | ||
super({ | ||
version, | ||
name: 'multisig-mon', | ||
loop: true, | ||
options: { | ||
loopIntervalMs: 60_000, | ||
...options, | ||
}, | ||
optionsSpec: { | ||
rpc: { | ||
validator: validators.provider, | ||
desc: 'Provider for network to monitor balances on', | ||
}, | ||
accounts: { | ||
validator: validators.str, | ||
desc: 'JSON array of [{ address, nickname, safe }] to monitor balances and nonces of', | ||
public: true, | ||
}, | ||
}, | ||
metricsSpec: { | ||
safeNonce: { | ||
type: Gauge, | ||
desc: 'Safe nonce', | ||
labels: ['address', 'nickname'], | ||
}, | ||
unexpectedRpcErrors: { | ||
type: Counter, | ||
desc: 'Number of unexpected RPC errors', | ||
labels: ['section', 'name'], | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
protected async init(): Promise<void> { | ||
this.state.accounts = JSON.parse(this.options.accounts) | ||
} | ||
|
||
protected async main(): Promise<void> { | ||
for (const account of this.state.accounts) { | ||
try { | ||
const safeContract = new ethers.Contract( | ||
account.address, | ||
Safe.abi, | ||
this.options.rpc | ||
) | ||
const safeNonce = await safeContract.nonce() | ||
this.logger.info(`got nonce`, { | ||
address: account.address, | ||
nickname: account.nickname, | ||
nonce: safeNonce.toString(), | ||
}) | ||
|
||
this.metrics.safeNonce.set( | ||
{ address: account.address, nickname: account.nickname }, | ||
parseInt(safeNonce.toString(), 10) | ||
) | ||
} catch (err) { | ||
this.logger.error(`got unexpected RPC error`, { | ||
section: 'safeNonce', | ||
name: 'getSafeNonce', | ||
err, | ||
}) | ||
this.metrics.unexpectedRpcErrors.inc({ | ||
section: 'safeNonce', | ||
name: 'getSafeNonce', | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
const service = new MultisigMonService() | ||
service.run() | ||
} |