Remove optional payoutAddress

Change --payout-address so that it is no longer optional. There is no longer an overload in `Marketplace.sol` for `fillSlot` accepting no `payoutAddress`.
This commit is contained in:
Eric 2024-08-12 16:43:31 +10:00
parent a668bca480
commit f9384d508a
No known key found for this signature in database
6 changed files with 36 additions and 49 deletions

View File

@ -295,10 +295,8 @@ type
payoutAddress* {.
desc: "Address to send reward payouts to"
defaultValue: EthAddress.none
defaultValueDesc: "Rewards will be sent to the SP's address (derived from --eth-private-key)"
name: "payout-address"
.}: Option[EthAddress]
.}: EthAddress
case persistenceCmd* {.
defaultValue: noCmd

View File

@ -19,7 +19,7 @@ type
OnChainMarket* = ref object of Market
contract: Marketplace
signer: Signer
payoutAddress: ?Address
payoutAddress: Address
MarketSubscription = market.Subscription
EventSubscription = ethers.Subscription
OnChainMarketSubscription = ref object of MarketSubscription
@ -28,7 +28,7 @@ type
func new*(
_: type OnChainMarket,
contract: Marketplace,
payoutAddress = Address.none): OnChainMarket =
payoutAddress: Address): OnChainMarket =
without signer =? contract.signer:
raiseAssert("Marketplace contract should have a signer")
@ -167,12 +167,9 @@ method fillSlot(market: OnChainMarket,
convertEthersError:
await market.approveFunds(collateral)
var fillSlot: Future[?TransactionResponse]
if payoutAddress =? market.payoutAddress:
fillSlot = market.contract.fillSlot(requestId, slotIndex, proof, payoutAddress)
else:
fillSlot = market.contract.fillSlot(requestId, slotIndex, proof)
discard await fillSlot.confirm(0)
discard await market.contract.fillSlot(
requestId, slotIndex, proof, market.payoutAddress
).confirm(0)
method freeSlot*(market: OnChainMarket, slotId: SlotId) {.async.} =
convertEthersError:

View File

@ -43,7 +43,6 @@ proc slashPercentage*(marketplace: Marketplace): UInt256 {.contract, view.}
proc minCollateralThreshold*(marketplace: Marketplace): UInt256 {.contract, view.}
proc requestStorage*(marketplace: Marketplace, request: StorageRequest): ?TransactionResponse {.contract.}
proc fillSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256, proof: Groth16Proof): ?TransactionResponse {.contract.}
proc fillSlot*(marketplace: Marketplace, requestId: RequestId, slotIndex: UInt256, proof: Groth16Proof, payoutAddress: Address): ?TransactionResponse {.contract.}
proc withdrawFunds*(marketplace: Marketplace, requestId: RequestId): ?TransactionResponse {.contract.}
proc freeSlot*(marketplace: Marketplace, id: SlotId): ?TransactionResponse {.contract.}

View File

@ -11,6 +11,7 @@ ethersuite "Marketplace contracts":
let proof = Groth16Proof.example
var client, host: Signer
var payoutAddress: Address
var marketplace: Marketplace
var token: Erc20Token
var periodicity: Periodicity
@ -24,6 +25,7 @@ ethersuite "Marketplace contracts":
setup:
client = ethProvider.getSigner(accounts[0])
host = ethProvider.getSigner(accounts[1])
payoutAddress = accounts[2]
let address = Marketplace.address(dummyVerifier = true)
marketplace = Marketplace.new(address, ethProvider.getSigner())
@ -42,7 +44,7 @@ ethersuite "Marketplace contracts":
discard await marketplace.requestStorage(request)
switchAccount(host)
discard await token.approve(marketplace.address, request.ask.collateral)
discard await marketplace.fillSlot(request.id, 0.u256, proof)
discard await marketplace.fillSlot(request.id, 0.u256, proof, payoutAddress)
slotId = request.slotId(0.u256)
proc waitUntilProofRequired(slotId: SlotId) {.async.} =
@ -57,7 +59,7 @@ ethersuite "Marketplace contracts":
proc startContract() {.async.} =
for slotIndex in 1..<request.ask.slots:
discard await token.approve(marketplace.address, request.ask.collateral)
discard await marketplace.fillSlot(request.id, slotIndex.u256, proof)
discard await marketplace.fillSlot(request.id, slotIndex.u256, proof, payoutAddress)
test "accept marketplace proofs":
switchAccount(host)
@ -75,14 +77,18 @@ ethersuite "Marketplace contracts":
test "can be paid out at the end":
switchAccount(host)
let address = await host.getAddress()
let hostAddress = await host.getAddress()
await startContract()
let requestEnd = await marketplace.requestEnd(request.id)
await ethProvider.advanceTimeTo(requestEnd.u256 + 1)
let startBalance = await token.balanceOf(address)
let startBalanceHost = await token.balanceOf(hostAddress)
let startBalancePayout = await token.balanceOf(payoutAddress)
discard await marketplace.freeSlot(slotId)
let endBalance = await token.balanceOf(address)
check endBalance == (startBalance + request.ask.duration * request.ask.reward + request.ask.collateral)
let endBalanceHost = await token.balanceOf(hostAddress)
let endBalancePayout = await token.balanceOf(payoutAddress)
check endBalanceHost == (startBalanceHost + request.ask.collateral)
check endBalancePayout == (startBalancePayout + request.ask.duration * request.ask.reward)
test "cannot mark proofs missing for cancelled request":
let expiry = await marketplace.requestExpiry(request.id)

View File

@ -17,13 +17,20 @@ ethersuite "On-Chain Market":
var slotIndex: UInt256
var periodicity: Periodicity
var host: Signer
var payoutAddress: Address
proc switchAccount(account: Signer) =
marketplace = marketplace.connect(account)
token = token.connect(account)
market = OnChainMarket.new(marketplace, payoutAddress)
setup:
let address = Marketplace.address(dummyVerifier = true)
marketplace = Marketplace.new(address, ethProvider.getSigner())
let config = await marketplace.config()
payoutAddress = accounts[2]
market = OnChainMarket.new(marketplace)
market = OnChainMarket.new(marketplace, payoutAddress)
let tokenAddress = await marketplace.token()
token = Erc20Token.new(tokenAddress, ethProvider.getSigner())
@ -31,6 +38,7 @@ ethersuite "On-Chain Market":
request = StorageRequest.example
request.client = accounts[0]
host = ethProvider.getSigner(accounts[1])
slotIndex = (request.ask.slots div 2).u256
@ -53,7 +61,7 @@ ethersuite "On-Chain Market":
test "fails to instantiate when contract does not have a signer":
let storageWithoutSigner = marketplace.connect(ethProvider)
expect AssertionDefect:
discard OnChainMarket.new(storageWithoutSigner)
discard OnChainMarket.new(storageWithoutSigner, payoutAddress)
test "knows signer address":
check (await market.getSigner()) == (await ethProvider.getSigner().getAddress())
@ -360,32 +368,12 @@ ethersuite "On-Chain Market":
(await market.queryPastStorageRequests(blocksAgo = 2))
)
test "pays out to host address, including collateral":
let address = request.client
await market.requestStorage(request)
for slotIndex in 0..<request.ask.slots:
await market.fillSlot(request.id, slotIndex.u256, proof, request.ask.collateral)
let requestEnd = await market.getRequestEnd(request.id)
await ethProvider.advanceTimeTo(requestEnd.u256 + 1)
let startBalance = await token.balanceOf(address)
await market.freeSlot(request.slotId(0.u256))
let endBalance = await token.balanceOf(address)
check endBalance == (startBalance +
request.ask.duration * request.ask.reward +
request.ask.collateral)
test "pays out to payout address, collateral paid to host address":
let hostAddress = request.client
let hostPayoutAddress = accounts[2]
let hostAddress = await host.getAddress()
market = OnChainMarket.new(marketplace, hostPayoutAddress.some)
await market.requestStorage(request)
switchAccount(host)
for slotIndex in 0..<request.ask.slots:
await market.fillSlot(request.id, slotIndex.u256, proof, request.ask.collateral)
@ -393,14 +381,13 @@ ethersuite "On-Chain Market":
await ethProvider.advanceTimeTo(requestEnd.u256 + 1)
let startBalanceHost = await token.balanceOf(hostAddress)
let startBalanceHostPayout = await token.balanceOf(hostPayoutAddress)
let startBalancePayout = await token.balanceOf(payoutAddress)
await market.freeSlot(request.slotId(0.u256))
let endBalanceHost = await token.balanceOf(hostAddress)
let endBalanceHostPayout = await token.balanceOf(hostPayoutAddress)
let endBalancePayout = await token.balanceOf(payoutAddress)
check endBalanceHostPayout == (startBalanceHostPayout +
check endBalanceHost == (startBalanceHost + request.ask.collateral)
check endBalancePayout == (startBalancePayout +
request.ask.duration * request.ask.reward)
check endBalanceHost == (startBalanceHost +
request.ask.collateral)

@ -1 +1 @@
Subproject commit be76f4042aafad65c8a303382fa302f8d775b10b
Subproject commit 6db5479c855ff9048c6557aa7966a40d308492b4