-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
WIP: Uniswap Module #4518
WIP: Uniswap Module #4518
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.
very excited about this module. Added some early comments. Check this issue for the next upcoming standard format for modules #4438
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.
WIP review
x/uniswap/internal/types/params.go
Outdated
) | ||
|
||
// uniswap parameters | ||
// Fee = 1 - (FeeN - FeeD) |
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.
Do you mean FeeN / FeeD
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.
yea, will update
x/uniswap/internal/types/params.go
Outdated
// uniswap parameters | ||
// Fee = 1 - (FeeN - FeeD) | ||
type FeeParams struct { | ||
FeeN sdk.Int `json:"fee_numerator"` // fee numerator |
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.
Why don't you just use sdk.Dec
here?
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.
The way getInputAmont/getOutputAmount are constructed in keeper.go requires these params. Would love help on reworking the equations to use the fee as sdk.Dec
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.
Agree, let’s use Dec
x/uniswap/handler.go
Outdated
// HandleMsgSwapOrder handler for MsgSwapOrder | ||
func HandleMsgSwapOrder(ctx sdk.Context, msg MsgSwapOrder, k Keeper) sdk.Result { | ||
if msg.IsBuyOrder { | ||
inputAmount := k.GetInputAmount(ctx, msg.SwapDenom, msg.Amount) |
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.
Where does the bound check occur?? Shouldn't it be added after this line?
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.
Also a deadline check is needed right?
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.
yea, also need to check that sender has enough of coin being sold. Also need checks balance checks for adding/removing liquidity
x/uniswap/internal/keeper/querier.go
Outdated
return queryBalance(ctx, req, k) | ||
case types.QueryLiquidity: | ||
return queryLiquidity(ctx, req, k) | ||
case types.Parameters: |
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 think this is a typo. Should be QueryParameters instead. Similarly, I'm guessing the method to be called is queryParameters()
ModuleCdc = codec.New() | ||
RegisterCodec(ModuleCdc) | ||
ModuleCdc.Seal() | ||
} |
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 guess codec.New() needs to be called once.
|
||
return sdk.Result{} | ||
} | ||
|
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 was going through 'GetInputPriceand
GetOutputPrice` mentioned in https://github.com/runtimeverification/verified-smart-contracts/blob/uniswap/uniswap/x-y-k.pdf
After discussing with @AdityaSripal we both feel that you swapped lesser than
and greater than
when it comes to buy order and sell order.
For instance, for a buy order, the calculated amount should be lesser than the maximum amount the sender is willing to pay. Thus change if msg.Input.Amount.LT(calculatedAmount)
to if calculatedAmount.LT(msg.input.Amount)
Similarly for a sell order, the calculated amount should be greater than the minimum amount the sender is willing to pay. Thus change if msg.Output.Amount.GT(outputAmount)
to if calculatedAmount.GT(msg.Output.Amount)
. I would change outputAmount
to calculatedAmount
for uniformity.
A better way to write the comment would be to specify calculated amount first followed by the amount the sender is willing to pay.
x/uniswap/internal/keeper/keeper.go
Outdated
panic(err) | ||
} | ||
return | ||
} |
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 guess it's better to use MustUnmarshalBinaryBare
and MustMarshalBinaryBare
instead. They take care of the panic part. This way the code gets reduced to one line and we don't even require the two methods.
x/uniswap/handler.go
Outdated
k.CreateReservePool(ctx, msg.Denom) | ||
} | ||
|
||
nativeLiqudiity, err := k.GetReservePool(ctx, NativeAsset) |
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.
Just a minor typo.
return bz, nil | ||
} | ||
|
||
// queryLiquidity returns the total liquidity avaliable for the provided denomination |
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.
avaliable
is a misspelling of available
(from misspell
)
// ValidateParams validates a set of params | ||
func ValidateParams(p Params) error { | ||
// TODO: ensure equivalent sdk.validateDenom validation | ||
if strings.TrimSpace(p.NativeDenom) != "" { |
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'm not sure how to go about validating this since validateDenom
is private. Maybe just call sdk.NewCoin(p.NativeDenom, sdk.ZeroInt())
to see if it panics and then catch the 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.
Maybe just make ValidateDenom
public?
} | ||
|
||
// HasReservePool returns true if the reserve pool exists | ||
func (keeper Keeper) HasReservePool(ctx sdk.Context, denom string) bool { |
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.
Gonna remove this and add a boolean to GetReservePool
to indicate if the reserve pool exists or not
cam we update the module based on #4618? 🙏 |
closing to switch from fork as base to branch on this repo, see #4644 for future development |
Addresses #4443
Targeted PR against correct branch (see CONTRIBUTING.md)
Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
Wrote tests
Updated relevant documentation (
docs/
)Added a relevant changelog entry:
clog add [section] [stanza] [message]
rereviewed
Files changed
in the github PR explorerFor Admin Use: