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

WIP: Uniswap Module #4518

Closed
wants to merge 17 commits into from
Closed

WIP: Uniswap Module #4518

wants to merge 17 commits into from

Conversation

colin-axner
Copy link
Contributor

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 explorer


For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

x/uniswap/handler.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@fedekunze fedekunze left a 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

x/uniswap/genesis.go Outdated Show resolved Hide resolved
x/uniswap/genesis.go Show resolved Hide resolved
x/uniswap/keeper/expected_keepers.go Outdated Show resolved Hide resolved
x/uniswap/module.go Outdated Show resolved Hide resolved
x/uniswap/module.go Outdated Show resolved Hide resolved
x/uniswap/keeper/keeper.go Outdated Show resolved Hide resolved
x/uniswap/types/msgs.go Outdated Show resolved Hide resolved
x/uniswap/types/msgs.go Outdated Show resolved Hide resolved
x/uniswap/internal/types/msgs.go Outdated Show resolved Hide resolved
x/uniswap/internal/types/msgs.go Outdated Show resolved Hide resolved
x/uniswap/internal/types/errors.go Outdated Show resolved Hide resolved
x/uniswap/handler.go Outdated Show resolved Hide resolved
x/uniswap/handler.go Outdated Show resolved Hide resolved
x/uniswap/handler.go Outdated Show resolved Hide resolved
x/uniswap/internal/keeper/keeper.go Outdated Show resolved Hide resolved
Copy link
Member

@AdityaSripal AdityaSripal left a 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/msgs.go Show resolved Hide resolved
x/uniswap/internal/types/msgs.go Outdated Show resolved Hide resolved
x/uniswap/internal/types/msgs.go Outdated Show resolved Hide resolved
)

// uniswap parameters
// Fee = 1 - (FeeN - FeeD)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, will update

// uniswap parameters
// Fee = 1 - (FeeN - FeeD)
type FeeParams struct {
FeeN sdk.Int `json:"fee_numerator"` // fee numerator
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Collaborator

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

// 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)
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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

return queryBalance(ctx, req, k)
case types.QueryLiquidity:
return queryLiquidity(ctx, req, k)
case types.Parameters:
Copy link
Contributor

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()
}
Copy link
Contributor

@aayushijain23 aayushijain23 Jun 17, 2019

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{}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I was going through 'GetInputPriceandGetOutputPrice` 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.

panic(err)
}
return
}
Copy link
Contributor

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.

k.CreateReservePool(ctx, msg.Denom)
}

nativeLiqudiity, err := k.GetReservePool(ctx, NativeAsset)
Copy link
Contributor

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
Copy link
Contributor

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) != "" {
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 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?

Copy link
Member

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 {
Copy link
Contributor Author

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

@fedekunze
Copy link
Collaborator

cam we update the module based on #4618? 🙏

@fedekunze fedekunze added the WIP label Jun 28, 2019
@colin-axner
Copy link
Contributor Author

closing to switch from fork as base to branch on this repo, see #4644 for future development

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.

5 participants