import { Chain, Models } from '@open-rights-exchange/chain-js' import { chainConfig } from './chainConfig' import { ModelsEthereum } from '../../index' export const { account1, permission1, account2 } = chainConfig.eth_ropsten export const unusedAccountPublicKey = 'EOS5vf6mmk2oU6ae1PXTtnZD7ucKasA3rUEzXyi5xR7WkzX8emEma' export const ERC20ABI = [ { anonymous: false, inputs: [ { indexed: true, internalType: 'address', name: 'owner', type: 'address', }, { indexed: true, internalType: 'address', name: 'spender', type: 'address', }, { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256', }, ], name: 'Approval', type: 'event', }, { anonymous: false, inputs: [ { indexed: true, internalType: 'address', name: 'from', type: 'address', }, { indexed: true, internalType: 'address', name: 'to', type: 'address', }, { indexed: false, internalType: 'uint256', name: 'value', type: 'uint256', }, ], name: 'Transfer', type: 'event', }, { inputs: [ { internalType: 'address', name: 'owner', type: 'address', }, { internalType: 'address', name: 'spender', type: 'address', }, ], name: 'allowance', outputs: [ { internalType: 'uint256', name: '', type: 'uint256', }, ], stateMutability: 'view', type: 'function', }, { inputs: [ { internalType: 'address', name: 'spender', type: 'address', }, { internalType: 'uint256', name: 'amount', type: 'uint256', }, ], name: 'approve', outputs: [ { internalType: 'bool', name: '', type: 'bool', }, ], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { internalType: 'address', name: 'account', type: 'address', }, ], name: 'balanceOf', outputs: [ { internalType: 'uint256', name: '', type: 'uint256', }, ], stateMutability: 'view', type: 'function', }, { inputs: [ { internalType: 'address', name: 'spender', type: 'address', }, { internalType: 'uint256', name: 'subtractedValue', type: 'uint256', }, ], name: 'decreaseAllowance', outputs: [ { internalType: 'bool', name: '', type: 'bool', }, ], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { internalType: 'address', name: 'spender', type: 'address', }, { internalType: 'uint256', name: 'addedValue', type: 'uint256', }, ], name: 'increaseAllowance', outputs: [ { internalType: 'bool', name: '', type: 'bool', }, ], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { internalType: 'uint256', name: 'amount', type: 'uint256', }, ], name: 'mint', outputs: [ { internalType: 'bool', name: '', type: 'bool', }, ], stateMutability: 'nonpayable', type: 'function', }, { inputs: [], name: 'totalSupply', outputs: [ { internalType: 'uint256', name: '', type: 'uint256', }, ], stateMutability: 'view', type: 'function', }, { inputs: [ { internalType: 'address', name: 'recipient', type: 'address', }, { internalType: 'uint256', name: 'amount', type: 'uint256', }, ], name: 'transfer', outputs: [ { internalType: 'bool', name: '', type: 'bool', }, ], stateMutability: 'nonpayable', type: 'function', }, { inputs: [ { internalType: 'address', name: 'sender', type: 'address', }, { internalType: 'address', name: 'recipient', type: 'address', }, { internalType: 'uint256', name: 'amount', type: 'uint256', }, ], name: 'transferFrom', outputs: [ { internalType: 'bool', name: '', type: 'bool', }, ], stateMutability: 'nonpayable', type: 'function', }, ] export const actionSendTokenEthereum = (fromAccount: string, toAccount: string) => { return { from: fromAccount, to: toAccount, contract: { abi: ERC20ABI, parameters: ['0xa26f803334002cbd7ddee757e95e684e417901e9', 1], method: 'transfer', }, } } const removeEmpty = (obj: any) => { // eslint-disable-next-line no-param-reassign Object.keys(obj).forEach(k => !obj[k] && obj[k] !== undefined && delete obj[k]) return obj } export const composeSendTokenEthereum = async ( chain: Chain, toAccount: string, gasPrice: string, gasLimit: string, nonce: string, ) => { let txn: ModelsEthereum.EthTransferParams = { to: toAccount as Models.ChainEntityNameBrand, value: '1', gasPrice, gasLimit, nonce, } txn = removeEmpty(txn) const action = await chain.composeAction(ModelsEthereum.EthereumChainActionType.ETHTransfer, txn) return action }