-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Tenderly Web3 Actions to monitor different RedStone smart c…
…ontracts (#212) * Implement web3 action for USDT, LSK and ETH token pairs * Add readme file for RedStone price feed monitoring * Add a little buffer in time for Web3 Actions * Apply review suggestions * Fix link inside README * Apply review suggestions
- Loading branch information
Showing
12 changed files
with
1,665 additions
and
0 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,41 @@ | ||
# RedStone Price Feed Monitoring | ||
|
||
Inside this directory, you will find the code for the RedStone Price Feed monitoring using Tenderly Web3 Actions. This code is used to monitor the price feed of the RedStone smart contracts for different token pairs and trigger alerts if the price feed was not updated for a certain period of time. In this case, the alert is sent to Opsgenie. | ||
|
||
## Install Tenderly CLI | ||
If you haven't already, install [Tenderly CLI](https://github.com/Tenderly/tenderly-cli#installation). | ||
|
||
Before you go on, you need to login with CLI, using your Tenderly credentials: | ||
|
||
```bash | ||
tenderly login | ||
``` | ||
|
||
## Build and Publish/Deploy Web3 Actions | ||
|
||
Before you can build and publish/deploy the Web3 Actions, you need modify the configuration `.yaml` file for the project. | ||
Some configuration files inside this directory are: | ||
- [`lskUsd.yaml`](./lskUsd.yaml) - configuration file for the RedStone price feed monitoring for the LSK/USD token pair | ||
- [`ethUsd.yaml`](./ethUsd.yaml) - configuration file for the RedStone price feed monitoring for the ETH/USD token pair | ||
- [`usdtUsd.yaml`](./usdtUsd.yaml) - configuration file for the RedStone price feed monitoring for the USDT/USD token pair | ||
|
||
You need to provide the following information in the configuration file(s), under `actions`: | ||
- `YOUR_ACCOUNT_SLUG` - your Tenderly account | ||
- `YOUR_PROJECT_SLUG` - your Tenderly project | ||
|
||
**Note**: Both of the above values can be accessed from the Settings page on your Tenderly dashboard. | ||
|
||
To build different Web3 Actions, run the following command: | ||
|
||
```bash | ||
tenderly actions build --project-config [yaml_filename_without_extension] | ||
``` | ||
|
||
To publish/deploy the Web3 Actions, run the following command: | ||
|
||
```bash | ||
tenderly actions publish --project-config [yaml_filename_without_extension] | ||
or | ||
tenderly actions deploy --project-config [yaml_filename_without_extension] | ||
``` | ||
`publish` is used to publish the Web3 Actions to the Tenderly platform without deploying them. |
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,13 @@ | ||
actions: | ||
YOUR_ACCOUNT_SLUG/YOUR_PROJECT_SLUG: | ||
runtime: v2 | ||
sources: tokenPairMonitor | ||
specs: | ||
RedStonePriceFeed_ETH-USD: | ||
description: Check if token pair price for ETH/USD is updated at least once every 6 hours. | ||
function: ethUsd:monitorEthUsdFn | ||
trigger: | ||
type: periodic | ||
periodic: | ||
interval: 1h | ||
execution_type: parallel |
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,13 @@ | ||
actions: | ||
YOUR_ACCOUNT_SLUG/YOUR_PROJECT_SLUG: | ||
runtime: v2 | ||
sources: tokenPairMonitor | ||
specs: | ||
RedStonePriceFeed_LSK-USD: | ||
description: Check if token pair price for LSK/USD is updated at least once every 6 hours. | ||
function: lskUsd:monitorLskUsdFn | ||
trigger: | ||
type: periodic | ||
periodic: | ||
interval: 1h | ||
execution_type: parallel |
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,5 @@ | ||
# Dependency directories | ||
node_modules/ | ||
|
||
# Ignore tsc output | ||
out/**/* |
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,24 @@ | ||
import { | ||
ActionFn, | ||
Context, | ||
Event, | ||
PeriodicEvent, | ||
} from '@tenderly/actions'; | ||
import { checkTokenPairPriceUpdateTime } from './validate'; | ||
|
||
// Define the contract address and token pair | ||
const CONTRACT_ADDRESS = "0x6b7AB4213c77A671Fc7AEe8eB23C9961fDdaB3b2"; | ||
const TOKEN_PAIR = "ETH/USD"; | ||
|
||
export const monitorEthUsdFn: ActionFn = async (context: Context, event: Event) => { | ||
const periodicEvent = event as PeriodicEvent; | ||
console.log(periodicEvent); | ||
|
||
// Get Opsgenie API key from the secrets | ||
const apiKey = await context.secrets.get("OPSGENIE_API_KEY"); | ||
|
||
// Current time in seconds | ||
const currentTimestamp = Math.floor(periodicEvent.time.getTime() / 1000); | ||
|
||
await checkTokenPairPriceUpdateTime(CONTRACT_ADDRESS, TOKEN_PAIR, apiKey, currentTimestamp); | ||
} |
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,24 @@ | ||
import { | ||
ActionFn, | ||
Context, | ||
Event, | ||
PeriodicEvent, | ||
} from '@tenderly/actions'; | ||
import { checkTokenPairPriceUpdateTime } from './validate'; | ||
|
||
// Define the contract address and token pair | ||
const CONTRACT_ADDRESS = "0xa1EbA9E63ed7BA328fE0778cFD67699F05378a96"; | ||
const TOKEN_PAIR = "LSK/USD"; | ||
|
||
export const monitorLskUsdFn: ActionFn = async (context: Context, event: Event) => { | ||
const periodicEvent = event as PeriodicEvent; | ||
console.log(periodicEvent); | ||
|
||
// Get Opsgenie API key from the secrets | ||
const apiKey = await context.secrets.get("OPSGENIE_API_KEY"); | ||
|
||
// Current time in seconds | ||
const currentTimestamp = Math.floor(periodicEvent.time.getTime() / 1000); | ||
|
||
await checkTokenPairPriceUpdateTime(CONTRACT_ADDRESS, TOKEN_PAIR, apiKey, currentTimestamp); | ||
} |
Oops, something went wrong.