Skip to content

Commit

Permalink
added native token and explorer url to chains response
Browse files Browse the repository at this point in the history
  • Loading branch information
1henny committed Jun 8, 2023
1 parent 4d68c2b commit 9695029
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
10 changes: 9 additions & 1 deletion docs/spec/components/schemas/Chain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ allOf:
- icon
- swap_contract_address
- swap_contract_version
- explorer_url
- native_symbol
properties:
name:
type: string
Expand Down Expand Up @@ -51,4 +53,10 @@ allOf:
example: "0x85718348D854CE2768e96D87a2ed6d12d619b67B"
swap_contract_version:
type: string
example: "PancakeSwap"
example: "PancakeSwap"
explorer_url:
type: string
example: "https://bscscan.com/"
native_symbol:
type: string
example: "BNB"
27 changes: 27 additions & 0 deletions internal/config/chains.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"gitlab.com/distributed_lab/logan/v3"
"gitlab.com/rarimo/dex-pairs-oracle/internal/chains"

"gitlab.com/distributed_lab/figure/v3"
Expand All @@ -23,6 +24,32 @@ func (c *config) ChainsCfg() *chains.Config {
panic(errors.Wrap(err, "failed to figure out "+cfgName))
}

if err := validateChains(cfg); err != nil {
panic(errors.Wrap(err, "failed to validate "+cfgName))
}

return &cfg
}).(*chains.Config)
}

func validateChains(cfg chains.Config) error {
for _, chain := range cfg.Chains {
if chain.NativeSymbol == "" {
return errors.From(errors.New("native symbol is required"), logan.F{
"chain": chain.Name,
})
}

for _, tokenInfo := range chain.TokensInfo.Tokens {
if tokenInfo.Symbol == chain.NativeSymbol {
continue
}
}

return errors.From(errors.New("native token is not configured in tokens"), logan.F{
"chain": chain.Name,
})
}

return nil
}
2 changes: 2 additions & 0 deletions internal/services/api/handlers/list_supported_chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func chainToResource(chain chains.Chain) resources.Chain {
SwapContractAddress: chain.SwapContractAddr.String(),
SwapContractVersion: string(chain.SwapContractVersion),
Type: chainTypeToResource(chain.Type),
ExplorerUrl: chain.ExplorerURL,
NativeSymbol: chain.NativeSymbol,
},
}
}
Expand Down
4 changes: 3 additions & 1 deletion resources/model_chain_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
package resources

type ChainAttributes struct {
Icon string `json:"icon"`
ExplorerUrl string `json:"explorer_url"`
Icon string `json:"icon"`
// The kind of the chain
Kind ChainKind `json:"kind"`
Name string `json:"name"`
NativeSymbol string `json:"native_symbol"`
Rpc string `json:"rpc"`
SwapContractAddress string `json:"swap_contract_address"`
SwapContractVersion string `json:"swap_contract_version"`
Expand Down

0 comments on commit 9695029

Please sign in to comment.