This is a detailed tutorial on how to make a deposit to one of the Morpho’s vaults through the DeFi API. To learn more about the flow in general, refer to the Getting Started section.
- Get the schema with the step list for obtaining approval.
- Create the permission request for the permit2 smart contract.
- Get the schema with the step list for initiating the deposit.
- Create the permission request for the Morpho bundler.
- Create the permission request for the P2P.ORG proxy contract.
- Prepare the final deposit transaction.
- Broadcast the deposit transaction to the Base network.
1. Get schema for approval
Before depositing assets into the vault, first grant permissions to the smart contracts involved in the integration to manage tokens. To check the action schema and retrieve a list of steps required for approval, send a GET request to /api/defi/v1/transactions/schema. Example request (forbase chain and Steakhouse USDC strategy):
action— operation type; in this caseapprovePermit2.chain— blockchain network, e.g.,base.protocol— integration name, e.g.,morpho.strategy— vault name, e.g.,Steakhouse USDC.x-client-hash— unique identifier of the user or merchant participating in the integration; obtained with the authentication token.
-
action— operation type; in this caseapprovePermit2. -
steps— schema with the list of steps describing which transactions you have to construct using the Craft Transaction Step endpoint.-
index— step number in the execution order. -
name— transaction type corresponding to thestepNamerequest parameter of the Craft Transaction Step endpoint. -
description— detailed information on the step purpose. -
inputs— list of request parameters required to construct a transaction, e.g., wallet address, amount of tokens, etc. It may include transactions that require a signature as well.key— parameter name.type— parameter object format.description— detailed information on the parameter.required— boolean flag indicating if this parameter is necessary for the request.
-
outputs— list of fields expected in the transaction response.key— raw transaction payload ready for signing, eitherencodedorjson(optional).type— transaction payload format.description— detailed information on the payload contents.
-
groupID— identifier of the group to which this step belongs. -
canExecuteInParallel— boolean flag indicating if it is possible to perform this step asynchronously. By executing in parallel, you can initiate the construction of multiple transactions at the same time.true— step can be performed asynchronously.false— step can only be performed synchronously.
-
isUnsignedTransaction— boolean flag indicating if the result of the step is a transaction that must be signed and broadcasted.
-
-
stepGroups— groups of steps that can be executed in parallel; currently is not operational. -
meta— API request attributes:time— request execution time in ms.requestId— unique identifier of the request.
Approval action summaryIn this schema, the
steps response array includes one step called finalPermit2AllowanceTransaction.It means that to approve token management, you have to prepare only one transaction and then sign and broadcast it.2. Create permission request for permit2 contract
-
To allow Morpho’s Permit2 contract to perform any operations with the specified amount of tokens, send a POST request to /api/defi/v1/transactions/steps/craft.
Example request (for
basechain andSteakhouse USDCstrategy):-
action— operation type. -
chain— blockchain network. -
protocol— integration name. -
strategy— vault name. -
userAddress— user wallet address. -
options.executeMode— DeFi API processing mode. The recommended value for each step can be found in the schema’scanExecuteInParallelfield.sync— synchronous; default for some networks so that the blockchain does not reverse the block in which the transaction is included. In this mode, before continuing with other steps, the user has to wait until the API operation is fully completed and the transaction is returned.async— asynchronous. In this mode, after sending the request, the user can continue with other steps according to the schema and periodically check the request status with the Get Step Crafting Status endpoint.
-
stepName— name of the transaction to construct. In this case, it isfinalPermit2AllowanceTransaction. -
payload— transaction data:amount— amount of tokens the permit2 contract is allowed to interact with. You can specify any amount, but not less than the deposit amount.asset— token denomination, e.g.,USDC.
-
operationId— unique identifier of the transaction. -
chain— blockchain network. -
action— operation type. -
status— current transaction status:AWAITING_CRAFT,IN_PROGRESS,READY_FOR_SIGNorDONE. -
protocol— integration name. -
strategy— vault name. -
userAddress— user wallet address. -
stepList— list of fields with the step results obtained according to the schema:index— step number in the execution order.type— object format.name— name of the transaction to construct. In this case, it isfinalPermit2AllowanceTransaction.description— detailed information on the step purpose.payload— raw transaction object ready for signing represented in two formats:encodedandjson(optional).verifierMeta— data object received from P2P.ORG’s verifier module.signature— signature provided by the verifier module, which confirms that the transaction was crafted and then cryptographically verified by P2P.ORG.
-
payload— final transaction payload represented either inencodedorjson(optional) format. -
verifierMeta— final transaction data object received from the verifier module. -
createdAt— timestamp of the transaction creation in the ISO 8601 format. -
updatedAt— timestamp of the transaction update in the ISO 8601 format. -
meta— API request attributes:time— request execution time in ms.requestId— unique identifier of the request.
-
-
Sign the raw
jsonorencodedobject in theresult.payloadfield. - Broadcast it to the network by sending a POST request to /api/defi/v1/transactions/steps/broadcast. By broadcasting this transaction, you’re granting permission to the permit2 smart contract to interact with the specified amount of tokens at your wallet address.
3. Get schema for deposit
The deposit action may require a various number of steps depending on the target chain and vault. To retrieve a list of steps for the preferred strategy, send a GET request to /api/defi/v1/transactions/schema. Example request (forbase chain and Steakhouse USDC strategy):
action— operation type; in this casedeposit.chain— blockchain network.protocol— integration name.strategy— vault name.x-client-hash— unique identifier of the user or merchant participating in the integration; obtained with the authentication token.
-
action— operation type. -
steps— schema with the list of steps describing which transactions you have to construct using the Craft Transaction Step endpoint.-
index— step number in the execution order. -
name— transaction type corresponding to thestepNamerequest parameter of the Craft Transaction Step endpoint. -
description— detailed information on the step purpose. -
inputs— list of request parameters required to construct a transaction, e.g., wallet address, amount of tokens, etc. It may include transactions that require a signature as well.-
key— parameter name. -
type— parameter object format. -
description— detailed information on the parameter. -
required— boolean flag indicating if this parameter is necessary for the request. -
requiresSignature— boolean flag indicating if the parameter is a transaction itself that must be signed. -
signatureSource— detailed information on the step at which the transaction requiring a signature was received:stepIndex— step number.stepName— transaction type.outputKey— resulting object format.
-
-
outputs— list of fields expected in the transaction response for the specific step.key— raw transaction payload ready for signing.type— object format, which is eitherencodedorjson(optional).description— detailed information on the payload contents.
-
groupID— identifier of the group to which this step belongs. -
canExecuteInParallel— boolean flag indicating if it is possible to perform this step asynchronously. By executing in parallel, you can initiate the construction of multiple transactions at the same time.true— step can be performed asynchronously.false— step can only be performed synchronously.
-
inputReferences— references tokeyfrom previous steps, either from the request or response.stepIndex— step number.outputKey— name of the specifickeyparameter from the step output.
-
-
stepGroups— groups of steps that can be executed in parallel; currently is not operational. -
meta— API request attributes:time— request execution time in ms.requestId— unique identifier of the request.
Deposit action summaryIn this schema, the
steps response array includes three steps ordered from 0 to 2. It means that the process of depositing assets to a vault requires three actions:- Allow transferring funds from the user wallet to the P2P proxy contract address.
- Allow transferring funds from the P2P proxy contract address to the vault address.
- Combine the two previous transactions to obtain the raw deposit transaction.
canExecuteInParallel parameter is false.4. Create permission request for the vault
-
Construct the first intermediate
permit2SingleDetailsForMorphotransaction according to the schema. To allow the Morpho bundler to withdraw assets from the P2P proxy address to the vault address, send a POST request to /api/defi/v1/transactions/steps/craft. Example request (forbasechain andSteakhouse USDCstrategy):-
chain— blockchain network. -
action— operation type. -
protocol— integration name. -
strategy— vault name. -
userAddress— user wallet address. -
options.executeMode— DeFi API processing mode. The recommended value for each step can be found in the schema’scanExecuteInParallelfield. -
stepName— step name corresponding to thenameresponse parameter of the Get Transaction Step Schema endpoint. In this case, it ispermit2SingleDetailsForMorpho. -
payload— transaction data:amount— amount of tokens to deposit.asset— token denomination, e.g.,USDC.
-
operationId— unique identifier of the transaction; required for the next steps. -
chain— blockchain network. -
action— operation type. -
status— current transaction status:AWAITING_CRAFT,IN_PROGRESS,READY_FOR_SIGNorDONE. -
protocol— integration name. -
strategy— vault name. -
userAddress— user wallet address. -
stepList— list of fields with the step results obtained according to the schema.For schemes with multiple steps: if a step has not been performed yet, the field will have
null. In this example, the response contains data for the step 0 only.index— step number in the execution order.type— object format.name— step name corresponding to thenameresponse field of the Get Transaction Step Schema endpoint.description— detailed information on the step purpose.payload— raw transaction object ready for signing represented in two formats:encodedandjson(optional).verifierMeta— data object received from P2P.ORG’s verifier module.signature— signature provided by the verifier module, which confirms that the transaction was crafted and then cryptographically verified by P2P.ORG.
-
payload— final transaction object.nulluntil there are schema steps yet to be performed. -
verifierMeta— final transaction data object received from the verifier module.nulluntil there are schema steps yet to be performed. -
createdAt— timestamp of the transaction creation in the ISO 8601 format. -
updatedAt— timestamp of the transaction update in the ISO 8601 format. -
meta— API request attributes:time— request execution time in ms.requestId— unique identifier of the request.
-
-
Sign the intermediate
jsonorencodedtransaction object from the step 0payloadfield.
5. Create permission request for P2P.ORG smart contract
-
Construct the second
permit2SingleDetailsForP2pProxyintermediate transaction according to the schema. To allow a P2P proxy contract to withdraw assets from your wallet address, send a POST request to /api/defi/v1/transactions/steps/craft. Mind specifying the correctstepNameaccording to the scheme’s step order as well as theoperationIDof the previous transaction. Example request (forbasechain andSteakhouse USDCstrategy):-
chain— blockchain network. -
action— operation type. -
protocol— integration name. -
strategy— vault name. -
userAddress— user wallet address. -
options.executeMode— DeFi API request processing mode. The recommended value for each step can be found in the schema’scanExecuteInParallelfield. -
stepName— step name corresponding to thenameresponse parameter of the Get Transaction Step Schema endpoint. In this case, it ispermit2SingleDetailsForP2pProxy. -
payload— transaction data:amount— amount of tokens to deposit.asset— token denomination, e.g.,USDC.operationId— unique identifier of thepermit2SingleDetailsForMorphotransaction.
-
operationId— unique identifier of thepermit2SingleDetailsForMorphotransaction. -
chain— blockchain network. -
action— operation type. -
status— current transaction status:AWAITING_CRAFT,IN_PROGRESS,READY_FOR_SIGNorDONE. -
protocol— integration name. -
strategy— vault name. -
userAddress— user wallet address. -
stepList— list of fields with the step results obtained according to the schema.For schemes with multiple steps: if a step has not been performed yet, the field will have
null. In this example, the response contains data for steps 0 and 1.index— step number in the execution order.type— parameter object format.name— step name corresponding to thenameresponse field of the Get Transaction Step Schema endpoint.description— detailed information on the step purpose.payload— raw transaction object ready for signing represented in two formats:encodedandjson(optional).verifierMeta— data object received from P2P.ORG’s verifier module.signature— signature provided by the verifier module, which confirms that the transaction was crafted and then cryptographically verified by P2P.ORG.
-
payload— final transaction object.nulluntil there are schema steps yet to be performed. -
verifierMeta— final transaction data object received from the verifier module.nulluntil there are schema steps yet to be performed. -
createdAt— timestamp of the transaction creation in the ISO 8601 format. -
updatedAt— timestamp of the transaction update in the ISO 8601 format. -
meta— API request attributes:time— request execution time in ms.requestId— request identifier; used as a correlating ID in logs.
-
-
Sign the intermediate
jsonorencodedtransaction object from the step 1payloadfield.
6. Prepare final deposit transaction
Construct the thirdfinalDepositTransaction transaction according to the schema.
To prepare the final deposit transaction, send a POST request to /api/defi/v1/transactions/steps/craft. Mind specifying the correct stepName according to the scheme’s step order and the operationID from the step 0.
Example request (for base chain and Steakhouse USDC strategy):
-
chain— blockchain network. -
action— operation type. -
protocol— integration name. -
strategy— vault name. -
userAddress— user wallet address. -
options.executeMode— DeFi API request processing mode. The recommended value for each step can be found in the schema’scanExecuteInParallelfield. -
stepName— step name corresponding to thenameresponse parameter of the Get Transaction Step Schema endpoint. In this case, it isfinalDepositTransaction. -
payload— transaction data:amount— amount of tokens to deposit.asset— token denomination, e.g.,USDC.operationId— unique identifier of thepermit2SingleDetailsForMorphotransaction.permit2SignatureForMorpho— signed transaction obtained at step 0.permit2SignatureForP2pProxy— signed transaction obtained at step 1.
-
operationId— unique identifier of thepermit2SingleDetailsForMorphotransaction. -
chain— blockchain network. -
action— operation type. -
status— current transaction status:AWAITING_CRAFT,IN_PROGRESS,READY_FOR_SIGNorDONE. -
protocol— integration name. -
strategy— vault name. -
userAddress— user wallet address. -
stepList— list of fields with the step results obtained according to the schema.index— step number in the execution order.type— parameter object format.name— step name corresponding to thenameresponse field of the Get Transaction Step Schema endpoint.description— detailed information on the step purpose.payload— raw transaction object ready for signing represented in two formats:encodedandjson(optional).verifierMeta— data object received from P2P.ORG’s verifier module.signature— signature provided by the verifier module, which confirms that the transaction was crafted and then cryptographically verified by P2P.ORG.
-
payload— final deposit transaction payload represented either inencodedan optionaljsonformat. -
verifierMeta— final transaction data object received from the verifier module. -
createdAt— timestamp of the transaction creation in the ISO 8601 format. -
updatedAt— timestamp of the transaction update in the ISO 8601 format. -
meta— API request attributes:time— request execution time in ms.requestId— request identifier; used as a correlating ID in logs.
7. Sign and broadcast final deposit transaction
The final deposit transaction now contains all thepayload objects from the previous intermediate transactions.
-
Sign the
jsonorencodedtransaction object from theresult.payloadfield. - Broadcast it to the network by sending a POST request to /api/defi/v1/transactions/steps/broadcast. By broadcasting this transaction, you’re making the deposit to the Steakhouse USDC vault on the Base blockchain.