UNPKG

@mstable/protocol

Version:
86 lines 6.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const config_1 = require("hardhat/config"); const generated_1 = require("types/generated"); const math_1 = require("@utils/math"); const utils_1 = require("ethers/lib/utils"); const constants_1 = require("@utils/constants"); const tokens_1 = require("./utils/tokens"); const signerFactory_1 = require("./utils/signerFactory"); const deploy_utils_1 = require("./utils/deploy-utils"); const networkAddressFactory_1 = require("./utils/networkAddressFactory"); config_1.task("token-approve", "Approve address or contract to transfer an amount of tokens from the signer's account") .addParam("asset", "Symbol of the asset being approved. eg mUSD, imUSD, PmUSD, GUSD, alUSD, MTA", undefined, config_1.types.string) .addParam("account", "Address or contract name of the account that is approved to transferFrom", undefined, config_1.types.string) .addOptionalParam("tokenType", "Token address, savings, vault or feederPool.", "address", config_1.types.string) .addOptionalParam("amount", "Amount to approve. Default is max unit128", undefined, config_1.types.int) .addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", config_1.types.string) .setAction(async (taskArgs, hre) => { const chain = networkAddressFactory_1.getChain(hre); const signer = await signerFactory_1.getSigner(hre, taskArgs.speed); const signerAddress = await signer.getAddress(); const assetSymbol = taskArgs.asset; const assetToken = tokens_1.tokens.find((t) => t.symbol === assetSymbol && t.chain === chain); if (!assetToken) throw Error(`Could not find asset with symbol ${assetSymbol}`); const { tokenType } = taskArgs; if (!assetToken[tokenType]) throw Error(`Can not find ${tokenType} for token ${assetSymbol}`); const token = generated_1.ERC20__factory.connect(assetToken[tokenType], signer); const approveAddress = networkAddressFactory_1.resolveAddress(taskArgs.account, chain); const amount = Number.isInteger(taskArgs.amount) ? math_1.simpleToExactAmount(taskArgs.amount, assetToken.decimals) : constants_1.MAX_INT128; const tx = await token.approve(approveAddress, amount); await deploy_utils_1.logTxDetails(tx, `${signerAddress} approves ${approveAddress} to transfer ${utils_1.formatUnits(amount, assetToken.decimals)} ${assetSymbol}`); }); config_1.task("token-transfer", "Transfer an amount of tokens from the signer to the recipient") .addParam("asset", "Symbol of the asset being approved. eg mUSD, imUSD, PmUSD, GUSD, alUSD, MTA", undefined, config_1.types.string) .addParam("recipient", "Address or contract name the tokens will be sent to.", undefined, config_1.types.string) .addOptionalParam("tokenType", "Token address, savings, vault or feederPool.", "address", config_1.types.string) .addParam("amount", "Amount to of token to be sent without the token decimals.", undefined, config_1.types.int) .addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", config_1.types.string) .setAction(async (taskArgs, hre) => { const chain = networkAddressFactory_1.getChain(hre); const signer = await signerFactory_1.getSigner(hre, taskArgs.speed); const signerAddress = await signer.getAddress(); const assetSymbol = taskArgs.asset; const assetToken = tokens_1.tokens.find((t) => t.symbol === assetSymbol && t.chain === chain); if (!assetToken) throw Error(`Could not find asset with symbol ${assetSymbol}`); const { tokenType } = taskArgs; if (!assetToken[tokenType]) throw Error(`Can not find ${tokenType} for token ${assetSymbol}`); const token = generated_1.ERC20__factory.connect(assetToken[tokenType], signer); const recipientAddress = networkAddressFactory_1.resolveAddress(taskArgs.recipient, chain); const amount = math_1.simpleToExactAmount(taskArgs.amount, assetToken.decimals); const desc = `${signerAddress} transfers ${utils_1.formatUnits(amount, assetToken.decimals)} ${assetSymbol} to ${recipientAddress}`; console.log(`About to send tx ${desc}`); const tx = await token.transfer(recipientAddress, amount); await deploy_utils_1.logTxDetails(tx, desc); }); config_1.task("token-transfer-from", "Transfer an amount of tokens from the sender to the recipient") .addParam("asset", "Symbol of the asset being approved. eg mUSD, imUSD, PmUSD, GUSD, alUSD, MTA", undefined, config_1.types.string) .addParam("sender", "Address or contract name the tokens will be sent from.", undefined, config_1.types.string) .addParam("recipient", "Address or contract name the tokens will be sent to.", undefined, config_1.types.string) .addOptionalParam("tokenType", "Token address, savings, vault or feederPool.", "address", config_1.types.string) .addParam("amount", "Amount to of token to be sent without the token decimals.", undefined, config_1.types.int) .addOptionalParam("speed", "Defender Relayer speed param: 'safeLow' | 'average' | 'fast' | 'fastest'", "fast", config_1.types.string) .setAction(async (taskArgs, hre) => { const chain = networkAddressFactory_1.getChain(hre); const signer = await signerFactory_1.getSigner(hre, taskArgs.speed); const signerAddress = await signer.getAddress(); const assetSymbol = taskArgs.asset; const assetToken = tokens_1.tokens.find((t) => t.symbol === assetSymbol && t.chain === chain); if (!assetToken) throw Error(`Could not find asset with symbol ${assetSymbol}`); const { tokenType } = taskArgs; if (!assetToken[tokenType]) throw Error(`Can not find ${tokenType} for token ${assetSymbol}`); const token = generated_1.ERC20__factory.connect(assetToken[tokenType], signer); const senderAddress = networkAddressFactory_1.resolveAddress(taskArgs.sender, chain); const recipientAddress = networkAddressFactory_1.resolveAddress(taskArgs.recipient, chain); const amount = math_1.simpleToExactAmount(taskArgs.amount, assetToken.decimals); const tx = await token.transferFrom(senderAddress, recipientAddress, amount); await deploy_utils_1.logTxDetails(tx, `${signerAddress} transfers ${utils_1.formatUnits(amount, assetToken.decimals)} ${assetSymbol} to ${recipientAddress}`); }); module.exports = {}; //# sourceMappingURL=token.js.map