impermax-sdk 2.1.214 → 2.1.215
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/lib/offchain/account/lendingPool/offchainAccountCollateralV2.js +1 -1
- package/lib/offchain/lendingPool/offchainCollateralV2.js +5 -0
- package/lib/onchain/account/lendingPool/onchainAccountCollateralV2.js +3 -3
- package/lib/onchain/account/onchainAccountPoolToken.d.ts +7 -3
- package/lib/onchain/account/onchainAccountPoolToken.js +19 -8
- package/lib/onchain/impermaxFactory/lendingPool/onchainCollateralV2.js +6 -2
- package/package.json +1 -1
|
@@ -27,8 +27,8 @@ class OffchainAccountCollateralV2 extends offchainAccountPoolToken_1.default {
|
|
|
27
27
|
return parseFloat(collateralPosition.balance);
|
|
28
28
|
}
|
|
29
29
|
async getLiquidity() {
|
|
30
|
-
// todo check if growth factor works
|
|
31
30
|
console.log("Offchain `getAmount`: %s", await this.getAmount());
|
|
31
|
+
console.log("Offchain `getGrowthFactor`: %s", await this.getCollateral().getGrowthFactor());
|
|
32
32
|
return await this.getAmount() * await this.getCollateral().getGrowthFactor();
|
|
33
33
|
}
|
|
34
34
|
// Notice: createNewPositionObject is not needed for V2
|
|
@@ -45,6 +45,11 @@ class OffchainCollateralV2 extends offchainPoolToken_1.default {
|
|
|
45
45
|
const reserve1 = parseFloat(lendingPoolData.pair.reserve1);
|
|
46
46
|
const totalSupply = parseFloat(lendingPoolData.pair.totalSupply);
|
|
47
47
|
const exchangeRate = await this.getExchangeRate();
|
|
48
|
+
console.log("offchain exchangeRate", exchangeRate);
|
|
49
|
+
console.log("offchain reserve0", reserve0);
|
|
50
|
+
console.log("offchain reserve1", reserve1);
|
|
51
|
+
console.log("offchain totalSupply", totalSupply);
|
|
52
|
+
console.log("offchain k", Math.sqrt(reserve0 * reserve1) / totalSupply);
|
|
48
53
|
return Math.sqrt(reserve0 * reserve1) / totalSupply * exchangeRate;
|
|
49
54
|
}
|
|
50
55
|
//
|
|
@@ -31,9 +31,9 @@ class OnchainAccountCollateralV2 extends onchainAccountPoolToken_1.default {
|
|
|
31
31
|
this.collateralCache = {};
|
|
32
32
|
}
|
|
33
33
|
async getLiquidity() {
|
|
34
|
-
console.log("Onchain `
|
|
35
|
-
|
|
36
|
-
return await this.
|
|
34
|
+
console.log("Onchain `getTokens`: %s", await this.getTokens());
|
|
35
|
+
console.log("Offchain `getGrowthFactor`: %s", await this.getCollateral().getGrowthFactor());
|
|
36
|
+
return await this.getTokens() * await this.getCollateral().getGrowthFactor();
|
|
37
37
|
}
|
|
38
38
|
// Notice: createNewPositionObject is not needed for V2
|
|
39
39
|
async createPositionObject(lockStateChange = false) {
|
|
@@ -6,7 +6,8 @@ export default abstract class OnchainAccountPoolToken {
|
|
|
6
6
|
protected poolToken: OnchainPoolToken;
|
|
7
7
|
protected cache: {
|
|
8
8
|
availableBalance?: Promise<number>;
|
|
9
|
-
|
|
9
|
+
tokens?: Promise<number>;
|
|
10
|
+
amount?: Promise<number>;
|
|
10
11
|
};
|
|
11
12
|
getPoolToken: () => OnchainPoolToken;
|
|
12
13
|
abstract getAccount(): OnchainAccount;
|
|
@@ -23,8 +24,11 @@ export default abstract class OnchainAccountPoolToken {
|
|
|
23
24
|
private initializeAvailableBalance;
|
|
24
25
|
getAvailableBalance(): Promise<number>;
|
|
25
26
|
getAvailableBalanceUSD(): Promise<number>;
|
|
26
|
-
private
|
|
27
|
-
|
|
27
|
+
private initializeTokens;
|
|
28
|
+
getTokens(): Promise<number>;
|
|
29
|
+
private initializeAmount;
|
|
30
|
+
getAmount(): Promise<number>;
|
|
31
|
+
getDeposited: () => Promise<number>;
|
|
28
32
|
getDepositedUSD(): Promise<number>;
|
|
29
33
|
getMaxWithdrawable(): Promise<number>;
|
|
30
34
|
}
|
|
@@ -13,6 +13,7 @@ class OnchainAccountPoolToken {
|
|
|
13
13
|
this.getLiquidityBuffer = () => this.getAccount().getOnchain().liquidityBuffer;
|
|
14
14
|
this.getUiMargin = () => this.getAccount().getOnchain().uiMargin;
|
|
15
15
|
this.getTokenPriceAccurate = async () => (await this.poolToken.getOffchainPoolToken()).getTokenPriceAccurate();
|
|
16
|
+
this.getDeposited = this.getAmount;
|
|
16
17
|
}
|
|
17
18
|
cleanCache() {
|
|
18
19
|
this.cache = {};
|
|
@@ -36,17 +37,27 @@ class OnchainAccountPoolToken {
|
|
|
36
37
|
const tokenPrice = await this.getTokenPriceAccurate();
|
|
37
38
|
return availableBalance * tokenPrice;
|
|
38
39
|
}
|
|
39
|
-
//
|
|
40
|
-
async
|
|
40
|
+
// Tokens
|
|
41
|
+
async initializeTokens() {
|
|
41
42
|
const poolToken = await this.poolToken.getPoolToken();
|
|
42
|
-
const exchangeRate = await this.poolToken.getExchangeRate();
|
|
43
43
|
const balance = await poolToken.methods.balanceOf(this.getAccountAddress()).call();
|
|
44
|
-
return (await this.poolToken.normalize(balance))
|
|
44
|
+
return (await this.poolToken.normalize(balance));
|
|
45
|
+
}
|
|
46
|
+
async getTokens() {
|
|
47
|
+
if (!this.cache.tokens)
|
|
48
|
+
this.cache.tokens = this.initializeTokens();
|
|
49
|
+
return this.cache.tokens;
|
|
50
|
+
}
|
|
51
|
+
// Deposited
|
|
52
|
+
async initializeAmount() {
|
|
53
|
+
const exchangeRate = await this.poolToken.getExchangeRate();
|
|
54
|
+
const tokens = await this.getTokens();
|
|
55
|
+
return (await this.poolToken.normalize(tokens)) * exchangeRate;
|
|
45
56
|
}
|
|
46
|
-
async
|
|
47
|
-
if (!this.cache.
|
|
48
|
-
this.cache.
|
|
49
|
-
return this.cache.
|
|
57
|
+
async getAmount() {
|
|
58
|
+
if (!this.cache.amount)
|
|
59
|
+
this.cache.amount = this.initializeAmount();
|
|
60
|
+
return this.cache.amount;
|
|
50
61
|
}
|
|
51
62
|
async getDepositedUSD() {
|
|
52
63
|
const deposited = await this.getDeposited();
|
|
@@ -37,9 +37,13 @@ class OnchainCollateralV2 extends onchainPoolToken_1.default {
|
|
|
37
37
|
async getGrowthFactor() {
|
|
38
38
|
const [reserve0, reserve1] = await this.getLendingPool().getReserves();
|
|
39
39
|
const totalSupply = await this.getLendingPool().getLPTotalSupply();
|
|
40
|
-
const stakedLPExchangeRate = await this.getLendingPool().getStakedLPExchangeRate();
|
|
41
40
|
const exchangeRate = await this.getExchangeRate();
|
|
42
|
-
|
|
41
|
+
console.log("onchain exchangeRate", exchangeRate);
|
|
42
|
+
console.log("onchain reserve0", reserve0);
|
|
43
|
+
console.log("onchain reserve1", reserve1);
|
|
44
|
+
console.log("onchain totalSupply", totalSupply);
|
|
45
|
+
console.log("onchain k", Math.sqrt(reserve0 * reserve1) / totalSupply);
|
|
46
|
+
return Math.sqrt(reserve0 * reserve1) / totalSupply * exchangeRate;
|
|
43
47
|
}
|
|
44
48
|
}
|
|
45
49
|
exports.default = OnchainCollateralV2;
|