@ajna-finance/sdk
Version:
A typescript SDK that can be used to create Dapps in Ajna ecosystem.
50 lines • 2.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getErc721PoolFactoryContract = void 0;
exports.deployNFTPool = deployNFTPool;
exports.getDeployedPools = getDeployedPools;
exports.getSubsetHash = getSubsetHash;
const tslib_1 = require("tslib");
const ethers_1 = require("ethers");
const ERC721PoolFactory_json_1 = tslib_1.__importDefault(require("../abis/ERC721PoolFactory.json"));
const Config_1 = require("../classes/Config");
const checksum_address_1 = tslib_1.__importDefault(require("../utils/checksum-address"));
const utils_1 = require("../utils");
const utils_2 = require("ethers/lib/utils");
const getErc721PoolFactoryContract = (provider) => {
return new ethers_1.ethers.Contract((0, checksum_address_1.default)(Config_1.Config.erc721PoolFactory), ERC721PoolFactory_json_1.default, provider);
};
exports.getErc721PoolFactoryContract = getErc721PoolFactoryContract;
function deployNFTPool(signer, collateralAddress, tokenIds, quoteAddress, interestRate, overrides) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const contract = (0, exports.getErc721PoolFactoryContract)(signer);
return yield (0, utils_1.createTransaction)(contract, {
methodName: 'deployPool(address,address,uint256[],uint256)',
args: [collateralAddress, quoteAddress, tokenIds, interestRate],
}, overrides);
});
}
function getDeployedPools(provider, collateralAddress, quoteAddress, subset) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const contract = (0, exports.getErc721PoolFactoryContract)(provider);
return yield contract.deployedPools(subset, collateralAddress, quoteAddress);
});
}
function getSubsetHash(tokensIds) {
//keccak256('ERC721_NON_SUBSET_HASH')
const ERC721_NON_SUBSET_HASH = '0x93e3b87db48beb11f82ff978661ba6e96f72f582300e9724191ab4b5d7964364';
if (tokensIds.length === 0)
return ERC721_NON_SUBSET_HASH;
else {
// check the array of token ids is sorted in ascending order
// revert if not sorted
for (let i = 0; i < tokensIds.length - 1; i++) {
if (tokensIds[i].gte(tokensIds[i + 1]))
throw new Error('Token ids must be sorted');
}
const abi = ethers_1.ethers.utils.defaultAbiCoder;
// hash the sorted array of tokenIds
return (0, utils_2.keccak256)(abi.encode(['uint256[]'], [tokensIds]));
}
}
//# sourceMappingURL=erc721-pool-factory.js.map