@scallop-io/sui-scallop-sdk 0.37.10 → 0.37.12

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 CHANGED
@@ -5,14 +5,14 @@
5
5
  </p>
6
6
  <p align="center">
7
7
  <a style="padding-right: 5px;" href="https://github.com/scallop-io/sui-scallop-sdk/releases">
8
- <img alt="GitHub release" src="https://img.shields.io/github/v/release/@scallop-io/sui-scallop-sdk?display_name=tag">
8
+ <img alt="GitHub release" src="https://img.shields.io/github/v/release/scallop-io/sui-scallop-sdk?display_name=tag">
9
9
  </a>
10
10
  <a href="https://github.com/scallop-io/sui-scallop-sdk/blob/main/LICENSE">
11
- <img alt="NPM" src="https://img.shields.io/npm/l/@scallop/sdk?registry_uri=https%3A%2F%2Fnpm.pkg.github.com%2F">
11
+ <img alt="GitHub licence" src="https://img.shields.io/github/license/scallop-io/sui-scallop-sdk?logoColor=blue">
12
12
  </a>
13
13
  </p>
14
14
 
15
- # The Typescript SDK for interacting with Scallop lending protocol on SUI network
15
+ # The Typescript SDK for interacting with the Scallop lending protocol on the SUI network
16
16
 
17
17
  ## Description
18
18
 
@@ -61,7 +61,7 @@ This SDK is used to interact with [sui-lending-protocal](https://github.com/scal
61
61
 
62
62
  For the original codes, please refer to `test/index.spec.ts` file.
63
63
 
64
- You need to setup the `.env` file before testing. (Reference `.env.example`)
64
+ You need to set up the `.env` file before testing. (Reference `.env.example`)
65
65
 
66
66
  - Setup the network
67
67
 
@@ -232,7 +232,7 @@ You need to setup the `.env` file before testing. (Reference `.env.example`)
232
232
 
233
233
  ## Use address manager
234
234
 
235
- General Users will basically only use the `get`, `getAddresses` or `getAllAddresses` methods to read addresses. Here are some simple examples:
235
+ General Users will basically only use the `get`, `getAddresses`, or `getAllAddresses` methods to read addresses. Here are some simple examples:
236
236
 
237
237
  ```typescript
238
238
  const address = new ScallopAddress({
@@ -252,9 +252,9 @@ const allAddresses = addressBuilder.getAllAddresses();
252
252
 
253
253
  Scallop currently maintains this address `6462a088a7ace142bb6d7e9b` for use in the production environment.
254
254
 
255
- Of course, you can also directly use the [sui-scallop-api](https://github.com/scallop-io/sui-scallop-api) project to directly request an addresses.
255
+ Of course, you can also directly use the [sui-scallop-api](https://github.com/scallop-io/sui-scallop-api) project to directly request addresses.
256
256
 
257
- The rest of the features are for Scallop administrators to use, and require a set of API authentication key to use the create, update, and delete address functions.
257
+ The rest of the features are for Scallop administrators to use, and require a set of API authentication keys to use the create, update, and delete address functions.
258
258
 
259
259
  ```typescript
260
260
  const address = new ScallopAddress({
package/dist/index.js CHANGED
@@ -514,7 +514,6 @@ var import_sui_kit5 = require("@scallop-io/sui-kit");
514
514
  // src/models/scallopUtils.ts
515
515
  var import_sui = require("@mysten/sui.js");
516
516
  var import_sui_kit = require("@scallop-io/sui-kit");
517
- var import_price_service_client = require("@pythnetwork/price-service-client");
518
517
  var ScallopUtils = class {
519
518
  constructor(params) {
520
519
  this._suiKit = new import_sui_kit.SuiKit(params);
@@ -534,23 +533,6 @@ var ScallopUtils = class {
534
533
  );
535
534
  return coins.map((c) => c.objectId);
536
535
  }
537
- /**
538
- * @description Fetch price feed VAAs of interest from the Pyth.
539
- * @param priceIds Array of hex-encoded price ids.
540
- * @param isTestnet Specify whether it is a test network.
541
- * @return Array of base64 encoded VAAs.
542
- */
543
- async getVaas(priceIds, isTestnet) {
544
- const connection = new import_price_service_client.PriceServiceConnection(
545
- isTestnet ? "https://xc-testnet.pyth.network" : "https://xc-mainnet.pyth.network",
546
- {
547
- priceFeedRequestConfig: {
548
- binary: true
549
- }
550
- }
551
- );
552
- return await connection.getLatestVaas(priceIds);
553
- }
554
536
  /**
555
537
  * @description Handle non-standard coins.
556
538
  * @param coinPackageId Package id of coin.
@@ -985,8 +967,8 @@ var newTxBlock = (scallopAddress, scallopUtils) => {
985
967
  };
986
968
 
987
969
  // src/txBuilders/oracle.ts
988
- var import_bcs = require("@mysten/bcs");
989
970
  var import_sui3 = require("@mysten/sui.js");
971
+ var import_pyth_sui_js = require("@pythnetwork/pyth-sui-js");
990
972
  var updateOraclesForWithdrawCollateral = async (txBlock, address, scallopUtils, suiKit, obligationId, isTestnet) => {
991
973
  const obligationCoinNames = await getObligationCoinNames(
992
974
  suiKit,
@@ -996,6 +978,7 @@ var updateOraclesForWithdrawCollateral = async (txBlock, address, scallopUtils,
996
978
  );
997
979
  return updateOracles(
998
980
  txBlock,
981
+ suiKit,
999
982
  address,
1000
983
  scallopUtils,
1001
984
  obligationCoinNames,
@@ -1014,6 +997,7 @@ var updateOraclesForBorrow = async (txBlock, address, scallopUtils, suiKit, obli
1014
997
  ];
1015
998
  return updateOracles(
1016
999
  txBlock,
1000
+ suiKit,
1017
1001
  address,
1018
1002
  scallopUtils,
1019
1003
  updateCoinNames,
@@ -1036,30 +1020,46 @@ var getObligationCoinNames = async (suiKit, obligationId, address, scallopUtils)
1036
1020
  });
1037
1021
  return obligationCoinNames;
1038
1022
  };
1039
- var updateOracles = async (txBlock, address, scallopUtils, coinNames, isTestnet) => {
1040
- const updateCoinTypes = [...new Set(coinNames)];
1041
- for (const coinName of updateCoinTypes) {
1042
- await updateOracle(txBlock, address, scallopUtils, coinName, isTestnet);
1023
+ var updateOracles = async (txBlock, suiKit, address, scallopUtils, coinNames, isTestnet) => {
1024
+ const rules = isTestnet ? ["pyth"] : ["pyth"];
1025
+ if (rules.includes("pyth")) {
1026
+ const pythClient = new import_pyth_sui_js.SuiPythClient(
1027
+ suiKit.provider(),
1028
+ address.get("core.oracles.pyth.state"),
1029
+ address.get("core.oracles.pyth.wormholeState")
1030
+ );
1031
+ const priceIds = coinNames.map(
1032
+ (coinName) => address.get(`core.coins.${coinName}.oracle.pyth.feed`)
1033
+ );
1034
+ const pythConnection = new import_pyth_sui_js.SuiPriceServiceConnection(
1035
+ isTestnet ? "hermes-beta.pyth.network" : "https://hermes.pyth.network"
1036
+ );
1037
+ const priceUpdateData = await pythConnection.getPriceFeedsUpdateData(
1038
+ priceIds
1039
+ );
1040
+ await pythClient.updatePriceFeeds(
1041
+ txBlock.txBlock,
1042
+ priceUpdateData,
1043
+ priceIds
1044
+ );
1045
+ }
1046
+ const updateCoinNames = [...new Set(coinNames)];
1047
+ for (const coinName of updateCoinNames) {
1048
+ await updateOracle(txBlock, rules, address, scallopUtils, coinName);
1043
1049
  }
1044
1050
  };
1045
- var updateOracle = async (txBlock, address, scallopUtils, coinName, isTestnet) => {
1051
+ var updateOracle = async (txBlock, rules, address, scallopUtils, coinName) => {
1046
1052
  const coinPackageId = address.get(`core.coins.${coinName}.id`);
1047
1053
  const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
1048
- const [vaaFromFeeId] = await scallopUtils.getVaas(
1049
- [address.get(`core.coins.${coinName}.oracle.pyth.feed`)],
1050
- isTestnet
1051
- );
1052
1054
  updatePrice(
1053
1055
  txBlock,
1054
- isTestnet ? ["pyth"] : ["pyth"],
1056
+ rules,
1055
1057
  address.get("core.packages.xOracle.id"),
1056
1058
  address.get("core.oracles.xOracle"),
1057
1059
  address.get("core.packages.pyth.id"),
1058
1060
  address.get("core.oracles.pyth.registry"),
1059
1061
  address.get("core.oracles.pyth.state"),
1060
- address.get("core.oracles.pyth.wormholeState"),
1061
1062
  address.get(`core.coins.${coinName}.oracle.pyth.feedObject`),
1062
- vaaFromFeeId,
1063
1063
  address.get("core.packages.switchboard.id"),
1064
1064
  address.get("core.oracles.switchboard.registry"),
1065
1065
  address.get(`core.coins.${coinName}.oracle.switchboard`),
@@ -1069,7 +1069,7 @@ var updateOracle = async (txBlock, address, scallopUtils, coinName, isTestnet) =
1069
1069
  coinType
1070
1070
  );
1071
1071
  };
1072
- function updatePrice(txBlock, rules, xOraclePackageId, xOracleId, pythPackageId, pythRegistryId, pythStateId, pythWormholeStateId, pythFeedObjectId, pythVaaFromFeeId, switchboardPackageId, switchboardRegistryId, switchboardAggregatorId, supraPackageId, supraRegistryId, supraHolderId, coinType) {
1072
+ function updatePrice(txBlock, rules, xOraclePackageId, xOracleId, pythPackageId, pythRegistryId, pythStateId, pythFeedObjectId, switchboardPackageId, switchboardRegistryId, switchboardAggregatorId, supraPackageId, supraRegistryId, supraHolderId, coinType) {
1073
1073
  const request = priceUpdateRequest(
1074
1074
  txBlock,
1075
1075
  xOraclePackageId,
@@ -1082,9 +1082,7 @@ function updatePrice(txBlock, rules, xOraclePackageId, xOracleId, pythPackageId,
1082
1082
  pythPackageId,
1083
1083
  request,
1084
1084
  pythStateId,
1085
- pythWormholeStateId,
1086
1085
  pythFeedObjectId,
1087
- pythVaaFromFeeId,
1088
1086
  pythRegistryId,
1089
1087
  coinType
1090
1088
  );
@@ -1143,20 +1141,10 @@ function updateSwitchboardPrice(txBlock, packageId, request, aggregatorId, regis
1143
1141
  [coinType]
1144
1142
  );
1145
1143
  }
1146
- function updatePythPrice(txBlock, packageId, request, stateId, wormholeStateId, feedObjectId, vaaFromFeeId, registryId, coinType) {
1147
- const [updateFee] = txBlock.splitSUIFromGas([1]);
1144
+ function updatePythPrice(txBlock, packageId, request, stateId, feedObjectId, registryId, coinType) {
1148
1145
  txBlock.moveCall(
1149
1146
  `${packageId}::rule::set_price`,
1150
- [
1151
- request,
1152
- wormholeStateId,
1153
- stateId,
1154
- feedObjectId,
1155
- registryId,
1156
- txBlock.pure([...(0, import_bcs.fromB64)(vaaFromFeeId)]),
1157
- updateFee,
1158
- import_sui3.SUI_CLOCK_OBJECT_ID
1159
- ],
1147
+ [request, stateId, feedObjectId, registryId, import_sui3.SUI_CLOCK_OBJECT_ID],
1160
1148
  [coinType]
1161
1149
  );
1162
1150
  }
@@ -1324,9 +1312,10 @@ var scallopQuickMethodsHandler = {
1324
1312
  return txBlock.repay(obligationArg, takeCoin, coinName);
1325
1313
  }
1326
1314
  },
1327
- updateAssetPricesQuick: ({ txBlock, scallopUtils, scallopAddress, isTestnet }) => async (coinNames) => {
1315
+ updateAssetPricesQuick: ({ txBlock, suiKit, scallopUtils, scallopAddress, isTestnet }) => async (coinNames) => {
1328
1316
  return updateOracles(
1329
1317
  txBlock,
1318
+ suiKit,
1330
1319
  scallopAddress,
1331
1320
  scallopUtils,
1332
1321
  coinNames,