mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
bump to contracts alpha.20 (#1295)
* bump to contracts alpha.20 Co-authored-by: Bogdan Fazakas <bogdan.fazakas@gmail.com>
This commit is contained in:
parent
7ca5000a66
commit
7932a845d5
14
package-lock.json
generated
14
package-lock.json
generated
@ -9,7 +9,7 @@
|
|||||||
"version": "1.0.0-next.19",
|
"version": "1.0.0-next.19",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/contracts": "1.0.0-alpha.19",
|
"@oceanprotocol/contracts": "1.0.0-alpha.20",
|
||||||
"bignumber.js": "^9.0.2",
|
"bignumber.js": "^9.0.2",
|
||||||
"cross-fetch": "^3.1.5",
|
"cross-fetch": "^3.1.5",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
@ -3033,9 +3033,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@oceanprotocol/contracts": {
|
"node_modules/@oceanprotocol/contracts": {
|
||||||
"version": "1.0.0-alpha.19",
|
"version": "1.0.0-alpha.20",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.19.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.20.tgz",
|
||||||
"integrity": "sha512-3E4eMo2lMyWMjiGk5dvSZvs/QNq7GSAPPzfMbxVLCdjfyP7kvVVVgn0pxabQtexkK4NK7tpNdA+IbsJaM0BBdw==",
|
"integrity": "sha512-Z+zP7XzYjZfd0+URupld2LLZ91E07EWM4wlxpRGOhXEZ7oL3iQAlRJGq6SZN7C65LSUaMQuhj+n5C8aYOXUdwQ==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@openzeppelin/contracts": "^4.3.3",
|
"@openzeppelin/contracts": "^4.3.3",
|
||||||
"@openzeppelin/test-helpers": "^0.5.15",
|
"@openzeppelin/test-helpers": "^0.5.15",
|
||||||
@ -27682,9 +27682,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@oceanprotocol/contracts": {
|
"@oceanprotocol/contracts": {
|
||||||
"version": "1.0.0-alpha.19",
|
"version": "1.0.0-alpha.20",
|
||||||
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.19.tgz",
|
"resolved": "https://registry.npmjs.org/@oceanprotocol/contracts/-/contracts-1.0.0-alpha.20.tgz",
|
||||||
"integrity": "sha512-3E4eMo2lMyWMjiGk5dvSZvs/QNq7GSAPPzfMbxVLCdjfyP7kvVVVgn0pxabQtexkK4NK7tpNdA+IbsJaM0BBdw==",
|
"integrity": "sha512-Z+zP7XzYjZfd0+URupld2LLZ91E07EWM4wlxpRGOhXEZ7oL3iQAlRJGq6SZN7C65LSUaMQuhj+n5C8aYOXUdwQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@openzeppelin/contracts": "^4.3.3",
|
"@openzeppelin/contracts": "^4.3.3",
|
||||||
"@openzeppelin/test-helpers": "^0.5.15",
|
"@openzeppelin/test-helpers": "^0.5.15",
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
"web3": "^1.7.0"
|
"web3": "^1.7.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/contracts": "1.0.0-alpha.19",
|
"@oceanprotocol/contracts": "1.0.0-alpha.20",
|
||||||
"bignumber.js": "^9.0.2",
|
"bignumber.js": "^9.0.2",
|
||||||
"cross-fetch": "^3.1.5",
|
"cross-fetch": "^3.1.5",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
|
@ -21,7 +21,7 @@ export interface FreOrderParams {
|
|||||||
|
|
||||||
export interface PriceAndFees {
|
export interface PriceAndFees {
|
||||||
baseTokenAmount: string
|
baseTokenAmount: string
|
||||||
baseTokenAmountBeforeFee: string
|
|
||||||
oceanFeeAmount: string
|
oceanFeeAmount: string
|
||||||
marketFeeAmount: string
|
marketFeeAmount: string
|
||||||
|
consumeMarketFeeAmount: string
|
||||||
}
|
}
|
||||||
|
@ -270,6 +270,25 @@ export class Pool {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get getMarketFee
|
||||||
|
* @param {String} poolAddress
|
||||||
|
* @return {String}
|
||||||
|
*/
|
||||||
|
async getMarketFee(poolAddress: string): Promise<string> {
|
||||||
|
const pool = setContractDefaults(
|
||||||
|
new this.web3.eth.Contract(this.poolAbi, poolAddress),
|
||||||
|
this.config
|
||||||
|
)
|
||||||
|
let result = null
|
||||||
|
try {
|
||||||
|
result = await pool.methods.getMarketFee().call()
|
||||||
|
} catch (e) {
|
||||||
|
LoggerInstance.error(`ERROR: Failed to get getMarketFee: ${e.message}`)
|
||||||
|
}
|
||||||
|
return this.web3.utils.fromWei(result).toString()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get marketFeeCollector of this pool
|
* Get marketFeeCollector of this pool
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
@ -673,17 +692,19 @@ export class Pool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Estimate gas cost for updateMarketFeeCollector
|
* Estimate gas cost for updatePublishMarketFee
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @param {String} newCollector new market fee collector address
|
* @param {String} newPublishMarketAddress new market address
|
||||||
|
* @param {String} newPublishMarketSwapFee new market swap fee
|
||||||
* @param {Contract} contractInstance optional contract instance
|
* @param {Contract} contractInstance optional contract instance
|
||||||
* @return {Promise<number>}
|
* @return {Promise<number>}
|
||||||
*/
|
*/
|
||||||
public async estUpdateMarketFeeCollector(
|
public async estUpdatePublishMarketFee(
|
||||||
address: string,
|
address: string,
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
newCollector: string,
|
newPublishMarketAddress: string,
|
||||||
|
newPublishMarketSwapFee: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const poolContract =
|
const poolContract =
|
||||||
@ -697,7 +718,7 @@ export class Pool {
|
|||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
estGas = await poolContract.methods
|
estGas = await poolContract.methods
|
||||||
.updateMarketFeeCollector(newCollector)
|
.updatePublishMarketFee(newPublishMarketAddress, newPublishMarketSwapFee)
|
||||||
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: address }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
estGas = gasLimitDefault
|
estGas = gasLimitDefault
|
||||||
@ -706,16 +727,18 @@ export class Pool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* updateMarketFeeCollector - updates marketFeeCollector - can be called only by the marketFeeCollector
|
* updatePublishMarketFee - sets a new newPublishMarketAddress and new newPublishMarketSwapFee- can be called only by the marketFeeCollector
|
||||||
* @param {String} address
|
* @param {String} address
|
||||||
* @param {String} poolAddress
|
* @param {String} poolAddress
|
||||||
* @param {String} newCollector new market fee collector address
|
* @param {String} newPublishMarketAddress new market fee collector address
|
||||||
|
* @param {String} newPublishMarketSwapFee fee recieved by the publisher market when a dt is swaped from a pool, percent
|
||||||
* @return {TransactionReceipt}
|
* @return {TransactionReceipt}
|
||||||
*/
|
*/
|
||||||
async updateMarketFeeCollector(
|
async updatePublishMarketFee(
|
||||||
address: string,
|
address: string,
|
||||||
poolAddress: string,
|
poolAddress: string,
|
||||||
newCollector: string
|
newPublishMarketAddress: string,
|
||||||
|
newPublishMarketSwapFee: string
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
if ((await this.getMarketFeeCollector(poolAddress)) !== address) {
|
if ((await this.getMarketFeeCollector(poolAddress)) !== address) {
|
||||||
throw new Error(`Caller is not MarketFeeCollector`)
|
throw new Error(`Caller is not MarketFeeCollector`)
|
||||||
@ -725,20 +748,26 @@ export class Pool {
|
|||||||
this.config
|
this.config
|
||||||
)
|
)
|
||||||
let result = null
|
let result = null
|
||||||
const estGas = await this.estUpdateMarketFeeCollector(
|
|
||||||
|
const estGas = await this.estUpdatePublishMarketFee(
|
||||||
address,
|
address,
|
||||||
poolAddress,
|
poolAddress,
|
||||||
newCollector
|
newPublishMarketAddress,
|
||||||
|
this.web3.utils.toWei(newPublishMarketSwapFee)
|
||||||
)
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = await pool.methods.updateMarketFeeCollector(newCollector).send({
|
result = await pool.methods
|
||||||
from: address,
|
.updatePublishMarketFee(
|
||||||
gas: estGas + 1,
|
newPublishMarketAddress,
|
||||||
gasPrice: await getFairGasPrice(this.web3, this.config)
|
this.web3.utils.toWei(newPublishMarketSwapFee)
|
||||||
})
|
)
|
||||||
|
.send({
|
||||||
|
from: address,
|
||||||
|
gas: estGas + 1,
|
||||||
|
gasPrice: await getFairGasPrice(this.web3, this.config)
|
||||||
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(`ERROR: Failed to swap exact amount in : ${e.message}`)
|
LoggerInstance.error(`ERROR: Failed to updatePublishMarketFee : ${e.message}`)
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -120,6 +120,8 @@ export class FixedRateExchange {
|
|||||||
* @param {String} account
|
* @param {String} account
|
||||||
* @param {String} dtAmount datatoken amount we want to buy
|
* @param {String} dtAmount datatoken amount we want to buy
|
||||||
* @param {String} datatokenAddress datatokenAddress
|
* @param {String} datatokenAddress datatokenAddress
|
||||||
|
* @param {String} consumeMarketAddress consumeMarketAddress
|
||||||
|
* @param {String} consumeMarketFee fee recieved by the consume market when a dt is bought from a fixed rate exchange, percent
|
||||||
* @param {Contract} contractInstance optional contract instance
|
* @param {Contract} contractInstance optional contract instance
|
||||||
* @return {Promise<number>}
|
* @return {Promise<number>}
|
||||||
*/
|
*/
|
||||||
@ -128,6 +130,8 @@ export class FixedRateExchange {
|
|||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
dtAmount: string,
|
dtAmount: string,
|
||||||
maxBaseTokenAmount: string,
|
maxBaseTokenAmount: string,
|
||||||
|
consumeMarketAddress: string,
|
||||||
|
consumeMarketFee: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
@ -135,7 +139,13 @@ export class FixedRateExchange {
|
|||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
estGas = await fixedRate.methods
|
estGas = await fixedRate.methods
|
||||||
.buyDT(datatokenAddress, dtAmount.toString(), maxBaseTokenAmount.toString())
|
.buyDT(
|
||||||
|
datatokenAddress,
|
||||||
|
dtAmount,
|
||||||
|
maxBaseTokenAmount,
|
||||||
|
consumeMarketAddress,
|
||||||
|
consumeMarketFee
|
||||||
|
)
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
estGas = gasLimitDefault
|
estGas = gasLimitDefault
|
||||||
@ -149,14 +159,19 @@ export class FixedRateExchange {
|
|||||||
* @param {String} datatokenAmount Amount of datatokens
|
* @param {String} datatokenAmount Amount of datatokens
|
||||||
* @param {String} maxBaseTokenAmount max amount of baseToken we want to pay for datatokenAmount
|
* @param {String} maxBaseTokenAmount max amount of baseToken we want to pay for datatokenAmount
|
||||||
* @param {String} address User address
|
* @param {String} address User address
|
||||||
|
* @param {String} consumeMarketAddress consumeMarketAddress
|
||||||
|
* @param {String} consumeMarketFee consumeMarketFee
|
||||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||||
*/
|
*/
|
||||||
public async buyDT(
|
public async buyDT(
|
||||||
address: string,
|
address: string,
|
||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
datatokenAmount: string,
|
datatokenAmount: string,
|
||||||
maxBaseTokenAmount: string
|
maxBaseTokenAmount: string,
|
||||||
|
consumeMarketAddress: string = '0x0000000000000000000000000000000000000000',
|
||||||
|
consumeMarketFee: string = '0'
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
|
const consumeMarketFeeFormatted = await this.web3.utils.toWei(consumeMarketFee)
|
||||||
const dtAmountFormatted = await this.amountToUnits(
|
const dtAmountFormatted = await this.amountToUnits(
|
||||||
(
|
(
|
||||||
await this.getExchange(exchangeId)
|
await this.getExchange(exchangeId)
|
||||||
@ -174,11 +189,19 @@ export class FixedRateExchange {
|
|||||||
address,
|
address,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
maxBtFormatted
|
maxBtFormatted,
|
||||||
|
consumeMarketAddress,
|
||||||
|
consumeMarketFeeFormatted
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.contract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.buyDT(exchangeId, dtAmountFormatted, maxBtFormatted)
|
.buyDT(
|
||||||
|
exchangeId,
|
||||||
|
dtAmountFormatted,
|
||||||
|
maxBtFormatted,
|
||||||
|
consumeMarketAddress,
|
||||||
|
consumeMarketFeeFormatted
|
||||||
|
)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
@ -196,6 +219,8 @@ export class FixedRateExchange {
|
|||||||
* @param {String} account
|
* @param {String} account
|
||||||
* @param {String} dtAmount datatoken amount we want to sell
|
* @param {String} dtAmount datatoken amount we want to sell
|
||||||
* @param {String} datatokenAddress datatokenAddress
|
* @param {String} datatokenAddress datatokenAddress
|
||||||
|
* @param {String} consumeMarketAddress consumeMarketAddress
|
||||||
|
* @param {String} consumeMarketFee consumeMarketFee
|
||||||
* @param {Contract} contractInstance optional contract instance
|
* @param {Contract} contractInstance optional contract instance
|
||||||
* @return {Promise<number>}
|
* @return {Promise<number>}
|
||||||
*/
|
*/
|
||||||
@ -204,6 +229,8 @@ export class FixedRateExchange {
|
|||||||
datatokenAddress: string,
|
datatokenAddress: string,
|
||||||
dtAmount: string,
|
dtAmount: string,
|
||||||
maxBaseTokenAmount: string,
|
maxBaseTokenAmount: string,
|
||||||
|
consumeMarketAddress: string,
|
||||||
|
consumeMarketFee: string,
|
||||||
contractInstance?: Contract
|
contractInstance?: Contract
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
const fixedRate = contractInstance || this.fixedRateContract
|
const fixedRate = contractInstance || this.fixedRateContract
|
||||||
@ -211,7 +238,13 @@ export class FixedRateExchange {
|
|||||||
let estGas
|
let estGas
|
||||||
try {
|
try {
|
||||||
estGas = await fixedRate.methods
|
estGas = await fixedRate.methods
|
||||||
.sellDT(datatokenAddress, dtAmount, maxBaseTokenAmount)
|
.sellDT(
|
||||||
|
datatokenAddress,
|
||||||
|
dtAmount,
|
||||||
|
maxBaseTokenAmount,
|
||||||
|
consumeMarketAddress,
|
||||||
|
consumeMarketFee
|
||||||
|
)
|
||||||
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
.estimateGas({ from: account }, (err, estGas) => (err ? gasLimitDefault : estGas))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
estGas = gasLimitDefault
|
estGas = gasLimitDefault
|
||||||
@ -225,14 +258,19 @@ export class FixedRateExchange {
|
|||||||
* @param {String} datatokenAmount Amount of datatokens
|
* @param {String} datatokenAmount Amount of datatokens
|
||||||
* @param {String} minBaseTokenAmount min amount of baseToken we want to receive back
|
* @param {String} minBaseTokenAmount min amount of baseToken we want to receive back
|
||||||
* @param {String} address User address
|
* @param {String} address User address
|
||||||
|
* @param {String} consumeMarketAddress consumeMarketAddress
|
||||||
|
* @param {String} consumeMarketFee consumeMarketFee
|
||||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||||
*/
|
*/
|
||||||
public async sellDT(
|
public async sellDT(
|
||||||
address: string,
|
address: string,
|
||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
datatokenAmount: string,
|
datatokenAmount: string,
|
||||||
minBaseTokenAmount: string
|
minBaseTokenAmount: string,
|
||||||
|
consumeMarketAddress: string = '0x0000000000000000000000000000000000000000',
|
||||||
|
consumeMarketFee: string = '0'
|
||||||
): Promise<TransactionReceipt> {
|
): Promise<TransactionReceipt> {
|
||||||
|
const consumeMarketFeeFormatted = await this.web3.utils.toWei(consumeMarketFee)
|
||||||
const dtAmountFormatted = await this.amountToUnits(
|
const dtAmountFormatted = await this.amountToUnits(
|
||||||
(
|
(
|
||||||
await this.getExchange(exchangeId)
|
await this.getExchange(exchangeId)
|
||||||
@ -249,11 +287,19 @@ export class FixedRateExchange {
|
|||||||
address,
|
address,
|
||||||
exchangeId,
|
exchangeId,
|
||||||
dtAmountFormatted,
|
dtAmountFormatted,
|
||||||
minBtFormatted
|
minBtFormatted,
|
||||||
|
consumeMarketAddress,
|
||||||
|
consumeMarketFeeFormatted
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
const trxReceipt = await this.contract.methods
|
const trxReceipt = await this.contract.methods
|
||||||
.sellDT(exchangeId, dtAmountFormatted, minBtFormatted)
|
.sellDT(
|
||||||
|
exchangeId,
|
||||||
|
dtAmountFormatted,
|
||||||
|
minBtFormatted,
|
||||||
|
consumeMarketAddress,
|
||||||
|
consumeMarketFeeFormatted
|
||||||
|
)
|
||||||
.send({
|
.send({
|
||||||
from: address,
|
from: address,
|
||||||
gas: estGas + 1,
|
gas: estGas + 1,
|
||||||
@ -533,17 +579,20 @@ export class FixedRateExchange {
|
|||||||
* calcBaseInGivenOutDT - Calculates how many base tokens are needed to get specified amount of datatokens
|
* calcBaseInGivenOutDT - Calculates how many base tokens are needed to get specified amount of datatokens
|
||||||
* @param {String} exchangeId ExchangeId
|
* @param {String} exchangeId ExchangeId
|
||||||
* @param {string} datatokenAmount Amount of datatokens user wants to buy
|
* @param {string} datatokenAmount Amount of datatokens user wants to buy
|
||||||
|
* @param {String} consumeMarketFee consumeMarketFee
|
||||||
* @return {Promise<PriceAndFees>} how many base tokens are needed and fees
|
* @return {Promise<PriceAndFees>} how many base tokens are needed and fees
|
||||||
*/
|
*/
|
||||||
public async calcBaseInGivenOutDT(
|
public async calcBaseInGivenOutDT(
|
||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
datatokenAmount: string
|
datatokenAmount: string,
|
||||||
|
consumeMarketFee: string = '0'
|
||||||
): Promise<PriceAndFees> {
|
): Promise<PriceAndFees> {
|
||||||
const fixedRateExchange = await this.getExchange(exchangeId)
|
const fixedRateExchange = await this.getExchange(exchangeId)
|
||||||
const result = await this.contract.methods
|
const result = await this.contract.methods
|
||||||
.calcBaseInGivenOutDT(
|
.calcBaseInGivenOutDT(
|
||||||
exchangeId,
|
exchangeId,
|
||||||
await this.amountToUnits(fixedRateExchange.datatoken, datatokenAmount)
|
await this.amountToUnits(fixedRateExchange.datatoken, datatokenAmount),
|
||||||
|
this.web3.utils.toWei(consumeMarketFee)
|
||||||
)
|
)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
@ -552,10 +601,6 @@ export class FixedRateExchange {
|
|||||||
fixedRateExchange.baseToken,
|
fixedRateExchange.baseToken,
|
||||||
result.baseTokenAmount
|
result.baseTokenAmount
|
||||||
),
|
),
|
||||||
baseTokenAmountBeforeFee: await this.unitsToAmount(
|
|
||||||
fixedRateExchange.baseToken,
|
|
||||||
result.baseTokenAmountBeforeFee
|
|
||||||
),
|
|
||||||
marketFeeAmount: await this.unitsToAmount(
|
marketFeeAmount: await this.unitsToAmount(
|
||||||
fixedRateExchange.baseToken,
|
fixedRateExchange.baseToken,
|
||||||
result.marketFeeAmount
|
result.marketFeeAmount
|
||||||
@ -563,6 +608,10 @@ export class FixedRateExchange {
|
|||||||
oceanFeeAmount: await this.unitsToAmount(
|
oceanFeeAmount: await this.unitsToAmount(
|
||||||
fixedRateExchange.baseToken,
|
fixedRateExchange.baseToken,
|
||||||
result.oceanFeeAmount
|
result.oceanFeeAmount
|
||||||
|
),
|
||||||
|
consumeMarketFeeAmount: await this.unitsToAmount(
|
||||||
|
fixedRateExchange.baseToken,
|
||||||
|
result.consumeMarketFeeAmount
|
||||||
)
|
)
|
||||||
} as PriceAndFees
|
} as PriceAndFees
|
||||||
return priceAndFees
|
return priceAndFees
|
||||||
@ -572,11 +621,13 @@ export class FixedRateExchange {
|
|||||||
* getBTOut - returns amount in baseToken that user will receive for datatokenAmount sold
|
* getBTOut - returns amount in baseToken that user will receive for datatokenAmount sold
|
||||||
* @param {String} exchangeId ExchangeId
|
* @param {String} exchangeId ExchangeId
|
||||||
* @param {Number} datatokenAmount Amount of datatokens
|
* @param {Number} datatokenAmount Amount of datatokens
|
||||||
|
* @param {String} consumeMarketFee consumeMarketFee
|
||||||
* @return {Promise<string>} Amount of baseTokens user will receive
|
* @return {Promise<string>} Amount of baseTokens user will receive
|
||||||
*/
|
*/
|
||||||
public async getAmountBTOut(
|
public async getAmountBTOut(
|
||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
datatokenAmount: string
|
datatokenAmount: string,
|
||||||
|
consumeMarketFee: string = '0'
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const result = await this.contract.methods
|
const result = await this.contract.methods
|
||||||
.calcBaseOutGivenInDT(
|
.calcBaseOutGivenInDT(
|
||||||
@ -586,7 +637,8 @@ export class FixedRateExchange {
|
|||||||
await this.getExchange(exchangeId)
|
await this.getExchange(exchangeId)
|
||||||
).datatoken,
|
).datatoken,
|
||||||
datatokenAmount
|
datatokenAmount
|
||||||
)
|
),
|
||||||
|
this.web3.utils.toWei(consumeMarketFee)
|
||||||
)
|
)
|
||||||
.call()
|
.call()
|
||||||
|
|
||||||
@ -594,7 +646,7 @@ export class FixedRateExchange {
|
|||||||
(
|
(
|
||||||
await this.getExchange(exchangeId)
|
await this.getExchange(exchangeId)
|
||||||
).baseToken,
|
).baseToken,
|
||||||
result.baseTokenAmount
|
result[0]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -560,10 +560,14 @@ describe('Pool unit test', () => {
|
|||||||
|
|
||||||
it('#updateMarketFeeCollector- should update market fee collector', async () => {
|
it('#updateMarketFeeCollector- should update market fee collector', async () => {
|
||||||
// contracts.accounts[0] is the marketFeeCollector
|
// contracts.accounts[0] is the marketFeeCollector
|
||||||
|
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
||||||
|
await pool.updatePublishMarketFee(
|
||||||
await pool.updateMarketFeeCollector(contracts.accounts[0], poolAddress, user3)
|
contracts.accounts[0],
|
||||||
|
poolAddress,
|
||||||
|
user3,
|
||||||
|
await pool.getMarketFee(poolAddress)
|
||||||
|
)
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === user3)
|
assert((await pool.getMarketFeeCollector(poolAddress)) === user3)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -1079,7 +1083,12 @@ describe('Pool unit test', () => {
|
|||||||
// contracts.accounts[0] is the marketFeeCollector
|
// contracts.accounts[0] is the marketFeeCollector
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
assert((await pool.getMarketFeeCollector(poolAddress)) === contracts.accounts[0])
|
||||||
|
|
||||||
await pool.updateMarketFeeCollector(contracts.accounts[0], poolAddress, user3)
|
await pool.updatePublishMarketFee(
|
||||||
|
contracts.accounts[0],
|
||||||
|
poolAddress,
|
||||||
|
user3,
|
||||||
|
await pool.getMarketFee(poolAddress)
|
||||||
|
)
|
||||||
|
|
||||||
assert((await pool.getMarketFeeCollector(poolAddress)) === user3)
|
assert((await pool.getMarketFeeCollector(poolAddress)) === user3)
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user