1
- import { type Accounts , Asset , AssetLocation , AssetSourceRelation , Chains } from '@/types' ;
2
- import { flatObject } from '@/utils.ts' ;
1
+ import { type Accounts , Asset , AssetSourceRelation , Chains } from '@/types' ;
3
2
import { bridge } from '@polkadot-api/descriptors' ;
4
3
import { createClient } from 'polkadot-api' ;
5
4
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat' ;
6
5
import { getWsProvider } from 'polkadot-api/ws-provider/web' ;
7
6
import { BaseChainManager } from './BaseManager' ;
8
7
9
8
export class BridgerHubManagaer extends BaseChainManager {
9
+ private chain = Chains . BridgeHub ;
10
+
10
11
connect ( ) {
11
- const client = createClient ( withPolkadotSdkCompat ( getWsProvider ( this . getChainType ( ) ) ) ) ;
12
- const api = client . getTypedApi ( bridge ) ;
12
+ const provider = withPolkadotSdkCompat ( getWsProvider ( this . chain ) ) ;
13
+ const client = createClient ( provider ) ;
13
14
14
15
// Verify connection
15
- if ( ! client || ! api ) {
16
- throw new Error ( `Failed to connect to ${ this . getChainType ( ) } ` ) ;
16
+ if ( ! client ) {
17
+ throw new Error ( `Failed to connect to ${ this . chain } ` ) ;
17
18
}
18
19
19
- this . clients . set ( this . getChainType ( ) , { client, api } ) ;
20
+ const api = client . getTypedApi ( bridge ) ;
21
+ this . clients . set ( this . chain , { client, api } ) ;
20
22
}
21
23
22
24
disconnect ( ) {
23
- this . clients . get ( Chains . BridgeHub ) ?. client . destroy ( ) ;
25
+ this . clients . get ( this . chain ) ?. client . destroy ( ) ;
24
26
}
25
27
26
28
getChainType ( ) {
27
- return Chains . BridgeHub ;
29
+ return this . chain ;
28
30
}
29
31
30
32
getXcmPallet ( ) {
31
- const api = this . getApi ( Chains . BridgeHub ) ;
33
+ const api = this . getApi ( this . chain ) ;
32
34
return api . tx . PolkadotXcm ;
33
35
}
34
36
@@ -50,19 +52,9 @@ export class BridgerHubManagaer extends BaseChainManager {
50
52
}
51
53
}
52
54
55
+ // Note: On BridgeHub, there should be no balance for any asset.
56
+ // There is DOT, but we are not tracking it.
53
57
async getAssetBalanceOf ( account : Accounts , asset : Asset ) : Promise < bigint > {
54
- const api = this . getApi ( Chains . BridgeHub ) ;
55
- // const asset_source_relation = this.getAssetSourceRelation(asset);
56
- // const asset_location = AssetLocation(asset, asset_source_relation).value;
57
- // const account_balances_result = await api.apis.FungiblesApi.query_account_balances(account);
58
- // if (account_balances_result.success === true && account_balances_result.value.type === 'V4') {
59
- // const assets = account_balances_result.value.value;
60
- // for (const asset of assets) {
61
- // if (Bun.deepEquals(flatObject(asset.id), flatObject(asset_location))) {
62
- // return asset.fun.value as bigint;
63
- // }
64
- // }
65
- // }
66
58
return 0n ;
67
59
}
68
60
0 commit comments