Skip to content

Commit

Permalink
DEBUG LOGS - REMOVE ME! git reset --soft ee8117e
Browse files Browse the repository at this point in the history
  • Loading branch information
rackstar committed Oct 19, 2023
1 parent ee8117e commit 8b8f724
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
15 changes: 13 additions & 2 deletions contracts/modules/capital/Ramm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "../../interfaces/IRamm.sol";
import "../../interfaces/ITokenController.sol";
import "../../libraries/Math.sol";
import "../../libraries/SafeUintCast.sol";
import "hardhat/console.sol";

contract Ramm is IRamm, MasterAwareV2 {
using SafeUintCast for uint;
Expand Down Expand Up @@ -125,7 +126,12 @@ contract Ramm is IRamm, MasterAwareV2 {
nxmB = nxmB * eth / state.eth;

nxmOut = state.nxmA - nxmA;

console.log('---- swapEthForNxm ----');
console.log('SOL state.eth', state.eth);
console.log('SOL eth', eth);
console.log('SOL nxmA', nxmA);
console.log('SOL nxmB', nxmB);
console.log('SOL nxmOut', nxmOut);
if (nxmOut < minAmountOut) {
revert InsufficientAmountOut(nxmOut, minAmountOut);
}
Expand Down Expand Up @@ -180,7 +186,12 @@ contract Ramm is IRamm, MasterAwareV2 {
nxmA = nxmA * eth / state.eth;

ethOut = state.eth - eth;

console.log('---- swapNxmForEth ----');
console.log('SOL state.eth', state.eth);
console.log('SOL eth', eth);
console.log('SOL nxmA', nxmA);
console.log('SOL nxmB', nxmB);
console.log('SOL nxmOut', ethOut);
if (ethOut < minAmountOut) {
revert InsufficientAmountOut(ethOut, minAmountOut);
}
Expand Down
26 changes: 21 additions & 5 deletions test/unit/Ramm/swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ const getExpectedStateAfterSwapNxmForEth = (state, nxmIn) => {
const currentEthLiquidity = state.eth;
const newNxmB = state.nxmB.add(nxmIn);
const newEthLiquidity = currentEthLiquidity.mul(state.nxmB).div(newNxmB);
return {
newNxmB,
const res = {
newEthLiquidity,
newNxmA: state.nxmA.mul(newEthLiquidity).div(currentEthLiquidity),
newNxmB,
ethOut: currentEthLiquidity.sub(newEthLiquidity),
};
console.log('---- SwapNxmForEth ----');
console.log('JSS state.eth', state.eth.toString());
console.log('JSs eth', newEthLiquidity.toString());
console.log('JSS nxmA', state.nxmA.mul(newEthLiquidity).div(currentEthLiquidity).toString());
console.log('JSS nxmB', newNxmB.toString());
console.log('JSS ethOut', currentEthLiquidity.sub(newEthLiquidity).toString());
return res;
};

/**
Expand All @@ -71,12 +78,19 @@ const getExpectedStateAfterSwapEthForNxm = (state, ethIn) => {
const currentEthLiquidity = state.eth;
const newEthLiquidity = currentEthLiquidity.add(ethIn);
const newNxmA = currentEthLiquidity.mul(state.nxmA).div(newEthLiquidity);
return {
const res = {
newEthLiquidity,
newNxmA,
newNxmB: state.nxmB.mul(newEthLiquidity).div(currentEthLiquidity),
nxmOut: state.nxmA.sub(newNxmA),
};
console.log('---- SwapEthForNxm ----');
console.log('JSS state.eth', state.eth.toString());
console.log('JSs eth', newEthLiquidity.toString());
console.log('JSS nxmA', newNxmA.toString());
console.log('JSS nxmB', state.nxmB.mul(newEthLiquidity).div(currentEthLiquidity).toString());
console.log('JSS nxmOut', state.nxmA.sub(newNxmA).toString());
return res;
};

describe('swap', function () {
Expand Down Expand Up @@ -291,7 +305,7 @@ describe('swap', function () {
expect(nxmOut).to.be.equal(expectedNxmOut);
});

it('should emit NxmSwappedForEth when successfully swapped NXM for ETH', async function () {
it.only('should emit NxmSwappedForEth when successfully swapped NXM for ETH', async function () {

Check failure on line 308 in test/unit/Ramm/swap.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected exclusive mocha test
const fixture = await loadFixture(setup);
const { ramm, pool, mcr, tokenController } = fixture.contracts;
const [member] = fixture.accounts.members;
Expand All @@ -305,11 +319,12 @@ describe('swap', function () {
const state = await getStateAtBlockTimestamp(ramm, pool, mcr, tokenController, timestamp + 1);
const { ethOut } = getExpectedStateAfterSwapNxmForEth(state, nxmIn);

// await setNextBlockBaseFee(0);
const swap = ramm.connect(member).swap(nxmIn, minAmountOut, deadline, { maxPriorityFeePerGas: 0 });
await expect(swap).to.emit(ramm, 'NxmSwappedForEth').withArgs(member.address, nxmIn, ethOut);
});

it('should emit EthSwappedForNxm when successfully swapped ETH for NXM', async function () {
it.only('should emit EthSwappedForNxm when successfully swapped ETH for NXM', async function () {

Check failure on line 327 in test/unit/Ramm/swap.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected exclusive mocha test
const fixture = await loadFixture(setup);
const { ramm, pool, mcr, tokenController } = fixture.contracts;
const [member] = fixture.accounts.members;
Expand All @@ -323,6 +338,7 @@ describe('swap', function () {
const state = await getStateAtBlockTimestamp(ramm, pool, mcr, tokenController, timestamp + 1);
const { nxmOut } = getExpectedStateAfterSwapEthForNxm(state, ethIn);

// await setNextBlockBaseFee(0);
const swap = ramm.connect(member).swap(0, minAmountOut, deadline, { value: ethIn, maxPriorityFeePerGas: 0 });
await expect(swap).to.emit(ramm, 'EthSwappedForNxm').withArgs(member.address, ethIn, nxmOut);
});
Expand Down

0 comments on commit 8b8f724

Please sign in to comment.