1
1
import { type AnchorProvider } from "@coral-xyz/anchor" ;
2
- import { type AssetControllerAccount , type TrackerAccount } from "./types" ;
2
+ import { type AssetControllerAccount } from "./types" ;
3
3
import {
4
4
getAssetControllerPda ,
5
5
getAssetControllerProgram ,
6
- getTrackerAccountPda ,
7
6
} from "./utils" ;
8
7
import { GetProgramAccountsFilter , PublicKey } from "@solana/web3.js" ;
9
- import { getPolicyAccount , getPolicyEngineAccount , PolicyAccount , PolicyEngineAccount } from "../policy-engine" ;
10
- import { DataAccount , DataRegistryAccount , getDataAccountsWithFilter , getDataRegistryAccount } from "../data-registry" ;
11
- import { getIdentityAccount , getIdentityRegistryAccount , IdentityAccount , IdentityRegistryAccount } from "../identity-registry" ;
12
8
13
9
/**
14
10
* Retrieves a asset controller account associated with a specific asset mint.
@@ -65,112 +61,4 @@ export async function getAssetControllerAccountsWithFilter(
65
61
return assetAccounts . map ( ( account ) =>
66
62
assetProgram . coder . accounts . decode ( "AssetControllerAccount" , account . account . data )
67
63
) ;
68
- }
69
-
70
- /**
71
- * Retrieves a tracker account pda associated with a specific asset mint and owner.
72
- * @param assetMint - The string representation of the asset mint.
73
- * @param owner - The string representation of the owner's public key.
74
- * @returns A promise resolving to the fetched tracker account, or `undefined` if it doesn't exist.
75
- */
76
- export async function getTrackerAccount (
77
- assetMint : string ,
78
- owner : string ,
79
- provider : AnchorProvider
80
- ) : Promise < TrackerAccount | undefined > {
81
- const assetProgram = getAssetControllerProgram ( provider ) ;
82
- const trackerPda = getTrackerAccountPda ( assetMint , owner ) ;
83
- return assetProgram . account . trackerAccount
84
- . fetch ( trackerPda )
85
- . then ( ( account ) => account )
86
- . catch ( ( ) => undefined ) ;
87
- }
88
-
89
- export const TRACKER_ACCOUNT_ASSET_MINT_OFFSET = 9 ;
90
- export const TRACKER_ACCOUNT_OWNER_OFFSET = 41 ;
91
-
92
- /**
93
- * Retrieves all tracker accounts associated with a specific asset mint.
94
- * @param assetMint - The string representation of the asset mint.
95
- * @returns A promise resolving to the fetched tracker accounts, or `undefined` if it doesn't exist.
96
- */
97
- export async function getTrackerAccountsWithFilter (
98
- filter : Omit < AssetControllerDataFilter , "authority" | "delegate" > ,
99
- provider : AnchorProvider
100
- ) : Promise < TrackerAccount [ ] | undefined > {
101
- const { assetMint, owner } = filter ;
102
- const assetProgram = getAssetControllerProgram ( provider ) ;
103
- const filters : GetProgramAccountsFilter [ ] = [ ] ;
104
- if ( assetMint ) {
105
- filters . push ( { memcmp : { offset : TRACKER_ACCOUNT_ASSET_MINT_OFFSET , bytes : new PublicKey ( assetMint ) . toBase58 ( ) } } ) ;
106
- }
107
- if ( owner ) {
108
- filters . push ( { memcmp : { offset : TRACKER_ACCOUNT_OWNER_OFFSET , bytes : new PublicKey ( owner ) . toBase58 ( ) } } ) ;
109
- }
110
- const trackerAccounts = await provider . connection . getProgramAccounts ( assetProgram . programId , {
111
- filters,
112
- } ) ;
113
- return trackerAccounts . map ( ( account ) =>
114
- assetProgram . coder . accounts . decode ( "TrackerAccount" , account . account . data )
115
- ) ;
116
- }
117
-
118
- export interface RwaAccounts {
119
- assetMint : string ;
120
- assetController ?: AssetControllerAccount ;
121
- tracker ?: TrackerAccount ;
122
- policyEngine ?: PolicyEngineAccount ;
123
- policyAccount ?: PolicyAccount ;
124
- dataRegistry ?: DataRegistryAccount ;
125
- dataAccounts ?: DataAccount [ ] ;
126
- identityRegistry ?: IdentityRegistryAccount ;
127
- identity ?: IdentityAccount ;
128
- }
129
-
130
-
131
- /**
132
- * Retrieves all RWA accounts associated with a specific asset mint.
133
- * @param assetMints - The string representation of the asset mint.
134
- * @returns A promise resolving to the fetched RWA accounts, or `undefined` if it doesn't exist.
135
- */
136
- export async function getRwaAccountsWithMints (
137
- assetMints : string [ ] ,
138
- provider : AnchorProvider ,
139
- owner ?: string ,
140
- ) : Promise < RwaAccounts [ ] > {
141
- const accounts : RwaAccounts [ ] = [ ] ;
142
- for ( const assetMint of assetMints ) {
143
- const assetController = getAssetControllerAccount ( assetMint , provider ) ;
144
- const tracker = owner ? getTrackerAccount ( assetMint , owner , provider ) : undefined ;
145
- const policyEngine = getPolicyEngineAccount ( assetMint , provider ) ;
146
- const policyAccount = getPolicyAccount ( assetMint , provider ) ;
147
- const dataRegistry = getDataRegistryAccount ( assetMint , provider ) ;
148
- const dataAccounts = getDataAccountsWithFilter ( { assetMint } , provider ) ;
149
- const identityRegistry = getIdentityRegistryAccount ( assetMint , provider ) ;
150
- const identity = owner ? getIdentityAccount ( assetMint , owner , provider ) : undefined ;
151
-
152
- const [ resolvedAssetController , resolvedTracker , resolvedPolicyEngine , resolvedPolicyAccount , resolvedDataRegistry , resolvedDataAccounts , resolvedIdentityRegistry , resolvedIdentity ] = await Promise . all ( [
153
- assetController ,
154
- tracker ,
155
- policyEngine ,
156
- policyAccount ,
157
- dataRegistry ,
158
- dataAccounts ,
159
- identityRegistry ,
160
- identity
161
- ] ) ;
162
-
163
- accounts . push ( {
164
- assetMint,
165
- assetController : resolvedAssetController ,
166
- tracker : resolvedTracker ,
167
- policyEngine : resolvedPolicyEngine ,
168
- policyAccount : resolvedPolicyAccount ,
169
- dataRegistry : resolvedDataRegistry ,
170
- dataAccounts : resolvedDataAccounts ,
171
- identityRegistry : resolvedIdentityRegistry ,
172
- identity : resolvedIdentity ,
173
- } ) ;
174
- }
175
- return accounts ;
176
64
}
0 commit comments