zo-sdk 0.0.3
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/.gitattributes +4 -0
- package/.prettierrc.js +5 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/babel.config.js +11 -0
- package/dist/api.cjs +466 -0
- package/dist/api.d.cts +26 -0
- package/dist/api.d.cts.map +1 -0
- package/dist/api.d.mts +26 -0
- package/dist/api.d.mts.map +1 -0
- package/dist/api.mjs +462 -0
- package/dist/consts/deployments-mainnet.json +28 -0
- package/dist/consts/deployments-testnet.json +93 -0
- package/dist/consts/index.cjs +101 -0
- package/dist/consts/index.d.cts +66 -0
- package/dist/consts/index.d.cts.map +1 -0
- package/dist/consts/index.d.mts +66 -0
- package/dist/consts/index.d.mts.map +1 -0
- package/dist/consts/index.mjs +94 -0
- package/dist/consts/price_id_to_object_id.mainnet.json +1 -0
- package/dist/consts/price_id_to_object_id.testnet.json +17 -0
- package/dist/consts/staking/deployments-mainnet.json +12 -0
- package/dist/consts/staking/deployments-testnet.json +11 -0
- package/dist/data.cjs +844 -0
- package/dist/data.d.cts +221 -0
- package/dist/data.d.cts.map +1 -0
- package/dist/data.d.mts +221 -0
- package/dist/data.d.mts.map +1 -0
- package/dist/data.mjs +840 -0
- package/dist/index.cjs +21 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +5 -0
- package/dist/oracle.cjs +178 -0
- package/dist/oracle.d.cts +24 -0
- package/dist/oracle.d.cts.map +1 -0
- package/dist/oracle.d.mts +24 -0
- package/dist/oracle.d.mts.map +1 -0
- package/dist/oracle.mjs +173 -0
- package/dist/utils.cjs +144 -0
- package/dist/utils.d.cts +46 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +46 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +129 -0
- package/jest.config.js +7 -0
- package/package.json +29 -0
- package/src/api.ts +544 -0
- package/src/consts/deployments-mainnet.json +28 -0
- package/src/consts/deployments-testnet.json +93 -0
- package/src/consts/index.ts +162 -0
- package/src/consts/price_id_to_object_id.mainnet.json +1 -0
- package/src/consts/price_id_to_object_id.testnet.json +17 -0
- package/src/consts/staking/deployments-mainnet.json +12 -0
- package/src/consts/staking/deployments-testnet.json +11 -0
- package/src/data.ts +1059 -0
- package/src/index.ts +5 -0
- package/src/oracle.ts +161 -0
- package/src/utils.ts +184 -0
- package/tests/api.test.ts +219 -0
- package/tests/data.test.ts +156 -0
- package/tests/oracle.test.ts +33 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { reverseKeyValue } from '../utils'
|
|
2
|
+
import mainnetJson from './deployments-mainnet.json'
|
|
3
|
+
import testnetJson from './deployments-testnet.json'
|
|
4
|
+
import PriceIdToObjectIdMainnet from './price_id_to_object_id.mainnet.json'
|
|
5
|
+
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
|
+
|
|
9
|
+
interface IVault {
|
|
10
|
+
weight: string
|
|
11
|
+
reservingFeeModel: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ISymbol {
|
|
15
|
+
supportedCollaterals: string[]
|
|
16
|
+
fundingFeeModel: string
|
|
17
|
+
positionConfig: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface ICoin {
|
|
21
|
+
decimals: number
|
|
22
|
+
module: string
|
|
23
|
+
metadata: string
|
|
24
|
+
treasury: string | null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
type IVersionedContract = string
|
|
28
|
+
|
|
29
|
+
type IFeeder = Record<string, IVersionedContract>
|
|
30
|
+
|
|
31
|
+
export interface IConsts {
|
|
32
|
+
zoCore: {
|
|
33
|
+
package: string
|
|
34
|
+
upgradeCap: string
|
|
35
|
+
adminCap: string
|
|
36
|
+
market: IVersionedContract
|
|
37
|
+
zlpMetadata: IVersionedContract
|
|
38
|
+
rebaseFeeModel: IVersionedContract
|
|
39
|
+
vaultsParent: string
|
|
40
|
+
symbolsParent: string
|
|
41
|
+
positionsParent: string
|
|
42
|
+
vaults: Record<string, IVault>
|
|
43
|
+
symbols: Record<string, ISymbol>
|
|
44
|
+
referralsParent: string
|
|
45
|
+
ordersParent: string
|
|
46
|
+
}
|
|
47
|
+
pythFeeder: {
|
|
48
|
+
package: string
|
|
49
|
+
state: IVersionedContract
|
|
50
|
+
wormhole: {
|
|
51
|
+
package: string
|
|
52
|
+
state: IVersionedContract
|
|
53
|
+
}
|
|
54
|
+
feeder: IFeeder
|
|
55
|
+
}
|
|
56
|
+
coins: Record<string, ICoin>
|
|
57
|
+
zoStaking: {
|
|
58
|
+
package: string
|
|
59
|
+
upgradeCap: string
|
|
60
|
+
adminCap: string
|
|
61
|
+
pool: string
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function toCamelCase(str: string): string {
|
|
66
|
+
return str.replaceAll(/_([a-z])/g, (_, letter) => letter.toUpperCase())
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function parse<T>(obj: unknown): T {
|
|
70
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
71
|
+
return obj as T
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (Array.isArray(obj)) {
|
|
75
|
+
return obj.map(item => parse<T>(item)) as T
|
|
76
|
+
}
|
|
77
|
+
const newObj: Record<string, unknown> = {}
|
|
78
|
+
for (const key in obj as object) {
|
|
79
|
+
if (Object.hasOwn(obj, key)) {
|
|
80
|
+
const camelCaseKey = toCamelCase(key)
|
|
81
|
+
newObj[camelCaseKey] = parse((obj as Record<string, unknown>)[key])
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return newObj as T
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export enum Network {
|
|
89
|
+
MAINNET = 'mainnet',
|
|
90
|
+
TESTNET = 'testnet',
|
|
91
|
+
DEVNET = 'devnet',
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function throwNetworkError(network: string): never {
|
|
95
|
+
throw new Error(`Unknown network: ${network}`)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function getConsts(network: Network): IConsts {
|
|
99
|
+
switch (network) {
|
|
100
|
+
case Network.TESTNET: {
|
|
101
|
+
return { ...parse(testnetJson), ...parse(testnetStakingJson) }
|
|
102
|
+
}
|
|
103
|
+
case Network.MAINNET: {
|
|
104
|
+
return { ...parse(mainnetJson), ...parse(mainnetStakingJson) }
|
|
105
|
+
}
|
|
106
|
+
default: {
|
|
107
|
+
return throwNetworkError(network)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export const ZLP_TOKEN_DECIMALS = 6
|
|
113
|
+
|
|
114
|
+
export const SECONDS_PER_EIGHT_HOUR = 8 * 60 * 60
|
|
115
|
+
|
|
116
|
+
export function getPythFeederToPriceId(network: Network): Record<string, string> {
|
|
117
|
+
switch (network) {
|
|
118
|
+
case Network.TESTNET: {
|
|
119
|
+
return reverseKeyValue(PriceIdToObjectIdTestnet)
|
|
120
|
+
}
|
|
121
|
+
case Network.MAINNET: {
|
|
122
|
+
return reverseKeyValue(PriceIdToObjectIdMainnet)
|
|
123
|
+
}
|
|
124
|
+
default: {
|
|
125
|
+
return throwNetworkError(network)
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function getPriceIdToPythFeeder(network: Network): Record<string, string> {
|
|
131
|
+
let priceIdToFeeder: Record<string, string> = {}
|
|
132
|
+
switch (network) {
|
|
133
|
+
case Network.TESTNET: {
|
|
134
|
+
priceIdToFeeder = PriceIdToObjectIdTestnet
|
|
135
|
+
break
|
|
136
|
+
}
|
|
137
|
+
case Network.MAINNET: {
|
|
138
|
+
priceIdToFeeder = PriceIdToObjectIdMainnet
|
|
139
|
+
break
|
|
140
|
+
}
|
|
141
|
+
default: {
|
|
142
|
+
throw new Error(`Unknown network: ${network}`)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return priceIdToFeeder
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function getPythFeederToId(network: Network): Record<string, string> {
|
|
149
|
+
const feederToId: Record<string, string> = {}
|
|
150
|
+
const consts = getConsts(network)
|
|
151
|
+
for (const key in consts.pythFeeder.feeder) {
|
|
152
|
+
if (Object.hasOwn(consts.pythFeeder.feeder, key)) {
|
|
153
|
+
const contract = consts.pythFeeder.feeder[key]
|
|
154
|
+
feederToId[contract] = key
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return feederToId
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export const ALLOW_TRADE_NO_TRADE = 0
|
|
161
|
+
export const ALLOW_TRADE_CAN_TRADE = 1
|
|
162
|
+
export const ALLOW_TRADE_MUST_TRADE = 2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"1fc18861232290221461220bd4e2acd1dcdfbc89c84092c93c18bdc7756c1588": "0x956fdcbf83a26c962319f7742f5728a0a7ce59c7f0cbe13c112b259e7ee953cd",
|
|
3
|
+
"31775e1d6897129e8a84eeba975778fb50015b88039e9bc140bbd839694ac0ae": "0x17b358d730663caa888c8b621b9994a60af422cd83f32237c6b2a8b3230d71b9",
|
|
4
|
+
"3f545e3f4ec9fd8eb3b9d9d6071a1da361f6729fa1b93d1d1baca3379551d99e": "0xfe38289883c3afed692e5856f4896b3e094d4793e2ccf0a2715b890a718fa5c0",
|
|
5
|
+
"41f3625971ca2ed2263e78573fe5ce23e13d2558ed3f2e47ab0f84fb9e7ae722": "0x9c4dd4008297ffa5e480684b8100ec21cc934405ed9a25d4e4d7b6259aad9c81",
|
|
6
|
+
"50c67b3fd225db8912a424dd4baed60ffdde625ed2feaaf283724f9608fea266": "0x1ebb295c789cc42b3b2a1606482cd1c7124076a0f5676718501fda8c7fd075a0",
|
|
7
|
+
"6cdc09f443fe8ed53517b9760b0674d054e719de9b83cba1bbb02c2439448590": "0xfb459da0f174b1ff0870323175da8d25c8d6d1b9f542d9c0801370e0af15b228",
|
|
8
|
+
"8112fed370f3d9751e513f7696472eab61b7f4e2487fd9f46c93de00a338631c": "0xc067432fbb32f09dfa38ef5adaea01b2f34f350cf4620a4ee426ee1552c8fcfe",
|
|
9
|
+
"946292ad3f481f36f5e558726cf4974e2a7a34598bf15d2abe3619e7b6a8db91": "0x94905bdcaa656b0908aa8a3a42cf72b0e8e2e849f7d0a7e0e39bb9e1dc3c9cf6",
|
|
10
|
+
"99137a18354efa7fb6840889d059fdb04c46a6ce21be97ab60d9ad93e91ac758": "0x3d52fffa2cd9e54b39bb36d282bdda560b15b8b4fdf4766a3c58499ef172bafc",
|
|
11
|
+
"ca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6": "0x4fde30cb8a5dc3cfee1c1c358fc66dc308408827efb217247c7ba54d76ccbee9",
|
|
12
|
+
"cb324dafd531712dd31c39969ae0246ee4c6ae167257bcf8ac27e28ca35e6a0c": "0xb0ba78106259b7ceefd288edc5f65b65f8b7bca0816e61dae5136616aac7d3da",
|
|
13
|
+
"d2c2c1f2bba8e0964f9589e060c2ee97f5e19057267ac3284caef3bd50bd2cb5": "0xe791d83be9ba9c271a6f956235381bb4c10208bd8aced8628cf1341b35f63fa0",
|
|
14
|
+
"eacabc6304d11fc10a757f63286ef44415d8e91b7a1a525ae94a7ec9398b73f3": "0xf96e3c4b7d74efbde9df5b669188421196e6164adf6fbaaa92903c42569807c8",
|
|
15
|
+
"f9c0172ba10dfa4d19088d94f5bf61d3b54d5bd7483a322a982e1373ee8ea31b": "0x72431a238277695d3f31e4425225a4462674ee6cceeea9d66447b210755fffba",
|
|
16
|
+
"fe650f0367d4a7ef9815a593ea15d36593f0643aaaf0149bb04be67ab851decd": "0x33fbce1cad5ca155f2f5051430b23a694bc6e5de6df43e0f8aefe29f4a84336d"
|
|
17
|
+
}
|