mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
inherit SideStaking from SmartContract
This commit is contained in:
parent
bf6bd53c1d
commit
a327bf5da5
@ -1,34 +1,13 @@
|
||||
import Web3 from 'web3'
|
||||
import { AbiItem } from 'web3-utils/types'
|
||||
import { TransactionReceipt } from 'web3-core'
|
||||
import { Contract } from 'web3-eth-contract'
|
||||
import SideStakingTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||
import { LoggerInstance, getFairGasPrice, estimateGas, unitsToAmount } from '../../utils'
|
||||
import { Config, ConfigHelper } from '../../config'
|
||||
import SideStakingAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||
import { LoggerInstance, getFairGasPrice, estimateGas } from '../../utils'
|
||||
import { SmartContract } from '..'
|
||||
|
||||
export class SideStaking {
|
||||
public ssAbi: AbiItem | AbiItem[]
|
||||
public web3: Web3
|
||||
public config: Config
|
||||
|
||||
constructor(
|
||||
web3: Web3,
|
||||
network?: string | number,
|
||||
ssAbi: AbiItem | AbiItem[] = null,
|
||||
config?: Config
|
||||
) {
|
||||
if (ssAbi) this.ssAbi = ssAbi
|
||||
else this.ssAbi = SideStakingTemplate.abi as AbiItem[]
|
||||
this.web3 = web3
|
||||
this.config = config || new ConfigHelper().getConfig(network || 'unknown')
|
||||
}
|
||||
|
||||
async unitsToAmount(
|
||||
token: string,
|
||||
amount: string,
|
||||
tokenDecimals?: number
|
||||
): Promise<string> {
|
||||
return unitsToAmount(this.web3, token, amount, tokenDecimals)
|
||||
export class SideStaking extends SmartContract {
|
||||
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||
return SideStakingAbi.abi as AbiItem[]
|
||||
}
|
||||
|
||||
/**
|
||||
@ -41,7 +20,7 @@ export class SideStaking {
|
||||
ssAddress: string,
|
||||
datatokenAddress: string
|
||||
): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods
|
||||
@ -65,7 +44,7 @@ export class SideStaking {
|
||||
datatokenAddress: string
|
||||
): Promise<string> {
|
||||
try {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
result = await sideStaking.methods
|
||||
.getDatatokenCurrentCirculatingSupply(datatokenAddress)
|
||||
@ -86,7 +65,7 @@ export class SideStaking {
|
||||
ssAddress: string,
|
||||
datatokenAddress: string
|
||||
): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods.getPublisherAddress(datatokenAddress).call()
|
||||
@ -103,7 +82,7 @@ export class SideStaking {
|
||||
* @return {String}
|
||||
*/
|
||||
async getBaseToken(ssAddress: string, datatokenAddress: string): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods.getBaseTokenAddress(datatokenAddress).call()
|
||||
@ -120,7 +99,7 @@ export class SideStaking {
|
||||
* @return {String}
|
||||
*/
|
||||
async getPoolAddress(ssAddress: string, datatokenAddress: string): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods.getPoolAddress(datatokenAddress).call()
|
||||
@ -140,7 +119,7 @@ export class SideStaking {
|
||||
ssAddress: string,
|
||||
datatokenAddress: string
|
||||
): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods.getBaseTokenBalance(datatokenAddress).call()
|
||||
@ -162,7 +141,7 @@ export class SideStaking {
|
||||
datatokenAddress: string,
|
||||
tokenDecimals?: number
|
||||
): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods.getDatatokenBalance(datatokenAddress).call()
|
||||
@ -180,7 +159,7 @@ export class SideStaking {
|
||||
* @return {String} end block for vesting amount
|
||||
*/
|
||||
async getvestingEndBlock(ssAddress: string, datatokenAddress: string): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods.getvestingEndBlock(datatokenAddress).call()
|
||||
@ -202,7 +181,7 @@ export class SideStaking {
|
||||
datatokenAddress: string,
|
||||
tokenDecimals?: number
|
||||
): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods.getvestingAmount(datatokenAddress).call()
|
||||
@ -223,7 +202,7 @@ export class SideStaking {
|
||||
ssAddress: string,
|
||||
datatokenAddress: string
|
||||
): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods.getvestingLastBlock(datatokenAddress).call()
|
||||
@ -245,7 +224,7 @@ export class SideStaking {
|
||||
datatokenAddress: string,
|
||||
tokenDecimals?: number
|
||||
): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods.getvestingAmountSoFar(datatokenAddress).call()
|
||||
@ -271,7 +250,7 @@ export class SideStaking {
|
||||
contractInstance?: Contract
|
||||
): Promise<number> {
|
||||
const sideStaking =
|
||||
contractInstance || new this.web3.eth.Contract(this.ssAbi as AbiItem[], ssAddress)
|
||||
contractInstance || new this.web3.eth.Contract(this.abi as AbiItem[], ssAddress)
|
||||
|
||||
return estimateGas(account, sideStaking.methods.getVesting, datatokenAddress)
|
||||
}
|
||||
@ -288,7 +267,7 @@ export class SideStaking {
|
||||
ssAddress: string,
|
||||
datatokenAddress: string
|
||||
): Promise<TransactionReceipt> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
|
||||
const estGas = await estimateGas(
|
||||
@ -326,7 +305,7 @@ export class SideStaking {
|
||||
contractInstance?: Contract
|
||||
): Promise<number> {
|
||||
const sideStaking =
|
||||
contractInstance || new this.web3.eth.Contract(this.ssAbi as AbiItem[], ssAddress)
|
||||
contractInstance || new this.web3.eth.Contract(this.abi as AbiItem[], ssAddress)
|
||||
|
||||
return estimateGas(
|
||||
account,
|
||||
@ -351,7 +330,7 @@ export class SideStaking {
|
||||
poolAddress: string,
|
||||
swapFee: number
|
||||
): Promise<TransactionReceipt> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
|
||||
const estGas = await estimateGas(
|
||||
@ -382,7 +361,7 @@ export class SideStaking {
|
||||
* @return {String}
|
||||
*/
|
||||
async getRouter(ssAddress: string): Promise<string> {
|
||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
||||
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||
let result = null
|
||||
try {
|
||||
result = await sideStaking.methods.router().call()
|
||||
|
Loading…
x
Reference in New Issue
Block a user