• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SizeCredit / sdk / 15829486002

23 Jun 2025 04:13PM UTC coverage: 56.275% (-1.9%) from 58.169%
15829486002

push

github

aviggiano
Merge branch 'main' of github.com:SizeCredit/size-sdk

91 of 165 branches covered (55.15%)

Branch coverage included in aggregate %.

326 of 576 relevant lines covered (56.6%)

3132.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.84
/src/Authorization.ts
1
// the order is important
2
export enum Action {
6✔
3
  DEPOSIT,
6✔
4
  WITHDRAW,
6✔
5
  BUY_CREDIT_LIMIT,
6✔
6
  SELL_CREDIT_LIMIT,
6✔
7
  BUY_CREDIT_MARKET,
6✔
8
  SELL_CREDIT_MARKET,
6✔
9
  SELF_LIQUIDATE,
6✔
10
  COMPENSATE,
6✔
11
  SET_USER_CONFIGURATION,
6✔
12
  SET_COPY_LIMIT_ORDER_CONFIGS, // renamed in v1.8
6✔
13
  SET_VAULT, // added in v1.8
6✔
14
  MANAGE_COLLECTION_SUBSCRIPTIONS, // added in v1.8
6✔
15
  // add more actions here
16
  NUMBER_OF_ACTIONS,
6✔
17
}
18

19
type AvailableActions = Exclude<
20
  Action,
21
  Action.NUMBER_OF_ACTIONS | Action.MANAGE_COLLECTION_SUBSCRIPTIONS
22
>;
23

24
export const ActionToFunctionName: Record<AvailableActions, string> = {
6✔
25
  [Action.DEPOSIT]: "deposit",
26
  [Action.WITHDRAW]: "withdraw",
27
  [Action.BUY_CREDIT_LIMIT]: "buyCreditLimit",
28
  [Action.SELL_CREDIT_LIMIT]: "sellCreditLimit",
29
  [Action.BUY_CREDIT_MARKET]: "buyCreditMarket",
30
  [Action.SELL_CREDIT_MARKET]: "sellCreditMarket",
31
  [Action.SELF_LIQUIDATE]: "selfLiquidate",
32
  [Action.COMPENSATE]: "compensate",
33
  [Action.SET_USER_CONFIGURATION]: "setUserConfiguration",
34
  [Action.SET_COPY_LIMIT_ORDER_CONFIGS]: "setCopyLimitOrderConfigs",
35
  [Action.SET_VAULT]: "setVault",
36
};
37

38
export const FunctionNameToAction: Record<string, AvailableActions> =
6✔
39
  Object.fromEntries(
40
    Object.entries(ActionToFunctionName).map(([action, functionName]) => [
66✔
41
      functionName,
42
      Number(action),
43
    ]),
44
  ) as Record<string, AvailableActions>;
45

46
export type ActionsBitmap = bigint;
47

48
export const toBigInt = (actionsBitmap: ActionsBitmap): bigint => actionsBitmap;
576✔
49

50
export const nullActionsBitmap = (): ActionsBitmap => 0n;
58✔
51

52
export const isValid = (actionsBitmap: ActionsBitmap): boolean => {
6✔
53
  const maxValidBitmap = (1n << BigInt(Action.NUMBER_OF_ACTIONS)) - 1n;
×
54
  return toBigInt(actionsBitmap) <= maxValidBitmap;
×
55
};
56

57
export const isActionSet = (
6✔
58
  actionsBitmap: ActionsBitmap,
59
  action: Action,
60
): boolean => (toBigInt(actionsBitmap) & (1n << BigInt(action))) !== 0n;
576✔
61

62
export function getActionsBitmap(
6✔
63
  actionOrActions: Action | Action[],
64
): ActionsBitmap {
65
  // Check if the argument is an array
66
  if (Array.isArray(actionOrActions)) {
60!
67
    const actions = actionOrActions;
60✔
68
    const combineBitmaps = (acc: bigint, action: Action): bigint =>
60✔
69
      acc | (1n << BigInt(action));
190✔
70

71
    return actions.reduce(combineBitmaps, 0n);
60✔
72
  } else {
73
    // Single action case
74
    const action = actionOrActions;
×
75
    return 1n << BigInt(action);
×
76
  }
77
}
78

79
export const Authorization = {
6✔
80
  Action,
81
  toBigInt,
82
  nullActionsBitmap,
83
  isValid,
84
  isActionSet,
85
  getActionsBitmap,
86
};
87

88
export default Authorization;
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc