Skip to content

Commit

Permalink
extract out cross contract interface
Browse files Browse the repository at this point in the history
  • Loading branch information
mconcat committed Feb 7, 2025
1 parent a29e0f9 commit fdbc764
Show file tree
Hide file tree
Showing 17 changed files with 354 additions and 27 deletions.
2 changes: 2 additions & 0 deletions contract/r/gnoswap/common/interfaces.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package common

105 changes: 105 additions & 0 deletions contract/r/gnoswap/communication_entrypoint.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Gnoswap Contract Communication Entrypoints

This document lists the contract-to-contract communication points in the Gnoswap system, showing which contracts call functions of other contracts.

## Contract-to-Contract Calls

### Governance Contract → Multiple Contracts
- Calls functions on various contracts through parameter registry system
- Registry allows execution of parameter changes across protocol
- Each registered contract must implement parameter handlers
- Used during proposal execution phase

### Governance Contract → Common Contract
- Calls `IsHalted` to check system state
- Calls `MustRegistered` to validate token paths

### Governance Contract → Pool Contract
- Calls `SetFeeProtocol` through parameter registry
- Calls `CollectProtocol` through parameter registry

### Governance Contract → Emission Contract
- Calls `MintAndDistributeGns` during proposal operations

### Position Contract → Pool Contract
- Calls `Mint` to add liquidity to a pool
- Calls `Burn` to remove liquidity from a pool
- Calls `Collect` to collect accumulated fees

### Staker Contract → Position Contract
- Calls `SetPositionOperator` to update position operators during staking operations

### Staker Contract → GNFT Contract
- Calls `TransferFrom` to transfer NFT ownership during staking/unstaking
- Calls `MustOwnerOf` to verify token ownership

### Staker Contract → GNS Contract
- Calls `Transfer` to distribute rewards and penalties

### Router Contract → Emission Contract
- Calls `MintAndDistributeGns` during swap operations

### Protocol Fee Contract → Common Contract
- Calls `ListRegisteredTokens` to get list of tokens
- Calls `BalanceOf` to check token balances
- Calls `GetTokenTeller` to get token interfaces
- Calls `AdminOnly` and `GovernanceOnly` for permission checks

### Community Pool Contract → Common Contract
- Calls `IsHalted` to check system state
- Calls `AdminOnly` and `GovernanceOnly` for permission checks
- Calls `GetTokenTeller` to get token interfaces

### Community Pool Contract → Token Contracts
- Calls `Transfer` on token contracts through TokenTeller interface
- Transfers tokens to specified addresses via governance proposals

### Protocol Fee Contract → Token Contracts
- Calls `Transfer` on token contracts through TokenTeller interface
- Distributes fees to DevOps and Governance/Staker addresses

### Launchpad Contract → Common Contract
- Calls `IsRegistered` to validate token paths
- Calls `GetTokenTeller` to get token interfaces
- Calls `AdminOnly` for permission checks

### Launchpad Contract → Emission Contract
- Calls `MintAndDistributeGns` during project operations

### Governance Staker Contract → XGNS Contract
- Calls `Mint` to create governance tokens
- Calls `Burn` to remove governance tokens
- Calls `BalanceOf` to check token balances

### Governance Staker Contract → GNS Contract
- Calls `BalanceOf` to check token balances
- Calls `Transfer` and `TransferFrom` for token operations

### Governance Staker Contract → Common Contract
- Calls `IsHalted` to check system state
- Calls `MustRegistered` to validate token paths
- Calls `GetTokenTeller` to get token interfaces

### Governance Staker Contract → WUGNOT Contract
- Calls `Withdraw` for native token operations

### Governance Staker Contract → Emission Contract
- Calls `MintAndDistributeGns` during reward operations

### Launchpad Contract → GNS Contract
- Calls `GetAvgBlockTimeInMs` for timing calculations
- Calls `TransferFrom` and `Transfer` for token operations

### Router Contract → WUGNOT Contract
- Calls `BalanceOf` to check wrapped token balances
- Interacts with wrap/unwrap functions for native token handling

### Emission Contract → GNS Contract
- Calls `MintGns` to create new GNS tokens
- Calls `Transfer` to distribute tokens to:
- Staker contract
- DevOps address
- Community Pool address
- Governance Staker address
- Calls `GetHalvingBlocksInRange` for emission rate updates
- Calls `GetEmission` to calculate distribution amounts
2 changes: 0 additions & 2 deletions contract/r/gnoswap/gov/governance/api.gno
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"time"

"gno.land/p/demo/json"

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

func createProposalJsonNode(id uint64, proposal ProposalInfo) *json.Node {
Expand Down
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"
)

const (
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
35 changes: 35 additions & 0 deletions contract/r/gnoswap/gov/staker/expected_realms.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package staker

import (
"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,
}
15 changes: 15 additions & 0 deletions contract/r/gnoswap/launchpad/expected_realms.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package launchpad

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

// 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,
}
27 changes: 27 additions & 0 deletions contract/r/gnoswap/position/expected_realms.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package position

import (
"gno.land/r/gnoswap/v1/pool"
u256 "gno.land/p/gnoswap/uint256"
)

// 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,
}
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 @@ -130,10 +130,6 @@ func ClearAccuTransferToGovStaker() {
assertOnlyNotHalted()

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

accuToGovStaker = avl.NewTree()
}

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

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

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

var emission EmissionI = EmissionI{
MintAndDistributeGns: emission.MintAndDistributeGns,
}
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

0 comments on commit fdbc764

Please sign in to comment.