Skip to content
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

Should be able to transfer leftover/change Ada back to it original address! #537

Closed
code-brewer opened this issue Jun 23, 2022 · 4 comments
Labels
enhancement New feature or request Tracked Issue is tracked in our internal backlog

Comments

@code-brewer
Copy link

code-brewer commented Jun 23, 2022

Describe the feature you'd like

These question come from the issue when practice the PPP week01 on testnet. I did some Bid action on the contract.
One Bid Tx is: https://testnet.cardanoscan.io/transaction/721856d69696a58a466b02779b01d28058356ef6cf3e4e4dee3952a6faddc081

In this Tx, one input Utxo that has 1000 Ada was consumed for about 5.555 Ada, but the leftover was not return its source account, instead, the leftover was split into 2 part and sent to two account.
Though all these accounts belong to one Wallet.
But I want the leftover return to it original address. How to archive this goal?

Code of the bid endpoint is almost the same as PPP week01 example, exception that I remove the mustValidateIn limitation.

bid :: forall w s. BidParams -> Contract w s Text ()
bid bp@BidParams{..} = do
    (oref, o, d@AuctionDatum{..}) <- findAuction bpCurrency bpToken
    when (bpBid < minBid d) $
        throwError $ pack $ printf "bid lower than minimal bid %d" (minBid d)
    pkh <- ownPaymentPubKeyHash
    let b  = Bid {bBidder = pkh, bBid = bpBid, bSecret = emptyByteString}
    let b2  = Bid {bBidder = pkh, bBid = bpBid, bSecret = bpSecret}
        d' = d {adHighestBid = Just b}
        v  = Value.singleton bpCurrency bpToken 1 <> Ada.lovelaceValueOf (minLovelace + bpBid)
        r  = Redeemer $ PlutusTx.toBuiltinData $ MkBid b2

        lookups = Constraints.typedValidatorLookups typedAuctionValidator P.<>
                  Constraints.otherScript auctionValidator                P.<>
                  Constraints.unspentOutputs (Map.singleton oref o)
        tx      = case adHighestBid of
                    Nothing      -> Constraints.mustPayToTheScript d' v                            <>
                                    Constraints.mustSpendScriptOutput oref r
                    Just Bid{..} -> Constraints.mustPayToTheScript d' v                            <>
                                    Constraints.mustPayToPubKey bBidder (Ada.lovelaceValueOf bBid) <>
                                    Constraints.mustSpendScriptOutput oref r
    ledgerTx <- submitTxConstraintsWith lookups tx
    void $ awaitTxConfirmed $ getCardanoTxId ledgerTx
    logInfo @P.String $ printf "made bid of %d lovelace in auction %s for token (%s, %s)"
        bpBid
        (P.show adAuction)
        (P.show bpCurrency)
        (P.show bpToken)

I have manager to do this via cardano-cli. So my question are:

  1. Is there equivalent constraints function in PAB endpoint as --tx-in-collateral of cardano-cli ?
  2. Is there equivalent constraints function in PAB endpoint as --change-address of cardano-cli ?

Maybe they are there, but I can not find them while searching for long time.

Describe alternatives you've considered

Should provide constraints to support feature like cli's --tx-in-collateral and --change-address.

@code-brewer code-brewer added the enhancement New feature or request label Jun 23, 2022
@code-brewer code-brewer changed the title Should be able to transfer leftover/change Ada to it original address! Should be able to transfer leftover/change Ada back to it original address! Jun 23, 2022
@ghost
Copy link

ghost commented Jun 23, 2022

It seems it's the way how cardano-wallet works which we use to balance the transaction. There is an issue for this — cardano-foundation/cardano-wallet#2614

I'm not sure but you may try to avoid using the cardano-wallet balancing (submitTxConstraintsWith calls balanceTx).

@koslambrou
Copy link
Contributor

And to answer the comparison with cardano-cli, we don't yet have the equivalent of --tx-in-collateral and --change-address. However they are tracked internally.

@koslambrou koslambrou added the Tracked Issue is tracked in our internal backlog label Jun 27, 2022
@koslambrou
Copy link
Contributor

BTW, the change address bit is already tracked by this issue: #108.

@koslambrou
Copy link
Contributor

The --tx-in-collateral fix is implemented in #690 and the change address is tracked in #108. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Tracked Issue is tracked in our internal backlog
Projects
None yet
Development

No branches or pull requests

2 participants