@defisaver/positions-sdk 0.0.30-dev → 0.0.30
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/README.md +63 -63
- package/cjs/compoundV3/index.js +1 -1
- package/cjs/config/contracts.d.ts +220 -1087
- package/cjs/config/contracts.js +44 -171
- package/cjs/contracts.js +10 -4
- package/cjs/curveUsd/index.js +1 -1
- package/cjs/helpers/curveUsdHelpers/index.d.ts +1 -2
- package/cjs/helpers/curveUsdHelpers/index.js +17 -25
- package/cjs/moneymarket/moneymarketCommonService.js +1 -1
- package/cjs/services/utils.d.ts +0 -4
- package/cjs/services/utils.js +1 -13
- package/cjs/types/contracts/generated/CrvUSDView.d.ts +4 -30
- package/cjs/types/curveUsd.d.ts +0 -6
- package/esm/compoundV3/index.js +1 -1
- package/esm/config/contracts.d.ts +220 -1087
- package/esm/config/contracts.js +44 -171
- package/esm/contracts.js +10 -4
- package/esm/curveUsd/index.js +1 -1
- package/esm/helpers/curveUsdHelpers/index.d.ts +1 -2
- package/esm/helpers/curveUsdHelpers/index.js +18 -26
- package/esm/moneymarket/moneymarketCommonService.js +1 -1
- package/esm/services/utils.d.ts +0 -4
- package/esm/services/utils.js +0 -11
- package/esm/types/contracts/generated/CrvUSDView.d.ts +4 -30
- package/esm/types/curveUsd.d.ts +0 -6
- package/package.json +40 -40
- package/src/aaveV2/index.ts +226 -226
- package/src/aaveV3/index.ts +561 -561
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +219 -219
- package/src/compoundV3/index.ts +275 -275
- package/src/config/contracts.js +676 -803
- package/src/constants/index.ts +3 -3
- package/src/contracts.ts +126 -120
- package/src/curveUsd/index.ts +228 -228
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +134 -134
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +181 -181
- package/src/helpers/curveUsdHelpers/index.ts +32 -40
- package/src/helpers/index.ts +5 -5
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/sparkHelpers/index.ts +106 -106
- package/src/index.ts +40 -40
- package/src/liquity/index.ts +116 -116
- package/src/maker/index.ts +101 -101
- package/src/markets/aave/index.ts +80 -80
- package/src/markets/aave/marketAssets.ts +24 -24
- package/src/markets/compound/index.ts +141 -141
- package/src/markets/compound/marketsAssets.ts +48 -48
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/index.ts +3 -3
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +10 -10
- package/src/moneymarket/moneymarketCommonService.ts +75 -75
- package/src/morpho/markets.ts +39 -39
- package/src/morphoAaveV2/index.ts +255 -255
- package/src/morphoAaveV3/index.ts +619 -619
- package/src/multicall/index.ts +22 -22
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +21 -21
- package/src/services/utils.ts +35 -48
- package/src/spark/index.ts +422 -422
- package/src/staking/staking.ts +167 -167
- package/src/types/aave.ts +256 -256
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +83 -83
- package/src/types/compound.ts +128 -128
- package/src/types/contracts/generated/CrvUSDView.ts +8 -43
- package/src/types/curveUsd.ts +112 -118
- package/src/types/index.ts +6 -6
- package/src/types/liquity.ts +30 -30
- package/src/types/maker.ts +50 -50
- package/src/types/spark.ts +106 -106
- package/yarn-error.log +0 -64
package/src/multicall/index.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import Web3 from 'web3';
|
|
2
|
-
import { UniMulticallContract } from '../contracts';
|
|
3
|
-
import { NetworkNumber } from '../types/common';
|
|
4
|
-
|
|
5
|
-
export const multicall = async (calls: any[], web3: Web3, network: NetworkNumber = NetworkNumber.Eth, blockNumber: 'latest' | number = 'latest') => {
|
|
6
|
-
const multicallContract = UniMulticallContract(web3, network);
|
|
7
|
-
const formattedCalls = calls.map((call) => {
|
|
8
|
-
const callData = web3.eth.abi.encodeFunctionCall(call.abiItem, call.params);
|
|
9
|
-
return { callData, target: call.target || '0x0', gasLimit: call.gasLimit || 1e6 };
|
|
10
|
-
});
|
|
11
|
-
const callResult = await multicallContract.methods.multicall(formattedCalls.filter(item => item.target !== '0x0')).call({}, blockNumber);
|
|
12
|
-
|
|
13
|
-
let formattedResult: any[] = [];
|
|
14
|
-
|
|
15
|
-
callResult.returnData.forEach(([success, gasUsed, result], i) => {
|
|
16
|
-
const formattedRes = result !== '0x'
|
|
17
|
-
? web3.eth.abi.decodeParameters(calls[i].abiItem.outputs, result)
|
|
18
|
-
: undefined;
|
|
19
|
-
formattedResult = [...formattedResult, formattedRes];
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
return formattedResult;
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
import { UniMulticallContract } from '../contracts';
|
|
3
|
+
import { NetworkNumber } from '../types/common';
|
|
4
|
+
|
|
5
|
+
export const multicall = async (calls: any[], web3: Web3, network: NetworkNumber = NetworkNumber.Eth, blockNumber: 'latest' | number = 'latest') => {
|
|
6
|
+
const multicallContract = UniMulticallContract(web3, network);
|
|
7
|
+
const formattedCalls = calls.map((call) => {
|
|
8
|
+
const callData = web3.eth.abi.encodeFunctionCall(call.abiItem, call.params);
|
|
9
|
+
return { callData, target: call.target || '0x0', gasLimit: call.gasLimit || 1e6 };
|
|
10
|
+
});
|
|
11
|
+
const callResult = await multicallContract.methods.multicall(formattedCalls.filter(item => item.target !== '0x0')).call({}, blockNumber);
|
|
12
|
+
|
|
13
|
+
let formattedResult: any[] = [];
|
|
14
|
+
|
|
15
|
+
callResult.returnData.forEach(([success, gasUsed, result], i) => {
|
|
16
|
+
const formattedRes = result !== '0x'
|
|
17
|
+
? web3.eth.abi.decodeParameters(calls[i].abiItem.outputs, result)
|
|
18
|
+
: undefined;
|
|
19
|
+
formattedResult = [...formattedResult, formattedRes];
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return formattedResult;
|
|
23
23
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
|
-
import Web3 from 'web3';
|
|
3
|
-
import { NetworkNumber } from '../types/common';
|
|
4
|
-
import { SECONDS_PER_YEAR } from '../constants';
|
|
5
|
-
import { PotContract } from '../contracts';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export const getDsrApy = async (web3: Web3, network: NetworkNumber) => {
|
|
9
|
-
const potContract = PotContract(web3, network);
|
|
10
|
-
return new Dec(await potContract.methods.dsr().call())
|
|
11
|
-
.div(new Dec(1e27))
|
|
12
|
-
.pow(SECONDS_PER_YEAR)
|
|
13
|
-
.sub(1)
|
|
14
|
-
.mul(100)
|
|
15
|
-
.toString();
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import Web3 from 'web3';
|
|
3
|
+
import { NetworkNumber } from '../types/common';
|
|
4
|
+
import { SECONDS_PER_YEAR } from '../constants';
|
|
5
|
+
import { PotContract } from '../contracts';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const getDsrApy = async (web3: Web3, network: NetworkNumber) => {
|
|
9
|
+
const potContract = PotContract(web3, network);
|
|
10
|
+
return new Dec(await potContract.methods.dsr().call())
|
|
11
|
+
.div(new Dec(1e27))
|
|
12
|
+
.pow(SECONDS_PER_YEAR)
|
|
13
|
+
.sub(1)
|
|
14
|
+
.mul(100)
|
|
15
|
+
.toString();
|
|
16
16
|
};
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import Web3 from 'web3';
|
|
2
|
-
import Dec from 'decimal.js';
|
|
3
|
-
import { COMPPriceFeedContract, ETHPriceFeedContract, USDCPriceFeedContract } from '../contracts';
|
|
4
|
-
import { NetworkNumber } from '../types/common';
|
|
5
|
-
|
|
6
|
-
export const getEthPrice = async (web3: Web3) => {
|
|
7
|
-
const contract = ETHPriceFeedContract(web3, NetworkNumber.Eth);
|
|
8
|
-
const price = await contract.methods.latestAnswer().call();
|
|
9
|
-
return new Dec(price).div(1e8).toString();
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export const getUSDCPrice = async (web3: Web3) => {
|
|
13
|
-
const contract = USDCPriceFeedContract(web3, NetworkNumber.Eth);
|
|
14
|
-
const price = await contract.methods.latestAnswer().call();
|
|
15
|
-
return new Dec(price).div(1e8).toString();
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const getCompPrice = async (web3: Web3) => {
|
|
19
|
-
const contract = COMPPriceFeedContract(web3, NetworkNumber.Eth);
|
|
20
|
-
const price = await contract.methods.latestAnswer().call();
|
|
21
|
-
return new Dec(price).div(1e8).toString();
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
import Dec from 'decimal.js';
|
|
3
|
+
import { COMPPriceFeedContract, ETHPriceFeedContract, USDCPriceFeedContract } from '../contracts';
|
|
4
|
+
import { NetworkNumber } from '../types/common';
|
|
5
|
+
|
|
6
|
+
export const getEthPrice = async (web3: Web3) => {
|
|
7
|
+
const contract = ETHPriceFeedContract(web3, NetworkNumber.Eth);
|
|
8
|
+
const price = await contract.methods.latestAnswer().call();
|
|
9
|
+
return new Dec(price).div(1e8).toString();
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const getUSDCPrice = async (web3: Web3) => {
|
|
13
|
+
const contract = USDCPriceFeedContract(web3, NetworkNumber.Eth);
|
|
14
|
+
const price = await contract.methods.latestAnswer().call();
|
|
15
|
+
return new Dec(price).div(1e8).toString();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const getCompPrice = async (web3: Web3) => {
|
|
19
|
+
const contract = COMPPriceFeedContract(web3, NetworkNumber.Eth);
|
|
20
|
+
const price = await contract.methods.latestAnswer().call();
|
|
21
|
+
return new Dec(price).div(1e8).toString();
|
|
22
22
|
};
|
package/src/services/utils.ts
CHANGED
|
@@ -1,48 +1,35 @@
|
|
|
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 getEthAmountForDecimals = (amount: string | number, decimals: string | number) => new Dec(amount).div(10 ** +decimals).toString();
|
|
25
|
-
|
|
26
|
-
export const handleWbtcLegacy = (asset: string) => (asset === 'WBTC Legacy' ? 'WBTC' : asset);
|
|
27
|
-
|
|
28
|
-
export const wethToEthByAddress = (maybeWethAddr: string, chainId = NetworkNumber.Eth) => getAssetInfo(wethToEth(getAssetInfoByAddress(maybeWethAddr, chainId).symbol), chainId).address;
|
|
29
|
-
|
|
30
|
-
export const ethToWethByAddress = (maybeEthAddr: string, chainId = NetworkNumber.Eth) => getAssetInfo(ethToWeth(getAssetInfoByAddress(maybeEthAddr, chainId).symbol), chainId).address;
|
|
31
|
-
|
|
32
|
-
export const bytesToString = (hex: string) => Buffer.from(hex.replace(/^0x/, ''), 'hex')
|
|
33
|
-
.toString()
|
|
34
|
-
// eslint-disable-next-line no-control-regex
|
|
35
|
-
.replace(/\x00/g, '');
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
|
|
39
|
-
*/
|
|
40
|
-
export const mapRange = (input: number | string, minInput: number | string, maxInput: number | string, minOutput:number | string, maxOutput: number | string) => {
|
|
41
|
-
// slope = 1.0 * (output_end - output_start) / (input_end - input_start)
|
|
42
|
-
const inputDiff = new Dec(maxInput).minus(minInput);
|
|
43
|
-
const outputDiff = new Dec(maxOutput).minus(minOutput);
|
|
44
|
-
const slope = new Dec(outputDiff).div(inputDiff);
|
|
45
|
-
|
|
46
|
-
// output = output_start + slope * (input - input_start)
|
|
47
|
-
return new Dec(minOutput).plus(new Dec(slope).mul(new Dec(input).minus(minInput))).toDP(2).toNumber();
|
|
48
|
-
};
|
|
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 getEthAmountForDecimals = (amount: string | number, decimals: string | number) => new Dec(amount).div(10 ** +decimals).toString();
|
|
25
|
+
|
|
26
|
+
export const handleWbtcLegacy = (asset: string) => (asset === 'WBTC Legacy' ? 'WBTC' : asset);
|
|
27
|
+
|
|
28
|
+
export const wethToEthByAddress = (maybeWethAddr: string, chainId = NetworkNumber.Eth) => getAssetInfo(wethToEth(getAssetInfoByAddress(maybeWethAddr, chainId).symbol), chainId).address;
|
|
29
|
+
|
|
30
|
+
export const ethToWethByAddress = (maybeEthAddr: string, chainId = NetworkNumber.Eth) => getAssetInfo(ethToWeth(getAssetInfoByAddress(maybeEthAddr, chainId).symbol), chainId).address;
|
|
31
|
+
|
|
32
|
+
export const bytesToString = (hex: string) => Buffer.from(hex.replace(/^0x/, ''), 'hex')
|
|
33
|
+
.toString()
|
|
34
|
+
// eslint-disable-next-line no-control-regex
|
|
35
|
+
.replace(/\x00/g, '');
|