Today we will be leveraging the Enso API for building a DeFi telegram information and execution bot.
The Enso API not only offers you all metadata such as apy, tvl, addresses, underlying tokens, logos, urls, and so forth. It also offers you execution into DeFi protocols for actions like:
- farming
- lending
- borrowing
- liquidity provisioning
- farming
- and much more
You can do native transaction bundling as well, i.e. enter 50 defi positions in one transaction.
Compatible with gnosis safe, and any smart wallet that enables delegatecall..
- Fork this repo
- Install dependencies with
npm install
- Copy .env.example into .env
- Generate telegram bot key
- Run
/newbot
- Input a unique name
- Copy you're API key and put inside of .env
- Run
- Start the bot with
npm run bot
- Send your bot
@your_bot_handle
the message/help
/help
: command to query information about projects including, protocol list, pool list and apy/start
: lists all resources and welcome message/route
: execute swaps, deposits, farming and so forthsingle
: route from 1 token to 1 tokenbatch
: route from 1 token to N
/projects
: query information about projects including, protocol list, pool list and apylist
: list all projects available through Ensopools
: list all pools for a project with Symbol, APY, TVL, and Addressapy
: fetch apy for a specific pool
Add the correct API URL in getRoute
inside of ./src/enso.ts
export async function getRoute(toToken: string, amountIn: BigNumber) {
const url = "XXX";
try {
const response = (
await axios.get(
`${url}?chainId=1&fromAddress=${SAFE_WALLET}&amountIn=${amountIn.toString()}&tokenIn=${ETH}&tokenOut=${toToken}`,
AUTH_HEADER
)
).data;
console.log("Single response:", response);
return response;
} catch (e: any) {
if (e instanceof AxiosError) throw `Route failed: ${e.response?.data}`;
else throw e;
}
}
Add the correct API URL in getRouteBundle
inside of ./src/enso.ts
export async function getRouteBundle(toTokens: string[], amountIn: BigNumber) {
const url = "XXX";
const amountSplit = amountIn.div(toTokens.length).toString();
const data = toTokens.map((token) => ({
protocol: "enso",
action: "route",
args: {
tokenIn: ETH,
tokenOut: token,
amountIn: amountSplit,
},
}));
try {
const response = (
await axios.post(
`${url}?chainId=1&fromAddress=${SAFE_WALLET}`,
data,
AUTH_HEADER
)
).data;
console.log("Batch response: ", response);
return response;
} catch (e) {
if (e instanceof AxiosError)
throw `Bundle failed: ${JSON.stringify(e.response?.data)}`;
else throw e;
}
}
Add the correct API URL in getProjects
inside of ./src/enso.ts
export async function getProjects() {
const url = "XXX";
let projects: any = [];
const standards = (await axios.get(url, AUTH_HEADER)).data;
standards.forEach((standard: any) => {
if (standard.protocol) projects.push(standard.protocol.slug);
if (standard.forks)
projects.push(...standard.forks.map((fork: any) => fork.slug));
});
return projects;
}
Add the correct API URL in getPools
inside of ./src/enso.ts
export async function getPools(project: string) {
const url = "XXX";
let pools = [["*Pool Name | APY | TVL | Pool Address*"]];
const response = (await axios.get(`${url}?protocol=${project}`, AUTH_HEADER))
.data;
// limit to 50 pools due to telegram message limit. You can still console.log the full list here before array if you want more details
for (let i = 0; i < (response.length < 50 ? response.length : 50); i++) {
pools.push([
response[i].subtitle,
response[i].apy,
response[i].tvl,
response[i].poolAddress,
]);
}
return pools;
}
Add the correct API URL in getPoolApy
inside of ./src/enso.ts
export async function getPoolApy(poolAddress: string) {
const url = "XXX";
const apy = (
await axios.get(`${url}?tokenAddress=${poolAddress}`, AUTH_HEADER)
).data[0].apy;
return apy;
}
Not knowing addresses is common.
Enable interaction within getRoute
, getRouteBundle
, and getPoolApy
.. and if there is any more.
For example
"eth": "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee",
"stecrv": "0x06325440D014e39736583c165C2963BA99fAf14E"
- Fetch all the underlying tokens, and then enable users to define the tokens they want exposure to.
- You can view this as an information intent:
Find me the top 10 best APY with exposure to stETH, and ETH
- You can view this as an information intent:
- Enable execution
Enable one call to withdraw all funds from the Smart Wallet to designated address passed in.