Skip to content

Commit

Permalink
[bot] - Update lists
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Jul 16, 2024
1 parent e67c45e commit 262d377
Show file tree
Hide file tree
Showing 172 changed files with 143,043 additions and 48,964 deletions.
10 changes: 0 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ jobs:
RPC_URI_FOR_56288=${{ secrets.RPC_URI_FOR_56288 }}
RPC_URI_FOR_81457=${{ secrets.RPC_URI_FOR_81457 }}
RPC_URI_FOR_111188=${{ secrets.RPC_URI_FOR_111188 }}
RPC_URI_FOR_2522=${{ secrets.RPC_URI_FOR_2522 }}
RPC_URI_FOR_9728=${{ secrets.RPC_URI_FOR_9728 }}
RPC_URI_FOR_17000=${{ secrets.RPC_URI_FOR_17000 }}
RPC_URI_FOR_18233=${{ secrets.RPC_URI_FOR_18233 }}
RPC_URI_FOR_28882=${{ secrets.RPC_URI_FOR_28882 }}
RPC_URI_FOR_80001=${{ secrets.RPC_URI_FOR_80001 }}
RPC_URI_FOR_84532=${{ secrets.RPC_URI_FOR_84532 }}
RPC_URI_FOR_421614=${{ secrets.RPC_URI_FOR_421614 }}
RPC_URI_FOR_11155111=${{ secrets.RPC_URI_FOR_11155111 }}
RPC_URI_FOR_11155420=${{ secrets.RPC_URI_FOR_11155420 }}
go run ./generators tokens
- name: Commit files
run: |
Expand Down
18 changes: 9 additions & 9 deletions generators/buildTokenList.1inch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ type T1InchList struct {
}

var APIURIFor1Inch = map[uint64]string{
1: `https://api.1inch.io/v5.0/1/tokens`,
10: `https://api.1inch.io/v5.0/10/tokens`,
56: `https://api.1inch.io/v5.0/56/tokens`,
100: `https://api.1inch.io/v5.0/100/tokens`,
137: `https://api.1inch.io/v5.0/137/tokens`,
250: `https://api.1inch.io/v5.0/250/tokens`,
42161: `https://api.1inch.io/v5.0/42161/tokens`,
43114: `https://api.1inch.io/v5.0/43114/tokens`,
1: `https://api.1inch.dev/token/v1.2/1/token-list`,
10: `https://api.1inch.dev/token/v1.2/10/token-list`,
56: `https://api.1inch.dev/token/v1.2/56/token-list`,
100: `https://api.1inch.dev/token/v1.2/100/token-list`,
137: `https://api.1inch.dev/token/v1.2/137/token-list`,
250: `https://api.1inch.dev/token/v1.2/250/token-list`,
42161: `https://api.1inch.dev/token/v1.2/42161/token-list`,
43114: `https://api.1inch.dev/token/v1.2/43114/token-list`,
}

func fetch1InchTokenList() []models.TokenListToken {
Expand All @@ -37,7 +37,7 @@ func fetch1InchTokenList() []models.TokenListToken {
continue
}

list := helpers.FetchJSON[T1InchList](uri)
list := helpers.FetchJSON[models.TokenListData[models.TokenListToken]](uri)
tokenAddresses := []common.Address{}
for _, token := range list.Tokens {
tokenAddresses = append(tokenAddresses, common.HexToAddress(token.Address))
Expand Down
4 changes: 3 additions & 1 deletion generators/buildTokenList.popular.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ func buildPopularList() {
}

helpers.SaveTokenListInJsonFile(tokenList, tokens, `popular.json`, helpers.SavingMethodStandard)
helpers.SaveChainListInJsonFile(tokenList, tokens)

// Update the chainlist with the new tokens
tokenList = helpers.LoadTokenListFromJsonFile(`popular.json`)
helpers.SaveChainListInJsonFile(tokenList)
}
8 changes: 4 additions & 4 deletions generators/buildTokenList.velo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func fetchVeloLikeTokenList(chainID uint64, sugarAddress common.Address) []model
addressesMap := make(map[common.Address]bool)
addressesSlice := []common.Address{}

for i := 0; i < 10; i++ {
offset := big.NewInt(int64(i * 500))
allTokens, err := veloSugar.All(nil, big.NewInt(500), offset, common.Address{})
for i := 0; i < 100; i++ {
offset := big.NewInt(int64(i * 25))
allTokens, err := veloSugar.All(nil, big.NewInt(25), offset, common.Address{})
if err != nil {
logs.Error(err)
return []models.TokenListToken{}
break
}
for _, token := range allTokens {
addressesMap[token.Token0] = true
Expand Down
1 change: 1 addition & 0 deletions generators/common/ethereum/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func Init() {
for _, chainID := range chains.SUPPORTED_CHAIN_IDS {
client, err := ethclient.Dial(GetRPCURI(chainID))
if err != nil {
logs.Warning(`Missing environment variable RPC_URI_FOR_` + strconv.FormatUint(chainID, 10))
os.Setenv(`RPC_URI_FOR_`+strconv.FormatUint(chainID, 10), chains.CHAINS[chainID].RpcURI)
RPC_ENDPOINTS[chainID] = useEnv(`RPC_URI_FOR_`+strconv.FormatUint(chainID, 10), RPC_ENDPOINTS[chainID])
client, err = ethclient.Dial(RPC_ENDPOINTS[chainID])
Expand Down
8 changes: 8 additions & 0 deletions generators/common/helpers/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"io/ioutil"
"net/http"
"os"
"strings"

"github.com/migratooor/tokenLists/generators/common/logs"
Expand All @@ -19,6 +20,12 @@ func FetchJSON[T any](uri string) (data T) {
req, _ := http.NewRequest("GET", uri, nil)
req.Header.Set("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36")
resp, err = http.DefaultClient.Do(req)
} else if strings.Contains(uri, `api.1inch.dev`) {
req, _ := http.NewRequest("GET", uri, nil)
onInchBearerFromEnv := os.Getenv("BEARER_FOR_1INCH")
req.Header.Set("Authorization", "Bearer "+onInchBearerFromEnv)
req.Header.Set("Content-Type", "application/json")
resp, err = http.DefaultClient.Do(req)
} else {
resp, err = http.Get(uri)
}
Expand All @@ -34,6 +41,7 @@ func FetchJSON[T any](uri string) (data T) {
}

if (resp.StatusCode < 200) || (resp.StatusCode > 299) {
logs.Error(`Error status code for URI ` + uri + `: ` + resp.Status)
return data
}

Expand Down
25 changes: 7 additions & 18 deletions generators/common/helpers/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func SaveTokenListInJsonFile(
filePath string,
method JSONSaveTokensMethods,
) error {
listName := BASE_PATH + `/lists/` + filePath
tokens := []models.TokenListToken{}
addresses := make(map[string]bool)
for _, token := range tokensMaybeDuplicates {
Expand Down Expand Up @@ -143,7 +144,7 @@ func SaveTokenListInJsonFile(
** If the list is empty, we skip
**************************************************************************/
if len(tokenList.NextTokensMap) == 0 {
return errors.New(`token list is empty`)
return errors.New(`token list is empty for ` + listName)
}

/**************************************************************************
Expand All @@ -165,7 +166,7 @@ func SaveTokenListInJsonFile(
}

if len(tokenList.NextTokensMap) <= baseCoinCount {
return errors.New(`token list is empty`)
return errors.New(`token list is empty for ` + listName)
}

tokenList.Timestamp = time.Now().Format(time.RFC3339)
Expand Down Expand Up @@ -199,7 +200,7 @@ func SaveTokenListInJsonFile(
** If there are no changes, we will just return.
**************************************************************************/
if !shouldBumpMajor && !shouldBumpMinor && !shouldBumpPatch {
return errors.New(`no changes detected`)
return errors.New(`no changes detected for ` + listName)
}

if shouldBumpMajor {
Expand Down Expand Up @@ -258,13 +259,12 @@ func SaveTokenListInJsonFile(

for chainID, tokens := range tokenListPerChainID {
if !chains.IsChainIDSupported(chainID) {
logs.Info(`ChainID ` + strconv.FormatUint(chainID, 10) + ` is not supported`)
continue
}
chainIDStr := strconv.FormatUint(chainID, 10)

if len(tokens) <= len(chains.CHAINS[chainID].ExtraTokens)+1 {
logs.Info(`No need to save the list for chainID ` + chainIDStr)
logs.Info(`No need to save the list ` + filePath + ` for chainID ` + chainIDStr)
continue //If we have as much tokens as the extra tokens, we don't need to save the list, this is the default list
}

Expand Down Expand Up @@ -297,19 +297,8 @@ func SaveTokenListInJsonFile(
// SaveChainListInJsonFile saves a chain list in a json file
func SaveChainListInJsonFile(
tokenList models.TokenListData[models.TokenListToken],
tokensMaybeDuplicates []models.TokenListToken,
) error {
tokens := []models.TokenListToken{}
addresses := make(map[string]bool)
for _, token := range tokensMaybeDuplicates {
key := token.Address + strconv.FormatUint(token.ChainID, 10)
if _, ok := addresses[key]; !ok {
addresses[key] = true
tokens = append(tokens, token)
}
}

for _, token := range tokens {
for _, token := range tokenList.Tokens {
if !chains.IsChainIDSupported(token.ChainID) {
continue
}
Expand Down Expand Up @@ -389,7 +378,7 @@ func SaveChainListInJsonFile(
** If there are no changes, we will just return.
**************************************************************************/
if !shouldBumpMajor && !shouldBumpMinor && !shouldBumpPatch {
return nil
return errors.New(`no changes detected`)
}

if shouldBumpMajor {
Expand Down
Loading

0 comments on commit 262d377

Please sign in to comment.