diff --git a/package.json b/package.json index cbd7c69..43859d0 100644 --- a/package.json +++ b/package.json @@ -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 ", "repository": "https://github.com/TokenUnion/polymarket-sdk.git", diff --git a/src/index.ts b/src/index.ts index 43129b7..e00597c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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"; diff --git a/src/negRisk/index.ts b/src/negRisk/index.ts index 3ce2aab..fd0f2f2 100644 --- a/src/negRisk/index.ts +++ b/src/negRisk/index.ts @@ -39,6 +39,6 @@ const redeemPositions = ({ negRiskAdapterAddress, conditionId, amounts }: Redeem value: "0", }); -const negRisk = { convertPositions, redeemPositions }; +const negRiskOperations = { convertPositions, redeemPositions }; -export { negRisk }; +export { negRiskOperations }; diff --git a/src/utils/getIndexSet.ts b/src/utils/getIndexSet.ts new file mode 100644 index 0000000..cdd712f --- /dev/null +++ b/src/utils/getIndexSet.ts @@ -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 }; diff --git a/src/utils/index.ts b/src/utils/index.ts index b3dc1c5..8af3d20 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -2,3 +2,4 @@ export { erc20ApprovalTransaction } from "./approveErc20"; export { erc1155ApprovalTransaction } from "./approveErc1155"; export { erc20TransferTransaction } from "./transferErc20"; export { ethTransferTransaction } from "./transferEth"; +export { getIndexSet } from "./getIndexSet"; diff --git a/test/getIndexSet.test.ts b/test/getIndexSet.test.ts new file mode 100644 index 0000000..18e37e9 --- /dev/null +++ b/test/getIndexSet.test.ts @@ -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); + }); +});