damm-sdk 1.1.31-alpha.31 → 1.1.31-alpha.32
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/dist/index.cjs +6551 -5002
- package/dist/index.cjs.map +32 -13
- package/dist/index.js +46852 -40275
- package/dist/index.js.map +120 -71
- package/dist/lib/addresses.d.ts +1 -0
- package/dist/lib/addresses.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/lib/addresses.ts +42 -0
package/dist/lib/addresses.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../src/lib/addresses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAwBpC,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAuBvE"}
|
|
1
|
+
{"version":3,"file":"addresses.d.ts","sourceRoot":"","sources":["../../src/lib/addresses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAwBpC,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAuBvE;AA0BD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAgB9E"}
|
package/package.json
CHANGED
package/src/lib/addresses.ts
CHANGED
|
@@ -46,3 +46,45 @@ export function getAddressOrThrow(chainId: number, key: string): Address {
|
|
|
46
46
|
|
|
47
47
|
return current as Address;
|
|
48
48
|
}
|
|
49
|
+
|
|
50
|
+
function findAddressPath(obj: any, targetAddress: string, currentPath: string[] = []): string[] | null {
|
|
51
|
+
if (typeof obj === "string") {
|
|
52
|
+
// Normalize addresses for comparison (case-insensitive)
|
|
53
|
+
if (obj.toLowerCase() === targetAddress.toLowerCase()) {
|
|
54
|
+
return currentPath;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (typeof obj !== "object" || obj === null) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
64
|
+
const newPath = [...currentPath, key];
|
|
65
|
+
const result = findAddressPath(value, targetAddress, newPath);
|
|
66
|
+
if (result !== null) {
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function getAddressNameOrThrow(chainId: number, address: string): string {
|
|
75
|
+
const chainName = chainIdToName[chainId];
|
|
76
|
+
if (!chainName) {
|
|
77
|
+
throw new Error(`DAMM-sdk: Unsupported chainId: ${chainId}`);
|
|
78
|
+
}
|
|
79
|
+
const chainContracts: any = (contractsRegistry as any)[chainName];
|
|
80
|
+
if (!chainContracts) {
|
|
81
|
+
throw new Error(`DAMM-sdk: No contracts found for chainId: ${chainId} (${chainName})`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const path = findAddressPath(chainContracts, address);
|
|
85
|
+
if (path === null) {
|
|
86
|
+
throw new Error(`DAMM-sdk: Address "${address}" not found for chainId ${chainId} (${chainName})`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return path.join(".");
|
|
90
|
+
}
|