Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
Szymx95 committed Apr 23, 2024
1 parent 72b4f20 commit 57dbe45
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions test/trinity/StabilityPoolTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1085,10 +1085,11 @@ contract("StabilityPool", async accounts => {
assert.isAtMost(th.getDifference(stability_col_DifferenceERC20, aliceGainERC20), 10000)
})

it("withdrawFromSP(): withdraw from SP forfeiting gains", async () => {
it.only("withdrawFromSP(): withdraw from SP forfeiting gains", async () => {
console.log((await priceFeed.getPrice(erc20.address)).toString())
await openWhaleVessel(erc20, (icr = 10), (extraDebtTokenAmt = 1_000_000))
await stabilityPool.provideToSP(dec(199_000, 18), validCollateral, { from: whale })

// 2 defaulter opens
await openVessel({
asset: erc20.address,
Expand All @@ -1113,11 +1114,16 @@ contract("StabilityPool", async accounts => {

// price drops: defaulter's Vessel falls below MCR, alice and whale Vessel remain active
await priceFeed.setPrice(erc20.address, dec("100", 18))

// defaulter's Vessel is closed.
const liquidationTx_1ERC20 = await vesselManagerOperations.liquidate(erc20.address, defaulter_1, {
from: owner,
}) // 180 TRI closed


const idx = validCollateral.indexOf(erc20.address)
console.log('lastAssetError_Offset after first liquidate ',(await stabilityPool.lastAssetError_Offset(idx)).toString())

const [, liquidatedCollERC20] = th.getEmittedLiquidationValues(liquidationTx_1ERC20)

// Get ActivePool and StabilityPool collateral before retrieval:
Expand All @@ -1127,12 +1133,17 @@ contract("StabilityPool", async accounts => {
// Expect alice to be entitled to 1000/200000 of the liquidated coll

const aliceExpectedGainERC20 = liquidatedCollERC20.mul(toBN(dec(1000, 18))).div(toBN(dec(200_000, 18)))
const idx = validCollateral.indexOf(erc20.address)
const aliceGainERC20 = (await stabilityPool.getDepositorGains(alice, validCollateral))[1][idx]
assert.isTrue(aliceExpectedGainERC20.eq(aliceGainERC20))

// Alice withdraws from SP, chooses not to receive gains to avoid transfer/swap costs
console.log('whale gains 1', ((await stabilityPool.getDepositorGains(whale, validCollateral))[1][idx]).toString())

await stabilityPool.withdrawFromSP(dec(1000, 18), [], { from: alice })
console.log('whale gains 2', ((await stabilityPool.getDepositorGains(whale, validCollateral))[1][idx]).toString())

await stabilityPool.provideToSP(1, validCollateral, { from: alice })
console.log('whale gains 3', ((await stabilityPool.getDepositorGains(whale, validCollateral))[1][idx]).toString())

const active_col_AfterERC20 = await activePool.getAssetBalance(erc20.address)
const stability_col_AfterERC20 = await stabilityPool.getCollateral(erc20.address)
Expand All @@ -1144,7 +1155,11 @@ contract("StabilityPool", async accounts => {
}) // 180 TRI closed
await stabilityPool.withdrawFromSP(dec(199_000, 18), validCollateral, { from: whale })
const stability_col_AfterWhaleERC20 = await stabilityPool.getCollateral(erc20.address)
assert.isAtMost(stability_col_AfterWhaleERC20.sub(aliceExpectedGainERC20), 10000)


const lastAssetError_Offset= (await stabilityPool.lastAssetError_Offset(idx)).div(toBN(10).pow(toBN(18)))

assert.equal(stability_col_AfterWhaleERC20.sub(aliceExpectedGainERC20), lastAssetError_Offset)
})

it("withdrawFromSP(): withdraw from SP, passing same asset twice will revert", async () => {
Expand Down

0 comments on commit 57dbe45

Please sign in to comment.