@d8x/perpetuals-sdk 0.0.21 → 0.0.22

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/src/utils.ts CHANGED
@@ -75,6 +75,42 @@ export function fromBytes4HexString(s: string): string {
75
75
  return res;
76
76
  }
77
77
 
78
+ /**
79
+ *
80
+ * @param {string} s string representing a hex-number ("0x...")
81
+ * @param {Object} mapping list of symbol and clean symbol pairs, e.g. [{symbol: "MATIC", cleanSymbol: "MATC"}, ...]
82
+ * @returns {string} user friendly currency symbol, e.g. "MATIC"
83
+ */
84
+ export function contractSymbolToSymbol(s: string, mapping: Array<{ [key: string]: string }>): string | undefined {
85
+ s = fromBytes4HexString(s);
86
+ for (let pair of mapping) {
87
+ if (pair.cleanSymbol == s) {
88
+ return pair.symbol;
89
+ }
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Converts symbol or symbol combination into long format
95
+ * @param {string} s symbol, e.g., USDC-MATC-USDC, MATC, USDC, ...
96
+ * @param {Object} mapping list of symbol and clean symbol pairs, e.g. [{symbol: "MATIC", cleanSymbol: "MATC"}, ...]
97
+ * @returns {string} long format e.g. MATIC. if not found the element is ""
98
+ */
99
+ export function symbol4BToLongSymbol(s: string, mapping: Array<{ [key: string]: string }>): string {
100
+ let ccy = s.split("-");
101
+ let longCCY = "";
102
+ for (let k = 0; k < ccy.length; k++) {
103
+ let sym = ccy[k];
104
+ for (let pair of mapping) {
105
+ if (pair.cleanSymbol == sym) {
106
+ longCCY = longCCY + "-" + pair.symbol;
107
+ break;
108
+ }
109
+ }
110
+ }
111
+ return longCCY.substring(1);
112
+ }
113
+
78
114
  export function combineFlags(f1: BigNumber, f2: BigNumber): BigNumber {
79
115
  return BigNumber.from(parseInt(f1.toString()) | parseInt(f2.toString()));
80
116
  }