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