@@ -66,19 +66,14 @@ export const makeGraphFromDefinition = (
66
66
67
67
// Force the presence of particular edges.
68
68
const edges = [ ...graph . edges ] as Array < FlowEdge | undefined > ;
69
-
70
- // Ensure intra-Agoric links with 0 fee / 0 time.
71
- // Nodes: +agoric, <Cash>, <Deposit> on @agoric.
72
- const agoricHub : AssetPlaceRef = '@agoric' ;
73
- const seats : AssetPlaceRef [ ] = [ '<Cash>' , '<Deposit>' ] ;
74
- const staging : AssetPlaceRef = '+agoric' ;
75
- const capacityDefault = 9_007_199_254_740_000 ; // slightly less than MAX_SAFE_INTEGER
69
+ const capacityDefault = 9_007_199_254_740_000 ; // not quite MAX_SAFE_INTEGER
76
70
const addOrReplaceEdge = (
77
71
src : AssetPlaceRef ,
78
72
dest : AssetPlaceRef ,
79
73
customAttrs ?: Omit < FlowEdge , 'id' | 'src' | 'dest' > ,
80
74
) => {
81
- if ( ! graph . nodes . has ( src ) || ! graph . nodes . has ( dest ) ) return ;
75
+ ( graph . nodes . has ( src ) && graph . nodes . has ( dest ) ) ||
76
+ Fail `Graph missing nodes for link ${ src } ->${ dest } ` ;
82
77
83
78
// Remove any existing edge for exact src->dest
84
79
for ( let i = 0 ; i < edges . length ; i += 1 ) {
@@ -96,26 +91,20 @@ export const makeGraphFromDefinition = (
96
91
edges . push ( { id : 'TBD' , src, dest, ...dataAttrs } ) ;
97
92
} ;
98
93
99
- // +agoric <-> @agoric
100
- addOrReplaceEdge ( staging , agoricHub ) ;
101
- addOrReplaceEdge ( agoricHub , staging ) ;
102
-
103
- // seats <-> @agoric and seats <-> +agoric
104
- for ( const seat of seats ) {
105
- addOrReplaceEdge ( seat , agoricHub ) ;
106
- addOrReplaceEdge ( agoricHub , seat ) ;
107
- addOrReplaceEdge ( seat , staging ) ;
108
- addOrReplaceEdge ( staging , seat ) ;
109
- }
94
+ // Ensure intra-Agoric links with 0 fee / 0 time:
95
+ // <Deposit> -> +agoric -> @agoric -> <Cash>
96
+ // eslint-disable-next-line github/array-foreach
97
+ ( [ '<Deposit>' , '+agoric' , '@agoric' , '<Cash>' ] as AssetPlaceRef [ ] ) . forEach (
98
+ ( dest , i , arr ) => {
99
+ const src : AssetPlaceRef | undefined = i === 0 ? undefined : arr [ i - 1 ] ;
100
+ if ( ! src || ! graph . nodes . has ( src ) || ! graph . nodes . has ( dest ) ) return ;
101
+ addOrReplaceEdge ( src , dest ) ;
102
+ } ,
103
+ ) ;
110
104
111
105
// Override the base graph with inter-hub links from spec.
112
106
for ( const link of spec . links ) {
113
- const src = `@${ link . src } ` as AssetPlaceRef ;
114
- const dest = `@${ link . dest } ` as AssetPlaceRef ;
115
- ( graph . nodes . has ( src ) && graph . nodes . has ( dest ) ) ||
116
- Fail `Graph missing nodes for link ${ src } ->${ dest } ` ;
117
-
118
- addOrReplaceEdge ( src , dest , {
107
+ addOrReplaceEdge ( `@${ link . src } ` , `@${ link . dest } ` , {
119
108
capacity : Number ( link . capacity ?? capacityDefault ) ,
120
109
variableFee : link . variableFeeBps ?? 0 ,
121
110
fixedFee : link . flatFee === undefined ? undefined : Number ( link . flatFee ) ,
0 commit comments