@scallop-io/sui-scallop-sdk 2.2.2-pyth-sponsored-transaction-alpha.1 → 2.2.2
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.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +10 -5
- package/src/builders/coreBuilder.ts +4 -13
- package/src/builders/oracles/index.ts +14 -17
- package/src/builders/oracles/pyth.ts +4 -12
- package/src/types/builder/core.ts +2 -4
package/package.json
CHANGED
|
@@ -55,11 +55,16 @@ const requireObligationInfo = async (
|
|
|
55
55
|
throw new Error(`No obligation found for sender ${sender}`);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const selectedObligation =
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
const selectedObligation = obligations.find(
|
|
59
|
+
(obligation) =>
|
|
60
|
+
obligation.id === obligationId || obligation.keyId === obligationKey
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
if (!selectedObligation) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`No obligation found for sender ${sender} with id ${obligationId} or key ${obligationKey}`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
63
68
|
|
|
64
69
|
return {
|
|
65
70
|
obligationId: selectedObligation.id,
|
|
@@ -382,13 +382,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
382
382
|
if (!marketCoin) throw new Error(`No market coin for ${poolCoinName}`);
|
|
383
383
|
return txBlock.withdraw(marketCoin, poolCoinName);
|
|
384
384
|
},
|
|
385
|
-
borrowQuick: async (
|
|
386
|
-
amount,
|
|
387
|
-
poolCoinName,
|
|
388
|
-
obligationId,
|
|
389
|
-
obligationKey,
|
|
390
|
-
isSponsoredTx = false
|
|
391
|
-
) => {
|
|
385
|
+
borrowQuick: async (amount, poolCoinName, obligationId, obligationKey) => {
|
|
392
386
|
const obligationInfo = await requireObligationInfo(
|
|
393
387
|
builder,
|
|
394
388
|
txBlock,
|
|
@@ -400,7 +394,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
400
394
|
obligationInfo.obligationId
|
|
401
395
|
)) ?? [];
|
|
402
396
|
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
403
|
-
await updateOracles(builder, txBlock, updateCoinNames
|
|
397
|
+
await updateOracles(builder, txBlock, updateCoinNames);
|
|
404
398
|
return txBlock.borrow(
|
|
405
399
|
obligationInfo.obligationId,
|
|
406
400
|
obligationInfo.obligationKey as SuiObjectArg,
|
|
@@ -413,8 +407,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
413
407
|
poolCoinName,
|
|
414
408
|
borrowReferral,
|
|
415
409
|
obligationId,
|
|
416
|
-
obligationKey
|
|
417
|
-
isSponsoredTx = false
|
|
410
|
+
obligationKey
|
|
418
411
|
) => {
|
|
419
412
|
const obligationInfo = await requireObligationInfo(
|
|
420
413
|
builder,
|
|
@@ -427,9 +420,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
427
420
|
obligationInfo.obligationId
|
|
428
421
|
)) ?? [];
|
|
429
422
|
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
430
|
-
await updateOracles(builder, txBlock, updateCoinNames
|
|
431
|
-
isSponsoredTx,
|
|
432
|
-
});
|
|
423
|
+
await updateOracles(builder, txBlock, updateCoinNames);
|
|
433
424
|
return txBlock.borrowWithReferral(
|
|
434
425
|
obligationInfo.obligationId,
|
|
435
426
|
obligationInfo.obligationKey as SuiObjectArg,
|
|
@@ -22,21 +22,19 @@ export const updateOracles = async (
|
|
|
22
22
|
builder: ScallopBuilder,
|
|
23
23
|
txBlock: SuiKitTxBlock,
|
|
24
24
|
assetCoinNames: string[] = [...builder.constants.whitelist.lending],
|
|
25
|
-
options
|
|
26
|
-
usePythPullModel
|
|
27
|
-
useOnChainXOracleList
|
|
28
|
-
sponsoredFeeds
|
|
29
|
-
|
|
25
|
+
options: {
|
|
26
|
+
usePythPullModel: boolean;
|
|
27
|
+
useOnChainXOracleList: boolean;
|
|
28
|
+
sponsoredFeeds: string[];
|
|
29
|
+
} = {
|
|
30
|
+
usePythPullModel: true,
|
|
31
|
+
useOnChainXOracleList: true,
|
|
32
|
+
sponsoredFeeds: [],
|
|
30
33
|
}
|
|
31
34
|
) => {
|
|
32
|
-
const usePythPullModel =
|
|
33
|
-
options?.usePythPullModel ?? builder.usePythPullModel;
|
|
34
|
-
const useOnChainXOracleList =
|
|
35
|
-
options?.useOnChainXOracleList ?? builder.useOnChainXOracleList;
|
|
36
35
|
const sponsoredFeeds = new Set(
|
|
37
|
-
|
|
36
|
+
builder.sponsoredFeeds ?? options.sponsoredFeeds
|
|
38
37
|
);
|
|
39
|
-
const isSponsoredTx = options?.isSponsoredTx ?? false;
|
|
40
38
|
|
|
41
39
|
// Validate the sponsoredFeeds content.
|
|
42
40
|
sponsoredFeeds.forEach((feed) => {
|
|
@@ -45,6 +43,10 @@ export const updateOracles = async (
|
|
|
45
43
|
}
|
|
46
44
|
});
|
|
47
45
|
|
|
46
|
+
const usePythPullModel = builder.usePythPullModel ?? options.usePythPullModel;
|
|
47
|
+
const useOnChainXOracleList =
|
|
48
|
+
builder.useOnChainXOracleList ?? options.useOnChainXOracleList;
|
|
49
|
+
|
|
48
50
|
const xOracleList = useOnChainXOracleList
|
|
49
51
|
? await builder.query.getAssetOracles()
|
|
50
52
|
: X_ORACLE_LIST;
|
|
@@ -90,12 +92,7 @@ export const updateOracles = async (
|
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
if (needToUpdatePythPriceFeeds.length > 0) {
|
|
93
|
-
await updatePythPriceFeeds(
|
|
94
|
-
builder,
|
|
95
|
-
needToUpdatePythPriceFeeds,
|
|
96
|
-
txBlock,
|
|
97
|
-
isSponsoredTx
|
|
98
|
-
);
|
|
95
|
+
await updatePythPriceFeeds(builder, needToUpdatePythPriceFeeds, txBlock);
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
98
|
|
|
@@ -8,19 +8,12 @@ import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
|
8
8
|
export const updatePythPriceFeeds = async (
|
|
9
9
|
builder: ScallopBuilder,
|
|
10
10
|
assetCoinNames: string[],
|
|
11
|
-
txBlock: SuiKitTxBlock
|
|
12
|
-
isSponsoredTx: boolean = false
|
|
11
|
+
txBlock: SuiKitTxBlock
|
|
13
12
|
) => {
|
|
14
13
|
const pythClient = new SuiPythClient(
|
|
15
14
|
builder.suiKit.client,
|
|
16
15
|
builder.address.get('core.oracles.pyth.state'),
|
|
17
|
-
builder.address.get('core.oracles.pyth.wormholeState')
|
|
18
|
-
{
|
|
19
|
-
defaultPackageId:
|
|
20
|
-
'0xa6f9bec2f9748656b6af8aafb5d7bc1a0d5faf25ac9645fc7f447822cd509325',
|
|
21
|
-
gasStationId:
|
|
22
|
-
'0xa8b8dcc9880166edb57b53e05f8df7364d31b5d9b7d107fd27f0b69cf338b687',
|
|
23
|
-
}
|
|
16
|
+
builder.address.get('core.oracles.pyth.wormholeState')
|
|
24
17
|
);
|
|
25
18
|
const priceIds = assetCoinNames.map((assetCoinName) =>
|
|
26
19
|
builder.address.get(`core.coins.${assetCoinName}.oracle.pyth.feed`)
|
|
@@ -36,10 +29,9 @@ export const updatePythPriceFeeds = async (
|
|
|
36
29
|
const priceUpdateData =
|
|
37
30
|
await pythConnection.getPriceFeedsUpdateData(priceIds);
|
|
38
31
|
await pythClient.updatePriceFeeds(
|
|
39
|
-
txBlock.txBlock,
|
|
32
|
+
txBlock.txBlock, // convert txBlock to TransactionBlock because pyth sdk not support new @mysten/sui yet
|
|
40
33
|
priceUpdateData,
|
|
41
|
-
priceIds
|
|
42
|
-
isSponsoredTx
|
|
34
|
+
priceIds
|
|
43
35
|
);
|
|
44
36
|
|
|
45
37
|
break;
|
|
@@ -99,16 +99,14 @@ export type CoreQuickMethods = {
|
|
|
99
99
|
amount: number,
|
|
100
100
|
poolCoinName: string,
|
|
101
101
|
obligationId?: SuiObjectArg,
|
|
102
|
-
obligationKey?: SuiObjectArg
|
|
103
|
-
isSponsoredTx?: boolean
|
|
102
|
+
obligationKey?: SuiObjectArg
|
|
104
103
|
) => Promise<TransactionResult>;
|
|
105
104
|
borrowWithReferralQuick: (
|
|
106
105
|
amount: number,
|
|
107
106
|
poolCoinName: string,
|
|
108
107
|
borrowReferral: SuiObjectArg,
|
|
109
108
|
obligationId?: SuiObjectArg,
|
|
110
|
-
obligationKey?: SuiObjectArg
|
|
111
|
-
isSponsoredTx?: boolean
|
|
109
|
+
obligationKey?: SuiObjectArg
|
|
112
110
|
) => Promise<TransactionResult>;
|
|
113
111
|
depositQuick: (
|
|
114
112
|
amount: number,
|