mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-02-25 07:53:19 +00:00
contracts: reward and collateral addresses no longer supported
This commit is contained in:
parent
4e506ff6f3
commit
bcf72ce066
@ -110,7 +110,7 @@ proc bootstrapInteractions(s: CodexServer): Future[void] {.async.} =
|
||||
|
||||
let marketplace = Marketplace.new(marketplaceAddress, signer)
|
||||
without market =? await OnChainMarket.load(
|
||||
marketplace, config.rewardRecipient, config.marketplaceRequestCacheSize
|
||||
marketplace, config.marketplaceRequestCacheSize
|
||||
), error:
|
||||
fatal "Cannot load market", error = error.msg
|
||||
quit QuitFailure
|
||||
|
||||
@ -355,11 +355,6 @@ type
|
||||
name: "validator-group-index"
|
||||
.}: uint16
|
||||
|
||||
rewardRecipient* {.
|
||||
desc: "Address to send payouts to (eg rewards and refunds)",
|
||||
name: "reward-recipient"
|
||||
.}: Option[EthAddress]
|
||||
|
||||
marketplaceRequestCacheSize* {.
|
||||
desc:
|
||||
"Maximum number of StorageRequests kept in memory." &
|
||||
|
||||
@ -20,7 +20,6 @@ type
|
||||
OnChainMarket* = ref object of Market
|
||||
contract: Marketplace
|
||||
signer: Signer
|
||||
rewardRecipient: ?Address
|
||||
configuration: MarketplaceConfig
|
||||
requestCache: LruCache[string, StorageRequest]
|
||||
|
||||
@ -44,7 +43,6 @@ proc loadConfig(
|
||||
proc load*(
|
||||
_: type OnChainMarket,
|
||||
contract: Marketplace,
|
||||
rewardRecipient = Address.none,
|
||||
requestCacheSize: uint16 = DefaultRequestCacheSize,
|
||||
): Future[?!OnChainMarket] {.async: (raises: [CancelledError]).} =
|
||||
without signer =? contract.signer:
|
||||
@ -55,7 +53,6 @@ proc load*(
|
||||
let market = OnChainMarket(
|
||||
contract: contract,
|
||||
signer: signer,
|
||||
rewardRecipient: rewardRecipient,
|
||||
requestCache: requestCache,
|
||||
)
|
||||
|
||||
@ -245,37 +242,12 @@ method freeSlot*(
|
||||
) {.async: (raises: [CancelledError, MarketError]).} =
|
||||
convertEthersError("Failed to free slot"):
|
||||
try:
|
||||
var freeSlot: Future[Confirmable]
|
||||
if rewardRecipient =? market.rewardRecipient:
|
||||
# If --reward-recipient specified, use it as the reward recipient, and use
|
||||
# the SP's address as the collateral recipient
|
||||
let collateralRecipient = await market.getSigner()
|
||||
# Add 10% to gas estimate to deal with different evm code flow when we
|
||||
# happen to be the one to make the request fail
|
||||
let gas = await market.contract.estimateGas.freeSlot(slotId)
|
||||
let overrides = TransactionOverrides(gasLimit: some (gas * 110) div 100)
|
||||
|
||||
# Add 10% to gas estimate to deal with different evm code flow when we
|
||||
# happen to be the one to make the request fail
|
||||
let gas = await market.contract.estimateGas.freeSlot(
|
||||
slotId, rewardRecipient, collateralRecipient
|
||||
)
|
||||
let overrides = TransactionOverrides(gasLimit: some (gas * 110) div 100)
|
||||
|
||||
freeSlot = market.contract.freeSlot(
|
||||
slotId,
|
||||
rewardRecipient, # --reward-recipient
|
||||
collateralRecipient, # SP's address
|
||||
overrides,
|
||||
)
|
||||
else:
|
||||
# Otherwise, use the SP's address as both the reward and collateral
|
||||
# recipient (the contract will use msg.sender for both)
|
||||
|
||||
# Add 10% to gas estimate to deal with different evm code flow when we
|
||||
# happen to be the one to make the request fail
|
||||
let gas = await market.contract.estimateGas.freeSlot(slotId)
|
||||
let overrides = TransactionOverrides(gasLimit: some (gas * 110) div 100)
|
||||
|
||||
freeSlot = market.contract.freeSlot(slotId, overrides)
|
||||
|
||||
discard await freeSlot.confirm(1)
|
||||
discard await market.contract.freeSlot(slotId, overrides).confirm(1)
|
||||
except Marketplace_SlotIsFree as parent:
|
||||
raise newException(
|
||||
SlotStateMismatchError, "Failed to free slot, slot is already free", parent
|
||||
|
||||
@ -113,19 +113,6 @@ proc freeSlot*(
|
||||
]
|
||||
.}
|
||||
|
||||
proc freeSlot*(
|
||||
marketplace: Marketplace,
|
||||
id: SlotId,
|
||||
rewardRecipient: Address,
|
||||
collateralRecipient: Address,
|
||||
): Confirmable {.
|
||||
contract,
|
||||
errors: [
|
||||
Marketplace_InvalidSlotHost, Marketplace_AlreadyPaid,
|
||||
Marketplace_StartNotBeforeExpiry, Marketplace_UnknownRequest, Marketplace_SlotIsFree,
|
||||
]
|
||||
.}
|
||||
|
||||
proc getRequest*(
|
||||
marketplace: Marketplace, id: RequestId
|
||||
): StorageRequest {.contract, view, errors: [Marketplace_UnknownRequest].}
|
||||
|
||||
@ -10,7 +10,6 @@ ethersuite "Marketplace contracts":
|
||||
let proof = Groth16Proof.example
|
||||
|
||||
var client, host: Signer
|
||||
var rewardRecipient, collateralRecipient: Address
|
||||
var marketplace: Marketplace
|
||||
var token: Erc20Token
|
||||
var periodicity: Periodicity
|
||||
@ -28,8 +27,6 @@ ethersuite "Marketplace contracts":
|
||||
setup:
|
||||
client = ethProvider.getSigner(accounts[0])
|
||||
host = ethProvider.getSigner(accounts[1])
|
||||
rewardRecipient = accounts[2]
|
||||
collateralRecipient = accounts[3]
|
||||
|
||||
let address = Marketplace.address(dummyVerifier = true)
|
||||
marketplace = Marketplace.new(address, ethProvider.getSigner())
|
||||
@ -100,27 +97,6 @@ ethersuite "Marketplace contracts":
|
||||
check endBalance ==
|
||||
(startBalance + expectedPayout(requestEnd.u256) + request.ask.collateralPerSlot)
|
||||
|
||||
test "can be paid out at the end, specifying reward and collateral recipient":
|
||||
switchAccount(host)
|
||||
let hostAddress = await host.getAddress()
|
||||
await startContract()
|
||||
let requestEnd = await marketplace.requestEnd(request.id)
|
||||
await ethProvider.advanceTimeTo(requestEnd.u256 + 1)
|
||||
let startBalanceHost = await token.balanceOf(hostAddress)
|
||||
let startBalanceReward = await token.balanceOf(rewardRecipient)
|
||||
let startBalanceCollateral = await token.balanceOf(collateralRecipient)
|
||||
discard await marketplace
|
||||
.freeSlot(slotId, rewardRecipient, collateralRecipient)
|
||||
.confirm(1)
|
||||
let endBalanceHost = await token.balanceOf(hostAddress)
|
||||
let endBalanceReward = await token.balanceOf(rewardRecipient)
|
||||
let endBalanceCollateral = await token.balanceOf(collateralRecipient)
|
||||
|
||||
check endBalanceHost == startBalanceHost
|
||||
check endBalanceReward == (startBalanceReward + expectedPayout(requestEnd.u256))
|
||||
check endBalanceCollateral ==
|
||||
(startBalanceCollateral + request.ask.collateralPerSlot)
|
||||
|
||||
test "cannot mark proofs missing for cancelled request":
|
||||
let expiry = await marketplace.requestExpiry(request.id)
|
||||
await ethProvider.advanceTimeTo((expiry + 1).u256)
|
||||
|
||||
@ -29,7 +29,6 @@ ethersuite "On-Chain Market":
|
||||
var periodicity: Periodicity
|
||||
var host: Signer
|
||||
var otherHost: Signer
|
||||
var hostRewardRecipient: Address
|
||||
|
||||
proc expectedPayout(
|
||||
r: StorageRequest, startTimestamp: UInt256, endTimestamp: UInt256
|
||||
@ -39,13 +38,12 @@ ethersuite "On-Chain Market":
|
||||
proc switchAccount(account: Signer) {.async.} =
|
||||
marketplace = marketplace.connect(account)
|
||||
token = token.connect(account)
|
||||
market = ! await OnChainMarket.load(marketplace, market.rewardRecipient)
|
||||
market = ! await OnChainMarket.load(marketplace)
|
||||
|
||||
setup:
|
||||
let address = Marketplace.address(dummyVerifier = true)
|
||||
marketplace = Marketplace.new(address, ethProvider.getSigner())
|
||||
let config = await marketplace.configuration()
|
||||
hostRewardRecipient = accounts[2]
|
||||
|
||||
market = ! await OnChainMarket.load(marketplace)
|
||||
let tokenAddress = await marketplace.token()
|
||||
@ -561,38 +559,6 @@ ethersuite "On-Chain Market":
|
||||
let expectedPayout = request.expectedPayout(filledAt, requestEnd.u256)
|
||||
check endBalance == (startBalance + expectedPayout + request.ask.collateralPerSlot)
|
||||
|
||||
test "pays rewards to reward recipient, collateral to host":
|
||||
market = ! await OnChainMarket.load(marketplace, hostRewardRecipient.some)
|
||||
let hostAddress = await host.getAddress()
|
||||
|
||||
await market.requestStorage(request)
|
||||
|
||||
await switchAccount(host)
|
||||
await market.reserveSlot(request.id, 0.uint64)
|
||||
await market.fillSlot(request.id, 0.uint64, proof, request.ask.collateralPerSlot)
|
||||
let filledAt = (await ethProvider.currentTime())
|
||||
|
||||
for slotIndex in 1 ..< request.ask.slots:
|
||||
await market.reserveSlot(request.id, slotIndex.uint64)
|
||||
await market.fillSlot(
|
||||
request.id, slotIndex.uint64, proof, request.ask.collateralPerSlot
|
||||
)
|
||||
|
||||
let requestEnd = await market.getRequestEnd(request.id)
|
||||
await ethProvider.advanceTimeTo(requestEnd.u256 + 1)
|
||||
|
||||
let startBalanceHost = await token.balanceOf(hostAddress)
|
||||
let startBalanceReward = await token.balanceOf(hostRewardRecipient)
|
||||
|
||||
await market.freeSlot(request.slotId(0.uint64))
|
||||
|
||||
let endBalanceHost = await token.balanceOf(hostAddress)
|
||||
let endBalanceReward = await token.balanceOf(hostRewardRecipient)
|
||||
|
||||
let expectedPayout = request.expectedPayout(filledAt, requestEnd.u256)
|
||||
check endBalanceHost == (startBalanceHost + request.ask.collateralPerSlot)
|
||||
check endBalanceReward == (startBalanceReward + expectedPayout)
|
||||
|
||||
test "the request is added to cache after the first access":
|
||||
await market.requestStorage(request)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user