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

Add split coins into parts to qclient #338

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

littleblackcloud
Copy link
Contributor

@littleblackcloud littleblackcloud commented Nov 8, 2024

Adds flags -p/--parts and -a/--part-amount, allowing you to split a coin into parts without needing to calculate and specifying the amounts.

Example - Split a coin into the specified amounts:

$ qclient token coins
1.000000000000 QUIL (Coin 0x1234)
$ qclient token split 0x1234 0.5 0.25 0.25
$ qclient token coins
0.250000000000 QUIL (Coin 0x1111)
0.250000000000 QUIL (Coin 0x2222)
0.500000000000 QUIL (Coin 0x3333)

Example - Split a coin into three parts:

$ qclient token coins
1.000000000000 QUIL (Coin 0x1234)
$ qclient token split 0x1234 --parts 3
$ qclient token coins
0.000000000250 QUIL (Coin 0x1111)
0.333333333250 QUIL (Coin 0x2222)
0.333333333250 QUIL (Coin 0x3333)
0.333333333250 QUIL (Coin 0x4444)

Note: Coin 0x1111 is the remainder.

Example - Split a coin into two parts using the specified amounts:

$ qclient token coins
1.000000000000 QUIL (Coin 0x1234)
$ qclient token split 0x1234 --parts 2 --part-amount 0.35
$ qclient token coins
0.300000000000 QUIL (Coin 0x1111)
0.350000000000 QUIL (Coin 0x2222)
0.350000000000 QUIL (Coin 0x3333)

Note: Coin 0x1111 is the remainder.

"github.com/shopspring/decimal"
"github.com/spf13/cobra"
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
)

func getCoinAmount(coinaddr []byte) *big.Int {
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 couldn't find a more efficient way to query the amount of a specific coin address, so I adopted the approach from client/cmd/coins.go.

If there's a better way I'm happy to refactor :)

@tjsturos
Copy link
Contributor

tjsturos commented Nov 8, 2024

One suggestion: add a --amounts flag to create 3 equal tokens in that amount and the rest as a remainder.

E.g.

# Original token 0x0001 has amount 10.0000 QUIL
qclient token split 0x0001 --parts 3 --amounts 1

# coins after split using --amounts
qclient token coins
7.000000000000 QUIL (Coin 0x0002) # split automatic remainder
1.000000000000 QUIL (Coin 0x0003) # split part 1
1.000000000000 QUIL (Coin 0x0004) # split part 2
1.000000000000 QUIL (Coin 0x0005) # split part 3

@littleblackcloud
Copy link
Contributor Author

Thanks for your suggestion @tjsturos! It's been implemented :)

@littleblackcloud littleblackcloud changed the title Add flag to split coins into parts Split coins into parts Nov 9, 2024
@littleblackcloud
Copy link
Contributor Author

littleblackcloud commented Nov 10, 2024

Added tests for the split operations.

@CassOnMars let me know if you prefer a single commit per PR :)

@littleblackcloud littleblackcloud changed the title Split coins into parts Add split coins into parts to qclient Nov 15, 2024
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.

2 participants