@defisaver/positions-sdk 0.0.198 → 0.0.199-dev-2
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/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +69 -69
- package/cjs/config/contracts.d.ts +126 -4
- package/cjs/config/contracts.js +14 -0
- package/cjs/contracts.d.ts +1 -0
- package/cjs/contracts.js +2 -1
- package/cjs/helpers/index.d.ts +1 -0
- package/cjs/helpers/index.js +2 -1
- package/cjs/helpers/liquityV2Helpers/index.d.ts +12 -0
- package/cjs/helpers/liquityV2Helpers/index.js +63 -0
- package/cjs/helpers/morphoBlueHelpers/index.js +66 -66
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/liquityV2/index.d.ts +18 -0
- package/cjs/liquityV2/index.js +184 -0
- package/cjs/markets/aave/marketAssets.js +2 -4
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/markets/liquityV2/index.d.ts +10 -0
- package/cjs/markets/liquityV2/index.js +47 -0
- package/cjs/moneymarket/moneymarketCommonService.js +1 -1
- package/cjs/types/contracts/generated/LiquityV2CollSurplusPool.d.ts +64 -0
- package/cjs/types/contracts/generated/LiquityV2CollSurplusPool.js +5 -0
- package/cjs/types/contracts/generated/LiquityV2TroveNFT.d.ts +73 -0
- package/cjs/types/contracts/generated/LiquityV2TroveNFT.js +5 -0
- package/cjs/types/contracts/generated/LiquityV2View.d.ts +244 -0
- package/cjs/types/contracts/generated/LiquityV2View.js +5 -0
- package/cjs/types/contracts/generated/index.d.ts +3 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/liquityV2.d.ts +111 -0
- package/cjs/types/liquityV2.js +24 -0
- package/esm/config/contracts.d.ts +126 -4
- package/esm/config/contracts.js +14 -0
- package/esm/contracts.d.ts +1 -0
- package/esm/contracts.js +1 -0
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/liquityV2Helpers/index.d.ts +12 -0
- package/esm/helpers/liquityV2Helpers/index.js +55 -0
- package/esm/helpers/morphoBlueHelpers/index.js +66 -66
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/liquityV2/index.d.ts +18 -0
- package/esm/liquityV2/index.js +173 -0
- package/esm/markets/aave/marketAssets.js +2 -4
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/markets/liquityV2/index.d.ts +10 -0
- package/esm/markets/liquityV2/index.js +40 -0
- package/esm/moneymarket/moneymarketCommonService.js +1 -1
- package/esm/types/contracts/generated/LiquityV2CollSurplusPool.d.ts +64 -0
- package/esm/types/contracts/generated/LiquityV2CollSurplusPool.js +4 -0
- package/esm/types/contracts/generated/LiquityV2TroveNFT.d.ts +73 -0
- package/esm/types/contracts/generated/LiquityV2TroveNFT.js +4 -0
- package/esm/types/contracts/generated/LiquityV2View.d.ts +244 -0
- package/esm/types/contracts/generated/LiquityV2View.js +4 -0
- package/esm/types/contracts/generated/index.d.ts +3 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/liquityV2.d.ts +111 -0
- package/esm/types/liquityV2.js +21 -0
- package/package.json +49 -49
- package/src/aaveV2/index.ts +227 -227
- package/src/aaveV3/index.ts +625 -625
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +220 -220
- package/src/compoundV3/index.ts +291 -291
- package/src/config/contracts.js +1109 -1095
- package/src/constants/index.ts +6 -6
- package/src/contracts.ts +133 -132
- package/src/curveUsd/index.ts +229 -229
- package/src/eulerV2/index.ts +303 -303
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +198 -198
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +246 -246
- package/src/helpers/curveUsdHelpers/index.ts +40 -40
- package/src/helpers/eulerHelpers/index.ts +232 -232
- package/src/helpers/index.ts +10 -9
- package/src/helpers/liquityV2Helpers/index.ts +80 -0
- package/src/helpers/llamaLendHelpers/index.ts +53 -53
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +365 -365
- package/src/helpers/sparkHelpers/index.ts +150 -150
- package/src/index.ts +50 -48
- package/src/liquity/index.ts +116 -116
- package/src/liquityV2/index.ts +220 -0
- package/src/llamaLend/index.ts +275 -275
- package/src/maker/index.ts +117 -117
- package/src/markets/aave/index.ts +152 -152
- package/src/markets/aave/marketAssets.ts +44 -46
- package/src/markets/compound/index.ts +213 -213
- package/src/markets/compound/marketsAssets.ts +82 -82
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/euler/index.ts +26 -26
- package/src/markets/index.ts +24 -24
- package/src/markets/liquityV2/index.ts +44 -0
- package/src/markets/llamaLend/contractAddresses.ts +141 -141
- package/src/markets/llamaLend/index.ts +235 -235
- package/src/markets/morphoBlue/index.ts +895 -895
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +10 -10
- package/src/moneymarket/moneymarketCommonService.ts +80 -80
- package/src/morphoAaveV2/index.ts +256 -256
- package/src/morphoAaveV3/index.ts +631 -631
- package/src/morphoBlue/index.ts +204 -204
- package/src/multicall/index.ts +22 -22
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +62 -62
- package/src/services/utils.ts +56 -56
- package/src/setup.ts +8 -8
- package/src/spark/index.ts +461 -461
- package/src/staking/staking.ts +220 -220
- package/src/types/aave.ts +271 -271
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +84 -84
- package/src/types/compound.ts +131 -131
- package/src/types/contracts/generated/LiquityV2CollSurplusPool.ts +130 -0
- package/src/types/contracts/generated/LiquityV2TroveNFT.ts +150 -0
- package/src/types/contracts/generated/LiquityV2View.ts +315 -0
- package/src/types/contracts/generated/index.ts +3 -0
- package/src/types/curveUsd.ts +118 -118
- package/src/types/euler.ts +171 -171
- package/src/types/index.ts +10 -9
- package/src/types/liquity.ts +30 -30
- package/src/types/liquityV2.ts +119 -0
- package/src/types/llamaLend.ts +155 -155
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +192 -192
- package/src/types/spark.ts +131 -131
package/src/services/utils.ts
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
|
-
import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
|
-
import { NetworkNumber } from '../types/common';
|
|
4
|
-
|
|
5
|
-
export const isLayer2Network = (networkId: NetworkNumber) => [10, 42161, 8453].includes(+networkId);
|
|
6
|
-
|
|
7
|
-
export const addToObjectIf = (condition: any, item: any) => (condition ? item : {});
|
|
8
|
-
|
|
9
|
-
export const ethToWeth = (maybeEth: any) => maybeEth?.replace(/^ETH$/, 'WETH');
|
|
10
|
-
|
|
11
|
-
export const wethToEth = (maybeWeth: any) => maybeWeth?.replace(/^WETH$/, 'ETH');
|
|
12
|
-
|
|
13
|
-
export const stEthToWstEth = (maybeStEth: any) => maybeStEth?.replace(/^stETH$/, 'wstETH');
|
|
14
|
-
|
|
15
|
-
export const wstEthToStEth = (maybeStEth: any) => maybeStEth?.replace(/^wstETH$/, 'stETH');
|
|
16
|
-
|
|
17
|
-
export const getAbiItem = (abi: any, methodName: string) => abi.find((i: any) => i.name === methodName);
|
|
18
|
-
|
|
19
|
-
export const ADDRESS_REGEX = /0x[0-9a-fA-F]{40}/;
|
|
20
|
-
export const isAddress = (address: string) => typeof address === 'string' && (new RegExp(ADDRESS_REGEX).test(address));
|
|
21
|
-
|
|
22
|
-
export const compareAddresses = (addr1 = '', addr2 = '') => addr1.toLowerCase() === addr2.toLowerCase();
|
|
23
|
-
|
|
24
|
-
export const getWeiAmountForDecimals = (amount: string | number, decimals: number) => new Dec(amount).mul(10 ** decimals).floor().toString();
|
|
25
|
-
|
|
26
|
-
export const getEthAmountForDecimals = (amount: string | number, decimals: string | number) => new Dec(amount).div(10 ** +decimals).toString();
|
|
27
|
-
|
|
28
|
-
export const handleWbtcLegacy = (asset: string) => (asset === 'WBTC Legacy' ? 'WBTC' : asset);
|
|
29
|
-
|
|
30
|
-
export const wethToEthByAddress = (maybeWethAddr: string, chainId = NetworkNumber.Eth) => getAssetInfo(wethToEth(getAssetInfoByAddress(maybeWethAddr, chainId).symbol), chainId).address;
|
|
31
|
-
|
|
32
|
-
export const ethToWethByAddress = (maybeEthAddr: string, chainId = NetworkNumber.Eth) => getAssetInfo(ethToWeth(getAssetInfoByAddress(maybeEthAddr, chainId).symbol), chainId).address;
|
|
33
|
-
|
|
34
|
-
export const bytesToString = (hex: string) => Buffer.from(hex.replace(/^0x/, ''), 'hex')
|
|
35
|
-
.toString()
|
|
36
|
-
// eslint-disable-next-line no-control-regex
|
|
37
|
-
.replace(/\x00/g, '');
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
|
|
41
|
-
*/
|
|
42
|
-
export const mapRange = (input: number | string, minInput: number | string, maxInput: number | string, minOutput:number | string, maxOutput: number | string) => {
|
|
43
|
-
// slope = 1.0 * (output_end - output_start) / (input_end - input_start)
|
|
44
|
-
const inputDiff = new Dec(maxInput).minus(minInput);
|
|
45
|
-
const outputDiff = new Dec(maxOutput).minus(minOutput);
|
|
46
|
-
const slope = new Dec(outputDiff).div(inputDiff);
|
|
47
|
-
|
|
48
|
-
// output = output_start + slope * (input - input_start)
|
|
49
|
-
return new Dec(minOutput).plus(new Dec(slope).mul(new Dec(input).minus(minInput))).toDP(2).toNumber();
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// eslint-disable-next-line no-bitwise
|
|
53
|
-
export const isEnabledOnBitmap = (bitmap: number, assetId: number) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
|
|
54
|
-
|
|
55
|
-
export const MAXUINT:string = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
56
|
-
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
|
+
import { NetworkNumber } from '../types/common';
|
|
4
|
+
|
|
5
|
+
export const isLayer2Network = (networkId: NetworkNumber) => [10, 42161, 8453].includes(+networkId);
|
|
6
|
+
|
|
7
|
+
export const addToObjectIf = (condition: any, item: any) => (condition ? item : {});
|
|
8
|
+
|
|
9
|
+
export const ethToWeth = (maybeEth: any) => maybeEth?.replace(/^ETH$/, 'WETH');
|
|
10
|
+
|
|
11
|
+
export const wethToEth = (maybeWeth: any) => maybeWeth?.replace(/^WETH$/, 'ETH');
|
|
12
|
+
|
|
13
|
+
export const stEthToWstEth = (maybeStEth: any) => maybeStEth?.replace(/^stETH$/, 'wstETH');
|
|
14
|
+
|
|
15
|
+
export const wstEthToStEth = (maybeStEth: any) => maybeStEth?.replace(/^wstETH$/, 'stETH');
|
|
16
|
+
|
|
17
|
+
export const getAbiItem = (abi: any, methodName: string) => abi.find((i: any) => i.name === methodName);
|
|
18
|
+
|
|
19
|
+
export const ADDRESS_REGEX = /0x[0-9a-fA-F]{40}/;
|
|
20
|
+
export const isAddress = (address: string) => typeof address === 'string' && (new RegExp(ADDRESS_REGEX).test(address));
|
|
21
|
+
|
|
22
|
+
export const compareAddresses = (addr1 = '', addr2 = '') => addr1.toLowerCase() === addr2.toLowerCase();
|
|
23
|
+
|
|
24
|
+
export const getWeiAmountForDecimals = (amount: string | number, decimals: number) => new Dec(amount).mul(10 ** decimals).floor().toString();
|
|
25
|
+
|
|
26
|
+
export const getEthAmountForDecimals = (amount: string | number, decimals: string | number) => new Dec(amount).div(10 ** +decimals).toString();
|
|
27
|
+
|
|
28
|
+
export const handleWbtcLegacy = (asset: string) => (asset === 'WBTC Legacy' ? 'WBTC' : asset);
|
|
29
|
+
|
|
30
|
+
export const wethToEthByAddress = (maybeWethAddr: string, chainId = NetworkNumber.Eth) => getAssetInfo(wethToEth(getAssetInfoByAddress(maybeWethAddr, chainId).symbol), chainId).address;
|
|
31
|
+
|
|
32
|
+
export const ethToWethByAddress = (maybeEthAddr: string, chainId = NetworkNumber.Eth) => getAssetInfo(ethToWeth(getAssetInfoByAddress(maybeEthAddr, chainId).symbol), chainId).address;
|
|
33
|
+
|
|
34
|
+
export const bytesToString = (hex: string) => Buffer.from(hex.replace(/^0x/, ''), 'hex')
|
|
35
|
+
.toString()
|
|
36
|
+
// eslint-disable-next-line no-control-regex
|
|
37
|
+
.replace(/\x00/g, '');
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
|
|
41
|
+
*/
|
|
42
|
+
export const mapRange = (input: number | string, minInput: number | string, maxInput: number | string, minOutput:number | string, maxOutput: number | string) => {
|
|
43
|
+
// slope = 1.0 * (output_end - output_start) / (input_end - input_start)
|
|
44
|
+
const inputDiff = new Dec(maxInput).minus(minInput);
|
|
45
|
+
const outputDiff = new Dec(maxOutput).minus(minOutput);
|
|
46
|
+
const slope = new Dec(outputDiff).div(inputDiff);
|
|
47
|
+
|
|
48
|
+
// output = output_start + slope * (input - input_start)
|
|
49
|
+
return new Dec(minOutput).plus(new Dec(slope).mul(new Dec(input).minus(minInput))).toDP(2).toNumber();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line no-bitwise
|
|
53
|
+
export const isEnabledOnBitmap = (bitmap: number, assetId: number) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
|
|
54
|
+
|
|
55
|
+
export const MAXUINT:string = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
56
|
+
|
|
57
57
|
export const isMaxuint = (amount: string) => compareAddresses(MAXUINT, amount);
|
package/src/setup.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
|
-
|
|
3
|
-
Decimal.set({
|
|
4
|
-
rounding: Decimal.ROUND_DOWN,
|
|
5
|
-
toExpPos: 9e15,
|
|
6
|
-
toExpNeg: -9e15,
|
|
7
|
-
precision: 50,
|
|
8
|
-
});
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
|
|
3
|
+
Decimal.set({
|
|
4
|
+
rounding: Decimal.ROUND_DOWN,
|
|
5
|
+
toExpPos: 9e15,
|
|
6
|
+
toExpNeg: -9e15,
|
|
7
|
+
precision: 50,
|
|
8
|
+
});
|