@scallop-io/sui-scallop-sdk 0.44.1 → 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 +5 -3
- package/dist/constants/enum.d.ts +4 -2
- package/dist/index.js +843 -228
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +803 -192
- package/dist/index.mjs.map +1 -1
- package/dist/models/scallopClient.d.ts +33 -2
- package/dist/models/scallopQuery.d.ts +36 -10
- package/dist/models/scallopUtils.d.ts +12 -4
- package/dist/queries/borrowIncentiveQuery.d.ts +24 -0
- package/dist/queries/coreQuery.d.ts +12 -0
- package/dist/queries/index.d.ts +1 -0
- package/dist/queries/portfolioQuery.d.ts +1 -0
- package/dist/queries/spoolQuery.d.ts +13 -5
- package/dist/types/address.d.ts +10 -2
- 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 +9 -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 +15 -1
- package/package.json +12 -12
- 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 +6 -1
- package/src/constants/enum.ts +18 -2
- package/src/models/scallopAddress.ts +47 -0
- package/src/models/scallopClient.ts +104 -2
- package/src/models/scallopQuery.ts +48 -14
- package/src/models/scallopUtils.ts +53 -15
- 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 +10 -2
- 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 +13 -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 +59 -9
- package/dist/utils/oracle.d.ts +0 -14
- package/src/utils/oracle.ts +0 -36
|
@@ -2,9 +2,6 @@ import type { SupportStakeMarketCoins } from '../constant';
|
|
|
2
2
|
type OptionalKeys<T> = {
|
|
3
3
|
[K in keyof T]?: T[K];
|
|
4
4
|
};
|
|
5
|
-
export type StakePools = OptionalKeys<Record<SupportStakeMarketCoins, StakePool>>;
|
|
6
|
-
export type RewardPools = OptionalKeys<Record<SupportStakeMarketCoins, RewardPool>>;
|
|
7
|
-
export type StakeAccounts = Record<SupportStakeMarketCoins, StakeAccount[]>;
|
|
8
5
|
export type Spools = OptionalKeys<Record<SupportStakeMarketCoins, Spool>>;
|
|
9
6
|
export type Spool = {
|
|
10
7
|
marketCoinName: SupportStakeMarketCoins;
|
|
@@ -17,8 +14,8 @@ export type Spool = {
|
|
|
17
14
|
coinPrice: number;
|
|
18
15
|
marketCoinPrice: number;
|
|
19
16
|
rewardCoinPrice: number;
|
|
20
|
-
} &
|
|
21
|
-
export type
|
|
17
|
+
} & Required<Pick<ParsedSpoolData, 'maxPoint' | 'distributedPoint' | 'maxStake'>> & CalculatedSpoolData & SpoolRewardPool;
|
|
18
|
+
export type OriginSpoolData = {
|
|
22
19
|
stakeType: {
|
|
23
20
|
fields: {
|
|
24
21
|
name: string;
|
|
@@ -34,7 +31,7 @@ export type OriginStakePoolData = {
|
|
|
34
31
|
createdAt: string;
|
|
35
32
|
lastUpdate: string;
|
|
36
33
|
};
|
|
37
|
-
export type
|
|
34
|
+
export type ParsedSpoolData = {
|
|
38
35
|
stakeType: string;
|
|
39
36
|
maxPoint: number;
|
|
40
37
|
distributedPoint: number;
|
|
@@ -46,7 +43,7 @@ export type ParsedStakePoolData = {
|
|
|
46
43
|
createdAt: number;
|
|
47
44
|
lastUpdate: number;
|
|
48
45
|
};
|
|
49
|
-
export type
|
|
46
|
+
export type CalculatedSpoolData = {
|
|
50
47
|
stakedAmount: number;
|
|
51
48
|
stakedCoin: number;
|
|
52
49
|
stakedValue: number;
|
|
@@ -57,21 +54,22 @@ export type CalculatedStakePoolData = {
|
|
|
57
54
|
startDate: Date;
|
|
58
55
|
endDate: Date;
|
|
59
56
|
};
|
|
60
|
-
export type
|
|
57
|
+
export type SpoolRewardPool = Required<Pick<ParsedSpoolRewardPoolData, 'exchangeRateNumerator' | 'exchangeRateDenominator'>> & CalculatedSpoolRewardPoolData;
|
|
58
|
+
export type OriginSpoolRewardPoolData = {
|
|
61
59
|
claimed_rewards: string;
|
|
62
60
|
exchange_rate_denominator: string;
|
|
63
61
|
exchange_rate_numerator: string;
|
|
64
62
|
rewards: string;
|
|
65
63
|
spool_id: string;
|
|
66
64
|
};
|
|
67
|
-
export type
|
|
65
|
+
export type ParsedSpoolRewardPoolData = {
|
|
68
66
|
claimedRewards: number;
|
|
69
67
|
exchangeRateNumerator: number;
|
|
70
68
|
exchangeRateDenominator: number;
|
|
71
69
|
rewards: number;
|
|
72
70
|
spoolId: string;
|
|
73
71
|
};
|
|
74
|
-
export type
|
|
72
|
+
export type CalculatedSpoolRewardPoolData = {
|
|
75
73
|
rewardApr: number;
|
|
76
74
|
totalRewardAmount: number;
|
|
77
75
|
totalRewardCoin: number;
|
|
@@ -83,9 +81,10 @@ export type CalculatedRewardPoolData = {
|
|
|
83
81
|
claimedRewardCoin: number;
|
|
84
82
|
claimedRewardValue: number;
|
|
85
83
|
rewardPerSec: number;
|
|
86
|
-
exchangeRateNumerator: number;
|
|
87
|
-
exchangeRateDenominator: number;
|
|
88
84
|
};
|
|
85
|
+
export type StakePools = OptionalKeys<Record<SupportStakeMarketCoins, StakePool>>;
|
|
86
|
+
export type StakeRewardPools = OptionalKeys<Record<SupportStakeMarketCoins, StakeRewardPool>>;
|
|
87
|
+
export type StakeAccounts = Record<SupportStakeMarketCoins, StakeAccount[]>;
|
|
89
88
|
export interface StakeAccount {
|
|
90
89
|
id: string;
|
|
91
90
|
type: string;
|
|
@@ -110,7 +109,7 @@ export interface StakePool {
|
|
|
110
109
|
createdAt: number;
|
|
111
110
|
lastUpdate: number;
|
|
112
111
|
}
|
|
113
|
-
export interface
|
|
112
|
+
export interface StakeRewardPool {
|
|
114
113
|
id: string;
|
|
115
114
|
type: string;
|
|
116
115
|
stakePoolId: string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
2
|
+
/**
|
|
3
|
+
* Check and get the sender from the transaction block.
|
|
4
|
+
*
|
|
5
|
+
* @param txBlock - TxBlock created by SuiKit.
|
|
6
|
+
* @return Sender of transaction.
|
|
7
|
+
*/
|
|
8
|
+
export declare const requireSender: (txBlock: SuiKitTxBlock) => string;
|
package/dist/utils/index.d.ts
CHANGED
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,2 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ScallopAddress } from '../models';
|
|
2
|
+
import type { SupportAssetCoins, SupportCoins, SupportMarketCoins } from '../types';
|
|
2
3
|
export declare const isMarketCoin: (coinName: SupportCoins) => coinName is SupportMarketCoins;
|
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scallop-io/sui-scallop-sdk",
|
|
3
|
-
"version": "0.44.
|
|
3
|
+
"version": "0.44.3",
|
|
4
4
|
"description": "Typescript sdk for interacting with Scallop contract on SUI",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sui",
|
|
@@ -42,24 +42,24 @@
|
|
|
42
42
|
"@mysten/sui.js": "^0.44.0",
|
|
43
43
|
"@noble/curves": "^1.2.0",
|
|
44
44
|
"@noble/hashes": "^1.3.2",
|
|
45
|
-
"@pythnetwork/price-service-client": "^1.8.
|
|
46
|
-
"@pythnetwork/pyth-sui-js": "^1.2.
|
|
45
|
+
"@pythnetwork/price-service-client": "^1.8.2",
|
|
46
|
+
"@pythnetwork/pyth-sui-js": "^1.2.4",
|
|
47
47
|
"@scallop-io/sui-kit": "^0.44.0",
|
|
48
48
|
"@scure/bip39": "^1.2.1",
|
|
49
|
-
"axios": "^1.
|
|
49
|
+
"axios": "^1.6.0",
|
|
50
50
|
"bignumber.js": "^9.1.2",
|
|
51
51
|
"superstruct": "^1.0.3",
|
|
52
52
|
"tweetnacl": "^1.0.3"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@commitlint/cli": "^18.
|
|
56
|
-
"@commitlint/config-conventional": "^18.
|
|
57
|
-
"@commitlint/prompt-cli": "^18.
|
|
58
|
-
"@types/node": "^20.8.
|
|
59
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
60
|
-
"@typescript-eslint/parser": "^6.
|
|
55
|
+
"@commitlint/cli": "^18.2.0",
|
|
56
|
+
"@commitlint/config-conventional": "^18.1.0",
|
|
57
|
+
"@commitlint/prompt-cli": "^18.2.0",
|
|
58
|
+
"@types/node": "^20.8.10",
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^6.10.0",
|
|
60
|
+
"@typescript-eslint/parser": "^6.10.0",
|
|
61
61
|
"dotenv": "^16.3.1",
|
|
62
|
-
"eslint": "^8.
|
|
62
|
+
"eslint": "^8.53.0",
|
|
63
63
|
"eslint-config-prettier": "^9.0.0",
|
|
64
64
|
"eslint-plugin-prettier": "^5.0.1",
|
|
65
65
|
"husky": "^8.0.3",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"standard-version": "^9.5.0",
|
|
69
69
|
"tsconfig-paths": "^4.2.0",
|
|
70
70
|
"tsup": "^7.2.0",
|
|
71
|
-
"typedoc": "^0.25.
|
|
71
|
+
"typedoc": "^0.25.3",
|
|
72
72
|
"typescript": "^5.2.2",
|
|
73
73
|
"vitest": "^0.34.6"
|
|
74
74
|
},
|
|
@@ -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
|
@@ -16,6 +16,7 @@ export const SUPPORT_POOLS = [
|
|
|
16
16
|
'cetus',
|
|
17
17
|
'afsui',
|
|
18
18
|
'hasui',
|
|
19
|
+
'vsui',
|
|
19
20
|
] as const;
|
|
20
21
|
|
|
21
22
|
export const SUPPORT_COLLATERALS = [
|
|
@@ -29,12 +30,16 @@ export const SUPPORT_COLLATERALS = [
|
|
|
29
30
|
'cetus',
|
|
30
31
|
'afsui',
|
|
31
32
|
'hasui',
|
|
33
|
+
'vsui',
|
|
32
34
|
] as const;
|
|
33
35
|
|
|
34
36
|
export const SUPPORT_SPOOLS = ['ssui', 'susdc', 'susdt'] as const;
|
|
35
37
|
|
|
36
|
-
export const
|
|
38
|
+
export const SUPPORT_SPOOLS_REWARDS = ['sui'] as const;
|
|
37
39
|
|
|
40
|
+
export const SUPPORT_BORROW_INCENTIVE_POOLS = ['sui', 'usdc'] as const;
|
|
41
|
+
|
|
42
|
+
export const SUPPORT_BORROW_INCENTIVE_REWARDS = ['sui'] as const;
|
|
38
43
|
export const SUPPORT_ORACLES = ['supra', 'switchboard', 'pyth'] as const;
|
|
39
44
|
|
|
40
45
|
export const SUPPORT_PACKAGES = [
|