@gearbox-protocol/sdk 0.0.52 → 0.0.55
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/core/contracts.d.ts +30 -17
- package/lib/core/contracts.js +48 -7
- package/lib/core/contractsRegister.js +24 -6
- package/lib/core/creditAccount.js +26 -20
- package/lib/core/events.d.ts +10 -10
- package/lib/core/events.js +22 -22
- package/lib/core/priceFeeds.js +61 -0
- package/lib/core/token.d.ts +42 -15
- package/lib/core/token.js +523 -46
- package/lib/core/tradeTypes.d.ts +21 -6
- package/lib/core/tradeTypes.js +5 -2
- package/lib/core/transactions.d.ts +2 -2
- package/lib/core/transactions.js +10 -10
- package/lib/index.d.ts +2 -0
- package/lib/index.js +6 -1
- package/lib/utils/mappers.d.ts +6 -0
- package/lib/utils/mappers.js +33 -0
- package/package.json +1 -1
- package/src/core/adapters.ts +13 -15
- package/src/core/contracts.ts +98 -45
- package/src/core/contractsRegister.ts +16 -8
- package/src/core/creditAccount.ts +33 -19
- package/src/core/events.ts +30 -22
- package/src/core/priceFeeds.ts +66 -0
- package/src/core/token.ts +685 -106
- package/src/core/tradeTypes.ts +24 -6
- package/src/core/transactions.ts +10 -10
- package/src/index.ts +2 -0
- package/src/utils/mappers.ts +23 -0
|
@@ -64,25 +64,39 @@ export class CreditAccountData {
|
|
|
64
64
|
prices: Record<string, number>,
|
|
65
65
|
tokens: Record<string, TokenData>
|
|
66
66
|
): Array<Balance> {
|
|
67
|
-
const priceCalc = (addr: string, amount: BigNumber) =>
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
const priceCalc = (addr: string, amount: BigNumber) => {
|
|
68
|
+
const price = prices[addr] || 0;
|
|
69
|
+
const { decimals = 18 } = tokens[addr] || {};
|
|
70
|
+
|
|
71
|
+
return amount
|
|
72
|
+
.mul(Math.floor(1000 * price))
|
|
73
|
+
.div(BigNumber.from(10).pow(decimals));
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const tokensAbcComparator = (t1?: TokenData, t2?: TokenData) => {
|
|
77
|
+
const { symbol: symbol1 = "" } = t1 || {};
|
|
78
|
+
const { symbol: symbol2 = "" } = t2 || {};
|
|
79
|
+
|
|
80
|
+
return symbol1 > symbol2 ? 1 : -1;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const safeBalances = this.balances || [];
|
|
84
|
+
|
|
85
|
+
return Object.entries(safeBalances)
|
|
86
|
+
.sort(([addr1, amount1], [addr2, amount2]) => {
|
|
87
|
+
const addr1Lc = addr1.toLowerCase();
|
|
88
|
+
const addr2Lc = addr2.toLowerCase();
|
|
89
|
+
|
|
90
|
+
const price1 = priceCalc(addr1Lc, amount1);
|
|
91
|
+
const price2 = priceCalc(addr2Lc, amount2);
|
|
92
|
+
|
|
93
|
+
return price1.eq(price2)
|
|
94
|
+
? tokensAbcComparator(tokens[addr1Lc], tokens[addr2Lc])
|
|
95
|
+
: price1.gt(price2)
|
|
96
|
+
? -1
|
|
97
|
+
: 1;
|
|
98
|
+
})
|
|
99
|
+
.map(([address, balance]) => ({ address, balance }));
|
|
86
100
|
}
|
|
87
101
|
}
|
|
88
102
|
|
package/src/core/events.ts
CHANGED
|
@@ -145,7 +145,8 @@ export class EventAddLiquidity extends EVMEvent {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
toString(tokenData: Record<string, TokenData>): string {
|
|
148
|
-
const { decimals = 18, symbol } =
|
|
148
|
+
const { decimals = 18, symbol } =
|
|
149
|
+
tokenData[this.underlyingToken.toLowerCase()] || {};
|
|
149
150
|
|
|
150
151
|
return `Pool ${getContractName(this.pool)}: Deposit ${formatBN(
|
|
151
152
|
this.amount,
|
|
@@ -179,7 +180,8 @@ export class EventRemoveLiquidity extends EVMEvent {
|
|
|
179
180
|
}
|
|
180
181
|
|
|
181
182
|
toString(tokenData: Record<string, TokenData>): string {
|
|
182
|
-
const { decimals = 18, symbol } =
|
|
183
|
+
const { decimals = 18, symbol } =
|
|
184
|
+
tokenData[this.dieselToken.toLowerCase()] || {};
|
|
183
185
|
|
|
184
186
|
return `Pool ${getContractName(this.pool)}: withdraw ${formatBN(
|
|
185
187
|
this.amount,
|
|
@@ -215,7 +217,8 @@ export class EventOpenCreditAccount extends EVMEvent {
|
|
|
215
217
|
}
|
|
216
218
|
|
|
217
219
|
toString(tokenData: Record<string, TokenData>): string {
|
|
218
|
-
const { decimals = 18, symbol } =
|
|
220
|
+
const { decimals = 18, symbol } =
|
|
221
|
+
tokenData[this.underlyingToken.toLowerCase()] || {};
|
|
219
222
|
|
|
220
223
|
return `Credit account ${getContractName(
|
|
221
224
|
this.creditManager
|
|
@@ -254,7 +257,8 @@ export class EventCloseCreditAccount extends EVMEvent {
|
|
|
254
257
|
}
|
|
255
258
|
|
|
256
259
|
toString(tokenData: Record<string, TokenData>): string {
|
|
257
|
-
const { decimals = 18, symbol } =
|
|
260
|
+
const { decimals = 18, symbol } =
|
|
261
|
+
tokenData[this.underlyingToken.toLowerCase()] || {};
|
|
258
262
|
|
|
259
263
|
return `Credit account ${getContractName(
|
|
260
264
|
this.creditManager
|
|
@@ -287,7 +291,8 @@ export class EventLiquidateCreditAccount extends EVMEvent {
|
|
|
287
291
|
}
|
|
288
292
|
|
|
289
293
|
toString(tokenData: Record<string, TokenData>): string {
|
|
290
|
-
const { decimals = 18, symbol } =
|
|
294
|
+
const { decimals = 18, symbol } =
|
|
295
|
+
tokenData[this.underlyingToken.toLowerCase()] || {};
|
|
291
296
|
|
|
292
297
|
return `Credit account ${getContractName(
|
|
293
298
|
this.creditManager
|
|
@@ -316,7 +321,7 @@ export class EventRepayCreditAccount extends EVMEvent {
|
|
|
316
321
|
this.creditManager = opts.creditManager;
|
|
317
322
|
}
|
|
318
323
|
|
|
319
|
-
toString(
|
|
324
|
+
toString(_: Record<string, TokenData>): string {
|
|
320
325
|
return `Credit account ${getContractName(this.creditManager)}: was repaid`;
|
|
321
326
|
}
|
|
322
327
|
}
|
|
@@ -344,7 +349,8 @@ export class EventAddCollateral extends EVMEvent {
|
|
|
344
349
|
}
|
|
345
350
|
|
|
346
351
|
toString(tokenData: Record<string, TokenData>): string {
|
|
347
|
-
const { decimals = 18, symbol } =
|
|
352
|
+
const { decimals = 18, symbol } =
|
|
353
|
+
tokenData[this.addedToken.toLowerCase()] || {};
|
|
348
354
|
|
|
349
355
|
return `Credit account ${getContractName(
|
|
350
356
|
this.creditManager
|
|
@@ -374,7 +380,8 @@ export class EventIncreaseBorrowAmount extends EVMEvent {
|
|
|
374
380
|
}
|
|
375
381
|
|
|
376
382
|
toString(tokenData: Record<string, TokenData>): string {
|
|
377
|
-
const { decimals = 18, symbol } =
|
|
383
|
+
const { decimals = 18, symbol } =
|
|
384
|
+
tokenData[this.underlyingToken.toLowerCase()] || {};
|
|
378
385
|
|
|
379
386
|
return `Credit account ${getContractName(
|
|
380
387
|
this.creditManager
|
|
@@ -451,7 +458,7 @@ export class EventCMNewParameters extends EVMEvent {
|
|
|
451
458
|
}
|
|
452
459
|
|
|
453
460
|
toString(tokenData: Record<string, TokenData>): string {
|
|
454
|
-
const token = tokenData[this.underlyingToken];
|
|
461
|
+
const token = tokenData[this.underlyingToken.toLowerCase()];
|
|
455
462
|
let msg = `Credit manager ${getContractName(this.creditManager)} updated: `;
|
|
456
463
|
|
|
457
464
|
if (this.minAmount !== this.prevMinAmount) {
|
|
@@ -529,7 +536,7 @@ export class EventTokenAllowed extends EVMEvent {
|
|
|
529
536
|
}
|
|
530
537
|
|
|
531
538
|
toString(tokenData: Record<string, TokenData>): string {
|
|
532
|
-
const token = tokenData[this.token];
|
|
539
|
+
const token = tokenData[this.token.toLowerCase()];
|
|
533
540
|
let msg = `Credit manager ${getContractName(this.creditManager)} updated `;
|
|
534
541
|
switch (this.status) {
|
|
535
542
|
case "NewToken":
|
|
@@ -573,7 +580,7 @@ export class EventTokenForbidden extends EVMEvent {
|
|
|
573
580
|
}
|
|
574
581
|
|
|
575
582
|
toString(tokenData: Record<string, TokenData>): string {
|
|
576
|
-
const token = tokenData[this.token];
|
|
583
|
+
const token = tokenData[this.token.toLowerCase()];
|
|
577
584
|
return `Credit manager ${getContractName(this.creditManager)} updated ${
|
|
578
585
|
token.symbol
|
|
579
586
|
} forbidden`;
|
|
@@ -894,7 +901,8 @@ export class EventNewExpectedLiquidityLimit extends EVMEvent {
|
|
|
894
901
|
}
|
|
895
902
|
|
|
896
903
|
toString(tokenData: Record<string, TokenData>): string {
|
|
897
|
-
const { decimals = 18, symbol } =
|
|
904
|
+
const { decimals = 18, symbol } =
|
|
905
|
+
tokenData[this.underlyingToken.toLowerCase()] || {};
|
|
898
906
|
|
|
899
907
|
return this.prevLimit.isZero()
|
|
900
908
|
? `Pool ${getContractName(
|
|
@@ -942,7 +950,7 @@ export class EventNewWithdrawFee extends EVMEvent {
|
|
|
942
950
|
this.prevFee = Number(opts.oldFee);
|
|
943
951
|
}
|
|
944
952
|
|
|
945
|
-
toString(
|
|
953
|
+
toString(_: Record<string, TokenData>): string {
|
|
946
954
|
return this.prevFee === 0
|
|
947
955
|
? `Pool ${getContractName(this.pool)} updated: withdraw fee was set to: ${
|
|
948
956
|
this.newFee / 100
|
|
@@ -975,7 +983,7 @@ export class EventNewPriceFeed extends EVMEvent {
|
|
|
975
983
|
}
|
|
976
984
|
|
|
977
985
|
toString(tokenData: Record<string, TokenData>): string {
|
|
978
|
-
const { symbol } = tokenData[this.token] || {};
|
|
986
|
+
const { symbol } = tokenData[this.token.toLowerCase()] || {};
|
|
979
987
|
|
|
980
988
|
return `PriceOracle: oracle for ${symbol} was updated to ${getContractName(
|
|
981
989
|
this.priceFeed
|
|
@@ -1005,7 +1013,7 @@ export class EventTakeForever extends EVMEvent {
|
|
|
1005
1013
|
this.to = opts.to;
|
|
1006
1014
|
}
|
|
1007
1015
|
|
|
1008
|
-
toString(
|
|
1016
|
+
toString(_: Record<string, TokenData>): string {
|
|
1009
1017
|
return `AccountFactory: account ${this.creditAccount} was taken forever and transferred to ${this.to}`;
|
|
1010
1018
|
}
|
|
1011
1019
|
}
|
|
@@ -1027,7 +1035,7 @@ export class EventPaused extends EVMEvent {
|
|
|
1027
1035
|
this.contract = opts.contract;
|
|
1028
1036
|
}
|
|
1029
1037
|
|
|
1030
|
-
toString(
|
|
1038
|
+
toString(_: Record<string, TokenData>): string {
|
|
1031
1039
|
return `${getContractName(this.contract)} was paused`;
|
|
1032
1040
|
}
|
|
1033
1041
|
}
|
|
@@ -1047,7 +1055,7 @@ export class EventUnPaused extends EVMEvent {
|
|
|
1047
1055
|
this.contract = opts.contract;
|
|
1048
1056
|
}
|
|
1049
1057
|
|
|
1050
|
-
toString(
|
|
1058
|
+
toString(_: Record<string, TokenData>): string {
|
|
1051
1059
|
return `${getContractName(this.contract)} was unpaused`;
|
|
1052
1060
|
}
|
|
1053
1061
|
}
|
|
@@ -1070,7 +1078,7 @@ export class EventPausableAdminAdded extends EVMEvent {
|
|
|
1070
1078
|
this.admin = opts.admin;
|
|
1071
1079
|
}
|
|
1072
1080
|
|
|
1073
|
-
toString(
|
|
1081
|
+
toString(_: Record<string, TokenData>): string {
|
|
1074
1082
|
return `ACL: pausable admin ${this.admin} was added`;
|
|
1075
1083
|
}
|
|
1076
1084
|
}
|
|
@@ -1093,7 +1101,7 @@ export class EventPausableAdminRemoved extends EVMEvent {
|
|
|
1093
1101
|
this.admin = opts.admin;
|
|
1094
1102
|
}
|
|
1095
1103
|
|
|
1096
|
-
toString(
|
|
1104
|
+
toString(_: Record<string, TokenData>): string {
|
|
1097
1105
|
return `ACL: pausable admin ${this.admin} was removed`;
|
|
1098
1106
|
}
|
|
1099
1107
|
}
|
|
@@ -1116,7 +1124,7 @@ export class EventUnPausableAdminAdded extends EVMEvent {
|
|
|
1116
1124
|
this.admin = opts.admin;
|
|
1117
1125
|
}
|
|
1118
1126
|
|
|
1119
|
-
toString(
|
|
1127
|
+
toString(_: Record<string, TokenData>): string {
|
|
1120
1128
|
return `ACL: unpausable admin ${this.admin} was added`;
|
|
1121
1129
|
}
|
|
1122
1130
|
}
|
|
@@ -1139,7 +1147,7 @@ export class EventUnPausableAdminRemoved extends EVMEvent {
|
|
|
1139
1147
|
this.admin = opts.admin;
|
|
1140
1148
|
}
|
|
1141
1149
|
|
|
1142
|
-
toString(
|
|
1150
|
+
toString(_: Record<string, TokenData>): string {
|
|
1143
1151
|
return `ACL: unpausable admin ${this.admin} was removed`;
|
|
1144
1152
|
}
|
|
1145
1153
|
}
|
|
@@ -1161,7 +1169,7 @@ export class EventTransferOwnership extends EVMEvent {
|
|
|
1161
1169
|
this.newOwner = opts.admin;
|
|
1162
1170
|
}
|
|
1163
1171
|
|
|
1164
|
-
toString(
|
|
1172
|
+
toString(_: Record<string, TokenData>): string {
|
|
1165
1173
|
return `ACL: configurator was changed to ${this.newOwner}`;
|
|
1166
1174
|
}
|
|
1167
1175
|
}
|
package/src/core/priceFeeds.ts
CHANGED
|
@@ -458,5 +458,71 @@ export const priceFeedsByNetwork: Record<SupportedToken, TokenPriceFeedData> = {
|
|
|
458
458
|
type: OracleType.LIKE_CURVE_LP_ORACLE,
|
|
459
459
|
curveSymbol: "gusd3CRV"
|
|
460
460
|
}
|
|
461
|
+
},
|
|
462
|
+
|
|
463
|
+
//GEARBOX
|
|
464
|
+
dDAI: {
|
|
465
|
+
priceFeedETH: {
|
|
466
|
+
type: OracleType.CHAINLINK_ORACLE,
|
|
467
|
+
address: "",
|
|
468
|
+
kovan: ""
|
|
469
|
+
},
|
|
470
|
+
priceFeedUSD: {
|
|
471
|
+
type: OracleType.CHAINLINK_ORACLE,
|
|
472
|
+
address: "",
|
|
473
|
+
kovan: ""
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
|
|
477
|
+
dUSDC: {
|
|
478
|
+
priceFeedETH: {
|
|
479
|
+
type: OracleType.CHAINLINK_ORACLE,
|
|
480
|
+
address: "",
|
|
481
|
+
kovan: ""
|
|
482
|
+
},
|
|
483
|
+
priceFeedUSD: {
|
|
484
|
+
type: OracleType.CHAINLINK_ORACLE,
|
|
485
|
+
address: "",
|
|
486
|
+
kovan: ""
|
|
487
|
+
}
|
|
488
|
+
},
|
|
489
|
+
|
|
490
|
+
dWBTC: {
|
|
491
|
+
priceFeedETH: {
|
|
492
|
+
type: OracleType.CHAINLINK_ORACLE,
|
|
493
|
+
address: "",
|
|
494
|
+
kovan: ""
|
|
495
|
+
},
|
|
496
|
+
priceFeedUSD: {
|
|
497
|
+
type: OracleType.CHAINLINK_ORACLE,
|
|
498
|
+
address: "",
|
|
499
|
+
kovan: ""
|
|
500
|
+
}
|
|
501
|
+
},
|
|
502
|
+
|
|
503
|
+
dWETH: {
|
|
504
|
+
priceFeedETH: {
|
|
505
|
+
type: OracleType.CHAINLINK_ORACLE,
|
|
506
|
+
address: "",
|
|
507
|
+
kovan: ""
|
|
508
|
+
},
|
|
509
|
+
priceFeedUSD: {
|
|
510
|
+
type: OracleType.CHAINLINK_ORACLE,
|
|
511
|
+
address: "",
|
|
512
|
+
kovan: ""
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
|
|
516
|
+
GEAR: {
|
|
517
|
+
priceFeedETH: {
|
|
518
|
+
type: OracleType.CHAINLINK_ORACLE,
|
|
519
|
+
address: "",
|
|
520
|
+
kovan: ""
|
|
521
|
+
},
|
|
522
|
+
priceFeedUSD: {
|
|
523
|
+
type: OracleType.CHAINLINK_ORACLE,
|
|
524
|
+
address: "",
|
|
525
|
+
kovan: ""
|
|
526
|
+
}
|
|
461
527
|
}
|
|
462
528
|
};
|