From d2385e9567eced8d4b10b523f08936ef8205e78c Mon Sep 17 00:00:00 2001 From: Nikos Karakostas Date: Thu, 15 Dec 2022 15:05:21 +0200 Subject: [PATCH] Support token types: moonbeam, klaytn, metis, moonriver, boba (#84) --- coin/coins.go | 290 +++++++++++++++++++++++++++++++------------- coin/coins.yml | 35 ++++++ coin/models.go | 10 ++ coin/models_test.go | 55 +++++++++ types/chain.go | 10 ++ types/chainid.go | 5 + types/token.go | 23 +++- types/token_test.go | 55 +++++++++ 8 files changed, 400 insertions(+), 83 deletions(-) diff --git a/coin/coins.go b/coin/coins.go index 6cb80e1..834d76b 100644 --- a/coin/coins.go +++ b/coin/coins.go @@ -1,6 +1,6 @@ // Code generated by go generate; DO NOT EDIT. // This file was generated by robots at -// 2022-10-17 22:01:13.452199091 +0300 EEST m=+0.001091687 +// 2022-12-15 14:09:36.876903 +0200 EET m=+0.003896126 // using data from coins.yml package coin @@ -45,88 +45,93 @@ func (c Coin) TokenAssetID(t string) AssetID { } const ( - ETHEREUM = 60 - CLASSIC = 61 - ICON = 74 - COSMOS = 118 - RIPPLE = 144 - STELLAR = 148 - POA = 178 - TRON = 195 - FIO = 235 - NIMIQ = 242 - IOTEX = 304 - ZILLIQA = 313 - AION = 425 - AETERNITY = 457 - KAVA = 459 - THETA = 500 - BINANCE = 714 - VECHAIN = 818 - CALLISTO = 820 - TOMOCHAIN = 889 + ETHEREUM = 60 + CLASSIC = 61 + ICON = 74 + COSMOS = 118 + RIPPLE = 144 + STELLAR = 148 + POA = 178 + TRON = 195 + FIO = 235 + NIMIQ = 242 + IOTEX = 304 + ZILLIQA = 313 + AION = 425 + AETERNITY = 457 + KAVA = 459 + THETA = 500 + BINANCE = 714 + VECHAIN = 818 + CALLISTO = 820 + TOMOCHAIN = 889 THUNDERTOKEN = 1001 - ONTOLOGY = 1024 - TEZOS = 1729 - KIN = 2017 - NEBULAS = 2718 - GOCHAIN = 6060 - WANCHAIN = 5718350 - WAVES = 5741564 - BITCOIN = 0 - LITECOIN = 2 - DOGE = 3 - DASH = 5 - VIACOIN = 14 - GROESTLCOIN = 17 - ZCASH = 133 - FIRO = 136 - BITCOINCASH = 145 - RAVENCOIN = 175 - QTUM = 2301 - ZELCASH = 19167 - DECRED = 42 - ALGORAND = 283 - NANO = 165 - DIGIBYTE = 20 - HARMONY = 1023 - KUSAMA = 434 - POLKADOT = 354 - SOLANA = 501 - NEAR = 397 - ELROND = 508 - SMARTCHAIN = 20000714 - FILECOIN = 461 - OASIS = 474 - MONACOIN = 22 - BITCOINGOLD = 156 - EOS = 194 - TERRA = 330 - BAND = 494 - NEO = 888 - CARDANO = 1815 - NULS = 8964 - POLYGON = 966 - THORCHAIN = 931 - OPTIMISM = 10000070 - XDAI = 10000100 - AVALANCHEC = 10009000 - HECO = 10000553 - FANTOM = 10000250 - ARBITRUM = 10042221 - CELO = 52752 - RONIN = 10002020 - OSMOSIS = 10000118 - CRONOS = 10000025 - KCC = 10000321 - AURORA = 1323161554 - KAVAEVM = 10002222 - METER = 18000 - EVMOS = 10009001 - NATIVEEVMOS = 20009001 - OKC = 996 - CRYPTOORG = 394 - APTOS = 637 + ONTOLOGY = 1024 + TEZOS = 1729 + KIN = 2017 + NEBULAS = 2718 + GOCHAIN = 6060 + WANCHAIN = 5718350 + WAVES = 5741564 + BITCOIN = 0 + LITECOIN = 2 + DOGE = 3 + DASH = 5 + VIACOIN = 14 + GROESTLCOIN = 17 + ZCASH = 133 + FIRO = 136 + BITCOINCASH = 145 + RAVENCOIN = 175 + QTUM = 2301 + ZELCASH = 19167 + DECRED = 42 + ALGORAND = 283 + NANO = 165 + DIGIBYTE = 20 + HARMONY = 1023 + KUSAMA = 434 + POLKADOT = 354 + SOLANA = 501 + NEAR = 397 + ELROND = 508 + SMARTCHAIN = 20000714 + FILECOIN = 461 + OASIS = 474 + MONACOIN = 22 + BITCOINGOLD = 156 + EOS = 194 + TERRA = 330 + BAND = 494 + NEO = 888 + CARDANO = 1815 + NULS = 8964 + POLYGON = 966 + THORCHAIN = 931 + OPTIMISM = 10000070 + XDAI = 10000100 + AVALANCHEC = 10009000 + HECO = 10000553 + FANTOM = 10000250 + ARBITRUM = 10042221 + CELO = 52752 + RONIN = 10002020 + OSMOSIS = 10000118 + CRONOS = 10000025 + KCC = 10000321 + AURORA = 1323161554 + KAVAEVM = 10002222 + METER = 18000 + EVMOS = 10009001 + NATIVEEVMOS = 20009001 + OKC = 996 + CRYPTOORG = 394 + APTOS = 637 + MOONBEAM = 10001284 + KLAYTN = 10008217 + METIS = 10001088 + MOONRIVER = 10001285 + BOBA = 10000288 ) var Coins = map[uint]Coin{ @@ -950,6 +955,56 @@ var Coins = map[uint]Coin{ MinConfirmations: 0, Blockchain: "Aptos", }, + MOONBEAM: { + ID: 10001284, + Handle: "moonbeam", + Symbol: "GLMR", + Name: "Moonbeam", + Decimals: 18, + BlockTime: 0, + MinConfirmations: 0, + Blockchain: "Ethereum", + }, + KLAYTN: { + ID: 10008217, + Handle: "klaytn", + Symbol: "KLAY", + Name: "Klaytn", + Decimals: 18, + BlockTime: 0, + MinConfirmations: 0, + Blockchain: "Ethereum", + }, + METIS: { + ID: 10001088, + Handle: "metis", + Symbol: "METIS", + Name: "Metis", + Decimals: 18, + BlockTime: 0, + MinConfirmations: 0, + Blockchain: "Ethereum", + }, + MOONRIVER: { + ID: 10001285, + Handle: "moonriver", + Symbol: "MOVR", + Name: "Moonriver", + Decimals: 18, + BlockTime: 0, + MinConfirmations: 0, + Blockchain: "Ethereum", + }, + BOBA: { + ID: 10000288, + Handle: "boba", + Symbol: "BOBAETH", + Name: "Boba", + Decimals: 18, + BlockTime: 0, + MinConfirmations: 0, + Blockchain: "Ethereum", + }, } var Chains = map[string]Coin{ @@ -1773,6 +1828,56 @@ var Chains = map[string]Coin{ MinConfirmations: 0, Blockchain: "Aptos", }, + Moonbeam().Handle: { + ID: 10001284, + Handle: "moonbeam", + Symbol: "GLMR", + Name: "Moonbeam", + Decimals: 18, + BlockTime: 0, + MinConfirmations: 0, + Blockchain: "Ethereum", + }, + Klaytn().Handle: { + ID: 10008217, + Handle: "klaytn", + Symbol: "KLAY", + Name: "Klaytn", + Decimals: 18, + BlockTime: 0, + MinConfirmations: 0, + Blockchain: "Ethereum", + }, + Metis().Handle: { + ID: 10001088, + Handle: "metis", + Symbol: "METIS", + Name: "Metis", + Decimals: 18, + BlockTime: 0, + MinConfirmations: 0, + Blockchain: "Ethereum", + }, + Moonriver().Handle: { + ID: 10001285, + Handle: "moonriver", + Symbol: "MOVR", + Name: "Moonriver", + Decimals: 18, + BlockTime: 0, + MinConfirmations: 0, + Blockchain: "Ethereum", + }, + Boba().Handle: { + ID: 10000288, + Handle: "boba", + Symbol: "BOBAETH", + Name: "Boba", + Decimals: 18, + BlockTime: 0, + MinConfirmations: 0, + Blockchain: "Ethereum", + }, } func Ethereum() Coin { @@ -2102,3 +2207,24 @@ func Cryptoorg() Coin { func Aptos() Coin { return Coins[APTOS] } + +func Moonbeam() Coin { + return Coins[MOONBEAM] +} + +func Klaytn() Coin { + return Coins[KLAYTN] +} + +func Metis() Coin { + return Coins[METIS] +} + +func Moonriver() Coin { + return Coins[MOONRIVER] +} + +func Boba() Coin { + return Coins[BOBA] +} + diff --git a/coin/coins.yml b/coin/coins.yml index 34414a8..f66be3d 100644 --- a/coin/coins.yml +++ b/coin/coins.yml @@ -629,3 +629,38 @@ name: Aptos decimals: 8 blockchain: Aptos + +- id: 10001284 + symbol: GLMR + handle: moonbeam + name: Moonbeam + decimals: 18 + blockchain: Ethereum + +- id: 10008217 + symbol: KLAY + handle: klaytn + name: Klaytn + decimals: 18 + blockchain: Ethereum + +- id: 10001088 + symbol: METIS + handle: metis + name: Metis + decimals: 18 + blockchain: Ethereum + +- id: 10001285 + symbol: MOVR + handle: moonriver + name: Moonriver + decimals: 18 + blockchain: Ethereum + +- id: 10000288 + symbol: BOBAETH + handle: boba + name: Boba + decimals: 18 + blockchain: Ethereum diff --git a/coin/models.go b/coin/models.go index 033cac6..8e98cb0 100644 --- a/coin/models.go +++ b/coin/models.go @@ -114,6 +114,16 @@ func GetCoinExploreURL(c Coin, tokenID, tokenType string) (string, error) { return fmt.Sprintf("https://www.oklink.com/en/okc/address/%s", tokenID), nil case APTOS: return "https://explorer.aptoslabs.com/", nil + case MOONBEAM: + return fmt.Sprintf("https://moonscan.io/token/%s", tokenID), nil + case KLAYTN: + return fmt.Sprintf("https://scope.klaytn.com/token/%s", tokenID), nil + case METIS: + return fmt.Sprintf("https://andromeda-explorer.metis.io/token/%s", tokenID), nil + case MOONRIVER: + return fmt.Sprintf("https://moonriver.moonscan.io/token/%s", tokenID), nil + case BOBA: + return fmt.Sprintf("https://bobascan.com/token/%s", tokenID), nil } return "", errors.New("no explorer for coin: " + c.Handle) diff --git a/coin/models_test.go b/coin/models_test.go index bf48676..dbe26a1 100644 --- a/coin/models_test.go +++ b/coin/models_test.go @@ -194,6 +194,56 @@ func TestGetCoinExploreURL(t *testing.T) { want: "https://www.oklink.com/en/okc/address/test", wantErr: false, }, + { + name: "Test Moonbeam", + args: args{ + addr: "test", + tokenType: "MOONBEAM", + chain: Moonbeam(), + }, + want: "https://moonscan.io/token/test", + wantErr: false, + }, + { + name: "Test Klaytn", + args: args{ + addr: "test", + tokenType: "KLAYTN", + chain: Klaytn(), + }, + want: "https://scope.klaytn.com/token/test", + wantErr: false, + }, + { + name: "Test Metis", + args: args{ + addr: "test", + tokenType: "METIS", + chain: Metis(), + }, + want: "https://andromeda-explorer.metis.io/token/test", + wantErr: false, + }, + { + name: "Test Moonriver", + args: args{ + addr: "test", + tokenType: "MOONRIVER", + chain: Moonriver(), + }, + want: "https://moonriver.moonscan.io/token/test", + wantErr: false, + }, + { + name: "Test Boba", + args: args{ + addr: "test", + tokenType: "BOBA", + chain: Boba(), + }, + want: "https://bobascan.com/token/test", + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -235,6 +285,11 @@ var evmCoinsTestSet = map[uint]struct{}{ EVMOS: {}, CELO: {}, OKC: {}, + MOONBEAM: {}, + KLAYTN: {}, + METIS: {}, + MOONRIVER: {}, + BOBA: {}, } // TestEvmCoinsList This test will automatically fail when new EVM chain is added to coins.yml diff --git a/types/chain.go b/types/chain.go index 5d97609..570f6d5 100644 --- a/types/chain.go +++ b/types/chain.go @@ -93,6 +93,16 @@ func GetChainFromAssetType(assetType string) (coin.Coin, error) { return coin.Okc(), nil case APTOS: return coin.Aptos(), nil + case MOONBEAM: + return coin.Moonbeam(), nil + case KLAYTN: + return coin.Klaytn(), nil + case METIS: + return coin.Metis(), nil + case MOONRIVER: + return coin.Moonriver(), nil + case BOBA: + return coin.Boba(), nil } return coin.Coin{}, errors.New("unknown asset type: " + assetType) diff --git a/types/chainid.go b/types/chainid.go index e8d3ab5..913adcf 100644 --- a/types/chainid.go +++ b/types/chainid.go @@ -9,4 +9,9 @@ const ( ChainIDGnosis = 100 ChainIDAvalanche = 43114 ChainIDFantom = 250 + ChainIDMoonbeam = 1284 + ChainIDKlaytn = 8217 + ChainIDMetis = 1088 + ChainIDMoonriver = 1285 + ChainIDBoba = 288 ) diff --git a/types/token.go b/types/token.go index 393b573..4f9386f 100644 --- a/types/token.go +++ b/types/token.go @@ -80,6 +80,11 @@ const ( EVMOS_ERC20 TokenType = "EVMOS_ERC20" KIP20 TokenType = "KIP20" APTOS TokenType = "APTOS" + MOONBEAM TokenType = "MOONBEAM" + KLAYTN TokenType = "KLAYTN" + METIS TokenType = "METIS" + MOONRIVER TokenType = "MOONRIVER" + BOBA TokenType = "BOBA" ) const ( @@ -148,6 +153,11 @@ func GetTokenTypes() []TokenType { EVMOS_ERC20, KIP20, APTOS, + MOONBEAM, + KLAYTN, + METIS, + MOONRIVER, + BOBA, } } @@ -257,7 +267,8 @@ func GetTokenVersion(tokenType string) (TokenVersion, error) { return TokenVersionV10, nil case RONIN, AURORA: return TokenVersionV11, nil - case ERC721, ERC1155, EOS, NEP5, VET, ONTOLOGY, THETA, TOMO, POA, OASIS, ALGORAND, KAVAERC20, METER, EVMOS_ERC20, KIP20: + case ERC721, ERC1155, EOS, NEP5, VET, ONTOLOGY, THETA, TOMO, POA, OASIS, ALGORAND, + KAVAERC20, METER, EVMOS_ERC20, KIP20, MOONBEAM, KLAYTN, METIS, MOONRIVER, BOBA: return TokenVersionUndefined, nil default: // This should not happen, as it is guarded by TestGetTokenVersionImplementEverySupportedTokenTypes @@ -327,6 +338,16 @@ func GetEthereumTokenTypeByIndex(coinIndex uint) (TokenType, error) { tokenType = EVMOS_ERC20 case coin.OKC: tokenType = KIP20 + case coin.MOONBEAM: + tokenType = MOONBEAM + case coin.KLAYTN: + tokenType = KLAYTN + case coin.METIS: + tokenType = METIS + case coin.MOONRIVER: + tokenType = MOONRIVER + case coin.BOBA: + tokenType = BOBA } if tokenType == "" { diff --git a/types/token_test.go b/types/token_test.go index cfdbd57..71d5b55 100644 --- a/types/token_test.go +++ b/types/token_test.go @@ -125,6 +125,31 @@ func TestGetEthereumTokenTypeByIndex(t *testing.T) { args: args{coinIndex: coin.ARBITRUM}, want: ARBITRUM, }, + { + name: "Moonbeam MOONBEAM", + args: args{coinIndex: coin.MOONBEAM}, + want: MOONBEAM, + }, + { + name: "Klaytn KLAYTN", + args: args{coinIndex: coin.KLAYTN}, + want: KLAYTN, + }, + { + name: "Metis METIS", + args: args{coinIndex: coin.METIS}, + want: METIS, + }, + { + name: "Moonriver MOONRIVER", + args: args{coinIndex: coin.MOONRIVER}, + want: MOONRIVER, + }, + { + name: "Boba BOBA", + args: args{coinIndex: coin.BOBA}, + want: BOBA, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { @@ -398,6 +423,36 @@ func TestGetTokenVersion(t *testing.T) { TokenVersionUndefined, nil, }, + { + "Moonbeam token version", + args{t: string(MOONBEAM)}, + TokenVersionUndefined, + nil, + }, + { + "Klaytn token version", + args{t: string(KLAYTN)}, + TokenVersionUndefined, + nil, + }, + { + "Metis token version", + args{t: string(METIS)}, + TokenVersionUndefined, + nil, + }, + { + "Moonriver token version", + args{t: string(MOONRIVER)}, + TokenVersionUndefined, + nil, + }, + { + "Boba token version", + args{t: string(BOBA)}, + TokenVersionUndefined, + nil, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {