Skip to content

Commit

Permalink
feat: add support for more Soroban tokens. (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat authored Jul 19, 2024
1 parent 008c2cb commit 2dcfe0c
Show file tree
Hide file tree
Showing 3 changed files with 267 additions and 0 deletions.
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Updated
- Give an alert when enabling hash signing in settings. (Ledger Stax and Ledger Flex)
- Add support for more Soroban tokens.
- Bug fixes.

## v5.4.1
Expand Down
66 changes: 66 additions & 0 deletions scripts/generate_token_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import requests

from stellar_sdk import Asset, Network, Address, utils
from stellar_sdk import xdr as stellar_xdr

LOBSTR_TOKEN_API_URL = "https://lobstr.co/api/v1/sep/assets/curated.json"
SOROSWAP_TOKEN_API_URL = (
"https://raw.githubusercontent.com/soroswap/token-list/main/tokenList.json"
)
STELLAR_EXPERT_TOKEN_API_URL = (
"https://api.stellar.expert/explorer/public/asset/?limit=50&order=desc&sort=rating"
)

lobstr_tokens = set()
soroswap_tokens = set()
stellar_expert_tokens = set()

resp = requests.get(LOBSTR_TOKEN_API_URL).json()
for record in resp["assets"]:
asset = Asset(record["code"], record["issuer"])
lobstr_tokens.add(asset)

resp = requests.get(SOROSWAP_TOKEN_API_URL).json()
for record in resp["assets"]:
asset = Asset(record["code"], record["issuer"])
soroswap_tokens.add(asset)

resp = requests.get(STELLAR_EXPERT_TOKEN_API_URL).json()
for record in resp["_embedded"]["records"]:
asset = record["asset"]
if len(asset.split("-")) == 1:
continue
else:
asset_code, asset_issuer = asset.split("-")[:2]
asset = Asset(asset_code, asset_issuer)
stellar_expert_tokens.add(asset)

# Find the common tokens
common_tokens = lobstr_tokens & soroswap_tokens & stellar_expert_tokens


def get_asset_contract_id(asset: Asset, network_passphrase: str) -> bytes:
"""Get the contract id of the wrapped token contract."""
network_id_hash = stellar_xdr.Hash(Network(network_passphrase).network_id())
data = stellar_xdr.HashIDPreimage(
stellar_xdr.EnvelopeType.ENVELOPE_TYPE_CONTRACT_ID,
contract_id=stellar_xdr.HashIDPreimageContractID(
network_id=network_id_hash,
contract_id_preimage=stellar_xdr.ContractIDPreimage(
stellar_xdr.ContractIDPreimageType.CONTRACT_ID_PREIMAGE_FROM_ASSET,
from_asset=asset.to_xdr_object(),
),
),
)
contract_id = utils.sha256(data.to_xdr_bytes())
return contract_id


def print_asset(asset):
contract_id = get_asset_contract_id(asset, Network.PUBLIC_NETWORK_PASSPHRASE)
print(f"// {Address.from_raw_contract(contract_id).address}")
print(f'{{{{{"".join([f"0x{x:02x}," for x in contract_id])}}}, "{asset.code}"}},')


for asset in common_tokens:
print_asset(asset)
200 changes: 200 additions & 0 deletions src/soroban_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ typedef struct {
char asset_name[MAX_TOKEN_NAME_LENGTH];
} soroban_token_t;

// This list is generated based on the data from scripts/gen_token_list.py
// Due to storage space limitations, on the NANO S we only support XLM and USDC.
static const soroban_token_t tokens[] = {
// CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA
{{
Expand All @@ -48,6 +50,204 @@ static const soroban_token_t tokens[] = {
},
"USDC",
},
#ifndef TARGET_NANOS
// CBVDRT5474OBUEXF5MJB3UGQ5CG7CKGCAH5M4RV5NBCDJUBZ5OXHJLOU
{{
0x6a, 0x38, 0xcf, 0xbc, 0xff, 0x1c, 0x1a, 0x12, 0xe5, 0xeb, 0x12,
0x1d, 0xd0, 0xd0, 0xe8, 0x8d, 0xf1, 0x28, 0xc2, 0x01, 0xfa, 0xce,
0x46, 0xbd, 0x68, 0x44, 0x34, 0xd0, 0x39, 0xeb, 0xae, 0x74,
},
"EURC"},
// CAIRIR3ITE2KNBWHRIAOBBZ2AHIKU5BVTKFTW5IYCOAENR4L5T2THGN6
{{
0x11, 0x14, 0x47, 0x68, 0x99, 0x34, 0xa6, 0x86, 0xc7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x88, 0x0b, 0x18, 0x55,
0x5a, 0xd7, 0x80, 0x15, 0x65, 0xa9, 0xdb, 0x2b, 0xa4, 0x98, 0x85,
0xb3, 0x7a, 0x2b, 0xd0, 0xc7, 0x9d, 0x74, 0xa2, 0x11, 0x19,
},
"FRED"},
// CCKCKCPHYVXQD4NECBFJTFSCU2AMSJGCNG4O6K4JVRE2BLPR7WNDBQIQ
{{
0x94, 0x25, 0x09, 0xe7, 0xc5, 0x6f, 0x01, 0xf1, 0xa4, 0x10, 0x4a,
0x99, 0x96, 0x42, 0xa6, 0x80, 0xc9, 0x24, 0xc2, 0x69, 0xb8, 0xef,
0x2b, 0x89, 0xac, 0x49, 0xa0, 0xad, 0xf1, 0xfd, 0x9a, 0x30,
},
"SHX"},
#endif
};

// get token name if by contract address
Expand Down

0 comments on commit 2dcfe0c

Please sign in to comment.