@defisaver/positions-sdk 0.0.3 → 0.0.5

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.
Files changed (55) hide show
  1. package/cjs/aaveV3/index.js +1 -1
  2. package/cjs/chickenBonds/index.d.ts +4 -0
  3. package/cjs/chickenBonds/index.js +94 -1
  4. package/cjs/config/contracts.d.ts +36 -2
  5. package/cjs/config/contracts.js +7 -1
  6. package/cjs/contracts.d.ts +1 -0
  7. package/cjs/contracts.js +2 -1
  8. package/cjs/helpers/chickenBondsHelpers/index.d.ts +2 -0
  9. package/cjs/helpers/chickenBondsHelpers/index.js +19 -0
  10. package/cjs/helpers/index.d.ts +1 -0
  11. package/cjs/helpers/index.js +2 -1
  12. package/cjs/staking/staking.d.ts +1 -0
  13. package/cjs/staking/staking.js +13 -1
  14. package/cjs/types/chickenBonds.d.ts +41 -0
  15. package/cjs/types/chickenBonds.js +13 -0
  16. package/cjs/types/contracts/generated/ChickenBondsManager.d.ts +28 -0
  17. package/cjs/types/contracts/generated/ChickenBondsManager.js +5 -0
  18. package/cjs/types/contracts/generated/ChickenBondsView.d.ts +68 -0
  19. package/cjs/types/contracts/generated/index.d.ts +1 -0
  20. package/cjs/types/index.d.ts +1 -0
  21. package/cjs/types/index.js +1 -0
  22. package/esm/aaveV3/index.js +1 -1
  23. package/esm/chickenBonds/index.d.ts +4 -0
  24. package/esm/chickenBonds/index.js +89 -2
  25. package/esm/config/contracts.d.ts +36 -2
  26. package/esm/config/contracts.js +7 -1
  27. package/esm/contracts.d.ts +1 -0
  28. package/esm/contracts.js +1 -0
  29. package/esm/helpers/chickenBondsHelpers/index.d.ts +2 -0
  30. package/esm/helpers/chickenBondsHelpers/index.js +11 -0
  31. package/esm/helpers/index.d.ts +1 -0
  32. package/esm/helpers/index.js +1 -0
  33. package/esm/staking/staking.d.ts +1 -0
  34. package/esm/staking/staking.js +12 -1
  35. package/esm/types/chickenBonds.d.ts +41 -0
  36. package/esm/types/chickenBonds.js +10 -0
  37. package/esm/types/contracts/generated/ChickenBondsManager.d.ts +28 -0
  38. package/esm/types/contracts/generated/ChickenBondsManager.js +4 -0
  39. package/esm/types/contracts/generated/ChickenBondsView.d.ts +68 -0
  40. package/esm/types/contracts/generated/index.d.ts +1 -0
  41. package/esm/types/index.d.ts +1 -0
  42. package/esm/types/index.js +1 -0
  43. package/package.json +1 -1
  44. package/src/aaveV3/index.ts +1 -1
  45. package/src/chickenBonds/index.ts +103 -1
  46. package/src/config/contracts.js +8 -2
  47. package/src/contracts.ts +3 -1
  48. package/src/helpers/chickenBondsHelpers/index.ts +13 -0
  49. package/src/helpers/index.ts +2 -1
  50. package/src/staking/staking.ts +12 -1
  51. package/src/types/chickenBonds.ts +45 -0
  52. package/src/types/contracts/generated/ChickenBondsManager.ts +59 -0
  53. package/src/types/contracts/generated/ChickenBondsView.ts +88 -0
  54. package/src/types/contracts/generated/index.ts +1 -0
  55. package/src/types/index.ts +2 -1
@@ -7,8 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { getAssetInfo } from '@defisaver/tokens';
11
- import { ChickenBondsViewContract } from '../contracts';
10
+ import Dec from 'decimal.js';
11
+ import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
12
+ import { ChickenBondsManagerContract, ChickenBondsViewContract } from '../contracts';
13
+ import { multicall } from '../multicall';
14
+ import { calcAverageBondAgeMs, calcCBondsBLUSDFloorPrice } from '../helpers/chickenBondsHelpers';
12
15
  export const getChickenBondsAccountBalances = (web3, network, block, addressMapping, bondId) => __awaiter(void 0, void 0, void 0, function* () {
13
16
  const viewContract = ChickenBondsViewContract(web3, network, block);
14
17
  const fullBondInfo = yield viewContract.methods.getBondFullInfo(bondId).call({}, block);
@@ -18,3 +21,87 @@ export const getChickenBondsAccountBalances = (web3, network, block, addressMapp
18
21
  },
19
22
  };
20
23
  });
24
+ export const fetchCBondsSystemInfo = (web3, network) => __awaiter(void 0, void 0, void 0, function* () {
25
+ const cBondsView = ChickenBondsViewContract(web3, network);
26
+ const cBondsManager = ChickenBondsManagerContract(web3, network);
27
+ const multicallData = [
28
+ {
29
+ target: cBondsView.options.address,
30
+ abiItem: cBondsView.options.jsonInterface.find(({ name }) => name === 'getSystemInfo'),
31
+ params: [],
32
+ },
33
+ {
34
+ target: cBondsManager.options.address,
35
+ abiItem: cBondsManager.options.jsonInterface.find(({ name }) => name === 'totalWeightedStartTimes'),
36
+ params: [],
37
+ },
38
+ {
39
+ target: cBondsManager.options.address,
40
+ abiItem: cBondsManager.options.jsonInterface.find(({ name }) => name === 'getAcquiredLUSDInSP'),
41
+ params: [],
42
+ },
43
+ {
44
+ target: cBondsManager.options.address,
45
+ abiItem: cBondsManager.options.jsonInterface.find(({ name }) => name === 'getAcquiredLUSDInCurve'),
46
+ params: [],
47
+ },
48
+ {
49
+ target: cBondsManager.options.address,
50
+ abiItem: cBondsManager.options.jsonInterface.find(({ name }) => name === 'yTokensHeldByCBM'),
51
+ params: [],
52
+ },
53
+ ];
54
+ const [{ 0: systemInfo }, { 0: totalWeightedStartTimes }, { 0: acquiredLUSDInSP }, { 0: acquiredLUSDInCurve }, { 0: yTokensHeldByCBM }] = yield multicall(multicallData, web3, network);
55
+ const payload = {
56
+ numPendingBonds: systemInfo.numPendingBonds,
57
+ numChickenInBonds: systemInfo.numChickenInBonds,
58
+ numChickenOutBonds: systemInfo.numChickenOutBonds,
59
+ accrualParameter: new Dec(assetAmountInEth(systemInfo.accrualParameter)).mul(1000).toString(),
60
+ bLUSDSupply: assetAmountInEth(systemInfo.bLUSDSupply, 'bLUSD'),
61
+ chickenInAMMFee: assetAmountInEth(systemInfo.chickenInAMMFee),
62
+ ownedLUSDInCurve: assetAmountInEth(systemInfo.ownedLUSDInCurve, 'LUSD'),
63
+ systemBackingRatio: assetAmountInEth(systemInfo.systemBackingRatio),
64
+ ownedLUSDInSP: assetAmountInEth(systemInfo.ownedLUSDInSP, 'LUSD'),
65
+ totalPendingLUSD: assetAmountInEth(systemInfo.totalPendingLUSD, 'LUSD'),
66
+ totalPermanentLUSD: assetAmountInEth(systemInfo.totalPermanentLUSD, 'LUSD'),
67
+ totalReserveLUSD: assetAmountInEth(systemInfo.totalReserveLUSD, 'LUSD'),
68
+ targetAverageAgeMs: 1296000000,
69
+ totalWeightedStartTimes: assetAmountInEth(totalWeightedStartTimes),
70
+ acquiredLUSDInSP: assetAmountInEth(acquiredLUSDInSP, 'LUSD'),
71
+ acquiredLUSDInCurve: assetAmountInEth(acquiredLUSDInCurve, 'LUSD'),
72
+ yTokensHeldByCBM: assetAmountInEth(yTokensHeldByCBM, 'ETH'), // yTokens is 18 decimals
73
+ };
74
+ const floorPrice = calcCBondsBLUSDFloorPrice(payload.bLUSDSupply, payload.totalReserveLUSD);
75
+ const averageBondAgeMs = calcAverageBondAgeMs(payload.totalWeightedStartTimes, payload.totalPendingLUSD);
76
+ return Object.assign(Object.assign({}, payload), { floorPrice,
77
+ averageBondAgeMs });
78
+ });
79
+ export const fetchCBondsForUser = (web3, network, address) => __awaiter(void 0, void 0, void 0, function* () {
80
+ const cBondsView = ChickenBondsViewContract(web3, network);
81
+ const bonds = yield cBondsView.methods.getUsersBonds(address).call();
82
+ return bonds.map(({ bondID, accruedBLUSD, claimedBLUSD, endTime, lusdAmount, maxAmountBLUSD, startTime, status, tokenURI, }) => ({
83
+ bondId: bondID,
84
+ status,
85
+ // tokenURI: decodeTokenURIToSvg(tokenURI),
86
+ startTime: new Date(+startTime * 1000),
87
+ endTime: new Date(+endTime * 1000),
88
+ accruedBLUSD: assetAmountInEth(accruedBLUSD, 'bLUSD'),
89
+ claimedBLUSD: assetAmountInEth(claimedBLUSD, 'bLUSD'),
90
+ lusdAmount: assetAmountInEth(lusdAmount, 'LUSD'),
91
+ maxAmountBLUSD: assetAmountInEth(maxAmountBLUSD, 'bLUSD'),
92
+ }));
93
+ });
94
+ export const fetchCBondForId = (web3, network, bondId) => __awaiter(void 0, void 0, void 0, function* () {
95
+ const cBondsView = ChickenBondsViewContract(web3, network);
96
+ const bond = yield cBondsView.methods.getBondFullInfo(bondId).call();
97
+ return {
98
+ bondId,
99
+ status: bond.status,
100
+ startTime: new Date(+bond.startTime * 1000),
101
+ endTime: new Date(+bond.endTime * 1000),
102
+ accruedBLUSD: assetAmountInEth(bond.accruedBLUSD, 'bLUSD'),
103
+ claimedBLUSD: assetAmountInEth(bond.claimedBLUSD, 'bLUSD'),
104
+ lusdAmount: assetAmountInEth(bond.lusdAmount, 'LUSD'),
105
+ maxAmountBLUSD: assetAmountInEth(bond.maxAmountBLUSD, 'bLUSD'),
106
+ };
107
+ });
@@ -2997,7 +2997,17 @@ export namespace McdDog {
2997
2997
  export { networks_55 as networks };
2998
2998
  }
2999
2999
  export namespace ChickenBondsView {
3000
- let abi_56: {
3000
+ let abi_56: ({
3001
+ inputs: never[];
3002
+ name: string;
3003
+ outputs: {
3004
+ internalType: string;
3005
+ name: string;
3006
+ type: string;
3007
+ }[];
3008
+ stateMutability: string;
3009
+ type: string;
3010
+ } | {
3001
3011
  inputs: {
3002
3012
  internalType: string;
3003
3013
  name: string;
@@ -3016,7 +3026,7 @@ export namespace ChickenBondsView {
3016
3026
  }[];
3017
3027
  stateMutability: string;
3018
3028
  type: string;
3019
- }[];
3029
+ })[];
3020
3030
  export { abi_56 as abi };
3021
3031
  let networks_56: {
3022
3032
  "1": {
@@ -3026,3 +3036,27 @@ export namespace ChickenBondsView {
3026
3036
  };
3027
3037
  export { networks_56 as networks };
3028
3038
  }
3039
+ export namespace ChickenBondsManager {
3040
+ let abi_57: {
3041
+ inputs: {
3042
+ internalType: string;
3043
+ name: string;
3044
+ type: string;
3045
+ }[];
3046
+ name: string;
3047
+ outputs: {
3048
+ internalType: string;
3049
+ name: string;
3050
+ type: string;
3051
+ }[];
3052
+ stateMutability: string;
3053
+ type: string;
3054
+ }[];
3055
+ export { abi_57 as abi };
3056
+ let networks_57: {
3057
+ "1": {
3058
+ address: string;
3059
+ };
3060
+ };
3061
+ export { networks_57 as networks };
3062
+ }
@@ -584,12 +584,18 @@ module.exports = {
584
584
  }
585
585
  },
586
586
  "ChickenBondsView": {
587
- "abi": [{ "inputs": [{ "internalType": "uint256", "name": "_bondID", "type": "uint256" }], "name": "getBondFullInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "bondID", "type": "uint256" }, { "internalType": "uint256", "name": "lusdAmount", "type": "uint256" }, { "internalType": "uint64", "name": "claimedBLUSD", "type": "uint64" }, { "internalType": "uint256", "name": "accruedBLUSD", "type": "uint256" }, { "internalType": "uint256", "name": "maxAmountBLUSD", "type": "uint256" }, { "internalType": "uint64", "name": "startTime", "type": "uint64" }, { "internalType": "uint64", "name": "endTime", "type": "uint64" }, { "internalType": "enum IChickenBondManager.BondStatus", "name": "status", "type": "uint8" }, { "internalType": "string", "name": "tokenURI", "type": "string" }], "internalType": "struct ChickenBondsView.BondDataFull", "name": "bond", "type": "tuple" }], "stateMutability": "view", "type": "function" }],
587
+ "abi": [{ "inputs": [], "name": "BorrowerOperations", "outputs": [{ "internalType": "contract IBorrowerOperations", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "CBManager", "outputs": [{ "internalType": "contract IChickenBondManager", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "CollSurplusPool", "outputs": [{ "internalType": "contract ICollSurplusPool", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "HintHelpers", "outputs": [{ "internalType": "contract IHintHelpers", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "LQTYStaking", "outputs": [{ "internalType": "contract ILQTYStaking", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "LUSD_GAS_COMPENSATION", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "PriceFeed", "outputs": [{ "internalType": "contract IPriceFeed", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "SortedTroves", "outputs": [{ "internalType": "contract ISortedTroves", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "StabilityPool", "outputs": [{ "internalType": "contract IStabilityPool", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "TroveManager", "outputs": [{ "internalType": "contract ITroveManager", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_bondID", "type": "uint256" }], "name": "getBondFullInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "bondID", "type": "uint256" }, { "internalType": "uint256", "name": "lusdAmount", "type": "uint256" }, { "internalType": "uint64", "name": "claimedBLUSD", "type": "uint64" }, { "internalType": "uint256", "name": "accruedBLUSD", "type": "uint256" }, { "internalType": "uint256", "name": "maxAmountBLUSD", "type": "uint256" }, { "internalType": "uint64", "name": "startTime", "type": "uint64" }, { "internalType": "uint64", "name": "endTime", "type": "uint64" }, { "internalType": "enum IChickenBondManager.BondStatus", "name": "status", "type": "uint8" }, { "internalType": "string", "name": "tokenURI", "type": "string" }], "internalType": "struct ChickenBondsView.BondDataFull", "name": "bond", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "getSystemInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "totalPendingLUSD", "type": "uint256" }, { "internalType": "uint256", "name": "totalReserveLUSD", "type": "uint256" }, { "internalType": "uint256", "name": "totalPermanentLUSD", "type": "uint256" }, { "internalType": "uint256", "name": "ownedLUSDInSP", "type": "uint256" }, { "internalType": "uint256", "name": "ownedLUSDInCurve", "type": "uint256" }, { "internalType": "uint256", "name": "systemBackingRatio", "type": "uint256" }, { "internalType": "uint256", "name": "accrualParameter", "type": "uint256" }, { "internalType": "uint256", "name": "chickenInAMMFee", "type": "uint256" }, { "internalType": "uint256", "name": "numPendingBonds", "type": "uint256" }, { "internalType": "uint256", "name": "numChickenInBonds", "type": "uint256" }, { "internalType": "uint256", "name": "numChickenOutBonds", "type": "uint256" }, { "internalType": "uint256", "name": "bLUSDSupply", "type": "uint256" }], "internalType": "struct ChickenBondsView.ChickenBondsSystemInfo", "name": "systemInfo", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_userAddr", "type": "address" }], "name": "getUsersBonds", "outputs": [{ "components": [{ "internalType": "uint256", "name": "bondID", "type": "uint256" }, { "internalType": "uint256", "name": "lusdAmount", "type": "uint256" }, { "internalType": "uint64", "name": "claimedBLUSD", "type": "uint64" }, { "internalType": "uint256", "name": "accruedBLUSD", "type": "uint256" }, { "internalType": "uint256", "name": "maxAmountBLUSD", "type": "uint256" }, { "internalType": "uint64", "name": "startTime", "type": "uint64" }, { "internalType": "uint64", "name": "endTime", "type": "uint64" }, { "internalType": "enum IChickenBondManager.BondStatus", "name": "status", "type": "uint8" }, { "internalType": "string", "name": "tokenURI", "type": "string" }], "internalType": "struct ChickenBondsView.BondDataFull[]", "name": "bonds", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }],
588
588
  "networks": {
589
589
  "1": {
590
590
  "address": "0x809a93fd4a0d7d7906Ef6176f0b5518b418Da08f",
591
591
  "createdBlock": 15739450
592
592
  }
593
593
  }
594
+ },
595
+ "ChickenBondsManager": {
596
+ "abi": [{ "inputs": [{ "internalType": "uint256", "name": "_bondID", "type": "uint256" }], "name": "chickenIn", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_bondID", "type": "uint256" }, { "internalType": "uint256", "name": "_minLUSD", "type": "uint256" }], "name": "chickenOut", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_lusdAmount", "type": "uint256" }], "name": "createBond", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "getAcquiredLUSDInCurve", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "getAcquiredLUSDInSP", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "_bLUSDToRedeem", "type": "uint256" }, { "internalType": "uint256", "name": "_minLUSDFromBAMMSPVault", "type": "uint256" }], "name": "redeem", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "totalWeightedStartTimes", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "yTokensHeldByCBM", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }],
597
+ "networks": {
598
+ "1": { "address": "0x57619FE9C539f890b19c61812226F9703ce37137" }
599
+ }
594
600
  }
595
601
  };
@@ -38,3 +38,4 @@ export declare const McdDogContract: (web3: Web3, network: NetworkNumber, block?
38
38
  export declare const McdJugContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.McdJug;
39
39
  export declare const McdVatContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.McdVat;
40
40
  export declare const ChickenBondsViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.ChickenBondsView;
41
+ export declare const ChickenBondsManagerContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.ChickenBondsManager;
package/esm/contracts.js CHANGED
@@ -53,3 +53,4 @@ export const McdDogContract = createContractFromConfigFunc('McdDog');
53
53
  export const McdJugContract = createContractFromConfigFunc('McdJug');
54
54
  export const McdVatContract = createContractFromConfigFunc('McdVat');
55
55
  export const ChickenBondsViewContract = createContractFromConfigFunc('ChickenBondsView');
56
+ export const ChickenBondsManagerContract = createContractFromConfigFunc('ChickenBondsManager');
@@ -0,0 +1,2 @@
1
+ export declare const calcCBondsBLUSDFloorPrice: (bLUSDSupply: string, totalReserveLUSD: string) => string;
2
+ export declare const calcAverageBondAgeMs: (totalWeightedStartTimes: string, totalPendingLusd: string) => number;
@@ -0,0 +1,11 @@
1
+ import Dec from 'decimal.js';
2
+ export const calcCBondsBLUSDFloorPrice = (bLUSDSupply, totalReserveLUSD) => {
3
+ if (new Dec(bLUSDSupply).eq(0))
4
+ return '1';
5
+ return new Dec(totalReserveLUSD).div(bLUSDSupply).toString();
6
+ };
7
+ export const calcAverageBondAgeMs = (totalWeightedStartTimes, totalPendingLusd) => {
8
+ const averageStartTimeMs = new Dec(totalWeightedStartTimes).div(totalPendingLusd).round().mul(1000)
9
+ .toNumber();
10
+ return Date.now() - averageStartTimeMs;
11
+ };
@@ -3,3 +3,4 @@ export * as compoundHelpers from './compoundHelpers';
3
3
  export * as sparkHelpers from './sparkHelpers';
4
4
  export * as curveUsdHelpers from './curveUsdHelpers';
5
5
  export * as makerHelpers from './makerHelpers';
6
+ export * as chickenBondsHelpers from './chickenBondsHelpers';
@@ -3,3 +3,4 @@ export * as compoundHelpers from './compoundHelpers';
3
3
  export * as sparkHelpers from './sparkHelpers';
4
4
  export * as curveUsdHelpers from './curveUsdHelpers';
5
5
  export * as makerHelpers from './makerHelpers';
6
+ export * as chickenBondsHelpers from './chickenBondsHelpers';
@@ -3,6 +3,7 @@ import { MMAssetsData, MMUsedAssets } from '../types/common';
3
3
  export declare const getStETHApr: (web3: Web3, fromBlock?: number, blockNumber?: 'latest' | number) => Promise<any>;
4
4
  export declare const getCbETHApr: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
5
5
  export declare const getREthApr: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
6
+ export declare const getDsrApy: (web3: Web3, blockNumber?: 'latest' | number) => Promise<string>;
6
7
  export declare const getStakingApy: (asset: string, web3: Web3, blockNumber?: 'latest' | number, fromBlock?: number | undefined) => Promise<any> | undefined;
7
8
  export declare const calculateInterestEarned: (principal: string, interest: string, type: string, apy?: boolean) => number;
8
9
  export declare const calculateNetApy: (usedAssets: MMUsedAssets, assetsData: MMAssetsData, isMorpho?: boolean) => {
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import Dec from 'decimal.js';
11
- import { CbEthContract, LidoContract, REthContract, wstETHContract, } from '../contracts';
11
+ import { CbEthContract, LidoContract, PotContract, REthContract, wstETHContract, } from '../contracts';
12
12
  import { NetworkNumber } from '../types/common';
13
13
  import { BLOCKS_IN_A_YEAR, SECONDS_PER_YEAR, AVG_BLOCK_TIME } from '../constants';
14
14
  import { multicall } from '../multicall';
@@ -67,6 +67,15 @@ export const getREthApr = (web3, blockNumber = 'latest') => __awaiter(void 0, vo
67
67
  .toString();
68
68
  return apr;
69
69
  });
70
+ export const getDsrApy = (web3, blockNumber = 'latest') => __awaiter(void 0, void 0, void 0, function* () {
71
+ const potContract = PotContract(web3, NetworkNumber.Eth);
72
+ return new Dec(yield potContract.methods.dsr().call())
73
+ .div(new Dec(1e27))
74
+ .pow(SECONDS_PER_YEAR)
75
+ .sub(1)
76
+ .mul(100)
77
+ .toString();
78
+ });
70
79
  export const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = undefined) => {
71
80
  if (asset === 'stETH' || asset === 'wstETH')
72
81
  return getStETHApr(web3, fromBlock, blockNumber);
@@ -74,6 +83,8 @@ export const getStakingApy = (asset, web3, blockNumber = 'latest', fromBlock = u
74
83
  return getCbETHApr(web3, blockNumber);
75
84
  if (asset === 'rETH')
76
85
  return getREthApr(web3, blockNumber);
86
+ if (asset === 'sDAI')
87
+ return getDsrApy(web3);
77
88
  };
78
89
  export const calculateInterestEarned = (principal, interest, type, apy = false) => {
79
90
  let interval = 1;
@@ -0,0 +1,41 @@
1
+ export type ChickenBondsSystemInfoStructOutputStruct = {
2
+ totalPendingLUSD: string;
3
+ totalReserveLUSD: string;
4
+ totalPermanentLUSD: string;
5
+ ownedLUSDInSP: string;
6
+ ownedLUSDInCurve: string;
7
+ systemBackingRatio: string;
8
+ accrualParameter: string;
9
+ chickenInAMMFee: string;
10
+ numPendingBonds: string;
11
+ numChickenInBonds: string;
12
+ numChickenOutBonds: string;
13
+ bLUSDSupply: string;
14
+ };
15
+ export interface ChickenBondsSystemInfoBasic extends ChickenBondsSystemInfoStructOutputStruct {
16
+ totalWeightedStartTimes: string;
17
+ targetAverageAgeMs: number;
18
+ acquiredLUSDInSP: string;
19
+ acquiredLUSDInCurve: string;
20
+ yTokensHeldByCBM: string;
21
+ floorPrice: string;
22
+ averageBondAgeMs: number;
23
+ }
24
+ export interface BondInfoBasic {
25
+ bondId: string;
26
+ status: string;
27
+ startTime: Date;
28
+ endTime: Date;
29
+ accruedBLUSD: string;
30
+ claimedBLUSD: string;
31
+ lusdAmount: string;
32
+ maxAmountBLUSD: string;
33
+ }
34
+ export declare enum BondStatus {
35
+ Nonexistent = "0",
36
+ Active = "1",
37
+ ChickenedOut = "2",
38
+ ChickenedIn = "3",
39
+ BrokeEven = "4",
40
+ Rebondable = "5"
41
+ }
@@ -0,0 +1,10 @@
1
+ export var BondStatus;
2
+ (function (BondStatus) {
3
+ // Order [0, 3] is set on contract
4
+ BondStatus["Nonexistent"] = "0";
5
+ BondStatus["Active"] = "1";
6
+ BondStatus["ChickenedOut"] = "2";
7
+ BondStatus["ChickenedIn"] = "3";
8
+ BondStatus["BrokeEven"] = "4";
9
+ BondStatus["Rebondable"] = "5";
10
+ })(BondStatus || (BondStatus = {}));
@@ -0,0 +1,28 @@
1
+ /// <reference types="node" />
2
+ import type BN from "bn.js";
3
+ import type { ContractOptions } from "web3-eth-contract";
4
+ import type { EventLog } from "web3-core";
5
+ import type { EventEmitter } from "events";
6
+ import type { Callback, NonPayableTransactionObject, BlockType, BaseContract } from "./types";
7
+ export interface EventOptions {
8
+ filter?: object;
9
+ fromBlock?: BlockType;
10
+ topics?: string[];
11
+ }
12
+ export interface ChickenBondsManager extends BaseContract {
13
+ constructor(jsonInterface: any[], address?: string, options?: ContractOptions): ChickenBondsManager;
14
+ clone(): ChickenBondsManager;
15
+ methods: {
16
+ chickenIn(_bondID: number | string | BN): NonPayableTransactionObject<void>;
17
+ chickenOut(_bondID: number | string | BN, _minLUSD: number | string | BN): NonPayableTransactionObject<void>;
18
+ createBond(_lusdAmount: number | string | BN): NonPayableTransactionObject<string>;
19
+ getAcquiredLUSDInCurve(): NonPayableTransactionObject<string>;
20
+ getAcquiredLUSDInSP(): NonPayableTransactionObject<string>;
21
+ redeem(_bLUSDToRedeem: number | string | BN, _minLUSDFromBAMMSPVault: number | string | BN): NonPayableTransactionObject<[string, string]>;
22
+ totalWeightedStartTimes(): NonPayableTransactionObject<string>;
23
+ yTokensHeldByCBM(): NonPayableTransactionObject<string>;
24
+ };
25
+ events: {
26
+ allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
27
+ };
28
+ }
@@ -0,0 +1,4 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ export {};
@@ -54,12 +54,80 @@ export declare namespace ChickenBondsView {
54
54
  tokenURI: string;
55
55
  };
56
56
  type BondDataFullStructOutput = BondDataFullStructOutputArray & BondDataFullStructOutputStruct;
57
+ type ChickenBondsSystemInfoStruct = [
58
+ number | string | BN,
59
+ number | string | BN,
60
+ number | string | BN,
61
+ number | string | BN,
62
+ number | string | BN,
63
+ number | string | BN,
64
+ number | string | BN,
65
+ number | string | BN,
66
+ number | string | BN,
67
+ number | string | BN,
68
+ number | string | BN,
69
+ number | string | BN
70
+ ] | {
71
+ totalPendingLUSD: number | string | BN;
72
+ totalReserveLUSD: number | string | BN;
73
+ totalPermanentLUSD: number | string | BN;
74
+ ownedLUSDInSP: number | string | BN;
75
+ ownedLUSDInCurve: number | string | BN;
76
+ systemBackingRatio: number | string | BN;
77
+ accrualParameter: number | string | BN;
78
+ chickenInAMMFee: number | string | BN;
79
+ numPendingBonds: number | string | BN;
80
+ numChickenInBonds: number | string | BN;
81
+ numChickenOutBonds: number | string | BN;
82
+ bLUSDSupply: number | string | BN;
83
+ };
84
+ type ChickenBondsSystemInfoStructOutputArray = [
85
+ string,
86
+ string,
87
+ string,
88
+ string,
89
+ string,
90
+ string,
91
+ string,
92
+ string,
93
+ string,
94
+ string,
95
+ string,
96
+ string
97
+ ];
98
+ type ChickenBondsSystemInfoStructOutputStruct = {
99
+ totalPendingLUSD: string;
100
+ totalReserveLUSD: string;
101
+ totalPermanentLUSD: string;
102
+ ownedLUSDInSP: string;
103
+ ownedLUSDInCurve: string;
104
+ systemBackingRatio: string;
105
+ accrualParameter: string;
106
+ chickenInAMMFee: string;
107
+ numPendingBonds: string;
108
+ numChickenInBonds: string;
109
+ numChickenOutBonds: string;
110
+ bLUSDSupply: string;
111
+ };
112
+ type ChickenBondsSystemInfoStructOutput = ChickenBondsSystemInfoStructOutputArray & ChickenBondsSystemInfoStructOutputStruct;
57
113
  }
58
114
  export interface ChickenBondsView extends BaseContract {
59
115
  constructor(jsonInterface: any[], address?: string, options?: ContractOptions): ChickenBondsView;
60
116
  clone(): ChickenBondsView;
61
117
  methods: {
118
+ BorrowerOperations(): NonPayableTransactionObject<string>;
119
+ CBManager(): NonPayableTransactionObject<string>;
120
+ CollSurplusPool(): NonPayableTransactionObject<string>;
121
+ HintHelpers(): NonPayableTransactionObject<string>;
122
+ LQTYStaking(): NonPayableTransactionObject<string>;
123
+ LUSD_GAS_COMPENSATION(): NonPayableTransactionObject<string>;
124
+ PriceFeed(): NonPayableTransactionObject<string>;
125
+ SortedTroves(): NonPayableTransactionObject<string>;
126
+ StabilityPool(): NonPayableTransactionObject<string>;
127
+ TroveManager(): NonPayableTransactionObject<string>;
62
128
  getBondFullInfo(_bondID: number | string | BN): NonPayableTransactionObject<ChickenBondsView.BondDataFullStructOutput>;
129
+ getSystemInfo(): NonPayableTransactionObject<ChickenBondsView.ChickenBondsSystemInfoStructOutput>;
130
+ getUsersBonds(_userAddr: string): NonPayableTransactionObject<ChickenBondsView.BondDataFullStructOutput[]>;
63
131
  };
64
132
  events: {
65
133
  allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
@@ -8,6 +8,7 @@ export type { AaveV3ProtocolDataProvider } from "./AaveV3ProtocolDataProvider";
8
8
  export type { AaveV3View } from "./AaveV3View";
9
9
  export type { BalanceScanner } from "./BalanceScanner";
10
10
  export type { CbEth } from "./CbEth";
11
+ export type { ChickenBondsManager } from "./ChickenBondsManager";
11
12
  export type { ChickenBondsView } from "./ChickenBondsView";
12
13
  export type { CollSurplusPool } from "./CollSurplusPool";
13
14
  export type { CompV3ETHBulker } from "./CompV3ETHBulker";
@@ -4,3 +4,4 @@ export * from './spark';
4
4
  export * from './curveUsd';
5
5
  export * from './liquity';
6
6
  export * from './maker';
7
+ export * from './chickenBonds';
@@ -4,3 +4,4 @@ export * from './spark';
4
4
  export * from './curveUsd';
5
5
  export * from './liquity';
6
6
  export * from './maker';
7
+ export * from './chickenBonds';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -244,7 +244,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
244
244
  await Promise.all(assetsData.map(async (_market: AaveV3AssetData) => {
245
245
  /* eslint-disable no-param-reassign */
246
246
  const rewardForMarket: IUiIncentiveDataProviderV3.AggregatedReserveIncentiveDataStructOutput | undefined = rewardInfo?.[_market.underlyingTokenAddress as any];
247
- if (['wstETH', 'cbETH', 'rETH'].includes(_market.symbol)) {
247
+ if (['wstETH', 'cbETH', 'rETH', 'sDAI'].includes(_market.symbol)) {
248
248
  if (!isLayer2Network(network) && _market.symbol === 'cbETH') return;
249
249
  _market.incentiveSupplyApy = await getStakingApy(_market.symbol, defaultWeb3);
250
250
  _market.incentiveSupplyToken = _market.symbol;
@@ -1,11 +1,15 @@
1
1
  import Web3 from 'web3';
2
+ import Dec from 'decimal.js';
2
3
 
3
4
  import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
4
5
  import {
5
6
  Blockish, NetworkNumber, PositionBalances,
6
7
  } from '../types/common';
7
8
 
8
- import { ChickenBondsViewContract } from '../contracts';
9
+ import { ChickenBondsManagerContract, ChickenBondsViewContract } from '../contracts';
10
+ import { BondInfoBasic, ChickenBondsSystemInfoBasic } from '../types';
11
+ import { multicall } from '../multicall';
12
+ import { calcAverageBondAgeMs, calcCBondsBLUSDFloorPrice } from '../helpers/chickenBondsHelpers';
9
13
 
10
14
  export const getChickenBondsAccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, bondId: string): Promise<PositionBalances> => {
11
15
  const viewContract = ChickenBondsViewContract(web3, network, block);
@@ -18,3 +22,101 @@ export const getChickenBondsAccountBalances = async (web3: Web3, network: Networ
18
22
  },
19
23
  };
20
24
  };
25
+
26
+ export const fetchCBondsSystemInfo = async (web3: Web3, network: NetworkNumber): Promise<ChickenBondsSystemInfoBasic> => {
27
+ const cBondsView = ChickenBondsViewContract(web3, network);
28
+ const cBondsManager = ChickenBondsManagerContract(web3, network);
29
+ const multicallData = [
30
+ {
31
+ target: cBondsView.options.address,
32
+ abiItem: cBondsView.options.jsonInterface.find(({ name }) => name === 'getSystemInfo'),
33
+ params: [],
34
+ },
35
+ {
36
+ target: cBondsManager.options.address,
37
+ abiItem: cBondsManager.options.jsonInterface.find(({ name }) => name === 'totalWeightedStartTimes'),
38
+ params: [],
39
+ },
40
+ {
41
+ target: cBondsManager.options.address,
42
+ abiItem: cBondsManager.options.jsonInterface.find(({ name }) => name === 'getAcquiredLUSDInSP'),
43
+ params: [],
44
+ },
45
+ {
46
+ target: cBondsManager.options.address,
47
+ abiItem: cBondsManager.options.jsonInterface.find(({ name }) => name === 'getAcquiredLUSDInCurve'),
48
+ params: [],
49
+ },
50
+ {
51
+ target: cBondsManager.options.address,
52
+ abiItem: cBondsManager.options.jsonInterface.find(({ name }) => name === 'yTokensHeldByCBM'),
53
+ params: [],
54
+ },
55
+ ];
56
+ const [{ 0: systemInfo }, { 0: totalWeightedStartTimes }, { 0: acquiredLUSDInSP }, { 0: acquiredLUSDInCurve }, { 0: yTokensHeldByCBM }] = await multicall(multicallData, web3, network);
57
+ const payload = {
58
+ numPendingBonds: systemInfo.numPendingBonds,
59
+ numChickenInBonds: systemInfo.numChickenInBonds,
60
+ numChickenOutBonds: systemInfo.numChickenOutBonds,
61
+ accrualParameter: new Dec(assetAmountInEth(systemInfo.accrualParameter)).mul(1000).toString(),
62
+ bLUSDSupply: assetAmountInEth(systemInfo.bLUSDSupply, 'bLUSD'),
63
+ chickenInAMMFee: assetAmountInEth(systemInfo.chickenInAMMFee),
64
+ ownedLUSDInCurve: assetAmountInEth(systemInfo.ownedLUSDInCurve, 'LUSD'),
65
+ systemBackingRatio: assetAmountInEth(systemInfo.systemBackingRatio),
66
+ ownedLUSDInSP: assetAmountInEth(systemInfo.ownedLUSDInSP, 'LUSD'),
67
+ totalPendingLUSD: assetAmountInEth(systemInfo.totalPendingLUSD, 'LUSD'),
68
+ totalPermanentLUSD: assetAmountInEth(systemInfo.totalPermanentLUSD, 'LUSD'),
69
+ totalReserveLUSD: assetAmountInEth(systemInfo.totalReserveLUSD, 'LUSD'),
70
+ targetAverageAgeMs: 1296000000,
71
+ totalWeightedStartTimes: assetAmountInEth(totalWeightedStartTimes),
72
+ acquiredLUSDInSP: assetAmountInEth(acquiredLUSDInSP, 'LUSD'),
73
+ acquiredLUSDInCurve: assetAmountInEth(acquiredLUSDInCurve, 'LUSD'),
74
+ yTokensHeldByCBM: assetAmountInEth(yTokensHeldByCBM, 'ETH'), // yTokens is 18 decimals
75
+ };
76
+
77
+ const floorPrice = calcCBondsBLUSDFloorPrice(payload.bLUSDSupply, payload.totalReserveLUSD);
78
+ const averageBondAgeMs = calcAverageBondAgeMs(payload.totalWeightedStartTimes, payload.totalPendingLUSD);
79
+
80
+ return {
81
+ ...payload,
82
+ floorPrice,
83
+ averageBondAgeMs,
84
+ };
85
+ };
86
+
87
+ export const fetchCBondsForUser = async (web3: Web3, network: NetworkNumber, address: string): Promise<BondInfoBasic[]> => {
88
+ const cBondsView = ChickenBondsViewContract(web3, network);
89
+
90
+ const bonds = await cBondsView.methods.getUsersBonds(address).call();
91
+
92
+ return bonds.map(({
93
+ bondID, accruedBLUSD, claimedBLUSD, endTime, lusdAmount, maxAmountBLUSD, startTime, status, tokenURI,
94
+ }) => ({
95
+ bondId: bondID,
96
+ status,
97
+ // tokenURI: decodeTokenURIToSvg(tokenURI),
98
+ startTime: new Date(+startTime * 1000),
99
+ endTime: new Date(+endTime * 1000),
100
+ accruedBLUSD: assetAmountInEth(accruedBLUSD, 'bLUSD'),
101
+ claimedBLUSD: assetAmountInEth(claimedBLUSD, 'bLUSD'),
102
+ lusdAmount: assetAmountInEth(lusdAmount, 'LUSD'),
103
+ maxAmountBLUSD: assetAmountInEth(maxAmountBLUSD, 'bLUSD'),
104
+ }));
105
+ };
106
+
107
+ export const fetchCBondForId = async (web3: Web3, network: NetworkNumber, bondId: string): Promise<BondInfoBasic> => {
108
+ const cBondsView = ChickenBondsViewContract(web3, network);
109
+
110
+ const bond = await cBondsView.methods.getBondFullInfo(bondId).call();
111
+
112
+ return {
113
+ bondId,
114
+ status: bond.status,
115
+ startTime: new Date(+bond.startTime * 1000),
116
+ endTime: new Date(+bond.endTime * 1000),
117
+ accruedBLUSD: assetAmountInEth(bond.accruedBLUSD, 'bLUSD'),
118
+ claimedBLUSD: assetAmountInEth(bond.claimedBLUSD, 'bLUSD'),
119
+ lusdAmount: assetAmountInEth(bond.lusdAmount, 'LUSD'),
120
+ maxAmountBLUSD: assetAmountInEth(bond.maxAmountBLUSD, 'bLUSD'),
121
+ };
122
+ };