zo-sdk 0.1.2 → 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 +128 -84
  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 +128 -84
  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 +1 -133
  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 +238 -133
  171. package/src/implementations/USDZDataAPI.ts +79 -74
  172. package/src/implementations/ZLPAPI.ts +296 -174
  173. package/src/implementations/ZLPDataAPI.ts +93 -88
  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
@@ -3,32 +3,34 @@
3
3
  * Implements SLP-specific trading and transaction methods for Sudo SDK
4
4
  */
5
5
 
6
+ import type { KioskClient, KioskOwnerCap } from '@mysten/kiosk'
7
+ import { KioskTransaction } from '@mysten/kiosk'
6
8
  import type { SuiClient } from '@mysten/sui/client'
7
9
  import { Transaction } from '@mysten/sui/transactions'
8
10
  import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils'
11
+
12
+ import { BaseAPI } from '../abstract'
9
13
  import type { Network } from '../consts'
10
14
  import { ALLOW_TRADE_CAN_TRADE, ALLOW_TRADE_MUST_TRADE, ALLOW_TRADE_NO_TRADE, LPToken } from '../consts'
11
15
  import type {
12
- ISLPAPI,
13
- ISLPCredential,
16
+ IBaseHistoryResponse,
17
+ IBaseMarketInfo,
18
+ IBaseMarketValuationInfo,
14
19
  IBaseOrderCapInfo,
15
20
  IBaseOrderInfo,
16
21
  IBasePositionCapInfo,
17
22
  IBasePositionConfig,
18
23
  IBasePositionInfo,
24
+ IBaseRebaseFeeModel,
19
25
  IBaseStaked,
20
- IBaseHistoryResponse,
21
- IBaseMarketInfo,
22
- IBaseMarketValuationInfo,
26
+ IBaseStakePool,
23
27
  IBaseSymbolInfo,
24
28
  IBaseVaultInfo,
25
- IBaseRebaseFeeModel,
26
- IBaseStakePool
29
+ ISLPAPI,
30
+ ISLPCredential,
27
31
  } from '../interfaces'
28
- import { BaseAPI } from '../abstract'
29
- import { SLPDataAPI } from './SLPDataAPI'
30
32
  import { joinSymbol } from '../utils'
31
- import { KioskClient, KioskOwnerCap, KioskTransaction } from '@mysten/kiosk'
33
+ import { SLPDataAPI } from './SLPDataAPI'
32
34
 
33
35
  export class SLPAPI extends BaseAPI implements ISLPAPI {
34
36
  public dataAPI: SLPDataAPI
@@ -37,83 +39,106 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
37
39
  network: Network,
38
40
  provider: SuiClient,
39
41
  apiEndpoint: string,
40
- connectionURL: string
42
+ connectionURL: string,
41
43
  ) {
42
44
  super(network, provider, apiEndpoint, connectionURL, LPToken.SLP)
43
45
  this.dataAPI = new SLPDataAPI(network, provider, apiEndpoint, connectionURL)
44
46
  }
45
47
 
46
- public valuateVaults(tx: Transaction) {
47
- throw new Error('Method not implemented.')
48
+ public valuateVaults(_tx: Transaction) {
49
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
48
50
  }
49
- public valuateSymbols(tx: Transaction) {
50
- throw new Error('Method not implemented.')
51
+
52
+ public valuateSymbols(_tx: Transaction) {
53
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
51
54
  }
52
- public valuate(tx: Transaction): { vaultsValuation: any; symbolsValuation: any } {
53
- throw new Error('Method not implemented.')
55
+
56
+ public valuate(_tx: Transaction): { vaultsValuation: any, symbolsValuation: any } {
57
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
54
58
  }
59
+
55
60
  public valuateMarket(): Promise<IBaseMarketValuationInfo> {
56
- throw new Error('Method not implemented.')
61
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
57
62
  }
58
- public fundingFeeRate(indexToken: string, long: boolean, sender?: string): Promise<number> {
59
- throw new Error('Method not implemented.')
63
+
64
+ public fundingFeeRate(_indexToken: string, _long: boolean, _sender?: string): Promise<number> {
65
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
60
66
  }
61
- public rebaseFeeRate(collateralToken: string, increase: boolean, amount: number, sender?: string): Promise<number> {
62
- throw new Error('Method not implemented.')
67
+
68
+ public rebaseFeeRate(_collateralToken: string, _increase: boolean, _amount: number, _sender?: string): Promise<number> {
69
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
63
70
  }
64
- public reservingFeeRate(collateralToken: string, amount: number, sender?: string): Promise<number> {
65
- throw new Error('Method not implemented.')
71
+
72
+ public reservingFeeRate(_collateralToken: string, _amount: number, _sender?: string): Promise<number> {
73
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
66
74
  }
67
- public calcPositionReserveFeeAmount(position: IBasePositionInfo): Promise<number> {
68
- throw new Error('Method not implemented.')
75
+
76
+ public calcPositionReserveFeeAmount(_position: IBasePositionInfo): Promise<number> {
77
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
69
78
  }
70
- public calcPositionFundingFeeValue(position: IBasePositionInfo): Promise<number> {
71
- throw new Error('Method not implemented.')
79
+
80
+ public calcPositionFundingFeeValue(_position: IBasePositionInfo): Promise<number> {
81
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
72
82
  }
83
+
73
84
  public getMarketInfo(): Promise<IBaseMarketInfo> {
74
- throw new Error('Method not implemented.')
85
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
75
86
  }
76
- public getVaultInfo(vault: string): Promise<IBaseVaultInfo> {
77
- throw new Error('Method not implemented.')
87
+
88
+ public getVaultInfo(_vault: string): Promise<IBaseVaultInfo> {
89
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
78
90
  }
79
- public getSymbolInfo(tokenId: string, long: boolean): Promise<IBaseSymbolInfo> {
80
- throw new Error('Method not implemented.')
91
+
92
+ public getSymbolInfo(_tokenId: string, _long: boolean): Promise<IBaseSymbolInfo> {
93
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
81
94
  }
82
- public getPositionConfig(indexToken: string, long: boolean): Promise<IBasePositionConfig> {
83
- throw new Error('Method not implemented.')
95
+
96
+ public getPositionConfig(_indexToken: string, _long: boolean): Promise<IBasePositionConfig> {
97
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
84
98
  }
99
+
85
100
  public getRebaseFeeModel(): Promise<IBaseRebaseFeeModel> {
86
- throw new Error('Method not implemented.')
101
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
87
102
  }
103
+
88
104
  public getOpenPositions(): Promise<IBasePositionInfo[]> {
89
- throw new Error('Method not implemented.')
105
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
90
106
  }
91
- public getPositionCapInfoList(owner: string): Promise<IBasePositionCapInfo[]> {
92
- throw new Error('Method not implemented.')
107
+
108
+ public getPositionCapInfoList(_owner: string): Promise<IBasePositionCapInfo[]> {
109
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
93
110
  }
94
- public getPositionInfoList(positionCapInfoList: IBasePositionCapInfo[], owner: string): Promise<IBasePositionInfo[]> {
95
- throw new Error('Method not implemented.')
111
+
112
+ public getPositionInfoList(_positionCapInfoList: IBasePositionCapInfo[], _owner: string): Promise<IBasePositionInfo[]> {
113
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
96
114
  }
97
- public getOrderCapInfoList(owner: string): Promise<IBaseOrderCapInfo[]> {
98
- throw new Error('Method not implemented.')
115
+
116
+ public getOrderCapInfoList(_owner: string): Promise<IBaseOrderCapInfo[]> {
117
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
99
118
  }
100
- public getOrderInfoList(orderCapInfoList: IBaseOrderCapInfo[], owner: string): Promise<IBaseOrderInfo[]> {
101
- throw new Error('Method not implemented.')
119
+
120
+ public getOrderInfoList(_orderCapInfoList: IBaseOrderCapInfo[], _owner: string): Promise<IBaseOrderInfo[]> {
121
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
102
122
  }
103
- public getHistory(trader: string, page: number, limit: number, orderType?: string, symbol?: string): Promise<IBaseHistoryResponse> {
104
- throw new Error('Method not implemented.')
123
+
124
+ public getHistory(_trader: string, _page: number, _limit: number, _orderType?: string, _symbol?: string): Promise<IBaseHistoryResponse> {
125
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
105
126
  }
106
- public getStaked(owner: string): Promise<IBaseStaked> {
107
- throw new Error('Method not implemented.')
127
+
128
+ public getStaked(_owner: string): Promise<IBaseStaked> {
129
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
108
130
  }
131
+
109
132
  public getStakePool(): Promise<IBaseStakePool> {
110
- throw new Error('Method not implemented.')
133
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
111
134
  }
112
- public hasReferral(referree: string): Promise<boolean> {
113
- throw new Error('Method not implemented.')
135
+
136
+ public hasReferral(_referree: string): Promise<boolean> {
137
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
114
138
  }
115
- public getReferralData(referree: string): Promise<any> {
116
- throw new Error('Method not implemented.')
139
+
140
+ public getReferralData(_referree: string): Promise<any> {
141
+ throw new Error(`Method not implemented in ${this.constructor.name}.`)
117
142
  }
118
143
 
119
144
  /**
@@ -123,19 +148,59 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
123
148
  coin: string,
124
149
  coinObjects: string[],
125
150
  amount: number,
126
- minAmountOut?: number,
151
+ minAmountOut = 0,
127
152
  referralAddress?: string,
128
- sender?: string
153
+ sender?: string,
154
+ sponsoredTx?: boolean,
155
+ suiCoinObjectsForPythUpdate?: string[],
156
+ isDepositingSui?: boolean,
129
157
  ): Promise<Transaction> {
130
158
  let tx = new Transaction()
159
+
160
+ // Add referral if needed
131
161
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
132
162
  tx = await this.addReferral(referralAddress, tx)
133
163
  }
134
- tx = await this.initOracleTxb(
135
- Object.keys(this.consts.pythFeeder.feeder),
136
- )
137
- const coinObject = this.processCoins(tx, coin, coinObjects)
138
- const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)])
164
+
165
+ // Initialize oracle transaction
166
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder)
167
+
168
+ // Handle sponsored transaction case
169
+ if (sponsoredTx) {
170
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
171
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject)
172
+
173
+ // Process deposit coins
174
+ const depositObject = isDepositingSui
175
+ ? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
176
+ : tx.splitCoins(this.processCoins(tx, coin, coinObjects, true), [tx.pure.u64(amount)])[0]
177
+
178
+ const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
179
+
180
+ tx.moveCall({
181
+ target: `${this.consts.sudoCore.upgradedPackage}::market::deposit`,
182
+ typeArguments: [
183
+ `${this.consts.sudoCore.package}::slp::SLP`,
184
+ this.consts.coins[coin].module,
185
+ ],
186
+ arguments: [
187
+ tx.object(this.consts.sudoCore.market),
188
+ tx.object(this.consts.sudoCore.rebaseFeeModel),
189
+ depositObject,
190
+ tx.pure.u64(minAmountOut),
191
+ vaultsValuation,
192
+ symbolsValuation,
193
+ ],
194
+ })
195
+ return tx
196
+ }
197
+
198
+ // Handle non-sponsored transaction case
199
+ tx = await this.initOracleTxb(pythFeederKeys, tx)
200
+ const depositObject = tx.splitCoins(
201
+ this.processCoins(tx, coin, coinObjects, false),
202
+ [tx.pure.u64(amount)],
203
+ )[0]
139
204
 
140
205
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
141
206
 
@@ -149,7 +214,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
149
214
  tx.object(this.consts.sudoCore.market),
150
215
  tx.object(this.consts.sudoCore.rebaseFeeModel),
151
216
  depositObject,
152
- tx.pure.u64(minAmountOut || 0),
217
+ tx.pure.u64(minAmountOut),
153
218
  vaultsValuation,
154
219
  symbolsValuation,
155
220
  ],
@@ -164,13 +229,25 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
164
229
  coin: string,
165
230
  lpCoinObjects: string[],
166
231
  amount: number,
167
- minAmountOut?: number
232
+ minAmountOut = 0,
233
+ sponsoredTx?: boolean,
234
+ suiCoinObjectsForPythUpdate?: string[],
168
235
  ): Promise<Transaction> {
169
- const tx = await this.initOracleTxb(
170
- Object.keys(this.consts.pythFeeder.feeder),
171
- )
172
- const lpCoinObject = this.processCoins(tx, `${this.consts.sudoCore.package}::slp::SLP`, lpCoinObjects)
173
- const [withdrawObject] = tx.splitCoins(lpCoinObject, [tx.pure.u64(amount)])
236
+ let tx = new Transaction()
237
+
238
+ // Initialize oracle transaction
239
+ const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder)
240
+
241
+ if (sponsoredTx) {
242
+ const suiCoinObject = this.processCoins(tx, 'sui', suiCoinObjectsForPythUpdate || [], true)
243
+ tx = await this.initOracleTxb(pythFeederKeys, tx, true, suiCoinObject)
244
+ }
245
+ else {
246
+ tx = await this.initOracleTxb(pythFeederKeys, tx)
247
+ }
248
+
249
+ const slpCoinObject = this.processCoins(tx, 'slp', lpCoinObjects, false)
250
+ const [withdrawObject] = tx.splitCoins(slpCoinObject, [tx.pure.u64(amount)])
174
251
  const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx)
175
252
 
176
253
  tx.moveCall({
@@ -183,7 +260,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
183
260
  tx.object(this.consts.sudoCore.market),
184
261
  tx.object(this.consts.sudoCore.rebaseFeeModel),
185
262
  withdrawObject,
186
- tx.pure.u64(minAmountOut || 0),
263
+ tx.pure.u64(minAmountOut),
187
264
  vaultsValuation,
188
265
  symbolsValuation,
189
266
  ],
@@ -196,10 +273,10 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
196
273
  toToken: string,
197
274
  fromAmount: bigint,
198
275
  fromCoinObjects: string[],
199
- minAmountOut?: number
276
+ minAmountOut?: number,
200
277
  ): Promise<Transaction> {
201
278
  const tx = await this.initOracleTxb(
202
- Object.keys(this.consts.sudoCore.vaults)
279
+ Object.keys(this.consts.sudoCore.vaults),
203
280
  )
204
281
  const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects)
205
282
  const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
@@ -228,11 +305,11 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
228
305
  /**
229
306
  * Stakes SLP tokens in Sudo staking pools
230
307
  */
231
- public async stake(
308
+ public stake(
232
309
  lpCoinObjects: string[],
233
310
  amount: bigint,
234
- pool: string
235
- ): Promise<Transaction> {
311
+ pool: string,
312
+ ): Transaction {
236
313
  if (!this.consts.sudoStaking) {
237
314
  throw new Error('Sudo staking configuration not found')
238
315
  }
@@ -259,11 +336,11 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
259
336
  /**
260
337
  * Unstakes SLP tokens from Sudo staking pools
261
338
  */
262
- public async unstake(
339
+ public unstake(
263
340
  credentials: ISLPCredential[],
264
341
  amount: bigint,
265
- pool: string
266
- ): Promise<Transaction> {
342
+ pool: string,
343
+ ): Transaction {
267
344
  if (!this.consts.sudoStaking) {
268
345
  throw new Error('Sudo staking configuration not found')
269
346
  }
@@ -271,9 +348,10 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
271
348
  const tx = new Transaction()
272
349
 
273
350
  for (const credential of credentials) {
274
- // eslint-disable-next-line unicorn/prefer-math-min-max
275
- const withdrawAmount =
276
- amount < credential.amount ? amount : credential.amount
351
+ const withdrawAmount = (() => {
352
+ const min = (a: bigint, b: bigint) => a < b ? a : b
353
+ return min(amount, credential.amount)
354
+ })()
277
355
  amount -= withdrawAmount
278
356
  tx.moveCall({
279
357
  target: `${this.consts.sudoStaking.package}::pool::withdraw`,
@@ -317,11 +395,11 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
317
395
  collateralPrice: number,
318
396
  isLimitOrder = false,
319
397
  isIocOrder = false,
320
- pricesSlippage: number = 0.003,
321
- collateralSlippage: number = 0.5,
398
+ pricesSlippage = 0.003,
399
+ collateralSlippage = 0.5,
322
400
  relayerFee = BigInt(0.5),
323
401
  referralAddress?: string,
324
- sender?: string
402
+ sender?: string,
325
403
  ): Promise<Transaction> {
326
404
  let tx = new Transaction()
327
405
  if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
@@ -350,13 +428,13 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
350
428
  this.consts.coins[collateralToken].module,
351
429
  this.consts.coins[indexToken].module,
352
430
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
353
- this.consts.coins['sui'].module,
431
+ this.consts.coins.sui.module,
354
432
  ],
355
433
  arguments: [
356
434
  tx.object(SUI_CLOCK_OBJECT_ID),
357
435
  tx.object(this.consts.sudoCore.market),
358
436
  tx.object(
359
- this.consts.sudoCore.vaults[collateralToken].reservingFeeModel
437
+ this.consts.sudoCore.vaults[collateralToken].reservingFeeModel,
360
438
  ),
361
439
  tx.object(this.consts.sudoCore.symbols[symbol].fundingFeeModel),
362
440
  tx.object(this.consts.sudoCore.symbols[symbol].positionConfig),
@@ -389,10 +467,9 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
389
467
  isTriggerOrder = false,
390
468
  isTakeProfitOrder = true,
391
469
  isIocOrder = false,
392
- pricesSlippage: number = 0.003,
393
- collateralSlippage: number = 0.5,
470
+ pricesSlippage = 0.003,
471
+ collateralSlippage = 0.5,
394
472
  relayerFee = BigInt(0.5),
395
- coinObjects?: string[]
396
473
  ): Promise<Transaction> {
397
474
  const tx = await this.initOracleTxb([collateralToken, indexToken])
398
475
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
@@ -401,22 +478,19 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
401
478
  const adjustPrice = this.processSlippage(
402
479
  indexPrice,
403
480
  !long,
404
- isTriggerOrder ? 0 : pricesSlippage
481
+ isTriggerOrder ? 0 : pricesSlippage,
405
482
  )
406
483
  const adjustCollateralPrice = this.processSlippage(
407
484
  collateralPrice,
408
485
  false,
409
- collateralSlippage
486
+ collateralSlippage,
410
487
  )
411
488
 
412
489
  let allowTrade = ALLOW_TRADE_MUST_TRADE
413
490
  if (isTriggerOrder) {
414
- if (isIocOrder || !isTakeProfitOrder) {
415
- allowTrade = ALLOW_TRADE_NO_TRADE
416
- } else {
417
- allowTrade = ALLOW_TRADE_CAN_TRADE
418
- }
419
- } else {
491
+ allowTrade = isIocOrder || !isTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
492
+ }
493
+ else {
420
494
  isTakeProfitOrder = true
421
495
  }
422
496
 
@@ -427,14 +501,14 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
427
501
  this.consts.coins[collateralToken].module,
428
502
  this.consts.coins[indexToken].module,
429
503
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
430
- this.consts.coins['sui'].module,
504
+ this.consts.coins.sui.module,
431
505
  ],
432
506
  arguments: [
433
507
  tx.object(SUI_CLOCK_OBJECT_ID),
434
508
  tx.object(this.consts.sudoCore.market),
435
509
  tx.object(pcpId),
436
510
  tx.object(
437
- this.consts.sudoCore.vaults[collateralToken].reservingFeeModel
511
+ this.consts.sudoCore.vaults[collateralToken].reservingFeeModel,
438
512
  ),
439
513
  tx.object(this.consts.sudoCore.symbols[symbol].fundingFeeModel),
440
514
  tx.object(this.consts.pythFeeder.feeder[collateralToken]),
@@ -454,44 +528,58 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
454
528
 
455
529
  public async decreaseMultiPositions(
456
530
  positions: Array<{
457
- pcpId: string,
458
- collateralToken: string,
459
- coinObjects: string[],
460
- indexToken: string,
461
- amount: bigint,
462
- long: boolean,
463
- indexPrice: number,
464
- collateralPrice: number,
465
- isTriggerOrder: boolean,
466
- isTakeProfitOrder: boolean,
467
- isIocOrder: boolean,
468
- slippage: number,
469
- relayerFee: bigint,
470
- }>, tx?: Transaction
531
+ pcpId: string
532
+ collateralToken: string
533
+ indexToken: string
534
+ amount: bigint
535
+ long: boolean
536
+ indexPrice: number
537
+ collateralPrice: number
538
+ isTriggerOrder?: boolean
539
+ isTakeProfitOrder?: boolean
540
+ isIocOrder?: boolean
541
+ pricesSlippage?: number
542
+ collateralSlippage?: number
543
+ relayerFee?: bigint
544
+ coinObjects?: string[]
545
+ }>,
546
+ tx?: Transaction,
471
547
  ): Promise<Transaction> {
472
548
  if (!tx) {
473
549
  tx = new Transaction()
474
550
  }
475
- tx = await this.initOracleTxb(positions.map(position => [position.collateralToken, position.indexToken]).flat(), tx)
551
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)
476
552
 
477
553
  for (const position of positions) {
478
554
  const {
479
555
  pcpId,
480
556
  collateralToken,
481
- coinObjects, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder, isTakeProfitOrder, isIocOrder, slippage, relayerFee
557
+ coinObjects = [],
558
+ indexToken,
559
+ amount,
560
+ long,
561
+ indexPrice,
562
+ collateralPrice,
563
+ isTriggerOrder = false,
564
+ isTakeProfitOrder = true,
565
+ isIocOrder = false,
566
+ pricesSlippage = 0.003,
567
+ collateralSlippage = 0.5,
568
+ relayerFee = BigInt(0.5),
482
569
  } = position
483
570
  let innerIsTakeProfitOrder = isTakeProfitOrder
484
571
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
485
572
  const coinObject = this.processCoins(tx, collateralToken, coinObjects)
486
573
  const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)])
487
574
 
488
- const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : slippage)
489
- const adjustCollateralPrice = this.processSlippage(collateralPrice, false, 0.5)
575
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
576
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
490
577
 
491
578
  let allowTrade = ALLOW_TRADE_MUST_TRADE
492
579
  if (isTriggerOrder) {
493
580
  allowTrade = isIocOrder || !innerIsTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
494
- } else {
581
+ }
582
+ else {
495
583
  innerIsTakeProfitOrder = true
496
584
  }
497
585
 
@@ -502,14 +590,14 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
502
590
  this.consts.coins[collateralToken].module,
503
591
  this.consts.coins[indexToken].module,
504
592
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
505
- this.consts.coins['sui'].module,
593
+ this.consts.coins.sui.module,
506
594
  ],
507
595
  arguments: [
508
596
  tx.object(SUI_CLOCK_OBJECT_ID),
509
597
  tx.object(this.consts.sudoCore.market),
510
598
  tx.object(pcpId),
511
599
  tx.object(
512
- this.consts.sudoCore.vaults[collateralToken].reservingFeeModel
600
+ this.consts.sudoCore.vaults[collateralToken].reservingFeeModel,
513
601
  ),
514
602
  tx.object(this.consts.sudoCore.symbols[symbol].fundingFeeModel),
515
603
  tx.object(this.consts.pythFeeder.feeder[collateralToken]),
@@ -533,7 +621,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
533
621
  indexToken: string,
534
622
  amount: number,
535
623
  coinObjects: string[],
536
- long: boolean
624
+ long: boolean,
537
625
  ): Promise<Transaction> {
538
626
  const tx = await this.initOracleTxb([collateralToken, indexToken])
539
627
  const coinObject = this.processCoins(tx, collateralToken, coinObjects)
@@ -561,7 +649,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
561
649
  collateralToken: string,
562
650
  indexToken: string,
563
651
  amount: number,
564
- long: boolean
652
+ long: boolean,
565
653
  ): Promise<Transaction> {
566
654
  const tx = await this.initOracleTxb([collateralToken, indexToken])
567
655
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
@@ -579,7 +667,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
579
667
  tx.object(this.consts.sudoCore.market),
580
668
  tx.object(pcpId),
581
669
  tx.object(
582
- this.consts.sudoCore.vaults[collateralToken].reservingFeeModel
670
+ this.consts.sudoCore.vaults[collateralToken].reservingFeeModel,
583
671
  ),
584
672
  tx.object(this.consts.sudoCore.symbols[symbol].fundingFeeModel),
585
673
  tx.object(this.consts.pythFeeder.feeder[collateralToken]),
@@ -591,25 +679,27 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
591
679
  return tx
592
680
  }
593
681
 
594
- public async cancelOrder(
682
+ public cancelOrder(
595
683
  orderCapId: string,
596
684
  collateralToken: string,
597
685
  indexToken: string,
598
686
  long: boolean,
599
687
  type: string,
600
- isV11Order?: boolean
601
- ): Promise<Transaction> {
688
+ ): Transaction {
602
689
  const tx = new Transaction()
603
690
  let functionName = ''
604
691
  switch (type) {
605
- case 'OPEN_POSITION':
692
+ case 'OPEN_POSITION': {
606
693
  functionName = 'clear_open_position_order_v1_1'
607
694
  break
608
- case 'DECREASE_POSITION':
695
+ }
696
+ case 'DECREASE_POSITION': {
609
697
  functionName = 'clear_decrease_position_order_v1_1'
610
698
  break
611
- default:
699
+ }
700
+ default: {
612
701
  throw new Error('invalid order type')
702
+ }
613
703
  }
614
704
  tx.moveCall({
615
705
  target: `${this.consts.sudoCore.upgradedPackage}::market::${functionName}`,
@@ -618,7 +708,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
618
708
  this.consts.coins[collateralToken].module,
619
709
  this.consts.coins[indexToken].module,
620
710
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
621
- this.consts.coins['sui'].module,
711
+ this.consts.coins.sui.module,
622
712
  ],
623
713
  arguments: [
624
714
  tx.object(this.consts.sudoCore.market),
@@ -628,16 +718,17 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
628
718
  return tx
629
719
  }
630
720
 
631
- public async cancelMultiOrders(
721
+ public cancelMultiOrders(
632
722
  orders: Array<{
633
- orderCapId: string,
634
- collateralToken: string,
635
- indexToken: string,
636
- long: boolean,
637
- type: string,
723
+ orderCapId: string
724
+ collateralToken: string
725
+ indexToken: string
726
+ long: boolean
727
+ type: string
638
728
  isV11Order?: boolean
639
- }>, tx?: Transaction
640
- ): Promise<Transaction> {
729
+ }>,
730
+ tx?: Transaction,
731
+ ): Transaction {
641
732
  if (!tx) {
642
733
  tx = new Transaction()
643
734
  }
@@ -701,7 +792,6 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
701
792
  indexToken: string,
702
793
  long: boolean,
703
794
  tx: Transaction,
704
- isV11Order?: boolean
705
795
  ): void {
706
796
  tx.moveCall({
707
797
  target: `${this.consts.sudoCore.upgradedPackage}::market::clear_open_position_order_v1_1`,
@@ -710,7 +800,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
710
800
  this.consts.coins[collateralToken].module,
711
801
  this.consts.coins[indexToken].module,
712
802
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
713
- this.consts.coins['sui'].module,
803
+ this.consts.coins.sui.module,
714
804
  ],
715
805
  arguments: [
716
806
  tx.object(this.consts.sudoCore.market),
@@ -724,7 +814,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
724
814
  collateralToken: string,
725
815
  indexToken: string,
726
816
  long: boolean,
727
- tx: Transaction
817
+ tx: Transaction,
728
818
  ): void {
729
819
  tx.moveCall({
730
820
  target: `${this.consts.sudoCore.upgradedPackage}::market::clear_decrease_position_order_v1_1`,
@@ -733,7 +823,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
733
823
  this.consts.coins[collateralToken].module,
734
824
  this.consts.coins[indexToken].module,
735
825
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
736
- this.consts.coins['sui'].module,
826
+ this.consts.coins.sui.module,
737
827
  ],
738
828
  arguments: [
739
829
  tx.object(this.consts.sudoCore.market),
@@ -801,13 +891,13 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
801
891
  this.consts.coins[collateralToken].module,
802
892
  this.consts.coins[indexToken].module,
803
893
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
804
- this.consts.coins['sui'].module,
894
+ this.consts.coins.sui.module,
805
895
  ],
806
896
  arguments: [
807
897
  tx.object(SUI_CLOCK_OBJECT_ID),
808
898
  tx.object(this.consts.sudoCore.market),
809
899
  tx.object(
810
- this.consts.sudoCore.vaults[collateralToken].reservingFeeModel
900
+ this.consts.sudoCore.vaults[collateralToken].reservingFeeModel,
811
901
  ),
812
902
  tx.object(this.consts.sudoCore.symbols[symbol].fundingFeeModel),
813
903
  tx.object(this.consts.sudoCore.symbols[symbol].positionConfig),
@@ -829,7 +919,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
829
919
  .return({
830
920
  itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
831
921
  item: sudoCard,
832
- promise: promise,
922
+ promise,
833
923
  })
834
924
  .finalize()
835
925
  return tx
@@ -849,10 +939,9 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
849
939
  isTriggerOrder = false,
850
940
  isTakeProfitOrder = true,
851
941
  isIocOrder = false,
852
- pricesSlippage: number = 0.003,
853
- collateralSlippage: number = 0.5,
942
+ pricesSlippage = 0.003,
943
+ collateralSlippage = 0.5,
854
944
  relayerFee = BigInt(0.5),
855
- coinObjects?: string[]
856
945
  ): Promise<Transaction> {
857
946
  const tx = await this.initOracleTxb([collateralToken, indexToken])
858
947
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
@@ -861,22 +950,19 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
861
950
  const adjustPrice = this.processSlippage(
862
951
  indexPrice,
863
952
  !long,
864
- isTriggerOrder ? 0 : pricesSlippage
953
+ isTriggerOrder ? 0 : pricesSlippage,
865
954
  )
866
955
  const adjustCollateralPrice = this.processSlippage(
867
956
  collateralPrice,
868
957
  false,
869
- collateralSlippage
958
+ collateralSlippage,
870
959
  )
871
960
 
872
961
  let allowTrade = ALLOW_TRADE_MUST_TRADE
873
962
  if (isTriggerOrder) {
874
- if (isIocOrder || !isTakeProfitOrder) {
875
- allowTrade = ALLOW_TRADE_NO_TRADE
876
- } else {
877
- allowTrade = ALLOW_TRADE_CAN_TRADE
878
- }
879
- } else {
963
+ allowTrade = isIocOrder || !isTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
964
+ }
965
+ else {
880
966
  isTakeProfitOrder = true
881
967
  }
882
968
 
@@ -898,14 +984,14 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
898
984
  this.consts.coins[collateralToken].module,
899
985
  this.consts.coins[indexToken].module,
900
986
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
901
- this.consts.coins['sui'].module,
987
+ this.consts.coins.sui.module,
902
988
  ],
903
989
  arguments: [
904
990
  tx.object(SUI_CLOCK_OBJECT_ID),
905
991
  tx.object(this.consts.sudoCore.market),
906
992
  tx.object(pcpId),
907
993
  tx.object(
908
- this.consts.sudoCore.vaults[collateralToken].reservingFeeModel
994
+ this.consts.sudoCore.vaults[collateralToken].reservingFeeModel,
909
995
  ),
910
996
  tx.object(this.consts.sudoCore.symbols[symbol].fundingFeeModel),
911
997
  tx.object(this.consts.pythFeeder.feeder[collateralToken]),
@@ -925,7 +1011,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
925
1011
  .return({
926
1012
  itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
927
1013
  item: sudoCard,
928
- promise: promise,
1014
+ promise,
929
1015
  })
930
1016
  .finalize()
931
1017
  return tx
@@ -933,29 +1019,30 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
933
1019
 
934
1020
  public async decreaseMultiPositionsWithSCard(
935
1021
  positions: Array<{
936
- pcpId: string,
937
- collateralToken: string,
938
- indexToken: string,
939
- amount: bigint,
940
- long: boolean,
941
- indexPrice: number,
942
- collateralPrice: number,
943
- isTriggerOrder: boolean,
944
- isTakeProfitOrder: boolean,
945
- isIocOrder: boolean,
946
- slippage: number,
947
- relayerFee: bigint,
948
- coinObjects: string[]
1022
+ pcpId: string
1023
+ collateralToken: string
1024
+ indexToken: string
1025
+ amount: bigint
1026
+ long: boolean
1027
+ indexPrice: number
1028
+ collateralPrice: number
1029
+ isTriggerOrder?: boolean
1030
+ isTakeProfitOrder?: boolean
1031
+ isIocOrder?: boolean
1032
+ pricesSlippage?: number
1033
+ collateralSlippage?: number
1034
+ relayerFee?: bigint
1035
+ coinObjects?: string[]
949
1036
  }>,
950
1037
  kioskClient: KioskClient,
951
1038
  kioskCap: KioskOwnerCap,
952
1039
  scard: string,
953
- tx?: Transaction
1040
+ tx?: Transaction,
954
1041
  ): Promise<Transaction> {
955
1042
  if (!tx) {
956
1043
  tx = new Transaction()
957
1044
  }
958
- tx = await this.initOracleTxb(positions.map(position => [position.collateralToken, position.indexToken]).flat(), tx)
1045
+ tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)
959
1046
 
960
1047
  const kioskTx = new KioskTransaction({
961
1048
  transaction: tx,
@@ -977,25 +1064,27 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
977
1064
  long,
978
1065
  indexPrice,
979
1066
  collateralPrice,
980
- isTriggerOrder,
981
- isTakeProfitOrder,
982
- isIocOrder,
983
- slippage,
984
- relayerFee,
985
- coinObjects,
1067
+ isTriggerOrder = false,
1068
+ isTakeProfitOrder = true,
1069
+ isIocOrder = false,
1070
+ pricesSlippage = 0.003,
1071
+ collateralSlippage = 0.5,
1072
+ relayerFee = BigInt(0.5),
1073
+ coinObjects = [],
986
1074
  } = position
987
1075
  let innerIsTakeProfitOrder = isTakeProfitOrder
988
1076
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
989
1077
  const coinObject = this.processCoins(tx, collateralToken, coinObjects)
990
1078
  const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)])
991
1079
 
992
- const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : slippage)
993
- const adjustCollateralPrice = this.processSlippage(collateralPrice, false, 0.5)
1080
+ const adjustPrice = this.processSlippage(indexPrice, !long, isTriggerOrder ? 0 : pricesSlippage)
1081
+ const adjustCollateralPrice = this.processSlippage(collateralPrice, false, collateralSlippage)
994
1082
 
995
1083
  let allowTrade = ALLOW_TRADE_MUST_TRADE
996
1084
  if (isTriggerOrder) {
997
1085
  allowTrade = isIocOrder || !innerIsTakeProfitOrder ? ALLOW_TRADE_NO_TRADE : ALLOW_TRADE_CAN_TRADE
998
- } else {
1086
+ }
1087
+ else {
999
1088
  innerIsTakeProfitOrder = true
1000
1089
  }
1001
1090
 
@@ -1006,14 +1095,14 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1006
1095
  this.consts.coins[collateralToken].module,
1007
1096
  this.consts.coins[indexToken].module,
1008
1097
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1009
- this.consts.coins['sui'].module,
1098
+ this.consts.coins.sui.module,
1010
1099
  ],
1011
1100
  arguments: [
1012
1101
  tx.object(SUI_CLOCK_OBJECT_ID),
1013
1102
  tx.object(this.consts.sudoCore.market),
1014
1103
  tx.object(pcpId),
1015
1104
  tx.object(
1016
- this.consts.sudoCore.vaults[collateralToken].reservingFeeModel
1105
+ this.consts.sudoCore.vaults[collateralToken].reservingFeeModel,
1017
1106
  ),
1018
1107
  tx.object(this.consts.sudoCore.symbols[symbol].fundingFeeModel),
1019
1108
  tx.object(this.consts.pythFeeder.feeder[collateralToken]),
@@ -1034,7 +1123,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1034
1123
  .return({
1035
1124
  itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
1036
1125
  item: sudoCard,
1037
- promise: promise,
1126
+ promise,
1038
1127
  })
1039
1128
  .finalize()
1040
1129
  return tx
@@ -1042,7 +1131,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1042
1131
 
1043
1132
  public addReferral(
1044
1133
  referrer: string,
1045
- tx?: Transaction
1134
+ tx?: Transaction,
1046
1135
  ): Transaction {
1047
1136
  if (!tx) {
1048
1137
  tx = new Transaction()
@@ -1058,24 +1147,24 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1058
1147
 
1059
1148
  public async adminUpdatePriceFeed(
1060
1149
  collateralToken: string,
1061
- indexToken: string
1150
+ indexToken: string,
1062
1151
  ): Promise<Transaction> {
1063
1152
  const tx = await this.initOracleTxb([collateralToken, indexToken])
1064
1153
  return tx
1065
1154
  }
1066
1155
 
1067
- public async adminSettlePosition(
1068
- positionId: string,
1069
- owner: string,
1070
- collateralToken: string,
1071
- indexToken: string,
1072
- long: boolean
1073
- ): Promise<Transaction> {
1156
+ public adminSettlePosition(
1157
+ _positionId: string,
1158
+ _owner: string,
1159
+ _collateralToken: string,
1160
+ _indexToken: string,
1161
+ _long: boolean,
1162
+ ): Transaction {
1074
1163
  // SLP does not support this operation
1075
- throw new Error('Method not implemented.')
1164
+ throw new Error(`Method not implemented for ${this.constructor.name}`)
1076
1165
  }
1077
1166
 
1078
- public async adminDecreasePosition(
1167
+ public adminDecreasePosition(
1079
1168
  positionId: string,
1080
1169
  owner: string,
1081
1170
  collateralToken: string,
@@ -1085,9 +1174,9 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1085
1174
  long: boolean,
1086
1175
  collateralPrice?: number,
1087
1176
  collateralSlippage?: number,
1088
- relayerFee?: bigint
1089
- ): Promise<Transaction> {
1090
- const tx = await this.initOracleTxb([collateralToken, indexToken])
1177
+ relayerFee?: bigint,
1178
+ ): Transaction {
1179
+ const tx = new Transaction()
1091
1180
  const symbol = joinSymbol(long ? 'long' : 'short', indexToken)
1092
1181
  const feeObject = tx.splitCoins(tx.gas, [tx.pure.u64(relayerFee || BigInt(1))])
1093
1182
 
@@ -1097,7 +1186,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1097
1186
  collateralSlippage || 0.5,
1098
1187
  )
1099
1188
 
1100
- let allowTrade = ALLOW_TRADE_MUST_TRADE
1189
+ const allowTrade = ALLOW_TRADE_MUST_TRADE
1101
1190
 
1102
1191
  tx.moveCall({
1103
1192
  target: `${this.consts.sudoCore.upgradedPackage}::market::admin_decrease_position_v1_3`,
@@ -1106,7 +1195,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1106
1195
  this.consts.coins[collateralToken].module,
1107
1196
  this.consts.coins[indexToken].module,
1108
1197
  `${this.consts.sudoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
1109
- this.consts.coins['sui'].module,
1198
+ this.consts.coins.sui.module,
1110
1199
  ],
1111
1200
  arguments: [
1112
1201
  tx.object(this.consts.sudoCore.adminCap),
@@ -1141,14 +1230,14 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1141
1230
  return tx
1142
1231
  }
1143
1232
 
1144
- public async adminClearClosedPosition(
1233
+ public adminClearClosedPosition(
1145
1234
  positionId: string,
1146
1235
  owner: string,
1147
1236
  collateralToken: string,
1148
1237
  indexToken: string,
1149
1238
  long: boolean,
1150
- tx: Transaction
1151
- ): Promise<void> {
1239
+ tx: Transaction,
1240
+ ): void {
1152
1241
  tx.moveCall({
1153
1242
  target: `${this.consts.sudoCore.upgradedPackage}::market::admin_clear_closed_position_v1_1`,
1154
1243
  typeArguments: [
@@ -1167,13 +1256,13 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1167
1256
  }
1168
1257
 
1169
1258
  // SLP Specific APIs
1170
- public async claimTokenFromSCard(
1259
+ public claimTokenFromSCard(
1171
1260
  token: string,
1172
1261
  coinObjects: string[],
1173
1262
  kioskClient: KioskClient,
1174
1263
  kioskCap: KioskOwnerCap,
1175
- scard: string
1176
- ): Promise<Transaction> {
1264
+ scard: string,
1265
+ ): Transaction {
1177
1266
  const tx = new Transaction()
1178
1267
  const kioskTx = new KioskTransaction({
1179
1268
  transaction: tx,
@@ -1187,7 +1276,7 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1187
1276
  })
1188
1277
 
1189
1278
  // claim tokens
1190
- coinObjects.forEach(coinObject => {
1279
+ coinObjects.forEach((coinObject) => {
1191
1280
  return tx.moveCall({
1192
1281
  target: `${this.consts.sudoNft.upgradedPackage}::card::claim_token`,
1193
1282
  typeArguments: [`${this.consts.coins[token].module}`],
@@ -1199,9 +1288,9 @@ export class SLPAPI extends BaseAPI implements ISLPAPI {
1199
1288
  .return({
1200
1289
  itemType: `${this.consts.sudoNft.package}::card::SudoCard`,
1201
1290
  item: sudoCard,
1202
- promise: promise,
1291
+ promise,
1203
1292
  })
1204
1293
  .finalize()
1205
1294
  return tx
1206
1295
  }
1207
- }
1296
+ }