Skip to content

Commit

Permalink
Brian/gim trade info update (#115)
Browse files Browse the repository at this point in the history
Change require to check that component is part of rebalance instead of current component. Allows trade info fetching for new components.
  • Loading branch information
bweick committed Jul 26, 2021
1 parent 266de14 commit 81f4cff
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
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
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@setprotocol/set-protocol-v2",
"version": "0.0.47",
"version": "0.0.48",
"description": "",
"main": "dist",
"types": "dist/types",
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

0 comments on commit 81f4cff

Please sign in to comment.