Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show Token2022 tokens #1482

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
14517e9
refactor balances
justinenerio Jun 3, 2024
b618d53
refactor fetching balances
justinenerio Jun 3, 2024
6c5bdac
fetch from token 2022 tokens
justinenerio Jun 3, 2024
1aa5305
Merge commit 'b618d535507b547cc6c9e3e4f8fa83adef3c9f0d' into fix-toke…
justinenerio Jun 3, 2024
b52632a
Merge commit '606a84fac3ccbe462ec9b4c1b5da690b3e376ce7' into fix-toke…
justinenerio Jun 4, 2024
9420543
added index and instructions
justinenerio Jun 27, 2024
18f1f10
add token program to ata
justinenerio Jun 28, 2024
7f6803e
upd TokenProgram ixs
justinenerio Jun 28, 2024
c5e4a48
move extension types
justinenerio Jun 28, 2024
cfcee35
added remaining token2022 ixs
justinenerio Jun 28, 2024
ac9ac95
upd parsed account
justinenerio Jun 29, 2024
d63c3d7
experimental
justinenerio Jun 29, 2024
9a6bc02
upd
justinenerio Jun 29, 2024
8b9b998
upd
justinenerio Jul 1, 2024
326f53d
Merge commit '7448e3aa2d1852a062b6707146687bb968ef6d0a' into fix-toke…
justinenerio Jul 1, 2024
0e8cdd3
Merge commit '8b9b998b93c2a90e7f3f5ef24aec75b56a917b94' into fix-toke…
justinenerio Jul 1, 2024
25a2a68
upd
justinenerio Jul 1, 2024
9c5efae
Merge branch 'master' into fix-token2022-list
justinenerio Jul 8, 2024
b3c684b
Merge branch 'master' into fix-token2022-list
justinenerio Jul 19, 2024
c0cae24
Merge branch 'master' into fix-token2022-list
justinenerio Aug 2, 2024
0002dba
Merge branch 'master' into fix-token2022-list
justinenerio Aug 12, 2024
cbcc142
Merge branch 'master' into fix-token2022-list
justinenerio Aug 15, 2024
9a388bb
Merge branch 'master' into fix-token2022-list
justinenerio Aug 16, 2024
dfb6f0e
Merge branch 'master' into fix-token2022-list
justinenerio Sep 3, 2024
6ac4cd6
Merge branch 'master' into fix-token2022-list
justinenerio Sep 11, 2024
9f96c60
Merge commit '6be502c4f2d56ead3df879f22dd84c6df40601c1' into fix-toke…
justinenerio Sep 13, 2024
c539a0f
Merge branch 'fix-token2022-list' of https://github.com/espresso-cash…
justinenerio Sep 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ class BalancesBloc extends Bloc<BalancesEvent, BalancesState>
) async {
try {
emit(const ProcessingState.processing());
final address = event.address;

final sol = await _solanaClient.getSolBalance(event.address);
final sol = await _solanaClient.getSolBalance(address);

final allAccounts = await _solanaClient.getSplAccounts(event.address);
final allAccounts = await _solanaClient.getSplAccounts(address);
final mainAccounts = await Future.wait<_MainTokenAccount?>(
allAccounts.map((programAccount) async {
final account = programAccount.account;
Expand All @@ -64,6 +65,16 @@ class BalancesBloc extends Bloc<BalancesEvent, BalancesState>
programAccount.pubkey,
a.info,
_tokens,
TokenProgramType.tokenProgram,
),
orElse: () async => null,
),
token2022: (parsed) => parsed.maybeMap(
account: (a) => _MainTokenAccount.create(
programAccount.pubkey,
a.info,
_tokens,
TokenProgramType.token2022Program,
),
orElse: () async => null,
),
Expand Down Expand Up @@ -111,10 +122,12 @@ class _MainTokenAccount {
String pubKey,
SplTokenAccountDataInfo info,
TokenList tokens,
TokenProgramType tokenProgramType,
) async {
final expectedPubKey = await findAssociatedTokenAddress(
owner: Ed25519HDPublicKey.fromBase58(info.owner),
mint: Ed25519HDPublicKey.fromBase58(info.mint),
tokenProgramType: tokenProgramType,
);

if (expectedPubKey.toBase58() != pubKey) return null;
Expand Down Expand Up @@ -153,12 +166,24 @@ extension on SolanaClient {
return CryptoAmount(value: lamports, cryptoCurrency: Currency.sol);
}

Future<Iterable<ProgramAccount>> getSplAccounts(String address) => rpcClient
.getTokenAccountsByOwner(
Future<Iterable<ProgramAccount>> getSplAccounts(String address) async {
final accounts = [
rpcClient.getTokenAccountsByOwner(
address,
const TokenAccountsFilter.byProgramId(TokenProgram.programId),
commitment: Commitment.confirmed,
encoding: Encoding.jsonParsed,
)
.value;
),
rpcClient.getTokenAccountsByOwner(
address,
const TokenAccountsFilter.byProgramId(Token2022Program.programId),
commitment: Commitment.confirmed,
encoding: Encoding.jsonParsed,
),
];

final results = await Future.wait(accounts);

return [...results[0].value, ...results[1].value];
}
}
Loading