@byzantine/vault-sdk
Version:
Byzantine Vault SDK for creating and managing vaults on Ethereum for restaking strategies
164 lines (163 loc) • 6.45 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SymbioticClient = void 0;
const VaultType_1 = require("./VaultType");
const utils_1 = require("../../utils");
const ContractProvider_1 = require("../../utils/ContractProvider");
class SymbioticClient {
constructor(provider, signer) {
this.provider = provider;
this.signer = signer;
this.contractProvider = new ContractProvider_1.ContractProvider(provider, signer);
this.vaultTypeClient = new VaultType_1.VaultTypeClient(provider);
}
/**
* Get the Symbiotic Vault contract instance
* @param vaultAddress The address of the Symbiotic vault or SuperVault
* @returns The Vault contract instance
*/
async getSymVaultContract(vaultAddress) {
return await this.contractProvider.getSymVaultContract(vaultAddress);
}
/**
* Get the sym vault address of a Symbiotic vault
* @param vaultAddress The address of the vault
* @returns The sym vault address
*/
async getSymVaultAddress(vaultAddress) {
return await this.contractProvider.getSymVaultAddress(vaultAddress);
}
/**
* Clear the cache for a specific vault or all vaults
* @param vaultAddress Optional address of the vault to clear from cache
*/
clearCache(vaultAddress) {
this.contractProvider.clearCache(vaultAddress);
}
/**
* Get the epoch at a specific timestamp for a Symbiotic vault
* @param vaultAddress The address of the vault
* @param timestamp The timestamp to check
* @returns The epoch number
*/
async getEpochAt(vaultAddress, timestamp) {
const symVaultContract = await this.getSymVaultContract(vaultAddress);
return await (0, utils_1.callContractMethod)(symVaultContract, "epochAt", timestamp);
}
/**
* Get the epoch duration for a Symbiotic vault
* @param vaultAddress The address of the vault
* @returns The epoch duration
*/
async getEpochDuration(vaultAddress) {
const symVaultContract = await this.getSymVaultContract(vaultAddress);
return await (0, utils_1.callContractMethod)(symVaultContract, "epochDuration");
}
/**
* Get the current epoch for a Symbiotic vault
* @param vaultAddress The address of the vault
* @returns The current epoch number
*/
async getCurrentEpoch(vaultAddress) {
const symVaultContract = await this.getSymVaultContract(vaultAddress);
const epoch = await (0, utils_1.callContractMethod)(symVaultContract, "currentEpoch");
return Number(epoch);
}
/**
* Get the start timestamp of the current epoch for a Symbiotic vault
* @param vaultAddress The address of the vault
* @returns The start timestamp of the current epoch
*/
async getCurrentEpochStart(vaultAddress) {
const symVaultContract = await this.getSymVaultContract(vaultAddress);
return await (0, utils_1.callContractMethod)(symVaultContract, "currentEpochStart");
}
/**
* Get the start timestamp of the previous epoch for a Symbiotic vault
* @param vaultAddress The address of the vault
* @returns The start timestamp of the previous epoch
*/
async getPreviousEpochStart(vaultAddress) {
const symVaultContract = await this.getSymVaultContract(vaultAddress);
return await (0, utils_1.callContractMethod)(symVaultContract, "previousEpochStart");
}
/**
* Get the start timestamp of the next epoch for a Symbiotic vault
* @param vaultAddress The address of the vault
* @returns The start timestamp of the next epoch
*/
async getNextEpochStart(vaultAddress) {
const symVaultContract = await this.getSymVaultContract(vaultAddress);
return await (0, utils_1.callContractMethod)(symVaultContract, "nextEpochStart");
}
/**
* Get the Delegator contract instance
* @param vaultAddress The address of the vault
* @returns The Delegator contract instance
*/
async getDelegatorContract(vaultAddress) {
return await this.contractProvider.getDelegatorContract(vaultAddress);
}
/**
* Get the delegator address for a vault
* @param vaultAddress The address of the vault
* @returns The delegator address
*/
async getDelegatorAddress(vaultAddress) {
return await this.contractProvider.getDelegatorAddress(vaultAddress);
}
/**
* Get the slasher address for a Symbiotic vault
* @param vaultAddress The address of the vault
* @returns The slasher address
*/
async getSlasherAddress(vaultAddress) {
return await this.contractProvider.getSlasherAddress(vaultAddress);
}
/**
* Get the delegator type for a Symbiotic vault
* @param vaultAddress The address of the vault
* @returns The delegator type
*/
async getDelegatorType(vaultAddress) {
const delegatorContract = await this.getDelegatorContract(vaultAddress);
return await (0, utils_1.callContractMethod)(delegatorContract, "TYPE");
}
/**
* Get the burner address for a vault
* @param vaultAddress The address of the vault
* @returns The burner address
*/
async getBurnerAddress(vaultAddress) {
return await this.contractProvider.getBurnerAddress(vaultAddress);
}
/**
* Get the delegator operator for a vault, only for OSD and ONSD vaults
* @param vaultAddress The address of the vault
* @returns The delegator operator
*/
async getDelegatorOperator(vaultAddress) {
const delegatorContract = await this.getDelegatorContract(vaultAddress);
try {
return await (0, utils_1.callContractMethod)(delegatorContract, "operator");
}
catch (error) {
throw new Error("Not an OSD or ONSD vault");
}
}
/**
* Get the delegator network for a vault, only for ONSD vaults
* @param vaultAddress The address of the vault
* @returns The delegator network
*/
async getDelegatorNetwork(vaultAddress) {
const delegatorContract = await this.getDelegatorContract(vaultAddress);
try {
return await (0, utils_1.callContractMethod)(delegatorContract, "network");
}
catch (error) {
throw new Error("Not an ONSD vault");
}
}
}
exports.SymbioticClient = SymbioticClient;