mirror of
https://github.com/logos-storage/logos-storage-contracts-eth.git
synced 2026-01-02 13:23:10 +00:00
chore: formatting
This commit is contained in:
parent
da59b7f31c
commit
fd17feaa4c
@ -90,7 +90,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
|
|||||||
config.protocolFeePermille <= 1000,
|
config.protocolFeePermille <= 1000,
|
||||||
Marketplace_ProtocolFeePermilleTooHigh()
|
Marketplace_ProtocolFeePermilleTooHigh()
|
||||||
);
|
);
|
||||||
|
|
||||||
_config = config;
|
_config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,9 +172,9 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
|
|||||||
* @param ask Request's ask
|
* @param ask Request's ask
|
||||||
*/
|
*/
|
||||||
function _collectProtocolFee(address from, Ask memory ask) private {
|
function _collectProtocolFee(address from, Ask memory ask) private {
|
||||||
uint256 fee = protocolFeeForRequestAsk(ask);
|
uint256 fee = protocolFeeForRequestAsk(ask);
|
||||||
_vault.getToken().safeTransferFrom(from, address(0xdead), fee);
|
_vault.getToken().safeTransferFrom(from, address(0xdead), fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Fills a slot. Reverts if an invalid proof of the slot data is
|
* @notice Fills a slot. Reverts if an invalid proof of the slot data is
|
||||||
@ -484,11 +484,13 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
|
|||||||
return _requestContexts[requestId].expiresAt;
|
return _requestContexts[requestId].expiresAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
function protocolFeeForRequestAsk(Ask memory ask) public view returns(uint256) {
|
function protocolFeeForRequestAsk(
|
||||||
|
Ask memory ask
|
||||||
|
) public view returns (uint256) {
|
||||||
TokensPerSecond pricePerSecond = ask.pricePerSecond();
|
TokensPerSecond pricePerSecond = ask.pricePerSecond();
|
||||||
uint128 requestPrice = pricePerSecond.accumulate(ask.duration);
|
uint128 requestPrice = pricePerSecond.accumulate(ask.duration);
|
||||||
|
|
||||||
return (requestPrice/1000) * _config.protocolFeePermille;
|
return (requestPrice / 1000) * _config.protocolFeePermille;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getHost(SlotId slotId) public view returns (address) {
|
function getHost(SlotId slotId) public view returns (address) {
|
||||||
|
|||||||
@ -28,7 +28,7 @@ const {
|
|||||||
maxPriceWithProtocolFee,
|
maxPriceWithProtocolFee,
|
||||||
pricePerSlotPerSecond,
|
pricePerSlotPerSecond,
|
||||||
payoutForDuration,
|
payoutForDuration,
|
||||||
protocolFee
|
protocolFee,
|
||||||
} = require("./price")
|
} = require("./price")
|
||||||
const { collateralPerSlot, repairReward } = require("./collateral")
|
const { collateralPerSlot, repairReward } = require("./collateral")
|
||||||
const {
|
const {
|
||||||
@ -168,7 +168,10 @@ describe("Marketplace", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("emits event when storage is requested", async function () {
|
it("emits event when storage is requested", async function () {
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
const now = await currentTime()
|
const now = await currentTime()
|
||||||
await setNextBlockTimestamp(now)
|
await setNextBlockTimestamp(now)
|
||||||
const expectedExpiry = now + request.expiry
|
const expectedExpiry = now + request.expiry
|
||||||
@ -178,7 +181,10 @@ describe("Marketplace", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("allows retrieval of request details", async function () {
|
it("allows retrieval of request details", async function () {
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
const id = requestId(request)
|
const id = requestId(request)
|
||||||
expect(await marketplace.getRequest(id)).to.be.request(request)
|
expect(await marketplace.getRequest(id)).to.be.request(request)
|
||||||
@ -186,7 +192,10 @@ describe("Marketplace", function () {
|
|||||||
|
|
||||||
it("rejects request with invalid client address", async function () {
|
it("rejects request with invalid client address", async function () {
|
||||||
let invalid = { ...request, client: host.address }
|
let invalid = { ...request, client: host.address }
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(invalid, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(invalid, config)
|
||||||
|
)
|
||||||
await expect(marketplace.requestStorage(invalid)).to.be.revertedWith(
|
await expect(marketplace.requestStorage(invalid)).to.be.revertedWith(
|
||||||
"Marketplace_InvalidClientAddress"
|
"Marketplace_InvalidClientAddress"
|
||||||
)
|
)
|
||||||
@ -209,7 +218,10 @@ describe("Marketplace", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("rejects request when expiry out of bounds", async function () {
|
it("rejects request when expiry out of bounds", async function () {
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
|
|
||||||
request.expiry = request.ask.duration + 1
|
request.expiry = request.ask.duration + 1
|
||||||
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
|
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
|
||||||
@ -237,7 +249,10 @@ describe("Marketplace", function () {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("rejects resubmission of request", async function () {
|
it("rejects resubmission of request", async function () {
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config) * 2)
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config) * 2
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
|
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
|
||||||
"Marketplace_RequestAlreadyExists"
|
"Marketplace_RequestAlreadyExists"
|
||||||
@ -286,7 +301,10 @@ describe("Marketplace", function () {
|
|||||||
describe("filling a slot with collateral", function () {
|
describe("filling a slot with collateral", function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
await token.approve(marketplace.address, collateralPerSlot(request))
|
await token.approve(marketplace.address, collateralPerSlot(request))
|
||||||
@ -366,7 +384,10 @@ describe("Marketplace", function () {
|
|||||||
it("is rejected when request is cancelled", async function () {
|
it("is rejected when request is cancelled", async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
let expired = { ...request, expiry: hours(1) + 1 }
|
let expired = { ...request, expiry: hours(1) + 1 }
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(expired)
|
await marketplace.requestStorage(expired)
|
||||||
await waitUntilCancelled(marketplace, expired)
|
await waitUntilCancelled(marketplace, expired)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
@ -405,7 +426,10 @@ describe("Marketplace", function () {
|
|||||||
marketplace.address,
|
marketplace.address,
|
||||||
collateralPerSlot(request) * lastSlot
|
collateralPerSlot(request) * lastSlot
|
||||||
)
|
)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config) * lastSlot)
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config) * lastSlot
|
||||||
|
)
|
||||||
for (let i = 0; i <= lastSlot; i++) {
|
for (let i = 0; i <= lastSlot; i++) {
|
||||||
await marketplace.reserveSlot(slot.request, i)
|
await marketplace.reserveSlot(slot.request, i)
|
||||||
await marketplace.fillSlot(slot.request, i, proof)
|
await marketplace.fillSlot(slot.request, i, proof)
|
||||||
@ -425,7 +449,10 @@ describe("Marketplace", function () {
|
|||||||
describe("filling slot without collateral", function () {
|
describe("filling slot without collateral", function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
})
|
})
|
||||||
@ -452,7 +479,10 @@ describe("Marketplace", function () {
|
|||||||
describe("submitting proofs when slot is filled", function () {
|
describe("submitting proofs when slot is filled", function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
@ -490,7 +520,10 @@ describe("Marketplace", function () {
|
|||||||
var requestTime
|
var requestTime
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
requestTime = await currentTime()
|
requestTime = await currentTime()
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
@ -534,7 +567,10 @@ describe("Marketplace", function () {
|
|||||||
id = slotId(slot)
|
id = slotId(slot)
|
||||||
|
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
@ -573,7 +609,10 @@ describe("Marketplace", function () {
|
|||||||
describe("paying out a slot", function () {
|
describe("paying out a slot", function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
@ -653,7 +692,10 @@ describe("Marketplace", function () {
|
|||||||
describe("fulfilling a request", function () {
|
describe("fulfilling a request", function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
@ -709,7 +751,10 @@ describe("Marketplace", function () {
|
|||||||
describe("withdrawing funds", function () {
|
describe("withdrawing funds", function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
|
|
||||||
// wait a bit, so that there are funds for the client to withdraw
|
// wait a bit, so that there are funds for the client to withdraw
|
||||||
@ -794,7 +839,9 @@ describe("Marketplace", function () {
|
|||||||
const startBalance = await token.balanceOf(client.address)
|
const startBalance = await token.balanceOf(client.address)
|
||||||
await marketplace.withdrawFunds(slot.request)
|
await marketplace.withdrawFunds(slot.request)
|
||||||
const endBalance = await token.balanceOf(client.address)
|
const endBalance = await token.balanceOf(client.address)
|
||||||
expect(endBalance - startBalance).to.equal(maxPriceWithProtocolFee(request, config) - protocolFee(request, config))
|
expect(endBalance - startBalance).to.equal(
|
||||||
|
maxPriceWithProtocolFee(request, config) - protocolFee(request, config)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("refunds the client for the remaining time when request fails", async function () {
|
it("refunds the client for the remaining time when request fails", async function () {
|
||||||
@ -810,7 +857,9 @@ describe("Marketplace", function () {
|
|||||||
await marketplace.withdrawFunds(slot.request)
|
await marketplace.withdrawFunds(slot.request)
|
||||||
const endBalance = await token.balanceOf(client.address)
|
const endBalance = await token.balanceOf(client.address)
|
||||||
|
|
||||||
const expectedRefund = payoutForDuration(request, startedAt, finishedAt) - protocolFee(request, config)
|
const expectedRefund =
|
||||||
|
payoutForDuration(request, startedAt, finishedAt) -
|
||||||
|
protocolFee(request, config)
|
||||||
expect(endBalance - startBalance).to.be.gte(expectedRefund)
|
expect(endBalance - startBalance).to.be.gte(expectedRefund)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -823,7 +872,11 @@ describe("Marketplace", function () {
|
|||||||
await setNextBlockTimestamp(filledAt)
|
await setNextBlockTimestamp(filledAt)
|
||||||
await marketplace.fillSlot(slot.request, slot.index, proof)
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
||||||
await waitUntilCancelled(marketplace, request)
|
await waitUntilCancelled(marketplace, request)
|
||||||
const expectedPartialHostReward = payoutForDuration(request, filledAt, expiresAt)
|
const expectedPartialHostReward = payoutForDuration(
|
||||||
|
request,
|
||||||
|
filledAt,
|
||||||
|
expiresAt
|
||||||
|
)
|
||||||
|
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
const startBalance = await token.balanceOf(client.address)
|
const startBalance = await token.balanceOf(client.address)
|
||||||
@ -861,7 +914,10 @@ describe("Marketplace", function () {
|
|||||||
|
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
@ -935,7 +991,10 @@ describe("Marketplace", function () {
|
|||||||
;({ periodOf, periodEnd } = periodic(period))
|
;({ periodOf, periodEnd } = periodic(period))
|
||||||
|
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
@ -1005,7 +1064,10 @@ describe("Marketplace", function () {
|
|||||||
describe("slot probability", function () {
|
describe("slot probability", function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
@ -1034,7 +1096,10 @@ describe("Marketplace", function () {
|
|||||||
;({ periodOf, periodEnd } = periodic(period))
|
;({ periodOf, periodEnd } = periodic(period))
|
||||||
|
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
@ -1119,7 +1184,10 @@ describe("Marketplace", function () {
|
|||||||
;({ periodOf, periodEnd } = periodic(period))
|
;({ periodOf, periodEnd } = periodic(period))
|
||||||
|
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
@ -1234,7 +1302,10 @@ describe("Marketplace", function () {
|
|||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
await token.approve(marketplace.address, collateral)
|
await token.approve(marketplace.address, collateral)
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("adds request to list when requesting storage", async function () {
|
it("adds request to list when requesting storage", async function () {
|
||||||
@ -1278,7 +1349,10 @@ describe("Marketplace", function () {
|
|||||||
describe("list of active slots", function () {
|
describe("list of active slots", function () {
|
||||||
beforeEach(async function () {
|
beforeEach(async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
switchAccount(host)
|
switchAccount(host)
|
||||||
const collateral = collateralPerSlot(request)
|
const collateral = collateralPerSlot(request)
|
||||||
@ -1360,24 +1434,35 @@ describe("Marketplace", function () {
|
|||||||
await token.approve(marketplace.address, priceWithProtocolFee)
|
await token.approve(marketplace.address, priceWithProtocolFee)
|
||||||
const startBalance = await token.balanceOf(client.address)
|
const startBalance = await token.balanceOf(client.address)
|
||||||
const startDeadBalance = await token.balanceOf(dead)
|
const startDeadBalance = await token.balanceOf(dead)
|
||||||
await expect(marketplace.requestStorage(request))
|
await expect(marketplace.requestStorage(request)).to.emit(
|
||||||
.to.emit(marketplace, "StorageRequested")
|
marketplace,
|
||||||
|
"StorageRequested"
|
||||||
|
)
|
||||||
const endBalance = await token.balanceOf(client.address)
|
const endBalance = await token.balanceOf(client.address)
|
||||||
const endDeadBalance = await token.balanceOf(dead)
|
const endDeadBalance = await token.balanceOf(dead)
|
||||||
expect(startBalance - endBalance).to.equal(maxPriceWithProtocolFee(request, config))
|
expect(startBalance - endBalance).to.equal(
|
||||||
expect(endDeadBalance - startDeadBalance).to.equal(protocolFee(request, config))
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
|
expect(endDeadBalance - startDeadBalance).to.equal(
|
||||||
|
protocolFee(request, config)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("is not returned when request is cancelled", async function () {
|
it("is not returned when request is cancelled", async function () {
|
||||||
switchAccount(client)
|
switchAccount(client)
|
||||||
await token.approve(marketplace.address, maxPriceWithProtocolFee(request, config))
|
await token.approve(
|
||||||
|
marketplace.address,
|
||||||
|
maxPriceWithProtocolFee(request, config)
|
||||||
|
)
|
||||||
await marketplace.requestStorage(request)
|
await marketplace.requestStorage(request)
|
||||||
await waitUntilCancelled(marketplace, request)
|
await waitUntilCancelled(marketplace, request)
|
||||||
|
|
||||||
const startBalance = await token.balanceOf(client.address)
|
const startBalance = await token.balanceOf(client.address)
|
||||||
await marketplace.withdrawFunds(slot.request)
|
await marketplace.withdrawFunds(slot.request)
|
||||||
const endBalance = await token.balanceOf(client.address)
|
const endBalance = await token.balanceOf(client.address)
|
||||||
expect(endBalance - startBalance).to.equal(maxPriceWithProtocolFee(request, config) - protocolFee(request, config))
|
expect(endBalance - startBalance).to.equal(
|
||||||
|
maxPriceWithProtocolFee(request, config) - protocolFee(request, config)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -3,7 +3,8 @@ function pricePerSlotPerSecond(request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function protocolFee(request, config) {
|
function protocolFee(request, config) {
|
||||||
let requestPrice = request.ask.slots * request.ask.duration * pricePerSlotPerSecond(request)
|
let requestPrice =
|
||||||
|
request.ask.slots * request.ask.duration * pricePerSlotPerSecond(request)
|
||||||
return (requestPrice / 1000) * config.protocolFeePermille
|
return (requestPrice / 1000) * config.protocolFeePermille
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,7 +19,8 @@ function maxPriceWithProtocolFee(request, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function maxPriceWithProtocolFee(request, config) {
|
function maxPriceWithProtocolFee(request, config) {
|
||||||
let requestPrice = request.ask.slots * request.ask.duration * pricePerSlotPerSecond(request)
|
let requestPrice =
|
||||||
|
request.ask.slots * request.ask.duration * pricePerSlotPerSecond(request)
|
||||||
let protocolFee = (requestPrice / 1000) * config.protocolFeePermille
|
let protocolFee = (requestPrice / 1000) * config.protocolFeePermille
|
||||||
return requestPrice + protocolFee
|
return requestPrice + protocolFee
|
||||||
}
|
}
|
||||||
@ -27,4 +29,10 @@ function payoutForDuration(request, start, end) {
|
|||||||
return (end - start) * pricePerSlotPerSecond(request)
|
return (end - start) * pricePerSlotPerSecond(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { maxPrice, maxPriceWithProtocolFee, protocolFee, pricePerSlotPerSecond, payoutForDuration }
|
module.exports = {
|
||||||
|
maxPrice,
|
||||||
|
maxPriceWithProtocolFee,
|
||||||
|
protocolFee,
|
||||||
|
pricePerSlotPerSecond,
|
||||||
|
payoutForDuration,
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user