fallen-icarus / cardano-swaps Goto Github PK
View Code? Open in Web Editor NEWA distributed order-book DEX using composable atomic swaps with full delegation control and endogenous liquidity.
License: Apache License 2.0
A distributed order-book DEX using composable atomic swaps with full delegation control and endogenous liquidity.
License: Apache License 2.0
This applies specifically to one-way swaps.
When a user requests to swap one token for another, they lock their tokens in the swap script. A trader can then fulfill that swap request by depositing the requested tokens into the swap script.
The requested tokens are now available to the user attached to their staking key. However, for the tokens to become spendable, the user has to "unlock" the tokens by signing with their stake key. This presents a point of friction because now the user has to visit the dapp again to use their tokens. Whereas a user may expect to submit a swap request, then come back later and either the requested tokens are in their wallet or they're not. If they're not in the wallet, it's reasonable for a user to need to take action to close the swap request (if desired). If the swap is completed, a user shouldn't need to go back to the dapp to make the tokens spendable.
The ideal case is that after a one-swap is fully completed, the tokens are deposited into the user's wallet and become spendable like any other Cardano native token.
To implement this, perhaps a new entry can be inserted into the SwapDatum indicating the final destination after the swap is completed. A simple check can be made to verify this value matches the wallet initiating the swap request. (Or alternatively, signing the transaction is authorization enough, thereby allowing the user to create a composable swap that sends the tokens to another destination after the swap is completed.)
For unlocking the tokens after a swap is completed, I see two ways this behavior could be implemented:
The second approach seems the most straightforward to implement. This would give a dapp permission to unlock tokens on a user's behalf. The disadvantages are that it still requires an additional transaction to unlock the tokens, the dapp owner would need to cover the cost of this transaction if they're to offer this user convenience, and there's no guarantee that the dapp owner will execute these requests on behalf of the user.
The first approach is ideal but will require more modifications and thought. Some assurances could also be provided to the user that the if the swap is fully executed, then they'll receive the tokens at their authorized destination. This will cut down on the number of transactions required to finish a swap.
I am trying to execute a one way swap - however, its not letting me withdraw the offer tokens
This is the datum of my swap utxo
datum { beaconId: '47cec2a1404ed91fc31124f29db15dc1aae77e0617868bcef351b8fd', pairBeacon: 'df91e329aa5a47288aca86568d24d4c1dbd69c8483934d0795fdc2c4fd13ec2c', offerId: '91d4f382273f442f15e9da48cb23349ba275f8818e4c7ac5d1004a16', offerName: '4d79555344', offerBeacon: '461e1f087114b671d83b7b461fb93ac6c89b3ee5491deae6a91039bef997a9b6', askId: 'cd453198b8056208716e175e2638f99465712d79d1f39b34248c8bee', askName: '446a65644d6963726f555344', askBeacon: '016e1bc9aafb50bf22059a36db003e16e3e43d415cf8eae5f122d251f66ca307', swapPrice: { numerator: 150000000n, denominator: 150000000n }, prevInput: null }
and this is the datum am supplying inline while trying to execute the swap { beaconId: '47cec2a1404ed91fc31124f29db15dc1aae77e0617868bcef351b8fd', pairBeacon: 'df91e329aa5a47288aca86568d24d4c1dbd69c8483934d0795fdc2c4fd13ec2c', offerId: '91d4f382273f442f15e9da48cb23349ba275f8818e4c7ac5d1004a16', offerName: '4d79555344', offerBeacon: '461e1f087114b671d83b7b461fb93ac6c89b3ee5491deae6a91039bef997a9b6', askId: 'cd453198b8056208716e175e2638f99465712d79d1f39b34248c8bee', askName: '446a65644d6963726f555344', askBeacon: '016e1bc9aafb50bf22059a36db003e16e3e43d415cf8eae5f122d251f66ca307', swapPrice: { numerator: 150000000n, denominator: 150000000n }, prevInput: { transactionId: { hash: '4c37615d6110f93e64ce28b948745e712ffc836234be7ac0238874030eb0dacb' }, outputIndex: 0n } }
This is my transaction
` const assetsToSend = {
lovelace: 1000000n,
'47cec2a1404ed91fc31124f29db15dc1aae77e0617868bcef351b8fd016e1bc9aafb50bf22059a36db003e16e3e43d415cf8eae5f122d251f66ca307': 1n,
'47cec2a1404ed91fc31124f29db15dc1aae77e0617868bcef351b8fd461e1f087114b671d83b7b461fb93ac6c89b3ee5491deae6a91039bef997a9b6': 1n,
'47cec2a1404ed91fc31124f29db15dc1aae77e0617868bcef351b8fddf91e329aa5a47288aca86568d24d4c1dbd69c8483934d0795fdc2c4fd13ec2c': 1n,
'91d4f382273f442f15e9da48cb23349ba275f8818e4c7ac5d1004a164d79555344': 1000000n, //withdrawing total offer tokens - 1 to the lucid.wallet.address
};
const tx = lucid
.newTx()
.validTo(Date.now() + 200000)
.collectFrom([utxo], Data.to(new Constr(2, [])))
.payToContract(
utxo.address,
{ inline: Data.to(datum, OneWaySwapDatum) },
assetsToSend
);`
However, am getting error Fail: offer_taken * price <= ask_given
it works if I set assetsToSend to the utxo.assets
so basically if I dont change any assets only then it works. But I need to withdraw the offer asset.
Can you please help me understand what I am missing?
Hey all,
Has this protocol been released on mainnet yet? I see the example all use test net.
Love what you guys are developing.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.