@glacislabs/stablegenie-zerodelta 3.4.0 → 4.0.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/dist/{chunk-Q3YSX4D5.js → chunk-ABI6ZH7O.js} +344 -3
- package/dist/{chunk-TYQF2L5C.js → chunk-FJQQLB2K.js} +411 -19
- package/dist/core/index.cjs +433 -18
- package/dist/core/index.d.cts +21 -4
- package/dist/core/index.d.ts +21 -4
- package/dist/core/index.js +1 -1
- package/dist/index.cjs +764 -26
- package/dist/index.d.cts +22 -3
- package/dist/index.d.ts +22 -3
- package/dist/index.js +2 -2
- package/dist/{mount-BT2NejVt.d.ts → mount-D5k_u92L.d.ts} +1 -1
- package/dist/{mount-D8NmWtqV.d.cts → mount-mcyZAzZc.d.cts} +1 -1
- package/dist/mount.cjs +743 -26
- package/dist/mount.d.cts +2 -2
- package/dist/mount.d.ts +2 -2
- package/dist/mount.js +2 -2
- package/dist/standalone.global.js +99 -7
- package/dist/{verify-34voZYj1.d.cts → verify-C9vzpm4T.d.cts} +225 -1
- package/dist/{verify-34voZYj1.d.ts → verify-C9vzpm4T.d.ts} +225 -1
- package/package.json +1 -1
|
@@ -23,6 +23,7 @@ var TRADEABLE_RWA_ASSETS = /* @__PURE__ */ new Set([
|
|
|
23
23
|
]);
|
|
24
24
|
var SUPPORTED_ASSETS = /* @__PURE__ */ new Set([...STABLE_ASSETS, ...TRADEABLE_RWA_ASSETS]);
|
|
25
25
|
var API_CACHE_TTL_MS = 6e4;
|
|
26
|
+
var SCREEN_CACHE_TTL_MS = 5 * 6e4;
|
|
26
27
|
var MAX_QUOTE_CANDIDATES = 8;
|
|
27
28
|
var QUOTE_BUFFER_BPS = 50;
|
|
28
29
|
var LZ_FEE_BUFFER_BPS = 1500n;
|
|
@@ -749,6 +750,338 @@ function brokenLaneReason(lane) {
|
|
|
749
750
|
}
|
|
750
751
|
}
|
|
751
752
|
|
|
753
|
+
// src/core/compliance.ts
|
|
754
|
+
var COMPLIANCE_DENY_LABEL = "Compliance check failed";
|
|
755
|
+
function complianceView(compliance, hasQuote = true) {
|
|
756
|
+
if (!hasQuote) {
|
|
757
|
+
return {
|
|
758
|
+
tone: "neutral",
|
|
759
|
+
label: "Compliance checks run with your quote",
|
|
760
|
+
headline: "No compliance decision for this payment yet",
|
|
761
|
+
blocked: false,
|
|
762
|
+
needsAction: false,
|
|
763
|
+
screened: false
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
const decision = compliance?.decision;
|
|
767
|
+
const screened = compliance?.status === "SCREENED";
|
|
768
|
+
if (decision === "DENY") {
|
|
769
|
+
return {
|
|
770
|
+
tone: "blocked",
|
|
771
|
+
label: COMPLIANCE_DENY_LABEL,
|
|
772
|
+
headline: "Blocked by compliance policy",
|
|
773
|
+
blocked: true,
|
|
774
|
+
needsAction: false,
|
|
775
|
+
screened
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
if (decision === "REVIEW" || decision === "REMEDIATE") {
|
|
779
|
+
const word = decision.toLowerCase();
|
|
780
|
+
return {
|
|
781
|
+
tone: "warn",
|
|
782
|
+
label: `Compliance: ${word} required`,
|
|
783
|
+
headline: `Manual ${word} required`,
|
|
784
|
+
blocked: false,
|
|
785
|
+
needsAction: true,
|
|
786
|
+
screened
|
|
787
|
+
};
|
|
788
|
+
}
|
|
789
|
+
if (decision === "ALLOW") {
|
|
790
|
+
return {
|
|
791
|
+
tone: "ok",
|
|
792
|
+
label: screened ? "Compliance checks passed" : "Allowed \u2014 wallets not screened",
|
|
793
|
+
headline: screened ? "Wallets screened and allowed" : "Allowed \u2014 wallets not screened",
|
|
794
|
+
blocked: false,
|
|
795
|
+
needsAction: false,
|
|
796
|
+
screened
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
return {
|
|
800
|
+
tone: "neutral",
|
|
801
|
+
label: screened ? "Screened \u2014 no policy decision returned" : "No compliance decision returned",
|
|
802
|
+
headline: screened ? "Screened \u2014 no policy decision returned" : "No compliance decision returned",
|
|
803
|
+
blocked: false,
|
|
804
|
+
needsAction: false,
|
|
805
|
+
screened
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
var CATEGORY_PHRASES = {
|
|
809
|
+
SANCTIONS: "sanctions",
|
|
810
|
+
TERRORISM_FINANCING: "terrorism financing",
|
|
811
|
+
STOLEN_FUNDS: "stolen funds",
|
|
812
|
+
RANSOMWARE: "ransomware",
|
|
813
|
+
SCAM: "scam activity",
|
|
814
|
+
DARKNET: "darknet activity",
|
|
815
|
+
MIXER: "mixer usage",
|
|
816
|
+
HIGH_RISK_ENTITY: "a high-risk entity",
|
|
817
|
+
PEP: "a politically-exposed person",
|
|
818
|
+
INDIRECT_EXPOSURE: "indirect exposure",
|
|
819
|
+
UNCLASSIFIED: "an unrecognized risk",
|
|
820
|
+
UNKNOWN: "an unrecognized risk"
|
|
821
|
+
};
|
|
822
|
+
function categoryLabel(code) {
|
|
823
|
+
const key = code.trim().toUpperCase();
|
|
824
|
+
const LABELS = {
|
|
825
|
+
SANCTIONS: "Sanctions",
|
|
826
|
+
TERRORISM_FINANCING: "Terrorist financing",
|
|
827
|
+
STOLEN_FUNDS: "Stolen funds",
|
|
828
|
+
RANSOMWARE: "Ransomware",
|
|
829
|
+
SCAM: "Scam",
|
|
830
|
+
DARKNET: "Darknet services",
|
|
831
|
+
MIXER: "Mixer",
|
|
832
|
+
HIGH_RISK_ENTITY: "High-risk entity",
|
|
833
|
+
PEP: "Politically exposed person (PEP)",
|
|
834
|
+
INDIRECT_EXPOSURE: "Indirect exposure",
|
|
835
|
+
UNCLASSIFIED: "Unclassified risk",
|
|
836
|
+
UNKNOWN: "Unclassified risk"
|
|
837
|
+
};
|
|
838
|
+
return LABELS[key] ?? key.toLowerCase().replace(/_/g, " ");
|
|
839
|
+
}
|
|
840
|
+
function cleanJurisdiction(code) {
|
|
841
|
+
return code.replace(/^(OFAC|TIER\d+|SANCTIONED)_/i, "").trim();
|
|
842
|
+
}
|
|
843
|
+
function stripBundlePrefix(head) {
|
|
844
|
+
if (head.startsWith("policy_")) return { head: head.slice("policy_".length), source: "policy" };
|
|
845
|
+
if (head.startsWith("legislation_")) return { head: head.slice("legislation_".length), source: "legislation" };
|
|
846
|
+
return { head, source: null };
|
|
847
|
+
}
|
|
848
|
+
function complianceReasonHead(raw) {
|
|
849
|
+
return stripBundlePrefix((raw.split(":")[0] ?? "").trim()).head;
|
|
850
|
+
}
|
|
851
|
+
function usd(raw) {
|
|
852
|
+
const n = Number(raw);
|
|
853
|
+
if (!Number.isFinite(n)) return `$${raw}`;
|
|
854
|
+
return `$${n.toLocaleString("en-US", { maximumFractionDigits: 2 })}`;
|
|
855
|
+
}
|
|
856
|
+
function capFromDetail(detail) {
|
|
857
|
+
const m = detail.match(/>([\d.]+)/);
|
|
858
|
+
return m ? ` (${usd(m[1])})` : "";
|
|
859
|
+
}
|
|
860
|
+
function categoryPhrase(detail) {
|
|
861
|
+
const cat = detail.replace(/\s*\(.*\)$/, "").toUpperCase();
|
|
862
|
+
return CATEGORY_PHRASES[cat] ?? cat.toLowerCase().replace(/_/g, " ");
|
|
863
|
+
}
|
|
864
|
+
function humanizeComplianceReason(raw) {
|
|
865
|
+
const [headRaw, ...restParts] = raw.split(":");
|
|
866
|
+
const detail = restParts.join(":").trim();
|
|
867
|
+
const { head, source } = stripBundlePrefix((headRaw ?? "").trim());
|
|
868
|
+
const scope = source === "legislation" ? "applicable regulations" : "the applicable policy";
|
|
869
|
+
switch (head) {
|
|
870
|
+
case "asset_pair_not_allowed": {
|
|
871
|
+
const m = detail.match(/^(\S+)->(\S+)\s+in\s+(\S+)/);
|
|
872
|
+
if (m) return `${m[1]} \u2192 ${m[2]} isn't available in your region (${cleanJurisdiction(m[3])}).`;
|
|
873
|
+
return "This asset pair isn't available in your region.";
|
|
874
|
+
}
|
|
875
|
+
case "asset_not_allowed": {
|
|
876
|
+
const m = detail.match(/^(\S+?)->(\S+?)(?::|$)/);
|
|
877
|
+
if (m) return `${m[1]} \u2192 ${m[2]} isn't permitted under ${scope}.`;
|
|
878
|
+
return `This asset pair isn't permitted under ${scope}.`;
|
|
879
|
+
}
|
|
880
|
+
case "blocked_jurisdiction":
|
|
881
|
+
return `Your region (${cleanJurisdiction(detail)}) isn't supported.`;
|
|
882
|
+
case "blocked_destination_jurisdiction":
|
|
883
|
+
return `The destination region (${cleanJurisdiction(detail)}) isn't supported.`;
|
|
884
|
+
case "jurisdiction_out_of_scope":
|
|
885
|
+
return `Not covered by ${scope}.`;
|
|
886
|
+
case "ui_block":
|
|
887
|
+
return `Payments aren't available in your region (${cleanJurisdiction(detail)}).`;
|
|
888
|
+
case "blocked_corridor_mode":
|
|
889
|
+
return "This route isn't currently open for payments.";
|
|
890
|
+
case "blocked_category":
|
|
891
|
+
return `Flagged for ${categoryPhrase(detail)}.`;
|
|
892
|
+
case "amount_exceeds_max_order_usd":
|
|
893
|
+
case "amount_exceeds_max":
|
|
894
|
+
return `Amount exceeds the maximum order size${capFromDetail(detail)}.`;
|
|
895
|
+
case "amount_exceeds_actor_cap":
|
|
896
|
+
return `Amount exceeds the limit for your account type${capFromDetail(detail)}.`;
|
|
897
|
+
case "amount_exceeds_jurisdiction_max":
|
|
898
|
+
return `Amount exceeds the limit for your region${capFromDetail(detail)}.`;
|
|
899
|
+
case "source_chain_not_allowed":
|
|
900
|
+
return `The source chain isn't permitted under ${scope}.`;
|
|
901
|
+
case "dest_chain_not_allowed":
|
|
902
|
+
return `The destination chain isn't permitted under ${scope}.`;
|
|
903
|
+
default:
|
|
904
|
+
return detail ? `${head.replace(/_/g, " ")} \u2014 ${detail}` : head.replace(/_/g, " ");
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
var COMPLIANCE_CHECK_ORDER = [
|
|
908
|
+
"location",
|
|
909
|
+
"screening",
|
|
910
|
+
"risk",
|
|
911
|
+
"asset",
|
|
912
|
+
"limits"
|
|
913
|
+
];
|
|
914
|
+
var CHECK_LABELS = {
|
|
915
|
+
location: "Location and corridor permitted",
|
|
916
|
+
screening: "Both wallets screened",
|
|
917
|
+
risk: "Risk policy passed",
|
|
918
|
+
asset: "Asset and amount allowed",
|
|
919
|
+
limits: "Transaction limits verified"
|
|
920
|
+
};
|
|
921
|
+
var CHECK_HEADS = {
|
|
922
|
+
location: [
|
|
923
|
+
"blocked_jurisdiction",
|
|
924
|
+
"blocked_destination_jurisdiction",
|
|
925
|
+
"ui_block",
|
|
926
|
+
"blocked_corridor_mode",
|
|
927
|
+
"jurisdiction_out_of_scope"
|
|
928
|
+
],
|
|
929
|
+
screening: [],
|
|
930
|
+
risk: ["blocked_category"],
|
|
931
|
+
asset: ["asset_pair_not_allowed", "asset_not_allowed", "source_chain_not_allowed", "dest_chain_not_allowed"],
|
|
932
|
+
limits: [
|
|
933
|
+
"amount_exceeds_max_order_usd",
|
|
934
|
+
"amount_exceeds_max",
|
|
935
|
+
"amount_exceeds_actor_cap",
|
|
936
|
+
"amount_exceeds_jurisdiction_max"
|
|
937
|
+
]
|
|
938
|
+
};
|
|
939
|
+
function distinctScreenedWallets(compliance) {
|
|
940
|
+
const seen = /* @__PURE__ */ new Set();
|
|
941
|
+
const wallets = [];
|
|
942
|
+
for (const raw of compliance?.screenedWallets ?? []) {
|
|
943
|
+
const address = raw?.trim();
|
|
944
|
+
if (!address) continue;
|
|
945
|
+
const key = /^0x[0-9a-fA-F]+$/.test(address) ? address.toLowerCase() : address;
|
|
946
|
+
if (seen.has(key)) continue;
|
|
947
|
+
seen.add(key);
|
|
948
|
+
wallets.push(address);
|
|
949
|
+
}
|
|
950
|
+
return wallets;
|
|
951
|
+
}
|
|
952
|
+
function shortAddress(a) {
|
|
953
|
+
return a.length > 12 ? `${a.slice(0, 6)}\u2026${a.slice(-4)}` : a;
|
|
954
|
+
}
|
|
955
|
+
function screeningLabel(wallets) {
|
|
956
|
+
if (wallets === 1) return "Wallet screened";
|
|
957
|
+
if (wallets === 2) return CHECK_LABELS.screening;
|
|
958
|
+
return "Wallets screened";
|
|
959
|
+
}
|
|
960
|
+
function complianceChecks(compliance, cv = complianceView(compliance)) {
|
|
961
|
+
if (cv.tone === "neutral") return [];
|
|
962
|
+
const byControl = /* @__PURE__ */ new Map();
|
|
963
|
+
for (const raw of compliance?.reasons ?? []) {
|
|
964
|
+
const head = complianceReasonHead(raw);
|
|
965
|
+
const id = COMPLIANCE_CHECK_ORDER.find((c) => CHECK_HEADS[c].includes(head));
|
|
966
|
+
if (!id) continue;
|
|
967
|
+
byControl.set(id, [...byControl.get(id) ?? [], raw]);
|
|
968
|
+
}
|
|
969
|
+
const screenedWallets = distinctScreenedWallets(compliance);
|
|
970
|
+
const wallets = screenedWallets.length;
|
|
971
|
+
const blocking = compliance?.blockingCategories?.length ?? 0;
|
|
972
|
+
return COMPLIANCE_CHECK_ORDER.map((id) => {
|
|
973
|
+
if (id === "screening") {
|
|
974
|
+
const ok2 = cv.screened || wallets > 0;
|
|
975
|
+
const note = wallets === 1 ? shortAddress(screenedWallets[0]) : wallets > 1 ? `${wallets} wallets screened` : void 0;
|
|
976
|
+
return { id, label: ok2 ? screeningLabel(wallets) : "Wallets not screened", ok: ok2, reasons: [], note };
|
|
977
|
+
}
|
|
978
|
+
const reasons = byControl.get(id) ?? [];
|
|
979
|
+
const ok = reasons.length === 0 && !(id === "risk" && blocking > 0);
|
|
980
|
+
return { id, label: CHECK_LABELS[id], ok, reasons };
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
function unattributedComplianceReasons(compliance, cv = complianceView(compliance)) {
|
|
984
|
+
const claimed = new Set(complianceChecks(compliance, cv).flatMap((c) => c.reasons));
|
|
985
|
+
return (compliance?.reasons ?? []).filter((r) => !claimed.has(r));
|
|
986
|
+
}
|
|
987
|
+
function complianceControlsEvaluated(compliance, cv = complianceView(compliance)) {
|
|
988
|
+
const checks = complianceChecks(compliance, cv);
|
|
989
|
+
if (checks.length === 0) return 0;
|
|
990
|
+
const named = /* @__PURE__ */ new Set();
|
|
991
|
+
for (const raw of [...compliance?.appliedPolicyNames ?? [], ...compliance?.appliedLegislation ?? []]) {
|
|
992
|
+
const name = raw?.trim();
|
|
993
|
+
if (name) named.add(name.toLowerCase());
|
|
994
|
+
}
|
|
995
|
+
return checks.length + named.size;
|
|
996
|
+
}
|
|
997
|
+
function complianceControlsLine(compliance, cv = complianceView(compliance)) {
|
|
998
|
+
if (cv.blocked || cv.needsAction) return cv.headline;
|
|
999
|
+
const n = complianceControlsEvaluated(compliance, cv);
|
|
1000
|
+
if (n === 0) return cv.headline;
|
|
1001
|
+
return `${n} compliance control${n === 1 ? "" : "s"} evaluated for this payment`;
|
|
1002
|
+
}
|
|
1003
|
+
function directComplianceFromScreens(screens) {
|
|
1004
|
+
const blockedAny = screens.some((s) => s.blocked);
|
|
1005
|
+
const cats = (pick) => [
|
|
1006
|
+
...new Set(screens.flatMap((s) => pick(s) ?? []))
|
|
1007
|
+
];
|
|
1008
|
+
return {
|
|
1009
|
+
status: "SCREENED",
|
|
1010
|
+
decision: blockedAny ? "DENY" : "ALLOW",
|
|
1011
|
+
screenedWallets: screens.map((s) => s.address),
|
|
1012
|
+
riskCategories: cats((s) => s.riskCategories),
|
|
1013
|
+
flaggedCategories: cats((s) => s.flaggedCategories),
|
|
1014
|
+
blockingCategories: cats((s) => s.blockingCategories),
|
|
1015
|
+
reasons: blockedAny ? cats((s) => s.blockingCategories).map((c) => `blocked_category:${c}`) : []
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
var DIRECT_CHECK_IDS = ["screening", "risk"];
|
|
1019
|
+
var DIRECT_SCOPE_NOTE = "Direct settlement moves your funds straight to the recipient, so wallet screening applies. Jurisdiction, corridor and amount policy are evaluated on routed payments.";
|
|
1020
|
+
var BLOCK_CATEGORY_LABELS = {
|
|
1021
|
+
STOLEN_FUNDS: "flagged as associated with stolen funds",
|
|
1022
|
+
SANCTIONS: "on a sanctions list",
|
|
1023
|
+
SANCTIONED: "on a sanctions list",
|
|
1024
|
+
OFAC: "on a sanctions list",
|
|
1025
|
+
TERRORIST_FINANCING: "flagged for terrorist financing",
|
|
1026
|
+
TERRORISM_FINANCING: "flagged for terrorist financing",
|
|
1027
|
+
FRAUD: "flagged for fraud",
|
|
1028
|
+
SCAM: "flagged as a scam address"
|
|
1029
|
+
};
|
|
1030
|
+
var BLOCK_LABEL_DEFAULT = "flagged by compliance screening";
|
|
1031
|
+
function blockLabelFor(categories) {
|
|
1032
|
+
for (const raw of categories) {
|
|
1033
|
+
const label = BLOCK_CATEGORY_LABELS[String(raw || "").trim().toUpperCase()];
|
|
1034
|
+
if (label) return label;
|
|
1035
|
+
}
|
|
1036
|
+
return BLOCK_LABEL_DEFAULT;
|
|
1037
|
+
}
|
|
1038
|
+
var REASON_TAGS = {
|
|
1039
|
+
blocked_jurisdiction: "Restricted country",
|
|
1040
|
+
ui_block: "Restricted country",
|
|
1041
|
+
blocked_destination_jurisdiction: "Restricted destination",
|
|
1042
|
+
blocked_corridor_mode: "Corridor closed",
|
|
1043
|
+
blocked_category: "Risk flag",
|
|
1044
|
+
amount_exceeds_max_order_usd: "Limit exceeded",
|
|
1045
|
+
amount_exceeds_max: "Limit exceeded",
|
|
1046
|
+
amount_exceeds_actor_cap: "Limit exceeded",
|
|
1047
|
+
amount_exceeds_jurisdiction_max: "Limit exceeded",
|
|
1048
|
+
asset_pair_not_allowed: "Asset not allowed",
|
|
1049
|
+
asset_not_allowed: "Asset not allowed",
|
|
1050
|
+
source_chain_not_allowed: "Chain not allowed",
|
|
1051
|
+
dest_chain_not_allowed: "Chain not allowed",
|
|
1052
|
+
jurisdiction_out_of_scope: "Out of scope"
|
|
1053
|
+
};
|
|
1054
|
+
function complianceReasonTag(raw) {
|
|
1055
|
+
const head = complianceReasonHead(raw);
|
|
1056
|
+
return REASON_TAGS[head] ?? head.replace(/_/g, " ");
|
|
1057
|
+
}
|
|
1058
|
+
function complianceTagOf(compliance) {
|
|
1059
|
+
const first = (compliance?.reasons ?? [])[0];
|
|
1060
|
+
return first ? complianceReasonTag(first) : "";
|
|
1061
|
+
}
|
|
1062
|
+
var FLOOR_CATEGORIES = ["SANCTIONS", "TERRORISM_FINANCING", "STOLEN_FUNDS", "RANSOMWARE"];
|
|
1063
|
+
var TUNABLE_CATEGORIES = ["SCAM", "DARKNET", "MIXER", "HIGH_RISK_ENTITY", "PEP", "INDIRECT_EXPOSURE", "UNCLASSIFIED"];
|
|
1064
|
+
var TUNED_OUTCOMES = {
|
|
1065
|
+
SCAM: "blocked",
|
|
1066
|
+
DARKNET: "blocked",
|
|
1067
|
+
MIXER: "flagged",
|
|
1068
|
+
HIGH_RISK_ENTITY: "flagged",
|
|
1069
|
+
PEP: "flagged",
|
|
1070
|
+
INDIRECT_EXPOSURE: "flagged",
|
|
1071
|
+
UNCLASSIFIED: "flagged"
|
|
1072
|
+
};
|
|
1073
|
+
function screeningOutcomeOf(category) {
|
|
1074
|
+
const key = category.trim().toUpperCase();
|
|
1075
|
+
if (FLOOR_CATEGORIES.includes(key)) return "always-blocked";
|
|
1076
|
+
return TUNED_OUTCOMES[key] ?? null;
|
|
1077
|
+
}
|
|
1078
|
+
var labelsFor = (outcome) => [...FLOOR_CATEGORIES, ...TUNABLE_CATEGORIES].filter((c) => screeningOutcomeOf(c) === outcome).map(categoryLabel);
|
|
1079
|
+
var SCREENING_BUCKETS = [
|
|
1080
|
+
{ outcome: "always-blocked", title: "Always blocked", detail: "Cannot be changed or disabled.", categories: labelsFor("always-blocked") },
|
|
1081
|
+
{ outcome: "blocked", title: "Blocked under this policy", detail: "The current policy stops the order.", categories: labelsFor("blocked") },
|
|
1082
|
+
{ outcome: "flagged", title: "Flagged", detail: "A warning is shown.", categories: labelsFor("flagged") }
|
|
1083
|
+
];
|
|
1084
|
+
|
|
752
1085
|
// src/core/solve.ts
|
|
753
1086
|
async function solveExactOut({ option, destination, destinationToken, payer, fetchQuote }) {
|
|
754
1087
|
const destDecimals = assetDecimals(destinationToken);
|
|
@@ -985,7 +1318,7 @@ function routeLabelFor(option, destinationToken, result) {
|
|
|
985
1318
|
const bridge = result.quote.bridge ? ` via ${result.quote.bridge}` : "";
|
|
986
1319
|
return `Swap ${option.symbol} to ${destinationToken.symbol} and settle on ZeroDelta${bridge}.`;
|
|
987
1320
|
}
|
|
988
|
-
async function buildRoute({ option, destination, destinationToken, chains, payer, fetchQuote, solve = solveExactOut, amountInRaw }) {
|
|
1321
|
+
async function buildRoute({ option, destination, destinationToken, chains, payer, fetchQuote, solve = solveExactOut, amountInRaw, compliance }) {
|
|
989
1322
|
const result = await solve({ option, destination, destinationToken, payer, fetchQuote, amountInRaw });
|
|
990
1323
|
const quote = result.quote;
|
|
991
1324
|
const destDecimals = assetDecimals(destinationToken);
|
|
@@ -1032,7 +1365,11 @@ async function buildRoute({ option, destination, destinationToken, chains, payer
|
|
|
1032
1365
|
bridge: quote.bridge,
|
|
1033
1366
|
feeBps: quote.feeBps,
|
|
1034
1367
|
estimatedDuration: quote.estimatedDuration,
|
|
1035
|
-
iterations: result.iterations
|
|
1368
|
+
iterations: result.iterations,
|
|
1369
|
+
// A direct transfer never reaches /quote (solve.ts short-circuits it), so there is no
|
|
1370
|
+
// gateway decision to carry. The caller screens both parties itself and passes the
|
|
1371
|
+
// synthesized verdict in — see plan.ts and compliance.ts::directComplianceFromScreens.
|
|
1372
|
+
compliance
|
|
1036
1373
|
}
|
|
1037
1374
|
};
|
|
1038
1375
|
}
|
|
@@ -1116,7 +1453,11 @@ async function buildRoute({ option, destination, destinationToken, chains, payer
|
|
|
1116
1453
|
gasCostSource: quote.gasCostSource,
|
|
1117
1454
|
msgValue: valueRaw.toString(),
|
|
1118
1455
|
deadline: order.deadline,
|
|
1119
|
-
iterations: result.iterations
|
|
1456
|
+
iterations: result.iterations,
|
|
1457
|
+
// Carried verbatim from the gateway's decision on THIS wallet pair. The projection used to
|
|
1458
|
+
// drop it, which is why the widget could show a price with no evidence of the control that
|
|
1459
|
+
// produced it.
|
|
1460
|
+
compliance: quote.compliance
|
|
1120
1461
|
}
|
|
1121
1462
|
};
|
|
1122
1463
|
}
|
|
@@ -1152,25 +1493,20 @@ function apiMessage(json, fallback) {
|
|
|
1152
1493
|
}
|
|
1153
1494
|
return sanitizeMessage(err?.message, fallback);
|
|
1154
1495
|
}
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
TERRORIST_FINANCING: "flagged for terrorist financing",
|
|
1161
|
-
FRAUD: "flagged for fraud",
|
|
1162
|
-
SCAM: "flagged as a scam address"
|
|
1163
|
-
};
|
|
1164
|
-
var BLOCK_LABEL_DEFAULT = "flagged by compliance screening";
|
|
1496
|
+
function isStructuredComplianceBlock(error) {
|
|
1497
|
+
const code = String(error?.code || "").toUpperCase();
|
|
1498
|
+
if (code === "COMPLIANCE_BLOCKED" || code === "COMPLIANCE_BLOCK") return true;
|
|
1499
|
+
return error?.status === 422 && Array.isArray(error?.reasons) && error.reasons.length > 0;
|
|
1500
|
+
}
|
|
1165
1501
|
function classifyQuoteError(error) {
|
|
1166
1502
|
if (!error) return null;
|
|
1167
1503
|
const reasons = Array.isArray(error.reasons) ? error.reasons : [];
|
|
1168
1504
|
const haystack = `${error.message || ""} ${reasons.join(" ")}`;
|
|
1169
1505
|
const catMatch = /blocked_category:\s*([A-Za-z_]+)/i.exec(haystack);
|
|
1170
|
-
const isBlock = !!catMatch || error.code === "blocked" || error.code === "compliance_block" || /\b(stolen|sanction(?:s|ed|ing)?|block(?:ed|list)|screen(?:ed|ing)?|compliance|ofac|denylist|blacklist)\b/i.test(haystack);
|
|
1506
|
+
const isBlock = isStructuredComplianceBlock(error) || !!catMatch || error.code === "blocked" || error.code === "compliance_block" || /\b(stolen|sanction(?:s|ed|ing)?|block(?:ed|list)|screen(?:ed|ing)?|compliance|ofac|denylist|blacklist)\b/i.test(haystack);
|
|
1171
1507
|
if (!isBlock) return null;
|
|
1172
1508
|
const category = (catMatch?.[1] || "").toUpperCase() || "COMPLIANCE";
|
|
1173
|
-
const label =
|
|
1509
|
+
const label = blockLabelFor([category]);
|
|
1174
1510
|
return {
|
|
1175
1511
|
blocked: true,
|
|
1176
1512
|
category,
|
|
@@ -1194,6 +1530,8 @@ function createApiClient(cfg) {
|
|
|
1194
1530
|
routes: null,
|
|
1195
1531
|
health: null
|
|
1196
1532
|
};
|
|
1533
|
+
const screenCache = /* @__PURE__ */ new Map();
|
|
1534
|
+
const screenInflight = /* @__PURE__ */ new Map();
|
|
1197
1535
|
const apiBase = cfg.apiBase.replace(/\/$/, "");
|
|
1198
1536
|
async function apiRequest(path, init = {}) {
|
|
1199
1537
|
const apiKey = await cfg.getApiKey();
|
|
@@ -1288,7 +1626,32 @@ function createApiClient(cfg) {
|
|
|
1288
1626
|
}
|
|
1289
1627
|
throw lastError;
|
|
1290
1628
|
}
|
|
1291
|
-
|
|
1629
|
+
async function screenWallet(address, chainId) {
|
|
1630
|
+
const addr = String(address || "").trim();
|
|
1631
|
+
if (!addr) throw apiError("An address is required to screen a wallet.", { code: "bad_request" });
|
|
1632
|
+
const key = `${/^0x[0-9a-fA-F]+$/.test(addr) ? addr.toLowerCase() : addr}|${chainId ?? ""}`;
|
|
1633
|
+
const hit = screenCache.get(key);
|
|
1634
|
+
if (hit && Date.now() - hit.at < SCREEN_CACHE_TTL_MS) return hit.value;
|
|
1635
|
+
const inflight = screenInflight.get(key);
|
|
1636
|
+
if (inflight) return inflight;
|
|
1637
|
+
const request = apiRequest("/screen/wallet", {
|
|
1638
|
+
method: "POST",
|
|
1639
|
+
body: JSON.stringify(chainId == null ? { address: addr } : { address: addr, chainId }),
|
|
1640
|
+
timeoutMs: 12e3
|
|
1641
|
+
}).then((screen) => {
|
|
1642
|
+
if (!screen || typeof screen !== "object" || typeof screen.blocked !== "boolean") {
|
|
1643
|
+
throw apiError("Compliance screening returned an unusable result.", { code: "bad_response" });
|
|
1644
|
+
}
|
|
1645
|
+
const value = { ...screen, address: screen.address || addr };
|
|
1646
|
+
screenCache.set(key, { at: Date.now(), value });
|
|
1647
|
+
return value;
|
|
1648
|
+
}).finally(() => {
|
|
1649
|
+
screenInflight.delete(key);
|
|
1650
|
+
});
|
|
1651
|
+
screenInflight.set(key, request);
|
|
1652
|
+
return request;
|
|
1653
|
+
}
|
|
1654
|
+
return { apiRequest, fetchChains, fetchTokens, fetchRoutes, fetchRouteHealth, fetchQuote, screenWallet, apiBase };
|
|
1292
1655
|
}
|
|
1293
1656
|
|
|
1294
1657
|
// src/core/plan.ts
|
|
@@ -1356,7 +1719,36 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
|
|
|
1356
1719
|
balanceTargets.push({ chainId: option.chainId, tokenAddress: option.address, decimals: option.decimals });
|
|
1357
1720
|
}
|
|
1358
1721
|
const walletBalances = readBalances ? await readBalances(payer, balanceTargets).catch(() => ({})) : {};
|
|
1359
|
-
const
|
|
1722
|
+
const directOptions = options.filter((option) => option.direct);
|
|
1723
|
+
let directCompliance = null;
|
|
1724
|
+
if (directOptions.length) {
|
|
1725
|
+
const parties = [];
|
|
1726
|
+
const seenParty = /* @__PURE__ */ new Set();
|
|
1727
|
+
for (const raw of [payer, destination.address]) {
|
|
1728
|
+
const addr = String(raw || "").trim();
|
|
1729
|
+
if (!addr) continue;
|
|
1730
|
+
const key = /^0x[0-9a-fA-F]+$/.test(addr) ? addr.toLowerCase() : addr;
|
|
1731
|
+
if (seenParty.has(key)) continue;
|
|
1732
|
+
seenParty.add(key);
|
|
1733
|
+
parties.push(addr);
|
|
1734
|
+
}
|
|
1735
|
+
try {
|
|
1736
|
+
const screens = await Promise.all(parties.map((address) => api.screenWallet(address, destination.chainId)));
|
|
1737
|
+
const blocked = screens.filter((screen) => screen.blocked);
|
|
1738
|
+
if (blocked.length) {
|
|
1739
|
+
const who = blocked.some((s) => s.address.toLowerCase() === payer.toLowerCase()) ? "your wallet" : "the recipient";
|
|
1740
|
+
const categories = [...new Set(blocked.flatMap((s) => s.blockingCategories ?? []))];
|
|
1741
|
+
throw apiError(
|
|
1742
|
+
`This payment was blocked by compliance screening \u2014 ${who} is ${blockLabelFor(categories)}. Choose a different recipient or connect a different wallet.`,
|
|
1743
|
+
{ blocked: true, blockedCategory: categories[0] || "COMPLIANCE", blockedReason: categories.join(", ") }
|
|
1744
|
+
);
|
|
1745
|
+
}
|
|
1746
|
+
directCompliance = directComplianceFromScreens(screens);
|
|
1747
|
+
} catch (error) {
|
|
1748
|
+
if (error?.blocked) throw error;
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1751
|
+
const candidates = directCompliance ? directOptions : [];
|
|
1360
1752
|
const heldOptions = options.filter((option) => !option.direct && hasPositiveBalance(option, walletBalances));
|
|
1361
1753
|
const heldKeys = new Set(heldOptions.map(optionBalanceKey));
|
|
1362
1754
|
const seenChains = /* @__PURE__ */ new Set();
|
|
@@ -1376,7 +1768,7 @@ async function fetchPaymentPlan(api, request, payer, wallet = {}, readBalances)
|
|
|
1376
1768
|
}
|
|
1377
1769
|
const routeErrors = [];
|
|
1378
1770
|
const routePromises = candidates.map(
|
|
1379
|
-
(option) => buildRoute({ option, destination, destinationToken, chains, payer, fetchQuote: api.fetchQuote }).catch((error) => {
|
|
1771
|
+
(option) => buildRoute({ option, destination, destinationToken, chains, payer, fetchQuote: api.fetchQuote, compliance: option.direct ? directCompliance ?? void 0 : void 0 }).catch((error) => {
|
|
1380
1772
|
routeErrors.push(error);
|
|
1381
1773
|
return null;
|
|
1382
1774
|
})
|
|
@@ -1966,4 +2358,4 @@ function createEngine(config = {}) {
|
|
|
1966
2358
|
};
|
|
1967
2359
|
}
|
|
1968
2360
|
|
|
1969
|
-
export { API_CACHE_TTL_MS, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, CHAIN_DISPLAY_NAMES, DEFAULT_WIDGET_API_BASE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, EXECUTABLE_STABLE_ASSETS, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_SAME_CLASS_PAY_BPS, MAX_UINT64, NO_PARTNER_ID, PREVIEW_OWNER, QUOTE_BUFFER_BPS, SAME_CLASS_STABLE, STABLEGENIE_INTENT_TTL_MS, STABLEGENIE_INTENT_VERSION, STABLEGENIE_SUPPORTED_ASSETS, STABLEGENIE_SUPPORTED_CHAIN_IDS, STABLE_ASSETS, SUBMIT_ORDER_SELECTOR, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, TRADEABLE_RWA_ASSETS, ZERO_ADDRESS, addressWord, allowanceCovers, apiError, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetClassOf, assetDecimals, brokenLaneFor, brokenLaneReason, buildCatalogue, buildPayOptions, buildRoute, buildSwapPlan, bytes32Word, bytesPayload, canAttachApiKey, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, classifyQuoteError, counterpartTokens, createApiClient, createEngine, createVerifier, decodeSubmitOrderCalldata, destinationAvailability, destinationKeys, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, executableRoutes, executionChainIds, fetchPaymentPlan, finalOf, findToken, formatNative, formatUnits, hasReachableDestination, hubDeliverableSymbols, isAddress, isDeliverable, isExecutableBridge, isHexAddress, isHexData, isHexQuantity, isKnownUnbridgeable, isLayerZeroRoute, isSourceToken, laneKey, laneKeys, maxNativeFeeWei, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeOrderRequest, normalizeOrderRequests, parseAllowedApiBase, parseUnitsDecimal, planErrorSummary, planMsgValueHex, productAssets, quoteSwapPreview, registryRpc, requiresNativeBridgeFee, resolveApiBase, resolveConfig, resolveSwapReceiver, routeNativeValue, scaleDecimals, solveExactIn, solveExactOut, sourceKeys, stableGenieIntentSchema, strip0x, suppressedLanes, symbolKey, toHexQuantity, tokenEnabled, tokenKey, txMatchesPlan, uint64Word, uintWord, validateDestination, validatePlannedTransaction, validateSwap };
|
|
2361
|
+
export { API_CACHE_TTL_MS, BLOCK_LABEL_DEFAULT, BUNDLED_NATIVE_SYMBOL, BUNDLED_RPC, CANONICAL_DECIMALS, CANONICAL_ESCROW, CANONICAL_INBOUND_BRIDGE, CHAIN_DISPLAY_NAMES, COMPLIANCE_CHECK_ORDER, COMPLIANCE_DENY_LABEL, DEFAULT_WIDGET_API_BASE, DIRECT_CHECK_IDS, DIRECT_SCOPE_NOTE, ERC20_ALLOWANCE_SELECTOR, ERC20_APPROVE_SELECTOR, ERC20_BALANCEOF_SELECTOR, ERC20_TRANSFER_SELECTOR, EXECUTABLE_STABLE_ASSETS, FLOOR_CATEGORIES, LZ_FEE_BUFFER_BPS, MAX_LZ_MSG_VALUE_WEI, MAX_LZ_MSG_VALUE_WEI_BY_CHAIN, MAX_QUOTE_CANDIDATES, MAX_SAME_CLASS_PAY_BPS, MAX_UINT64, NO_PARTNER_ID, PREVIEW_OWNER, QUOTE_BUFFER_BPS, SAME_CLASS_STABLE, SCREENING_BUCKETS, SCREEN_CACHE_TTL_MS, STABLEGENIE_INTENT_TTL_MS, STABLEGENIE_INTENT_VERSION, STABLEGENIE_SUPPORTED_ASSETS, STABLEGENIE_SUPPORTED_CHAIN_IDS, STABLE_ASSETS, SUBMIT_ORDER_SELECTOR, SUPPORTED_ASSETS, SUPPORTED_CHAIN_IDS, TRADEABLE_RWA_ASSETS, TUNABLE_CATEGORIES, ZERO_ADDRESS, addressWord, allowanceCovers, apiError, applyLayerZeroBuffer, assertAddress, assertQuoteMatchesSelection, assetClassOf, assetDecimals, blockLabelFor, brokenLaneFor, brokenLaneReason, buildCatalogue, buildPayOptions, buildRoute, buildSwapPlan, bytes32Word, bytesPayload, canAttachApiKey, categoryLabel, chainById, chainNameOf, chainSelectable, checkEscrow, checkNativeFee, classifyQuoteError, complianceChecks, complianceControlsEvaluated, complianceControlsLine, complianceReasonHead, complianceReasonTag, complianceTagOf, complianceView, counterpartTokens, createApiClient, createEngine, createVerifier, decodeSubmitOrderCalldata, destinationAvailability, destinationKeys, directComplianceFromScreens, distinctScreenedWallets, encodeAllowance, encodeApprove, encodeBalanceOf, encodeSubmitOrder, encodeTransfer, executableRoutes, executionChainIds, fetchPaymentPlan, finalOf, findToken, formatNative, formatUnits, hasReachableDestination, hubDeliverableSymbols, humanizeComplianceReason, isAddress, isDeliverable, isExecutableBridge, isHexAddress, isHexData, isHexQuantity, isKnownUnbridgeable, isLayerZeroRoute, isSourceToken, laneKey, laneKeys, maxNativeFeeWei, nativeFeeShortLabel, nativeFeeShortMessage, nativeSymbol, normalizeAddress, normalizeDecimalText, normalizeOrderRequest, normalizeOrderRequests, parseAllowedApiBase, parseUnitsDecimal, planErrorSummary, planMsgValueHex, productAssets, quoteSwapPreview, registryRpc, requiresNativeBridgeFee, resolveApiBase, resolveConfig, resolveSwapReceiver, routeNativeValue, scaleDecimals, screeningOutcomeOf, solveExactIn, solveExactOut, sourceKeys, stableGenieIntentSchema, strip0x, suppressedLanes, symbolKey, toHexQuantity, tokenEnabled, tokenKey, txMatchesPlan, uint64Word, uintWord, unattributedComplianceReasons, validateDestination, validatePlannedTransaction, validateSwap };
|