@@ -1374,6 +1374,83 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
13741374 return resp ;
13751375 }
13761376
1377+ /**
1378+ * Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
1379+ * Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
1380+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
1381+ * @param amount - Number of vault shares (adapter tokens) to redeem
1382+ * @param creditManager - Credit manager address
1383+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
1384+ */
1385+ public async getKYCUnwrapCalls (
1386+ amount : bigint ,
1387+ creditManager : Address ,
1388+ ) : Promise < Array < MultiCall > | undefined > {
1389+ const suite = this . sdk . marketRegister . findCreditManager ( creditManager ) ;
1390+ const meta = this . sdk . tokensMeta . mustGet ( suite . underlying ) ;
1391+ if ( ! this . sdk . tokensMeta . isKYCUnderlying ( meta ) ) {
1392+ return undefined ;
1393+ }
1394+
1395+ const adapter = suite . creditManager . adapters . get ( meta . addr ) ;
1396+ const adapterAddress = adapter ?. address ;
1397+
1398+ if ( ! adapterAddress ) {
1399+ return undefined ;
1400+ }
1401+
1402+ const mc : Array < MultiCall > = [
1403+ {
1404+ target : adapterAddress ,
1405+ callData : encodeFunctionData ( {
1406+ abi : ierc4626AdapterAbi ,
1407+ functionName : "redeem" ,
1408+ args : [ amount , ADDRESS_0X0 , ADDRESS_0X0 ] ,
1409+ } ) ,
1410+ } ,
1411+ ] ;
1412+
1413+ return mc ;
1414+ }
1415+ /**
1416+ * Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
1417+ * Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
1418+ * Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
1419+ * @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
1420+ * @param creditManager - Credit manager address
1421+ * @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
1422+ */
1423+ public async getKYCWrapCalls (
1424+ amount : bigint ,
1425+ creditManager : Address ,
1426+ ) : Promise < Array < MultiCall > | undefined > {
1427+ const suite = this . sdk . marketRegister . findCreditManager ( creditManager ) ;
1428+ const meta = this . sdk . tokensMeta . mustGet ( suite . underlying ) ;
1429+ if ( ! this . sdk . tokensMeta . isKYCUnderlying ( meta ) ) {
1430+ return undefined ;
1431+ }
1432+
1433+ const adapter = suite . creditManager . adapters . get ( meta . addr ) ;
1434+ const adapterAddress = adapter ?. address ;
1435+
1436+ if ( ! adapterAddress ) {
1437+ return undefined ;
1438+ }
1439+
1440+ const mc : Array < MultiCall > = [
1441+ {
1442+ target : adapterAddress ,
1443+ callData : encodeFunctionData ( {
1444+ abi : ierc4626AdapterAbi ,
1445+ functionName : "deposit" ,
1446+ args : [ amount , ADDRESS_0X0 ] ,
1447+ } ) ,
1448+ } ,
1449+ ] ;
1450+
1451+ return mc ;
1452+ }
1453+
13771454 /**
13781455 * Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
13791456 *
@@ -1838,3 +1915,27 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
18381915 return caLists ;
18391916 }
18401917}
1918+
1919+ const ierc4626AdapterAbi = [
1920+ {
1921+ inputs : [
1922+ { name : "assets" , type : "uint256" , internalType : "uint256" } ,
1923+ { name : "receiver" , type : "address" , internalType : "address" } ,
1924+ ] ,
1925+ name : "deposit" ,
1926+ outputs : [ { name : "useSafePrices" , type : "bool" , internalType : "bool" } ] ,
1927+ stateMutability : "nonpayable" ,
1928+ type : "function" ,
1929+ } ,
1930+ {
1931+ inputs : [
1932+ { name : "shares" , type : "uint256" , internalType : "uint256" } ,
1933+ { name : "receiver" , type : "address" , internalType : "address" } ,
1934+ { name : "owner" , type : "address" , internalType : "address" } ,
1935+ ] ,
1936+ name : "redeem" ,
1937+ outputs : [ { name : "useSafePrices" , type : "bool" , internalType : "bool" } ] ,
1938+ stateMutability : "nonpayable" ,
1939+ type : "function" ,
1940+ } ,
1941+ ] as const ;
0 commit comments