Search Apps Documentation Source Content File Folder Download Copy Actions Download

manager.gno

1.42 Kb ยท 60 lines
 1package v1
 2
 3import (
 4	"gno.land/p/nt/ufmt"
 5	"gno.land/r/gnoswap/position"
 6)
 7
 8// GetNextId is the next position ID to be minted
 9func (p *positionV1) getNextId() uint64 {
10	return p.store.GetPositionNextID()
11}
12
13// incrementNextId increments the next position ID to be minted
14func (p *positionV1) incrementNextId() error {
15	return p.store.SetPositionNextID(p.getNextId() + 1)
16}
17
18// createNewPosition creates a new position with the given position data.
19func (p *positionV1) createNewPosition(id uint64, pos position.Position) uint64 {
20	if p.ExistPosition(id) {
21		panic(newErrorWithDetail(
22			errPositionExist,
23			ufmt.Sprintf("positionId(%d)", id),
24		))
25	}
26
27	err := p.setPosition(id, pos)
28	if err != nil {
29		panic(err)
30	}
31
32	err = p.incrementNextId()
33	if err != nil {
34		panic(err)
35	}
36
37	return id
38}
39
40// setPosition sets a position for a given position ID.
41// Returns false if position is newly created, true if position already existed and was updated.
42func (p *positionV1) setPosition(id uint64, pos position.Position) error {
43	return p.store.SetPosition(id, pos)
44}
45
46// mustUpdatePosition updates a position for a given position ID.
47func (p *positionV1) mustUpdatePosition(id uint64, pos position.Position) {
48	err := p.setPosition(id, pos)
49	if err != nil {
50		panic(err)
51	}
52}
53
54// removePosition removes a position for a given position ID
55func (p *positionV1) removePosition(id uint64) {
56	err := p.store.RemovePosition(id)
57	if err != nil {
58		panic(err)
59	}
60}