mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
general renaming in FixedRateExchange
This commit is contained in:
parent
76bbf49d93
commit
83b8d1dce3
@ -33,7 +33,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
* @param {String} consumeMarketFee consumeMarketFee in fraction
|
* @param {String} consumeMarketFee consumeMarketFee in fraction
|
||||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||||
*/
|
*/
|
||||||
public async buyDT<G extends boolean = false>(
|
public async buyDatatokens<G extends boolean = false>(
|
||||||
address: string,
|
address: string,
|
||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
datatokenAmount: string,
|
datatokenAmount: string,
|
||||||
@ -97,7 +97,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
* @param {String} consumeMarketFee consumeMarketFee in fraction
|
* @param {String} consumeMarketFee consumeMarketFee in fraction
|
||||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||||
*/
|
*/
|
||||||
public async sellDT<G extends boolean = false>(
|
public async sellDatatokens<G extends boolean = false>(
|
||||||
address: string,
|
address: string,
|
||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
datatokenAmount: string,
|
datatokenAmount: string,
|
||||||
@ -299,7 +299,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
* @param {String} exchangeId ExchangeId
|
* @param {String} exchangeId ExchangeId
|
||||||
* @return {Promise<string>} dt supply formatted
|
* @return {Promise<string>} dt supply formatted
|
||||||
*/
|
*/
|
||||||
public async getDTSupply(exchangeId: string): Promise<string> {
|
public async getDatatokenSupply(exchangeId: string): Promise<string> {
|
||||||
const dtSupply = await this.contract.methods.getDTSupply(exchangeId).call()
|
const dtSupply = await this.contract.methods.getDTSupply(exchangeId).call()
|
||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
return await this.unitsToAmount(exchange.datatoken, dtSupply, +exchange.dtDecimals)
|
return await this.unitsToAmount(exchange.datatoken, dtSupply, +exchange.dtDecimals)
|
||||||
@ -310,7 +310,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
* @param {String} exchangeId ExchangeId
|
* @param {String} exchangeId ExchangeId
|
||||||
* @return {Promise<string>} dt supply formatted
|
* @return {Promise<string>} dt supply formatted
|
||||||
*/
|
*/
|
||||||
public async getBTSupply(exchangeId: string): Promise<string> {
|
public async getBasetokenSupply(exchangeId: string): Promise<string> {
|
||||||
const btSupply = await this.contract.methods.getBTSupply(exchangeId).call()
|
const btSupply = await this.contract.methods.getBTSupply(exchangeId).call()
|
||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
return await this.unitsToAmount(exchange.baseToken, btSupply, +exchange.btDecimals)
|
return await this.unitsToAmount(exchange.baseToken, btSupply, +exchange.btDecimals)
|
||||||
@ -326,19 +326,19 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* calcBaseInGivenOutDT - Calculates how many base tokens are needed to get specified amount of datatokens
|
* calcBaseInGivenDatatokensOut - 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 in fraction
|
* @param {String} consumeMarketFee consumeMarketFee in fraction
|
||||||
* @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 calcBaseInGivenDatatokensOut(
|
||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
datatokenAmount: string,
|
datatokenAmount: string,
|
||||||
consumeMarketFee: string = '0'
|
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 outDT = await this.contract.methods
|
||||||
.calcBaseInGivenOutDT(
|
.calcBaseInGivenOutDT(
|
||||||
exchangeId,
|
exchangeId,
|
||||||
await this.amountToUnits(
|
await this.amountToUnits(
|
||||||
@ -353,22 +353,22 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
const priceAndFees = {
|
const priceAndFees = {
|
||||||
baseTokenAmount: await this.unitsToAmount(
|
baseTokenAmount: await this.unitsToAmount(
|
||||||
fixedRateExchange.baseToken,
|
fixedRateExchange.baseToken,
|
||||||
result.baseTokenAmount,
|
outDT.baseTokenAmount,
|
||||||
+fixedRateExchange.btDecimals
|
+fixedRateExchange.btDecimals
|
||||||
),
|
),
|
||||||
marketFeeAmount: await this.unitsToAmount(
|
marketFeeAmount: await this.unitsToAmount(
|
||||||
fixedRateExchange.baseToken,
|
fixedRateExchange.baseToken,
|
||||||
result.marketFeeAmount,
|
outDT.marketFeeAmount,
|
||||||
+fixedRateExchange.btDecimals
|
+fixedRateExchange.btDecimals
|
||||||
),
|
),
|
||||||
oceanFeeAmount: await this.unitsToAmount(
|
oceanFeeAmount: await this.unitsToAmount(
|
||||||
fixedRateExchange.baseToken,
|
fixedRateExchange.baseToken,
|
||||||
result.oceanFeeAmount,
|
outDT.oceanFeeAmount,
|
||||||
+fixedRateExchange.btDecimals
|
+fixedRateExchange.btDecimals
|
||||||
),
|
),
|
||||||
consumeMarketFeeAmount: await this.unitsToAmount(
|
consumeMarketFeeAmount: await this.unitsToAmount(
|
||||||
fixedRateExchange.baseToken,
|
fixedRateExchange.baseToken,
|
||||||
result.consumeMarketFeeAmount,
|
outDT.consumeMarketFeeAmount,
|
||||||
+fixedRateExchange.btDecimals
|
+fixedRateExchange.btDecimals
|
||||||
)
|
)
|
||||||
} as PriceAndFees
|
} as PriceAndFees
|
||||||
@ -382,7 +382,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
* @param {String} consumeMarketFee consumeMarketFee in fraction
|
* @param {String} consumeMarketFee consumeMarketFee in fraction
|
||||||
* @return {Promise<string>} Amount of baseTokens user will receive
|
* @return {Promise<string>} Amount of baseTokens user will receive
|
||||||
*/
|
*/
|
||||||
public async getAmountBTOut(
|
public async getAmountBasetokensOut(
|
||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
datatokenAmount: string,
|
datatokenAmount: string,
|
||||||
consumeMarketFee: string = '0'
|
consumeMarketFee: string = '0'
|
||||||
@ -409,34 +409,34 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
* @return {Promise<FixedPricedExchange>} Exchange details
|
* @return {Promise<FixedPricedExchange>} Exchange details
|
||||||
*/
|
*/
|
||||||
public async getExchange(exchangeId: string): Promise<FixedPriceExchange> {
|
public async getExchange(exchangeId: string): Promise<FixedPriceExchange> {
|
||||||
const result: FixedPriceExchange = await this.contract.methods
|
const exchange: FixedPriceExchange = await this.contract.methods
|
||||||
.getExchange(exchangeId)
|
.getExchange(exchangeId)
|
||||||
.call()
|
.call()
|
||||||
result.dtDecimals = result.dtDecimals.toString()
|
exchange.dtDecimals = exchange.dtDecimals.toString()
|
||||||
result.btDecimals = result.btDecimals.toString()
|
exchange.btDecimals = exchange.btDecimals.toString()
|
||||||
result.dtBalance = await this.unitsToAmount(
|
exchange.dtBalance = await this.unitsToAmount(
|
||||||
result.datatoken,
|
exchange.datatoken,
|
||||||
result.dtBalance,
|
exchange.dtBalance,
|
||||||
+result.dtDecimals
|
+exchange.dtDecimals
|
||||||
)
|
)
|
||||||
result.btBalance = await this.unitsToAmount(
|
exchange.btBalance = await this.unitsToAmount(
|
||||||
result.baseToken,
|
exchange.baseToken,
|
||||||
result.btBalance,
|
exchange.btBalance,
|
||||||
+result.btDecimals
|
+exchange.btDecimals
|
||||||
)
|
)
|
||||||
result.dtSupply = await this.unitsToAmount(
|
exchange.dtSupply = await this.unitsToAmount(
|
||||||
result.datatoken,
|
exchange.datatoken,
|
||||||
result.dtSupply,
|
exchange.dtSupply,
|
||||||
+result.dtDecimals
|
+exchange.dtDecimals
|
||||||
)
|
)
|
||||||
result.btSupply = await this.unitsToAmount(
|
exchange.btSupply = await this.unitsToAmount(
|
||||||
result.baseToken,
|
exchange.baseToken,
|
||||||
result.btSupply,
|
exchange.btSupply,
|
||||||
+result.btDecimals
|
+exchange.btDecimals
|
||||||
)
|
)
|
||||||
result.fixedRate = this.web3.utils.fromWei(result.fixedRate)
|
exchange.fixedRate = this.web3.utils.fromWei(exchange.fixedRate)
|
||||||
result.exchangeId = exchangeId
|
exchange.exchangeId = exchangeId
|
||||||
return result
|
return exchange
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -445,24 +445,24 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
* @return {Promise<FixedPricedExchange>} Exchange details
|
* @return {Promise<FixedPricedExchange>} Exchange details
|
||||||
*/
|
*/
|
||||||
public async getFeesInfo(exchangeId: string): Promise<FeesInfo> {
|
public async getFeesInfo(exchangeId: string): Promise<FeesInfo> {
|
||||||
const result: FeesInfo = await this.contract.methods.getFeesInfo(exchangeId).call()
|
const feesInfo: FeesInfo = await this.contract.methods.getFeesInfo(exchangeId).call()
|
||||||
result.opcFee = this.web3.utils.fromWei(result.opcFee.toString())
|
feesInfo.opcFee = this.web3.utils.fromWei(feesInfo.opcFee.toString())
|
||||||
result.marketFee = this.web3.utils.fromWei(result.marketFee.toString())
|
feesInfo.marketFee = this.web3.utils.fromWei(feesInfo.marketFee.toString())
|
||||||
|
|
||||||
const exchange = await this.getExchange(exchangeId)
|
const exchange = await this.getExchange(exchangeId)
|
||||||
result.marketFeeAvailable = await this.unitsToAmount(
|
feesInfo.marketFeeAvailable = await this.unitsToAmount(
|
||||||
exchange.baseToken,
|
exchange.baseToken,
|
||||||
result.marketFeeAvailable,
|
feesInfo.marketFeeAvailable,
|
||||||
+exchange.btDecimals
|
+exchange.btDecimals
|
||||||
)
|
)
|
||||||
result.oceanFeeAvailable = await this.unitsToAmount(
|
feesInfo.oceanFeeAvailable = await this.unitsToAmount(
|
||||||
exchange.baseToken,
|
exchange.baseToken,
|
||||||
result.oceanFeeAvailable,
|
feesInfo.oceanFeeAvailable,
|
||||||
+exchange.btDecimals
|
+exchange.btDecimals
|
||||||
)
|
)
|
||||||
|
|
||||||
result.exchangeId = exchangeId
|
feesInfo.exchangeId = exchangeId
|
||||||
return result
|
return feesInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -480,8 +480,8 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
* @return {Promise<Boolean>} Result
|
* @return {Promise<Boolean>} Result
|
||||||
*/
|
*/
|
||||||
public async isActive(exchangeId: string): Promise<boolean> {
|
public async isActive(exchangeId: string): Promise<boolean> {
|
||||||
const result = await this.contract.methods.isActive(exchangeId).call()
|
const active = await this.contract.methods.isActive(exchangeId).call()
|
||||||
return result
|
return active
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -558,7 +558,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
* @param {String} amount amount to be collected
|
* @param {String} amount amount to be collected
|
||||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||||
*/
|
*/
|
||||||
public async collectBT<G extends boolean = false>(
|
public async collectBasetokens<G extends boolean = false>(
|
||||||
address: string,
|
address: string,
|
||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
@ -599,7 +599,7 @@ export class FixedRateExchange extends SmartContractWithAddress {
|
|||||||
* @param {String} amount amount to be collected
|
* @param {String} amount amount to be collected
|
||||||
* @return {Promise<TransactionReceipt>} transaction receipt
|
* @return {Promise<TransactionReceipt>} transaction receipt
|
||||||
*/
|
*/
|
||||||
public async collectDT<G extends boolean = false>(
|
public async collectDatatokens<G extends boolean = false>(
|
||||||
address: string,
|
address: string,
|
||||||
exchangeId: string,
|
exchangeId: string,
|
||||||
amount: string,
|
amount: string,
|
||||||
|
@ -616,7 +616,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
const fixedRate = new FixedRateExchange(freAddress, web3)
|
const fixedRate = new FixedRateExchange(freAddress, web3)
|
||||||
const oceanAmount = await (
|
const oceanAmount = await (
|
||||||
await fixedRate.calcBaseInGivenOutDT(freId, '1')
|
await fixedRate.calcBaseInGivenDatatokensOut(freId, '1')
|
||||||
).baseTokenAmount
|
).baseTokenAmount
|
||||||
/// ```
|
/// ```
|
||||||
/// Now that the market has fetched those values it can display the asset on the front end. In our case we will just console log the results:
|
/// Now that the market has fetched those values it can display the asset on the front end. In our case we will just console log the results:
|
||||||
@ -659,7 +659,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
/// ```
|
/// ```
|
||||||
/// Now we can make the contract call
|
/// Now we can make the contract call
|
||||||
/// ```Typescript
|
/// ```Typescript
|
||||||
await fixedRate.buyDT(consumerAccount, freId, '1', '2')
|
await fixedRate.buyDatatokens(consumerAccount, freId, '1', '2')
|
||||||
|
|
||||||
consumerOCEANBalance = await balance(web3, addresses.Ocean, consumerAccount)
|
consumerOCEANBalance = await balance(web3, addresses.Ocean, consumerAccount)
|
||||||
console.log(`Consumer OCEAN balance after swap: ${consumerOCEANBalance}`)
|
console.log(`Consumer OCEAN balance after swap: ${consumerOCEANBalance}`)
|
||||||
|
@ -168,31 +168,31 @@ describe('Fixed Rate unit test', () => {
|
|||||||
expect(await fixedRate.getRate(exchangeId)).to.equal('1')
|
expect(await fixedRate.getRate(exchangeId)).to.equal('1')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getDTSupply - should get the dt supply in the exchange', async () => {
|
it('#getDatatokenSupply - should get the dt supply in the exchange', async () => {
|
||||||
// exchange owner hasn't approved any DT for sell
|
// exchange owner hasn't approved any DT for sell
|
||||||
expect(await fixedRate.getDTSupply(exchangeId)).to.equal('0')
|
expect(await fixedRate.getDatatokenSupply(exchangeId)).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getBTSupply - should get the bt supply in the exchange', async () => {
|
it('#getBasetokenSupply - should get the bt supply in the exchange', async () => {
|
||||||
// no baseToken at the beginning
|
// no baseToken at the beginning
|
||||||
expect(await fixedRate.getBTSupply(exchangeId)).to.equal('0')
|
expect(await fixedRate.getBasetokenSupply(exchangeId)).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#calcBaseInGivenOutDT - should get bt amount in for a specific dt amount', async () => {
|
it('#calcBaseInGivenDatatokensOut - should get bt amount in for a specific dt amount', async () => {
|
||||||
// 100.2 DAI for 100 DT (0.1% market fee and 0.1% ocean fee)
|
// 100.2 DAI for 100 DT (0.1% market fee and 0.1% ocean fee)
|
||||||
expect(
|
expect(
|
||||||
await (
|
await (
|
||||||
await fixedRate.calcBaseInGivenOutDT(exchangeId, '100')
|
await fixedRate.calcBaseInGivenDatatokensOut(exchangeId, '100')
|
||||||
).baseTokenAmount
|
).baseTokenAmount
|
||||||
).to.equal('100.3')
|
).to.equal('100.3')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getAmountBTOut - should get bt amount out for a specific dt amount', async () => {
|
it('#getAmountBasetokensOut - should get bt amount out for a specific dt amount', async () => {
|
||||||
// 99.8 DAI for 100 DT (0.1% market fee and 0.1% ocean fee)
|
// 99.8 DAI for 100 DT (0.1% market fee and 0.1% ocean fee)
|
||||||
expect(await fixedRate.getAmountBTOut(exchangeId, '100')).to.equal('99.7')
|
expect(await fixedRate.getAmountBasetokensOut(exchangeId, '100')).to.equal('99.7')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#buyDT - user1 should buy some dt', async () => {
|
it('#buyDatatokens - user1 should buy some dt', async () => {
|
||||||
// total supply is ZERO right now so dt owner mints 1000 DT and approves the fixed rate contract
|
// total supply is ZERO right now so dt owner mints 1000 DT and approves the fixed rate contract
|
||||||
await dtContract.methods
|
await dtContract.methods
|
||||||
.mint(exchangeOwner, web3.utils.toWei('1000'))
|
.mint(exchangeOwner, web3.utils.toWei('1000'))
|
||||||
@ -209,7 +209,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// user1 buys 10 DT
|
// user1 buys 10 DT
|
||||||
const tx = await fixedRate.buyDT(user1, exchangeId, '10', '11')
|
const tx = await fixedRate.buyDatatokens(user1, exchangeId, '10', '11')
|
||||||
// console.log(tx.events.Swapped.returnValues)
|
// console.log(tx.events.Swapped.returnValues)
|
||||||
assert(tx.events.Swapped != null)
|
assert(tx.events.Swapped != null)
|
||||||
const args = tx.events.Swapped.returnValues
|
const args = tx.events.Swapped.returnValues
|
||||||
@ -235,12 +235,12 @@ describe('Fixed Rate unit test', () => {
|
|||||||
expect((await fixedRate.getExchange(exchangeId)).dtBalance).to.equal('0')
|
expect((await fixedRate.getExchange(exchangeId)).dtBalance).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#sellDT - user1 should sell some dt', async () => {
|
it('#sellDatatokens - user1 should sell some dt', async () => {
|
||||||
await approve(web3, user1, dtAddress, contracts.fixedRateAddress, '100')
|
await approve(web3, user1, dtAddress, contracts.fixedRateAddress, '100')
|
||||||
const daiBalanceBefore = new BigNumber(
|
const daiBalanceBefore = new BigNumber(
|
||||||
await balance(web3, contracts.daiAddress, user1)
|
await balance(web3, contracts.daiAddress, user1)
|
||||||
)
|
)
|
||||||
const tx = await fixedRate.sellDT(user1, exchangeId, '10', '9')
|
const tx = await fixedRate.sellDatatokens(user1, exchangeId, '10', '9')
|
||||||
// console.log(tx.events.Swapped.returnValues)
|
// console.log(tx.events.Swapped.returnValues)
|
||||||
assert(tx.events.Swapped != null)
|
assert(tx.events.Swapped != null)
|
||||||
const args = tx.events.Swapped.returnValues
|
const args = tx.events.Swapped.returnValues
|
||||||
@ -263,7 +263,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
// no BTs in the contract (except for the fees, but not accounted here)
|
// no BTs in the contract (except for the fees, but not accounted here)
|
||||||
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
||||||
// DT supply is back at 1000 (exchange Owner allowance + dt balance in the fixed rate)
|
// DT supply is back at 1000 (exchange Owner allowance + dt balance in the fixed rate)
|
||||||
expect(await fixedRate.getDTSupply(exchangeId)).to.equal('1000')
|
expect(await fixedRate.getDatatokenSupply(exchangeId)).to.equal('1000')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getExchange - should return exchange details', async () => {
|
it('#getExchange - should return exchange details', async () => {
|
||||||
@ -307,26 +307,30 @@ describe('Fixed Rate unit test', () => {
|
|||||||
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS)
|
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#collectBT- should collect BT in the contract, if exchangeOwner', async () => {
|
it('#collectBasetokens- should collect BT in the contract, if exchangeOwner', async () => {
|
||||||
// there are no bt in the contract
|
// there are no bt in the contract
|
||||||
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
||||||
// user1 buys 1 DT
|
// user1 buys 1 DT
|
||||||
await fixedRate.buyDT(user1, exchangeId, '1', '2')
|
await fixedRate.buyDatatokens(user1, exchangeId, '1', '2')
|
||||||
// 1 DAI in the contract
|
// 1 DAI in the contract
|
||||||
const fixedRateDetails = await fixedRate.getExchange(exchangeId)
|
const fixedRateDetails = await fixedRate.getExchange(exchangeId)
|
||||||
expect(fixedRateDetails.btBalance).to.equal('1')
|
expect(fixedRateDetails.btBalance).to.equal('1')
|
||||||
// owner collects BTs
|
// owner collects BTs
|
||||||
await fixedRate.collectBT(exchangeOwner, exchangeId, fixedRateDetails.btBalance)
|
await fixedRate.collectBasetokens(
|
||||||
|
exchangeOwner,
|
||||||
|
exchangeId,
|
||||||
|
fixedRateDetails.btBalance
|
||||||
|
)
|
||||||
// btBalance is zero
|
// btBalance is zero
|
||||||
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#collectDT- should collect DT in the contract, if exchangeOwner', async () => {
|
it('#collectDatatokens- should collect DT in the contract, if exchangeOwner', async () => {
|
||||||
const result = await fixedRate.getExchange(exchangeId)
|
const result = await fixedRate.getExchange(exchangeId)
|
||||||
// 9 dts left
|
// 9 dts left
|
||||||
expect(result.dtBalance).to.equal('9')
|
expect(result.dtBalance).to.equal('9')
|
||||||
// owner collects DTs
|
// owner collects DTs
|
||||||
await fixedRate.collectDT(exchangeOwner, exchangeId, result.dtBalance)
|
await fixedRate.collectDatatokens(exchangeOwner, exchangeId, result.dtBalance)
|
||||||
// no more dts in the contract
|
// no more dts in the contract
|
||||||
const result2 = await fixedRate.getExchange(exchangeId)
|
const result2 = await fixedRate.getExchange(exchangeId)
|
||||||
expect(result2.dtBalance).to.equal('0')
|
expect(result2.dtBalance).to.equal('0')
|
||||||
@ -473,31 +477,31 @@ describe('Fixed Rate unit test', () => {
|
|||||||
expect(await fixedRate.getRate(exchangeId)).to.equal('1')
|
expect(await fixedRate.getRate(exchangeId)).to.equal('1')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getDTSupply - should get the dt supply in the exchange', async () => {
|
it('#getDatatokenSupply - should get the dt supply in the exchange', async () => {
|
||||||
// exchange owner hasn't approved any DT for sell
|
// exchange owner hasn't approved any DT for sell
|
||||||
expect(await fixedRate.getDTSupply(exchangeId)).to.equal('0')
|
expect(await fixedRate.getDatatokenSupply(exchangeId)).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getBTSupply - should get the bt supply in the exchange', async () => {
|
it('#getBasetokenSupply - should get the bt supply in the exchange', async () => {
|
||||||
// no baseToken at the beginning
|
// no baseToken at the beginning
|
||||||
expect(await fixedRate.getBTSupply(exchangeId)).to.equal('0')
|
expect(await fixedRate.getBasetokenSupply(exchangeId)).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#calcBaseInGivenOutDT - should get bt amount in for a specific dt amount', async () => {
|
it('#calcBaseInGivenDatatokensOut - should get bt amount in for a specific dt amount', async () => {
|
||||||
// 100.2 USDC for 100 DT (0.1% market fee and 0.1% ocean fee)
|
// 100.2 USDC for 100 DT (0.1% market fee and 0.1% ocean fee)
|
||||||
expect(
|
expect(
|
||||||
await (
|
await (
|
||||||
await fixedRate.calcBaseInGivenOutDT(exchangeId, '100')
|
await fixedRate.calcBaseInGivenDatatokensOut(exchangeId, '100')
|
||||||
).baseTokenAmount
|
).baseTokenAmount
|
||||||
).to.equal('100.3')
|
).to.equal('100.3')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getAmountBTOut - should get bt amount out for a specific dt amount', async () => {
|
it('#getAmountBasetokensOut - should get bt amount out for a specific dt amount', async () => {
|
||||||
// 99.8 USDC for 100 DT (0.1% market fee and 0.1% ocean fee)
|
// 99.8 USDC for 100 DT (0.1% market fee and 0.1% ocean fee)
|
||||||
expect(await fixedRate.getAmountBTOut(exchangeId, '100')).to.equal('99.7')
|
expect(await fixedRate.getAmountBasetokensOut(exchangeId, '100')).to.equal('99.7')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#buyDT - user1 should buy some dt', async () => {
|
it('#buyDatatokens - user1 should buy some dt', async () => {
|
||||||
// total supply is ZERO right now so dt owner mints 1000 DT and approves the fixed rate contract
|
// total supply is ZERO right now so dt owner mints 1000 DT and approves the fixed rate contract
|
||||||
await dtContract.methods
|
await dtContract.methods
|
||||||
.mint(exchangeOwner, web3.utils.toWei('1000'))
|
.mint(exchangeOwner, web3.utils.toWei('1000'))
|
||||||
@ -514,7 +518,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// user1 buys 10 DT
|
// user1 buys 10 DT
|
||||||
const tx = await fixedRate.buyDT(user1, exchangeId, '10', '11')
|
const tx = await fixedRate.buyDatatokens(user1, exchangeId, '10', '11')
|
||||||
// console.log(tx.events.Swapped.returnValues)
|
// console.log(tx.events.Swapped.returnValues)
|
||||||
assert(tx.events.Swapped != null)
|
assert(tx.events.Swapped != null)
|
||||||
const args = tx.events.Swapped.returnValues
|
const args = tx.events.Swapped.returnValues
|
||||||
@ -544,12 +548,12 @@ describe('Fixed Rate unit test', () => {
|
|||||||
expect((await fixedRate.getExchange(exchangeId)).dtBalance).to.equal('0')
|
expect((await fixedRate.getExchange(exchangeId)).dtBalance).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#sellDT - user1 should sell some dt', async () => {
|
it('#sellDatatokens - user1 should sell some dt', async () => {
|
||||||
await approve(web3, user1, dtAddress, contracts.fixedRateAddress, '10')
|
await approve(web3, user1, dtAddress, contracts.fixedRateAddress, '10')
|
||||||
const usdcBalanceBefore = new BigNumber(
|
const usdcBalanceBefore = new BigNumber(
|
||||||
await balance(web3, contracts.usdcAddress, user1)
|
await balance(web3, contracts.usdcAddress, user1)
|
||||||
)
|
)
|
||||||
const tx = await fixedRate.sellDT(user1, exchangeId, '10', '9')
|
const tx = await fixedRate.sellDatatokens(user1, exchangeId, '10', '9')
|
||||||
// console.log(tx.events.Swapped.returnValues)
|
// console.log(tx.events.Swapped.returnValues)
|
||||||
assert(tx.events.Swapped != null)
|
assert(tx.events.Swapped != null)
|
||||||
const args = tx.events.Swapped.returnValues
|
const args = tx.events.Swapped.returnValues
|
||||||
@ -576,7 +580,7 @@ describe('Fixed Rate unit test', () => {
|
|||||||
// no BTs in the contract (except for the fees, but not accounted here)
|
// no BTs in the contract (except for the fees, but not accounted here)
|
||||||
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
||||||
// DT supply is back at 1000 (exchange Owner allowance + dt balance in the fixed rate)
|
// DT supply is back at 1000 (exchange Owner allowance + dt balance in the fixed rate)
|
||||||
expect(await fixedRate.getDTSupply(exchangeId)).to.equal('1000')
|
expect(await fixedRate.getDatatokenSupply(exchangeId)).to.equal('1000')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#getExchange - should return exchange details', async () => {
|
it('#getExchange - should return exchange details', async () => {
|
||||||
@ -620,26 +624,30 @@ describe('Fixed Rate unit test', () => {
|
|||||||
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS)
|
expect(await fixedRate.getAllowedSwapper(exchangeId)).to.equal(ZERO_ADDRESS)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#collectBT- should collect BT in the contract, if exchangeOwner', async () => {
|
it('#collectBasetokens- should collect BT in the contract, if exchangeOwner', async () => {
|
||||||
// there are no bt in the contract
|
// there are no bt in the contract
|
||||||
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
||||||
// user1 buys 1 DT
|
// user1 buys 1 DT
|
||||||
await fixedRate.buyDT(user1, exchangeId, '1', '2')
|
await fixedRate.buyDatatokens(user1, exchangeId, '1', '2')
|
||||||
// 1 DAI in the contract
|
// 1 DAI in the contract
|
||||||
const exchangeDetails = await fixedRate.getExchange(exchangeId)
|
const exchangeDetails = await fixedRate.getExchange(exchangeId)
|
||||||
expect(exchangeDetails.btBalance).to.equal('1')
|
expect(exchangeDetails.btBalance).to.equal('1')
|
||||||
// owner collects BTs
|
// owner collects BTs
|
||||||
await fixedRate.collectBT(exchangeOwner, exchangeId, exchangeDetails.btBalance)
|
await fixedRate.collectBasetokens(
|
||||||
|
exchangeOwner,
|
||||||
|
exchangeId,
|
||||||
|
exchangeDetails.btBalance
|
||||||
|
)
|
||||||
// btBalance is zero
|
// btBalance is zero
|
||||||
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
expect((await fixedRate.getExchange(exchangeId)).btBalance).to.equal('0')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('#collectDT- should collect DT in the contract, if exchangeOwner', async () => {
|
it('#collectDatatokens- should collect DT in the contract, if exchangeOwner', async () => {
|
||||||
const result = await fixedRate.getExchange(exchangeId)
|
const result = await fixedRate.getExchange(exchangeId)
|
||||||
// 9 dts left
|
// 9 dts left
|
||||||
expect(result.dtBalance).to.equal('9')
|
expect(result.dtBalance).to.equal('9')
|
||||||
// owner collects DTs
|
// owner collects DTs
|
||||||
await fixedRate.collectDT(exchangeOwner, exchangeId, result.dtBalance)
|
await fixedRate.collectDatatokens(exchangeOwner, exchangeId, result.dtBalance)
|
||||||
// no more dts in the contract
|
// no more dts in the contract
|
||||||
const result2 = await fixedRate.getExchange(exchangeId)
|
const result2 = await fixedRate.getExchange(exchangeId)
|
||||||
expect(result2.dtBalance).to.equal('0')
|
expect(result2.dtBalance).to.equal('0')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user