You can deposit funds from any network supported by MAAT Vaults. The deposit process is the same across all networks, ensuring convenience and uniformity of use.
1. How to deposit
You need to call the deposit function to deposit the funds. This function deposits a specified amount of assets into the contract and assigns the corresponding shares to the receiver.
_receiver: The address that will receive the corresponding shares.
Example Usage with Ethers.js
import { Contract, ethers } from 'ethers'
import MAAT_ABI from 'our package'
const ERC20_ABI = [
{
type: 'function',
name: 'approve',
inputs: [
{ name: 'spender', type: 'address', internalType: 'address' },
{ name: 'value', type: 'uint256', internalType: 'uint256' },
],
outputs: [{ name: '', type: 'bool', internalType: 'bool' }],
stateMutability: 'nonpayable',
},
]
async function deposit(
maatVaultAddress: string,
amount: bigint,
tokenAddress: string,
) {
// create provider wallet and contract instances
const provider = new ethers.JsonRpcProvider('RPC_URL')
const wallet = new ethers.Wallet('PRIVATE_KEY', provider)
const maatVaultContract = new Contract(maatVaultAddress, MAAT_ABI, wallet)
const tokenContract = new Contract(tokenAddress, ERC20_ABI, wallet)
// approve MAAT to spend token
const approveTx = await tokenContract.approve(maatVaultAddress, amount)
// wait for approval to be confirmed
await approveTx.wait()
// deposit token into MAAT
await maatVaultContract.deposit(tokenAddress, amount)
}
Example Usage with Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
interface IERC20 {
function approve(address spender, uint amount) external returns (bool);
}
contract Example {
///@notice Deposit tokens into Maat Vault
///@dev Explain to a developer any extra details
///@param maatVault Address of the Maat Vault
///@param token Address of the token to deposit
///@param amount Amount of tokens to deposit
///@param receiver Address of the shares receiver
///@return Amount of shares minted to the receiver
function deposit(
address maatVault,
address token,
uint amount,
address receiver
) external returns (uint) {
// approve maatVault to spend token
IERC20(token).approve(maatVault, amount);
// deposit
uint shares = IMaatVaultV1(maatVault).deposit(amount, receiver);
// amount of shares minted
return shares;
}
}