diff --git a/.changeset/spotty-worms-matter.md b/.changeset/spotty-worms-matter.md new file mode 100644 index 00000000..b1ef6434 --- /dev/null +++ b/.changeset/spotty-worms-matter.md @@ -0,0 +1,5 @@ +--- +"@enzymefinance/sdk": patch +--- + +Deposit transactions for backend diff --git a/packages/sdk/src/Deposit.ts b/packages/sdk/src/Deposit.ts index 68a5de1b..7d1b6cba 100644 --- a/packages/sdk/src/Deposit.ts +++ b/packages/sdk/src/Deposit.ts @@ -4,12 +4,10 @@ import { Viem } from "@enzymefinance/sdk/Utils"; import { Assertion } from "@enzymefinance/sdk/Utils"; import { type Address, type Hex, type PublicClient } from "viem"; -/** - * Get the shares action timelock. - * - * @param client The public client to use to read the contract. - * @returns The shares action timelock in seconds. - */ +//-------------------------------------------------------------------------------------------- +// DEPOSIT +//-------------------------------------------------------------------------------------------- + export function getSharesActionTimelock( client: PublicClient, args: Viem.ContractCallParameters<{ @@ -42,8 +40,8 @@ export async function getExpectedSharesForDeposit( client: PublicClient, args: Viem.ContractCallParameters<{ comptrollerProxy: Address; - depositor: Address; amount: bigint; + depositor: Address; }>, ) { const { result } = await Viem.simulateContract(client, args, { @@ -57,19 +55,74 @@ export async function getExpectedSharesForDeposit( return result; } -export async function getExpectedSharesForNativeTokenDeposit( - client: PublicClient, +export async function deposit( args: Viem.ContractCallParameters<{ - depositWrapper: Address; comptrollerProxy: Address; - minSharesQuantity: bigint; - exchange: Address; - exchangeApproveTarget: Address; - exchangeData: Hex; - minInvestmentAmount: bigint; - depositor: Address; amount: bigint; + depositor: Address; + minSharesQuantity: bigint; }>, +) { + return new Viem.PopulatedTransaction({ + abi: Abis.IComptrollerLib, + functionName: "buyShares", + address: args.comptrollerProxy, + args: [args.amount, args.minSharesQuantity], + }); +} + +//-------------------------------------------------------------------------------------------- +// REDEMPTION +//-------------------------------------------------------------------------------------------- + +export async function getSpecificAssetsRedemptionExpectedAmounts( + client: PublicClient, + args: Viem.ContractCallParameters<{ + signer: Address; + recipient: Address; + sharesQuantity: bigint; + payoutAssets: Address[]; + payoutPercentages: bigint[]; + }>, +) { + const { result: payoutAmounts } = await Viem.simulateContract(client, args, { + abi: Abis.IComptrollerLib, + functionName: "redeemSharesForSpecificAssets", + address: args.signer, + args: [args.recipient, args.sharesQuantity, args.payoutAssets, args.payoutPercentages], + }); + + const output: Record
= {}; + + for (let i = 0; i < args.payoutAssets.length; i++) { + const payoutAsset = args.payoutAssets[i]; + const payoutAmount = payoutAmounts[i]; + Assertion.invariant(payoutAmount !== undefined, "Expected payout amount to be defined."); + Assertion.invariant(payoutAsset !== undefined, "Expected payout asset to be defined."); + + output[payoutAsset] = payoutAmount; + } + + return output; +} + +//-------------------------------------------------------------------------------------------- +// DEPOSIT WRAPPER +//-------------------------------------------------------------------------------------------- + +interface NativeDepositArgs { + depositWrapper: Address; + comptrollerProxy: Address; + exchange: Address; + exchangeApproveTarget: Address; + exchangeData: Hex; + minInvestmentAmount: bigint; + amount: bigint; +} + +export async function getExpectedSharesForNativeTokenDeposit( + client: PublicClient, + args: Viem.ContractCallParameters