@wildcatfi/wildcat-sdk 1.0.15 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -0
- package/dist/account.d.ts +42 -43
- package/dist/account.d.ts.map +1 -1
- package/dist/account.js +120 -95
- package/dist/account.js.map +1 -1
- package/dist/constants.d.ts +16 -8
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +30 -12
- package/dist/constants.js.map +1 -1
- package/dist/controller.d.ts +43 -11
- package/dist/controller.d.ts.map +1 -1
- package/dist/controller.js +119 -21
- package/dist/controller.js.map +1 -1
- package/dist/index.d.ts +17 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -8
- package/dist/index.js.map +1 -1
- package/dist/market.d.ts +107 -0
- package/dist/market.d.ts.map +1 -0
- package/dist/market.js +265 -0
- package/dist/market.js.map +1 -0
- package/dist/mockerc20factory.js +1 -1
- package/dist/mockerc20factory.js.map +1 -1
- package/dist/token.d.ts +3 -3
- package/dist/token.d.ts.map +1 -1
- package/dist/token.js +18 -18
- package/dist/token.js.map +1 -1
- package/dist/typechain/IERC20.d.ts +42 -1
- package/dist/typechain/IERC20.d.ts.map +1 -1
- package/dist/typechain/MarketLens.d.ts +705 -0
- package/dist/typechain/MarketLens.d.ts.map +1 -0
- package/dist/typechain/{mock/index.js → MarketLens.js} +1 -1
- package/dist/typechain/MarketLens.js.map +1 -0
- package/dist/typechain/MockArchControllerOwner.d.ts +130 -0
- package/dist/typechain/MockArchControllerOwner.d.ts.map +1 -0
- package/dist/typechain/{WildcatVaultController.js → MockArchControllerOwner.js} +1 -1
- package/dist/typechain/MockArchControllerOwner.js.map +1 -0
- package/dist/typechain/{mock/MockERC20Factory.d.ts → MockERC20Factory.d.ts} +4 -3
- package/dist/typechain/MockERC20Factory.d.ts.map +1 -0
- package/dist/typechain/MockERC20Factory.js.map +1 -0
- package/dist/typechain/WildcatArchController.d.ts +525 -0
- package/dist/typechain/WildcatArchController.d.ts.map +1 -0
- package/dist/typechain/{VaultLens.js → WildcatArchController.js} +1 -1
- package/dist/typechain/WildcatArchController.js.map +1 -0
- package/dist/typechain/WildcatMarket.d.ts +1060 -0
- package/dist/typechain/WildcatMarket.d.ts.map +1 -0
- package/dist/typechain/{DebtTokenBase.js → WildcatMarket.js} +1 -1
- package/dist/typechain/WildcatMarket.js.map +1 -0
- package/dist/typechain/WildcatMarketController.d.ts +437 -0
- package/dist/typechain/WildcatMarketController.d.ts.map +1 -0
- package/dist/typechain/{WildcatVaultFactory.js → WildcatMarketController.js} +1 -1
- package/dist/typechain/WildcatMarketController.js.map +1 -0
- package/dist/typechain/WildcatMarketControllerFactory.d.ts +375 -0
- package/dist/typechain/WildcatMarketControllerFactory.d.ts.map +1 -0
- package/dist/typechain/WildcatMarketControllerFactory.js +3 -0
- package/dist/typechain/WildcatMarketControllerFactory.js.map +1 -0
- package/dist/typechain/common.d.ts.map +1 -1
- package/dist/typechain/factories/IERC20__factory.d.ts +44 -0
- package/dist/typechain/factories/IERC20__factory.d.ts.map +1 -1
- package/dist/typechain/factories/IERC20__factory.js +57 -0
- package/dist/typechain/factories/IERC20__factory.js.map +1 -1
- package/dist/typechain/factories/MarketLens__factory.d.ts +3428 -0
- package/dist/typechain/factories/MarketLens__factory.d.ts.map +1 -0
- package/dist/typechain/factories/MarketLens__factory.js +4389 -0
- package/dist/typechain/factories/MarketLens__factory.js.map +1 -0
- package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts +85 -0
- package/dist/typechain/factories/MockArchControllerOwner__factory.d.ts.map +1 -0
- package/dist/typechain/factories/MockArchControllerOwner__factory.js +118 -0
- package/dist/typechain/factories/MockArchControllerOwner__factory.js.map +1 -0
- package/dist/typechain/factories/MockERC20Factory__factory.d.ts +52 -0
- package/dist/typechain/factories/MockERC20Factory__factory.d.ts.map +1 -0
- package/dist/typechain/factories/MockERC20Factory__factory.js +75 -0
- package/dist/typechain/factories/MockERC20Factory__factory.js.map +1 -0
- package/dist/typechain/factories/WildcatArchController__factory.d.ts +536 -0
- package/dist/typechain/factories/WildcatArchController__factory.d.ts.map +1 -0
- package/dist/typechain/factories/WildcatArchController__factory.js +705 -0
- package/dist/typechain/factories/WildcatArchController__factory.js.map +1 -0
- package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts +431 -0
- package/dist/typechain/factories/WildcatMarketControllerFactory__factory.d.ts.map +1 -0
- package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js +561 -0
- package/dist/typechain/factories/WildcatMarketControllerFactory__factory.js.map +1 -0
- package/dist/typechain/factories/WildcatMarketController__factory.d.ts +517 -0
- package/dist/typechain/factories/WildcatMarketController__factory.d.ts.map +1 -0
- package/dist/typechain/factories/WildcatMarketController__factory.js +677 -0
- package/dist/typechain/factories/WildcatMarketController__factory.js.map +1 -0
- package/dist/typechain/factories/{WildcatVaultToken__factory.d.ts → WildcatMarket__factory.d.ts} +640 -93
- package/dist/typechain/factories/{VaultLens__factory.d.ts.map → WildcatMarket__factory.d.ts.map} +1 -1
- package/dist/typechain/factories/{WildcatVaultToken__factory.js → WildcatMarket__factory.js} +795 -97
- package/dist/typechain/factories/WildcatMarket__factory.js.map +1 -0
- package/dist/typechain/factories/index.d.ts +7 -5
- package/dist/typechain/factories/index.d.ts.map +1 -1
- package/dist/typechain/factories/index.js +15 -24
- package/dist/typechain/factories/index.js.map +1 -1
- package/dist/typechain/index.d.ts +21 -9
- package/dist/typechain/index.d.ts.map +1 -1
- package/dist/typechain/index.js +29 -3
- package/dist/typechain/index.js.map +1 -1
- package/dist/utils/assert.d.ts +2 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/assert.js +16 -0
- package/dist/utils/assert.js.map +1 -0
- package/dist/utils/index.d.ts +5 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +21 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/math.d.ts +5 -0
- package/dist/utils/math.d.ts.map +1 -0
- package/dist/utils/math.js +26 -0
- package/dist/utils/math.js.map +1 -0
- package/dist/{misc.d.ts → utils/misc.d.ts} +3 -0
- package/dist/utils/misc.d.ts.map +1 -0
- package/dist/{misc.js → utils/misc.js} +12 -1
- package/dist/utils/misc.js.map +1 -0
- package/dist/utils/type-parsers.d.ts +24 -0
- package/dist/utils/type-parsers.d.ts.map +1 -0
- package/dist/utils/type-parsers.js +21 -0
- package/dist/utils/type-parsers.js.map +1 -0
- package/dist/withdrawal-batch.d.ts +28 -0
- package/dist/withdrawal-batch.d.ts.map +1 -0
- package/dist/withdrawal-batch.js +45 -0
- package/dist/withdrawal-batch.js.map +1 -0
- package/dist/withdrawal-status.d.ts +53 -0
- package/dist/withdrawal-status.d.ts.map +1 -0
- package/dist/withdrawal-status.js +187 -0
- package/dist/withdrawal-status.js.map +1 -0
- package/package.json +3 -2
- package/dist/factory.d.ts +0 -28
- package/dist/factory.d.ts.map +0 -1
- package/dist/factory.js +0 -50
- package/dist/factory.js.map +0 -1
- package/dist/misc.d.ts.map +0 -1
- package/dist/misc.js.map +0 -1
- package/dist/typechain/DebtTokenBase.d.ts +0 -508
- package/dist/typechain/DebtTokenBase.d.ts.map +0 -1
- package/dist/typechain/DebtTokenBase.js.map +0 -1
- package/dist/typechain/VaultLens.d.ts +0 -338
- package/dist/typechain/VaultLens.d.ts.map +0 -1
- package/dist/typechain/VaultLens.js.map +0 -1
- package/dist/typechain/WildcatVaultController.d.ts +0 -331
- package/dist/typechain/WildcatVaultController.d.ts.map +0 -1
- package/dist/typechain/WildcatVaultController.js.map +0 -1
- package/dist/typechain/WildcatVaultFactory.d.ts +0 -161
- package/dist/typechain/WildcatVaultFactory.d.ts.map +0 -1
- package/dist/typechain/WildcatVaultFactory.js.map +0 -1
- package/dist/typechain/WildcatVaultToken.d.ts +0 -653
- package/dist/typechain/WildcatVaultToken.d.ts.map +0 -1
- package/dist/typechain/WildcatVaultToken.js +0 -3
- package/dist/typechain/WildcatVaultToken.js.map +0 -1
- package/dist/typechain/factories/VaultLens__factory.d.ts +0 -1540
- package/dist/typechain/factories/VaultLens__factory.js +0 -1981
- package/dist/typechain/factories/VaultLens__factory.js.map +0 -1
- package/dist/typechain/factories/WildcatVaultController__factory.d.ts +0 -440
- package/dist/typechain/factories/WildcatVaultController__factory.d.ts.map +0 -1
- package/dist/typechain/factories/WildcatVaultController__factory.js +0 -573
- package/dist/typechain/factories/WildcatVaultController__factory.js.map +0 -1
- package/dist/typechain/factories/WildcatVaultFactory__factory.d.ts +0 -225
- package/dist/typechain/factories/WildcatVaultFactory__factory.d.ts.map +0 -1
- package/dist/typechain/factories/WildcatVaultFactory__factory.js +0 -299
- package/dist/typechain/factories/WildcatVaultFactory__factory.js.map +0 -1
- package/dist/typechain/factories/WildcatVaultToken__factory.d.ts.map +0 -1
- package/dist/typechain/factories/WildcatVaultToken__factory.js.map +0 -1
- package/dist/typechain/factories/mock/ERC20__factory.d.ts +0 -237
- package/dist/typechain/factories/mock/ERC20__factory.d.ts.map +0 -1
- package/dist/typechain/factories/mock/ERC20__factory.js +0 -317
- package/dist/typechain/factories/mock/ERC20__factory.js.map +0 -1
- package/dist/typechain/factories/mock/MockERC20Factory__factory.d.ts +0 -65
- package/dist/typechain/factories/mock/MockERC20Factory__factory.d.ts.map +0 -1
- package/dist/typechain/factories/mock/MockERC20Factory__factory.js +0 -98
- package/dist/typechain/factories/mock/MockERC20Factory__factory.js.map +0 -1
- package/dist/typechain/factories/mock/MockERC20__factory.d.ts +0 -292
- package/dist/typechain/factories/mock/MockERC20__factory.d.ts.map +0 -1
- package/dist/typechain/factories/mock/MockERC20__factory.js +0 -394
- package/dist/typechain/factories/mock/MockERC20__factory.js.map +0 -1
- package/dist/typechain/factories/mock/index.d.ts +0 -4
- package/dist/typechain/factories/mock/index.d.ts.map +0 -1
- package/dist/typechain/factories/mock/index.js +0 -13
- package/dist/typechain/factories/mock/index.js.map +0 -1
- package/dist/typechain/mock/ERC20.d.ts +0 -207
- package/dist/typechain/mock/ERC20.d.ts.map +0 -1
- package/dist/typechain/mock/ERC20.js +0 -3
- package/dist/typechain/mock/ERC20.js.map +0 -1
- package/dist/typechain/mock/MockERC20.d.ts +0 -247
- package/dist/typechain/mock/MockERC20.d.ts.map +0 -1
- package/dist/typechain/mock/MockERC20.js +0 -3
- package/dist/typechain/mock/MockERC20.js.map +0 -1
- package/dist/typechain/mock/MockERC20Factory.d.ts.map +0 -1
- package/dist/typechain/mock/MockERC20Factory.js.map +0 -1
- package/dist/typechain/mock/index.d.ts +0 -4
- package/dist/typechain/mock/index.d.ts.map +0 -1
- package/dist/typechain/mock/index.js.map +0 -1
- package/dist/vault.d.ts +0 -89
- package/dist/vault.d.ts.map +0 -1
- package/dist/vault.js +0 -218
- package/dist/vault.js.map +0 -1
- /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 {
|
|
4
|
-
import {
|
|
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
|
|
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
|
|
33
|
+
export declare class MarketAccount {
|
|
35
34
|
account: string;
|
|
36
|
-
|
|
35
|
+
isAuthorizedOnController: boolean;
|
|
36
|
+
role: LenderRole;
|
|
37
|
+
scaledMarketBalance: BigNumber;
|
|
38
|
+
marketBalance: TokenAmount;
|
|
37
39
|
underlyingBalance: TokenAmount;
|
|
38
40
|
underlyingApproval: BigNumber;
|
|
39
|
-
|
|
40
|
-
constructor(account: string,
|
|
41
|
-
static readonly UpdatableKeys: Array<keyof
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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:
|
|
101
|
-
static
|
|
102
|
-
static
|
|
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 `
|
|
105
|
-
* If `
|
|
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
|
|
106
|
+
static getMarketAccount(provider: SignerOrProvider, account: string, market: Market | string): Promise<MarketAccount>;
|
|
108
107
|
/**
|
|
109
|
-
* Get multiple `
|
|
110
|
-
* instances or
|
|
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
|
|
112
|
+
static getMarketAccountsForLender(provider: SignerOrProvider, account: string, markets: Market[] | string[]): Promise<MarketAccount[]>;
|
|
114
113
|
/**
|
|
115
|
-
* Get all `
|
|
116
|
-
* Fetches the
|
|
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
|
|
117
|
+
static getAllMarketAccountsForLender(provider: SignerOrProvider, account: string): Promise<MarketAccount[]>;
|
|
119
118
|
/**
|
|
120
|
-
* Get paginated `
|
|
121
|
-
* Fetches the
|
|
122
|
-
* @note Throws an error if `start + count` exceeds the number of
|
|
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
|
|
123
|
+
static getPaginatedMarketAccounts(provider: SignerOrProvider, account: string, start: number | undefined, count: number): Promise<MarketAccount[]>;
|
|
125
124
|
}
|
|
126
125
|
//# sourceMappingURL=account.d.ts.map
|
package/dist/account.d.ts.map
CHANGED
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,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ty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MarketAccount = exports.LenderRole = void 0;
|
|
4
4
|
const token_1 = require("./token");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const market_1 = require("./market");
|
|
6
|
+
const utils_1 = require("./utils");
|
|
7
7
|
const constants_1 = require("./constants");
|
|
8
|
-
const
|
|
9
|
-
|
|
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
|
|
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
|
|
20
|
-
constructor(account,
|
|
27
|
+
class MarketAccount {
|
|
28
|
+
constructor(account, isAuthorizedOnController, role, scaledMarketBalance, marketBalance, underlyingBalance, underlyingApproval, market) {
|
|
21
29
|
this.account = account;
|
|
22
|
-
this.
|
|
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.
|
|
36
|
+
this.market = market;
|
|
26
37
|
}
|
|
27
38
|
get userHasBalance() {
|
|
28
|
-
return this.
|
|
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.
|
|
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.
|
|
44
|
-
if (this.
|
|
45
|
-
throw Error(`Unexpected controller address: ${this.
|
|
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.
|
|
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
|
-
*
|
|
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.
|
|
81
|
+
const token = this.market.underlyingToken;
|
|
62
82
|
const signer = await token.signer.getAddress();
|
|
63
83
|
if (signer !== this.account) {
|
|
64
|
-
throw Error(`
|
|
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.
|
|
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
|
|
92
|
+
* given their underlying balance and the market's max supply
|
|
73
93
|
*/
|
|
74
94
|
get maximumDeposit() {
|
|
75
|
-
return (0, token_1.minTokenAmount)(this.
|
|
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 (
|
|
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.
|
|
127
|
+
const signer = await this.market.signer.getAddress();
|
|
105
128
|
if (signer !== this.account) {
|
|
106
|
-
throw Error(`
|
|
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.
|
|
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
|
|
139
|
+
* given their market balance and the market's assets.
|
|
117
140
|
*/
|
|
118
141
|
get maximumWithdrawal() {
|
|
119
|
-
return (0, token_1.minTokenAmount)(this.
|
|
142
|
+
return (0, token_1.minTokenAmount)(this.market.totalAssets, this.marketBalance);
|
|
120
143
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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(`
|
|
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
|
|
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.
|
|
162
|
+
return (0, token_1.minTokenAmount)(this.market.outstandingDebt, this.underlyingBalance);
|
|
138
163
|
}
|
|
139
164
|
get canRepayDelinquent() {
|
|
140
|
-
return this.
|
|
165
|
+
return this.market.delinquentDebt.lt(this.maximumRepay) && this.isBorrower;
|
|
141
166
|
}
|
|
142
167
|
get canRepayOutstanding() {
|
|
143
|
-
return this.
|
|
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.
|
|
193
|
+
const signer = await this.market.signer.getAddress();
|
|
169
194
|
if (signer !== this.account) {
|
|
170
|
-
throw Error(`
|
|
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.
|
|
200
|
+
return this.market.contract.repay(amount);
|
|
176
201
|
}
|
|
177
202
|
async repayOutstandingDebt() {
|
|
178
|
-
const signer = await this.
|
|
203
|
+
const signer = await this.market.signer.getAddress();
|
|
179
204
|
if (signer !== this.account) {
|
|
180
|
-
throw Error(`
|
|
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.
|
|
210
|
+
return this.market.contract.repayOutstandingDebt();
|
|
186
211
|
}
|
|
187
212
|
async repayDelinquentDebt() {
|
|
188
|
-
const signer = await this.
|
|
213
|
+
const signer = await this.market.signer.getAddress();
|
|
189
214
|
if (signer !== this.account) {
|
|
190
|
-
throw Error(`
|
|
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.
|
|
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.
|
|
227
|
+
return (0, token_1.minTokenAmount)(amount, this.market.borrowableAssets);
|
|
203
228
|
}
|
|
204
229
|
async borrow(amount) {
|
|
205
|
-
const signer = await this.
|
|
230
|
+
const signer = await this.market.signer.getAddress();
|
|
206
231
|
if (signer !== this.account) {
|
|
207
|
-
throw Error(`
|
|
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.
|
|
237
|
+
if (amount.gt(this.market.borrowableAssets)) {
|
|
213
238
|
throw Error("Insufficient borrowable assets");
|
|
214
239
|
}
|
|
215
|
-
return this.
|
|
240
|
+
return this.market.contract.borrow(amount.raw);
|
|
216
241
|
}
|
|
217
242
|
/* ------ Updates ------ */
|
|
218
243
|
async update() {
|
|
219
|
-
const
|
|
220
|
-
(0,
|
|
244
|
+
const acccountMarketInfo = await this.market.getAccount(this.account);
|
|
245
|
+
(0, utils_1.updateObject)(this, acccountMarketInfo, MarketAccount.UpdatableKeys);
|
|
221
246
|
}
|
|
222
247
|
applyUpdate(info) {
|
|
223
|
-
const account =
|
|
224
|
-
(0,
|
|
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
|
|
228
|
-
return new
|
|
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
|
|
231
|
-
return
|
|
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 `
|
|
235
|
-
* If `
|
|
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
|
|
262
|
+
static async getMarketAccount(provider, account, market) {
|
|
238
263
|
const lens = (0, constants_1.getLensContract)(provider);
|
|
239
|
-
if (
|
|
264
|
+
if (market instanceof market_1.Market) {
|
|
240
265
|
return lens
|
|
241
|
-
.
|
|
242
|
-
.then((info) =>
|
|
266
|
+
.getMarketLenderStatus(account, market.address)
|
|
267
|
+
.then((info) => MarketAccount.fromMarketLenderStatus(account, info, market));
|
|
243
268
|
}
|
|
244
269
|
else {
|
|
245
270
|
return lens
|
|
246
|
-
.
|
|
247
|
-
.then((info) =>
|
|
271
|
+
.getMarketDataWithLenderStatus(account, market)
|
|
272
|
+
.then((info) => MarketAccount.fromMarketDataWithLenderStatus(provider, account, info));
|
|
248
273
|
}
|
|
249
274
|
}
|
|
250
275
|
/**
|
|
251
|
-
* Get multiple `
|
|
252
|
-
* instances or
|
|
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
|
|
280
|
+
static async getMarketAccountsForLender(provider, account, markets) {
|
|
256
281
|
const lens = (0, constants_1.getLensContract)(provider);
|
|
257
|
-
if (
|
|
282
|
+
if (markets.length === 0) {
|
|
258
283
|
return [];
|
|
259
284
|
}
|
|
260
|
-
if (
|
|
285
|
+
if (isMarketInstanceArray(markets)) {
|
|
261
286
|
return lens
|
|
262
|
-
.
|
|
263
|
-
.then((infos) => infos.map((info, 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
|
-
.
|
|
268
|
-
.then((infos) => infos.map((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 `
|
|
273
|
-
* Fetches the
|
|
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
|
|
300
|
+
static getAllMarketAccountsForLender(provider, account) {
|
|
276
301
|
const lens = (0, constants_1.getLensContract)(provider);
|
|
277
302
|
return lens
|
|
278
|
-
.
|
|
279
|
-
.then((infos) => infos.map((info) =>
|
|
303
|
+
.getAllMarketsDataWithLenderStatus(account)
|
|
304
|
+
.then((infos) => infos.map((info) => MarketAccount.fromMarketDataWithLenderStatus(provider, account, info)));
|
|
280
305
|
}
|
|
281
306
|
/**
|
|
282
|
-
* Get paginated `
|
|
283
|
-
* Fetches the
|
|
284
|
-
* @note Throws an error if `start + count` exceeds the number of
|
|
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
|
|
311
|
+
static getPaginatedMarketAccounts(provider, account, start = 0, count) {
|
|
287
312
|
const lens = (0, constants_1.getLensContract)(provider);
|
|
288
313
|
return lens
|
|
289
|
-
.
|
|
290
|
-
.then((infos) => infos.map((info) =>
|
|
314
|
+
.getPaginatedMarketsDataWithLenderStatus(account, start, count)
|
|
315
|
+
.then((infos) => infos.map((info) => MarketAccount.fromMarketDataWithLenderStatus(provider, account, info)));
|
|
291
316
|
}
|
|
292
317
|
}
|
|
293
|
-
|
|
294
|
-
"
|
|
318
|
+
MarketAccount.UpdatableKeys = [
|
|
319
|
+
"marketBalance",
|
|
295
320
|
"underlyingBalance",
|
|
296
321
|
"underlyingApproval"
|
|
297
322
|
];
|
|
298
|
-
exports.
|
|
323
|
+
exports.MarketAccount = MarketAccount;
|
|
299
324
|
//# sourceMappingURL=account.js.map
|