diff --git a/internal/graphql/resolvers/defi.go b/internal/graphql/resolvers/defi.go index ae4f6154..031e965e 100644 --- a/internal/graphql/resolvers/defi.go +++ b/internal/graphql/resolvers/defi.go @@ -71,12 +71,6 @@ func (dt *DefiToken) TotalSupply() (hexutil.Big, error) { return dt.repo.Erc20TotalSupply(&dt.Address) } -// DefiConfiguration resolves the current DeFi contract settings. -func (rs *rootResolver) DefiConfiguration() (*types.DefiSettings, error) { - // pass the call to repository - return rs.repo.DefiConfiguration() -} - // ErcTokenBalance resolves the current available balance of the specified token // for the specified owner. func (rs *rootResolver) ErcTokenBalance(args *struct { diff --git a/internal/graphql/resolvers/defi_configuration.go b/internal/graphql/resolvers/defi_configuration.go new file mode 100644 index 00000000..d3e4f294 --- /dev/null +++ b/internal/graphql/resolvers/defi_configuration.go @@ -0,0 +1,48 @@ +// Package resolvers implements GraphQL resolvers to incoming API requests. +package resolvers + +import ( + "fantom-api-graphql/internal/config" + "fantom-api-graphql/internal/repository" + "fantom-api-graphql/internal/types" + "github.com/ethereum/go-ethereum/common" +) + +// DefiConfiguration represents a resolvable DeFi Configuration instance. +type DefiConfiguration struct { + repo repository.Repository + cfg *config.Config + *types.DefiSettings +} + +// NewDefiConfiguration creates a new instance of resolvable DeFi token. +func NewDefiConfiguration(cf *types.DefiSettings, cfg *config.Config, repo repository.Repository) *DefiConfiguration { + return &DefiConfiguration{ + repo: repo, + cfg: cfg, + DefiSettings: cf, + } +} + +// DefiConfiguration resolves the current DeFi contract settings. +func (rs *rootResolver) DefiConfiguration() (*DefiConfiguration, error) { + // pass the call to repository + st, err := rs.repo.DefiConfiguration() + if err != nil { + return nil, err + } + + return NewDefiConfiguration(st, rs.cfg, rs.repo), nil +} + +// UniswapCoreFactory returns the address of the Uniswap factory contract +// from the app configuration. +func (dfc *DefiConfiguration) UniswapCoreFactory() common.Address { + return common.HexToAddress(dfc.cfg.DefiUniswapCore) +} + +// UniswapRouter returns the address of the Uniswap router contract +// from the app configuration. +func (dfc *DefiConfiguration) UniswapRouter() common.Address { + return common.HexToAddress(dfc.cfg.DefiUniswapRouter) +} diff --git a/internal/graphql/resolvers/root.go b/internal/graphql/resolvers/root.go index 2c6fd697..ad7e4e73 100644 --- a/internal/graphql/resolvers/root.go +++ b/internal/graphql/resolvers/root.go @@ -25,6 +25,9 @@ const ( // ApiResolver represents the API interface expected to handle API access points type ApiResolver interface { + // Config returns the app configuration. + Config() *config.Config + // State resolves current state of the blockchain. State() (CurrentState, error) @@ -153,7 +156,7 @@ type ApiResolver interface { SendTransaction(*struct{ Tx hexutil.Bytes }) (*Transaction, error) // DefiConfiguration resolves the current DeFi contract settings. - DefiConfiguration() (*types.DefiSettings, error) + DefiConfiguration() (*DefiConfiguration, error) // DefiTokens resolves list of DeFi tokens available for the DeFi functions. DefiTokens() ([]*DefiToken, error) @@ -313,3 +316,8 @@ func listLimitCount(count int32, limit uint32) int32 { return int32(limit) } + +// Config returns the application configuration. +func (rs *rootResolver) Config() *config.Config { + return rs.cfg +} diff --git a/internal/graphql/schema/bundle.go b/internal/graphql/schema/bundle.go index 838c633d..f712ac61 100644 --- a/internal/graphql/schema/bundle.go +++ b/internal/graphql/schema/bundle.go @@ -1,6 +1,6 @@ package gqlschema -// Auto generated GraphQL schema bundle; created 2020-09-22 09:25 +// Auto generated GraphQL schema bundle; created 2020-10-04 20:12 const schema = ` # DefiToken represents a token available for DeFi operations. type DefiToken { @@ -791,6 +791,12 @@ type DefiSettings { # fMintDebtPool is the address of the fMint debt pool. fMintDebtPool: Address! + + # uniswapCoreFactory is the address of the Uniswap Core Factory contract. + uniswapCoreFactory: Address! + + # uniswapRouter is the address of the Uniswap Router contract. + uniswapRouter: Address! } # EstimatedRewards represents a calculated rewards estimation for an account or amount staked diff --git a/internal/graphql/schema/definition/types/defi_config.graphql b/internal/graphql/schema/definition/types/defi_config.graphql index 2725afb6..1154ead8 100644 --- a/internal/graphql/schema/definition/types/defi_config.graphql +++ b/internal/graphql/schema/definition/types/defi_config.graphql @@ -46,4 +46,10 @@ type DefiSettings { # fMintDebtPool is the address of the fMint debt pool. fMintDebtPool: Address! + + # uniswapCoreFactory is the address of the Uniswap Core Factory contract. + uniswapCoreFactory: Address! + + # uniswapRouter is the address of the Uniswap Router contract. + uniswapRouter: Address! }