diff --git a/src/interfaces/RouterInterface.ts b/src/interfaces/RouterInterface.ts new file mode 100644 index 00000000..6c5a3139 --- /dev/null +++ b/src/interfaces/RouterInterface.ts @@ -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 +} diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 185f4770..447a29d4 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -2,3 +2,4 @@ export * from './FixedRateInterface' export * from './PoolInterface' export * from './Erc20Interface' export * from './DispenserInterface' +export * from './RouterInterface' diff --git a/src/pools/Router.ts b/src/pools/Router.ts index bef064c2..e71c063a 100644 --- a/src/pools/Router.ts +++ b/src/pools/Router.ts @@ -3,18 +3,8 @@ import Web3 from 'web3' import { TransactionReceipt } from 'web3-core' import { AbiItem } from 'web3-utils' import defaultRouter from '@oceanprotocol/contracts/artifacts/contracts/pools/FactoryRouter.sol/FactoryRouter.json' -import { LoggerInstance, getFairGasPrice } from '../utils' - -interface Operations { - exchangeIds: string - source: string - operation: number - tokenIn: string - amountsIn: string | number - tokenOut: string - amountsOut: string | number - maxPrice: string | number -} +import { getFairGasPrice } from '../utils' +import { Operation } from '../interfaces/RouterInterface' /** * Provides an interface for FactoryRouter contract @@ -49,10 +39,10 @@ export class Router { /** * Estimate gas cost for buyDTBatch method * @param {String} address - * @param {Operations} operations Operations objects array + * @param {Operation} operations Operations objects array * @return {Promise} Transaction receipt */ - public async estGasBuyDTBatch(address: string, operations: Operations[]): Promise { + public async estGasBuyDTBatch(address: string, operations: Operation[]): Promise { const gasLimitDefault = this.GASLIMIT_DEFAULT let estGas try { @@ -68,12 +58,12 @@ export class Router { /** * BuyDTBatch * @param {String} address - * @param {Operations} operations Operations objects array + * @param {Operation} operations Operations objects array * @return {Promise} Transaction receipt */ public async buyDTBatch( address: string, - operations: Operations[] + operations: Operation[] ): Promise { const estGas = await this.estGasBuyDTBatch(address, operations) diff --git a/src/pools/balancer/Pool.ts b/src/pools/balancer/Pool.ts index 3a351f21..768ec0d7 100644 --- a/src/pools/balancer/Pool.ts +++ b/src/pools/balancer/Pool.ts @@ -353,7 +353,7 @@ export class Pool { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress) let result = null try { - result = await pool.methods._marketCollector().call() + result = await pool.methods._publishMarketCollector().call() } catch (e) { this.logger.error(`ERROR: Failed to get marketFeeCollector address: ${e.message}`) } @@ -509,7 +509,7 @@ export class Pool { const pool = new this.web3.eth.Contract(this.poolABI, poolAddress) let weight = null try { - const result = await pool.methods.publishMarketFee(token).call() + const result = await pool.methods.publishMarketFees(token).call() weight = await this.unitsToAmount(token, result) } catch (e) { this.logger.error(`ERROR: Failed to get market fees for a token: ${e.message}`) diff --git a/test/unit/pools/Router.test.ts b/test/unit/pools/Router.test.ts index 480f0116..c373e401 100644 --- a/test/unit/pools/Router.test.ts +++ b/test/unit/pools/Router.test.ts @@ -16,7 +16,7 @@ import { LoggerInstance } from '../../../src/utils' import { NFTFactory, NFTCreateData } from '../../../src/factories/NFTFactory' import { Router } from '../../../src/pools/Router' import { BigNumber } from 'bignumber.js' -import { Erc20CreateParams, PoolCreationParams } from '../../../src/interfaces' +import { Erc20CreateParams, PoolCreationParams, Operation } from '../../../src/interfaces' const { keccak256 } = require('@ethersproject/keccak256') const web3 = new Web3('http://127.0.0.1:8545') const communityCollector = '0xeE9300b7961e0a01d9f0adb863C7A227A07AaD75' @@ -292,7 +292,7 @@ describe('Router unit test', () => { // 1 - swapExactAmountOut // 2 - FixedRateExchange // 3 - Dispenser - const operations1 = { + const operations1: Operation = { exchangeIds: keccak256('0x00'), // used only for FixedRate or Dispenser, but needs to be filled even for pool source: pool1, // pool Address operation: 0, // swapExactAmountIn @@ -300,10 +300,12 @@ describe('Router unit test', () => { amountsIn: web3.utils.toWei('1'), // when swapExactAmountIn is EXACT amount IN tokenOut: erc20Token, amountsOut: web3.utils.toWei('0.1'), // when swapExactAmountIn is MIN amount OUT - maxPrice: web3.utils.toWei('10') // max price (only for pools) + maxPrice: web3.utils.toWei('10'), // max price (only for pools), + swapMarketFee: web3.utils.toWei('0.1'), + marketFeeAddress: contracts.accounts[0] } - const operations2 = { + const operations2: Operation = { exchangeIds: keccak256('0x00'), // used only for FixedRate or Dispenser, but needs to be filled even for pool source: pool2, // pool Address operation: 0, // swapExactAmountIn @@ -311,7 +313,9 @@ describe('Router unit test', () => { amountsIn: web3.utils.toWei('1'), // when swapExactAmountIn is EXACT amount IN tokenOut: erc20Token2, amountsOut: web3.utils.toWei('0.1'), // when swapExactAmountIn is MIN amount OUT - maxPrice: web3.utils.toWei('10') // max price (only for pools) + maxPrice: web3.utils.toWei('10'), // max price (only for pools) + swapMarketFee: web3.utils.toWei('0.1'), + marketFeeAddress: contracts.accounts[0] } await router.buyDTBatch(user2, [operations1, operations2])