Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ERC-6123: Feature/erc 6123 after settlement #871

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ERCS/erc-6123.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ The settlement amount will be checked according to contract terms, resulting in
function performSettlement(int256 settlementAmount, string memory settlementData) external;
```

#### Settlement Phase: `afterTransfer`
#### Settlement Phase: `afterSettlement`

This method - either called back from the provided settlement token directly or from an eligible address - completes the settlement transfer.
The transactionData is emitted as part of the corresponding event: `SettlementTransferred` or `SettlementFailed`
This might result in a termination or start of the next settlement phase, depending on the provided success flag.

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


Expand Down Expand Up @@ -262,13 +262,13 @@ The interface design and reference implementation are based on the following con

### State diagram of trade and process states

![image info](../assets/eip-6123/doc/sdc_trade_states.svg)
![image info](../assets/erc-6123/doc/sdc_trade_states.svg)

The diagram shows the trade states of a single trade SDC as in `SDCSingleTrade.sol`.

### Sequence diagram of reference implementation 'SDCPledgedBalance.sol'

![image info](../assets/eip-6123/doc/sequence.svg)
![image info](../assets/erc-6123/doc/sequence.svg)

The sequence diagram show the function calls that create the trade and stellement state transitions
and the emitted events.
Expand Down
14 changes: 7 additions & 7 deletions assets/erc-6123/contracts/ERC20Settlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "./IERC20Settlement.sol";
* @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
* Settlement Token calls back the referenced SDC by calling "afterSettlement" with a success flag. Depending on this SDC perfoms next state change
*/
contract ERC20Settlement is ERC20, IERC20Settlement{

Expand All @@ -38,11 +38,11 @@ contract ERC20Settlement is ERC20, IERC20Settlement{

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

Expand All @@ -57,14 +57,14 @@ contract ERC20Settlement is ERC20, IERC20Settlement{
requiredBalance += values[i];
}
if (balanceOf(msg.sender) < requiredBalance){
ISDC(callbackContract).afterTransfer(false, transactionID, Strings.toString(transactionID));
ISDC(callbackContract).afterSettlement(false, transactionID, Strings.toString(transactionID));
return;
}
else{
for(uint256 i = 0; i < to.length; i++){
_transfer(msg.sender,to[i],values[i]);
}
ISDC(callbackContract).afterTransfer(true, transactionID, Strings.toString(transactionID));
ISDC(callbackContract).afterSettlement(true, transactionID, Strings.toString(transactionID));
}
}

Expand All @@ -79,14 +79,14 @@ contract ERC20Settlement is ERC20, IERC20Settlement{
totalRequiredBalance += values[j];
}
if (balanceOf(fromAddress) < totalRequiredBalance){
ISDC(callbackContract).afterTransfer(false, transactionID, Strings.toString(transactionID));
ISDC(callbackContract).afterSettlement(false, transactionID, Strings.toString(transactionID));
return;
}

}
for(uint256 i = 0; i < to.length; i++){
_transfer(from[i],to[i],values[i]);
}
ISDC(callbackContract).afterTransfer(true, transactionID, Strings.toString(transactionID));
ISDC(callbackContract).afterSettlement(true, transactionID, Strings.toString(transactionID));
}
}
14 changes: 7 additions & 7 deletions assets/erc-6123/contracts/IERC20Settlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
* @title ERC6123 - Settlement Token Interface
* @dev Settlement Token Interface enhances the ERC20 Token by introducing an asynchronous (checked) transfer functionality which can be used to directly interact with an SDC.
* Transfers can be conducted for single or multiple transactions where SDC will receive a success message whether the transfer was executed successfully or not.
* The SDC or callbackContract needs to implemnt a function afterTransfer(bool success, uint256 transactionID, string memory transactionData)
* The SDC or callbackContract needs to implemnt a function afterSettlement(bool success, uint256 transactionID, string memory transactionData)
*/
interface IERC20Settlement is IERC20 {

Expand All @@ -19,7 +19,7 @@ interface IERC20Settlement is IERC20 {
* @param to the address to which to transfer
* @param value the value to transfer
* @param transactionID a transaction ID that may serve as correlation ID, will be passed to the callback.
* @param callbackContract a contract implementing afterTransfer
* @param callbackContract a contract implementing afterSettlement
*/
event TransferRequested(address from, address to, uint256 value, uint256 transactionID, address callbackContract);

Expand All @@ -29,7 +29,7 @@ interface IERC20Settlement is IERC20 {
* @param to the addresses to which to transfer
* @param value the values to transfer
* @param transactionID a transaction ID that may serve as correlation ID, will be passed to the callback.
* @param callbackContract a contract implementing afterTransfer
* @param callbackContract a contract implementing afterSettlement
*/
event TransferBatchRequested(address[] from, address[] to, uint256[] value, uint256 transactionID, address callbackContract);

Expand All @@ -38,7 +38,7 @@ interface IERC20Settlement is IERC20 {
* @param to - receiver
* @param value - transfer amount
* @param transactionID - an id that will be passed back to the callback
* @param callbackContract - a contract implementing the method afterTransfer(bool success, uint256 transactionID, string memory transactionData)
* @param callbackContract - a contract implementing the method afterSettlement(bool success, uint256 transactionID, string memory transactionData)
*/
function transferAndCallback(address to, uint256 value, uint256 transactionID, address callbackContract) external;

Expand All @@ -48,7 +48,7 @@ interface IERC20Settlement is IERC20 {
* @param to - receiver
* @param value - transfer amount
* @param transactionID - an id that will be passed back to the callback
* @param callbackContract - a contract implementing the method afterTransfer(bool success, uint256 transactionID, string memory transactionData)
* @param callbackContract - a contract implementing the method afterSettlement(bool success, uint256 transactionID, string memory transactionData)
*/
function transferFromAndCallback(address from, address to, uint256 value, uint256 transactionID, address callbackContract) external ;

Expand All @@ -57,7 +57,7 @@ interface IERC20Settlement is IERC20 {
* @param to - receivers
* @param values - transfer amounts
* @param transactionID - an id that will be passed back to the callback
* @param callbackContract - a contract implementing the method afterTransfer(bool success, uint256 transactionID, string memory transactionData)
* @param callbackContract - a contract implementing the method afterSettlement(bool success, uint256 transactionID, string memory transactionData)
*/
function transferBatchAndCallback(address[] memory to, uint256[] memory values, uint256 transactionID, address callbackContract) external;

Expand All @@ -67,7 +67,7 @@ interface IERC20Settlement is IERC20 {
* @param to - receivers
* @param values - transfer amounts
* @param transactionID - an id that will be passed back to the callback
* @param callbackContract - a contract implementing the method afterTransfer(bool success, uint256 transactionID, string memory transactionData)
* @param callbackContract - a contract implementing the method afterSettlement(bool success, uint256 transactionID, string memory transactionData)
*/
function transferBatchFromAndCallback(address[] memory from, address[] memory to, uint256[] memory values, uint256 transactionID, address callbackContract) external;
}
2 changes: 1 addition & 1 deletion assets/erc-6123/contracts/ISDC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ interface ISDC {
* @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.
*/
function afterTransfer(bool success, uint256 transactionID, string memory transactionData) external;
function afterSettlement(bool success, uint256 transactionID, string memory transactionData) external;

/// Trade termination

Expand Down
6 changes: 3 additions & 3 deletions assets/erc-6123/contracts/SDCSingleTradePledgedBalance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ contract SDCSingleTradePledgedBalance is SDCSingleTrade {
}

/*
* afterTransfer processes SDC depending on success of the respective payment and depending on the current trade state
* afterSettlement processes SDC depending on success of the respective payment and depending on the current trade state
* Good Case: state will be settled, failed settlement will trigger the pledge balance transfer and termination
*/
function afterTransfer(bool success, uint256 transactionID, string memory transactionData) external override {
function afterSettlement(bool success, uint256 transactionID, string memory transactionData) external override {
if ( inStateConfirmed()){
if (success){
setTradeState(TradeState.Settled);
Expand Down Expand Up @@ -130,7 +130,7 @@ contract SDCSingleTradePledgedBalance is SDCSingleTrade {
}
}
else
revert("Trade State does not allow to call 'afterTransfer'");
revert("Trade State does not allow to call 'afterSettlement'");
}

/*
Expand Down
4 changes: 2 additions & 2 deletions assets/erc-6123/doc/sdc_trade_states.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions assets/erc-6123/doc/sequence.puml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SDC-->EventHandler: emit TradeIncepted

== TradeState 'inTransfer' ==

SettlementToken->SDC: callback tx 'afterTransfer'
SettlementToken->SDC: callback tx 'afterSettlement'

SDC-->EventHandler: emit TradeActivated

Expand All @@ -68,7 +68,7 @@ SDC->SettlementToken: tx 'transferFrom' settlement amount from Paying Party to R
== TradeState 'inTransfer' ==

alt Transfer Check
SettlementToken->SDC: callback tx 'afterTransfer'
SettlementToken->SDC: callback tx 'afterSettlement'
else success
SDC-->EventHandler: emit SettlementTransferred
== TradeState 'Settled' ==
Expand Down
2 changes: 1 addition & 1 deletion assets/erc-6123/doc/sequence.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.4",
"version": "0.5.0",
"description": "Solidity Smart Derivative Contracts",
"author": "Christian Fries, Peter Kohl-Landgraf, Alexandros Korpis",
"license": "ISC",
Expand Down
Loading