@gearbox-protocol/sdk 13.0.0-next.23 → 13.0.0-next.25
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/sdk/accounts/AbstractCreditAccountsService.js +31 -0
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +2 -0
- package/dist/cjs/sdk/base/TokensMeta.js +3 -3
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +31 -0
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +2 -0
- package/dist/esm/sdk/base/TokensMeta.js +3 -3
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +9 -0
- package/dist/types/sdk/accounts/types.d.ts +9 -0
- package/dist/types/sdk/base/token-types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -1140,6 +1140,37 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
1140
1140
|
];
|
|
1141
1141
|
return mc;
|
|
1142
1142
|
}
|
|
1143
|
+
/**
|
|
1144
|
+
* Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
1145
|
+
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
|
|
1146
|
+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1147
|
+
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
|
|
1148
|
+
* @param creditManager - Credit manager address
|
|
1149
|
+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1150
|
+
*/
|
|
1151
|
+
async getDepositDiffCalls(amount, creditManager) {
|
|
1152
|
+
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1153
|
+
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1154
|
+
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1155
|
+
return void 0;
|
|
1156
|
+
}
|
|
1157
|
+
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1158
|
+
const adapterAddress = adapter?.address;
|
|
1159
|
+
if (!adapterAddress) {
|
|
1160
|
+
return void 0;
|
|
1161
|
+
}
|
|
1162
|
+
const mc = [
|
|
1163
|
+
{
|
|
1164
|
+
target: adapterAddress,
|
|
1165
|
+
callData: (0, import_viem.encodeFunctionData)({
|
|
1166
|
+
abi: ierc4626AdapterAbi,
|
|
1167
|
+
functionName: "depositDiff",
|
|
1168
|
+
args: [amount]
|
|
1169
|
+
})
|
|
1170
|
+
}
|
|
1171
|
+
];
|
|
1172
|
+
return mc;
|
|
1173
|
+
}
|
|
1143
1174
|
/**
|
|
1144
1175
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
1145
1176
|
*
|
|
@@ -172,11 +172,13 @@ class CreditAccountServiceV310 extends import_AbstractCreditAccountsService.Abst
|
|
|
172
172
|
creditManager: ca.creditManager,
|
|
173
173
|
creditAccount: ca
|
|
174
174
|
});
|
|
175
|
+
const wrapCalls = await this.getDepositDiffCalls(1n, ca.creditManager) ?? [];
|
|
175
176
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
176
177
|
const calls = [
|
|
177
178
|
...priceUpdates,
|
|
178
179
|
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
179
180
|
...claimPath.calls,
|
|
181
|
+
...wrapCalls,
|
|
180
182
|
...assetsToWithdraw.map(
|
|
181
183
|
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, import_math.MAX_UINT256, to)
|
|
182
184
|
)
|
|
@@ -68,7 +68,7 @@ class TokensMeta extends import_utils.AddressMap {
|
|
|
68
68
|
`extended token data not loaded for ${t.symbol} (${t.addr})`
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
|
-
return
|
|
71
|
+
return !!t.contractType?.startsWith("PHANTOM_TOKEN::");
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
74
|
* Returns true if the token is a KYC underlying token, throws if the token data is not loaded
|
|
@@ -81,7 +81,7 @@ class TokensMeta extends import_utils.AddressMap {
|
|
|
81
81
|
`extended token data not loaded for ${t.symbol} (${t.addr})`
|
|
82
82
|
);
|
|
83
83
|
}
|
|
84
|
-
return
|
|
84
|
+
return !!t.contractType?.startsWith("KYC_UNDERLYING::");
|
|
85
85
|
}
|
|
86
86
|
/**
|
|
87
87
|
* Returns true if the token is a DSToken, throws if the token data is not loaded
|
|
@@ -206,7 +206,7 @@ class TokensMeta extends import_utils.AddressMap {
|
|
|
206
206
|
`token ${meta.symbol} (${token}) is ${contractType} but serialize failed: ${serializeResp.error}`
|
|
207
207
|
);
|
|
208
208
|
}
|
|
209
|
-
} else
|
|
209
|
+
} else {
|
|
210
210
|
this.upsert(token, {
|
|
211
211
|
...meta,
|
|
212
212
|
contractType
|
|
@@ -1130,6 +1130,37 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
1130
1130
|
];
|
|
1131
1131
|
return mc;
|
|
1132
1132
|
}
|
|
1133
|
+
/**
|
|
1134
|
+
* Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
1135
|
+
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
|
|
1136
|
+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
1137
|
+
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
|
|
1138
|
+
* @param creditManager - Credit manager address
|
|
1139
|
+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
1140
|
+
*/
|
|
1141
|
+
async getDepositDiffCalls(amount, creditManager) {
|
|
1142
|
+
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
1143
|
+
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
|
|
1144
|
+
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
|
|
1145
|
+
return void 0;
|
|
1146
|
+
}
|
|
1147
|
+
const adapter = suite.creditManager.adapters.get(meta.addr);
|
|
1148
|
+
const adapterAddress = adapter?.address;
|
|
1149
|
+
if (!adapterAddress) {
|
|
1150
|
+
return void 0;
|
|
1151
|
+
}
|
|
1152
|
+
const mc = [
|
|
1153
|
+
{
|
|
1154
|
+
target: adapterAddress,
|
|
1155
|
+
callData: encodeFunctionData({
|
|
1156
|
+
abi: ierc4626AdapterAbi,
|
|
1157
|
+
functionName: "depositDiff",
|
|
1158
|
+
args: [amount]
|
|
1159
|
+
})
|
|
1160
|
+
}
|
|
1161
|
+
];
|
|
1162
|
+
return mc;
|
|
1163
|
+
}
|
|
1133
1164
|
/**
|
|
1134
1165
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
1135
1166
|
*
|
|
@@ -149,11 +149,13 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
149
149
|
creditManager: ca.creditManager,
|
|
150
150
|
creditAccount: ca
|
|
151
151
|
});
|
|
152
|
+
const wrapCalls = await this.getDepositDiffCalls(1n, ca.creditManager) ?? [];
|
|
152
153
|
const addCollateral = collateralAssets.filter((a) => a.balance > 0);
|
|
153
154
|
const calls = [
|
|
154
155
|
...priceUpdates,
|
|
155
156
|
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
|
|
156
157
|
...claimPath.calls,
|
|
158
|
+
...wrapCalls,
|
|
157
159
|
...assetsToWithdraw.map(
|
|
158
160
|
(t) => this.prepareWithdrawToken(ca.creditFacade, t.token, MAX_UINT256, to)
|
|
159
161
|
)
|
|
@@ -56,7 +56,7 @@ class TokensMeta extends AddressMap {
|
|
|
56
56
|
`extended token data not loaded for ${t.symbol} (${t.addr})`
|
|
57
57
|
);
|
|
58
58
|
}
|
|
59
|
-
return
|
|
59
|
+
return !!t.contractType?.startsWith("PHANTOM_TOKEN::");
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* Returns true if the token is a KYC underlying token, throws if the token data is not loaded
|
|
@@ -69,7 +69,7 @@ class TokensMeta extends AddressMap {
|
|
|
69
69
|
`extended token data not loaded for ${t.symbol} (${t.addr})`
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
|
-
return
|
|
72
|
+
return !!t.contractType?.startsWith("KYC_UNDERLYING::");
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
75
75
|
* Returns true if the token is a DSToken, throws if the token data is not loaded
|
|
@@ -194,7 +194,7 @@ class TokensMeta extends AddressMap {
|
|
|
194
194
|
`token ${meta.symbol} (${token}) is ${contractType} but serialize failed: ${serializeResp.error}`
|
|
195
195
|
);
|
|
196
196
|
}
|
|
197
|
-
} else
|
|
197
|
+
} else {
|
|
198
198
|
this.upsert(token, {
|
|
199
199
|
...meta,
|
|
200
200
|
contractType
|
|
@@ -238,6 +238,15 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
|
|
|
238
238
|
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
239
239
|
*/
|
|
240
240
|
getRedeemDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
|
|
241
|
+
/**
|
|
242
|
+
* Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
243
|
+
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
|
|
244
|
+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
245
|
+
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
|
|
246
|
+
* @param creditManager - Credit manager address
|
|
247
|
+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
248
|
+
*/
|
|
249
|
+
getDepositDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
|
|
241
250
|
/**
|
|
242
251
|
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
243
252
|
*
|
|
@@ -683,6 +683,15 @@ export interface ICreditAccountsService extends Construct {
|
|
|
683
683
|
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
684
684
|
*/
|
|
685
685
|
getRedeemDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
|
|
686
|
+
/**
|
|
687
|
+
* Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
|
|
688
|
+
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
|
|
689
|
+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
|
|
690
|
+
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
|
|
691
|
+
* @param creditManager - Credit manager address
|
|
692
|
+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
|
|
693
|
+
*/
|
|
694
|
+
getDepositDiffCalls(amount: bigint, creditManager: Address): Promise<Array<MultiCall> | undefined>;
|
|
686
695
|
/**
|
|
687
696
|
* Withdraws a single collateral from credit account to wallet to and updates quotas;
|
|
688
697
|
* technically can withdraw several tokens at once
|
|
@@ -8,6 +8,7 @@ export type KYCUnderlyingContractType = typeof KYC_UNDERLYING_DEFAULT | typeof K
|
|
|
8
8
|
export type PhantomTokenContractType = (typeof PHANTOM_TOKEN_CONTRACT_TYPES)[number];
|
|
9
9
|
export type SimpleTokenMeta = TokenData & {
|
|
10
10
|
isDSToken?: boolean;
|
|
11
|
+
contractType?: string;
|
|
11
12
|
};
|
|
12
13
|
export type PhantomTokenMeta = SimpleTokenMeta & {
|
|
13
14
|
contractType: PhantomTokenContractType;
|