@gearbox-protocol/sdk 12.9.1 → 12.9.3

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.
@@ -30,17 +30,14 @@ function assembleOperations(input) {
30
30
  executeResults,
31
31
  register,
32
32
  underlying,
33
- txHash,
34
- blockNumber,
35
33
  liquidationRemainingFunds,
36
34
  phantomTokens,
37
35
  strict
38
36
  } = input;
39
37
  let offset = 0;
40
- const meta = { txHash, blockNumber };
41
38
  return facadeCalls.map((fc) => {
42
39
  if (fc.operation === "PartiallyLiquidateCreditAccount") {
43
- return assemblePartialLiquidation(fc, meta);
40
+ return assemblePartialLiquidation(fc);
44
41
  }
45
42
  const count = countAdapterCalls(fc.innerCalls, register);
46
43
  const sliced = executeResults.slice(offset, offset + count);
@@ -59,7 +56,6 @@ function assembleOperations(input) {
59
56
  switch (fc.operation) {
60
57
  case "OpenCreditAccount":
61
58
  return {
62
- ...meta,
63
59
  operation: fc.operation,
64
60
  creditAccount: fc.creditAccount,
65
61
  onBehalfOf: fc.parsed.rawArgs.onBehalfOf,
@@ -68,7 +64,6 @@ function assembleOperations(input) {
68
64
  };
69
65
  case "LiquidateCreditAccount":
70
66
  return {
71
- ...meta,
72
67
  operation: fc.operation,
73
68
  creditAccount: fc.creditAccount,
74
69
  to: fc.parsed.rawArgs.to,
@@ -78,7 +73,6 @@ function assembleOperations(input) {
78
73
  };
79
74
  default:
80
75
  return {
81
- ...meta,
82
76
  operation: fc.operation,
83
77
  creditAccount: fc.creditAccount,
84
78
  multicall
@@ -92,10 +86,9 @@ function countAdapterCalls(innerCalls, register) {
92
86
  return !contract || contract instanceof import_adapters.AbstractAdapterContract;
93
87
  }).length;
94
88
  }
95
- function assemblePartialLiquidation(fc, meta) {
89
+ function assemblePartialLiquidation(fc) {
96
90
  const { rawArgs } = fc.parsed;
97
91
  return {
98
- ...meta,
99
92
  operation: "PartiallyLiquidateCreditAccount",
100
93
  creditAccount: fc.creditAccount,
101
94
  token: rawArgs.token,
@@ -21,20 +21,20 @@ __export(mapOperations_exports, {
21
21
  mapOperations: () => mapOperations
22
22
  });
23
23
  module.exports = __toCommonJS(mapOperations_exports);
24
- function mapInnerOperation(op, visitor) {
24
+ function mapInnerOperation(op, visitor, ctx) {
25
25
  switch (op.operation) {
26
26
  case "Execute":
27
- return visitor.Execute(op);
27
+ return visitor.Execute(op, ctx);
28
28
  case "IncreaseBorrowedAmount":
29
- return visitor.IncreaseBorrowedAmount(op);
29
+ return visitor.IncreaseBorrowedAmount(op, ctx);
30
30
  case "DecreaseBorrowedAmount":
31
- return visitor.DecreaseBorrowedAmount(op);
31
+ return visitor.DecreaseBorrowedAmount(op, ctx);
32
32
  case "AddCollateral":
33
- return visitor.AddCollateral(op);
33
+ return visitor.AddCollateral(op, ctx);
34
34
  case "WithdrawCollateral":
35
- return visitor.WithdrawCollateral(op);
35
+ return visitor.WithdrawCollateral(op, ctx);
36
36
  case "UpdateQuota":
37
- return visitor.UpdateQuota(op);
37
+ return visitor.UpdateQuota(op, ctx);
38
38
  }
39
39
  }
40
40
  function mapOuterOperation(op, visitor) {
@@ -46,25 +46,25 @@ function mapOuterOperation(op, visitor) {
46
46
  case "MultiCall":
47
47
  case "BotMulticall": {
48
48
  const multicall = op.multicall.map(
49
- (inner) => mapInnerOperation(inner, visitor)
49
+ (inner) => mapInnerOperation(inner, visitor, op)
50
50
  );
51
51
  return visitor.MultiCall(op, multicall);
52
52
  }
53
53
  case "OpenCreditAccount": {
54
54
  const multicall = op.multicall.map(
55
- (inner) => mapInnerOperation(inner, visitor)
55
+ (inner) => mapInnerOperation(inner, visitor, op)
56
56
  );
57
57
  return visitor.OpenCreditAccount(op, multicall);
58
58
  }
59
59
  case "CloseCreditAccount": {
60
60
  const multicall = op.multicall.map(
61
- (inner) => mapInnerOperation(inner, visitor)
61
+ (inner) => mapInnerOperation(inner, visitor, op)
62
62
  );
63
63
  return visitor.CloseCreditAccount(op, multicall);
64
64
  }
65
65
  case "LiquidateCreditAccount": {
66
66
  const multicall = op.multicall.map(
67
- (inner) => mapInnerOperation(inner, visitor)
67
+ (inner) => mapInnerOperation(inner, visitor, op)
68
68
  );
69
69
  return visitor.LiquidateCreditAccount(op, multicall);
70
70
  }
@@ -38,6 +38,7 @@ function parseCreditAccountTransaction(input) {
38
38
  const logs = receipt.logs;
39
39
  const txHash = receipt.transactionHash;
40
40
  const blockNumber = Number(receipt.blockNumber);
41
+ const timestamp = Number(receipt.blockTimestamp ?? 0);
41
42
  const facadeCalls = (0, import_findFacadeCalls.findFacadeCalls)(
42
43
  trace,
43
44
  creditFacade,
@@ -51,21 +52,27 @@ function parseCreditAccountTransaction(input) {
51
52
  liquidationRemainingFunds,
52
53
  phantomTokens
53
54
  } = (0, import_extractTransfers.extractTransfers)(logs, creditAccount, pool, creditFacade);
55
+ const meta = {
56
+ creditFacade,
57
+ timestamp,
58
+ blockNumber,
59
+ txHash
60
+ };
54
61
  const facadeOps = (0, import_assembleOperations.assembleOperations)({
55
62
  facadeCalls,
56
63
  executeResults,
57
64
  register,
58
65
  underlying,
59
- txHash,
60
- blockNumber,
61
66
  liquidationRemainingFunds,
62
67
  phantomTokens,
63
68
  strict
64
- });
69
+ }).map((o) => ({ ...o, ...meta }));
65
70
  const directOps = directTransfers.map((dt) => ({
66
71
  operation: "DirectTokenTransfer",
67
72
  txHash,
68
73
  blockNumber,
74
+ timestamp,
75
+ protocol: dt.token,
69
76
  creditAccount,
70
77
  ...dt
71
78
  }));
@@ -18,112 +18,161 @@ 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
+ createLegacyVisitor: () => createLegacyVisitor,
22
22
  toLegacyOperations: () => toLegacyOperations
23
23
  });
24
24
  module.exports = __toCommonJS(toLegacyOperation_exports);
25
25
  var import_mapOperations = require("./mapOperations.js");
26
- const legacyVisitor = {
27
- Execute(op) {
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
- };
120
- }
121
- };
122
- function toLegacyOperations(ops) {
123
- return (0, import_mapOperations.mapOperations)(ops, legacyVisitor);
26
+ function commonFields(op, params) {
27
+ return {
28
+ timestamp: op.timestamp,
29
+ sessionId: params.sessionId,
30
+ protocol: op.creditFacade
31
+ };
32
+ }
33
+ function innerCommonFields(ctx, params) {
34
+ return {
35
+ txHash: ctx.txHash,
36
+ blockNum: ctx.blockNumber,
37
+ timestamp: ctx.timestamp,
38
+ sessionId: params.sessionId,
39
+ protocol: ctx.creditFacade
40
+ };
41
+ }
42
+ function createLegacyVisitor(params) {
43
+ return {
44
+ Execute(op, ctx) {
45
+ return {
46
+ ...op.legacy,
47
+ txHash: ctx.txHash,
48
+ blockNum: ctx.blockNumber,
49
+ timestamp: ctx.timestamp,
50
+ sessionId: params.sessionId,
51
+ protocol: op.protocol
52
+ };
53
+ },
54
+ IncreaseBorrowedAmount(op, ctx) {
55
+ return {
56
+ operation: op.operation,
57
+ amount: op.amount.toString(),
58
+ ...innerCommonFields(ctx, params),
59
+ protocol: params.creditManager
60
+ };
61
+ },
62
+ DecreaseBorrowedAmount(op, ctx) {
63
+ return {
64
+ operation: op.operation,
65
+ amount: op.amount.toString(),
66
+ ...innerCommonFields(ctx, params),
67
+ protocol: params.creditManager
68
+ };
69
+ },
70
+ AddCollateral(op, ctx) {
71
+ return {
72
+ operation: op.operation,
73
+ token: op.token,
74
+ amount: op.amount.toString(),
75
+ ...innerCommonFields(ctx, params)
76
+ };
77
+ },
78
+ WithdrawCollateral(op, ctx) {
79
+ return {
80
+ operation: op.operation,
81
+ token: op.token,
82
+ amount: op.amount.toString(),
83
+ to: op.to,
84
+ ...op.phantomToken ? { phantomToken: op.phantomToken } : {},
85
+ ...innerCommonFields(ctx, params)
86
+ };
87
+ },
88
+ UpdateQuota(op, ctx) {
89
+ return {
90
+ operation: op.operation,
91
+ token: op.token,
92
+ change: op.change.toString(),
93
+ ...innerCommonFields(ctx, params)
94
+ };
95
+ },
96
+ DirectTokenTransfer(op) {
97
+ return {
98
+ operation: op.operation,
99
+ txHash: op.txHash,
100
+ blockNum: op.blockNumber,
101
+ timestamp: op.timestamp,
102
+ sessionId: params.sessionId,
103
+ protocol: op.protocol,
104
+ token: op.token,
105
+ amount: op.amount.toString(),
106
+ from: op.from,
107
+ to: op.creditAccount
108
+ };
109
+ },
110
+ MultiCall(op, multicall) {
111
+ return {
112
+ operation: op.operation,
113
+ txHash: op.txHash,
114
+ blockNum: op.blockNumber,
115
+ ...commonFields(op, params),
116
+ multicall
117
+ };
118
+ },
119
+ OpenCreditAccount(op, multicall) {
120
+ return {
121
+ operation: op.operation,
122
+ txHash: op.txHash,
123
+ blockNum: op.blockNumber,
124
+ ...commonFields(op, params),
125
+ // TODO: missing legacy fields:
126
+ // userFunds: require prices to compute as
127
+ // sum of AddCollateral/WithdrawCollateral amounts denominated in underlying token.
128
+ // initialFunds: === userFunds
129
+ //
130
+ // leverage: (userFunds + borrowAmount) / userFunds
131
+ // where borrowAmount = sum of IncreaseDebt amounts in multicall (computable from data)
132
+ multicall
133
+ };
134
+ },
135
+ CloseCreditAccount(op, multicall) {
136
+ return {
137
+ operation: op.operation,
138
+ txHash: op.txHash,
139
+ blockNum: op.blockNumber,
140
+ ...commonFields(op, params),
141
+ // TODO: missing legacy fields:
142
+ // remainingFunds:
143
+ multicall
144
+ };
145
+ },
146
+ LiquidateCreditAccount(op, multicall) {
147
+ return {
148
+ operation: op.operation,
149
+ txHash: op.txHash,
150
+ blockNum: op.blockNumber,
151
+ ...commonFields(op, params),
152
+ to: op.to,
153
+ remainingFunds: op.remainingFunds.toString(),
154
+ multicall
155
+ };
156
+ },
157
+ PartiallyLiquidateCreditAccount(op) {
158
+ return {
159
+ operation: op.operation,
160
+ txHash: op.txHash,
161
+ blockNum: op.blockNumber,
162
+ ...commonFields(op, params),
163
+ token: op.token,
164
+ repaidAmount: op.repaidAmount.toString(),
165
+ minSeizedAmount: op.minSeizedAmount.toString(),
166
+ to: op.to
167
+ };
168
+ }
169
+ };
170
+ }
171
+ function toLegacyOperations(ops, params) {
172
+ return (0, import_mapOperations.mapOperations)(ops, createLegacyVisitor(params));
124
173
  }
125
174
  // Annotate the CommonJS export names for ESM import in node:
126
175
  0 && (module.exports = {
127
- legacyVisitor,
176
+ createLegacyVisitor,
128
177
  toLegacyOperations
129
178
  });
@@ -7,17 +7,14 @@ function assembleOperations(input) {
7
7
  executeResults,
8
8
  register,
9
9
  underlying,
10
- txHash,
11
- blockNumber,
12
10
  liquidationRemainingFunds,
13
11
  phantomTokens,
14
12
  strict
15
13
  } = input;
16
14
  let offset = 0;
17
- const meta = { txHash, blockNumber };
18
15
  return facadeCalls.map((fc) => {
19
16
  if (fc.operation === "PartiallyLiquidateCreditAccount") {
20
- return assemblePartialLiquidation(fc, meta);
17
+ return assemblePartialLiquidation(fc);
21
18
  }
22
19
  const count = countAdapterCalls(fc.innerCalls, register);
23
20
  const sliced = executeResults.slice(offset, offset + count);
@@ -36,7 +33,6 @@ function assembleOperations(input) {
36
33
  switch (fc.operation) {
37
34
  case "OpenCreditAccount":
38
35
  return {
39
- ...meta,
40
36
  operation: fc.operation,
41
37
  creditAccount: fc.creditAccount,
42
38
  onBehalfOf: fc.parsed.rawArgs.onBehalfOf,
@@ -45,7 +41,6 @@ function assembleOperations(input) {
45
41
  };
46
42
  case "LiquidateCreditAccount":
47
43
  return {
48
- ...meta,
49
44
  operation: fc.operation,
50
45
  creditAccount: fc.creditAccount,
51
46
  to: fc.parsed.rawArgs.to,
@@ -55,7 +50,6 @@ function assembleOperations(input) {
55
50
  };
56
51
  default:
57
52
  return {
58
- ...meta,
59
53
  operation: fc.operation,
60
54
  creditAccount: fc.creditAccount,
61
55
  multicall
@@ -69,10 +63,9 @@ function countAdapterCalls(innerCalls, register) {
69
63
  return !contract || contract instanceof AbstractAdapterContract;
70
64
  }).length;
71
65
  }
72
- function assemblePartialLiquidation(fc, meta) {
66
+ function assemblePartialLiquidation(fc) {
73
67
  const { rawArgs } = fc.parsed;
74
68
  return {
75
- ...meta,
76
69
  operation: "PartiallyLiquidateCreditAccount",
77
70
  creditAccount: fc.creditAccount,
78
71
  token: rawArgs.token,
@@ -1,17 +1,17 @@
1
- function mapInnerOperation(op, visitor) {
1
+ function mapInnerOperation(op, visitor, ctx) {
2
2
  switch (op.operation) {
3
3
  case "Execute":
4
- return visitor.Execute(op);
4
+ return visitor.Execute(op, ctx);
5
5
  case "IncreaseBorrowedAmount":
6
- return visitor.IncreaseBorrowedAmount(op);
6
+ return visitor.IncreaseBorrowedAmount(op, ctx);
7
7
  case "DecreaseBorrowedAmount":
8
- return visitor.DecreaseBorrowedAmount(op);
8
+ return visitor.DecreaseBorrowedAmount(op, ctx);
9
9
  case "AddCollateral":
10
- return visitor.AddCollateral(op);
10
+ return visitor.AddCollateral(op, ctx);
11
11
  case "WithdrawCollateral":
12
- return visitor.WithdrawCollateral(op);
12
+ return visitor.WithdrawCollateral(op, ctx);
13
13
  case "UpdateQuota":
14
- return visitor.UpdateQuota(op);
14
+ return visitor.UpdateQuota(op, ctx);
15
15
  }
16
16
  }
17
17
  function mapOuterOperation(op, visitor) {
@@ -23,25 +23,25 @@ function mapOuterOperation(op, visitor) {
23
23
  case "MultiCall":
24
24
  case "BotMulticall": {
25
25
  const multicall = op.multicall.map(
26
- (inner) => mapInnerOperation(inner, visitor)
26
+ (inner) => mapInnerOperation(inner, visitor, op)
27
27
  );
28
28
  return visitor.MultiCall(op, multicall);
29
29
  }
30
30
  case "OpenCreditAccount": {
31
31
  const multicall = op.multicall.map(
32
- (inner) => mapInnerOperation(inner, visitor)
32
+ (inner) => mapInnerOperation(inner, visitor, op)
33
33
  );
34
34
  return visitor.OpenCreditAccount(op, multicall);
35
35
  }
36
36
  case "CloseCreditAccount": {
37
37
  const multicall = op.multicall.map(
38
- (inner) => mapInnerOperation(inner, visitor)
38
+ (inner) => mapInnerOperation(inner, visitor, op)
39
39
  );
40
40
  return visitor.CloseCreditAccount(op, multicall);
41
41
  }
42
42
  case "LiquidateCreditAccount": {
43
43
  const multicall = op.multicall.map(
44
- (inner) => mapInnerOperation(inner, visitor)
44
+ (inner) => mapInnerOperation(inner, visitor, op)
45
45
  );
46
46
  return visitor.LiquidateCreditAccount(op, multicall);
47
47
  }
@@ -15,6 +15,7 @@ function parseCreditAccountTransaction(input) {
15
15
  const logs = receipt.logs;
16
16
  const txHash = receipt.transactionHash;
17
17
  const blockNumber = Number(receipt.blockNumber);
18
+ const timestamp = Number(receipt.blockTimestamp ?? 0);
18
19
  const facadeCalls = findFacadeCalls(
19
20
  trace,
20
21
  creditFacade,
@@ -28,21 +29,27 @@ function parseCreditAccountTransaction(input) {
28
29
  liquidationRemainingFunds,
29
30
  phantomTokens
30
31
  } = extractTransfers(logs, creditAccount, pool, creditFacade);
32
+ const meta = {
33
+ creditFacade,
34
+ timestamp,
35
+ blockNumber,
36
+ txHash
37
+ };
31
38
  const facadeOps = assembleOperations({
32
39
  facadeCalls,
33
40
  executeResults,
34
41
  register,
35
42
  underlying,
36
- txHash,
37
- blockNumber,
38
43
  liquidationRemainingFunds,
39
44
  phantomTokens,
40
45
  strict
41
- });
46
+ }).map((o) => ({ ...o, ...meta }));
42
47
  const directOps = directTransfers.map((dt) => ({
43
48
  operation: "DirectTokenTransfer",
44
49
  txHash,
45
50
  blockNumber,
51
+ timestamp,
52
+ protocol: dt.token,
46
53
  creditAccount,
47
54
  ...dt
48
55
  }));
@@ -1,104 +1,153 @@
1
1
  import { mapOperations } from "./mapOperations.js";
2
- const legacyVisitor = {
3
- Execute(op) {
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
- };
96
- }
97
- };
98
- function toLegacyOperations(ops) {
99
- return mapOperations(ops, legacyVisitor);
2
+ function commonFields(op, params) {
3
+ return {
4
+ timestamp: op.timestamp,
5
+ sessionId: params.sessionId,
6
+ protocol: op.creditFacade
7
+ };
8
+ }
9
+ function innerCommonFields(ctx, params) {
10
+ return {
11
+ txHash: ctx.txHash,
12
+ blockNum: ctx.blockNumber,
13
+ timestamp: ctx.timestamp,
14
+ sessionId: params.sessionId,
15
+ protocol: ctx.creditFacade
16
+ };
17
+ }
18
+ function createLegacyVisitor(params) {
19
+ return {
20
+ Execute(op, ctx) {
21
+ return {
22
+ ...op.legacy,
23
+ txHash: ctx.txHash,
24
+ blockNum: ctx.blockNumber,
25
+ timestamp: ctx.timestamp,
26
+ sessionId: params.sessionId,
27
+ protocol: op.protocol
28
+ };
29
+ },
30
+ IncreaseBorrowedAmount(op, ctx) {
31
+ return {
32
+ operation: op.operation,
33
+ amount: op.amount.toString(),
34
+ ...innerCommonFields(ctx, params),
35
+ protocol: params.creditManager
36
+ };
37
+ },
38
+ DecreaseBorrowedAmount(op, ctx) {
39
+ return {
40
+ operation: op.operation,
41
+ amount: op.amount.toString(),
42
+ ...innerCommonFields(ctx, params),
43
+ protocol: params.creditManager
44
+ };
45
+ },
46
+ AddCollateral(op, ctx) {
47
+ return {
48
+ operation: op.operation,
49
+ token: op.token,
50
+ amount: op.amount.toString(),
51
+ ...innerCommonFields(ctx, params)
52
+ };
53
+ },
54
+ WithdrawCollateral(op, ctx) {
55
+ return {
56
+ operation: op.operation,
57
+ token: op.token,
58
+ amount: op.amount.toString(),
59
+ to: op.to,
60
+ ...op.phantomToken ? { phantomToken: op.phantomToken } : {},
61
+ ...innerCommonFields(ctx, params)
62
+ };
63
+ },
64
+ UpdateQuota(op, ctx) {
65
+ return {
66
+ operation: op.operation,
67
+ token: op.token,
68
+ change: op.change.toString(),
69
+ ...innerCommonFields(ctx, params)
70
+ };
71
+ },
72
+ DirectTokenTransfer(op) {
73
+ return {
74
+ operation: op.operation,
75
+ txHash: op.txHash,
76
+ blockNum: op.blockNumber,
77
+ timestamp: op.timestamp,
78
+ sessionId: params.sessionId,
79
+ protocol: op.protocol,
80
+ token: op.token,
81
+ amount: op.amount.toString(),
82
+ from: op.from,
83
+ to: op.creditAccount
84
+ };
85
+ },
86
+ MultiCall(op, multicall) {
87
+ return {
88
+ operation: op.operation,
89
+ txHash: op.txHash,
90
+ blockNum: op.blockNumber,
91
+ ...commonFields(op, params),
92
+ multicall
93
+ };
94
+ },
95
+ OpenCreditAccount(op, multicall) {
96
+ return {
97
+ operation: op.operation,
98
+ txHash: op.txHash,
99
+ blockNum: op.blockNumber,
100
+ ...commonFields(op, params),
101
+ // TODO: missing legacy fields:
102
+ // userFunds: require prices to compute as
103
+ // sum of AddCollateral/WithdrawCollateral amounts denominated in underlying token.
104
+ // initialFunds: === userFunds
105
+ //
106
+ // leverage: (userFunds + borrowAmount) / userFunds
107
+ // where borrowAmount = sum of IncreaseDebt amounts in multicall (computable from data)
108
+ multicall
109
+ };
110
+ },
111
+ CloseCreditAccount(op, multicall) {
112
+ return {
113
+ operation: op.operation,
114
+ txHash: op.txHash,
115
+ blockNum: op.blockNumber,
116
+ ...commonFields(op, params),
117
+ // TODO: missing legacy fields:
118
+ // remainingFunds:
119
+ multicall
120
+ };
121
+ },
122
+ LiquidateCreditAccount(op, multicall) {
123
+ return {
124
+ operation: op.operation,
125
+ txHash: op.txHash,
126
+ blockNum: op.blockNumber,
127
+ ...commonFields(op, params),
128
+ to: op.to,
129
+ remainingFunds: op.remainingFunds.toString(),
130
+ multicall
131
+ };
132
+ },
133
+ PartiallyLiquidateCreditAccount(op) {
134
+ return {
135
+ operation: op.operation,
136
+ txHash: op.txHash,
137
+ blockNum: op.blockNumber,
138
+ ...commonFields(op, params),
139
+ token: op.token,
140
+ repaidAmount: op.repaidAmount.toString(),
141
+ minSeizedAmount: op.minSeizedAmount.toString(),
142
+ to: op.to
143
+ };
144
+ }
145
+ };
146
+ }
147
+ function toLegacyOperations(ops, params) {
148
+ return mapOperations(ops, createLegacyVisitor(params));
100
149
  }
101
150
  export {
102
- legacyVisitor,
151
+ createLegacyVisitor,
103
152
  toLegacyOperations
104
153
  };
@@ -1,14 +1,12 @@
1
- import type { Address, Hex } from "viem";
1
+ import type { Address } from "viem";
2
2
  import type { AddressMap, ChainContractsRegister } from "../sdk/index.js";
3
3
  import type { ExecuteResult, FacadeParsedCall } from "./internal-types.js";
4
- import type { OuterFacadeOperation } from "./types.js";
4
+ import type { FacadeOperationMetadata, OuterFacadeOperation } from "./types.js";
5
5
  export interface AssembleOperationsInput {
6
6
  facadeCalls: FacadeParsedCall[];
7
7
  executeResults: ExecuteResult[];
8
8
  register: ChainContractsRegister;
9
9
  underlying: Address;
10
- txHash: Hex;
11
- blockNumber: number;
12
10
  liquidationRemainingFunds?: bigint;
13
11
  phantomTokens?: AddressMap<Address>;
14
12
  strict?: boolean;
@@ -21,4 +19,4 @@ export interface AssembleOperationsInput {
21
19
  * the entire transaction) is sliced per facade call based on how many
22
20
  * adapter/unknown inner calls each one contains.
23
21
  */
24
- export declare function assembleOperations(input: AssembleOperationsInput): OuterFacadeOperation[];
22
+ export declare function assembleOperations(input: AssembleOperationsInput): Omit<OuterFacadeOperation, keyof FacadeOperationMetadata>[];
@@ -1,18 +1,18 @@
1
1
  import type { AdapterOperation } from "../plugins/adapters/index.js";
2
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";
3
+ import type { CloseCreditAccountOperation, CreditAccountOperation, DirectTokenTransferOperation, FacadeOperationMetadata, LiquidateCreditAccountOperation, MulticallOperation, OpenCreditAccountOperation, PartialLiquidationOperation } from "./types.js";
4
4
  /**
5
5
  * Visitor that maps each operation node in a {@link CreditAccountOperation}
6
6
  * tree to a new representation.
7
7
  *
8
8
  */
9
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;
10
+ Execute(op: AdapterOperation, ctx: FacadeOperationMetadata): TInner;
11
+ IncreaseBorrowedAmount(op: IncreaseDebtOp, ctx: FacadeOperationMetadata): TInner;
12
+ DecreaseBorrowedAmount(op: DecreaseDebtOp, ctx: FacadeOperationMetadata): TInner;
13
+ AddCollateral(op: AddCollateralOp, ctx: FacadeOperationMetadata): TInner;
14
+ WithdrawCollateral(op: WithdrawCollateralOp, ctx: FacadeOperationMetadata): TInner;
15
+ UpdateQuota(op: UpdateQuotaOp, ctx: FacadeOperationMetadata): TInner;
16
16
  DirectTokenTransfer(op: DirectTokenTransferOperation): TOuter;
17
17
  MultiCall(op: MulticallOperation, multicall: TInner[]): TOuter;
18
18
  OpenCreditAccount(op: OpenCreditAccountOperation, multicall: TInner[]): TOuter;
@@ -6,7 +6,7 @@ export interface ParseTransactionInput {
6
6
  * Output of `debug_traceTransaction`
7
7
  */
8
8
  trace: unknown;
9
- receipt: Pick<TransactionReceipt<bigint | number>, "logs" | "transactionHash" | "blockNumber">;
9
+ receipt: Pick<TransactionReceipt<bigint | number>, "logs" | "transactionHash" | "blockNumber" | "blockTimestamp">;
10
10
  pool: Address;
11
11
  /**
12
12
  * Underlying token of the pool.
@@ -1,4 +1,4 @@
1
- import type { Hex } from "viem";
1
+ import type { Address, Hex } from "viem";
2
2
  import { type OperationVisitor } from "./mapOperations.js";
3
3
  import type { CreditAccountOperation } from "./types.js";
4
4
  export interface LegacyApiOperation {
@@ -11,10 +11,9 @@ export interface LegacyMulticallOp {
11
11
  operation: string;
12
12
  [key: string]: unknown;
13
13
  }
14
- export declare const legacyVisitor: OperationVisitor<LegacyMulticallOp, LegacyApiOperation>;
15
- /**
16
- * Converts new parser output to the legacy API format for comparison.
17
- *
18
- * Missing `initialFunds`/`userFunds`/`leverage` on OpenCreditAccount.
19
- */
20
- export declare function toLegacyOperations(ops: CreditAccountOperation[]): LegacyApiOperation[];
14
+ export interface LegacyVisitorParams {
15
+ sessionId: string;
16
+ creditManager: Address;
17
+ }
18
+ export declare function createLegacyVisitor(params: LegacyVisitorParams): OperationVisitor<LegacyMulticallOp, LegacyApiOperation>;
19
+ export declare function toLegacyOperations(ops: CreditAccountOperation[], params: LegacyVisitorParams): LegacyApiOperation[];
@@ -12,25 +12,29 @@ export interface DirectTransferInfo {
12
12
  export interface OperationMetadata {
13
13
  txHash: Hex;
14
14
  blockNumber: number;
15
+ timestamp: number;
15
16
  }
16
- export interface MulticallOperation extends OperationMetadata {
17
+ export interface FacadeOperationMetadata extends OperationMetadata {
18
+ creditFacade: Address;
19
+ }
20
+ export interface MulticallOperation extends FacadeOperationMetadata {
17
21
  operation: "MultiCall" | "BotMulticall";
18
22
  creditAccount: Address;
19
23
  multicall: InnerOperation[];
20
24
  }
21
- export interface OpenCreditAccountOperation extends OperationMetadata {
25
+ export interface OpenCreditAccountOperation extends FacadeOperationMetadata {
22
26
  operation: "OpenCreditAccount";
23
27
  creditAccount: Address;
24
28
  onBehalfOf: Address;
25
29
  referralCode: bigint;
26
30
  multicall: InnerOperation[];
27
31
  }
28
- export interface CloseCreditAccountOperation extends OperationMetadata {
32
+ export interface CloseCreditAccountOperation extends FacadeOperationMetadata {
29
33
  operation: "CloseCreditAccount";
30
34
  creditAccount: Address;
31
35
  multicall: InnerOperation[];
32
36
  }
33
- export interface LiquidateCreditAccountOperation extends OperationMetadata {
37
+ export interface LiquidateCreditAccountOperation extends FacadeOperationMetadata {
34
38
  operation: "LiquidateCreditAccount";
35
39
  creditAccount: Address;
36
40
  to: Address;
@@ -38,7 +42,7 @@ export interface LiquidateCreditAccountOperation extends OperationMetadata {
38
42
  remainingFunds: bigint;
39
43
  multicall: InnerOperation[];
40
44
  }
41
- export interface PartialLiquidationOperation extends OperationMetadata {
45
+ export interface PartialLiquidationOperation extends FacadeOperationMetadata {
42
46
  operation: "PartiallyLiquidateCreditAccount";
43
47
  creditAccount: Address;
44
48
  token: Address;
@@ -48,6 +52,7 @@ export interface PartialLiquidationOperation extends OperationMetadata {
48
52
  }
49
53
  export interface DirectTokenTransferOperation extends OperationMetadata {
50
54
  operation: "DirectTokenTransfer";
55
+ protocol: Address;
51
56
  token: Address;
52
57
  from: Address;
53
58
  creditAccount: Address;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "12.9.1",
3
+ "version": "12.9.3",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",