@scallop-io/sui-scallop-sdk 0.44.2 → 0.44.4
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 +12 -0
- package/dist/constants/common.d.ts +3 -1
- package/dist/constants/enum.d.ts +3 -2
- package/dist/index.js +815 -228
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +776 -192
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +33 -2
- package/dist/models/scallopQuery.d.ts +31 -10
- package/dist/models/scallopUtils.d.ts +11 -4
- package/dist/queries/borrowIncentiveQuery.d.ts +24 -0
- package/dist/queries/coreQuery.d.ts +8 -0
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/spoolQuery.d.ts +13 -5
- package/dist/types/address.d.ts +8 -0
- package/dist/types/builder/borrowIncentive.d.ts +31 -0
- package/dist/types/builder/index.d.ts +3 -1
- package/dist/types/constant/common.d.ts +5 -3
- package/dist/types/constant/enum.d.ts +6 -3
- package/dist/types/query/borrowIncentive.d.ts +118 -0
- package/dist/types/query/core.d.ts +1 -0
- package/dist/types/query/index.d.ts +1 -0
- package/dist/types/query/portfolio.d.ts +13 -0
- package/dist/types/query/spool.d.ts +12 -13
- package/dist/utils/builder.d.ts +8 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/query.d.ts +33 -10
- package/dist/utils/util.d.ts +13 -0
- package/package.json +1 -1
- package/src/builders/borrowIncentiveBuilder.ts +257 -0
- package/src/builders/coreBuilder.ts +1 -14
- package/src/builders/index.ts +9 -2
- package/src/builders/spoolBuilder.ts +3 -16
- package/src/constants/common.ts +4 -1
- package/src/constants/enum.ts +8 -2
- package/src/models/scallopAddress.ts +8 -0
- package/src/models/scallopClient.ts +104 -2
- package/src/models/scallopQuery.ts +48 -14
- package/src/models/scallopUtils.ts +21 -5
- package/src/queries/borrowIncentiveQuery.ts +167 -0
- package/src/queries/coreQuery.ts +58 -15
- package/src/queries/index.ts +1 -0
- package/src/queries/portfolioQuery.ts +59 -5
- package/src/queries/spoolQuery.ts +87 -71
- package/src/types/address.ts +8 -0
- package/src/types/builder/borrowIncentive.ts +67 -0
- package/src/types/builder/index.ts +5 -1
- package/src/types/builder/spool.ts +0 -1
- package/src/types/constant/common.ts +10 -3
- package/src/types/constant/enum.ts +9 -3
- package/src/types/query/borrowIncentive.ts +150 -0
- package/src/types/query/core.ts +1 -1
- package/src/types/query/index.ts +1 -0
- package/src/types/query/portfolio.ts +16 -0
- package/src/types/query/spool.ts +28 -18
- package/src/utils/builder.ts +15 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/query.ts +279 -72
- package/src/utils/util.ts +36 -2
- package/dist/utils/oracle.d.ts +0 -14
- package/src/utils/oracle.ts +0 -36
package/dist/utils/query.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js';
|
|
2
2
|
import type { ScallopUtils } from '../models';
|
|
3
|
-
import type { OriginMarketPoolData, ParsedMarketPoolData, CalculatedMarketPoolData, OriginMarketCollateralData, ParsedMarketCollateralData, CalculatedMarketCollateralData,
|
|
3
|
+
import type { OriginMarketPoolData, ParsedMarketPoolData, CalculatedMarketPoolData, OriginMarketCollateralData, ParsedMarketCollateralData, CalculatedMarketCollateralData, OriginSpoolData, ParsedSpoolData, CalculatedSpoolData, OriginSpoolRewardPoolData, ParsedSpoolRewardPoolData, CalculatedSpoolRewardPoolData, OriginBorrowIncentivePoolData, ParsedBorrowIncentivePoolData, CalculatedBorrowIncentivePoolData, OriginBorrowIncentiveRewardPoolData, ParsedBorrowIncentiveRewardPoolData, CalculatedBorrowIncentiveRewardPoolData, OriginBorrowIncentiveAccountData, ParsedBorrowIncentiveAccountData } from '../types';
|
|
4
4
|
/**
|
|
5
5
|
* Parse origin market pool data to a more readable format.
|
|
6
6
|
*
|
|
@@ -18,20 +18,43 @@ export declare const calculateMarketPoolData: (utils: ScallopUtils, parsedMarket
|
|
|
18
18
|
export declare const parseOriginMarketCollateralData: (originMarketCollateralData: OriginMarketCollateralData) => ParsedMarketCollateralData;
|
|
19
19
|
export declare const calculateMarketCollateralData: (utils: ScallopUtils, parsedMarketCollateralData: ParsedMarketCollateralData) => CalculatedMarketCollateralData;
|
|
20
20
|
/**
|
|
21
|
-
* Parse origin
|
|
21
|
+
* Parse origin spool data to a more readable format.
|
|
22
22
|
*
|
|
23
|
-
* @param
|
|
24
|
-
* @return Parsed
|
|
23
|
+
* @param originSpoolData - Origin spool data
|
|
24
|
+
* @return Parsed spool data
|
|
25
25
|
*/
|
|
26
|
-
export declare const
|
|
27
|
-
export declare const
|
|
26
|
+
export declare const parseOriginSpoolData: (originSpoolData: OriginSpoolData) => ParsedSpoolData;
|
|
27
|
+
export declare const calculateSpoolData: (parsedSpoolData: ParsedSpoolData, stakeMarketCoinPrice: number, stakeMarketCoinDecimal: number) => CalculatedSpoolData;
|
|
28
28
|
/**
|
|
29
|
-
* Parse origin reward pool data to a more readable format.
|
|
29
|
+
* Parse origin spool reward pool data to a more readable format.
|
|
30
30
|
*
|
|
31
31
|
* @param originRewardPoolData - Origin reward pool data
|
|
32
|
-
* @return Parsed reward pool data
|
|
32
|
+
* @return Parsed spool reward pool data
|
|
33
33
|
*/
|
|
34
|
-
export declare const
|
|
35
|
-
export declare const
|
|
34
|
+
export declare const parseOriginSpoolRewardPoolData: (originSpoolRewardPoolData: OriginSpoolRewardPoolData) => ParsedSpoolRewardPoolData;
|
|
35
|
+
export declare const calculateSpoolRewardPoolData: (parsedSpoolData: ParsedSpoolData, parsedSpoolRewardPoolData: ParsedSpoolRewardPoolData, calculatedSpoolData: CalculatedSpoolData, rewardCoinPrice: number, rewardCoinDecimal: number) => CalculatedSpoolRewardPoolData;
|
|
36
|
+
/**
|
|
37
|
+
* Parse origin borrow incentive pool data to a more readable format.
|
|
38
|
+
*
|
|
39
|
+
* @param originBorrowIncentivePoolData - Origin borrow incentive pool data
|
|
40
|
+
* @return Parsed borrow incentive pool data
|
|
41
|
+
*/
|
|
42
|
+
export declare const parseOriginBorrowIncentivePoolData: (originBorrowIncentivePoolData: OriginBorrowIncentivePoolData) => ParsedBorrowIncentivePoolData;
|
|
43
|
+
export declare const calculateBorrowIncentivePoolData: (parsedBorrowIncentivePoolData: ParsedBorrowIncentivePoolData, borrowIncentiveCoinPrice: number, borrowIncentiveCoinDecimal: number) => CalculatedBorrowIncentivePoolData;
|
|
44
|
+
/**
|
|
45
|
+
* Parse origin borrow incentive reward pool data to a more readable format.
|
|
46
|
+
*
|
|
47
|
+
* @param originBorrowIncentiveRewardPoolData - Origin borrow incentive reward pool data
|
|
48
|
+
* @return Parsed borrow incentive reward pool data
|
|
49
|
+
*/
|
|
50
|
+
export declare const parseOriginBorrowIncentiveRewardPoolData: (originBorrowIncentiveRewardPoolData: OriginBorrowIncentiveRewardPoolData) => ParsedBorrowIncentiveRewardPoolData;
|
|
51
|
+
export declare const calculateBorrowIncentiveRewardPoolData: (parsedBorrowIncentivePoolData: ParsedBorrowIncentivePoolData, parsedBorrowIncentiveRewardPoolData: ParsedBorrowIncentiveRewardPoolData, calculatedBorrowIncentivePoolData: CalculatedBorrowIncentivePoolData, rewardCoinPrice: number, rewardCoinDecimal: number) => CalculatedBorrowIncentiveRewardPoolData;
|
|
52
|
+
/**
|
|
53
|
+
* Parse origin borrow incentive account data to a more readable format.
|
|
54
|
+
*
|
|
55
|
+
* @param originBorrowIncentiveAccountData - Origin borrow incentive account data
|
|
56
|
+
* @return Parsed borrow incentive account data
|
|
57
|
+
*/
|
|
58
|
+
export declare const parseOriginBorrowIncentiveAccountData: (originBorrowIncentiveAccountData: OriginBorrowIncentiveAccountData) => ParsedBorrowIncentiveAccountData;
|
|
36
59
|
export declare const minBigNumber: (...args: BigNumber.Value[]) => BigNumber;
|
|
37
60
|
export declare const maxBigNumber: (...args: BigNumber.Value[]) => BigNumber;
|
package/dist/utils/util.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import type { ScallopAddress } from '../models';
|
|
1
2
|
import type { SupportAssetCoins, SupportCoins, SupportMarketCoins } from '../types';
|
|
2
3
|
export declare const isMarketCoin: (coinName: SupportCoins) => coinName is SupportMarketCoins;
|
|
3
4
|
export declare const parseAssetSymbol: (coinName: SupportAssetCoins) => string;
|
|
5
|
+
/**
|
|
6
|
+
* Parse price from pyth price feed.
|
|
7
|
+
*
|
|
8
|
+
* @param feed - Price feed object from pyth.
|
|
9
|
+
* @param address - Scallop address instance.
|
|
10
|
+
* @return Price Data inclue coin name, price, and publish time.
|
|
11
|
+
*/
|
|
12
|
+
export declare const parseDataFromPythPriceFeed: (feed: PriceFeed, address: ScallopAddress) => {
|
|
13
|
+
coinName: SupportAssetCoins;
|
|
14
|
+
price: number;
|
|
15
|
+
publishTime: number;
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
|
+
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui.js/utils';
|
|
3
|
+
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
4
|
+
import { borrowIncentiveRewardCoins } from '../constants/enum';
|
|
5
|
+
import { getObligations, getObligationLocked } from '../queries';
|
|
6
|
+
import { requireSender } from '../utils';
|
|
7
|
+
import type { SuiAddressArg } from '@scallop-io/sui-kit';
|
|
8
|
+
import type { ScallopBuilder } from '../models';
|
|
9
|
+
import type {
|
|
10
|
+
BorrowIncentiveIds,
|
|
11
|
+
GenerateBorrowIncentiveNormalMethod,
|
|
12
|
+
GenerateBorrowIncentiveQuickMethod,
|
|
13
|
+
SuiTxBlockWithBorrowIncentiveNormalMethods,
|
|
14
|
+
BorrowIncentiveTxBlock,
|
|
15
|
+
ScallopTxBlock,
|
|
16
|
+
} from '../types';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Check and get Obligation information from transaction block.
|
|
20
|
+
*
|
|
21
|
+
* @description
|
|
22
|
+
* If the obligation id is provided, direactly return it.
|
|
23
|
+
* If both obligation id and key is provided, direactly return them.
|
|
24
|
+
* Otherwise, automatically get obligation id and key from the sender.
|
|
25
|
+
*
|
|
26
|
+
* @param builder - Scallop builder instance.
|
|
27
|
+
* @param txBlock - TxBlock created by SuiKit.
|
|
28
|
+
* @param obligationId - Obligation id.
|
|
29
|
+
* @param obligationKey - Obligation key.
|
|
30
|
+
* @return Obligation id and key.
|
|
31
|
+
*/
|
|
32
|
+
const requireObligationInfo = async (
|
|
33
|
+
...params: [
|
|
34
|
+
builder: ScallopBuilder,
|
|
35
|
+
txBlock: SuiKitTxBlock,
|
|
36
|
+
obligationId?: SuiAddressArg,
|
|
37
|
+
obligationKey?: SuiAddressArg,
|
|
38
|
+
]
|
|
39
|
+
) => {
|
|
40
|
+
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
41
|
+
if (
|
|
42
|
+
params.length === 4 &&
|
|
43
|
+
obligationId &&
|
|
44
|
+
obligationKey &&
|
|
45
|
+
typeof obligationId === 'string'
|
|
46
|
+
) {
|
|
47
|
+
const obligationLocked = await getObligationLocked(
|
|
48
|
+
builder.query,
|
|
49
|
+
obligationId
|
|
50
|
+
);
|
|
51
|
+
return { obligationId, obligationKey, obligationLocked };
|
|
52
|
+
}
|
|
53
|
+
const sender = requireSender(txBlock);
|
|
54
|
+
const obligations = await getObligations(builder.query, sender);
|
|
55
|
+
if (obligations.length === 0) {
|
|
56
|
+
throw new Error(`No obligation found for sender ${sender}`);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
obligationId: obligations[0].id,
|
|
60
|
+
obligationKey: obligations[0].keyId,
|
|
61
|
+
obligationLocked: obligations[0].locked,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Generate borrow incentive normal methods.
|
|
67
|
+
*
|
|
68
|
+
* @param builder - Scallop builder instance.
|
|
69
|
+
* @param txBlock - TxBlock created by SuiKit .
|
|
70
|
+
* @return Borrow incentive normal methods.
|
|
71
|
+
*/
|
|
72
|
+
const generateBorrowIncentiveNormalMethod: GenerateBorrowIncentiveNormalMethod =
|
|
73
|
+
({ builder, txBlock }) => {
|
|
74
|
+
const borrowIncentiveIds: BorrowIncentiveIds = {
|
|
75
|
+
borrowIncentivePkg: builder.address.get('borrowIncentive.id'),
|
|
76
|
+
query: builder.address.get('borrowIncentive.query'),
|
|
77
|
+
incentivePools: builder.address.get('borrowIncentive.incentivePools'),
|
|
78
|
+
incentiveAccounts: builder.address.get(
|
|
79
|
+
'borrowIncentive.incentiveAccounts'
|
|
80
|
+
),
|
|
81
|
+
obligationAccessStore: builder.address.get('core.obligationAccessStore'),
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
stakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
85
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
86
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
87
|
+
txBlock.moveCall(
|
|
88
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::stake`,
|
|
89
|
+
[
|
|
90
|
+
borrowIncentiveIds.incentivePools,
|
|
91
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
92
|
+
obligaionKey,
|
|
93
|
+
obligationId,
|
|
94
|
+
borrowIncentiveIds.obligationAccessStore,
|
|
95
|
+
SUI_CLOCK_OBJECT_ID,
|
|
96
|
+
],
|
|
97
|
+
[rewardType]
|
|
98
|
+
);
|
|
99
|
+
},
|
|
100
|
+
unstakeObligation: (obligationId, obligaionKey, coinName) => {
|
|
101
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
102
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
103
|
+
txBlock.moveCall(
|
|
104
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::unstake`,
|
|
105
|
+
[
|
|
106
|
+
borrowIncentiveIds.incentivePools,
|
|
107
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
108
|
+
obligaionKey,
|
|
109
|
+
obligationId,
|
|
110
|
+
SUI_CLOCK_OBJECT_ID,
|
|
111
|
+
],
|
|
112
|
+
[rewardType]
|
|
113
|
+
);
|
|
114
|
+
},
|
|
115
|
+
claimBorrowIncentive: (obligationId, obligaionKey, coinName) => {
|
|
116
|
+
const rewardCoinName = borrowIncentiveRewardCoins[coinName];
|
|
117
|
+
const rewardType = builder.utils.parseCoinType(rewardCoinName);
|
|
118
|
+
return txBlock.moveCall(
|
|
119
|
+
`${borrowIncentiveIds.borrowIncentivePkg}::user::redeem_rewards`,
|
|
120
|
+
[
|
|
121
|
+
borrowIncentiveIds.incentivePools,
|
|
122
|
+
borrowIncentiveIds.incentiveAccounts,
|
|
123
|
+
obligaionKey,
|
|
124
|
+
obligationId,
|
|
125
|
+
SUI_CLOCK_OBJECT_ID,
|
|
126
|
+
],
|
|
127
|
+
[rewardType]
|
|
128
|
+
);
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Generate spool quick methods.
|
|
135
|
+
*
|
|
136
|
+
* @description
|
|
137
|
+
* The quick methods are the same as the normal methods, but they will automatically
|
|
138
|
+
* help users organize transaction blocks, include get stake account info, and transfer
|
|
139
|
+
* coins to the sender. So, they are all asynchronous methods.
|
|
140
|
+
*
|
|
141
|
+
* @param builder - Scallop builder instance.
|
|
142
|
+
* @param txBlock - TxBlock created by SuiKit .
|
|
143
|
+
* @return Spool quick methods.
|
|
144
|
+
*/
|
|
145
|
+
const generateBorrowIncentiveQuickMethod: GenerateBorrowIncentiveQuickMethod =
|
|
146
|
+
({ builder, txBlock }) => {
|
|
147
|
+
return {
|
|
148
|
+
stakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
149
|
+
const {
|
|
150
|
+
obligationId: obligationArg,
|
|
151
|
+
obligationKey: obligationtKeyArg,
|
|
152
|
+
obligationLocked: obligationLocked,
|
|
153
|
+
} = await requireObligationInfo(
|
|
154
|
+
builder,
|
|
155
|
+
txBlock,
|
|
156
|
+
obligation,
|
|
157
|
+
obligationKey
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const unstakeObligationBeforeStake =
|
|
161
|
+
!!txBlock.txBlock.blockData.transactions.find(
|
|
162
|
+
(txn) =>
|
|
163
|
+
txn.kind === 'MoveCall' &&
|
|
164
|
+
txn.target ===
|
|
165
|
+
`${builder.address.get('borrowIncentive.id')}::user::unstake`
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
if (!obligationLocked || unstakeObligationBeforeStake) {
|
|
169
|
+
txBlock.stakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
unstakeObligationQuick: async (coinName, obligation, obligationKey) => {
|
|
173
|
+
const {
|
|
174
|
+
obligationId: obligationArg,
|
|
175
|
+
obligationKey: obligationtKeyArg,
|
|
176
|
+
obligationLocked: obligationLocked,
|
|
177
|
+
} = await requireObligationInfo(
|
|
178
|
+
builder,
|
|
179
|
+
txBlock,
|
|
180
|
+
obligation,
|
|
181
|
+
obligationKey
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
if (obligationLocked) {
|
|
185
|
+
txBlock.unstakeObligation(obligationArg, obligationtKeyArg, coinName);
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
claimBorrowIncentiveQuick: async (
|
|
189
|
+
coinName,
|
|
190
|
+
obligation,
|
|
191
|
+
obligationKey
|
|
192
|
+
) => {
|
|
193
|
+
const {
|
|
194
|
+
obligationId: obligationArg,
|
|
195
|
+
obligationKey: obligationtKeyArg,
|
|
196
|
+
} = await requireObligationInfo(
|
|
197
|
+
builder,
|
|
198
|
+
txBlock,
|
|
199
|
+
obligation,
|
|
200
|
+
obligationKey
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
return txBlock.claimBorrowIncentive(
|
|
204
|
+
obligationArg,
|
|
205
|
+
obligationtKeyArg,
|
|
206
|
+
coinName
|
|
207
|
+
);
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Create an enhanced transaction block instance for interaction with borrow incentive modules of the Scallop contract.
|
|
214
|
+
*
|
|
215
|
+
* @param builder - Scallop builder instance.
|
|
216
|
+
* @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
|
|
217
|
+
* @return Scallop borrow incentive txBlock.
|
|
218
|
+
*/
|
|
219
|
+
export const newBorrowIncentiveTxBlock = (
|
|
220
|
+
builder: ScallopBuilder,
|
|
221
|
+
initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock
|
|
222
|
+
) => {
|
|
223
|
+
const txBlock =
|
|
224
|
+
initTxBlock instanceof TransactionBlock
|
|
225
|
+
? new SuiKitTxBlock(initTxBlock)
|
|
226
|
+
: initTxBlock
|
|
227
|
+
? initTxBlock
|
|
228
|
+
: new SuiKitTxBlock();
|
|
229
|
+
|
|
230
|
+
const normalMethod = generateBorrowIncentiveNormalMethod({
|
|
231
|
+
builder,
|
|
232
|
+
txBlock,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const normalTxBlock = new Proxy(txBlock, {
|
|
236
|
+
get: (target, prop) => {
|
|
237
|
+
if (prop in normalMethod) {
|
|
238
|
+
return Reflect.get(normalMethod, prop);
|
|
239
|
+
}
|
|
240
|
+
return Reflect.get(target, prop);
|
|
241
|
+
},
|
|
242
|
+
}) as SuiTxBlockWithBorrowIncentiveNormalMethods;
|
|
243
|
+
|
|
244
|
+
const quickMethod = generateBorrowIncentiveQuickMethod({
|
|
245
|
+
builder,
|
|
246
|
+
txBlock: normalTxBlock,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
return new Proxy(normalTxBlock, {
|
|
250
|
+
get: (target, prop) => {
|
|
251
|
+
if (prop in quickMethod) {
|
|
252
|
+
return Reflect.get(quickMethod, prop);
|
|
253
|
+
}
|
|
254
|
+
return Reflect.get(target, prop);
|
|
255
|
+
},
|
|
256
|
+
}) as BorrowIncentiveTxBlock;
|
|
257
|
+
};
|
|
@@ -3,6 +3,7 @@ import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui.js/utils';
|
|
|
3
3
|
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
4
4
|
import { getObligations } from '../queries';
|
|
5
5
|
import { updateOracles } from './oracle';
|
|
6
|
+
import { requireSender } from '../utils';
|
|
6
7
|
import type { SuiAddressArg } from '@scallop-io/sui-kit';
|
|
7
8
|
import type { ScallopBuilder } from '../models';
|
|
8
9
|
import type {
|
|
@@ -14,20 +15,6 @@ import type {
|
|
|
14
15
|
ScallopTxBlock,
|
|
15
16
|
} from '../types';
|
|
16
17
|
|
|
17
|
-
/**
|
|
18
|
-
* Check and get the sender from the transaction block.
|
|
19
|
-
*
|
|
20
|
-
* @param txBlock - txBlock created by SuiKit.
|
|
21
|
-
* @return Sender of transaction.
|
|
22
|
-
*/
|
|
23
|
-
const requireSender = (txBlock: SuiKitTxBlock) => {
|
|
24
|
-
const sender = txBlock.blockData.sender;
|
|
25
|
-
if (!sender) {
|
|
26
|
-
throw new Error('Sender is required');
|
|
27
|
-
}
|
|
28
|
-
return sender;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
18
|
/**
|
|
32
19
|
* Check and get Obligation information from transaction block.
|
|
33
20
|
*
|
package/src/builders/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
|
2
2
|
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
3
3
|
import { newCoreTxBlock } from './coreBuilder';
|
|
4
4
|
import { newSpoolTxBlock } from './spoolBuilder';
|
|
5
|
+
import { newBorrowIncentiveTxBlock } from './borrowIncentiveBuilder';
|
|
5
6
|
import type { ScallopBuilder } from '../models';
|
|
6
7
|
import type { ScallopTxBlock } from '../types';
|
|
7
8
|
|
|
@@ -16,12 +17,18 @@ export const newScallopTxBlock = (
|
|
|
16
17
|
builder: ScallopBuilder,
|
|
17
18
|
initTxBlock?: ScallopTxBlock | SuiKitTxBlock | TransactionBlock
|
|
18
19
|
): ScallopTxBlock => {
|
|
19
|
-
const
|
|
20
|
+
const borrowIncentiveTxBlock = newBorrowIncentiveTxBlock(
|
|
21
|
+
builder,
|
|
22
|
+
initTxBlock
|
|
23
|
+
);
|
|
24
|
+
const spoolTxBlock = newSpoolTxBlock(builder, borrowIncentiveTxBlock);
|
|
20
25
|
const coreTxBlock = newCoreTxBlock(builder, spoolTxBlock);
|
|
21
26
|
|
|
22
27
|
return new Proxy(coreTxBlock, {
|
|
23
28
|
get: (target, prop) => {
|
|
24
|
-
if (prop in
|
|
29
|
+
if (prop in borrowIncentiveTxBlock) {
|
|
30
|
+
return Reflect.get(borrowIncentiveTxBlock, prop);
|
|
31
|
+
} else if (prop in spoolTxBlock) {
|
|
25
32
|
return Reflect.get(spoolTxBlock, prop);
|
|
26
33
|
}
|
|
27
34
|
return Reflect.get(target, prop);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { TransactionBlock } from '@mysten/sui.js/transactions';
|
|
2
2
|
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui.js/utils';
|
|
3
3
|
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
4
|
-
import {
|
|
4
|
+
import { spoolRewardCoins } from '../constants/enum';
|
|
5
5
|
import { getStakeAccounts } from '../queries/spoolQuery';
|
|
6
|
+
import { requireSender } from '../utils';
|
|
6
7
|
import type { SuiAddressArg } from '@scallop-io/sui-kit';
|
|
7
8
|
import type { TransactionResult } from '@mysten/sui.js/transactions';
|
|
8
9
|
import type { ScallopBuilder } from '../models';
|
|
@@ -16,20 +17,6 @@ import type {
|
|
|
16
17
|
ScallopTxBlock,
|
|
17
18
|
} from '../types';
|
|
18
19
|
|
|
19
|
-
/**
|
|
20
|
-
* Check and get the sender from the transaction block.
|
|
21
|
-
*
|
|
22
|
-
* @param txBlock - TxBlock created by SuiKit.
|
|
23
|
-
* @return Sender of transaction.
|
|
24
|
-
*/
|
|
25
|
-
const requireSender = (txBlock: SuiKitTxBlock) => {
|
|
26
|
-
const sender = txBlock.blockData.sender;
|
|
27
|
-
if (!sender) {
|
|
28
|
-
throw new Error('Sender is required');
|
|
29
|
-
}
|
|
30
|
-
return sender;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
20
|
/**
|
|
34
21
|
* Check and get stake account id from transaction block.
|
|
35
22
|
*
|
|
@@ -158,7 +145,7 @@ const generateSpoolNormalMethod: GenerateSpoolNormalMethod = ({
|
|
|
158
145
|
);
|
|
159
146
|
const marketCoinType =
|
|
160
147
|
builder.utils.parseMarketCoinType(stakeMarketCoinName);
|
|
161
|
-
const rewardCoinName =
|
|
148
|
+
const rewardCoinName = spoolRewardCoins[stakeMarketCoinName];
|
|
162
149
|
const rewardCoinType = builder.utils.parseCoinType(rewardCoinName);
|
|
163
150
|
return txBlock.moveCall(
|
|
164
151
|
`${spoolIds.spoolPkg}::user::redeem_rewards`,
|
package/src/constants/common.ts
CHANGED
|
@@ -35,8 +35,11 @@ export const SUPPORT_COLLATERALS = [
|
|
|
35
35
|
|
|
36
36
|
export const SUPPORT_SPOOLS = ['ssui', 'susdc', 'susdt'] as const;
|
|
37
37
|
|
|
38
|
-
export const
|
|
38
|
+
export const SUPPORT_SPOOLS_REWARDS = ['sui'] as const;
|
|
39
39
|
|
|
40
|
+
export const SUPPORT_BORROW_INCENTIVE_POOLS = ['sui', 'usdc'] as const;
|
|
41
|
+
|
|
42
|
+
export const SUPPORT_BORROW_INCENTIVE_REWARDS = ['sui'] as const;
|
|
40
43
|
export const SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;
|
|
41
44
|
|
|
42
45
|
export const SUPPORT_PACKAGES = [
|
package/src/constants/enum.ts
CHANGED
|
@@ -3,7 +3,8 @@ import type {
|
|
|
3
3
|
AssetCoins,
|
|
4
4
|
MarketCoins,
|
|
5
5
|
StakeMarketCoins,
|
|
6
|
-
|
|
6
|
+
StakeRewardCoins,
|
|
7
|
+
BorrowIncentiveRewardCoins,
|
|
7
8
|
AssetCoinIds,
|
|
8
9
|
WormholeCoinIds,
|
|
9
10
|
VoloCoinIds,
|
|
@@ -68,12 +69,17 @@ export const stakeMarketCoins: StakeMarketCoins = {
|
|
|
68
69
|
susdt: 'susdt',
|
|
69
70
|
};
|
|
70
71
|
|
|
71
|
-
export const
|
|
72
|
+
export const spoolRewardCoins: StakeRewardCoins = {
|
|
72
73
|
ssui: 'sui',
|
|
73
74
|
susdc: 'sui',
|
|
74
75
|
susdt: 'sui',
|
|
75
76
|
};
|
|
76
77
|
|
|
78
|
+
export const borrowIncentiveRewardCoins: BorrowIncentiveRewardCoins = {
|
|
79
|
+
sui: 'sui',
|
|
80
|
+
usdc: 'sui',
|
|
81
|
+
};
|
|
82
|
+
|
|
77
83
|
export const coinIds: AssetCoinIds = {
|
|
78
84
|
sui: '0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
79
85
|
eth: '0xaf8cd5edc19c4512f4259f0bee101a40d41ebed738ade5874359610ef8eeced5',
|
|
@@ -14,6 +14,7 @@ const EMPTY_ADDRESSES: AddressesInterface = {
|
|
|
14
14
|
market: '',
|
|
15
15
|
adminCap: '',
|
|
16
16
|
coinDecimalsRegistry: '',
|
|
17
|
+
obligationAccessStore: '',
|
|
17
18
|
coins: {
|
|
18
19
|
btc: {
|
|
19
20
|
id: '',
|
|
@@ -198,6 +199,13 @@ const EMPTY_ADDRESSES: AddressesInterface = {
|
|
|
198
199
|
},
|
|
199
200
|
},
|
|
200
201
|
},
|
|
202
|
+
borrowIncentive: {
|
|
203
|
+
id: '',
|
|
204
|
+
adminCap: '',
|
|
205
|
+
query: '',
|
|
206
|
+
incentivePools: '',
|
|
207
|
+
incentiveAccounts: '',
|
|
208
|
+
},
|
|
201
209
|
};
|
|
202
210
|
|
|
203
211
|
/**
|
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
SupportAssetCoins,
|
|
18
18
|
SupportStakeCoins,
|
|
19
19
|
SupportStakeMarketCoins,
|
|
20
|
+
SupportBorrowIncentiveCoins,
|
|
20
21
|
ScallopTxBlock,
|
|
21
22
|
} from '../types';
|
|
22
23
|
|
|
@@ -189,8 +190,8 @@ export class ScallopClient {
|
|
|
189
190
|
* @param stakeMarketCoinName - Support stake market coin.
|
|
190
191
|
* @return Reward pool data.
|
|
191
192
|
*/
|
|
192
|
-
async
|
|
193
|
-
return await this.query.
|
|
193
|
+
async getStakeRewardPool(stakeMarketCoinName: SupportStakeMarketCoins) {
|
|
194
|
+
return await this.query.getStakeRewardPool(stakeMarketCoinName);
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
/* ==================== Core Method ==================== */
|
|
@@ -819,6 +820,107 @@ export class ScallopClient {
|
|
|
819
820
|
}
|
|
820
821
|
}
|
|
821
822
|
|
|
823
|
+
/* ==================== Borrow Incentive Method ==================== */
|
|
824
|
+
|
|
825
|
+
/**
|
|
826
|
+
* stake obligaion.
|
|
827
|
+
*
|
|
828
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
829
|
+
* @param obligaionId - The obligation account object.
|
|
830
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
831
|
+
* @param walletAddress - The wallet address of the owner.
|
|
832
|
+
* @return Transaction block response or transaction block
|
|
833
|
+
*/
|
|
834
|
+
public async stakeObligation<S extends boolean>(
|
|
835
|
+
coinName: SupportBorrowIncentiveCoins,
|
|
836
|
+
obligaionId: string,
|
|
837
|
+
obligaionKeyId: string,
|
|
838
|
+
sign: S = true as S,
|
|
839
|
+
walletAddress?: string
|
|
840
|
+
): Promise<ScallopClientFnReturnType<S>> {
|
|
841
|
+
const txBlock = this.builder.createTxBlock();
|
|
842
|
+
const sender = walletAddress || this.walletAddress;
|
|
843
|
+
txBlock.setSender(sender);
|
|
844
|
+
|
|
845
|
+
await txBlock.stakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
846
|
+
|
|
847
|
+
if (sign) {
|
|
848
|
+
return (await this.suiKit.signAndSendTxn(
|
|
849
|
+
txBlock
|
|
850
|
+
)) as ScallopClientFnReturnType<S>;
|
|
851
|
+
} else {
|
|
852
|
+
return txBlock.txBlock as ScallopClientFnReturnType<S>;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* unstake obligaion.
|
|
858
|
+
*
|
|
859
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
860
|
+
* @param obligaionId - The obligation account object.
|
|
861
|
+
* @param obligaionKeyId - The obligation key account object.
|
|
862
|
+
* @param walletAddress - The wallet address of the owner.
|
|
863
|
+
* @return Transaction block response or transaction block
|
|
864
|
+
*/
|
|
865
|
+
public async unstakeObligation<S extends boolean>(
|
|
866
|
+
coinName: SupportBorrowIncentiveCoins,
|
|
867
|
+
obligaionId: string,
|
|
868
|
+
obligaionKeyId: string,
|
|
869
|
+
sign: S = true as S,
|
|
870
|
+
walletAddress?: string
|
|
871
|
+
): Promise<ScallopClientFnReturnType<S>> {
|
|
872
|
+
const txBlock = this.builder.createTxBlock();
|
|
873
|
+
const sender = walletAddress || this.walletAddress;
|
|
874
|
+
txBlock.setSender(sender);
|
|
875
|
+
|
|
876
|
+
await txBlock.unstakeObligationQuick(coinName, obligaionId, obligaionKeyId);
|
|
877
|
+
|
|
878
|
+
if (sign) {
|
|
879
|
+
return (await this.suiKit.signAndSendTxn(
|
|
880
|
+
txBlock
|
|
881
|
+
)) as ScallopClientFnReturnType<S>;
|
|
882
|
+
} else {
|
|
883
|
+
return txBlock.txBlock as ScallopClientFnReturnType<S>;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* unstake market coin from the specific spool.
|
|
889
|
+
*
|
|
890
|
+
* @param marketCoinName - Types of mak coin.
|
|
891
|
+
* @param amount - The amount of coins would deposit.
|
|
892
|
+
* @param sign - Decide to directly sign the transaction or return the transaction block.
|
|
893
|
+
* @param accountId - The stake account object.
|
|
894
|
+
* @param walletAddress - The wallet address of the owner.
|
|
895
|
+
* @return Transaction block response or transaction block
|
|
896
|
+
*/
|
|
897
|
+
public async claimBorrowIncentive<S extends boolean>(
|
|
898
|
+
coinName: SupportBorrowIncentiveCoins,
|
|
899
|
+
obligaionId: string,
|
|
900
|
+
obligaionKeyId: string,
|
|
901
|
+
sign: S = true as S,
|
|
902
|
+
walletAddress?: string
|
|
903
|
+
): Promise<ScallopClientFnReturnType<S>> {
|
|
904
|
+
const txBlock = this.builder.createTxBlock();
|
|
905
|
+
const sender = walletAddress || this.walletAddress;
|
|
906
|
+
txBlock.setSender(sender);
|
|
907
|
+
|
|
908
|
+
const rewardCoin = await txBlock.claimBorrowIncentiveQuick(
|
|
909
|
+
coinName,
|
|
910
|
+
obligaionId,
|
|
911
|
+
obligaionKeyId
|
|
912
|
+
);
|
|
913
|
+
txBlock.transferObjects([rewardCoin], sender);
|
|
914
|
+
|
|
915
|
+
if (sign) {
|
|
916
|
+
return (await this.suiKit.signAndSendTxn(
|
|
917
|
+
txBlock
|
|
918
|
+
)) as ScallopClientFnReturnType<S>;
|
|
919
|
+
} else {
|
|
920
|
+
return txBlock.txBlock as ScallopClientFnReturnType<S>;
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
|
|
822
924
|
/* ==================== Other Method ==================== */
|
|
823
925
|
|
|
824
926
|
/**
|