launchpad_project_deposits.gno
2.37 Kb · 76 lines
1package staker
2
3import (
4 bptree "gno.land/p/nt/bptree/v0"
5)
6
7// LaunchpadProjectDeposits manages deposit amounts for launchpad projects.
8// It tracks the total staked amount for each project identified by owner address.
9type LaunchpadProjectDeposits struct {
10 // deposits maps owner address to deposit amount
11 deposits *bptree.BPTree // string -> int64
12}
13
14// NewLaunchpadProjectDeposits creates an empty owner-to-deposit tree.
15//
16// Returns:
17// - *LaunchpadProjectDeposits: deposit manager initialized with an empty tree.
18func NewLaunchpadProjectDeposits() *LaunchpadProjectDeposits {
19 return &LaunchpadProjectDeposits{
20 deposits: bptree.NewBPTreeN(16),
21 }
22}
23
24// GetDeposits returns the owner-to-deposit tree managed by this instance.
25//
26// Returns:
27// - *bptree.BPTree: tree keyed by owner address string and storing int64 amounts.
28func (lpd *LaunchpadProjectDeposits) GetDeposits() *bptree.BPTree {
29 return lpd.deposits
30}
31
32// SetDeposits replaces the owner-to-deposit tree.
33//
34// Parameters:
35// - deposits: tree keyed by owner address string and storing int64 amounts.
36func (lpd *LaunchpadProjectDeposits) SetDeposits(deposits *bptree.BPTree) {
37 lpd.deposits = deposits
38}
39
40// GetDeposit looks up a project's deposit by owner address.
41//
42// Parameters:
43// - ownerAddress: owner address string used as the deposit key.
44//
45// Returns:
46// - int64: stored deposit amount in the smallest token unit, or zero when absent.
47// - bool: true when an int64 deposit is stored for the owner.
48func (lpd *LaunchpadProjectDeposits) GetDeposit(ownerAddress string) (int64, bool) {
49 deposit := lpd.deposits.Get(ownerAddress)
50 if deposit == nil {
51 return 0, false
52 }
53 amount, ok := deposit.(int64)
54 return amount, ok
55}
56
57// SetDeposit stores or replaces an owner's deposit amount.
58//
59// Parameters:
60// - ownerAddress: owner address string used as the deposit key.
61// - amount: deposit amount in the smallest token unit.
62func (lpd *LaunchpadProjectDeposits) SetDeposit(ownerAddress string, amount int64) {
63 lpd.deposits.Set(ownerAddress, amount)
64}
65
66// RemoveDeposit removes an owner's deposit entry.
67//
68// Parameters:
69// - ownerAddress: owner address string whose deposit entry should be removed.
70//
71// Returns:
72// - bool: true when an entry was removed; false when no entry existed.
73func (lpd *LaunchpadProjectDeposits) RemoveDeposit(ownerAddress string) bool {
74 _, ok := lpd.deposits.Remove(ownerAddress)
75 return ok
76}