@scallop-io/sui-scallop-sdk 0.44.27 → 0.44.28
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/builders/borrowIncentiveBuilder.d.ts +0 -7
- package/dist/index.js +90 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -37
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopQuery.d.ts +12 -0
- package/dist/queries/borrowIncentiveQuery.d.ts +8 -0
- package/dist/types/query/vesca.d.ts +2 -1
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +6 -55
- package/src/builders/vescaBuilder.ts +7 -3
- package/src/models/scallopQuery.ts +20 -0
- package/src/queries/borrowIncentiveQuery.ts +95 -0
- package/src/queries/vescaQuery.ts +18 -5
- package/src/types/query/vesca.ts +2 -1
package/dist/index.mjs
CHANGED
|
@@ -2442,6 +2442,63 @@ var queryBorrowIncentiveAccounts = async (query, obligationId, borrowIncentiveCo
|
|
|
2442
2442
|
}, {});
|
|
2443
2443
|
return borrowIncentiveAccounts;
|
|
2444
2444
|
};
|
|
2445
|
+
var getBindedObligationId = async (query, veScaKeyId) => {
|
|
2446
|
+
const borrowIncentiveObjectId = query.address.get("borrowIncentive.object");
|
|
2447
|
+
const incentivePoolsId = query.address.get("borrowIncentive.incentivePools");
|
|
2448
|
+
const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : query.address.get("vesca.id");
|
|
2449
|
+
const client = query.suiKit.client();
|
|
2450
|
+
const incentivePoolsResponse = await client.getObject({
|
|
2451
|
+
id: incentivePoolsId,
|
|
2452
|
+
options: {
|
|
2453
|
+
showContent: true
|
|
2454
|
+
}
|
|
2455
|
+
});
|
|
2456
|
+
if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
|
|
2457
|
+
return null;
|
|
2458
|
+
const incentivePoolFields = incentivePoolsResponse.data.content.fields;
|
|
2459
|
+
const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
|
|
2460
|
+
const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
|
|
2461
|
+
const veScaBindTableResponse = await client.getDynamicFieldObject({
|
|
2462
|
+
parentId: veScaBindTableId,
|
|
2463
|
+
name: {
|
|
2464
|
+
type: keyType,
|
|
2465
|
+
value: veScaKeyId
|
|
2466
|
+
}
|
|
2467
|
+
});
|
|
2468
|
+
if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
|
|
2469
|
+
return null;
|
|
2470
|
+
const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
|
|
2471
|
+
const obligationId = veScaBindTableFields.value.fields.id;
|
|
2472
|
+
return obligationId;
|
|
2473
|
+
};
|
|
2474
|
+
var getBindedVeScaKey = async (query, obliationId) => {
|
|
2475
|
+
const borrowIncentiveObjectId = query.address.get("borrowIncentive.object");
|
|
2476
|
+
const incentiveAccountsId = query.address.get(
|
|
2477
|
+
"borrowIncentive.incentiveAccounts"
|
|
2478
|
+
);
|
|
2479
|
+
const corePkg = query.address.get("core.object");
|
|
2480
|
+
const client = query.suiKit.client();
|
|
2481
|
+
const incentiveAccountsObject = await client.getObject({
|
|
2482
|
+
id: incentiveAccountsId,
|
|
2483
|
+
options: {
|
|
2484
|
+
showContent: true
|
|
2485
|
+
}
|
|
2486
|
+
});
|
|
2487
|
+
if (incentiveAccountsObject.data?.content?.dataType !== "moveObject")
|
|
2488
|
+
return null;
|
|
2489
|
+
const incentiveAccountsTableId = incentiveAccountsObject.data.content.fields.accounts.fields.id.id;
|
|
2490
|
+
const bindedIncentiveAcc = await client.getDynamicFieldObject({
|
|
2491
|
+
parentId: incentiveAccountsTableId,
|
|
2492
|
+
name: {
|
|
2493
|
+
type: `${borrowIncentiveObjectId}::typed_id::TypedID<${corePkg}::obligation::Obligation>`,
|
|
2494
|
+
value: obliationId
|
|
2495
|
+
}
|
|
2496
|
+
});
|
|
2497
|
+
if (bindedIncentiveAcc.data?.content?.dataType !== "moveObject")
|
|
2498
|
+
return null;
|
|
2499
|
+
const bindedIncentiveAccFields = bindedIncentiveAcc.data.content.fields;
|
|
2500
|
+
return bindedIncentiveAccFields.value.fields.binded_ve_sca_key?.fields.id ?? null;
|
|
2501
|
+
};
|
|
2445
2502
|
|
|
2446
2503
|
// src/queries/priceQuery.ts
|
|
2447
2504
|
var getPythPrice = async (query, assetCoinName) => {
|
|
@@ -3027,11 +3084,19 @@ var getVeSca = async (query, veScaKeyId, ownerAddress) => {
|
|
|
3027
3084
|
const veScaDynamicFieldObject = veScaDynamicFieldObjectResponse.data;
|
|
3028
3085
|
if (veScaDynamicFieldObject && veScaDynamicFieldObject.content && veScaDynamicFieldObject.content.dataType === "moveObject" && "fields" in veScaDynamicFieldObject.content) {
|
|
3029
3086
|
const dynamicFields = veScaDynamicFieldObject.content.fields.value.fields;
|
|
3087
|
+
const remainingLockPeriodInMilliseconds = Math.max(
|
|
3088
|
+
+dynamicFields.unlock_at * 1e3 - Date.now(),
|
|
3089
|
+
0
|
|
3090
|
+
);
|
|
3091
|
+
const lockedScaAmount = String(dynamicFields.locked_sca_amount);
|
|
3092
|
+
const lockedScaCoin = BigNumber4(dynamicFields.locked_sca_amount).shiftedBy(-9).toNumber();
|
|
3093
|
+
const currentVeScaBalance = lockedScaCoin * (Math.floor(remainingLockPeriodInMilliseconds / 1e3) / MAX_LOCK_DURATION);
|
|
3030
3094
|
vesca = {
|
|
3031
3095
|
id: veScaDynamicFieldObject.objectId,
|
|
3032
3096
|
keyId: veScaKeyId,
|
|
3033
|
-
lockedScaAmount
|
|
3034
|
-
lockedScaCoin
|
|
3097
|
+
lockedScaAmount,
|
|
3098
|
+
lockedScaCoin,
|
|
3099
|
+
currentVeScaBalance,
|
|
3035
3100
|
unlockAt: BigNumber4(dynamicFields.unlock_at).toNumber()
|
|
3036
3101
|
};
|
|
3037
3102
|
}
|
|
@@ -3567,6 +3632,22 @@ var ScallopQuery = class {
|
|
|
3567
3632
|
async getTvl(indexer = false) {
|
|
3568
3633
|
return await getTotalValueLocked(this, indexer);
|
|
3569
3634
|
}
|
|
3635
|
+
/**
|
|
3636
|
+
* Get binded obligationId from a veScaKey if it exists.
|
|
3637
|
+
* @param veScaKey
|
|
3638
|
+
* @returns obligationId
|
|
3639
|
+
*/
|
|
3640
|
+
async getBindedObligationId(veScaKey) {
|
|
3641
|
+
return await getBindedObligationId(this, veScaKey);
|
|
3642
|
+
}
|
|
3643
|
+
/**
|
|
3644
|
+
* Get binded veSCA key from a obligationId if it exists.
|
|
3645
|
+
* @param obligationId
|
|
3646
|
+
* @returns veScaKey
|
|
3647
|
+
*/
|
|
3648
|
+
async getBindedVeScaKey(obligationId) {
|
|
3649
|
+
return await getBindedVeScaKey(this, obligationId);
|
|
3650
|
+
}
|
|
3570
3651
|
};
|
|
3571
3652
|
|
|
3572
3653
|
// src/constants/pyth.ts
|
|
@@ -4596,7 +4677,10 @@ var requireVeSca = async (...params) => {
|
|
|
4596
4677
|
if (veScas.length === 0) {
|
|
4597
4678
|
return void 0;
|
|
4598
4679
|
}
|
|
4599
|
-
return veScas
|
|
4680
|
+
return veScas.reduce(
|
|
4681
|
+
(prev, acc) => acc.currentVeScaBalance > prev.currentVeScaBalance ? acc : prev,
|
|
4682
|
+
veScas[0]
|
|
4683
|
+
);
|
|
4600
4684
|
};
|
|
4601
4685
|
var generateNormalVeScaMethod = ({
|
|
4602
4686
|
builder,
|
|
@@ -4730,7 +4814,7 @@ var generateQuickVeScaMethod = ({
|
|
|
4730
4814
|
const veScaKey = txBlock.lockSca(scaCoin, newUnlockAt);
|
|
4731
4815
|
transferObjects.push(veScaKey);
|
|
4732
4816
|
} else {
|
|
4733
|
-
if (veSca.
|
|
4817
|
+
if (veSca.lockedScaCoin !== 0) {
|
|
4734
4818
|
const unlockedSca = txBlock.redeemSca(veSca.keyId);
|
|
4735
4819
|
transferObjects.push(unlockedSca);
|
|
4736
4820
|
}
|
|
@@ -4790,7 +4874,7 @@ var generateQuickVeScaMethod = ({
|
|
|
4790
4874
|
checkRenewExpiredVeSca(scaAmount, lockPeriodInDays, veSca?.unlockAt);
|
|
4791
4875
|
if (veSca) {
|
|
4792
4876
|
const transferObjects = [];
|
|
4793
|
-
if (veSca.
|
|
4877
|
+
if (veSca.lockedScaCoin !== 0) {
|
|
4794
4878
|
const unlockedSca = txBlock.redeemSca(veSca.keyId);
|
|
4795
4879
|
transferObjects.push(unlockedSca);
|
|
4796
4880
|
}
|
|
@@ -4871,37 +4955,6 @@ var requireObligationInfo2 = async (...params) => {
|
|
|
4871
4955
|
obligationLocked: selectedObligation.locked
|
|
4872
4956
|
};
|
|
4873
4957
|
};
|
|
4874
|
-
var getBindedObligationId = async (builder, veScaKey) => {
|
|
4875
|
-
const borrowIncentiveObjectId = builder.address.get("borrowIncentive.object");
|
|
4876
|
-
const incentivePoolsId = builder.address.get(
|
|
4877
|
-
"borrowIncentive.incentivePools"
|
|
4878
|
-
);
|
|
4879
|
-
const veScaPkgId = IS_VE_SCA_TEST ? "0xb220d034bdf335d77ae5bfbf6daf059c2cc7a1f719b12bfed75d1736fac038c8" : builder.address.get("vesca.id");
|
|
4880
|
-
const client = builder.suiKit.client();
|
|
4881
|
-
const incentivePoolsResponse = await client.getObject({
|
|
4882
|
-
id: incentivePoolsId,
|
|
4883
|
-
options: {
|
|
4884
|
-
showContent: true
|
|
4885
|
-
}
|
|
4886
|
-
});
|
|
4887
|
-
if (incentivePoolsResponse.data?.content?.dataType !== "moveObject")
|
|
4888
|
-
return false;
|
|
4889
|
-
const incentivePoolFields = incentivePoolsResponse.data.content.fields;
|
|
4890
|
-
const veScaBindTableId = incentivePoolFields.ve_sca_bind.fields.id.id;
|
|
4891
|
-
const keyType = `${borrowIncentiveObjectId}::typed_id::TypedID<${veScaPkgId}::ve_sca::VeScaKey>`;
|
|
4892
|
-
const veScaBindTableResponse = await client.getDynamicFieldObject({
|
|
4893
|
-
parentId: veScaBindTableId,
|
|
4894
|
-
name: {
|
|
4895
|
-
type: keyType,
|
|
4896
|
-
value: veScaKey
|
|
4897
|
-
}
|
|
4898
|
-
});
|
|
4899
|
-
if (veScaBindTableResponse.data?.content?.dataType !== "moveObject")
|
|
4900
|
-
return false;
|
|
4901
|
-
const veScaBindTableFields = veScaBindTableResponse.data.content.fields;
|
|
4902
|
-
const obligationId = veScaBindTableFields.value.fields.id;
|
|
4903
|
-
return obligationId;
|
|
4904
|
-
};
|
|
4905
4958
|
var generateBorrowIncentiveNormalMethod = ({ builder, txBlock }) => {
|
|
4906
4959
|
const borrowIncentiveIds = {
|
|
4907
4960
|
borrowIncentivePkg: IS_VE_SCA_TEST ? "0x4d5a7cefa4147b4ace0ca845b20437d6ac0d32e5f2f855171f745472c2576246" : builder.address.get("borrowIncentive.id"),
|
|
@@ -5041,7 +5094,7 @@ var generateBorrowIncentiveQuickMethod = ({ builder, txBlock }) => {
|
|
|
5041
5094
|
const veSca = await requireVeSca(builder, txBlock, veScaKey);
|
|
5042
5095
|
if (veSca) {
|
|
5043
5096
|
const bindedObligationId = await getBindedObligationId(
|
|
5044
|
-
builder,
|
|
5097
|
+
builder.query,
|
|
5045
5098
|
veSca.keyId
|
|
5046
5099
|
);
|
|
5047
5100
|
if (!bindedObligationId || bindedObligationId === obligationArg) {
|