UNPKG

@ajna-finance/sdk

Version:

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

71 lines 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FungiblePoolFactory = void 0; const tslib_1 = require("tslib"); const ethers_1 = require("ethers"); const Config_1 = require("../classes/Config"); const constants_1 = require("../constants"); const erc20_pool_factory_1 = require("../contracts/erc20-pool-factory"); const types_1 = require("../types"); const ContractBase_1 = require("./ContractBase"); const FungiblePool_1 = require("./FungiblePool"); /** * Factory used to find or create pools with ERC20 collateral. */ class FungiblePoolFactory extends ContractBase_1.ContractBase { constructor(signerOrProvider) { super(signerOrProvider); } /** * Creates a new pool. * @param signer pool creator * @param collateralAddress address of the ERC20 collateral token * @param quoteAddress address of the ERC20 quote token * @param interestRate initial interest rate, between 1%-10%, as WAD * @returns promise to transaction */ deployPool(signer, collateralAddress, quoteAddress, interestRate) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return (0, erc20_pool_factory_1.deployPool)(signer, collateralAddress, quoteAddress, interestRate); }); } /** * Returns existing pool for two tokens. * @param collateralAddress token address * @param quoteAddress token address * @returns {@link FungiblePool} modeling desired pool */ getPool(collateralAddress, quoteAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const poolAddress = yield this.getPoolAddress(collateralAddress, quoteAddress); if (poolAddress === ethers_1.constants.AddressZero) throw new types_1.SdkError('Pool for specified tokens was not found'); return yield this.getPoolByAddress(poolAddress); }); } /** * Returns existing pool. * @param poolAddress address of pool * @returns {@link FungiblePool} modeling desired pool */ getPoolByAddress(poolAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const newPool = new FungiblePool_1.FungiblePool(this.getProvider(), poolAddress, Config_1.Config.ajnaToken); yield newPool.initialize(); return newPool; }); } /** * Finds address of an existing pool for two tokens. * @param collateralAddress token address * @param quoteAddress token address * @returns address of the existing pool */ getPoolAddress(collateralAddress, quoteAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield (0, erc20_pool_factory_1.deployedPools)(this.getProvider(), collateralAddress, quoteAddress, constants_1.ERC20_NON_SUBSET_HASH); }); } } exports.FungiblePoolFactory = FungiblePoolFactory; //# sourceMappingURL=FungiblePoolFactory.js.map