diff --git a/docs/spec/components/schemas/Chain.yaml b/docs/spec/components/schemas/Chain.yaml index 0020671..6b1a313 100644 --- a/docs/spec/components/schemas/Chain.yaml +++ b/docs/spec/components/schemas/Chain.yaml @@ -15,7 +15,7 @@ allOf: - swap_contract_address - swap_contract_version - explorer_url - - native_symbol + - native_token properties: name: type: string @@ -57,6 +57,5 @@ allOf: explorer_url: type: string example: "https://bscscan.com/" - native_symbol: - type: string - example: "BNB" \ No newline at end of file + native_token: + $ref: '#/components/schemas/NativeTokenInfo' \ No newline at end of file diff --git a/docs/spec/components/schemas/NativeTokenInfo.yaml b/docs/spec/components/schemas/NativeTokenInfo.yaml new file mode 100644 index 0000000..bff0c3b --- /dev/null +++ b/docs/spec/components/schemas/NativeTokenInfo.yaml @@ -0,0 +1,23 @@ +type: object +required: + - name + - symbol + - decimals +properties: + name: + type: string + description: | + The name of the token. + example: "Binance Coin" + symbol: + type: string + description: | + The symbol of the token. + example: "BNB" + decimals: + type: integer + format: int64 + description: | + The number of decimals the token uses - e.g. 18, means to divide the token amount by 1000000000000000000 to get its user representation. + example: 18 + diff --git a/internal/services/api/handlers/list_supported_chains.go b/internal/services/api/handlers/list_supported_chains.go index 8eb7a7a..2bd0632 100644 --- a/internal/services/api/handlers/list_supported_chains.go +++ b/internal/services/api/handlers/list_supported_chains.go @@ -69,7 +69,7 @@ func ListSupportedChain(w http.ResponseWriter, r *http.Request) { } func chainToResource(chain chains.Chain) resources.Chain { - return resources.Chain{ + c := resources.Chain{ Key: resources.Key{ ID: strconv.FormatInt(chain.ID, 10), Type: resources.CHAINS, @@ -83,9 +83,21 @@ func chainToResource(chain chains.Chain) resources.Chain { SwapContractVersion: string(chain.SwapContractVersion), Type: chainTypeToResource(chain.Type), ExplorerUrl: chain.ExplorerURL, - NativeSymbol: chain.NativeSymbol, }, } + + for _, token := range chain.TokensInfo.Tokens { + if token.Native { + c.Attributes.NativeToken = resources.NativeTokenInfo{ + Symbol: token.Symbol, + Name: token.Name, + Decimals: token.Decimals, + } + break + } + } + + return c } func chainKindToResource(kind chains.Kind) resources.ChainKind { diff --git a/resources/model_chain_attributes.go b/resources/model_chain_attributes.go index 174de90..4c23969 100644 --- a/resources/model_chain_attributes.go +++ b/resources/model_chain_attributes.go @@ -8,12 +8,12 @@ type ChainAttributes struct { 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"` + Kind ChainKind `json:"kind"` + Name string `json:"name"` + NativeToken NativeTokenInfo `json:"native_token"` + Rpc string `json:"rpc"` + SwapContractAddress string `json:"swap_contract_address"` + SwapContractVersion string `json:"swap_contract_version"` // The type of the chain Type ChainType `json:"type"` } diff --git a/resources/model_native_token_info.go b/resources/model_native_token_info.go new file mode 100644 index 0000000..66b6c7e --- /dev/null +++ b/resources/model_native_token_info.go @@ -0,0 +1,14 @@ +/* + * GENERATED. Do not modify. Your changes might be overwritten! + */ + +package resources + +type NativeTokenInfo struct { + // The number of decimals the token uses - e.g. 18, means to divide the token amount by 1000000000000000000 to get its user representation. + Decimals int64 `json:"decimals"` + // The name of the token. + Name string `json:"name"` + // The symbol of the token. + Symbol string `json:"symbol"` +}