@vultisig/core-chain 1.4.1 → 1.4.3

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/chains/cosmos/cosmosMsgTypes.d.ts +5 -1
  3. package/dist/chains/cosmos/cosmosMsgTypes.d.ts.map +1 -1
  4. package/dist/chains/cosmos/cosmosMsgTypes.js +5 -0
  5. package/dist/chains/cosmos/cosmosMsgTypes.js.map +1 -1
  6. package/dist/chains/cosmos/protoEncoding.d.ts +68 -0
  7. package/dist/chains/cosmos/protoEncoding.d.ts.map +1 -0
  8. package/dist/chains/cosmos/protoEncoding.js +140 -0
  9. package/dist/chains/cosmos/protoEncoding.js.map +1 -0
  10. package/dist/chains/cosmos/qbtc/claim/buildClaimTx.js +1 -1
  11. package/dist/chains/cosmos/qbtc/claim/buildClaimTx.js.map +1 -1
  12. package/dist/chains/cosmos/qbtc/claim/computeClaimHashes.d.ts +4 -2
  13. package/dist/chains/cosmos/qbtc/claim/computeClaimHashes.d.ts.map +1 -1
  14. package/dist/chains/cosmos/qbtc/claim/computeClaimHashes.js +17 -6
  15. package/dist/chains/cosmos/qbtc/claim/computeClaimHashes.js.map +1 -1
  16. package/dist/chains/cosmos/qbtc/protoEncoding.d.ts +11 -10
  17. package/dist/chains/cosmos/qbtc/protoEncoding.d.ts.map +1 -1
  18. package/dist/chains/cosmos/qbtc/protoEncoding.js +11 -49
  19. package/dist/chains/cosmos/qbtc/protoEncoding.js.map +1 -1
  20. package/dist/chains/cosmos/staking/lcdQueries.d.ts +117 -0
  21. package/dist/chains/cosmos/staking/lcdQueries.d.ts.map +1 -0
  22. package/dist/chains/cosmos/staking/lcdQueries.js +80 -0
  23. package/dist/chains/cosmos/staking/lcdQueries.js.map +1 -0
  24. package/dist/chains/cosmos/terraClassicTax.d.ts +91 -0
  25. package/dist/chains/cosmos/terraClassicTax.d.ts.map +1 -0
  26. package/dist/chains/cosmos/terraClassicTax.js +191 -0
  27. package/dist/chains/cosmos/terraClassicTax.js.map +1 -0
  28. package/dist/chains/cosmos/thor/lp/pools.d.ts +1 -1
  29. package/dist/chains/cosmos/thor/lp/pools.d.ts.map +1 -1
  30. package/dist/chains/cosmos/thor/lp/pools.js +1 -1
  31. package/dist/chains/cosmos/thor/lp/pools.js.map +1 -1
  32. package/dist/chains/ton/messageBody/decode.d.ts +42 -0
  33. package/dist/chains/ton/messageBody/decode.d.ts.map +1 -0
  34. package/dist/chains/ton/messageBody/decode.js +337 -0
  35. package/dist/chains/ton/messageBody/decode.js.map +1 -0
  36. package/dist/chains/ton/messageBody/knownRouters.d.ts +19 -0
  37. package/dist/chains/ton/messageBody/knownRouters.d.ts.map +1 -0
  38. package/dist/chains/ton/messageBody/knownRouters.js +179 -0
  39. package/dist/chains/ton/messageBody/knownRouters.js.map +1 -0
  40. package/dist/chains/ton/messageBody/opcodes.d.ts +23 -0
  41. package/dist/chains/ton/messageBody/opcodes.d.ts.map +1 -0
  42. package/dist/chains/ton/messageBody/opcodes.js +22 -0
  43. package/dist/chains/ton/messageBody/opcodes.js.map +1 -0
  44. package/dist/chains/ton/messageBody/types.d.ts +50 -0
  45. package/dist/chains/ton/messageBody/types.d.ts.map +1 -0
  46. package/dist/chains/ton/messageBody/types.js +2 -0
  47. package/dist/chains/ton/messageBody/types.js.map +1 -0
  48. package/dist/coin/balance/resolvers/polkadot.d.ts.map +1 -1
  49. package/dist/coin/balance/resolvers/polkadot.js +72 -6
  50. package/dist/coin/balance/resolvers/polkadot.js.map +1 -1
  51. package/package.json +41 -4
@@ -0,0 +1,80 @@
1
+ import { cosmosRpcUrl } from '../cosmosRpcUrl.js';
2
+ export const getDelegationsUrl = (chain, delegatorAddress) => `${cosmosRpcUrl[chain]}/cosmos/staking/v1beta1/delegations/${delegatorAddress}`;
3
+ export const getUnbondingDelegationsUrl = (chain, delegatorAddress) => `${cosmosRpcUrl[chain]}/cosmos/staking/v1beta1/delegators/${delegatorAddress}/unbonding_delegations`;
4
+ export const getDelegatorRewardsUrl = (chain, delegatorAddress) => `${cosmosRpcUrl[chain]}/cosmos/distribution/v1beta1/delegators/${delegatorAddress}/rewards`;
5
+ export const getAuthAccountUrl = (chain, address) => `${cosmosRpcUrl[chain]}/cosmos/auth/v1beta1/accounts/${address}`;
6
+ async function lcdGet(url, opts = {}) {
7
+ const f = opts.fetchImpl ?? fetch;
8
+ const res = await f(url, { signal: opts.signal });
9
+ if (!res.ok) {
10
+ // 404 on `/auth/accounts/{addr}` for an unseen address is a legitimate
11
+ // response shape on some chains. Caller decides what to do with it; we
12
+ // surface the status so they can branch on `error.message.includes('404')`.
13
+ throw new Error(`LCD ${res.status}: ${url}`);
14
+ }
15
+ return (await res.json());
16
+ }
17
+ export async function getCosmosDelegations(chain, delegatorAddress, opts = {}) {
18
+ const raw = await lcdGet(getDelegationsUrl(chain, delegatorAddress), opts);
19
+ return raw.delegation_responses.map(d => ({
20
+ validatorAddress: d.delegation.validator_address,
21
+ balance: d.balance,
22
+ shares: d.delegation.shares,
23
+ }));
24
+ }
25
+ export async function getCosmosUnbondingDelegations(chain, delegatorAddress, opts = {}) {
26
+ const raw = await lcdGet(getUnbondingDelegationsUrl(chain, delegatorAddress), opts);
27
+ return raw.unbonding_responses.map(u => ({
28
+ validatorAddress: u.validator_address,
29
+ entries: u.entries.map(e => ({
30
+ creationHeight: e.creation_height,
31
+ completionTime: e.completion_time,
32
+ initialBalance: e.initial_balance,
33
+ balance: e.balance,
34
+ })),
35
+ }));
36
+ }
37
+ export async function getCosmosDelegatorRewards(chain, delegatorAddress, opts = {}) {
38
+ const raw = await lcdGet(getDelegatorRewardsUrl(chain, delegatorAddress), opts);
39
+ return {
40
+ // `?? []` on both fields: an address with zero unclaimed rewards (rare
41
+ // but valid - e.g. brand-new delegator who hasn't accrued anything yet,
42
+ // or one who claimed in the same block) returns a body where `rewards`
43
+ // (and sometimes `total`) is missing entirely on some chain firmwares.
44
+ // Without the fallback the .map call would throw on undefined.
45
+ rewards: (raw.rewards ?? []).map(r => ({ validatorAddress: r.validator_address, reward: r.reward })),
46
+ total: raw.total ?? [],
47
+ };
48
+ }
49
+ /**
50
+ * Returns the wrapped vesting account if the address is a vesting account,
51
+ * otherwise null. The auth endpoint always wraps in `BaseAccount` for
52
+ * non-vesting addresses, so we filter by `@type`.
53
+ *
54
+ * Used by callers that need to surface vesting state to the user (e.g.
55
+ * "X LUNA still locked, vesting until 2024-05-26"). NOT used by the staking
56
+ * msg builders — undelegate works on any delegated balance regardless of
57
+ * vesting state, the contract just controls when the unbonded coins become
58
+ * spendable post-21-day window.
59
+ */
60
+ export async function getCosmosVestingAccount(chain, address, opts = {}) {
61
+ let raw;
62
+ try {
63
+ raw = await lcdGet(getAuthAccountUrl(chain, address), opts);
64
+ }
65
+ catch (e) {
66
+ // 404 on a brand-new (zero-tx) address is normal — return null so the
67
+ // caller doesn't have to differentiate "not found" from "not vesting".
68
+ if (e instanceof Error && e.message.startsWith('LCD 404'))
69
+ return null;
70
+ throw e;
71
+ }
72
+ const t = raw.account['@type'];
73
+ if (t === '/cosmos.vesting.v1beta1.PeriodicVestingAccount' ||
74
+ t === '/cosmos.vesting.v1beta1.ContinuousVestingAccount' ||
75
+ t === '/cosmos.vesting.v1beta1.DelayedVestingAccount') {
76
+ return raw.account;
77
+ }
78
+ return null;
79
+ }
80
+ //# sourceMappingURL=lcdQueries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lcdQueries.js","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/cosmos/staking/lcdQueries.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AA6F9C,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,KAAmB,EAAE,gBAAwB,EAAU,EAAE,CACzF,GAAG,YAAY,CAAC,KAAK,CAAC,uCAAuC,gBAAgB,EAAE,CAAA;AAEjF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CA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H,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,KAAmB,EACnB,OAAe,EACf,OAAkB,EAAE;IAGpB,IAAI,GAAQ,CAAA;IACZ,IAAI,CAAC;QACH,GAAG,GAAG,MAAM,MAAM,CAAM,iBAAiB,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,CAAA;IAClE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,sEAAsE;QACtE,uEAAuE;QACvE,IAAI,CAAC,YAAY,KAAK,IAAI,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC;YAAE,OAAO,IAAI,CAAA;QACtE,MAAM,CAAC,CAAA;IACT,CAAC;IACD,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC9B,IACE,CAAC,KAAK,gDAAgD;QACtD,CAAC,KAAK,kDAAkD;QACxD,CAAC,KAAK,+CAA+C,EACrD,CAAC;QACD,OAAO,GAAG,CAAC,OAAoC,CAAA;IACjD,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Terra Classic stability-tax queries + math.
3
+ *
4
+ * Background: Terra Classic (chain-id `columbus-5`) inherits the original
5
+ * Terra "treasury" module from cosmos-sdk Terra v1, which charges a
6
+ * stability tax on `MsgSend` / `MsgMultiSend` for every native denom
7
+ * EXCEPT `uluna` (LUNC itself is fee-exempt). The tax is a fraction of
8
+ * the transferred amount (governance-controlled, fixed-point 18-decimal),
9
+ * and is capped per-denom by a separate per-denom ceiling.
10
+ *
11
+ * As of this lift the live `tax_rate` is `0` (governance has effectively
12
+ * paused the tax post-UST-collapse), but the treasury module still exists
13
+ * and the rate is queryable — historically it was 1.2% with caps that
14
+ * mostly came into play for large `uusd` transfers. If governance ever
15
+ * re-enables the tax, signing paths that ignore it produce txs that get
16
+ * rejected by the chain's ante handler ("insufficient fee").
17
+ *
18
+ * Terra v2 (`phoenix-1`) does NOT have a treasury module — the same
19
+ * endpoints return HTTP 501 — so callers should only invoke these for
20
+ * `Chain.TerraClassic`.
21
+ *
22
+ * Consumers should query the rate AT SIGN-TIME (not cached across
23
+ * sessions), because governance rate changes propagate immediately.
24
+ * Within a single signing call, both `getTerraClassicTaxRate` and any
25
+ * `getTerraClassicTaxCaps(denom)` calls are safe to memoize — the rate
26
+ * does not change mid-tx.
27
+ */
28
+ /**
29
+ * `cosmosRpcUrl` for Terra Classic actually points at the LCD root (despite
30
+ * the dict name) — the same convention as `staking/lcdQueries`. Keep both
31
+ * URL builders side-by-side here so it's obvious where the tax module
32
+ * lives.
33
+ *
34
+ * Reference: terra-money/classic-core, x/treasury REST routes.
35
+ */
36
+ export declare const getTerraClassicTaxRateUrl: () => string;
37
+ export declare const getTerraClassicTaxCapsUrl: (denom: string) => string;
38
+ /**
39
+ * cosmos-sdk `Dec` is fixed-point with 18 decimals — the on-the-wire
40
+ * representation of `0.012` (1.2%) is the integer `12000000000000000`.
41
+ * Multiplying an amount by `rate` and dividing by `DEC_SCALE` gives the
42
+ * tax in base units of the same denom.
43
+ */
44
+ export declare const TERRA_CLASSIC_TAX_DEC_SCALE: bigint;
45
+ type FetchOpts = {
46
+ fetchImpl?: typeof fetch;
47
+ signal?: AbortSignal;
48
+ };
49
+ /**
50
+ * Fetches the current Terra Classic stability tax rate as an 18-decimal
51
+ * fixed-point bigint (e.g. `0n` if paused, `12_000_000_000_000_000n` if
52
+ * 1.2%). Throws when the LCD response is HTTP 200 but missing `tax_rate` —
53
+ * fail-closed, because silently treating "missing" as `0n` would
54
+ * undercalculate fees if a flaky LCD started returning `{}` after the chain
55
+ * un-pauses the tax (causing post-sign "insufficient fee" rejections).
56
+ */
57
+ export declare function getTerraClassicTaxRate(opts?: FetchOpts): Promise<bigint>;
58
+ /**
59
+ * Fetches the per-denom tax cap as a base-unit bigint (e.g.
60
+ * `60_000_000_000_000_000n` for `uluna`). The cap is the maximum tax that
61
+ * can be levied on a single transfer regardless of the rate-derived
62
+ * amount — when the chain re-enables the tax, large `uusd` transfers in
63
+ * particular hit the cap rather than the rate.
64
+ *
65
+ * Returns `null` ONLY for HTTP 404 ("no entry for this denom") — the
66
+ * caller treats `null` as "no per-denom cap" (the math helper interprets
67
+ * a missing cap as `+∞`).
68
+ *
69
+ * Fails closed (throws) on any other shape we don't recognize — including
70
+ * a `200` response with the `tax_cap` field missing or null. A flaky or
71
+ * tampered LCD that drops the field would otherwise turn a capped denom
72
+ * into an uncapped one and overcharge the user. Codex round-1 P1.
73
+ */
74
+ export declare function getTerraClassicTaxCap(denom: string, opts?: FetchOpts): Promise<bigint | null>;
75
+ /**
76
+ * Pure helper: given a transfer `amount`, its `denom`, the current 18-decimal
77
+ * `rate`, and a per-denom `caps` map, returns the stability tax in base
78
+ * units of `denom`.
79
+ *
80
+ * Rules (mirroring x/treasury's ante handler):
81
+ * - `denom === 'uluna'` is fee-exempt → returns `0n`.
82
+ * - `rate === 0n` → returns `0n` (the most common case today; lets callers
83
+ * skip the cap fetch entirely and avoid spurious LCD load).
84
+ * - Otherwise, `tax = floor(amount * rate / 10^18)`, then clamp to
85
+ * `caps[denom]` if present (cap of `null`/missing = uncapped).
86
+ *
87
+ * `floor` matches the cosmos-sdk Dec.MulInt rounding for positive values.
88
+ */
89
+ export declare const applyTerraClassicTax: (amount: bigint, denom: string, rate: bigint, caps: Record<string, bigint | null | undefined>) => bigint;
90
+ export {};
91
+ //# sourceMappingURL=terraClassicTax.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terraClassicTax.d.ts","sourceRoot":"","sources":["../../../../../../packages/core/chain/chains/cosmos/terraClassicTax.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAUH;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,QAAO,MAC0B,CAAA;AAEvE,eAAO,MAAM,yBAAyB,GAAI,OAAO,MAAM,KAAG,MAK0C,CAAA;AAMpG;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,QAAa,CAAA;AAMrD,KAAK,SAAS,GAAG;IAAE,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IAAC,MAAM,CAAC,EAAE,WAAW,CAAA;CAAE,CAAA;AAoDnE;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,GAAE,SAAc,GACnB,OAAO,CAAC,MAAM,CAAC,CAOjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,SAAc,GACnB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAmBxB;AAMD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,GAC/B,QAAQ,MAAM,EACd,OAAO,MAAM,EACb,MAAM,MAAM,EACZ,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,KAC9C,MAiBF,CAAA"}
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Terra Classic stability-tax queries + math.
3
+ *
4
+ * Background: Terra Classic (chain-id `columbus-5`) inherits the original
5
+ * Terra "treasury" module from cosmos-sdk Terra v1, which charges a
6
+ * stability tax on `MsgSend` / `MsgMultiSend` for every native denom
7
+ * EXCEPT `uluna` (LUNC itself is fee-exempt). The tax is a fraction of
8
+ * the transferred amount (governance-controlled, fixed-point 18-decimal),
9
+ * and is capped per-denom by a separate per-denom ceiling.
10
+ *
11
+ * As of this lift the live `tax_rate` is `0` (governance has effectively
12
+ * paused the tax post-UST-collapse), but the treasury module still exists
13
+ * and the rate is queryable — historically it was 1.2% with caps that
14
+ * mostly came into play for large `uusd` transfers. If governance ever
15
+ * re-enables the tax, signing paths that ignore it produce txs that get
16
+ * rejected by the chain's ante handler ("insufficient fee").
17
+ *
18
+ * Terra v2 (`phoenix-1`) does NOT have a treasury module — the same
19
+ * endpoints return HTTP 501 — so callers should only invoke these for
20
+ * `Chain.TerraClassic`.
21
+ *
22
+ * Consumers should query the rate AT SIGN-TIME (not cached across
23
+ * sessions), because governance rate changes propagate immediately.
24
+ * Within a single signing call, both `getTerraClassicTaxRate` and any
25
+ * `getTerraClassicTaxCaps(denom)` calls are safe to memoize — the rate
26
+ * does not change mid-tx.
27
+ */
28
+ import { Chain } from '../../Chain.js';
29
+ import { cosmosRpcUrl } from './cosmosRpcUrl.js';
30
+ // ---------------------------------------------------------------------------
31
+ // LCD endpoints
32
+ // ---------------------------------------------------------------------------
33
+ /**
34
+ * `cosmosRpcUrl` for Terra Classic actually points at the LCD root (despite
35
+ * the dict name) — the same convention as `staking/lcdQueries`. Keep both
36
+ * URL builders side-by-side here so it's obvious where the tax module
37
+ * lives.
38
+ *
39
+ * Reference: terra-money/classic-core, x/treasury REST routes.
40
+ */
41
+ export const getTerraClassicTaxRateUrl = () => `${cosmosRpcUrl[Chain.TerraClassic]}/terra/treasury/v1beta1/tax_rate`;
42
+ export const getTerraClassicTaxCapsUrl = (denom) =>
43
+ // URL-encode the denom: `ibc/<HASH>` and `factory/<addr>/<subdenom>` carry
44
+ // forward-slashes that would otherwise become extra path segments and the
45
+ // LCD would 404 (silently undertaxing those denoms once the rate is
46
+ // nonzero).
47
+ `${cosmosRpcUrl[Chain.TerraClassic]}/terra/treasury/v1beta1/tax_caps/${encodeURIComponent(denom)}`;
48
+ // ---------------------------------------------------------------------------
49
+ // Constants
50
+ // ---------------------------------------------------------------------------
51
+ /**
52
+ * cosmos-sdk `Dec` is fixed-point with 18 decimals — the on-the-wire
53
+ * representation of `0.012` (1.2%) is the integer `12000000000000000`.
54
+ * Multiplying an amount by `rate` and dividing by `DEC_SCALE` gives the
55
+ * tax in base units of the same denom.
56
+ */
57
+ export const TERRA_CLASSIC_TAX_DEC_SCALE = 10n ** 18n;
58
+ async function lcdGetJson(url, opts) {
59
+ const f = opts.fetchImpl ?? fetch;
60
+ const res = await f(url, { signal: opts.signal });
61
+ if (!res.ok)
62
+ throw new Error(`LCD ${res.status}: ${url}`);
63
+ return (await res.json());
64
+ }
65
+ /**
66
+ * Parses a cosmos-sdk `Dec` string ("0.012000000000000000") into the
67
+ * 18-decimal fixed-point integer representation (`12000000000000000n`).
68
+ * Accepts the integer-string form too ("12000000000000000") for callers
69
+ * that already pre-multiplied. Throws on negative values or NaN.
70
+ */
71
+ const parseDecToFixed18 = (s) => {
72
+ if (typeof s !== 'string') {
73
+ throw new Error(`tax_rate: expected string Dec, got ${typeof s}`);
74
+ }
75
+ const trimmed = s.trim();
76
+ if (trimmed.length === 0)
77
+ throw new Error('tax_rate: empty Dec string');
78
+ // Bigint-safe Dec parse: split on the decimal point if present, then
79
+ // pad/truncate the fractional part to exactly 18 digits.
80
+ const negative = trimmed.startsWith('-');
81
+ if (negative)
82
+ throw new Error(`tax_rate: negative Dec rejected (${trimmed})`);
83
+ // Validate strict Dec shape — single decimal point at most, and
84
+ // reject 19+ fractional digits outright. Truncating past 18 digits
85
+ // would let `1.0000000000000000001` (semantically > 100%) parse as
86
+ // exactly `10^18` and pass the cap guard below — fail-closed instead.
87
+ // Codex round-1 P1.
88
+ if (!/^[0-9]+(\.[0-9]{1,18})?$/.test(trimmed)) {
89
+ throw new Error(`tax_rate: malformed Dec "${trimmed}" (expected digits with at most 18 fractional digits)`);
90
+ }
91
+ const [intPart, fracPart = ''] = trimmed.split('.');
92
+ // intPart is guaranteed non-empty by the regex; fracPart is in [0, 18]
93
+ // digits so no truncation is needed (it's exactly representable).
94
+ const fracPadded = fracPart.padEnd(18, '0');
95
+ const value = BigInt(intPart) * TERRA_CLASSIC_TAX_DEC_SCALE + BigInt(fracPadded);
96
+ // Cap at 100% (Dec value `1.0` on the 18-decimal scale = `10^18`). A
97
+ // hostile or buggy LCD returning `tax_rate: '1000.0'` would otherwise
98
+ // drain the user — real Terra rates are < 5%.
99
+ if (value > TERRA_CLASSIC_TAX_DEC_SCALE) {
100
+ throw new Error(`tax_rate: rate above 100% rejected (${trimmed})`);
101
+ }
102
+ return value;
103
+ };
104
+ /**
105
+ * Fetches the current Terra Classic stability tax rate as an 18-decimal
106
+ * fixed-point bigint (e.g. `0n` if paused, `12_000_000_000_000_000n` if
107
+ * 1.2%). Throws when the LCD response is HTTP 200 but missing `tax_rate` —
108
+ * fail-closed, because silently treating "missing" as `0n` would
109
+ * undercalculate fees if a flaky LCD started returning `{}` after the chain
110
+ * un-pauses the tax (causing post-sign "insufficient fee" rejections).
111
+ */
112
+ export async function getTerraClassicTaxRate(opts = {}) {
113
+ const raw = await lcdGetJson(getTerraClassicTaxRateUrl(), opts);
114
+ if (raw.tax_rate === undefined || raw.tax_rate === null) {
115
+ throw new Error('tax_rate: missing field on 200 response');
116
+ }
117
+ return parseDecToFixed18(raw.tax_rate);
118
+ }
119
+ /**
120
+ * Fetches the per-denom tax cap as a base-unit bigint (e.g.
121
+ * `60_000_000_000_000_000n` for `uluna`). The cap is the maximum tax that
122
+ * can be levied on a single transfer regardless of the rate-derived
123
+ * amount — when the chain re-enables the tax, large `uusd` transfers in
124
+ * particular hit the cap rather than the rate.
125
+ *
126
+ * Returns `null` ONLY for HTTP 404 ("no entry for this denom") — the
127
+ * caller treats `null` as "no per-denom cap" (the math helper interprets
128
+ * a missing cap as `+∞`).
129
+ *
130
+ * Fails closed (throws) on any other shape we don't recognize — including
131
+ * a `200` response with the `tax_cap` field missing or null. A flaky or
132
+ * tampered LCD that drops the field would otherwise turn a capped denom
133
+ * into an uncapped one and overcharge the user. Codex round-1 P1.
134
+ */
135
+ export async function getTerraClassicTaxCap(denom, opts = {}) {
136
+ let raw;
137
+ try {
138
+ raw = await lcdGetJson(getTerraClassicTaxCapsUrl(denom), opts);
139
+ }
140
+ catch (e) {
141
+ // 404 ⇒ "no entry for this denom" (semantically uncapped).
142
+ if (e instanceof Error && e.message.startsWith('LCD 404'))
143
+ return null;
144
+ throw e;
145
+ }
146
+ if (raw.tax_cap === undefined || raw.tax_cap === null) {
147
+ throw new Error(`tax_cap: 200 response missing tax_cap for ${denom} — refusing to fail-open and overcharge`);
148
+ }
149
+ if (!/^[0-9]+$/.test(raw.tax_cap)) {
150
+ throw new Error(`tax_cap: malformed bigint "${raw.tax_cap}"`);
151
+ }
152
+ return BigInt(raw.tax_cap);
153
+ }
154
+ // ---------------------------------------------------------------------------
155
+ // Pure math
156
+ // ---------------------------------------------------------------------------
157
+ /**
158
+ * Pure helper: given a transfer `amount`, its `denom`, the current 18-decimal
159
+ * `rate`, and a per-denom `caps` map, returns the stability tax in base
160
+ * units of `denom`.
161
+ *
162
+ * Rules (mirroring x/treasury's ante handler):
163
+ * - `denom === 'uluna'` is fee-exempt → returns `0n`.
164
+ * - `rate === 0n` → returns `0n` (the most common case today; lets callers
165
+ * skip the cap fetch entirely and avoid spurious LCD load).
166
+ * - Otherwise, `tax = floor(amount * rate / 10^18)`, then clamp to
167
+ * `caps[denom]` if present (cap of `null`/missing = uncapped).
168
+ *
169
+ * `floor` matches the cosmos-sdk Dec.MulInt rounding for positive values.
170
+ */
171
+ export const applyTerraClassicTax = (amount, denom, rate, caps) => {
172
+ if (amount < 0n) {
173
+ throw new Error('applyTerraClassicTax: amount must be non-negative');
174
+ }
175
+ if (rate < 0n) {
176
+ throw new Error('applyTerraClassicTax: rate must be non-negative');
177
+ }
178
+ if (denom === 'uluna')
179
+ return 0n;
180
+ if (rate === 0n)
181
+ return 0n;
182
+ const raw = (amount * rate) / TERRA_CLASSIC_TAX_DEC_SCALE;
183
+ const cap = caps[denom];
184
+ if (cap === undefined || cap === null)
185
+ return raw;
186
+ if (cap < 0n) {
187
+ throw new Error(`applyTerraClassicTax: negative cap for ${denom}`);
188
+ }
189
+ return raw < cap ? raw : cap;
190
+ };
191
+ //# sourceMappingURL=terraClassicTax.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"terraClassicTax.js","sourceRoot":"","sources":["../../../../../../packages/core/chain/chains/cosmos/terraClassicTax.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0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ChB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAA;IACtE,CAAC;IACD,IAAI,IAAI,GAAG,EAAE,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;IACpE,CAAC;IACD,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,EAAE,CAAA;IAChC,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,EAAE,CAAA;IAE1B,MAAM,GAAG,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,2BAA2B,CAAA;IACzD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;IACvB,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,GAAG,CAAA;IACjD,IAAI,GAAG,GAAG,EAAE,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,0CAA0C,KAAK,EAAE,CAAC,CAAA;IACpE,CAAC;IACD,OAAO,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;AAC9B,CAAC,CAAA"}
@@ -2,7 +2,7 @@
2
2
  * Midgard base URL used by every helper in this module. Matches what
3
3
  * vultisig-ios and the rujira package use as the default mainnet endpoint.
4
4
  */
5
- export declare const thorchainMidgardBaseUrl = "https://midgard.ninerealms.com";
5
+ export declare const thorchainMidgardBaseUrl = "https://midgard.thorchain.network";
6
6
  /**
7
7
  * Validate a THORChain pool id is in the canonical format.
8
8
  *
@@ -1 +1 @@
1
- {"version":3,"file":"pools.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/chain/chains/cosmos/thor/lp/pools.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,uBAAuB,mCAAmC,CAAA;AA2BvE;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,IAahD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,OAG5C,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAAA;AAsBD,MAAM,MAAM,wBAAwB,GAAG;IACrC,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAS,wBAA6B,KACrC,OAAO,CAAC,oBAAoB,EAAE,CAahC,CAAA"}
1
+ {"version":3,"file":"pools.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/core/chain/chains/cosmos/thor/lp/pools.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,uBAAuB,sCAAsC,CAAA;AA2B1E;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,IAahD,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,OAG5C,CAAA;AAED;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,cAAc,EAAE,MAAM,CAAA;IACtB,SAAS,EAAE,MAAM,CAAA;IACjB,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAAA;AAsBD,MAAM,MAAM,wBAAwB,GAAG;IACrC,iEAAiE;IACjE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CACvB,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,UAAS,wBAA6B,KACrC,OAAO,CAAC,oBAAoB,EAAE,CAahC,CAAA"}
@@ -3,7 +3,7 @@ import { queryUrl } from '@vultisig/lib-utils/query/queryUrl';
3
3
  * Midgard base URL used by every helper in this module. Matches what
4
4
  * vultisig-ios and the rujira package use as the default mainnet endpoint.
5
5
  */
6
- export const thorchainMidgardBaseUrl = 'https://midgard.ninerealms.com';
6
+ export const thorchainMidgardBaseUrl = 'https://midgard.thorchain.network';
7
7
  /**
8
8
  * Canonical THORChain pool-id format: `CHAIN.ASSET` for native assets
9
9
  * (e.g. `BTC.BTC`, `ETH.ETH`) or `CHAIN.ASSET-CONTRACT` for ERC-20-style
@@ -1 +1 @@
1
- {"version":3,"file":"pools.js","sourceRoot":"","sources":["../../../../../../../../packages/core/chain/chains/cosmos/thor/lp/pools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAA;AAE7D;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,gCAAgC,CAAA;AAEvE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,GAAG,qCAAqC,CAAA;AAExD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAQ,EAAE;IACtD,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CACb,8DAA8D,OAAO,IAAI,IAAI,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CACvG,CAAA;IACH,CAAC;IACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,sBAAsB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,qCAAqC;YAC7E,0EAA0E;YAC1E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,MAAM,aAAa,GAAG,CAAC,GAAY,EAAwB,EAAE,CAAC,CAAC;IAC7D,KAAK,EAAE,GAAG,CAAC,KAAK,IAAI,EAAE;IACtB,MAAM,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE;IACxB,UAAU,EAAE,GAAG,CAAC,UAAU,IAAI,GAAG;IACjC,SAAS,EAAE,GAAG,CAAC,SAAS,IAAI,GAAG;IAC/B,cAAc,EAAE,GAAG,CAAC,cAAc,IAAI,GAAG;IACzC,SAAS,EAAE,GAAG,CAAC,SAAS,IAAI,GAAG;IAC/B,oBAAoB,EAAE,GAAG,CAAC,oBAAoB,IAAI,GAAG;CACtD,CAAC,CAAA;AAOF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EACpC,UAAoC,EAAE,EACL,EAAE;IACnC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAA;IAC1E,MAAM,GAAG,GACP,MAAM,KAAK,IAAI;QACb,CAAC,CAAC,GAAG,uBAAuB,WAAW;QACvC,CAAC,CAAC,GAAG,uBAAuB,oBAAoB,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAA;IAChF,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAU,GAAG,CAAC,CAAA;IACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CACb,6CAA6C,GAAG,SAAS,OAAO,GAAG,EAAE,CACtE,CAAA;IACH,CAAC;IACD,OAAQ,GAAiB,CAAC,GAAG,CAAC,aAAa,CAAC,CAAA;AAC9C,CAAC,CAAA"}
@@ -0,0 +1,42 @@
1
+ import { TonMessageBodyIntent } from './types.js';
2
+ export declare const tonPayloadToBase64: (payload?: string | null) => string | null;
3
+ /**
4
+ * Input to {@link decodeTonMessageBody}. `outerDestination` is the `to` field
5
+ * of the outgoing TON message (`TonMessage.to` in the keysign payload). It is
6
+ * required to bind opcode-based swap classification to known router contracts.
7
+ */
8
+ export type DecodeTonMessageBodyInput = {
9
+ payload: string | null | undefined;
10
+ outerDestination: string | null | undefined;
11
+ };
12
+ /**
13
+ * Decode the body BOC of a TON internal message into a structured intent.
14
+ *
15
+ * Accepts the base64 BOC carried in `TonMessage.payload` (Vultisig's keysign
16
+ * payload schema) along with the outer message destination. Returns `null`
17
+ * when the payload is empty, not a parseable BOC, has no opcode header, or
18
+ * carries an opcode this decoder doesn't yet handle — callers should fall
19
+ * back to displaying the raw TON transfer.
20
+ *
21
+ * **Router binding.** Opcodes are contract-local in TON, so an attacker can
22
+ * craft a body whose leading 32 bits collide with a known DEX swap opcode. To
23
+ * prevent the keysign UI from labeling such a body as a "swap":
24
+ *
25
+ * - `DEDUST_NATIVE_SWAP` is dispatched only when `outerDestination` is a
26
+ * known DeDust **native vault** (NOT the factory — the factory only
27
+ * receives `create_vault`/`create_pool` ops; `swap#ea06185d` lives on
28
+ * the per-asset vault contracts per
29
+ * https://docs.dedust.io/reference/tlb-schemes).
30
+ * - `PTON_TRANSFER` (STON.fi v2 TON-side swap) is dispatched only when
31
+ * `outerDestination` is a known STON.fi v2 pTON wallet.
32
+ * - STON.fi v2 jetton-swap detection inside `JETTON_TRANSFER` is gated on
33
+ * the inner `destination` field being a known STON.fi v2 router.
34
+ *
35
+ * DeDust jetton-swap detection is intentionally not provided — DeDust vaults
36
+ * are per-jetton and not statically enumerable.
37
+ *
38
+ * Note: dApps sometimes prefix a jetton transfer body with an empty 32-bit
39
+ * "text comment" header (op = 0). In that case, we look at the next 32 bits.
40
+ */
41
+ export declare const decodeTonMessageBody: ({ payload: payloadBase64, outerDestination, }: DecodeTonMessageBodyInput) => TonMessageBodyIntent | null;
42
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../../../../../packages/core/chain/chains/ton/messageBody/decode.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,oBAAoB,EAAiB,MAAM,SAAS,CAAA;AA2B7D,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,GAAG,IAAI,KAAG,MAAM,GAAG,IAOrE,CAAA;AAqRD;;;;GAIG;AACH,MAAM,MAAM,yBAAyB,GAAG;IACtC,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAClC,gBAAgB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;CAC5C,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,oBAAoB,GAAI,+CAGlC,yBAAyB,KAAG,oBAAoB,GAAG,IA0CrD,CAAA"}