@wildcatfi/wildcat-sdk 1.0.15 → 2.0.0

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 (195) hide show
  1. package/README.md +88 -0
  2. package/dist/account.d.ts +42 -43
  3. package/dist/account.d.ts.map +1 -1
  4. package/dist/account.js +120 -95
  5. package/dist/account.js.map +1 -1
  6. package/dist/constants.d.ts +16 -8
  7. package/dist/constants.d.ts.map +1 -1
  8. package/dist/constants.js +30 -12
  9. package/dist/constants.js.map +1 -1
  10. package/dist/controller.d.ts +43 -11
  11. package/dist/controller.d.ts.map +1 -1
  12. package/dist/controller.js +127 -21
  13. package/dist/controller.js.map +1 -1
  14. package/dist/index.d.ts +17 -8
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +30 -8
  17. package/dist/index.js.map +1 -1
  18. package/dist/market.d.ts +105 -0
  19. package/dist/market.d.ts.map +1 -0
  20. package/dist/market.js +263 -0
  21. package/dist/market.js.map +1 -0
  22. package/dist/mockerc20factory.js +1 -1
  23. package/dist/mockerc20factory.js.map +1 -1
  24. package/dist/token.d.ts +2 -3
  25. package/dist/token.d.ts.map +1 -1
  26. package/dist/token.js +7 -8
  27. package/dist/token.js.map +1 -1
  28. package/dist/typechain/IERC20.d.ts +42 -1
  29. package/dist/typechain/IERC20.d.ts.map +1 -1
  30. package/dist/typechain/MarketLens.d.ts +705 -0
  31. package/dist/typechain/MarketLens.d.ts.map +1 -0
  32. package/dist/typechain/{mock/index.js → MarketLens.js} +1 -1
  33. package/dist/typechain/MarketLens.js.map +1 -0
  34. package/dist/typechain/MockArchControllerOwner.d.ts +130 -0
  35. package/dist/typechain/MockArchControllerOwner.d.ts.map +1 -0
  36. package/dist/typechain/{WildcatVaultController.js → MockArchControllerOwner.js} +1 -1
  37. package/dist/typechain/MockArchControllerOwner.js.map +1 -0
  38. package/dist/typechain/{mock/MockERC20Factory.d.ts → MockERC20Factory.d.ts} +4 -3
  39. package/dist/typechain/MockERC20Factory.d.ts.map +1 -0
  40. package/dist/typechain/MockERC20Factory.js.map +1 -0
  41. package/dist/typechain/WildcatArchController.d.ts +525 -0
  42. package/dist/typechain/WildcatArchController.d.ts.map +1 -0
  43. package/dist/typechain/{VaultLens.js → WildcatArchController.js} +1 -1
  44. package/dist/typechain/WildcatArchController.js.map +1 -0
  45. package/dist/typechain/WildcatMarket.d.ts +1060 -0
  46. package/dist/typechain/WildcatMarket.d.ts.map +1 -0
  47. package/dist/typechain/{DebtTokenBase.js → WildcatMarket.js} +1 -1
  48. package/dist/typechain/WildcatMarket.js.map +1 -0
  49. package/dist/typechain/WildcatMarketController.d.ts +437 -0
  50. package/dist/typechain/WildcatMarketController.d.ts.map +1 -0
  51. package/dist/typechain/{WildcatVaultFactory.js → WildcatMarketController.js} +1 -1
  52. package/dist/typechain/WildcatMarketController.js.map +1 -0
  53. package/dist/typechain/WildcatMarketControllerFactory.d.ts +375 -0
  54. package/dist/typechain/WildcatMarketControllerFactory.d.ts.map +1 -0
  55. package/dist/typechain/WildcatMarketControllerFactory.js +3 -0
  56. package/dist/typechain/WildcatMarketControllerFactory.js.map +1 -0
  57. package/dist/typechain/common.d.ts.map +1 -1
  58. package/dist/typechain/factories/IERC20__factory.d.ts +44 -0
  59. package/dist/typechain/factories/IERC20__factory.d.ts.map +1 -1
  60. package/dist/typechain/factories/IERC20__factory.js +57 -0
  61. package/dist/typechain/factories/IERC20__factory.js.map +1 -1
  62. package/dist/typechain/factories/MarketLens__factory.d.ts +3428 -0
  63. package/dist/typechain/factories/MarketLens__factory.d.ts.map +1 -0
  64. package/dist/typechain/factories/MarketLens__factory.js +4389 -0
  65. package/dist/typechain/factories/MarketLens__factory.js.map +1 -0
  66. package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts +85 -0
  67. package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts.map +1 -0
  68. package/dist/typechain/factories/MockArchControllerOwner__factory.js +118 -0
  69. package/dist/typechain/factories/MockArchControllerOwner__factory.js.map +1 -0
  70. package/dist/typechain/factories/MockERC20Factory__factory.d.ts +52 -0
  71. package/dist/typechain/factories/MockERC20Factory__factory.d.ts.map +1 -0
  72. package/dist/typechain/factories/MockERC20Factory__factory.js +75 -0
  73. package/dist/typechain/factories/MockERC20Factory__factory.js.map +1 -0
  74. package/dist/typechain/factories/WildcatArchController__factory.d.ts +536 -0
  75. package/dist/typechain/factories/WildcatArchController__factory.d.ts.map +1 -0
  76. package/dist/typechain/factories/WildcatArchController__factory.js +705 -0
  77. package/dist/typechain/factories/WildcatArchController__factory.js.map +1 -0
  78. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts +431 -0
  79. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts.map +1 -0
  80. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js +561 -0
  81. package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js.map +1 -0
  82. package/dist/typechain/factories/WildcatMarketController__factory.d.ts +517 -0
  83. package/dist/typechain/factories/WildcatMarketController__factory.d.ts.map +1 -0
  84. package/dist/typechain/factories/WildcatMarketController__factory.js +677 -0
  85. package/dist/typechain/factories/WildcatMarketController__factory.js.map +1 -0
  86. package/dist/typechain/factories/{WildcatVaultToken__factory.d.ts → WildcatMarket__factory.d.ts} +640 -93
  87. package/dist/typechain/factories/{VaultLens__factory.d.ts.map → WildcatMarket__factory.d.ts.map} +1 -1
  88. package/dist/typechain/factories/{WildcatVaultToken__factory.js → WildcatMarket__factory.js} +795 -97
  89. package/dist/typechain/factories/WildcatMarket__factory.js.map +1 -0
  90. package/dist/typechain/factories/index.d.ts +7 -5
  91. package/dist/typechain/factories/index.d.ts.map +1 -1
  92. package/dist/typechain/factories/index.js +15 -24
  93. package/dist/typechain/factories/index.js.map +1 -1
  94. package/dist/typechain/index.d.ts +21 -9
  95. package/dist/typechain/index.d.ts.map +1 -1
  96. package/dist/typechain/index.js +29 -3
  97. package/dist/typechain/index.js.map +1 -1
  98. package/dist/utils/assert.d.ts +2 -0
  99. package/dist/utils/assert.d.ts.map +1 -0
  100. package/dist/utils/assert.js +16 -0
  101. package/dist/utils/assert.js.map +1 -0
  102. package/dist/utils/index.d.ts +5 -0
  103. package/dist/utils/index.d.ts.map +1 -0
  104. package/dist/utils/index.js +21 -0
  105. package/dist/utils/index.js.map +1 -0
  106. package/dist/utils/math.d.ts +5 -0
  107. package/dist/utils/math.d.ts.map +1 -0
  108. package/dist/utils/math.js +26 -0
  109. package/dist/utils/math.js.map +1 -0
  110. package/dist/{misc.d.ts → utils/misc.d.ts} +3 -0
  111. package/dist/utils/misc.d.ts.map +1 -0
  112. package/dist/{misc.js → utils/misc.js} +12 -1
  113. package/dist/utils/misc.js.map +1 -0
  114. package/dist/utils/type-parsers.d.ts +24 -0
  115. package/dist/utils/type-parsers.d.ts.map +1 -0
  116. package/dist/utils/type-parsers.js +21 -0
  117. package/dist/utils/type-parsers.js.map +1 -0
  118. package/dist/withdrawal-batch.d.ts +25 -0
  119. package/dist/withdrawal-batch.d.ts.map +1 -0
  120. package/dist/withdrawal-batch.js +38 -0
  121. package/dist/withdrawal-batch.js.map +1 -0
  122. package/dist/withdrawal-status.d.ts +53 -0
  123. package/dist/withdrawal-status.d.ts.map +1 -0
  124. package/dist/withdrawal-status.js +187 -0
  125. package/dist/withdrawal-status.js.map +1 -0
  126. package/package.json +3 -2
  127. package/dist/factory.d.ts +0 -28
  128. package/dist/factory.d.ts.map +0 -1
  129. package/dist/factory.js +0 -50
  130. package/dist/factory.js.map +0 -1
  131. package/dist/misc.d.ts.map +0 -1
  132. package/dist/misc.js.map +0 -1
  133. package/dist/typechain/DebtTokenBase.d.ts +0 -508
  134. package/dist/typechain/DebtTokenBase.d.ts.map +0 -1
  135. package/dist/typechain/DebtTokenBase.js.map +0 -1
  136. package/dist/typechain/VaultLens.d.ts +0 -338
  137. package/dist/typechain/VaultLens.d.ts.map +0 -1
  138. package/dist/typechain/VaultLens.js.map +0 -1
  139. package/dist/typechain/WildcatVaultController.d.ts +0 -331
  140. package/dist/typechain/WildcatVaultController.d.ts.map +0 -1
  141. package/dist/typechain/WildcatVaultController.js.map +0 -1
  142. package/dist/typechain/WildcatVaultFactory.d.ts +0 -161
  143. package/dist/typechain/WildcatVaultFactory.d.ts.map +0 -1
  144. package/dist/typechain/WildcatVaultFactory.js.map +0 -1
  145. package/dist/typechain/WildcatVaultToken.d.ts +0 -653
  146. package/dist/typechain/WildcatVaultToken.d.ts.map +0 -1
  147. package/dist/typechain/WildcatVaultToken.js +0 -3
  148. package/dist/typechain/WildcatVaultToken.js.map +0 -1
  149. package/dist/typechain/factories/VaultLens__factory.d.ts +0 -1540
  150. package/dist/typechain/factories/VaultLens__factory.js +0 -1981
  151. package/dist/typechain/factories/VaultLens__factory.js.map +0 -1
  152. package/dist/typechain/factories/WildcatVaultController__factory.d.ts +0 -440
  153. package/dist/typechain/factories/WildcatVaultController__factory.d.ts.map +0 -1
  154. package/dist/typechain/factories/WildcatVaultController__factory.js +0 -573
  155. package/dist/typechain/factories/WildcatVaultController__factory.js.map +0 -1
  156. package/dist/typechain/factories/WildcatVaultFactory__factory.d.ts +0 -225
  157. package/dist/typechain/factories/WildcatVaultFactory__factory.d.ts.map +0 -1
  158. package/dist/typechain/factories/WildcatVaultFactory__factory.js +0 -299
  159. package/dist/typechain/factories/WildcatVaultFactory__factory.js.map +0 -1
  160. package/dist/typechain/factories/WildcatVaultToken__factory.d.ts.map +0 -1
  161. package/dist/typechain/factories/WildcatVaultToken__factory.js.map +0 -1
  162. package/dist/typechain/factories/mock/ERC20__factory.d.ts +0 -237
  163. package/dist/typechain/factories/mock/ERC20__factory.d.ts.map +0 -1
  164. package/dist/typechain/factories/mock/ERC20__factory.js +0 -317
  165. package/dist/typechain/factories/mock/ERC20__factory.js.map +0 -1
  166. package/dist/typechain/factories/mock/MockERC20Factory__factory.d.ts +0 -65
  167. package/dist/typechain/factories/mock/MockERC20Factory__factory.d.ts.map +0 -1
  168. package/dist/typechain/factories/mock/MockERC20Factory__factory.js +0 -98
  169. package/dist/typechain/factories/mock/MockERC20Factory__factory.js.map +0 -1
  170. package/dist/typechain/factories/mock/MockERC20__factory.d.ts +0 -292
  171. package/dist/typechain/factories/mock/MockERC20__factory.d.ts.map +0 -1
  172. package/dist/typechain/factories/mock/MockERC20__factory.js +0 -394
  173. package/dist/typechain/factories/mock/MockERC20__factory.js.map +0 -1
  174. package/dist/typechain/factories/mock/index.d.ts +0 -4
  175. package/dist/typechain/factories/mock/index.d.ts.map +0 -1
  176. package/dist/typechain/factories/mock/index.js +0 -13
  177. package/dist/typechain/factories/mock/index.js.map +0 -1
  178. package/dist/typechain/mock/ERC20.d.ts +0 -207
  179. package/dist/typechain/mock/ERC20.d.ts.map +0 -1
  180. package/dist/typechain/mock/ERC20.js +0 -3
  181. package/dist/typechain/mock/ERC20.js.map +0 -1
  182. package/dist/typechain/mock/MockERC20.d.ts +0 -247
  183. package/dist/typechain/mock/MockERC20.d.ts.map +0 -1
  184. package/dist/typechain/mock/MockERC20.js +0 -3
  185. package/dist/typechain/mock/MockERC20.js.map +0 -1
  186. package/dist/typechain/mock/MockERC20Factory.d.ts.map +0 -1
  187. package/dist/typechain/mock/MockERC20Factory.js.map +0 -1
  188. package/dist/typechain/mock/index.d.ts +0 -4
  189. package/dist/typechain/mock/index.d.ts.map +0 -1
  190. package/dist/typechain/mock/index.js.map +0 -1
  191. package/dist/vault.d.ts +0 -89
  192. package/dist/vault.d.ts.map +0 -1
  193. package/dist/vault.js +0 -218
  194. package/dist/vault.js.map +0 -1
  195. /package/dist/typechain/{mock/MockERC20Factory.js → MockERC20Factory.js} +0 -0
package/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # MarketController
2
+
3
+ ## Deploying markets
4
+
5
+ ### 1. Get controller info for borrower
6
+
7
+ ```ts
8
+ import { getController, MarketController, MarketParameters } from '@wildcatfi/wildcat-sdk';
9
+
10
+ const controller: MarketController = await getController(signer, borrower);
11
+ ```
12
+
13
+ ### 2. Get parameter constraints for new markets
14
+
15
+ `controller.constraints: MarketParameterConstraints` contains the min/max values of
16
+ - `annualInterestBips`
17
+ - `delinquencyFeeBips`
18
+ - `withdrawalBatchDuration`
19
+ - `reserveRatioBips`
20
+ - `delinquencyGracePeriod`
21
+
22
+ If provided values are out of this range, market deployment will revert.
23
+
24
+
25
+ ### 3. Deploying a mock token for new market
26
+
27
+ ```ts
28
+ import { deployToken } from "@wildcatfi/wildcat-sdk";
29
+
30
+ await deployToken(signer, 'name', 'symbol')
31
+ ```
32
+
33
+ ### 4. Deploying new market
34
+
35
+ ```ts
36
+ const marketParameters: MarketParameters = {...}
37
+
38
+ // 1. Ensure borrower is registered on the arch-controller.
39
+ // For the testnet deployment, anyone can register a borrower
40
+ if (!controller.isRegisteredBorrower) {
41
+ await controller.registerBorrower()
42
+ }
43
+ // 2. Ensure the `asset, namePrefix, symbolPrefix` are unique.
44
+ if (controller.getExistingMarketForParameters(marketParameters)) {
45
+ throw Error()
46
+ }
47
+ // 3. Deploy market
48
+ const market: Market = await controller.deployMarket(marketParameters);
49
+
50
+ ```
51
+
52
+ # Market
53
+
54
+ ## Get market instances
55
+
56
+ ### 1. Get all `Market` instances on Wildcat
57
+
58
+ ```ts
59
+ import { getAllMarkets } from '@wildcatfi/wildcat-sdk';
60
+
61
+ const markets = getAllMarkets(provider);
62
+ ```
63
+
64
+ ### 2. Get all `Market` instances for borrower
65
+
66
+ ```ts
67
+ const controller: MarketController = await getController(signer, borrower);
68
+ // controller.markets has an array of all Market instances for the controller
69
+ ```
70
+
71
+ # MarketAccount
72
+
73
+ ## Get `MarketAccount`
74
+
75
+ ### 1. Get `MarketAccount` for every market
76
+ ```ts
77
+ import { getAllMarketAccountsForLender } from '@wildcatfi/wildcat-sdk';
78
+ const accounts = await getAllMarketAccountsForLender(signer, lenderAddress);
79
+ ```
80
+
81
+ ## Deposit
82
+
83
+ ### 1. Get underlying assets from mock token
84
+ ```ts
85
+ if (market.underlyingToken.isMock) {
86
+ await market.underlyingToken.faucet();
87
+ }
88
+ ```
package/dist/account.d.ts CHANGED
@@ -1,58 +1,62 @@
1
1
  import { BigNumber, ContractTransaction } from "ethers";
2
2
  import { TokenAmount } from "./token";
3
- import { Vault } from "./vault";
4
- import { AccountVaultInfoStructOutput, VaultDataWithAccountStructOutput } from "./typechain";
3
+ import { Market } from "./market";
4
+ import { MarketLenderStatusStructOutput, MarketDataWithLenderStatusStructOutput } from "./typechain";
5
5
  import { SignerOrProvider } from "./types";
6
+ import { LenderWithdrawalStatus } from "./withdrawal-status";
6
7
  export type DepositStatus = {
7
- status: "InsufficientBalance";
8
- } | {
9
- status: "ExceedsMaximumDeposit";
8
+ status: "InsufficientBalance" | "ExceedsMaximumDeposit" | "Ready" | "InsufficientRole";
10
9
  } | {
11
10
  status: "InsufficientAllowance";
12
11
  remainder: TokenAmount;
13
- } | {
14
- status: "Ready";
15
12
  };
16
13
  export type RepayStatus = {
17
- status: "InsufficientBalance";
18
- } | {
19
- status: "ExceedsOutstandingDebt";
14
+ status: "InsufficientBalance" | "ExceedsOutstandingDebt" | "Ready";
20
15
  } | {
21
16
  status: "InsufficientAllowance";
22
17
  remainder: TokenAmount;
23
- } | {
24
- status: "Ready";
25
18
  };
19
+ export declare enum LenderRole {
20
+ Null = 0,
21
+ Blocked = 1,
22
+ WithdrawOnly = 2,
23
+ DepositAndWithdraw = 3
24
+ }
26
25
  /**
27
- * Class to provide information about a vault user's account
26
+ * Class to provide information about a market user's account
28
27
  * and to wrap interactions.
29
28
  *
30
29
  * Use `update()` to update the account's state.
31
30
  *
32
31
  *
33
32
  */
34
- export declare class VaultAccount {
33
+ export declare class MarketAccount {
35
34
  account: string;
36
- vaultBalance: TokenAmount;
35
+ isAuthorizedOnController: boolean;
36
+ role: LenderRole;
37
+ scaledMarketBalance: BigNumber;
38
+ marketBalance: TokenAmount;
37
39
  underlyingBalance: TokenAmount;
38
40
  underlyingApproval: BigNumber;
39
- vault: Vault;
40
- constructor(account: string, vaultBalance: TokenAmount, underlyingBalance: TokenAmount, underlyingApproval: BigNumber, vault: Vault);
41
- static readonly UpdatableKeys: Array<keyof VaultAccount>;
41
+ market: Market;
42
+ constructor(account: string, isAuthorizedOnController: boolean, role: LenderRole, scaledMarketBalance: BigNumber, marketBalance: TokenAmount, underlyingBalance: TokenAmount, underlyingApproval: BigNumber, market: Market);
43
+ static readonly UpdatableKeys: Array<keyof MarketAccount>;
42
44
  get userHasBalance(): boolean;
43
45
  get userHasUnderlyingBalance(): boolean;
44
46
  get isBorrower(): boolean;
47
+ get canDeposit(): boolean;
48
+ get canWithdraw(): boolean;
45
49
  setAPR(newAprBips: number): Promise<ContractTransaction>;
46
50
  isApprovedFor(amount: TokenAmount): boolean;
47
51
  /**
48
52
  * @returns Remaining amount of underlying token user must approve
49
- * vault to spend to make a deposit.
53
+ * market to spend to make a deposit.
50
54
  */
51
55
  getAllowanceRemainder(amount: TokenAmount): TokenAmount;
52
56
  approveAllowanceRemainder(amount: TokenAmount): Promise<ContractTransaction>;
53
57
  /**
54
58
  * @returns Maximum amount of underlying token user can deposit
55
- * given their underlying balance and the vault's max supply
59
+ * given their underlying balance and the market's max supply
56
60
  */
57
61
  get maximumDeposit(): TokenAmount;
58
62
  /**
@@ -67,15 +71,10 @@ export declare class VaultAccount {
67
71
  deposit(amount: TokenAmount): Promise<ContractTransaction>;
68
72
  /**
69
73
  * @returns Amount of underlying token user can withdraw
70
- * given their vault balance and the vault's assets.
74
+ * given their market balance and the market's assets.
71
75
  */
72
76
  get maximumWithdrawal(): TokenAmount;
73
- /**
74
- * @returns Amount of underlying token user can actually withdraw
75
- * given a target amount.
76
- */
77
- getWithdrawalAmount(amount: TokenAmount): TokenAmount;
78
- withdraw(amount: TokenAmount): Promise<ContractTransaction>;
77
+ queueWithdrawal(amount: TokenAmount): Promise<LenderWithdrawalStatus>;
79
78
  get maximumRepay(): TokenAmount;
80
79
  get canRepayDelinquent(): boolean;
81
80
  get canRepayOutstanding(): boolean;
@@ -97,30 +96,30 @@ export declare class VaultAccount {
97
96
  getBorrowableAmount(amount: TokenAmount): TokenAmount;
98
97
  borrow(amount: TokenAmount): Promise<ContractTransaction>;
99
98
  update(): Promise<void>;
100
- applyUpdate(info: AccountVaultInfoStructOutput): void;
101
- static fromAccountVaultInfoStruct(account: string, info: AccountVaultInfoStructOutput, vault: Vault): VaultAccount;
102
- static fromVaultDataWithAccountStruct(provider: SignerOrProvider, account: string, info: VaultDataWithAccountStructOutput): VaultAccount;
99
+ applyUpdate(info: MarketLenderStatusStructOutput): void;
100
+ static fromMarketLenderStatus(account: string, info: MarketLenderStatusStructOutput, market: Market): MarketAccount;
101
+ static fromMarketDataWithLenderStatus(provider: SignerOrProvider, account: string, info: MarketDataWithLenderStatusStructOutput): MarketAccount;
103
102
  /**
104
- * Get a `VaultAccount` for a given account and existing `Vault` instance.
105
- * If `vault` is a string, the vault data will be fetched in the same call as the account data.
103
+ * Get a `MarketAccount` for a given account and existing `Market` instance.
104
+ * If `market` is a string, the market data will be fetched in the same call as the account data.
106
105
  */
107
- static getVaultAccount(provider: SignerOrProvider, account: string, vault: Vault | string): Promise<VaultAccount>;
106
+ static getMarketAccount(provider: SignerOrProvider, account: string, market: Market | string): Promise<MarketAccount>;
108
107
  /**
109
- * Get multiple `VaultAccount`s given an account and existing list of `Vault`
110
- * instances or vault addresses. If `vaults` is an array of strings, the vault
108
+ * Get multiple `MarketAccount`s given an account and existing list of `Market`
109
+ * instances or market addresses. If `markets` is an array of strings, the market
111
110
  * data will be fetched in the same call as the account data.
112
111
  */
113
- static getVaultAccounts(provider: SignerOrProvider, account: string, vaults: Vault[] | string[]): Promise<VaultAccount[]>;
112
+ static getMarketAccountsForLender(provider: SignerOrProvider, account: string, markets: Market[] | string[]): Promise<MarketAccount[]>;
114
113
  /**
115
- * Get all `VaultAccount`s for a given account.
116
- * Fetches the vault data in the same call as the account data.
114
+ * Get all `MarketAccount`s for a given account.
115
+ * Fetches the market data in the same call as the account data.
117
116
  */
118
- static getAllVaultAccounts(provider: SignerOrProvider, account: string): Promise<VaultAccount[]>;
117
+ static getAllMarketAccountsForLender(provider: SignerOrProvider, account: string): Promise<MarketAccount[]>;
119
118
  /**
120
- * Get paginated `VaultAccount`s for a given account.
121
- * Fetches the vault data in the same call as the account data.
122
- * @note Throws an error if `start + count` exceeds the number of vaults.
119
+ * Get paginated `MarketAccount`s for a given account.
120
+ * Fetches the market data in the same call as the account data.
121
+ * @note Throws an error if `start + count` exceeds the number of markets.
123
122
  */
124
- static getPaginatedVaultAccounts(provider: SignerOrProvider, account: string, start: number | undefined, count: number): Promise<VaultAccount[]>;
123
+ static getPaginatedMarketAccounts(provider: SignerOrProvider, account: string, start: number | undefined, count: number): Promise<MarketAccount[]>;
125
124
  }
126
125
  //# sourceMappingURL=account.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,WAAW,EAAkB,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,4BAA4B,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAC;AAG7F,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,MAAM,MAAM,aAAa,GACrB;IACE,MAAM,EAAE,qBAAqB,CAAC;CAC/B,GACD;IACE,MAAM,EAAE,uBAAuB,CAAC;CACjC,GACD;IACE,MAAM,EAAE,uBAAuB,CAAC;IAChC,SAAS,EAAE,WAAW,CAAC;CACxB,GACD;IACE,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAEN,MAAM,MAAM,WAAW,GACnB;IACE,MAAM,EAAE,qBAAqB,CAAC;CAC/B,GACD;IACE,MAAM,EAAE,wBAAwB,CAAC;CAClC,GACD;IACE,MAAM,EAAE,uBAAuB,CAAC;IAChC,SAAS,EAAE,WAAW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AgB,EAC1B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,aAAa,EAAE,CAAC;IAS3B;;;;OAIG;IACH,MAAM,CAAC,0BAA0B,CAC/B,QAAQ,EAAE,gBAAgB,EAC1B,OAAO,EAAE,MAAM,EACf,KAAK,oBAAI,EACT,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,aAAa,EAAE,CAAC;CAQ5B"}
package/dist/account.js CHANGED
@@ -1,37 +1,57 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultAccount = void 0;
3
+ exports.MarketAccount = exports.LenderRole = void 0;
4
4
  const token_1 = require("./token");
5
- const vault_1 = require("./vault");
6
- const misc_1 = require("./misc");
5
+ const market_1 = require("./market");
6
+ const utils_1 = require("./utils");
7
7
  const constants_1 = require("./constants");
8
- const isVaultInstanceArray = (vaults) => {
9
- return typeof vaults[0] !== "string";
8
+ const withdrawal_status_1 = require("./withdrawal-status");
9
+ var LenderRole;
10
+ (function (LenderRole) {
11
+ LenderRole[LenderRole["Null"] = 0] = "Null";
12
+ LenderRole[LenderRole["Blocked"] = 1] = "Blocked";
13
+ LenderRole[LenderRole["WithdrawOnly"] = 2] = "WithdrawOnly";
14
+ LenderRole[LenderRole["DepositAndWithdraw"] = 3] = "DepositAndWithdraw";
15
+ })(LenderRole = exports.LenderRole || (exports.LenderRole = {}));
16
+ const isMarketInstanceArray = (markets) => {
17
+ return typeof markets[0] !== "string";
10
18
  };
11
19
  /**
12
- * Class to provide information about a vault user's account
20
+ * Class to provide information about a market user's account
13
21
  * and to wrap interactions.
14
22
  *
15
23
  * Use `update()` to update the account's state.
16
24
  *
17
25
  *
18
26
  */
19
- class VaultAccount {
20
- constructor(account, vaultBalance, underlyingBalance, underlyingApproval, vault) {
27
+ class MarketAccount {
28
+ constructor(account, isAuthorizedOnController, role, scaledMarketBalance, marketBalance, underlyingBalance, underlyingApproval, market) {
21
29
  this.account = account;
22
- this.vaultBalance = vaultBalance;
30
+ this.isAuthorizedOnController = isAuthorizedOnController;
31
+ this.role = role;
32
+ this.scaledMarketBalance = scaledMarketBalance;
33
+ this.marketBalance = marketBalance;
23
34
  this.underlyingBalance = underlyingBalance;
24
35
  this.underlyingApproval = underlyingApproval;
25
- this.vault = vault;
36
+ this.market = market;
26
37
  }
27
38
  get userHasBalance() {
28
- return this.vaultBalance.gt(0);
39
+ return this.marketBalance.gt(0);
29
40
  }
30
41
  get userHasUnderlyingBalance() {
31
42
  return this.underlyingBalance.gt(0);
32
43
  }
33
44
  get isBorrower() {
34
- return this.vault.borrower.toLowerCase() === this.account.toLowerCase();
45
+ return this.market.borrower.toLowerCase() === this.account.toLowerCase();
46
+ }
47
+ get canDeposit() {
48
+ return (this.role === LenderRole.DepositAndWithdraw ||
49
+ (this.role === LenderRole.Null && this.isAuthorizedOnController));
50
+ }
51
+ get canWithdraw() {
52
+ return (this.role === LenderRole.WithdrawOnly ||
53
+ this.role === LenderRole.DepositAndWithdraw ||
54
+ (this.role === LenderRole.Null && this.isAuthorizedOnController));
35
55
  }
36
56
  async setAPR(newAprBips) {
37
57
  if (!this.isBorrower) {
@@ -40,11 +60,11 @@ class VaultAccount {
40
60
  if (newAprBips > 10000) {
41
61
  throw Error("APR must be less than 100% (10000 BIPS)");
42
62
  }
43
- const controller = (0, constants_1.getControllerContract)(this.vault.provider);
44
- if (this.vault.controller !== controller.address) {
45
- throw Error(`Unexpected controller address: ${this.vault.controller}`);
63
+ const controller = (0, constants_1.getControllerContract)(this.market.provider, this.market.controller);
64
+ if (this.market.controller !== controller.address) {
65
+ throw Error(`Unexpected controller address: ${this.market.controller}`);
46
66
  }
47
- return controller.setAnnualInterestBips(this.vault.address, newAprBips);
67
+ return controller.setAnnualInterestBips(this.market.address, newAprBips);
48
68
  }
49
69
  /* ------ Approval ------ */
50
70
  isApprovedFor(amount) {
@@ -52,27 +72,27 @@ class VaultAccount {
52
72
  }
53
73
  /**
54
74
  * @returns Remaining amount of underlying token user must approve
55
- * vault to spend to make a deposit.
75
+ * market to spend to make a deposit.
56
76
  */
57
77
  getAllowanceRemainder(amount) {
58
78
  return amount.satsub(this.underlyingApproval);
59
79
  }
60
80
  async approveAllowanceRemainder(amount) {
61
- const token = this.vault.underlyingToken;
81
+ const token = this.market.underlyingToken;
62
82
  const signer = await token.signer.getAddress();
63
83
  if (signer !== this.account) {
64
- throw Error(`VaultAccount signer ${signer} does not match ${this.account}`);
84
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
65
85
  }
66
86
  amount = this.getAllowanceRemainder(amount);
67
- return token.contract.approve(this.vault.address, amount.raw);
87
+ return token.contract.approve(this.market.address, amount.raw);
68
88
  }
69
89
  /* ------ Deposits ------ */
70
90
  /**
71
91
  * @returns Maximum amount of underlying token user can deposit
72
- * given their underlying balance and the vault's max supply
92
+ * given their underlying balance and the market's max supply
73
93
  */
74
94
  get maximumDeposit() {
75
- return (0, token_1.minTokenAmount)(this.vault.maximumDeposit, this.underlyingBalance);
95
+ return (0, token_1.minTokenAmount)(this.market.maximumDeposit, this.underlyingBalance);
76
96
  }
77
97
  /**
78
98
  * @returns Amount of underlying token user can actually deposit
@@ -85,7 +105,10 @@ class VaultAccount {
85
105
  * @returns Status for deposit
86
106
  */
87
107
  checkDepositStep(amount) {
88
- if (amount.gt(this.vault.maximumDeposit)) {
108
+ if (!this.canDeposit) {
109
+ return { status: "InsufficientRole" };
110
+ }
111
+ if (amount.gt(this.market.maximumDeposit)) {
89
112
  return { status: "ExceedsMaximumDeposit" };
90
113
  }
91
114
  if (amount.gt(this.underlyingBalance)) {
@@ -101,46 +124,48 @@ class VaultAccount {
101
124
  }
102
125
  // TODO: Add support for depositUpTo
103
126
  async deposit(amount) {
104
- const signer = await this.vault.signer.getAddress();
127
+ const signer = await this.market.signer.getAddress();
105
128
  if (signer !== this.account) {
106
- throw Error(`VaultAccount signer ${signer} does not match ${this.account}`);
129
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
107
130
  }
108
131
  if (amount.gt(this.underlyingBalance)) {
109
132
  throw Error("Insufficient balance");
110
133
  }
111
- return this.vault.contract.deposit(amount.raw, this.account);
134
+ return this.market.contract.deposit(amount.raw);
112
135
  }
113
136
  /* ------ Withdrawals ------ */
114
137
  /**
115
138
  * @returns Amount of underlying token user can withdraw
116
- * given their vault balance and the vault's assets.
139
+ * given their market balance and the market's assets.
117
140
  */
118
141
  get maximumWithdrawal() {
119
- return (0, token_1.minTokenAmount)(this.vault.totalAssets, this.vaultBalance);
142
+ return (0, token_1.minTokenAmount)(this.market.totalAssets, this.marketBalance);
120
143
  }
121
- /**
122
- * @returns Amount of underlying token user can actually withdraw
123
- * given a target amount.
124
- */
125
- getWithdrawalAmount(amount) {
126
- return (0, token_1.minTokenAmount)(amount, this.maximumWithdrawal);
127
- }
128
- async withdraw(amount) {
129
- const signer = await this.vault.signer.getAddress();
144
+ async queueWithdrawal(amount) {
145
+ if (!this.canWithdraw) {
146
+ throw Error(`Lender role insufficient to withdraw`);
147
+ }
148
+ const signer = await this.market.signer.getAddress();
130
149
  if (signer !== this.account) {
131
- throw Error(`VaultAccount signer ${signer} does not match ${this.account}`);
150
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
151
+ }
152
+ const tx = await this.market.contract.queueWithdrawal(amount.raw).then((tx) => tx.wait());
153
+ const queuedWithdrawalTopic = this.market.contract.interface.getEventTopic("QueuedWithdrawal");
154
+ const queuedWithdrawalTransaction = (0, withdrawal_status_1.toQueueWithdrawalTransaction)(this.market.underlyingToken, tx.events.find((e) => e.topics[0] === queuedWithdrawalTopic));
155
+ if (!queuedWithdrawalTransaction) {
156
+ throw Error("No queued withdrawal event found");
132
157
  }
133
- return this.vault.contract.withdraw(amount.raw, this.account);
158
+ return withdrawal_status_1.LenderWithdrawalStatus.getWithdrawalForLender(this.market, queuedWithdrawalTransaction.expiry, this.account);
134
159
  }
135
160
  /* ------ Repaying ------ */
136
161
  get maximumRepay() {
137
- return (0, token_1.minTokenAmount)(this.vault.outstandingDebt, this.underlyingBalance);
162
+ return (0, token_1.minTokenAmount)(this.market.outstandingDebt, this.underlyingBalance);
138
163
  }
139
164
  get canRepayDelinquent() {
140
- return this.vault.delinquentDebt.lt(this.maximumRepay) && this.isBorrower;
165
+ return this.market.delinquentDebt.lt(this.maximumRepay) && this.isBorrower;
141
166
  }
142
167
  get canRepayOutstanding() {
143
- return this.vault.outstandingDebt.lt(this.maximumRepay) && this.isBorrower;
168
+ return this.market.outstandingDebt.lt(this.maximumRepay) && this.isBorrower;
144
169
  }
145
170
  /**
146
171
  * @returns Amount of underlying token user can actually repay
@@ -165,135 +190,135 @@ class VaultAccount {
165
190
  return { status: "Ready" };
166
191
  }
167
192
  async repay(amount) {
168
- const signer = await this.vault.signer.getAddress();
193
+ const signer = await this.market.signer.getAddress();
169
194
  if (signer !== this.account) {
170
- throw Error(`VaultAccount signer ${signer} does not match ${this.account}`);
195
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
171
196
  }
172
197
  if (!this.isBorrower) {
173
198
  throw Error("Only borrower can repay");
174
199
  }
175
- return this.vault.contract.repay(amount);
200
+ return this.market.contract.repay(amount);
176
201
  }
177
202
  async repayOutstandingDebt() {
178
- const signer = await this.vault.signer.getAddress();
203
+ const signer = await this.market.signer.getAddress();
179
204
  if (signer !== this.account) {
180
- throw Error(`VaultAccount signer ${signer} does not match ${this.account}`);
205
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
181
206
  }
182
207
  if (!this.isBorrower) {
183
208
  throw Error("Only borrower can repay");
184
209
  }
185
- return this.vault.contract.repayOutstandingDebt();
210
+ return this.market.contract.repayOutstandingDebt();
186
211
  }
187
212
  async repayDelinquentDebt() {
188
- const signer = await this.vault.signer.getAddress();
213
+ const signer = await this.market.signer.getAddress();
189
214
  if (signer !== this.account) {
190
- throw Error(`VaultAccount signer ${signer} does not match ${this.account}`);
215
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
191
216
  }
192
217
  if (!this.isBorrower) {
193
218
  throw Error("Only borrower can repay");
194
219
  }
195
- return this.vault.contract.repayDelinquentDebt();
220
+ return this.market.contract.repayDelinquentDebt();
196
221
  }
197
222
  /* ------ Borrowing ------ */
198
223
  /**
199
224
  * @returns Amount of underlying token borrower can borrow
200
225
  */
201
226
  getBorrowableAmount(amount) {
202
- return (0, token_1.minTokenAmount)(amount, this.vault.borrowableAssets);
227
+ return (0, token_1.minTokenAmount)(amount, this.market.borrowableAssets);
203
228
  }
204
229
  async borrow(amount) {
205
- const signer = await this.vault.signer.getAddress();
230
+ const signer = await this.market.signer.getAddress();
206
231
  if (signer !== this.account) {
207
- throw Error(`VaultAccount signer ${signer} does not match ${this.account}`);
232
+ throw Error(`MarketAccount signer ${signer} does not match ${this.account}`);
208
233
  }
209
234
  if (!this.isBorrower) {
210
235
  throw Error("Only borrower can borrow");
211
236
  }
212
- if (amount.gt(this.vault.borrowableAssets)) {
237
+ if (amount.gt(this.market.borrowableAssets)) {
213
238
  throw Error("Insufficient borrowable assets");
214
239
  }
215
- return this.vault.contract.borrow(amount.raw);
240
+ return this.market.contract.borrow(amount.raw);
216
241
  }
217
242
  /* ------ Updates ------ */
218
243
  async update() {
219
- const acccountVaultInfo = await this.vault.getAccountInfo();
220
- (0, misc_1.updateObject)(this, acccountVaultInfo, VaultAccount.UpdatableKeys);
244
+ const acccountMarketInfo = await MarketAccount.getMarketAccount(this.market.provider, this.account, this.market);
245
+ (0, utils_1.updateObject)(this, acccountMarketInfo, MarketAccount.UpdatableKeys);
221
246
  }
222
247
  applyUpdate(info) {
223
- const account = VaultAccount.fromAccountVaultInfoStruct(this.account, info, this.vault);
224
- (0, misc_1.updateObject)(this, account, VaultAccount.UpdatableKeys);
248
+ const account = MarketAccount.fromMarketLenderStatus(this.account, info, this.market);
249
+ (0, utils_1.updateObject)(this, account, MarketAccount.UpdatableKeys);
225
250
  }
226
251
  /* ------ Builders / Getters ------ */
227
- static fromAccountVaultInfoStruct(account, info, vault) {
228
- return new VaultAccount(account, vault.vaultToken.getAmount(info.normalizedBalance), vault.underlyingToken.getAmount(info.underlyingBalance), info.underlyingApproval, vault);
252
+ static fromMarketLenderStatus(account, info, market) {
253
+ return new MarketAccount(account, info.isAuthorizedOnController, info.role, info.scaledBalance, market.marketToken.getAmount(info.normalizedBalance), market.underlyingToken.getAmount(info.underlyingBalance), info.underlyingApproval, market);
229
254
  }
230
- static fromVaultDataWithAccountStruct(provider, account, info) {
231
- return VaultAccount.fromAccountVaultInfoStruct(account, info.account, vault_1.Vault.fromVaultMetadataStruct(info.vault, provider));
255
+ static fromMarketDataWithLenderStatus(provider, account, info) {
256
+ return MarketAccount.fromMarketLenderStatus(account, info.lenderStatus, market_1.Market.fromMarketData(info.market, provider));
232
257
  }
233
258
  /**
234
- * Get a `VaultAccount` for a given account and existing `Vault` instance.
235
- * If `vault` is a string, the vault data will be fetched in the same call as the account data.
259
+ * Get a `MarketAccount` for a given account and existing `Market` instance.
260
+ * If `market` is a string, the market data will be fetched in the same call as the account data.
236
261
  */
237
- static async getVaultAccount(provider, account, vault) {
262
+ static async getMarketAccount(provider, account, market) {
238
263
  const lens = (0, constants_1.getLensContract)(provider);
239
- if (vault instanceof vault_1.Vault) {
264
+ if (market instanceof market_1.Market) {
240
265
  return lens
241
- .getAccountVaultInfo(account, vault.address)
242
- .then((info) => VaultAccount.fromAccountVaultInfoStruct(account, info, vault));
266
+ .getMarketLenderStatus(account, market.address)
267
+ .then((info) => MarketAccount.fromMarketLenderStatus(account, info, market));
243
268
  }
244
269
  else {
245
270
  return lens
246
- .getVaultDataWithAccount(account, vault)
247
- .then((info) => VaultAccount.fromVaultDataWithAccountStruct(provider, account, info));
271
+ .getMarketDataWithLenderStatus(account, market)
272
+ .then((info) => MarketAccount.fromMarketDataWithLenderStatus(provider, account, info));
248
273
  }
249
274
  }
250
275
  /**
251
- * Get multiple `VaultAccount`s given an account and existing list of `Vault`
252
- * instances or vault addresses. If `vaults` is an array of strings, the vault
276
+ * Get multiple `MarketAccount`s given an account and existing list of `Market`
277
+ * instances or market addresses. If `markets` is an array of strings, the market
253
278
  * data will be fetched in the same call as the account data.
254
279
  */
255
- static async getVaultAccounts(provider, account, vaults) {
280
+ static async getMarketAccountsForLender(provider, account, markets) {
256
281
  const lens = (0, constants_1.getLensContract)(provider);
257
- if (vaults.length === 0) {
282
+ if (markets.length === 0) {
258
283
  return [];
259
284
  }
260
- if (isVaultInstanceArray(vaults)) {
285
+ if (isMarketInstanceArray(markets)) {
261
286
  return lens
262
- .getAccountVaultsInfo(account, vaults.map((v) => v.address))
263
- .then((infos) => infos.map((info, i) => VaultAccount.fromAccountVaultInfoStruct(account, info, vaults[i])));
287
+ .getMarketsLenderStatus(account, markets.map((v) => v.address))
288
+ .then((infos) => infos.map((info, i) => MarketAccount.fromMarketLenderStatus(account, info, markets[i])));
264
289
  }
265
290
  else {
266
291
  return lens
267
- .getVaultsDataWithAccount(account, vaults)
268
- .then((infos) => infos.map((info) => VaultAccount.fromVaultDataWithAccountStruct(provider, account, info)));
292
+ .getMarketsDataWithLenderStatus(account, markets)
293
+ .then((infos) => infos.map((info) => MarketAccount.fromMarketDataWithLenderStatus(provider, account, info)));
269
294
  }
270
295
  }
271
296
  /**
272
- * Get all `VaultAccount`s for a given account.
273
- * Fetches the vault data in the same call as the account data.
297
+ * Get all `MarketAccount`s for a given account.
298
+ * Fetches the market data in the same call as the account data.
274
299
  */
275
- static getAllVaultAccounts(provider, account) {
300
+ static getAllMarketAccountsForLender(provider, account) {
276
301
  const lens = (0, constants_1.getLensContract)(provider);
277
302
  return lens
278
- .getAllVaultsDataWithAccount(account)
279
- .then((infos) => infos.map((info) => VaultAccount.fromVaultDataWithAccountStruct(provider, account, info)));
303
+ .getAllMarketsDataWithLenderStatus(account)
304
+ .then((infos) => infos.map((info) => MarketAccount.fromMarketDataWithLenderStatus(provider, account, info)));
280
305
  }
281
306
  /**
282
- * Get paginated `VaultAccount`s for a given account.
283
- * Fetches the vault data in the same call as the account data.
284
- * @note Throws an error if `start + count` exceeds the number of vaults.
307
+ * Get paginated `MarketAccount`s for a given account.
308
+ * Fetches the market data in the same call as the account data.
309
+ * @note Throws an error if `start + count` exceeds the number of markets.
285
310
  */
286
- static getPaginatedVaultAccounts(provider, account, start = 0, count) {
311
+ static getPaginatedMarketAccounts(provider, account, start = 0, count) {
287
312
  const lens = (0, constants_1.getLensContract)(provider);
288
313
  return lens
289
- .getPaginatedVaultsDataWithAccount(account, start, count)
290
- .then((infos) => infos.map((info) => VaultAccount.fromVaultDataWithAccountStruct(provider, account, info)));
314
+ .getPaginatedMarketsDataWithLenderStatus(account, start, count)
315
+ .then((infos) => infos.map((info) => MarketAccount.fromMarketDataWithLenderStatus(provider, account, info)));
291
316
  }
292
317
  }
293
- VaultAccount.UpdatableKeys = [
294
- "vaultBalance",
318
+ MarketAccount.UpdatableKeys = [
319
+ "marketBalance",
295
320
  "underlyingBalance",
296
321
  "underlyingApproval"
297
322
  ];
298
- exports.VaultAccount = VaultAccount;
323
+ exports.MarketAccount = MarketAccount;
299
324
  //# sourceMappingURL=account.js.map