Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brian/gim trade info update #115

Merged
merged 3 commits into from Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion contracts/protocol/modules/GeneralIndexModule.sol
Expand Up @@ -576,7 +576,10 @@ contract GeneralIndexModule is ModuleBase, ReentrancyGuard {
onlyValidAndInitializedSet(_setToken)
returns (bool, uint256)
{
require(_setToken.isComponent(address(_component)), "Component not recognized");
require(
rebalanceInfo[_setToken].rebalanceComponents.contains(address(_component)),
"Component not recognized"
);
uint256 totalSupply = _setToken.totalSupply();
return _calculateTradeSizeAndDirection(_setToken, _component, totalSupply);
}
Expand Down
36 changes: 31 additions & 5 deletions test/protocol/modules/generalIndexModule.spec.ts
Expand Up @@ -20,7 +20,8 @@ import {
ether,
preciseDiv,
preciseMul,
preciseMulCeil
preciseMulCeil,
usdc
} from "@utils/index";
import {
cacheBeforeEach,
Expand Down Expand Up @@ -2185,9 +2186,9 @@ describe("GeneralIndexModule", () => {

before(async () => {
// current units [ether(86.9565217), bitcoin(.01111111), ether(100), ZERO]
newComponents = [];
newComponents = [setup.usdc.address];
oldTargetUnits = [ether("60.869565780223716593"), bitcoin(.02), ether(55)];
newTargetUnits = [];
newTargetUnits = [usdc(100)];
issueAmount = ether("20.000000000000000001");
});

Expand All @@ -2208,6 +2209,8 @@ describe("GeneralIndexModule", () => {
};

beforeEach(async () => {
await indexModule.setTradeMaximums(index.address, [setup.usdc.address], [usdc(3000)]);

initializeSubjectVariables();

await startRebalance();
Expand Down Expand Up @@ -2242,6 +2245,29 @@ describe("GeneralIndexModule", () => {
expect(isSendTokenFixed).to.be.true;
});

describe("when the component is being added to the Set", async () => {
beforeEach(async () => {
subjectComponent = setup.usdc.address;
});

it("the correct trade direction and size should be returned", async () => {
const totalSupply = await subjectSetToken.totalSupply();
const currentUsdcUnit = await subjectSetToken.getDefaultPositionRealUnit(setup.usdc.address);
const expectedUsdcSize = preciseDiv(
preciseMulCeil(usdc(100), totalSupply).sub(preciseMul(currentUsdcUnit, totalSupply)),
PRECISE_UNIT.sub(feePercentage)
);

const [
isSendTokenFixed,
componentQuantity,
] = await subject();

expect(componentQuantity).to.eq(expectedUsdcSize);
expect(isSendTokenFixed).to.be.false;
});
});

describe("and the buy component does not meet the max trade size", async () => {
beforeEach(async () => {
await indexModule.startRebalance(
Expand Down Expand Up @@ -2283,9 +2309,9 @@ describe("GeneralIndexModule", () => {
});
});

describe("when the component is not valid", async () => {
describe("when the component is not part of the rebalance", async () => {
beforeEach(() => {
subjectComponent = ADDRESS_ZERO;
subjectComponent = setup.weth.address;
});

it("should revert", async () => {
Expand Down