zo-sdk 0.0.4 → 0.0.5

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.
Files changed (46) hide show
  1. package/.gitattributes +4 -0
  2. package/.prettierrc.js +5 -0
  3. package/babel.config.js +11 -0
  4. package/dist/api.cjs +466 -0
  5. package/dist/api.d.cts +26 -0
  6. package/dist/api.d.cts.map +1 -0
  7. package/dist/api.d.mts +26 -0
  8. package/dist/api.d.mts.map +1 -0
  9. package/dist/api.mjs +462 -0
  10. package/dist/consts/deployments-mainnet.json +28 -0
  11. package/dist/consts/deployments-testnet.json +93 -0
  12. package/dist/consts/index.cjs +101 -0
  13. package/dist/consts/index.d.cts +66 -0
  14. package/dist/consts/index.d.cts.map +1 -0
  15. package/dist/consts/index.d.mts +66 -0
  16. package/dist/consts/index.d.mts.map +1 -0
  17. package/dist/consts/index.mjs +94 -0
  18. package/dist/consts/price_id_to_object_id.mainnet.json +1 -0
  19. package/dist/consts/price_id_to_object_id.testnet.json +17 -0
  20. package/dist/consts/staking/deployments-mainnet.json +12 -0
  21. package/dist/consts/staking/deployments-testnet.json +11 -0
  22. package/dist/data.cjs +844 -0
  23. package/dist/data.d.cts +221 -0
  24. package/dist/data.d.cts.map +1 -0
  25. package/dist/data.d.mts +221 -0
  26. package/dist/data.d.mts.map +1 -0
  27. package/dist/data.mjs +840 -0
  28. package/dist/index.cjs +21 -0
  29. package/dist/index.d.cts +6 -0
  30. package/dist/index.d.cts.map +1 -0
  31. package/dist/index.d.mts +6 -0
  32. package/dist/index.d.mts.map +1 -0
  33. package/dist/index.mjs +5 -0
  34. package/dist/oracle.cjs +178 -0
  35. package/dist/oracle.d.cts +24 -0
  36. package/dist/oracle.d.cts.map +1 -0
  37. package/dist/oracle.d.mts +24 -0
  38. package/dist/oracle.d.mts.map +1 -0
  39. package/dist/oracle.mjs +173 -0
  40. package/dist/utils.cjs +144 -0
  41. package/dist/utils.d.cts +46 -0
  42. package/dist/utils.d.cts.map +1 -0
  43. package/dist/utils.d.mts +46 -0
  44. package/dist/utils.d.mts.map +1 -0
  45. package/dist/utils.mjs +129 -0
  46. package/package.json +3 -2
@@ -0,0 +1,46 @@
1
+ import { SuiClient } from "@mysten/sui/client";
2
+ import { HermesClient } from "@pythnetwork/hermes-client";
3
+ import type { IConsts } from "./consts/index.mjs";
4
+ import { Network } from "./consts/index.mjs";
5
+ export declare function createJsonRpcProvider(network: Network): SuiClient;
6
+ export declare function createPythConnection(network: Network): HermesClient;
7
+ export declare function decimalToObject(decimal: {
8
+ value: string;
9
+ }): number;
10
+ export declare function rateToObject(rate: {
11
+ value: string;
12
+ }): number;
13
+ interface SRate {
14
+ fields: {
15
+ is_positive: boolean;
16
+ value: {
17
+ fields: {
18
+ value: string | number;
19
+ };
20
+ };
21
+ };
22
+ }
23
+ export declare function sRateToObject(sRate: SRate): number;
24
+ interface SuiDecimal {
25
+ fields: {
26
+ is_positive: boolean;
27
+ value: {
28
+ fields: {
29
+ value: string;
30
+ };
31
+ };
32
+ };
33
+ }
34
+ export declare function sDecimalToObject(sDecimal: SuiDecimal): number;
35
+ export declare function parseValue(field: any): number;
36
+ export type ReversedKeyValue<T extends object> = {
37
+ [K in keyof T]: T[K] extends keyof T ? keyof T : T[K] extends keyof T | infer V ? V : never;
38
+ };
39
+ export declare function reverseKeyValue<T extends object>(obj: T): ReversedKeyValue<T>;
40
+ export declare function parseSymbolKey(input: string): string[];
41
+ export declare function upperFirstCharacter(word: string): string;
42
+ export declare function joinSymbol(direction: string, token: string): string;
43
+ export declare function suiSymbolToSymbol(symbol: string, consts: IConsts): string;
44
+ export declare function base64ToUint8Array(base64: string): Uint8Array<ArrayBuffer>;
45
+ export {};
46
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,2BAA0B;AAChE,OAAO,EAAE,Y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AC,CAAC,CAY7E;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAqBtD;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAExD;AAED,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnE;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CASzE;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,2BAYhD"}
package/dist/utils.mjs ADDED
@@ -0,0 +1,129 @@
1
+ import { SuiClient, SuiHTTPTransport } from "@mysten/sui/client";
2
+ import { HermesClient } from "@pythnetwork/hermes-client";
3
+ import { Network } from "./consts/index.mjs";
4
+ export function createJsonRpcProvider(network) {
5
+ let url = '';
6
+ switch (network) {
7
+ case Network.DEVNET: {
8
+ url = 'https://explorer-rpc.devnet.sui.io/';
9
+ break;
10
+ }
11
+ case Network.TESTNET: {
12
+ url = 'https://sui-testnet.blockvision.org/v1/2sXCJEJNOCdIJhLaDtyhKzqwn6k';
13
+ break;
14
+ }
15
+ case Network.MAINNET: {
16
+ url = 'https://rpc-mainnet.suiscan.xyz';
17
+ break;
18
+ }
19
+ default: {
20
+ url = 'https://explorer-rpc.devnet.sui.io/';
21
+ }
22
+ }
23
+ return new SuiClient({
24
+ transport: new SuiHTTPTransport({ url }),
25
+ });
26
+ }
27
+ export function createPythConnection(network) {
28
+ let priceConnectionUrl;
29
+ switch (network) {
30
+ case Network.TESTNET: {
31
+ priceConnectionUrl = 'https://xc-testnet.pyth.network';
32
+ break;
33
+ }
34
+ case Network.MAINNET: {
35
+ priceConnectionUrl = 'https://xc-mainnet.pyth.network';
36
+ break;
37
+ }
38
+ default: {
39
+ priceConnectionUrl = 'https://xc-testnet.pyth.network';
40
+ }
41
+ }
42
+ return new HermesClient(priceConnectionUrl);
43
+ }
44
+ export function decimalToObject(decimal) {
45
+ return Number(BigInt(decimal.value)) / 1e18;
46
+ }
47
+ export function rateToObject(rate) {
48
+ return Number(BigInt(rate.value)) / 1e18;
49
+ }
50
+ export function sRateToObject(sRate) {
51
+ const sign = sRate.fields.is_positive ? 1 : -1;
52
+ return Number(BigInt(sRate.fields.value.fields.value)) / 1e18 * sign;
53
+ }
54
+ export function sDecimalToObject(sDecimal) {
55
+ const sign = sDecimal.fields.is_positive ? 1 : -1;
56
+ return Number(BigInt(sDecimal.fields.value.fields.value)) / 1e18 * sign;
57
+ }
58
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
+ export function parseValue(field) {
60
+ if (field.type && field.type.endsWith('::decimal::Decimal')) {
61
+ return decimalToObject({ value: field.fields.value });
62
+ }
63
+ else if (field.type && field.type.endsWith('::rate::Rate')) {
64
+ return rateToObject({ value: field.fields.value });
65
+ }
66
+ else if (field.type && field.type.endsWith('::srate::SRate')) {
67
+ return sRateToObject(field);
68
+ }
69
+ else if (field.type && field.type.endsWith('::sdecimal::SDecimal')) {
70
+ return sDecimalToObject(field);
71
+ }
72
+ return Number.parseInt(field, 10);
73
+ }
74
+ export function reverseKeyValue(obj) {
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ const reversed = {};
77
+ for (const key in obj) {
78
+ if (Object.hasOwn(obj, key)) {
79
+ const value = obj[key];
80
+ reversed[value] = key;
81
+ }
82
+ }
83
+ return reversed;
84
+ }
85
+ export function parseSymbolKey(input) {
86
+ // This regex will match uppercase letters
87
+ const regex = /[A-Z]/;
88
+ let result = [];
89
+ let wordStart = 0;
90
+ for (let i = 1; i < input.length; i += 1) {
91
+ if (regex.test(input[i])) {
92
+ // Found an uppercase letter, so we split the string here
93
+ result.push(input.slice(wordStart, i));
94
+ wordStart = i;
95
+ }
96
+ }
97
+ // Add the last word to the result array
98
+ result.push(input.slice(wordStart));
99
+ // Convert the words to lowercase
100
+ result = result.map(word => word.toLowerCase());
101
+ return result;
102
+ }
103
+ export function upperFirstCharacter(word) {
104
+ return word.charAt(0).toUpperCase() + word.slice(1);
105
+ }
106
+ export function joinSymbol(direction, token) {
107
+ return `${direction}${upperFirstCharacter(token)}`;
108
+ }
109
+ export function suiSymbolToSymbol(symbol, consts) {
110
+ if (symbol === '0x2::sui::SUI') {
111
+ return 'sui';
112
+ }
113
+ const ret = {};
114
+ for (const key of Object.keys(consts.coins)) {
115
+ ret[consts.coins[key].module] = key;
116
+ }
117
+ return ret[symbol];
118
+ }
119
+ export function base64ToUint8Array(base64) {
120
+ // Decode Base64 to binary
121
+ const binary = atob(base64);
122
+ // Create a Uint8Array from the binary data
123
+ const uint8Array = new Uint8Array(binary.length);
124
+ // Populate the Uint8Array with the binary data
125
+ for (let i = 0; i < binary.length; i += 1) {
126
+ uint8Array[i] = binary.codePointAt(i);
127
+ }
128
+ return uint8Array;
129
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zo-sdk",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "ISC",
@@ -35,6 +35,7 @@
35
35
  "decimal.js": "10.4.3"
36
36
  },
37
37
  "devDependencies": {
38
- "@ts-bridge/cli": "^0.6.3"
38
+ "@ts-bridge/cli": "^0.6.3",
39
+ "typescript": "^5.0.0"
39
40
  }
40
41
  }