Skip to content

Commit

Permalink
emit EndedSponsorPosition when sponsors are removed. Don't register a…
Browse files Browse the repository at this point in the history
…ny party members with EMPCreator (#1353)

Signed-off-by: Nick Pai <npai.nyc@gmail.com>
  • Loading branch information
nicholaspai authored May 5, 2020
1 parent 3e4b7db commit ed62317
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ contract ExpiringMultiPartyCreator is ContractCreator, Testable {
// also need to attack the base chain for this long to prevent dispute transactions from processing.
uint256 public constant STRICT_LIQUIDATION_LIVENESS = 3600;

event CreatedExpiringMultiParty(address indexed expiringMultiPartyAddress, address indexed partyMemberAddress);
event CreatedExpiringMultiParty(address indexed expiringMultiPartyAddress, address indexed deployerAddress);

/**
* @notice Constructs the ExpiringMultiPartyCreator contract.
Expand Down Expand Up @@ -110,17 +110,13 @@ contract ExpiringMultiPartyCreator is ContractCreator, Testable {

/**
* @notice Creates an instance of expiring multi party and registers it within the registry.
* @dev caller is automatically registered as the first (and only) party member.
* @param params is a `ConstructorParams` object from ExpiringMultiParty.
* @return address of the deployed ExpiringMultiParty contract
*/
function createExpiringMultiParty(Params memory params) public returns (address) {
ExpiringMultiParty derivative = new ExpiringMultiParty(_convertParams(params));

address[] memory parties = new address[](1);
parties[0] = msg.sender;

_registerContract(parties, address(derivative));
_registerContract(new address[](0), address(derivative));

emit CreatedExpiringMultiParty(address(derivative), msg.sender);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ contract PricelessPositionManager is FeePayer, AdministrateeInterface {

emit RequestTransferPositionExecuted(msg.sender, newSponsorAddress);
emit NewSponsor(newSponsorAddress);
emit EndedSponsorPosition(msg.sender);
}

/**
Expand Down Expand Up @@ -480,6 +481,7 @@ contract PricelessPositionManager is FeePayer, AdministrateeInterface {

// Reset the position state as all the value has been removed after settlement.
delete positions[msg.sender];
emit EndedSponsorPosition(msg.sender);
}

// Take the min of the remaining collateral and the collateral "owed". If the contract is undercapitalized,
Expand Down
7 changes: 3 additions & 4 deletions core/test/financial-templates/ExpiringMultiPartyCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const IdentifierWhitelist = artifacts.require("IdentifierWhitelist");
const AddressWhitelist = artifacts.require("AddressWhitelist");
const Timer = artifacts.require("Timer");

contract("ExpiringMultiParty", function(accounts) {
contract("ExpiringMultiPartyCreator", function(accounts) {
let contractCreator = accounts[0];

// Contract variables
Expand Down Expand Up @@ -133,7 +133,7 @@ contract("ExpiringMultiParty", function(accounts) {
let expiringMultiPartyAddress;
truffleAssert.eventEmitted(createdAddressResult, "CreatedExpiringMultiParty", ev => {
expiringMultiPartyAddress = ev.expiringMultiPartyAddress;
return ev.expiringMultiPartyAddress != 0 && ev.partyMemberAddress == contractCreator;
return ev.expiringMultiPartyAddress != 0 && ev.deployerAddress == contractCreator;
});

// Ensure value returned from the event is the same as returned from the function.
Expand Down Expand Up @@ -163,9 +163,8 @@ contract("ExpiringMultiParty", function(accounts) {
let expiringMultiPartyAddress;
truffleAssert.eventEmitted(createdAddressResult, "CreatedExpiringMultiParty", ev => {
expiringMultiPartyAddress = ev.expiringMultiPartyAddress;
return ev.expiringMultiPartyAddress != 0 && ev.partyMemberAddress == contractCreator;
return ev.expiringMultiPartyAddress != 0 && ev.deployerAddress == contractCreator;
});
assert.isTrue(await registry.isContractRegistered(expiringMultiPartyAddress));
assert.isTrue(await registry.isPartyMemberOfContract(contractCreator, expiringMultiPartyAddress));
});
});
12 changes: 10 additions & 2 deletions core/test/financial-templates/Liquidatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,10 @@ contract("Liquidatable", function(accounts) {
});
});

describe("Liquidation has been created", () => {
describe("Full liquidation has been created", () => {
// Used to catch events.
let liquidationResult;

beforeEach(async () => {
// Create position
await liquidationContract.create(
Expand All @@ -453,7 +456,7 @@ contract("Liquidatable", function(accounts) {

// Create a Liquidation
liquidationTime = await liquidationContract.getCurrentTime();
await liquidationContract.createLiquidation(
liquidationResult = await liquidationContract.createLiquidation(
sponsor,
{ rawValue: pricePerToken.toString() },
{ rawValue: amountOfSynthetic.toString() },
Expand Down Expand Up @@ -486,6 +489,11 @@ contract("Liquidatable", function(accounts) {
assert.equal(newLiquidation.liquidationTime.toString(), liquidationTime.toString());
assert.equal(newLiquidation.settlementPrice.toString(), "0");
});
it("EndedSponsorPosition event was emitted", async () => {
truffleAssert.eventEmitted(liquidationResult, "EndedSponsorPosition", ev => {
return ev.sponsor == sponsor;
});
});
it("Liquidation does not exist", async () => {
assert(await didContractThrow(liquidationContract.liquidations(sponsor, liquidationParams.falseLiquidationId)));
});
Expand Down
8 changes: 6 additions & 2 deletions core/test/financial-templates/PricelessPositionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -792,15 +792,19 @@ contract("PricelessPositionManager", function(accounts) {
assert.equal(redeemedAmount.toString(), expectedTotalSponsorCollateralReturned.toString());

// Execute the settlement and check balances.
await settleExpired({ from: sponsor });
await pricelessPositionManager.settleExpired({ from: sponsor });
settleExpiredResult = await settleExpired({ from: sponsor });
const sponsorFinalCollateral = await collateral.balanceOf(sponsor);
const sponsorFinalSynthetic = await tokenCurrency.balanceOf(sponsor);
assert.equal(
sponsorFinalCollateral.sub(sponsorInitialCollateral).toString(),
expectedTotalSponsorCollateralReturned
);

// Check events.
truffleAssert.eventEmitted(settleExpiredResult, "EndedSponsorPosition", ev => {
return ev.sponsor == sponsor;
});

// The token Sponsor should have no synthetic positions left after settlement.
assert.equal(sponsorFinalSynthetic, 0);

Expand Down

0 comments on commit ed62317

Please sign in to comment.