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

fix: when uncrossing after auction refine approximately expanded AMMs… #11736

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions core/execution/amm/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,32 +970,30 @@ func (e *Engine) UpdateSubAccountBalance(

// OrderbookShape expands all registered AMM's into orders between the given prices. If `ammParty` is supplied then just the pool
// with that party id is expanded.
func (e *Engine) OrderbookShape(st, nd *num.Uint, ammParty *string) ([]*types.Order, []*types.Order) {
func (e *Engine) OrderbookShape(st, nd *num.Uint, ammParty *string) []*types.OrderbookShapeResult {
if ammParty == nil {
// no party give, expand all registered
buys, sells := []*types.Order{}, []*types.Order{}
res := make([]*types.OrderbookShapeResult, 0, len(e.poolsCpy))
for _, p := range e.poolsCpy {
b, s := p.OrderbookShape(st, nd, e.idgen)
buys = append(buys, b...)
sells = append(sells, s...)
res = append(res, p.OrderbookShape(st, nd, e.idgen))
}
return buys, sells
return res
}

// asked to expand just one AMM, lets find it, first amm-party -> owning party
owner, ok := e.ammParties[*ammParty]
if !ok {
return nil, nil
return nil
}

// now owning party -> pool
p, ok := e.pools[owner]
if !ok {
return nil, nil
return nil
}

// expand it
return p.OrderbookShape(st, nd, e.idgen)
return []*types.OrderbookShapeResult{p.OrderbookShape(st, nd, e.idgen)}
}

func (e *Engine) GetAMMPoolsBySubAccount() map[string]common.AMMPool {
Expand Down
21 changes: 14 additions & 7 deletions core/execution/amm/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ func (sm *shapeMaker) adjustRegion() bool {
return true
}

func (sm *shapeMaker) makeShape() ([]*types.Order, []*types.Order) {
func (sm *shapeMaker) makeShape() {
if !sm.adjustRegion() {
// if there is no overlap between the input region and the AMM's bounds then there are no orders
return sm.buys, sm.sells
return
}

// create accurate orders at the boundary of the adjusted region (even if we are going to make approximate internal steps)
Expand Down Expand Up @@ -481,15 +481,22 @@ func (sm *shapeMaker) makeShape() ([]*types.Order, []*types.Order) {
logging.Int("sells", len(sm.sells)),
)
}
return sm.buys, sm.sells
}

func (p *Pool) OrderbookShape(from, to *num.Uint, idgen *idgeneration.IDGenerator) ([]*types.Order, []*types.Order) {
return newShapeMaker(
func (p *Pool) OrderbookShape(from, to *num.Uint, idgen *idgeneration.IDGenerator) *types.OrderbookShapeResult {
sm := newShapeMaker(
p.log,
p,
from,
to,
idgen).
makeShape()
idgen)

sm.makeShape()

return &types.OrderbookShapeResult{
AmmParty: sm.pool.AMMParty,
Buys: sm.buys,
Sells: sm.sells,
Approx: sm.approx,
}
}
Loading
Loading