@zofai/zo-sdk 0.2.9 → 0.2.11
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/abstract/BaseAPI.cjs +7 -1
- package/dist/abstract/BaseAPI.cjs.map +1 -1
- package/dist/abstract/BaseAPI.d.cts +11 -10
- package/dist/abstract/BaseAPI.d.cts.map +1 -1
- package/dist/abstract/BaseAPI.d.mts +11 -10
- package/dist/abstract/BaseAPI.d.mts.map +1 -1
- package/dist/abstract/BaseAPI.mjs +7 -1
- package/dist/abstract/BaseAPI.mjs.map +1 -1
- package/dist/abstract/BaseDataAPI.d.cts +1 -1
- package/dist/abstract/BaseDataAPI.d.cts.map +1 -1
- package/dist/abstract/BaseDataAPI.d.mts +1 -1
- package/dist/abstract/BaseDataAPI.d.mts.map +1 -1
- package/dist/api.cjs +12 -12
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +1 -1
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.mts +1 -1
- package/dist/api.d.mts.map +1 -1
- package/dist/api.mjs +12 -12
- package/dist/api.mjs.map +1 -1
- package/dist/bcs.d.cts +41 -71
- package/dist/bcs.d.cts.map +1 -1
- package/dist/bcs.d.mts +41 -71
- package/dist/bcs.d.mts.map +1 -1
- package/dist/coins.cjs +74 -0
- package/dist/coins.cjs.map +1 -0
- package/dist/coins.d.cts +37 -0
- package/dist/coins.d.cts.map +1 -0
- package/dist/coins.d.mts +37 -0
- package/dist/coins.d.mts.map +1 -0
- package/dist/coins.mjs +67 -0
- package/dist/coins.mjs.map +1 -0
- package/dist/data.d.cts +6 -6
- package/dist/data.d.cts.map +1 -1
- package/dist/data.d.mts +6 -6
- package/dist/data.d.mts.map +1 -1
- package/dist/factory/SDKFactory.d.cts +1 -1
- package/dist/factory/SDKFactory.d.cts.map +1 -1
- package/dist/factory/SDKFactory.d.mts +1 -1
- package/dist/factory/SDKFactory.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.cjs +192 -100
- package/dist/implementations/SLPAPI.cjs.map +1 -1
- package/dist/implementations/SLPAPI.d.cts +24 -24
- package/dist/implementations/SLPAPI.d.cts.map +1 -1
- package/dist/implementations/SLPAPI.d.mts +24 -24
- package/dist/implementations/SLPAPI.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.mjs +192 -100
- package/dist/implementations/SLPAPI.mjs.map +1 -1
- package/dist/implementations/SLPDataAPI.cjs +2 -2
- package/dist/implementations/SLPDataAPI.cjs.map +1 -1
- package/dist/implementations/SLPDataAPI.d.cts +5 -5
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/SLPDataAPI.d.mts +5 -5
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/SLPDataAPI.mjs +2 -2
- package/dist/implementations/SLPDataAPI.mjs.map +1 -1
- package/dist/implementations/USDZAPI.cjs +176 -92
- package/dist/implementations/USDZAPI.cjs.map +1 -1
- package/dist/implementations/USDZAPI.d.cts +22 -22
- package/dist/implementations/USDZAPI.d.cts.map +1 -1
- package/dist/implementations/USDZAPI.d.mts +22 -22
- package/dist/implementations/USDZAPI.d.mts.map +1 -1
- package/dist/implementations/USDZAPI.mjs +176 -92
- package/dist/implementations/USDZAPI.mjs.map +1 -1
- package/dist/implementations/USDZDataAPI.d.cts +5 -5
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
- package/dist/implementations/USDZDataAPI.d.mts +5 -5
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.cjs +84 -46
- package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.cts +12 -12
- package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.mts +12 -12
- package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.mjs +84 -46
- package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.cts +5 -5
- package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.mts +5 -5
- package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -1
- package/dist/implementations/ZLPAPI.cjs +192 -100
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +24 -24
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +24 -24
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +192 -100
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.cts +5 -5
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.mts +5 -5
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +26 -22
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +26 -22
- package/dist/interfaces/base.d.mts.map +1 -1
- package/dist/interfaces/slp.d.cts +1 -1
- package/dist/interfaces/slp.d.cts.map +1 -1
- package/dist/interfaces/slp.d.mts +1 -1
- package/dist/interfaces/slp.d.mts.map +1 -1
- package/dist/interfaces/usdz.d.cts +1 -1
- package/dist/interfaces/usdz.d.cts.map +1 -1
- package/dist/interfaces/usdz.d.mts +1 -1
- package/dist/interfaces/usdz.d.mts.map +1 -1
- package/dist/interfaces/zbtcvc.d.cts +1 -1
- package/dist/interfaces/zbtcvc.d.cts.map +1 -1
- package/dist/interfaces/zbtcvc.d.mts +1 -1
- package/dist/interfaces/zbtcvc.d.mts.map +1 -1
- package/dist/interfaces/zlp.d.cts +1 -1
- package/dist/interfaces/zlp.d.cts.map +1 -1
- package/dist/interfaces/zlp.d.mts +1 -1
- package/dist/interfaces/zlp.d.mts.map +1 -1
- package/dist/oracle.cjs +27 -22
- package/dist/oracle.cjs.map +1 -1
- package/dist/oracle.d.cts +14 -2
- package/dist/oracle.d.cts.map +1 -1
- package/dist/oracle.d.mts +14 -2
- package/dist/oracle.d.mts.map +1 -1
- package/dist/oracle.mjs +27 -22
- package/dist/oracle.mjs.map +1 -1
- package/dist/suiClient.cjs +8 -0
- package/dist/suiClient.cjs.map +1 -0
- package/dist/suiClient.d.cts +8 -0
- package/dist/suiClient.d.cts.map +1 -0
- package/dist/suiClient.d.mts +8 -0
- package/dist/suiClient.d.mts.map +1 -0
- package/dist/suiClient.mjs +2 -0
- package/dist/suiClient.mjs.map +1 -0
- package/dist/utils.cjs +7 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +2 -2
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +7 -3
- package/dist/utils.mjs.map +1 -1
- package/package.json +4 -4
- package/src/abstract/BaseAPI.ts +11 -9
- package/src/abstract/BaseDataAPI.ts +1 -1
- package/src/api.ts +13 -17
- package/src/coins.ts +116 -0
- package/src/data.ts +1 -1
- package/src/factory/SDKFactory.ts +1 -1
- package/src/implementations/SLPAPI.ts +200 -116
- package/src/implementations/SLPDataAPI.ts +3 -3
- package/src/implementations/USDZAPI.ts +185 -95
- package/src/implementations/USDZDataAPI.ts +1 -1
- package/src/implementations/ZBTCVCAPI.ts +99 -53
- package/src/implementations/ZBTCVCDataAPI.ts +1 -1
- package/src/implementations/ZLPAPI.ts +200 -111
- package/src/implementations/ZLPDataAPI.ts +1 -1
- package/src/index.ts +3 -1
- package/src/interfaces/base.ts +14 -22
- package/src/interfaces/slp.ts +0 -1
- package/src/interfaces/usdz.ts +0 -1
- package/src/interfaces/zbtcvc.ts +0 -1
- package/src/interfaces/zlp.ts +0 -1
- package/src/oracle.ts +70 -30
- package/src/suiClient.ts +11 -0
- package/src/utils.ts +9 -3
- package/tsconfig.json +8 -1
|
@@ -26,7 +26,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
26
26
|
/**
|
|
27
27
|
* Deposits collateral into SLP vault using Sudo SDK approach
|
|
28
28
|
*/
|
|
29
|
-
async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx
|
|
29
|
+
async deposit(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, sponsoredTx) {
|
|
30
30
|
let tx = new transactions_1.Transaction();
|
|
31
31
|
// Add referral if needed
|
|
32
32
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
@@ -36,8 +36,12 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
36
36
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
37
37
|
// Handle sponsored transaction case
|
|
38
38
|
if (sponsoredTx) {
|
|
39
|
-
const
|
|
40
|
-
|
|
39
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
40
|
+
sender: this.requireSenderForSponsored(sender),
|
|
41
|
+
additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
|
|
42
|
+
});
|
|
43
|
+
tx = oracle.tx;
|
|
44
|
+
const { suiCoinObject } = oracle;
|
|
41
45
|
// Process deposit coins
|
|
42
46
|
const depositObject = coin === 'sui'
|
|
43
47
|
? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
|
|
@@ -61,7 +65,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
61
65
|
return tx;
|
|
62
66
|
}
|
|
63
67
|
// Handle non-sponsored transaction case
|
|
64
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
68
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
65
69
|
const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
|
|
66
70
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
67
71
|
tx.moveCall({
|
|
@@ -84,7 +88,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
84
88
|
/**
|
|
85
89
|
* Deposits collateral into SLP vault and returns a coin
|
|
86
90
|
*/
|
|
87
|
-
async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx
|
|
91
|
+
async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
|
|
88
92
|
if (!tx) {
|
|
89
93
|
tx = new transactions_1.Transaction();
|
|
90
94
|
}
|
|
@@ -96,8 +100,12 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
96
100
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
97
101
|
// Handle sponsored transaction case
|
|
98
102
|
if (sponsoredTx) {
|
|
99
|
-
const
|
|
100
|
-
|
|
103
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
104
|
+
sender: this.requireSenderForSponsored(sender),
|
|
105
|
+
additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
|
|
106
|
+
});
|
|
107
|
+
tx = oracle.tx;
|
|
108
|
+
const { suiCoinObject } = oracle;
|
|
101
109
|
// Process deposit coins
|
|
102
110
|
const depositObject = coin === 'sui'
|
|
103
111
|
? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
|
|
@@ -118,7 +126,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
118
126
|
return mintedCoin;
|
|
119
127
|
}
|
|
120
128
|
// Handle non-sponsored transaction case
|
|
121
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
129
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
122
130
|
const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
|
|
123
131
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
124
132
|
const [mintedCoin] = tx.moveCall({
|
|
@@ -141,7 +149,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
141
149
|
/**
|
|
142
150
|
* Deposits collateral pool with PTB deposit object
|
|
143
151
|
*/
|
|
144
|
-
async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx
|
|
152
|
+
async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
|
|
145
153
|
if (!tx) {
|
|
146
154
|
tx = new transactions_1.Transaction();
|
|
147
155
|
}
|
|
@@ -153,8 +161,12 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
153
161
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
154
162
|
// Handle sponsored transaction case
|
|
155
163
|
if (sponsoredTx) {
|
|
156
|
-
const
|
|
157
|
-
|
|
164
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
165
|
+
sender: this.requireSenderForSponsored(sender),
|
|
166
|
+
additionalSuiAmount: 0n,
|
|
167
|
+
});
|
|
168
|
+
tx = oracle.tx;
|
|
169
|
+
const { suiCoinObject } = oracle;
|
|
158
170
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
159
171
|
tx.moveCall({
|
|
160
172
|
target: `${this.consts.sudoCore.upgradedPackage}::market::deposit`,
|
|
@@ -174,7 +186,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
174
186
|
return tx;
|
|
175
187
|
}
|
|
176
188
|
// Handle non-sponsored transaction case
|
|
177
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
189
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
178
190
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
179
191
|
tx.moveCall({
|
|
180
192
|
target: `${this.consts.sudoCore.upgradedPackage}::market::deposit`,
|
|
@@ -196,16 +208,20 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
196
208
|
/**
|
|
197
209
|
* Withdraws collateral from SLP vault using Sudo SDK approach
|
|
198
210
|
*/
|
|
199
|
-
async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx,
|
|
211
|
+
async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, sender) {
|
|
200
212
|
let tx = new transactions_1.Transaction();
|
|
201
213
|
// Initialize oracle transaction
|
|
202
214
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
203
215
|
if (sponsoredTx) {
|
|
204
|
-
const
|
|
205
|
-
|
|
216
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
217
|
+
sender: this.requireSenderForSponsored(sender),
|
|
218
|
+
additionalSuiAmount: 0n,
|
|
219
|
+
});
|
|
220
|
+
tx = oracle.tx;
|
|
221
|
+
const { suiCoinObject } = oracle;
|
|
206
222
|
}
|
|
207
223
|
else {
|
|
208
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
224
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
209
225
|
}
|
|
210
226
|
const slpCoinObject = this.processCoins(tx, 'slp', lpCoinObjects, false);
|
|
211
227
|
const [withdrawObject] = tx.splitCoins(slpCoinObject, [tx.pure.u64(amount)]);
|
|
@@ -236,7 +252,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
236
252
|
}
|
|
237
253
|
// Initialize oracle transaction
|
|
238
254
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
239
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
255
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
240
256
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
241
257
|
tx.moveCall({
|
|
242
258
|
target: `${this.consts.sudoCore.upgradedPackage}::market::withdraw`,
|
|
@@ -255,18 +271,22 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
255
271
|
});
|
|
256
272
|
return tx;
|
|
257
273
|
}
|
|
258
|
-
async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx,
|
|
274
|
+
async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx, sender) {
|
|
259
275
|
if (!tx) {
|
|
260
276
|
tx = new transactions_1.Transaction();
|
|
261
277
|
}
|
|
262
278
|
// Initialize oracle transaction
|
|
263
279
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
264
280
|
if (sponsoredTx) {
|
|
265
|
-
const
|
|
266
|
-
|
|
281
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
282
|
+
sender: this.requireSenderForSponsored(sender),
|
|
283
|
+
additionalSuiAmount: 0n,
|
|
284
|
+
});
|
|
285
|
+
tx = oracle.tx;
|
|
286
|
+
const { suiCoinObject } = oracle;
|
|
267
287
|
}
|
|
268
288
|
else {
|
|
269
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
289
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
270
290
|
}
|
|
271
291
|
const slpCoinObject = this.processCoins(tx, 'slp', lpCoinObjects, false);
|
|
272
292
|
const [withdrawObject] = tx.splitCoins(slpCoinObject, [tx.pure.u64(amount)]);
|
|
@@ -289,7 +309,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
289
309
|
return withdrawCoin;
|
|
290
310
|
}
|
|
291
311
|
async swap(fromToken, toToken, fromAmount, fromCoinObjects, minAmountOut) {
|
|
292
|
-
const tx = await this.initOracleTxb(Object.keys(this.consts.sudoCore.vaults));
|
|
312
|
+
const { tx } = await this.initOracleTxb(Object.keys(this.consts.sudoCore.vaults));
|
|
293
313
|
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
|
|
294
314
|
const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
|
|
295
315
|
tx.pure.u64(fromAmount),
|
|
@@ -323,7 +343,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
323
343
|
if (!tx) {
|
|
324
344
|
tx = new transactions_1.Transaction();
|
|
325
345
|
}
|
|
326
|
-
tx = await this.initOracleTxb(Object.keys(this.consts.sudoCore.vaults), tx);
|
|
346
|
+
tx = (await this.initOracleTxb(Object.keys(this.consts.sudoCore.vaults), tx)).tx;
|
|
327
347
|
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
|
|
328
348
|
const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
|
|
329
349
|
tx.pure.u64(fromAmount),
|
|
@@ -513,7 +533,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
513
533
|
/**
|
|
514
534
|
* Opens a position using Sudo SDK approach
|
|
515
535
|
*/
|
|
516
|
-
async openPosition(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx
|
|
536
|
+
async openPosition(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
517
537
|
let tx = new transactions_1.Transaction();
|
|
518
538
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
519
539
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -528,11 +548,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
528
548
|
// Handle oracle initialization and coin processing
|
|
529
549
|
let suiCoinObject;
|
|
530
550
|
if (sponsoredTx) {
|
|
531
|
-
|
|
532
|
-
|
|
551
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
552
|
+
sender: this.requireSenderForSponsored(sender),
|
|
553
|
+
additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
|
|
554
|
+
});
|
|
555
|
+
tx = oracle.tx;
|
|
556
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
533
557
|
}
|
|
534
558
|
else {
|
|
535
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
559
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
536
560
|
}
|
|
537
561
|
// Process coin splitting
|
|
538
562
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -567,7 +591,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
567
591
|
/**
|
|
568
592
|
* Opens a position using Sudo SDK approach
|
|
569
593
|
*/
|
|
570
|
-
async openPositionWithCoin(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx
|
|
594
|
+
async openPositionWithCoin(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
571
595
|
if (!tx) {
|
|
572
596
|
tx = new transactions_1.Transaction();
|
|
573
597
|
}
|
|
@@ -584,11 +608,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
584
608
|
// Handle oracle initialization and coin processing
|
|
585
609
|
let suiCoinObject;
|
|
586
610
|
if (sponsoredTx) {
|
|
587
|
-
|
|
588
|
-
|
|
611
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
612
|
+
sender: this.requireSenderForSponsored(sender),
|
|
613
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
614
|
+
});
|
|
615
|
+
tx = oracle.tx;
|
|
616
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
589
617
|
}
|
|
590
618
|
else {
|
|
591
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
619
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
592
620
|
}
|
|
593
621
|
// Process coin splitting
|
|
594
622
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -623,7 +651,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
623
651
|
/**
|
|
624
652
|
* Opens a new position in SLP (V2 - uses v3 contract)
|
|
625
653
|
*/
|
|
626
|
-
async openPositionV2(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx
|
|
654
|
+
async openPositionV2(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
627
655
|
let tx = new transactions_1.Transaction();
|
|
628
656
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
629
657
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -639,11 +667,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
639
667
|
// Handle oracle initialization and coin processing
|
|
640
668
|
let suiCoinObject;
|
|
641
669
|
if (sponsoredTx) {
|
|
642
|
-
|
|
643
|
-
|
|
670
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
671
|
+
sender: this.requireSenderForSponsored(sender),
|
|
672
|
+
additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
|
|
673
|
+
});
|
|
674
|
+
tx = oracle.tx;
|
|
675
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
644
676
|
}
|
|
645
677
|
else {
|
|
646
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
678
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
647
679
|
}
|
|
648
680
|
// Process coin splitting
|
|
649
681
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -677,7 +709,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
677
709
|
/**
|
|
678
710
|
* Opens a new position with Coin in SLP (V2 - uses v3 contract)
|
|
679
711
|
*/
|
|
680
|
-
async openPositionWithCoinV2(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx
|
|
712
|
+
async openPositionWithCoinV2(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
681
713
|
if (!tx) {
|
|
682
714
|
tx = new transactions_1.Transaction();
|
|
683
715
|
}
|
|
@@ -695,11 +727,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
695
727
|
// Handle oracle initialization and coin processing
|
|
696
728
|
let suiCoinObject;
|
|
697
729
|
if (sponsoredTx) {
|
|
698
|
-
|
|
699
|
-
|
|
730
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
731
|
+
sender: this.requireSenderForSponsored(sender),
|
|
732
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
733
|
+
});
|
|
734
|
+
tx = oracle.tx;
|
|
735
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
700
736
|
}
|
|
701
737
|
else {
|
|
702
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
738
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
703
739
|
}
|
|
704
740
|
// Process coin splitting
|
|
705
741
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -733,7 +769,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
733
769
|
/**
|
|
734
770
|
* Decreases an existing position in SLP using Sudo SDK approach
|
|
735
771
|
*/
|
|
736
|
-
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, sponsoredTx,
|
|
772
|
+
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, sponsoredTx, sender) {
|
|
737
773
|
if (!coinObjects) {
|
|
738
774
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
739
775
|
}
|
|
@@ -750,11 +786,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
750
786
|
}
|
|
751
787
|
let suiCoinObject;
|
|
752
788
|
if (sponsoredTx) {
|
|
753
|
-
|
|
754
|
-
|
|
789
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
790
|
+
sender: this.requireSenderForSponsored(sender),
|
|
791
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
792
|
+
});
|
|
793
|
+
tx = oracle.tx;
|
|
794
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
755
795
|
}
|
|
756
796
|
else {
|
|
757
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
797
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
758
798
|
}
|
|
759
799
|
// Handle oracle initialization and coin processing
|
|
760
800
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -788,7 +828,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
788
828
|
/**
|
|
789
829
|
* Decreases an existing position in SLP (V2 - uses v3 contract)
|
|
790
830
|
*/
|
|
791
|
-
async decreasePositionV2(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx,
|
|
831
|
+
async decreasePositionV2(pcpId, collateralToken, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), coinObjects, sponsoredTx, sender) {
|
|
792
832
|
if (!coinObjects) {
|
|
793
833
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
794
834
|
}
|
|
@@ -806,11 +846,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
806
846
|
// Handle oracle initialization and coin processing
|
|
807
847
|
let suiCoinObject;
|
|
808
848
|
if (sponsoredTx) {
|
|
809
|
-
|
|
810
|
-
|
|
849
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
850
|
+
sender: this.requireSenderForSponsored(sender),
|
|
851
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
852
|
+
});
|
|
853
|
+
tx = oracle.tx;
|
|
854
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
811
855
|
}
|
|
812
856
|
else {
|
|
813
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
857
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
814
858
|
}
|
|
815
859
|
// Process coin splitting
|
|
816
860
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -840,18 +884,19 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
840
884
|
});
|
|
841
885
|
return tx;
|
|
842
886
|
}
|
|
843
|
-
async decreaseMultiPositions(positions, tx, sponsoredTx,
|
|
887
|
+
async decreaseMultiPositions(positions, tx, sponsoredTx, sender) {
|
|
844
888
|
if (!tx) {
|
|
845
889
|
tx = new transactions_1.Transaction();
|
|
846
890
|
}
|
|
847
891
|
// Handle oracle initialization and coin processing
|
|
848
892
|
let suiCoinObject;
|
|
849
893
|
if (sponsoredTx) {
|
|
850
|
-
|
|
851
|
-
tx =
|
|
894
|
+
const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
|
|
895
|
+
tx = oracle.tx;
|
|
896
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
852
897
|
}
|
|
853
898
|
else {
|
|
854
|
-
tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
|
|
899
|
+
tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
|
|
855
900
|
}
|
|
856
901
|
for (const position of positions) {
|
|
857
902
|
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;
|
|
@@ -896,14 +941,21 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
896
941
|
}
|
|
897
942
|
return tx;
|
|
898
943
|
}
|
|
899
|
-
async decreaseMultiPositionsV2(positions, tx, sponsoredTx,
|
|
900
|
-
|
|
944
|
+
async decreaseMultiPositionsV2(positions, tx, sponsoredTx, sender, feeObjects) {
|
|
945
|
+
let transaction = tx ?? new transactions_1.Transaction();
|
|
901
946
|
// Handle oracle initialization and coin processing
|
|
902
947
|
const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
948
|
+
let suiCoinObject;
|
|
949
|
+
if (sponsoredTx) {
|
|
950
|
+
const oracle = await this.initOracleTxb(tokens, transaction, true, {
|
|
951
|
+
sender: this.requireSenderForSponsored(sender),
|
|
952
|
+
});
|
|
953
|
+
transaction = oracle.tx;
|
|
954
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
955
|
+
}
|
|
956
|
+
else {
|
|
957
|
+
transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
|
|
958
|
+
}
|
|
907
959
|
if (!feeObjects || feeObjects.length !== positions.length) {
|
|
908
960
|
throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
|
|
909
961
|
}
|
|
@@ -948,16 +1000,20 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
948
1000
|
}
|
|
949
1001
|
return transaction;
|
|
950
1002
|
}
|
|
951
|
-
async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx,
|
|
1003
|
+
async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, sender) {
|
|
952
1004
|
let tx = new transactions_1.Transaction();
|
|
953
1005
|
// Handle oracle initialization and coin processing
|
|
954
1006
|
let suiCoinObject;
|
|
955
1007
|
if (sponsoredTx) {
|
|
956
|
-
|
|
957
|
-
|
|
1008
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1009
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1010
|
+
additionalSuiAmount: collateralToken === 'sui' ? BigInt(amount) : 0n,
|
|
1011
|
+
});
|
|
1012
|
+
tx = oracle.tx;
|
|
1013
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
958
1014
|
}
|
|
959
1015
|
else {
|
|
960
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1016
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
961
1017
|
}
|
|
962
1018
|
// Process coin splitting
|
|
963
1019
|
const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(amount)], sponsoredTx, suiCoinObject);
|
|
@@ -977,16 +1033,20 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
977
1033
|
});
|
|
978
1034
|
return tx;
|
|
979
1035
|
}
|
|
980
|
-
async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx,
|
|
1036
|
+
async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, sender) {
|
|
981
1037
|
let tx = new transactions_1.Transaction();
|
|
982
1038
|
// Handle oracle initialization and coin processing
|
|
983
1039
|
let suiCoinObject;
|
|
984
1040
|
if (sponsoredTx) {
|
|
985
|
-
|
|
986
|
-
|
|
1041
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1042
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1043
|
+
additionalSuiAmount: 0n,
|
|
1044
|
+
});
|
|
1045
|
+
tx = oracle.tx;
|
|
1046
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
987
1047
|
}
|
|
988
1048
|
else {
|
|
989
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1049
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
990
1050
|
}
|
|
991
1051
|
const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
|
|
992
1052
|
tx.moveCall({
|
|
@@ -1164,7 +1224,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1164
1224
|
arguments: [tx.object(this.consts.sudoCore.market), tx.object(orderCapId)],
|
|
1165
1225
|
});
|
|
1166
1226
|
}
|
|
1167
|
-
async openPositionWithSCard(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx
|
|
1227
|
+
async openPositionWithSCard(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
1168
1228
|
let tx = new transactions_1.Transaction();
|
|
1169
1229
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
1170
1230
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -1188,11 +1248,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1188
1248
|
// Handle oracle initialization and coin processing
|
|
1189
1249
|
let suiCoinObject;
|
|
1190
1250
|
if (sponsoredTx) {
|
|
1191
|
-
|
|
1192
|
-
|
|
1251
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1252
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1253
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1254
|
+
});
|
|
1255
|
+
tx = oracle.tx;
|
|
1256
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1193
1257
|
}
|
|
1194
1258
|
else {
|
|
1195
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1259
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1196
1260
|
}
|
|
1197
1261
|
// Process coin splitting
|
|
1198
1262
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1232,7 +1296,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1232
1296
|
.finalize();
|
|
1233
1297
|
return tx;
|
|
1234
1298
|
}
|
|
1235
|
-
async openPositionWithCoinAndSCard(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx
|
|
1299
|
+
async openPositionWithCoinAndSCard(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder = false, isIocOrder = false, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
1236
1300
|
if (!tx) {
|
|
1237
1301
|
tx = new transactions_1.Transaction();
|
|
1238
1302
|
}
|
|
@@ -1258,11 +1322,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1258
1322
|
// Handle oracle initialization and coin processing
|
|
1259
1323
|
let suiCoinObject;
|
|
1260
1324
|
if (sponsoredTx) {
|
|
1261
|
-
|
|
1262
|
-
|
|
1325
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1326
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1327
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1328
|
+
});
|
|
1329
|
+
tx = oracle.tx;
|
|
1330
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1263
1331
|
}
|
|
1264
1332
|
else {
|
|
1265
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1333
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1266
1334
|
}
|
|
1267
1335
|
// Process coin splitting
|
|
1268
1336
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -1302,7 +1370,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1302
1370
|
.finalize();
|
|
1303
1371
|
return tx;
|
|
1304
1372
|
}
|
|
1305
|
-
async openPositionWithSCardV2(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx
|
|
1373
|
+
async openPositionWithSCardV2(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
1306
1374
|
let tx = new transactions_1.Transaction();
|
|
1307
1375
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
1308
1376
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -1327,11 +1395,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1327
1395
|
// Handle oracle initialization and coin processing
|
|
1328
1396
|
let suiCoinObject;
|
|
1329
1397
|
if (sponsoredTx) {
|
|
1330
|
-
|
|
1331
|
-
|
|
1398
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1399
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1400
|
+
additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
|
|
1401
|
+
});
|
|
1402
|
+
tx = oracle.tx;
|
|
1403
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1332
1404
|
}
|
|
1333
1405
|
else {
|
|
1334
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1406
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1335
1407
|
}
|
|
1336
1408
|
// Process coin splitting
|
|
1337
1409
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1371,7 +1443,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1371
1443
|
return tx;
|
|
1372
1444
|
}
|
|
1373
1445
|
// S Card operations
|
|
1374
|
-
async openPositionWithCoinAndSCardV2(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx
|
|
1446
|
+
async openPositionWithCoinAndSCardV2(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, kioskClient, kioskCap, scard, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
1375
1447
|
if (!tx) {
|
|
1376
1448
|
tx = new transactions_1.Transaction();
|
|
1377
1449
|
}
|
|
@@ -1398,11 +1470,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1398
1470
|
// Handle oracle initialization and coin processing
|
|
1399
1471
|
let suiCoinObject;
|
|
1400
1472
|
if (sponsoredTx) {
|
|
1401
|
-
|
|
1402
|
-
|
|
1473
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1474
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1475
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1476
|
+
});
|
|
1477
|
+
tx = oracle.tx;
|
|
1478
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1403
1479
|
}
|
|
1404
1480
|
else {
|
|
1405
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1481
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1406
1482
|
}
|
|
1407
1483
|
// Process coin splitting
|
|
1408
1484
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -1441,7 +1517,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1441
1517
|
.finalize();
|
|
1442
1518
|
return tx;
|
|
1443
1519
|
}
|
|
1444
|
-
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, sponsoredTx,
|
|
1520
|
+
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, sponsoredTx, sender) {
|
|
1445
1521
|
if (!coinObjects) {
|
|
1446
1522
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
1447
1523
|
}
|
|
@@ -1468,11 +1544,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1468
1544
|
// Handle oracle initialization and coin processing
|
|
1469
1545
|
let suiCoinObject;
|
|
1470
1546
|
if (sponsoredTx) {
|
|
1471
|
-
|
|
1472
|
-
|
|
1547
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1548
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1549
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1550
|
+
});
|
|
1551
|
+
tx = oracle.tx;
|
|
1552
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1473
1553
|
}
|
|
1474
1554
|
else {
|
|
1475
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1555
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1476
1556
|
}
|
|
1477
1557
|
// Process coin splitting
|
|
1478
1558
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1511,7 +1591,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1511
1591
|
.finalize();
|
|
1512
1592
|
return tx;
|
|
1513
1593
|
}
|
|
1514
|
-
async decreasePositionWithSCardV2(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, sponsoredTx,
|
|
1594
|
+
async decreasePositionWithSCardV2(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, sponsoredTx, sender) {
|
|
1515
1595
|
if (!coinObjects) {
|
|
1516
1596
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
1517
1597
|
}
|
|
@@ -1538,11 +1618,15 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1538
1618
|
// Handle oracle initialization and coin processing
|
|
1539
1619
|
let suiCoinObject;
|
|
1540
1620
|
if (sponsoredTx) {
|
|
1541
|
-
|
|
1542
|
-
|
|
1621
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1622
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1623
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1624
|
+
});
|
|
1625
|
+
tx = oracle.tx;
|
|
1626
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1543
1627
|
}
|
|
1544
1628
|
else {
|
|
1545
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1629
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1546
1630
|
}
|
|
1547
1631
|
// Process coin splitting
|
|
1548
1632
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1580,18 +1664,19 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1580
1664
|
.finalize();
|
|
1581
1665
|
return tx;
|
|
1582
1666
|
}
|
|
1583
|
-
async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx,
|
|
1667
|
+
async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender) {
|
|
1584
1668
|
if (!tx) {
|
|
1585
1669
|
tx = new transactions_1.Transaction();
|
|
1586
1670
|
}
|
|
1587
1671
|
// Handle oracle initialization and coin processing
|
|
1588
1672
|
let suiCoinObject;
|
|
1589
1673
|
if (sponsoredTx) {
|
|
1590
|
-
|
|
1591
|
-
tx =
|
|
1674
|
+
const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
|
|
1675
|
+
tx = oracle.tx;
|
|
1676
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1592
1677
|
}
|
|
1593
1678
|
else {
|
|
1594
|
-
tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
|
|
1679
|
+
tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
|
|
1595
1680
|
}
|
|
1596
1681
|
const kioskTx = new kiosk_1.KioskTransaction({
|
|
1597
1682
|
transaction: tx,
|
|
@@ -1653,14 +1738,21 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1653
1738
|
.finalize();
|
|
1654
1739
|
return tx;
|
|
1655
1740
|
}
|
|
1656
|
-
async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx,
|
|
1657
|
-
|
|
1741
|
+
async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender, feeObjects) {
|
|
1742
|
+
let transaction = tx ?? new transactions_1.Transaction();
|
|
1658
1743
|
// Handle oracle initialization and coin processing
|
|
1659
1744
|
const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1745
|
+
let suiCoinObject;
|
|
1746
|
+
if (sponsoredTx) {
|
|
1747
|
+
const oracle = await this.initOracleTxb(tokens, transaction, true, {
|
|
1748
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1749
|
+
});
|
|
1750
|
+
transaction = oracle.tx;
|
|
1751
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1752
|
+
}
|
|
1753
|
+
else {
|
|
1754
|
+
transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
|
|
1755
|
+
}
|
|
1664
1756
|
if (!feeObjects || feeObjects.length !== positions.length) {
|
|
1665
1757
|
throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
|
|
1666
1758
|
}
|
|
@@ -1734,7 +1826,7 @@ class SLPAPI extends abstract_1.BaseAPI {
|
|
|
1734
1826
|
return tx;
|
|
1735
1827
|
}
|
|
1736
1828
|
async adminUpdatePriceFeed(collateralToken, indexToken) {
|
|
1737
|
-
const tx = await this.initOracleTxb([collateralToken, indexToken]);
|
|
1829
|
+
const { tx } = await this.initOracleTxb([collateralToken, indexToken]);
|
|
1738
1830
|
return tx;
|
|
1739
1831
|
}
|
|
1740
1832
|
adminSettlePosition(_positionId, _owner, _collateralToken, _indexToken, _long) {
|