@t2000/sdk 0.19.21 → 0.19.23
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 +52 -60
- 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 +50 -57
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.js +4 -15
- package/dist/browser.js.map +1 -1
- package/dist/{index-CRyFiIZm.d.cts → descriptors-B6qt_mwi.d.cts} +4 -226
- package/dist/{index-CRyFiIZm.d.ts → descriptors-B6qt_mwi.d.ts} +4 -226
- package/dist/index.cjs +86 -282
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -20
- package/dist/index.d.ts +19 -20
- package/dist/index.js +84 -272
- package/dist/index.js.map +1 -1
- package/package.json +7 -2
|
@@ -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 {
|
|
@@ -508,6 +505,7 @@ async function buildWithdrawTx(client, address, amount, options = {}) {
|
|
|
508
505
|
}
|
|
509
506
|
async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
510
507
|
const asset = options.asset ?? "USDC";
|
|
508
|
+
const sponsored = options.sponsored ?? true;
|
|
511
509
|
const assetInfo = resolveAssetInfo(asset);
|
|
512
510
|
const posResult = await getPositions(client, address);
|
|
513
511
|
const supply = posResult.positions.find(
|
|
@@ -525,7 +523,7 @@ async function addWithdrawToTx(tx, client, address, amount, options = {}) {
|
|
|
525
523
|
});
|
|
526
524
|
return { coin, effectiveAmount: 0 };
|
|
527
525
|
}
|
|
528
|
-
await refreshOracle(tx, client, address);
|
|
526
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
|
|
529
527
|
try {
|
|
530
528
|
const coin = await withdrawCoinPTB(tx, assetInfo.type, rawAmount, sdkOptions(client));
|
|
531
529
|
return { coin, effectiveAmount };
|
|
@@ -549,8 +547,9 @@ async function addSaveToTx(tx, _client, _address, coin, options = {}) {
|
|
|
549
547
|
}
|
|
550
548
|
async function addRepayToTx(tx, client, address, coin, options = {}) {
|
|
551
549
|
const asset = options.asset ?? "USDC";
|
|
550
|
+
const sponsored = options.sponsored ?? true;
|
|
552
551
|
const assetInfo = resolveAssetInfo(asset);
|
|
553
|
-
await refreshOracle(tx, client, address);
|
|
552
|
+
await refreshOracle(tx, client, address, { skipPythUpdate: sponsored });
|
|
554
553
|
try {
|
|
555
554
|
await repayCoinPTB(tx, assetInfo.type, coin, { env: "prod" });
|
|
556
555
|
} catch (err) {
|
|
@@ -587,12 +586,16 @@ async function buildRepayTx(client, address, amount, options = {}) {
|
|
|
587
586
|
const asset = options.asset ?? "USDC";
|
|
588
587
|
const assetInfo = resolveAssetInfo(asset);
|
|
589
588
|
const coins = await fetchCoins(client, address, assetInfo.type);
|
|
590
|
-
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with
|
|
589
|
+
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", `No ${assetInfo.displayName} coins to repay with. Withdraw some savings first to get cash.`);
|
|
591
590
|
const totalBalance = coins.reduce((sum, c) => sum + BigInt(c.balance), 0n);
|
|
591
|
+
const rawRequested = Number(stableToRaw(amount, assetInfo.decimals));
|
|
592
|
+
if (Number(totalBalance) < rawRequested && Number(totalBalance) < 1e3) {
|
|
593
|
+
throw new T2000Error("INSUFFICIENT_BALANCE", `Not enough ${assetInfo.displayName} to repay (need $${amount.toFixed(2)}, wallet has ~$${(Number(totalBalance) / 10 ** assetInfo.decimals).toFixed(4)}). Withdraw some savings first.`);
|
|
594
|
+
}
|
|
592
595
|
const tx = new Transaction();
|
|
593
596
|
tx.setSender(address);
|
|
594
597
|
const coinObj = mergeCoins(tx, coins);
|
|
595
|
-
const rawAmount = Math.min(
|
|
598
|
+
const rawAmount = Math.min(rawRequested, Number(totalBalance));
|
|
596
599
|
const [repayCoin] = tx.splitCoins(coinObj, [rawAmount]);
|
|
597
600
|
await refreshOracle(tx, client, address, {
|
|
598
601
|
skipPythUpdate: options.sponsored,
|
|
@@ -685,8 +688,9 @@ async function addClaimRewardsToTx(tx, client, address) {
|
|
|
685
688
|
}
|
|
686
689
|
}
|
|
687
690
|
|
|
688
|
-
// src/adapters/
|
|
689
|
-
var
|
|
691
|
+
// src/adapters/descriptors.ts
|
|
692
|
+
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
693
|
+
var naviDescriptor = {
|
|
690
694
|
id: "navi",
|
|
691
695
|
name: "NAVI Protocol",
|
|
692
696
|
packages: [],
|
|
@@ -702,6 +706,42 @@ var descriptor = {
|
|
|
702
706
|
"incentive_v3::repay": "repay"
|
|
703
707
|
}
|
|
704
708
|
};
|
|
709
|
+
var suilendDescriptor = {
|
|
710
|
+
id: "suilend",
|
|
711
|
+
name: "Suilend",
|
|
712
|
+
packages: [SUILEND_PACKAGE],
|
|
713
|
+
actionMap: {
|
|
714
|
+
"lending_market::deposit_liquidity_and_mint_ctokens": "save",
|
|
715
|
+
"lending_market::deposit_ctokens_into_obligation": "save",
|
|
716
|
+
"lending_market::create_obligation": "save",
|
|
717
|
+
"lending_market::withdraw_ctokens": "withdraw",
|
|
718
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
|
|
719
|
+
"lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
|
|
720
|
+
"lending_market::fulfill_liquidity_request": "withdraw",
|
|
721
|
+
"lending_market::unstake_sui_from_staker": "withdraw",
|
|
722
|
+
"lending_market::borrow": "borrow",
|
|
723
|
+
"lending_market::repay": "repay"
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
var cetusDescriptor = {
|
|
727
|
+
id: "cetus",
|
|
728
|
+
name: "Cetus DEX",
|
|
729
|
+
packages: [CETUS_PACKAGE],
|
|
730
|
+
actionMap: {
|
|
731
|
+
"router::swap": "swap",
|
|
732
|
+
"router::swap_ab_bc": "swap",
|
|
733
|
+
"router::swap_ab_cb": "swap",
|
|
734
|
+
"router::swap_ba_bc": "swap",
|
|
735
|
+
"router::swap_ba_cb": "swap"
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
var allDescriptors = [
|
|
739
|
+
naviDescriptor,
|
|
740
|
+
suilendDescriptor,
|
|
741
|
+
cetusDescriptor
|
|
742
|
+
];
|
|
743
|
+
|
|
744
|
+
// src/adapters/navi.ts
|
|
705
745
|
var NaviAdapter = class {
|
|
706
746
|
id = "navi";
|
|
707
747
|
name = "NAVI Protocol";
|
|
@@ -942,18 +982,6 @@ function fallbackQuote(fromAsset, amount, poolPrice) {
|
|
|
942
982
|
}
|
|
943
983
|
|
|
944
984
|
// src/adapters/cetus.ts
|
|
945
|
-
var descriptor2 = {
|
|
946
|
-
id: "cetus",
|
|
947
|
-
name: "Cetus DEX",
|
|
948
|
-
packages: [CETUS_PACKAGE],
|
|
949
|
-
actionMap: {
|
|
950
|
-
"router::swap": "swap",
|
|
951
|
-
"router::swap_ab_bc": "swap",
|
|
952
|
-
"router::swap_ab_cb": "swap",
|
|
953
|
-
"router::swap_ba_bc": "swap",
|
|
954
|
-
"router::swap_ba_cb": "swap"
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
985
|
var CetusAdapter = class {
|
|
958
986
|
id = "cetus";
|
|
959
987
|
name = "Cetus";
|
|
@@ -1012,7 +1040,6 @@ var CetusAdapter = class {
|
|
|
1012
1040
|
});
|
|
1013
1041
|
}
|
|
1014
1042
|
};
|
|
1015
|
-
var SUILEND_PACKAGE = "0xf95b06141ed4a174f239417323bde3f209b972f5930d8521ea38a52aff3a6ddf";
|
|
1016
1043
|
var MIN_HEALTH_FACTOR2 = 1.5;
|
|
1017
1044
|
async function quietSuilend(fn) {
|
|
1018
1045
|
const origLog = console.log;
|
|
@@ -1029,23 +1056,6 @@ async function quietSuilend(fn) {
|
|
|
1029
1056
|
console.warn = origWarn;
|
|
1030
1057
|
});
|
|
1031
1058
|
}
|
|
1032
|
-
var descriptor3 = {
|
|
1033
|
-
id: "suilend",
|
|
1034
|
-
name: "Suilend",
|
|
1035
|
-
packages: [SUILEND_PACKAGE],
|
|
1036
|
-
actionMap: {
|
|
1037
|
-
"lending_market::deposit_liquidity_and_mint_ctokens": "save",
|
|
1038
|
-
"lending_market::deposit_ctokens_into_obligation": "save",
|
|
1039
|
-
"lending_market::create_obligation": "save",
|
|
1040
|
-
"lending_market::withdraw_ctokens": "withdraw",
|
|
1041
|
-
"lending_market::redeem_ctokens_and_withdraw_liquidity": "withdraw",
|
|
1042
|
-
"lending_market::redeem_ctokens_and_withdraw_liquidity_request": "withdraw",
|
|
1043
|
-
"lending_market::fulfill_liquidity_request": "withdraw",
|
|
1044
|
-
"lending_market::unstake_sui_from_staker": "withdraw",
|
|
1045
|
-
"lending_market::borrow": "borrow",
|
|
1046
|
-
"lending_market::repay": "repay"
|
|
1047
|
-
}
|
|
1048
|
-
};
|
|
1049
1059
|
var SuilendAdapter = class {
|
|
1050
1060
|
id = "suilend";
|
|
1051
1061
|
name = "Suilend";
|
|
@@ -1456,24 +1466,7 @@ var SuilendAdapter = class {
|
|
|
1456
1466
|
}
|
|
1457
1467
|
}
|
|
1458
1468
|
};
|
|
1459
|
-
var descriptor4 = {
|
|
1460
|
-
id: "sentinel",
|
|
1461
|
-
name: "Sui Sentinel",
|
|
1462
|
-
packages: [SENTINEL.PACKAGE],
|
|
1463
|
-
actionMap: {
|
|
1464
|
-
"sentinel::request_attack": "sentinel_attack",
|
|
1465
|
-
"sentinel::consume_prompt": "sentinel_settle"
|
|
1466
|
-
}
|
|
1467
|
-
};
|
|
1468
|
-
|
|
1469
|
-
// src/adapters/index.ts
|
|
1470
|
-
var allDescriptors = [
|
|
1471
|
-
descriptor,
|
|
1472
|
-
descriptor3,
|
|
1473
|
-
descriptor2,
|
|
1474
|
-
descriptor4
|
|
1475
|
-
];
|
|
1476
1469
|
|
|
1477
|
-
export { CetusAdapter, NaviAdapter, ProtocolRegistry, SuilendAdapter, allDescriptors,
|
|
1470
|
+
export { CetusAdapter, NaviAdapter, ProtocolRegistry, SuilendAdapter, allDescriptors, cetusDescriptor, naviDescriptor, suilendDescriptor };
|
|
1478
1471
|
//# sourceMappingURL=index.js.map
|
|
1479
1472
|
//# sourceMappingURL=index.js.map
|