@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,78 @@
|
|
|
1
|
+
import { PublicKey, VersionedTransaction, type AddressLookupTableAccount, type TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
export declare const LIQUIDATION_POLICY: Readonly<{
|
|
3
|
+
minimumDiscountBps: 50;
|
|
4
|
+
maximumDiscountBps: 500;
|
|
5
|
+
maximumEmergencyRewardBps: 100;
|
|
6
|
+
emergencyMaintenanceFractionBps: 7000;
|
|
7
|
+
recoveryBufferBps: 200;
|
|
8
|
+
solventFeeBps: 100;
|
|
9
|
+
protocolFeeShareBps: number;
|
|
10
|
+
maximumPrincipalCoverageBps: 7500;
|
|
11
|
+
maximumDailyInsuranceDrawBps: 5000;
|
|
12
|
+
}>;
|
|
13
|
+
export interface LiquidationHealthInput {
|
|
14
|
+
/** Linear symmetric-EMA value, in debt token atoms, after eligibility fees. */
|
|
15
|
+
collateralValue: bigint;
|
|
16
|
+
/** Indexed position debt in the same token atoms. */
|
|
17
|
+
debt: bigint;
|
|
18
|
+
maintenanceBps: number;
|
|
19
|
+
}
|
|
20
|
+
/** Gates use exact products. Display equity is deliberately a separate value. */
|
|
21
|
+
export declare function liquidationHealth(input: LiquidationHealthInput): {
|
|
22
|
+
eligible: boolean;
|
|
23
|
+
emergencyAllowed: boolean;
|
|
24
|
+
referenceInsolvent: boolean;
|
|
25
|
+
recoveryTargetReached: boolean;
|
|
26
|
+
distressProgressBps: number;
|
|
27
|
+
equityAtoms: bigint;
|
|
28
|
+
equityBps: number | null;
|
|
29
|
+
};
|
|
30
|
+
/** Current health determines incentives; emergency and full-close gates remain separate. A partial quote may select a smaller affordable discount (at least
|
|
31
|
+
* 50 bps). Use preview.rates.buyerDiscountBps for the actual payment terms.
|
|
32
|
+
*/
|
|
33
|
+
export declare function liquidationIncentives(input: LiquidationHealthInput): {
|
|
34
|
+
maximumBuyerDiscountBps: number;
|
|
35
|
+
/** @deprecated This is the ceiling. Read the actual discount from preview. */
|
|
36
|
+
buyerDiscountBps: number;
|
|
37
|
+
emergencyRewardBps: number;
|
|
38
|
+
emergencyAllowed: boolean;
|
|
39
|
+
};
|
|
40
|
+
/** P excludes hLP funding. H is current indexed hLP debt, including interest. */
|
|
41
|
+
export declare function liquidationInsuranceTarget(principal: bigint, hlpIndexedDebt: bigint): bigint;
|
|
42
|
+
/** Net fee atoms. Physical transfer-fee gross-ups are additional, separate costs. */
|
|
43
|
+
export declare function liquidationFeeAllocation(netDebtRepaid: bigint, insuranceBalance: bigint, target: bigint, surplusCap?: bigint): {
|
|
44
|
+
total: bigint;
|
|
45
|
+
protocol: bigint;
|
|
46
|
+
insurance: bigint;
|
|
47
|
+
lp: bigint;
|
|
48
|
+
};
|
|
49
|
+
export declare function liquidationLossAllocation(principal: bigint, debt: bigint, recovery: bigint, insuranceNetCapacity: bigint, coverageBps?: number): {
|
|
50
|
+
principalRepaid: bigint;
|
|
51
|
+
interestPaid: bigint;
|
|
52
|
+
insuranceCredit: bigint;
|
|
53
|
+
principalWrittenOff: bigint;
|
|
54
|
+
interestCanceled: bigint;
|
|
55
|
+
surplus: bigint;
|
|
56
|
+
};
|
|
57
|
+
export declare function deriveLiquidationSessionAddress(position: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
58
|
+
/** Gross a route's final debt-token transfer up to the preview's required
|
|
59
|
+
* escrow credit. This is the incoming transfer; the preview already budgets
|
|
60
|
+
* outgoing custody transfers. Use the mint's effective fee for the current
|
|
61
|
+
* epoch, and obtain a fresh quote if the epoch changes.
|
|
62
|
+
*/
|
|
63
|
+
export declare function grossLiquidationPayment(netCredit: bigint, fee: {
|
|
64
|
+
basisPoints: number;
|
|
65
|
+
maximumFee: bigint;
|
|
66
|
+
}): bigint;
|
|
67
|
+
export declare function deriveLiquidationPaymentAddress(position: PublicKey, debtMint: PublicKey, programId?: PublicKey): [PublicKey, number];
|
|
68
|
+
/** Compile the already-bound instruction list without prepending instructions
|
|
69
|
+
* that would invalidate begin's settle index. Lookup tables must be active.
|
|
70
|
+
* The caller simulates, signs and submits; this helper never sends funds.
|
|
71
|
+
*/
|
|
72
|
+
export declare function flashLiquidationV0Transaction(params: {
|
|
73
|
+
payer: PublicKey;
|
|
74
|
+
recentBlockhash: string;
|
|
75
|
+
instructions: readonly TransactionInstruction[];
|
|
76
|
+
lookupTables?: AddressLookupTableAccount[];
|
|
77
|
+
}): VersionedTransaction;
|
|
78
|
+
//# sourceMappingURL=liquidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquidation.d.ts","sourceRoot":"","sources":["../src/liquidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAsB,oBAAoB,EAAE,KAAK,yBAAyB,EAAE,KAAK,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AASnJ,eAAO,MAAM,kBAAkB;;;;;;;;;;EAU7B,CAAC;AAEH,MAAM,WAAW,sBAAsB;IACrC,+EAA+E;IAC/E,eAAe,EAAE,MAAM,CAAC;IACxB,qDAAqD;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,MAAM,CAAC;CACxB;AAQD,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB;;;;;;;;EAc9D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,sBAAsB;;IAO/D,8EAA8E;;;;EAKjF;AAED,iFAAiF;AACjF,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,MAAM,CAO5F;AAED,qFAAqF;AACrF,wBAAgB,wBAAwB,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,SAAU;;;;;EAU7H;AAED,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,oBAAoB,EAAE,MAAM,EAAE,WAAW,SAAQ;;;;;;;EAQ7I;AAED,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,YAAkB,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAErH;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CASnH;AAED,wBAAgB,+BAA+B,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,YAAkB,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,CAE1I;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,MAAM,EAAE;IACpD,KAAK,EAAE,SAAS,CAAC;IAAC,eAAe,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,SAAS,sBAAsB,EAAE,CAAC;IAC3F,YAAY,CAAC,EAAE,yBAAyB,EAAE,CAAC;CAC5C,GAAG,oBAAoB,CAGvB"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { PublicKey, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import { DEFAULT_PROTOCOL_REVENUE_SHARE_BPS, DUSK_PROGRAM_ID } from "./constants.js";
|
|
3
|
+
const BPS = 10000n;
|
|
4
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
5
|
+
const min = (a, b) => a < b ? a : b;
|
|
6
|
+
const max = (a, b) => a > b ? a : b;
|
|
7
|
+
const ceilDiv = (a, b) => (a + b - 1n) / b;
|
|
8
|
+
export const LIQUIDATION_POLICY = Object.freeze({
|
|
9
|
+
minimumDiscountBps: 50,
|
|
10
|
+
maximumDiscountBps: 500,
|
|
11
|
+
maximumEmergencyRewardBps: 100,
|
|
12
|
+
emergencyMaintenanceFractionBps: 7_000,
|
|
13
|
+
recoveryBufferBps: 200,
|
|
14
|
+
solventFeeBps: 100,
|
|
15
|
+
protocolFeeShareBps: DEFAULT_PROTOCOL_REVENUE_SHARE_BPS,
|
|
16
|
+
maximumPrincipalCoverageBps: 7_500,
|
|
17
|
+
maximumDailyInsuranceDrawBps: 5_000,
|
|
18
|
+
});
|
|
19
|
+
function amount(value, name) {
|
|
20
|
+
if (typeof value !== "bigint" || value < 0n || value > U64_MAX) {
|
|
21
|
+
throw new RangeError(`${name} must be an unsigned u64 bigint`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** Gates use exact products. Display equity is deliberately a separate value. */
|
|
25
|
+
export function liquidationHealth(input) {
|
|
26
|
+
amount(input.collateralValue, "collateralValue");
|
|
27
|
+
amount(input.debt, "debt");
|
|
28
|
+
if (!Number.isSafeInteger(input.maintenanceBps) || input.maintenanceBps <= 0 || input.maintenanceBps >= 10_000) {
|
|
29
|
+
throw new RangeError("maintenanceBps must be between 1 and 9999");
|
|
30
|
+
}
|
|
31
|
+
const value = input.collateralValue;
|
|
32
|
+
const equity = value - input.debt;
|
|
33
|
+
const required = value * BigInt(input.maintenanceBps);
|
|
34
|
+
const eligible = input.debt > 0n && (equity <= 0n || equity * BPS <= required);
|
|
35
|
+
const emergencyAllowed = input.debt > 0n && (equity <= 0n || equity * BPS * 100n <= required * 70n);
|
|
36
|
+
const distressProgressBps = input.debt === 0n ? 0n : equity <= 0n ? BPS : max(0n, required - equity * BPS) * BPS / required;
|
|
37
|
+
const recoveryTargetReached = input.debt === 0n || (equity > 0n && equity * BPS >= value * BigInt(input.maintenanceBps + 200));
|
|
38
|
+
return { eligible, emergencyAllowed, referenceInsolvent: input.debt > 0n && equity <= 0n, recoveryTargetReached, distressProgressBps: Number(distressProgressBps), equityAtoms: equity, equityBps: value === 0n ? null : Number(equity * BPS / value) };
|
|
39
|
+
}
|
|
40
|
+
/** Current health determines incentives; emergency and full-close gates remain separate. A partial quote may select a smaller affordable discount (at least
|
|
41
|
+
* 50 bps). Use preview.rates.buyerDiscountBps for the actual payment terms.
|
|
42
|
+
*/
|
|
43
|
+
export function liquidationIncentives(input) {
|
|
44
|
+
const health = liquidationHealth(input);
|
|
45
|
+
if (!health.eligible)
|
|
46
|
+
throw new Error("Position is not liquidatable");
|
|
47
|
+
const progress = BigInt(health.distressProgressBps);
|
|
48
|
+
const maximumBuyerDiscountBps = Number(50n + (450n * progress / BPS));
|
|
49
|
+
return {
|
|
50
|
+
maximumBuyerDiscountBps,
|
|
51
|
+
/** @deprecated This is the ceiling. Read the actual discount from preview. */
|
|
52
|
+
buyerDiscountBps: maximumBuyerDiscountBps,
|
|
53
|
+
emergencyRewardBps: Number((100n * progress / BPS)),
|
|
54
|
+
emergencyAllowed: health.emergencyAllowed,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/** P excludes hLP funding. H is current indexed hLP debt, including interest. */
|
|
58
|
+
export function liquidationInsuranceTarget(principal, hlpIndexedDebt) {
|
|
59
|
+
for (const [name, value] of Object.entries({ principal, hlpIndexedDebt })) {
|
|
60
|
+
if (typeof value !== "bigint" || value < 0n || value > (1n << 128n) - 1n)
|
|
61
|
+
throw new RangeError(`${name} must be an unsigned u128 bigint`);
|
|
62
|
+
}
|
|
63
|
+
const target = ceilDiv(principal, 20n) + ceilDiv(hlpIndexedDebt, 15n);
|
|
64
|
+
amount(target, "target");
|
|
65
|
+
return target;
|
|
66
|
+
}
|
|
67
|
+
/** Net fee atoms. Physical transfer-fee gross-ups are additional, separate costs. */
|
|
68
|
+
export function liquidationFeeAllocation(netDebtRepaid, insuranceBalance, target, surplusCap = U64_MAX) {
|
|
69
|
+
for (const [name, value] of Object.entries({ netDebtRepaid, insuranceBalance, target, surplusCap }))
|
|
70
|
+
amount(value, name);
|
|
71
|
+
const total = min(netDebtRepaid / 100n, surplusCap);
|
|
72
|
+
const protocol = total * BigInt(LIQUIDATION_POLICY.protocolFeeShareBps) / BPS;
|
|
73
|
+
const designated = total - protocol;
|
|
74
|
+
const shortfall = max(0n, target - insuranceBalance);
|
|
75
|
+
const insurance = target === 0n || shortfall === 0n ? 0n
|
|
76
|
+
: insuranceBalance * 4n <= target * 3n ? min(designated, shortfall)
|
|
77
|
+
: min(designated * 4n * shortfall / target, shortfall);
|
|
78
|
+
return { total, protocol, insurance, lp: designated - insurance };
|
|
79
|
+
}
|
|
80
|
+
export function liquidationLossAllocation(principal, debt, recovery, insuranceNetCapacity, coverageBps = 7_500) {
|
|
81
|
+
for (const [name, value] of Object.entries({ principal, debt, recovery, insuranceNetCapacity }))
|
|
82
|
+
amount(value, name);
|
|
83
|
+
if (principal > debt || !Number.isSafeInteger(coverageBps) || coverageBps < 0 || coverageBps > 7_500)
|
|
84
|
+
throw new RangeError("Invalid principal or insurance coverage");
|
|
85
|
+
const principalRepaid = min(principal, recovery);
|
|
86
|
+
const gap = principal - principalRepaid;
|
|
87
|
+
const insuranceCredit = min(gap * BigInt(coverageBps) / BPS, insuranceNetCapacity);
|
|
88
|
+
const interestPaid = min(debt - principal, max(0n, recovery - principal));
|
|
89
|
+
return { principalRepaid, interestPaid, insuranceCredit, principalWrittenOff: gap - insuranceCredit, interestCanceled: debt - principal - interestPaid, surplus: max(0n, recovery - debt) };
|
|
90
|
+
}
|
|
91
|
+
export function deriveLiquidationSessionAddress(position, programId = DUSK_PROGRAM_ID) {
|
|
92
|
+
return PublicKey.findProgramAddressSync([Buffer.from("liquidation-session"), position.toBuffer()], programId);
|
|
93
|
+
}
|
|
94
|
+
/** Gross a route's final debt-token transfer up to the preview's required
|
|
95
|
+
* escrow credit. This is the incoming transfer; the preview already budgets
|
|
96
|
+
* outgoing custody transfers. Use the mint's effective fee for the current
|
|
97
|
+
* epoch, and obtain a fresh quote if the epoch changes.
|
|
98
|
+
*/
|
|
99
|
+
export function grossLiquidationPayment(netCredit, fee) {
|
|
100
|
+
amount(netCredit, "netCredit");
|
|
101
|
+
amount(fee.maximumFee, "maximumFee");
|
|
102
|
+
if (!Number.isSafeInteger(fee.basisPoints) || fee.basisPoints < 0 || fee.basisPoints > 10_000)
|
|
103
|
+
throw new RangeError("Invalid transfer fee");
|
|
104
|
+
if (netCredit === 0n || fee.basisPoints === 0 || fee.maximumFee === 0n)
|
|
105
|
+
return netCredit;
|
|
106
|
+
const capped = netCredit + fee.maximumFee;
|
|
107
|
+
const gross = fee.basisPoints === 10_000 ? capped : min(capped, ceilDiv(netCredit * BPS, BPS - BigInt(fee.basisPoints)));
|
|
108
|
+
amount(gross, "grossPayment");
|
|
109
|
+
return gross;
|
|
110
|
+
}
|
|
111
|
+
export function deriveLiquidationPaymentAddress(position, debtMint, programId = DUSK_PROGRAM_ID) {
|
|
112
|
+
return PublicKey.findProgramAddressSync([Buffer.from("liquidation-payment"), position.toBuffer(), debtMint.toBuffer()], programId);
|
|
113
|
+
}
|
|
114
|
+
/** Compile the already-bound instruction list without prepending instructions
|
|
115
|
+
* that would invalidate begin's settle index. Lookup tables must be active.
|
|
116
|
+
* The caller simulates, signs and submits; this helper never sends funds.
|
|
117
|
+
*/
|
|
118
|
+
export function flashLiquidationV0Transaction(params) {
|
|
119
|
+
const message = new TransactionMessage({ payerKey: params.payer, recentBlockhash: params.recentBlockhash, instructions: [...params.instructions] }).compileToV0Message(params.lookupTables ?? []);
|
|
120
|
+
return new VersionedTransaction(message);
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=liquidation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"liquidation.js","sourceRoot":"","sources":["../src/liquidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,oBAAoB,EAA+D,MAAM,iBAAiB,CAAC;AACnJ,OAAO,EAAE,kCAAkC,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAErF,MAAM,GAAG,GAAG,MAAO,CAAC;AACpB,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,GAAG,CAAC,GAAG,EAAE,CAAC;AACjC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACpD,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,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|
|
4
|
+
* The program writes the names provided at `initialize_market`, and there is
|
|
5
|
+
* no instruction to change them afterwards, so the strings are decided once,
|
|
6
|
+
* here, for every market. No brand in the name: the token is identified by
|
|
7
|
+
* what it is and which market it belongs to.
|
|
8
|
+
*
|
|
9
|
+
* yLP name `META/USDC yLP` symbol `yME.US`
|
|
10
|
+
* jrLP name `META/USDC jrLP` symbol `jrME.US`
|
|
11
|
+
* base hLP name `META hLP` symbol `hMETA`
|
|
12
|
+
* quote hLP name `USDC hLP` symbol `hUSDC`
|
|
13
|
+
*
|
|
14
|
+
* Metaplex caps names at 32 and symbols at 10 bytes. Asset symbols are cleaned
|
|
15
|
+
* and restricted to ASCII before deterministic shortening, so character and
|
|
16
|
+
* byte limits cannot diverge.
|
|
17
|
+
*/
|
|
18
|
+
import type { MarketLpMintKind } from "./market-bootstrap.js";
|
|
19
|
+
export declare const MAX_LP_NAME_LENGTH = 32;
|
|
20
|
+
export declare const MAX_LP_SYMBOL_LENGTH = 10;
|
|
21
|
+
export declare const MAX_LP_URI_LENGTH = 200;
|
|
22
|
+
export interface LpTokenNaming {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly symbol: string;
|
|
25
|
+
/** For the off-chain metadata JSON; not written on chain. */
|
|
26
|
+
readonly description: string;
|
|
27
|
+
}
|
|
28
|
+
export interface LpTokenNamingParams {
|
|
29
|
+
kind: MarketLpMintKind | "junior";
|
|
30
|
+
baseSymbol: string;
|
|
31
|
+
quoteSymbol: string;
|
|
32
|
+
}
|
|
33
|
+
export declare function lpTokenNaming(params: LpTokenNamingParams): LpTokenNaming;
|
|
34
|
+
/** Naming for all four LP receipt kinds of one market. */
|
|
35
|
+
export declare function marketLpTokenNaming(params: Omit<LpTokenNamingParams, "kind">): Record<MarketLpMintKind | "junior", LpTokenNaming>;
|
|
36
|
+
export interface LpTokenMetadataInput {
|
|
37
|
+
name: string;
|
|
38
|
+
symbol: string;
|
|
39
|
+
uri: string;
|
|
40
|
+
}
|
|
41
|
+
/** Match the on-chain Metaplex input contract before a transaction is built. */
|
|
42
|
+
export declare function assertLpTokenMetadata(metadata: LpTokenMetadataInput): void;
|
|
43
|
+
//# sourceMappingURL=lp-naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lp-naming.d.ts","sourceRoot":"","sources":["../src/lp-naming.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,eAAO,MAAM,kBAAkB,KAAK,CAAC;AACrC,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,6DAA6D;IAC7D,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,gBAAgB,GAAG,QAAQ,CAAC;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACrB;AA6BD,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,aAAa,CA4BxE;AAED,0DAA0D;AAC1D,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,MAAM,CAAC,GACxC,MAAM,CAAC,gBAAgB,GAAG,QAAQ,EAAE,aAAa,CAAC,CAOpD;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;CACb;AAED,gFAAgF;AAChF,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,IAAI,CAc1E"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const MAX_LP_NAME_LENGTH = 32;
|
|
2
|
+
export const MAX_LP_SYMBOL_LENGTH = 10;
|
|
3
|
+
export const MAX_LP_URI_LENGTH = 200;
|
|
4
|
+
function cleanSymbol(symbol) {
|
|
5
|
+
const cleaned = symbol.trim().replace(/^\$+/, "").replace(/\s+/g, "");
|
|
6
|
+
if (cleaned.length === 0) {
|
|
7
|
+
throw new Error("asset symbol is empty");
|
|
8
|
+
}
|
|
9
|
+
if (!/^[\x21-\x7e]+$/.test(cleaned)) {
|
|
10
|
+
throw new Error("asset symbol must contain printable ASCII characters only");
|
|
11
|
+
}
|
|
12
|
+
return cleaned;
|
|
13
|
+
}
|
|
14
|
+
/** Trim two symbols, longest first, until their combined length fits. */
|
|
15
|
+
function fitPair(first, second, budget) {
|
|
16
|
+
let a = first;
|
|
17
|
+
let b = second;
|
|
18
|
+
while (a.length + b.length > budget) {
|
|
19
|
+
if (a.length >= b.length && a.length > 1) {
|
|
20
|
+
a = a.slice(0, -1);
|
|
21
|
+
}
|
|
22
|
+
else if (b.length > 1) {
|
|
23
|
+
b = b.slice(0, -1);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new Error(`cannot fit "${first}" and "${second}" into ${budget} characters`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return [a, b];
|
|
30
|
+
}
|
|
31
|
+
export function lpTokenNaming(params) {
|
|
32
|
+
const base = cleanSymbol(params.baseSymbol);
|
|
33
|
+
const quote = cleanSymbol(params.quoteSymbol);
|
|
34
|
+
const market = `${base}/${quote}`;
|
|
35
|
+
if (params.kind === "ylp" || params.kind === "junior") {
|
|
36
|
+
const junior = params.kind === "junior";
|
|
37
|
+
const symbolPrefix = junior ? "jr" : "y";
|
|
38
|
+
const nameSuffix = junior ? " jrLP" : " yLP";
|
|
39
|
+
const [na, nb] = fitPair(base, quote, MAX_LP_NAME_LENGTH - 1 - nameSuffix.length);
|
|
40
|
+
const a = base.slice(0, 2).toUpperCase();
|
|
41
|
+
const b = quote.slice(0, 2).toUpperCase();
|
|
42
|
+
return {
|
|
43
|
+
name: `${na}/${nb}${nameSuffix}`,
|
|
44
|
+
symbol: `${symbolPrefix}${a}.${b}`,
|
|
45
|
+
description: junior
|
|
46
|
+
? `Dusk jrLP for the ${market} market: productive first-loss liquidity with junior income and a notice period before conversion to yLP.`
|
|
47
|
+
: `Dusk yLP for the ${market} market: a senior share of pooled ${base} and ${quote} liquidity, protected by available insurance and junior capital against covered credit losses.`,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const side = params.kind === "baseHlp" ? base : quote;
|
|
51
|
+
const other = params.kind === "baseHlp" ? quote : base;
|
|
52
|
+
return {
|
|
53
|
+
name: `${side.slice(0, MAX_LP_NAME_LENGTH - 4)} hLP`,
|
|
54
|
+
symbol: `h${side.slice(0, MAX_LP_SYMBOL_LENGTH - 1)}`,
|
|
55
|
+
description: `Dusk hLP for ${side} in the ${market} market: a hedged, 2x leveraged liquidity share funded from the ${other} side.`,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Naming for all four LP receipt kinds of one market. */
|
|
59
|
+
export function marketLpTokenNaming(params) {
|
|
60
|
+
return {
|
|
61
|
+
ylp: lpTokenNaming({ ...params, kind: "ylp" }),
|
|
62
|
+
junior: lpTokenNaming({ ...params, kind: "junior" }),
|
|
63
|
+
baseHlp: lpTokenNaming({ ...params, kind: "baseHlp" }),
|
|
64
|
+
quoteHlp: lpTokenNaming({ ...params, kind: "quoteHlp" }),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** Match the on-chain Metaplex input contract before a transaction is built. */
|
|
68
|
+
export function assertLpTokenMetadata(metadata) {
|
|
69
|
+
if (!metadata.name || !/^[\x20-\x7e]+$/.test(metadata.name) || metadata.name.length > MAX_LP_NAME_LENGTH) {
|
|
70
|
+
throw new Error(`LP token name must be printable ASCII and at most ${MAX_LP_NAME_LENGTH} bytes`);
|
|
71
|
+
}
|
|
72
|
+
if (!metadata.symbol || !/^[\x21-\x7e]+$/.test(metadata.symbol) || metadata.symbol.length > MAX_LP_SYMBOL_LENGTH) {
|
|
73
|
+
throw new Error(`LP token symbol must be printable ASCII and at most ${MAX_LP_SYMBOL_LENGTH} bytes`);
|
|
74
|
+
}
|
|
75
|
+
if (!metadata.uri.startsWith("http")
|
|
76
|
+
|| metadata.uri.length > MAX_LP_URI_LENGTH
|
|
77
|
+
|| !/^[\x21-\x7e]+$/.test(metadata.uri)) {
|
|
78
|
+
throw new Error(`LP token URI must start with http and be at most ${MAX_LP_URI_LENGTH} bytes`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=lp-naming.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lp-naming.js","sourceRoot":"","sources":["../src/lp-naming.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AACrC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,CAAC;AACvC,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAerC,SAAS,WAAW,CAAC,MAAc;IACjC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACtE,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;IAC/E,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,yEAAyE;AACzE,SAAS,OAAO,CAAC,KAAa,EAAE,MAAc,EAAE,MAAc;IAC5D,IAAI,CAAC,GAAG,KAAK,CAAC;IAC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
|
|
4
|
+
/** The address suffix `initialize_market` requires for each LP mint kind. */
|
|
5
|
+
export declare const LP_MINT_ADDRESS_SUFFIX: Readonly<Record<MarketLpMintKind, string>>;
|
|
6
|
+
export declare const DEFAULT_VANITY_SERVER_URL = "https://vanity.omnipair.fi";
|
|
7
|
+
/** Whether `mint` satisfies the production address rule for `kind`. */
|
|
8
|
+
export declare function hasLpMintAddressSuffix(kind: MarketLpMintKind, mint: AddressLike): boolean;
|
|
9
|
+
/** The Token-2022 account address `base` and `seed` create. */
|
|
10
|
+
export declare function deriveLpMintFromSeed(base: AddressLike, seed: string): Promise<PublicKey>;
|
|
11
|
+
export interface LpMintSeed {
|
|
12
|
+
readonly kind: MarketLpMintKind;
|
|
13
|
+
readonly base: PublicKey;
|
|
14
|
+
readonly seed: string;
|
|
15
|
+
readonly mint: PublicKey;
|
|
16
|
+
}
|
|
17
|
+
export interface GrindLpMintSeedOptions {
|
|
18
|
+
kind: MarketLpMintKind;
|
|
19
|
+
/** The creator's key: it signs `createAccountWithSeed`, and it is hashed into the address. */
|
|
20
|
+
base: AddressLike;
|
|
21
|
+
serverUrl?: string;
|
|
22
|
+
/** Overall deadline for one request. The server itself never times out. */
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
fetch?: typeof fetch;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Ask the vanity server for a seed whose Token-2022 address ends in the
|
|
28
|
+
* suffix for `kind`, and verify the answer before returning it.
|
|
29
|
+
*/
|
|
30
|
+
export declare function grindLpMintSeed(options: GrindLpMintSeedOptions): Promise<LpMintSeed>;
|
|
31
|
+
/** One seed per LP mint a market needs, ground for the same base. */
|
|
32
|
+
export declare function grindMarketLpMintSeeds(options: Omit<GrindLpMintSeedOptions, "kind">): Promise<Record<MarketLpMintKind, LpMintSeed>>;
|
|
33
|
+
//# sourceMappingURL=lp-vanity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lp-vanity.d.ts","sour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GAC5C,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC,CAO/C"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vanity addresses for LP mints.
|
|
3
|
+
*
|
|
4
|
+
* Production builds of the program accept an LP mint only if its address ends
|
|
5
|
+
* in `yLP` (the yLP mint) or `hLP` (either hLP mint); the check is an exact,
|
|
6
|
+
* case-sensitive comparison on the base58 string. Rather than grinding
|
|
7
|
+
* keypairs, the mint is created at a `create_with_seed` address, and what is
|
|
8
|
+
* ground is the seed: `sha256(base ‖ seed ‖ Token-2022)` until the encoding
|
|
9
|
+
* ends in the suffix. The creator's own key is the base, so nothing new has
|
|
10
|
+
* to be kept secret and nothing new has to sign.
|
|
11
|
+
*
|
|
12
|
+
* The grinding itself runs on the vanity server (omnipair/vanity-server), the
|
|
13
|
+
* same service the V1 app used for `omLP`. Three characters cost about 200k
|
|
14
|
+
* attempts, well under a second there. Every result is re-derived locally
|
|
15
|
+
* before it is trusted.
|
|
16
|
+
*/
|
|
17
|
+
import { TOKEN_2022_PROGRAM_ID } from "@solana/spl-token";
|
|
18
|
+
import { PublicKey } from "@solana/web3.js";
|
|
19
|
+
import { address } from "./address.js";
|
|
20
|
+
/** The address suffix `initialize_market` requires for each LP mint kind. */
|
|
21
|
+
export const LP_MINT_ADDRESS_SUFFIX = {
|
|
22
|
+
ylp: "yLP",
|
|
23
|
+
baseHlp: "hLP",
|
|
24
|
+
quoteHlp: "hLP",
|
|
25
|
+
};
|
|
26
|
+
export const DEFAULT_VANITY_SERVER_URL = "https://vanity.omnipair.fi";
|
|
27
|
+
/** Whether `mint` satisfies the production address rule for `kind`. */
|
|
28
|
+
export function hasLpMintAddressSuffix(kind, mint) {
|
|
29
|
+
return address(mint).toBase58().endsWith(LP_MINT_ADDRESS_SUFFIX[kind]);
|
|
30
|
+
}
|
|
31
|
+
/** The Token-2022 account address `base` and `seed` create. */
|
|
32
|
+
export function deriveLpMintFromSeed(base, seed) {
|
|
33
|
+
return PublicKey.createWithSeed(address(base), seed, TOKEN_2022_PROGRAM_ID);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Ask the vanity server for a seed whose Token-2022 address ends in the
|
|
37
|
+
* suffix for `kind`, and verify the answer before returning it.
|
|
38
|
+
*/
|
|
39
|
+
export async function grindLpMintSeed(options) {
|
|
40
|
+
const base = address(options.base);
|
|
41
|
+
const suffix = LP_MINT_ADDRESS_SUFFIX[options.kind];
|
|
42
|
+
const serverUrl = (options.serverUrl ?? DEFAULT_VANITY_SERVER_URL).replace(/\/+$/, "");
|
|
43
|
+
const url = new URL(`${serverUrl}/grind`);
|
|
44
|
+
url.searchParams.set("base", base.toBase58());
|
|
45
|
+
url.searchParams.set("suffix", suffix);
|
|
46
|
+
url.searchParams.set("owner", TOKEN_2022_PROGRAM_ID.toBase58());
|
|
47
|
+
const doFetch = options.fetch ?? globalThis.fetch;
|
|
48
|
+
if (typeof doFetch !== "function") {
|
|
49
|
+
throw new Error("grindLpMintSeed needs a fetch implementation");
|
|
50
|
+
}
|
|
51
|
+
const controller = new AbortController();
|
|
52
|
+
const timer = setTimeout(() => controller.abort(), options.timeoutMs ?? 120_000);
|
|
53
|
+
let body;
|
|
54
|
+
try {
|
|
55
|
+
const response = await doFetch(url, { signal: controller.signal });
|
|
56
|
+
body = (await response.json().catch(() => ({})));
|
|
57
|
+
if (!response.ok) {
|
|
58
|
+
throw new Error(`vanity server ${response.status}: ${typeof body.error === "string" ? body.error : "grind failed"}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
clearTimeout(timer);
|
|
63
|
+
}
|
|
64
|
+
if (typeof body.seed !== "string" || typeof body.address !== "string") {
|
|
65
|
+
throw new Error("vanity server returned no seed");
|
|
66
|
+
}
|
|
67
|
+
// The server drops a suffix it cannot parse and grinds unconstrained; it
|
|
68
|
+
// echoes what it actually used, so an echo that differs means the result is
|
|
69
|
+
// not what was asked for.
|
|
70
|
+
if (body.suffix !== suffix) {
|
|
71
|
+
throw new Error(`vanity server ground suffix ${JSON.stringify(body.suffix)}, not ${suffix}`);
|
|
72
|
+
}
|
|
73
|
+
if (body.owner !== TOKEN_2022_PROGRAM_ID.toBase58()) {
|
|
74
|
+
throw new Error(`vanity server ground for owner ${String(body.owner)}, not Token-2022`);
|
|
75
|
+
}
|
|
76
|
+
const mint = await deriveLpMintFromSeed(base, body.seed);
|
|
77
|
+
if (mint.toBase58() !== body.address) {
|
|
78
|
+
throw new Error(`vanity server address ${body.address} does not derive from base ${base.toBase58()} and seed "${body.seed}"`);
|
|
79
|
+
}
|
|
80
|
+
if (!hasLpMintAddressSuffix(options.kind, mint)) {
|
|
81
|
+
throw new Error(`derived mint ${mint.toBase58()} does not end in ${suffix}`);
|
|
82
|
+
}
|
|
83
|
+
return { kind: options.kind, base, seed: body.seed, mint };
|
|
84
|
+
}
|
|
85
|
+
/** One seed per LP mint a market needs, ground for the same base. */
|
|
86
|
+
export async function grindMarketLpMintSeeds(options) {
|
|
87
|
+
const [ylp, baseHlp, quoteHlp] = await Promise.all([
|
|
88
|
+
grindLpMintSeed({ ...options, kind: "ylp" }),
|
|
89
|
+
grindLpMintSeed({ ...options, kind: "baseHlp" }),
|
|
90
|
+
grindLpMintSeed({ ...options, kind: "quoteHlp" }),
|
|
91
|
+
]);
|
|
92
|
+
return { ylp, baseHlp, quoteHlp };
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=lp-vanity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lp-vanity.js","sourceRoot":"","sources":["../src/lp-vanity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAoB,MAAM,cAAc,CAAC;AAGzD,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AO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;KAClD,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Keypair, PublicKey, type Connection, type TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import { type AddressLike } from "./address.js";
|
|
3
|
+
/** Every LP mint a market needs, in the order `initialize_market` takes them. */
|
|
4
|
+
export declare const MARKET_LP_MINT_KINDS: readonly ["ylp", "baseHlp", "quoteHlp"];
|
|
5
|
+
export type MarketLpMintKind = (typeof MARKET_LP_MINT_KINDS)[number];
|
|
6
|
+
/**
|
|
7
|
+
* A market's identity is its parameter hash, so two markets over the same pair
|
|
8
|
+
* are distinct only if their hashes are. The namespace keeps deployments from
|
|
9
|
+
* colliding: the same label and pair on devnet and mainnet hash differently.
|
|
10
|
+
*/
|
|
11
|
+
export declare function deriveMarketParamsHash(params: {
|
|
12
|
+
namespace: string;
|
|
13
|
+
label: string;
|
|
14
|
+
baseMint: AddressLike;
|
|
15
|
+
quoteMint: AddressLike;
|
|
16
|
+
}): Promise<Uint8Array>;
|
|
17
|
+
/**
|
|
18
|
+
* The parameters a market launches with.
|
|
19
|
+
*
|
|
20
|
+
* Every field is required rather than defaulted, because a market's economics
|
|
21
|
+
* are not something to inherit silently from a library version — see
|
|
22
|
+
* `defaultMarketLaunchConfig` for a starting point that can be overridden
|
|
23
|
+
* field by field.
|
|
24
|
+
*/
|
|
25
|
+
export interface MarketLaunchConfig {
|
|
26
|
+
swapFeeBps: number;
|
|
27
|
+
divergenceFeeShareCapBps: number;
|
|
28
|
+
volatilityFeeShareCapBps: number;
|
|
29
|
+
targetHlpLeverageBps: number;
|
|
30
|
+
settlementDivergenceBps: number;
|
|
31
|
+
emaHalfLifeMs: bigint | number | string;
|
|
32
|
+
directionalEmaHalfLifeMs: bigint | number | string;
|
|
33
|
+
curveDepthEmaHalfLifeMs: bigint | number | string;
|
|
34
|
+
maxDailyBorrowBps: number;
|
|
35
|
+
globalHealthContributionCapBps: number;
|
|
36
|
+
borrowMarketHealthFloorBps: number;
|
|
37
|
+
amm: Record<string, unknown>;
|
|
38
|
+
irm: Record<string, unknown>;
|
|
39
|
+
startTime: bigint | number | string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The configuration the devnet markets launched with, and a reasonable
|
|
43
|
+
* starting point for a new one. The zeroed AMM fields switch off the
|
|
44
|
+
* launch-fee ramp, the rate limiter and the dynamic fee coefficients: a market
|
|
45
|
+
* that wants any of those should set them deliberately.
|
|
46
|
+
*/
|
|
47
|
+
export declare function defaultMarketLaunchConfig(overrides?: Partial<MarketLaunchConfig>): MarketLaunchConfig;
|
|
48
|
+
export interface HookedLpMint {
|
|
49
|
+
/** Must sign the transaction carrying these instructions. */
|
|
50
|
+
readonly keypair: Keypair;
|
|
51
|
+
readonly mint: PublicKey;
|
|
52
|
+
readonly instructions: readonly TransactionInstruction[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create one transfer-hooked LP mint.
|
|
56
|
+
*
|
|
57
|
+
* The extension has to be initialized between allocating the account and
|
|
58
|
+
* initializing the mint, and the account has to be sized for it up front —
|
|
59
|
+
* a mint initialized without the space cannot gain the extension afterwards.
|
|
60
|
+
* The hook authority is left unset (`PublicKey.default`) so nothing can
|
|
61
|
+
* repoint it; the program is the hook and that is fixed at creation.
|
|
62
|
+
*/
|
|
63
|
+
export declare function createHookedLpMintInstructions(params: {
|
|
64
|
+
payer: AddressLike;
|
|
65
|
+
decimals: number;
|
|
66
|
+
/** The market PDA, which owns every LP mint it issues. */
|
|
67
|
+
mintAuthority: AddressLike;
|
|
68
|
+
transferHookProgramId: AddressLike;
|
|
69
|
+
/** From `getMinimumBalanceForRentExemption(lpMintLen())`. */
|
|
70
|
+
lamports: number;
|
|
71
|
+
/** Supply one to reproduce a known mint; otherwise a fresh key. */
|
|
72
|
+
keypair?: Keypair;
|
|
73
|
+
}): HookedLpMint;
|
|
74
|
+
export interface SeededLpMint {
|
|
75
|
+
/** Signs `createAccountWithSeed`: the wallet the seed was ground for. */
|
|
76
|
+
readonly base: PublicKey;
|
|
77
|
+
readonly seed: string;
|
|
78
|
+
readonly mint: PublicKey;
|
|
79
|
+
readonly instructions: readonly TransactionInstruction[];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create one transfer-hooked LP mint at a `create_with_seed` address.
|
|
83
|
+
*
|
|
84
|
+
* The mint address is `sha256(base ‖ seed ‖ Token-2022 program)`, so the
|
|
85
|
+
* creator can grind seeds until the address ends in the suffix
|
|
86
|
+
* `initialize_market` demands in production builds, and no second keypair
|
|
87
|
+
* ever exists: only `base` and the payer sign. The owner program is part of
|
|
88
|
+
* the derivation, which is why a seed ground for the SPL Token program does
|
|
89
|
+
* not produce the same address here.
|
|
90
|
+
*/
|
|
91
|
+
export declare function createHookedLpMintWithSeedInstructions(params: {
|
|
92
|
+
payer: AddressLike;
|
|
93
|
+
/** The key the seed was ground against. Must sign. */
|
|
94
|
+
base: AddressLike;
|
|
95
|
+
seed: string;
|
|
96
|
+
decimals: number;
|
|
97
|
+
/** The market PDA, which owns every LP mint it issues. */
|
|
98
|
+
mintAuthority: AddressLike;
|
|
99
|
+
transferHookProgramId: AddressLike;
|
|
100
|
+
/** From `getMinimumBalanceForRentExemption(lpMintLen())`. */
|
|
101
|
+
lamports: number;
|
|
102
|
+
/** The address the seed was ground for; rejected unless it derives from `base` and `seed`. */
|
|
103
|
+
mint?: AddressLike;
|
|
104
|
+
}): Promise<SeededLpMint>;
|
|
105
|
+
/** Account size of an LP mint, which is a Token-2022 mint plus the hook. */
|
|
106
|
+
export declare function lpMintLen(): number;
|
|
107
|
+
/** Rent for one LP mint, to pass to `createHookedLpMintInstructions`. */
|
|
108
|
+
export declare function lpMintRent(connection: Connection): Promise<number>;
|
|
109
|
+
//# sourceMappingURL=market-bootstrap.d.ts.map
|
|
@@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