@t2000/sdk 0.19.20 → 0.19.22
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/README.md +0 -9
- package/dist/adapters/descriptors.cjs +68 -0
- package/dist/adapters/descriptors.cjs.map +1 -0
- package/dist/adapters/descriptors.d.cts +3 -0
- package/dist/adapters/descriptors.d.ts +3 -0
- package/dist/adapters/descriptors.js +63 -0
- package/dist/adapters/descriptors.js.map +1 -0
- package/dist/adapters/index.cjs +69 -64
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +171 -3
- package/dist/adapters/index.d.ts +171 -3
- package/dist/adapters/index.js +67 -61
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.js +2 -15
- package/dist/browser.js.map +1 -1
- package/dist/{index-DAxuyiS2.d.cts → descriptors-B6qt_mwi.d.cts} +5 -225
- package/dist/{index-DAxuyiS2.d.ts → descriptors-B6qt_mwi.d.ts} +5 -225
- package/dist/index.cjs +86 -291
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +18 -20
- package/dist/index.d.ts +18 -20
- package/dist/index.js +84 -281
- package/dist/index.js.map +1 -1
- package/package.json +11 -6
|
@@ -1,3 +1,171 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import '@mysten/sui/jsonRpc';
|
|
1
|
+
import { L as LendingAdapter, e as SwapAdapter, w as LendingRates, a1 as SwapQuote, z as AdapterPositions, y as AdapterCapability, O as HealthInfo, J as AdapterTxResult, M as MaxWithdrawResult, h as MaxBorrowResult, a6 as PendingReward } from '../descriptors-B6qt_mwi.cjs';
|
|
2
|
+
export { U as PerpsAdapter, $ as ProtocolDescriptor, a2 as allDescriptors, a3 as cetusDescriptor, a4 as naviDescriptor, a5 as suilendDescriptor } from '../descriptors-B6qt_mwi.cjs';
|
|
3
|
+
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
4
|
+
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
5
|
+
|
|
6
|
+
declare class ProtocolRegistry {
|
|
7
|
+
private lending;
|
|
8
|
+
private swap;
|
|
9
|
+
registerLending(adapter: LendingAdapter): void;
|
|
10
|
+
registerSwap(adapter: SwapAdapter): void;
|
|
11
|
+
bestSaveRate(asset: string): Promise<{
|
|
12
|
+
adapter: LendingAdapter;
|
|
13
|
+
rate: LendingRates;
|
|
14
|
+
}>;
|
|
15
|
+
bestBorrowRate(asset: string, opts?: {
|
|
16
|
+
requireSameAssetBorrow?: boolean;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
adapter: LendingAdapter;
|
|
19
|
+
rate: LendingRates;
|
|
20
|
+
}>;
|
|
21
|
+
bestSwapQuote(from: string, to: string, amount: number): Promise<{
|
|
22
|
+
adapter: SwapAdapter;
|
|
23
|
+
quote: SwapQuote;
|
|
24
|
+
}>;
|
|
25
|
+
bestSaveRateAcrossAssets(): Promise<{
|
|
26
|
+
adapter: LendingAdapter;
|
|
27
|
+
rate: LendingRates;
|
|
28
|
+
asset: string;
|
|
29
|
+
}>;
|
|
30
|
+
allRatesAcrossAssets(): Promise<Array<{
|
|
31
|
+
protocol: string;
|
|
32
|
+
protocolId: string;
|
|
33
|
+
asset: string;
|
|
34
|
+
rates: LendingRates;
|
|
35
|
+
}>>;
|
|
36
|
+
allRates(asset: string): Promise<Array<{
|
|
37
|
+
protocol: string;
|
|
38
|
+
protocolId: string;
|
|
39
|
+
rates: LendingRates;
|
|
40
|
+
}>>;
|
|
41
|
+
allPositions(address: string): Promise<Array<{
|
|
42
|
+
protocol: string;
|
|
43
|
+
protocolId: string;
|
|
44
|
+
positions: AdapterPositions;
|
|
45
|
+
}>>;
|
|
46
|
+
getLending(id: string): LendingAdapter | undefined;
|
|
47
|
+
getSwap(id: string): SwapAdapter | undefined;
|
|
48
|
+
listLending(): LendingAdapter[];
|
|
49
|
+
listSwap(): SwapAdapter[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare class NaviAdapter implements LendingAdapter {
|
|
53
|
+
readonly id = "navi";
|
|
54
|
+
readonly name = "NAVI Protocol";
|
|
55
|
+
readonly version = "1.0.0";
|
|
56
|
+
readonly capabilities: readonly AdapterCapability[];
|
|
57
|
+
readonly supportedAssets: readonly string[];
|
|
58
|
+
readonly supportsSameAssetBorrow = true;
|
|
59
|
+
private client;
|
|
60
|
+
init(client: SuiJsonRpcClient): Promise<void>;
|
|
61
|
+
initSync(client: SuiJsonRpcClient): void;
|
|
62
|
+
getRates(asset: string): Promise<LendingRates>;
|
|
63
|
+
getPositions(address: string): Promise<AdapterPositions>;
|
|
64
|
+
getHealth(address: string): Promise<HealthInfo>;
|
|
65
|
+
buildSaveTx(address: string, amount: number, asset: string, options?: {
|
|
66
|
+
collectFee?: boolean;
|
|
67
|
+
sponsored?: boolean;
|
|
68
|
+
}): Promise<AdapterTxResult>;
|
|
69
|
+
buildWithdrawTx(address: string, amount: number, asset: string, options?: {
|
|
70
|
+
sponsored?: boolean;
|
|
71
|
+
}): Promise<AdapterTxResult & {
|
|
72
|
+
effectiveAmount: number;
|
|
73
|
+
}>;
|
|
74
|
+
buildBorrowTx(address: string, amount: number, asset: string, options?: {
|
|
75
|
+
collectFee?: boolean;
|
|
76
|
+
sponsored?: boolean;
|
|
77
|
+
}): Promise<AdapterTxResult>;
|
|
78
|
+
buildRepayTx(address: string, amount: number, asset: string, options?: {
|
|
79
|
+
sponsored?: boolean;
|
|
80
|
+
skipOracle?: boolean;
|
|
81
|
+
}): Promise<AdapterTxResult>;
|
|
82
|
+
maxWithdraw(address: string, _asset: string): Promise<MaxWithdrawResult>;
|
|
83
|
+
maxBorrow(address: string, _asset: string): Promise<MaxBorrowResult>;
|
|
84
|
+
addWithdrawToTx(tx: Transaction, address: string, amount: number, asset: string): Promise<{
|
|
85
|
+
coin: TransactionObjectArgument;
|
|
86
|
+
effectiveAmount: number;
|
|
87
|
+
}>;
|
|
88
|
+
addSaveToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
|
|
89
|
+
collectFee?: boolean;
|
|
90
|
+
}): Promise<void>;
|
|
91
|
+
addRepayToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string): Promise<void>;
|
|
92
|
+
getPendingRewards(address: string): Promise<PendingReward[]>;
|
|
93
|
+
addClaimRewardsToTx(tx: Transaction, address: string): Promise<PendingReward[]>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class CetusAdapter implements SwapAdapter {
|
|
97
|
+
readonly id = "cetus";
|
|
98
|
+
readonly name = "Cetus";
|
|
99
|
+
readonly version = "1.0.0";
|
|
100
|
+
readonly capabilities: readonly AdapterCapability[];
|
|
101
|
+
private client;
|
|
102
|
+
init(client: SuiJsonRpcClient): Promise<void>;
|
|
103
|
+
initSync(client: SuiJsonRpcClient): void;
|
|
104
|
+
getQuote(from: string, to: string, amount: number): Promise<SwapQuote>;
|
|
105
|
+
buildSwapTx(address: string, from: string, to: string, amount: number, maxSlippageBps?: number): Promise<AdapterTxResult & {
|
|
106
|
+
estimatedOut: number;
|
|
107
|
+
toDecimals: number;
|
|
108
|
+
}>;
|
|
109
|
+
getSupportedPairs(): Array<{
|
|
110
|
+
from: string;
|
|
111
|
+
to: string;
|
|
112
|
+
}>;
|
|
113
|
+
getPoolPrice(): Promise<number>;
|
|
114
|
+
addSwapToTx(tx: Transaction, address: string, inputCoin: TransactionObjectArgument, from: string, to: string, amount: number, maxSlippageBps?: number): Promise<{
|
|
115
|
+
outputCoin: TransactionObjectArgument;
|
|
116
|
+
estimatedOut: number;
|
|
117
|
+
toDecimals: number;
|
|
118
|
+
}>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare class SuilendAdapter implements LendingAdapter {
|
|
122
|
+
readonly id = "suilend";
|
|
123
|
+
readonly name = "Suilend";
|
|
124
|
+
readonly version = "3.0.0";
|
|
125
|
+
readonly capabilities: readonly AdapterCapability[];
|
|
126
|
+
readonly supportedAssets: readonly string[];
|
|
127
|
+
readonly supportsSameAssetBorrow = false;
|
|
128
|
+
private client;
|
|
129
|
+
private sdkClient;
|
|
130
|
+
init(client: SuiJsonRpcClient): Promise<void>;
|
|
131
|
+
initSync(client: SuiJsonRpcClient): void;
|
|
132
|
+
private getSdkClient;
|
|
133
|
+
private resolveSymbol;
|
|
134
|
+
getRates(asset: string): Promise<LendingRates>;
|
|
135
|
+
getPositions(address: string): Promise<AdapterPositions>;
|
|
136
|
+
getHealth(address: string): Promise<HealthInfo>;
|
|
137
|
+
buildSaveTx(address: string, amount: number, asset: string, options?: {
|
|
138
|
+
collectFee?: boolean;
|
|
139
|
+
}): Promise<AdapterTxResult>;
|
|
140
|
+
buildWithdrawTx(address: string, amount: number, asset: string): Promise<AdapterTxResult & {
|
|
141
|
+
effectiveAmount: number;
|
|
142
|
+
}>;
|
|
143
|
+
addWithdrawToTx(tx: Transaction, address: string, amount: number, asset: string): Promise<{
|
|
144
|
+
coin: TransactionObjectArgument;
|
|
145
|
+
effectiveAmount: number;
|
|
146
|
+
}>;
|
|
147
|
+
addSaveToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
|
|
148
|
+
collectFee?: boolean;
|
|
149
|
+
}): Promise<void>;
|
|
150
|
+
buildBorrowTx(address: string, amount: number, asset: string, options?: {
|
|
151
|
+
collectFee?: boolean;
|
|
152
|
+
}): Promise<AdapterTxResult>;
|
|
153
|
+
buildRepayTx(address: string, amount: number, asset: string): Promise<AdapterTxResult>;
|
|
154
|
+
addRepayToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string): Promise<void>;
|
|
155
|
+
private resolveWithdrawCTokens;
|
|
156
|
+
maxWithdraw(address: string, _asset: string): Promise<{
|
|
157
|
+
maxAmount: number;
|
|
158
|
+
healthFactorAfter: number;
|
|
159
|
+
currentHF: number;
|
|
160
|
+
}>;
|
|
161
|
+
maxBorrow(address: string, _asset: string): Promise<{
|
|
162
|
+
maxAmount: number;
|
|
163
|
+
healthFactorAfter: number;
|
|
164
|
+
currentHF: number;
|
|
165
|
+
}>;
|
|
166
|
+
private fetchAllCoins;
|
|
167
|
+
getPendingRewards(address: string): Promise<PendingReward[]>;
|
|
168
|
+
addClaimRewardsToTx(tx: Transaction, address: string): Promise<PendingReward[]>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export { AdapterCapability, AdapterPositions, AdapterTxResult, CetusAdapter, HealthInfo, LendingAdapter, LendingRates, NaviAdapter, ProtocolRegistry, SuilendAdapter, SwapAdapter, SwapQuote };
|
package/dist/adapters/index.d.ts
CHANGED
|
@@ -1,3 +1,171 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import '@mysten/sui/jsonRpc';
|
|
1
|
+
import { L as LendingAdapter, e as SwapAdapter, w as LendingRates, a1 as SwapQuote, z as AdapterPositions, y as AdapterCapability, O as HealthInfo, J as AdapterTxResult, M as MaxWithdrawResult, h as MaxBorrowResult, a6 as PendingReward } from '../descriptors-B6qt_mwi.js';
|
|
2
|
+
export { U as PerpsAdapter, $ as ProtocolDescriptor, a2 as allDescriptors, a3 as cetusDescriptor, a4 as naviDescriptor, a5 as suilendDescriptor } from '../descriptors-B6qt_mwi.js';
|
|
3
|
+
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
4
|
+
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
5
|
+
|
|
6
|
+
declare class ProtocolRegistry {
|
|
7
|
+
private lending;
|
|
8
|
+
private swap;
|
|
9
|
+
registerLending(adapter: LendingAdapter): void;
|
|
10
|
+
registerSwap(adapter: SwapAdapter): void;
|
|
11
|
+
bestSaveRate(asset: string): Promise<{
|
|
12
|
+
adapter: LendingAdapter;
|
|
13
|
+
rate: LendingRates;
|
|
14
|
+
}>;
|
|
15
|
+
bestBorrowRate(asset: string, opts?: {
|
|
16
|
+
requireSameAssetBorrow?: boolean;
|
|
17
|
+
}): Promise<{
|
|
18
|
+
adapter: LendingAdapter;
|
|
19
|
+
rate: LendingRates;
|
|
20
|
+
}>;
|
|
21
|
+
bestSwapQuote(from: string, to: string, amount: number): Promise<{
|
|
22
|
+
adapter: SwapAdapter;
|
|
23
|
+
quote: SwapQuote;
|
|
24
|
+
}>;
|
|
25
|
+
bestSaveRateAcrossAssets(): Promise<{
|
|
26
|
+
adapter: LendingAdapter;
|
|
27
|
+
rate: LendingRates;
|
|
28
|
+
asset: string;
|
|
29
|
+
}>;
|
|
30
|
+
allRatesAcrossAssets(): Promise<Array<{
|
|
31
|
+
protocol: string;
|
|
32
|
+
protocolId: string;
|
|
33
|
+
asset: string;
|
|
34
|
+
rates: LendingRates;
|
|
35
|
+
}>>;
|
|
36
|
+
allRates(asset: string): Promise<Array<{
|
|
37
|
+
protocol: string;
|
|
38
|
+
protocolId: string;
|
|
39
|
+
rates: LendingRates;
|
|
40
|
+
}>>;
|
|
41
|
+
allPositions(address: string): Promise<Array<{
|
|
42
|
+
protocol: string;
|
|
43
|
+
protocolId: string;
|
|
44
|
+
positions: AdapterPositions;
|
|
45
|
+
}>>;
|
|
46
|
+
getLending(id: string): LendingAdapter | undefined;
|
|
47
|
+
getSwap(id: string): SwapAdapter | undefined;
|
|
48
|
+
listLending(): LendingAdapter[];
|
|
49
|
+
listSwap(): SwapAdapter[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
declare class NaviAdapter implements LendingAdapter {
|
|
53
|
+
readonly id = "navi";
|
|
54
|
+
readonly name = "NAVI Protocol";
|
|
55
|
+
readonly version = "1.0.0";
|
|
56
|
+
readonly capabilities: readonly AdapterCapability[];
|
|
57
|
+
readonly supportedAssets: readonly string[];
|
|
58
|
+
readonly supportsSameAssetBorrow = true;
|
|
59
|
+
private client;
|
|
60
|
+
init(client: SuiJsonRpcClient): Promise<void>;
|
|
61
|
+
initSync(client: SuiJsonRpcClient): void;
|
|
62
|
+
getRates(asset: string): Promise<LendingRates>;
|
|
63
|
+
getPositions(address: string): Promise<AdapterPositions>;
|
|
64
|
+
getHealth(address: string): Promise<HealthInfo>;
|
|
65
|
+
buildSaveTx(address: string, amount: number, asset: string, options?: {
|
|
66
|
+
collectFee?: boolean;
|
|
67
|
+
sponsored?: boolean;
|
|
68
|
+
}): Promise<AdapterTxResult>;
|
|
69
|
+
buildWithdrawTx(address: string, amount: number, asset: string, options?: {
|
|
70
|
+
sponsored?: boolean;
|
|
71
|
+
}): Promise<AdapterTxResult & {
|
|
72
|
+
effectiveAmount: number;
|
|
73
|
+
}>;
|
|
74
|
+
buildBorrowTx(address: string, amount: number, asset: string, options?: {
|
|
75
|
+
collectFee?: boolean;
|
|
76
|
+
sponsored?: boolean;
|
|
77
|
+
}): Promise<AdapterTxResult>;
|
|
78
|
+
buildRepayTx(address: string, amount: number, asset: string, options?: {
|
|
79
|
+
sponsored?: boolean;
|
|
80
|
+
skipOracle?: boolean;
|
|
81
|
+
}): Promise<AdapterTxResult>;
|
|
82
|
+
maxWithdraw(address: string, _asset: string): Promise<MaxWithdrawResult>;
|
|
83
|
+
maxBorrow(address: string, _asset: string): Promise<MaxBorrowResult>;
|
|
84
|
+
addWithdrawToTx(tx: Transaction, address: string, amount: number, asset: string): Promise<{
|
|
85
|
+
coin: TransactionObjectArgument;
|
|
86
|
+
effectiveAmount: number;
|
|
87
|
+
}>;
|
|
88
|
+
addSaveToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
|
|
89
|
+
collectFee?: boolean;
|
|
90
|
+
}): Promise<void>;
|
|
91
|
+
addRepayToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string): Promise<void>;
|
|
92
|
+
getPendingRewards(address: string): Promise<PendingReward[]>;
|
|
93
|
+
addClaimRewardsToTx(tx: Transaction, address: string): Promise<PendingReward[]>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class CetusAdapter implements SwapAdapter {
|
|
97
|
+
readonly id = "cetus";
|
|
98
|
+
readonly name = "Cetus";
|
|
99
|
+
readonly version = "1.0.0";
|
|
100
|
+
readonly capabilities: readonly AdapterCapability[];
|
|
101
|
+
private client;
|
|
102
|
+
init(client: SuiJsonRpcClient): Promise<void>;
|
|
103
|
+
initSync(client: SuiJsonRpcClient): void;
|
|
104
|
+
getQuote(from: string, to: string, amount: number): Promise<SwapQuote>;
|
|
105
|
+
buildSwapTx(address: string, from: string, to: string, amount: number, maxSlippageBps?: number): Promise<AdapterTxResult & {
|
|
106
|
+
estimatedOut: number;
|
|
107
|
+
toDecimals: number;
|
|
108
|
+
}>;
|
|
109
|
+
getSupportedPairs(): Array<{
|
|
110
|
+
from: string;
|
|
111
|
+
to: string;
|
|
112
|
+
}>;
|
|
113
|
+
getPoolPrice(): Promise<number>;
|
|
114
|
+
addSwapToTx(tx: Transaction, address: string, inputCoin: TransactionObjectArgument, from: string, to: string, amount: number, maxSlippageBps?: number): Promise<{
|
|
115
|
+
outputCoin: TransactionObjectArgument;
|
|
116
|
+
estimatedOut: number;
|
|
117
|
+
toDecimals: number;
|
|
118
|
+
}>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declare class SuilendAdapter implements LendingAdapter {
|
|
122
|
+
readonly id = "suilend";
|
|
123
|
+
readonly name = "Suilend";
|
|
124
|
+
readonly version = "3.0.0";
|
|
125
|
+
readonly capabilities: readonly AdapterCapability[];
|
|
126
|
+
readonly supportedAssets: readonly string[];
|
|
127
|
+
readonly supportsSameAssetBorrow = false;
|
|
128
|
+
private client;
|
|
129
|
+
private sdkClient;
|
|
130
|
+
init(client: SuiJsonRpcClient): Promise<void>;
|
|
131
|
+
initSync(client: SuiJsonRpcClient): void;
|
|
132
|
+
private getSdkClient;
|
|
133
|
+
private resolveSymbol;
|
|
134
|
+
getRates(asset: string): Promise<LendingRates>;
|
|
135
|
+
getPositions(address: string): Promise<AdapterPositions>;
|
|
136
|
+
getHealth(address: string): Promise<HealthInfo>;
|
|
137
|
+
buildSaveTx(address: string, amount: number, asset: string, options?: {
|
|
138
|
+
collectFee?: boolean;
|
|
139
|
+
}): Promise<AdapterTxResult>;
|
|
140
|
+
buildWithdrawTx(address: string, amount: number, asset: string): Promise<AdapterTxResult & {
|
|
141
|
+
effectiveAmount: number;
|
|
142
|
+
}>;
|
|
143
|
+
addWithdrawToTx(tx: Transaction, address: string, amount: number, asset: string): Promise<{
|
|
144
|
+
coin: TransactionObjectArgument;
|
|
145
|
+
effectiveAmount: number;
|
|
146
|
+
}>;
|
|
147
|
+
addSaveToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string, options?: {
|
|
148
|
+
collectFee?: boolean;
|
|
149
|
+
}): Promise<void>;
|
|
150
|
+
buildBorrowTx(address: string, amount: number, asset: string, options?: {
|
|
151
|
+
collectFee?: boolean;
|
|
152
|
+
}): Promise<AdapterTxResult>;
|
|
153
|
+
buildRepayTx(address: string, amount: number, asset: string): Promise<AdapterTxResult>;
|
|
154
|
+
addRepayToTx(tx: Transaction, address: string, coin: TransactionObjectArgument, asset: string): Promise<void>;
|
|
155
|
+
private resolveWithdrawCTokens;
|
|
156
|
+
maxWithdraw(address: string, _asset: string): Promise<{
|
|
157
|
+
maxAmount: number;
|
|
158
|
+
healthFactorAfter: number;
|
|
159
|
+
currentHF: number;
|
|
160
|
+
}>;
|
|
161
|
+
maxBorrow(address: string, _asset: string): Promise<{
|
|
162
|
+
maxAmount: number;
|
|
163
|
+
healthFactorAfter: number;
|
|
164
|
+
currentHF: number;
|
|
165
|
+
}>;
|
|
166
|
+
private fetchAllCoins;
|
|
167
|
+
getPendingRewards(address: string): Promise<PendingReward[]>;
|
|
168
|
+
addClaimRewardsToTx(tx: Transaction, address: string): Promise<PendingReward[]>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export { AdapterCapability, AdapterPositions, AdapterTxResult, CetusAdapter, HealthInfo, LendingAdapter, LendingRates, NaviAdapter, ProtocolRegistry, SuilendAdapter, SwapAdapter, SwapQuote };
|
package/dist/adapters/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import { normalizeStructTag } from '@mysten/sui/utils';
|
|
|
5
5
|
import { SuilendClient, LENDING_MARKET_ID, LENDING_MARKET_TYPE } from '@suilend/sdk/client';
|
|
6
6
|
import { initializeSuilend, initializeObligations } from '@suilend/sdk/lib/initialize';
|
|
7
7
|
import { Side } from '@suilend/sdk/lib/types';
|
|
8
|
-
import '@mysten/sui/bcs';
|
|
9
8
|
|
|
10
9
|
// src/constants.ts
|
|
11
10
|
var SAVE_FEE_BPS = 10n;
|
|
@@ -74,8 +73,6 @@ var INVESTMENT_ASSETS = {
|
|
|
74
73
|
ETH: SUPPORTED_ASSETS.ETH,
|
|
75
74
|
GOLD: SUPPORTED_ASSETS.GOLD
|
|
76
75
|
};
|
|
77
|
-
var SENTINEL = {
|
|
78
|
-
PACKAGE: "0x88b83f36dafcd5f6dcdcf1d2cb5889b03f61264ab3cee9cae35db7aa940a21b7"};
|
|
79
76
|
|
|
80
77
|
// src/errors.ts
|
|
81
78
|
var T2000Error = class extends Error {
|
|
@@ -292,6 +289,7 @@ function sdkOptions(client) {
|
|
|
292
289
|
return { env: "prod", client, cacheTime: 0, disableCache: true };
|
|
293
290
|
}
|
|
294
291
|
async function refreshOracle(tx, client, address, options) {
|
|
292
|
+
if (options?.skipOracle) return;
|
|
295
293
|
const origInfo = console.info;
|
|
296
294
|
const origWarn = console.warn;
|
|
297
295
|
console.info = (...args) => {
|
|
@@ -459,13 +457,14 @@ async function buildSaveTx(client, address, amount, options = {}) {
|
|
|
459
457
|
const assetInfo = resolveAssetInfo(asset);
|
|
460
458
|
const coins = await fetchCoins(client, address, assetInfo.type);
|
|
461
459
|
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins found`);
|
|
460
|
+
const totalBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
|
|
462
461
|
const tx = new Transaction();
|
|
463
462
|
tx.setSender(address);
|
|
464
463
|
const coinObj = mergeCoins(tx, coins);
|
|
465
464
|
if (options.collectFee) {
|
|
466
465
|
addCollectFeeToTx(tx, coinObj, "save");
|
|
467
466
|
}
|
|
468
|
-
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
467
|
+
const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
|
|
469
468
|
try {
|
|
470
469
|
await depositCoinPTB(tx, assetInfo.type, coinObj, {
|
|
471
470
|
...sdkOptions(client),
|
|
@@ -506,6 +505,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
506
505
|
}
|
|
507
506
|
async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
508
507
|
const asset = options.asset ?? "USDC";
|
|
508
|
+
const sponsored = options.sponsored ?? true;
|
|
509
509
|
const assetInfo = resolveAssetInfo(asset);
|
|
510
510
|
const posResult = await getPositions(client, address);
|
|
511
511
|
const supply = posResult.positions.find(
|
|
@@ -523,7 +523,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
523
523
|
});
|
|
524
524
|
return { coin, effectiveAmount: 0 };
|
|
525
525
|
}
|
|
526
|
-
await refreshOracle(tx, client, address);
|
|
526
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
|
|
527
527
|
try {
|
|
528
528
|
const coin = await withdrawCoinPTB(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
529
529
|
return { coin, effectiveAmount };
|
|
@@ -547,8 +547,9 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
|
|
|
547
547
|
}
|
|
548
548
|
async function addRepayToTx(tx, client, address, coin, options = {}) {
|
|
549
549
|
const asset = options.asset ?? "USDC";
|
|
550
|
+
const sponsored = options.sponsored ?? true;
|
|
550
551
|
const assetInfo = resolveAssetInfo(asset);
|
|
551
|
-
await refreshOracle(tx, client, address);
|
|
552
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
|
|
552
553
|
try {
|
|
553
554
|
await repayCoinPTB(tx, assetInfo.type, coin, { env: "prod" });
|
|
554
555
|
} catch (err) {
|
|
@@ -586,12 +587,16 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
586
587
|
const assetInfo = resolveAssetInfo(asset);
|
|
587
588
|
const coins = await fetchCoins(client, address, assetInfo.type);
|
|
588
589
|
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with`);
|
|
590
|
+
const totalBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
|
|
589
591
|
const tx = new Transaction();
|
|
590
592
|
tx.setSender(address);
|
|
591
593
|
const coinObj = mergeCoins(tx, coins);
|
|
592
|
-
const rawAmount = Number(stableToRaw(amount, assetInfo.decimals));
|
|
594
|
+
const rawAmount = Math.min(Number(stableToRaw(amount, assetInfo.decimals)), Number(totalBalance));
|
|
593
595
|
const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
|
|
594
|
-
await refreshOracle(tx, client, address, {
|
|
596
|
+
await refreshOracle(tx, client, address, {
|
|
597
|
+
skipPythUpdate: options.sponsored,
|
|
598
|
+
skipOracle: options.skipOracle
|
|
599
|
+
});
|
|
595
600
|
try {
|
|
596
601
|
await repayCoinPTB(tx, assetInfo.type, repayCoin, {
|
|
597
602
|
...sdkOptions(client),
|
|
@@ -679,8 +684,9 @@ async function addClaimRewardsToTx(tx, client, address) {
|
|
|
679
684
|
}
|
|
680
685
|
}
|
|
681
686
|
|
|
682
|
-
// src/adapters/
|
|
683
|
-
var
|
|
687
|
+
// src/adapters/descriptors.ts
|
|
688
|
+
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
689
|
+
var naviDescriptor = {
|
|
684
690
|
id: "navi",
|
|
685
691
|
name: "NAVI Protocol",
|
|
686
692
|
packages: [],
|
|
@@ -696,6 +702,42 @@ var descriptor = {
|
|
|
696
702
|
"incentive_v3::repay": "repay"
|
|
697
703
|
}
|
|
698
704
|
};
|
|
705
|
+
var suilendDescriptor = {
|
|
706
|
+
id: "suilend",
|
|
707
|
+
name: "Suilend",
|
|
708
|
+
packages: [SUILEND_PACKAGE],
|
|
709
|
+
actionMap: {
|
|
710
|
+
"lending_market::deposit_liquidity_and_mint_ctokens": "save",
|
|
711
|
+
"lending_market::deposit_ctokens_into_obligation": "save",
|
|
712
|
+
"lending_market::create_obligation": "save",
|
|
713
|
+
"lending_market::withdraw_ctokens": "withdraw",
|
|
714
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
|
|
715
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
|
|
716
|
+
"lending_market::fulfill_liquidity_request": "withdraw",
|
|
717
|
+
"lending_market::unstake_sui_from_staker": "withdraw",
|
|
718
|
+
"lending_market::borrow": "borrow",
|
|
719
|
+
"lending_market::repay": "repay"
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
var cetusDescriptor = {
|
|
723
|
+
id: "cetus",
|
|
724
|
+
name: "Cetus DEX",
|
|
725
|
+
packages: [CETUS_PACKAGE],
|
|
726
|
+
actionMap: {
|
|
727
|
+
"router::swap": "swap",
|
|
728
|
+
"router::swap_ab_bc": "swap",
|
|
729
|
+
"router::swap_ab_cb": "swap",
|
|
730
|
+
"router::swap_ba_bc": "swap",
|
|
731
|
+
"router::swap_ba_cb": "swap"
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
var allDescriptors = [
|
|
735
|
+
naviDescriptor,
|
|
736
|
+
suilendDescriptor,
|
|
737
|
+
cetusDescriptor
|
|
738
|
+
];
|
|
739
|
+
|
|
740
|
+
// src/adapters/navi.ts
|
|
699
741
|
var NaviAdapter = class {
|
|
700
742
|
id = "navi";
|
|
701
743
|
name = "NAVI Protocol";
|
|
@@ -744,7 +786,11 @@ var NaviAdapter = class {
|
|
|
744
786
|
}
|
|
745
787
|
async buildRepayTx(address, amount, asset, options) {
|
|
746
788
|
const normalized = normalizeAsset(asset);
|
|
747
|
-
const tx = await buildRepayTx(this.client, address, amount, {
|
|
789
|
+
const tx = await buildRepayTx(this.client, address, amount, {
|
|
790
|
+
asset: normalized,
|
|
791
|
+
sponsored: options?.sponsored,
|
|
792
|
+
skipOracle: options?.skipOracle
|
|
793
|
+
});
|
|
748
794
|
return { tx };
|
|
749
795
|
}
|
|
750
796
|
async maxWithdraw(address, _asset) {
|
|
@@ -932,18 +978,6 @@ function fallbackQuote(fromAsset, amount, poolPrice) {
|
|
|
932
978
|
}
|
|
933
979
|
|
|
934
980
|
// src/adapters/cetus.ts
|
|
935
|
-
var descriptor2 = {
|
|
936
|
-
id: "cetus",
|
|
937
|
-
name: "Cetus DEX",
|
|
938
|
-
packages: [CETUS_PACKAGE],
|
|
939
|
-
actionMap: {
|
|
940
|
-
"router::swap": "swap",
|
|
941
|
-
"router::swap_ab_bc": "swap",
|
|
942
|
-
"router::swap_ab_cb": "swap",
|
|
943
|
-
"router::swap_ba_bc": "swap",
|
|
944
|
-
"router::swap_ba_cb": "swap"
|
|
945
|
-
}
|
|
946
|
-
};
|
|
947
981
|
var CetusAdapter = class {
|
|
948
982
|
id = "cetus";
|
|
949
983
|
name = "Cetus";
|
|
@@ -1002,7 +1036,6 @@ var CetusAdapter = class {
|
|
|
1002
1036
|
});
|
|
1003
1037
|
}
|
|
1004
1038
|
};
|
|
1005
|
-
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
1006
1039
|
var MIN_HEALTH_FACTOR2 = 1.5;
|
|
1007
1040
|
async function quietSuilend(fn) {
|
|
1008
1041
|
const origLog = console.log;
|
|
@@ -1019,23 +1052,6 @@ async function quietSuilend(fn) {
|
|
|
1019
1052
|
console.warn = origWarn;
|
|
1020
1053
|
});
|
|
1021
1054
|
}
|
|
1022
|
-
var descriptor3 = {
|
|
1023
|
-
id: "suilend",
|
|
1024
|
-
name: "Suilend",
|
|
1025
|
-
packages: [SUILEND_PACKAGE],
|
|
1026
|
-
actionMap: {
|
|
1027
|
-
"lending_market::deposit_liquidity_and_mint_ctokens": "save",
|
|
1028
|
-
"lending_market::deposit_ctokens_into_obligation": "save",
|
|
1029
|
-
"lending_market::create_obligation": "save",
|
|
1030
|
-
"lending_market::withdraw_ctokens": "withdraw",
|
|
1031
|
-
"lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
|
|
1032
|
-
"lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
|
|
1033
|
-
"lending_market::fulfill_liquidity_request": "withdraw",
|
|
1034
|
-
"lending_market::unstake_sui_from_staker": "withdraw",
|
|
1035
|
-
"lending_market::borrow": "borrow",
|
|
1036
|
-
"lending_market::repay": "repay"
|
|
1037
|
-
}
|
|
1038
|
-
};
|
|
1039
1055
|
var SuilendAdapter = class {
|
|
1040
1056
|
id = "suilend";
|
|
1041
1057
|
name = "Suilend";
|
|
@@ -1378,16 +1394,23 @@ var SuilendAdapter = class {
|
|
|
1378
1394
|
if (obligationOwnerCaps.length === 0 || obligations.length === 0) return [];
|
|
1379
1395
|
const ob = obligations[0];
|
|
1380
1396
|
const rewards = [];
|
|
1397
|
+
const WAD = 1e18;
|
|
1381
1398
|
for (const dep of ob.deposits) {
|
|
1382
|
-
|
|
1399
|
+
const urm = dep.userRewardManager;
|
|
1400
|
+
for (const rw of dep.reserve.depositsPoolRewardManager?.poolRewards ?? []) {
|
|
1383
1401
|
if (rw.endTimeMs <= Date.now()) continue;
|
|
1402
|
+
let claimableAmount = 0;
|
|
1403
|
+
const userReward = urm?.rewards?.[rw.rewardIndex];
|
|
1404
|
+
if (userReward?.earnedRewards) {
|
|
1405
|
+
claimableAmount = Number(BigInt(userReward.earnedRewards.value.toString())) / WAD / 10 ** rw.mintDecimals;
|
|
1406
|
+
}
|
|
1384
1407
|
const symbol = rw.symbol || rw.coinType.split("::").pop() || "UNKNOWN";
|
|
1385
1408
|
rewards.push({
|
|
1386
1409
|
protocol: "suilend",
|
|
1387
1410
|
asset: this.resolveSymbol(dep.coinType),
|
|
1388
1411
|
coinType: rw.coinType,
|
|
1389
1412
|
symbol,
|
|
1390
|
-
amount:
|
|
1413
|
+
amount: claimableAmount,
|
|
1391
1414
|
estimatedValueUsd: 0
|
|
1392
1415
|
});
|
|
1393
1416
|
}
|
|
@@ -1439,24 +1462,7 @@ var SuilendAdapter = class {
|
|
|
1439
1462
|
}
|
|
1440
1463
|
}
|
|
1441
1464
|
};
|
|
1442
|
-
var descriptor4 = {
|
|
1443
|
-
id: "sentinel",
|
|
1444
|
-
name: "Sui Sentinel",
|
|
1445
|
-
packages: [SENTINEL.PACKAGE],
|
|
1446
|
-
actionMap: {
|
|
1447
|
-
"sentinel::request_attack": "sentinel_attack",
|
|
1448
|
-
"sentinel::consume_prompt": "sentinel_settle"
|
|
1449
|
-
}
|
|
1450
|
-
};
|
|
1451
|
-
|
|
1452
|
-
// src/adapters/index.ts
|
|
1453
|
-
var allDescriptors = [
|
|
1454
|
-
descriptor,
|
|
1455
|
-
descriptor3,
|
|
1456
|
-
descriptor2,
|
|
1457
|
-
descriptor4
|
|
1458
|
-
];
|
|
1459
1465
|
|
|
1460
|
-
export { CetusAdapter, NaviAdapter, ProtocolRegistry, SuilendAdapter, allDescriptors,
|
|
1466
|
+
export { CetusAdapter, NaviAdapter, ProtocolRegistry, SuilendAdapter, allDescriptors, cetusDescriptor, naviDescriptor, suilendDescriptor };
|
|
1461
1467
|
//# sourceMappingURL=index.js.map
|
|
1462
1468
|
//# sourceMappingURL=index.js.map
|