Skip to content

Commit

Permalink
Merge pull request #1129 from oceanprotocol/post-audit-contract-updates
Browse files Browse the repository at this point in the history
Post audit contract updates
  • Loading branch information
bogdanfazakas authored Dec 7, 2021
2 parents fc78f65 + 35c59f0 commit 7a9648a
Show file tree
Hide file tree
Showing 15 changed files with 850 additions and 390 deletions.
210 changes: 72 additions & 138 deletions package-lock.json

Large diffs are not rendered by default.

80 changes: 47 additions & 33 deletions src/datatokens/Datatoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ interface Roles {
export interface OrderParams {
consumer: string
amount: string
serviceId: number
consumeFeeAddress: string
consumeFeeToken: string
consumeFeeAmount: string
serviceIndex: number
providerFeeAddress: string
providerFeeToken: string
providerFeeAmount: string
}

export interface DispenserParams {
Expand Down Expand Up @@ -818,10 +818,10 @@ export class Datatoken {
* @param {String} address User address which calls
* @param {String} consumer Consumer Address
* @param {String} amount Amount of tokens that is going to be transfered
* @param {Number} serviceId Service index in the metadata
* @param {String} mpFeeAddress Consume marketplace fee address
* @param {String} feeToken address of the token marketplace wants to add fee on top
* @param {String} feeAmount amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI
* @param {Number} serviceIndex Service index in the metadata
* @param {String} providerFeeAddress Consume marketplace fee address
* @param {String} providerFeeToken address of the token marketplace wants to add fee on top
* @param {String} providerFeeAmount amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI
* @param {Contract} contractInstance optional contract instance
* @return {Promise<any>}
*/
Expand All @@ -830,10 +830,10 @@ export class Datatoken {
address: string,
consumer: string,
amount: string,
serviceId: number,
mpFeeAddress: string,
feeToken: string,
feeAmount: string,
serviceIndex: number,
providerFeeAddress: string,
providerFeeToken: string,
providerFeeAmount: string,
contractInstance?: Contract
): Promise<any> {
const dtContract =
Expand All @@ -847,10 +847,10 @@ export class Datatoken {
.startOrder(
consumer,
this.web3.utils.toWei(amount),
serviceId,
mpFeeAddress,
feeToken,
this.web3.utils.toWei(feeAmount)
serviceIndex,
providerFeeAddress,
providerFeeToken,
this.web3.utils.toWei(providerFeeAmount)
)
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
} catch (e) {
Expand All @@ -864,45 +864,48 @@ export class Datatoken {
* @param {String} address User address which calls
* @param {String} consumer Consumer Address
* @param {String} amount Amount of tokens that is going to be transfered
* @param {Number} serviceId Service index in the metadata
* @param {String} mpFeeAddress Consume marketplace fee address
* @param {String} feeToken address of the token marketplace wants to add fee on top
* @param {String} feeAmount amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI
* @param {Number} serviceIndex Service index in the metadata
* @param {String} providerFeeAddress Consume marketplace fee address
* @param {String} providerFeeToken address of the token marketplace wants to add fee on top
* @param {String} providerFeeAmount amount of feeToken to be transferred to mpFeeAddress on top, will be converted to WEI
* @return {Promise<TransactionReceipt>} string
*/
public async startOrder(
dtAddress: string,
address: string,
consumer: string,
amount: string,
serviceId: number,
mpFeeAddress: string,
feeToken: string,
feeAmount: string
serviceIndex: number,
providerFeeAddress: string,
providerFeeToken: string,
providerFeeAmount: string
): Promise<TransactionReceipt> {
const dtContract = new this.web3.eth.Contract(this.datatokensABI, dtAddress)
if (!mpFeeAddress) mpFeeAddress = '0x0000000000000000000000000000000000000000'
if (!providerFeeAddress)
providerFeeAddress = '0x0000000000000000000000000000000000000000'

try {
const estGas = await this.estGasStartOrder(
dtAddress,
address,
consumer,
amount,
serviceId,
mpFeeAddress,
feeToken,
feeAmount,
serviceIndex,
providerFeeAddress,
providerFeeToken,
providerFeeAmount,
dtContract
)

const trxReceipt = await dtContract.methods
.startOrder(
consumer,
this.web3.utils.toWei(amount),
serviceId,
mpFeeAddress,
feeToken,
this.web3.utils.toWei(feeAmount)
serviceIndex,
providerFeeAddress,
providerFeeToken,
this.web3.utils.toWei(providerFeeAmount)
)
.send({
from: address,
Expand Down Expand Up @@ -1202,6 +1205,17 @@ export class Datatoken {
return nftAddress
}

/** Returns true if address has deployERC20 role
* @param {String} dtAddress Datatoken adress
* @param {String} dtAddress Datatoken adress
* @return {Promise<number>}
*/
public async isERC20Deployer(dtAddress: string, adddress: string): Promise<string> {
const dtContract = new this.web3.eth.Contract(this.datatokensABI, dtAddress)
const isERC20Deployer = await dtContract.methods.isERC20Deployer(adddress).call()
return isERC20Deployer
}

/**
* Get Address Balance for datatoken
* @param {String} dtAddress Datatoken adress
Expand Down
8 changes: 4 additions & 4 deletions src/factories/NFTFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export interface TokenOrder {
tokenAddress: string
consumer: string
amount: string | number
serviceId: number
consumeFeeAddress: string
consumeFeeToken: string // address of the token marketplace wants to add fee on top
consumeFeeAmount: number
serviceIndex: number
providerFeeAddress: string
providerFeeToken: string
providerFeeAmount: string
}

export interface NFTCreateData {
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/FixedRateInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export interface FreOrderParams {
exchangeContract: string
exchangeId: string
maxBaseTokenAmount: string
swapMarketFee: string
marketFeeAddress: string
}
20 changes: 20 additions & 0 deletions src/interfaces/PoolInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@ export interface CurrentFees {
tokens: string[]
amounts: string[]
}

export interface TokenInOutMarket {
tokenIn: string
tokenOut: string
marketFeeAddress: string
}

export interface AmountsInMaxFee {
tokenAmountIn: string
minAmountOut: string
swapMarketFee: string
maxPrice?: string
}

export interface AmountsOutMaxFee {
tokenAmountOut: string
maxAmountIn: string
swapMarketFee: string
maxPrice?: string
}
59 changes: 59 additions & 0 deletions src/interfaces/RouterInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
export interface Operation {
/**
* used only for FixedRate or Dispenser, but needs to be filled even for pool
* @type {string}
*/
exchangeIds: string
/**
* pool Address
* @type {string}
*/
source: string
/**
* operation:
* 0 - swapExactAmountIn
* 1 - swapExactAmountOut
* 2 - FixedRateExchange
* 3 - Dispenser
* @type {number}
*/
operation: number
/**
* token in address
* @type {string}
*/
tokenIn: string
/**
* when swapExactAmountIn is EXACT amount IN
* expressed in Wei
* @type {string | number}
*/
amountsIn: string | number
/**
* token out address
* @type {string}
*/
tokenOut: string
/**
* when swapExactAmountIn is MIN amount OUT
* expressed in Wei
* @type {string | number}
*/
amountsOut: string | number
/**
* max price (only for pools)
* expressed in Wei
* @type {string | number}
*/
maxPrice: string | number
/**
* swap fee amount
* @type {string}
*/
swapMarketFee: string
/**
* market fee address to receive fees
* @type {string}
*/
marketFeeAddress: string
}
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './FixedRateInterface'
export * from './PoolInterface'
export * from './Erc20Interface'
export * from './DispenserInterface'
export * from './RouterInterface'
Loading

0 comments on commit 7a9648a

Please sign in to comment.