zo-sdk 0.1.24 → 0.1.26
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.map +1 -1
- package/dist/abstract/BaseAPI.d.cts +2 -2
- package/dist/abstract/BaseAPI.d.cts.map +1 -1
- package/dist/abstract/BaseAPI.d.mts +2 -2
- package/dist/abstract/BaseAPI.d.mts.map +1 -1
- package/dist/abstract/BaseAPI.mjs.map +1 -1
- package/dist/consts/deployments-shared-mainnet.json +50 -0
- package/dist/consts/deployments-shared-testnet.json +45 -0
- package/dist/consts/deployments-usdz-mainnet.json +30 -10
- package/dist/consts/index.cjs +13 -0
- package/dist/consts/index.cjs.map +1 -1
- package/dist/consts/index.d.cts +6 -1
- package/dist/consts/index.d.cts.map +1 -1
- package/dist/consts/index.d.mts +6 -1
- package/dist/consts/index.d.mts.map +1 -1
- package/dist/consts/index.mjs +12 -0
- package/dist/consts/index.mjs.map +1 -1
- package/dist/implementations/SLPAPI.cjs +84 -0
- package/dist/implementations/SLPAPI.cjs.map +1 -1
- package/dist/implementations/SLPAPI.d.cts +12 -0
- package/dist/implementations/SLPAPI.d.cts.map +1 -1
- package/dist/implementations/SLPAPI.d.mts +12 -0
- package/dist/implementations/SLPAPI.d.mts.map +1 -1
- package/dist/implementations/SLPAPI.mjs +84 -0
- package/dist/implementations/SLPAPI.mjs.map +1 -1
- package/dist/implementations/SLPDataAPI.cjs +77 -2
- package/dist/implementations/SLPDataAPI.cjs.map +1 -1
- package/dist/implementations/SLPDataAPI.d.cts +6 -0
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/SLPDataAPI.d.mts +6 -0
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/SLPDataAPI.mjs +77 -2
- package/dist/implementations/SLPDataAPI.mjs.map +1 -1
- package/dist/implementations/USDZAPI.cjs +4 -13
- package/dist/implementations/USDZAPI.cjs.map +1 -1
- package/dist/implementations/USDZAPI.d.cts.map +1 -1
- package/dist/implementations/USDZAPI.d.mts.map +1 -1
- package/dist/implementations/USDZAPI.mjs +4 -13
- package/dist/implementations/USDZAPI.mjs.map +1 -1
- package/dist/implementations/USDZDataAPI.cjs +3 -2
- package/dist/implementations/USDZDataAPI.cjs.map +1 -1
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -1
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -1
- package/dist/implementations/USDZDataAPI.mjs +3 -2
- package/dist/implementations/USDZDataAPI.mjs.map +1 -1
- package/dist/implementations/ZBTCVCAPI.cjs +4 -13
- package/dist/implementations/ZBTCVCAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCAPI.mjs +4 -13
- package/dist/implementations/ZBTCVCAPI.mjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.cjs +2 -1
- package/dist/implementations/ZBTCVCDataAPI.cjs.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZBTCVCDataAPI.mjs +2 -1
- package/dist/implementations/ZBTCVCDataAPI.mjs.map +1 -1
- package/dist/implementations/ZLPAPI.cjs +103 -25
- package/dist/implementations/ZLPAPI.cjs.map +1 -1
- package/dist/implementations/ZLPAPI.d.cts +13 -3
- package/dist/implementations/ZLPAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPAPI.d.mts +13 -3
- package/dist/implementations/ZLPAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPAPI.mjs +103 -25
- package/dist/implementations/ZLPAPI.mjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.cjs +86 -4
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.cts +6 -3
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -1
- package/dist/implementations/ZLPDataAPI.d.mts +6 -3
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -1
- package/dist/implementations/ZLPDataAPI.mjs +86 -4
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -1
- package/dist/interfaces/base.d.cts +2 -2
- package/dist/interfaces/base.d.cts.map +1 -1
- package/dist/interfaces/base.d.mts +2 -2
- package/dist/interfaces/base.d.mts.map +1 -1
- package/dist/interfaces/slp.d.cts +1 -0
- package/dist/interfaces/slp.d.cts.map +1 -1
- package/dist/interfaces/slp.d.mts +1 -0
- package/dist/interfaces/slp.d.mts.map +1 -1
- package/dist/interfaces/zlp.d.cts +1 -0
- package/dist/interfaces/zlp.d.cts.map +1 -1
- package/dist/interfaces/zlp.d.mts +1 -0
- package/dist/interfaces/zlp.d.mts.map +1 -1
- package/dist/oracle.cjs +1 -0
- package/dist/oracle.cjs.map +1 -1
- package/dist/oracle.d.cts +1 -0
- package/dist/oracle.d.cts.map +1 -1
- package/dist/oracle.d.mts +1 -0
- package/dist/oracle.d.mts.map +1 -1
- package/dist/oracle.mjs +2 -1
- package/dist/oracle.mjs.map +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.mjs +2 -2
- package/dist/utils.mjs.map +1 -1
- package/package.json +9 -9
- package/src/abstract/BaseAPI.ts +6 -2
- package/src/consts/deployments-shared-mainnet.json +50 -0
- package/src/consts/deployments-shared-testnet.json +45 -0
- package/src/consts/deployments-usdz-mainnet.json +31 -11
- package/src/consts/deployments-zlp-mainnet.json +1 -1
- package/src/consts/index.ts +15 -1
- package/src/implementations/SLPAPI.ts +104 -0
- package/src/implementations/SLPDataAPI.ts +107 -15
- package/src/implementations/USDZAPI.ts +5 -17
- package/src/implementations/USDZDataAPI.ts +3 -2
- package/src/implementations/ZBTCVCAPI.ts +5 -17
- package/src/implementations/ZBTCVCDataAPI.ts +2 -1
- package/src/implementations/ZLPAPI.ts +124 -27
- package/src/implementations/ZLPDataAPI.ts +111 -4
- package/src/interfaces/base.ts +6 -2
- package/src/interfaces/slp.ts +4 -1
- package/src/interfaces/zlp.ts +1 -0
- package/src/oracle.ts +3 -1
- package/src/utils.ts +2 -2
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
IBaseHistoryResponse,
|
|
16
16
|
IBaseStaked,
|
|
17
17
|
IBaseStakePool,
|
|
18
|
+
IZLPCredential,
|
|
18
19
|
IZLPDataAPI,
|
|
19
20
|
IZLPFundingFeeModel,
|
|
20
21
|
IZLPMarketInfo,
|
|
@@ -26,6 +27,7 @@ import type {
|
|
|
26
27
|
IZLPPositionInfo,
|
|
27
28
|
IZLPRebaseFeeModel,
|
|
28
29
|
IZLPReservingFeeModel,
|
|
30
|
+
IZLPStakePool,
|
|
29
31
|
IZLPSymbolConfig,
|
|
30
32
|
IZLPSymbolInfo,
|
|
31
33
|
IZLPVaultInfo,
|
|
@@ -42,12 +44,64 @@ export class ZLPDataAPI extends BaseDataAPI implements IZLPDataAPI {
|
|
|
42
44
|
super(network, provider, apiEndpoint, connectionURL, LPToken.ZLP)
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
public getStaked(
|
|
46
|
-
|
|
47
|
+
public async getStaked(owner: string): Promise<IBaseStaked> {
|
|
48
|
+
let rawCredentialsData: any[] = []
|
|
49
|
+
let queryNextPage = true
|
|
50
|
+
let queryCursor: string | undefined | null
|
|
51
|
+
|
|
52
|
+
const limit = 50
|
|
53
|
+
|
|
54
|
+
while (queryNextPage) {
|
|
55
|
+
const { data, hasNextPage, nextCursor } = await this.provider.getOwnedObjects({
|
|
56
|
+
owner,
|
|
57
|
+
filter: {
|
|
58
|
+
MoveModule: {
|
|
59
|
+
package: this.consts.zoStaking.package,
|
|
60
|
+
module: 'pool',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
options: {
|
|
64
|
+
showType: true,
|
|
65
|
+
showContent: true,
|
|
66
|
+
},
|
|
67
|
+
cursor: queryCursor,
|
|
68
|
+
limit,
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
queryNextPage = hasNextPage
|
|
72
|
+
queryCursor = nextCursor!
|
|
73
|
+
if (!data)
|
|
74
|
+
break
|
|
75
|
+
rawCredentialsData = [...rawCredentialsData, ...data]
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const pool = await this.getStakePool()
|
|
79
|
+
|
|
80
|
+
const credentials = rawCredentialsData.map((item: any) =>
|
|
81
|
+
ZLPDataAPI.parseCredential(item, pool),
|
|
82
|
+
)
|
|
83
|
+
return {
|
|
84
|
+
credentials,
|
|
85
|
+
amount: credentials.reduce(
|
|
86
|
+
(acc: bigint, cur: IZLPCredential) => acc + cur.amount,
|
|
87
|
+
BigInt(0),
|
|
88
|
+
),
|
|
89
|
+
claimable: credentials.reduce(
|
|
90
|
+
(acc: bigint, cur: IZLPCredential) => acc + cur.claimable,
|
|
91
|
+
BigInt(0),
|
|
92
|
+
),
|
|
93
|
+
}
|
|
47
94
|
}
|
|
48
95
|
|
|
49
|
-
public getStakePool(): Promise<
|
|
50
|
-
|
|
96
|
+
public async getStakePool(): Promise<IZLPStakePool> {
|
|
97
|
+
const poolId = this.consts.zoStaking.pools.ZLP
|
|
98
|
+
const raw = await this.provider.getObject({
|
|
99
|
+
id: poolId,
|
|
100
|
+
options: {
|
|
101
|
+
showContent: true,
|
|
102
|
+
},
|
|
103
|
+
})
|
|
104
|
+
return ZLPDataAPI.parseStakePool(raw)
|
|
51
105
|
}
|
|
52
106
|
|
|
53
107
|
/**
|
|
@@ -907,4 +961,57 @@ export class ZLPDataAPI extends BaseDataAPI implements IZLPDataAPI {
|
|
|
907
961
|
return vaultInfo.unrealisedReservingFeeAmount
|
|
908
962
|
+ (vaultInfo.reservedAmount * reservingFeeModel.multiplier * periods) / 1e18
|
|
909
963
|
}
|
|
964
|
+
|
|
965
|
+
private static parseCredential(raw: any, pool: IZLPStakePool): IZLPCredential {
|
|
966
|
+
const stakedAmount = BigInt(raw.data.content.fields.stake)
|
|
967
|
+
const accRewardPerShare = BigInt(
|
|
968
|
+
raw.data.content.fields.acc_reward_per_share,
|
|
969
|
+
)
|
|
970
|
+
return {
|
|
971
|
+
id: raw.data.objectId,
|
|
972
|
+
lockUntil: parseValue(raw.data.content.fields.lock_until),
|
|
973
|
+
amount: stakedAmount,
|
|
974
|
+
accRewardPerShare,
|
|
975
|
+
claimable:
|
|
976
|
+
((pool.accRewardPerShare - accRewardPerShare) * stakedAmount)
|
|
977
|
+
/ BigInt(1e18),
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
private static parseStakePool(raw: any): IZLPStakePool {
|
|
982
|
+
const content = raw.data.content.fields
|
|
983
|
+
const pool = {
|
|
984
|
+
id: content.id.id,
|
|
985
|
+
enabled: content.enabled,
|
|
986
|
+
lastUpdatedTime: parseValue(content.last_updated_time),
|
|
987
|
+
stakedAmount: BigInt(content.staked_amount),
|
|
988
|
+
reward: BigInt(content.reward_vault),
|
|
989
|
+
startTime: parseValue(content.start_time),
|
|
990
|
+
endTime: parseValue(content.end_time),
|
|
991
|
+
rewardRate: BigInt(content.reward_rate),
|
|
992
|
+
accRewardPerShare: BigInt(content.acc_reward_per_share),
|
|
993
|
+
lockDuration: parseValue(content.lock_duration),
|
|
994
|
+
}
|
|
995
|
+
ZLPDataAPI.refreshPool(pool, Math.floor(Date.now() / 1000))
|
|
996
|
+
return pool
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
private static refreshPool(pool: IZLPStakePool, timestamp: number): void {
|
|
1000
|
+
if (timestamp <= pool.lastUpdatedTime || timestamp < pool.startTime) {
|
|
1001
|
+
return
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
const applicableEndTime = Math.max(pool.endTime, pool.lastUpdatedTime)
|
|
1005
|
+
|
|
1006
|
+
const calculationEndTime = Math.min(timestamp, applicableEndTime)
|
|
1007
|
+
|
|
1008
|
+
if (calculationEndTime > pool.lastUpdatedTime && pool.stakedAmount > BigInt(0) && pool.rewardRate > BigInt(0)) {
|
|
1009
|
+
const timeDiff = BigInt(calculationEndTime - pool.lastUpdatedTime)
|
|
1010
|
+
const rewardAmount = timeDiff * pool.rewardRate
|
|
1011
|
+
const rewardPerShare = (rewardAmount * BigInt(1e18)) / pool.stakedAmount
|
|
1012
|
+
pool.accRewardPerShare += rewardPerShare
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
pool.lastUpdatedTime = calculationEndTime
|
|
1016
|
+
}
|
|
910
1017
|
}
|
package/src/interfaces/base.ts
CHANGED
|
@@ -372,7 +372,9 @@ export interface IBaseAPI {
|
|
|
372
372
|
indexToken: string,
|
|
373
373
|
amount: number,
|
|
374
374
|
coinObjects: string[],
|
|
375
|
-
long: boolean
|
|
375
|
+
long: boolean,
|
|
376
|
+
sponsoredTx?: boolean,
|
|
377
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
376
378
|
) => Promise<Transaction>
|
|
377
379
|
|
|
378
380
|
redeemFromPosition: (
|
|
@@ -380,7 +382,9 @@ export interface IBaseAPI {
|
|
|
380
382
|
collateralToken: string,
|
|
381
383
|
indexToken: string,
|
|
382
384
|
amount: number,
|
|
383
|
-
long: boolean
|
|
385
|
+
long: boolean,
|
|
386
|
+
sponsoredTx?: boolean,
|
|
387
|
+
suiCoinObjectsForPythUpdate?: string[],
|
|
384
388
|
) => Promise<Transaction>
|
|
385
389
|
|
|
386
390
|
cancelOrder: (
|
package/src/interfaces/slp.ts
CHANGED
|
@@ -56,7 +56,10 @@ export interface ISLPHistory extends IBaseHistory { }
|
|
|
56
56
|
|
|
57
57
|
export interface ISLPStaked extends IBaseStaked { }
|
|
58
58
|
|
|
59
|
-
export interface ISLPStakePool extends IBaseStakePool {
|
|
59
|
+
export interface ISLPStakePool extends IBaseStakePool {
|
|
60
|
+
// SLP-specific stake pool fields to match new staking implementation
|
|
61
|
+
rewardRate?: bigint // Optional for backward compatibility
|
|
62
|
+
}
|
|
60
63
|
|
|
61
64
|
export interface ISLPCredential extends IBaseCredential { }
|
|
62
65
|
|
package/src/interfaces/zlp.ts
CHANGED
package/src/oracle.ts
CHANGED
|
@@ -4,12 +4,13 @@ import type { PriceFeed } from '@pythnetwork/pyth-sui-js'
|
|
|
4
4
|
import { SuiPriceServiceConnection, SuiPythClient } from '@pythnetwork/pyth-sui-js'
|
|
5
5
|
|
|
6
6
|
import type { IConsts, Network } from './consts'
|
|
7
|
-
import { getConsts, getPriceIdToPythFeeder, getPythFeederToId, getPythFeederToPriceId, LPToken } from './consts'
|
|
7
|
+
import { getConsts, getPriceIdToPythFeeder, getPythFeederToId, getPythFeederToPriceId, getSharedConfig, LPToken } from './consts'
|
|
8
8
|
import { createJsonRpcProvider } from './utils'
|
|
9
9
|
|
|
10
10
|
export class OracleAPI {
|
|
11
11
|
network: Network
|
|
12
12
|
consts: IConsts
|
|
13
|
+
sharedConfig: IConsts
|
|
13
14
|
connectionURL: string
|
|
14
15
|
PythFeederToPriceId: Record<string, string>
|
|
15
16
|
PythFeederToId: Record<string, string>
|
|
@@ -27,6 +28,7 @@ export class OracleAPI {
|
|
|
27
28
|
) {
|
|
28
29
|
this.network = network
|
|
29
30
|
this.consts = getConsts(network, lpToken)
|
|
31
|
+
this.sharedConfig = getSharedConfig(network)
|
|
30
32
|
this.connectionURL = connectionURL
|
|
31
33
|
this.PythFeederToPriceId = getPythFeederToPriceId(network)
|
|
32
34
|
this.PythFeederToId = getPythFeederToId(network)
|
package/src/utils.ts
CHANGED
|
@@ -123,8 +123,8 @@ export function parseSymbolKey(input: string): string[] {
|
|
|
123
123
|
// Add the last word to the result array
|
|
124
124
|
result.push(input.slice(wordStart))
|
|
125
125
|
|
|
126
|
-
// Convert the words to lowercase
|
|
127
|
-
result = result.map(word => word.toLowerCase())
|
|
126
|
+
// Convert the words to lowercase, handle words ending with '_'
|
|
127
|
+
result = result.map(word => word.endsWith('_') ? word.slice(0, -1).toLowerCase() : word.toLowerCase())
|
|
128
128
|
|
|
129
129
|
return result
|
|
130
130
|
}
|