Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

Commit

Permalink
CU-myvunu: tests completed
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddentao committed Jun 1, 2021
1 parent 600df93 commit 6f80b90
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 30 deletions.
6 changes: 3 additions & 3 deletions contracts/CommonUpgradeFacet.sol
Expand Up @@ -14,8 +14,8 @@ contract CommonUpgradeFacet is Controller, IDiamondUpgradeFacet {
}

function getVersionInfo () public override pure returns (string memory num_, uint256 date_, string memory hash_) {
num_ = "1.0.0-local.1622125613634";
date_ = 1622125613;
hash_ = "c8bd93b460e85c98596bafc0bc270a2cfd9ae98e";
num_ = "1.0.0-local.1622543414262";
date_ = 1622543414;
hash_ = "600df938e274580aed301fa109710a7d81bc8e57";
}
}
24 changes: 15 additions & 9 deletions contracts/PolicyTranchTokens.sol
Expand Up @@ -81,11 +81,14 @@ contract PolicyTranchTokensFacet is EternalStorage, Controller, IDiamondFacet, I
function _transfer(uint _index, address _from, address _to, uint256 _value) private {
// when token holder is sending to the market
address market = settings().getRootAddress(SETTING_MARKET);
address treasury = address(_getTreasury());

// if this is a transfer to the market
if (market == _to) {
// and they're not the initial balance holder of the token (i.e. the policy/tranch)
// and the sender is not the initial holder of the token
address initialHolder = dataAddress[__i(_index, "initialHolder")];
if (initialHolder != _from) {
// then they must be a trader, in which case ony allow this if the policy is active
// then the sender must be a trader, in which case ony allow this if the policy is active
require(dataUint256["state"] == POLICY_STATE_ACTIVE, 'can only trade when policy is active');
}
}
Expand All @@ -98,10 +101,10 @@ contract PolicyTranchTokensFacet is EternalStorage, Controller, IDiamondFacet, I
dataUint256[fromKey] = dataUint256[fromKey].sub(_value);
dataUint256[toKey] = dataUint256[toKey].add(_value);

// this is a transfer from the market to a buyer
if (market == _from) {
// if we are in the initial sale period
if (dataUint256[__i(_index, "state")] == TRANCH_STATE_SELLING) {
// if we are in the initial sale period
if (dataUint256[__i(_index, "state")] == TRANCH_STATE_SELLING) {
// this is a transfer from the market to a buyer
if (market == _from) {
// record how many "shares" were sold
dataUint256[__i(_index, "sharesSold")] = dataUint256[__i(_index, "sharesSold")].add(_value);
// update tranch balance
Expand All @@ -116,8 +119,11 @@ contract PolicyTranchTokensFacet is EternalStorage, Controller, IDiamondFacet, I
_setTranchState(_index, TRANCH_STATE_ACTIVE);
}
}
// if we are in policy buyback state
else if (dataUint256["state"] == POLICY_STATE_BUYBACK) {
}
// if we are in policy buyback state
else if (dataUint256["state"] == POLICY_STATE_BUYBACK) {
// if this is a transfer to the treasury
if (treasury == _to) {
// if we've bought back all tokens
if (dataUint256[toKey] == dataUint256[__i(_index, "numShares")]) {
dataBool[__i(_index, "buybackCompleted")] = true;
Expand All @@ -130,6 +136,6 @@ contract PolicyTranchTokensFacet is EternalStorage, Controller, IDiamondFacet, I
}
}
}
}
}
}
}
15 changes: 0 additions & 15 deletions deployedAddresses.json
Expand Up @@ -2,41 +2,26 @@
"ACL": {
"4": {
"address": "0x22355D3783513Fb0d9f3AE90544dc5D5C19E3453"
},
"5777": {
"address": "0x4Fd35574a2C60131925D305F293122459D60128A"
}
},
"Settings": {
"4": {
"address": "0x96503D4a21641F74F01886A3D4ffA9d526c568Bb"
},
"5777": {
"address": "0xcF9848324f364E1b6D115a151b49D6D53b45D519"
}
},
"EntityDeployer": {
"4": {
"address": "0xbAC2a36596Cf30cd5099997f8baaB4EB0E346c69"
},
"5777": {
"address": "0x938Ff5A356C0DB4eff4002AC592B4E7CA6c81DD3"
}
},
"EtherToken": {
"4": {
"address": "0xC9296387C5f6C8A87e7867e711c9ED00100b9705"
},
"5777": {
"address": "0xC3a51657Fd28A0441BA1C2D6A002dCdbdF1C8183"
}
},
"MatchingMarket": {
"4": {
"address": "0xC3Cf462fb3bd4eE4AF5D07fc4EfdE75b6596f5f1"
},
"5777": {
"address": "0x639e4fEf825D51C9c1d358dcf5709CC0770b4eA6"
}
}
}
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@nayms/contracts",
"version": "1.0.0-local.1622125613634",
"version": "1.0.0-local.1622543414262",
"description": "Nayms smart contracts",
"main": "index.js",
"publishConfig": {
Expand Down
40 changes: 38 additions & 2 deletions test/integrationFlow.js
Expand Up @@ -76,6 +76,7 @@ contract('Integration: Flow', accounts => {
let POLICY_STATE_APPROVED
let POLICY_STATE_CANCELLED
let POLICY_STATE_BUYBACK
let POLICY_STATE_CLOSED

let TRANCH_STATE_CREATED
let TRANCH_STATE_SELLING
Expand Down Expand Up @@ -195,6 +196,7 @@ contract('Integration: Flow', accounts => {
POLICY_STATE_IN_APPROVAL = await policyStates.POLICY_STATE_IN_APPROVAL()
POLICY_STATE_APPROVED = await policyStates.POLICY_STATE_APPROVED()
POLICY_STATE_BUYBACK = await policyStates.POLICY_STATE_BUYBACK()
POLICY_STATE_CLOSED = await policyStates.POLICY_STATE_CLOSED()

TRANCH_STATE_CREATED = await policyStates.TRANCH_STATE_CREATED()
TRANCH_STATE_SELLING = await policyStates.TRANCH_STATE_SELLING()
Expand Down Expand Up @@ -1280,7 +1282,7 @@ contract('Integration: Flow', accounts => {
expect(treasuryPostBalance - treasuryPreBalance).to.eq(100)
})

it.only('keeps track of when a tranch has been totally bought back', async () => {
it('keeps track of when a tranch has been totally bought back', async () => {
const tranchTkn = await getTranchToken(0)

await tranchTkn.balanceOf(entity.address).should.eventually.eq(0)
Expand All @@ -1296,8 +1298,42 @@ contract('Integration: Flow', accounts => {
await market.sellAllAmount(tranchTkn.address, offer[2], etherToken.address, offer[0], { from: accounts[2] });

await tranchTkn.balanceOf(entity.address).should.eventually.eq(numShares)

expect((await policy.getTranchInfo(0)).buybackCompleted_).to.eq(true)
})

it('sets policy to closed once all tranches have been fully bought back', async () => {
// buyback tranch 0
expect((await policy.getTranchInfo(0)).buybackCompleted_).to.eq(false)

const tranchTkn0 = await getTranchToken(0)

const { finalBuybackofferId_: buybackOfferId0 } = await policy.getTranchInfo(0)

const offer0 = await market.getOffer(buybackOfferId0)

await market.sellAllAmount(tranchTkn0.address, offer0[2], etherToken.address, offer0[0], { from: accounts[2] });

expect((await policy.getTranchInfo(0)).buybackCompleted_).to.eq(true)

// check: policy still in buyback state
await policy.getInfo().should.eventually.matchObj({ state_: POLICY_STATE_BUYBACK })

// buyback tranch 1
expect((await policy.getTranchInfo(1)).buybackCompleted_).to.eq(false)

const tranchTkn1 = await getTranchToken(1)

const { finalBuybackofferId_: buybackOfferId1 } = await policy.getTranchInfo(1)

const offer1 = await market.getOffer(buybackOfferId1)

await market.sellAllAmount(tranchTkn1.address, offer1[2], etherToken.address, offer1[0], { from: accounts[2] });

expect((await policy.getTranchInfo(1)).buybackCompleted_).to.eq(true)

// TODO: expect((await policy.getTranchInfo(0)).buybackCompleted_).to.eq(true)
// check: policy now closed
await policy.getInfo().should.eventually.matchObj({ state_: POLICY_STATE_CLOSED })
})
})
})
Expand Down

0 comments on commit 6f80b90

Please sign in to comment.