Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion contract/p/gnoswap/store/doc.gno
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
// - CastToBool: Casts to bool with error handling
// - CastToString: Casts to string with error handling
// - CastToAddress: Casts to address with error handling
// - CastToTree: Casts to *avl.Tree with error handling
// - CastToTree: Casts to *bptree.BPTree with error handling
//
// These utilities are used internally by typed getters but can also be used directly.
//
Expand Down
8 changes: 4 additions & 4 deletions contract/p/gnoswap/store/kv_store.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package store
import (
"chain/runtime"

avl "gno.land/p/nt/avl/v0"
bptree "gno.land/p/nt/bptree/v0"
)

// kvStore represents a domain-specific key-value storage
Expand Down Expand Up @@ -116,9 +116,9 @@ func (k *kvStore) GetAddress(key string) (address, error) {
return castToAddress(result)
}

// GetTree retrieves a value by key and casts it to *avl.Tree
// Returns ErrFailedCast if the value is not of type *avl.Tree
func (k *kvStore) GetTree(key string) (*avl.Tree, error) {
// GetTree retrieves a value by key and casts it to *bptree.BPTree
// Returns ErrFailedCast if the value is not of type *bptree.BPTree
func (k *kvStore) GetTree(key string) (*bptree.BPTree, error) {
result, err := k.Get(key)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions contract/p/gnoswap/store/kv_store_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"
"testing"

avl "gno.land/p/nt/avl/v0"
bptree "gno.land/p/nt/bptree/v0"
testutils "gno.land/p/nt/testutils/v0"
uassert "gno.land/p/nt/uassert/v0"
)
Expand Down Expand Up @@ -681,7 +681,7 @@ func TestAllTypedGetters_Success(t *testing.T) {
uassert.NoError(t, err)
err = store.Set("address_key", domainAddr)
uassert.NoError(t, err)
tree := avl.NewTree()
tree := bptree.NewBPTree32()
err = store.Set("tree_key", tree)
uassert.NoError(t, err)

Expand Down
4 changes: 2 additions & 2 deletions contract/p/gnoswap/store/types.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package store

import avl "gno.land/p/nt/avl/v0"
import bptree "gno.land/p/nt/bptree/v0"

type Permission uint8

Expand Down Expand Up @@ -40,7 +40,7 @@ type KVStore interface {
GetAddress(key string) (address, error)

// GetTree retrieves a tree value by key
GetTree(key string) (*avl.Tree, error)
GetTree(key string) (*bptree.BPTree, error)

// Set stores a value with the given key
Set(key string, value any) error
Expand Down
12 changes: 6 additions & 6 deletions contract/p/gnoswap/store/utils.gno
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package store

import (
avl "gno.land/p/nt/avl/v0"
bptree "gno.land/p/nt/bptree/v0"
ufmt "gno.land/p/nt/ufmt/v0"
)

Expand Down Expand Up @@ -49,12 +49,12 @@ func castToString(result any) (string, error) {
return v, nil
}

// castToTree safely casts an any value to *avl.Tree
// Returns ErrFailedCast if the value is not of type *avl.Tree
func castToTree(result any) (*avl.Tree, error) {
tree, ok := result.(*avl.Tree)
// castToTree safely casts an any value to *bptree.BPTree
// Returns ErrFailedCast if the value is not of type *bptree.BPTree
func castToTree(result any) (*bptree.BPTree, error) {
tree, ok := result.(*bptree.BPTree)
if !ok {
return nil, ufmt.Errorf("%s: %s", ErrFailedCast.Error(), ufmt.Sprintf("cast %T to *avl.Tree", result))
return nil, ufmt.Errorf("%s: %s", ErrFailedCast.Error(), ufmt.Sprintf("cast %T to *bptree.BPTree", result))
}

return tree, nil
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Expand Down
4 changes: 2 additions & 2 deletions contract/p/gnoswap/store/utils_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package store
import (
"testing"

avl "gno.land/p/nt/avl/v0"
bptree "gno.land/p/nt/bptree/v0"
testutils "gno.land/p/nt/testutils/v0"
uassert "gno.land/p/nt/uassert/v0"
)
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestcastToTree(t *testing.T) {
{
name: "Success",
verifyFn: func(t *testing.T) {
tree := avl.NewTree()
tree := bptree.NewBPTree32()
var value any = tree
result, err := castToTree(value)
uassert.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions contract/p/gnoswap/version_manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ manager.ChangeImplementation("gno.land/r/gnoswap/protocol_fee/v1_hotfix")
- Storage access controlled via realm context (`runtime.CurrentRealm()`)
- No data migration required - all versions share the same storage
- Type assertions required when retrieving current implementation
- AVL tree used for efficient initializer storage and lookup
- B+Tree used for efficient initializer storage and lookup

## Limitations

Expand All @@ -245,4 +245,4 @@ manager.ChangeImplementation("gno.land/r/gnoswap/protocol_fee/v1_hotfix")
## Related Packages

- `gno.land/p/gnoswap/store`: KVStore with permission-based access control
- `gno.land/p/nt/avl`: AVL tree for initializer storage
- `gno.land/p/nt/bptree/v0`: B+Tree for initializer storage
4 changes: 2 additions & 2 deletions contract/p/gnoswap/version_manager/doc.gno
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@
// ## Related Packages
//
// - gno.land/p/gnoswap/store: Provides KVStore with permission-based access control
// - gno.land/p/nt/avl: AVL tree used for efficient initializer storage and lookup
// - gno.land/p/nt/avl/rotree: Read-only tree wrapper for safe external access
// - gno.land/p/nt/bptree: B+ tree used for efficient initializer storage and lookup
// - gno.land/p/nt/bptree/rotree: Read-only tree wrapper for safe external access
//
// Package version_manager is intended for use in Gno smart contracts requiring
// dynamic, upgradeable implementations with zero-downtime version switching.
Expand Down
2 changes: 1 addition & 1 deletion contract/p/gnoswap/version_manager/types.gno
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package version_manager

import "gno.land/p/nt/avl/v0/rotree"
import "gno.land/p/nt/bptree/v0/rotree"

// VersionManager defines the interface for managing multiple versioned implementations of a domain.
// It enables the Strategy Pattern at the package level, allowing runtime switching between
Expand Down
12 changes: 6 additions & 6 deletions contract/p/gnoswap/version_manager/version_manager.gno
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"strings"

"gno.land/p/gnoswap/store"
avl "gno.land/p/nt/avl/v0"
rotree "gno.land/p/nt/avl/v0/rotree"
bptree "gno.land/p/nt/bptree/v0"
rotree "gno.land/p/nt/bptree/v0/rotree"
ufmt "gno.land/p/nt/ufmt/v0"
)

Expand All @@ -33,7 +33,7 @@ import (
type versionManager struct {
// initializers stores registered initializer functions keyed by package path
// Each initializer bootstraps a specific version's implementation
initializers *avl.Tree
initializers *bptree.BPTree

// domainKVStore is the shared storage layer accessible by all versions
// The domain (proxy) realm is the owner and has write permission
Expand Down Expand Up @@ -165,7 +165,7 @@ func (vm *versionManager) GetDomainPath() string {
return vm.domainPath
}

// GetInitializers returns the AVL tree containing all registered initializer functions.
// GetInitializers returns the B+Tree containing all registered initializer functions.
// Keys are package paths, values are initializer functions.
// Useful for inspecting which versions are available.
func (vm *versionManager) GetInitializers() *rotree.ReadOnlyTree {
Expand Down Expand Up @@ -234,14 +234,14 @@ func NewVersionManager(
domainPath: domainPath,
domainKVStore: kvStore,
initializeDomainStoreFn: initializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
currentPackagePath: "",
currentImplementation: nil,
}
}

// makeInitializerSafe creates a safe copy of an initializer function for read-only tree access.
// This is used by GetInitializers to wrap the internal AVL tree in a read-only view,
// This is used by GetInitializers to wrap the internal B+Tree in a read-only view,
// preventing external modification of registered initializers.
func makeInitializerSafe(data any) any {
fn, ok := data.(func(store any) any)
Expand Down
24 changes: 12 additions & 12 deletions contract/p/gnoswap/version_manager/version_manager_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"gno.land/p/gnoswap/store"
avl "gno.land/p/nt/avl/v0"
bptree "gno.land/p/nt/bptree/v0"
uassert "gno.land/p/nt/uassert/v0"
ufmt "gno.land/p/nt/ufmt/v0"
)
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestChangeImplementation_Errors(t *testing.T) {
domainPath: "gno.land/r/gnoswap/protocol_fee",
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
}
return vm, "gno.land/r/gnoswap/protocol_fee/v999"
},
Expand All @@ -203,7 +203,7 @@ func TestChangeImplementation_Errors(t *testing.T) {
domainPath: "gno.land/r/gnoswap/pool",
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
}
return vm, ""
},
Expand All @@ -218,7 +218,7 @@ func TestChangeImplementation_Errors(t *testing.T) {
domainPath: "gno.land/r/gnoswap/protocol_fee",
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
}
vm.initializers.Set("gno.land/r/gnoswap/protocol_fee/v1", "not a function")
return vm, "gno.land/r/gnoswap/protocol_fee/v1"
Expand All @@ -233,7 +233,7 @@ func TestChangeImplementation_Errors(t *testing.T) {
domainPath: "gno.land/r/gnoswap/pool",
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
}
vm.initializers.Set("gno.land/r/gnoswap/pool/v1", 42)
return vm, "gno.land/r/gnoswap/pool/v1"
Expand All @@ -248,7 +248,7 @@ func TestChangeImplementation_Errors(t *testing.T) {
domainPath: "gno.land/r/gnoswap/position",
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
}
vm.initializers.Set("gno.land/r/gnoswap/position/v1", nil)
return vm, "gno.land/r/gnoswap/position/v1"
Expand Down Expand Up @@ -425,7 +425,7 @@ func TestChangeImplementation_Success(t *testing.T) {
domainPath: tt.domainPath,
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
currentPackagePath: "",
currentImplementation: nil,
}
Expand Down Expand Up @@ -459,7 +459,7 @@ func TestGetInitializers(t *testing.T) {
domainPath: "gno.land/r/gnoswap/protocol_fee",
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
}

vm.initializers.Set("gno.land/r/gnoswap/protocol_fee/v1", mockInitializer("v1"))
Expand All @@ -483,7 +483,7 @@ func TestGetInitializers(t *testing.T) {
domainPath: "gno.land/r/gnoswap/pool",
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
}

versions := []string{"v1", "v2", "v3"}
Expand Down Expand Up @@ -512,7 +512,7 @@ func TestGetInitializers(t *testing.T) {
domainPath: "gno.land/r/gnoswap/position",
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
}

initializers := vm.GetInitializers()
Expand Down Expand Up @@ -665,7 +665,7 @@ func TestIsContainDomainPath(t *testing.T) {
domainPath: tt.domainPath,
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
}

result := vm.isContainDomainPath(tt.testPath)
Expand Down Expand Up @@ -728,7 +728,7 @@ func TestChangeImplementation_StateConsistency(t *testing.T) {
domainPath: tt.domainPath,
domainKVStore: kvStore,
initializeDomainStoreFn: mockInitializeDomainStoreFn,
initializers: avl.NewTree(),
initializers: bptree.NewBPTree32(),
currentPackagePath: "",
currentImplementation: nil,
}
Expand Down
2 changes: 1 addition & 1 deletion contract/r/gnoswap/emission/distribution.gno
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func ClearDistributedToGovStaker(cur realm) {
}

// setDistributionBpsPct changes percentage of each target for how much GNS it will get by emission.
// Creates new AVL tree if nil.
// Creates new map if nil.
func setDistributionBpsPct(target int, pct int64) {
if distributionBpsPct == nil {
distributionBpsPct = make(map[int]int64)
Expand Down
2 changes: 1 addition & 1 deletion contract/r/gnoswap/gnft/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ gnft.Burn(cur, tokenId)
### State Variables

- `nft *grc721.AdminToken`: GRC721 token instance
- `tokenURIs avl.Tree`: TokenID → parameter string mapping
- `tokenURIs tree`: TokenID → parameter string mapping

### Access Control

Expand Down
4 changes: 2 additions & 2 deletions contract/r/gnoswap/gnft/gnft_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -799,13 +799,13 @@ func TestBurn(t *testing.T) {
} else {
Burn(cross, tid(tt.tokenIdToBurn))

// Verify complete AVL tree cleanup after burn
// Verify complete B+Tree cleanup after burn
// 1. OwnerOf should return error for burned token
_, err := OwnerOf(tid(tt.tokenIdToBurn))
uassert.Error(t, err)
uassert.Equal(t, errInvalidTokenId, err.Error())

// 2. Exists should return false (token completely removed from AVL tree)
// 2. Exists should return false (token completely removed from B+Tree)
exists := Exists(tid(tt.tokenIdToBurn))
uassert.False(t, exists)

Expand Down
Loading
Loading