UNPKG

@celo/contractkit

Version:

Celo's ContractKit to interact with Celo network

97 lines 4.05 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.AbstractFeeCurrencyWrapper = void 0; const BaseWrapper_1 = require("./BaseWrapper"); const MINIMAL_TOKEN_INFO_ABI = [ { type: 'function', stateMutability: 'view', outputs: [{ type: 'string', name: '', internalType: 'string' }], name: 'symbol', inputs: [], }, { type: 'function', stateMutability: 'view', outputs: [{ type: 'string', name: '', internalType: 'string' }], name: 'name', inputs: [], }, { type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'address', name: '', internalType: 'address' }], name: 'adaptedToken', }, // usdt adapter uses slightly different interface this adaptedToken/getAdaptedToken are aliases { type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'address', name: '', internalType: 'address' }], name: 'getAdaptedToken', }, { type: 'function', stateMutability: 'view', inputs: [], outputs: [{ type: 'uint8', name: '', internalType: 'uint8' }], name: 'decimals', }, ]; class AbstractFeeCurrencyWrapper extends BaseWrapper_1.BaseWrapper { getFeeCurrencyInformation(whitelist) { return __awaiter(this, void 0, void 0, function* () { const feeCurrencies = whitelist !== null && whitelist !== void 0 ? whitelist : (yield this.getAddresses()); return Promise.all(feeCurrencies.map((address) => __awaiter(this, void 0, void 0, function* () { // @ts-expect-error abi typing is not 100% correct but works let contract = new this.connection.web3.eth.Contract(MINIMAL_TOKEN_INFO_ABI, address); const adaptedToken = (yield contract.methods .adaptedToken() .call() .catch(() => contract.methods .getAdaptedToken() .call() .catch(() => undefined))); // if standard didnt work try alt if (adaptedToken) { // @ts-expect-error abi typing is not 100% correct but works contract = new this.connection.web3.eth.Contract(MINIMAL_TOKEN_INFO_ABI, adaptedToken); } return Promise.all([ contract.methods .name() .call() .catch(() => undefined), contract.methods .symbol() .call() .catch(() => undefined), contract.methods .decimals() .call() .then((x) => x && parseInt(x, 10)) .catch(() => undefined), ]).then(([name, symbol, decimals]) => ({ name, symbol, address, adaptedToken, decimals, })); }))); }); } } exports.AbstractFeeCurrencyWrapper = AbstractFeeCurrencyWrapper; //# sourceMappingURL=AbstractFeeCurrencyWrapper.js.map