UNPKG

@ajna-finance/sdk

Version:

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

67 lines 3.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getErc20PoolContractMulti = exports.getErc20PoolContract = void 0; exports.collateralScale = collateralScale; exports.drawDebt = drawDebt; exports.repayDebt = repayDebt; exports.addCollateral = addCollateral; exports.removeCollateral = removeCollateral; exports.approve = approve; const tslib_1 = require("tslib"); const ERC20Pool_json_1 = tslib_1.__importDefault(require("../abis/ERC20Pool.json")); const transactions_1 = require("../utils/transactions"); const erc20_1 = require("./erc20"); const ethers_1 = require("ethers"); const ethcall_1 = require("ethcall"); const getErc20PoolContract = (poolAddress, provider) => { return new ethers_1.ethers.Contract(poolAddress, ERC20Pool_json_1.default, provider); }; exports.getErc20PoolContract = getErc20PoolContract; const getErc20PoolContractMulti = (poolAddress) => { return new ethcall_1.Contract(poolAddress, ERC20Pool_json_1.default); }; exports.getErc20PoolContractMulti = getErc20PoolContractMulti; function collateralScale(contract) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield contract.collateralScale(); }); } function drawDebt(contract, borrowerAddress, amountToBorrow, limitIndex, collateralToPledge, overrides) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield (0, transactions_1.createTransaction)(contract, { methodName: 'drawDebt', args: [borrowerAddress, amountToBorrow, limitIndex, collateralToPledge], }, overrides); }); } function repayDebt(contract, borrowerAddress, maxQuoteTokenAmountToRepay, collateralAmountToPull, collateralReceiver, limitIndex, overrides) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield (0, transactions_1.createTransaction)(contract, { methodName: 'repayDebt', args: [ borrowerAddress, maxQuoteTokenAmountToRepay, collateralAmountToPull, collateralReceiver, limitIndex, ], }, overrides); }); } function addCollateral(contract, amountToAdd, bucketIndex, expiry, overrides) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield (0, transactions_1.createTransaction)(contract, { methodName: 'addCollateral', args: [amountToAdd, bucketIndex, expiry] }, overrides); }); } function removeCollateral(contract, bucketIndex, maxAmount, overrides) { return tslib_1.__awaiter(this, void 0, void 0, function* () { return yield (0, transactions_1.createTransaction)(contract, { methodName: 'removeCollateral', args: [maxAmount, bucketIndex] }, overrides); }); } function approve(signer, poolAddress, tokenAddress, allowance, overrides) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const contract = (0, erc20_1.getErc20Contract)(tokenAddress, signer); return yield (0, transactions_1.createTransaction)(contract, { methodName: 'approve', args: [poolAddress, allowance] }, overrides); }); } //# sourceMappingURL=erc20-pool.js.map