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

feat: use std.Address (rather then users.AddressOrName) #481

Merged
merged 2 commits into from
Jan 22, 2025
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
10 changes: 5 additions & 5 deletions contract/r/gnoswap/community_pool/community_pool_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestTransferTokenByAdmin(t *testing.T) {
name: "panic if not enough balance",
setup: func() {
std.TestSetRealm(adminRealm)
gns.Transfer(common.AddrToUser(consts.COMMUNITY_POOL_ADDR), 10_000)
gns.Transfer(consts.COMMUNITY_POOL_ADDR, 10_000)
},
caller: adminRealm,
tokenPath: consts.GNS_PATH,
Expand Down Expand Up @@ -95,9 +95,9 @@ func TestTransferTokenByAdmin(t *testing.T) {
TransferTokenByAdmin(tt.tokenPath, tt.to, tt.amount)
})
} else {
receiverOldBalance := gns.BalanceOf(common.AddrToUser(tt.to))
receiverOldBalance := gns.BalanceOf(tt.to)
TransferTokenByAdmin(tt.tokenPath, tt.to, tt.amount)
receiverNewBalance := gns.BalanceOf(common.AddrToUser(tt.to))
receiverNewBalance := gns.BalanceOf(tt.to)
uassert.Equal(t, receiverNewBalance-receiverOldBalance, tt.amount)
}
})
Expand Down Expand Up @@ -175,9 +175,9 @@ func TestTransferToken(t *testing.T) {
TransferToken(tt.tokenPath, tt.to, tt.amount)
})
} else {
receiverOldBalance := gns.BalanceOf(common.AddrToUser(tt.to))
receiverOldBalance := gns.BalanceOf(tt.to)
TransferToken(tt.tokenPath, tt.to, tt.amount)
receiverNewBalance := gns.BalanceOf(common.AddrToUser(tt.to))
receiverNewBalance := gns.BalanceOf(tt.to)
uassert.Equal(t, receiverNewBalance-receiverOldBalance, tt.amount)
}
})
Expand Down
143 changes: 0 additions & 143 deletions contract/r/gnoswap/community_pool/tests/init_token_register_test.gno

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion contract/r/gnoswap/emission/_helper_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ func resetObject(t *testing.T) {
func gnsBalance(t *testing.T, addr std.Address) uint64 {
t.Helper()

return gns.BalanceOf(a2u(addr))
return gns.BalanceOf(addr)
}
14 changes: 7 additions & 7 deletions contract/r/gnoswap/emission/distribution.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"std"
"strconv"

"gno.land/r/gnoswap/v1/consts"
"gno.land/r/gnoswap/v1/gns"

"gno.land/p/demo/avl"
"gno.land/p/demo/ufmt"

"gno.land/r/gnoswap/v1/consts"
"gno.land/r/gnoswap/v1/gns"
)

const (
Expand Down Expand Up @@ -176,22 +176,22 @@ func calculateAmount(amount, bptPct uint64) uint64 {
func transferToTarget(target int, amount uint64) {
switch target {
case LIQUIDITY_STAKER:
gns.Transfer(a2u(consts.STAKER_ADDR), amount)
gns.Transfer(consts.STAKER_ADDR, amount)
distributedToStaker += amount
accuDistributedToStaker += amount

case DEVOPS:
gns.Transfer(a2u(consts.DEV_OPS), amount)
gns.Transfer(consts.DEV_OPS, amount)
distributedToDevOps += amount
accuDistributedToDevOps += amount

case COMMUNITY_POOL:
gns.Transfer(a2u(consts.COMMUNITY_POOL_ADDR), amount)
gns.Transfer(consts.COMMUNITY_POOL_ADDR, amount)
distributedToCommunityPool += amount
accuDistributedToCommunityPool += amount

case GOV_STAKER:
gns.Transfer(a2u(consts.GOV_STAKER_ADDR), amount)
gns.Transfer(consts.GOV_STAKER_ADDR, amount)
distributedToGovStaker += amount
accuDistributedToGovStaker += amount

Expand Down
2 changes: 1 addition & 1 deletion contract/r/gnoswap/emission/distribution_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func TestTransferToTarget(t *testing.T) {
target: LIQUIDITY_STAKER,
setup: func() {
std.TestSetRealm(adminRealm)
gns.Transfer(a2u(consts.EMISSION_ADDR), 100000) // give enough balance for emission
gns.Transfer(consts.EMISSION_ADDR, 100000) // give enough balance for emission
},
amount: 100,
verify: func() {
Expand Down
2 changes: 1 addition & 1 deletion contract/r/gnoswap/emission/emission.gno
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func MintAndDistributeGns() uint64 {
return 0
}
// Mint new tokens and add any leftover amounts from previous distribution
mintedEmissionRewardAmount := gns.MintGns(a2u(consts.EMISSION_ADDR))
mintedEmissionRewardAmount := gns.MintGns(consts.EMISSION_ADDR)
if hasLeftGNSAmount() {
mintedEmissionRewardAmount += GetLeftGNSAmount()
setLeftGNSAmount(0)
Expand Down
6 changes: 0 additions & 6 deletions contract/r/gnoswap/emission/utils.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,12 @@ import (
"strconv"

"gno.land/p/demo/ufmt"
pusers "gno.land/p/demo/users"

"gno.land/r/gnoswap/v1/common"
)

const MAX_BPS_PCT uint64 = 10000

// a2u converts std.Address to pusers.AddressOrName.
func a2u(addr std.Address) pusers.AddressOrName {
return pusers.AddressOrName(addr)
}

// getPrevRealm returns object of the previous realm.
func getPrevRealm() std.Realm {
return std.PrevRealm()
Expand Down
13 changes: 0 additions & 13 deletions contract/r/gnoswap/gnft/utils.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"gno.land/p/demo/grc/grc721"
"gno.land/p/demo/ufmt"
pusers "gno.land/p/demo/users"
)

// getPrevAsString returns the address and package path of the previous realm.
Expand All @@ -19,18 +18,6 @@ func getPrevAddr() std.Address {
return std.PrevRealm().Addr()
}

// a2u converts std.Address to pusers.AddressOrName.
// pusers is a package that contains the user-related functions.
//
// Input:
// - addr: the address to convert
//
// Output:
// - pusers.AddressOrName: the converted address
func a2u(addr std.Address) pusers.AddressOrName {
return pusers.AddressOrName(addr)
}

// tid converts uint64 to grc721.TokenID.
//
// Input:
Expand Down
Loading
Loading