-
Notifications
You must be signed in to change notification settings - Fork 118
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
Minor asset loop out fixes #876
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I think a unit test around the fixpoint conversion would make sense.
484d049
to
32647a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🏆
Added few comments.
// | ||
// * `F_s` is the scale component. It is an integer specifying how | ||
// many decimal places `F_c` should be divided by to obtain the fractional | ||
// representation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This type is the same as github.com/lightninglabs/taproot-assets/taprpc/rfqrpc.FixedPoint
Can we include .proto file from taproot-assets?
If this is not possible, I propose to add TODO to deduplicate this in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not straightforward to include the proto files from other repos.
E.g. even within tap it's in multiple files:
https://github.com/lightninglabs/taproot-assets/blob/563efdc6c50b73cc9ea9d4fd77553c46948f6f01/taprpc/rfqrpc/rfq.proto#L112
https://github.com/lightninglabs/taproot-assets/blob/563efdc6c50b73cc9ea9d4fd77553c46948f6f01/taprpc/priceoraclerpc/price_oracle.proto#L48
|
||
// unmarshalFixedPoint converts an RPC FixedPoint to a BigIntFixedPoint. | ||
func unmarshalFixedPoint(fp *looprpc.FixedPoint) (*rfqmath.BigIntFixedPoint, | ||
error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to reuse https://pkg.go.dev/github.com/lightninglabs/taproot-assets/taprpc/rfqrpc#UnmarshalFixedPoint
looprpc.FixedPoint is the same type as rfqrpc.FixedPoint (has the same fields).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible to create a struct manually filling the fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
created a rfqrpc.FixedPoint
struct and called rfqrpc.UnmarshalFixedPoint
loopd/swapclient_server.go
Outdated
SwapAssetRate: &looprpc.FixedPoint{ | ||
Scale: uint32(quote.LoopOutRfq.SwapAssetRate.Scale), | ||
Coefficient: quote.LoopOutRfq.SwapAssetRate.Coefficient.String(), | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose to factor out this transformation to a function, e.g. marshalFixedPoint
.
It is used twice, for PrepayAssetRate and for SwapAssetRate.
SwapAssetRate: marshalFixedPoint(quote.LoopOutRfq.SwapAssetRate),
We can also cover functions marshalFixedPoint and unmarshalFixedPoint with a unit test making sure everything is converted properly back and forth.
32647a5
to
9008b3b
Compare
9008b3b
to
d0191d2
Compare
This PR adds some minor asset loop out fixes:
This is what a loop out quote will look like now:
![image](https://private-user-images.githubusercontent.com/8904314/405550561-7855ea47-97d7-4005-8005-7d508244543b.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg5MDU1ODEsIm5iZiI6MTczODkwNTI4MSwicGF0aCI6Ii84OTA0MzE0LzQwNTU1MDU2MS03ODU1ZWE0Ny05N2Q3LTQwMDUtODAwNS03ZDUwODI0NDU0M2IucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIwNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMDdUMDUxNDQxWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ODg2NzQxMTliMWI0ZDA5MjQ4NjkwYTU5NTFhMmQzMjZhMmYyZGNjMDczZmYzYzA3MjA2ZjMzOGM0YzdkZmQzMyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.VDvxml3yGf1zDqokaqJkGKHtvLF2ldaQ8hOFB6W_Y6E)