@lumenwipe/verify 0.6.0 → 0.8.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 +61 -1
- package/README.md +2 -0
- package/dist/index.cjs +260 -18
- package/dist/index.d.cts +67 -3
- package/dist/index.d.ts +67 -3
- package/dist/index.js +261 -20
- package/package.json +1 -1
- package/vectors/close-v1.json +4678 -599
package/dist/index.d.ts
CHANGED
|
@@ -202,6 +202,22 @@ export declare interface CloseExpectationInput extends ExitExpectations {
|
|
|
202
202
|
classicConversions: Record<string, ClassicConversionChoice>;
|
|
203
203
|
/** The Soroban token conversions the user chose, keyed by token contract. */
|
|
204
204
|
tokenConversions: Record<string, TokenConversionChoice>;
|
|
205
|
+
/**
|
|
206
|
+
* The classic liquidity pools the account holds shares in, by hex pool id. Build it with
|
|
207
|
+
* {@link poolWithdrawalExpectations} from the account read, never from a plan or a transactions
|
|
208
|
+
* response. A withdrawal must name one of these pools, for exactly its shares, with each minimum
|
|
209
|
+
* at least 98% and at most 101% of what these reserves give; a pool share line may be removed
|
|
210
|
+
* only for one of these pools, named by the asset pair and fee its operation carries. Omitted,
|
|
211
|
+
* every withdrawal and pool share line removal is refused.
|
|
212
|
+
*/
|
|
213
|
+
poolWithdrawals?: Record<string, PoolWithdrawalExpectation>;
|
|
214
|
+
/**
|
|
215
|
+
* The entries this account sponsors, as the account read lists them: pass its
|
|
216
|
+
* `sponsoredEntries` as is, never a list from a plan or a transactions response. A sponsorship
|
|
217
|
+
* revoke must name one of these entries, by kind, owner and key, at most once per transaction.
|
|
218
|
+
* Omitted, every sponsorship revoke is refused.
|
|
219
|
+
*/
|
|
220
|
+
sponsoredEntries?: SponsoredEntry[];
|
|
205
221
|
}
|
|
206
222
|
|
|
207
223
|
declare interface DataEntry {
|
|
@@ -385,6 +401,22 @@ declare interface FxdaoCdpPosition extends DefiPositionBase {
|
|
|
385
401
|
debtToken?: string;
|
|
386
402
|
}
|
|
387
403
|
|
|
404
|
+
/** A classic constant-product pool as the ledger holds it. Amounts in stroops, as integers. */
|
|
405
|
+
declare interface LiquidityPoolState {
|
|
406
|
+
/** "native" or "CODE:ISSUER", in the pool's own (lexicographic) order. */
|
|
407
|
+
assetA: string;
|
|
408
|
+
/** The pool's second asset, in the same form. */
|
|
409
|
+
assetB: string;
|
|
410
|
+
/** In basis points; 30 for every classic pool. */
|
|
411
|
+
fee: number;
|
|
412
|
+
/** The pool's reserve of `assetA`. */
|
|
413
|
+
reserveA: string;
|
|
414
|
+
/** The pool's reserve of `assetB`. */
|
|
415
|
+
reserveB: string;
|
|
416
|
+
/** Pool shares outstanding. */
|
|
417
|
+
totalShares: string;
|
|
418
|
+
}
|
|
419
|
+
|
|
388
420
|
/** The Stellar network a transaction is verified for. Selects the network passphrase the XDR is
|
|
389
421
|
* decoded with and the bundled registry entries that apply. */
|
|
390
422
|
export declare type Network = "mainnet" | "testnet";
|
|
@@ -429,8 +461,31 @@ declare interface PlanBlocker {
|
|
|
429
461
|
|
|
430
462
|
declare interface PoolShareEntry {
|
|
431
463
|
poolId: string;
|
|
464
|
+
/** Pool shares held, in the 7-decimal units Horizon reports. */
|
|
465
|
+
balance: string;
|
|
466
|
+
/** The pool's ledger entry, read over RPC; null when it could not be read. */
|
|
467
|
+
pool: LiquidityPoolState | null;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** A classic liquidity pool the account holds shares in, as the account read showed it. Every
|
|
471
|
+
* amount is in stroops. */
|
|
472
|
+
export declare interface PoolWithdrawalExpectation {
|
|
473
|
+
/** The pool shares the account holds. A withdrawal must name exactly these. */
|
|
474
|
+
shares: string;
|
|
475
|
+
/** The pool's reserve of its first asset. */
|
|
476
|
+
reserveA: string;
|
|
477
|
+
/** The pool's reserve of its second asset. */
|
|
478
|
+
reserveB: string;
|
|
479
|
+
/** The pool shares outstanding. */
|
|
480
|
+
totalShares: string;
|
|
432
481
|
}
|
|
433
482
|
|
|
483
|
+
/**
|
|
484
|
+
* The pool half of a close expectation, from the account read the user reviewed. A pool the read
|
|
485
|
+
* could not see into is left out, so a withdrawal from it is refused.
|
|
486
|
+
*/
|
|
487
|
+
export declare function poolWithdrawalExpectations(accountState: AccountState | null | undefined): Record<string, PoolWithdrawalExpectation>;
|
|
488
|
+
|
|
434
489
|
/**
|
|
435
490
|
* Whether a close to `address` on `network` goes through the shared intermediary: true only for
|
|
436
491
|
* an exchange the registry bundled in this package lists, on that network, as unable to receive
|
|
@@ -569,15 +624,21 @@ declare interface SoroswapLpPosition extends DefiPositionBase {
|
|
|
569
624
|
* A ledger entry this account currently sponsors, on another account (or itself, for
|
|
570
625
|
* "account" - a fully-sponsored account creation). Mirrors the ledger-key kinds
|
|
571
626
|
* RevokeSponsorship supports. Claimable balances have no owning-account concept in
|
|
572
|
-
* their ledger key (unlike
|
|
627
|
+
* their ledger key (unlike every other kind), so they carry only balanceId.
|
|
573
628
|
*/
|
|
574
|
-
declare type SponsoredEntry = {
|
|
629
|
+
export declare type SponsoredEntry = {
|
|
575
630
|
kind: "account";
|
|
576
631
|
owner: string;
|
|
577
632
|
} | {
|
|
578
633
|
kind: "trustline";
|
|
579
634
|
owner: string;
|
|
580
635
|
asset: string;
|
|
636
|
+
}
|
|
637
|
+
/** A liquidity pool share trustline, named by its 64-character hex pool id. */
|
|
638
|
+
| {
|
|
639
|
+
kind: "pool_share_trustline";
|
|
640
|
+
owner: string;
|
|
641
|
+
poolId: string;
|
|
581
642
|
} | {
|
|
582
643
|
kind: "offer";
|
|
583
644
|
owner: string;
|
|
@@ -623,6 +684,9 @@ declare interface Trustline {
|
|
|
623
684
|
asset: string;
|
|
624
685
|
balance: string;
|
|
625
686
|
limit?: string;
|
|
687
|
+
/** What the account's open offers are buying of this asset; from the Horizon-compatible
|
|
688
|
+
* reader only. */
|
|
689
|
+
buyingLiabilities?: string;
|
|
626
690
|
/** True only when `authorization` is `authorized`. */
|
|
627
691
|
authorized: boolean;
|
|
628
692
|
authorization: TrustlineAuthorization;
|
|
@@ -655,7 +719,7 @@ declare interface UnrecognizedDefiPosition {
|
|
|
655
719
|
* that applies to several operation kinds (the fee cap, the operation source) shares one code,
|
|
656
720
|
* since the kind is visible in the transaction itself.
|
|
657
721
|
*/
|
|
658
|
-
declare const VERIFICATION_ERROR_CODES: readonly ["registry_expired", "registry_snapshot_invalid", "registry_memo_type_conflict", "registry_memo_type_unconfirmed", "transaction_source_mismatch", "expiry_missing", "expiry_too_far", "fee_unreadable", "fee_above_cap", "operation_unknown", "operation_source_mismatch", "merge_multiple", "merge_direct_refused", "merge_destination_mismatch", "mediator_handoff_shape", "mediator_forward_source_mismatch", "mediator_forward_destination_mismatch", "mediator_forward_not_native", "mediator_forward_short", "transfer_not_chosen", "transfer_destination_mismatch", "transfer_to_deposit_address", "transfer_duplicate", "transfer_amount_short", "token_transfer_function_invalid", "token_transfer_from_mismatch", "token_transfer_foreign_contract", "conversion_recipient_mismatch", "conversion_not_to_xlm", "conversion_min_out_missing", "conversion_asset_not_chosen", "conversion_duplicate", "conversion_min_out_below_floor", "conversion_amount_short", "swap_quote_missing", "swap_args_unreadable", "swap_referral_recipient", "swap_route_asset_unknown", "swap_auth_unexpected_call", "swap_auth_exceeds_amount", "trustline_not_removal", "data_entry_not_removal", "offer_not_cancellation", "signer_added", "signer_unknown", "master_weight_changed", "thresholds_raised", "account_settings_changed", "invocation_not_alone", "invocation_auth_beyond_self", "invocation_address_unsupported", "invocation_foreign_account", "exit_contract_not_position", "exit_expectation_inconsistent", "exit_function_not_allowed", "exit_foreign_contract", "exit_argument_party_mismatch", "exit_arguments_unexpected", "exit_request_not_allowed", "exit_unverified_spend", "exit_spend_not_repay", "exit_liquidity_auth_invalid", "exit_auth_foreign_contract", "exit_token_function_not_allowed", "exit_token_argument_count", "exit_token_recipient_mismatch", "memo_unexpected", "memo_type_unreadable", "memo_missing", "memo_value_mismatch", "memo_type_mismatch", "memo_required", "memo_invalid_text"];
|
|
722
|
+
declare const VERIFICATION_ERROR_CODES: readonly ["registry_expired", "registry_snapshot_invalid", "registry_memo_type_conflict", "registry_memo_type_unconfirmed", "transaction_source_mismatch", "expiry_missing", "expiry_too_far", "fee_unreadable", "fee_above_cap", "operation_unknown", "operation_source_mismatch", "merge_multiple", "merge_direct_refused", "merge_destination_mismatch", "mediator_handoff_shape", "mediator_forward_source_mismatch", "mediator_forward_destination_mismatch", "mediator_forward_not_native", "mediator_forward_balance_unknown", "mediator_forward_short", "transfer_not_chosen", "transfer_destination_mismatch", "transfer_to_deposit_address", "transfer_duplicate", "transfer_amount_short", "token_transfer_function_invalid", "token_transfer_from_mismatch", "token_transfer_foreign_contract", "conversion_recipient_mismatch", "conversion_not_to_xlm", "conversion_min_out_missing", "conversion_asset_not_chosen", "conversion_duplicate", "conversion_min_out_below_floor", "conversion_amount_short", "swap_quote_missing", "swap_args_unreadable", "swap_referral_recipient", "swap_route_asset_unknown", "swap_auth_unexpected_call", "swap_auth_exceeds_amount", "pool_not_held", "pool_withdraw_duplicate", "pool_withdraw_amount_mismatch", "pool_withdraw_min_missing", "pool_withdraw_min_below_floor", "pool_withdraw_min_above_reserves", "pool_line_mismatch", "sponsorship_revoke_unknown", "sponsorship_revoke_duplicate", "trustline_not_removal", "data_entry_not_removal", "offer_not_cancellation", "signer_added", "signer_unknown", "master_weight_changed", "thresholds_raised", "account_settings_changed", "invocation_not_alone", "invocation_auth_beyond_self", "invocation_address_unsupported", "invocation_foreign_account", "exit_contract_not_position", "exit_expectation_inconsistent", "exit_function_not_allowed", "exit_foreign_contract", "exit_argument_party_mismatch", "exit_arguments_unexpected", "exit_request_not_allowed", "exit_unverified_spend", "exit_spend_not_repay", "exit_liquidity_auth_invalid", "exit_auth_foreign_contract", "exit_token_function_not_allowed", "exit_token_argument_count", "exit_token_recipient_mismatch", "memo_unexpected", "memo_type_unreadable", "memo_missing", "memo_value_mismatch", "memo_type_mismatch", "memo_required", "memo_invalid_text"];
|
|
659
723
|
|
|
660
724
|
/** Thrown when a server-built close transaction fails verification. Never sign past this. */
|
|
661
725
|
export declare class VerificationError extends Error {
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Asset, TransactionBuilder, Address, StrKey, scValToNative } from '@stellar/stellar-sdk';
|
|
1
|
+
import { Asset, TransactionBuilder, getLiquidityPoolId, Address, StrKey, scValToNative } from '@stellar/stellar-sdk';
|
|
2
|
+
|
|
3
|
+
// ../../apps/web/lib/stellar/verify.ts
|
|
2
4
|
|
|
3
5
|
// ../../apps/web/config/networks.ts
|
|
4
6
|
var NETWORK_PASSPHRASES = {
|
|
@@ -394,6 +396,12 @@ function describeInvocation(op) {
|
|
|
394
396
|
function toHex(bytes) {
|
|
395
397
|
return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
396
398
|
}
|
|
399
|
+
function fromHex(hex) {
|
|
400
|
+
const out = new Uint8Array(hex.length / 2);
|
|
401
|
+
for (let i = 0; i < out.length; i++)
|
|
402
|
+
out.set([Number.parseInt(hex.slice(i * 2, i * 2 + 2), 16)], i);
|
|
403
|
+
return out;
|
|
404
|
+
}
|
|
397
405
|
function toBase64(bytes) {
|
|
398
406
|
return btoa(String.fromCharCode(...bytes));
|
|
399
407
|
}
|
|
@@ -460,7 +468,30 @@ function decodeSigner(signer) {
|
|
|
460
468
|
}
|
|
461
469
|
return null;
|
|
462
470
|
}
|
|
463
|
-
|
|
471
|
+
var keyBytes = (value) => typeof value === "string" ? fromHex(value) : value;
|
|
472
|
+
function revokedSignerKey(signer) {
|
|
473
|
+
if ("ed25519PublicKey" in signer) return signer.ed25519PublicKey;
|
|
474
|
+
if ("ed25519SignedPayload" in signer) return signer.ed25519SignedPayload;
|
|
475
|
+
if ("preAuthTx" in signer) return StrKey.encodePreAuthTx(keyBytes(signer.preAuthTx));
|
|
476
|
+
return StrKey.encodeSha256Hash(keyBytes(signer.sha256Hash));
|
|
477
|
+
}
|
|
478
|
+
function revokedDataName(raw) {
|
|
479
|
+
const body = raw?.body;
|
|
480
|
+
const revoke = body?.type === "revokeSponsorship" ? body.revokeSponsorshipOp : void 0;
|
|
481
|
+
const key = revoke?.type === "revokeSponsorshipLedgerEntry" ? revoke.ledgerKey : void 0;
|
|
482
|
+
if (key?.type !== "data") return void 0;
|
|
483
|
+
try {
|
|
484
|
+
return STRICT_UTF8.decode(key.data.dataName.bytes);
|
|
485
|
+
} catch {
|
|
486
|
+
return void 0;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function rawOperations(tx) {
|
|
490
|
+
const envelope = tx.toEnvelope();
|
|
491
|
+
if (envelope.type === "envelopeTypeTxV0") return envelope.v0.tx.operations;
|
|
492
|
+
return envelope.type === "envelopeTypeTx" ? envelope.v1.tx.operations : [];
|
|
493
|
+
}
|
|
494
|
+
function normalizeOp(op, raw) {
|
|
464
495
|
switch (op.type) {
|
|
465
496
|
case "pathPaymentStrictSend":
|
|
466
497
|
return {
|
|
@@ -481,9 +512,29 @@ function normalizeOp(op) {
|
|
|
481
512
|
};
|
|
482
513
|
case "changeTrust": {
|
|
483
514
|
const line = op.line;
|
|
484
|
-
|
|
485
|
-
|
|
515
|
+
if ("getCode" in line) {
|
|
516
|
+
return { type: "change_trust", asset: assetToString(line), limit: op.limit };
|
|
517
|
+
}
|
|
518
|
+
const params = line.getLiquidityPoolParameters();
|
|
519
|
+
return {
|
|
520
|
+
type: "change_trust",
|
|
521
|
+
asset: `pool:${line.toString()}`,
|
|
522
|
+
limit: op.limit,
|
|
523
|
+
pool: {
|
|
524
|
+
assetA: assetToString(params.assetA),
|
|
525
|
+
assetB: assetToString(params.assetB),
|
|
526
|
+
fee: params.fee
|
|
527
|
+
}
|
|
528
|
+
};
|
|
486
529
|
}
|
|
530
|
+
case "liquidityPoolWithdraw":
|
|
531
|
+
return {
|
|
532
|
+
type: "liquidity_pool_withdraw",
|
|
533
|
+
poolId: op.liquidityPoolId,
|
|
534
|
+
amount: op.amount,
|
|
535
|
+
minAmountA: op.minAmountA,
|
|
536
|
+
minAmountB: op.minAmountB
|
|
537
|
+
};
|
|
487
538
|
case "accountMerge":
|
|
488
539
|
return { type: "account_merge", destination: op.destination };
|
|
489
540
|
case "manageSellOffer":
|
|
@@ -517,13 +568,35 @@ function normalizeOp(op) {
|
|
|
517
568
|
case "revokeAccountSponsorship":
|
|
518
569
|
return { type: "revoke_sponsorship", entryKind: "account", owner: op.account };
|
|
519
570
|
case "revokeTrustlineSponsorship":
|
|
520
|
-
return
|
|
571
|
+
return "getLiquidityPoolId" in op.asset ? {
|
|
572
|
+
type: "revoke_sponsorship",
|
|
573
|
+
entryKind: "trustline",
|
|
574
|
+
owner: op.account,
|
|
575
|
+
poolId: op.asset.getLiquidityPoolId()
|
|
576
|
+
} : {
|
|
577
|
+
type: "revoke_sponsorship",
|
|
578
|
+
entryKind: "trustline",
|
|
579
|
+
owner: op.account,
|
|
580
|
+
asset: assetToString(op.asset)
|
|
581
|
+
};
|
|
521
582
|
case "revokeOfferSponsorship":
|
|
522
|
-
return {
|
|
523
|
-
|
|
524
|
-
|
|
583
|
+
return {
|
|
584
|
+
type: "revoke_sponsorship",
|
|
585
|
+
entryKind: "offer",
|
|
586
|
+
owner: op.seller,
|
|
587
|
+
offerId: op.offerId
|
|
588
|
+
};
|
|
589
|
+
case "revokeDataSponsorship": {
|
|
590
|
+
const name = revokedDataName(raw);
|
|
591
|
+
return name === void 0 ? { type: "revoke_sponsorship", entryKind: "data_entry", owner: op.account } : { type: "revoke_sponsorship", entryKind: "data_entry", owner: op.account, name };
|
|
592
|
+
}
|
|
525
593
|
case "revokeSignerSponsorship":
|
|
526
|
-
return {
|
|
594
|
+
return {
|
|
595
|
+
type: "revoke_sponsorship",
|
|
596
|
+
entryKind: "signer",
|
|
597
|
+
owner: op.account,
|
|
598
|
+
signerKey: revokedSignerKey(op.signer)
|
|
599
|
+
};
|
|
527
600
|
case "invokeHostFunction":
|
|
528
601
|
return describeInvocation(op);
|
|
529
602
|
default:
|
|
@@ -535,8 +608,9 @@ function sumAmounts(a, b) {
|
|
|
535
608
|
}
|
|
536
609
|
function intentFromXdr(xdr2, networkPassphrase) {
|
|
537
610
|
const tx = TransactionBuilder.fromXdr(xdr2, networkPassphrase);
|
|
538
|
-
const
|
|
539
|
-
|
|
611
|
+
const raw = rawOperations(tx);
|
|
612
|
+
const operations = tx.operations.map((op, index) => ({
|
|
613
|
+
...normalizeOp(op, raw[index]),
|
|
540
614
|
source: op.source ?? tx.source
|
|
541
615
|
}));
|
|
542
616
|
const merge = operations.find(
|
|
@@ -588,6 +662,150 @@ function xlmToStroops(xlm) {
|
|
|
588
662
|
var MAX_EXIT_FEE_STROOPS = BigInt(1e7);
|
|
589
663
|
var MAX_CLASSIC_FEE_PER_OPERATION_STROOPS = BigInt(1e3);
|
|
590
664
|
var MAX_VALIDITY_SECONDS = 900;
|
|
665
|
+
function poolWithdrawalExpectations(accountState) {
|
|
666
|
+
const pools = {};
|
|
667
|
+
for (const share of accountState?.poolShares ?? []) {
|
|
668
|
+
if (!share.pool) continue;
|
|
669
|
+
pools[share.poolId] = {
|
|
670
|
+
shares: xlmToStroops(share.balance),
|
|
671
|
+
reserveA: share.pool.reserveA,
|
|
672
|
+
reserveB: share.pool.reserveB,
|
|
673
|
+
totalShares: share.pool.totalShares
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
return pools;
|
|
677
|
+
}
|
|
678
|
+
var POOL_MIN_FLOOR_BPS = BigInt(9800);
|
|
679
|
+
var POOL_MIN_CEILING_BPS = BigInt(10100);
|
|
680
|
+
function assertPoolMinimum(min, shares, reserve, total) {
|
|
681
|
+
const given = total > BigInt(0) ? shares * reserve / total : BigInt(0);
|
|
682
|
+
if (given > BigInt(0) && min <= BigInt(0)) {
|
|
683
|
+
throw new VerificationError(
|
|
684
|
+
"pool_withdraw_min_missing",
|
|
685
|
+
"A pool withdrawal has no minimum for an asset the pool pays out."
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
if (min < given * POOL_MIN_FLOOR_BPS / BigInt(1e4)) {
|
|
689
|
+
throw new VerificationError(
|
|
690
|
+
"pool_withdraw_min_below_floor",
|
|
691
|
+
"A pool withdrawal would accept less than the pool's reserves give. If the pool moved since the analysis, run it again."
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
if (min > given * POOL_MIN_CEILING_BPS / BigInt(1e4)) {
|
|
695
|
+
throw new VerificationError(
|
|
696
|
+
"pool_withdraw_min_above_reserves",
|
|
697
|
+
"A pool withdrawal asks for more than the pool's reserves give. If the pool moved since the analysis, run it again."
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
function assertPoolWithdrawal(op, expected, seen) {
|
|
702
|
+
const held = expected.poolWithdrawals?.[op.poolId];
|
|
703
|
+
if (!held) {
|
|
704
|
+
throw new VerificationError(
|
|
705
|
+
"pool_not_held",
|
|
706
|
+
"A withdrawal names a liquidity pool your account holds no shares in."
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
if (seen.has(op.poolId)) {
|
|
710
|
+
throw new VerificationError(
|
|
711
|
+
"pool_withdraw_duplicate",
|
|
712
|
+
"The transaction would withdraw from the same liquidity pool more than once."
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
seen.add(op.poolId);
|
|
716
|
+
const shares = BigInt(held.shares);
|
|
717
|
+
if (BigInt(xlmToStroops(op.amount)) !== shares) {
|
|
718
|
+
throw new VerificationError(
|
|
719
|
+
"pool_withdraw_amount_mismatch",
|
|
720
|
+
"A pool withdrawal does not withdraw exactly the shares your account holds."
|
|
721
|
+
);
|
|
722
|
+
}
|
|
723
|
+
const total = BigInt(held.totalShares);
|
|
724
|
+
assertPoolMinimum(BigInt(xlmToStroops(op.minAmountA)), shares, BigInt(held.reserveA), total);
|
|
725
|
+
assertPoolMinimum(BigInt(xlmToStroops(op.minAmountB)), shares, BigInt(held.reserveB), total);
|
|
726
|
+
}
|
|
727
|
+
function sdkAsset(asset) {
|
|
728
|
+
if (asset === "native") return Asset.native();
|
|
729
|
+
const [code, issuer] = asset.split(":");
|
|
730
|
+
return new Asset(code ?? "", issuer);
|
|
731
|
+
}
|
|
732
|
+
var entryKey = (kind, owner, key) => JSON.stringify([kind, owner, key]);
|
|
733
|
+
function sponsoredEntryKey(entry) {
|
|
734
|
+
switch (entry.kind) {
|
|
735
|
+
case "account":
|
|
736
|
+
return entryKey(entry.kind, entry.owner, "");
|
|
737
|
+
case "trustline":
|
|
738
|
+
return entryKey(entry.kind, entry.owner, entry.asset);
|
|
739
|
+
case "pool_share_trustline":
|
|
740
|
+
return entryKey(entry.kind, entry.owner, entry.poolId);
|
|
741
|
+
case "offer":
|
|
742
|
+
return entryKey(entry.kind, entry.owner, entry.offerId);
|
|
743
|
+
case "data_entry":
|
|
744
|
+
return entryKey(entry.kind, entry.owner, entry.name);
|
|
745
|
+
case "signer":
|
|
746
|
+
return entryKey(entry.kind, entry.owner, entry.signerKey);
|
|
747
|
+
case "claimable_balance":
|
|
748
|
+
return null;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
function revokedEntryKey(op) {
|
|
752
|
+
switch (op.entryKind) {
|
|
753
|
+
case "account":
|
|
754
|
+
return entryKey("account", op.owner, "");
|
|
755
|
+
case "trustline":
|
|
756
|
+
if (op.poolId !== void 0) return entryKey("pool_share_trustline", op.owner, op.poolId);
|
|
757
|
+
return op.asset === void 0 ? null : entryKey("trustline", op.owner, op.asset);
|
|
758
|
+
case "offer":
|
|
759
|
+
return op.offerId === void 0 ? null : entryKey("offer", op.owner, op.offerId);
|
|
760
|
+
case "data_entry":
|
|
761
|
+
return op.name === void 0 ? null : entryKey("data_entry", op.owner, op.name);
|
|
762
|
+
case "signer":
|
|
763
|
+
return op.signerKey === void 0 ? null : entryKey("signer", op.owner, op.signerKey);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
function assertSponsoredEntryRevoke(op, expected, seen) {
|
|
767
|
+
const key = revokedEntryKey(op);
|
|
768
|
+
const listed = new Set((expected.sponsoredEntries ?? []).map(sponsoredEntryKey));
|
|
769
|
+
if (key === null || !listed.has(key)) {
|
|
770
|
+
throw new VerificationError(
|
|
771
|
+
"sponsorship_revoke_unknown",
|
|
772
|
+
"A sponsorship revoke names an entry your account is not known to sponsor."
|
|
773
|
+
);
|
|
774
|
+
}
|
|
775
|
+
if (seen.has(key)) {
|
|
776
|
+
throw new VerificationError(
|
|
777
|
+
"sponsorship_revoke_duplicate",
|
|
778
|
+
"The transaction would revoke the sponsorship of the same entry more than once."
|
|
779
|
+
);
|
|
780
|
+
}
|
|
781
|
+
seen.add(key);
|
|
782
|
+
}
|
|
783
|
+
function assertPoolLine(op, expected) {
|
|
784
|
+
const mismatch = new VerificationError(
|
|
785
|
+
"pool_line_mismatch",
|
|
786
|
+
"A pool share trustline change does not match the pool it names."
|
|
787
|
+
);
|
|
788
|
+
if (!op.pool) throw mismatch;
|
|
789
|
+
let poolId;
|
|
790
|
+
try {
|
|
791
|
+
poolId = toHex(
|
|
792
|
+
getLiquidityPoolId("constant_product", {
|
|
793
|
+
assetA: sdkAsset(op.pool.assetA),
|
|
794
|
+
assetB: sdkAsset(op.pool.assetB),
|
|
795
|
+
fee: op.pool.fee
|
|
796
|
+
})
|
|
797
|
+
);
|
|
798
|
+
} catch {
|
|
799
|
+
throw mismatch;
|
|
800
|
+
}
|
|
801
|
+
if (op.asset !== `pool:liquidity_pool:${poolId}`) throw mismatch;
|
|
802
|
+
if (!expected.poolWithdrawals?.[poolId]) {
|
|
803
|
+
throw new VerificationError(
|
|
804
|
+
"pool_not_held",
|
|
805
|
+
"A trustline change names a liquidity pool your account holds no shares in."
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
}
|
|
591
809
|
function assertMergeShape(intent, expected) {
|
|
592
810
|
const merges = intent.operations.filter((o) => o.type === "account_merge");
|
|
593
811
|
if (merges.length === 0) return null;
|
|
@@ -740,11 +958,22 @@ function readSwapArgs(fn, args) {
|
|
|
740
958
|
const min = integer(args[4]);
|
|
741
959
|
if (!CONTRACT_ID.test(token) || !CONTRACT_ID.test(assetOut)) return null;
|
|
742
960
|
if (amountIn === null || min === null) return null;
|
|
743
|
-
if (args[6] !== "null") return null;
|
|
961
|
+
if (args[6] !== "null" && !isZeroFeePartner(args[6] ?? "")) return null;
|
|
744
962
|
return { token, assetOut, amountIn, destination: args[0] ?? "", minAmountOut: min };
|
|
745
963
|
}
|
|
746
964
|
return null;
|
|
747
965
|
}
|
|
966
|
+
function isZeroFeePartner(rendered) {
|
|
967
|
+
let parsed;
|
|
968
|
+
try {
|
|
969
|
+
parsed = JSON.parse(rendered);
|
|
970
|
+
} catch {
|
|
971
|
+
return false;
|
|
972
|
+
}
|
|
973
|
+
if (typeof parsed !== "object" || parsed === null) return false;
|
|
974
|
+
const { id } = parsed;
|
|
975
|
+
return typeof id === "string" && rendered === JSON.stringify({ bps: 0, id });
|
|
976
|
+
}
|
|
748
977
|
var XBULL_SWAP_FUNCTION = "strict_send";
|
|
749
978
|
function readXBullSwapArgs(args) {
|
|
750
979
|
if (args.length !== 6) return null;
|
|
@@ -871,6 +1100,12 @@ function assetCode(asset) {
|
|
|
871
1100
|
function assertForwardCarriesTheBalance(forwardAmount, nativeBalance) {
|
|
872
1101
|
const forwarded = BigInt(xlmToStroops(forwardAmount));
|
|
873
1102
|
const observed = BigInt(xlmToStroops(nativeBalance));
|
|
1103
|
+
if (observed <= FORWARD_SHORTFALL_TOLERANCE_STROOPS) {
|
|
1104
|
+
throw new VerificationError(
|
|
1105
|
+
"mediator_forward_balance_unknown",
|
|
1106
|
+
"The balance this close would pass on is unknown or too small to check, so the hand-off is refused. Run the analysis again, or close to a wallet you control."
|
|
1107
|
+
);
|
|
1108
|
+
}
|
|
874
1109
|
const floor = observed - FORWARD_SHORTFALL_TOLERANCE_STROOPS;
|
|
875
1110
|
if (forwarded < floor) {
|
|
876
1111
|
throw new VerificationError(
|
|
@@ -925,6 +1160,8 @@ function assertCloseIntent(intent, expected) {
|
|
|
925
1160
|
const forward = assertMergeShape(intent, expected);
|
|
926
1161
|
const seenTransfers = /* @__PURE__ */ new Set();
|
|
927
1162
|
const seenConversions = /* @__PURE__ */ new Set();
|
|
1163
|
+
const seenWithdrawals = /* @__PURE__ */ new Set();
|
|
1164
|
+
const seenSponsoredEntries = /* @__PURE__ */ new Set();
|
|
928
1165
|
for (const op of intent.operations) {
|
|
929
1166
|
switch (op.type) {
|
|
930
1167
|
case "payment": {
|
|
@@ -980,7 +1217,11 @@ function assertCloseIntent(intent, expected) {
|
|
|
980
1217
|
}
|
|
981
1218
|
break;
|
|
982
1219
|
}
|
|
1220
|
+
case "liquidity_pool_withdraw":
|
|
1221
|
+
assertPoolWithdrawal(op, expected, seenWithdrawals);
|
|
1222
|
+
break;
|
|
983
1223
|
case "change_trust":
|
|
1224
|
+
if (op.pool || op.asset.startsWith("pool:")) assertPoolLine(op, expected);
|
|
984
1225
|
if (Number(op.limit) !== 0 && !expected.claimTrustlineAssets.includes(op.asset)) {
|
|
985
1226
|
throw new VerificationError(
|
|
986
1227
|
"trustline_not_removal",
|
|
@@ -1414,11 +1655,8 @@ function assertCloseIntent(intent, expected) {
|
|
|
1414
1655
|
"operation_unknown",
|
|
1415
1656
|
"The transaction contains an unrecognized operation."
|
|
1416
1657
|
);
|
|
1417
|
-
// Stryker disable next-line ConditionalExpression: this case's entire body is a no-op
|
|
1418
|
-
// `break` (see the comment below for why revoke_sponsorship needs no check). Collapsing it
|
|
1419
|
-
// just falls through to the next case, which is also a no-op `break` - unobservable either
|
|
1420
|
-
// way.
|
|
1421
1658
|
case "revoke_sponsorship":
|
|
1659
|
+
assertSponsoredEntryRevoke(op, expected, seenSponsoredEntries);
|
|
1422
1660
|
break;
|
|
1423
1661
|
case "account_merge":
|
|
1424
1662
|
case "claim_claimable_balance":
|
|
@@ -2043,13 +2281,13 @@ var contract_registry_default = {
|
|
|
2043
2281
|
protocol: "soroswap",
|
|
2044
2282
|
kind: "aggregator",
|
|
2045
2283
|
address: "CARVQXFP4JF5ELLXUMQ6DALR346YVGBMQOHB4ENA7SSVXAYABXLBDDC4",
|
|
2046
|
-
wasmHash: "
|
|
2284
|
+
wasmHash: "72138d720c2d89831906a5f6e88dcf832abda02125fa32e9f0ebf1714041901f",
|
|
2047
2285
|
version: "v2",
|
|
2048
2286
|
label: "Soroswap aggregator v2 (mainnet, deployed 2026-09-14) - the contract a multi-protocol token conversion invokes; swap_exact_in only, partner None",
|
|
2049
2287
|
verifiedLive: true,
|
|
2050
|
-
verifiedBy: "2026-09-29: readLiveWasmHash over RPC
|
|
2288
|
+
verifiedBy: "2026-09-29: readLiveWasmHash over RPC; its config() names the registry's Soroswap and Aquarius routers; 2026-10-10 (#581) and 2026-11-17 (#1008): live hash re-read and matched; 2026-11-23 (#1112): re-pinned after the admin-signed upgrade tx a63e8e58a88623b4a22a0a4cab19c1514ebcc0d28702f04e384bc615e634ad33 (ledger 65628395), which the Soroswap SDK calls aggregator v3; no public source or SEP-55 metadata, so trusted by spec diff, on-chain swap_exact_in auth and a read-only simulation",
|
|
2051
2289
|
source: "the Soroswap API's own swap builds and the Soroswap team's confirmation; not yet in soroswap/aggregator public/mainnet.contracts.json",
|
|
2052
|
-
verifiedAt: "2026-11-
|
|
2290
|
+
verifiedAt: "2026-11-23"
|
|
2053
2291
|
},
|
|
2054
2292
|
{
|
|
2055
2293
|
network: "mainnet",
|
|
@@ -2700,6 +2938,9 @@ function verifyCloseTransaction2(input) {
|
|
|
2700
2938
|
function exitExpectations2(accountState, network) {
|
|
2701
2939
|
return exitExpectations(accountState, network);
|
|
2702
2940
|
}
|
|
2941
|
+
function poolWithdrawalExpectations2(accountState) {
|
|
2942
|
+
return poolWithdrawalExpectations(accountState);
|
|
2943
|
+
}
|
|
2703
2944
|
function requiresMediator(address, network) {
|
|
2704
2945
|
return mediatorAllowedFor(address, network);
|
|
2705
2946
|
}
|
|
@@ -2707,4 +2948,4 @@ function verifyRevokeAllowanceTransaction2(unsignedXdr, networkPassphrase, expec
|
|
|
2707
2948
|
verifyRevokeAllowanceTransaction(unsignedXdr, networkPassphrase, expected, nowSeconds);
|
|
2708
2949
|
}
|
|
2709
2950
|
|
|
2710
|
-
export { RevokeAllowanceVerificationError, VerificationError, exitExpectations2 as exitExpectations, requiresMediator, verifyCloseTransaction2 as verifyCloseTransaction, verifyRevokeAllowanceTransaction2 as verifyRevokeAllowanceTransaction };
|
|
2951
|
+
export { RevokeAllowanceVerificationError, VerificationError, exitExpectations2 as exitExpectations, poolWithdrawalExpectations2 as poolWithdrawalExpectations, requiresMediator, verifyCloseTransaction2 as verifyCloseTransaction, verifyRevokeAllowanceTransaction2 as verifyRevokeAllowanceTransaction };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lumenwipe/verify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Reference verifier for LumenWipe close transactions, compiled from the web app's own trust anchor, with a conformance vector set.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|