UNPKG

@ajna-finance/sdk

Version:

A typescript SDK that can be used to create Dapps in Ajna ecosystem.

94 lines 3.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ClaimableReserveAuction = void 0; const tslib_1 = require("tslib"); const ethers_1 = require("ethers"); const pool_1 = require("../contracts/pool"); const numeric_1 = require("../utils/numeric"); /** * Models a pool's claimable reserve auction (CRA). */ class ClaimableReserveAuction { /** * @param provider JSON-RPC endpoint * @param contract pool contract reference * @param contractUtils PoolInfoUtils contract rererence * @param poolAddress identifies pool where claimable reserve auction is started */ constructor(provider, contract, contractUtils, poolAddress) { this.provider = provider; this.contract = contract; this.contractUtils = contractUtils; this.poolAddress = poolAddress; } /** * Purchases claimable reserves during a `CRA` using `Ajna` token. * @param maxAmount maximum amount of quote token to purchase at the current auction price * @return promise to transaction */ takeAndBurn(signer_1) { return tslib_1.__awaiter(this, arguments, void 0, function* (signer, maxAmount = ethers_1.constants.MaxUint256) { const contractPoolWithSigner = this.contract.connect(signer); return (0, pool_1.takeReserves)(contractPoolWithSigner, maxAmount); }); } /** * Called by actor to start a `Claimable Reserve Auction` (`CRA`). * @param signer auction initiator * @return promise to transaction */ kick(signer) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contractPoolWithSigner = this.contract.connect(signer); return (0, pool_1.kickReserveAuction)(contractPoolWithSigner); }); } /** * Retrieves claimable reserve auction statistics. * @returns {@link CRAStatus} */ getStatus() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const reservesInfoCall = this.contractUtils.poolReservesInfo(this.poolAddress); const kickTimeCall = this.contract.reservesInfo(); const [reservesInfoResponse, kickTimeResponse] = yield Promise.all([ reservesInfoCall, kickTimeCall, ]); const [reserves, claimableReserves, claimableReservesRemaining, price] = reservesInfoResponse; const [, , lastKickTimestamp] = kickTimeResponse; const ajnaToBurn = (0, numeric_1.wmul)(claimableReservesRemaining, price); return { lastKickTime: new Date(lastKickTimestamp.toNumber() * 1000), ajnaToBurn, reserves, claimableReserves, claimableReservesRemaining, price, }; }); } /** * Defines if auction is ongoing. * @returns boolean that defines if auction is ongoing */ isTakeable() { return tslib_1.__awaiter(this, void 0, void 0, function* () { const reservesInfoCall = this.contractUtils.poolReservesInfo(this.poolAddress); const kickTimeCall = this.contract.reservesInfo(); const [reservesInfoResponse, kickTimeResponse] = yield Promise.all([ reservesInfoCall, kickTimeCall, ]); const [, , claimableReservesRemaining, , timeRemaining] = reservesInfoResponse; const [, , lastKickTimestamp] = kickTimeResponse; const kickTime = ethers_1.BigNumber.from(lastKickTimestamp).mul(1000); const isKicked = kickTime.gt(0); const reservesRemaining = claimableReservesRemaining.gt(0); const expired = timeRemaining.eq(0); return isKicked && reservesRemaining && !expired; }); } } exports.ClaimableReserveAuction = ClaimableReserveAuction; //# sourceMappingURL=ClaimableReserveAuction.js.map