Skip to content

Commit

Permalink
Add tokenlist validation (trustwallet#17111)
Browse files Browse the repository at this point in the history
* Add tokenlist validation

* Fix according to review
  • Loading branch information
unanoc authored Jan 7, 2022
1 parent 9059319 commit e7f9efc
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 138 deletions.
1 change: 1 addition & 0 deletions .github/assets.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ validators_settings:
- "go.sum"
- ".golangci.yml"
- "Makefile"
- "bin"
skip_files:
- "node_modules"

Expand Down
2 changes: 1 addition & 1 deletion blockchains/binance/assets/BAKE-5E0/info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "BakeryToken",
"type": "BEP2",
"symbol": "BAKE-5E0",
"symbol": "BAKE",
"decimals": 8,
"website": "",
"description": "-",
Expand Down
2 changes: 1 addition & 1 deletion blockchains/binance/assets/BURGER-33A/info.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Burger Swap",
"type": "BEP2",
"symbol": "BURGER-33A",
"symbol": "BURGER",
"decimals": 8,
"website": "",
"description": "-",
Expand Down
10 changes: 0 additions & 10 deletions blockchains/binance/tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -1089,16 +1089,6 @@
"logoURI": "https://assets.trustwalletapp.com/blockchains/binance/assets/BET-844/logo.png",
"pairs": []
},
{
"asset": "c714_tBIFI-290",
"type": "BEP2",
"address": "BIFI-290",
"name": "beefy.finance",
"symbol": "BIFI",
"decimals": 8,
"logoURI": "https://assets.trustwalletapp.com/blockchains/binance/assets/BIFI-290/logo.png",
"pairs": []
},
{
"asset": "c714_tBKBT-3A6",
"type": "BEP2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "LTO",
"symbol": "XLTO",
"symbol": "LTO",
"type": "ERC20",
"decimals": 8,
"description": "Old ERC20 Smart Contract for LTO Network, please swap to v2. LTO Network is a layer-1 platform for decentralized identities, verifiable credentials and decentralized workflow applications, while maintaining data privacy and GDPR compliance.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Wrapped CrescoFin (WCRES)",
"type": "ERC20",
"symbol": "WCRES",
"symbol": "wCRES",
"decimals": 18,
"website": "https://defi.crescofin.ch",
"description": "wCRES represents unregistered equity in CrescoFin, a better banking alternative, with higher rates than in a bank and fully insured deposits and returns.\n\nIncorporated and regulated in Switzerland.",
Expand Down
18 changes: 4 additions & 14 deletions blockchains/ethereum/tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@
{
"asset": "c60_t0x41a3dba3d677e573636ba691a70ff2d606c29666",
"type": "ERC20",
"address": "0x41a3dba3d677e573636ba691a70ff2d606c29666",
"address": "0x41A3Dba3D677E573636BA691a70ff2D606c29666",
"name": "GoBlank",
"symbol": "BLANK",
"decimals": 18,
Expand Down Expand Up @@ -1503,7 +1503,7 @@
"type": "ERC20",
"address": "0x514910771AF9Ca656af840dff83E8264EcF986CA",
"name": "ChainLink",
"symbol": "Link",
"symbol": "LINK",
"decimals": 18,
"logoURI": "https://assets.trustwalletapp.com/blockchains/ethereum/assets/0x514910771AF9Ca656af840dff83E8264EcF986CA/logo.png",
"pairs": []
Expand Down Expand Up @@ -2190,16 +2190,6 @@
"logoURI": "https://assets.trustwalletapp.com/blockchains/ethereum/assets/0x8c15Ef5b4B21951d50E53E4fbdA8298FFAD25057/logo.png",
"pairs": []
},
{
"asset": "c60_t0x8c8687fC965593DFb2F0b4EAeFD55E9D8df348df",
"type": "ERC20",
"address": "0x8c8687fC965593DFb2F0b4EAeFD55E9D8df348df",
"name": "PAID Network",
"symbol": "PAID",
"decimals": 18,
"logoURI": "https://assets.trustwalletapp.com/blockchains/ethereum/assets/0x8c8687fC965593DFb2F0b4EAeFD55E9D8df348df/logo.png",
"pairs": []
},
{
"chainId": 1,
"asset": "c60_t0x8CE9137d39326AD0cD6491fb5CC0CbA0e089b6A9",
Expand Down Expand Up @@ -3178,7 +3168,7 @@
"type": "ERC20",
"address": "0xdd974D5C2e2928deA5F71b9825b8b646686BD200",
"name": "Kyber Network Crystal",
"symbol": "KNC",
"symbol": "KNCL",
"decimals": 18,
"logoURI": "https://assets.trustwalletapp.com/blockchains/ethereum/assets/0xdd974D5C2e2928deA5F71b9825b8b646686BD200/logo.png",
"pairs": []
Expand Down Expand Up @@ -3279,7 +3269,7 @@
"type": "ERC20",
"address": "0xE95A203B1a91a908F9B9CE46459d101078c2c3cb",
"name": "aEthereum",
"symbol": "aEth",
"symbol": "aETHc",
"decimals": 18,
"logoURI": "https://assets.trustwalletapp.com/blockchains/ethereum/assets/0xE95A203B1a91a908F9B9CE46459d101078c2c3cb/logo.png",
"pairs": []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Filecoin",
"name": "Binance-Peg Filecoin",
"website": "https://filecoin.io",
"description": "Filecoin provides a blockchain-based marketplace that aims to revolutionize the global storage economy.",
"explorer": "https://bscscan.com/token/0x0D8Ce2A99Bb6e3B7Db580eD848240e4a0F9aE153",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"explorer": "https://bscscan.com/token/0x63870a18b6e42b01ef1ad8a2302ef50b7132054f",
"research": "",
"type": "BEP20",
"symbol": "blink",
"symbol": "BLINK",
"decimals": 6,
"status": "active",
"id": "0x63870A18B6e42b01Ef1Ad8A2302ef50B7132054F"
Expand Down
4 changes: 2 additions & 2 deletions blockchains/smartchain/tokenlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
"type": "BEP20",
"address": "0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82",
"name": "PancakeSwap Token",
"symbol": "Cake",
"symbol": "CAKE",
"decimals": 18,
"logoURI": "https://assets.trustwalletapp.com/blockchains/smartchain/assets/0x0E09FaBB73Bd3Ade0a17ECC321fD13a19e81cE82/logo.png",
"pairs": []
Expand Down Expand Up @@ -511,7 +511,7 @@
"address": "0x78650B139471520656b9E7aA7A5e9276814a38e9",
"name": "StandardBTCHashrateToken",
"symbol": "BTCST",
"decimals": 18,
"decimals": 17,
"logoURI": "https://assets.trustwalletapp.com/blockchains/smartchain/assets/0x78650B139471520656b9E7aA7A5e9276814a38e9/logo.png",
"pairs": []
},
Expand Down
16 changes: 0 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,10 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/trustwallet/assets-go-libs v0.0.16 h1:nbKrf/pHKQCut4Q5Mdg5BinLdFxOqvzEeAgIgzX0/P8=
github.com/trustwallet/assets-go-libs v0.0.16/go.mod h1:agKWTQ9ECSzQ++7P/9viSxJnG1Kp+WhfDyI3pAmtnVM=
github.com/trustwallet/assets-go-libs v0.0.17-0.20211220141041-3b3a722649fa h1:d+FAYtxmN8mJK9jobkzOotwSEU2KPZ9H4gmuBg6dv3M=
github.com/trustwallet/assets-go-libs v0.0.17-0.20211220141041-3b3a722649fa/go.mod h1:agKWTQ9ECSzQ++7P/9viSxJnG1Kp+WhfDyI3pAmtnVM=
github.com/trustwallet/assets-go-libs v0.0.17-0.20211220141745-408afc4f7467 h1:JYCmTXnQfR/RElBY9aFppwLVwvy7wuBNbtW5f31j1Vs=
github.com/trustwallet/assets-go-libs v0.0.17-0.20211220141745-408afc4f7467/go.mod h1:agKWTQ9ECSzQ++7P/9viSxJnG1Kp+WhfDyI3pAmtnVM=
github.com/trustwallet/assets-go-libs v0.0.17-0.20211220144503-44a66d3a5e92 h1:TT3IFY3cBZBQAMdoVA8bzdH8q58d8hkiiVpBAmZJ+J8=
github.com/trustwallet/assets-go-libs v0.0.17-0.20211220144503-44a66d3a5e92/go.mod h1:agKWTQ9ECSzQ++7P/9viSxJnG1Kp+WhfDyI3pAmtnVM=
github.com/trustwallet/assets-go-libs v0.0.17 h1:s/XF4C7peyFuKadoRr9YhjfMoWAx9yKzk2IFmtT5ZpM=
github.com/trustwallet/assets-go-libs v0.0.17/go.mod h1:agKWTQ9ECSzQ++7P/9viSxJnG1Kp+WhfDyI3pAmtnVM=
github.com/trustwallet/assets-go-libs v0.0.19-0.20211224113937-74dc923bd4b5 h1:3bqdCY+jcpx6QCYc+Eb/Kci3ZRljI7CP6t3H+JhKAmo=
github.com/trustwallet/assets-go-libs v0.0.19-0.20211224113937-74dc923bd4b5/go.mod h1:jPJ2JP6SF+/6fXLETojEtSssCB5Lyeid8rjS6NLS4e4=
github.com/trustwallet/assets-go-libs v0.0.19-0.20211224115115-e2089570f2fd h1:QtDE54pHNtql9sQvyAyO6alzyaXcnIUuwNytcF25EyU=
github.com/trustwallet/assets-go-libs v0.0.19-0.20211224115115-e2089570f2fd/go.mod h1:jPJ2JP6SF+/6fXLETojEtSssCB5Lyeid8rjS6NLS4e4=
github.com/trustwallet/assets-go-libs v0.0.19 h1:Zn7su7wSrJLOHSeEoM+jz8smmIFsX+tAGI3FQ7rwwqQ=
github.com/trustwallet/assets-go-libs v0.0.19/go.mod h1:/il5tQtqP3uSDbyDTfP1OsL3kSIg+v6+QBRz3okXZpc=
github.com/trustwallet/go-libs v0.2.21-0.20211217144209-59d4828f9793 h1:KFtyLpBPbMyUdeCth/Zcej/SSgAFIo6fxdS2eEPEg3I=
github.com/trustwallet/go-libs v0.2.21-0.20211217144209-59d4828f9793/go.mod h1:7QdAp1lcteKKI0DYqGoaO8KO4eTNYjGmg8vHy0YXkKc=
github.com/trustwallet/go-primitives v0.0.17 h1:1fBxZMKGCHdHtgdUzsqdFlD21+1GneIk/sxN6jxYBds=
github.com/trustwallet/go-primitives v0.0.17/go.mod h1:jLqd7rm+4EYG5JdpxhngM9HwbqfEXzKy/wK4vUB7STs=
github.com/trustwallet/go-primitives v0.0.19 h1:IvuzU1tB5u+UpjPkJqPqVvb8axLj1LI5nQmTvhmNIck=
github.com/trustwallet/go-primitives v0.0.19/go.mod h1:jLqd7rm+4EYG5JdpxhngM9HwbqfEXzKy/wK4vUB7STs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
21 changes: 12 additions & 9 deletions internal/processor/model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package processor

import "github.com/trustwallet/assets/internal/file"
import (
"github.com/trustwallet/assets/internal/file"
"github.com/trustwallet/go-primitives/types"
)

type (
Validator struct {
Expand Down Expand Up @@ -29,14 +32,14 @@ type (
}

TokenItem struct {
Asset string `json:"asset"`
Type string `json:"type"`
Address string `json:"address"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Decimals uint `json:"decimals"`
LogoURI string `json:"logoURI"`
Pairs []Pair `json:"pairs"`
Asset string `json:"asset"`
Type types.TokenType `json:"type"`
Address string `json:"address"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Decimals uint `json:"decimals"`
LogoURI string `json:"logoURI"`
Pairs []Pair `json:"pairs"`
}

Pair struct {
Expand Down
110 changes: 35 additions & 75 deletions internal/processor/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,116 +12,85 @@ func NewService(fileProvider *file.Service) *Service {
return &Service{fileService: fileProvider}
}

func (s *Service) GetValidator(f *file.AssetFile) *Validator {
func (s *Service) GetValidator(f *file.AssetFile) []Validator {
switch f.Type() {
case file.TypeRootFolder:
return &Validator{
Name: "Root folder contains only allowed files",
Run: s.ValidateRootFolder,
return []Validator{
{Name: "Root folder contains only allowed files", Run: s.ValidateRootFolder},
}
case file.TypeChainFolder:
return &Validator{
Name: "Chain folders are lowercase and contains only allowed files",
Run: s.ValidateChainFolder,
return []Validator{
{Name: "Chain folders are lowercase and contains only allowed files", Run: s.ValidateChainFolder},
}
case file.TypeChainLogoFile, file.TypeAssetLogoFile, file.TypeValidatorsLogoFile, file.TypeDappsLogoFile:
return &Validator{
Name: "Logos (size, dimension)",
Run: s.ValidateImage,
return []Validator{
{Name: "Logos (size, dimension)", Run: s.ValidateImage},
}
case file.TypeAssetFolder:
return &Validator{
Name: "Each asset folder has valid asset address and contains logo/info",
Run: s.ValidateAssetFolder,
return []Validator{
{Name: "Each asset folder has valid asset address and contains logo/info", Run: s.ValidateAssetFolder},
}
case file.TypeDappsFolder:
return &Validator{
Name: "Dapps folder (allowed only png files, lowercase)",
Run: s.ValidateDappsFolder,
return []Validator{
{Name: "Dapps folder (allowed only png files, lowercase)", Run: s.ValidateDappsFolder},
}
case file.TypeAssetInfoFile:
return &Validator{
Name: "Asset info (is valid json, fields)",
Run: s.ValidateAssetInfoFile,
return []Validator{
{Name: "Asset info (is valid json, fields)", Run: s.ValidateAssetInfoFile},
}
case file.TypeChainInfoFile:
return &Validator{
Name: "Chain Info (is valid json, fields)",
Run: s.ValidateChainInfoFile,
return []Validator{
{Name: "Chain Info (is valid json, fields)", Run: s.ValidateChainInfoFile},
}
case file.TypeValidatorsListFile:
return &Validator{
Name: "Validators list file",
Run: s.ValidateValidatorsListFile,
return []Validator{
{Name: "Validators list file", Run: s.ValidateValidatorsListFile},
}
case file.TypeTokenListFile:
return &Validator{
Name: "Token list (if assets from list present in chain)",
Run: s.ValidateTokenListFile,
return []Validator{
{Name: "Token list (if assets from list present in chain)", Run: s.ValidateTokenListFile},
}
case file.TypeChainInfoFolder:
return &Validator{
Name: "Chain Info Folder (has files)",
Run: s.ValidateInfoFolder,
return []Validator{
{Name: "Chain Info Folder (has files)", Run: s.ValidateInfoFolder},
}
case file.TypeValidatorsAssetFolder:
return &Validator{
Name: "Validators asset folder (has logo, valid asset address)",
Run: s.ValidateValidatorsAssetFolder,
return []Validator{
{Name: "Validators asset folder (has logo, valid asset address)", Run: s.ValidateValidatorsAssetFolder},
}
}

return nil
}

func (s *Service) GetFixers(f *file.AssetFile) []Fixer {
infoFixer := Fixer{
Name: "Formatting all info.json files",
jsonFixer := Fixer{
Name: "Formatting all json files",
Run: s.FixJSON,
}

ethAssetFixer := Fixer{
Name: "Renaming EVM's asset folder to valid address checksum",
Run: s.FixETHAddressChecksum,
}

logoFixer := Fixer{
Name: "Resizing and compressing logo images",
Run: s.FixLogo,
}

chainInfoFixer := Fixer{
Name: "Fixing chain info.json files",
Run: s.FixChainInfoJSON,
}

assetInfoFixer := Fixer{
Name: "Fixing asset info.json files",
Run: s.FixAssetInfoJSON,
}

switch f.Type() {
case file.TypeChainInfoFile:
return []Fixer{
infoFixer,
chainInfoFixer,
jsonFixer,
{Name: "Fixing chain info.json files", Run: s.FixChainInfoJSON},
}
case file.TypeAssetInfoFile:
return []Fixer{
infoFixer,
assetInfoFixer,
jsonFixer,
{Name: "Fixing asset info.json files", Run: s.FixAssetInfoJSON},
}
case file.TypeValidatorsListFile:
return []Fixer{
infoFixer,
jsonFixer,
}
case file.TypeAssetFolder:
return []Fixer{
ethAssetFixer,
{Name: "Renaming EVM's asset folder to valid address checksum", Run: s.FixETHAddressChecksum},
}
case file.TypeChainLogoFile, file.TypeAssetLogoFile, file.TypeValidatorsLogoFile, file.TypeDappsLogoFile:
return []Fixer{
logoFixer,
{Name: "Resizing and compressing logo images", Run: s.FixLogo},
}
}

Expand All @@ -130,22 +99,13 @@ func (s *Service) GetFixers(f *file.AssetFile) []Fixer {

func (s *Service) GetUpdatersAuto() []Updater {
return []Updater{
{
Name: "Retrieving missing token images, creating binance token list.",
Run: s.UpdateBinanceTokens,
},
{Name: "Retrieving missing token images, creating binance token list.", Run: s.UpdateBinanceTokens},
}
}

func (s *Service) GetUpdatersManual() []Updater {
return []Updater{
{
Name: "Update tokenlist.json for Ethereum",
Run: s.UpdateEthereumTokenlist,
},
{
Name: "Update tokenlist.json for Smartchain",
Run: s.UpdateSmartchainTokenlist,
},
{Name: "Update tokenlist.json for Ethereum", Run: s.UpdateEthereumTokenlist},
{Name: "Update tokenlist.json for Smartchain", Run: s.UpdateSmartchainTokenlist},
}
}
Loading

0 comments on commit e7f9efc

Please sign in to comment.