@scallop-io/sui-scallop-sdk 0.46.48 → 0.46.50
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/index.js +96 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -42
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopBuilder.d.ts +3 -3
- package/dist/models/scallopQuery.d.ts +2 -1
- package/dist/queries/loyaltyProgramQuery.d.ts +1 -1
- package/dist/queries/priceQuery.d.ts +1 -1
- package/dist/types/model.d.ts +3 -1
- package/package.json +1 -1
- package/src/models/scallopBuilder.ts +3 -3
- package/src/models/scallopClient.ts +6 -3
- package/src/models/scallopQuery.ts +19 -14
- package/src/queries/loyaltyProgramQuery.ts +1 -1
- package/src/queries/priceQuery.ts +37 -19
- package/src/types/model.ts +3 -1
- package/src/utils/query.ts +17 -15
- package/dist/test.d.ts +0 -1
- package/src/test.ts +0 -19
package/dist/index.mjs
CHANGED
|
@@ -1529,7 +1529,7 @@ var ScallopAddress = class {
|
|
|
1529
1529
|
};
|
|
1530
1530
|
|
|
1531
1531
|
// src/models/scallopClient.ts
|
|
1532
|
-
import { normalizeSuiAddress as
|
|
1532
|
+
import { normalizeSuiAddress as normalizeSuiAddress4 } from "@mysten/sui.js/utils";
|
|
1533
1533
|
import { SuiKit as SuiKit4 } from "@scallop-io/sui-kit";
|
|
1534
1534
|
|
|
1535
1535
|
// src/models/scallopUtils.ts
|
|
@@ -1962,7 +1962,7 @@ var calculateBorrowIncentivePoolPointData = (parsedBorrowIncentivePoolData, pars
|
|
|
1962
1962
|
BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
1963
1963
|
weightScale
|
|
1964
1964
|
)
|
|
1965
|
-
).dividedBy(weightedStakedValue).isFinite() ? rewardValueForYear.multipliedBy(
|
|
1965
|
+
).dividedBy(weightedStakedValue).isFinite() && parsedBorrowIncentivePoolPointData.points > 0 ? rewardValueForYear.multipliedBy(
|
|
1966
1966
|
BigNumber(parsedBorrowIncentivePoolPointData.baseWeight).dividedBy(
|
|
1967
1967
|
weightScale
|
|
1968
1968
|
)
|
|
@@ -3245,27 +3245,44 @@ var getPythPrice = async (query, assetCoinName, priceFeedObject) => {
|
|
|
3245
3245
|
return 0;
|
|
3246
3246
|
};
|
|
3247
3247
|
var getPythPrices = async (query, assetCoinNames) => {
|
|
3248
|
-
const
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3248
|
+
const pythPriceFeedIds = assetCoinNames.reduce(
|
|
3249
|
+
(prev, assetCoinName) => {
|
|
3250
|
+
const pythPriceFeed = query.address.get(
|
|
3251
|
+
`core.coins.${assetCoinName}.oracle.pyth.feedObject`
|
|
3252
|
+
);
|
|
3253
|
+
if (!prev[pythPriceFeed]) {
|
|
3254
|
+
prev[pythPriceFeed] = [assetCoinName];
|
|
3255
|
+
} else {
|
|
3256
|
+
prev[pythPriceFeed].push(assetCoinName);
|
|
3257
|
+
}
|
|
3258
|
+
return prev;
|
|
3259
|
+
},
|
|
3260
|
+
{}
|
|
3261
|
+
);
|
|
3258
3262
|
const priceFeedObjects = await query.cache.queryGetObjects(
|
|
3259
|
-
|
|
3260
|
-
{
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
+
Object.keys(pythPriceFeedIds),
|
|
3264
|
+
{ showContent: true }
|
|
3265
|
+
);
|
|
3266
|
+
const assetToPriceFeedMapping = priceFeedObjects.reduce(
|
|
3267
|
+
(prev, priceFeedObject) => {
|
|
3268
|
+
pythPriceFeedIds[priceFeedObject.objectId].forEach((assetCoinName) => {
|
|
3269
|
+
prev[assetCoinName] = priceFeedObject;
|
|
3270
|
+
});
|
|
3271
|
+
return prev;
|
|
3272
|
+
},
|
|
3273
|
+
{}
|
|
3263
3274
|
);
|
|
3264
3275
|
return (await Promise.all(
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3276
|
+
Object.entries(assetToPriceFeedMapping).map(
|
|
3277
|
+
async ([assetCoinName, priceFeedObject]) => ({
|
|
3278
|
+
coinName: assetCoinName,
|
|
3279
|
+
price: await getPythPrice(
|
|
3280
|
+
query,
|
|
3281
|
+
assetCoinName,
|
|
3282
|
+
priceFeedObject
|
|
3283
|
+
)
|
|
3284
|
+
})
|
|
3285
|
+
)
|
|
3269
3286
|
)).reduce(
|
|
3270
3287
|
(prev, curr) => {
|
|
3271
3288
|
prev[curr.coinName] = curr.price;
|
|
@@ -4239,6 +4256,7 @@ var getSCoinAmount = async (query, sCoinName, ownerAddress) => {
|
|
|
4239
4256
|
};
|
|
4240
4257
|
|
|
4241
4258
|
// src/models/scallopQuery.ts
|
|
4259
|
+
import { normalizeSuiAddress as normalizeSuiAddress2 } from "@mysten/sui.js/utils";
|
|
4242
4260
|
var ScallopQuery = class {
|
|
4243
4261
|
constructor(params, instance) {
|
|
4244
4262
|
this.params = params;
|
|
@@ -4258,6 +4276,9 @@ var ScallopQuery = class {
|
|
|
4258
4276
|
query: this
|
|
4259
4277
|
});
|
|
4260
4278
|
this.indexer = new ScallopIndexer(this.params, { cache: this.cache });
|
|
4279
|
+
this.walletAddress = normalizeSuiAddress2(
|
|
4280
|
+
params?.walletAddress || this.suiKit.currentAddress()
|
|
4281
|
+
);
|
|
4261
4282
|
}
|
|
4262
4283
|
/**
|
|
4263
4284
|
* Request the scallop API to initialize data.
|
|
@@ -4336,7 +4357,7 @@ var ScallopQuery = class {
|
|
|
4336
4357
|
* @param ownerAddress - The owner address.
|
|
4337
4358
|
* @return Obligations data.
|
|
4338
4359
|
*/
|
|
4339
|
-
async getObligations(ownerAddress) {
|
|
4360
|
+
async getObligations(ownerAddress = this.walletAddress) {
|
|
4340
4361
|
return await getObligations(this, ownerAddress);
|
|
4341
4362
|
}
|
|
4342
4363
|
/**
|
|
@@ -4355,7 +4376,7 @@ var ScallopQuery = class {
|
|
|
4355
4376
|
* @param ownerAddress - The owner address.
|
|
4356
4377
|
* @return All coin amounts.
|
|
4357
4378
|
*/
|
|
4358
|
-
async getCoinAmounts(assetCoinNames, ownerAddress) {
|
|
4379
|
+
async getCoinAmounts(assetCoinNames, ownerAddress = this.walletAddress) {
|
|
4359
4380
|
return await getCoinAmounts(this, assetCoinNames, ownerAddress);
|
|
4360
4381
|
}
|
|
4361
4382
|
/**
|
|
@@ -4365,7 +4386,7 @@ var ScallopQuery = class {
|
|
|
4365
4386
|
* @param ownerAddress - The owner address.
|
|
4366
4387
|
* @return Coin amount.
|
|
4367
4388
|
*/
|
|
4368
|
-
async getCoinAmount(assetCoinName, ownerAddress) {
|
|
4389
|
+
async getCoinAmount(assetCoinName, ownerAddress = this.walletAddress) {
|
|
4369
4390
|
return await getCoinAmount(this, assetCoinName, ownerAddress);
|
|
4370
4391
|
}
|
|
4371
4392
|
/**
|
|
@@ -4375,7 +4396,7 @@ var ScallopQuery = class {
|
|
|
4375
4396
|
* @param ownerAddress - The owner address.
|
|
4376
4397
|
* @return All market market coin amounts.
|
|
4377
4398
|
*/
|
|
4378
|
-
async getMarketCoinAmounts(marketCoinNames, ownerAddress) {
|
|
4399
|
+
async getMarketCoinAmounts(marketCoinNames, ownerAddress = this.walletAddress) {
|
|
4379
4400
|
return await getMarketCoinAmounts(this, marketCoinNames, ownerAddress);
|
|
4380
4401
|
}
|
|
4381
4402
|
/**
|
|
@@ -4385,7 +4406,7 @@ var ScallopQuery = class {
|
|
|
4385
4406
|
* @param ownerAddress - The owner address.
|
|
4386
4407
|
* @return Market market coin amount.
|
|
4387
4408
|
*/
|
|
4388
|
-
async getMarketCoinAmount(marketCoinName, ownerAddress) {
|
|
4409
|
+
async getMarketCoinAmount(marketCoinName, ownerAddress = this.walletAddress) {
|
|
4389
4410
|
return await getMarketCoinAmount(this, marketCoinName, ownerAddress);
|
|
4390
4411
|
}
|
|
4391
4412
|
/**
|
|
@@ -4433,7 +4454,7 @@ var ScallopQuery = class {
|
|
|
4433
4454
|
* @param ownerAddress - The owner address.
|
|
4434
4455
|
* @return All Stake accounts data.
|
|
4435
4456
|
*/
|
|
4436
|
-
async getAllStakeAccounts(ownerAddress) {
|
|
4457
|
+
async getAllStakeAccounts(ownerAddress = this.walletAddress) {
|
|
4437
4458
|
return await getStakeAccounts(this, ownerAddress);
|
|
4438
4459
|
}
|
|
4439
4460
|
/**
|
|
@@ -4443,7 +4464,7 @@ var ScallopQuery = class {
|
|
|
4443
4464
|
* @param ownerAddress - The owner address.
|
|
4444
4465
|
* @return Stake accounts data.
|
|
4445
4466
|
*/
|
|
4446
|
-
async getStakeAccounts(stakeMarketCoinName, ownerAddress) {
|
|
4467
|
+
async getStakeAccounts(stakeMarketCoinName, ownerAddress = this.walletAddress) {
|
|
4447
4468
|
const allStakeAccount = await this.getAllStakeAccounts(ownerAddress);
|
|
4448
4469
|
return allStakeAccount[stakeMarketCoinName] ?? [];
|
|
4449
4470
|
}
|
|
@@ -4548,7 +4569,7 @@ var ScallopQuery = class {
|
|
|
4548
4569
|
* @param indexer - Whether to use indexer.
|
|
4549
4570
|
* @return All lending and spool infomation.
|
|
4550
4571
|
*/
|
|
4551
|
-
async getLendings(poolCoinNames, ownerAddress, indexer = false) {
|
|
4572
|
+
async getLendings(poolCoinNames, ownerAddress = this.walletAddress, indexer = false) {
|
|
4552
4573
|
return await getLendings(this, poolCoinNames, ownerAddress, indexer);
|
|
4553
4574
|
}
|
|
4554
4575
|
/**
|
|
@@ -4559,7 +4580,7 @@ var ScallopQuery = class {
|
|
|
4559
4580
|
* @param indexer - Whether to use indexer.
|
|
4560
4581
|
* @return Lending pool data.
|
|
4561
4582
|
*/
|
|
4562
|
-
async getLending(poolCoinName, ownerAddress, indexer = false) {
|
|
4583
|
+
async getLending(poolCoinName, ownerAddress = this.walletAddress, indexer = false) {
|
|
4563
4584
|
return await getLending(this, poolCoinName, ownerAddress, indexer);
|
|
4564
4585
|
}
|
|
4565
4586
|
/**
|
|
@@ -4572,7 +4593,7 @@ var ScallopQuery = class {
|
|
|
4572
4593
|
* @param indexer - Whether to use indexer.
|
|
4573
4594
|
* @return All obligation accounts information.
|
|
4574
4595
|
*/
|
|
4575
|
-
async getObligationAccounts(ownerAddress, indexer = false) {
|
|
4596
|
+
async getObligationAccounts(ownerAddress = this.walletAddress, indexer = false) {
|
|
4576
4597
|
return await getObligationAccounts(this, ownerAddress, indexer);
|
|
4577
4598
|
}
|
|
4578
4599
|
/**
|
|
@@ -4586,7 +4607,7 @@ var ScallopQuery = class {
|
|
|
4586
4607
|
* @param indexer - Whether to use indexer.
|
|
4587
4608
|
* @return Borrowing and collateral information.
|
|
4588
4609
|
*/
|
|
4589
|
-
async getObligationAccount(obligationId, ownerAddress, indexer = false) {
|
|
4610
|
+
async getObligationAccount(obligationId, ownerAddress = this.walletAddress, indexer = false) {
|
|
4590
4611
|
return await getObligationAccount(
|
|
4591
4612
|
this,
|
|
4592
4613
|
obligationId,
|
|
@@ -4668,7 +4689,7 @@ var ScallopQuery = class {
|
|
|
4668
4689
|
* @param ownerAddress - The owner address.
|
|
4669
4690
|
* @return All market sCoin amounts.
|
|
4670
4691
|
*/
|
|
4671
|
-
async getSCoinAmounts(sCoinNames, ownerAddress) {
|
|
4692
|
+
async getSCoinAmounts(sCoinNames, ownerAddress = this.walletAddress) {
|
|
4672
4693
|
return await getSCoinAmounts(this, sCoinNames, ownerAddress);
|
|
4673
4694
|
}
|
|
4674
4695
|
/**
|
|
@@ -4678,7 +4699,7 @@ var ScallopQuery = class {
|
|
|
4678
4699
|
* @param ownerAddress - The owner address.
|
|
4679
4700
|
* @return sCoin amount.
|
|
4680
4701
|
*/
|
|
4681
|
-
async getSCoinAmount(sCoinName, ownerAddress) {
|
|
4702
|
+
async getSCoinAmount(sCoinName, ownerAddress = this.walletAddress) {
|
|
4682
4703
|
const parsedSCoinName = this.utils.parseSCoinName(sCoinName);
|
|
4683
4704
|
return parsedSCoinName ? await getSCoinAmount(this, parsedSCoinName, ownerAddress) : 0;
|
|
4684
4705
|
}
|
|
@@ -5103,7 +5124,7 @@ var ScallopUtils = class {
|
|
|
5103
5124
|
};
|
|
5104
5125
|
|
|
5105
5126
|
// src/models/scallopBuilder.ts
|
|
5106
|
-
import { normalizeSuiAddress as
|
|
5127
|
+
import { normalizeSuiAddress as normalizeSuiAddress3 } from "@mysten/sui.js/utils";
|
|
5107
5128
|
import { SuiKit as SuiKit3 } from "@scallop-io/sui-kit";
|
|
5108
5129
|
|
|
5109
5130
|
// src/builders/coreBuilder.ts
|
|
@@ -6784,7 +6805,7 @@ var ScallopBuilder = class {
|
|
|
6784
6805
|
query: this.query,
|
|
6785
6806
|
cache: this.cache
|
|
6786
6807
|
});
|
|
6787
|
-
this.walletAddress =
|
|
6808
|
+
this.walletAddress = normalizeSuiAddress3(
|
|
6788
6809
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
6789
6810
|
);
|
|
6790
6811
|
this.isTestnet = params.networkType ? params.networkType === "testnet" : false;
|
|
@@ -6822,7 +6843,7 @@ var ScallopBuilder = class {
|
|
|
6822
6843
|
* @param sender - Sender address.
|
|
6823
6844
|
* @return Take coin and left coin.
|
|
6824
6845
|
*/
|
|
6825
|
-
async selectCoin(txBlock, assetCoinName, amount, sender) {
|
|
6846
|
+
async selectCoin(txBlock, assetCoinName, amount, sender = this.walletAddress) {
|
|
6826
6847
|
const coinType = this.utils.parseCoinType(assetCoinName);
|
|
6827
6848
|
const coins = await this.utils.selectCoins(amount, coinType, sender);
|
|
6828
6849
|
const [takeCoin, leftCoin] = txBlock.takeAmountFromCoins(coins, amount);
|
|
@@ -6837,7 +6858,7 @@ var ScallopBuilder = class {
|
|
|
6837
6858
|
* @param sender - Sender address.
|
|
6838
6859
|
* @return Take coin and left coin.
|
|
6839
6860
|
*/
|
|
6840
|
-
async selectMarketCoin(txBlock, marketCoinName, amount, sender) {
|
|
6861
|
+
async selectMarketCoin(txBlock, marketCoinName, amount, sender = this.walletAddress) {
|
|
6841
6862
|
const marketCoinType = this.utils.parseMarketCoinType(marketCoinName);
|
|
6842
6863
|
const coins = await this.utils.selectCoins(amount, marketCoinType, sender);
|
|
6843
6864
|
const totalAmount = coins.reduce((prev, coin) => {
|
|
@@ -6859,7 +6880,7 @@ var ScallopBuilder = class {
|
|
|
6859
6880
|
* @param sender - Sender address.
|
|
6860
6881
|
* @return Take coin and left coin.
|
|
6861
6882
|
*/
|
|
6862
|
-
async selectSCoin(txBlock, sCoinName, amount, sender) {
|
|
6883
|
+
async selectSCoin(txBlock, sCoinName, amount, sender = this.walletAddress) {
|
|
6863
6884
|
const sCoinType = this.utils.parseSCoinType(sCoinName);
|
|
6864
6885
|
const coins = await this.utils.selectCoins(amount, sCoinType, sender);
|
|
6865
6886
|
const totalAmount = coins.reduce((prev, coin) => {
|
|
@@ -6919,7 +6940,7 @@ var ScallopClient = class {
|
|
|
6919
6940
|
utils: this.utils,
|
|
6920
6941
|
cache: this.cache
|
|
6921
6942
|
});
|
|
6922
|
-
this.walletAddress =
|
|
6943
|
+
this.walletAddress = normalizeSuiAddress4(
|
|
6923
6944
|
params?.walletAddress || this.suiKit.currentAddress()
|
|
6924
6945
|
);
|
|
6925
6946
|
}
|
|
@@ -7266,12 +7287,12 @@ var ScallopClient = class {
|
|
|
7266
7287
|
const txBlock = this.builder.createTxBlock();
|
|
7267
7288
|
const sender = walletAddress || this.walletAddress;
|
|
7268
7289
|
txBlock.setSender(sender);
|
|
7269
|
-
const
|
|
7290
|
+
const sCoin = await txBlock.unstakeQuick(
|
|
7270
7291
|
amount,
|
|
7271
7292
|
stakeMarketCoinName,
|
|
7272
7293
|
stakeAccountId
|
|
7273
7294
|
);
|
|
7274
|
-
txBlock.transferObjects([
|
|
7295
|
+
txBlock.transferObjects([sCoin], sender);
|
|
7275
7296
|
if (sign) {
|
|
7276
7297
|
return await this.suiKit.signAndSendTxn(
|
|
7277
7298
|
txBlock
|
|
@@ -7287,12 +7308,15 @@ var ScallopClient = class {
|
|
|
7287
7308
|
const stakeMarketCoin = await txBlock.unstakeQuick(
|
|
7288
7309
|
amount,
|
|
7289
7310
|
stakeMarketCoinName,
|
|
7290
|
-
stakeAccountId
|
|
7311
|
+
stakeAccountId,
|
|
7312
|
+
false
|
|
7291
7313
|
);
|
|
7292
7314
|
const stakeCoinName = this.utils.parseCoinName(stakeMarketCoinName);
|
|
7293
7315
|
if (stakeMarketCoin) {
|
|
7294
7316
|
const coin = txBlock.withdraw(stakeMarketCoin, stakeCoinName);
|
|
7295
7317
|
txBlock.transferObjects([coin], sender);
|
|
7318
|
+
} else {
|
|
7319
|
+
throw new Error(`No stake found for ${stakeMarketCoinName}`);
|
|
7296
7320
|
}
|
|
7297
7321
|
if (sign) {
|
|
7298
7322
|
return await this.suiKit.signAndSendTxn(
|