Giter Club home page Giter Club logo

cardano-swaps's Issues

Feature request: allow closing of completed swap without user approval

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:

  1. Allow destination to be changed to the authorized address within the datum during the execution of the Swap redeemer for the swap script if: a) the token balance reaches zero, and b) all beacon tokens are burned (i.e. the swap is completed).
  2. Create a new redeemer for the swap script that allows spending if: a) the token balance is zero and b) all beacon tokens are burned (i.e. the swap is completed), and c) the destination matches the authorized destination in the datum.

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.

Cannot withdraw offer asset from one way swap utxo

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?

Mainnet?

Hey all,

Has this protocol been released on mainnet yet? I see the example all use test net.

Love what you guys are developing.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.