zo-sdk 0.1.1 → 0.1.3

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 (183) hide show
  1. package/dist/abstract/BaseAPI.cjs +3 -4
  2. package/dist/abstract/BaseAPI.cjs.map +1 -1
  3. package/dist/abstract/BaseAPI.d.cts +13 -13
  4. package/dist/abstract/BaseAPI.d.cts.map +1 -1
  5. package/dist/abstract/BaseAPI.d.mts +13 -13
  6. package/dist/abstract/BaseAPI.d.mts.map +1 -1
  7. package/dist/abstract/BaseAPI.mjs +3 -4
  8. package/dist/abstract/BaseAPI.mjs.map +1 -1
  9. package/dist/abstract/BaseDataAPI.cjs +2 -2
  10. package/dist/abstract/BaseDataAPI.cjs.map +1 -1
  11. package/dist/abstract/BaseDataAPI.d.cts +2 -2
  12. package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
  13. package/dist/abstract/BaseDataAPI.d.mts +2 -2
  14. package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
  15. package/dist/abstract/BaseDataAPI.mjs +2 -2
  16. package/dist/abstract/BaseDataAPI.mjs.map +1 -1
  17. package/dist/abstract/index.cjs +3 -3
  18. package/dist/abstract/index.cjs.map +1 -1
  19. package/dist/abstract/index.d.cts +1 -1
  20. package/dist/abstract/index.d.cts.map +1 -1
  21. package/dist/abstract/index.d.mts +1 -1
  22. package/dist/abstract/index.d.mts.map +1 -1
  23. package/dist/abstract/index.mjs +1 -1
  24. package/dist/abstract/index.mjs.map +1 -1
  25. package/dist/api.cjs +2 -1
  26. package/dist/api.cjs.map +1 -1
  27. package/dist/api.d.cts.map +1 -1
  28. package/dist/api.d.mts.map +1 -1
  29. package/dist/api.mjs +2 -1
  30. package/dist/api.mjs.map +1 -1
  31. package/dist/bcs.cjs.map +1 -1
  32. package/dist/bcs.d.cts.map +1 -1
  33. package/dist/bcs.d.mts.map +1 -1
  34. package/dist/bcs.mjs.map +1 -1
  35. package/dist/consts/deployments-slp-mainnet.json +0 -70
  36. package/dist/consts/deployments-usdz-mainnet.json +1 -133
  37. package/dist/consts/index.cjs +21 -14
  38. package/dist/consts/index.cjs.map +1 -1
  39. package/dist/consts/index.d.cts.map +1 -1
  40. package/dist/consts/index.d.mts.map +1 -1
  41. package/dist/consts/index.mjs +21 -14
  42. package/dist/consts/index.mjs.map +1 -1
  43. package/dist/factory/SDKFactory.cjs +21 -14
  44. package/dist/factory/SDKFactory.cjs.map +1 -1
  45. package/dist/factory/SDKFactory.d.cts +4 -4
  46. package/dist/factory/SDKFactory.d.cts.map +1 -1
  47. package/dist/factory/SDKFactory.d.mts +4 -4
  48. package/dist/factory/SDKFactory.d.mts.map +1 -1
  49. package/dist/factory/SDKFactory.mjs +22 -15
  50. package/dist/factory/SDKFactory.mjs.map +1 -1
  51. package/dist/implementations/SLPAPI.cjs +143 -110
  52. package/dist/implementations/SLPAPI.cjs.map +1 -1
  53. package/dist/implementations/SLPAPI.d.cts +49 -47
  54. package/dist/implementations/SLPAPI.d.cts.map +1 -1
  55. package/dist/implementations/SLPAPI.d.mts +49 -47
  56. package/dist/implementations/SLPAPI.d.mts.map +1 -1
  57. package/dist/implementations/SLPAPI.mjs +143 -110
  58. package/dist/implementations/SLPAPI.mjs.map +1 -1
  59. package/dist/implementations/SLPDataAPI.cjs +98 -89
  60. package/dist/implementations/SLPDataAPI.cjs.map +1 -1
  61. package/dist/implementations/SLPDataAPI.d.cts +21 -21
  62. package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
  63. package/dist/implementations/SLPDataAPI.d.mts +21 -21
  64. package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
  65. package/dist/implementations/SLPDataAPI.mjs +98 -89
  66. package/dist/implementations/SLPDataAPI.mjs.map +1 -1
  67. package/dist/implementations/USDZAPI.cjs +129 -85
  68. package/dist/implementations/USDZAPI.cjs.map +1 -1
  69. package/dist/implementations/USDZAPI.d.cts +46 -45
  70. package/dist/implementations/USDZAPI.d.cts.map +1 -1
  71. package/dist/implementations/USDZAPI.d.mts +46 -45
  72. package/dist/implementations/USDZAPI.d.mts.map +1 -1
  73. package/dist/implementations/USDZAPI.mjs +129 -85
  74. package/dist/implementations/USDZAPI.mjs.map +1 -1
  75. package/dist/implementations/USDZDataAPI.cjs +48 -47
  76. package/dist/implementations/USDZDataAPI.cjs.map +1 -1
  77. package/dist/implementations/USDZDataAPI.d.cts +19 -19
  78. package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
  79. package/dist/implementations/USDZDataAPI.d.mts +19 -19
  80. package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
  81. package/dist/implementations/USDZDataAPI.mjs +49 -48
  82. package/dist/implementations/USDZDataAPI.mjs.map +1 -1
  83. package/dist/implementations/ZLPAPI.cjs +137 -89
  84. package/dist/implementations/ZLPAPI.cjs.map +1 -1
  85. package/dist/implementations/ZLPAPI.d.cts +50 -48
  86. package/dist/implementations/ZLPAPI.d.cts.map +1 -1
  87. package/dist/implementations/ZLPAPI.d.mts +50 -48
  88. package/dist/implementations/ZLPAPI.d.mts.map +1 -1
  89. package/dist/implementations/ZLPAPI.mjs +137 -89
  90. package/dist/implementations/ZLPAPI.mjs.map +1 -1
  91. package/dist/implementations/ZLPDataAPI.cjs +62 -63
  92. package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
  93. package/dist/implementations/ZLPDataAPI.d.cts +19 -19
  94. package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
  95. package/dist/implementations/ZLPDataAPI.d.mts +19 -19
  96. package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
  97. package/dist/implementations/ZLPDataAPI.mjs +63 -64
  98. package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
  99. package/dist/implementations/index.cjs +5 -5
  100. package/dist/implementations/index.cjs.map +1 -1
  101. package/dist/implementations/index.d.cts +2 -2
  102. package/dist/implementations/index.d.cts.map +1 -1
  103. package/dist/implementations/index.d.mts +2 -2
  104. package/dist/implementations/index.d.mts.map +1 -1
  105. package/dist/implementations/index.mjs +2 -2
  106. package/dist/implementations/index.mjs.map +1 -1
  107. package/dist/index.cjs +9 -9
  108. package/dist/index.cjs.map +1 -1
  109. package/dist/index.d.cts +6 -6
  110. package/dist/index.d.cts.map +1 -1
  111. package/dist/index.d.mts +6 -6
  112. package/dist/index.d.mts.map +1 -1
  113. package/dist/index.mjs +6 -6
  114. package/dist/index.mjs.map +1 -1
  115. package/dist/interfaces/base.cjs +0 -1
  116. package/dist/interfaces/base.cjs.map +1 -1
  117. package/dist/interfaces/base.d.cts +57 -57
  118. package/dist/interfaces/base.d.cts.map +1 -1
  119. package/dist/interfaces/base.d.mts +57 -57
  120. package/dist/interfaces/base.d.mts.map +1 -1
  121. package/dist/interfaces/base.mjs +1 -1
  122. package/dist/interfaces/base.mjs.map +1 -1
  123. package/dist/interfaces/index.d.cts +4 -4
  124. package/dist/interfaces/index.d.cts.map +1 -1
  125. package/dist/interfaces/index.d.mts +4 -4
  126. package/dist/interfaces/index.d.mts.map +1 -1
  127. package/dist/interfaces/slp.cjs +0 -2
  128. package/dist/interfaces/slp.cjs.map +1 -1
  129. package/dist/interfaces/slp.d.cts +5 -5
  130. package/dist/interfaces/slp.d.cts.map +1 -1
  131. package/dist/interfaces/slp.d.mts +5 -5
  132. package/dist/interfaces/slp.d.mts.map +1 -1
  133. package/dist/interfaces/slp.mjs +1 -2
  134. package/dist/interfaces/slp.mjs.map +1 -1
  135. package/dist/interfaces/usdz.d.cts +1 -1
  136. package/dist/interfaces/usdz.d.cts.map +1 -1
  137. package/dist/interfaces/usdz.d.mts +1 -1
  138. package/dist/interfaces/usdz.d.mts.map +1 -1
  139. package/dist/interfaces/zlp.d.cts +5 -5
  140. package/dist/interfaces/zlp.d.cts.map +1 -1
  141. package/dist/interfaces/zlp.d.mts +5 -5
  142. package/dist/interfaces/zlp.d.mts.map +1 -1
  143. package/dist/oracle.cjs +12 -2
  144. package/dist/oracle.cjs.map +1 -1
  145. package/dist/oracle.d.cts +4 -3
  146. package/dist/oracle.d.cts.map +1 -1
  147. package/dist/oracle.d.mts +4 -3
  148. package/dist/oracle.d.mts.map +1 -1
  149. package/dist/oracle.mjs +13 -3
  150. package/dist/oracle.mjs.map +1 -1
  151. package/dist/utils.cjs +1 -1
  152. package/dist/utils.cjs.map +1 -1
  153. package/dist/utils.d.cts.map +1 -1
  154. package/dist/utils.d.mts.map +1 -1
  155. package/dist/utils.mjs +1 -1
  156. package/dist/utils.mjs.map +1 -1
  157. package/eslint.config.mjs +18 -0
  158. package/package.json +16 -15
  159. package/src/abstract/BaseAPI.ts +55 -49
  160. package/src/abstract/BaseDataAPI.ts +19 -17
  161. package/src/abstract/index.ts +1 -1
  162. package/src/api.ts +3 -1
  163. package/src/bcs.ts +9 -9
  164. package/src/consts/deployments-slp-mainnet.json +0 -70
  165. package/src/consts/deployments-usdz-mainnet.json +2 -134
  166. package/src/consts/index.ts +22 -15
  167. package/src/factory/SDKFactory.ts +49 -41
  168. package/src/implementations/SLPAPI.ts +299 -210
  169. package/src/implementations/SLPDataAPI.ts +163 -146
  170. package/src/implementations/USDZAPI.ts +239 -134
  171. package/src/implementations/USDZDataAPI.ts +79 -74
  172. package/src/implementations/ZLPAPI.ts +296 -174
  173. package/src/implementations/ZLPDataAPI.ts +94 -89
  174. package/src/implementations/index.ts +3 -3
  175. package/src/index.ts +17 -17
  176. package/src/interfaces/base.ts +123 -116
  177. package/src/interfaces/index.ts +14 -17
  178. package/src/interfaces/slp.ts +20 -19
  179. package/src/interfaces/usdz.ts +13 -13
  180. package/src/interfaces/zlp.ts +22 -21
  181. package/src/oracle.ts +25 -5
  182. package/src/utils.ts +9 -9
  183. package/tsconfig.json +1 -1
@@ -5,101 +5,130 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SLPAPI = void 0;
8
+ const kiosk_1 = require("@mysten/kiosk");
8
9
  const transactions_1 = require("@mysten/sui/transactions");
9
10
  const utils_1 = require("@mysten/sui/utils");
10
- const consts_1 = require("../consts/index.cjs");
11
11
  const abstract_1 = require("../abstract/index.cjs");
12
- const SLPDataAPI_1 = require("./SLPDataAPI.cjs");
12
+ const consts_1 = require("../consts/index.cjs");
13
13
  const utils_2 = require("../utils.cjs");
14
- const kiosk_1 = require("@mysten/kiosk");
14
+ const SLPDataAPI_1 = require("./SLPDataAPI.cjs");
15
15
  class SLPAPI extends abstract_1.BaseAPI {
16
16
  constructor(network, provider, apiEndpoint, connectionURL) {
17
17
  super(network, provider, apiEndpoint, connectionURL, consts_1.LPToken.SLP);
18
18
  this.dataAPI = new SLPDataAPI_1.SLPDataAPI(network, provider, apiEndpoint, connectionURL);
19
19
  }
20
- valuateVaults(tx) {
21
- throw new Error('Method not implemented.');
20
+ valuateVaults(_tx) {
21
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
22
22
  }
23
- valuateSymbols(tx) {
24
- throw new Error('Method not implemented.');
23
+ valuateSymbols(_tx) {
24
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
25
25
  }
26
- valuate(tx) {
27
- throw new Error('Method not implemented.');
26
+ valuate(_tx) {
27
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
28
28
  }
29
29
  valuateMarket() {
30
- throw new Error('Method not implemented.');
30
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
31
31
  }
32
- fundingFeeRate(indexToken, long, sender) {
33
- throw new Error('Method not implemented.');
32
+ fundingFeeRate(_indexToken, _long, _sender) {
33
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
34
34
  }
35
- rebaseFeeRate(collateralToken, increase, amount, sender) {
36
- throw new Error('Method not implemented.');
35
+ rebaseFeeRate(_collateralToken, _increase, _amount, _sender) {
36
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
37
37
  }
38
- reservingFeeRate(collateralToken, amount, sender) {
39
- throw new Error('Method not implemented.');
38
+ reservingFeeRate(_collateralToken, _amount, _sender) {
39
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
40
40
  }
41
- calcPositionReserveFeeAmount(position) {
42
- throw new Error('Method not implemented.');
41
+ calcPositionReserveFeeAmount(_position) {
42
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
43
43
  }
44
- calcPositionFundingFeeValue(position) {
45
- throw new Error('Method not implemented.');
44
+ calcPositionFundingFeeValue(_position) {
45
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
46
46
  }
47
47
  getMarketInfo() {
48
- throw new Error('Method not implemented.');
48
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
49
49
  }
50
- getVaultInfo(vault) {
51
- throw new Error('Method not implemented.');
50
+ getVaultInfo(_vault) {
51
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
52
52
  }
53
- getSymbolInfo(tokenId, long) {
54
- throw new Error('Method not implemented.');
53
+ getSymbolInfo(_tokenId, _long) {
54
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
55
55
  }
56
- getPositionConfig(indexToken, long) {
57
- throw new Error('Method not implemented.');
56
+ getPositionConfig(_indexToken, _long) {
57
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
58
58
  }
59
59
  getRebaseFeeModel() {
60
- throw new Error('Method not implemented.');
60
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
61
61
  }
62
62
  getOpenPositions() {
63
- throw new Error('Method not implemented.');
63
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
64
64
  }
65
- getPositionCapInfoList(owner) {
66
- throw new Error('Method not implemented.');
65
+ getPositionCapInfoList(_owner) {
66
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
67
67
  }
68
- getPositionInfoList(positionCapInfoList, owner) {
69
- throw new Error('Method not implemented.');
68
+ getPositionInfoList(_positionCapInfoList, _owner) {
69
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
70
70
  }
71
- getOrderCapInfoList(owner) {
72
- throw new Error('Method not implemented.');
71
+ getOrderCapInfoList(_owner) {
72
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
73
73
  }
74
- getOrderInfoList(orderCapInfoList, owner) {
75
- throw new Error('Method not implemented.');
74
+ getOrderInfoList(_orderCapInfoList, _owner) {
75
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
76
76
  }
77
- getHistory(trader, page, limit, orderType, symbol) {
78
- throw new Error('Method not implemented.');
77
+ getHistory(_trader, _page, _limit, _orderType, _symbol) {
78
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
79
79
  }
80
- getStaked(owner) {
81
- throw new Error('Method not implemented.');
80
+ getStaked(_owner) {
81
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
82
82
  }
83
83
  getStakePool() {
84
- throw new Error('Method not implemented.');
84
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
85
85
  }
86
- hasReferral(referree) {
87
- throw new Error('Method not implemented.');
86
+ hasReferral(_referree) {
87
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
88
88
  }
89
- getReferralData(referree) {
90
- throw new Error('Method not implemented.');
89
+ getReferralData(_referree) {
90
+ throw new Error(`Method not implemented in ${this.constructor.name}.`);
91
91
  }
92
92
  /**
93
93
  * Deposits collateral into SLP vault using Sudo SDK approach
94
94
  */
95
- async deposit(coin, coinObjects, amount, minAmountOut, referralAddress, sender) {
95
+ async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx, suiCoinObjectsForPythUpdate, isDepositingSui) {
96
96
  let tx = new transactions_1.Transaction();
97
+ // Add referral if needed
97
98
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
98
99
  tx = await this.addReferral(referralAddress, tx);
99
100
  }
100
- tx = await this.initOracleTxb(Object.keys(this.consts.pythFeeder.feeder));
101
- const coinObject = this.processCoins(tx, coin, coinObjects);
102
- const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
101
+ // Initialize oracle transaction
102
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
103
+ // Handle sponsored transaction case
104
+ if (sponsoredTx) {
105
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
106
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
107
+ // Process deposit coins
108
+ const depositObject = isDepositingSui
109
+ ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
110
+ : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0];
111
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
112
+ tx.moveCall({
113
+ target: `${this.consts.sudoCore.upgradedPackage}::market::deposit`,
114
+ typeArguments: [
115
+ `${this.consts.sudoCore.package}::slp::SLP`,
116
+ this.consts.coins[coin].module,
117
+ ],
118
+ arguments: [
119
+ tx.object(this.consts.sudoCore.market),
120
+ tx.object(this.consts.sudoCore.rebaseFeeModel),
121
+ depositObject,
122
+ tx.pure.u64(minAmountOut),
123
+ vaultsValuation,
124
+ symbolsValuation,
125
+ ],
126
+ });
127
+ return tx;
128
+ }
129
+ // Handle non-sponsored transaction case
130
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
131
+ const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
103
132
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
104
133
  tx.moveCall({
105
134
  target: `${this.consts.sudoCore.upgradedPackage}::market::deposit`,
@@ -111,7 +140,7 @@ class SLPAPI extends abstract_1.BaseAPI {
111
140
  tx.object(this.consts.sudoCore.market),
112
141
  tx.object(this.consts.sudoCore.rebaseFeeModel),
113
142
  depositObject,
114
- tx.pure.u64(minAmountOut || 0),
143
+ tx.pure.u64(minAmountOut),
115
144
  vaultsValuation,
116
145
  symbolsValuation,
117
146
  ],
@@ -121,10 +150,19 @@ class SLPAPI extends abstract_1.BaseAPI {
121
150
  /**
122
151
  * Withdraws collateral from SLP vault using Sudo SDK approach
123
152
  */
124
- async withdraw(coin, lpCoinObjects, amount, minAmountOut) {
125
- const tx = await this.initOracleTxb(Object.keys(this.consts.pythFeeder.feeder));
126
- const lpCoinObject = this.processCoins(tx, `${this.consts.sudoCore.package}::slp::SLP`, lpCoinObjects);
127
- const [withdrawObject] = tx.splitCoins(lpCoinObject, [tx.pure.u64(amount)]);
153
+ async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, suiCoinObjectsForPythUpdate) {
154
+ let tx = new transactions_1.Transaction();
155
+ // Initialize oracle transaction
156
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
157
+ if (sponsoredTx) {
158
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true);
159
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject);
160
+ }
161
+ else {
162
+ tx = await this.initOracleTxb(pythFeederKeys, tx);
163
+ }
164
+ const slpCoinObject = this.processCoins(tx, 'slp', lpCoinObjects, false);
165
+ const [withdrawObject] = tx.splitCoins(slpCoinObject, [tx.pure.u64(amount)]);
128
166
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
129
167
  tx.moveCall({
130
168
  target: `${this.consts.sudoCore.upgradedPackage}::market::withdraw`,
@@ -136,7 +174,7 @@ class SLPAPI extends abstract_1.BaseAPI {
136
174
  tx.object(this.consts.sudoCore.market),
137
175
  tx.object(this.consts.sudoCore.rebaseFeeModel),
138
176
  withdrawObject,
139
- tx.pure.u64(minAmountOut || 0),
177
+ tx.pure.u64(minAmountOut),
140
178
  vaultsValuation,
141
179
  symbolsValuation,
142
180
  ],
@@ -170,7 +208,7 @@ class SLPAPI extends abstract_1.BaseAPI {
170
208
  /**
171
209
  * Stakes SLP tokens in Sudo staking pools
172
210
  */
173
- async stake(lpCoinObjects, amount, pool) {
211
+ stake(lpCoinObjects, amount, pool) {
174
212
  if (!this.consts.sudoStaking) {
175
213
  throw new Error('Sudo staking configuration not found');
176
214
  }
@@ -194,14 +232,16 @@ class SLPAPI extends abstract_1.BaseAPI {
194
232
  /**
195
233
  * Unstakes SLP tokens from Sudo staking pools
196
234
  */
197
- async unstake(credentials, amount, pool) {
235
+ unstake(credentials, amount, pool) {
198
236
  if (!this.consts.sudoStaking) {
199
237
  throw new Error('Sudo staking configuration not found');
200
238
  }
201
239
  const tx = new transactions_1.Transaction();
202
240
  for (const credential of credentials) {
203
- // eslint-disable-next-line unicorn/prefer-math-min-max
204
- const withdrawAmount = amount < credential.amount ? amount : credential.amount;
241
+ const withdrawAmount = (() => {
242
+ const min = (a, b) => a < b ? a : b;
243
+ return min(amount, credential.amount);
244
+ })();
205
245
  amount -= withdrawAmount;
206
246
  tx.moveCall({
207
247
  target: `${this.consts.sudoStaking.package}::pool::withdraw`,
@@ -257,7 +297,7 @@ class SLPAPI extends abstract_1.BaseAPI {
257
297
  this.consts.coins[collateralToken].module,
258
298
  this.consts.coins[indexToken].module,
259
299
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
260
- this.consts.coins['sui'].module,
300
+ this.consts.coins.sui.module,
261
301
  ],
262
302
  arguments: [
263
303
  tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
@@ -282,7 +322,7 @@ class SLPAPI extends abstract_1.BaseAPI {
282
322
  /**
283
323
  * Decreases an existing position in SLP using Sudo SDK approach
284
324
  */
285
- async decreasePosition(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects) {
325
+ async decreasePosition(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5)) {
286
326
  const tx = await this.initOracleTxb([collateralToken, indexToken]);
287
327
  const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
288
328
  const feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
@@ -290,12 +330,7 @@ class SLPAPI extends abstract_1.BaseAPI {
290
330
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
291
331
  let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
292
332
  if (isTriggerOrder) {
293
- if (isIocOrder || !isTakeProfitOrder) {
294
- allowTrade = consts_1.ALLOW_TRADE_NO_TRADE;
295
- }
296
- else {
297
- allowTrade = consts_1.ALLOW_TRADE_CAN_TRADE;
298
- }
333
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
299
334
  }
300
335
  else {
301
336
  isTakeProfitOrder = true;
@@ -307,7 +342,7 @@ class SLPAPI extends abstract_1.BaseAPI {
307
342
  this.consts.coins[collateralToken].module,
308
343
  this.consts.coins[indexToken].module,
309
344
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
310
- this.consts.coins['sui'].module,
345
+ this.consts.coins.sui.module,
311
346
  ],
312
347
  arguments: [
313
348
  tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
@@ -332,15 +367,15 @@ class SLPAPI extends abstract_1.BaseAPI {
332
367
  if (!tx) {
333
368
  tx = new transactions_1.Transaction();
334
369
  }
335
- tx = await this.initOracleTxb(positions.map(position => [position.collateralToken, position.indexToken]).flat(), tx);
370
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
336
371
  for (const position of positions) {
337
- const { pcpId, collateralToken, coinObjects, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder, isTakeProfitOrder, isIocOrder, slippage, relayerFee } = position;
372
+ const { pcpId, collateralToken, coinObjects = [], indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), } = position;
338
373
  let innerIsTakeProfitOrder = isTakeProfitOrder;
339
374
  const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
340
375
  const coinObject = this.processCoins(tx, collateralToken, coinObjects);
341
376
  const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)]);
342
- const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : slippage);
343
- const adjustCollateralPrice = this.processSlippage(collateralPrice, false, 0.5);
377
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
378
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
344
379
  let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
345
380
  if (isTriggerOrder) {
346
381
  allowTrade = isIocOrder || !innerIsTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
@@ -355,7 +390,7 @@ class SLPAPI extends abstract_1.BaseAPI {
355
390
  this.consts.coins[collateralToken].module,
356
391
  this.consts.coins[indexToken].module,
357
392
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
358
- this.consts.coins['sui'].module,
393
+ this.consts.coins.sui.module,
359
394
  ],
360
395
  arguments: [
361
396
  tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
@@ -421,18 +456,21 @@ class SLPAPI extends abstract_1.BaseAPI {
421
456
  });
422
457
  return tx;
423
458
  }
424
- async cancelOrder(orderCapId, collateralToken, indexToken, long, type, isV11Order) {
459
+ cancelOrder(orderCapId, collateralToken, indexToken, long, type) {
425
460
  const tx = new transactions_1.Transaction();
426
461
  let functionName = '';
427
462
  switch (type) {
428
- case 'OPEN_POSITION':
463
+ case 'OPEN_POSITION': {
429
464
  functionName = 'clear_open_position_order_v1_1';
430
465
  break;
431
- case 'DECREASE_POSITION':
466
+ }
467
+ case 'DECREASE_POSITION': {
432
468
  functionName = 'clear_decrease_position_order_v1_1';
433
469
  break;
434
- default:
470
+ }
471
+ default: {
435
472
  throw new Error('invalid order type');
473
+ }
436
474
  }
437
475
  tx.moveCall({
438
476
  target: `${this.consts.sudoCore.upgradedPackage}::market::${functionName}`,
@@ -441,7 +479,7 @@ class SLPAPI extends abstract_1.BaseAPI {
441
479
  this.consts.coins[collateralToken].module,
442
480
  this.consts.coins[indexToken].module,
443
481
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
444
- this.consts.coins['sui'].module,
482
+ this.consts.coins.sui.module,
445
483
  ],
446
484
  arguments: [
447
485
  tx.object(this.consts.sudoCore.market),
@@ -450,7 +488,7 @@ class SLPAPI extends abstract_1.BaseAPI {
450
488
  });
451
489
  return tx;
452
490
  }
453
- async cancelMultiOrders(orders, tx) {
491
+ cancelMultiOrders(orders, tx) {
454
492
  if (!tx) {
455
493
  tx = new transactions_1.Transaction();
456
494
  }
@@ -498,7 +536,7 @@ class SLPAPI extends abstract_1.BaseAPI {
498
536
  arguments: [tx.object(this.consts.sudoCore.market), tx.object(pcpId)],
499
537
  });
500
538
  }
501
- clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx, isV11Order) {
539
+ clearOpenPositionOrder(orderCapId, collateralToken, indexToken, long, tx) {
502
540
  tx.moveCall({
503
541
  target: `${this.consts.sudoCore.upgradedPackage}::market::clear_open_position_order_v1_1`,
504
542
  typeArguments: [
@@ -506,7 +544,7 @@ class SLPAPI extends abstract_1.BaseAPI {
506
544
  this.consts.coins[collateralToken].module,
507
545
  this.consts.coins[indexToken].module,
508
546
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
509
- this.consts.coins['sui'].module,
547
+ this.consts.coins.sui.module,
510
548
  ],
511
549
  arguments: [
512
550
  tx.object(this.consts.sudoCore.market),
@@ -522,7 +560,7 @@ class SLPAPI extends abstract_1.BaseAPI {
522
560
  this.consts.coins[collateralToken].module,
523
561
  this.consts.coins[indexToken].module,
524
562
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
525
- this.consts.coins['sui'].module,
563
+ this.consts.coins.sui.module,
526
564
  ],
527
565
  arguments: [
528
566
  tx.object(this.consts.sudoCore.market),
@@ -564,7 +602,7 @@ class SLPAPI extends abstract_1.BaseAPI {
564
602
  this.consts.coins[collateralToken].module,
565
603
  this.consts.coins[indexToken].module,
566
604
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
567
- this.consts.coins['sui'].module,
605
+ this.consts.coins.sui.module,
568
606
  ],
569
607
  arguments: [
570
608
  tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
@@ -589,12 +627,12 @@ class SLPAPI extends abstract_1.BaseAPI {
589
627
  .return({
590
628
  itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
591
629
  item: sudoCard,
592
- promise: promise,
630
+ promise,
593
631
  })
594
632
  .finalize();
595
633
  return tx;
596
634
  }
597
- async decreasePositionWithSCard(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects) {
635
+ async decreasePositionWithSCard(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5)) {
598
636
  const tx = await this.initOracleTxb([collateralToken, indexToken]);
599
637
  const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
600
638
  const feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee)]); // Sudo contract requires SUI as fee
@@ -602,12 +640,7 @@ class SLPAPI extends abstract_1.BaseAPI {
602
640
  const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
603
641
  let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
604
642
  if (isTriggerOrder) {
605
- if (isIocOrder || !isTakeProfitOrder) {
606
- allowTrade = consts_1.ALLOW_TRADE_NO_TRADE;
607
- }
608
- else {
609
- allowTrade = consts_1.ALLOW_TRADE_CAN_TRADE;
610
- }
643
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
611
644
  }
612
645
  else {
613
646
  isTakeProfitOrder = true;
@@ -628,7 +661,7 @@ class SLPAPI extends abstract_1.BaseAPI {
628
661
  this.consts.coins[collateralToken].module,
629
662
  this.consts.coins[indexToken].module,
630
663
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
631
- this.consts.coins['sui'].module,
664
+ this.consts.coins.sui.module,
632
665
  ],
633
666
  arguments: [
634
667
  tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
@@ -652,7 +685,7 @@ class SLPAPI extends abstract_1.BaseAPI {
652
685
  .return({
653
686
  itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
654
687
  item: sudoCard,
655
- promise: promise,
688
+ promise,
656
689
  })
657
690
  .finalize();
658
691
  return tx;
@@ -661,7 +694,7 @@ class SLPAPI extends abstract_1.BaseAPI {
661
694
  if (!tx) {
662
695
  tx = new transactions_1.Transaction();
663
696
  }
664
- tx = await this.initOracleTxb(positions.map(position => [position.collateralToken, position.indexToken]).flat(), tx);
697
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
665
698
  const kioskTx = new kiosk_1.KioskTransaction({
666
699
  transaction: tx,
667
700
  kioskClient,
@@ -672,13 +705,13 @@ class SLPAPI extends abstract_1.BaseAPI {
672
705
  itemId: scard,
673
706
  });
674
707
  for (const position of positions) {
675
- const { pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder, isTakeProfitOrder, isIocOrder, slippage, relayerFee, coinObjects, } = position;
708
+ const { pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects = [], } = position;
676
709
  let innerIsTakeProfitOrder = isTakeProfitOrder;
677
710
  const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
678
711
  const coinObject = this.processCoins(tx, collateralToken, coinObjects);
679
712
  const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)]);
680
- const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : slippage);
681
- const adjustCollateralPrice = this.processSlippage(collateralPrice, false, 0.5);
713
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage);
714
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage);
682
715
  let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
683
716
  if (isTriggerOrder) {
684
717
  allowTrade = isIocOrder || !innerIsTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
@@ -693,7 +726,7 @@ class SLPAPI extends abstract_1.BaseAPI {
693
726
  this.consts.coins[collateralToken].module,
694
727
  this.consts.coins[indexToken].module,
695
728
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
696
- this.consts.coins['sui'].module,
729
+ this.consts.coins.sui.module,
697
730
  ],
698
731
  arguments: [
699
732
  tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
@@ -718,7 +751,7 @@ class SLPAPI extends abstract_1.BaseAPI {
718
751
  .return({
719
752
  itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
720
753
  item: sudoCard,
721
- promise: promise,
754
+ promise,
722
755
  })
723
756
  .finalize();
724
757
  return tx;
@@ -738,16 +771,16 @@ class SLPAPI extends abstract_1.BaseAPI {
738
771
  const tx = await this.initOracleTxb([collateralToken, indexToken]);
739
772
  return tx;
740
773
  }
741
- async adminSettlePosition(positionId, owner, collateralToken, indexToken, long) {
774
+ adminSettlePosition(_positionId, _owner, _collateralToken, _indexToken, _long) {
742
775
  // SLP does not support this operation
743
- throw new Error('Method not implemented.');
776
+ throw new Error(`Method not implemented for ${this.constructor.name}`);
744
777
  }
745
- async adminDecreasePosition(positionId, owner, collateralToken, indexToken, positionAmount, amount, long, collateralPrice, collateralSlippage, relayerFee) {
746
- const tx = await this.initOracleTxb([collateralToken, indexToken]);
778
+ adminDecreasePosition(positionId, owner, collateralToken, indexToken, positionAmount, amount, long, collateralPrice, collateralSlippage, relayerFee) {
779
+ const tx = new transactions_1.Transaction();
747
780
  const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
748
781
  const feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee || BigInt(1))]);
749
782
  const adjustCollateralPrice = this.processSlippage(collateralPrice || 0, false, collateralSlippage || 0.5);
750
- let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
783
+ const allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
751
784
  tx.moveCall({
752
785
  target: `${this.consts.sudoCore.upgradedPackage}::market::admin_decrease_position_v1_3`,
753
786
  typeArguments: [
@@ -755,7 +788,7 @@ class SLPAPI extends abstract_1.BaseAPI {
755
788
  this.consts.coins[collateralToken].module,
756
789
  this.consts.coins[indexToken].module,
757
790
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
758
- this.consts.coins['sui'].module,
791
+ this.consts.coins.sui.module,
759
792
  ],
760
793
  arguments: [
761
794
  tx.object(this.consts.sudoCore.adminCap),
@@ -778,7 +811,7 @@ class SLPAPI extends abstract_1.BaseAPI {
778
811
  }
779
812
  return tx;
780
813
  }
781
- async adminClearClosedPosition(positionId, owner, collateralToken, indexToken, long, tx) {
814
+ adminClearClosedPosition(positionId, owner, collateralToken, indexToken, long, tx) {
782
815
  tx.moveCall({
783
816
  target: `${this.consts.sudoCore.upgradedPackage}::market::admin_clear_closed_position_v1_1`,
784
817
  typeArguments: [
@@ -796,7 +829,7 @@ class SLPAPI extends abstract_1.BaseAPI {
796
829
  });
797
830
  }
798
831
  // SLP Specific APIs
799
- async claimTokenFromSCard(token, coinObjects, kioskClient, kioskCap, scard) {
832
+ claimTokenFromSCard(token, coinObjects, kioskClient, kioskCap, scard) {
800
833
  const tx = new transactions_1.Transaction();
801
834
  const kioskTx = new kiosk_1.KioskTransaction({
802
835
  transaction: tx,
@@ -808,7 +841,7 @@ class SLPAPI extends abstract_1.BaseAPI {
808
841
  itemId: scard,
809
842
  });
810
843
  // claim tokens
811
- coinObjects.forEach(coinObject => {
844
+ coinObjects.forEach((coinObject) => {
812
845
  return tx.moveCall({
813
846
  target: `${this.consts.sudoNft.upgradedPackage}::card::claim_token`,
814
847
  typeArguments: [`${this.consts.coins[token].module}`],
@@ -819,7 +852,7 @@ class SLPAPI extends abstract_1.BaseAPI {
819
852
  .return({
820
853
  itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
821
854
  item: sudoCard,
822
- promise: promise,
855
+ promise,
823
856
  })
824
857
  .finalize();
825
858
  return tx;