zo-sdk 0.0.50 → 0.1.0
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 +272 -20
- package/dist/abstract/BaseAPI.cjs +117 -0
- package/dist/abstract/BaseAPI.cjs.map +1 -0
- package/dist/abstract/BaseAPI.d.cts +131 -0
- package/dist/abstract/BaseAPI.d.cts.map +1 -0
- package/dist/abstract/BaseAPI.d.mts +131 -0
- package/dist/abstract/BaseAPI.d.mts.map +1 -0
- package/dist/abstract/BaseAPI.mjs +113 -0
- package/dist/abstract/BaseAPI.mjs.map +1 -0
- package/dist/abstract/BaseDataAPI.cjs +139 -0
- package/dist/abstract/BaseDataAPI.cjs.map +1 -0
- package/dist/abstract/BaseDataAPI.d.cts +89 -0
- package/dist/abstract/BaseDataAPI.d.cts.map +1 -0
- package/dist/abstract/BaseDataAPI.d.mts +89 -0
- package/dist/abstract/BaseDataAPI.d.mts.map +1 -0
- package/dist/abstract/BaseDataAPI.mjs +135 -0
- package/dist/abstract/BaseDataAPI.mjs.map +1 -0
- package/dist/abstract/index.cjs +12 -0
- package/dist/abstract/index.cjs.map +1 -0
- package/dist/abstract/index.d.cts +7 -0
- package/dist/abstract/index.d.cts.map +1 -0
- package/dist/abstract/index.d.mts +7 -0
- package/dist/abstract/index.d.mts.map +1 -0
- package/dist/abstract/index.mjs +7 -0
- package/dist/abstract/index.mjs.map +1 -0
- package/dist/bcs.cjs +42 -0
- package/dist/bcs.cjs.map +1 -0
- package/dist/bcs.d.cts +91 -0
- package/dist/bcs.d.cts.map +1 -0
- package/dist/bcs.d.mts +91 -0
- package/dist/bcs.d.mts.map +1 -0
- package/dist/bcs.mjs +39 -0
- package/dist/bcs.mjs.map +1 -0
- package/dist/consts/deployments-slp-mainnet.json +710 -0
- package/dist/consts/deployments-slp-testnet.json +109 -0
- package/dist/consts/deployments-usdz-mainnet.json +180 -0
- package/dist/consts/deployments-usdz-testnet.json +98 -0
- package/dist/consts/{deployments-mainnet.json → deployments-zlp-mainnet.json} +278 -42
- package/dist/consts/index.cjs +40 -8
- package/dist/consts/index.cjs.map +1 -1
- package/dist/consts/index.d.cts +81 -11
- package/dist/consts/index.d.cts.map +1 -1
- package/dist/consts/index.d.mts +81 -11
- package/dist/consts/index.d.mts.map +1 -1
- package/dist/consts/index.mjs +39 -7
- package/dist/consts/index.mjs.map +1 -1
- package/dist/consts/price_id_to_object_id.mainnet.json +9 -1
- package/dist/data.cjs +2 -2
- package/dist/data.cjs.map +1 -1
- package/dist/data.mjs +2 -2
- package/dist/data.mjs.map +1 -1
- package/dist/factory/SDKFactory.cjs +185 -0
- package/dist/factory/SDKFactory.cjs.map +1 -0
- package/dist/factory/SDKFactory.d.cts +74 -0
- package/dist/factory/SDKFactory.d.cts.map +1 -0
- package/dist/factory/SDKFactory.d.mts +74 -0
- package/dist/factory/SDKFactory.d.mts.map +1 -0
- package/dist/factory/SDKFactory.mjs +179 -0
- package/dist/factory/SDKFactory.mjs.map +1 -0
- package/dist/implementations/SLPAPI.cjs +829 -0
- package/dist/implementations/SLPAPI.cjs.map +1 -0
- package/dist/implementations/SLPAPI.d.cts +120 -0
- package/dist/implementations/SLPAPI.d.cts.map +1 -0
- package/dist/implementations/SLPAPI.d.mts +120 -0
- package/dist/implementations/SLPAPI.d.mts.map +1 -0
- package/dist/implementations/SLPAPI.mjs +825 -0
- package/dist/implementations/SLPAPI.mjs.map +1 -0
- package/dist/implementations/SLPDataAPI.cjs +916 -0
- package/dist/implementations/SLPDataAPI.cjs.map +1 -0
- package/dist/implementations/SLPDataAPI.d.cts +102 -0
- package/dist/implementations/SLPDataAPI.d.cts.map +1 -0
- package/dist/implementations/SLPDataAPI.d.mts +102 -0
- package/dist/implementations/SLPDataAPI.d.mts.map +1 -0
- package/dist/implementations/SLPDataAPI.mjs +912 -0
- package/dist/implementations/SLPDataAPI.mjs.map +1 -0
- package/dist/implementations/USDZAPI.cjs +522 -0
- package/dist/implementations/USDZAPI.cjs.map +1 -0
- package/dist/implementations/USDZAPI.d.cts +118 -0
- package/dist/implementations/USDZAPI.d.cts.map +1 -0
- package/dist/implementations/USDZAPI.d.mts +118 -0
- package/dist/implementations/USDZAPI.d.mts.map +1 -0
- package/dist/implementations/USDZAPI.mjs +518 -0
- package/dist/implementations/USDZAPI.mjs.map +1 -0
- package/dist/implementations/USDZDataAPI.cjs +697 -0
- package/dist/implementations/USDZDataAPI.cjs.map +1 -0
- package/dist/implementations/USDZDataAPI.d.cts +86 -0
- package/dist/implementations/USDZDataAPI.d.cts.map +1 -0
- package/dist/implementations/USDZDataAPI.d.mts +86 -0
- package/dist/implementations/USDZDataAPI.d.mts.map +1 -0
- package/dist/implementations/USDZDataAPI.mjs +693 -0
- package/dist/implementations/USDZDataAPI.mjs.map +1 -0
- package/dist/implementations/ZLPAPI.cjs +809 -0
- package/dist/implementations/ZLPAPI.cjs.map +1 -0
- package/dist/implementations/ZLPAPI.d.cts +121 -0
- package/dist/implementations/ZLPAPI.d.cts.map +1 -0
- package/dist/implementations/ZLPAPI.d.mts +121 -0
- package/dist/implementations/ZLPAPI.d.mts.map +1 -0
- package/dist/implementations/ZLPAPI.mjs +805 -0
- package/dist/implementations/ZLPAPI.mjs.map +1 -0
- package/dist/implementations/ZLPDataAPI.cjs +724 -0
- package/dist/implementations/ZLPDataAPI.cjs.map +1 -0
- package/dist/implementations/ZLPDataAPI.d.cts +83 -0
- package/dist/implementations/ZLPDataAPI.d.cts.map +1 -0
- package/dist/implementations/ZLPDataAPI.d.mts +83 -0
- package/dist/implementations/ZLPDataAPI.d.mts.map +1 -0
- package/dist/implementations/ZLPDataAPI.mjs +720 -0
- package/dist/implementations/ZLPDataAPI.mjs.map +1 -0
- package/dist/implementations/index.cjs +22 -0
- package/dist/implementations/index.cjs.map +1 -0
- package/dist/implementations/index.d.cts +11 -0
- package/dist/implementations/index.d.cts.map +1 -0
- package/dist/implementations/index.d.mts +11 -0
- package/dist/implementations/index.d.mts.map +1 -0
- package/dist/implementations/index.mjs +13 -0
- package/dist/implementations/index.mjs.map +1 -0
- package/dist/index.cjs +47 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +45 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +45 -0
- package/dist/index.mjs.map +1 -1
- package/dist/interfaces/base.cjs +8 -0
- package/dist/interfaces/base.cjs.map +1 -0
- package/dist/interfaces/base.d.cts +293 -0
- package/dist/interfaces/base.d.cts.map +1 -0
- package/dist/interfaces/base.d.mts +293 -0
- package/dist/interfaces/base.d.mts.map +1 -0
- package/dist/interfaces/base.mjs +6 -0
- package/dist/interfaces/base.mjs.map +1 -0
- package/dist/interfaces/index.cjs +29 -0
- package/dist/interfaces/index.cjs.map +1 -0
- package/dist/interfaces/index.d.cts +13 -0
- package/dist/interfaces/index.d.cts.map +1 -0
- package/dist/interfaces/index.d.mts +13 -0
- package/dist/interfaces/index.d.mts.map +1 -0
- package/dist/interfaces/index.mjs +13 -0
- package/dist/interfaces/index.mjs.map +1 -0
- package/dist/interfaces/slp.cjs +9 -0
- package/dist/interfaces/slp.cjs.map +1 -0
- package/dist/interfaces/slp.d.cts +115 -0
- package/dist/interfaces/slp.d.cts.map +1 -0
- package/dist/interfaces/slp.d.mts +115 -0
- package/dist/interfaces/slp.d.mts.map +1 -0
- package/dist/interfaces/slp.mjs +7 -0
- package/dist/interfaces/slp.mjs.map +1 -0
- package/dist/interfaces/usdz.cjs +7 -0
- package/dist/interfaces/usdz.cjs.map +1 -0
- package/dist/interfaces/usdz.d.cts +40 -0
- package/dist/interfaces/usdz.d.cts.map +1 -0
- package/dist/interfaces/usdz.d.mts +40 -0
- package/dist/interfaces/usdz.d.mts.map +1 -0
- package/dist/interfaces/usdz.mjs +6 -0
- package/dist/interfaces/usdz.mjs.map +1 -0
- package/dist/interfaces/zlp.cjs +7 -0
- package/dist/interfaces/zlp.cjs.map +1 -0
- package/dist/interfaces/zlp.d.cts +45 -0
- package/dist/interfaces/zlp.d.cts.map +1 -0
- package/dist/interfaces/zlp.d.mts +45 -0
- package/dist/interfaces/zlp.d.mts.map +1 -0
- package/dist/interfaces/zlp.mjs +6 -0
- package/dist/interfaces/zlp.mjs.map +1 -0
- package/dist/oracle.cjs +7 -35
- package/dist/oracle.cjs.map +1 -1
- package/dist/oracle.d.cts +3 -4
- package/dist/oracle.d.cts.map +1 -1
- package/dist/oracle.d.mts +3 -4
- package/dist/oracle.d.mts.map +1 -1
- package/dist/oracle.mjs +8 -32
- package/dist/oracle.mjs.map +1 -1
- package/package.json +1 -1
- package/src/abstract/BaseAPI.ts +429 -0
- package/src/abstract/BaseDataAPI.ts +204 -0
- package/src/abstract/index.ts +7 -0
- package/src/bcs.ts +45 -0
- package/src/consts/deployments-slp-mainnet.json +710 -0
- package/src/consts/deployments-slp-testnet.json +109 -0
- package/src/consts/deployments-usdz-mainnet.json +180 -0
- package/src/consts/deployments-usdz-testnet.json +98 -0
- package/src/consts/{deployments-mainnet.json → deployments-zlp-mainnet.json} +279 -43
- package/src/consts/index.ts +134 -39
- package/src/consts/price_id_to_object_id.mainnet.json +10 -2
- package/src/data.ts +2 -2
- package/src/factory/SDKFactory.ts +282 -0
- package/src/implementations/SLPAPI.ts +1207 -0
- package/src/implementations/SLPDataAPI.ts +1188 -0
- package/src/implementations/USDZAPI.ts +715 -0
- package/src/implementations/USDZDataAPI.ts +826 -0
- package/src/implementations/ZLPAPI.ts +1130 -0
- package/src/implementations/ZLPDataAPI.ts +856 -0
- package/src/implementations/index.ts +14 -0
- package/src/index.ts +53 -0
- package/src/interfaces/base.ts +556 -0
- package/src/interfaces/index.ts +45 -0
- package/src/interfaces/slp.ts +156 -0
- package/src/interfaces/usdz.ts +71 -0
- package/src/interfaces/zlp.ts +96 -0
- package/src/oracle.ts +12 -42
- package/tsconfig.json +4 -2
- package/dist/consts/staking/deployments-mainnet.json +0 -12
- package/dist/consts/staking/deployments-testnet.json +0 -11
- package/src/consts/staking/deployments-mainnet.json +0 -12
- package/src/consts/staking/deployments-testnet.json +0 -11
- /package/dist/consts/{deployments-testnet.json → deployments-zlp-testnet.json} +0 -0
- /package/src/consts/{deployments-testnet.json → deployments-zlp-testnet.json} +0 -0
package/src/consts/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { reverseKeyValue } from '../utils'
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import zlpMainnetJson from './deployments-zlp-mainnet.json'
|
|
3
|
+
import zlpTestnetJson from './deployments-zlp-testnet.json'
|
|
4
|
+
import usdzMainnetJson from './deployments-usdz-mainnet.json'
|
|
5
|
+
import usdzTestnetJson from './deployments-usdz-testnet.json'
|
|
6
|
+
import slpMainnetJson from './deployments-slp-mainnet.json'
|
|
7
|
+
import slpTestnetJson from './deployments-slp-testnet.json'
|
|
4
8
|
import PriceIdToObjectIdMainnet from './price_id_to_object_id.mainnet.json'
|
|
5
9
|
import PriceIdToObjectIdTestnet from './price_id_to_object_id.testnet.json'
|
|
6
|
-
import mainnetStakingJson from './staking/deployments-mainnet.json'
|
|
7
|
-
import testnetStakingJson from './staking/deployments-testnet.json'
|
|
8
10
|
|
|
9
11
|
interface IVault {
|
|
10
12
|
weight: string
|
|
@@ -25,8 +27,8 @@ interface ICoin {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
interface IPrizePool {
|
|
28
|
-
id: string
|
|
29
|
-
display: string
|
|
30
|
+
id: string
|
|
31
|
+
display: string
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
type IVersionedContract = string
|
|
@@ -50,57 +52,120 @@ export interface IConsts {
|
|
|
50
52
|
referralsParent: string
|
|
51
53
|
ordersParent: string
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
sudoCore: {
|
|
54
56
|
package: string
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
upgradedPackage: string
|
|
58
|
+
upgradeCap: string
|
|
59
|
+
adminCap: string
|
|
60
|
+
market: IVersionedContract
|
|
61
|
+
slpMetadata: IVersionedContract
|
|
62
|
+
rebaseFeeModel: IVersionedContract
|
|
63
|
+
vaultsParent: string
|
|
64
|
+
symbolsParent: string
|
|
65
|
+
positionsParent: string
|
|
66
|
+
vaults: Record<string, IVault>
|
|
67
|
+
symbols: Record<string, ISymbol>
|
|
68
|
+
referralsParent: string
|
|
69
|
+
ordersParent: string
|
|
70
|
+
}
|
|
71
|
+
usdzCore: {
|
|
72
|
+
package: string
|
|
73
|
+
upgradedPackage: string
|
|
74
|
+
upgradeCap: string
|
|
75
|
+
adminCap: string
|
|
76
|
+
market: IVersionedContract
|
|
77
|
+
usdzMetadata: IVersionedContract
|
|
78
|
+
rebaseFeeModel: IVersionedContract
|
|
79
|
+
vaultsParent: string
|
|
80
|
+
symbolsParent: string
|
|
81
|
+
positionsParent: string
|
|
82
|
+
vaults: Record<string, IVault>
|
|
83
|
+
symbols: Record<string, ISymbol>
|
|
84
|
+
referralsParent: string
|
|
85
|
+
ordersParent: string
|
|
61
86
|
}
|
|
62
|
-
coins: Record<string, ICoin>
|
|
63
87
|
zoStaking: {
|
|
64
88
|
package: string
|
|
89
|
+
upgradedPackage: string
|
|
65
90
|
upgradeCap: string
|
|
66
91
|
adminCap: string
|
|
67
92
|
pool: string
|
|
68
93
|
},
|
|
69
94
|
zoLootbox: {
|
|
70
|
-
package: string
|
|
71
|
-
upgradedPackage: string
|
|
72
|
-
upgradeCap: string
|
|
73
|
-
adminCap: string
|
|
74
|
-
lootboxTreasury: string
|
|
75
|
-
lootboxSettings: string
|
|
76
|
-
prizePoolParent: string
|
|
77
|
-
prizePools:
|
|
78
|
-
[key: string]: IPrizePool;
|
|
79
|
-
};
|
|
95
|
+
package: string
|
|
96
|
+
upgradedPackage: string
|
|
97
|
+
upgradeCap: string
|
|
98
|
+
adminCap: string
|
|
99
|
+
lootboxTreasury: string
|
|
100
|
+
lootboxSettings: string
|
|
101
|
+
prizePoolParent: string
|
|
102
|
+
prizePools: Record<string, IPrizePool>
|
|
80
103
|
}
|
|
104
|
+
sudoStaking: {
|
|
105
|
+
package: string
|
|
106
|
+
upgradedPackage: string
|
|
107
|
+
upgradeCap: string
|
|
108
|
+
adminCap: string
|
|
109
|
+
pool: string
|
|
110
|
+
}
|
|
111
|
+
sudoNft: {
|
|
112
|
+
package: string
|
|
113
|
+
upgradedPackage: string
|
|
114
|
+
upgradeCap: string
|
|
115
|
+
adminCap: string
|
|
116
|
+
mintSettings: string
|
|
117
|
+
cardRegistry: string
|
|
118
|
+
displayCard: string
|
|
119
|
+
displayMintTicket: string
|
|
120
|
+
silverCardTracker: string
|
|
121
|
+
emeraldCardTracker: string
|
|
122
|
+
blackCardTracker: string
|
|
123
|
+
transferPolicy: string
|
|
124
|
+
transferPolicyCap: string
|
|
125
|
+
}
|
|
126
|
+
sudoLootbox: {
|
|
127
|
+
package: string
|
|
128
|
+
upgradedPackage: string
|
|
129
|
+
upgradeCap: string
|
|
130
|
+
adminCap: string
|
|
131
|
+
lootboxTreasury: string
|
|
132
|
+
lootboxSettings: string
|
|
133
|
+
prizePoolParent: string
|
|
134
|
+
prizePool: Record<string, IPrizePool>
|
|
135
|
+
}
|
|
136
|
+
pythFeeder: {
|
|
137
|
+
package: string
|
|
138
|
+
state: IVersionedContract
|
|
139
|
+
wormhole: {
|
|
140
|
+
package: string
|
|
141
|
+
state: IVersionedContract
|
|
142
|
+
}
|
|
143
|
+
feeder: IFeeder
|
|
144
|
+
}
|
|
145
|
+
coins: Record<string, ICoin>
|
|
81
146
|
}
|
|
82
147
|
|
|
83
148
|
function toCamelCase(str: string): string {
|
|
84
|
-
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
149
|
+
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
85
150
|
}
|
|
86
151
|
|
|
87
152
|
function parse(obj: any): any {
|
|
88
153
|
if (typeof obj !== 'object' || obj === null) {
|
|
89
|
-
return obj
|
|
154
|
+
return obj
|
|
90
155
|
}
|
|
91
156
|
|
|
92
157
|
if (Array.isArray(obj)) {
|
|
93
|
-
return obj.map(parse)
|
|
158
|
+
return obj.map(parse)
|
|
94
159
|
}
|
|
95
160
|
|
|
96
|
-
const newObj: any = {}
|
|
161
|
+
const newObj: any = {}
|
|
97
162
|
|
|
98
163
|
for (const key in obj) {
|
|
99
|
-
const camelCaseKey = toCamelCase(key)
|
|
100
|
-
newObj[camelCaseKey] = parse(obj[key])
|
|
164
|
+
const camelCaseKey = toCamelCase(key)
|
|
165
|
+
newObj[camelCaseKey] = parse(obj[key])
|
|
101
166
|
}
|
|
102
167
|
|
|
103
|
-
return newObj
|
|
168
|
+
return newObj
|
|
104
169
|
}
|
|
105
170
|
|
|
106
171
|
export enum Network {
|
|
@@ -109,17 +174,45 @@ export enum Network {
|
|
|
109
174
|
DEVNET = 'devnet',
|
|
110
175
|
}
|
|
111
176
|
|
|
177
|
+
export enum LPToken {
|
|
178
|
+
ZLP = 'ZLP',
|
|
179
|
+
USDZ = 'USDZ',
|
|
180
|
+
SLP = 'SLP',
|
|
181
|
+
}
|
|
182
|
+
|
|
112
183
|
function throwNetworkError(network: string): never {
|
|
113
184
|
throw new Error(`Unknown network: ${network}`)
|
|
114
185
|
}
|
|
115
186
|
|
|
116
|
-
export function getConsts(network: string): IConsts {
|
|
187
|
+
export function getConsts(network: string, lpToken: LPToken = LPToken.ZLP): IConsts {
|
|
117
188
|
switch (network) {
|
|
118
189
|
case Network.TESTNET: {
|
|
119
|
-
|
|
190
|
+
let testnetDeployment
|
|
191
|
+
switch (lpToken) {
|
|
192
|
+
case LPToken.USDZ:
|
|
193
|
+
testnetDeployment = usdzTestnetJson
|
|
194
|
+
break
|
|
195
|
+
case LPToken.SLP:
|
|
196
|
+
testnetDeployment = slpTestnetJson
|
|
197
|
+
break
|
|
198
|
+
default:
|
|
199
|
+
testnetDeployment = zlpTestnetJson
|
|
200
|
+
}
|
|
201
|
+
return { ...parse(testnetDeployment) }
|
|
120
202
|
}
|
|
121
203
|
case Network.MAINNET: {
|
|
122
|
-
|
|
204
|
+
let mainnetDeployment
|
|
205
|
+
switch (lpToken) {
|
|
206
|
+
case LPToken.USDZ:
|
|
207
|
+
mainnetDeployment = usdzMainnetJson
|
|
208
|
+
break
|
|
209
|
+
case LPToken.SLP:
|
|
210
|
+
mainnetDeployment = slpMainnetJson
|
|
211
|
+
break
|
|
212
|
+
default:
|
|
213
|
+
mainnetDeployment = zlpMainnetJson
|
|
214
|
+
}
|
|
215
|
+
return { ...parse(mainnetDeployment) }
|
|
123
216
|
}
|
|
124
217
|
default: {
|
|
125
218
|
return throwNetworkError(network)
|
|
@@ -128,6 +221,8 @@ export function getConsts(network: string): IConsts {
|
|
|
128
221
|
}
|
|
129
222
|
|
|
130
223
|
export const ZLP_TOKEN_DECIMALS = 6
|
|
224
|
+
export const SLP_TOKEN_DECIMALS = 6
|
|
225
|
+
export const USDZ_TOKEN_DECIMALS = 6
|
|
131
226
|
|
|
132
227
|
export const SECONDS_PER_EIGHT_HOUR = 8 * 60 * 60
|
|
133
228
|
|
|
@@ -164,15 +259,15 @@ export function getPriceIdToPythFeeder(network: Network): Record<string, string>
|
|
|
164
259
|
}
|
|
165
260
|
|
|
166
261
|
export function getPythFeederToId(network: string): Record<string, string> {
|
|
167
|
-
let feederToId: Record<string, string> = {}
|
|
168
|
-
const consts = getConsts(network)
|
|
262
|
+
let feederToId: Record<string, string> = {}
|
|
263
|
+
const consts = getConsts(network)
|
|
169
264
|
for (const key in consts.pythFeeder.feeder) {
|
|
170
265
|
if (Object.prototype.hasOwnProperty.call(consts.pythFeeder.feeder, key)) {
|
|
171
|
-
const contract = consts.pythFeeder.feeder[key]
|
|
172
|
-
feederToId[contract] = key
|
|
266
|
+
const contract = consts.pythFeeder.feeder[key]
|
|
267
|
+
feederToId[contract] = key
|
|
173
268
|
}
|
|
174
269
|
}
|
|
175
|
-
return feederToId
|
|
270
|
+
return feederToId
|
|
176
271
|
}
|
|
177
272
|
|
|
178
273
|
export const ALLOW_TRADE_NO_TRADE = 0
|
|
@@ -21,5 +21,13 @@
|
|
|
21
21
|
"0a0408d619e9380abad35060f9192039ed5042fa6f82301d0e48bb52be830996": "0xb804ada6f77feb30a73fbed7fc53dc66ff25133dee0815109d4267e43b2e6bdd",
|
|
22
22
|
"2b9ab1e972a281585084148ba1389800799bd4be63b957507db1349314e47445": "0x4d1862d9ca2ad1f054f606220c22e0bcf37330d57bb82baa2063fd8193fc24ae",
|
|
23
23
|
"58cd29ef0e714c5affc44f269b2c1899a52da4169d7acc147b9da692e6953608": "0x330c38d9af008421306242945f9308dc80c0c6a3e30b289a079fbff5ceeb4696",
|
|
24
|
-
"8414cfadf82f6bed644d2e399c11df21ec0131aa574c56030b132113dbbf3a0a": "0xbfa0e395413d94a7c45a9b987431a313a6e9da2e1b892f1924f64a0aff21e59f"
|
|
25
|
-
|
|
24
|
+
"8414cfadf82f6bed644d2e399c11df21ec0131aa574c56030b132113dbbf3a0a": "0xbfa0e395413d94a7c45a9b987431a313a6e9da2e1b892f1924f64a0aff21e59f",
|
|
25
|
+
"09f7c1d7dfbb7df2b8fe3d3d87ee94a2259d212da4f30c1f0540d066dfa44723": "0xfa3d517e6ae2647708313f811fe7f481f8254cd738073e3e23dfca3b578c21d2",
|
|
26
|
+
"eff7446475e218517566ea99e72a4abec2e1bd8498b43b7d8331e29dcb059389": "0xd2e6ed72dcd8922164e1aa833ff39077cf01cb55b41a37324e8baccf93b1be9d",
|
|
27
|
+
"17cd845b16e874485b2684f8b8d1517d744105dbb904eec30222717f4bc9ee0d": "0xd779885c5246357e24cbde7348f2d81f756d9650975c02d81346b15d8b557ebf",
|
|
28
|
+
"57ff7100a282e4af0c91154679c5dae2e5dcacb93fd467ea9cb7e58afdcfde27": "0xf3bc79117acc3636d57778d9d0f83a871df1b7a53eb61fe893ff108d9664ec8b",
|
|
29
|
+
"fdf28a46570252b25fd31cb257973f865afc5ca2f320439e45d95e0394bc7382": "0x3ef821a54dbdfe3f211b2ff7261dea0f0330c72fd292422ce586e21f43809a56",
|
|
30
|
+
"d9912df360b5b7f21a122f15bdd5e27f62ce5e72bd316c291f7c86620e07fb2a": "0x94ef89923e7beccd4a52043a9451a87c614684b847426fb5fd76faa8cb1e907f",
|
|
31
|
+
"bb5ff26e47a3a6cc7ec2fce1db996c2a145300edc5acaabe43bf9ff7c5dd5d32": "0xc6352e1ea55d7b5acc3ed690cc3cdf8007978071d7bfd6a189445018cfb366e0",
|
|
32
|
+
"03ae4db29ed4ae33d323568895aa00337e658e348b37509f5372ae51f0af00d5": "0x7c5b7837c44a69b469325463ac0673ac1aa8435ff44ddb4191c9ae380463647f"
|
|
33
|
+
}
|
package/src/data.ts
CHANGED
|
@@ -592,7 +592,7 @@ export class DataAPI extends OracleAPI {
|
|
|
592
592
|
|
|
593
593
|
#calculatePositionFundingFee(position: IPositionInfo, symbol: ISymbolInfo, model: IFundingFeeModel, price: number, lpSupplyAmount: number, timestamp: number): number {
|
|
594
594
|
const accFundingRate = this.#calcAccFundingFeeRate(symbol, model, price, lpSupplyAmount, timestamp)
|
|
595
|
-
return position.fundingFeeValue + (accFundingRate -
|
|
595
|
+
return position.fundingFeeValue + (accFundingRate - position.lastFundingRate) * position.positionSize
|
|
596
596
|
}
|
|
597
597
|
|
|
598
598
|
#calculateVaultReservingFee(vault: IVaultInfo, model: IReservingFeeModel, timestamp: number): number {
|
|
@@ -602,7 +602,7 @@ export class DataAPI extends OracleAPI {
|
|
|
602
602
|
|
|
603
603
|
#calculatePositionReserveFee(position: IPositionInfo, vault: IVaultInfo, model: IReservingFeeModel, timestamp: number): number {
|
|
604
604
|
const accReservingRate = this.#calcAccReservingFeeRate(vault, model, timestamp)
|
|
605
|
-
return position.reservingFeeAmount + (accReservingRate -
|
|
605
|
+
return position.reservingFeeAmount + (accReservingRate - position.lastReservingRate) * position.collateralAmount
|
|
606
606
|
}
|
|
607
607
|
|
|
608
608
|
public async getPastFee(days = 7) {
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Factory for creating appropriate SDK instances based on LP token type
|
|
3
|
+
* This is the main entry point for the re-architected SDK system
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { SuiClient } from '@mysten/sui/client'
|
|
7
|
+
import type { Network, LPToken } from '../consts'
|
|
8
|
+
import { LPToken as LPTokenEnum } from '../consts'
|
|
9
|
+
import type {
|
|
10
|
+
IBaseDataAPI,
|
|
11
|
+
IBaseAPI,
|
|
12
|
+
ISDKFactory,
|
|
13
|
+
IZLPDataAPI,
|
|
14
|
+
IZLPAPI,
|
|
15
|
+
ISLPDataAPI,
|
|
16
|
+
ISLPAPI,
|
|
17
|
+
IUSDZDataAPI,
|
|
18
|
+
IUSDZAPI
|
|
19
|
+
} from '../interfaces'
|
|
20
|
+
|
|
21
|
+
// Import concrete implementations
|
|
22
|
+
import {
|
|
23
|
+
ZLPDataAPI,
|
|
24
|
+
ZLPAPI,
|
|
25
|
+
SLPDataAPI,
|
|
26
|
+
SLPAPI,
|
|
27
|
+
USDZDataAPI,
|
|
28
|
+
USDZAPI
|
|
29
|
+
} from '../implementations'
|
|
30
|
+
|
|
31
|
+
export class SDKFactory implements ISDKFactory {
|
|
32
|
+
private static instance: SDKFactory
|
|
33
|
+
|
|
34
|
+
// Singleton instances for DataAPI
|
|
35
|
+
private zlpDataAPIInstance: IZLPDataAPI | null = null
|
|
36
|
+
private slpDataAPIInstance: ISLPDataAPI | null = null
|
|
37
|
+
private usdzDataAPIInstance: IUSDZDataAPI | null = null
|
|
38
|
+
|
|
39
|
+
// Singleton instances for API
|
|
40
|
+
private zlpAPIInstance: IZLPAPI | null = null
|
|
41
|
+
private slpAPIInstance: ISLPAPI | null = null
|
|
42
|
+
private usdzAPIInstance: IUSDZAPI | null = null
|
|
43
|
+
|
|
44
|
+
private constructor() { }
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Gets the singleton instance of the SDK factory
|
|
48
|
+
*/
|
|
49
|
+
public static getInstance(): SDKFactory {
|
|
50
|
+
if (!SDKFactory.instance) {
|
|
51
|
+
SDKFactory.instance = new SDKFactory()
|
|
52
|
+
}
|
|
53
|
+
return SDKFactory.instance
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a DataAPI instance based on the LP token type (returns singleton)
|
|
58
|
+
*/
|
|
59
|
+
public createDataAPI(
|
|
60
|
+
network: Network,
|
|
61
|
+
provider: SuiClient,
|
|
62
|
+
apiEndpoint: string,
|
|
63
|
+
connectionURL: string,
|
|
64
|
+
lpToken: LPToken
|
|
65
|
+
): IBaseDataAPI {
|
|
66
|
+
switch (lpToken) {
|
|
67
|
+
case LPTokenEnum.ZLP:
|
|
68
|
+
if (!this.zlpDataAPIInstance) {
|
|
69
|
+
this.zlpDataAPIInstance = new ZLPDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
70
|
+
}
|
|
71
|
+
return this.zlpDataAPIInstance
|
|
72
|
+
case LPTokenEnum.SLP:
|
|
73
|
+
if (!this.slpDataAPIInstance) {
|
|
74
|
+
this.slpDataAPIInstance = new SLPDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
75
|
+
}
|
|
76
|
+
return this.slpDataAPIInstance
|
|
77
|
+
case LPTokenEnum.USDZ:
|
|
78
|
+
if (!this.usdzDataAPIInstance) {
|
|
79
|
+
this.usdzDataAPIInstance = new USDZDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
80
|
+
}
|
|
81
|
+
return this.usdzDataAPIInstance
|
|
82
|
+
default:
|
|
83
|
+
throw new Error(`Unsupported LP token type: ${lpToken}`)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Creates an API instance based on the LP token type (returns singleton)
|
|
89
|
+
*/
|
|
90
|
+
public createAPI(
|
|
91
|
+
network: Network,
|
|
92
|
+
provider: SuiClient,
|
|
93
|
+
apiEndpoint: string,
|
|
94
|
+
connectionURL: string,
|
|
95
|
+
lpToken: LPToken
|
|
96
|
+
): IBaseAPI {
|
|
97
|
+
switch (lpToken) {
|
|
98
|
+
case LPTokenEnum.ZLP:
|
|
99
|
+
if (!this.zlpAPIInstance) {
|
|
100
|
+
this.zlpAPIInstance = new ZLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
101
|
+
}
|
|
102
|
+
return this.zlpAPIInstance
|
|
103
|
+
case LPTokenEnum.SLP:
|
|
104
|
+
if (!this.slpAPIInstance) {
|
|
105
|
+
this.slpAPIInstance = new SLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
106
|
+
}
|
|
107
|
+
return this.slpAPIInstance
|
|
108
|
+
case LPTokenEnum.USDZ:
|
|
109
|
+
if (!this.usdzAPIInstance) {
|
|
110
|
+
this.usdzAPIInstance = new USDZAPI(network, provider, apiEndpoint, connectionURL)
|
|
111
|
+
}
|
|
112
|
+
return this.usdzAPIInstance
|
|
113
|
+
default:
|
|
114
|
+
throw new Error(`Unsupported LP token type: ${lpToken}`)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Creates a typed DataAPI instance for ZLP (returns singleton)
|
|
120
|
+
*/
|
|
121
|
+
public createZLPDataAPI(
|
|
122
|
+
network: Network,
|
|
123
|
+
provider: SuiClient,
|
|
124
|
+
apiEndpoint: string,
|
|
125
|
+
connectionURL: string
|
|
126
|
+
): IZLPDataAPI {
|
|
127
|
+
if (!this.zlpDataAPIInstance) {
|
|
128
|
+
this.zlpDataAPIInstance = new ZLPDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
129
|
+
}
|
|
130
|
+
return this.zlpDataAPIInstance
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Creates a typed API instance for ZLP (returns singleton)
|
|
135
|
+
*/
|
|
136
|
+
public createZLPAPI(
|
|
137
|
+
network: Network,
|
|
138
|
+
provider: SuiClient,
|
|
139
|
+
apiEndpoint: string,
|
|
140
|
+
connectionURL: string
|
|
141
|
+
): IZLPAPI {
|
|
142
|
+
if (!this.zlpAPIInstance) {
|
|
143
|
+
this.zlpAPIInstance = new ZLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
144
|
+
}
|
|
145
|
+
return this.zlpAPIInstance
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Creates a typed DataAPI instance for SLP (returns singleton)
|
|
150
|
+
*/
|
|
151
|
+
public createSLPDataAPI(
|
|
152
|
+
network: Network,
|
|
153
|
+
provider: SuiClient,
|
|
154
|
+
apiEndpoint: string,
|
|
155
|
+
connectionURL: string
|
|
156
|
+
): ISLPDataAPI {
|
|
157
|
+
if (!this.slpDataAPIInstance) {
|
|
158
|
+
this.slpDataAPIInstance = new SLPDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
159
|
+
}
|
|
160
|
+
return this.slpDataAPIInstance
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Creates a typed API instance for SLP (returns singleton)
|
|
165
|
+
*/
|
|
166
|
+
public createSLPAPI(
|
|
167
|
+
network: Network,
|
|
168
|
+
provider: SuiClient,
|
|
169
|
+
apiEndpoint: string,
|
|
170
|
+
connectionURL: string
|
|
171
|
+
): ISLPAPI {
|
|
172
|
+
if (!this.slpAPIInstance) {
|
|
173
|
+
this.slpAPIInstance = new SLPAPI(network, provider, apiEndpoint, connectionURL)
|
|
174
|
+
}
|
|
175
|
+
return this.slpAPIInstance
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Creates a typed DataAPI instance for USDZ (returns singleton)
|
|
180
|
+
*/
|
|
181
|
+
public createUSDZDataAPI(
|
|
182
|
+
network: Network,
|
|
183
|
+
provider: SuiClient,
|
|
184
|
+
apiEndpoint: string,
|
|
185
|
+
connectionURL: string
|
|
186
|
+
): IUSDZDataAPI {
|
|
187
|
+
if (!this.usdzDataAPIInstance) {
|
|
188
|
+
this.usdzDataAPIInstance = new USDZDataAPI(network, provider, apiEndpoint, connectionURL)
|
|
189
|
+
}
|
|
190
|
+
return this.usdzDataAPIInstance
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Creates a typed API instance for USDZ (returns singleton)
|
|
195
|
+
*/
|
|
196
|
+
public createUSDZAPI(
|
|
197
|
+
network: Network,
|
|
198
|
+
provider: SuiClient,
|
|
199
|
+
apiEndpoint: string,
|
|
200
|
+
connectionURL: string
|
|
201
|
+
): IUSDZAPI {
|
|
202
|
+
if (!this.usdzAPIInstance) {
|
|
203
|
+
this.usdzAPIInstance = new USDZAPI(network, provider, apiEndpoint, connectionURL)
|
|
204
|
+
}
|
|
205
|
+
return this.usdzAPIInstance
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Validates if a given LP token is supported
|
|
210
|
+
*/
|
|
211
|
+
public isLPTokenSupported(lpToken: string): lpToken is LPToken {
|
|
212
|
+
return Object.values(LPTokenEnum).includes(lpToken as LPToken)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Gets all supported LP token types
|
|
217
|
+
*/
|
|
218
|
+
public getSupportedLPTokens(): LPToken[] {
|
|
219
|
+
return Object.values(LPTokenEnum)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Clears all singleton instances (useful for testing or configuration changes)
|
|
224
|
+
*/
|
|
225
|
+
public clearInstances(): void {
|
|
226
|
+
this.zlpDataAPIInstance = null
|
|
227
|
+
this.slpDataAPIInstance = null
|
|
228
|
+
this.usdzDataAPIInstance = null
|
|
229
|
+
this.zlpAPIInstance = null
|
|
230
|
+
this.slpAPIInstance = null
|
|
231
|
+
this.usdzAPIInstance = null
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Creates the appropriate SDK instance based on string LP token type
|
|
236
|
+
* Useful for dynamic SDK creation from configuration
|
|
237
|
+
*/
|
|
238
|
+
public createSDKFromString(
|
|
239
|
+
lpTokenString: string,
|
|
240
|
+
network: Network,
|
|
241
|
+
provider: SuiClient,
|
|
242
|
+
apiEndpoint: string,
|
|
243
|
+
connectionURL: string,
|
|
244
|
+
includeTrading = true
|
|
245
|
+
): IBaseDataAPI | IBaseAPI {
|
|
246
|
+
if (!this.isLPTokenSupported(lpTokenString)) {
|
|
247
|
+
throw new Error(`Unsupported LP token: ${lpTokenString}`)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const lpToken = lpTokenString as LPToken
|
|
251
|
+
|
|
252
|
+
if (includeTrading) {
|
|
253
|
+
return this.createAPI(network, provider, apiEndpoint, connectionURL, lpToken)
|
|
254
|
+
} else {
|
|
255
|
+
return this.createDataAPI(network, provider, apiEndpoint, connectionURL, lpToken)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Export convenience functions for backward compatibility
|
|
261
|
+
export function createDataAPI(
|
|
262
|
+
network: Network,
|
|
263
|
+
provider: SuiClient,
|
|
264
|
+
apiEndpoint: string,
|
|
265
|
+
connectionURL: string,
|
|
266
|
+
lpToken: LPToken
|
|
267
|
+
): IBaseDataAPI {
|
|
268
|
+
return SDKFactory.getInstance().createDataAPI(network, provider, apiEndpoint, connectionURL, lpToken)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function createAPI(
|
|
272
|
+
network: Network,
|
|
273
|
+
provider: SuiClient,
|
|
274
|
+
apiEndpoint: string,
|
|
275
|
+
connectionURL: string,
|
|
276
|
+
lpToken: LPToken
|
|
277
|
+
): IBaseAPI {
|
|
278
|
+
return SDKFactory.getInstance().createAPI(network, provider, apiEndpoint, connectionURL, lpToken)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Export the singleton instance for direct use
|
|
282
|
+
export const sdkFactory = SDKFactory.getInstance()
|