@gearbox-protocol/sdk 12.9.2 → 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.
- package/dist/cjs/history/mapOperations.js +11 -11
- package/dist/cjs/history/toLegacyOperation.js +35 -12
- package/dist/esm/history/mapOperations.js +11 -11
- package/dist/esm/history/toLegacyOperation.js +35 -12
- package/dist/types/history/mapOperations.d.ts +7 -7
- package/dist/types/history/toLegacyOperation.d.ts +2 -1
- 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,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: params.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: params.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
|
}
|
|
@@ -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: params.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: params.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;
|
|
@@ -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 {
|
|
@@ -13,6 +13,7 @@ export interface LegacyMulticallOp {
|
|
|
13
13
|
}
|
|
14
14
|
export interface LegacyVisitorParams {
|
|
15
15
|
sessionId: string;
|
|
16
|
+
creditManager: Address;
|
|
16
17
|
}
|
|
17
18
|
export declare function createLegacyVisitor(params: LegacyVisitorParams): OperationVisitor<LegacyMulticallOp, LegacyApiOperation>;
|
|
18
19
|
export declare function toLegacyOperations(ops: CreditAccountOperation[], params: LegacyVisitorParams): LegacyApiOperation[];
|