@reyaxyz/sdk 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/index.js +4 -1
  2. package/dist/index.js.map +1 -1
  3. package/dist/services/executeTransaction.js.map +1 -1
  4. package/dist/services/lp/index.js +19 -0
  5. package/dist/services/lp/index.js.map +1 -0
  6. package/dist/services/lp/lp.js +28 -9
  7. package/dist/services/lp/lp.js.map +1 -1
  8. package/dist/services/lp/types.js.map +1 -1
  9. package/dist/services/margin-accounts/account.js.map +1 -1
  10. package/dist/services/margin-accounts/deposit.js.map +1 -1
  11. package/dist/services/margin-accounts/index.js +21 -0
  12. package/dist/services/margin-accounts/index.js.map +1 -0
  13. package/dist/services/margin-accounts/types.js.map +1 -1
  14. package/dist/services/margin-accounts/withdraw.js.map +1 -1
  15. package/dist/services/orders/index.js +19 -0
  16. package/dist/services/orders/index.js.map +1 -0
  17. package/dist/services/orders/order.js +13 -4
  18. package/dist/services/orders/order.js.map +1 -1
  19. package/dist/services/orders/types.js.map +1 -1
  20. package/dist/services/token/approve.js +4 -3
  21. package/dist/services/token/approve.js.map +1 -1
  22. package/dist/services/token/common.js.map +1 -1
  23. package/dist/services/token/getAllowance.js +4 -3
  24. package/dist/services/token/getAllowance.js.map +1 -1
  25. package/dist/services/token/index.js +20 -0
  26. package/dist/services/token/index.js.map +1 -0
  27. package/dist/services/token/types.js.map +1 -1
  28. package/dist/types/index.d.ts +4 -1
  29. package/dist/types/index.d.ts.map +1 -1
  30. package/dist/types/services/executeTransaction.d.ts +3 -3
  31. package/dist/types/services/executeTransaction.d.ts.map +1 -1
  32. package/dist/types/services/lp/index.d.ts +3 -0
  33. package/dist/types/services/lp/index.d.ts.map +1 -0
  34. package/dist/types/services/lp/lp.d.ts +3 -3
  35. package/dist/types/services/lp/lp.d.ts.map +1 -1
  36. package/dist/types/services/lp/types.d.ts +12 -11
  37. package/dist/types/services/lp/types.d.ts.map +1 -1
  38. package/dist/types/services/margin-accounts/account.d.ts +2 -2
  39. package/dist/types/services/margin-accounts/account.d.ts.map +1 -1
  40. package/dist/types/services/margin-accounts/deposit.d.ts +2 -2
  41. package/dist/types/services/margin-accounts/deposit.d.ts.map +1 -1
  42. package/dist/types/services/margin-accounts/index.d.ts +5 -0
  43. package/dist/types/services/margin-accounts/index.d.ts.map +1 -0
  44. package/dist/types/services/margin-accounts/types.d.ts +7 -7
  45. package/dist/types/services/margin-accounts/types.d.ts.map +1 -1
  46. package/dist/types/services/margin-accounts/withdraw.d.ts +2 -2
  47. package/dist/types/services/margin-accounts/withdraw.d.ts.map +1 -1
  48. package/dist/types/services/orders/index.d.ts +3 -0
  49. package/dist/types/services/orders/index.d.ts.map +1 -0
  50. package/dist/types/services/orders/order.d.ts +2 -2
  51. package/dist/types/services/orders/order.d.ts.map +1 -1
  52. package/dist/types/services/orders/types.d.ts +14 -9
  53. package/dist/types/services/orders/types.d.ts.map +1 -1
  54. package/dist/types/services/token/approve.d.ts +2 -2
  55. package/dist/types/services/token/approve.d.ts.map +1 -1
  56. package/dist/types/services/token/common.d.ts +2 -2
  57. package/dist/types/services/token/common.d.ts.map +1 -1
  58. package/dist/types/services/token/getAllowance.d.ts +2 -2
  59. package/dist/types/services/token/getAllowance.d.ts.map +1 -1
  60. package/dist/types/services/token/index.d.ts +4 -0
  61. package/dist/types/services/token/index.d.ts.map +1 -0
  62. package/dist/types/services/token/types.d.ts +6 -8
  63. package/dist/types/services/token/types.d.ts.map +1 -1
  64. package/dist/types/utils/lp.d.ts +4 -0
  65. package/dist/types/utils/lp.d.ts.map +1 -0
  66. package/dist/types/utils/trade.d.ts +3 -0
  67. package/dist/types/utils/trade.d.ts.map +1 -0
  68. package/dist/utils/lp.js +28 -0
  69. package/dist/utils/lp.js.map +1 -0
  70. package/dist/utils/trade.js +33 -0
  71. package/dist/utils/trade.js.map +1 -0
  72. package/package.json +3 -2
  73. package/src/index.ts +4 -1
  74. package/src/services/executeTransaction.ts +3 -3
  75. package/src/services/lp/index.ts +2 -0
  76. package/src/services/lp/lp.ts +49 -16
  77. package/src/services/lp/types.ts +14 -11
  78. package/src/services/margin-accounts/account.ts +2 -2
  79. package/src/services/margin-accounts/deposit.ts +2 -2
  80. package/src/services/margin-accounts/index.ts +4 -0
  81. package/src/services/margin-accounts/types.ts +7 -7
  82. package/src/services/margin-accounts/withdraw.ts +2 -2
  83. package/src/services/orders/index.ts +2 -0
  84. package/src/services/orders/order.ts +33 -11
  85. package/src/services/orders/types.ts +16 -9
  86. package/src/services/token/approve.ts +7 -4
  87. package/src/services/token/common.ts +2 -2
  88. package/src/services/token/getAllowance.ts +7 -4
  89. package/src/services/token/index.ts +3 -0
  90. package/src/services/token/types.ts +9 -11
  91. package/src/utils/lp.ts +27 -0
  92. package/src/utils/trade.ts +39 -0
@@ -1,3 +1,3 @@
1
- import { WithdrawArgs } from './types';
2
- export declare const withdraw: (params: WithdrawArgs) => Promise<unknown>;
1
+ import { WithdrawParams } from './types';
2
+ export declare const withdraw: (params: WithdrawParams) => Promise<unknown>;
3
3
  //# sourceMappingURL=withdraw.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"withdraw.d.ts","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAKvC,eAAO,MAAM,QAAQ,WAAkB,YAAY,KAAG,QAAQ,OAAO,CAmBpE,CAAC"}
1
+ {"version":3,"file":"withdraw.d.ts","sourceRoot":"/","sources":["services/margin-accounts/withdraw.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAKzC,eAAO,MAAM,QAAQ,WAAkB,cAAc,KAAG,QAAQ,OAAO,CAmBtE,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './order';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/orders/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
@@ -1,3 +1,3 @@
1
- import { MatchOrderArgs } from './types';
2
- export declare const matchOrder: (params: MatchOrderArgs) => Promise<unknown>;
1
+ import { MatchOrderParams, MatchOrderResult } from './types';
2
+ export declare const matchOrder: (params: MatchOrderParams) => Promise<MatchOrderResult>;
3
3
  //# sourceMappingURL=order.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"order.d.ts","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAKzC,eAAO,MAAM,UAAU,WAAkB,cAAc,KAAG,QAAQ,OAAO,CAoBxE,CAAC"}
1
+ {"version":3,"file":"order.d.ts","sourceRoot":"/","sources":["services/orders/order.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAS7D,eAAO,MAAM,UAAU,WACb,gBAAgB,KACvB,QAAQ,gBAAgB,CAoC1B,CAAC"}
@@ -1,12 +1,17 @@
1
- import { Signer } from 'ethers';
2
- export type MatchOrderArgs = {
3
- signer: Signer;
4
- chainId: number;
5
- accountId: number;
6
- orderBase: bigint;
7
- orderPriceLimit: bigint;
8
- counterpartyAccountIds: number[];
9
- marketId: number;
1
+ import { Signer, JsonRpcSigner } from 'ethers';
2
+ export type MarketParams = {
3
+ id: number;
10
4
  exchangeId: number;
5
+ counterpartyAccountIds: number[];
6
+ currentPrice: number;
7
+ };
8
+ export type MatchOrderParams = {
9
+ signer: Signer | JsonRpcSigner;
10
+ marginAccountId: number;
11
+ orderSize: number;
12
+ market: MarketParams;
13
+ };
14
+ export type MatchOrderResult = {
15
+ transactionHash: string | null;
11
16
  };
12
17
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/orders/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE/C,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB,EAAE,MAAM,EAAE,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,YAAY,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC,CAAC"}
@@ -1,3 +1,3 @@
1
- import { ApproveTokenArgs } from './types';
2
- export declare const approveTokenSpending: (params: ApproveTokenArgs) => Promise<number>;
1
+ import { ApproveTokenParams } from './types';
2
+ export declare const approveTokenSpending: (params: ApproveTokenParams) => Promise<number>;
3
3
  //# sourceMappingURL=approve.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"approve.d.ts","sourceRoot":"/","sources":["services/token/approve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIzD,eAAO,MAAM,oBAAoB,WACvB,gBAAgB,KACvB,QAAQ,MAAM,CA6ChB,CAAC"}
1
+ {"version":3,"file":"approve.d.ts","sourceRoot":"/","sources":["services/token/approve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAI3D,eAAO,MAAM,oBAAoB,WACvB,kBAAkB,KACzB,QAAQ,MAAM,CAgDhB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Contract, Signer } from 'ethers';
2
- import { GetERC20AllowanceArgs } from './types';
2
+ import { GetERC20AllowanceParams } from './types';
3
3
  export declare const descale: (tokenDecimals: number) => (value: bigint) => number;
4
4
  export declare const scale: (tokenDecimals: number) => (value: number) => bigint;
5
5
  export declare const getERC20TokenContract: (tokenAddress: string, subject: Signer) => Contract;
@@ -10,5 +10,5 @@ export declare const getTokenDetails: (caseSensitiveAddress: string) => {
10
10
  tokenDecimals: number;
11
11
  tokenDescaler: (value: bigint) => number;
12
12
  };
13
- export declare const getERC20Allowance: ({ walletAddress, tokenAddress, spenderAddress, subject, }: GetERC20AllowanceArgs) => Promise<number>;
13
+ export declare const getERC20Allowance: ({ walletAddress, tokenAddress, spenderAddress, subject, }: GetERC20AllowanceParams) => Promise<number>;
14
14
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"/","sources":["services/token/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEhD,eAAO,MAAM,OAAO,kBAAmB,MAAM,aACzB,MAAM,WAKzB,CAAC;AAEF,eAAO,MAAM,KAAK,kBAAmB,MAAM,aACvB,MAAM,WAOzB,CAAC;AAEF,eAAO,MAAM,qBAAqB,iBAClB,MAAM,WACX,MAAM,KACd,QAWF,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAExC,eAAO,MAAM,gBAAgB,QAAS,MAAM,KAAG,OAE9C,CAAC;AAEF,eAAO,MAAM,eAAe,yBACJ,MAAM;eAEjB,UAAU,MAAM,CAAC;mBACb,MAAM;2BACE,MAAM,KAAK,MAAM;CAezC,CAAC;AAEF,eAAO,MAAM,iBAAiB,8DAK3B,qBAAqB,KAAG,QAAQ,MAAM,CAWxC,CAAC"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"/","sources":["services/token/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAElD,eAAO,MAAM,OAAO,kBAAmB,MAAM,aACzB,MAAM,WAKzB,CAAC;AAEF,eAAO,MAAM,KAAK,kBAAmB,MAAM,aACvB,MAAM,WAOzB,CAAC;AAEF,eAAO,MAAM,qBAAqB,iBAClB,MAAM,WACX,MAAM,KACd,QAWF,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC;AAExC,eAAO,MAAM,gBAAgB,QAAS,MAAM,KAAG,OAE9C,CAAC;AAEF,eAAO,MAAM,eAAe,yBACJ,MAAM;eAEjB,UAAU,MAAM,CAAC;mBACb,MAAM;2BACE,MAAM,KAAK,MAAM;CAezC,CAAC;AAEF,eAAO,MAAM,iBAAiB,8DAK3B,uBAAuB,KAAG,QAAQ,MAAM,CAW1C,CAAC"}
@@ -1,3 +1,3 @@
1
- import { GetAllowanceArgs } from './types';
2
- export declare const getAllowance: (params: GetAllowanceArgs) => Promise<number>;
1
+ import { GetAllowanceParams } from './types';
2
+ export declare const getAllowance: (params: GetAllowanceParams) => Promise<number>;
3
3
  //# sourceMappingURL=getAllowance.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getAllowance.d.ts","sourceRoot":"/","sources":["services/token/getAllowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAIzD,eAAO,MAAM,YAAY,WACf,gBAAgB,KACvB,QAAQ,MAAM,CAiBhB,CAAC"}
1
+ {"version":3,"file":"getAllowance.d.ts","sourceRoot":"/","sources":["services/token/getAllowance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAI3D,eAAO,MAAM,YAAY,WACf,kBAAkB,KACzB,QAAQ,MAAM,CAoBhB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from './types';
2
+ export * from './approve';
3
+ export * from './getAllowance';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["services/token/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC"}
@@ -1,21 +1,19 @@
1
- import { Signer } from 'ethers';
1
+ import { JsonRpcSigner, Signer } from 'ethers';
2
2
  export declare enum ApprovalType {
3
3
  LP = 0,
4
4
  DEPOSIT = 1
5
5
  }
6
- export type ApproveTokenArgs = {
7
- signer: Signer;
8
- chainId: number;
6
+ export type ApproveTokenParams = {
7
+ signer: Signer | JsonRpcSigner;
9
8
  token: string;
10
9
  type: ApprovalType;
11
10
  };
12
- export type GetAllowanceArgs = {
13
- signer: Signer;
14
- chainId: number;
11
+ export type GetAllowanceParams = {
12
+ signer: Signer | JsonRpcSigner;
15
13
  token: string;
16
14
  type: ApprovalType;
17
15
  };
18
- export type GetERC20AllowanceArgs = {
16
+ export type GetERC20AllowanceParams = {
19
17
  walletAddress: string;
20
18
  tokenAddress: string;
21
19
  spenderAddress: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/token/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,oBAAY,YAAY;IACtB,EAAE,IAAA;IACF,OAAO,IAAA;CACR;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"/","sources":["services/token/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAE/C,oBAAY,YAAY;IACtB,EAAE,IAAA;IACF,OAAO,IAAA;CACR;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function calculateMinSharesForLp(lpAmount: number): number;
2
+ export declare function calculateMinOutForLp(sharesAmount: number): number;
3
+ export declare function expandLpAmount(amount: number): number;
4
+ //# sourceMappingURL=lp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lp.d.ts","sourceRoot":"/","sources":["utils/lp.ts"],"names":[],"mappings":"AAEA,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOhE;AAED,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAOjE;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMrD"}
@@ -0,0 +1,3 @@
1
+ export declare function calculatePriceLimitForTrade(orderPrice: number, size: number): bigint;
2
+ export declare function calculateOrderBaseFromOrderSize(orderSize: number, currentPrice: number): bigint;
3
+ //# sourceMappingURL=trade.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trade.d.ts","sourceRoot":"/","sources":["utils/trade.ts"],"names":[],"mappings":"AAEA,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GACX,MAAM,CAkBR;AAED,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,GACnB,MAAM,CAUR"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.expandLpAmount = exports.calculateMinOutForLp = exports.calculateMinSharesForLp = void 0;
7
+ var bignumber_js_1 = __importDefault(require("bignumber.js"));
8
+ function calculateMinSharesForLp(lpAmount) {
9
+ var amount = (0, bignumber_js_1.default)(lpAmount);
10
+ // Calculate 1% // @todo update this number once we have it
11
+ var offset = amount.times(0.99);
12
+ return amount.minus(offset).times(1e6).toNumber(); // rUSD/USDC has 6 decimals, change if needed
13
+ }
14
+ exports.calculateMinSharesForLp = calculateMinSharesForLp;
15
+ function calculateMinOutForLp(sharesAmount) {
16
+ var amount = (0, bignumber_js_1.default)(sharesAmount);
17
+ // Calculate 1% // @todo update once we have the exact number
18
+ var offset = amount.times(0.99);
19
+ return amount.minus(offset).times(1e6).toNumber(); // rUSD/USDC has 6 decimals, change if needed
20
+ }
21
+ exports.calculateMinOutForLp = calculateMinOutForLp;
22
+ function expandLpAmount(amount) {
23
+ var decimalFactor = (0, bignumber_js_1.default)('1000000'); // 10^6
24
+ var amountDenormalised = (0, bignumber_js_1.default)(amount).times(decimalFactor).toFixed(0);
25
+ return Number(amountDenormalised);
26
+ }
27
+ exports.expandLpAmount = expandLpAmount;
28
+ //# sourceMappingURL=lp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lp.js","sourceRoot":"/","sources":["utils/lp.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AAErC,SAAgB,uBAAuB,CAAC,QAAgB;IACtD,IAAM,MAAM,GAAG,IAAA,sBAAS,EAAC,QAAQ,CAAC,CAAC;IAEnC,2DAA2D;IAC3D,IAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,6CAA6C;AAClG,CAAC;AAPD,0DAOC;AAED,SAAgB,oBAAoB,CAAC,YAAoB;IACvD,IAAM,MAAM,GAAG,IAAA,sBAAS,EAAC,YAAY,CAAC,CAAC;IAEvC,6DAA6D;IAC7D,IAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,6CAA6C;AAClG,CAAC;AAPD,oDAOC;AAED,SAAgB,cAAc,CAAC,MAAc;IAC3C,IAAM,aAAa,GAAG,IAAA,sBAAS,EAAC,SAAS,CAAC,CAAC,CAAC,OAAO;IAEnD,IAAM,kBAAkB,GAAG,IAAA,sBAAS,EAAC,MAAM,CAAC,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAE7E,OAAO,MAAM,CAAC,kBAAkB,CAAC,CAAC;AACpC,CAAC;AAND,wCAMC","sourcesContent":["import BigNumber from 'bignumber.js';\n\nexport function calculateMinSharesForLp(lpAmount: number): number {\n const amount = BigNumber(lpAmount);\n\n // Calculate 1% // @todo update this number once we have it\n const offset = amount.times(0.99);\n\n return amount.minus(offset).times(1e6).toNumber(); // rUSD/USDC has 6 decimals, change if needed\n}\n\nexport function calculateMinOutForLp(sharesAmount: number): number {\n const amount = BigNumber(sharesAmount);\n\n // Calculate 1% // @todo update once we have the exact number\n const offset = amount.times(0.99);\n\n return amount.minus(offset).times(1e6).toNumber(); // rUSD/USDC has 6 decimals, change if needed\n}\n\nexport function expandLpAmount(amount: number): number {\n const decimalFactor = BigNumber('1000000'); // 10^6\n\n const amountDenormalised = BigNumber(amount).times(decimalFactor).toFixed(0);\n\n return Number(amountDenormalised);\n}\n"]}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.calculateOrderBaseFromOrderSize = exports.calculatePriceLimitForTrade = void 0;
7
+ var bignumber_js_1 = __importDefault(require("bignumber.js"));
8
+ function calculatePriceLimitForTrade(orderPrice, size) {
9
+ // Ensure orderPrice is BigInt
10
+ var orderPriceBigInt = (0, bignumber_js_1.default)(orderPrice);
11
+ // Calculate 50% of the order price
12
+ var offset = orderPriceBigInt.div(2);
13
+ // Determine if the size is positive or negative and adjust the price accordingly
14
+ if (size > 0) {
15
+ // Trade is long, so add
16
+ return BigInt((0, bignumber_js_1.default)(orderPriceBigInt).plus(offset).times(1e18).toFixed(0));
17
+ }
18
+ else {
19
+ return BigInt((0, bignumber_js_1.default)(orderPriceBigInt).minus(offset).times(1e18).toFixed(0));
20
+ }
21
+ }
22
+ exports.calculatePriceLimitForTrade = calculatePriceLimitForTrade;
23
+ function calculateOrderBaseFromOrderSize(orderSize, currentPrice) {
24
+ var decimalFactor = (0, bignumber_js_1.default)('1000000'); // 10^6
25
+ // @todo check decimal places handling if this should stay hardcoded to 6
26
+ var orderBase = (0, bignumber_js_1.default)(orderSize)
27
+ .times(decimalFactor)
28
+ .div(currentPrice)
29
+ .toFixed(0);
30
+ return BigInt(orderBase);
31
+ }
32
+ exports.calculateOrderBaseFromOrderSize = calculateOrderBaseFromOrderSize;
33
+ //# sourceMappingURL=trade.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"trade.js","sourceRoot":"/","sources":["utils/trade.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AAErC,SAAgB,2BAA2B,CACzC,UAAkB,EAClB,IAAY;IAEZ,8BAA8B;IAC9B,IAAM,gBAAgB,GAAG,IAAA,sBAAS,EAAC,UAAU,CAAC,CAAC;IAE/C,mCAAmC;IACnC,IAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IAEvC,iFAAiF;IACjF,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,wBAAwB;QACxB,OAAO,MAAM,CACX,IAAA,sBAAS,EAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAChE,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CACX,IAAA,sBAAS,EAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CACjE,CAAC;IACJ,CAAC;AACH,CAAC;AArBD,kEAqBC;AAED,SAAgB,+BAA+B,CAC7C,SAAiB,EACjB,YAAoB;IAEpB,IAAM,aAAa,GAAG,IAAA,sBAAS,EAAC,SAAS,CAAC,CAAC,CAAC,OAAO;IACnD,yEAAyE;IAEzE,IAAM,SAAS,GAAG,IAAA,sBAAS,EAAC,SAAS,CAAC;SACnC,KAAK,CAAC,aAAa,CAAC;SACpB,GAAG,CAAC,YAAY,CAAC;SACjB,OAAO,CAAC,CAAC,CAAC,CAAC;IAEd,OAAO,MAAM,CAAC,SAAS,CAAC,CAAC;AAC3B,CAAC;AAbD,0EAaC","sourcesContent":["import BigNumber from 'bignumber.js';\n\nexport function calculatePriceLimitForTrade(\n orderPrice: number,\n size: number,\n): bigint {\n // Ensure orderPrice is BigInt\n const orderPriceBigInt = BigNumber(orderPrice);\n\n // Calculate 50% of the order price\n const offset = orderPriceBigInt.div(2);\n\n // Determine if the size is positive or negative and adjust the price accordingly\n if (size > 0) {\n // Trade is long, so add\n return BigInt(\n BigNumber(orderPriceBigInt).plus(offset).times(1e18).toFixed(0),\n );\n } else {\n return BigInt(\n BigNumber(orderPriceBigInt).minus(offset).times(1e18).toFixed(0),\n );\n }\n}\n\nexport function calculateOrderBaseFromOrderSize(\n orderSize: number,\n currentPrice: number,\n): bigint {\n const decimalFactor = BigNumber('1000000'); // 10^6\n // @todo check decimal places handling if this should stay hardcoded to 6\n\n const orderBase = BigNumber(orderSize)\n .times(decimalFactor)\n .div(currentPrice)\n .toFixed(0);\n\n return BigInt(orderBase);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reyaxyz/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "registry": "https://registry.npmjs.org"
@@ -29,8 +29,9 @@
29
29
  "generate:coverage-badges": "npx istanbul-badges-readme --silent"
30
30
  },
31
31
  "dependencies": {
32
+ "bignumber.js": "^9.1.2",
32
33
  "ethers": "6.9.0"
33
34
  },
34
35
  "packageManager": "pnpm@8.10.4",
35
- "gitHead": "0cd4bd2ca7ec708fcf7ef2198aa7abdc4dbbc83c"
36
+ "gitHead": "9f810c7953f01af4fa09087b604e8c99007b0de0"
36
37
  }
package/src/index.ts CHANGED
@@ -1 +1,4 @@
1
- export * from './utils/action';
1
+ export * from './services/lp';
2
+ export * from './services/margin-accounts';
3
+ export * from './services/orders';
4
+ export * from './services/token';
@@ -1,4 +1,4 @@
1
- import { Signer } from 'ethers';
1
+ import { JsonRpcSigner, Signer } from 'ethers';
2
2
  import { getGasBuffer } from '../utils/txHelpers';
3
3
  import { getAddress } from '../utils/contractAddresses';
4
4
  import { TransactionType } from '../utils/consts';
@@ -11,7 +11,7 @@ export type Transaction = {
11
11
  };
12
12
 
13
13
  export async function estimateGas(
14
- signer: Signer,
14
+ signer: Signer | JsonRpcSigner,
15
15
  data: string,
16
16
  value: string,
17
17
  chainId: number,
@@ -42,7 +42,7 @@ export async function estimateGas(
42
42
  }
43
43
 
44
44
  export async function executeTransaction(
45
- signer: Signer,
45
+ signer: Signer | JsonRpcSigner,
46
46
  data: string,
47
47
  value: string,
48
48
  chainId: number,
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './lp';
@@ -3,48 +3,81 @@ import {
3
3
  encodeProvideLiquidityCall,
4
4
  encodeRemoveLiquidityCall,
5
5
  } from './encode';
6
- import { ProvideLiquidityArgs, RemoveLiquidityArgs } from './types';
6
+ import {
7
+ ProvideLiquidityParams,
8
+ ProvideLiquidityResult,
9
+ RemoveLiquidityParams,
10
+ RemoveLiquidityResult,
11
+ } from './types';
7
12
  import { TransactionType } from '../../utils/consts';
13
+ import {
14
+ calculateMinOutForLp,
15
+ calculateMinSharesForLp,
16
+ expandLpAmount,
17
+ } from '../../utils/lp';
8
18
 
9
19
  export const provideLiquidity = async (
10
- params: ProvideLiquidityArgs,
11
- ): Promise<unknown> => {
12
- // @todo update type once we agree on the structure
20
+ params: ProvideLiquidityParams,
21
+ ): Promise<ProvideLiquidityResult> => {
22
+ const ownerAddrees = await params.signer.getAddress();
23
+ // @todo we might not have chainId for reya network, update once we have information
24
+ const chainId = 80001;
25
+ const minShares = calculateMinSharesForLp(params.amount);
26
+
27
+ if (params.amount === 0) {
28
+ throw new Error('LP amount can not be 0');
29
+ }
30
+
31
+ const amount = expandLpAmount(params.amount);
32
+
13
33
  const { calldata: data, value } = encodeProvideLiquidityCall(
14
34
  params.poolId,
15
- params.owner,
16
- params.amount,
17
- params.minShares,
35
+ ownerAddrees,
36
+ amount,
37
+ minShares,
18
38
  );
19
39
 
20
40
  const result = await executeTransaction(
21
41
  params.signer,
22
42
  data,
23
43
  value,
24
- params.chainId,
44
+ chainId,
25
45
  TransactionType.LP,
26
46
  );
27
47
 
28
- return result;
48
+ return {
49
+ transactionHash: result?.hash || null,
50
+ };
29
51
  };
30
52
 
31
53
  export const removeLiquidity = async (
32
- params: RemoveLiquidityArgs,
33
- ): Promise<unknown> => {
34
- // @todo update type once we agree on the structure
54
+ params: RemoveLiquidityParams,
55
+ ): Promise<RemoveLiquidityResult> => {
56
+ // @todo we might not have chainId for reya nework, update once we have information
57
+ const chainId = 80001;
58
+
59
+ if (params.sharesAmount === 0) {
60
+ throw new Error('Shares amount can not be 0');
61
+ }
62
+
63
+ const minOut = calculateMinOutForLp(params.sharesAmount);
64
+
65
+ const amount = expandLpAmount(params.sharesAmount);
35
66
  const { calldata: data, value } = encodeRemoveLiquidityCall(
36
67
  params.poolId,
37
- params.sharesAmount,
38
- params.minOut,
68
+ amount,
69
+ minOut,
39
70
  );
40
71
 
41
72
  const result = await executeTransaction(
42
73
  params.signer,
43
74
  data,
44
75
  value,
45
- params.chainId,
76
+ chainId,
46
77
  TransactionType.LP,
47
78
  );
48
79
 
49
- return result;
80
+ return {
81
+ transactionHash: result?.hash || null,
82
+ };
50
83
  };
@@ -1,18 +1,21 @@
1
- import { Signer } from 'ethers';
1
+ import { JsonRpcSigner, Signer } from 'ethers';
2
2
 
3
- export type ProvideLiquidityArgs = {
4
- signer: Signer;
5
- chainId: number;
6
- poolId: number;
7
- owner: string;
3
+ export type ProvideLiquidityParams = {
4
+ signer: Signer | JsonRpcSigner;
8
5
  amount: number;
9
- minShares: number;
6
+ poolId: number;
10
7
  };
11
8
 
12
- export type RemoveLiquidityArgs = {
13
- signer: Signer;
14
- chainId: number;
9
+ export type RemoveLiquidityParams = {
10
+ signer: Signer | JsonRpcSigner;
15
11
  poolId: number;
16
12
  sharesAmount: number;
17
- minOut: number;
13
+ };
14
+
15
+ export type ProvideLiquidityResult = {
16
+ transactionHash: string | null;
17
+ };
18
+
19
+ export type RemoveLiquidityResult = {
20
+ transactionHash: string | null;
18
21
  };
@@ -1,10 +1,10 @@
1
1
  import { executeTransaction } from '../executeTransaction';
2
2
  import { encodeCreateAccountCall } from './encode';
3
- import { CreateAccountArgs } from './types';
3
+ import { CreateAccountParams } from './types';
4
4
  import { TransactionType } from '../../utils/consts';
5
5
 
6
6
  export const createAccount = async (
7
- params: CreateAccountArgs,
7
+ params: CreateAccountParams,
8
8
  ): Promise<unknown> => {
9
9
  // @todo update type once we agree on the structure
10
10
  const { calldata: data, value } = encodeCreateAccountCall(
@@ -1,9 +1,9 @@
1
- import { DepositArgs } from './types';
1
+ import { DepositParams } from './types';
2
2
  import { encodeDeposit } from './encode';
3
3
  import { executeTransaction } from '../executeTransaction';
4
4
  import { TransactionType } from '../../utils/consts';
5
5
 
6
- export const deposit = async (params: DepositArgs): Promise<unknown> => {
6
+ export const deposit = async (params: DepositParams): Promise<unknown> => {
7
7
  // @todo update type once we agree on the structure
8
8
  const { calldata: data, value } = encodeDeposit(
9
9
  params.accountId,
@@ -0,0 +1,4 @@
1
+ export * from './types';
2
+ export * from './account';
3
+ export * from './deposit';
4
+ export * from './withdraw';
@@ -1,13 +1,13 @@
1
- import { Signer } from 'ethers';
1
+ import { JsonRpcSigner, Signer } from 'ethers';
2
2
 
3
- export type CreateAccountArgs = {
4
- signer: Signer;
3
+ export type CreateAccountParams = {
4
+ signer: Signer | JsonRpcSigner;
5
5
  chainId: number;
6
6
  ownerAddress: string;
7
7
  };
8
8
 
9
- export type DepositArgs = {
10
- signer: Signer;
9
+ export type DepositParams = {
10
+ signer: Signer | JsonRpcSigner;
11
11
  chainId: number;
12
12
  accountId: number;
13
13
  token: string;
@@ -16,8 +16,8 @@ export type DepositArgs = {
16
16
  exchangeId: number;
17
17
  };
18
18
 
19
- export type WithdrawArgs = {
20
- signer: Signer;
19
+ export type WithdrawParams = {
20
+ signer: Signer | JsonRpcSigner;
21
21
  chainId: number;
22
22
  accountId: number;
23
23
  token: string;
@@ -1,9 +1,9 @@
1
- import { WithdrawArgs } from './types';
1
+ import { WithdrawParams } from './types';
2
2
  import { encodeWithdraw } from './encode';
3
3
  import { executeTransaction } from '../executeTransaction';
4
4
  import { TransactionType } from '../../utils/consts';
5
5
 
6
- export const withdraw = async (params: WithdrawArgs): Promise<unknown> => {
6
+ export const withdraw = async (params: WithdrawParams): Promise<unknown> => {
7
7
  // @todo update type once we agree on the structure
8
8
  const { calldata: data, value } = encodeWithdraw(
9
9
  params.accountId,
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './order';
@@ -1,26 +1,48 @@
1
- import { MatchOrderArgs } from './types';
1
+ import { MatchOrderParams, MatchOrderResult } from './types';
2
2
  import { encodeMatchOrder } from './encode';
3
3
  import { executeTransaction } from '../executeTransaction';
4
4
  import { TransactionType } from '../../utils/consts';
5
+ import {
6
+ calculateOrderBaseFromOrderSize,
7
+ calculatePriceLimitForTrade,
8
+ } from '../../utils/trade';
9
+
10
+ export const matchOrder = async (
11
+ params: MatchOrderParams,
12
+ ): Promise<MatchOrderResult> => {
13
+ if (params.orderSize === 0) {
14
+ throw new Error('Position size can not be 0');
15
+ }
16
+ const orderPriceLimit = calculatePriceLimitForTrade(
17
+ params.market.currentPrice,
18
+ params.orderSize,
19
+ );
20
+
21
+ const orderBase = calculateOrderBaseFromOrderSize(
22
+ params.orderSize,
23
+ params.market.currentPrice,
24
+ );
5
25
 
6
- export const matchOrder = async (params: MatchOrderArgs): Promise<unknown> => {
7
- // @todo update type once we agree on the structure
8
26
  const { calldata: data, value } = encodeMatchOrder(
9
- params.accountId,
10
- params.orderBase,
11
- params.orderPriceLimit,
12
- params.counterpartyAccountIds,
13
- params.marketId,
14
- params.exchangeId,
27
+ params.marginAccountId,
28
+ orderBase,
29
+ orderPriceLimit,
30
+ params.market.counterpartyAccountIds,
31
+ params.market.id,
32
+ params.market.exchangeId,
15
33
  );
16
34
 
35
+ // @todo update it
36
+ const chainId = 80001;
17
37
  const result = await executeTransaction(
18
38
  params.signer,
19
39
  data,
20
40
  value,
21
- params.chainId,
41
+ chainId,
22
42
  TransactionType.TRADE,
23
43
  );
24
44
 
25
- return result;
45
+ return {
46
+ transactionHash: result?.hash || null,
47
+ };
26
48
  };
@@ -1,12 +1,19 @@
1
- import { Signer } from 'ethers';
1
+ import { Signer, JsonRpcSigner } from 'ethers';
2
2
 
3
- export type MatchOrderArgs = {
4
- signer: Signer;
5
- chainId: number;
6
- accountId: number;
7
- orderBase: bigint;
8
- orderPriceLimit: bigint;
9
- counterpartyAccountIds: number[];
10
- marketId: number;
3
+ export type MarketParams = {
4
+ id: number;
11
5
  exchangeId: number;
6
+ counterpartyAccountIds: number[];
7
+ currentPrice: number;
8
+ };
9
+
10
+ export type MatchOrderParams = {
11
+ signer: Signer | JsonRpcSigner;
12
+ marginAccountId: number;
13
+ orderSize: number;
14
+ market: MarketParams;
15
+ };
16
+
17
+ export type MatchOrderResult = {
18
+ transactionHash: string | null;
12
19
  };