Skip to content

Commit

Permalink
feat: add api
Browse files Browse the repository at this point in the history
  • Loading branch information
NahWe authored Aug 10, 2024
1 parent 83b8faf commit 2b017f1
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
47 changes: 47 additions & 0 deletions frontend/api/createVault.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { createPublicClient, createWalletClient, http } from 'viem';
import { getContract } from 'viem';
import { ABI, CONTRACT_ADDRESS } from '../../vaultConfig';


const publicClient = createPublicClient({
transport: http(),
chain: {
id: 1,
name: 'Ethereum',
},
});

const walletClient = createWalletClient({
transport: http(),
chain: {
id: 1,
name: 'Ethereum',
},
privateKey: process.env.PRIVATE_KEY,
});


const contract = getContract({
address: CONTRACT_ADDRESS,
abi: ABI,
client: walletClient,
})

export default async function handler(req, res) {
const { method, params } = req.body;

try {
let result;

switch (method) {
case 'createERC4626':
const { asset, minHealthFactor, maxHealthFactor } = params;
result = await factoryContract.createERC4626(asset, minHealthFactor, maxHealthFactor);
break;
}

res.status(200).json({ success: true, result });
} catch (error) {
res.status(500).json({ success: false, error: error.message });
}
}
57 changes: 57 additions & 0 deletions frontend/api/vaultConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
export const CONTRACT_ADDRESS = "0x2D48adbf60cb643333fa7e58c20b8908Ee451e3a";

export const ABI = [
{
"inputs": [
{ "internalType": "contract IPool", "name": "lendingPool_", "type": "address" },
{ "internalType": "contract IRewardsController", "name": "rewardsController_", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"inputs": [],
"name": "AaveV3ERC4626Factory__ATokenNonexistent",
"type": "error"
},
{
"inputs": [
{ "internalType": "contract ERC20", "name": "asset", "type": "address" },
{ "internalType": "uint256", "name": "minHealthFactor_", "type": "uint256" },
{ "internalType": "uint256", "name": "maxHealthFactor_", "type": "uint256" }
],
"name": "createERC4626",
"outputs": [
{ "internalType": "contract ERC4626", "name": "vault", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "lendingPool",
"outputs": [
{ "internalType": "contract IPool", "name": "", "type": "address" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "rewardRecipient",
"outputs": [
{ "internalType": "address", "name": "", "type": "address" }
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "rewardsController",
"outputs": [
{ "internalType": "contract IRewardsController", "name": "", "type": "address" }
],
"stateMutability": "view",
"type": "function"
}
];

0 comments on commit 2b017f1

Please sign in to comment.