Twin Actions
V API
module crypto
Blockchain Actions (crypto)
Contents
- account_delete
- account_init
- asset_burn
- asset_create
- asset_delete
- asset_mint
- buy
- defi_pool_deposit
- defi_pool_info
- defi_pool_withdraw
- defi_pool_withdraw_all
- info
- orderbook_info
- sell
- send
- trade_delete
- trade_delete_all
- trade_info
- AccountArgs
- AccountAsset
- AccountInfo
- AssetBurnArgs
- AssetCreateArgs
- AssetDeleteArgs
- AssetMintArgs
- BuyActionArg
- DefiPoolDepositArgs
- DefiPoolIdentity
- DefiPoolInfo
- DefiPoolInfoPairInfo
- DefiPoolWithDrawArgs
- MultiSig
- OrderBookInfo
- OrderBookInfoArgs
- OrderBookInfoPair
- SellActionArg
- SendArgs
- TradeInfoPair
account_delete
fn account_delete(name string) ?
delete account on the handler in case it was already initialized, does not give error if not active yet if multisignature more than one will have to do
account_init
fn account_init(args AccountArgs) ?
init the account on the action handler will give error if it already exists and mneomonic or type different will also give error if an error to create it e.g. wrong mnemonic the account will be selected, which means all actions done after are done on this account
asset_burn
fn asset_burn(args AssetBurnArgs) ?
destroy some of the tokens of the asset multisignature is used when asset was multisignature
asset_create
fn asset_create(args AssetCreateArgs) ?
asset_delete
fn asset_delete(args AssetDeleteArgs) ?
deletes the asset, checks the multisignature approach
asset_mint
fn asset_mint(args AssetMintArgs) ?
mint amount of tokens of the asset multisignature is used when asset was multisignature
buy
fn buy(args BuyActionArg) ?string
set of actions to buy an asset everything is re-calculated to USD pricing of USD comes from the blockchain (only stellar/algorand) the action server will execute in the background and return a uid4 identifier, which can be used to check sometimes the blockchain supports a deadline, sometimes the action handler will have to do it
pub struct BuyActionArg {
asset_buy string // the asset you want to buy
max_price_usd f64 //maximum price your want to biy for
expirationtime_min u16 //max time in minutes, the trade stays open
memo string // per type blockchain we need to check that memo
field is not too long, is not everywhere used
}
defi_pool_deposit
fn defi_pool_deposit(account string, args DefiPoolDepositArgs) ?
set of arguments to create, or add to a DEFIPool
pool can exist or it can be a new one if there is already money, you will just add to it
defi_pool_info
fn defi_pool_info(args DefiPoolIdentity) ?DefiPoolInfo
get all info from defi pool
defi_pool_withdraw
fn defi_pool_withdraw(account string, args DefiPoolWithDrawArgs) ?
withdraw money from the pool need to specify which currency and amount per currency
defi_pool_withdraw_all
fn defi_pool_withdraw_all(account string, args DefiPoolIdentity) ?
withdraw money from the pool, do the maximum the purpose is to get all your money out from the pool the handler need to implement the logic to take all out
info
fn info(name string) ?AccountInfo
return info about your account, the name is the name of the account as used in .account_init() the info returned
pub struct AccountInfo {
pubkey_bin []u8 // binary form of key
pubkey_ed25519 ed25519.PublicKey // can be empty, if not same type, but often it is
assets []Asset
}
pub struct AccountAsset {
amount f64
currency string // always lowercase
}
orderbook_info
fn orderbook_info(account string, args OrderBookInfoArgs) ?string
returns all relevant info from an orderbook
sell
fn sell(args SellActionArg) ?string
set of actions to sell an asset everything is re-calculated to USD, the money you get back is in USDC pricing of USD comes from the blockchain (only stellar/algorand) the action server will execute in the background and return a uid4 identifier, which can be used to check sometimes the blockchain supports a deadline, sometimes the action handler will have to do it
pub struct SellActionArg {
asset_sell string // the asset you want to sell
min_price_usd f64 // min price your want to sell for always in USDC
expirationtime_min u16 // max time in minutes, the trade stays open
memo string // per type blockchain we need to check that memo
field is not too long, is not everywhere used
}
send
fn send(args SendArgs) ?
send money to a user on the chosen blockchain network the account used is the one who is selected
SendArgs {
account string
to string
amount f64
memo string
currency string
}
``` multisig is supported, if account is multisig, the the needed needs to be done
[[Return to contents]](#Contents)
## trade_delete
```v
fn trade_delete(account string, uid string) ?TradeInfoPair
dlete an open trade, the uid is unique uid is uid4, and as given by sales/buy order creation
trade_delete_all
fn trade_delete_all(account string) ?TradeInfoPair
delete all you open trades
trade_info
fn trade_info(account string, uid string) ?TradeInfoPair
returns all relevant info from an orderbook uid is uid4, and as given by sales/buy order creation
AccountArgs
struct AccountArgs {
pub:
name string
mnemonic string
blockchaintype BlockchainType
expiration int = 300 // will expire default 5 min
multisig MultiSig // optional
}
AccountAsset
struct AccountAsset {
amount f64
currency string // always lowercase
}
AccountInfo
struct AccountInfo {
pubkey_bin []u8 // binary form of key
pubkey_ed25519 ed25519.PublicKey // can be empty, if not same type, but often it is
assets []Asset
}
AssetBurnArgs
struct AssetBurnArgs {
pub:
account string
name string
burnamount f64
}
AssetCreateArgs
struct AssetCreateArgs {
pub:
account string
name string
// TODO specify
multisig MultiSig // optional
}
AssetDeleteArgs
struct AssetDeleteArgs {
pub:
account string
name string
}
AssetMintArgs
struct AssetMintArgs {
pub:
account string
name string
mintamount f64
}
BuyActionArg
struct BuyActionArg {
account string
asset_buy string // the asset you want to buy
max_price_usd f64 // maximum price your want to buy for
expirationtime_min u16 // max time in minutes, the trade stays open
memo string // per type blockchain we need to check that memo field
// is not too long, is not everywhere used
}
DefiPoolDepositArgs
struct DefiPoolDepositArgs {
poolasset1 string // a pool has 2 assets, this is the first one
amount1 f64
currency1 string
poolasset2 string // a pool has 2 assets, this is the first one
amount2 f64
currency2 string
memo string // per type blockchain we need to check that memo field is not too long, is not everywhere used
}
set of arguments to create, or add to a DEFIPool this is for an AMM DEFI pool (Automatic Market Making DEFI Pool)
DefiPoolIdentity
struct DefiPoolIdentity {
poolasset1 string // a pool has 2 assets, this is the first one
poolasset2 string
}
identify a pool, is unique, the order of asset 1 or 2 does not matter
DefiPoolInfo
struct DefiPoolInfo {
pairs []DefiPoolInfoPairInfo // is always 2, need to check this is correct
// TODO what else is important here?
}
DefiPoolInfoPairInfo
struct DefiPoolInfoPairInfo {
currency string
amount f64
// TODO what else is important here?
}
DefiPoolWithDrawArgs
struct DefiPoolWithDrawArgs {
poolasset1 string // a pool has 2 assets, this is the first one
amount1 f64
currency1 string
poolasset2 string // a pool has 2 assets, this is the first one
amount2 f64
currency2 string
memo string // per type blockchain we need to check that memo field is not too long, is not everywhere used
}
withdraw money from the pool need to specify which currency and amount per currency
MultiSig
struct MultiSig {
pub:
pubkeys []string // the pubkeys of who needs to sign
min_signature i16 // how many need minimally to sign
}
OrderBookInfo
struct OrderBookInfo {
pub mut:
pairs []OrderBookInfoPair
}
OrderBookInfoArgs
struct OrderBookInfoArgs {
pub mut:
only_my_orders bool = true
}
OrderBookInfoPair
struct OrderBookInfoPair {
pub mut:
currency1 string
// TODO specify
}
SellActionArg
struct SellActionArg {
account string
asset_sell string // the asset you want to sell
min_price_usd f64 // min price your want to sell for always in USDC
expirationtime_min u16 // max time in minutes, the trade stays open
memo string // per type blockchain we need to check that memo field is not too long, is not everywhere used
}
SendArgs
struct SendArgs {
account string // the account we are sending info from
to string
amount f64
currency string
memo string // per type blockchain we need to check that memo field is not too long
}
TradeInfoPair
struct TradeInfoPair {
pub mut:
// TODO specify
state TradeState
}
Powered by vdoc.
module tfgrid
TFGrid workload deployment
inspired by: https://library.threefold.me/info/manual/#/manual3_iac/grid3_javascript
this client allows deployment of all kinds of workloads on TFGrid
- kubernetes
- vm
- zdb
- networks
- qsfs (quantum safe filesystem)
- kvs (key value stor)
- gateways
- ...
TODO:
Principles
The metadata we need to remember is stored in the KVS on TFChain (encrypted by the private key of the account). This metadata is important it has all info in relation to workloads we have deployed, where are they deployed, ...
TODO
- key value stor on tfchain
- most of primitives
- how to do capacity planning using the TFGrid Proxy
Contents
- account_delete
- account_init
- vm_create
- vm_delete
- vm_info
- zdb_create
- zdb_delete
- zdb_info
- ZDBMode
- AccountArgs
- IPRange
- MultiSig
- VMArgs
- VMDisk
- VMInfo
- VMNet
- ZDBArgs
- ZDBInfo
account_delete
fn account_delete(name string) ?
delete account on the handler in case it was already initialized, does not give error if not active yet if multisignature more than one will have to do
account_init
fn account_init(args AccountArgs)
init the account on the action handler for TFGrid will give error if it already exists and mneomonic or type different will also give error if an error to create it e.g. wrong mnemonic the account will be selected, which means all actions done after are done on this account
vm_create
fn vm_create(args VMArgs) ?
init the account on the action handler for TFGrid will give error if it already exists and mneomonic or type different will also give error if an error to create it e.g. wrong mnemonic the account will be selected, which means all actions done after are done on this account
vm_delete
fn vm_delete(name string) ?
vm_info
fn vm_info(name string) ?VMInfo
get object info from a deployed ZDB namespace
zdb_create
fn zdb_create(args ZDBArgs) ?
init the account on the action handler for TFGrid will give error if it already exists and mneomonic or type different will also give error if an error to create it e.g. wrong mnemonic the account will be selected, which means all actions done after are done on this account
zdb_delete
fn zdb_delete(name string) ?
zdb_info
fn zdb_info(name string) ?ZDBInfo
get object info from a deployed ZDB namespace
ZDBMode
enum ZDBMode {
user
seq
}
AccountArgs
struct AccountArgs {
pub:
name string
mnemonic string // private key in mnemonic form to be able to work on the right TFGrid net (TFChain)
nettype TFGridNet
expiration int = 300 // will expire default 5 min
multisig MultiSig // optional, not implemented yet in TFGrid
}
IPRange
struct IPRange {
pub:
range string = '10.10.0.0'
mask i16 = 16
}
MultiSig
struct MultiSig {
pub:
pubkeys []string // the pubkeys of who needs to sign
min_signature i16 // how many need minimally to sign
}
used for when we do smart contract for IT with multiple people
VMArgs
struct VMArgs {
pub:
name string
disks []VMDisk
network VMNet
node_id u32 // id of the node where this VM needs to be deployed
public_ip bool // connect virtual machine to public internet, this VM will receive an IP address
planetary bool // connect the virtual machine to the planetary network
cpu u8 // nr of cpu cores 1...16
memory u16 // MB of ram e.g. 1024*2 would be 2 GB
rootfs_size u16 = 1 // GB of root filesystem
flist string = 'https://hub.grid.tf/tf-official-apps/base:latest.flist'
entrypoint string = '/sbin/zinit init'
env map[string]string // environment variables as passed to VM
ssh_key string // default ssh_key is alias to SSH_KEY in env
}
VMDisk
struct VMDisk {
pub:
name string = 'default'
size i16 = 8 // GB size of disk
mountpoint string = '/testdisk'
}
VMInfo
struct VMInfo {
pub:
name string
disks []VMDisk
network VMNet
node_id u32 // id of the node where this VM needs to be deployed
public_ip bool // connect virtual machine to public internet, this VM will receive an IP address
planetary bool // connect the virtual machine to the planetary network
cpu u8 // nr of cpu cores 1...16
memory u16 // MB of ram e.g. 1024*2 would be 2 GB
rootfs_size u16 = 1 // GB of root filesystem
flist string = 'https://hub.grid.tf/tf-official-apps/base:latest.flist'
entrypoint string = '/sbin/zinit init'
env map[string]string // environment variables as passed to VM
ssh_key string // default ssh_key is alias to SSH_KEY in env
}
TODO what info comes back?
VMNet
struct VMNet {
pub:
name string
range IPRange
}
network needs to correspond to network created on nodes, otherwise this will not work
ZDBArgs
struct ZDBArgs {
pub:
name string
node_id u32 // id of the node where this ZDB namespace needs to be deployed
mode ZDBMode
disk_size u16 = 9
public bool // a public namespace can be read-only if a password is set
password string // password as set on the namespace
}
ZDBInfo
struct ZDBInfo {
pub:
name string
node_id u32 // id of the node where this ZDB namespace needs to be deployed
mode ZDBMode
disk_size u16 = 9
public bool // a public namespace can be read-only if a password is set
password string // password as set on the namespace
}
TODO what info comes back?
Powered by vdoc.
module twinactions
Twin actions
set of actions as can be executed by twin, can be done by different executors e.g.
- vlang
- golang
- javascript
most of them right now are done in golang
Contents
action_send
fn action_send(b resp2.Builder) ?resp.StringLineReader
TODO complete