@scallop-io/sui-scallop-sdk 0.37.9 → 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({
@@ -1,5 +1,6 @@
1
1
  export declare const API_BASE_URL = "https://sui.api.scallop.io";
2
2
  export declare const ADDRESSES_ID = "6462a088a7ace142bb6d7e9b";
3
+ export declare const PROTOCOL_OBJECT_ID = "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
3
4
  export declare const SUPPORT_ASSET_COINS: readonly ["eth", "btc", "usdc", "usdt", "sui", "apt", "sol", "cetus"];
4
5
  export declare const SUPPORT_COLLATERAL_COINS: readonly ["eth", "btc", "usdc", "usdt", "sui", "apt", "sol", "cetus"];
5
6
  export declare const SUPPORT_ORACLES: readonly ["supra", "switchboard", "pyth"];
package/dist/index.js CHANGED
@@ -32,6 +32,7 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  ADDRESSES_ID: () => ADDRESSES_ID,
34
34
  API_BASE_URL: () => API_BASE_URL,
35
+ PROTOCOL_OBJECT_ID: () => PROTOCOL_OBJECT_ID,
35
36
  SUI_COIN_TYPE_ARG_REGEX: () => SUI_COIN_TYPE_ARG_REGEX,
36
37
  SUPPORT_ASSET_COINS: () => SUPPORT_ASSET_COINS,
37
38
  SUPPORT_COLLATERAL_COINS: () => SUPPORT_COLLATERAL_COINS,
@@ -47,6 +48,7 @@ module.exports = __toCommonJS(src_exports);
47
48
  // src/constants/common.ts
48
49
  var API_BASE_URL = "https://sui.api.scallop.io";
49
50
  var ADDRESSES_ID = "6462a088a7ace142bb6d7e9b";
51
+ var PROTOCOL_OBJECT_ID = "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
50
52
  var SUPPORT_ASSET_COINS = [
51
53
  "eth",
52
54
  "btc",
@@ -512,7 +514,6 @@ var import_sui_kit5 = require("@scallop-io/sui-kit");
512
514
  // src/models/scallopUtils.ts
513
515
  var import_sui = require("@mysten/sui.js");
514
516
  var import_sui_kit = require("@scallop-io/sui-kit");
515
- var import_price_service_client = require("@pythnetwork/price-service-client");
516
517
  var ScallopUtils = class {
517
518
  constructor(params) {
518
519
  this._suiKit = new import_sui_kit.SuiKit(params);
@@ -532,23 +533,6 @@ var ScallopUtils = class {
532
533
  );
533
534
  return coins.map((c) => c.objectId);
534
535
  }
535
- /**
536
- * @description Fetch price feed VAAs of interest from the Pyth.
537
- * @param priceIds Array of hex-encoded price ids.
538
- * @param isTestnet Specify whether it is a test network.
539
- * @return Array of base64 encoded VAAs.
540
- */
541
- async getVaas(priceIds, isTestnet) {
542
- const connection = new import_price_service_client.PriceServiceConnection(
543
- isTestnet ? "https://xc-testnet.pyth.network" : "https://xc-mainnet.pyth.network",
544
- {
545
- priceFeedRequestConfig: {
546
- binary: true
547
- }
548
- }
549
- );
550
- return await connection.getLatestVaas(priceIds);
551
- }
552
536
  /**
553
537
  * @description Handle non-standard coins.
554
538
  * @param coinPackageId Package id of coin.
@@ -619,17 +603,16 @@ var ScallopUtils = class {
619
603
  * @description Handle market coin types.
620
604
  *
621
605
  * @param coinPackageId Package id of coin.
622
- * @param protocolPkgId Package id of protocol.
623
606
  * @param coinName specific support coin name.
624
607
  *
625
608
  * @return marketCoinType.
626
609
  */
627
- parseMarketCoinType(coinPackageId, protocolPkgId, coinName) {
610
+ parseMarketCoinType(coinPackageId, coinName) {
628
611
  const coinType = this.parseCoinType(
629
612
  coinName === "sui" ? import_sui.SUI_FRAMEWORK_ADDRESS : coinPackageId,
630
613
  coinName
631
614
  );
632
- return `${protocolPkgId}::reserve::MarketCoin<${coinType}>`;
615
+ return `${PROTOCOL_OBJECT_ID}::reserve::MarketCoin<${coinType}>`;
633
616
  }
634
617
  };
635
618
 
@@ -693,7 +676,6 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils, rateType) => {
693
676
  const symbol = coin.toUpperCase();
694
677
  const marketCoinType = scallopUtils.parseMarketCoinType(
695
678
  scallopAddress.get(`core.coins.${coin}.id`),
696
- scallopAddress.get("core.packages.protocol.id"),
697
679
  coin
698
680
  );
699
681
  const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" || coin === "btc" || coin === "apt" || coin === "sol" ? {
@@ -790,14 +772,12 @@ var queryObligation = async (obligationId, scallopAddress, suiKit) => {
790
772
  const queryResult = await suiKit.inspectTxn(txBlock);
791
773
  return queryResult.events[0].parsedJson;
792
774
  };
793
- var getObligations = async (ownerAddress, scallopAddress, suiKit) => {
775
+ var getObligations = async (ownerAddress, suiKit) => {
794
776
  const owner = ownerAddress || suiKit.currentAddress();
795
777
  const keyObjectRefs = await suiKit.provider().getOwnedObjects({
796
778
  owner,
797
779
  filter: {
798
- StructType: `${scallopAddress.get(
799
- "core.packages.protocol.id"
800
- )}::obligation::ObligationKey`
780
+ StructType: `${PROTOCOL_OBJECT_ID}::obligation::ObligationKey`
801
781
  }
802
782
  });
803
783
  const keyIds = keyObjectRefs.data.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
@@ -987,8 +967,8 @@ var newTxBlock = (scallopAddress, scallopUtils) => {
987
967
  };
988
968
 
989
969
  // src/txBuilders/oracle.ts
990
- var import_bcs = require("@mysten/bcs");
991
970
  var import_sui3 = require("@mysten/sui.js");
971
+ var import_pyth_sui_js = require("@pythnetwork/pyth-sui-js");
992
972
  var updateOraclesForWithdrawCollateral = async (txBlock, address, scallopUtils, suiKit, obligationId, isTestnet) => {
993
973
  const obligationCoinNames = await getObligationCoinNames(
994
974
  suiKit,
@@ -998,6 +978,7 @@ var updateOraclesForWithdrawCollateral = async (txBlock, address, scallopUtils,
998
978
  );
999
979
  return updateOracles(
1000
980
  txBlock,
981
+ suiKit,
1001
982
  address,
1002
983
  scallopUtils,
1003
984
  obligationCoinNames,
@@ -1016,6 +997,7 @@ var updateOraclesForBorrow = async (txBlock, address, scallopUtils, suiKit, obli
1016
997
  ];
1017
998
  return updateOracles(
1018
999
  txBlock,
1000
+ suiKit,
1019
1001
  address,
1020
1002
  scallopUtils,
1021
1003
  updateCoinNames,
@@ -1038,30 +1020,46 @@ var getObligationCoinNames = async (suiKit, obligationId, address, scallopUtils)
1038
1020
  });
1039
1021
  return obligationCoinNames;
1040
1022
  };
1041
- var updateOracles = async (txBlock, address, scallopUtils, coinNames, isTestnet) => {
1042
- const updateCoinTypes = [...new Set(coinNames)];
1043
- for (const coinName of updateCoinTypes) {
1044
- 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);
1045
1049
  }
1046
1050
  };
1047
- var updateOracle = async (txBlock, address, scallopUtils, coinName, isTestnet) => {
1051
+ var updateOracle = async (txBlock, rules, address, scallopUtils, coinName) => {
1048
1052
  const coinPackageId = address.get(`core.coins.${coinName}.id`);
1049
1053
  const coinType = scallopUtils.parseCoinType(coinPackageId, coinName);
1050
- const [vaaFromFeeId] = await scallopUtils.getVaas(
1051
- [address.get(`core.coins.${coinName}.oracle.pyth.feed`)],
1052
- isTestnet
1053
- );
1054
1054
  updatePrice(
1055
1055
  txBlock,
1056
- isTestnet ? ["pyth"] : ["pyth"],
1056
+ rules,
1057
1057
  address.get("core.packages.xOracle.id"),
1058
1058
  address.get("core.oracles.xOracle"),
1059
1059
  address.get("core.packages.pyth.id"),
1060
1060
  address.get("core.oracles.pyth.registry"),
1061
1061
  address.get("core.oracles.pyth.state"),
1062
- address.get("core.oracles.pyth.wormholeState"),
1063
1062
  address.get(`core.coins.${coinName}.oracle.pyth.feedObject`),
1064
- vaaFromFeeId,
1065
1063
  address.get("core.packages.switchboard.id"),
1066
1064
  address.get("core.oracles.switchboard.registry"),
1067
1065
  address.get(`core.coins.${coinName}.oracle.switchboard`),
@@ -1071,7 +1069,7 @@ var updateOracle = async (txBlock, address, scallopUtils, coinName, isTestnet) =
1071
1069
  coinType
1072
1070
  );
1073
1071
  };
1074
- 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) {
1075
1073
  const request = priceUpdateRequest(
1076
1074
  txBlock,
1077
1075
  xOraclePackageId,
@@ -1084,9 +1082,7 @@ function updatePrice(txBlock, rules, xOraclePackageId, xOracleId, pythPackageId,
1084
1082
  pythPackageId,
1085
1083
  request,
1086
1084
  pythStateId,
1087
- pythWormholeStateId,
1088
1085
  pythFeedObjectId,
1089
- pythVaaFromFeeId,
1090
1086
  pythRegistryId,
1091
1087
  coinType
1092
1088
  );
@@ -1145,20 +1141,10 @@ function updateSwitchboardPrice(txBlock, packageId, request, aggregatorId, regis
1145
1141
  [coinType]
1146
1142
  );
1147
1143
  }
1148
- function updatePythPrice(txBlock, packageId, request, stateId, wormholeStateId, feedObjectId, vaaFromFeeId, registryId, coinType) {
1149
- const [updateFee] = txBlock.splitSUIFromGas([1]);
1144
+ function updatePythPrice(txBlock, packageId, request, stateId, feedObjectId, registryId, coinType) {
1150
1145
  txBlock.moveCall(
1151
1146
  `${packageId}::rule::set_price`,
1152
- [
1153
- request,
1154
- wormholeStateId,
1155
- stateId,
1156
- feedObjectId,
1157
- registryId,
1158
- txBlock.pure([...(0, import_bcs.fromB64)(vaaFromFeeId)]),
1159
- updateFee,
1160
- import_sui3.SUI_CLOCK_OBJECT_ID
1161
- ],
1147
+ [request, stateId, feedObjectId, registryId, import_sui3.SUI_CLOCK_OBJECT_ID],
1162
1148
  [coinType]
1163
1149
  );
1164
1150
  }
@@ -1173,12 +1159,7 @@ var selectCoin = async (txBlock, scallopAddress, scallopUtils, coinName, amount,
1173
1159
  };
1174
1160
  var selectMarketCoin = async (txBlock, scallopAddress, scallopUtils, coinName, amount, sender) => {
1175
1161
  const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
1176
- const protocolPackageId = scallopAddress.get("core.packages.protocol.id");
1177
- const coinType = scallopUtils.parseMarketCoinType(
1178
- coinPackageId,
1179
- protocolPackageId,
1180
- coinName
1181
- );
1162
+ const coinType = scallopUtils.parseMarketCoinType(coinPackageId, coinName);
1182
1163
  const coins = await scallopUtils.selectCoins(sender, amount, coinType);
1183
1164
  const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
1184
1165
  return { takeCoin, leftCoin };
@@ -1193,13 +1174,13 @@ var requireSender = (txBlock) => {
1193
1174
  return sender;
1194
1175
  };
1195
1176
  var requireObligationInfo = async (...args) => {
1196
- const [txBlock, scallopAddress, suiKit, obligationId, obligationKey] = args;
1197
- if (args.length === 4 && obligationId)
1177
+ const [txBlock, suiKit, obligationId, obligationKey] = args;
1178
+ if (args.length === 3 && obligationId)
1198
1179
  return { obligationId };
1199
- if (args.length === 5 && obligationId && obligationKey)
1180
+ if (args.length === 4 && obligationId && obligationKey)
1200
1181
  return { obligationId, obligationKey };
1201
1182
  const sender = requireSender(txBlock);
1202
- const obligations = await getObligations(sender, scallopAddress, suiKit);
1183
+ const obligations = await getObligations(sender, suiKit);
1203
1184
  if (obligations.length === 0) {
1204
1185
  throw new Error(`No obligation found for sender ${sender}`);
1205
1186
  }
@@ -1213,7 +1194,6 @@ var scallopQuickMethodsHandler = {
1213
1194
  const sender = requireSender(txBlock);
1214
1195
  const { obligationId: obligationArg } = await requireObligationInfo(
1215
1196
  txBlock,
1216
- scallopAddress,
1217
1197
  suiKit,
1218
1198
  obligationId
1219
1199
  );
@@ -1236,7 +1216,6 @@ var scallopQuickMethodsHandler = {
1236
1216
  takeCollateralQuick: ({ txBlock, suiKit, scallopUtils, scallopAddress, isTestnet }) => async (amount, coinName, obligationId, obligationKey) => {
1237
1217
  const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo(
1238
1218
  txBlock,
1239
- scallopAddress,
1240
1219
  suiKit,
1241
1220
  obligationId,
1242
1221
  obligationKey
@@ -1290,7 +1269,6 @@ var scallopQuickMethodsHandler = {
1290
1269
  borrowQuick: ({ txBlock, suiKit, scallopUtils, scallopAddress, isTestnet }) => async (amount, coinName, obligationId, obligationKey) => {
1291
1270
  const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo(
1292
1271
  txBlock,
1293
- scallopAddress,
1294
1272
  suiKit,
1295
1273
  obligationId,
1296
1274
  obligationKey
@@ -1315,7 +1293,6 @@ var scallopQuickMethodsHandler = {
1315
1293
  const sender = requireSender(txBlock);
1316
1294
  const { obligationId: obligationArg } = await requireObligationInfo(
1317
1295
  txBlock,
1318
- scallopAddress,
1319
1296
  suiKit,
1320
1297
  obligationId
1321
1298
  );
@@ -1335,9 +1312,10 @@ var scallopQuickMethodsHandler = {
1335
1312
  return txBlock.repay(obligationArg, takeCoin, coinName);
1336
1313
  }
1337
1314
  },
1338
- updateAssetPricesQuick: ({ txBlock, scallopUtils, scallopAddress, isTestnet }) => async (coinNames) => {
1315
+ updateAssetPricesQuick: ({ txBlock, suiKit, scallopUtils, scallopAddress, isTestnet }) => async (coinNames) => {
1339
1316
  return updateOracles(
1340
1317
  txBlock,
1318
+ suiKit,
1341
1319
  scallopAddress,
1342
1320
  scallopUtils,
1343
1321
  coinNames,
@@ -1400,7 +1378,7 @@ var ScallopClient = class {
1400
1378
  */
1401
1379
  async getObligations(ownerAddress) {
1402
1380
  const owner = ownerAddress || this.walletAddress;
1403
- return getObligations(owner, this.address, this.suiKit);
1381
+ return getObligations(owner, this.suiKit);
1404
1382
  }
1405
1383
  /**
1406
1384
  * Query obligation data.
@@ -1640,6 +1618,7 @@ var Scallop = class {
1640
1618
  0 && (module.exports = {
1641
1619
  ADDRESSES_ID,
1642
1620
  API_BASE_URL,
1621
+ PROTOCOL_OBJECT_ID,
1643
1622
  SUI_COIN_TYPE_ARG_REGEX,
1644
1623
  SUPPORT_ASSET_COINS,
1645
1624
  SUPPORT_COLLATERAL_COINS,