An autonomous/decentralized swap app for tokens transfer between 2 parties without third-party intermediation :D
When you want to negotiate something with someone, don't you feel afraid of being the first to give/send and being deceived by the other party, who might run away without fulfilling the agreement? The solution for this case in token transfers is: AutonomousSwap. There is a smart contract that does the intermediation between the parties, only allowing the final trade in both of them prove and confirm they have the funds. In the end, the transfer is made at the same transaction, sending the tokens for both of them at the same time.
It's like an exchange in a MMORPG, where we first declare our itens to be traded, then confirm the partner's submition and finally complets the trade.
The stages are:
Order creation: One of the parties creates an order, passing:
This step also validates:
This process generates an random 'orderID' that identifies the order, write it down. With this orderID, the parter can then:
Join an order: A partner can join an existing/active order using an orderID. Need pass:
This step validates the same validations as the previous step, plus:
After that, both must approve the amount/id submitted in the order to follow the next stages:
Then, to finish, the parter does:
It's finished! You and your partner swapped tokens with each other without concern!
!!!!WAIT THERE! WHAT IF AFTER THE THIRD STAGE I REGRET MY DECISION? HOW CAN I HAVE MY TOKENS BACK?!!!! Worry not! There is a fifth stage:
That is it! Done :D
Note: At the moment, the front-end only works on the Sepolia AutonomousSwap deployed instance (needs to change rpcUrl and contract addres in the js files to work in other networks).
I used Solidity as the smart contract programming language, Hardhat as the smart contract development framework and Remix to test the functionality fastly. I've used the partner infrastructure to do the deployment. Everything went well. I've also male an awesome front-end interface with Svelte, Javascript, Typescript, HTML, CSS, Tailwind.