@gmsol-labs/gmsol-sdk 0.8.0-beta.1 → 0.8.0-beta.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/index.d.ts CHANGED
@@ -112,47 +112,6 @@ export interface BestSwapPath {
112
112
  arbitrage_exists: boolean | undefined;
113
113
  }
114
114
 
115
- /**
116
- * Arguments for order simulation.
117
- */
118
- export interface SimulateOrderArgs {
119
- kind: CreateOrderKind;
120
- params: CreateOrderParams;
121
- collateral_or_swap_out_token: StringPubkey;
122
- pay_token?: StringPubkey | undefined;
123
- receive_token?: StringPubkey | undefined;
124
- swap_path?: StringPubkey[] | undefined;
125
- prefer_swap_out_token_update?: boolean | undefined;
126
- }
127
-
128
- /**
129
- * Simulation output for increase order.
130
- */
131
- export interface IncreaseOrderSimulationOutput {
132
- swaps: string[];
133
- report: string;
134
- position: string;
135
- }
136
-
137
- /**
138
- * Simulation output for decrease order.
139
- */
140
- export interface DecreaseOrderSimulationOutput {
141
- swaps: string[];
142
- report: string;
143
- position: string;
144
- decrease_swap: string | undefined;
145
- }
146
-
147
- /**
148
- * Simulation output for swap order.
149
- */
150
- export interface SwapOrderSimulationOutput {
151
- output_token: StringPubkey;
152
- amount: bigint;
153
- report: string[];
154
- }
155
-
156
115
  /**
157
116
  * Options for creating orders.
158
117
  */
@@ -230,6 +189,50 @@ export interface BuildTransactionOptions {
230
189
  compute_unit_min_priority_lamports?: number | undefined;
231
190
  }
232
191
 
192
+ /**
193
+ * Arguments for order simulation.
194
+ */
195
+ export interface SimulateOrderArgs {
196
+ kind: CreateOrderKind;
197
+ params: CreateOrderParams;
198
+ collateral_or_swap_out_token: StringPubkey;
199
+ pay_token?: StringPubkey | undefined;
200
+ receive_token?: StringPubkey | undefined;
201
+ swap_path?: StringPubkey[] | undefined;
202
+ prefer_swap_out_token_update?: boolean | undefined;
203
+ skip_limit_price_validation?: boolean | undefined;
204
+ limit_swap_slippage?: bigint | undefined;
205
+ update_prices_for_limit_order?: boolean | undefined;
206
+ }
207
+
208
+ /**
209
+ * Simulation output for increase order.
210
+ */
211
+ export interface IncreaseOrderSimulationOutput {
212
+ swaps: string[];
213
+ report: string;
214
+ position: string | undefined;
215
+ }
216
+
217
+ /**
218
+ * Simulation output for decrease order.
219
+ */
220
+ export interface DecreaseOrderSimulationOutput {
221
+ swaps: string[];
222
+ report: string;
223
+ position: string | undefined;
224
+ decrease_swap: string | undefined;
225
+ }
226
+
227
+ /**
228
+ * Simulation output for swap order.
229
+ */
230
+ export interface SwapOrderSimulationOutput {
231
+ output_token: StringPubkey;
232
+ amount: bigint;
233
+ report: string[];
234
+ }
235
+
233
236
 
234
237
  /**
235
238
  * A Base58-encoded string representing a public key.
@@ -237,6 +240,26 @@ export interface BuildTransactionOptions {
237
240
  export type StringPubkey = string;
238
241
 
239
242
 
243
+ /**
244
+ * Options for updating [`MarketGraph`] with [`Simulator`].
245
+ */
246
+ export interface UpdateGraphWithSimulatorOptions {
247
+ /**
248
+ * Whether to update token prices with the simulator.
249
+ */
250
+ update_token_prices?: boolean | undefined;
251
+ }
252
+
253
+ /**
254
+ * Options for creating [`Simulator`].
255
+ */
256
+ export interface CreateGraphSimulatorOptions {
257
+ /**
258
+ * Market filter.
259
+ */
260
+ market_filter?: StringPubkey[] | undefined;
261
+ }
262
+
240
263
  /**
241
264
  * Config for [`MarketGraph`](super::MarketGraph).
242
265
  */
@@ -679,6 +702,56 @@ export interface CreateGlvDeposit {
679
702
  skip_glv_token_ata_creation?: boolean;
680
703
  }
681
704
 
705
+ /**
706
+ * Builder for the `create_shift` instruction.
707
+ */
708
+ export interface CreateShift {
709
+ /**
710
+ * Program.
711
+ */
712
+ program?: StoreProgram;
713
+ /**
714
+ * Payer (a.k.a. owner).
715
+ */
716
+ payer: StringPubkey;
717
+ /**
718
+ * Reciever.
719
+ */
720
+ receiver?: StringPubkey | undefined;
721
+ /**
722
+ * Nonce for the shift.
723
+ */
724
+ nonce?: NonceBytes | undefined;
725
+ /**
726
+ * The from-market token.
727
+ */
728
+ from_market_token: StringPubkey;
729
+ /**
730
+ * From-market token account.
731
+ */
732
+ from_market_token_account?: StringPubkey | undefined;
733
+ /**
734
+ * The to-market token.
735
+ */
736
+ to_market_token: StringPubkey;
737
+ /**
738
+ * Execution fee paid to the keeper in lamports.
739
+ */
740
+ execution_lamports?: number;
741
+ /**
742
+ * From-market token amount to pay.
743
+ */
744
+ from_market_token_amount?: number;
745
+ /**
746
+ * Minimum to-market token amount to receive.
747
+ */
748
+ min_to_market_token_amount?: number;
749
+ /**
750
+ * Whether to skip the creation of to-market token ATA.
751
+ */
752
+ skip_to_market_token_ata_creation?: boolean;
753
+ }
754
+
682
755
  /**
683
756
  * Hint for [`CreateWithdrawal`].
684
757
  */
@@ -1456,6 +1529,10 @@ export class Market {
1456
1529
  * Get short token address.
1457
1530
  */
1458
1531
  short_token_address(): string;
1532
+ /**
1533
+ * Create a clone of this market.
1534
+ */
1535
+ clone(): Market;
1459
1536
  }
1460
1537
  /**
1461
1538
  * A JS binding for [`MarketGraph`].
@@ -1506,6 +1583,18 @@ export class MarketGraph {
1506
1583
  * Simulates order execution.
1507
1584
  */
1508
1585
  simulate_order(args: SimulateOrderArgs, position?: Position | null): OrderSimulationOutput;
1586
+ /**
1587
+ * Create a simulator.
1588
+ */
1589
+ to_simulator(options?: CreateGraphSimulatorOptions | null): Simulator;
1590
+ /**
1591
+ * Update with simulator.
1592
+ */
1593
+ update_with_simulator(simulator: Simulator, options?: UpdateGraphWithSimulatorOptions | null): void;
1594
+ /**
1595
+ * Create a clone of this graph.
1596
+ */
1597
+ clone(): MarketGraph;
1509
1598
  }
1510
1599
  /**
1511
1600
  * Wrapper of [`MarketModel`].
@@ -1525,6 +1614,10 @@ export class MarketModel {
1525
1614
  * Create an empty position model.
1526
1615
  */
1527
1616
  create_empty_position(args: CreateEmptyPositionArgs): PositionModel;
1617
+ /**
1618
+ * Create a clone of this market model.
1619
+ */
1620
+ clone(): MarketModel;
1528
1621
  }
1529
1622
  /**
1530
1623
  * wasm-bindgen version of the Message struct.
@@ -1548,15 +1641,19 @@ export class OrderSimulationOutput {
1548
1641
  /**
1549
1642
  * Returns increase order simulation output.
1550
1643
  */
1551
- increase(): IncreaseOrderSimulationOutput | undefined;
1644
+ increase(skip_position?: boolean | null): IncreaseOrderSimulationOutput | undefined;
1552
1645
  /**
1553
1646
  * Returns decrease order simulation output.
1554
1647
  */
1555
- decrease(): DecreaseOrderSimulationOutput | undefined;
1648
+ decrease(skip_position?: boolean | null): DecreaseOrderSimulationOutput | undefined;
1556
1649
  /**
1557
1650
  * Returns swap order simulation output.
1558
1651
  */
1559
1652
  swap(): SwapOrderSimulationOutput | undefined;
1653
+ /**
1654
+ * Returns the result position model.
1655
+ */
1656
+ position_model(): PositionModel | undefined;
1560
1657
  }
1561
1658
  /**
1562
1659
  * The `ElGamalPubkey` type as a `Pod`.
@@ -1606,6 +1703,10 @@ export class Position {
1606
1703
  * Convert to a [`JsPositionModel`].
1607
1704
  */
1608
1705
  to_model(market: MarketModel): PositionModel;
1706
+ /**
1707
+ * Create a clone of this position.
1708
+ */
1709
+ clone(): Position;
1609
1710
  }
1610
1711
  /**
1611
1712
  * JS version of [`PositionModel`].
@@ -1637,6 +1738,10 @@ export class PositionModel {
1637
1738
  * Update with trade event.
1638
1739
  */
1639
1740
  update_with_trade_event(event: TradeEvent, force_update?: boolean | null): boolean;
1741
+ /**
1742
+ * Create a clone of this position model.
1743
+ */
1744
+ clone(): PositionModel;
1640
1745
  }
1641
1746
  /**
1642
1747
  * The address of a [Solana account][acc].
@@ -1694,6 +1799,30 @@ export class Pubkey {
1694
1799
  */
1695
1800
  static findProgramAddress(seeds: any[], program_id: Pubkey): any;
1696
1801
  }
1802
+ /**
1803
+ * A JS binding for [`Simulator`].
1804
+ */
1805
+ export class Simulator {
1806
+ private constructor();
1807
+ free(): void;
1808
+ /**
1809
+ * Get market by its market token.
1810
+ */
1811
+ get_market(market_token: string): MarketModel | undefined;
1812
+ /**
1813
+ * Get price for the given token.
1814
+ */
1815
+ get_price(token: string): Value | undefined;
1816
+ /**
1817
+ * Upsert the prices for the given token.
1818
+ */
1819
+ insert_price(token: string, price: Value): void;
1820
+ simulate_order(args: SimulateOrderArgs, position?: Position | null): OrderSimulationOutput;
1821
+ /**
1822
+ * Create a clone of this simulator.
1823
+ */
1824
+ clone(): Simulator;
1825
+ }
1697
1826
  /**
1698
1827
  * JS version of [`TradeEvent`].
1699
1828
  */
package/index_bg.js CHANGED
@@ -799,6 +799,14 @@ export class Market {
799
799
  wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
800
800
  }
801
801
  }
802
+ /**
803
+ * Create a clone of this market.
804
+ * @returns {Market}
805
+ */
806
+ clone() {
807
+ const ret = wasm.market_clone(this.__wbg_ptr);
808
+ return Market.__wrap(ret);
809
+ }
802
810
  }
803
811
 
804
812
  const MarketGraphFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -809,6 +817,14 @@ const MarketGraphFinalization = (typeof FinalizationRegistry === 'undefined')
809
817
  */
810
818
  export class MarketGraph {
811
819
 
820
+ static __wrap(ptr) {
821
+ ptr = ptr >>> 0;
822
+ const obj = Object.create(MarketGraph.prototype);
823
+ obj.__wbg_ptr = ptr;
824
+ MarketGraphFinalization.register(obj, obj.__wbg_ptr, obj);
825
+ return obj;
826
+ }
827
+
812
828
  __destroy_into_raw() {
813
829
  const ptr = this.__wbg_ptr;
814
830
  this.__wbg_ptr = 0;
@@ -949,6 +965,35 @@ export class MarketGraph {
949
965
  }
950
966
  return OrderSimulationOutput.__wrap(ret[0]);
951
967
  }
968
+ /**
969
+ * Create a simulator.
970
+ * @param {CreateGraphSimulatorOptions | null} [options]
971
+ * @returns {Simulator}
972
+ */
973
+ to_simulator(options) {
974
+ const ret = wasm.marketgraph_to_simulator(this.__wbg_ptr, isLikeNone(options) ? 0 : addToExternrefTable0(options));
975
+ return Simulator.__wrap(ret);
976
+ }
977
+ /**
978
+ * Update with simulator.
979
+ * @param {Simulator} simulator
980
+ * @param {UpdateGraphWithSimulatorOptions | null} [options]
981
+ */
982
+ update_with_simulator(simulator, options) {
983
+ _assertClass(simulator, Simulator);
984
+ const ret = wasm.marketgraph_update_with_simulator(this.__wbg_ptr, simulator.__wbg_ptr, isLikeNone(options) ? 0 : addToExternrefTable0(options));
985
+ if (ret[1]) {
986
+ throw takeFromExternrefTable0(ret[0]);
987
+ }
988
+ }
989
+ /**
990
+ * Create a clone of this graph.
991
+ * @returns {MarketGraph}
992
+ */
993
+ clone() {
994
+ const ret = wasm.marketgraph_clone(this.__wbg_ptr);
995
+ return MarketGraph.__wrap(ret);
996
+ }
952
997
  }
953
998
 
954
999
  const MarketModelFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -1014,6 +1059,14 @@ export class MarketModel {
1014
1059
  }
1015
1060
  return PositionModel.__wrap(ret[0]);
1016
1061
  }
1062
+ /**
1063
+ * Create a clone of this market model.
1064
+ * @returns {MarketModel}
1065
+ */
1066
+ clone() {
1067
+ const ret = wasm.marketmodel_clone(this.__wbg_ptr);
1068
+ return MarketModel.__wrap(ret);
1069
+ }
1017
1070
  }
1018
1071
 
1019
1072
  const MessageFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -1093,10 +1146,11 @@ export class OrderSimulationOutput {
1093
1146
  }
1094
1147
  /**
1095
1148
  * Returns increase order simulation output.
1149
+ * @param {boolean | null} [skip_position]
1096
1150
  * @returns {IncreaseOrderSimulationOutput | undefined}
1097
1151
  */
1098
- increase() {
1099
- const ret = wasm.ordersimulationoutput_increase(this.__wbg_ptr);
1152
+ increase(skip_position) {
1153
+ const ret = wasm.ordersimulationoutput_increase(this.__wbg_ptr, isLikeNone(skip_position) ? 0xFFFFFF : skip_position ? 1 : 0);
1100
1154
  if (ret[2]) {
1101
1155
  throw takeFromExternrefTable0(ret[1]);
1102
1156
  }
@@ -1104,10 +1158,11 @@ export class OrderSimulationOutput {
1104
1158
  }
1105
1159
  /**
1106
1160
  * Returns decrease order simulation output.
1161
+ * @param {boolean | null} [skip_position]
1107
1162
  * @returns {DecreaseOrderSimulationOutput | undefined}
1108
1163
  */
1109
- decrease() {
1110
- const ret = wasm.ordersimulationoutput_decrease(this.__wbg_ptr);
1164
+ decrease(skip_position) {
1165
+ const ret = wasm.ordersimulationoutput_decrease(this.__wbg_ptr, isLikeNone(skip_position) ? 0xFFFFFF : skip_position ? 1 : 0);
1111
1166
  if (ret[2]) {
1112
1167
  throw takeFromExternrefTable0(ret[1]);
1113
1168
  }
@@ -1124,6 +1179,14 @@ export class OrderSimulationOutput {
1124
1179
  }
1125
1180
  return takeFromExternrefTable0(ret[0]);
1126
1181
  }
1182
+ /**
1183
+ * Returns the result position model.
1184
+ * @returns {PositionModel | undefined}
1185
+ */
1186
+ position_model() {
1187
+ const ret = wasm.ordersimulationoutput_position_model(this.__wbg_ptr);
1188
+ return ret === 0 ? undefined : PositionModel.__wrap(ret);
1189
+ }
1127
1190
  }
1128
1191
 
1129
1192
  const PodElGamalPubkeyFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -1308,6 +1371,14 @@ export class Position {
1308
1371
  }
1309
1372
  return PositionModel.__wrap(ret[0]);
1310
1373
  }
1374
+ /**
1375
+ * Create a clone of this position.
1376
+ * @returns {Position}
1377
+ */
1378
+ clone() {
1379
+ const ret = wasm.position_clone(this.__wbg_ptr);
1380
+ return Position.__wrap(ret);
1381
+ }
1311
1382
  }
1312
1383
 
1313
1384
  const PositionModelFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -1395,6 +1466,14 @@ export class PositionModel {
1395
1466
  }
1396
1467
  return ret[0] !== 0;
1397
1468
  }
1469
+ /**
1470
+ * Create a clone of this position model.
1471
+ * @returns {PositionModel}
1472
+ */
1473
+ clone() {
1474
+ const ret = wasm.positionmodel_clone(this.__wbg_ptr);
1475
+ return PositionModel.__wrap(ret);
1476
+ }
1398
1477
  }
1399
1478
 
1400
1479
  const PubkeyFinalization = (typeof FinalizationRegistry === 'undefined')
@@ -1551,6 +1630,101 @@ export class Pubkey {
1551
1630
  }
1552
1631
  }
1553
1632
 
1633
+ const SimulatorFinalization = (typeof FinalizationRegistry === 'undefined')
1634
+ ? { register: () => {}, unregister: () => {} }
1635
+ : new FinalizationRegistry(ptr => wasm.__wbg_simulator_free(ptr >>> 0, 1));
1636
+ /**
1637
+ * A JS binding for [`Simulator`].
1638
+ */
1639
+ export class Simulator {
1640
+
1641
+ static __wrap(ptr) {
1642
+ ptr = ptr >>> 0;
1643
+ const obj = Object.create(Simulator.prototype);
1644
+ obj.__wbg_ptr = ptr;
1645
+ SimulatorFinalization.register(obj, obj.__wbg_ptr, obj);
1646
+ return obj;
1647
+ }
1648
+
1649
+ __destroy_into_raw() {
1650
+ const ptr = this.__wbg_ptr;
1651
+ this.__wbg_ptr = 0;
1652
+ SimulatorFinalization.unregister(this);
1653
+ return ptr;
1654
+ }
1655
+
1656
+ free() {
1657
+ const ptr = this.__destroy_into_raw();
1658
+ wasm.__wbg_simulator_free(ptr, 0);
1659
+ }
1660
+ /**
1661
+ * Get market by its market token.
1662
+ * @param {string} market_token
1663
+ * @returns {MarketModel | undefined}
1664
+ */
1665
+ get_market(market_token) {
1666
+ const ptr0 = passStringToWasm0(market_token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1667
+ const len0 = WASM_VECTOR_LEN;
1668
+ const ret = wasm.simulator_get_market(this.__wbg_ptr, ptr0, len0);
1669
+ if (ret[2]) {
1670
+ throw takeFromExternrefTable0(ret[1]);
1671
+ }
1672
+ return ret[0] === 0 ? undefined : MarketModel.__wrap(ret[0]);
1673
+ }
1674
+ /**
1675
+ * Get price for the given token.
1676
+ * @param {string} token
1677
+ * @returns {Value | undefined}
1678
+ */
1679
+ get_price(token) {
1680
+ const ptr0 = passStringToWasm0(token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1681
+ const len0 = WASM_VECTOR_LEN;
1682
+ const ret = wasm.simulator_get_price(this.__wbg_ptr, ptr0, len0);
1683
+ if (ret[2]) {
1684
+ throw takeFromExternrefTable0(ret[1]);
1685
+ }
1686
+ return takeFromExternrefTable0(ret[0]);
1687
+ }
1688
+ /**
1689
+ * Upsert the prices for the given token.
1690
+ * @param {string} token
1691
+ * @param {Value} price
1692
+ */
1693
+ insert_price(token, price) {
1694
+ const ptr0 = passStringToWasm0(token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
1695
+ const len0 = WASM_VECTOR_LEN;
1696
+ const ret = wasm.simulator_insert_price(this.__wbg_ptr, ptr0, len0, price);
1697
+ if (ret[1]) {
1698
+ throw takeFromExternrefTable0(ret[0]);
1699
+ }
1700
+ }
1701
+ /**
1702
+ * @param {SimulateOrderArgs} args
1703
+ * @param {Position | null} [position]
1704
+ * @returns {OrderSimulationOutput}
1705
+ */
1706
+ simulate_order(args, position) {
1707
+ let ptr0 = 0;
1708
+ if (!isLikeNone(position)) {
1709
+ _assertClass(position, Position);
1710
+ ptr0 = position.__destroy_into_raw();
1711
+ }
1712
+ const ret = wasm.simulator_simulate_order(this.__wbg_ptr, args, ptr0);
1713
+ if (ret[2]) {
1714
+ throw takeFromExternrefTable0(ret[1]);
1715
+ }
1716
+ return OrderSimulationOutput.__wrap(ret[0]);
1717
+ }
1718
+ /**
1719
+ * Create a clone of this simulator.
1720
+ * @returns {Simulator}
1721
+ */
1722
+ clone() {
1723
+ const ret = wasm.simulator_clone(this.__wbg_ptr);
1724
+ return Simulator.__wrap(ret);
1725
+ }
1726
+ }
1727
+
1554
1728
  const SystemInstructionFinalization = (typeof FinalizationRegistry === 'undefined')
1555
1729
  ? { register: () => {}, unregister: () => {} }
1556
1730
  : new FinalizationRegistry(ptr => wasm.__wbg_systeminstruction_free(ptr >>> 0, 1));
package/index_bg.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@gmsol-labs/gmsol-sdk",
3
3
  "type": "module",
4
4
  "description": "GMX-Solana is an extension of GMX on the Solana blockchain.",
5
- "version": "0.8.0-beta.1",
5
+ "version": "0.8.0-beta.3",
6
6
  "license": "SEE LICENSE IN ../../LICENSE",
7
7
  "repository": {
8
8
  "type": "git",