1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

lots of ABI typings

This commit is contained in:
Matthias Kretschmann 2020-08-19 12:56:48 +02:00
parent 7cf85f6392
commit bbd465992b
Signed by: m
GPG Key ID: 606EEEF3C479A91F
9 changed files with 76 additions and 65 deletions

View File

@ -39,7 +39,6 @@
"dependencies": {
"@ethereum-navigator/navigator": "^0.5.0",
"@oceanprotocol/contracts": "^0.3.4",
"bignumber.js": "^9.0.0",
"decimal.js": "^10.2.0",
"fs": "0.0.1-security",
"node-fetch": "^2.6.0",

View File

@ -1,19 +1,23 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
import { Pool } from './Pool'
/**
* Ocean Pools submodule exposed under ocean.pool
*/
export class OceanPool extends Pool {
public oceanAddress: string = null
public dtAddress: string = null
constructor(
web3: Web3,
FactoryABI: any = null,
PoolABI: any = null,
factoryABI: AbiItem | AbiItem[] = null,
poolABI: AbiItem | AbiItem[] = null,
factoryAddress: string = null,
oceanAddress: string = null,
gaslimit?: number
) {
super(web3, FactoryABI, PoolABI, factoryAddress, gaslimit)
super(web3, factoryABI, poolABI, factoryAddress, gaslimit)
if (oceanAddress) {
this.oceanAddress = oceanAddress
}
@ -76,6 +80,7 @@ export class OceanPool extends Pool {
const tokens = await this.getCurrentTokens(account, poolAddress)
let token
for (token of tokens) {
// TODO: Potential timing attack, left side: true
if (token !== this.oceanAddress) this.dtAddress = token
}
return this.dtAddress
@ -314,7 +319,7 @@ export class OceanPool extends Pool {
*/
public async searchPoolforDT(account: string, dtAddress: string): Promise<string[]> {
const result: string[] = []
const factory = new this.web3.eth.Contract(this.FactoryABI, this.factoryAddress, {
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
from: account
})
const events = await factory.getPastEvents('SPoolRegistered', {

View File

@ -1,6 +1,7 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
import Decimal from 'decimal.js'
import * as jsonPoolABI from '@oceanprotocol/contracts/artifacts/SPool.json'
import * as jsonpoolABI from '@oceanprotocol/contracts/artifacts/SPool.json'
import { PoolFactory } from './PoolFactory'
/**
@ -13,18 +14,18 @@ export interface TokensToAdd {
}
export class Pool extends PoolFactory {
private PoolABI: any
private poolABI: AbiItem | AbiItem[]
constructor(
web3: Web3,
FactoryABI: any = null,
PoolABI: any = null,
factoryABI: AbiItem | AbiItem[] = null,
poolABI: AbiItem | AbiItem[] = null,
factoryAddress: string = null,
gaslimit?: number
) {
super(web3, FactoryABI, factoryAddress, gaslimit)
if (PoolABI) this.PoolABI = PoolABI
else this.PoolABI = jsonPoolABI.abi
super(web3, factoryABI, factoryAddress, gaslimit)
if (poolABI) this.poolABI = poolABI
else this.poolABI = jsonpoolABI.abi
}
/**
@ -142,7 +143,7 @@ export class Pool extends PoolFactory {
poolAddress: string,
tokens: TokensToAdd[]
): Promise<void> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
@ -176,7 +177,7 @@ export class Pool extends PoolFactory {
* @param {String} fee (will be converted to wei)
*/
async setSwapFee(account: string, poolAddress: string, fee: string): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -196,7 +197,7 @@ export class Pool extends PoolFactory {
* @param {String} poolAddress
*/
async finalize(account: string, poolAddress: string): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -216,7 +217,7 @@ export class Pool extends PoolFactory {
* @param {String} poolAddress
*/
async getNumTokens(account: string, poolAddress: string): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -235,7 +236,7 @@ export class Pool extends PoolFactory {
* @return {String[]}
*/
async getCurrentTokens(account: string, poolAddress: string): Promise<string[]> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -254,7 +255,7 @@ export class Pool extends PoolFactory {
* @return {String[]}
*/
async getFinalTokens(account: string, poolAddress: string): Promise<string[]> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -273,7 +274,7 @@ export class Pool extends PoolFactory {
* @return {String}
*/
async getController(account: string, poolAddress: string): Promise<string> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -297,7 +298,7 @@ export class Pool extends PoolFactory {
poolAddress: string,
controllerAddress: string
): Promise<string> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -319,7 +320,7 @@ export class Pool extends PoolFactory {
* @return {Boolean}
*/
async isBound(account: string, poolAddress: string, token: string): Promise<boolean> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -339,7 +340,7 @@ export class Pool extends PoolFactory {
* @return {String}
*/
async getReserve(account: string, poolAddress: string, token: string): Promise<string> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let amount = null
@ -359,7 +360,7 @@ export class Pool extends PoolFactory {
* @return {Boolean}
*/
async isFinalized(account: string, poolAddress: string): Promise<boolean> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -378,7 +379,7 @@ export class Pool extends PoolFactory {
* @return {String} Swap fee in wei
*/
async getSwapFee(account: string, poolAddress: string): Promise<string> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let fee = null
@ -403,7 +404,7 @@ export class Pool extends PoolFactory {
poolAddress: string,
token: string
): Promise<string> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let weight = null
@ -428,7 +429,7 @@ export class Pool extends PoolFactory {
poolAddress: string,
token: string
): Promise<string> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let weight = null
@ -451,7 +452,7 @@ export class Pool extends PoolFactory {
account: string,
poolAddress: string
): Promise<string> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let weight = null
@ -484,7 +485,7 @@ export class Pool extends PoolFactory {
minAmountOut: string,
maxPrice: string
): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -524,7 +525,7 @@ export class Pool extends PoolFactory {
minAmountOut: string,
maxPrice: string
): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -558,7 +559,7 @@ export class Pool extends PoolFactory {
poolAmountOut: string,
maxAmountsIn: string[]
): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
const weiMaxAmountsIn = []
@ -595,7 +596,7 @@ export class Pool extends PoolFactory {
poolAmountIn: string,
minAmountsOut: string
): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
const weiMinAmountsOut = []
@ -630,7 +631,7 @@ export class Pool extends PoolFactory {
tokenAmountIn: string,
minPoolAmountOut: string
): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -664,7 +665,7 @@ export class Pool extends PoolFactory {
poolAmountOut: string,
maxAmountIn: string
): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -698,7 +699,7 @@ export class Pool extends PoolFactory {
poolAmountIn: string,
minTokenAmountOut: string
): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -732,7 +733,7 @@ export class Pool extends PoolFactory {
tokenAmountOut: string,
maxPoolAmountIn: string
): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let result = null
@ -764,7 +765,7 @@ export class Pool extends PoolFactory {
tokenIn: string,
tokenOut: string
): Promise<any> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let price = null
@ -791,7 +792,7 @@ export class Pool extends PoolFactory {
tokenIn: string,
tokenOut: string
): Promise<string> {
const pool = new this.web3.eth.Contract(this.PoolABI, poolAddress, {
const pool = new this.web3.eth.Contract(this.poolABI, poolAddress, {
from: account
})
let price = null

View File

@ -1,22 +1,23 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
import * as jsonFactoryABI from '@oceanprotocol/contracts/artifacts/SFactory.json'
export class PoolFactory {
public GASLIMIT_DEFAULT = 5000000
public web3: any = null
public FactoryABI: any
public factoryAddress: any
public web3: Web3 = null
public factoryABI: AbiItem | AbiItem[]
public factoryAddress: string
constructor(
web3: Web3,
FactoryABI: any = null,
factoryABI: AbiItem | AbiItem[] = null,
factoryAddress: string = null,
gaslimit?: number
) {
this.web3 = web3
if (FactoryABI) this.FactoryABI = FactoryABI
else this.FactoryABI = jsonFactoryABI.abi
if (factoryABI) this.factoryABI = factoryABI
else this.factoryABI = jsonFactoryABI.abi
if (factoryAddress) {
this.factoryAddress = factoryAddress
}
@ -37,7 +38,7 @@ export class PoolFactory {
return null
}
const factory = new this.web3.eth.Contract(this.FactoryABI, this.factoryAddress, {
const factory = new this.web3.eth.Contract(this.factoryABI, this.factoryAddress, {
from: account
})

View File

@ -1,14 +1,17 @@
const defaultFactoryABI = require('@oceanprotocol/contracts/artifacts/DTFactory.json')
const defaultDatatokensABI = require('@oceanprotocol/contracts/artifacts/DataTokenTemplate.json')
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
import defaultFactoryABI from '@oceanprotocol/contracts/artifacts/DTFactory.json'
import defaultDatatokensABI from '@oceanprotocol/contracts/artifacts/DataTokenTemplate.json'
/**
* Provides a interface to DataTokens
*/
export class DataTokens {
public factoryAddress: string
public factoryABI: any
public datatokensABI: any
public web3: any
public factoryABI: AbiItem | AbiItem[]
public datatokensABI: AbiItem | AbiItem[]
public web3: Web3
/**
* Instantiate DataTokens (independently of Ocean).
@ -18,7 +21,12 @@ export class DataTokens {
* @param {any} web3
*/
constructor(factoryAddress: string, factoryABI: any, datatokensABI: any, web3: any) {
constructor(
factoryAddress: string,
factoryABI: AbiItem | AbiItem[],
datatokensABI: AbiItem | AbiItem[],
web3: Web3
) {
this.factoryAddress = factoryAddress
this.factoryABI = factoryABI || defaultFactoryABI.abi
this.datatokensABI = datatokensABI || defaultDatatokensABI.abi

View File

@ -1,4 +1,3 @@
import BigNumber from 'bignumber.js'
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
/**

View File

@ -1,18 +1,12 @@
import { Accounts } from './Accounts'
import { Assets } from './Assets'
// import { Compute } from './Compute'
import { Versions } from './Versions'
import { OceanUtils } from './utils/Utils'
import { MetadataStore } from '../metadatastore/MetadataStore'
import { Provider } from '../provider/Provider'
import { DataTokens } from '../datatokens/Datatokens'
import { Network } from '../datatokens/Network'
import { Config } from '../models/Config'
import {
Instantiable,
generateIntantiableConfigFromConfig

View File

@ -1,3 +1,5 @@
import Web3 from 'web3'
import { AbiItem } from 'web3-utils/types'
import { Contract } from 'web3-eth-contract'
export class BalancerContractHandler {
@ -8,14 +10,14 @@ export class BalancerContractHandler {
public factoryBytecode: string
public factoryAddress: string
public poolAddress: string
public web3: any
public web3: Web3
constructor(
factoryABI: Contract,
factoryABI: AbiItem | AbiItem[],
factoryBytecode: string,
poolABI: Contract,
poolABI: AbiItem | AbiItem[],
poolBytecode: string,
web3: any
web3: Web3
) {
this.web3 = web3
this.factory = new this.web3.eth.Contract(factoryABI)

View File

@ -1,4 +1,6 @@
import Web3 from 'web3'
import { Contract } from 'web3-eth-contract'
import { AbiItem } from 'web3-utils/types'
export class TestContractHandler {
public factory: Contract
@ -8,14 +10,14 @@ export class TestContractHandler {
public factoryBytecode: string
public factoryAddress: string
public templateAddress: string
public web3: any
public web3: Web3
constructor(
factoryABI: Contract,
datatokensABI: Contract,
factoryABI: AbiItem | AbiItem[],
datatokensABI: AbiItem | AbiItem[],
templateBytecode: string,
factoryBytecode: string,
web3: any
web3: Web3
) {
this.web3 = web3
this.factory = new this.web3.eth.Contract(factoryABI)