@omnipair/dusk-sdk 2.0.2 → 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 +1011 -16
- 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 +71 -14
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +155 -28
- 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 +3253 -378
- package/dist/get.d.ts.map +1 -1
- package/dist/get.js +130 -70
- 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 +17175 -5862
- 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/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 -31
- 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 +17235 -5922
- 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 +517 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +1172 -23
- 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 +236 -26
- package/src/delegate.ts +238 -0
- package/src/dusk.ts +28 -0
- package/src/get.ts +247 -82
- 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 +17175 -5862
- 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/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 -31
- package/src/types_delegate.ts +6125 -0
- package/src/types_v2.ts +17174 -5861
- 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 +2073 -34
- package/src/yield-client.ts +117 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { Program } from "@coral-xyz/anchor";
|
|
2
|
+
import { createAssociatedTokenAccountIdempotentInstruction, getAssociatedTokenAddressSync, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
3
|
+
import { ComputeBudgetProgram, Transaction, type AccountMeta, type TransactionInstruction } from "@solana/web3.js";
|
|
4
|
+
import { address, type AddressLike } from "./address.js";
|
|
5
|
+
import { deriveFutarchyAuthorityAddress, deriveHlpCohortAddress, deriveJuniorCohortAddress, deriveYieldAccountAddress } from "./constants.js";
|
|
6
|
+
import { governanceIntegerBN, type GovernanceIntegerLike } from "./governance.js";
|
|
7
|
+
import { DuskGet } from "./get.js";
|
|
8
|
+
import { previewReturnDataBytes } from "./preview.js";
|
|
9
|
+
import { tokenProgramForMint } from "./referral.js";
|
|
10
|
+
import type { Dusk as DuskIdl } from "./types_v2.js";
|
|
11
|
+
import type { FundInterestReceipt } from "./type-aliases.js";
|
|
12
|
+
import { DuskWrite } from "./write.js";
|
|
13
|
+
|
|
14
|
+
export interface FundInterestParams {
|
|
15
|
+
market: AddressLike;
|
|
16
|
+
caller: AddressLike;
|
|
17
|
+
/** Gross debt-token atoms, including the protocol allocation. Defaults to available cash. */
|
|
18
|
+
maxBaseGross?: GovernanceIntegerLike;
|
|
19
|
+
maxQuoteGross?: GovernanceIntegerLike;
|
|
20
|
+
}
|
|
21
|
+
export type { FundInterestReceipt };
|
|
22
|
+
export interface HarvestYieldParams extends FundInterestParams {
|
|
23
|
+
owner: AddressLike;
|
|
24
|
+
kind: "ylp" | "junior" | "baseHlp" | "quoteHlp";
|
|
25
|
+
asset: "base" | "quote";
|
|
26
|
+
/** Set false to collect existing funded claims independently of new funding. */
|
|
27
|
+
fundAccruedInterest?: boolean;
|
|
28
|
+
/** Old hLP mint after terminal closure. Its yield indexes are frozen in its cohort PDA. */
|
|
29
|
+
retiredHlpMint?: AddressLike;
|
|
30
|
+
/** Wiped junior generation; previously earned income remains claimable. */
|
|
31
|
+
retiredJuniorMint?: AddressLike;
|
|
32
|
+
/** Extra accounts required by a Token-2022 asset transfer hook. */
|
|
33
|
+
transferHookAccounts?: readonly AccountMeta[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Market-wide cash funding and holder-specific harvesting. Builders never
|
|
37
|
+
* sign or submit. Funding can rebalance both hLPs and change the AMM mark;
|
|
38
|
+
* moving interest out of reserves by itself does not change swap reserves.
|
|
39
|
+
*/
|
|
40
|
+
export class DuskYield {
|
|
41
|
+
readonly write: DuskWrite;
|
|
42
|
+
readonly get: DuskGet;
|
|
43
|
+
constructor(readonly program: Program<DuskIdl>, feePayer?: AddressLike) {
|
|
44
|
+
this.write = new DuskWrite(program);
|
|
45
|
+
this.get = new DuskGet(program, feePayer);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async fundInstruction(params: FundInterestParams): Promise<TransactionInstruction> {
|
|
49
|
+
const market = address(params.market);
|
|
50
|
+
const s = await this.get.market(market);
|
|
51
|
+
return this.write.instruction("fundInterest", {
|
|
52
|
+
maxBaseGross: governanceIntegerBN(params.maxBaseGross ?? 0xffffffffffffffffn, "maxBaseGross"),
|
|
53
|
+
maxQuoteGross: governanceIntegerBN(params.maxQuoteGross ?? 0xffffffffffffffffn, "maxQuoteGross"),
|
|
54
|
+
}, { accounts: {
|
|
55
|
+
market, caller: address(params.caller), futarchyAuthority: deriveFutarchyAuthorityAddress(this.program.programId)[0],
|
|
56
|
+
baseMint: s.baseSide.assetMint, quoteMint: s.quoteSide.assetMint,
|
|
57
|
+
baseReserveVault: s.baseSide.reserveVault, quoteReserveVault: s.quoteSide.reserveVault,
|
|
58
|
+
baseInterestVault: s.baseSide.interestVault, quoteInterestVault: s.quoteSide.interestVault,
|
|
59
|
+
tokenProgram: TOKEN_PROGRAM_ID, token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
60
|
+
}, remainingAccounts: await this.write.hlpRemainingAccounts(market, s) });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Simulates actual funding, transfer fees and the joint hLP rebalance.
|
|
64
|
+
* This is a current-bank estimate, not a reservation of cash or yield.
|
|
65
|
+
*/
|
|
66
|
+
async previewFunding(params: FundInterestParams): Promise<FundInterestReceipt> {
|
|
67
|
+
const ix = await this.fundInstruction(params);
|
|
68
|
+
const simulation = await this.get.simulateWithContext([
|
|
69
|
+
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }),
|
|
70
|
+
ComputeBudgetProgram.requestHeapFrame({ bytes: 256 * 1024 }), ix,
|
|
71
|
+
]);
|
|
72
|
+
const data = simulation.value.returnData;
|
|
73
|
+
if (!data || data.programId !== this.program.programId.toBase58()) throw new Error("Missing Dusk funding return data");
|
|
74
|
+
return this.program.coder.types.decode("fundInterestReceipt", previewReturnDataBytes(data)) as FundInterestReceipt;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async buildHarvest(params: HarvestYieldParams) {
|
|
78
|
+
if (!["ylp", "junior", "baseHlp", "quoteHlp"].includes(params.kind)) throw new Error("Invalid yield token kind");
|
|
79
|
+
if (params.asset !== "base" && params.asset !== "quote") throw new Error("Invalid yield asset");
|
|
80
|
+
const market = address(params.market), owner = address(params.owner), caller = address(params.caller);
|
|
81
|
+
const s = await this.get.market(market);
|
|
82
|
+
const side = params.asset === "base" ? s.baseSide : s.quoteSide;
|
|
83
|
+
if (params.kind === "ylp" && params.retiredHlpMint) throw new Error("yLP does not have receipt cohorts");
|
|
84
|
+
if (params.retiredJuniorMint && params.kind !== "junior") throw new Error("A retired junior mint requires junior kind");
|
|
85
|
+
if (params.kind === "junior" && params.retiredHlpMint) throw new Error("Junior cannot use an hLP cohort");
|
|
86
|
+
const lpMint = params.retiredJuniorMint ? address(params.retiredJuniorMint) : params.retiredHlpMint
|
|
87
|
+
? address(params.retiredHlpMint)
|
|
88
|
+
: params.kind === "ylp" ? s.ylpMint : params.kind === "junior" ? s.juniorMint : params.kind === "baseHlp" ? s.baseSide.hlpMint : s.quoteSide.hlpMint;
|
|
89
|
+
const kind = params.kind === "ylp" ? "ylp" : params.kind === "junior" ? "junior" : "hlp";
|
|
90
|
+
const [yieldAccount] = deriveYieldAccountAddress(market, owner, lpMint, side.assetMint, kind, this.program.programId);
|
|
91
|
+
const claim = await this.get.yieldAccount(yieldAccount);
|
|
92
|
+
const tokenProgram = await tokenProgramForMint(this.program.provider.connection, side.assetMint);
|
|
93
|
+
const recipientAssetAccount = getAssociatedTokenAddressSync(side.assetMint, claim.recipient, true, tokenProgram);
|
|
94
|
+
const instructions: TransactionInstruction[] = [
|
|
95
|
+
ComputeBudgetProgram.setComputeUnitLimit({ units: 1_400_000 }),
|
|
96
|
+
ComputeBudgetProgram.requestHeapFrame({ bytes: 256 * 1024 }),
|
|
97
|
+
createAssociatedTokenAccountIdempotentInstruction(caller, recipientAssetAccount, claim.recipient, side.assetMint, tokenProgram),
|
|
98
|
+
];
|
|
99
|
+
if (params.fundAccruedInterest !== false) instructions.push(await this.fundInstruction(params));
|
|
100
|
+
instructions.push(await this.write.instruction("harvest", { tokenKind: { [kind]: {} } }, { accounts: {
|
|
101
|
+
market, owner, caller, assetMint: side.assetMint, lpMint,
|
|
102
|
+
ownerLpAccount: getAssociatedTokenAddressSync(lpMint, owner, true, TOKEN_2022_PROGRAM_ID),
|
|
103
|
+
reserveVault: side.reserveVault, interestVault: side.interestVault, recipientAssetAccount, yieldAccount,
|
|
104
|
+
tokenProgram: TOKEN_PROGRAM_ID, token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
105
|
+
}, remainingAccounts: [
|
|
106
|
+
...(params.retiredHlpMint
|
|
107
|
+
? [{ pubkey: deriveHlpCohortAddress(market, lpMint, this.program.programId)[0], isSigner: false, isWritable: false }]
|
|
108
|
+
: []),
|
|
109
|
+
...(params.retiredJuniorMint
|
|
110
|
+
? [{ pubkey: deriveJuniorCohortAddress(market, lpMint, this.program.programId)[0], isSigner: false, isWritable: false }]
|
|
111
|
+
: []),
|
|
112
|
+
...(params.transferHookAccounts ?? []),
|
|
113
|
+
],
|
|
114
|
+
}));
|
|
115
|
+
return { instructions, transaction: new Transaction().add(...instructions), yieldAccount, recipientAssetAccount };
|
|
116
|
+
}
|
|
117
|
+
}
|