@scallop-io/sui-scallop-sdk 3.0.2 → 4.1.0
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/Logger-Cg2iFdpH.d.ts +8 -0
- package/dist/builder.cjs +22 -0
- package/dist/builder.d.cts +28 -0
- package/dist/builder.d.ts +28 -0
- package/dist/builder.js +4 -0
- package/dist/chunk-33AK5RWM.js +15 -0
- package/dist/chunk-6UQ4NWEU.js +3 -0
- package/dist/chunk-DIC6P5HB.js +11 -0
- package/dist/chunk-S34VOEZN.js +3 -0
- package/dist/chunk-VTGQACWU.js +6 -0
- package/dist/client.cjs +21 -0
- package/dist/client.d.cts +401 -0
- package/dist/client.d.ts +401 -0
- package/dist/client.js +5 -0
- package/dist/errors.cjs +10 -0
- package/dist/errors.d.cts +32 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.js +1 -0
- package/dist/index.cjs +51 -34
- package/dist/index.d.cts +130 -3145
- package/dist/index.d.ts +130 -3145
- package/dist/index.js +8 -12
- package/dist/logger.cjs +6 -0
- package/dist/logger.d.cts +7 -0
- package/dist/logger.d.ts +7 -0
- package/dist/logger.js +1 -0
- package/dist/query-DkitepDi.d.ts +3305 -0
- package/dist/query.cjs +19 -0
- package/dist/query.d.cts +9 -0
- package/dist/query.d.ts +9 -0
- package/dist/query.js +3 -0
- package/dist/types.cjs +2 -0
- package/dist/types.d.cts +90 -0
- package/dist/types.d.ts +90 -0
- package/dist/types.js +1 -0
- package/package.json +98 -56
- package/src/constants/api.ts +2 -0
- package/src/constants/coinType.ts +2 -0
- package/src/constants/common.ts +0 -7
- package/src/constants/index.ts +2 -0
- package/src/constants/queryKeys.ts +14 -7
- package/src/constants/testAddress.ts +1 -0
- package/src/datasources/api.ts +34 -0
- package/src/datasources/indexer.ts +8 -0
- package/src/datasources/onchain.ts +121 -0
- package/src/entries/builder.ts +5 -0
- package/src/entries/client.ts +3 -0
- package/src/entries/errors.ts +2 -0
- package/src/entries/index.ts +17 -0
- package/src/entries/logger.ts +2 -0
- package/src/entries/query.ts +6 -0
- package/src/entries/types.ts +2 -0
- package/src/errors/ScallopConfigError.ts +8 -0
- package/src/errors/ScallopError.ts +30 -0
- package/src/errors/ScallopIndexerError.ts +8 -0
- package/src/errors/ScallopParseError.ts +8 -0
- package/src/errors/ScallopRpcError.ts +8 -0
- package/src/errors/ScallopTransactionBuildError.ts +8 -0
- package/src/errors/index.ts +6 -0
- package/src/logger/Logger.ts +6 -0
- package/src/logger/consoleLogger.ts +13 -0
- package/src/logger/index.ts +3 -0
- package/src/logger/noopLogger.ts +8 -0
- package/src/mappers/index.ts +1 -0
- package/src/mappers/moveTypeMapper.ts +48 -0
- package/src/models/index.ts +8 -10
- package/src/models/interface.ts +9 -9
- package/src/models/scallop.ts +9 -16
- package/src/models/scallopAddress/const.ts +416 -0
- package/src/models/scallopAddress/index.ts +188 -0
- package/src/models/scallopAddress/types.ts +212 -0
- package/src/models/{scallopBuilder.ts → scallopBuilder/index.ts} +65 -29
- package/src/models/scallopBuilder/types.ts +37 -0
- package/src/models/{scallopClient.ts → scallopClient/index.ts} +157 -598
- package/src/models/scallopClient/types.ts +25 -0
- package/src/models/scallopConstants/config/AddressConfigSource.ts +13 -0
- package/src/models/scallopConstants/config/ConfigValidator.ts +70 -0
- package/src/models/scallopConstants/config/PoolAddressConfigSource.ts +12 -0
- package/src/models/scallopConstants/config/ScallopConfig.ts +80 -0
- package/src/models/scallopConstants/config/ScallopConfigSnapshot.ts +46 -0
- package/src/models/scallopConstants/config/WhitelistConfigSource.ts +16 -0
- package/src/models/scallopConstants/config/index.ts +6 -0
- package/src/models/scallopConstants/const.ts +19 -0
- package/src/models/scallopConstants/constantsSource.ts +98 -0
- package/src/models/scallopConstants/deriveConstants.ts +150 -0
- package/src/models/scallopConstants/index.ts +257 -0
- package/src/models/scallopConstants/loadConstantsState.ts +135 -0
- package/src/models/scallopConstants/types.ts +77 -0
- package/src/models/scallopConstants/utils.ts +69 -0
- package/src/models/scallopQuery/index.ts +1279 -0
- package/src/models/scallopQuery/types.ts +9 -0
- package/src/models/scallopQuery/utils.ts +13 -0
- package/src/models/scallopUtils/index.ts +505 -0
- package/src/models/scallopUtils/types.ts +30 -0
- package/src/models/transactionExecutor.ts +122 -0
- package/src/repositories/addressApi/helpers.ts +14 -0
- package/src/repositories/addressApi/index.ts +24 -0
- package/src/repositories/addressApi/schema.ts +0 -0
- package/src/repositories/addressApi/types.ts +177 -0
- package/src/repositories/base.ts +38 -0
- package/src/repositories/borrowIncentive/bcs.ts +11 -0
- package/src/repositories/borrowIncentive/helpers.ts +396 -0
- package/src/repositories/borrowIncentive/index.ts +52 -0
- package/src/{types/query/borrowIncentive.ts → repositories/borrowIncentive/types.ts} +69 -23
- package/src/repositories/borrowIncentive/utils.ts +234 -0
- package/src/repositories/cache.ts +4 -0
- package/src/repositories/coinBalance/helpers.ts +394 -0
- package/src/repositories/coinBalance/index.ts +69 -0
- package/src/repositories/coinBalance/types.ts +33 -0
- package/src/repositories/flashloan/const.ts +3 -0
- package/src/repositories/flashloan/helpers.ts +107 -0
- package/src/repositories/flashloan/index.ts +34 -0
- package/src/repositories/flashloan/types.ts +16 -0
- package/src/repositories/isolatedAssets/bcs.ts +4 -0
- package/src/repositories/isolatedAssets/const.ts +2 -0
- package/src/repositories/isolatedAssets/helpers.ts +91 -0
- package/src/repositories/isolatedAssets/index.ts +42 -0
- package/src/repositories/isolatedAssets/types.ts +35 -0
- package/src/repositories/loyaltyProgram/bcs.ts +7 -0
- package/src/repositories/loyaltyProgram/helpers.ts +117 -0
- package/src/repositories/loyaltyProgram/index.ts +28 -0
- package/src/repositories/loyaltyProgram/schema.ts +18 -0
- package/src/repositories/loyaltyProgram/types.ts +37 -0
- package/src/repositories/market/const.ts +6 -0
- package/src/repositories/market/helpers.ts +740 -0
- package/src/repositories/market/index.ts +137 -0
- package/src/repositories/market/mapper.ts +30 -0
- package/src/repositories/market/types.ts +443 -0
- package/src/repositories/market/utils.ts +285 -0
- package/src/repositories/obligation/helpers.ts +228 -0
- package/src/repositories/obligation/index.ts +51 -0
- package/src/repositories/obligation/types.ts +71 -0
- package/src/repositories/obligation/utils.ts +57 -0
- package/src/repositories/poolAddresses/const.ts +5 -0
- package/src/repositories/poolAddresses/helpers.ts +422 -0
- package/src/repositories/poolAddresses/index.ts +56 -0
- package/src/repositories/poolAddresses/schema.ts +34 -0
- package/src/repositories/poolAddresses/types.ts +69 -0
- package/src/repositories/price/const.ts +1 -0
- package/src/repositories/price/helpers.ts +237 -0
- package/src/repositories/price/index.ts +91 -0
- package/src/repositories/price/schema.ts +24 -0
- package/src/repositories/price/types.ts +56 -0
- package/src/repositories/price/utils.ts +21 -0
- package/src/repositories/referral/bcs.ts +3 -0
- package/src/repositories/referral/helper.ts +24 -0
- package/src/repositories/referral/index.ts +31 -0
- package/src/repositories/referral/types.ts +33 -0
- package/src/repositories/spool/const.ts +1 -0
- package/src/repositories/spool/helpers.ts +471 -0
- package/src/repositories/spool/index.ts +135 -0
- package/src/{types/query/spool.ts → repositories/spool/types.ts} +67 -2
- package/src/repositories/spool/utils.ts +215 -0
- package/src/repositories/types.ts +39 -0
- package/src/repositories/utils.ts +137 -0
- package/src/repositories/veSca/bcs.ts +6 -0
- package/src/repositories/veSca/helpers.ts +341 -0
- package/src/repositories/veSca/index.ts +57 -0
- package/src/repositories/veSca/types.ts +79 -0
- package/src/repositories/veScaLoyaltyProgram/bcs.ts +3 -0
- package/src/repositories/veScaLoyaltyProgram/helpers.ts +135 -0
- package/src/repositories/veScaLoyaltyProgram/index.ts +28 -0
- package/src/repositories/veScaLoyaltyProgram/schema.ts +15 -0
- package/src/repositories/veScaLoyaltyProgram/types.ts +47 -0
- package/src/repositories/wiring/datasources.ts +42 -0
- package/src/repositories/wiring/metadata.ts +292 -0
- package/src/repositories/wiring/registry.ts +194 -0
- package/src/repositories/wiring/source.ts +63 -0
- package/src/repositories/xOracle/bcs.ts +7 -0
- package/src/repositories/xOracle/const.ts +1 -0
- package/src/repositories/xOracle/helpers.ts +304 -0
- package/src/repositories/xOracle/index.ts +45 -0
- package/src/repositories/xOracle/types.ts +96 -0
- package/src/repositories/xOracle/utils.ts +3 -0
- package/src/services/client/BorrowService.ts +229 -0
- package/src/services/client/CollateralService.ts +76 -0
- package/src/services/client/LendingService.ts +75 -0
- package/src/services/client/ReferralService.ts +71 -0
- package/src/services/client/SpoolService.ts +170 -0
- package/src/services/client/VeScaService.ts +142 -0
- package/src/services/client/types.ts +44 -0
- package/src/services/index.ts +8 -0
- package/src/services/query/portfolioCalculations.ts +1171 -0
- package/src/txBuilders/borrowIncentive/index.ts +80 -0
- package/src/txBuilders/borrowIncentive/moveCalls.ts +124 -0
- package/src/txBuilders/borrowIncentive/quick.ts +207 -0
- package/src/txBuilders/context.ts +62 -0
- package/src/txBuilders/core/index.ts +95 -0
- package/src/txBuilders/core/moveCalls.ts +241 -0
- package/src/txBuilders/core/quick.ts +306 -0
- package/src/{builders → txBuilders}/index.ts +35 -9
- package/src/txBuilders/loyaltyProgram/index.ts +78 -0
- package/src/txBuilders/loyaltyProgram/moveCalls.ts +44 -0
- package/src/txBuilders/loyaltyProgram/quick.ts +58 -0
- package/src/txBuilders/manifest.ts +160 -0
- package/src/txBuilders/modules.ts +70 -0
- package/src/{builders → txBuilders}/oracles/index.ts +3 -2
- package/src/{builders → txBuilders}/oracles/pyth.ts +4 -3
- package/src/txBuilders/referral/index.ts +72 -0
- package/src/txBuilders/referral/moveCalls.ts +93 -0
- package/src/txBuilders/referral/quick.ts +57 -0
- package/src/txBuilders/sCoin/index.ts +72 -0
- package/src/txBuilders/sCoin/moveCalls.ts +36 -0
- package/src/txBuilders/sCoin/quick.ts +34 -0
- package/src/txBuilders/spool/index.ts +82 -0
- package/src/txBuilders/spool/moveCalls.ts +79 -0
- package/src/{builders/spoolBuilder.ts → txBuilders/spool/quick.ts} +22 -162
- package/src/txBuilders/utils.ts +36 -0
- package/src/txBuilders/verify.ts +45 -0
- package/src/txBuilders/vesca/index.ts +75 -0
- package/src/txBuilders/vesca/moveCalls.ts +147 -0
- package/src/{builders/vescaBuilder.ts → txBuilders/vesca/quick.ts} +85 -274
- package/src/types/address.ts +4 -178
- package/src/types/builder/borrowIncentive.ts +4 -3
- package/src/types/builder/core.ts +6 -33
- package/src/types/builder/index.ts +5 -1
- package/src/types/builder/loyaltyProgram.ts +4 -3
- package/src/types/builder/modules.ts +49 -0
- package/src/types/builder/referral.ts +5 -4
- package/src/types/builder/sCoin.ts +20 -2
- package/src/types/builder/spool.ts +22 -2
- package/src/types/builder/vesca.ts +4 -12
- package/src/types/constant/index.ts +3 -1
- package/src/types/constant/queryKeys.ts +15 -8
- package/src/types/index.ts +5 -6
- package/src/types/internal/dto.ts +46 -0
- package/src/types/internal/index.ts +2 -0
- package/src/types/internal/move.ts +13 -0
- package/src/types/public/index.ts +21 -0
- package/src/types/query/core.ts +0 -317
- package/src/types/query/index.ts +3 -4
- package/src/types/query/portfolio.ts +2 -15
- package/src/types/repositories/borrowIncentive.ts +12 -0
- package/src/types/repositories/index.ts +9 -0
- package/src/types/repositories/loyaltyProgram.ts +2 -0
- package/src/types/repositories/market.ts +13 -0
- package/src/types/repositories/spool.ts +21 -0
- package/src/types/repositories/veSca.ts +5 -0
- package/src/types/repositories/veScaLoyaltyProgram.ts +2 -0
- package/src/types/sui.ts +0 -1
- package/src/utils/array.ts +7 -0
- package/src/utils/cache.ts +17 -0
- package/src/utils/object.ts +30 -12
- package/src/utils/query.ts +9 -190
- package/src/utils/vesca.ts +0 -8
- package/src/builders/borrowIncentiveBuilder.ts +0 -372
- package/src/builders/coreBuilder.ts +0 -636
- package/src/builders/loyaltyProgramBuilder.ts +0 -142
- package/src/builders/referralBuilder.ts +0 -192
- package/src/builders/sCoinBuilder.ts +0 -124
- package/src/index.ts +0 -13
- package/src/models/scallopAddress.ts +0 -841
- package/src/models/scallopAxios.ts +0 -185
- package/src/models/scallopConstants.ts +0 -380
- package/src/models/scallopIndexer.ts +0 -226
- package/src/models/scallopQuery.ts +0 -974
- package/src/models/scallopQueryClient.ts +0 -29
- package/src/models/scallopSuiKit.ts +0 -480
- package/src/models/scallopUtils.ts +0 -734
- package/src/queries/borrowIncentiveQuery.ts +0 -361
- package/src/queries/borrowLimitQuery.ts +0 -33
- package/src/queries/coreQuery.ts +0 -1173
- package/src/queries/flashloanFeeQuery.ts +0 -92
- package/src/queries/index.ts +0 -15
- package/src/queries/isolatedAssetQuery.ts +0 -103
- package/src/queries/loyaltyProgramQuery.ts +0 -178
- package/src/queries/ownerQuery.ts +0 -32
- package/src/queries/poolAddressesQuery.ts +0 -340
- package/src/queries/portfolioQuery.ts +0 -1149
- package/src/queries/priceQuery.ts +0 -37
- package/src/queries/referralQuery.ts +0 -42
- package/src/queries/sCoinQuery.ts +0 -195
- package/src/queries/spoolQuery.ts +0 -542
- package/src/queries/supplyLimitQuery.ts +0 -32
- package/src/queries/switchboardQuery.ts +0 -65
- package/src/queries/vescaQuery.ts +0 -312
- package/src/queries/xOracleQuery.ts +0 -149
- package/src/types/constant/common.ts +0 -55
- package/src/types/query/loyaltyProgram.ts +0 -12
- package/src/types/query/vesca.ts +0 -27
- package/src/utils/index.ts +0 -7
- package/src/utils/indexer.ts +0 -47
- /package/src/{models → datasources}/rateLimiter.ts +0 -0
|
@@ -1,636 +0,0 @@
|
|
|
1
|
-
import { Transaction } from '@mysten/sui/transactions';
|
|
2
|
-
import { SUI_CLOCK_OBJECT_ID } from '@mysten/sui/utils';
|
|
3
|
-
import { SuiTxBlock as SuiKitTxBlock } from '@scallop-io/sui-kit';
|
|
4
|
-
import { getObligations } from '../queries/index.js';
|
|
5
|
-
import { updateOracles } from './oracles/index.js';
|
|
6
|
-
import { requireSender } from '../utils/index.js';
|
|
7
|
-
import type { SuiObjectArg } from '@scallop-io/sui-kit';
|
|
8
|
-
import type { ScallopBuilder } from 'src/models/index.js';
|
|
9
|
-
import type {
|
|
10
|
-
CoreIds,
|
|
11
|
-
GenerateCoreNormalMethod,
|
|
12
|
-
GenerateCoreQuickMethod,
|
|
13
|
-
SuiTxBlockWithCoreNormalMethods,
|
|
14
|
-
CoreTxBlock,
|
|
15
|
-
ScallopTxBlock,
|
|
16
|
-
NestedResult,
|
|
17
|
-
SuiTxBlockWithSpool,
|
|
18
|
-
CoreNormalMethods,
|
|
19
|
-
CoreQuickMethods,
|
|
20
|
-
} from 'src/types/index.js';
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Check and get Obligation information from transaction block.
|
|
24
|
-
*
|
|
25
|
-
* @description
|
|
26
|
-
* If the obligation id is provided, directly return it.
|
|
27
|
-
* If both obligation id and key is provided, directly return them.
|
|
28
|
-
* Otherwise, automatically get obligation id and key from the sender.
|
|
29
|
-
*
|
|
30
|
-
* @param builder - Scallop builder instance.
|
|
31
|
-
* @param txBlock - TxBlock created by SuiKit.
|
|
32
|
-
* @param obligationId - Obligation id.
|
|
33
|
-
* @param obligationKey - Obligation key.
|
|
34
|
-
* @return Obligation id and key.
|
|
35
|
-
*/
|
|
36
|
-
const requireObligationInfo = async (
|
|
37
|
-
...params: [
|
|
38
|
-
builder: ScallopBuilder,
|
|
39
|
-
txBlock: SuiKitTxBlock,
|
|
40
|
-
obligationId?: SuiObjectArg,
|
|
41
|
-
obligationKey?: SuiObjectArg,
|
|
42
|
-
]
|
|
43
|
-
) => {
|
|
44
|
-
const [builder, txBlock, obligationId, obligationKey] = params;
|
|
45
|
-
if (params.length === 3 && obligationId) return { obligationId };
|
|
46
|
-
if (params.length === 4 && obligationId && obligationKey)
|
|
47
|
-
return { obligationId, obligationKey };
|
|
48
|
-
const sender = requireSender(txBlock);
|
|
49
|
-
const obligations = await getObligations(builder, sender);
|
|
50
|
-
if (obligations.length === 0) {
|
|
51
|
-
throw new Error(`No obligation found for sender ${sender}`);
|
|
52
|
-
}
|
|
53
|
-
return {
|
|
54
|
-
obligationId: obligations[0].id,
|
|
55
|
-
obligationKey: obligations[0].keyId,
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Generate core normal methods.
|
|
61
|
-
*
|
|
62
|
-
* @param builder - Scallop builder instance.
|
|
63
|
-
* @param txBlock - TxBlock created by SuiKit.
|
|
64
|
-
* @return Core normal methods.
|
|
65
|
-
*/
|
|
66
|
-
const generateCoreNormalMethod: GenerateCoreNormalMethod = ({
|
|
67
|
-
builder,
|
|
68
|
-
txBlock,
|
|
69
|
-
}) => {
|
|
70
|
-
const coreIds: CoreIds = {
|
|
71
|
-
protocolPkg: builder.address.get('core.packages.protocol.id'),
|
|
72
|
-
market: builder.address.get('core.market'),
|
|
73
|
-
version: builder.address.get('core.version'),
|
|
74
|
-
coinDecimalsRegistry: builder.address.get('core.coinDecimalsRegistry'),
|
|
75
|
-
xOracle: builder.address.get('core.oracles.xOracle'),
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const referralPkgId = builder.address.get('referral.id');
|
|
79
|
-
const referralWitnessType = `${referralPkgId}::scallop_referral_program::REFERRAL_WITNESS`;
|
|
80
|
-
const clockObjectRef = txBlock.sharedObjectRef({
|
|
81
|
-
objectId: SUI_CLOCK_OBJECT_ID,
|
|
82
|
-
mutable: false,
|
|
83
|
-
initialSharedVersion: '1',
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const depositCollateral: CoreNormalMethods['depositCollateral'] = (
|
|
87
|
-
obligation,
|
|
88
|
-
coin,
|
|
89
|
-
collateralCoinName
|
|
90
|
-
) => {
|
|
91
|
-
const coinType = builder.utils.parseCoinType(collateralCoinName);
|
|
92
|
-
builder.moveCall(
|
|
93
|
-
txBlock,
|
|
94
|
-
`${coreIds.protocolPkg}::deposit_collateral::deposit_collateral`,
|
|
95
|
-
[coreIds.version, obligation, coreIds.market, coin],
|
|
96
|
-
[coinType]
|
|
97
|
-
);
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const supply: CoreNormalMethods['supply'] = (coin, poolCoinName) => {
|
|
101
|
-
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
102
|
-
return builder.moveCall(
|
|
103
|
-
txBlock,
|
|
104
|
-
`${coreIds.protocolPkg}::mint::mint`,
|
|
105
|
-
[coreIds.version, coreIds.market, coin, clockObjectRef],
|
|
106
|
-
[coinType]
|
|
107
|
-
);
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
openObligation: () => {
|
|
112
|
-
const [obligation, obligationKey, obligationHotPotato] = builder.moveCall(
|
|
113
|
-
txBlock,
|
|
114
|
-
`${coreIds.protocolPkg}::open_obligation::open_obligation`,
|
|
115
|
-
[coreIds.version]
|
|
116
|
-
);
|
|
117
|
-
return [obligation, obligationKey, obligationHotPotato] as [
|
|
118
|
-
NestedResult,
|
|
119
|
-
NestedResult,
|
|
120
|
-
NestedResult,
|
|
121
|
-
];
|
|
122
|
-
},
|
|
123
|
-
returnObligation: (obligation, obligationHotPotato) => {
|
|
124
|
-
builder.moveCall(
|
|
125
|
-
txBlock,
|
|
126
|
-
`${coreIds.protocolPkg}::open_obligation::return_obligation`,
|
|
127
|
-
[coreIds.version, obligation, obligationHotPotato]
|
|
128
|
-
);
|
|
129
|
-
},
|
|
130
|
-
openObligationEntry: () => {
|
|
131
|
-
builder.moveCall(
|
|
132
|
-
txBlock,
|
|
133
|
-
`${coreIds.protocolPkg}::open_obligation::open_obligation_entry`,
|
|
134
|
-
[coreIds.version]
|
|
135
|
-
);
|
|
136
|
-
},
|
|
137
|
-
/**
|
|
138
|
-
* @deprecated Use {@link depositCollateral} instead.
|
|
139
|
-
*/
|
|
140
|
-
addCollateral: depositCollateral,
|
|
141
|
-
depositCollateral,
|
|
142
|
-
takeCollateral: (obligation, obligationKey, amount, collateralCoinName) => {
|
|
143
|
-
const coinType = builder.utils.parseCoinType(collateralCoinName);
|
|
144
|
-
// return await builder.moveCall(
|
|
145
|
-
return builder.moveCall(
|
|
146
|
-
txBlock,
|
|
147
|
-
`${coreIds.protocolPkg}::withdraw_collateral::withdraw_collateral`,
|
|
148
|
-
[
|
|
149
|
-
coreIds.version,
|
|
150
|
-
obligation,
|
|
151
|
-
obligationKey,
|
|
152
|
-
coreIds.market,
|
|
153
|
-
coreIds.coinDecimalsRegistry,
|
|
154
|
-
txBlock.pure.u64(amount),
|
|
155
|
-
coreIds.xOracle,
|
|
156
|
-
clockObjectRef,
|
|
157
|
-
],
|
|
158
|
-
[coinType]
|
|
159
|
-
);
|
|
160
|
-
},
|
|
161
|
-
/**
|
|
162
|
-
* @deprecated Use {@link supply} instead.
|
|
163
|
-
*/
|
|
164
|
-
deposit: supply,
|
|
165
|
-
supply,
|
|
166
|
-
depositEntry: (coin, poolCoinName) => {
|
|
167
|
-
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
168
|
-
// return await builder.moveCall(
|
|
169
|
-
return builder.moveCall(
|
|
170
|
-
txBlock,
|
|
171
|
-
`${coreIds.protocolPkg}::mint::mint_entry`,
|
|
172
|
-
[coreIds.version, coreIds.market, coin, clockObjectRef],
|
|
173
|
-
[coinType]
|
|
174
|
-
);
|
|
175
|
-
},
|
|
176
|
-
withdraw: (marketCoin, poolCoinName) => {
|
|
177
|
-
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
178
|
-
// return await builder.moveCall(
|
|
179
|
-
return builder.moveCall(
|
|
180
|
-
txBlock,
|
|
181
|
-
`${coreIds.protocolPkg}::redeem::redeem`,
|
|
182
|
-
[coreIds.version, coreIds.market, marketCoin, clockObjectRef],
|
|
183
|
-
[coinType]
|
|
184
|
-
);
|
|
185
|
-
},
|
|
186
|
-
withdrawEntry: (marketCoin, poolCoinName) => {
|
|
187
|
-
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
188
|
-
// return await builder.moveCall(
|
|
189
|
-
return builder.moveCall(
|
|
190
|
-
txBlock,
|
|
191
|
-
`${coreIds.protocolPkg}::redeem::redeem_entry`,
|
|
192
|
-
[coreIds.version, coreIds.market, marketCoin, clockObjectRef],
|
|
193
|
-
[coinType]
|
|
194
|
-
);
|
|
195
|
-
},
|
|
196
|
-
borrow: (obligation, obligationKey, amount, poolCoinName) => {
|
|
197
|
-
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
198
|
-
// return await builder.moveCall(
|
|
199
|
-
return builder.moveCall(
|
|
200
|
-
txBlock,
|
|
201
|
-
`${coreIds.protocolPkg}::borrow::borrow`,
|
|
202
|
-
[
|
|
203
|
-
coreIds.version,
|
|
204
|
-
obligation,
|
|
205
|
-
obligationKey,
|
|
206
|
-
coreIds.market,
|
|
207
|
-
coreIds.coinDecimalsRegistry,
|
|
208
|
-
amount,
|
|
209
|
-
coreIds.xOracle,
|
|
210
|
-
clockObjectRef,
|
|
211
|
-
],
|
|
212
|
-
[coinType]
|
|
213
|
-
);
|
|
214
|
-
},
|
|
215
|
-
borrowWithReferral: (
|
|
216
|
-
obligation,
|
|
217
|
-
obligationKey,
|
|
218
|
-
borrowReferral,
|
|
219
|
-
amount,
|
|
220
|
-
poolCoinName
|
|
221
|
-
) => {
|
|
222
|
-
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
223
|
-
// return await builder.moveCall(
|
|
224
|
-
return builder.moveCall(
|
|
225
|
-
txBlock,
|
|
226
|
-
`${coreIds.protocolPkg}::borrow::borrow_with_referral`,
|
|
227
|
-
[
|
|
228
|
-
coreIds.version,
|
|
229
|
-
obligation,
|
|
230
|
-
obligationKey,
|
|
231
|
-
coreIds.market,
|
|
232
|
-
coreIds.coinDecimalsRegistry,
|
|
233
|
-
borrowReferral,
|
|
234
|
-
typeof amount === 'number' ? txBlock.pure.u64(amount) : amount,
|
|
235
|
-
coreIds.xOracle,
|
|
236
|
-
clockObjectRef,
|
|
237
|
-
],
|
|
238
|
-
[coinType, referralWitnessType]
|
|
239
|
-
);
|
|
240
|
-
},
|
|
241
|
-
borrowEntry: (obligation, obligationKey, amount, poolCoinName) => {
|
|
242
|
-
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
243
|
-
// return await builder.moveCall(
|
|
244
|
-
return builder.moveCall(
|
|
245
|
-
txBlock,
|
|
246
|
-
`${coreIds.protocolPkg}::borrow::borrow_entry`,
|
|
247
|
-
[
|
|
248
|
-
coreIds.version,
|
|
249
|
-
obligation,
|
|
250
|
-
obligationKey,
|
|
251
|
-
coreIds.market,
|
|
252
|
-
coreIds.coinDecimalsRegistry,
|
|
253
|
-
txBlock.pure.u64(amount),
|
|
254
|
-
coreIds.xOracle,
|
|
255
|
-
clockObjectRef,
|
|
256
|
-
],
|
|
257
|
-
[coinType]
|
|
258
|
-
);
|
|
259
|
-
},
|
|
260
|
-
repay: (obligation, coin, poolCoinName) => {
|
|
261
|
-
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
262
|
-
builder.moveCall(
|
|
263
|
-
txBlock,
|
|
264
|
-
`${coreIds.protocolPkg}::repay::repay`,
|
|
265
|
-
[coreIds.version, obligation, coreIds.market, coin, clockObjectRef],
|
|
266
|
-
[coinType]
|
|
267
|
-
);
|
|
268
|
-
},
|
|
269
|
-
borrowFlashLoan: (amount, poolCoinName) => {
|
|
270
|
-
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
271
|
-
return builder.moveCall(
|
|
272
|
-
txBlock,
|
|
273
|
-
`${coreIds.protocolPkg}::flash_loan::borrow_flash_loan`,
|
|
274
|
-
[coreIds.version, coreIds.market, amount],
|
|
275
|
-
[coinType]
|
|
276
|
-
);
|
|
277
|
-
},
|
|
278
|
-
repayFlashLoan: (coin, loan, poolCoinName) => {
|
|
279
|
-
const coinType = builder.utils.parseCoinType(poolCoinName);
|
|
280
|
-
builder.moveCall(
|
|
281
|
-
txBlock,
|
|
282
|
-
`${coreIds.protocolPkg}::flash_loan::repay_flash_loan`,
|
|
283
|
-
[coreIds.version, coreIds.market, coin, loan],
|
|
284
|
-
[coinType]
|
|
285
|
-
);
|
|
286
|
-
},
|
|
287
|
-
liquidate: (obligation, coin, debtCoinName, collateralCoinName) => {
|
|
288
|
-
const debtCoinType = builder.utils.parseCoinType(debtCoinName);
|
|
289
|
-
const collateralCoinType =
|
|
290
|
-
builder.utils.parseCoinType(collateralCoinName);
|
|
291
|
-
const [debtCoin, collateralCoin] = builder.moveCall(
|
|
292
|
-
txBlock,
|
|
293
|
-
`${coreIds.protocolPkg}::liquidate::liquidate`,
|
|
294
|
-
[
|
|
295
|
-
coreIds.version,
|
|
296
|
-
obligation,
|
|
297
|
-
coreIds.market,
|
|
298
|
-
coin,
|
|
299
|
-
coreIds.coinDecimalsRegistry,
|
|
300
|
-
coreIds.xOracle,
|
|
301
|
-
clockObjectRef,
|
|
302
|
-
],
|
|
303
|
-
[debtCoinType, collateralCoinType]
|
|
304
|
-
);
|
|
305
|
-
|
|
306
|
-
return [debtCoin, collateralCoin] as [NestedResult, NestedResult];
|
|
307
|
-
},
|
|
308
|
-
};
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Generate core quick methods.
|
|
313
|
-
*
|
|
314
|
-
* @description
|
|
315
|
-
* The quick methods are the same as the normal methods, but they will automatically
|
|
316
|
-
* help users organize transaction blocks, include query obligation info, and transfer
|
|
317
|
-
* coins to the sender. So, they are all asynchronous methods.
|
|
318
|
-
*
|
|
319
|
-
* @param builder - Scallop builder instance.
|
|
320
|
-
* @param txBlock - TxBlock created by SuiKit.
|
|
321
|
-
* @return Core quick methods.
|
|
322
|
-
*/
|
|
323
|
-
const generateCoreQuickMethod: GenerateCoreQuickMethod = ({
|
|
324
|
-
builder,
|
|
325
|
-
txBlock,
|
|
326
|
-
}) => {
|
|
327
|
-
const supplyQuick: CoreQuickMethods['supplyQuick'] = async (
|
|
328
|
-
amount,
|
|
329
|
-
poolCoinName,
|
|
330
|
-
returnSCoin = true,
|
|
331
|
-
isSponsoredTx = false
|
|
332
|
-
) => {
|
|
333
|
-
const sender = requireSender(txBlock);
|
|
334
|
-
const { leftCoin, takeCoin } = await builder.selectCoin(
|
|
335
|
-
txBlock,
|
|
336
|
-
poolCoinName,
|
|
337
|
-
amount,
|
|
338
|
-
sender,
|
|
339
|
-
isSponsoredTx
|
|
340
|
-
);
|
|
341
|
-
if (leftCoin) {
|
|
342
|
-
txBlock.transferObjects([leftCoin], sender);
|
|
343
|
-
}
|
|
344
|
-
const marketCoinDeposit = txBlock.supply(takeCoin, poolCoinName);
|
|
345
|
-
|
|
346
|
-
// convert to sCoin
|
|
347
|
-
return returnSCoin
|
|
348
|
-
? txBlock.mintSCoin(
|
|
349
|
-
builder.utils.parseMarketCoinName(poolCoinName),
|
|
350
|
-
marketCoinDeposit
|
|
351
|
-
)
|
|
352
|
-
: marketCoinDeposit;
|
|
353
|
-
};
|
|
354
|
-
const depositCollateralQuick: CoreQuickMethods['depositCollateralQuick'] =
|
|
355
|
-
async (amount, collateralCoinName, obligationId, isSponsoredTx = false) => {
|
|
356
|
-
const sender = requireSender(txBlock);
|
|
357
|
-
const { obligationId: obligationArg } = await requireObligationInfo(
|
|
358
|
-
builder,
|
|
359
|
-
txBlock,
|
|
360
|
-
obligationId
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
const { takeCoin, leftCoin } = await builder.selectCoin(
|
|
364
|
-
txBlock,
|
|
365
|
-
collateralCoinName,
|
|
366
|
-
amount,
|
|
367
|
-
sender,
|
|
368
|
-
isSponsoredTx
|
|
369
|
-
);
|
|
370
|
-
|
|
371
|
-
if (leftCoin) {
|
|
372
|
-
txBlock.transferObjects([leftCoin], sender);
|
|
373
|
-
}
|
|
374
|
-
txBlock.depositCollateral(obligationArg, takeCoin, collateralCoinName);
|
|
375
|
-
};
|
|
376
|
-
|
|
377
|
-
return {
|
|
378
|
-
/**
|
|
379
|
-
* @deprecated Use {@link depositCollateralQuick} instead.
|
|
380
|
-
*/
|
|
381
|
-
addCollateralQuick: depositCollateralQuick,
|
|
382
|
-
depositCollateralQuick,
|
|
383
|
-
takeCollateralQuick: async (
|
|
384
|
-
amount,
|
|
385
|
-
collateralCoinName,
|
|
386
|
-
obligationId,
|
|
387
|
-
obligationKey,
|
|
388
|
-
updateOracleOptions
|
|
389
|
-
) => {
|
|
390
|
-
const obligationInfo = await requireObligationInfo(
|
|
391
|
-
builder,
|
|
392
|
-
txBlock,
|
|
393
|
-
obligationId,
|
|
394
|
-
obligationKey
|
|
395
|
-
);
|
|
396
|
-
const updateCoinNames = await builder.utils.getObligationCoinNames(
|
|
397
|
-
obligationInfo.obligationId
|
|
398
|
-
);
|
|
399
|
-
await updateOracles(
|
|
400
|
-
builder,
|
|
401
|
-
txBlock,
|
|
402
|
-
updateCoinNames,
|
|
403
|
-
updateOracleOptions
|
|
404
|
-
);
|
|
405
|
-
return txBlock.takeCollateral(
|
|
406
|
-
obligationInfo.obligationId,
|
|
407
|
-
obligationInfo.obligationKey as SuiObjectArg,
|
|
408
|
-
amount,
|
|
409
|
-
collateralCoinName
|
|
410
|
-
);
|
|
411
|
-
},
|
|
412
|
-
/**
|
|
413
|
-
* @deprecated Use {@link supplyQuick} instead.
|
|
414
|
-
*/
|
|
415
|
-
depositQuick: supplyQuick,
|
|
416
|
-
supplyQuick,
|
|
417
|
-
withdrawQuick: async (amount, poolCoinName) => {
|
|
418
|
-
const sender = requireSender(txBlock);
|
|
419
|
-
const sCoinName = builder.utils.parseSCoinName(poolCoinName);
|
|
420
|
-
if (!sCoinName) throw new Error(`No sCoin for ${poolCoinName}`);
|
|
421
|
-
|
|
422
|
-
// eslint-disable-next-line prefer-const
|
|
423
|
-
let { sCoin, marketCoin } = await builder.selectSCoinOrMarketCoin(
|
|
424
|
-
txBlock,
|
|
425
|
-
sCoinName,
|
|
426
|
-
amount,
|
|
427
|
-
sender
|
|
428
|
-
);
|
|
429
|
-
|
|
430
|
-
if (sCoin) {
|
|
431
|
-
const newMarketCoin = txBlock.burnSCoin(sCoinName, sCoin);
|
|
432
|
-
if (marketCoin) {
|
|
433
|
-
txBlock.mergeCoins(marketCoin, [newMarketCoin]);
|
|
434
|
-
} else {
|
|
435
|
-
marketCoin = newMarketCoin;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
if (!marketCoin) throw new Error(`No market coin for ${poolCoinName}`);
|
|
440
|
-
return txBlock.withdraw(marketCoin, poolCoinName);
|
|
441
|
-
},
|
|
442
|
-
borrowQuick: async (
|
|
443
|
-
amount,
|
|
444
|
-
poolCoinName,
|
|
445
|
-
obligationId,
|
|
446
|
-
obligationKey,
|
|
447
|
-
updateOracleOptions
|
|
448
|
-
) => {
|
|
449
|
-
const obligationInfo = await requireObligationInfo(
|
|
450
|
-
builder,
|
|
451
|
-
txBlock,
|
|
452
|
-
obligationId,
|
|
453
|
-
obligationKey
|
|
454
|
-
);
|
|
455
|
-
const obligationCoinNames =
|
|
456
|
-
(await builder.utils.getObligationCoinNames(
|
|
457
|
-
obligationInfo.obligationId
|
|
458
|
-
)) ?? [];
|
|
459
|
-
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
460
|
-
await updateOracles(
|
|
461
|
-
builder,
|
|
462
|
-
txBlock,
|
|
463
|
-
updateCoinNames,
|
|
464
|
-
updateOracleOptions
|
|
465
|
-
);
|
|
466
|
-
return txBlock.borrow(
|
|
467
|
-
obligationInfo.obligationId,
|
|
468
|
-
obligationInfo.obligationKey as SuiObjectArg,
|
|
469
|
-
amount,
|
|
470
|
-
poolCoinName
|
|
471
|
-
);
|
|
472
|
-
},
|
|
473
|
-
borrowWithReferralQuick: async (
|
|
474
|
-
amount,
|
|
475
|
-
poolCoinName,
|
|
476
|
-
borrowReferral,
|
|
477
|
-
obligationId,
|
|
478
|
-
obligationKey,
|
|
479
|
-
updateOracleOptions
|
|
480
|
-
) => {
|
|
481
|
-
const obligationInfo = await requireObligationInfo(
|
|
482
|
-
builder,
|
|
483
|
-
txBlock,
|
|
484
|
-
obligationId,
|
|
485
|
-
obligationKey
|
|
486
|
-
);
|
|
487
|
-
const obligationCoinNames =
|
|
488
|
-
(await builder.utils.getObligationCoinNames(
|
|
489
|
-
obligationInfo.obligationId
|
|
490
|
-
)) ?? [];
|
|
491
|
-
const updateCoinNames = [...obligationCoinNames, poolCoinName];
|
|
492
|
-
await updateOracles(
|
|
493
|
-
builder,
|
|
494
|
-
txBlock,
|
|
495
|
-
updateCoinNames,
|
|
496
|
-
updateOracleOptions
|
|
497
|
-
);
|
|
498
|
-
return txBlock.borrowWithReferral(
|
|
499
|
-
obligationInfo.obligationId,
|
|
500
|
-
obligationInfo.obligationKey as SuiObjectArg,
|
|
501
|
-
borrowReferral,
|
|
502
|
-
amount,
|
|
503
|
-
poolCoinName
|
|
504
|
-
);
|
|
505
|
-
},
|
|
506
|
-
repayQuick: async (
|
|
507
|
-
amount,
|
|
508
|
-
poolCoinName,
|
|
509
|
-
obligationId,
|
|
510
|
-
isSponsoredTx = false
|
|
511
|
-
) => {
|
|
512
|
-
const sender = requireSender(txBlock);
|
|
513
|
-
const obligationInfo = await requireObligationInfo(
|
|
514
|
-
builder,
|
|
515
|
-
txBlock,
|
|
516
|
-
obligationId
|
|
517
|
-
);
|
|
518
|
-
|
|
519
|
-
const { leftCoin, takeCoin } = await builder.selectCoin(
|
|
520
|
-
txBlock,
|
|
521
|
-
poolCoinName,
|
|
522
|
-
amount,
|
|
523
|
-
sender,
|
|
524
|
-
isSponsoredTx
|
|
525
|
-
);
|
|
526
|
-
if (leftCoin) txBlock.transferObjects([leftCoin], sender);
|
|
527
|
-
return txBlock.repay(obligationInfo.obligationId, takeCoin, poolCoinName);
|
|
528
|
-
},
|
|
529
|
-
updateAssetPricesQuick: async (assetCoinNames, updateOracleOptions) => {
|
|
530
|
-
return await updateOracles(
|
|
531
|
-
builder,
|
|
532
|
-
txBlock,
|
|
533
|
-
assetCoinNames,
|
|
534
|
-
updateOracleOptions
|
|
535
|
-
);
|
|
536
|
-
},
|
|
537
|
-
liquidateQuick: async (
|
|
538
|
-
amount,
|
|
539
|
-
debtCoinName,
|
|
540
|
-
collateralCoinName,
|
|
541
|
-
obligationId,
|
|
542
|
-
updateOracleOptions
|
|
543
|
-
) => {
|
|
544
|
-
const sender = requireSender(txBlock);
|
|
545
|
-
|
|
546
|
-
// Update oracle prices for debt and collateral coins
|
|
547
|
-
const updateCoinNames =
|
|
548
|
-
await builder.utils.getObligationCoinNames(obligationId);
|
|
549
|
-
|
|
550
|
-
await updateOracles(
|
|
551
|
-
builder,
|
|
552
|
-
txBlock,
|
|
553
|
-
updateCoinNames,
|
|
554
|
-
updateOracleOptions
|
|
555
|
-
);
|
|
556
|
-
|
|
557
|
-
// Select coins for liquidation
|
|
558
|
-
const { takeCoin, leftCoin } = await builder.selectCoin(
|
|
559
|
-
txBlock,
|
|
560
|
-
debtCoinName,
|
|
561
|
-
amount,
|
|
562
|
-
sender,
|
|
563
|
-
updateOracleOptions?.isSponsoredTx ?? false
|
|
564
|
-
);
|
|
565
|
-
|
|
566
|
-
if (leftCoin) {
|
|
567
|
-
txBlock.transferObjects([leftCoin], sender);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
// Convert obligation to SharedObjectRef format
|
|
571
|
-
const obligationSharedObject =
|
|
572
|
-
typeof obligationId === 'string'
|
|
573
|
-
? txBlock.object(obligationId)
|
|
574
|
-
: obligationId;
|
|
575
|
-
|
|
576
|
-
// Execute liquidation
|
|
577
|
-
return txBlock.liquidate(
|
|
578
|
-
obligationSharedObject,
|
|
579
|
-
takeCoin,
|
|
580
|
-
debtCoinName,
|
|
581
|
-
collateralCoinName
|
|
582
|
-
);
|
|
583
|
-
},
|
|
584
|
-
};
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
/**
|
|
588
|
-
* Create an enhanced transaction block instance for interaction with core modules of the Scallop contract.
|
|
589
|
-
*
|
|
590
|
-
* @param builder - Scallop builder instance.
|
|
591
|
-
* @param initTxBlock - Scallop txBlock, txBlock created by SuiKit, or original transaction block.
|
|
592
|
-
* @return Scallop core txBlock.
|
|
593
|
-
*/
|
|
594
|
-
export const newCoreTxBlock = (
|
|
595
|
-
builder: ScallopBuilder,
|
|
596
|
-
initTxBlock?:
|
|
597
|
-
| ScallopTxBlock
|
|
598
|
-
| SuiKitTxBlock
|
|
599
|
-
| Transaction
|
|
600
|
-
| SuiTxBlockWithSpool
|
|
601
|
-
) => {
|
|
602
|
-
const txBlock =
|
|
603
|
-
initTxBlock instanceof Transaction
|
|
604
|
-
? new SuiKitTxBlock(initTxBlock)
|
|
605
|
-
: initTxBlock
|
|
606
|
-
? initTxBlock
|
|
607
|
-
: new SuiKitTxBlock();
|
|
608
|
-
|
|
609
|
-
const normalMethod = generateCoreNormalMethod({
|
|
610
|
-
builder,
|
|
611
|
-
txBlock,
|
|
612
|
-
});
|
|
613
|
-
|
|
614
|
-
const normalTxBlock = new Proxy(txBlock, {
|
|
615
|
-
get: (target, prop) => {
|
|
616
|
-
if (prop in normalMethod) {
|
|
617
|
-
return Reflect.get(normalMethod, prop);
|
|
618
|
-
}
|
|
619
|
-
return Reflect.get(target, prop);
|
|
620
|
-
},
|
|
621
|
-
}) as SuiTxBlockWithCoreNormalMethods;
|
|
622
|
-
|
|
623
|
-
const quickMethod = generateCoreQuickMethod({
|
|
624
|
-
builder,
|
|
625
|
-
txBlock: normalTxBlock,
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
return new Proxy(normalTxBlock, {
|
|
629
|
-
get: (target, prop) => {
|
|
630
|
-
if (prop in quickMethod) {
|
|
631
|
-
return Reflect.get(quickMethod, prop);
|
|
632
|
-
}
|
|
633
|
-
return Reflect.get(target, prop);
|
|
634
|
-
},
|
|
635
|
-
}) as CoreTxBlock;
|
|
636
|
-
};
|