@zofai/zo-sdk 0.1.93 → 0.1.95
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/README.md +4 -3
- package/dist/consts/deployments-slp-mainnet.json +1 -1
- package/dist/consts/deployments-usdz-mainnet.json +1 -1
- package/dist/consts/deployments-zlp-mainnet.json +1 -1
- package/dist/implementations/SLPAPI.cjs +34 -0
- package/dist/implementations/SLPAPI.cjs.map +1 -1
- package/dist/implementations/SLPAPI.d.cts +6 -0
- package/dist/implementations/SLPAPI.d.cts.map +1 -1
- package/dist/implementations/SLPAPI.d.mts +6 -0
- package/dist/implementations/SLPAPI.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.mjs +34 -0
- package/dist/implementations/SLPAPI.mjs.map +1 -1
- package/dist/implementations/SLPDataAPI.cjs +212 -47
- package/dist/implementations/SLPDataAPI.cjs.map +1 -1
- package/dist/implementations/SLPDataAPI.d.cts +8 -1
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/SLPDataAPI.d.mts +8 -1
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/SLPDataAPI.mjs +212 -47
- package/dist/implementations/SLPDataAPI.mjs.map +1 -1
- package/dist/implementations/USDZAPI.cjs +32 -0
- package/dist/implementations/USDZAPI.cjs.map +1 -1
- package/dist/implementations/USDZAPI.d.cts +6 -0
- package/dist/implementations/USDZAPI.d.cts.map +1 -1
- package/dist/implementations/USDZAPI.d.mts +6 -0
- package/dist/implementations/USDZAPI.d.mts.map +1 -1
- package/dist/implementations/USDZAPI.mjs +32 -0
- package/dist/implementations/USDZAPI.mjs.map +1 -1
- package/dist/implementations/USDZDataAPI.cjs +197 -44
- package/dist/implementations/USDZDataAPI.cjs.map +1 -1
- package/dist/implementations/USDZDataAPI.d.cts +8 -1
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
- package/dist/implementations/USDZDataAPI.d.mts +8 -1
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
- package/dist/implementations/USDZDataAPI.mjs +197 -44
- package/dist/implementations/USDZDataAPI.mjs.map +1 -1
- package/dist/implementations/ZLPAPI.cjs +34 -0
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +6 -0
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +6 -0
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +34 -0
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.cjs +200 -46
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.cts +8 -1
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.mts +8 -1
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPDataAPI.mjs +200 -46
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +22 -0
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +22 -0
- package/dist/interfaces/base.d.mts.map +1 -1
- package/dist/interfaces/slp.d.cts +11 -1
- package/dist/interfaces/slp.d.cts.map +1 -1
- package/dist/interfaces/slp.d.mts +11 -1
- package/dist/interfaces/slp.d.mts.map +1 -1
- package/dist/interfaces/usdz.d.cts +11 -1
- package/dist/interfaces/usdz.d.cts.map +1 -1
- package/dist/interfaces/usdz.d.mts +11 -1
- package/dist/interfaces/usdz.d.mts.map +1 -1
- package/dist/interfaces/zlp.d.cts +11 -1
- package/dist/interfaces/zlp.d.cts.map +1 -1
- package/dist/interfaces/zlp.d.mts +11 -1
- package/dist/interfaces/zlp.d.mts.map +1 -1
- package/docs/SUMMARY.md +1 -0
- package/docs/getting-started.md +4 -4
- package/docs/introduction.md +3 -3
- package/docs/swap-integration.md +183 -0
- package/docs/type-safety.md +1 -1
- package/package.json +1 -1
- package/src/consts/deployments-slp-mainnet.json +1 -1
- package/src/consts/deployments-usdz-mainnet.json +1 -1
- package/src/consts/deployments-zlp-mainnet.json +1 -1
- package/src/implementations/SLPAPI.ts +46 -0
- package/src/implementations/SLPDataAPI.ts +235 -19
- package/src/implementations/USDZAPI.ts +41 -0
- package/src/implementations/USDZDataAPI.ts +221 -16
- package/src/implementations/ZLPAPI.ts +43 -0
- package/src/implementations/ZLPDataAPI.ts +222 -17
- package/src/interfaces/base.ts +26 -0
- package/src/interfaces/slp.ts +19 -0
- package/src/interfaces/usdz.ts +19 -0
- package/src/interfaces/zlp.ts +19 -0
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
IBaseHistoryResponse,
|
|
16
16
|
IBaseOrderType,
|
|
17
17
|
IBaseStaked,
|
|
18
|
+
ISwapFeeBreakdown,
|
|
18
19
|
IUSDZCredential,
|
|
19
20
|
IUSDZDataAPI,
|
|
20
21
|
IUSDZFundingFeeModel,
|
|
@@ -37,6 +38,20 @@ import type {
|
|
|
37
38
|
} from '../interfaces'
|
|
38
39
|
import { joinSymbol, parseSymbolKey, parseValue, suiSymbolToSymbol } from '../utils'
|
|
39
40
|
|
|
41
|
+
interface SwapImpactConfig {
|
|
42
|
+
id: string
|
|
43
|
+
enabled: boolean
|
|
44
|
+
impactMultiplier: number
|
|
45
|
+
maxImpactRate: number
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface EmaVolatilityFeeConfig {
|
|
49
|
+
id: string
|
|
50
|
+
enabled: boolean
|
|
51
|
+
multiplier: number
|
|
52
|
+
maxFeeRate: number
|
|
53
|
+
}
|
|
54
|
+
|
|
40
55
|
export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
41
56
|
constructor(
|
|
42
57
|
network: Network,
|
|
@@ -226,7 +241,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
226
241
|
(await this.getOraclePrice(tokenId)).getPriceUnchecked().getPriceAsNumberUnchecked(),
|
|
227
242
|
marketInfo.lpSupplyWithDecimals,
|
|
228
243
|
Date.now() / 1000,
|
|
229
|
-
oiState && oiState.enabled ? oiState
|
|
244
|
+
oiState && oiState.enabled ? oiState : undefined,
|
|
230
245
|
pairedSymbol.openingSize,
|
|
231
246
|
)
|
|
232
247
|
|
|
@@ -385,6 +400,164 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
385
400
|
}
|
|
386
401
|
}
|
|
387
402
|
|
|
403
|
+
public async calculateSwapFeeBreakdown(fromToken: string, toToken: string, fromAmount: number): Promise<ISwapFeeBreakdown> {
|
|
404
|
+
const timestamp = Date.now() / 1000
|
|
405
|
+
|
|
406
|
+
const fromDecimals = this.consts.coins[fromToken]?.decimals
|
|
407
|
+
const toDecimals = this.consts.coins[toToken]?.decimals
|
|
408
|
+
if (fromDecimals === undefined || toDecimals === undefined) {
|
|
409
|
+
throw new Error(`Unknown token decimals for swap: ${fromToken} -> ${toToken}`)
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const fromFeed = await this.getOraclePrice(fromToken)
|
|
413
|
+
const toFeed = await this.getOraclePrice(toToken)
|
|
414
|
+
const fromPrice = fromFeed.getPriceUnchecked().getPriceAsNumberUnchecked()
|
|
415
|
+
const toPrice = toFeed.getPriceUnchecked().getPriceAsNumberUnchecked()
|
|
416
|
+
|
|
417
|
+
const swapValue = (fromAmount * fromPrice) / (10 ** fromDecimals)
|
|
418
|
+
const totalVaultsValue = await this.#getTotalVaultsValueUsd(timestamp)
|
|
419
|
+
|
|
420
|
+
const rebaseFeeInRate = await this.rebaseFeeRate(fromToken, true, fromAmount)
|
|
421
|
+
const rebaseFeeInValue = swapValue * rebaseFeeInRate
|
|
422
|
+
|
|
423
|
+
const estimatedToAmount = toPrice !== 0
|
|
424
|
+
? (swapValue * (10 ** toDecimals)) / toPrice
|
|
425
|
+
: 0
|
|
426
|
+
const rebaseFeeOutRate = await this.rebaseFeeRate(toToken, false, estimatedToAmount)
|
|
427
|
+
const rebaseFeeOutValue = swapValue * rebaseFeeOutRate
|
|
428
|
+
|
|
429
|
+
const swapImpactCfg = await this.#getSwapImpactConfig()
|
|
430
|
+
const swapImpactFeeValue = swapImpactCfg?.enabled
|
|
431
|
+
? USDZDataAPI.#computeSwapImpactFeeValue(swapValue, totalVaultsValue, swapImpactCfg.impactMultiplier, swapImpactCfg.maxImpactRate)
|
|
432
|
+
: 0
|
|
433
|
+
|
|
434
|
+
const emaCfg = await this.#getEmaVolatilityFeeConfig()
|
|
435
|
+
const emaVolatilityFeeValue = emaCfg?.enabled
|
|
436
|
+
? USDZDataAPI.#computeEmaVolatilityFeeValue(
|
|
437
|
+
swapValue,
|
|
438
|
+
USDZDataAPI.#maxEmaDivergenceRate(fromFeed, toFeed),
|
|
439
|
+
emaCfg.multiplier,
|
|
440
|
+
emaCfg.maxFeeRate,
|
|
441
|
+
)
|
|
442
|
+
: 0
|
|
443
|
+
|
|
444
|
+
const totalFeeValue = rebaseFeeInValue + rebaseFeeOutValue + swapImpactFeeValue + emaVolatilityFeeValue
|
|
445
|
+
const totalFeeRate = swapValue !== 0 ? totalFeeValue / swapValue : 0
|
|
446
|
+
|
|
447
|
+
return {
|
|
448
|
+
swapValue,
|
|
449
|
+
totalVaultsValue,
|
|
450
|
+
rebaseFeeInRate,
|
|
451
|
+
rebaseFeeOutRate,
|
|
452
|
+
rebaseFeeInValue,
|
|
453
|
+
rebaseFeeOutValue,
|
|
454
|
+
swapImpactFeeValue,
|
|
455
|
+
emaVolatilityFeeValue,
|
|
456
|
+
totalFeeValue,
|
|
457
|
+
totalFeeRate,
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
async #getTotalVaultsValueUsd(timestamp: number): Promise<number> {
|
|
462
|
+
const vaultKeys = Object.keys(this.consts.zoCore.vaults)
|
|
463
|
+
const vaultValues = await Promise.all(vaultKeys.map(async (vault) => {
|
|
464
|
+
const vaultInfo = await this.getVaultInfo(vault)
|
|
465
|
+
const reservingFeeDelta = USDZDataAPI.calculateVaultReservingFee(vaultInfo, vaultInfo.reservingFeeModel, timestamp)
|
|
466
|
+
const totalVaultAmount = reservingFeeDelta + vaultInfo.liquidity + vaultInfo.reservedAmount
|
|
467
|
+
const oraclePrice = (await this.getOraclePrice(vault)).getPriceUnchecked().getPriceAsNumberUnchecked()
|
|
468
|
+
const { decimals } = this.consts.coins[vault]
|
|
469
|
+
return totalVaultAmount * oraclePrice / (10 ** decimals)
|
|
470
|
+
}))
|
|
471
|
+
return vaultValues.reduce((acc, curr) => acc + curr, 0)
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
async #getSwapImpactConfig(): Promise<SwapImpactConfig | null> {
|
|
475
|
+
const raw = await this.#getMarketDynamicFieldObjectByKeySuffix(this.consts.zoCore.market, 'SwapImpactConfigKey')
|
|
476
|
+
if (!raw)
|
|
477
|
+
return null
|
|
478
|
+
return USDZDataAPI.#parseSwapImpactConfig(raw)
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
async #getEmaVolatilityFeeConfig(): Promise<EmaVolatilityFeeConfig | null> {
|
|
482
|
+
const raw = await this.#getMarketDynamicFieldObjectByKeySuffix(this.consts.zoCore.market, 'EmaVolatilityFeeConfigKey')
|
|
483
|
+
if (!raw)
|
|
484
|
+
return null
|
|
485
|
+
return USDZDataAPI.#parseEmaVolatilityFeeConfig(raw)
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
async #getMarketDynamicFieldObjectByKeySuffix(parentId: string, keyTypeSuffix: string): Promise<any | null> {
|
|
489
|
+
let cursor: string | null | undefined
|
|
490
|
+
let hasNextPage = true
|
|
491
|
+
|
|
492
|
+
while (hasNextPage) {
|
|
493
|
+
const page = await this.provider.getDynamicFields({ parentId, cursor })
|
|
494
|
+
for (const field of page.data) {
|
|
495
|
+
const type = (field.name as any)?.type
|
|
496
|
+
if (typeof type === 'string' && type.endsWith(`::${keyTypeSuffix}`)) {
|
|
497
|
+
return await this.provider.getDynamicFieldObject({
|
|
498
|
+
parentId,
|
|
499
|
+
name: field.name as any,
|
|
500
|
+
})
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
hasNextPage = page.hasNextPage
|
|
504
|
+
cursor = page.nextCursor
|
|
505
|
+
}
|
|
506
|
+
return null
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
static #parseSwapImpactConfig(raw: any): SwapImpactConfig {
|
|
510
|
+
const { fields } = raw.data.content
|
|
511
|
+
return {
|
|
512
|
+
id: fields.id.id,
|
|
513
|
+
enabled: fields.enabled,
|
|
514
|
+
impactMultiplier: parseValue(fields.impact_multiplier),
|
|
515
|
+
maxImpactRate: parseValue(fields.max_impact_rate),
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
static #parseEmaVolatilityFeeConfig(raw: any): EmaVolatilityFeeConfig {
|
|
520
|
+
const { fields } = raw.data.content
|
|
521
|
+
return {
|
|
522
|
+
id: fields.id.id,
|
|
523
|
+
enabled: fields.enabled,
|
|
524
|
+
multiplier: parseValue(fields.multiplier),
|
|
525
|
+
maxFeeRate: parseValue(fields.max_fee_rate),
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
static #computeSwapImpactFeeValue(swapValue: number, totalVaultsValue: number, impactMultiplier: number, maxImpactRate: number): number {
|
|
530
|
+
if (swapValue <= 0 || totalVaultsValue <= 0)
|
|
531
|
+
return 0
|
|
532
|
+
const utilization = swapValue / totalVaultsValue
|
|
533
|
+
const rawImpactRate = impactMultiplier * utilization
|
|
534
|
+
const impactRate = Math.min(rawImpactRate, maxImpactRate)
|
|
535
|
+
return swapValue * impactRate
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
static #computeEmaVolatilityFeeValue(swapValue: number, maxDiv: number, multiplier: number, maxFeeRate: number): number {
|
|
539
|
+
if (swapValue <= 0 || maxDiv <= 0)
|
|
540
|
+
return 0
|
|
541
|
+
const rawFeeRate = multiplier * maxDiv
|
|
542
|
+
const feeRate = Math.min(rawFeeRate, maxFeeRate)
|
|
543
|
+
return swapValue * feeRate
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
static #maxEmaDivergenceRate(sourceFeed: any, destFeed: any): number {
|
|
547
|
+
const sourceDiv = USDZDataAPI.#emaDivergenceRate(sourceFeed)
|
|
548
|
+
const destDiv = USDZDataAPI.#emaDivergenceRate(destFeed)
|
|
549
|
+
return Math.max(sourceDiv, destDiv)
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
static #emaDivergenceRate(priceFeed: any): number {
|
|
553
|
+
const price = priceFeed.getPriceUnchecked().getPriceAsNumberUnchecked()
|
|
554
|
+
const ema = priceFeed.getEmaPriceUnchecked().getPriceAsNumberUnchecked()
|
|
555
|
+
const denom = Math.abs(price)
|
|
556
|
+
if (denom === 0)
|
|
557
|
+
return 0
|
|
558
|
+
return Math.abs(price - ema) / denom
|
|
559
|
+
}
|
|
560
|
+
|
|
388
561
|
public async getPositionCapInfoList(owner: string): Promise<IUSDZPositionCapInfo[]> {
|
|
389
562
|
const positionCapInfoList: IUSDZPositionCapInfo[] = []
|
|
390
563
|
let cursor: string | undefined | null
|
|
@@ -638,7 +811,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
638
811
|
const longSize = longSymbol.openingSize
|
|
639
812
|
const shortSize = shortSymbol.openingSize
|
|
640
813
|
|
|
641
|
-
const deltaRate = USDZDataAPI.calcOiFundingFeeRate(oiState.model, longSize, shortSize, elapsed)
|
|
814
|
+
const deltaRate = USDZDataAPI.calcOiFundingFeeRate(oiState.model, longSize, shortSize, elapsed, oiState.maxOiLong, oiState.maxOiShort)
|
|
642
815
|
return long ? deltaRate : -deltaRate
|
|
643
816
|
}
|
|
644
817
|
|
|
@@ -725,12 +898,42 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
725
898
|
return pnlPerRate >= 0 ? -secondsRate : secondsRate
|
|
726
899
|
}
|
|
727
900
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
901
|
+
/**
|
|
902
|
+
* OI funding rate matching Move compute_oi_funding_rate_capped.
|
|
903
|
+
* When both maxOiLong and maxOiShort are set and > 0, uses normalized skew (oi/cap);
|
|
904
|
+
* otherwise falls back to (long - short) / total.
|
|
905
|
+
*/
|
|
906
|
+
private static calcOiFundingFeeRate(
|
|
907
|
+
model: IUSDZOiFundingModel,
|
|
908
|
+
oiLong: number,
|
|
909
|
+
oiShort: number,
|
|
910
|
+
elapsed: number,
|
|
911
|
+
maxOiLong?: number,
|
|
912
|
+
maxOiShort?: number,
|
|
913
|
+
): number {
|
|
914
|
+
let skew: number
|
|
915
|
+
if (maxOiLong && maxOiShort && maxOiLong > 0 && maxOiShort > 0) {
|
|
916
|
+
const normLong = Math.min(oiLong / maxOiLong, 1)
|
|
917
|
+
const normShort = Math.min(oiShort / maxOiShort, 1)
|
|
918
|
+
skew = normLong - normShort
|
|
919
|
+
}
|
|
920
|
+
else {
|
|
921
|
+
const total = oiLong + oiShort
|
|
922
|
+
if (total === 0)
|
|
923
|
+
return 0
|
|
924
|
+
skew = (oiLong - oiShort) / total
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
if (skew === 0)
|
|
928
|
+
return 0
|
|
929
|
+
|
|
930
|
+
const skewIsPositive = skew > 0
|
|
931
|
+
const skewAbs = Math.abs(skew)
|
|
932
|
+
const exponentInt = Math.floor(model.exponent)
|
|
933
|
+
const skewPow = skewAbs ** exponentInt
|
|
934
|
+
const dailyRate = Math.min(model.multiplier * skewPow, model.max)
|
|
935
|
+
const secondsRate = (dailyRate * elapsed) / SECONDS_PER_EIGHT_HOUR
|
|
936
|
+
return skewIsPositive ? secondsRate : -secondsRate
|
|
734
937
|
}
|
|
735
938
|
|
|
736
939
|
private static calcAccFundingFeeRate(
|
|
@@ -739,16 +942,16 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
739
942
|
price: number,
|
|
740
943
|
lpSupplyAmount: number,
|
|
741
944
|
timestamp: number,
|
|
742
|
-
|
|
945
|
+
oiState?: IUSDZOiFundingState,
|
|
743
946
|
pairedOpeningSize?: number,
|
|
744
947
|
): number {
|
|
745
948
|
if (symbol.lastUpdate > 0) {
|
|
746
949
|
const elapsed = timestamp - symbol.lastUpdate
|
|
747
950
|
if (elapsed > 0) {
|
|
748
|
-
if (
|
|
951
|
+
if (oiState?.enabled && oiState.model && typeof pairedOpeningSize === 'number') {
|
|
749
952
|
const longSize = symbol.long ? symbol.openingSize : pairedOpeningSize
|
|
750
953
|
const shortSize = symbol.long ? pairedOpeningSize : symbol.openingSize
|
|
751
|
-
const deltaRate = USDZDataAPI.calcOiFundingFeeRate(
|
|
954
|
+
const deltaRate = USDZDataAPI.calcOiFundingFeeRate(oiState.model, longSize, shortSize, elapsed, oiState.maxOiLong, oiState.maxOiShort)
|
|
752
955
|
return symbol.accFundingRate + deltaRate
|
|
753
956
|
}
|
|
754
957
|
const deltaSize = USDZDataAPI.calcDeltaSize(symbol, price)
|
|
@@ -765,7 +968,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
765
968
|
price: number,
|
|
766
969
|
lpSupplyAmount: number,
|
|
767
970
|
timestamp: number,
|
|
768
|
-
|
|
971
|
+
oiState?: IUSDZOiFundingState,
|
|
769
972
|
pairedOpeningSize?: number,
|
|
770
973
|
): number {
|
|
771
974
|
const accFundingRate = USDZDataAPI.calcAccFundingFeeRate(
|
|
@@ -774,7 +977,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
774
977
|
price,
|
|
775
978
|
lpSupplyAmount,
|
|
776
979
|
timestamp,
|
|
777
|
-
|
|
980
|
+
oiState,
|
|
778
981
|
pairedOpeningSize,
|
|
779
982
|
)
|
|
780
983
|
return symbol.unrealisedFundingFeeValue + (accFundingRate - symbol.accFundingRate) * symbol.openingSize
|
|
@@ -980,7 +1183,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
980
1183
|
(await this.getOraclePrice(positionInfo.indexToken)).getPriceUnchecked().getPriceAsNumberUnchecked(),
|
|
981
1184
|
(await this.getMarketInfo()).lpSupplyWithDecimals,
|
|
982
1185
|
Date.now() / 1000,
|
|
983
|
-
oiState && oiState.enabled ? oiState
|
|
1186
|
+
oiState && oiState.enabled ? oiState : undefined,
|
|
984
1187
|
pairedSymbol.openingSize,
|
|
985
1188
|
)
|
|
986
1189
|
|
|
@@ -994,7 +1197,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
994
1197
|
price: number,
|
|
995
1198
|
lpSupplyAmount: number,
|
|
996
1199
|
timestamp: number,
|
|
997
|
-
|
|
1200
|
+
oiState?: IUSDZOiFundingState,
|
|
998
1201
|
pairedOpeningSize?: number,
|
|
999
1202
|
): number {
|
|
1000
1203
|
const accFundingRate = USDZDataAPI.calcAccFundingFeeRate(
|
|
@@ -1003,7 +1206,7 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
1003
1206
|
price,
|
|
1004
1207
|
lpSupplyAmount,
|
|
1005
1208
|
timestamp,
|
|
1006
|
-
|
|
1209
|
+
oiState,
|
|
1007
1210
|
pairedOpeningSize,
|
|
1008
1211
|
)
|
|
1009
1212
|
return position.fundingFeeValue + (accFundingRate - position.lastFundingRate) * position.positionSize
|
|
@@ -1045,6 +1248,8 @@ export class USDZDataAPI extends BaseDataAPI implements IUSDZDataAPI {
|
|
|
1045
1248
|
exponent: parseValue(content.model.fields.exponent),
|
|
1046
1249
|
max: parseValue(content.model.fields.max),
|
|
1047
1250
|
},
|
|
1251
|
+
maxOiLong: content.max_oi_long !== null && content.max_oi_long !== undefined ? parseValue(content.max_oi_long) : undefined,
|
|
1252
|
+
maxOiShort: content.max_oi_short !== null && content.max_oi_short !== undefined ? parseValue(content.max_oi_short) : undefined,
|
|
1048
1253
|
}
|
|
1049
1254
|
}
|
|
1050
1255
|
|
|
@@ -624,6 +624,49 @@ export class ZLPAPI extends BaseAPI implements IZLPAPI {
|
|
|
624
624
|
return tx
|
|
625
625
|
}
|
|
626
626
|
|
|
627
|
+
/**
|
|
628
|
+
* Swaps tokens and returns the output coin to the user (PTB).
|
|
629
|
+
* Same as swap() but returns the output coin as TransactionObjectArgument for use in composed transactions.
|
|
630
|
+
* Pass optional tx to compose with other move calls; otherwise a new transaction is created.
|
|
631
|
+
*/
|
|
632
|
+
public async swapV2Ptb(
|
|
633
|
+
fromToken: string,
|
|
634
|
+
toToken: string,
|
|
635
|
+
fromAmount: bigint,
|
|
636
|
+
fromCoinObjects: string[],
|
|
637
|
+
minAmountOut?: number,
|
|
638
|
+
tx?: Transaction,
|
|
639
|
+
): Promise<TransactionObjectArgument> {
|
|
640
|
+
if (!tx) {
|
|
641
|
+
tx = new Transaction()
|
|
642
|
+
}
|
|
643
|
+
tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults), tx)
|
|
644
|
+
const fromCoinObject = this.processCoins(tx, fromToken, fromCoinObjects)
|
|
645
|
+
const [fromDepositObject] = tx.splitCoins(fromCoinObject, [
|
|
646
|
+
tx.pure.u64(fromAmount),
|
|
647
|
+
])
|
|
648
|
+
const vaultsValuation = this.dataAPI.valuateVaults(tx)
|
|
649
|
+
|
|
650
|
+
const [outputCoin] = tx.moveCall({
|
|
651
|
+
target: `${this.consts.zoCore.upgradedPackage}::market::swap_v2_ptb`,
|
|
652
|
+
typeArguments: [
|
|
653
|
+
`${this.consts.zoCore.package}::zlp::ZLP`,
|
|
654
|
+
this.consts.coins[fromToken].module,
|
|
655
|
+
this.consts.coins[toToken].module,
|
|
656
|
+
],
|
|
657
|
+
arguments: [
|
|
658
|
+
tx.object(this.consts.zoCore.market),
|
|
659
|
+
tx.object(this.consts.zoCore.rebaseFeeModel),
|
|
660
|
+
fromDepositObject,
|
|
661
|
+
tx.pure.u64(minAmountOut || 0),
|
|
662
|
+
vaultsValuation,
|
|
663
|
+
tx.object(this.consts.pythFeeder.feeder[fromToken]),
|
|
664
|
+
tx.object(this.consts.pythFeeder.feeder[toToken]),
|
|
665
|
+
],
|
|
666
|
+
})
|
|
667
|
+
return outputCoin
|
|
668
|
+
}
|
|
669
|
+
|
|
627
670
|
/**
|
|
628
671
|
* Opens a new position in ZLP
|
|
629
672
|
*/
|