@yellow-org/sdk 1.0.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +999 -0
- package/dist/abis/generated.d.ts +4300 -0
- package/dist/abis/generated.js +1 -0
- package/dist/app/index.d.ts +2 -0
- package/dist/app/index.js +2 -0
- package/dist/app/packing.d.ts +7 -0
- package/dist/app/packing.js +111 -0
- package/dist/app/types.d.ts +91 -0
- package/dist/app/types.js +42 -0
- package/dist/asset_store.d.ts +13 -0
- package/dist/asset_store.js +121 -0
- package/dist/blockchain/evm/channel_hub_abi.d.ts +4284 -0
- package/dist/blockchain/evm/channel_hub_abi.js +5475 -0
- package/dist/blockchain/evm/client.d.ts +46 -0
- package/dist/blockchain/evm/client.js +428 -0
- package/dist/blockchain/evm/erc20.d.ts +13 -0
- package/dist/blockchain/evm/erc20.js +54 -0
- package/dist/blockchain/evm/erc20_abi.d.ts +144 -0
- package/dist/blockchain/evm/erc20_abi.js +96 -0
- package/dist/blockchain/evm/index.d.ts +6 -0
- package/dist/blockchain/evm/index.js +6 -0
- package/dist/blockchain/evm/interface.d.ts +10 -0
- package/dist/blockchain/evm/interface.js +1 -0
- package/dist/blockchain/evm/types.d.ts +27 -0
- package/dist/blockchain/evm/types.js +1 -0
- package/dist/blockchain/evm/utils.d.ts +9 -0
- package/dist/blockchain/evm/utils.js +129 -0
- package/dist/blockchain/index.d.ts +1 -0
- package/dist/blockchain/index.js +1 -0
- package/dist/client.d.ts +99 -0
- package/dist/client.js +720 -0
- package/dist/config.d.ts +12 -0
- package/dist/config.js +28 -0
- package/dist/core/event.d.ts +29 -0
- package/dist/core/event.js +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.js +6 -0
- package/dist/core/interface.d.ts +53 -0
- package/dist/core/interface.js +1 -0
- package/dist/core/state.d.ts +21 -0
- package/dist/core/state.js +267 -0
- package/dist/core/state_packer.d.ts +13 -0
- package/dist/core/state_packer.js +98 -0
- package/dist/core/types.d.ts +203 -0
- package/dist/core/types.js +220 -0
- package/dist/core/utils.d.ts +16 -0
- package/dist/core/utils.js +181 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/rpc/api.d.ts +181 -0
- package/dist/rpc/api.js +1 -0
- package/dist/rpc/client.d.ts +36 -0
- package/dist/rpc/client.js +102 -0
- package/dist/rpc/dialer.d.ts +30 -0
- package/dist/rpc/dialer.js +146 -0
- package/dist/rpc/error.d.ts +18 -0
- package/dist/rpc/error.js +27 -0
- package/dist/rpc/index.d.ts +7 -0
- package/dist/rpc/index.js +7 -0
- package/dist/rpc/message.d.ts +25 -0
- package/dist/rpc/message.js +102 -0
- package/dist/rpc/methods.d.ts +30 -0
- package/dist/rpc/methods.js +27 -0
- package/dist/rpc/types.d.ts +101 -0
- package/dist/rpc/types.js +1 -0
- package/dist/signers.d.ts +48 -0
- package/dist/signers.js +96 -0
- package/dist/utils/sign.d.ts +2 -0
- package/dist/utils/sign.js +8 -0
- package/dist/utils.d.ts +42 -0
- package/dist/utils.js +226 -0
- package/package.json +89 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
export class ClientAssetStore {
|
|
2
|
+
constructor(getAssetsFn) {
|
|
3
|
+
this.cache = new Map();
|
|
4
|
+
this.getAssetsFn = getAssetsFn;
|
|
5
|
+
}
|
|
6
|
+
async getAssetDecimals(asset) {
|
|
7
|
+
const cached = this.cache.get(asset.toLowerCase());
|
|
8
|
+
if (cached) {
|
|
9
|
+
return cached.decimals;
|
|
10
|
+
}
|
|
11
|
+
const assets = await this.getAssetsFn();
|
|
12
|
+
for (const a of assets) {
|
|
13
|
+
this.cache.set(a.symbol.toLowerCase(), a);
|
|
14
|
+
if (a.symbol.toLowerCase() === asset.toLowerCase()) {
|
|
15
|
+
return a.decimals;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
throw new Error(`asset ${asset} not found`);
|
|
19
|
+
}
|
|
20
|
+
async getTokenDecimals(blockchainId, tokenAddress) {
|
|
21
|
+
if (this.cache.size === 0) {
|
|
22
|
+
const assets = await this.getAssetsFn();
|
|
23
|
+
for (const a of assets) {
|
|
24
|
+
this.cache.set(a.symbol.toLowerCase(), a);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const tokenAddrLower = tokenAddress.toLowerCase();
|
|
28
|
+
for (const asset of this.cache.values()) {
|
|
29
|
+
for (const token of asset.tokens) {
|
|
30
|
+
if (token.blockchainId === blockchainId &&
|
|
31
|
+
token.address.toLowerCase() === tokenAddrLower) {
|
|
32
|
+
return token.decimals;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`token ${tokenAddress} on blockchain ${blockchainId} not found`);
|
|
37
|
+
}
|
|
38
|
+
async getTokenAddress(asset, blockchainId) {
|
|
39
|
+
if (this.cache.size === 0) {
|
|
40
|
+
const assets = await this.getAssetsFn();
|
|
41
|
+
for (const a of assets) {
|
|
42
|
+
this.cache.set(a.symbol.toLowerCase(), a);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const assetLower = asset.toLowerCase();
|
|
46
|
+
for (const a of this.cache.values()) {
|
|
47
|
+
if (a.symbol.toLowerCase() === assetLower) {
|
|
48
|
+
for (const token of a.tokens) {
|
|
49
|
+
if (token.blockchainId === blockchainId) {
|
|
50
|
+
return token.address;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
throw new Error(`asset ${asset} not available on blockchain ${blockchainId}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const assets = await this.getAssetsFn();
|
|
57
|
+
for (const a of assets) {
|
|
58
|
+
this.cache.set(a.symbol.toLowerCase(), a);
|
|
59
|
+
if (a.symbol.toLowerCase() === assetLower) {
|
|
60
|
+
for (const token of a.tokens) {
|
|
61
|
+
if (token.blockchainId === blockchainId) {
|
|
62
|
+
return token.address;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
throw new Error(`asset ${asset} not available on blockchain ${blockchainId}`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
throw new Error(`asset ${asset} not found`);
|
|
69
|
+
}
|
|
70
|
+
async assetExistsOnBlockchain(blockchainId, asset) {
|
|
71
|
+
const assetLower = asset.toLowerCase();
|
|
72
|
+
for (const a of this.cache.values()) {
|
|
73
|
+
if (a.symbol.toLowerCase() === assetLower) {
|
|
74
|
+
for (const token of a.tokens) {
|
|
75
|
+
if (token.blockchainId === blockchainId) {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const assets = await this.getAssetsFn();
|
|
83
|
+
for (const a of assets) {
|
|
84
|
+
this.cache.set(a.symbol.toLowerCase(), a);
|
|
85
|
+
if (a.symbol.toLowerCase() === assetLower) {
|
|
86
|
+
for (const token of a.tokens) {
|
|
87
|
+
if (token.blockchainId === blockchainId) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
async getSuggestedBlockchainId(asset) {
|
|
97
|
+
const key = asset.toLowerCase();
|
|
98
|
+
const cached = this.cache.get(key);
|
|
99
|
+
if (cached) {
|
|
100
|
+
if (cached.suggestedBlockchainId === 0n) {
|
|
101
|
+
throw new Error(`no suggested blockchain ID for asset ${asset}`);
|
|
102
|
+
}
|
|
103
|
+
return cached.suggestedBlockchainId;
|
|
104
|
+
}
|
|
105
|
+
const assets = await this.getAssetsFn();
|
|
106
|
+
for (const a of assets) {
|
|
107
|
+
this.cache.set(a.symbol.toLowerCase(), a);
|
|
108
|
+
}
|
|
109
|
+
const fetched = this.cache.get(key);
|
|
110
|
+
if (fetched) {
|
|
111
|
+
if (fetched.suggestedBlockchainId === 0n) {
|
|
112
|
+
throw new Error(`no suggested blockchain ID for asset ${asset}`);
|
|
113
|
+
}
|
|
114
|
+
return fetched.suggestedBlockchainId;
|
|
115
|
+
}
|
|
116
|
+
throw new Error(`asset ${asset} not found`);
|
|
117
|
+
}
|
|
118
|
+
clearCache() {
|
|
119
|
+
this.cache.clear();
|
|
120
|
+
}
|
|
121
|
+
}
|