UNPKG

@ajna-finance/sdk

Version:

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

89 lines 4.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NonfungiblePoolFactory = void 0; const tslib_1 = require("tslib"); const ethers_1 = require("ethers"); const erc721_pool_factory_1 = require("../contracts/erc721-pool-factory"); const types_1 = require("../types"); const Config_1 = require("./Config"); const ContractBase_1 = require("./ContractBase"); const NonfungiblePool_1 = require("./NonfungiblePool"); /** * Factory used to find or create pools with ERC721 collateral. */ class NonfungiblePoolFactory extends ContractBase_1.ContractBase { constructor(signerOrProvider) { super(signerOrProvider); } /** * Creates a new collection pool allowing all tokenIds. * @param signer pool creator * @param nftAddress address of the ERC721 collateral token * @param quoteAddress address of the ERC20 quote token * @param interestRate initial interest rate, between 1%-10%, as WAD * @returns promise to transaction */ deployCollectionPool(signer, nftAddress, quoteAddress, interestRate) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return (0, erc721_pool_factory_1.deployNFTPool)(signer, nftAddress, [], quoteAddress, interestRate); }); } /** * Creates a new subset pool whitelisting specific tokenIds. * @param signer pool creator * @param nftAddress address of the ERC721 collateral token * @param subset array of tokenIds to whitelist * @param quoteAddress address of the ERC20 quote token * @param interestRate initial interest rate, between 1%-10%, as WAD * @returns promise to transaction */ deploySubsetPool(signer, nftAddress, subset, quoteAddress, interestRate) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return (0, erc721_pool_factory_1.deployNFTPool)(signer, nftAddress, subset, quoteAddress, interestRate); }); } /** * Returns existing pool for two tokens. * @param collateralAddress token address * @param subset array of tokenIds for subset pool, empty array for collection pool * @param quoteAddress token address * @returns {@link NonfungiblePool} modeling desired pool */ getPool(collateralAddress, subset, quoteAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const poolAddress = yield this.getPoolAddress(collateralAddress, subset, 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 NonfungiblePool} modeling desired pool */ getPoolByAddress(poolAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const newPool = new NonfungiblePool_1.NonfungiblePool(this.getProvider(), poolAddress, Config_1.Config.ajnaToken); yield newPool.initialize(); return newPool; }); } /** * Finds address of an existing pool. * @param collateralAddress token address * @param subset specifies tokenIds whitelisted in pool * @param quoteAddress token address * @returns address of the existing pool, or zero address if not found */ getPoolAddress(collateralAddress, subset, quoteAddress) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const provider = this.getProvider(); const hash = (0, erc721_pool_factory_1.getSubsetHash)(subset.map(val => ethers_1.BigNumber.from(val))); return yield (0, erc721_pool_factory_1.getDeployedPools)(provider, collateralAddress, quoteAddress, hash); }); } } exports.NonfungiblePoolFactory = NonfungiblePoolFactory; //# sourceMappingURL=NonfungiblePoolFactory.js.map