-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Composable Transactions #149
Comments
CommandsA more advanced approach would contain different commands, and the first element would be the command to be executed:
The The The Example 1:
Example 2:
Example 3:
|
VariablesAnother possible feature is the use of variables in the arguments, using some form of identification like One hard-coded variable can be the result of the last call. Example usage:
When we need to store the result to use later, we use the
ImplementationTo implement this is easy: iterate over the items in the array and check if they start and end with For security reasons, block variable substitution in the first item (command) The variable substitution also makes the |
Finished ConceptTo support a variety of use cases, composable transactions should contain many different commands:
List of Commands
UsingHere is an example script (payload) that would be used to check the returned amount of tokens on a token swap:
This feature allows real TRUSTLESS TRANSACTIONS, where the user does not trust even the swap contract! It can allow for direct token swaps between users A and B, in a complete trustless way And many other use cases that are possible with this new feature SecurityExecution of these scripts is only enabled on transactions with type |
COMPOSABLE TRANSACTIONS
It is a method to call many contracts in a single transaction.
All the process is atomic. If some of the calls fail, all the transaction is rolled back.
It is used in cases where the user desires to process many things at the same time atomically.
Use Cases
1: Purchase airplane tickets and hotel reservation from different contracts, only if both succeed. If some of the purchases fail, the other is reverted (the user does not want one of them if the other is not acquired).
2: Swap token and buy something with it. If the purchase fails, the user does not want that token.
3: Swap tokens using a split route. If one of the routes fail, revert the other(s). Also check the minimum output in the transaction itself (by adding individual outputs) and revert if not satisfied.
4: Swap to an exact amount of the output token when using a multi-hop route, by either: a. doing a reverse swap of the surplus amount, or b. querying a contract for the right amount to send (between approved range) in the same transaction.
5: Add liquidity to a pool (2 tokens) in a single transaction
6: Trustless swap or purchase - check if the purchased token was received, otherwise revert the transaction
7: Transferring tokens (fungible and/or non-fungible) to multiple recipients at the same time
8: Transferring different tokens (fungible and/or non-fungible) to one recipient in a single transaction
9: Mint many non-fungible tokens (NFTs) in a single transaction
10: Approve contract B to use contract A (token) and then call a function on contract B that handles the resources on contract A (eg: approve and swap, approve and add liquidity) on a single transaction
11: Approve, use resource, and remove approval on a single transaction, with the guarantee that no other operation would happen in between while the resource/token is approved to contract B
Implementation
It may be possible to implement it with backwards compatibility with existing transactions, by adding a new transaction type:
And then the call information is stored in the
payload
in JSON format.It would be a list of calls processed in order
Each call containing the contract address, function to call, and arguments:
Example uses:
Buy 2 products or services on a single transaction:
Acquire token2 via swap and buy a product/service with it:
Add liquidity to a swap pair:
The text was updated successfully, but these errors were encountered: