Skip to content

Commit

Permalink
Merge pull request #49 from VenusProtocol/develop
Browse files Browse the repository at this point in the history
Release new Keeper Bots package
  • Loading branch information
coreyar authored Aug 16, 2024
2 parents 7c6ca40 + d054cc5 commit 666d546
Show file tree
Hide file tree
Showing 72 changed files with 371 additions and 458 deletions.
4 changes: 2 additions & 2 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ cache
coverage
dist
typechain
packages/token-converter-bot/src/config/abis/generated.ts
packages/token-converter-bot/subgraph-client/.graphqlclient
packages/keeper-bots/src/config/abis/generated.ts
packages/keeper-bots/subgraph-client/.graphqlclient
12 changes: 6 additions & 6 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
env:
THE_GRAPH_STUDIO_API_KEY: ${{ secrets.THE_GRAPH_STUDIO_API_KEY }}
run: |
yarn workspace @venusprotocol/token-converter-bot run generate-abis
yarn workspace @venusprotocol/token-converter-bot run generate-subgraph-types
yarn workspace @venusprotocol/keeper-bots run generate-abis
yarn workspace @venusprotocol/keeper-bots run generate-subgraph-types
- name: Build Keeper Bot Contracts
run: yarn workspace @venusprotocol/keeper-bot-contracts run build
Expand All @@ -50,12 +50,12 @@ jobs:
- name: Install dependencies
run: yarn

- name: Build Token Converter Bots
- name: Build Keeper Bots
env:
THE_GRAPH_STUDIO_API_KEY: ${{ secrets.THE_GRAPH_STUDIO_API_KEY }}
run: yarn workspace @venusprotocol/token-converter-bot run build
run: yarn workspace @venusprotocol/keeper-bots run build

- name: Release Token Converter Bot
- name: Release Keeper Bot
if: ${{ always() }}
env:
THE_GRAPH_STUDIO_API_KEY: ${{ secrets.THE_GRAPH_STUDIO_API_KEY }}
Expand All @@ -65,7 +65,7 @@ jobs:
GIT_AUTHOR_EMAIL: tools@venus.io
GIT_COMMITTER_NAME: Venus Tools
GIT_COMMITTER_EMAIL: tools@venus.io
run: yarn workspace @venusprotocol/token-converter-bot run semantic-release
run: yarn workspace @venusprotocol/keeper-bots run semantic-release

- name: Install dependencies
run: yarn
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ jobs:

- name: Prepare
run: |
yarn workspace @venusprotocol/token-converter-bot run generate-abis
yarn workspace @venusprotocol/token-converter-bot run generate-subgraph-types
yarn workspace @venusprotocol/keeper-bots run generate-abis
yarn workspace @venusprotocol/keeper-bots run generate-subgraph-types
- name: Check linting of solidity and typescript
run: yarn lint
Expand All @@ -51,8 +51,8 @@ jobs:

- name: Prepare tests
run: |
yarn workspace @venusprotocol/token-converter-bot run generate-abis
yarn workspace @venusprotocol/token-converter-bot run generate-subgraph-types
yarn workspace @venusprotocol/keeper-bots run generate-abis
yarn workspace @venusprotocol/keeper-bots run generate-subgraph-types
- name: Run hardhat compile and tests coverage
run: |
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ artifacts
!.yarn/versions

# Generated files
packages/token-converter-bot/src/config/abis/generated.ts
packages/token-converter-bot/src/subgraph-client/.graphclient
packages/keeper-bots/src/config/abis/generated.ts
packages/keeper-bots/src/subgraph-client/.graphclient

# Build
dist
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@venusprotocol/keeper-bots",
"name": "@venusprotocol/keeper-bots-monorepo",
"version": "1.1.1",
"description": "Keeper bots for Venus Protocol",
"private": true,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@venusprotocol/cli",
"version": "1.4.0",
"version": "1.5.0-dev.2",
"license": "MIT",
"bin": {
"venus": "dist/venus.js"
Expand Down Expand Up @@ -28,7 +28,7 @@
"@graphql-mesh/cli": "^0.90.5",
"@graphql-mesh/config": "^0.100.5",
"@graphql-mesh/graphql": "^0.98.4",
"@venusprotocol/token-converter-bot": "^1.2.0-dev.1",
"@venusprotocol/keeper-bots": "1.0.0-dev.1",
"@venusprotocol/venus-protocol": "^9.1.0",
"dotenv": "^16.3.1",
"graphql": "^16.8.1",
Expand Down
57 changes: 48 additions & 9 deletions packages/cli/source/commands/conversionPairs.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,68 @@
import { option } from "pastel";
import zod from "zod";
import { useEffect, useState } from "react";
import { Box, Text, useApp } from "ink";
import { TokenConverterConfigs, getAllConverterConfigs } from "@venusprotocol/token-converter-bot";
import {
BalanceResult,
getAllConverterConfigs,
getConverterConfigsByConverter,
getTokenConvertersTokenBalances,
} from "@venusprotocol/keeper-bots";
import { addressValidation } from "../utils/validation.js";

export const options = zod.object({
converter: addressValidation
.describe(
option({
description: "Token converter address",
alias: "c",
}),
)
.optional(),
});

interface Props {
options: zod.infer<typeof options>;
}

/**
* Helper command to list available conversion pairs
*/
export default function ConversionPairs() {
const [configs, setConfigs] = useState<TokenConverterConfigs>([]);
export default function ConversionPairs({ options }: Props) {
const { converter } = options;
const [configs, setConfigs] = useState<BalanceResult[]>([]);

const { exit } = useApp();

useEffect(() => {
(async () => {
const configs = await getAllConverterConfigs();
setConfigs(configs);
let configs = [];
if (converter) {
configs = await getConverterConfigsByConverter(converter);
} else {
configs = await getAllConverterConfigs();
}
const { results } = await getTokenConvertersTokenBalances(
configs,
"0x0000000000000000000000000000000000000000",
false,
);

setConfigs(results);
})().finally(exit);
}, []);

return (
<Box flexDirection="column">
{configs.map(c => (
<Box key={c.id} flexDirection="row">
<Text>Token Converter: {c.tokenConverter.id} </Text>
<Text>Token In: {c.tokenIn.address} </Text>
<Text>Token Out: {c.tokenOut.address}</Text>
<Box key={`${c.tokenConverter}-${c.assetIn.address}-${c.assetOut.address}`} flexDirection="row">
<Text>Token Converter: {c.tokenConverter} </Text>
<Text>
Token In: {c.assetIn.symbol} {c.assetIn.address}{" "}
</Text>
<Text>
Token Out: {c.assetOut.symbol} {c.assetOut.address} (Balance {c.assetOut.balance.toString()})
</Text>
</Box>
))}
</Box>
Expand Down
19 changes: 10 additions & 9 deletions packages/cli/source/commands/convert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { option } from "pastel";
import { Box, Spacer, Text, useApp, useStderr } from "ink";
import zod from "zod";
import { parseUnits } from "viem";
import { TokenConverter, PancakeSwapProvider, UniswapProvider } from "@venusprotocol/token-converter-bot";
import { TokenConverter, PancakeSwapProvider, UniswapProvider, BalanceResult } from "@venusprotocol/keeper-bots";
import { stringifyBigInt, getConverterConfigId } from "../utils/index.js";
import { Options, Title, BorderBox } from "../components/index.js";
import { reducer, defaultState } from "../state/convert.js";
Expand Down Expand Up @@ -174,9 +174,10 @@ export default function Convert({ options }: Props) {
await tokenConverter.releaseFundsForConversions(potentialConversions);
}
await Promise.allSettled(
potentialConversions.map(async (t: any) => {
potentialConversions.map(async (t: BalanceResult) => {
let amountOut = t.assetOut.balance;
const vTokenAddress = t.assetOutVTokens.core || t.assetOutVTokens.isolated[1];

const vTokenAddress = t.assetOutVTokens.core || t.assetOutVTokens.isolated![0]![1];
const { underlyingPriceUsd, underlyingUsdValue, underlyingDecimals } = await tokenConverter.getUsdValue(
t.assetOut.address,
vTokenAddress,
Expand All @@ -191,7 +192,7 @@ export default function Convert({ options }: Props) {
const arbitrageArgs = await tokenConverter.prepareConversion(
t.tokenConverter,
t.assetOut.address,
t.assetIn,
t.assetIn.address,
amountOut,
);

Expand All @@ -209,7 +210,7 @@ export default function Convert({ options }: Props) {
context: {
converter: t.tokenConverter,
tokenToReceiveFromConverter: t.assetOut.address,
tokenToSendToConverter: t.assetIn,
tokenToSendToConverter: t.assetIn.address,
amount,
minIncome,
percentage: Number((minIncome * 10000000n) / amount) / 10000000,
Expand All @@ -223,9 +224,9 @@ export default function Convert({ options }: Props) {
type: "ExecuteTrade",
error: "Insufficient wallet balance to pay min income",
context: {
converter: t.tokenConverter.id,
converter: t.tokenConverter,
tokenToReceiveFromConverter: t.assetOut.address,
tokenToSendToConverter: t.assetIn,
tokenToSendToConverter: t.assetIn.address,
amount,
minIncome,
percentage: Number((minIncome * 10000000n) / amount) / 10000000,
Expand All @@ -237,9 +238,9 @@ export default function Convert({ options }: Props) {
type: "ExecuteTrade",
error: "Min income too high",
context: {
converter: t.tokenConverter.id,
converter: t.tokenConverter,
tokenToReceiveFromConverter: t.assetOut.address,
tokenToSendToConverter: t.assetIn,
tokenToSendToConverter: t.assetIn.address,
amount,
minIncome,
percentage: Number((minIncome * 10000000n) / amount) / 10000000,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/source/commands/releaseFunds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
getAddresses,
PancakeSwapProvider,
UniswapProvider,
} from "@venusprotocol/token-converter-bot";
} from "@venusprotocol/keeper-bots";
import usePublicClient from "../queries/usePublicClient.js";
import { Options, BorderBox } from "../components/index.js";
import { reducer, defaultState } from "../state/releaseFunds.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/source/state/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
GetBestTradeMessage,
ArbitrageMessage,
PotentialConversionsMessage,
} from "@venusprotocol/token-converter-bot";
} from "@venusprotocol/keeper-bots";

interface ExecuteTradeMessage {
type: "ExecuteTrade";
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/source/state/releaseFunds.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Message } from "@venusprotocol/token-converter-bot";
import { Message } from "@venusprotocol/keeper-bots";

interface State {
releasedFunds: {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@venusprotocol/token-converter-bot",
"version": "1.2.0",
"name": "@venusprotocol/keeper-bots",
"version": "1.0.0-dev.2",
"description": "",
"scripts": {
"dev": "tsc --watch",
Expand Down Expand Up @@ -28,8 +28,8 @@
"typings": "dist/index.d.ts",
"dependencies": {
"@graphprotocol/client-cli": "3.0.0",
"@pancakeswap/sdk": "^5.8.0",
"@pancakeswap/smart-router": "^5.1.3",
"@pancakeswap/sdk": "^5.8.8",
"@pancakeswap/smart-router": "^6.0.17",
"@pancakeswap/v3-core": "^1.0.2",
"@uniswap/sdk": "^3.0.3",
"@uniswap/sdk-core": "^5.3.1",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CurrencyAmount, Percent, Token } from "@pancakeswap/sdk";
import { CurrencyAmount, Fraction, Percent, Token } from "@pancakeswap/sdk";
import { RouteV3 } from "@uniswap/router-sdk";
import { Token as UniswapToken } from "@uniswap/sdk-core";
import { FeeAmount, Pool, Route as V3RouteSDK } from "@uniswap/v3-sdk";
Expand Down Expand Up @@ -113,11 +113,11 @@ export const mockTrade = {
path: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c000cf6bb5389c92bdda8a3747ddb454cb7a64626c63" as const,
inputToken: {
address: "0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c" as const,
amount: 8904975230019520420n,
amount: new Fraction(8904975230019520420n, 1),
},
outputToken: {
address: "0xcf6bb5389c92bdda8a3747ddb454cb7a64626c63" as const,
amount: 517926942058379677423n,
amount: new Fraction(517926942058379677423n, 1),
},
};

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createWalletClient, http } from "viem";
import { PrivateKeyAccount, privateKeyToAccount } from "viem/accounts";

import getConfig from "../";
import getConfig from "..";
import { chains } from "../chains";

const readPrivateKeyFromEnv = (chainName: string): PrivateKeyAccount => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,52 @@ const safelyGetEnvVar = <T extends keyof typeof process.env>(key: T) => {

export const swapSubgraphUrlByNetwork = {
bsctestnet: "https://api.thegraph.com/subgraphs/name/pancakeswap/exchange-v3-chapel",
bscmainnet: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/5zvR82QoaXYFyDEKLZ9t6v9adgnptxYpKpSbxtgVENFV`,
ethereum: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/5zvR82QoaXYFyDEKLZ9t6v9adgnptxYpKpSbxtgVENFV`,
sepolia: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/B4QeFHkfWXjKCDzNn3BJtDRDfG6VeHzGXgkf4Jt3fRn5`,
bscmainnet: `https://gateway-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/Hv1GncLY5docZoGtXjo4kwbTvxm3MAhVZqBZE4sUT9eZ`,
ethereum: `https://gateway-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/5zvR82QoaXYFyDEKLZ9t6v9adgnptxYpKpSbxtgVENFV`,
sepolia: `https://gateway-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/B4QeFHkfWXjKCDzNn3BJtDRDfG6VeHzGXgkf4Jt3fRn5`,
};

export const protocolReserveSubgraphUrlByNetwork = {
bsctestnet: `https://gateway-testnet-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/56kKcG5fTJfmCncsvq9n2quExvFUfSEds3Lpk5dkWkgE`,
bscmainnet: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/2ZCWgaBc8KoWW8kh7MRzf9KPdr7NTZ5cda9bxpFDk4wG`,
ethereum: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/QmcFbWExHdYuV3XQNPrX5PA467jRvSrtUfMLxoA6t95nSn`,
bsctestnet: `https://gateway-testnet-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/56kKcG5fTJfmCncsvq9n2quExvFUfSEds3Lpk5dkWkgE`,
bscmainnet: `https://gateway-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/2ZCWgaBc8KoWW8kh7MRzf9KPdr7NTZ5cda9bxpFDk4wG`,
ethereum: `https://gateway-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/deployments/id/QmcFbWExHdYuV3XQNPrX5PA467jRvSrtUfMLxoA6t95nSn`,
sepolia: `https://api.studio.thegraph.com/query/${process.env.TESTNET_GRAPH_ID}/venus-protocol-reserve-sepolia/version/latest`,
};

export const isolatedPoolsSubgraphUrlByNetwork = {
bsctestnet: `https://gateway-testnet-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/mkXvkAme9PyDnSrLkajVHKVX7eG2HHATcYPE1qGF7gc`,
bscmainnet: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/H2a3D64RV4NNxyJqx9jVFQRBpQRzD6zNZjLDotgdCrTC`,
ethereum: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/Htf6Hh1qgkvxQxqbcv4Jp5AatsaiY5dNLVcySkpCaxQ8`,
sepolia: `https://gateway-testnet-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/6YURB3bABVUNusgjtY7fNMkELGmKm9aaWirMQ9UZeDFj`,
bsctestnet: `https://gateway-testnet-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/mkXvkAme9PyDnSrLkajVHKVX7eG2HHATcYPE1qGF7gc`,
bscmainnet: `https://gateway-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/H2a3D64RV4NNxyJqx9jVFQRBpQRzD6zNZjLDotgdCrTC`,
ethereum: `https://gateway-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/Htf6Hh1qgkvxQxqbcv4Jp5AatsaiY5dNLVcySkpCaxQ8`,
sepolia: `https://gateway-testnet-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/6YURB3bABVUNusgjtY7fNMkELGmKm9aaWirMQ9UZeDFj`,
};

export const corePoolSubgraphUrlByNetwork = {
bsctestnet: `https://gateway-testnet-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/AK258nTjNqNk8dKZwmPFiuxWX3yNfV7rYztXpegCmZ6A`,
bscmainnet: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.THE_GRAPH_STUDIO_API_KEY}/subgraphs/id/7h65Zf3pXXPmf8g8yZjjj2bqYiypVxems5d8riLK1DyR`,
bsctestnet: `https://gateway-testnet-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/AK258nTjNqNk8dKZwmPFiuxWX3yNfV7rYztXpegCmZ6A`,
bscmainnet: `https://gateway-arbitrum.network.thegraph.com/api/${safelyGetEnvVar(
"THE_GRAPH_STUDIO_API_KEY",
)}/subgraphs/id/7h65Zf3pXXPmf8g8yZjjj2bqYiypVxems5d8riLK1DyR`,
ethereum: "",
sepolia: "",
};
Expand Down
Loading

0 comments on commit 666d546

Please sign in to comment.