Skip to content

Commit

Permalink
feat: let proposers release its bond if the response is won and not used
Browse files Browse the repository at this point in the history
  • Loading branch information
moebius committed Nov 28, 2023
1 parent db865ab commit 53a989e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"package.json": "sort-package-json"
},
"dependencies": {
"@defi-wonderland/prophet-core-contracts": "0.0.0-5fbc6720",
"@defi-wonderland/prophet-core-contracts": "0.0.0-c8bd8736",
"@defi-wonderland/solidity-utils": "0.0.0-3e9c8e8b",
"@openzeppelin/contracts": "^4.9.3",
"ds-test": "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0",
Expand Down
26 changes: 26 additions & 0 deletions solidity/contracts/modules/response/BondedResponseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,30 @@ contract BondedResponseModule is Module, IBondedResponseModule {

emit RequestFinalized(_response.requestId, _response, _finalizer);
}

/// @inheritdoc IBondedResponseModule
function releaseUncalledResponse(
IOracle.Request calldata _request,
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external {
bytes32 _disputeId = _validateDispute(_request, _response, _dispute);

if (ORACLE.disputeStatus(_disputeId) != IOracle.DisputeStatus.Won) {
revert BondedResponseModule_InvalidReleaseParameters();
}

bytes32 _finalizedResponseId = ORACLE.getFinalizedResponseId(_response.requestId);
if (_finalizedResponseId == _dispute.responseId || _finalizedResponseId == bytes32(0)) {
revert BondedResponseModule_InvalidReleaseParameters();
}

RequestParameters memory _params = decodeRequestData(_request.responseModuleData);
_params.accountingExtension.release({
_bonder: _response.proposer,
_requestId: _response.requestId,
_token: _params.bondToken,
_amount: _params.bondSize
});
}
}
18 changes: 18 additions & 0 deletions solidity/interfaces/modules/response/IBondedResponseModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ interface IBondedResponseModule is IResponseModule {
*/
error BondedResponseModule_AlreadyResponded();

/**
* @notice Thrown when trying to release an uncalled response with an invalid request, response or dispute
*/
error BondedResponseModule_InvalidReleaseParameters();

/*///////////////////////////////////////////////////////////////
STRUCTS
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -99,4 +104,17 @@ interface IBondedResponseModule is IResponseModule {
IOracle.Response calldata _response,
address _finalizer
) external;

/**
* @notice Releases the proposer fund if the response is valid and it has not been used to finalize the request
*
* @param _request The finalized request
* @param _response The uncalled response
* @param _response The won dispute
*/
function releaseUncalledResponse(
IOracle.Request calldata _request,
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) external;
}
12 changes: 5 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@
dependencies:
"@jridgewell/trace-mapping" "0.3.9"

"@defi-wonderland/[email protected]5fbc6720":
version "0.0.0-5fbc6720"
resolved "https://registry.yarnpkg.com/@defi-wonderland/prophet-core-contracts/-/prophet-core-contracts-0.0.0-5fbc6720.tgz#5fef99e5a9064289566c8b7eec3e754c20c67166"
integrity sha512-tXiSGhSFW/QJhW4eLKJ7MCUXEG+NvJvOPteFHlri+GEiXfQRQztpWBQYSngI68C+rourOTVCbXSm0bDJK2UfMw==
"@defi-wonderland/[email protected]c8bd8736":
version "0.0.0-c8bd8736"
resolved "https://registry.yarnpkg.com/@defi-wonderland/prophet-core-contracts/-/prophet-core-contracts-0.0.0-c8bd8736.tgz#3f27e8296831b384c9bb516bcef3d7bceb5383bd"
integrity sha512-Zh+kWY6GZsEf6+Fs399XOxlWojWN1yFyznjnXh2Ydfxa72AqzyviaEPgse5zc9diizGJnBsyo9FRF/BY+EbuTg==
dependencies:
"@defi-wonderland/solidity-utils" "0.0.0-3e9c8e8b"
"@openzeppelin/contracts" "^4.9.3"
Expand Down Expand Up @@ -1183,16 +1183,15 @@ dotgitignore@^2.1.0:

"ds-test@git+https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0":
version "1.0.0"
uid e282159d5170298eb2455a6c05280ab5a73a4ef0
resolved "git+https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0"

"ds-test@https://github.com/dapphub/ds-test":
version "1.0.0"
uid e282159d5170298eb2455a6c05280ab5a73a4ef0
resolved "https://github.com/dapphub/ds-test#e282159d5170298eb2455a6c05280ab5a73a4ef0"

"ds-test@https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0":
version "1.0.0"
uid e282159d5170298eb2455a6c05280ab5a73a4ef0
resolved "https://github.com/dapphub/ds-test.git#e282159d5170298eb2455a6c05280ab5a73a4ef0"

eastasianwidth@^0.2.0:
Expand Down Expand Up @@ -3285,7 +3284,6 @@ [email protected]:

"solmate@https://github.com/transmissions11/solmate.git#bfc9c25865a274a7827fea5abf6e4fb64fc64e6c":
version "6.1.0"
uid bfc9c25865a274a7827fea5abf6e4fb64fc64e6c
resolved "https://github.com/transmissions11/solmate.git#bfc9c25865a274a7827fea5abf6e4fb64fc64e6c"

sort-object-keys@^1.1.3:
Expand Down

0 comments on commit 53a989e

Please sign in to comment.