@chorus-one/ethereum
Version:
All-in-one toolkit for building staking dApps on Ethereum network
43 lines (42 loc) • 1.55 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBaseData = void 0;
const decimal_js_1 = __importDefault(require("decimal.js"));
const priceOracleAbi_1 = require("../contracts/priceOracleAbi");
const getBaseData = async (connector, vaultAddress) => {
const publicClient = connector.eth;
const mintTokenRatePromise = publicClient.readContract({
abi: priceOracleAbi_1.PriceOracleAbi,
functionName: 'latestAnswer',
address: connector.priceOracle
});
const osTokenConfigPromise = connector.graphqlRequest({
type: 'graph',
op: 'Vault',
query: `
query Vault($address: ID!) {
vault(id: $address) {
osTokenConfig {
ltvPercent
liqThresholdPercent
}
}
}
`,
variables: {
address: vaultAddress
}
});
const [mintTokenRate, osTokenConfig] = await Promise.all([mintTokenRatePromise, osTokenConfigPromise]);
// ETH per osETH exchange rate
const rate = new decimal_js_1.default(mintTokenRate.toString()).div(1_000_000_000_000_000_000).toString();
return {
rate,
ltvPercent: BigInt(osTokenConfig.data.vault.osTokenConfig.ltvPercent),
thresholdPercent: BigInt(osTokenConfig.data.vault.osTokenConfig.liqThresholdPercent) // minting threshold, max 90%
};
};
exports.getBaseData = getBaseData;