@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
@@ -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
- "1": {
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
  }
package/src/contracts.ts CHANGED
@@ -92,4 +92,6 @@ export const McdSpotterContract = createContractFromConfigFunc<ContractTypes.Mcd
92
92
  export const McdDogContract = createContractFromConfigFunc<ContractTypes.McdDog>('McdDog');
93
93
  export const McdJugContract = createContractFromConfigFunc<ContractTypes.McdJug>('McdJug');
94
94
  export const McdVatContract = createContractFromConfigFunc<ContractTypes.McdVat>('McdVat');
95
- export const ChickenBondsViewContract = createContractFromConfigFunc<ContractTypes.ChickenBondsView>('ChickenBondsView');
95
+
96
+ export const ChickenBondsViewContract = createContractFromConfigFunc<ContractTypes.ChickenBondsView>('ChickenBondsView');
97
+ export const ChickenBondsManagerContract = createContractFromConfigFunc<ContractTypes.ChickenBondsManager>('ChickenBondsManager');
@@ -0,0 +1,13 @@
1
+ import Dec from 'decimal.js';
2
+
3
+ export const calcCBondsBLUSDFloorPrice = (bLUSDSupply: string, totalReserveLUSD: string) => {
4
+ if (new Dec(bLUSDSupply).eq(0)) return '1';
5
+ return new Dec(totalReserveLUSD).div(bLUSDSupply).toString();
6
+ };
7
+
8
+ export const calcAverageBondAgeMs = (totalWeightedStartTimes: string, totalPendingLusd: string) => {
9
+ const averageStartTimeMs = new Dec(totalWeightedStartTimes).div(totalPendingLusd).round().mul(1000)
10
+ .toNumber();
11
+
12
+ return Date.now() - averageStartTimeMs;
13
+ };
@@ -2,4 +2,5 @@ export * as aaveHelpers from './aaveHelpers';
2
2
  export * as compoundHelpers from './compoundHelpers';
3
3
  export * as sparkHelpers from './sparkHelpers';
4
4
  export * as curveUsdHelpers from './curveUsdHelpers';
5
- export * as makerHelpers from './makerHelpers';
5
+ export * as makerHelpers from './makerHelpers';
6
+ export * as chickenBondsHelpers from './chickenBondsHelpers';
@@ -1,7 +1,7 @@
1
1
  import Dec from 'decimal.js';
2
2
  import Web3 from 'web3';
3
3
  import {
4
- CbEthContract, LidoContract, REthContract, wstETHContract,
4
+ CbEthContract, LidoContract, PotContract, REthContract, wstETHContract,
5
5
  } from '../contracts';
6
6
  import { MMAssetsData, MMUsedAssets, NetworkNumber } from '../types/common';
7
7
  import { ContractEventLog } from '../types/contracts/generated/types';
@@ -66,10 +66,21 @@ export const getREthApr = async (web3: Web3, blockNumber: 'latest' | number = 'l
66
66
  return apr;
67
67
  };
68
68
 
69
+ export const getDsrApy = async (web3: Web3, blockNumber: 'latest' | number = 'latest') => {
70
+ const potContract = PotContract(web3, NetworkNumber.Eth);
71
+ return new Dec(await potContract.methods.dsr().call())
72
+ .div(new Dec(1e27))
73
+ .pow(SECONDS_PER_YEAR)
74
+ .sub(1)
75
+ .mul(100)
76
+ .toString();
77
+ };
78
+
69
79
  export const getStakingApy = (asset: string, web3: Web3, blockNumber: 'latest' | number = 'latest', fromBlock: number | undefined = undefined) => {
70
80
  if (asset === 'stETH' || asset === 'wstETH') return getStETHApr(web3, fromBlock, blockNumber);
71
81
  if (asset === 'cbETH') return getCbETHApr(web3, blockNumber);
72
82
  if (asset === 'rETH') return getREthApr(web3, blockNumber);
83
+ if (asset === 'sDAI') return getDsrApy(web3);
73
84
  };
74
85
 
75
86
  export const calculateInterestEarned = (principal: string, interest: string, type: string, apy = false) => {
@@ -0,0 +1,45 @@
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
+
16
+ export interface ChickenBondsSystemInfoBasic extends ChickenBondsSystemInfoStructOutputStruct {
17
+ totalWeightedStartTimes: string
18
+ targetAverageAgeMs: number
19
+ acquiredLUSDInSP: string
20
+ acquiredLUSDInCurve: string
21
+ yTokensHeldByCBM: string
22
+ floorPrice: string
23
+ averageBondAgeMs: number
24
+ }
25
+
26
+ export interface BondInfoBasic {
27
+ bondId: string,
28
+ status: string,
29
+ startTime: Date,
30
+ endTime: Date,
31
+ accruedBLUSD: string,
32
+ claimedBLUSD: string,
33
+ lusdAmount: string,
34
+ maxAmountBLUSD: string,
35
+ }
36
+
37
+ export enum BondStatus {
38
+ // Order [0, 3] is set on contract
39
+ Nonexistent = '0',
40
+ Active = '1',
41
+ ChickenedOut = '2',
42
+ ChickenedIn = '3',
43
+ BrokeEven = '4',
44
+ Rebondable = '5',
45
+ }
@@ -0,0 +1,59 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+
5
+ import type BN from "bn.js";
6
+ import type { ContractOptions } from "web3-eth-contract";
7
+ import type { EventLog } from "web3-core";
8
+ import type { EventEmitter } from "events";
9
+ import type {
10
+ Callback,
11
+ PayableTransactionObject,
12
+ NonPayableTransactionObject,
13
+ BlockType,
14
+ ContractEventLog,
15
+ BaseContract,
16
+ } from "./types";
17
+
18
+ export interface EventOptions {
19
+ filter?: object;
20
+ fromBlock?: BlockType;
21
+ topics?: string[];
22
+ }
23
+
24
+ export interface ChickenBondsManager extends BaseContract {
25
+ constructor(
26
+ jsonInterface: any[],
27
+ address?: string,
28
+ options?: ContractOptions
29
+ ): ChickenBondsManager;
30
+ clone(): ChickenBondsManager;
31
+ methods: {
32
+ chickenIn(_bondID: number | string | BN): NonPayableTransactionObject<void>;
33
+
34
+ chickenOut(
35
+ _bondID: number | string | BN,
36
+ _minLUSD: number | string | BN
37
+ ): NonPayableTransactionObject<void>;
38
+
39
+ createBond(
40
+ _lusdAmount: number | string | BN
41
+ ): NonPayableTransactionObject<string>;
42
+
43
+ getAcquiredLUSDInCurve(): NonPayableTransactionObject<string>;
44
+
45
+ getAcquiredLUSDInSP(): NonPayableTransactionObject<string>;
46
+
47
+ redeem(
48
+ _bLUSDToRedeem: number | string | BN,
49
+ _minLUSDFromBAMMSPVault: number | string | BN
50
+ ): NonPayableTransactionObject<[string, string]>;
51
+
52
+ totalWeightedStartTimes(): NonPayableTransactionObject<string>;
53
+
54
+ yTokensHeldByCBM(): NonPayableTransactionObject<string>;
55
+ };
56
+ events: {
57
+ allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
58
+ };
59
+ }
@@ -70,6 +70,68 @@ export declare namespace ChickenBondsView {
70
70
  };
71
71
  export type BondDataFullStructOutput = BondDataFullStructOutputArray &
72
72
  BondDataFullStructOutputStruct;
73
+
74
+ export type ChickenBondsSystemInfoStruct =
75
+ | [
76
+ number | string | BN,
77
+ number | string | BN,
78
+ number | string | BN,
79
+ number | string | BN,
80
+ number | string | BN,
81
+ number | string | BN,
82
+ number | string | BN,
83
+ number | string | BN,
84
+ number | string | BN,
85
+ number | string | BN,
86
+ number | string | BN,
87
+ number | string | BN
88
+ ]
89
+ | {
90
+ totalPendingLUSD: number | string | BN;
91
+ totalReserveLUSD: number | string | BN;
92
+ totalPermanentLUSD: number | string | BN;
93
+ ownedLUSDInSP: number | string | BN;
94
+ ownedLUSDInCurve: number | string | BN;
95
+ systemBackingRatio: number | string | BN;
96
+ accrualParameter: number | string | BN;
97
+ chickenInAMMFee: number | string | BN;
98
+ numPendingBonds: number | string | BN;
99
+ numChickenInBonds: number | string | BN;
100
+ numChickenOutBonds: number | string | BN;
101
+ bLUSDSupply: number | string | BN;
102
+ };
103
+
104
+ export type ChickenBondsSystemInfoStructOutputArray = [
105
+ string,
106
+ string,
107
+ string,
108
+ string,
109
+ string,
110
+ string,
111
+ string,
112
+ string,
113
+ string,
114
+ string,
115
+ string,
116
+ string
117
+ ];
118
+ export type ChickenBondsSystemInfoStructOutputStruct = {
119
+ totalPendingLUSD: string;
120
+ totalReserveLUSD: string;
121
+ totalPermanentLUSD: string;
122
+ ownedLUSDInSP: string;
123
+ ownedLUSDInCurve: string;
124
+ systemBackingRatio: string;
125
+ accrualParameter: string;
126
+ chickenInAMMFee: string;
127
+ numPendingBonds: string;
128
+ numChickenInBonds: string;
129
+ numChickenOutBonds: string;
130
+ bLUSDSupply: string;
131
+ };
132
+ export type ChickenBondsSystemInfoStructOutput =
133
+ ChickenBondsSystemInfoStructOutputArray &
134
+ ChickenBondsSystemInfoStructOutputStruct;
73
135
  }
74
136
 
75
137
  export interface ChickenBondsView extends BaseContract {
@@ -80,9 +142,35 @@ export interface ChickenBondsView extends BaseContract {
80
142
  ): ChickenBondsView;
81
143
  clone(): ChickenBondsView;
82
144
  methods: {
145
+ BorrowerOperations(): NonPayableTransactionObject<string>;
146
+
147
+ CBManager(): NonPayableTransactionObject<string>;
148
+
149
+ CollSurplusPool(): NonPayableTransactionObject<string>;
150
+
151
+ HintHelpers(): NonPayableTransactionObject<string>;
152
+
153
+ LQTYStaking(): NonPayableTransactionObject<string>;
154
+
155
+ LUSD_GAS_COMPENSATION(): NonPayableTransactionObject<string>;
156
+
157
+ PriceFeed(): NonPayableTransactionObject<string>;
158
+
159
+ SortedTroves(): NonPayableTransactionObject<string>;
160
+
161
+ StabilityPool(): NonPayableTransactionObject<string>;
162
+
163
+ TroveManager(): NonPayableTransactionObject<string>;
164
+
83
165
  getBondFullInfo(
84
166
  _bondID: number | string | BN
85
167
  ): NonPayableTransactionObject<ChickenBondsView.BondDataFullStructOutput>;
168
+
169
+ getSystemInfo(): NonPayableTransactionObject<ChickenBondsView.ChickenBondsSystemInfoStructOutput>;
170
+
171
+ getUsersBonds(
172
+ _userAddr: string
173
+ ): NonPayableTransactionObject<ChickenBondsView.BondDataFullStructOutput[]>;
86
174
  };
87
175
  events: {
88
176
  allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
@@ -11,6 +11,7 @@ export type { AaveV3ProtocolDataProvider } from "./AaveV3ProtocolDataProvider";
11
11
  export type { AaveV3View } from "./AaveV3View";
12
12
  export type { BalanceScanner } from "./BalanceScanner";
13
13
  export type { CbEth } from "./CbEth";
14
+ export type { ChickenBondsManager } from "./ChickenBondsManager";
14
15
  export type { ChickenBondsView } from "./ChickenBondsView";
15
16
  export type { CollSurplusPool } from "./CollSurplusPool";
16
17
  export type { CompV3ETHBulker } from "./CompV3ETHBulker";
@@ -3,4 +3,5 @@ export * from './compound';
3
3
  export * from './spark';
4
4
  export * from './curveUsd';
5
5
  export * from './liquity';
6
- export * from './maker';
6
+ export * from './maker';
7
+ export * from './chickenBonds';