@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.
- package/.eslintignore +5 -0
- package/.eslintrc.js +52 -0
- package/.husky/pre-push +4 -0
- package/lib/apy/convexAPY.js +3 -5
- package/lib/apy/lidoAPY.js +8 -9
- package/lib/contracts/contracts.d.ts +5 -2
- package/lib/contracts/contracts.js +19 -18
- package/lib/core/constants.d.ts +1 -1
- package/lib/core/constants.js +2 -2
- package/lib/core/creditAccount.js +7 -5
- package/lib/core/creditManager.d.ts +1 -1
- package/lib/core/creditManager.js +1 -7
- package/lib/core/creditSession.js +14 -3
- package/lib/core/eventOrTx.d.ts +1 -1
- package/lib/core/events.d.ts +19 -19
- package/lib/core/events.js +23 -21
- package/lib/core/pool.d.ts +1 -1
- package/lib/core/pool.js +1 -7
- package/lib/core/price.js +6 -1
- package/lib/core/strategy.d.ts +1 -3
- package/lib/core/strategy.js +14 -13
- package/lib/core/tokenDistributor.js +1 -1
- package/lib/core/transactions.d.ts +18 -3
- package/lib/core/transactions.js +39 -3
- package/lib/index.d.ts +8 -2
- package/lib/index.js +8 -1
- package/lib/oracles/priceFeeds.js +1 -1
- package/lib/pathfinder/convexLP.d.ts +1 -1
- package/lib/pathfinder/convexLP.js +26 -29
- package/lib/pathfinder/curveLP.d.ts +1 -1
- package/lib/pathfinder/curveLP.js +5 -7
- package/lib/pathfinder/path.d.ts +1 -1
- package/lib/pathfinder/path.js +38 -42
- package/lib/pathfinder/trade.d.ts +1 -2
- package/lib/pathfinder/tradeTypes.d.ts +5 -5
- package/lib/pathfinder/yVault.d.ts +2 -2
- package/lib/pathfinder/yVault.js +18 -15
- package/lib/strategies/convex.d.ts +12 -0
- package/lib/strategies/convex.js +74 -1
- package/lib/strategies/creditFacade.d.ts +1 -0
- package/lib/strategies/creditFacade.js +3 -0
- package/lib/strategies/curve.d.ts +15 -60
- package/lib/strategies/curve.js +74 -1
- package/lib/strategies/lido.d.ts +6 -0
- package/lib/strategies/lido.js +23 -1
- package/lib/strategies/uniswapV2.d.ts +1 -0
- package/lib/strategies/uniswapV2.js +6 -19
- package/lib/strategies/uniswapV3.d.ts +1 -0
- package/lib/strategies/uniswapV3.js +4 -1
- package/lib/strategies/yearn.d.ts +8 -0
- package/lib/strategies/yearn.js +92 -12
- package/lib/tokens/convex.d.ts +3 -3
- package/lib/tokens/curveLP.d.ts +7 -2
- package/lib/tokens/curveLP.js +8 -1
- package/lib/tokens/gear.d.ts +2 -2
- package/lib/tokens/gear.js +1 -1
- package/lib/tokens/normal.d.ts +1 -1
- package/lib/tokens/token.js +4 -4
- package/lib/tokens/tokenData.d.ts +3 -1
- package/lib/tokens/tokenData.js +10 -8
- package/lib/tokens/yearn.d.ts +6 -2
- package/lib/tokens/yearn.js +6 -0
- package/lib/utils/errors.d.ts +6 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/formatter.d.ts +1 -1
- package/lib/utils/formatter.js +17 -14
- package/lib/utils/loading.d.ts +2 -1
- package/lib/utils/loading.js +9 -13
- package/lib/utils/mappers.js +2 -2
- package/lib/utils/network.js +2 -2
- package/lib/utils/repeater.js +12 -24
- package/lib/utils/validate.js +1 -1
- package/package.json +24 -7
- package/src/apy/convexAPY.ts +6 -6
- package/src/apy/lidoAPY.ts +12 -11
- package/src/contracts/contracts.ts +27 -17
- package/src/core/constants.ts +1 -1
- package/src/core/creditAccount.ts +28 -5
- package/src/core/creditManager.ts +29 -4
- package/src/core/creditOperation.ts +7 -7
- package/src/core/creditSession.ts +25 -5
- package/src/core/errors.ts +1 -0
- package/src/core/eventOrTx.ts +8 -5
- package/src/core/events.ts +85 -24
- package/src/core/history.ts +46 -46
- package/src/core/operations.ts +6 -0
- package/src/core/pool.ts +16 -4
- package/src/core/price.ts +7 -3
- package/src/core/strategy.ts +27 -23
- package/src/core/tokenDistributor.ts +2 -2
- package/src/core/transactions.ts +427 -350
- package/src/index.ts +10 -3
- package/src/oracles/priceFeeds.ts +523 -523
- package/src/pathfinder/contracts.ts +15 -13
- package/src/pathfinder/convexLP.ts +29 -25
- package/src/pathfinder/curveLP.ts +57 -53
- package/src/pathfinder/path.ts +17 -9
- package/src/pathfinder/priority.ts +11 -11
- package/src/pathfinder/trade.ts +84 -77
- package/src/pathfinder/tradeTypes.ts +98 -94
- package/src/pathfinder/yVault.ts +26 -11
- package/src/payload/token.ts +3 -3
- package/src/strategies/convex.ts +361 -186
- package/src/strategies/creditFacade.ts +74 -53
- package/src/strategies/curve.ts +400 -189
- package/src/strategies/lido.ts +70 -32
- package/src/strategies/uniswapV2.ts +93 -111
- package/src/strategies/uniswapV3.ts +118 -91
- package/src/strategies/yearn.ts +187 -60
- package/src/tokens/connectors.ts +6 -6
- package/src/tokens/convex.ts +297 -296
- package/src/tokens/curveLP.ts +176 -165
- package/src/tokens/gear.ts +47 -45
- package/src/tokens/normal.ts +801 -802
- package/src/tokens/token.ts +9 -5
- package/src/tokens/tokenData.ts +19 -9
- package/src/tokens/tokenType.ts +11 -11
- package/src/tokens/yearn.ts +130 -124
- package/src/utils/errors.ts +11 -0
- package/src/utils/formatter.ts +22 -18
- package/src/utils/loading.ts +14 -6
- package/src/utils/mappers.ts +8 -6
- package/src/utils/multicall.ts +2 -0
- package/src/utils/network.ts +21 -21
- package/src/utils/repeater.ts +2 -2
- package/src/utils/validate.ts +1 -1
- package/lib/utils/events.d.ts +0 -2
- package/lib/utils/events.js +0 -13
- package/src/utils/events.ts +0 -10
package/src/core/transactions.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
+
| "TxOpenMultitokenAccount";
|
|
20
|
+
content: string;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
23
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
amount: BigNumber;
|
|
61
|
+
underlyingToken: string;
|
|
62
|
+
pool: string;
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
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
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
101
|
+
amount: BigNumber;
|
|
102
|
+
dieselToken: string;
|
|
103
|
+
pool: string;
|
|
99
104
|
}
|
|
100
105
|
|
|
101
106
|
export class TxRemoveLiquidity extends EVMTx {
|
|
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
|
-
|
|
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
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
209
|
+
amount: BigNumber;
|
|
210
|
+
addedToken: string;
|
|
211
|
+
creditManager: string;
|
|
199
212
|
}
|
|
200
213
|
|
|
201
214
|
export class TxAddCollateral extends EVMTx {
|
|
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
|
-
|
|
230
|
-
|
|
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
|
-
|
|
237
|
-
|
|
238
|
-
|
|
251
|
+
amount: BigNumber;
|
|
252
|
+
underlyingToken: string;
|
|
253
|
+
creditManager: string;
|
|
239
254
|
}
|
|
240
255
|
|
|
241
256
|
export class TxIncreaseBorrowAmount extends EVMTx {
|
|
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
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
294
|
+
amount: BigNumber;
|
|
295
|
+
underlyingToken: string;
|
|
296
|
+
leverage: number;
|
|
297
|
+
creditManager: string;
|
|
281
298
|
}
|
|
282
299
|
|
|
283
300
|
export class TxOpenAccount extends EVMTx {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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
|
-
|
|
403
|
+
creditManager: string;
|
|
327
404
|
}
|
|
328
405
|
|
|
329
406
|
export class TxRepayAccount extends EVMTx {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
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
|
-
|
|
434
|
+
creditManager: string;
|
|
358
435
|
}
|
|
359
436
|
|
|
360
437
|
export class TxCloseAccount extends EVMTx {
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
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
|
-
|
|
465
|
+
token: string;
|
|
389
466
|
}
|
|
390
467
|
|
|
391
468
|
export class TxApprove extends EVMTx {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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
|
}
|