@defisaver/positions-sdk 0.0.4 → 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 (48) hide show
  1. package/cjs/chickenBonds/index.d.ts +4 -0
  2. package/cjs/chickenBonds/index.js +94 -1
  3. package/cjs/config/contracts.d.ts +36 -2
  4. package/cjs/config/contracts.js +7 -1
  5. package/cjs/contracts.d.ts +1 -0
  6. package/cjs/contracts.js +2 -1
  7. package/cjs/helpers/chickenBondsHelpers/index.d.ts +2 -0
  8. package/cjs/helpers/chickenBondsHelpers/index.js +19 -0
  9. package/cjs/helpers/index.d.ts +1 -0
  10. package/cjs/helpers/index.js +2 -1
  11. package/cjs/types/chickenBonds.d.ts +41 -0
  12. package/cjs/types/chickenBonds.js +13 -0
  13. package/cjs/types/contracts/generated/ChickenBondsManager.d.ts +28 -0
  14. package/cjs/types/contracts/generated/ChickenBondsManager.js +5 -0
  15. package/cjs/types/contracts/generated/ChickenBondsView.d.ts +68 -0
  16. package/cjs/types/contracts/generated/index.d.ts +1 -0
  17. package/cjs/types/index.d.ts +1 -0
  18. package/cjs/types/index.js +1 -0
  19. package/esm/chickenBonds/index.d.ts +4 -0
  20. package/esm/chickenBonds/index.js +89 -2
  21. package/esm/config/contracts.d.ts +36 -2
  22. package/esm/config/contracts.js +7 -1
  23. package/esm/contracts.d.ts +1 -0
  24. package/esm/contracts.js +1 -0
  25. package/esm/helpers/chickenBondsHelpers/index.d.ts +2 -0
  26. package/esm/helpers/chickenBondsHelpers/index.js +11 -0
  27. package/esm/helpers/index.d.ts +1 -0
  28. package/esm/helpers/index.js +1 -0
  29. package/esm/types/chickenBonds.d.ts +41 -0
  30. package/esm/types/chickenBonds.js +10 -0
  31. package/esm/types/contracts/generated/ChickenBondsManager.d.ts +28 -0
  32. package/esm/types/contracts/generated/ChickenBondsManager.js +4 -0
  33. package/esm/types/contracts/generated/ChickenBondsView.d.ts +68 -0
  34. package/esm/types/contracts/generated/index.d.ts +1 -0
  35. package/esm/types/index.d.ts +1 -0
  36. package/esm/types/index.js +1 -0
  37. package/package.json +1 -1
  38. package/src/chickenBonds/index.ts +103 -1
  39. package/src/config/contracts.js +8 -2
  40. package/src/contracts.ts +3 -1
  41. package/src/helpers/chickenBondsHelpers/index.ts +13 -0
  42. package/src/helpers/index.ts +2 -1
  43. package/src/types/chickenBonds.ts +45 -0
  44. package/src/types/contracts/generated/ChickenBondsManager.ts +59 -0
  45. package/src/types/contracts/generated/ChickenBondsView.ts +88 -0
  46. package/src/types/contracts/generated/index.ts +1 -0
  47. package/src/types/index.ts +2 -1
  48. package/yarn-error.log +0 -64
@@ -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';
@@ -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.4",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -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
+ };
@@ -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';
@@ -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
+ }