Overview
Morpho Vaults are smart contracts that allow users to deposit assets into yield-generating vaults built on top of Morpho’s lending protocol. We’ll walk through the steps of using Turnkey to sign some common transactions to Morpho’s Steakhouse USDC Vault on Base Mainnet. The flow is also going to show Turnkey’s policy engine in action by restricting the signing operations only to the specific Morpho contracts. The working example can be found here.Getting started
The first step is to set up your Turnkey organization and account. By following the Quickstart guide, you should have:- A root user with a public/private API key pair within the Turnkey parent organization
- An organization ID
Setting up the policy for the non-root user
Now, we want to use the non-root user for signing transactions to Morpho and restrict it to only be able to interact with the USDC and Morpho vault smart contracts. We’ll define a new API client that would use the organization root user to create the required policy:Set up the Turnkey signer
We’ll be using@turnkey/viem
to create a Turnkey custom signer which implements the signing APIs expected by the viem
client. Notice that the Turnkey API client is going to use the non-root user API key now as using a root user will bypass the policy engine evaluation.
Approve the vault to spend USDC and deposit USDC into the vault
Check user share balance and vault data
In order to see how much the user can withdraw we can call thebalanceOf
function if the Vault contract.
Withdraw from the vault or redeem the whole amount
Call thewithdraw
function if you want a specific amount:
redeem
for the full shares amount: