@scallop-io/sui-scallop-sdk 0.37.8 → 0.37.10
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/dist/constants/common.d.ts +3 -2
- package/dist/index.js +43 -29
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -29
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopUtils.d.ts +1 -2
- package/dist/queries/obligation.d.ts +3 -3
- package/package.json +1 -1
- package/src/constants/common.ts +9 -0
- package/src/models/scallopClient.ts +1 -1
- package/src/models/scallopUtils.ts +21 -7
- package/src/queries/market.ts +13 -4
- package/src/queries/obligation.ts +5 -10
- package/src/txBuilders/coin.ts +1 -6
- package/src/txBuilders/quickMethods.ts +4 -9
|
@@ -1,7 +1,8 @@
|
|
|
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
|
|
4
|
-
export declare const
|
|
3
|
+
export declare const PROTOCOL_OBJECT_ID = "0xefe8b36d5b2e43728cc323298626b83177803521d195cfb11e15b910e892fddf";
|
|
4
|
+
export declare const SUPPORT_ASSET_COINS: readonly ["eth", "btc", "usdc", "usdt", "sui", "apt", "sol", "cetus"];
|
|
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"];
|
|
6
7
|
export declare const SUPPORT_PACKAGES: readonly ["coinDecimalsRegistry", "math", "whitelist", "x", "protocol", "query", "supra", "pyth", "switchboard", "xOracle", "testCoin"];
|
|
7
8
|
export declare const SUI_COIN_TYPE_ARG_REGEX: RegExp;
|
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,19 +48,26 @@ 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",
|
|
53
55
|
"usdc",
|
|
54
56
|
"usdt",
|
|
55
|
-
"sui"
|
|
57
|
+
"sui",
|
|
58
|
+
"apt",
|
|
59
|
+
"sol",
|
|
60
|
+
"cetus"
|
|
56
61
|
];
|
|
57
62
|
var SUPPORT_COLLATERAL_COINS = [
|
|
58
63
|
"eth",
|
|
59
64
|
"btc",
|
|
60
65
|
"usdc",
|
|
61
66
|
"usdt",
|
|
62
|
-
"sui"
|
|
67
|
+
"sui",
|
|
68
|
+
"apt",
|
|
69
|
+
"sol",
|
|
70
|
+
"cetus"
|
|
63
71
|
];
|
|
64
72
|
var SUPPORT_ORACLES = ["supra", "switchboard", "pyth"];
|
|
65
73
|
var SUPPORT_PACKAGES = [
|
|
@@ -558,7 +566,13 @@ var ScallopUtils = class {
|
|
|
558
566
|
// USDT
|
|
559
567
|
"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c",
|
|
560
568
|
// ETH
|
|
561
|
-
"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5"
|
|
569
|
+
"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5",
|
|
570
|
+
// BTC
|
|
571
|
+
"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881",
|
|
572
|
+
// SOL
|
|
573
|
+
"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8",
|
|
574
|
+
// APT
|
|
575
|
+
"0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37"
|
|
562
576
|
];
|
|
563
577
|
if (wormHoleCoins.includes(coinPackageId)) {
|
|
564
578
|
return `${coinPackageId}::coin::COIN`;
|
|
@@ -579,7 +593,13 @@ var ScallopUtils = class {
|
|
|
579
593
|
// USDT
|
|
580
594
|
"0xc060006111016b8a020ad5b33834984a437aaa7d3c74c18e09a95d48aceab08c::coin::COIN",
|
|
581
595
|
// ETH
|
|
582
|
-
"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN"
|
|
596
|
+
"0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5::coin::COIN",
|
|
597
|
+
// BTC
|
|
598
|
+
"0x027792d9fed7f9844eb4839566001bb6f6cb4804f66aa2da6fe1ee242d896881::coin::COIN",
|
|
599
|
+
// SOL
|
|
600
|
+
"0xb7844e289a8410e50fb3ca48d69eb9cf29e27d223ef90353fe1bd8e27ff8f3f8::coin::COIN",
|
|
601
|
+
// APT
|
|
602
|
+
"0x3a5143bb1196e3bcdfab6203d1683ae29edd26294fc8bfeafe4aaa9d2704df37::coin::COIN"
|
|
583
603
|
];
|
|
584
604
|
if (coinType === wormHoleCoinTypes[0]) {
|
|
585
605
|
return "usdc";
|
|
@@ -587,6 +607,12 @@ var ScallopUtils = class {
|
|
|
587
607
|
return "usdt";
|
|
588
608
|
} else if (coinType === wormHoleCoinTypes[2]) {
|
|
589
609
|
return "eth";
|
|
610
|
+
} else if (coinType === wormHoleCoinTypes[3]) {
|
|
611
|
+
return "btc";
|
|
612
|
+
} else if (coinType === wormHoleCoinTypes[4]) {
|
|
613
|
+
return "sol";
|
|
614
|
+
} else if (coinType === wormHoleCoinTypes[5]) {
|
|
615
|
+
return "apt";
|
|
590
616
|
} else {
|
|
591
617
|
return coinType.split("::")[2].toLowerCase();
|
|
592
618
|
}
|
|
@@ -595,17 +621,16 @@ var ScallopUtils = class {
|
|
|
595
621
|
* @description Handle market coin types.
|
|
596
622
|
*
|
|
597
623
|
* @param coinPackageId Package id of coin.
|
|
598
|
-
* @param protocolPkgId Package id of protocol.
|
|
599
624
|
* @param coinName specific support coin name.
|
|
600
625
|
*
|
|
601
626
|
* @return marketCoinType.
|
|
602
627
|
*/
|
|
603
|
-
parseMarketCoinType(coinPackageId,
|
|
628
|
+
parseMarketCoinType(coinPackageId, coinName) {
|
|
604
629
|
const coinType = this.parseCoinType(
|
|
605
630
|
coinName === "sui" ? import_sui.SUI_FRAMEWORK_ADDRESS : coinPackageId,
|
|
606
631
|
coinName
|
|
607
632
|
);
|
|
608
|
-
return `${
|
|
633
|
+
return `${PROTOCOL_OBJECT_ID}::reserve::MarketCoin<${coinType}>`;
|
|
609
634
|
}
|
|
610
635
|
};
|
|
611
636
|
|
|
@@ -669,10 +694,9 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils, rateType) => {
|
|
|
669
694
|
const symbol = coin.toUpperCase();
|
|
670
695
|
const marketCoinType = scallopUtils.parseMarketCoinType(
|
|
671
696
|
scallopAddress.get(`core.coins.${coin}.id`),
|
|
672
|
-
scallopAddress.get("core.packages.protocol.id"),
|
|
673
697
|
coin
|
|
674
698
|
);
|
|
675
|
-
const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" ? {
|
|
699
|
+
const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" || coin === "btc" || coin === "apt" || coin === "sol" ? {
|
|
676
700
|
from: "Wormhole",
|
|
677
701
|
type: "Portal from Ethereum"
|
|
678
702
|
} : void 0;
|
|
@@ -729,7 +753,7 @@ var queryMarket = async (scallopAddress, suiKit, scallopUtils, rateType) => {
|
|
|
729
753
|
coinType
|
|
730
754
|
);
|
|
731
755
|
const symbol = coin.toUpperCase();
|
|
732
|
-
const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" ? {
|
|
756
|
+
const wrappedType = coin === "usdc" || coin === "usdt" || coin === "eth" || coin === "btc" || coin === "apt" || coin === "sol" ? {
|
|
733
757
|
from: "Wormhole",
|
|
734
758
|
type: "Portal from Ethereum"
|
|
735
759
|
} : void 0;
|
|
@@ -766,14 +790,12 @@ var queryObligation = async (obligationId, scallopAddress, suiKit) => {
|
|
|
766
790
|
const queryResult = await suiKit.inspectTxn(txBlock);
|
|
767
791
|
return queryResult.events[0].parsedJson;
|
|
768
792
|
};
|
|
769
|
-
var getObligations = async (ownerAddress,
|
|
793
|
+
var getObligations = async (ownerAddress, suiKit) => {
|
|
770
794
|
const owner = ownerAddress || suiKit.currentAddress();
|
|
771
795
|
const keyObjectRefs = await suiKit.provider().getOwnedObjects({
|
|
772
796
|
owner,
|
|
773
797
|
filter: {
|
|
774
|
-
StructType: `${
|
|
775
|
-
"core.packages.protocol.id"
|
|
776
|
-
)}::obligation::ObligationKey`
|
|
798
|
+
StructType: `${PROTOCOL_OBJECT_ID}::obligation::ObligationKey`
|
|
777
799
|
}
|
|
778
800
|
});
|
|
779
801
|
const keyIds = keyObjectRefs.data.map((ref) => ref?.data?.objectId).filter((id) => id !== void 0);
|
|
@@ -1149,12 +1171,7 @@ var selectCoin = async (txBlock, scallopAddress, scallopUtils, coinName, amount,
|
|
|
1149
1171
|
};
|
|
1150
1172
|
var selectMarketCoin = async (txBlock, scallopAddress, scallopUtils, coinName, amount, sender) => {
|
|
1151
1173
|
const coinPackageId = scallopAddress.get(`core.coins.${coinName}.id`);
|
|
1152
|
-
const
|
|
1153
|
-
const coinType = scallopUtils.parseMarketCoinType(
|
|
1154
|
-
coinPackageId,
|
|
1155
|
-
protocolPackageId,
|
|
1156
|
-
coinName
|
|
1157
|
-
);
|
|
1174
|
+
const coinType = scallopUtils.parseMarketCoinType(coinPackageId, coinName);
|
|
1158
1175
|
const coins = await scallopUtils.selectCoins(sender, amount, coinType);
|
|
1159
1176
|
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
|
|
1160
1177
|
return { takeCoin, leftCoin };
|
|
@@ -1169,13 +1186,13 @@ var requireSender = (txBlock) => {
|
|
|
1169
1186
|
return sender;
|
|
1170
1187
|
};
|
|
1171
1188
|
var requireObligationInfo = async (...args) => {
|
|
1172
|
-
const [txBlock,
|
|
1173
|
-
if (args.length ===
|
|
1189
|
+
const [txBlock, suiKit, obligationId, obligationKey] = args;
|
|
1190
|
+
if (args.length === 3 && obligationId)
|
|
1174
1191
|
return { obligationId };
|
|
1175
|
-
if (args.length ===
|
|
1192
|
+
if (args.length === 4 && obligationId && obligationKey)
|
|
1176
1193
|
return { obligationId, obligationKey };
|
|
1177
1194
|
const sender = requireSender(txBlock);
|
|
1178
|
-
const obligations = await getObligations(sender,
|
|
1195
|
+
const obligations = await getObligations(sender, suiKit);
|
|
1179
1196
|
if (obligations.length === 0) {
|
|
1180
1197
|
throw new Error(`No obligation found for sender ${sender}`);
|
|
1181
1198
|
}
|
|
@@ -1189,7 +1206,6 @@ var scallopQuickMethodsHandler = {
|
|
|
1189
1206
|
const sender = requireSender(txBlock);
|
|
1190
1207
|
const { obligationId: obligationArg } = await requireObligationInfo(
|
|
1191
1208
|
txBlock,
|
|
1192
|
-
scallopAddress,
|
|
1193
1209
|
suiKit,
|
|
1194
1210
|
obligationId
|
|
1195
1211
|
);
|
|
@@ -1212,7 +1228,6 @@ var scallopQuickMethodsHandler = {
|
|
|
1212
1228
|
takeCollateralQuick: ({ txBlock, suiKit, scallopUtils, scallopAddress, isTestnet }) => async (amount, coinName, obligationId, obligationKey) => {
|
|
1213
1229
|
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo(
|
|
1214
1230
|
txBlock,
|
|
1215
|
-
scallopAddress,
|
|
1216
1231
|
suiKit,
|
|
1217
1232
|
obligationId,
|
|
1218
1233
|
obligationKey
|
|
@@ -1266,7 +1281,6 @@ var scallopQuickMethodsHandler = {
|
|
|
1266
1281
|
borrowQuick: ({ txBlock, suiKit, scallopUtils, scallopAddress, isTestnet }) => async (amount, coinName, obligationId, obligationKey) => {
|
|
1267
1282
|
const { obligationId: obligationArg, obligationKey: obligationKeyArg } = await requireObligationInfo(
|
|
1268
1283
|
txBlock,
|
|
1269
|
-
scallopAddress,
|
|
1270
1284
|
suiKit,
|
|
1271
1285
|
obligationId,
|
|
1272
1286
|
obligationKey
|
|
@@ -1291,7 +1305,6 @@ var scallopQuickMethodsHandler = {
|
|
|
1291
1305
|
const sender = requireSender(txBlock);
|
|
1292
1306
|
const { obligationId: obligationArg } = await requireObligationInfo(
|
|
1293
1307
|
txBlock,
|
|
1294
|
-
scallopAddress,
|
|
1295
1308
|
suiKit,
|
|
1296
1309
|
obligationId
|
|
1297
1310
|
);
|
|
@@ -1376,7 +1389,7 @@ var ScallopClient = class {
|
|
|
1376
1389
|
*/
|
|
1377
1390
|
async getObligations(ownerAddress) {
|
|
1378
1391
|
const owner = ownerAddress || this.walletAddress;
|
|
1379
|
-
return getObligations(owner, this.
|
|
1392
|
+
return getObligations(owner, this.suiKit);
|
|
1380
1393
|
}
|
|
1381
1394
|
/**
|
|
1382
1395
|
* Query obligation data.
|
|
@@ -1616,6 +1629,7 @@ var Scallop = class {
|
|
|
1616
1629
|
0 && (module.exports = {
|
|
1617
1630
|
ADDRESSES_ID,
|
|
1618
1631
|
API_BASE_URL,
|
|
1632
|
+
PROTOCOL_OBJECT_ID,
|
|
1619
1633
|
SUI_COIN_TYPE_ARG_REGEX,
|
|
1620
1634
|
SUPPORT_ASSET_COINS,
|
|
1621
1635
|
SUPPORT_COLLATERAL_COINS,
|