zo-sdk 0.0.14 → 0.0.16

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.
package/dist/api.cjs CHANGED
@@ -26,359 +26,325 @@ class API extends data_1.DataAPI {
26
26
  }
27
27
  return tx.object(coinObjects[0]);
28
28
  });
29
- Object.defineProperty(this, "deposit", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: async (coin, coinObjects, amount, minAmountOut = 0) => {
34
- const tx = await this.initOracleTxb(Object.keys(this.consts.pythFeeder.feeder));
35
- const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, coin, coinObjects);
36
- const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
37
- const { vaultsValuation, symbolsValuation, } = this.valuate(tx);
38
- tx.moveCall({
39
- target: `${this.consts.zoCore.package}::market::deposit`,
40
- typeArguments: [
41
- `${this.consts.zoCore.package}::zlp::ZLP`,
42
- this.consts.coins[coin].module,
43
- ],
44
- arguments: [
45
- tx.object(this.consts.zoCore.market),
46
- tx.object(this.consts.zoCore.rebaseFeeModel),
47
- depositObject,
48
- tx.pure.u64(minAmountOut),
49
- vaultsValuation,
50
- symbolsValuation,
51
- ],
52
- });
53
- return tx;
29
+ this.deposit = async (coin, coinObjects, amount, minAmountOut = 0, referralAddress = '', sender = '') => {
30
+ let tx = await this.initOracleTxb(Object.keys(this.consts.pythFeeder.feeder));
31
+ if (referralAddress && !await this.hasReferral(sender || '')) {
32
+ tx = await this.addReferral(referralAddress, tx);
54
33
  }
55
- });
56
- Object.defineProperty(this, "withdraw", {
57
- enumerable: true,
58
- configurable: true,
59
- writable: true,
60
- value: async (coin, zlpCoinObjects, amount, minAmountOut = 0) => {
61
- const tx = await this.initOracleTxb(Object.keys(this.consts.pythFeeder.feeder));
62
- const zlpCoinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, 'zlp', zlpCoinObjects);
63
- const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
64
- const { vaultsValuation, symbolsValuation, } = this.valuate(tx);
65
- tx.moveCall({
66
- target: `${this.consts.zoCore.package}::market::withdraw`,
67
- typeArguments: [
68
- `${this.consts.zoCore.package}::zlp::ZLP`,
69
- this.consts.coins[coin].module,
70
- ],
71
- arguments: [
72
- tx.object(this.consts.zoCore.market),
73
- tx.object(this.consts.zoCore.rebaseFeeModel),
74
- withdrawObject,
75
- tx.pure.u64(minAmountOut),
76
- vaultsValuation,
77
- symbolsValuation,
78
- ],
79
- });
80
- return tx;
34
+ const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, coin, coinObjects);
35
+ const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
36
+ const { vaultsValuation, symbolsValuation, } = this.valuate(tx);
37
+ tx.moveCall({
38
+ target: `${this.consts.zoCore.package}::market::deposit`,
39
+ typeArguments: [
40
+ `${this.consts.zoCore.package}::zlp::ZLP`,
41
+ this.consts.coins[coin].module,
42
+ ],
43
+ arguments: [
44
+ tx.object(this.consts.zoCore.market),
45
+ tx.object(this.consts.zoCore.rebaseFeeModel),
46
+ depositObject,
47
+ tx.pure.u64(minAmountOut),
48
+ vaultsValuation,
49
+ symbolsValuation,
50
+ ],
51
+ });
52
+ return tx;
53
+ };
54
+ this.withdraw = async (coin, zlpCoinObjects, amount, minAmountOut = 0) => {
55
+ const tx = await this.initOracleTxb(Object.keys(this.consts.pythFeeder.feeder));
56
+ const zlpCoinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, 'zlp', zlpCoinObjects);
57
+ const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
58
+ const { vaultsValuation, symbolsValuation, } = this.valuate(tx);
59
+ tx.moveCall({
60
+ target: `${this.consts.zoCore.package}::market::withdraw`,
61
+ typeArguments: [
62
+ `${this.consts.zoCore.package}::zlp::ZLP`,
63
+ this.consts.coins[coin].module,
64
+ ],
65
+ arguments: [
66
+ tx.object(this.consts.zoCore.market),
67
+ tx.object(this.consts.zoCore.rebaseFeeModel),
68
+ withdrawObject,
69
+ tx.pure.u64(minAmountOut),
70
+ vaultsValuation,
71
+ symbolsValuation,
72
+ ],
73
+ });
74
+ return tx;
75
+ };
76
+ this.openPosition = async (collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, slippage = 0.003, isLimitOrder = false, isIocOrder = false, relayerFee = BigInt(1), referralAddress = '', sender = '') => {
77
+ let tx = new transactions_1.Transaction();
78
+ if (referralAddress && !await this.hasReferral(sender || '')) {
79
+ tx = await this.addReferral(referralAddress, tx);
81
80
  }
82
- });
83
- Object.defineProperty(this, "openPosition", {
84
- enumerable: true,
85
- configurable: true,
86
- writable: true,
87
- value: async (collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, slippage = 0.003, isLimitOrder = false, isIocOrder = false, relayerFee = BigInt(1), referralAddress = '', sender = '') => {
88
- let tx = new transactions_1.Transaction();
89
- if (referralAddress && !await this.hasReferral(sender || '')) {
90
- tx = await this.addReferral(referralAddress, tx);
91
- }
92
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
93
- const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, collateralToken, coinObjects);
94
- const [depositObject, feeObject] = tx.splitCoins(coinObject, [
95
- tx.pure.u64(collateralAmount),
96
- tx.pure.u64(relayerFee)
97
- ]);
98
- const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
99
- const adjustPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, indexPrice, long, isLimitOrder ? 0 : slippage);
100
- const adjustCollateralPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, collateralPrice, false, 0.5);
101
- let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
102
- if (isLimitOrder) {
103
- allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
104
- }
105
- tx.moveCall({
106
- target: `${this.consts.zoCore.package}::market::open_position`,
107
- typeArguments: [
108
- `${this.consts.zoCore.package}::zlp::ZLP`,
109
- this.consts.coins[collateralToken].module,
110
- this.consts.coins[indexToken].module,
111
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
112
- this.consts.coins[collateralToken].module,
113
- ],
114
- arguments: [
115
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
116
- tx.object(this.consts.zoCore.market),
117
- tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
118
- tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
119
- tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
120
- tx.object(this.consts.pythFeeder.feeder[collateralToken]),
121
- tx.object(this.consts.pythFeeder.feeder[indexToken]),
122
- depositObject,
123
- feeObject,
124
- tx.pure.u8(allowTrade),
125
- tx.pure.u64(size),
126
- tx.pure.u64(reserveAmount),
127
- tx.pure.u256(adjustCollateralPrice),
128
- tx.pure.u256(adjustPrice),
129
- ],
130
- });
131
- return tx;
81
+ tx = await this.initOracleTxb([collateralToken, indexToken], tx);
82
+ const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, collateralToken, coinObjects);
83
+ const [depositObject, feeObject] = tx.splitCoins(coinObject, [
84
+ tx.pure.u64(collateralAmount),
85
+ tx.pure.u64(relayerFee)
86
+ ]);
87
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
88
+ const adjustPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, indexPrice, long, isLimitOrder ? 0 : slippage);
89
+ const adjustCollateralPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, collateralPrice, false, 0.5);
90
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
91
+ if (isLimitOrder) {
92
+ allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
132
93
  }
133
- });
134
- Object.defineProperty(this, "pledgeInPosition", {
135
- enumerable: true,
136
- configurable: true,
137
- writable: true,
138
- value: async (pcpId, collateralToken, indexToken, amount, coinObjects, long) => {
139
- const tx = await this.initOracleTxb([collateralToken, indexToken]);
140
- const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, collateralToken, coinObjects);
141
- const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
142
- tx.moveCall({
143
- target: `${this.consts.zoCore.package}::market::pledge_in_position`,
144
- typeArguments: [
145
- `${this.consts.zoCore.package}::zlp::ZLP`,
146
- this.consts.coins[collateralToken].module,
147
- this.consts.coins[indexToken].module,
148
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
149
- ],
150
- arguments: [
151
- tx.object(this.consts.zoCore.market),
152
- tx.object(pcpId),
153
- depositObject,
154
- ],
155
- });
156
- return tx;
94
+ tx.moveCall({
95
+ target: `${this.consts.zoCore.package}::market::open_position`,
96
+ typeArguments: [
97
+ `${this.consts.zoCore.package}::zlp::ZLP`,
98
+ this.consts.coins[collateralToken].module,
99
+ this.consts.coins[indexToken].module,
100
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
101
+ this.consts.coins[collateralToken].module,
102
+ ],
103
+ arguments: [
104
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
105
+ tx.object(this.consts.zoCore.market),
106
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
107
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
108
+ tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
109
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
110
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
111
+ depositObject,
112
+ feeObject,
113
+ tx.pure.u8(allowTrade),
114
+ tx.pure.u64(size),
115
+ tx.pure.u64(reserveAmount),
116
+ tx.pure.u256(adjustCollateralPrice),
117
+ tx.pure.u256(adjustPrice),
118
+ ],
119
+ });
120
+ return tx;
121
+ };
122
+ this.pledgeInPosition = async (pcpId, collateralToken, indexToken, amount, coinObjects, long) => {
123
+ const tx = await this.initOracleTxb([collateralToken, indexToken]);
124
+ const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, collateralToken, coinObjects);
125
+ const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
126
+ tx.moveCall({
127
+ target: `${this.consts.zoCore.package}::market::pledge_in_position`,
128
+ typeArguments: [
129
+ `${this.consts.zoCore.package}::zlp::ZLP`,
130
+ this.consts.coins[collateralToken].module,
131
+ this.consts.coins[indexToken].module,
132
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
133
+ ],
134
+ arguments: [
135
+ tx.object(this.consts.zoCore.market),
136
+ tx.object(pcpId),
137
+ depositObject,
138
+ ],
139
+ });
140
+ return tx;
141
+ };
142
+ this.redeemFromPosition = async (pcpId, collateralToken, indexToken, amount, long) => {
143
+ const tx = await this.initOracleTxb([collateralToken, indexToken]);
144
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
145
+ tx.moveCall({
146
+ target: `${this.consts.zoCore.package}::market::redeem_from_position`,
147
+ typeArguments: [
148
+ `${this.consts.zoCore.package}::zlp::ZLP`,
149
+ this.consts.coins[collateralToken].module,
150
+ this.consts.coins[indexToken].module,
151
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
152
+ ],
153
+ arguments: [
154
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
155
+ tx.object(this.consts.zoCore.market),
156
+ tx.object(pcpId),
157
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
158
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
159
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
160
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
161
+ tx.pure.u64(amount),
162
+ ],
163
+ });
164
+ return tx;
165
+ };
166
+ this.decreasePosition = async (pcpId, collateralToken, coinObjects, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, slippage = 0.003, relayerFee = BigInt(1)) => {
167
+ const tx = await this.initOracleTxb([collateralToken, indexToken]);
168
+ const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
169
+ const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, collateralToken, coinObjects);
170
+ const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)]);
171
+ const adjustPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, indexPrice, !long, isTriggerOrder ? 0 : slippage);
172
+ const adjustCollateralPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, collateralPrice, false, 0.5);
173
+ let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
174
+ if (isTriggerOrder) {
175
+ allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
157
176
  }
158
- });
159
- Object.defineProperty(this, "redeemFromPosition", {
160
- enumerable: true,
161
- configurable: true,
162
- writable: true,
163
- value: async (pcpId, collateralToken, indexToken, amount, long) => {
164
- const tx = await this.initOracleTxb([collateralToken, indexToken]);
165
- const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
166
- tx.moveCall({
167
- target: `${this.consts.zoCore.package}::market::redeem_from_position`,
168
- typeArguments: [
169
- `${this.consts.zoCore.package}::zlp::ZLP`,
170
- this.consts.coins[collateralToken].module,
171
- this.consts.coins[indexToken].module,
172
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
173
- ],
174
- arguments: [
175
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
176
- tx.object(this.consts.zoCore.market),
177
- tx.object(pcpId),
178
- tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
179
- tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
180
- tx.object(this.consts.pythFeeder.feeder[collateralToken]),
181
- tx.object(this.consts.pythFeeder.feeder[indexToken]),
182
- tx.pure.u64(amount),
183
- ],
184
- });
185
- return tx;
177
+ else {
178
+ isTakeProfitOrder = true;
186
179
  }
187
- });
188
- Object.defineProperty(this, "decreasePosition", {
189
- enumerable: true,
190
- configurable: true,
191
- writable: true,
192
- value: async (pcpId, collateralToken, coinObjects, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, slippage = 0.003, relayerFee = BigInt(1)) => {
193
- const tx = await this.initOracleTxb([collateralToken, indexToken]);
194
- const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
195
- const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, collateralToken, coinObjects);
196
- const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)]);
197
- const adjustPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, indexPrice, !long, isTriggerOrder ? 0 : slippage);
198
- const adjustCollateralPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, collateralPrice, false, 0.5);
199
- let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
200
- if (isTriggerOrder) {
201
- allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
180
+ /* console.log('isTriggerOrder:', isTriggerOrder)
181
+ console.log('isIocOrder:', isIocOrder)
182
+ console.log('isTakeProfitOrder:', isTakeProfitOrder)
183
+ console.log('adjustPrice:', adjustPrice)
184
+ console.log('allowTrade:', allowTrade)
185
+ console.log('isTriggerOrder:', isTriggerOrder)
186
+ console.log('isTakeProfitOrder:', isTakeProfitOrder) */
187
+ tx.moveCall({
188
+ target: `${this.consts.zoCore.package}::market::decrease_position`,
189
+ typeArguments: [
190
+ `${this.consts.zoCore.package}::zlp::ZLP`,
191
+ this.consts.coins[collateralToken].module,
192
+ this.consts.coins[indexToken].module,
193
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
194
+ this.consts.coins[collateralToken].module,
195
+ ],
196
+ arguments: [
197
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
198
+ tx.object(this.consts.zoCore.market),
199
+ tx.object(pcpId),
200
+ tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
201
+ tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
202
+ tx.object(this.consts.pythFeeder.feeder[collateralToken]),
203
+ tx.object(this.consts.pythFeeder.feeder[indexToken]),
204
+ feeObject,
205
+ tx.pure.u8(allowTrade),
206
+ tx.pure.bool(isTakeProfitOrder),
207
+ tx.pure.u64(amount),
208
+ tx.pure.u256(adjustCollateralPrice),
209
+ tx.pure.u256(adjustPrice),
210
+ ],
211
+ });
212
+ return tx;
213
+ };
214
+ this.cancelOrder = (orderCapId, collateralToken, indexToken, long, type, isV11Order = false) => {
215
+ const tx = new transactions_1.Transaction();
216
+ let functionName = '';
217
+ switch (type) {
218
+ case 'OPEN_POSITION': {
219
+ functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
220
+ break;
202
221
  }
203
- else {
204
- isTakeProfitOrder = true;
222
+ case 'DECREASE_POSITION': {
223
+ functionName = isV11Order ? 'clear_decrease_position_order' : 'clear_decrease_position_order';
224
+ break;
205
225
  }
206
- /* console.log('isTriggerOrder:', isTriggerOrder)
207
- console.log('isIocOrder:', isIocOrder)
208
- console.log('isTakeProfitOrder:', isTakeProfitOrder)
209
- console.log('adjustPrice:', adjustPrice)
210
- console.log('allowTrade:', allowTrade)
211
- console.log('isTriggerOrder:', isTriggerOrder)
212
- console.log('isTakeProfitOrder:', isTakeProfitOrder) */
213
- tx.moveCall({
214
- target: `${this.consts.zoCore.package}::market::decrease_position`,
215
- typeArguments: [
216
- `${this.consts.zoCore.package}::zlp::ZLP`,
217
- this.consts.coins[collateralToken].module,
218
- this.consts.coins[indexToken].module,
219
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
220
- this.consts.coins[collateralToken].module,
221
- ],
222
- arguments: [
223
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
224
- tx.object(this.consts.zoCore.market),
225
- tx.object(pcpId),
226
- tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
227
- tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
228
- tx.object(this.consts.pythFeeder.feeder[collateralToken]),
229
- tx.object(this.consts.pythFeeder.feeder[indexToken]),
230
- feeObject,
231
- tx.pure.u8(allowTrade),
232
- tx.pure.bool(isTakeProfitOrder),
233
- tx.pure.u64(amount),
234
- tx.pure.u256(adjustCollateralPrice),
235
- tx.pure.u256(adjustPrice),
236
- ],
237
- });
238
- return tx;
239
- }
240
- });
241
- Object.defineProperty(this, "cancelOrder", {
242
- enumerable: true,
243
- configurable: true,
244
- writable: true,
245
- value: (orderCapId, collateralToken, indexToken, long, type, isV11Order = false) => {
246
- const tx = new transactions_1.Transaction();
247
- let functionName = '';
248
- switch (type) {
249
- case 'OPEN_POSITION': {
250
- functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
251
- break;
252
- }
253
- case 'DECREASE_POSITION': {
254
- functionName = isV11Order ? 'clear_decrease_position_order' : 'clear_decrease_position_order';
255
- break;
256
- }
257
- default: {
258
- throw new Error('invalid order type');
259
- }
226
+ default: {
227
+ throw new Error('invalid order type');
260
228
  }
261
- tx.moveCall({
262
- target: `${this.consts.zoCore.package}::market::${functionName}`,
263
- typeArguments: [
264
- `${this.consts.zoCore.package}::zlp::ZLP`,
265
- this.consts.coins[collateralToken].module,
266
- this.consts.coins[indexToken].module,
267
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
268
- this.consts.coins[collateralToken].module,
269
- ],
270
- arguments: [
271
- tx.object(this.consts.zoCore.market),
272
- tx.object(orderCapId),
273
- ],
274
- });
275
- return tx;
276
229
  }
277
- });
278
- Object.defineProperty(this, "swap", {
279
- enumerable: true,
280
- configurable: true,
281
- writable: true,
282
- value: async (fromToken, toToken, fromAmount, fromCoinObjects) => {
283
- const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
284
- const fromCoinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, fromToken, fromCoinObjects);
285
- const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)]);
286
- const vaultsValuation = this.valuateVaults(tx);
287
- tx.moveCall({
288
- target: `${this.consts.zoCore.package}::market::swap`,
289
- typeArguments: [
290
- `${this.consts.zoCore.package}::zlp::ZLP`,
291
- this.consts.coins[fromToken].module,
292
- this.consts.coins[toToken].module,
293
- ],
294
- arguments: [
295
- tx.object(this.consts.zoCore.market),
296
- tx.object(this.consts.zoCore.rebaseFeeModel),
297
- fromDepositObject,
298
- // FIXME: minAmountOut
299
- tx.pure.u64(0),
300
- vaultsValuation,
301
- ],
302
- });
303
- return tx;
230
+ tx.moveCall({
231
+ target: `${this.consts.zoCore.package}::market::${functionName}`,
232
+ typeArguments: [
233
+ `${this.consts.zoCore.package}::zlp::ZLP`,
234
+ this.consts.coins[collateralToken].module,
235
+ this.consts.coins[indexToken].module,
236
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
237
+ this.consts.coins[collateralToken].module,
238
+ ],
239
+ arguments: [
240
+ tx.object(this.consts.zoCore.market),
241
+ tx.object(orderCapId),
242
+ ],
243
+ });
244
+ return tx;
245
+ };
246
+ this.swap = async (fromToken, toToken, fromAmount, fromCoinObjects) => {
247
+ const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
248
+ const fromCoinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, fromToken, fromCoinObjects);
249
+ const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)]);
250
+ const vaultsValuation = this.valuateVaults(tx);
251
+ tx.moveCall({
252
+ target: `${this.consts.zoCore.package}::market::swap`,
253
+ typeArguments: [
254
+ `${this.consts.zoCore.package}::zlp::ZLP`,
255
+ this.consts.coins[fromToken].module,
256
+ this.consts.coins[toToken].module,
257
+ ],
258
+ arguments: [
259
+ tx.object(this.consts.zoCore.market),
260
+ tx.object(this.consts.zoCore.rebaseFeeModel),
261
+ fromDepositObject,
262
+ // FIXME: minAmountOut
263
+ tx.pure.u64(0),
264
+ vaultsValuation,
265
+ ],
266
+ });
267
+ return tx;
268
+ };
269
+ this.clearClosedPosition = (pcpId, collateralToken, indexToken, long, tx) => {
270
+ tx.moveCall({
271
+ target: `${this.consts.zoCore.package}::market::clear_closed_position`,
272
+ typeArguments: [
273
+ `${this.consts.zoCore.package}::zlp::ZLP`,
274
+ this.consts.coins[collateralToken].module,
275
+ this.consts.coins[indexToken].module,
276
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
277
+ ],
278
+ arguments: [
279
+ tx.object(this.consts.zoCore.market),
280
+ tx.object(pcpId),
281
+ ],
282
+ });
283
+ };
284
+ this.clearOpenPositionOrder = (orderCapId, collateralToken, indexToken, long, tx, isV11Order = false) => {
285
+ const funcName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
286
+ tx.moveCall({
287
+ target: `${this.consts.zoCore.package}::market::${funcName}`,
288
+ typeArguments: [
289
+ `${this.consts.zoCore.package}::zlp::ZLP`,
290
+ this.consts.coins[collateralToken].module,
291
+ this.consts.coins[indexToken].module,
292
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
293
+ this.consts.coins[collateralToken].module,
294
+ ],
295
+ arguments: [
296
+ tx.object(this.consts.zoCore.market),
297
+ tx.object(orderCapId),
298
+ ],
299
+ });
300
+ };
301
+ this.clearDecreasePositionOrder = (orderCapId, collateralToken, indexToken, long, tx, isV11Order = false) => {
302
+ const funcName = isV11Order ? 'clear_decrease_position_order' : 'clear_decrease_position_order';
303
+ tx.moveCall({
304
+ target: `${this.consts.zoCore.package}::market::${funcName}`,
305
+ typeArguments: [
306
+ `${this.consts.zoCore.package}::zlp::ZLP`,
307
+ this.consts.coins[collateralToken].module,
308
+ this.consts.coins[indexToken].module,
309
+ `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
310
+ this.consts.coins[collateralToken].module,
311
+ ],
312
+ arguments: [
313
+ tx.object(this.consts.zoCore.market),
314
+ tx.object(orderCapId),
315
+ ],
316
+ });
317
+ };
318
+ this.stake = (coinObjects, amount, pool, tx) => {
319
+ if (!tx) {
320
+ tx = new transactions_1.Transaction();
304
321
  }
305
- });
306
- Object.defineProperty(this, "clearClosedPosition", {
307
- enumerable: true,
308
- configurable: true,
309
- writable: true,
310
- value: (pcpId, collateralToken, indexToken, long, tx) => {
311
- tx.moveCall({
312
- target: `${this.consts.zoCore.package}::market::clear_closed_position`,
313
- typeArguments: [
314
- `${this.consts.zoCore.package}::zlp::ZLP`,
315
- this.consts.coins[collateralToken].module,
316
- this.consts.coins[indexToken].module,
317
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
318
- ],
319
- arguments: [
320
- tx.object(this.consts.zoCore.market),
321
- tx.object(pcpId),
322
- ],
323
- });
322
+ const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, 'zlp', coinObjects);
323
+ const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
324
+ tx.moveCall({
325
+ target: `${this.consts.zoStaking.package}::pool::deposit`,
326
+ typeArguments: [
327
+ `${this.consts.zoCore.package}::zlp::ZLP`,
328
+ this.consts.coins.sui.module,
329
+ ],
330
+ arguments: [
331
+ tx.object(pool),
332
+ tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
333
+ depositObject,
334
+ ],
335
+ });
336
+ return tx;
337
+ };
338
+ this.unstake = (credentials, amount, pool, tx) => {
339
+ if (!tx) {
340
+ tx = new transactions_1.Transaction();
324
341
  }
325
- });
326
- Object.defineProperty(this, "clearOpenPositionOrder", {
327
- enumerable: true,
328
- configurable: true,
329
- writable: true,
330
- value: (orderCapId, collateralToken, indexToken, long, tx, isV11Order = false) => {
331
- const funcName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
342
+ for (const credential of credentials) {
343
+ // eslint-disable-next-line unicorn/prefer-math-min-max
344
+ const withdrawAmount = amount < credential.amount ? amount : credential.amount;
345
+ amount -= withdrawAmount;
332
346
  tx.moveCall({
333
- target: `${this.consts.zoCore.package}::market::${funcName}`,
334
- typeArguments: [
335
- `${this.consts.zoCore.package}::zlp::ZLP`,
336
- this.consts.coins[collateralToken].module,
337
- this.consts.coins[indexToken].module,
338
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
339
- this.consts.coins[collateralToken].module,
340
- ],
341
- arguments: [
342
- tx.object(this.consts.zoCore.market),
343
- tx.object(orderCapId),
344
- ],
345
- });
346
- }
347
- });
348
- Object.defineProperty(this, "clearDecreasePositionOrder", {
349
- enumerable: true,
350
- configurable: true,
351
- writable: true,
352
- value: (orderCapId, collateralToken, indexToken, long, tx, isV11Order = false) => {
353
- const funcName = isV11Order ? 'clear_decrease_position_order' : 'clear_decrease_position_order';
354
- tx.moveCall({
355
- target: `${this.consts.zoCore.package}::market::${funcName}`,
356
- typeArguments: [
357
- `${this.consts.zoCore.package}::zlp::ZLP`,
358
- this.consts.coins[collateralToken].module,
359
- this.consts.coins[indexToken].module,
360
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
361
- this.consts.coins[collateralToken].module,
362
- ],
363
- arguments: [
364
- tx.object(this.consts.zoCore.market),
365
- tx.object(orderCapId),
366
- ],
367
- });
368
- }
369
- });
370
- Object.defineProperty(this, "stake", {
371
- enumerable: true,
372
- configurable: true,
373
- writable: true,
374
- value: (coinObjects, amount, pool, tx) => {
375
- if (!tx) {
376
- tx = new transactions_1.Transaction();
377
- }
378
- const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, 'zlp', coinObjects);
379
- const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
380
- tx.moveCall({
381
- target: `${this.consts.zoStaking.package}::pool::deposit`,
347
+ target: `0xdb353cb79a88d5ee83b7c0ca0249662a1facab17ba62879080ea3d61b9d21112::pool::withdraw`,
382
348
  typeArguments: [
383
349
  `${this.consts.zoCore.package}::zlp::ZLP`,
384
350
  this.consts.coins.sui.module,
@@ -386,74 +352,41 @@ class API extends data_1.DataAPI {
386
352
  arguments: [
387
353
  tx.object(pool),
388
354
  tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
389
- depositObject,
355
+ tx.object(credential.id),
356
+ tx.pure.u64(withdrawAmount),
390
357
  ],
391
358
  });
392
- return tx;
393
- }
394
- });
395
- Object.defineProperty(this, "unstake", {
396
- enumerable: true,
397
- configurable: true,
398
- writable: true,
399
- value: (credentials, amount, pool, tx) => {
400
- if (!tx) {
401
- tx = new transactions_1.Transaction();
402
- }
403
- for (const credential of credentials) {
404
- // eslint-disable-next-line unicorn/prefer-math-min-max
405
- const withdrawAmount = amount < credential.amount ? amount : credential.amount;
406
- amount -= withdrawAmount;
359
+ if (credential.amount === BigInt(0)) {
407
360
  tx.moveCall({
408
- target: `0xdb353cb79a88d5ee83b7c0ca0249662a1facab17ba62879080ea3d61b9d21112::pool::withdraw`,
361
+ target: `${this.consts.zoStaking.package}::pool::clear_empty_credential`,
409
362
  typeArguments: [
410
363
  `${this.consts.zoCore.package}::zlp::ZLP`,
411
364
  this.consts.coins.sui.module,
412
365
  ],
413
366
  arguments: [
414
- tx.object(pool),
415
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
416
367
  tx.object(credential.id),
417
- tx.pure.u64(withdrawAmount),
418
368
  ],
419
369
  });
420
- if (credential.amount === BigInt(0)) {
421
- tx.moveCall({
422
- target: `${this.consts.zoStaking.package}::pool::clear_empty_credential`,
423
- typeArguments: [
424
- `${this.consts.zoCore.package}::zlp::ZLP`,
425
- this.consts.coins.sui.module,
426
- ],
427
- arguments: [
428
- tx.object(credential.id),
429
- ],
430
- });
431
- }
432
370
  }
433
- return tx;
434
371
  }
435
- });
436
- Object.defineProperty(this, "addReferral", {
437
- enumerable: true,
438
- configurable: true,
439
- writable: true,
440
- value: (referrer, tx) => {
441
- if (!tx) {
442
- tx = new transactions_1.Transaction();
443
- }
444
- tx.moveCall({
445
- target: `${this.consts.zoCore.package}::market::add_new_referral`,
446
- typeArguments: [
447
- `${this.consts.zoCore.package}::zlp::ZLP`,
448
- ],
449
- arguments: [
450
- tx.object(this.consts.zoCore.market),
451
- tx.object(referrer),
452
- ],
453
- });
454
- return tx;
372
+ return tx;
373
+ };
374
+ this.addReferral = (referrer, tx) => {
375
+ if (!tx) {
376
+ tx = new transactions_1.Transaction();
455
377
  }
456
- });
378
+ tx.moveCall({
379
+ target: `${this.consts.zoCore.package}::market::add_new_referral`,
380
+ typeArguments: [
381
+ `${this.consts.zoCore.package}::zlp::ZLP`,
382
+ ],
383
+ arguments: [
384
+ tx.object(this.consts.zoCore.market),
385
+ tx.object(referrer),
386
+ ],
387
+ });
388
+ return tx;
389
+ };
457
390
  }
458
391
  static getInstance(network, provider, apiEndpoint, connectionURL) {
459
392
  if (!API.instance) {
@@ -467,3 +400,4 @@ _API_processCoins = new WeakMap(), _API_instances = new WeakSet(), _API_processS
467
400
  const raw = long ? (indexPrice * (1 + slippage)) : (indexPrice * (1 - slippage));
468
401
  return BigInt(Math.round(raw * 1e18));
469
402
  };
403
+ //# sourceMappingURL=api.cjs.map