UNPKG

@volare.finance/volare.js

Version:
141 lines 6.54 kB
"use strict"; /** * @file vanilla.ts * @author astra <astra@volare.finance> * @date 2022 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Vanilla = void 0; const tslib_1 = require("tslib"); const utils_js_1 = require("@volare.finance/utils.js"); const Controller_1 = require("./Controller"); const MarginCalculator_1 = require("./MarginCalculator"); const OracleV2_1 = require("./OracleV2"); const protocols_1 = require("./protocols"); const Whitelist_1 = require("./Whitelist"); class Vanilla extends utils_js_1.Provider { constructor(options) { super(options.endpoint); this.oracle = new OracleV2_1.OracleV2(options.contracts.OracleV2, options.endpoint); this.whitelist = new Whitelist_1.Whitelist(options.contracts.Whitelist, options.endpoint); this.marginCalculator = new MarginCalculator_1.MarginCalculator(options.contracts.MarginCalculator, options.endpoint); this.controller = new Controller_1.Controller(options.contracts.Controller, options.endpoint); } isWhitelistedVToken(vTokenAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.whitelist.isWhitelistedVToken(vTokenAddress); }); } getPrice(assetAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.oracle.getPrice(assetAddress); }); } getExpiryPrice(assetAddress, expiryTimestamp) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.oracle.getExpiryPrice(assetAddress, expiryTimestamp); }); } /*** * @description calculate required collateral margin for a vault * @param ownerAddress * @param vaultId * @param vaultType * @return the vault collateral amount, * and marginRequired the minimal amount of collateral needed in a vault, scaled to 1e27 */ getMarginRequired(ownerAddress, vaultId, vaultType) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const vault = yield this.getVault(ownerAddress, vaultId); return this.marginCalculator.getMarginRequired(vault, vaultType); }); } /** * @notice returns the amount of collateral that can be removed from an actual or a theoretical vault * @dev return amount is denominated in the collateral asset for the vToken in the vault, or the collateral asset in the vault * @param ownerAddress * @param vaultId theoretical vault that needs to be checked * @param vaultType vault type (0 for spread/max loss, 1 for naked margin) * @return excessCollateral the amount by which the margin is above or below the required amount * @return isExcess True if there is excess margin in the vault, False if there is a deficit of margin in the vault * if True, collateral can be taken out from the vault, if False, additional collateral needs to be added to vault */ getExcessCollateral(ownerAddress, vaultId, vaultType) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const vault = yield this.getVault(ownerAddress, vaultId); return this.marginCalculator.getExcessCollateral(vault, vaultType); }); } getNakedCap(assetAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.getNakedCap(assetAddress); }); } getNakedPoolBalance(assetAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.getNakedPoolBalance(assetAddress); }); } getPayout(vTokenAddress, vTokenAmount) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.getPayout(vTokenAddress, vTokenAmount); }); } getAccountVaultCounter(ownerAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.getAccountVaultCounter(ownerAddress); }); } getVault(ownerAddress, vaultId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.getVault(ownerAddress, vaultId); }); } getVaultWithDetails(ownerAddress, vaultId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield this.controller.getVaultWithDetails(ownerAddress, vaultId); }); } short(writer, vaultId, index, vToken, vTokenAmount, vaultType = protocols_1.VaultType.FullyCollateralized) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.short(writer, vaultId, index, vToken, vTokenAmount, vaultType); }); } redeem(owner, vToken, vTokenAmount) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.redeem(owner, vToken, vTokenAmount); }); } settle(writer, vaultId) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.settle(writer, vaultId); }); } liquidate(wallet, ownerAddress, vaultId, vTokenAmount) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.liquidate(wallet, ownerAddress, vaultId, vTokenAmount); }); } depositCollateral(owner, vaultId, index, collateralAddress, collateralAmount) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.depositCollateral(owner, vaultId, index, collateralAddress, collateralAmount); }); } withdrawCollateral(owner, vaultId, index, collateralAddress, collateralAmount) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.withdrawCollateral(owner, vaultId, index, collateralAddress, collateralAmount); }); } depositLong(owner, vaultId, index, vToken, vTokenAmount) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.depositLong(owner, vaultId, index, vToken, vTokenAmount); }); } withdrawLong(owner, vaultId, index, vToken, vTokenAmount) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return this.controller.withdrawLong(owner, vaultId, index, vToken, vTokenAmount); }); } } exports.Vanilla = Vanilla; //# sourceMappingURL=vanilla.js.map