@gearbox-protocol/sdk 14.12.0-next.57 → 14.12.0-next.59
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/abi/ILiquidationCompressorV313.js +43 -1
- package/dist/cjs/abi/IWithdrawalCompressorV313.js +71 -41
- package/dist/cjs/dev/claimDSToken.js +85 -6
- package/dist/cjs/dev/withdrawalUtils.js +173 -119
- package/dist/cjs/sdk/accounts/liquidations/LiquidationsService.js +27 -43
- package/dist/cjs/sdk/accounts/liquidations/constants.js +1 -1
- package/dist/cjs/sdk/accounts/liquidations/helpers.js +4 -2
- package/dist/cjs/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +12 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +10 -0
- package/dist/cjs/sdk/accounts/withdrawal-compressor/addresses.js +1 -1
- package/dist/esm/abi/ILiquidationCompressorV313.js +43 -1
- package/dist/esm/abi/IWithdrawalCompressorV313.js +71 -41
- package/dist/esm/dev/claimDSToken.js +86 -7
- package/dist/esm/dev/withdrawalUtils.js +173 -119
- package/dist/esm/sdk/accounts/liquidations/LiquidationsService.js +29 -45
- package/dist/esm/sdk/accounts/liquidations/constants.js +1 -1
- package/dist/esm/sdk/accounts/liquidations/helpers.js +4 -2
- package/dist/esm/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.js +12 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.js +10 -0
- package/dist/esm/sdk/accounts/withdrawal-compressor/addresses.js +1 -1
- package/dist/types/abi/ILiquidationCompressorV313.d.ts +36 -1
- package/dist/types/abi/IWithdrawalCompressorV313.d.ts +62 -38
- package/dist/types/dev/withdrawalUtils.d.ts +9 -5
- package/dist/types/sdk/accounts/liquidations/helpers.d.ts +8 -1
- package/dist/types/sdk/accounts/liquidations/types.d.ts +27 -5
- package/dist/types/sdk/accounts/withdrawal-compressor/AbstractWithdrawalCompressorContract.d.ts +3 -3
- package/dist/types/sdk/accounts/withdrawal-compressor/WithdrawalCompressorV313Contract.d.ts +62 -38
- package/dist/types/sdk/accounts/withdrawal-compressor/types.d.ts +10 -0
- package/package.json +1 -1
|
@@ -47,7 +47,12 @@ const iLiquidationCompressorV313Abi = [
|
|
|
47
47
|
internalType: "struct LiquidationData",
|
|
48
48
|
components: [
|
|
49
49
|
{
|
|
50
|
-
name: "
|
|
50
|
+
name: "requiredToken",
|
|
51
|
+
type: "address",
|
|
52
|
+
internalType: "address"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "requiredAmount",
|
|
51
56
|
type: "uint256",
|
|
52
57
|
internalType: "uint256"
|
|
53
58
|
},
|
|
@@ -102,6 +107,11 @@ const iLiquidationCompressorV313Abi = [
|
|
|
102
107
|
type: "bool",
|
|
103
108
|
internalType: "bool"
|
|
104
109
|
},
|
|
110
|
+
{
|
|
111
|
+
name: "isCreditAccountFrozen",
|
|
112
|
+
type: "bool",
|
|
113
|
+
internalType: "bool"
|
|
114
|
+
},
|
|
105
115
|
{
|
|
106
116
|
name: "kycProtocol",
|
|
107
117
|
type: "string",
|
|
@@ -116,6 +126,38 @@ const iLiquidationCompressorV313Abi = [
|
|
|
116
126
|
}],
|
|
117
127
|
stateMutability: "nonpayable"
|
|
118
128
|
},
|
|
129
|
+
{
|
|
130
|
+
type: "function",
|
|
131
|
+
name: "getRWALiquidators",
|
|
132
|
+
inputs: [{
|
|
133
|
+
name: "marketConfigurator",
|
|
134
|
+
type: "address",
|
|
135
|
+
internalType: "address"
|
|
136
|
+
}],
|
|
137
|
+
outputs: [{
|
|
138
|
+
name: "",
|
|
139
|
+
type: "tuple[]",
|
|
140
|
+
internalType: "struct RWALiquidatorInfo[]",
|
|
141
|
+
components: [
|
|
142
|
+
{
|
|
143
|
+
name: "gateway",
|
|
144
|
+
type: "address",
|
|
145
|
+
internalType: "address"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: "liquidatorAddress",
|
|
149
|
+
type: "address",
|
|
150
|
+
internalType: "address"
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "contractType",
|
|
154
|
+
type: "bytes32",
|
|
155
|
+
internalType: "bytes32"
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
}],
|
|
159
|
+
stateMutability: "view"
|
|
160
|
+
},
|
|
119
161
|
{
|
|
120
162
|
type: "function",
|
|
121
163
|
name: "version",
|
|
@@ -76,6 +76,11 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
76
76
|
internalType: "bytes"
|
|
77
77
|
}]
|
|
78
78
|
},
|
|
79
|
+
{
|
|
80
|
+
name: "redeemer",
|
|
81
|
+
type: "address",
|
|
82
|
+
internalType: "address"
|
|
83
|
+
},
|
|
79
84
|
{
|
|
80
85
|
name: "extraData",
|
|
81
86
|
type: "bytes",
|
|
@@ -124,6 +129,11 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
124
129
|
type: "uint256",
|
|
125
130
|
internalType: "uint256"
|
|
126
131
|
},
|
|
132
|
+
{
|
|
133
|
+
name: "redeemer",
|
|
134
|
+
type: "address",
|
|
135
|
+
internalType: "address"
|
|
136
|
+
},
|
|
127
137
|
{
|
|
128
138
|
name: "extraData",
|
|
129
139
|
type: "bytes",
|
|
@@ -137,9 +147,9 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
137
147
|
type: "function",
|
|
138
148
|
name: "getExternalAccountCurrentWithdrawals",
|
|
139
149
|
inputs: [{
|
|
140
|
-
name: "
|
|
141
|
-
type: "address",
|
|
142
|
-
internalType: "address"
|
|
150
|
+
name: "withdrawalTokens",
|
|
151
|
+
type: "address[]",
|
|
152
|
+
internalType: "address[]"
|
|
143
153
|
}, {
|
|
144
154
|
name: "account",
|
|
145
155
|
type: "address",
|
|
@@ -201,6 +211,11 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
201
211
|
internalType: "bytes"
|
|
202
212
|
}]
|
|
203
213
|
},
|
|
214
|
+
{
|
|
215
|
+
name: "redeemer",
|
|
216
|
+
type: "address",
|
|
217
|
+
internalType: "address"
|
|
218
|
+
},
|
|
204
219
|
{
|
|
205
220
|
name: "extraData",
|
|
206
221
|
type: "bytes",
|
|
@@ -249,6 +264,11 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
249
264
|
type: "uint256",
|
|
250
265
|
internalType: "uint256"
|
|
251
266
|
},
|
|
267
|
+
{
|
|
268
|
+
name: "redeemer",
|
|
269
|
+
type: "address",
|
|
270
|
+
internalType: "address"
|
|
271
|
+
},
|
|
252
272
|
{
|
|
253
273
|
name: "extraData",
|
|
254
274
|
type: "bytes",
|
|
@@ -262,9 +282,9 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
262
282
|
type: "function",
|
|
263
283
|
name: "getExternalAccountCurrentWithdrawals",
|
|
264
284
|
inputs: [{
|
|
265
|
-
name: "
|
|
266
|
-
type: "address
|
|
267
|
-
internalType: "address
|
|
285
|
+
name: "withdrawalToken",
|
|
286
|
+
type: "address",
|
|
287
|
+
internalType: "address"
|
|
268
288
|
}, {
|
|
269
289
|
name: "account",
|
|
270
290
|
type: "address",
|
|
@@ -326,6 +346,11 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
326
346
|
internalType: "bytes"
|
|
327
347
|
}]
|
|
328
348
|
},
|
|
349
|
+
{
|
|
350
|
+
name: "redeemer",
|
|
351
|
+
type: "address",
|
|
352
|
+
internalType: "address"
|
|
353
|
+
},
|
|
329
354
|
{
|
|
330
355
|
name: "extraData",
|
|
331
356
|
type: "bytes",
|
|
@@ -374,6 +399,11 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
374
399
|
type: "uint256",
|
|
375
400
|
internalType: "uint256"
|
|
376
401
|
},
|
|
402
|
+
{
|
|
403
|
+
name: "redeemer",
|
|
404
|
+
type: "address",
|
|
405
|
+
internalType: "address"
|
|
406
|
+
},
|
|
377
407
|
{
|
|
378
408
|
name: "extraData",
|
|
379
409
|
type: "bytes",
|
|
@@ -383,36 +413,6 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
383
413
|
}],
|
|
384
414
|
stateMutability: "view"
|
|
385
415
|
},
|
|
386
|
-
{
|
|
387
|
-
type: "function",
|
|
388
|
-
name: "getWithdrawalStatus",
|
|
389
|
-
inputs: [{
|
|
390
|
-
name: "redeemer",
|
|
391
|
-
type: "address",
|
|
392
|
-
internalType: "address"
|
|
393
|
-
}],
|
|
394
|
-
outputs: [{
|
|
395
|
-
name: "",
|
|
396
|
-
type: "uint8",
|
|
397
|
-
internalType: "enum WithdrawalStatus"
|
|
398
|
-
}],
|
|
399
|
-
stateMutability: "view"
|
|
400
|
-
},
|
|
401
|
-
{
|
|
402
|
-
type: "function",
|
|
403
|
-
name: "getWithdrawalStatus",
|
|
404
|
-
inputs: [{
|
|
405
|
-
name: "redeemers",
|
|
406
|
-
type: "address[]",
|
|
407
|
-
internalType: "address[]"
|
|
408
|
-
}],
|
|
409
|
-
outputs: [{
|
|
410
|
-
name: "",
|
|
411
|
-
type: "uint8[]",
|
|
412
|
-
internalType: "enum WithdrawalStatus[]"
|
|
413
|
-
}],
|
|
414
|
-
stateMutability: "view"
|
|
415
|
-
},
|
|
416
416
|
{
|
|
417
417
|
type: "function",
|
|
418
418
|
name: "getWithdrawableAssets",
|
|
@@ -559,11 +559,6 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
559
559
|
type: "address",
|
|
560
560
|
internalType: "address"
|
|
561
561
|
},
|
|
562
|
-
{
|
|
563
|
-
name: "withdrawalToken",
|
|
564
|
-
type: "address",
|
|
565
|
-
internalType: "address"
|
|
566
|
-
},
|
|
567
562
|
{
|
|
568
563
|
name: "amount",
|
|
569
564
|
type: "uint256",
|
|
@@ -644,6 +639,11 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
644
639
|
type: "address",
|
|
645
640
|
internalType: "address"
|
|
646
641
|
},
|
|
642
|
+
{
|
|
643
|
+
name: "withdrawalToken",
|
|
644
|
+
type: "address",
|
|
645
|
+
internalType: "address"
|
|
646
|
+
},
|
|
647
647
|
{
|
|
648
648
|
name: "amount",
|
|
649
649
|
type: "uint256",
|
|
@@ -710,6 +710,36 @@ const iWithdrawalCompressorV313Abi = [
|
|
|
710
710
|
}],
|
|
711
711
|
stateMutability: "view"
|
|
712
712
|
},
|
|
713
|
+
{
|
|
714
|
+
type: "function",
|
|
715
|
+
name: "getWithdrawalStatus",
|
|
716
|
+
inputs: [{
|
|
717
|
+
name: "redeemers",
|
|
718
|
+
type: "address[]",
|
|
719
|
+
internalType: "address[]"
|
|
720
|
+
}],
|
|
721
|
+
outputs: [{
|
|
722
|
+
name: "",
|
|
723
|
+
type: "uint8[]",
|
|
724
|
+
internalType: "enum WithdrawalStatus[]"
|
|
725
|
+
}],
|
|
726
|
+
stateMutability: "view"
|
|
727
|
+
},
|
|
728
|
+
{
|
|
729
|
+
type: "function",
|
|
730
|
+
name: "getWithdrawalStatus",
|
|
731
|
+
inputs: [{
|
|
732
|
+
name: "redeemer",
|
|
733
|
+
type: "address",
|
|
734
|
+
internalType: "address"
|
|
735
|
+
}],
|
|
736
|
+
outputs: [{
|
|
737
|
+
name: "",
|
|
738
|
+
type: "uint8",
|
|
739
|
+
internalType: "enum WithdrawalStatus"
|
|
740
|
+
}],
|
|
741
|
+
stateMutability: "view"
|
|
742
|
+
},
|
|
713
743
|
{
|
|
714
744
|
type: "function",
|
|
715
745
|
name: "version",
|
|
@@ -6,6 +6,85 @@ const require_dev_kycUtils = require("./kycUtils.js");
|
|
|
6
6
|
let viem = require("viem");
|
|
7
7
|
let viem_accounts = require("viem/accounts");
|
|
8
8
|
//#region src/dev/claimDSToken.ts
|
|
9
|
+
/**
|
|
10
|
+
* `COMPLIANCE_CONFIGURATION_SERVICE` id in the DS protocol service registry
|
|
11
|
+
*/
|
|
12
|
+
const COMPLIANCE_CONFIGURATION_SERVICE = 256n;
|
|
13
|
+
const iDSComplianceConfigurationServiceAbi = (0, viem.parseAbi)(["function getUSLockPeriod() external view returns (uint256)", "function getNonUSLockPeriod() external view returns (uint256)"]);
|
|
14
|
+
/**
|
|
15
|
+
* Returns issuance time that is old enough for the issued tokens to be past
|
|
16
|
+
* both US and non-US compliance lock periods, or `undefined` when the token
|
|
17
|
+
* has no compliance configuration service (e.g. MockDSToken)
|
|
18
|
+
*/
|
|
19
|
+
async function getUnlockedIssuanceTime({ anvil, token, logger }) {
|
|
20
|
+
try {
|
|
21
|
+
const complianceConfiguration = await anvil.readContract({
|
|
22
|
+
address: token,
|
|
23
|
+
abi: require_abi_rwa_iDSToken.iDSTokenAbi,
|
|
24
|
+
functionName: "getDSService",
|
|
25
|
+
args: [COMPLIANCE_CONFIGURATION_SERVICE]
|
|
26
|
+
});
|
|
27
|
+
if ((0, viem.isAddressEqual)(complianceConfiguration, viem.zeroAddress)) return;
|
|
28
|
+
const [usLockPeriod, nonUSLockPeriod] = await anvil.multicall({
|
|
29
|
+
contracts: [{
|
|
30
|
+
address: complianceConfiguration,
|
|
31
|
+
abi: iDSComplianceConfigurationServiceAbi,
|
|
32
|
+
functionName: "getUSLockPeriod"
|
|
33
|
+
}, {
|
|
34
|
+
address: complianceConfiguration,
|
|
35
|
+
abi: iDSComplianceConfigurationServiceAbi,
|
|
36
|
+
functionName: "getNonUSLockPeriod"
|
|
37
|
+
}],
|
|
38
|
+
allowFailure: false
|
|
39
|
+
});
|
|
40
|
+
const lockPeriod = usLockPeriod > nonUSLockPeriod ? usLockPeriod : nonUSLockPeriod;
|
|
41
|
+
const { timestamp } = await anvil.getBlock();
|
|
42
|
+
logger?.debug(`Lock periods: US ${usLockPeriod}, non-US ${nonUSLockPeriod} (compliance configuration service ${complianceConfiguration})`);
|
|
43
|
+
return timestamp > lockPeriod ? timestamp - lockPeriod : 0n;
|
|
44
|
+
} catch (e) {
|
|
45
|
+
logger?.debug(`Failed to get compliance lock periods: ${e}`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Issues tokens to investor via `issueTokensCustom` with issuance time that
|
|
51
|
+
* bypasses compliance lock periods, falling back to plain `issueTokens` for
|
|
52
|
+
* tokens that do not support it (e.g. MockDSToken)
|
|
53
|
+
*
|
|
54
|
+
* ACRED tokens do not have this lock, but STAC has
|
|
55
|
+
*/
|
|
56
|
+
async function issueDSTokens(props) {
|
|
57
|
+
const { anvil, account, token, investor, amount, logger } = props;
|
|
58
|
+
const issuanceTime = await getUnlockedIssuanceTime(props);
|
|
59
|
+
if (issuanceTime !== void 0) try {
|
|
60
|
+
return await require_dev_kycUtils.writeAndWait(anvil, {
|
|
61
|
+
account,
|
|
62
|
+
chain: anvil.chain,
|
|
63
|
+
address: token,
|
|
64
|
+
abi: require_abi_rwa_iDSToken.iDSTokenAbi,
|
|
65
|
+
functionName: "issueTokensCustom",
|
|
66
|
+
args: [
|
|
67
|
+
investor,
|
|
68
|
+
amount,
|
|
69
|
+
issuanceTime,
|
|
70
|
+
0n,
|
|
71
|
+
"",
|
|
72
|
+
0n
|
|
73
|
+
]
|
|
74
|
+
});
|
|
75
|
+
} catch (e) {
|
|
76
|
+
logger?.debug(`issueTokensCustom failed: ${e}`);
|
|
77
|
+
}
|
|
78
|
+
logger?.debug("Falling back to issueTokens");
|
|
79
|
+
return require_dev_kycUtils.writeAndWait(anvil, {
|
|
80
|
+
account,
|
|
81
|
+
chain: anvil.chain,
|
|
82
|
+
address: token,
|
|
83
|
+
abi: require_abi_rwa_iDSToken.iDSTokenAbi,
|
|
84
|
+
functionName: "issueTokens",
|
|
85
|
+
args: [investor, amount]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
9
88
|
async function claimDSToken(props) {
|
|
10
89
|
const { anvil, investor, adminPrivateKey, token, marketConfigurators, rwaFactories, usdAmount: usdAmountProp = "100000" } = props;
|
|
11
90
|
const account = (0, viem_accounts.privateKeyToAccount)(adminPrivateKey);
|
|
@@ -36,13 +115,13 @@ async function claimDSToken(props) {
|
|
|
36
115
|
logger
|
|
37
116
|
});
|
|
38
117
|
logger?.debug(`Issuing ${amount} tokens to ${investor}...`);
|
|
39
|
-
const mintHash = await
|
|
118
|
+
const mintHash = await issueDSTokens({
|
|
119
|
+
anvil,
|
|
40
120
|
account,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
args: [investor, amount]
|
|
121
|
+
token,
|
|
122
|
+
investor,
|
|
123
|
+
amount,
|
|
124
|
+
logger
|
|
46
125
|
});
|
|
47
126
|
logger?.debug(`Done! tx: ${mintHash}`);
|
|
48
127
|
const balance = await anvil.readContract({
|