impermax-sdk 1.2.13 → 1.2.15
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.
|
@@ -4,7 +4,7 @@ exports.DEFAULT_ROUTER = exports.ROUTER = void 0;
|
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
exports.ROUTER = {
|
|
6
6
|
[types_1.Networks.Ropsten]: {
|
|
7
|
-
[types_1.Factory.V2V1]: '0xbFf4acF789297A8507Eb7493AE18EB2C3A3A9632'
|
|
7
|
+
[types_1.Factory.V2V1]: '0xbFf4acF789297A8507Eb7493AE18EB2C3A3A9632' // OLD ROUTER
|
|
8
8
|
},
|
|
9
9
|
[types_1.Networks.Mainnet]: {
|
|
10
10
|
[types_1.Factory.V2V1]: '0x6271c6D2Cf5072D769A16eD99C8D5F3272d44E4F'
|
|
@@ -9,6 +9,9 @@ export default abstract class OnchainPoolToken {
|
|
|
9
9
|
exchangeRate?: Promise<number>;
|
|
10
10
|
totalBalance?: Promise<number>;
|
|
11
11
|
};
|
|
12
|
+
protected lockedCache: {
|
|
13
|
+
exchangeRate?: Promise<number>;
|
|
14
|
+
};
|
|
12
15
|
cleanCache(): void;
|
|
13
16
|
abstract getOffchainPoolToken(): Promise<OffchainPoolToken>;
|
|
14
17
|
abstract getPoolTokenAddress(): Promise<Address>;
|
|
@@ -28,4 +31,5 @@ export default abstract class OnchainPoolToken {
|
|
|
28
31
|
getTotalBalanceUSD(): Promise<number>;
|
|
29
32
|
protected initializeExchangeRate(): Promise<number>;
|
|
30
33
|
getExchangeRate(): Promise<number>;
|
|
34
|
+
getLockedExchangeRate(): Promise<number>;
|
|
31
35
|
}
|
|
@@ -14,6 +14,8 @@ const ether_utils_1 = require("../utils/ether-utils");
|
|
|
14
14
|
class OnchainPoolToken {
|
|
15
15
|
constructor() {
|
|
16
16
|
this.cache = {};
|
|
17
|
+
// Cache that can't be erased
|
|
18
|
+
this.lockedCache = {};
|
|
17
19
|
}
|
|
18
20
|
cleanCache() {
|
|
19
21
|
this.cache = {};
|
|
@@ -67,7 +69,7 @@ class OnchainPoolToken {
|
|
|
67
69
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
70
|
if (!(0, utils_1.isValidNumber)(amount))
|
|
69
71
|
return null;
|
|
70
|
-
const exchangeRate = yield this.
|
|
72
|
+
const exchangeRate = yield this.getLockedExchangeRate();
|
|
71
73
|
return (0, ether_utils_1.decimalToBalance)(amount / exchangeRate, yield this.getDecimals());
|
|
72
74
|
});
|
|
73
75
|
}
|
|
@@ -75,7 +77,7 @@ class OnchainPoolToken {
|
|
|
75
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
76
78
|
if (!amount)
|
|
77
79
|
return null;
|
|
78
|
-
const exchangeRate = yield this.
|
|
80
|
+
const exchangeRate = yield this.getLockedExchangeRate();
|
|
79
81
|
return parseFloat(amount.toString()) * exchangeRate / Math.pow(10, yield this.getDecimals());
|
|
80
82
|
});
|
|
81
83
|
}
|
|
@@ -116,5 +118,12 @@ class OnchainPoolToken {
|
|
|
116
118
|
return this.cache.exchangeRate;
|
|
117
119
|
});
|
|
118
120
|
}
|
|
121
|
+
getLockedExchangeRate() {
|
|
122
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
if (!this.lockedCache.exchangeRate)
|
|
124
|
+
this.lockedCache.exchangeRate = this.getExchangeRate();
|
|
125
|
+
return this.lockedCache.exchangeRate;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
119
128
|
}
|
|
120
129
|
exports.default = OnchainPoolToken;
|