Skip to content

Commit

Permalink
support for aptos fungible assets (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
gipshtw authored Jan 20, 2025
1 parent 99382f8 commit 2df33ee
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
7 changes: 6 additions & 1 deletion coin/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ func GetCoinExploreURL(c Coin, tokenID, tokenType string) (string, error) {
case OKC:
return fmt.Sprintf("https://www.oklink.com/en/okc/address/%s", tokenID), nil
case APTOS:
return "https://explorer.aptoslabs.com/", nil
switch tokenType {
case "APTOSFA":
return fmt.Sprintf("https://explorer.aptoslabs.com/fungible_asset/%s?network=mainnet", tokenID), nil
default:
return fmt.Sprintf("https://explorer.aptoslabs.com/coin/%s?network=mainnet", tokenID), nil
}
case MOONBEAM:
return fmt.Sprintf("https://moonscan.io/token/%s", tokenID), nil
case KLAYTN:
Expand Down
20 changes: 20 additions & 0 deletions coin/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,26 @@ func TestGetCoinExploreURL(t *testing.T) {
want: "https://explorer.zklink.io/address/0xF573fA04A73d5AC442F3DEa8741317fEaA3cDeab",
wantErr: false,
},
{
name: "Test Aptos (legacy)",
args: args{
addr: "0xacd014e8bdf395fa8497b6d585b164547a9d45269377bdf67c96c541b7fec9ed::coin::T",
tokenType: "APTOS",
chain: Aptos(),
},
want: "https://explorer.aptoslabs.com/coin/0xacd014e8bdf395fa8497b6d585b164547a9d45269377bdf67c96c541b7fec9ed::coin::T?network=mainnet",
wantErr: false,
},
{
name: "Test Aptos (fungible asset)",
args: args{
addr: "0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b",
tokenType: "APTOSFA",
chain: Aptos(),
},
want: "https://explorer.aptoslabs.com/fungible_asset/0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b?network=mainnet",
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion types/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func GetChainFromAssetType(assetType string) (coin.Coin, error) {
return coin.Evmos(), nil
case KIP20:
return coin.Okc(), nil
case APTOS:
case APTOS, APTOSFA:
return coin.Aptos(), nil
case MOONBEAM:
return coin.Moonbeam(), nil
Expand Down
16 changes: 16 additions & 0 deletions types/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ func TestGetChainFromAssetType(t *testing.T) {
want: coin.Cfxevm(),
wantErr: false,
},
{
name: "Test APTOS (legacy)",
args: args{
type_: "APTOS",
},
want: coin.Aptos(),
wantErr: false,
},
{
name: "Test APTOSFA (fungible asset)",
args: args{
type_: "APTOSFA",
},
want: coin.Aptos(),
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
12 changes: 11 additions & 1 deletion types/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"strconv"
"strings"

"github.com/trustwallet/go-primitives/asset"
"github.com/trustwallet/go-primitives/coin"
Expand Down Expand Up @@ -88,6 +89,7 @@ const (
EVMOS_ERC20 TokenType = "EVMOS_ERC20"
KIP20 TokenType = "KIP20"
APTOS TokenType = "APTOS"
APTOSFA TokenType = "APTOSFA"
MOONBEAM TokenType = "MOONBEAM"
KLAYTN TokenType = "KAIA"
METIS TokenType = "METIS"
Expand Down Expand Up @@ -146,6 +148,7 @@ const (
TokenVersionV18 TokenVersion = 18
TokenVersionV19 TokenVersion = 19
TokenVersionV20 TokenVersion = 20
TokenVersionV21 TokenVersion = 21
TokenVersionUndefined TokenVersion = -1
)

Expand Down Expand Up @@ -211,6 +214,7 @@ func GetTokenTypes() []TokenType {
EVMOS_ERC20,
KIP20,
APTOS,
APTOSFA,
MOONBEAM,
KLAYTN,
METIS,
Expand Down Expand Up @@ -319,7 +323,11 @@ func GetTokenType(c uint, tokenID string) (string, bool) {
case coin.OKC:
return string(KIP20), true
case coin.APTOS:
return string(APTOS), true
// TODO: improve this
if strings.Contains(tokenID, "::") {
return string(APTOS), true
}
return string(APTOSFA), true
case coin.TON:
return string(JETTON), true
case coin.SUI:
Expand Down Expand Up @@ -428,6 +436,8 @@ func GetTokenVersion(tokenType string) (TokenVersion, error) {
case ERC721, ERC1155, EOS, NEP5, VET, ONTOLOGY, THETA, TOMO, POA, OASIS, ALGORAND, METER, EVMOS_ERC20,
KIP20, STRIDE, NEUTRON, FA2, CARDANO, NATIVEEVMOS, CRYPTOORG, COSMOS, OSMOSIS, STARGAZE:
return TokenVersionUndefined, nil
case APTOSFA:
return TokenVersionV21, nil
default:
// This should not happen, as it is guarded by TestGetTokenVersionImplementEverySupportedTokenTypes
return TokenVersionUndefined, fmt.Errorf("tokenType %s: %w", parsedTokenType, errTokenVersionNotImplemented)
Expand Down
8 changes: 7 additions & 1 deletion types/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,16 @@ func TestGetTokenType(t *testing.T) {
},
{
name: "Aptos",
args: args{coin.APTOS, ""},
args: args{coin.APTOS, "0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDT"},
want: string(APTOS),
wantBool: true,
},
{
name: "Aptos",
args: args{coin.APTOS, "0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b"},
want: string(APTOSFA),
wantBool: true,
},
{
name: "Jetton",
args: args{coin.TON, ""},
Expand Down

0 comments on commit 2df33ee

Please sign in to comment.