Karaka automation also supports Hive Engine tokens with a powerful set of commands to suit many situations. Let's walk through some example rules that demonstrate staking, transferring, buying and selling tokens.
Karaka is an Automation (clerk) for Hive and Hive Engine blockchains.
Karaka is a Maori word meaning variously: an English loanword for 'clerk' or 'clock' and a significant coastal plant 'Corynocarpus laevigatus'.
Get Karaka from https://github.com/Stormrose/karaka
It's helpful if you've read the previous tutorial. This tutorial talks about the basic config.json
file structure and introduces the concept of rules and facts.
Hive engine config is contained within a section at the top level of the JSON file. Don't put this inside the hive
blockchain section. The basic config.json file
{
"intervalmins": 43,
"hiveengine": {
"apinode": "https://api.hive.blog",
"sidechainuri": "https://api.hive-engine.com/rpc",
"accounts": {
"eturnerx": "***YourPrivateActiveKeyHere***"
},
"rules": [
...
]
}
}
Within the hiveengine
blockchain section are apinode
, sidechainuri
, a map of accounts
and their keys, and a list of rules
. Hive engine configuration is the same as for Hive, but with a Hive Engine API endpoint. If you're not sure which sidechainuri
to use, use the one in the example above.
If your config file includes a hive
section, you can omit the apinode
entry. Also, if your config has a hive
section and you already have the account plus key in the accounts
map of the hive
section, then you can refer to that like this for inside your hiveengine
section:
"accounts": {
"eturnerx": { "from": "hive" }
}
Facts
from?Just like for Hive, Karaka assets facts about the tokens held. These also take the format of accountname.factname
. Fact names include the token symbol and the suffixes _balance
and _stake
. Here are some examples:
eturnerx.SWAP.HIVE_balance
eturnerx.VIBES_balance
eturnerx.PAL_stake
Karaka's then
clause commands work pretty much the same for Hive and Hive Engine tokens. The transfer
and stake
commands use the same prefixes and parameters.
A key difference is that the sell
command can only sell a token for SWAP.HIVE
and the buy
command must be used when exchanging SWAP.HIVE
for another token. In the buy command, the keyword of
is used instead of for
.
sell 10 PAL for SWAP.HIVE from eturnerx at market
buy 10 SWAP.HIVE of LEO from eturnerx at market
The full range of mathematical expressions can be used in rules, too, just like in rules written for Hive.
Here's a completed config.json
file with a rule filled in.
{
"intervalmins": 43,
"apinode": "https://api.hive.blog",
"sidechainuri": "https://api.hive-engine.com/rpc",
"hiveengine": {
"accounts": {
"eturnerx": "***YourPrivateActiveKeyHere***"
},
"rules": [
{
"if": "eturnerx.SWAP.HIVE_balance > 1.0",
"then": "buy 1.0 SWAP.HIVE of LEO from eturnerx at market"
}
]
}
}
Let's learn by stepping through some basic recipes that you can adjust to your own purposes.
As you collect tribal tokens, you might want to sell some and stake some automatically. This example does 50% either way once there are at least two tokens.
"if": "eturnerx.PAL_balance > 2.0",
"then": [
"sell (eturnerx.PAL_balance * 0.5) PAL for SWAP.HIVE from eturnerx at market",
"stake (eturnerx.PAL_balance * 0.5) PAL from eturnerx"
]
You might also want to maintain a minimum liquid reserve of a tribal token. In this case, let's hold 100 tokens, sell 20% over that and stake 80%. The rule doesn't trigger unless there are at least two tokens over the reserve of 100.
"if": "eturnerx.PAL_balance > 102",
"then": [
"sell ((eturnerx.PAL_balance - 100) * 0.2) PAL for SWAP.HIVE from eturnerx at market",
"stake ((eturnerx.PAL_balance - 100) * 0.8) PAL from eturnerx"
]
In these two rules, we use any SWAP.HIVE, we have to purchase our favourite tribal token and power it up. First, Karaka will buy the VIBES token, but the VIBES balance is not updated until the next round, and so this is a two-round process.
{
"if": "eturnerx.SWAP.HIVE_balance > 1.0",
"then": "buy (eturnerx.SWAP.HIVE_balance) SWAP.HIVE of VIBES from eturnerx at market"
}, {
"if": "eturnerx.VIBES_balance > 1.0",
"then": "stake (eturnerx.VIBES_balance) VIBES from eturnerx"
}
Once you've earned some SWAP.HIVE, you might want to withdraw some as HIVE. Karaka can do this with a transfer to @hiveswap. A memo with some text is compulsory; otherwise, your coins might go missing. Also, I would only do this with small amounts.
"if": "eturnerx.SWAP.HIVE_balance > 102.0",
"transfer (eturnerx.SWAP.HIVE_balance - 100) SWAP.HIVE from eturnerx to hiveswap memo \"Withdrawal for HE\""
Some further notes: Memos must be enclosed in backslash-escaped-straight-double-quotes \"Like this\"
. Also, check that the @hiveswap service is still running - it is as of May 2021, but things may change in future.
I hope these recipes give you plenty of ideas about how Karaka can automate how you manage your Hive Engine tokens. I've personally found my admin workload decrease, and Karaka rules remove the spur-of-the-moment emotional decision making. Decide once, execute consistently can be a powerful way to meet your stacking goals, and Karaka excels at this.
If you have any questions about Karaka, then please get in touch.