Skip to content

Commit a067034

Browse files
committed
fix: add kyc calls generation
1 parent 72d6805 commit a067034

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

src/sdk/accounts/AbstractCreditAccountsService.ts

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/sdk/accounts/types.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,32 @@ export interface ICreditAccountsService extends Construct {
810810
options: PriceUpdatesOptions,
811811
): Promise<Array<MultiCall>>;
812812

813+
/**
814+
* Returns multicall entries to redeem (unwrap) KYC ERC-4626 vault shares into underlying for the given credit manager.
815+
* Used when withdrawing debt from a KYC market: redeems adapter vault shares so the underlying can be withdrawn.
816+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
817+
* @param amount - Number of vault shares (adapter tokens) to redeem
818+
* @param creditManager - Credit manager address
819+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
820+
*/
821+
getKYCUnwrapCalls(
822+
amount: bigint,
823+
creditManager: Address,
824+
): Promise<Array<MultiCall> | undefined>;
825+
826+
/**
827+
* Returns multicall entries to deposit (wrap) underlying into KYC ERC-4626 vault shares for the given credit manager.
828+
* Used when adding debt on a KYC market: deposits underlying into the adapter vault so shares are minted on the account.
829+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
830+
* @param amount - Amount of underlying assets to deposit into the vault (in underlying decimals)
831+
* @param creditManager - Credit manager address
832+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
833+
*/
834+
getKYCWrapCalls(
835+
amount: bigint,
836+
creditManager: Address,
837+
): Promise<Array<MultiCall> | undefined>;
838+
813839
/**
814840
* Withdraws a single collateral from credit account to wallet to and updates quotas;
815841
* technically can withdraw several tokens at once

0 commit comments

Comments
 (0)