@gearbox-protocol/sdk 0.0.66 → 0.0.69
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/lib/contracts/adapters.d.ts +15 -0
- package/lib/contracts/adapters.js +19 -0
- package/lib/contracts/contracts.d.ts +60 -0
- package/lib/contracts/contracts.js +242 -0
- package/lib/contracts/contractsRegister.d.ts +2 -0
- package/lib/contracts/contractsRegister.js +58 -0
- package/lib/contracts/protocols.d.ts +13 -0
- package/lib/contracts/protocols.js +39 -0
- package/lib/core/contracts.js +2 -2
- package/lib/core/events.js +1 -1
- package/lib/core/tradeTypes.d.ts +1 -1
- package/lib/core/transactions.js +1 -1
- package/lib/index.d.ts +8 -9
- package/lib/index.js +10 -10
- package/lib/oracles/oracles.d.ts +38 -0
- package/lib/oracles/oracles.js +12 -0
- package/lib/oracles/priceFeeds.d.ts +3 -0
- package/lib/oracles/priceFeeds.js +492 -0
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +2 -20
- package/lib/pathfinder/curveLP.d.ts +2 -2
- package/lib/pathfinder/curveLP.js +8 -27
- package/lib/pathfinder/path.d.ts +2 -8
- package/lib/pathfinder/path.js +27 -34
- package/lib/pathfinder/trade.d.ts +35 -0
- package/lib/pathfinder/trade.js +62 -0
- package/lib/pathfinder/tradeTypes.d.ts +83 -0
- package/lib/pathfinder/tradeTypes.js +26 -0
- package/lib/pathfinder/yVault.d.ts +1 -1
- package/lib/pathfinder/yVault.js +4 -23
- package/lib/tokens/convex.d.ts +2 -2
- package/lib/tokens/convex.js +1 -1
- package/lib/tokens/curveLP.d.ts +1 -1
- package/lib/tokens/curveLP.js +1 -1
- package/lib/tokens/gear.d.ts +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/normal.js +1 -1
- package/lib/tokens/token.d.ts +1 -1
- package/lib/tokens/token.js +10 -10
- package/lib/tokens/yearn.d.ts +2 -2
- package/lib/tokens/yearn.js +3 -3
- package/package.json +1 -1
- package/src/{core → contracts}/adapters.ts +0 -0
- package/src/{core → contracts}/contracts.ts +10 -10
- package/src/{core → contracts}/contractsRegister.ts +0 -0
- package/src/{core → contracts}/protocols.ts +0 -0
- package/src/core/events.ts +932 -915
- package/src/core/transactions.ts +360 -352
- package/src/index.ts +8 -9
- package/src/{core → oracles}/oracles.ts +0 -0
- package/src/oracles/priceFeeds.ts +528 -0
- package/src/pathfinder/convexLP.ts +1 -1
- package/src/pathfinder/curveLP.ts +3 -4
- package/src/pathfinder/path.ts +23 -53
- package/src/pathfinder/trade.ts +83 -0
- package/src/{core → pathfinder}/tradeTypes.ts +6 -6
- package/src/pathfinder/yVault.ts +1 -2
- package/src/tokens/convex.ts +2 -2
- package/src/tokens/curveLP.ts +1 -1
- package/src/tokens/gear.ts +1 -1
- package/src/tokens/normal.ts +1 -1
- package/src/tokens/token.ts +22 -12
- package/src/tokens/yearn.ts +4 -4
- package/src/core/creditCard.ts +0 -15
- package/src/core/priceFeeds.ts +0 -528
- package/src/core/swap.ts +0 -4
- package/src/core/trade.ts +0 -83
package/src/core/transactions.ts
CHANGED
|
@@ -1,407 +1,415 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
amount: BigNumber;
|
|
58
|
+
underlyingToken: string;
|
|
59
|
+
pool: string;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export class TxAddLiquidity extends EVMTx {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
amount: BigNumber;
|
|
97
|
+
dieselToken: string;
|
|
98
|
+
pool: string;
|
|
99
99
|
}
|
|
100
|
+
|
|
100
101
|
export class TxRemoveLiquidity extends EVMTx {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
196
|
+
amount: BigNumber;
|
|
197
|
+
addedToken: string;
|
|
198
|
+
creditManager: string;
|
|
197
199
|
}
|
|
200
|
+
|
|
198
201
|
export class TxAddCollateral extends EVMTx {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
+
amount: BigNumber;
|
|
237
|
+
underlyingToken: string;
|
|
238
|
+
creditManager: string;
|
|
236
239
|
}
|
|
240
|
+
|
|
237
241
|
export class TxIncreaseBorrowAmount extends EVMTx {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
+
amount: BigNumber;
|
|
278
|
+
underlyingToken: string;
|
|
279
|
+
leverage: number;
|
|
280
|
+
creditManager: string;
|
|
277
281
|
}
|
|
282
|
+
|
|
278
283
|
export class TxOpenAccount extends EVMTx {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
-
|
|
326
|
+
creditManager: string;
|
|
322
327
|
}
|
|
328
|
+
|
|
323
329
|
export class TxRepayAccount extends EVMTx {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
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
|
-
|
|
357
|
+
creditManager: string;
|
|
352
358
|
}
|
|
359
|
+
|
|
353
360
|
export class TxCloseAccount extends EVMTx {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
388
|
+
token: string;
|
|
382
389
|
}
|
|
390
|
+
|
|
383
391
|
export class TxApprove extends EVMTx {
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
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
|
}
|