defichain-compound v0.8.0
DFI earnings automation for DeFiChain
Introduction
defichain-compound is a CLI daemon that is running in parallel with defid of the DeFiChain desktop wallet or masternode. Its purpose is to execute automatic compounding actions based on a configuration file.
This project has been approved by the community as CFP-2211-01. Thank you all for your support! š
Installation
npm -g install defichain-compoundIn case npm is not already available please see Downloading and installing Node.js and npm.
After the installation a config file needs to be created (see below). Once the config file is ready, simply execute the command defichain-compound. It will then prompt for the wallet passphrase and fork a daemon process in the background that will constantly be running and acting according to the configured actions.
Configuration
The default config file is ~/.defichain-compound. Using the --conf option a different location for the config file can be chosen.
Compounding Actions
The parameter TARGET in the config file defines the compounding action. The following actions are supported:
| Action | TARGET | Example value for TARGET | Example use case |
|---|---|---|---|
| Add pool liquidity | Pool pair symbol | BTC-DFI | Compounding BTC-DFI pool liquidity mining |
| Token swap | Token symbol | ETH | DCA into ETH token |
| Wallet transfer | DeFiChain wallet address | bDEl...wxTgV | Transfer DFI to Cake for staking |
All tokens and pool pairs on DeFiChain are supported. For swapping into dTokens the route is DFI ā DUSD ā dToken.
Example Config File
# Connection to defid
RPC_URL=http://user:password@localhost:8554
# Amount of DFI needed before the action is executed
DFI_COMPOUND_AMOUNT=5
# Wallet address of the desktop client
WALLET_ADDRESS=address
# Target for compounding action (see documentation)
TARGET=wallet address(es) or token symbol(s) or pool pair symbol(s)
# Logfile and pidfile
LOGFILE=/tmp/defichain-compound.log
PIDFILE=/tmp/defichain-compound.pid
# Interval to check if compounding is needed
CHECK_INTERVAL_MINUTES=720Rotating Actions
TARGET can be set to multiple values separated by a single space. The actions are then rotated in order. To keep state across restarts defichain-compound will rewrite the config file so that the first listed action in TARGET is always the one to execute next.
Example 1
TARGET=ETH-DFI BTC-DFI DOGEWhen DFI_COMPOUND_AMOUNT is reached for the first time buy into the ETH-DFI pool. When again DFI_COMPOUND_AMOUNT is reached buy into the BTC-DFI pool. When again DFI_COMPOUND_AMOUNT is reached buy DOGE. Repeat infinitely.
Example 2
TARGET=BTC-DFI BTC-DFI ETH-DFIInvest into the BTC-DFI and ETH-DFI pools at a 2:1 ratio.
Example 3
TARGET=ETH-DFI bDEl...wxTgVInvest half of the earnings into the ETH-DFI pool and transfer the other half to bDEl...wxTgV for staking.
Update Config
The daemon updates its config on SIGHUP. Note that LOGFILE and PIDFILE are not updated in this scenario. Example:
kill -HUP $(<"/tmp/defichain-compound.pid")Wallet Passphrase
In order to sign transactions defichain-compound needs to know the passphrase of the wallet. The recommended and most secure way is to use the interactive prompt when starting the daemon.
If fully unattended operation including startup is desired, the passphrase can also be passed via the DEFICHAIN_WALLET_PASSPHRASE environment variable. Upon forking its child process into daemon mode defichain-compound will then delete the variable from the environment.
Utility Functions
Holdings Summary
When started with the --holdings option, instead of going into daemon mode an overview of all holdings in the wallet is shown. Optionally a currency symbol can be given as argument to show the values in the respective currency. The default is USD. DFI is also a valid option to get the total equivalent in DFI tokens.
Example
$ defichain-compound --holdings CHF
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā Token Amount CHF Value ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¢
ā BTC-DFI 14.74536882 3321.08 ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¢
ā AAPL-DUSD 43.92371935 897.94 ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¢
ā DFI 4.94089433 3.31 ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā¢
ā Total 4222.33 ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāNOTE: Because of the current difficulties with DUSD's peg, its value can be determined using various strategies. This calculation is using the ratio of the DUSD-DFI liquidity pool.
Example Session
Here's an example run with TARGET=ETH-DFI for illustration purposes:
2022-10-04 09:00:03.652 Balance: 13.41241989 (DFI token: 0.38993539 / UTXO: 13.0224845)
2022-10-04 09:00:03.658 Compound threshold of 5.1 (5 + 0.1) reached
2022-10-04 09:00:03.755 Convert 4.61006461 UTXO to DFI token
2022-10-04 09:00:03.916 Conversion transaction: c7e7...6d26
2022-10-04 09:00:03.916 Waiting for conversion to complete
2022-10-04 09:00:29.500 Conversion completed
2022-10-04 09:00:29.505 Swap 2.5 DFI token to ETH token
2022-10-04 09:00:29.521 Swap transaction: 9a08...2573
2022-10-04 09:00:29.521 Waiting for swap to complete
2022-10-04 09:00:50.743 Received 0.00129444 ETH token
2022-10-04 09:00:50.744 Add pool liquidity 0.00129444 ETH / 2.5 DFI
2022-10-04 09:00:51.649 Add pool liquidity transaction: 04d8...db4a
2022-10-04 09:00:51.649 Waiting for liquidity transaction to complete
2022-10-04 09:02:32.290 Received 0.05677079 ETH-DFI tokenDisclaimer
This is not financial advice. Please only run this code if you fully understand what it is doing. This code is provided as-is with no warranty. I take no responsibility for lost funds or any other damage that it might cause.