@vultisig/core-chain 2.37.0 → 2.38.0
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/CHANGELOG.md +8 -0
- package/dist/chains/solana/kamino/KaminoServiceError.d.ts +63 -0
- package/dist/chains/solana/kamino/KaminoServiceError.d.ts.map +1 -0
- package/dist/chains/solana/kamino/KaminoServiceError.js +29 -0
- package/dist/chains/solana/kamino/KaminoServiceError.js.map +1 -0
- package/dist/chains/solana/kamino/amount.d.ts +141 -0
- package/dist/chains/solana/kamino/amount.d.ts.map +1 -0
- package/dist/chains/solana/kamino/amount.js +156 -0
- package/dist/chains/solana/kamino/amount.js.map +1 -0
- package/dist/chains/solana/kamino/api.d.ts +20 -0
- package/dist/chains/solana/kamino/api.d.ts.map +1 -0
- package/dist/chains/solana/kamino/api.js +59 -0
- package/dist/chains/solana/kamino/api.js.map +1 -0
- package/dist/chains/solana/kamino/baseUnits.d.ts +23 -0
- package/dist/chains/solana/kamino/baseUnits.d.ts.map +1 -0
- package/dist/chains/solana/kamino/baseUnits.js +30 -0
- package/dist/chains/solana/kamino/baseUnits.js.map +1 -0
- package/dist/chains/solana/kamino/config.d.ts +27 -0
- package/dist/chains/solana/kamino/config.d.ts.map +1 -0
- package/dist/chains/solana/kamino/config.js +27 -0
- package/dist/chains/solana/kamino/config.js.map +1 -0
- package/dist/chains/solana/kamino/decimal.d.ts +24 -0
- package/dist/chains/solana/kamino/decimal.d.ts.map +1 -0
- package/dist/chains/solana/kamino/decimal.js +52 -0
- package/dist/chains/solana/kamino/decimal.js.map +1 -0
- package/dist/chains/solana/kamino/models.d.ts +148 -0
- package/dist/chains/solana/kamino/models.d.ts.map +1 -0
- package/dist/chains/solana/kamino/models.js +2 -0
- package/dist/chains/solana/kamino/models.js.map +1 -0
- package/dist/chains/solana/kamino/position.d.ts +79 -0
- package/dist/chains/solana/kamino/position.d.ts.map +1 -0
- package/dist/chains/solana/kamino/position.js +52 -0
- package/dist/chains/solana/kamino/position.js.map +1 -0
- package/dist/chains/solana/kamino/rate.d.ts +57 -0
- package/dist/chains/solana/kamino/rate.d.ts.map +1 -0
- package/dist/chains/solana/kamino/rate.js +88 -0
- package/dist/chains/solana/kamino/rate.js.map +1 -0
- package/dist/chains/solana/kamino/registry.d.ts +70 -0
- package/dist/chains/solana/kamino/registry.d.ts.map +1 -0
- package/dist/chains/solana/kamino/registry.js +67 -0
- package/dist/chains/solana/kamino/registry.js.map +1 -0
- package/dist/chains/solana/kamino/tx/actions.d.ts +22 -0
- package/dist/chains/solana/kamino/tx/actions.d.ts.map +1 -0
- package/dist/chains/solana/kamino/tx/actions.js +85 -0
- package/dist/chains/solana/kamino/tx/actions.js.map +1 -0
- package/dist/chains/solana/kamino/tx/computeBudget.d.ts +66 -0
- package/dist/chains/solana/kamino/tx/computeBudget.d.ts.map +1 -0
- package/dist/chains/solana/kamino/tx/computeBudget.js +73 -0
- package/dist/chains/solana/kamino/tx/computeBudget.js.map +1 -0
- package/dist/chains/solana/kamino/tx/decode.d.ts +121 -0
- package/dist/chains/solana/kamino/tx/decode.d.ts.map +1 -0
- package/dist/chains/solana/kamino/tx/decode.js +458 -0
- package/dist/chains/solana/kamino/tx/decode.js.map +1 -0
- package/dist/chains/solana/kamino/tx/instructions.d.ts +260 -0
- package/dist/chains/solana/kamino/tx/instructions.d.ts.map +1 -0
- package/dist/chains/solana/kamino/tx/instructions.js +256 -0
- package/dist/chains/solana/kamino/tx/instructions.js.map +1 -0
- package/dist/chains/solana/kamino/tx/sequence.d.ts +123 -0
- package/dist/chains/solana/kamino/tx/sequence.d.ts.map +1 -0
- package/dist/chains/solana/kamino/tx/sequence.js +235 -0
- package/dist/chains/solana/kamino/tx/sequence.js.map +1 -0
- package/dist/chains/solana/kamino/tx/validate.d.ts +138 -0
- package/dist/chains/solana/kamino/tx/validate.d.ts.map +1 -0
- package/dist/chains/solana/kamino/tx/validate.js +542 -0
- package/dist/chains/solana/kamino/tx/validate.js.map +1 -0
- package/dist/chains/solana/kamino/tx/wire.d.ts +107 -0
- package/dist/chains/solana/kamino/tx/wire.d.ts.map +1 -0
- package/dist/chains/solana/kamino/tx/wire.js +274 -0
- package/dist/chains/solana/kamino/tx/wire.js.map +1 -0
- package/dist/chains/solana/kamino/vaultInfo.d.ts +17 -0
- package/dist/chains/solana/kamino/vaultInfo.d.ts.map +1 -0
- package/dist/chains/solana/kamino/vaultInfo.js +150 -0
- package/dist/chains/solana/kamino/vaultInfo.js.map +1 -0
- package/package.json +91 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants for Kamino Earn vaults (kVaults) on Solana.
|
|
3
|
+
*
|
|
4
|
+
* The REST API is public and unauthenticated — the action endpoints build an
|
|
5
|
+
* unsigned transaction from the caller's wallet address alone, which is why
|
|
6
|
+
* every built transaction must be validated on-device before it is signed.
|
|
7
|
+
*/
|
|
8
|
+
export const kaminoConfig = {
|
|
9
|
+
/** Kamino's public REST API. No key, no auth header. */
|
|
10
|
+
apiBaseUrl: 'https://api.kamino.finance',
|
|
11
|
+
/** The kVaults program every deposit and withdraw invokes. */
|
|
12
|
+
programId: 'KvauGMspG5k6rtzrqqn7WNn3oZdyKqLKwK2XWQ8FLjd',
|
|
13
|
+
/**
|
|
14
|
+
* Kamino's farms program. Every launch vault has a farm attached, so a
|
|
15
|
+
* deposit ends with `initializeUser` + `stake` against this program and the
|
|
16
|
+
* shares never land in the user's wallet.
|
|
17
|
+
*/
|
|
18
|
+
farmsProgramId: 'FarmsPZpWu9i7Kky8tPN37rs2TpmMrAZrC7S7vJa91Hr',
|
|
19
|
+
/**
|
|
20
|
+
* Wrapped SOL. The SOL vault's underlying token is this mint, not native
|
|
21
|
+
* SOL, which is why its deposits carry a wrap prefix.
|
|
22
|
+
*/
|
|
23
|
+
wrappedSolMint: 'So11111111111111111111111111111111111111112',
|
|
24
|
+
/** Circle's USDC — the underlying token of both dollar vaults. */
|
|
25
|
+
usdcMint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/solana/kamino/config.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,wDAAwD;IACxD,UAAU,EAAE,4BAA4B;IAExC,8DAA8D;IAC9D,SAAS,EAAE,6CAA6C;IAExD;;;;OAIG;IACH,cAAc,EAAE,8CAA8C;IAE9D;;;OAGG;IACH,cAAc,EAAE,6CAA6C;IAE7D,kEAAkE;IAClE,QAAQ,EAAE,8CAA8C;CAChD,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict-format parsing for Kamino's numeric JSON, which arrives as decimal
|
|
3
|
+
* strings (`"0.03994268764493801732"`, `"1.0536041812651029025"`).
|
|
4
|
+
*
|
|
5
|
+
* The format is validated rather than coerced: grouping separators, exponents
|
|
6
|
+
* and whitespace are rejected instead of being silently mis-read. What this
|
|
7
|
+
* does not guarantee is exactness — a JS `number` holds ~16 significant digits
|
|
8
|
+
* and Kamino publishes longer values. That is acceptable for the display
|
|
9
|
+
* values `parseKaminoDisplayDecimal` is used on (APY, PnL, prices). Anything
|
|
10
|
+
* that sizes a transaction must use `KaminoRate`, which is exact.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Whether `raw` is a plain decimal string: optional leading `-`, ASCII digits,
|
|
14
|
+
* at most one `.`, at least one digit. Everything else — grouping separators,
|
|
15
|
+
* exponents, whitespace, non-ASCII digits — is rejected.
|
|
16
|
+
*/
|
|
17
|
+
export declare const isPlainKaminoDecimal: (raw: string) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Parses a display-only value (APY, price, PnL) after strict format
|
|
20
|
+
* validation, or `undefined` when the format is not a plain decimal. Never use
|
|
21
|
+
* the result to size a transaction — it round-trips through a binary double.
|
|
22
|
+
*/
|
|
23
|
+
export declare const parseKaminoDisplayDecimal: (raw: string) => number | undefined;
|
|
24
|
+
//# sourceMappingURL=decimal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decimal.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/solana/kamino/decimal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,MAAM,KAAG,OAmBlD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,KAAK,MAAM,KAAG,MAAM,GAAG,SAGhE,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict-format parsing for Kamino's numeric JSON, which arrives as decimal
|
|
3
|
+
* strings (`"0.03994268764493801732"`, `"1.0536041812651029025"`).
|
|
4
|
+
*
|
|
5
|
+
* The format is validated rather than coerced: grouping separators, exponents
|
|
6
|
+
* and whitespace are rejected instead of being silently mis-read. What this
|
|
7
|
+
* does not guarantee is exactness — a JS `number` holds ~16 significant digits
|
|
8
|
+
* and Kamino publishes longer values. That is acceptable for the display
|
|
9
|
+
* values `parseKaminoDisplayDecimal` is used on (APY, PnL, prices). Anything
|
|
10
|
+
* that sizes a transaction must use `KaminoRate`, which is exact.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Whether `raw` is a plain decimal string: optional leading `-`, ASCII digits,
|
|
14
|
+
* at most one `.`, at least one digit. Everything else — grouping separators,
|
|
15
|
+
* exponents, whitespace, non-ASCII digits — is rejected.
|
|
16
|
+
*/
|
|
17
|
+
export const isPlainKaminoDecimal = (raw) => {
|
|
18
|
+
if (!raw)
|
|
19
|
+
return false;
|
|
20
|
+
let hasDigit = false;
|
|
21
|
+
let hasSeparator = false;
|
|
22
|
+
for (let index = 0; index < raw.length; index++) {
|
|
23
|
+
const character = raw[index];
|
|
24
|
+
if (character === '-') {
|
|
25
|
+
if (index !== 0)
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
else if (character === '.') {
|
|
29
|
+
if (hasSeparator)
|
|
30
|
+
return false;
|
|
31
|
+
hasSeparator = true;
|
|
32
|
+
}
|
|
33
|
+
else if (character >= '0' && character <= '9') {
|
|
34
|
+
hasDigit = true;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return hasDigit;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Parses a display-only value (APY, price, PnL) after strict format
|
|
44
|
+
* validation, or `undefined` when the format is not a plain decimal. Never use
|
|
45
|
+
* the result to size a transaction — it round-trips through a binary double.
|
|
46
|
+
*/
|
|
47
|
+
export const parseKaminoDisplayDecimal = (raw) => {
|
|
48
|
+
if (!isPlainKaminoDecimal(raw))
|
|
49
|
+
return undefined;
|
|
50
|
+
return Number(raw);
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=decimal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decimal.js","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/solana/kamino/decimal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAW,EAAW,EAAE;IAC3D,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAA;IAEtB,IAAI,QAAQ,GAAG,KAAK,CAAA;IACpB,IAAI,YAAY,GAAG,KAAK,CAAA;IACxB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAChD,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,CAAA;QAC5B,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;YACtB,IAAI,KAAK,KAAK,CAAC;gBAAE,OAAO,KAAK,CAAA;QAC/B,CAAC;aAAM,IAAI,SAAS,KAAK,GAAG,EAAE,CAAC;YAC7B,IAAI,YAAY;gBAAE,OAAO,KAAK,CAAA;YAC9B,YAAY,GAAG,IAAI,CAAA;QACrB,CAAC;aAAM,IAAI,SAAS,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,EAAE,CAAC;YAChD,QAAQ,GAAG,IAAI,CAAA;QACjB,CAAC;aAAM,CAAC;YACN,OAAO,KAAK,CAAA;QACd,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,GAAW,EAAsB,EAAE;IAC3E,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC;QAAE,OAAO,SAAS,CAAA;IAChD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAA;AACpB,CAAC,CAAA"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { KaminoShareAmount, KaminoTokenAmount } from './amount.js';
|
|
2
|
+
import { KaminoRate } from './rate.js';
|
|
3
|
+
import { KaminoVaultDescriptor } from './registry.js';
|
|
4
|
+
/**
|
|
5
|
+
* `GET /kvaults/vaults/{address}`. Every numeric field arrives as a string;
|
|
6
|
+
* nothing here may be consumed without going through the typed amounts.
|
|
7
|
+
*/
|
|
8
|
+
export type KaminoVaultStateResponse = {
|
|
9
|
+
address: string;
|
|
10
|
+
programId: string;
|
|
11
|
+
state: {
|
|
12
|
+
name: string;
|
|
13
|
+
tokenMint: string;
|
|
14
|
+
tokenMintDecimals: number;
|
|
15
|
+
sharesMint: string;
|
|
16
|
+
/**
|
|
17
|
+
* Share decimals are independent of token decimals — across the live vault
|
|
18
|
+
* set the pairs include (6,6), (6,9), (8,8) and (9,9). Never assume they
|
|
19
|
+
* match.
|
|
20
|
+
*/
|
|
21
|
+
sharesMintDecimals: number;
|
|
22
|
+
/**
|
|
23
|
+
* Base units of the **underlying token**. Correctly denominated, unlike
|
|
24
|
+
* `minWithdrawAmount` — but still not a figure the program accepts: a
|
|
25
|
+
* deposit at exactly this amount is refused. Only the effective-minimum
|
|
26
|
+
* derivation in `fetchKaminoVaultInfo` may read it.
|
|
27
|
+
*/
|
|
28
|
+
minDepositAmount: string;
|
|
29
|
+
/**
|
|
30
|
+
* Base units of the **underlying token**, despite naming the unit the
|
|
31
|
+
* withdraw endpoint takes. Reading it as a share count is a silent error on
|
|
32
|
+
* a dollar vault (the rate is near 1) and a ~930× one on the SOL vault. It
|
|
33
|
+
* is also not the floor the program enforces — see the effective-minimum
|
|
34
|
+
* derivation in `fetchKaminoVaultInfo`, which is what forms should use.
|
|
35
|
+
* Nothing but that derivation may read this field.
|
|
36
|
+
*/
|
|
37
|
+
minWithdrawAmount: string;
|
|
38
|
+
/** Address lookup table the built transactions reference. */
|
|
39
|
+
vaultLookupTable: string;
|
|
40
|
+
/**
|
|
41
|
+
* When set, deposits auto-stake the shares into this farm and they never
|
|
42
|
+
* appear in the user's associated token account.
|
|
43
|
+
*/
|
|
44
|
+
vaultFarm: string;
|
|
45
|
+
performanceFeeBps: number;
|
|
46
|
+
managementFeeBps: number;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* `GET /kvaults/vaults/{address}/metrics`. Every numeric field is a decimal
|
|
51
|
+
* string; APYs are fractions (`"0.0391"` = 3.91%), not percentages.
|
|
52
|
+
*/
|
|
53
|
+
export type KaminoVaultMetricsResponse = {
|
|
54
|
+
apy30d: string;
|
|
55
|
+
/** Underlying tokens per share — the rate for valuing a position. */
|
|
56
|
+
tokensPerShare: string;
|
|
57
|
+
/** USD per share. NOT interchangeable with `tokensPerShare`. */
|
|
58
|
+
sharePrice: string;
|
|
59
|
+
tokenPrice: string;
|
|
60
|
+
tokensAvailable: string;
|
|
61
|
+
tokensInvested: string;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* One element of `GET /kvaults/users/{owner}/positions`. Shares only — the
|
|
65
|
+
* endpoint returns no token or fiat value.
|
|
66
|
+
*/
|
|
67
|
+
export type KaminoUserPositionResponse = {
|
|
68
|
+
vaultAddress: string;
|
|
69
|
+
/**
|
|
70
|
+
* Shares held inside the vault's farm. For a farmed vault this is where a
|
|
71
|
+
* deposit lands, so it is normally the whole position.
|
|
72
|
+
*/
|
|
73
|
+
stakedShares: string;
|
|
74
|
+
/** Shares sitting in the user's associated token account. */
|
|
75
|
+
unstakedShares: string;
|
|
76
|
+
totalShares: string;
|
|
77
|
+
};
|
|
78
|
+
/** `GET /kvaults/users/{owner}/vaults/{vault}/pnl`. */
|
|
79
|
+
export type KaminoPnlResponse = {
|
|
80
|
+
totalCostBasis: KaminoPnlAmounts;
|
|
81
|
+
totalPnl: KaminoPnlAmounts;
|
|
82
|
+
};
|
|
83
|
+
/** One PnL figure expressed in the three denominations the API reports. */
|
|
84
|
+
export type KaminoPnlAmounts = {
|
|
85
|
+
token: string;
|
|
86
|
+
sol: string;
|
|
87
|
+
usd: string;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* A launch vault after its registry entry has been merged with live API state
|
|
91
|
+
* and metrics. This is what the feature layer consumes; the raw responses stay
|
|
92
|
+
* at the service boundary. The vault's identity (mints, decimals, farm) is
|
|
93
|
+
* read from `descriptor` — the registry's record — never from the response: a
|
|
94
|
+
* transaction built by the API cannot be validated against values the same API
|
|
95
|
+
* supplied.
|
|
96
|
+
*/
|
|
97
|
+
export type KaminoVaultInfo = {
|
|
98
|
+
descriptor: KaminoVaultDescriptor;
|
|
99
|
+
/** On-chain vault name (`"Steakhouse USDC"`). */
|
|
100
|
+
name: string;
|
|
101
|
+
/**
|
|
102
|
+
* The smallest deposit a form may offer.
|
|
103
|
+
*
|
|
104
|
+
* DERIVED: the published `minDepositAmount` plus a margin, because the
|
|
105
|
+
* program refuses a deposit at exactly the published figure. See
|
|
106
|
+
* `fetchKaminoVaultInfo`.
|
|
107
|
+
*/
|
|
108
|
+
minDeposit: KaminoTokenAmount;
|
|
109
|
+
/**
|
|
110
|
+
* The smallest withdraw a form may offer, in SHARE base units.
|
|
111
|
+
*
|
|
112
|
+
* DERIVED, not `state.minWithdrawAmount` read at face value: that field is
|
|
113
|
+
* denominated in the underlying token and the program's own floor is higher
|
|
114
|
+
* than it. Because the derivation goes through `tokensPerShare`, this figure
|
|
115
|
+
* moves with the rate, and it is hydrated in the same response.
|
|
116
|
+
*/
|
|
117
|
+
minWithdraw: KaminoShareAmount;
|
|
118
|
+
/**
|
|
119
|
+
* The address lookup table the built transactions reference.
|
|
120
|
+
*
|
|
121
|
+
* Live rather than pinned: unlike the mints and the farm, Kamino can
|
|
122
|
+
* legitimately repoint a vault at a new table. A substituted table renames
|
|
123
|
+
* an account into a mismatch rather than out of one, so no transaction check
|
|
124
|
+
* rests on it.
|
|
125
|
+
*/
|
|
126
|
+
lookupTable: string;
|
|
127
|
+
/** 30-day APY as a fraction (0.0391 = 3.91%). Display-only. */
|
|
128
|
+
apy30d: number;
|
|
129
|
+
/**
|
|
130
|
+
* Underlying tokens per share, kept exact: this rate sizes a withdraw, and a
|
|
131
|
+
* rounding error in it can over-request shares.
|
|
132
|
+
*/
|
|
133
|
+
tokensPerShare: KaminoRate;
|
|
134
|
+
/** USD price of the underlying token. Display-only. */
|
|
135
|
+
tokenPriceUsd: number;
|
|
136
|
+
/**
|
|
137
|
+
* The underlying balance the vault currently holds liquid, rather than
|
|
138
|
+
* invested in lending reserves. `undefined` when the metrics response did
|
|
139
|
+
* not carry a readable value.
|
|
140
|
+
*
|
|
141
|
+
* Advisory only — it says what a withdraw is likely to be able to settle
|
|
142
|
+
* immediately, and nothing sizes a transaction from it. The measured ratio
|
|
143
|
+
* is well under 1% of the launch vaults, so a withdraw above this buffer is
|
|
144
|
+
* the ordinary case, not an exception.
|
|
145
|
+
*/
|
|
146
|
+
tokensAvailable?: KaminoTokenAmount;
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/solana/kamino/models.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAElD;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,MAAM,CAAA;IACf,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,SAAS,EAAE,MAAM,CAAA;QACjB,iBAAiB,EAAE,MAAM,CAAA;QACzB,UAAU,EAAE,MAAM,CAAA;QAClB;;;;WAIG;QACH,kBAAkB,EAAE,MAAM,CAAA;QAC1B;;;;;WAKG;QACH,gBAAgB,EAAE,MAAM,CAAA;QACxB;;;;;;;WAOG;QACH,iBAAiB,EAAE,MAAM,CAAA;QACzB,6DAA6D;QAC7D,gBAAgB,EAAE,MAAM,CAAA;QACxB;;;WAGG;QACH,SAAS,EAAE,MAAM,CAAA;QACjB,iBAAiB,EAAE,MAAM,CAAA;QACzB,gBAAgB,EAAE,MAAM,CAAA;KACzB,CAAA;CACF,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,MAAM,EAAE,MAAM,CAAA;IACd,qEAAqE;IACrE,cAAc,EAAE,MAAM,CAAA;IACtB,gEAAgE;IAChE,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,eAAe,EAAE,MAAM,CAAA;IACvB,cAAc,EAAE,MAAM,CAAA;CACvB,CAAA;AAED;;;GAGG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,YAAY,EAAE,MAAM,CAAA;IACpB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAA;IACpB,6DAA6D;IAC7D,cAAc,EAAE,MAAM,CAAA;IACtB,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,uDAAuD;AACvD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,gBAAgB,CAAA;IAChC,QAAQ,EAAE,gBAAgB,CAAA;CAC3B,CAAA;AAED,2EAA2E;AAC3E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,qBAAqB,CAAA;IACjC,iDAAiD;IACjD,IAAI,EAAE,MAAM,CAAA;IACZ;;;;;;OAMG;IACH,UAAU,EAAE,iBAAiB,CAAA;IAC7B;;;;;;;OAOG;IACH,WAAW,EAAE,iBAAiB,CAAA;IAC9B;;;;;;;OAOG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,+DAA+D;IAC/D,MAAM,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,cAAc,EAAE,UAAU,CAAA;IAC1B,uDAAuD;IACvD,aAAa,EAAE,MAAM,CAAA;IACrB;;;;;;;;;OASG;IACH,eAAe,CAAC,EAAE,iBAAiB,CAAA;CACpC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/solana/kamino/models.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { KaminoShareAmount } from './amount.js';
|
|
2
|
+
import { KaminoUserPositionResponse } from './models.js';
|
|
3
|
+
/**
|
|
4
|
+
* The user's share balance in one vault, split the way `/positions` reports
|
|
5
|
+
* it.
|
|
6
|
+
*
|
|
7
|
+
* Shares, never tokens: the withdraw endpoint takes shares and the balance a
|
|
8
|
+
* full withdraw must send is a share count. The token figure a form is
|
|
9
|
+
* denominated in is a projection of these at the current rate, and it is
|
|
10
|
+
* derived — never the other way round.
|
|
11
|
+
*/
|
|
12
|
+
export type KaminoSharePosition = {
|
|
13
|
+
staked: KaminoShareAmount;
|
|
14
|
+
unstaked: KaminoShareAmount;
|
|
15
|
+
total: KaminoShareAmount;
|
|
16
|
+
/**
|
|
17
|
+
* The largest share amount `POST /ktx/kvault/withdraw` will size as a share
|
|
18
|
+
* count rather than rewriting to `u64::MAX` — its *withdraw everything*
|
|
19
|
+
* sentinel.
|
|
20
|
+
*
|
|
21
|
+
* The sentinel fires at greater-than-**or-equal-to** the spendable balance,
|
|
22
|
+
* not merely above it. That was measured, not assumed, on wallets whose
|
|
23
|
+
* balance is an exact `u64` in a token account, so there is no rounding
|
|
24
|
+
* anywhere in the comparison. So "the whole balance" is not a request this
|
|
25
|
+
* API accepts, and the maximum has to be the largest amount strictly
|
|
26
|
+
* beneath it.
|
|
27
|
+
*
|
|
28
|
+
* Truncating the reported string is necessary and NOT sufficient. It gives a
|
|
29
|
+
* value strictly below the balance only when there were digits past the
|
|
30
|
+
* mint's scale to throw away; when the balance is exactly representable the
|
|
31
|
+
* truncation IS the balance, and asking for it is asking for everything. So
|
|
32
|
+
* the exact case gives up one base unit — `10^-6` of a share, worth about a
|
|
33
|
+
* ten-thousandth of a cent on the launch vaults — and the inexact case does
|
|
34
|
+
* not have to.
|
|
35
|
+
*/
|
|
36
|
+
spendable: KaminoShareAmount;
|
|
37
|
+
/**
|
|
38
|
+
* Whether the two reported parts add up to the reported total.
|
|
39
|
+
*
|
|
40
|
+
* A response whose total exceeds its parts has shares it has not accounted
|
|
41
|
+
* for, and a withdraw flow has to know exactly how the position is split:
|
|
42
|
+
* the unstaked half is what decides how many shares the farm is asked to
|
|
43
|
+
* release, and a request built against a wrong split is one the API will
|
|
44
|
+
* answer with a different transaction from the one being checked for.
|
|
45
|
+
*
|
|
46
|
+
* Compared at the API's OWN precision, never at the share mint's scale.
|
|
47
|
+
* Truncating three strings to six decimals and adding two of them can miss
|
|
48
|
+
* the third by a base unit with nothing wrong — `0.9445485 + 0.9595935`
|
|
49
|
+
* truncates to `944548 + 959593`, one short of `1904142` — and refusing a
|
|
50
|
+
* real position over a last decimal place is not a guard, it is a bug.
|
|
51
|
+
*/
|
|
52
|
+
accountsForItsTotal: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Whether the three reported numbers can all be true at once. A response
|
|
55
|
+
* whose parts sum past its total says the user holds more shares than they
|
|
56
|
+
* hold — figures that cannot be spent as a balance, and spending a balance
|
|
57
|
+
* that is too large is precisely the mistake the API turns into `u64::MAX`.
|
|
58
|
+
* The sum is compared at the API's own precision, like
|
|
59
|
+
* `accountsForItsTotal`: each part can sit below the total while the pair
|
|
60
|
+
* still exceeds it, and a truncated comparison could mask a real excess.
|
|
61
|
+
*/
|
|
62
|
+
isPlausible: boolean;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Parses one `/positions` element at the vault's pinned share scale.
|
|
66
|
+
* `undefined` when any of the three values is not a plain decimal — a value
|
|
67
|
+
* that is present and unreadable is a failed read, not a zero balance.
|
|
68
|
+
*
|
|
69
|
+
* Every value is TRUNCATED to the share mint's own decimals on the way in.
|
|
70
|
+
* The endpoint reports up to 14 decimal places for a 6-decimal mint, and the
|
|
71
|
+
* extra digits are not a balance anyone can spend: handing the reported
|
|
72
|
+
* string straight back as an amount asks for more than the position holds,
|
|
73
|
+
* which the API rewrites to its withdraw-everything sentinel.
|
|
74
|
+
*/
|
|
75
|
+
export declare const parseKaminoSharePosition: ({ position, shareDecimals, }: {
|
|
76
|
+
position: KaminoUserPositionResponse;
|
|
77
|
+
shareDecimals: number;
|
|
78
|
+
}) => KaminoSharePosition | undefined;
|
|
79
|
+
//# sourceMappingURL=position.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/solana/kamino/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA0E,MAAM,UAAU,CAAA;AACpH,OAAO,EAAE,0BAA0B,EAAE,MAAM,UAAU,CAAA;AAGrD;;;;;;;;GAQG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,iBAAiB,CAAA;IACzB,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,KAAK,EAAE,iBAAiB,CAAA;IACxB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,SAAS,EAAE,iBAAiB,CAAA;IAC5B;;;;;;;;;;;;;;OAcG;IACH,mBAAmB,EAAE,OAAO,CAAA;IAC5B;;;;;;;;OAQG;IACH,WAAW,EAAE,OAAO,CAAA;CACrB,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB,GAAI,8BAGtC;IACD,QAAQ,EAAE,0BAA0B,CAAA;IACpC,aAAa,EAAE,MAAM,CAAA;CACtB,KAAG,mBAAmB,GAAG,SAqBzB,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { kaminoShareAmount, kaminoShareAmountFromDecimalString, scaleKaminoRate } from './amount.js';
|
|
2
|
+
import { compareKaminoRates, kaminoRateEquals, parseKaminoRate, sumKaminoRates } from './rate.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parses one `/positions` element at the vault's pinned share scale.
|
|
5
|
+
* `undefined` when any of the three values is not a plain decimal — a value
|
|
6
|
+
* that is present and unreadable is a failed read, not a zero balance.
|
|
7
|
+
*
|
|
8
|
+
* Every value is TRUNCATED to the share mint's own decimals on the way in.
|
|
9
|
+
* The endpoint reports up to 14 decimal places for a 6-decimal mint, and the
|
|
10
|
+
* extra digits are not a balance anyone can spend: handing the reported
|
|
11
|
+
* string straight back as an amount asks for more than the position holds,
|
|
12
|
+
* which the API rewrites to its withdraw-everything sentinel.
|
|
13
|
+
*/
|
|
14
|
+
export const parseKaminoSharePosition = ({ position, shareDecimals, }) => {
|
|
15
|
+
const staked = kaminoShareAmountFromDecimalString(position.stakedShares, shareDecimals);
|
|
16
|
+
const unstaked = kaminoShareAmountFromDecimalString(position.unstakedShares, shareDecimals);
|
|
17
|
+
const total = kaminoShareAmountFromDecimalString(position.totalShares, shareDecimals);
|
|
18
|
+
const spendable = spendableShares(position.totalShares, shareDecimals);
|
|
19
|
+
if (!staked || !unstaked || !total || !spendable)
|
|
20
|
+
return undefined;
|
|
21
|
+
const reportedSum = sumKaminoRates(position.stakedShares, position.unstakedShares);
|
|
22
|
+
const reportedTotal = parseKaminoRate(position.totalShares);
|
|
23
|
+
return {
|
|
24
|
+
staked,
|
|
25
|
+
unstaked,
|
|
26
|
+
total,
|
|
27
|
+
spendable,
|
|
28
|
+
accountsForItsTotal: reportedSum ? kaminoRateEquals(reportedSum, position.totalShares) : false,
|
|
29
|
+
// The amounts above parsed, so the parts are non-negative; what remains to
|
|
30
|
+
// check is that together they do not exceed the total.
|
|
31
|
+
isPlausible: reportedSum !== undefined && reportedTotal !== undefined && compareKaminoRates(reportedSum, reportedTotal) <= 0,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The spendable rule: truncate to the mint's scale, and give up one base unit
|
|
36
|
+
* only when the truncation was exact (see `KaminoSharePosition.spendable`).
|
|
37
|
+
* Refusing the sentinel is the point of the whole withdraw guard, so it is
|
|
38
|
+
* never accepted to make a 100% withdraw work — the dust is the price of the
|
|
39
|
+
* sentinel being indistinguishable, in the bytes, from an amount the user
|
|
40
|
+
* never asked for.
|
|
41
|
+
*/
|
|
42
|
+
const spendableShares = (totalShares, shareDecimals) => {
|
|
43
|
+
const rate = parseKaminoRate(totalShares);
|
|
44
|
+
if (!rate)
|
|
45
|
+
return undefined;
|
|
46
|
+
const scaled = scaleKaminoRate({ rate, toDecimals: shareDecimals });
|
|
47
|
+
if (!scaled)
|
|
48
|
+
return undefined;
|
|
49
|
+
const baseUnits = scaled.isExact ? scaled.baseUnits - 1n : scaled.baseUnits;
|
|
50
|
+
return kaminoShareAmount(baseUnits < 0n ? 0n : baseUnits, shareDecimals);
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=position.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"position.js","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/solana/kamino/position.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,iBAAiB,EAAE,kCAAkC,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAEpH,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAgE9F;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,EACvC,QAAQ,EACR,aAAa,GAId,EAAmC,EAAE;IACpC,MAAM,MAAM,GAAG,kCAAkC,CAAC,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC,CAAA;IACvF,MAAM,QAAQ,GAAG,kCAAkC,CAAC,QAAQ,CAAC,cAAc,EAAE,aAAa,CAAC,CAAA;IAC3F,MAAM,KAAK,GAAG,kCAAkC,CAAC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,CAAA;IACrF,MAAM,SAAS,GAAG,eAAe,CAAC,QAAQ,CAAC,WAAW,EAAE,aAAa,CAAC,CAAA;IACtE,IAAI,CAAC,MAAM,IAAI,CAAC,QAAQ,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAA;IAElE,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAA;IAClF,MAAM,aAAa,GAAG,eAAe,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAA;IAE3D,OAAO;QACL,MAAM;QACN,QAAQ;QACR,KAAK;QACL,SAAS;QACT,mBAAmB,EAAE,WAAW,CAAC,CAAC,CAAC,gBAAgB,CAAC,WAAW,EAAE,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK;QAC9F,2EAA2E;QAC3E,uDAAuD;QACvD,WAAW,EACT,WAAW,KAAK,SAAS,IAAI,aAAa,KAAK,SAAS,IAAI,kBAAkB,CAAC,WAAW,EAAE,aAAa,CAAC,IAAI,CAAC;KAClH,CAAA;AACH,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,eAAe,GAAG,CAAC,WAAmB,EAAE,aAAqB,EAAiC,EAAE;IACpG,MAAM,IAAI,GAAG,eAAe,CAAC,WAAW,CAAC,CAAA;IACzC,IAAI,CAAC,IAAI;QAAE,OAAO,SAAS,CAAA;IAC3B,MAAM,MAAM,GAAG,eAAe,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,CAAA;IACnE,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAA;IAE7B,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAA;IAC3E,OAAO,iBAAiB,CAAC,SAAS,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;AAC1E,CAAC,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An exact decimal value from the API, held as `numerator / 10^scale`.
|
|
3
|
+
*
|
|
4
|
+
* This exists because floating-point (and any fixed-precision decimal)
|
|
5
|
+
* arithmetic rounds. A share rate drives how many shares a withdraw burns, and
|
|
6
|
+
* the API does not validate amounts — it rewrites an over-sized withdraw to
|
|
7
|
+
* `u64::MAX`, meaning *withdraw everything*. A division that rounded up at the
|
|
8
|
+
* far end of the mantissa could therefore turn a partial withdraw into a full
|
|
9
|
+
* exit. Integer arithmetic removes the question.
|
|
10
|
+
*/
|
|
11
|
+
export type KaminoRate = {
|
|
12
|
+
numerator: bigint;
|
|
13
|
+
/** Denominator exponent: the value is `numerator / 10^scale`. */
|
|
14
|
+
scale: number;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Parses Kamino's decimal-string form exactly, with no intermediate binary or
|
|
18
|
+
* fixed-precision representation. `undefined` when the string is not a plain
|
|
19
|
+
* decimal.
|
|
20
|
+
*/
|
|
21
|
+
export declare const parseKaminoRate: (raw: string) => KaminoRate | undefined;
|
|
22
|
+
/** Whether the rate names a value strictly above zero. */
|
|
23
|
+
export declare const isPositiveKaminoRate: (rate: KaminoRate) => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* This value's numerator at `targetScale` decimal places, or `undefined` when
|
|
26
|
+
* the target is too coarse to hold it without loss.
|
|
27
|
+
*/
|
|
28
|
+
export declare const kaminoRateNumeratorAtScale: (rate: KaminoRate, targetScale: number) => bigint | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The exact sum of two API decimal strings, or `undefined` when either is not
|
|
31
|
+
* one.
|
|
32
|
+
*
|
|
33
|
+
* Exists so two reported figures can be added at the precision they were
|
|
34
|
+
* reported at, rather than after each has been truncated to a mint's scale.
|
|
35
|
+
* See `parseKaminoSharePosition` for why that distinction is the difference
|
|
36
|
+
* between a guard and a false refusal.
|
|
37
|
+
*/
|
|
38
|
+
export declare const sumKaminoRates: (lhs: string, rhs: string) => KaminoRate | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Whether `raw` names exactly the same number as `rate`. `false` when it is
|
|
41
|
+
* not a plain decimal at all — an unreadable figure is never equal to a
|
|
42
|
+
* readable one.
|
|
43
|
+
*/
|
|
44
|
+
export declare const kaminoRateEquals: (rate: KaminoRate, raw: string) => boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Orders two exact rates: negative when `lhs < rhs`, zero when equal,
|
|
47
|
+
* positive when `lhs > rhs`. Both values are brought to a common scale first,
|
|
48
|
+
* so the comparison happens at full reported precision rather than after a
|
|
49
|
+
* truncation that could mask a one-base-unit difference.
|
|
50
|
+
*/
|
|
51
|
+
export declare const compareKaminoRates: (lhs: KaminoRate, rhs: KaminoRate) => number;
|
|
52
|
+
/**
|
|
53
|
+
* Renders the rate back to its plain decimal-string form (no trailing zeros,
|
|
54
|
+
* no exponent).
|
|
55
|
+
*/
|
|
56
|
+
export declare const renderKaminoRate: (rate: KaminoRate) => string;
|
|
57
|
+
//# sourceMappingURL=rate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/solana/kamino/rate.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,MAAM,CAAA;IACjB,iEAAiE;IACjE,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,MAAM,KAAG,UAAU,GAAG,SAgB1D,CAAA;AAED,0DAA0D;AAC1D,eAAO,MAAM,oBAAoB,GAAI,MAAM,UAAU,KAAG,OAA8B,CAAA;AAEtF;;;GAGG;AACH,eAAO,MAAM,0BAA0B,GAAI,MAAM,UAAU,EAAE,aAAa,MAAM,KAAG,MAAM,GAAG,SAG3F,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,KAAK,MAAM,EAAE,KAAK,MAAM,KAAG,UAAU,GAAG,SAWtE,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,UAAU,EAAE,KAAK,MAAM,KAAG,OAQhE,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,KAAK,UAAU,EAAE,KAAK,UAAU,KAAG,MAMrE,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,UAAU,KAAG,MACwB,CAAA"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { renderKaminoBaseUnits } from './baseUnits.js';
|
|
2
|
+
import { isPlainKaminoDecimal } from './decimal.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parses Kamino's decimal-string form exactly, with no intermediate binary or
|
|
5
|
+
* fixed-precision representation. `undefined` when the string is not a plain
|
|
6
|
+
* decimal.
|
|
7
|
+
*/
|
|
8
|
+
export const parseKaminoRate = (raw) => {
|
|
9
|
+
if (!isPlainKaminoDecimal(raw))
|
|
10
|
+
return undefined;
|
|
11
|
+
const separatorIndex = raw.indexOf('.');
|
|
12
|
+
const whole = separatorIndex === -1 ? raw : raw.slice(0, separatorIndex);
|
|
13
|
+
const fraction = separatorIndex === -1 ? '' : raw.slice(separatorIndex + 1);
|
|
14
|
+
// isPlainKaminoDecimal guarantees at least one digit, so `digits` is never
|
|
15
|
+
// empty even for forms like ".5" or "-.5".
|
|
16
|
+
const sign = whole.startsWith('-') ? -1n : 1n;
|
|
17
|
+
const digits = (whole.startsWith('-') ? whole.slice(1) : whole) + fraction;
|
|
18
|
+
return {
|
|
19
|
+
numerator: sign * BigInt(digits),
|
|
20
|
+
scale: fraction.length,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/** Whether the rate names a value strictly above zero. */
|
|
24
|
+
export const isPositiveKaminoRate = (rate) => rate.numerator > 0n;
|
|
25
|
+
/**
|
|
26
|
+
* This value's numerator at `targetScale` decimal places, or `undefined` when
|
|
27
|
+
* the target is too coarse to hold it without loss.
|
|
28
|
+
*/
|
|
29
|
+
export const kaminoRateNumeratorAtScale = (rate, targetScale) => {
|
|
30
|
+
if (targetScale < rate.scale)
|
|
31
|
+
return undefined;
|
|
32
|
+
return rate.numerator * 10n ** BigInt(targetScale - rate.scale);
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The exact sum of two API decimal strings, or `undefined` when either is not
|
|
36
|
+
* one.
|
|
37
|
+
*
|
|
38
|
+
* Exists so two reported figures can be added at the precision they were
|
|
39
|
+
* reported at, rather than after each has been truncated to a mint's scale.
|
|
40
|
+
* See `parseKaminoSharePosition` for why that distinction is the difference
|
|
41
|
+
* between a guard and a false refusal.
|
|
42
|
+
*/
|
|
43
|
+
export const sumKaminoRates = (lhs, rhs) => {
|
|
44
|
+
const left = parseKaminoRate(lhs);
|
|
45
|
+
const right = parseKaminoRate(rhs);
|
|
46
|
+
if (!left || !right)
|
|
47
|
+
return undefined;
|
|
48
|
+
const scale = Math.max(left.scale, right.scale);
|
|
49
|
+
const a = kaminoRateNumeratorAtScale(left, scale);
|
|
50
|
+
const b = kaminoRateNumeratorAtScale(right, scale);
|
|
51
|
+
if (a === undefined || b === undefined)
|
|
52
|
+
return undefined;
|
|
53
|
+
return { numerator: a + b, scale };
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Whether `raw` names exactly the same number as `rate`. `false` when it is
|
|
57
|
+
* not a plain decimal at all — an unreadable figure is never equal to a
|
|
58
|
+
* readable one.
|
|
59
|
+
*/
|
|
60
|
+
export const kaminoRateEquals = (rate, raw) => {
|
|
61
|
+
const other = parseKaminoRate(raw);
|
|
62
|
+
if (!other)
|
|
63
|
+
return false;
|
|
64
|
+
const scale = Math.max(rate.scale, other.scale);
|
|
65
|
+
const a = kaminoRateNumeratorAtScale(rate, scale);
|
|
66
|
+
const b = kaminoRateNumeratorAtScale(other, scale);
|
|
67
|
+
return a !== undefined && b !== undefined && a === b;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Orders two exact rates: negative when `lhs < rhs`, zero when equal,
|
|
71
|
+
* positive when `lhs > rhs`. Both values are brought to a common scale first,
|
|
72
|
+
* so the comparison happens at full reported precision rather than after a
|
|
73
|
+
* truncation that could mask a one-base-unit difference.
|
|
74
|
+
*/
|
|
75
|
+
export const compareKaminoRates = (lhs, rhs) => {
|
|
76
|
+
const scale = Math.max(lhs.scale, rhs.scale);
|
|
77
|
+
const a = lhs.numerator * 10n ** BigInt(scale - lhs.scale);
|
|
78
|
+
const b = rhs.numerator * 10n ** BigInt(scale - rhs.scale);
|
|
79
|
+
if (a === b)
|
|
80
|
+
return 0;
|
|
81
|
+
return a < b ? -1 : 1;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Renders the rate back to its plain decimal-string form (no trailing zeros,
|
|
85
|
+
* no exponent).
|
|
86
|
+
*/
|
|
87
|
+
export const renderKaminoRate = (rate) => renderKaminoBaseUnits({ baseUnits: rate.numerator, decimals: rate.scale });
|
|
88
|
+
//# sourceMappingURL=rate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate.js","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/solana/kamino/rate.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Relative risk of a launch vault, used to order and label them.
|
|
3
|
+
*
|
|
4
|
+
* This is curation, not API data — Kamino exposes no risk or curator field
|
|
5
|
+
* anywhere, so both live here and travel with the allow-list.
|
|
6
|
+
*
|
|
7
|
+
* `conservative` is plain over-collateralised lending against liquid crypto
|
|
8
|
+
* collateral. `privateCredit` lends against tokenized private credit —
|
|
9
|
+
* reinsurance, receivables and corporate bonds — which is materially different
|
|
10
|
+
* risk and must not be presented as government-backed.
|
|
11
|
+
*/
|
|
12
|
+
export declare const kaminoRiskTiers: readonly ["conservative", "privateCredit"];
|
|
13
|
+
/** One of the curated risk-tier labels a launch vault is shown under. */
|
|
14
|
+
export type KaminoRiskTier = (typeof kaminoRiskTiers)[number];
|
|
15
|
+
/**
|
|
16
|
+
* A curated vault the app offers.
|
|
17
|
+
*
|
|
18
|
+
* This carries everything a transaction is checked against, because a value
|
|
19
|
+
* fetched from the API cannot be used to validate a transaction built by the
|
|
20
|
+
* same API — the check would be circular, and a compromised response could
|
|
21
|
+
* supply a matching pair. The fields below are all immutable properties of the
|
|
22
|
+
* vault: a kVault's mints, their decimals and its farm are fixed at creation.
|
|
23
|
+
* Everything that legitimately moves — name, minimums, APY, rates, the lookup
|
|
24
|
+
* table — stays live, and the vault-info hydration refuses a response that
|
|
25
|
+
* disagrees with the pinned identity.
|
|
26
|
+
*/
|
|
27
|
+
export type KaminoVaultDescriptor = {
|
|
28
|
+
address: string;
|
|
29
|
+
/**
|
|
30
|
+
* The vault's underlying token mint. Pinned: the deposit source and the
|
|
31
|
+
* withdraw destination are derived from it.
|
|
32
|
+
*/
|
|
33
|
+
tokenMint: string;
|
|
34
|
+
/**
|
|
35
|
+
* Pinned because it scales every amount. A wrong scale mis-sizes the
|
|
36
|
+
* transfer by a power of ten while every other check still passes.
|
|
37
|
+
*/
|
|
38
|
+
tokenDecimals: number;
|
|
39
|
+
sharesMint: string;
|
|
40
|
+
sharesDecimals: number;
|
|
41
|
+
/**
|
|
42
|
+
* The farm a deposit stakes into, or `undefined` when the vault has none.
|
|
43
|
+
* Pinned because `farms::stake` moves the whole share balance into it.
|
|
44
|
+
*/
|
|
45
|
+
farm?: string;
|
|
46
|
+
/** Shown until live state arrives, and as the fallback if it never does. */
|
|
47
|
+
fallbackName: string;
|
|
48
|
+
curator: string;
|
|
49
|
+
riskTier: KaminoRiskTier;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The curated set of Kamino Earn vaults the app exposes.
|
|
53
|
+
*
|
|
54
|
+
* Kamino runs 160+ vaults; `GET /kvaults/vaults` returns all of them as a
|
|
55
|
+
* single ~340 KB payload. The allow-list both curates and keeps the fetch
|
|
56
|
+
* small — the three entries are hydrated with three ~2.8 KB per-vault requests
|
|
57
|
+
* instead.
|
|
58
|
+
*
|
|
59
|
+
* The share scale is independent of the token scale — 6 against 9 on the SOL
|
|
60
|
+
* vault — so nothing may assume the two match.
|
|
61
|
+
*/
|
|
62
|
+
export declare const kaminoVaultRegistry: readonly KaminoVaultDescriptor[];
|
|
63
|
+
/**
|
|
64
|
+
* Resolves the curated entry for a vault address, or `undefined` for any
|
|
65
|
+
* address the registry does not carry. The returned descriptor is the app's
|
|
66
|
+
* record of the vault's identity — always resolve through here rather than
|
|
67
|
+
* accepting descriptor-shaped data from elsewhere.
|
|
68
|
+
*/
|
|
69
|
+
export declare const getKaminoVaultDescriptor: (address: string) => KaminoVaultDescriptor | undefined;
|
|
70
|
+
//# sourceMappingURL=registry.d.ts.map
|