@scallop-io/sui-scallop-sdk 0.44.2 → 0.44.3
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 +753 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +714 -175
- 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/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 +166 -0
- package/src/queries/coreQuery.ts +57 -15
- package/src/queries/index.ts +1 -0
- package/src/queries/spoolQuery.ts +78 -62
- 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/spool.ts +28 -18
- package/src/utils/builder.ts +15 -0
- package/src/utils/index.ts +1 -1
- package/src/utils/query.ts +277 -70
- 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/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
|
/**
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
queryObligation,
|
|
7
7
|
getStakeAccounts,
|
|
8
8
|
getStakePool,
|
|
9
|
-
|
|
9
|
+
getStakeRewardPool,
|
|
10
10
|
getPythPrice,
|
|
11
11
|
getMarketPools,
|
|
12
12
|
getMarketPool,
|
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
getMarketCollateral,
|
|
15
15
|
getSpools,
|
|
16
16
|
getSpool,
|
|
17
|
+
queryBorrowIncentivePools,
|
|
18
|
+
queryBorrowIncentiveAccounts,
|
|
17
19
|
getCoinAmounts,
|
|
18
20
|
getCoinAmount,
|
|
19
21
|
getMarketCoinAmounts,
|
|
@@ -33,7 +35,8 @@ import {
|
|
|
33
35
|
SupportCollateralCoins,
|
|
34
36
|
SupportMarketCoins,
|
|
35
37
|
StakePools,
|
|
36
|
-
|
|
38
|
+
StakeRewardPools,
|
|
39
|
+
SupportBorrowIncentiveCoins,
|
|
37
40
|
} from '../types';
|
|
38
41
|
import { ScallopAddress } from './scallopAddress';
|
|
39
42
|
import { ScallopUtils } from './scallopUtils';
|
|
@@ -323,43 +326,74 @@ export class ScallopQuery {
|
|
|
323
326
|
}
|
|
324
327
|
|
|
325
328
|
/**
|
|
326
|
-
* Get reward pools data.
|
|
329
|
+
* Get stake reward pools data.
|
|
327
330
|
*
|
|
328
331
|
* @description
|
|
329
332
|
* For backward compatible, it is recommended to use `getSpools` method
|
|
330
333
|
* to get all spools data.
|
|
331
334
|
*
|
|
332
335
|
* @param stakeMarketCoinNames - Specific an array of stake market coin name.
|
|
333
|
-
* @return
|
|
336
|
+
* @return Stake reward pools data.
|
|
334
337
|
*/
|
|
335
|
-
public async
|
|
338
|
+
public async getStakeRewardPools(
|
|
336
339
|
stakeMarketCoinNames?: SupportStakeMarketCoins[]
|
|
337
340
|
) {
|
|
338
341
|
stakeMarketCoinNames = stakeMarketCoinNames ?? [...SUPPORT_SPOOLS];
|
|
339
|
-
const
|
|
342
|
+
const stakeRewardPools: StakeRewardPools = {};
|
|
340
343
|
for (const stakeMarketCoinName of stakeMarketCoinNames) {
|
|
341
|
-
const
|
|
344
|
+
const stakeRewardPool = await getStakeRewardPool(
|
|
345
|
+
this,
|
|
346
|
+
stakeMarketCoinName
|
|
347
|
+
);
|
|
342
348
|
|
|
343
|
-
if (
|
|
344
|
-
|
|
349
|
+
if (stakeRewardPool) {
|
|
350
|
+
stakeRewardPools[stakeMarketCoinName] = stakeRewardPool;
|
|
345
351
|
}
|
|
346
352
|
}
|
|
347
353
|
|
|
348
|
-
return
|
|
354
|
+
return stakeRewardPools;
|
|
349
355
|
}
|
|
350
356
|
|
|
351
357
|
/**
|
|
352
|
-
* Get reward pool data.
|
|
358
|
+
* Get stake reward pool data.
|
|
353
359
|
*
|
|
354
360
|
* @description
|
|
355
361
|
* For backward compatible, it is recommended to use `getSpool` method
|
|
356
362
|
* to get spool data.
|
|
357
363
|
*
|
|
358
364
|
* @param marketCoinName - Specific support stake market coin name.
|
|
359
|
-
* @return
|
|
365
|
+
* @return Stake reward pool data.
|
|
360
366
|
*/
|
|
361
|
-
public async
|
|
362
|
-
|
|
367
|
+
public async getStakeRewardPool(
|
|
368
|
+
stakeMarketCoinName: SupportStakeMarketCoins
|
|
369
|
+
) {
|
|
370
|
+
return await getStakeRewardPool(this, stakeMarketCoinName);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Get borrow incentive pools data.
|
|
375
|
+
*
|
|
376
|
+
* @param coinNames - Specific an array of support borrow incentive coin name.
|
|
377
|
+
* @return Borrow incentive pools data.
|
|
378
|
+
*/
|
|
379
|
+
public async getBorrowIncentivePools(
|
|
380
|
+
coinNames?: SupportBorrowIncentiveCoins[]
|
|
381
|
+
) {
|
|
382
|
+
return await queryBorrowIncentivePools(this, coinNames);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Get borrow incentive accounts data.
|
|
387
|
+
*
|
|
388
|
+
* @param coinNames - Specific support borrow incentive coin name.
|
|
389
|
+
* @param ownerAddress - The owner address.
|
|
390
|
+
* @return Borrow incentive accounts data.
|
|
391
|
+
*/
|
|
392
|
+
public async getBorrowIncentiveAccounts(
|
|
393
|
+
obligationId: string,
|
|
394
|
+
coinNames?: SupportBorrowIncentiveCoins[]
|
|
395
|
+
) {
|
|
396
|
+
return await queryBorrowIncentiveAccounts(this, obligationId, coinNames);
|
|
363
397
|
}
|
|
364
398
|
|
|
365
399
|
/**
|