@scallop-io/sui-scallop-sdk 1.4.23 → 1.5.0-alpha.1
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/index.d.ts +1 -0
- package/dist/constants/xoracle.d.ts +2 -0
- package/dist/index.js +564 -619
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +574 -630
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopIndexer.d.ts +1 -0
- package/dist/models/scallopPrice.d.ts +0 -0
- package/dist/models/scallopQuery.d.ts +25 -3
- package/dist/queries/coreQuery.d.ts +1 -1
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/poolAddressesQuery.d.ts +2 -2
- package/dist/queries/priceQuery.d.ts +1 -1
- package/dist/queries/xOracleQuery.d.ts +13 -0
- package/dist/types/address.d.ts +1 -0
- package/dist/types/constant/index.d.ts +1 -0
- package/dist/types/constant/xOracle.d.ts +9 -0
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +11 -25
- package/src/builders/coreBuilder.ts +15 -72
- package/src/builders/oracle.ts +73 -46
- package/src/builders/referralBuilder.ts +9 -20
- package/src/builders/spoolBuilder.ts +10 -38
- package/src/builders/vescaBuilder.ts +11 -26
- package/src/constants/enum.ts +10 -5
- package/src/constants/index.ts +1 -0
- package/src/constants/poolAddress.ts +343 -184
- package/src/constants/testAddress.ts +35 -252
- package/src/constants/xoracle.ts +25 -0
- package/src/models/scallopIndexer.ts +11 -0
- package/src/models/scallopPrice.ts +0 -0
- package/src/models/scallopQuery.ts +58 -11
- package/src/models/scallopUtils.ts +1 -1
- package/src/queries/coreQuery.ts +16 -6
- package/src/queries/index.ts +1 -0
- package/src/queries/poolAddressesQuery.ts +5 -2
- package/src/queries/priceQuery.ts +10 -3
- package/src/queries/vescaQuery.ts +8 -17
- package/src/queries/xOracleQuery.ts +124 -0
- package/src/types/address.ts +1 -0
- package/src/types/constant/index.ts +1 -0
- package/src/types/constant/xOracle.ts +11 -0
- package/src/utils/util.ts +1 -1
|
File without changes
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SuiKit, SuiObjectArg } from '@scallop-io/sui-kit';
|
|
2
|
-
import { ScallopQueryParams, SupportStakeMarketCoins, SupportAssetCoins, SupportPoolCoins, SupportCollateralCoins, SupportMarketCoins, SupportBorrowIncentiveCoins, SupportSCoin, ScallopQueryInstanceParams, MarketPool, CoinPrices, MarketPools, MarketCollaterals } from '../types';
|
|
2
|
+
import { ScallopQueryParams, SupportStakeMarketCoins, SupportAssetCoins, SupportPoolCoins, SupportCollateralCoins, SupportMarketCoins, SupportBorrowIncentiveCoins, SupportSCoin, ScallopQueryInstanceParams, MarketPool, CoinPrices, MarketPools, MarketCollaterals, xOracleRules } from '../types';
|
|
3
3
|
import { ScallopAddress } from './scallopAddress';
|
|
4
4
|
import { ScallopUtils } from './scallopUtils';
|
|
5
5
|
import { ScallopIndexer } from './scallopIndexer';
|
|
@@ -128,7 +128,10 @@ export declare class ScallopQuery {
|
|
|
128
128
|
* @param obligationId - The obligation id.
|
|
129
129
|
* @return Obligation data.
|
|
130
130
|
*/
|
|
131
|
-
queryObligation(obligationId:
|
|
131
|
+
queryObligation(obligationId: SuiObjectArg, args?: {
|
|
132
|
+
version: SuiObjectArg;
|
|
133
|
+
market: SuiObjectArg;
|
|
134
|
+
}): Promise<import("../types").ObligationQueryInterface | undefined>;
|
|
132
135
|
/**
|
|
133
136
|
* Get all asset coin amounts.
|
|
134
137
|
*
|
|
@@ -536,6 +539,11 @@ export declare class ScallopQuery {
|
|
|
536
539
|
* @returns price data
|
|
537
540
|
*/
|
|
538
541
|
getCoinPriceByIndexer(poolName: SupportPoolCoins): Promise<number>;
|
|
542
|
+
/**
|
|
543
|
+
* Get all supported pool price from indexer
|
|
544
|
+
* @returns prices data
|
|
545
|
+
*/
|
|
546
|
+
getCoinPricesByIndexer(): Promise<Record<string, number>>;
|
|
539
547
|
/**
|
|
540
548
|
* Get all coin prices, including sCoin
|
|
541
549
|
* @returns prices data
|
|
@@ -543,6 +551,7 @@ export declare class ScallopQuery {
|
|
|
543
551
|
getAllCoinPrices(args?: {
|
|
544
552
|
marketPools?: MarketPools;
|
|
545
553
|
coinPrices?: CoinPrices;
|
|
554
|
+
indexer?: boolean;
|
|
546
555
|
}): Promise<{
|
|
547
556
|
susdc?: number | undefined;
|
|
548
557
|
ssbeth?: number | undefined;
|
|
@@ -589,7 +598,7 @@ export declare class ScallopQuery {
|
|
|
589
598
|
* Query all address (lending pool, collateral pool, borrow dynamics, interest models, etc.) of all pool
|
|
590
599
|
* @returns
|
|
591
600
|
*/
|
|
592
|
-
getPoolAddresses(): Promise<import("../types").OptionalKeys<Record<"usdc" | "sbeth" | "sbusdt" | "sbwbtc" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd" | "blub", {
|
|
601
|
+
getPoolAddresses(poolNames?: SupportPoolCoins[]): Promise<import("../types").OptionalKeys<Record<"usdc" | "sbeth" | "sbusdt" | "sbwbtc" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd" | "blub", {
|
|
593
602
|
coinName: string;
|
|
594
603
|
symbol: string;
|
|
595
604
|
lendingPoolAddress?: string;
|
|
@@ -679,4 +688,17 @@ export declare class ScallopQuery {
|
|
|
679
688
|
totalCollateralValue: number;
|
|
680
689
|
totalSupplyValue: number;
|
|
681
690
|
}>;
|
|
691
|
+
/**
|
|
692
|
+
* Get both primary and secondary price update policy objects
|
|
693
|
+
* @returns price update policies
|
|
694
|
+
*/
|
|
695
|
+
getPriceUpdatePolicies(): Promise<{
|
|
696
|
+
primary: import("@mysten/sui/client").SuiObjectResponse | null;
|
|
697
|
+
secondary: import("@mysten/sui/client").SuiObjectResponse | null;
|
|
698
|
+
}>;
|
|
699
|
+
/**
|
|
700
|
+
* Return the supported primary and secondary oracles for all supported pool assets
|
|
701
|
+
* @returns
|
|
702
|
+
*/
|
|
703
|
+
getAssetOracles(): Promise<Record<SupportAssetCoins, xOracleRules>>;
|
|
682
704
|
}
|
|
@@ -125,7 +125,7 @@ export declare const getObligationLocked: (cache: ScallopCache, obligation: stri
|
|
|
125
125
|
*/
|
|
126
126
|
export declare const queryObligation: ({ address, }: {
|
|
127
127
|
address: ScallopAddress;
|
|
128
|
-
}, obligationId: SuiObjectArg) => Promise<ObligationQueryInterface | undefined>;
|
|
128
|
+
}, obligationId: SuiObjectArg, version?: SuiObjectArg, market?: SuiObjectArg) => Promise<ObligationQueryInterface | undefined>;
|
|
129
129
|
/**
|
|
130
130
|
* Query all owned coin amount.
|
|
131
131
|
*
|
package/dist/queries/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ScallopQuery } from 'src/models';
|
|
2
|
-
import { OptionalKeys } from 'src/types';
|
|
3
|
-
export declare const getAllAddresses: (query: ScallopQuery) => Promise<OptionalKeys<Record<"usdc" | "sbeth" | "sbusdt" | "sbwbtc" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd" | "blub", {
|
|
2
|
+
import { OptionalKeys, SupportPoolCoins } from 'src/types';
|
|
3
|
+
export declare const getAllAddresses: (query: ScallopQuery, pools?: SupportPoolCoins[]) => Promise<OptionalKeys<Record<"usdc" | "sbeth" | "sbusdt" | "sbwbtc" | "weth" | "wbtc" | "wusdc" | "wusdt" | "sui" | "wapt" | "wsol" | "cetus" | "afsui" | "hasui" | "vsui" | "sca" | "fud" | "deep" | "fdusd" | "blub", {
|
|
4
4
|
coinName: string;
|
|
5
5
|
symbol: string;
|
|
6
6
|
lendingPoolAddress?: string;
|
|
@@ -14,7 +14,7 @@ export declare const getPythPrice: ({ address, }: {
|
|
|
14
14
|
export declare const getPythPrices: ({ address, }: {
|
|
15
15
|
address: ScallopAddress;
|
|
16
16
|
}, assetCoinNames: SupportAssetCoins[]) => Promise<Record<SupportAssetCoins, number>>;
|
|
17
|
-
export declare const getAllCoinPrices: (query: ScallopQuery, marketPools?: MarketPools, coinPrices?: CoinPrices) => Promise<{
|
|
17
|
+
export declare const getAllCoinPrices: (query: ScallopQuery, marketPools?: MarketPools, coinPrices?: CoinPrices, indexer?: boolean) => Promise<{
|
|
18
18
|
susdc?: number | undefined;
|
|
19
19
|
ssbeth?: number | undefined;
|
|
20
20
|
ssbusdt?: number | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SuiObjectResponse } from '@mysten/sui/client';
|
|
2
|
+
import { ScallopAddress, ScallopUtils } from 'src/models';
|
|
3
|
+
import { SupportAssetCoins, SupportOracleType, xOracleRuleType } from 'src/types';
|
|
4
|
+
/**
|
|
5
|
+
* Query the price update policy table ids. Usually the value for these table will be constant.
|
|
6
|
+
* @param query
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const getPriceUpdatePolicies: (address: ScallopAddress) => Promise<{
|
|
10
|
+
primary: SuiObjectResponse | null;
|
|
11
|
+
secondary: SuiObjectResponse | null;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const getAssetOracles: (utils: ScallopUtils, ruleType: xOracleRuleType) => Promise<Record<SupportAssetCoins, SupportOracleType[]>>;
|
package/dist/types/address.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { SupportAssetCoins, SupportOracleType } from './common';
|
|
2
|
+
export type xOracleRules = {
|
|
3
|
+
primary: SupportOracleType[];
|
|
4
|
+
secondary: SupportOracleType[];
|
|
5
|
+
};
|
|
6
|
+
export type xOracleRuleType = keyof xOracleRules;
|
|
7
|
+
export type xOracleListType = {
|
|
8
|
+
[key in SupportAssetCoins]: xOracleRules;
|
|
9
|
+
};
|
package/package.json
CHANGED
|
@@ -98,6 +98,12 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
98
98
|
config: builder.address.get('vesca.config'),
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
+
const clockObjectRef = txBlock.sharedObjectRef({
|
|
102
|
+
objectId: SUI_CLOCK_OBJECT_ID,
|
|
103
|
+
mutable: false,
|
|
104
|
+
initialSharedVersion: '1',
|
|
105
|
+
});
|
|
106
|
+
|
|
101
107
|
return {
|
|
102
108
|
stakeObligation: (obligationId, obligationKey) => {
|
|
103
109
|
builder.moveCall(
|
|
@@ -110,11 +116,7 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
110
116
|
obligationKey,
|
|
111
117
|
obligationId,
|
|
112
118
|
borrowIncentiveIds.obligationAccessStore,
|
|
113
|
-
|
|
114
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
115
|
-
mutable: false,
|
|
116
|
-
initialSharedVersion: '1',
|
|
117
|
-
}),
|
|
119
|
+
clockObjectRef,
|
|
118
120
|
]
|
|
119
121
|
);
|
|
120
122
|
},
|
|
@@ -133,11 +135,7 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
133
135
|
veScaIds.treasury,
|
|
134
136
|
veScaIds.table,
|
|
135
137
|
veScaKey,
|
|
136
|
-
|
|
137
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
138
|
-
mutable: false,
|
|
139
|
-
initialSharedVersion: '1',
|
|
140
|
-
}),
|
|
138
|
+
clockObjectRef,
|
|
141
139
|
],
|
|
142
140
|
[]
|
|
143
141
|
);
|
|
@@ -152,11 +150,7 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
152
150
|
borrowIncentiveIds.incentiveAccounts,
|
|
153
151
|
obligationKey,
|
|
154
152
|
obligationId,
|
|
155
|
-
|
|
156
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
157
|
-
mutable: false,
|
|
158
|
-
initialSharedVersion: '1',
|
|
159
|
-
}),
|
|
153
|
+
clockObjectRef,
|
|
160
154
|
]
|
|
161
155
|
);
|
|
162
156
|
},
|
|
@@ -171,11 +165,7 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
171
165
|
borrowIncentiveIds.incentiveAccounts,
|
|
172
166
|
obligationKey,
|
|
173
167
|
obligationId,
|
|
174
|
-
|
|
175
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
176
|
-
mutable: false,
|
|
177
|
-
initialSharedVersion: '1',
|
|
178
|
-
}),
|
|
168
|
+
clockObjectRef,
|
|
179
169
|
],
|
|
180
170
|
[rewardType]
|
|
181
171
|
);
|
|
@@ -190,11 +180,7 @@ const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
|
190
180
|
borrowIncentiveIds.incentiveAccounts,
|
|
191
181
|
obligation,
|
|
192
182
|
veScaKey,
|
|
193
|
-
|
|
194
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
195
|
-
mutable: false,
|
|
196
|
-
initialSharedVersion: '1',
|
|
197
|
-
}),
|
|
183
|
+
clockObjectRef,
|
|
198
184
|
]
|
|
199
185
|
);
|
|
200
186
|
},
|
|
@@ -75,6 +75,11 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
75
75
|
|
|
76
76
|
const referralPkgId = builder.address.get('referral.id');
|
|
77
77
|
const referralWitnessType = `${referralPkgId}::scallop_referral_program::REFERRAL_WITNESS`;
|
|
78
|
+
const clockObjectRef = txBlock.sharedObjectRef({
|
|
79
|
+
objectId: SUI_CLOCK_OBJECT_ID,
|
|
80
|
+
mutable: false,
|
|
81
|
+
initialSharedVersion: '1',
|
|
82
|
+
});
|
|
78
83
|
|
|
79
84
|
return {
|
|
80
85
|
openObligation: () => {
|
|
@@ -126,11 +131,7 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
126
131
|
coreIds.coinDecimalsRegistry,
|
|
127
132
|
txBlock.pure.u64(amount),
|
|
128
133
|
coreIds.xOracle,
|
|
129
|
-
|
|
130
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
131
|
-
mutable: false,
|
|
132
|
-
initialSharedVersion: '1',
|
|
133
|
-
}),
|
|
134
|
+
clockObjectRef,
|
|
134
135
|
],
|
|
135
136
|
[coinType]
|
|
136
137
|
);
|
|
@@ -141,16 +142,7 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
141
142
|
return builder.moveCall(
|
|
142
143
|
txBlock,
|
|
143
144
|
`${coreIds.protocolPkg}::mint::mint`,
|
|
144
|
-
[
|
|
145
|
-
coreIds.version,
|
|
146
|
-
coreIds.market,
|
|
147
|
-
coin,
|
|
148
|
-
txBlock.sharedObjectRef({
|
|
149
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
150
|
-
mutable: false,
|
|
151
|
-
initialSharedVersion: '1',
|
|
152
|
-
}),
|
|
153
|
-
],
|
|
145
|
+
[coreIds.version, coreIds.market, coin, clockObjectRef],
|
|
154
146
|
[coinType]
|
|
155
147
|
);
|
|
156
148
|
},
|
|
@@ -160,16 +152,7 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
160
152
|
return builder.moveCall(
|
|
161
153
|
txBlock,
|
|
162
154
|
`${coreIds.protocolPkg}::mint::mint_entry`,
|
|
163
|
-
[
|
|
164
|
-
coreIds.version,
|
|
165
|
-
coreIds.market,
|
|
166
|
-
coin,
|
|
167
|
-
txBlock.sharedObjectRef({
|
|
168
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
169
|
-
mutable: false,
|
|
170
|
-
initialSharedVersion: '1',
|
|
171
|
-
}),
|
|
172
|
-
],
|
|
155
|
+
[coreIds.version, coreIds.market, coin, clockObjectRef],
|
|
173
156
|
[coinType]
|
|
174
157
|
);
|
|
175
158
|
},
|
|
@@ -179,16 +162,7 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
179
162
|
return builder.moveCall(
|
|
180
163
|
txBlock,
|
|
181
164
|
`${coreIds.protocolPkg}::redeem::redeem`,
|
|
182
|
-
[
|
|
183
|
-
coreIds.version,
|
|
184
|
-
coreIds.market,
|
|
185
|
-
marketCoin,
|
|
186
|
-
txBlock.sharedObjectRef({
|
|
187
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
188
|
-
mutable: false,
|
|
189
|
-
initialSharedVersion: '1',
|
|
190
|
-
}),
|
|
191
|
-
],
|
|
165
|
+
[coreIds.version, coreIds.market, marketCoin, clockObjectRef],
|
|
192
166
|
[coinType]
|
|
193
167
|
);
|
|
194
168
|
},
|
|
@@ -198,16 +172,7 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
198
172
|
return builder.moveCall(
|
|
199
173
|
txBlock,
|
|
200
174
|
`${coreIds.protocolPkg}::redeem::redeem_entry`,
|
|
201
|
-
[
|
|
202
|
-
coreIds.version,
|
|
203
|
-
coreIds.market,
|
|
204
|
-
marketCoin,
|
|
205
|
-
txBlock.sharedObjectRef({
|
|
206
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
207
|
-
mutable: false,
|
|
208
|
-
initialSharedVersion: '1',
|
|
209
|
-
}),
|
|
210
|
-
],
|
|
175
|
+
[coreIds.version, coreIds.market, marketCoin, clockObjectRef],
|
|
211
176
|
[coinType]
|
|
212
177
|
);
|
|
213
178
|
},
|
|
@@ -225,11 +190,7 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
225
190
|
coreIds.coinDecimalsRegistry,
|
|
226
191
|
amount,
|
|
227
192
|
coreIds.xOracle,
|
|
228
|
-
|
|
229
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
230
|
-
mutable: false,
|
|
231
|
-
initialSharedVersion: '1',
|
|
232
|
-
}),
|
|
193
|
+
clockObjectRef,
|
|
233
194
|
],
|
|
234
195
|
[coinType]
|
|
235
196
|
);
|
|
@@ -255,11 +216,7 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
255
216
|
borrowReferral,
|
|
256
217
|
typeof amount === 'number' ? txBlock.pure.u64(amount) : amount,
|
|
257
218
|
coreIds.xOracle,
|
|
258
|
-
|
|
259
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
260
|
-
mutable: false,
|
|
261
|
-
initialSharedVersion: '1',
|
|
262
|
-
}),
|
|
219
|
+
clockObjectRef,
|
|
263
220
|
],
|
|
264
221
|
[coinType, referralWitnessType]
|
|
265
222
|
);
|
|
@@ -278,11 +235,7 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
278
235
|
coreIds.coinDecimalsRegistry,
|
|
279
236
|
txBlock.pure.u64(amount),
|
|
280
237
|
coreIds.xOracle,
|
|
281
|
-
|
|
282
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
283
|
-
mutable: false,
|
|
284
|
-
initialSharedVersion: '1',
|
|
285
|
-
}),
|
|
238
|
+
clockObjectRef,
|
|
286
239
|
],
|
|
287
240
|
[coinType]
|
|
288
241
|
);
|
|
@@ -292,17 +245,7 @@ const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
|
292
245
|
builder.moveCall(
|
|
293
246
|
txBlock,
|
|
294
247
|
`${coreIds.protocolPkg}::repay::repay`,
|
|
295
|
-
[
|
|
296
|
-
coreIds.version,
|
|
297
|
-
obligation,
|
|
298
|
-
coreIds.market,
|
|
299
|
-
coin,
|
|
300
|
-
txBlock.sharedObjectRef({
|
|
301
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
302
|
-
mutable: false,
|
|
303
|
-
initialSharedVersion: '1',
|
|
304
|
-
}),
|
|
305
|
-
],
|
|
248
|
+
[coreIds.version, obligation, coreIds.market, coin, clockObjectRef],
|
|
306
249
|
[coinType]
|
|
307
250
|
);
|
|
308
251
|
},
|
|
@@ -479,7 +422,7 @@ const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
|
479
422
|
)) ?? [];
|
|
480
423
|
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
481
424
|
await updateOracles(builder, txBlock, updateCoinNames);
|
|
482
|
-
return
|
|
425
|
+
return txBlock.borrow(
|
|
483
426
|
obligationInfo.obligationId,
|
|
484
427
|
obligationInfo.obligationKey as SuiObjectArg,
|
|
485
428
|
amount,
|
package/src/builders/oracle.ts
CHANGED
|
@@ -7,8 +7,14 @@ import { SUPPORT_COLLATERALS, SUPPORT_POOLS } from '../constants';
|
|
|
7
7
|
import type { TransactionArgument } from '@mysten/sui/transactions';
|
|
8
8
|
import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
9
9
|
import type { ScallopBuilder } from '../models';
|
|
10
|
-
import type {
|
|
10
|
+
import type {
|
|
11
|
+
SupportAssetCoins,
|
|
12
|
+
SupportOracleType,
|
|
13
|
+
xOracleRules,
|
|
14
|
+
xOracleRuleType,
|
|
15
|
+
} from '../types';
|
|
11
16
|
import { PYTH_ENDPOINTS } from 'src/constants/pyth';
|
|
17
|
+
import { xOracleList } from 'src/constants';
|
|
12
18
|
|
|
13
19
|
/**
|
|
14
20
|
* Update the price of the oracle for multiple coin.
|
|
@@ -21,18 +27,26 @@ import { PYTH_ENDPOINTS } from 'src/constants/pyth';
|
|
|
21
27
|
export const updateOracles = async (
|
|
22
28
|
builder: ScallopBuilder,
|
|
23
29
|
txBlock: SuiKitTxBlock,
|
|
24
|
-
assetCoinNames
|
|
30
|
+
assetCoinNames: SupportAssetCoins[] = [
|
|
31
|
+
...new Set([...SUPPORT_POOLS, ...SUPPORT_COLLATERALS]),
|
|
32
|
+
],
|
|
25
33
|
options: {
|
|
26
34
|
usePythPullModel: boolean;
|
|
27
35
|
} = { usePythPullModel: true }
|
|
28
36
|
) => {
|
|
29
37
|
const usePythPullModel =
|
|
30
38
|
builder.params.usePythPullModel ?? options.usePythPullModel;
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
// const rules: SupportOracleType[] = builder.isTestnet ? ['pyth'] : ['pyth'];
|
|
40
|
+
const flattenedRules: SupportOracleType[] = [
|
|
41
|
+
...new Set(
|
|
42
|
+
Object.values(xOracleList).flatMap(({ primary, secondary }) => [
|
|
43
|
+
...primary,
|
|
44
|
+
...secondary,
|
|
45
|
+
])
|
|
46
|
+
),
|
|
33
47
|
];
|
|
34
|
-
|
|
35
|
-
if (
|
|
48
|
+
|
|
49
|
+
if (flattenedRules.includes('pyth') && usePythPullModel) {
|
|
36
50
|
const pythClient = new SuiPythClient(
|
|
37
51
|
builder.suiKit.client(),
|
|
38
52
|
builder.address.get('core.oracles.pyth.state'),
|
|
@@ -69,7 +83,12 @@ export const updateOracles = async (
|
|
|
69
83
|
// Remove duplicate coin names.
|
|
70
84
|
const updateAssetCoinNames = [...new Set(assetCoinNames)];
|
|
71
85
|
for (const assetCoinName of updateAssetCoinNames) {
|
|
72
|
-
await updateOracle(
|
|
86
|
+
await updateOracle(
|
|
87
|
+
builder,
|
|
88
|
+
txBlock,
|
|
89
|
+
assetCoinName,
|
|
90
|
+
xOracleList[assetCoinName]
|
|
91
|
+
);
|
|
73
92
|
}
|
|
74
93
|
};
|
|
75
94
|
|
|
@@ -84,7 +103,7 @@ const updateOracle = async (
|
|
|
84
103
|
builder: ScallopBuilder,
|
|
85
104
|
txBlock: SuiKitTxBlock,
|
|
86
105
|
assetCoinName: SupportAssetCoins,
|
|
87
|
-
rules:
|
|
106
|
+
rules: xOracleRules
|
|
88
107
|
) => {
|
|
89
108
|
const coinType = builder.utils.parseCoinType(assetCoinName);
|
|
90
109
|
|
|
@@ -129,7 +148,7 @@ const updateOracle = async (
|
|
|
129
148
|
*/
|
|
130
149
|
const updatePrice = (
|
|
131
150
|
txBlock: SuiKitTxBlock,
|
|
132
|
-
rules:
|
|
151
|
+
rules: xOracleRules,
|
|
133
152
|
xOraclePackageId: string,
|
|
134
153
|
xOracleId: TransactionArgument | string,
|
|
135
154
|
pythPackageId: string,
|
|
@@ -150,37 +169,42 @@ const updatePrice = (
|
|
|
150
169
|
xOracleId,
|
|
151
170
|
coinType
|
|
152
171
|
);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
172
|
+
Object.entries(rules).forEach(([type, rule]: [any, SupportOracleType[]]) => {
|
|
173
|
+
if (rule.includes('pyth')) {
|
|
174
|
+
updatePythPrice(
|
|
175
|
+
type,
|
|
176
|
+
txBlock,
|
|
177
|
+
pythPackageId,
|
|
178
|
+
request,
|
|
179
|
+
pythStateId,
|
|
180
|
+
pythFeedObjectId,
|
|
181
|
+
pythRegistryId,
|
|
182
|
+
coinType
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
if (rule.includes('supra')) {
|
|
186
|
+
updateSupraPrice(
|
|
187
|
+
type,
|
|
188
|
+
txBlock,
|
|
189
|
+
supraPackageId,
|
|
190
|
+
request,
|
|
191
|
+
supraHolderId,
|
|
192
|
+
supraRegistryId,
|
|
193
|
+
coinType
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
if (rule.includes('switchboard')) {
|
|
197
|
+
updateSwitchboardPrice(
|
|
198
|
+
type,
|
|
199
|
+
txBlock,
|
|
200
|
+
switchboardPackageId,
|
|
201
|
+
request,
|
|
202
|
+
switchboardAggregatorId,
|
|
203
|
+
switchboardRegistryId,
|
|
204
|
+
coinType
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
184
208
|
|
|
185
209
|
confirmPriceUpdateRequest(
|
|
186
210
|
txBlock,
|
|
@@ -260,6 +284,7 @@ const confirmPriceUpdateRequest = (
|
|
|
260
284
|
* @return TxBlock created by SuiKit.
|
|
261
285
|
*/
|
|
262
286
|
const updateSupraPrice = (
|
|
287
|
+
type: xOracleRuleType,
|
|
263
288
|
txBlock: SuiKitTxBlock,
|
|
264
289
|
packageId: string,
|
|
265
290
|
request: TransactionArgument,
|
|
@@ -268,15 +293,15 @@ const updateSupraPrice = (
|
|
|
268
293
|
coinType: string
|
|
269
294
|
) => {
|
|
270
295
|
txBlock.moveCall(
|
|
271
|
-
`${packageId}::rule::
|
|
296
|
+
`${packageId}::rule::set_price_as_${type}`,
|
|
272
297
|
[
|
|
273
298
|
request,
|
|
274
299
|
holderId,
|
|
275
300
|
registryId,
|
|
276
301
|
txBlock.sharedObjectRef({
|
|
277
302
|
objectId: SUI_CLOCK_OBJECT_ID,
|
|
278
|
-
mutable: false,
|
|
279
303
|
initialSharedVersion: '1',
|
|
304
|
+
mutable: false,
|
|
280
305
|
}),
|
|
281
306
|
],
|
|
282
307
|
[coinType]
|
|
@@ -296,6 +321,7 @@ const updateSupraPrice = (
|
|
|
296
321
|
* @return TxBlock created by SuiKit.
|
|
297
322
|
*/
|
|
298
323
|
const updateSwitchboardPrice = (
|
|
324
|
+
type: xOracleRuleType,
|
|
299
325
|
txBlock: SuiKitTxBlock,
|
|
300
326
|
packageId: string,
|
|
301
327
|
request: TransactionArgument,
|
|
@@ -304,15 +330,15 @@ const updateSwitchboardPrice = (
|
|
|
304
330
|
coinType: string
|
|
305
331
|
) => {
|
|
306
332
|
txBlock.moveCall(
|
|
307
|
-
`${packageId}::rule::
|
|
333
|
+
`${packageId}::rule::set_price_as_${type}`,
|
|
308
334
|
[
|
|
309
335
|
request,
|
|
310
336
|
aggregatorId,
|
|
311
337
|
registryId,
|
|
312
338
|
txBlock.sharedObjectRef({
|
|
313
339
|
objectId: SUI_CLOCK_OBJECT_ID,
|
|
314
|
-
mutable: false,
|
|
315
340
|
initialSharedVersion: '1',
|
|
341
|
+
mutable: false,
|
|
316
342
|
}),
|
|
317
343
|
],
|
|
318
344
|
[coinType]
|
|
@@ -335,6 +361,7 @@ const updateSwitchboardPrice = (
|
|
|
335
361
|
* @return TxBlock created by SuiKit.
|
|
336
362
|
*/
|
|
337
363
|
const updatePythPrice = (
|
|
364
|
+
type: xOracleRuleType,
|
|
338
365
|
txBlock: SuiKitTxBlock,
|
|
339
366
|
packageId: string,
|
|
340
367
|
request: TransactionArgument,
|
|
@@ -344,7 +371,7 @@ const updatePythPrice = (
|
|
|
344
371
|
coinType: string
|
|
345
372
|
) => {
|
|
346
373
|
txBlock.moveCall(
|
|
347
|
-
`${packageId}::rule::
|
|
374
|
+
`${packageId}::rule::set_price_as_${type}`,
|
|
348
375
|
[
|
|
349
376
|
request,
|
|
350
377
|
stateId,
|
|
@@ -352,8 +379,8 @@ const updatePythPrice = (
|
|
|
352
379
|
registryId,
|
|
353
380
|
txBlock.sharedObjectRef({
|
|
354
381
|
objectId: SUI_CLOCK_OBJECT_ID,
|
|
355
|
-
mutable: false,
|
|
356
382
|
initialSharedVersion: '1',
|
|
383
|
+
mutable: false,
|
|
357
384
|
}),
|
|
358
385
|
],
|
|
359
386
|
[coinType]
|