Skip to content

Commit

Permalink
Website: Fixed typos in events / added arguments to SettlementEvaluat…
Browse files Browse the repository at this point in the history
…ed event.

Merged by EIP-Bot.
  • Loading branch information
cfries authored Aug 2, 2024
1 parent e402021 commit ff5a0ba
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 50 deletions.
10 changes: 5 additions & 5 deletions ERCS/erc-6123.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,26 @@ function afterTransfer(bool success, uint256 transactionData) external;

#### Trade Termination: `requestTermination`

Allows an eligible party to request a mutual termination of the trade with the correspondig `tradeData` with a termination amount she is willing to pay and provide further termination terms (e.g. an XML)
Allows an eligible party to request a mutual termination of the trade with the correspondig `tradeId` with a termination amount she is willing to pay and provide further termination terms (e.g. an XML)

```solidity
function requestTradeTermination(string memory tradeData, int256 terminationPayment, string memory terminationTerms) external;
function requestTradeTermination(string memory tradeId, int256 terminationPayment, string memory terminationTerms) external;
```

#### Trade Termination: `confirmTradeTermination`

Allows an eligible party to confirm a previously requested (mutual) trade termination, including termination payment value and termination terms

```solidity
function confirmTradeTermination(string memory tradeData, int256 terminationPayment, string memory terminationTerms) external;
function confirmTradeTermination(string memory tradeId, int256 terminationPayment, string memory terminationTerms) external;
```

#### Trade Termination: `cancelTradeTermination`

The party that initiated `requestTradeTermination` has the option to withdraw the request, e.g., in the case where the termination is not confirmed in a timely manner.

```solidity
function cancelTradeTermination(string memory tradeData, int256 terminationPayment, string memory terminationTerms) external;
function cancelTradeTermination(string memory tradeId, int256 terminationPayment, string memory terminationTerms) external;
```

### Trade Events
Expand Down Expand Up @@ -178,7 +178,7 @@ event TradeActivated(string tradeId);
Emitted when a settlement is requested. May trigger the settlement phase.

```solidity
event SettlementRequested(address initiator, string tradeData, string lastSettlementData);
event SettlementRequested(address initiator, string tradeId, string lastSettlementData);
```

### SettlementEvaluated
Expand Down
13 changes: 7 additions & 6 deletions assets/erc-6123/contracts/ERC20Settlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity >=0.7.0 <0.9.0;
import "./ISDC.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "./IERC20Settlement.sol";

contract ERC20Settlement is ERC20, IERC20Settlement{
Expand Down Expand Up @@ -39,9 +40,9 @@ contract ERC20Settlement is ERC20, IERC20Settlement{

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

function checkedTransferFrom(address from, address to, uint256 value, uint256 transactionID) external view onlySDC {
Expand All @@ -54,14 +55,14 @@ contract ERC20Settlement is ERC20, IERC20Settlement{
for(uint256 i = 0; i < values.length; i++)
requiredBalance += values[i];
if (balanceOf(msg.sender) < requiredBalance){
ISDC(sdcAddress).afterTransfer(false, transactionID);
ISDC(sdcAddress).afterTransfer(false, Strings.toString(transactionID));
return;
}
else{
for(uint256 i = 0; i < to.length; i++){
_transfer(sdcAddress,to[i],values[i]);
}
ISDC(sdcAddress).afterTransfer(true, transactionID);
ISDC(sdcAddress).afterTransfer(true, Strings.toString(transactionID));
}
}

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

}
for(uint256 i = 0; i < to.length; i++){
_transfer(from[i],to[i],values[i]);
}
ISDC(sdcAddress).afterTransfer(true, transactionID);
ISDC(sdcAddress).afterTransfer(true, Strings.toString(transactionID));
}

}
44 changes: 23 additions & 21 deletions assets/erc-6123/contracts/ISDC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ interface ISDC {
/**
* @dev Emitted when a new trade is incepted from a eligible counterparty
* @param initiator is the address from which trade was incepted
* @param withParty is the party the inceptor wants to trade with
* @param tradeId is the trade ID (e.g. generated internally)
* @param tradeData holding the trade parameters
* @param tradeData a description of the trade specification e.g. in xml format, suggested structure - see assets/eip-6123/doc/sample-tradedata-filestructure.xml
* @param position is the position the inceptor has in that trade
* @param paymentAmount is the payment amount which can be positive or negative (viewed from the inceptor)
* @param initialSettlementData the initial settlement data (e.g. initial market data at which trade was incepted)
*/
event TradeIncepted(address initiator, string tradeId, string tradeData);
event TradeIncepted(address initiator, address withParty, string tradeId, string tradeData, int position, int256 paymentAmount, string initialSettlementData);

/**
* @dev Emitted when an incepted trade is confirmed by the opposite counterparty
Expand All @@ -99,34 +103,38 @@ interface ISDC {

/**
* @dev Emitted when an active trade is terminated
* @param tradeId the trade identifier of the activated trade
* @param cause string holding data associated with the termination, e.g. transactionData upon a failed transaction
*/
event TradeTerminated(string cause);
event TradeTerminated(string tradeId, string cause);

/* Events related to the settlement process */

/**
* @dev Emitted when Settlement phase is initiated
* @dev Emitted when a settlement gets requested
* @param initiator the address of the requesting party
* @param tradeData holding the stored trade data
* @param lastSettlementData holding the settlementdata from previous settlement (next settlement will be the increment of next valuation compared to former valuation)
*/
event SettlementEvaluated();
event SettlementRequested(address initiator, string tradeData, string lastSettlementData);

/**
* @dev Emitted when settlement process has been finished
* @dev Emitted when Settlement has been valued and settlement phase is initiated
* @param initiator the address of the requesting party
* @param settlementAmount the settlement amount. If settlementAmount > 0 then receivingParty receives this amount from other party. If settlementAmount < 0 then other party receives -settlementAmount from receivingParty.
* @param settlementData. the tripple (product, previousSettlementData, settlementData) determines the settlementAmount.
*/
event SettlementTranfered(string transactionData);
event SettlementEvaluated(address initiator, int256 settlementAmount, string settlementData);

/**
* @dev Emitted when settlement process has been finished
*/
event SettlementFailed(string transactionData);
event SettlementTransferred(string transactionData);

/**
* @dev Emitted when a settlement gets requested
* @param initiator the address of the requesting party
* @param tradeData holding the stored trade data
* @param lastSettlementData holding the settlementdata from previous settlement (next settlement will be the increment of next valuation compared to former valuation)
* @dev Emitted when settlement process has been finished
*/
event SettlementRequested(address initiator, string tradeData, string lastSettlementData);
event SettlementFailed(string transactionData);

/* Events related to trade termination */

Expand Down Expand Up @@ -154,12 +162,6 @@ interface ISDC {
*/
event TradeTerminationCanceled(address cpAddress, string tradeId, string terminationTerms);

/**
* @dev Emitted when trade processing is halted
* @param message of what has happened
*/
event ProcessHalted(string message);

/*------------------------------------------- FUNCTIONALITY ---------------------------------------------------------------------------------------*/

/// Trade Inception
Expand Down Expand Up @@ -218,9 +220,9 @@ 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 transactionData data associtated with the transfer, will be emitted via the events.
* @dev emit a {SettlementTranfered} or a {SettlementFailed} event. May emit a {TradeTerminated} event.
* @dev emit a {SettlementTransferred} or a {SettlementFailed} event. May emit a {TradeTerminated} event.
*/
function afterTransfer(bool success, uint256 transactionData) external;
function afterTransfer(bool success, string memory transactionData) external;

/// Trade termination

Expand Down
4 changes: 2 additions & 2 deletions assets/erc-6123/contracts/SDCSingleTrade.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import "./ERC20Settlement.sol";
* - upon termination all remaining 'locked' amounts will be transferred back to the counterparties
*/

abstract contract SDC is ISDC {
abstract contract SDCSingleTrade is ISDC {
/*
* Trade States
*/
Expand Down Expand Up @@ -143,7 +143,7 @@ abstract contract SDC is ISDC {
upfrontPayment = _position == 1 ? _paymentAmount : -_paymentAmount; // upfrontPayment is saved with view on the receiving party
tradeID = Strings.toString(transactionHash);
tradeData = _tradeData; // Set trade data to enable querying already in inception state
emit TradeIncepted(msg.sender, tradeID, _tradeData);
emit TradeIncepted(msg.sender, _withParty, tradeID, _tradeData, _position, _paymentAmount, _initialSettlementData);
}

/*
Expand Down
19 changes: 9 additions & 10 deletions assets/erc-6123/contracts/SDCSingleTradePledgedBalance.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ import "./ERC20Settlement.sol";
*-------------------------------------*
*/

contract SDCPledgedBalance is SDC {

contract SDCSingleTradePledgedBalance is SDCSingleTrade {

struct MarginRequirement {
uint256 buffer;
Expand All @@ -54,7 +53,7 @@ contract SDCPledgedBalance is SDC {
address _settlementToken,
uint256 _initialBuffer, // m
uint256 _initalTerminationFee // p
) SDC(_party1,_party2,_settlementToken) {
) SDCSingleTrade(_party1,_party2,_settlementToken) {
marginRequirements[party1] = MarginRequirement(_initialBuffer, _initalTerminationFee);
marginRequirements[party2] = MarginRequirement(_initialBuffer, _initalTerminationFee);
}
Expand Down Expand Up @@ -87,7 +86,7 @@ contract SDCPledgedBalance is SDC {
address[] memory to = new address[](1);
uint256[] memory amounts = new uint256[](1);
from[0] = settlementPayer; to[0] = otherParty(settlementPayer); amounts[0] = transferAmount;
emit SettlementEvaluated();
emit SettlementEvaluated(msg.sender, settlementAmount, _settlementData);
setTradeState(TradeState.InTransfer);
settlementToken.checkedBatchTransferFrom(from,to,amounts,transactionID);
}
Expand All @@ -96,36 +95,36 @@ contract SDCPledgedBalance is SDC {
* afterTransfer 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 transactionHash) external override {
function afterTransfer(bool success, string memory transactionHash) external override {
if ( inStateConfirmed()){
if (success){
setTradeState(TradeState.Settled);
emit TradeActivated(getTradeID());
}
else{
setTradeState(TradeState.Terminated);
emit TradeTerminated("Upfront Transfer Failure");
emit TradeTerminated(tradeID, "Upfront Transfer Failure");
}
}
else if ( inStateTransfer() ){
if (success){
setTradeState(TradeState.Settled);
emit SettlementTranfered("Settlement Settled - Pledge Transfer");
emit SettlementTransferred("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);
processTerminationWithPledge(settlementAmount);
emit TradeTerminated("Settlement Failed - Pledge Transfer");
emit TradeTerminated(tradeID, "Settlement Failed - Pledge Transfer");
}
}
else if( inStateTermination() ){
if (success){
setTradeState(TradeState.Terminated);
emit TradeTerminated("Trade terminated sucessfully");
emit TradeTerminated(tradeID, "Trade terminated sucessfully");
}
else{
emit TradeTerminated("Mutual Termination failed - Pledge Transfer");
emit TradeTerminated(tradeID, "Mutual Termination failed - Pledge Transfer");
processTerminationWithPledge(getTerminationPayment());
}
}
Expand Down
11 changes: 5 additions & 6 deletions assets/erc-6123/test/SDCTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,12 @@ describe("Livecycle Unit-Tests for SDC Plege Balance", () => {
counterparty1 = _counterparty1;
counterparty2 = _counterparty2;
ERC20Factory = await ethers.getContractFactory("ERC20Settlement");
SDCFactory = await ethers.getContractFactory("SDCPledgedBalance");
SDCFactory = await ethers.getContractFactory("SDCSingleTradePledgedBalance");
//oken = await ERC20Factory.deploy();
// await token.deployed();
});



it("1. Counterparties incept and confirm a trade successfully, Upfront is transferred from CP1 to CP2", async () => {
let token = await ERC20Factory.deploy();
await token.connect(counterparty1).mint(counterparty1.address,initialLiquidityBalance);
Expand Down Expand Up @@ -187,7 +186,7 @@ describe("Livecycle Unit-Tests for SDC Plege Balance", () => {
const incept_call = await sdc.connect(counterparty1).inceptTrade(counterparty2.address, trade_data, 1, upfront, "initialMarketData");
const receipt = await incept_call.wait();
const event = receipt.events.find(event => event.event === 'TradeIncepted');
const trade_id = event.args[1];
const trade_id = event.args[2];
const confirm_call = await sdc.connect(counterparty2).confirmTrade(counterparty1.address, trade_data, -1, -upfront, "initialMarketData");
await expect(confirm_call).to.emit(sdc, "TradeConfirmed");
const terminate_call = await sdc.connect(counterparty1).requestTradeTermination(trade_id, terminationPayment, "terminationTerms");
Expand All @@ -212,7 +211,7 @@ describe("Livecycle Unit-Tests for SDC Plege Balance", () => {
const incept_call = await sdc.connect(counterparty1).inceptTrade(counterparty2.address, trade_data, 1, 0, "initialMarketData");
const receipt = await incept_call.wait();
const event = receipt.events.find(event => event.event === 'TradeIncepted');
const trade_id = event.args[1];
const trade_id = event.args[2];
const confirm_call = await sdc.connect(counterparty2).confirmTrade(counterparty1.address, trade_data, -1, 0, "initialMarketData");
const terminate_call = await sdc.connect(counterparty2).requestTradeTermination(trade_id, -terminationPayment, "terminationTerms");
const confirm_terminate_call = await sdc.connect(counterparty1).confirmTradeTermination(trade_id, +terminationPayment, "terminationTerms");
Expand All @@ -229,7 +228,7 @@ describe("Livecycle Unit-Tests for SDC Plege Balance", () => {
const incept_call = await sdc.connect(counterparty1).inceptTrade(counterparty2.address, trade_data, 1, 0, "initialMarketData");
const receipt = await incept_call.wait();
const event = receipt.events.find(event => event.event === 'TradeIncepted');
const trade_id = event.args[1];
const trade_id = event.args[2];
const confirm_call = await sdc.connect(counterparty2).confirmTrade(counterparty1.address, trade_data, -1, 0, "initialMarketData");
const terminate_call = await sdc.connect(counterparty1).requestTradeTermination(trade_id, -terminationPayment, "terminationTerms");
const confirm_terminate_call = await sdc.connect(counterparty2).confirmTradeTermination(trade_id, +terminationPayment, "terminationTerms");
Expand Down Expand Up @@ -305,7 +304,7 @@ describe("Livecycle Unit-Tests for SDC Plege Balance", () => {
const incept_call = await sdc.connect(counterparty1).inceptTrade(counterparty2.address, trade_data, 1, 0, "initialMarketData");
const receipt = await incept_call.wait();
const event = receipt.events.find(event => event.event === 'TradeIncepted');
const trade_id = event.args[1];
const trade_id = event.args[2];
const confirm_call = await sdc.connect(counterparty2).confirmTrade(counterparty1.address, trade_data, -1, 0, "initialMarketData");
await expect(confirm_call).to.emit(sdc, "TradeConfirmed");
const terminate_call = await sdc.connect(counterparty1).requestTradeTermination(trade_id, 10000000, "terminationTerms");
Expand Down

0 comments on commit ff5a0ba

Please sign in to comment.