Tired of non-stop worrying whether you will get liquidated when the market moves? You want to get the maximum out of your Degen Delta Neutral Strategy on Mirror? You want to minimize the risk of your rewards token (SPEC, MIR) losing in value, and rather want to sell them? You want to maintain a healthy LTV on your Anchor Borrow and deposit the borrowed UST into Anchor Earn? Not sure to claim and sell your token rewards?
Then, this bot is for you!
Automatically manage all your ANC, MIR, SPEC token rewards, Mirror Delta Neutral Short Positions, UST claims after lockup, Anchor Borrow and Earn for Terra, deposits and withdraws from liquidity pools to sell.
If this bot is helpful to you and helps maximize your gainz, feel free to donate a bit to terra1xl0ww4tykjmm4vnzck0qz5luu6rxl97wuwmgfg
. This will also keep the development going and the bot up-to-date. Thank you! :)
Special thanks to unl1k3ly as his bot taught me what I needed to know. Thanks Terra, Mirror, Spectrum, Anchor team and the Terra Community!
I found there are many calculations out there. But most are just wrong. They do not consider volatility or the most important factor hodl time.
So I made 2x overly detailed calculation that I base my decisions on. I consider this valuable for you, even if you do not run the Terra-One-Stop-Bot.
Delta Neutral Simulation & Playground: https://docs.google.com/spreadsheets/d/19WyuPtGz1SGJsCKZGskD7JAGAT9THUFy9b2GtbMR7JI
- '3. Conclusion' shows you which mAssets current would return what APY. You can change what top mAssets you want to consider. The sheet calculates those rankings once per hour new.
- If you want to play a little bit around look at the sheet '0. Calc', and change the yellow filled cells.
- The amount you want to put in is not relevant, as all is calculated based on a percentage basis, as transaction costs are not considered.
Decision Help Min Values: https://docs.google.com/spreadsheets/d/1U9jd5rarvWwbeuGLzkuG7Hyx4B71Pkdrmoj894SGr3M
- Gives you a basis to make your decision what minimum deposits, withdraws, sell quantities, etc. to set for the Terra-One-Stop-Bot.
- Withdraws your MIR, SPEC, ANC from your LP tokens
- Claims your unclaimed MIR, SPEC, ANC tokens
- Claims unlocked UST on Mirror
- Sells your MIR, SPEC, ANC tokens
- Deposits your MIR, SPEC, ANC tokens into corresponding LP
- Repays debt at Anchor if your LTV requires it
- Borrows more UST from Anchor if you LTV allows it
- Deposits UST (from sale of MIR, SPEC, ANC and Borrow) in Anchor Earn to get more aUST
- Deposits collateral in your short positions
- Withdraws collateral from your short positions
- Sends you an update via Slack, Telegram or Email
- Runs at your defined intervals
- Runs in debug mode
- Logs information for you
- Other stuff
Due to the order of which the functions are executed, the priority is on a repayment of debt to Anchor rather than depositing more aUST into your shorts on Mirror, as crypto is more volatile than the legacy stock market.
I made the One-Stop-Bot as much configureable as possible. You can configure what you like in the B_config.py
. This order here is also the logical flow of the bot.
0. Setup
* XXX_min_price
Define a minimum prices for SPEC, MIR, ANC to trigger a sale
* XXX_min_total_value
Define a minimum value (= price of token * amount to sell) for SPEC, MIR, ANC to be acted on (sale or deposit)
- Withdraws your MIR, SPEC, ANC from your LP tokens
XXX_withdraw_and_sell_if_min_price_is_reached
True/False withdraw of your token and UST from LP to sell if BOTHXXX_min_price
ANDXXX_min_total_value
is exceeded
- Claims your unclaimed MIR, SPEC, ANC tokens
XXX_claim_and_sell_token
True/False sale of SPEC, MIR, ANC (SPEC gets claimed from all your farms Mirror, Anchor, Pylon and Spectrum) if BOTHXXX_min_price
ANDXXX_min_total_value
is exceededXXX_claim_and_deposit_in_LP
True/False deposit of SPEC, MIR, ANC to the corresponding LP if ONLYXXX_min_total_value
is exceeded
- Claims unlocked UST on Mirror
Mirror_claim_unlocked_UST
True/False claim of unlocked USTMirror_min_amount_UST_to_claim
Define a minimum of unlocked UST to be claimed
- Sells your MIR, SPEC, ANC tokens
- For each token there can be only a sell or deposit allowed.
- Deposits your MIR, SPEC, ANC tokens into corresponding LP
- For each token there can be only a sell or deposit allowed.
- Repays debt at Anchor if your LTV requires it
Anchor_enable_auto_repay_of_debt
True/False auto repayment of debtAnchor_enable_withdraw_of_deposited_UST
True/False allowance to withdraw UST from Anchor Earn to repay debtAnchor_enable_partially_repay_if_not_enough_UST_in_wallet
True/False of partial debt repayment (withdraw all deposited UST on Anchor Earn + all UST available in wallet)Anchor_lower_distance
Define lower_distance from maximal ltv ratio below a repayment will be executedAnchor_target_distance
Define target_distance from maximal ltv ratio that is restored when repay debt/borrow more USTAnchor_min_repay_limit
Define minimum debt repayment limit
- Borrows more UST from Anchor if you LTV allows it
Anchor_enable_auto_borrow_UST
True/False auto borrow of more USTAnchor_upper_distance
Define upper_distance from maximal ltv ratio above more UST will be borrowedAnchor_min_borrow_limit
Define minimum borrow limitAnchor_borrow_cooldown
Define cooldown period in days for the auto borrow function
- Deposits UST (from sale of MIR, SPEC, ANC and Borrow) in Anchor Earn to get more aUST
Anchor_Earn_enable_deposit_UST
True/False enable deposit of freshly gained UST (from the sale of SPEC, MIR & Mirror claim) into Anchor EarnAnchor_Earn_min_deposit_amount
Define minimum UST amount to depositAnchor_Earn_min_balance_to_keep_in_wallet
This this bot also deposits token in LP, you should have a UST balance in your wallet.
- Deposits collateral in your short positions
Mirror_enable_deposit_collateral
True/False deposit of collateral (Luna, UST, aUST supported)Mirror_lower_distance
Define lower_distance from minimal ratio below collateral will be depositedMirror_target_distance
Define target_distance from minimal ratio that is restored when depoit/withdraw collateralMirror_min_deposit_limit_in_UST
Define minimum deposit limit in UST
- Withdraws collateral from your short positions
Mirror_enable_withdraw_collateral
True/False withdraw of collateralMirror_upper_distance
Define upper_distance from minimal ratio above collateral will be withdrawnMirror_min_withdraw_limit_in_UST
Define minimum withdraw limit in USTMirror_withdraw_cooldown
Define cooldown period in days for the auto withdraw function
- Sends you a report on Telegram, Slack and/or Email if something has been done. Also writes logs into ./logs and sends you a status update if you want.
Send_me_a_report
True/False prepares a summary of what has happened, if something has happened. Always includes WARNINGs and ERRORs.Notify_Slack
True/False notifications to be received on SlackNotify_Telegram
True/False notifications to be received on TelegramNotify_Gmail
True/False notifications to be send through Gmail to any emailEmail_format
Define to receive the report and status update in TEXT or HTMLSend_me_a_status_update
True/False if you want to receive a status update anyway depending on yourStatus_update_frequency
Status_update_frequency
Define in what intervals (hours) you want to receive a status updateStatus_update_time
Define at what time you want to receive the status update
- Runs the bot at your defined intervals
Run_interval_for_Scheduler
Define the frequency how often the scheduler should run the bot
- Debug
Debug_mode
True/False debug mode for default.logDisable_all_transaction_defs
True/False disables all transaction functions, by returning a fake transaction hashReturn_failed_tx
True/False if you want that transaction to be a failed transaction hash
- Logging
Logging_detail
Define what level of detail each log shall show
- Other stuff
Safety_multiple_on_transaction_fees
Safety multiple on transaction feesBlock_failed_transaction_cooldown
If case a transaction fails, you can set it to NOT be tried again for a period of hours.
- Withdraws any UST from Anchor Borrow to deposit that new UST collateral on Mirror.
- Deposits any UST to Anchor Earn to deposit that new aUST as collateral on Mirror.
- Sells, buys, swaps any Luna to deposit it as collateral on Mirror.
- Uses withdrawn aUST or UST from Mirror to repay your Anchor Borrow debt (if you run the One-Stop-Bot often enough of course it will loop and eventually repay that debt).
- If you withdraw pool rewards, sell them, claim UST etc. and it is still not enough UST to exceed the
config.Anchor_Earn_min_deposit_amount
that UST will just remain in your wallet. They will NOT be "remembered" for the next run of the One-Stop-Bot. - The bot currently only supports UST, aUST and Luna as collateral on Mirror (you really should only use aUST anyway).
- It's recommended to run this code in a contained environment at maximum security.
- Do not run the bot in too short intervals. I implemented async def for the most part, so the current runtime is around 10-30 sec depending on your internet connection.
- Watch your UST balance, as this bot is doing transactions, hence drains your UST balance.
- Use this bot at your own risk. I have done my best to check it, but program bugs & human bugs happen and I am not financial advisor.
- This bot can be used with the Testnet. I strongly recommend playing on the Testnet or with
Disable_all_transaction_defs
set to True first, before letting it manage your funds for real. Here you can get free UST, LUNA etc: https://faucet.terra.money/. - Since the LTV/min ratios on Mirror and Anchor are defined exactly opposite each other, it may gets confusing to set the
lower_distance
,target_distance
,upper_distance
. I wrote some explanations, but make sure you take time to understand it. - For your own safety all functions are set to False by default. Enable them one by one.
- Deposits / withdrawals of collateral as well as repayments / borrowing of debt are limited by an amount. So if your collateral loses lots of value in one day, there will be multiple deposits / repayments per day to keep your funds safe.
- If however, your collateral gains in value and you withdraw aUST from Mirror or borrow more UST from Anchor a time cooldown (which you can define) will act as a limit. If you set the cooldown to 3, only once every 3 days collateral will be withdrawn from Mirror / more UST will be borrowed from Anchor. This decreases the risk / transaction fees when one day your collateral value spikes, just to crash the next day.
- Since a wallet seed is required, ensure you protect it and know what you're doing while using this automation.
- If you don't want to pass secrets into the B_Config.py file, make sure you declare it as a system variable.
- Everything will be logged into the
./logs
folder. Make sure you check those from time to time!
git clone
this repository.- Rename
B_Config.py.sample
toB_Config.py
. - Change
B_Config.py
as you desire and feed your seed (a dedicated wallet is recommended). - Run
pip3 install -r A_Requirements.txt
. - Run the One-Stop-Bot with a crontab directly or with
python D_Scheduler.py
. - Make yourself familiar with the bot by using the TESTNET first (Get free UST/LUNA here: https://faucet.terra.money/) by enabling features step-by-step.
- Then use your real wallet on the MAINNET but with
Disable_all_transaction_defs
set to True. - If you feel comfortable set
Disable_all_transaction_defs
to False and let the bot work for you.
If you use more Slack, it might be simpler to be notified there using Slack Webhooks.
- Create a Slack APP.
- Add the APP to a channel and get a webhook URL to feed the
B_Config.py
. More information can be found via this link https://api.slack.com/incoming-webhooks.
If you want to be notified via Telegram, you'd need to get TELEGRAM_TOKEN
and your TELEGRAM_CHAT_ID
from your Telegram bot.
- On Telegram, find
@BotFather
and open a DM. - Use
/newbot
to create a new bot for yourself. - Then, name the bot as you wish, ie:
MyCoolBot
. - Now, choose whatever username you desire for your bot, ie:
MyCool_bot
. - Done! You should see a "Congratulations" message from BotFather.
- To get your own
chat_id
, simply send a message in the group with your bot and run the following command below:curl -s https://api.telegram.org/botACCESSTOKEN/getUpdates
(replaceACCESSTOKEN
with an actual token you just got from item #5). - You should get something like this
{"ok":true .... "from":{"id":1386432285 ...."text":"Hello"}}]}
We are looking for the "id" as this is thechat_id
. - Write your
access_token
andchat_id
in theB_Config.py
file.
To send emails from your Google account you need to get a GMAIL_APP_PASSWORD
.
- Go to manage my Google account (https://myaccount.google.com/security).
- Under "Signing in to Google" confirm that "2-Step Verification" is "On" for the account.
- Under "Signing in to Google" select "App passwords".
- Select the app as "Mail" and the device as "Other (Custom name)" and name it (for example: One-Stop-Bot-Terra).
- Copy the app password, it will be in a yellow box and looks like: "cjut fanq prdo diby".
- Run Mirror withdrawals before repay of Anchor Borrow to make use of that available aUST
- Build a front end.