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 { AbiItem } from 'web3-utils/types'
|
||||||
import { TransactionReceipt } from 'web3-core'
|
import { TransactionReceipt } from 'web3-core'
|
||||||
import { Contract } from 'web3-eth-contract'
|
import { Contract } from 'web3-eth-contract'
|
||||||
import SideStakingTemplate from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
import SideStakingAbi from '@oceanprotocol/contracts/artifacts/contracts/pools/ssContracts/SideStaking.sol/SideStaking.json'
|
||||||
import { LoggerInstance, getFairGasPrice, estimateGas, unitsToAmount } from '../../utils'
|
import { LoggerInstance, getFairGasPrice, estimateGas } from '../../utils'
|
||||||
import { Config, ConfigHelper } from '../../config'
|
import { SmartContract } from '..'
|
||||||
|
|
||||||
export class SideStaking {
|
export class SideStaking extends SmartContract {
|
||||||
public ssAbi: AbiItem | AbiItem[]
|
getDefaultAbi(): AbiItem | AbiItem[] {
|
||||||
public web3: Web3
|
return SideStakingAbi.abi as AbiItem[]
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,7 +20,7 @@ export class SideStaking {
|
|||||||
ssAddress: string,
|
ssAddress: string,
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods
|
result = await sideStaking.methods
|
||||||
@ -65,7 +44,7 @@ export class SideStaking {
|
|||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
try {
|
try {
|
||||||
const sideStaking = new this.web3.eth.Contract(this.ssAbi, ssAddress)
|
const sideStaking = new this.web3.eth.Contract(this.abi, ssAddress)
|
||||||
let result = null
|
let result = null
|
||||||
result = await sideStaking.methods
|
result = await sideStaking.methods
|
||||||
.getDatatokenCurrentCirculatingSupply(datatokenAddress)
|
.getDatatokenCurrentCirculatingSupply(datatokenAddress)
|
||||||
@ -86,7 +65,7 @@ export class SideStaking {
|
|||||||
ssAddress: string,
|
ssAddress: string,
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getPublisherAddress(datatokenAddress).call()
|
result = await sideStaking.methods.getPublisherAddress(datatokenAddress).call()
|
||||||
@ -103,7 +82,7 @@ export class SideStaking {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
async getBaseToken(ssAddress: string, datatokenAddress: string): Promise<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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getBaseTokenAddress(datatokenAddress).call()
|
result = await sideStaking.methods.getBaseTokenAddress(datatokenAddress).call()
|
||||||
@ -120,7 +99,7 @@ export class SideStaking {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
async getPoolAddress(ssAddress: string, datatokenAddress: string): Promise<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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getPoolAddress(datatokenAddress).call()
|
result = await sideStaking.methods.getPoolAddress(datatokenAddress).call()
|
||||||
@ -140,7 +119,7 @@ export class SideStaking {
|
|||||||
ssAddress: string,
|
ssAddress: string,
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getBaseTokenBalance(datatokenAddress).call()
|
result = await sideStaking.methods.getBaseTokenBalance(datatokenAddress).call()
|
||||||
@ -162,7 +141,7 @@ export class SideStaking {
|
|||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
tokenDecimals?: number
|
tokenDecimals?: number
|
||||||
): Promise<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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getDatatokenBalance(datatokenAddress).call()
|
result = await sideStaking.methods.getDatatokenBalance(datatokenAddress).call()
|
||||||
@ -180,7 +159,7 @@ export class SideStaking {
|
|||||||
* @return {String} end block for vesting amount
|
* @return {String} end block for vesting amount
|
||||||
*/
|
*/
|
||||||
async getvestingEndBlock(ssAddress: string, datatokenAddress: string): Promise<string> {
|
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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingEndBlock(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingEndBlock(datatokenAddress).call()
|
||||||
@ -202,7 +181,7 @@ export class SideStaking {
|
|||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
tokenDecimals?: number
|
tokenDecimals?: number
|
||||||
): Promise<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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingAmount(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingAmount(datatokenAddress).call()
|
||||||
@ -223,7 +202,7 @@ export class SideStaking {
|
|||||||
ssAddress: string,
|
ssAddress: string,
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingLastBlock(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingLastBlock(datatokenAddress).call()
|
||||||
@ -245,7 +224,7 @@ export class SideStaking {
|
|||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
tokenDecimals?: number
|
tokenDecimals?: number
|
||||||
): Promise<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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.getvestingAmountSoFar(datatokenAddress).call()
|
result = await sideStaking.methods.getvestingAmountSoFar(datatokenAddress).call()
|
||||||
@ -271,7 +250,7 @@ export class SideStaking {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const sideStaking =
|
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)
|
return estimateGas(account, sideStaking.methods.getVesting, datatokenAddress)
|
||||||
}
|
}
|
||||||
@ -288,7 +267,7 @@ export class SideStaking {
|
|||||||
ssAddress: string,
|
ssAddress: string,
|
||||||
datatokenAddress: string
|
datatokenAddress: string
|
||||||
): Promise<TransactionReceipt> {
|
): 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
|
let result = null
|
||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
@ -326,7 +305,7 @@ export class SideStaking {
|
|||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const sideStaking =
|
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(
|
return estimateGas(
|
||||||
account,
|
account,
|
||||||
@ -351,7 +330,7 @@ export class SideStaking {
|
|||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
swapFee: number
|
swapFee: number
|
||||||
): Promise<TransactionReceipt> {
|
): 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
|
let result = null
|
||||||
|
|
||||||
const estGas = await estimateGas(
|
const estGas = await estimateGas(
|
||||||
@ -382,7 +361,7 @@ export class SideStaking {
|
|||||||
* @return {String}
|
* @return {String}
|
||||||
*/
|
*/
|
||||||
async getRouter(ssAddress: string): Promise<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
|
let result = null
|
||||||
try {
|
try {
|
||||||
result = await sideStaking.methods.router().call()
|
result = await sideStaking.methods.router().call()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user