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

Implement estimateBalancedTxBody and estimateOrCalculateBalancedTxBody #511

Conversation

Jimbo4350
Copy link
Contributor

@Jimbo4350 Jimbo4350 commented Apr 8, 2024

Changelog

- description: |
    Implement estimateBalancedTxBody and estimateOrCalculateBalancedTxBody
# uncomment types applicable to the change:
  type:
  - feature        # introduces a new feature
  # - breaking       # the API has changed in a breaking way
  - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  # - improvement    # QoL changes e.g. refactoring
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

Additional context for the PR goes here. If the PR fixes a particular issue please provide a link to the issue.

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

@Jimbo4350 Jimbo4350 force-pushed the jordan/update-autobalance-to-handle-fee-estimation-and-calculation branch from 1d89840 to 1806feb Compare April 8, 2024 20:38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add Show and Error instances for error types?

cardano-api/internal/Cardano/Api/Fees.hs Outdated Show resolved Hide resolved
@@ -29,9 +29,14 @@ module Cardano.Api.Fees (
evaluateTransactionBalance,

-- * Automated transaction building
estimateBalancedTxBody,
estimateOrCalculateBalancedTxBody,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking it would be good to have unit tests or golden tests for these new functions.

Even if it we have very basic ones to start with.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what changes are we expecting in cardano-cli to follow from this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking it would be good to have unit tests or golden tests for these new functions.

Totally agree. I have a branch open in cardano-node which is passing. I'm going to start looking at cardano-node-emulator because its annoying to have to propagate changes to cardano-testnet in order to test certain functions in cardano-api.

Copy link
Contributor Author

@Jimbo4350 Jimbo4350 Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also what changes are we expecting in cardano-cli to follow from this PR?

It's not 100% clear but I would like to leave build-raw as it is and let users balance the tx on their own. I would like to modify build slightly to offer "offline" and "online" transaction balancing.

-- Why * 100? requiredCollateral is the product of the collateral percentage and the tx fee
-- We choose to multiply 100 rather than divide by 100 to make the calculation
-- easier to manage. At the end of the calculation we then use % 100 to perform our division
-- and round up.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the round up happen? rationalToCoinViaFloor takes the floor, so I assume that's a round down?

Copy link
Contributor Author

@Jimbo4350 Jimbo4350 Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the returnCollateral is floored. This means that the requiredCollateral is rounded upwards and potentially slightly over estimated.

@Jimbo4350 Jimbo4350 force-pushed the jordan/update-autobalance-to-handle-fee-estimation-and-calculation branch from 792aae4 to 0eb6628 Compare April 9, 2024 20:08
@Jimbo4350 Jimbo4350 force-pushed the jordan/update-autobalance-to-handle-fee-estimation-and-calculation branch from 0eb6628 to fa622de Compare April 11, 2024 14:10
@Jimbo4350 Jimbo4350 enabled auto-merge April 11, 2024 14:10
@Jimbo4350 Jimbo4350 added this pull request to the merge queue Apr 11, 2024
Merged via the queue into main with commit 3bbdf8a Apr 11, 2024
20 of 21 checks passed
@Jimbo4350 Jimbo4350 deleted the jordan/update-autobalance-to-handle-fee-estimation-and-calculation branch April 11, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants