zo-sdk 0.0.12 → 0.0.14

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 (54) hide show
  1. package/dist/api.cjs +469 -0
  2. package/dist/{api.d.ts → api.d.cts} +6 -5
  3. package/dist/api.d.cts.map +1 -0
  4. package/dist/api.d.mts +26 -0
  5. package/dist/api.d.mts.map +1 -0
  6. package/dist/api.mjs +465 -0
  7. package/dist/consts/deployments-mainnet.json +87 -15
  8. package/dist/consts/deployments-testnet.json +23 -23
  9. package/dist/consts/{index.js → index.cjs} +8 -12
  10. package/dist/consts/{index.d.ts → index.d.cts} +1 -0
  11. package/dist/consts/index.d.cts.map +1 -0
  12. package/dist/consts/index.d.mts +66 -0
  13. package/dist/consts/index.d.mts.map +1 -0
  14. package/dist/consts/index.mjs +92 -0
  15. package/dist/consts/price_id_to_object_id.mainnet.json +8 -1
  16. package/dist/{data.js → data.cjs} +246 -155
  17. package/dist/{data.d.ts → data.d.cts} +9 -8
  18. package/dist/data.d.cts.map +1 -0
  19. package/dist/data.d.mts +221 -0
  20. package/dist/data.d.mts.map +1 -0
  21. package/dist/data.mjs +841 -0
  22. package/dist/{index.js → index.cjs} +5 -6
  23. package/dist/index.d.cts +6 -0
  24. package/dist/index.d.cts.map +1 -0
  25. package/dist/index.d.mts +6 -0
  26. package/dist/index.d.mts.map +1 -0
  27. package/dist/index.mjs +5 -0
  28. package/dist/{oracle.js → oracle.cjs} +51 -8
  29. package/dist/{oracle.d.ts → oracle.d.cts} +7 -6
  30. package/dist/oracle.d.cts.map +1 -0
  31. package/dist/oracle.d.mts +24 -0
  32. package/dist/oracle.d.mts.map +1 -0
  33. package/dist/oracle.mjs +173 -0
  34. package/dist/{utils.js → utils.cjs} +1 -2
  35. package/dist/{utils.d.ts → utils.d.cts} +5 -4
  36. package/dist/utils.d.cts.map +1 -0
  37. package/dist/utils.d.mts +46 -0
  38. package/dist/utils.d.mts.map +1 -0
  39. package/dist/utils.mjs +128 -0
  40. package/package.json +23 -13
  41. package/src/consts/deployments-mainnet.json +87 -15
  42. package/src/consts/deployments-testnet.json +23 -23
  43. package/src/consts/index.ts +1 -1
  44. package/src/consts/price_id_to_object_id.mainnet.json +8 -1
  45. package/tsconfig.json +19 -9
  46. package/babel.config.js +0 -11
  47. package/dist/api.js +0 -400
  48. package/dist/api.js.map +0 -1
  49. package/dist/consts/index.js.map +0 -1
  50. package/dist/data.js.map +0 -1
  51. package/dist/index.d.ts +0 -5
  52. package/dist/index.js.map +0 -1
  53. package/dist/oracle.js.map +0 -1
  54. package/dist/utils.js.map +0 -1
@@ -1,18 +1,52 @@
1
1
  {
2
2
  "zo_core": {
3
- "package": "",
4
- "upgrade_cap": "",
5
- "admin_cap": "",
6
- "market": "",
7
- "zlp_metadata": "",
8
- "rebase_fee_model": "",
9
- "referrals_parent": "",
10
- "vaults_parent": "",
11
- "symbols_parent": "",
12
- "positions_parent": "",
13
- "orders_parent": "",
14
- "vaults": {},
15
- "symbols": {}
3
+ "package": "0xce6a4384ceb1306efdb45cd0b093a7a49669a998749c59e614be8cfdf1352530",
4
+ "upgrade_cap": "0x0b703c8e709ce86bcb1468ed47047b0d7020c72beca0a907a17b0e17bdb0f54c",
5
+ "admin_cap": "0x4a152188f491e6b0c58115369318f9b50bf15e685322f2ef8e9a68e71638eb15",
6
+ "market": "0x94314e176d16ad0c77d0f3326ea5914db01d037fa0db644b1bf545dbe482bfb8",
7
+ "zlp_metadata": "0x3a3ab1dbcc939ee71669aed0fe885c7c3b23e17021ff2f877929f9c88d97ee60",
8
+ "rebase_fee_model": "0xa4a426e677da3a3358648978ae7510c17261ce12302287ccbdc61d48e54fdbd6",
9
+ "referrals_parent": "0x32f369c166cddb21db5369bb90ff8e462ca5f4f21e0eabae5e5d1a0d4154f6e8",
10
+ "vaults_parent": "0x3299e9ee800425afcfd51339cb53a8d0f73856e2ec1268d73caa8d5213068635",
11
+ "symbols_parent": "0x89975b6ec33ac0e53766229c3b642e817708bbd7299cda7509d6fabf5cd14069",
12
+ "positions_parent": "0x7e7870464138f3c7eaa7b1398813b86169d76bf74fcb8b55d68409e40ee68c41",
13
+ "orders_parent": "0x3c5f69a5166afe5459e21c64615e8f3a6111adf60e6f30a0fafd9df5e2ee07d4",
14
+ "vaults": {
15
+ "usdt": {
16
+ "weight": "50000000000000000",
17
+ "reserving_fee_model": "0xab77fbcb9c02c3ab36acf7ea6dacde6e4d4ece6e0d18cf692aeb8af4355c8087"
18
+ },
19
+ "sui": {
20
+ "weight": "200000000000000000",
21
+ "reserving_fee_model": "0xbfd086e19531fae3dedba1ff1f22321810783fcbff74f7dd802941f385a649b5"
22
+ },
23
+ "nusdc": {
24
+ "weight": "50000000000000000",
25
+ "reserving_fee_model": "0x6aba9dd9d842e5afb48f56e6c557f306dd3b438482cde9661e98d5e4c946baa5"
26
+ }
27
+ },
28
+ "symbols": {
29
+ "long_btc": {
30
+ "supported_collaterals": ["usdt"],
31
+ "funding_fee_model": "0x170dca23442b842c592bfe97f769eeb9dc1e3f91211ab82b601150f0d7cbba5f",
32
+ "position_config": "0x63021a70938256c4b70163e52123566a4c704caab067b5468ac6bedc97d3bd93"
33
+ },
34
+ "short_btc": {
35
+ "supported_collaterals": ["usdt"],
36
+ "funding_fee_model": "0x2cd4ad4a33f7d87211e2d096cd9ef6de99338fe7f8de5face4b00a13df2f44a4",
37
+ "position_config": "0xb29751c5539afb5d2b514bba53d825b5b0eeebb9b18d2928da9bc368a4ef537f"
38
+ },
39
+ "long_eth": {
40
+ "supported_collaterals": ["usdt"],
41
+ "funding_fee_model": "0x26a0cb7d6258c0afa6f7b68f88ba7873bd19dcd343dece854451134f0b2fb2cb",
42
+ "position_config": "0xea3e608b6097b17e3a17ae406ac463818bcdd122fe168368f5ba53994f74643b"
43
+ },
44
+ "short_eth": {
45
+ "supported_collaterals": ["usdt"],
46
+ "funding_fee_model": "0x68513b9675b03c33bceb680dee18468f2148cdea513687e21e3d3b630508b17d",
47
+ "position_config": "0x8a2a300e9f4fc471eba474e9b2e40244522394efc71a10803219425cdc1cadee"
48
+ }
49
+ }
16
50
  },
17
51
  "pyth_feeder": {
18
52
  "package": "0x8d97f1cd6ac663735be08d1d2b6d02a159e711586461306ce60a2b7a6a565a9e",
@@ -22,7 +56,45 @@
22
56
  "package": "0x5306f64e312b581766351c07af79c72fcb1cd25147157fdc2f8ad76de9a3fb6a",
23
57
  "state": "0xaeab97f96cf9877fee2883315d459552b2b921edc16d7ceac6eab944dd88919c"
24
58
  },
25
- "feeder": {}
59
+ "feeder": {
60
+ "sui": "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37",
61
+ "btc": "0x9a62b4863bdeaabdc9500fce769cf7e72d5585eeb28a6d26e4cafadc13f76ab2",
62
+ "eth": "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab",
63
+ "nusdc": "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab",
64
+ "usdt": "0x985e3db9f93f76ee8bace7c3dd5cc676a096accd5d9e09e9ae0fb6e492b14572",
65
+ "deep": "0x8c7f3a322b94cc69db2a2ac575cbd94bf5766113324c3a3eceac91e3e88a51ed"
66
+ }
26
67
  },
27
- "coins": {}
68
+ "coins": {
69
+ "sui": {
70
+ "decimals": 9,
71
+ "module": "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
72
+ "metadata": "0x9258181f5ceac8dbffb7030890243caed69a9599d2886d957a9cb7656af3bdb3"
73
+ },
74
+ "btc": {
75
+ "decimals": 8,
76
+ "module": "0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN",
77
+ "metadata": "0x5d3c6e60eeff8a05b693b481539e7847dfe33013e7070cdcb387f5c0cac05dfd"
78
+ },
79
+ "eth": {
80
+ "decimals": 8,
81
+ "module": "0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN",
82
+ "metadata": "0x8900e4ceede3363bef086d6b50ca89d816d0e90bf6bc46efefe1f8455e08f50f"
83
+ },
84
+ "nusdc": {
85
+ "decimals": 6,
86
+ "module": "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
87
+ "metadata": "0x69b7a7c3c200439c1b5f3b19d7d495d5966d5f08de66c69276152f8db3992ec6"
88
+ },
89
+ "usdt": {
90
+ "decimals": 6,
91
+ "module": "0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",
92
+ "metadata": "0xfb0e3eb97dd158a5ae979dddfa24348063843c5b20eb8381dd5fa7c93699e45c"
93
+ },
94
+ "deep": {
95
+ "decimals": 6,
96
+ "module": "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP",
97
+ "metadata": "0x6e60b051a08fa836f5a7acd7c464c8d9825bc29c44657fe170fe9b8e1e4770c0"
98
+ }
99
+ }
28
100
  }
@@ -1,46 +1,46 @@
1
1
  {
2
2
  "zo_core": {
3
- "package": "0xec6db545c6fa70a67b0b4122ee9068f6fc186fbcca93c2021f257be08b020d29",
4
- "upgrade_cap": "0x4ac4eaa60e2c3d9c905a6b19a8915de161360e717e7fb7c825eaffabc8a4f37d",
5
- "admin_cap": "0x8fc34ddcf92ec04108258399afa264fb6bf6948adea3feda3b4a0853fd52e2d9",
6
- "market": "0x82cfe3d857ad2e5feecd64762548ded75a000896391217fbc9ff9509e81d5472",
7
- "zlp_metadata": "0xabe892092d7bdf78b57654f50df88c34cdaab019af970814a459da394ef765c6",
8
- "rebase_fee_model": "0xabb420bb3e2be80244f854e4de3cbd70ac242f3271848393a4322ca7aacf3f3d",
9
- "referrals_parent": "0xf5ccc36426095a8857fd27891907f2242e9399b4443df66fd86f2f47d94afc34",
10
- "vaults_parent": "0x574b14c9b7a3b4f78eee68e820d15f5ecbac7a7508bcc1dbf3380e8b0725a0bd",
11
- "symbols_parent": "0xc348082a5c6a3d2483db637c78f28bd1961d7ba0de10a5318716d703fb8466f5",
12
- "positions_parent": "0x21a40a58b29aba0c024e678858d3c1cfb00eba4858af641bacc6eac5e78d1fb5",
13
- "orders_parent": "0x9b5d81641dc2ac6c2a225fdd75d32321896a096c38b33cecbe73a59a32b5224e",
3
+ "package": "0x7edfa7f292c8b623ca79bd2cd84e2d0e00eba76115a105b1437157cda307127f",
4
+ "upgrade_cap": "0xa94cef1809098efc654e5c7bdd584f60b4523c71ce935886e9c91efa0da807fd",
5
+ "admin_cap": "0x3c5714f2faa3cac854b2b1227114f1840133ab852dd48bfa0a3557720de03906",
6
+ "market": "0x77a3f0ee8b2dfbc570914629eb2cc5812a986108b336c840d77e69ba45bd8ba0",
7
+ "zlp_metadata": "0x3aedadbcdc1cf254fabc69110f9cf9fcbcc121c39347c4c75ad92903db8bd6eb",
8
+ "rebase_fee_model": "0x3375eb8b5082d1c52ab7d62c94a8f850f012f9cb4a03d96737b7256a31be4071",
9
+ "referrals_parent": "0xe51a4e8663280bf14e42a4f8e63141b45dc45c74fcf0470b17a96a2a625e80f9",
10
+ "vaults_parent": "0x1fc28cf4326a83533b127d5e072827c12995a0934b81513d5a5bcbae1038a8c2",
11
+ "symbols_parent": "0xc6eade51827828d28733b12f930b756b3cd78cdea0ad3e9773ca70d6ce30fdbd",
12
+ "positions_parent": "0xa3c40a6facbca7871ec1e6e51418b76d9f8200bcfeaa690b6687be9efcde04b9",
13
+ "orders_parent": "0x2a988712c811b8c063fee45e5bda61b3237e91ac3a94d542ef738bf0c56f0eae",
14
14
  "vaults": {
15
15
  "usdt": {
16
- "weight": "50000000000000000",
17
- "reserving_fee_model": "0xe2d1ea0df536ec62fbce793e294594a6fb5122cecfd1a0ae76caff7bcc303c49"
16
+ "weight": "100000000000000000",
17
+ "reserving_fee_model": "0xcd5f7a1cdb21d5bbd8d017682a3d5e854641ea5a84e639a320a6a4c702c4b8c8"
18
18
  },
19
19
  "sui": {
20
- "weight": "50000000000000000",
21
- "reserving_fee_model": "0x1ae6c6868efec5c9bb9897d75f0d1d62704a12079da614dc310a1898b2a1d2c6"
20
+ "weight": "100000000000000000",
21
+ "reserving_fee_model": "0xd0aaf3e8acad869a16b56fcd1c2f29ed9fbe5b10fc05290d65557547211107a1"
22
22
  }
23
23
  },
24
24
  "symbols": {
25
25
  "long_btc": {
26
26
  "supported_collaterals": ["usdt"],
27
- "funding_fee_model": "0x200c498ec92ebc835bda11f4d225bc91c44e73d711606f787990fe83b8692bac",
28
- "position_config": "0x12997666d278c42223161b596efdb79f86210970acd4aacfc711e6bb3c20f6d7"
27
+ "funding_fee_model": "0x016af381b6fc9933a816b54c32599b36ceca42f2889eddebc0230d48fc4910a0",
28
+ "position_config": "0x383f9600cf086829922b8e4b67a533edf60c104c42ddedd43b02994470e55b74"
29
29
  },
30
30
  "short_btc": {
31
31
  "supported_collaterals": ["usdt"],
32
- "funding_fee_model": "0x3a6a3e71460e8c143ed7fe296a77a45723b6ea61c10aa45e9c48bd3a352f93f5",
33
- "position_config": "0xe5f6e4e9b7c070c54cdd6ae2826bf6bc32441085a4ffd263f4eaa97d3711e120"
32
+ "funding_fee_model": "0x699530a75af4a4d58cab4f58485e30e65a438528345746b523b3d83e49465178",
33
+ "position_config": "0xcec1a314f020ab3bd602f9f481a6a686560c8c35e3dae6c88d3176444fc100dd"
34
34
  },
35
35
  "long_eth": {
36
36
  "supported_collaterals": ["usdt"],
37
- "funding_fee_model": "0x096b4495fd183baab7e0a440920a92523b1a287d11875ad79db39ba685a2f87f",
38
- "position_config": "0x7ca6ff396247d1538949fed3728fac334e75f66914026ef9a0dba6bbb3b749e7"
37
+ "funding_fee_model": "0x1e6ebf6f39b43a4feb775d50fc2eac0b12371c36b3ae937027820025dbc03c8a",
38
+ "position_config": "0xb9b536e0f8e9fcae28a48476fd0000208c1e288b5b1b23af07e7aad05d71b139"
39
39
  },
40
40
  "short_eth": {
41
41
  "supported_collaterals": ["usdt"],
42
- "funding_fee_model": "0x84c2473239acf91bcb760beb4df59a1e11399924e87c1016b08d60f8cacde811",
43
- "position_config": "0xfc9ca4b88ca9ada838fb87eebe24667b06d76c8c8f0a07e107e7939b1abbddc8"
42
+ "funding_fee_model": "0x92f488d758ddf483be3b90f6bc9dbc79cecd3fe6b5339e710e35ffb28435d612",
43
+ "position_config": "0xd4b0cd45c96df2e1c571e51e4729f5752037ba0f6a5ffc6dd6269083b0226b31"
44
44
  }
45
45
  }
46
46
  },
@@ -63,7 +63,7 @@ export interface IConsts {
63
63
  }
64
64
 
65
65
  function toCamelCase(str: string): string {
66
- return str.replace(/_([a-z])/g, (match, letter) => letter.toUpperCase());
66
+ return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
67
67
  }
68
68
 
69
69
  function parse(obj: any): any {
@@ -1 +1,8 @@
1
- {}
1
+ {
2
+ "eaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a": "0x5dec622733a204ca27f5a90d8c2fad453cc6665186fd5dff13a83d0b6c9027ab",
3
+ "2b89b9dc8fdf9f34709a5b106b472f0f39bb6ca9ce04b0fd7f2e971688e2e53b": "0x985e3db9f93f76ee8bace7c3dd5cc676a096accd5d9e09e9ae0fb6e492b14572",
4
+ "23d7315113f5b1d3ba7a83604c44b94d79f4fd69af77f804fc7f920a6dc65744": "0x801dbc2f0053d34734814b2d6df491ce7807a725fe9a01ad74a07e9c51396c37",
5
+ "ff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace": "0x9193fd47f9a0ab99b6e365a464c8a9ae30e6150fc37ed2a89c1586631f6fc4ab",
6
+ "e62df6c8b4a85fe1a67db44dc12de5db330f7ac66b72dc658afedf0f4a415b43": "0x9a62b4863bdeaabdc9500fce769cf7e72d5585eeb28a6d26e4cafadc13f76ab2",
7
+ "29bdd5248234e33bd93d3b81100b5fa32eaa5997843847e2c2cb16d7c6d9f7ff": "0x8c7f3a322b94cc69db2a2ac575cbd94bf5766113324c3a3eceac91e3e88a51ed"
8
+ }
package/tsconfig.json CHANGED
@@ -1,15 +1,25 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES2020",
4
- "module": "CommonJS",
5
- "strict": true,
6
- "esModuleInterop": true,
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
7
  "skipLibCheck": true,
8
- "forceConsistentCasingInFileNames": true,
9
- "declaration": true,
10
- "outDir": "./dist",
11
- "sourceMap": true,
12
- "resolveJsonModule": true
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "Bundler",
11
+ "isolatedModules": true,
12
+ "moduleDetection": "force",
13
+ "noEmit": true,
14
+ "resolveJsonModule": true,
15
+ "allowSyntheticDefaultImports": true,
16
+
17
+ /* Linting */
18
+ "strict": true,
19
+ "noUnusedLocals": true,
20
+ "noUnusedParameters": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+ "noUncheckedSideEffectImports": true
13
23
  },
14
- "include": ["src/**/*"]
24
+ "include": ["src/**/*.ts"]
15
25
  }
package/babel.config.js DELETED
@@ -1,11 +0,0 @@
1
- module.exports = {
2
- presets: [
3
- [
4
- "@babel/preset-env",
5
- {
6
- modules: "auto",
7
- },
8
- ],
9
- ],
10
- plugins: ["@babel/plugin-transform-modules-commonjs"],
11
- };
package/dist/api.js DELETED
@@ -1,400 +0,0 @@
1
- "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var _API_instances, _API_processCoins, _API_processSlippage;
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.API = void 0;
10
- const transactions_1 = require("@mysten/sui/transactions");
11
- const utils_1 = require("@mysten/sui/utils");
12
- const consts_1 = require("./consts");
13
- const data_1 = require("./data");
14
- const utils_2 = require("./utils");
15
- class API extends data_1.DataAPI {
16
- // eslint-disable-next-line @typescript-eslint/no-useless-constructor
17
- constructor(network, provider, apiEndpoint, connectionURL) {
18
- super(network, provider, apiEndpoint, connectionURL);
19
- _API_instances.add(this);
20
- _API_processCoins.set(this, (tx, coin, coinObjects) => {
21
- if (coin === 'sui') {
22
- return tx.gas;
23
- }
24
- if (coinObjects.length > 1) {
25
- tx.mergeCoins(tx.object(coinObjects[0]), coinObjects.slice(1).map(coinObject => tx.object(coinObject)));
26
- }
27
- return tx.object(coinObjects[0]);
28
- });
29
- this.deposit = async (coin, coinObjects, amount, minAmountOut = 0) => {
30
- const tx = await this.initOracleTxb(Object.keys(this.consts.pythFeeder.feeder));
31
- const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, coin, coinObjects);
32
- const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
33
- const { vaultsValuation, symbolsValuation, } = this.valuate(tx);
34
- tx.moveCall({
35
- target: `${this.consts.zoCore.package}::market::deposit`,
36
- typeArguments: [
37
- `${this.consts.zoCore.package}::zlp::ZLP`,
38
- this.consts.coins[coin].module,
39
- ],
40
- arguments: [
41
- tx.object(this.consts.zoCore.market),
42
- tx.object(this.consts.zoCore.rebaseFeeModel),
43
- depositObject,
44
- tx.pure.u64(minAmountOut),
45
- vaultsValuation,
46
- symbolsValuation,
47
- ],
48
- });
49
- return tx;
50
- };
51
- this.withdraw = async (coin, zlpCoinObjects, amount, minAmountOut = 0) => {
52
- const tx = await this.initOracleTxb(Object.keys(this.consts.pythFeeder.feeder));
53
- const zlpCoinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, 'zlp', zlpCoinObjects);
54
- const [withdrawObject] = tx.splitCoins(zlpCoinObject, [tx.pure.u64(amount)]);
55
- const { vaultsValuation, symbolsValuation, } = this.valuate(tx);
56
- tx.moveCall({
57
- target: `${this.consts.zoCore.package}::market::withdraw`,
58
- typeArguments: [
59
- `${this.consts.zoCore.package}::zlp::ZLP`,
60
- this.consts.coins[coin].module,
61
- ],
62
- arguments: [
63
- tx.object(this.consts.zoCore.market),
64
- tx.object(this.consts.zoCore.rebaseFeeModel),
65
- withdrawObject,
66
- tx.pure.u64(minAmountOut),
67
- vaultsValuation,
68
- symbolsValuation,
69
- ],
70
- });
71
- return tx;
72
- };
73
- this.openPosition = async (collateralToken, indexToken, size, collateralAmount, coinObjects, long, reserveAmount, indexPrice, collateralPrice, slippage = 0.003, isLimitOrder = false, isIocOrder = false, relayerFee = BigInt(1), referralAddress = '', sender = '') => {
74
- let tx = new transactions_1.Transaction();
75
- if (referralAddress && !await this.hasReferral(sender || '')) {
76
- tx = await this.addReferral(referralAddress, tx);
77
- }
78
- tx = await this.initOracleTxb([collateralToken, indexToken], tx);
79
- const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, collateralToken, coinObjects);
80
- const [depositObject, feeObject] = tx.splitCoins(coinObject, [
81
- tx.pure.u64(collateralAmount),
82
- tx.pure.u64(relayerFee)
83
- ]);
84
- const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
85
- const adjustPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, indexPrice, long, isLimitOrder ? 0 : slippage);
86
- const adjustCollateralPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, collateralPrice, false, 0.5);
87
- let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
88
- if (isLimitOrder) {
89
- allowTrade = isIocOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
90
- }
91
- tx.moveCall({
92
- target: `${this.consts.zoCore.package}::market::open_position`,
93
- typeArguments: [
94
- `${this.consts.zoCore.package}::zlp::ZLP`,
95
- this.consts.coins[collateralToken].module,
96
- this.consts.coins[indexToken].module,
97
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
98
- this.consts.coins[collateralToken].module,
99
- ],
100
- arguments: [
101
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
102
- tx.object(this.consts.zoCore.market),
103
- tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
104
- tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
105
- tx.object(this.consts.zoCore.symbols[symbol].positionConfig),
106
- tx.object(this.consts.pythFeeder.feeder[collateralToken]),
107
- tx.object(this.consts.pythFeeder.feeder[indexToken]),
108
- depositObject,
109
- feeObject,
110
- tx.pure.u8(allowTrade),
111
- tx.pure.u64(size),
112
- tx.pure.u64(reserveAmount),
113
- tx.pure.u256(adjustCollateralPrice),
114
- tx.pure.u256(adjustPrice),
115
- ],
116
- });
117
- return tx;
118
- };
119
- this.pledgeInPosition = async (pcpId, collateralToken, indexToken, amount, coinObjects, long) => {
120
- const tx = await this.initOracleTxb([collateralToken, indexToken]);
121
- const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, collateralToken, coinObjects);
122
- const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
123
- tx.moveCall({
124
- target: `${this.consts.zoCore.package}::market::pledge_in_position`,
125
- typeArguments: [
126
- `${this.consts.zoCore.package}::zlp::ZLP`,
127
- this.consts.coins[collateralToken].module,
128
- this.consts.coins[indexToken].module,
129
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
130
- ],
131
- arguments: [
132
- tx.object(this.consts.zoCore.market),
133
- tx.object(pcpId),
134
- depositObject,
135
- ],
136
- });
137
- return tx;
138
- };
139
- this.redeemFromPosition = async (pcpId, collateralToken, indexToken, amount, long) => {
140
- const tx = await this.initOracleTxb([collateralToken, indexToken]);
141
- const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
142
- tx.moveCall({
143
- target: `${this.consts.zoCore.package}::market::redeem_from_position`,
144
- typeArguments: [
145
- `${this.consts.zoCore.package}::zlp::ZLP`,
146
- this.consts.coins[collateralToken].module,
147
- this.consts.coins[indexToken].module,
148
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
149
- ],
150
- arguments: [
151
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
152
- tx.object(this.consts.zoCore.market),
153
- tx.object(pcpId),
154
- tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
155
- tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
156
- tx.object(this.consts.pythFeeder.feeder[collateralToken]),
157
- tx.object(this.consts.pythFeeder.feeder[indexToken]),
158
- tx.pure.u64(amount),
159
- ],
160
- });
161
- return tx;
162
- };
163
- this.decreasePosition = async (pcpId, collateralToken, coinObjects, indexToken, amount, long, indexPrice, collateralPrice, isTriggerOrder = false, isTakeProfitOrder = true, isIocOrder = false, slippage = 0.003, relayerFee = BigInt(1)) => {
164
- const tx = await this.initOracleTxb([collateralToken, indexToken]);
165
- const symbol = (0, utils_2.joinSymbol)(long ? 'long' : 'short', indexToken);
166
- const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, collateralToken, coinObjects);
167
- const feeObject = tx.splitCoins(coinObject, [tx.pure.u64(relayerFee)]);
168
- const adjustPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, indexPrice, !long, isTriggerOrder ? 0 : slippage);
169
- const adjustCollateralPrice = __classPrivateFieldGet(this, _API_instances, "m", _API_processSlippage).call(this, collateralPrice, false, 0.5);
170
- let allowTrade = consts_1.ALLOW_TRADE_MUST_TRADE;
171
- if (isTriggerOrder) {
172
- allowTrade = isIocOrder || !isTakeProfitOrder ? consts_1.ALLOW_TRADE_NO_TRADE : consts_1.ALLOW_TRADE_CAN_TRADE;
173
- }
174
- else {
175
- isTakeProfitOrder = true;
176
- }
177
- /* console.log('isTriggerOrder:', isTriggerOrder)
178
- console.log('isIocOrder:', isIocOrder)
179
- console.log('isTakeProfitOrder:', isTakeProfitOrder)
180
- console.log('adjustPrice:', adjustPrice)
181
- console.log('allowTrade:', allowTrade)
182
- console.log('isTriggerOrder:', isTriggerOrder)
183
- console.log('isTakeProfitOrder:', isTakeProfitOrder) */
184
- tx.moveCall({
185
- target: `${this.consts.zoCore.package}::market::decrease_position`,
186
- typeArguments: [
187
- `${this.consts.zoCore.package}::zlp::ZLP`,
188
- this.consts.coins[collateralToken].module,
189
- this.consts.coins[indexToken].module,
190
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
191
- this.consts.coins[collateralToken].module,
192
- ],
193
- arguments: [
194
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
195
- tx.object(this.consts.zoCore.market),
196
- tx.object(pcpId),
197
- tx.object(this.consts.zoCore.vaults[collateralToken].reservingFeeModel),
198
- tx.object(this.consts.zoCore.symbols[symbol].fundingFeeModel),
199
- tx.object(this.consts.pythFeeder.feeder[collateralToken]),
200
- tx.object(this.consts.pythFeeder.feeder[indexToken]),
201
- feeObject,
202
- tx.pure.u8(allowTrade),
203
- tx.pure.bool(isTakeProfitOrder),
204
- tx.pure.u64(amount),
205
- tx.pure.u256(adjustCollateralPrice),
206
- tx.pure.u256(adjustPrice),
207
- ],
208
- });
209
- return tx;
210
- };
211
- this.cancelOrder = (orderCapId, collateralToken, indexToken, long, type, isV11Order = false) => {
212
- const tx = new transactions_1.Transaction();
213
- let functionName = '';
214
- switch (type) {
215
- case 'OPEN_POSITION': {
216
- functionName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
217
- break;
218
- }
219
- case 'DECREASE_POSITION': {
220
- functionName = isV11Order ? 'clear_decrease_position_order' : 'clear_decrease_position_order';
221
- break;
222
- }
223
- default: {
224
- throw new Error('invalid order type');
225
- }
226
- }
227
- tx.moveCall({
228
- target: `${this.consts.zoCore.package}::market::${functionName}`,
229
- typeArguments: [
230
- `${this.consts.zoCore.package}::zlp::ZLP`,
231
- this.consts.coins[collateralToken].module,
232
- this.consts.coins[indexToken].module,
233
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
234
- this.consts.coins[collateralToken].module,
235
- ],
236
- arguments: [
237
- tx.object(this.consts.zoCore.market),
238
- tx.object(orderCapId),
239
- ],
240
- });
241
- return tx;
242
- };
243
- this.swap = async (fromToken, toToken, fromAmount, fromCoinObjects) => {
244
- const tx = await this.initOracleTxb(Object.keys(this.consts.zoCore.vaults));
245
- const fromCoinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, fromToken, fromCoinObjects);
246
- const [fromDepositObject] = tx.splitCoins(fromCoinObject, [tx.pure.u64(fromAmount)]);
247
- const vaultsValuation = this.valuateVaults(tx);
248
- tx.moveCall({
249
- target: `${this.consts.zoCore.package}::market::swap`,
250
- typeArguments: [
251
- `${this.consts.zoCore.package}::zlp::ZLP`,
252
- this.consts.coins[fromToken].module,
253
- this.consts.coins[toToken].module,
254
- ],
255
- arguments: [
256
- tx.object(this.consts.zoCore.market),
257
- tx.object(this.consts.zoCore.rebaseFeeModel),
258
- fromDepositObject,
259
- // FIXME: minAmountOut
260
- tx.pure.u64(0),
261
- vaultsValuation,
262
- ],
263
- });
264
- return tx;
265
- };
266
- this.clearClosedPosition = (pcpId, collateralToken, indexToken, long, tx) => {
267
- tx.moveCall({
268
- target: `${this.consts.zoCore.package}::market::clear_closed_position`,
269
- typeArguments: [
270
- `${this.consts.zoCore.package}::zlp::ZLP`,
271
- this.consts.coins[collateralToken].module,
272
- this.consts.coins[indexToken].module,
273
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
274
- ],
275
- arguments: [
276
- tx.object(this.consts.zoCore.market),
277
- tx.object(pcpId),
278
- ],
279
- });
280
- };
281
- this.clearOpenPositionOrder = (orderCapId, collateralToken, indexToken, long, tx, isV11Order = false) => {
282
- const funcName = isV11Order ? 'clear_open_position_order' : 'clear_open_position_order';
283
- tx.moveCall({
284
- target: `${this.consts.zoCore.package}::market::${funcName}`,
285
- typeArguments: [
286
- `${this.consts.zoCore.package}::zlp::ZLP`,
287
- this.consts.coins[collateralToken].module,
288
- this.consts.coins[indexToken].module,
289
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
290
- this.consts.coins[collateralToken].module,
291
- ],
292
- arguments: [
293
- tx.object(this.consts.zoCore.market),
294
- tx.object(orderCapId),
295
- ],
296
- });
297
- };
298
- this.clearDecreasePositionOrder = (orderCapId, collateralToken, indexToken, long, tx, isV11Order = false) => {
299
- const funcName = isV11Order ? 'clear_decrease_position_order' : 'clear_decrease_position_order';
300
- tx.moveCall({
301
- target: `${this.consts.zoCore.package}::market::${funcName}`,
302
- typeArguments: [
303
- `${this.consts.zoCore.package}::zlp::ZLP`,
304
- this.consts.coins[collateralToken].module,
305
- this.consts.coins[indexToken].module,
306
- `${this.consts.zoCore.package}::market::${long ? 'LONG' : 'SHORT'}`,
307
- this.consts.coins[collateralToken].module,
308
- ],
309
- arguments: [
310
- tx.object(this.consts.zoCore.market),
311
- tx.object(orderCapId),
312
- ],
313
- });
314
- };
315
- this.stake = (coinObjects, amount, pool, tx) => {
316
- if (!tx) {
317
- tx = new transactions_1.Transaction();
318
- }
319
- const coinObject = __classPrivateFieldGet(this, _API_processCoins, "f").call(this, tx, 'zlp', coinObjects);
320
- const [depositObject] = tx.splitCoins(coinObject, [tx.pure.u64(amount)]);
321
- tx.moveCall({
322
- target: `${this.consts.zoStaking.package}::pool::deposit`,
323
- typeArguments: [
324
- `${this.consts.zoCore.package}::zlp::ZLP`,
325
- this.consts.coins.sui.module,
326
- ],
327
- arguments: [
328
- tx.object(pool),
329
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
330
- depositObject,
331
- ],
332
- });
333
- return tx;
334
- };
335
- this.unstake = (credentials, amount, pool, tx) => {
336
- if (!tx) {
337
- tx = new transactions_1.Transaction();
338
- }
339
- for (const credential of credentials) {
340
- // eslint-disable-next-line unicorn/prefer-math-min-max
341
- const withdrawAmount = amount < credential.amount ? amount : credential.amount;
342
- amount -= withdrawAmount;
343
- tx.moveCall({
344
- target: `0xdb353cb79a88d5ee83b7c0ca0249662a1facab17ba62879080ea3d61b9d21112::pool::withdraw`,
345
- typeArguments: [
346
- `${this.consts.zoCore.package}::zlp::ZLP`,
347
- this.consts.coins.sui.module,
348
- ],
349
- arguments: [
350
- tx.object(pool),
351
- tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
352
- tx.object(credential.id),
353
- tx.pure.u64(withdrawAmount),
354
- ],
355
- });
356
- if (credential.amount === BigInt(0)) {
357
- tx.moveCall({
358
- target: `${this.consts.zoStaking.package}::pool::clear_empty_credential`,
359
- typeArguments: [
360
- `${this.consts.zoCore.package}::zlp::ZLP`,
361
- this.consts.coins.sui.module,
362
- ],
363
- arguments: [
364
- tx.object(credential.id),
365
- ],
366
- });
367
- }
368
- }
369
- return tx;
370
- };
371
- this.addReferral = (referrer, tx) => {
372
- if (!tx) {
373
- tx = new transactions_1.Transaction();
374
- }
375
- tx.moveCall({
376
- target: `${this.consts.zoCore.package}::market::add_new_referral`,
377
- typeArguments: [
378
- `${this.consts.zoCore.package}::zlp::ZLP`,
379
- ],
380
- arguments: [
381
- tx.object(this.consts.zoCore.market),
382
- tx.object(referrer),
383
- ],
384
- });
385
- return tx;
386
- };
387
- }
388
- static getInstance(network, provider, apiEndpoint, connectionURL) {
389
- if (!API.instance) {
390
- API.instance = new API(network, provider, apiEndpoint, connectionURL);
391
- }
392
- return API.instance;
393
- }
394
- }
395
- exports.API = API;
396
- _API_processCoins = new WeakMap(), _API_instances = new WeakSet(), _API_processSlippage = function _API_processSlippage(indexPrice, long, slippage) {
397
- const raw = long ? (indexPrice * (1 + slippage)) : (indexPrice * (1 - slippage));
398
- return BigInt(Math.round(raw * 1e18));
399
- };
400
- //# sourceMappingURL=api.js.map