@byzantine/vault-sdk
Version:
Byzantine Vault SDK for creating and managing vaults on Ethereum for restaking strategies
131 lines (130 loc) • 5.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.VaultTypeClient = void 0;
const ethers_1 = require("ethers");
const abis_1 = require("../../constants/abis");
const utils_1 = require("../../utils");
class VaultTypeClient {
constructor(provider) {
this.provider = provider;
}
/**
* Get the ERC20 contract instance
* @param vaultAddress The address of the vault
* @returns The ERC20 contract instance
*/
getContractWithSymABI(vaultAddress) {
return new ethers_1.ethers.Contract(vaultAddress, abis_1.SYM_ERC20_ABI, this.provider);
}
/**
* Get the ERC20 contract instance with EigenLayer ABI
* @param vaultAddress The address of the vault
* @returns The ERC20 contract instance
*/
getContractWithEigenABI(vaultAddress) {
return new ethers_1.ethers.Contract(vaultAddress, abis_1.ERC20_VAULT_ABI, this.provider);
}
/**
* Get the ERC20 contract instance with SuperVault ABI
* @param vaultAddress The address of the vault
* @returns The ERC20 contract instance
*/
getContractWithSuperABI(vaultAddress) {
return new ethers_1.ethers.Contract(vaultAddress, abis_1.SUPER_ERC20_ABI, this.provider);
}
/**
* Check if a vault is a Symbiotic vault
* @param vaultAddress The address of the vault to check
* @returns True if the vault is a Symbiotic vault, false otherwise
*/
async isSymbioticVault(vaultAddress) {
try {
const vaultContract = this.getContractWithSymABI(vaultAddress);
// Try to access the symVault property, which only exists on Symbiotic vaults
await (0, utils_1.callContractMethod)(vaultContract, "symVault");
return true;
}
catch (error) {
return false;
}
}
/**
* Check if a vault is an EigenLayer vault
* @param vaultAddress The address of the vault to check
* @returns True if the vault is an EigenLayer vault, false otherwise
*/
async isEigenVault(vaultAddress) {
try {
const vaultContract = this.getContractWithEigenABI(vaultAddress);
// Try to access delegatedTo which only exists on EigenLayer vaults
await (0, utils_1.callContractMethod)(vaultContract, "delegatedTo");
return true;
}
catch (error) {
// If that failed, try another EigenLayer-specific method
try {
const vaultContract = this.getContractWithEigenABI(vaultAddress);
await (0, utils_1.callContractMethod)(vaultContract, "eigenStrategy");
return true;
}
catch (innerError) {
return false;
}
}
}
/**
* Check if a vault is a SuperVault
* SuperVaults may have properties of both Symbiotic and EigenLayer vaults
* @param vaultAddress The address of the vault to check
* @returns True if the vault is a SuperVault, false otherwise
*/
async isSupervault(vaultAddress) {
try {
const vaultContract = this.getContractWithSuperABI(vaultAddress);
// Try multiple methods to determine if it's a SuperVault
try {
// First try getDistributionRatio
const distributionRatio = await (0, utils_1.callContractMethod)(vaultContract, "getDistributionRatio");
return true;
}
catch (methodError) {
// If that fails, try with getUnderlyingVaults
try {
const underlyingVaults = await (0, utils_1.callContractMethod)(vaultContract, "getUnderlyingVaults");
return Array.isArray(underlyingVaults) && underlyingVaults.length > 0;
}
catch (underlyingError) {
// Try a third method - symRatio
try {
await (0, utils_1.callContractMethod)(vaultContract, "symRatio");
return true;
}
catch (ratioError) {
return false;
}
}
}
}
catch (error) {
return false;
}
}
/**
* Get the type of vault
* @param vaultAddress The address of the vault to check
* @returns The type of the vault as defined in RestakingProtocol
*/
async getVaultType(vaultAddress) {
const isSymbiotic = await this.isSymbioticVault(vaultAddress);
if (isSymbiotic)
return "Symbiotic";
const isEigen = await this.isEigenVault(vaultAddress);
if (isEigen)
return "EigenLayer";
const isSuper = await this.isSupervault(vaultAddress);
if (isSuper)
return "SuperVault";
return undefined; // Default fallback, though this is unexpected
}
}
exports.VaultTypeClient = VaultTypeClient;