UNPKG

@secux/app-eth

Version:
18 lines (15 loc) 3.48 kB
"use strict"; /*! Copyright 2022 SecuX Technology Inc Copyright Chen Wei-En Copyright Wu Tsung-Yu Licensed under the Apache License, Version 2.0 (the License); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an AS IS BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */var __importDefault=this&&this.__importDefault||function(mod){return mod&&mod.__esModule?mod:{default:mod}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.erc20_def=exports.ERC20=void 0;const abi_1=require("@ethersproject/abi"),ow_1=__importDefault(require("ow")),app_eth_1=require("./app-eth"),interface_1=require("./interface"),transaction_1=require("./transaction"),interface_2=require("@secux/protocol-transaction/lib/interface");exports.ERC20=class{static prepareTransfer(path,content,args){(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_transferData);const data=exports.erc20_def.encodeFunctionData("transfer",[args.toAddress,args.amount]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.TOKEN)}static prepareTransferFrom(path,content,args){(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_transferFromData);const data=exports.erc20_def.encodeFunctionData("transferFrom",[args.fromAddress,args.toAddress,args.amount]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.TOKEN)}static prepareApprove(path,content,args){(0,ow_1.default)(content,interface_1.ow_baseData),(0,ow_1.default)(args,ow_transferData);const data=exports.erc20_def.encodeFunctionData("approve",[args.toAddress,args.amount]),builder=(0,transaction_1.getBuilder)(Object.assign(Object.assign({},content),{data}));return(0,app_eth_1.prepareSign)(path,builder,interface_2.TransactionType.TOKEN)}},exports.erc20_def=new abi_1.Interface(["function name() public view returns (string)","function symbol() public view returns (string)","function decimals() public view returns (uint8)","function totalSupply() public view returns (uint256)","function balanceOf(address _owner) public view returns (uint256 balance)","function transfer(address _to, uint256 _value) public returns (bool success)","function transferFrom(address _from, address _to, uint256 _value) public returns (bool success)","function approve(address _spender, uint256 _value) public returns (bool success)","function allowance(address _owner, address _spender) public view returns (uint256 remaining)","event Transfer(address indexed _from, address indexed _to, uint256 _value)","event Approval(address indexed _owner, address indexed _spender, uint256 _value)"]);const ow_transferData=ow_1.default.object.exactShape({toAddress:interface_1.ow_address,amount:ow_1.default.any(ow_1.default.number.positive,interface_1.ow_hexString32)}),ow_transferFromData=ow_1.default.object.exactShape({fromAddress:interface_1.ow_address,toAddress:interface_1.ow_address,amount:ow_1.default.any(ow_1.default.number.positive,interface_1.ow_hexString32)});