@gearbox-protocol/sdk 12.9.2 → 12.9.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/mapOperations.js +11 -11
- package/dist/cjs/history/parseCreditAccountTransaction.js +2 -0
- package/dist/cjs/history/toLegacyOperation.js +35 -12
- package/dist/esm/history/mapOperations.js +11 -11
- package/dist/esm/history/parseCreditAccountTransaction.js +2 -0
- package/dist/esm/history/toLegacyOperation.js +35 -12
- package/dist/types/history/mapOperations.d.ts +7 -7
- package/dist/types/history/parseCreditAccountTransaction.d.ts +1 -0
- package/dist/types/history/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -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
|
}
|
|
@@ -30,6 +30,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
30
30
|
receipt,
|
|
31
31
|
pool,
|
|
32
32
|
creditFacade,
|
|
33
|
+
creditManager,
|
|
33
34
|
creditAccount,
|
|
34
35
|
underlying,
|
|
35
36
|
register,
|
|
@@ -53,6 +54,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
53
54
|
phantomTokens
|
|
54
55
|
} = (0, import_extractTransfers.extractTransfers)(logs, creditAccount, pool, creditFacade);
|
|
55
56
|
const meta = {
|
|
57
|
+
creditManager,
|
|
56
58
|
creditFacade,
|
|
57
59
|
timestamp,
|
|
58
60
|
blockNumber,
|
|
@@ -30,44 +30,67 @@ function commonFields(op, params) {
|
|
|
30
30
|
protocol: op.creditFacade
|
|
31
31
|
};
|
|
32
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
|
+
}
|
|
33
42
|
function createLegacyVisitor(params) {
|
|
34
43
|
return {
|
|
35
|
-
Execute(op) {
|
|
36
|
-
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
|
+
};
|
|
37
53
|
},
|
|
38
|
-
IncreaseBorrowedAmount(op) {
|
|
54
|
+
IncreaseBorrowedAmount(op, ctx) {
|
|
39
55
|
return {
|
|
40
56
|
operation: op.operation,
|
|
41
|
-
amount: op.amount.toString()
|
|
57
|
+
amount: op.amount.toString(),
|
|
58
|
+
...innerCommonFields(ctx, params),
|
|
59
|
+
protocol: ctx.creditManager
|
|
42
60
|
};
|
|
43
61
|
},
|
|
44
|
-
DecreaseBorrowedAmount(op) {
|
|
62
|
+
DecreaseBorrowedAmount(op, ctx) {
|
|
45
63
|
return {
|
|
46
64
|
operation: op.operation,
|
|
47
|
-
amount: op.amount.toString()
|
|
65
|
+
amount: op.amount.toString(),
|
|
66
|
+
...innerCommonFields(ctx, params),
|
|
67
|
+
protocol: ctx.creditManager
|
|
48
68
|
};
|
|
49
69
|
},
|
|
50
|
-
AddCollateral(op) {
|
|
70
|
+
AddCollateral(op, ctx) {
|
|
51
71
|
return {
|
|
52
72
|
operation: op.operation,
|
|
53
73
|
token: op.token,
|
|
54
|
-
amount: op.amount.toString()
|
|
74
|
+
amount: op.amount.toString(),
|
|
75
|
+
...innerCommonFields(ctx, params)
|
|
55
76
|
};
|
|
56
77
|
},
|
|
57
|
-
WithdrawCollateral(op) {
|
|
78
|
+
WithdrawCollateral(op, ctx) {
|
|
58
79
|
return {
|
|
59
80
|
operation: op.operation,
|
|
60
81
|
token: op.token,
|
|
61
82
|
amount: op.amount.toString(),
|
|
62
83
|
to: op.to,
|
|
63
|
-
...op.phantomToken ? { phantomToken: op.phantomToken } : {}
|
|
84
|
+
...op.phantomToken ? { phantomToken: op.phantomToken } : {},
|
|
85
|
+
...innerCommonFields(ctx, params)
|
|
64
86
|
};
|
|
65
87
|
},
|
|
66
|
-
UpdateQuota(op) {
|
|
88
|
+
UpdateQuota(op, ctx) {
|
|
67
89
|
return {
|
|
68
90
|
operation: op.operation,
|
|
69
91
|
token: op.token,
|
|
70
|
-
change: op.change.toString()
|
|
92
|
+
change: op.change.toString(),
|
|
93
|
+
...innerCommonFields(ctx, params)
|
|
71
94
|
};
|
|
72
95
|
},
|
|
73
96
|
DirectTokenTransfer(op) {
|
|
@@ -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
|
}
|
|
@@ -7,6 +7,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
7
7
|
receipt,
|
|
8
8
|
pool,
|
|
9
9
|
creditFacade,
|
|
10
|
+
creditManager,
|
|
10
11
|
creditAccount,
|
|
11
12
|
underlying,
|
|
12
13
|
register,
|
|
@@ -30,6 +31,7 @@ function parseCreditAccountTransaction(input) {
|
|
|
30
31
|
phantomTokens
|
|
31
32
|
} = extractTransfers(logs, creditAccount, pool, creditFacade);
|
|
32
33
|
const meta = {
|
|
34
|
+
creditManager,
|
|
33
35
|
creditFacade,
|
|
34
36
|
timestamp,
|
|
35
37
|
blockNumber,
|
|
@@ -6,44 +6,67 @@ function commonFields(op, params) {
|
|
|
6
6
|
protocol: op.creditFacade
|
|
7
7
|
};
|
|
8
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
|
+
}
|
|
9
18
|
function createLegacyVisitor(params) {
|
|
10
19
|
return {
|
|
11
|
-
Execute(op) {
|
|
12
|
-
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
|
+
};
|
|
13
29
|
},
|
|
14
|
-
IncreaseBorrowedAmount(op) {
|
|
30
|
+
IncreaseBorrowedAmount(op, ctx) {
|
|
15
31
|
return {
|
|
16
32
|
operation: op.operation,
|
|
17
|
-
amount: op.amount.toString()
|
|
33
|
+
amount: op.amount.toString(),
|
|
34
|
+
...innerCommonFields(ctx, params),
|
|
35
|
+
protocol: ctx.creditManager
|
|
18
36
|
};
|
|
19
37
|
},
|
|
20
|
-
DecreaseBorrowedAmount(op) {
|
|
38
|
+
DecreaseBorrowedAmount(op, ctx) {
|
|
21
39
|
return {
|
|
22
40
|
operation: op.operation,
|
|
23
|
-
amount: op.amount.toString()
|
|
41
|
+
amount: op.amount.toString(),
|
|
42
|
+
...innerCommonFields(ctx, params),
|
|
43
|
+
protocol: ctx.creditManager
|
|
24
44
|
};
|
|
25
45
|
},
|
|
26
|
-
AddCollateral(op) {
|
|
46
|
+
AddCollateral(op, ctx) {
|
|
27
47
|
return {
|
|
28
48
|
operation: op.operation,
|
|
29
49
|
token: op.token,
|
|
30
|
-
amount: op.amount.toString()
|
|
50
|
+
amount: op.amount.toString(),
|
|
51
|
+
...innerCommonFields(ctx, params)
|
|
31
52
|
};
|
|
32
53
|
},
|
|
33
|
-
WithdrawCollateral(op) {
|
|
54
|
+
WithdrawCollateral(op, ctx) {
|
|
34
55
|
return {
|
|
35
56
|
operation: op.operation,
|
|
36
57
|
token: op.token,
|
|
37
58
|
amount: op.amount.toString(),
|
|
38
59
|
to: op.to,
|
|
39
|
-
...op.phantomToken ? { phantomToken: op.phantomToken } : {}
|
|
60
|
+
...op.phantomToken ? { phantomToken: op.phantomToken } : {},
|
|
61
|
+
...innerCommonFields(ctx, params)
|
|
40
62
|
};
|
|
41
63
|
},
|
|
42
|
-
UpdateQuota(op) {
|
|
64
|
+
UpdateQuota(op, ctx) {
|
|
43
65
|
return {
|
|
44
66
|
operation: op.operation,
|
|
45
67
|
token: op.token,
|
|
46
|
-
change: op.change.toString()
|
|
68
|
+
change: op.change.toString(),
|
|
69
|
+
...innerCommonFields(ctx, params)
|
|
47
70
|
};
|
|
48
71
|
},
|
|
49
72
|
DirectTokenTransfer(op) {
|
|
@@ -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;
|
|
@@ -15,6 +15,7 @@ export interface OperationMetadata {
|
|
|
15
15
|
timestamp: number;
|
|
16
16
|
}
|
|
17
17
|
export interface FacadeOperationMetadata extends OperationMetadata {
|
|
18
|
+
creditManager: Address;
|
|
18
19
|
creditFacade: Address;
|
|
19
20
|
}
|
|
20
21
|
export interface MulticallOperation extends FacadeOperationMetadata {
|