Search Apps Documentation Source Content File Folder Download Copy Actions Download

instance.gno

1.56 Kb · 70 lines
 1package v1
 2
 3import (
 4	"gno.land/p/gnoswap/deps/grc721"
 5	"gno.land/r/gnoswap/gnft"
 6	"gno.land/r/gnoswap/position"
 7)
 8
 9type positionV1 struct {
10	store       position.IPositionStore
11	nftAccessor NFTAccessor
12}
13
14func NewPositionV1(positionStore position.IPositionStore, accessor NFTAccessor) position.IPosition {
15	return &positionV1{
16		store:       positionStore,
17		nftAccessor: accessor,
18	}
19}
20
21type NFTAccessor interface {
22	Approve(_ int, rlm realm, approved address, tid grc721.TokenID) error
23	Mint(_ int, rlm realm, to address, tid grc721.TokenID) grc721.TokenID
24	Burn(_ int, rlm realm, tid grc721.TokenID)
25	TotalSupply() int64
26	Exists(tid grc721.TokenID) bool
27	OwnerOf(tid grc721.TokenID) (address, error)
28}
29
30type gnftAccessor struct{}
31
32func (n *gnftAccessor) Approve(_ int, rlm realm, approved address, tid grc721.TokenID) error {
33	if !rlm.IsCurrent() {
34		return errSpoofedRealm
35	}
36
37	return gnft.Approve(cross(rlm), approved, tid)
38}
39
40func (n *gnftAccessor) Mint(_ int, rlm realm, to address, tid grc721.TokenID) grc721.TokenID {
41	if !rlm.IsCurrent() {
42		panic(errSpoofedRealm)
43	}
44
45	return gnft.Mint(cross(rlm), to, tid)
46}
47
48func (n *gnftAccessor) Burn(_ int, rlm realm, tid grc721.TokenID) {
49	if !rlm.IsCurrent() {
50		panic(errSpoofedRealm)
51	}
52
53	gnft.Burn(cross(rlm), tid)
54}
55
56func (n *gnftAccessor) TotalSupply() int64 {
57	return gnft.TotalSupply()
58}
59
60func (n *gnftAccessor) Exists(tid grc721.TokenID) bool {
61	return gnft.Exists(tid)
62}
63
64func (n *gnftAccessor) OwnerOf(tid grc721.TokenID) (address, error) {
65	return gnft.OwnerOf(tid)
66}
67
68func newGNFTAccessor() NFTAccessor {
69	return &gnftAccessor{}
70}