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

Registry based cross contract communication #509

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 0 additions & 1 deletion contract/r/gnoswap/gov/governance/config.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"gno.land/p/demo/ufmt"

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

var (
Expand Down
2 changes: 0 additions & 2 deletions contract/r/gnoswap/gov/governance/execute.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"gno.land/p/demo/avl"
"gno.land/p/demo/ufmt"
"gno.land/r/gnoswap/v1/common"

en "gno.land/r/gnoswap/v1/emission"
)

// Governance can execute multiple messages in a single proposal
Expand Down
86 changes: 86 additions & 0 deletions contract/r/gnoswap/gov/governance/expected_realms.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package governance

import (
"std"

"gno.land/r/gnoswap/v1/emission"
"gno.land/r/gnoswap/v1/community_pool"
"gno.land/r/gnoswap/v1/pool"
"gno.land/r/gnoswap/v1/protocol_fee"
"gno.land/r/gnoswap/v1/router"
"gno.land/r/gnoswap/v1/staker"
)

type EmissionI struct {
MintAndDistributeGns func() uint64
ChangeDistributionPct func(
target01 int,
pct01 uint64,
target02 int,
pct02 uint64,
target03 int,
pct03 uint64,
target04 int,
pct04 uint64,
)
GetDistributedToGovStaker func() uint64
}

var en EmissionI = EmissionI{
MintAndDistributeGns: emission.MintAndDistributeGns,
ChangeDistributionPct: emission.ChangeDistributionPct,
GetDistributedToGovStaker: emission.GetDistributedToGovStaker,
}

type CommunityPoolI struct {
TransferToken func(pkgPath string, to std.Address, amount uint64)
}

var cp CommunityPoolI = CommunityPoolI{
TransferToken: community_pool.TransferToken,
}

type PoolI struct {
SetFeeProtocol func(feeProtocol0 uint8, feeProtocol1 uint8)
SetPoolCreationFee func(poolCreationFee uint64)
SetWithdrawalFee func(withdrawalFee uint64)
}

var pl PoolI = PoolI{
SetFeeProtocol: pool.SetFeeProtocol,
SetPoolCreationFee: pool.SetPoolCreationFee,
SetWithdrawalFee: pool.SetWithdrawalFee,
}

type ProtocolFeeI struct {
SetDevOpsPct func(devOpsPct uint64)
}

var pf ProtocolFeeI = ProtocolFeeI{
SetDevOpsPct: protocol_fee.SetDevOpsPct,
}

type RouterI struct {
SetSwapFee func(swapFee uint64)
}

var rr RouterI = RouterI{
SetSwapFee: router.SetSwapFee,
}

type StakerI struct {
SetDepositGnsAmount func(depositGnsAmount uint64)
SetPoolTier func(poolId string, poolTier uint64)
ChangePoolTier func(poolId string, poolTier uint64)
RemovePoolTier func(poolId string)
SetUnStakingFee func(unstakingFee uint64)
SetWarmUp func(percent int64, block int64)
}

var sr StakerI = StakerI{
SetDepositGnsAmount: staker.SetDepositGnsAmount,
SetPoolTier: staker.SetPoolTier,
ChangePoolTier: staker.ChangePoolTier,
RemovePoolTier: staker.RemovePoolTier,
SetUnStakingFee: staker.SetUnStakingFee,
}
7 changes: 0 additions & 7 deletions contract/r/gnoswap/gov/governance/fn_registry.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ import (
"gno.land/p/gnoswap/consts"
"gno.land/r/gnoswap/v1/gns"

cp "gno.land/r/gnoswap/v1/community_pool"
en "gno.land/r/gnoswap/v1/emission"
pl "gno.land/r/gnoswap/v1/pool"
pf "gno.land/r/gnoswap/v1/protocol_fee"
rr "gno.land/r/gnoswap/v1/router"
sr "gno.land/r/gnoswap/v1/staker"

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

Expand Down
1 change: 0 additions & 1 deletion contract/r/gnoswap/gov/governance/proposal.gno
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"gno.land/r/gnoswap/v1/common"
"gno.land/r/gnoswap/v1/gov/xgns"

en "gno.land/r/gnoswap/v1/emission"
gs "gno.land/r/gnoswap/v1/gov/staker"
)

Expand Down
2 changes: 0 additions & 2 deletions contract/r/gnoswap/gov/governance/vote.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (

"gno.land/p/demo/avl"

en "gno.land/r/gnoswap/v1/emission"

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

"gno.land/p/demo/ufmt"
Expand Down
55 changes: 55 additions & 0 deletions contract/r/gnoswap/gov/staker/expected_realms.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package staker

import (
"std"

"gno.land/p/demo/avl"
"gno.land/r/gnoswap/v1/emission"
"gno.land/r/gnoswap/v1/protocol_fee"
)

// EmissionI defines the interface for emission realm interactions
type EmissionI struct {
MintAndDistributeGns func() uint64
GetDistributedToGovStaker func() uint64
ClearDistributedToGovStaker func()
}

// ProtocolFeeI defines the interface for protocol_fee realm interactions
type ProtocolFeeI struct {
DistributeProtocolFee func()
GetAccuTransferToGovStaker func() *avl.Tree
ClearAccuTransferToGovStaker func()
}

// en is the emission interface instance
var en EmissionI = EmissionI{
MintAndDistributeGns: emission.MintAndDistributeGns,
GetDistributedToGovStaker: emission.GetDistributedToGovStaker,
ClearDistributedToGovStaker: emission.ClearDistributedToGovStaker,
}

// pf is the protocol_fee interface instance
var pf ProtocolFeeI = ProtocolFeeI{
DistributeProtocolFee: protocol_fee.DistributeProtocolFee,
GetAccuTransferToGovStaker: protocol_fee.GetAccuTransferToGovStaker,
ClearAccuTransferToGovStaker: protocol_fee.ClearAccuTransferToGovStaker,
}

// SetEmissionRealm replaces the emission interface implementation
func SetEmissionRealm(newEn EmissionI) {
// caller := std.PrevRealm().Addr()
// if !governance.IsPermittedSetter(caller) {
// panic("caller not permitted to set realm implementation")
// }
en = newEn
}

// SetProtocolFeeRealm replaces the protocol fee interface implementation
func SetProtocolFeeRealm(newPf ProtocolFeeI) {
// caller := std.PrevRealm().Addr()
// if !governance.IsPermittedSetter(caller) {
// panic("caller not permitted to set realm implementation")
// }
pf = newPf
}
27 changes: 27 additions & 0 deletions contract/r/gnoswap/launchpad/expected_realms.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package launchpad

import (
"std"

"gno.land/r/gnoswap/v1/emission"
"gno.land/r/gnoswap/v1/gov/governance"
)

// EmissionI defines the interface for emission realm interactions
type EmissionI struct {
MintAndDistributeGns func() uint64
}

// en is the emission interface instance
var en EmissionI = EmissionI{
MintAndDistributeGns: emission.MintAndDistributeGns,
}

// SetEmissionRealm replaces the emission interface implementation
func SetEmissionRealm(newEn EmissionI) {
caller := std.PrevRealm().Addr()
if !governance.IsPermittedSetter(caller) {
panic("caller not permitted to set realm implementation")
}
en = newEn
}
37 changes: 37 additions & 0 deletions contract/r/gnoswap/position/expected_realms.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package position

import (
"std"

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

// PoolI defines the interface for pool operations
type PoolI struct {
GetPoolFromPoolPath func(poolPath string) *pool.Pool
PoolGetSlot0SqrtPriceX96 func(poolPath string) string
PoolGetSlot0Tick func(poolPath string) int32
PoolGetFeeGrowthGlobal0X128 func(poolPath string) string
PoolGetFeeGrowthGlobal1X128 func(poolPath string) string
PoolGetTickFeeGrowthOutside0X128 func(poolPath string, tick int32) string
PoolGetTickFeeGrowthOutside1X128 func(poolPath string, tick int32) string
}

var pl PoolI = PoolI{
GetPoolFromPoolPath: pool.GetPoolFromPoolPath,
PoolGetSlot0SqrtPriceX96: pool.PoolGetSlot0SqrtPriceX96,
PoolGetSlot0Tick: pool.PoolGetSlot0Tick,
PoolGetFeeGrowthGlobal0X128: pool.PoolGetFeeGrowthGlobal0X128,
PoolGetFeeGrowthGlobal1X128: pool.PoolGetFeeGrowthGlobal1X128,
PoolGetTickFeeGrowthOutside0X128: pool.PoolGetTickFeeGrowthOutside0X128,
PoolGetTickFeeGrowthOutside1X128: pool.PoolGetTickFeeGrowthOutside1X128,
}

// SetPoolRealm replaces the pool interface implementation
func SetPoolRealm(newPl PoolI) {
// caller := std.PrevRealm().Addr()
// if !governance.IsPermittedSetter(caller) {
// panic("caller not permitted to set realm implementation")
// }
pl = newPl
}
4 changes: 0 additions & 4 deletions contract/r/gnoswap/protocol_fee/protocol_fee.gno
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,6 @@ func ClearAccuTransferToGovStaker() {
assertOnlyNotHalted()

caller := std.PrevRealm().Addr()
if err := common.GovStakerOnly(caller); err != nil {
panic(err)
}

accuToGovStaker = avl.NewTree()
}

Expand Down
25 changes: 25 additions & 0 deletions contract/r/gnoswap/router/expected_realms.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package router

import (
"std"

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

// EmissionI defines the interface for emission operations
type EmissionI struct {
MintAndDistributeGns func() uint64
}

var en EmissionI = EmissionI{
MintAndDistributeGns: emission.MintAndDistributeGns,
}

// SetEmissionRealm replaces the emission interface implementation
func SetEmissionRealm(newEmission EmissionI) {
// caller := std.PrevRealm().Addr()
// if !governance.IsPermittedSetter(caller) {
// panic("caller not permitted to set realm implementation")
// }
en = newEmission
}
5 changes: 2 additions & 3 deletions contract/r/gnoswap/router/router.gno
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import (

"gno.land/p/gnoswap/consts"
"gno.land/r/demo/wugnot"

en "gno.land/r/gnoswap/v1/emission"
"gno.land/r/gnoswap/v1/emission"
)

// commonSwapSetup Common validation and setup logic extracted from SwapRoute
func commonSwapSetup() {
assertOnlyNotHalted()
assertDirectCallOnly()

en.MintAndDistributeGns()
emission.MintAndDistributeGns()
}

// handleSingleSwap handles a single swap operation.
Expand Down
Loading