@defisaver/positions-sdk 0.0.13 → 0.0.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.
- package/cjs/aaveV3/index.js +14 -8
- package/esm/aaveV3/index.js +14 -8
- package/package.json +2 -2
- package/src/aaveV3/index.ts +17 -8
- package/yarn-error.log +0 -64
package/cjs/aaveV3/index.js
CHANGED
|
@@ -137,10 +137,22 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
137
137
|
let borrowCap = tokenMarket.borrowCap;
|
|
138
138
|
let discountRateOnBorrow = '0';
|
|
139
139
|
if (nativeAsset && facilitatorsList && discountRate && minDiscountTokenBalance && minGhoBalanceForDiscount && ghoDiscountedPerDiscountToken) {
|
|
140
|
-
|
|
140
|
+
const facilitatorBucket = yield ghoContract.methods.getFacilitatorBucket(facilitatorsList[0]).call();
|
|
141
|
+
const availableFacilitatorCap = (0, tokens_1.assetAmountInEth)(new decimal_js_1.default(facilitatorBucket[0]).sub(facilitatorBucket[1]).toString(), 'GHO');
|
|
142
|
+
borrowCap = decimal_js_1.default.min(borrowCap, availableFacilitatorCap).toString();
|
|
141
143
|
discountRateOnBorrow = (0, exports.aaveV3CalculateDiscountRate)(tokenMarket.totalBorrow.toString(), '3160881469228662060510133', // stkAAVE total supply
|
|
142
144
|
discountRate, minDiscountTokenBalance, minGhoBalanceForDiscount, ghoDiscountedPerDiscountToken);
|
|
143
145
|
}
|
|
146
|
+
let marketLiquidity = nativeAsset
|
|
147
|
+
? (0, tokens_1.assetAmountInEth)(new decimal_js_1.default((0, tokens_1.assetAmountInWei)(borrowCap.toString(), 'GHO'))
|
|
148
|
+
.sub(tokenMarket.totalBorrow.toString())
|
|
149
|
+
.toString(), symbol)
|
|
150
|
+
: (0, tokens_1.assetAmountInEth)(new decimal_js_1.default(tokenMarket.totalSupply.toString())
|
|
151
|
+
.sub(tokenMarket.totalBorrow.toString())
|
|
152
|
+
.toString(), symbol);
|
|
153
|
+
if (new decimal_js_1.default(marketLiquidity).lt(0)) {
|
|
154
|
+
marketLiquidity = '0';
|
|
155
|
+
}
|
|
144
156
|
return (Object.assign(Object.assign({ nativeAsset }, (0, utils_1.addToObjectIf)(nativeAsset, {
|
|
145
157
|
discountData: {
|
|
146
158
|
ghoDiscountedPerDiscountToken,
|
|
@@ -148,13 +160,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
148
160
|
minDiscountTokenBalance,
|
|
149
161
|
minGhoBalanceForDiscount,
|
|
150
162
|
},
|
|
151
|
-
})), { symbol, isIsolated: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).gt(0), debtCeilingForIsolationMode: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).div(100).toString(), isSiloed: tokenMarket.isSiloedForBorrowing, eModeCategory: +tokenMarket.emodeCategory, isolationModeTotalDebt: new decimal_js_1.default(tokenMarket.isolationModeTotalDebt).div(100).toString(), assetId: Number(tokenMarket.assetId), underlyingTokenAddress: tokenMarket.underlyingTokenAddress, supplyRate: new decimal_js_1.default(tokenMarket.supplyRate.toString()).div(1e25).toString(), borrowRate: new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).toString(), borrowRateDiscounted: nativeAsset ? new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).mul(1 - parseFloat(discountRateOnBorrow)).toString() : '0', borrowRateStable: new decimal_js_1.default(tokenMarket.borrowRateStable.toString()).div(1e25).toString(), collateralFactor: new decimal_js_1.default(tokenMarket.collateralFactor.toString()).div(10000).toString(), liquidationRatio: new decimal_js_1.default(tokenMarket.liquidationRatio.toString()).div(10000).toString(), marketLiquidity:
|
|
152
|
-
? (0, tokens_1.assetAmountInEth)(new decimal_js_1.default((0, tokens_1.assetAmountInWei)(borrowCap.toString(), 'GHO'))
|
|
153
|
-
.sub(tokenMarket.totalBorrow.toString())
|
|
154
|
-
.toString(), symbol)
|
|
155
|
-
: (0, tokens_1.assetAmountInEth)(new decimal_js_1.default(tokenMarket.totalSupply.toString())
|
|
156
|
-
.sub(tokenMarket.totalBorrow.toString())
|
|
157
|
-
.toString(), symbol), utilization: new decimal_js_1.default(tokenMarket.totalBorrow.toString())
|
|
163
|
+
})), { symbol, isIsolated: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).gt(0), debtCeilingForIsolationMode: new decimal_js_1.default(tokenMarket.debtCeilingForIsolationMode).div(100).toString(), isSiloed: tokenMarket.isSiloedForBorrowing, eModeCategory: +tokenMarket.emodeCategory, isolationModeTotalDebt: new decimal_js_1.default(tokenMarket.isolationModeTotalDebt).div(100).toString(), assetId: Number(tokenMarket.assetId), underlyingTokenAddress: tokenMarket.underlyingTokenAddress, supplyRate: new decimal_js_1.default(tokenMarket.supplyRate.toString()).div(1e25).toString(), borrowRate: new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).toString(), borrowRateDiscounted: nativeAsset ? new decimal_js_1.default(tokenMarket.borrowRateVariable.toString()).div(1e25).mul(1 - parseFloat(discountRateOnBorrow)).toString() : '0', borrowRateStable: new decimal_js_1.default(tokenMarket.borrowRateStable.toString()).div(1e25).toString(), collateralFactor: new decimal_js_1.default(tokenMarket.collateralFactor.toString()).div(10000).toString(), liquidationRatio: new decimal_js_1.default(tokenMarket.liquidationRatio.toString()).div(10000).toString(), marketLiquidity, utilization: new decimal_js_1.default(tokenMarket.totalBorrow.toString())
|
|
158
164
|
.div(new decimal_js_1.default(tokenMarket.totalSupply.toString()))
|
|
159
165
|
.times(100)
|
|
160
166
|
.toString(), usageAsCollateralEnabled: tokenMarket.usageAsCollateralEnabled, supplyCap: tokenMarket.supplyCap, borrowCap, totalSupply: (0, tokens_1.assetAmountInEth)(tokenMarket.totalSupply.toString(), symbol), isInactive: !tokenMarket.isActive, isFrozen: tokenMarket.isFrozen, isPaused: tokenMarket.isPaused, canBeBorrowed: tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen && tokenMarket.borrowingEnabled && isBorrowAllowed, canBeSupplied: !nativeAsset && tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen, canBeWithdrawn: tokenMarket.isActive && !tokenMarket.isPaused, canBePayBacked: tokenMarket.isActive && !tokenMarket.isPaused, disabledStableBorrowing: !tokenMarket.stableBorrowRateEnabled, totalBorrow: (0, tokens_1.assetAmountInEth)(tokenMarket.totalBorrow.toString(), symbol), totalBorrowVar: (0, tokens_1.assetAmountInEth)(tokenMarket.totalBorrowVar.toString(), symbol), price: new decimal_js_1.default(tokenMarket.price.toString()).div(1e8).toString(), isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled, isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled, eModeCategoryData: {
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -128,10 +128,22 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
128
128
|
let borrowCap = tokenMarket.borrowCap;
|
|
129
129
|
let discountRateOnBorrow = '0';
|
|
130
130
|
if (nativeAsset && facilitatorsList && discountRate && minDiscountTokenBalance && minGhoBalanceForDiscount && ghoDiscountedPerDiscountToken) {
|
|
131
|
-
|
|
131
|
+
const facilitatorBucket = yield ghoContract.methods.getFacilitatorBucket(facilitatorsList[0]).call();
|
|
132
|
+
const availableFacilitatorCap = assetAmountInEth(new Dec(facilitatorBucket[0]).sub(facilitatorBucket[1]).toString(), 'GHO');
|
|
133
|
+
borrowCap = Dec.min(borrowCap, availableFacilitatorCap).toString();
|
|
132
134
|
discountRateOnBorrow = aaveV3CalculateDiscountRate(tokenMarket.totalBorrow.toString(), '3160881469228662060510133', // stkAAVE total supply
|
|
133
135
|
discountRate, minDiscountTokenBalance, minGhoBalanceForDiscount, ghoDiscountedPerDiscountToken);
|
|
134
136
|
}
|
|
137
|
+
let marketLiquidity = nativeAsset
|
|
138
|
+
? assetAmountInEth(new Dec(assetAmountInWei(borrowCap.toString(), 'GHO'))
|
|
139
|
+
.sub(tokenMarket.totalBorrow.toString())
|
|
140
|
+
.toString(), symbol)
|
|
141
|
+
: assetAmountInEth(new Dec(tokenMarket.totalSupply.toString())
|
|
142
|
+
.sub(tokenMarket.totalBorrow.toString())
|
|
143
|
+
.toString(), symbol);
|
|
144
|
+
if (new Dec(marketLiquidity).lt(0)) {
|
|
145
|
+
marketLiquidity = '0';
|
|
146
|
+
}
|
|
135
147
|
return (Object.assign(Object.assign({ nativeAsset }, addToObjectIf(nativeAsset, {
|
|
136
148
|
discountData: {
|
|
137
149
|
ghoDiscountedPerDiscountToken,
|
|
@@ -139,13 +151,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
139
151
|
minDiscountTokenBalance,
|
|
140
152
|
minGhoBalanceForDiscount,
|
|
141
153
|
},
|
|
142
|
-
})), { symbol, isIsolated: new Dec(tokenMarket.debtCeilingForIsolationMode).gt(0), debtCeilingForIsolationMode: new Dec(tokenMarket.debtCeilingForIsolationMode).div(100).toString(), isSiloed: tokenMarket.isSiloedForBorrowing, eModeCategory: +tokenMarket.emodeCategory, isolationModeTotalDebt: new Dec(tokenMarket.isolationModeTotalDebt).div(100).toString(), assetId: Number(tokenMarket.assetId), underlyingTokenAddress: tokenMarket.underlyingTokenAddress, supplyRate: new Dec(tokenMarket.supplyRate.toString()).div(1e25).toString(), borrowRate: new Dec(tokenMarket.borrowRateVariable.toString()).div(1e25).toString(), borrowRateDiscounted: nativeAsset ? new Dec(tokenMarket.borrowRateVariable.toString()).div(1e25).mul(1 - parseFloat(discountRateOnBorrow)).toString() : '0', borrowRateStable: new Dec(tokenMarket.borrowRateStable.toString()).div(1e25).toString(), collateralFactor: new Dec(tokenMarket.collateralFactor.toString()).div(10000).toString(), liquidationRatio: new Dec(tokenMarket.liquidationRatio.toString()).div(10000).toString(), marketLiquidity:
|
|
143
|
-
? assetAmountInEth(new Dec(assetAmountInWei(borrowCap.toString(), 'GHO'))
|
|
144
|
-
.sub(tokenMarket.totalBorrow.toString())
|
|
145
|
-
.toString(), symbol)
|
|
146
|
-
: assetAmountInEth(new Dec(tokenMarket.totalSupply.toString())
|
|
147
|
-
.sub(tokenMarket.totalBorrow.toString())
|
|
148
|
-
.toString(), symbol), utilization: new Dec(tokenMarket.totalBorrow.toString())
|
|
154
|
+
})), { symbol, isIsolated: new Dec(tokenMarket.debtCeilingForIsolationMode).gt(0), debtCeilingForIsolationMode: new Dec(tokenMarket.debtCeilingForIsolationMode).div(100).toString(), isSiloed: tokenMarket.isSiloedForBorrowing, eModeCategory: +tokenMarket.emodeCategory, isolationModeTotalDebt: new Dec(tokenMarket.isolationModeTotalDebt).div(100).toString(), assetId: Number(tokenMarket.assetId), underlyingTokenAddress: tokenMarket.underlyingTokenAddress, supplyRate: new Dec(tokenMarket.supplyRate.toString()).div(1e25).toString(), borrowRate: new Dec(tokenMarket.borrowRateVariable.toString()).div(1e25).toString(), borrowRateDiscounted: nativeAsset ? new Dec(tokenMarket.borrowRateVariable.toString()).div(1e25).mul(1 - parseFloat(discountRateOnBorrow)).toString() : '0', borrowRateStable: new Dec(tokenMarket.borrowRateStable.toString()).div(1e25).toString(), collateralFactor: new Dec(tokenMarket.collateralFactor.toString()).div(10000).toString(), liquidationRatio: new Dec(tokenMarket.liquidationRatio.toString()).div(10000).toString(), marketLiquidity, utilization: new Dec(tokenMarket.totalBorrow.toString())
|
|
149
155
|
.div(new Dec(tokenMarket.totalSupply.toString()))
|
|
150
156
|
.times(100)
|
|
151
157
|
.toString(), usageAsCollateralEnabled: tokenMarket.usageAsCollateralEnabled, supplyCap: tokenMarket.supplyCap, borrowCap, totalSupply: assetAmountInEth(tokenMarket.totalSupply.toString(), symbol), isInactive: !tokenMarket.isActive, isFrozen: tokenMarket.isFrozen, isPaused: tokenMarket.isPaused, canBeBorrowed: tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen && tokenMarket.borrowingEnabled && isBorrowAllowed, canBeSupplied: !nativeAsset && tokenMarket.isActive && !tokenMarket.isPaused && !tokenMarket.isFrozen, canBeWithdrawn: tokenMarket.isActive && !tokenMarket.isPaused, canBePayBacked: tokenMarket.isActive && !tokenMarket.isPaused, disabledStableBorrowing: !tokenMarket.stableBorrowRateEnabled, totalBorrow: assetAmountInEth(tokenMarket.totalBorrow.toString(), symbol), totalBorrowVar: assetAmountInEth(tokenMarket.totalBorrowVar.toString(), symbol), price: new Dec(tokenMarket.price.toString()).div(1e8).toString(), isolationModeBorrowingEnabled: tokenMarket.isolationModeBorrowingEnabled, isFlashLoanEnabled: tokenMarket.isFlashLoanEnabled, eModeCategoryData: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/positions-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"author": "",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@defisaver/tokens": "^1.
|
|
22
|
+
"@defisaver/tokens": "^1.5.3",
|
|
23
23
|
"decimal.js": "^10.4.3",
|
|
24
24
|
"@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
|
|
25
25
|
"@ethersproject/bignumber": "^5.7.0"
|
package/src/aaveV3/index.ts
CHANGED
|
@@ -178,7 +178,10 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
178
178
|
let discountRateOnBorrow = '0';
|
|
179
179
|
|
|
180
180
|
if (nativeAsset && facilitatorsList && discountRate && minDiscountTokenBalance && minGhoBalanceForDiscount && ghoDiscountedPerDiscountToken) {
|
|
181
|
-
|
|
181
|
+
const facilitatorBucket = await ghoContract.methods.getFacilitatorBucket(facilitatorsList[0]).call();
|
|
182
|
+
const availableFacilitatorCap = assetAmountInEth(new Dec(facilitatorBucket[0]).sub(facilitatorBucket[1]).toString(), 'GHO');
|
|
183
|
+
|
|
184
|
+
borrowCap = Dec.min(borrowCap, availableFacilitatorCap).toString();
|
|
182
185
|
|
|
183
186
|
discountRateOnBorrow = aaveV3CalculateDiscountRate(
|
|
184
187
|
tokenMarket.totalBorrow.toString(),
|
|
@@ -190,6 +193,18 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
190
193
|
);
|
|
191
194
|
}
|
|
192
195
|
|
|
196
|
+
let marketLiquidity = nativeAsset
|
|
197
|
+
? assetAmountInEth(new Dec(assetAmountInWei(borrowCap.toString(), 'GHO'))
|
|
198
|
+
.sub(tokenMarket.totalBorrow.toString())
|
|
199
|
+
.toString(), symbol)
|
|
200
|
+
: assetAmountInEth(new Dec(tokenMarket.totalSupply.toString())
|
|
201
|
+
.sub(tokenMarket.totalBorrow.toString())
|
|
202
|
+
.toString(), symbol);
|
|
203
|
+
|
|
204
|
+
if (new Dec(marketLiquidity).lt(0)) {
|
|
205
|
+
marketLiquidity = '0';
|
|
206
|
+
}
|
|
207
|
+
|
|
193
208
|
return ({
|
|
194
209
|
nativeAsset,
|
|
195
210
|
...addToObjectIf(nativeAsset, {
|
|
@@ -214,13 +229,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
214
229
|
borrowRateStable: new Dec(tokenMarket.borrowRateStable.toString()).div(1e25).toString(),
|
|
215
230
|
collateralFactor: new Dec(tokenMarket.collateralFactor.toString()).div(10000).toString(),
|
|
216
231
|
liquidationRatio: new Dec(tokenMarket.liquidationRatio.toString()).div(10000).toString(),
|
|
217
|
-
marketLiquidity
|
|
218
|
-
? assetAmountInEth(new Dec(assetAmountInWei(borrowCap.toString(), 'GHO'))
|
|
219
|
-
.sub(tokenMarket.totalBorrow.toString())
|
|
220
|
-
.toString(), symbol)
|
|
221
|
-
: assetAmountInEth(new Dec(tokenMarket.totalSupply.toString())
|
|
222
|
-
.sub(tokenMarket.totalBorrow.toString())
|
|
223
|
-
.toString(), symbol),
|
|
232
|
+
marketLiquidity,
|
|
224
233
|
utilization: new Dec(tokenMarket.totalBorrow.toString())
|
|
225
234
|
.div(new Dec(tokenMarket.totalSupply.toString()))
|
|
226
235
|
.times(100)
|
package/yarn-error.log
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
Arguments:
|
|
2
|
-
/Users/stefan/.nvm/versions/node/v14.19.0/bin/node /usr/local/Cellar/yarn/1.22.19/libexec/bin/yarn.js
|
|
3
|
-
|
|
4
|
-
PATH:
|
|
5
|
-
/Users/stefan/.nvm/versions/node/v14.19.0/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/go/bin:/Users/stefan/WebstormProjects/defisaver-positions-sdk/node_modules/.bin:/usr/local/go
|
|
6
|
-
|
|
7
|
-
Yarn version:
|
|
8
|
-
1.22.19
|
|
9
|
-
|
|
10
|
-
Node version:
|
|
11
|
-
14.19.0
|
|
12
|
-
|
|
13
|
-
Platform:
|
|
14
|
-
darwin x64
|
|
15
|
-
|
|
16
|
-
Trace:
|
|
17
|
-
Error: incorrect data check
|
|
18
|
-
at Zlib.zlibOnError [as onerror] (zlib.js:187:17)
|
|
19
|
-
|
|
20
|
-
npm manifest:
|
|
21
|
-
{
|
|
22
|
-
"name": "defisaver-positions-sdk",
|
|
23
|
-
"version": "0.0.1",
|
|
24
|
-
"description": "",
|
|
25
|
-
"main": "./cjs/index.js",
|
|
26
|
-
"module": "./esm/src/index.js",
|
|
27
|
-
"types": "./esm/src/index.d.ts",
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build:esm": "rm -rf esm && tsc -p tsconfig.json",
|
|
30
|
-
"build:cjs": "rm -rf cjs && tsc -p tsconfig.cjs.json",
|
|
31
|
-
"build": "npm run build:cjs && npm run build:esm",
|
|
32
|
-
"dev": "tsc -p tsconfig.cjs.json --watch",
|
|
33
|
-
"lint": "eslint src/ --fix",
|
|
34
|
-
"generate-contracts": "node scripts/generateContracts.js",
|
|
35
|
-
"test": "mocha tests/*",
|
|
36
|
-
"build-test": "npm run build && mocha tests/*"
|
|
37
|
-
},
|
|
38
|
-
"keywords": [],
|
|
39
|
-
"author": "",
|
|
40
|
-
"license": "ISC",
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"@defisaver/tokens": "^1.4.56",
|
|
43
|
-
"decimal.js": "^10.4.3"
|
|
44
|
-
},
|
|
45
|
-
"devDependencies": {
|
|
46
|
-
"@defisaver/eslint-config": "^1.0.1",
|
|
47
|
-
"chai": "^4.3.8",
|
|
48
|
-
"dotenv": "^16.3.1",
|
|
49
|
-
"eslint": "^8.49.0",
|
|
50
|
-
"mocha": "^10.2.0",
|
|
51
|
-
"typechain": "^8.3.1",
|
|
52
|
-
"typechain-target-web3-v1-3mihai3": "^6.0.2",
|
|
53
|
-
"typescript": "^5.2.2"
|
|
54
|
-
},
|
|
55
|
-
"peerDependencies": {
|
|
56
|
-
"web3": "^1.10.2"
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
yarn manifest:
|
|
61
|
-
No manifest
|
|
62
|
-
|
|
63
|
-
Lockfile:
|
|
64
|
-
No lockfile
|