@omnipair/dusk-sdk 2.0.1 → 2.16.0-next.20261102
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 +1085 -26
- package/dist/amounts.d.ts +9 -0
- package/dist/amounts.d.ts.map +1 -0
- package/dist/amounts.js +10 -0
- package/dist/amounts.js.map +1 -0
- package/dist/constants.d.ts +80 -33
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +175 -64
- package/dist/constants.js.map +1 -1
- package/dist/delegate.d.ts +94 -0
- package/dist/delegate.d.ts.map +1 -0
- package/dist/delegate.js +131 -0
- package/dist/delegate.js.map +1 -0
- package/dist/dusk.d.ts +14 -0
- package/dist/dusk.d.ts.map +1 -1
- package/dist/dusk.js +22 -0
- package/dist/dusk.js.map +1 -1
- package/dist/get.d.ts +3285 -237
- package/dist/get.d.ts.map +1 -1
- package/dist/get.js +140 -71
- package/dist/get.js.map +1 -1
- package/dist/governance-client.d.ts +169 -0
- package/dist/governance-client.d.ts.map +1 -0
- package/dist/governance-client.js +146 -0
- package/dist/governance-client.js.map +1 -0
- package/dist/governance.d.ts +313 -0
- package/dist/governance.d.ts.map +1 -0
- package/dist/governance.js +902 -0
- package/dist/governance.js.map +1 -0
- package/dist/hash.d.ts +9 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +16 -0
- package/dist/hash.js.map +1 -0
- package/dist/hlp-liquidation-client.d.ts +106 -0
- package/dist/hlp-liquidation-client.d.ts.map +1 -0
- package/dist/hlp-liquidation-client.js +150 -0
- package/dist/hlp-liquidation-client.js.map +1 -0
- package/dist/idl_delegate.d.ts +3 -0
- package/dist/idl_delegate.d.ts.map +1 -0
- package/dist/idl_delegate.js +3 -0
- package/dist/idl_delegate.js.map +1 -0
- package/dist/idl_delegate.json +6119 -0
- package/dist/idl_v2.json +18372 -6121
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -1
- package/dist/interest-accounting.d.ts +49 -0
- package/dist/interest-accounting.d.ts.map +1 -0
- package/dist/interest-accounting.js +72 -0
- package/dist/interest-accounting.js.map +1 -0
- package/dist/leverage-actions.d.ts +122 -0
- package/dist/leverage-actions.d.ts.map +1 -0
- package/dist/leverage-actions.js +228 -0
- package/dist/leverage-actions.js.map +1 -0
- package/dist/leverage-margins.d.ts +12 -0
- package/dist/leverage-margins.d.ts.map +1 -0
- package/dist/leverage-margins.js +45 -0
- package/dist/leverage-margins.js.map +1 -0
- package/dist/leverage-preview.d.ts +587 -0
- package/dist/leverage-preview.d.ts.map +1 -0
- package/dist/leverage-preview.js +89 -0
- package/dist/leverage-preview.js.map +1 -0
- package/dist/liquidation-client.d.ts +230 -0
- package/dist/liquidation-client.d.ts.map +1 -0
- package/dist/liquidation-client.js +239 -0
- package/dist/liquidation-client.js.map +1 -0
- package/dist/liquidation.d.ts +78 -0
- package/dist/liquidation.d.ts.map +1 -0
- package/dist/liquidation.js +122 -0
- package/dist/liquidation.js.map +1 -0
- package/dist/lp-naming.d.ts +43 -0
- package/dist/lp-naming.d.ts.map +1 -0
- package/dist/lp-naming.js +81 -0
- package/dist/lp-naming.js.map +1 -0
- package/dist/lp-vanity.d.ts +33 -0
- package/dist/lp-vanity.d.ts.map +1 -0
- package/dist/lp-vanity.js +94 -0
- package/dist/lp-vanity.js.map +1 -0
- package/dist/market-bootstrap.d.ts +109 -0
- package/dist/market-bootstrap.d.ts.map +1 -0
- package/dist/market-bootstrap.js +158 -0
- package/dist/market-bootstrap.js.map +1 -0
- package/dist/market-launch.d.ts +45 -0
- package/dist/market-launch.d.ts.map +1 -0
- package/dist/market-launch.js +76 -0
- package/dist/market-launch.js.map +1 -0
- package/dist/oracle.d.ts +46 -0
- package/dist/oracle.d.ts.map +1 -0
- package/dist/oracle.js +103 -0
- package/dist/oracle.js.map +1 -0
- package/dist/preview.d.ts +39 -1
- package/dist/preview.d.ts.map +1 -1
- package/dist/preview.js +12 -0
- package/dist/preview.js.map +1 -1
- package/dist/protection.d.ts +48 -0
- package/dist/protection.d.ts.map +1 -0
- package/dist/protection.js +88 -0
- package/dist/protection.js.map +1 -0
- package/dist/referral.d.ts +28 -28
- package/dist/referral.d.ts.map +1 -1
- package/dist/referral.js +41 -33
- package/dist/referral.js.map +1 -1
- package/dist/risk-pricing.d.ts +14 -0
- package/dist/risk-pricing.d.ts.map +1 -0
- package/dist/risk-pricing.js +25 -0
- package/dist/risk-pricing.js.map +1 -0
- package/dist/simulation.d.ts +45 -0
- package/dist/simulation.d.ts.map +1 -0
- package/dist/simulation.js +106 -0
- package/dist/simulation.js.map +1 -0
- package/dist/tranche-client.d.ts +121 -0
- package/dist/tranche-client.d.ts.map +1 -0
- package/dist/tranche-client.js +185 -0
- package/dist/tranche-client.js.map +1 -0
- package/dist/transfer-fees.d.ts +46 -0
- package/dist/transfer-fees.d.ts.map +1 -0
- package/dist/transfer-fees.js +76 -0
- package/dist/transfer-fees.js.map +1 -0
- package/dist/type-aliases.d.ts +271 -30
- package/dist/type-aliases.d.ts.map +1 -1
- package/dist/types_delegate.d.ts +6126 -0
- package/dist/types_delegate.d.ts.map +1 -0
- package/dist/types_delegate.js +2 -0
- package/dist/types_delegate.js.map +1 -0
- package/dist/types_v2.d.ts +18105 -5854
- package/dist/types_v2.d.ts.map +1 -1
- package/dist/virtual-book/index.d.ts +4 -0
- package/dist/virtual-book/index.d.ts.map +1 -0
- package/dist/virtual-book/index.js +4 -0
- package/dist/virtual-book/index.js.map +1 -0
- package/dist/virtual-book/market.d.ts +608 -0
- package/dist/virtual-book/market.d.ts.map +1 -0
- package/dist/virtual-book/market.js +59 -0
- package/dist/virtual-book/market.js.map +1 -0
- package/dist/virtual-book/projection.d.ts +44 -0
- package/dist/virtual-book/projection.d.ts.map +1 -0
- package/dist/virtual-book/projection.js +229 -0
- package/dist/virtual-book/projection.js.map +1 -0
- package/dist/virtual-book/quotes.d.ts +1241 -0
- package/dist/virtual-book/quotes.d.ts.map +1 -0
- package/dist/virtual-book/quotes.js +233 -0
- package/dist/virtual-book/quotes.js.map +1 -0
- package/dist/write.d.ts +584 -14
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +1371 -47
- package/dist/write.js.map +1 -1
- package/dist/yield-client.d.ts +51 -0
- package/dist/yield-client.d.ts.map +1 -0
- package/dist/yield-client.js +98 -0
- package/dist/yield-client.js.map +1 -0
- package/package.json +9 -2
- package/src/amounts.ts +13 -0
- package/src/constants.ts +276 -111
- package/src/delegate.ts +238 -0
- package/src/dusk.ts +28 -0
- package/src/get.ts +267 -90
- package/src/governance-client.ts +234 -0
- package/src/governance.ts +1422 -0
- package/src/hash.ts +15 -0
- package/src/hlp-liquidation-client.ts +195 -0
- package/src/idl_delegate.json +6119 -0
- package/src/idl_delegate.ts +3 -0
- package/src/idl_v2.json +18372 -6121
- package/src/index.ts +31 -0
- package/src/interest-accounting.ts +85 -0
- package/src/leverage-actions.ts +216 -0
- package/src/leverage-margins.ts +48 -0
- package/src/leverage-preview.ts +86 -0
- package/src/liquidation-client.ts +297 -0
- package/src/liquidation.ts +137 -0
- package/src/lp-naming.ts +127 -0
- package/src/lp-vanity.ts +135 -0
- package/src/market-bootstrap.ts +273 -0
- package/src/market-launch.ts +103 -0
- package/src/oracle.ts +120 -0
- package/src/preview.ts +53 -1
- package/src/protection.ts +112 -0
- package/src/referral.ts +71 -71
- package/src/risk-pricing.ts +28 -0
- package/src/simulation.ts +169 -0
- package/src/tranche-client.ts +187 -0
- package/src/transfer-fees.ts +99 -0
- package/src/type-aliases.ts +280 -30
- package/src/types_delegate.ts +6125 -0
- package/src/types_v2.ts +18372 -6121
- package/src/virtual-book/index.ts +3 -0
- package/src/virtual-book/market.ts +76 -0
- package/src/virtual-book/projection.ts +265 -0
- package/src/virtual-book/quotes.ts +308 -0
- package/src/write.ts +2394 -67
- package/src/yield-client.ts +117 -0
package/src/get.ts
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
|
+
import { DuskWrite, type DuskInstructionName } from "./write.js";
|
|
1
2
|
import type { BN, Program } from "@coral-xyz/anchor";
|
|
3
|
+
import { previewLeverageAction, type PreviewLeverageActionParams } from "./leverage-preview.js";
|
|
4
|
+
import { PublicKey, TransactionInstruction, type Commitment } from "@solana/web3.js";
|
|
2
5
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
} from "
|
|
6
|
+
simulatePreviewWithContext,
|
|
7
|
+
type PreviewSimulationOptions,
|
|
8
|
+
type SimulateOptions,
|
|
9
|
+
} from "./simulation.js";
|
|
10
|
+
export { DuskSimulationError, DuskPreviewTimeoutError } from "./simulation.js";
|
|
11
|
+
export type {
|
|
12
|
+
SimulateOptions,
|
|
13
|
+
PreviewSimulationOptions,
|
|
14
|
+
DuskPreviewSimulation,
|
|
15
|
+
} from "./simulation.js";
|
|
16
|
+
import {
|
|
17
|
+
previewVirtualBookSnapshot,
|
|
18
|
+
previewVirtualBookQuotes,
|
|
19
|
+
previewVirtualBookBatch,
|
|
20
|
+
projectDuskVirtualBook,
|
|
21
|
+
type DuskVirtualBookSnapshot,
|
|
22
|
+
type VirtualBookQuoteOptions,
|
|
23
|
+
type VirtualBookQuoteRequest,
|
|
24
|
+
} from "./virtual-book/index.js";
|
|
8
25
|
|
|
9
26
|
import {
|
|
10
27
|
deriveBorrowPositionAddress,
|
|
@@ -14,24 +31,32 @@ import {
|
|
|
14
31
|
deriveLeveragePositionAddress,
|
|
15
32
|
deriveMarketAddress,
|
|
16
33
|
deriveMarketCollateralVaultAddress,
|
|
17
|
-
deriveMarketFeeVaultAddress,
|
|
18
34
|
deriveMarketInterestVaultAddress,
|
|
19
35
|
deriveMarketReserveVaultAddress,
|
|
20
|
-
|
|
36
|
+
deriveParameterProposalAddress,
|
|
37
|
+
deriveProposalSupportAddress,
|
|
38
|
+
deriveReferralAccrualAddress,
|
|
39
|
+
deriveReferralPartnerAddress,
|
|
21
40
|
deriveTokenMetadataAddress,
|
|
22
41
|
deriveYieldAccountAddress,
|
|
23
42
|
deriveYieldTransferHookValidationAddress,
|
|
43
|
+
type U64SeedLike,
|
|
24
44
|
} from "./constants.js";
|
|
25
45
|
import { address, DEFAULT_READONLY_PUBLIC_KEY, normalizeAccountKeys, type AddressLike } from "./address.js";
|
|
46
|
+
import { getStoredLeverageMargins } from "./leverage-margins.js";
|
|
26
47
|
import {
|
|
48
|
+
decodePreviewHlpDepositCapacityReturnData,
|
|
49
|
+
type HlpDepositCapacityPreview,
|
|
27
50
|
decodePreviewAddLiquidityReturnData,
|
|
28
51
|
decodePreviewBorrowCapacityReturnData,
|
|
29
52
|
decodePreviewBorrowPositionReturnData,
|
|
53
|
+
decodePreviewBorrowPositionCapacityReturnData,
|
|
30
54
|
decodePreviewMarketReturnData,
|
|
31
55
|
decodePreviewSwapReturnData,
|
|
32
56
|
type AddLiquidityPreview,
|
|
33
57
|
type BorrowCapacityPreview,
|
|
34
58
|
type BorrowPositionPreview,
|
|
59
|
+
type BorrowPositionCapacityPreview,
|
|
35
60
|
type MarketPreview,
|
|
36
61
|
type PreviewReturnData,
|
|
37
62
|
type SwapPreview,
|
|
@@ -42,6 +67,10 @@ import type {
|
|
|
42
67
|
LeverageDelegation,
|
|
43
68
|
LeveragePosition,
|
|
44
69
|
Market,
|
|
70
|
+
ParameterProposal,
|
|
71
|
+
ProposalSupport,
|
|
72
|
+
ReferralAccrual,
|
|
73
|
+
ReferralPartner,
|
|
45
74
|
YieldAccount,
|
|
46
75
|
} from "./type-aliases.js";
|
|
47
76
|
import type { Dusk } from "./types_v2.js";
|
|
@@ -52,7 +81,6 @@ export const pda = {
|
|
|
52
81
|
tokenMetadata: deriveTokenMetadataAddress,
|
|
53
82
|
marketReserveVault: deriveMarketReserveVaultAddress,
|
|
54
83
|
marketCollateralVault: deriveMarketCollateralVaultAddress,
|
|
55
|
-
marketFeeVault: deriveMarketFeeVaultAddress,
|
|
56
84
|
marketInterestVault: deriveMarketInterestVaultAddress,
|
|
57
85
|
borrowPosition: deriveBorrowPositionAddress,
|
|
58
86
|
leveragePosition: deriveLeveragePositionAddress,
|
|
@@ -60,16 +88,23 @@ export const pda = {
|
|
|
60
88
|
yieldTransferHookValidation: deriveYieldTransferHookValidationAddress,
|
|
61
89
|
hlpYlpVault: deriveHlpYlpVaultAddress,
|
|
62
90
|
insurance: deriveInsuranceAddress,
|
|
63
|
-
|
|
91
|
+
referralPartner: deriveReferralPartnerAddress,
|
|
92
|
+
referralAccrual: deriveReferralAccrualAddress,
|
|
93
|
+
parameterProposal: deriveParameterProposalAddress,
|
|
94
|
+
proposalSupport: deriveProposalSupportAddress,
|
|
64
95
|
} as const;
|
|
65
96
|
|
|
66
|
-
export interface SimulateOptions {
|
|
67
|
-
|
|
68
|
-
|
|
97
|
+
export interface PreviewHlpDepositCapacityParams extends SimulateOptions {
|
|
98
|
+
market: AddressLike;
|
|
99
|
+
futarchyAuthority?: AddressLike;
|
|
100
|
+
baseMint: AddressLike;
|
|
101
|
+
quoteMint: AddressLike;
|
|
102
|
+
targetHlpMint: AddressLike;
|
|
69
103
|
}
|
|
70
104
|
|
|
71
105
|
export interface PreviewSwapParams extends SimulateOptions {
|
|
72
106
|
market: AddressLike;
|
|
107
|
+
futarchyAuthority?: AddressLike;
|
|
73
108
|
assetInMint: AddressLike;
|
|
74
109
|
assetOutMint: AddressLike;
|
|
75
110
|
exactAssetIn: BN;
|
|
@@ -85,32 +120,36 @@ export interface PreviewAddLiquidityParams extends SimulateOptions {
|
|
|
85
120
|
|
|
86
121
|
export interface PreviewBorrowCapacityParams extends SimulateOptions {
|
|
87
122
|
market: AddressLike;
|
|
88
|
-
futarchyAuthority?: AddressLike;
|
|
89
123
|
collateralAssetMint: AddressLike;
|
|
90
124
|
debtAssetMint: AddressLike;
|
|
125
|
+
/** Net collateral amount credited to the vault after any deposit transfer fee. */
|
|
91
126
|
collateralAmount: BN;
|
|
92
127
|
/**
|
|
93
|
-
* Candidate
|
|
94
|
-
*
|
|
128
|
+
* Candidate debt amount used for the returned CF and health fields. When
|
|
129
|
+
* omitted, the program quotes at maximum borrow capacity.
|
|
95
130
|
*/
|
|
96
131
|
projectedBorrowAmount?: BN | null;
|
|
97
|
-
withReferral?: boolean;
|
|
98
|
-
maxAcceptableReferralFeeBps?: number;
|
|
99
132
|
}
|
|
100
133
|
|
|
101
|
-
export interface
|
|
134
|
+
export interface PreviewBorrowPositionCapacityParams extends SimulateOptions {
|
|
135
|
+
capacityKind: "borrow" | "withdraw";
|
|
102
136
|
market: AddressLike;
|
|
103
137
|
borrowPosition: AddressLike;
|
|
138
|
+
collateralAssetMint: AddressLike;
|
|
139
|
+
debtAssetMint: AddressLike;
|
|
140
|
+
/** Net credit after transfer fees, or negative collateral vault debit. */
|
|
141
|
+
collateralChange: BN;
|
|
142
|
+
/** Additional debt; omit for maximum additional capacity. */
|
|
143
|
+
projectedBorrowAmount?: BN | null;
|
|
104
144
|
}
|
|
105
145
|
|
|
106
|
-
export
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
146
|
+
export interface PreviewBorrowPositionParams extends SimulateOptions {
|
|
147
|
+
market: AddressLike;
|
|
148
|
+
borrowPosition: AddressLike;
|
|
149
|
+
/** Market base mint; liquidation fields value collateral after its transfer fee. */
|
|
150
|
+
baseMint: AddressLike;
|
|
151
|
+
/** Market quote mint; liquidation fields value collateral after its transfer fee. */
|
|
152
|
+
quoteMint: AddressLike;
|
|
114
153
|
}
|
|
115
154
|
|
|
116
155
|
export class DuskGet {
|
|
@@ -135,65 +174,163 @@ export class DuskGet {
|
|
|
135
174
|
return client.fetch(address(account));
|
|
136
175
|
}
|
|
137
176
|
|
|
177
|
+
private allProgramAccounts<T>(name: string): Promise<Array<{ publicKey: PublicKey; account: T }>> {
|
|
178
|
+
const client = (
|
|
179
|
+
this.program as unknown as {
|
|
180
|
+
account: Record<string, { all(): Promise<Array<{ publicKey: PublicKey; account: T }>> }>;
|
|
181
|
+
}
|
|
182
|
+
).account[name];
|
|
183
|
+
if (!client) {
|
|
184
|
+
throw new Error(`Unknown Dusk account type: ${name}`);
|
|
185
|
+
}
|
|
186
|
+
return client.all();
|
|
187
|
+
}
|
|
188
|
+
|
|
138
189
|
market(account: AddressLike): Promise<Market> {
|
|
139
|
-
return this.
|
|
190
|
+
return this.programAccount<Market>("market", account);
|
|
140
191
|
}
|
|
141
192
|
|
|
142
193
|
borrowPosition(account: AddressLike): Promise<BorrowPosition> {
|
|
143
|
-
return this.
|
|
194
|
+
return this.programAccount<BorrowPosition>("borrowPosition", account);
|
|
144
195
|
}
|
|
145
196
|
|
|
146
197
|
leveragePosition(account: AddressLike): Promise<LeveragePosition> {
|
|
147
|
-
return this.
|
|
198
|
+
return this.programAccount<LeveragePosition>("leveragePosition", account);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Fetch saved margin terms; does not quote an opening or an increase. */
|
|
202
|
+
async leverageMargins(account: AddressLike) {
|
|
203
|
+
return getStoredLeverageMargins(await this.leveragePosition(account));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
previewLeverageAction(params: PreviewLeverageActionParams) {
|
|
207
|
+
return previewLeverageAction(this.program, params);
|
|
148
208
|
}
|
|
149
209
|
|
|
150
210
|
leverageDelegation(account: AddressLike): Promise<LeverageDelegation> {
|
|
151
|
-
return this.
|
|
211
|
+
return this.programAccount<LeverageDelegation>("leverageDelegation", account);
|
|
152
212
|
}
|
|
153
213
|
|
|
154
214
|
yieldAccount(account: AddressLike): Promise<YieldAccount> {
|
|
155
|
-
return this.
|
|
215
|
+
return this.programAccount<YieldAccount>("yieldAccount", account);
|
|
156
216
|
}
|
|
157
217
|
|
|
158
218
|
futarchyAuthority(account: AddressLike = deriveFutarchyAuthorityAddress()[0]): Promise<FutarchyAuthority> {
|
|
159
|
-
return this.
|
|
219
|
+
return this.programAccount<FutarchyAuthority>("futarchyAuthority", account);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
referralPartner(account: AddressLike): Promise<ReferralPartner> {
|
|
223
|
+
return this.programAccount<ReferralPartner>("referralPartner", account);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
referralAccrual(account: AddressLike): Promise<ReferralAccrual> {
|
|
227
|
+
return this.programAccount<ReferralAccrual>("referralAccrual", account);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
parameterProposal(account: AddressLike): Promise<ParameterProposal> {
|
|
231
|
+
return this.programAccount<ParameterProposal>("parameterProposal", account);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
proposalSupport(account: AddressLike): Promise<ProposalSupport> {
|
|
235
|
+
return this.programAccount<ProposalSupport>("proposalSupport", account);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
parameterProposalFor(
|
|
239
|
+
market: AddressLike,
|
|
240
|
+
proposer: AddressLike,
|
|
241
|
+
nonce: U64SeedLike
|
|
242
|
+
): Promise<ParameterProposal> {
|
|
243
|
+
const [proposal] = deriveParameterProposalAddress(
|
|
244
|
+
address(market),
|
|
245
|
+
address(proposer),
|
|
246
|
+
nonce,
|
|
247
|
+
this.program.programId
|
|
248
|
+
);
|
|
249
|
+
return this.parameterProposal(proposal);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
proposalSupportFor(
|
|
253
|
+
proposal: AddressLike,
|
|
254
|
+
supporter: AddressLike
|
|
255
|
+
): Promise<ProposalSupport> {
|
|
256
|
+
const [support] = deriveProposalSupportAddress(
|
|
257
|
+
address(proposal),
|
|
258
|
+
address(supporter),
|
|
259
|
+
this.program.programId
|
|
260
|
+
);
|
|
261
|
+
return this.proposalSupport(support);
|
|
160
262
|
}
|
|
161
263
|
|
|
162
264
|
allMarkets() {
|
|
163
|
-
return this.
|
|
265
|
+
return this.allProgramAccounts<Market>("market");
|
|
164
266
|
}
|
|
165
267
|
|
|
166
268
|
allBorrowPositions() {
|
|
167
|
-
return this.
|
|
269
|
+
return this.allProgramAccounts<BorrowPosition>("borrowPosition");
|
|
168
270
|
}
|
|
169
271
|
|
|
170
272
|
allLeveragePositions() {
|
|
171
|
-
return this.
|
|
273
|
+
return this.allProgramAccounts<LeveragePosition>("leveragePosition");
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
allReferralPartners() {
|
|
277
|
+
return this.allProgramAccounts<ReferralPartner>("referralPartner");
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
allReferralAccruals() {
|
|
281
|
+
return this.allProgramAccounts<ReferralAccrual>("referralAccrual");
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
allParameterProposals() {
|
|
285
|
+
return this.allProgramAccounts<ParameterProposal>("parameterProposal");
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
allProposalSupports() {
|
|
289
|
+
return this.allProgramAccounts<ProposalSupport>("proposalSupport");
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private previewInstruction(
|
|
293
|
+
name: string,
|
|
294
|
+
args: unknown[],
|
|
295
|
+
accounts: Record<string, unknown>
|
|
296
|
+
): Promise<TransactionInstruction> {
|
|
297
|
+
return new DuskWrite(this.program).instruction(name as DuskInstructionName, args, { accounts });
|
|
172
298
|
}
|
|
173
299
|
|
|
174
300
|
async previewMarket(market: AddressLike, options: SimulateOptions = {}): Promise<MarketPreview> {
|
|
175
|
-
const instruction = await this.
|
|
176
|
-
.previewMarket()
|
|
177
|
-
.accounts(normalizeAccountKeys({ market }))
|
|
178
|
-
.instruction();
|
|
301
|
+
const instruction = await this.previewInstruction("previewMarket", [], normalizeAccountKeys({ market }));
|
|
179
302
|
|
|
180
303
|
return decodePreviewMarketReturnData(await this.simulateReturnData(instruction, options));
|
|
181
304
|
}
|
|
182
305
|
|
|
306
|
+
/** Current full-value hedge admission and funding ceiling, including transfer fees.
|
|
307
|
+
* A Ready status is not an amount-specific execution guarantee; simulate the
|
|
308
|
+
* completed deposit transaction to check rounding, slippage and custody.
|
|
309
|
+
*/
|
|
310
|
+
async previewHlpDepositCapacity(params: PreviewHlpDepositCapacityParams): Promise<HlpDepositCapacityPreview> {
|
|
311
|
+
const instruction = await this.previewInstruction("previewHlpDepositCapacity", [], normalizeAccountKeys({
|
|
312
|
+
market: params.market,
|
|
313
|
+
futarchyAuthority: params.futarchyAuthority ?? deriveFutarchyAuthorityAddress(this.program.programId)[0],
|
|
314
|
+
baseMint: params.baseMint,
|
|
315
|
+
quoteMint: params.quoteMint,
|
|
316
|
+
targetHlpMint: params.targetHlpMint,
|
|
317
|
+
}));
|
|
318
|
+
return decodePreviewHlpDepositCapacityReturnData(await this.simulateReturnData(instruction, params));
|
|
319
|
+
}
|
|
320
|
+
|
|
183
321
|
async previewAddLiquidity(params: PreviewAddLiquidityParams): Promise<AddLiquidityPreview> {
|
|
184
|
-
const instruction = await this.
|
|
185
|
-
|
|
322
|
+
const instruction = await this.previewInstruction(
|
|
323
|
+
"previewAddLiquidity",
|
|
324
|
+
[{
|
|
186
325
|
baseDepositAmount: params.baseDepositAmount,
|
|
187
326
|
quoteDepositAmount: params.quoteDepositAmount,
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
normalizeAccountKeys({
|
|
327
|
+
}],
|
|
328
|
+
normalizeAccountKeys({
|
|
191
329
|
market: params.market,
|
|
192
330
|
baseMint: params.baseMint,
|
|
193
331
|
quoteMint: params.quoteMint,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
.instruction();
|
|
332
|
+
})
|
|
333
|
+
);
|
|
197
334
|
|
|
198
335
|
return decodePreviewAddLiquidityReturnData(
|
|
199
336
|
await this.simulateReturnData(instruction, params)
|
|
@@ -201,18 +338,19 @@ export class DuskGet {
|
|
|
201
338
|
}
|
|
202
339
|
|
|
203
340
|
async previewSwap(params: PreviewSwapParams): Promise<SwapPreview> {
|
|
204
|
-
const instruction = await this.
|
|
205
|
-
|
|
341
|
+
const instruction = await this.previewInstruction(
|
|
342
|
+
"previewSwap",
|
|
343
|
+
[{
|
|
206
344
|
exactAssetIn: params.exactAssetIn,
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
normalizeAccountKeys({
|
|
345
|
+
}],
|
|
346
|
+
normalizeAccountKeys({
|
|
210
347
|
market: params.market,
|
|
348
|
+
futarchyAuthority:
|
|
349
|
+
params.futarchyAuthority ?? deriveFutarchyAuthorityAddress()[0],
|
|
211
350
|
assetInMint: params.assetInMint,
|
|
212
351
|
assetOutMint: params.assetOutMint,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
.instruction();
|
|
352
|
+
})
|
|
353
|
+
);
|
|
216
354
|
|
|
217
355
|
return decodePreviewSwapReturnData(await this.simulateReturnData(instruction, params));
|
|
218
356
|
}
|
|
@@ -220,60 +358,99 @@ export class DuskGet {
|
|
|
220
358
|
async previewBorrowCapacity(
|
|
221
359
|
params: PreviewBorrowCapacityParams
|
|
222
360
|
): Promise<BorrowCapacityPreview> {
|
|
223
|
-
const instruction = await this.
|
|
224
|
-
|
|
361
|
+
const instruction = await this.previewInstruction(
|
|
362
|
+
"previewBorrowCapacity",
|
|
363
|
+
[{
|
|
225
364
|
collateralAmount: params.collateralAmount,
|
|
226
365
|
projectedBorrowAmount: params.projectedBorrowAmount ?? null,
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
})
|
|
230
|
-
.accounts(
|
|
231
|
-
normalizeAccountKeys({
|
|
366
|
+
}],
|
|
367
|
+
normalizeAccountKeys({
|
|
232
368
|
market: params.market,
|
|
233
|
-
futarchyAuthority: params.futarchyAuthority ?? deriveFutarchyAuthorityAddress()[0],
|
|
234
369
|
collateralAssetMint: params.collateralAssetMint,
|
|
235
370
|
debtAssetMint: params.debtAssetMint,
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
.instruction();
|
|
371
|
+
})
|
|
372
|
+
);
|
|
239
373
|
|
|
240
374
|
return decodePreviewBorrowCapacityReturnData(await this.simulateReturnData(instruction, params));
|
|
241
375
|
}
|
|
242
376
|
|
|
377
|
+
async previewBorrowPositionCapacity(
|
|
378
|
+
params: PreviewBorrowPositionCapacityParams
|
|
379
|
+
): Promise<BorrowPositionCapacityPreview> {
|
|
380
|
+
const instruction = await this.previewInstruction(
|
|
381
|
+
"previewBorrowPositionCapacity",
|
|
382
|
+
[{
|
|
383
|
+
capacityKind: params.capacityKind === "borrow" ? { borrow: {} } : { withdraw: {} },
|
|
384
|
+
collateralChange: params.collateralChange,
|
|
385
|
+
projectedBorrowAmount: params.projectedBorrowAmount ?? null,
|
|
386
|
+
}],
|
|
387
|
+
normalizeAccountKeys({
|
|
388
|
+
market: params.market,
|
|
389
|
+
borrowPosition: params.borrowPosition,
|
|
390
|
+
collateralAssetMint: params.collateralAssetMint,
|
|
391
|
+
debtAssetMint: params.debtAssetMint,
|
|
392
|
+
})
|
|
393
|
+
);
|
|
394
|
+
|
|
395
|
+
return decodePreviewBorrowPositionCapacityReturnData(await this.simulateReturnData(instruction, params));
|
|
396
|
+
}
|
|
397
|
+
|
|
243
398
|
async previewBorrowPosition(params: PreviewBorrowPositionParams): Promise<BorrowPositionPreview> {
|
|
244
|
-
const instruction = await this.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
399
|
+
const instruction = await this.previewInstruction(
|
|
400
|
+
"previewBorrowPosition",
|
|
401
|
+
[],
|
|
402
|
+
normalizeAccountKeys({
|
|
248
403
|
market: params.market,
|
|
249
404
|
borrowPosition: params.borrowPosition,
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
405
|
+
baseMint: params.baseMint,
|
|
406
|
+
quoteMint: params.quoteMint,
|
|
407
|
+
})
|
|
408
|
+
);
|
|
253
409
|
|
|
254
410
|
return decodePreviewBorrowPositionReturnData(await this.simulateReturnData(instruction, params));
|
|
255
411
|
}
|
|
256
412
|
|
|
413
|
+
/** Simulate one or more instructions while retaining bank and account provenance. */
|
|
414
|
+
simulateWithContext(
|
|
415
|
+
instructions: readonly TransactionInstruction[],
|
|
416
|
+
options: PreviewSimulationOptions = {}
|
|
417
|
+
) {
|
|
418
|
+
return simulatePreviewWithContext(this.program, instructions, {
|
|
419
|
+
...options,
|
|
420
|
+
feePayer: options.feePayer ?? this.program.provider.publicKey ?? this.defaultFeePayer,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
|
|
257
424
|
async simulateReturnData(
|
|
258
425
|
instruction: TransactionInstruction,
|
|
259
426
|
options: SimulateOptions = {}
|
|
260
427
|
): Promise<PreviewReturnData> {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
428
|
+
return (await this.simulateWithContext([instruction], options)).value.returnData!;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
previewVirtualBookSnapshot(market: AddressLike, options: PreviewSimulationOptions = {}) {
|
|
432
|
+
return previewVirtualBookSnapshot(this.program, market, options);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
previewVirtualBookBatch(
|
|
436
|
+
snapshot: DuskVirtualBookSnapshot,
|
|
437
|
+
requests: VirtualBookQuoteRequest[],
|
|
438
|
+
options: PreviewSimulationOptions = {}
|
|
439
|
+
) {
|
|
440
|
+
return previewVirtualBookBatch(this.program, snapshot, requests, options);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
previewVirtualBookQuotes(
|
|
444
|
+
snapshot: DuskVirtualBookSnapshot,
|
|
445
|
+
options: VirtualBookQuoteOptions = {}
|
|
446
|
+
) {
|
|
447
|
+
return previewVirtualBookQuotes(this.program, snapshot, options);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/** Fee-inclusive display depth. Transaction quotes must still use the exact requested input. */
|
|
451
|
+
async previewVirtualBook(market: AddressLike, options: VirtualBookQuoteOptions = {}) {
|
|
452
|
+
const snapshot = await this.previewVirtualBookSnapshot(market, options);
|
|
453
|
+
const quotes = await this.previewVirtualBookQuotes(snapshot, options);
|
|
454
|
+
return { ...quotes, book: projectDuskVirtualBook(quotes)! };
|
|
278
455
|
}
|
|
279
456
|
}
|