mirror of
https://github.com/0x1d/drift-keeper.git
synced 2025-12-15 18:58:21 +01:00
Multi-Cloud Deployment (#1)
* Introduce instances list to scale bots and add config templating * Use env var for wallet address if not provided as path param * Expose SOL price as metric * Update docs * Add auto-swap * Add Panopticon * implement backoff stategy in autoswap * Add retry logic for withdraw and swap * bump drift-sdk, update ctl.sh and docs * Update filler bot, add tx metrics * Add user-metrics * Update build and dashboard
This commit is contained in:
1
wallet-tracker/.gitignore
vendored
1
wallet-tracker/.gitignore
vendored
@@ -1,2 +1 @@
|
||||
|
||||
node_modules/
|
||||
|
||||
18
wallet-tracker/README.md
Normal file
18
wallet-tracker/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Wallet-Tracker
|
||||
|
||||
## Endpoints
|
||||
|
||||
Metrics: /metrics/:wallet-address?
|
||||
If a `wallet-address` is provided in the URL, the app will fetch the metrics states from the given address.
|
||||
|
||||
If only 1 wallet needs to be tracked, it is also possible to set the `WALLET_ADDRESS` environment variable and just call the `/metrics` path.
|
||||
|
||||
## Metrics
|
||||
|
||||
Jupiter:
|
||||
- SOL Price
|
||||
|
||||
Solana:
|
||||
- SOL Balance
|
||||
- USDC Balance
|
||||
- SOL Balance in USDC
|
||||
@@ -3,24 +3,35 @@ const { createMetrics } = require('./metrics');
|
||||
const { loadWalletBalance, loadUSDCBalance, loadSolanaMarketData, extractWalletBalance, extractUSDCBalance, extractSOLPrice } = require('./solana');
|
||||
|
||||
const WALLET_ADDRESS = process.env.WALLET_ADDRESS;
|
||||
const [registry, usdcBalanceMetric, solBalanceMetric, solUsdcBalanceMetric] = createMetrics();
|
||||
const [registry, usdcBalanceMetric, solBalanceMetric, solUsdcBalanceMetric, solPriceMetric] = createMetrics();
|
||||
const app = express();
|
||||
|
||||
app.get('/metrics', async (req, res) => {
|
||||
const trimWalletAddress = (walletAddress) => {
|
||||
return `${walletAddress.slice(0,4)}...${walletAddress.slice(walletAddress.length-4, walletAddress.length)}`;
|
||||
}
|
||||
|
||||
app.get('/metrics/:addr?', async (req, res) => {
|
||||
const walletAddress = req.params.addr || WALLET_ADDRESS;
|
||||
console.log(`Gathering metrics for ${walletAddress}`);
|
||||
res.setHeader('Content-Type', registry.contentType);
|
||||
|
||||
registry.resetMetrics();
|
||||
|
||||
let [solBalance, usdcBalance, marketData] = await Promise.all([
|
||||
loadWalletBalance(WALLET_ADDRESS),
|
||||
loadUSDCBalance(WALLET_ADDRESS),
|
||||
loadWalletBalance(walletAddress),
|
||||
loadUSDCBalance(walletAddress),
|
||||
loadSolanaMarketData()]);
|
||||
|
||||
solBalanceMetric.set({ wallet: WALLET_ADDRESS}, extractWalletBalance(solBalance));
|
||||
usdcBalanceMetric.set({ wallet: WALLET_ADDRESS}, extractUSDCBalance(usdcBalance));
|
||||
solUsdcBalanceMetric.set({ wallet: WALLET_ADDRESS}, extractWalletBalance(solBalance) * extractSOLPrice(marketData));
|
||||
|
||||
let label = { wallet: walletAddress, walletShort: trimWalletAddress(walletAddress) };
|
||||
|
||||
solBalanceMetric.set(label, extractWalletBalance(solBalance));
|
||||
usdcBalanceMetric.set(label, extractUSDCBalance(usdcBalance));
|
||||
solUsdcBalanceMetric.set(label, extractWalletBalance(solBalance) * extractSOLPrice(marketData));
|
||||
solPriceMetric.set(extractSOLPrice(marketData));
|
||||
|
||||
res.send(await registry.metrics());
|
||||
});
|
||||
|
||||
app.listen(3000, () => {
|
||||
console.log("Server is running on port 3000");
|
||||
});
|
||||
});
|
||||
@@ -6,26 +6,32 @@ const createMetrics = () => {
|
||||
const solBalanceMetric = new client.Gauge({
|
||||
name: "sol_balance",
|
||||
help: "SOL Balance",
|
||||
labelNames: ['wallet']
|
||||
labelNames: ['wallet','walletShort']
|
||||
});
|
||||
const usdcBalanceMetric = new client.Gauge({
|
||||
name: "usdc_balance",
|
||||
help: "USDC Balance",
|
||||
labelNames: ['wallet']
|
||||
labelNames: ['wallet','walletShort']
|
||||
});
|
||||
const solUsdcBalanceMetric = new client.Gauge({
|
||||
name: "sol_usdc_balance",
|
||||
help: "SOL Balance in USDC",
|
||||
labelNames: ['wallet']
|
||||
labelNames: ['wallet','walletShort']
|
||||
});
|
||||
|
||||
const solPriceMetric = new client.Gauge({
|
||||
name: "sol_price",
|
||||
help: "SOL Price in USDC"
|
||||
});
|
||||
|
||||
registry.registerMetric(usdcBalanceMetric);
|
||||
registry.registerMetric(solBalanceMetric);
|
||||
registry.registerMetric(solUsdcBalanceMetric);
|
||||
registry.registerMetric(solPriceMetric);
|
||||
|
||||
return [registry, usdcBalanceMetric, solBalanceMetric, solUsdcBalanceMetric];
|
||||
return [registry, usdcBalanceMetric, solBalanceMetric, solUsdcBalanceMetric, solPriceMetric];
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
createMetrics
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user