Skip to content

Commit

Permalink
Add getIndexSet (#7)
Browse files Browse the repository at this point in the history
* add getIndexSet and tests

* add extra test case
  • Loading branch information
mshrieve authored Dec 5, 2023
1 parent 1d96400 commit 0fcef94
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@polymarket/sdk",
"version": "5.0.0",
"version": "5.0.1",
"description": "SDK to simplify common interactions with the Polymarket proxy wallet",
"author": "Tom French <[email protected]>",
"repository": "https://github.com/TokenUnion/polymarket-sdk.git",
Expand Down
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "./conditionalTokens";
export * from "./matic";
export * from "./markets";
export * from "./debt";
export { ethTransferTransaction, erc20TransferTransaction } from "./utils";

export { ethTransferTransaction, erc20TransferTransaction, getIndexSet } from "./utils";
export { getProxyWalletAddress } from "./proxyWallet";
export { negRisk } from "./negRisk";
export { negRiskOperations } from "./negRisk";
4 changes: 2 additions & 2 deletions src/negRisk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ const redeemPositions = ({ negRiskAdapterAddress, conditionId, amounts }: Redeem
value: "0",
});

const negRisk = { convertPositions, redeemPositions };
const negRiskOperations = { convertPositions, redeemPositions };

export { negRisk };
export { negRiskOperations };
5 changes: 5 additions & 0 deletions src/utils/getIndexSet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const getIndexSet = (indices: number[]) =>
// eslint-disable-next-line no-bitwise
[...new Set(indices)].reduce((acc, index) => acc + (1 << index), 0);

export { getIndexSet };
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { erc20ApprovalTransaction } from "./approveErc20";
export { erc1155ApprovalTransaction } from "./approveErc1155";
export { erc20TransferTransaction } from "./transferErc20";
export { ethTransferTransaction } from "./transferEth";
export { getIndexSet } from "./getIndexSet";
28 changes: 28 additions & 0 deletions test/getIndexSet.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* eslint-env jest */

import { getIndexSet } from "../src";

const testCases = [
[[0], 1],
[[1], 2],
[[0, 1], 3],
[[0, 0, 1], 3],
[[2], 4],
[[0, 2], 5],
[[1, 2], 6],
[[0, 1, 2], 7],
[[3], 8],
[[0, 3], 9],
[[1, 3], 10],
[[0, 1, 3], 11],
[[2, 3], 12],
[[0, 2, 3], 13],
[[1, 2, 3], 14],
[[0, 1, 2, 3], 15],
] as [number[], number][];

describe("getIndexSet", () => {
it.each(testCases)(`should compute the index set`, (indices, expectedIndexSet) => {
expect(getIndexSet(indices)).toEqual(expectedIndexSet);
});
});

0 comments on commit 0fcef94

Please sign in to comment.