@gearbox-protocol/sdk 12.9.0-txparser.2 → 12.9.0-txparser.4
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/dist/cjs/history/extractTransfers.js +3 -1
- package/dist/cjs/history/index.js +5 -4
- package/dist/cjs/history/mapOperations.js +79 -0
- package/dist/cjs/history/parseCreditAccountTransaction.js +1 -7
- package/dist/cjs/history/toLegacyOperation.js +98 -89
- package/dist/esm/history/extractTransfers.js +3 -1
- package/dist/esm/history/index.js +3 -3
- package/dist/esm/history/mapOperations.js +55 -0
- package/dist/esm/history/parseCreditAccountTransaction.js +1 -7
- package/dist/esm/history/toLegacyOperation.js +97 -89
- package/dist/types/history/index.d.ts +2 -2
- package/dist/types/history/inner-operations.d.ts +13 -13
- package/dist/types/history/mapOperations.d.ts +27 -0
- package/dist/types/history/parseCreditAccountTransaction.d.ts +1 -4
- package/dist/types/history/toLegacyOperation.d.ts +4 -19
- package/dist/types/history/types.d.ts +17 -17
- package/dist/types/plugins/adapters/types.d.ts +4 -9
- package/package.json +1 -1
- package/dist/cjs/history/enrichTokens.js +0 -80
- package/dist/esm/history/enrichTokens.js +0 -56
- package/dist/types/history/enrichTokens.d.ts +0 -5
|
@@ -75,7 +75,9 @@ function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
|
75
75
|
if ((0, import_viem.isAddressEqual)(from, pool) && (0, import_viem.isAddressEqual)(to, creditAccount) || (0, import_viem.isAddressEqual)(from, creditAccount) && (0, import_viem.isAddressEqual)(to, pool)) {
|
|
76
76
|
continue;
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
if ((0, import_viem.isAddressEqual)(from, creditAccount) || (0, import_viem.isAddressEqual)(to, creditAccount)) {
|
|
79
|
+
currentEntries.push({ token, amount: value, from, to });
|
|
80
|
+
}
|
|
79
81
|
if ((0, import_viem.isAddressEqual)(to, creditAccount) && !isInRange(log.logIndex, ranges)) {
|
|
80
82
|
directTransfers.push({ token, from, amount: value });
|
|
81
83
|
}
|
|
@@ -19,20 +19,21 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var history_exports = {};
|
|
21
21
|
__export(history_exports, {
|
|
22
|
-
parseCreditAccountTransaction: () => import_parseCreditAccountTransaction.parseCreditAccountTransaction
|
|
23
|
-
toLegacyOperations: () => import_toLegacyOperation.toLegacyOperations
|
|
22
|
+
parseCreditAccountTransaction: () => import_parseCreditAccountTransaction.parseCreditAccountTransaction
|
|
24
23
|
});
|
|
25
24
|
module.exports = __toCommonJS(history_exports);
|
|
26
25
|
__reExport(history_exports, require("./inner-operations.js"), module.exports);
|
|
26
|
+
__reExport(history_exports, require("./mapOperations.js"), module.exports);
|
|
27
27
|
var import_parseCreditAccountTransaction = require("./parseCreditAccountTransaction.js");
|
|
28
28
|
__reExport(history_exports, require("./populateContractsRegister.js"), module.exports);
|
|
29
|
-
|
|
29
|
+
__reExport(history_exports, require("./toLegacyOperation.js"), module.exports);
|
|
30
30
|
__reExport(history_exports, require("./types.js"), module.exports);
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
33
33
|
parseCreditAccountTransaction,
|
|
34
|
-
toLegacyOperations,
|
|
35
34
|
...require("./inner-operations.js"),
|
|
35
|
+
...require("./mapOperations.js"),
|
|
36
36
|
...require("./populateContractsRegister.js"),
|
|
37
|
+
...require("./toLegacyOperation.js"),
|
|
37
38
|
...require("./types.js")
|
|
38
39
|
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var mapOperations_exports = {};
|
|
20
|
+
__export(mapOperations_exports, {
|
|
21
|
+
mapOperations: () => mapOperations
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(mapOperations_exports);
|
|
24
|
+
function mapInnerOperation(op, visitor) {
|
|
25
|
+
switch (op.operation) {
|
|
26
|
+
case "Execute":
|
|
27
|
+
return visitor.Execute(op);
|
|
28
|
+
case "IncreaseBorrowedAmount":
|
|
29
|
+
return visitor.IncreaseBorrowedAmount(op);
|
|
30
|
+
case "DecreaseBorrowedAmount":
|
|
31
|
+
return visitor.DecreaseBorrowedAmount(op);
|
|
32
|
+
case "AddCollateral":
|
|
33
|
+
return visitor.AddCollateral(op);
|
|
34
|
+
case "WithdrawCollateral":
|
|
35
|
+
return visitor.WithdrawCollateral(op);
|
|
36
|
+
case "UpdateQuota":
|
|
37
|
+
return visitor.UpdateQuota(op);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function mapOuterOperation(op, visitor) {
|
|
41
|
+
switch (op.operation) {
|
|
42
|
+
case "DirectTokenTransfer":
|
|
43
|
+
return visitor.DirectTokenTransfer(op);
|
|
44
|
+
case "PartiallyLiquidateCreditAccount":
|
|
45
|
+
return visitor.PartiallyLiquidateCreditAccount(op);
|
|
46
|
+
case "MultiCall":
|
|
47
|
+
case "BotMulticall": {
|
|
48
|
+
const multicall = op.multicall.map(
|
|
49
|
+
(inner) => mapInnerOperation(inner, visitor)
|
|
50
|
+
);
|
|
51
|
+
return visitor.MultiCall(op, multicall);
|
|
52
|
+
}
|
|
53
|
+
case "OpenCreditAccount": {
|
|
54
|
+
const multicall = op.multicall.map(
|
|
55
|
+
(inner) => mapInnerOperation(inner, visitor)
|
|
56
|
+
);
|
|
57
|
+
return visitor.OpenCreditAccount(op, multicall);
|
|
58
|
+
}
|
|
59
|
+
case "CloseCreditAccount": {
|
|
60
|
+
const multicall = op.multicall.map(
|
|
61
|
+
(inner) => mapInnerOperation(inner, visitor)
|
|
62
|
+
);
|
|
63
|
+
return visitor.CloseCreditAccount(op, multicall);
|
|
64
|
+
}
|
|
65
|
+
case "LiquidateCreditAccount": {
|
|
66
|
+
const multicall = op.multicall.map(
|
|
67
|
+
(inner) => mapInnerOperation(inner, visitor)
|
|
68
|
+
);
|
|
69
|
+
return visitor.LiquidateCreditAccount(op, multicall);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function mapOperations(ops, visitor) {
|
|
74
|
+
return ops.map((op) => mapOuterOperation(op, visitor));
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
mapOperations
|
|
79
|
+
});
|
|
@@ -22,7 +22,6 @@ __export(parseCreditAccountTransaction_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(parseCreditAccountTransaction_exports);
|
|
24
24
|
var import_assembleOperations = require("./assembleOperations.js");
|
|
25
|
-
var import_enrichTokens = require("./enrichTokens.js");
|
|
26
25
|
var import_extractTransfers = require("./extractTransfers.js");
|
|
27
26
|
var import_findFacadeCalls = require("./findFacadeCalls.js");
|
|
28
27
|
function parseCreditAccountTransaction(input) {
|
|
@@ -70,12 +69,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
70
69
|
creditAccount,
|
|
71
70
|
...dt
|
|
72
71
|
}));
|
|
73
|
-
|
|
74
|
-
const resolve = (addr) => {
|
|
75
|
-
const meta = register.tokensMeta.mustGet(addr);
|
|
76
|
-
return { address: addr, symbol: meta.symbol, decimals: meta.decimals };
|
|
77
|
-
};
|
|
78
|
-
return (0, import_enrichTokens.enrichOperations)(rawOps, resolve);
|
|
72
|
+
return [...facadeOps, ...directOps];
|
|
79
73
|
}
|
|
80
74
|
// Annotate the CommonJS export names for ESM import in node:
|
|
81
75
|
0 && (module.exports = {
|
|
@@ -18,103 +18,112 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var toLegacyOperation_exports = {};
|
|
20
20
|
__export(toLegacyOperation_exports, {
|
|
21
|
+
legacyVisitor: () => legacyVisitor,
|
|
21
22
|
toLegacyOperations: () => toLegacyOperations
|
|
22
23
|
});
|
|
23
24
|
module.exports = __toCommonJS(toLegacyOperation_exports);
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
var import_mapOperations = require("./mapOperations.js");
|
|
26
|
+
const legacyVisitor = {
|
|
27
|
+
Execute(op) {
|
|
26
28
|
return { ...op.legacy };
|
|
29
|
+
},
|
|
30
|
+
IncreaseBorrowedAmount(op) {
|
|
31
|
+
return {
|
|
32
|
+
operation: op.operation,
|
|
33
|
+
amount: op.amount.toString()
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
DecreaseBorrowedAmount(op) {
|
|
37
|
+
return {
|
|
38
|
+
operation: op.operation,
|
|
39
|
+
amount: op.amount.toString()
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
AddCollateral(op) {
|
|
43
|
+
return {
|
|
44
|
+
operation: op.operation,
|
|
45
|
+
token: op.token,
|
|
46
|
+
amount: op.amount.toString()
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
WithdrawCollateral(op) {
|
|
50
|
+
return {
|
|
51
|
+
operation: op.operation,
|
|
52
|
+
token: op.token,
|
|
53
|
+
amount: op.amount.toString(),
|
|
54
|
+
to: op.to,
|
|
55
|
+
...op.phantomToken ? { phantomToken: op.phantomToken } : {}
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
UpdateQuota(op) {
|
|
59
|
+
return {
|
|
60
|
+
operation: op.operation,
|
|
61
|
+
token: op.token,
|
|
62
|
+
change: op.change.toString()
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
DirectTokenTransfer(op) {
|
|
66
|
+
return {
|
|
67
|
+
operation: op.operation,
|
|
68
|
+
txHash: op.txHash,
|
|
69
|
+
blockNum: op.blockNumber,
|
|
70
|
+
token: op.token,
|
|
71
|
+
amount: op.amount.toString(),
|
|
72
|
+
from: op.from,
|
|
73
|
+
to: op.creditAccount
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
MultiCall(op, multicall) {
|
|
77
|
+
return {
|
|
78
|
+
operation: op.operation,
|
|
79
|
+
txHash: op.txHash,
|
|
80
|
+
blockNum: op.blockNumber,
|
|
81
|
+
multicall
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
OpenCreditAccount(op, multicall) {
|
|
85
|
+
return {
|
|
86
|
+
operation: op.operation,
|
|
87
|
+
txHash: op.txHash,
|
|
88
|
+
blockNum: op.blockNumber,
|
|
89
|
+
multicall
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
CloseCreditAccount(op, multicall) {
|
|
93
|
+
return {
|
|
94
|
+
operation: op.operation,
|
|
95
|
+
txHash: op.txHash,
|
|
96
|
+
blockNum: op.blockNumber,
|
|
97
|
+
multicall
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
LiquidateCreditAccount(op, multicall) {
|
|
101
|
+
return {
|
|
102
|
+
operation: op.operation,
|
|
103
|
+
txHash: op.txHash,
|
|
104
|
+
blockNum: op.blockNumber,
|
|
105
|
+
to: op.to,
|
|
106
|
+
remainingFunds: op.remainingFunds.toString(),
|
|
107
|
+
multicall
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
PartiallyLiquidateCreditAccount(op) {
|
|
111
|
+
return {
|
|
112
|
+
operation: op.operation,
|
|
113
|
+
txHash: op.txHash,
|
|
114
|
+
blockNum: op.blockNumber,
|
|
115
|
+
token: op.token,
|
|
116
|
+
repaidAmount: op.repaidAmount.toString(),
|
|
117
|
+
minSeizedAmount: op.minSeizedAmount.toString(),
|
|
118
|
+
to: op.to
|
|
119
|
+
};
|
|
27
120
|
}
|
|
28
|
-
|
|
29
|
-
case "IncreaseBorrowedAmount":
|
|
30
|
-
return {
|
|
31
|
-
operation: op.operation,
|
|
32
|
-
amount: op.amount.toString()
|
|
33
|
-
};
|
|
34
|
-
case "DecreaseBorrowedAmount":
|
|
35
|
-
return {
|
|
36
|
-
operation: op.operation,
|
|
37
|
-
amount: op.amount.toString()
|
|
38
|
-
};
|
|
39
|
-
case "AddCollateral":
|
|
40
|
-
return {
|
|
41
|
-
operation: op.operation,
|
|
42
|
-
token: op.token.address,
|
|
43
|
-
amount: op.amount.toString()
|
|
44
|
-
};
|
|
45
|
-
case "WithdrawCollateral":
|
|
46
|
-
return {
|
|
47
|
-
operation: op.operation,
|
|
48
|
-
token: op.token.address,
|
|
49
|
-
amount: op.amount.toString(),
|
|
50
|
-
to: op.to,
|
|
51
|
-
...op.phantomToken ? { phantomToken: op.phantomToken.address } : {}
|
|
52
|
-
};
|
|
53
|
-
case "UpdateQuota":
|
|
54
|
-
return {
|
|
55
|
-
operation: op.operation,
|
|
56
|
-
token: op.token.address,
|
|
57
|
-
change: op.change.toString()
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
function convertFacadeOp(op) {
|
|
62
|
-
const base = {
|
|
63
|
-
operation: op.operation,
|
|
64
|
-
txHash: op.txHash,
|
|
65
|
-
blockNum: op.blockNumber
|
|
66
|
-
};
|
|
67
|
-
switch (op.operation) {
|
|
68
|
-
case "MultiCall":
|
|
69
|
-
case "BotMulticall":
|
|
70
|
-
return {
|
|
71
|
-
...base,
|
|
72
|
-
multicall: op.multicall.map(convertMulticallOp)
|
|
73
|
-
};
|
|
74
|
-
case "OpenCreditAccount":
|
|
75
|
-
return {
|
|
76
|
-
...base,
|
|
77
|
-
multicall: op.multicall.map(convertMulticallOp)
|
|
78
|
-
};
|
|
79
|
-
case "CloseCreditAccount":
|
|
80
|
-
return {
|
|
81
|
-
...base,
|
|
82
|
-
multicall: op.multicall.map(convertMulticallOp)
|
|
83
|
-
};
|
|
84
|
-
case "LiquidateCreditAccount":
|
|
85
|
-
return {
|
|
86
|
-
...base,
|
|
87
|
-
to: op.to,
|
|
88
|
-
remainingFunds: op.remainingFunds.toString(),
|
|
89
|
-
multicall: op.multicall.map(convertMulticallOp)
|
|
90
|
-
};
|
|
91
|
-
case "PartiallyLiquidateCreditAccount":
|
|
92
|
-
return {
|
|
93
|
-
...base,
|
|
94
|
-
token: op.token.address,
|
|
95
|
-
repaidAmount: op.repaidAmount.toString(),
|
|
96
|
-
minSeizedAmount: op.minSeizedAmount.toString(),
|
|
97
|
-
to: op.to
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
}
|
|
121
|
+
};
|
|
101
122
|
function toLegacyOperations(ops) {
|
|
102
|
-
return
|
|
103
|
-
if (op.operation === "DirectTokenTransfer") {
|
|
104
|
-
return {
|
|
105
|
-
operation: op.operation,
|
|
106
|
-
txHash: op.txHash,
|
|
107
|
-
blockNum: op.blockNumber,
|
|
108
|
-
token: op.token.address,
|
|
109
|
-
amount: op.amount.toString(),
|
|
110
|
-
from: op.from,
|
|
111
|
-
to: op.creditAccount
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
return convertFacadeOp(op);
|
|
115
|
-
});
|
|
123
|
+
return (0, import_mapOperations.mapOperations)(ops, legacyVisitor);
|
|
116
124
|
}
|
|
117
125
|
// Annotate the CommonJS export names for ESM import in node:
|
|
118
126
|
0 && (module.exports = {
|
|
127
|
+
legacyVisitor,
|
|
119
128
|
toLegacyOperations
|
|
120
129
|
});
|
|
@@ -56,7 +56,9 @@ function extractTransfers(logs, creditAccount, pool, creditFacade) {
|
|
|
56
56
|
if (isAddressEqual(from, pool) && isAddressEqual(to, creditAccount) || isAddressEqual(from, creditAccount) && isAddressEqual(to, pool)) {
|
|
57
57
|
continue;
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
if (isAddressEqual(from, creditAccount) || isAddressEqual(to, creditAccount)) {
|
|
60
|
+
currentEntries.push({ token, amount: value, from, to });
|
|
61
|
+
}
|
|
60
62
|
if (isAddressEqual(to, creditAccount) && !isInRange(log.logIndex, ranges)) {
|
|
61
63
|
directTransfers.push({ token, from, amount: value });
|
|
62
64
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
export * from "./inner-operations.js";
|
|
2
|
+
export * from "./mapOperations.js";
|
|
2
3
|
import { parseCreditAccountTransaction } from "./parseCreditAccountTransaction.js";
|
|
3
4
|
export * from "./populateContractsRegister.js";
|
|
4
|
-
|
|
5
|
+
export * from "./toLegacyOperation.js";
|
|
5
6
|
export * from "./types.js";
|
|
6
7
|
export {
|
|
7
|
-
parseCreditAccountTransaction
|
|
8
|
-
toLegacyOperations
|
|
8
|
+
parseCreditAccountTransaction
|
|
9
9
|
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
function mapInnerOperation(op, visitor) {
|
|
2
|
+
switch (op.operation) {
|
|
3
|
+
case "Execute":
|
|
4
|
+
return visitor.Execute(op);
|
|
5
|
+
case "IncreaseBorrowedAmount":
|
|
6
|
+
return visitor.IncreaseBorrowedAmount(op);
|
|
7
|
+
case "DecreaseBorrowedAmount":
|
|
8
|
+
return visitor.DecreaseBorrowedAmount(op);
|
|
9
|
+
case "AddCollateral":
|
|
10
|
+
return visitor.AddCollateral(op);
|
|
11
|
+
case "WithdrawCollateral":
|
|
12
|
+
return visitor.WithdrawCollateral(op);
|
|
13
|
+
case "UpdateQuota":
|
|
14
|
+
return visitor.UpdateQuota(op);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function mapOuterOperation(op, visitor) {
|
|
18
|
+
switch (op.operation) {
|
|
19
|
+
case "DirectTokenTransfer":
|
|
20
|
+
return visitor.DirectTokenTransfer(op);
|
|
21
|
+
case "PartiallyLiquidateCreditAccount":
|
|
22
|
+
return visitor.PartiallyLiquidateCreditAccount(op);
|
|
23
|
+
case "MultiCall":
|
|
24
|
+
case "BotMulticall": {
|
|
25
|
+
const multicall = op.multicall.map(
|
|
26
|
+
(inner) => mapInnerOperation(inner, visitor)
|
|
27
|
+
);
|
|
28
|
+
return visitor.MultiCall(op, multicall);
|
|
29
|
+
}
|
|
30
|
+
case "OpenCreditAccount": {
|
|
31
|
+
const multicall = op.multicall.map(
|
|
32
|
+
(inner) => mapInnerOperation(inner, visitor)
|
|
33
|
+
);
|
|
34
|
+
return visitor.OpenCreditAccount(op, multicall);
|
|
35
|
+
}
|
|
36
|
+
case "CloseCreditAccount": {
|
|
37
|
+
const multicall = op.multicall.map(
|
|
38
|
+
(inner) => mapInnerOperation(inner, visitor)
|
|
39
|
+
);
|
|
40
|
+
return visitor.CloseCreditAccount(op, multicall);
|
|
41
|
+
}
|
|
42
|
+
case "LiquidateCreditAccount": {
|
|
43
|
+
const multicall = op.multicall.map(
|
|
44
|
+
(inner) => mapInnerOperation(inner, visitor)
|
|
45
|
+
);
|
|
46
|
+
return visitor.LiquidateCreditAccount(op, multicall);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function mapOperations(ops, visitor) {
|
|
51
|
+
return ops.map((op) => mapOuterOperation(op, visitor));
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
mapOperations
|
|
55
|
+
};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { assembleOperations } from "./assembleOperations.js";
|
|
2
|
-
import { enrichOperations } from "./enrichTokens.js";
|
|
3
2
|
import { extractTransfers } from "./extractTransfers.js";
|
|
4
3
|
import { findFacadeCalls } from "./findFacadeCalls.js";
|
|
5
4
|
function parseCreditAccountTransaction(input) {
|
|
@@ -47,12 +46,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
47
46
|
creditAccount,
|
|
48
47
|
...dt
|
|
49
48
|
}));
|
|
50
|
-
|
|
51
|
-
const resolve = (addr) => {
|
|
52
|
-
const meta = register.tokensMeta.mustGet(addr);
|
|
53
|
-
return { address: addr, symbol: meta.symbol, decimals: meta.decimals };
|
|
54
|
-
};
|
|
55
|
-
return enrichOperations(rawOps, resolve);
|
|
49
|
+
return [...facadeOps, ...directOps];
|
|
56
50
|
}
|
|
57
51
|
export {
|
|
58
52
|
parseCreditAccountTransaction
|
|
@@ -1,96 +1,104 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { mapOperations } from "./mapOperations.js";
|
|
2
|
+
const legacyVisitor = {
|
|
3
|
+
Execute(op) {
|
|
3
4
|
return { ...op.legacy };
|
|
5
|
+
},
|
|
6
|
+
IncreaseBorrowedAmount(op) {
|
|
7
|
+
return {
|
|
8
|
+
operation: op.operation,
|
|
9
|
+
amount: op.amount.toString()
|
|
10
|
+
};
|
|
11
|
+
},
|
|
12
|
+
DecreaseBorrowedAmount(op) {
|
|
13
|
+
return {
|
|
14
|
+
operation: op.operation,
|
|
15
|
+
amount: op.amount.toString()
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
AddCollateral(op) {
|
|
19
|
+
return {
|
|
20
|
+
operation: op.operation,
|
|
21
|
+
token: op.token,
|
|
22
|
+
amount: op.amount.toString()
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
WithdrawCollateral(op) {
|
|
26
|
+
return {
|
|
27
|
+
operation: op.operation,
|
|
28
|
+
token: op.token,
|
|
29
|
+
amount: op.amount.toString(),
|
|
30
|
+
to: op.to,
|
|
31
|
+
...op.phantomToken ? { phantomToken: op.phantomToken } : {}
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
UpdateQuota(op) {
|
|
35
|
+
return {
|
|
36
|
+
operation: op.operation,
|
|
37
|
+
token: op.token,
|
|
38
|
+
change: op.change.toString()
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
DirectTokenTransfer(op) {
|
|
42
|
+
return {
|
|
43
|
+
operation: op.operation,
|
|
44
|
+
txHash: op.txHash,
|
|
45
|
+
blockNum: op.blockNumber,
|
|
46
|
+
token: op.token,
|
|
47
|
+
amount: op.amount.toString(),
|
|
48
|
+
from: op.from,
|
|
49
|
+
to: op.creditAccount
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
MultiCall(op, multicall) {
|
|
53
|
+
return {
|
|
54
|
+
operation: op.operation,
|
|
55
|
+
txHash: op.txHash,
|
|
56
|
+
blockNum: op.blockNumber,
|
|
57
|
+
multicall
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
OpenCreditAccount(op, multicall) {
|
|
61
|
+
return {
|
|
62
|
+
operation: op.operation,
|
|
63
|
+
txHash: op.txHash,
|
|
64
|
+
blockNum: op.blockNumber,
|
|
65
|
+
multicall
|
|
66
|
+
};
|
|
67
|
+
},
|
|
68
|
+
CloseCreditAccount(op, multicall) {
|
|
69
|
+
return {
|
|
70
|
+
operation: op.operation,
|
|
71
|
+
txHash: op.txHash,
|
|
72
|
+
blockNum: op.blockNumber,
|
|
73
|
+
multicall
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
LiquidateCreditAccount(op, multicall) {
|
|
77
|
+
return {
|
|
78
|
+
operation: op.operation,
|
|
79
|
+
txHash: op.txHash,
|
|
80
|
+
blockNum: op.blockNumber,
|
|
81
|
+
to: op.to,
|
|
82
|
+
remainingFunds: op.remainingFunds.toString(),
|
|
83
|
+
multicall
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
PartiallyLiquidateCreditAccount(op) {
|
|
87
|
+
return {
|
|
88
|
+
operation: op.operation,
|
|
89
|
+
txHash: op.txHash,
|
|
90
|
+
blockNum: op.blockNumber,
|
|
91
|
+
token: op.token,
|
|
92
|
+
repaidAmount: op.repaidAmount.toString(),
|
|
93
|
+
minSeizedAmount: op.minSeizedAmount.toString(),
|
|
94
|
+
to: op.to
|
|
95
|
+
};
|
|
4
96
|
}
|
|
5
|
-
|
|
6
|
-
case "IncreaseBorrowedAmount":
|
|
7
|
-
return {
|
|
8
|
-
operation: op.operation,
|
|
9
|
-
amount: op.amount.toString()
|
|
10
|
-
};
|
|
11
|
-
case "DecreaseBorrowedAmount":
|
|
12
|
-
return {
|
|
13
|
-
operation: op.operation,
|
|
14
|
-
amount: op.amount.toString()
|
|
15
|
-
};
|
|
16
|
-
case "AddCollateral":
|
|
17
|
-
return {
|
|
18
|
-
operation: op.operation,
|
|
19
|
-
token: op.token.address,
|
|
20
|
-
amount: op.amount.toString()
|
|
21
|
-
};
|
|
22
|
-
case "WithdrawCollateral":
|
|
23
|
-
return {
|
|
24
|
-
operation: op.operation,
|
|
25
|
-
token: op.token.address,
|
|
26
|
-
amount: op.amount.toString(),
|
|
27
|
-
to: op.to,
|
|
28
|
-
...op.phantomToken ? { phantomToken: op.phantomToken.address } : {}
|
|
29
|
-
};
|
|
30
|
-
case "UpdateQuota":
|
|
31
|
-
return {
|
|
32
|
-
operation: op.operation,
|
|
33
|
-
token: op.token.address,
|
|
34
|
-
change: op.change.toString()
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function convertFacadeOp(op) {
|
|
39
|
-
const base = {
|
|
40
|
-
operation: op.operation,
|
|
41
|
-
txHash: op.txHash,
|
|
42
|
-
blockNum: op.blockNumber
|
|
43
|
-
};
|
|
44
|
-
switch (op.operation) {
|
|
45
|
-
case "MultiCall":
|
|
46
|
-
case "BotMulticall":
|
|
47
|
-
return {
|
|
48
|
-
...base,
|
|
49
|
-
multicall: op.multicall.map(convertMulticallOp)
|
|
50
|
-
};
|
|
51
|
-
case "OpenCreditAccount":
|
|
52
|
-
return {
|
|
53
|
-
...base,
|
|
54
|
-
multicall: op.multicall.map(convertMulticallOp)
|
|
55
|
-
};
|
|
56
|
-
case "CloseCreditAccount":
|
|
57
|
-
return {
|
|
58
|
-
...base,
|
|
59
|
-
multicall: op.multicall.map(convertMulticallOp)
|
|
60
|
-
};
|
|
61
|
-
case "LiquidateCreditAccount":
|
|
62
|
-
return {
|
|
63
|
-
...base,
|
|
64
|
-
to: op.to,
|
|
65
|
-
remainingFunds: op.remainingFunds.toString(),
|
|
66
|
-
multicall: op.multicall.map(convertMulticallOp)
|
|
67
|
-
};
|
|
68
|
-
case "PartiallyLiquidateCreditAccount":
|
|
69
|
-
return {
|
|
70
|
-
...base,
|
|
71
|
-
token: op.token.address,
|
|
72
|
-
repaidAmount: op.repaidAmount.toString(),
|
|
73
|
-
minSeizedAmount: op.minSeizedAmount.toString(),
|
|
74
|
-
to: op.to
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
}
|
|
97
|
+
};
|
|
78
98
|
function toLegacyOperations(ops) {
|
|
79
|
-
return ops
|
|
80
|
-
if (op.operation === "DirectTokenTransfer") {
|
|
81
|
-
return {
|
|
82
|
-
operation: op.operation,
|
|
83
|
-
txHash: op.txHash,
|
|
84
|
-
blockNum: op.blockNumber,
|
|
85
|
-
token: op.token.address,
|
|
86
|
-
amount: op.amount.toString(),
|
|
87
|
-
from: op.from,
|
|
88
|
-
to: op.creditAccount
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
return convertFacadeOp(op);
|
|
92
|
-
});
|
|
99
|
+
return mapOperations(ops, legacyVisitor);
|
|
93
100
|
}
|
|
94
101
|
export {
|
|
102
|
+
legacyVisitor,
|
|
95
103
|
toLegacyOperations
|
|
96
104
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export type { TokenInfo } from "../plugins/adapters/types.js";
|
|
2
1
|
export * from "./inner-operations.js";
|
|
2
|
+
export * from "./mapOperations.js";
|
|
3
3
|
export { parseCreditAccountTransaction } from "./parseCreditAccountTransaction.js";
|
|
4
4
|
export * from "./populateContractsRegister.js";
|
|
5
|
-
export
|
|
5
|
+
export * from "./toLegacyOperation.js";
|
|
6
6
|
export * from "./types.js";
|
|
@@ -4,54 +4,54 @@ import type { AdapterOperation } from "../plugins/adapters/index.js";
|
|
|
4
4
|
* Increase debt (borrow more).
|
|
5
5
|
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L149-L154
|
|
6
6
|
*/
|
|
7
|
-
export interface IncreaseDebtOp
|
|
7
|
+
export interface IncreaseDebtOp {
|
|
8
8
|
operation: "IncreaseBorrowedAmount";
|
|
9
|
-
token:
|
|
9
|
+
token: Address;
|
|
10
10
|
amount: bigint;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
13
|
* Decrease debt (repay).
|
|
14
14
|
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L155-L161
|
|
15
15
|
*/
|
|
16
|
-
export interface DecreaseDebtOp
|
|
16
|
+
export interface DecreaseDebtOp {
|
|
17
17
|
operation: "DecreaseBorrowedAmount";
|
|
18
|
-
token:
|
|
18
|
+
token: Address;
|
|
19
19
|
amount: bigint;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Add collateral to credit account.
|
|
23
23
|
*/
|
|
24
|
-
export interface AddCollateralOp
|
|
24
|
+
export interface AddCollateralOp {
|
|
25
25
|
operation: "AddCollateral";
|
|
26
|
-
token:
|
|
26
|
+
token: Address;
|
|
27
27
|
amount: bigint;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Withdraw collateral from credit account.
|
|
31
31
|
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L162-L171
|
|
32
32
|
*/
|
|
33
|
-
export interface WithdrawCollateralOp
|
|
33
|
+
export interface WithdrawCollateralOp {
|
|
34
34
|
operation: "WithdrawCollateral";
|
|
35
|
-
token:
|
|
35
|
+
token: Address;
|
|
36
36
|
amount: bigint;
|
|
37
37
|
to: Address;
|
|
38
|
-
phantomToken?:
|
|
38
|
+
phantomToken?: Address;
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Update token quota on credit account.
|
|
42
42
|
* @see https://github.com/Gearbox-protocol/charts_server/blob/master/core/operation_type_v3.go#L172-L178
|
|
43
43
|
*/
|
|
44
|
-
export interface UpdateQuotaOp
|
|
44
|
+
export interface UpdateQuotaOp {
|
|
45
45
|
operation: "UpdateQuota";
|
|
46
|
-
token:
|
|
46
|
+
token: Address;
|
|
47
47
|
change: bigint;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
50
50
|
* Union of facade inner-call operation types (non-adapter credit account operations).
|
|
51
51
|
* Discriminated on the `operation` field.
|
|
52
52
|
*/
|
|
53
|
-
export type InnerFacadeOperation
|
|
53
|
+
export type InnerFacadeOperation = IncreaseDebtOp | DecreaseDebtOp | AddCollateralOp | WithdrawCollateralOp | UpdateQuotaOp;
|
|
54
54
|
/**
|
|
55
55
|
* All operations that can happen within a CreditFacade's multicall and that we're interested in.
|
|
56
56
|
*/
|
|
57
|
-
export type InnerOperation
|
|
57
|
+
export type InnerOperation = AdapterOperation | InnerFacadeOperation;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { AdapterOperation } from "../plugins/adapters/index.js";
|
|
2
|
+
import type { AddCollateralOp, DecreaseDebtOp, IncreaseDebtOp, UpdateQuotaOp, WithdrawCollateralOp } from "./inner-operations.js";
|
|
3
|
+
import type { CloseCreditAccountOperation, CreditAccountOperation, DirectTokenTransferOperation, LiquidateCreditAccountOperation, MulticallOperation, OpenCreditAccountOperation, PartialLiquidationOperation } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Visitor that maps each operation node in a {@link CreditAccountOperation}
|
|
6
|
+
* tree to a new representation.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
export interface OperationVisitor<TInner, TOuter> {
|
|
10
|
+
Execute(op: AdapterOperation): TInner;
|
|
11
|
+
IncreaseBorrowedAmount(op: IncreaseDebtOp): TInner;
|
|
12
|
+
DecreaseBorrowedAmount(op: DecreaseDebtOp): TInner;
|
|
13
|
+
AddCollateral(op: AddCollateralOp): TInner;
|
|
14
|
+
WithdrawCollateral(op: WithdrawCollateralOp): TInner;
|
|
15
|
+
UpdateQuota(op: UpdateQuotaOp): TInner;
|
|
16
|
+
DirectTokenTransfer(op: DirectTokenTransferOperation): TOuter;
|
|
17
|
+
MultiCall(op: MulticallOperation, multicall: TInner[]): TOuter;
|
|
18
|
+
OpenCreditAccount(op: OpenCreditAccountOperation, multicall: TInner[]): TOuter;
|
|
19
|
+
CloseCreditAccount(op: CloseCreditAccountOperation, multicall: TInner[]): TOuter;
|
|
20
|
+
LiquidateCreditAccount(op: LiquidateCreditAccountOperation, multicall: TInner[]): TOuter;
|
|
21
|
+
PartiallyLiquidateCreditAccount(op: PartialLiquidationOperation): TOuter;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Walks a list of {@link CreditAccountOperation}s, mapping each node via the
|
|
25
|
+
* given visitor
|
|
26
|
+
*/
|
|
27
|
+
export declare function mapOperations<TInner, TOuter>(ops: CreditAccountOperation[], visitor: OperationVisitor<TInner, TOuter>): TOuter[];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Address, TransactionReceipt } from "viem";
|
|
2
|
-
import type { TokenInfo } from "../plugins/adapters/types.js";
|
|
3
2
|
import type { ChainContractsRegister } from "../sdk/index.js";
|
|
4
3
|
import type { CreditAccountOperation } from "./types.js";
|
|
5
4
|
export interface ParseTransactionInput {
|
|
@@ -23,7 +22,5 @@ export interface ParseTransactionInput {
|
|
|
23
22
|
}
|
|
24
23
|
/**
|
|
25
24
|
* Parses a single transaction into classified credit account operations.
|
|
26
|
-
* Token address fields are enriched with metadata (symbol, decimals) from
|
|
27
|
-
* `register.tokensMeta`.
|
|
28
25
|
*/
|
|
29
|
-
export declare function parseCreditAccountTransaction(input: ParseTransactionInput): CreditAccountOperation
|
|
26
|
+
export declare function parseCreditAccountTransaction(input: ParseTransactionInput): CreditAccountOperation[];
|
|
@@ -1,35 +1,20 @@
|
|
|
1
1
|
import type { Hex } from "viem";
|
|
2
|
-
import type
|
|
2
|
+
import { type OperationVisitor } from "./mapOperations.js";
|
|
3
3
|
import type { CreditAccountOperation } from "./types.js";
|
|
4
|
-
/**
|
|
5
|
-
* JSON-serializable representation of a top-level legacy API operation.
|
|
6
|
-
* Mirrors the shape returned by charts-server's `/operations` endpoint,
|
|
7
|
-
* but omits fields the new parser cannot produce (sessionId, timestamp,
|
|
8
|
-
* protocol on inner ops, initialFunds/userFunds/leverage).
|
|
9
|
-
*/
|
|
10
4
|
export interface LegacyApiOperation {
|
|
11
5
|
operation: string;
|
|
12
6
|
txHash: Hex;
|
|
13
7
|
blockNum: number;
|
|
14
8
|
[key: string]: unknown;
|
|
15
9
|
}
|
|
16
|
-
/**
|
|
17
|
-
* JSON-serializable representation of an inner multicall operation
|
|
18
|
-
* from the legacy API.
|
|
19
|
-
*/
|
|
20
10
|
export interface LegacyMulticallOp {
|
|
21
11
|
operation: string;
|
|
22
12
|
[key: string]: unknown;
|
|
23
13
|
}
|
|
14
|
+
export declare const legacyVisitor: OperationVisitor<LegacyMulticallOp, LegacyApiOperation>;
|
|
24
15
|
/**
|
|
25
16
|
* Converts new parser output to the legacy API format for comparison.
|
|
26
17
|
*
|
|
27
|
-
*
|
|
28
|
-
* (not `blockNumber`), matching the charts-server JSON shape.
|
|
29
|
-
*
|
|
30
|
-
* Fields that only exist in the old API and cannot be derived from the
|
|
31
|
-
* new parser output are omitted: `sessionId`, `timestamp`, `protocol`
|
|
32
|
-
* on all operations, and `initialFunds`/`userFunds`/`leverage` on
|
|
33
|
-
* OpenCreditAccount.
|
|
18
|
+
* Missing `initialFunds`/`userFunds`/`leverage` on OpenCreditAccount.
|
|
34
19
|
*/
|
|
35
|
-
export declare function toLegacyOperations(ops: CreditAccountOperation
|
|
20
|
+
export declare function toLegacyOperations(ops: CreditAccountOperation[]): LegacyApiOperation[];
|
|
@@ -4,8 +4,8 @@ import type { InnerOperation } from "./inner-operations.js";
|
|
|
4
4
|
* An ERC-20 Transfer to the credit account that was not part of any
|
|
5
5
|
* facade operation (multicall, liquidation, etc.).
|
|
6
6
|
*/
|
|
7
|
-
export interface DirectTransferInfo
|
|
8
|
-
token:
|
|
7
|
+
export interface DirectTransferInfo {
|
|
8
|
+
token: Address;
|
|
9
9
|
from: Address;
|
|
10
10
|
amount: bigint;
|
|
11
11
|
}
|
|
@@ -13,42 +13,42 @@ export interface OperationMetadata {
|
|
|
13
13
|
txHash: Hex;
|
|
14
14
|
blockNumber: number;
|
|
15
15
|
}
|
|
16
|
-
export interface MulticallOperation
|
|
16
|
+
export interface MulticallOperation extends OperationMetadata {
|
|
17
17
|
operation: "MultiCall" | "BotMulticall";
|
|
18
18
|
creditAccount: Address;
|
|
19
|
-
multicall: InnerOperation
|
|
19
|
+
multicall: InnerOperation[];
|
|
20
20
|
}
|
|
21
|
-
export interface OpenCreditAccountOperation
|
|
21
|
+
export interface OpenCreditAccountOperation extends OperationMetadata {
|
|
22
22
|
operation: "OpenCreditAccount";
|
|
23
23
|
creditAccount: Address;
|
|
24
24
|
onBehalfOf: Address;
|
|
25
25
|
referralCode: bigint;
|
|
26
|
-
multicall: InnerOperation
|
|
26
|
+
multicall: InnerOperation[];
|
|
27
27
|
}
|
|
28
|
-
export interface CloseCreditAccountOperation
|
|
28
|
+
export interface CloseCreditAccountOperation extends OperationMetadata {
|
|
29
29
|
operation: "CloseCreditAccount";
|
|
30
30
|
creditAccount: Address;
|
|
31
|
-
multicall: InnerOperation
|
|
31
|
+
multicall: InnerOperation[];
|
|
32
32
|
}
|
|
33
|
-
export interface LiquidateCreditAccountOperation
|
|
33
|
+
export interface LiquidateCreditAccountOperation extends OperationMetadata {
|
|
34
34
|
operation: "LiquidateCreditAccount";
|
|
35
35
|
creditAccount: Address;
|
|
36
36
|
to: Address;
|
|
37
|
-
token:
|
|
37
|
+
token: Address;
|
|
38
38
|
remainingFunds: bigint;
|
|
39
|
-
multicall: InnerOperation
|
|
39
|
+
multicall: InnerOperation[];
|
|
40
40
|
}
|
|
41
|
-
export interface PartialLiquidationOperation
|
|
41
|
+
export interface PartialLiquidationOperation extends OperationMetadata {
|
|
42
42
|
operation: "PartiallyLiquidateCreditAccount";
|
|
43
43
|
creditAccount: Address;
|
|
44
|
-
token:
|
|
44
|
+
token: Address;
|
|
45
45
|
repaidAmount: bigint;
|
|
46
46
|
minSeizedAmount: bigint;
|
|
47
47
|
to: Address;
|
|
48
48
|
}
|
|
49
|
-
export interface DirectTokenTransferOperation
|
|
49
|
+
export interface DirectTokenTransferOperation extends OperationMetadata {
|
|
50
50
|
operation: "DirectTokenTransfer";
|
|
51
|
-
token:
|
|
51
|
+
token: Address;
|
|
52
52
|
from: Address;
|
|
53
53
|
creditAccount: Address;
|
|
54
54
|
amount: bigint;
|
|
@@ -57,9 +57,9 @@ export interface DirectTokenTransferOperation<TToken = Address> extends Operatio
|
|
|
57
57
|
* Discriminated union of all facade-level operation types.
|
|
58
58
|
* One per facade entry-point call within a transaction.
|
|
59
59
|
*/
|
|
60
|
-
export type OuterFacadeOperation
|
|
60
|
+
export type OuterFacadeOperation = MulticallOperation | OpenCreditAccountOperation | CloseCreditAccountOperation | LiquidateCreditAccountOperation | PartialLiquidationOperation;
|
|
61
61
|
/**
|
|
62
62
|
* Discriminated union of all credit account operation types
|
|
63
63
|
* (facade operations + direct token transfers).
|
|
64
64
|
*/
|
|
65
|
-
export type CreditAccountOperation
|
|
65
|
+
export type CreditAccountOperation = OuterFacadeOperation | DirectTokenTransferOperation;
|
|
@@ -49,16 +49,11 @@ export declare enum AdapterType {
|
|
|
49
49
|
VELODROME_V2_ROUTER = "VELODROME_V2_ROUTER",
|
|
50
50
|
YEARN_V2 = "YEARN_V2"
|
|
51
51
|
}
|
|
52
|
-
export interface TokenInfo {
|
|
53
|
-
address: Address;
|
|
54
|
-
symbol: string;
|
|
55
|
-
decimals: number;
|
|
56
|
-
}
|
|
57
52
|
/**
|
|
58
53
|
* A single ERC-20 Transfer event captured between Execute boundaries.
|
|
59
54
|
*/
|
|
60
|
-
export interface TokenTransfer
|
|
61
|
-
token:
|
|
55
|
+
export interface TokenTransfer {
|
|
56
|
+
token: Address;
|
|
62
57
|
amount: bigint;
|
|
63
58
|
from: Address;
|
|
64
59
|
to: Address;
|
|
@@ -66,7 +61,7 @@ export interface TokenTransfer<TToken = Address> {
|
|
|
66
61
|
/**
|
|
67
62
|
* Parsed adapter operation to display in credit account transactions history
|
|
68
63
|
*/
|
|
69
|
-
export interface AdapterOperation
|
|
64
|
+
export interface AdapterOperation {
|
|
70
65
|
operation: "Execute";
|
|
71
66
|
/**
|
|
72
67
|
* Address of Gearbox Adapter contract
|
|
@@ -108,6 +103,6 @@ export interface AdapterOperation<TToken = Address> {
|
|
|
108
103
|
/**
|
|
109
104
|
* ERC20 transfer to and from credit account made during adapter call
|
|
110
105
|
*/
|
|
111
|
-
transfers: TokenTransfer
|
|
106
|
+
transfers: TokenTransfer[];
|
|
112
107
|
legacy: LegacyAdapterOperation;
|
|
113
108
|
}
|
package/package.json
CHANGED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var enrichTokens_exports = {};
|
|
20
|
-
__export(enrichTokens_exports, {
|
|
21
|
-
enrichOperations: () => enrichOperations
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(enrichTokens_exports);
|
|
24
|
-
function enrichOperations(ops, resolve) {
|
|
25
|
-
return ops.map((op) => enrichOperation(op, resolve));
|
|
26
|
-
}
|
|
27
|
-
function enrichOperation(op, resolve) {
|
|
28
|
-
switch (op.operation) {
|
|
29
|
-
case "DirectTokenTransfer":
|
|
30
|
-
return { ...op, token: resolve(op.token) };
|
|
31
|
-
case "PartiallyLiquidateCreditAccount":
|
|
32
|
-
return { ...op, token: resolve(op.token) };
|
|
33
|
-
case "LiquidateCreditAccount":
|
|
34
|
-
return {
|
|
35
|
-
...op,
|
|
36
|
-
token: resolve(op.token),
|
|
37
|
-
multicall: enrichMulticall(op.multicall, resolve)
|
|
38
|
-
};
|
|
39
|
-
case "OpenCreditAccount":
|
|
40
|
-
case "CloseCreditAccount":
|
|
41
|
-
case "MultiCall":
|
|
42
|
-
case "BotMulticall":
|
|
43
|
-
return { ...op, multicall: enrichMulticall(op.multicall, resolve) };
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function enrichMulticall(ops, resolve) {
|
|
47
|
-
return ops.map((op) => enrichInnerOp(op, resolve));
|
|
48
|
-
}
|
|
49
|
-
function enrichInnerOp(op, resolve) {
|
|
50
|
-
switch (op.operation) {
|
|
51
|
-
case "Execute":
|
|
52
|
-
return {
|
|
53
|
-
...op,
|
|
54
|
-
transfers: op.transfers.map((t) => ({ ...t, token: resolve(t.token) }))
|
|
55
|
-
};
|
|
56
|
-
case "IncreaseBorrowedAmount":
|
|
57
|
-
case "DecreaseBorrowedAmount":
|
|
58
|
-
return { ...op, token: resolve(op.token) };
|
|
59
|
-
case "AddCollateral":
|
|
60
|
-
return { ...op, token: resolve(op.token) };
|
|
61
|
-
case "WithdrawCollateral": {
|
|
62
|
-
const enriched = {
|
|
63
|
-
operation: op.operation,
|
|
64
|
-
token: resolve(op.token),
|
|
65
|
-
amount: op.amount,
|
|
66
|
-
to: op.to
|
|
67
|
-
};
|
|
68
|
-
if (op.phantomToken) {
|
|
69
|
-
enriched.phantomToken = resolve(op.phantomToken);
|
|
70
|
-
}
|
|
71
|
-
return enriched;
|
|
72
|
-
}
|
|
73
|
-
case "UpdateQuota":
|
|
74
|
-
return { ...op, token: resolve(op.token) };
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
-
0 && (module.exports = {
|
|
79
|
-
enrichOperations
|
|
80
|
-
});
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
function enrichOperations(ops, resolve) {
|
|
2
|
-
return ops.map((op) => enrichOperation(op, resolve));
|
|
3
|
-
}
|
|
4
|
-
function enrichOperation(op, resolve) {
|
|
5
|
-
switch (op.operation) {
|
|
6
|
-
case "DirectTokenTransfer":
|
|
7
|
-
return { ...op, token: resolve(op.token) };
|
|
8
|
-
case "PartiallyLiquidateCreditAccount":
|
|
9
|
-
return { ...op, token: resolve(op.token) };
|
|
10
|
-
case "LiquidateCreditAccount":
|
|
11
|
-
return {
|
|
12
|
-
...op,
|
|
13
|
-
token: resolve(op.token),
|
|
14
|
-
multicall: enrichMulticall(op.multicall, resolve)
|
|
15
|
-
};
|
|
16
|
-
case "OpenCreditAccount":
|
|
17
|
-
case "CloseCreditAccount":
|
|
18
|
-
case "MultiCall":
|
|
19
|
-
case "BotMulticall":
|
|
20
|
-
return { ...op, multicall: enrichMulticall(op.multicall, resolve) };
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function enrichMulticall(ops, resolve) {
|
|
24
|
-
return ops.map((op) => enrichInnerOp(op, resolve));
|
|
25
|
-
}
|
|
26
|
-
function enrichInnerOp(op, resolve) {
|
|
27
|
-
switch (op.operation) {
|
|
28
|
-
case "Execute":
|
|
29
|
-
return {
|
|
30
|
-
...op,
|
|
31
|
-
transfers: op.transfers.map((t) => ({ ...t, token: resolve(t.token) }))
|
|
32
|
-
};
|
|
33
|
-
case "IncreaseBorrowedAmount":
|
|
34
|
-
case "DecreaseBorrowedAmount":
|
|
35
|
-
return { ...op, token: resolve(op.token) };
|
|
36
|
-
case "AddCollateral":
|
|
37
|
-
return { ...op, token: resolve(op.token) };
|
|
38
|
-
case "WithdrawCollateral": {
|
|
39
|
-
const enriched = {
|
|
40
|
-
operation: op.operation,
|
|
41
|
-
token: resolve(op.token),
|
|
42
|
-
amount: op.amount,
|
|
43
|
-
to: op.to
|
|
44
|
-
};
|
|
45
|
-
if (op.phantomToken) {
|
|
46
|
-
enriched.phantomToken = resolve(op.phantomToken);
|
|
47
|
-
}
|
|
48
|
-
return enriched;
|
|
49
|
-
}
|
|
50
|
-
case "UpdateQuota":
|
|
51
|
-
return { ...op, token: resolve(op.token) };
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
export {
|
|
55
|
-
enrichOperations
|
|
56
|
-
};
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import type { TokenInfo } from "../plugins/adapters/types.js";
|
|
3
|
-
import type { CreditAccountOperation } from "./types.js";
|
|
4
|
-
export type TokenResolver = (addr: Address) => TokenInfo;
|
|
5
|
-
export declare function enrichOperations(ops: CreditAccountOperation[], resolve: TokenResolver): CreditAccountOperation<TokenInfo>[];
|