@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 ZLPAPI extends abstract_1.BaseAPI {
|
|
|
26
26
|
/**
|
|
27
27
|
* Deposits collateral into ZLP vault
|
|
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 ZLPAPI 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]
|
|
@@ -58,7 +62,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
58
62
|
return tx;
|
|
59
63
|
}
|
|
60
64
|
// Handle non-sponsored transaction case
|
|
61
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
65
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
62
66
|
const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
|
|
63
67
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
64
68
|
tx.moveCall({
|
|
@@ -81,7 +85,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
81
85
|
/**
|
|
82
86
|
* Deposits collateral into ZLP vault and returns a coin
|
|
83
87
|
*/
|
|
84
|
-
async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx
|
|
88
|
+
async depositPtb(coin, coinObjects, amount, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
|
|
85
89
|
if (!tx) {
|
|
86
90
|
tx = new transactions_1.Transaction();
|
|
87
91
|
}
|
|
@@ -93,8 +97,12 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
93
97
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
94
98
|
// Handle sponsored transaction case
|
|
95
99
|
if (sponsoredTx) {
|
|
96
|
-
const
|
|
97
|
-
|
|
100
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
101
|
+
sender: this.requireSenderForSponsored(sender),
|
|
102
|
+
additionalSuiAmount: coin === 'sui' ? BigInt(amount) : 0n,
|
|
103
|
+
});
|
|
104
|
+
tx = oracle.tx;
|
|
105
|
+
const { suiCoinObject } = oracle;
|
|
98
106
|
// Process deposit coins
|
|
99
107
|
const depositObject = coin === 'sui'
|
|
100
108
|
? tx.splitCoins(suiCoinObject, [tx.pure.u64(amount)])[0]
|
|
@@ -115,7 +123,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
115
123
|
return mintedCoin;
|
|
116
124
|
}
|
|
117
125
|
// Handle non-sponsored transaction case
|
|
118
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
126
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
119
127
|
const depositObject = tx.splitCoins(this.processCoins(tx, coin, coinObjects, false), [tx.pure.u64(amount)])[0];
|
|
120
128
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
121
129
|
const [mintedCoin] = tx.moveCall({
|
|
@@ -135,7 +143,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
135
143
|
});
|
|
136
144
|
return mintedCoin;
|
|
137
145
|
}
|
|
138
|
-
async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx
|
|
146
|
+
async depositWithPtb(coin, depositObject, minAmountOut = 0, referralAddress, sender, tx, sponsoredTx) {
|
|
139
147
|
if (!tx) {
|
|
140
148
|
tx = new transactions_1.Transaction();
|
|
141
149
|
}
|
|
@@ -147,8 +155,12 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
147
155
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
148
156
|
// Handle sponsored transaction case
|
|
149
157
|
if (sponsoredTx) {
|
|
150
|
-
const
|
|
151
|
-
|
|
158
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
159
|
+
sender: this.requireSenderForSponsored(sender),
|
|
160
|
+
additionalSuiAmount: 0n,
|
|
161
|
+
});
|
|
162
|
+
tx = oracle.tx;
|
|
163
|
+
const { suiCoinObject } = oracle;
|
|
152
164
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
153
165
|
tx.moveCall({
|
|
154
166
|
target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
|
|
@@ -165,7 +177,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
165
177
|
return tx;
|
|
166
178
|
}
|
|
167
179
|
// Handle non-sponsored transaction case
|
|
168
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
180
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
169
181
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
170
182
|
tx.moveCall({
|
|
171
183
|
target: `${this.consts.zoCore.upgradedPackage}::market::deposit`,
|
|
@@ -187,16 +199,20 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
187
199
|
/**
|
|
188
200
|
* Withdraws collateral from ZLP vault
|
|
189
201
|
*/
|
|
190
|
-
async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx,
|
|
202
|
+
async withdraw(coin, lpCoinObjects, amount, minAmountOut = 0, sponsoredTx, sender) {
|
|
191
203
|
let tx = new transactions_1.Transaction();
|
|
192
204
|
// Initialize oracle transaction
|
|
193
205
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
194
206
|
if (sponsoredTx) {
|
|
195
|
-
const
|
|
196
|
-
|
|
207
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
208
|
+
sender: this.requireSenderForSponsored(sender),
|
|
209
|
+
additionalSuiAmount: 0n,
|
|
210
|
+
});
|
|
211
|
+
tx = oracle.tx;
|
|
212
|
+
const { suiCoinObject } = oracle;
|
|
197
213
|
}
|
|
198
214
|
else {
|
|
199
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
215
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
200
216
|
}
|
|
201
217
|
const zlpCoinObject = this.processCoins(tx, 'zlp', lpCoinObjects, false);
|
|
202
218
|
const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
|
|
@@ -227,7 +243,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
227
243
|
}
|
|
228
244
|
// Initialize oracle transaction
|
|
229
245
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
230
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
246
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
231
247
|
const { vaultsValuation, symbolsValuation } = this.dataAPI.valuate(tx);
|
|
232
248
|
tx.moveCall({
|
|
233
249
|
target: `${this.consts.zoCore.upgradedPackage}::market::withdraw`,
|
|
@@ -246,18 +262,22 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
246
262
|
});
|
|
247
263
|
return tx;
|
|
248
264
|
}
|
|
249
|
-
async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx,
|
|
265
|
+
async withdrawPtb(coin, lpCoinObjects, amount, minAmountOut = 0, tx, sponsoredTx, sender) {
|
|
250
266
|
if (!tx) {
|
|
251
267
|
tx = new transactions_1.Transaction();
|
|
252
268
|
}
|
|
253
269
|
// Initialize oracle transaction
|
|
254
270
|
const pythFeederKeys = Object.keys(this.consts.pythFeeder.feeder);
|
|
255
271
|
if (sponsoredTx) {
|
|
256
|
-
const
|
|
257
|
-
|
|
272
|
+
const oracle = await this.initOracleTxb(pythFeederKeys, tx, true, {
|
|
273
|
+
sender: this.requireSenderForSponsored(sender),
|
|
274
|
+
additionalSuiAmount: 0n,
|
|
275
|
+
});
|
|
276
|
+
tx = oracle.tx;
|
|
277
|
+
const { suiCoinObject } = oracle;
|
|
258
278
|
}
|
|
259
279
|
else {
|
|
260
|
-
tx = await this.initOracleTxb(pythFeederKeys, tx);
|
|
280
|
+
tx = (await this.initOracleTxb(pythFeederKeys, tx)).tx;
|
|
261
281
|
}
|
|
262
282
|
const zlpCoinObject = this.processCoins(tx, 'zlp', lpCoinObjects, false);
|
|
263
283
|
const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
|
|
@@ -442,7 +462,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
442
462
|
return rewardCoin;
|
|
443
463
|
}
|
|
444
464
|
async swap(fromToken, toToken, fromAmount, fromCoinObjects, minAmountOut) {
|
|
445
|
-
const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
|
|
465
|
+
const { tx } = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
|
|
446
466
|
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
|
|
447
467
|
const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)]);
|
|
448
468
|
const vaultsValuation = this.dataAPI.valuateVaults(tx);
|
|
@@ -474,7 +494,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
474
494
|
if (!tx) {
|
|
475
495
|
tx = new transactions_1.Transaction();
|
|
476
496
|
}
|
|
477
|
-
tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx);
|
|
497
|
+
tx = (await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx)).tx;
|
|
478
498
|
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects);
|
|
479
499
|
const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
|
|
480
500
|
tx.pure.u64(fromAmount),
|
|
@@ -502,7 +522,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
502
522
|
/**
|
|
503
523
|
* Opens a new position in ZLP
|
|
504
524
|
*/
|
|
505
|
-
async openPosition(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx
|
|
525
|
+
async openPosition(collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, sponsoredTx) {
|
|
506
526
|
let tx = new transactions_1.Transaction();
|
|
507
527
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
508
528
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -517,11 +537,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
517
537
|
// Handle oracle initialization and coin processing
|
|
518
538
|
let suiCoinObject;
|
|
519
539
|
if (sponsoredTx) {
|
|
520
|
-
|
|
521
|
-
|
|
540
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
541
|
+
sender: this.requireSenderForSponsored(sender),
|
|
542
|
+
additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
|
|
543
|
+
});
|
|
544
|
+
tx = oracle.tx;
|
|
545
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
522
546
|
}
|
|
523
547
|
else {
|
|
524
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
548
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
525
549
|
}
|
|
526
550
|
// Process coin splitting
|
|
527
551
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -556,7 +580,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
556
580
|
/**
|
|
557
581
|
* Opens a new position in ZLP
|
|
558
582
|
*/
|
|
559
|
-
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
|
|
583
|
+
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) {
|
|
560
584
|
let tx = new transactions_1.Transaction();
|
|
561
585
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
562
586
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -572,11 +596,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
572
596
|
// Handle oracle initialization and coin processing
|
|
573
597
|
let suiCoinObject;
|
|
574
598
|
if (sponsoredTx) {
|
|
575
|
-
|
|
576
|
-
|
|
599
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
600
|
+
sender: this.requireSenderForSponsored(sender),
|
|
601
|
+
additionalSuiAmount: collateralToken === 'sui' ? collateralAmount + relayerFee : 0n,
|
|
602
|
+
});
|
|
603
|
+
tx = oracle.tx;
|
|
604
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
577
605
|
}
|
|
578
606
|
else {
|
|
579
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
607
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
580
608
|
}
|
|
581
609
|
// Process coin splitting
|
|
582
610
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -610,7 +638,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
610
638
|
/**
|
|
611
639
|
* Opens a new position with Coin in ZLP
|
|
612
640
|
*/
|
|
613
|
-
async openPositionWithCoin(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx
|
|
641
|
+
async openPositionWithCoin(collateralToken, indexToken, size, coinObj, long, reserveAmount, indexPrice, collateralPrice, isLimitOrder, isIocOrder, pricesSlippage = 0.003, collateralSlippage = 0.5, relayerFee = BigInt(0.5), referralAddress, sender, tx, sponsoredTx) {
|
|
614
642
|
if (!tx) {
|
|
615
643
|
tx = new transactions_1.Transaction();
|
|
616
644
|
}
|
|
@@ -627,11 +655,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
627
655
|
// Handle oracle initialization and coin processing
|
|
628
656
|
let suiCoinObject;
|
|
629
657
|
if (sponsoredTx) {
|
|
630
|
-
|
|
631
|
-
|
|
658
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
659
|
+
sender: this.requireSenderForSponsored(sender),
|
|
660
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
661
|
+
});
|
|
662
|
+
tx = oracle.tx;
|
|
663
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
632
664
|
}
|
|
633
665
|
else {
|
|
634
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
666
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
635
667
|
}
|
|
636
668
|
// Process coin splitting
|
|
637
669
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -666,7 +698,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
666
698
|
/**
|
|
667
699
|
* Opens a new position with Coin in ZLP (V2)
|
|
668
700
|
*/
|
|
669
|
-
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
|
|
701
|
+
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) {
|
|
670
702
|
if (!tx) {
|
|
671
703
|
tx = new transactions_1.Transaction();
|
|
672
704
|
}
|
|
@@ -684,11 +716,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
684
716
|
// Handle oracle initialization and coin processing
|
|
685
717
|
let suiCoinObject;
|
|
686
718
|
if (sponsoredTx) {
|
|
687
|
-
|
|
688
|
-
|
|
719
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
720
|
+
sender: this.requireSenderForSponsored(sender),
|
|
721
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
722
|
+
});
|
|
723
|
+
tx = oracle.tx;
|
|
724
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
689
725
|
}
|
|
690
726
|
else {
|
|
691
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
727
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
692
728
|
}
|
|
693
729
|
// Process coin splitting
|
|
694
730
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -722,7 +758,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
722
758
|
/**
|
|
723
759
|
* Decreases an existing position in ZLP
|
|
724
760
|
*/
|
|
725
|
-
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,
|
|
761
|
+
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) {
|
|
726
762
|
if (!coinObjects) {
|
|
727
763
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
728
764
|
}
|
|
@@ -740,11 +776,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
740
776
|
// Handle oracle initialization and coin processing
|
|
741
777
|
let suiCoinObject;
|
|
742
778
|
if (sponsoredTx) {
|
|
743
|
-
|
|
744
|
-
|
|
779
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
780
|
+
sender: this.requireSenderForSponsored(sender),
|
|
781
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
782
|
+
});
|
|
783
|
+
tx = oracle.tx;
|
|
784
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
745
785
|
}
|
|
746
786
|
else {
|
|
747
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
787
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
748
788
|
}
|
|
749
789
|
// Process coin splitting
|
|
750
790
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -778,7 +818,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
778
818
|
/**
|
|
779
819
|
* Decreases an existing position in ZLP
|
|
780
820
|
*/
|
|
781
|
-
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,
|
|
821
|
+
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) {
|
|
782
822
|
if (!coinObjects) {
|
|
783
823
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
784
824
|
}
|
|
@@ -796,11 +836,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
796
836
|
// Handle oracle initialization and coin processing
|
|
797
837
|
let suiCoinObject;
|
|
798
838
|
if (sponsoredTx) {
|
|
799
|
-
|
|
800
|
-
|
|
839
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
840
|
+
sender: this.requireSenderForSponsored(sender),
|
|
841
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
842
|
+
});
|
|
843
|
+
tx = oracle.tx;
|
|
844
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
801
845
|
}
|
|
802
846
|
else {
|
|
803
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
847
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
804
848
|
}
|
|
805
849
|
// Process coin splitting
|
|
806
850
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -830,18 +874,19 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
830
874
|
});
|
|
831
875
|
return tx;
|
|
832
876
|
}
|
|
833
|
-
async decreaseMultiPositions(positions, tx, sponsoredTx,
|
|
877
|
+
async decreaseMultiPositions(positions, tx, sponsoredTx, sender) {
|
|
834
878
|
if (!tx) {
|
|
835
879
|
tx = new transactions_1.Transaction();
|
|
836
880
|
}
|
|
837
881
|
// Handle oracle initialization and coin processing
|
|
838
882
|
let suiCoinObject;
|
|
839
883
|
if (sponsoredTx) {
|
|
840
|
-
|
|
841
|
-
tx =
|
|
884
|
+
const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
|
|
885
|
+
tx = oracle.tx;
|
|
886
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
842
887
|
}
|
|
843
888
|
else {
|
|
844
|
-
tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
|
|
889
|
+
tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
|
|
845
890
|
}
|
|
846
891
|
for (const position of positions) {
|
|
847
892
|
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;
|
|
@@ -886,14 +931,21 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
886
931
|
}
|
|
887
932
|
return tx;
|
|
888
933
|
}
|
|
889
|
-
async decreaseMultiPositionsV2(positions, tx, sponsoredTx,
|
|
890
|
-
|
|
934
|
+
async decreaseMultiPositionsV2(positions, tx, sponsoredTx, sender, feeObjects) {
|
|
935
|
+
let transaction = tx ?? new transactions_1.Transaction();
|
|
891
936
|
// Handle oracle initialization and coin processing
|
|
892
937
|
const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
938
|
+
let suiCoinObject;
|
|
939
|
+
if (sponsoredTx) {
|
|
940
|
+
const oracle = await this.initOracleTxb(tokens, transaction, true, {
|
|
941
|
+
sender: this.requireSenderForSponsored(sender),
|
|
942
|
+
});
|
|
943
|
+
transaction = oracle.tx;
|
|
944
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
945
|
+
}
|
|
946
|
+
else {
|
|
947
|
+
transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
|
|
948
|
+
}
|
|
897
949
|
if (!feeObjects || feeObjects.length !== positions.length) {
|
|
898
950
|
throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
|
|
899
951
|
}
|
|
@@ -938,7 +990,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
938
990
|
}
|
|
939
991
|
return transaction;
|
|
940
992
|
}
|
|
941
|
-
async openPositionWithSCard(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
|
|
993
|
+
async openPositionWithSCard(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) {
|
|
942
994
|
let tx = new transactions_1.Transaction();
|
|
943
995
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
944
996
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -962,11 +1014,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
962
1014
|
// Handle oracle initialization and coin processing
|
|
963
1015
|
let suiCoinObject;
|
|
964
1016
|
if (sponsoredTx) {
|
|
965
|
-
|
|
966
|
-
|
|
1017
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1018
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1019
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1020
|
+
});
|
|
1021
|
+
tx = oracle.tx;
|
|
1022
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
967
1023
|
}
|
|
968
1024
|
else {
|
|
969
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1025
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
970
1026
|
}
|
|
971
1027
|
// Process coin splitting
|
|
972
1028
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1006,7 +1062,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1006
1062
|
.finalize();
|
|
1007
1063
|
return tx;
|
|
1008
1064
|
}
|
|
1009
|
-
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
|
|
1065
|
+
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) {
|
|
1010
1066
|
let tx = new transactions_1.Transaction();
|
|
1011
1067
|
if (referralAddress && !(await this.dataAPI.hasReferral(sender || ''))) {
|
|
1012
1068
|
tx = await this.addReferral(referralAddress, tx);
|
|
@@ -1031,11 +1087,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1031
1087
|
// Handle oracle initialization and coin processing
|
|
1032
1088
|
let suiCoinObject;
|
|
1033
1089
|
if (sponsoredTx) {
|
|
1034
|
-
|
|
1035
|
-
|
|
1090
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1091
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1092
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1093
|
+
});
|
|
1094
|
+
tx = oracle.tx;
|
|
1095
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1036
1096
|
}
|
|
1037
1097
|
else {
|
|
1038
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1098
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1039
1099
|
}
|
|
1040
1100
|
// Process coin splitting
|
|
1041
1101
|
const [depositObject, feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(collateralAmount), tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1074,7 +1134,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1074
1134
|
.finalize();
|
|
1075
1135
|
return tx;
|
|
1076
1136
|
}
|
|
1077
|
-
async openPositionWithCoinAndSCard(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
|
|
1137
|
+
async openPositionWithCoinAndSCard(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) {
|
|
1078
1138
|
if (!tx) {
|
|
1079
1139
|
tx = new transactions_1.Transaction();
|
|
1080
1140
|
}
|
|
@@ -1100,11 +1160,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1100
1160
|
// Handle oracle initialization and coin processing
|
|
1101
1161
|
let suiCoinObject;
|
|
1102
1162
|
if (sponsoredTx) {
|
|
1103
|
-
|
|
1104
|
-
|
|
1163
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1164
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1165
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1166
|
+
});
|
|
1167
|
+
tx = oracle.tx;
|
|
1168
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1105
1169
|
}
|
|
1106
1170
|
else {
|
|
1107
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1171
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1108
1172
|
}
|
|
1109
1173
|
// Process coin splitting
|
|
1110
1174
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -1144,7 +1208,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1144
1208
|
.finalize();
|
|
1145
1209
|
return tx;
|
|
1146
1210
|
}
|
|
1147
|
-
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
|
|
1211
|
+
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) {
|
|
1148
1212
|
if (!tx) {
|
|
1149
1213
|
tx = new transactions_1.Transaction();
|
|
1150
1214
|
}
|
|
@@ -1171,11 +1235,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1171
1235
|
// Handle oracle initialization and coin processing
|
|
1172
1236
|
let suiCoinObject;
|
|
1173
1237
|
if (sponsoredTx) {
|
|
1174
|
-
|
|
1175
|
-
|
|
1238
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1239
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1240
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1241
|
+
});
|
|
1242
|
+
tx = oracle.tx;
|
|
1243
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1176
1244
|
}
|
|
1177
1245
|
else {
|
|
1178
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1246
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1179
1247
|
}
|
|
1180
1248
|
// Process coin splitting
|
|
1181
1249
|
const [feeObject] = tx.splitCoins(coinObj, [tx.pure.u64(relayerFee)]);
|
|
@@ -1214,7 +1282,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1214
1282
|
.finalize();
|
|
1215
1283
|
return tx;
|
|
1216
1284
|
}
|
|
1217
|
-
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,
|
|
1285
|
+
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) {
|
|
1218
1286
|
if (!coinObjects) {
|
|
1219
1287
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
1220
1288
|
}
|
|
@@ -1241,11 +1309,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1241
1309
|
// Handle oracle initialization and coin processing
|
|
1242
1310
|
let suiCoinObject;
|
|
1243
1311
|
if (sponsoredTx) {
|
|
1244
|
-
|
|
1245
|
-
|
|
1312
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1313
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1314
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1315
|
+
});
|
|
1316
|
+
tx = oracle.tx;
|
|
1317
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1246
1318
|
}
|
|
1247
1319
|
else {
|
|
1248
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1320
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1249
1321
|
}
|
|
1250
1322
|
// Process coin splitting
|
|
1251
1323
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1284,7 +1356,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1284
1356
|
.finalize();
|
|
1285
1357
|
return tx;
|
|
1286
1358
|
}
|
|
1287
|
-
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,
|
|
1359
|
+
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) {
|
|
1288
1360
|
if (!coinObjects) {
|
|
1289
1361
|
throw new Error(`${this.constructor.name}: coinObjects is required`);
|
|
1290
1362
|
}
|
|
@@ -1311,11 +1383,15 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1311
1383
|
// Handle oracle initialization and coin processing
|
|
1312
1384
|
let suiCoinObject;
|
|
1313
1385
|
if (sponsoredTx) {
|
|
1314
|
-
|
|
1315
|
-
|
|
1386
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1387
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1388
|
+
additionalSuiAmount: collateralToken === 'sui' ? relayerFee : 0n,
|
|
1389
|
+
});
|
|
1390
|
+
tx = oracle.tx;
|
|
1391
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1316
1392
|
}
|
|
1317
1393
|
else {
|
|
1318
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1394
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1319
1395
|
}
|
|
1320
1396
|
// Process coin splitting
|
|
1321
1397
|
const [feeObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(relayerFee)], sponsoredTx, suiCoinObject);
|
|
@@ -1353,18 +1429,19 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1353
1429
|
.finalize();
|
|
1354
1430
|
return tx;
|
|
1355
1431
|
}
|
|
1356
|
-
async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx,
|
|
1432
|
+
async decreaseMultiPositionsWithSCard(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender) {
|
|
1357
1433
|
if (!tx) {
|
|
1358
1434
|
tx = new transactions_1.Transaction();
|
|
1359
1435
|
}
|
|
1360
1436
|
// Handle oracle initialization and coin processing
|
|
1361
1437
|
let suiCoinObject;
|
|
1362
1438
|
if (sponsoredTx) {
|
|
1363
|
-
|
|
1364
|
-
tx =
|
|
1439
|
+
const oracle = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx, true, { sender: this.requireSenderForSponsored(sender) });
|
|
1440
|
+
tx = oracle.tx;
|
|
1441
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1365
1442
|
}
|
|
1366
1443
|
else {
|
|
1367
|
-
tx = await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx);
|
|
1444
|
+
tx = (await this.initOracleTxb(positions.flatMap(position => [position.collateralToken, position.indexToken]), tx)).tx;
|
|
1368
1445
|
}
|
|
1369
1446
|
const kioskTx = new kiosk_1.KioskTransaction({
|
|
1370
1447
|
transaction: tx,
|
|
@@ -1426,14 +1503,21 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1426
1503
|
.finalize();
|
|
1427
1504
|
return tx;
|
|
1428
1505
|
}
|
|
1429
|
-
async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx,
|
|
1430
|
-
|
|
1506
|
+
async decreaseMultiPositionsWithSCardV2(positions, kioskClient, kioskCap, scard, tx, sponsoredTx, sender, feeObjects) {
|
|
1507
|
+
let transaction = tx ?? new transactions_1.Transaction();
|
|
1431
1508
|
// Handle oracle initialization and coin processing
|
|
1432
1509
|
const tokens = positions.flatMap(position => [position.collateralToken, position.indexToken]);
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1510
|
+
let suiCoinObject;
|
|
1511
|
+
if (sponsoredTx) {
|
|
1512
|
+
const oracle = await this.initOracleTxb(tokens, transaction, true, {
|
|
1513
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1514
|
+
});
|
|
1515
|
+
transaction = oracle.tx;
|
|
1516
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1517
|
+
}
|
|
1518
|
+
else {
|
|
1519
|
+
transaction = (await this.initOracleTxb(tokens, transaction, false)).tx;
|
|
1520
|
+
}
|
|
1437
1521
|
if (!feeObjects || feeObjects.length !== positions.length) {
|
|
1438
1522
|
throw new Error('feeObjects must be provided (pre-processed via buildFeeCoinObjects) and match positions length');
|
|
1439
1523
|
}
|
|
@@ -1498,16 +1582,20 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1498
1582
|
/**
|
|
1499
1583
|
* Pledges in position (ZLP-specific functionality)
|
|
1500
1584
|
*/
|
|
1501
|
-
async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx,
|
|
1585
|
+
async pledgeInPosition(pcpId, collateralToken, indexToken, amount, coinObjects, long, sponsoredTx, sender) {
|
|
1502
1586
|
let tx = new transactions_1.Transaction();
|
|
1503
1587
|
// Handle oracle initialization and coin processing
|
|
1504
1588
|
let suiCoinObject;
|
|
1505
1589
|
if (sponsoredTx) {
|
|
1506
|
-
|
|
1507
|
-
|
|
1590
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1591
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1592
|
+
additionalSuiAmount: collateralToken === 'sui' ? BigInt(amount) : 0n,
|
|
1593
|
+
});
|
|
1594
|
+
tx = oracle.tx;
|
|
1595
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1508
1596
|
}
|
|
1509
1597
|
else {
|
|
1510
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1598
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1511
1599
|
}
|
|
1512
1600
|
// Process coin splitting
|
|
1513
1601
|
const [depositObject] = this.processCoinSplitting(tx, collateralToken, coinObjects, [tx.pure.u64(amount)], sponsoredTx, suiCoinObject);
|
|
@@ -1523,16 +1611,20 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1523
1611
|
});
|
|
1524
1612
|
return tx;
|
|
1525
1613
|
}
|
|
1526
|
-
async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx,
|
|
1614
|
+
async redeemFromPosition(pcpId, collateralToken, indexToken, amount, long, sponsoredTx, sender) {
|
|
1527
1615
|
let tx = new transactions_1.Transaction();
|
|
1528
1616
|
// Handle oracle initialization and coin processing
|
|
1529
1617
|
let suiCoinObject;
|
|
1530
1618
|
if (sponsoredTx) {
|
|
1531
|
-
|
|
1532
|
-
|
|
1619
|
+
const oracle = await this.initOracleTxb([collateralToken, indexToken], tx, true, {
|
|
1620
|
+
sender: this.requireSenderForSponsored(sender),
|
|
1621
|
+
additionalSuiAmount: 0n,
|
|
1622
|
+
});
|
|
1623
|
+
tx = oracle.tx;
|
|
1624
|
+
suiCoinObject = oracle.suiCoinObject;
|
|
1533
1625
|
}
|
|
1534
1626
|
else {
|
|
1535
|
-
tx = await this.initOracleTxb([collateralToken, indexToken], tx);
|
|
1627
|
+
tx = (await this.initOracleTxb([collateralToken, indexToken], tx)).tx;
|
|
1536
1628
|
}
|
|
1537
1629
|
const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
|
|
1538
1630
|
tx.moveCall({
|
|
@@ -1719,7 +1811,7 @@ class ZLPAPI extends abstract_1.BaseAPI {
|
|
|
1719
1811
|
return tx;
|
|
1720
1812
|
}
|
|
1721
1813
|
async adminUpdatePriceFeed(collateralToken, indexToken) {
|
|
1722
|
-
const tx = await this.initOracleTxb([collateralToken, indexToken]);
|
|
1814
|
+
const { tx } = await this.initOracleTxb([collateralToken, indexToken]);
|
|
1723
1815
|
return tx;
|
|
1724
1816
|
}
|
|
1725
1817
|
adminSettlePosition(positionId, owner, collateralToken, indexToken, long) {
|