Skip to content

Commit

Permalink
Add Uniswap contracts addresses to the DeFi API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiri Malek committed Oct 4, 2020
1 parent ed60320 commit b8f8f14
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
6 changes: 0 additions & 6 deletions internal/graphql/resolvers/defi.go
Expand Up @@ -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 {
Expand Down
48 changes: 48 additions & 0 deletions 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)
}
10 changes: 9 additions & 1 deletion internal/graphql/resolvers/root.go
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
8 changes: 7 additions & 1 deletion 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 {
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions internal/graphql/schema/definition/types/defi_config.graphql
Expand Up @@ -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!
}

0 comments on commit b8f8f14

Please sign in to comment.