aergoio / aergo

aergo blockchain kernel
http://docs.aergo.io
MIT License
214 stars 44 forks source link

Text-Based Transactions #252

Open kroggen opened 12 months ago

kroggen commented 12 months ago

Create a new type of transaction (TEXT) in which the payload contains a text command

Then the nodes must process the command via the Aergo engine (Go or smart contract or both)

This makes the transaction simpler to understand when signing on a hardware wallet

Examples

Transfer ARC1 tokens

Transfer 0.235 ABC to Am23az…

Transfer {amount} {symbol} to {account}

Transfer ARC2 token

Transfer ShowTickets "FISU 2023 A125" to Am23az…

Transfer {contract} {id} to {account}

The rule to differentiate transfer: if first argument is a number -> ARC1, otherwise -> ARC2


Swap ARC1 tokens

Swap 10 ABC for 3.5 DOPS using XSwap
Swap 10 ABC for [at least] 3.5 DOPS using XSwap

Swap {amount} {symbol} for [at least] {amount} {symbol} using {swap-service} [text options...]


Limit Swap orders

Swap 10 ABC for 3.5 DOPS using XSwap Limit-Order

Create Swap Order: 10 ABC for 3.5 DOPS using XSwap

Create Order: Swap 10 ABC for 3.5 DOPS using XSwap

Direct Swap

Create order

Sell 10.1 ABC at 5.3 USDT each
Sell 10.1 ABC for 123.4 USDT
Sell 123.4 USDT for 10.1 ABC

Buy 10.1 ABC with 123.4 USDT
Buy 10.1 ABC at 5.3 USDT each

Swap 10.1 ABC for 123.4 USDT

Create Swap Order: 10 ABC for 3.5 DOPS

Create Order: Swap 10 ABC for 3.5 DOPS

Execute order

Buy 10.1 ABC with 123.4 USDT from Am…

Sell 10.1 ABC at 5.3 USDT each to Am…

Swap 10.1 ABC for 123.4 USDT with Am...

Cancel order

Cancel order 2: Sell 10.1 ABC at 5.3 USDT each
Cancel order 3: Sell 10.1 ABC for 123.4 USDT
Cancel order 4: Sell 123.4 USDT for 10.1 ABC

Cancel order 5: Buy 10.1 ABC with 123.4 USDT
Cancel order 5: Buy 10.1 ABC at 5.3 USDT each

or:

Cancel sale of 10.1 ABC at 5.3 USDT each
Cancel sale of 10.1 ABC for 123.4 USDT
Cancel sale of 123.4 USDT for 10.1 ABC

Cancel buy of 10.1 ABC with 123.4 USDT
Cancel buy of 10.1 ABC at 5.3 USDT each

What if there are many with the same values?

  1. cancel just one
  2. cancel all
  3. cancel by id

Check NFTs

Amounts

Requirements

Must keep a store of symbol -> address

For ARC2 it can be name -> address

Or maybe also use the name system to resolve symbol -> address

Name of swap contracts should also point to an address

May need to get the address of the pair from the swap factory or router

Maybe use a MultiSig contract for that, or DAO

Notes

How to support different languages? (localization)

  1. Use AI to translate? Is it possible to send a translate request, be processed by many nodes, the result aggregated and signed, but not saved to the blockchain? Only do compute, not storage write. And store on blockchain only the allowed nodes and the logic. Like a transaction that does not save to the chain. but the txn itself is saved (nonce. maybe also paid?) Or just use 3+ diff nodes, each one with known public key, then check the signature of responses
  2. Hardware wallets do not support UTF-8, so why? Only show the translation on screen
  3. Display a simplified command, like "10.1 ABC -> 123.4 USDT" for "Sell 10.1 ABC for 123.4 USDT"
  4. Support many languages, include the lang id on the txn, and let the contract deal with them (server side, native support)

How to handle options, like slippage?

kroggen commented 12 months ago

Command Processing

The command can be processed by:

A. A Lua smart contract running on the user account (similar to composable txns) B. Code in golang that uses a smart contract to read the maps

On the first case, as it is running on the user account it cannot read the token maps, so it must call another contract to read the map of symbol to address

Contracts that support text transactions could export a function with common name, like execute_text_command() On this case the recipient could be optionally filled (contain the MultiSig wallet address) If empty, it means the sender's account The sender must be approved to run the command!

Direct Swap:

  1. via EOA contract (maybe not important? advantage: the code can be updated)
  2. using a smart contract as wallet (super wallet)

Super Wallet

The user can have many wallets. The wallet address must be specified on the txn recipient, and displayed on the hardware wallet:

---------------------
       Wallet
Am89us4...
---------------------

---------------------
       Command
...
---------------------

How to use the text transaction with the "super wallet"?

  1. MultiSig wallets can call the contract that processes text-based commands, on its behalf (delegate call)
  2. Have a special text command to interface with MultiSig wallets, like create proposal, vote...
  3. Just transfer the text command to the contract. It can then call the text-processing contract
  4. Put the MultiSig wallet address on the txn recipient. Call the execute_text_command() on the contract, using the sender as the sender
Approve Proposal: 5

Approve Proposal: Sell 10.1 ABC for 123.4 USDT

Approve Proposal 5: Sell 10.1 ABC for 123.4 USDT

There may be also proposals with:

If the proposal is too long, it can just show the proposal ID.

EOA Contract

How the text-processing contract could call the user's account code? First check if the cmd is recognized. If yes, process it. If not, transfer the text command to the contract via calling the execute_text_command() on the user's wallet code (check the sender!). It can process commands related to the account, like "Buy", "Sell", "Cancel" (limit orders) When making the call to the user's account code: Make a call using the account address as the recipient, set the function name and args... the golang code should load the user's account contract and make the call Or just do a delegate call (?)

Composable Transactions

1. Execute a MultiCall script for a given text command

Should it handle Composable Txns? A. many operations on a single txn B. check the amount of received token

Or use templates for this purpose

Maybe the text commands can replace templates for Composable Transactions. Maybe all cases in which templates would be used (common cases) could be replaced by text commands

Should it have separate text commands for Composable Transactions? (different txn type?)

2. Many text commands on a transaction

Both these could be supported:

  1. Whole commands separated by Tab
  2. Composable commands:
Transfer 0.235 ABC, 3.5 DOPS, ShowTickets "FISU 2023 A125" to Am23az…

Transfer to Am23az…Gs89: 0.235 ABC, 3.5 DOPS, ShowTickets "FISU 2023 A125"

But how would be the interface on the wallet to make multiple transfers?

Check also the method to compose transactions

shepelt commented 3 months ago

I think there are additional interesting use-case for text-based transactions

I think both are very interesting side-effects.

BTW Small Lanauge Models such as Phi-2 (https://huggingface.co/spaces/plug/phi-offline?model=phi_2_0_q4k) are compact enough to operate even in the browser and some businesses (such as banks) that used to rely on old-styled chatbots found legitimate use-cases for those models. It will be interesting to support plugging-in compact language models on to Aergo. (Of course direct on-chain storage will be still dificult, but we can figure something out like IPFS or filecoin to do that)