Skip to content

Commit

Permalink
update cm account and bt operator with cancellation funcs and add 1 test
Browse files Browse the repository at this point in the history
  • Loading branch information
havan committed Oct 18, 2024
1 parent 011f682 commit 8e994e6
Show file tree
Hide file tree
Showing 8 changed files with 402 additions and 1 deletion.
72 changes: 72 additions & 0 deletions abi/contracts/account/CMAccount.sol/CMAccount.json
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "acceptCancellation",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -1171,6 +1184,19 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "cancelCancellationProposal",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -1219,6 +1245,29 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "refundAmount",
"type": "uint256"
},
{
"internalType": "address",
"name": "refundCurrency",
"type": "address"
}
],
"name": "counterCancellationProposal",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "getAllServiceHashes",
Expand Down Expand Up @@ -1869,6 +1918,29 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "refundAmount",
"type": "uint256"
},
{
"internalType": "address",
"name": "refundCurrency",
"type": "address"
}
],
"name": "initiateCancellation",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,44 @@
],
"name": "TokenApprovalFailed",
"type": "error"
},
{
"inputs": [
{
"internalType": "address",
"name": "bookingToken",
"type": "address"
},
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "getCancellationProposalStatus",
"outputs": [
{
"internalType": "uint256",
"name": "refundAmount",
"type": "uint256"
},
{
"internalType": "address",
"name": "refundCurrency",
"type": "address"
},
{
"internalType": "address",
"name": "initiatedBy",
"type": "address"
},
{
"internalType": "bool",
"name": "isActive",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
}
]
106 changes: 106 additions & 0 deletions abi/contracts/booking-token/IBookingToken.sol/IBookingToken.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
[
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "acceptCancellation",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand All @@ -12,6 +25,76 @@
"stateMutability": "payable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "cancelCancellationProposal",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "newRefundAmount",
"type": "uint256"
},
{
"internalType": "address",
"name": "newRefundCurrency",
"type": "address"
}
],
"name": "counterCancellationProposal",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
}
],
"name": "getCancellationProposalStatus",
"outputs": [
{
"internalType": "uint256",
"name": "refundAmount",
"type": "uint256"
},
{
"internalType": "address",
"name": "refundCurrency",
"type": "address"
},
{
"internalType": "address",
"name": "initiatedBy",
"type": "address"
},
{
"internalType": "bool",
"name": "isActive",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand All @@ -36,6 +119,29 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "uint256",
"name": "tokenId",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "refundAmount",
"type": "uint256"
},
{
"internalType": "address",
"name": "refundCurrency",
"type": "address"
}
],
"name": "initiateCancellation",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
Expand Down
35 changes: 35 additions & 0 deletions contracts/account/CMAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -761,4 +761,39 @@ contract CMAccount is
function setGasMoneyWithdrawal(uint256 limit, uint256 period) public onlyRole(BOT_ADMIN_ROLE) {
_setGasMoneyWithdrawal(limit, period);
}

/***************************************************
* CANCELLATION *
***************************************************/

// FIXME: Create a specific role for those

function initiateCancellation(
uint256 tokenId,
uint256 refundAmount,
address refundCurrency
) public onlyRole(SERVICE_ADMIN_ROLE) {
BookingTokenOperator.initiateCancellation(getBookingTokenAddress(), tokenId, refundAmount, refundCurrency);
}

function acceptCancellation(uint256 tokenId) public onlyRole(SERVICE_ADMIN_ROLE) {
BookingTokenOperator.acceptCancellation(getBookingTokenAddress(), tokenId);
}

function counterCancellationProposal(
uint256 tokenId,
uint256 refundAmount,
address refundCurrency
) public onlyRole(SERVICE_ADMIN_ROLE) {
BookingTokenOperator.counterCancellationProposal(
getBookingTokenAddress(),
tokenId,
refundAmount,
refundCurrency
);
}

function cancelCancellationProposal(uint256 tokenId) public onlyRole(SERVICE_ADMIN_ROLE) {
BookingTokenOperator.cancelCancellationProposal(getBookingTokenAddress(), tokenId);
}
}
33 changes: 33 additions & 0 deletions contracts/booking-token/BookingTokenOperator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,37 @@ library BookingTokenOperator {
IBookingToken(bookingToken).buyReservedToken{ value: price }(tokenId);
}
}

function initiateCancellation(
address bookingToken,
uint256 tokenId,
uint256 refundAmount,
address refundCurrency
) public {
IBookingToken(bookingToken).initiateCancellation(tokenId, refundAmount, refundCurrency);
}

function acceptCancellation(address bookingToken, uint256 tokenId) public {
IBookingToken(bookingToken).acceptCancellation(tokenId);
}

function counterCancellationProposal(
address bookingToken,
uint256 tokenId,
uint256 refundAmount,
address refundCurrency
) public {
IBookingToken(bookingToken).counterCancellationProposal(tokenId, refundAmount, refundCurrency);
}

function cancelCancellationProposal(address bookingToken, uint256 tokenId) public {
IBookingToken(bookingToken).cancelCancellationProposal(tokenId);
}

function getCancellationProposalStatus(
address bookingToken,
uint256 tokenId
) public view returns (uint256 refundAmount, address refundCurrency, address initiatedBy, bool isActive) {
return IBookingToken(bookingToken).getCancellationProposalStatus(tokenId);
}
}
45 changes: 45 additions & 0 deletions contracts/booking-token/IBookingToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,49 @@ interface IBookingToken {
function buyReservedToken(uint256 tokenId) external payable;

function getReservationPrice(uint256 tokenId) external view returns (uint256 price, IERC20 paymentToken);

/**
* @notice Initiates a cancellation for a bought token.
*
* @param tokenId The token id to initiate the cancellation for
* @param refundAmount The proposed refund amount in wei
* @param refundCurrency The ERC20 token address for the refund
*/
function initiateCancellation(uint256 tokenId, uint256 refundAmount, address refundCurrency) external;

/**
* @notice Accepts a cancellation proposal for a bought token.
*
* @param tokenId The token id to accept the cancellation for
*/
function acceptCancellation(uint256 tokenId) external;

/**
* @notice Counters a cancellation proposal with a new proposal.
*
* @param tokenId The token id to counter the cancellation for
* @param newRefundAmount The new proposed refund amount in wei
* @param newRefundCurrency The new ERC20 token address for the refund
*/
function counterCancellationProposal(uint256 tokenId, uint256 newRefundAmount, address newRefundCurrency) external;

/**
* @notice Cancels an active cancellation proposal. Only the initiator can cancel.
*
* @param tokenId The token id for which to cancel the proposal
*/
function cancelCancellationProposal(uint256 tokenId) external;

/**
* @notice Retrieves the current cancellation proposal status for a given token.
*
* @param tokenId The token id to check the proposal status for
* @return refundAmount The proposed refund amount
* @return refundCurrency The address of the proposed refund currency
* @return initiatedBy The address that initiated the cancellation
* @return isActive The status of the cancellation proposal
*/
function getCancellationProposalStatus(
uint256 tokenId
) external view returns (uint256 refundAmount, address refundCurrency, address initiatedBy, bool isActive);
}
Loading

0 comments on commit 8e994e6

Please sign in to comment.