squid-js/src/keeper/contracts/Token.ts

32 lines
1008 B
TypeScript
Raw Normal View History

2019-06-20 00:20:09 +02:00
import BigNumber from 'bignumber.js'
import ContractBase from './ContractBase'
import { InstantiableConfig } from '../../Instantiable.abstract'
2018-10-18 13:12:23 +02:00
export default class OceanToken extends ContractBase {
2019-06-20 00:20:09 +02:00
public static async getInstance(
config: InstantiableConfig
): Promise<OceanToken> {
const token: OceanToken = new OceanToken('OceanToken')
await token.init(config)
2018-10-02 10:06:26 +02:00
return token
}
public async approve(to: string, price: number | string, from?: string) {
2019-06-20 00:20:09 +02:00
return this.sendFrom('approve', [to, String(price)], from)
}
public async decimals(): Promise<number> {
2019-06-20 00:20:09 +02:00
return this.call('decimals', [])
}
2018-10-05 12:34:31 +02:00
public async balanceOf(address: string): Promise<number> {
2019-06-20 00:20:09 +02:00
return this.call('balanceOf', [address]).then((balance: string) =>
new BigNumber(balance).toNumber()
)
}
2019-02-15 14:44:48 +01:00
2019-03-01 13:24:04 +01:00
public async transfer(to: string, amount: number, from: string) {
2019-06-20 00:20:09 +02:00
return this.send('transfer', from, [to, amount])
2019-02-15 14:44:48 +01:00
}
}