@@ -2,111 +2,9 @@ import { rpc, scValToBigInt, scValToNative, xdr } from '@stellar/stellar-sdk';
22import { config } from '../config' ;
33import { simulateRead } from './tx' ;
44
5- export interface ProtocolStatus {
6- status : 'ok' | 'unavailable' ;
7- paused : boolean ;
8- yieldPool : bigint ;
9- fetchedAt : number ;
10- error ?: string ;
11- }
12-
13- export type EscrowAction =
14- | 'create_commitment'
15- | 'create_commitment_default'
16- | 'fund_escrow'
17- | 'refund'
18- | 'refund_partial'
19- | 'early_exit'
20- | 'release'
21- | 'settle' ;
22-
23- export interface ActionPolicy {
24- action : EscrowAction ;
25- pausedBlocked : boolean ;
26- pausedReason ?: string ;
27- contractDoc : string ;
28- }
29-
30- /**
31- * Escrow pause policy table documenting contract entrypoint behavior.
32- * Mirrors contracts/escrow/src/lib.rs:
33- * - create_commitment: L433 (checks is_paused_internal -> Error::Paused)
34- * - create_commitment_default: L501 (checks is_paused_internal -> Error::Paused)
35- * - fund_escrow: L571 (checks is_paused_internal -> Error::Paused)
36- * - refund: L712 (checks is_paused_internal -> Error::Paused)
37- * - refund_partial: L723 (checks is_paused_internal -> Error::Paused)
38- * - early_exit: applies refund under the hood (checks is_paused_internal -> Error::Paused)
39- * - release: does NOT check pause on-chain (remains active for mature payouts)
40- * - settle: does NOT check pause on-chain (remains active for mature payouts)
41- */
42- export const ACTION_POLICIES : Record < EscrowAction , ActionPolicy > = {
43- create_commitment : {
44- action : 'create_commitment' ,
45- pausedBlocked : true ,
46- pausedReason : 'Commitment creation is temporarily paused by the contract operator.' ,
47- contractDoc : 'contracts/escrow/src/lib.rs: create_commitment checks is_paused_internal' ,
48- } ,
49- create_commitment_default : {
50- action : 'create_commitment_default' ,
51- pausedBlocked : true ,
52- pausedReason : 'Commitment creation is temporarily paused by the contract operator.' ,
53- contractDoc : 'contracts/escrow/src/lib.rs: create_commitment_default checks is_paused_internal' ,
54- } ,
55- fund_escrow : {
56- action : 'fund_escrow' ,
57- pausedBlocked : true ,
58- pausedReason : 'Escrow funding is temporarily paused by the contract operator.' ,
59- contractDoc : 'contracts/escrow/src/lib.rs: fund_escrow checks is_paused_internal' ,
60- } ,
61- refund : {
62- action : 'refund' ,
63- pausedBlocked : true ,
64- pausedReason : 'Refunds are temporarily paused by the contract operator.' ,
65- contractDoc : 'contracts/escrow/src/lib.rs: refund checks is_paused_internal' ,
66- } ,
67- refund_partial : {
68- action : 'refund_partial' ,
69- pausedBlocked : true ,
70- pausedReason : 'Partial refunds are temporarily paused by the contract operator.' ,
71- contractDoc : 'contracts/escrow/src/lib.rs: refund_partial checks is_paused_internal' ,
72- } ,
73- early_exit : {
74- action : 'early_exit' ,
75- pausedBlocked : true ,
76- pausedReason : 'Early exits are temporarily disabled while the contract is paused.' ,
77- contractDoc : 'contracts/escrow/src/lib.rs: early_exit / refund checks is_paused_internal' ,
78- } ,
79- release : {
80- action : 'release' ,
81- pausedBlocked : false ,
82- contractDoc : 'contracts/escrow/src/lib.rs: release does not check pause' ,
83- } ,
84- settle : {
85- action : 'settle' ,
86- pausedBlocked : false ,
87- contractDoc : 'contracts/escrow/src/lib.rs: settle_commitment / release does not check pause' ,
88- } ,
89- } ;
5+ import type { ProtocolStatus } from './protocol-policy' ;
906
91- export function isActionBlocked ( action : EscrowAction , paused : boolean ) : boolean {
92- if ( ! paused ) return false ;
93- return Boolean ( ACTION_POLICIES [ action ] ?. pausedBlocked ) ;
94- }
95-
96- export function getActionPauseReason ( action : EscrowAction , paused : boolean ) : string | undefined {
97- if ( ! paused ) return undefined ;
98- return ACTION_POLICIES [ action ] ?. pausedBlocked ? ACTION_POLICIES [ action ] ?. pausedReason : undefined ;
99- }
100-
101- export const COVERAGE_WARNING_MESSAGE =
102- 'Yield pool currently cannot cover this payout; settlement will fail until it is topped up.' ;
103-
104- export function isPayoutUncovered (
105- accruedYield : bigint | number ,
106- yieldPool : bigint | number ,
107- ) : boolean {
108- return BigInt ( accruedYield ) > BigInt ( yieldPool ) ;
109- }
7+ export * from './protocol-policy' ;
1108
1119export function decodeBool ( val : unknown ) : boolean {
11210 if ( typeof val === 'boolean' ) return val ;
0 commit comments