@skalenetwork/ima-js
Version:
Simple TS/JS library to interact with SKALE IMA
46 lines (45 loc) • 2.23 kB
JavaScript
/**
* @license
* SKALE ima-js
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { DepositBox } from './DepositBox';
import * as transactions from '../../transactions';
export class DepositBoxERC20 extends DepositBox {
async approve(tokenName, amount, opts) {
const tokenContract = this.tokens[tokenName];
const txData = await tokenContract.approve.populateTransaction(this.address, amount);
return await transactions.send(this.provider, txData, opts, this.txName('approve'));
}
async deposit(chainName, tokenName, amount, opts) {
const tokenContract = this.tokens[tokenName];
const tokenContractAddress = await tokenContract.getAddress();
const txData = await this.contract.depositERC20.populateTransaction(chainName, tokenContractAddress, amount);
return await transactions.send(this.provider, txData, opts, this.txName('depositERC20'));
}
async getTokenMappingsLength(chainName) {
return await this.contract.getSchainToAllERC20Length(chainName);
}
async getTokenMappings(chainName, from, to) {
return await this.contract.getSchainToAllERC20(chainName, from, to);
}
async isTokenAdded(chainName, erc20OnMainnet) {
return await this.contract.getSchainToERC20(chainName, erc20OnMainnet);
}
async addTokenByOwner(chainName, erc20OnMainnet, opts) {
const txData = await this.contract.addERC20TokenByOwner.populateTransaction(chainName, erc20OnMainnet);
return await transactions.send(this.provider, txData, opts, this.txName('addERC20TokenByOwner'));
}
}