@gearbox-protocol/sdk 0.0.102 → 0.0.105

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 (129) hide show
  1. package/.eslintignore +5 -0
  2. package/.eslintrc.js +52 -0
  3. package/.husky/pre-push +4 -0
  4. package/lib/apy/convexAPY.js +3 -5
  5. package/lib/apy/lidoAPY.js +8 -9
  6. package/lib/contracts/contracts.d.ts +5 -2
  7. package/lib/contracts/contracts.js +19 -18
  8. package/lib/core/constants.d.ts +1 -1
  9. package/lib/core/constants.js +2 -2
  10. package/lib/core/creditAccount.js +7 -5
  11. package/lib/core/creditManager.d.ts +1 -1
  12. package/lib/core/creditManager.js +1 -7
  13. package/lib/core/creditSession.js +14 -3
  14. package/lib/core/eventOrTx.d.ts +1 -1
  15. package/lib/core/events.d.ts +19 -19
  16. package/lib/core/events.js +23 -21
  17. package/lib/core/pool.d.ts +1 -1
  18. package/lib/core/pool.js +1 -7
  19. package/lib/core/price.js +6 -1
  20. package/lib/core/strategy.d.ts +1 -3
  21. package/lib/core/strategy.js +14 -13
  22. package/lib/core/tokenDistributor.js +1 -1
  23. package/lib/core/transactions.d.ts +18 -3
  24. package/lib/core/transactions.js +39 -3
  25. package/lib/index.d.ts +8 -2
  26. package/lib/index.js +8 -1
  27. package/lib/oracles/priceFeeds.js +1 -1
  28. package/lib/pathfinder/convexLP.d.ts +1 -1
  29. package/lib/pathfinder/convexLP.js +26 -29
  30. package/lib/pathfinder/curveLP.d.ts +1 -1
  31. package/lib/pathfinder/curveLP.js +5 -7
  32. package/lib/pathfinder/path.d.ts +1 -1
  33. package/lib/pathfinder/path.js +38 -42
  34. package/lib/pathfinder/trade.d.ts +1 -2
  35. package/lib/pathfinder/tradeTypes.d.ts +5 -5
  36. package/lib/pathfinder/yVault.d.ts +2 -2
  37. package/lib/pathfinder/yVault.js +18 -15
  38. package/lib/strategies/convex.d.ts +12 -0
  39. package/lib/strategies/convex.js +74 -1
  40. package/lib/strategies/creditFacade.d.ts +1 -0
  41. package/lib/strategies/creditFacade.js +3 -0
  42. package/lib/strategies/curve.d.ts +15 -60
  43. package/lib/strategies/curve.js +74 -1
  44. package/lib/strategies/lido.d.ts +6 -0
  45. package/lib/strategies/lido.js +23 -1
  46. package/lib/strategies/uniswapV2.d.ts +1 -0
  47. package/lib/strategies/uniswapV2.js +6 -19
  48. package/lib/strategies/uniswapV3.d.ts +1 -0
  49. package/lib/strategies/uniswapV3.js +4 -1
  50. package/lib/strategies/yearn.d.ts +8 -0
  51. package/lib/strategies/yearn.js +92 -12
  52. package/lib/tokens/convex.d.ts +3 -3
  53. package/lib/tokens/curveLP.d.ts +7 -2
  54. package/lib/tokens/curveLP.js +8 -1
  55. package/lib/tokens/gear.d.ts +2 -2
  56. package/lib/tokens/gear.js +1 -1
  57. package/lib/tokens/normal.d.ts +1 -1
  58. package/lib/tokens/token.js +4 -4
  59. package/lib/tokens/tokenData.d.ts +3 -1
  60. package/lib/tokens/tokenData.js +10 -8
  61. package/lib/tokens/yearn.d.ts +6 -2
  62. package/lib/tokens/yearn.js +6 -0
  63. package/lib/utils/errors.d.ts +6 -0
  64. package/lib/utils/errors.js +13 -0
  65. package/lib/utils/formatter.d.ts +1 -1
  66. package/lib/utils/formatter.js +17 -14
  67. package/lib/utils/loading.d.ts +2 -1
  68. package/lib/utils/loading.js +9 -13
  69. package/lib/utils/mappers.js +2 -2
  70. package/lib/utils/network.js +2 -2
  71. package/lib/utils/repeater.js +12 -24
  72. package/lib/utils/validate.js +1 -1
  73. package/package.json +24 -7
  74. package/src/apy/convexAPY.ts +6 -6
  75. package/src/apy/lidoAPY.ts +12 -11
  76. package/src/contracts/contracts.ts +27 -17
  77. package/src/core/constants.ts +1 -1
  78. package/src/core/creditAccount.ts +28 -5
  79. package/src/core/creditManager.ts +29 -4
  80. package/src/core/creditOperation.ts +7 -7
  81. package/src/core/creditSession.ts +25 -5
  82. package/src/core/errors.ts +1 -0
  83. package/src/core/eventOrTx.ts +8 -5
  84. package/src/core/events.ts +85 -24
  85. package/src/core/history.ts +46 -46
  86. package/src/core/operations.ts +6 -0
  87. package/src/core/pool.ts +16 -4
  88. package/src/core/price.ts +7 -3
  89. package/src/core/strategy.ts +27 -23
  90. package/src/core/tokenDistributor.ts +2 -2
  91. package/src/core/transactions.ts +427 -350
  92. package/src/index.ts +10 -3
  93. package/src/oracles/priceFeeds.ts +523 -523
  94. package/src/pathfinder/contracts.ts +15 -13
  95. package/src/pathfinder/convexLP.ts +29 -25
  96. package/src/pathfinder/curveLP.ts +57 -53
  97. package/src/pathfinder/path.ts +17 -9
  98. package/src/pathfinder/priority.ts +11 -11
  99. package/src/pathfinder/trade.ts +84 -77
  100. package/src/pathfinder/tradeTypes.ts +98 -94
  101. package/src/pathfinder/yVault.ts +26 -11
  102. package/src/payload/token.ts +3 -3
  103. package/src/strategies/convex.ts +361 -186
  104. package/src/strategies/creditFacade.ts +74 -53
  105. package/src/strategies/curve.ts +400 -189
  106. package/src/strategies/lido.ts +70 -32
  107. package/src/strategies/uniswapV2.ts +93 -111
  108. package/src/strategies/uniswapV3.ts +118 -91
  109. package/src/strategies/yearn.ts +187 -60
  110. package/src/tokens/connectors.ts +6 -6
  111. package/src/tokens/convex.ts +297 -296
  112. package/src/tokens/curveLP.ts +176 -165
  113. package/src/tokens/gear.ts +47 -45
  114. package/src/tokens/normal.ts +801 -802
  115. package/src/tokens/token.ts +9 -5
  116. package/src/tokens/tokenData.ts +19 -9
  117. package/src/tokens/tokenType.ts +11 -11
  118. package/src/tokens/yearn.ts +130 -124
  119. package/src/utils/errors.ts +11 -0
  120. package/src/utils/formatter.ts +22 -18
  121. package/src/utils/loading.ts +14 -6
  122. package/src/utils/mappers.ts +8 -6
  123. package/src/utils/multicall.ts +2 -0
  124. package/src/utils/network.ts +21 -21
  125. package/src/utils/repeater.ts +2 -2
  126. package/src/utils/validate.ts +1 -1
  127. package/lib/utils/events.d.ts +0 -2
  128. package/lib/utils/events.js +0 -13
  129. package/src/utils/events.ts +0 -10
@@ -1,415 +1,492 @@
1
- import {BigNumber} from "ethers";
2
- import {TokenData} from "../tokens/tokenData";
3
- import {formatBN} from "../utils/formatter";
4
- import {EVMTx, EVMTxProps} from "./eventOrTx";
5
- import {getContractName} from "../contracts/contractsRegister";
6
- import {LEVERAGE_DECIMALS} from "./constants";
1
+ import { BigNumber } from "ethers";
2
+ import { TokenData } from "../tokens/tokenData";
3
+ import { formatBN } from "../utils/formatter";
4
+ import { EVMTx, EVMTxProps } from "./eventOrTx";
5
+ import { getContractName } from "../contracts/contractsRegister";
6
+ import { LEVERAGE_DECIMALS } from "./constants";
7
7
 
8
8
  export interface TxSerialized {
9
- type:
10
- | "TxAddLiquidity"
11
- | "TxRemoveLiquidity"
12
- | "TxSwap"
13
- | "TxAddCollateral"
14
- | "TxIncreaseBorrowAmount"
15
- | "TxOpenAccount"
16
- | "TxRepayAccount"
17
- | "TxCloseAccount"
18
- | "TxApprove";
19
- content: string;
9
+ type:
10
+ | "TxAddLiquidity"
11
+ | "TxRemoveLiquidity"
12
+ | "TxSwap"
13
+ | "TxAddCollateral"
14
+ | "TxIncreaseBorrowAmount"
15
+ | "TxOpenAccount"
16
+ | "TxRepayAccount"
17
+ | "TxCloseAccount"
18
+ | "TxApprove"
19
+ | "TxOpenMultitokenAccount";
20
+ content: string;
20
21
  }
21
22
 
22
23
  export class TxSerializer {
23
- static serialize(items: Array<EVMTx>): string {
24
- return JSON.stringify(items.map(i => i.serialize()));
25
- }
26
-
27
- static deserialize(data: string): Array<EVMTx> {
28
- return (JSON.parse(data) as Array<TxSerialized>).map(e => {
29
- const params = JSON.parse(e.content);
30
- switch (e.type) {
31
- case "TxAddLiquidity":
32
- return new TxAddLiquidity(params);
33
- case "TxRemoveLiquidity":
34
- return new TxRemoveLiquidity(params);
35
- case "TxSwap":
36
- return new TXSwap(params);
37
- case "TxAddCollateral":
38
- return new TxAddCollateral(params);
39
- case "TxIncreaseBorrowAmount":
40
- return new TxIncreaseBorrowAmount(params);
41
- case "TxOpenAccount":
42
- return new TxOpenAccount(params);
43
- case "TxRepayAccount":
44
- return new TxRepayAccount(params);
45
- case "TxCloseAccount":
46
- return new TxCloseAccount(params);
47
- case "TxApprove":
48
- return new TxApprove(params);
49
- default:
50
- throw new Error("Unknown transaction for parsing");
51
- }
52
- });
53
- }
24
+ static serialize(items: Array<EVMTx>): string {
25
+ return JSON.stringify(items.map(i => i.serialize()));
26
+ }
27
+
28
+ static deserialize(data: string): Array<EVMTx> {
29
+ return (JSON.parse(data) as Array<TxSerialized>).map(e => {
30
+ const params = JSON.parse(e.content);
31
+ switch (e.type) {
32
+ case "TxAddLiquidity":
33
+ return new TxAddLiquidity(params);
34
+ case "TxRemoveLiquidity":
35
+ return new TxRemoveLiquidity(params);
36
+ case "TxSwap":
37
+ return new TXSwap(params);
38
+ case "TxAddCollateral":
39
+ return new TxAddCollateral(params);
40
+ case "TxIncreaseBorrowAmount":
41
+ return new TxIncreaseBorrowAmount(params);
42
+ case "TxOpenAccount":
43
+ return new TxOpenAccount(params);
44
+ case "TxRepayAccount":
45
+ return new TxRepayAccount(params);
46
+ case "TxCloseAccount":
47
+ return new TxCloseAccount(params);
48
+ case "TxApprove":
49
+ return new TxApprove(params);
50
+ case "TxOpenMultitokenAccount":
51
+ return new TxOpenMultitokenAccount(params);
52
+ default:
53
+ throw new Error("Unknown transaction for parsing");
54
+ }
55
+ });
56
+ }
54
57
  }
55
58
 
56
59
  interface AddLiquidityProps extends EVMTxProps {
57
- amount: BigNumber;
58
- underlyingToken: string;
59
- pool: string;
60
+ amount: BigNumber;
61
+ underlyingToken: string;
62
+ pool: string;
60
63
  }
61
64
 
62
65
  export class TxAddLiquidity extends EVMTx {
63
- public readonly amount: BigNumber;
64
- public readonly underlyingToken: string;
65
- public readonly pool: string;
66
-
67
- constructor(opts: AddLiquidityProps) {
68
- super({
69
- block: opts.block,
70
- txHash: opts.txHash,
71
- txStatus: opts.txStatus,
72
- timestamp: opts.timestamp
73
- });
74
- this.amount = opts.amount;
75
- this.underlyingToken = opts.underlyingToken;
76
- this.pool = opts.pool;
77
- }
78
-
79
- toString(tokenData: Record<string, TokenData>): string {
80
- const token = tokenData[this.underlyingToken.toLowerCase()];
81
- return `${getContractName(this.pool)}: Deposit ${formatBN(
82
- this.amount,
83
- token?.decimals || 18
84
- )} ${token?.symbol || ""}`;
85
- }
86
-
87
- serialize(): TxSerialized {
88
- return {
89
- type: "TxAddLiquidity",
90
- content: JSON.stringify(this)
91
- };
92
- }
66
+ public readonly amount: BigNumber;
67
+
68
+ public readonly underlyingToken: string;
69
+
70
+ public readonly pool: string;
71
+
72
+ constructor(opts: AddLiquidityProps) {
73
+ super({
74
+ block: opts.block,
75
+ txHash: opts.txHash,
76
+ txStatus: opts.txStatus,
77
+ timestamp: opts.timestamp
78
+ });
79
+ this.amount = opts.amount;
80
+ this.underlyingToken = opts.underlyingToken;
81
+ this.pool = opts.pool;
82
+ }
83
+
84
+ toString(tokenData: Record<string, TokenData>): string {
85
+ const token = tokenData[this.underlyingToken.toLowerCase()];
86
+ return `${getContractName(this.pool)}: Deposit ${formatBN(
87
+ this.amount,
88
+ token?.decimals || 18
89
+ )} ${token?.symbol || ""}`;
90
+ }
91
+
92
+ serialize(): TxSerialized {
93
+ return {
94
+ type: "TxAddLiquidity",
95
+ content: JSON.stringify(this)
96
+ };
97
+ }
93
98
  }
94
99
 
95
100
  interface RemoveLiquidityProps extends EVMTxProps {
96
- amount: BigNumber;
97
- dieselToken: string;
98
- pool: string;
101
+ amount: BigNumber;
102
+ dieselToken: string;
103
+ pool: string;
99
104
  }
100
105
 
101
106
  export class TxRemoveLiquidity extends EVMTx {
102
- public readonly amount: BigNumber;
103
- public readonly dieselToken: string;
104
- public readonly pool: string;
105
-
106
- constructor(opts: RemoveLiquidityProps) {
107
- super({
108
- block: opts.block,
109
- txHash: opts.txHash,
110
- txStatus: opts.txStatus,
111
- timestamp: opts.timestamp
112
- });
113
- this.amount = opts.amount;
114
- this.dieselToken = opts.dieselToken;
115
- this.pool = opts.pool;
116
- }
117
-
118
- toString(tokenData: Record<string, TokenData>): string {
119
- const dtoken = tokenData[this.dieselToken.toLowerCase()];
120
- return `${getContractName(this.pool)}: Withdraw ${formatBN(
121
- this.amount,
122
- dtoken?.decimals || 18
123
- )} ${dtoken?.symbol || ""}`;
124
- }
125
-
126
- serialize(): TxSerialized {
127
- return {
128
- type: "TxRemoveLiquidity",
129
- content: JSON.stringify(this)
130
- };
131
- }
107
+ public readonly amount: BigNumber;
108
+
109
+ public readonly dieselToken: string;
110
+
111
+ public readonly pool: string;
112
+
113
+ constructor(opts: RemoveLiquidityProps) {
114
+ super({
115
+ block: opts.block,
116
+ txHash: opts.txHash,
117
+ txStatus: opts.txStatus,
118
+ timestamp: opts.timestamp
119
+ });
120
+ this.amount = opts.amount;
121
+ this.dieselToken = opts.dieselToken;
122
+ this.pool = opts.pool;
123
+ }
124
+
125
+ toString(tokenData: Record<string, TokenData>): string {
126
+ const dtoken = tokenData[this.dieselToken.toLowerCase()];
127
+ return `${getContractName(this.pool)}: Withdraw ${formatBN(
128
+ this.amount,
129
+ dtoken?.decimals || 18
130
+ )} ${dtoken?.symbol || ""}`;
131
+ }
132
+
133
+ serialize(): TxSerialized {
134
+ return {
135
+ type: "TxRemoveLiquidity",
136
+ content: JSON.stringify(this)
137
+ };
138
+ }
132
139
  }
133
140
 
134
141
  interface SwapProps extends EVMTxProps {
135
- protocol: string;
136
- operation: string;
137
- amountFrom: BigNumber;
138
- amountTo?: BigNumber;
139
- tokenFrom: string;
140
- tokenTo?: string;
141
- creditManager: string;
142
+ protocol: string;
143
+ operation: string;
144
+ amountFrom: BigNumber;
145
+ amountTo?: BigNumber;
146
+ tokenFrom: string;
147
+ tokenTo?: string;
148
+ creditManager: string;
142
149
  }
143
150
 
144
151
  export class TXSwap extends EVMTx {
145
- public readonly protocol: string;
146
- public readonly operation: string;
147
- public readonly amountFrom: BigNumber;
148
- public readonly amountTo?: BigNumber;
149
- public readonly tokenFrom: string;
150
- public readonly tokenTo?: string;
151
- public readonly creditManager: string;
152
-
153
- constructor(opts: SwapProps) {
154
- super({
155
- block: opts.block,
156
- txHash: opts.txHash,
157
- txStatus: opts.txStatus,
158
- timestamp: opts.timestamp
159
- });
160
- this.protocol = opts.protocol;
161
- this.operation = opts.operation;
162
- this.amountFrom = opts.amountFrom;
163
- this.amountTo = opts.amountTo;
164
- this.tokenFrom = opts.tokenFrom;
165
- this.tokenTo = opts.tokenTo;
166
- this.creditManager = opts.creditManager;
167
- }
152
+ public readonly protocol: string;
168
153
 
169
- toString(tokenData: Record<string, TokenData>): string {
170
- const tokenFrom = tokenData[this.tokenFrom.toLowerCase()];
171
-
172
- let toPart = "";
173
- if (this.tokenTo && this.amountTo) {
174
- const tokenTo = tokenData[this.tokenTo.toLowerCase()];
175
- toPart = ` ⇒ ${formatBN(this.amountTo, tokenTo?.decimals || 18)} ${
176
- tokenTo?.symbol || ""
177
- }`;
178
- }
179
-
180
- return `Credit account ${getContractName(this.creditManager)}: ${
181
- this.operation
182
- } ${formatBN(this.amountFrom, tokenFrom?.decimals || 18)} ${
183
- tokenFrom?.symbol || ""
184
- } ${toPart} on ${getContractName(this.protocol)}`;
185
- }
154
+ public readonly operation: string;
155
+
156
+ public readonly amountFrom: BigNumber;
157
+
158
+ public readonly amountTo?: BigNumber;
159
+
160
+ public readonly tokenFrom: string;
161
+
162
+ public readonly tokenTo?: string;
163
+
164
+ public readonly creditManager: string;
165
+
166
+ constructor(opts: SwapProps) {
167
+ super({
168
+ block: opts.block,
169
+ txHash: opts.txHash,
170
+ txStatus: opts.txStatus,
171
+ timestamp: opts.timestamp
172
+ });
173
+ this.protocol = opts.protocol;
174
+ this.operation = opts.operation;
175
+ this.amountFrom = opts.amountFrom;
176
+ this.amountTo = opts.amountTo;
177
+ this.tokenFrom = opts.tokenFrom;
178
+ this.tokenTo = opts.tokenTo;
179
+ this.creditManager = opts.creditManager;
180
+ }
186
181
 
187
- serialize(): TxSerialized {
188
- return {
189
- type: "TxSwap",
190
- content: JSON.stringify(this)
191
- };
182
+ toString(tokenData: Record<string, TokenData>): string {
183
+ const tokenFrom = tokenData[this.tokenFrom.toLowerCase()];
184
+
185
+ let toPart = "";
186
+ if (this.tokenTo && this.amountTo) {
187
+ const tokenTo = tokenData[this.tokenTo.toLowerCase()];
188
+ toPart = ` ⇒ ${formatBN(this.amountTo, tokenTo?.decimals || 18)} ${
189
+ tokenTo?.symbol || ""
190
+ }`;
192
191
  }
192
+
193
+ return `Credit account ${getContractName(this.creditManager)}: ${
194
+ this.operation
195
+ } ${formatBN(this.amountFrom, tokenFrom?.decimals || 18)} ${
196
+ tokenFrom?.symbol || ""
197
+ } ${toPart} on ${getContractName(this.protocol)}`;
198
+ }
199
+
200
+ serialize(): TxSerialized {
201
+ return {
202
+ type: "TxSwap",
203
+ content: JSON.stringify(this)
204
+ };
205
+ }
193
206
  }
194
207
 
195
208
  interface AddCollateralProps extends EVMTxProps {
196
- amount: BigNumber;
197
- addedToken: string;
198
- creditManager: string;
209
+ amount: BigNumber;
210
+ addedToken: string;
211
+ creditManager: string;
199
212
  }
200
213
 
201
214
  export class TxAddCollateral extends EVMTx {
202
- public readonly amount: BigNumber;
203
- public readonly addedToken: string;
204
- public readonly creditManager: string;
205
-
206
- constructor(opts: AddCollateralProps) {
207
- super({
208
- block: opts.block,
209
- txHash: opts.txHash,
210
- txStatus: opts.txStatus,
211
- timestamp: opts.timestamp
212
- });
213
- this.amount = opts.amount;
214
- this.addedToken = opts.addedToken;
215
- this.creditManager = opts.creditManager;
216
- }
217
-
218
- toString(tokenData: Record<string, TokenData>): string {
219
- const addedToken = tokenData[this.addedToken.toLowerCase()];
220
- return `Credit account ${getContractName(
221
- this.creditManager
222
- )}: Added ${formatBN(this.amount, addedToken.decimals)} ${
223
- addedToken.symbol
224
- } as collateral`;
225
- }
226
-
227
- serialize(): TxSerialized {
228
- return {
229
- type: "TxAddCollateral",
230
- content: JSON.stringify(this)
231
- };
232
- }
215
+ public readonly amount: BigNumber;
216
+
217
+ public readonly addedToken: string;
218
+
219
+ public readonly creditManager: string;
220
+
221
+ constructor(opts: AddCollateralProps) {
222
+ super({
223
+ block: opts.block,
224
+ txHash: opts.txHash,
225
+ txStatus: opts.txStatus,
226
+ timestamp: opts.timestamp
227
+ });
228
+ this.amount = opts.amount;
229
+ this.addedToken = opts.addedToken;
230
+ this.creditManager = opts.creditManager;
231
+ }
232
+
233
+ toString(tokenData: Record<string, TokenData>): string {
234
+ const addedToken = tokenData[this.addedToken.toLowerCase()];
235
+ return `Credit account ${getContractName(
236
+ this.creditManager
237
+ )}: Added ${formatBN(this.amount, addedToken.decimals)} ${
238
+ addedToken.symbol
239
+ } as collateral`;
240
+ }
241
+
242
+ serialize(): TxSerialized {
243
+ return {
244
+ type: "TxAddCollateral",
245
+ content: JSON.stringify(this)
246
+ };
247
+ }
233
248
  }
234
249
 
235
250
  interface IncreaseBorrowAmountProps extends EVMTxProps {
236
- amount: BigNumber;
237
- underlyingToken: string;
238
- creditManager: string;
251
+ amount: BigNumber;
252
+ underlyingToken: string;
253
+ creditManager: string;
239
254
  }
240
255
 
241
256
  export class TxIncreaseBorrowAmount extends EVMTx {
242
- public readonly amount: BigNumber;
243
- public readonly underlyingToken: string;
244
- public readonly creditManager: string;
245
-
246
- constructor(opts: IncreaseBorrowAmountProps) {
247
- super({
248
- block: opts.block,
249
- txHash: opts.txHash,
250
- txStatus: opts.txStatus,
251
- timestamp: opts.timestamp
252
- });
253
- this.amount = opts.amount;
254
- this.underlyingToken = opts.underlyingToken;
255
- this.creditManager = opts.creditManager;
256
- }
257
-
258
- toString(tokenData: Record<string, TokenData>): string {
259
- const token = tokenData[this.underlyingToken.toLowerCase()];
260
- return `Credit account ${getContractName(
261
- this.creditManager
262
- )}: Borrowed amount was increased for ${formatBN(
263
- this.amount,
264
- token?.decimals || 18
265
- )} ${token?.symbol}`;
266
- }
267
-
268
- serialize(): TxSerialized {
269
- return {
270
- type: "TxIncreaseBorrowAmount",
271
- content: JSON.stringify(this)
272
- };
273
- }
257
+ public readonly amount: BigNumber;
258
+
259
+ public readonly underlyingToken: string;
260
+
261
+ public readonly creditManager: string;
262
+
263
+ constructor(opts: IncreaseBorrowAmountProps) {
264
+ super({
265
+ block: opts.block,
266
+ txHash: opts.txHash,
267
+ txStatus: opts.txStatus,
268
+ timestamp: opts.timestamp
269
+ });
270
+ this.amount = opts.amount;
271
+ this.underlyingToken = opts.underlyingToken;
272
+ this.creditManager = opts.creditManager;
273
+ }
274
+
275
+ toString(tokenData: Record<string, TokenData>): string {
276
+ const token = tokenData[this.underlyingToken.toLowerCase()];
277
+ return `Credit account ${getContractName(
278
+ this.creditManager
279
+ )}: Borrowed amount was increased for ${formatBN(
280
+ this.amount,
281
+ token?.decimals || 18
282
+ )} ${token?.symbol}`;
283
+ }
284
+
285
+ serialize(): TxSerialized {
286
+ return {
287
+ type: "TxIncreaseBorrowAmount",
288
+ content: JSON.stringify(this)
289
+ };
290
+ }
274
291
  }
275
292
 
276
293
  interface OpenAccountProps extends EVMTxProps {
277
- amount: BigNumber;
278
- underlyingToken: string;
279
- leverage: number;
280
- creditManager: string;
294
+ amount: BigNumber;
295
+ underlyingToken: string;
296
+ leverage: number;
297
+ creditManager: string;
281
298
  }
282
299
 
283
300
  export class TxOpenAccount extends EVMTx {
284
- public readonly amount: BigNumber;
285
- public readonly underlyingToken: string;
286
- public readonly leverage: number;
287
- public readonly creditManager: string;
288
-
289
- constructor(opts: OpenAccountProps) {
290
- super({
291
- block: opts.block,
292
- txHash: opts.txHash,
293
- txStatus: opts.txStatus,
294
- timestamp: opts.timestamp
295
- });
296
- this.amount = BigNumber.from(opts.amount);
297
- this.underlyingToken = opts.underlyingToken;
298
- this.leverage = opts.leverage;
299
- this.creditManager = opts.creditManager;
300
- }
301
-
302
- toString(tokenData: Record<string, TokenData>): string {
303
- const token = tokenData[this.underlyingToken.toLowerCase()];
304
- return `Credit account ${getContractName(
305
- this.creditManager
306
- )}: opening ${formatBN(this.amount, token?.decimals || 18)} ${
307
- token?.symbol
308
- } x ${this.leverage.toFixed(2)} ⇒
301
+ public readonly amount: BigNumber;
302
+
303
+ public readonly underlyingToken: string;
304
+
305
+ public readonly leverage: number;
306
+
307
+ public readonly creditManager: string;
308
+
309
+ constructor(opts: OpenAccountProps) {
310
+ super({
311
+ block: opts.block,
312
+ txHash: opts.txHash,
313
+ txStatus: opts.txStatus,
314
+ timestamp: opts.timestamp
315
+ });
316
+ this.amount = BigNumber.from(opts.amount);
317
+ this.underlyingToken = opts.underlyingToken;
318
+ this.leverage = opts.leverage;
319
+ this.creditManager = opts.creditManager;
320
+ }
321
+
322
+ toString(tokenData: Record<string, TokenData>): string {
323
+ const token = tokenData[this.underlyingToken.toLowerCase()];
324
+ return `Credit account ${getContractName(
325
+ this.creditManager
326
+ )}: opening ${formatBN(this.amount, token?.decimals || 18)} ${
327
+ token?.symbol
328
+ } x ${this.leverage.toFixed(2)} ⇒
309
329
  ${formatBN(
310
- this.amount
311
- .mul(Math.floor(this.leverage * LEVERAGE_DECIMALS))
312
- .div(LEVERAGE_DECIMALS),
313
- token?.decimals || 18
314
- )} ${token?.symbol}`;
315
- }
330
+ this.amount
331
+ .mul(Math.floor(this.leverage * LEVERAGE_DECIMALS))
332
+ .div(LEVERAGE_DECIMALS),
333
+ token?.decimals || 18
334
+ )} ${token?.symbol}`;
335
+ }
336
+
337
+ serialize(): TxSerialized {
338
+ return {
339
+ type: "TxOpenAccount",
340
+ content: JSON.stringify(this)
341
+ };
342
+ }
343
+ }
316
344
 
317
- serialize(): TxSerialized {
318
- return {
319
- type: "TxOpenAccount",
320
- content: JSON.stringify(this)
321
- };
322
- }
345
+ interface TxOpenMultitokenAccountProps extends EVMTxProps {
346
+ borrowedAmount: BigNumber;
347
+ creditManager: string;
348
+ underlyingToken: string;
349
+ assets: Array<string>;
350
+ }
351
+
352
+ export class TxOpenMultitokenAccount extends EVMTx {
353
+ public readonly borrowedAmount: BigNumber;
354
+
355
+ public readonly creditManager: string;
356
+
357
+ public readonly underlyingToken: string;
358
+
359
+ public readonly assets: Array<string>;
360
+
361
+ constructor(opts: TxOpenMultitokenAccountProps) {
362
+ super({
363
+ block: opts.block,
364
+ txHash: opts.txHash,
365
+ txStatus: opts.txStatus,
366
+ timestamp: opts.timestamp
367
+ });
368
+ this.borrowedAmount = BigNumber.from(opts.borrowedAmount);
369
+ this.underlyingToken = opts.underlyingToken;
370
+ this.creditManager = opts.creditManager;
371
+ this.assets = opts.assets;
372
+ }
373
+
374
+ toString(tokenData: Record<string, TokenData>): string {
375
+ const underlyingToken = tokenData[this.underlyingToken.toLowerCase()];
376
+
377
+ const assetSymbols = this.assets.reduce<Array<string>>(
378
+ (acc, assetAddress) => {
379
+ const token = tokenData[assetAddress.toLowerCase()];
380
+ if (token) acc.push(token.symbol);
381
+ return acc;
382
+ },
383
+ []
384
+ );
385
+
386
+ return `Credit account ${getContractName(
387
+ this.creditManager
388
+ )}: opening. Borrowed amount: ${formatBN(
389
+ this.borrowedAmount,
390
+ underlyingToken?.decimals || 18
391
+ )} ${underlyingToken?.symbol}; assets: ${assetSymbols.join(", ")}`;
392
+ }
393
+
394
+ serialize(): TxSerialized {
395
+ return {
396
+ type: "TxOpenMultitokenAccount",
397
+ content: JSON.stringify(this)
398
+ };
399
+ }
323
400
  }
324
401
 
325
402
  interface RepayAccountProps extends EVMTxProps {
326
- creditManager: string;
403
+ creditManager: string;
327
404
  }
328
405
 
329
406
  export class TxRepayAccount extends EVMTx {
330
- public readonly creditManager: string;
331
-
332
- constructor(opts: RepayAccountProps) {
333
- super({
334
- block: opts.block,
335
- txHash: opts.txHash,
336
- txStatus: opts.txStatus,
337
- timestamp: opts.timestamp
338
- });
339
- this.creditManager = opts.creditManager;
340
- }
341
-
342
- toString(_: Record<string, TokenData>): string {
343
- return `Credit account ${getContractName(
344
- this.creditManager
345
- )}: Repaying account`;
346
- }
347
-
348
- serialize(): TxSerialized {
349
- return {
350
- type: "TxRepayAccount",
351
- content: JSON.stringify(this)
352
- };
353
- }
407
+ public readonly creditManager: string;
408
+
409
+ constructor(opts: RepayAccountProps) {
410
+ super({
411
+ block: opts.block,
412
+ txHash: opts.txHash,
413
+ txStatus: opts.txStatus,
414
+ timestamp: opts.timestamp
415
+ });
416
+ this.creditManager = opts.creditManager;
417
+ }
418
+
419
+ toString(): string {
420
+ return `Credit account ${getContractName(
421
+ this.creditManager
422
+ )}: Repaying account`;
423
+ }
424
+
425
+ serialize(): TxSerialized {
426
+ return {
427
+ type: "TxRepayAccount",
428
+ content: JSON.stringify(this)
429
+ };
430
+ }
354
431
  }
355
432
 
356
433
  interface CloseAccountProps extends EVMTxProps {
357
- creditManager: string;
434
+ creditManager: string;
358
435
  }
359
436
 
360
437
  export class TxCloseAccount extends EVMTx {
361
- public readonly creditManager: string;
362
-
363
- constructor(opts: CloseAccountProps) {
364
- super({
365
- block: opts.block,
366
- txHash: opts.txHash,
367
- txStatus: opts.txStatus,
368
- timestamp: opts.timestamp
369
- });
370
- this.creditManager = opts.creditManager;
371
- }
372
-
373
- toString(_: Record<string, TokenData>): string {
374
- return `Credit account ${getContractName(
375
- this.creditManager
376
- )}: Closing account`;
377
- }
378
-
379
- serialize(): TxSerialized {
380
- return {
381
- type: "TxCloseAccount",
382
- content: JSON.stringify(this)
383
- };
384
- }
438
+ public readonly creditManager: string;
439
+
440
+ constructor(opts: CloseAccountProps) {
441
+ super({
442
+ block: opts.block,
443
+ txHash: opts.txHash,
444
+ txStatus: opts.txStatus,
445
+ timestamp: opts.timestamp
446
+ });
447
+ this.creditManager = opts.creditManager;
448
+ }
449
+
450
+ toString(): string {
451
+ return `Credit account ${getContractName(
452
+ this.creditManager
453
+ )}: Closing account`;
454
+ }
455
+
456
+ serialize(): TxSerialized {
457
+ return {
458
+ type: "TxCloseAccount",
459
+ content: JSON.stringify(this)
460
+ };
461
+ }
385
462
  }
386
463
 
387
464
  interface ApproveProps extends EVMTxProps {
388
- token: string;
465
+ token: string;
389
466
  }
390
467
 
391
468
  export class TxApprove extends EVMTx {
392
- public readonly token: string;
393
-
394
- constructor(opts: ApproveProps) {
395
- super({
396
- block: opts.block,
397
- txHash: opts.txHash,
398
- txStatus: opts.txStatus,
399
- timestamp: opts.timestamp
400
- });
401
- this.token = opts.token;
402
- }
403
-
404
- toString(tokenData: Record<string, TokenData>): string {
405
- const token = tokenData[this.token.toLowerCase()];
406
- return `Approve ${token?.symbol}`;
407
- }
408
-
409
- serialize(): TxSerialized {
410
- return {
411
- type: "TxApprove",
412
- content: JSON.stringify(this)
413
- };
414
- }
469
+ public readonly token: string;
470
+
471
+ constructor(opts: ApproveProps) {
472
+ super({
473
+ block: opts.block,
474
+ txHash: opts.txHash,
475
+ txStatus: opts.txStatus,
476
+ timestamp: opts.timestamp
477
+ });
478
+ this.token = opts.token;
479
+ }
480
+
481
+ toString(tokenData: Record<string, TokenData>): string {
482
+ const token = tokenData[this.token.toLowerCase()];
483
+ return `Approve ${token?.symbol}`;
484
+ }
485
+
486
+ serialize(): TxSerialized {
487
+ return {
488
+ type: "TxApprove",
489
+ content: JSON.stringify(this)
490
+ };
491
+ }
415
492
  }