@gearbox-protocol/sdk 0.0.67 → 0.0.68

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 (66) hide show
  1. package/lib/contracts/adapters.d.ts +15 -0
  2. package/lib/contracts/adapters.js +19 -0
  3. package/lib/contracts/contracts.d.ts +60 -0
  4. package/lib/contracts/contracts.js +242 -0
  5. package/lib/contracts/contractsRegister.d.ts +2 -0
  6. package/lib/contracts/contractsRegister.js +58 -0
  7. package/lib/contracts/protocols.d.ts +13 -0
  8. package/lib/contracts/protocols.js +39 -0
  9. package/lib/core/events.js +1 -1
  10. package/lib/core/tradeTypes.d.ts +1 -1
  11. package/lib/core/transactions.js +1 -1
  12. package/lib/index.d.ts +8 -9
  13. package/lib/index.js +10 -10
  14. package/lib/oracles/oracles.d.ts +38 -0
  15. package/lib/oracles/oracles.js +12 -0
  16. package/lib/oracles/priceFeeds.d.ts +3 -0
  17. package/lib/oracles/priceFeeds.js +492 -0
  18. package/lib/pathfinder/convexLP.d.ts +1 -1
  19. package/lib/pathfinder/convexLP.js +2 -20
  20. package/lib/pathfinder/curveLP.d.ts +2 -2
  21. package/lib/pathfinder/curveLP.js +8 -27
  22. package/lib/pathfinder/path.d.ts +2 -8
  23. package/lib/pathfinder/path.js +27 -34
  24. package/lib/pathfinder/trade.d.ts +35 -0
  25. package/lib/pathfinder/trade.js +62 -0
  26. package/lib/pathfinder/tradeTypes.d.ts +83 -0
  27. package/lib/pathfinder/tradeTypes.js +26 -0
  28. package/lib/pathfinder/yVault.d.ts +1 -1
  29. package/lib/pathfinder/yVault.js +4 -23
  30. package/lib/tokens/convex.d.ts +2 -2
  31. package/lib/tokens/convex.js +1 -1
  32. package/lib/tokens/curveLP.d.ts +1 -1
  33. package/lib/tokens/curveLP.js +1 -1
  34. package/lib/tokens/gear.d.ts +1 -1
  35. package/lib/tokens/normal.d.ts +1 -1
  36. package/lib/tokens/normal.js +1 -1
  37. package/lib/tokens/token.d.ts +1 -1
  38. package/lib/tokens/token.js +5 -5
  39. package/lib/tokens/yearn.d.ts +2 -2
  40. package/lib/tokens/yearn.js +3 -3
  41. package/package.json +1 -1
  42. package/src/{core → contracts}/adapters.ts +0 -0
  43. package/src/{core → contracts}/contracts.ts +3 -3
  44. package/src/{core → contracts}/contractsRegister.ts +0 -0
  45. package/src/{core → contracts}/protocols.ts +0 -0
  46. package/src/core/events.ts +932 -915
  47. package/src/core/transactions.ts +360 -352
  48. package/src/index.ts +8 -9
  49. package/src/{core → oracles}/oracles.ts +0 -0
  50. package/src/oracles/priceFeeds.ts +528 -0
  51. package/src/pathfinder/convexLP.ts +1 -1
  52. package/src/pathfinder/curveLP.ts +3 -4
  53. package/src/pathfinder/path.ts +23 -53
  54. package/src/pathfinder/trade.ts +83 -0
  55. package/src/{core → pathfinder}/tradeTypes.ts +6 -6
  56. package/src/pathfinder/yVault.ts +1 -2
  57. package/src/tokens/convex.ts +2 -2
  58. package/src/tokens/curveLP.ts +1 -1
  59. package/src/tokens/gear.ts +1 -1
  60. package/src/tokens/normal.ts +1 -1
  61. package/src/tokens/token.ts +17 -7
  62. package/src/tokens/yearn.ts +4 -4
  63. package/src/core/creditCard.ts +0 -15
  64. package/src/core/priceFeeds.ts +0 -528
  65. package/src/core/swap.ts +0 -4
  66. package/src/core/trade.ts +0 -83
@@ -1,407 +1,415 @@
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 "./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
+ content: string;
20
20
  }
21
21
 
22
22
  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
- }
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
+ }
54
54
  }
55
55
 
56
56
  interface AddLiquidityProps extends EVMTxProps {
57
- amount: BigNumber;
58
- underlyingToken: string;
59
- pool: string;
57
+ amount: BigNumber;
58
+ underlyingToken: string;
59
+ pool: string;
60
60
  }
61
61
 
62
62
  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
- }
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
+ }
93
93
  }
94
94
 
95
95
  interface RemoveLiquidityProps extends EVMTxProps {
96
- amount: BigNumber;
97
- dieselToken: string;
98
- pool: string;
96
+ amount: BigNumber;
97
+ dieselToken: string;
98
+ pool: string;
99
99
  }
100
+
100
101
  export class TxRemoveLiquidity extends EVMTx {
101
- public readonly amount: BigNumber;
102
- public readonly dieselToken: string;
103
- public readonly pool: string;
104
-
105
- constructor(opts: RemoveLiquidityProps) {
106
- super({
107
- block: opts.block,
108
- txHash: opts.txHash,
109
- txStatus: opts.txStatus,
110
- timestamp: opts.timestamp
111
- });
112
- this.amount = opts.amount;
113
- this.dieselToken = opts.dieselToken;
114
- this.pool = opts.pool;
115
- }
116
-
117
- toString(tokenData: Record<string, TokenData>): string {
118
- const dtoken = tokenData[this.dieselToken.toLowerCase()];
119
- return `${getContractName(this.pool)}: Withdraw ${formatBN(
120
- this.amount,
121
- dtoken?.decimals || 18
122
- )} ${dtoken?.symbol || ""}`;
123
- }
124
-
125
- serialize(): TxSerialized {
126
- return {
127
- type: "TxRemoveLiquidity",
128
- content: JSON.stringify(this)
129
- };
130
- }
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
+ }
131
132
  }
132
133
 
133
134
  interface SwapProps extends EVMTxProps {
134
- protocol: string;
135
- operation: string;
136
- amountFrom: BigNumber;
137
- amountTo?: BigNumber;
138
- tokenFrom: string;
139
- tokenTo?: string;
140
- creditManager: string;
135
+ protocol: string;
136
+ operation: string;
137
+ amountFrom: BigNumber;
138
+ amountTo?: BigNumber;
139
+ tokenFrom: string;
140
+ tokenTo?: string;
141
+ creditManager: string;
141
142
  }
143
+
142
144
  export class TXSwap extends EVMTx {
143
- public readonly protocol: string;
144
- public readonly operation: string;
145
- public readonly amountFrom: BigNumber;
146
- public readonly amountTo?: BigNumber;
147
- public readonly tokenFrom: string;
148
- public readonly tokenTo?: string;
149
- public readonly creditManager: string;
150
-
151
- constructor(opts: SwapProps) {
152
- super({
153
- block: opts.block,
154
- txHash: opts.txHash,
155
- txStatus: opts.txStatus,
156
- timestamp: opts.timestamp
157
- });
158
- this.protocol = opts.protocol;
159
- this.operation = opts.operation;
160
- this.amountFrom = opts.amountFrom;
161
- this.amountTo = opts.amountTo;
162
- this.tokenFrom = opts.tokenFrom;
163
- this.tokenTo = opts.tokenTo;
164
- this.creditManager = opts.creditManager;
165
- }
166
-
167
- toString(tokenData: Record<string, TokenData>): string {
168
- const tokenFrom = tokenData[this.tokenFrom.toLowerCase()];
169
-
170
- let toPart = "";
171
- if (this.tokenTo && this.amountTo) {
172
- const tokenTo = tokenData[this.tokenTo.toLowerCase()];
173
- toPart = ` ⇒ ${formatBN(this.amountTo, tokenTo?.decimals || 18)} ${
174
- tokenTo?.symbol || ""
175
- }`;
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
+ }
168
+
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)}`;
176
185
  }
177
186
 
178
- return `Credit account ${getContractName(this.creditManager)}: ${
179
- this.operation
180
- } ${formatBN(this.amountFrom, tokenFrom?.decimals || 18)} ${
181
- tokenFrom?.symbol || ""
182
- } ${toPart} on ${getContractName(this.protocol)}`;
183
- }
184
-
185
- serialize(): TxSerialized {
186
- return {
187
- type: "TxSwap",
188
- content: JSON.stringify(this)
189
- };
190
- }
187
+ serialize(): TxSerialized {
188
+ return {
189
+ type: "TxSwap",
190
+ content: JSON.stringify(this)
191
+ };
192
+ }
191
193
  }
192
194
 
193
195
  interface AddCollateralProps extends EVMTxProps {
194
- amount: BigNumber;
195
- addedToken: string;
196
- creditManager: string;
196
+ amount: BigNumber;
197
+ addedToken: string;
198
+ creditManager: string;
197
199
  }
200
+
198
201
  export class TxAddCollateral extends EVMTx {
199
- public readonly amount: BigNumber;
200
- public readonly addedToken: string;
201
- public readonly creditManager: string;
202
-
203
- constructor(opts: AddCollateralProps) {
204
- super({
205
- block: opts.block,
206
- txHash: opts.txHash,
207
- txStatus: opts.txStatus,
208
- timestamp: opts.timestamp
209
- });
210
- this.amount = opts.amount;
211
- this.addedToken = opts.addedToken;
212
- this.creditManager = opts.creditManager;
213
- }
214
-
215
- toString(tokenData: Record<string, TokenData>): string {
216
- const addedToken = tokenData[this.addedToken.toLowerCase()];
217
- return `Credit account ${getContractName(
218
- this.creditManager
219
- )}: Added ${formatBN(this.amount, addedToken.decimals)} ${
220
- addedToken.symbol
221
- } as collateral`;
222
- }
223
-
224
- serialize(): TxSerialized {
225
- return {
226
- type: "TxAddCollateral",
227
- content: JSON.stringify(this)
228
- };
229
- }
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
+ }
230
233
  }
231
234
 
232
235
  interface IncreaseBorrowAmountProps extends EVMTxProps {
233
- amount: BigNumber;
234
- underlyingToken: string;
235
- creditManager: string;
236
+ amount: BigNumber;
237
+ underlyingToken: string;
238
+ creditManager: string;
236
239
  }
240
+
237
241
  export class TxIncreaseBorrowAmount extends EVMTx {
238
- public readonly amount: BigNumber;
239
- public readonly underlyingToken: string;
240
- public readonly creditManager: string;
241
-
242
- constructor(opts: IncreaseBorrowAmountProps) {
243
- super({
244
- block: opts.block,
245
- txHash: opts.txHash,
246
- txStatus: opts.txStatus,
247
- timestamp: opts.timestamp
248
- });
249
- this.amount = opts.amount;
250
- this.underlyingToken = opts.underlyingToken;
251
- this.creditManager = opts.creditManager;
252
- }
253
-
254
- toString(tokenData: Record<string, TokenData>): string {
255
- const token = tokenData[this.underlyingToken.toLowerCase()];
256
- return `Credit account ${getContractName(
257
- this.creditManager
258
- )}: Borrowed amount was increased for ${formatBN(
259
- this.amount,
260
- token?.decimals || 18
261
- )} ${token?.symbol}`;
262
- }
263
-
264
- serialize(): TxSerialized {
265
- return {
266
- type: "TxIncreaseBorrowAmount",
267
- content: JSON.stringify(this)
268
- };
269
- }
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
+ }
270
274
  }
271
275
 
272
276
  interface OpenAccountProps extends EVMTxProps {
273
- amount: BigNumber;
274
- underlyingToken: string;
275
- leverage: number;
276
- creditManager: string;
277
+ amount: BigNumber;
278
+ underlyingToken: string;
279
+ leverage: number;
280
+ creditManager: string;
277
281
  }
282
+
278
283
  export class TxOpenAccount extends EVMTx {
279
- public readonly amount: BigNumber;
280
- public readonly underlyingToken: string;
281
- public readonly leverage: number;
282
- public readonly creditManager: string;
283
-
284
- constructor(opts: OpenAccountProps) {
285
- super({
286
- block: opts.block,
287
- txHash: opts.txHash,
288
- txStatus: opts.txStatus,
289
- timestamp: opts.timestamp
290
- });
291
- this.amount = BigNumber.from(opts.amount);
292
- this.underlyingToken = opts.underlyingToken;
293
- this.leverage = opts.leverage;
294
- this.creditManager = opts.creditManager;
295
- }
296
-
297
- toString(tokenData: Record<string, TokenData>): string {
298
- const token = tokenData[this.underlyingToken.toLowerCase()];
299
- return `Credit account ${getContractName(
300
- this.creditManager
301
- )}: opening ${formatBN(this.amount, token?.decimals || 18)} ${
302
- token?.symbol
303
- } x ${this.leverage.toFixed(2)} ⇒
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)} ⇒
304
309
  ${formatBN(
305
- this.amount
306
- .mul(Math.floor(this.leverage * LEVERAGE_DECIMALS))
307
- .div(LEVERAGE_DECIMALS),
308
- token?.decimals || 18
309
- )} ${token?.symbol}`;
310
- }
311
-
312
- serialize(): TxSerialized {
313
- return {
314
- type: "TxOpenAccount",
315
- content: JSON.stringify(this)
316
- };
317
- }
310
+ this.amount
311
+ .mul(Math.floor(this.leverage * LEVERAGE_DECIMALS))
312
+ .div(LEVERAGE_DECIMALS),
313
+ token?.decimals || 18
314
+ )} ${token?.symbol}`;
315
+ }
316
+
317
+ serialize(): TxSerialized {
318
+ return {
319
+ type: "TxOpenAccount",
320
+ content: JSON.stringify(this)
321
+ };
322
+ }
318
323
  }
319
324
 
320
325
  interface RepayAccountProps extends EVMTxProps {
321
- creditManager: string;
326
+ creditManager: string;
322
327
  }
328
+
323
329
  export class TxRepayAccount extends EVMTx {
324
- public readonly creditManager: string;
325
-
326
- constructor(opts: RepayAccountProps) {
327
- super({
328
- block: opts.block,
329
- txHash: opts.txHash,
330
- txStatus: opts.txStatus,
331
- timestamp: opts.timestamp
332
- });
333
- this.creditManager = opts.creditManager;
334
- }
335
-
336
- toString(_: Record<string, TokenData>): string {
337
- return `Credit account ${getContractName(
338
- this.creditManager
339
- )}: Repaying account`;
340
- }
341
-
342
- serialize(): TxSerialized {
343
- return {
344
- type: "TxRepayAccount",
345
- content: JSON.stringify(this)
346
- };
347
- }
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
+ }
348
354
  }
349
355
 
350
356
  interface CloseAccountProps extends EVMTxProps {
351
- creditManager: string;
357
+ creditManager: string;
352
358
  }
359
+
353
360
  export class TxCloseAccount extends EVMTx {
354
- public readonly creditManager: string;
355
-
356
- constructor(opts: CloseAccountProps) {
357
- super({
358
- block: opts.block,
359
- txHash: opts.txHash,
360
- txStatus: opts.txStatus,
361
- timestamp: opts.timestamp
362
- });
363
- this.creditManager = opts.creditManager;
364
- }
365
-
366
- toString(_: Record<string, TokenData>): string {
367
- return `Credit account ${getContractName(
368
- this.creditManager
369
- )}: Closing account`;
370
- }
371
-
372
- serialize(): TxSerialized {
373
- return {
374
- type: "TxCloseAccount",
375
- content: JSON.stringify(this)
376
- };
377
- }
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
+ }
378
385
  }
379
386
 
380
387
  interface ApproveProps extends EVMTxProps {
381
- token: string;
388
+ token: string;
382
389
  }
390
+
383
391
  export class TxApprove extends EVMTx {
384
- public readonly token: string;
385
-
386
- constructor(opts: ApproveProps) {
387
- super({
388
- block: opts.block,
389
- txHash: opts.txHash,
390
- txStatus: opts.txStatus,
391
- timestamp: opts.timestamp
392
- });
393
- this.token = opts.token;
394
- }
395
-
396
- toString(tokenData: Record<string, TokenData>): string {
397
- const token = tokenData[this.token.toLowerCase()];
398
- return `Approve ${token?.symbol}`;
399
- }
400
-
401
- serialize(): TxSerialized {
402
- return {
403
- type: "TxApprove",
404
- content: JSON.stringify(this)
405
- };
406
- }
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
+ }
407
415
  }