UNPKG

@celo/contractkit

Version:

Celo's ContractKit to interact with Celo network

96 lines 5.8 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReserveWrapper = void 0; const BaseWrapper_1 = require("./BaseWrapper"); /** * Contract for handling reserve for stable currencies */ class ReserveWrapper extends BaseWrapper_1.BaseWrapper { constructor() { super(...arguments); /** * Query Tobin tax staleness threshold parameter. * @returns Current Tobin tax staleness threshold. */ this.tobinTaxStalenessThreshold = (0, BaseWrapper_1.proxyCall)(this.contract.methods.tobinTaxStalenessThreshold, undefined, BaseWrapper_1.valueToBigNumber); this.dailySpendingRatio = (0, BaseWrapper_1.proxyCall)(this.contract.methods.getDailySpendingRatio, undefined, BaseWrapper_1.fixidityValueToBigNumber); this.isSpender = (0, BaseWrapper_1.proxyCall)(this.contract.methods.isSpender); this.transferGold = (0, BaseWrapper_1.proxySend)(this.connection, this.contract.methods.transferGold); this.getOrComputeTobinTax = (0, BaseWrapper_1.proxySend)(this.connection, this.contract.methods.getOrComputeTobinTax); this.frozenReserveGoldStartBalance = (0, BaseWrapper_1.proxyCall)(this.contract.methods.frozenReserveGoldStartBalance, undefined, BaseWrapper_1.valueToBigNumber); this.frozenReserveGoldStartDay = (0, BaseWrapper_1.proxyCall)(this.contract.methods.frozenReserveGoldStartDay, undefined, BaseWrapper_1.valueToBigNumber); this.frozenReserveGoldDays = (0, BaseWrapper_1.proxyCall)(this.contract.methods.frozenReserveGoldDays, undefined, BaseWrapper_1.valueToBigNumber); /** * @notice Returns a list of weights used for the allocation of reserve assets. * @return An array of a list of weights used for the allocation of reserve assets. */ this.getAssetAllocationWeights = (0, BaseWrapper_1.proxyCall)(this.contract.methods.getAssetAllocationWeights, undefined, (weights) => weights.map(BaseWrapper_1.valueToBigNumber)); /** * @notice Returns a list of token symbols that have been allocated. * @return An array of token symbols that have been allocated. */ this.getAssetAllocationSymbols = (0, BaseWrapper_1.proxyCall)(this.contract.methods.getAssetAllocationSymbols, undefined, (symbols) => symbols.map((symbol) => this.connection.hexToAscii(symbol))); /** * @alias {getReserveCeloBalance} */ this.getReserveGoldBalance = (0, BaseWrapper_1.proxyCall)(this.contract.methods.getReserveGoldBalance, undefined, BaseWrapper_1.valueToBigNumber); /** * @notice Returns the amount of CELO included in the reserve * @return {BigNumber} The CELO amount included in the reserve. */ this.getReserveCeloBalance = this.getReserveGoldBalance; /** * @notice Returns the amount of unfrozen CELO in the Reserve contract. * @see {getUnfrozenReserveCeloBalance} * @return {BigNumber} amount in wei */ this.getUnfrozenBalance = (0, BaseWrapper_1.proxyCall)(this.contract.methods.getUnfrozenBalance, undefined, BaseWrapper_1.valueToBigNumber); /** * @notice Returns the amount of unfrozen CELO included in the reserve * contract and in other reserve addresses. * @see {getUnfrozenBalance} * @return {BigNumber} amount in wei */ this.getUnfrozenReserveCeloBalance = (0, BaseWrapper_1.proxyCall)(this.contract.methods.getUnfrozenReserveGoldBalance, undefined, BaseWrapper_1.valueToBigNumber); this.getOtherReserveAddresses = (0, BaseWrapper_1.proxyCall)(this.contract.methods.getOtherReserveAddresses); this.isOtherReserveAddress = (0, BaseWrapper_1.proxyCall)(this.contract.methods.isOtherReserveAddress); } /** * Returns current configuration parameters. */ getConfig() { return __awaiter(this, void 0, void 0, function* () { return { tobinTaxStalenessThreshold: yield this.tobinTaxStalenessThreshold(), frozenReserveGoldStartBalance: yield this.frozenReserveGoldStartBalance(), frozenReserveGoldStartDay: yield this.frozenReserveGoldStartDay(), frozenReserveGoldDays: yield this.frozenReserveGoldDays(), otherReserveAddresses: yield this.getOtherReserveAddresses(), }; }); } getSpenders() { return __awaiter(this, void 0, void 0, function* () { const spendersAdded = (yield this.getPastEvents('SpenderAdded', { fromBlock: 0, toBlock: 'latest', })).map((eventlog) => eventlog.returnValues.spender); const spendersRemoved = (yield this.getPastEvents('SpenderRemoved', { fromBlock: 0, toBlock: 'latest', })).map((eventlog) => eventlog.returnValues.spender); return spendersAdded.filter((spender) => !spendersRemoved.includes(spender)); }); } } exports.ReserveWrapper = ReserveWrapper; //# sourceMappingURL=Reserve.js.map