Skip to content

Commit

Permalink
Update ERC-6123: Fixes to reference implementation of Settlement Token
Browse files Browse the repository at this point in the history
Merged by EIP-Bot.
  • Loading branch information
cfries authored Nov 10, 2024
1 parent 4030cd3 commit 12349b3
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
2 changes: 1 addition & 1 deletion ERCS/erc-6123.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ The transactionData is emitted as part of the corresponding event: `SettlementTr
This might result in a termination or start of the next settlement phase, depending on the provided success flag.

```solidity
function afterTransfer(bool success, string memory transactionData) external;
function afterTransfer(bool success, uint256 transactionID, string memory transactionData) external;
```


Expand Down
16 changes: 9 additions & 7 deletions assets/erc-6123/contracts/ERC20Settlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "./IERC20Settlement.sol";

contract ERC20Settlement is ERC20, IERC20Settlement{

/*------------------------------------------- DESCRIPTION ---------------------------------------------------------------------------------------
* @title Reference (example) Implementation for Settlement Token Interface
* @dev This token performs transfers on-chain.
* Token is tied to one SDC address
* Only SDC can call checkedTransfers
* Settlement Token calls back the referenced SDC by calling "afterTransfer" with a success flag. Depending on this SDC perfoms next state change
*/

contract ERC20Settlement is ERC20, IERC20Settlement{

modifier onlySDC() {
require(msg.sender == sdcAddress, "Only allowed to be called from SDC Address"); _;
Expand All @@ -39,10 +37,13 @@ contract ERC20Settlement is ERC20, IERC20Settlement{
}

function transferAndCallback(address to, uint256 value, uint256 transactionID, address callbackContract) public onlySDC{
if ( balanceOf(sdcAddress) < value)
if ( balanceOf(msg.sender) < value) {
ISDC(callbackContract).afterTransfer(false, transactionID, Strings.toString(transactionID));
else
}
else {
_transfer(msg.sender,to,value);
ISDC(callbackContract).afterTransfer(true, transactionID, Strings.toString(transactionID));
}
}

function transferFromAndCallback(address from, address to, uint256 value, uint256 transactionID, address callbackContract) external view onlySDC {
Expand All @@ -52,15 +53,16 @@ contract ERC20Settlement is ERC20, IERC20Settlement{
function transferBatchAndCallback(address[] memory to, uint256[] memory values, uint256 transactionID, address callbackContract) public onlySDC{
require (to.length == values.length, "Array Length mismatch");
uint256 requiredBalance = 0;
for(uint256 i = 0; i < values.length; i++)
for(uint256 i = 0; i < values.length; i++) {
requiredBalance += values[i];
}
if (balanceOf(msg.sender) < requiredBalance){
ISDC(callbackContract).afterTransfer(false, transactionID, Strings.toString(transactionID));
return;
}
else{
for(uint256 i = 0; i < to.length; i++){
_transfer(sdcAddress,to[i],values[i]);
_transfer(msg.sender,to[i],values[i]);
}
ISDC(callbackContract).afterTransfer(true, transactionID, Strings.toString(transactionID));
}
Expand Down
10 changes: 7 additions & 3 deletions assets/erc-6123/contracts/ISDC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,17 @@ interface ISDC {

/**
* @dev Emitted when settlement process has been finished
* @param transactionID a transaction id
* @param transactionData data associtated with the transfer, will be emitted via the events.
*/
event SettlementTransferred(string transactionData);
event SettlementTransferred(uint256 transactionID, string transactionData);

/**
* @dev Emitted when settlement process has been finished
* @param transactionID a transaction id
* @param transactionData data associtated with the transfer, will be emitted via the events.
*/
event SettlementFailed(string transactionData);
event SettlementFailed(uint256 transactionID, string transactionData);

/* Events related to trade termination */

Expand Down Expand Up @@ -222,7 +226,7 @@ interface ISDC {
/**
* @notice May get called from outside to to finish a transfer (callback). The trade decides on how to proceed based on success flag
* @param success tells the protocol whether transfer was successful
* @param transactionID a transaction
* @param transactionID a transaction id
* @param transactionData data associtated with the transfer, will be emitted via the events.
* @dev emit a {SettlementTransferred} or a {SettlementFailed} event. May emit a {TradeTerminated} event.
*/
Expand Down
5 changes: 3 additions & 2 deletions assets/erc-6123/contracts/SDCSingleTradePledgedBalance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ contract SDCSingleTradePledgedBalance is SDCSingleTrade {
else if ( inStateTransfer() ){
if (success){
setTradeState(TradeState.Settled);
emit SettlementTransferred("Settlement Settled - Pledge Transfer");
emit SettlementTransferred(transactionID, "Settlement Settled - Pledge Transfer");
}
else{ // Settlement & Pledge Case: transferAmount is transferred from SDC balance (i.e. pledged balance).
int256 settlementAmount = settlementAmounts[settlementAmounts.length-1];
setTradeState(TradeState.InTermination);
emit SettlementFailed(transactionID, "Settlement Failed - Pledge Transfer");
int256 settlementAmount = settlementAmounts[settlementAmounts.length-1];
processTerminationWithPledge(settlementAmount);
emit TradeTerminated(tradeID, "Settlement Failed - Pledge Transfer");
}
Expand Down
2 changes: 1 addition & 1 deletion assets/erc-6123/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finmath.net/sdc",
"version": "0.4.3",
"version": "0.4.4",
"description": "Solidity Smart Derivative Contracts",
"author": "Christian Fries, Peter Kohl-Landgraf, Alexandros Korpis",
"license": "ISC",
Expand Down

0 comments on commit 12349b3

Please sign in to comment.